Index: channels/chan_sip.c =================================================================== RCS file: /usr/cvsroot/asterisk/channels/chan_sip.c,v retrieving revision 1.784 diff -u -r1.784 chan_sip.c --- channels/chan_sip.c 20 Jul 2005 17:05:18 -0000 1.784 +++ channels/chan_sip.c 23 Jul 2005 16:29:00 -0000 @@ -2183,12 +2183,13 @@ int needcancel = 0; struct ast_flags locflags = {0}; - if (option_debug) - ast_log(LOG_DEBUG, "sip_hangup(%s)\n", ast->name); if (!p) { ast_log(LOG_DEBUG, "Asked to hangup channel not connected\n"); return 0; } + if (option_debug) + ast_log(LOG_DEBUG, "Hangup call %s, SIP callid %s)\n", ast->name, p->callid); + ast_mutex_lock(&p->lock); #ifdef OSP_SUPPORT if ((p->osphandle > -1) && (ast->_state == AST_STATE_UP)) { @@ -2204,12 +2205,14 @@ } /* Determine how to disconnect */ if (p->owner != ast) { - ast_log(LOG_WARNING, "Huh? We aren't the owner?\n"); + ast_log(LOG_WARNING, "Huh? We aren't the owner? Can't hangup call.\n"); ast_mutex_unlock(&p->lock); return 0; } + /* If the call is not UP, we need to send CANCEL instead of BYE */ if (ast->_state != AST_STATE_UP) needcancel = 1; + /* Disconnect */ p = ast->tech_pvt; if (p->vad) { @@ -2224,9 +2227,10 @@ ast_update_use_count(); ast_set_flag(&locflags, SIP_NEEDDESTROY); + /* Start the process if it's not already started */ if (!ast_test_flag(p, SIP_ALREADYGONE) && !ast_strlen_zero(p->initreq.data)) { - if (needcancel) { + if (needcancel) { /* Outgoing call, not up */ if (ast_test_flag(p, SIP_OUTGOING)) { transmit_request_with_auth(p, SIP_CANCEL, p->ocseq, 1, 0); /* Actually don't destroy us yet, wait for the 487 on our original @@ -2243,14 +2247,14 @@ update_user_counter(p, INC_IN_USE); } } - } else { + } else { /* Incoming call, not up */ char *res; if (ast->hangupcause && ((res = hangup_cause2sip(ast->hangupcause)))) { transmit_response_reliable(p, res, &p->initreq, 1); } else transmit_response_reliable(p, "403 Forbidden", &p->initreq, 1); } - } else { + } else { /* Call is in UP state, send BYE */ if (!p->pendinginvite) { /* Send a hangup */ transmit_request_with_auth(p, SIP_BYE, 0, 1, 1); @@ -3809,6 +3813,11 @@ } respprep(&resp, p, msg, req); add_header(&resp, "Content-Length", "0"); + /* 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->owner && p->owner->hangupcause) { + add_header(&resp, "X-asterisk-hangupcause:", ast_cause2str(p->owner->hangupcause)); + } add_blank_header(&resp); return send_response(p, &resp, reliable, seqno); } @@ -5010,14 +5019,20 @@ struct sip_request resp; reqprep(&resp, p, sipmethod, seqno, newbranch); - if (*p->realm) - { + if (*p->realm) { char digest[1024]; memset(digest, 0, sizeof(digest)); build_reply_digest(p, sipmethod, digest, sizeof(digest)); add_header(&resp, "Proxy-Authorization", digest); } + /* If we are hanging up and know a cause for that, send it in clear text to make + debugging easier. */ + if (sipmethod == SIP_BYE) { + if (p->owner && p->owner->hangupcause) { + add_header(&resp, "X-asterisk-hangupcause:", ast_cause2str(p->owner->hangupcause)); + } + } add_header(&resp, "Content-Length", "0"); add_blank_header(&resp);