--- chan_sip.c.dist 2004-05-09 19:40:49.000000000 -0400 +++ chan_sip.c.patched_3 2004-05-11 22:54:13.000000000 -0400 @@ -482,8 +482,27 @@ static int update_user_counter(struct sip_pvt *fup, int event); static void prune_peers(void); static int sip_do_reload(void); -static int sip_debug_test_addr(struct sockaddr_in *addr); -static int sip_debug_test_pvt(struct sip_pvt *p); + + +static inline int sip_debug_test_addr(struct sockaddr_in *addr) { + if (sipdebug == 0) + return 0; + /* See if we pass debug IP filter */ + if (debugaddr.sin_addr.s_addr) { + if (((ntohs(debugaddr.sin_port) != 0) + && (debugaddr.sin_port != addr->sin_port)) + || (debugaddr.sin_addr.s_addr != addr->sin_addr.s_addr)) + return 0; + } + return 1; +} + +static inline int sip_debug_test_pvt(struct sip_pvt *p) { + if (sipdebug == 0) + return 0; + return sip_debug_test_addr((p->nat ? &p->recv : &p->sa)); +} + static int __sip_xmit(struct sip_pvt *p, char *data, int len) { @@ -729,13 +748,15 @@ static int sip_sendtext(struct ast_channel *ast, char *text) { struct sip_pvt *p = ast->pvt->pvt; - if (sip_debug_test_pvt(p)) + int debug=sip_debug_test_pvt(p); + + if (debug) ast_verbose("Sending text %s on %s\n", text, ast->name); if (!p) return -1; if (!text || ast_strlen_zero(text)) return 0; - if (sip_debug_test_pvt(p)) + if (debug) ast_verbose("Really sending text %s on %s\n", text, ast->name); transmit_message_with_text(p, text); return 0; @@ -903,22 +924,6 @@ return(u); } -static int sip_debug_test_addr(struct sockaddr_in *addr) { - /* See if we pass debug IP filter */ - if (sipdebug == 0) return 0; - if (debugaddr.sin_addr.s_addr) { - if (((ntohs(debugaddr.sin_port) != 0) && - (debugaddr.sin_port != addr->sin_port)) || - (debugaddr.sin_addr.s_addr != addr->sin_addr.s_addr)) - return 0; - } - return 1; -} - -static int sip_debug_test_pvt(struct sip_pvt *p) { - return (sipdebug && sip_debug_test_addr((p->nat ? &p->recv : &p->sa))); -} - static int create_addr(struct sip_pvt *r, char *peer) { struct hostent *hp; @@ -1341,7 +1346,7 @@ struct sip_pvt *p = ast->pvt->pvt; int needcancel = 0; int needdestroy = 0; - if (option_debug) + if (option_debug || sipdebug) ast_log(LOG_DEBUG, "sip_hangup(%s)\n", ast->name); if (!ast->pvt->pvt) { ast_log(LOG_DEBUG, "Asked to hangup channel not connected\n"); @@ -1440,7 +1445,7 @@ } ast_setstate(ast, AST_STATE_UP); - if (option_debug) + if (option_debug || sipdebug) ast_log(LOG_DEBUG, "sip_answer(%s)\n", ast->name); res = transmit_response_with_sdp(p, "200 OK", &p->initreq, 1); } @@ -1899,7 +1904,7 @@ p->next = iflist; iflist = p; ast_mutex_unlock(&iflock); - if (option_debug) + if (option_debug || sipdebug) ast_log(LOG_DEBUG, "Allocating new SIP call for %s\n", callid); return p; } @@ -2182,6 +2187,7 @@ int iterator; int sendonly = 0; int x; + int debug=sip_debug_test_pvt(p); /* Get codec and RTP info from SDP */ if (strcasecmp(get_header(req, "Content-Type"), "application/sdp")) { @@ -2216,7 +2222,7 @@ ast_log(LOG_WARNING, "Error in codec string '%s'\n", codecs); return -1; } - if (sip_debug_test_pvt(p)) + if (debug) ast_verbose("Found RTP audio format %d\n", codec); ast_rtp_set_m_type(p->rtp, codec); codecs += len; @@ -2236,7 +2242,7 @@ ast_log(LOG_WARNING, "Error in codec string '%s'\n", codecs); return -1; } - if (sip_debug_test_pvt(p)) + if (debug) ast_verbose("Found video format %s\n", ast_getformatname(codec)); ast_rtp_set_m_type(p->vrtp, codec); codecs += len; @@ -2272,7 +2278,7 @@ sendonly=0; } if (sscanf(a, "rtpmap: %u %[^/]/", &codec, mimeSubtype) != 2) continue; - if (sip_debug_test_pvt(p)) + if (debug) ast_verbose("Found description format %s\n", mimeSubtype); /* Note: should really look at the 'freq' and '#chans' params too */ ast_rtp_set_rtpmap_type(p->rtp, codec, "audio", mimeSubtype); @@ -2289,7 +2295,7 @@ p->jointcapability = p->capability & (peercapability | vpeercapability); p->noncodeccapability = noncodeccapability & (peernoncodeccapability | vpeernoncodeccapability); - if (sip_debug_test_pvt(p)) { + if (debug) { ast_verbose("Capabilities: us - %d, them - %d/%d, combined - %d\n", p->capability, peercapability, vpeercapability, p->jointcapability); ast_verbose("Non-codec capabilities: us - %d, them - %d, combined - %d\n", @@ -2484,11 +2490,12 @@ int port, hn; struct hostent *hp; struct ast_hostent ahp; + int debug=sip_debug_test_pvt(p); /* Parse uri to h (host) and port - uri is already just the part inside the <> */ /* general form we are expecting is sip[s]:username[:password]@host[:port][;...] */ - if (sip_debug_test_pvt(p)) + if (debug) ast_verbose("set_destination: Parsing <%s> for address/port to send to\n", uri); /* Find and parse hostname */ @@ -2533,7 +2540,7 @@ p->sa.sin_family = AF_INET; memcpy(&p->sa.sin_addr, hp->h_addr, sizeof(p->sa.sin_addr)); p->sa.sin_port = htons(port); - if (sip_debug_test_pvt(p)) + if (debug) ast_verbose("set_destination: set destination to %s, port %d\n", inet_ntoa(p->sa.sin_addr), port); } @@ -2814,6 +2821,8 @@ int x; struct sockaddr_in dest; struct sockaddr_in vdest = { 0, }; + int debug=sip_debug_test_pvt(p); + /* XXX We break with the "recommendation" and send our IP, in order that our peer doesn't have to ast_gethostbyname() us XXX */ len = 0; @@ -2852,10 +2861,11 @@ vdest.sin_port = vsin.sin_port; } } - if (sip_debug_test_pvt(p)) + if (debug){ ast_verbose("We're at %s port %d\n", inet_ntoa(p->ourip), ntohs(sin.sin_port)); - if (sip_debug_test_pvt(p) && p->vrtp) - ast_verbose("Video is at %s port %d\n", inet_ntoa(p->ourip), ntohs(vsin.sin_port)); + if (p->vrtp) + ast_verbose("Video is at %s port %d\n", inet_ntoa(p->ourip), ntohs(vsin.sin_port)); + } snprintf(v, sizeof(v), "v=0\r\n"); snprintf(o, sizeof(o), "o=root %d %d IN IP4 %s\r\n", p->sessionid, p->sessionversion, inet_ntoa(dest.sin_addr)); snprintf(s, sizeof(s), "s=session\r\n"); @@ -2864,7 +2874,7 @@ snprintf(m, sizeof(m), "m=audio %d RTP/AVP", ntohs(dest.sin_port)); snprintf(m2, sizeof(m2), "m=video %d RTP/AVP", ntohs(vdest.sin_port)); if (p->jointcapability & p->prefcodec) { - if (sip_debug_test_pvt(p)) + if (debug) ast_verbose("Answering/Requesting with root capability %d\n", p->prefcodec); codec = ast_rtp_lookup_code(p->rtp, 1, p->prefcodec); if (codec > -1) { @@ -2885,7 +2895,7 @@ cur = prefs; while(cur) { if (p->jointcapability & cur->codec) { - if (sip_debug_test_pvt(p)) + if (debug) ast_verbose("Answering/Requesting with preferred capability %d\n", cur->codec); codec = ast_rtp_lookup_code(p->rtp, 1, cur->codec); if (codec > -1) { @@ -2907,7 +2917,7 @@ /* Now send any other common codecs, and non-codec formats: */ for (x = 1; x <= (videosupport ? AST_FORMAT_MAX_VIDEO : AST_FORMAT_MAX_AUDIO); x <<= 1) { if ((p->jointcapability & x) && !(alreadysent & x)) { - if (sip_debug_test_pvt(p)) + if (debug) ast_verbose("Answering with capability %d\n", x); codec = ast_rtp_lookup_code(p->rtp, 1, x); if (codec > -1) { @@ -2926,7 +2936,7 @@ } for (x = 1; x <= AST_RTP_MAX; x <<= 1) { if (p->noncodeccapability & x) { - if (sip_debug_test_pvt(p)) + if (debug) ast_verbose("Answering with non-codec capability %d\n", x); codec = ast_rtp_lookup_code(p->rtp, 0, x); if (codec > -1) { @@ -4001,7 +4011,7 @@ transmit_state_notify(p, state, 1); - if (option_debug) + if (option_debug || sipdebug) ast_verbose(VERBOSE_PREFIX_1 "Extension Changed %s new state %d for Notify User %s\n", exten, state, p->username); return 0; } @@ -4443,6 +4453,8 @@ int res = 0; char *t; char calleridname[50]; + int debug=sip_debug_test_addr(sin); + /* Terminate URI */ t = uri; while(*t && (*t > 32) && (*t != ';')) @@ -4518,10 +4530,10 @@ p->noncodeccapability &= ~AST_RTP_DTMF; } } - if (user && sip_debug_test_addr(sin)) + if (user && debug) ast_verbose("Found user '%s'\n", user->name); } else { - if (user && sip_debug_test_addr(sin)) + if (user && debug) ast_verbose("Found user '%s', but fails host access\n", user->name); user = NULL; } @@ -4536,7 +4548,7 @@ /* peer = find_peer(NULL, sin); */ ast_mutex_unlock(&peerl.lock); if (peer) { - if (sip_debug_test_addr(sin)) + if (debug) ast_verbose("Found peer '%s'\n", peer->name); /* Take the peer */ p->nat = peer->nat; @@ -4582,7 +4594,7 @@ free(peer); } } else - if (sip_debug_test_addr(sin)) + if (debug) ast_verbose("Found no matching peer or user for '%s:%d'\n", inet_ntoa(p->recv.sin_addr), ntohs(p->recv.sin_port)); } @@ -5845,6 +5857,8 @@ int res; int gotdest; struct ast_frame af = { AST_FRAME_NULL, }; + int debug = sip_debug_test_pvt(p); + /* Clear out potential response */ memset(&resp, 0, sizeof(resp)); /* Get Method and Cseq */ @@ -5943,7 +5957,7 @@ /* Process the SDP portion */ if (!ignore) { /* Use this as the basis */ - if (sip_debug_test_pvt(p)) + if (debug) ast_verbose("Using latest request as basis request\n"); /* This call is no longer outgoing if it ever was */ p->outgoing = 0; @@ -5959,7 +5973,7 @@ /* Queue NULL frame to prod ast_rtp_bridge if appropriate */ if (p->owner) ast_queue_frame(p->owner, &af); - } else if (sip_debug_test_pvt(p)) + } else if (debug) ast_verbose("Ignoring this request\n"); if (!p->lastinvite) { /* Handle authentication if this is our first invite */ @@ -6174,7 +6188,7 @@ transmit_response(p, "200 OK", req); } else if (!strcasecmp(cmd, "MESSAGE")) { if (!ignore) { - if (sip_debug_test_pvt(p)) + if (debug) ast_verbose("Receiving message!\n"); receive_message(p, req); } @@ -6182,13 +6196,13 @@ } else if (!strcasecmp(cmd, "SUBSCRIBE")) { if (!ignore) { /* Use this as the basis */ - if (sip_debug_test_pvt(p)) + if (debug) ast_verbose("Using latest SUBSCRIBE request as basis request\n"); /* This call is no longer outgoing if it ever was */ p->outgoing = 0; copy_request(&p->initreq, req); check_via(p, req); - } else if (sip_debug_test_pvt(p)) + } else if (debug) ast_verbose("Ignoring this request\n"); if (!p->lastinvite) { @@ -6246,14 +6260,14 @@ } } else if (!strcasecmp(cmd, "INFO")) { if (!ignore) { - if (sip_debug_test_pvt(p)) + if (debug) ast_verbose("Receiving DTMF!\n"); receive_info(p, req); } transmit_response(p, "200 OK", req); } else if (!strcasecmp(cmd, "REGISTER")) { /* Use this as the basis */ - if (sip_debug_test_pvt(p)) + if (debug) ast_verbose("Using latest request as basis request\n"); copy_request(&p->initreq, req); check_via(p, req); @@ -6310,14 +6324,15 @@ ast_log(LOG_WARNING, "Recv error: %s\n", strerror(errno)); return 1; } + int debug=sip_debug_test_addr(&sin); req.data[res] = '\0'; req.len = res; - if (sip_debug_test_addr(&sin)) + if (debug) ast_verbose("\n\nSip read: \n%s\n", req.data); if (pedanticsipchecking) req.len = lws2sws(req.data, req.len); parse(&req); - if (sip_debug_test_addr(&sin)) + if (debug) ast_verbose("%d headers, %d lines\n", req.headers, req.lines); if (req.headers < 2) { /* Must have at least two headers */