X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fvcard_edit.c;h=4f6183dc570775b37d05cec92022d16092f07a59;hb=0f72e15a12dcc90e3dbfc01ff35c0e910a8d419e;hp=e20d296736c35df4c4ad28b2a855c29a93503e93;hpb=52d8adf3fa79c627e904b403e0cb525a30adbe0e;p=citadel.git diff --git a/webcit/vcard_edit.c b/webcit/vcard_edit.c index e20d29673..4f6183dc5 100644 --- a/webcit/vcard_edit.c +++ b/webcit/vcard_edit.c @@ -1,37 +1,22 @@ /* - * vcard_edit.c - * - * Handles editing of vCard objects. - * * $Id$ */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +/** + * \defgroup vCardEdit Handles on-screen editing of vCard objects. + * \ingroup VCards + */ +/*@{*/ #include "webcit.h" #include "vcard.h" - -/* Edit the vCard component of a MIME message. Supply the message number +/** + * \brief Edit the vCard component of a MIME message. + * Supply the message number * and MIME part number to fetch. Or, specify -1 for the message number * to start with a blank card. + * \param msgnum number of the item on the citadel server + * \param partnum what??? + * \param return_to where to go back in the browser after edit ???? */ void do_edit_vcard(long msgnum, char *partnum, char *return_to) { char buf[SIZ]; @@ -40,25 +25,28 @@ void do_edit_vcard(long msgnum, char *partnum, char *return_to) { struct vCard *v; int i; char *key, *value; - char whatuser[SIZ]; - - char lastname[SIZ]; - char firstname[SIZ]; - char middlename[SIZ]; - char prefix[SIZ]; - char suffix[SIZ]; - char pobox[SIZ]; - char extadr[SIZ]; - char street[SIZ]; - char city[SIZ]; - char state[SIZ]; - char zipcode[SIZ]; - char country[SIZ]; - char hometel[SIZ]; - char worktel[SIZ]; - char primary_inetemail[SIZ]; + char whatuser[256]; + + char lastname[256]; + char firstname[256]; + char middlename[256]; + char prefix[256]; + char suffix[256]; + char pobox[256]; + char extadr[256]; + char street[256]; + char city[256]; + char state[256]; + char zipcode[256]; + char country[256]; + char hometel[256]; + char worktel[256]; + char primary_inetemail[256]; char other_inetemail[SIZ]; char extrafields[SIZ]; + char fullname[256]; + char title[256]; + char org[256]; lastname[0] = 0; firstname[0] = 0; @@ -76,23 +64,24 @@ void do_edit_vcard(long msgnum, char *partnum, char *return_to) { worktel[0] = 0; primary_inetemail[0] = 0; other_inetemail[0] = 0; + title[0] = 0; + org[0] = 0; extrafields[0] = 0; + fullname[0] = 0; - output_headers(3); - - strcpy(whatuser, ""); + safestrncpy(whatuser, "", sizeof whatuser); if (msgnum >= 0) { sprintf(buf, "MSG0 %ld|1", msgnum); serv_puts(buf); - serv_gets(buf); + serv_getln(buf, sizeof buf); if (buf[0] != '1') { - wDumpContent(1); + convenience_page("770000", _("Error"), &buf[4]); return; } - while (serv_gets(buf), strcmp(buf, "000")) { + while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { if (!strncasecmp(buf, "from=", 5)) { - strcpy(whatuser, &buf[5]); + safestrncpy(whatuser, &buf[5], sizeof whatuser); } else if (!strncasecmp(buf, "node=", 5)) { strcat(whatuser, " @ "); @@ -100,22 +89,19 @@ void do_edit_vcard(long msgnum, char *partnum, char *return_to) { } } - sprintf(buf, "OPNA %ld|%s", msgnum, partnum); + sprintf(buf, "DLAT %ld|%s", msgnum, partnum); serv_puts(buf); - serv_gets(buf); - if (buf[0] != '2') { - wDumpContent(1); + serv_getln(buf, sizeof buf); + if (buf[0] != '6') { + convenience_page("770000", "Error", &buf[4]); return; } total_len = atoi(&buf[4]); - serialized_vcard = malloc(total_len + 1); - - read_server_binary(serialized_vcard, total_len); - - serv_puts("CLOS"); - serv_gets(buf); - serialized_vcard[total_len + 1] = 0; + serialized_vcard = malloc(total_len + 2); + + serv_read(serialized_vcard, total_len); + serialized_vcard[total_len] = 0; v = vcard_load(serialized_vcard); free(serialized_vcard); @@ -126,34 +112,46 @@ void do_edit_vcard(long msgnum, char *partnum, char *return_to) { value = vcard_get_prop(v, "", 0, i++, 0); if (!strcasecmp(key, "n")) { - extract_token(lastname, value, 0, ';'); - extract_token(firstname, value, 1, ';'); - extract_token(middlename, value, 2, ';'); - extract_token(prefix, value, 3, ';'); - extract_token(suffix, value, 4, ';'); + extract_token(lastname, value, 0, ';', sizeof lastname); + extract_token(firstname, value, 1, ';', sizeof firstname); + extract_token(middlename, value, 2, ';', sizeof middlename); + extract_token(prefix, value, 3, ';', sizeof prefix); + extract_token(suffix, value, 4, ';', sizeof suffix); + } + + else if (!strcasecmp(key, "fn")) { + safestrncpy(fullname, value, sizeof fullname); + } + + else if (!strcasecmp(key, "title")) { + safestrncpy(title, value, sizeof title); + } + + else if (!strcasecmp(key, "org")) { + safestrncpy(org, value, sizeof org); } else if (!strcasecmp(key, "adr")) { - extract_token(pobox, value, 0, ';'); - extract_token(extadr, value, 1, ';'); - extract_token(street, value, 2, ';'); - extract_token(city, value, 3, ';'); - extract_token(state, value, 4, ';'); - extract_token(zipcode, value, 5, ';'); - extract_token(country, value, 6, ';'); + extract_token(pobox, value, 0, ';', sizeof pobox); + extract_token(extadr, value, 1, ';', sizeof extadr); + extract_token(street, value, 2, ';', sizeof street); + extract_token(city, value, 3, ';', sizeof city); + extract_token(state, value, 4, ';', sizeof state); + extract_token(zipcode, value, 5, ';', sizeof zipcode); + extract_token(country, value, 6, ';', sizeof country); } else if (!strcasecmp(key, "tel;home")) { - extract_token(hometel, value, 0, ';'); + extract_token(hometel, value, 0, ';', sizeof hometel); } else if (!strcasecmp(key, "tel;work")) { - extract_token(worktel, value, 0, ';'); + extract_token(worktel, value, 0, ';', sizeof worktel); } else if (!strcasecmp(key, "email;internet")) { if (primary_inetemail[0] == 0) { - strcpy(primary_inetemail, value); + safestrncpy(primary_inetemail, value, sizeof primary_inetemail); } else { if (other_inetemail[0] != 0) { @@ -175,107 +173,174 @@ void do_edit_vcard(long msgnum, char *partnum, char *return_to) { vcard_free(v); } - /* Display the form */ - do_template("beginbox_nt"); - wprintf("
\n"); - wprintf("

