Changeset 2445
- Timestamp:
- 08/15/07 10:48:55 (1 year ago)
- Files:
-
- plugins/opie-sync/src/opie_comms.c (modified) (48 diffs)
- plugins/opie-sync/src/opie_debug.h (deleted)
- plugins/opie-sync/src/opie_sync.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/opie-sync/src/opie_comms.c
r2113 r2445 40 40 #include <opensync/opensync-plugin.h> 41 41 42 #include "opie_debug.h"43 42 #include "opie_comms.h" 44 43 #include "opie_xml.h" … … 93 92 */ 94 93 RemoteData *create_temp_file(const char *remote_file, int tmpfilemode) { 94 osync_trace(TRACE_ENTRY, "%s(%s, %i)", __func__, remote_file, tmpfilemode); 95 95 96 RemoteData *pair = g_malloc(sizeof(RemoteData)); 96 97 pair->remote_filename = g_strdup(remote_file); … … 105 106 pair->local_fd = open(pair->local_filename, O_RDWR | O_EXCL); 106 107 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 ); 108 109 } 109 110 } … … 124 125 } 125 126 127 osync_trace(TRACE_EXIT, "%s(%p)", __func__, pair); 126 128 return pair; 127 129 } … … 132 134 */ 133 135 void cleanup_temp_file(RemoteData *data, int tmpfilemode) { 136 osync_trace(TRACE_ENTRY, "%s(%p, %i)", __func__, data, tmpfilemode); 137 134 138 if(tmpfilemode == TT_VISIBLE) { 135 139 if(unlink(data->local_filename) == -1) { … … 142 146 g_free(data->local_filename); 143 147 g_free(data); 148 149 osync_trace(TRACE_EXIT, "%s", __func__); 144 150 } 145 151 … … 149 155 */ 150 156 int backup_file(const char *backupfile, int fd) { 157 osync_trace(TRACE_ENTRY, "%s(%s, %i)", __func__, backupfile, fd); 158 151 159 int destfd = 0; 152 int rc = TRUE;160 int rc = FALSE; 153 161 int bufsize = 1024; 154 162 int rbytes, wbytes; … … 157 165 destfd = open(backupfile, O_CREAT | O_WRONLY | O_EXCL, 0600); 158 166 if(destfd == -1) { 167 osync_trace( TRACE_INTERNAL, "error creating backup file" ); 159 168 perror("error creating backup file"); 160 169 goto error; … … 168 177 rbytes = read(fd, buf, bufsize); 169 178 if(rbytes == -1) { 179 osync_trace( TRACE_INTERNAL, "error reading during backup" ); 170 180 perror("error reading during backup"); 171 181 close(destfd); … … 175 185 wbytes = write(destfd, buf, rbytes); 176 186 if(wbytes == -1) { 187 osync_trace( TRACE_INTERNAL, "error writing to backup file" ); 177 188 perror("error writing to backup file"); 178 189 close(destfd); … … 189 200 /* Rewind to start */ 190 201 lseek(fd, 0, SEEK_SET); 202 203 rc = TRUE; 191 204 192 205 error: 193 206 g_free(buf); 194 207 208 osync_trace(TRACE_EXIT, "%s(%i)", __func__, rc); 195 209 return rc; 196 210 } … … 201 215 char *create_backup_dir(const char *backupdir) 202 216 { 217 osync_trace(TRACE_ENTRY, "%s(%s)", __func__, backupdir); 218 203 219 time_t currtime; 204 220 char *backuppath = NULL; … … 214 230 if(g_mkdir_with_parents(backuppath, 0700)) { 215 231 perror("error creating backup directory"); 232 osync_trace(TRACE_EXIT_ERROR, "error creating backup directory"); 216 233 goto error; 217 234 } 235 236 osync_trace(TRACE_EXIT, "%s", __func__); 218 237 return backuppath; 219 238 … … 240 259 gboolean opie_fetch_file(OpiePluginEnv *env, OPIE_OBJECT_TYPE objtype, const char *remotefile, xmlDoc **doc, OSyncObjTypeSink *sink) 241 260 { 261 osync_trace(TRACE_ENTRY, "%s(%p, %i, %s, %p, %p)", __func__, env, objtype, remotefile, doc, sink); 262 242 263 gboolean rc = TRUE; 243 264 int tmpfilemode; … … 263 284 case OPIE_CONN_NONE: 264 285 /* no connection (useful for debugging) */ 265 OPIE_DEBUG("Skipping Connection.\n");286 osync_trace( TRACE_INTERNAL, "Skipping Connection" ); 266 287 break; 267 288 268 289 case OPIE_CONN_FTP: 269 290 /* attempt an FTP connection */ 270 OPIE_DEBUG("Attempting FTP Connection.\n");291 osync_trace( TRACE_INTERNAL, "Attempting FTP Connection." ); 271 292 if(objtype == OPIE_OBJECT_TYPE_NOTE) { 272 293 *doc = opie_xml_create_notes_doc(); … … 282 303 case OPIE_CONN_SCP: 283 304 /* attempt an scp connection */ 284 OPIE_DEBUG("Attempting scp Connection.\n");305 osync_trace( TRACE_INTERNAL, "Attempting scp Connection." ); 285 306 if(objtype == OPIE_OBJECT_TYPE_NOTE) { 286 307 /* FIXME support SCP for notes */ 287 OPIE_DEBUG("SCP not supported for notes.\n");308 osync_trace( TRACE_INTERNAL, "SCP not supported for notes." ); 288 309 rc = FALSE; 289 310 } … … 339 360 cleanup_temp_file(data, tmpfilemode); 340 361 362 osync_trace(TRACE_EXIT, "%s(%i)", __func__, rc ); 341 363 return rc; 342 364 } … … 348 370 gboolean ftp_fetch_file(OpiePluginEnv* env, RemoteData *data) 349 371 { 372 osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, env, data); 373 350 374 gboolean rc = TRUE; 351 375 char* ftpurl = NULL; … … 362 386 if(!root_path) { 363 387 fprintf(stderr, "qcop_get_root: %s\n", env->qcopconn->resultmsg); 388 osync_trace(TRACE_EXIT_ERROR, "qcop_get_root: %s", env->qcopconn->resultmsg); 364 389 return FALSE; 365 390 } … … 383 408 if(!fd) 384 409 { 385 OPIE_DEBUG("Failed to open temporary file\n");410 osync_trace(TRACE_EXIT_ERROR, "failed to open temporary file"); 386 411 g_free(ftpurl); 387 412 return FALSE; … … 399 424 #endif 400 425 401 OPIE_DEBUG(ftpurl); 402 OPIE_DEBUG("\n"); 426 osync_trace( TRACE_INTERNAL, "Fetching %s", ftpurl ); 403 427 404 428 /* perform the transfer */ … … 409 433 /* This is not unlikely (eg. blank device). Note that Opie's FTP 410 434 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" ); 412 436 /* Close the fd and set it to -1 to indicate the file wasn't there */ 413 437 data->local_fd = -1; … … 417 441 /* could not get the file */ 418 442 fprintf(stderr, "FTP download failed (error %d)\n", res); 443 osync_trace(TRACE_EXIT_ERROR, "FTP download failed (error %d)", res); 419 444 return FALSE; 420 445 } 421 446 else 422 447 { 423 OPIE_DEBUG("FTP ok\n");448 osync_trace( TRACE_INTERNAL, "FTP ok" ); 424 449 } 425 450 … … 444 469 } 445 470 446 return rc; 471 osync_trace(TRACE_EXIT, "%s(%i)", __func__, rc); 472 return rc; 447 473 } 448 474 449 475 gboolean ftp_fetch_notes(OpiePluginEnv* env, xmlDoc *doc) 450 476 { 477 osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, env, doc); 478 451 479 gboolean rc = TRUE; 452 480 char* ftpurl = NULL; … … 464 492 if(!root_path) { 465 493 fprintf(stderr, "qcop_get_root: %s\n", env->qcopconn->resultmsg); 494 osync_trace(TRACE_EXIT_ERROR, "qcop_get_root: %s", env->qcopconn->resultmsg); 466 495 return FALSE; 467 496 } … … 531 560 /* could not get the file */ 532 561 fprintf(stderr, "FTP download failed (error %d)\n", res); 562 osync_trace( TRACE_INTERNAL, "FTP download failed (error %d)", res ); 533 563 rc = FALSE; 534 564 } 535 565 else 536 566 { 537 OPIE_DEBUG("FTP ok\n");567 osync_trace( TRACE_INTERNAL, "FTP ok" ); 538 568 } 539 569 … … 548 578 } 549 579 550 return rc; 580 osync_trace(TRACE_EXIT, "%s(%i)", __func__, rc); 581 return rc; 551 582 } 552 583 553 584 gboolean ftp_put_notes(OpiePluginEnv* env, xmlDoc *doc) 554 585 { 586 osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, env, doc); 587 555 588 gboolean rc = TRUE; 556 589 CURL *curl; … … 566 599 if(!root_path) { 567 600 fprintf(stderr, "qcop_get_root: %s\n", env->qcopconn->resultmsg); 601 osync_trace(TRACE_EXIT_ERROR, "qcop_get_root: %s", env->qcopconn->resultmsg); 568 602 return FALSE; 569 603 } … … 627 661 { 628 662 fprintf(stderr, "FTP notes upload failed (error %d)\n", res); 663 osync_trace( TRACE_INTERNAL, "FTP notes upload failed (error %d)", res ); 629 664 rc = FALSE; 630 665 } 631 666 else 632 667 { 633 OPIE_DEBUG("FTP notes upload ok\n");668 osync_trace( TRACE_INTERNAL, "FTP notes upload ok" ); 634 669 rc = TRUE; 635 670 } … … 657 692 } 658 693 659 return rc; 694 osync_trace(TRACE_EXIT, "%s(%i)", __func__, rc); 695 return rc; 660 696 } 661 697 … … 675 711 { 676 712 osync_trace(TRACE_ENTRY, "%s", __func__ ); 713 677 714 gboolean rc = TRUE; 678 715 int tmpfilemode; … … 710 747 case OPIE_CONN_FTP: 711 748 /* attempt an FTP connection */ 712 OPIE_DEBUG("Attempting FTP Put File.\n");749 osync_trace( TRACE_INTERNAL, "Attempting FTP Put File." ); 713 750 if(objtype == OPIE_OBJECT_TYPE_NOTE) { 714 751 rc = ftp_put_notes(env, doc); … … 721 758 case OPIE_CONN_SCP: 722 759 /* attempt and scp connection */ 723 OPIE_DEBUG("Attempting scp Put File.\n");760 osync_trace( TRACE_INTERNAL, "Attempting scp Put File." ); 724 761 if(objtype == OPIE_OBJECT_TYPE_NOTE) { 725 762 /* FIXME support SCP for notes */ 726 OPIE_DEBUG("SCP not supported for notes.\n");763 osync_trace( TRACE_INTERNAL, "SCP not supported for notes." ); 727 764 rc = FALSE; 728 765 } … … 749 786 /* Run the backup */ 750 787 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 ); 751 789 rc = backup_file(backupfile, data->local_fd); 752 790 g_free(backupfile); … … 759 797 } 760 798 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 ); 762 800 } 763 801 … … 775 813 gboolean ftp_put_file(OpiePluginEnv* env, RemoteData *data) 776 814 { 815 osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, env, data); 816 777 817 gboolean rc = TRUE; 778 818 struct stat file_info; … … 789 829 if(!root_path) { 790 830 fprintf(stderr, "qcop_get_root: %s\n", env->qcopconn->resultmsg); 831 osync_trace(TRACE_EXIT_ERROR, "qcop_get_root: %s", env->qcopconn->resultmsg); 791 832 return FALSE; 792 833 } … … 829 870 { 830 871 fprintf(stderr, "FTP upload failed (error %d)\n", res); 872 osync_trace( TRACE_INTERNAL, "FTP upload failed (error %d)", res ); 831 873 rc = FALSE; 832 874 } 833 875 else 834 876 { 835 OPIE_DEBUG("FTP upload ok\n");877 osync_trace( TRACE_INTERNAL, "FTP upload ok" ); 836 878 rc = TRUE; 837 879 } … … 857 899 } 858 900 901 osync_trace(TRACE_EXIT, "%s(%i)", __func__, rc ); 859 902 return rc; 860 903 } … … 866 909 gboolean scp_fetch_file(OpiePluginEnv* env, RemoteData *data) 867 910 { 911 osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, env, data); 912 868 913 gboolean rc = TRUE; 869 914 char* scpcommand = NULL; … … 890 935 if((scpretval == -1) || (WEXITSTATUS(scpretval) != 0)) 891 936 { 892 OPIE_DEBUG("SFTP failed\n");937 osync_trace( TRACE_INTERNAL, "SFTP failed" ); 893 938 rc = FALSE; 894 939 } 895 940 else 896 941 { 897 OPIE_DEBUG("SFTP ok\n");942 osync_trace( TRACE_INTERNAL, "SFTP ok" ); 898 943 } 899 944 … … 901 946 /* reopen the temp file */ 902 947 data->local_fd = open(data->local_filename, O_RDWR | O_EXCL); 903 } 948 } 949 950 osync_trace(TRACE_EXIT, "%s(%i)", __func__, rc ); 904 951 return rc; 905 952 } … … 911 958 gboolean scp_put_file(OpiePluginEnv* env, RemoteData *data) 912 959 { 960 osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, env, data); 961 913 962 gboolean rc = TRUE; 914 963 char* scpcommand = NULL; … … 924 973 char* errmsg = g_strdup_printf("SFTP could not create batch file: %s\n", 925 974 strerror(errno)); 926 OPIE_DEBUG(errmsg);975 osync_trace( TRACE_INTERNAL, "%s", errmsg ); 927 976 g_free(errmsg); 928 977 rc = FALSE; … … 941 990 char* errmsg = g_strdup_printf("SFTP could not write to batch file: %s\n", 942 991 strerror(errno)); 943 OPIE_DEBUG(errmsg);992 osync_trace( TRACE_INTERNAL, "%s", errmsg ); 944 993 g_free(errmsg); 945 994 rc = FALSE; … … 963 1012 { 964 1013 rc = FALSE; 965 OPIE_DEBUG("SFTP upload failed\n");1014 osync_trace( TRACE_INTERNAL, "SFTP upload failed" ); 966 1015 } 967 1016 else 968 1017 { 969 1018 rc = TRUE; 970 OPIE_DEBUG("SFTP upload ok\n");1019 osync_trace( TRACE_INTERNAL, "SFTP upload ok" ); 971 1020 } 972 1021 … … 976 1025 char* errmsg = g_strdup_printf("SFTP could not remove batch file: %s\n", 977 1026 strerror(errno)); 978 OPIE_DEBUG(errmsg);1027 osync_trace( TRACE_INTERNAL, "%s", errmsg ); 979 1028 g_free(errmsg); 980 1029 } … … 986 1035 } 987 1036 1037 osync_trace(TRACE_EXIT, "%s(%d)", __func__, rc ); 988 1038 return rc; 989 1039 } plugins/opie-sync/src/opie_sync.c
r2443 r2445 294 294 295 295 char *uid = opie_xml_get_tagged_uid(item_node); 296 297 296 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 301 297 unsigned char *hash = hash_xml_node(env->doc, item_node); 302 298
