Hi Nabil, Il giorno mar, 08/11/2005 alle 17.08 +0100, Nabil Sayegh ha scritto:
> Up to 4096 should be no problem 0xd000 - 0xdfff. > Of course we can use other bases, too. Which, i will to use it for separate DATE and METADATE. > I had the same idea, when I started, but that's more or less the same dilemma > like in 4) I'm happy to known that yuo had the same idea! > The advantage of dedicated IDs would be, that apps that know how to handle CE > would easily be able to interprete the additional fields, without having to > implement a vCard parser. Right, I agree with you. > Yes, a mixture of 1) and 3) > > X-AIM;TYPE=HOME;X-EVOLUTION-UI-SLOT=1:aim > => > ID_MESSAGING_AIM_HOME > ID_MESSAGING_AIM_HOME_META (or _EVOLUTION whatever) I will try this. Before do anything, I extended the enqueue_field/process_queue algorithm for manage any fields type so not only tel_home/tel_work/email are handled but any fields that use TYPE=PREF are automatically handled (mobile phone, fax, messaging). For types that not use TYPE=PREF nothing change. I think is a good idea, and you ? With the previous patch seems easy to add more entry of the same type. I wrote a patch for increase the number of email, tel_home and tel_work. If you agree with my for these two patch I will try to handle metadata. The patchs attached is wrote for the libraries rra modifies by my (in particular with the entry-fields and multiline patchs that I posted some day ago). Regards Sergio
--- ./lib/synce_ids.h.orig 2005-11-10 17:12:13.000000000 +0100 +++ ./lib/synce_ids.h 2005-11-10 17:12:02.000000000 +0100 @@ -0,0 +1,11 @@ +#ifndef __synce_ids_h__ +#define __synce_ids_h__ + +#define SYNCE_ID_BASE 0xd000 +#define ID_EMAIL4 (SYNCE_ID_BASE+0) +#define ID_HOME3_TEL (SYNCE_ID_BASE+1) +#define ID_HOME4_TEL (SYNCE_ID_BASE+2) +#define ID_WORK3_TEL (SYNCE_ID_BASE+3) +#define ID_WORK4_TEL (SYNCE_ID_BASE+4) + +#endif --- ./lib/contact.c.orig 2005-11-10 17:10:38.000000000 +0100 +++ ./lib/contact.c 2005-11-10 17:33:02.000000000 +0100 @@ -2,6 +2,7 @@ #define _GNU_SOURCE 1 #include "contact.h" #include "contact_ids.h" +#include "synce_ids.h" #include "strbuf.h" #include "dbstream.h" #include "strv.h" @@ -368,6 +369,8 @@ break; case ID_HOME2_TEL: + case ID_HOME3_TEL: + case ID_HOME4_TEL: strbuf_append_tel_type(vcard, "HOME,VOICE", flags); strbuf_append_escaped_wstr(vcard, pFields[i].val.lpwstr, flags); strbuf_append_crlf(vcard); @@ -380,6 +383,8 @@ break; case ID_WORK2_TEL: + case ID_WORK3_TEL: + case ID_WORK4_TEL: strbuf_append_tel_type(vcard, "WORK,VOICE", flags); strbuf_append_escaped_wstr(vcard, pFields[i].val.lpwstr, flags); strbuf_append_crlf(vcard); @@ -480,6 +485,7 @@ case ID_EMAIL2: case ID_EMAIL3: + case ID_EMAIL4: strbuf_append_type(vcard, "EMAIL", "INTERNET", flags); strbuf_append_escaped_wstr(vcard, pFields[i].val.lpwstr, flags); strbuf_append_crlf(vcard); @@ -803,6 +809,8 @@ INDEX_WORK_FAX, INDEX_HOME_FAX, INDEX_HOME2_TEL, + INDEX_HOME3_TEL, + INDEX_HOME4_TEL, INDEX_BIRTHDAY, INDEX_ANNIVERSARY, INDEX_CATEGORY, @@ -810,6 +818,8 @@ INDEX_ASSISTANT_TEL, INDEX_CHILDREN, INDEX_WORK2_TEL, + INDEX_WORK3_TEL, + INDEX_WORK4_TEL, INDEX_WEB_PAGE, INDEX_PAGER, INDEX_SPOUSE, @@ -834,6 +844,7 @@ INDEX_EMAIL, INDEX_EMAIL2, INDEX_EMAIL3, + INDEX_EMAIL4, ID_COUNT } field_index; @@ -883,6 +894,8 @@ ID_WORK_FAX, ID_HOME_FAX, ID_HOME2_TEL, + ID_HOME3_TEL, + ID_HOME4_TEL, ID_BIRTHDAY, ID_ANNIVERSARY, ID_CATEGORY, @@ -890,6 +903,8 @@ ID_ASSISTANT_TEL, ID_CHILDREN, ID_WORK2_TEL, + ID_WORK3_TEL, + ID_WORK4_TEL, ID_WEB_PAGE, ID_PAGER, ID_SPOUSE, @@ -913,7 +928,8 @@ ID_OTHER_COUNTRY, ID_EMAIL, ID_EMAIL2, - ID_EMAIL3 + ID_EMAIL3, + ID_EMAIL4 }; static char* strdup_quoted_printable(const unsigned char* source)/*{{{*/ @@ -1217,6 +1233,12 @@ case 1: add_string(parser, INDEX_HOME2_TEL, type, value); break; + case 2: + add_string(parser, INDEX_HOME3_TEL, type, value); + break; + case 3: + add_string(parser, INDEX_HOME4_TEL, type, value); + break; } } } @@ -1233,6 +1255,12 @@ case 1: add_string(parser, INDEX_WORK2_TEL, type, value); break; + case 2: + add_string(parser, INDEX_WORK3_TEL, type, value); + break; + case 3: + add_string(parser, INDEX_WORK4_TEL, type, value); + break; } } } @@ -1283,6 +1311,9 @@ case 2: add_string(parser, INDEX_EMAIL3, type, value); break; + case 3: + add_string(parser, INDEX_EMAIL4, type, value); + break; } }/*}}}*/ else if (STR_EQUAL(name, "URL"))/*{{{*/
--- ./lib/contact.c.orig 2005-11-10 14:59:05.000000000 +0100 +++ ./lib/contact.c 2005-11-10 16:57:05.000000000 +0100 @@ -780,6 +780,9 @@ CEPROPVAL* fields; size_t field_index; bool utf8; /* default charset is utf8 */ + int count_email; + int count_tel_work; + int count_tel_home; } Parser; typedef enum _field_index @@ -1083,10 +1086,8 @@ Parser* parser, char* name, char* type, - char* value, - int nth) + char* value) { - bool success = false; #if VERBOSE @@ -1115,7 +1116,7 @@ } }/*}}}*/ - if (parser->level != 1 && nth==0) + if (parser->level != 1) { synce_error("Not within BEGIN:VCARD / END:VCARD"); goto exit; @@ -1205,17 +1206,35 @@ /* TODO: make type uppercase */ if (STR_IN_STR(type, "HOME")) { - if (nth<=1) - add_string(parser, fax ? INDEX_HOME_FAX : INDEX_HOME_TEL, type, value); - else - add_string(parser, INDEX_HOME2_TEL, type, value); + if (fax) { + add_string(parser, INDEX_HOME_FAX, type, value); + } else { + switch (parser->count_tel_home++) + { + case 0: + add_string(parser, INDEX_HOME_TEL, type, value); + break; + case 1: + add_string(parser, INDEX_HOME2_TEL, type, value); + break; + } + } } else if (STR_IN_STR(type, "WORK")) { - if (nth<=1) - add_string(parser, fax ? INDEX_WORK_FAX : INDEX_WORK_TEL, type, value); - else - add_string(parser, INDEX_WORK2_TEL, type, value); + if (fax) { + add_string(parser, INDEX_WORK_FAX, type, value); + } else { + switch (parser->count_tel_work++) + { + case 0: + add_string(parser, INDEX_WORK_TEL, type, value); + break; + case 1: + add_string(parser, INDEX_WORK2_TEL, type, value); + break; + } + } } else if (STR_IN_STR(type, "CELL")) { @@ -1253,15 +1272,15 @@ type, name); } - switch (nth) + switch (parser->count_email++) { - case 1: - add_string(parser, INDEX_EMAIL, type, value); + case 0: + add_string(parser, INDEX_EMAIL, type, value); break; - case 2: + case 1: add_string(parser, INDEX_EMAIL2, type, value); break; - case 3: + case 2: add_string(parser, INDEX_EMAIL3, type, value); break; } @@ -1380,21 +1399,20 @@ void enqueue_field(/*{{{*/ struct FieldStrings *fs, int *count, - int max, struct FieldStrings *data) { int slot=-1; int i; /* if there are free slots, there is no problem */ - if ((*count)<max) + if ((*count)<MAX_FIELD_COUNT) slot=(*count); else if (data->pref) /* so there is no free slot, but a(nother) preferred one is coming kick out a non-preferred one, if possible */ - for (i=0; i<max; i++) - if (!fs[i].pref) { + for (i=0; i<MAX_FIELD_COUNT; i++) + if (!fs[i].pref && !strcmp(fs[i].type, data->type)) { slot=i; break; } @@ -1416,7 +1434,6 @@ int count) { int i; - int j=1; char *loc; /* Get the first preferred and make it the preferred one on the device */ @@ -1426,8 +1443,7 @@ parser, fs[i].name, fs[i].type, - fs[i].value, - j++); + fs[i].value); /* mark this as already processed */ fs[i].name=NULL; break; @@ -1449,8 +1465,7 @@ parser, fs[i].name, fs[i].type, - fs[i].value, - j++); + fs[i].value); } } }/*}}}*/ @@ -1479,13 +1494,9 @@ const char* value_end = NULL; char* value_ml = NULL; - struct FieldStrings *tel_work = malloc( MAX_TEL_WORK * sizeof( struct FieldStrings ) ); - struct FieldStrings *tel_home = malloc( MAX_TEL_HOME * sizeof( struct FieldStrings ) ); - struct FieldStrings *email = malloc( MAX_EMAIL * sizeof( struct FieldStrings ) ); + struct FieldStrings *queue_field = malloc( MAX_FIELD_COUNT * sizeof( struct FieldStrings ) ); struct FieldStrings *tmp_field = malloc( 1 * sizeof( struct FieldStrings ) ); - int count_tel_work = 0; - int count_tel_home = 0; - int count_email = 0; + int count_field = 0; parser.vcard_version = RRA_CONTACT_VERSION_UNKNOWN; parser.level = 0; @@ -1493,6 +1504,10 @@ parser.field_index = 0; parser.utf8 = flags & RRA_CONTACT_UTF8; + parser.count_email = 0; + parser.count_tel_work = 0; + parser.count_tel_home = 0; + for (count=0; count < ID_COUNT; count++) { CEPROPVAL* field = &parser.fields[parser.field_index++]; @@ -1584,41 +1599,16 @@ break; } - /* We have to queue tel and email fields, as there may be more than one, - and we have to find out, which one is the preferred. - Unfortunately there may be none, or many preferred fields :( - */ - tmp_field->name = strndup(name, name_end - name); tmp_field->type = type ? strndup(type, type_end - type) : strdup(""); - if (value_ml) - tmp_field->value = value_ml; - else - tmp_field->value = strndup(value, value_end - value); + tmp_field->value = strndup(value, value_end - value); tmp_field->pref = STR_IN_STR(tmp_field->type, "PREF"); - if ( STR_IN_STR(tmp_field->name, "TEL") && - STR_IN_STR(tmp_field->type, "WORK") && - !STR_IN_STR(tmp_field->type, "FAX")) { - enqueue_field(tel_work, &count_tel_work, MAX_TEL_WORK, tmp_field); - } - else if ( STR_IN_STR(tmp_field->name, "TEL") && - STR_IN_STR(tmp_field->type, "HOME") && - !STR_IN_STR(tmp_field->type, "FAX")) { - enqueue_field(tel_home, &count_tel_home, MAX_TEL_HOME, tmp_field); - } - else if (STR_IN_STR(tmp_field->name, "EMAIL")) { - enqueue_field(email, &count_email, MAX_EMAIL, tmp_field); - } - else { - parser_handle_field( - &parser, - tmp_field->name, - tmp_field->type, - tmp_field->value, - 0); - } + enqueue_field(queue_field, &count_field, tmp_field); state = VCARD_STATE_NEWLINE; + + if (value_ml) + free(value_ml); } p++; break;/*}}}*/ @@ -1636,7 +1626,10 @@ value = p; } else + { + value = value_ml; state = VCARD_STATE_VALUE; + } } else p++; @@ -1648,9 +1641,7 @@ } } - process_queue(&parser, tel_work, count_tel_work); - process_queue(&parser, tel_home, count_tel_home); - process_queue(&parser, email, count_email); + process_queue(&parser, queue_field, count_field); *field_count = parser.field_index;