static void send_commits (CcnetProcessor *processor, const char *head) { SeafileSendcommitV3Proc *proc = (SeafileSendcommitV3Proc *)processor; USE_PRIV; char *last_uploaded; last_uploaded = seaf_repo_manager_get_repo_property (seaf->repo_mgr, proc->tx_task->repo_id, REPO_LOCAL_HEAD); if (!last_uploaded || strlen(last_uploaded) != 40) { seaf_warning ("Last uploaded commit id is not found in db or invalid.\n"); ccnet_processor_send_update (processor, SC_SHUTDOWN, SS_SHUTDOWN, NULL, 0); ccnet_processor_done (processor, FALSE); return; } memcpy (priv->last_uploaded_id, last_uploaded, 40); g_free (last_uploaded); ccnet_processor_thread_create (processor, seaf->job_mgr, compute_upload_commits_thread, compute_upload_commits_done, processor); }
static int sync_repo_slave_start (CcnetProcessor *processor, int argc, char **argv) { USE_PRIV; if (argc != 2) { g_warning ("[sync-repo-slave] argc(%d) must be 2\n", argc); ccnet_processor_done (processor, FALSE); return -1; } memcpy (priv->repo_id, argv[0], 37); priv->branch_name = g_strdup (argv[1]); /* send the head commit of the branch */ if (ccnet_processor_thread_create (processor, seaf->job_mgr, send_repo_branch_info, thread_done, processor) < 0) { g_warning ("[sync repo] failed to start thread.\n"); ccnet_processor_send_response (processor, SC_SERVER_ERROR, SS_SERVER_ERROR, NULL, 0); ccnet_processor_done (processor, FALSE); return -1; } return 0; }
static int start (CcnetProcessor *processor, int argc, char **argv) { char *session_token; USE_PRIV; if (argc != 1) { ccnet_processor_send_response (processor, SC_BAD_ARGS, SS_BAD_ARGS, NULL, 0); ccnet_processor_done (processor, FALSE); return -1; } session_token = argv[0]; if (seaf_token_manager_verify_token (seaf->token_mgr, NULL, processor->peer_id, session_token, priv->repo_id) == 0) { ccnet_processor_thread_create (processor, seaf->job_mgr, get_repo_info_thread, get_repo_info_done, processor); return 0; } else { ccnet_processor_send_response (processor, SC_ACCESS_DENIED, SS_ACCESS_DENIED, NULL, 0); ccnet_processor_done (processor, FALSE); return -1; } }
static int put_commit_start (CcnetProcessor *processor, int argc, char **argv) { char *head_id, *remote_id = NULL; char *session_token; USE_PRIV; if (argc < 2) { ccnet_processor_send_response (processor, SC_BAD_ARGS, SS_BAD_ARGS, NULL, 0); ccnet_processor_done (processor, FALSE); return -1; } if (argc == 2) { head_id = argv[0]; session_token = argv[1]; } else if (argc >= 3) { head_id = argv[0]; remote_id = argv[1]; session_token = argv[2]; } if (strlen(head_id) != 40 || (remote_id && strlen(remote_id) != 40)) { ccnet_processor_send_response (processor, SC_BAD_ARGS, SS_BAD_ARGS, NULL, 0); ccnet_processor_done (processor, FALSE); return -1; } if (seaf_token_manager_verify_token (seaf->token_mgr, processor->peer_id, session_token, NULL) < 0) { ccnet_processor_send_response (processor, SC_ACCESS_DENIED, SS_ACCESS_DENIED, NULL, 0); ccnet_processor_done (processor, FALSE); return -1; } memcpy (priv->head_commit_id, head_id, 41); if (remote_id != NULL) memcpy (priv->remote_commit_id, remote_id, 41); ccnet_processor_send_response (processor, SC_OK, SS_OK, NULL, 0); priv->reader_id = seaf_obj_store_register_async_read (seaf->commit_mgr->obj_store, read_done_cb, processor); priv->registered = TRUE; ccnet_processor_thread_create (processor, seaf->job_mgr, collect_commit_id_thread, collect_commit_id_done, processor); return 0; }
static void send_commits (CcnetProcessor *processor, const char *head) { ccnet_processor_thread_create (processor, seaf->job_mgr, compute_upload_commits_thread, compute_upload_commits_done, processor); }
static int start_compute (CcnetProcessor *processor) { int rc; rc = ccnet_processor_thread_create (processor, compute_repo_size, NULL); if (rc < 0) { g_warning ("[repo stat] failed to create thread.\n"); return -1; } return 0; }
static void get_email_cb (void *result, void *data, GError *error) { char *email = result; CcnetProcessor *processor = data; USE_PRIV; if (!email) { g_warning ("[check tx] cannot find email for peer %s.\n", processor->peer_id); ccnet_processor_send_response (processor, SC_ACCESS_DENIED, SS_ACCESS_DENIED, NULL, 0); ccnet_processor_done (processor, FALSE); return; } priv->email = g_strdup(email); ccnet_processor_thread_create (processor, check_tx, thread_done, processor); }
static int start (CcnetProcessor *processor, int argc, char **argv) { USE_PRIV; char *session_token; if (argc != 4) { ccnet_processor_send_response (processor, SC_BAD_ARGS, SS_BAD_ARGS, NULL, 0); ccnet_processor_done (processor, FALSE); return -1; } if (!is_uuid_valid(argv[0]) || strlen(argv[2]) != 40) { ccnet_processor_send_response (processor, SC_BAD_ARGS, SS_BAD_ARGS, NULL, 0); ccnet_processor_done (processor, FALSE); return -1; } memcpy (priv->repo_id, argv[0], 36); memcpy (priv->new_head, argv[2], 40); priv->branch_name = g_strdup(argv[1]); session_token = argv[3]; if (seaf_token_manager_verify_token (seaf->token_mgr, NULL, processor->peer_id, session_token, NULL) < 0) { ccnet_processor_send_response (processor, SC_ACCESS_DENIED, SS_ACCESS_DENIED, NULL, 0); ccnet_processor_done (processor, FALSE); return -1; } ccnet_processor_thread_create (processor, seaf->job_mgr, update_repo, thread_done, processor); return 0; }
static int check_fs_tree_from (CcnetProcessor *processor, const char *root_id) { USE_PRIV; memcpy (priv->root_id, root_id, 40); priv->fetch_objs = NULL; int rc = ccnet_processor_thread_create (processor, seaf->job_mgr, check_objects_thread, check_objects_done, processor); if (rc < 0) { seaf_warning ("Failed to start worker thread.\n"); return -1; } priv->worker_running = TRUE; return 0; }
static void get_repo_info_done (void *data) { CcnetProcessor *processor = data; USE_PRIV; if (priv->success) { ccnet_processor_send_response (processor, SC_OK, SS_OK, NULL, 0); register_async_io (processor); ccnet_processor_thread_create (processor, seaf->job_mgr, calculate_send_object_list, calculate_send_object_list_done, processor); } else { ccnet_processor_send_response (processor, SC_SHUTDOWN, SS_SHUTDOWN, NULL, 0); ccnet_processor_done (processor, FALSE); } }
static int start (CcnetProcessor *processor, int argc, char **argv) { char *repo_id, *branch_name, *token; USE_PRIV; if (argc != 5) { ccnet_processor_send_response (processor, SC_BAD_ARGS, SS_BAD_ARGS, NULL, 0); ccnet_processor_done (processor, FALSE); return -1; } if (strcmp (argv[0], "upload") == 0) { priv->type = CHECK_TX_TYPE_UPLOAD; } else if (strcmp (argv[0], "download") == 0) { priv->type = CHECK_TX_TYPE_DOWNLOAD; } else { ccnet_processor_send_response (processor, SC_BAD_ARGS, SS_BAD_ARGS, NULL, 0); ccnet_processor_done (processor, FALSE); return -1; } int client_version = atoi(argv[1]); if (client_version == 4) { seaf_debug ("Client protocol version is 4, not supported.\n"); ccnet_processor_send_response (processor, SC_PROTOCOL_MISMATCH, SS_PROTOCOL_MISMATCH, NULL, 0); ccnet_processor_done (processor, FALSE); return -1; } repo_id = argv[2]; branch_name = argv[3]; token = argv[4]; if (strlen(repo_id) != 36) { ccnet_processor_send_response (processor, SC_BAD_ARGS, SS_BAD_ARGS, NULL, 0); ccnet_processor_done (processor, FALSE); return -1; } if (priv->type == CHECK_TX_TYPE_UPLOAD && strcmp (branch_name, "master") != 0) { ccnet_processor_send_response (processor, SC_BAD_ARGS, SS_BAD_ARGS, NULL, 0); ccnet_processor_done (processor, FALSE); return -1; } memcpy (priv->repo_id, repo_id, 37); priv->branch_name = g_strdup(branch_name); priv->token = g_strdup(token); CcnetPeer *peer = ccnet_get_peer (seaf->ccnetrpc_client, processor->peer_id); if (!peer || !peer->session_key) { seaf_warning ("[check tx slave v3] session key of peer %.10s is null\n", processor->peer_id); ccnet_processor_send_response (processor, SC_BAD_PEER, SS_BAD_PEER, NULL, 0); ccnet_processor_done (processor, FALSE); if (peer) g_object_unref (peer); return -1; } priv->session_key = g_strdup(peer->session_key); priv->peer_addr = g_strdup(peer->addr_str); priv->peer_name = g_strdup(peer->name); if (!priv->peer_name) priv->peer_name = g_strdup("Unknown"); g_object_unref (peer); seaf_debug ("[check-tx] %s repo %.8s.\n", argv[0], repo_id); ccnet_processor_thread_create (processor, seaf->job_mgr, check_tx, thread_done, processor); return 0; }
static void handle_response (CcnetProcessor *processor, char *code, char *code_msg, char *content, int clen) { switch (processor->state) { case INIT: if (strncmp (code, SC_OK, 3) == 0) processor->state = CHECK_OBJECT_LIST; else { seaf_warning ("Bad response: %s %s\n", code, code_msg); ccnet_processor_done (processor, FALSE); } break; case CHECK_OBJECT_LIST: if (strncmp (code, SC_OBJ_LIST_SEG, 3) == 0) { if (clen % 40 != 0) { seaf_warning ("Invalid object list segment length %d.\n", clen); ccnet_processor_send_update (processor, SC_SHUTDOWN, SS_SHUTDOWN, NULL, 0); ccnet_processor_done (processor, FALSE); return; } process_recv_object_list (processor, content, clen); } else if (strncmp (code, SC_OBJ_LIST_SEG_END, 3) == 0) { ccnet_processor_thread_create (processor, seaf->job_mgr, calculate_needed_object_list, calculate_needed_object_list_done, processor); } else if (strncmp (code, SC_END, 3) == 0) { /* The server finds nothing to put. */ ccnet_processor_done (processor, TRUE); } else { seaf_warning ("Bad response: %s %s\n", code, code_msg); ccnet_processor_send_update (processor, SC_BAD_RESPONSE_CODE, SS_BAD_RESPONSE_CODE, NULL, 0); ccnet_processor_done (processor, FALSE); } break; case GET_OBJECTS: if (strncmp(code, SC_OBJ_SEG, 3) == 0) { recv_fs_object_seg (processor, content, clen); } else if (strncmp(code, SC_OBJ_SEG_END, 3) == 0) { recv_fs_object_seg (processor, content, clen); process_fs_object_seg (processor); } else if (strncmp(code, SC_OBJECT, 3) == 0) { recv_fs_object (processor, content, clen); } else { seaf_warning ("Bad response: %s %s\n", code, code_msg); ccnet_processor_send_update (processor, SC_BAD_RESPONSE_CODE, SS_BAD_RESPONSE_CODE, NULL, 0); ccnet_processor_done (processor, FALSE); } break; default: g_return_if_reached (); } }
static void handle_update (CcnetProcessor *processor, char *code, char *code_msg, char *content, int clen) { USE_PRIV; switch (processor->state) { case CHECK_OBJECT_LIST: if (strncmp (code, SC_OBJ_LIST_SEG, 3) == 0) { if (clen % 40 != 0) { seaf_warning ("Invalid object list segment length %d.\n", clen); ccnet_processor_send_response (processor, SC_SHUTDOWN, SS_SHUTDOWN, NULL, 0); ccnet_processor_done (processor, FALSE); return; } priv->recv_objs = g_memdup(content, clen); priv->recv_len = clen; ccnet_processor_thread_create (processor, seaf->job_mgr, process_object_list, process_object_list_done, processor); } else if (strncmp (code, SC_OBJ_LIST_SEG_END, 3) == 0) { if (priv->total_needed == 0) { seaf_debug ("No objects are needed. Done.\n"); ccnet_processor_send_response (processor, SC_END, SS_END, NULL, 0); ccnet_processor_done (processor, TRUE); return; } processor->state = RECV_OBJECTS; } else if (strncmp (code, SC_END, 3) == 0) { /* The client finds nothing to upload. */ ccnet_processor_done (processor, TRUE); } else { seaf_warning ("Bad update: %s %s\n", code, code_msg); ccnet_processor_send_response (processor, SC_BAD_UPDATE_CODE, SS_BAD_UPDATE_CODE, NULL, 0); ccnet_processor_done (processor, FALSE); } break; case RECV_OBJECTS: if (strncmp(code, SC_OBJ_SEG, 3) == 0) { recv_fs_object_seg (processor, content, clen); } else if (strncmp(code, SC_OBJ_SEG_END, 3) == 0) { recv_fs_object_seg (processor, content, clen); process_fs_object_seg (processor); } else if (strncmp(code, SC_OBJECT, 3) == 0) { recv_fs_object (processor, content, clen); } else { seaf_warning ("Bad update: %s %s\n", code, code_msg); ccnet_processor_send_response (processor, SC_BAD_UPDATE_CODE, SS_BAD_UPDATE_CODE, NULL, 0); ccnet_processor_done (processor, FALSE); } break; default: g_return_if_reached (); } }