--- trunk/chan_sip.c 2009/01/30 09:58:35 4 +++ trunk/chan_sip.c 2009/01/30 11:35:53 7 @@ -1361,6 +1361,7 @@ #define SIP_PAGE2_RTAUTOCLEAR (1 << 2) /*!< GP: Should we clean memory from peers after expiry? */ /* Space for addition of other realtime flags in the future */ #define SIP_PAGE2_STATECHANGEQUEUE (1 << 9) /*!< D: Unsent state pending change exists */ +#define SIP_PAGE2_Q850_REASON (1 << 10) /*!< DP: Get/send cause code via Reason header */ #define SIP_PAGE2_VIDEOSUPPORT (1 << 14) /*!< DP: Video supported if offered? */ #define SIP_PAGE2_TEXTSUPPORT (1 << 15) /*!< GDP: Global text enable */ @@ -1391,7 +1392,7 @@ (SIP_PAGE2_ALLOWSUBSCRIBE | SIP_PAGE2_ALLOWOVERLAP | SIP_PAGE2_IGNORESDPVERSION | \ SIP_PAGE2_VIDEOSUPPORT | SIP_PAGE2_T38SUPPORT | SIP_PAGE2_RFC2833_COMPENSATE | \ SIP_PAGE2_BUGGY_MWI | SIP_PAGE2_TEXTSUPPORT | SIP_PAGE2_FAX_DETECT | \ - SIP_PAGE2_UDPTL_DESTINATION | SIP_PAGE2_VIDEOSUPPORT_ALWAYS) + SIP_PAGE2_UDPTL_DESTINATION | SIP_PAGE2_VIDEOSUPPORT_ALWAYS | SIP_PAGE2_Q850_REASON) /*@}*/ @@ -8581,11 +8582,17 @@ /* 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) { - char buf[10]; + char buf[20]; add_header(&resp, "X-Asterisk-HangupCause", ast_cause2str(p->owner->hangupcause)); snprintf(buf, sizeof(buf), "%d", p->owner->hangupcause); add_header(&resp, "X-Asterisk-HangupCauseCode", buf); + + if (ast_test_flag(&p->flags[1], SIP_PAGE2_Q850_REASON)) { + sprintf(buf, "Q.850;cause=%d", p->owner->hangupcause); + add_header(&resp, "Reason", buf); + } + } return send_response(p, &resp, reliable, seqno); } @@ -10950,11 +10957,16 @@ /* If we are hanging up and know a cause for that, send it in clear text to make debugging easier. */ if (sipmethod == SIP_BYE) { - char buf[10]; + char buf[20]; add_header(&resp, "X-Asterisk-HangupCause", ast_cause2str(p->hangupcause)); snprintf(buf, sizeof(buf), "%d", p->hangupcause); add_header(&resp, "X-Asterisk-HangupCauseCode", buf); + + if (ast_test_flag(&p->flags[1], SIP_PAGE2_Q850_REASON)) { + sprintf(buf, "Q.850;cause=%d", p->hangupcause); + add_header(&resp, "Reason", buf); + } } add_header_contentLength(&resp, 0); @@ -14297,6 +14309,7 @@ ast_cli(fd, " Sess-Refresh : %s\n", strefresher2str(peer->stimer.st_ref)); ast_cli(fd, " Sess-Expires : %d secs\n", peer->stimer.st_max_se); ast_cli(fd, " Min-Sess : %d secs\n", peer->stimer.st_min_se); + ast_cli(fd, " Q850Reason : %s\n", ast_test_flag(&peer->flags[1], SIP_PAGE2_Q850_REASON) ? "Yes" : "No"); ast_cli(fd, "\n"); peer = unref_peer(peer, "sip_show_peer: unref_peer: done with peer ptr"); } else if (peer && type == 1) { /* manager listing */ @@ -14374,6 +14387,7 @@ astman_append(s, "SIP-Useragent: %s\r\n", peer->useragent); astman_append(s, "Reg-Contact: %s\r\n", peer->fullcontact); astman_append(s, "QualifyFreq: %d ms\r\n", peer->qualifyfreq); + astman_append(s, "SIP-Use-Reason-Header : %s\n", (ast_test_flag(&peer->flags[1], SIP_PAGE2_Q850_REASON))?"Y":"N"); if (peer->chanvars) { for (v = peer->chanvars ; v ; v = v->next) { astman_append(s, "ChanVariable: %s=%s\r\n", v->name, v->value); @@ -17096,6 +17110,7 @@ char *c_copy = ast_strdupa(c); /* Skip the Cseq and its subsequent spaces */ const char *msg = ast_skip_blanks(ast_skip_nonblanks(c_copy)); + char *reason_header = NULL; if (!msg) msg = ""; @@ -17103,8 +17118,14 @@ sipmethod = find_sip_method(msg); owner = p->owner; - if (owner) - owner->hangupcause = hangup_sip2cause(resp); + if (owner) { + if (ast_test_flag(&p->flags[1], SIP_PAGE2_Q850_REASON) && + (reason_header = strstr(get_header(req, "Reason"), "cause=")) && + sscanf(reason_header, "cause=%d", &owner->hangupcause)) + ast_verb(3, "Using SIP Reason header for cause code:%d\n", owner->hangupcause); + else + owner->hangupcause = hangup_sip2cause(resp); + } /* Acknowledge whatever it is destined for */ if ((resp >= 100) && (resp <= 199)) @@ -22678,7 +22699,10 @@ } else { peer->stimer.st_ref = i; } - } + } else if (!strcasecmp(v->name, "use_q850_reason")) { + ast_set2_flag(&peer->flags[1], ast_true(v->value), SIP_PAGE2_Q850_REASON); + } + } if (!peer->socket.type) { @@ -23447,7 +23471,10 @@ ast_log(LOG_WARNING, "Invalid pokepeers '%s' at line %d of %s\n", v->value, v->lineno, config); global_qualify_peers = DEFAULT_QUALIFY_PEERS; } - } + } else if (!strcasecmp(v->name, "use_q850_reason")) { + ast_set2_flag(&global_flags[1], ast_true(v->value), SIP_PAGE2_Q850_REASON); + } + } if (!sip_cfg.allow_external_domains && AST_LIST_EMPTY(&domain_list)) {