[asterisk-commits] branch oej/test-this-branch r10650 - in /team/oej/test-this-branch: ./ channels/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Feb 21 11:50:17 MST 2006


Author: oej
Date: Tue Feb 21 12:50:14 2006
New Revision: 10650

URL: http://svn.digium.com/view/asterisk?rev=10650&view=rev
Log:
Integrating sipdiversion branch

Modified:
    team/oej/test-this-branch/   (props changed)
    team/oej/test-this-branch/channels/chan_sip.c

Propchange: team/oej/test-this-branch/
------------------------------------------------------------------------------
    svnmerge-integrated = /trunk:1-10645

Modified: team/oej/test-this-branch/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/channels/chan_sip.c?rev=10650&r1=10649&r2=10650&view=diff
==============================================================================
--- team/oej/test-this-branch/channels/chan_sip.c (original)
+++ team/oej/test-this-branch/channels/chan_sip.c Tue Feb 21 12:50:14 2006
@@ -636,6 +636,7 @@
 		AST_STRING_FIELD(language);	/*!< Default language for this call */
 		AST_STRING_FIELD(musicclass);	/*!< Music on Hold class */
 		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] */
@@ -2924,6 +2925,8 @@
 		tmp->cid.cid_name = ast_strdup(i->cid_name);
 	if (!ast_strlen_zero(i->rdnis))
 		tmp->cid.cid_rdnis = ast_strdup(i->rdnis);
+	if (!ast_strlen_zero(i->redircause))
+		pbx_builtin_setvar_helper(tmp, "__PRIREDIRECTREASON", i->redircause);
 	if (!ast_strlen_zero(i->exten) && strcmp(i->exten, "s"))
 		tmp->cid.cid_dnid = ast_strdup(i->exten);
 	tmp->priority = 1;
@@ -6592,10 +6595,41 @@
 	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 *params, *reason, *stop;
 	struct sip_request *req;
 	
 	req = oreq;
@@ -6604,6 +6638,41 @@
 	ast_copy_string(tmp, get_header(req, "Diversion"), sizeof(tmp));
 	if (ast_strlen_zero(tmp))
 		return 0;
+
+	/* Get diversion-reason param if present */
+	params = strchr(tmp, ';');
+	if (params && *params == ';' && *(params+1) != '\0') {
+		while (*params == ';' || *params == ' ') params++;
+		if (strlen(params) >= strlen("reason=")) {
+			if (strncasecmp(params, "reason", strlen("reason")) == 0) {
+				reason = strchr(params, '=');
+				if (reason && *reason == '=') {
+					reason++;
+					/* Remove enclosing double-quotes */
+					if (*reason == '"') {
+						reason++;
+						stop = reason;
+						while (*stop != '"') {
+							if (*stop == '\0') {
+								/* Missing end-quote */
+								*reason = '\0';
+								break;
+							}
+							stop++;
+						}
+						*stop = '\0';
+					} else {
+						stop = reason;
+						while (*stop && *stop != ';' && *stop != '"') stop++;
+						*stop = '\0';
+					}
+					if (*reason)
+						sip_set_redirstr(p, reason);
+				}
+			}
+		}
+	}
+
 	c = get_in_brackets(tmp);
 	if (strncmp(c, "sip:", 4)) {
 		ast_log(LOG_WARNING, "Huh?  Not an RDNIS SIP header (%s)?\n", c);



More information about the asterisk-commits mailing list