Переглянути джерело

rtpengine: use core str comparison functions and macros

Victor Seva 11 місяців тому
батько
коміт
ef9fa6fb34

+ 3 - 8
src/modules/rtpengine/rtpengine.c

@@ -859,11 +859,6 @@ static int bind_force_send_ip(int sock_idx)
 	return 0;
 }
 
-static inline int str_cmp(const str *a, const str *b)
-{
-	return !(a->len == b->len && !strncmp(a->s, b->s, a->len));
-}
-
 static inline int str_eq(const str *p, const char *q)
 {
 	int l = strlen(q);
@@ -963,7 +958,7 @@ struct rtpp_node *get_rtpp_node(struct rtpp_set *rtpp_list, str *url)
 	lock_get(rtpp_list->rset_lock);
 	rtpp_node = rtpp_list->rn_first;
 	while(rtpp_node) {
-		if(str_cmp(&rtpp_node->rn_url, url) == 0) {
+		if(str_strcmp(&rtpp_node->rn_url, url) == 0) {
 			lock_release(rtpp_list->rset_lock);
 			return rtpp_node;
 		}
@@ -4247,7 +4242,7 @@ static void parse_call_stats_1(struct minmax_mos_label_stats *mmls,
 		if(!bencode_dictionary_get_str(tag_dict, "label", &check))
 			continue;
 		LM_DBG("rtpengine: XXX got label %.*s\n", check.len, check.s);
-		if(str_cmp(&check, &label))
+		if(str_strcmp(&check, &label))
 			continue;
 		LM_DBG("rtpengine: XXX label match\n");
 		medias =
@@ -5800,4 +5795,4 @@ static int bind_rtpengine(rtpengine_api_t *api)
 	api->rtpengine_delete = ki_rtpengine_delete;
 
 	return 0;
-}
+}

+ 8 - 26
src/modules/rtpengine/rtpengine_hash.c

@@ -11,24 +11,6 @@ static void rtpengine_hash_table_free_row_lock(gen_lock_t *row_lock);
 
 static struct rtpengine_hash_table *rtpengine_hash_table;
 
-/* from sipwise rtpengine */
-static int str_cmp_str(const str a, const str b)
-{
-	if(a.len < b.len)
-		return -1;
-	if(a.len > b.len)
-		return 1;
-	if(a.len == 0 && b.len == 0)
-		return 0;
-	return memcmp(a.s, b.s, a.len);
-}
-
-/* from sipwise rtpengine */
-static int str_equal(str a, str b)
-{
-	return (str_cmp_str(a, b) == 0);
-}
-
 /* from sipwise rtpengine */
 static unsigned int str_hash(str s)
 {
@@ -254,8 +236,8 @@ int rtpengine_hash_table_insert(
 
 	while(entry) {
 		// if found, don't add new entry
-		if(str_equal(entry->callid, new_entry->callid)
-				&& str_equal(entry->viabranch, new_entry->viabranch)) {
+		if(STR_EQ(entry->callid, new_entry->callid)
+				&& STR_EQ(entry->viabranch, new_entry->viabranch)) {
 			// unlock
 			lock_release(rtpengine_hash_table->row_locks[hash_index]);
 			LM_NOTICE("callid=%.*s, viabranch=%.*s already in hashtable, "
@@ -324,9 +306,9 @@ int rtpengine_hash_table_remove(
 
 	while(entry) {
 		// if callid found, delete entry
-		if((str_equal(entry->callid, callid)
-				   && str_equal(entry->viabranch, viabranch))
-				|| (str_equal(entry->callid, callid) && viabranch.len == 0
+		if((STR_EQ(entry->callid, callid)
+				   && STR_EQ(entry->viabranch, viabranch))
+				|| (STR_EQ(entry->callid, callid) && viabranch.len == 0
 						&& op == OP_DELETE)) {
 			// set pointers; exclude entry
 			last_entry->next = entry->next;
@@ -407,9 +389,9 @@ struct rtpp_node *rtpengine_hash_table_lookup(
 
 	while(entry) {
 		// if callid found, return entry
-		if((str_equal(entry->callid, callid)
-				   && str_equal(entry->viabranch, viabranch))
-				|| (str_equal(entry->callid, callid) && viabranch.len == 0
+		if((STR_EQ(entry->callid, callid)
+				   && STR_EQ(entry->viabranch, viabranch))
+				|| (STR_EQ(entry->callid, callid) && viabranch.len == 0
 						&& op == OP_DELETE)) {
 			node = entry->node;