]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
res_calendar: Add support for fetching calendars when reloading 98/3998/3
authorLudovic Gasc (GMLudo) <gmludo@gmail.com>
Thu, 29 Sep 2016 17:45:39 +0000 (19:45 +0200)
committerJoshua Colp <jcolp@digium.com>
Mon, 10 Oct 2016 15:43:53 +0000 (10:43 -0500)
We use a lot res_calendar, we are very happy with that, especially
because you use libical, the almost alone opensource library that
supports really ical format with all types of recurrency.

Nevertheless, some features are missed for our business use cases.

This first patch adds a new option in calendar.conf:
fetch_again_at_reload. Be my guest for a better name.

If it's true, when you'll launch "module reload res_calendar.so",
Asterisk will download again the calendar.

The business use case is that we have a WebUI with a scheduler planner,
we know when the calendars are modified.

For now, we need to define 1 minute of timeout to have a chance that
our user doesn't wait too long between the modification and the real
test.  But it generates a lot of useless HTTP traffic.

ASTERISK-26422 #close

Change-Id: I384b02ebfa42b142bbbd5b7221458c7f4dee7077

configs/samples/calendar.conf.sample
include/asterisk/calendar.h
res/res_calendar.c

index 82b8702f014d73dce26bb45bfddc360d1924dd5d..d87b3b2c4e6a15eecd19d2ef3676fc9ee32427ed 100644 (file)
@@ -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(<field>)} dialplan function:
index da4af01ef3ded830dc6160655d1dbeab9845a5bb..e9dcd8809491dfdd5a0d3e93cfa97b5fa0a2deb2 100644 (file)
@@ -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;
index 6f6f711b3eb67bba5e714c62ff303ffabde446b1..029ecebd07bc32d3121fd27076ce3ff2efe33ab3 100644 (file)
@@ -436,6 +436,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 = 0;
 
        for (v = ast_variable_browse(cfg, cat); v; v = v->next) {
                if (!strcasecmp(v->name, "autoreminder")) {
@@ -457,6 +458,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")) {
@@ -482,7 +485,7 @@ static struct ast_calendar *build_calendar(struct ast_config *cfg, const char *c
                }
        }
 
-       if (new_calendar) {
+       if (new_calendar || cal->fetch_again_at_reload) {
                cal->thread = AST_PTHREADT_NULL;
                ast_cond_init(&cal->unload, NULL);
                ao2_link(calendars, cal);