]> code.citadel.org Git - citadel.git/commitdiff
* serv_vcard.c: fixed crashola bug in cmd_greg()
authorArt Cancro <ajc@citadel.org>
Wed, 29 Sep 1999 17:26:56 +0000 (17:26 +0000)
committerArt Cancro <ajc@citadel.org>
Wed, 29 Sep 1999 17:26:56 +0000 (17:26 +0000)
* tools.c: simplified and improved the string tokenizer.  Now it runs in a
           single pass with no intermediate buffer.

citadel/ChangeLog
citadel/serv_vcard.c
citadel/tools.c
citadel/vcard.c

index 2f5e7bd8f9429305a4d74f89457a9c98be50d2f8..f1bff00312d467a6b96cd335f4f8d0a7815d568f 100644 (file)
@@ -1,4 +1,9 @@
 $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)
 
@@ -1278,3 +1283,4 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
        * Initial CVS import 
+
index 1301d54d0d6688a1b087837ffc7edfdcd6e25be6..9ba8ceb5f836ab344159ea729cb68dd1124fb608 100644 (file)
@@ -273,15 +273,16 @@ void cmd_greg(char *argbuf)
        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);
index 189f922cd4039d2c3f66abe80944ec6ee28fd691..0b7e1aaf720ffa6d7d4dea6161e5d72d25f22163 100644 (file)
@@ -32,44 +32,35 @@ int num_parms(char *source)
        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
@@ -78,9 +69,9 @@ int extract_int(char *source, int parmnum)
 {
        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
@@ -89,9 +80,6 @@ long extract_long(char *source, long int parmnum)
 {
        char buf[256];
        
-       extract(buf,source,parmnum);
+       extract_token(buf, source, parmnum, '|');
        return(atol(buf));
-       }
-
-
-
+}
index a34a466b0306800270a033358f41142254da1b3f..e7836516e239822055c590ff0fbfac655db89ce0 100644 (file)
@@ -131,6 +131,7 @@ struct vCard *vcard_load(char *vtext) {
 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,
@@ -138,9 +139,11 @@ char *vcard_get_prop(struct vCard *v, char *propname, int is_partial) {
                         && (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;
 }