[Asterisk-code-review] res_calendar: Enable setting a default busy state on calendars for ev... (asterisk[master])

Jaco Kroon asteriskteam at digium.com
Thu Mar 23 04:14:11 CDT 2023


Jaco Kroon has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/20025 )


Change subject: res_calendar: Enable setting a default busy state on calendars for events without an explicit busy state.
......................................................................

res_calendar: Enable setting a default busy state on calendars for
events without an explicit busy state.

Change-Id: I60b9b8d5637ef1f509996d21acfe148aff1c0009
Signed-off-by: Jaco Kroon <jaco at uls.co.za>
---
M configs/samples/calendar.conf.sample
M include/asterisk/calendar.h
M res/res_calendar.c
3 files changed, 33 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/25/20025/1

diff --git a/configs/samples/calendar.conf.sample b/configs/samples/calendar.conf.sample
index 08cbd3a..2b313c7 100644
--- a/configs/samples/calendar.conf.sample
+++ b/configs/samples/calendar.conf.sample
@@ -7,6 +7,7 @@
 ;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
+;default_busy_state = free|busy|tentative ; default free, any other value will be treated as a boolean resulting in true => busy and everything else defaults to free.
 ;
 ;
 ; You can set up res_calendar to execute a call upon an upcoming busy status
diff --git a/include/asterisk/calendar.h b/include/asterisk/calendar.h
index d22ae15..3e2be0b 100644
--- a/include/asterisk/calendar.h
+++ b/include/asterisk/calendar.h
@@ -137,6 +137,7 @@
 	ast_cond_t unload;
 	unsigned int unloading:1;
 	unsigned int pending_deletion:1;
+	enum ast_calendar_busy_state default_busy_state;  /*!< The default busy state of events without an explicit value */
 	struct ao2_container *events;  /*!< The events that are known at this time */
 };
 
@@ -205,4 +206,9 @@
 /*! \brief Convert a free-busy state integer value to a string.
  */
 const char* ast_calendar_busy_state_to_str(enum ast_calendar_busy_state busy_state);
+
+/*! \brief Convert a string to a free-busy state.
+ */
+enum ast_calendar_busy_state ast_calendar_busy_state_from_str(const char* busy_state);
+
 #endif /* _ASTERISK_CALENDAR_H */
diff --git a/res/res_calendar.c b/res/res_calendar.c
index 428f10a..3e61e3f 100644
--- a/res/res_calendar.c
+++ b/res/res_calendar.c
@@ -371,6 +371,17 @@
 	}
 }
 
+enum ast_calendar_busy_state ast_calendar_busy_state_from_str(const char* busy_state)
+{
+	if (strcasecmp(busy_state, "free"))
+		return AST_CALENDAR_BS_FREE;
+	if (strcasecmp(busy_state, "busy"))
+		return AST_CALENDAR_BS_BUSY;
+	if (strcasecmp(busy_state, "tentative"))
+		return AST_CALENDAR_BS_BUSY_TENTATIVE;
+	return ast_true(busy_state) ? AST_CALENDAR_BS_BUSY : AST_CALENDAR_BS_FREE;
+}
+
 static int calendar_busy_callback(void *obj, void *arg, int flags)
 {
 	struct ast_calendar_event *event = obj;
@@ -455,6 +466,7 @@
 	cal->timeframe = 60;
 	cal->notify_waittime = 30000;
 	cal->fetch_again_at_reload = 0;
+	cal->default_busy_state = AST_CALENDAR_BS_FREE;
 
 	for (v = ast_variable_browse(cfg, cat); v; v = v->next) {
 		if (!strcasecmp(v->name, "autoreminder")) {
@@ -500,6 +512,8 @@
 				}
 				ast_free(name);
 			}
+		} else if (!strcasecmp(v->name, "default_busy_state")) {
+			cal->default_busy_state = ast_calendar_busy_state_from_str(v->value);
 		}
 	}
 
@@ -696,6 +710,7 @@
 	event->notify_sched = -1;
 	event->bs_start_sched = -1;
 	event->bs_end_sched = -1;
+	event->busy_state = cal->default_busy_state;
 
 	AST_LIST_HEAD_INIT_NOLOCK(&event->attendees);
 

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/20025
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: I60b9b8d5637ef1f509996d21acfe148aff1c0009
Gerrit-Change-Number: 20025
Gerrit-PatchSet: 1
Gerrit-Owner: Jaco Kroon <jaco at uls.co.za>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20230323/ec0d6580/attachment-0001.html>


More information about the asterisk-code-review mailing list