Asterisk - The Open Source Telephony Project  21.4.1
Data Structures | Macros | Functions | Variables
res_calendar.c File Reference

Calendaring API. More...

#include "asterisk.h"
#include "asterisk/_private.h"
#include "asterisk/channel.h"
#include "asterisk/calendar.h"
#include "asterisk/utils.h"
#include "asterisk/astobj2.h"
#include "asterisk/module.h"
#include "asterisk/config.h"
#include "asterisk/devicestate.h"
#include "asterisk/linkedlists.h"
#include "asterisk/sched.h"
#include "asterisk/dial.h"
#include "asterisk/cli.h"
#include "asterisk/pbx.h"
#include "asterisk/app.h"
#include "asterisk/format_cache.h"

Go to the source code of this file.

Data Structures

struct  evententry
 
struct  eventlist
 
struct  techs
 

Macros

#define CALENDAR_BUCKETS   19
 
#define FORMAT   "%-20.20s %-10.10s %-6.6s\n"
 
#define FORMAT   "%-10.10s %-30.30s\n"
 
#define FORMAT   "%-18.18s : %-20.20s\n"
 
#define FORMAT2   "%-12.12s: %-40.60s\n"
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
static int add_event_to_list (struct eventlist *events, struct ast_calendar_event *event, time_t start, time_t end)
 
static int add_new_event_cb (void *obj, void *arg, int flags)
 
static const char * ast_calendar_busy_state_to_str (enum ast_calendar_busy_state busy_state)
 
void ast_calendar_clear_events (struct ast_calendar *cal)
 Remove all events from calendar. More...
 
const struct ast_configast_calendar_config_acquire (void)
 Grab and lock pointer to the calendar config (read only) More...
 
void ast_calendar_config_release (void)
 Release the calendar config.
 
struct ast_calendar_eventast_calendar_event_alloc (struct ast_calendar *cal)
 Allocate an astobj2 ast_calendar_event object. More...
 
struct ao2_containerast_calendar_event_container_alloc (void)
 Allocate an astobj2 container for ast_calendar_event objects. More...
 
void ast_calendar_merge_events (struct ast_calendar *cal, struct ao2_container *new_events)
 Add an event to the list of events for a calendar. More...
 
int ast_calendar_register (struct ast_calendar_tech *tech)
 Register a new calendar technology. More...
 
struct ast_calendar_eventast_calendar_unref_event (struct ast_calendar_event *event)
 Unreference an ast_calendar_event. More...
 
void ast_calendar_unregister (struct ast_calendar_tech *tech)
 Unregister a new calendar technology. More...
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static struct ast_calendarbuild_calendar (struct ast_config *cfg, const char *cat, const struct ast_calendar_tech *tech)
 
static int calendar_busy_callback (void *obj, void *arg, int flags)
 
