kabc Library API Documentation

Enum.cpp

00001 /*
00002     libvcard - vCard parsing library for vCard version 3.0
00003 
00004     Copyright (C) 1998 Rik Hemsley rik@kde.org
00005     
00006   Permission is hereby granted, free of charge, to any person obtaining a copy
00007   of this software and associated documentation files (the "Software"), to
00008   deal in the Software without restriction, including without limitation the
00009   rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
00010   sell copies of the Software, and to permit persons to whom the Software is
00011   furnished to do so, subject to the following conditions:
00012 
00013   The above copyright notice and this permission notice shall be included in
00014   all copies or substantial portions of the Software.
00015 
00016   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00017   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00018   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
00019   AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
00020   ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00021   WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00022 */
00023 
00024 #include <qcstring.h>
00025 #include <ctype.h>
00026 
00027 #include <VCardEnum.h>
00028 
00029 using namespace VCARD;
00030 
00031 // There are 31 possible types, not including extensions.
00032     const QCString
00033 VCARD::paramNames [] =
00034 {
00035     "NAME",
00036     "PROFILE",
00037     "SOURCE",
00038     "FN",
00039     "N",
00040     "NICKNAME",
00041     "PHOTO",
00042     "BDAY",
00043     "ADR",
00044     "LABEL",
00045     "TEL",
00046     "EMAIL",
00047     "MAILER",
00048     "TZ",
00049     "GEO",
00050     "TITLE",
00051     "ROLE",
00052     "LOGO",
00053     "AGENT",
00054     "ORG",
00055     "CATEGORIES",
00056     "NOTE",
00057     "PRODID",
00058     "REV",
00059     "SORT-STRING",
00060     "SOUND",
00061     "UID",
00062     "URL",
00063     "VERSION",
00064     "CLASS",
00065     "KEY"
00066 };
00067 
00068     const ParamType
00069 VCARD::paramTypesTable[] = {
00070     ParamNone,      // NAME
00071     ParamNone,      // PROFILE
00072     ParamSource,        // SOURCE
00073     ParamText,      // FN
00074     ParamText,      // N
00075     ParamText,      // NICKNAME
00076     ParamImage,     // PHOTO (inline/refer)
00077     ParamDate,      // BDAY ("VALUE = "date-time/date)
00078     ParamAddrText,      // ADR (adr-param/text-param)
00079     ParamAddrText,      // LABEL (adr-param/text-param)
00080     ParamTel,       // TEL
00081     ParamEmail,     // EMAIL
00082     ParamText,      // MAILER
00083     ParamNone,      // TZ
00084     ParamNone,      // GEO
00085     ParamText,      // TITLE
00086     ParamText,      // ROLE
00087     ParamImage,     // LOGO
00088     ParamAgent,     // AGENT
00089     ParamText,      // ORG
00090     ParamText,      // CATEGORIES
00091     ParamText,      // NOTE
00092     ParamNone,      // PRODID
00093     ParamDate,      // REV
00094     ParamText,      // SORT-STRING
00095     ParamSound,     // SOUND
00096     ParamNone,      // UID
00097     ParamNone,      // URL
00098     ParamNone,      // VERSION
00099     ParamNone,      // CLASS
00100     ParamTextBin,       // KEY
00101     ParamTextNS     // X
00102 };
00103 
00104     ParamType
00105 VCARD::EntityTypeToParamType(EntityType e)
00106 {
00107     ParamType t(ParamUnknown);
00108 
00109     switch (e) {
00110     
00111     //---------------------------------------------------------------// 
00112         case EntityAgent:       t = ParamAgent;     break;
00113     //---------------------------------------------------------------// 
00114         case EntitySound:       t = ParamSound;     break;
00115     //---------------------------------------------------------------// 
00116         case EntitySource:      t = ParamSource;    break;
00117     //---------------------------------------------------------------// 
00118         case EntityTelephone:       t = ParamTel;       break;
00119     //---------------------------------------------------------------// 
00120         case EntityEmail:       t = ParamEmail;     break;
00121     //---------------------------------------------------------------// 
00122         case EntityKey:         t = ParamTextBin;   break;
00123     //---------------------------------------------------------------// 
00124         case EntityExtension:       t = ParamTextNS;    break;
00125     //---------------------------------------------------------------// 
00126         case EntityAddress:
00127         case EntityLabel:       t = ParamAddrText;  break;
00128     //---------------------------------------------------------------// 
00129         case EntityBirthday:
00130         case EntityRevision:        t = ParamDate;      break;
00131     //---------------------------------------------------------------// 
00132         case EntityPhoto:
00133         case EntityLogo:        t = ParamImage;     break;
00134     //---------------------------------------------------------------// 
00135         case EntityOrganisation:
00136         case EntityTitle:
00137         case EntityRole:
00138         case EntityFullName:
00139         case EntityMailer:
00140         case EntityN:
00141         case EntitySortString:
00142         case EntityNickname:
00143         case EntityCategories:
00144         case EntityNote:        t = ParamText;      break;
00145     //---------------------------------------------------------------//     
00146         case EntityProductID:
00147         case EntityTimeZone:
00148         case EntityUID:
00149         case EntityURL:
00150         case EntityClass:
00151         case EntityGeo:
00152         case EntityName:
00153         case EntityVersion:
00154         case EntityProfile:
00155         default:            t = ParamNone;      break;
00156     //---------------------------------------------------------------// 
00157 
00158     }
00159     
00160     return t;
00161 }
00162 
00163     ValueType
00164 VCARD::EntityTypeToValueType(EntityType e)
00165 {
00166     ValueType t(ValueUnknown);
00167 
00168     switch (e) {
00169     
00170     //---------------------------------------------------------------// 
00171         case EntitySound:       t = ValueSound;     break;
00172     //---------------------------------------------------------------// 
00173         case EntityAgent:       t = ValueAgent;     break;
00174     //---------------------------------------------------------------// 
00175         case EntityAddress:     t = ValueAddress;   break;
00176     //---------------------------------------------------------------// 
00177         case EntityTelephone:       t = ValueTel;       break;
00178     //---------------------------------------------------------------// 
00179         case EntityKey:         t = ValueTextBin;   break;
00180     //---------------------------------------------------------------// 
00181         case EntityOrganisation:    t = ValueOrg;       break;
00182     //---------------------------------------------------------------// 
00183         case EntityN:           t = ValueN;     break;
00184     //---------------------------------------------------------------// 
00185         case EntityTimeZone:        t = ValueUTC;       break;
00186     //---------------------------------------------------------------//     
00187         case EntityClass:       t = ValueClass;     break;
00188     //---------------------------------------------------------------//     
00189         case EntityGeo:         t = ValueGeo;       break;
00190     //---------------------------------------------------------------//     
00191         case EntitySource:
00192         case EntityURL:         t = ValueURI;       break;
00193     //---------------------------------------------------------------//     
00194         case EntityPhoto:
00195         case EntityLogo:        t = ValueImage;     break;
00196     //---------------------------------------------------------------// 
00197         case EntityBirthday:
00198         case EntityRevision:        t = ValueDate;      break;
00199     //---------------------------------------------------------------// 
00200         case EntityCategories:
00201         case EntityNickname:        t = ValueTextList;  break;
00202     //---------------------------------------------------------------// 
00203         case EntityLabel:
00204         case EntityExtension:
00205         case EntityEmail:
00206         case EntityTitle:
00207         case EntityRole:
00208         case EntityFullName:
00209         case EntityMailer:
00210         case EntityProductID:
00211         case EntityName:
00212         case EntitySortString:
00213         case EntityVersion:
00214         case EntityProfile:
00215         case EntityUID:
00216         case EntityNote:
00217         default:            t = ValueText;      break;
00218     //---------------------------------------------------------------// 
00219 
00220     }
00221     
00222     return t;
00223 }
00224 
00225     QCString
00226 VCARD::EntityTypeToParamName(EntityType e)
00227 {
00228     if ( e > EntityUnknown ) e = EntityUnknown;
00229     return paramNames[ int( e ) ];
00230 }
00231 
00232     EntityType
00233 VCARD::EntityNameToEntityType(const QCString & s)
00234 {
00235     if (s.isEmpty()) return EntityUnknown;
00236     
00237     EntityType t(EntityUnknown);
00238     
00239     switch (s[0]) {
00240 
00241         case 'A':
00242             if (s == "ADR")
00243                 t = EntityAddress;
00244             else if (s == "AGENT")
00245                 t = EntityAgent;
00246             break;
00247 
00248         case 'B':
00249             if (s == "BDAY")
00250                 t = EntityBirthday;
00251             break;
00252 
00253         case 'C':
00254             if (s == "CATEGORIES")
00255                 t = EntityCategories;
00256             else if (s == "CLASS")
00257                 t = EntityClass;
00258             break;
00259 
00260         case 'E':
00261             if (s == "EMAIL")
00262                 t = EntityEmail;
00263             break;
00264 
00265         case 'F':
00266             if (s == "FN")
00267                 t = EntityFullName;
00268             break;
00269 
00270         case 'G':
00271             if (s == "GEO")
00272                 t = EntityGeo;
00273             break;
00274 
00275         case 'K':
00276             if (s == "KEY")
00277                 t = EntityKey;
00278             break;
00279 
00280         case 'L':
00281             if (s == "LABEL")
00282                 t = EntityLabel;
00283             else if (s == "LOGO")
00284                 t = EntityLogo;
00285             break;
00286 
00287         case 'M':
00288             if (s == "MAILER")
00289                 t = EntityMailer;
00290             break;
00291             
00292         case 'N':
00293             if (s == "N")
00294                 t = EntityN;
00295             else if (s == "NAME")
00296                 t = EntityName;
00297             else if (s == "NICKNAME")
00298                 t = EntityNickname;
00299             else if (s == "NOTE")
00300                 t = EntityNote;
00301             break;
00302 
00303         case 'O':
00304             if (s == "ORG")
00305                 t = EntityOrganisation;
00306             break;
00307 
00308         case 'P':
00309             if (s == "PHOTO")
00310                 t = EntityPhoto;
00311             else if (s == "PRODID")
00312                 t = EntityProductID;
00313             else if (s == "PROFILE")
00314                 t = EntityProfile;
00315             break;
00316         
00317         case 'R':
00318             if (s == "REV")
00319                 t = EntityRevision;
00320             else if (s == "ROLE")
00321                 t = EntityRole;
00322             break;
00323             
00324         case 'S':
00325             if (s == "SORT-STRING")
00326                 t = EntitySortString;
00327             else if (s == "SOUND")
00328                 t = EntitySound;
00329             else if (s == "SOURCE")
00330                 t = EntitySource;
00331             break;
00332 
00333         case 'T':
00334             if (s == "TEL")
00335                 t = EntityTelephone;
00336             else if (s == "TITLE")
00337                 t = EntityTitle;
00338             else if (s == "TZ")
00339                 t = EntityTimeZone;
00340             break;
00341 
00342         case 'U':
00343             if (s == "UID")
00344                 t = EntityUID;
00345             else if (s == "URL")
00346                 t = EntityURL;
00347         case 'V':
00348             if (s == "VERSION")
00349                 t = EntityVersion;
00350             break;
00351 
00352         case 'X':
00353             if (s.left(2) == "X-")
00354                 t = EntityExtension;
00355             break;
00356             
00357         default:
00358             
00359             t = EntityUnknown;
00360     }
00361     
00362     return t;
00363 }
00364 
00365 // The copyright notice below refers to the base64 codec functions used below,
00366 // which are modified from the original sources.
00367 
00368 /*
00369  * Original version Copyright 1988 by The Leland Stanford Junior University
00370  * Copyright 1998 by the University of Washington
00371  *
00372  *  Permission to use, copy, modify, and distribute this software and its
00373  * documentation for any purpose and without fee is hereby granted, provided
00374  * that the above copyright notices appear in all copies and that both the
00375  * above copyright notices and this permission notice appear in supporting
00376  * documentation, and that the name of the University of Washington or The
00377  * Leland Stanford Junior University not be used in advertising or publicity
00378  * pertaining to distribution of the software without specific, written prior
00379  * permission.  This software is made available "as is", and
00380  * THE UNIVERSITY OF WASHINGTON AND THE LELAND STANFORD JUNIOR UNIVERSITY
00381  * DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, WITH REGARD TO THIS SOFTWARE,
00382  * INCLUDING WITHOUT LIMITATION ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
00383  * FITNESS FOR A PARTICULAR PURPOSE, AND IN NO EVENT SHALL THE UNIVERSITY OF
00384  * WASHINGTON OR THE LELAND STANFORD JUNIOR UNIVERSITY BE LIABLE FOR ANY
00385  * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
00386  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
00387  * CONTRACT, TORT (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF
00388  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00389  *
00390  */
00391 
00392 static char B64[] = 
00393     "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
00394 
00395 // the mime base64 disctionary used for decoding
00396 static signed char b64dec[] = {
00397     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0
00398     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 10
00399     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 20
00400     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 30
00401     -1, -1, -1,-19, -1, -1, -1,-16, -4, -4, // 40 -19 == '+' -16 == '/'
00402     -4, -4, -4, -4, -4, -4, -4, -4, -1, -1, // 50 -4 == '0'
00403     -1,  0, -1, -1, -1, 65, 65, 65, 65, 65, // 60 0 == '=' 65 == 'A'
00404     65, 65, 65, 65, 65, 65, 65, 65, 65, 65, // 70
00405     65, 65, 65, 65, 65, 65, 65, 65, 65, 65, // 80
00406     65, -1, -1, -1, -1, -1, -1, 71, 71, 71, // 90 71 == 'a'
00407     71, 71, 71, 71, 71, 71, 71, 71, 71, 71, // 100
00408     71, 71, 71, 71, 71, 71, 71, 71, 71, 71, // 110
00409     71, 71, 71, -1, -1, -1, -1, -1, -1, -1, // 120
00410     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 130
00411     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 140
00412     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 150
00413     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 160
00414     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 170
00415     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 180
00416     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 190
00417     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 200
00418     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 210
00419     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 220
00420     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 230
00421     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 240
00422     -1, -1, -1, -1, -1, -1, -1              // 250
00423 };
00424 
00425     char *
00426 VCARD::decodeBase64(const char * s, unsigned long srcl, unsigned long & len)
00427 {
00428     register unsigned char c;
00429     register unsigned long e(0);
00430     len = 0;
00431     unsigned const char * src = (unsigned const char *)s;
00432     char * ret = new char[srcl + (srcl / 4 + 1)];
00433     register char *d = ret;
00434     while (srcl--) { // Critical loop
00435         c = *src++;
00436         int dec = b64dec[c];
00437         if (dec == -1) continue;
00438         if (c == '=') {
00439             switch (e++) {
00440                 case 3: e = 0;                              break;
00441                 case 2: if (*src == '=')                    break;
00442                 default: delete [] ret; ret = 0; return 0;  break;
00443             }
00444             continue;
00445         }
00446         c -= dec;
00447         if (e == 0) { *d = c << 2; ++e; continue; }
00448         switch (e) {
00449             case 1: *d |= c >> 4; *++d = c << 4;    break;
00450             case 2: *d |= c >> 2; *++d = c << 6;    break;
00451             case 3: *d++ |= c; e = 0; continue;     break;
00452         }
00453         ++e;
00454     }
00455     len = d - (char *)ret;
00456     return ret;
00457 }
00458 
00459 
00460     char *
00461 VCARD::encodeBase64(const char * src, unsigned long srcl, unsigned long & destl)
00462 {
00463     register const unsigned char *s = (unsigned char *)src;
00464     register unsigned long i = ((srcl + 2) / 3) * 4;
00465     destl = i += 2 * ((i / 60) + 1);
00466     i = 0;
00467     char * ret = new char[destl];
00468     register unsigned char *d((unsigned char *)ret);
00469     while (srcl != 0) { // Critical loop
00470         *d++ = B64[s[0] >> 2];
00471         *d++ = B64[((s[0] << 4) + (--srcl == 0 ? 0 : s[1] >> 4)) & 0x3f];
00472         *d++ = srcl == 0 ? '=' :
00473             B64[((s[1] << 2) + (--srcl == 0 ? 0 : s[2] >> 6)) & 0x3f];
00474         *d++ = srcl == 0 ?  '=' : B64[s[2] & 0x3f];
00475         if (srcl != 0) srcl--;
00476         if (++i == 15) { i = 0; *d++ = '\r'; *d++ = '\n'; }
00477         s += 3;
00478     }
00479     *d = '\r'; *++d = '\n'; *++d = '\0';
00480     return ret;
00481 }
00482 
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.4.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 27 22:16:07 2005 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001