#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
+#include <ical.h>
+#include <libcitadel.h>
#include "citadel.h"
#include "server.h"
#include "citserver.h"
#include "config.h"
#include "user_ops.h"
#include "room_ops.h"
-#include "tools.h"
#include "msgbase.h"
-#include "mime_parser.h"
#include "internet_addressing.h"
#include "serv_calendar.h"
#include "euidindex.h"
#include "ctdl_module.h"
-
-#ifdef CITADEL_WITH_CALENDAR_SERVICE
-
-#include <ical.h>
#include "ical_dezonify.h"
/*
* Write a calendar object into the specified user's calendar room.
+ * If the supplied user is NULL, this function writes the calendar object
+ * to the currently selected room.
*/
void ical_write_to_cal(struct ctdluser *u, icalcomponent *cal) {
char temp[PATH_MAX];
- FILE *fp;
- char *ser;
- icalcomponent *encaps;
+ FILE *fp = NULL;
+ char *ser = NULL;
+ icalcomponent *encaps = NULL;
+ struct CtdlMessage *msg = NULL;
+ icalcomponent *tmp=NULL;
if (cal == NULL) return;
* a full VCALENDAR component, and save that instead.
*/
if (icalcomponent_isa(cal) != ICAL_VCALENDAR_COMPONENT) {
- encaps = ical_encapsulate_subcomponent(
- icalcomponent_new_clone(cal)
- );
+ tmp = icalcomponent_new_clone(cal);
+ encaps = ical_encapsulate_subcomponent(tmp);
ical_write_to_cal(u, encaps);
+ icalcomponent_free(tmp);
icalcomponent_free(encaps);
return;
}
- CtdlMakeTempFileName(temp, sizeof temp);
ser = icalcomponent_as_ical_string(cal);
if (ser == NULL) return;
- /* Make a temp file out of it */
- fp = fopen(temp, "w");
- if (fp == NULL) return;
- fwrite(ser, strlen(ser), 1, fp);
- fclose(fp);
+ /* If the caller supplied a user, write to that user's default calendar room */
+ if (u) {
+ /* Make a temp file out of it */
+ CtdlMakeTempFileName(temp, sizeof temp);
+ fp = fopen(temp, "w");
+ if (fp != NULL) {
+ fwrite(ser, strlen(ser), 1, fp);
+ fclose(fp);
+
+ /* This handy API function does all the work for us. */
+ CtdlWriteObject(USERCALENDARROOM, /* which room */
+ "text/calendar", /* MIME type */
+ temp, /* temp file */
+ u, /* which user */
+ 0, /* not binary */
+ 0, /* don't delete others of this type */
+ 0 /* no flags */
+ );
+ unlink(temp);
+ }
+ }
- /* This handy API function does all the work for us.
- */
- CtdlWriteObject(USERCALENDARROOM, /* which room */
- "text/calendar", /* MIME type */
- temp, /* temp file */
- u, /* which user */
- 0, /* not binary */
- 0, /* don't delete others of this type */
- 0); /* no flags */
-
- unlink(temp);
+ /* If the caller did not supply a user, write to the currently selected room */
+ if (!u) {
+ msg = malloc(sizeof(struct CtdlMessage));
+ memset(msg, 0, sizeof(struct CtdlMessage));
+ msg->cm_magic = CTDLMESSAGE_MAGIC;
+ msg->cm_anon_type = MES_NORMAL;
+ msg->cm_format_type = 4;
+ msg->cm_fields['A'] = strdup(CC->user.fullname);
+ msg->cm_fields['O'] = strdup(CC->room.QRname);
+ msg->cm_fields['N'] = strdup(config.c_nodename);
+ msg->cm_fields['H'] = strdup(config.c_humannode);
+ msg->cm_fields['M'] = malloc(strlen(ser) + 40);
+ strcpy(msg->cm_fields['M'], "Content-type: text/calendar\r\n\r\n");
+ strcat(msg->cm_fields['M'], ser);
+
+ /* Now write the data */
+ CtdlSubmitMsg(msg, NULL, "");
+ CtdlFreeMessage(msg);
+ }
+
+ /* In either case, now we can free the serialized calendar object */
+// free(ser);
}
if (!strncasecmp(attendee_string, "MAILTO:", 7)) {
strcpy(attendee_string, &attendee_string[7]);
striplt(attendee_string);
- recp = validate_recipients(attendee_string);
+ recp = validate_recipients(attendee_string, NULL, 0);
if (recp != NULL) {
if (!strcasecmp(recp->recp_local, CC->user.fullname)) {
if (me_attend) icalproperty_free(me_attend);
reply_message_text);
if (msg != NULL) {
- valid = validate_recipients(organizer_string);
+ valid = validate_recipients(organizer_string, NULL, 0);
CtdlSubmitMsg(msg, valid, "");
CtdlFreeMessage(msg);
free_recipients(valid);
}
}
- if (strcasecmp(cbtype, "text/calendar")) {
+ if ( (strcasecmp(cbtype, "text/calendar"))
+ && (strcasecmp(cbtype, "application/ics")) ) {
return;
}
struct original_event_container *oec = NULL;
- if (strcasecmp(cbtype, "text/calendar")) {
+ if ( (strcasecmp(cbtype, "text/calendar"))
+ && (strcasecmp(cbtype, "application/ics")) ) {
return;
}
oec = (struct original_event_container *) cbuserdata;
/* If not found, try it as an unqualified email address. */
if (found_user != 0) {
strcpy(buf, who);
- recp = validate_recipients(buf);
+ recp = validate_recipients(buf, NULL, 0);
lprintf(CTDL_DEBUG, "Trying <%s>\n", buf);
if (recp != NULL) {
if (recp->num_local == 1) {
if (found_user != 0) {
snprintf(buf, sizeof buf, "%s@%s", who, config.c_fqdn);
lprintf(CTDL_DEBUG, "Trying <%s>\n", buf);
- recp = validate_recipients(buf);
+ recp = validate_recipients(buf, NULL, 0);
if (recp != NULL) {
if (recp->num_local == 1) {
found_user = getuser(&usbuf, recp->recp_local);
|| (!strcasecmp(type, "directory")) ) {
snprintf(buf, sizeof buf, "%s@%s", who, host);
lprintf(CTDL_DEBUG, "Trying <%s>\n", buf);
- recp = validate_recipients(buf);
+ recp = validate_recipients(buf, NULL, 0);
if (recp != NULL) {
if (recp->num_local == 1) {
found_user = getuser(&usbuf, recp->recp_local);
if (fb == NULL) {
cprintf("%d Internal error: cannot allocate memory.\n",
ERROR + INTERNAL_ERROR);
- icalcomponent_free(encaps);
getroom(&CC->room, hold_rm);
return;
}
strcat(buf, "@");
strcat(buf, config.c_fqdn);
}
- for (i=0; i<strlen(buf); ++i) {
+ for (i=0; buf[i]; ++i) {
if (buf[i]==' ') buf[i] = '_';
}
icalcomponent_add_property(fb, icalproperty_new_organizer(buf));
}
cprintf("%d Transmit data now\n", SEND_LISTING);
- calstream = CtdlReadMessageBody("000", config.c_maxmsglen, NULL, 0);
+ calstream = CtdlReadMessageBody("000", config.c_maxmsglen, NULL, 0, 0);
if (calstream == NULL) {
return;
}
* in. This will almost never happen.
*/
if (icalcomponent_isa(cal) != ICAL_VCALENDAR_COMPONENT) {
- ical_write_to_cal(&CC->user, cal);
+ ical_write_to_cal(NULL, cal);
}
/*
* In the more likely event that we're looking at a VCALENDAR with the VEVENT
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);
+ ical_write_to_cal(NULL, c);
}
}
icalproperty *attendee = NULL;
char summary_string[SIZ];
icalproperty *summary = NULL;
+ size_t reqsize;
if (cal == NULL) {
lprintf(CTDL_ERR, "ERROR: trying to reply to NULL event?\n");
icalcomponent_free(encaps); /* Don't need this anymore. */
if (serialized_request == NULL) return;
- request_message_text = malloc(strlen(serialized_request) + SIZ);
+ reqsize = strlen(serialized_request) + SIZ;
+ request_message_text = malloc(reqsize);
if (request_message_text != NULL) {
- sprintf(request_message_text,
+ snprintf(request_message_text, reqsize,
"Content-type: text/calendar\r\n\r\n%s\r\n",
serialized_request
);
request_message_text);
if (msg != NULL) {
- valid = validate_recipients(attendees_string);
+ valid = validate_recipients(attendees_string, NULL, 0);
CtdlSubmitMsg(msg, valid, "");
CtdlFreeMessage(msg);
free_recipients(valid);
imm = (struct icalmessagemod *)cbuserdata;
/* We're only interested in calendar data. */
- if (strcasecmp(cbtype, "text/calendar")) {
+ if ( (strcasecmp(cbtype, "text/calendar"))
+ && (strcasecmp(cbtype, "application/ics")) ) {
return;
}
icalcomponent *cal;
/* We're only interested in calendar items here. */
- if (strcasecmp(cbtype, "text/calendar")) {
+ if ( (strcasecmp(cbtype, "text/calendar"))
+ && (strcasecmp(cbtype, "application/ics")) ) {
return;
}
* ical_obj_beforesave() sees it there, it'll set the Exclusive msgid
* to that string.
*/
- if (!strcasecmp(cbtype, "text/calendar")) {
+ if ( (!strcasecmp(cbtype, "text/calendar"))
+ || (!strcasecmp(cbtype, "application/ics")) ) {
cal = icalcomponent_new_from_string(content);
if (cal != NULL) {
ical_saving_vevent(cal);
}
-#endif /* CITADEL_WITH_CALENDAR_SERVICE */
+
+void serv_calendar_destroy(void)
+{
+ icaltimezone_free_builtin_timezones();
+}
/*
* Register this module with the Citadel server.
*/
CTDL_MODULE_INIT(calendar)
{
-#ifdef CITADEL_WITH_CALENDAR_SERVICE
- CtdlRegisterMessageHook(ical_obj_beforesave, EVT_BEFORESAVE);
- CtdlRegisterMessageHook(ical_obj_aftersave, EVT_AFTERSAVE);
- CtdlRegisterSessionHook(ical_create_room, EVT_LOGIN);
- 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
-
+ if (!threading)
+ {
+ CtdlRegisterMessageHook(ical_obj_beforesave, EVT_BEFORESAVE);
+ CtdlRegisterMessageHook(ical_obj_aftersave, EVT_AFTERSAVE);
+ CtdlRegisterSessionHook(ical_create_room, EVT_LOGIN);
+ 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);
+ CtdlRegisterFixedOutputHook("application/ics", ical_fixed_output);
+ CtdlRegisterCleanupHook(serv_calendar_destroy);
+ }
+
/* return our Subversion id for the Log */
return "$Id$";
}
-
-
-void serv_calendar_destroy(void)
-{
-#ifdef CITADEL_WITH_CALENDAR_SERVICE
- icaltimezone_free_builtin_timezones();
-#endif
-}