Changeset 2463

Show
Ignore:
Timestamp:
08/17/07 17:10:54 (1 year ago)
Author:
paule
Message:

Re-enable debugging with local files (conntype = none)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/opie-sync/src/opie_comms.c

    r2461 r2463  
    3232#include <errno.h> 
    3333 
     34#include <glib.h> 
     35#include <glib/gstdio.h> 
     36 
    3437#include <curl/curl.h> 
    3538#include <curl/types.h> 
     
    4851int opie_curl_nullwrite(void *buffer, size_t size, size_t nmemb, void *stream); 
    4952int opie_curl_strread(void *buffer, size_t size, size_t nmemb, void *stream); 
     53gboolean local_fetch_file(OpiePluginEnv* env, const char *remotefile, GString **data); 
    5054gboolean ftp_fetch_file(OpiePluginEnv* env, const char *remotefile, GString **data); 
    5155gboolean scp_fetch_file(OpiePluginEnv* env, const char *remotefile, GString **data); 
     56gboolean local_put_file(OpiePluginEnv* env, const char *remotefile, const char *data); 
    5257gboolean ftp_put_file(OpiePluginEnv* env, const char *remotefile, char *data); 
    5358gboolean scp_put_file(OpiePluginEnv* env, const char *remotefile, char *data); 
     
    182187        { 
    183188                case OPIE_CONN_NONE: 
    184                         /* no connection (useful for debugging) */ 
    185                         osync_trace( TRACE_INTERNAL, "Skipping Connection" ); 
     189                        /* Read from local file (for debugging) */ 
     190                        osync_trace( TRACE_INTERNAL, "Fetching local file" ); 
     191                        if(objtype == OPIE_OBJECT_TYPE_NOTE) { 
     192                                /* FIXME enable notes debugging */ 
     193                        } 
     194                        else 
     195                                rc = local_fetch_file(env, remotefile, &data); 
     196                         
    186197                        break; 
    187198                         
     
    259270        if(data) 
    260271                g_string_free(data, TRUE); 
     272         
     273        osync_trace(TRACE_EXIT, "%s(%i)", __func__, rc ); 
     274        return rc; 
     275} 
     276 
     277/* 
     278 * Fetch a file from disk (don't fail if file doesn't exist) 
     279 */ 
     280gboolean local_fetch_file(OpiePluginEnv* env, const char *remotefile, GString **data) 
     281{ 
     282        osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, env, data); 
     283         
     284        char *basename = g_path_get_basename(remotefile); 
     285        char *localfile = g_strdup_printf("/tmp/%s", basename); 
     286        gboolean rc; 
     287         
     288        if(g_access(localfile, F_OK) == 0) { 
     289                OSyncError *error = NULL; 
     290                int len = 0; 
     291                char *str = NULL;  
     292                rc = osync_file_read(localfile, &str, &len, &error); 
     293                *data = g_string_new_len(str, len); 
     294                free(str); 
     295        } 
     296        else { 
     297                *data = NULL; 
     298                rc = TRUE; 
     299        } 
     300         
     301        osync_trace(TRACE_EXIT, "%s(%i)", __func__, rc ); 
     302        return rc; 
     303} 
     304 
     305/* 
     306 * Write a file to disk 
     307 */ 
     308gboolean local_put_file(OpiePluginEnv* env, const char *remotefile, const char *data) 
     309{ 
     310        osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, env, data); 
     311         
     312        char *basename = g_path_get_basename(remotefile); 
     313        char *localfile = g_strdup_printf("/tmp/%s", basename); 
     314        gboolean rc; 
     315         
     316        OSyncError *error = NULL; 
     317        rc = osync_file_write(localfile, data, strlen(data), 0660, &error); 
    261318         
    262319        osync_trace(TRACE_EXIT, "%s(%i)", __func__, rc ); 
     
    610667                { 
    611668                        case OPIE_CONN_NONE: 
    612                                 /* Do nothing */ 
    613                                 osync_trace(TRACE_INTERNAL, "Skipping Put" ); 
     669                                /* Write to local file (for debugging) */ 
     670                                osync_trace(TRACE_INTERNAL, "Writing local file" ); 
     671                                if(objtype == OPIE_OBJECT_TYPE_NOTE) { 
     672                                        /* FIXME enable notes debugging */ 
     673                                } 
     674                                else  
     675                                        local_put_file(env, remotefile, data); 
     676                         
    614677                                break; 
    615678