Exemple #1
0
static void
handle_update (CcnetProcessor *processor,
               char *code, char *code_msg,
               char *content, int clen)
{
    switch (processor->state) {
    case RECV_ROOT:
        if (strncmp(code, SC_ROOT, 3) == 0) {
            queue_fs_roots (processor, content, clen);
        } else if (strncmp(code, SC_ROOT_END, 3) == 0) {
            /* change state to FETCH_OBJECT */
            process_fsroot_list (processor);
            processor->timer = ccnet_timer_new (
                                   (TimerCB)check_end_condition, processor, CHECK_INTERVAL);
            processor->state = FETCH_OBJECT;
        } 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 FETCH_OBJECT:
        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 ();
    }
}
Exemple #2
0
static void
handle_response (CcnetProcessor *processor,
                 char *code, char *code_msg,
                 char *content, int clen)
{
    SeafileGetfsProc *proc = (SeafileGetfsProc *)processor;
    TransferTask *task = proc->tx_task;

    switch (processor->state) {
    case REQUEST_SENT:
        if (strncmp(code, SC_OK, 3) == 0) {
            load_fsroot_list (processor);
            processor->timer = ccnet_timer_new (
                (TimerCB)check_object, processor, CHECK_INTERVAL);
            processor->state = FETCH_OBJECT;
            return;
        }
        break;
    case FETCH_OBJECT:
        if (strncmp(code, SC_OBJ_SEG, 3) == 0) {
            recv_fs_object_seg (processor, content, clen);
            return;

        } else if (strncmp(code, SC_OBJ_SEG_END, 3) == 0) {
            recv_fs_object_seg (processor, content, clen);
            process_fs_object_seg (processor);
            return;
            
        } else if (strncmp(code, SC_OBJECT, 3) == 0) {
            recv_fs_object (processor, content, clen);
            return;
        }
        break;
    default:
        g_assert (0);
    }

    g_warning ("Bad response: %s %s.\n", code, code_msg);
    if (memcmp (code, SC_ACCESS_DENIED, 3) == 0)
        transfer_task_set_error (task, TASK_ERR_ACCESS_DENIED);
    ccnet_processor_done (processor, FALSE);
}
Exemple #3
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 ();
    }
}
Exemple #4
0
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 ();
    }
}