]> code.citadel.org Git - citadel.git/blobdiff - citadel/serv_calendar.c
* Reference count adjustments are now deferred by queuing
[citadel.git] / citadel / serv_calendar.c
index 8b121aef56f9b11f0aa46cee4866eb119bb0d67e..cbb3f84c44af6b378b5bbce5c3a29bcc6bed9ca9 100644 (file)
@@ -104,8 +104,6 @@ icalcomponent *ical_encapsulate_subcomponent(icalcomponent *subcomp) {
 
 /*
  * Write a calendar object into the specified user's calendar room.
- * 
- * ok
  */
 void ical_write_to_cal(struct ctdluser *u, icalcomponent *cal) {
        char temp[PATH_MAX];
@@ -432,7 +430,7 @@ void ical_respond(long msgnum, char *partnum, char *action) {
                /* Now that we've processed this message, we don't need it
                 * anymore.  So delete it.
                 */
-               CtdlDeleteMessages(CC->room.QRname, msgnum, "", 1);
+               CtdlDeleteMessages(CC->room.QRname, &msgnum, 1, "");
 
                /* Free the memory we allocated and return a response. */
                icalcomponent_free(ird.cal);
@@ -779,7 +777,7 @@ void ical_handle_rsvp(long msgnum, char *partnum, char *action) {
                /* Now that we've processed this message, we don't need it
                 * anymore.  So delete it.  (Maybe make this optional?)
                 */
-               CtdlDeleteMessages(CC->room.QRname, msgnum, "", 1);
+               CtdlDeleteMessages(CC->room.QRname, &msgnum, 1, "");
 
                /* Free the memory we allocated and return a response. */
                icalcomponent_free(ird.cal);
@@ -978,7 +976,7 @@ void ical_hunt_for_conflicts(icalcomponent *cal) {
 
        cprintf("%d Conflicting events:\n", LISTING_FOLLOWS);
 
-       CtdlForEachMessage(MSGS_ALL, 0, "text/calendar",
+       CtdlForEachMessage(MSGS_ALL, 0, NULL, "text/calendar",
                NULL,
                ical_hunt_for_conflicts_backend,
                (void *) cal
@@ -1283,7 +1281,7 @@ void ical_freebusy(char *who) {
 
        /* Add busy time from events */
        lprintf(CTDL_DEBUG, "Adding busy time from events\n");
-       CtdlForEachMessage(MSGS_ALL, 0, "text/calendar",
+       CtdlForEachMessage(MSGS_ALL, 0, NULL, "text/calendar",
                NULL, ical_freebusy_backend, (void *)fb
        );
 
@@ -1337,7 +1335,7 @@ void ical_freebusy(char *who) {
  * for calendar events and adds them each into one big calendar component.
  */
 void ical_getics_backend(long msgnum, void *data) {
-       icalcomponent *encaps;
+       icalcomponent *encaps, *c;
        struct CtdlMessage *msg;
        struct ical_respond_data ird;
 
@@ -1363,12 +1361,27 @@ void ical_getics_backend(long msgnum, void *data) {
 
        /* Here we go: put the VEVENT into the VCALENDAR.  We now no longer
         * are responsible for "the_request"'s memory -- it will be freed
-        * when we free "encaps". (FIXME strip out the old encapsulation)
+        * when we free "encaps".
         */
-       icalcomponent_add_component(encaps, ird.cal);
-       //cprintf("%s\n", icalcomponent_as_ical_string(encaps));
-       cprintf("%s\n", icalcomponent_as_ical_string(ird.cal));
-       icalcomponent_free(ird.cal);
+
+       /* If the top-level component is *not* a VCALENDAR, we can drop it right
+        * in.  This will almost never happen.
+        */
+       if (icalcomponent_isa(ird.cal) != ICAL_VCALENDAR_COMPONENT) {
+               icalcomponent_add_component(encaps, ird.cal);
+       }
+       /*
+        * In the more likely event that we're looking at a VCALENDAR with the VEVENT
+        * and other components encapsulated inside, we have to extract them.
+        */
+       else {
+               for (c = icalcomponent_get_first_component(ird.cal, ICAL_ANY_COMPONENT);
+                   (c != NULL);
+                   c = icalcomponent_get_next_component(ird.cal, ICAL_ANY_COMPONENT)) {
+                       icalcomponent_add_component(encaps, icalcomponent_new_clone(c));
+               }
+               icalcomponent_free(ird.cal);
+       }
 }
 
 
@@ -1380,6 +1393,13 @@ void ical_getics_backend(long msgnum, void *data) {
 void ical_getics(void)
 {
        icalcomponent *encaps = NULL;
+       char *ser = NULL;
+
+       if ( (CC->room.QRdefaultview != VIEW_CALENDAR)
+          &&(CC->room.QRdefaultview != VIEW_TASKS) ) {
+               cprintf("%d Not a calendar room\n", ERROR+NOT_HERE);
+               return;         /* Not a vCalendar-centric room */
+       }
 
        encaps = icalcomponent_new_vcalendar();
        if (encaps == NULL) {
@@ -1401,18 +1421,83 @@ void ical_getics(void)
        icalcomponent_set_method(encaps, ICAL_METHOD_PUBLISH);
 
        /* Now go through the room encapsulating all calendar items. */
-       CtdlForEachMessage(MSGS_ALL, 0, "text/calendar",
+       CtdlForEachMessage(MSGS_ALL, 0, NULL,
+               "text/calendar",
                NULL,
                ical_getics_backend,
                (void *) encaps
        );
 
-       cprintf("000\n");
+       ser = strdup(icalcomponent_as_ical_string(encaps));
+       client_write(ser, strlen(ser));
+       free(ser);
+       cprintf("\n000\n");
        icalcomponent_free(encaps);     /* Don't need this anymore. */
 
 }
 
 
+/*
+ * Delete all of the calendar items in the current room, and replace them
+ * with calendar items from a client-supplied data stream.
+ */
+void ical_putics(void)
+{
+       char *calstream = NULL;
+       icalcomponent *cal;
+       icalcomponent *c;
+
+       if ( (CC->room.QRdefaultview != VIEW_CALENDAR)
+          &&(CC->room.QRdefaultview != VIEW_TASKS) ) {
+               cprintf("%d Not a calendar room\n", ERROR+NOT_HERE);
+               return;         /* Not a vCalendar-centric room */
+       }
+
+       if (!CtdlDoIHavePermissionToDeleteMessagesFromThisRoom()) {
+               cprintf("%d Permission denied.\n", ERROR+HIGHER_ACCESS_REQUIRED);
+               return;
+       }
+
+       cprintf("%d Transmit data now\n", SEND_LISTING);
+        calstream = CtdlReadMessageBody("000", config.c_maxmsglen, NULL, 0);
+       if (calstream == NULL) {
+               return;
+       }
+
+       cal = icalcomponent_new_from_string(calstream);
+       free(calstream);
+       ical_dezonify(cal);
+
+       /* We got our data stream -- now do something with it. */
+
+       /* Delete the existing messages in the room, because we are replacing
+        * the entire calendar with an entire new (or updated) calendar.
+        * (Careful: this opens an S_ROOMS critical section!)
+        */
+       CtdlDeleteMessages(CC->room.QRname, NULL, 0, "");
+
+       /* If the top-level component is *not* a VCALENDAR, we can drop it right
+        * in.  This will almost never happen.
+        */
+       if (icalcomponent_isa(cal) != ICAL_VCALENDAR_COMPONENT) {
+               ical_write_to_cal(&CC->user, cal);
+       }
+       /*
+        * In the more likely event that we're looking at a VCALENDAR with the VEVENT
+        * and other components encapsulated inside, we have to extract them.
+        */
+       else {
+               for (c = icalcomponent_get_first_component(cal, ICAL_ANY_COMPONENT);
+                   (c != NULL);
+                   c = icalcomponent_get_next_component(cal, ICAL_ANY_COMPONENT)) {
+                       ical_write_to_cal(&CC->user, c);
+               }
+       }
+
+       icalcomponent_free(cal);
+}
+
+
 /*
  * All Citadel calendar commands from the client come through here.
  */
@@ -1477,6 +1562,11 @@ void cmd_ical(char *argbuf)
                return;
        }
 
+       if (!strcasecmp(subcmd, "putics")) {
+               ical_putics();
+               return;
+       }
+
        cprintf("%d Invalid subcommand\n", ERROR + CMD_NOT_SUPPORTED);
 }
 
@@ -1937,7 +2027,6 @@ int ical_obj_aftersave(struct CtdlMessage *msg)
        /* Then determine content-type of the message */
        
        /* It must be an RFC822 message! */
-       /* FIXME: Not handling MIME multipart messages; implement with IMIP */
        if (msg->cm_format_type != 4) return(1);
        
        /* Find the Content-Type: header */
@@ -1985,87 +2074,26 @@ 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));
+               cprintf("%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);
-               }
-
+               cprintf("%s\n", (const char *)icalproperty_get_comment(p));
        }
 
        p = icalcomponent_get_first_property(cal, ICAL_DESCRIPTION_PROPERTY);
        if (p != NULL) {
-               cprintf("Description: %s\n", (const char *)icalproperty_get_comment(p));
+               cprintf("%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)) {
 
@@ -2089,7 +2117,7 @@ void ical_fixed_output_backend(icalcomponent *cal,
 
 
 /*
- * Function to output a calendar item  as plain text.  Nobody uses MSG0
+ * Function to output vcalendar data as plain text.  Nobody uses MSG0
  * anymore, so really this is just so we expose the vCard data to the full
  * text indexer.
  */
@@ -2103,7 +2131,6 @@ void ical_fixed_output(char *ptr, int len) {
        free(stringy_cal);
 
        if (cal == NULL) {
-               cprintf("There was an error parsing this calendar item.\n");
                return;
        }