Changeset 2546

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

gpe-sync: add protocol version checking

Files:

Legend:

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

    r2522 r2546  
     12007-10-09  Graham Cobb  <g+770@cobb.uk.net> 
     2 
     3        * src/gpe_sync.h, src/gpe_sync.c (discover): Add protocol version checking 
     4 
    152007-09-11  Graham Cobb  <g+770@cobb.uk.net> 
    26 
  • plugins/gpe/src/gpe_sync.c

    r2521 r2546  
    2626 * \param ctx           The context of the plugin 
    2727 */ 
    28 static void gpe_connect(void *userdata, OSyncPluginInfo *info, OSyncContext *ctx) 
    29 
    30         osync_trace(TRACE_ENTRY, "GPE-SYNC %s(%p, %p, %p)", __func__, userdata, info, ctx); 
    31  
    32         // We need to get the context to load all our stuff. 
    33         gpe_environment *env = ((sink_environment *)userdata)->gpe_env; 
    34          
     28static void gpe_connect_internal(gpe_environment *env, char **client_err) 
     29
     30        osync_trace(TRACE_ENTRY, "GPE-SYNC %s(%p, %p)", __func__, env, client_err); 
     31 
    3532        // Do nothing if already connected 
    3633        if (env->client) { 
    3734          osync_trace(TRACE_INTERNAL, "GPE-SYNC %s: already connected", __func__); 
    3835        } else { 
    39           char *client_err; 
    4036          if (env->use_local) { 
    41             env->client = gpesync_client_open_local(env->command, &client_err); 
     37            env->client = gpesync_client_open_local(env->command, client_err); 
    4238          } 
    4339          else if (env->use_ssh) 
    4440            { 
    4541              gchar *path = g_strdup_printf ("%s@%s", env->username, env->device_addr); 
    46               env->client = gpesync_client_open_ssh (path, env->command, &client_err); 
     42              env->client = gpesync_client_open_ssh (path, env->command, client_err); 
    4743            } 
    4844          else 
    49             env->client = gpesync_client_open (env->device_addr, env->device_port, &client_err); 
    50  
    51           if (env->client == NULL) { 
    52             osync_context_report_error(ctx, OSYNC_ERROR_NO_CONNECTION, client_err); 
    53             osync_trace(TRACE_EXIT_ERROR, "GPE-SYNC %s: connect failed: %s", __func__, client_err); 
    54             return; 
    55           } 
     45            env->client = gpesync_client_open (env->device_addr, env->device_port, client_err); 
     46        } 
     47 
     48        osync_trace(TRACE_EXIT, "GPE-SYNC %s", __func__); 
     49
     50static void gpe_connect(void *userdata, OSyncPluginInfo *info, OSyncContext *ctx) 
     51
     52        char *client_err = NULL; 
     53 
     54        osync_trace(TRACE_ENTRY, "GPE-SYNC %s(%p, %p, %p)", __func__, userdata, info, ctx); 
     55 
     56        // We need to get the context to load all our stuff. 
     57        gpe_environment *env = ((sink_environment *)userdata)->gpe_env; 
     58         
     59        gpe_connect_internal(env, &client_err); 
     60 
     61        if (env->client == NULL) { 
     62          osync_context_report_error(ctx, OSYNC_ERROR_NO_CONNECTION, client_err); 
     63          osync_trace(TRACE_EXIT_ERROR, "GPE-SYNC %s: connect failed: %s", __func__, client_err); 
     64          if (client_err) g_free(client_err); 
     65          return; 
    5666        } 
    5767         
     
    8191 * \brief ctx           The context of the plugin 
    8292 */ 
    83 static void gpe_disconnect(void *userdata, OSyncPluginInfo *info, OSyncContext *ctx) 
    84 
    85         osync_trace(TRACE_ENTRY, "GPE-SYNC %s(%p, %p, %p)", __func__, userdata, info, ctx); 
    86         gpe_environment *env = ((sink_environment *)userdata)->gpe_env; 
     93static void gpe_disconnect_internal(gpe_environment *env) 
     94
     95        osync_trace(TRACE_ENTRY, "GPE-SYNC %s(%p)", __func__, env); 
    8796         
    8897        if (env->client) { 
     
    9099                env->client = NULL; 
    91100        } 
     101 
     102        osync_trace(TRACE_EXIT, "GPE-SYNC %s", __func__); 
     103} 
     104static 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); 
    92110 
    93111        //Answer the call 
     
    192210static osync_bool discover(void *userdata, OSyncPluginInfo *info, OSyncError **error) 
    193211{ 
     212        gchar *err_string = NULL; 
     213        gchar *response = NULL; 
     214        unsigned int v_major = 1, v_minor = 0, v_edit = 0; // Default version 1.0.0 
     215 
    194216        osync_trace(TRACE_ENTRY, "GPE-SYNC %s(%p, %p, %p)", __func__, userdata, info, error); 
    195217 
    196218        gpe_environment *env = (gpe_environment *)userdata; 
    197219 
    198         // Report avaliable sinks... 
    199         // FIXME: one day this should connect to the device first and check its capabilities 
    200         if (env->contact_sink.sink) osync_objtype_sink_set_available(env->contact_sink.sink, TRUE); 
    201         if (env->todo_sink.sink) osync_objtype_sink_set_available(env->todo_sink.sink, TRUE); 
    202         if (env->calendar_sink.sink) osync_objtype_sink_set_available(env->calendar_sink.sink, TRUE); 
    203  
    204         // FIXME: should get version info from the device 
     220        // Try to connect 
     221        gpe_connect_internal(env, &err_string); 
     222 
     223        if (env->client == NULL) { 
     224          osync_error_set(error, OSYNC_ERROR_NO_CONNECTION, err_string); 
     225          osync_trace(TRACE_EXIT_ERROR, "GPE-SYNC %s: connect failed: %s", __func__, err_string); 
     226          if (err_string) g_free(err_string); 
     227          return FALSE; 
     228        } 
     229 
     230        // Get version info from the device 
     231        gpesync_client_exec(env->client, "version", client_callback_string, &response, NULL); 
     232 
     233        if (sscanf(response, "OK:%u:%u:%u", &v_major, &v_minor, &v_edit) != 3) { 
     234          osync_trace(TRACE_INTERNAL, "version command error: %s", response); 
     235        } 
     236        osync_trace(TRACE_INTERNAL, "gpesyncd version = %d.%d.%d", v_major, v_minor, v_edit); 
     237 
     238        if (v_major != MIN_PROTOCOL_MAJOR || v_minor < MIN_PROTOCOL_MINOR) { 
     239          osync_error_set(error, OSYNC_ERROR_NOT_SUPPORTED, "gpesyncd version %d.%d not supported -- require %d.%d",  
     240                          v_major, v_minor, MIN_PROTOCOL_MAJOR, MIN_PROTOCOL_MINOR); 
     241          osync_trace(TRACE_EXIT_ERROR, "GPE-SYNC %s: gpesyncd version %d.%d not supported -- require %d.%d",  
     242                      __func__, v_major, v_minor, MIN_PROTOCOL_MAJOR, MIN_PROTOCOL_MINOR); 
     243          return FALSE; 
     244        } 
     245 
     246        gchar *version_string = g_strdup_printf("%d.%d.%d", v_major, v_minor, v_edit); 
    205247        OSyncVersion *version = osync_version_new(error); 
    206248        osync_version_set_plugin(version, "gpe-sync"); 
    207249        //osync_version_set_modelversion(version, "version"); 
    208250        //osync_version_set_firmwareversion(version, "firmwareversion"); 
    209         //osync_version_set_softwareversion(version, "softwareversion"); 
     251        osync_version_set_softwareversion(version, version_string); 
    210252        //osync_version_set_hardwareversion(version, "hardwareversion"); 
    211253        osync_plugin_info_set_version(info, version); 
    212254        osync_version_unref(version); 
     255        g_free(version_string); 
     256 
     257        // Report avaliable sinks... 
     258        // GPE always supports contacts, todos and events 
     259        if (env->contact_sink.sink) osync_objtype_sink_set_available(env->contact_sink.sink, TRUE); 
     260        if (env->todo_sink.sink) osync_objtype_sink_set_available(env->todo_sink.sink, TRUE); 
     261        if (env->calendar_sink.sink) osync_objtype_sink_set_available(env->calendar_sink.sink, TRUE); 
     262        // One day we may add notes... 
     263 
     264        gpe_disconnect_internal(env); 
    213265 
    214266        osync_trace(TRACE_EXIT, "GPE-SYNC %s", __func__); 
  • plugins/gpe/src/gpe_sync.h

    r2521 r2546  
    8282#define GPE_HASH_LOAD_ERROR 3 
    8383 
     84/* 
     85 * Minimum protocol version number supported 
     86 * 
     87 * Major number must be equal: increment this if we cannot even parse 
     88 * the protocol correctly any more 
     89 * 
     90 * Minor number must be less than or equal to the other end: increment  
     91 * this if a new command is vital for correct operation 
     92 * 
     93 * Edit number ignored but reported in logs 
     94 */ 
     95#define MIN_PROTOCOL_MAJOR 1 
     96#define MIN_PROTOCOL_MINOR 0 
     97 
    8498#endif