[asterisk-commits] mmichelson: branch group/pimp_my_sip r379275 - /team/group/pimp_my_sip/res/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jan 16 15:05:29 CST 2013


Author: mmichelson
Date: Wed Jan 16 15:05:26 2013
New Revision: 379275

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=379275
Log:
Make copies of the supplements when adding them to a session.


Modified:
    team/group/pimp_my_sip/res/res_sip_session.c

Modified: team/group/pimp_my_sip/res/res_sip_session.c
URL: http://svnview.digium.com/svn/asterisk/team/group/pimp_my_sip/res/res_sip_session.c?view=diff&rev=379275&r1=379274&r2=379275
==============================================================================
--- team/group/pimp_my_sip/res/res_sip_session.c (original)
+++ team/group/pimp_my_sip/res/res_sip_session.c Wed Jan 16 15:05:26 2013
@@ -167,6 +167,17 @@
 	AST_RWLIST_TRAVERSE_SAFE_END;
 }
 
+static struct ast_sip_session_supplement *supplement_dup(const struct ast_sip_session_supplement *src)
+{
+	struct ast_sip_session_supplement *dst = ast_calloc(1, sizeof(*dst));
+	if (!dst) {
+		return NULL;
+	}
+	/* Will need to revisit if shallow copy becomes an issue */
+	*dst = *src;
+	return dst;
+}
+
 #define DATASTORE_BUCKETS 53
 
 static void session_datastore_destroy(void *obj)
@@ -357,11 +368,27 @@
 {
 	struct ast_sip_session *session = obj;
 	struct ast_sip_session_supplement *supplement;
-	AST_LIST_TRAVERSE(&session->supplements, supplement, next) {
+	while ((supplement = AST_LIST_REMOVE_HEAD(&session->supplements, next))) {
 		supplement->session_end(session);
+		ast_free(supplement);
 	}
 	ao2_cleanup(session->datastores);
 	AST_LIST_HEAD_DESTROY(&session->supplements);
+}
+
+static int add_supplements(struct ast_sip_session *session)
+{
+	struct ast_sip_session_supplement *iter;
+	SCOPED_LOCK(lock, &session_supplements, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK);
+
+	AST_RWLIST_TRAVERSE(&session_supplements, iter, next) {
+		struct ast_sip_session_supplement *copy = supplement_dup(iter);
+		if (!copy) {
+			return -1;
+		}
+		AST_LIST_INSERT_TAIL(&session->supplements, copy, next);
+	}
+	return 0;
 }
 
 struct ast_sip_session *ast_sip_session_alloc(struct ast_sip_endpoint *endpoint, pjsip_inv_session *inv_session)
@@ -371,19 +398,16 @@
 	if (!session) {
 		return NULL;
 	}
+	AST_LIST_HEAD_INIT(&session->supplements);
 	session->datastores = ao2_container_alloc(DATASTORE_BUCKETS, datastore_hash, datastore_cmp);
 	if (!session->datastores) {
 		return NULL;
 	}
 	session->endpoint = endpoint;
 	session->inv_session = inv_session;
-	AST_LIST_HEAD_INIT(&session->supplements);
-	/* XXX There is probably a better way of doing this */
-	AST_RWLIST_RDLOCK(&session_supplements);
-	AST_RWLIST_TRAVERSE(&session_supplements, iter, next) {
-		AST_LIST_INSERT_TAIL(&session->supplements, iter, next);
-	}
-	AST_RWLIST_UNLOCK(&session_supplements);
+	if (add_supplements(session)) {
+		return NULL;
+	}
 	AST_LIST_TRAVERSE(&session->supplements, iter, next) {
 		iter->session_begin(session);
 	}
@@ -477,7 +501,9 @@
 		return;
 	}
 	AST_LIST_TRAVERSE(&session->supplements, supplement, next) {
-		supplement->incoming_request(session, rdata);
+		if (!supplement->method || !strcmp(supplement->method, "INVITE")) {
+			supplement->incoming_request(session, rdata);
+		}
 	}
 	if (handle_sdp(rdata)) {
 		/* Dangit. After all that, we have to reject the call */




More information about the asterisk-commits mailing list