" - "Contact information for "); - escputs(whatuser); - wprintf("

\n"); - - wprintf("" - "" - "" - "" - "" - "\n"); - wprintf("", + /** Display the form */ + output_headers(1, 1, 2, 0, 0, 0); + wprintf("
\n"); + wprintf(""); + wprintf("

"); + wprintf(_("Edit contact information")); + wprintf("

"); + wprintf("
\n"); + wprintf("
\n"); + + wprintf("\n"); + wprintf("\n", WC->nonce); + wprintf("
" + "
PrefixFirstMiddleLastSuffix
\n"); + + wprintf("" + "" + "" + "" + "" + "\n", + _("Prefix"), _("First"), _("Middle"), _("Last"), _("Suffix") + ); + wprintf("", prefix); - wprintf("", + wprintf("", firstname); - wprintf("", + wprintf("", middlename); - wprintf("", + wprintf("", lastname); - wprintf("
%s%s%s%s%s
\n", + wprintf("
\n", suffix); - wprintf("" - "\n", + wprintf("
PO box (optional):
"); + wprintf("\n", country); + wprintf("
"); + + wprintf(_("Display name:")); + wprintf("
" + "

\n", + fullname + ); + + wprintf(_("Title:")); + wprintf("
" + "

\n", + title + ); + + wprintf(_("Organization:")); + wprintf("
" + "

\n", + org + ); + + wprintf("
"); + + wprintf(""); + wprintf("\n", pobox); - wprintf("" - "\n", + wprintf("\n", extadr); - wprintf("" - "\n", + wprintf("\n", street); - wprintf("" - "\n", city); - wprintf(" State: " - "\n", + wprintf("\n", state); - wprintf(" ZIP code: " - "\n", + wprintf("\n", zipcode); - wprintf("" - "
"); + wprintf(_("PO box:")); + wprintf("" + "
Address line 1:
"); + wprintf(_("Address:")); + wprintf("" + "
Address line 2:
" + "
City:\n", + wprintf("
"); + wprintf(_("City:")); + wprintf("" + "
"); + wprintf(_("State:")); + wprintf("" + "
"); + wprintf(_("ZIP code:")); + wprintf("" + "
Country:
\n", + wprintf("
"); + wprintf(_("Country:")); + wprintf("" + "
\n"); + + wprintf("\n"); - wprintf("" - "\n", + wprintf("
Home telephone:
" + "\n", hometel); - wprintf("" - "
"); + wprintf(_("Home telephone:")); + wprintf("
Work telephone:
\n", + wprintf(""); + wprintf(_("Work telephone:")); + wprintf("" + "\n", worktel); - wprintf("
" - "
Primary Internet e-mail address
" - ""); + wprintf("
"); + + wprintf("" + "
"); + wprintf(_("Primary Internet e-mail address")); + wprintf("
" + "
" - "
" - "Other Internet e-mail addresses
" - "

