]> code.citadel.org Git - citadel.git/blobdiff - webcit/vcard.c
* Header file adjustments to make it work on FreeBSD
[citadel.git] / webcit / vcard.c
index f11d253b707c933b5f32ecfbb8e5ad3dd73405a2..2198486a3edd1b5454e6ee34e25e95640c22b68a 100644 (file)
@@ -1,38 +1,43 @@
 /*
  * $Id$
  *
- * vCard implementation for Citadel/UX
+ * vCard data type implementation for Citadel/UX
  *
- * Copyright (C) 1999 by Art Cancro
+ * Copyright (C) 1999-2005 by Art Cancro
  * This code is freely redistributable under the terms of the GNU General
  * Public License.  All other rights reserved.
  */
 
-
+#include <ctype.h>
 #include <stdlib.h>
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
+#endif
 #include <stdio.h>
+#ifdef HAVE_FCNTL_H
 #include <fcntl.h>
+#endif
 #include <signal.h>
-
-#if TIME_WITH_SYS_TIME
-# include <sys/time.h>
-# include <time.h>
-#else
-# if HAVE_SYS_TIME_H
-#  include <sys/time.h>
-# else
-#  include <time.h>
-# endif
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/socket.h>
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
 #endif
-
-#include <ctype.h>
+#ifdef HAVE_LIMITS_H
+#include <limits.h>
+#endif
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
 #include <string.h>
+#include <pwd.h>
 #include <errno.h>
-#include <limits.h>
-#include <syslog.h>
-
+#include <stdarg.h>
+#include <pthread.h>
+#include <signal.h>
 #include "webcit.h"
+#include "webserver.h"
 #include "vcard.h"
 
 /* 
@@ -63,6 +68,7 @@ struct vCard *vcard_load(char *vtext) {
        int i;
        int colonpos, nlpos;
 
+       if (vtext == NULL) return vcard_new();
        mycopy = strdup(vtext);
        if (mycopy == NULL) return NULL;
 
@@ -97,15 +103,20 @@ struct vCard *vcard_load(char *vtext) {
                        strncpy(valuebuf, &ptr[colonpos+1], nlpos-colonpos-1);
                        valuebuf[nlpos-colonpos-1] = 0;
 
-                       if ( (!strcasecmp(namebuf, "end"))
-                          && (!strcasecmp(valuebuf, "vcard")) )  valid = 0;
-                       if ( (!strcasecmp(namebuf, "begin"))
-                          && (!strcasecmp(valuebuf, "vcard")) )  valid = 1;
+                       if (!strcasecmp(namebuf, "end")) {
+                               valid = 0;
+                       }
+                       if (    (!strcasecmp(namebuf, "begin"))
+                               && (!strcasecmp(valuebuf, "vcard"))
+                       ) {
+                               valid = 1;
+                       }
 
                        if ( (valid) && (strcasecmp(namebuf, "begin")) ) {
                                ++v->numprops;
                                v->prop = realloc(v->prop,
-                                       (v->numprops * sizeof(char *) * 2) );
+                                       (v->numprops * sizeof(struct vCardProp))
+                               );
                                v->prop[v->numprops-1].name = namebuf;
                                v->prop[v->numprops-1].value = valuebuf;
                        } 
@@ -208,7 +219,7 @@ void vcard_set_prop(struct vCard *v, char *name, char *value, int append) {
        /* Otherwise, append it */
        ++v->numprops;
        v->prop = realloc(v->prop,
-               (v->numprops * sizeof(char *) * 2) );
+               (v->numprops * sizeof(struct vCardProp)) );
        v->prop[v->numprops-1].name = strdup(name);
        v->prop[v->numprops-1].value = strdup(value);
 }
@@ -239,7 +250,7 @@ char *vcard_serialize(struct vCard *v)
        ser = malloc(len);
        if (ser == NULL) return NULL;
 
-       strcpy(ser, "begin:vcard\r\n");
+       safestrncpy(ser, "begin:vcard\r\n", len);
        if (v->numprops) for (i=0; i<(v->numprops); ++i) {
                strcat(ser, v->prop[i].name);
                strcat(ser, ":");