summaryrefslogtreecommitdiff
path: root/library/backend/vobject.cpp
Unidiff
Diffstat (limited to 'library/backend/vobject.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/backend/vobject.cpp116
1 files changed, 58 insertions, 58 deletions
diff --git a/library/backend/vobject.cpp b/library/backend/vobject.cpp
index e6f6b78..dab128e 100644
--- a/library/backend/vobject.cpp
+++ b/library/backend/vobject.cpp
@@ -1,62 +1,62 @@
1/*************************************************************************** 1/***************************************************************************
2(C) Copyright 1996 Apple Computer, Inc., AT&T Corp., International 2(C) Copyright 1996 Apple Computer, Inc., AT&T Corp., International
3Business Machines Corporation and Siemens Rolm Communications Inc. 3Business Machines Corporation and Siemens Rolm Communications Inc.
4 4
5For purposes of this license notice, the term Licensors shall mean, 5For purposes of this license notice, the term Licensors shall mean,
6collectively, Apple Computer, Inc., AT&T Corp., International 6collectively, Apple Computer, Inc., AT&T Corp., International
7Business Machines Corporation and Siemens Rolm Communications Inc. 7Business Machines Corporation and Siemens Rolm Communications Inc.
8The term Licensor shall mean any of the Licensors. 8The term Licensor shall mean any of the Licensors.
9 9
10Subject to acceptance of the following conditions, permission is hereby 10Subject to acceptance of the following conditions, permission is hereby
11granted by Licensors without the need for written agreement and without 11granted by Licensors without the need for written agreement and without
12license or royalty fees, to use, copy, modify and distribute this 12license or royalty fees, to use, copy, modify and distribute this
13software for any purpose. 13software for any purpose.
14 14
15The above copyright notice and the following four paragraphs must be 15The above copyright notice and the following four paragraphs must be
16reproduced in all copies of this software and any software including 16reproduced in all copies of this software and any software including
17this software. 17this software.
18 18
19THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS AND NO LICENSOR SHALL HAVE 19THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS AND NO LICENSOR SHALL HAVE
20ANY OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR 20ANY OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR
21MODIFICATIONS. 21MODIFICATIONS.
22 22
23IN NO EVENT SHALL ANY LICENSOR BE LIABLE TO ANY PARTY FOR DIRECT, 23IN NO EVENT SHALL ANY LICENSOR BE LIABLE TO ANY PARTY FOR DIRECT,
24INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOST PROFITS ARISING OUT 24INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOST PROFITS ARISING OUT
25OF THE USE OF THIS SOFTWARE EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 25OF THE USE OF THIS SOFTWARE EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
26DAMAGE. 26DAMAGE.
27 27
28EACH LICENSOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED, 28EACH LICENSOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED,
29INCLUDING BUT NOT LIMITED TO ANY WARRANTY OF NONINFRINGEMENT OR THE 29INCLUDING BUT NOT LIMITED TO ANY WARRANTY OF NONINFRINGEMENT OR THE
30IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 30IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31PURPOSE. 31PURPOSE.
32 32
33The software is provided with RESTRICTED RIGHTS. Use, duplication, or 33The software is provided with RESTRICTED RIGHTS. Use, duplication, or
34disclosure by the government are subject to restrictions set forth in 34disclosure by the government are subject to restrictions set forth in
35DFARS 252.227-7013 or 48 CFR 52.227-19, as applicable. 35DFARS 252.227-7013 or 48 CFR 52.227-19, as applicable.
36 36
37***************************************************************************/ 37***************************************************************************/
38 38
39/* 39/*
40 * src: vobject.c 40 * src: vobject.c
41 * doc: vobject and APIs to construct vobject, APIs pretty print 41 * doc: vobject and APIs to construct vobject, APIs pretty print
42 * vobject, and convert a vobject into its textual representation. 42 * vobject, and convert a vobject into its textual representation.
43 */ 43 */
44 44
45 #ifndef MWERKS 45 #ifndef MWERKS
46#include <malloc.h> 46#include <malloc.h>
47#endif 47#endif
48 48
49#include "vobject_p.h" 49#include <qtopia/private/vobject_p.h>
50#include "qfiledirect_p.h" 50#include <qtopia/private/qfiledirect_p.h>
51#include <string.h> 51#include <string.h>
52#include <stdio.h> 52#include <stdio.h>
53#include <fcntl.h> 53#include <fcntl.h>
54//#include <io.h> 54//#include <io.h>
55 55
56 56
57 #define NAME_OF(o) o->id 57 #define NAME_OF(o) o->id
58 #define VALUE_TYPE(o) o->valType 58 #define VALUE_TYPE(o) o->valType
59 #define STRINGZ_VALUE_OF(o) o->val.strs 59 #define STRINGZ_VALUE_OF(o) o->val.strs
60 #define INTEGER_VALUE_OF(o) o->val.i 60 #define INTEGER_VALUE_OF(o) o->val.i
61 #define LONG_VALUE_OF(o) o->val.l 61 #define LONG_VALUE_OF(o) o->val.l
62 #define ANY_VALUE_OF(o) o->val.any 62 #define ANY_VALUE_OF(o) o->val.any
@@ -318,36 +318,36 @@ DLLEXPORT(VObject*) setValueWithSize_(VObject *prop, void *val, unsigned int siz
318 setVObjectLongValue(sizeProp, size); 318 setVObjectLongValue(sizeProp, size);
319 return prop; 319 return prop;
320} 320}
321 321
322DLLEXPORT(VObject*) setValueWithSize(VObject *prop, void *val, unsigned int size) 322DLLEXPORT(VObject*) setValueWithSize(VObject *prop, void *val, unsigned int size)
323{ 323{
324 void *p = dupStr((const char *)val,size); 324 void *p = dupStr((const char *)val,size);
325 return setValueWithSize_(prop,p,p?size:0); 325 return setValueWithSize_(prop,p,p?size:0);
326} 326}
327 327
328DLLEXPORT(void) initPropIterator(VObjectIterator *i, VObject *o) 328DLLEXPORT(void) initPropIterator(VObjectIterator *i, VObject *o)
329{ 329{
330 i->start = o->prop; 330 i->start = o->prop;
331 i->next = 0; 331 i->next = 0;
332} 332}
333 333
334DLLEXPORT(void) initVObjectIterator(VObjectIterator *i, VObject *o) 334DLLEXPORT(void) initVObjectIterator(VObjectIterator *i, VObject *o)
335{ 335{
336 i->start = o->next; 336 i->start = o->next;
337 i->next = 0; 337 i->next = 0;
338} 338}
339 339
340DLLEXPORT(int) moreIteration(VObjectIterator *i) 340DLLEXPORT(int) moreIteration(VObjectIterator *i)
341{ 341{
342 return (i->start && (i->next==0 || i->next!=i->start)); 342 return (i->start && (i->next==0 || i->next!=i->start));
343} 343}
344 344
345DLLEXPORT(VObject*) nextVObject(VObjectIterator *i) 345DLLEXPORT(VObject*) nextVObject(VObjectIterator *i)
346{ 346{
347 if (i->start && i->next != i->start) { 347 if (i->start && i->next != i->start) {
348 if (i->next == 0) { 348 if (i->next == 0) {
349 i->next = i->start->next; 349 i->next = i->start->next;
350 return i->next; 350 return i->next;
351 } 351 }
352 else { 352 else {
353 i->next = i->next->next; 353 i->next = i->next->next;
@@ -394,25 +394,25 @@ DLLEXPORT(VObject*) addGroup(VObject *o, const char *g)
394 if (dot) { 394 if (dot) {
395 n = dot+1; 395 n = dot+1;
396 *dot=0; 396 *dot=0;
397 } 397 }
398 else 398 else
399 n = gs; 399 n = gs;
400 /* property(VCGroupingProp=n); 400 /* property(VCGroupingProp=n);
401 *and the value may have VCGrouping property 401 *and the value may have VCGrouping property
402 */ 402 */
403 t = addProp(t,VCGroupingProp); 403 t = addProp(t,VCGroupingProp);
404 setVObjectStringZValue(t,lookupProp_(n)); 404 setVObjectStringZValue(t,lookupProp_(n));
405 } while (n != gs); 405 } while (n != gs);
406 deleteStr(gs); 406 deleteStr(gs);
407 return p; 407 return p;
408 } 408 }
409 else 409 else
410 return addProp_(o,lookupProp(g)); 410 return addProp_(o,lookupProp(g));
411} 411}
412 412
413DLLEXPORT(VObject*) addPropValue(VObject *o, const char *p, const char *v) 413DLLEXPORT(VObject*) addPropValue(VObject *o, const char *p, const char *v)
414{ 414{
415 VObject *prop; 415 VObject *prop;
416 prop = addProp(o,p); 416 prop = addProp(o,p);
417 setVObjectStringZValue_(prop, strdup( v ) ); 417 setVObjectStringZValue_(prop, strdup( v ) );
418 return prop; 418 return prop;
@@ -790,52 +790,52 @@ static struct PreDefProp propNames[] = {
790 { VCWorkProp, 0, 0, 0 }, 790 { VCWorkProp, 0, 0, 0 },
791 { VCX400Prop, 0, 0, 0 }, 791 { VCX400Prop, 0, 0, 0 },
792 { VCX509Prop, 0, 0, 0 }, 792 { VCX509Prop, 0, 0, 0 },
793 { VCXRuleProp, 0, 0, 0 }, 793 { VCXRuleProp, 0, 0, 0 },
794 { 0,0,0,0 } 794 { 0,0,0,0 }
795 }; 795 };
796 796
797 797
798static struct PreDefProp* lookupPropInfo(const char* str) 798static struct PreDefProp* lookupPropInfo(const char* str)
799{ 799{
800 /* brute force for now, could use a hash table here. */ 800 /* brute force for now, could use a hash table here. */
801 int i; 801 int i;
802 802
803 for (i = 0; propNames[i].name; i++) 803 for (i = 0; propNames[i].name; i++)
804 if (qstricmp(str, propNames[i].name) == 0) { 804 if (qstricmp(str, propNames[i].name) == 0) {
805 return &propNames[i]; 805 return &propNames[i];
806 } 806 }
807 807
808 return 0; 808 return 0;
809} 809}
810 810
811 811
812DLLEXPORT(const char*) lookupProp_(const char* str) 812DLLEXPORT(const char*) lookupProp_(const char* str)
813{ 813{
814 int i; 814 int i;
815 815
816 for (i = 0; propNames[i].name; i++) 816 for (i = 0; propNames[i].name; i++)
817 if (qstricmp(str, propNames[i].name) == 0) { 817 if (qstricmp(str, propNames[i].name) == 0) {
818 const char* s; 818 const char* s;
819 s = propNames[i].alias?propNames[i].alias:propNames[i].name; 819 s = propNames[i].alias?propNames[i].alias:propNames[i].name;
820 return lookupStr(s); 820 return lookupStr(s);
821 } 821 }
822 return lookupStr(str); 822 return lookupStr(str);
823} 823}
824 824
825 825
826DLLEXPORT(const char*) lookupProp(const char* str) 826DLLEXPORT(const char*) lookupProp(const char* str)
827{ 827{
828 int i; 828 int i;
829 829
830 for (i = 0; propNames[i].name; i++) 830 for (i = 0; propNames[i].name; i++)
831 if (qstricmp(str, propNames[i].name) == 0) { 831 if (qstricmp(str, propNames[i].name) == 0) {
832 const char *s; 832 const char *s;
833 fieldedProp = propNames[i].fields; 833 fieldedProp = propNames[i].fields;
834 s = propNames[i].alias?propNames[i].alias:propNames[i].name; 834 s = propNames[i].alias?propNames[i].alias:propNames[i].name;
835 return lookupStr(s); 835 return lookupStr(s);
836 } 836 }
837 fieldedProp = 0; 837 fieldedProp = 0;
838 return lookupStr(str); 838 return lookupStr(str);
839} 839}
840 840
841 841
@@ -996,45 +996,45 @@ static int writeBase64(OFile *fp, unsigned char *s, long len)
996 } 996 }
997 // now output 'quad' with appropriate whitespace and line ending 997 // now output 'quad' with appropriate whitespace and line ending
998 appendsOFile(fp, (numQuads == 0 ? " " : "")); 998 appendsOFile(fp, (numQuads == 0 ? " " : ""));
999 appendsOFile(fp, quad); 999 appendsOFile(fp, quad);
1000 appendsOFile(fp, ((cur >= len)?"\n" :(numQuads==MAXQUADS-1?"\n" : ""))); 1000 appendsOFile(fp, ((cur >= len)?"\n" :(numQuads==MAXQUADS-1?"\n" : "")));
1001 numQuads = (numQuads + 1) % MAXQUADS; 1001 numQuads = (numQuads + 1) % MAXQUADS;
1002 } 1002 }
1003 appendcOFile(fp,'\n'); 1003 appendcOFile(fp,'\n');
1004 1004
1005 return 1; 1005 return 1;
1006} 1006}
1007 1007
1008static const char *replaceChar(unsigned char c) 1008static const char *replaceChar(unsigned char c)
1009{ 1009{
1010 if (c == '\n') { 1010 if (c == '\n') {
1011 return "=0A=\n"; 1011 return "=0A=\n";
1012 } else if ( 1012 } else if (
1013 (c >= 'A' && c <= 'Z') 1013 (c >= 'A' && c <= 'Z')
1014 || 1014 ||
1015 (c >= 'a' && c <= 'z') 1015 (c >= 'a' && c <= 'z')
1016 || 1016 ||
1017 (c >= '0' && c <= '9') 1017 (c >= '0' && c <= '9')
1018 || 1018 ||
1019 (c >= '\'' && c <= ')') 1019 (c >= '\'' && c <= ')')
1020 || 1020 ||
1021 (c >= '+' && c <= '-') 1021 (c >= '+' && c <= '-')
1022 || 1022 ||
1023 (c == '/') 1023 (c == '/')
1024 || 1024 ||
1025 (c == '?') 1025 (c == '?')
1026 || 1026 ||
1027 (c == ' ')) 1027 (c == ' '))
1028 { 1028 {
1029 return 0; 1029 return 0;
1030 } 1030 }
1031 1031
1032 static char trans[4]; 1032 static char trans[4];
1033 trans[0] = '='; 1033 trans[0] = '=';
1034 trans[3] = '\0'; 1034 trans[3] = '\0';
1035 int rem = c % 16; 1035 int rem = c % 16;
1036 int div = c / 16; 1036 int div = c / 16;
1037 1037
1038 if (div < 10) 1038 if (div < 10)
1039 trans[1] = '0' + div; 1039 trans[1] = '0' + div;
1040 else 1040 else
@@ -1042,34 +1042,34 @@ static const char *replaceChar(unsigned char c)
1042 1042
1043 if (rem < 10) 1043 if (rem < 10)
1044 trans[2] = '0' + rem; 1044 trans[2] = '0' + rem;
1045 else 1045 else
1046 trans[2] = 'A' + (rem - 10); 1046 trans[2] = 'A' + (rem - 10);
1047 1047
1048 return trans; 1048 return trans;
1049} 1049}
1050 1050
1051static void writeQPString(OFile *fp, const char *s) 1051static void writeQPString(OFile *fp, const char *s)
1052{ 1052{
1053 /* 1053 /*
1054 only A-Z, 0-9 and 1054 only A-Z, 0-9 and
1055 "'" (ASCII code 39) 1055 "'" (ASCII code 39)
1056 "(" (ASCII code 40) 1056 "(" (ASCII code 40)
1057 ")" (ASCII code 41) 1057 ")" (ASCII code 41)
1058 "+" (ASCII code 43) 1058 "+" (ASCII code 43)
1059 "," (ASCII code 44) 1059 "," (ASCII code 44)
1060 "-" (ASCII code 45) 1060 "-" (ASCII code 45)
1061 "/" (ASCII code 47) 1061 "/" (ASCII code 47)
1062 "?" (ASCII code 63) 1062 "?" (ASCII code 63)
1063 1063
1064 should remain un-encoded. 1064 should remain un-encoded.
1065 '=' needs to be encoded as it is the escape character. 1065 '=' needs to be encoded as it is the escape character.
1066 ';' needs to be as it is a field separator. 1066 ';' needs to be as it is a field separator.
1067 1067
1068 */ 1068 */
1069 const char *p = s; 1069 const char *p = s;
1070 while (*p) { 1070 while (*p) {
1071 const char *rep = replaceChar(*p); 1071 const char *rep = replaceChar(*p);
1072 if (rep) 1072 if (rep)
1073 appendsOFile(fp, rep); 1073 appendsOFile(fp, rep);
1074 else 1074 else
1075 appendcOFile(fp, *p); 1075 appendcOFile(fp, *p);
@@ -1084,25 +1084,25 @@ static bool includesUnprintable(VObject *o)
1084 const char *p = STRINGZ_VALUE_OF(o); 1084 const char *p = STRINGZ_VALUE_OF(o);
1085 if (p) { 1085 if (p) {
1086 while (*p) { 1086 while (*p) {
1087 if (replaceChar(*p)) 1087 if (replaceChar(*p))
1088 return TRUE; 1088 return TRUE;
1089 p++; 1089 p++;
1090 } 1090 }
1091 } 1091 }
1092 } 1092 }
1093 } 1093 }
1094 return FALSE; 1094 return FALSE;
1095} 1095}
1096 1096
1097static void writeVObject_(OFile *fp, VObject *o); 1097static void writeVObject_(OFile *fp, VObject *o);
1098 1098
1099static void writeValue(OFile *fp, VObject *o, unsigned long size) 1099static void writeValue(OFile *fp, VObject *o, unsigned long size)
1100{ 1100{
1101 if (o == 0) return; 1101 if (o == 0) return;
1102 switch (VALUE_TYPE(o)) { 1102 switch (VALUE_TYPE(o)) {
1103 case VCVT_STRINGZ: { 1103 case VCVT_STRINGZ: {
1104 writeQPString(fp, STRINGZ_VALUE_OF(o)); 1104 writeQPString(fp, STRINGZ_VALUE_OF(o));
1105 break; 1105 break;
1106 } 1106 }
1107 case VCVT_UINT: { 1107 case VCVT_UINT: {
1108 char buf[16]; 1108 char buf[16];
@@ -1220,25 +1220,25 @@ static void writeProp(OFile *fp, VObject *o)
1220 if (t) n = i; 1220 if (t) n = i;
1221 fields++; 1221 fields++;
1222 } 1222 }
1223 fields = fields_; 1223 fields = fields_;
1224 for (i=0;i<n;i++) { 1224 for (i=0;i<n;i++) {
1225 writeValue(fp,isAPropertyOf(o,*fields),0); 1225 writeValue(fp,isAPropertyOf(o,*fields),0);
1226 fields++; 1226 fields++;
1227 if (i<(n-1)) appendcOFile(fp,';'); 1227 if (i<(n-1)) appendcOFile(fp,';');
1228 } 1228 }
1229 } 1229 }
1230 } 1230 }
1231 1231
1232 1232
1233 if (VALUE_TYPE(o)) { 1233 if (VALUE_TYPE(o)) {
1234 if ( includesUnprintable(o) ) { 1234 if ( includesUnprintable(o) ) {
1235 appendsOFile(fp, ";" VCEncodingProp "=" VCQuotedPrintableProp); 1235 appendsOFile(fp, ";" VCEncodingProp "=" VCQuotedPrintableProp);
1236 appendsOFile(fp, ";" VCCharSetProp "=" "UTF-8"); 1236 appendsOFile(fp, ";" VCCharSetProp "=" "UTF-8");
1237 } 1237 }
1238 unsigned long size = 0; 1238 unsigned long size = 0;
1239 VObject *p = isAPropertyOf(o,VCDataSizeProp); 1239 VObject *p = isAPropertyOf(o,VCDataSizeProp);
1240 if (p) size = LONG_VALUE_OF(p); 1240 if (p) size = LONG_VALUE_OF(p);
1241 appendcOFile(fp,':'); 1241 appendcOFile(fp,':');
1242 writeValue(fp,o,size); 1242 writeValue(fp,o,size);
1243 } 1243 }
1244 1244