[asterisk-commits] oej: branch oej/codename-pineapple r47214 - in /team/oej/codename-pineapple/c...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Mon Nov 6 00:18:31 MST 2006


Author: oej
Date: Mon Nov  6 01:18:30 2006
New Revision: 47214

URL: http://svn.digium.com/view/asterisk?rev=47214&view=rev
Log:
Update from Berlin

Modified:
    team/oej/codename-pineapple/channels/chan_sip3.c
    team/oej/codename-pineapple/channels/sip3/sip3.h
    team/oej/codename-pineapple/channels/sip3/sip3_compose.c
    team/oej/codename-pineapple/channels/sip3/sip3_dialog.c
    team/oej/codename-pineapple/channels/sip3/sip3_parse.c
    team/oej/codename-pineapple/channels/sip3/sip3_services.c
    team/oej/codename-pineapple/channels/sip3/sip3funcs.h

Modified: team/oej/codename-pineapple/channels/chan_sip3.c
URL: http://svn.digium.com/view/asterisk/team/oej/codename-pineapple/channels/chan_sip3.c?rev=47214&r1=47213&r2=47214&view=diff
==============================================================================
--- team/oej/codename-pineapple/channels/chan_sip3.c (original)
+++ team/oej/codename-pineapple/channels/chan_sip3.c Mon Nov  6 01:18:30 2006
@@ -298,7 +298,10 @@
  *	state engine works properly.
 
  * 	\title Random thoughts
- *	- Integrate sip_pkt and sip_request
+ *	- Integrate sip_pkt and sip_request - done
+ *	- Mark the UNACKed packets in dialog->packets with a flag
+ *		Maybe two lists of packets, to keep it simple for do_monitor?
+ *		Or a flag when we have no open transactions?
  *	- Use sip-request as "transaction holders" within sip_dialog
  *	- Keep them in Cseq order
  *	- Add transaction state
@@ -631,15 +634,56 @@
 	return sip_debug_test_addr(sip_real_dst(dialog));
 }
 
+/*! \brief Find via branch parameter */
+static void find_via_branch(struct sip_dialog *dialog, struct sip_request *req)
+{
+	char *dupvia = ast_strdupa(req->via);
+	char *viabranch;
+	char *sep;
+
+	if (ast_strlen_zero(req->via))
+		return;
+	dupvia = ast_strdupa(req->via);
+	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, "* Found via branch %s\n", viabranch);
+	ast_string_field_set(dialog, remotebranch, viabranch);
+}
+
+
+/*! \brief Make branch tag for via header if it does not exist yet */
+static char *ourdialogbranch(struct sip_dialog *dialog, int forcenewbranch)
+{
+	char branch[20];
+	int seed = 0;
+
+	if (forcenewbranch || ast_strlen_zero(dialog->ourbranch)) {
+		if (forcenewbranch)
+			seed ^= ast_random();
+		else
+			seed = ast_random();
+		snprintf(branch, sizeof(branch), "z9hG4bk%08x", seed);
+		ast_string_field_set(dialog, ourbranch, branch);
+	}
+
+	return((char *) dialog->ourbranch);
+	
+}
+
 /*! \brief Build a Via header for a request */
-GNURK void build_via(struct sip_dialog *dialog)
+GNURK void build_via(struct sip_dialog *dialog, int forcenewbranch)
 {
 	/* Work around buggy UNIDEN UIP200 firmware */
 	const char *rport = ast_test_flag(&dialog->flags[0], SIP_NAT) & SIP_NAT_RFC3581 ? ";rport" : "";
 
 	/* z9hG4bK is a magic cookie.  See RFC 3261 section 8.1.1.7 */
-	ast_string_field_build(dialog, via, "SIP/2.0/UDP %s:%d;branch=z9hG4bK%08x%s",
-			 ast_inet_ntoa(dialog->ourip), sipnet_ourport(), dialog->branch, rport);
+	ast_string_field_build(dialog, via, "SIP/2.0/UDP %s:%d;branch=%s%s",
+			ast_inet_ntoa(dialog->ourip), sipnet_ourport(), 
+			ourdialogbranch(dialog, forcenewbranch), rport);
 }
 
 GNURK void append_history_full(struct sip_dialog *p, const char *fmt, ...)
