]> code.citadel.org Git - citadel.git/commitdiff
* Worked a little more on the vCard stuff. The serv_vcard module is now in
authorArt Cancro <ajc@citadel.org>
Fri, 24 Sep 1999 02:54:18 +0000 (02:54 +0000)
committerArt Cancro <ajc@citadel.org>
Fri, 24 Sep 1999 02:54:18 +0000 (02:54 +0000)
  place, and a "read my vcard" function is there; "write my" is next...

citadel/ChangeLog
citadel/citadel.h
citadel/serv_vcard.c
citadel/vcard.c
citadel/vcard.h

index f26a2b055965405856e0a6d30ee0123edcb9825d..7cac06ca0eaabaa2343494c358c884a1705a7202 100644 (file)
@@ -1,4 +1,8 @@
 $Log$
+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...
+
 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.
@@ -1264,3 +1268,4 @@ 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 8a8ffd3d3726a4e2d4adb4c78730a8d1962ff9b9..1f8f4ebb99bc95aff5b5685b16e98b902407b43a 100644 (file)
@@ -245,6 +245,7 @@ struct floor {
 #define BASEROOM       "Lobby"
 #define MAILROOM       "Mail"
 #define AIDEROOM       "Aide"
+#define CONFIGROOM     "My Citadel Config"
 
 
 /*
index 84a37260ef73ed8599579f4834d03f3756404b30..889bbdbb050becea46bf3508d9d612624a2f7b9e 100644 (file)
 #include "config.h"
 #include "dynloader.h"
 #include "room_ops.h"
+#include "user_ops.h"
 #include "policy.h"
 #include "database.h"
 #include "msgbase.h"
+#include "vcard.h"
+
+struct vcard_internal_info {
+       long msgnum;
+};
+
+/* Message number symbol used internally by these functions */
+unsigned long SYM_VCARD;
+#define VC ((struct vcard_internal_info *)CtdlGetUserData(SYM_VCARD))
+
+
+/*
+ * This handler detects whether the user is attempting to save a new
+ * vCard as part of his/her personal configuration, and handles the replace
+ * function accordingly.
+ */
+int vcard_personal_upload(struct CtdlMessage *msg) {
+       char *ptr;
+       int linelen;
+
+       /* If this isn't the configuration room, or if this isn't a MIME
+        * message, don't bother.
+        */
+       if (strcasecmp(msg->cm_fields['O'], CONFIGROOM)) return(0);
+       if (msg->cm_format_type != 4) return(0);
+
+       ptr = msg->cm_fields['M'];
+       while (ptr != NULL) {
+       
+               linelen = strcspn(ptr, "\n");
+               lprintf(9, "linelen == %d\n", linelen);
+               if (linelen == 0) return(0);    /* end of headers */    
+               
+               if (!strncasecmp(ptr, "Content-type: text/x-vcard", 26)) {
+                       /* Bingo!  The user is uploading a new vCard, so
+                        * delete the old one.
+                        */
+                       CtdlDeleteMessages(msg->cm_fields['O'],
+                                       0L, "text/x-vcard");
+                       return(0);
+               }
+
+               ptr = strchr((char *)ptr, '\n');
+               if (ptr != NULL) ++ptr;
+       }
+
+       return(0);
+}
+
+
+
+/*
+ * back end function used by vcard_get_my()
+ */
+void vcard_gm_backend(long msgnum) {
+       VC->msgnum = msgnum;
+}
+
+
+/*
+ * If this user has a vcard on disk, read it into memory, otherwise allocate
+ * and return an empty vCard.
+ */
+struct vCard *vcard_get_my(void) {
+        char hold_rm[ROOMNAMELEN];
+        char config_rm[ROOMNAMELEN];
+       struct CtdlMessage *msg;
+       struct vCard *v;
+
+        strcpy(hold_rm, CC->quickroom.QRname); /* save current room */
+        MailboxName(config_rm, &CC->usersupp, CONFIGROOM);
+
+        if (getroom(&CC->quickroom, config_rm) != 0) {
+                getroom(&CC->quickroom, hold_rm);
+                return new_vcard();
+        }
+
+        /* We want the last (and probably only) vcard in this room */
+       VC->msgnum = (-1);
+        CtdlForEachMessage(MSGS_LAST, 1, "text/x-vcard", vcard_gm_backend);
+        getroom(&CC->quickroom, hold_rm);      /* return to saved room */
+
+       if (VC->msgnum < 0L) return new_vcard();
+
+       msg = CtdlFetchMessage(VC->msgnum);
+       if (msg == NULL) return new_vcard();
+
+       v = load_vcard(msg->cm_fields['M']);
+       CtdlFreeMessage(msg);
+       return v;
+}
+
+
+/*
+ * Store this user's vCard in the appropriate place
+ */
+/*
+ * Write our config to disk
+ */
+void vcard_write_my(struct vCard *v) {
+        char temp[PATH_MAX];
+        FILE *fp;
+       char *ser;
+
+        strcpy(temp, tmpnam(NULL));
+
+        fp = fopen(temp, "w");
+        if (fp == NULL) return;
+       fwrite("FIXFIXFIXFIX FIX FIX", 100, 1, fp);
+        fclose(fp);
+
+        /* this handy API function does all the work for us */
+        CtdlWriteObject(CONFIGROOM, "text/x-vcard", temp, 1, 0, 1);
+
+        unlink(temp);
+}
+
+
+
 
 char *Dynamic_Module_Init(void)
 {
-   return "$Id$";
+       CtdlAllocUserData(SYM_VCARD, sizeof(struct vcard_internal_info));
+       CtdlRegisterMessageHook(vcard_personal_upload, EVT_BEFORESAVE);
+       return "$Id$";
 }
index a241b1040984bdf59dd01b75b3b40205c1b7aa53..eb9030422708eed6ac993b72fe921dae3cf4ce4f 100644 (file)
@@ -141,3 +141,31 @@ void free_vcard(struct vCard *v) {
        
        memset(v, 0, sizeof(struct vCard));
 }
+
+
+/*
+ * Set a name/value pair in the card
+ */
+void set_prop(struct vCard *v, char *name, char *value) {
+       int i;
+
+       if (v->magic != CTDL_VCARD_MAGIC) return;       /* Self-check */
+
+       /* If this key is already present, replace it */
+       if (v->numprops) for (i=0; i<(v->numprops); ++i) {
+               if (!strcasecmp(v->prop[i].name, name)) {
+                       phree(v->prop[i].name);
+                       phree(v->prop[i].value);
+                       v->prop[i].name = strdoop(name);
+                       v->prop[i].value = strdoop(value);
+                       return;
+               }
+       }
+
+       /* Otherwise, append it */
+       ++v->numprops;
+       v->prop = reallok(v->prop,
+               (v->numprops * sizeof(char *) * 2) );
+       v->prop[v->numprops-1].name = strdoop(name);
+       v->prop[v->numprops-1].value = (value);
+}
index f3713ca9988d4499833bb7f19d22477190324009..035e5caa637640c5d795e2c8d3dc37e4eccfd388 100644 (file)
@@ -27,3 +27,4 @@ struct vCard {
 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);