[asterisk-commits] file: branch group/pimp_my_sip r389898 - /team/group/pimp_my_sip/res/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue May 28 12:55:31 CDT 2013


Author: file
Date: Tue May 28 12:55:27 2013
New Revision: 389898

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=389898
Log:
Minor tweak to allow multiple methods to be specified when registering a supplement.

This is becoming a common occurence so moving filtering to a single place is nifty.

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=389898&r1=389897&r2=389898
==============================================================================
--- team/group/pimp_my_sip/res/res_sip_session.c (original)
+++ team/group/pimp_my_sip/res/res_sip_session.c Tue May 28 12:55:27 2013
@@ -1325,7 +1325,20 @@
 	handle_incoming_request(session, rdata);
 }
 
-static int has_supplement(struct ast_sip_session *session, pjsip_rx_data *rdata)
+static pj_bool_t does_method_match(const pj_str_t *message_method, const char *supplement_method)
+{
+	pj_str_t method;
+
+	if (ast_strlen_zero(supplement_method)) {
+		return PJ_TRUE;
+	}
+
+	pj_cstr(&method, supplement_method);
+
+	return pj_stristr(&method, message_method) ? PJ_TRUE : PJ_FALSE;
+}
+
+static pj_bool_t has_supplement(const struct ast_sip_session *session, const pjsip_rx_data *rdata)
 {
 	struct ast_sip_session_supplement *supplement;
 	struct pjsip_method *method = &rdata->msg_info.msg->line.req.method;
@@ -1335,7 +1348,7 @@
 	}
 
 	AST_LIST_TRAVERSE(&session->supplements, supplement, next) {
-		if (!supplement->method || !pj_strcmp2(&method->name, supplement->method)) {
+		if (does_method_match(&method->name, supplement->method)) {
 			return PJ_TRUE;
 		}
 	}
@@ -1485,8 +1498,7 @@
 
 	ast_debug(3, "Method is %.*s\n", (int) pj_strlen(&req.method.name), pj_strbuf(&req.method.name));
 	AST_LIST_TRAVERSE(&session->supplements, supplement, next) {
-		if (supplement->incoming_request && (
-				!supplement->method || !pj_strcmp2(&req.method.name, supplement->method))) {
+		if (supplement->incoming_request && does_method_match(&req.method.name, supplement->method)) {
 			if (supplement->incoming_request(session, rdata)) {
 				break;
 			}
@@ -1503,8 +1515,7 @@
 			pj_strbuf(&status.reason));
 
 	AST_LIST_TRAVERSE(&session->supplements, supplement, next) {
-		if (supplement->incoming_response && (
-				!supplement->method || !pj_strcmp2(&rdata->msg_info.cseq->method.name, supplement->method))) {
+		if (supplement->incoming_response && does_method_match(&rdata->msg_info.cseq->method.name, supplement->method)) {
 			supplement->incoming_response(session, rdata);
 		}
 	}
@@ -1531,8 +1542,7 @@
 
 	ast_debug(3, "Method is %.*s\n", (int) pj_strlen(&req.method.name), pj_strbuf(&req.method.name));
 	AST_LIST_TRAVERSE(&session->supplements, supplement, next) {
-		if (supplement->outgoing_request &&
-				(!supplement->method || !pj_strcmp2(&req.method.name, supplement->method))) {
+		if (supplement->outgoing_request && does_method_match(&req.method.name, supplement->method)) {
 			supplement->outgoing_request(session, tdata);
 		}
 	}




More information about the asterisk-commits mailing list