Changeset 2521
- Timestamp:
- 09/11/07 01:58:48 (1 year ago)
- Files:
-
- plugins/gpe/src/gpe-sync (modified) (2 diffs)
- plugins/gpe/src/gpe_sync.c (modified) (1 diff)
- plugins/gpe/src/gpe_sync.h (modified) (2 diffs)
- plugins/gpe/src/gpe_xml.c (modified) (3 diffs)
- plugins/gpe/src/gpesync_client.c (modified) (7 diffs)
- plugins/gpe/src/gpesync_client.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/gpe/src/gpe-sync
r2516 r2521 3 3 4 4 1) You can use gpesyncd locally (if opensync is running 5 on the same system) by specifying :5 on the same system) by specifying the <local>...</local> option. 6 6 7 <use_local>1</use_local>8 <use_ssh>0</use_ssh>7 In this case you can specify <command>shell command</command> 8 to change the shell command which is invoked. 9 9 10 In this case, no other tags are used.10 Specifying the <command> tag is not recommended. 11 11 12 2) You can use SSH to connect to the device by specifying: 12 2) You can use SSH to connect to the device by specifying the 13 <ssh>...<ssh> option. 13 14 14 <use_local>0</use_local> 15 <use_ssh>1</use_ssh> 16 17 In this case, the <handheld_ip> and <handheld_user> tags are used. 15 In this case, the <handheld_ip>, <handheld_user> and <command> 16 tags can be used. 18 17 19 18 Note that the handheld_ip can be a name or an address and may be … … 24 23 should be specified as "user". 25 24 26 3) You can connect to a running gpesyncd daemon by specifying:25 Specifying the <command> tag is not recommended. 27 26 28 <use_local>0</use_local>29 < use_ssh>0</use_ssh>27 3) You can connect to a running gpesyncd daemon by specifying the 28 <remote>...</remote> option. 30 29 31 30 In this case, the <handheld_ip> and <handheld_port> tags are used. 32 31 32 Either use the <ssh> configuration shown below or remove it and uncomment 33 one of the other sections. Each section is configured to show the default values 34 used if the tags are not specified. 33 35 --> 34 <!-- All tags are set to their default values below --> 35 <use_local>0</use_local> 36 <use_ssh>1</use_ssh> 37 <handheld_ip>127.0.0.1</handheld_ip> 38 <handheld_port>6446</handheld_port> 39 <handheld_user>gpeuser</handheld_user> 36 37 <ssh> 38 <handheld_ip>127.0.0.1</handheld_ip> 39 <handheld_user>gpeuser</handheld_user> 40 <command>gpesyncd --remote</command> 41 </ssh> 42 43 <!-- 44 <local> 45 <command>gpesyncd --remote</command> 46 </local> 47 --> 48 49 <!-- 50 <remote> 51 <handheld_ip>127.0.0.1</handheld_ip> 52 <handheld_port>6446</handheld_port> 53 </remote> 54 --> 55 40 56 </config> plugins/gpe/src/gpe_sync.c
r2516 r2521 39 39 char *client_err; 40 40 if (env->use_local) { 41 env->client = gpesync_client_open_local( &client_err);41 env->client = gpesync_client_open_local(env->command, &client_err); 42 42 } 43 43 else if (env->use_ssh) 44 44 { 45 45 gchar *path = g_strdup_printf ("%s@%s", env->username, env->device_addr); 46 env->client = gpesync_client_open_ssh (path, &client_err);46 env->client = gpesync_client_open_ssh (path, env->command, &client_err); 47 47 } 48 48 else plugins/gpe/src/gpe_sync.h
r2516 r2521 39 39 // this is needed for gpe_xml.c: 40 40 #include <libxml/parser.h> 41 #include <libxml/xpath.h> 41 42 42 43 #include "gpesync_client.h" … … 62 63 char *device_addr; // the ip of the handheld; 63 64 char *username; // The user on the handheld 65 char *command; // Command to run 64 66 int device_port; 65 67 int use_ssh; 66 68 int use_local; 69 int use_remote; 67 70 68 71 int debuglevel; plugins/gpe/src/gpe_xml.c
r2516 r2521 2 2 * gpe-sync - A plugin for the opensync framework 3 3 * Copyright (C) 2005 Martin Felis <martin@silef.de> 4 * Copyright (C) 2007 Graham R. Cobb <g+opensync@cobb.uk.net> 4 5 * 5 6 * This library is free software; you can redistribute it and/or … … 24 25 osync_bool gpe_parse_settings(gpe_environment *env, const char *data) 25 26 { 26 xmlDocPtr doc; 27 xmlNodePtr cur; 27 xmlDocPtr doc = NULL; 28 xmlXPathContextPtr ctx = NULL; 29 xmlXPathObjectPtr obj = NULL; 30 /// xmlNodePtr cur; 28 31 29 32 osync_trace(TRACE_ENTRY, "GPE-SYNC %s(%p, %p)", __func__, env, data); 30 33 31 34 // Set the defaults 32 env->device_addr = (char*)malloc(sizeof(char)*10); 33 strcpy(env->device_addr, "127.0.0.1"); 35 env->device_addr = g_strdup("127.0.0.1"); 34 36 env->device_port = 6446; 35 env->username = (char*)malloc(sizeof(char)*9); 36 strcpy(env->username, "gpeuser"); 37 env->use_ssh = 1; 37 env->username = g_strdup("gpeuser"); 38 env->command = g_strdup("gpesyncd --remote"); 39 env->use_ssh = 0; 40 env->use_local = 0; 41 env->use_remote = 0; 42 env->debuglevel = 0; 43 44 xmlInitParser(); 38 45 39 46 doc = xmlParseMemory(data, strlen(data)+1); … … 43 50 return FALSE; 44 51 } 45 46 cur = xmlDocGetRootElement(doc);47 52 48 if(!cur) { 49 osync_trace(TRACE_EXIT_ERROR, "GPE-SYNC %s: Data seems to be empty", __func__); 50 return FALSE; 53 ctx = xmlXPathNewContext(doc); 54 55 /* Work out which type connection to use */ 56 obj = xmlXPathEval("/config/local", ctx); 57 if (obj && obj->nodesetval && obj->nodesetval->nodeNr) { 58 env->use_local = 1; 59 osync_trace(TRACE_INTERNAL, "GPE-SYNC %s: <local> seen", __func__); 60 } 61 if (obj) xmlXPathFreeObject(obj); 62 obj = xmlXPathEval("/config/ssh", ctx); 63 if (obj && obj->nodesetval && obj->nodesetval->nodeNr) { 64 if (env->use_local) { 65 osync_trace(TRACE_EXIT_ERROR, "GPE-SYNC %s: <local> and <ssh> both found in config file", __func__); 66 goto error; 67 } 68 env->use_ssh = 1; 69 osync_trace(TRACE_INTERNAL, "GPE-SYNC %s: <ssh> seen", __func__); 70 } 71 if (obj) xmlXPathFreeObject(obj); 72 obj = xmlXPathEval("/config/remote", ctx); 73 if (obj && obj->nodesetval && obj->nodesetval->nodeNr) { 74 if (env->use_local) { 75 osync_trace(TRACE_EXIT_ERROR, "GPE-SYNC %s: <local> and <remote> both found in config file", __func__); 76 goto error; 77 } 78 if (env->use_ssh) { 79 osync_trace(TRACE_EXIT_ERROR, "GPE-SYNC %s: <ssh> and <remote> both found in config file", __func__); 80 goto error; 81 } 82 env->use_remote = 1; 83 osync_trace(TRACE_INTERNAL, "GPE-SYNC %s: <remote> seen", __func__); 84 } 85 if (!(env->use_local || env->use_ssh || env->use_remote)) { 86 osync_trace(TRACE_EXIT_ERROR, "GPE-SYNC %s: one of <local>, <remote>, <ssh> must be specified in config file", __func__); 87 goto error; 51 88 } 52 89 53 if (xmlStrcmp(cur->name, (xmlChar*)"config")) { 54 xmlFreeDoc(doc); 55 osync_trace(TRACE_EXIT_ERROR, "GPE-SYNC %s: data seems not to be a valid configdata", __func__); 56 return FALSE; 90 if (obj) xmlXPathFreeObject(obj); 91 obj = xmlXPathEval("//handheld_ip/text()", ctx); 92 if (obj && obj->nodesetval && obj->nodesetval->nodeNr) { 93 if (!(env->use_remote || env->use_ssh)) { 94 osync_trace(TRACE_ERROR, "GPE-SYNC %s: <handheld_ip> should only be specified in <remote> or <ssh> sections", __func__); 95 } 96 g_free(env->device_addr); 97 xmlChar *str=xmlXPathCastToString(obj); 98 env->device_addr = g_strdup(str); 99 xmlFree(str); 100 osync_trace(TRACE_INTERNAL, "GPE-SYNC %s: <handheld_ip> = %s", __func__, env->device_addr); 57 101 } 58 102 59 cur = cur->xmlChildrenNode; 60 61 while (cur != NULL) { 62 char *str = (char*)xmlNodeGetContent(cur); 63 if (str) { 64 if (!xmlStrcmp(cur->name, (const xmlChar *)"handheld_ip")) { 65 // convert the string to an ip 66 env->device_addr = g_strdup(str); 67 } 68 if (!xmlStrcmp(cur->name, (const xmlChar *)"handheld_port")) { 69 env->device_port = atoi(str); 70 } 71 if (!xmlStrcmp(cur->name, (const xmlChar *)"use_ssh")) { 72 env->use_ssh = atoi(str); 73 } 74 if (!xmlStrcmp(cur->name, (const xmlChar *)"use_local")) { 75 env->use_local = atoi(str); 76 } 77 if (!xmlStrcmp(cur->name, (const xmlChar *)"handheld_user")) { 78 env->username = g_strdup(str); 79 } 80 xmlFree(str); 81 } 82 cur = cur->next; 103 if (obj) xmlXPathFreeObject(obj); 104 obj = xmlXPathEval("//handheld_user/text()", ctx); 105 if (obj && obj->nodesetval && obj->nodesetval->nodeNr) { 106 if (!(env->use_ssh)) { 107 osync_trace(TRACE_ERROR, "GPE-SYNC %s: <handheld_user> should only be specified in <ssh> section", __func__); 108 } 109 g_free(env->username); 110 xmlChar *str=xmlXPathCastToString(obj); 111 env->username = g_strdup(str); 112 xmlFree(str); 113 osync_trace(TRACE_INTERNAL, "GPE-SYNC %s: <handheld_user> = %s", __func__, env->username); 83 114 } 84 115 116 if (obj) xmlXPathFreeObject(obj); 117 obj = xmlXPathEval("//command/text()", ctx); 118 if (obj && obj->nodesetval && obj->nodesetval->nodeNr) { 119 if (!(env->use_local || env->use_ssh)) { 120 osync_trace(TRACE_ERROR, "GPE-SYNC %s: <command> should only be specified in <local> or <ssh> sections", __func__); 121 } 122 g_free(env->username); 123 xmlChar *str=xmlXPathCastToString(obj); 124 env->command = g_strdup(str); 125 xmlFree(str); 126 osync_trace(TRACE_INTERNAL, "GPE-SYNC %s: <command> = %s", __func__, env->command); 127 } 128 129 if (obj) xmlXPathFreeObject(obj); 130 obj = xmlXPathEval("//handheld_port/text()", ctx); 131 if (obj && obj->nodesetval && obj->nodesetval->nodeNr) { 132 if (!(env->use_remote)) { 133 osync_trace(TRACE_ERROR, "GPE-SYNC %s: <handheld_port> should only be specified in <remote> section", __func__); 134 } 135 xmlChar *str=xmlXPathCastToString(obj); 136 env->device_port = atoi(str); 137 xmlFree(str); 138 osync_trace(TRACE_INTERNAL, "GPE-SYNC %s: <handheld_port> = %d", __func__, env->device_port); 139 } 140 141 if (obj) xmlXPathFreeObject(obj); 142 obj = xmlXPathEval("//debug/text()", ctx); 143 if (obj && obj->nodesetval && obj->nodesetval->nodeNr) { 144 xmlChar *str=xmlXPathCastToString(obj); 145 env->debuglevel = atoi(str); 146 xmlFree(str); 147 osync_trace(TRACE_INTERNAL, "GPE-SYNC %s: <debug> = %d", __func__, env->debuglevel); 148 } 149 150 if (obj) xmlXPathFreeObject(obj); 151 xmlXPathFreeContext(ctx); 85 152 xmlFreeDoc(doc); 153 xmlCleanupParser(); 86 154 osync_trace(TRACE_EXIT, "GPE-SYNC %s", __func__); 87 155 return TRUE; 156 error: 157 if (obj) xmlXPathFreeObject(obj); 158 if (ctx) xmlXPathFreeContext(ctx); 159 if (doc) xmlFreeDoc(doc); 160 xmlCleanupParser(); 161 return FALSE; 88 162 } plugins/gpe/src/gpesync_client.c
r2516 r2521 1 1 /* 2 2 * Copyright (C) 2005 Martin Felis <martin@silef.de> 3 * Copyright (C) 2007 Graham R. Cobb <g+opensync@cobb.uk.net> 3 4 * 4 5 * This program is free software; you can redistribute it and/or … … 223 224 224 225 gpesync_client * 225 gpesync_client_open_ssh (const char *addr, gchar **errmsg)226 gpesync_client_open_ssh (const char *addr, const char * command, gchar **errmsg) 226 227 { 227 228 gpesync_client *ctx; 228 229 gchar *hostname = NULL; 229 230 gchar *username = NULL; 230 gchar *str ;231 gchar *str, *str2; 231 232 gchar *p; 233 #define MAXARGS 20 234 char *argv[MAXARGS+1]; 235 int i; 232 236 233 237 int in_fds[2], out_fds[2]; … … 251 255 if (username == NULL) 252 256 username = (gchar *) g_get_user_name (); 257 258 /* Assemble argument list for exec */ 259 str2 = g_strdup(command); 260 argv[0] = "ssh"; 261 argv[1] = "-l"; 262 argv[2] = username; 263 argv[3] = hostname; 264 i=3; p=str2; 265 while (i++ < MAXARGS && p && *p != 0) { 266 argv[i] = p; 267 /* Look for the next space */ 268 p = strchr(p, ' '); 269 if (!p) break; 270 p[0]=0; // Null terminate argument 271 while (*++p==' ') ; // Skip blanks 272 } 273 argv[i] = NULL; 253 274 254 275 ctx = g_malloc0 (sizeof (gpesync_client)); … … 268 289 close (in_fds[0]); 269 290 if (verbose) 270 fprintf (stderr, "connecting as %s to %s filename: %s\n", username, hostname, "gpesyncd"); 271 execlp ("ssh", "ssh", "-l", username, hostname, "gpesyncd", "--remote", 272 NULL); 291 fprintf (stderr, "connecting as %s to %s with command %s (argc=%d)\n", username, hostname, command, i); 292 execvp ("ssh", argv); 273 293 perror ("exec"); 274 294 } … … 284 304 285 305 g_free (str); 286 306 g_free (str2); 307 287 308 return ctx; 288 309 } 289 310 290 311 gpesync_client * 291 gpesync_client_open_local ( gchar **errmsg)312 gpesync_client_open_local (const char * command, gchar **errmsg) 292 313 { 293 314 gpesync_client *ctx; 315 gchar *str2, *p; 316 char *argv[MAXARGS+1]; 317 int i; 294 318 295 319 int in_fds[2], out_fds[2]; 296 320 pid_t pid; 321 322 /* Assemble argument list for exec */ 323 str2 = g_strdup(command); 324 i=-1; p=str2; 325 while (i++ < MAXARGS && p && *p != 0) { 326 argv[i] = p; 327 /* Look for the next space */ 328 p = strchr(p, ' '); 329 if (!p) {i++; break;} 330 p[0]=0; // Null terminate argument 331 while (*++p==' ') ; // Skip blanks 332 } 333 argv[i] = NULL; 297 334 298 335 ctx = g_malloc0 (sizeof (gpesync_client)); … … 313 350 if (verbose) 314 351 fprintf (stderr, "connecting to gpesyncd locally"); 315 execlp ("gpesyncd", "gpesyncd", "--remote", 316 NULL); 352 execvp (argv[0], argv); 317 353 perror ("exec"); 318 354 } … … 320 356 close (out_fds[0]); 321 357 close (in_fds[1]); 358 359 g_free (str2); 322 360 323 361 ctx->outfd = out_fds[1]; plugins/gpe/src/gpesync_client.h
r2516 r2521 1 1 /* 2 2 * Copyright (C) 2005 Martin Felis <martin@silef.de> 3 * Copyright (C) 2007 Graham R. Cobb <g+opensync@cobb.uk.net> 3 4 * 4 5 * This program is free software; you can redistribute it and/or … … 47 48 * 48 49 */ 49 gpesync_client *gpesync_client_open_ssh(const char *addr, c har **errmsg);50 gpesync_client *gpesync_client_open_local(c har **errmsg);50 gpesync_client *gpesync_client_open_ssh(const char *addr, const char * command, char **errmsg); 51 gpesync_client *gpesync_client_open_local(const char * command, char **errmsg); 51 52 gpesync_client *gpesync_client_open(const char *addr, int port, char **errmsg); 52 53
