$Log$
+Revision 1.374 1999/09/29 17:26:56 ajc
+* serv_vcard.c: fixed crashola bug in cmd_greg()
+* tools.c: simplified and improved the string tokenizer. Now it runs in a
+ single pass with no intermediate buffer.
+
Revision 1.373 1999/09/28 03:27:37 ajc
* Fully migrated cmd_greg() and cmd_regi() into serv_vcard (still has bugs)
Fri Jul 10 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
* Initial CVS import
+
cprintf("%s\n", usbuf.password);
cprintf("%s\n", vcard_get_prop(v, "n", 0)); /* name */
- strcpy(adr, vcard_get_prop(v, "adr", 0)); /* address... */
+ sprintf(adr, "%s", vcard_get_prop(v, "adr", 0));/* address... */
+ lprintf(9, "adr is <%s>\n", adr);
extract_token(buf, adr, 2, ';');
cprintf("%s\n", buf); /* street */
- extract_token(buf, adr, 2, ';');
+ extract_token(buf, adr, 3, ';');
cprintf("%s\n", buf); /* city */
- extract_token(buf, adr, 2, ';');
+ extract_token(buf, adr, 4, ';');
cprintf("%s\n", buf); /* state */
- extract_token(buf, adr, 2, ';');
+ extract_token(buf, adr, 5, ';');
cprintf("%s\n", buf); /* zip */
tel = vcard_get_prop(v, "tel;home", 0);
for (a=0; a<strlen(source); ++a)
if (source[a]=='|') ++count;
return(count);
- }
+}
/*
- * extract() - extract a parameter from a series of "|" separated...
+ * extract() - a smarter string tokenizer
*/
void extract_token(char *dest, char *source, int parmnum, char separator)
{
- char buf[256];
- int count = 0;
- int n;
+ int i;
+ int len;
+ int curr_parm;
+
+ strcpy(dest,"");
+ len = 0;
+ curr_parm = 0;
if (strlen(source)==0) {
- strcpy(dest,"");
return;
}
- n = num_parms(source);
-
- if (parmnum >= n) {
- strcpy(dest,"");
- return;
+ for (i=0; i<strlen(source); ++i) {
+ if (source[i]==separator) {
+ ++curr_parm;
}
- strcpy(buf,source);
- if ( (parmnum == 0) && (n == 1) ) {
- strcpy(dest,buf);
- for (n=0; n<strlen(dest); ++n)
- if (dest[n]==separator) dest[n] = 0;
- return;
+ else if (curr_parm == parmnum) {
+ dest[len+1] = 0;
+ dest[len++] = source[i];
}
-
- while (count++ < parmnum) do {
- strcpy(buf,&buf[1]);
- } while( (strlen(buf)>0) && (buf[0]!=separator) );
- if (buf[0]==separator) strcpy(buf,&buf[1]);
- for (count = 0; count<strlen(buf); ++count)
- if (buf[count] == separator) buf[count] = 0;
- strcpy(dest,buf);
}
+}
/*
* extract_int() - extract an int parm w/o supplying a buffer
{
char buf[256];
- extract(buf,source,parmnum);
+ extract_token(buf, source, parmnum, '|');
return(atoi(buf));
- }
+}
/*
* extract_long() - extract an long parm w/o supplying a buffer
{
char buf[256];
- extract(buf,source,parmnum);
+ extract_token(buf, source, parmnum, '|');
return(atol(buf));
- }
-
-
-
+}
char *vcard_get_prop(struct vCard *v, char *propname, int is_partial) {
int i;
+ lprintf(9, "vcard_get_prop(%s, %d) called\n", propname, is_partial);
if (v->numprops) for (i=0; i<(v->numprops); ++i) {
if ( (!strcasecmp(v->prop[i].name, propname))
|| ( (!strncasecmp(v->prop[i].name,
&& (v->prop[i].name[strlen(propname)] == ';')
&& (is_partial) ) ) {
return(v->prop[i].value);
+ lprintf(9, "found: value is <%s>\n", v->prop[i].value);
}
}
+ lprintf(9, "not found: returning null\n");
return NULL;
}