Public feed #601016

Untitled

public text v1 · immutable
Raw Edit
·published 2007-07-03 07:23 UTC
rendered paste body
#include <stdio.h>
#include <string.h>
#include <CoreFoundation/CoreFoundation.h>
#include <MobileDevice/MobileDevice.h>

void recursive_ls(struct afc_connection *conn, char *path)
{
    char *dirent;
    char *newpath;
    int i;
    mach_error_t err;
    struct afc_directory *dir;

    err = AFCDirectoryOpen(conn, path, &dir);
    if (err)
        return;
    // fprintf(stderr, "AFCDirectoryOpen: %08x\n", err);

    while (1) {
        err = AFCDirectoryRead(0, dir, &dirent);
        if (err || !dirent)
            return;

        if (!strcmp(dirent, ".") || !strcmp(dirent, ".."))
            continue;

        printf("%s%s\n", path, dirent);
        asprintf(&newpath, "%s%s/", path, dirent);

        recursive_ls(conn, newpath);

        free(newpath);
        //fprintf(stderr, "AFCDirectoryRead: %08x, dirent=%08x\n", err, (unsigned int)dirent);
    }
}

void device_notification_callback(struct am_device_notification_callback_info *
    info)
{
    int i;
    mach_error_t err;
    struct afc_connection *conn;
    struct afc_device_info *dinfo;
    struct am_device *dev = info->dev;
    unsigned int afc_handle;

    fprintf(stderr, "device notification callback: got info with msg %d\n",
        info->msg);

    err = AMDeviceConnect(dev); 
    fprintf(stderr, "AMDeviceConnect: %08x\n", err);
    err = AMDeviceIsPaired(dev); 
    fprintf(stderr, "AMDeviceIsPaired: %08x\n", err);
    err = AMDeviceValidatePairing(dev); 
    fprintf(stderr, "AMDeviceValidatePairing: %08x\n", err);
    err = AMDeviceStartSession(dev);
    fprintf(stderr, "AMDeviceStartSession: %08x\n", err);
    err = AMDeviceStartService(dev, AMSVC_AFC, &afc_handle, NULL);
    fprintf(stderr, "AMDeviceStartService: %08x\n", err);
    err = AMDeviceStopSession(dev);
    fprintf(stderr, "AMDeviceStopSession: %08x\n", err);
    err = AFCConnectionOpen(afc_handle, 0, &conn); 
    fprintf(stderr, "AFCConnectionOpen: %08x\n", err);
    err = AFCDeviceInfoOpen(conn, &dinfo);
    fprintf(stderr, "AFCDeviceInfoOpen: %08x\n", err);
    AFCPlatformInit();

    recursive_ls(conn, "/");

    fprintf(stderr, "break here\n");
}

int main()
{
    mach_error_t err;
    struct am_device_notification *notif;

    err = AMDeviceNotificationSubscribe(device_notification_callback, 0, 0, 0,
        &notif);
    fprintf(stderr, "AMDeviceNotificationSubscribe: %08x\n", err);

    fprintf(stderr, "Running...\n");

    CFRunLoopRun();

    return 0;
}