MEGA SDK

repository·master·Indexed 23 days ago

https://github.com/meganz/sdk

A client access engine providing low-level and intermediate APIs for interacting with MEGA's secure, end-to-end encrypted cloud storage. It supports multiple platforms including Android, iOS, Linux, macOS, and Windows, offering a documented intermediate layer via include/megaapi.h and various example implementations in C++, Java (Android), and Objective-C (iOS).

Tokens
6K
Snippets
16
Records
41
Agent score
81%

What's inside meganz-sdk

  1. Overview of MEGA SDK contents

    master

    The MEGA SDK provides multiple layers of access to MEGA's secure cloud storage:

    1. Low-level SDK: Provides full access to all SDK features. The megacli command-line tool is the primary example of its usage.
    2. Intermediate Layer: A documented layer designed to facilitate binding with other programming languages. The primary entry point is the include/megaapi.h header.
    3. Example Applications: Provided for various platforms:
      • C++: A plain C++ example in examples/simple_client.
      • Android: Java bindings based on SWIG in examples/android.
      • iOS: Objective-C bindings in examples/iOS.

    Additionally, MEGAcmd is a higher-level application that uses the SDK to provide interactive and scriptable access (e.g., via PHP or Python).

  2. Important limitations of Folder Syncing

    master

    The current sync functionality has several constraints that developers must account for:

    • Concurrency: No locking between clients; concurrent creation of identical names can cause server-side duplicates.
    • Naming Semantics: Syncing between different filesystems (e.g., Windows vs POSIX) can lead to data loss due to case sensitivity differences.
    • Encoding: On POSIX, filenames are assumed to be UTF-8. Invalid sequences cause undefined behavior.
    • Filesystem Exposure: Local items must not be exposed to the sync subsystem more than once (e.g., via symlinks or nested syncs) to avoid data loss.
    • Versioning: No in-place versioning. Deleted remote files are moved to //bin/SyncDebris (for owned accounts only). Deleted local files are moved to a hidden debris folder in the sync root.
    • Write Pattern: No delta writes; changed files are overwritten in their entirety. Do not sync live database tables.
    • Network: No direct peer-to-peer syncing; all traffic goes through MEGA's remote infrastructure.
    • Directionality: No support for unidirectional (backup-only) syncing.
  3. Build and run the iOS Example app

    master

    The iOS Example app is an Xcode project designed to demonstrate MEGA SDK capabilities on iOS (Target OS: iOS 7.0+). It provides a demo implementation for user authentication, file/folder management (listing, navigating, downloading, uploading, creating, deleting, renaming, exporting), and contact viewing.

    Prerequisites

    1. Download or clone the complete MEGA SDK repository.
    2. Download the prebuilt third-party dependencies from this link.
    3. Uncompress the dependencies and move the include and lib directories into sdk/bindings/ios/3rdparty.

    Build Steps

    1. Navigate to sdk/examples/iOS and open MEGA.xcworkspace in Xcode.
    2. Ensure the Demo target is selected in the Xcode scheme selector.
    3. Build and run the application on an iOS device or simulator.
  4. Build the MEGA SDK library

    master

    The SDK uses CMake for configuration and VCPKG to manage dependencies on GNU/Linux, macOS, and Windows.

    Prerequisites

    Common Tools:

    • Git
    • CMake 3.19 or higher

    Platform Specifics:

    • Windows: Visual Studio 2022, MSVC v142, and Windows 10 SDK (10.0.22621.0).
    • macOS: Xcode and Developer tools (xcode-select --install), plus autoconf, autoconf-archive, automake, pkg-config, nasm, and libtool.
    • Linux (Debian-based): sudo apt install build-essential curl zip unzip autoconf autoconf-archive nasm libtool-bin
  5. Build and run the iOS Swift Example app

    master

    The iOS Swift Example app is an Xcode project designed for developing MEGA applications on iOS (Target OS: iOS 8.0 or higher). It demonstrates core MEGA functionality including user login, file/folder navigation, downloading files, node management (delete, rename, export), viewing contacts, and logout.

    Prerequisites

    1. Download or clone the complete MEGA SDK repository.
    2. Download the prebuilt third-party dependencies from: https://mega.nz/#!gN9w0I7Q!-OPUWBoEnvXeZWkkC5oUho2MFm_49nwBwN6q07sxKII.

    Setup Instructions

    1. Uncompress the downloaded dependencies.
    2. Move the include and lib directories into sdk/bindings/ios/3rdparty within your SDK folder.
    3. Navigate to sdk/examples/Swift and open MEGAWS.xcworkspace in Xcode.
    4. Ensure the MEGA target is selected in Xcode.
    5. Build and run the application.

    Building Third-Party Dependencies Manually

    If you prefer to build the dependencies from source instead of using prebuilt binaries:

    1. Open a terminal in sdk/bindings/ios/3rdparty.
    2. Execute the build script:
    sh build-all.sh

    Note: This process may take approximately 20 minutes to complete.

  6. Prepare SDK source and VCPKG

    master

    To prepare your workspace, create a directory, clone the SDK repository, and clone the VCPKG repository alongside it.

    # Create workspace
    mkdir mega
    cd mega
    
    # Clone SDK
    git clone https://github.com/meganz/sdk
    
    # Clone VCPKG (if not already present)
    git clone https://github.com/microsoft/vcpkg

    Note: Ensure your local VCPKG repository is up to date by running git pull inside the VCPKG directory to avoid dependency errors.

    mkdir mega
    cd mega
    
    git clone https://github.com/meganz/sdk
    
    git clone https://github.com/microsoft/vcpkg
  7. Make another Release Candidate (RC)

    master

    To create a new Release Candidate, configure the [make_another_rc] section in your local config.toml. The script automatically determines the new RC number by incrementing the last existing RC for that release by 1.

    Required Environment Variables:

    • GITLAB_TOKEN
    • JIRA_TOKEN
    • SLACK_TOKEN

    Execution: Run the script from a directory within the repository intended for the RC.

    python3 path/to/make_another_rc.py path/to/config.toml
  8. Set up Python environment for automation scripts

    master

    The automation scripts require Python 3 (tested with 3.12.2).

    Installation Steps:

    1. Install pip (e.g., python3 -m ensurepip --upgrade or sudo apt install python3-pip on Ubuntu).
    2. Install dependencies: pip install -r requirements.txt.
    3. Handling externally-managed-environment errors: If you encounter this error, use a virtual environment:
      python3 -m venv .venv
      ./.venv/bin/python -m pip install -r requirements.txt
    python3 -m venv .venv
    ./.venv/bin/python -m pip install -r requirements.txt
  9. Configure Slack for automation notifications

    master

    To enable Slack notifications, you must provide a User OAuth Token.

    Setup Steps:

    1. Create a Slack App via api.slack.com/apps.
    2. In OAuth & Permissions, add the chat:write scope to User Token Scopes.
    3. Install to Workspace and copy the User OAuth Token.
    4. Set the token in the SLACK_TOKEN environment variable.

    Channel and Thread Identification:

    • Channel: Use the name (e.g., foo_bar without the #) or the ID from the web URL (the component after /client/AAAAAAAAA/).
    • Thread ID: Obtain the thread ID from a message URL (e.g., .../archives/BBBBBBBBBBB/pTTTTTTTTTTTTTTTT). Split the TTTTTTTTTTTTTTTT part by a . to get the 10.6 format TTTTTTTT.TTTTTT.
  10. Patch a Release

    master

    To patch an existing release, configure the [patch_release] section in your local config.toml. Note that automation is only provided for step 7 and beyond due to complexity with multiple patches.

    Required Environment Variables:

    • GITLAB_TOKEN
    • JIRA_TOKEN
    • SLACK_TOKEN
    • GPG_KEYGRIP
    • GPG_PASSWORD

    Execution: Run the script from a directory within the repository intended for patching.

    python3 ./patch_release.py path/to/config.toml
  11. Configure environment variables for building MEGA SDK on Android

    master

    Before building the third-party libraries and the MEGA SDK (libmega.so), you must configure the following environment variables or create symbolic links in your home directory:

    • NDK_ROOT: Path to your Android NDK installation.
    • ANDROID_HOME: Path to your Android SDK installation.
    • JAVA_HOME: Path to your Java installation.

    Symbolic Link Method: Alternatively, you can create symbolic links at ${HOME}/android-ndk, ${HOME}/android-sdk, and ${HOME}/android-java pointing to their respective installation paths.

  12. Integrate zxcvbn-c into C/C++ programs

    master

    zxcvbn-c is a C/C++ implementation of the zxcvbn password strength estimation. It is intended to be included directly in your project's source code. It primarily supports character sets using single-byte characters (0x20 to 0x7E).

    Integration Methods

    There are two ways to include dictionary data:

    1. Embedded (Included in executable):

      • Use files: zxcvbn.c, zxcvbn.h, and dict-src.h.
      • This method is useful for standalone binaries where you don't want to manage external data files.
    2. External (Read from file):

      • Use files: zxcvbn.c, zxcvbn.h, dict-crc.h, and zxcvbn.dict.
      • You must compile with the #define USE_DICT_FILE macro.
      • The dict-crc.h file contains the CRC of the dictionary data, allowing your executable to detect file corruption.

    Compilation Note

    To compile as C++, rename zxcvbn.c to zxcvbn.cpp (or your compiler's preferred extension).