author | eilers <eilers> | 2004-11-19 11:05:19 (UTC) |
---|---|---|
committer | eilers <eilers> | 2004-11-19 11:05:19 (UTC) |
commit | 362e353e4ee43a5aa37fd4c264ad0b40bbd0098b (patch) (unidiff) | |
tree | 52de09cbe81e5105cfdef9b606c10e4239cef814 | |
parent | 6b1a6e3bf5d012e517c9668501f030d8c660b537 (diff) | |
download | opie-362e353e4ee43a5aa37fd4c264ad0b40bbd0098b.zip opie-362e353e4ee43a5aa37fd4c264ad0b40bbd0098b.tar.gz opie-362e353e4ee43a5aa37fd4c264ad0b40bbd0098b.tar.bz2 |
Don't just allow "TYPE=<value>".. This makes the vcard import filter more
robust against unexpected typos..
-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 | |||
@@ -1102,263 +1102,265 @@ static void writeEncString(OFile *fp, const char *s, bool nosemi) | |||
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 |