[Commits] .cvsignore NONE 1.1 Makefile.am NONE 1.1 README.TXT NONE 1.1 port.h NONE 1.1 vcc.y NONE 1.1 vobject.c NONE 1.1 vobject.h NONE 1.1

miras at claws-mail.org miras at claws-mail.org
Sat Dec 31 15:41:24 CET 2011


Update of /home/claws-mail/contacts/extensions/vcard/src/libversit
In directory claws-mail:/tmp/cvs-serv19121/extensions/vcard/src/libversit

Added Files:
	.cvsignore Makefile.am README.TXT port.h vcc.y vobject.c 
	vobject.h 
Log Message:
2011-12-31 [mir]	0.6.0cvs64

	* extensions/vcard/.cvsignore
	* extensions/vcard/AUTHORS
	* extensions/vcard/ChangeLog
	* extensions/vcard/Makefile.am
	* extensions/vcard/NEWS
	* extensions/vcard/README
	* extensions/vcard/TODO
	* extensions/vcard/configure.ac
	* extensions/vcard/src/.cvsignore
	* extensions/vcard/src/Makefile.am
	* extensions/vcard/src/vcard-extension.c
	* extensions/vcard/src/vcard-utils.c
	* extensions/vcard/src/vcard-utils.h
	* extensions/vcard/src/libversit/.cvsignore
	* extensions/vcard/src/libversit/Makefile.am
	* extensions/vcard/src/libversit/README.TXT
	* extensions/vcard/src/libversit/port.h
	* extensions/vcard/src/libversit/vcc.y
	* extensions/vcard/src/libversit/vobject.c
	* extensions/vcard/src/libversit/vobject.h
	    Initial upload of extension to support
	    import and export for contacts in vCard format. 

--- NEW FILE: .cvsignore ---
COPYING
INSTALL
Makefile
Makefile.in
aclocal.m4
autom4te.cache
auxdir
*.bz2
claws-contacts.desktop
claws-contacts.pc
config
config.h
config.h.in
config.log
config.status
configure
libtool
m4
org.clawsmail.ClawsContact.service
.deps
.libs
*.lo
*.la
claws-contacts
server-bindings.h
stamp-h1
src/Makefile.in

--- NEW FILE: port.h ---
/***************************************************************************
(C) Copyright 1996 Apple Computer, Inc., AT&T Corp., International             
Business Machines Corporation and Siemens Rolm Communications Inc.             
                                                                               
For purposes of this license notice, the term Licensors shall mean,            
collectively, Apple Computer, Inc., AT&T Corp., International                  
Business Machines Corporation and Siemens Rolm Communications Inc.             
The term Licensor shall mean any of the Licensors.                             
                                                                               
Subject to acceptance of the following conditions, permission is hereby        
granted by Licensors without the need for written agreement and without        
license or royalty fees, to use, copy, modify and distribute this              
software for any purpose.                                                      
                                                                               
The above copyright notice and the following four paragraphs must be           
reproduced in all copies of this software and any software including           
this software.                                                                 
                                                                               
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS AND NO LICENSOR SHALL HAVE       
ANY OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR       
MODIFICATIONS.                                                                 
                                                                               
IN NO EVENT SHALL ANY LICENSOR BE LIABLE TO ANY PARTY FOR DIRECT,              
INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOST PROFITS ARISING OUT         
OF THE USE OF THIS SOFTWARE EVEN IF ADVISED OF THE POSSIBILITY OF SUCH         
DAMAGE.                                                                        
                                                                               
EACH LICENSOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED,       
INCLUDING BUT NOT LIMITED TO ANY WARRANTY OF NONINFRINGEMENT OR THE            
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR             
PURPOSE.                                                                       

The software is provided with RESTRICTED RIGHTS.  Use, duplication, or         
disclosure by the government are subject to restrictions set forth in          
DFARS 252.227-7013 or 48 CFR 52.227-19, as applicable.                         

***************************************************************************/

#ifndef __PORT_H__
#define __PORT_H__ 1


#if defined(__CPLUSPLUS__) || defined(__cplusplus)
extern "C" {
#endif
                     
/* some of these #defines are commented out because */
/* Visual C++ sets them on the compiler command line instead */

/* #define _DEBUG */
/* #define WIN32 */
/* #define WIN16 */
/* #define _WINDOWS */
/* #define __MWERKS__ */
/* #define INCLUDEMFC */

#define	vCardClipboardFormat		"+//ISBN 1-887687-00-9::versit::PDI//vCard"
#define	vCalendarClipboardFormat	"+//ISBN 1-887687-00-9::versit::PDI//vCalendar"

/* The above strings vCardClipboardFormat and vCalendarClipboardFormat 
are globally unique IDs which can be used to generate clipboard format 
ID's as per the requirements of a specific platform. For example, in 
Windows they are used as the parameter in a call to RegisterClipboardFormat. 
For example:

  CLIPFORMAT foo = RegisterClipboardFormat(vCardClipboardFormat);

*/

#define vCardMimeType		"text/x-vCard"
#define vCalendarMimeType	"text/x-vCalendar"

#define DLLEXPORT(t) t

#ifndef FALSE
#define FALSE	0
#endif
#ifndef TRUE
#define TRUE	1
#endif

#define stricmp strcasecmp
	
#if defined(__CPLUSPLUS__) || defined(__cplusplus)
}
#endif

#endif /* __PORT_H__ */

--- NEW FILE: Makefile.am ---
# $Id: Makefile.am,v 1.1 2011-12-31 14:41:22 miras Exp $
AUTOMAKE_OPTIONS = gnu

noinst_LTLIBRARIES = libversit.la

INCLUDES = \
	   @GLIB_CFLAGS@

AM_CPPFLAGS = \
		-DG_LOG_DOMAIN=\"Claws-Contacts\"

YACCFLAGS = \
	    -d

libversit_la_SOURCES = \
		    port.h \
		    vobject.c \
		    vobject.h \
		    vcc.c \
		    vcc.h

libversit_la_LIBADD= \
   @GLIB_LIBS@

.y.c:
	$(YACC) $(YACCFLAGS) -o$@ $<
#yacc -o $@ -d $<

.l.c:
	lex -o$@ $<

CLEANFILES = \
	     vcc.c \
	     vcc.h

EXTRA_DIST = \
	README.TXT \
	vcc.y


--- NEW FILE: vobject.h ---
/***************************************************************************
(C) Copyright 1996 Apple Computer, Inc., AT&T Corp., International             
Business Machines Corporation and Siemens Rolm Communications Inc.             
                                                                               
For purposes of this license notice, the term Licensors shall mean,            
collectively, Apple Computer, Inc., AT&T Corp., International                  
Business Machines Corporation and Siemens Rolm Communications Inc.             
The term Licensor shall mean any of the Licensors.                             
                                                                               
Subject to acceptance of the following conditions, permission is hereby        
granted by Licensors without the need for written agreement and without        
license or royalty fees, to use, copy, modify and distribute this              
software for any purpose.                                                      
                                                                               
The above copyright notice and the following four paragraphs must be           
reproduced in all copies of this software and any software including           
this software.                                                                 
                                                                               
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS AND NO LICENSOR SHALL HAVE       
ANY OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR       
MODIFICATIONS.                                                                 
                                                                               
IN NO EVENT SHALL ANY LICENSOR BE LIABLE TO ANY PARTY FOR DIRECT,              
INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOST PROFITS ARISING OUT         
OF THE USE OF THIS SOFTWARE EVEN IF ADVISED OF THE POSSIBILITY OF SUCH         
DAMAGE.                                                                        
                                                                               
EACH LICENSOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED,       
INCLUDING BUT NOT LIMITED TO ANY WARRANTY OF NONINFRINGEMENT OR THE            
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR             
PURPOSE.                                                                       

The software is provided with RESTRICTED RIGHTS.  Use, duplication, or         
disclosure by the government are subject to restrictions set forth in          
DFARS 252.227-7013 or 48 CFR 52.227-19, as applicable.                         

***************************************************************************/

