]> code.citadel.org Git - citadel.git/blobdiff - webcit/calendar.c
* read static/server files directly into the outbuffer
[citadel.git] / webcit / calendar.c
index 44dba7f8476153bc39835a6d13d7ad91f481dbab..7b6374eed97bf88d5b4a44a76633221868042f51 100644 (file)
@@ -417,14 +417,27 @@ void display_individual_cal(icalcomponent *cal, long msgnum, char *from, int unr
 {
        icalproperty *ps = NULL;
        struct icaltimetype dtstart, dtend;
+       struct icaldurationtype dur;
        struct wcsession *WCC = WC;
        disp_cal *Cal;
        size_t len;
+
+       /* recur variables */
+       icalproperty *rrule = NULL;
+       struct icalrecurrencetype recur;
+       icalrecur_iterator *ritr = NULL;
+       struct icaltimetype next;
        int num_recur = 0;
+
+       dtstart = icaltime_null_time();
+       dtend = icaltime_null_time();
        
        if (WCC->disp_cal_items == NULL)
                WCC->disp_cal_items = NewHash(0, Flathash);
-       
+
+
+
+       /* Note: anything we do here, we also have to do below for the recurrences. */
        Cal = (disp_cal*) malloc(sizeof(disp_cal));
        memset(Cal, 0, sizeof(disp_cal));
 
@@ -462,7 +475,13 @@ void display_individual_cal(icalcomponent *cal, long msgnum, char *from, int unr
 
 #ifdef TECH_PREVIEW
 
-       /* handle recurring events (unfinished) */
+       /* handle recurring events */
+
+       if (icaltime_is_null_time(dtstart)) return;     /* Can't recur without a start time */
+
+       if (!icaltime_is_null_time(dtend)) {            /* Need duration for recurrences */
+               dur = icaltime_subtract(dtend, dtstart);
+       }
 
        /*
         * Just let libical iterate the recurrence, and keep looping back to the top of this function,
@@ -471,17 +490,49 @@ void display_individual_cal(icalcomponent *cal, long msgnum, char *from, int unr
         * thing (but we'll have to see).
         */
 
-       icalproperty *rrule = icalcomponent_get_first_property(Cal->cal, ICAL_RRULE_PROPERTY);
+       rrule = icalcomponent_get_first_property(Cal->cal, ICAL_RRULE_PROPERTY);
        if (!rrule) return;
-       struct icalrecurrencetype recur = icalproperty_get_rrule(rrule);
-       icalrecur_iterator *ritr = icalrecur_iterator_new(recur, dtstart);
+       recur = icalproperty_get_rrule(rrule);
+       ritr = icalrecur_iterator_new(recur, dtstart);
        if (!ritr) return;
 
-       struct icaltimetype next;
        while (next = icalrecur_iterator_next(ritr), !icaltime_is_null_time(next) ) {
                ++num_recur;
-               lprintf(9, "* Doing a recurrence %d\n", num_recur);
+
+               /* Note: anything we do here, we also have to do above for the root event. */
+               Cal = (disp_cal*) malloc(sizeof(disp_cal));
+               memset(Cal, 0, sizeof(disp_cal));
+       
+               Cal->cal = icalcomponent_new_clone(cal);
+               Cal->unread = unread;
+               len = strlen(from);
+               Cal->from = (char*)malloc(len+ 1);
+               memcpy(Cal->from, from, len + 1);
+               ical_dezonify(Cal->cal);
+               Cal->cal_msgnum = msgnum;
+
+               ps = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
+               if (ps != NULL) {
+                       icalcomponent_remove_property(Cal->cal, ps);
+                       ps = icalproperty_new_dtstart(next);
+                       icalcomponent_add_property(Cal->cal, ps);
+                       Cal->event_start = icaltime_as_timet(next);
+               }
+
+               ps = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
+               if (ps != NULL) {
+                       icalcomponent_remove_property(Cal->cal, ps);
+                       /* FIXME now set the dtend property and stuff it somewhere */
+               }
+
+               Put(WCC->disp_cal_items, 
+                       (char*) &Cal->event_start,
+                       sizeof(Cal->event_start), 
+                       Cal, 
+                       delete_cal);
        }
+       time_t tt = icaltime_as_timet(next);
+       lprintf(9, "Performed %d recurrences; final one is %s", num_recur, ctime(&tt));
 
 #endif /* TECH_PREVIEW */
 
@@ -850,17 +901,11 @@ void save_individual_task(icalcomponent *supplied_vtodo, long msgnum, char* from
 
 
 
-/**
- * \brief generic item handler
- * Code common to all display handlers.  Given a message number and a MIME
+/*
+ * Code common to all icalendar display handlers.  Given a message number and a MIME
  * type, we load the message and hunt for that MIME type.  If found, we load
  * the relevant part, deserialize it into a libical component, filter it for
  * the requested object type, and feed it to the specified handler.
- * \param mimetype mimetyp of our object
- * \param which_kind sort of ical type
- * \param msgnum number of the mesage in our db
- * \param callback a funcion \todo
- *
  */
 void display_using_handler(long msgnum, int unread,
                           icalcomponent_kind which_kind,
@@ -913,17 +958,15 @@ void display_using_handler(long msgnum, int unread,
 
                                ical_dezonify(cal);
 
-                               /** Simple components of desired type */
+                               /* Simple components of desired type */
                                if (icalcomponent_isa(cal) == which_kind) {
                                        callback(cal, msgnum, from, unread);
                                }
 
-                               /** Subcomponents of desired type */
-                               for (c = icalcomponent_get_first_component(cal,
-                                                                          which_kind);
+                               /* Subcomponents of desired type */
+                               for (c = icalcomponent_get_first_component(cal, which_kind);
                                     (c != 0);
-                                    c = icalcomponent_get_next_component(cal,
-                                                                         which_kind)) {
+                                    c = icalcomponent_get_next_component(cal, which_kind)) {
                                        callback(c, msgnum, from, unread);
                                }
                                icalcomponent_free(cal);
@@ -934,69 +977,61 @@ void display_using_handler(long msgnum, int unread,
        icalmemory_free_ring();
 }
 
-/**
- * \brief display whole calendar
- * \param msgnum number of the mesage in our db
+/*
+ * Display a calendar item
  */
 void display_calendar(long msgnum, int unread) {
-       display_using_handler(msgnum, unread,
-                             ICAL_VEVENT_COMPONENT,
-                             display_individual_cal);
+       display_using_handler(msgnum, unread, ICAL_VEVENT_COMPONENT, display_individual_cal);
 }
 
-/**
- * \brief display whole taksview
- * \param msgnum number of the mesage in our db
+/*
+ * Display task view
  */
 void display_task(long msgnum, int unread) {
-       display_using_handler(msgnum, unread,
-                             ICAL_VTODO_COMPONENT,
-                             display_individual_cal);
+       display_using_handler(msgnum, unread, ICAL_VTODO_COMPONENT, display_individual_cal);
 }
 
-/**
- * \brief display the editor component for a task
+/*
+ * Display the editor component for a task
  */
 void display_edit_task(void) {
        long msgnum = 0L;
                        
-       /** Force change the room if we have to */
+       /* Force change the room if we have to */
        if (havebstr("taskrm")) {
                gotoroom((char *)bstr("taskrm"));
        }
 
        msgnum = lbstr("msgnum");
        if (msgnum > 0L) {
-               /** existing task */
+               /* existing task */
                display_using_handler(msgnum, 0,
                                      ICAL_VTODO_COMPONENT,
                                      display_edit_individual_task);
        }
        else {
-               /** new task */
+               /* new task */
                display_edit_individual_task(NULL, 0L, "", 0);
        }
 }
 
-/**
- *\brief save an edited task
+/*
+ * save an edited task
  */
 void save_task(void) {
        long msgnum = 0L;
 
        msgnum = lbstr("msgnum");
        if (msgnum > 0L) {
-               display_using_handler(msgnum, 0,
-                                     ICAL_VTODO_COMPONENT,
-                                     save_individual_task);
+               display_using_handler(msgnum, 0, ICAL_VTODO_COMPONENT, save_individual_task);
        }
        else {
                save_individual_task(NULL, 0L, "", 0);
        }
 }
 
-/**
- * \brief display the editor component for an event
+/*
+ * display the editor component for an event
  */
 void display_edit_event(void) {
        long msgnum = 0L;
@@ -1004,9 +1039,7 @@ void display_edit_event(void) {
        msgnum = lbstr("msgnum");
        if (msgnum > 0L) {
                /* existing event */
-               display_using_handler(msgnum, 0,
-                                     ICAL_VEVENT_COMPONENT,
-                                     display_edit_individual_event);
+               display_using_handler(msgnum, 0, ICAL_VEVENT_COMPONENT, display_edit_individual_event);
        }
        else {
                /* new event */
@@ -1014,8 +1047,8 @@ void display_edit_event(void) {
        }
 }
 
-/**
- * \brief save an edited event
+/*
+ * save an edited event
  */
 void save_event(void) {
        long msgnum = 0L;
@@ -1023,9 +1056,7 @@ void save_event(void) {
        msgnum = lbstr("msgnum");
 
        if (msgnum > 0L) {
-               display_using_handler(msgnum, 0,
-                                     ICAL_VEVENT_COMPONENT,
-                                     save_individual_event);
+               display_using_handler(msgnum, 0, ICAL_VEVENT_COMPONENT, save_individual_event);
        }
        else {
                save_individual_event(NULL, 0L, "", 0);
@@ -1036,15 +1067,14 @@ void save_event(void) {
 
 
 
-/**
- * \brief freebusy display (for client software)
- * \param req dunno. ?????
+/*
+ * Anonymous request of freebusy data for a user
  */
 void do_freebusy(char *req) {
        char who[SIZ];
        char buf[SIZ];
-       char *fb;
        int len;
+       long lines;
 
        extract_token(who, req, 1, ' ', sizeof who);
        if (!strncasecmp(who, "/freebusy/", 10)) {
@@ -1064,17 +1094,16 @@ void do_freebusy(char *req) {
        serv_getln(buf, sizeof buf);
 
        if (buf[0] != '1') {
-               wprintf("HTTP/1.1 404 %s\n", &buf[4]);
+               hprintf("HTTP/1.1 404 %s\n", &buf[4]);
                output_headers(0, 0, 0, 0, 0, 0);
-               wprintf("Content-Type: text/plain\r\n");
-               wprintf("\r\n");
+               hprintf("Content-Type: text/plain\r\n");
                wprintf("%s\n", &buf[4]);
+               end_burst();
                return;
        }
 
-       fb = read_server_text();
-       http_transmit_thing(fb, strlen(fb), "text/calendar", 0);
-       free(fb);
+       read_server_text(WC->WBuf, &lines);
+       http_transmit_thing("text/calendar", 0);
 }