gnokii-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnokii 0.6.0 and LDIF import


From: Michael Klemme
Subject: gnokii 0.6.0 and LDIF import
Date: Sun, 21 Mar 2004 16:08:10 -0000
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040113

Hallo!

I have some scripts that create an LDIF file that I then import into Mozilla and two web mail providers.

I would like to extend this to my Nokia 6310i mibile as well, using gnokii over bluetooth.


I could not find out how to replace the complete ME addressbook using the comman line options available. I therefore created a new option "-replace" that overwrites the phone book from entry 1 onwards.
Patch attached.


I think attribute names in LDAP/LDIF are case insensitive (but I am not 100% sure). Therfore, I used 'strncasecmp' to compare attribute names (patch attached). I hope this is available beyond Linux.
I also added some more field names for fax and mobile phones.


gnokii requires a 'telephoneNumber' entry. Otherwise the entire entry is refused. According to Mozills this is the work phone of a person.

However, this number is not written to my Nokia (using the nk6510 driver), it just disappears. The 'telephoneNumber' is written to entry->number and not into a subentry field
I modified the program to set entry->number from the first number sub-entry.
This solution still fails on entries without any phone number, but as far as my mobile is concerned I do not care.


All entries are group family.
How can that be changed?
This info is not written on LDIF export from the phone.


I encode all texts such as names base64.
However, the text in the mobile is cut off exactly at this position. Why?




Cheers
        Michael
--- gnokii/gnokii.c.orig        Sun Feb 22 23:44:27 2004
+++ gnokii/gnokii.c     Sun Mar 21 13:55:35 2004
@@ -3303,6 +3303,8 @@
                                1 - vCard
                                2 - LDIF
                        */
+       int replace = 0; /* replace entire telephone book */
+       
        char *line, oline[MAX_INPUT_LINE_LEN];
        int i;
 
@@ -3315,11 +3317,12 @@
                { "memory",             required_argument,      NULL, 'm'},
                { "memory-location",    required_argument,      NULL, 'n'},
                { "location",           required_argument,      NULL, 'n'},
+               { "replace",            0,                      NULL, 'r'},
                { NULL,                 0,                      NULL, 0}
        };
 
        /* Option parsing */
