• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeabc
 

tdeabc

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

tdeabc

Skip menu "tdeabc"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeabc

Skip menu "tdeabc"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeabc by doxygen 1.9.4
This website is maintained by Timothy Pearson.