24 #include <tqcstring.h>
27 #include <VCardEnum.h>
29 using namespace VCARD;
35 VCARD::paramNames [] =
72 VCARD::paramTypesTable[] = {
109 VCARD::EntityTypeToParamType(EntityType e)
111 ParamType t(ParamUnknown);
116 case EntityAgent: t = ParamAgent;
break;
118 case EntitySound: t = ParamSound;
break;
120 case EntitySource: t = ParamSource;
break;
122 case EntityTelephone: t = ParamTel;
break;
124 case EntityEmail: t = ParamEmail;
break;
126 case EntityKey: t = ParamTextBin;
break;
128 case EntityExtension: t = ParamTextNS;
break;
131 case EntityLabel: t = ParamAddrText;
break;
134 case EntityRevision: t = ParamDate;
break;
137 case EntityLogo: t = ParamImage;
break;
139 case EntityOrganisation:
145 case EntitySortString:
147 case EntityCategories:
148 case EntityNote: t = ParamText;
break;
150 case EntityProductID:
160 default: t = ParamNone;
break;
169 VCARD::EntityTypeToValueType(EntityType e)
171 ValueType t(ValueUnknown);
176 case EntitySound: t = ValueSound;
break;
178 case EntityAgent: t = ValueAgent;
break;
180 case EntityAddress: t = ValueAddress;
break;
182 case EntityTelephone: t = ValueTel;
break;
184 case EntityKey: t = ValueTextBin;
break;
186 case EntityOrganisation: t = ValueOrg;
break;
188 case EntityN: t = ValueN;
break;
190 case EntityTimeZone: t = ValueUTC;
break;
192 case EntityClass: t = ValueClass;
break;
194 case EntityGeo: t = ValueGeo;
break;
197 case EntityURL: t = ValueURI;
break;
200 case EntityLogo: t = ValueImage;
break;
203 case EntityRevision: t = ValueDate;
break;
205 case EntityCategories:
206 case EntityNickname: t = ValueTextList;
break;
209 case EntityExtension:
215 case EntityProductID:
217 case EntitySortString:
223 default: t = ValueText;
break;
232 VCARD::EntityTypeToParamName(EntityType e)
234 if ( e > EntityUnknown ) e = EntityUnknown;
235 return paramNames[ int( e ) ];
239 VCARD::EntityNameToEntityType(
const TQCString & s)
241 if (s.isEmpty())
return EntityUnknown;
243 EntityType t(EntityUnknown);
250 else if (s ==
"AGENT")
260 if (s ==
"CATEGORIES")
261 t = EntityCategories;
262 else if (s ==
"CLASS")
289 else if (s ==
"LOGO")
301 else if (s ==
"NAME")
303 else if (s ==
"NICKNAME")
305 else if (s ==
"NOTE")
311 t = EntityOrganisation;
317 else if (s ==
"PRODID")
319 else if (s ==
"PROFILE")
326 else if (s ==
"ROLE")
331 if (s ==
"SORT-STRING")
332 t = EntitySortString;
333 else if (s ==
"SOUND")
335 else if (s ==
"SOURCE")
342 else if (s ==
"TITLE")
361 if (s.left(2) ==
"X-")
401 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
404 static signed char b64dec[] = {
405 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
406 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
407 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
408 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
409 -1, -1, -1,-19, -1, -1, -1,-16, -4, -4,
410 -4, -4, -4, -4, -4, -4, -4, -4, -1, -1,
411 -1, 0, -1, -1, -1, 65, 65, 65, 65, 65,
412 65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
413 65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
414 65, -1, -1, -1, -1, -1, -1, 71, 71, 71,
415 71, 71, 71, 71, 71, 71, 71, 71, 71, 71,
416 71, 71, 71, 71, 71, 71, 71, 71, 71, 71,
417 71, 71, 71, -1, -1, -1, -1, -1, -1, -1,
418 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
419 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
420 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
421 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
422 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
423 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
424 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
425 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
426 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
427 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
428 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
429 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
430 -1, -1, -1, -1, -1, -1, -1
434 VCARD::decodeBase64(
const char * s,
unsigned long srcl,
unsigned long & len)
439 unsigned const char * src = (
unsigned const char *)s;
440 char * ret =
new char[srcl + (srcl / 4 + 1)];
445 if (dec == -1)
continue;
448 case 3: e = 0;
break;
449 case 2:
if (*src ==
'=')
break;
450 default:
delete [] ret; ret = 0;
return 0;
break;
455 if (e == 0) { *d = c << 2; ++e;
continue; }
457 case 1: *d |= c >> 4; *++d = c << 4;
break;
458 case 2: *d |= c >> 2; *++d = c << 6;
break;
459 case 3: *d++ |= c; e = 0;
continue;
break;
463 len = d - (
char *)ret;
469 VCARD::encodeBase64(
const char * src,
unsigned long srcl,
unsigned long & destl)
471 const unsigned char *s = (
unsigned char *)src;
472 unsigned long i = ((srcl + 2) / 3) * 4;
473 destl = i += 2 * ((i / 60) + 1);
475 char * ret =
new char[destl];
476 unsigned char *d((
unsigned char *)ret);
478 *d++ = B64[s[0] >> 2];
479 *d++ = B64[((s[0] << 4) + (--srcl == 0 ? 0 : s[1] >> 4)) & 0x3f];
480 *d++ = srcl == 0 ?
'=' :
481 B64[((s[1] << 2) + (--srcl == 0 ? 0 : s[2] >> 6)) & 0x3f];
482 *d++ = srcl == 0 ?
'=' : B64[s[2] & 0x3f];
483 if (srcl != 0) srcl--;
484 if (++i == 15) { i = 0; *d++ =
'\r'; *d++ =
'\n'; }
487 *d =
'\r'; *++d =
'\n'; *++d =
'\0';