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;
#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 */
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;
}
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;
}
/*! \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)
/*! \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));
}
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 ;
}
/* 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)");
/* 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;
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);
}
(!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);
}
} 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;
}
}
(*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;
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;
/* 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 */
}
/* 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++;
}
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");
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);
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) {
*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);
}
}
}
/* 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;
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));
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);
}
/* 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 */
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);
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;
}
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);
/*! \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;
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");
{
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;
}
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 */
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;
}
} 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;
}
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 */
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);
}
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;
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));
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")) {
int arglen;
int no = 0;
int ok = 0;
- char *content = (char *) NULL;
+ const char *content = (char *) NULL;
char varbuf[128];
arglen = strlen(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");