]> code.citadel.org Git - citadel.git/blobdiff - citadel/serv_vcard.c
* extract_token() now expects to be supplied with the size of the
[citadel.git] / citadel / serv_vcard.c
index 49cae5ea888bf379342c3f0d2483d70c38d8ed52..d1f747e69cc97909eb046667dae76b4b99cf2fe8 100644 (file)
 #include "vcard.h"
 #include "serv_ldap.h"
 
-struct vcard_internal_info {
-       long msgnum;
-};
-
-/* Message number symbol used internally by these functions */
-#define VC ((struct vcard_internal_info *)CtdlGetUserData(SYM_VCARD))
-
-
 /*
  * set global flag calling for an aide to validate new users
  */
@@ -374,9 +366,18 @@ int vcard_upload_beforesave(struct CtdlMessage *msg) {
                                        vcard_set_prop(v, "UID", buf, 0);
                                }
 
-                               /* Set the EUID of the message to the UID of the vCard */
+                               /* 
+                                * Set the EUID of the message to the UID of the vCard.
+                                * Also set the Subject if there isn't already one.
+                                */
                                if (msg->cm_fields['E'] != NULL) free(msg->cm_fields['E']);
-                               msg->cm_fields['E'] = strdup(buf);
+                               s = vcard_get_prop(v, "UID", 0, 0, 0);
+                               if (s != NULL) {
+                                       msg->cm_fields['E'] = strdup(s);
+                                       if (msg->cm_fields['U'] == NULL) {
+                                               msg->cm_fields['U'] = strdup(s);
+                                       }
+                               }
 
                                /* Re-serialize it back into the msg body */
                                ser = vcard_serialize(v);
