]> code.citadel.org Git - citadel.git/commitdiff
* Finished prettying up the vCard display
authorArt Cancro <ajc@citadel.org>
Fri, 17 Oct 2003 03:08:28 +0000 (03:08 +0000)
committerArt Cancro <ajc@citadel.org>
Fri, 17 Oct 2003 03:08:28 +0000 (03:08 +0000)
webcit/ChangeLog
webcit/messages.c

index e62ba261faedee0271ee9366236ad73eb6b8aab1..952aa33b15a5b23f05369421fa872a9450ba03de 100644 (file)
@@ -1,4 +1,7 @@
 $Log$
+Revision 500.29  2003/10/17 03:08:28  ajc
+* Finished prettying up the vCard display
+
 Revision 500.28  2003/10/17 02:31:45  ajc
 * Multi-line string literals are deprecated in GCC 3.1 unless each line
   is wrapped in quotes.  Performed this fix so it'll compile.
@@ -1596,3 +1599,4 @@ Sun Dec  6 19:50:55 EST 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
 
 1998-12-03 Nathan Bryant <bryant@cs.usm.maine.edu>
        * webserver.c: warning fix
+
index c81b4d5e0f72974a73ccab33d73bfb9152a29c95..01f8bb04d51acc22cc52db6393ef3e5f86c1a0fe 100644 (file)
@@ -114,6 +114,12 @@ void fetchname_parsed_vcard(struct vCard *v, char *storename) {
  *
  * Set 'full' to nonzero to display the full card, otherwise it will only
  * show a summary line.
+ *
+ * This code is a bit ugly, so perhaps an explanation is due: we do this
+ * in two passes through the vCard fields.  On the first pass, we process
+ * fields we understand, and then render them in a pretty fashion at the
+ * end.  Then we make a second pass, outputting all the fields we don't
+ * understand in a simple two-column name/value format.
  */
 void display_parsed_vcard(struct vCard *v, int full) {
        int i, j;
@@ -122,6 +128,8 @@ void display_parsed_vcard(struct vCard *v, int full) {
        int is_qp = 0;
        int is_b64 = 0;
        char *thisname, *thisvalue;
+       char firsttoken[SIZ];
+       int pass;
 
        char displayname[SIZ];
        char phone[SIZ];
@@ -147,121 +155,138 @@ void display_parsed_vcard(struct vCard *v, int full) {
        }
 
        wprintf("<TABLE bgcolor=#888888>");
-       if (v->numprops) for (i=0; i<(v->numprops); ++i) {
+       for (pass=1; pass<=2; ++pass) {
 
-               thisname = strdup(v->prop[i].name);
+               if (v->numprops) for (i=0; i<(v->numprops); ++i) {
 
-               for (j=0; j<num_tokens(thisname, ';'); ++j) {
-                       extract_token(buf, thisname, j, ';');
-                       if (!strcasecmp(buf, "encoding=quoted-printable")) {
-                               is_qp = 1;
-                               remove_token(thisname, j, ';');
+                       thisname = strdup(v->prop[i].name);
+                       extract_token(firsttoken, thisname, 0, ';');
+       
+                       for (j=0; j<num_tokens(thisname, ';'); ++j) {
+                               extract_token(buf, thisname, j, ';');
+                               if (!strcasecmp(buf, "encoding=quoted-printable")) {
+                                       is_qp = 1;
+                                       remove_token(thisname, j, ';');
+                               }
+                               if (!strcasecmp(buf, "encoding=base64")) {
+                                       is_b64 = 1;
+                                       remove_token(thisname, j, ';');
+                               }
                        }
-                       if (!strcasecmp(buf, "encoding=base64")) {
-                               is_b64 = 1;
-                               remove_token(thisname, j, ';');
+       
+                       if (is_qp) {
+                               thisvalue = malloc(strlen(v->prop[i].value) + 50);
+                               j = CtdlDecodeQuotedPrintable(
+                                       thisvalue, v->prop[i].value,
+                                       strlen(v->prop[i].value) );
+                               thisvalue[j] = 0;
                        }
-               }
-
-               if (is_qp) {
-                       thisvalue = malloc(strlen(v->prop[i].value) + 50);
-                       j = CtdlDecodeQuotedPrintable(
-                               thisvalue, v->prop[i].value,
-                               strlen(v->prop[i].value) );
-                       thisvalue[j] = 0;
-               }
-               else if (is_b64) {
-                       thisvalue = malloc(strlen(v->prop[i].value) + 50);
-                       CtdlDecodeBase64(
-                               thisvalue, v->prop[i].value,
-                               strlen(v->prop[i].value) );
-               }
-               else {
-                       thisvalue = strdup(v->prop[i].value);
-               }
-
-               /*** Various fields we may encounter ***/
-
-               /* N is name, but only if there's no FN already there */
-               if (!strcasecmp(thisname, "n")
-                  || (!strncasecmp(thisname, "n;", 2)) ) {
-                       if (strlen(displayname) == 0) {
+                       else if (is_b64) {
+                               thisvalue = malloc(strlen(v->prop[i].value) + 50);
+                               CtdlDecodeBase64(
+                                       thisvalue, v->prop[i].value,
+                                       strlen(v->prop[i].value) );
+                       }
+                       else {
+                               thisvalue = strdup(v->prop[i].value);
+                       }
+       
+                       /*** Various fields we may encounter ***/
+       
+                       /* N is name, but only if there's no FN already there */
+                       if (!strcasecmp(firsttoken, "n")) {
+                               if (strlen(displayname) == 0) {
+                                       strcpy(displayname, thisvalue);
+                               }
+                       }
+       
+                       /* FN (full name) is a true 'display name' field */
+                       else if (!strcasecmp(firsttoken, "fn")) {
                                strcpy(displayname, thisvalue);
                        }
-               }
-
-               /* FN (full name) is a true 'display name' field */
-               else if (!strcasecmp(thisname, "fn")
-                  || (!strncasecmp(thisname, "fn;", 3)) ) {
-                       strcpy(displayname, thisvalue);
-               }
-
-               else if (!strncasecmp(thisname, "email", 5)) {
-                       if (strlen(mailto) > 0) strcat(mailto, "<BR>");
-                       strcat(mailto,
-                               "<A HREF=\"/display_enter"
-                               "?force_room=_MAIL_&recp=");
-                       urlesc(&mailto[strlen(mailto)], thisvalue);
-                       strcat(mailto, "\">");
-                       urlesc(&mailto[strlen(mailto)], thisvalue);
-                       strcat(mailto, "</A>");
-               }
-               else if (!strncasecmp(thisname, "tel;", 4)) {
-                       if (strlen(phone) > 0) strcat(phone, "<BR>");
-                       strcat(phone, thisvalue);
-                       for (j=0; j<num_tokens(thisname, ';'); ++j) {
-                               extract_token(buf, thisname, j, ';');
-                               if (!strcasecmp(buf, "tel"))
-                                       strcat(phone, "");
-                               else if (!strcasecmp(buf, "work"))
-                                       strcat(phone, " (work)");
-                               else if (!strcasecmp(buf, "home"))
-                                       strcat(phone, " (home)");
-                               else if (!strcasecmp(buf, "cell"))
-                                       strcat(phone, " (cell)");
-                               else {
-                                       strcat(phone, " (");
-                                       strcat(phone, buf);
-                                       strcat(phone, ")");
+       
+                       else if (!strcasecmp(firsttoken, "email")) {
+                               if (strlen(mailto) > 0) strcat(mailto, "<BR>");
+                               strcat(mailto,
+                                       "<A HREF=\"/display_enter"
+                                       "?force_room=_MAIL_&recp=");
+                               urlesc(&mailto[strlen(mailto)], thisvalue);
+                               strcat(mailto, "\">");
+                               urlesc(&mailto[strlen(mailto)], thisvalue);
+                               strcat(mailto, "</A>");
+                       }
+                       else if (!strcasecmp(firsttoken, "tel")) {
+                               if (strlen(phone) > 0) strcat(phone, "<BR>");
+                               strcat(phone, thisvalue);
+                               for (j=0; j<num_tokens(thisname, ';'); ++j) {
+                                       extract_token(buf, thisname, j, ';');
+                                       if (!strcasecmp(buf, "tel"))
+                                               strcat(phone, "");
+                                       else if (!strcasecmp(buf, "work"))
+                                               strcat(phone, " (work)");
+                                       else if (!strcasecmp(buf, "home"))
+                                               strcat(phone, " (home)");
+                                       else if (!strcasecmp(buf, "cell"))
+                                               strcat(phone, " (cell)");
+                                       else {
+                                               strcat(phone, " (");
+                                               strcat(phone, buf);
+                                               strcat(phone, ")");
+                                       }
                                }
                        }
-               }
-               else if (!strcasecmp(thisname, "adr")) {
-                       wprintf("<TR><TD>Address:</TD><TD>");
-                       for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
-                               extract_token(buf, thisvalue, j, ';');
-                               if (strlen(buf) > 0) {
-                                       escputs(buf);
-                                       wprintf("<BR>");
+                       else if (!strcasecmp(firsttoken, "adr")) {
+                               if (pass == 2) {
+                                       wprintf("<TR><TD>Address:</TD><TD>");
+                                       for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
+                                               extract_token(buf, thisvalue, j, ';');
+                                               if (strlen(buf) > 0) {
+                                                       escputs(buf);
+                                                       wprintf("<BR>");
+                                               }
+                                       }
+                                       wprintf("</TD></TR>\n");
                                }
                        }
-                       wprintf("</TD></TR>\n");
+                       else if (!strcasecmp(firsttoken, "version")) {
+                               /* ignore */
+                       }
+                       else if (!strcasecmp(firsttoken, "rev")) {
+                               /* ignore */
+                       }
+                       else if (!strcasecmp(firsttoken, "label")) {
+                               /* ignore */
+                       }
+                       else {
+                               if (pass == 2) {
+                                       wprintf("<TR><TD>");
+                                       escputs(thisname);
+                                       wprintf("</TD><TD>");
+                                       escputs(thisvalue);
+                                       wprintf("</TD></TR>\n");
+                               }
+                       }
+       
+                       free(thisname);
+                       free(thisvalue);
                }
-               else {
-                       wprintf("<TR><TD>");
-                       escputs(thisname);
-                       wprintf("</TD><TD>");
-                       escputs(thisvalue);
-                       wprintf("</TD></TR>\n");
+       
+               if (pass == 1) {
+                       wprintf("<TR BGCOLOR=\"#AAAAAA\">"
+                       "<TD COLSPAN=2 BGCOLOR=\"#FFFFFF\">"
+                       "<IMG ALIGN=CENTER SRC=\"/static/vcard.gif\">"
+                       "<FONT SIZE=+1><B>");
+                       escputs(displayname);
+                       wprintf("</B></FONT></TD></TR>\n");
+               
+                       if (strlen(phone) > 0)
+                               wprintf("<TR><TD>Telephone:</TD><TD>%s</TD></TR>\n", phone);
+                       if (strlen(mailto) > 0)
+                               wprintf("<TR><TD>E-mail:</TD><TD>%s</TD></TR>\n", mailto);
                }
 
-               free(thisname);
-               free(thisvalue);
-
        }
 
-       wprintf("<TR BGCOLOR=\"#AAAAAA\">"
-       "<TD COLSPAN=2 BGCOLOR=\"#FFFFFF\">"
-       "<IMG ALIGN=CENTER SRC=\"/static/vcard.gif\">"
-       "<FONT SIZE=+1><B>");
-       escputs(displayname);
-       wprintf("</B></FONT></TD></TR>\n");
-
-       if (strlen(phone) > 0)
-               wprintf("<TR><TD>Telephone:</TD><TD>%s</TD></TR>\n", phone);
-       if (strlen(mailto) > 0)
-               wprintf("<TR><TD>E-mail:</TD><TD>%s</TD></TR>\n", mailto);
-
        wprintf("</TABLE>\n");
 }