configs/samples/calendar.conf.sample | 2 ++ include/asterisk/calendar.h | 1 + res/res_calendar.c | 11 ++++++++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/configs/samples/calendar.conf.sample b/configs/samples/calendar.conf.sample index 82b8702..d87b3b2 100644 --- a/configs/samples/calendar.conf.sample +++ b/configs/samples/calendar.conf.sample @@ -6,6 +6,8 @@ ;refresh = 15 ; refresh calendar every n minutes ;timeframe = 60 ; number of minutes of calendar data to pull for each refresh period ; ; should always be >= refresh +;fetch_again_at_reload = no ; to reload the calendar content when the module is reloaded +; ; ; You can set up res_calendar to execute a call upon an upcoming busy status ; The following fields are available from the ${CALENDAR_EVENT()} dialplan function: diff --git a/include/asterisk/calendar.h b/include/asterisk/calendar.h index da4af01..e9dcd88 100644 --- a/include/asterisk/calendar.h +++ b/include/asterisk/calendar.h @@ -129,6 +129,7 @@ struct ast_calendar { int autoreminder; /*!< If set, override any calendar_tech specific notification times and use this time (in mins) */ int notify_waittime; /*!< Maxiumum time to allow for a notification attempt */ int refresh; /*!< When to refresh the calendar events */ + int fetch_again_at_reload; /*!< To reload the calendar content when the module is reloaded */ int timeframe; /*!< Span (in mins) of calendar data to pull with each request */ pthread_t thread; /*!< The thread that the calendar is loaded/updated in */ ast_cond_t unload; diff --git a/res/res_calendar.c b/res/res_calendar.c index 2641654..ba66010 100644 --- a/res/res_calendar.c +++ b/res/res_calendar.c @@ -408,7 +408,13 @@ static struct ast_calendar *build_calendar(struct ast_config *cfg, const char *c struct ast_variable *v, *last = NULL; int new_calendar = 0; - if (!(cal = find_calendar(cat))) { + cal = find_calendar(cat); + if (cal && cal->fetch_again_at_reload) { + /** remove old calendar. New will be created */ + cal->pending_deletion = 1; + cal = unref_calendar(cal); + } + if (!cal) { new_calendar = 1; if (!(cal = ao2_alloc(sizeof(*cal), calendar_destructor))) { ast_log(LOG_ERROR, "Could not allocate calendar structure. Stopping.\n"); @@ -436,6 +442,7 @@ static struct ast_calendar *build_calendar(struct ast_config *cfg, const char *c cal->refresh = 3600; cal->timeframe = 60; cal->notify_waittime = 30000; + cal->fetch_again_at_reload = 1; for (v = ast_variable_browse(cfg, cat); v; v = v->next) { if (!strcasecmp(v->name, "autoreminder")) { @@ -457,6 +464,8 @@ static struct ast_calendar *build_calendar(struct ast_config *cfg, const char *c ast_string_field_set(cal, notify_appdata, v->value); } else if (!strcasecmp(v->name, "refresh")) { cal->refresh = atoi(v->value); + } else if (!strcasecmp(v->name, "fetch_again_at_reload")) { + cal->fetch_again_at_reload = ast_true(v->value); } else if (!strcasecmp(v->name, "timeframe")) { cal->timeframe = atoi(v->value); } else if (!strcasecmp(v->name, "setvar")) {