static int calendar_busy_exec (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
 A dialplan function that can be used to determine the busy status of a calendar.
 
static int calendar_cmp_fn (void *obj, void *arg, int flags)
 
static void calendar_destructor (void *obj)
 
static int calendar_devstate_change (const void *data)
 
static void calendar_event_destructor (void *obj)
 
static int calendar_event_notify (const void *data)
 
static int calendar_event_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
 
static int calendar_hash_fn (const void *obj, const int flags)
 
static int calendar_is_busy (struct ast_calendar *cal)
 
static void calendar_join_attendees (struct ast_calendar_event *event, char *buf, size_t len)
 
static int calendar_query_exec (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
 
static int calendar_query_result_exec (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
 
static int calendar_write_exec (struct ast_channel *chan, const char *cmd, char *data, const char *value)
 
static enum ast_device_state calendarstate (const char *data)
 
static int cb_pending_deletion (void *user_data, void *arg, int flags)
 
static int cb_rm_pending_deletion (void *user_data, void *arg, int flags)
 
static int clear_events_cb (void *user_data, void *arg, int flags)
 
static void copy_event_data (struct ast_calendar_event *dst, struct ast_calendar_event *src)
 
static struct ast_calendar_eventdestroy_event (struct ast_calendar_event *event)
 
static void * do_notify (void *data)
 
static void * do_refresh (void *data)
 
static char * epoch_to_string (char *buf, size_t buflen, time_t epoch)
 
static int event_cmp_fn (void *obj, void *arg, int flags)
 
static int event_hash_fn (const void *obj, const int flags)
 
static void event_notification_destroy (void *data)
 
static void * event_notification_duplicate (void *data)
 
static void eventlist_destroy (void *data)
 
static void eventlist_destructor (void *obj)
 
static void * eventlist_duplicate (void *data)
 
static struct ast_calendarfind_calendar (const char *name)
 
static struct ast_calendar_eventfind_event (struct ao2_container *events, const char *uid)
 
static char * generate_random_string (char *buf, size_t size)
 Generate 32 byte random string (stolen from chan_sip.c)
 
static char * handle_dump_sched (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * handle_show_calendar (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * handle_show_calendars (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 CLI command to list available calendars.
 
static char * handle_show_calendars_types (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 CLI command to list of all calendars types currently loaded on the backend.
 
static int load_config (int reload)
 
static int load_module (void)
 Load the module. More...
 
static int load_tech_calendars (struct ast_calendar_tech *tech)
 
static int match_caltech_cb (void *user_data, void *arg, int flags)
 
static int merge_events_cb (void *obj, void *arg, int flags)
 
static int null_chan_write (struct ast_channel *chan, struct ast_frame *frame)
 
static int reload (void)
 
static int schedule_calendar_event (struct ast_calendar *cal, struct ast_calendar_event *old_event, struct ast_calendar_event *cmp_event)
 
static int unload_module (void)
 
static struct ast_calendarunref_calendar (struct ast_calendar *cal)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER , .description = "Asterisk Calendar integration" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "da6642af068ee5e6490c5b1d2cc1d238" , .support_level = AST_MODULE_SUPPORT_EXTENDED, .load = load_module, .unload = unload_module, .reload = reload, .load_pri = AST_MODPRI_DEVSTATE_PROVIDER, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct ast_custom_function calendar_busy_function
 
static struct ast_cli_entry calendar_cli []
 
static struct ast_configcalendar_config
 
static struct ast_custom_function calendar_event_function
 
static struct ast_custom_function calendar_query_function
 
static struct ast_custom_function calendar_query_result_function
 
static struct ast_custom_function calendar_write_function
 
static struct ao2_containercalendars
 
static ast_rwlock_t config_lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} }
 
static const struct ast_datastore_info event_notification_datastore
 
static const struct ast_datastore_info eventlist_datastore_info
 
static int module_unloading
 
static const struct ast_channel_tech null_tech
 
static ast_cond_t refresh_condition
 
static pthread_t refresh_thread = AST_PTHREADT_NULL
 
static ast_mutex_t refreshlock
 
static ast_mutex_t reloadlock
 
static struct ast_sched_contextsched
 
static struct techs techs = { .first = NULL, .last = NULL, .lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} } , }
 

Detailed Description

Calendaring API.

Todo:

Support responding to a meeting invite

Support writing attendees

Definition in file res_calendar.c.

Function Documentation

void ast_calendar_clear_events ( struct ast_calendar cal)

Remove all events from calendar.

Parameters
calcalendar whose events need to be cleared

Definition at line 662 of file res_calendar.c.

References ao2_callback, ast_debug, ast_calendar::events, ast_calendar::name, OBJ_MULTIPLE, OBJ_NODATA, and OBJ_UNLINK.

663 {
664  ast_debug(3, "Clearing all events for calendar %s\n", cal->name);
665 
666  ao2_callback(cal->events, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, clear_events_cb, NULL);
667 }
#define ao2_callback(c, flags, cb_fn, arg)
ao2_callback() is a generic function that applies cb_fn() to all objects in a container, as described below.
Definition: astobj2.h:1693
#define ast_debug(level,...)
Log a DEBUG message.
const ast_string_field name
Definition: calendar.h:129
struct ao2_container * events
Definition: calendar.h:140
const struct ast_config* ast_calendar_config_acquire ( void  )

Grab and lock pointer to the calendar config (read only)

Note
ast_calendar_config_release must be called when finished with the pointer
Returns
the parsed calendar config

Definition at line 260 of file res_calendar.c.

261 {
262  ast_rwlock_rdlock(&config_lock);
263 
264  if (!calendar_config) {
265  ast_rwlock_unlock(&config_lock);
266  return NULL;
267  }
268 
269  return calendar_config;
270 }
struct ast_calendar_event* ast_calendar_event_alloc ( struct ast_calendar cal)

Allocate an astobj2 ast_calendar_event object.

Parameters
calcalendar to allocate an event for
Returns
a new, initialized calendar event

Definition at line 669 of file res_calendar.c.

References ast_calendar_unref_event(), AST_LIST_HEAD_INIT_NOLOCK, and ast_string_field_init.

670 {
671  struct ast_calendar_event *event;
672  if (!(event = ao2_alloc(sizeof(*event), calendar_event_destructor))) {
673  return NULL;
674  }
675 
676  if (ast_string_field_init(event, 32)) {
677  event = ast_calendar_unref_event(event);
678  return NULL;
679  }
680 
681  event->owner = cal;
682  event->notify_sched = -1;
683  event->bs_start_sched = -1;
684  event->bs_end_sched = -1;
685 
686  AST_LIST_HEAD_INIT_NOLOCK(&event->attendees);
687 
688  return event;
689 }
Definition: astman.c:222
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Definition: stringfields.h:359
#define AST_LIST_HEAD_INIT_NOLOCK(head)
Initializes a list head structure.
Definition: linkedlists.h:681
Calendar events.
Definition: calendar.h:95
struct ast_calendar_event * ast_calendar_unref_event(struct ast_calendar_event *event)
Unreference an ast_calendar_event.
Definition: res_calendar.c:323
struct ao2_container* ast_calendar_event_container_alloc ( void  )

Allocate an astobj2 container for ast_calendar_event objects.

Returns
a new event container

Definition at line 691 of file res_calendar.c.

References AO2_ALLOC_OPT_LOCK_MUTEX, and ao2_container_alloc_hash.

692 {
693  return ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, CALENDAR_BUCKETS,
694  event_hash_fn, NULL, event_cmp_fn);
695 }
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Allocate and initialize a hash container with the desired number of buckets.
Definition: astobj2.h:1303
void ast_calendar_merge_events ( struct ast_calendar cal,
struct ao2_container new_events 
)

Add an event to the list of events for a calendar.

Parameters
calcalendar containing the events to be merged
new_eventsan oa2 container of events to be merged into cal->events

Definition at line 1060 of file res_calendar.c.

References ao2_callback, ast_calendar::events, OBJ_MULTIPLE, OBJ_NODATA, and OBJ_UNLINK.

1061 {
1062  /* Loop through all events attached to the calendar. If there is a matching new event
1063  * merge its data over and handle any schedule changes that need to be made. Then remove
1064  * the new_event from new_events so that we are left with only new_events that we can add later. */
1065  ao2_callback(cal->events, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, merge_events_cb, new_events);
1066 
1067  /* Now, we should only have completely new events in new_events. Loop through and add them */
1068  ao2_callback(new_events, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, add_new_event_cb, cal->events);
1069 }
#define ao2_callback(c, flags, cb_fn, arg)
ao2_callback() is a generic function that applies cb_fn() to all objects in a container, as described below.
Definition: astobj2.h:1693
struct ao2_container * events
Definition: calendar.h:140
int ast_calendar_register ( struct ast_calendar_tech tech)

Register a new calendar technology.

Parameters
techcalendar technology to register
Return values
0success
-1failure

Definition at line 551 of file res_calendar.c.

References AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_TRAVERSE, and AST_LIST_UNLOCK.

552 {
553  struct ast_calendar_tech *iter;
554 
555  if (!calendar_config) {
556  ast_log(LOG_WARNING, "Calendar support disabled, not loading %s calendar module\n", tech->type);
557  return -1;
558  }
559 
561  AST_LIST_TRAVERSE(&techs, iter, list) {
562  if(!strcasecmp(tech->type, iter->type)) {
563  ast_log(LOG_WARNING, "Already have a handler for calendar type '%s'\n", tech->type);
565  return -1;
566  }
567  }
568  AST_LIST_INSERT_HEAD(&techs, tech, list);
569  tech->user = ast_module_user_add(NULL);
571 
572  ast_verb(2, "Registered calendar type '%s' (%s)\n", tech->type, tech->description);
573 
574  return load_tech_calendars(tech);
575 }
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:40
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:140
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:491
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
Definition: linkedlists.h:711
Individual calendaring technology data.
Definition: calendar.h:71
struct ast_calendar_event* ast_calendar_unref_event ( struct ast_calendar_event event)

Unreference an ast_calendar_event.

Parameters
eventevent to unref
Returns
NULL

Definition at line 323 of file res_calendar.c.

References ao2_ref.

Referenced by ast_calendar_event_alloc().

324 {
325  ao2_ref(event, -1);
326  return NULL;
327 }
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
void ast_calendar_unregister ( struct ast_calendar_tech tech)

Unregister a new calendar technology.

Parameters
techcalendar technology to unregister

Definition at line 589 of file res_calendar.c.

References ao2_callback, AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, OBJ_MULTIPLE, OBJ_NODATA, and OBJ_UNLINK.

590 {
591  struct ast_calendar_tech *iter;
592 
594  AST_LIST_TRAVERSE_SAFE_BEGIN(&techs, iter, list) {
595  if (iter != tech) {
596  continue;
597  }
598 
599  ao2_callback(calendars, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, match_caltech_cb, tech);
600 
602  ast_module_user_remove(iter->user);
603  ast_verb(2, "Unregistered calendar type '%s'\n", tech->type);
604  break;
605  }
608 
609 }
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:40
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:140
#define ao2_callback(c, flags, cb_fn, arg)
ao2_callback() is a generic function that applies cb_fn() to all objects in a container, as described below.
Definition: astobj2.h:1693
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:615
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:557
Individual calendaring technology data.
Definition: calendar.h:71
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: linkedlists.h:529
static struct ast_calendar* build_calendar ( struct ast_config cfg,
const char *  cat,
const struct ast_calendar_tech tech 
)
static

Create new calendar, old will be removed during reload

Definition at line 402 of file res_calendar.c.

References AO2_ALLOC_OPT_LOCK_MUTEX, ao2_container_alloc_hash, ao2_link, ao2_unlink, ast_strdup, ast_string_field_init, ast_string_field_set, ast_strip(), ast_true(), ast_calendar::autoreminder, ast_calendar::events, ast_calendar::fetch_again_at_reload, ast_calendar_tech::load_calendar, ast_variable::name, ast_calendar::name, ast_variable::next, ast_calendar::notify_channel, ast_calendar::notify_waittime, ast_calendar::refresh, ast_calendar::thread, ast_calendar::timeframe, ast_variable::value, and ast_calendar::vars.

403 {
404  struct ast_calendar *cal;
405  struct ast_variable *v, *last = NULL;
406  int new_calendar = 0;
407 
408  cal = find_calendar(cat);
409  if (cal && cal->fetch_again_at_reload) {
410  /** Create new calendar, old will be removed during reload */
411  cal = unref_calendar(cal);
412  }
413  if (!cal) {
414  new_calendar = 1;
415  if (!(cal = ao2_alloc(sizeof(*cal), calendar_destructor))) {
416  ast_log(LOG_ERROR, "Could not allocate calendar structure. Stopping.\n");
417  return NULL;
418  }
419 
421  CALENDAR_BUCKETS, event_hash_fn, NULL, event_cmp_fn);
422  if (!cal->events) {
423  ast_log(LOG_ERROR, "Could not allocate events container for %s\n", cat);
424  cal = unref_calendar(cal);
425  return NULL;
426  }
427 
428  if (ast_string_field_init(cal, 32)) {
429  ast_log(LOG_ERROR, "Couldn't create string fields for %s\n", cat);
430  cal = unref_calendar(cal);
431  return NULL;
432  }
433  } else {
434  cal->pending_deletion = 0;
435  }
436 
437  ast_string_field_set(cal, name, cat);
438  cal->tech = tech;
439 
440  cal->refresh = 3600;
441  cal->timeframe = 60;
442  cal->notify_waittime = 30000;
443  cal->fetch_again_at_reload = 0;
444 
445  for (v = ast_variable_browse(cfg, cat); v; v = v->next) {
446  if (!strcasecmp(v->name, "autoreminder")) {
447  cal->autoreminder = atoi(v->value);
448  } else if (!strcasecmp(v->name, "channel")) {
449  ast_string_field_set(cal, notify_channel, v->value);
450  } else if (!strcasecmp(v->name, "context")) {
451  ast_string_field_set(cal, notify_context, v->value);
452  } else if (!strcasecmp(v->name, "extension")) {
453  ast_string_field_set(cal, notify_extension, v->value);
454  } else if (!strcasecmp(v->name, "waittime")) {
455  int i = atoi(v->value);
456  if (i > 0) {
457  cal->notify_waittime = 1000 * i;
458  }
459  } else if (!strcasecmp(v->name, "app")) {
460  ast_string_field_set(cal, notify_app, v->value);
461  } else if (!strcasecmp(v->name, "appdata")) {
462  ast_string_field_set(cal, notify_appdata, v->value);
463  } else if (!strcasecmp(v->name, "refresh")) {
464  cal->refresh = atoi(v->value);
465  } else if (!strcasecmp(v->name, "fetch_again_at_reload")) {
467  } else if (!strcasecmp(v->name, "timeframe")) {
468  cal->timeframe = atoi(v->value);
469  } else if (!strcasecmp(v->name, "setvar")) {
470  char *name, *value;
471  struct ast_variable *var;
472 
473  if ((name = (value = ast_strdup(v->value)))) {
474  strsep(&value, "=");
475  if (value) {
476  if ((var = ast_variable_new(ast_strip(name), ast_strip(value), ""))) {
477  if (last) {
478  last->next = var;
479  } else {
480  cal->vars = var;
481  }
482  last = var;
483  }
484  } else {
485  ast_log(LOG_WARNING, "Malformed argument. Should be '%s: variable=value'\n", v->name);
486  }
487  ast_free(name);
488  }
489  }
490  }
491 
492  if (cal->autoreminder && ast_strlen_zero(cal->notify_channel)) {
493  ast_log(LOG_WARNING,
494  "You have set 'autoreminder' but not 'channel' for calendar '%s.' "
495  "Notifications will not occur.\n",
496  cal->name);
497  }
498 
499  if (new_calendar) {
500  cal->thread = AST_PTHREADT_NULL;
501  ast_cond_init(&cal->unload, NULL);
502  ao2_link(calendars, cal);
503  if (ast_pthread_create(&cal->thread, NULL, cal->tech->load_calendar, cal)) {
504  /* If we start failing to create threads, go ahead and return NULL
505  * and the tech module will be unregistered
506  */
507  ao2_unlink(calendars, cal);
508  cal = unref_calendar(cal);
509  }
510  }
511 
512  return cal;
513 }
struct ast_variable * next
int fetch_again_at_reload
Definition: calendar.h:134
struct ast_variable * vars
Definition: calendar.h:130
Structure for variables, used for configurations and for channel variables.
int notify_waittime
Definition: calendar.h:132
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:241
int timeframe
Definition: calendar.h:135
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Definition: stringfields.h:359
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition: strings.h:223
const ast_string_field name
Definition: calendar.h:129
struct ao2_container * events
Definition: calendar.h:140
pthread_t thread
Definition: calendar.h:136
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Allocate and initialize a hash container with the desired number of buckets.
Definition: astobj2.h:1303
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true". This function checks to see whether a string passed to it is an indication of an "true" value. It checks to see if the string is "yes", "true", "y", "t", "on" or "1".
Definition: utils.c:2199
#define ao2_unlink(container, obj)
Remove an object from a container.
Definition: astobj2.h:1578
void *(* load_calendar)(void *data)
Definition: calendar.h:77
Asterisk calendar structure.
Definition: calendar.h:119
int autoreminder
Definition: calendar.h:131
const ast_string_field notify_channel
Definition: calendar.h:129
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:521
#define ao2_link(container, obj)
Add an object to a container.
Definition: astobj2.h:1532
static int load_module ( void  )
static

Load the module.

Module loading including tests for configuration or dependencies. This function can return AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_DECLINE, or AST_MODULE_LOAD_SUCCESS. If a dependency or environment variable fails tests return AST_MODULE_LOAD_FAILURE. If the module can not load the configuration file or other non-critical problem return AST_MODULE_LOAD_DECLINE. On success return AST_MODULE_LOAD_SUCCESS.

Definition at line 1923 of file res_calendar.c.

References AO2_ALLOC_OPT_LOCK_MUTEX, ao2_container_alloc_hash, ast_cli_register_multiple, ast_config_destroy(), ast_custom_function_register, ast_devstate_prov_add(), AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, and ast_sched_context_create().

1924 {
1925  calendars = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, CALENDAR_BUCKETS,
1926  calendar_hash_fn, NULL, calendar_cmp_fn);
1927  if (!calendars) {
1928  ast_log(LOG_ERROR, "Unable to allocate calendars container!\n");
1929  return AST_MODULE_LOAD_DECLINE;
1930  }
1931 
1932  if (load_config(0)) {
1933  /* We don't have calendar support enabled */
1934  return AST_MODULE_LOAD_DECLINE;
1935  }
1936 
1937  ast_mutex_init(&refreshlock);
1938  ast_cond_init(&refresh_condition, NULL);
1939  ast_mutex_init(&reloadlock);
1940 
1941  if (!(sched = ast_sched_context_create())) {
1942  ast_log(LOG_ERROR, "Unable to create sched context\n");
1943  ast_config_destroy(calendar_config);
1944  calendar_config = NULL;
1945  return AST_MODULE_LOAD_DECLINE;
1946  }
1947 
1948  if (ast_pthread_create_background(&refresh_thread, NULL, do_refresh, NULL) < 0) {
1949  ast_log(LOG_ERROR, "Unable to start refresh thread--notifications disabled!\n");
1950  }
1951 
1952  ast_custom_function_register(&calendar_busy_function);
1953  ast_custom_function_register(&calendar_event_function);
1954  ast_custom_function_register(&calendar_query_function);
1955  ast_custom_function_register(&calendar_query_result_function);
1956  ast_custom_function_register(&calendar_write_function);
1957  ast_cli_register_multiple(calendar_cli, ARRAY_LEN(calendar_cli));
1958 
1959  ast_devstate_prov_add("Calendar", calendarstate);
1960 
1961  return AST_MODULE_LOAD_SUCCESS;
1962 }
Definition: sched.c:76
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
int ast_devstate_prov_add(const char *label, ast_devstate_prov_cb_type callback)
Add device state provider.
Definition: devicestate.c:391
struct ast_sched_context * ast_sched_context_create(void)
Create a scheduler context.
Definition: sched.c:238
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Allocate and initialize a hash container with the desired number of buckets.
Definition: astobj2.h:1303
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
void ast_config_destroy(struct ast_config *cfg)
Destroys a config.
Definition: extconf.c:1289
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1558