@@ -1933,8 +1977,12 @@
 	determine_firstline_parts(req);
 	/* Determine the seqno of this request once and for all */
 
+	req->callid = get_header(req, "Call-ID");
+	req->from = get_header(req, "From");
+	req->to = get_header(req, "To");
+	req->via = get_header(req, "Via");	/* Get the first via header only */
+	req->cseqheader = get_header(req, "CSeq");  
 	/* Seqno can be zero, but anyway... */
-	req->cseqheader = get_header(req, "CSeq");
 	if (!req->seqno && sscanf(req->cseqheader, "%d ", &seqno) != 1)
 		req->seqno = seqno;
 }
@@ -2544,8 +2592,7 @@
 	req.method = sipmethod;
 	if (init) {		/* Seems like init always is 2 */
 		/* Bump branch even on initial requests */
-		p->branch ^= ast_random();
-		build_via(p);
+		build_via(p, TRUE);
 		if (init > 1)
 			initreqprep(&req, p, sipmethod);
 		else
@@ -4685,7 +4732,7 @@
 		struct sip_request req;
 		struct ast_variable *var;
 
-		if (!(p = sip_alloc(NULL, NULL, 0, SIP_NOTIFY))) {
+		if (!(p = sip_alloc(NULL, NULL, FALSE, SIP_NOTIFY))) {
 			ast_log(LOG_WARNING, "Unable to build sip pvt data for notify (memory/socket error)\n");
 			return RESULT_FAILURE;
 		}
@@ -4705,7 +4752,7 @@
 		/* Recalculate our side, and recalculate Call ID */
 		if (sip_ouraddrfor(&p->sa.sin_addr, &p->ourip))
 			p->ourip = sipnet.__ourip;
-		build_via(p);
+		build_via(p, FALSE);
 		build_callid_pvt(p);
 		ast_cli(fd, "Sending NOTIFY of type '%s' to '%s'\n", argv[2], argv[i]);
 		transmit_sip_request(p, &req);
@@ -5370,7 +5417,7 @@
 	if (ast_strlen_zero(p->theirtag) || (resp >= 200)) {
 		char tag[128];
 
-		gettag(req, "To", tag, sizeof(tag));
+		gettag(req->to, tag, sizeof(tag));
 		ast_string_field_set(p, theirtag, tag);
 	}
 	if (p->relatedpeer && p->method == SIP_OPTIONS) {
@@ -5620,7 +5667,7 @@
 		  	the final reply to our INVITE */
 			char tag[128];
 
-			gettag(req, "To", tag, sizeof(tag));
+			gettag(req->to, tag, sizeof(tag));
 			ast_string_field_set(p, theirtag, tag);
 		}
 
@@ -7091,7 +7138,7 @@
 	if (ast_strlen_zero(p->theirtag)) {
 		char tag[128];
 
-		gettag(req, "From", tag, sizeof(tag));
+		gettag(req->from, tag, sizeof(tag));
 		ast_string_field_set(p, theirtag, tag);
 	}
 	snprintf(p->lastmsg, sizeof(p->lastmsg), "Rx: %s", cmd);
@@ -7203,7 +7250,7 @@
 		p = peer->mwipvt;
 	} else {
 		/* Build temporary dialog for this message */
-		if (!(p = sip_alloc(NULL, NULL, 0, SIP_NOTIFY))) 
+		if (!(p = sip_alloc(NULL, NULL, FALSE, SIP_NOTIFY))) 
 			return -1;
 		if (create_addr_from_peer(p, peer)) {
 			/* Maybe they're not registered, etc. */
@@ -7213,7 +7260,7 @@
 		/* Recalculate our side, and recalculate Call ID */
 		if (sip_ouraddrfor(&p->sa.sin_addr, &p->ourip))
 			p->ourip = sipnet.__ourip;
-		build_via(p);
+		build_via(p, FALSE);
 		build_callid_pvt(p);
 		/* Destroy this session after 32 secs */
 		sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
@@ -7473,7 +7520,7 @@
 			ast_log(LOG_NOTICE, "Still have a QUALIFY dialog active, deleting\n");
 		sip_destroy(peer->call);
 	}
-	if (!(p = peer->call = sip_alloc(NULL, NULL, 0, SIP_OPTIONS)))
+	if (!(p = peer->call = sip_alloc(NULL, NULL, FALSE, SIP_OPTIONS)))
 		return -1;
 	
 	p->sa = peer->addr;
@@ -7493,7 +7540,7 @@
 	/* Recalculate our side, and recalculate Call ID */
 	if (sip_ouraddrfor(&p->sa.sin_addr, &p->ourip))
 		p->ourip = sipnet.__ourip;
-	build_via(p);
+	build_via(p, FALSE);
 	build_callid_pvt(p);
 
 	if (peer->pokeexpire > -1)
@@ -7609,7 +7656,7 @@
 	if (option_debug)
 		ast_log(LOG_DEBUG, "Asked to create a SIP channel with formats: %s\n", ast_getformatname_multiple(tmp, sizeof(tmp), oldformat));
 
-	if (!(p = sip_alloc(NULL, NULL, 0, SIP_INVITE))) {
+	if (!(p = sip_alloc(NULL, NULL, FALSE, SIP_INVITE))) {
 		ast_log(LOG_ERROR, "Unable to build sip pvt data for '%s' (Out of memory or socket error)\n", (char *)data);
 		*cause = AST_CAUSE_SWITCH_CONGESTION;
 		return NULL;
@@ -7646,7 +7693,7 @@
 	/* Recalculate our side, and recalculate Call ID */
 	if (sip_ouraddrfor(&p->sa.sin_addr, &p->ourip))
 		p->ourip = sipnet.__ourip;
-	build_via(p);
+	build_via(p, FALSE);
 	build_callid_pvt(p);
 	
 	/* We have an extension to call, don't use the full contact here */

Modified: team/oej/codename-pineapple/channels/sip3/sip3.h
URL: http://svn.digium.com/view/asterisk/team/oej/codename-pineapple/channels/sip3/sip3.h?rev=47214&r1=47213&r2=47214&view=diff
==============================================================================
--- team/oej/codename-pineapple/channels/sip3/sip3.h (original)
+++ team/oej/codename-pineapple/channels/sip3/sip3.h Mon Nov  6 01:18:30 2006
@@ -373,7 +373,11 @@
 	enum transaction_state state;	/*!< State of this transaction */
 	char *rlPart1; 	        /*!< SIP Method Name or "SIP/2.0" protocol version */
 	char *rlPart2; 	        /*!< The Request URI or Response Status */
-	const char *cseqheader;	/*! Pointer to the cseq header */
+	const char *cseqheader;	/*!< Pointer to the cseq header */
+	const char *callid;	/*!< Pointer to the call ID header */
+	const char *via;	/*!< Pointer to the Via header */
+	const char *to;		/*!< Pointer to the To header */
+	const char *from;	/*!< Pointer to the from header */
 	int len;                /*!< Length */
 	int headers;            /*!< # of SIP Headers */
 	unsigned int flags;     /*!< SIP_PKT Flags for this packet */
@@ -711,7 +715,8 @@
 		AST_STRING_FIELD(callid);	/*!< Dialog ID: Global CallID  - the call ID is a unique ID for this SIP dialog,
 							a string that never changes during the dialog */
 		AST_STRING_FIELD(theirtag);	/*!< Dialog ID: remote side's tag */
-		AST_STRING_FIELD(thisbranch);	/*!< Dialog ID: branch tag from topmost via */
+		AST_STRING_FIELD(remotebranch);	/*!< Dialog ID: branch tag from topmost via */
+		AST_STRING_FIELD(ourbranch);	/*!< Dialog ID: branch tag from topmost via */
 		AST_STRING_FIELD(randdata);	/*!< Random data */
 		AST_STRING_FIELD(realm);	/*!< Authorization realm for this dialog */
 		AST_STRING_FIELD(nonce);	/*!< Authorization nonce */
@@ -759,7 +764,6 @@
 	unsigned int sipoptions;		/*!< Supported SIP options on the other end */
 	int authtries;				/*!< Times we've tried to authenticate */
 	int expiry;				/*!< How long we take to expire */
-	long branch;				/*!< The branch identifier of this session */
 	char tag[11];				/*!< Dialog ID: Our tag for this session */
 	int callingpres;			/*!< Caller ID presentation settings */
 	struct sip_route *route;		/*!< Head of linked list of routing steps (fm Record-Route) */

Modified: team/oej/codename-pineapple/channels/sip3/sip3_compose.c
URL: http://svn.digium.com/view/asterisk/team/oej/codename-pineapple/channels/sip3/sip3_compose.c?rev=47214&r1=47213&r2=47214&view=diff
==============================================================================
--- team/oej/codename-pineapple/channels/sip3/sip3_compose.c (original)
+++ team/oej/codename-pineapple/channels/sip3/sip3_compose.c Mon Nov  6 01:18:30 2006
@@ -133,7 +133,7 @@
 }
 
 /*! \brief Prepare SIP response packet */
-int respprep(struct sip_request *resp, struct sip_dialog *p, const char *msg, const struct sip_request *req)
+int respprep(struct sip_request *resp, struct sip_dialog *p, const char *msg, struct sip_request *req)
 {
 	char newto[256];
 	const char *ot;
@@ -142,8 +142,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");
+	copy_header(resp, req, "From");	/* XXX this can be simplified when we are sure that req->from works*/
+	if (ast_strlen_zero(req->to))
+		req->to = get_header(req, "To");
+	ot = 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 */
@@ -156,8 +159,8 @@
 		ot = newto;
 	}
 	add_header(resp, "To", ot);
-	copy_header(resp, req, "Call-ID");
-	copy_header(resp, req, "CSeq");
+	copy_header(resp, req, "Call-ID");	/* Should use req->callid */
+	copy_header(resp, req, "CSeq");		/* Should use req->cseqheader */
 	add_header(resp, "User-Agent", global.useragent);
 	add_header(resp, "Allow", ALLOWED_METHODS);
 	add_header(resp, "Supported", SUPPORTED_EXTENSIONS);
@@ -173,7 +176,7 @@
 			snprintf(contact, sizeof(contact), "%s;expires=%d", p->our_contact, p->expiry);
 			add_header(resp, "Contact", contact);	/* Not when we unregister */
 		}
-	} else if (msg[0] != '4' && p->our_contact[0]) {
+	} else if (msg[0] != '4' && p->our_contact[0] && req->method != SIP_BYE && req->method != SIP_CANCEL) {
 		add_header(resp, "Contact", p->our_contact);
 	}
 	return 0;
@@ -324,10 +327,7 @@
 		seqno = p->ocseq;
 	}
 	
