Changeset 2521

Show
Ignore:
Timestamp:
09/11/07 01:58:48 (1 year ago)
Author:
gcobb
Message:

Create new configuration file syntax

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/gpe/src/gpe-sync

    r2516 r2521  
    33         
    44        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. 
    66 
    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. 
    99 
    10         In this case, no other tags are used. 
     10        Specifying the <command> tag is not recommended. 
    1111 
    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. 
    1314 
    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. 
    1817 
    1918        Note that the handheld_ip can be a name or an address and may be 
     
    2423        should be specified as "user". 
    2524 
    26         3) You can connect to a running gpesyncd daemon by specifying: 
     25        Specifying the <command> tag is not recommended. 
    2726 
    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. 
    3029 
    3130        In this case, the <handheld_ip> and <handheld_port> tags are used. 
    3231 
     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.  
    3335  --> 
    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 
    4056</config> 
  • plugins/gpe/src/gpe_sync.c

    r2516 r2521  
    3939          char *client_err; 
    4040          if (env->use_local) { 
    41             env->client = gpesync_client_open_local(&client_err); 
     41            env->client = gpesync_client_open_local(env->command, &client_err); 
    4242          } 
    4343          else if (env->use_ssh) 
    4444            { 
    4545              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); 
    4747            } 
    4848          else 
  • plugins/gpe/src/gpe_sync.h

    r2516 r2521  
    3939// this is needed for gpe_xml.c: 
    4040#include <libxml/parser.h> 
     41#include <libxml/xpath.h> 
    4142 
    4243#include "gpesync_client.h" 
     
    6263        char *device_addr; // the ip of the handheld; 
    6364        char *username; // The user on the handheld 
     65        char *command; // Command to run 
    6466        int device_port; 
    6567        int use_ssh; 
    6668        int use_local; 
     69        int use_remote; 
    6770         
    6871        int debuglevel; 
  • plugins/gpe/src/gpe_xml.c

    r2516 r2521  
    22 * gpe-sync - A plugin for the opensync framework 
    33 * Copyright (C) 2005  Martin Felis <martin@silef.de> 
     4 * Copyright (C) 2007  Graham R. Cobb <g+opensync@cobb.uk.net> 
    45 *  
    56 * This library is free software; you can redistribute it and/or 
     
    2425osync_bool gpe_parse_settings(gpe_environment *env, const char *data) 
    2526{ 
    26         xmlDocPtr doc; 
    27         xmlNodePtr cur; 
     27        xmlDocPtr doc = NULL; 
     28        xmlXPathContextPtr ctx = NULL; 
     29        xmlXPathObjectPtr obj = NULL; 
     30        ///     xmlNodePtr cur; 
    2831 
    2932        osync_trace(TRACE_ENTRY, "GPE-SYNC %s(%p, %p)", __func__, env, data); 
    3033 
    3134        // 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"); 
    3436        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(); 
    3845 
    3946        doc = xmlParseMemory(data, strlen(data)+1); 
     
    4350          return FALSE; 
    4451        } 
    45          
    46         cur = xmlDocGetRootElement(doc); 
    4752 
    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; 
    5188        } 
    5289 
    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); 
    57101        } 
    58102 
    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); 
    83114        } 
    84115 
     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); 
    85152        xmlFreeDoc(doc); 
     153        xmlCleanupParser(); 
    86154        osync_trace(TRACE_EXIT, "GPE-SYNC %s", __func__); 
    87155        return TRUE; 
     156 error: 
     157        if (obj) xmlXPathFreeObject(obj); 
     158        if (ctx) xmlXPathFreeContext(ctx); 
     159        if (doc) xmlFreeDoc(doc); 
     160        xmlCleanupParser(); 
     161        return FALSE; 
    88162} 
  • plugins/gpe/src/gpesync_client.c

    r2516 r2521  
    11/* 
    22 * Copyright (C) 2005 Martin Felis <martin@silef.de> 
     3 * Copyright (C) 2007  Graham R. Cobb <g+opensync@cobb.uk.net> 
    34 * 
    45 * This program is free software; you can redistribute it and/or 
     
    223224 
    224225gpesync_client * 
    225 gpesync_client_open_ssh (const char *addr, gchar **errmsg) 
     226gpesync_client_open_ssh (const char *addr, const char * command, gchar **errmsg) 
    226227{ 
    227228  gpesync_client *ctx; 
    228229  gchar *hostname = NULL; 
    229230  gchar *username = NULL; 
    230   gchar *str
     231  gchar *str, *str2
    231232  gchar *p; 
     233#define MAXARGS 20 
     234  char *argv[MAXARGS+1]; 
     235  int i; 
    232236 
    233237  int in_fds[2], out_fds[2]; 
     
    251255  if (username == NULL) 
    252256    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; 
    253274 
    254275  ctx = g_malloc0 (sizeof (gpesync_client)); 
     
    268289      close (in_fds[0]); 
    269290      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); 
    273293      perror ("exec"); 
    274294    } 
     
    284304  
    285305  g_free (str); 
    286    
     306  g_free (str2); 
     307 
    287308  return ctx; 
    288309} 
    289310 
    290311gpesync_client * 
    291 gpesync_client_open_local (gchar **errmsg) 
     312gpesync_client_open_local (const char * command, gchar **errmsg) 
    292313{ 
    293314  gpesync_client *ctx; 
     315  gchar *str2, *p; 
     316  char *argv[MAXARGS+1]; 
     317  int i; 
    294318 
    295319  int in_fds[2], out_fds[2]; 
    296320  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; 
    297334 
    298335  ctx = g_malloc0 (sizeof (gpesync_client)); 
     
    313350      if (verbose) 
    314351        fprintf (stderr, "connecting to gpesyncd locally"); 
    315       execlp ("gpesyncd", "gpesyncd", "--remote", 
    316               NULL); 
     352      execvp (argv[0], argv); 
    317353      perror ("exec"); 
    318354    } 
     
    320356  close (out_fds[0]); 
    321357  close (in_fds[1]); 
     358 
     359  g_free (str2); 
    322360 
    323361  ctx->outfd = out_fds[1]; 
  • plugins/gpe/src/gpesync_client.h

    r2516 r2521  
    11/* 
    22 * Copyright (C) 2005 Martin Felis <martin@silef.de> 
     3 * Copyright (C) 2007  Graham R. Cobb <g+opensync@cobb.uk.net> 
    34 * 
    45 * This program is free software; you can redistribute it and/or 
     
    4748 * 
    4849 */ 
    49 gpesync_client *gpesync_client_open_ssh(const char *addr, char **errmsg); 
    50 gpesync_client *gpesync_client_open_local(char **errmsg); 
     50gpesync_client *gpesync_client_open_ssh(const char *addr, const char * command, char **errmsg); 
     51gpesync_client *gpesync_client_open_local(const char * command, char **errmsg); 
    5152gpesync_client *gpesync_client_open(const char *addr, int port,  char **errmsg); 
    5253