summaryrefslogtreecommitdiffabout
path: root/kabc/vcard/Enum.cpp
Unidiff
Diffstat (limited to 'kabc/vcard/Enum.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/vcard/Enum.cpp482
1 files changed, 482 insertions, 0 deletions
diff --git a/kabc/vcard/Enum.cpp b/kabc/vcard/Enum.cpp
new file mode 100644
index 0000000..cc48b5a
--- a/dev/null
+++ b/kabc/vcard/Enum.cpp
@@ -0,0 +1,482 @@
1/*
2 libvcard - vCard parsing library for vCard version 3.0
3
4 Copyright (C) 1998 Rik Hemsley rik@kde.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#include <qcstring.h>
25#include <ctype.h>
26
27#include <VCardEnum.h>
28
29using namespace VCARD;
30
31// There are 31 possible types, not including extensions.
32 const QCString
33VCARD::paramNames [] =
34{
35 "NAME",
36 "PROFILE",
37 "SOURCE",
38 "FN",
39 "N",
40 "NICKNAME",
41 "PHOTO",
42 "BDAY",
43 "ADR",
44 "LABEL",
45 "TEL",
46 "EMAIL",
47 "MAILER",
48 "TZ",
49 "GEO",
50 "TITLE",
51 "ROLE",
52 "LOGO",
53 "AGENT",
54 "ORG",
55 "CATEGORIES",
56 "NOTE",
57 "PRODID",
58 "REV",
59 "SORT-STRING",
60 "SOUND",
61 "UID",
62 "URL",
63 "VERSION",
64 "CLASS",
65 "KEY"
66};
67
68 const ParamType
69VCARD::paramTypesTable[] = {
70 ParamNone, // NAME
71 ParamNone, // PROFILE
72 ParamSource, // SOURCE
73 ParamText, // FN
74 ParamText, // N
75 ParamText, // NICKNAME
76 ParamImage, // PHOTO (inline/refer)
77 ParamDate, // BDAY ("VALUE = "date-time/date)
78 ParamAddrText, // ADR (adr-param/text-param)
79 ParamAddrText, // LABEL (adr-param/text-param)
80 ParamTel, // TEL
81 ParamEmail, // EMAIL
82 ParamText, // MAILER
83 ParamNone, // TZ
84 ParamNone, // GEO
85 ParamText, // TITLE
86 ParamText, // ROLE
87 ParamImage, // LOGO
88 ParamAgent, // AGENT
89 ParamText, // ORG
90 ParamText, // CATEGORIES
91 ParamText, // NOTE
92 ParamNone, // PRODID
93 ParamDate, // REV
94 ParamText, // SORT-STRING
95 ParamSound, // SOUND
96 ParamNone, // UID
97 ParamNone, // URL
98 ParamNone, // VERSION
99 ParamNone, // CLASS
100 ParamTextBin, // KEY
101 ParamTextNS // X
102};
103
104 ParamType
105VCARD::EntityTypeToParamType(EntityType e)
106{
107 ParamType t(ParamUnknown);
108
109 switch (e) {
110
111 //---------------------------------------------------------------//
112 case EntityAgent: t = ParamAgent; break;
113 //---------------------------------------------------------------//
114 case EntitySound: t = ParamSound; break;
115 //---------------------------------------------------------------//
116 case EntitySource: t = ParamSource;break;
117 //---------------------------------------------------------------//
118 case EntityTelephone: t = ParamTel; break;
119 //---------------------------------------------------------------//
120 case EntityEmail: t = ParamEmail; break;
121 //---------------------------------------------------------------//
122 case EntityKey: t = ParamTextBin;break;
123 //---------------------------------------------------------------//
124 case EntityExtension: t = ParamTextNS;break;
125 //---------------------------------------------------------------//
126 case EntityAddress:
127 case EntityLabel: t = ParamAddrText;break;
128 //---------------------------------------------------------------//
129 case EntityBirthday:
130 case EntityRevision: t = ParamDate; break;
131 //---------------------------------------------------------------//
132 case EntityPhoto:
133 case EntityLogo: t = ParamImage; break;
134 //---------------------------------------------------------------//
135 case EntityOrganisation:
136 case EntityTitle:
137 case EntityRole:
138 case EntityFullName:
139 case EntityMailer:
140 case EntityN:
141 case EntitySortString:
142 case EntityNickname:
143 case EntityCategories:
144 case EntityNote: t = ParamText; break;
145 //---------------------------------------------------------------//
146 case EntityProductID:
147 case EntityTimeZone:
148 case EntityUID:
149 case EntityURL:
150 case EntityClass:
151 case EntityGeo:
152 case EntityName:
153 case EntityVersion:
154 case EntityProfile:
155 default: t = ParamNone; break;
156 //---------------------------------------------------------------//
157
158 }
159
160 return t;
161}
162
163 ValueType
164VCARD::EntityTypeToValueType(EntityType e)
165{
166 ValueType t(ValueUnknown);
167
168 switch (e) {
169
170 //---------------------------------------------------------------//
171 case EntitySound: t = ValueSound; break;
172 //---------------------------------------------------------------//
173 case EntityAgent: t = ValueAgent; break;
174 //---------------------------------------------------------------//
175 case EntityAddress: t = ValueAddress;break;
176 //---------------------------------------------------------------//
177 case EntityTelephone: t = ValueTel; break;
178 //---------------------------------------------------------------//
179 case EntityKey: t = ValueTextBin;break;
180 //---------------------------------------------------------------//
181 case EntityOrganisation: t = ValueOrg; break;
182 //---------------------------------------------------------------//
183 case EntityN: t = ValueN; break;
184 //---------------------------------------------------------------//
185 case EntityTimeZone: t = ValueUTC; break;
186 //---------------------------------------------------------------//
187 case EntityClass: t = ValueClass; break;
188 //---------------------------------------------------------------//
189 case EntityGeo: t = ValueGeo; break;
190 //---------------------------------------------------------------//
191 case EntitySource:
192 case EntityURL: t = ValueURI; break;
193 //---------------------------------------------------------------//
194 case EntityPhoto:
195 case EntityLogo: t = ValueImage; break;
196 //---------------------------------------------------------------//
197 case EntityBirthday:
198 case EntityRevision: t = ValueDate; break;
199 //---------------------------------------------------------------//
200 case EntityCategories:
201 case EntityNickname: t = ValueTextList;break;
202 //---------------------------------------------------------------//
203 case EntityLabel:
204 case EntityExtension:
205 case EntityEmail:
206 case EntityTitle:
207 case EntityRole:
208 case EntityFullName:
209 case EntityMailer:
210 case EntityProductID:
211 case EntityName:
212 case EntitySortString:
213 case EntityVersion:
214 case EntityProfile:
215 case EntityUID:
216 case EntityNote:
217 default: t = ValueText; break;
218 //---------------------------------------------------------------//
219
220 }
221
222 return t;
223}
224
225 QCString
226VCARD::EntityTypeToParamName(EntityType e)
227{
228 if ( e > EntityUnknown ) e = EntityUnknown;
229 return paramNames[ int( e ) ];
230}
231
232 EntityType
233VCARD::EntityNameToEntityType(const QCString & s)
234{
235 if (s.isEmpty()) return EntityUnknown;
236
237 EntityType t(EntityUnknown);
238
239 switch (s[0]) {
240
241 case 'A':
242 if (s == "ADR")
243 t = EntityAddress;
244 else if (s == "AGENT")
245 t = EntityAgent;
246 break;
247
248 case 'B':
249 if (s == "BDAY")
250 t = EntityBirthday;
251 break;
252
253 case 'C':
254 if (s == "CATEGORIES")
255 t = EntityCategories;
256 else if (s == "CLASS")
257 t = EntityClass;
258 break;
259
260 case 'E':
261 if (s == "EMAIL")
262 t = EntityEmail;
263 break;
264
265 case 'F':
266 if (s == "FN")
267 t = EntityFullName;
268 break;
269
270 case 'G':
271 if (s == "GEO")
272 t = EntityGeo;
273 break;
274
275 case 'K':
276 if (s == "KEY")
277 t = EntityKey;
278 break;
279
280 case 'L':
281 if (s == "LABEL")
282 t = EntityLabel;
283 else if (s == "LOGO")
284 t = EntityLogo;
285 break;
286
287 case 'M':
288 if (s == "MAILER")
289 t = EntityMailer;
290 break;
291
292 case 'N':
293 if (s == "N")
294 t = EntityN;
295 else if (s == "NAME")
296 t = EntityName;
297 else if (s == "NICKNAME")
298 t = EntityNickname;
299 else if (s == "NOTE")
300 t = EntityNote;
301 break;
302
303 case 'O':
304 if (s == "ORG")
305 t = EntityOrganisation;
306 break;
307
308 case 'P':
309 if (s == "PHOTO")
310 t = EntityPhoto;
311 else if (s == "PRODID")
312 t = EntityProductID;
313 else if (s == "PROFILE")
314 t = EntityProfile;
315 break;
316
317 case 'R':
318 if (s == "REV")
319 t = EntityRevision;
320 else if (s == "ROLE")
321 t = EntityRole;
322 break;
323
324 case 'S':
325 if (s == "SORT-STRING")
326 t = EntitySortString;
327 else if (s == "SOUND")
328 t = EntitySound;
329 else if (s == "SOURCE")
330 t = EntitySource;
331 break;
332
333 case 'T':
334 if (s == "TEL")
335 t = EntityTelephone;
336 else if (s == "TITLE")
337 t = EntityTitle;
338 else if (s == "TZ")
339 t = EntityTimeZone;
340 break;
341
342 case 'U':
343 if (s == "UID")
344 t = EntityUID;
345 else if (s == "URL")
346 t = EntityURL;
347 case 'V':
348 if (s == "VERSION")
349 t = EntityVersion;
350 break;
351
352 case 'X':
353 if (s.left(2) == "X-")
354 t = EntityExtension;
355 break;
356
357 default:
358
359 t = EntityUnknown;
360 }
361
362 return t;
363}
364
365// The copyright notice below refers to the base64 codec functions used below,
366// which are modified from the original sources.
367
368/*
369 * Original version Copyright 1988 by The Leland Stanford Junior University
370 * Copyright 1998 by the University of Washington
371 *
372 * Permission to use, copy, modify, and distribute this software and its
373 * documentation for any purpose and without fee is hereby granted, provided
374 * that the above copyright notices appear in all copies and that both the
375 * above copyright notices and this permission notice appear in supporting
376 * documentation, and that the name of the University of Washington or The
377 * Leland Stanford Junior University not be used in advertising or publicity
378 * pertaining to distribution of the software without specific, written prior
379 * permission. This software is made available "as is", and
380 * THE UNIVERSITY OF WASHINGTON AND THE LELAND STANFORD JUNIOR UNIVERSITY
381 * DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, WITH REGARD TO THIS SOFTWARE,
382 * INCLUDING WITHOUT LIMITATION ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
383 * FITNESS FOR A PARTICULAR PURPOSE, AND IN NO EVENT SHALL THE UNIVERSITY OF
384 * WASHINGTON OR THE LELAND STANFORD JUNIOR UNIVERSITY BE LIABLE FOR ANY
385 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
386 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
387 * CONTRACT, TORT (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF
388 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
389 *
390 */
391
392static char B64[] =
393 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
394
395// the mime base64 disctionary used for decoding
396static signed char b64dec[] = {
397 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0
398 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 10
399 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 20
400 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 30
401 -1, -1, -1,-19, -1, -1, -1,-16, -4, -4, // 40 -19 == '+' -16 == '/'
402 -4, -4, -4, -4, -4, -4, -4, -4, -1, -1, // 50 -4 == '0'
403 -1, 0, -1, -1, -1, 65, 65, 65, 65, 65, // 60 0 == '=' 65 == 'A'
404 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, // 70
405 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, // 80
406 65, -1, -1, -1, -1, -1, -1, 71, 71, 71, // 90 71 == 'a'
407 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, // 100
408 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, // 110
409 71, 71, 71, -1, -1, -1, -1, -1, -1, -1, // 120
410 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 130
411 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 140
412 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 150
413 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 160
414 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 170
415 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 180
416 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 190
417 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 200
418 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 210
419 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 220
420 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 230
421 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 240
422 -1, -1, -1, -1, -1, -1, -1 // 250
423};
424
425 char *
426VCARD::decodeBase64(const char * s, unsigned long srcl, unsigned long & len)
427{
428 register unsigned char c;
429 register unsigned long e(0);
430 len = 0;
431 unsigned const char * src = (unsigned const char *)s;
432 char * ret = new char[srcl + (srcl / 4 + 1)];
433 register char *d = ret;
434 while (srcl--) { // Critical loop
435 c = *src++;
436 int dec = b64dec[c];
437 if (dec == -1) continue;
438 if (c == '=') {
439 switch (e++) {
440 case 3: e = 0; break;
441 case 2: if (*src == '=') break;
442 default: delete [] ret; ret = 0; return 0;break;
443 }
444 continue;
445 }
446 c -= dec;
447 if (e == 0) { *d = c << 2; ++e; continue; }
448 switch (e) {
449 case 1: *d |= c >> 4; *++d = c << 4;break;
450 case 2: *d |= c >> 2; *++d = c << 6;break;
451 case 3: *d++ |= c; e = 0; continue; break;
452 }
453 ++e;
454 }
455 len = d - (char *)ret;
456 return ret;
457}
458
459
460 char *
461VCARD::encodeBase64(const char * src, unsigned long srcl, unsigned long & destl)
462{
463 register const unsigned char *s = (unsigned char *)src;
464 register unsigned long i = ((srcl + 2) / 3) * 4;
465 destl = i += 2 * ((i / 60) + 1);
466 i = 0;
467 char * ret = new char[destl];
468 register unsigned char *d((unsigned char *)ret);
469 while (srcl != 0) { // Critical loop
470 *d++ = B64[s[0] >> 2];
471 *d++ = B64[((s[0] << 4) + (--srcl == 0 ? 0 : s[1] >> 4)) & 0x3f];
472 *d++ = srcl == 0 ? '=' :
473 B64[((s[1] << 2) + (--srcl == 0 ? 0 : s[2] >> 6)) & 0x3f];
474 *d++ = srcl == 0 ?'=' : B64[s[2] & 0x3f];
475 if (srcl != 0) srcl--;
476 if (++i == 15) { i = 0; *d++ = '\r'; *d++ = '\n'; }
477 s += 3;
478 }
479 *d = '\r'; *++d = '\n'; *++d = '\0';
480 return ret;
481}
482