-rw-r--r-- | library/backend/vobject.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/library/backend/vobject.cpp b/library/backend/vobject.cpp index 592d116..28b8bae 100644 --- a/library/backend/vobject.cpp +++ b/library/backend/vobject.cpp | |||
@@ -974,391 +974,393 @@ static void initOFile(OFile *fp, FILE *ofp) | |||
974 | fp->len = 0; | 974 | fp->len = 0; |
975 | fp->limit = 0; | 975 | fp->limit = 0; |
976 | fp->alloc = 0; | 976 | fp->alloc = 0; |
977 | fp->fail = 0; | 977 | fp->fail = 0; |
978 | } | 978 | } |
979 | 979 | ||
980 | static int writeBase64(OFile *fp, unsigned char *s, long len) | 980 | static int writeBase64(OFile *fp, unsigned char *s, long len) |
981 | { | 981 | { |
982 | long cur = 0; | 982 | long cur = 0; |
983 | int i, numQuads = 0; | 983 | int i, numQuads = 0; |
984 | unsigned long trip; | 984 | unsigned long trip; |
985 | unsigned char b; | 985 | unsigned char b; |
986 | char quad[5]; | 986 | char quad[5]; |
987 | #define MAXQUADS 16 | 987 | #define MAXQUADS 16 |
988 | 988 | ||
989 | quad[4] = 0; | 989 | quad[4] = 0; |
990 | 990 | ||
991 | while (cur < len) { | 991 | while (cur < len) { |
992 | // collect the triplet of bytes into 'trip' | 992 | // collect the triplet of bytes into 'trip' |
993 | trip = 0; | 993 | trip = 0; |
994 | for (i = 0; i < 3; i++) { | 994 | for (i = 0; i < 3; i++) { |
995 | b = (cur < len) ? *(s + cur) : 0; | 995 | b = (cur < len) ? *(s + cur) : 0; |
996 | cur++; | 996 | cur++; |
997 | trip = trip << 8 | b; | 997 | trip = trip << 8 | b; |
998 | } | 998 | } |
999 | // fill in 'quad' with the appropriate four characters | 999 | // fill in 'quad' with the appropriate four characters |
1000 | for (i = 3; i >= 0; i--) { | 1000 | for (i = 3; i >= 0; i--) { |
1001 | b = (unsigned char)(trip & 0x3F); | 1001 | b = (unsigned char)(trip & 0x3F); |
1002 | trip = trip >> 6; | 1002 | trip = trip >> 6; |
1003 | if ((3 - i) < (cur - len)) | 1003 | if ((3 - i) < (cur - len)) |
1004 | quad[i] = '='; // pad char | 1004 | quad[i] = '='; // pad char |
1005 | else if (b < 26) quad[i] = (char)b + 'A'; | 1005 | else if (b < 26) quad[i] = (char)b + 'A'; |
1006 | else if (b < 52) quad[i] = (char)(b - 26) + 'a'; | 1006 | else if (b < 52) quad[i] = (char)(b - 26) + 'a'; |
1007 | else if (b < 62) quad[i] = (char)(b - 52) + '0'; | 1007 | else if (b < 62) quad[i] = (char)(b - 52) + '0'; |
1008 | else if (b == 62) quad[i] = '+'; | 1008 | else if (b == 62) quad[i] = '+'; |
1009 | else quad[i] = '/'; | 1009 | else quad[i] = '/'; |
1010 | } | 1010 | } |
1011 | // now output 'quad' with appropriate whitespace and line ending | 1011 | // now output 'quad' with appropriate whitespace and line ending |
1012 | appendsOFile(fp, (numQuads == 0 ? " " : "")); | 1012 | appendsOFile(fp, (numQuads == 0 ? " " : "")); |
1013 | appendsOFile(fp, quad); | 1013 | appendsOFile(fp, quad); |
1014 | appendsOFile(fp, ((cur >= len)?"\n" :(numQuads==MAXQUADS-1?"\n" : ""))); | 1014 | appendsOFile(fp, ((cur >= len)?"\n" :(numQuads==MAXQUADS-1?"\n" : ""))); |
1015 | numQuads = (numQuads + 1) % MAXQUADS; | 1015 | numQuads = (numQuads + 1) % MAXQUADS; |
1016 | } | 1016 | } |
1017 | appendcOFile(fp,'\n'); | 1017 | appendcOFile(fp,'\n'); |
1018 | 1018 | ||
1019 | return 1; | 1019 | return 1; |
1020 | } | 1020 | } |
1021 | 1021 | ||
1022 | static const char *qpReplaceChar(unsigned char c) | 1022 | static const char *qpReplaceChar(unsigned char c) |
1023 | { | 1023 | { |
1024 | if (c == '\n') { | 1024 | if (c == '\n') { |
1025 | return "=0A=\n"; | 1025 | return "=0A=\n"; |
1026 | } else if ( | 1026 | } else if ( |
1027 | // RFC 1521 | 1027 | // RFC 1521 |
1028 | (c >= 32 && c <= 60) // Note: " " not allowed at EOL | 1028 | (c >= 32 && c <= 60) // Note: " " not allowed at EOL |
1029 | || | 1029 | || |
1030 | (c >= 62 && c <= 126) | 1030 | (c >= 62 && c <= 126) |
1031 | ) | 1031 | ) |
1032 | { | 1032 | { |
1033 | return 0; | 1033 | return 0; |
1034 | } | 1034 | } |
1035 | 1035 | ||
1036 | static char trans[4]; | 1036 | static char trans[4]; |
1037 | trans[0] = '='; | 1037 | trans[0] = '='; |
1038 | trans[3] = '\0'; | 1038 | trans[3] = '\0'; |
1039 | int rem = c % 16; | 1039 | int rem = c % 16; |
1040 | int div = c / 16; | 1040 | int div = c / 16; |
1041 | 1041 | ||
1042 | if (div < 10) | 1042 | if (div < 10) |
1043 | trans[1] = '0' + div; | 1043 | trans[1] = '0' + div; |
1044 | else | 1044 | else |
1045 | trans[1] = 'A' + (div - 10); | 1045 | trans[1] = 'A' + (div - 10); |
1046 | 1046 | ||
1047 | if (rem < 10) | 1047 | if (rem < 10) |
1048 | trans[2] = '0' + rem; | 1048 | trans[2] = '0' + rem; |
1049 | else | 1049 | else |
1050 | trans[2] = 'A' + (rem - 10); | 1050 | trans[2] = 'A' + (rem - 10); |
1051 | 1051 | ||
1052 | return trans; | 1052 | return trans; |
1053 | } | 1053 | } |
1054 | 1054 | ||
1055 | static void writeEncString(OFile *fp, const char *s, bool nosemi) | 1055 | static void writeEncString(OFile *fp, const char *s, bool nosemi) |
1056 | { | 1056 | { |
1057 | /* | 1057 | /* |
1058 | only A-Z, 0-9 and | 1058 | only A-Z, 0-9 and |
1059 | "'" (ASCII code 39) | 1059 | "'" (ASCII code 39) |
1060 | "(" (ASCII code 40) | 1060 | "(" (ASCII code 40) |
1061 | ")" (ASCII code 41) | 1061 | ")" (ASCII code 41) |
1062 | "+" (ASCII code 43) | 1062 | "+" (ASCII code 43) |
1063 | "," (ASCII code 44) | 1063 | "," (ASCII code 44) |
1064 | "-" (ASCII code 45) | 1064 | "-" (ASCII code 45) |
1065 | "/" (ASCII code 47) | 1065 | "/" (ASCII code 47) |
1066 | "?" (ASCII code 63) | 1066 | "?" (ASCII code 63) |
1067 | 1067 | ||
1068 | should remain un-encoded. | 1068 | should remain un-encoded. |
1069 | '=' needs to be encoded as it is the escape character. | 1069 | '=' needs to be encoded as it is the escape character. |
1070 | ';' needs to be as it is a field separator. | 1070 | ';' needs to be as it is a field separator. |
1071 | 1071 | ||
1072 | */ | 1072 | */ |
1073 | const char *p = s; | 1073 | const char *p = s; |
1074 | switch ( vobj_enc ) { | 1074 | switch ( vobj_enc ) { |
1075 | case EightBit: | 1075 | case EightBit: |
1076 | while (*p) { | 1076 | while (*p) { |
1077 | if ( *p == '\n' || nosemi && ( *p == '\\' || *p == ';' ) ) | 1077 | if ( *p == '\n' || nosemi && ( *p == '\\' || *p == ';' ) ) |
1078 | appendcOFile(fp, '\\'); | 1078 | appendcOFile(fp, '\\'); |
1079 | appendcOFile(fp, *p); | 1079 | appendcOFile(fp, *p); |
1080 | p++; | 1080 | p++; |
1081 | } | 1081 | } |
1082 | break; | 1082 | break; |
1083 | case QuotedPrintable: | 1083 | case QuotedPrintable: |
1084 | while (*p) { | 1084 | while (*p) { |
1085 | const char *rep = qpReplaceChar(*p); | 1085 | const char *rep = qpReplaceChar(*p); |
1086 | if (rep) | 1086 | if (rep) |
1087 | appendsOFile(fp, rep); | 1087 | appendsOFile(fp, rep); |
1088 | else if ( *p == ';' && nosemi ) | 1088 | else if ( *p == ';' && nosemi ) |
1089 | appendsOFile(fp, "=3B"); | 1089 | appendsOFile(fp, "=3B"); |
1090 | else if ( *p == ' ' ) { | 1090 | else if ( *p == ' ' ) { |
1091 | if ( !p[1] || p[1] == '\n' ) // RFC 1521 | 1091 | if ( !p[1] || p[1] == '\n' ) // RFC 1521 |
1092 | appendsOFile(fp, "=20"); | 1092 | appendsOFile(fp, "=20"); |
1093 | else | 1093 | else |
1094 | appendcOFile(fp, *p); | 1094 | appendcOFile(fp, *p); |
1095 | } else | 1095 | } else |
1096 | appendcOFile(fp, *p); | 1096 | appendcOFile(fp, *p); |
1097 | p++; | 1097 | p++; |
1098 | } | 1098 | } |
1099 | break; | 1099 | break; |
1100 | case Base64: | 1100 | case Base64: |
1101 | writeBase64(fp, (unsigned char*)p, strlen(p)); | 1101 | writeBase64(fp, (unsigned char*)p, strlen(p)); |
1102 | break; | 1102 | break; |
1103 | } | 1103 | } |
1104 | } | 1104 | } |
1105 | 1105 | ||
1106 | static bool includesUnprintable(VObject *o, bool nosemi) | 1106 | static bool includesUnprintable(VObject *o, bool nosemi) |
1107 | { | 1107 | { |
1108 | if (o) { | 1108 | if (o) { |
1109 | if (VALUE_TYPE(o) == VCVT_STRINGZ) { | 1109 | if (VALUE_TYPE(o) == VCVT_STRINGZ) { |
1110 | const char *p = STRINGZ_VALUE_OF(o); | 1110 | const char *p = STRINGZ_VALUE_OF(o); |
1111 | if (p) { | 1111 | if (p) { |
1112 | while (*p) { | 1112 | while (*p) { |
1113 | if (*p==' ' && (!p[1] || p[1]=='\n') // RFC 1521: spaces at ends need quoting | 1113 | if (*p==' ' && (!p[1] || p[1]=='\n') // RFC 1521: spaces at ends need quoting |
1114 | || qpReplaceChar(*p) | 1114 | || qpReplaceChar(*p) |
1115 | || *p==';' && nosemi ) | 1115 | || *p==';' && nosemi ) |
1116 | return TRUE; | 1116 | return TRUE; |
1117 | p++; | 1117 | p++; |
1118 | } | 1118 | } |
1119 | } | 1119 | } |
1120 | } | 1120 | } |
1121 | } | 1121 | } |
1122 | return FALSE; | 1122 | return FALSE; |
1123 | } | 1123 | } |
1124 | 1124 | ||
1125 | static void writeVObject_(OFile *fp, VObject *o); | 1125 | static void writeVObject_(OFile *fp, VObject *o); |
1126 | 1126 | ||
1127 | static void writeValue(OFile *fp, VObject *o, unsigned long size, bool nosemi) | 1127 | static void writeValue(OFile *fp, VObject *o, unsigned long size, bool nosemi) |
1128 | { | 1128 | { |
1129 | if (o == 0) return; | 1129 | if (o == 0) return; |
1130 | switch (VALUE_TYPE(o)) { | 1130 | switch (VALUE_TYPE(o)) { |
1131 | case VCVT_STRINGZ: { | 1131 | case VCVT_STRINGZ: { |
1132 | writeEncString(fp, STRINGZ_VALUE_OF(o), nosemi); | 1132 | writeEncString(fp, STRINGZ_VALUE_OF(o), nosemi); |
1133 | break; | 1133 | break; |
1134 | } | 1134 | } |
1135 | case VCVT_UINT: { | 1135 | case VCVT_UINT: { |
1136 | char buf[16]; | 1136 | char buf[16]; |
1137 | sprintf(buf,"%u", INTEGER_VALUE_OF(o)); | 1137 | sprintf(buf,"%u", INTEGER_VALUE_OF(o)); |
1138 | appendsOFile(fp,buf); | 1138 | appendsOFile(fp,buf); |
1139 | break; | 1139 | break; |
1140 | } | 1140 | } |
1141 | case VCVT_ULONG: { | 1141 | case VCVT_ULONG: { |
1142 | char buf[16]; | 1142 | char buf[16]; |
1143 | sprintf(buf,"%lu", LONG_VALUE_OF(o)); | 1143 | sprintf(buf,"%lu", LONG_VALUE_OF(o)); |
1144 | appendsOFile(fp,buf); | 1144 | appendsOFile(fp,buf); |
1145 | break; | 1145 | break; |
1146 | } | 1146 | } |
1147 | case VCVT_RAW: { | 1147 | case VCVT_RAW: { |
1148 | appendcOFile(fp,'\n'); | 1148 | appendcOFile(fp,'\n'); |
1149 | writeBase64(fp,(unsigned char*)(ANY_VALUE_OF(o)),size); | 1149 | writeBase64(fp,(unsigned char*)(ANY_VALUE_OF(o)),size); |
1150 | break; | 1150 | break; |
1151 | } | 1151 | } |
1152 | case VCVT_VOBJECT: | 1152 | case VCVT_VOBJECT: |
1153 | appendcOFile(fp,'\n'); | 1153 | appendcOFile(fp,'\n'); |
1154 | writeVObject_(fp,VOBJECT_VALUE_OF(o)); | 1154 | writeVObject_(fp,VOBJECT_VALUE_OF(o)); |
1155 | break; | 1155 | break; |
1156 | } | 1156 | } |
1157 | } | 1157 | } |
1158 | 1158 | ||
1159 | static void writeAttrValue(OFile *fp, VObject *o) | 1159 | static void writeAttrValue(OFile *fp, VObject *o) |
1160 | { | 1160 | { |
1161 | if (NAME_OF(o)) { | 1161 | if (NAME_OF(o)) { |
1162 | struct PreDefProp *pi; | 1162 | struct PreDefProp *pi; |
1163 | pi = lookupPropInfo(NAME_OF(o)); | 1163 | pi = lookupPropInfo(NAME_OF(o)); |
1164 | if (pi && ((pi->flags & PD_INTERNAL) != 0)) return; | 1164 | if (pi && ((pi->flags & PD_INTERNAL) != 0)) return; |
1165 | if ( includesUnprintable(o,TRUE) ) | 1165 | if ( includesUnprintable(o,TRUE) ) |
1166 | appendsOFileEncCs(fp); | 1166 | appendsOFileEncCs(fp); |
1167 | appendcOFile(fp,';'); | 1167 | appendcOFile(fp,';'); |
1168 | appendsOFile(fp,NAME_OF(o)); | 1168 | appendsOFile(fp,NAME_OF(o)); |
1169 | } else { | 1169 | } else { |
1170 | appendcOFile(fp,';'); | 1170 | appendcOFile(fp,';'); |
1171 | } | 1171 | } |
1172 | if (VALUE_TYPE(o)) { | 1172 | if (VALUE_TYPE(o)) { |
1173 | appendcOFile(fp,'='); | 1173 | appendcOFile(fp,'='); |
1174 | writeValue(fp,o,0,TRUE); | 1174 | writeValue(fp,o,0,TRUE); |
1175 | } | 1175 | } |
1176 | } | 1176 | } |
1177 | 1177 | ||
1178 | static void writeGroup(OFile *fp, VObject *o) | 1178 | static void writeGroup(OFile *fp, VObject *o) |
1179 | { | 1179 | { |
1180 | char buf1[256]; | 1180 | char buf1[256]; |
1181 | char buf2[256]; | 1181 | char buf2[256]; |
1182 | strcpy(buf1,NAME_OF(o)); | 1182 | strcpy(buf1,NAME_OF(o)); |
1183 | while ((o=isAPropertyOf(o,VCGroupingProp)) != 0) { | 1183 | while ((o=isAPropertyOf(o,VCGroupingProp)) != 0) { |
1184 | strcpy(buf2,STRINGZ_VALUE_OF(o)); | 1184 | strcpy(buf2,STRINGZ_VALUE_OF(o)); |
1185 | strcat(buf2,"."); | 1185 | strcat(buf2,"."); |
1186 | strcat(buf2,buf1); | 1186 | strcat(buf2,buf1); |
1187 | strcpy(buf1,buf2); | 1187 | strcpy(buf1,buf2); |
1188 | } | 1188 | } |
1189 | appendsOFile(fp,buf1); | 1189 | appendsOFile(fp,buf1); |
1190 | } | 1190 | } |
1191 | 1191 | ||
1192 | static int inList(const char **list, const char *s) | 1192 | static int inList(const char **list, const char *s) |
1193 | { | 1193 | { |
1194 | if (list == 0) return 0; | 1194 | if (list == 0) return 0; |
1195 | while (*list) { | 1195 | while (*list) { |
1196 | if (qstricmp(*list,s) == 0) return 1; | 1196 | if (qstricmp(*list,s) == 0) return 1; |
1197 | list++; | 1197 | list++; |
1198 | } | 1198 | } |
1199 | return 0; | 1199 | return 0; |
1200 | } | 1200 | } |
1201 | 1201 | ||
1202 | static void writeProp(OFile *fp, VObject *o) | 1202 | static void writeProp(OFile *fp, VObject *o) |
1203 | { | 1203 | { |
1204 | if (NAME_OF(o)) { | 1204 | if (NAME_OF(o)) { |
1205 | struct PreDefProp *pi; | 1205 | struct PreDefProp *pi; |
1206 | VObjectIterator t; | 1206 | VObjectIterator t; |
1207 | const char **fields_ = 0; | 1207 | const char **fields_ = 0; |
1208 | pi = lookupPropInfo(NAME_OF(o)); | 1208 | pi = lookupPropInfo(NAME_OF(o)); |
1209 | if (pi && ((pi->flags & PD_BEGIN) != 0)) { | 1209 | if (pi && ((pi->flags & PD_BEGIN) != 0)) { |
1210 | writeVObject_(fp,o); | 1210 | writeVObject_(fp,o); |
1211 | return; | 1211 | return; |
1212 | } | 1212 | } |
1213 | if (isAPropertyOf(o,VCGroupingProp)) | 1213 | if (isAPropertyOf(o,VCGroupingProp)) |
1214 | writeGroup(fp,o); | 1214 | writeGroup(fp,o); |
1215 | else | 1215 | else |
1216 | appendsOFile(fp,NAME_OF(o)); | 1216 | appendsOFile(fp,NAME_OF(o)); |
1217 | if (pi) fields_ = pi->fields; | 1217 | if (pi) fields_ = pi->fields; |
1218 | initPropIterator(&t,o); | 1218 | initPropIterator(&t,o); |
1219 | while (moreIteration(&t)) { | 1219 | while (moreIteration(&t)) { |
1220 | const char *s; | 1220 | const char *s; |
1221 | VObject *eachProp = nextVObject(&t); | 1221 | VObject *eachProp = nextVObject(&t); |
1222 | s = NAME_OF(eachProp); | 1222 | s = NAME_OF(eachProp); |
1223 | if (qstricmp(VCGroupingProp,s) && !inList(fields_,s)) | 1223 | if (qstricmp(VCGroupingProp,s) && !inList(fields_,s)) |
1224 | writeAttrValue(fp,eachProp); | 1224 | writeAttrValue(fp,eachProp); |
1225 | } | 1225 | } |
1226 | if (fields_) { | 1226 | if (fields_) { |
1227 | int i = 0, n = 0; | 1227 | int i = 0, n = 0; |
1228 | const char** fields = fields_; | 1228 | const char** fields = fields_; |
1229 | /* output prop as fields */ | 1229 | /* output prop as fields */ |
1230 | bool printable = TRUE; | 1230 | bool printable = TRUE; |
1231 | while (*fields && printable) { | 1231 | while (*fields && printable) { |
1232 | VObject *t = isAPropertyOf(o,*fields); | 1232 | VObject *t = isAPropertyOf(o,*fields); |
1233 | if (includesUnprintable(t,TRUE)) | 1233 | if (includesUnprintable(t,TRUE)) |
1234 | printable = FALSE; | 1234 | printable = FALSE; |
1235 | fields++; | 1235 | fields++; |
1236 | } | 1236 | } |
1237 | fields = fields_; | 1237 | fields = fields_; |
1238 | if (!printable) | 1238 | if (!printable) |
1239 | appendsOFileEncCs(fp); | 1239 | appendsOFileEncCs(fp); |
1240 | appendcOFile(fp,':'); | 1240 | appendcOFile(fp,':'); |
1241 | while (*fields) { | 1241 | while (*fields) { |
1242 | VObject *t = isAPropertyOf(o,*fields); | 1242 | VObject *t = isAPropertyOf(o,*fields); |
1243 | i++; | 1243 | i++; |
1244 | if (t) n = i; | 1244 | if (t) n = i; |
1245 | fields++; | 1245 | fields++; |
1246 | } | 1246 | } |
1247 | fields = fields_; | 1247 | fields = fields_; |
1248 | for (i=0;i<n;i++) { | 1248 | for (i=0;i<n;i++) { |
1249 | writeValue(fp,isAPropertyOf(o,*fields),0,TRUE); | 1249 | writeValue(fp,isAPropertyOf(o,*fields),0,TRUE); |
1250 | fields++; | 1250 | fields++; |
1251 | if (i<(n-1)) appendcOFile(fp,';'); | 1251 | if (i<(n-1)) appendcOFile(fp,';'); |
1252 | } | 1252 | } |
1253 | } | 1253 | } |
1254 | } | 1254 | } |
1255 | 1255 | ||
1256 | 1256 | ||
1257 | if (VALUE_TYPE(o)) { | 1257 | if (VALUE_TYPE(o)) { |
1258 | if ( includesUnprintable(o,FALSE) ) | 1258 | if ( includesUnprintable(o,FALSE) ) |
1259 | appendsOFileEncCs(fp); | 1259 | appendsOFileEncCs(fp); |
1260 | unsigned long size = 0; | 1260 | unsigned long size = 0; |
1261 | VObject *p = isAPropertyOf(o,VCDataSizeProp); | 1261 | VObject *p = isAPropertyOf(o,VCDataSizeProp); |
1262 | if (p) size = LONG_VALUE_OF(p); | 1262 | if (p) size = LONG_VALUE_OF(p); |
1263 | appendcOFile(fp,':'); | 1263 | appendcOFile(fp,':'); |
1264 | writeValue(fp,o,size,FALSE); | 1264 | writeValue(fp,o,size,FALSE); |
1265 | } | 1265 | } |
1266 | 1266 | ||
1267 | appendcOFile(fp,'\n'); | 1267 | appendcOFile(fp,'\n'); |
1268 | } | 1268 | } |
1269 | 1269 | ||
1270 | static void writeVObject_(OFile *fp, VObject *o) | 1270 | static void writeVObject_(OFile *fp, VObject *o) |
1271 | { | 1271 | { |
1272 | if (NAME_OF(o)) { | 1272 | if (NAME_OF(o)) { |
1273 | struct PreDefProp *pi; | 1273 | struct PreDefProp *pi; |
1274 | pi = lookupPropInfo(NAME_OF(o)); | 1274 | pi = lookupPropInfo(NAME_OF(o)); |
1275 | 1275 | ||
1276 | if (pi && ((pi->flags & PD_BEGIN) != 0)) { | 1276 | if (pi && ((pi->flags & PD_BEGIN) != 0)) { |
1277 | VObjectIterator t; | 1277 | VObjectIterator t; |
1278 | const char *begin = NAME_OF(o); | 1278 | const char *begin = NAME_OF(o); |
1279 | appendsOFile(fp,"BEGIN:"); | 1279 | appendsOFile(fp,"BEGIN:"); |
1280 | appendsOFile(fp,begin); | 1280 | appendsOFile(fp,begin); |
1281 | appendcOFile(fp,'\n'); | 1281 | appendcOFile(fp,'\n'); |
1282 | initPropIterator(&t,o); | 1282 | initPropIterator(&t,o); |
1283 | while (moreIteration(&t)) { | 1283 | while (moreIteration(&t)) { |
1284 | VObject *eachProp = nextVObject(&t); | 1284 | VObject *eachProp = nextVObject(&t); |
1285 | writeProp(fp, eachProp); | 1285 | writeProp(fp, eachProp); |
1286 | } | 1286 | } |
1287 | appendsOFile(fp,"END:"); | 1287 | appendsOFile(fp,"END:"); |
1288 | appendsOFile(fp,begin); | 1288 | appendsOFile(fp,begin); |
1289 | appendsOFile(fp,"\n\n"); | 1289 | appendsOFile(fp,"\n\n"); |
1290 | } | 1290 | } |
1291 | } | 1291 | } |
1292 | } | 1292 | } |
1293 | 1293 | ||
1294 | static void initVObjectEncoding() | 1294 | static void initVObjectEncoding() |
1295 | { | 1295 | { |
1296 | Config pimConfig( "Beam" ); | 1296 | Config pimConfig( "Beam" ); |
1297 | pimConfig.setGroup("Send"); | 1297 | pimConfig.setGroup("Send"); |
1298 | Config devcfg(pimConfig.readEntry("DeviceConfig"),Config::File); | 1298 | Config devcfg(pimConfig.readEntry("DeviceConfig"),Config::File); |
1299 | QString enc = "QP"; | 1299 | QString enc = "QP"; |
1300 | QString cs = "UTF-8"; | 1300 | QString cs = "UTF-8"; |
1301 | if ( devcfg.isValid() ) { | 1301 | if ( devcfg.isValid() ) { |
1302 | devcfg.setGroup("Send"); | 1302 | devcfg.setGroup("Send"); |
1303 | enc = devcfg.readEntry("Encoding","QP"); | 1303 | enc = devcfg.readEntry("Encoding","QP"); |
1304 | cs = devcfg.readEntry("CharSet","UTF-8"); | 1304 | cs = devcfg.readEntry("CharSet","UTF-8"); |
1305 | } | 1305 | } |
1306 | strncpy(vobj_cs,cs.latin1(),10); | 1306 | strncpy(vobj_cs,cs.latin1(),10); |
1307 | if ( enc == "QP" ) { | 1307 | if ( enc == "QP" ) { |
1308 | vobj_enc = QuotedPrintable; | 1308 | vobj_enc = QuotedPrintable; |
1309 | vobj_enc_s = VCQuotedPrintableProp; | 1309 | vobj_enc_s = VCQuotedPrintableProp; |
1310 | } else if ( enc == "B64" ) { | 1310 | } else if ( enc == "B64" ) { |
1311 | vobj_enc = Base64; | 1311 | vobj_enc = Base64; |
1312 | vobj_enc_s = VCBase64Prop; | 1312 | vobj_enc_s = VCBase64Prop; |
1313 | } else { | 1313 | } else { |
1314 | vobj_enc = EightBit; | 1314 | vobj_enc = EightBit; |
1315 | vobj_enc_s = 0; | 1315 | vobj_enc_s = 0; |
1316 | } | 1316 | } |
1317 | } | 1317 | } |
1318 | 1318 | ||
1319 | void writeVObject(FILE *fp, VObject *o) | 1319 | void writeVObject(FILE *fp, VObject *o) |
1320 | { | 1320 | { |
1321 | initVObjectEncoding(); | 1321 | initVObjectEncoding(); |
1322 | 1322 | ||
1323 | OFile ofp; | 1323 | OFile ofp; |
1324 | // ##### | 1324 | // ##### |
1325 | //_setmode(_fileno(fp), _O_BINARY); | 1325 | //_setmode(_fileno(fp), _O_BINARY); |
1326 | initOFile(&ofp,fp); | 1326 | initOFile(&ofp,fp); |
1327 | writeVObject_(&ofp,o); | 1327 | writeVObject_(&ofp,o); |
1328 | } | 1328 | } |
1329 | 1329 | ||
1330 | DLLEXPORT(void) writeVObjectToFile(char *fname, VObject *o) | 1330 | DLLEXPORT(void) writeVObjectToFile(char *fname, VObject *o) |
1331 | { | 1331 | { |
1332 | QFileDirect f( fname); | 1332 | QFileDirect f( fname); |
1333 | if ( !f.open( IO_WriteOnly ) ) { | 1333 | if ( !f.open( IO_WriteOnly ) ) { |
1334 | qWarning("Unable to open vobject write %s", fname); | 1334 | qWarning("Unable to open vobject write %s", fname); |
1335 | return; | 1335 | return; |
1336 | } | 1336 | } |
1337 | 1337 | ||
1338 | writeVObject( f.directHandle(),o ); | 1338 | writeVObject( f.directHandle(),o ); |
1339 | } | 1339 | } |
1340 | 1340 | ||
1341 | DLLEXPORT(void) writeVObjectsToFile(char *fname, VObject *list) | 1341 | DLLEXPORT(void) writeVObjectsToFile(char *fname, VObject *list) |
1342 | { | 1342 | { |
1343 | QFileDirect f( fname); | 1343 | QFileDirect f( fname); |
1344 | if ( !f.open( IO_WriteOnly ) ) { | 1344 | if ( !f.open( IO_WriteOnly ) ) { |
1345 | qWarning("Unable to open vobject write %s", fname); | 1345 | qWarning("Unable to open vobject write %s", fname); |
1346 | return; | 1346 | return; |
1347 | } | 1347 | } |
1348 | 1348 | ||
1349 | while (list) { | 1349 | while (list) { |
1350 | writeVObject(f.directHandle(),list); | 1350 | writeVObject(f.directHandle(),list); |
1351 | list = nextVObjectInList(list); | 1351 | list = nextVObjectInList(list); |
1352 | } | 1352 | } |
1353 | } | 1353 | } |
1354 | 1354 | ||
1355 | DLLEXPORT(const char *) vObjectTypeInfo(VObject *o) | 1355 | DLLEXPORT(const char *) vObjectTypeInfo(VObject *o) |
1356 | { | 1356 | { |
1357 | const char *type = vObjectName( o ); | 1357 | const char *type = vObjectName( o ); |
1358 | if ( strcmp( type, "TYPE" ) == 0 ) | 1358 | if ( strcmp( type, "type" ) == 0 || |
1359 | type = vObjectStringZValue( o ); | 1359 | strcmp( type, "TYPE" ) == 0 || |
1360 | strcmp( type, "Type" ) == 0 ) | ||
1361 | type = vObjectStringZValue( o ); | ||
1360 | return type; | 1362 | return type; |
1361 | } | 1363 | } |
1362 | 1364 | ||
1363 | 1365 | ||
1364 | // end of source file vobject.c | 1366 | // end of source file vobject.c |