11 #include "../misc/coding/coding.h" 17 if (strcmp(s,
"ME") == 0)
return MEM_ME;
18 else if (strcmp(s,
"SM") == 0)
return MEM_SM;
19 else if (strcmp(s,
"ON") == 0)
return MEM_ON;
20 else if (strcmp(s,
"DC") == 0)
return MEM_DC;
21 else if (strcmp(s,
"RC") == 0)
return MEM_RC;
22 else if (strcmp(s,
"MC") == 0)
return MEM_MC;
23 else if (strcmp(s,
"MT") == 0)
return MEM_MT;
24 else if (strcmp(s,
"FD") == 0)
return MEM_FD;
25 else if (strcmp(s,
"VM") == 0)
return MEM_VM;
26 else if (strcmp(s,
"SL") == 0)
return MEM_SL;
27 else if (strcmp(s,
"QD") == 0)
return MEM_QD;
37 static char split[] = {
'\0',
',',
'\0',
' ',
'\0',
'\0'};
39 int first = -1, last = -1, name = -1;
61 if (last != -1 && first != -1) {
66 }
else if (last != -1) {
68 }
else if (first != -1) {
93 if ((*Number) == -1) {
106 if (*Number != -1)
break;
128 int Name, Number, Group, i;
129 int firstname = -1, secondname = -1, lastname = -1;
130 int address = -1, city = -1, state = -1, zip = -1, country = -1;
131 int workaddress = -1, workcity = -1, workstate = -1, workzip = -1, workcountry = -1;
132 unsigned char buffer[1024];
141 error =
VC_StoreLine(Buffer, buff_len, Length,
"BEGIN:VCARD");
142 if (error !=
ERR_NONE)
return error;
148 if (error !=
ERR_NONE)
return error;
151 error =
VC_StoreLine(Buffer, buff_len, Length,
"TEL:%s",
153 if (error !=
ERR_NONE)
return error;
157 error =
VC_StoreLine(Buffer, buff_len, Length,
"VERSION:2.1");
158 if (error !=
ERR_NONE)
return error;
163 if (error !=
ERR_NONE)
return error;
166 if (error !=
ERR_NONE)
return error;
174 error =
VC_Store(Buffer, buff_len, Length,
"N");
175 if (error !=
ERR_NONE)
return error;
178 error =
VC_Store(Buffer, buff_len, Length,
"NICKNAME");
179 if (error !=
ERR_NONE)
return error;
182 error =
VC_Store(Buffer, buff_len, Length,
"FN");
183 if (error !=
ERR_NONE)
return error;
186 error =
VC_Store(Buffer, buff_len, Length,
"X-NAME-PREFIX");
187 if (error !=
ERR_NONE)
return error;
190 error =
VC_Store(Buffer, buff_len, Length,
"X-NAME-SUFFIX");
191 if (error !=
ERR_NONE)
return error;
247 if (error !=
ERR_NONE)
return error;
252 if (error !=
ERR_NONE)
return error;
266 error =
VC_Store(Buffer, buff_len, Length,
"TEL");
267 if (error !=
ERR_NONE)
return error;
270 error =
VC_Store(Buffer, buff_len, Length,
";PREF");
271 if (error !=
ERR_NONE)
return error;
275 error =
VC_Store(Buffer, buff_len, Length,
";HOME");
276 if (error !=
ERR_NONE)
return error;
279 error =
VC_Store(Buffer, buff_len, Length,
";WORK");
280 if (error !=
ERR_NONE)
return error;
287 error =
VC_Store(Buffer, buff_len, Length,
";OTHER");
288 if (error !=
ERR_NONE)
return error;
291 error =
VC_Store(Buffer, buff_len, Length,
";PAGER");
292 if (error !=
ERR_NONE)
return error;
295 error =
VC_Store(Buffer, buff_len, Length,
";CELL");
296 if (error !=
ERR_NONE)
return error;
299 error =
VC_Store(Buffer, buff_len, Length,
";FAX");
300 if (error !=
ERR_NONE)
return error;
303 error =
VC_Store(Buffer, buff_len, Length,
";MSG");
304 if (error !=
ERR_NONE)
return error;
307 error =
VC_Store(Buffer, buff_len, Length,
";VIDEO");
308 if (error !=
ERR_NONE)
return error;
319 error =
VC_Store(Buffer, buff_len, Length,
"NOTE");
320 if (error !=
ERR_NONE)
return error;
331 if (error !=
ERR_NONE)
return error;
333 error =
VC_Store(Buffer, buff_len, Length,
"ADR;WORK");
335 error =
VC_Store(Buffer, buff_len, Length,
"ADR;HOME");
337 error =
VC_Store(Buffer, buff_len, Length,
"ADR");
339 if (error !=
ERR_NONE)
return error;
347 error =
VC_Store(Buffer, buff_len, Length,
"EMAIL");
348 if (error !=
ERR_NONE)
return error;
355 error =
VC_Store(Buffer, buff_len, Length,
"URL");
356 if (error !=
ERR_NONE)
return error;
363 error =
VC_Store(Buffer, buff_len, Length,
"X-IRMC-LUID");
364 if (error !=
ERR_NONE)
return error;
371 error =
VC_Store(Buffer, buff_len, Length,
"X-SIP;VOIP");
372 if (error !=
ERR_NONE)
return error;
379 error =
VC_Store(Buffer, buff_len, Length,
"X-SIP;SWIS");
380 if (error !=
ERR_NONE)
return error;
387 error =
VC_Store(Buffer, buff_len, Length,
"X-WV-ID");
388 if (error !=
ERR_NONE)
return error;
395 error =
VC_Store(Buffer, buff_len, Length,
"X-SIP");
396 if (error !=
ERR_NONE)
return error;
403 error =
VC_Store(Buffer, buff_len, Length,
"X-DTMF");
404 if (error !=
ERR_NONE)
return error;
411 error =
VC_Store(Buffer, buff_len, Length,
"X-SIP;POC");
412 if (error !=
ERR_NONE)
return error;
419 error =
VC_Store(Buffer, buff_len, Length,
"TITLE");
420 if (error !=
ERR_NONE)
return error;
427 error =
VC_Store(Buffer, buff_len, Length,
"ORG");
428 if (error !=
ERR_NONE)
return error;
432 error =
VC_Store(Buffer, buff_len, Length,
"PHOTO;TYPE=");
433 if (error !=
ERR_NONE)
return error;
434 switch (bitmap->
Type) {
436 error =
VC_Store(Buffer, buff_len, Length,
"BMP;");
439 error =
VC_Store(Buffer, buff_len, Length,
"GIF;");
442 error =
VC_Store(Buffer, buff_len, Length,
"JPEG;");
445 error =
VC_Store(Buffer, buff_len, Length,
"ICO;");
448 error =
VC_Store(Buffer, buff_len, Length,
"PNG;");
452 error =
VC_Store(Buffer, buff_len, Length,
"UNKNOWN;");
455 if (error !=
ERR_NONE)
return error;
456 error =
VC_Store(Buffer, buff_len, Length,
"ENCODING=BASE64:");
457 if (error !=
ERR_NONE)
return error;
459 if (error !=
ERR_NONE)
return error;
464 if (error !=
ERR_NONE)
return error;
469 if (error !=
ERR_NONE)
return error;
489 if (error !=
ERR_NONE)
return error;
493 if (firstname != -1 || secondname != -1 || lastname != -1) {
495 if (lastname != -1) {
500 buffer[2*pos + 1] =
';';
502 if (firstname != -1) {
506 if (secondname != -1) {
508 buffer[2*pos + 1] =
' ';
514 buffer[2*pos + 1] = 0;
516 if (error !=
ERR_NONE)
return error;
519 if (workaddress != -1 || workcity != -1 || workstate != -1 || workzip != -1 || workcountry != -1) {
522 buffer[2*pos + 1] =
';';
525 buffer[2*pos + 1] =
';';
527 if (workaddress != -1) {
532 buffer[2*pos + 1] =
';';
534 if (workcity != -1) {
539 buffer[2*pos + 1] =
';';
541 if (workstate != -1) {
546 buffer[2*pos + 1] =
';';
553 buffer[2*pos + 1] =
';';
555 if (workcountry != -1) {
560 buffer[2*pos + 1] = 0;
562 if (error !=
ERR_NONE)
return error;
565 if (address != -1 || city != -1 || state != -1 || zip != -1 || country != -1) {
568 buffer[2*pos + 1] =
';';
571 buffer[2*pos + 1] =
';';
578 buffer[2*pos + 1] =
';';
585 buffer[2*pos + 1] =
';';
592 buffer[2*pos + 1] =
';';
599 buffer[2*pos + 1] =
';';
606 buffer[2*pos + 1] = 0;
608 if (error !=
ERR_NONE)
return error;
614 error =
VC_StoreLine(Buffer, buff_len, Length,
"END:VCARD");
615 if (error !=
ERR_NONE)
return error;
645 while ((*pos!=
'*')&&(*pos!=
'#')) {
669 #define CHECK_NUM_ENTRIES { \ 670 if (Pbk->EntriesNum >= GSM_PHONEBOOK_ENTRIES) { error = ERR_MOREMEMORY; goto vcard_done; } \ 671 Pbk->Entries[Pbk->EntriesNum].AddError = ERR_NONE; \ 699 if (error !=
ERR_NONE)
goto vcard_done;
700 if (strlen(Line) == 0)
break;
703 if (strstr(Line,
"BEGIN:VCARD")) Level = 1;
707 if (strstr(Line,
"END:VCARD")) {
710 if (strstr(Line,
"VERSION:") != NULL) {
711 version = atoi(Line + 8);
712 dbgprintf(di,
"vCard version %d\n", version);
714 if (
ReadVCALText(Line,
"N", Buff, (version >= 3), NULL)) {
733 if (s == NULL)
continue;
742 if (strncmp(Line,
"PHOTO;JPEG;BASE64:", 18) == 0 ||
743 strncmp(Line,
"PHOTO;BASE64;JPEG:", 18) == 0 ||
744 strncmp(Line,
"PHOTO;TYPE=JPEG;BASE64:", 23) == 0 ||
745 strncmp(Line,
"PHOTO;BASE64;TYPE=JPEG:", 23) == 0 ||
746 strncmp(Line,
"PHOTO;TYPE=JPEG;ENCODING=BASE64:", 32) == 0 ||
747 strncmp(Line,
"PHOTO;ENCODING=BASE64;TYPE=JPEG:", 32) == 0 ||
748 strncmp(Line,
"PHOTO;JPEG;ENCODING=BASE64:", 27) == 0 ||
749 strncmp(Line,
"PHOTO;ENCODING=BASE64;JPEG:", 27) == 0) {
751 s = strchr(Line,
':');
754 while (isspace((
int)*s) && *s) s++;
771 if (
ReadVCALText(Line,
"TEL", Buff, (version >= 3), &location) ||
772 ReadVCALText(Line,
"TEL;VOICE", Buff, (version >= 3), &location) ||
773 ReadVCALText(Line,
"TEL;MAIN", Buff, (version >= 3), &location)) {
774 if (Buff[1] ==
'+') {
785 if (
ReadVCALText(Line,
"TEL;VIDEO", Buff, (version >= 3), &location)) {
786 if (Buff[1] ==
'+') {
797 if (
ReadVCALText(Line,
"TEL;CELL", Buff, (version >= 3), &location) ||
798 ReadVCALText(Line,
"TEL;CELL;VOICE", Buff, (version >= 3), &location)) {
799 if (Buff[1] ==
'+') {
810 if (
ReadVCALText(Line,
"TEL;OTHER", Buff, (version >= 3), &location) ||
811 ReadVCALText(Line,
"TEL;OTHER;VOICE", Buff, (version >= 3), &location)) {
812 if (Buff[1] ==
'+') {
823 if (
ReadVCALText(Line,
"TEL;PAGER", Buff, (version >= 3), &location) ||
824 ReadVCALText(Line,
"TEL;PAGER;VOICE", Buff, (version >= 3), &location)) {
825 if (Buff[1] ==
'+') {
836 if (
ReadVCALText(Line,
"TEL;MSG", Buff, (version >= 3), &location) ||
837 ReadVCALText(Line,
"TEL;MSG;VOICE", Buff, (version >= 3), &location)) {
838 if (Buff[1] ==
'+') {
850 if (
ReadVCALText(Line,
"TEL;FAX", Buff, (version >= 3), &location) ||
851 ReadVCALText(Line,
"TEL;FAX;VOICE", Buff, (version >= 3), &location)) {
852 if (Buff[1] ==
'+') {
863 if (
ReadVCALText(Line,
"TITLE", Buff, (version >= 3), &location)) {
870 if (
ReadVCALText(Line,
"NOTE", Buff, (version >= 3), &location)) {
877 if (
ReadVCALText(Line,
"LABEL", Buff, (version >= 3), &location) ||
878 ReadVCALText(Line,
"ADR", Buff, (version >= 3), &location)) {
891 if (s == NULL)
continue;
899 if (s == NULL)
continue;
907 if (s == NULL)
continue;
915 if (s == NULL)
continue;
923 if (s == NULL)
continue;
931 if (
ReadVCALText(Line,
"EMAIL", Buff, (version >= 3), &location) ||
932 ReadVCALText(Line,
"EMAIL;OTHER", Buff, (version >= 3), &location) ||
933 ReadVCALText(Line,
"EMAIL;INTERNET", Buff, (version >= 3), &location)) {
940 if (
ReadVCALText(Line,
"X-IRMC-LUID", Buff, (version >= 3), &location)) {
947 if (
ReadVCALText(Line,
"X-DTMF", Buff, (version >= 3), &location)) {
954 if (
ReadVCALText(Line,
"X-SIP", Buff, (version >= 3), &location)) {
961 if (
ReadVCALText(Line,
"X-SIP;VOIP", Buff, (version >= 3), &location)) {
968 if (
ReadVCALText(Line,
"X-WV-ID", Buff, (version >= 3), &location)) {
975 if (
ReadVCALText(Line,
"X-SIP;SWIS", Buff, (version >= 3), &location)) {
982 if (
ReadVCALText(Line,
"X-SIP;POC", Buff, (version >= 3), &location)) {
989 if (
ReadVCALText(Line,
"URL", Buff, (version >= 3), &location)) {
996 if (
ReadVCALText(Line,
"ORG", Buff, (version >= 3), &location)) {
1003 if (
ReadVCALText(Line,
"NICKNAME", Buff, (version >= 3), &location)) {
1010 if (
ReadVCALText(Line,
"FN", Buff, (version >= 3), &location)) {
1017 if (
ReadVCALText(Line,
"X-NAME-PREFIX", Buff, (version >= 3), &location)) {
1024 if (
ReadVCALText(Line,
"X-NAME-SUFFIX", Buff, (version >= 3), &location)) {
1031 if (
ReadVCALText(Line,
"CATEGORIES", Buff, (version >= 3), &location)) {
1039 if (
ReadVCALText(Line,
"BDAY", Buff, (version >= 3), NULL)) {
1047 if (
ReadVCALText(Line,
"LAST-MODIFIED", Buff, (version >= 3), NULL)) {
1055 if (
ReadVCALText(Line,
"X-PRIVATE", Buff, (version >= 3), NULL)) {
1062 if (
ReadVCALText(Line,
"X-CALLER-GROUP", Buff, (version >= 3), NULL)) {
1069 if (
ReadVCALText(Line,
"X-GAMMU-LOCATION", Buff, (version >= 3), NULL)) {
1072 if (
ReadVCALText(Line,
"X-GAMMU-MEMORY", Buff, (version >= 3), NULL)) {
void GSM_TweakInternationalNumber(unsigned char *Number, const GSM_NumberType numType)
GSM_Error GSM_EncodeVCARD(GSM_Debug_Info *di, char *Buffer, const size_t buff_len, size_t *Length, GSM_MemoryEntry *pbk, const gboolean header, const GSM_VCardVersion Version)
char * DecodeUnicodeString(const unsigned char *src)
void GSM_PhonebookFindDefaultNameNumberGroup(const GSM_MemoryEntry *entry, int *Name, int *Number, int *Group)
unsigned char * VCALGetTextPart(unsigned char *Buff, int *pos)
void CopyUnicodeString(unsigned char *Dest, const unsigned char *Source)
GSM_Error GSM_GetVCSLine(char **OutBuffer, char *Buffer, size_t *Pos, size_t MaxLen, gboolean MergeLines)
GSM_MemoryType MemoryType
#define GSM_PHONEBOOK_TEXT_LENGTH
GSM_Error VC_StoreDateTime(char *Buffer, const size_t buff_len, size_t *Pos, const GSM_DateTime *Date, const char *Start)
GSM_Error VC_StoreText(char *Buffer, const size_t buff_len, size_t *Pos, const unsigned char *Text, const char *Start, const gboolean UTF8)
GSM_BinaryPicture_Types Type
void GSM_FreeMemoryEntry(GSM_MemoryEntry *Entry)
#define GSM_MemoryTypeToString(x)
size_t UnicodeLength(const unsigned char *str)
#define CHECK_NUM_ENTRIES
GSM_BinaryPicture Picture
GSM_Error VC_StoreLine(char *Buffer, const size_t buff_len, size_t *Pos, const char *format,...)
gboolean ReadVCALDateTime(const char *Buffer, GSM_DateTime *dt)
GSM_Error VC_Store(char *Buffer, const size_t buff_len, size_t *Pos, const char *format,...)
unsigned char Text[(GSM_PHONEBOOK_TEXT_LENGTH+1) *2]
void EncodeUnicode(unsigned char *dest, const char *src, size_t len)
GSM_Error VC_StoreBase64(char *Buffer, const size_t buff_len, size_t *Pos, const unsigned char *data, const size_t length)
GSM_Error GSM_DecodeVCARD(GSM_Debug_Info *di, char *Buffer, size_t *Pos, GSM_MemoryEntry *Pbk, GSM_VCardVersion Version)
unsigned char * GSM_PhonebookGetEntryName(const GSM_MemoryEntry *entry)
gboolean ReadVCALText(char *Buffer, const char *Start, unsigned char *Value, const gboolean UTF8, GSM_EntryLocation *location)
GSM_EntryLocation Location
int smfprintf(GSM_Debug_Info *d, const char *format,...)
GSM_MemoryType GSM_StringToMemoryType(const char *s)
GSM_Error VC_StoreDate(char *Buffer, const size_t buff_len, size_t *Pos, const GSM_DateTime *Date, const char *Start)
int DecodeBASE64(const char *Input, unsigned char *Output, const size_t Length)
GSM_SubMemoryEntry Entries[GSM_PHONEBOOK_ENTRIES]