Changeset 2549

Show
Ignore:
Timestamp:
10/11/07 01:54:01 (1 year ago)
Author:
gcobb
Message:

gpe-sync: add multiple calendar support

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/gpe/ChangeLog

    r2546 r2549  
     12007-10-11  Graham Cobb  <g+770@cobb.uk.net> 
     2 
     3        * src/gpe_sync.c, src/gpe_sync.h: Add multiple calendar support 
     4        * src/gpe_xml.c, src/gpe-sync: Add <calendar> configuration support 
     5 
    162007-10-09  Graham Cobb  <g+770@cobb.uk.net> 
    27 
  • plugins/gpe/src/gpe-sync

    r2521 r2549  
    66 
    77        In this case you can specify <command>shell command</command> 
    8         to change the shell command which is invoked. 
    9  
    10         Specifying the <command> tag is not recommended. 
     8        to change the shell command which is invoked.  However, specifying  
     9        the <command> tag is not recommended. 
    1110 
    1211        2) You can use SSH to connect to the device by specifying the 
    13         <ssh>...<ssh> option. 
     12        <ssh>...</ssh> option. 
    1413 
    1514        In this case, the <handheld_ip>, <handheld_user> and <command>  
     
    2827        <remote>...</remote> option. 
    2928 
    30         In this case, the <handheld_ip> and <handheld_port> tags are used. 
     29        In this case, the <handheld_ip> and <handheld_port> tags can be used. 
    3130 
    32   Either use the <ssh> configuration shown below or remove it and uncomment 
     31  Either customise the <ssh> configuration shown below or remove it and uncomment 
    3332  one of the other sections.  Each section is configured to show the default values 
    3433  used if the tags are not specified.  
    3534  --> 
    36  
    3735  <ssh> 
    3836    <handheld_ip>127.0.0.1</handheld_ip> 
     
    4038    <command>gpesyncd --remote</command> 
    4139  </ssh> 
    42  
    4340  <!-- 
    4441  <local> 
     
    4643  </local> 
    4744  --> 
    48  
    4945  <!-- 
    5046  <remote> 
     
    5450  --> 
    5551 
     52  <!-- 
     53  The <calendar> tag can be used to specify which GPE calendar 
     54  should be used for this synchronisation.  If the <calendar> 
     55  tag is specified then only the named calendar is considered 
     56  (only events in that calendar wil be sent from GPE and all 
     57  events sent to GPE will be stored in that calendar).  If the 
     58  <calendar> tag is not specified, then all events, from all 
     59  calendars, will be sent from GPE and new events will be created 
     60  in the default calendar. 
     61 
     62  Note that an error occurs if the named calendar does not exist 
     63  and calendar names are case-sensitive. 
     64  --> 
     65  <!-- <calendar>Some Calendar</calendar> --> 
    5666</config> 
  • plugins/gpe/src/gpe_sync.c

    r2546 r2549  
    2121 
    2222#include "gpe_sync.h" 
     23 
     24/*! \brief Closes the connection to the databases 
     25 * 
     26 * \brief ctx           The context of the plugin 
     27 */ 
     28static void gpe_disconnect_internal(gpe_environment *env) 
     29{ 
     30        osync_trace(TRACE_ENTRY, "GPE-SYNC %s(%p)", __func__, env); 
     31         
     32        if (env->client) { 
     33                gpesync_client_close (env->client); 
     34                env->client = NULL; 
     35        } 
     36 
     37        osync_trace(TRACE_EXIT, "GPE-SYNC %s", __func__); 
     38} 
     39static void gpe_disconnect(void *userdata, OSyncPluginInfo *info, OSyncContext *ctx) 
     40{ 
     41        osync_trace(TRACE_ENTRY, "GPE-SYNC %s(%p, %p, %p)", __func__, userdata, info, ctx); 
     42        gpe_environment *env = ((sink_environment *)userdata)->gpe_env; 
     43         
     44        gpe_disconnect_internal(env); 
     45 
     46        //Answer the call 
     47        osync_context_report_success(ctx); 
     48        osync_trace(TRACE_EXIT, "GPE-SYNC %s", __func__); 
     49} 
    2350 
    2451/*! \brief Connects to the databases of GPE 
     
    6693        } 
    6794         
     95        // Set calendar name 
     96        if (env->calendar) { 
     97          gchar *response = NULL; 
     98          gpesync_client_exec_printf(env->client, "path vevent %s", client_callback_string, &response, NULL, env->calendar); 
     99          if (strncmp(response, "OK", 2) != 0) { 
     100            osync_context_report_error(ctx, OSYNC_ERROR_MISCONFIGURATION, "calendar %s not found",  
     101                          env->calendar); 
     102            osync_trace(TRACE_EXIT_ERROR, "GPE-SYNC %s: calendar %s not found",  
     103                      __func__, env->calendar); 
     104            gpe_disconnect_internal(env); 
     105            g_free(response); 
     106            return; 
     107          } 
     108          g_free(response); 
     109        } 
     110 
    68111        osync_context_report_success(ctx); 
    69112 
     
    78121{ 
    79122        osync_trace(TRACE_ENTRY, "GPE-SYNC %s(%p, %p, %p)", __func__, userdata, info, ctx); 
    80         gpe_environment *env = ((sink_environment *)userdata)->gpe_env; 
     123        //gpe_environment *env = ((sink_environment *)userdata)->gpe_env; 
    81124 
    82125        //If we use anchors we have to update it now. 
    83126         
    84         //Answer the call 
    85         osync_context_report_success(ctx); 
    86         osync_trace(TRACE_EXIT, "GPE-SYNC %s", __func__); 
    87 } 
    88  
    89 /*! \brief Closes the connection to the databases 
    90  * 
    91  * \brief ctx           The context of the plugin 
    92  */ 
    93 static void gpe_disconnect_internal(gpe_environment *env) 
    94 { 
    95         osync_trace(TRACE_ENTRY, "GPE-SYNC %s(%p)", __func__, env); 
    96          
    97         if (env->client) { 
    98                 gpesync_client_close (env->client); 
    99                 env->client = NULL; 
    100         } 
    101  
    102         osync_trace(TRACE_EXIT, "GPE-SYNC %s", __func__); 
    103 } 
    104 static void gpe_disconnect(void *userdata, OSyncPluginInfo *info, OSyncContext *ctx) 
    105 { 
    106         osync_trace(TRACE_ENTRY, "GPE-SYNC %s(%p, %p, %p)", __func__, userdata, info, ctx); 
    107         gpe_environment *env = ((sink_environment *)userdata)->gpe_env; 
    108          
    109         gpe_disconnect_internal(env); 
    110  
    111127        //Answer the call 
    112128        osync_context_report_success(ctx); 
     
    241257          osync_trace(TRACE_EXIT_ERROR, "GPE-SYNC %s: gpesyncd version %d.%d not supported -- require %d.%d",  
    242258                      __func__, v_major, v_minor, MIN_PROTOCOL_MAJOR, MIN_PROTOCOL_MINOR); 
     259          g_free(response); 
    243260          return FALSE; 
    244261        } 
     
    255272        g_free(version_string); 
    256273 
    257         // Report avaliable sinks... 
     274        if (env->calendar) { 
     275          // Calendar support requires at least version 1.2 
     276          if (v_minor < 2) { 
     277            osync_error_set(error, OSYNC_ERROR_NOT_SUPPORTED, "gpesyncd version %d.%d does not support <calendar> -- require %d.%d",  
     278                          v_major, v_minor, MIN_PROTOCOL_MAJOR, 2); 
     279            osync_trace(TRACE_EXIT_ERROR, "GPE-SYNC %s: gpesyncd version %d.%d does not support <calendar> -- require %d.%d",  
     280                      __func__, v_major, v_minor, MIN_PROTOCOL_MAJOR, 2); 
     281            gpe_disconnect_internal(env); 
     282            g_free(response); 
     283            return FALSE; 
     284          } 
     285 
     286          // Verify calendar name 
     287          gpesync_client_exec_printf(env->client, "path vevent %s", client_callback_string, &response, NULL, env->calendar); 
     288          if (strncmp(response, "OK", 2) != 0) { 
     289            osync_error_set(error, OSYNC_ERROR_MISCONFIGURATION, "calendar %s not found",  
     290                          env->calendar); 
     291            osync_trace(TRACE_EXIT_ERROR, "GPE-SYNC %s: calendar %s not found",  
     292                      __func__, env->calendar); 
     293            gpe_disconnect_internal(env); 
     294            g_free(response); 
     295          } 
     296        } 
     297 
     298        // Report available sinks... 
    258299        // GPE always supports contacts, todos and events 
    259300        if (env->contact_sink.sink) osync_objtype_sink_set_available(env->contact_sink.sink, TRUE); 
     
    264305        gpe_disconnect_internal(env); 
    265306 
     307        g_free(response); 
    266308        osync_trace(TRACE_EXIT, "GPE-SYNC %s", __func__); 
    267309        return TRUE; 
  • plugins/gpe/src/gpe_sync.h

    r2546 r2549  
    6868        int use_local; 
    6969        int use_remote; 
     70        char *calendar; // Name of GPE calendar to use or NULL 
    7071         
    7172        int debuglevel; 
  • plugins/gpe/src/gpe_xml.c

    r2521 r2549  
    4141        env->use_remote = 0; 
    4242        env->debuglevel = 0; 
     43        env->calendar = NULL; 
    4344         
    4445        xmlInitParser(); 
     
    5354        ctx = xmlXPathNewContext(doc); 
    5455 
    55         /* Work out which type connection to use */ 
     56        /* Work out which type of connection to use */ 
    5657        obj = xmlXPathEval("/config/local", ctx); 
    5758        if (obj && obj->nodesetval && obj->nodesetval->nodeNr) { 
     
    149150 
    150151        if (obj) xmlXPathFreeObject(obj); 
     152        obj = xmlXPathEval("//calendar/text()", ctx); 
     153        if (obj && obj->nodesetval && obj->nodesetval->nodeNr) { 
     154          xmlChar *str=xmlXPathCastToString(obj); 
     155          env->calendar = g_strdup(str); 
     156          xmlFree(str); 
     157          osync_trace(TRACE_INTERNAL, "GPE-SYNC %s: <calendar> = %s", __func__, env->calendar); 
     158        } 
     159 
     160        if (obj) xmlXPathFreeObject(obj); 
    151161        xmlXPathFreeContext(ctx); 
    152162        xmlFreeDoc(doc);