--- ../../asterisk.old/channels/chan_sip.c 2006-01-30 15:07:51.000000000 +0100 +++ chan_sip.c 2006-01-30 15:24:11.000000000 +0100 @@ -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_copy_string(p->redircause, "UNKNOWN", sizeof(p->redircause)); + } else if (strcmp(reason, "user-busy")==0) { + ast_copy_string(p->redircause, "BUSY", sizeof(p->redircause)); + } else if (strcmp(reason, "no-answer")==0) { + ast_copy_string(p->redircause, "NOANSWER", sizeof(p->redircause)); + } else if (strcmp(reason, "unavailable")==0) { + ast_copy_string(p->redircause, "UNREACHABLE", sizeof(p->redircause)); + } else if (strcmp(reason, "unconditional")==0) { + ast_copy_string(p->redircause, "UNCONDITIONAL", sizeof(p->redircause)); + } else if (strcmp(reason, "time-of-day")==0) { + ast_copy_string(p->redircause, "UNKNOWN", sizeof(p->redircause)); + } else if (strcmp(reason, "do-not-disturb")==0) { + ast_copy_string(p->redircause, "UNKNOWN", sizeof(p->redircause)); + } else if (strcmp(reason, "deflection")==0) { + ast_copy_string(p->redircause, "UNKNOWN", sizeof(p->redircause)); + } else if (strcmp(reason, "follow-me")==0) { + ast_copy_string(p->redircause, "UNKNOWN", sizeof(p->redircause)); + } else if (strcmp(reason, "out-of-service")==0) { + ast_copy_string(p->redircause, "UNREACHABLE", sizeof(p->redircause)); + } else if (strcmp(reason, "away")==0) { + ast_copy_string(p->redircause, "UNREACHABLE", sizeof(p->redircause)); + } else { + ast_copy_string(p->redircause, "UNKNOWN", sizeof(p->redircause)); + } +} + /*! \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);