@@ -479,8 +480,11 @@ int vcard_upload_aftersave(struct CtdlMessage *msg) {
 /*
  * back end function used for callbacks
  */
-void vcard_gu_backend(long msgnum, void *userdata) {
-       VC->msgnum = msgnum;
+void vcard_gu_backend(long supplied_msgnum, void *userdata) {
+       long *msgnum;
+
+       msgnum = (long *) userdata;
+       *msgnum = supplied_msgnum;
 }
 
 
@@ -493,6 +497,7 @@ struct vCard *vcard_get_user(struct ctdluser *u) {
         char config_rm[ROOMNAMELEN];
        struct CtdlMessage *msg;
        struct vCard *v;
+       long VCmsgnum;
 
         strcpy(hold_rm, CC->room.QRname);      /* save current room */
         MailboxName(config_rm, sizeof config_rm, u, USERCONFIGROOM);
@@ -503,14 +508,14 @@ struct vCard *vcard_get_user(struct ctdluser *u) {
         }
 
         /* We want the last (and probably only) vcard in this room */
-       VC->msgnum = (-1);
+       VCmsgnum = (-1);
         CtdlForEachMessage(MSGS_LAST, 1, "text/x-vcard",
-               NULL, vcard_gu_backend, NULL);
+               NULL, vcard_gu_backend, (void *)&VCmsgnum );
         getroom(&CC->room, hold_rm);   /* return to saved room */
 
-       if (VC->msgnum < 0L) return vcard_new();
+       if (VCmsgnum < 0L) return vcard_new();
 
-       msg = CtdlFetchMessage(VC->msgnum, 1);
+       msg = CtdlFetchMessage(VCmsgnum, 1);
        if (msg == NULL) return vcard_new();
 
        v = vcard_load(msg->cm_fields['M']);
@@ -595,7 +600,7 @@ void cmd_regi(char *argbuf) {
 
        cprintf("%d Send registration...\n", SEND_LISTING);
        a=0;
-       while (client_gets(buf), strcmp(buf,"000")) {
+       while (client_getln(buf, sizeof buf), strcmp(buf,"000")) {
                if (a==0) vcard_set_prop(my_vcard, "n", buf, 0);
                if (a==1) strcpy(tmpaddr, buf);
                if (a==2) strcpy(tmpcity, buf);
@@ -631,11 +636,11 @@ void cmd_greg(char *argbuf)
        struct ctdluser usbuf;
        struct vCard *v;
        char *s;
-       char who[SIZ];
-       char adr[SIZ];
-       char buf[SIZ];
+       char who[USERNAME_SIZE];
+       char adr[256];
+       char buf[256];
 
-       extract(who, argbuf, 0);
+       extract_token(who, argbuf, 0, '|', sizeof who);
 
        if (!(CC->logged_in)) {
                cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
@@ -666,13 +671,13 @@ void cmd_greg(char *argbuf)
        s = vcard_get_prop(v, "adr", 0, 0, 0);
        snprintf(adr, sizeof adr, "%s", s ? s : " ");/* address... */
 
-       extract_token(buf, adr, 2, ';');
+       extract_token(buf, adr, 2, ';', sizeof buf);
        cprintf("%s\n", buf);                           /* street */
-       extract_token(buf, adr, 3, ';');
+       extract_token(buf, adr, 3, ';', sizeof buf);
        cprintf("%s\n", buf);                           /* city */
-       extract_token(buf, adr, 4, ';');
+       extract_token(buf, adr, 4, ';', sizeof buf);
        cprintf("%s\n", buf);                           /* state */
-       extract_token(buf, adr, 5, ';');
+       extract_token(buf, adr, 5, ';', sizeof buf);
        cprintf("%s\n", buf);                           /* zip */
 
        s = vcard_get_prop(v, "tel;home", 0, 0, 0);
@@ -691,7 +696,7 @@ void cmd_greg(char *argbuf)
        s = vcard_get_prop(v, "adr", 0, 0, 0);
        snprintf(adr, sizeof adr, "%s", s ? s : " ");/* address... */
 
-       extract_token(buf, adr, 6, ';');
+       extract_token(buf, adr, 6, ';', sizeof buf);
        cprintf("%s\n", buf);                           /* country */
        cprintf("000\n");
 }
@@ -701,14 +706,14 @@ void cmd_greg(char *argbuf)
  * When a user is being created, create his/her vCard.
  */
 void vcard_newuser(struct ctdluser *usbuf) {
-       char buf[SIZ];
-       char vname[SIZ];
+       char buf[256];
+       char vname[256];
 
-       char lastname[SIZ];
-       char firstname[SIZ];
-       char middlename[SIZ];
-       char honorific_prefixes[SIZ];
-       char honorific_suffixes[SIZ];
+       char lastname[256];
+       char firstname[256];
+       char middlename[256];
+       char honorific_prefixes[256];
+       char honorific_suffixes[256];
 
        struct vCard *v;
        int i;
@@ -717,42 +722,43 @@ void vcard_newuser(struct ctdluser *usbuf) {
         * fully expanded vCard name based on the number of
         * words in the name
         */
-       strcpy(lastname, "");
-       strcpy(firstname, "");
-       strcpy(middlename, "");
-       strcpy(honorific_prefixes, "");
-       strcpy(honorific_suffixes, "");
+       safestrncpy(lastname, "", sizeof lastname);
+       safestrncpy(firstname, "", sizeof firstname);
+       safestrncpy(middlename, "", sizeof middlename);
+       safestrncpy(honorific_prefixes, "", sizeof honorific_prefixes);
+       safestrncpy(honorific_suffixes, "", sizeof honorific_suffixes);
 
-       strcpy(buf, usbuf->fullname);
+       safestrncpy(buf, usbuf->fullname, sizeof buf);
 
        /* Honorific suffixes */
        if (num_tokens(buf, ',') > 1) {
-               extract_token(honorific_suffixes, buf, (num_tokens(buf, ' ') - 1), ',');
+               extract_token(honorific_suffixes, buf, (num_tokens(buf, ' ') - 1), ',',
+                       sizeof honorific_suffixes);
                remove_token(buf, (num_tokens(buf, ',') - 1), ',');
        }
 
        /* Find a last name */
-       extract_token(lastname, buf, (num_tokens(buf, ' ') - 1), ' ');
+       extract_token(lastname, buf, (num_tokens(buf, ' ') - 1), ' ', sizeof lastname);
        remove_token(buf, (num_tokens(buf, ' ') - 1), ' ');
 
        /* Find honorific prefixes */
        if (num_tokens(buf, ' ') > 2) {
-               extract_token(honorific_prefixes, buf, 0, ' ');
+               extract_token(honorific_prefixes, buf, 0, ' ', sizeof honorific_prefixes);
                remove_token(buf, 0, ' ');
        }
 
        /* Find a middle name */
        if (num_tokens(buf, ' ') > 1) {
-               extract_token(middlename, buf, (num_tokens(buf, ' ') - 1), ' ');
+               extract_token(middlename, buf, (num_tokens(buf, ' ') - 1), ' ', sizeof middlename);
                remove_token(buf, (num_tokens(buf, ' ') - 1), ' ');
        }
 
        /* Anything left is probably the first name */
-       strcpy(firstname, buf);
+       safestrncpy(firstname, buf, sizeof firstname);
        striplt(firstname);
 
        /* Compose the structured name */
-       sprintf(vname, "%s;%s;%s;%s;%s", lastname, firstname, middlename,
+       snprintf(vname, sizeof vname, "%s;%s;%s;%s;%s", lastname, firstname, middlename,
                honorific_prefixes, honorific_suffixes);
 
        lprintf(CTDL_DEBUG, "Converted <%s> to <%s>\n", usbuf->fullname, vname);
@@ -889,12 +895,12 @@ EOH:      CtdlFreeMessage(msg);
  * Query Directory
  */
 void cmd_qdir(char *argbuf) {
-       char citadel_addr[SIZ];
-       char internet_addr[SIZ];
+       char citadel_addr[256];
+       char internet_addr[256];
 
        if (CtdlAccessCheck(ac_logged_in)) return;
 
-       extract(internet_addr, argbuf, 0);
+       extract_token(internet_addr, argbuf, 0, '|', sizeof internet_addr);
 
        if (CtdlDirectoryLookup(citadel_addr, internet_addr) != 0) {
                cprintf("%d %s was not found.\n",
@@ -937,14 +943,6 @@ void vcard_create_room(void)
 
 
 
-/*
- * Session startup, allocate some per-session data
- */
-void vcard_session_startup_hook(void) {
-       CtdlAllocUserData(SYM_VCARD, sizeof(struct vcard_internal_info));
-}
-
-
 /*
  * When a user logs in...
  */
@@ -965,7 +963,6 @@ char *serv_vcard_init(void)
 {
        struct ctdlroom qr;
 
-       CtdlRegisterSessionHook(vcard_session_startup_hook, EVT_START);
        CtdlRegisterSessionHook(vcard_session_login_hook, EVT_LOGIN);
        CtdlRegisterMessageHook(vcard_upload_beforesave, EVT_BEFORESAVE);
        CtdlRegisterMessageHook(vcard_upload_aftersave, EVT_AFTERSAVE);