/*
 
The vCard/vCalendar C interface is implemented in the set 
of files as follows:

vcc.y, yacc source, and vcc.c, the yacc output you will use
implements the core parser

vobject.c implements an API that insulates the caller from
the parser and changes in the vCard/vCalendar BNF

port.h defines compilation environment dependent stuff

vcc.h and vobject.h are header files for their .c counterparts

vcaltmp.h and vcaltmp.c implement vCalendar "macro" functions
which you may find useful.

test.c is a standalone test driver that exercises some of
the features of the APIs provided. Invoke test.exe on a
VCARD/VCALENDAR input text file and you will see the pretty
print output of the internal representation (this pretty print
output should give you a good idea of how the internal 
representation looks like -- there is one such output in the 
following too). Also, a file with the .out suffix is generated 
to show that the internal representation can be written back 
in the original text format.

For more information on this API see the readme.txt file
which accompanied this distribution.

  Also visit:

		http://www.versit.com
		http://www.ralden.com

*/


#ifndef __VOBJECT_H__
#define __VOBJECT_H__ 1


#include "port.h"
#include <stdlib.h>
#include <stdio.h>

#if defined(__CPLUSPLUS__) || defined(__cplusplus)
extern "C" {
#endif


#define VC7bitProp				"7BIT"
#define VC8bitProp				"8BIT"
#define VCAAlarmProp			"AALARM"
#define VCAdditionalNamesProp	"ADDN"
#define VCAdrProp				"ADR"
#define VCAgentProp				"AGENT"
#define VCAIFFProp				"AIFF"
#define VCAOLProp				"AOL"
#define VCAppleLinkProp			"APPLELINK"
#define VCAttachProp			"ATTACH"
#define VCAttendeeProp			"ATTENDEE"
#define VCATTMailProp			"ATTMAIL"
#define VCAudioContentProp		"AUDIOCONTENT"
#define VCAVIProp				"AVI"
#define VCBase64Prop			"BASE64"
#define VCBBSProp				"BBS"
#define VCBirthDateProp			"BDAY"
#define VCBMPProp				"BMP"
#define VCBodyProp				"BODY"
#define VCBusinessRoleProp		"ROLE"
#define VCCalProp				"VCALENDAR"
#define VCCaptionProp			"CAP"
#define VCCardProp				"VCARD"
#define VCCarProp				"CAR"
#define VCCategoriesProp		"CATEGORIES"
#define VCCellularProp			"CELL"
#define VCCGMProp				"CGM"
#define VCCharSetProp			"CS"
#define VCCIDProp				"CID"
#define VCCISProp				"CIS"
#define VCCityProp				"L"
#define VCClassProp				"CLASS"
#define VCCommentProp			"NOTE"
#define VCCompletedProp			"COMPLETED"
#define VCContentIDProp			"CONTENT-ID"
#define VCCountryNameProp		"C"
#define VCDAlarmProp			"DALARM"
#define VCDataSizeProp			"DATASIZE"
#define VCDayLightProp			"DAYLIGHT"
#define VCDCreatedProp			"DCREATED"
#define VCDeliveryLabelProp     "LABEL"
#define VCDescriptionProp		"DESCRIPTION"
#define VCDIBProp				"DIB"
#define VCDisplayStringProp		"DISPLAYSTRING"
#define VCDomesticProp			"DOM"
#define VCDTendProp				"DTEND"
#define VCDTstartProp			"DTSTART"
#define VCDueProp				"DUE"
#define VCEmailAddressProp		"EMAIL"
#define VCEncodingProp			"ENCODING"
#define VCEndProp				"END"
#define VCEventProp				"VEVENT"
#define VCEWorldProp			"EWORLD"
#define VCExNumProp				"EXNUM"
#define VCExpDateProp			"EXDATE"
#define VCExpectProp			"EXPECT"
#define VCExtAddressProp		"EXT ADD"
#define VCFamilyNameProp		"F"
#define VCFaxProp				"FAX"
#define VCFullNameProp			"FN"
#define VCGeoProp				"GEO"
#define VCGeoLocationProp		"GEO"
#define VCGIFProp				"GIF"
#define VCGivenNameProp			"G"
#define VCGroupingProp			"Grouping"
#define VCHomeProp				"HOME"
#define VCIBMMailProp			"IBMMail"
#define VCInlineProp			"INLINE"
#define VCInternationalProp		"INTL"
#define VCInternetProp			"INTERNET"
#define VCISDNProp				"ISDN"
#define VCJPEGProp				"JPEG"
#define VCLanguageProp			"LANG"
#define VCLastModifiedProp		"LAST-MODIFIED"
#define VCLastRevisedProp		"REV"
#define VCLocationProp			"LOCATION"
#define VCLogoProp				"LOGO"
#define VCMailerProp			"MAILER"
#define VCMAlarmProp			"MALARM"
#define VCMCIMailProp			"MCIMAIL"
#define VCMessageProp			"MSG"
#define VCMETProp				"MET"
#define VCModemProp				"MODEM"
#define VCMPEG2Prop				"MPEG2"
#define VCMPEGProp				"MPEG"
#define VCMSNProp				"MSN"
#define VCNamePrefixesProp		"NPRE"
#define VCNameProp				"N"
#define VCNameSuffixesProp		"NSUF"
#define VCNoteProp				"NOTE"
#define VCOrgNameProp			"ORGNAME"
#define VCOrgProp				"ORG"
#define VCOrgUnit2Prop			"OUN2"
#define VCOrgUnit3Prop			"OUN3"
#define VCOrgUnit4Prop			"OUN4"
#define VCOrgUnitProp			"OUN"
#define VCPagerProp				"PAGER"
#define VCPAlarmProp			"PALARM"
#define VCParcelProp			"PARCEL"
#define VCPartProp				"PART"
#define VCPCMProp				"PCM"
#define VCPDFProp				"PDF"
#define VCPGPProp				"PGP"
#define VCPhotoProp				"PHOTO"
#define VCPICTProp				"PICT"
#define VCPMBProp				"PMB"
#define VCPostalBoxProp			"BOX"
#define VCPostalCodeProp		"PC"
#define VCPostalProp			"POSTAL"
#define VCPowerShareProp		"POWERSHARE"
#define VCPreferredProp			"PREF"
#define VCPriorityProp			"PRIORITY"
#define VCProcedureNameProp		"PROCEDURENAME"
#define VCProdIdProp			"PRODID"
#define VCProdigyProp			"PRODIGY"
#define VCPronunciationProp		"SOUND"
#define VCPSProp				"PS"
#define VCPublicKeyProp			"KEY"
#define VCQPProp				"QP"
#define VCQuickTimeProp			"QTIME"
#define VCQuotedPrintableProp	"QUOTED-PRINTABLE"
#define VCRDateProp				"RDATE"
#define VCRegionProp			"R"
#define VCRelatedToProp			"RELATED-TO"
#define VCRepeatCountProp		"REPEATCOUNT"
#define VCResourcesProp			"RESOURCES"
#define VCRNumProp				"RNUM"
#define VCRoleProp				"ROLE"
#define VCRRuleProp				"RRULE"
#define VCRSVPProp				"RSVP"
#define VCRunTimeProp			"RUNTIME"
#define VCSequenceProp			"SEQUENCE"
#define VCSnoozeTimeProp		"SNOOZETIME"
#define VCStartProp				"START"
#define VCStatusProp			"STATUS"
#define VCStreetAddressProp		"STREET"
#define VCSubTypeProp			"SUBTYPE"
#define VCSummaryProp			"SUMMARY"
#define VCTelephoneProp			"TEL"
#define VCTIFFProp				"TIFF"
#define VCTimeZoneProp			"TZ"
#define VCTitleProp				"TITLE"
#define VCTLXProp				"TLX"
#define VCTodoProp				"VTODO"
#define VCTranspProp			"TRANSP"
#define VCUniqueStringProp		"UID"
#define VCURLProp				"URL"
#define VCURLValueProp			"URLVAL"
#define VCValueProp				"VALUE"
#define VCVersionProp			"VERSION"
#define VCVideoProp				"VIDEO"
#define VCVoiceProp				"VOICE"
#define VCWAVEProp				"WAVE"
#define VCWMFProp				"WMF"
#define VCWorkProp				"WORK"
#define VCX400Prop				"X400"
#define VCX509Prop				"X509"
#define VCXRuleProp				"XRULE"

/* Extensions */

#define XPilotIdProp                            "X-PILOTID"
#define XPilotStatusProp                        "X-PILOTSTAT"
#define XPilotNoTimeProp                        "X-PILOT-NOTIME"

typedef struct VObject VObject;

typedef struct VObjectIterator {
    VObject* start;
    VObject* next;
    } VObjectIterator;

extern DLLEXPORT(VObject*) newVObject(const char *id);
extern DLLEXPORT(void) deleteVObject(VObject *p);
extern DLLEXPORT(char*) dupStr(const char *s, unsigned int size);
extern DLLEXPORT(void) deleteStr(const char *p);
extern DLLEXPORT(void) unUseStr(const char *s);

extern DLLEXPORT(void) setVObjectName(VObject *o, const char* id);
extern DLLEXPORT(void) setVObjectStringZValue(VObject *o, const char *s);
extern DLLEXPORT(void) setVObjectStringZValue_(VObject *o, const char *s);
extern DLLEXPORT(void) setVObjectUStringZValue(VObject *o, const wchar_t *s);
extern DLLEXPORT(void) setVObjectUStringZValue_(VObject *o, const wchar_t *s);
extern DLLEXPORT(void) setVObjectIntegerValue(VObject *o, unsigned int i);
extern DLLEXPORT(void) setVObjectLongValue(VObject *o, unsigned long l);
extern DLLEXPORT(void) setVObjectAnyValue(VObject *o, void *t);
extern DLLEXPORT(VObject*) setValueWithSize(VObject *prop, void *val, unsigned int size);
extern DLLEXPORT(VObject*) setValueWithSize_(VObject *prop, void *val, unsigned int size);

extern DLLEXPORT(const char*) vObjectName(VObject *o);
extern DLLEXPORT(const char*) vObjectStringZValue(VObject *o);
extern DLLEXPORT(const wchar_t*) vObjectUStringZValue(VObject *o);
extern DLLEXPORT(unsigned int) vObjectIntegerValue(VObject *o);
extern DLLEXPORT(unsigned long) vObjectLongValue(VObject *o);
extern DLLEXPORT(void*) vObjectAnyValue(VObject *o);
extern DLLEXPORT(VObject*) vObjectVObjectValue(VObject *o);
extern DLLEXPORT(void) setVObjectVObjectValue(VObject *o, VObject *p);

extern DLLEXPORT(VObject*) addVObjectProp(VObject *o, VObject *p);
extern DLLEXPORT(VObject*) addProp(VObject *o, const char *id);
extern DLLEXPORT(VObject*) addProp_(VObject *o, const char *id);
extern DLLEXPORT(VObject*) addPropValue(VObject *o, const char *p, const char *v);
extern DLLEXPORT(VObject*) addPropSizedValue_(VObject *o, const char *p, const char *v, unsigned int size);
extern DLLEXPORT(VObject*) addPropSizedValue(VObject *o, const char *p, const char *v, unsigned int size);
extern DLLEXPORT(VObject*) addGroup(VObject *o, const char *g);
extern DLLEXPORT(void) addList(VObject **o, VObject *p);

extern DLLEXPORT(VObject*) isAPropertyOf(VObject *o, const char *id);

extern DLLEXPORT(VObject*) nextVObjectInList(VObject *o);
extern DLLEXPORT(void) initPropIterator(VObjectIterator *i, VObject *o);
extern DLLEXPORT(int) moreIteration(VObjectIterator *i);
extern DLLEXPORT(VObject*) nextVObject(VObjectIterator *i);

extern DLLEXPORT(char*) writeMemVObject(char *s, int *len, VObject *o);
extern DLLEXPORT(char*) writeMemVObjects(char *s, int *len, VObject *list);

extern DLLEXPORT(const char*) lookupStr(const char *s);
extern DLLEXPORT(void) cleanStrTbl();

extern DLLEXPORT(void) cleanVObject(VObject *o);
extern DLLEXPORT(void) cleanVObjects(VObject *list);

extern DLLEXPORT(const char*) lookupProp(const char* str);
extern DLLEXPORT(const char*) lookupProp_(const char* str);

extern DLLEXPORT(wchar_t*) fakeUnicode(const char *ps, int *bytes);
extern DLLEXPORT(int) uStrLen(const wchar_t *u);
extern DLLEXPORT(char*) fakeCString(const wchar_t *u);

extern DLLEXPORT(void) printVObjectToFile(char *fname,VObject *o);
extern DLLEXPORT(void) printVObjectsToFile(char *fname,VObject *list);
extern DLLEXPORT(void) writeVObjectToFile(char *fname, VObject *o);
extern DLLEXPORT(void) writeVObjectsToFile(char *fname, VObject *list);

extern DLLEXPORT(int) vObjectValueType(VObject *o);

/* return type of vObjectValueType: */
#define VCVT_NOVALUE	0
	/* if the VObject has no value associated with it. */
#define VCVT_STRINGZ	1
	/* if the VObject has value set by setVObjectStringZValue. */
#define VCVT_USTRINGZ	2
	/* if the VObject has value set by setVObjectUStringZValue. */
#define VCVT_UINT		3
	/* if the VObject has value set by setVObjectIntegerValue. */
#define VCVT_ULONG		4
	/* if the VObject has value set by setVObjectLongValue. */
#define VCVT_RAW		5
	/* if the VObject has value set by setVObjectAnyValue. */
#define VCVT_VOBJECT	6
	/* if the VObject has value set by setVObjectVObjectValue. */

extern const char** fieldedProp;

/* NOTE regarding printVObject and writeVObject

The functions below are not exported from the DLL because they
take a FILE* as a parameter, which cannot be passed across a DLL 
interface (at least that is my experience). Instead you can use
their companion functions which take file names or pointers
to memory. However, if you are linking this code into 
your build directly then you may find them a more convenient API
and you can go ahead and use them. If you try to use them with 
the DLL LIB you will get a link error.
*/
extern void printVObject(FILE *fp,VObject *o);
extern void writeVObject(FILE *fp, VObject *o);

/* Forgotten functions added by Michael Rasmussen <mir at datanom.net> */
DLLEXPORT(VObject*) Parse_MIME(const char *input, unsigned long len);
VObject* Parse_MIME_FromFile(FILE *file);
DLLEXPORT(VObject*) Parse_MIME_FromFileName(char *fname);

typedef void (* MimeErrorHandler)(char *, void *);
DLLEXPORT(void) registerMimeErrorHandler(MimeErrorHandler me, void* data);

#if defined(__CPLUSPLUS__) || defined(__cplusplus)
}
#endif

