summaryrefslogtreecommitdiff
path: root/library/backend/vobject.cpp
authorzecke <zecke>2003-08-29 18:02:09 (UTC)
committer zecke <zecke>2003-08-29 18:02:09 (UTC)
commit885c645ee48ae53467e244521c011c73bc106afb (patch) (side-by-side diff)
tree9024be25b2503788d3aa77b7a86b89e543cdd865 /library/backend/vobject.cpp
parented6da2303a8fabec50991365914f0e4d20a21ea6 (diff)
downloadopie-885c645ee48ae53467e244521c011c73bc106afb.zip
opie-885c645ee48ae53467e244521c011c73bc106afb.tar.gz
opie-885c645ee48ae53467e244521c011c73bc106afb.tar.bz2
Fixes for base64 decoding and encoding of vCard
Diffstat (limited to 'library/backend/vobject.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/backend/vobject.cpp5
1 files changed, 1 insertions, 4 deletions
diff --git a/library/backend/vobject.cpp b/library/backend/vobject.cpp
index 4c8de70..9263c3a 100644
--- a/library/backend/vobject.cpp
+++ b/library/backend/vobject.cpp
@@ -1,175 +1,173 @@
/***************************************************************************
(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.
***************************************************************************/
/*
* src: vobject.c
* doc: vobject and APIs to construct vobject, APIs pretty print
* vobject, and convert a vobject into its textual representation.
*/
-#ifndef MWERKS
-#include <malloc.h>
-#endif
+#include <stdlib.h>
#include <qtopia/config.h>
#include "vobject_p.h"
#include "qfiledirect_p.h"
#include <string.h>
#include <stdio.h>
#include <fcntl.h>
//#include <io.h>
#define NAME_OF(o) o->id
#define VALUE_TYPE(o) o->valType
#define STRINGZ_VALUE_OF(o) o->val.strs
#define INTEGER_VALUE_OF(o) o->val.i
#define LONG_VALUE_OF(o) o->val.l
#define ANY_VALUE_OF(o) o->val.any
#define VOBJECT_VALUE_OF(o) o->val.vobj
static char vobj_cs[10];
static enum { EightBit, QuotedPrintable, Base64 } vobj_enc=EightBit;
static const char *vobj_enc_s=0;
typedef union ValueItem {
const char *strs;
unsigned int i;
unsigned long l;
void *any;
VObject *vobj;
} ValueItem;
struct VObject {
VObject *next;
const char *id;
VObject *prop;
unsigned short valType;
ValueItem val;
};
typedef struct StrItem StrItem;
struct StrItem {
StrItem *next;
const char *s;
unsigned int refCnt;
};
DLLEXPORT(const char**) fieldedProp;
/*----------------------------------------------------------------------
The following functions involve with memory allocation:
newVObject
deleteVObject
dupStr
deleteStr
newStrItem
deleteStrItem
----------------------------------------------------------------------*/
DLLEXPORT(VObject*) newVObject_(const char *id)
{
VObject *p = (VObject*)malloc(sizeof(VObject));
p->next = 0;
p->id = id;
p->prop = 0;
VALUE_TYPE(p) = 0;
ANY_VALUE_OF(p) = 0;
return p;
}
DLLEXPORT(VObject*) newVObject(const char *id)
{
return newVObject_(lookupStr(id));
}
DLLEXPORT(void) deleteVObject(VObject *p)
{
unUseStr(p->id);
free(p);
}
DLLEXPORT(char*) dupStr(const char *s, unsigned int size)
{
char *t;
if (size == 0) {
size = strlen(s);
}
t = (char*)malloc(size+1);
if (t) {
memcpy(t,s,size);
t[size] = 0;
return t;
}
else {
return (char*)0;
}
}
DLLEXPORT(void) deleteStr(const char *p)
{
if (p) free((void*)p);
}
static StrItem* newStrItem(const char *s, StrItem *next)
{
StrItem *p = (StrItem*)malloc(sizeof(StrItem));
p->next = next;
p->s = s;
p->refCnt = 1;
return p;
}
static void deleteStrItem(StrItem *p)
{
free((void*)p);
}
/*----------------------------------------------------------------------
The following function provide accesses to VObject's value.
----------------------------------------------------------------------*/
DLLEXPORT(const char*) vObjectName(VObject *o)
{
return NAME_OF(o);
}
@@ -632,257 +630,256 @@ static const char *MAlarmFields[] = {
static const char *PAlarmFields[] = {
VCRunTimeProp,
VCSnoozeTimeProp,
VCRepeatCountProp,
VCProcedureNameProp,
0
};
static struct PreDefProp propNames[] = {
{ VC7bitProp, 0, 0, 0 },
{ VC8bitProp, 0, 0, 0 },
{ VCAAlarmProp, 0, AAlarmFields, 0 },
{ VCAdditionalNamesProp, 0, 0, 0 },
{ VCAdrProp, 0, adrFields, 0 },
{ VCAgentProp, 0, 0, 0 },
{ VCAIFFProp, 0, 0, 0 },
{ VCAOLProp, 0, 0, 0 },
{ VCAppleLinkProp, 0, 0, 0 },
{ VCAttachProp, 0, 0, 0 },
{ VCAttendeeProp, 0, 0, 0 },
{ VCATTMailProp, 0, 0, 0 },
{ VCAudioContentProp, 0, 0, 0 },
{ VCAVIProp, 0, 0, 0 },
{ VCBase64Prop, 0, 0, 0 },
{ VCBBSProp, 0, 0, 0 },
{ VCBirthDateProp, 0, 0, 0 },
{ VCBMPProp, 0, 0, 0 },
{ VCBodyProp, 0, 0, 0 },
{ VCBusinessRoleProp, 0, 0, 0 },
{ VCCalProp, 0, 0, PD_BEGIN },
{ VCCaptionProp, 0, 0, 0 },
{ VCCardProp, 0, 0, PD_BEGIN },
{ VCCarProp, 0, 0, 0 },
{ VCCategoriesProp, 0, 0, 0 },
{ VCCellularProp, 0, 0, 0 },
{ VCCGMProp, 0, 0, 0 },
{ VCCharSetProp, 0, 0, 0 },
{ VCCIDProp, VCContentIDProp, 0, 0 },
{ VCCISProp, 0, 0, 0 },
{ VCCityProp, 0, 0, 0 },
{ VCClassProp, 0, 0, 0 },
{ VCCommentProp, 0, 0, 0 },
{ VCCompletedProp, 0, 0, 0 },
{ VCContentIDProp, 0, 0, 0 },
{ VCCountryNameProp, 0, 0, 0 },
{ VCDAlarmProp, 0, DAlarmFields, 0 },
{ VCDataSizeProp, 0, 0, PD_INTERNAL },
{ VCDayLightProp, 0, 0, 0 },
{ VCDCreatedProp, 0, 0, 0 },
{ VCDeliveryLabelProp, 0, 0, 0 },
{ VCDescriptionProp, 0, 0, 0 },
{ VCDIBProp, 0, 0, 0 },
{ VCDisplayStringProp, 0, 0, 0 },
{ VCDomesticProp, 0, 0, 0 },
{ VCDTendProp, 0, 0, 0 },
{ VCDTstartProp, 0, 0, 0 },
{ VCDueProp, 0, 0, 0 },
{ VCEmailAddressProp, 0, 0, 0 },
{ VCEncodingProp, 0, 0, 0 },
{ VCEndProp, 0, 0, 0 },
{ VCEventProp, 0, 0, PD_BEGIN },
{ VCEWorldProp, 0, 0, 0 },
{ VCExNumProp, 0, 0, 0 },
{ VCExpDateProp, 0, 0, 0 },
{ VCExpectProp, 0, 0, 0 },
{ VCExtAddressProp, 0, 0, 0 },
{ VCFamilyNameProp, 0, 0, 0 },
{ VCFaxProp, 0, 0, 0 },
{ VCFullNameProp, 0, 0, 0 },
{ VCGeoLocationProp, 0, 0, 0 },
{ VCGeoProp, 0, 0, 0 },
{ VCGIFProp, 0, 0, 0 },
{ VCGivenNameProp, 0, 0, 0 },
{ VCGroupingProp, 0, 0, 0 },
{ VCHomeProp, 0, 0, 0 },
{ VCIBMMailProp, 0, 0, 0 },
{ VCInlineProp, 0, 0, 0 },
{ VCInternationalProp, 0, 0, 0 },
{ VCInternetProp, 0, 0, 0 },
{ VCISDNProp, 0, 0, 0 },
{ VCJPEGProp, 0, 0, 0 },
{ VCLanguageProp, 0, 0, 0 },
{ VCLastModifiedProp, 0, 0, 0 },
{ VCLastRevisedProp, 0, 0, 0 },
{ VCLocationProp, 0, 0, 0 },
{ VCLogoProp, 0, 0, 0 },
{ VCMailerProp, 0, 0, 0 },
{ VCMAlarmProp, 0, MAlarmFields, 0 },
{ VCMCIMailProp, 0, 0, 0 },
{ VCMessageProp, 0, 0, 0 },
{ VCMETProp, 0, 0, 0 },
{ VCModemProp, 0, 0, 0 },
{ VCMPEG2Prop, 0, 0, 0 },
{ VCMPEGProp, 0, 0, 0 },
{ VCMSNProp, 0, 0, 0 },
{ VCNamePrefixesProp, 0, 0, 0 },
{ VCNameProp, 0, nameFields, 0 },
{ VCNameSuffixesProp, 0, 0, 0 },
{ VCNoteProp, 0, 0, 0 },
{ VCOrgNameProp, 0, 0, 0 },
{ VCOrgProp, 0, orgFields, 0 },
{ VCOrgUnit2Prop, 0, 0, 0 },
{ VCOrgUnit3Prop, 0, 0, 0 },
{ VCOrgUnit4Prop, 0, 0, 0 },
{ VCOrgUnitProp, 0, 0, 0 },
{ VCPagerProp, 0, 0, 0 },
{ VCPAlarmProp, 0, PAlarmFields, 0 },
{ VCParcelProp, 0, 0, 0 },
{ VCPartProp, 0, 0, 0 },
{ VCPCMProp, 0, 0, 0 },
{ VCPDFProp, 0, 0, 0 },
{ VCPGPProp, 0, 0, 0 },
{ VCPhotoProp, 0, 0, 0 },
{ VCPICTProp, 0, 0, 0 },
{ VCPMBProp, 0, 0, 0 },
{ VCPostalBoxProp, 0, 0, 0 },
{ VCPostalCodeProp, 0, 0, 0 },
{ VCPostalProp, 0, 0, 0 },
{ VCPowerShareProp, 0, 0, 0 },
{ VCPreferredProp, 0, 0, 0 },
{ VCPriorityProp, 0, 0, 0 },
{ VCProcedureNameProp, 0, 0, 0 },
{ VCProdIdProp, 0, 0, 0 },
{ VCProdigyProp, 0, 0, 0 },
{ VCPronunciationProp, 0, 0, 0 },
{ VCPSProp, 0, 0, 0 },
{ VCPublicKeyProp, 0, 0, 0 },
{ VCQPProp, VCQuotedPrintableProp, 0, 0 },
- { VCQPProp, VCBase64Prop, 0, 0 },
{ VCQuickTimeProp, 0, 0, 0 },
{ VCQuotedPrintableProp, 0, 0, 0 },
{ VCRDateProp, 0, 0, 0 },
{ VCRegionProp, 0, 0, 0 },
{ VCRelatedToProp, 0, 0, 0 },
{ VCRepeatCountProp, 0, 0, 0 },
{ VCResourcesProp, 0, 0, 0 },
{ VCRNumProp, 0, 0, 0 },
{ VCRoleProp, 0, 0, 0 },
{ VCRRuleProp, 0, 0, 0 },
{ VCRSVPProp, 0, 0, 0 },
{ VCRunTimeProp, 0, 0, 0 },
{ VCSequenceProp, 0, 0, 0 },
{ VCSnoozeTimeProp, 0, 0, 0 },
{ VCStartProp, 0, 0, 0 },
{ VCStatusProp, 0, 0, 0 },
{ VCStreetAddressProp, 0, 0, 0 },
{ VCSubTypeProp, 0, 0, 0 },
{ VCSummaryProp, 0, 0, 0 },
{ VCTelephoneProp, 0, 0, 0 },
{ VCTIFFProp, 0, 0, 0 },
{ VCTimeZoneProp, 0, 0, 0 },
{ VCTitleProp, 0, 0, 0 },
{ VCTLXProp, 0, 0, 0 },
{ VCTodoProp, 0, 0, PD_BEGIN },
{ VCTranspProp, 0, 0, 0 },
{ VCUniqueStringProp, 0, 0, 0 },
{ VCURLProp, 0, 0, 0 },
{ VCURLValueProp, 0, 0, 0 },
{ VCValueProp, 0, 0, 0 },
{ VCVersionProp, 0, 0, 0 },
{ VCVideoProp, 0, 0, 0 },
{ VCVoiceProp, 0, 0, 0 },
{ VCWAVEProp, 0, 0, 0 },
{ VCWMFProp, 0, 0, 0 },
{ VCWorkProp, 0, 0, 0 },
{ VCX400Prop, 0, 0, 0 },
{ VCX509Prop, 0, 0, 0 },
{ VCXRuleProp, 0, 0, 0 },
{ 0,0,0,0 }
};
static struct PreDefProp* lookupPropInfo(const char* str)
{
/* brute force for now, could use a hash table here. */
int i;
for (i = 0; propNames[i].name; i++)
if (qstricmp(str, propNames[i].name) == 0) {
return &propNames[i];
}
return 0;
}
DLLEXPORT(const char*) lookupProp_(const char* str)
{
int i;
for (i = 0; propNames[i].name; i++)
if (qstricmp(str, propNames[i].name) == 0) {
const char* s;
s = propNames[i].alias?propNames[i].alias:propNames[i].name;
return lookupStr(s);
}
return lookupStr(str);
}
DLLEXPORT(const char*) lookupProp(const char* str)
{
int i;
for (i = 0; propNames[i].name; i++)
if (qstricmp(str, propNames[i].name) == 0) {
const char *s;
fieldedProp = propNames[i].fields;
s = propNames[i].alias?propNames[i].alias:propNames[i].name;
return lookupStr(s);
}
fieldedProp = 0;
return lookupStr(str);
}
/*----------------------------------------------------------------------
APIs to Output text form.
----------------------------------------------------------------------*/
#define OFILE_REALLOC_SIZE 256
typedef struct OFile {
FILE *fp;
char *s;
int len;
int limit;
int alloc:1;
int fail:1;
} OFile;
#if 0
static void appendsOFile(OFile *fp, const char *s)
{
int slen;
if (fp->fail) return;
slen = strlen(s);
if (fp->fp) {
fwrite(s,1,slen,fp->fp);
}
else {
stuff:
if (fp->len + slen < fp->limit) {
memcpy(fp->s+fp->len,s,slen);
fp->len += slen;
return;
}
else if (fp->alloc) {
fp->limit = fp->limit + OFILE_REALLOC_SIZE;
if (OFILE_REALLOC_SIZE <= slen) fp->limit += slen;
fp->s = (char *) realloc(fp->s,fp->limit);
if (fp->s) goto stuff;
}
if (fp->alloc)
free(fp->s);
fp->s = 0;
fp->fail = 1;
}
}