Changeset 2478
- Timestamp:
- 08/20/07 11:12:12 (1 year ago)
- Files:
-
- plugins/opie-sync/src/opie-sync (modified) (1 diff)
- plugins/opie-sync/src/opie_comms.c (modified) (19 diffs)
- plugins/opie-sync/src/opie_sync.c (modified) (4 diffs)
- plugins/opie-sync/src/opie_sync.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/opie-sync/src/opie-sync
r2476 r2478 7 7 <port>4242</port> 8 8 <conntype>ftp</conntype> 9 <notestype>basic</notestype> 9 10 </config> plugins/opie-sync/src/opie_comms.c
r2476 r2478 230 230 return NULL; 231 231 } 232 233 234 char *get_remote_notes_path(OpiePluginEnv *env) 235 { 236 osync_trace(TRACE_ENTRY, "%s(%p)", __func__, env); 237 char* root_path; 238 239 if ( env->use_qcop ) { 240 root_path = qcop_get_root(env->qcopconn); 241 if(!root_path) { 242 fprintf(stderr, "qcop_get_root: %s\n", env->qcopconn->resultmsg); 243 osync_trace(TRACE_EXIT_ERROR, "qcop_get_root: %s", env->qcopconn->resultmsg); 244 return NULL; 245 } 246 osync_trace( TRACE_INTERNAL, "QCop root path = %s", root_path ); 247 } 248 else 249 root_path = g_strdup( "" ); 250 251 char *notes_path; 252 if(env->notes_type == NOTES_TYPE_OPIE_NOTES) 253 notes_path = g_build_filename(root_path, "Documents/text/plain", NULL); 254 else 255 notes_path = g_strdup(root_path); 256 257 g_free(root_path); 258 259 osync_trace(TRACE_EXIT, "%s(%s)", __func__, notes_path); 260 return notes_path; 261 } 262 232 263 233 264 … … 647 678 if (env->host && env->username && env->password ) 648 679 { 649 char* separator_path; 650 if ( env->use_qcop ) 651 { 652 char* root_path = qcop_get_root(env->qcopconn); 653 if(!root_path) { 654 fprintf(stderr, "qcop_get_root: %s\n", env->qcopconn->resultmsg); 655 osync_trace(TRACE_EXIT_ERROR, "qcop_get_root: %s", env->qcopconn->resultmsg); 656 return FALSE; 657 } 658 osync_trace( TRACE_INTERNAL, "QCop root path = %s", root_path ); 659 separator_path = g_strdup_printf("%s/", root_path); 660 g_free(root_path); 661 } else { 662 separator_path = g_strdup( "/" ); 663 } 664 665 ftpurl = g_strdup_printf("ftp://%s:%s@%s:%u%s", 680 char *remotepath = get_remote_notes_path(env); 681 if(!remotepath) { 682 osync_trace(TRACE_EXIT_ERROR, "%s: failed to get remote notes path", __func__); 683 return FALSE; 684 } 685 686 ftpurl = g_strdup_printf("ftp://%s:%s@%s:%u%s/", 666 687 env->username, 667 688 env->password, 668 689 env->host, 669 690 env->device_port, 670 separator_path);691 remotepath); 671 692 672 693 /* curl init */ … … 677 698 curl_easy_setopt(curl, CURLOPT_WRITEDATA, bufstr); 678 699 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, opie_curl_strwrite); 700 701 osync_trace(TRACE_INTERNAL, "retrieving directory: %s", ftpurl); 679 702 680 703 /* get the dir listing */ … … 694 717 GString *bufstr = g_string_new(""); 695 718 char *ftpfileurl = g_strdup_printf("%s/%s", ftpurl, ptr); 719 osync_trace(TRACE_INTERNAL, "retrieving file: %s", ftpfileurl); 696 720 curl_easy_setopt(curl, CURLOPT_URL, ftpfileurl); 697 721 curl_easy_setopt(curl, CURLOPT_WRITEDATA, bufstr); 698 722 res = curl_easy_perform(curl); 723 osync_trace(TRACE_INTERNAL, "done retrieving, result = %i", res); 699 724 g_free(ftpfileurl); 700 725 /* Remove .txt from end of file name */ … … 731 756 g_free(ftpurl); 732 757 curl_easy_cleanup(curl); 733 g_free( separator_path);758 g_free(remotepath); 734 759 } 735 760 else … … 750 775 CURL *curl; 751 776 CURLcode res; 752 char* separator_path;753 777 char *ftpurl; 754 778 755 779 if (env->host && env->username && env->password ) 756 780 { 757 if ( env->use_qcop ) 758 { 759 char* root_path = qcop_get_root(env->qcopconn); 760 if(!root_path) { 761 fprintf(stderr, "qcop_get_root: %s\n", env->qcopconn->resultmsg); 762 osync_trace(TRACE_EXIT_ERROR, "qcop_get_root: %s", env->qcopconn->resultmsg); 763 return FALSE; 764 } 765 osync_trace( TRACE_INTERNAL, "QCop root path = %s", root_path ); 766 separator_path = g_strdup_printf("%s/", root_path); 767 g_free(root_path); 768 } else { 769 separator_path = g_strdup( "/" ); 770 } 771 781 char *remotepath = get_remote_notes_path(env); 782 if(!remotepath) { 783 osync_trace(TRACE_EXIT_ERROR, "%s: failed to get remote notes path", __func__); 784 return FALSE; 785 } 786 772 787 xmlNode *node = opie_xml_get_first(doc, "notes", "note"); 773 788 while(node) { … … 790 805 env->host, 791 806 env->device_port, 792 separator_path);807 remotepath); 793 808 794 809 struct curl_slist *cmdlist = NULL; 795 char *command = g_strdup_printf("DELE %s %s.txt", separator_path, notename);810 char *command = g_strdup_printf("DELE %s/%s.txt", remotepath, notename); 796 811 cmdlist = curl_slist_append(cmdlist, command); 797 812 curl_easy_setopt(curl, CURLOPT_QUOTE, cmdlist); … … 800 815 else { 801 816 /* Changed note, upload it */ 802 ftpurl = g_strdup_printf("ftp://%s:%s@%s:%u%s %s.txt",817 ftpurl = g_strdup_printf("ftp://%s:%s@%s:%u%s/%s.txt", 803 818 env->username, 804 819 env->password, 805 820 env->host, 806 821 env->device_port, 807 separator_path,822 remotepath, 808 823 notename); 809 824 … … 845 860 } 846 861 847 g_free( separator_path);862 g_free(remotepath); 848 863 } 849 864 else … … 1002 1017 curl_easy_setopt(curl, CURLOPT_READDATA, data); 1003 1018 curl_easy_setopt(curl, CURLOPT_READFUNCTION, opie_curl_strread); 1004 1019 m_totalwritten = 0; 1005 1020 1006 1021 curl_easy_setopt(curl, CURLOPT_FTP_CREATE_MISSING_DIRS, 1); … … 1233 1248 char* scpcommand = NULL; 1234 1249 int scpretval, scpexitstatus; 1250 char *remotepath = NULL; 1235 1251 1236 1252 if(env->host && env->device_port && env->username) { 1237 char* separator_path; 1238 if ( env->use_qcop ) 1239 { 1240 char* root_path = qcop_get_root(env->qcopconn); 1241 if(!root_path) { 1242 fprintf(stderr, "qcop_get_root: %s\n", env->qcopconn->resultmsg); 1243 osync_trace(TRACE_EXIT_ERROR, "qcop_get_root: %s", env->qcopconn->resultmsg); 1244 return FALSE; 1245 } 1246 osync_trace( TRACE_INTERNAL, "QCop root path = %s", root_path ); 1247 separator_path = g_strdup_printf("%s/", root_path); 1248 g_free(root_path); 1249 } else { 1250 separator_path = g_strdup( "/" ); 1253 remotepath = get_remote_notes_path(env); 1254 if(!remotepath) { 1255 osync_trace(TRACE_EXIT_ERROR, "%s: failed to get remote notes path", __func__); 1256 return FALSE; 1251 1257 } 1252 1258 1253 1259 /* Create a temp directory */ 1254 char *randstr = g_strdup_printf("opie-sync-%i", g_random_int_range(0, G_MAXUINT32));1260 char *randstr = g_strdup_printf("opie-sync-%i", g_random_int_range(0, 2000000000)); 1255 1261 char *temppath = g_build_filename(g_get_tmp_dir(), randstr); 1256 1262 g_free(randstr); … … 1266 1272 this with scp unfortunately because scp seems to return 1 1267 1273 on any error */ 1268 scpcommand = g_strdup_printf("ssh -o BatchMode=yes %s@%s \"ls %s *.txt > /dev/null\"",1274 scpcommand = g_strdup_printf("ssh -o BatchMode=yes %s@%s \"ls %s/*.txt > /dev/null\"", 1269 1275 env->username, 1270 1276 env->host, 1271 separator_path);1277 remotepath); 1272 1278 1273 1279 scpretval = pclose(popen(scpcommand,"w")); … … 1283 1289 1284 1290 /* Fetch all text files from the remote path into the temp directory */ 1285 scpcommand = g_strdup_printf("scp -p -q -B %s@%s:%s *.txt %s",1291 scpcommand = g_strdup_printf("scp -p -q -B %s@%s:%s/*.txt %s", 1286 1292 env->username, 1287 1293 env->host, 1288 separator_path,1294 remotepath, 1289 1295 temppath); 1290 1296 … … 1315 1321 if(scpcommand); 1316 1322 g_free(scpcommand); 1323 1324 if(remotepath) 1325 g_free(remotepath); 1317 1326 1318 1327 osync_trace(TRACE_EXIT, "%s(%i)", __func__, rc ); … … 1331 1340 int scpretval, scpexitstatus; 1332 1341 char *temppath = NULL; 1333 char * separator_path = NULL;1342 char *remotepath = NULL; 1334 1343 1335 1344 if(env->host && env->device_port && env->username) { 1336 if ( env->use_qcop ) 1337 { 1338 char* root_path = qcop_get_root(env->qcopconn); 1339 if(!root_path) { 1340 fprintf(stderr, "qcop_get_root: %s\n", env->qcopconn->resultmsg); 1341 osync_trace(TRACE_EXIT_ERROR, "qcop_get_root: %s", env->qcopconn->resultmsg); 1342 return FALSE; 1343 } 1344 osync_trace( TRACE_INTERNAL, "QCop root path = %s", root_path ); 1345 separator_path = g_strdup_printf("%s/", root_path); 1346 g_free(root_path); 1347 } else { 1348 separator_path = g_strdup( "/" ); 1345 remotepath = get_remote_notes_path(env); 1346 if(!remotepath) { 1347 osync_trace(TRACE_EXIT_ERROR, "%s: failed to get remote notes path", __func__); 1348 return FALSE; 1349 1349 } 1350 1350 … … 1368 1368 1369 1369 /* create remote path */ 1370 scpcommand = g_strdup_printf("ssh -o BatchMode=yes %s@%s \"mkdir -p %s \"",1370 scpcommand = g_strdup_printf("ssh -o BatchMode=yes %s@%s \"mkdir -p %s/\"", 1371 1371 env->username, 1372 1372 env->host, 1373 separator_path);1373 remotepath); 1374 1374 1375 1375 scpretval = pclose(popen(scpcommand,"w")); … … 1388 1388 env->username, 1389 1389 env->host, 1390 separator_path);1390 remotepath); 1391 1391 1392 1392 scpretval = pclose(popen(scpcommand,"w")); … … 1423 1423 if(deletedfiles->len > 0) { 1424 1424 g_free(scpcommand); 1425 scpcommand = g_strdup_printf("ssh -o BatchMode=yes %s@%s \"cd %s && rm -f %s\"",1425 scpcommand = g_strdup_printf("ssh -o BatchMode=yes %s@%s \"cd %s/ && rm -f %s\"", 1426 1426 env->username, 1427 1427 env->host, 1428 separator_path,1428 remotepath, 1429 1429 deletedfiles->str); 1430 1430 … … 1451 1451 } 1452 1452 1453 if( separator_path)1454 g_free( separator_path);1453 if(remotepath) 1454 g_free(remotepath); 1455 1455 1456 1456 if(scpcommand); plugins/opie-sync/src/opie_sync.c
r2476 r2478 61 61 env->backupdir = NULL; 62 62 env->localdir = g_strdup("/tmp"); 63 env->notes_type = NOTES_TYPE_BASIC; 63 64 64 65 doc = xmlParseMemory(config, strlen(config)); … … 125 126 g_free(env->localdir); 126 127 env->localdir = g_strdup(str); 128 } else if (!xmlStrcmp(cur->name, (const xmlChar *)"notestype")) { 129 if ( (!strcasecmp(str, "opie-notes")) || (!strcasecmp(str, "opie_notes")) ) 130 env->notes_type = NOTES_TYPE_OPIE_NOTES; 131 else if ( strcasecmp(str, "basic") == 0 ) 132 env->notes_type = NOTES_TYPE_BASIC; 133 else { 134 osync_error_set(error, OSYNC_ERROR_GENERIC, "Invalid value \"%s\" for configuration option \"%s\"", str, cur->name); 135 goto error_free_doc; 136 } 127 137 } else { 128 138 osync_error_set(error, OSYNC_ERROR_GENERIC, "Invalid configuration file option \"%s\"", cur->name); … … 275 285 goto error; 276 286 287 if(env->objtype == OPIE_OBJECT_TYPE_NOTE) { 288 /* Check if the notestype config option has changed since the last sync */ 289 char *anchorpath = g_strdup_printf("%s/anchor.db", osync_plugin_info_get_configdir(info)); 290 char *notes_type_str = g_strdup_printf("%d", env->plugin_env->notes_type); 291 if (!osync_anchor_compare(anchorpath, "notestype", notes_type_str)) 292 osync_objtype_sink_set_slowsync(sink, TRUE); 293 g_free(notes_type_str); 294 g_free(anchorpath); 295 } 296 277 297 osync_context_report_success(ctx); 278 298 osync_trace(TRACE_EXIT, "%s", __func__); … … 532 552 } 533 553 554 if(env->objtype == OPIE_OBJECT_TYPE_NOTE) { 555 char *anchorpath = g_strdup_printf("%s/anchor.db", osync_plugin_info_get_configdir(info)); 556 char *notes_type_str = g_strdup_printf("%d", env->plugin_env->notes_type); 557 osync_anchor_update(anchorpath, "notestype", notes_type_str); 558 g_free(notes_type_str); 559 g_free(anchorpath); 560 } 561 534 562 osync_context_report_success(ctx); 535 563 osync_trace(TRACE_EXIT, "%s", __func__); plugins/opie-sync/src/opie_sync.h
r2476 r2478 50 50 51 51 typedef enum { 52 NOTES_TYPE_OPIE_NOTES, 53 NOTES_TYPE_BASIC 54 } OPIE_NOTES_TYPE; 55 56 typedef enum { 52 57 OPIE_OBJECT_TYPE_UNKNOWN, 53 58 OPIE_OBJECT_TYPE_CONTACT, … … 69 74 gchar* backuppath; /* the full path to the backup dir for this session */ 70 75 gchar* localdir; /* path to local files if conntype = OPIE_CONN_NONE (for debugging) */ 76 OPIE_NOTES_TYPE notes_type; 71 77 72 78 gboolean use_qcop;
