From 9b401ace7f8430ec5085e77995d51309a6bc341d Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Sat, 19 Oct 2002 04:16:37 +0000 Subject: [PATCH] * Save an incoming meeting request into the user's calendar. --- webcit/ChangeLog | 4 +- webcit/calendar.c | 117 ++++++++++++++++++++++++++++++++++++++++++-- webcit/roomops.c | 6 +-- webcit/tools.c | 26 ++++++++++ webcit/vcard_edit.c | 22 +-------- webcit/webcit.h | 3 ++ 6 files changed, 150 insertions(+), 28 deletions(-) diff --git a/webcit/ChangeLog b/webcit/ChangeLog index 81c08bb0a..96be6dea2 100644 --- a/webcit/ChangeLog +++ b/webcit/ChangeLog @@ -1,4 +1,7 @@ $Log$ +Revision 400.40 2002/10/19 04:16:37 ajc +* Save an incoming meeting request into the user's calendar. + Revision 400.39 2002/10/18 20:55:05 ajc * Began work on meeting request accept/decline @@ -1074,4 +1077,3 @@ Sun Dec 6 19:50:55 EST 1998 Art Cancro 1998-12-03 Nathan Bryant * webserver.c: warning fix - diff --git a/webcit/calendar.c b/webcit/calendar.c index 84ccc0ea6..0c6c4b26b 100644 --- a/webcit/calendar.c +++ b/webcit/calendar.c @@ -193,6 +193,69 @@ void cal_process_object(icalcomponent *cal, } +/* + * Back end for cal_add() -- this writes it to the message base + */ +void pencil_it_in(icalcomponent *cal) { + char hold_rm[SIZ]; + char buf[SIZ]; + char *serialized_event; + + /* Save the name of the room we're in */ + strcpy(hold_rm, WC->wc_roomname); + + /* Go find the user's calendar */ + serv_printf("GOTO %s", CALENDAR_ROOM_NAME); + serv_gets(buf); + if (buf[0] != '2') return; + + /* Enter the message */ + serialized_event = icalcomponent_as_ical_string(cal); + if (serialized_event != NULL) { + sprintf(buf, "ENT0 1|||4||"); + serv_puts(buf); + serv_gets(buf); + if (buf[0] == '4') { + serv_puts("Content-type: text/calendar"); + serv_puts(""); + serv_write(serialized_event, strlen(serialized_event)); + serv_puts(""); + serv_puts("000"); + } + } + + /* Return to the room we were in */ + serv_printf("GOTO %s", hold_rm); + serv_gets(buf); +} + + +/* + * Add a calendar object to the user's calendar + */ +void cal_add(icalcomponent *cal, int recursion_level) { + icalcomponent *c; + + /* + * The VEVENT subcomponent is the one we're interested in saving. + */ + if (icalcomponent_isa(cal) == ICAL_VEVENT_COMPONENT) { + /* Save to the message base */ + pencil_it_in(cal); + + } + + /* If the component has subcomponents, recurse through them. */ + for (c = icalcomponent_get_first_component(cal, ICAL_ANY_COMPONENT); + (c != 0); + c = icalcomponent_get_next_component(cal, ICAL_ANY_COMPONENT)) { + /* Recursively process subcomponent */ + cal_add(c, recursion_level+1); + } + +} + + /* * Deserialize a calendar object in a message so it can be processed. * (This is the main entry point for these things) @@ -221,6 +284,11 @@ void cal_process_attachment(char *part_source, long msgnum, char *cal_partnum) { * Respond to a meeting request */ void respond_to_request(void) { + char buf[SIZ]; + size_t total_len; + char *serialized_cal; + icalcomponent *cal; + output_headers(3); wprintf("
" @@ -229,12 +297,53 @@ void respond_to_request(void) { "

\n" ); - wprintf("msgnum = %s
\n", bstr("msgnum")); - wprintf("cal_partnum = %s
\n", bstr("cal_partnum")); - wprintf("sc = %s
\n", bstr("sc")); + sprintf(buf, "OPNA %s|%s", bstr("msgnum"), bstr("cal_partnum")); + serv_puts(buf); + serv_gets(buf); + if (buf[0] != '2') { + wprintf("Error: %s
\n", &buf[4]); + wDumpContent(1); + return; + } + + total_len = atoi(&buf[4]); + serialized_cal = malloc(total_len + 1); + + read_server_binary(serialized_cal, total_len); + + serv_puts("CLOS"); + serv_gets(buf); + serialized_cal[total_len + 1] = 0; + + /* Deserialize it */ + cal = icalcomponent_new_from_string(serialized_cal); + free(serialized_cal); + + if (cal == NULL) { + wprintf("Error parsing calendar object: %s
\n", + icalerror_strerror(icalerrno)); + wDumpContent(1); + return; + } + + /* Save this in the user's calendar if necessary */ + if (!strcasecmp(bstr("sc"), "Accept")) { + cal_add(cal, 0); + } + + /* Send a reply if necessary */ + /* FIXME ... do this */ + + /* Free the memory we obtained from libical's constructor */ + icalcomponent_free(cal); + + /* Delete the message from the inbox */ + /* FIXME ... do this */ + - /* use OPNA command to foo this */ + wprintf("Done!
\n"); + /* ...and now we're done. */ wDumpContent(1); } diff --git a/webcit/roomops.c b/webcit/roomops.c index 3be38e159..65f018071 100644 --- a/webcit/roomops.c +++ b/webcit/roomops.c @@ -476,7 +476,7 @@ void gotoroom(char *gname, int display_name) */ char *pop_march(int desired_floor) { - static char TheRoom[64]; + static char TheRoom[128]; int TheFloor = 0; int TheOrder = 32767; int TheWeight = 0; @@ -520,7 +520,7 @@ void gotonext(void) { char buf[SIZ]; struct march *mptr, *mptr2; - char next_room[32]; + char next_room[128]; /* First check to see if the march-mode list is already allocated. * If it is, pop the first room off the list and go there. @@ -1531,7 +1531,7 @@ void display_private(char *rname, int req_pass) */ void goto_private(void) { - char hold_rm[32]; + char hold_rm[SIZ]; char buf[SIZ]; if (strcasecmp(bstr("sc"), "OK")) { diff --git a/webcit/tools.c b/webcit/tools.c index a5b943b27..bc1113cb4 100644 --- a/webcit/tools.c +++ b/webcit/tools.c @@ -328,3 +328,29 @@ int is_msg_in_mset(char *mset, long msgnum) { } + +/* + * Read binary data from server into memory + */ +void read_server_binary(char *buffer, size_t total_len) { + char buf[SIZ]; + size_t bytes = 0; + size_t thisblock = 0; + + while (bytes < total_len) { + thisblock = 4095; + if ((total_len - bytes) < thisblock) { + thisblock = total_len - bytes; + } + serv_printf("READ %d|%d", (int)bytes, (int)thisblock); + serv_gets(buf); + if (buf[0] == '6') { + thisblock = (size_t)atoi(&buf[4]); + serv_read(&buffer[bytes], thisblock); + bytes += thisblock; + } + else { + wprintf("Error: %s
\n", &buf[4]); + } + } +} diff --git a/webcit/vcard_edit.c b/webcit/vcard_edit.c index 151edcb86..8a9d1b429 100644 --- a/webcit/vcard_edit.c +++ b/webcit/vcard_edit.c @@ -34,8 +34,6 @@ void do_edit_vcard(long msgnum, char *partnum, char *return_to) { char buf[SIZ]; char *serialized_vcard = NULL; size_t total_len = 0; - size_t bytes = 0; - size_t thisblock = 0; struct vCard *v; int i; char *key, *value; @@ -95,9 +93,6 @@ void do_edit_vcard(long msgnum, char *partnum, char *return_to) { } } - total_len = atoi(&buf[4]); - - sprintf(buf, "OPNA %ld|%s", msgnum, partnum); serv_puts(buf); serv_gets(buf); @@ -108,21 +103,8 @@ void do_edit_vcard(long msgnum, char *partnum, char *return_to) { total_len = atoi(&buf[4]); serialized_vcard = malloc(total_len + 1); - while (bytes < total_len) { - thisblock = 4000; - if ((total_len - bytes) < thisblock) thisblock = total_len - bytes; - sprintf(buf, "READ %d|%d", (int)bytes, (int)thisblock); - serv_puts(buf); - serv_gets(buf); - if (buf[0] == '6') { - thisblock = atoi(&buf[4]); - serv_read(&serialized_vcard[bytes], thisblock); - bytes += thisblock; - } - else { - wprintf("Error: %s
\n", &buf[4]); - } - } + + read_server_binary(serialized_vcard, total_len); serv_puts("CLOS"); serv_gets(buf); diff --git a/webcit/webcit.h b/webcit/webcit.h index eeb434af9..294762e38 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -8,6 +8,8 @@ #include #endif +#define CALENDAR_ROOM_NAME "Calendar" + #define SIZ 4096 /* generic buffer size */ #define TRACE fprintf(stderr, "Checkpoint: %s, %d\n", __FILE__, __LINE__) @@ -366,3 +368,4 @@ void respond_to_request(void); extern char *months[]; extern char *days[]; +void read_server_binary(char *buffer, size_t total_len); -- 2.39.2