#endif /* __VOBJECT_H__ */



--- NEW FILE: vcc.y ---
%{

/***************************************************************************
(C) Copyright 1996 Apple Computer, Inc., AT&T Corp., International
Business Machines Corporation and Siemens Rolm Communications Inc.

For purposes of this license notice, the term Licensors shall mean,
collectively, Apple Computer, Inc., AT&T Corp., International
Business Machines Corporation and Siemens Rolm Communications Inc.
The term Licensor shall mean any of the Licensors.

Subject to acceptance of the following conditions, permission is hereby
granted by Licensors without the need for written agreement and without
license or royalty fees, to use, copy, modify and distribute this
software for any purpose.

The above copyright notice and the following four paragraphs must be
reproduced in all copies of this software and any software including
this software.
[...1263 lines suppressed...]
	user_data = data;
    }

static void mime_error(char *s)
    {
    char msg[256];
    if (mimeErrorHandler) {
	sprintf(msg,"%s at line %d", s, mime_lineNum);
	mimeErrorHandler(msg, user_data);
	}
    }

static void mime_error_(char *s)
    {
    if (mimeErrorHandler) {
	mimeErrorHandler(s, user_data);
	}
    }



--- NEW FILE: README.TXT ---
NOTE: If you used the earlier APIs released by Versit
then you will want to look at the document "migrate.doc"
included with this package. It contains a discussion of
the differences between the old API and this one.

----------------------------------------------------------------

The vCard/vCalendar C interface is implemented in the set 
of files as follows:

vcc.y, yacc source, and vcc.c, the yacc output you will use
implements the core parser

vobject.c implements an API that insulates the caller from
the parser and changes in the vCard/vCalendar BNF

port.h defines compilation environment dependent stuff

vcc.h and vobject.h are header files for their .c counterparts

vcaltmp.h and vcaltmp.c implement vCalendar "macro" functions
which you may find useful.

test.c is a standalone test driver that exercises some of
the features of the APIs provided. Invoke test.exe on a
VCARD/VCALENDAR input text file and you will see the pretty
print output of the internal representation (this pretty print
output should give you a good idea of how the internal 
representation looks like -- there is one such output in the 
following too). Also, a file with the .out suffix is generated 
to show that the internal representation can be written back 
in the original text format.

-----------------------------------------------------------------
			
			  
				VObject for VCard/VCalendar

Table of Contents
=================
1. VObject
2. Internal Representations of VCard/VCalendar
3. Iterating Through VObject's Properties or Values
4. Pretty Printing a VObject Tree
5. Building A VObject Representation of A VCard/VCalendar
6. Converting A VObject Representation Into Its Textual Representation
7. Miscellaneous Notes On VObject APIs usages
8. Brief descriptions of each APIs
9. Additional Programming Notes.

This document is mainly about the VObject and its APIs. The main
use of a VObject is to represent a VCard or a VCalendar inside
a program. However, its use is not limited to aforemention as it
can represent an arbitrary information that makes up of a tree or
forest of properties/values.

1. VObject
   =======
A VObject can have a name (id) and a list of associated properties and
a value. Each property is itself a VObject.

2. Internal Representations of VCard/VCalendar
   ===========================================
A list of VCard or a VCalendar is represented by a list of VObjects.
The name (id) of the VObjects in the list is either VCCardProp or
VCCalProp. Each of these VObjects can have a list of properties.
Since a property is represented as a VObject, each of these properties
can have a name, a list of properties, and a value.

For example, the input file "vobject.vcf":
	
BEGIN:VCARD
N:Alden;Roland
FN:Roland H. Alden
ORG:AT&T;Versit Project Office
TITLE:Consultant
EMAIL;WORK;PREF;INTERNET:sf!rincon!ralden at alden.attmail.com
EMAIL;INTERNET:ralden at sfgate.com
EMAIL;MCIMail:242-2200
LABEL;DOM;POSTAL;PARCEL;HOME;WORK;QUOTED-PRINTABLE:Roland H. Alden=0A=
Suite 2208=0A=
One Pine Street=0A=
San Francisco, CA 94111
LABEL;POSTAL;PARCEL;HOME;WORK;QUOTED-PRINTABLE:Roland H. Alden=0A=
Suite 2208=0A=
One Pine Street=0A=
San Francisco, CA 94111=0A=
U.S.A.
TEL;WORK;PREF;MSG:+1 415 296 9106
TEL;WORK;FAX:+1 415 296 9016
TEL;MSG;CELL:+1 415 608 5981
ADR:;Suite 2208;One Pine Street;San Francisco;CA;94111;U.S.A.
SOUND:ROW-LAND H ALL-DIN
LOGO;GIF;BASE64:
    R0lGODdhpgBOAMQAAP///+/v797e3s7Ozr29va2trZycnIyMjHt7e2NjY1JSUkJC
    QjExMSEhIRAQEO///87v9973/73n95zW71K13jGl1nvG50Kt3iGc1gCMzq3e94zO
    7xCU1nO952O15wAAACwAAAAApgBOAAAF/yAgjmRpnmiqrmzrvnAsz3Rt33iu73zv
    /8CgcEj8QTaeywWTyWCUno2kSK0KI5tLc8vtNi+WiHVMlj0mFK96nalsxOW4fPSw
    cNj4tQc+7xcjGh4WExJTJYUTFkp3eU0eEH6RkpOUlTARhRoWm5ydFpCWoS0QEqAu
    ARKaHRcVjV0borEoFl0cSre4Sq67FA+yvwAeTU8XHZ7HmxS6u2wVfMCVpAE3pJoW
    ylrMptDcOqSF4OHg3eQ5pInInb7lcc86mNbLzBXsZbRfUOn6ucyNHvVWJHCpQFDf
    MWwEEzLqx2YCQCqF3OnItClJNmYcJD7cSAKTuI/gtnEcOQKkyVIk6/+ds5CkFcMM
    61LiENikwi1jBnNyuvUSjwWZOS5uIZarqNFcNl32XMMB6I06GgoJ+bZp1ZKeDl8E
    +MC1K1cBIhZ4HUu2LAsCZdOWRQDt20lxIlccSHsgrNq7Xc/ixcsWmNu34WKyYJCW
    gQjCe9XqTZy2L4pv04gg2sSKSc8OLgTcBSuWsdkVaD2TdXyiQxebFyjo1Gnx6tJm
    LuaqrdtZtNfFtruSNmF5IKujwIsmJbjwtRqNJhrcNVw79wcRAgogmE4ArIjQzj/s
    JvHAGCFDQR4UqigPK4sBe62XwO51OwADiMcqUG+iOdcFAL+hW20BfAoEexlwAnu6
    mZDAXQ1EVh//WfhxJB5gIbHgwFgOTOiVAgOuVQKAfKFg3weGwSBYFZMp4hpDGKyA
    3lgJKECWgiMQyBVpW+0V4oJjNfhCNkR1IgWEb21QlRK9GdfFCgeOZYBsXgm4noYj
    GEBhAQHYh0J8XenoQnFGdrkUciJY6FUAK15ogozakcBhliKsyZWHDMZQ0wWC/Aim
    DB6h01KRr/lXQgFxAqDcWDACgCZpUnrVQJtjwTnWjS6MWAYqqfDnSaEkJOlVXQBo
    2pWTMUJ53WgAuPncCR9q6VQMAYjZlXWJmknCoSUM2p4BC+SaKwG88hoZlvfFMM4f
    hQh5TXkv+RklWYtC91mopJIAKFkJlDAW/wF25ShnLbeo5gmQ+1FGkJdrKCuCi2OR
    BuwHBcwqKgABrMtVAgpem61XkLbAJ7n8uiIpvGVhO4KpH1QLbbpqLheZvQCkGoNL
    thSzSTg2UGVBBzbtaxwKsYrmgLvRAlCmWgwMAADD66rKAgR3XlGspcdkZYK8ibU7
    asgEl+XAyB8I7PCqMWiWncGGimpfAgO4ypXSPpOVLwsRCDJxRD2AoyeRRv5kApO5
    fXwzwvfOKLKtaTWtbQxccmGLTZy8xYlVSvXbhbk0M2YzrYfJJ0K8m+V9NgxpyC04
    UycI/aiuiH9Y8NftDUwWp1Wm5UABnAUKwwRsPFGBt4Oc9PZvGvNLwf8JOZt8Arpe
    eY23yDovwIDiBX74NAsPVLDJj3Hh4JEExsKcjrlKf9DsCVx3ZfLqAKBuG1s/A90C
    z2KjYHjjyPOdG1spz6BBUr+BcUxUb1nDCTa/VZD2Uv+YkLPAKJC9dNEh7628WgqI
    ybzlaA+ufxMa6bxC6ciLUQLcx5UGIAAsAkDA6wQkOxrcY39yo4cQMNWCAPTKV1R4
    wPkgaBxzOc8FtMiF1NoGoXBRJjgoPApmPsjCFlbMdzCM4TFy50IXxI2DPcHAv2rY
    gghsEIeu8CAPW6ABIPYEFkOsAeaMyIz0JfGJUExBBGRIRX0IMYovWCIT1eBELNpA
    i1vcgta8iANPCIQOghzQABl30J0tXqBla4wjFLFQxZzAUY42CIAd5OYBCuKxB2c4
    I0b28EcrQKADgmSKB9RYyDhA4BqCxIBqrtjIMTwoFeCjYSU3KZMQAAA7

BEGIN:VCALENDAR
DCREATED:19960523T100522
PRODID:-//Alden Roland/Hand Crafted In North Carolina//NONSGML Made By Hand//EN
VERSION:0.3
BEGIN:VEVENT
START:19960523T120000
END:19960523T130000
SUBTYPE:PHONE CALL
SUMMARY:VERSIT PDI PR Teleconference/Interview
DESCRIPTION:VERSIT PDI PR Teleconference/Interview With Tom Streeter and Alden Roland
END:VEVENT
BEGIN:VEVENT
START:19960523T113000
END:19960523T115500
SUBTYPE:LUNCH
SUMMARY:Eat in the cafeteria today
END:VEVENT
END:VCALENDAR

END:VCARD


will conceptually be be represented as
    vcard
	VCNameProp
	    VCFamilyNameProp=Alden
	    VCGivenNameProp=Roland
	VCFullNameProp=Roland H.Alden
	....
	
note that
    EMAIL;WORK;PREF;INTERNET:sf!rincon!ralden at alden.attmail.com
will be represented as:
	VCEmailAddress=sf!rincon!ralden at alden.attmail.com
	    VCWork
	    VCPreferred
	    VCInternet
where the lower level properties are properties of the property
VCEmailAddress.

Groupings are flattened out in the VObject representation such
that:
	a.b:blah
	a.c:blahblah
are represented as:
	b=blah
	    VCGrouping=a
	c=blahblah
	    VCGrouping=a
i.e. one can read the above as:
	 the property "b" has value "blah" and property "VCGrouping"
		with the value "a".
	 the property "c" has value "blahblah" and property "VCGrouping"
		with the value "a".
likewise, multi-level groupings are flatten similarly. e.g.
	a.b.c:blah
	a.b.e:blahblah
-->
	c=blah
	    VCGrouping=b
		VCGrouping=a
	e=blahblah
	    VCGrouping=b
		VCGrouping=a
which read:
	 the property "c" has value "blah" and property "VCGrouping"
		with the value "b" which has property "VCGrouping"
		with value "a".
	 the property "e" has value "blahblah" and property "VCGrouping"
		with the value "b" which has property "VCGrouping"
		with value "a".

3. Iterating Through VObject's Properties or Values
   ================================================
The following is a skeletal form of iterating through
all properties of a vobject, o:

    // assume the object of interest, o, is of type VObject
    VObjectIterator i;
    initPropIterator(&i,o);
    while (moreIteration(&i)) {
	VObject *each = nextVObject(&i);
	// ... do something with "each" property 
	}

Use the API vObjectName() to access a VObject's name.
Use the API vObjectValueType() to determine if a VObject has
	a value. For VCard/VCalendar application, you
	should not need this function as practically
	all values are either of type VCVT_USTRINGZ or
	VCVT_RAW (i.e set by setVObjectUStringZValue and
	setVObjectAnyValue APIs respectively), and the
	value returned by calls to vObjectUStringZValue
	and vObjectAnyValue are 0 if a VObject has no
	value. (There is a minor exception where VObject with
	VCDataSizeProp has value that is set by
	setVObjectLongValue).
Use the APIs vObject???Value() to access a VObject's value.
	where ??? is the expected type.
Use the APIs setvObject???Value() to set or modify a VObject's value.
	where ??? is the expected type.
Use the API isAPropertyOf() to query if a name match the name of
	a property of a VObject. Since isAPropertyOf() return
	the matching property, we can use that to retrieve
	a property and subsequently the value of the property.

4. Pretty Printing a VObject Tree
   ==============================
VObject tree can be pretty printed with the printVObject() function.
The output of pretty printing a VObject representation of the input
test file "vobject.vcf" is shown below. Note that the indentation
indicates the tree hirerarchy where the immediate children nodes
of a parent node is all at the same indentation level and the
immediate children nodes are the immediate properties of the
associated parent nodes.  In the following, {N,FN,ORG,TITLE,...}
are immediate properties of VCARD. {F and G} are properties of N
with value {"Alden" and "Roland"} respectively; FN has no property
but has the value "Roland H. Alden"; EMAIL has value and
the properties WORK, PREF, and INTERNET.


VCARD
    N
        F="Alden"
        G="Roland"
    FN="Roland H. Alden"
    ORG
        ORGNAME="AT&T"
        OUN="Versit Project Office"
    TITLE="Consultant"
    EMAIL="sf!rincon!ralden at alden.attmail.com"
        WORK
        PREF
        INTERNET
    EMAIL="ralden at sfgate.com"
        INTERNET
    EMAIL="242-2200"
        MCIMail
    LABEL="Roland H. Alden
            Suite 2208
            One Pine Street
            San Francisco, CA 94111"
        DOM
        POSTAL
        PARCEL
        HOME
        WORK
        QP
    LABEL="Roland H. Alden
            Suite 2208
            One Pine Street
            San Francisco, CA 94111
            U.S.A."
        POSTAL
        PARCEL
        HOME
        WORK
        QP
    TEL="+1 415 296 9106"
        WORK
        PREF
        MSG
    TEL="+1 415 296 9016"
        WORK
        FAX
    TEL="+1 415 608 5981"
        MSG
        CELL
    ADR
        EXT ADD="Suite 2208"
        STREET="One Pine Street"
        L="San Francisco"
        R="CA"
        PC="94111"
        C="U.S.A."
    SOUND="ROW-LAND H ALL-DIN"
    LOGO=[raw data]
        GIF
        BASE64
        DataSize=1482
VCALENDAR
    DCREATED="19960523T100522"
    PRODID="-//Alden Roland/Hand Crafted In North Carolina//NONSGML Made By Hand//EN"
    VERSION="0.3"
    VEVENT
        START="19960523T120000"
        END="19960523T130000"
        SUBTYPE="PHONE CALL"
        SUMMARY="VERSIT PDI PR Teleconference/Interview"
        DESCRIPTION="VERSIT PDI PR Teleconference/Interview With Tom Streeter and Alden Roland"
    VEVENT
        START="19960523T113000"
        END="19960523T115500"
        SUBTYPE="LUNCH"
        SUMMARY="Eat in the cafeteria today"

5. Building A VObject Representation of A VCard/VCalendar
   ======================================================
The parser in vcc.y converts an input file with one or more
VCard/VCalendar that is in their textual representation
into their corresponding VObject representation.

VObject representation of a VCard/VCalendar can also be built
directly with calls to the VObject building APIs. e.g.

	VObject *prop;
	VObject *vcard = newVObject(VCCardProp);
	prop = addProp(vcard,VCNameProp);
		addPropValue(prop,VCFamilyNameProp,"Alden");
		addPropValue(prop,VCGivenNameProp,"Roland");
	addPropValue(vcard,VCFullNameProp,"Roland H. Alden");
	....

6. Converting A VObject Representation Into Its Textual Representation
   ===================================================================
The VObject representation can be converted back to its textual
representation via the call to writeVObject() or writeMemVObject()
API. e.g.
   a. to write to a file:
	// assume vcard is of type VObject
	FILE *fp = fopen("alden.vcf","w");
	writeVObject(fp,vcard);
   a. to write to memory, and let the API allocate the required memory.
	char* clipboard = writeVObject(0,0,vcard);
	... do something to clipboard
	free(clipboard);
   b. to write to a user allocated buffer:
	char clipboard[16384];
	int len = 16384;
	char *buf  = writeVObject(clipboard,&len,vcard);
	... buf will be equal to clipboard if the write
	is successful otherwise 0.

In the case of writing to memory, the memory buffer can be either
allocated by the API or the user. If the user allocate the
memory for the buffer, then the length of the buffer needs to be
communicated to the API via a variable. The variable passed as
the length argument will be overwritten with the actual size
of the text output. A 0 return value from writeMemVObject()
indicates an error which could be caused by overflowing the
size of the buffer or lack of heap memory.

7. Miscellaneous Notes On VObject APIs usages
   ==========================================
a. vcc.h -- contains basic interfaces to the parser:
    VObject* Parse_MIME(const char *input, unsigned long len);
    VObject* Parse_MIME_FromFile(FILE *file);
	-- both of this return a null-terminated list of
	   VObject that is either a VCARD or VCALENDAR.
	   To iterate through this list, do
		VObject *t, *v;
		v = Parse_Mime_FromFile(fp);
		while (v) {
		    // ... do something to v.
		    t = v;
		    v = nextVObjectInList(v);
		    cleanVObject(t);
		    }
	    note that call to cleanVObject will release
	    resource used to represent the VObject.

b. vobject.h -- contains basic interfaces to the VObject APIs.
	see the header for more details.
	The structure of VObject is purposely (hiddened) not exposed
	to the user. Every access has to be done via
	the APIs. This way, if we need to change the
	structure or implementation, the client need not
	recompile as long as the interfaces remain the
	same.

c. values of a property is determined by the property definition
	itself. The vobject APIs does not attempt to enforce
	any of such definition. It is the consumer responsibility
	to know what value is expected from a property. e.g
	most properties have unicode string value, so to access
	the value of these type of properties, you will use
	the vObjectUStringZValue() to read the value and
	setVObjectUStringZValue() to set or modify the value.
	Refer to the VCard and VCalendar specifications for
	the definition of each property.

d. properties name (id) are case incensitive.

8. Brief descriptions of each APIs
   ===============================
   * the predefined properties' names (id) are listed under vobject.h
	each is of the form VC*Prop. e.g.
		#define VC7bitProp		"7BIT"
		#define VCAAlarmProp	"AALARM"
		....

   * consumer of a VObject can only define pointers to VObject.

   * a variable of type VObjectIterator, say "i", can be used to iterate
	through a VObject's properties, say "o". The APIs related to
	VObjectIterator are:
		void initPropIterator(VObjectIterator *i, VObject *o);
			-- e.g. usage
				initPropIterator(&i,o);
		int moreIteration(VObjectIterator *i);
			-- e.g. usage
				while (moreIteration(&i)) { ... }
		VObject* nextVObject(VObjectIterator *i);
			-- e.g. usage
				while (moreIteration(&i)) {
				    VObject *each = nextVObject(&i);
				    }

    * VObject can be chained together to form a list. e.g. of such
	use is in the parser where the return value of the parser is
	a link list of VObject. A link list of VObject can be
	built by:
		void addList(VObject **o, VObject *p);
	and iterated by
		VObject* nextVObjectInList(VObject *o);
			-- next VObjectInList return 0 if the list
				is exhausted.

    * the following APIs are mainly used to construct a VObject tree:
	VObject* newVObject(const char *id);
	    -- used extensively internally by VObject APIs but when
		used externally, its use is mainly limited to the
		construction of top level object (e.g. an object
		with VCCardProp or VCCalendarProp id).
	
	void deleteVObject(VObject *p);
	    -- to deallocate single VObject, for most user, use
		cleanVObject(VObject *o) instead for freeing all
		resources associated with the VObject.

	char* dupStr(const char *s, unsigned int size);
	    -- duplicate a string s. If size is 0, the string is
		assume to be a null-terminated. 

	void deleteStr(const char *p);
	    -- used to deallocate a string allocated by dupStr();

	void setVObjectName(VObject *o, const char* id);
	    -- set the id of VObject o. This function is not
		normally used by the user. The setting of id
		is normally done as part of other APIs (e.g.
		addProp()).

	void setVObjectStringZValue(VObject *o, const char *s);
	    -- set a string value of a VObject.

	void setVObjectUStringZValue(VObject *o, const wchar_t *s);
	    -- set a Unicode string value of a VObject.

	void setVObjectIntegerValue(VObject *o, unsigned int i);
	    -- set an integer value of a VObject.

	void setVObjectLongValue(VObject *o, unsigned long l);
	    -- set an long integer value of a VObject.

	void setVObjectAnyValue(VObject *o, void *t);
	    -- set any value of a VObject. The value type is
		unspecified.

	VObject* setValueWithSize(VObject *prop, void *val, unsigned int size);
	    -- set a raw data (stream of bytes) value of a VObject
		whose size is size. The internal VObject representation
		is
			this object = val
			    VCDataSizeProp=size
		i.e. the value val will be attached to the VObject prop
		and a property of VCDataSize whose value is size
		is also added to the object.
		
	void setVObjectVObjectValue(VObject *o, VObject *p);
	    -- set a VObject as the value of another VObject.

	const char* vObjectName(VObject *o);
	    -- retrieve the VObject's Name (i.e. id).

	const char* vObjectStringZValue(VObject *o);
	    -- retrieve the VObject's value interpreted as
		null-terminated string.

	const wchar_t* vObjectUStringZValue(VObject *o);
	    -- retrieve the VObject's value interpreted as
		null-terminated unicode string.

	unsigned int vObjectIntegerValue(VObject *o);
	    -- retrieve the VObject's value interpreted as
		integer.

	unsigned long vObjectLongValue(VObject *o);
	    -- retrieve the VObject's value interpreted as
		long integer.

	void* vObjectAnyValue(VObject *o);
	    -- retrieve the VObject's value interpreted as
		any value.

	VObject* vObjectVObjectValue(VObject *o);
	    -- retrieve the VObject's value interpreted as
		a VObject.

	VObject* addVObjectProp(VObject *o, VObject *p);
	    -- add a VObject p as a property of VObject o.
		(not normally used externally for building a
		VObject).

	VObject* addProp(VObject *o, const char *id);
	    -- add a property whose name is id to VObject o.

	VObject* addPropValue(VObject *o, const char *id, const char *v);
	    -- add a property whose name is id and whose value
		is a null-terminated string to VObject o.

	VObject* addPropSizedValue(VObject *o, const char *id,
			const char *v, unsigned int size);
	    -- add a property whose name is id and whose value
		is a stream of bytes of size size, to VObject o.

	VObject* addGroup(VObject *o, const char *g);
	    -- add a group g to VObject o.
		e.g. if g is a.b.c, you will have
		    o
			c
			   VCGroupingProp=b
			       VCGroupingProp=a
		and the object c is returned.
		
	VObject* isAPropertyOf(VObject *o, const char *id);
	     -- query if a property by the name id is in o and
		return the VObject that represent that property.

	void printVObject(VObject *o);
	     -- pretty print VObject o to stdout (for debugging use).

	void writeVObject(FILE *fp, VObject *o);
	     -- convert VObject o to its textual representation and
		write it to file.

	char* writeMemVObject(char *s, int *len, VObject *o);
	     -- convert VObject o to its textual representation and
		write it to memory. If s is 0, then memory required
		to hold the textual representation will be allocated
		by this API. If a variable len is passed, len will
		be overwriten with the byte size of the textual
		representation. If s is non-zero, then s has to
		be a user allocated buffer whose size has be passed
		in len as a variable. Memory allocated by the API
		has to be freed with call to free. The return value
		of this API is either the user supplied buffer,
		the memory allocated by the API, or 0 (in case of
		failure).

	void cleanStrTbl();
		-- this function has to be called when all
		VObject has been destroyed.

	void cleanVObject(VObject *o);
		-- release all resources used by VObject o.

	wchar_t* fakeUnicode(const char *ps, int *bytes);
		-- convert char* to wchar_t*.

	extern int uStrLen(const wchar_t *u);
		-- length of unicode u.

	char *fakeCString(const wchar_t *u);
		-- convert wchar_t to CString (blindly assumes that
		this could be done).

9. Additional Programming Notes
   ============================
In the following notes, please refers to the listing
of Example.vcf and its VObject Representation
(shown at the end of this section).

* Handling the Return Value of the VCard/VCalendar Parser
    The example input text file contains two root VObjects
    (a VCalendar and a VCard). The output of the VCard/VCalendar
    parser is a null-terminated list of VObjects. For this
    particular input file, the list will have two VObjects.
    The following shows a template for iterating through the
    output of the Parser:

	VObject *t, *v;
	v = Parse_Mime_fromFileName("example.vcf");
	while (v) {
	    // currently, v will either be a VCard or a VCalendar
	    //	do whatever your application need to do to
	    //  v here ...
	    t = v;
	    v = nextVObjectInList(v);
	    cleanVObject(t);
	    }

* Iterating Through a VCard/VCalendar VObject
    From the VObject APIs point of view, a VCard VObject
    is the same as a VCalendar VObject. However, the application
    needs to know what are in a VCard or a VCalendar.
    For example, A VCalendar VObject can have VCDCreatedProp,
    a VCGEOLocationProp, etc, and one or more VCEventProp and
    or VCTodoProp. The VCEventProp and VCTodoProp can have
    many properties of their own, which in turn could have
    more properties (e.g. VCDAlarmProp can be a VCEventProp
    VObject's property, and VCRunTimeProp can be a
    VCDAlarmProp VObject's property. Because a VObject tree
    can be arbitrarily complex, in general, to process all
    properties and values of a VObject tree, a recursive walk
    is desirable. An example recursive VObject tree walk
    can be found in the vobject.c source lines for printVObject*
    and writeVObject* APIs. Depending on what the application need
    to do with a VCard or a VCalendar, a recursive walk
    of the VObject tree may or may not be desirable. An example
    template of a non-recursive walk is shown below:
	
    void processVCardVCalendar(char *inputFile)
    {
	VObject *t, *v;
	v = Parse_Mime_fromFileName(inputFile);
	while (v) {
	    char *n = vObjectName(v);
	    if (strcmp(n,VCCardProp) == 0) {
		do_VCard(v);
		}
	    else if (strcmp(n,VCCalendarProp) == 0) {
		do_VCalendar(v);
		}
	    else {
		// don't know how to handle anything else!
		}
	    t = v;
	    v = nextVObjectInList(v);
	    cleanVObject(t);
	    }
    }

    void  do_VCard(VObject *vcard)
    {
	VObjectIterator t;
	initPropIterator(&t,vcard);
	while (moreIteration(&t)) {
	    VObject *eachProp = nextVObject(&t);
	    //	The primarly purpose of this example is to
	    //  show how to iterate through a VCard VObject,
	    //	it is not meant to be efficient at all.
	    char *n = vObjectName(eachProp);
	    if (strcmp(n,VCNameProp)==0) {
		do_name(eachProp);
		}
	    else if (strcmp(n,VCEmailProp)==0) {
		do_email(eachProp);
		}
	    else if (strcmp(n,VCLabelProp)==0) {
		do_label(eachProp);
		}
	    else if ....
	    }
    }

    void  do_VCalendar(VObject *vcal)
    {
	VObjectIterator t;
	initPropIterator(&t,vcard);
	while (moreIteration(&t)) {
	    VObject *eachProp = nextVObject(&t);
	    //	The primarly purpose of this example is to
	    //  show how to iterate through a VCalendar VObject,
	    //	it is not meant to be efficient at all.
	    char *n = vObjectName(eachProp);
	    if (strcmp(n,VCDCreatedProp)==0) {
		do_DCreated(eachProp);
		}
	    else if (strcmp(n,VCVersionProp)==0) {
		do_Version(eachProp);
		}
	    else if (strcmp(n,VCTodoProp)==0) {
		do_Todo(eachProp);
		}
	    else if (strcmp(n,VCEventProp)==0) {
		do_Event(eachProp);
		}
	    else if ....
	    }
    }

    void do_Todo(VObject *vtodo) { ... }

    void do_Event(VObject *vevent) { ... }

    ...
    
* Property's Values and Properties
    The VObject APIs do not attempt to check for the
    correctness of the values of a property. Nor do they
    will prevent the user from attaching a non-VCard/VCalendar
    standard property to a VCard/VCalendar property. Take
    the example of line [11] of the example, "O.K" is not
    a valid value of VCStatusProp.  It is up to the application
    to accept or reject the value of a property.
    
* Output of printVObject
    PrintVObject pretty prints a VObject tree in human
    readable form. See the listing at the end of the file
    for an example output of printVObject on the example
    input file "Example.vcf".

    Note that binary data are not shown in the output of
    printVObject. Instead, a note is made ([raw data]) to
    indicate that there exists such a binary data.

* Note on Binary Data
    When the value of a property is a binary data, it is only
    useful to know the size of the binary data.

    In the case of the VCard/VCalendar parser, it chooses
    to represent the size information as a separate property
    called VCDataSizeProp whose value is the size of the binary
    data. The APIs sequence to construct the VObject subtree
    of line [44] of Example.vcf is

	    // VObject *vcard;
	    VObject *p1 = addProp(vcard,VCLogoProp);
	    (void) addProp(p1,VCGIFProp);
	    (void) addProp(p1,VCBASE64Prop);
	    VObject *p2 = addProp(p1,VCDataSizeProp);
	    (void) setVObjectLongValue(p2,1482);
	    setVObjectAnyValue(vcard,...pointer to binary data);
	
    Note the presence of VCBase64Prop will cause the
    writeVObject API to output the binary data as BASE64 text.
    For VCard/VCalendar application, having the VCBase64Prop
    property is pratically always neccessary for property with
    binary data as its value.
	
* Note on Quoted-Printable String
    String value with embedded newline are written out as
    quoted-prinatable string. It is therefore important
    to mark a property with a string value that has
    one or more embedded newlines, with the VCQutedPrintableProp
    property. e.g.
			
	// VObject *root;
	char *msg="To be\nor\nnot to be";
	VObject *p = addPropValue(root,VCDescriptionProp,msg);
	    // the following is how you mark a property with
	    //	a property. In this case, the marker is
	    //  VCQuotedPrintableProp
	    addProp(p,VCQuotedPrintableProp);

* Note on Unicode
    Although, the current parser takes ASCII text file only,
    string values are all stored as Unicode in the VObject tree.
    For now, when using the VObject APIs to construct a
    VObject tree, one should always convert ASCII string value
    to a Unicode string value:

	// VObject *root;
	VObject *p = addProp(root,VCSomeProp);
	setVObjectUStringZValue(p,fakeUnicode(someASCIIStringZvalue));

    An API is provided to simplify the above process:

	addPropValue(root,VCSomeProp,someASCIIStringZValue);

    Note that someASCIISTringZValue is automatically converted to
    Unicode by addPropValue API, where as, the former code
    sequence do an explicit call to fakeUnicode.

    To read back the value, one should use the vObjectUStringZValue
    API not vObjectStringZValue API. The value returned by the
    vObjectUStringZValue API is a Unicode string. If the application
    do not know how to handle Unicode string, it can use the
    fakeCString API to convert it back to ASCII string (as long
    as the conversion is meaningful).

    Note that fakeCString return a heap allocated memory. It is
    important to call deleteStr on fakeCString return value if
    it is not longer required (or there will be memory leak).

    NOTE: Unfortunately, at the point when this document is written,
    there is still no consensus on how Unicode is to be handled
    in the textual representation of VCard/VCalendar. So, there
    is no version of writeVObject and the parser to output and
    input Unicode textual representation of VCard/VCalendar.
   

Example.vcf
-----------
line
number Input Text (example.vcf)
------ ----------
1      BEGIN:VCALENDAR
2      DCREATED:19961102T100522
3      GEO:0,0
4      VERSION:1.0
5      BEGIN:VEVENT
6      DTSTART:19961103T000000
7      DTEND:20000101T000000
8      DESCRIPTION;QUOTED-PRINTABLE:To be =0A=
9      or =0A=
10     not to be
11     STATUS:O.K.
12     X-ACTION:No action required
13     DALARM:19961103T114500;5;3;Enjoy
14     MALARM:19970101T120000;;;johny at nowhere.com;Call Mom.
15     END:VEVENT
16
17     BEGIN:VTODO
18     DUE:19960614T0173000
19     DESCRIPTION:Relex.
20     END:VTODO
21
22     END:VCALENDAR
23
24     BEGIN:VCARD
25     N:Alden;Roland
26     FN:Roland H. Alden
27     ORG:AT&T;Versit Project Office
28     TITLE:Consultant
29     EMAIL;WORK;PREF;INTERNET:ralden at ralden.com
30     LABEL;DOM;POSTAL;PARCEL;HOME;WORK;QUOTED-PRINTABLE:Roland H. Alden=0A=
31     Suite 2208=0A=
32     One Pine Street=0A=
33     San Francisco, CA 94111
34     LABEL;POSTAL;PARCEL;HOME;WORK;QUOTED-PRINTABLE:Roland H. Alden=0A=
35     Suite 2208=0A=
36     One Pine Street=0A=
37     San Francisco, CA 94111=0A=
38     U.S.A.
39     TEL;WORK;PREF;MSG:+1 415 296 9106
40     TEL;WORK;FAX:+1 415 296 9016
41     TEL;MSG;CELL:+1 415 608 5981
42     ADR:;Suite 2208;One Pine Street;San Francisco;CA;94111;U.S.A.
43     SOUND:ROW-LAND H ALL-DIN
44     LOGO;GIF;BASE64:
45         R0lGODdhpgBOAMQAAP///+/v797e3s7Ozr29va2trZycnIyMjHt7e2NjY1JSUkJC
    ... 30 lines of BASE64 data not shown here.
76     END:VCARD


VObject Representation of Example.vcf:
-------------------------------------
line
in
text
file  VObject Tree as Printed by printVObject API
----  -------------------------------------------
1     VCALENDAR
2         DCREATED="19961102T100522"
3         GEO="0,0"
4         VERSION="1.0"
5         VEVENT
6             DTSTART="19961103T000000"
7             DTEND="20000101T000000"
8             DESCRIPTION="To be
9                     or
10                    not to be"
8                 QUOTED-PRINTABLE
11            STATUS="O.K."
12            X-ACTION="No action required"
13            DALARM
13                RUNTIME="19961103T114500"
13                SNOOZETIME="5"
13                REPEATCOUNT="3"
13                DISPLAYSTRING="Enjoy"
14            MALARM
14                RUNTIME="19970101T120000"
14                EMAIL="johny at nowhere.com"
14                NOTE="Call Mom"
17        VTODO
18            DUE="19960614T0173000"
19            DESCRIPTION="Relex."
24    VCARD
25        N
25            F="Alden"
25            G="Roland"
26        FN="Roland H. Alden"
27        ORG
27            ORGNAME="AT&T"
27            OUN="Versit Project Office"
28        TITLE="Consultant"
29        EMAIL="ralden at alden.com"
29            WORK
29            PREF
29            INTERNET
30        LABEL="Roland H. Alden
31                Suite 2208
32                One Pine Street
33                San Francisco, CA 94111"
30            DOM
30            POSTAL
30            PARCEL
30            HOME
30            WORK
30            QUOTED-PRINTABLE
34        LABEL="Roland H. Alden
35                Suite 2208
36                One Pine Street
37                San Francisco, CA 94111
38                U.S.A."
34            POSTAL
34            PARCEL
34            HOME
34            WORK
34            QUOTED-PRINTABLE
39        TEL="+1 415 296 9106"
39            WORK
39            PREF
39            MSG
40        TEL="+1 415 296 9016"
40            WORK
40            FAX
41        TEL="+1 415 608 5981"
41            MSG
41            CELL
42        ADR
42            EXT ADD="Suite 2208"
42            STREET="One Pine Street"
42            L="San Francisco"
42            R="CA"
42            PC="94111"
42            C="U.S.A."
43        SOUND="ROW-LAND H ALL-DIN"
44        LOGO=[raw data]
44            GIF
44            BASE64
44            DATASIZE=1482


--- NEW FILE: vobject.c ---
/***************************************************************************
(C) Copyright 1996 Apple Computer, Inc., AT&T Corp., International             
Business Machines Corporation and Siemens Rolm Communications Inc.             
                                                                               
For purposes of this license notice, the term Licensors shall mean,            
collectively, Apple Computer, Inc., AT&T Corp., International                  
Business Machines Corporation and Siemens Rolm Communications Inc.             
The term Licensor shall mean any of the Licensors.                             
                                                                               
Subject to acceptance of the following conditions, permission is hereby        
granted by Licensors without the need for written agreement and without        
license or royalty fees, to use, copy, modify and distribute this              
software for any purpose.                                                      
                                                                               
The above copyright notice and the following four paragraphs must be           
reproduced in all copies of this software and any software including           
this software.                                                                 
                                                                               
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS AND NO LICENSOR SHALL HAVE       
[...1430 lines suppressed...]

    if (!u)
	return strdup("");
    
    t = s = (char*)malloc(len);

    while (*u) {
	if (*u == (wchar_t)0x2028)
	    *t = '\n';
	else if (*u == (wchar_t)0x2029)
	    *t = '\r';
	else
	    *t = (char)*u;
	u++; t++;
	}
    *t = 0;
    return s;
}

/* end of source file vobject.c */



More information about the Commits mailing list