--- chan_sip.c 2004-05-17 16:42:44.000000000 -0400 +++ chan_sip.c_new2 2004-05-17 16:52:47.000000000 -0400 @@ -498,8 +498,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); + + +/*--- sip_debug_test_addr: See if we pass debug IP filter */ +static inline int sip_debug_test_addr(struct sockaddr_in *addr) { + 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 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)); +} + /*--- __sip_xmit: Transmit SIP message ---*/ static int __sip_xmit(struct sip_pvt *p, char *data, int len) @@ -822,13 +841,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; @@ -1003,22 +1024,6 @@ return(u); } -/*--- sip_debug_test_addr: See if we pass debug IP filter */ -static int sip_debug_test_addr(struct sockaddr_in *addr) { - 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))); -} - /*--- create_addr: create address structure from peer definition ---*/ /* Or, if peer not found, find it in the global DNS */ /* returns TRUE on failure, FALSE on success */ @@ -2350,6 +2355,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")) { @@ -2384,7 +2390,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; @@ -2404,7 +2410,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; @@ -2440,7 +2446,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); @@ -2457,7 +2463,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", @@ -2659,11 +2665,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 */ @@ -2708,7 +2715,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); } @@ -3003,6 +3010,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; @@ -3041,10 +3050,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"); @@ -3053,7 +3063,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) { @@ -3074,7 +3084,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) { @@ -3096,7 +3106,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) { @@ -3115,7 +3125,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) { @@ -4682,6 +4692,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 != ';')) @@ -4757,10 +4769,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; } @@ -4775,7 +4787,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; @@ -4821,7 +4833,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)); } @@ -6188,6 +6200,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 */ @@ -6286,7 +6300,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; @@ -6302,7 +6316,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 */ @@ -6533,7 +6547,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); } @@ -6541,13 +6555,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) { @@ -6605,14 +6619,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); @@ -6671,14 +6685,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 */