[asterisk-commits] branch oej/02-labarea r20845 - /team/oej/02-labarea/channels/chan_sip.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Mon Apr 17 01:18:14 MST 2006


Author: oej
Date: Mon Apr 17 03:18:11 2006
New Revision: 20845

URL: http://svn.digium.com/view/asterisk?rev=20845&view=rev
Log:
Fixing stuff...

Modified:
    team/oej/02-labarea/channels/chan_sip.c

Modified: team/oej/02-labarea/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/oej/02-labarea/channels/chan_sip.c?rev=20845&r1=20844&r2=20845&view=diff
==============================================================================
--- team/oej/02-labarea/channels/chan_sip.c (original)
+++ team/oej/02-labarea/channels/chan_sip.c Mon Apr 17 03:18:11 2006
@@ -720,6 +720,7 @@
 	int method;				/*!< SIP method that opened this dialog */
 	AST_DECLARE_STRING_FIELDS(
 		AST_STRING_FIELD(callid);	/*!< Global CallID */
+		AST_STRING_FIELD(viabranchtag);	/*!< Via branch in this session */
 		AST_STRING_FIELD(randdata);	/*!< Random data */
 		AST_STRING_FIELD(accountcode);	/*!< Account code */
 		AST_STRING_FIELD(realm);	/*!< Authorization realm */
@@ -1072,6 +1073,7 @@
 static struct sip_peer *temp_peer(const char *name);
 static int sip_send_mwi_to_peer(struct sip_peer *peer);
 static int sip_scheddestroy(struct sip_pvt *p, int ms);
+void find_via_branch(struct sip_pvt *p, struct sip_request *req);
 
 /*------Request handling functions */
 static int handle_request_invite(struct sip_pvt *p, struct sip_request *req, int debug, int seqno, struct sockaddr_in *sin, int *recount, char *e);
@@ -1132,6 +1134,23 @@
 			return (char *) referstatusstrings[x].text;
 	}
 	return "";
+}
+
+/*! \brief Find via branch parameter */
+void find_via_branch(struct sip_pvt *p, struct sip_request *req)
+{
+	char *dupvia = ast_strdupa(req->via);
+	char *viabranch;
+	char *sep;
+
+	if (!(viabranch = strcasestr(dupvia, ";branch=")))
+		return;
+	viabranch += 8;
+	if ((sep = strchr(viabranch, ';')))
+		*sep = '\0';
+	if (ast_test_flag(req, SIP_PKT_DEBUG) && option_debug > 3)
+		ast_log(LOG_DEBUG, "* Find via branch %s\n", viabranch);
+	ast_string_field_set(p, viabranchtag, viabranch);
 }
 
 /*! \brief Initialize the initital request packet in the pvt structure.
@@ -3464,8 +3483,10 @@
 	}
 	ast_mutex_unlock(&iflock);			/* Unlock the interface list */
 
-	if ((p = sip_alloc(req->callid, sin, 1, intended_method)))	/* Allocate new call */
+	if ((p = sip_alloc(req->callid, sin, 1, intended_method))) {	/* Allocate new call */
 		ast_mutex_lock(&p->lock);		/* Lock this new PVT while we are in action */
+		find_via_branch(p, req);
+	}
 	return p;
 }
 
@@ -4257,8 +4278,11 @@
 	copy_via_headers(p, resp, req, "Via");
 	if (msg[0] == '2')
 		copy_all_header(resp, req, "Record-Route");
-	copy_header(resp, req, "From");
-	ot = get_header(req, "To");
+	if (!ast_strlen_zero(req->from))
+		add_header(resp, "From", req->from);
+	else
+		copy_header(resp, req, "From");
+	ot = req->to ? req->to : get_header(req, "To");
 	if (!strcasestr(ot, "tag=") && strncmp(msg, "100", 3)) {
 		/* Add the proper tag if we don't have it already.  If they have specified
 		   their tag, use it.  Otherwise, use our own tag */
@@ -4271,8 +4295,14 @@
 		ot = newto;
 	}
 	add_header(resp, "To", ot);
-	add_header(resp, "Call-ID", req->callid);
-	add_header(resp, "Cseq", req->cseq);
+	if (!ast_strlen_zero(req->callid))
+		add_header(resp, "Call-ID", req->callid);
+	else
+		copy_header(resp, req, "Call-ID");
+	if (!ast_strlen_zero(req->cseq))
+		add_header(resp, "Cseq", req->cseq);
+	else
+		copy_header(resp, req, "Cseq");
 	add_header(resp, "User-Agent", global_useragent);
 	add_header(resp, "Allow", ALLOWED_METHODS);
 	if (msg[0] == '2' && (p->method == SIP_SUBSCRIBE || p->method == SIP_REGISTER)) {
@@ -4400,9 +4430,10 @@
 {
 	struct sip_request resp;
 	int seqno = 0;
-
-	if (reliable && (sscanf(get_header(req, "CSeq"), "%d ", &seqno) != 1)) {
-		ast_log(LOG_WARNING, "Unable to determine sequence number from '%s'\n", get_header(req, "CSeq"));
+	const char *cseq = req->cseq ? req->cseq : get_header(req, "CSeq");
+
+	if (reliable && (sscanf(cseq, "%d ", &seqno) != 1)) {
+		ast_log(LOG_WARNING, "Unable to determine sequence number from '%s'\n", cseq);
 		return -1;
 	}
 	respprep(&resp, p, msg, req);
@@ -11582,7 +11613,7 @@
 		ast_log(LOG_DEBUG, "**** Received %s (%d) - Command in SIP %s\n", sip_methods[p->method].text, sip_methods[p->method].id, cmd); 
 
 	/* Check for loop in INVITE */
-	if (p->icseq && (p->icseq > seqno) && req->method == SIP_INVITE) {
+	if (p->icseq && (p->icseq == seqno) && req->method == SIP_INVITE) {
 		//SKREP
 		ast_log(LOG_DEBUG, "**** Our initial VIA %s - This req VIA %s\n", p->initreq.via, req->via);
 	}



More information about the asterisk-commits mailing list