Changeset 2445

Show
Ignore:
Timestamp:
08/15/07 10:48:55 (1 year ago)
Author:
paule
Message:

Clean up debug messages - replace use of OPIE_DEBUG macro with osync_trace(); fix backup_file to return FALSE on error

Files:

Legend:

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

    r2113 r2445  
    4040#include <opensync/opensync-plugin.h> 
    4141 
    42 #include "opie_debug.h" 
    4342#include "opie_comms.h" 
    4443#include "opie_xml.h" 
     
    9392 */ 
    9493RemoteData *create_temp_file(const char *remote_file, int tmpfilemode) { 
     94        osync_trace(TRACE_ENTRY, "%s(%s, %i)", __func__, remote_file, tmpfilemode); 
     95         
    9596        RemoteData *pair = g_malloc(sizeof(RemoteData)); 
    9697        pair->remote_filename = g_strdup(remote_file); 
     
    105106                        pair->local_fd = open(pair->local_filename, O_RDWR | O_EXCL); 
    106107                if(pair->local_fd == -1) { 
    107                         osync_trace( TRACE_INTERNAL, "failed to open file" ); 
     108                        osync_trace( TRACE_INTERNAL, "failed to open local file %s", pair->local_filename ); 
    108109                } 
    109110        } 
     
    124125        } 
    125126         
     127        osync_trace(TRACE_EXIT, "%s(%p)", __func__, pair); 
    126128        return pair; 
    127129} 
     
    132134 */ 
    133135void cleanup_temp_file(RemoteData *data, int tmpfilemode) { 
     136        osync_trace(TRACE_ENTRY, "%s(%p, %i)", __func__, data, tmpfilemode); 
     137         
    134138        if(tmpfilemode == TT_VISIBLE) { 
    135139                if(unlink(data->local_filename) == -1) { 
     
    142146        g_free(data->local_filename); 
    143147        g_free(data); 
     148 
     149        osync_trace(TRACE_EXIT, "%s", __func__); 
    144150} 
    145151 
     
    149155 */ 
    150156int backup_file(const char *backupfile, int fd) { 
     157        osync_trace(TRACE_ENTRY, "%s(%s, %i)", __func__, backupfile, fd); 
     158         
    151159        int destfd = 0; 
    152         int rc = TRUE; 
     160        int rc = FALSE; 
    153161        int bufsize = 1024; 
    154162        int rbytes, wbytes; 
     
    157165        destfd = open(backupfile, O_CREAT | O_WRONLY | O_EXCL, 0600); 
    158166        if(destfd == -1) { 
     167                osync_trace( TRACE_INTERNAL, "error creating backup file" ); 
    159168                perror("error creating backup file"); 
    160169                goto error; 
     
    168177                rbytes = read(fd, buf, bufsize); 
    169178                if(rbytes == -1) { 
     179                        osync_trace( TRACE_INTERNAL, "error reading during backup" ); 
    170180                        perror("error reading during backup"); 
    171181                        close(destfd); 
     
    175185                        wbytes = write(destfd, buf, rbytes); 
    176186                        if(wbytes == -1) { 
     187                                osync_trace( TRACE_INTERNAL, "error writing to backup file" ); 
    177188                                perror("error writing to backup file"); 
    178189                                close(destfd); 
     
    189200        /* Rewind to start */ 
    190201        lseek(fd, 0, SEEK_SET); 
     202         
     203        rc = TRUE; 
    191204 
    192205error: 
    193206        g_free(buf); 
    194207         
     208        osync_trace(TRACE_EXIT, "%s(%i)", __func__, rc); 
    195209        return rc; 
    196210} 
     
    201215char *create_backup_dir(const char *backupdir) 
    202216{ 
     217        osync_trace(TRACE_ENTRY, "%s(%s)", __func__, backupdir); 
     218         
    203219        time_t currtime; 
    204220        char *backuppath = NULL; 
     
    214230        if(g_mkdir_with_parents(backuppath, 0700)) { 
    215231                perror("error creating backup directory"); 
     232                osync_trace(TRACE_EXIT_ERROR, "error creating backup directory"); 
    216233                goto error; 
    217234        } 
     235         
     236        osync_trace(TRACE_EXIT, "%s", __func__); 
    218237        return backuppath; 
    219238 
     
    240259gboolean opie_fetch_file(OpiePluginEnv *env, OPIE_OBJECT_TYPE objtype, const char *remotefile, xmlDoc **doc, OSyncObjTypeSink *sink) 
    241260{ 
     261        osync_trace(TRACE_ENTRY, "%s(%p, %i, %s, %p, %p)", __func__, env, objtype, remotefile, doc, sink); 
     262         
    242263        gboolean rc = TRUE; 
    243264        int tmpfilemode; 
     
    263284                case OPIE_CONN_NONE: 
    264285                        /* no connection (useful for debugging) */ 
    265                         OPIE_DEBUG("Skipping Connection.\n"); 
     286                        osync_trace( TRACE_INTERNAL, "Skipping Connection" ); 
    266287                        break; 
    267288                         
    268289                case OPIE_CONN_FTP: 
    269290                        /* attempt an FTP connection */ 
    270                         OPIE_DEBUG("Attempting FTP Connection.\n"); 
     291                        osync_trace( TRACE_INTERNAL, "Attempting FTP Connection." ); 
    271292                        if(objtype == OPIE_OBJECT_TYPE_NOTE) { 
    272293                                *doc = opie_xml_create_notes_doc(); 
     
    282303                case OPIE_CONN_SCP: 
    283304                        /* attempt an scp connection */ 
    284                         OPIE_DEBUG("Attempting scp Connection.\n"); 
     305                        osync_trace( TRACE_INTERNAL, "Attempting scp Connection." ); 
    285306                        if(objtype == OPIE_OBJECT_TYPE_NOTE) { 
    286307                                /* FIXME support SCP for notes */ 
    287                                 OPIE_DEBUG("SCP not supported for notes.\n"); 
     308                                osync_trace( TRACE_INTERNAL, "SCP not supported for notes." ); 
    288309                                rc = FALSE; 
    289310                        } 
     
    339360                cleanup_temp_file(data, tmpfilemode); 
    340361         
     362        osync_trace(TRACE_EXIT, "%s(%i)", __func__, rc ); 
    341363        return rc; 
    342364} 
     
    348370gboolean ftp_fetch_file(OpiePluginEnv* env, RemoteData *data) 
    349371{ 
     372        osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, env, data); 
     373         
    350374        gboolean rc = TRUE; 
    351375        char* ftpurl = NULL; 
     
    362386                        if(!root_path) { 
    363387                                fprintf(stderr, "qcop_get_root: %s\n", env->qcopconn->resultmsg); 
     388                                osync_trace(TRACE_EXIT_ERROR, "qcop_get_root: %s", env->qcopconn->resultmsg); 
    364389                                return FALSE; 
    365390                        } 
     
    383408                if(!fd) 
    384409                { 
    385                         OPIE_DEBUG("Failed to open temporary file\n"); 
     410                        osync_trace(TRACE_EXIT_ERROR, "failed to open temporary file"); 
    386411                        g_free(ftpurl); 
    387412                        return FALSE; 
     
    399424#endif 
    400425 
    401                 OPIE_DEBUG(ftpurl); 
    402                 OPIE_DEBUG("\n"); 
     426                osync_trace( TRACE_INTERNAL, "Fetching %s", ftpurl ); 
    403427 
    404428                /* perform the transfer */ 
     
    409433                        /* This is not unlikely (eg. blank device). Note that Opie's FTP 
    410434                                server returns "access denied" on non-existent directory. */ 
    411                         OPIE_DEBUG("FTP file doesn't exist, ignoring\n"); 
     435                        osync_trace( TRACE_INTERNAL, "FTP file doesn't exist, ignoring" ); 
    412436                        /* Close the fd and set it to -1 to indicate the file wasn't there */ 
    413437                        data->local_fd = -1; 
     
    417441                        /* could not get the file */ 
    418442                        fprintf(stderr, "FTP download failed (error %d)\n", res); 
     443                        osync_trace(TRACE_EXIT_ERROR, "FTP download failed (error %d)", res); 
    419444                        return FALSE; 
    420445                } 
    421446                else 
    422447                { 
    423                         OPIE_DEBUG("FTP ok\n"); 
     448                        osync_trace( TRACE_INTERNAL, "FTP ok" ); 
    424449                } 
    425450 
     
    444469        } 
    445470         
    446   return rc;  
     471        osync_trace(TRACE_EXIT, "%s(%i)", __func__, rc); 
     472  return rc; 
    447473} 
    448474 
    449475gboolean ftp_fetch_notes(OpiePluginEnv* env, xmlDoc *doc) 
    450476{ 
     477        osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, env, doc); 
     478         
    451479        gboolean rc = TRUE; 
    452480        char* ftpurl = NULL; 
     
    464492                        if(!root_path) { 
    465493                                fprintf(stderr, "qcop_get_root: %s\n", env->qcopconn->resultmsg); 
     494                                osync_trace(TRACE_EXIT_ERROR, "qcop_get_root: %s", env->qcopconn->resultmsg); 
    466495                                return FALSE; 
    467496                        } 
     
    531560                        /* could not get the file */ 
    532561                        fprintf(stderr, "FTP download failed (error %d)\n", res); 
     562                        osync_trace( TRACE_INTERNAL, "FTP download failed (error %d)", res ); 
    533563                        rc = FALSE; 
    534564                } 
    535565                else 
    536566                { 
    537                         OPIE_DEBUG("FTP ok\n"); 
     567                        osync_trace( TRACE_INTERNAL, "FTP ok" ); 
    538568                } 
    539569 
     
    548578        } 
    549579         
    550   return rc;  
     580        osync_trace(TRACE_EXIT, "%s(%i)", __func__, rc); 
     581  return rc; 
    551582} 
    552583 
    553584gboolean ftp_put_notes(OpiePluginEnv* env, xmlDoc *doc) 
    554585{ 
     586        osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, env, doc); 
     587         
    555588        gboolean rc = TRUE; 
    556589        CURL *curl; 
     
    566599                        if(!root_path) { 
    567600                                fprintf(stderr, "qcop_get_root: %s\n", env->qcopconn->resultmsg); 
     601                                osync_trace(TRACE_EXIT_ERROR, "qcop_get_root: %s", env->qcopconn->resultmsg); 
    568602                                return FALSE; 
    569603                        } 
     
    627661                                        { 
    628662                                                fprintf(stderr, "FTP notes upload failed (error %d)\n", res); 
     663                                                osync_trace( TRACE_INTERNAL, "FTP notes upload failed (error %d)", res ); 
    629664                                                rc = FALSE; 
    630665                                        } 
    631666                                        else 
    632667                                        { 
    633                                                 OPIE_DEBUG("FTP notes upload ok\n"); 
     668                                                osync_trace( TRACE_INTERNAL, "FTP notes upload ok" ); 
    634669                                                rc = TRUE; 
    635670                                        } 
     
    657692        } 
    658693         
    659         return rc;  
     694        osync_trace(TRACE_EXIT, "%s(%i)", __func__, rc); 
     695        return rc; 
    660696} 
    661697 
     
    675711{ 
    676712        osync_trace(TRACE_ENTRY, "%s", __func__ ); 
     713         
    677714        gboolean rc = TRUE; 
    678715        int tmpfilemode; 
     
    710747                        case OPIE_CONN_FTP: 
    711748                                /* attempt an FTP connection */ 
    712                                 OPIE_DEBUG("Attempting FTP Put File.\n"); 
     749                                osync_trace( TRACE_INTERNAL, "Attempting FTP Put File." ); 
    713750                                if(objtype == OPIE_OBJECT_TYPE_NOTE) { 
    714751                                        rc = ftp_put_notes(env, doc); 
     
    721758                        case OPIE_CONN_SCP: 
    722759                                /* attempt and scp connection */ 
    723                                 OPIE_DEBUG("Attempting scp Put File.\n"); 
     760                                osync_trace( TRACE_INTERNAL, "Attempting scp Put File." ); 
    724761                                if(objtype == OPIE_OBJECT_TYPE_NOTE) { 
    725762                                        /* FIXME support SCP for notes */ 
    726                                         OPIE_DEBUG("SCP not supported for notes.\n"); 
     763                                        osync_trace( TRACE_INTERNAL, "SCP not supported for notes." ); 
    727764                                        rc = FALSE; 
    728765                                } 
     
    749786                                /* Run the backup */ 
    750787                                fprintf(stderr, "Error during upload to device, writing file to %s", backupfile);  
     788                                osync_trace( TRACE_INTERNAL, "Error during upload to device, writing file to %s", backupfile ); 
    751789                                rc = backup_file(backupfile, data->local_fd); 
    752790                                g_free(backupfile); 
     
    759797        } 
    760798        else { 
    761                 OPIE_DEBUG("OPIE: No address/todo/calendar changes to write\n"); 
     799                osync_trace(TRACE_INTERNAL, "No address/todo/calendar changes to write", __func__, rc ); 
    762800        } 
    763801         
     
    775813gboolean ftp_put_file(OpiePluginEnv* env, RemoteData *data)  
    776814{ 
     815        osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, env, data); 
     816         
    777817        gboolean rc = TRUE; 
    778818        struct stat file_info; 
     
    789829                        if(!root_path) { 
    790830                                fprintf(stderr, "qcop_get_root: %s\n", env->qcopconn->resultmsg); 
     831                                osync_trace(TRACE_EXIT_ERROR, "qcop_get_root: %s", env->qcopconn->resultmsg); 
    791832                                return FALSE; 
    792833                        } 
     
    829870                        { 
    830871                                fprintf(stderr, "FTP upload failed (error %d)\n", res); 
     872                                osync_trace( TRACE_INTERNAL, "FTP upload failed (error %d)", res ); 
    831873                                rc = FALSE; 
    832874                        }  
    833875                        else 
    834876                        { 
    835                                 OPIE_DEBUG("FTP upload ok\n"); 
     877                                osync_trace( TRACE_INTERNAL, "FTP upload ok" ); 
    836878                                rc = TRUE; 
    837879                        } 
     
    857899        } 
    858900         
     901        osync_trace(TRACE_EXIT, "%s(%i)", __func__, rc ); 
    859902        return rc; 
    860903} 
     
    866909gboolean scp_fetch_file(OpiePluginEnv* env, RemoteData *data) 
    867910{ 
     911        osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, env, data); 
     912         
    868913        gboolean rc = TRUE; 
    869914        char* scpcommand = NULL; 
     
    890935                if((scpretval == -1) || (WEXITSTATUS(scpretval) != 0)) 
    891936                { 
    892                         OPIE_DEBUG("SFTP failed\n"); 
     937                        osync_trace( TRACE_INTERNAL, "SFTP failed" ); 
    893938                        rc = FALSE; 
    894939                } 
    895940                else  
    896941                { 
    897                         OPIE_DEBUG("SFTP ok\n"); 
     942                        osync_trace( TRACE_INTERNAL, "SFTP ok" ); 
    898943                } 
    899944                 
     
    901946                /* reopen the temp file */  
    902947                data->local_fd = open(data->local_filename, O_RDWR | O_EXCL); 
    903         }   
     948        } 
     949         
     950        osync_trace(TRACE_EXIT, "%s(%i)", __func__, rc ); 
    904951        return rc; 
    905952} 
     
    911958gboolean scp_put_file(OpiePluginEnv* env, RemoteData *data) 
    912959{ 
     960        osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, env, data); 
     961         
    913962        gboolean rc = TRUE; 
    914963        char* scpcommand = NULL; 
     
    924973                char* errmsg = g_strdup_printf("SFTP could not create batch file: %s\n", 
    925974                                                                                                                                        strerror(errno)); 
    926                 OPIE_DEBUG(errmsg); 
     975                osync_trace( TRACE_INTERNAL, "%s", errmsg ); 
    927976                g_free(errmsg); 
    928977                rc = FALSE; 
     
    941990                        char* errmsg = g_strdup_printf("SFTP could not write to batch file: %s\n", 
    942991                                                                                                                                                strerror(errno)); 
    943                         OPIE_DEBUG(errmsg); 
     992                        osync_trace( TRACE_INTERNAL, "%s", errmsg ); 
    944993                        g_free(errmsg); 
    945994                        rc = FALSE; 
     
    9631012                        { 
    9641013                                rc = FALSE; 
    965                                 OPIE_DEBUG("SFTP upload failed\n"); 
     1014                                osync_trace( TRACE_INTERNAL, "SFTP upload failed" ); 
    9661015                        } 
    9671016                        else 
    9681017                        { 
    9691018                                rc = TRUE; 
    970                                 OPIE_DEBUG("SFTP upload ok\n"); 
     1019                                osync_trace( TRACE_INTERNAL, "SFTP upload ok" ); 
    9711020                        } 
    9721021 
     
    9761025                                char* errmsg = g_strdup_printf("SFTP could not remove batch file: %s\n", 
    9771026                                                               strerror(errno)); 
    978                                 OPIE_DEBUG(errmsg); 
     1027                                osync_trace( TRACE_INTERNAL, "%s", errmsg ); 
    9791028                                g_free(errmsg); 
    9801029                        } 
     
    9861035        } 
    9871036         
     1037        osync_trace(TRACE_EXIT, "%s(%d)", __func__, rc ); 
    9881038        return rc; 
    9891039} 
  • plugins/opie-sync/src/opie_sync.c

    r2443 r2445  
    294294                 
    295295                char *uid = opie_xml_get_tagged_uid(item_node); 
    296                  
    297296                char *data = xml_node_to_text(env->doc, item_node); 
    298                 printf("OPIE: uid %s\n", uid); 
    299                 printf("OPIE: change xml = %s\n", data); 
    300                  
    301297                unsigned char *hash = hash_xml_node(env->doc, item_node); 
    302298