[asterisk-commits] main/devicestate: Prevent duplicate registration of device s... (asterisk[11])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Jul 11 11:04:13 CDT 2015


Matt Jordan has submitted this change and it was merged.

Change subject: main/devicestate: Prevent duplicate registration of device state providers
......................................................................


main/devicestate: Prevent duplicate registration of device state providers

Currently, the device state provider API will allow you to register a
device state provider with the same case insensitive name more than
once. This could cause strange issues, as the duplicate device state
providers will not be queried when a device's state has to be polled.
This patch updates the API such that a device state provider with the
same name as one that has already registered will be rejected.

Change-Id: I4a418a12280b7b6e4960bd44f302e27cd036ceb2
---
M main/devicestate.c
1 file changed, 9 insertions(+), 0 deletions(-)

Approvals:
  Anonymous Coward #1000019: Verified
  Matt Jordan: Looks good to me, approved
  Joshua Colp: Looks good to me, but someone else must approve



diff --git a/main/devicestate.c b/main/devicestate.c
index 0833e27..48d2d5c 100644
--- a/main/devicestate.c
+++ b/main/devicestate.c
@@ -370,6 +370,7 @@
 /*! \brief Add device state provider */
 int ast_devstate_prov_add(const char *label, ast_devstate_prov_cb_type callback)
 {
+	struct devstate_prov *devcb;
 	struct devstate_prov *devprov;
 
 	if (!callback || !(devprov = ast_calloc(1, sizeof(*devprov))))
@@ -379,6 +380,14 @@
 	ast_copy_string(devprov->label, label, sizeof(devprov->label));
 
 	AST_RWLIST_WRLOCK(&devstate_provs);
+	AST_RWLIST_TRAVERSE(&devstate_provs, devcb, list) {
+		if (!strcasecmp(devcb->label, label)) {
+			ast_log(LOG_WARNING, "Device state provider '%s' already registered\n", label);
+			ast_free(devprov);
+			AST_RWLIST_UNLOCK(&devstate_provs);
+			return -1;
+		}
+	}
 	AST_RWLIST_INSERT_HEAD(&devstate_provs, devprov, list);
 	AST_RWLIST_UNLOCK(&devstate_provs);
 

-- 
To view, visit https://gerrit.asterisk.org/782
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I4a418a12280b7b6e4960bd44f302e27cd036ceb2
Gerrit-PatchSet: 2
Gerrit-Project: asterisk
Gerrit-Branch: 11
Gerrit-Owner: Matt Jordan <mjordan at digium.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Matt Jordan <mjordan at digium.com>



More information about the asterisk-commits mailing list