2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 2008 - 2009, Digium, Inc.
6 * Terry Wilson <twilson@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
20 * \brief Calendaring API
22 * \todo Support responding to a meeting invite
23 * \todo Support writing attendees
28 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
30 #include "asterisk/_private.h"
31 #include "asterisk/calendar.h"
32 #include "asterisk/utils.h"
33 #include "asterisk/astobj2.h"
34 #include "asterisk/module.h"
35 #include "asterisk/config.h"
36 #include "asterisk/channel.h"
37 #include "asterisk/devicestate.h"
38 #include "asterisk/linkedlists.h"
39 #include "asterisk/sched.h"
40 #include "asterisk/dial.h"
41 #include "asterisk/cli.h"
42 #include "asterisk/pbx.h"
43 #include "asterisk/app.h"
46 <function name="CALENDAR_BUSY" language="en_US">
48 Determine if the calendar is marked busy at this time.
51 <parameter name="calendar" required="true" />
54 <para>Check the specified calendar's current busy status.</para>
57 <function name="CALENDAR_EVENT" language="en_US">
59 Get calendar event notification data from a notification call.
62 <parameter name="field" required="true">
64 <enum name="summary"><para>The VEVENT SUMMARY property or Exchange event 'subject'</para></enum>
65 <enum name="description"><para>The text description of the event</para></enum>
66 <enum name="organizer"><para>The organizer of the event</para></enum>
67 <enum name="location"><para>The location of the eventt</para></enum>
68 <enum name="calendar"><para>The name of the calendar associated with the event</para></enum>
69 <enum name="uid"><para>The unique identifier for this event</para></enum>
70 <enum name="start"><para>The start time of the event</para></enum>
71 <enum name="end"><para>The end time of the event</para></enum>
72 <enum name="busystate"><para>The busy state of the event 0=FREE, 1=TENTATIVE, 2=BUSY</para></enum>
77 <para>Whenever a calendar event notification call is made, the event data
78 may be accessed with this function.</para>
81 <function name="CALENDAR_QUERY" language="en_US">
82 <synopsis>Query a calendar server and store the data on a channel
85 <parameter name="calendar" required="true">
86 <para>The calendar that should be queried</para>
88 <parameter name="start" required="false">
89 <para>The start time of the query (in seconds since epoch)</para>
91 <parameter name="end" required="false">
92 <para>The end time of the query (in seconds since epoch)</para>
96 <para>Get a list of events in the currently accessible timeframe of the <replaceable>calendar</replaceable>
97 The function returns the id for accessing the result with CALENDAR_QUERY_RESULT()</para>
100 <function name="CALENDAR_QUERY_RESULT" language="en_US">
102 Retrieve data from a previously run CALENDAR_QUERY() call
105 <parameter name="id" required="true">
106 <para>The query ID returned by <literal>CALENDAR_QUERY</literal></para>
108 <parameter name="field" required="true">
110 <enum name="getnum"><para>number of events occurring during time range</para></enum>
111 <enum name="summary"><para>A summary of the event</para></enum>
112 <enum name="description"><para>The full event description</para></enum>
113 <enum name="organizer"><para>The event organizer</para></enum>
114 <enum name="location"><para>The event location</para></enum>
115 <enum name="calendar"><para>The name of the calendar associted with the event</para></enum>
116 <enum name="uid"><para>The unique identifier for the event</para></enum>
117 <enum name="start"><para>The start time of the event (in seconds since epoch)</para></enum>
118 <enum name="end"><para>The end time of the event (in seconds since epoch)</para></enum>
119 <enum name="busystate"><para>The busy status of the event 0=FREE, 1=TENTATIVE, 2=BUSY</para></enum>
122 <parameter name="entry" required="false" default="1">
123 <para>Return data from a specific event returned by the query</para>
127 <para>After running CALENDAR_QUERY and getting a result <replaceable>id</replaceable>, calling
128 <literal>CALENDAR_QUERY</literal> with that <replaceable>id</replaceable> and a <replaceable>field</replaceable>
129 will return the data for that field. If multiple events matched the query, and <replaceable>entry</replaceable>
130 is provided, information from that event will be returned.</para>
133 <function name="CALENDAR_WRITE" language="en_US">
134 <synopsis>Write an event to a calendar</synopsis>
136 <parameter name="calendar" required="true">
137 <para>The calendar to write to</para>
139 <parameter name="field" multiple="true" required="true">
141 <enum name="summary"><para>A summary of the event</para></enum>
142 <enum name="description"><para>The full event description</para></enum>
143 <enum name="organizer"><para>The event organizer</para></enum>
144 <enum name="location"><para>The event location</para></enum>
145 <enum name="uid"><para>The unique identifier for the event</para></enum>
146 <enum name="start"><para>The start time of the event (in seconds since epoch)</para></enum>
147 <enum name="end"><para>The end time of the event (in seconds since epoch)</para></enum>
148 <enum name="busystate"><para>The busy status of the event 0=FREE, 1=TENTATIVE, 2=BUSY</para></enum>
153 <para>Example: CALENDAR_WRITE(calendar,field1,field2,field3)=val1,val2,val3</para>
154 <para>The field and value arguments can easily be set/passed using the HASHKEYS() and HASH() functions</para>
159 #define CALENDAR_BUCKETS 19
161 static struct ao2_container *calendars;
162 static struct sched_context *sched;
163 static pthread_t refresh_thread = AST_PTHREADT_NULL;
164 static ast_mutex_t refreshlock;
165 static ast_cond_t refresh_condition;
166 static ast_mutex_t reloadlock;
168 static void event_notification_destroy(void *data);
169 static void *event_notification_duplicate(void *data);
170 static void eventlist_destroy(void *data);
171 static void *eventlist_duplicate(void *data);
173 static const struct ast_datastore_info event_notification_datastore = {
174 .type = "EventNotification",
175 .destroy = event_notification_destroy,
176 .duplicate = event_notification_duplicate,
179 static const struct ast_datastore_info eventlist_datastore_info = {
180 .type = "CalendarEventList",
181 .destroy = eventlist_destroy,
182 .duplicate = eventlist_duplicate,
186 struct ast_calendar_event *event;
187 AST_LIST_ENTRY(evententry) list;
190 static AST_LIST_HEAD_STATIC(techs, ast_calendar_tech);
191 AST_LIST_HEAD_NOLOCK(eventlist, evententry); /* define the type */
193 struct ast_config *ast_calendar_config;
195 static struct ast_calendar *unref_calendar(struct ast_calendar *cal)
201 static int calendar_hash_fn(const void *obj, const int flags)
203 const struct ast_calendar *cal = obj;
204 return ast_str_case_hash(cal->name);
207 static int calendar_cmp_fn(void *obj, void *arg, int flags)
209 const struct ast_calendar *one = obj, *two = arg;
210 return !strcasecmp(one->name, two->name) ? CMP_MATCH | CMP_STOP: 0;
213 static struct ast_calendar *find_calendar(const char *name)
215 struct ast_calendar tmp = {
218 return ao2_find(calendars, &tmp, OBJ_POINTER);
221 static int event_hash_fn(const void *obj, const int flags)
223 const struct ast_calendar_event *event = obj;
224 return ast_str_hash(event->uid);
227 static int event_cmp_fn(void *obj, void *arg, int flags)
229 const struct ast_calendar_event *one = obj, *two = arg;
230 return !strcmp(one->uid, two->uid) ? CMP_MATCH | CMP_STOP : 0;
233 static struct ast_calendar_event *find_event(struct ao2_container *events, const char *uid)
235 struct ast_calendar_event tmp = {
238 return ao2_find(events, &tmp, OBJ_POINTER);
241 struct ast_calendar_event *ast_calendar_unref_event(struct ast_calendar_event *event)
247 static void calendar_destructor(void *obj)
249 struct ast_calendar *cal = obj;
251 ast_debug(3, "Destroying calendar %s\n", cal->name);
255 ast_cond_signal(&cal->unload);
256 pthread_join(cal->thread, NULL);
258 cal->tech_pvt = cal->tech->unref_calendar(cal->tech_pvt);
260 ast_calendar_clear_events(cal);
261 ast_string_field_free_memory(cal);
262 ao2_ref(cal->events, -1);
266 static void eventlist_destructor(void *obj)
268 struct eventlist *events = obj;
269 struct evententry *entry;
271 while ((entry = AST_LIST_REMOVE_HEAD(events, list))) {
272 ao2_ref(entry->event, -1);
277 static int calendar_busy_callback(void *obj, void *arg, int flags)
279 struct ast_calendar_event *event = obj;
281 struct timeval tv = ast_tvnow();
283 if (tv.tv_sec >= event->start && tv.tv_sec <= event->end && event->busy_state > AST_CALENDAR_BS_FREE) {
291 static int calendar_is_busy(struct ast_calendar *cal)
295 ao2_callback(cal->events, OBJ_NODATA, calendar_busy_callback, &is_busy);
300 static enum ast_device_state calendarstate(const char *data)
302 struct ast_calendar *cal;
304 if (ast_strlen_zero(data) || (!(cal = find_calendar(data)))) {
305 return AST_DEVICE_INVALID;
308 if (cal->tech->is_busy) {
309 return cal->tech->is_busy(cal) ? AST_DEVICE_INUSE : AST_DEVICE_NOT_INUSE;
312 return calendar_is_busy(cal) ? AST_DEVICE_INUSE : AST_DEVICE_NOT_INUSE;
315 static struct ast_calendar *build_calendar(struct ast_config *cfg, const char *cat, const struct ast_calendar_tech *tech)
317 struct ast_calendar *cal;
318 struct ast_variable *v;
319 int new_calendar = 0;
321 if (!(cal = find_calendar(cat))) {
323 if (!(cal = ao2_alloc(sizeof(*cal), calendar_destructor))) {
324 ast_log(LOG_ERROR, "Could not allocate calendar structure. Stopping.\n");
328 if (!(cal->events = ao2_container_alloc(CALENDAR_BUCKETS, event_hash_fn, event_cmp_fn))) {
329 ast_log(LOG_ERROR, "Could not allocate events container for %s\n", cat);
330 cal = unref_calendar(cal);
334 if (ast_string_field_init(cal, 32)) {
335 ast_log(LOG_ERROR, "Couldn't create string fields for %s\n", cat);
336 cal = unref_calendar(cal);
340 cal->pending_deletion = 0;
343 ast_string_field_set(cal, name, cat);
349 for (v = ast_variable_browse(cfg, cat); v; v = v->next) {
350 if (!strcasecmp(v->name, "autoreminder")) {
351 cal->autoreminder = atoi(v->value);
352 } else if (!strcasecmp(v->name, "channel")) {
353 ast_string_field_set(cal, notify_channel, v->value);
354 } else if (!strcasecmp(v->name, "context")) {
355 ast_string_field_set(cal, notify_context, v->value);
356 } else if (!strcasecmp(v->name, "extension")) {
357 ast_string_field_set(cal, notify_extension, v->value);
358 } else if (!strcasecmp(v->name, "waittime")) {
359 cal->notify_waittime = atoi(v->value);
360 } else if (!strcasecmp(v->name, "app")) {
361 ast_string_field_set(cal, notify_app, v->value);
362 } else if (!strcasecmp(v->name, "appdata")) {
363 ast_string_field_set(cal, notify_appdata, v->value);
364 } else if (!strcasecmp(v->name, "refresh")) {
365 cal->refresh = atoi(v->value);
366 } else if (!strcasecmp(v->name, "timeframe")) {
367 cal->timeframe = atoi(v->value);
372 cal->thread = AST_PTHREADT_NULL;
373 ast_cond_init(&cal->unload, NULL);
374 ao2_link(calendars, cal);
375 if (ast_pthread_create(&cal->thread, NULL, cal->tech->load_calendar, cal)) {
376 /* If we start failing to create threads, go ahead and return NULL
377 * and the tech module will be unregistered
379 ao2_unlink(calendars, cal);
380 cal = unref_calendar(cal);
387 static int load_tech_calendars(struct ast_calendar_tech *tech)
389 struct ast_calendar *cal;
390 const char *cat = NULL;
393 if (!ast_calendar_config) {
394 ast_log(LOG_WARNING, "Calendar support disabled, not loading %s calendar module\n", tech->type);
398 while ((cat = ast_category_browse(ast_calendar_config, cat))) {
399 if (!strcasecmp(cat, "general")) {
403 if (!(val = ast_variable_retrieve(ast_calendar_config, cat, "type")) || strcasecmp(val, tech->type)) {
407 /* A serious error occurred loading calendars from this tech and it should be disabled */
408 if (!(cal = build_calendar(ast_calendar_config, cat, tech))) {
409 ast_calendar_unregister(tech);
413 cal = unref_calendar(cal);
419 int ast_calendar_register(struct ast_calendar_tech *tech)
421 struct ast_calendar_tech *iter;
423 AST_LIST_LOCK(&techs);
424 AST_LIST_TRAVERSE(&techs, iter, list) {
425 if(!strcasecmp(tech->type, iter->type)) {
426 ast_log(LOG_WARNING, "Already have a handler for calendar type '%s'\n", tech->type);
427 AST_LIST_UNLOCK(&techs);
431 AST_LIST_INSERT_HEAD(&techs, tech, list);
432 AST_LIST_UNLOCK(&techs);
434 ast_verb(2, "Registered calendar type '%s' (%s)\n", tech->type, tech->description);
436 return load_tech_calendars(tech);
439 static int match_caltech_cb(void *user_data, void *arg, int flags)
441 struct ast_calendar *cal = user_data;
442 struct ast_calendar_tech *tech = arg;
444 if (cal->tech == tech) {
451 void ast_calendar_unregister(struct ast_calendar_tech *tech)
453 struct ast_calendar_tech *iter;
455 AST_LIST_LOCK(&techs);
456 AST_LIST_TRAVERSE_SAFE_BEGIN(&techs, iter, list) {
461 ao2_callback(calendars, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, match_caltech_cb, tech);
463 AST_LIST_REMOVE_CURRENT(list);
464 ast_verb(2, "Unregistered calendar type '%s'\n", tech->type);
467 AST_LIST_TRAVERSE_SAFE_END;
468 AST_LIST_UNLOCK(&techs);
472 static void calendar_event_destructor(void *obj)
474 struct ast_calendar_event *event = obj;
475 struct ast_calendar_attendee *attendee;
477 ast_debug(3, "Destroying event for calendar '%s'\n", event->owner->name);
478 ast_string_field_free_memory(event);
479 while ((attendee = AST_LIST_REMOVE_HEAD(&event->attendees, next))) {
480 if (attendee->data) {
481 ast_free(attendee->data);
487 /* This is only called from ao2_callbacks that are going to unref the event for us,
488 * so we don't unref the event here. */
489 static struct ast_calendar_event *destroy_event(struct ast_calendar_event *event)
491 if (event->notify_sched > -1 && ast_sched_del(sched, event->notify_sched)) {
492 ast_debug(3, "Notification running, can't delete sched entry\n");
494 if (event->bs_start_sched > -1 && ast_sched_del(sched, event->bs_start_sched)) {
495 ast_debug(3, "Devicestate update (start) running, can't delete sched entry\n");
497 if (event->bs_end_sched > -1 && ast_sched_del(sched, event->bs_end_sched)) {
498 ast_debug(3, "Devicestate update (end) running, can't delete sched entry\n");
501 /* If an event is being deleted and we've fired an event changing the status at the beginning,
502 * but haven't hit the end event yet, go ahead and set the devicestate to the current busy status */
503 if (event->bs_start_sched < 0 && event->bs_end_sched >= 0) {
504 if (!calendar_is_busy(event->owner)) {
505 ast_devstate_changed(AST_DEVICE_NOT_INUSE, "Calendar/%s", event->owner->name);
507 ast_devstate_changed(AST_DEVICE_BUSY, "Calendar/%s", event->owner->name);
514 static int clear_events_cb(void *user_data, void *arg, int flags)
516 struct ast_calendar_event *event = user_data;
518 event = destroy_event(event);
523 void ast_calendar_clear_events(struct ast_calendar *cal)
525 ast_debug(3, "Clearing all events for calendar %s\n", cal->name);
527 ao2_callback(cal->events, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, clear_events_cb, NULL);
530 struct ast_calendar_event *ast_calendar_event_alloc(struct ast_calendar *cal)
532 struct ast_calendar_event *event;
533 if (!(event = ao2_alloc(sizeof(*event), calendar_event_destructor))) {
537 if (ast_string_field_init(event, 32)) {
538 event = ast_calendar_unref_event(event);
543 event->notify_sched = -1;
544 event->bs_start_sched = -1;
545 event->bs_end_sched = -1;
547 AST_LIST_HEAD_INIT_NOLOCK(&event->attendees);
552 struct ao2_container *ast_calendar_event_container_alloc(void)
554 return ao2_container_alloc(CALENDAR_BUCKETS, event_hash_fn, event_cmp_fn);
557 static void event_notification_destroy(void *data)
559 struct ast_calendar_event *event = data;
561 event = ast_calendar_unref_event(event);
565 static void *event_notification_duplicate(void *data)
567 struct ast_calendar_event *event = data;
578 /*! \brief Generate 32 byte random string (stolen from chan_sip.c)*/
579 static char *generate_random_string(char *buf, size_t size)
584 for (x = 0; x < 4; x++) {
585 val[x] = ast_random();
587 snprintf(buf, size, "%08lx%08lx%08lx%08lx", val[0], val[1], val[2], val[3]);
592 static int calendar_event_notify(const void *data)
594 struct ast_calendar_event *event = (void *)data;
595 char tech[256], dest[256], buf[8], *tmp;
596 struct ast_dial *dial = NULL;
597 struct ast_channel *chan = NULL;
598 struct ast_str *apptext = NULL;
600 char start[12], end[12], busystate[2];
601 struct ast_datastore *datastore;
603 if (!(event && event->owner)) {
604 ast_log(LOG_ERROR, "Extremely low-cal...in fact cal is NULL!\n");
609 event->notify_sched = -1;
611 ast_copy_string(tech, event->owner->notify_channel, sizeof(tech));
613 if ((tmp = strchr(tech, '/'))) {
616 ast_copy_string(dest, tmp, sizeof(dest));
618 ast_log(LOG_WARNING, "Channel should be in form Tech/Dest\n");
622 if (!(dial = ast_dial_create())) {
623 ast_log(LOG_ERROR, "Could not create dial structure\n");
627 if (ast_dial_append(dial, tech, dest) < 0) {
628 ast_log(LOG_ERROR, "Could not append channel\n");
632 ast_dial_set_global_timeout(dial, event->owner->notify_waittime);
633 generate_random_string(buf, sizeof(buf));
634 if (!(chan = ast_channel_alloc(1, AST_STATE_DOWN, 0, 0, 0, 0, 0, 0, 0, "Calendar/%s-%s", event->owner->name, buf))) {
635 ast_log(LOG_ERROR, "Could not allocate notification channel\n");
639 snprintf(busystate, sizeof(busystate), "%d", event->busy_state);
640 snprintf(start, sizeof(start), "%lu", event->start);
641 snprintf(end, sizeof(end), "%lu", event->end);
643 chan->nativeformats = AST_FORMAT_SLINEAR;
645 if (!(datastore = ast_datastore_alloc(&event_notification_datastore, NULL))) {
646 ast_log(LOG_ERROR, "Could not allocate datastore, notification not being sent!\n");
650 datastore->data = event;
651 datastore->inheritance = DATASTORE_INHERIT_FOREVER;
654 res = ast_channel_datastore_add(chan, datastore);
656 if (!(apptext = ast_str_create(32))) {
660 if (!ast_strlen_zero(event->owner->notify_app)) {
661 ast_str_set(&apptext, 0, "%s,%s", event->owner->notify_app, event->owner->notify_appdata);
663 ast_str_set(&apptext, 0, "Dial,Local/%s@%s", event->owner->notify_extension, event->owner->notify_context);
665 ast_dial_option_global_enable(dial, AST_DIAL_OPTION_ANSWER_EXEC, ast_str_buffer(apptext));
667 ast_dial_run(dial, chan, 1);
671 event = ast_calendar_unref_event(event);
672 if (res == -1 && dial) {
673 ast_dial_destroy(dial);
679 ast_channel_release(chan);
685 static int calendar_devstate_change(const void *data)
687 struct ast_calendar_event *event = (struct ast_calendar_event *)data;
688 struct timeval now = ast_tvnow();
692 ast_log(LOG_WARNING, "Event was NULL!\n");
698 is_end_event = event->end <= now.tv_sec;
701 event->bs_end_sched = -1;
703 event->bs_start_sched = -1;
706 /* We can have overlapping events, so ignore the event->busy_state and check busy state
707 * based on all events in the calendar */
708 if (!calendar_is_busy(event->owner)) {
709 ast_devstate_changed(AST_DEVICE_NOT_INUSE, "Calendar/%s", event->owner->name);
711 ast_devstate_changed(AST_DEVICE_BUSY, "Calendar/%s", event->owner->name);
714 event = ast_calendar_unref_event(event);
719 static void copy_event_data(struct ast_calendar_event *dst, struct ast_calendar_event *src)
721 struct ast_calendar_attendee *attendee;
723 ast_string_field_set(dst, summary, src->summary);
724 ast_string_field_set(dst, description, src->description);
725 ast_string_field_set(dst, organizer, src->organizer);
726 ast_string_field_set(dst, location, src->location);
727 ast_string_field_set(dst, uid, src->uid);
728 dst->owner = src->owner;
729 dst->start = src->start;
731 dst->alarm = src->alarm;
732 dst->busy_state = src->busy_state;
734 while ((attendee = AST_LIST_REMOVE_HEAD(&src->attendees, next))) {
735 AST_LIST_INSERT_TAIL(&dst->attendees, attendee, next);
739 static int schedule_calendar_event(struct ast_calendar *cal, struct ast_calendar_event *old_event, struct ast_calendar_event *cmp_event)
741 struct timeval now = ast_tvnow();
742 struct ast_calendar_event *event;
743 time_t alarm_notify_sched = 0, devstate_sched_start, devstate_sched_end;
746 event = cmp_event ? cmp_event : old_event;
749 if (!cmp_event || old_event->alarm != event->alarm) {
751 if (cal->autoreminder) {
752 alarm_notify_sched = (event->start - (60 * cal->autoreminder) - now.tv_sec) * 1000;
753 } else if (event->alarm) {
754 alarm_notify_sched = (event->alarm - now.tv_sec) * 1000;
757 /* For now, send the notification if we missed it, but the meeting hasn't happened yet */
758 if (event->start >= now.tv_sec) {
759 if (alarm_notify_sched <= 0) {
760 alarm_notify_sched = 1;
762 ast_mutex_lock(&refreshlock);
763 AST_SCHED_REPLACE(old_event->notify_sched, sched, alarm_notify_sched, calendar_event_notify, old_event);
764 ast_mutex_unlock(&refreshlock);
765 ast_debug(3, "Calendar alarm event notification scheduled to happen in %ld ms\n", alarm_notify_sched);
769 if (!cmp_event || old_event->start != event->start) {
771 devstate_sched_start = (event->start - now.tv_sec) * 1000;
773 if (devstate_sched_start < 1) {
774 devstate_sched_start = 1;
777 ast_mutex_lock(&refreshlock);
778 AST_SCHED_REPLACE(old_event->bs_start_sched, sched, devstate_sched_start, calendar_devstate_change, old_event);
779 ast_mutex_unlock(&refreshlock);
780 ast_debug(3, "Calendar bs_start event notification scheduled to happen in %ld ms\n", devstate_sched_start);
783 if (!cmp_event || old_event->end != event->end) {
785 devstate_sched_end = (event->end - now.tv_sec) * 1000;
786 ast_mutex_lock(&refreshlock);
787 AST_SCHED_REPLACE(old_event->bs_end_sched, sched, devstate_sched_end, calendar_devstate_change, old_event);
788 ast_mutex_unlock(&refreshlock);
789 ast_debug(3, "Calendar bs_end event notification scheduled to happen in %ld ms\n", devstate_sched_end);
793 ast_cond_signal(&refresh_condition);
801 static int merge_events_cb(void *obj, void *arg, int flags)
803 struct ast_calendar_event *old_event = obj, *new_event;
804 struct ao2_container *new_events = arg;
806 /* If we don't find the old_event in new_events, then we can safely delete the old_event */
807 if (!(new_event = find_event(new_events, old_event->uid))) {
808 old_event = destroy_event(old_event);
812 /* We have events to merge. If any data that will affect a scheduler event has changed,
813 * then we need to replace the scheduler event */
814 schedule_calendar_event(old_event->owner, old_event, new_event);
816 /* Since we don't want to mess with cancelling sched events and adding new ones, just
817 * copy the internals of the new_event to the old_event */
818 copy_event_data(old_event, new_event);
820 /* Now we can go ahead and unlink the new_event from new_events and unref it so that only completely
821 * new events remain in the container */
822 ao2_unlink(new_events, new_event);
823 new_event = ast_calendar_unref_event(new_event);
828 static int add_new_event_cb(void *obj, void *arg, int flags)
830 struct ast_calendar_event *new_event = obj;
831 struct ao2_container *events = arg;
833 ao2_link(events, new_event);
834 schedule_calendar_event(new_event->owner, new_event, NULL);
838 void ast_calendar_merge_events(struct ast_calendar *cal, struct ao2_container *new_events)
840 /* Loop through all events attached to the calendar. If there is a matching new event
841 * merge its data over and handle any schedule changes that need to be made. Then remove
842 * the new_event from new_events so that we are left with only new_events that we can add later. */
843 ao2_callback(cal->events, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, merge_events_cb, new_events);
845 /* Now, we should only have completely new events in new_events. Loop through and add them */
846 ao2_callback(new_events, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, add_new_event_cb, cal->events);
850 static int load_config(void *data)
852 struct ast_flags config_flags = { CONFIG_FLAG_FILEUNCHANGED };
853 struct ast_config *tmpcfg;
855 if (!(tmpcfg = ast_config_load2("calendar.conf", "calendar", config_flags)) ||
856 tmpcfg == CONFIG_STATUS_FILEINVALID) {
857 ast_log(LOG_ERROR, "Unable to load config calendar.conf\n");
861 if (tmpcfg == CONFIG_STATUS_FILEUNCHANGED) {
865 if (ast_calendar_config) {
866 ast_config_destroy(ast_calendar_config);
869 ast_calendar_config = tmpcfg;
874 /*! \brief A dialplan function that can be used to determine the busy status of a calendar */
875 static int calendar_busy_exec(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
877 struct ast_calendar *cal;
879 if (ast_strlen_zero(data)) {
880 ast_log(LOG_WARNING, "CALENDAR_BUSY requires an argument: CALENDAR_BUSY(<calendar_name>)\n");
884 cal = find_calendar(data);
887 ast_log(LOG_WARNING, "Could not find calendar '%s'\n", data);
891 strcpy(buf, calendar_is_busy(cal) ? "1" : "0");
896 static struct ast_custom_function calendar_busy_function = {
897 .name = "CALENDAR_BUSY",
898 .read = calendar_busy_exec,
901 static int add_event_to_list(struct eventlist *events, struct ast_calendar_event *event, time_t start, time_t end)
903 struct evententry *entry, *iter;
904 int event_startdiff = abs(start - event->start);
905 int event_enddiff = abs(end - event->end);
908 if (!(entry = ast_calloc(1, sizeof(*entry)))) {
909 ast_log(LOG_ERROR, "Unable to allocate memory for event list\n");
913 entry->event = event;
917 AST_LIST_TRAVERSE_SAFE_BEGIN(events, iter, list) {
918 int startdiff = abs(iter->event->start - start);
920 ast_debug(10, "Comparing %s with startdiff %d to %s with startdiff %d\n", event->summary, event_startdiff, iter->event->summary, startdiff);
922 if (startdiff > event_startdiff) {
923 AST_LIST_INSERT_BEFORE_CURRENT(entry, list);
926 if (startdiff == event_startdiff) {
927 int enddiff = abs(iter->event->end - end);
929 if (enddiff > event_enddiff) {
930 AST_LIST_INSERT_BEFORE_CURRENT(entry, list);
933 if (event_startdiff == enddiff) {
934 if (strcmp(event->uid, iter->event->uid) < 0) {
935 AST_LIST_INSERT_BEFORE_CURRENT(entry, list);
941 AST_LIST_TRAVERSE_SAFE_END;
943 AST_LIST_INSERT_TAIL(events, entry, list);
948 AST_LIST_TRAVERSE_SAFE_BEGIN(events, iter, list) {
950 if (iter->event->start > event->start) {
951 AST_LIST_INSERT_BEFORE_CURRENT(entry, list);
955 if (iter->event->start == event->start) {
956 if ((iter->event->end - iter->event->start) == (event->end - event->start)) {
957 if (strcmp(event->uid, iter->event->uid) < 0) {
958 AST_LIST_INSERT_BEFORE_CURRENT(entry, list);
962 if ((iter->event->end - iter->event->start) < (event->end - event->start)) {
963 AST_LIST_INSERT_BEFORE_CURRENT(entry, list);
968 AST_LIST_TRAVERSE_SAFE_END;
970 AST_LIST_INSERT_TAIL(events, entry, list);
975 static void eventlist_destroy(void *data)
977 struct eventlist *events = data;
982 static void *eventlist_duplicate(void *data)
984 struct eventlist *events = data;
995 static int calendar_query_exec(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
997 struct ast_calendar *cal;
998 struct ao2_iterator i;
999 struct ast_calendar_event *event;
1000 struct eventlist *events;
1001 time_t start = INT_MIN, end = INT_MAX;
1002 struct ast_datastore *eventlist_datastore;
1003 AST_DECLARE_APP_ARGS(args,
1004 AST_APP_ARG(calendar);
1010 ast_log(LOG_WARNING, "%s requires a channel to store the data on\n", cmd);
1014 AST_STANDARD_APP_ARGS(args, data);
1016 if (ast_strlen_zero(args.calendar)) {
1017 ast_log(LOG_WARNING, "%s requires a calendar argument\n", cmd);
1021 if (!(cal = find_calendar(args.calendar))) {
1022 ast_log(LOG_WARNING, "Unknown calendar '%s'\n", args.calendar);
1026 if (!(events = ao2_alloc(sizeof(*events), eventlist_destructor))) {
1027 ast_log(LOG_ERROR, "Unable to allocate memory for event list\n");
1028 cal = unref_calendar(cal);
1032 if (!ast_strlen_zero(args.start)) {
1033 start = atoi(args.start);
1036 if (!ast_strlen_zero(args.end)) {
1037 end = atoi(args.end);
1040 i = ao2_iterator_init(cal->events, 0);
1041 while ((event = ao2_iterator_next(&i))) {
1042 if (!(start > event->end || end < event->start)) {
1043 ast_debug(10, "%s (%ld - %ld) overlapped with (%ld - %ld)\n", event->summary, event->start, event->end, start, end);
1044 if (add_event_to_list(events, event, start, end) < 0) {
1045 event = ast_calendar_unref_event(event);
1050 event = ast_calendar_unref_event(event);
1053 ast_channel_lock(chan);
1055 generate_random_string(buf, len);
1056 } while (ast_channel_datastore_find(chan, &eventlist_datastore_info, buf));
1057 ast_channel_unlock(chan);
1059 if (!(eventlist_datastore = ast_datastore_alloc(&eventlist_datastore_info, buf))) {
1060 ast_log(LOG_ERROR, "Could not allocate datastore!\n");
1064 eventlist_datastore->inheritance = DATASTORE_INHERIT_FOREVER;
1065 eventlist_datastore->data = events;
1067 ast_channel_lock(chan);
1068 ast_channel_datastore_add(chan, eventlist_datastore);
1069 ast_channel_unlock(chan);
1074 static struct ast_custom_function calendar_query_function = {
1075 .name = "CALENDAR_QUERY",
1076 .read = calendar_query_exec,
1079 static void calendar_join_attendees(struct ast_calendar_event *event, char *buf, size_t len)
1081 struct ast_str *tmp;
1082 struct ast_calendar_attendee *attendee;
1084 if (!(tmp = ast_str_create(32))) {
1085 ast_log(LOG_ERROR, "Could not allocate memory for attendees!\n");
1089 AST_LIST_TRAVERSE(&event->attendees, attendee, next) {
1090 ast_str_append(&tmp, 0, "%s%s", attendee == AST_LIST_FIRST(&event->attendees) ? "" : ",", attendee->data);
1093 ast_copy_string(buf, ast_str_buffer(tmp), len);
1097 static int calendar_query_result_exec(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
1099 struct ast_datastore *datastore;
1100 struct eventlist *events;
1101 struct evententry *entry;
1103 AST_DECLARE_APP_ARGS(args,
1110 ast_log(LOG_WARNING, "%s requires a channel\n", cmd);
1114 AST_STANDARD_APP_ARGS(args, data);
1116 if (ast_strlen_zero(args.id) || ast_strlen_zero(args.field)) {
1117 ast_log(LOG_WARNING, "%s requires an id and a field", cmd);
1121 ast_channel_lock(chan);
1122 if (!(datastore = ast_channel_datastore_find(chan, &eventlist_datastore_info, args.id))) {
1123 ast_log(LOG_WARNING, "There is no event notification datastore with id '%s' on '%s'!\n", args.id, chan->name);
1124 ast_channel_unlock(chan);
1127 ast_channel_unlock(chan);
1129 if (!(events = datastore->data)) {
1130 ast_log(LOG_WARNING, "The datastore contains no data!\n");
1134 if (!ast_strlen_zero(args.row)) {
1135 row = atoi(args.row);
1138 AST_LIST_TRAVERSE(events, entry, list) {
1142 if (!strcasecmp(args.field, "summary")) {
1143 ast_copy_string(buf, entry->event->summary, len);
1144 } else if (!strcasecmp(args.field, "description")) {
1145 ast_copy_string(buf, entry->event->description, len);
1146 } else if (!strcasecmp(args.field, "organizer")) {
1147 ast_copy_string(buf, entry->event->organizer, len);
1148 } else if (!strcasecmp(args.field, "location")) {
1149 ast_copy_string(buf, entry->event->location, len);
1150 } else if (!strcasecmp(args.field, "calendar")) {
1151 ast_copy_string(buf, entry->event->owner->name, len);
1152 } else if (!strcasecmp(args.field, "uid")) {
1153 ast_copy_string(buf, entry->event->uid, len);
1154 } else if (!strcasecmp(args.field, "start")) {
1155 snprintf(buf, len, "%ld", entry->event->start);
1156 } else if (!strcasecmp(args.field, "end")) {
1157 snprintf(buf, len, "%ld", entry->event->end);
1158 } else if (!strcasecmp(args.field, "busystate")) {
1159 snprintf(buf, len, "%d", entry->event->busy_state);
1160 } else if (!strcasecmp(args.field, "attendees")) {
1161 calendar_join_attendees(entry->event, buf, len);
1163 ast_log(LOG_WARNING, "Unknown field '%s'\n", args.field);
1171 static struct ast_custom_function calendar_query_result_function = {
1172 .name = "CALENDAR_QUERY_RESULT",
1173 .read = calendar_query_result_exec,
1176 static int calendar_write_exec(struct ast_channel *chan, const char *cmd, char *data, const char *value)
1179 char *val_dup = NULL;
1180 struct ast_calendar *cal = NULL;
1181 struct ast_calendar_event *event = NULL;
1182 AST_DECLARE_APP_ARGS(fields,
1183 AST_APP_ARG(field)[10];
1185 AST_DECLARE_APP_ARGS(values,
1186 AST_APP_ARG(value)[10];
1189 if (!(val_dup = ast_strdup(value))) {
1190 ast_log(LOG_ERROR, "Could not allocate memory for values\n");
1194 AST_STANDARD_APP_ARGS(fields, data);
1195 AST_STANDARD_APP_ARGS(values, val_dup);
1197 /* XXX Eventually we will support unnamed calendars, so if we don't find one, we parse
1198 * for a calendar type and create it */
1199 if (!(cal = find_calendar(fields.field[0]))) {
1200 ast_log(LOG_WARNING, "Couldn't find calendar '%s'\n", fields.field[0]);
1204 if (!(cal->tech->write_event)) {
1205 ast_log(LOG_WARNING, "Calendar '%s' has no write function!\n", cal->name);
1209 if (!(event = ast_calendar_event_alloc(cal))) {
1213 if (ast_strlen_zero(fields.field[0])) {
1214 ast_log(LOG_WARNING, "CALENDAR_WRITE requires a calendar name!\n");
1218 if (fields.argc - 1 != values.argc) {
1219 ast_log(LOG_WARNING, "CALENDAR_WRITE should have the same number of fields (%d) and values (%d)!\n", fields.argc - 1, values.argc);
1225 for (i = 1, j = 0; i < fields.argc; i++, j++) {
1226 if (!strcasecmp(fields.field[i], "summary")) {
1227 ast_string_field_set(event, summary, values.value[j]);
1228 } else if (!strcasecmp(fields.field[i], "description")) {
1229 ast_string_field_set(event, description, values.value[j]);
1230 } else if (!strcasecmp(fields.field[i], "organizer")) {
1231 ast_string_field_set(event, organizer, values.value[j]);
1232 } else if (!strcasecmp(fields.field[i], "location")) {
1233 ast_string_field_set(event, location, values.value[j]);
1234 } else if (!strcasecmp(fields.field[i], "uid")) {
1235 ast_string_field_set(event, uid, values.value[j]);
1236 } else if (!strcasecmp(fields.field[i], "start")) {
1237 event->start = atoi(values.value[j]);
1238 } else if (!strcasecmp(fields.field[i], "end")) {
1239 event->end = atoi(values.value[j]);
1240 } else if (!strcasecmp(fields.field[i], "busystate")) {
1241 event->busy_state = atoi(values.value[j]);
1243 ast_log(LOG_WARNING, "Unknown calendar event field '%s'\n", fields.field[i]);
1247 if((ret = cal->tech->write_event(event))) {
1248 ast_log(LOG_WARNING, "Writing event to calendar '%s' failed!\n", cal->name);
1253 cal = unref_calendar(cal);
1256 event = ast_calendar_unref_event(event);
1265 static struct ast_custom_function calendar_write_function = {
1266 .name = "CALENDAR_WRITE",
1267 .write = calendar_write_exec,
1270 /*! \brief CLI command to list available calendars */
1271 static char *handle_show_calendars(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1273 #define FORMAT "%-20.20s %-10.10s %-6.6s\n"
1274 struct ao2_iterator i;
1275 struct ast_calendar *cal;
1279 e->command = "calendar show calendars";
1281 "Usage: calendar show calendars\n"
1282 " Lists all registered calendars.\n";
1288 ast_cli(a->fd, FORMAT, "Calendar", "Type", "Status");
1289 ast_cli(a->fd, FORMAT, "--------", "----", "------");
1290 i = ao2_iterator_init(calendars, 0);
1291 while ((cal = ao2_iterator_next(&i))) {
1292 ast_cli(a->fd, FORMAT, cal->name, cal->tech->type, calendar_is_busy(cal) ? "busy" : "free");
1293 cal = unref_calendar(cal);
1300 static char *epoch_to_string(char *buf, size_t buflen, time_t epoch)
1303 struct timeval tv = {
1311 ast_localtime(&tv, &tm, NULL);
1312 ast_strftime(buf, buflen, "%F %r", &tm);
1317 static char *handle_show_calendar(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1319 #define FORMAT "%-17.17s : %-20.20s\n"
1320 #define FORMAT2 "%-12.12s: %-40.60s\n"
1321 struct ao2_iterator i;
1322 struct ast_calendar *cal;
1323 struct ast_calendar_event *event;
1329 e->command = "calendar show calendar";
1331 "Usage: calendar show calendar <calendar name>\n"
1332 " Displays information about a calendar\n";
1339 i = ao2_iterator_init(calendars, 0);
1340 while ((cal = ao2_iterator_next(&i))) {
1341 if (!strncasecmp(a->word, cal->name, strlen(a->word)) && ++which > a->n) {
1342 ret = ast_strdup(cal->name);
1343 cal = unref_calendar(cal);
1346 cal = unref_calendar(cal);
1352 return CLI_SHOWUSAGE;
1355 if (!(cal = find_calendar(a->argv[3]))) {
1359 ast_cli(a->fd, FORMAT, "Name", cal->name);
1360 ast_cli(a->fd, FORMAT, "Notify channel", cal->notify_channel);
1361 ast_cli(a->fd, FORMAT, "Notify context", cal->notify_context);
1362 ast_cli(a->fd, FORMAT, "Notify extension", cal->notify_extension);
1363 ast_cli(a->fd, FORMAT, "Notify application", cal->notify_app);
1364 ast_cli(a->fd, FORMAT, "Notify appdata", cal->notify_appdata);
1365 ast_cli(a->fd, "%-17.17s : %d\n", "Refresh time", cal->refresh);
1366 ast_cli(a->fd, "%-17.17s : %d\n", "Timeframe", cal->timeframe);
1367 ast_cli(a->fd, "%-17.17s : %d\n", "Autoreminder", cal->autoreminder);
1368 ast_cli(a->fd, "%s\n", "Events");
1369 ast_cli(a->fd, "%s\n", "------");
1371 i = ao2_iterator_init(cal->events, 0);
1372 while ((event = ao2_iterator_next(&i))) {
1375 ast_cli(a->fd, FORMAT2, "Summary", event->summary);
1376 ast_cli(a->fd, FORMAT2, "Description", event->description);
1377 ast_cli(a->fd, FORMAT2, "Organizer", event->organizer);
1378 ast_cli(a->fd, FORMAT2, "Location", event->location);
1379 ast_cli(a->fd, FORMAT2, "UID", event->uid);
1380 ast_cli(a->fd, FORMAT2, "Start", epoch_to_string(buf, sizeof(buf), event->start));
1381 ast_cli(a->fd, FORMAT2, "End", epoch_to_string(buf, sizeof(buf), event->end));
1382 ast_cli(a->fd, FORMAT2, "Alarm", epoch_to_string(buf, sizeof(buf), event->alarm));
1383 ast_cli(a->fd, "\n");
1385 event = ast_calendar_unref_event(event);
1387 cal = unref_calendar(cal);
1393 static char *handle_dump_sched(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1397 e->command = "calendar dump sched";
1399 "Usage: calendar dump sched\n"
1400 " Dump the calendar sched context";
1407 ast_sched_dump(sched);
1412 static struct ast_cli_entry calendar_cli[] = {
1413 AST_CLI_DEFINE(handle_show_calendar, "Display information about a calendar"),
1414 AST_CLI_DEFINE(handle_show_calendars, "Show registered calendars"),
1415 AST_CLI_DEFINE(handle_dump_sched, "Dump calendar sched context"),
1418 static int calendar_event_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
1420 struct ast_datastore *datastore;
1421 struct ast_calendar_event *event;
1423 if (ast_strlen_zero(data)) {
1424 ast_log(LOG_WARNING, "%s requires an argument\n", cmd);
1428 ast_channel_lock(chan);
1429 if (!(datastore = ast_channel_datastore_find(chan, &event_notification_datastore, NULL))) {
1430 ast_log(LOG_WARNING, "There is no event notification datastore on '%s'!\n", chan->name);
1431 ast_channel_unlock(chan);
1434 ast_channel_unlock(chan);
1436 if (!(event = datastore->data)) {
1437 ast_log(LOG_WARNING, "The datastore contains no data!\n");
1441 if (!strcasecmp(data, "summary")) {
1442 ast_copy_string(buf, event->summary, len);
1443 } else if (!strcasecmp(data, "description")) {
1444 ast_copy_string(buf, event->description, len);
1445 } else if (!strcasecmp(data, "organizer")) {
1446 ast_copy_string(buf, event->organizer, len);
1447 } else if (!strcasecmp(data, "location")) {
1448 ast_copy_string(buf, event->location, len);
1449 } else if (!strcasecmp(data, "calendar")) {
1450 ast_copy_string(buf, event->owner->name, len);
1451 } else if (!strcasecmp(data, "uid")) {
1452 ast_copy_string(buf, event->uid, len);
1453 } else if (!strcasecmp(data, "start")) {
1454 snprintf(buf, len, "%ld", (long)event->start);
1455 } else if (!strcasecmp(data, "end")) {
1456 snprintf(buf, len, "%ld", (long)event->end);
1457 } else if (!strcasecmp(data, "busystate")) {
1458 snprintf(buf, len, "%d", event->busy_state);
1459 } else if (!strcasecmp(data, "attendees")) {
1460 calendar_join_attendees(event, buf, len);
1467 static struct ast_custom_function calendar_event_function = {
1468 .name = "CALENDAR_EVENT",
1469 .read = calendar_event_read,
1472 static int cb_pending_deletion(void *user_data, void *arg, int flags)
1474 struct ast_calendar *cal = user_data;
1476 cal->pending_deletion = 1;
1481 static int cb_rm_pending_deletion(void *user_data, void *arg, int flags)
1483 struct ast_calendar *cal = user_data;
1485 return cal->pending_deletion ? CMP_MATCH : 0;
1488 static int reload(void)
1490 struct ast_calendar_tech *iter;
1492 ast_mutex_lock(&reloadlock);
1494 /* Mark existing calendars for deletion */
1495 ao2_callback(calendars, OBJ_NODATA | OBJ_MULTIPLE, cb_pending_deletion, NULL);
1498 AST_LIST_LOCK(&techs);
1499 AST_LIST_TRAVERSE(&techs, iter, list) {
1500 if (load_tech_calendars(iter)) {
1501 ast_log(LOG_WARNING, "Failed to reload %s calendars, module disabled\n", iter->type);
1504 AST_LIST_UNLOCK(&techs);
1506 /* Delete calendars that no longer show up in the config */
1507 ao2_callback(calendars, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, cb_rm_pending_deletion, NULL);
1509 ast_mutex_unlock(&reloadlock);
1514 static void *do_refresh(void *data)
1517 struct timeval now = ast_tvnow();
1518 struct timespec ts = {0,};
1521 ast_mutex_lock(&refreshlock);
1523 if ((wait = ast_sched_wait(sched)) < 0) {
1527 ts.tv_sec = (now.tv_sec + wait / 1000) + 1;
1528 res = ast_cond_timedwait(&refresh_condition, &refreshlock, &ts);
1530 ast_mutex_unlock(&refreshlock);
1532 ast_sched_runq(sched);
1538 /* If I were to allow unloading it would look something like this */
1539 static int unload_module(void)
1541 struct ast_calendar_tech *tech;
1543 ast_devstate_prov_del("calendar");
1544 ast_custom_function_unregister(&calendar_busy_function);
1545 ast_custom_function_unregister(&calendar_event_function);
1546 ast_custom_function_unregister(&calendar_query_function);
1547 ast_custom_function_unregister(&calendar_query_result_function);
1548 ast_custom_function_unregister(&calendar_write_function);
1549 ast_cli_unregister_multiple(calendar_cli, ARRAY_LEN(calendar_cli));
1551 /* Remove all calendars */
1552 ao2_callback(calendars, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, NULL, NULL);
1554 AST_LIST_LOCK(&techs);
1555 AST_LIST_TRAVERSE_SAFE_BEGIN(&techs, tech, list) {
1556 ast_unload_resource(tech->module, 0);
1558 AST_LIST_TRAVERSE_SAFE_END;
1559 AST_LIST_UNLOCK(&techs);
1564 static int load_module(void)
1566 if (load_config(NULL)) {
1567 /* We don't have calendar support enabled */
1571 if (!(calendars = ao2_container_alloc(CALENDAR_BUCKETS, calendar_hash_fn, calendar_cmp_fn))) {
1572 ast_log(LOG_ERROR, "Unable to allocate calendars container!\n");
1576 ast_mutex_init(&refreshlock);
1577 ast_cond_init(&refresh_condition, NULL);
1578 ast_mutex_init(&reloadlock);
1580 if (!(sched = sched_context_create())) {
1581 ast_log(LOG_ERROR, "Unable to create sched context\n");
1585 if (ast_pthread_create_background(&refresh_thread, NULL, do_refresh, NULL) < 0) {
1586 ast_log(LOG_ERROR, "Unable to start refresh thread--notifications disabled!\n");
1589 ast_custom_function_register(&calendar_busy_function);
1590 ast_custom_function_register(&calendar_event_function);
1591 ast_custom_function_register(&calendar_query_function);
1592 ast_custom_function_register(&calendar_query_result_function);
1593 ast_custom_function_register(&calendar_write_function);
1594 ast_cli_register_multiple(calendar_cli, ARRAY_LEN(calendar_cli));
1596 ast_devstate_prov_add("Calendar", calendarstate);
1598 /* Since other modules depend on this, disable unloading */
1599 ast_module_ref(ast_module_info->self);
1603 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS, "Asterisk Calendar integration",
1604 .load = load_module,
1605 .unload = unload_module,