]> code.citadel.org Git - citadel.git/blob - webcit/vcard_edit.c
* More vCard editing stuff
[citadel.git] / webcit / vcard_edit.c
1 /*
2  * vcard_edit.c
3  *
4  * Handles editing of vCard objects.
5  *
6  * $Id$
7  */
8
9 #include <ctype.h>
10 #include <stdlib.h>
11 #include <unistd.h>
12 #include <stdio.h>
13 #include <fcntl.h>
14 #include <signal.h>
15 #include <sys/types.h>
16 #include <sys/wait.h>
17 #include <sys/socket.h>
18 #include <sys/time.h>
19 #include <limits.h>
20 #include <netinet/in.h>
21 #include <netdb.h>
22 #include <string.h>
23 #include <pwd.h>
24 #include <errno.h>
25 #include <stdarg.h>
26 #include <pthread.h>
27 #include <signal.h>
28 #include "webcit.h"
29 #include "vcard.h"
30
31
32
33 void edit_vcard(void) {
34         char buf[SIZ];
35         char *serialized_vcard = NULL;
36         size_t total_len = 0;
37         size_t bytes = 0;
38         size_t thisblock = 0;
39         struct vCard *v;
40         int i;
41         char *key, *value;
42
43         char lastname[SIZ];
44         char firstname[SIZ];
45         char middlename[SIZ];
46         char prefix[SIZ];
47         char suffix[SIZ];
48         char pobox[SIZ];
49         char extadr[SIZ];
50         char street[SIZ];
51         char city[SIZ];
52         char state[SIZ];
53         char zipcode[SIZ];
54         char country[SIZ];
55         char extrafields[SIZ];
56
57         lastname[0] = 0;
58         firstname[0] = 0;
59         middlename[0] = 0;
60         prefix[0] = 0;
61         suffix[0] = 0;
62         pobox[0] = 0;
63         extadr[0] = 0;
64         street[0] = 0;
65         city[0] = 0;
66         state[0] = 0;
67         zipcode[0] = 0;
68         country[0] = 0;
69         extrafields[0] = 0;
70
71         output_headers(1);
72         sprintf(buf, "OPNA %s|%s", bstr("msgnum"), bstr("partnum") );
73         serv_puts(buf);
74         serv_gets(buf);
75         if (buf[0] != '2') {
76                 wDumpContent(1);
77                 return;
78         }
79
80         total_len = atoi(&buf[4]);
81         serialized_vcard = malloc(total_len + 1);
82         while (bytes < total_len) {
83                 thisblock = 4000;
84                 if ((total_len - bytes) < thisblock) thisblock = total_len - bytes;
85                 sprintf(buf, "READ %d|%d", bytes, thisblock);
86                 serv_puts(buf);
87                 serv_gets(buf);
88                 if (buf[0] == '6') {
89                         thisblock = atoi(&buf[4]);
90                         serv_read(&serialized_vcard[bytes], thisblock);
91                         bytes += thisblock;
92                 }
93                 else {
94                         wprintf("Error: %s<BR>\n", &buf[4]);
95                 }
96         }
97
98         serv_puts("CLOS");
99         serv_gets(buf);
100         serialized_vcard[total_len + 1] = 0;
101
102         v = vcard_load(serialized_vcard);
103         free(serialized_vcard);
104
105         /* Populate the variables for our form */
106         i = 0;
107         while (key = vcard_get_prop(v, "", 0, i, 1), key != NULL) {
108                 value = vcard_get_prop(v, "", 0, i++, 0);
109
110                 if (!strcasecmp(key, "n")) {
111                         extract_token(lastname, value, 0, ';');
112                         extract_token(firstname, value, 1, ';');
113                         extract_token(middlename, value, 2, ';');
114                         extract_token(prefix, value, 3, ';');
115                         extract_token(suffix, value, 4, ';');
116                 }
117
118                 else if (!strcasecmp(key, "adr")) {
119                         extract_token(pobox, value, 0, ';');
120                         extract_token(extadr, value, 1, ';');
121                         extract_token(street, value, 2, ';');
122                         extract_token(city, value, 3, ';');
123                         extract_token(state, value, 4, ';');
124                         extract_token(zipcode, value, 5, ';');
125                         extract_token(country, value, 6, ';');
126                 }
127
128                 else {
129                         strcat(extrafields, key);
130                         strcat(extrafields, ":");
131                         strcat(extrafields, value);
132                         strcat(extrafields, "\n");
133                 }
134
135         }
136         
137         vcard_free(v);
138
139         /* Display the form */
140         wprintf("<FORM METHOD=\"POST\" ACTION=\"/do_FIXME_stuff\">\n");
141         wprintf("<H2><IMG VALIGN=CENTER SRC=\"/static/vcard.gif\">"
142                 "Contact information for FIXME</H2>\n");
143
144         wprintf("Last name: "
145                 "<INPUT TYPE=\"text\" NAME=\"lastname\" "
146                 "VALUE=\"%s\" MAXLENGTH=\"29\"><BR>\n",
147                 lastname);
148         wprintf("First name: "
149                 "<INPUT TYPE=\"text\" NAME=\"firstname\" "
150                 "VALUE=\"%s\" MAXLENGTH=\"29\"><BR>\n",
151                 firstname);
152         wprintf("Prefix: "
153                 "<INPUT TYPE=\"text\" NAME=\"prefix\" "
154                 "VALUE=\"%s\" MAXLENGTH=\"5\"><BR>\n",
155                 prefix);
156         wprintf("Suffix: "
157                 "<INPUT TYPE=\"text\" NAME=\"suffix\" "
158                 "VALUE=\"%s\" MAXLENGTH=\"10\"><BR><BR>\n",
159                 suffix);
160
161         wprintf("<TABLE border=0><TR><TD>Address - PO box; optional:</TD>"
162                 "<TD><INPUT TYPE=\"text\" NAME=\"pobox\" "
163                 "VALUE=\"%s\" MAXLENGTH=\"29\"></TD></TR>\n",
164                 pobox);
165         wprintf("<TR><TD>Street:</TD>"
166                 "<TD><INPUT TYPE=\"text\" NAME=\"extadr\" "
167                 "VALUE=\"%s\" MAXLENGTH=\"29\"></TD></TR>\n",
168                 extadr);
169         wprintf("<TR><TD>&nbsp;</TD>"
170                 "<TD><INPUT TYPE=\"text\" NAME=\"street\" "
171                 "VALUE=\"%s\" MAXLENGTH=\"29\"></TD></TR>\n",
172                 street);
173         wprintf("<TR><TD>City:</TD>"
174                 "<TD><INPUT TYPE=\"text\" NAME=\"city\" "
175                 "VALUE=\"%s\" MAXLENGTH=\"29\">\n",
176                 city);
177         wprintf(" State: "
178                 "<INPUT TYPE=\"text\" NAME=\"state\" "
179                 "VALUE=\"%s\" MAXLENGTH=\"2\">\n",
180                 state);
181         wprintf(" ZIP code: "
182                 "<INPUT TYPE=\"text\" NAME=\"zipcode\" "
183                 "VALUE=\"%s\" MAXLENGTH=\"10\"></TD></TR>\n",
184                 zipcode);
185         wprintf("<TR><TD>Country:</TD>"
186                 "<TD><INPUT TYPE=\"text\" NAME=\"country\" "
187                 "VALUE=\"%s\" MAXLENGTH=\"29\"></TD></TR></TABLE>\n",
188                 country);
189
190         wprintf("<TEXTAREA NAME=\"extrafields\" ROWS=10 COLS=80 WIDTH=80>");
191         escputs(extrafields);
192         wprintf("</TEXTAREA><BR>\n");
193
194          
195         wDumpContent(1);
196 }