summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Jordan <mjordan@digium.com>2015-06-27 17:51:43 -0500
committerMatt Jordan <mjordan@digium.com>2015-07-11 10:33:38 -0500
commitf77e688f20f84aba2a5c3a0b2aa6565792912bf5 (patch)
tree7c83388cd2e0fb29a26d860edeecfc69099c1e05
parent1b7760a8aac5f43ed72849598ada769207c51c13 (diff)
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
-rw-r--r--main/devicestate.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/main/devicestate.c b/main/devicestate.c
index e2cc2f2f3..aba6159b4 100644
--- a/main/devicestate.c
+++ b/main/devicestate.c
@@ -397,6 +397,7 @@ enum ast_device_state ast_device_state(const char *device)
/*! \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))))
@@ -406,6 +407,14 @@ int ast_devstate_prov_add(const char *label, ast_devstate_prov_cb_type callback)
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);