pjsip_distributor.c: Fix unidentified_requests hash functions.
authorRichard Mudgett <rmudgett@digium.com>
Thu, 29 Jun 2017 23:22:33 +0000 (18:22 -0500)
committerRichard Mudgett <rmudgett@digium.com>
Fri, 30 Jun 2017 17:01:21 +0000 (12:01 -0500)
The OBJ_SEARCH_xxx defines should not be used as if they were individual
bits.  They represent a multi-bit enumeration value field.

Change-Id: I32abc9a475396dab02402a7014357dd94284e17b

res/res_pjsip/pjsip_distributor.c

index cca26a8..2c9bcbf 100644 (file)
@@ -837,7 +837,7 @@ static int suspects_compare(void *obj, void *arg, int flags)
                /* Fall through */
        case OBJ_SEARCH_KEY:
                if (strcmp(object_left->src_name, right_key) == 0) {
-                       cmp = CMP_MATCH | CMP_STOP;
+                       cmp = CMP_MATCH;
                }
                break;
        case OBJ_SEARCH_PARTIAL_KEY:
@@ -852,15 +852,25 @@ static int suspects_compare(void *obj, void *arg, int flags)
        return cmp;
 }
 
-static int suspects_hash(const void *obj, int flags) {
-       const struct unidentified_request *object_left = obj;
+static int suspects_hash(const void *obj, int flags)
+{
+       const struct unidentified_request *object;
+       const char *key;
 
-       if (flags & OBJ_SEARCH_OBJECT) {
-               return ast_str_hash(object_left->src_name);
-       } else if (flags & OBJ_SEARCH_KEY) {
-               return ast_str_hash(obj);
+       switch (flags & OBJ_SEARCH_MASK) {
+       case OBJ_SEARCH_KEY:
+               key = obj;
+               break;
+       case OBJ_SEARCH_OBJECT:
+               object = obj;
+               key = object->src_name;
+               break;
+       default:
+               /* Hash can only work on something with a full key. */
+               ast_assert(0);
+               return 0;
        }
-       return -1;
+       return ast_str_hash(key);
 }
 
 static struct ao2_container *cli_unid_get_container(const char *regex)