summaryrefslogtreecommitdiff
path: root/library/backend
Side-by-side diff
Diffstat (limited to 'library/backend') (more/less context) (ignore whitespace changes)
-rw-r--r--library/backend/vcc.y22
-rw-r--r--library/backend/vcc_yacc.cpp139
-rw-r--r--library/backend/vobject.cpp273
-rw-r--r--library/backend/vobject_p.h31
4 files changed, 251 insertions, 214 deletions
diff --git a/library/backend/vcc.y b/library/backend/vcc.y
index 6781312..94a8fea 100644
--- a/library/backend/vcc.y
+++ b/library/backend/vcc.y
@@ -29,193 +29,193 @@ 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: vcc.c
* doc: Parser for vCard and vCalendar. Note that this code is
* generated by a yacc parser generator. Generally it should not
* be edited by hand. The real source is vcc.y. The #line directives
* can be commented out here to make it easier to trace through
* in a debugger. However, if a bug is found it should
* be fixed in vcc.y and this file regenerated.
*/
/* debugging utilities */
#if __DEBUG
#define DBG_(x) printf x
#else
#define DBG_(x)
#endif
/**** External Functions ****/
/* assign local name to parser variables and functions so that
we can use more than one yacc based parser.
*/
#if 0
#define yyparse mime_parse
#define yylex mime_lex
#define yyerror mime_error
#define yychar mime_char
/* #define p_yyval p_mime_val */
#undef yyval
#define yyval mime_yyval
/* #define p_yylval p_mime_lval */
#undef yylval
#define yylval mime_yylval
#define yydebug mime_debug
#define yynerrs mime_nerrs
#define yyerrflag mime_errflag
#define yyss mime_ss
#define yyssp mime_ssp
#define yyvs mime_vs
#define yyvsp mime_vsp
#define yylhs mime_lhs
#define yylen mime_len
#define yydefred mime_defred
#define yydgoto mime_dgoto
#define yysindex mime_sindex
#define yyrindex mime_rindex
#define yygindex mime_gindex
#define yytable mime_table
#define yycheck mime_check
#define yyname mime_name
#define yyrule mime_rule
#ifdef YYPREFIX
#undef YYPREFIX
#endif
#define YYPREFIX "mime_"
#endif
#ifndef _NO_LINE_FOLDING
#define _SUPPORT_LINE_FOLDING 1
#endif
/* undef below if compile with MFC */
/* #define INCLUDEMFC 1 */
#if defined(WIN32) || defined(_WIN32)
#ifdef INCLUDEMFC
#include <afx.h>
#endif
#endif
#include <string.h>
#ifndef __MWERKS__
#include <stdlib.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
//#ifdef PALMTOPCENTER
//#include <qpe/vobject_p.h>
//#else
-#include <qtopia/private/vobject_p.h>
+#include "vobject_p.h"
//#endif
/**** Types, Constants ****/
#define YYDEBUG 0 /* 1 to compile in some debugging code */
#define MAXTOKEN 256 /* maximum token (line) length */
#define YYSTACKSIZE 100 // ~unref ?
#define MAXLEVEL 10 /* max # of nested objects parseable */
/* (includes outermost) */
/**** Global Variables ****/
int mime_lineNum, mime_numErrors; /* yyerror() can use these */
static VObject* vObjList;
static VObject *curProp;
static VObject *curObj;
static VObject* ObjStack[MAXLEVEL];
static int ObjStackTop;
/* A helpful utility for the rest of the app. */
#if __CPLUSPLUS__
extern "C" {
#endif
extern void yyerror(char *s);
#if __CPLUSPLUS__
};
#endif
int yyparse();
enum LexMode {
L_NORMAL,
L_VCARD,
L_VCAL,
L_VEVENT,
L_VTODO,
L_VALUES,
L_BASE64,
L_QUOTED_PRINTABLE
};
/**** Private Forward Declarations ****/
static int pushVObject(const char *prop);
static VObject* popVObject();
static void lexPopMode(int top);
static int lexWithinMode(enum LexMode mode);
static void lexPushMode(enum LexMode mode);
static void enterProps(const char *s);
static void enterAttr(const char *s1, const char *s2);
static void enterValues(const char *value);
#define mime_error yyerror
void mime_error(char *s);
void mime_error_(char *s);
%}
/***************************************************************************/
/*** The grammar ****/
/***************************************************************************/
%union {
char *str;
VObject *vobj;
}
%token
EQ COLON DOT SEMICOLON SPACE HTAB LINESEP NEWLINE
BEGIN_VCARD END_VCARD BEGIN_VCAL END_VCAL
BEGIN_VEVENT END_VEVENT BEGIN_VTODO END_VTODO
ID
/*
* NEWLINE is the token that would occur outside a vCard,
* while LINESEP is the token that would occur inside a vCard.
*/
%token <str>
STRING ID
%type <str> name value
%type <vobj> vcard vcal vobject
%start mime
%%
mime: vobjects
;
vobjects: vobjects vobject
{ addList(&vObjList, $2); curObj = 0; }
@@ -630,202 +630,208 @@ static void lexSkipWhite() {
static char* lexGetWord() {
int c;
lexSkipWhite();
lexClearToken();
c = lexLookahead();
while (c != EOF && !strchr("\t\n ;:=",c)) {
lexAppendc(c);
lexSkipLookahead();
c = lexLookahead();
}
lexAppendc(0);
return lexStr();
}
static void lexPushLookaheadc(int c) {
int putptr;
/* can't putback EOF, because it never leaves lookahead buffer */
if (c == EOF) return;
putptr = (int)lexBuf.getPtr - 1;
if (putptr < 0) putptr += MAX_LEX_LOOKAHEAD;
lexBuf.getPtr = putptr;
lexBuf.buf[putptr] = c;
lexBuf.len += 1;
}
static char* lexLookaheadWord() {
/* this function can lookahead word with max size of MAX_LEX_LOOKAHEAD_0
/ and thing bigger than that will stop the lookahead and return 0;
/ leading white spaces are not recoverable.
*/
int c;
int len = 0;
int curgetptr = 0;
lexSkipWhite();
lexClearToken();
curgetptr = (int)lexBuf.getPtr; // remember!
while (len < (MAX_LEX_LOOKAHEAD_0)) {
c = lexGetc();
len++;
if (c == EOF || strchr("\t\n ;:=", c)) {
lexAppendc(0);
/* restore lookahead buf. */
lexBuf.len += len;
lexBuf.getPtr = curgetptr;
return lexStr();
}
else
lexAppendc(c);
}
lexBuf.len += len; /* char that has been moved to lookahead buffer */
lexBuf.getPtr = curgetptr;
return 0;
}
#ifdef _SUPPORT_LINE_FOLDING
static void handleMoreRFC822LineBreak(int c) {
/* suport RFC 822 line break in cases like
* ADR: foo;
* morefoo;
* more foo;
*/
if (c == ';') {
int a;
lexSkipLookahead();
/* skip white spaces */
a = lexLookahead();
while (a == ' ' || a == '\t') {
lexSkipLookahead();
a = lexLookahead();
}
if (a == '\n') {
lexSkipLookahead();
a = lexLookahead();
if (a == ' ' || a == '\t') {
/* continuation, throw away all the \n and spaces read so
* far
*/
lexSkipWhite();
lexPushLookaheadc(';');
}
else {
lexPushLookaheadc('\n');
lexPushLookaheadc(';');
}
}
else {
lexPushLookaheadc(';');
}
}
}
static char* lexGet1Value() {
int c;
lexSkipWhite();
c = lexLookahead();
lexClearToken();
- while (c != EOF && c != ';') {
+ while (c != EOF && (c != ';' || !fieldedProp)) {
if (c == '\\' ) {
int a;
lexSkipLookahead();
a = lexLookahead();
- if ( a != ';' ) {
- lexAppendc('\\');
- } else {
+ if ( a == ';' ) {
lexAppendc( ';' );
lexSkipLookahead();
+ } else if ( a == '\n' ) {
+ lexAppendc( '\n' );
+ lexSkipLookahead();
+ } else if ( a == '\\' ) {
+ lexAppendc( '\\' );
+ lexSkipLookahead();
+ } else {
+ lexAppendc('\\');
}
} else if (c == '\n') {
int a;
lexSkipLookahead();
a = lexLookahead();
if (a == ' ' || a == '\t') {
lexAppendc(' ');
lexSkipLookahead();
}
else {
lexPushLookaheadc('\n');
break;
}
}
else {
lexAppendc(c);
lexSkipLookahead();
}
c = lexLookahead();
}
lexAppendc(0);
handleMoreRFC822LineBreak(c);
return c==EOF?0:lexStr();
}
#endif
static int match_begin_name(int end) {
char *n = lexLookaheadWord();
int token = ID;
if (n) {
if (!qstricmp(n,"vcard")) token = end?END_VCARD:BEGIN_VCARD;
else if (!qstricmp(n,"vcalendar")) token = end?END_VCAL:BEGIN_VCAL;
else if (!qstricmp(n,"vevent")) token = end?END_VEVENT:BEGIN_VEVENT;
else if (!qstricmp(n,"vtodo")) token = end?END_VTODO:BEGIN_VTODO;
deleteStr(n);
return token;
}
return 0;
}
#ifdef INCLUDEMFC
void initLex(const char *inputstring, unsigned long inputlen, CFile *inputfile)
#else
void initLex(const char *inputstring, unsigned long inputlen, FILE *inputfile)
#endif
{
// initialize lex mode stack
lexBuf.lexModeStack[lexBuf.lexModeStackTop=0] = L_NORMAL;
// iniatialize lex buffer.
lexBuf.inputString = (char*) inputstring;
lexBuf.inputLen = inputlen;
lexBuf.curPos = 0;
lexBuf.inputFile = inputfile;
lexBuf.len = 0;
lexBuf.getPtr = 0;
lexBuf.maxToken = MAXTOKEN;
lexBuf.strs = (char*)malloc(MAXTOKEN);
lexBuf.strsLen = 0;
}
static void finiLex() {
free(lexBuf.strs);
}
/*-----------------------------------*/
/* This parses and converts the base64 format for binary encoding into
* a decoded buffer (allocated with new). See RFC 1521.
*/
static char * lexGetDataFromBase64()
{
unsigned long bytesLen = 0, bytesMax = 0;
int quadIx = 0, pad = 0;
unsigned long trip = 0;
unsigned char b;
int c;
unsigned char *bytes = NULL;
unsigned char *oldBytes = NULL;
DBG_(("db: lexGetDataFromBase64\n"));
while (1) {
c = lexGetc();
if (c == '\n') {
++mime_lineNum;
if (lexLookahead() == '\n') {
/* a '\n' character by itself means end of data */
break;
}
else continue; /* ignore '\n' */
}
else {
@@ -868,291 +874,295 @@ static char * lexGetDataFromBase64()
int i;
for (i = 0; i < 3; i++) {
outBytes[2-i] = (unsigned char)(trip & 0xFF);
trip >>= 8;
}
numOut = 3 - pad;
if (bytesLen + numOut > bytesMax) {
if (!bytes) {
bytesMax = 1024;
bytes = (unsigned char*)malloc((size_t)bytesMax);
}
else {
bytesMax <<= 2;
oldBytes = bytes;
bytes = (unsigned char*)realloc(bytes,(size_t)bytesMax);
}
if (bytes == 0) {
mime_error("out of memory while processing BASE64 data\n");
}
}
if (bytes) {
memcpy(bytes + bytesLen, outBytes, numOut);
bytesLen += numOut;
}
trip = 0;
quadIx = 0;
}
}
} /* while */
DBG_(("db: bytesLen = %d\n", bytesLen));
/* kludge: all this won't be necessary if we have tree form
representation */
if (bytes) {
setValueWithSize(curProp,bytes,(unsigned int)bytesLen);
free(bytes);
}
else if (oldBytes) {
setValueWithSize(curProp,oldBytes,(unsigned int)bytesLen);
free(oldBytes);
}
return 0;
}
static int match_begin_end_name(int end) {
int token;
lexSkipWhite();
if (lexLookahead() != ':') return ID;
lexSkipLookahead();
lexSkipWhite();
token = match_begin_name(end);
if (token == ID) {
lexPushLookaheadc(':');
DBG_(("db: ID '%s'\n", yylval.str));
return ID;
}
else if (token != 0) {
lexSkipLookaheadWord();
deleteStr(yylval.str);
DBG_(("db: begin/end %d\n", token));
return token;
}
return 0;
}
static char* lexGetQuotedPrintable()
{
int c;
lexSkipWhite();
c = lexLookahead();
lexClearToken();
while (c != EOF && c != ';') {
if (c == '\n') {
// break, leave '\n' on remaining chars.
break;
} else if (c == '=') {
int cur = 0;
int next;
lexSkipLookahead(); // skip '='
next = lexLookahead();
if (next == '\n') {
// skip and only skip the \n
lexSkipLookahead();
c = lexLookahead();
++mime_lineNum; // aid in error reporting
continue;
} else if (next >= '0' && next <= '9') {
cur = next - '0';
} else if (next >= 'A' && next <= 'F') {
cur = next - 'A' + 10;
} else {
// we have been sent buggy stuff. doesn't matter
// what we do so long as we keep going.
// should probably spit an error here
+ lexSkipLookahead();
c = lexLookahead();
continue;
}
lexSkipLookahead(); // skip A-Z0-9
next = lexLookahead();
cur = cur * 16;
// this time really just expecting 0-9A-F
if (next >= '0' && next <= '9') {
cur += next - '0';
} else if (next >= 'A' && next <= 'F') {
cur += next - 'A' + 10;
} else {
// we have been sent buggy stuff. doesn't matter
// what we do so long as we keep going.
// should probably spit an error here
+ lexSkipLookahead();
c = lexLookahead();
continue;
}
// got a valid escaped =. append it.
lexSkipLookahead(); // skip second 0-9A-F
lexAppendc(cur);
} else {
lexSkipLookahead(); // skip whatever we just read.
lexAppendc(c); // and append it.
}
c = lexLookahead();
}
lexAppendc(0);
return c==EOF?0:lexStr();
}
static int yylex() {
int lexmode = LEXMODE();
if (lexmode == L_VALUES) {
int c = lexGetc();
- if (c == ';') {
+ if (c == ';' && fieldedProp) {
DBG_(("db: SEMICOLON\n"));
lexPushLookaheadc(c);
handleMoreRFC822LineBreak(c);
lexSkipLookahead();
return SEMICOLON;
}
else if (strchr("\n",c)) {
++mime_lineNum;
/* consume all line separator(s) adjacent to each other */
c = lexLookahead();
while (strchr("\n",c)) {
lexSkipLookahead();
c = lexLookahead();
++mime_lineNum;
}
DBG_(("db: LINESEP\n"));
return LINESEP;
}
else {
char *p = 0;
lexPushLookaheadc(c);
if (lexWithinMode(L_BASE64)) {
/* get each char and convert to bin on the fly... */
p = lexGetDataFromBase64();
yylval.str = p;
return STRING;
}
else if (lexWithinMode(L_QUOTED_PRINTABLE)) {
p = lexGetQuotedPrintable();
}
else {
#ifdef _SUPPORT_LINE_FOLDING
p = lexGet1Value();
#else
p = lexGetStrUntil(";\n");
#endif
}
if (p) {
DBG_(("db: STRING: '%s'\n", p));
yylval.str = p;
return STRING;
}
else return 0;
}
}
else {
/* normal mode */
while (1) {
int c = lexGetc();
switch(c) {
case ':': {
/* consume all line separator(s) adjacent to each other */
/* ignoring linesep immediately after colon. */
+ /* I don't see this in the spec, and it breaks null values -- WA
c = lexLookahead();
while (strchr("\n",c)) {
lexSkipLookahead();
c = lexLookahead();
++mime_lineNum;
}
+ */
DBG_(("db: COLON\n"));
return COLON;
}
case ';':
DBG_(("db: SEMICOLON\n"));
return SEMICOLON;
case '=':
DBG_(("db: EQ\n"));
return EQ;
/* ignore whitespace in this mode */
case '\t':
case ' ': continue;
case '\n': {
++mime_lineNum;
continue;
}
case EOF: return 0;
break;
default: {
lexPushLookaheadc(c);
if (isalnum(c)) {
char *t = lexGetWord();
yylval.str = t;
if (!qstricmp(t, "begin")) {
return match_begin_end_name(0);
}
else if (!qstricmp(t,"end")) {
return match_begin_end_name(1);
}
else {
DBG_(("db: ID '%s'\n", t));
return ID;
}
}
else {
/* unknow token */
return 0;
}
break;
}
}
}
}
return 0;
}
/***************************************************************************/
/*** Public Functions ****/
/***************************************************************************/
static VObject* Parse_MIMEHelper()
{
ObjStackTop = -1;
mime_numErrors = 0;
mime_lineNum = 1;
vObjList = 0;
curObj = 0;
if (yyparse() != 0)
return 0;
finiLex();
return vObjList;
}
/*--------------------------------------------*/
DLLEXPORT(VObject*) Parse_MIME(const char *input, unsigned long len)
{
initLex(input, len, 0);
return Parse_MIMEHelper();
}
#if INCLUDEMFC
DLLEXPORT(VObject*) Parse_MIME_FromFile(CFile *file)
{
unsigned long startPos;
VObject *result;
initLex(0,-1,file);
startPos = file->GetPosition();
if (!(result = Parse_MIMEHelper()))
file->Seek(startPos, CFile::begin);
return result;
}
#else
VObject* Parse_MIME_FromFile(FILE *file)
{
VObject *result;
long startPos;
initLex(0,(unsigned long)-1,file);
diff --git a/library/backend/vcc_yacc.cpp b/library/backend/vcc_yacc.cpp
index b2b0c14..5649522 100644
--- a/library/backend/vcc_yacc.cpp
+++ b/library/backend/vcc_yacc.cpp
@@ -65,193 +65,193 @@ 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: vcc.c
* doc: Parser for vCard and vCalendar. Note that this code is
* generated by a yacc parser generator. Generally it should not
* be edited by hand. The real source is vcc.y. The #line directives
* can be commented out here to make it easier to trace through
* in a debugger. However, if a bug is found it should
* be fixed in vcc.y and this file regenerated.
*/
/* debugging utilities */
#if __DEBUG
#define DBG_(x) printf x
#else
#define DBG_(x)
#endif
/**** External Functions ****/
/* assign local name to parser variables and functions so that
we can use more than one yacc based parser.
*/
#if 0
#define yyparse mime_parse
#define yylex mime_lex
#define yyerror mime_error
#define yychar mime_char
/* #define p_yyval p_mime_val */
#undef yyval
#define yyval mime_yyval
/* #define p_yylval p_mime_lval */
#undef yylval
#define yylval mime_yylval
#define yydebug mime_debug
#define yynerrs mime_nerrs
#define yyerrflag mime_errflag
#define yyss mime_ss
#define yyssp mime_ssp
#define yyvs mime_vs
#define yyvsp mime_vsp
#define yylhs mime_lhs
#define yylen mime_len
#define yydefred mime_defred
#define yydgoto mime_dgoto
#define yysindex mime_sindex
#define yyrindex mime_rindex
#define yygindex mime_gindex
#define yytable mime_table
#define yycheck mime_check
#define yyname mime_name
#define yyrule mime_rule
#ifdef YYPREFIX
#undef YYPREFIX
#endif
#define YYPREFIX "mime_"
#endif
#ifndef _NO_LINE_FOLDING
#define _SUPPORT_LINE_FOLDING 1
#endif
/* undef below if compile with MFC */
/* #define INCLUDEMFC 1 */
#if defined(WIN32) || defined(_WIN32)
#ifdef INCLUDEMFC
#include <afx.h>
#endif
#endif
#include <string.h>
#ifndef __MWERKS__
#include <stdlib.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
/*#ifdef PALMTOPCENTER */
/*#include <qpe/vobject_p.h> */
/*#else */
-#include <qtopia/private/vobject_p.h>
+#include "vobject_p.h"
/*#endif */
/**** Types, Constants ****/
#define YYDEBUG 0 /* 1 to compile in some debugging code */
#define MAXTOKEN 256 /* maximum token (line) length */
#define YYSTACKSIZE 100 /* ~unref ? */
#define MAXLEVEL 10 /* max # of nested objects parseable */
/* (includes outermost) */
/**** Global Variables ****/
int mime_lineNum, mime_numErrors; /* yyerror() can use these */
static VObject* vObjList;
static VObject *curProp;
static VObject *curObj;
static VObject* ObjStack[MAXLEVEL];
static int ObjStackTop;
/* A helpful utility for the rest of the app. */
#if __CPLUSPLUS__
extern "C" {
#endif
extern void yyerror(char *s);
#if __CPLUSPLUS__
};
#endif
int yyparse();
enum LexMode {
L_NORMAL,
L_VCARD,
L_VCAL,
L_VEVENT,
L_VTODO,
L_VALUES,
L_BASE64,
L_QUOTED_PRINTABLE
};
/**** Private Forward Declarations ****/
static int pushVObject(const char *prop);
static VObject* popVObject();
static void lexPopMode(int top);
static int lexWithinMode(enum LexMode mode);
static void lexPushMode(enum LexMode mode);
static void enterProps(const char *s);
static void enterAttr(const char *s1, const char *s2);
static void enterValues(const char *value);
#define mime_error yyerror
void mime_error(char *s);
void mime_error_(char *s);
#line 189 "backend/vcc.y"
typedef union {
char *str;
VObject *vobj;
} YYSTYPE;
#line 225 "y.tab.c"
#define EQ 257
#define COLON 258
#define DOT 259
#define SEMICOLON 260
#define SPACE 261
#define HTAB 262
#define LINESEP 263
#define NEWLINE 264
#define BEGIN_VCARD 265
#define END_VCARD 266
#define BEGIN_VCAL 267
#define END_VCAL 268
#define BEGIN_VEVENT 269
#define END_VEVENT 270
#define BEGIN_VTODO 271
#define END_VTODO 272
#define ID 273
#define STRING 274
#define YYERRCODE 256
short vcclhs[] = { -1,
0, 6, 6, 5, 5, 8, 3, 9, 3, 7,
7, 13, 10, 10, 15, 11, 11, 14, 14, 16,
17, 17, 1, 18, 12, 12, 2, 2, 20, 4,
21, 4, 19, 19, 22, 22, 22, 25, 23, 26,
23, 27, 24, 28, 24,
};
short vcclen[] = { 2,
1, 2, 1, 1, 1, 0, 4, 0, 3, 2,
1, 0, 5, 1, 0, 3, 1, 2, 1, 2,
1, 3, 1, 0, 4, 1, 1, 0, 0, 4,
0, 3, 2, 1, 1, 1, 1, 0, 4, 0,
3, 0, 4, 0, 3,
};
@@ -650,202 +650,208 @@ static void lexSkipWhite() {
static char* lexGetWord() {
int c;
lexSkipWhite();
lexClearToken();
c = lexLookahead();
while (c != EOF && !strchr("\t\n ;:=",c)) {
lexAppendc(c);
lexSkipLookahead();
c = lexLookahead();
}
lexAppendc(0);
return lexStr();
}
static void lexPushLookaheadc(int c) {
int putptr;
/* can't putback EOF, because it never leaves lookahead buffer */
if (c == EOF) return;
putptr = (int)lexBuf.getPtr - 1;
if (putptr < 0) putptr += MAX_LEX_LOOKAHEAD;
lexBuf.getPtr = putptr;
lexBuf.buf[putptr] = c;
lexBuf.len += 1;
}
static char* lexLookaheadWord() {
/* this function can lookahead word with max size of MAX_LEX_LOOKAHEAD_0
/ and thing bigger than that will stop the lookahead and return 0;
/ leading white spaces are not recoverable.
*/
int c;
int len = 0;
int curgetptr = 0;
lexSkipWhite();
lexClearToken();
curgetptr = (int)lexBuf.getPtr; // remember!
while (len < (MAX_LEX_LOOKAHEAD_0)) {
c = lexGetc();
len++;
if (c == EOF || strchr("\t\n ;:=", c)) {
lexAppendc(0);
/* restore lookahead buf. */
lexBuf.len += len;
lexBuf.getPtr = curgetptr;
return lexStr();
}
else
lexAppendc(c);
}
lexBuf.len += len; /* char that has been moved to lookahead buffer */
lexBuf.getPtr = curgetptr;
return 0;
}
#ifdef _SUPPORT_LINE_FOLDING
static void handleMoreRFC822LineBreak(int c) {
/* suport RFC 822 line break in cases like
* ADR: foo;
* morefoo;
* more foo;
*/
if (c == ';') {
int a;
lexSkipLookahead();
/* skip white spaces */
a = lexLookahead();
while (a == ' ' || a == '\t') {
lexSkipLookahead();
a = lexLookahead();
}
if (a == '\n') {
lexSkipLookahead();
a = lexLookahead();
if (a == ' ' || a == '\t') {
/* continuation, throw away all the \n and spaces read so
* far
*/
lexSkipWhite();
lexPushLookaheadc(';');
}
else {
lexPushLookaheadc('\n');
lexPushLookaheadc(';');
}
}
else {
lexPushLookaheadc(';');
}
}
}
static char* lexGet1Value() {
int c;
lexSkipWhite();
c = lexLookahead();
lexClearToken();
- while (c != EOF && c != ';') {
+ while (c != EOF && (c != ';' || !fieldedProp)) {
if (c == '\\' ) {
int a;
lexSkipLookahead();
a = lexLookahead();
- if ( a != ';' ) {
- lexAppendc('\\');
- } else {
+ if ( a == ';' ) {
lexAppendc( ';' );
lexSkipLookahead();
+ } else if ( a == '\n' ) {
+ lexAppendc( '\n' );
+ lexSkipLookahead();
+ } else if ( a == '\\' ) {
+ lexAppendc( '\\' );
+ lexSkipLookahead();
+ } else {
+ lexAppendc('\\');
}
} else if (c == '\n') {
int a;
lexSkipLookahead();
a = lexLookahead();
if (a == ' ' || a == '\t') {
lexAppendc(' ');
lexSkipLookahead();
}
else {
lexPushLookaheadc('\n');
break;
}
}
else {
lexAppendc(c);
lexSkipLookahead();
}
c = lexLookahead();
}
lexAppendc(0);
handleMoreRFC822LineBreak(c);
return c==EOF?0:lexStr();
}
#endif
static int match_begin_name(int end) {
char *n = lexLookaheadWord();
int token = ID;
if (n) {
if (!qstricmp(n,"vcard")) token = end?END_VCARD:BEGIN_VCARD;
else if (!qstricmp(n,"vcalendar")) token = end?END_VCAL:BEGIN_VCAL;
else if (!qstricmp(n,"vevent")) token = end?END_VEVENT:BEGIN_VEVENT;
else if (!qstricmp(n,"vtodo")) token = end?END_VTODO:BEGIN_VTODO;
deleteStr(n);
return token;
}
return 0;
}
#ifdef INCLUDEMFC
void initLex(const char *inputstring, unsigned long inputlen, CFile *inputfile)
#else
void initLex(const char *inputstring, unsigned long inputlen, FILE *inputfile)
#endif
{
// initialize lex mode stack
lexBuf.lexModeStack[lexBuf.lexModeStackTop=0] = L_NORMAL;
// iniatialize lex buffer.
lexBuf.inputString = (char*) inputstring;
lexBuf.inputLen = inputlen;
lexBuf.curPos = 0;
lexBuf.inputFile = inputfile;
lexBuf.len = 0;
lexBuf.getPtr = 0;
lexBuf.maxToken = MAXTOKEN;
lexBuf.strs = (char*)malloc(MAXTOKEN);
lexBuf.strsLen = 0;
}
static void finiLex() {
free(lexBuf.strs);
}
/*-----------------------------------*/
/* This parses and converts the base64 format for binary encoding into
* a decoded buffer (allocated with new). See RFC 1521.
*/
static char * lexGetDataFromBase64()
{
unsigned long bytesLen = 0, bytesMax = 0;
int quadIx = 0, pad = 0;
unsigned long trip = 0;
unsigned char b;
int c;
unsigned char *bytes = NULL;
unsigned char *oldBytes = NULL;
DBG_(("db: lexGetDataFromBase64\n"));
while (1) {
c = lexGetc();
if (c == '\n') {
++mime_lineNum;
if (lexLookahead() == '\n') {
/* a '\n' character by itself means end of data */
break;
}
else continue; /* ignore '\n' */
}
else {
@@ -857,460 +863,473 @@ static char * lexGetDataFromBase64()
b = (unsigned char)(c - '0') + 52;
else if (c == '+')
b = 62;
else if (c == '/')
b = 63;
else if (c == '=') {
b = 0;
pad++;
} else if ((c == ' ') || (c == '\t')) {
continue;
} else { /* error condition */
if (bytes) free(bytes);
else if (oldBytes) free(oldBytes);
// error recovery: skip until 2 adjacent newlines.
DBG_(("db: invalid character 0x%x '%c'\n", c,c));
if (c != EOF) {
c = lexGetc();
while (c != EOF) {
if (c == '\n' && lexLookahead() == '\n') {
++mime_lineNum;
break;
}
c = lexGetc();
}
}
return NULL;
}
trip = (trip << 6) | b;
if (++quadIx == 4) {
unsigned char outBytes[3];
int numOut;
int i;
for (i = 0; i < 3; i++) {
outBytes[2-i] = (unsigned char)(trip & 0xFF);
trip >>= 8;
}
numOut = 3 - pad;
if (bytesLen + numOut > bytesMax) {
if (!bytes) {
bytesMax = 1024;
bytes = (unsigned char*)malloc((size_t)bytesMax);
}
else {
bytesMax <<= 2;
oldBytes = bytes;
bytes = (unsigned char*)realloc(bytes,(size_t)bytesMax);
}
if (bytes == 0) {
mime_error("out of memory while processing BASE64 data\n");
}
}
if (bytes) {
memcpy(bytes + bytesLen, outBytes, numOut);
bytesLen += numOut;
}
trip = 0;
quadIx = 0;
}
}
} /* while */
DBG_(("db: bytesLen = %d\n", bytesLen));
/* kludge: all this won't be necessary if we have tree form
representation */
if (bytes) {
setValueWithSize(curProp,bytes,(unsigned int)bytesLen);
free(bytes);
}
else if (oldBytes) {
setValueWithSize(curProp,oldBytes,(unsigned int)bytesLen);
free(oldBytes);
}
return 0;
}
static int match_begin_end_name(int end) {
int token;
lexSkipWhite();
if (lexLookahead() != ':') return ID;
lexSkipLookahead();
lexSkipWhite();
token = match_begin_name(end);
if (token == ID) {
lexPushLookaheadc(':');
DBG_(("db: ID '%s'\n", yylval.str));
return ID;
}
else if (token != 0) {
lexSkipLookaheadWord();
deleteStr(yylval.str);
DBG_(("db: begin/end %d\n", token));
return token;
}
return 0;
}
static char* lexGetQuotedPrintable()
- {
- int cur;
-
+{
+ int c;
+ lexSkipWhite();
+ c = lexLookahead();
lexClearToken();
- do {
- cur = lexGetc();
- switch (cur) {
- case '=': {
- int c = 0;
- int next[2];
- int i;
- for (i = 0; i < 2; i++) {
- next[i] = lexGetc();
- if (next[i] >= '0' && next[i] <= '9')
- c = c * 16 + next[i] - '0';
- else if (next[i] >= 'A' && next[i] <= 'F')
- c = c * 16 + next[i] - 'A' + 10;
- else
- break;
- }
- if (i == 0) {
- /* single '=' follow by LINESEP is continuation sign? */
- if (next[0] == '\n') {
- ++mime_lineNum;
- }
- else {
- lexPushLookaheadc('=');
- goto EndString;
- }
- }
- else if (i == 1) {
- lexPushLookaheadc(next[1]);
- lexPushLookaheadc(next[0]);
- lexAppendc('=');
- } else {
- lexAppendc(c);
- }
- break;
- } /* '=' */
- case '\n': {
- lexPushLookaheadc('\n');
- goto EndString;
- }
- case (int)EOF:
- break;
- default:
- lexAppendc(cur);
- break;
- } /* switch */
- } while (cur != (int)EOF);
-EndString:
+ while (c != EOF && c != ';') {
+ if (c == '\n') {
+ // break, leave '\n' on remaining chars.
+ break;
+ } else if (c == '=') {
+ int cur = 0;
+ int next;
+
+ lexSkipLookahead(); // skip '='
+ next = lexLookahead();
+
+ if (next == '\n') {
+ // skip and only skip the \n
+ lexSkipLookahead();
+ c = lexLookahead();
+ ++mime_lineNum; // aid in error reporting
+ continue;
+ } else if (next >= '0' && next <= '9') {
+ cur = next - '0';
+ } else if (next >= 'A' && next <= 'F') {
+ cur = next - 'A' + 10;
+ } else {
+ // we have been sent buggy stuff. doesn't matter
+ // what we do so long as we keep going.
+ // should probably spit an error here
+ lexSkipLookahead();
+ c = lexLookahead();
+ continue;
+ }
+
+ lexSkipLookahead(); // skip A-Z0-9
+ next = lexLookahead();
+
+ cur = cur * 16;
+ // this time really just expecting 0-9A-F
+ if (next >= '0' && next <= '9') {
+ cur += next - '0';
+ } else if (next >= 'A' && next <= 'F') {
+ cur += next - 'A' + 10;
+ } else {
+ // we have been sent buggy stuff. doesn't matter
+ // what we do so long as we keep going.
+ // should probably spit an error here
+ lexSkipLookahead();
+ c = lexLookahead();
+ continue;
+ }
+
+ // got a valid escaped =. append it.
+ lexSkipLookahead(); // skip second 0-9A-F
+ lexAppendc(cur);
+ } else {
+ lexSkipLookahead(); // skip whatever we just read.
+ lexAppendc(c); // and append it.
+ }
+ c = lexLookahead();
+ }
lexAppendc(0);
- return lexStr();
- } /* LexQuotedPrintable */
+ return c==EOF?0:lexStr();
+}
static int yylex() {
int lexmode = LEXMODE();
if (lexmode == L_VALUES) {
int c = lexGetc();
- if (c == ';') {
+ if (c == ';' && fieldedProp) {
DBG_(("db: SEMICOLON\n"));
lexPushLookaheadc(c);
handleMoreRFC822LineBreak(c);
lexSkipLookahead();
return SEMICOLON;
}
else if (strchr("\n",c)) {
++mime_lineNum;
/* consume all line separator(s) adjacent to each other */
c = lexLookahead();
while (strchr("\n",c)) {
lexSkipLookahead();
c = lexLookahead();
++mime_lineNum;
}
DBG_(("db: LINESEP\n"));
return LINESEP;
}
else {
char *p = 0;
lexPushLookaheadc(c);
if (lexWithinMode(L_BASE64)) {
/* get each char and convert to bin on the fly... */
p = lexGetDataFromBase64();
yylval.str = p;
return STRING;
}
else if (lexWithinMode(L_QUOTED_PRINTABLE)) {
p = lexGetQuotedPrintable();
}
else {
#ifdef _SUPPORT_LINE_FOLDING
p = lexGet1Value();
#else
p = lexGetStrUntil(";\n");
#endif
}
if (p) {
DBG_(("db: STRING: '%s'\n", p));
yylval.str = p;
return STRING;
}
else return 0;
}
}
else {
/* normal mode */
while (1) {
int c = lexGetc();
switch(c) {
case ':': {
/* consume all line separator(s) adjacent to each other */
/* ignoring linesep immediately after colon. */
+ /* I don't see this in the spec, and it breaks null values -- WA
c = lexLookahead();
while (strchr("\n",c)) {
lexSkipLookahead();
c = lexLookahead();
++mime_lineNum;
}
+ */
DBG_(("db: COLON\n"));
return COLON;
}
case ';':
DBG_(("db: SEMICOLON\n"));
return SEMICOLON;
case '=':
DBG_(("db: EQ\n"));
return EQ;
/* ignore whitespace in this mode */
case '\t':
case ' ': continue;
case '\n': {
++mime_lineNum;
continue;
}
case EOF: return 0;
break;
default: {
lexPushLookaheadc(c);
if (isalnum(c)) {
char *t = lexGetWord();
yylval.str = t;
if (!qstricmp(t, "begin")) {
return match_begin_end_name(0);
}
else if (!qstricmp(t,"end")) {
return match_begin_end_name(1);
}
else {
DBG_(("db: ID '%s'\n", t));
return ID;
}
}
else {
/* unknow token */
return 0;
}
break;
}
}
}
}
return 0;
}
/***************************************************************************/
/*** Public Functions ****/
/***************************************************************************/
static VObject* Parse_MIMEHelper()
{
ObjStackTop = -1;
mime_numErrors = 0;
mime_lineNum = 1;
vObjList = 0;
curObj = 0;
if (yyparse() != 0)
return 0;
finiLex();
return vObjList;
}
/*--------------------------------------------*/
DLLEXPORT(VObject*) Parse_MIME(const char *input, unsigned long len)
{
initLex(input, len, 0);
return Parse_MIMEHelper();
}
#if INCLUDEMFC
DLLEXPORT(VObject*) Parse_MIME_FromFile(CFile *file)
{
unsigned long startPos;
VObject *result;
initLex(0,-1,file);
startPos = file->GetPosition();
if (!(result = Parse_MIMEHelper()))
file->Seek(startPos, CFile::begin);
return result;
}
#else
VObject* Parse_MIME_FromFile(FILE *file)
{
VObject *result;
long startPos;
initLex(0,(unsigned long)-1,file);
startPos = ftell(file);
if (!(result = Parse_MIMEHelper())) {
fseek(file,startPos,SEEK_SET);
}
return result;
}
DLLEXPORT(VObject*) Parse_MIME_FromFileName(char *fname)
{
FILE *fp = fopen(fname,"r");
if (fp) {
VObject* o = Parse_MIME_FromFile(fp);
fclose(fp);
return o;
}
else {
char msg[80];
sprintf(msg, "can't open file '%s' for reading\n", fname);
mime_error_(msg);
return 0;
}
}
#endif
/*-------------------------------------*/
static MimeErrorHandler mimeErrorHandler;
DLLEXPORT(void) registerMimeErrorHandler(MimeErrorHandler me)
{
mimeErrorHandler = me;
}
void mime_error(char *s)
{
char msg[256];
if (mimeErrorHandler) {
sprintf(msg,"%s at line %d", s, mime_lineNum);
mimeErrorHandler(msg);
}
}
void mime_error_(char *s)
{
if (mimeErrorHandler) {
mimeErrorHandler(s);
}
}
-#line 1221 "y.tab.c"
+#line 1240 "y.tab.c"
#define YYABORT goto yyabort
#define YYREJECT goto yyabort
#define YYACCEPT goto yyaccept
#define YYERROR goto yyerrlab
int
#if defined(__STDC__)
yyparse(void)
#else
yyparse()
#endif
{
register int yym, yyn, yystate;
#if YYDEBUG
register char *yys;
extern char *getenv();
if (yys = getenv("YYDEBUG"))
{
yyn = *yys;
if (yyn >= '0' && yyn <= '9')
yydebug = yyn - '0';
}
#endif
yynerrs = 0;
yyerrflag = 0;
yychar = (-1);
yyssp = yyss;
yyvsp = yyvs;
*yyssp = yystate = 0;
yyloop:
if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
if (yychar < 0)
{
if ((yychar = yylex()) < 0) yychar = 0;
#if YYDEBUG
if (yydebug)
{
yys = 0;
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
if (!yys) yys = "illegal-symbol";
printf("%sdebug: state %d, reading %d (%s)\n",
YYPREFIX, yystate, yychar, yys);
}
#endif
}
if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
{
#if YYDEBUG
if (yydebug)
printf("%sdebug: state %d, shifting to state %d\n",
YYPREFIX, yystate, yytable[yyn]);
#endif
if (yyssp >= yyss + yystacksize - 1)
{
goto yyoverflow;
}
*++yyssp = yystate = yytable[yyn];
*++yyvsp = yylval;
yychar = (-1);
if (yyerrflag > 0) --yyerrflag;
goto yyloop;
}
if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
{
yyn = yytable[yyn];
goto yyreduce;
}
if (yyerrflag) goto yyinrecovery;
yyerror("syntax error");
#ifdef lint
goto yyerrlab;
#endif
yyerrlab:
++yynerrs;
yyinrecovery:
if (yyerrflag < 3)
{
yyerrflag = 3;
for (;;)
{
if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
{
#if YYDEBUG
if (yydebug)
printf("%sdebug: state %d, error recovery shifting\
to state %d\n", YYPREFIX, *yyssp, yytable[yyn]);
#endif
if (yyssp >= yyss + yystacksize - 1)
{
goto yyoverflow;
@@ -1424,153 +1443,153 @@ case 21:
#line 289 "backend/vcc.y"
{
enterAttr(yyvsp[0].str,0);
}
break;
case 22:
#line 293 "backend/vcc.y"
{
enterAttr(yyvsp[-2].str,yyvsp[0].str);
}
break;
case 24:
#line 302 "backend/vcc.y"
{ enterValues(yyvsp[-1].str); }
break;
case 26:
#line 304 "backend/vcc.y"
{ enterValues(yyvsp[0].str); }
break;
case 28:
#line 309 "backend/vcc.y"
{ yyval.str = 0; }
break;
case 29:
#line 314 "backend/vcc.y"
{ if (!pushVObject(VCCalProp)) YYERROR; }
break;
case 30:
#line 317 "backend/vcc.y"
{ yyval.vobj = popVObject(); }
break;
case 31:
#line 319 "backend/vcc.y"
{ if (!pushVObject(VCCalProp)) YYERROR; }
break;
case 32:
#line 321 "backend/vcc.y"
{ yyval.vobj = popVObject(); }
break;
case 38:
#line 336 "backend/vcc.y"
{
lexPushMode(L_VEVENT);
if (!pushVObject(VCEventProp)) YYERROR;
}
break;
case 39:
#line 342 "backend/vcc.y"
{
lexPopMode(0);
popVObject();
}
break;
case 40:
#line 347 "backend/vcc.y"
{
lexPushMode(L_VEVENT);
if (!pushVObject(VCEventProp)) YYERROR;
}
break;
case 41:
#line 352 "backend/vcc.y"
{
lexPopMode(0);
popVObject();
}
break;
case 42:
#line 360 "backend/vcc.y"
{
lexPushMode(L_VTODO);
if (!pushVObject(VCTodoProp)) YYERROR;
}
break;
case 43:
#line 366 "backend/vcc.y"
{
lexPopMode(0);
popVObject();
}
break;
case 44:
#line 371 "backend/vcc.y"
{
lexPushMode(L_VTODO);
if (!pushVObject(VCTodoProp)) YYERROR;
}
break;
case 45:
#line 376 "backend/vcc.y"
{
lexPopMode(0);
popVObject();
}
break;
-#line 1521 "y.tab.c"
+#line 1540 "y.tab.c"
}
yyssp -= yym;
yystate = *yyssp;
yyvsp -= yym;
yym = yylhs[yyn];
if (yystate == 0 && yym == 0)
{
#if YYDEBUG
if (yydebug)
printf("%sdebug: after reduction, shifting from state 0 to\
state %d\n", YYPREFIX, YYFINAL);
#endif
yystate = YYFINAL;
*++yyssp = YYFINAL;
*++yyvsp = yyval;
if (yychar < 0)
{
if ((yychar = yylex()) < 0) yychar = 0;
#if YYDEBUG
if (yydebug)
{
yys = 0;
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
if (!yys) yys = "illegal-symbol";
printf("%sdebug: state %d, reading %d (%s)\n",
YYPREFIX, YYFINAL, yychar, yys);
}
#endif
}
if (yychar == 0) goto yyaccept;
goto yyloop;
}
if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
yystate = yytable[yyn];
else
yystate = yydgoto[yym];
#if YYDEBUG
if (yydebug)
printf("%sdebug: after reduction, shifting from state %d \
to state %d\n", YYPREFIX, *yyssp, yystate);
#endif
if (yyssp >= yyss + yystacksize - 1)
{
goto yyoverflow;
}
*++yyssp = yystate;
*++yyvsp = yyval;
goto yyloop;
yyoverflow:
yyerror("yacc stack overflow");
yyabort:
return (1);
yyaccept:
return (0);
}
diff --git a/library/backend/vobject.cpp b/library/backend/vobject.cpp
index 2c5b577..b6d17dc 100644
--- a/library/backend/vobject.cpp
+++ b/library/backend/vobject.cpp
@@ -1,185 +1,190 @@
/***************************************************************************
-(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.
+(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
+ * 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 <qtopia/private/vobject_p.h>
-#include <qtopia/private/qfiledirect_p.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;
};
-const char** fieldedProp;
+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);
}
DLLEXPORT(void) setVObjectName(VObject *o, const char* id)
{
NAME_OF(o) = id;
}
DLLEXPORT(const char*) vObjectStringZValue(VObject *o)
{
return STRINGZ_VALUE_OF(o);
}
DLLEXPORT(void) setVObjectStringZValue(VObject *o, const char *s)
{
STRINGZ_VALUE_OF(o) = dupStr(s,0);
VALUE_TYPE(o) = VCVT_STRINGZ;
@@ -234,269 +239,269 @@ DLLEXPORT(void) setVObjectVObjectValue(VObject *o, VObject *p)
VOBJECT_VALUE_OF(o) = p;
VALUE_TYPE(o) = VCVT_VOBJECT;
}
DLLEXPORT(int) vObjectValueType(VObject *o)
{
return VALUE_TYPE(o);
}
/*----------------------------------------------------------------------
The following functions can be used to build VObject.
----------------------------------------------------------------------*/
DLLEXPORT(VObject*) addVObjectProp(VObject *o, VObject *p)
{
/* circular link list pointed to tail */
/*
o {next,id,prop,val}
V
pn {next,id,prop,val}
V
...
p1 {next,id,prop,val}
V
pn
-->
o {next,id,prop,val}
V
pn {next,id,prop,val}
V
p {next,id,prop,val}
...
p1 {next,id,prop,val}
V
pn
*/
VObject *tail = o->prop;
if (tail) {
p->next = tail->next;
o->prop = tail->next = p;
}
else {
o->prop = p->next = p;
}
return p;
}
DLLEXPORT(VObject*) addProp(VObject *o, const char *id)
{
return addVObjectProp(o,newVObject(id));
}
DLLEXPORT(VObject*) addProp_(VObject *o, const char *id)
{
return addVObjectProp(o,newVObject_(id));
}
DLLEXPORT(void) addList(VObject **o, VObject *p)
{
p->next = 0;
if (*o == 0) {
*o = p;
}
else {
VObject *t = *o;
while (t->next) {
t = t->next;
}
t->next = p;
}
}
DLLEXPORT(VObject*) nextVObjectInList(VObject *o)
{
return o->next;
}
DLLEXPORT(VObject*) setValueWithSize_(VObject *prop, void *val, unsigned int size)
{
VObject *sizeProp;
setVObjectAnyValue(prop, val);
sizeProp = addProp(prop,VCDataSizeProp);
setVObjectLongValue(sizeProp, size);
return prop;
}
DLLEXPORT(VObject*) setValueWithSize(VObject *prop, void *val, unsigned int size)
{
void *p = dupStr((const char *)val,size);
return setValueWithSize_(prop,p,p?size:0);
}
DLLEXPORT(void) initPropIterator(VObjectIterator *i, VObject *o)
{
- i->start = o->prop;
+ i->start = o->prop;
i->next = 0;
}
DLLEXPORT(void) initVObjectIterator(VObjectIterator *i, VObject *o)
{
- i->start = o->next;
+ i->start = o->next;
i->next = 0;
}
DLLEXPORT(int) moreIteration(VObjectIterator *i)
-{
+{
return (i->start && (i->next==0 || i->next!=i->start));
}
DLLEXPORT(VObject*) nextVObject(VObjectIterator *i)
{
if (i->start && i->next != i->start) {
if (i->next == 0) {
i->next = i->start->next;
return i->next;
}
else {
i->next = i->next->next;
return i->next;
}
}
else return (VObject*)0;
}
DLLEXPORT(VObject*) isAPropertyOf(VObject *o, const char *id)
{
VObjectIterator i;
initPropIterator(&i,o);
while (moreIteration(&i)) {
VObject *each = nextVObject(&i);
if (!qstricmp(id,each->id))
return each;
}
return (VObject*)0;
}
DLLEXPORT(VObject*) addGroup(VObject *o, const char *g)
{
/*
a.b.c
-->
prop(c)
prop(VCGrouping=b)
prop(VCGrouping=a)
*/
char *dot = strrchr(g,'.');
if (dot) {
VObject *p, *t;
char *gs, *n = dot+1;
gs = dupStr(g,0); /* so we can write to it. */
/* used to be
* t = p = addProp_(o,lookupProp_(n));
*/
t = p = addProp_(o,lookupProp(n));
dot = strrchr(gs,'.');
*dot = 0;
do {
dot = strrchr(gs,'.');
if (dot) {
n = dot+1;
*dot=0;
}
else
n = gs;
/* property(VCGroupingProp=n);
* and the value may have VCGrouping property
*/
t = addProp(t,VCGroupingProp);
setVObjectStringZValue(t,lookupProp_(n));
} while (n != gs);
- deleteStr(gs);
+ deleteStr(gs);
return p;
}
else
return addProp_(o,lookupProp(g));
}
DLLEXPORT(VObject*) addPropValue(VObject *o, const char *p, const char *v)
{
VObject *prop;
prop = addProp(o,p);
setVObjectStringZValue_(prop, strdup( v ) );
return prop;
}
DLLEXPORT(VObject*) addPropSizedValue_(VObject *o, const char *p, const char *v,
unsigned int size)
{
VObject *prop;
prop = addProp(o,p);
setValueWithSize_(prop, (void*)v, size);
return prop;
}
DLLEXPORT(VObject*) addPropSizedValue(VObject *o, const char *p, const char *v,
unsigned int size)
{
return addPropSizedValue_(o,p,dupStr(v,size),size);
}
DLLEXPORT(void) cleanVObject(VObject *o)
{
if (o == 0) return;
if (o->prop) {
/* destroy time: cannot use the iterator here.
Have to break the cycle in the circular link
list and turns it into regular NULL-terminated
list -- since at some point of destruction,
the reference entry for the iterator to work
will not longer be valid.
*/
VObject *p;
p = o->prop->next;
o->prop->next = 0;
do {
VObject *t = p->next;
cleanVObject(p);
p = t;
} while (p);
}
switch (VALUE_TYPE(o)) {
case VCVT_STRINGZ:
case VCVT_RAW:
// assume they are all allocated by malloc.
free((char*)STRINGZ_VALUE_OF(o));
break;
case VCVT_VOBJECT:
cleanVObject(VOBJECT_VALUE_OF(o));
break;
}
deleteVObject(o);
}
DLLEXPORT(void) cleanVObjects(VObject *list)
{
while (list) {
VObject *t = list;
list = nextVObjectInList(list);
cleanVObject(t);
}
}
/*----------------------------------------------------------------------
The following is a String Table Facilities.
----------------------------------------------------------------------*/
#define STRTBLSIZE 255
static StrItem *strTbl[STRTBLSIZE];
static unsigned int hashStr(const char *s)
{
unsigned int h = 0;
int i;
for (i=0;s[i];i++) {
h += s[i]*i;
}
return h % STRTBLSIZE;
}
DLLEXPORT(const char*) lookupStr(const char *s)
{
StrItem *t;
unsigned int h = hashStr(s);
if ((t = strTbl[h]) != 0) {
do {
@@ -706,641 +711,655 @@ static struct PreDefProp propNames[] = {
{ 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 },
{ 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;
}
}
static void appendcOFile(OFile *fp, char c)
{
if (fp->fail) return;
if (fp->fp) {
fputc(c,fp->fp);
}
else {
stuff:
if (fp->len+1 < fp->limit) {
fp->s[fp->len] = c;
fp->len++;
return;
}
else if (fp->alloc) {
fp->limit = fp->limit + OFILE_REALLOC_SIZE;
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;
}
}
#else
static void appendcOFile_(OFile *fp, char c)
{
if (fp->fail) return;
if (fp->fp) {
fputc(c,fp->fp);
}
else {
stuff:
if (fp->len+1 < fp->limit) {
fp->s[fp->len] = c;
fp->len++;
return;
}
else if (fp->alloc) {
fp->limit = fp->limit + OFILE_REALLOC_SIZE;
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;
}
}
static void appendcOFile(OFile *fp, char c)
{
if (c == '\n') {
/* write out as <CR><LF> */
appendcOFile_(fp,0xd);
appendcOFile_(fp,0xa);
}
else
appendcOFile_(fp,c);
}
static void appendsOFile(OFile *fp, const char *s)
{
int i, slen;
slen = strlen(s);
for (i=0; i<slen; i++) {
appendcOFile(fp,s[i]);
}
}
#endif
+static void appendsOFileEncCs(OFile *fp)
+{
+ if ( vobj_enc_s ) {
+ appendsOFile(fp, ";" VCEncodingProp "=");
+ appendsOFile(fp, vobj_enc_s);
+ }
+ appendsOFile(fp, ";" VCCharSetProp "=");
+ appendsOFile(fp, vobj_cs);
+}
+
+
static void initOFile(OFile *fp, FILE *ofp)
{
fp->fp = ofp;
fp->s = 0;
fp->len = 0;
fp->limit = 0;
fp->alloc = 0;
fp->fail = 0;
}
static int writeBase64(OFile *fp, unsigned char *s, long len)
{
long cur = 0;
int i, numQuads = 0;
unsigned long trip;
unsigned char b;
char quad[5];
#define MAXQUADS 16
quad[4] = 0;
while (cur < len) {
// collect the triplet of bytes into 'trip'
trip = 0;
for (i = 0; i < 3; i++) {
b = (cur < len) ? *(s + cur) : 0;
cur++;
trip = trip << 8 | b;
}
// fill in 'quad' with the appropriate four characters
for (i = 3; i >= 0; i--) {
b = (unsigned char)(trip & 0x3F);
trip = trip >> 6;
if ((3 - i) < (cur - len))
quad[i] = '='; // pad char
else if (b < 26) quad[i] = (char)b + 'A';
else if (b < 52) quad[i] = (char)(b - 26) + 'a';
else if (b < 62) quad[i] = (char)(b - 52) + '0';
else if (b == 62) quad[i] = '+';
else quad[i] = '/';
}
// now output 'quad' with appropriate whitespace and line ending
appendsOFile(fp, (numQuads == 0 ? " " : ""));
appendsOFile(fp, quad);
appendsOFile(fp, ((cur >= len)?"\n" :(numQuads==MAXQUADS-1?"\n" : "")));
numQuads = (numQuads + 1) % MAXQUADS;
}
appendcOFile(fp,'\n');
return 1;
}
-static const char *replaceChar(unsigned char c)
+static const char *qpReplaceChar(unsigned char c)
{
if (c == '\n') {
return "=0A=\n";
} else if (
- (c >= 'A' && c <= 'Z')
- ||
- (c >= 'a' && c <= 'z')
- ||
- (c >= '0' && c <= '9')
- ||
- (c >= '\'' && c <= ')')
- ||
- (c >= '+' && c <= '-')
- ||
- (c == '/')
- ||
- (c == '?')
+ // RFC 1521
+ (c >= 32 && c <= 60) // Note: " " not allowed at EOL
||
- (c == ' '))
- {
+ (c >= 62 && c <= 126)
+ )
+ {
return 0;
}
-#warning "Bug-Workaround must be fixed !"
- // IF THIS FUNCTION RETURNES TRUE, THE DATA IS EXPORTED
- // AS QUOTED PRINTABLE.
- // BUT THE PARSER IS UNABLE TO IMPORT THIS, THEREFORE
- // I DECIDED TO DISABLE IT UNTIL TROLLTECH FIXES THIS BUG
- // SEE ALSO includesUnprintable(VObject *o)
- // (se)
-
- return 0;
-
-#if 0
static char trans[4];
trans[0] = '=';
trans[3] = '\0';
int rem = c % 16;
int div = c / 16;
if (div < 10)
trans[1] = '0' + div;
else
trans[1] = 'A' + (div - 10);
if (rem < 10)
trans[2] = '0' + rem;
else
trans[2] = 'A' + (rem - 10);
return trans;
-#endif
}
-static void writeQPString(OFile *fp, const char *s)
+static void writeEncString(OFile *fp, const char *s, bool nosemi)
{
/*
- only A-Z, 0-9 and
+ only A-Z, 0-9 and
"'" (ASCII code 39)
"(" (ASCII code 40)
")" (ASCII code 41)
"+" (ASCII code 43)
"," (ASCII code 44)
"-" (ASCII code 45)
"/" (ASCII code 47)
"?" (ASCII code 63)
-
+
should remain un-encoded.
'=' needs to be encoded as it is the escape character.
';' needs to be as it is a field separator.
*/
const char *p = s;
- while (*p) {
- const char *rep = replaceChar(*p);
- if (rep)
- appendsOFile(fp, rep);
- else
- appendcOFile(fp, *p);
- p++;
+ switch ( vobj_enc ) {
+ case EightBit:
+ while (*p) {
+ if ( *p == '\n' || nosemi && ( *p == '\\' || *p == ';' ) )
+ appendcOFile(fp, '\\');
+ appendcOFile(fp, *p);
+ p++;
+ }
+ break;
+ case QuotedPrintable:
+ while (*p) {
+ const char *rep = qpReplaceChar(*p);
+ if (rep)
+ appendsOFile(fp, rep);
+ else if ( *p == ';' && nosemi )
+ appendsOFile(fp, "=3B");
+ else if ( *p == ' ' ) {
+ if ( !p[1] || p[1] == '\n' ) // RFC 1521
+ appendsOFile(fp, "=20");
+ else
+ appendcOFile(fp, *p);
+ } else
+ appendcOFile(fp, *p);
+ p++;
+ }
+ break;
+ case Base64:
+ writeBase64(fp, (unsigned char*)p, strlen(p));
+ break;
}
}
static bool includesUnprintable(VObject *o)
{
-
-#if 0
-
- // IF THIS FUNCTION RETURNES TRUE, THE DATA IS EXPORTED
- // AS QUOTED PRINTABLE.
- // BUT THE PARSER IS UNABLE TO IMPORT THIS, THEREFORE
- // I DECIDED TO DISABLE IT UNTIL TROLLTECH FIXES THIS BUG
- // SEE ALSO *replaceChar(unsigned char c)
- // (se)
-
if (o) {
if (VALUE_TYPE(o) == VCVT_STRINGZ) {
const char *p = STRINGZ_VALUE_OF(o);
if (p) {
while (*p) {
- if (replaceChar(*p))
+ if (*p==' ' && (!p[1] || p[1]=='\n') // RFC 1521: spaces at ends need quoting
+ || qpReplaceChar(*p) )
return TRUE;
p++;
}
}
}
}
-
-#endif
-#warning "Bug-Workaround must be fixed !"
-
return FALSE;
}
-
+
static void writeVObject_(OFile *fp, VObject *o);
-static void writeValue(OFile *fp, VObject *o, unsigned long size)
+static void writeValue(OFile *fp, VObject *o, unsigned long size, bool nosemi)
{
if (o == 0) return;
switch (VALUE_TYPE(o)) {
case VCVT_STRINGZ: {
- writeQPString(fp, STRINGZ_VALUE_OF(o));
+ writeEncString(fp, STRINGZ_VALUE_OF(o), nosemi);
break;
}
case VCVT_UINT: {
char buf[16];
sprintf(buf,"%u", INTEGER_VALUE_OF(o));
appendsOFile(fp,buf);
break;
}
case VCVT_ULONG: {
char buf[16];
sprintf(buf,"%lu", LONG_VALUE_OF(o));
appendsOFile(fp,buf);
break;
}
case VCVT_RAW: {
appendcOFile(fp,'\n');
writeBase64(fp,(unsigned char*)(ANY_VALUE_OF(o)),size);
break;
}
case VCVT_VOBJECT:
appendcOFile(fp,'\n');
writeVObject_(fp,VOBJECT_VALUE_OF(o));
break;
}
}
static void writeAttrValue(OFile *fp, VObject *o)
{
if (NAME_OF(o)) {
struct PreDefProp *pi;
pi = lookupPropInfo(NAME_OF(o));
if (pi && ((pi->flags & PD_INTERNAL) != 0)) return;
- if ( includesUnprintable(o) ) {
- appendsOFile(fp, ";" VCEncodingProp "=" VCQuotedPrintableProp);
- appendsOFile(fp, ";" VCCharSetProp "=" "UTF-8");
- }
+ if ( includesUnprintable(o) )
+ appendsOFileEncCs(fp);
appendcOFile(fp,';');
appendsOFile(fp,NAME_OF(o));
- }
- else
+ } else {
appendcOFile(fp,';');
+ }
if (VALUE_TYPE(o)) {
appendcOFile(fp,'=');
- writeValue(fp,o,0);
- }
+ writeValue(fp,o,0,TRUE);
+ }
}
static void writeGroup(OFile *fp, VObject *o)
{
char buf1[256];
char buf2[256];
strcpy(buf1,NAME_OF(o));
while ((o=isAPropertyOf(o,VCGroupingProp)) != 0) {
strcpy(buf2,STRINGZ_VALUE_OF(o));
strcat(buf2,".");
strcat(buf2,buf1);
strcpy(buf1,buf2);
}
appendsOFile(fp,buf1);
}
static int inList(const char **list, const char *s)
{
if (list == 0) return 0;
while (*list) {
if (qstricmp(*list,s) == 0) return 1;
list++;
}
return 0;
}
static void writeProp(OFile *fp, VObject *o)
{
if (NAME_OF(o)) {
struct PreDefProp *pi;
VObjectIterator t;
const char **fields_ = 0;
pi = lookupPropInfo(NAME_OF(o));
if (pi && ((pi->flags & PD_BEGIN) != 0)) {
writeVObject_(fp,o);
return;
}
if (isAPropertyOf(o,VCGroupingProp))
writeGroup(fp,o);
else
appendsOFile(fp,NAME_OF(o));
if (pi) fields_ = pi->fields;
initPropIterator(&t,o);
while (moreIteration(&t)) {
const char *s;
VObject *eachProp = nextVObject(&t);
s = NAME_OF(eachProp);
if (qstricmp(VCGroupingProp,s) && !inList(fields_,s))
writeAttrValue(fp,eachProp);
}
if (fields_) {
int i = 0, n = 0;
const char** fields = fields_;
/* output prop as fields */
bool printable = TRUE;
while (*fields && printable) {
VObject *t = isAPropertyOf(o,*fields);
if (includesUnprintable(t))
printable = FALSE;
fields++;
}
fields = fields_;
- if (!printable) {
- appendsOFile(fp, ";" VCEncodingProp "=" VCQuotedPrintableProp);
- appendsOFile(fp, ";" VCCharSetProp "=" "UTF-8");
- }
+ if (!printable)
+ appendsOFileEncCs(fp);
appendcOFile(fp,':');
while (*fields) {
VObject *t = isAPropertyOf(o,*fields);
i++;
if (t) n = i;
fields++;
}
fields = fields_;
for (i=0;i<n;i++) {
- writeValue(fp,isAPropertyOf(o,*fields),0);
+ writeValue(fp,isAPropertyOf(o,*fields),0,TRUE);
fields++;
if (i<(n-1)) appendcOFile(fp,';');
}
}
}
-
+
if (VALUE_TYPE(o)) {
- if ( includesUnprintable(o) ) {
- appendsOFile(fp, ";" VCEncodingProp "=" VCQuotedPrintableProp);
- appendsOFile(fp, ";" VCCharSetProp "=" "UTF-8");
- }
+ if ( includesUnprintable(o) )
+ appendsOFileEncCs(fp);
unsigned long size = 0;
VObject *p = isAPropertyOf(o,VCDataSizeProp);
if (p) size = LONG_VALUE_OF(p);
appendcOFile(fp,':');
- writeValue(fp,o,size);
+ writeValue(fp,o,size,FALSE);
}
appendcOFile(fp,'\n');
}
static void writeVObject_(OFile *fp, VObject *o)
{
if (NAME_OF(o)) {
struct PreDefProp *pi;
pi = lookupPropInfo(NAME_OF(o));
if (pi && ((pi->flags & PD_BEGIN) != 0)) {
VObjectIterator t;
const char *begin = NAME_OF(o);
appendsOFile(fp,"BEGIN:");
appendsOFile(fp,begin);
appendcOFile(fp,'\n');
initPropIterator(&t,o);
while (moreIteration(&t)) {
VObject *eachProp = nextVObject(&t);
writeProp(fp, eachProp);
}
appendsOFile(fp,"END:");
appendsOFile(fp,begin);
appendsOFile(fp,"\n\n");
}
}
}
+static void initVObjectEncoding()
+{
+ Config pimConfig( "Beam" );
+ pimConfig.setGroup("Send");
+ Config devcfg(pimConfig.readEntry("DeviceConfig"),Config::File);
+ QString enc = "QP";
+ QString cs = "UTF-8";
+ if ( devcfg.isValid() ) {
+ devcfg.setGroup("Send");
+ enc = devcfg.readEntry("Encoding","QP");
+ cs = devcfg.readEntry("CharSet","UTF-8");
+ }
+ strncpy(vobj_cs,cs.latin1(),10);
+ if ( enc == "QP" ) {
+ vobj_enc = QuotedPrintable;
+ vobj_enc_s = VCQuotedPrintableProp;
+ } else if ( enc == "B64" ) {
+ vobj_enc = Base64;
+ vobj_enc_s = VCBase64Prop;
+ } else {
+ vobj_enc = EightBit;
+ vobj_enc_s = 0;
+ }
+}
+
void writeVObject(FILE *fp, VObject *o)
{
+ initVObjectEncoding();
+
OFile ofp;
// #####
//_setmode(_fileno(fp), _O_BINARY);
initOFile(&ofp,fp);
writeVObject_(&ofp,o);
}
DLLEXPORT(void) writeVObjectToFile(char *fname, VObject *o)
{
QFileDirect f( fname);
if ( !f.open( IO_WriteOnly ) ) {
qWarning("Unable to open vobject write %s", fname);
return;
}
writeVObject( f.directHandle(),o );
}
DLLEXPORT(void) writeVObjectsToFile(char *fname, VObject *list)
{
QFileDirect f( fname);
if ( !f.open( IO_WriteOnly ) ) {
qWarning("Unable to open vobject write %s", fname);
return;
}
while (list) {
writeVObject(f.directHandle(),list);
list = nextVObjectInList(list);
}
}
-#ifndef __SHARP_COMP_
-
-// This function is not available in the Sharp ROM for SL 5500 !
-// Therefore I have to move it into the header file.. (se)
-
DLLEXPORT(const char *) vObjectTypeInfo(VObject *o)
{
const char *type = vObjectName( o );
if ( strcmp( type, "TYPE" ) == 0 )
type = vObjectStringZValue( o );
return type;
}
-#endif
+
// end of source file vobject.c
diff --git a/library/backend/vobject_p.h b/library/backend/vobject_p.h
index bab22bb..f969898 100644
--- a/library/backend/vobject_p.h
+++ b/library/backend/vobject_p.h
@@ -6,197 +6,201 @@ 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
*/
// No tr() anywhere in this file
#ifndef __VOBJECT_H__
#define __VOBJECT_H__ 1
#include <qstring.h>
#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"
#undef DLLEXPORT
+ //#include <qtopia/qpeglobal.h>
#include <qglobal.h>
-#if defined(Q_WS_WIN)
+
+#if defined(QTOPIA_MAKEDLL)
#define DLLEXPORT(t) __declspec(dllexport) t
+#elif defined(QTOPIA_DLL)
+#define DLLEXPORT(t) __declspec(dllimport) t
#else
-#define DLLEXPORT(t) t
+#define DLLEXPORT(t) t
#endif
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
#include <stdlib.h>
#include <stdio.h>
#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 "CHARSET"
#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"
@@ -258,164 +262,149 @@ For example:
#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"
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) 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(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(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(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_UINT 2
/* if the VObject has value set by setVObjectIntegerValue. */
#define VCVT_ULONG 3
/* if the VObject has value set by setVObjectLongValue. */
#define VCVT_RAW 4
/* if the VObject has value set by setVObjectAnyValue. */
#define VCVT_VOBJECT 5
/* if the VObject has value set by setVObjectVObjectValue. */
-extern const char** fieldedProp;
+extern DLLEXPORT(const char**) fieldedProp;
/***************************************************
* The methods below are implemented in vcc.c (generated from vcc.y )
***************************************************/
/* 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 writeVObject(FILE *fp, VObject *o);
+extern DLLEXPORT(void) writeVObject(FILE *fp, VObject *o);
typedef void (*MimeErrorHandler)(char *);
extern DLLEXPORT(void) registerMimeErrorHandler(MimeErrorHandler);
extern DLLEXPORT(VObject*) Parse_MIME(const char *input, unsigned long len);
extern DLLEXPORT(VObject*) Parse_MIME_FromFileName(char* fname);
/* NOTE regarding Parse_MIME_FromFile
The function above, Parse_MIME_FromFile, comes in two flavors,
neither of which is exported from the DLL. Each version takes
a CFile or FILE* as a parameter, neither of which can be
passed across a DLL interface (at least that is my experience).
If you are linking this code into your build directly then
you may find them a more convenient API that the other flavors
that take a file name. If you use them with the DLL LIB you
will get a link error.
*/
#if INCLUDEMFC
-extern VObject* Parse_MIME_FromFile(CFile *file);
+extern DLLEXPORT(VObject*) Parse_MIME_FromFile(CFile *file);
#else
-extern VObject* Parse_MIME_FromFile(FILE *file);
+extern DLLEXPORT(VObject*) Parse_MIME_FromFile(FILE *file);
#endif
-#define __SHARP_COMP_
-
-#ifndef __SHARP_COMP_
extern DLLEXPORT(const char *) vObjectTypeInfo(VObject *o);
-#else
-// This function is not available in the Sharp ROM for SL 5500 !
-// Therefore I have to move it into the header file.. (se)
-
-inline const char* vObjectTypeInfo(VObject *o)
-{
- const char *type = vObjectName( o );
- if ( strcmp( type, "TYPE" ) == 0 )
- type = vObjectStringZValue( o );
- return type;
-}
-#endif
#endif /* __VOBJECT_H__ */