* 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);
* 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);
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, ';');
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);
}
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, ';');
#include <limits.h>
#include <syslog.h>
-#include "webcit.h"
+#include "citadel.h"
+#include "server.h"
+#include "support.h"
#include "vcard.h"
/*
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;
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.
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);
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);
}
}
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;
&& (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);
+ }
}
}
}
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);
}
/* 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);
}
strlen(v->prop[i].value) + 4;
}
- ser = malloc(len);
+ ser = mallok(len);
if (ser == NULL) return NULL;
strcpy(ser, "begin:vcard\r\n");