[svn-commits] ctooley: branch ctooley/excel-sip-changes r118943 - /team/ctooley/excel-sip-c...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu May 29 08:09:44 CDT 2008


Author: ctooley
Date: Thu May 29 08:09:43 2008
New Revision: 118943

URL: http://svn.digium.com/view/asterisk?view=rev&rev=118943
Log:
initial 300 Multiple choices functionality DOES NOT WORK CORRECTLY

Modified:
    team/ctooley/excel-sip-changes/channels/chan_sip.c

Modified: team/ctooley/excel-sip-changes/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/ctooley/excel-sip-changes/channels/chan_sip.c?view=diff&rev=118943&r1=118942&r2=118943
==============================================================================
--- team/ctooley/excel-sip-changes/channels/chan_sip.c (original)
+++ team/ctooley/excel-sip-changes/channels/chan_sip.c Thu May 29 08:09:43 2008
@@ -1826,6 +1826,7 @@
 static int sip_write(struct ast_channel *ast, struct ast_frame *frame);
 static int sip_indicate(struct ast_channel *ast, int condition, const void *data, size_t datalen);
 static int sip_transfer(struct ast_channel *ast, const char *dest);
+static int sip_routeresponse(struct ast_channel *ast, const char *dest, const char *routelist);
 static int sip_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
 static int sip_senddigit_begin(struct ast_channel *ast, char digit);
 static int sip_senddigit_end(struct ast_channel *ast, char digit, unsigned int duration);
@@ -1898,6 +1899,7 @@
 static void *sip_park_thread(void *stuff);
 static int sip_park(struct ast_channel *chan1, struct ast_channel *chan2, struct sip_request *req, int seqno);
 static int sip_sipredirect(struct sip_pvt *p, const char *dest);
+static int sip_redirect_multiplechoices(struct sip_pvt *p, const char *dest, const char *content);
 
 /*--- Codec handling / SDP */
 static void try_suggested_sip_codec(struct sip_pvt *p);
@@ -2197,6 +2199,7 @@
 	.write_text = sip_write,
 	.indicate = sip_indicate,		/* called with chan locked */
 	.transfer = sip_transfer,		/* called with chan locked */
+	.routeresponse = sip_routeresponse,	/* called with chan locked */
 	.fixup = sip_fixup,			/* called with chan locked */
 	.send_digit_begin = sip_senddigit_begin,	/* called with chan unlocked */
 	.send_digit_end = sip_senddigit_end,
@@ -4912,6 +4915,7 @@
 			return "484 Address incomplete";
 		case AST_CAUSE_USER_BUSY:
 			return "486 Busy here";
+		case AST_CAUSE_NORMAL_TEMPORARY_FAILURE: /* 41 */
 		case AST_CAUSE_FAILURE:
 			return "500 Server internal failure";
 		case AST_CAUSE_FACILITY_REJECTED:	/* 29 */
@@ -5340,6 +5344,24 @@
 	}
 	sip_pvt_unlock(p);
 
+	return res;
+}
+
+
+/*! \brief Respond to a Route Request SIP INVITE */
+static int sip_routeresponse(struct ast_channel *ast, const char *dest, const char *routelist)
+{
+	struct sip_pvt *p = ast->tech_pvt;
+	int res;
+
+	if(!routelist)	/* functions below do not take a NULL */
+		routelist = "";
+
+	if (!dest)	/* functions below do not take a NULL */
+		dest = "";
+	sip_pvt_lock(p);
+	res = sip_redirect_multiplechoices(p, dest, routelist);
+	sip_pvt_unlock(p);
 	return res;
 }
 
@@ -7827,7 +7849,10 @@
 		return -1;
 	}
 	respprep(&resp, p, msg, req);
-	add_header_contentLength(&resp, 0);
+	clheader = get_header(req, "Content-Length");
+	if(!clheader[0]) {
+		add_header_contentLength(&resp, 0);
+	}
 	/* If we are cancelling an incoming invite for some reason, add information
 		about the reason why we are doing this in clear text */
 	if (p->method == SIP_INVITE && msg[0] != '1' && p->owner && p->owner->hangupcause) {
@@ -7917,6 +7942,18 @@
 static int transmit_response(struct sip_pvt *p, const char *msg, const struct sip_request *req) 
 {
 	return __transmit_response(p, msg, req, XMIT_UNRELIABLE);
+}
+
+/*! \brief Transmit response, with routedata */
+static int transmit_response_with_routedata(struct sip_pvt *p, const char *msg, const struct sip_request *req, const char *routedata) 
+{
+	struct sip_request resp;
+	respprep(&resp, p, msg, req);
+	append_date(&resp);
+	add_header(&resp, "Content-Type", "text/plain");
+	add_header_contentLength(&resp, strlen(routedata));
+	add_line(&resp, routedata);
+	return send_response(p, &resp, XMIT_CRITICAL, 1);
 }
 
 /*! \brief Transmit response, no retransmits */
@@ -22501,6 +22538,58 @@
 	return 0;
 }
 
+/*! \brief Redirect call connect with a 300 multiple choices redirect
+\note	Called by the routeresponse() dialplan application through the sip_routeresponse()
+	pbx interface function
+ */
+static int sip_redirect_multiplechoices(struct sip_pvt *p, const char *dest, const char *content)
+{
+	char *cdest;
+	char *extension, *host, *port;
+	char tmp[80];
+	
+	cdest = ast_strdupa(dest);
+	
+	extension = strsep(&cdest, "@");
+	host = strsep(&cdest, ":");
+	port = strsep(&cdest, ":");
+	if (ast_strlen_zero(extension)) {
+		ast_log(LOG_ERROR, "Missing mandatory argument: extension\n");
+		return 0;
+	}
+
+	/* we'll issue the redirect message here */
+	if (!host) {
+		char *localtmp;
+		ast_copy_string(tmp, get_header(&p->initreq, "To"), sizeof(tmp));
+		if (ast_strlen_zero(tmp)) {
+			ast_log(LOG_ERROR, "Cannot retrieve the 'To' header from the original SIP request!\n");
+			return 0;
+		}
+		if ((localtmp = strcasestr(tmp, "sip:")) && (localtmp = strchr(localtmp, '@'))) {
+			char lhost[80], lport[80];
+			memset(lhost, 0, sizeof(lhost));
+			memset(lport, 0, sizeof(lport));
+			localtmp++;
+			/* This is okey because lhost and lport are as big as tmp */
+			sscanf(localtmp, "%[^<>:; ]:%[^<>:; ]", lhost, lport);
+			if (ast_strlen_zero(lhost)) {
+				ast_log(LOG_ERROR, "Can't find the host address\n");
+				return 0;
+			}
+			host = ast_strdupa(lhost);
+			if (!ast_strlen_zero(lport)) {
+				port = ast_strdupa(lport);
+			}
+		}
+	}
+
+	transmit_response_with_routedata(p, "300 Multiple choices", &p->initreq, content);
+	sip_scheddestroy(p, 10);	/*  Make sure we stop send this reply. */
+	sip_alreadygone(p);
+	return 0;
+}
+
 /*! \brief Return SIP UA's codec (part of the RTP interface) */
 static int sip_get_codec(struct ast_channel *chan)
 {




More information about the svn-commits mailing list