Changeset 2142

Show
Ignore:
Timestamp:
06/12/07 14:13:50 (1 year ago)
Author:
mjahn
Message:

r1044@semo: mjahn | 2007-06-07 13:44:31 +0200

r1041@semo (orig r2096): dgollub | 2007-06-07 13:24:26 +0200
Copy of gnokii-sync 0.2X to trunk


r1042@semo (orig r2097): dgollub | 2007-06-07 13:31:22 +0200
Initial port of gnokii-sync to 0.30 API
Still not working .. quick hack on a 3h train ride.
Facing some problems with libgnokii :(



r1043@semo (orig r2098): dgollub | 2007-06-07 13:35:35 +0200
Updated INSTALL, README and ChangeLog? of gnokii-sync



Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/gnokii-sync/SConstruct

    r2107 r2142  
    5454install_plugin = '${DESTDIR}$prefix/$libsuffix/opensync/plugins' 
    5555install_format = '${DESTDIR}$prefix/$libsuffix/opensync/formats' 
    56 install_config = '${DESTDIR}$prefix/share/opensync/defaults' 
    5756 
    58 Export('env opts testenv install_prefix install_plugin install_format install_config') 
     57Export('env opts testenv install_prefix install_plugin install_format') 
    5958 
    6059SConscript(['src/SConscript']) 
  • plugins/gnokii-sync/build/linux/osync_build.py

    r2099 r2142  
    3737        env.ParseConfig('pkg-config --cflags --libs gnokii') 
    3838        env.Append(CCFLAGS = r'-I.') 
    39 #       env.Append(CCFLAGS = [r'-Wall', r'-Werror', r'-O2']) 
    40         env.Append(CCFLAGS = [r'-Wall', r'-O2']) 
     39        env.Append(CCFLAGS = [r'-Wall', r'-Werror', r'-O2']) 
    4140        env.Append(CCFLAGS = r'-DVERSION="\"' + config.version + r'\""') 
    4241         
     
    5049         
    5150        return testenv 
     51 
  • plugins/gnokii-sync/src/SConscript

    r2139 r2142  
    99 
    1010# basic vformat plugins 
    11 gnokii_sync = env.SharedLibrary('gnokii-sync', ['gnokii_sync.c', 'gnokii_calendar.c', 'gnokii_contact.c', 'gnokii_config.c', 'gnokii_comm.c'], LIBS = ['opensync', 'gnokii']
    12 gnokii_event = env.SharedLibrary('gnokii-event', ['gnokii_calendar_format.c', 'gnokii_calendar_utils.c'], LIBS = ['opensync']
    13 gnokii_contact = env.SharedLibrary('gnokii-contact', ['gnokii_contact_format.c', 'gnokii_contact_utils.c'], LIBS = ['opensync']
     11gnokii_sync = env.SharedLibrary('gnokii-sync', ['gnokii_sync.c', 'gnokii_calendar.c', 'gnokii_contact.c', 'gnokii_config.c', 'gnokii_comm.c'], LIBS = ['opensync', 'gnokii'], LIBPATH = '$prefix/$libsuffix'
     12gnokii_event = env.SharedLibrary('gnokii-event', ['gnokii_calendar_format.c'], LIBS = ['opensync'], LIBPATH = '$prefix/$libsuffix'
     13gnokii_contact = env.SharedLibrary('gnokii-contact', ['gnokii_contact_format.c'], LIBS = ['opensync'], LIBPATH = '$prefix/$libsuffix'
    1414 
    1515 
    16 # install synchronization plugin and config  
     16# install synchronization plugin  
    1717env.Install(install_plugin, gnokii_sync) 
    18 env.Install(install_config, ['gnokii-sync'])     
    19  
    20 # install format plugins 
     18# install format plugin 
    2119env.Install(install_format, gnokii_event) 
    2220env.Install(install_format, gnokii_contact) 
  • plugins/gnokii-sync/src/gnokii_calendar.c

    r2133 r2142  
    202202        if (error == GN_ERR_EMPTYLOCATION) { 
    203203                osync_trace(TRACE_EXIT, "%s: no calendar note left.", __func__); 
    204                 g_free(calnote); 
    205204                return NULL; 
    206205        } 
     
    209208        if (error != GN_ERR_NONE) { 
    210209                osync_trace(TRACE_EXIT_ERROR, "%s(): error while query the phone - gnokii: %s", __func__, gn_error_print(error)); 
    211                 g_free(calnote); 
    212210                return NULL; 
    213211        } 
     
    369367                        break; 
    370368 
     369                OSyncChange *change = osync_change_new(&error); 
     370 
    371371                // prepare UID with gnokii-calendar-<memory location> 
    372372                uid = g_strdup_printf ("gnokii-calendar-%i", calnote->location); 
    373                 osync_hashtable_report(sinkenv->hashtable, uid); 
    374  
     373                osync_change_set_uid(change, uid); 
     374 
     375                // get hash of calnote 
    375376                hash = gnokii_calendar_hash(calnote); 
    376                 OSyncChangeType type = osync_hashtable_get_changetype(sinkenv->hashtable, uid, hash); 
    377  
    378                 if (type == OSYNC_CHANGE_TYPE_UNMODIFIED) { 
    379                         g_free(hash); 
    380                         g_free(uid); 
    381                         g_free(calnote); 
    382                         continue; 
    383                 } 
    384  
    385                 osync_hashtable_update_hash(sinkenv->hashtable, type, uid, hash); 
    386  
    387                 OSyncChange *change = osync_change_new(&error); 
    388  
    389                 osync_change_set_uid(change, uid); 
    390377                osync_change_set_hash(change, hash);     
    391                 osync_change_set_changetype(change, type); 
    392378 
    393379                // set data 
    394                 osync_trace(TRACE_INTERNAL, "objformat: %p", sinkenv->objformat); 
    395                 OSyncData *odata = osync_data_new((char *) calnote, sizeof(gn_calnote), sinkenv->objformat, &error); 
    396                 if (!odata) { 
     380                OSyncData *data = osync_data_new((char *) calnote, sizeof(gn_calnote), sinkenv->objformat, &error); 
     381                if (!data) { 
    397382                        osync_change_unref(change); 
    398383                        osync_context_report_osyncwarning(ctx, error); 
     
    400385                        g_free(hash); 
    401386                        g_free(uid); 
    402                         g_free(calnote); 
    403387                        continue; 
    404388                } 
    405389 
    406                 osync_data_set_objtype(odata, osync_objtype_sink_get_name(sink)); 
    407                 osync_change_set_data(change, odata); 
    408                 osync_data_unref(odata); 
    409  
    410                 osync_context_report_change(ctx, change); 
    411  
    412                 osync_trace(TRACE_INTERNAL, "Change: %p", change); 
    413  
    414                 osync_change_unref(change); 
     390                osync_data_set_objtype(data, osync_objtype_sink_get_name(sink)); 
     391                osync_change_set_data(change, data); 
     392                osync_data_unref(data); 
     393         
     394                OSyncChangeType type = osync_hashtable_get_changetype(sinkenv->hashtable, uid, hash); 
     395                if (type != OSYNC_CHANGE_TYPE_UNMODIFIED) { 
     396                        osync_trace(TRACE_INTERNAL, "Position: %i Needs to be reported (!= hash)", calnote->location); 
     397                        osync_context_report_change(ctx, change); 
     398                        osync_hashtable_update_hash(sinkenv->hashtable, type, uid, hash); 
     399                }        
    415400 
    416401                g_free(hash); 
     
    458443        g_free(caldata); 
    459444 
    460         osync_context_report_success(ctx); 
    461  
    462445        osync_trace(TRACE_EXIT, "%s", __func__); 
    463446} 
     
    575558        } 
    576559         
     560        // answer the call 
    577561        osync_context_report_success(ctx); 
    578                                 
     562 
     563        // blubb 
     564        /* 
     565        osync_trace(TRACE_INTERNAL, "change->hash: %s change->changetype: %i", osync_change_get_hash(change), 
     566                       osync_change_get_changetype(change)); 
     567        */ 
     568                        
     569        g_free(calnote); 
     570         
    579571        // update hashtable 
    580572        osync_hashtable_update_hash(sinkenv->hashtable, osync_change_get_changetype(change), osync_change_get_uid(change), osync_change_get_hash(change)); 
  • plugins/gnokii-sync/src/gnokii_calendar_format.c

    r2133 r2142  
    5656 
    5757        // Type 
    58         xmlfield = osync_xmlfield_new(xmlformat, "Categories", error); 
     58        xmlfield = osync_xmlfield_new(xmlformat, "Category", error); 
    5959        switch (cal->type) { 
    6060                case GN_CALNOTE_MEETING: 
     
    193193                xmlfield = osync_xmlfield_new(xmlformat, "Alarm", error); 
    194194 
    195                 // TODO: How to handle AlarmAction? 
    196                 // AUDIO by tone?  
    197                 // DISPLAY by silent?    
    198                 // EMAIL and PRODECDURE isn't supported by libgnokii 
    199195                if (cal->alarm.tone) 
    200                         osync_xmlfield_set_key_value(xmlfield, "AlarmAction", "AUDIO"); 
    201                 else 
    202196                        osync_xmlfield_set_key_value(xmlfield, "AlarmAction", "DISPLAY"); 
    203  
    204197 
    205198 
     
    211204 
    212205        // Summary 
    213         if (strlen(cal->text)) { 
     206        if (cal->text) { 
    214207                xmlfield = osync_xmlfield_new(xmlformat, "Summary", error); 
    215208                osync_xmlfield_set_key_value(xmlfield, "Content", cal->text); 
     
    217210 
    218211        // Phone Number 
    219         if (strlen(cal->phone_number) && cal->type == GN_CALNOTE_CALL) { 
     212        if (cal->phone_number && cal->type == GN_CALNOTE_CALL) { 
    220213                xmlfield = osync_xmlfield_new(xmlformat, "Description", error); 
    221214                osync_xmlfield_set_key_value(xmlfield, "Content", cal->phone_number); 
     
    223216 
    224217        // mlocation 
    225         if (strlen(cal->mlocation) && cal->type == GN_CALNOTE_MEETING) { 
     218        if (cal->mlocation && cal->type == GN_CALNOTE_MEETING) { 
    226219                xmlfield = osync_xmlfield_new(xmlformat, "Location", error); 
    227220                osync_xmlfield_set_key_value(xmlfield, "Content", cal->mlocation); 
     
    296289} 
    297290 
    298 static void _xmlfield_category(gn_calnote *calnote, OSyncXMLField *xmlfield) 
    299 { 
    300         int i; 
    301         int numnodes = osync_xmlfield_get_key_count(xmlfield); 
    302         for (i=0; i < numnodes; i++) { 
    303                 const char *category = osync_xmlfield_get_nth_key_value(xmlfield, i); 
    304  
    305                 if (!strcasecmp(category, "Meeting")) 
    306                         calnote->type = GN_CALNOTE_MEETING; 
    307                 else if (!strcasecmp(category, "Calling")) 
    308                         calnote->type = GN_CALNOTE_CALL; 
    309                 else if (!strcasecmp(category, "Birthday")) 
    310                         calnote->type = GN_CALNOTE_BIRTHDAY; 
    311                 else if (!strcasecmp(category, "Reminder")) 
    312                         calnote->type = GN_CALNOTE_REMINDER; 
    313                 else if (!strcasecmp(category, "Memo")) 
    314                         calnote->type = GN_CALNOTE_MEMO; 
    315  
    316                 else 
    317                         // When no known type was found it will check later 
    318                         // for a valid type.  
    319                         calnote->type = 0; 
    320  
    321         } 
    322 } 
    323  
    324 static void _xmlfield_datestarted(gn_calnote *calnote, OSyncXMLField *xmlfield, int *alldayevent) 
    325 { 
    326  
    327         const char *dtstart = osync_xmlfield_get_key_value(xmlfield, "Content"); 
    328  
    329         struct tm *starttm = osync_time_vtime2tm(dtstart); 
    330         struct tm *tmptm = NULL; 
    331  
    332         if (!osync_time_isdate(dtstart) && osync_time_isutc(dtstart)) { 
    333                 tmptm = starttm; 
    334                 int offset = osync_time_timezone_diff(tmptm); 
    335                 starttm = osync_time_tm2localtime(tmptm, offset); 
    336                 g_free(tmptm); 
    337         } 
    338  
    339         calnote->time = gnokii_util_tm2timestamp(starttm); 
    340  
    341         g_free(starttm); 
    342  
    343         // Only 3 matches (=date) means all day event  
    344         if (osync_time_isdate(dtstart)) 
    345                 *alldayevent = 1; 
    346  
    347         // Nokia cellphones cannot handle seconds in calendar - so set it to ZERO 
    348         calnote->time.second = 0; 
    349  
    350 } 
    351  
    352 void static _xmlfield_dateend(gn_calnote *calnote, OSyncXMLField *xmlfield) 
    353 { 
    354  
    355         const char *dtend = osync_xmlfield_get_key_value(xmlfield, "Content"); 
    356  
    357  
    358         struct tm *endtm = osync_time_vtime2tm(dtend); 
    359         struct tm *tmptm = NULL; 
    360         if (!osync_time_isdate(dtend) && osync_time_isutc(dtend)) { 
    361                 tmptm = endtm; 
    362                 int offset = osync_time_timezone_diff(tmptm); 
    363                 endtm = osync_time_tm2localtime(tmptm, offset); 
    364                 g_free(tmptm); 
    365         } 
    366  
    367         calnote->end_time = gnokii_util_tm2timestamp(endtm); 
    368         g_free(endtm); 
    369  
    370         // Nokia cellphones cannot handle seconds in calendar so set it to ZERO 
    371         calnote->end_time.second = 0; 
    372  
    373 } 
    374  
    375 void static _xmlfield_alarm(gn_calnote *calnote, OSyncXMLField *xmlfield) 
    376 { 
    377         int seconds_before = 0; 
    378         time_t start_timet, alarm_timet; 
    379  
    380         calnote->alarm.enabled = 1; 
    381          
    382         const char *action = osync_xmlfield_get_key_value(xmlfield, "AlarmAction"); 
    383  
    384         if (!action) 
    385                 osync_trace(TRACE_INTERNAL, "AlarmAction wasn't set!"); 
    386  
    387         if (action && (!strcasecmp(action, "DISPLAY") || !strcasecmp(action, "AUDIO"))) 
    388                 calnote->alarm.tone = 1; 
    389  
    390  
    391          
    392         const char *trigger = osync_xmlfield_get_key_value(xmlfield, "AlarmTrigger"); 
    393  
    394         if (!trigger)  
    395                 osync_trace(TRACE_INTERNAL, "AlarmTrigger wasn't set!"); 
    396  
    397         const char *triggertype = osync_xmlfield_get_attr(xmlfield, "Value");            
    398  
    399         if (triggertype && !strcasecmp("DURATION", triggertype)) { 
    400                 seconds_before = gnokii_util_alarmevent2secs(trigger); 
    401  
    402                 // convert start event in to seconds 
    403                 start_timet = gnokii_util_timestamp2unix(&(calnote->time)); 
    404  
    405                 // timestamp for alarm 
    406                 alarm_timet = start_timet - seconds_before; 
    407         } else if (triggertype && ! strcasecmp("DATE-TIME", triggertype)) { 
    408                 // TODO: untested! - check UTC offeset issues 
    409                 alarm_timet = osync_time_vtime2unix(trigger, 0); 
    410         } else { 
    411                 osync_trace(TRACE_INTERNAL, "Unkown TRIGGERVALUE - skip Alarm."); 
    412                 return; 
    413         } 
    414  
    415         // convert timestamp of alarm to gnokii timestamp 
    416         calnote->alarm.timestamp = gnokii_util_unix2timestamp(alarm_timet); 
    417 } 
    418  
    419 void static _xmlfield_summary(gn_calnote *calnote, OSyncXMLField *xmlfield) 
    420 { 
    421         const char *summary = osync_xmlfield_get_key_value(xmlfield, "Content"); 
    422         strncpy(calnote->text, summary, GN_CALNOTE_MAX_LENGTH);  
    423 } 
    424  
    425 void static _xmlfield_location(gn_calnote *calnote, OSyncXMLField *xmlfield) 
    426 { 
    427         const char *location = osync_xmlfield_get_key_value(xmlfield, "Content"); 
    428 //      if (calnote->type == GN_CALNOTE_MEETING && location) 
    429         strncpy(calnote->mlocation, location, GN_CALNOTE_MAX_LENGTH); 
    430 } 
    431  
    432 void static _xmlfield_description(gn_calnote *calnote, OSyncXMLField *xmlfield) 
    433 { 
    434  
    435         const char *description = osync_xmlfield_get_key_value(xmlfield, "Content"); 
    436 //      if (calnote->type == GN_CALNOTE_CALL || gnokii_util_valid_number(tmp)) 
    437         strncpy(calnote->phone_number, description, GN_CALNOTE_NUMBER_MAX_LENGTH); 
    438 } 
    439  
    440 void static _xmlfield_recurrencerule(gn_calnote *calnote, OSyncXMLField *xmlfield) 
    441 { 
    442         int interval = 0; 
    443  
    444         const char *freq = osync_xmlfield_get_key_value(xmlfield, "Frequency"); 
    445  
    446         if (!strcasecmp(freq, "DAILY")) 
    447                 calnote->recurrence = GN_CALNOTE_DAILY; 
    448         else if (!strcasecmp(freq, "WEEKLY"))  
    449                 calnote->recurrence = GN_CALNOTE_WEEKLY; 
    450         else if (!strcasecmp(freq, "MONTHLY")) 
    451                 calnote->recurrence = GN_CALNOTE_MONTHLY; 
    452         else if (!strcasecmp(freq, "YEARLY")) 
    453                 calnote->recurrence = GN_CALNOTE_YEARLY; 
    454  
    455         const char *ival = osync_xmlfield_get_key_value(xmlfield, "Interval"); 
    456  
    457         if (ival) 
    458                 sscanf(ival, "%u", &interval); 
    459  
    460         // TODO: Get this merged by demerger.... 
    461         // Nokia phones only support a interval of 2 for weeks 
    462         if (calnote->recurrence == GN_CALNOTE_WEEKLY && interval == 2) 
    463                 calnote->recurrence = GN_CALNOTE_2WEEKLY; 
    464 } 
    465  
    466  
    467291/*  
    468292 * Converts from XMLFormat-event to the gnokii event object type (gn_calnote). 
     
    473297                        output, outpsize, config, free_input, error); 
    474298 
    475         OSyncXMLFormat *xmlformat = (OSyncXMLFormat *)input; 
    476         unsigned int size; 
    477         char *str; 
    478         osync_xmlformat_assemble(xmlformat, &str, &size); 
    479         osync_trace(TRACE_INTERNAL, "Input XMLFormat is:\n%s", str); 
    480         g_free(str); 
    481  
    482 //      struct tm *starttm = NULL, *endtm = NULL, *tmptm = NULL; 
     299        osync_trace(TRACE_SENSITIVE, "Input XML is:\n%s", osxml_write_to_string((xmlDoc *)input)); 
     300 
     301        char *tmp; 
     302        struct tm *starttm = NULL, *endtm = NULL, *tmptm = NULL; 
     303        int offset = 0; 
    483304        osync_bool alldayevent = 0; 
    484  
    485         if (strcmp("event", osync_xmlformat_get_objtype(xmlformat))) { 
    486                 osync_error_set(error, OSYNC_ERROR_GENERIC, "Wrong xmlformat: %s",  osync_xmlformat_get_objtype(xmlformat)); 
     305        xmlNode *cur = NULL; 
     306        xmlNode *root = xmlDocGetRootElement((xmlDoc *)input); 
     307 
     308        if (!root) { 
     309                osync_error_set(error, OSYNC_ERROR_GENERIC, "Unable to get xml root element"); 
    487310                goto error; 
    488311        } 
    489312 
     313        if (xmlStrcmp(root->name, (xmlChar *) "vcal")) { 
     314                osync_error_set(error, OSYNC_ERROR_GENERIC, "Wrong (event) xml root element"); 
     315                goto error; 
     316        } 
     317 
     318        // Event child 
     319        root = osxml_get_node(root, "Event"); 
     320 
    490321        // prepare calnote 
    491         gn_calnote *calnote = osync_try_malloc0(sizeof(gn_calnote), error); 
    492  
    493         OSyncXMLField *xmlfield = osync_xmlformat_get_first_field(xmlformat); 
    494         for (; xmlfield; xmlfield = osync_xmlfield_get_next(xmlfield)) { 
    495                 osync_trace(TRACE_INTERNAL, "Field: %s", osync_xmlfield_get_name(xmlfield)); 
    496  
    497                 if (!strcmp("Categories", osync_xmlfield_get_name(xmlfield))) 
    498                         _xmlfield_category(calnote, xmlfield); 
    499                 else if (!strcmp("DateStarted", osync_xmlfield_get_name(xmlfield))) 
    500                         _xmlfield_datestarted(calnote, xmlfield, &alldayevent); 
    501                 else if (!strcmp("DateEnd", osync_xmlfield_get_name(xmlfield))) 
    502                         _xmlfield_dateend(calnote, xmlfield); 
    503                 else if (!strcmp("Alarm", osync_xmlfield_get_name(xmlfield))) 
    504                         _xmlfield_alarm(calnote, xmlfield); 
    505                 else if (!strcmp("Summary", osync_xmlfield_get_name(xmlfield))) 
    506                         _xmlfield_summary(calnote, xmlfield); 
    507                 else if (!strcmp("Location", osync_xmlfield_get_name(xmlfield))) 
    508                         _xmlfield_location(calnote, xmlfield); 
    509                 else if (!strcmp("Description", osync_xmlfield_get_name(xmlfield))) 
    510                         _xmlfield_description(calnote, xmlfield); 
    511                 else if (!strcmp("RecurrenceRule", osync_xmlfield_get_name(xmlfield))) 
    512                         _xmlfield_recurrencerule(calnote, xmlfield); 
    513  
    514         } 
    515  
     322        gn_calnote *calnote = NULL; 
     323        calnote = (gn_calnote *) malloc(sizeof(gn_calnote)); 
     324 
     325        memset(calnote, 0, sizeof(gn_calnote)); 
     326 
     327        // Type 
     328        // TODO: handle more then one category - not only the first 
     329        cur = osxml_get_node(root, "Categories"); 
     330        if (cur) { 
     331 
     332                tmp = (char *) xmlNodeGetContent(cur); 
     333 
     334                if (!strcasecmp(tmp, "Meeting")) 
     335                        calnote->type = GN_CALNOTE_MEETING; 
     336                else if (!strcasecmp(tmp, "Calling")) 
     337                        calnote->type = GN_CALNOTE_CALL; 
     338                else if (!strcasecmp(tmp, "Birthday")) 
     339                        calnote->type = GN_CALNOTE_BIRTHDAY; 
     340                else if (!strcasecmp(tmp, "Reminder")) 
     341                        calnote->type = GN_CALNOTE_REMINDER; 
     342                else if (!strcasecmp(tmp, "Memo")) 
     343                        calnote->type = GN_CALNOTE_MEMO; 
     344 
     345                else 
     346                        // When no known type was found it will check later 
     347                        // for a valid type.  
     348                        calnote->type = 0; 
     349 
     350                g_free(tmp); 
     351        } 
     352 
     353        // DateStarted  
     354        cur = osxml_get_node(root, "DateStarted"); 
     355        if (cur) { 
     356 
     357                tmp = osxml_find_node(cur, "Content"); 
     358 
     359                /* 
     360                ret = sscanf(tmp, "%04u%02u%02uT%02u%02u%02u", 
     361                                &(calnote->time.year), 
     362                                &(calnote->time.month), 
     363                                &(calnote->time.day), 
     364                                &(calnote->time.hour), 
     365                                &(calnote->time.minute), 
     366                                &(calnote->time.second)); 
     367                */               
     368 
     369                starttm = osync_time_vtime2tm(tmp); 
     370 
     371                if (!osync_time_isdate(tmp) && osync_time_isutc(tmp)) { 
     372                        tmptm = starttm; 
     373                        offset = osync_time_timezone_diff(tmptm); 
     374                        starttm = osync_time_tm2localtime(tmptm, offset); 
     375                        g_free(tmptm); 
     376                } 
     377 
     378                calnote->time = gnokii_util_tm2timestamp(starttm); 
     379 
     380                g_free(starttm); 
     381 
     382                // Only 3 matches (=date) means all day event  
     383                if (osync_time_isdate(tmp)) 
     384                        alldayevent = 1; 
     385 
     386                g_free(tmp); 
     387                         
     388 
     389                // Nokia cellphones cannot handle seconds in calendar - so set it to ZERO 
     390                calnote->time.second = 0; 
     391        } 
    516392                 
    517393 
     394        // DateEnd 
     395        cur = osxml_get_node(root, "DateEnd"); 
     396        if (cur) { 
     397 
     398                tmp = osxml_find_node(cur, "Content"); 
     399 
     400                endtm = osync_time_vtime2tm(tmp); 
     401                if (!osync_time_isdate(tmp) && osync_time_isutc(tmp)) { 
     402                        tmptm = endtm; 
     403                        endtm = osync_time_tm2localtime(tmptm, offset); 
     404                        g_free(tmptm); 
     405                } 
     406 
     407                g_free(tmp); 
     408 
     409                calnote->end_time = gnokii_util_tm2timestamp(endtm); 
     410 
     411                g_free(endtm); 
     412 
     413                // Nokia cellphones cannot handle seconds in calendar so set it to ZERO 
     414                calnote->end_time.second = 0; 
     415        } 
     416 
     417        /* Alarm - TODO: is not fully supported 
     418         *              Not supported: 
     419         *              ^^^^^^^^^^^^^^ 
     420         *              # alarm after event 
     421         *              # alarm before event end 
     422         *              # ... 
     423         */ 
     424        cur = osxml_get_node(root, "Alarm"); 
     425        if (cur && calnote->time.year) { 
     426 
     427                int seconds_before = 0; 
     428                time_t start_timet, alarm_timet; 
     429 
     430                calnote->alarm.enabled = 1; 
     431                 
     432                tmp = osxml_find_node(cur, "AlarmAction"); 
     433                if (tmp && !strcasecmp(tmp, "DISPLAY")) 
     434                        calnote->alarm.tone = 1; 
     435 
     436                g_free(tmp); 
     437                 
     438                // get AlarmTrigger root 
     439                xmlNode *sub = osxml_get_node(cur, "AlarmTrigger"); 
     440 
     441                // get node with iCal duration 
     442                tmp = osxml_find_node(sub, "Content"); 
     443 
     444                // convert iCal duration string into seconds (before event) 
     445                seconds_before = gnokii_util_alarmevent2secs(tmp); 
     446 
     447                g_free(tmp); 
     448                 
     449                // convert start event in to seconds 
     450                start_timet = gnokii_util_timestamp2unix(&(calnote->time)); 
     451 
     452                // timestamp for alarm 
     453                alarm_timet = start_timet - seconds_before; 
     454 
     455                // convert timestamp of alarm to gnokii timestamp 
     456                calnote->alarm.timestamp = gnokii_util_unix2timestamp(alarm_timet); 
     457        } 
     458 
     459        // Summary 
     460        cur = osxml_get_node(root, "Summary"); 
     461        if (cur) { 
     462                tmp = (char *) xmlNodeGetContent(cur); 
     463                strncpy(calnote->text, tmp, sizeof(calnote->text));  
     464                g_free(tmp); 
     465        } 
     466 
     467        // meeting location 
     468        cur = osxml_get_node(root, "Location"); 
     469        if (cur) { 
     470                tmp = (char *) xmlNodeGetContent(cur); 
     471 
     472                if (calnote->type == GN_CALNOTE_MEETING && tmp) 
     473                        strncpy(calnote->mlocation, tmp, sizeof(calnote->mlocation)); 
     474 
     475                g_free(tmp); 
     476        } 
     477 
     478        // PhoneNumber 
     479        cur = osxml_get_node(root, "Description"); 
     480        if (cur) { 
     481                tmp = (char *) xmlNodeGetContent(cur); 
     482                if (calnote->type == GN_CALNOTE_CALL || gnokii_util_valid_number(tmp)) 
     483                        strncpy(calnote->phone_number, tmp, sizeof(calnote->phone_number)); 
     484 
     485                g_free(tmp); 
     486        } 
     487 
     488        // Reccurence 
     489        cur = osxml_get_node(root, "RecurrenceRule"); 
     490        if (cur) { 
     491                int interval = 0; 
     492 
     493                for (cur = cur->children; cur; cur = cur->next) { 
     494 
     495                        tmp = (char *) xmlNodeGetContent(cur); 
     496 
     497                        if (strstr(tmp, "DAILY")) 
     498                                calnote->recurrence = GN_CALNOTE_DAILY; 
     499                        else if (strstr(tmp, "WEEKLY"))  
     500                                calnote->recurrence = GN_CALNOTE_WEEKLY; 
     501                        else if (strstr(tmp, "MONTHLY")) 
     502                                calnote->recurrence = GN_CALNOTE_MONTHLY; 
     503                        else if (strstr(tmp, "YEARLY")) 
     504                                calnote->recurrence = GN_CALNOTE_YEARLY; 
     505 
     506                        else if (strstr(tmp, "INTERVAL")) 
     507                                sscanf(tmp, "INTERVAL=%u", &interval); 
     508 
     509                        g_free(tmp); 
     510                } 
     511 
     512                // Nokia phones only support a interval of 2 for weeks 
     513                if (calnote->recurrence == GN_CALNOTE_WEEKLY && interval == 2) 
     514                        calnote->recurrence = GN_CALNOTE_2WEEKLY; 
     515        } 
    518516 
    519517        // check for type which fits for given data if no type was set 
    520518        if (!calnote->type) 
    521519                calnote->type = gnokii_util_calendar_type(calnote, alldayevent); 
     520 
    522521 
    523522        *free_input = TRUE; 
     
    534533 
    535534 
    536 static void destroy_gnokii_event(char *input, unsigned int inpsize) 
     535static void destroy_gnokii_event(char *input, size_t inpsize) 
    537536{ 
    538537        osync_trace(TRACE_ENTRY, "%s(%p, %i)", __func__, input, inpsize); 
  • plugins/gnokii-sync/src/gnokii_calendar_utils.c

    r2133 r2142  
    3030 * Returns: seconds before event 
    3131 */ 
    32 int gnokii_util_alarmevent2secs(const char *alarm) { 
     32int gnokii_util_alarmevent2secs(char *alarm) { 
    3333 
    3434        osync_trace(TRACE_ENTRY, "%s(%s)", __func__, alarm); 
     
    240240        date = gnokii_util_timestamp2tm(timestamp); 
    241241        timet = mktime(date); 
    242         g_free(date); 
    243242 
    244243        osync_trace(TRACE_EXIT, "%s: %ul", __func__, timet); 
  • plugins/gnokii-sync/src/gnokii_calendar_utils.h

    r2133 r2142  
    2626gn_timestamp gnokii_util_tm2timestamp(const struct tm *timetm); 
    2727time_t gnokii_util_timestamp2unix(gn_timestamp *timestamp); 
    28 int gnokii_util_alarmevent2secs(const char *alarm); 
     28int gnokii_util_alarmevent2secs(char *alarm); 
    2929char *gnokii_util_secs2alarmevent(int secs_before_event);  
    30 osync_bool gnokii_util_valid_number(const char *number);  
     30osync_bool gnokii_util_valid_number(char *number);  
    3131gn_calnote_type gnokii_util_calendar_type(gn_calnote *calnote, osync_bool alldayevent); 
    3232 
  • plugins/gnokii-sync/src/gnokii_config.c

    r2099 r2142  
    2121#include "gnokii_sync.h" 
    2222 
     23/* Set connection types 
     24 */ 
     25void parse_connection_type(char *str, gn_config *config) { 
     26 
     27        if (!strcasecmp(str, "bluetooth")) 
     28                config->connection_type = GN_CT_Bluetooth; 
     29        else if (!strcasecmp(str, "irda")) 
     30                config->connection_type = GN_CT_Irda; 
     31        else if (!strcasecmp(str, "dku2")) 
     32                config->connection_type = GN_CT_DKU2; 
     33        else if (!strcasecmp(str, "dau9p")) 
     34                config->connection_type = GN_CT_DAU9P; 
     35        else if (!strcasecmp(str, "dlr3p")) 
     36                config->connection_type = GN_CT_DLR3P; 
     37        else if (!strcasecmp(str, "serial")) 
     38                config->connection_type = GN_CT_Serial; 
     39        else if (!strcasecmp(str, "infrared")) 
     40                config->connection_type = GN_CT_Infrared; 
     41        else if (!strcasecmp(str, "tekram")) 
     42                config->connection_type = GN_CT_Tekram; 
     43        else if (!strcasecmp(str, "tcp")) 
     44                config->connection_type = GN_CT_TCP; 
     45        else if (!strcasecmp(str, "m2bus")) 
     46                config->connection_type = GN_CT_M2BUS; 
     47        else if (!strcasecmp(str, "dku2libusb")) 
     48                config->connection_type = GN_CT_DKU2LIBUSB; 
     49        else 
     50                config->connection_type = GN_CT_NONE; 
     51} 
     52 
    2353/* Parse config file of gnokii plugin  
    2454 * 
     
    2757 * ReturnVal: false     on error 
    2858 */ 
    29 osync_bool gnokii_config_parse(struct gn_statemachine *state, const char *data, OSyncError **error) 
     59osync_bool gnokii_config_parse(gn_config *config, const char *data, OSyncError **error) 
    3060{ 
    31         osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, state, data, error); 
    32         int i = 0; 
     61        osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, config, data, error); 
    3362        char *str = NULL; 
    34         char **lines = malloc(sizeof(char*) * 10); 
    35         memset(lines, 0, sizeof(char*) * 10); 
    3663        xmlDocPtr doc; 
    3764        xmlNodePtr cur; 
     
    6390        cur = cur->xmlChildrenNode; 
    6491 
    65         lines[i] = g_strdup("[global]"); 
    66  
    6792        while (cur != NULL) { 
    6893                str = (char *) xmlNodeGetContent(cur); 
     
    7095                if (str) { 
    7196                        if (!xmlStrcmp(cur->name, (const xmlChar *) "model")) 
    72                                 lines[++i] = g_strdup_printf("model = %s", str); 
     97                                strncpy(config->model, str, strlen(str)); 
    7398         
    7499                        if (!xmlStrcmp(cur->name, (const xmlChar *) "port")) 
    75                                 lines[++i] = g_strdup_printf("port = %s", str); 
     100                                strncpy(config->port_device, str, strlen(str)); 
    76101 
    77                         if (!xmlStrcmp(cur->name, (const xmlChar *) "connection")) 
    78                                 lines[++i] = g_strdup_printf("connection = %s", str); 
     102                        if (!xmlStrcmp(cur->name, (const xmlChar *) "connection")) { 
     103                                // check for connection types which are supported by gnokii. 
     104                                parse_connection_type(str, config); 
     105                        } 
    79106 
    80107                        // rfcomm channel 
    81                         if (!xmlStrcmp(cur->name, (const xmlChar *) "rfcomm_channel")) 
    82                                 lines[++i] = g_strdup_printf("rfcomm_channel = %s", str); 
     108                        if (!xmlStrcmp(cur->name, (const xmlChar *) "rfcomm_channel")) { 
     109                                config->rfcomm_cn = atoi(str); 
     110                        } 
    83111 
    84112                        // check for debug option of libgnokii 
    85113                        if (!xmlStrcmp(cur->name, (const xmlChar *) "debug")) { 
    86                                 lines[++i] = g_strdup("[logging]"); 
    87                                 lines[++i] = g_strdup_printf("debug = %s", str); 
     114                                if (!strcasecmp(str, "on")) 
     115                                       gn_log_debug_mask = GN_LOG_T_STDERR;    // debug output to stderr 
    88116                        } 
    89117                        g_free(str); 
     
    93121        } 
    94122 
    95         /* TODO: adapt error handling to return value of gn_cfg_phone_load() 
    96123        if (!strlen(config->model)) { 
    97124                osync_error_set(error, OSYNC_ERROR_GENERIC, "Model is not set in configuration"); 
     
    111138                return FALSE; 
    112139        } 
    113         */ 
    114140 
    115         gn_cfg_memory_read(lines); 
    116         gn_cfg_phone_load(NULL, state);  
    117  
    118         for (i=0; lines[i] != NULL; i++) 
    119                 g_free(lines[i]); 
    120  
    121         g_free(lines); 
    122141 
    123142        xmlFreeDoc(doc); 
     
    126145} 
    127146 
     147/* Fill the statemachine struct for libgnokii with: 
     148 * model, port (serial connection) or MAC address (bluetooth) and connection type. 
     149 * This is required for the cellphone connection.  
     150 * 
     151 */ 
     152void gnokii_config_state(struct gn_statemachine *state, gn_config *config) { 
     153 
     154        /* model */ 
     155        strncpy(state->config.model, config->model, GN_MODEL_MAX_LENGTH); 
     156 
     157        /* port (bluetooth: destination mac address) */ 
     158        strncpy(state->config.port_device, config->port_device, GN_DEVICE_NAME_MAX_LENGTH); 
     159 
     160        /* connection type - gn_connection_type */ 
     161        state->config.connection_type = config->connection_type;  
     162 
     163        /* rfcomm channel */ 
     164        state->config.rfcomm_cn = config->rfcomm_cn; 
     165         
     166} 
     167 
  • plugins/gnokii-sync/src/gnokii_config.h

    r2099 r2142  
    2121#include <gnokii.h> 
    2222 
    23 osync_bool gnokii_config_parse(struct gn_statemachine *state, const char *data, OSyncError **error); 
     23void gnokii_config_state(struct gn_statemachine *state, gn_config *config); 
     24osync_bool gnokii_config_parse(gn_config *config, const char *data, OSyncError **error); 
    2425 
  • plugins/gnokii-sync/src/gnokii_contact.c

    r2134 r2142  
    158158                        if (error == GN_ERR_EMPTYLOCATION) { 
    159159                                osync_trace(TRACE_EXIT, "%s(): memorty_type: %i location: %i counter: %i", __func__, contact->memory_type, contact->location, i); 
    160                                 g_free(data); 
    161160                                return contact; 
    162161                        } 
     
    167166        } 
    168167 
    169         g_free(data); 
    170         g_free(contact); 
     168        // TODO set error and leave 
    171169        osync_trace(TRACE_EXIT, "%s(): NO FREE LOCATION!", __func__); 
    172170        return NULL; 
     
    361359        gn_phonebook_entry *contact = NULL; 
    362360        gn_memory_status memstat; 
    363         gn_data *data = osync_try_malloc0(sizeof(gn_data), &error);  
     361        gn_data *data = (gn_data *) malloc(sizeof(gn_data)); 
     362 
     363        memset(data, 0, sizeof(gn_data)); 
    364364 
    365365        OSyncObjTypeSink *sink = osync_plugin_info_get_sink(info); 
     
    367367        gnokii_sinkenv *sinkenv = osync_objtype_sink_get_userdata(sink); 
    368368        gnokii_environment *env = (gnokii_environment *) plugindata;&n