Back to index

lightning-sunbird  0.9+nobinonly
nsVCardObj.h
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 /***************************************************************************
00038 (C) Copyright 1996 Apple Computer, Inc., AT&T Corp., International             
00039 Business Machines Corporation and Siemens Rolm Communications Inc.             
00040                                                                                
00041 For purposes of this license notice, the term Licensors shall mean,            
00042 collectively, Apple Computer, Inc., AT&T Corp., International                  
00043 Business Machines Corporation and Siemens Rolm Communications Inc.             
00044 The term Licensor shall mean any of the Licensors.                             
00045                                                                                
00046 Subject to acceptance of the following conditions, permission is hereby        
00047 granted by Licensors without the need for written agreement and without        
00048 license or royalty fees, to use, copy, modify and distribute this              
00049 software for any purpose.                                                      
00050                                                                                
00051 The above copyright notice and the following four paragraphs must be           
00052 reproduced in all copies of this software and any software including           
00053 this software.                                                                 
00054                                                                                
00055 THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS AND NO LICENSOR SHALL HAVE       
00056 ANY OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR       
00057 MODIFICATIONS.                                                                 
00058                                                                                
00059 IN NO EVENT SHALL ANY LICENSOR BE LIABLE TO ANY PARTY FOR DIRECT,              
00060 INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOST PROFITS ARISING OUT         
00061 OF THE USE OF THIS SOFTWARE EVEN IF ADVISED OF THE POSSIBILITY OF SUCH         
00062 DAMAGE.                                                                        
00063                                                                                
00064 EACH LICENSOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED,       
00065 INCLUDING BUT NOT LIMITED TO ANY WARRANTY OF NONINFRINGEMENT OR THE            
00066 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR             
00067 PURPOSE.                                                                       
00068 
00069 The software is provided with RESTRICTED RIGHTS.  Use, duplication, or         
00070 disclosure by the government are subject to restrictions set forth in          
00071 DFARS 252.227-7013 or 48 CFR 52.227-19, as applicable.                         
00072 
00073 ***************************************************************************/
00074 
00075 /*
00076  
00077 The vCard/vCalendar C interface is implemented in the set 
00078 of files as follows:
00079 
00080 vcc.y, yacc source, and vcc.c, the yacc output you will use
00081 implements the core parser
00082 
00083 vobject.c implements an API that insulates the caller from
00084 the parser and changes in the vCard/vCalendar BNF
00085 
00086 port.h defines compilation environment dependent stuff
00087 
00088 vcc.h and vobject.h are header files for their .c counterparts
00089 
00090 vcaltmp.h and vcaltmp.c implement vCalendar "macro" functions
00091 which you may find useful.
00092 
00093 test.c is a standalone test driver that exercises some of
00094 the features of the APIs provided. Invoke test.exe on a
00095 VCARD/VCALENDAR input text file and you will see the pretty
00096 print output of the internal representation (this pretty print
00097 output should give you a good idea of how the internal 
00098 representation looks like -- there is one such output in the 
00099 following too). Also, a file with the .out suffix is generated 
00100 to show that the internal representation can be written back 
00101 in the original text format.
00102 
00103 For more information on this API see the readme.txt file
00104 which accompanied this distribution.
00105 
00106   Also visit:
00107 
00108     http://www.versit.com
00109     http://www.ralden.com
00110 
00111 */
00112 
00113 
00114 #ifndef __VOBJECT_H__
00115 #define __VOBJECT_H__ 1
00116 
00117 /*
00118 Unfortunately, on the Mac (and possibly other platforms) with our current, out-dated
00119 libraries (Plauger), |wchar_t| is defined incorrectly, which breaks vcards.
00120 
00121 We can't fix Plauger because it doesn't come with source. Later, when we
00122 upgrade to MSL, we can make this evil hack go away.  In the mean time,
00123 vcards are not allowed to use the (incorrectly defined) |wchar_t| type.  Instead,
00124 they will use an appropriately defined local type |vwchar_t|.
00125 */
00126 
00127 #ifdef XP_MAC
00128         typedef uint16  vwchar_t; 
00129 #else
00130         typedef wchar_t vwchar_t;
00131 #endif
00132 
00133 #include "prtypes.h"
00134 #include "nsFileSpec.h"
00135 
00136 class nsOutputFileStream;
00137 
00138 PR_BEGIN_EXTERN_C
00139 
00140 #define VC7bitProp        "7bit"
00141 #define VC8bitProp        "8bit"
00142 #define VCAAlarmProp      "aalarm"
00143 #define VCAdditionalNamesProp "addn"
00144 #define VCAdrProp       "adr"
00145 #define VCAgentProp       "agent"
00146 #define VCAIFFProp        "aiff"
00147 #define VCAOLProp       "aol"
00148 #define VCAppleLinkProp     "applelink"
00149 #define VCAttachProp      "attach"
00150 #define VCAttendeeProp      "attendee"
00151 #define VCATTMailProp     "attmail"
00152 #define VCAudioContentProp    "audiocontent"
00153 #define VCAVIProp       "avi"
00154 #define VCBase64Prop      "base64"
00155 #define VCBBSProp       "bbs"
00156 #define VCBirthDateProp     "bday"
00157 #define VCBMPProp       "bmp"
00158 #define VCBodyProp        "body"
00159 #define VCBusinessRoleProp    "role"
00160 #define VCCalProp       "vcalendar"
00161 #define VCCaptionProp     "cap"
00162 #define VCCardProp        "vcard"
00163 #define VCCarProp       "car"
00164 #define VCCategoriesProp    "categories"
00165 #define VCCellularProp      "cell"
00166 #define VCCGMProp       "cgm"
00167 #define VCCharSetProp     "cs"
00168 #define VCCIDProp       "cid"
00169 #define VCCISProp       "cis"
00170 #define VCCityProp        "l"
00171 #define VCClassProp       "class"
00172 #define VCCommentProp     "note"
00173 #define VCCompletedProp     "completed"
00174 #define VCContentIDProp     "content-id"
00175 #define VCCountryNameProp   "c"
00176 #define VCDAlarmProp      "dalarm"
00177 #define VCDataSizeProp      "datasize"
00178 #define VCDayLightProp      "daylight"
00179 #define VCDCreatedProp      "dcreated"
00180 #define VCDeliveryLabelProp     "label"
00181 #define VCDescriptionProp   "description"
00182 #define VCDIBProp       "dib"
00183 #define VCDisplayStringProp   "displaystring"
00184 #define VCDomesticProp      "dom"
00185 #define VCDTendProp       "dtend"
00186 #define VCDTstartProp     "dtstart"
00187 #define VCDueProp       "due"
00188 #define VCEmailAddressProp    "email"
00189 #define VCEncodingProp      "encoding"
00190 #define VCEndProp       "end"
00191 #define VCEventProp       "vevent"
00192 #define VCEWorldProp      "eworld"
00193 #define VCExNumProp       "exnum"
00194 #define VCExpDateProp     "exdate"
00195 #define VCExpectProp      "expect"
00196 #define VCExtAddressProp    "ext add"
00197 #define VCFamilyNameProp    "f"
00198 #define VCFaxProp       "fax"
00199 #define VCFullNameProp      "fn"
00200 #define VCGeoProp       "geo"
00201 #define VCGeoLocationProp   "geo"
00202 #define VCGIFProp       "gif"
00203 #define VCGivenNameProp     "g"
00204 #define VCGroupingProp      "grouping"
00205 #define VCHomeProp        "home"
00206 #define VCIBMMailProp     "ibmmail"
00207 #define VCInlineProp      "inline"
00208 #define VCInternationalProp   "intl"
00209 #define VCInternetProp      "internet"
00210 #define VCISDNProp        "isdn"
00211 #define VCJPEGProp        "jpeg"
00212 #define VCLanguageProp      "lang"
00213 #define VCLastModifiedProp    "last-modified"
00214 #define VCLastRevisedProp   "rev"
00215 #define VCLocationProp      "location"
00216 #define VCLogoProp        "logo"
00217 #define VCMailerProp      "mailer"
00218 #define VCMAlarmProp      "malarm"
00219 #define VCMCIMailProp     "mcimail"
00220 #define VCMessageProp     "msg"
00221 #define VCMETProp       "met"
00222 #define VCModemProp       "modem"
00223 #define VCMPEG2Prop       "mpeg2"
00224 #define VCMPEGProp        "mpeg"
00225 #define VCMSNProp       "msn"
00226 #define VCNamePrefixesProp    "npre"
00227 #define VCNameProp        "n"
00228 #define VCNameSuffixesProp    "nsuf"
00229 #define VCNoteProp        "note"
00230 #define VCOrgNameProp     "orgname"
00231 #define VCOrgProp       "org"
00232 #define VCOrgUnit2Prop      "oun2"
00233 #define VCOrgUnit3Prop      "oun3"
00234 #define VCOrgUnit4Prop      "oun4"
00235 #define VCOrgUnitProp     "oun"
00236 #define VCPagerProp       "pager"
00237 #define VCPAlarmProp      "palarm"
00238 #define VCParcelProp      "parcel"
00239 #define VCPartProp        "part"
00240 #define VCPCMProp       "pcm"
00241 #define VCPDFProp       "pdf"
00242 #define VCPGPProp       "pgp"
00243 #define VCPhotoProp       "photo"
00244 #define VCPICTProp        "pict"
00245 #define VCPMBProp       "pmb"
00246 #define VCPostalBoxProp     "box"
00247 #define VCPostalCodeProp    "pc"
00248 #define VCPostalProp      "postal"
00249 #define VCPowerShareProp    "powershare"
00250 #define VCPreferredProp     "pref"
00251 #define VCPriorityProp      "priority"
00252 #define VCProcedureNameProp   "procedurename"
00253 #define VCProdIdProp      "prodid"
00254 #define VCProdigyProp     "prodigy"
00255 #define VCPronunciationProp   "sound"
00256 #define VCPSProp        "ps"
00257 #define VCPublicKeyProp     "key"
00258 #define VCQPProp        "qp"
00259 #define VCQuickTimeProp     "qtime"
00260 #define VCQuotedPrintableProp "quoted-printable"
00261 #define VCRDateProp       "rdate"
00262 #define VCRegionProp      "r"
00263 #define VCRelatedToProp     "related-to"
00264 #define VCRepeatCountProp   "repeatcount"
00265 #define VCResourcesProp     "resources"
00266 #define VCRNumProp        "rnum"
00267 #define VCRoleProp        "role"
00268 #define VCRRuleProp       "rrule"
00269 #define VCRSVPProp        "rsvp"
00270 #define VCRunTimeProp     "runtime"
00271 #define VCSequenceProp      "sequence"
00272 #define VCSnoozeTimeProp    "snoozetime"
00273 #define VCStartProp       "start"
00274 #define VCStatusProp      "status"
00275 #define VCStreetAddressProp   "street"
00276 #define VCSubTypeProp     "subtype"
00277 #define VCSummaryProp     "summary"
00278 #define VCTelephoneProp     "tel"
00279 #define VCTIFFProp        "tiff"
00280 #define VCTimeZoneProp      "tz"
00281 #define VCTitleProp       "title"
00282 #define VCTLXProp       "tlx"
00283 #define VCTodoProp        "vtodo"
00284 #define VCTranspProp      "transp"
00285 #define VCUniqueStringProp    "uid"
00286 #define VCURLProp       "url"
00287 #define VCURLValueProp      "urlval"
00288 #define VCValueProp       "value"
00289 #define VCVersionProp     "version"
00290 #define VCVideoProp       "video"
00291 #define VCVoiceProp       "voice"
00292 #define VCWAVEProp        "wave"
00293 #define VCWMFProp       "wmf"
00294 #define VCWorkProp        "work"
00295 #define VCX400Prop        "x400"
00296 #define VCX509Prop        "x509"
00297 #define VCXRuleProp       "xrule"
00298 #define VCCooltalk        "x-mozilla-cpt"
00299 #define VCCooltalkAddress   "x-moxilla-cpadr"
00300 #define VCUseServer       "x-mozilla-cpsrv"
00301 #define VCUseHTML       "x-mozilla-html"
00302 
00303 /* return type of vObjectValueType: */
00304 #define VCVT_NOVALUE  0
00305   /* if the VObject has no value associated with it. */
00306 #define VCVT_STRINGZ  1
00307   /* if the VObject has value set by setVObjectStringZValue. */
00308 #define VCVT_USTRINGZ 2
00309   /* if the VObject has value set by setVObjectUStringZValue. */
00310 #define VCVT_UINT   3
00311   /* if the VObject has value set by setVObjectIntegerValue. */
00312 #define VCVT_ULONG    4
00313   /* if the VObject has value set by setVObjectLongValue. */
00314 #define VCVT_RAW    5
00315   /* if the VObject has value set by setVObjectAnyValue. */
00316 #define VCVT_VOBJECT  6
00317   /* if the VObject has value set by setVObjectVObjectValue. */
00318 
00319 #define NAME_OF(o)        o->id
00320 #define VALUE_TYPE(o)     o->valType
00321 #define STRINGZ_VALUE_OF(o)   o->val.strs
00322 #define USTRINGZ_VALUE_OF(o)  o->val.ustrs
00323 #define INTEGER_VALUE_OF(o)   o->val.i
00324 #define LONG_VALUE_OF(o)    o->val.l
00325 #define ANY_VALUE_OF(o)     o->val.any
00326 #define VOBJECT_VALUE_OF(o)   o->val.vobj
00327 
00328 typedef struct VObject VObject;
00329 
00330 typedef union ValueItem {
00331     const char *strs;
00332     const vwchar_t *ustrs;
00333     unsigned int i;
00334     unsigned long l;
00335     void *any;
00336     VObject *vobj;
00337     } ValueItem;
00338 
00339 struct VObject {
00340     VObject *next;
00341     const char *id;
00342     VObject *prop;
00343     unsigned short valType;
00344     ValueItem val;
00345     }; 
00346 
00347 typedef struct StrItem StrItem;
00348 
00349 struct StrItem {
00350     StrItem *next;
00351     const char *s;
00352     unsigned int refCnt;
00353     };
00354 
00355 typedef struct OFile {
00356     nsOutputFileStream *fp;
00357     char *s;
00358     int len;
00359     int limit;
00360     int alloc:1;
00361     int fail:1;
00362     } OFile;
00363 
00364 typedef struct VObjectIterator {
00365     VObject* start;
00366     VObject* next;
00367     } VObjectIterator;
00368 
00369 VObject*    newVObject(const char *id);
00370 void      deleteVObject(VObject *p);
00371 char*     dupStr(const char *s, unsigned int size);
00372 extern "C" void     deleteString(char *p);
00373 void      unUseStr(const char *s);
00374 
00375 void      setVObjectName(VObject *o, const char* id);
00376 void      setVObjectStringZValue(VObject *o, const char *s);
00377 void      setVObjectStringZValue_(VObject *o, const char *s);
00378 void      setVObjectUStringZValue(VObject *o, const vwchar_t *s);
00379 void      setVObjectUStringZValue_(VObject *o, const vwchar_t *s);
00380 void      setVObjectIntegerValue(VObject *o, unsigned int i);
00381 void      setVObjectLongValue(VObject *o, unsigned long l);
00382 void      setVObjectAnyValue(VObject *o, void *t);
00383 VObject*    setValueWithSize(VObject *prop, void *val, unsigned int size);
00384 VObject*    setValueWithSize_(VObject *prop, void *val, unsigned int size);
00385 
00386 const char* vObjectName(VObject *o);
00387 const char* vObjectStringZValue(VObject *o);
00388 const vwchar_t* vObjectUStringZValue(VObject *o);
00389 unsigned int vObjectIntegerValue(VObject *o);
00390 unsigned long vObjectLongValue(VObject *o);
00391 void* vObjectAnyValue(VObject *o);
00392 VObject* vObjectVObjectValue(VObject *o);
00393 void setVObjectVObjectValue(VObject *o, VObject *p);
00394 
00395 VObject* addVObjectProp(VObject *o, VObject *p);
00396 VObject* addProp(VObject *o, const char *id);
00397 VObject* addProp_(VObject *o, const char *id);
00398 VObject* addPropValue(VObject *o, const char *p, const char *v);
00399 VObject* addPropSizedValue_(VObject *o, const char *p, const char *v, unsigned int size);
00400 VObject* addPropSizedValue(VObject *o, const char *p, const char *v, unsigned int size);
00401 VObject* addGroup(VObject *o, const char *g);
00402 void addList(VObject **o, VObject *p);
00403 
00404 VObject* isAPropertyOf(VObject *o, const char *id);
00405 
00406 VObject* nextVObjectInList(VObject *o);
00407 void initPropIterator(VObjectIterator *i, VObject *o);
00408 int moreIteration(VObjectIterator *i);
00409 VObject* nextVObject(VObjectIterator *i);
00410 
00411 extern void printVObject(nsOutputFileStream *fp,VObject *o);
00412 void printVObject_(nsOutputFileStream *fp, VObject *o, int level);
00413 extern void writeVObject(nsOutputFileStream *fp, VObject *o);
00414 
00415 void writeVObject_(OFile *fp, VObject *o);
00416 char* writeMemVObject(char *s, int *len, VObject *o);
00417 extern "C" char* writeMemoryVObjects(char *s, int *len, VObject *list, PRBool expandSpaces);
00418 
00419 const char* lookupStr(const char *s);
00420 
00421 void cleanVObject(VObject *o);
00422 void cleanVObjects(VObject *list);
00423 
00424 const char* lookupProp(const char* str);
00425 const char* lookupProp_(const char* str);
00426 
00427 vwchar_t* fakeUnicode(const char *ps, int *bytes);
00428 int uStrLen(const vwchar_t *u);
00429 char* fakeCString(const vwchar_t *u);
00430 
00431 void printVObjectToFile(nsFileSpec *fname,VObject *o);
00432 void printVObjectsToFile(nsFileSpec *fname,VObject *list);
00433 void writeVObjectToFile(nsFileSpec *fname, VObject *o);
00434 void writeVObjectsToFile(nsFileSpec *fname, VObject *list);
00435 
00436 #define MAXPROPNAMESIZE 256
00437 #define MAXMOZPROPNAMESIZE 16
00438 
00439 PR_END_EXTERN_C
00440 
00441 #endif /* __VOBJECT_H__ */
00442 
00443