From 576df19cae13f5937c2e55bdc6fee10038512e80 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Thu, 20 Oct 2005 02:56:44 +0000 Subject: [PATCH] * serv_calendar.c: registered a fixed output hook for text/calendar. --- citadel/ChangeLog | 3 + citadel/ft_wordbreaker.h | 2 +- citadel/serv_calendar.c | 138 ++++++++++++++++++++++++++++++++++++++ citadel/serv_extensions.c | 1 - 4 files changed, 142 insertions(+), 2 deletions(-) diff --git a/citadel/ChangeLog b/citadel/ChangeLog index 78ec35ca7..39866b966 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -1,3 +1,6 @@ +Wed Oct 19 22:55:19 EDT 2005 ajc +* serv_calendar.c: registered a fixed output hook for text/calendar. + Wed Oct 19 13:30:16 EDT 2005 ajc * New type of server hook: CtdlRegisterFixedOutputHook(). This is for extending the fixed_output() function for arbitrary new MIME types. The diff --git a/citadel/ft_wordbreaker.h b/citadel/ft_wordbreaker.h index 4d6fcc099..caca77d29 100644 --- a/citadel/ft_wordbreaker.h +++ b/citadel/ft_wordbreaker.h @@ -9,7 +9,7 @@ * later on, or even if we update this one, we can use a different ID so the * system knows it needs to throw away the existing index and rebuild it. */ -#define FT_WORDBREAKER_ID 0x001b +#define FT_WORDBREAKER_ID 0x001c /* * Minimum and maximum length of words to index diff --git a/citadel/serv_calendar.c b/citadel/serv_calendar.c index 9baed0f75..2d8a38240 100644 --- a/citadel/serv_calendar.c +++ b/citadel/serv_calendar.c @@ -1893,6 +1893,143 @@ void ical_session_shutdown(void) { } +/* + * Back end for ical_fixed_output() + */ +void ical_fixed_output_backend(icalcomponent *cal, + int recursion_level +) { + icalcomponent *c; + icalproperty *method = NULL; + icalproperty_method the_method = ICAL_METHOD_NONE; + icalproperty *p; + struct icaltimetype t; + time_t tt; + char buf[256]; + + /* Look for a method */ + method = icalcomponent_get_first_property(cal, ICAL_METHOD_PROPERTY); + + /* See what we need to do with this */ + if (method != NULL) { + the_method = icalproperty_get_method(method); + switch(the_method) { + case ICAL_METHOD_REQUEST: + cprintf("Meeting invitation\n"); + break; + case ICAL_METHOD_REPLY: + cprintf("Attendee's reply to your invitation\n"); + break; + case ICAL_METHOD_PUBLISH: + cprintf("Published event\n"); + break; + default: + cprintf("This is an unknown type of calendar item.\n"); + break; + } + } + + p = icalcomponent_get_first_property(cal, ICAL_SUMMARY_PROPERTY); + if (p != NULL) { + cprintf("Summary: %s\n", (const char *)icalproperty_get_comment(p)); + } + + p = icalcomponent_get_first_property(cal, ICAL_LOCATION_PROPERTY); + if (p != NULL) { + cprintf("Location: %s\n", (const char *)icalproperty_get_comment(p)); + } + + /* + * Only show start/end times if we're actually looking at the VEVENT + * component. Otherwise it shows bogus dates for things like timezone. + */ + if (icalcomponent_isa(cal) == ICAL_VEVENT_COMPONENT) { + + p = icalcomponent_get_first_property(cal, + ICAL_DTSTART_PROPERTY); + if (p != NULL) { + t = icalproperty_get_dtstart(p); + + if (t.is_date) { + cprintf("Date: %s %d, %d\n", + ascmonths[t.month - 1], + t.day, t.year + ); + } + else { + tt = icaltime_as_timet(t); + fmt_date(buf, sizeof buf, tt, 0); + cprintf("Starting date/time: %s\n", buf); + } + } + + p = icalcomponent_get_first_property(cal, ICAL_DTEND_PROPERTY); + if (p != NULL) { + t = icalproperty_get_dtend(p); + tt = icaltime_as_timet(t); + fmt_date(buf, sizeof buf, tt, 0); + cprintf("Ending date/time: %s\n", buf); + } + + } + + p = icalcomponent_get_first_property(cal, ICAL_DESCRIPTION_PROPERTY); + if (p != NULL) { + cprintf("Description: %s\n", (const char *)icalproperty_get_comment(p)); + } + + /* If the component has attendees, iterate through them. */ + for (p = icalcomponent_get_first_property(cal, ICAL_ATTENDEE_PROPERTY); (p != NULL); p = icalcomponent_get_next_property(cal, ICAL_ATTENDEE_PROPERTY)) { + cprintf("Attendee: "); + safestrncpy(buf, icalproperty_get_attendee(p), sizeof buf); + if (!strncasecmp(buf, "MAILTO:", 7)) { + + /* screen name or email address */ + strcpy(buf, &buf[7]); + striplt(buf); + cprintf("%s ", buf); + } + cprintf("\n"); + } + + /* 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 */ + ical_fixed_output_backend(c, recursion_level+1); + } +} + + + +/* + * Function to output a calendar item as plain text. Nobody uses MSG0 + * anymore, so really this is just so we expose the vCard data to the full + * text indexer. + */ +void ical_fixed_output(char *ptr, int len) { + icalcomponent *cal; + char *stringy_cal; + + stringy_cal = malloc(len + 1); + safestrncpy(stringy_cal, ptr, len + 1); + cal = icalcomponent_new_from_string(stringy_cal); + free(stringy_cal); + + if (cal == NULL) { + cprintf("There was an error parsing this calendar item.\n"); + return; + } + + ical_dezonify(cal); + ical_fixed_output_backend(cal, 0); + + /* Free the memory we obtained from libical's constructor */ + icalcomponent_free(cal); +} + + #endif /* CITADEL_WITH_CALENDAR_SERVICE */ /* @@ -1907,6 +2044,7 @@ char *serv_calendar_init(void) CtdlRegisterProtoHook(cmd_ical, "ICAL", "Citadel iCal commands"); CtdlRegisterSessionHook(ical_session_startup, EVT_START); CtdlRegisterSessionHook(ical_session_shutdown, EVT_STOP); + CtdlRegisterFixedOutputHook("text/calendar", ical_fixed_output); #endif return "$Id$"; } diff --git a/citadel/serv_extensions.c b/citadel/serv_extensions.c index f2b0c78d4..46e35d194 100644 --- a/citadel/serv_extensions.c +++ b/citadel/serv_extensions.c @@ -393,7 +393,6 @@ int PerformFixedOutputHooks(char *content_type, char *content, int content_lengt struct FixedOutputHook *fcn; for (fcn = FixedOutputTable; fcn != NULL; fcn = fcn->next) { - lprintf(CTDL_DEBUG, "comparing %s to %s\n", content_type, fcn->content_type); if (!strcasecmp(content_type, fcn->content_type)) { (*fcn->h_function_pointer) (content, content_length); return(1); -- 2.39.2