]> code.citadel.org Git - citadel.git/blob - webcit/vcard_edit.c
* Wrote some skeleton code for robust vCard editing
[citadel.git] / webcit / vcard_edit.c
1 /*
2  * vcard_edit.c
3  *
4  * Handles editing of vCard objects.
5  *
6  * $Id$
7  */
8
9
10 #include <ctype.h>
11 #include <stdlib.h>
12 #include <unistd.h>
13 #include <stdio.h>
14 #include <fcntl.h>
15 #include <signal.h>
16 #include <sys/types.h>
17 #include <sys/wait.h>
18 #include <sys/socket.h>
19 #include <sys/time.h>
20 #include <limits.h>
21 #include <netinet/in.h>
22 #include <netdb.h>
23 #include <string.h>
24 #include <pwd.h>
25 #include <errno.h>
26 #include <stdarg.h>
27 #include <pthread.h>
28 #include <signal.h>
29 #include "webcit.h"
30 #include "vcard.h"
31
32
33
34 void edit_vcard(void) {
35         char buf[SIZ];
36         char *serialized_vcard = NULL;
37         size_t total_len = 0;
38         size_t bytes = 0;
39         size_t thisblock = 0;
40         struct vCard *v;
41         int i;
42         char *prop;
43
44         output_headers(1);
45         sprintf(buf, "OPNA %s|%s", bstr("msgnum"), bstr("partnum") );
46         serv_puts(buf);
47         serv_gets(buf);
48         if (buf[0] != '2') {
49                 wDumpContent(1);
50                 return;
51         }
52
53         total_len = atoi(&buf[4]);
54         serialized_vcard = malloc(total_len + 1);
55         while (bytes < total_len) {
56                 thisblock = 4000;
57                 if ((total_len - bytes) < thisblock) thisblock = total_len - bytes;
58                 sprintf(buf, "READ %d|%d", bytes, thisblock);
59                 serv_puts(buf);
60                 serv_gets(buf);
61                 if (buf[0] == '6') {
62                         thisblock = atoi(&buf[4]);
63                         serv_read(&serialized_vcard[bytes], thisblock);
64                         bytes += thisblock;
65                 }
66                 else {
67                         wprintf("Error: %s<BR>\n", &buf[4]);
68                 }
69         }
70
71         serv_puts("CLOS");
72         serv_gets(buf);
73         serialized_vcard[total_len + 1] = 0;
74
75         v = vcard_load(serialized_vcard);
76         free(serialized_vcard);
77
78         wprintf("<BLINK>   FIXME    </BLINK><BR><BR>\n"
79                 "This needs to be implemented as an editable form.<BR><BR>\n");
80
81         i = 0;
82         while (prop = vcard_get_prop(v, "", 0, i++), prop != NULL) {
83                 escputs(prop);
84                 wprintf("<BR>\n");
85         }
86         
87         vcard_free(v);
88          
89         wDumpContent(1);
90 }