-	if (newbranch) {
-		p->branch ^= ast_random();
-		build_via(p);
-	}
+	build_via(p, newbranch);
 
 	/* Check for strict or loose router */
 	if (p->route && !ast_strlen_zero(p->route->hop) && strstr(p->route->hop,";lr") == NULL) {

Modified: team/oej/codename-pineapple/channels/sip3/sip3_dialog.c
URL: http://svn.digium.com/view/asterisk/team/oej/codename-pineapple/channels/sip3/sip3_dialog.c?rev=47214&r1=47213&r2=47214&view=diff
==============================================================================
--- team/oej/codename-pineapple/channels/sip3/sip3_dialog.c (original)
+++ team/oej/codename-pineapple/channels/sip3/sip3_dialog.c Mon Nov  6 01:18:30 2006
@@ -92,7 +92,7 @@
 #include "sip3funcs.h"
 
 /*! \page chan_sip3_dialogs Chan_sip3: The dialog list
-	\par The dialog list
+	\title The dialog list
 	The dialog list contains all active dialogs in various states.
 	A dialog can be 
 	- an active call
@@ -100,7 +100,9 @@
 	- a subscription
 	- an inbound or outbound registration
 
-	We will implement dialog states soon
+	\title Dialog states
+	Dialog states affect operation, especially in an INVITE
+	dialog. We now try to change dialog state in a clear way
 	\ref enum dialogstate
 
 */
@@ -120,12 +122,16 @@
 void dialoglist_lock(void)
 {
 	ast_mutex_lock(&dialoglock);
+	if (option_debug > 3)
+		ast_log(LOG_DEBUG, "=== SIP dialog list: LOCKED\n");
 }
 
 /*! \brief Unlock list of active SIP dialogs */
 void dialoglist_unlock(void)
 {
 	ast_mutex_unlock(&dialoglock);
+	if (option_debug > 3)
+		ast_log(LOG_DEBUG, "=== SIP dialog list: UNLOCKED\n");
 }
 
 /*! \brief Convert SIP dialog states to string */
@@ -161,14 +167,23 @@
 /*! \brief Change dialog state for a SIP dialog and output to debug */
 void dialogstatechange(struct sip_dialog *dialog, enum dialogstate newstate)
 {
-	dialog->state = newstate;
-	if (sipdebug && option_debug > 1)
-		ast_log(LOG_DEBUG, "-- Dialog %s changed state to %s\n", dialog->callid, dialogstate2str(newstate));
+	if (dialog->state == newstate) {
+		if (option_debug > 3)
+			ast_log(LOG_DEBUG, "Asked to change state to dialog that already has requested state: %s State %s\n", dialog->callid, dialogstate2str(newstate));
+	} else {
+		dialog->state = newstate;
+		if (sipdebug && option_debug > 1)
+			ast_log(LOG_DEBUG, "-- Dialog %s changed state to %s\n", dialog->callid, dialogstate2str(newstate));
+		if (global.recordhistory)
+			append_history(dialog, "DialogState", "New state: %s O-Cseq %d I-Cseq %d", dialogstate2str(newstate), dialog->ocseq, dialog->icseq);
+	}
 }
 
 
 /*! \brief For a reliable transmission, we need to get an reply to stop retransmission. 
-	Acknowledges receipt of a packet and stops retransmission */
+	Acknowledges receipt of a packet and stops retransmission 
+	\note Assume that the dialog is locked. 
+ */
 /* We need a method for responses too ... */
 void __sip_ack(struct sip_dialog *dialog, int seqno, int resp, int sipmethod, int reset)
 {
@@ -226,6 +241,7 @@
 }
 
 /*! \brief Acks receipt of packet, keep it around (used for provisional responses) 
+	\note Assume that the dialog is locked.
  */
 int __sip_semi_ack(struct sip_dialog *dialog, int seqno, int resp, int sipmethod)
 {
@@ -630,7 +646,6 @@
 
 	ast_set2_flag(&p->flags[0], !global.recordhistory, SIP_NO_HISTORY);
 
-	p->branch = ast_random();	
 	make_our_tag(p->tag, sizeof(p->tag));
 	p->ocseq = INITIAL_CSEQ;
 
@@ -678,7 +693,7 @@
 	if (p->method != SIP_REGISTER)
 		ast_string_field_set(p, fromdomain, global.default_fromdomain);
 
-	build_via(p);
+	build_via(p, TRUE);
 	if (!callid)					/* Make sure we have a unique call ID */
 		build_callid_pvt(p);
 	else
@@ -767,7 +782,6 @@
 	} else
 		p->ourip = sipnet.__ourip;
 
-	p->branch = ast_random();
 	make_our_tag(p->tag, sizeof(p->tag));
 	p->ocseq = INITIAL_CSEQ;
 
@@ -778,7 +792,7 @@
 	}
 
 	ast_string_field_set(p, fromdomain, global.default_fromdomain);
