[asterisk-commits] kmoore: branch 1.8 r357940 - in /branches/1.8: include/asterisk/ main/ tests/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Mar 2 15:02:27 CST 2012
Author: kmoore
Date: Fri Mar 2 15:02:21 2012
New Revision: 357940
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=357940
Log:
Fix case-sensitivity for device-specific event subscriptions and CCSS
This change fixes case-sensitivity for device-specific subscriptions such that
the technology identifier is case-insensitive while the remainder of the device
string is still case-sensitive. This should also preserve the original case of
the device string as passed in to the event system. CCSS is the only feature
affected as it is the only consumer of device-specific event subscriptions.
The second part of this patch addresses similar case-sensitivity issues within
CCSS itself that prevented it from functioning correctly after the fix to the
events system.
This adds a unit test to verify that the event system works as expected.
(closes issue ASTERISK-19422)
Review: https://reviewboard.asterisk.org/r/1780/
Modified:
branches/1.8/include/asterisk/strings.h
branches/1.8/main/ccss.c
branches/1.8/main/event.c
branches/1.8/tests/test_event.c
Modified: branches/1.8/include/asterisk/strings.h
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/include/asterisk/strings.h?view=diff&rev=357940&r1=357939&r2=357940
==============================================================================
--- branches/1.8/include/asterisk/strings.h (original)
+++ branches/1.8/include/asterisk/strings.h Fri Mar 2 15:02:21 2012
@@ -897,6 +897,26 @@
)
/*!
+ * \brief Convert the tech portion of a device string to upper case
+ *
+ * \retval dev_str Returns the char* passed in for convenience
+ */
+AST_INLINE_API(
+char *ast_tech_to_upper(char *dev_str),
+{
+ char *pos;
+ if (!dev_str || !strchr(dev_str, '/')) {
+ return dev_str;
+ }
+
+ for (pos = dev_str; *pos && *pos != '/'; pos++) {
+ *pos = toupper(*pos);
+ }
+ return dev_str;
+}
+)
+
+/*!
* \brief Compute a hash value on a string
*
* This famous hash algorithm was written by Dan Bernstein and is
Modified: branches/1.8/main/ccss.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/main/ccss.c?view=diff&rev=357940&r1=357939&r2=357940
==============================================================================
--- branches/1.8/main/ccss.c (original)
+++ branches/1.8/main/ccss.c Fri Mar 2 15:02:21 2012
@@ -1103,7 +1103,10 @@
static struct generic_monitor_instance_list *find_generic_monitor_instance_list(const char * const device_name)
{
- struct generic_monitor_instance_list finder = {.device_name = device_name};
+ struct generic_monitor_instance_list finder = {0};
+ char *uppertech = ast_strdupa(device_name);
+ ast_tech_to_upper(uppertech);
+ finder.device_name = uppertech;
return ao2_t_find(generic_monitors, &finder, OBJ_POINTER, "Finding generic monitor instance list");
}
@@ -1125,15 +1128,18 @@
{
struct generic_monitor_instance_list *generic_list = ao2_t_alloc(sizeof(*generic_list),
generic_monitor_instance_list_destructor, "allocate generic monitor instance list");
+ char * device_name;
if (!generic_list) {
return NULL;
}
- if (!(generic_list->device_name = ast_strdup(monitor->interface->device_name))) {
+ if (!(device_name = ast_strdup(monitor->interface->device_name))) {
cc_unref(generic_list, "Failed to strdup the monitor's device name");
return NULL;
}
+ ast_tech_to_upper(device_name);
+ generic_list->device_name = device_name;
if (!(generic_list->sub = ast_event_subscribe(AST_EVENT_DEVICE_STATE,
generic_monitor_devstate_cb, "Requesting CC", NULL,
Modified: branches/1.8/main/event.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/main/event.c?view=diff&rev=357940&r1=357939&r2=357940
==============================================================================
--- branches/1.8/main/event.c (original)
+++ branches/1.8/main/event.c Fri Mar 2 15:02:21 2012
@@ -411,8 +411,16 @@
res = (sub_ie_val->payload.uint & event_ie_val->payload.uint);
break;
case AST_EVENT_IE_PLTYPE_STR:
- res = !strcmp(sub_ie_val->payload.str, event_ie_val->payload.str);
+ {
+ const char *substr = sub_ie_val->payload.str;
+ const char *estr = event_ie_val->payload.str;
+ if (sub_ie_val->ie_type == AST_EVENT_IE_DEVICE) {
+ substr = ast_tech_to_upper(ast_strdupa(substr));
+ estr = ast_tech_to_upper(ast_strdupa(estr));
+ }
+ res = !strcmp(substr, estr);
break;
+ }
case AST_EVENT_IE_PLTYPE_RAW:
res = (sub_ie_val->raw_datalen == event_ie_val->raw_datalen
&& !memcmp(sub_ie_val->payload.raw, event_ie_val->payload.raw,
@@ -576,8 +584,19 @@
}
str = event2 ? ast_event_get_ie_str(event2, ie_val->ie_type) : ie_val->payload.str;
- if (str && !strcmp(str, ast_event_get_ie_str(event, ie_val->ie_type))) {
- return 1;
+ if (str) {
+ const char *e1str, *e2str;
+ e1str = ast_event_get_ie_str(event, ie_val->ie_type);
+ e2str = str;
+
+ if (ie_val->ie_type == AST_EVENT_IE_DEVICE) {
+ e1str = ast_tech_to_upper(ast_strdupa(e1str));
+ e2str = ast_tech_to_upper(ast_strdupa(e2str));
+ }
+
+ if (!strcmp(e1str, e2str)) {
+ return 1;
+ }
}
return 0;
@@ -820,7 +839,13 @@
return -1;
}
- ie_val->payload.hash = ast_str_hash(str);
+ if (ie_type == AST_EVENT_IE_DEVICE) {
+ char *uppertech = ast_strdupa(str);
+ ast_tech_to_upper(uppertech);
+ ie_val->payload.hash = ast_str_hash(uppertech);
+ } else {
+ ie_val->payload.hash = ast_str_hash(str);
+ }
AST_LIST_INSERT_TAIL(&sub->ie_vals, ie_val, entry);
@@ -1116,7 +1141,13 @@
str_payload = alloca(payload_len);
strcpy(str_payload->str, str);
- str_payload->hash = ast_str_hash(str);
+ if (ie_type == AST_EVENT_IE_DEVICE) {
+ char *uppertech = ast_strdupa(str);
+ ast_tech_to_upper(uppertech);
+ str_payload->hash = ast_str_hash(uppertech);
+ } else {
+ str_payload->hash = ast_str_hash(str);
+ }
return ast_event_append_ie_raw(event, ie_type, str_payload, payload_len);
}
Modified: branches/1.8/tests/test_event.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/tests/test_event.c?view=diff&rev=357940&r1=357939&r2=357940
==============================================================================
--- branches/1.8/tests/test_event.c (original)
+++ branches/1.8/tests/test_event.c Fri Mar 2 15:02:21 2012
@@ -606,6 +606,25 @@
res = AST_TEST_FAIL;
}
+ /* Make sure that the tech portion of the device string is case-insensitive */
+ sub_res = ast_event_check_subscriber(AST_EVENT_CUSTOM,
+ AST_EVENT_IE_DEVICE, AST_EVENT_IE_PLTYPE_STR, "foo/bar",
+ AST_EVENT_IE_END);
+ if (sub_res != AST_EVENT_SUB_EXISTS) {
+ ast_test_status_update(test, "Str FOO/bar subscription lacks proper case-sensitivity for device strings\n");
+ res = AST_TEST_FAIL;
+ }
+
+ /* Make sure that the non-tech portion of the device string is case-sensitive
+ * and fails to match appropriately */
+ sub_res = ast_event_check_subscriber(AST_EVENT_CUSTOM,
+ AST_EVENT_IE_DEVICE, AST_EVENT_IE_PLTYPE_STR, "FOO/BAR",
+ AST_EVENT_IE_END);
+ if (sub_res == AST_EVENT_SUB_EXISTS) {
+ ast_test_status_update(test, "Str FOO/bar subscription lacks proper case-sensitivity for device strings\n");
+ res = AST_TEST_FAIL;
+ }
+
sub_res = ast_event_check_subscriber(AST_EVENT_CUSTOM,
AST_EVENT_IE_DEVICE, AST_EVENT_IE_PLTYPE_STR, "Money",
AST_EVENT_IE_END);
More information about the asterisk-commits
mailing list