-       while ((i = getopt_long(argc, args, "ovlfm:n:", options, NULL)) != -1) {
+       while ((i = getopt_long(argc, args, "ovlfm:n:r", options, NULL)) != -1) 
{
                switch (i) {
                case 'o':
                        confirm = 1;
@@ -3340,6 +3343,9 @@
                case 'n':
                        default_location = atoi(optarg);
                        break;
+               case 'r':
+                       replace=1;
+                       break;
                default:
                        usage(stderr, -1);
                        break;
@@ -3379,7 +3385,11 @@
 
                error = GN_ERR_NONE;
 
-               if (find_free) {
+               if (replace) {
+                 /* automatically pick next location */
+                 entry.location =  default_location ++;
+               }
+               else if (find_free) {
 #if 0
                        error = gn_sm_functions(GN_OP_FindFreePhonebookEntry, 
&data, &state);
                        if (error == GN_ERR_NOTIMPLEMENTED) {
@@ -3408,7 +3418,7 @@
                                break;
                        }
                }
-
+               
                if (!confirm) {
                        gn_phonebook_entry aux;
 
@@ -3448,9 +3458,14 @@
                        fprintf (stderr, 
                                 _("Write Succeeded: memory type: %s, loc: %d, 
name: %s, number: %s\n"), 
                                 gn_memory_type2str(entry.memory_type), 
entry.location, entry.name, entry.number);
-               else
-                       fprintf (stderr, _("Write FAILED (%s): memory type: %s, 
loc: %d, name: %s, number: %s\n"), 
-                                gn_error_print(error), 
gn_memory_type2str(entry.memory_type), entry.location, entry.name, 
entry.number);
+               else {
+                 fprintf (stderr, _("Write FAILED (%s): memory type: %s, loc: 
%d, name: %s, number: %s\n"), 
+                          gn_error_print(error), 
gn_memory_type2str(entry.memory_type), entry.location, entry.name, 
entry.number);
+                 if (replace) {
+                   /* try saving to this slot for next entry */
+                   entry.location =  --default_location;
+                 }
+               }
        }
        return error;
 }
--- common/ldif.c.orig  Sun Feb 22 23:44:27 2004
+++ common/ldif.c       Sun Mar 21 16:06:35 2004
@@ -139,7 +139,7 @@
        return 0;
 }
 
-#define BEGINS(a) ( !strncmp(buf, a, strlen(a)) )
+#define BEGINS(a) ( !strncasecmp(buf, a, strlen(a)) )
 #define STORE2(a, b, c) if (BEGINS(a)) { c; strncpy(b, buf+strlen(a), 
strlen(buf)-strlen(a)-1); continue; }
 #define STORE2_BASE64(a, b, c) if (BEGINS(a)) { c; utf8_base64_decode(b, 
GN_PHONEBOOK_NAME_MAX_LENGTH, buf+strlen(a), strlen(buf)-strlen(a)-1); 
continue; }
 
@@ -164,6 +164,7 @@
 API int gn_ldif2phonebook(FILE *f, gn_phonebook_entry *entry)
 {
        char buf[10240];
+       int i;
 
        while (1) {
                if (!fgets(buf, 1024, f))
@@ -179,8 +180,6 @@
                }
                STORE("cn: ", entry->name);
                STORE_BASE64("cn:: ", entry->name);
-               STORE("telephoneNumber: ", entry->number);
-               STORE_BASE64("telephoneNumber:: ", entry->number);
 
                STORESUB("homeurl: ", GN_PHONEBOOK_ENTRY_URL);
                STORESUB_BASE64("homeurl:: ", GN_PHONEBOOK_ENTRY_URL);
@@ -190,13 +189,16 @@
                STORESUB_BASE64("homePostalAddress:: ", 
GN_PHONEBOOK_ENTRY_Postal);
                STORESUB("Description: ", GN_PHONEBOOK_ENTRY_Note);
                STORESUB_BASE64("Description:: ", GN_PHONEBOOK_ENTRY_Note);
-
                STORENUM("homePhone: ", GN_PHONEBOOK_NUMBER_Home);
                STORENUM_BASE64("homePhone:: ", GN_PHONEBOOK_NUMBER_Home);
                STORENUM("mobile: ", GN_PHONEBOOK_NUMBER_Mobile);
-               STORENUM_BASE64("mobile:: ", GN_PHONEBOOK_NUMBER_Mobile);
+               STORENUM_BASE64("cellphone:: ", GN_PHONEBOOK_NUMBER_Mobile);
+               STORENUM("mobile: ", GN_PHONEBOOK_NUMBER_Mobile);
+               STORENUM_BASE64("cellphone:: ", GN_PHONEBOOK_NUMBER_Mobile);
                STORENUM("fax: ", GN_PHONEBOOK_NUMBER_Fax);
                STORENUM_BASE64("fax:: ", GN_PHONEBOOK_NUMBER_Fax);
+               STORENUM("facsimiletelephonenumber: ", GN_PHONEBOOK_NUMBER_Fax);
+               STORENUM_BASE64("facsimiletelephonenumber:: ", 
GN_PHONEBOOK_NUMBER_Fax);
                STORENUM("workPhone: ", GN_PHONEBOOK_NUMBER_Work);
                STORENUM_BASE64("workPhone:: ", GN_PHONEBOOK_NUMBER_Work);
                STORENUM("telephoneNumber: ", GN_PHONEBOOK_NUMBER_General);
@@ -204,6 +206,24 @@
 
                if (BEGINS("\n"))
                        break;
+       }
+
+       /* set entry->number from the first sub-entry that is a number */
+       for (i=0; i < entry->subentries_count && entry->number[0] == 0; i++) {
+         if (entry->subentries[i].entry_type == GN_PHONEBOOK_ENTRY_Number) {
+           switch (entry->subentries[i].number_type) 
+             {
+             case GN_PHONEBOOK_NUMBER_General:
+             case GN_PHONEBOOK_NUMBER_Work: 
+             case GN_PHONEBOOK_NUMBER_Home:
+             case GN_PHONEBOOK_NUMBER_Mobile:
+               {
+                 printf ("setting default number to %s\n", 
entry->subentries[i].data.number);
+                 strcpy (entry->number, entry->subentries[i].data.number);
+                 break;
+               }
+             }
+         }
        }
        return 0;
 }

reply via email to

[Prev in Thread] Current Thread [Next in Thread]