]> code.citadel.org Git - citadel.git/blobdiff - citadel/serv_vcard.c
* Buffered output needs to be flushed in several places. Added calls to
[citadel.git] / citadel / serv_vcard.c
index f7487e4030d1a1d2b22545bbe4f23363e2fa43f6..af22b3fda2f44a4997dd47c76d42bb37cfaa54d6 100644 (file)
@@ -169,7 +169,7 @@ void vcard_directory_add_user(char *internet_addr, char *citadel_addr) {
 void vcard_add_to_directory(long msgnum, void *data) {
        struct CtdlMessage *msg;
 
-       msg = CtdlFetchMessage(msgnum);
+       msg = CtdlFetchMessage(msgnum, 1);
        if (msg != NULL) {
                vcard_extract_internet_addresses(msg, vcard_directory_add_user);
        }
@@ -262,6 +262,9 @@ int vcard_upload_beforesave(struct CtdlMessage *msg) {
        char buf[SIZ];
        struct ctdluser usbuf;
        long what_user;
+       struct vCard *v = NULL;
+       char *ser = NULL;
+       int i = 0;
 
        if (!CC->logged_in) return(0);  /* Only do this if logged in. */
 
@@ -331,6 +334,34 @@ int vcard_upload_beforesave(struct CtdlMessage *msg) {
                                 msg->cm_fields['A'], NODENAME);
                         msg->cm_fields['E'] = strdup(buf);
 
+                       /* Insert or replace RFC2739-compliant free/busy URL */
+                       v = vcard_load(msg->cm_fields['M']);
+                       if (v != NULL) {
+
+                               /* Manipulate the vCard data structure */
+                               sprintf(buf, "http://%s/%s.vfb",
+                                       config.c_fqdn,
+                                       usbuf.fullname);
+                               for (i=0; i<strlen(buf); ++i) {
+                                       if (buf[i] == ' ') buf[i] = '_';
+                               }
+                               vcard_set_prop(v, "FBURL;PREF", buf, 0);
+
+                               /* Re-serialize it back into the msg body */
+                               ser = vcard_serialize(v);
+                               if (ser != NULL) {
+                                       msg->cm_fields['M'] = realloc(
+                                               msg->cm_fields['M'],
+                                               strlen(ser) + 1024
+                                       );
+                                       sprintf(msg->cm_fields['M'],
+                                               "Content-type: text/x-vcard"
+                                               "\r\n\r\n%s\r\n", ser);
+                                       free(ser);
+                               }
+                               vcard_free(v);
+                       }
+
                        /* Now allow the save to complete. */
                        return(0);
                }
@@ -380,6 +411,11 @@ int vcard_upload_aftersave(struct CtdlMessage *msg) {
                        I = atol(msg->cm_fields['I']);
                        if (I < 0L) return(0);
 
+                       /* Store our Internet return address in memory */
+                       v = vcard_load(msg->cm_fields['M']);
+                       vcard_populate_cs_inet_email(v);
+                       vcard_free(v);
+
                        /* Put it in the Global Address Book room... */
                        CtdlSaveMsgPointerInRoom(ADDRESS_BOOK_ROOM, I,
                                (SM_VERIFY_GOODNESS | SM_DO_REPL_CHECK) );
@@ -387,11 +423,6 @@ int vcard_upload_aftersave(struct CtdlMessage *msg) {
                        /* ...and also in the directory database. */
                        vcard_add_to_directory(I, NULL);
 
-                       /* Store our Internet return address in memory */
-                       v = vcard_load(msg->cm_fields['M']);
-                       vcard_populate_cs_inet_email(v);
-                       vcard_free(v);
-
                        /* Some sites want an Aide to be notified when a
                         * user registers or re-registers...
                         */
@@ -448,7 +479,7 @@ struct vCard *vcard_get_user(struct ctdluser *u) {
 
        if (VC->msgnum < 0L) return vcard_new();
 
-       msg = CtdlFetchMessage(VC->msgnum);
+       msg = CtdlFetchMessage(VC->msgnum, 1);
        if (msg == NULL) return vcard_new();
 
        v = vcard_load(msg->cm_fields['M']);
@@ -530,6 +561,7 @@ void cmd_regi(char *argbuf) {
        strcpy(tmpcountry, "USA");
 
        cprintf("%d Send registration...\n", SEND_LISTING);
+       flush_output();
        a=0;
        while (client_gets(buf), strcmp(buf,"000")) {
                if (a==0) vcard_set_prop(my_vcard, "n", buf, 0);
@@ -702,6 +734,7 @@ void vcard_newuser(struct ctdluser *usbuf) {
        }
        vcard_add_prop(v, "fn", usbuf->fullname);
        vcard_add_prop(v, "n", vname);
+       vcard_add_prop(v, "adr", "adr:;;_;_;_;00000;__");
        vcard_add_prop(v, "email;internet", buf);
        vcard_write_user(usbuf, v);
        vcard_free(v);
@@ -793,7 +826,7 @@ void vcard_delete_remove(char *room, long msgnum) {
                return;
        }
 
-       msg = CtdlFetchMessage(msgnum);
+       msg = CtdlFetchMessage(msgnum, 1);
        if (msg == NULL) return;
 
        ptr = msg->cm_fields['M'];