-rw-r--r-- | libkcal/versit/vobject.c | 297 |
1 files changed, 159 insertions, 138 deletions
diff --git a/libkcal/versit/vobject.c b/libkcal/versit/vobject.c index 637efb2..3fac63e 100644 --- a/libkcal/versit/vobject.c +++ b/libkcal/versit/vobject.c | |||
@@ -44,12 +44,13 @@ DFARS 252.227-7013 or 48 CFR 52.227-19, as applicable. | |||
44 | 44 | ||
45 | #include <stdlib.h> | 45 | #ifdef WIN32 |
46 | #define snprintf _snprintf | ||
47 | #define strcasecmp stricmp | ||
48 | #endif | ||
46 | 49 | ||
47 | #include "vobject.h" | 50 | #include "vobject.h" |
51 | #include <stdlib.h> | ||
48 | #include <string.h> | 52 | #include <string.h> |
49 | #include <stdio.h> | 53 | #include <stdio.h> |
50 | #ifdef _WIN32_ | 54 | #include <fcntl.h> |
51 | 55 | ||
52 | #define strcasecmp _stricmp | ||
53 | |||
54 | #endif | ||
55 | 56 | ||
@@ -64,2 +65,27 @@ DFARS 252.227-7013 or 48 CFR 52.227-19, as applicable. | |||
64 | 65 | ||
66 | typedef union ValueItem { | ||
67 | const char *strs; | ||
68 | const wchar_t *ustrs; | ||
69 | unsigned int i; | ||
70 | unsigned long l; | ||
71 | void *any; | ||
72 | VObject *vobj; | ||
73 | } ValueItem; | ||
74 | |||
75 | struct VObject { | ||
76 | VObject *next; | ||
77 | const char *id; | ||
78 | VObject *prop; | ||
79 | unsigned short valType; | ||
80 | ValueItem val; | ||
81 | }; | ||
82 | |||
83 | typedef struct StrItem StrItem; | ||
84 | |||
85 | struct StrItem { | ||
86 | StrItem *next; | ||
87 | const char *s; | ||
88 | unsigned int refCnt; | ||
89 | }; | ||
90 | |||
65 | const char** fieldedProp; | 91 | const char** fieldedProp; |
@@ -78,3 +104,3 @@ const char** fieldedProp; | |||
78 | 104 | ||
79 | VObject* newVObject_(const char *id) | 105 | DLLEXPORT(VObject*) newVObject_(const char *id) |
80 | { | 106 | { |
@@ -89,3 +115,3 @@ VObject* newVObject_(const char *id) | |||
89 | 115 | ||
90 | VObject* newVObject(const char *id) | 116 | DLLEXPORT(VObject*) newVObject(const char *id) |
91 | { | 117 | { |
@@ -94,12 +120,9 @@ VObject* newVObject(const char *id) | |||
94 | 120 | ||
95 | void deleteVObject(VObject *p) | 121 | DLLEXPORT(void) deleteVObject(VObject *p) |
96 | { | 122 | { |
97 | if (p->id) | ||
98 | unUseStr(p->id); | 123 | unUseStr(p->id); |
99 | if (p) | ||
100 | free(p); | 124 | free(p); |
101 | p = NULL; | ||
102 | } | 125 | } |
103 | 126 | ||
104 | char* dupStr(const char *s, unsigned int size) | 127 | DLLEXPORT(char*) dupStr(const char *s, unsigned int size) |
105 | { | 128 | { |
@@ -120,7 +143,5 @@ char* dupStr(const char *s, unsigned int size) | |||
120 | 143 | ||
121 | void deleteStr(const char *p) | 144 | DLLEXPORT(void) deleteStr(const char *p) |
122 | { | 145 | { |
123 | if (p) | 146 | if (p) free((void*)p); |
124 | free((void*)p); | ||
125 | p = NULL; | ||
126 | } | 147 | } |
@@ -139,5 +160,3 @@ static void deleteStrItem(StrItem *p) | |||
139 | { | 160 | { |
140 | if (p) | ||
141 | free((void*)p); | 161 | free((void*)p); |
142 | p = NULL; | ||
143 | } | 162 | } |
@@ -149,3 +168,3 @@ static void deleteStrItem(StrItem *p) | |||
149 | 168 | ||
150 | const char* vObjectName(VObject *o) | 169 | DLLEXPORT(const char*) vObjectName(VObject *o) |
151 | { | 170 | { |
@@ -154,3 +173,3 @@ const char* vObjectName(VObject *o) | |||
154 | 173 | ||
155 | void setVObjectName(VObject *o, const char* id) | 174 | DLLEXPORT(void) setVObjectName(VObject *o, const char* id) |
156 | { | 175 | { |
@@ -159,3 +178,3 @@ void setVObjectName(VObject *o, const char* id) | |||
159 | 178 | ||
160 | const char* vObjectStringZValue(VObject *o) | 179 | DLLEXPORT(const char*) vObjectStringZValue(VObject *o) |
161 | { | 180 | { |
@@ -164,3 +183,3 @@ const char* vObjectStringZValue(VObject *o) | |||
164 | 183 | ||
165 | void setVObjectStringZValue(VObject *o, const char *s) | 184 | DLLEXPORT(void) setVObjectStringZValue(VObject *o, const char *s) |
166 | { | 185 | { |
@@ -170,3 +189,3 @@ void setVObjectStringZValue(VObject *o, const char *s) | |||
170 | 189 | ||
171 | void setVObjectStringZValue_(VObject *o, const char *s) | 190 | DLLEXPORT(void) setVObjectStringZValue_(VObject *o, const char *s) |
172 | { | 191 | { |
@@ -176,3 +195,3 @@ void setVObjectStringZValue_(VObject *o, const char *s) | |||
176 | 195 | ||
177 | const wchar_t* vObjectUStringZValue(VObject *o) | 196 | DLLEXPORT(const wchar_t*) vObjectUStringZValue(VObject *o) |
178 | { | 197 | { |
@@ -181,3 +200,3 @@ const wchar_t* vObjectUStringZValue(VObject *o) | |||
181 | 200 | ||
182 | void setVObjectUStringZValue(VObject *o, const wchar_t *s) | 201 | DLLEXPORT(void) setVObjectUStringZValue(VObject *o, const wchar_t *s) |
183 | { | 202 | { |
@@ -187,3 +206,3 @@ void setVObjectUStringZValue(VObject *o, const wchar_t *s) | |||
187 | 206 | ||
188 | void setVObjectUStringZValue_(VObject *o, const wchar_t *s) | 207 | DLLEXPORT(void) setVObjectUStringZValue_(VObject *o, const wchar_t *s) |
189 | { | 208 | { |
@@ -193,3 +212,3 @@ void setVObjectUStringZValue_(VObject *o, const wchar_t *s) | |||
193 | 212 | ||
194 | unsigned int vObjectIntegerValue(VObject *o) | 213 | DLLEXPORT(unsigned int) vObjectIntegerValue(VObject *o) |
195 | { | 214 | { |
@@ -198,3 +217,3 @@ unsigned int vObjectIntegerValue(VObject *o) | |||
198 | 217 | ||
199 | void setVObjectIntegerValue(VObject *o, unsigned int i) | 218 | DLLEXPORT(void) setVObjectIntegerValue(VObject *o, unsigned int i) |
200 | { | 219 | { |
@@ -204,3 +223,3 @@ void setVObjectIntegerValue(VObject *o, unsigned int i) | |||
204 | 223 | ||
205 | unsigned long vObjectLongValue(VObject *o) | 224 | DLLEXPORT(unsigned long) vObjectLongValue(VObject *o) |
206 | { | 225 | { |
@@ -209,3 +228,3 @@ unsigned long vObjectLongValue(VObject *o) | |||
209 | 228 | ||
210 | void setVObjectLongValue(VObject *o, unsigned long l) | 229 | DLLEXPORT(void) setVObjectLongValue(VObject *o, unsigned long l) |
211 | { | 230 | { |
@@ -215,3 +234,3 @@ void setVObjectLongValue(VObject *o, unsigned long l) | |||
215 | 234 | ||
216 | void* vObjectAnyValue(VObject *o) | 235 | DLLEXPORT(void*) vObjectAnyValue(VObject *o) |
217 | { | 236 | { |
@@ -220,3 +239,3 @@ void* vObjectAnyValue(VObject *o) | |||
220 | 239 | ||
221 | void setVObjectAnyValue(VObject *o, void *t) | 240 | DLLEXPORT(void) setVObjectAnyValue(VObject *o, void *t) |
222 | { | 241 | { |
@@ -226,3 +245,3 @@ void setVObjectAnyValue(VObject *o, void *t) | |||
226 | 245 | ||
227 | VObject* vObjectVObjectValue(VObject *o) | 246 | DLLEXPORT(VObject*) vObjectVObjectValue(VObject *o) |
228 | { | 247 | { |
@@ -231,3 +250,3 @@ VObject* vObjectVObjectValue(VObject *o) | |||
231 | 250 | ||
232 | void setVObjectVObjectValue(VObject *o, VObject *p) | 251 | DLLEXPORT(void) setVObjectVObjectValue(VObject *o, VObject *p) |
233 | { | 252 | { |
@@ -237,3 +256,3 @@ void setVObjectVObjectValue(VObject *o, VObject *p) | |||
237 | 256 | ||
238 | int vObjectValueType(VObject *o) | 257 | DLLEXPORT(int) vObjectValueType(VObject *o) |
239 | { | 258 | { |
@@ -247,3 +266,3 @@ int vObjectValueType(VObject *o) | |||
247 | 266 | ||
248 | VObject* addVObjectProp(VObject *o, VObject *p) | 267 | DLLEXPORT(VObject*) addVObjectProp(VObject *o, VObject *p) |
249 | { | 268 | { |
@@ -282,3 +301,3 @@ VObject* addVObjectProp(VObject *o, VObject *p) | |||
282 | 301 | ||
283 | VObject* addProp(VObject *o, const char *id) | 302 | DLLEXPORT(VObject*) addProp(VObject *o, const char *id) |
284 | { | 303 | { |
@@ -287,3 +306,3 @@ VObject* addProp(VObject *o, const char *id) | |||
287 | 306 | ||
288 | VObject* addProp_(VObject *o, const char *id) | 307 | DLLEXPORT(VObject*) addProp_(VObject *o, const char *id) |
289 | { | 308 | { |
@@ -292,3 +311,3 @@ VObject* addProp_(VObject *o, const char *id) | |||
292 | 311 | ||
293 | void addList(VObject **o, VObject *p) | 312 | DLLEXPORT(void) addList(VObject **o, VObject *p) |
294 | { | 313 | { |
@@ -307,3 +326,3 @@ void addList(VObject **o, VObject *p) | |||
307 | 326 | ||
308 | VObject* nextVObjectInList(VObject *o) | 327 | DLLEXPORT(VObject*) nextVObjectInList(VObject *o) |
309 | { | 328 | { |
@@ -312,3 +331,3 @@ VObject* nextVObjectInList(VObject *o) | |||
312 | 331 | ||
313 | VObject* setValueWithSize_(VObject *prop, void *val, unsigned int size) | 332 | DLLEXPORT(VObject*) setValueWithSize_(VObject *prop, void *val, unsigned int size) |
314 | { | 333 | { |
@@ -321,5 +340,5 @@ VObject* setValueWithSize_(VObject *prop, void *val, unsigned int size) | |||
321 | 340 | ||
322 | VObject* setValueWithSize(VObject *prop, void *val, unsigned int size) | 341 | DLLEXPORT(VObject*) setValueWithSize(VObject *prop, void *val, unsigned int size) |
323 | { | 342 | { |
324 | void *p = dupStr(val,size); | 343 | void *p = dupStr((const char *)val,size); |
325 | return setValueWithSize_(prop,p,p?size:0); | 344 | return setValueWithSize_(prop,p,p?size:0); |
@@ -327,3 +346,3 @@ VObject* setValueWithSize(VObject *prop, void *val, unsigned int size) | |||
327 | 346 | ||
328 | void initPropIterator(VObjectIterator *i, VObject *o) | 347 | DLLEXPORT(void) initPropIterator(VObjectIterator *i, VObject *o) |
329 | { | 348 | { |
@@ -333,3 +352,3 @@ void initPropIterator(VObjectIterator *i, VObject *o) | |||
333 | 352 | ||
334 | void initVObjectIterator(VObjectIterator *i, VObject *o) | 353 | DLLEXPORT(void) initVObjectIterator(VObjectIterator *i, VObject *o) |
335 | { | 354 | { |
@@ -339,3 +358,3 @@ void initVObjectIterator(VObjectIterator *i, VObject *o) | |||
339 | 358 | ||
340 | int moreIteration(VObjectIterator *i) | 359 | DLLEXPORT(int) moreIteration(VObjectIterator *i) |
341 | { | 360 | { |
@@ -344,3 +363,3 @@ int moreIteration(VObjectIterator *i) | |||
344 | 363 | ||
345 | VObject* nextVObject(VObjectIterator *i) | 364 | DLLEXPORT(VObject*) nextVObject(VObjectIterator *i) |
346 | { | 365 | { |
@@ -359,3 +378,3 @@ VObject* nextVObject(VObjectIterator *i) | |||
359 | 378 | ||
360 | VObject* isAPropertyOf(VObject *o, const char *id) | 379 | DLLEXPORT(VObject*) isAPropertyOf(VObject *o, const char *id) |
361 | { | 380 | { |
@@ -365,3 +384,3 @@ VObject* isAPropertyOf(VObject *o, const char *id) | |||
365 | VObject *each = nextVObject(&i); | 384 | VObject *each = nextVObject(&i); |
366 | if (!strcasecmp(id,each->id)) | 385 | if (!stricmp(id,each->id)) |
367 | return each; | 386 | return each; |
@@ -371,3 +390,3 @@ VObject* isAPropertyOf(VObject *o, const char *id) | |||
371 | 390 | ||
372 | VObject* addGroup(VObject *o, const char *g) | 391 | DLLEXPORT(VObject*) addGroup(VObject *o, const char *g) |
373 | { | 392 | { |
@@ -412,3 +431,3 @@ VObject* addGroup(VObject *o, const char *g) | |||
412 | 431 | ||
413 | VObject* addPropValue(VObject *o, const char *p, const char *v) | 432 | DLLEXPORT(VObject*) addPropValue(VObject *o, const char *p, const char *v) |
414 | { | 433 | { |
@@ -420,3 +439,3 @@ VObject* addPropValue(VObject *o, const char *p, const char *v) | |||
420 | 439 | ||
421 | VObject* addPropSizedValue_(VObject *o, const char *p, const char *v, | 440 | DLLEXPORT(VObject*) addPropSizedValue_(VObject *o, const char *p, const char *v, |
422 | unsigned int size) | 441 | unsigned int size) |
@@ -429,3 +448,3 @@ VObject* addPropSizedValue_(VObject *o, const char *p, const char *v, | |||
429 | 448 | ||
430 | VObject* addPropSizedValue(VObject *o, const char *p, const char *v, | 449 | DLLEXPORT(VObject*) addPropSizedValue(VObject *o, const char *p, const char *v, |
431 | unsigned int size) | 450 | unsigned int size) |
@@ -530,3 +549,3 @@ void printVObject(FILE *fp,VObject *o) | |||
530 | 549 | ||
531 | void printVObjectToFile(char *fname,VObject *o) | 550 | DLLEXPORT(void) printVObjectToFile(char *fname,VObject *o) |
532 | { | 551 | { |
@@ -539,3 +558,3 @@ void printVObjectToFile(char *fname,VObject *o) | |||
539 | 558 | ||
540 | void printVObjectsToFile(char *fname,VObject *list) | 559 | DLLEXPORT(void) printVObjectsToFile(char *fname,VObject *list) |
541 | { | 560 | { |
@@ -551,3 +570,3 @@ void printVObjectsToFile(char *fname,VObject *list) | |||
551 | 570 | ||
552 | void cleanVObject(VObject *o) | 571 | DLLEXPORT(void) cleanVObject(VObject *o) |
553 | { | 572 | { |
@@ -585,3 +604,3 @@ void cleanVObject(VObject *o) | |||
585 | 604 | ||
586 | void cleanVObjects(VObject *list) | 605 | DLLEXPORT(void) cleanVObjects(VObject *list) |
587 | { | 606 | { |
@@ -612,6 +631,4 @@ static unsigned int hashStr(const char *s) | |||
612 | 631 | ||
613 | const char* lookupStr(const char *s) | 632 | DLLEXPORT(const char*) lookupStr(const char *s) |
614 | { | 633 | { |
615 | char *newS; | ||
616 | |||
617 | StrItem *t; | 634 | StrItem *t; |
@@ -620,3 +637,3 @@ const char* lookupStr(const char *s) | |||
620 | do { | 637 | do { |
621 | if (strcasecmp(t->s,s) == 0) { | 638 | if (stricmp(t->s,s) == 0) { |
622 | t->refCnt++; | 639 | t->refCnt++; |
@@ -627,28 +644,25 @@ const char* lookupStr(const char *s) | |||
627 | } | 644 | } |
628 | newS = dupStr(s,0); | 645 | s = dupStr(s,0); |
629 | strTbl[h] = newStrItem(newS,strTbl[h]); | 646 | strTbl[h] = newStrItem(s,strTbl[h]); |
630 | return newS; | 647 | return s; |
631 | } | 648 | } |
632 | 649 | ||
633 | void unUseStr(const char *s) | 650 | DLLEXPORT(void) unUseStr(const char *s) |
634 | { | 651 | { |
635 | StrItem *cur, *prev; | 652 | StrItem *t, *p; |
636 | |||
637 | unsigned int h = hashStr(s); | 653 | unsigned int h = hashStr(s); |
638 | cur = strTbl[h]; | 654 | if ((t = strTbl[h]) != 0) { |
639 | prev = cur; | 655 | p = t; |
640 | while (cur != 0) { | 656 | do { |
641 | if (strcasecmp(cur->s,s) == 0) { | 657 | if (stricmp(t->s,s) == 0) { |
642 | cur->refCnt--; | 658 | t->refCnt--; |
643 | /* if that was the last reference to this string, kill it. */ | 659 | if (t->refCnt == 0) { |
644 | if (cur->refCnt == 0) { | 660 | if (p == strTbl[h]) { |
645 | if (cur == strTbl[h]) { | 661 | strTbl[h] = t->next; |
646 | strTbl[h] = cur->next; | 662 | } |
647 | deleteStr(prev->s); | 663 | else { |
648 | deleteStrItem(prev); | 664 | p->next = t->next; |
649 | } else { | ||
650 | prev->next = cur->next; | ||
651 | deleteStr(cur->s); | ||
652 | deleteStrItem(cur); | ||
653 | } | 665 | } |
666 | deleteStr(t->s); | ||
667 | deleteStrItem(t); | ||
654 | return; | 668 | return; |
@@ -656,4 +670,5 @@ void unUseStr(const char *s) | |||
656 | } | 670 | } |
657 | prev = cur; | 671 | p = t; |
658 | cur = cur->next; | 672 | t = t->next; |
673 | } while (t); | ||
659 | } | 674 | } |
@@ -661,3 +676,3 @@ void unUseStr(const char *s) | |||
661 | 676 | ||
662 | void cleanStrTbl() | 677 | DLLEXPORT(void) cleanStrTbl() |
663 | { | 678 | { |
@@ -672,3 +687,3 @@ void cleanStrTbl() | |||
672 | deleteStrItem(p); | 687 | deleteStrItem(p); |
673 | } | 688 | } while (t); |
674 | strTbl[i] = 0; | 689 | strTbl[i] = 0; |
@@ -809,3 +824,3 @@ static struct PreDefProp propNames[] = { | |||
809 | { VCExNumProp, 0, 0, 0 }, | 824 | { VCExNumProp, 0, 0, 0 }, |
810 | { VCExDateProp, 0, 0, 0 }, | 825 | { VCExpDateProp, 0, 0, 0 }, |
811 | { VCExpectProp, 0, 0, 0 }, | 826 | { VCExpectProp, 0, 0, 0 }, |
@@ -923,3 +938,3 @@ static struct PreDefProp* lookupPropInfo(const char* str) | |||
923 | for (i = 0; propNames[i].name; i++) | 938 | for (i = 0; propNames[i].name; i++) |
924 | if (strcasecmp(str, propNames[i].name) == 0) { | 939 | if (stricmp(str, propNames[i].name) == 0) { |
925 | return &propNames[i]; | 940 | return &propNames[i]; |
@@ -931,3 +946,3 @@ static struct PreDefProp* lookupPropInfo(const char* str) | |||
931 | 946 | ||
932 | const char* lookupProp_(const char* str) | 947 | DLLEXPORT(const char*) lookupProp_(const char* str) |
933 | { | 948 | { |
@@ -936,3 +951,3 @@ const char* lookupProp_(const char* str) | |||
936 | for (i = 0; propNames[i].name; i++) | 951 | for (i = 0; propNames[i].name; i++) |
937 | if (strcasecmp(str, propNames[i].name) == 0) { | 952 | if (stricmp(str, propNames[i].name) == 0) { |
938 | const char* s; | 953 | const char* s; |
@@ -945,3 +960,3 @@ const char* lookupProp_(const char* str) | |||
945 | 960 | ||
946 | const char* lookupProp(const char* str) | 961 | DLLEXPORT(const char*) lookupProp(const char* str) |
947 | { | 962 | { |
@@ -950,3 +965,3 @@ const char* lookupProp(const char* str) | |||
950 | for (i = 0; propNames[i].name; i++) | 965 | for (i = 0; propNames[i].name; i++) |
951 | if (strcasecmp(str, propNames[i].name) == 0) { | 966 | if (stricmp(str, propNames[i].name) == 0) { |
952 | const char *s; | 967 | const char *s; |
@@ -974,7 +989,3 @@ typedef struct OFile { | |||
974 | 989 | ||
975 | |||
976 | /* vCalendar files need crlf linebreaks. The disabled functions didn't provide | ||
977 | that. */ | ||
978 | #if 0 | 990 | #if 0 |
979 | |||
980 | static void appendsOFile(OFile *fp, const char *s) | 991 | static void appendsOFile(OFile *fp, const char *s) |
@@ -997,6 +1008,3 @@ stuff: | |||
997 | if (OFILE_REALLOC_SIZE <= slen) fp->limit += slen; | 1008 | if (OFILE_REALLOC_SIZE <= slen) fp->limit += slen; |
998 | if (fp->s) | 1009 | fp->s = (char *) realloc(fp->s,fp->limit); |
999 | fp->s = realloc(fp->s,fp->limit); | ||
1000 | else | ||
1001 | fp->s = malloc(fp->limit); | ||
1002 | if (fp->s) goto stuff; | 1010 | if (fp->s) goto stuff; |
@@ -1025,3 +1033,3 @@ stuff: | |||
1025 | fp->limit = fp->limit + OFILE_REALLOC_SIZE; | 1033 | fp->limit = fp->limit + OFILE_REALLOC_SIZE; |
1026 | fp->s = realloc(fp->s,fp->limit); | 1034 | fp->s = (char *) realloc(fp->s,fp->limit); |
1027 | if (fp->s) goto stuff; | 1035 | if (fp->s) goto stuff; |
@@ -1034,5 +1042,3 @@ stuff: | |||
1034 | } | 1042 | } |
1035 | |||
1036 | #else | 1043 | #else |
1037 | |||
1038 | static void appendcOFile_(OFile *fp, char c) | 1044 | static void appendcOFile_(OFile *fp, char c) |
@@ -1147,14 +1153,29 @@ static int writeBase64(OFile *fp, unsigned char *s, long len) | |||
1147 | 1153 | ||
1148 | /* this function really sucks. Too basic. */ | 1154 | static void writeString(OFile *fp, const char *s) |
1149 | static void writeQPString(OFile *fp, const char *s, int qp) | 1155 | { |
1156 | appendsOFile(fp,s); | ||
1157 | } | ||
1158 | |||
1159 | static void writeQPString(OFile *fp, const char *s) | ||
1150 | { | 1160 | { |
1161 | char buf[4]; | ||
1162 | int count=0; | ||
1151 | const char *p = s; | 1163 | const char *p = s; |
1164 | |||
1152 | while (*p) { | 1165 | while (*p) { |
1153 | if (*p == '\n') { | 1166 | /* break up lines biggger than 75 chars */ |
1154 | if (p[1]) appendsOFile(fp,"=0A="); | 1167 | if(count >=74){ |
1168 | count=0; | ||
1169 | appendsOFile(fp,"=\n"); | ||
1155 | } | 1170 | } |
1156 | if (*p == '=' && qp) | 1171 | |
1157 | appendsOFile(fp,"=3D"); | 1172 | /* escape any non ASCII characters and '=' as per rfc1521 */ |
1158 | else | 1173 | if (*p<= 0x1f || *p >=0x7f || *p == '=' ) { |
1174 | sprintf(buf,"=%02X",(unsigned char)*p); | ||
1175 | appendsOFile(fp,buf); | ||
1176 | count+=3; | ||
1177 | } else { | ||
1159 | appendcOFile(fp,*p); | 1178 | appendcOFile(fp,*p); |
1179 | count++; | ||
1180 | } | ||
1160 | p++; | 1181 | p++; |
@@ -1163,5 +1184,7 @@ static void writeQPString(OFile *fp, const char *s, int qp) | |||
1163 | 1184 | ||
1185 | |||
1186 | |||
1164 | static void writeVObject_(OFile *fp, VObject *o); | 1187 | static void writeVObject_(OFile *fp, VObject *o); |
1165 | 1188 | ||
1166 | static void writeValue(OFile *fp, VObject *o, unsigned long size) | 1189 | static void writeValue(OFile *fp, VObject *o, unsigned long size,int quote) |
1167 | { | 1190 | { |
@@ -1171,6 +1194,4 @@ static void writeValue(OFile *fp, VObject *o, unsigned long size) | |||
1171 | char *s = fakeCString(USTRINGZ_VALUE_OF(o)); | 1194 | char *s = fakeCString(USTRINGZ_VALUE_OF(o)); |
1172 | if (isAPropertyOf(o, VCQuotedPrintableProp)) | 1195 | if(quote) writeQPString(fp, s); |
1173 | writeQPString(fp, s, 1); | 1196 | else writeString(fp,s); |
1174 | else | ||
1175 | writeQPString(fp, s, 0); | ||
1176 | deleteStr(s); | 1197 | deleteStr(s); |
@@ -1179,6 +1200,4 @@ static void writeValue(OFile *fp, VObject *o, unsigned long size) | |||
1179 | case VCVT_STRINGZ: { | 1200 | case VCVT_STRINGZ: { |
1180 | if (isAPropertyOf(o, VCQuotedPrintableProp)) | 1201 | if(quote) writeQPString(fp, STRINGZ_VALUE_OF(o)); |
1181 | writeQPString(fp, STRINGZ_VALUE_OF(o), 1); | 1202 | else writeString(fp,STRINGZ_VALUE_OF(o)); |
1182 | else | ||
1183 | writeQPString(fp, STRINGZ_VALUE_OF(o), 0); | ||
1184 | break; | 1203 | break; |
@@ -1222,3 +1241,3 @@ static void writeAttrValue(OFile *fp, VObject *o) | |||
1222 | appendcOFile(fp,'='); | 1241 | appendcOFile(fp,'='); |
1223 | writeValue(fp,o,0); | 1242 | writeValue(fp,o,0,0); |
1224 | } | 1243 | } |
@@ -1232,6 +1251,5 @@ static void writeGroup(OFile *fp, VObject *o) | |||
1232 | while ((o=isAPropertyOf(o,VCGroupingProp)) != 0) { | 1251 | while ((o=isAPropertyOf(o,VCGroupingProp)) != 0) { |
1233 | strncpy(buf2,STRINGZ_VALUE_OF(o),sizeof(buf2)); | 1252 | strcpy(buf2,STRINGZ_VALUE_OF(o)); |
1234 | buf2[sizeof(buf2)] = '\0'; | 1253 | strcat(buf2,"."); |
1235 | strncat(buf2,".",sizeof(buf2)-strlen(buf2)-1); | 1254 | strcat(buf2,buf1); |
1236 | strncat(buf2,buf1,sizeof(buf2)-strlen(buf2)-1); | ||
1237 | strcpy(buf1,buf2); | 1255 | strcpy(buf1,buf2); |
@@ -1245,3 +1263,3 @@ static int inList(const char **list, const char *s) | |||
1245 | while (*list) { | 1263 | while (*list) { |
1246 | if (strcasecmp(*list,s) == 0) return 1; | 1264 | if (stricmp(*list,s) == 0) return 1; |
1247 | list++; | 1265 | list++; |
@@ -1253,2 +1271,3 @@ static void writeProp(OFile *fp, VObject *o) | |||
1253 | { | 1271 | { |
1272 | int isQuoted=0; | ||
1254 | if (NAME_OF(o)) { | 1273 | if (NAME_OF(o)) { |
@@ -1272,4 +1291,6 @@ static void writeProp(OFile *fp, VObject *o) | |||
1272 | s = NAME_OF(eachProp); | 1291 | s = NAME_OF(eachProp); |
1273 | if (strcasecmp(VCGroupingProp,s) && !inList(fields_,s)) | 1292 | if (stricmp(VCGroupingProp,s) && !inList(fields_,s)) |
1274 | writeAttrValue(fp,eachProp); | 1293 | writeAttrValue(fp,eachProp); |
1294 | if (stricmp(VCQPProp,s)==0 || stricmp(VCQuotedPrintableProp,s)==0) | ||
1295 | isQuoted=1; | ||
1275 | } | 1296 | } |
@@ -1281,5 +1302,5 @@ static void writeProp(OFile *fp, VObject *o) | |||
1281 | while (*fields) { | 1302 | while (*fields) { |
1282 | VObject *tl = isAPropertyOf(o,*fields); | 1303 | VObject *t = isAPropertyOf(o,*fields); |
1283 | i++; | 1304 | i++; |
1284 | if (tl) n = i; | 1305 | if (t) n = i; |
1285 | fields++; | 1306 | fields++; |
@@ -1288,3 +1309,3 @@ static void writeProp(OFile *fp, VObject *o) | |||
1288 | for (i=0;i<n;i++) { | 1309 | for (i=0;i<n;i++) { |
1289 | writeValue(fp,isAPropertyOf(o,*fields),0); | 1310 | writeValue(fp,isAPropertyOf(o,*fields),0,isQuoted); |
1290 | fields++; | 1311 | fields++; |
@@ -1300,3 +1321,3 @@ static void writeProp(OFile *fp, VObject *o) | |||
1300 | appendcOFile(fp,':'); | 1321 | appendcOFile(fp,':'); |
1301 | writeValue(fp,o,size); | 1322 | writeValue(fp,o,size,isQuoted); |
1302 | } | 1323 | } |
@@ -1337,3 +1358,3 @@ void writeVObject(FILE *fp, VObject *o) | |||
1337 | 1358 | ||
1338 | void writeVObjectToFile(char *fname, VObject *o) | 1359 | DLLEXPORT(void) writeVObjectToFile(char *fname, VObject *o) |
1339 | { | 1360 | { |
@@ -1346,3 +1367,3 @@ void writeVObjectToFile(char *fname, VObject *o) | |||
1346 | 1367 | ||
1347 | void writeVObjectsToFile(char *fname, VObject *list) | 1368 | DLLEXPORT(void) writeVObjectsToFile(char *fname, VObject *list) |
1348 | { | 1369 | { |
@@ -1358,3 +1379,3 @@ void writeVObjectsToFile(char *fname, VObject *list) | |||
1358 | 1379 | ||
1359 | char* writeMemVObject(char *s, int *len, VObject *o) | 1380 | DLLEXPORT(char*) writeMemVObject(char *s, int *len, VObject *o) |
1360 | { | 1381 | { |
@@ -1368,3 +1389,3 @@ char* writeMemVObject(char *s, int *len, VObject *o) | |||
1368 | 1389 | ||
1369 | char* writeMemVObjects(char *s, int *len, VObject *list) | 1390 | DLLEXPORT(char*) writeMemVObjects(char *s, int *len, VObject *list) |
1370 | { | 1391 | { |
@@ -1384,3 +1405,3 @@ char* writeMemVObjects(char *s, int *len, VObject *list) | |||
1384 | ----------------------------------------------------------------------*/ | 1405 | ----------------------------------------------------------------------*/ |
1385 | wchar_t* fakeUnicode(const char *ps, int *bytes) | 1406 | DLLEXPORT(wchar_t*) fakeUnicode(const char *ps, int *bytes) |
1386 | { | 1407 | { |
@@ -1407,3 +1428,3 @@ wchar_t* fakeUnicode(const char *ps, int *bytes) | |||
1407 | 1428 | ||
1408 | int uStrLen(const wchar_t *u) | 1429 | DLLEXPORT(int) uStrLen(const wchar_t *u) |
1409 | { | 1430 | { |
@@ -1414,3 +1435,3 @@ int uStrLen(const wchar_t *u) | |||
1414 | 1435 | ||
1415 | char* fakeCString(const wchar_t *u) | 1436 | DLLEXPORT(char*) fakeCString(const wchar_t *u) |
1416 | { | 1437 | { |
@@ -1418,3 +1439,3 @@ char* fakeCString(const wchar_t *u) | |||
1418 | int len = uStrLen(u) + 1; | 1439 | int len = uStrLen(u) + 1; |
1419 | t = s = (char*)malloc(len+1); | 1440 | t = s = (char*)malloc(len); |
1420 | while (*u) { | 1441 | while (*u) { |