-	build_via(p);
+	build_via(p, TRUE);
 	ast_string_field_set(p, callid, callid);
 
 	/* Use this temporary pvt structure to send the message */
@@ -794,88 +808,98 @@
 	Called by handle_request, sipsock_read */
 struct sip_dialog *match_or_create_dialog(struct sip_request *req, struct sockaddr_in *sin, const int intended_method)
 {
-	struct sip_dialog *p = NULL;
+	struct sip_dialog *cur = NULL;
 	char *tag = "";	/* note, tag is never NULL */
 	char totag[128];
 	char fromtag[128];
-	const char *callid = get_header(req, "Call-ID");
-	const char *from = get_header(req, "From");
-	const char *to = get_header(req, "To");
-	const char *cseq = get_header(req, "Cseq");
+
+	if (ast_strlen_zero(req->callid))
+		req->callid = get_header(req, "Call-ID");
+	if (ast_strlen_zero(req->from))
+		req->from = get_header(req, "From");
+	if (ast_strlen_zero(req->to))
+		req->to = get_header(req, "To");
+	if (ast_strlen_zero(req->cseqheader))
+		req->cseqheader = get_header(req, "Cseq");
 
 	/* Call-ID, to, from and Cseq are required by RFC 3261. (Max-forwards and via too - ignored now) */
 	/* get_header always returns non-NULL so we must use ast_strlen_zero() */
-	if (ast_strlen_zero(callid) || ast_strlen_zero(to) ||
-			ast_strlen_zero(from) || ast_strlen_zero(cseq))
+	if (ast_strlen_zero(req->callid) || ast_strlen_zero(req->to) ||
+			ast_strlen_zero(req->from) || ast_strlen_zero(req->cseqheader))
 		return NULL;	/* Invalid packet */
 
 	/* In principle Call-ID's uniquely identify a call, but with a forking SIP proxy
 	   we need more to identify a branch - so we have to check branch, from
 	   and to tags to identify a call leg.
 	   */
-	if (gettag(req, "To", totag, sizeof(totag)))
+	if (gettag(req->to, totag, sizeof(totag)))
 		ast_set_flag(req, SIP_PKT_WITH_TOTAG);	/* Used in handle_request/response */
-	gettag(req, "From", fromtag, sizeof(fromtag));
+	gettag(req->from, fromtag, sizeof(fromtag));
 
 	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);
