[svn-commits] rizzo: branch rizzo/astobj2 r47262 - /team/rizzo/astobj2/channels/chan_sip.c

svn-commits at lists.digium.com svn-commits at lists.digium.com
Tue Nov 7 08:05:17 MST 2006


Author: rizzo
Date: Tue Nov  7 09:05:17 2006
New Revision: 47262

URL: http://svn.digium.com/view/asterisk?rev=47262&view=rev
Log:
move the pvt_matching code in find_call to its own function, once
again to ease moving to containers.


Modified:
    team/rizzo/astobj2/channels/chan_sip.c

Modified: team/rizzo/astobj2/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/rizzo/astobj2/channels/chan_sip.c?rev=47262&r1=47261&r2=47262&view=diff
==============================================================================
--- team/rizzo/astobj2/channels/chan_sip.c (original)
+++ team/rizzo/astobj2/channels/chan_sip.c Tue Nov  7 09:05:17 2006
@@ -4374,14 +4374,56 @@
 	return p;
 }
 
+/*! \brief argument to the helper function to identify a call */
+struct find_call_cb_arg {
+	enum sipmethod method;
+	const char *callid;
+	const char *fromtag;
+	const char *totag;
+	const char *tag;
+};
+
+/*!
+ * code to determine whether this is the pvt that we are looking for.
+ * Return FALSE if not found, true otherwise. p is unlocked.
+ */
+static int find_call_cb(struct sip_pvt *p, struct find_call_cb_arg *arg)
+{
+	/* In pedantic, we do not want packets with bad syntax to be connected to a PVT */
+	int found = FALSE;
+	if (arg->method == SIP_REGISTER)
+		found = (!strcmp(p->callid, arg->callid));
+	else 
+		found = (!strcmp(p->callid, arg->callid) && 
+		(!pedanticsipchecking || !arg->tag || ast_strlen_zero(p->theirtag) || !strcmp(p->theirtag, arg->tag))) ;
+
+	if (option_debug > 4)
+		ast_log(LOG_DEBUG, "= %s Their Call ID: %s Their Tag %s Our tag: %s\n", found ? "Found" : "No match", p->callid, p->theirtag, p->tag);
+
+	/* If we get a new request within an existing to-tag - check the to tag as well */
+	if (pedanticsipchecking && found  && arg->method != SIP_RESPONSE) {	/* SIP Request */
+		if (p->tag[0] == '\0' && arg->totag[0]) {
+			/* We have no to tag, but they have. Wrong dialog */
+			found = FALSE;
+		} else if (arg->totag[0]) {			/* Both have tags, compare them */
+			if (strcmp(arg->totag, p->tag)) {
+				found = FALSE;		/* This is not our packet */
+			}
+		}
+		if (!found && option_debug > 4)
+			ast_log(LOG_DEBUG, "= Being pedantic: This is not our match on request: Call ID: %s Ourtag <null> Totag %s Method %s\n", p->callid, arg->totag, sip_methods[arg->method].text);
+	}
+	return found;
+}
+
 /*! \brief Connect incoming SIP message to current dialog or create new dialog structure
 	Called by handle_request, sipsock_read */
 static struct sip_pvt *find_call(struct sip_request *req, struct sockaddr_in *sin, const int intended_method)
 {
 	struct sip_pvt *p = NULL;
-	char *tag = "";	/* note, tag is never NULL */
-	char totag[128];
-	char fromtag[128];
+	char totag[128];	/* not initialized, but not used if !pedantic */
+	char fromtag[128];	/* not initialized, but not used if !pedantic */
+	struct find_call_cb_arg arg;
 	const char *callid = get_header(req, "Call-ID");
 	const char *from = get_header(req, "From");
 	const char *to = get_header(req, "To");
@@ -4392,6 +4434,12 @@
 	if (ast_strlen_zero(callid) || ast_strlen_zero(to) ||
 			ast_strlen_zero(from) || ast_strlen_zero(cseq))
 		return NULL;	/* Invalid packet */
+
+	arg.method = req->method;
+	arg.callid = callid;
+	arg.fromtag = fromtag;
+	arg.totag = totag;
+	arg.tag = ""; 	/* make sure tag is never NULL */
 
 	if (pedanticsipchecking) {
 		/* In principle Call-ID's uniquely identify a call, but with a forking SIP proxy
@@ -4404,7 +4452,7 @@
 			ast_set_flag(req, SIP_PKT_WITH_TOTAG);	/* Used in handle_request/response */
 		gettag(req, "From", fromtag, sizeof(fromtag));
 
-		tag = (req->method == SIP_RESPONSE) ? totag : fromtag;
+		arg.tag = (req->method == SIP_RESPONSE) ? totag : fromtag;
 
 		if (option_debug > 4 )
 			ast_log(LOG_DEBUG, "= Looking for  Call ID: %s (Checking %s) --From tag %s --To-tag %s  \n", callid, req->method==SIP_RESPONSE ? "To" : "From", fromtag, totag);
@@ -4412,40 +4460,15 @@
 
 	dialoglist_lock();
 	for (p = dialoglist; p; p = p->next) {
-		/* In pedantic, we do not want packets with bad syntax to be connected to a PVT */
-		int found = FALSE;
-		if (req->method == SIP_REGISTER)
-			found = (!strcmp(p->callid, callid));
-		else 
-			found = (!strcmp(p->callid, callid) && 
-			(!pedanticsipchecking || !tag || ast_strlen_zero(p->theirtag) || !strcmp(p->theirtag, tag))) ;
-
-		if (option_debug > 4)
-			ast_log(LOG_DEBUG, "= %s Their Call ID: %s Their Tag %s Our tag: %s\n", found ? "Found" : "No match", p->callid, p->theirtag, p->tag);
-
-		/* If we get a new request within an existing to-tag - check the to tag as well */
-		if (pedanticsipchecking && found  && req->method != SIP_RESPONSE) {	/* SIP Request */
-			if (p->tag[0] == '\0' && totag[0]) {
-				/* We have no to tag, but they have. Wrong dialog */
-				found = FALSE;
-			} else if (totag[0]) {			/* Both have tags, compare them */
-				if (strcmp(totag, p->tag)) {
-					found = FALSE;		/* This is not our packet */
-				}
-			}
-			if (!found && option_debug > 4)
-				ast_log(LOG_DEBUG, "= Being pedantic: This is not our match on request: Call ID: %s Ourtag <null> Totag %s Method %s\n", p->callid, totag, sip_methods[req->method].text);
-		}
-
-
-		if (found) {
-			/* Found the call */
+		if (find_call_cb(p, &arg)) {
+			/* Found the call, lock p before unlocking the container */
 			sip_pvt_lock(p);
-			dialoglist_unlock();
-			return p;
+			break;
 		}
 	}
 	dialoglist_unlock();
+	if (p)
+		return p;
 	
 	/* See if the method is capable of creating a dialog */
 	if (sip_methods[intended_method].can_create == CAN_CREATE_DIALOG) {



More information about the svn-commits mailing list