]> code.citadel.org Git - citadel.git/commitdiff
* vcard.c: another API update
authorArt Cancro <ajc@citadel.org>
Tue, 5 Mar 2002 04:47:49 +0000 (04:47 +0000)
committerArt Cancro <ajc@citadel.org>
Tue, 5 Mar 2002 04:47:49 +0000 (04:47 +0000)
citadel/ChangeLog
citadel/serv_vcard.c
citadel/vcard.c
citadel/vcard.h

index b17807c3eed3e12b7d3ba59ff862db3c9d7a29f6..0b9ea18152c91220122287b92807254cb2cee9ed 100644 (file)
@@ -1,4 +1,7 @@
  $Log$
+ Revision 590.126  2002/03/05 04:47:49  ajc
+ * vcard.c: another API update
+
  Revision 590.125  2002/03/04 05:29:39  ajc
  * Made a small API change to vcard.c for WebCit, brought the change over here too
    in order to keep vcard.c identical everywhere.
@@ -3387,3 +3390,4 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import 
+
index 8fdfb0efcacb2c1ae87e3fb5706740b65ec756e3..b4cbe6269c58736ff2147d74d51ed59453fe7028 100644 (file)
@@ -98,7 +98,7 @@ void vcard_extract_internet_addresses(struct CtdlMessage *msg,
         * the "email;internet" key
         */
        do {
-               s = vcard_get_prop(v, "email;internet", 0, instance++);
+               s = vcard_get_prop(v, "email;internet", 0, instance++, 0);
                if (s != NULL) {
                        addr = strdoop(s);
                        striplt(addr);
@@ -216,7 +216,7 @@ void vcard_populate_cs_inet_email(struct vCard *v) {
         * the "email;internet" key
         */
        do {
-               s = vcard_get_prop(v, "email;internet", 0, instance++);
+               s = vcard_get_prop(v, "email;internet", 0, instance++, 0);
                if (s != NULL) {
                        continue_searching = 1;
                        addr = strdoop(s);
@@ -560,10 +560,10 @@ void cmd_greg(char *argbuf)
        cprintf("%d %s\n", LISTING_FOLLOWS, usbuf.fullname);
        cprintf("%ld\n", usbuf.usernum);
        cprintf("%s\n", usbuf.password);
-       s = vcard_get_prop(v, "n", 0, 0);
+       s = vcard_get_prop(v, "n", 0, 0, 0);
        cprintf("%s\n", s ? s : " ");   /* name */
 
-       s = vcard_get_prop(v, "adr", 0, 0);
+       s = vcard_get_prop(v, "adr", 0, 0, 0);
        sprintf(adr, "%s", s ? s : " ");/* address... */
 
        extract_token(buf, adr, 2, ';');
@@ -575,8 +575,8 @@ void cmd_greg(char *argbuf)
        extract_token(buf, adr, 5, ';');
        cprintf("%s\n", buf);                           /* zip */
 
-       s = vcard_get_prop(v, "tel;home", 0, 0);
-       if (s == NULL) s = vcard_get_prop(v, "tel", 1, 0);
+       s = vcard_get_prop(v, "tel;home", 0, 0, 0);
+       if (s == NULL) s = vcard_get_prop(v, "tel", 1, 0, 0);
        if (s != NULL) {
                cprintf("%s\n", s);
        }
@@ -586,9 +586,9 @@ void cmd_greg(char *argbuf)
 
        cprintf("%d\n", usbuf.axlevel);
 
-       s = vcard_get_prop(v, "email;internet", 0, 0);
+       s = vcard_get_prop(v, "email;internet", 0, 0, 0);
        cprintf("%s\n", s ? s : " ");
-       s = vcard_get_prop(v, "adr", 0, 0);
+       s = vcard_get_prop(v, "adr", 0, 0, 0);
        sprintf(adr, "%s", s ? s : " ");/* address... */
 
        extract_token(buf, adr, 6, ';');
index 03a16b689d196c5851ec29d8156131b4bbe772ad..e0825316c1c10775c28849367e985ad02ea80f7f 100644 (file)
@@ -32,7 +32,9 @@
 #include <limits.h>
 #include <syslog.h>
 
-#include "webcit.h"
+#include "citadel.h"
+#include "server.h"
+#include "support.h"
 #include "vcard.h"
 
 /* 
@@ -41,7 +43,7 @@
 struct vCard *vcard_new() {
        struct vCard *v;
 
-       v = (struct vCard *) malloc(sizeof(struct vCard));
+       v = (struct vCard *) mallok(sizeof(struct vCard));
        if (v == NULL) return v;
 
        v->magic = CTDL_VCARD_MAGIC;
@@ -63,7 +65,7 @@ struct vCard *vcard_load(char *vtext) {
        int i;
        int colonpos, nlpos;
 
-       mycopy = strdup(vtext);
+       mycopy = strdoop(vtext);
        if (mycopy == NULL) return NULL;
 
        /* First, fix this big pile o' vCard to make it more parseable.
@@ -90,8 +92,8 @@ struct vCard *vcard_load(char *vtext) {
                nlpos = pattern2(ptr, "\n");
 
                if (nlpos > colonpos > 0) {
-                       namebuf = malloc(colonpos + 1);
-                       valuebuf = malloc(nlpos - colonpos + 1);
+                       namebuf = mallok(colonpos + 1);
+                       valuebuf = mallok(nlpos - colonpos + 1);
                        strncpy(namebuf, ptr, colonpos);
                        namebuf[colonpos] = 0;
                        strncpy(valuebuf, &ptr[colonpos+1], nlpos-colonpos-1);
@@ -104,14 +106,14 @@ struct vCard *vcard_load(char *vtext) {
 
                        if ( (valid) && (strcasecmp(namebuf, "begin")) ) {
                                ++v->numprops;
-                               v->prop = realloc(v->prop,
+                               v->prop = reallok(v->prop,
                                        (v->numprops * sizeof(char *) * 2) );
                                v->prop[v->numprops-1].name = namebuf;
                                v->prop[v->numprops-1].value = valuebuf;
                        } 
                        else {
-                               free(namebuf);
-                               free(valuebuf);
+                               phree(namebuf);
+                               phree(valuebuf);
                        }
 
                }
@@ -122,20 +124,21 @@ struct vCard *vcard_load(char *vtext) {
                if (*ptr == '\n') ++ptr;
        }
 
-       free(mycopy);
+       phree(mycopy);
        return v;
 }
 
 
 /*
- * Fetch the value of a particular key
+ * Fetch the value of a particular key.
  * If is_partial is set to 1, a partial match is ok (for example,
- * a key of "tel;home" will satisfy a search for "tel")
+ * a key of "tel;home" will satisfy a search for "tel").
  * Set "instance" to a value higher than 0 to return subsequent instances
- * of the same key
+ * of the same key.
+ * Set "get_propname" to nonzero to fetch the property name instead of value.
  */
 char *vcard_get_prop(struct vCard *v, char *propname,
-                       int is_partial, int instance) {
+                       int is_partial, int instance, int get_propname) {
        int i;
        int found_instance = 0;
 
@@ -147,7 +150,12 @@ char *vcard_get_prop(struct vCard *v, char *propname,
                         && (v->prop[i].name[strlen(propname)] == ';')
                         && (is_partial) ) ) {
                        if (instance == found_instance++) {
-                               return(v->prop[i].value);
+                               if (get_propname) {
+                                       return(v->prop[i].name);
+                               }
+                               else {
+                                       return(v->prop[i].value);
+                               }
                        }
                }
        }
@@ -167,14 +175,14 @@ void vcard_free(struct vCard *v) {
        if (v->magic != CTDL_VCARD_MAGIC) return;       /* Self-check */
        
        if (v->numprops) for (i=0; i<(v->numprops); ++i) {
-               free(v->prop[i].name);
-               free(v->prop[i].value);
+               phree(v->prop[i].name);
+               phree(v->prop[i].value);
        }
 
-       if (v->prop != NULL) free(v->prop);
+       if (v->prop != NULL) phree(v->prop);
        
        memset(v, 0, sizeof(struct vCard));
-       free(v);
+       phree(v);
 }
 
 
@@ -191,20 +199,20 @@ void vcard_set_prop(struct vCard *v, char *name, char *value, int append) {
        /* If this key is already present, replace it */
        if (!append) if (v->numprops) for (i=0; i<(v->numprops); ++i) {
                if (!strcasecmp(v->prop[i].name, name)) {
-                       free(v->prop[i].name);
-                       free(v->prop[i].value);
-                       v->prop[i].name = strdup(name);
-                       v->prop[i].value = strdup(value);
+                       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 = realloc(v->prop,
+       v->prop = reallok(v->prop,
                (v->numprops * sizeof(char *) * 2) );
-       v->prop[v->numprops-1].name = strdup(name);
-       v->prop[v->numprops-1].value = strdup(value);
+       v->prop[v->numprops-1].name = strdoop(name);
+       v->prop[v->numprops-1].value = strdoop(value);
 }
 
 
@@ -230,7 +238,7 @@ char *vcard_serialize(struct vCard *v)
                        strlen(v->prop[i].value) + 4;
        }
 
-       ser = malloc(len);
+       ser = mallok(len);
        if (ser == NULL) return NULL;
 
        strcpy(ser, "begin:vcard\r\n");
index 743efa99063c2c415d8167f74239af4b74a54e31..aae58eb3c2b2e9cd5009cff1a03faf29cd1fbb0d 100644 (file)
@@ -29,5 +29,5 @@ struct vCard *vcard_load(char *);
 void vcard_free(struct vCard *);
 void vcard_set_prop(struct vCard *v, char *name, char *value, int append);
 char *vcard_get_prop(struct vCard *v, char *propname, int is_partial,
-                       int instance);
+                       int instance, int return_propname);
 char *vcard_serialize(struct vCard *);