]> code.citadel.org Git - citadel.git/commitdiff
* The vCard 'class' is now linked into the server, though it's not really
authorArt Cancro <ajc@citadel.org>
Thu, 23 Sep 1999 03:07:56 +0000 (03:07 +0000)
committerArt Cancro <ajc@citadel.org>
Thu, 23 Sep 1999 03:07:56 +0000 (03:07 +0000)
  functional yet.  Its constructors/destructors are debugged, though.

citadel/ChangeLog
citadel/Makefile.in
citadel/vcard.c
citadel/vcard.h [new file with mode: 0644]

index de6e5b56a864fc622abb79a273aec8449f9fe57d..f26a2b055965405856e0a6d30ee0123edcb9825d 100644 (file)
@@ -1,4 +1,8 @@
 $Log$
+Revision 1.369  1999/09/23 03:07:56  ajc
+* The vCard 'class' is now linked into the server, though it's not really
+  functional yet.  Its constructors/destructors are debugged, though.
+
 Revision 1.368  1999/09/19 21:28:33  ajc
 * Finished off the message architecture stuff with a new class of hooks to
   enable future server-side handlers.
@@ -1260,4 +1264,3 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
        * Initial CVS import 
-
index fee766b18599b8da96e944eae98f5ec42a0e8d31..a9f03400cba3fb2b7510d7618cf46f739eda80db 100644 (file)
@@ -68,7 +68,7 @@ SOURCES=aidepost.c citadel.c citmail.c citserver.c client_chat.c commands.c \
        serv_info.c serv_test.c setup.c snprintf.c stats.c \
        support.c sysdep.c tools.c user_ops.c userlist.c serv_expire.c \
        whobbs.c sendcommand.c mime_parser.c base64.c qpdecode.c getutline.c \
-       auth.c chkpwd.c client_icq.c html.c
+       auth.c chkpwd.c client_icq.c html.c vcard.c
 
 DEP_FILES=$(SOURCES:.c=.d)
 
@@ -104,7 +104,7 @@ netpoll: netpoll.o config.o ipc_c_tcp.o tools.o $(LIBOBJS)
 SERV_OBJS = citserver.ro user_ops.ro support.ro room_ops.ro file_ops.ro \
        msgbase.ro config.ro sysdep.ro locate_host.ro housekeeping.ro \
        database.ro control.ro logging.ro policy.ro dynloader.ro tools.ro \
-       mime_parser.ro html.ro $(AUTH) $(LIBOBJS:.o=.ro)
+       mime_parser.ro html.ro vcard.ro $(AUTH) $(LIBOBJS:.o=.ro)
 
 citserver: $(SERV_OBJS)
        $(CC) $(SERV_OBJS) $(LDFLAGS) $(SERVER_LDFLAGS) $(LIBS) $(NETLIBS) $(GDBM) -o citserver
index acdaafd9cde7c9bbaa190a435884bd8881629bf7..a241b1040984bdf59dd01b75b3b40205c1b7aa53 100644 (file)
@@ -9,28 +9,27 @@
  */
 
 
+#include "sysdep.h"
 #include <stdlib.h>
 #include <unistd.h>
 #include <stdio.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <time.h>
 #include <ctype.h>
 #include <string.h>
