* "read my vCard" and "write my vCard" are written and tested.
authorArt Cancro <ajc@citadel.org>
Fri, 24 Sep 1999 03:32:19 +0000 (03:32 +0000)
committerArt Cancro <ajc@citadel.org>
Fri, 24 Sep 1999 03:32:19 +0000 (03:32 +0000)
citadel/ChangeLog
citadel/msgbase.c
citadel/msgbase.h
citadel/serv_vcard.c
citadel/server.h
citadel/vcard.c
citadel/vcard.h

index 7cac06ca0eaabaa2343494c358c884a1705a7202..2ba0368a60dce47cd23a236199d60df4d8d7e62b 100644 (file)
@@ -1,4 +1,7 @@
 $Log$
+Revision 1.371  1999/09/24 03:32:19  ajc
+* "read my vCard" and "write my vCard" are written and tested.
+
 Revision 1.370  1999/09/24 02:54:17  ajc
 * Worked a little more on the vCard stuff.  The serv_vcard module is now in
   place, and a "read my vcard" function is there; "write my" is next...
@@ -1268,4 +1271,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 b6255c01b859f450db838976d7880fa85310bf1b..3d1a07d66e0a775cea9e1196093c74af1a18229b 100644 (file)
@@ -919,7 +919,7 @@ void cmd_msg3(char *cmdbuf)
 {
        long msgnum;
        struct CtdlMessage *msg;
-       struct sermsgret smr;
+       struct ser_ret smr;
 
        if (CC->internal_pgm == 0) {
                cprintf("%d This command is for internal programs only.\n",
@@ -993,7 +993,7 @@ long send_message(struct CtdlMessage *msg,  /* pointer to buffer */
        long newmsgid;
        long retval;
        char msgidbuf[32];
-        struct sermsgret smr;
+        struct ser_ret smr;
 
        /* Get a new message number */
        newmsgid = get_new_message_number();
@@ -1043,11 +1043,11 @@ long send_message(struct CtdlMessage *msg,      /* pointer to buffer */
 /*
  * Serialize a struct CtdlMessage into the format used on disk and network.
  * 
- * This function returns a "struct sermsgret" (defined in msgbase.h) which
+ * This function loads up a "struct ser_ret" (defined in server.h) which
  * contains the length of the serialized message and a pointer to the
  * serialized message in memory.  THE LATTER MUST BE FREED BY THE CALLER.
  */
-void serialize_message(struct sermsgret *ret,          /* return values */
+void serialize_message(struct ser_ret *ret,            /* return values */
                        struct CtdlMessage *msg)        /* unserialized msg */
 {
        size_t wlen;
index 3eaf237e3979ad147718c2cfa433b5fda6b200bf..cac60f9bb9868dc5e0f5a970f3bf899a2e38446c 100644 (file)
@@ -2,11 +2,6 @@
 
 #define aide_message(text)      quickie_message("Citadel",NULL,AIDEROOM,text)
 
-struct sermsgret {
-       size_t len;
-       char *ser;
-};
-
 #define MSGS_ALL        0
 #define MSGS_OLD        1
 #define MSGS_NEW        2
@@ -58,5 +53,5 @@ int CtdlDeleteMessages(char *, long, char *);
 void CtdlWriteObject(char *, char *, char *, int, int, int);
 struct CtdlMessage *CtdlFetchMessage(long msgnum);
 void CtdlFreeMessage(struct CtdlMessage *msg);
-void serialize_message(struct sermsgret *, struct CtdlMessage *);
+void serialize_message(struct ser_ret *, struct CtdlMessage *);
 int is_valid_message(struct CtdlMessage *);
index 889bbdbb050becea46bf3508d9d612624a2f7b9e..650f1304f592f0c3293723ac2a6e15a542e98ffc 100644 (file)
@@ -134,10 +134,17 @@ void vcard_write_my(struct vCard *v) {
        char *ser;
 
         strcpy(temp, tmpnam(NULL));
+       ser = serialize_vcard(v);
 
         fp = fopen(temp, "w");
         if (fp == NULL) return;
-       fwrite("FIXFIXFIXFIX FIX FIX", 100, 1, fp);
+       fprintf(fp, "Content-type: text/x-vcard\r\n\r\n");
+       if (ser == NULL) {
+               fprintf(fp, "begin:vcard\r\nend:vcard\r\n");
+       } else {
+               fwrite(ser, strlen(ser), 1, fp);
+               phree(ser);
+       }
         fclose(fp);
 
         /* this handy API function does all the work for us */
index a538b3611b3162865d5fd453aff6b2b18079259e..f12c23fcafcff0373125b5ea81f359e47d2e88e1 100644 (file)
@@ -354,6 +354,15 @@ extern struct TheHeap *heap;
 #endif
 
 
+/* 
+ * Serialization routines use this struct to return a pointer and a length
+ */
+struct ser_ret {
+        size_t len;
+        char *ser;
+};
+
+
 /*
  * New format for a message in memory
  */
index eb9030422708eed6ac993b72fe921dae3cf4ce4f..8cf2d2d8c0b0c94cbab643c4d93641a808f777ee 100644 (file)
@@ -169,3 +169,41 @@ void set_prop(struct vCard *v, char *name, char *value) {
        v->prop[v->numprops-1].name = strdoop(name);
        v->prop[v->numprops-1].value = (value);
 }
+
+
+
+
+/*
+ * Serialize a struct vcard into a standard text/x-vcard MIME type.
+ *
+ */
+char *serialize_vcard(struct vCard *v)
+{
+       char *ser;
+       int i;
+       size_t len;
+
+       if (v->magic != CTDL_VCARD_MAGIC) return NULL;  /* self check */
+
+       /* Figure out how big a buffer we need to allocate */
+       len = 64;       /* for begin, end, and a little padding for safety */
+       if (v->numprops) for (i=0; i<(v->numprops); ++i) {
+               len = len +
+                       strlen(v->prop[i].name) +
+                       strlen(v->prop[i].value) + 4;
+       }
+
+       ser = mallok(len);
+       if (ser == NULL) return NULL;
+
+       strcpy(ser, "begin:vcard\r\n");
+       if (v->numprops) for (i=0; i<(v->numprops); ++i) {
+               strcat(ser, v->prop[i].name);
+               strcat(ser, ":");
+               strcat(ser, v->prop[i].name);
+               strcat(ser, "\r\n");
+       }
+       strcat(ser, "end:vcard\r\n");
+
+       return ser;
+}
index 035e5caa637640c5d795e2c8d3dc37e4eccfd388..6e6260e274420d283a8b6f822cec2721a37734c2 100644 (file)
@@ -28,3 +28,4 @@ struct vCard *new_vcard(void);
 struct vCard *load_vcard(char *);
 void free_vcard(struct vCard *);
 void set_prop(struct vCard *v, char *name, char *value);
+char *serialize_vcard(struct vCard *);