]> code.citadel.org Git - citadel.git/blobdiff - webcit/vcard.c
* strlen(); strcpy -> single strlen + memmove
[citadel.git] / webcit / vcard.c
index d236b00c5a2774cc7d8ae008fe884cf272450610..65dfd1c0fc5cbd632eb0b1f0fac6c2ab2a5cb25e 100644 (file)
@@ -84,6 +84,7 @@ struct vCard *vcard_load(char *vtext) {
        char *mycopy, *ptr;
        char *namebuf, *valuebuf;
        int i;
+       int len;
        int colonpos, nlpos;
 
        if (vtext == NULL) return vcard_new();
@@ -95,12 +96,15 @@ struct vCard *vcard_load(char *vtext) {
         * To make it easier to parse, we convert CRLF to LF, and unfold any
         * multi-line fields into single lines.
         */
-       for (i=0; i<strlen(mycopy); ++i) {
+       len = strlen(mycopy);
+       for (i=0; i<len; ++i) {
                if (!strncmp(&mycopy[i], "\r\n", 2)) {
-                       strcpy(&mycopy[i], &mycopy[i+1]);
+                       memmove(&mycopy[i], &mycopy[i+1], len - i);
+                       len --;
                }
                if ( (mycopy[i]=='\n') && (isspace(mycopy[i+1])) ) {
-                       strcpy(&mycopy[i], &mycopy[i+1]);
+                       memmove(&mycopy[i], &mycopy[i+1], len - i);
+                       len --;
                }
        }
 
@@ -108,7 +112,7 @@ struct vCard *vcard_load(char *vtext) {
        if (v == NULL) return v;
 
        ptr = mycopy;
-       while (strlen(ptr)>0) {
+       while (*ptr != '\0') {
                colonpos = (-1);
                nlpos = (-1);
                colonpos = pattern2(ptr, ":");
@@ -147,7 +151,7 @@ struct vCard *vcard_load(char *vtext) {
 
                }
 
-               while ( (*ptr != '\n') && (strlen(ptr)>0) ) {
+               while ( (*ptr != '\n') && (*ptr != '\0') ) {
                        ++ptr;
                }
                if (*ptr == '\n') ++ptr;
@@ -260,7 +264,7 @@ void vcard_set_prop(struct vCard *v, char *name, char *value, int append) {
 
 
 /**
- * \brief Serialize a struct vcard into a standard text/x-vcard MIME type.
+ * \brief Serialize a struct vcard into its standard format.
  * \param v vCard to serialize
  * \return the serialized vCard
  */
@@ -286,9 +290,9 @@ char *vcard_serialize(struct vCard *v)
 
        safestrncpy(ser, "begin:vcard\r\n", len);
        if (v->numprops) for (i=0; i<(v->numprops); ++i) {
-               if (strcasecmp(v->prop[i].name, "end")) {
+               if ( (strcasecmp(v->prop[i].name, "end")) && (v->prop[i].value != NULL) ) {
                        is_utf8 = 0;
-                       for (j=0; i<strlen(v->prop[i].value); ++i) {
+                       for (j=0; j<strlen(v->prop[i].value); ++j) {
                                if ( (v->prop[i].value[j] < 32) || (v->prop[i].value[j] > 126) ) {
                                        is_utf8 = 1;
                                }