00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <tqcstring.h>
00025 #include <ctype.h>
00026
00027 #include <VCardEnum.h>
00028
00029 using namespace VCARD;
00030
00031
00032
00033
00034 const TQCString
00035 VCARD::paramNames [] =
00036 {
00037 "NAME",
00038 "PROFILE",
00039 "SOURCE",
00040 "FN",
00041 "N",
00042 "NICKNAME",
00043 "PHOTO",
00044 "BDAY",
00045 "ADR",
00046 "LABEL",
00047 "TEL",
00048 "EMAIL",
00049 "MAILER",
00050 "TZ",
00051 "GEO",
00052 "TITLE",
00053 "ROLE",
00054 "LOGO",
00055 "AGENT",
00056 "ORG",
00057 "CATEGORIES",
00058 "NOTE",
00059 "PRODID",
00060 "REV",
00061 "SORT-STRING",
00062 "SOUND",
00063 "UID",
00064 "URL",
00065 "VERSION",
00066 "CLASS",
00067 "KEY",
00068 "URI"
00069 };
00070
00071 const ParamType
00072 VCARD::paramTypesTable[] = {
00073 ParamNone,
00074 ParamNone,
00075 ParamSource,
00076 ParamText,
00077 ParamText,
00078 ParamText,
00079 ParamImage,
00080 ParamDate,
00081 ParamAddrText,
00082 ParamAddrText,
00083 ParamTel,
00084 ParamEmail,
00085 ParamText,
00086 ParamNone,
00087 ParamNone,
00088 ParamText,
00089 ParamText,
00090 ParamImage,
00091 ParamAgent,
00092 ParamText,
00093 ParamText,
00094 ParamText,
00095 ParamNone,
00096 ParamDate,
00097 ParamText,
00098 ParamSound,
00099 ParamNone,
00100 ParamNone,
00101 ParamNone,
00102 ParamNone,
00103 ParamTextBin,
00104 ParamTextNS,
00105 ParamNone
00106 };
00107
00108 ParamType
00109 VCARD::EntityTypeToParamType(EntityType e)
00110 {
00111 ParamType t(ParamUnknown);
00112
00113 switch (e) {
00114
00115
00116 case EntityAgent: t = ParamAgent; break;
00117
00118 case EntitySound: t = ParamSound; break;
00119
00120 case EntitySource: t = ParamSource; break;
00121
00122 case EntityTelephone: t = ParamTel; break;
00123
00124 case EntityEmail: t = ParamEmail; break;
00125
00126 case EntityKey: t = ParamTextBin; break;
00127
00128 case EntityExtension: t = ParamTextNS; break;
00129
00130 case EntityAddress:
00131 case EntityLabel: t = ParamAddrText; break;
00132
00133 case EntityBirthday:
00134 case EntityRevision: t = ParamDate; break;
00135
00136 case EntityPhoto:
00137 case EntityLogo: t = ParamImage; break;
00138
00139 case EntityOrganisation:
00140 case EntityTitle:
00141 case EntityRole:
00142 case EntityFullName:
00143 case EntityMailer:
00144 case EntityN:
00145 case EntitySortString:
00146 case EntityNickname:
00147 case EntityCategories:
00148 case EntityNote: t = ParamText; break;
00149
00150 case EntityProductID:
00151 case EntityTimeZone:
00152 case EntityUID:
00153 case EntityURL:
00154 case EntityClass:
00155 case EntityGeo:
00156 case EntityName:
00157 case EntityVersion:
00158 case EntityProfile:
00159 case EntityURI:
00160 default: t = ParamNone; break;
00161
00162
00163 }
00164
00165 return t;
00166 }
00167
00168 ValueType
00169 VCARD::EntityTypeToValueType(EntityType e)
00170 {
00171 ValueType t(ValueUnknown);
00172
00173 switch (e) {
00174
00175
00176 case EntitySound: t = ValueSound; break;
00177
00178 case EntityAgent: t = ValueAgent; break;
00179
00180 case EntityAddress: t = ValueAddress; break;
00181
00182 case EntityTelephone: t = ValueTel; break;
00183
00184 case EntityKey: t = ValueTextBin; break;
00185
00186 case EntityOrganisation: t = ValueOrg; break;
00187
00188 case EntityN: t = ValueN; break;
00189
00190 case EntityTimeZone: t = ValueUTC; break;
00191
00192 case EntityClass: t = ValueClass; break;
00193
00194 case EntityGeo: t = ValueGeo; break;
00195
00196 case EntitySource:
00197 case EntityURL: t = ValueURI; break;
00198
00199 case EntityPhoto:
00200 case EntityLogo: t = ValueImage; break;
00201
00202 case EntityBirthday:
00203 case EntityRevision: t = ValueDate; break;
00204
00205 case EntityCategories:
00206 case EntityNickname: t = ValueTextList; break;
00207
00208 case EntityLabel:
00209 case EntityExtension:
00210 case EntityEmail:
00211 case EntityTitle:
00212 case EntityRole:
00213 case EntityFullName:
00214 case EntityMailer:
00215 case EntityProductID:
00216 case EntityName:
00217 case EntitySortString:
00218 case EntityVersion:
00219 case EntityProfile:
00220 case EntityUID:
00221 case EntityNote:
00222 case EntityURI:
00223 default: t = ValueText; break;
00224
00225
00226 }
00227
00228 return t;
00229 }
00230
00231 TQCString
00232 VCARD::EntityTypeToParamName(EntityType e)
00233 {
00234 if ( e > EntityUnknown ) e = EntityUnknown;
00235 return paramNames[ int( e ) ];
00236 }
00237
00238 EntityType
00239 VCARD::EntityNameToEntityType(const TQCString & s)
00240 {
00241 if (s.isEmpty()) return EntityUnknown;
00242
00243 EntityType t(EntityUnknown);
00244
00245 switch (s[0]) {
00246
00247 case 'A':
00248 if (s == "ADR")
00249 t = EntityAddress;
00250 else if (s == "AGENT")
00251 t = EntityAgent;
00252 break;
00253
00254 case 'B':
00255 if (s == "BDAY")
00256 t = EntityBirthday;
00257 break;
00258
00259 case 'C':
00260 if (s == "CATEGORIES")
00261 t = EntityCategories;
00262 else if (s == "CLASS")
00263 t = EntityClass;
00264 break;
00265
00266 case 'E':
00267 if (s == "EMAIL")
00268 t = EntityEmail;
00269 break;
00270
00271 case 'F':
00272 if (s == "FN")
00273 t = EntityFullName;
00274 break;
00275
00276 case 'G':
00277 if (s == "GEO")
00278 t = EntityGeo;
00279 break;
00280
00281 case 'K':
00282 if (s == "KEY")
00283 t = EntityKey;
00284 break;
00285
00286 case 'L':
00287 if (s == "LABEL")
00288 t = EntityLabel;
00289 else if (s == "LOGO")
00290 t = EntityLogo;
00291 break;
00292
00293 case 'M':
00294 if (s == "MAILER")
00295 t = EntityMailer;
00296 break;
00297
00298 case 'N':
00299 if (s == "N")
00300 t = EntityN;
00301 else if (s == "NAME")
00302 t = EntityName;
00303 else if (s == "NICKNAME")
00304 t = EntityNickname;
00305 else if (s == "NOTE")
00306 t = EntityNote;
00307 break;
00308
00309 case 'O':
00310 if (s == "ORG")
00311 t = EntityOrganisation;
00312 break;
00313
00314 case 'P':
00315 if (s == "PHOTO")
00316 t = EntityPhoto;
00317 else if (s == "PRODID")
00318 t = EntityProductID;
00319 else if (s == "PROFILE")
00320 t = EntityProfile;
00321 break;
00322
00323 case 'R':
00324 if (s == "REV")
00325 t = EntityRevision;
00326 else if (s == "ROLE")
00327 t = EntityRole;
00328 break;
00329
00330 case 'S':
00331 if (s == "SORT-STRING")
00332 t = EntitySortString;
00333 else if (s == "SOUND")
00334 t = EntitySound;
00335 else if (s == "SOURCE")
00336 t = EntitySource;
00337 break;
00338
00339 case 'T':
00340 if (s == "TEL")
00341 t = EntityTelephone;
00342 else if (s == "TITLE")
00343 t = EntityTitle;
00344 else if (s == "TZ")
00345 t = EntityTimeZone;
00346 break;
00347
00348 case 'U':
00349 if (s == "UID")
00350 t = EntityUID;
00351 else if (s == "URL")
00352 t = EntityURL;
00353 else if (s == "URI")
00354 t = EntityURI;
00355 case 'V':
00356 if (s == "VERSION")
00357 t = EntityVersion;
00358 break;
00359
00360 case 'X':
00361 if (s.left(2) == "X-")
00362 t = EntityExtension;
00363 break;
00364
00365 default:
00366
00367 t = EntityUnknown;
00368 }
00369
00370 return t;
00371 }
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400 static char B64[] =
00401 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
00402
00403
00404 static signed char b64dec[] = {
00405 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
00406 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
00407 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
00408 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
00409 -1, -1, -1,-19, -1, -1, -1,-16, -4, -4,
00410 -4, -4, -4, -4, -4, -4, -4, -4, -1, -1,
00411 -1, 0, -1, -1, -1, 65, 65, 65, 65, 65,
00412 65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
00413 65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
00414 65, -1, -1, -1, -1, -1, -1, 71, 71, 71,
00415 71, 71, 71, 71, 71, 71, 71, 71, 71, 71,
00416 71, 71, 71, 71, 71, 71, 71, 71, 71, 71,
00417 71, 71, 71, -1, -1, -1, -1, -1, -1, -1,
00418 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
00419 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
00420 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
00421 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
00422 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
00423 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
00424 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
00425 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
00426 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
00427 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
00428 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
00429 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
00430 -1, -1, -1, -1, -1, -1, -1
00431 };
00432
00433 char *
00434 VCARD::decodeBase64(const char * s, unsigned long srcl, unsigned long & len)
00435 {
00436 register unsigned char c;
00437 register unsigned long e(0);
00438 len = 0;
00439 unsigned const char * src = (unsigned const char *)s;
00440 char * ret = new char[srcl + (srcl / 4 + 1)];
00441 register char *d = ret;
00442 while (srcl--) {
00443 c = *src++;
00444 int dec = b64dec[c];
00445 if (dec == -1) continue;
00446 if (c == '=') {
00447 switch (e++) {
00448 case 3: e = 0; break;
00449 case 2: if (*src == '=') break;
00450 default: delete [] ret; ret = 0; return 0; break;
00451 }
00452 continue;
00453 }
00454 c -= dec;
00455 if (e == 0) { *d = c << 2; ++e; continue; }
00456 switch (e) {
00457 case 1: *d |= c >> 4; *++d = c << 4; break;
00458 case 2: *d |= c >> 2; *++d = c << 6; break;
00459 case 3: *d++ |= c; e = 0; continue; break;
00460 }
00461 ++e;
00462 }
00463 len = d - (char *)ret;
00464 return ret;
00465 }
00466
00467
00468 char *
00469 VCARD::encodeBase64(const char * src, unsigned long srcl, unsigned long & destl)
00470 {
00471 register const unsigned char *s = (unsigned char *)src;
00472 register unsigned long i = ((srcl + 2) / 3) * 4;
00473 destl = i += 2 * ((i / 60) + 1);
00474 i = 0;
00475 char * ret = new char[destl];
00476 register unsigned char *d((unsigned char *)ret);
00477 while (srcl != 0) {
00478 *d++ = B64[s[0] >> 2];
00479 *d++ = B64[((s[0] << 4) + (--srcl == 0 ? 0 : s[1] >> 4)) & 0x3f];
00480 *d++ = srcl == 0 ? '=' :
00481 B64[((s[1] << 2) + (--srcl == 0 ? 0 : s[2] >> 6)) & 0x3f];
00482 *d++ = srcl == 0 ? '=' : B64[s[2] & 0x3f];
00483 if (srcl != 0) srcl--;
00484 if (++i == 15) { i = 0; *d++ = '\r'; *d++ = '\n'; }
00485 s += 3;
00486 }
00487 *d = '\r'; *++d = '\n'; *++d = '\0';
00488 return ret;
00489 }
00490