[Asterisk-code-review] app_queue: Fix hint updates for included contexts (asterisk[18])

N A asteriskteam at digium.com
Tue Sep 21 11:55:19 CDT 2021


N A has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/16528 )


Change subject: app_queue: Fix hint updates for included contexts
......................................................................

app_queue: Fix hint updates for included contexts

Previously, if custom hints were used with the hint:
format in app_queue, when device state changes occured,
app_queue would only do a literal string comparison of
the context used for the hint in app_queue and the context
of the hint which just changed state. This caused hints
to not update and become stale if the context associated
with the agent included the context which actually changes
state, essentially completely breaking device state for
any such agents defined in this manner.

This fix adds an additional check to ensure that included
contexts are also compared against the context which changed
state, so that the behavior is correct no matter whether the
context is specified to app_queue directly or indirectly.

ASTERISK-29578 #close

Change-Id: I8caf2f8da8157ef3d9ea71a8568c1eec95592b78
---
M apps/app_queue.c
1 file changed, 47 insertions(+), 2 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/28/16528/1

diff --git a/apps/app_queue.c b/apps/app_queue.c
index 93adb3f..3c4cdbc 100644
--- a/apps/app_queue.c
+++ b/apps/app_queue.c
@@ -2630,6 +2630,46 @@
 	return state;
 }
 
+/*!
+ * \brief Returns if one context includes another context
+ *
+ * \param parent Parent context to search for child
+ * \param child Context to check for inclusion in parent
+ *
+ * This function recrusively checks if the context child is included in the context parent.
+ *
+ * \return 1 if child is included in parent, 0 if not
+ */
+static int context_included(const char *parent, const char *child);
+static int context_included(const char *parent, const char *child)
+{
+	struct ast_context *c = NULL;
+
+	c = ast_context_find(parent);
+	if (!c) {
+		/* well, if parent doesn't exist, how can the child be included in it? */
+		return 0;
+	}
+	if (!strcmp(ast_get_context_name(c), parent)) {
+		/* found the context of the hint app_queue is using. Now, see
+			if that context includes the one that just changed state */
+		struct ast_include *inc = NULL;
+
+		while ((inc = (struct ast_include*) ast_walk_context_includes(c, inc))) {
+			const char *includename = ast_get_include_name(inc);
+			if (!strcasecmp(child, includename)) {
+				return 1;
+			}
+			/* recurse on this context, for nested includes. The
+				PBX extension parser will prevent infinite recursion. */
+			if (context_included(includename, child)) {
+				return 1;
+			}
+		}
+	}
+	return 0;
+}
+
 static int extension_state_cb(const char *context, const char *exten, struct ast_state_cb_info *info, void *data)
 {
 	struct ao2_iterator miter, qiter;
@@ -2650,9 +2690,14 @@
 		miter = ao2_iterator_init(q->members, 0);
 		for (; (m = ao2_iterator_next(&miter)); ao2_ref(m, -1)) {
 			if (!strcmp(m->state_context, context) && !strcmp(m->state_exten, exten)) {
+				found = 1;
+			} else if (!strcmp(m->state_exten, exten) && context_included(m->state_context, context)) {
+				/* context could be included in m->state_context. We need to check. */
+				found = 1;
+			}
+			if (found) {
 				update_status(q, m, device_state);
 				ao2_ref(m, -1);
-				found = 1;
 				break;
 			}
 		}
@@ -2663,7 +2708,7 @@
 	}
 	ao2_iterator_destroy(&qiter);
 
-        if (found) {
+	if (found) {
 		ast_debug(1, "Extension '%s@%s' changed to state '%d' (%s)\n", exten, context, device_state, ast_devstate2str(device_state));
 	} else {
 		ast_debug(3, "Extension '%s@%s' changed to state '%d' (%s) but we don't care because they're not a member of any queue.\n",

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

Gerrit-Project: asterisk
Gerrit-Branch: 18
Gerrit-Change-Id: I8caf2f8da8157ef3d9ea71a8568c1eec95592b78
Gerrit-Change-Number: 16528
Gerrit-PatchSet: 1
Gerrit-Owner: N A <mail at interlinked.x10host.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20210921/735169dc/attachment.html>


More information about the asterisk-code-review mailing list