Variable Documentation

struct ast_custom_function calendar_busy_function
static
Initial value:
= {
.name = "CALENDAR_BUSY",
}
static int calendar_busy_exec(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
A dialplan function that can be used to determine the busy status of a calendar.

Definition at line 1121 of file res_calendar.c.

struct ast_custom_function calendar_event_function
static
Initial value:
= {
.name = "CALENDAR_EVENT",
.read = calendar_event_read,
}

Definition at line 1797 of file res_calendar.c.

struct ast_custom_function calendar_query_function
static
Initial value:
= {
.name = "CALENDAR_QUERY",
.read = calendar_query_exec,
}

Definition at line 1306 of file res_calendar.c.

struct ast_custom_function calendar_query_result_function
static
Initial value:
= {
.name = "CALENDAR_QUERY_RESULT",
.read = calendar_query_result_exec,
}

Definition at line 1417 of file res_calendar.c.

struct ast_custom_function calendar_write_function
static
Initial value:
= {
.name = "CALENDAR_WRITE",
.write = calendar_write_exec,
}

Definition at line 1529 of file res_calendar.c.

const struct ast_datastore_info event_notification_datastore
static
Initial value:
= {
.type = "EventNotification",
.destroy = event_notification_destroy,
.duplicate = event_notification_duplicate,
}

Definition at line 237 of file res_calendar.c.

const struct ast_datastore_info eventlist_datastore_info
static
Initial value:
= {
.type = "CalendarEventList",
.destroy = eventlist_destroy,
.duplicate = eventlist_duplicate,
}

Definition at line 243 of file res_calendar.c.

const struct ast_channel_tech null_tech
static
Initial value:
= {
.type = "NULL",
.description = "Null channel (should not see this)",
.write = null_chan_write,
}

Definition at line 737 of file res_calendar.c.