]> code.citadel.org Git - citadel.git/blobdiff - citadel/serv_vcard.c
* Removed the built-in memory leak checker. It wasn't threadsafe and
[citadel.git] / citadel / serv_vcard.c
index 3db7f3d028f00a892ee9e4c5ea58a80bdc1bed5d..f7487e4030d1a1d2b22545bbe4f23363e2fa43f6 100644 (file)
@@ -113,14 +113,14 @@ void vcard_extract_internet_addresses(struct CtdlMessage *msg,
        do {
                s = vcard_get_prop(v, "email;internet", 0, instance++, 0);
                if (s != NULL) {
-                       addr = strdoop(s);
+                       addr = strdup(s);
                        striplt(addr);
                        if (strlen(addr) > 0) {
                                if (callback != NULL) {
                                        callback(addr, citadel_address);
                                }
                        }
-                       phree(addr);
+                       free(addr);
                        found_something = 1;
                }
                else {
@@ -229,7 +229,7 @@ void vcard_populate_cs_inet_email(struct vCard *v) {
                s = vcard_get_prop(v, "email;internet", 0, instance++, 0);
                if (s != NULL) {
                        continue_searching = 1;
-                       addr = strdoop(s);
+                       addr = strdup(s);
                        striplt(addr);
                        if (strlen(addr) > 0) {
                                if (IsDirectory(addr)) {
@@ -240,7 +240,7 @@ void vcard_populate_cs_inet_email(struct vCard *v) {
                                        );
                                }
                        }
-                       phree(addr);
+                       free(addr);
                }
                else {
                        continue_searching = 0;
@@ -320,16 +320,16 @@ int vcard_upload_beforesave(struct CtdlMessage *msg) {
                         * replication always works correctly
                         */
                         if (msg->cm_fields['E'] != NULL)
-                                phree(msg->cm_fields['E']);
+                                free(msg->cm_fields['E']);
 
                         if (msg->cm_fields['A'] != NULL)
-                                phree(msg->cm_fields['A']);
+                                free(msg->cm_fields['A']);
 
-                       msg->cm_fields['A'] = strdoop(usbuf.fullname);
+                       msg->cm_fields['A'] = strdup(usbuf.fullname);
 
                         snprintf(buf, sizeof buf, VCARD_EXT_FORMAT,
                                 msg->cm_fields['A'], NODENAME);
-                        msg->cm_fields['E'] = strdoop(buf);
+                        msg->cm_fields['E'] = strdup(buf);
 
                        /* Now allow the save to complete. */
                        return(0);
@@ -477,7 +477,7 @@ void vcard_write_user(struct ctdluser *u, struct vCard *v) {
                fprintf(fp, "begin:vcard\r\nend:vcard\r\n");
        } else {
                fwrite(ser, strlen(ser), 1, fp);
-               phree(ser);
+               free(ser);
        }
         fclose(fp);
 
@@ -639,16 +639,59 @@ void cmd_greg(char *argbuf)
 void vcard_newuser(struct ctdluser *usbuf) {
        char buf[SIZ];
        char vname[SIZ];
+
+       char lastname[SIZ];
+       char firstname[SIZ];
+       char middlename[SIZ];
+       char honorific_prefixes[SIZ];
+       char honorific_suffixes[SIZ];
+
        struct vCard *v;
        int i;
-       int vnum;
 
        /* Try to intelligently convert the screen name to a
         * fully expanded vCard name based on the number of
         * words in the name
         */
-       vnum = num_tokens(usbuf->fullname, ' ');
-       strcpy(vname, usbuf->fullname); /* FIXME */
+       strcpy(lastname, "");
+       strcpy(firstname, "");
+       strcpy(middlename, "");
+       strcpy(honorific_prefixes, "");
+       strcpy(honorific_suffixes, "");
+
+       strcpy(buf, usbuf->fullname);
+
+       /* Honorific suffixes */
+       if (num_tokens(buf, ',') > 1) {
+               extract_token(honorific_suffixes, buf, (num_tokens(buf, ' ') - 1), ',');
+               remove_token(buf, (num_tokens(buf, ',') - 1), ',');
+       }
+
+       /* Find a last name */
+       extract_token(lastname, buf, (num_tokens(buf, ' ') - 1), ' ');
+       remove_token(buf, (num_tokens(buf, ' ') - 1), ' ');
+
+       /* Find honorific prefixes */
+       if (num_tokens(buf, ' ') > 2) {
+               extract_token(honorific_prefixes, buf, 0, ' ');
+               remove_token(buf, 0, ' ');
+       }
+
+       /* Find a middle name */
+       if (num_tokens(buf, ' ') > 1) {
+               extract_token(middlename, buf, (num_tokens(buf, ' ') - 1), ' ');
+               remove_token(buf, (num_tokens(buf, ' ') - 1), ' ');
+       }
+
+       /* Anything left is probably the first name */
+       strcpy(firstname, buf);
+       striplt(firstname);
+
+       /* Compose the structured name */
+       sprintf(vname, "%s;%s;%s;%s;%s", lastname, firstname, middlename,
+               honorific_prefixes, honorific_suffixes);
+
+       lprintf(CTDL_DEBUG, "Converted <%s> to <%s>\n", usbuf->fullname, vname);
 
        /* Create and save the vCard */
         v = vcard_new();
@@ -657,6 +700,7 @@ void vcard_newuser(struct ctdluser *usbuf) {
        for (i=0; i<strlen(buf); ++i) {
                if (buf[i] == ' ') buf[i] = '_';
        }
+       vcard_add_prop(v, "fn", usbuf->fullname);
        vcard_add_prop(v, "n", vname);
        vcard_add_prop(v, "email;internet", buf);
        vcard_write_user(usbuf, v);
@@ -673,23 +717,23 @@ void vcard_purge(struct ctdluser *usbuf) {
        struct CtdlMessage *msg;
        char buf[SIZ];
 
-       msg = (struct CtdlMessage *) mallok(sizeof(struct CtdlMessage));
+       msg = (struct CtdlMessage *) malloc(sizeof(struct CtdlMessage));
        if (msg == NULL) return;
        memset(msg, 0, sizeof(struct CtdlMessage));
 
         msg->cm_magic = CTDLMESSAGE_MAGIC;
         msg->cm_anon_type = MES_NORMAL;
         msg->cm_format_type = 0;
-        msg->cm_fields['A'] = strdoop(usbuf->fullname);
-        msg->cm_fields['O'] = strdoop(ADDRESS_BOOK_ROOM);
-        msg->cm_fields['N'] = strdoop(NODENAME);
-        msg->cm_fields['M'] = strdoop("Purge this vCard\n");
+        msg->cm_fields['A'] = strdup(usbuf->fullname);
+        msg->cm_fields['O'] = strdup(ADDRESS_BOOK_ROOM);
+        msg->cm_fields['N'] = strdup(NODENAME);
+        msg->cm_fields['M'] = strdup("Purge this vCard\n");
 
         snprintf(buf, sizeof buf, VCARD_EXT_FORMAT,
                        msg->cm_fields['A'], NODENAME);
-        msg->cm_fields['E'] = strdoop(buf);
+        msg->cm_fields['E'] = strdup(buf);
 
-       msg->cm_fields['S'] = strdoop("CANCEL");
+       msg->cm_fields['S'] = strdup("CANCEL");
 
         CtdlSubmitMsg(msg, NULL, ADDRESS_BOOK_ROOM);
         CtdlFreeMessage(msg);