diff options
author | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2005-12-03 23:35:15 +0000 |
---|---|---|
committer | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2005-12-03 23:35:15 +0000 |
commit | 18c7099e31c5c72b3e8e87ab133d0bb4d4690525 (patch) | |
tree | 6e721fec1c580a14e5e583d304b537adb2f8e1d1 /channels | |
parent | 4f21a12d586becc90677159c269b560314c49c3f (diff) |
add the 'sip debug' options to the set of global flags and fix some compiler warnings
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@7319 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'channels')
-rw-r--r-- | channels/chan_sip.c | 104 |
1 files changed, 54 insertions, 50 deletions
diff --git a/channels/chan_sip.c b/channels/chan_sip.c index 7b97b5220..eb8b0b640 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -409,9 +409,6 @@ static struct in_addr __ourip; static struct sockaddr_in outboundproxyip; static int ourport; -#define SIP_DEBUG_CONFIG 1 << 0 -#define SIP_DEBUG_CONSOLE 1 << 1 -static int sipdebug = 0; static struct sockaddr_in debugaddr; static int tos = 0; @@ -571,11 +568,18 @@ struct sip_auth { #define SIP_PAGE2_RTAUTOCLEAR (1 << 2) #define SIP_PAGE2_IGNOREREGEXPIRE (1 << 3) #define SIP_PAGE2_RT_FROMCONTACT (1 << 4) +#define SIP_PAGE2_DEBUG (3 << 5) +#define SIP_PAGE2_DEBUG_CONFIG (1 << 5) +#define SIP_PAGE2_DEBUG_CONSOLE (1 << 6) /* SIP packet flags */ #define SIP_PKT_DEBUG (1 << 0) /*!< Debug this packet */ #define SIP_PKT_WITH_TOTAG (1 << 1) /*!< This packet has a to-tag */ +#define SIP_DEBUG ast_test_flag(&global_flags_page2, SIP_PAGE2_DEBUG) +#define SIP_DEBUG_CONFIG ast_test_flag(&global_flags_page2, SIP_PAGE2_DEBUG_CONFIG) +#define SIP_DEBUG_CONSOLE ast_test_flag(&global_flags_page2, SIP_PAGE2_DEBUG_CONSOLE) + static int global_rtautoclear = 120; /*! \brief sip_pvt: PVT structures are used for each SIP conversation, ie. a call */ @@ -991,7 +995,7 @@ unsigned int parse_sip_options(struct sip_pvt *pvt, char *supported) if (ast_strlen_zero(supported) ) return 0; - if (option_debug > 2 && sipdebug) + if (option_debug > 2 && SIP_DEBUG) ast_log(LOG_DEBUG, "Begin: parsing SIP \"Supported: %s\"\n", supported); next = temp; @@ -1003,18 +1007,18 @@ unsigned int parse_sip_options(struct sip_pvt *pvt, char *supported) } while (*next == ' ') /* Skip spaces */ next++; - if (option_debug > 2 && sipdebug) + if (option_debug > 2 && SIP_DEBUG) ast_log(LOG_DEBUG, "Found SIP option: -%s-\n", next); for (i=0; (i < (sizeof(sip_options) / sizeof(sip_options[0]))) && !res; i++) { if (!strcasecmp(next, sip_options[i].text)) { profile |= sip_options[i].id; res = 1; - if (option_debug > 2 && sipdebug) + if (option_debug > 2 && SIP_DEBUG) ast_log(LOG_DEBUG, "Matched SIP option: %s\n", next); } } if (!res) - if (option_debug > 2 && sipdebug) + if (option_debug > 2 && SIP_DEBUG) ast_log(LOG_DEBUG, "Found no match for SIP option: %s (Please file bug report!)\n", next); next = sep; } @@ -1029,7 +1033,7 @@ unsigned int parse_sip_options(struct sip_pvt *pvt, char *supported) /*! \brief 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) + if (!SIP_DEBUG) return 0; if (debugaddr.sin_addr.s_addr) { if (((ntohs(debugaddr.sin_port) != 0) @@ -1043,7 +1047,7 @@ static inline int sip_debug_test_addr(struct sockaddr_in *addr) /*! \brief sip_debug_test_pvt: Test PVT for debugging output */ static inline int sip_debug_test_pvt(struct sip_pvt *p) { - if (sipdebug == 0) + if (!SIP_DEBUG) return 0; return sip_debug_test_addr(((ast_test_flag(p, SIP_NAT) & SIP_NAT_ROUTE) ? &p->recv : &p->sa)); } @@ -1166,12 +1170,12 @@ static int retrans_pkt(void *data) pkt->retrans++; if (!pkt->timer_t1) { /* Re-schedule using timer_a and timer_t1 */ - if (sipdebug && option_debug > 3) + if (SIP_DEBUG && option_debug > 3) ast_log(LOG_DEBUG, "SIP TIMER: Not rescheduling id #%d:%s (Method %d) (No timer T1)\n", pkt->retransid, sip_methods[pkt->method].text, pkt->method); } else { int siptimer_a; - if (sipdebug && option_debug > 3) + if (SIP_DEBUG && option_debug > 3) ast_log(LOG_DEBUG, "SIP TIMER: Rescheduling retransmission #%d (%d) %s - %d\n", pkt->retransid, pkt->retrans, sip_methods[pkt->method].text, pkt->method); if (!pkt->timer_a) pkt->timer_a = 2 ; @@ -1204,10 +1208,8 @@ static int retrans_pkt(void *data) } /* Too many retries */ if (pkt->owner && pkt->method != SIP_OPTIONS) { - if (ast_test_flag(pkt, FLAG_FATAL) || sipdebug) /* Tell us if it's critical or if we're debugging */ - ast_log(LOG_WARNING, "Maximum retries exceeded on transmission %s for seqno %d (%s %s)\n", pkt->owner->callid, pkt->seqno, (ast_test_flag(pkt, FLAG_FATAL)) ? "Critical" : "Non-critical", (ast_test_flag(pkt, FLAG_RESPONSE)) ? "Response" : "Request"); - } else { - if (pkt->method == SIP_OPTIONS && sipdebug) + if (ast_test_flag(pkt, FLAG_FATAL) || SIP_DEBUG) /* Tell us if it's critical or if we're debugging */ ast_log(LOG_WARNING, "Maximum retries exceeded on transmission %s for seqno %d (%s %s)\n", pkt->owner->callid, pkt->seqno, (ast_test_flag(pkt, FLAG_FATAL)) ? "Critical" : "Non-critical", (ast_test_flag(pkt, FLAG_RESPONSE)) ? "Response" : "Request"); } else { + if ((pkt->method == SIP_OPTIONS) && SIP_DEBUG) ast_log(LOG_WARNING, "Cancelling retransmit of OPTIONs (call id %s) \n", pkt->owner->callid); } append_history(pkt->owner, "MaxRetries", (ast_test_flag(pkt, FLAG_FATAL)) ? "(Critical)" : "(Non-critical)"); @@ -1280,7 +1282,7 @@ static int __sip_reliable_xmit(struct sip_pvt *p, int seqno, int resp, char *dat /* Schedule retransmission */ pkt->retransid = ast_sched_add_variable(sched, siptimer_a, retrans_pkt, pkt, 1); - if (option_debug > 3 && sipdebug) + if (option_debug > 3 && SIP_DEBUG) ast_log(LOG_DEBUG, "*** SIP TIMER: Initalizing retransmit timer on packet: Id #%d\n", pkt->retransid); pkt->next = p->packets; p->packets = pkt; @@ -1374,7 +1376,7 @@ static int __sip_ack(struct sip_pvt *p, int seqno, int resp, int sipmethod) else p->packets = cur->next; if (cur->retransid > -1) { - if (sipdebug && option_debug > 3) + if (SIP_DEBUG && option_debug > 3) ast_log(LOG_DEBUG, "** SIP TIMER: Cancelling retransmit of packet (reply received) Retransid #%d\n", cur->retransid); ast_sched_del(sched, cur->retransid); } @@ -1429,7 +1431,7 @@ static int __sip_semi_ack(struct sip_pvt *p, int seqno, int resp, int sipmethod) (!strncasecmp(msg, cur->data, strlen(msg)) && (cur->data[strlen(msg)] < 33)))) { /* this is our baby */ if (cur->retransid > -1) { - if (option_debug > 3 && sipdebug) + if (option_debug > 3 && SIP_DEBUG) ast_log(LOG_DEBUG, "*** SIP TIMER: Cancelling retransmission #%d - %s (got response)\n", cur->retransid, msg); ast_sched_del(sched, cur->retransid); } @@ -2228,7 +2230,7 @@ static int update_call_counter(struct sip_pvt *fup, int event) } else { *inuse = 0; } - if (option_debug > 1 || sipdebug) { + if (option_debug > 1 || SIP_DEBUG) { ast_log(LOG_DEBUG, "Call %s %s '%s' removed from call limit %d\n", outgoing ? "to" : "from", u ? "user":"peer", name, *call_limit); } break; @@ -2244,7 +2246,7 @@ static int update_call_counter(struct sip_pvt *fup, int event) } } (*inuse)++; - if (option_debug > 1 || sipdebug) { + if (option_debug > 1 || SIP_DEBUG) { ast_log(LOG_DEBUG, "Call %s %s '%s' is %d out of %d\n", outgoing ? "to" : "from", u ? "user":"peer", name, *inuse, *call_limit); } break; @@ -2676,12 +2678,12 @@ static int sip_indicate(struct ast_channel *ast, int condition) res = -1; break; case AST_CONTROL_HOLD: /* The other part of the bridge are put on hold */ - if (sipdebug) + if (SIP_DEBUG) ast_log(LOG_DEBUG, "Bridged channel now on hold%s\n", p->callid); res = -1; break; case AST_CONTROL_UNHOLD: /* The other part of the bridge are back from hold */ - if (sipdebug) + if (SIP_DEBUG) ast_log(LOG_DEBUG, "Bridged channel is back from hold, let's talk! : %s\n", p->callid); res = -1; break; @@ -3313,7 +3315,7 @@ static void parse_request(struct sip_request *req) /* We've got a new header */ *c = 0; - if (sipdebug && option_debug > 3) + if (SIP_DEBUG && option_debug > 3) ast_log(LOG_DEBUG, "Header %d: %s (%d)\n", f, req->header[f], (int) strlen(req->header[f])); if (ast_strlen_zero(req->header[f])) { /* Line by itself means we're now in content */ @@ -3333,7 +3335,7 @@ static void parse_request(struct sip_request *req) } /* Check for last header */ if (!ast_strlen_zero(req->header[f])) { - if (sipdebug && option_debug > 3) + if (SIP_DEBUG && option_debug > 3) ast_log(LOG_DEBUG, "Header %d: %s (%d)\n", f, req->header[f], (int) strlen(req->header[f])); f++; } @@ -3345,7 +3347,7 @@ static void parse_request(struct sip_request *req) if (*c == '\n') { /* We've got a new line */ *c = 0; - if (sipdebug && option_debug > 3) + if (SIP_DEBUG && option_debug > 3) ast_log(LOG_DEBUG, "Line: %s (%d)\n", req->line[f], (int) strlen(req->line[f])); if (f >= SIP_MAX_LINES - 1) { ast_log(LOG_WARNING, "Too many SDP lines. Ignoring.\n"); @@ -4578,7 +4580,7 @@ static int transmit_reinvite_with_sdp(struct sip_pvt *p) reqprep(&req, p, SIP_INVITE, 0, 1); add_header(&req, "Allow", ALLOWED_METHODS); - if (sipdebug) + if (SIP_DEBUG) add_header(&req, "X-asterisk-info", "SIP re-invite (RTP bridge)"); ast_rtp_offered_from_local(p->rtp, 1); add_sdp(&req, p); @@ -4879,11 +4881,11 @@ static int transmit_invite(struct sip_pvt *p, int sipmethod, int sdp, int init) add_header(&req, "Allow", ALLOWED_METHODS); if (p->options && p->options->addsipheaders ) { struct ast_channel *ast; - char *header = (char *) NULL; + const char *header = (char *) NULL; char *content = (char *) NULL; char *end = (char *) NULL; struct varshead *headp = (struct varshead *) NULL; - struct ast_var_t *current; + const struct ast_var_t *current; ast = p->owner; /* The owner channel */ if (ast) { @@ -4912,7 +4914,7 @@ static int transmit_invite(struct sip_pvt *p, int sipmethod, int sdp, int init) *end = '\0'; add_header(&req, headdup, content); - if (sipdebug) + if (SIP_DEBUG) ast_log(LOG_DEBUG, "Adding SIP Header \"%s\" with content :%s: \n", headdup, content); } } @@ -5233,7 +5235,7 @@ static int sip_reregister(void *data) } /* Since registry's are only added/removed by the the monitor thread, this may be overkill to reference/dereference at all here */ - if (sipdebug) + if (SIP_DEBUG) ast_log(LOG_NOTICE, " -- Re-registration for %s@%s\n", r->username, r->hostname); r->expire = -1; @@ -5447,7 +5449,7 @@ static int transmit_register(struct sip_registry *r, int sipmethod, char *auth, char digest[1024]; /* We have auth data to reuse, build a digest header! */ - if (sipdebug) + if (SIP_DEBUG) ast_log(LOG_DEBUG, " >>> Re-using Auth data for %s@%s\n", r->username, r->hostname); ast_copy_string(p->realm, r->realm, sizeof(p->realm)); ast_copy_string(p->nonce, r->nonce, sizeof(p->nonce)); @@ -6271,13 +6273,13 @@ static int check_auth(struct sip_pvt *p, struct sip_request *req, char *randdata snprintf(randdata, randlen, "%08x", thread_safe_rand()); if (ua_hash && !strncasecmp(ua_hash, resp_hash, strlen(resp_hash))) { - if (sipdebug) + if (SIP_DEBUG) ast_log(LOG_NOTICE, "stale nonce received from '%s'\n", get_header(req, "To")); /* We got working auth token, based on stale nonce . */ transmit_response_with_auth(p, response, req, randdata, reliable, respheader, 1); } else { /* Everything was wrong, so give the device one more try with a new challenge */ - if (sipdebug) + if (SIP_DEBUG) ast_log(LOG_NOTICE, "Bad authentication received from '%s'\n", get_header(req, "To")); transmit_response_with_auth(p, response, req, randdata, reliable, respheader, 0); } @@ -8616,7 +8618,7 @@ static void handle_request_info(struct sip_pvt *p, struct sip_request *req) /* send a FLASH event */ struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_FLASH, }; ast_queue_frame(p->owner, &f); - if (sipdebug) + if (SIP_DEBUG) ast_verbose("* DTMF-relay event received: FLASH\n"); } else { /* send a DTMF event */ @@ -8631,7 +8633,7 @@ static void handle_request_info(struct sip_pvt *p, struct sip_request *req) f.subclass = 'A' + (event - 12); } ast_queue_frame(p->owner, &f); - if (sipdebug) + if (SIP_DEBUG) ast_verbose("* DTMF-relay event received: %c\n", f.subclass); } transmit_response(p, "200 OK", req); @@ -8692,7 +8694,9 @@ static int sip_do_debug_ip(int fd, int argc, char *argv[]) ast_cli(fd, "SIP Debugging Enabled for IP: %s\n", ast_inet_ntoa(iabuf, sizeof(iabuf), debugaddr.sin_addr)); else ast_cli(fd, "SIP Debugging Enabled for IP: %s:%d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), debugaddr.sin_addr), port); - sipdebug |= SIP_DEBUG_CONSOLE; + + ast_set_flag(&global_flags_page2, SIP_PAGE2_DEBUG_CONSOLE); + return RESULT_SUCCESS; } @@ -8710,7 +8714,7 @@ static int sip_do_debug_peer(int fd, int argc, char *argv[]) memcpy(&debugaddr.sin_addr, &peer->addr.sin_addr, sizeof(debugaddr.sin_addr)); debugaddr.sin_port = peer->addr.sin_port; ast_cli(fd, "SIP Debugging Enabled for IP: %s:%d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), debugaddr.sin_addr), ntohs(debugaddr.sin_port)); - sipdebug |= SIP_DEBUG_CONSOLE; + ast_set_flag(&global_flags_page2, SIP_PAGE2_DEBUG_CONSOLE); } else ast_cli(fd, "Unable to get IP address of peer '%s'\n", argv[3]); ASTOBJ_UNREF(peer,sip_destroy_peer); @@ -8722,7 +8726,7 @@ static int sip_do_debug_peer(int fd, int argc, char *argv[]) /*! \brief sip_do_debug: Turn on SIP debugging (CLI command) */ static int sip_do_debug(int fd, int argc, char *argv[]) { - int oldsipdebug = sipdebug & SIP_DEBUG_CONSOLE; + int oldsipdebug = SIP_DEBUG_CONSOLE; if (argc != 2) { if (argc != 4) return RESULT_SHOWUSAGE; @@ -8732,7 +8736,7 @@ static int sip_do_debug(int fd, int argc, char *argv[]) return sip_do_debug_peer(fd, argc, argv); else return RESULT_SHOWUSAGE; } - sipdebug |= SIP_DEBUG_CONSOLE; + ast_set_flag(&global_flags_page2, SIP_PAGE2_DEBUG_CONSOLE); memset(&debugaddr, 0, sizeof(debugaddr)); if (oldsipdebug) ast_cli(fd, "SIP Debugging re-enabled\n"); @@ -8826,7 +8830,7 @@ static int sip_no_debug(int fd, int argc, char *argv[]) { if (argc != 3) return RESULT_SHOWUSAGE; - sipdebug &= ~SIP_DEBUG_CONSOLE; + ast_clear_flag(&global_flags_page2, SIP_PAGE2_DEBUG_CONSOLE); ast_cli(fd, "SIP Debugging Disabled\n"); return RESULT_SUCCESS; } @@ -8995,7 +8999,7 @@ static int build_reply_digest(struct sip_pvt *p, int method, char* digest, int d username = auth->username; secret = auth->secret; md5secret = auth->md5secret; - if (sipdebug) + if (SIP_DEBUG) ast_log(LOG_DEBUG,"Using realm %s authentication for call %s\n", p->realm, p->callid); } else { /* No authentication, use peer or register= config */ @@ -9657,7 +9661,7 @@ static int handle_response_register(struct sip_pvt *p, int resp, char *rest, str expires_ms -= MAX((expires_ms * EXPIRY_GUARD_PCT),EXPIRY_GUARD_MIN); else expires_ms -= EXPIRY_GUARD_SECS * 1000; - if (sipdebug) + if (SIP_DEBUG) ast_log(LOG_NOTICE, "Outbound Registration: Expiry for %s is %d sec (Scheduling reregistration in %d s)\n", r->hostname, expires, expires_ms/1000); r->refresh= (int) expires_ms / 1000; @@ -10372,7 +10376,7 @@ static int handle_request_invite(struct sip_pvt *p, struct sip_request *req, int } } else { - if (option_debug > 1 && sipdebug) + if (option_debug > 1 && SIP_DEBUG) ast_log(LOG_DEBUG, "Got a SIP re-invite for call %s\n", p->callid); c = p->owner; } @@ -10780,7 +10784,7 @@ static int handle_request_subscribe(struct sip_pvt *p, struct sip_request *req, if (p->expiry > max_expiry) p->expiry = max_expiry; } - if (sipdebug || option_debug > 1) + if (SIP_DEBUG || option_debug > 1) ast_log(LOG_DEBUG, "Adding subscription for extension %s context %s for peer %s\n", p->exten, p->context, p->username); if (p->autokillid > -1) sip_cancel_destroy(p); /* Remove subscription expiry for renewals */ @@ -11355,7 +11359,7 @@ static int sip_poke_peer(struct sip_peer *peer) return 0; } if (peer->call > 0) { - if (sipdebug) + if (SIP_DEBUG) ast_log(LOG_NOTICE, "Still have a QUALIFY dialog active, deleting\n"); sip_destroy(peer->call); } @@ -11682,7 +11686,7 @@ static int add_sip_domain(const char *domain, const enum domain_mode mode, const AST_LIST_INSERT_TAIL(&domain_list, d, list); AST_LIST_UNLOCK(&domain_list); - if (sipdebug) + if (SIP_DEBUG) ast_log(LOG_DEBUG, "Added local SIP domain '%s'\n", domain); return 1; @@ -12252,7 +12256,7 @@ static int reload_config(void) memset(&localaddr, 0, sizeof(localaddr)); memset(&externip, 0, sizeof(externip)); memset(&prefs, 0 , sizeof(prefs)); - sipdebug &= ~SIP_DEBUG_CONFIG; + ast_clear_flag(&global_flags_page2, SIP_PAGE2_DEBUG_CONFIG); /* Initialize some reasonable defaults at SIP reload */ ast_copy_string(default_context, DEFAULT_CONTEXT, sizeof(default_context)); @@ -12400,7 +12404,7 @@ static int reload_config(void) default_expiry = DEFAULT_DEFAULT_EXPIRY; } else if (!strcasecmp(v->name, "sipdebug")) { if (ast_true(v->value)) - sipdebug |= SIP_DEBUG_CONFIG; + ast_set_flag(&global_flags_page2, SIP_PAGE2_DEBUG_CONFIG); } else if (!strcasecmp(v->name, "dumphistory")) { dumphistory = ast_true(v->value); } else if (!strcasecmp(v->name, "recordhistory")) { @@ -12770,7 +12774,7 @@ static int sip_addheader(struct ast_channel *chan, void *data) int arglen; int no = 0; int ok = 0; - char *content = (char *) NULL; + const char *content = (char *) NULL; char varbuf[128]; arglen = strlen(data); @@ -12791,7 +12795,7 @@ static int sip_addheader(struct ast_channel *chan, void *data) } if (ok) { pbx_builtin_setvar_helper (chan, varbuf, data); - if (sipdebug) + if (SIP_DEBUG) ast_log(LOG_DEBUG,"SIP Header added \"%s\" as %s\n", (char *) data, varbuf); } else { ast_log(LOG_WARNING, "Too many SIP headers added, max 50\n"); |