+		ast_log(LOG_DEBUG, "= Looking for  Call ID: %s (Checking %s) --From tag %s --To-tag %s  \n", req->callid, req->method==SIP_RESPONSE ? "To" : "From", fromtag, totag);
 
 	dialoglist_lock();
-	for (p = dialoglist; p; p = p->next) {
+	for (cur = dialoglist; cur; cur = cur->next) {
 		/* 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));
+			found = (!strcmp(cur->callid, req->callid));
 		else 
-			found = (!strcmp(p->callid, callid) && 
-			(!tag || ast_strlen_zero(p->theirtag) || !strcmp(p->theirtag, tag))) ;
+			found = (!strcmp(cur->callid, req->callid) && 
+			(!tag || ast_strlen_zero(cur->theirtag) || !strcmp(cur->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);
+			ast_log(LOG_DEBUG, "= %s Their Call ID: %s Their Tag %s Our tag: %s\n", found ? "Found" : "No match", cur->callid, cur->theirtag, cur->tag);
 
 		/* If we get a new request within an existing to-tag - check the to tag as well */
 		if (found  && req->method != SIP_RESPONSE) {	/* SIP Request */
-			if (p->tag[0] == '\0' && totag[0]) {
+			if (cur->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)) {
+				if (strcmp(totag, cur->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_method2txt(req->method));
+				ast_log(LOG_DEBUG, "= Being pedantic: This is not our match on request: Call ID: %s Ourtag <null> Totag %s Method %s\n", cur->callid, totag, sip_method2txt(req->method));
 		}
 
 
 		if (found) {
 			/* Found the call */
-			ast_mutex_lock(&p->lock);
+			ast_mutex_lock(&cur->lock);
 			dialoglist_unlock();
-			return p;
+			return cur;
 		}
 	}
 	dialoglist_unlock();
-	if (sip_methods[intended_method].creates_dialog == CAN_CREATE_DIALOG) {
-		if (intended_method == SIP_REFER) {
-
-			/* We do not support out-of-dialog REFERs yet */
-			transmit_response_using_temp(callid, sin, 1, intended_method, req, "603 Declined (no dialog)");
-		} else if (intended_method == SIP_NOTIFY) {
-			/* We do not support out-of-dialog NOTIFY either,
-			  like voicemail notification, so cancel that early */
-			transmit_response_using_temp(callid, sin, 1, intended_method, req, "489 Bad event");
-		} else if ((p = sip_alloc(callid, sin, 1, intended_method))) {
+	if (sip_methods[intended_method].creates_dialog != CAN_CREATE_DIALOG && intended_method != SIP_RESPONSE) {
+		transmit_response_using_temp(req->callid, sin, TRUE, intended_method, req, "481 Call leg/transaction does not exist");
+		return cur;
+	}
+	switch (intended_method) {
+	case SIP_REFER:
+		/* We do not support out-of-dialog REFERs yet */
+		transmit_response_using_temp(req->callid, sin, TRUE, intended_method, req, "603 Declined (no dialog)");
+		break;
+	case SIP_NOTIFY:
+		/* We do not support out-of-dialog NOTIFY either,
+		  like voicemail notification, so cancel that early */
+		transmit_response_using_temp(req->callid, sin, TRUE, intended_method, req, "489 Bad event");
+		break;
+	default:
+		/* ready to create a new dialog. */
+		if ((cur = sip_alloc(req->callid, sin, TRUE, intended_method))) {
 			/* This method creates dialog */
-			/* Ok, we've created a dialog, let's go and process it */
-			ast_mutex_lock(&p->lock);
+			/* Ok, 	we've created a dialog, let's go and process it */
+			ast_mutex_lock(&cur->lock);
 		}
-	} else {
-		if (intended_method != SIP_RESPONSE)
-			transmit_response_using_temp(callid, sin, 1, intended_method, req, "481 Call leg/transaction does not exist");
-	}
-
-	return p;
-}
+		break;
+	}
+
+	return cur;
+}

Modified: team/oej/codename-pineapple/channels/sip3/sip3_parse.c
URL: http://svn.digium.com/view/asterisk/team/oej/codename-pineapple/channels/sip3/sip3_parse.c?rev=47214&r1=47213&r2=47214&view=diff
==============================================================================
--- team/oej/codename-pineapple/channels/sip3/sip3_parse.c (original)
+++ team/oej/codename-pineapple/channels/sip3/sip3_parse.c Mon Nov  6 01:18:30 2006
@@ -196,15 +196,14 @@
  * \return Returns the pointer to the provided tag buffer,
  *         or NULL if the tag was not found.
  */
-const char *gettag(const struct sip_request *req, const char *header, char *tagbuf, int tagbufsize)
+const char *gettag(const char *header, char *tagbuf, int tagbufsize)
 {
 	const char *thetag;
 
 	if (!tagbuf)
 		return NULL;
 	tagbuf[0] = '\0'; 	/* reset the buffer */
-	thetag = get_header(req, header);
-	thetag = strcasestr(thetag, ";tag=");
+	thetag = strcasestr(header, ";tag=");
 	if (thetag) {
 		thetag += 5;
 		ast_copy_string(tagbuf, thetag, tagbufsize);

Modified: team/oej/codename-pineapple/channels/sip3/sip3_services.c
URL: http://svn.digium.com/view/asterisk/team/oej/codename-pineapple/channels/sip3/sip3_services.c?rev=47214&r1=47213&r2=47214&view=diff
==============================================================================
--- team/oej/codename-pineapple/channels/sip3/sip3_services.c (original)
+++ team/oej/codename-pineapple/channels/sip3/sip3_services.c Mon Nov  6 01:18:30 2006
@@ -498,15 +498,12 @@
 	snprintf(addr, sizeof(addr), "sip:%s", S_OR(p->fromdomain, r->hostname));
 	ast_string_field_set(p, uri, addr);
 
-	p->branch ^= ast_random();
-
 	init_req(&req, sipmethod, addr);
 
 	/* Add to CSEQ */
 	snprintf(tmp, sizeof(tmp), "%u %s", ++r->ocseq, sip_method2txt(sipmethod));
 	p->ocseq = r->ocseq;
-
-	build_via(p);
+	build_via(p, TRUE);
 	add_header(&req, "Via", p->via);
 	add_header(&req, "From", from);
 	add_header(&req, "To", to);

Modified: team/oej/codename-pineapple/channels/sip3/sip3funcs.h
URL: http://svn.digium.com/view/asterisk/team/oej/codename-pineapple/channels/sip3/sip3funcs.h?rev=47214&r1=47213&r2=47214&view=diff
==============================================================================
--- team/oej/codename-pineapple/channels/sip3/sip3funcs.h (original)
+++ team/oej/codename-pineapple/channels/sip3/sip3funcs.h Mon Nov  6 01:18:30 2006
@@ -69,7 +69,7 @@
 GNURK int transmit_state_notify(struct sip_dialog *p, int state, int full, int timeout);
 GNURK int transmit_request_with_auth(struct sip_dialog *p, int sipmethod, int seqno, enum xmittype reliable, int newbranch);
 GNURK void do_setnat(struct sip_dialog *p, int natflags);
-GNURK void build_via(struct sip_dialog *p);
+GNURK void build_via(struct sip_dialog *p, int forcenewbranch);
 GNURK void __sip_pretend_ack(struct sip_dialog *p);
 GNURK int create_addr(struct sip_dialog *dialog, const char *opeer);
 GNURK void build_contact(struct sip_dialog *p);
@@ -127,7 +127,7 @@
 GNURK const char *__get_header(const struct sip_request *req, const char *name, int *start);
 GNURK char *get_in_brackets(char *tmp);
 GNURK char *generate_random_string(char *buf, size_t size);
-GNURK const char *gettag(const struct sip_request *req, const char *header, char *tagbuf, int tagbufsize);
+GNURK const char *gettag(const char *header, char *tagbuf, int tagbufsize);
 GNURK int determine_firstline_parts(struct sip_request *req);
 GNURK void extract_uri(struct sip_dialog *p, struct sip_request *req);
 
@@ -136,7 +136,7 @@
 GNURK void append_date(struct sip_request *req);
 GNURK int add_text(struct sip_request *req, const char *text);
 GNURK int add_digit(struct sip_request *req, char digit);
-GNURK int respprep(struct sip_request *resp, struct sip_dialog *p, const char *msg, const struct sip_request *req);
+GNURK int respprep(struct sip_request *resp, struct sip_dialog *p, const char *msg, struct sip_request *req);
 GNURK void add_route(struct sip_request *req, struct sip_route *route);
 GNURK int add_line(struct sip_request *req, const char *line);
 GNURK int add_header_contentLength(struct sip_request *req, int len);



More information about the asterisk-commits mailing list