示例#1
0
/*
 * Called once one file was sent successfully. Starts the sending of the next file, if there is one.
 */
static void upload_done( void *context, char *last_modified, const char *format, ... ) {
    upload_context *  uContext = (upload_context *)context;
    char msg[MAX_SIZEOF_RESPONSE_MSG];
    va_list ap;
    char ** new_cursor;
    char * new_full_path;

    if(format) {
        va_start(ap, format);
        vsnprintf(msg,sizeof(msg),format,ap);
        va_end(ap);
        roadmap_log(ROADMAP_DEBUG,"done uploading file : %s. Received response : %s",*uContext->cursor,msg);
        strncpy(SyncUploadMessages[SyncUploadNumMessages], msg, MAX_SIZEOF_RESPONSE_MSG);
    }

    SyncProgressCurrentItem ++ ;
    SyncProgressLoaded = 0;
    SyncUploadNumMessages  ++;

    new_cursor = (uContext->cursor)+1;
    roadmap_file_remove(NULL, uContext->full_path); // remove the previous file

    if( (*new_cursor == NULL )  || ( SyncUploadNumMessages == MAX_MSGS ) ) {
        roadmap_path_list_free(uContext->files);
        roadmap_log(ROADMAP_DEBUG, "finished uploading editor_sync files");

    } else {
        int size;
        const char *header;

        upload_context * new_context;
        new_full_path = roadmap_path_join( editor_sync_get_export_path(), *new_cursor );
        new_context= malloc(sizeof(upload_context));
        new_context->cursor = new_cursor;
        new_context->files = uContext->files;
        new_context->full_path = new_full_path;
        size = roadmap_file_length (NULL, new_full_path);
        header = roadmap_http_async_get_upload_header(DEFAULT_CONTENT_TYPE, new_full_path, size, RealTime_GetUserName(), Realtime_GetPassword());
        if (!roadmap_http_async_post_file(&gUploadCallbackFunctions, (void *)new_context, editor_upload_get_url(), header, new_full_path, size))
        {
            roadmap_log( ROADMAP_ERROR, "File upload error, couldn't start sync socket connect. for file %s ", new_full_path);
            roadmap_path_free(new_full_path);
            roadmap_path_list_free (new_context->files);
            free(new_context);
        }
    }

    roadmap_path_free(uContext->full_path);
    free(uContext);
}
示例#2
0
/*  Name        : roadmap_recorder_voice_uploader()
 *  Purpose     : Upload the voice to the server. Auxiliary static function
 *  Params      : (in) voice_folder
 *  			: (in) voice_file
 *              : (out) voice_id - the string containing the resulting voice ID, received from the server
 *						the input buffer must be of size ROADMAP_VOICE_ID_BUF_LEN
 *              : (out) message - parsed response from the server
 */
static BOOL roadmap_recorder_voice_uploader( const char *voice_folder, const char *voice_file,
        char* voice_id, RecorderVoiceUploadCallback cb, void * context)
{
    BOOL res = FALSE;
    char* full_path;
    const char* target_url;
    upload_context *  ctx;
    int size;
    const char *header;

    if( !voice_id )
    {
        roadmap_log( ROADMAP_ERROR, "File upload error: voice id buffer is not available!!" );
        return FALSE;
    }

    // Get the full path to the file
    full_path = roadmap_path_join( voice_folder, voice_file );

    // Set the target to upload to
    target_url = get_upload_url();

    roadmap_log( ROADMAP_DEBUG, "Uploading file: %s. ", full_path );

    ctx = malloc(sizeof(upload_context));
    ctx->context = context;
    ctx->cb = cb;
    ctx->full_path = full_path;
    ctx->voice_id = voice_id;

    // Upload and get the response
    size = roadmap_file_length (NULL, full_path);
    header = roadmap_http_async_get_upload_header(VOICE_UPLOAD_CONTENT_TYPE, full_path, size, NULL, NULL);
    if (roadmap_http_async_post_file(&gUploadCallbackFunctions, (void *)ctx, target_url, header, full_path, size))
    {
        //change to debug and comment.
        roadmap_log( ROADMAP_DEBUG, "Started Async connection for file : %s", full_path );
        res = TRUE;
    }
    else
    {
        roadmap_log( ROADMAP_WARNING, "File upload error on socket connect %s", full_path );
        roadmap_path_free( full_path );
        free( ctx );
        res = FALSE;
    }

    return res;
}
示例#3
0
static int sync_do_upload () {
    char **files;
    char **cursor;
    const char* directory = editor_sync_get_export_path();
    int count;
    upload_context *  context;
    char * full_path;
    int size;
    const char *header;

    files = roadmap_path_list (directory, ".wud");

    count = 0;
    for (cursor = files; *cursor != NULL; ++cursor) {
        count++;
    }

    //
    cursor = files;
    count = 0;
    //

    context= malloc(sizeof(upload_context));
    context->cursor = cursor;
    context->files = files;
    full_path = roadmap_path_join( directory, *cursor );
    context->full_path = full_path;


    SyncProgressItems = count;
    SyncProgressCurrentItem = 1;
    SyncProgressLoaded = 0;
    SyncUploadNumMessages = 0;

    // this starts the async sending sequence. Further progress is done through the callbacks.
    size = roadmap_file_length (NULL, full_path);
    header = roadmap_http_async_get_upload_header(DEFAULT_CONTENT_TYPE, full_path, size, RealTime_GetUserName(), Realtime_GetPassword());
    if (!roadmap_http_async_post_file(&gUploadCallbackFunctions, (void *)context, editor_upload_get_url(), header, full_path, size))
    {
        roadmap_log( ROADMAP_ERROR, "File upload error, couldn't start sync socket connect. for file %s ", full_path);
//	  roadmap_path_free(full_path);
//	  roadmap_path_list_free (files);
//	  free(context);
        return 0;
    }

    return 1;
}