\n"); + wprintf("
\n"); + + wprintf("\n"); - wprintf("\n"); - wprintf("\n"); - wprintf("
\n" - "" + wprintf("
\n" + "" " " - "" - "
\n" + "" + "
\n", + _("Save changes"), + _("Cancel") ); - do_template("endbox"); + wprintf("\n"); wDumpContent(1); } - +/** + * \brief commit the edits to the citadel server + */ void edit_vcard(void) { long msgnum; char *partnum; @@ -287,34 +352,56 @@ void edit_vcard(void) { - +/** + * \brief parse edited vcard from the browser + */ void submit_vcard(void) { + struct vCard *v; + char *serialized_vcard; char buf[SIZ]; int i; - if (strcmp(bstr("sc"), "OK")) { + if (IsEmptyStr(bstr("ok_button"))) { readloop("readnew"); return; } sprintf(buf, "ENT0 1|||4||"); serv_puts(buf); - serv_gets(buf); + serv_getln(buf, sizeof buf); if (buf[0] != '4') { edit_vcard(); return; } - serv_puts("Content-type: text/x-vcard"); - serv_puts(""); - serv_puts("begin:vcard"); - serv_printf("n:%s;%s;%s;%s;%s", + /** Make a vCard structure out of the data supplied in the form */ + + snprintf(buf, sizeof buf, "begin:vcard\r\n%s\r\nend:vcard\r\n", + bstr("extrafields") + ); + v = vcard_load(buf); /** Start with the extra fields */ + if (v == NULL) { + safestrncpy(WC->ImportantMessage, + _("An error has occurred."), + sizeof WC->ImportantMessage + ); + edit_vcard(); + return; + } + + snprintf(buf, sizeof buf, "%s;%s;%s;%s;%s", bstr("lastname"), bstr("firstname"), bstr("middlename"), bstr("prefix"), bstr("suffix") ); - serv_printf("adr:%s;%s;%s;%s;%s;%s;%s", + vcard_add_prop(v, "n", buf); + + vcard_add_prop(v, "title", bstr("title")); + vcard_add_prop(v, "fn", bstr("fullname")); + vcard_add_prop(v, "org", bstr("org")); + + snprintf(buf, sizeof buf, "%s;%s;%s;%s;%s;%s;%s", bstr("pobox"), bstr("extadr"), bstr("street"), @@ -322,28 +409,47 @@ void submit_vcard(void) { bstr("state"), bstr("zipcode"), bstr("country") ); - serv_printf("tel;home:%s", bstr("hometel") ); - serv_printf("tel;work:%s", bstr("worktel") ); + vcard_add_prop(v, "adr", buf); + + vcard_add_prop(v, "tel;home", bstr("hometel")); + vcard_add_prop(v, "tel;work", bstr("worktel")); + vcard_add_prop(v, "email;internet", bstr("primary_inetemail")); - serv_printf("email;internet:%s\n", bstr("primary_inetemail")); for (i=0; i 0) { - serv_printf("email;internet:%s", buf); + extract_token(buf, bstr("other_inetemail"), i, '\n', sizeof buf); + if (!IsEmptyStr(buf)) { + vcard_add_prop(v, "email;internet", buf); } } - serv_printf("%s", bstr("extrafields") ); - serv_puts("end:vcard"); + serialized_vcard = vcard_serialize(v); + vcard_free(v); + if (serialized_vcard == NULL) { + safestrncpy(WC->ImportantMessage, + _("An error has occurred."), + sizeof WC->ImportantMessage + ); + edit_vcard(); + return; + } + + serv_puts("Content-type: text/x-vcard; charset=UTF-8"); + serv_puts(""); + serv_printf("%s\r\n", serialized_vcard); serv_puts("000"); + free(serialized_vcard); - if (!strcmp(bstr("return_to"), "/select_user_to_edit")) { + if (!strcmp(bstr("return_to"), "select_user_to_edit")) { select_user_to_edit(NULL, NULL); } - else if (!strcmp(bstr("return_to"), "/do_welcome")) { + else if (!strcmp(bstr("return_to"), "do_welcome")) { do_welcome(); } else { readloop("readnew"); } } + + + +/*@}*/