-
-#define CTDL_VCARD_MAGIC       0xa1f9
-
-/*
- * This data structure represents a vCard object currently in memory.
- */
-struct vCard {
-       int magic;
-       int numprops;
-       struct {
-               char *name;
-               char *value;
-       } *prop;
-};
-
-
-
+#include <errno.h>
+#include <limits.h>
+#include <pthread.h>
+#include <syslog.h>
+#include "citadel.h"
+#include "server.h"
+#include "control.h"
+#include "sysdep_decls.h"
+#include "support.h"
+#include "config.h"
+#include "tools.h"
+#include "vcard.h"
 
 /* 
  * Constructor (empty vCard)
@@ -38,7 +37,7 @@ struct vCard {
 struct vCard *new_vcard() {
        struct vCard *v;
 
-       v = (struct vCard *) malloc(sizeof(struct vCard));
+       v = (struct vCard *) mallok(sizeof(struct vCard));
        if (v == NULL) return v;
 
        v->magic = CTDL_VCARD_MAGIC;
@@ -49,6 +48,81 @@ struct vCard *new_vcard() {
 }
 
 
+/*
+ * Constructor (supply serialized vCard)
+ */
+struct vCard *load_vcard(char *vtext) {
+       struct vCard *v;
+       int valid = 0;
+       char *mycopy, *ptr;
+       char *namebuf, *valuebuf;
+       int i;
+       int colonpos, nlpos;
+
+       mycopy = strdoop(vtext);
+       if (mycopy == NULL) return NULL;
+
+       /* First, fix this big pile o' vCard to make it more parseable.
+        * To make it easier to parse, we convert CRLF to LF, and unfold any
+        * multi-line fields into single lines.
+        */
+       for (i=0; i<strlen(mycopy); ++i) {
+               if (!strncmp(&mycopy[i], "\r\n", 2)) {
+                       strcpy(&mycopy[i], &mycopy[i+1]);
+               }
+               if ( (mycopy[i]=='\n') && (isspace(mycopy[i+1])) ) {
+                       strcpy(&mycopy[i], &mycopy[i+1]);
+               }
+       }
+
+       v = new_vcard();
+       if (v == NULL) return v;
+
+       ptr = mycopy;
+       while (strlen(ptr)>0) {
+               colonpos = (-1);
+               nlpos = (-1);
+               colonpos = pattern2(ptr, ":");
+               nlpos = pattern2(ptr, "\n");
+
+               if (nlpos > colonpos > 0) {
+                       namebuf = mallok(colonpos + 1);
+                       valuebuf = mallok(nlpos - colonpos + 1);
+                       strncpy(namebuf, ptr, colonpos);
+                       namebuf[colonpos] = 0;
+                       strncpy(valuebuf, &ptr[colonpos+1], nlpos-colonpos-1);
+                       valuebuf[nlpos-colonpos-1] = 0;
+
+                       if ( (!strcasecmp(namebuf, "begin"))
+                          && (!strcasecmp(valuebuf, "vcard")) )  valid = 1;
+                       if ( (!strcasecmp(namebuf, "end"))
+                          && (!strcasecmp(valuebuf, "vcard")) )  valid = 0;
+
+                       if (valid) {
+                               ++v->numprops;
+                               v->prop = reallok(v->prop,
+                                       (v->numprops * sizeof(char *) * 2) );
+                               v->prop[v->numprops-1].name = namebuf;
+                               v->prop[v->numprops-1].value = valuebuf;
+                       }
+                       else {
+                               phree(namebuf);
+                               phree(valuebuf);
+                       }
+
+               }
+
+               while ( (*ptr != '\n') && (strlen(ptr)>0) ) {
+                       ++ptr;
+               }
+               if (*ptr == '\n') ++ptr;
+       }
+
+       phree(mycopy);
+       return v;
+}
+
+
 
 /*
  * Destructor
@@ -59,11 +133,11 @@ void free_vcard(struct vCard *v) {
        if (v->magic != CTDL_VCARD_MAGIC) return;       /* Self-check */
        
        if (v->numprops) for (i=0; i<(v->numprops); ++i) {
-               free(v->prop[i].name);
-               free(v->prop[i].value);
+               phree(v->prop[i].name);
+               phree(v->prop[i].value);
        }
 
-       if (v->prop != NULL) free(v->prop);
+       if (v->prop != NULL) phree(v->prop);
        
        memset(v, 0, sizeof(struct vCard));
 }
diff --git a/citadel/vcard.h b/citadel/vcard.h
new file mode 100644 (file)
index 0000000..f3713ca
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * $Id$
+ *
+ * vCard implementation for Citadel/UX
+ *
+ * Copyright (C) 1999 by Art Cancro
+ * This code is freely redistributable under the terms of the GNU General
+ * Public License.  All other rights reserved.
+ */
+
+
+#define CTDL_VCARD_MAGIC       0xa1f9
+
+/*
+ * This data structure represents a vCard object currently in memory.
+ */
+struct vCard {
+       int magic;
+       int numprops;
+       struct vCardProp {
+               char *name;
+               char *value;
+       } *prop;
+};
+
+
+struct vCard *new_vcard(void);
+struct vCard *load_vcard(char *);
+void free_vcard(struct vCard *);