[asterisk-commits] branch oej/sipdiversion r8904 - in /team/oej/sipdiversion: ./ channels/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Jan 31 14:20:50 MST 2006


Author: oej
Date: Mon Jan 30 09:53:17 2006
New Revision: 8904

URL: http://svn.digium.com/view/asterisk?rev=8904&view=rev
Log:
Adding patch from issue #5484 created by tinning - support for Diversion: header

Modified:
    team/oej/sipdiversion/   (props changed)
    team/oej/sipdiversion/channels/chan_sip.c

Propchange: team/oej/sipdiversion/
------------------------------------------------------------------------------
    svnmerge-integrated = /trunk:1-8901

Modified: team/oej/sipdiversion/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/oej/sipdiversion/channels/chan_sip.c?rev=8904&r1=8903&r2=8904&view=diff
==============================================================================
--- team/oej/sipdiversion/channels/chan_sip.c (original)
+++ team/oej/sipdiversion/channels/chan_sip.c Mon Jan 30 09:53:17 2006
@@ -622,6 +622,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] */
@@ -2880,6 +2881,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;
@@ -6579,10 +6582,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;
@@ -6591,6 +6625,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