]> code.citadel.org Git - citadel.git/blob - webcit/vcard_edit.c
* a few more fields
[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 hometel[SIZ];
56         char worktel[SIZ];
57         char extrafields[SIZ];
58
59         lastname[0] = 0;
60         firstname[0] = 0;
61         middlename[0] = 0;
62         prefix[0] = 0;
63         suffix[0] = 0;
64         pobox[0] = 0;
65         extadr[0] = 0;
66         street[0] = 0;
67         city[0] = 0;
68         state[0] = 0;
69         zipcode[0] = 0;
70         country[0] = 0;
71         hometel[0] = 0;
72         worktel[0] = 0;
73         extrafields[0] = 0;
74
75         output_headers(1);
76         sprintf(buf, "OPNA %s|%s", bstr("msgnum"), bstr("partnum") );
77         serv_puts(buf);
78         serv_gets(buf);
79         if (buf[0] != '2') {
80                 wDumpContent(1);
81                 return;
82         }
83
84         total_len = atoi(&buf[4]);
85         serialized_vcard = malloc(total_len + 1);
86         while (bytes < total_len) {
87                 thisblock = 4000;
88                 if ((total_len - bytes) < thisblock) thisblock = total_len - bytes;
89                 sprintf(buf, "READ %d|%d", bytes, thisblock);
90                 serv_puts(buf);
91                 serv_gets(buf);
92                 if (buf[0] == '6') {
93                         thisblock = atoi(&buf[4]);
94                         serv_read(&serialized_vcard[bytes], thisblock);
95                         bytes += thisblock;
96                 }
97                 else {
98                         wprintf("Error: %s<BR>\n", &buf[4]);
99                 }
100         }
101
102         serv_puts("CLOS");
103         serv_gets(buf);
104         serialized_vcard[total_len + 1] = 0;
105
106         v = vcard_load(serialized_vcard);
107         free(serialized_vcard);
108
109         /* Populate the variables for our form */
110         i = 0;
111         while (key = vcard_get_prop(v, "", 0, i, 1), key != NULL) {
112                 value = vcard_get_prop(v, "", 0, i++, 0);
113
114                 if (!strcasecmp(key, "n")) {
115                         extract_token(lastname, value, 0, ';');
116                         extract_token(firstname, value, 1, ';');
117                         extract_token(middlename, value, 2, ';');
118                         extract_token(prefix, value, 3, ';');
119                         extract_token(suffix, value, 4, ';');
120                 }
121
122                 else if (!strcasecmp(key, "adr")) {
123                         extract_token(pobox, value, 0, ';');
124                         extract_token(extadr, value, 1, ';');
125                         extract_token(street, value, 2, ';');
126                         extract_token(city, value, 3, ';');
127                         extract_token(state, value, 4, ';');
128                         extract_token(zipcode, value, 5, ';');
129                         extract_token(country, value, 6, ';');
130                 }
131
132                 else if (!strcasecmp(key, "tel;home")) {
133                         extract_token(hometel, value, 0, ';');
134                 }
135
136                 else if (!strcasecmp(key, "tel;work")) {
137                         extract_token(hometel, value, 0, ';');
138                 }
139
140                 else {
141                         strcat(extrafields, key);
142                         strcat(extrafields, ":");
143                         strcat(extrafields, value);
144                         strcat(extrafields, "\n");
145                 }
146
147         }
148         
149         vcard_free(v);
150
151         /* Display the form */
152         wprintf("<FORM METHOD=\"POST\" ACTION=\"/do_FIXME_stuff\">\n");
153         wprintf("<H2><IMG VALIGN=CENTER SRC=\"/static/vcard.gif\">"
154                 "Contact information for FIXME</H2>\n");
155
156         wprintf("Last name: "
157                 "<INPUT TYPE=\"text\" NAME=\"lastname\" "
158                 "VALUE=\"%s\" MAXLENGTH=\"29\"><BR>\n",
159                 lastname);
160         wprintf("First name: "
161                 "<INPUT TYPE=\"text\" NAME=\"firstname\" "
162                 "VALUE=\"%s\" MAXLENGTH=\"29\"><BR>\n",
163                 firstname);
164         wprintf("Prefix: "
165                 "<INPUT TYPE=\"text\" NAME=\"prefix\" "
166                 "VALUE=\"%s\" MAXLENGTH=\"5\"><BR>\n",
167                 prefix);
168         wprintf("Suffix: "
169                 "<INPUT TYPE=\"text\" NAME=\"suffix\" "
170                 "VALUE=\"%s\" MAXLENGTH=\"10\"><BR><BR>\n",
171                 suffix);
172
173         wprintf("<TABLE border=0><TR><TD>Address - PO box; optional:</TD>"
174                 "<TD><INPUT TYPE=\"text\" NAME=\"pobox\" "
175                 "VALUE=\"%s\" MAXLENGTH=\"29\"></TD></TR>\n",
176                 pobox);
177         wprintf("<TR><TD>Street:</TD>"
178                 "<TD><INPUT TYPE=\"text\" NAME=\"extadr\" "
179                 "VALUE=\"%s\" MAXLENGTH=\"29\"></TD></TR>\n",
180                 extadr);
181         wprintf("<TR><TD>&nbsp;</TD>"
182                 "<TD><INPUT TYPE=\"text\" NAME=\"street\" "
183                 "VALUE=\"%s\" MAXLENGTH=\"29\"></TD></TR>\n",
184                 street);
185         wprintf("<TR><TD>City:</TD>"
186                 "<TD><INPUT TYPE=\"text\" NAME=\"city\" "
187                 "VALUE=\"%s\" MAXLENGTH=\"29\">\n",
188                 city);
189         wprintf(" State: "
190                 "<INPUT TYPE=\"text\" NAME=\"state\" "
191                 "VALUE=\"%s\" MAXLENGTH=\"2\">\n",
192                 state);
193         wprintf(" ZIP code: "
194                 "<INPUT TYPE=\"text\" NAME=\"zipcode\" "
195                 "VALUE=\"%s\" MAXLENGTH=\"10\"></TD></TR>\n",
196                 zipcode);
197         wprintf("<TR><TD>Country:</TD>"
198                 "<TD><INPUT TYPE=\"text\" NAME=\"country\" "
199                 "VALUE=\"%s\" MAXLENGTH=\"29\"></TD></TR></TABLE>\n",
200                 country);
201
202         wprintf("<TABLE BORDER=0><TR><TD>Home telephone:</TD>"
203                 "<TD><INPUT TYPE=\"text\" NAME=\"hometel\" "
204                 "VALUE=\"%s\" MAXLENGTH=\"29\"></TD></TR>\n",
205                 hometel);
206         wprintf("<TR><TD>Work telephone:</TD>"
207                 "<TD><INPUT TYPE=\"text\" NAME=\"worktel\" "
208                 "VALUE=\"%s\" MAXLENGTH=\"29\"></TD></TR></TABLE>\n",
209                 worktel);
210
211         wprintf("<TEXTAREA NAME=\"extrafields\" ROWS=10 COLS=80 WIDTH=80>");
212         escputs(extrafields);
213         wprintf("</TEXTAREA><BR>\n");
214
215          
216         wDumpContent(1);
217 }