[svn-commits] oej: branch oej/codename-pineapple r45376 - in /team/oej/codename-pineapple/c...

svn-commits at lists.digium.com svn-commits at lists.digium.com
Tue Oct 17 13:04:59 MST 2006


Author: oej
Date: Tue Oct 17 15:04:58 2006
New Revision: 45376

URL: http://svn.digium.com/view/asterisk?rev=45376&view=rev
Log:
Add support for SIP diversion header

Modified:
    team/oej/codename-pineapple/channels/chan_sip3.c
    team/oej/codename-pineapple/channels/sip3/sip3.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=45376&r1=45375&r2=45376&view=diff
==============================================================================
--- team/oej/codename-pineapple/channels/chan_sip3.c (original)
+++ team/oej/codename-pineapple/channels/chan_sip3.c Tue Oct 17 15:04:58 2006
@@ -130,6 +130,8 @@
 	- Implement netsock API in this channel
 	- Add File's multithreading code
 	- Make debugaddr a ha list instead of one address and move it out of sipnet
+
+	- change "sip nodebug" to "sip debug off" and "sip debug" to "sip debug on"
 
 	- ... And much more
 */
@@ -6099,29 +6101,87 @@
 	return res;
 }
 
+/*! \brief Translate referring cause */
+static void sip_set_redirstr(struct sip_pvt *p, char *reason) {
+
+	if (strcmp(reason, "unknown")==0) {
+		ast_string_field_set(p, redircause, "UNKNOWN");
+	} else if (strcmp(reason, "user-busy")==0) {
+		ast_string_field_set(p, redircause, "BUSY");
+	} else if (strcmp(reason, "no-answer")==0) {
+		ast_string_field_set(p, redircause, "NOANSWER");
+	} else if (strcmp(reason, "unavailable")==0) {
+		ast_string_field_set(p, redircause, "UNREACHABLE");
+	} else if (strcmp(reason, "unconditional")==0) {
+		ast_string_field_set(p, redircause, "UNCONDITIONAL");
+	} else if (strcmp(reason, "time-of-day")==0) {
+		ast_string_field_set(p, redircause, "UNKNOWN");
+	} else if (strcmp(reason, "do-not-disturb")==0) {
+		ast_string_field_set(p, redircause, "UNKNOWN");
+	} else if (strcmp(reason, "deflection")==0) {
+		ast_string_field_set(p, redircause, "UNKNOWN");
+	} else if (strcmp(reason, "follow-me")==0) {
+		ast_string_field_set(p, redircause, "UNKNOWN");
+	} else if (strcmp(reason, "out-of-service")==0) {
+		ast_string_field_set(p, redircause, "UNREACHABLE");
+	} else if (strcmp(reason, "away")==0) {
+		ast_string_field_set(p, redircause, "UNREACHABLE");
+	} else {
+		ast_string_field_set(p, redircause, "UNKNOWN");
+	}
+}
+
 /*! \brief Get referring dnis */
 static int get_rdnis(struct sip_pvt *p, struct sip_request *oreq)
 {
-	char tmp[256], *c, *a;
+	char tmp[256], *exten, *rexten, *rdomain;
+	char *params, *reason = NULL;
 	struct sip_request *req;
 	
-	req = oreq;
-	if (!req)
-		req = &p->initreq;
+	req = oreq ? oreq : &p->initreq;
+
 	ast_copy_string(tmp, get_header(req, "Diversion"), sizeof(tmp));
 	if (ast_strlen_zero(tmp))
 		return 0;
-	c = get_in_brackets(tmp);
-	if (strncmp(c, "sip:", 4)) {
-		ast_log(LOG_WARNING, "Huh?  Not an RDNIS SIP header (%s)?\n", c);
+
+	exten = get_in_brackets(tmp);
+	if (strncmp(exten, "sip:", 4)) {
+		ast_log(LOG_WARNING, "Huh?  Not an RDNIS SIP header (%s)?\n", exten);
 		return -1;
 	}
-	c += 4;
-	a = c;
-	strsep(&a, "@;");	/* trim anything after @ or ; */
+	exten += 4;
+
+	/* Get diversion-reason param if present */
+	if ((params = strchr(tmp, ';'))) {
+		*params = '\0';	/* Cut off parameters  */
+		params++;
+		while (*params == ';' || *params == ' ')
+			params++;
+		/* Check if we have a reason parameter */
+		if ((reason = strcasestr(params, "reason="))) {
+			reason+=7;
+			/* Remove enclosing double-quotes */
+			if (*reason == '"') 
+				ast_strip_quoted(reason, "\"", "\"");
+			if (!ast_strlen_zero(reason)) {
+				sip_set_redirstr(p, reason);
+				if (p->owner) {
+					pbx_builtin_setvar_helper(p->owner, "__PRIREDIRECTREASON", p->redircause);
+					pbx_builtin_setvar_helper(p->owner, "__SIPREDIRECTREASON", reason);
+				}
+			}
+		}
+	}
+
+	rdomain = exten;
+	rexten = strsep(&rdomain, "@");	/* trim anything after @ */
+	if (p->owner) 
+		pbx_builtin_setvar_helper(p->owner, "__SIPRDNISDOMAIN", rdomain);
+
 	if (sip_debug_test_pvt(p))
-		ast_verbose("RDNIS is %s\n", c);
-	ast_string_field_set(p, rdnis, c);
+		ast_verbose("RDNIS for this call is is %s (reason %s)\n", exten, reason ? reason : "");
+
+	ast_string_field_set(p, rdnis, rexten);
 
 	return 0;
 }
@@ -13959,6 +14019,7 @@
 	/* 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");
@@ -13966,6 +14027,7 @@
 		}
 		if ((localtmp = strstr(tmp, "sip:")) && (localtmp = strchr(localtmp, '@'))) {
 			char lhost[80], lport[80];
+
 			memset(lhost, 0, sizeof(lhost));
 			memset(lport, 0, sizeof(lport));
 			localtmp++;

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=45376&r1=45375&r2=45376&view=diff
==============================================================================
--- team/oej/codename-pineapple/channels/sip3/sip3.h (original)
+++ team/oej/codename-pineapple/channels/sip3/sip3.h Tue Oct 17 15:04:58 2006
@@ -612,6 +612,7 @@
 		AST_STRING_FIELD(mohinterpret);	/*!< MOH class to use when put on hold */
 		AST_STRING_FIELD(mohsuggest);	/*!< MOH class to suggest when putting a peer on hold */
 		AST_STRING_FIELD(rdnis);	/*!< Referring DNIS */
+		AST_STRING_FIELD(redircause);	/*!< Referring cause */
 		AST_STRING_FIELD(theirtag);	/*!< Their tag */
 		AST_STRING_FIELD(username);	/*!< [user] name */
 		AST_STRING_FIELD(peername);	/*!< [peer] name, not set if [user] */



More information about the svn-commits mailing list