[svn-commits] mmichelson: branch group/CCSS r231093 - /team/group/CCSS/channels/chan_sip.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Nov 24 12:17:16 CST 2009


Author: mmichelson
Date: Tue Nov 24 12:17:14 2009
New Revision: 231093

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=231093
Log:
Fix some incorrect hashing in SIP ESCs.

ESC entries are hashed based on the entity tag that
is created for them. There were two problems fixed here.

1. The ESC entries were being linked into the ESC before
having an entity tag assigned. The result would be that
we would never be able to find an ESC entry since we would
look in the incorrect bucket.

2. Since we create a new entity tag for every 200 OK we
send, the result is that an ESC entry's entity tag would
change from what it was when originally linked. To fix this,
we have to unlink, change the entity tag, and then re-link.


Modified:
    team/group/CCSS/channels/chan_sip.c

Modified: team/group/CCSS/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/group/CCSS/channels/chan_sip.c?view=diff&rev=231093&r1=231092&r2=231093
==============================================================================
--- team/group/CCSS/channels/chan_sip.c (original)
+++ team/group/CCSS/channels/chan_sip.c Tue Nov 24 12:17:14 2009
@@ -2039,6 +2039,19 @@
 	return 0;
 }
 
+static void create_new_sip_etag(struct sip_esc_entry *esc_entry, int is_linked)
+{
+	int new_etag = ast_atomic_fetchadd_int(&esc_etag_counter, +1);
+	struct event_state_compositor *esc = get_esc(esc_entry->event);
+
+	ast_assert(esc != NULL);
+	if (is_linked) {
+		ao2_unlink(esc->compositor, esc_entry);
+	}
+	snprintf(esc_entry->entity_tag, sizeof(esc_entry->entity_tag), "%d", new_etag);
+	ao2_link(esc->compositor, esc_entry);
+}
+
 static struct sip_esc_entry *create_esc_entry(struct event_state_compositor *esc, struct sip_request *req, const int expires)
 {
 	struct sip_esc_entry *esc_entry;
@@ -2064,7 +2077,9 @@
 	ao2_ref(esc_entry, +1);
 	esc_entry->sched_id = ast_sched_add(sched, expires_ms, publish_expire, esc_entry);
 
-	ao2_link(esc->compositor, esc_entry);
+	/* Note: This links the esc_entry into the ESC properly */
+	create_new_sip_etag(esc_entry, 0);
+
 	return esc_entry;
 }
 
@@ -2086,11 +2101,6 @@
 	for (i = 0; i < ARRAY_LEN(event_state_compositors); i++) {
 		ao2_ref(event_state_compositors[i].compositor, -1);
 	}
-}
-
-static int create_new_sip_etag(void)
-{
-	return ast_atomic_fetchadd_int(&esc_etag_counter, +1);
 }
 
 /*! \brief Struct to handle custom SIP notify requests. Dynamically allocated when needed */
@@ -10370,13 +10380,13 @@
 	return send_response(p, &resp, reliable, seqno);
 }
 
-static int transmit_response_with_sip_etag(struct sip_pvt *p, const char *msg, const struct sip_request *req, struct sip_esc_entry *esc_entry)
+static int transmit_response_with_sip_etag(struct sip_pvt *p, const char *msg, const struct sip_request *req, struct sip_esc_entry *esc_entry, int need_new_etag)
 {
 	struct sip_request resp;
-	int new_etag;
-
-	new_etag = create_new_sip_etag();
-	snprintf(esc_entry->entity_tag, sizeof(esc_entry->entity_tag), "%d", new_etag);
+
+	if (need_new_etag) {
+		create_new_sip_etag(esc_entry, 1);
+	}
 	respprep(&resp, p, msg, req);
 	add_header(&resp, "SIP-ETag", esc_entry->entity_tag);
 
@@ -22814,7 +22824,7 @@
 	}
 
 	if (!res) {
-		transmit_response_with_sip_etag(p, "200 OK", req, esc_entry);
+		transmit_response_with_sip_etag(p, "200 OK", req, esc_entry, 0);
 	}
 
 	ao2_ref(esc_entry, -1);
@@ -22842,7 +22852,7 @@
 	}
 
 	if (!res) {
-		transmit_response_with_sip_etag(p, "200 OK", req, esc_entry);
+		transmit_response_with_sip_etag(p, "200 OK", req, esc_entry, 1);
 	}
 
 	ao2_ref(esc_entry, -1);
@@ -22870,7 +22880,7 @@
 	}
 
 	if (!res) {
-		transmit_response_with_sip_etag(p, "200 OK", req, esc_entry);
+		transmit_response_with_sip_etag(p, "200 OK", req, esc_entry, 1);
 	}
 
 	return res;
@@ -22894,7 +22904,7 @@
 	}
 
 	if (!res) {
-		transmit_response_with_sip_etag(p, "200 OK", req, esc_entry);
+		transmit_response_with_sip_etag(p, "200 OK", req, esc_entry, 1);
 	} 
 
 	ao2_ref(esc_entry, -1);




More information about the svn-commits mailing list