예제 #1
0
int SeafileRpcClient::getRepoTransferInfo(const QString& repo_id, int *rate, int *percent)
{
    GError *error = NULL;
    GObject *task = searpc_client_call__object (seafile_rpc_client_,
                                                "seafile_find_transfer_task",
                                                SEAFILE_TYPE_TASK,
                                                &error, 1,
                                                "string", toCStr(repo_id));
    if (error) {
        g_error_free(error);
        return -1;
    }

    if (!task) {
        return -1;
    }

    int finished = 0;
    int total = 0;
    g_object_get (task,
                  "rate", rate,
                  "block_total", &total,
                  "block_done", &finished,
                  NULL);

    if (total == 0) {
        *percent = 0;
    } else {
        *percent = 100 * finished / total;
    }

    g_object_unref(task);

    return 0;
}
예제 #2
0
int SeafileRpcClient::getLocalRepo(const QString& repo_id, LocalRepo *repo)
{
    GError *error = NULL;
    GObject *obj = searpc_client_call__object(
        seafile_rpc_client_,
        "seafile_get_repo",
        SEAFILE_TYPE_REPO,
        &error, 1,
        "string", toCStr(repo_id));

    if (error != NULL) {
        g_error_free(error);
        return -1;
    }

    if (obj == NULL) {
        return -1;
    }

    *repo = LocalRepo::fromGObject(obj);
    g_object_unref(obj);

    getSyncStatus(*repo);
    return 0;
}
예제 #3
0
void SeafileRpcClient::getCheckOutDetail(CloneTask *task)
{
    GError *error = NULL;
    GObject *obj = searpc_client_call__object(
        seafile_rpc_client_,
        "seafile_get_checkout_task",
        SEAFILE_TYPE_CHECKOUT_TASK,
        &error, 1,
        "string", toCStr(task->repo_id));

    if (error != NULL) {
        g_error_free(error);
        return;
    }

    if (obj == NULL) {
        return;
    }

    int checkout_done = 0;
    int checkout_total = 0;

    g_object_get (obj,
                  "total_files", &checkout_total,
                  "finished_files", &checkout_done,
                  NULL);

    task->checkout_done = checkout_done;
    task->checkout_total = checkout_total;

    g_object_unref (obj);
}
예제 #4
0
void SeafileRpcClient::getSyncStatus(LocalRepo &repo)
{
    if (repo.worktree_invalid) {
        repo.setSyncInfo("error", "invalid worktree");
        return;
    }

    GError *error = NULL;
    SeafileSyncTask *task = (SeafileSyncTask *)
        searpc_client_call__object (seafile_rpc_client_,
                                    "seafile_get_repo_sync_task",
                                    SEAFILE_TYPE_SYNC_TASK,
                                    &error, 1,
                                    "string", toCStr(repo.id));
    if (error) {
        repo.setSyncInfo("unknown");
        return;
    }

    if (!task) {
        repo.setSyncInfo("waiting for sync");
        return;
    }

    char *state = NULL;
    char *err = NULL;
    g_object_get(task, "state", &state, "error", &err, NULL);

    repo.setSyncInfo(state,
                     g_strcmp0(state, "error") == 0 ? err : NULL);

    g_free (state);
    g_free (err);
    g_object_unref(task);
}
예제 #5
0
GObject *
seafile_web_query_access_token (SearpcClient *client,
                                const char *token,
                                GError **error)
{
    return searpc_client_call__object (
        client, "seafile_web_query_access_token", SEAFILE_TYPE_WEB_ACCESS, error,
        1, "string", token);
}
예제 #6
0
CcnetPeer *
ccnet_get_peer_by_idname (SearpcClient *client, const char *idname)
{
    if (!idname)
        return NULL;
    return (CcnetPeer *) searpc_client_call__object(
        client, "get_peer_by_idname", CCNET_TYPE_PEER, NULL,
        1, "string", idname);
}
예제 #7
0
void SeafileRpcClient::getTransferDetail(CloneTask* task)
{
    GError *error = NULL;
    GObject *obj = searpc_client_call__object(
        seafile_rpc_client_,
        "seafile_find_transfer_task",
        SEAFILE_TYPE_TASK,
        &error, 1,
        "string", toCStr(task->repo_id));

    if (error != NULL) {
        g_error_free(error);
        return;
    }

    if (obj == NULL) {
        return;
    }

    if (task->state == "error") {
        char *err = NULL;
        g_object_get(obj, "error_str", &err, NULL);
        task->error_str = err;
    } else if (task->state == "fetch") {
        char *rt_state = NULL;
        g_object_get (obj, "rt_state", &rt_state, NULL);
        task->rt_state = rt_state;
        g_free (rt_state);

        if (task->rt_state == "data") {
            int block_done = 0;
            int block_total = 0;

            g_object_get (obj,
                          "block_done", &block_done,
                          "block_total", &block_total,
                          NULL);

            task->block_done = block_done;
            task->block_total = block_total;
        } else if (task->rt_state == "fs") {
            int fs_objects_done = 0;
            int fs_objects_total = 0;

            g_object_get (obj,
                          "fs_objects_done", &fs_objects_done,
                          "fs_objects_total", &fs_objects_total,
                          NULL);

            task->fs_objects_done = fs_objects_done;
            task->fs_objects_total = fs_objects_total;
        }
    }

    g_object_unref (obj);
}
예제 #8
0
GObject *
seafile_get_decrypt_key (SearpcClient *client,
                         const char *repo_id,
                         const char *user,
                         GError **error)
{
    return searpc_client_call__object (
        client, "seafile_get_decrypt_key", SEAFILE_TYPE_CRYPT_KEY, error,
        2, "string", repo_id, "string", user);
}
예제 #9
0
CcnetPeer *
ccnet_get_peer (SearpcClient *client, const char *peer_id)
{
    if (!peer_id)
        return NULL;

    return (CcnetPeer *) searpc_client_call__object(
        client, "get_peer",CCNET_TYPE_PEER, NULL,
        1, "string", peer_id);
}
예제 #10
0
GObject *
seafile_get_repo (SearpcClient *client,
                  const char *repo_id,
                  GError **error)
{
    g_return_val_if_fail (client && repo_id, NULL);

    return searpc_client_call__object (
        client, "seafile_get_repo", SEAFILE_TYPE_REPO, error,
        1, "string", repo_id);
}
예제 #11
0
파일: searpc.c 프로젝트: haiwen/libsearpc
void
test_searpc__object_call (void)
{
    GObject *result;
    GError *error = NULL;

    result = searpc_client_call__object (client, "get_maman_bar",
                                         MAMAN_TYPE_BAR, &error,
                                         1, "string", "kitty");
    cl_assert (error == NULL);
    g_object_unref (result);
}
예제 #12
0
CcnetPeer *
ccnet_get_default_relay (SearpcClient *client)
{
    CcnetSessionBase *base = (CcnetSessionBase *)
        searpc_client_call__object(
            client, "get_session_info", CCNET_TYPE_SESSION_BASE, NULL, 0);

    if (!base)
        return NULL;

    CcnetPeer *relay = ccnet_get_peer (client, base->relay_id);
    g_object_unref (base);
    return relay;
}
예제 #13
0
void SeafileRpcClient::getSyncStatus(LocalRepo &repo)
{
    if (repo.worktree_invalid) {
        repo.setSyncInfo("error", "invalid worktree");
        return;
    }

    GError *error = NULL;
    SeafileSyncTask *task = (SeafileSyncTask *)
        searpc_client_call__object (seafile_rpc_client_,
                                    "seafile_get_repo_sync_task",
                                    SEAFILE_TYPE_SYNC_TASK,
                                    &error, 1,
                                    "string", toCStr(repo.id));
    if (error) {
        repo.setSyncInfo("unknown");
        g_error_free(error);
        return;
    }

    if (!task) {
        repo.setSyncInfo("waiting for sync");
        return;
    }

    char *state = NULL;
    char *err = NULL;
    g_object_get(task, "state", &state, "error", &err, NULL);

    // seaf-daemon would retry three times for errors like quota/permission
    // before setting the "state" field to "error", but the GUI should display
    // the error from the beginning.
    if (err != NULL && strlen(err) > 0 && strcmp(err, "Success") != 0) {
        state = g_strdup("error");
    }

    repo.setSyncInfo(state,
                     g_strcmp0(state, "error") == 0 ? err : NULL);

    if (repo.sync_state == LocalRepo::SYNC_STATE_ING) {
        getRepoTransferInfo(repo.id, &repo.transfer_rate, &repo.transfer_percentage);
    }

    g_free (state);
    g_free (err);
    g_object_unref(task);
}
예제 #14
0
int SeafileRpcClient::generateMagicAndRandomKey(int enc_version,
                                                const QString &repo_id,
                                                const QString &passwd,
                                                QString *magic,
                                                QString *random_key)
{
    GError *error = NULL;
    GObject *obj = searpc_client_call__object (
        seafile_rpc_client_,
        "seafile_generate_magic_and_random_key",
        SEAFILE_TYPE_ENCRYPTION_INFO,
        &error, 3,
        "int", enc_version,
        "string", toCStr(repo_id),
        "string", toCStr(passwd));
    if (error) {
        qWarning("failed to generate magic and random_key : %s\n", error->message);
        g_error_free(error);
        return -1;
    }

    char *c_magic = NULL;
    char *c_random_key = NULL;
    g_object_get (obj,
                  "magic", &c_magic,
                  "random_key", &c_random_key,
                  NULL);

    *magic = QString(c_magic);
    *random_key = QString(c_random_key);

    g_object_unref (obj);
    g_free (c_magic);
    g_free (c_random_key);
    return 0;
}
예제 #15
0
파일: readdir.c 프로젝트: janBest/seafile
static CcnetEmailUser *get_user_from_ccnet (SearpcClient *client, const char *user)
{
    return (CcnetEmailUser *)searpc_client_call__object (client,
                                       "get_emailuser", CCNET_TYPE_EMAIL_USER, NULL,
                                       1, "string", user);
}