232 #include <inttypes.h> 277 #include "sip/include/dialplan_functions.h" 684 .resync_threshold = 1000,
720 {
NONE,
"-",
"unknown",
"unknown" },
722 {
DIALOG_INFO_XML,
"dialog",
"application/dialog-info+xml",
"dialog-info+xml" },
723 {
CPIM_PIDF_XML,
"presence",
"application/cpim-pidf+xml",
"cpim-pidf+xml" },
724 {
PIDF_XML,
"presence",
"application/pidf+xml",
"pidf+xml" },
725 {
XPIDF_XML,
"presence",
"application/xpidf+xml",
"xpidf+xml" },
726 {
MWI_NOTIFICATION,
"message-summary",
"application/simple-message-summary",
"mwi" }
813 #define SIP_PEDANTIC_DECODE(str) \ 814 if (sip_cfg.pedanticsipchecking && !ast_strlen_zero(str)) { \ 815 ast_uri_decode(str, ast_uri_sip_user); \ 948 static const struct {
958 static const struct {
1044 #define sip_pvt_lock(x) ao2_lock(x) 1045 #define sip_pvt_trylock(x) ao2_trylock(x) 1046 #define sip_pvt_unlock(x) ao2_unlock(x) 1058 #define BOGUS_PEER_MD5SECRET "intentionally_invalid_md5_string" 1076 #define SIP_TRANSPORT_STR_BUFSIZE 128 1157 #define UNLINK(element, head, prev) do { \ 1159 (prev)->next = (element)->next; \ 1161 (head) = (element)->next; \ 1239 const char *
file,
int line,
const char *func);
1240 #define find_call(req, addr, intended_method) \ 1241 __find_call(req, addr, intended_method, __FILE__, __LINE__, __PRETTY_FUNCTION__) 1279 int debug,
int *min_packet_size,
int *max_packet_size);
1291 const char *secret,
const char *md5secret,
int sipmethod,
1337 #define peer_in_destruction(peer) (ao2_ref(peer, 0) == 0) 1389 const char *
name,
int flag,
unsigned int transport);
1448 static const char *
find_alias(
const char *
name,
const char *_default);
1551 static int parse_minse(
const char *p_hdrval,
int *
const p_interval);
1575 .description =
"Session Initiation Protocol (SIP)",
1673 .name =
"call-completion",
1701 if (!(epa_entry =
ao2_t_alloc(
sizeof(*epa_entry), static_data->
destructor,
"Allocate new EPA entry"))) {
1801 expires_ms = expires * 1000;
1843 const char *uri = arg;
1858 const char *uri = arg;
1873 struct sip_pvt *call_pvt = arg;
2025 return monitor_instance->
core_id;
2049 ao2_t_ref(monitor_instance->
suspension_entry, -1,
"Decrementing suspension entry refcount in sip_monitor_instance_destructor");
2058 if (!monitor_instance) {
2063 ao2_ref(monitor_instance, -1);
2071 ao2_link(sip_monitor_instances, monitor_instance);
2072 return monitor_instance;
2108 if (!monitor_instance) {
2129 ao2_t_ref(monitor, +1,
"Adding a ref to the monitor for the scheduler");
2144 ast_str_append(&body, 0,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
2151 ast_str_append(&body, 0,
"<presence xmlns=\"urn:ietf:params:xml:ns:pidf\" entity=\"%s\">\n", presentity);
2153 ast_str_append(&body, 0,
"<status><basic>%s</basic></status>\n", state ==
CC_OPEN ?
"open" :
"closed");
2166 if (!monitor_instance) {
2174 ao2_ref(monitor_instance, -1);
2177 if (!(cc_entry =
ast_calloc(1,
sizeof(*cc_entry)))) {
2178 ast_log(
LOG_WARNING,
"Unable to allocate space for instance data of EPA entry for call-completion\n");
2179 ao2_ref(monitor_instance, -1);
2216 if (!monitor_instance) {
2237 if (*sched_id != -1) {
2239 ao2_t_ref(monitor, -1,
"Removing scheduler's reference to the monitor");
2247 ao2_unlink(sip_monitor_instances, monitor_instance);
2257 static const char cc_purpose[] =
"purpose=call-completion";
2258 static const int cc_purpose_len =
sizeof(cc_purpose) - 1;
2265 uri =
strsep(&call_info,
";");
2267 while ((purpose =
strsep(&call_info,
";"))) {
2268 if (!strncmp(purpose, cc_purpose, cc_purpose_len)) {
2278 while ((service_str =
strsep(&call_info,
";"))) {
2279 if (!strncmp(service_str,
"m=", 2)) {
2292 strsep(&service_str,
"=");
2363 ao2_ref(monitor_instance, -1);
2388 .name =
"SIP TCP server",
2399 .name =
"SIP TLS server",
2406 #define append_history(p, event, fmt , args... ) append_history_full(p, "%-15s " fmt, event, ## args) 2415 for (cur = table; cur->
s; cur++) {
2430 for (cur = table; cur->
s; cur++) {
2431 if (!strcasecmp(cur->
s, s)) {
2461 && !strchr(
"-.!%*_+`'~", *str)) {
2481 code = reason->
code;
2498 #define check_request_transport(peer, tmpl) ({ \ 2500 if (peer->socket.type == tmpl->socket.type) \ 2502 else if (!(peer->transports & tmpl->socket.type)) {\ 2503 ast_log(LOG_ERROR, \ 2504 "'%s' is not a valid transport for '%s'. we only use '%s'! ending call.\n", \ 2505 sip_get_transport(tmpl->socket.type), peer->name, get_transport_list(peer->transports) \ 2508 } else if (peer->socket.type & AST_TRANSPORT_TLS) { \ 2509 ast_log(LOG_WARNING, \ 2510 "peer '%s' HAS NOT USED (OR SWITCHED TO) TLS in favor of '%s' (but this was allowed in sip.conf)!\n", \ 2511 peer->name, sip_get_transport(tmpl->socket.type) \ 2515 "peer '%s' has contacted us over %s even though we prefer %s.\n", \ 2516 peer->name, sip_get_transport(tmpl->socket.type), sip_get_transport(peer->socket.type) \ 2529 for (v = src ; v ; v = v->
next) {
2575 ao2_t_ref(packet, -1,
"thread destruction, removing packet from frame queue");
2595 ao2_t_ref(th, -1,
"Failed to open alert pipe on sip_threadinfo");
2596 ast_log(
LOG_ERROR,
"Could not create sip alert pipe in tcptls thread, error %s\n", strerror(
errno));
2599 ao2_t_ref(tcptls_session, +1,
"tcptls_session ref for sip_threadinfo object");
2602 ao2_t_link(threadt, th,
"Adding new tcptls helper thread");
2603 ao2_t_ref(th, -1,
"Decrementing threadinfo ref from alloc, only table ref remains");
2614 .tcptls_session = tcptls_session,
2618 if (!tcptls_session) {
2624 if (!tcptls_session->
stream ||
2627 goto tcptls_write_setup_error;
2630 if (!(th =
ao2_t_find(threadt, &tmp,
OBJ_POINTER,
"ao2_find, getting sip_threadinfo in tcp helper thread"))) {
2632 goto tcptls_write_setup_error;
2643 if (write(th->
alert_pipe[1], &alert,
sizeof(alert)) == -1) {
2645 ao2_t_ref(packet, -1,
"could not write to alert pipe, remove packet");
2654 ao2_t_ref(th, -1,
"In sip_tcptls_write, unref threadinfo object after finding it");
2657 tcptls_write_setup_error:
2659 ao2_t_ref(th, -1,
"In sip_tcptls_write, unref threadinfo obj, could not create packet");
2662 ao2_t_ref(packet, -1,
"could not allocate packet's data");
2692 uint64_t payload_len;
2703 char data[payload_len + 1];
2709 strncpy(data, payload, payload_len);
2710 data[payload_len] =
'\0';
2744 if(time(&now) == -1) {
2791 char *content_length_str;
2792 int content_length = -1;
2810 if ((content_length_str =
strcasestr(msg,
"\nContent-Length:"))) {
2811 content_length_str +=
sizeof(
"\nContent-Length:") - 1;
2812 }
else if ((content_length_str =
strcasestr(msg,
"\nl:"))) {
2813 content_length_str +=
sizeof(
"\nl:") - 1;
2824 if (!strchr(content_length_str,
'\n')) {
2828 if (sscanf(content_length_str,
"%30d", &content_length) != 1) {
2829 content_length = -1;
2834 return content_length;
2862 body = strstr(message,
"\r\n\r\n");
2869 body +=
sizeof(
"\r\n\r\n") - 1;
2870 body_len = message_len - (body - message);
2876 if (content_length < 0) {
2878 }
else if (content_length == 0) {
2883 if (body_len == 0) {
2894 if (body_len < content_length) {
2897 }
else if (body_len > content_length) {
2919 int authenticated, time_t start)
2930 if (!tcptls_session->
client && !authenticated) {
2936 ast_debug(2,
"SIP TCP/TLS server timed out\n");
2944 ast_debug(2,
"SIP TCP/TLS server :: ast_wait_for_input returned %d\n", res);
2946 }
else if (res == 0) {
2947 ast_debug(2,
"SIP TCP/TLS server timed out\n");
2956 ast_debug(2,
"SIP TCP/TLS server error when receiving data\n");
2958 }
else if (res == 0) {
2959 ast_debug(2,
"SIP TCP/TLS server has shut down\n");
2962 readbuf[res] =
'\0';
2971 ast_log(
LOG_WARNING,
"Rejecting TCP/TLS packet from '%s' because way too large: %zu\n",
2987 int res,
timeout = -1, authenticated = 0, flags;
2989 struct sip_request req = { 0, } , reqcpy = { 0, };
2991 char buf[1024] =
"";
2992 struct pollfd fds[2] = { { 0 }, { 0 }, };
3006 if (!tcptls_session->
client) {
3017 ao2_t_ref(me, +1,
"Adding threadinfo ref for tcp_helper_thread");
3020 .tcptls_session = tcptls_session,
3023 if ((!(ca = tcptls_session->
parent)) ||
3024 (!(me =
ao2_t_find(threadt, &tmp,
OBJ_POINTER,
"ao2_find, getting sip_threadinfo in tcp helper thread")))) {
3046 fds[0].events = fds[1].events = POLLIN | POLLPRI;
3055 if(time(&start) == -1) {
3079 if (!tcptls_session->
client && !authenticated ) {
3097 }
else if (res == 0) {
3112 str_save = req.
data;
3113 memset(&req, 0,
sizeof(req));
3114 req.
data = str_save;
3117 str_save = reqcpy.data;
3118 memset(&reqcpy, 0,
sizeof(reqcpy));
3119 reqcpy.data = str_save;
3122 memset(buf, 0,
sizeof(buf));
3141 if (fds[1].revents) {
3147 if (read(me->
alert_pipe[0], &alert,
sizeof(alert)) == -1) {
3158 ast_log(
LOG_WARNING,
"TCPTLS thread alert_pipe indicated packet should be sent, but frame_q is empty\n");
3166 ao2_t_ref(packet, -1,
"tcptls packet sent, this is no longer needed");
3181 if (tcptls_session && !tcptls_session->
client && !authenticated) {
3186 ao2_t_unlink(threadt, me,
"Removing tcptls helper thread, thread is closing");
3187 ao2_t_ref(me, -1,
"Removing tcp_helper_threads threadinfo ref");
3194 ao2_t_ref(ca, -1,
"closing tcptls thread, getting rid of client tcptls_session arguments");
3197 if (tcptls_session) {
3204 tcptls_session =
NULL;
3215 if (peer->
expire != -1) {
3314 while ((cp = dialog->
packets)) {
3318 ao2_t_ref(cp, -1,
"Stop scheduled packet retransmission"));
3319 ao2_t_ref(cp, -1,
"Packet retransmission list");
3336 dialog_unref(dialog,
"Stop scheduled request_queue_sched_id"));
3339 dialog_unref(dialog,
"Stop scheduled provisional keepalive"));
3353 struct sip_pvt *dialog = (
void *) data;
3356 dialog_unref(dialog,
"Stop scheduled items for unlink action");
3371 dialog_ref(dialog,
"Let's bump the count in the unlink so it doesn't accidentally become dead before we are done");
3373 ao2_t_unlink(dialogs, dialog,
"unlinking dialog via ao2_unlink");
3374 ao2_t_unlink(dialogs_needdestroy, dialog,
"unlinking dialog_needdestroy via ao2_unlink");
3375 ao2_t_unlink(dialogs_rtpcheck, dialog,
"unlinking dialog_rtpcheck via ao2_unlink");
3406 dialog_ref(dialog,
"Stop scheduled items for unlink action");
3412 dialog_unref(dialog,
"Failed to schedule stop scheduled items for unlink action");
3416 dialog_unref(dialog,
"Let's unbump the count in the unlink so the poor pvt can disappear if it is time");
3420 __attribute__((
format(printf, 2, 3)));
3426 return map_x_s(referstatusstrings, rstatus,
"");
3434 append_history(pvt,
"NeedDestroy",
"Setting needdestroy because %s", reason);
3437 ao2_t_link(dialogs_needdestroy, pvt,
"link pvt into dialogs_needdestroy container");
3447 ast_debug(1,
"Initializing already initialized SIP dialog %s (presumably reinvite)\n", p->
callid);
3462 ast_debug(3,
"Setting SIP_ALREADYGONE on dialog %s\n", dialog->
callid);
3493 char *mutable_proxy, *sep, *
name;
3507 sep = strchr(mutable_proxy,
',');
3522 dest->
name[0] =
'\0';
3540 int port = standard;
3541 if (
ast_strlen_zero(pt) || (sscanf(pt,
"%30d", &port) != 1) || (port < 1) || (port > 65535)) {
3553 ast_debug(1,
"OBPROXY: Applying dialplan set OBproxy to this call\n");
3560 ast_debug(1,
"OBPROXY: Applying peer OBproxy to this call\n");
3567 ast_debug(1,
"OBPROXY: Applying global OBproxy to this call\n");
3573 ast_debug(1,
"OBPROXY: Not applying OBproxy to this call\n");
3587 int l_name = name ? strlen(name) : 0;
3589 return (l_name >= len && name && name[len] < 33 &&
3666 if (!strcasecmp(transport,
"udp")) {
3669 if (!strcasecmp(transport,
"tcp")) {
3672 if (!strcasecmp(transport,
"tls")) {
3675 if (!strcasecmp(transport,
"ws")) {
3678 if (!strcasecmp(transport,
"wss")) {
3718 buf[strlen(buf) - 1] = 0;
3825 ast_debug(2,
"Socket type is TCP but no tcptls_session is present to write to\n");
3853 snprintf(p->
via,
sizeof(p->
via),
"SIP/2.0/%s %s;branch=z9hG4bK%08x%s",
3856 (
unsigned)p->
branch, rport);
3892 "but we're using IPv6, which doesn't need it. Please " 3893 "remove \"localnet\" and/or \"externaddr\" settings.\n");
3896 want_remap = localaddr &&
3944 ast_debug(1,
"Target address %s is not local, substituting externaddr\n",
3992 vsnprintf(buf,
sizeof(buf), fmt, ap);
3994 l = strlen(buf) + 1;
3995 if (!(hist =
ast_calloc(1,
sizeof(*hist) + l))) {
3998 if (!p->history && !(p->history =
ast_calloc(1,
sizeof(*p->history)))) {
4002 memcpy(hist->
event, buf, l);
4006 p->history_entries--;
4010 p->history_entries++;
4066 ast_debug(4,
"SIP TIMER: Not rescheduling id #%d:%s (Method %d) (No timer T1)\n",
4075 ast_debug(4,
"SIP TIMER: Rescheduling retransmission #%d (%d) %s - %d\n",
4101 reschedule = siptimer_a;
4102 ast_debug(4,
"** SIP timers: Rescheduling retransmission %d to %d ms (t1 %d ms (Retrans id #%d)) \n",
4112 ast_verbose(
"Retransmitting #%d (%s) to %s:\n%s\n---\n",
4127 if (reschedule >= diff) {
4143 ast_log(
LOG_WARNING,
"Retransmission timeout reached on transmission %s for seqno %u (%s %s) -- See https://wiki.asterisk.org/wiki/display/AST/SIP+Retransmissions\n" 4144 "Packet timed out after %dms with no response\n",
4147 pkt->
is_fatal ?
"Critical" :
"Non-critical",
4148 pkt->
is_resp ?
"Response" :
"Request",
4152 ast_log(
LOG_WARNING,
"Cancelling retransmit of OPTIONs (call id %s) -- See https://wiki.asterisk.org/wiki/display/AST/SIP+Retransmissions\n", pkt->
owner->
callid);
4167 ast_log(
LOG_WARNING,
"Hanging up call %s - no reply to our critical packet (see https://wiki.asterisk.org/wiki/display/AST/SIP+Retransmissions).\n", pkt->
owner->
callid);
4216 append_history(pkt->
owner,
"ByeFailure",
"Remote peer doesn't respond to bye. Destroying call anyway.");
4225 ao2_t_ref(pkt, -1,
"Packet retransmission list (retransmission complete)");
4236 ao2_t_ref(pkt, -1,
"Scheduled packet retransmission complete");
4243 struct sip_pkt *pkt = (
void *) data;
4246 ao2_t_ref(pkt, -1,
"Stop scheduled packet retransmission"));
4247 ao2_t_ref(pkt, -1,
"Stop packet retransmission action");
4253 ao2_t_ref(pkt, +1,
"Stop packet retransmission action");
4256 ao2_t_ref(pkt, -1,
"Failed to schedule stop packet retransmission action");
4262 struct sip_pkt *pkt = (
void *) vdoomed;
4294 ao2_t_ref(pkt, -1,
"Failed to initialize");
4303 pkt->
owner =
dialog_ref(p,
"__sip_reliable_xmit: setting pkt->owner");
4331 ao2_t_ref(pkt, +1,
"Schedule packet retransmission");
4334 ao2_t_ref(pkt, -1,
"Failed to schedule packet retransmission");
4338 ast_debug(4,
"*** SIP TIMER: Initializing retransmit timer on packet: Id #%d\n", pkt->
retransid);
4345 ast_log(
LOG_ERROR,
"Serious Network Trouble; __sip_xmit returns error for pkt data\n");
4350 ao2_t_ref(pkt, -1,
"Packet retransmission list");
4383 ast_debug(3,
"Re-scheduled destruction of SIP subscription %s\n", p->
callid ? p->
callid :
"<unknown>");
4390 char method_str[31];
4394 if (sscanf(p->
lastmsg,
"Tx: %30s", method_str) == 1 || sscanf(p->
lastmsg,
"Rx: %30s", method_str) == 1) {
4412 "Autodestruct on dialog '%s' with owner %s in place (Method: %s). Rescheduling destruction for 10000 ms\n",
4425 ast_debug(3,
"Finally hanging up channel after transfer: %s\n", p->
callid);
4455 struct sip_pvt *pvt = (
void *) data;
4473 dialog_unref(pvt,
"Failed to schedule cancel destroy action");
4488 int ms = sched_data->
ms;
4528 ast_verbose(
"Scheduling destruction of SIP dialog '%s' in %d ms (Method: %s)\n",
4532 sched_data =
ast_malloc(
sizeof(*sched_data));
4537 sched_data->
pvt = p;
4538 sched_data->
ms = ms;
4573 const char *msg =
"Not Found";
4585 for (cur = p->
packets; cur; prev = cur, cur = cur->
next) {
4598 ast_debug(4,
"** SIP TIMER: Cancelling retransmit of packet (reply received) Retransid #%d\n", cur->
retransid);
4604 ao2_t_ref(cur, -1,
"Packet retransmission list");
4608 ast_debug(1,
"Stopping retransmission on '%s' of %s %u: Match %s\n",
4609 p->
callid, resp ?
"Response" :
"Request", seqno, msg);
4650 ast_debug(1,
"(Provisional) Stopping retransmission (but retaining packet) on '%s' %s %u: %s\n", p->
callid, resp ?
"Response" :
"Request", seqno, res == -1 ?
"Not Found" :
"Found");
4674 const char *msg =
NULL;
4681 msg =
"183 Session Progress";
4702 dialog_unref(pvt,
"Schedule provisional keepalive complete");
4718 struct sip_pvt *pvt = (
void *) data;
4727 dialog_unref(pvt,
"Stop scheduled provisional keepalive for update"));
4732 dialog_ref(pvt,
"Schedule provisional keepalive");
4737 dialog_unref(pvt,
"Failed to schedule provisional keepalive");
4742 dialog_unref(pvt,
"Update provisional keepalive action");
4749 struct sip_pvt *pvt = (
void *) data;
4757 struct sip_pvt *pvt = (
void *) data;
4764 dialog_ref(pvt,
"Update provisional keepalive action");
4768 dialog_unref(pvt,
"Failed to schedule update provisional keepalive action");
4775 struct sip_pvt *pvt = (
void *) data;
4778 dialog_unref(pvt,
"Stop scheduled provisional keepalive"));
4779 dialog_unref(pvt,
"Stop provisional keepalive action");
4785 dialog_ref(pvt,
"Stop provisional keepalive action");
4788 dialog_unref(pvt,
"Failed to schedule stop provisional keepalive action");
4830 ast_verbose(
"\n<--- %sTransmitting (%s) to %s --->\n%s\n<------------>\n",
4945 ast_log(
LOG_ERROR,
"Attempt to Ref a null pointer. sip private structure is gone!\n");
4965 char *cp = (
char *) data;
5002 ast_debug(1,
"Attempt to Ref a null pointer. Sip private structure is gone!\n");
5040 *cp = p->
dsp ? 1 : 0;
5076 char last_char =
'\0';
5078 for (s = start; *s && s != lim; last_char = *s++) {
5079 if (*s ==
'"' && last_char !=
'\\')
5144 ast_debug(2,
"Trying to send MESSAGE to device that does not support it.\n");
5167 static void realtime_update_peer(
const char *
peername,
struct ast_sockaddr *addr,
const char *defaultuser,
const char *fullcontact,
const char *useragent,
int expirey,
unsigned short deprecated_username,
int lastms,
const char *path)
5170 char ipaddr[INET6_ADDRSTRLEN];
5171 char regseconds[20];
5172 char *tablename =
NULL;
5173 char str_lastms[20];
5176 char *syslabel =
NULL;
5178 time_t nowtime = time(
NULL) + expirey;
5179 const char *fc = fullcontact ?
"fullcontact" :
NULL;
5183 tablename = realtimeregs ?
"sipregs" :
"sippeers";
5185 snprintf(str_lastms,
sizeof(str_lastms),
"%d", lastms);
5186 snprintf(regseconds,
sizeof(regseconds),
"%d", (
int)nowtime);
5193 syslabel =
"regserver";
5207 "port", port,
"regseconds", regseconds,
5208 deprecated_username ?
"username" :
"defaultuser", defaultuser,
5209 "useragent", useragent,
"lastms", str_lastms,
5211 fc, fullcontact, syslabel, sysname,
SENTINEL);
5214 "port", port,
"regseconds", regseconds,
5215 "useragent", useragent,
"lastms", str_lastms,
5216 deprecated_username ?
"username" :
"defaultuser", defaultuser,
5223 "port", port,
"regseconds", regseconds,
5224 deprecated_username ?
"username" :
"defaultuser", defaultuser,
5225 "useragent", useragent,
"lastms", str_lastms,
5226 fc, fullcontact, syslabel, sysname,
SENTINEL);
5229 "port", port,
"regseconds", regseconds,
5230 "useragent", useragent,
"lastms", str_lastms,
5231 deprecated_username ?
"username" :
"defaultuser", defaultuser,
5253 while ((ext =
strsep(&stringp,
"&"))) {
5254 if ((context = strchr(ext,
'@'))) {
5257 ast_log(
LOG_WARNING,
"Context %s must exist in regcontext= in sip.conf!\n", context);
5283 #define REMOVE_MAILBOX_WITH_LOCKED_PEER(__peer) \ 5285 struct sip_mailbox *__mailbox;\ 5287 __mailbox = AST_LIST_REMOVE_HEAD(&(__peer->mailboxes), entry);\ 5288 ao2_unlock(__peer);\ 5401 const char *insecure;
5438 const char *regname;
5459 if (!strcasecmp(regname, peername)) {
5496 for (tmp = var;
tmp; tmp = tmp->
next) {
5497 if (!strcasecmp(tmp->
name,
"name")) {
5527 for (tmp = *var;
tmp; tmp = tmp->
next) {
5528 if (!strcasecmp(tmp->
name,
"host")) {
5565 const char *old_name = *
name;
5628 if (varregs && *varregs) {
5638 if (varregs && !*varregs) {
5668 sip_unref_peer(peer,
"register_realtime_peers: Done registering releasing");
5690 char ipaddr[INET6_ADDRSTRLEN];
5701 }
else if (addr &&
realtime_peer_by_addr(&newpeername, addr, ipaddr, callbackexten, &var, realtimeregs ? &varregs : NULL)) {
5711 for (tmp = var;
tmp; tmp = tmp->
next) {
5712 if (!strcasecmp(tmp->
name,
"type") && (!strcasecmp(tmp->
value,
"peer"))) {
5719 peer =
build_peer(newpeername, var, varregs,
TRUE, devstate_only);
5726 if (peer->
type == 0) {
5729 }
else if (which_objects ==
FINDPEERS) {
5736 ast_debug(3,
"-REALTIME- loading peer from database to memory. Name: %s. Peer objects: %d\n", peer->
name,
rpeerobjs);
5747 ao2_t_link(peers, peer,
"link peer into peers table");
5749 ao2_t_link(peers_by_ip, peer,
"link peer into peers_by_ip table");
5764 int *which_objects = data;
5767 if (strcmp(search->
name, match->name)) {
5771 switch (*which_objects) {
5811 if (!p && (realtime || devstate_only)) {
5814 p =
realtime_peer(peer, addr, callbackexten, devstate_only, which_objects);
5816 switch (which_objects) {
5868 mode = natflags ?
"On" :
"Off";
5871 ast_debug(1,
"Setting NAT on RTP to %s\n", mode);
5875 ast_debug(1,
"Setting NAT on VRTP to %s\n", mode);
5879 ast_debug(1,
"Setting NAT on UDPTL to %s\n", mode);
5883 ast_debug(1,
"Setting NAT on TRTP to %s\n", mode);
5968 *to_sock = *from_sock;
6018 ast_log(
LOG_ERROR,
"No DTLS-SRTP support present on engine for RTP instance '%p', was it compiled with support for it?\n",
6024 ast_log(
LOG_ERROR,
"Attempted to set an invalid DTLS-SRTP configuration on RTP instance '%p'\n",
6030 ast_log(
LOG_ERROR,
"Failed to create required SRTP structure on RTP instance '%p'\n",
6150 dialog->
recv = dialog->
sa;
6223 credentials = peer->
auth;
6225 ao2_t_ref(credentials, +1,
"Ref peer auth for dialog");
6246 new_callid = strchr(tmpcall,
'@');
6253 callid_size = strlen(tmpcall) + strlen(peer->
fromdomain) + 2;
6255 snprintf(new_callid, callid_size,
"%s@%s", tmpcall, peer->
fromdomain);
6320 char *
peername, *peername2, *hostn;
6349 sip_unref_peer(peer,
"create_addr: unref peer from sip_find_peer hashtab lookup");
6355 ast_log(
LOG_WARNING,
"Purely numeric hostname (%s), and not a peer--rejecting!\n", peername);
6387 snprintf(service,
sizeof(service),
"_%s._%s.%s",
6438 dialog_unref(p,
"unreffing arg passed into auto_congest callback (p->initid)");
6451 const char *referer =
NULL;
6468 ao2_t_ref(recall_monitor, -1,
"Got the URI we need so unreffing monitor");
6483 }
else if (!strcmp(
ast_var_name(current),
"SIPFROMDOMAIN")) {
6485 }
else if (!strcmp(
ast_var_name(current),
"SIPTRANSFER")) {
6488 }
else if (!strcmp(
ast_var_name(current),
"SIPTRANSFER_REFERER")) {
6491 }
else if (!strcmp(
ast_var_name(current),
"SIPTRANSFER_REPLACES")) {
6494 }
else if (!strcmp(
ast_var_name(current),
"SIP_MAX_FORWARDS")) {
6496 ast_log(
LOG_WARNING,
"The SIP_MAX_FORWARDS channel variable is not a valid integer.\n");
6510 ast_debug(1,
"Direct media not possible when using SRTP, ignoring canreinvite setting\n");
6544 snprintf(buf,
sizeof(buf)-1,
"-> %s (via %s)", p->
cid_name, referer);
6546 snprintf(buf,
sizeof(buf)-1,
"-> %s", p->
cid_name);
6586 memset(&update_connected, 0,
sizeof(update_connected));
6597 update_connected.
id.
name = 1;
6620 dialog_unref(_data,
"dialog ptr dec when SCHED_REPLACE del op succeeded"),
6621 dialog_unref(p,
"dialog ptr dec when SCHED_REPLACE add failed"),
6622 dialog_ref(p,
"dialog ptr inc when SCHED_REPLACE add succeeded") );
6689 ast_debug(2,
"This call did not properly clean up call limits. Call ID %s\n", p->
callid);
6851 ast_debug(3,
"Updating call counter for %s call\n", outgoing ?
"outgoing" :
"incoming");
6870 ast_debug(2,
"%s is not a local device, no call limit\n", name);
6922 ast_debug(2,
"Call %s %s '%s' removed from call limit %d\n", outgoing ?
"to" :
"from",
"peer", name, *call_limit);
6928 if (*call_limit > 0 ) {
6929 if (*inuse >= *call_limit) {
6930 ast_log(
LOG_NOTICE,
"Call %s %s '%s' rejected due to usage limit of %d\n", outgoing ?
"to" :
"from",
"peer", name, *call_limit);
6931 sip_unref_peer(p,
"update_call_counter: unref peer p, call limit exceeded");
6956 ast_debug(2,
"Call %s %s '%s' is %d out of %d\n", outgoing ?
"to" :
"from",
"peer", name, *inuse, *call_limit);
6976 ast_log(
LOG_ERROR,
"update_call_counter(%s, %d) called with no event!\n", name, event);
6980 sip_unref_peer(p,
"update_call_counter: sip_unref_peer from call counter");
7060 if (cause < 500 && cause >= 400) {
7063 }
else if (cause < 600 && cause >= 500) {
7066 }
else if (cause < 700 && cause >= 600) {
7114 return "404 Not Found";
7117 return "503 Service Unavailable";
7119 return "408 Request Timeout";
7122 return "480 Temporarily unavailable";
7124 return "403 Forbidden";
7128 return "480 Temporarily unavailable";
7130 return "484 Address incomplete";
7132 return "486 Busy here";
7134 return "500 Server internal failure";
7136 return "501 Not Implemented";
7138 return "503 Service Unavailable";
7141 return "502 Bad Gateway";
7143 return "488 Not Acceptable Here";
7145 return "500 Network error";
7149 ast_debug(1,
"AST hangup cause %d (no match found in SIP)\n", cause);
7178 struct sip_pvt *pvt = (
void *) data;
7191 dialog_unref(pvt,
"Failed to schedule stop reinviteid action");
7200 int needcancel =
FALSE;
7201 int needdestroy = 0;
7205 ast_debug(1,
"Asked to hangup channel that was not connected\n");
7209 ast_debug(1,
"This call was answered elsewhere\n");
7221 ast_debug(1,
"update_call_counter(%s) - decrement call limit counter on hangup\n", p->
username);
7224 ast_debug(4,
"SIP Transfer: Not hanging up right now... Rescheduling hangup for %s.\n", p->
callid);
7229 oldowner = p->
owner;
7243 ast_debug(1,
"update_call_counter(%s) - decrement call limit counter on hangup\n", p->
username);
7248 if (p->
owner != ast) {
7292 append_history(p,
"DELAY",
"Not sending cancel, waiting for timeout");
7408 char *codec_list_copy;
7411 int first_codec = 1;
7428 if (!original_jointcaps) {
7433 for (codec = strtok_r(codec_list_copy,
",", &strtok_ptr); codec; codec = strtok_r(
NULL,
",", &strtok_ptr)) {
7440 ast_log(
AST_LOG_NOTICE,
"Ignoring ${SIP_CODEC*} variable because of unrecognized/not configured codec %s (check allow/disallow in sip.conf)\n", codec);
7445 ast_verb(4,
"Set codec to '%s' for this call because of ${SIP_CODEC*} variable\n", codec);
7452 ast_verb(4,
"Add codec to '%s' for this call because of ${SIP_CODEC*} variable\n", codec);
7458 ast_log(
AST_LOG_NOTICE,
"Ignoring ${SIP_CODEC*} variable because it is not shared by both ends: %s\n", codec);
7469 ao2_ref(original_jointcaps, -1);
7483 ast_debug(1,
"Asked to answer channel %s without tech pvt; ignoring\n",
7520 ast_log(
LOG_WARNING,
"Asked to transmit frame type %s, while native formats is %s read/write = %s/%s\n",
7533 }
else if (p->
rtp) {
7634 ast_debug(1,
"New channel is zombie\n");
7636 ast_debug(1,
"Old channel is zombie\n");
7650 if (p->
owner != oldchan)
7675 ast_debug(1,
"Asked to begin DTMF digit on channel %s with no pvt; ignoring\n",
7705 ast_debug(1,
"Asked to end DTMF digit on channel %s with no pvt; ignoring\n",
7736 ast_debug(1,
"Asked to transfer channel %s with no pvt; ignoring\n",
7885 ast_debug(1,
"Setting NAT on UDPTL to %s\n", natflags ?
"On" :
"Off");
7900 const char *content_type,
7901 const char *content,
7902 const char *useragent_filter)
7928 for (var = headers;
var; var = var->
next) {
7932 add_header(&req,
"Content-Type", content_type);
7954 ast_debug(1,
"Asked to indicate condition on channel %s with no pvt; ignoring\n",
8179 const char *my_name;
8191 tmp =
ast_channel_alloc_with_endpoint(1, state, i->
cid_num, i->
cid_name, i->
accountcode, i->
exten, i->
context, assignedids, requestor, i->
amaflags, i->
relatedpeer->
endpoint,
"SIP/%s-%08x", my_name, (
unsigned)
ast_atomic_fetchadd_int((
int *)&
chan_idx, +1));
8193 tmp =
ast_channel_alloc(1, state, i->
cid_num, i->
cid_name, i->
accountcode, i->
exten, i->
context, assignedids, requestor, i->
amaflags,
"SIP/%s-%08x", my_name, (
unsigned)
ast_atomic_fetchadd_int((
int *)&
chan_idx, +1));
8285 ast_debug(3,
"This channel can handle video! HOLLYWOOD next!\n");
8287 ast_debug(3,
"This channel will not be able to handle video.\n");
8316 if (needvideo && i->
vrtp) {
8324 if (needtext && i->
trtp) {
8355 ast_channel_parkinglot_set(tmp, i->
parkinglot);
8364 ast_channel_language_set(tmp, i->
language);
8369 ast_log(
LOG_ERROR,
"Unknown country code '%s' for tonezone. Check indications.conf for available country codes.\n", i->
zone);
8427 char valuebuf[1024];
8446 int len = strlen(name);
8451 if (!strncasecmp(line, name, len) && line[len] ==
'=') {
8470 const char *line =
NULL;
8476 while (*start < stop) {
8478 if (line[1] ==
'=') {
8492 int len = strlen(name);
8495 for (i = 0; i < req->
lines; i++) {
8497 if (!strncasecmp(line, name, len) && line[len] == delimiter) {
8511 {
"Content-Type",
"c" },
8512 {
"Content-Encoding",
"e" },
8516 {
"Content-Length",
"l" },
8519 {
"Supported",
"k" },
8520 {
"Refer-To",
"r" },
8521 {
"Referred-By",
"b" },
8522 {
"Allow-Events",
"u" },
8525 {
"Accept-Contact",
"a" },
8526 {
"Reject-Contact",
"j" },
8527 {
"Request-Disposition",
"d" },
8528 {
"Session-Expires",
"x" },
8529 {
"Identity",
"y" },
8530 {
"Identity-Info",
"n" },
8538 for (x = 0; x <
ARRAY_LEN(aliases); x++) {
8539 if (!strcasecmp(aliases[x].fullname, name))
8540 return aliases[x].shortname;
8551 if (strlen(name) == 1) {
8553 for (x = 0; x <
ARRAY_LEN(aliases); ++x) {
8554 if (!strcasecmp(aliases[x].shortname, name))
8555 return aliases[x].fullname;
8572 int x,
len = strlen(name), slen = (sname ? 1 : 0);
8573 for (x = *start; x < req->
headers; x++) {
8575 int smatch = 0,
match = !strncasecmp(header, name, len);
8577 smatch = !strncasecmp(header, sname, slen);
8579 if (
match || smatch) {
8581 const char *r = header + (
match ?
len : slen );
8583 while (*r ==
' ' || *r ==
'\t') {
8621 for (i = 0; i < req->
lines; i++) {
8659 unsigned char* arr = f->
data.
ptr;
8664 for (i = 0; i < f->
datalen; i++) {
8665 ast_str_append(&out, 0,
"%c", (arr[i] >
' ' && arr[i] <
'}') ? arr[i] :
'.');
8668 for (i = 0; i < f->
datalen; i++) {
8699 ast_debug(1,
"Bogus frame of format '%s' received from '%s'!\n",
8704 ast_debug(1,
"Oooh, format changed to %s\n",
8746 int faxdetected =
FALSE;
8804 snprintf(buf, size,
"%08lx%08lx%08lx%08lx", (
unsigned long)val[0], (
unsigned long)val[1], (
unsigned long)val[2], (
unsigned long)val[3]);
8838 #define CONTAINER_UNLINK(container, obj, tag) \ 8841 typeof((obj)) __removed_obj; \ 8842 __removed_obj = ao2_t_callback((container), \ 8843 OBJ_UNLINK | OBJ_POINTER, ao2_match_by_addr, (obj), (tag)); \ 8844 if (__removed_obj) { \ 8845 ao2_ref(__removed_obj, -1); \ 8862 int in_dialog_container;
8863 int in_rtp_container;
8869 "About to change the callid -- remove the old name");
8871 "About to change the callid -- remove the old name");
8877 if (in_dialog_container) {
8878 ao2_t_link(dialogs, pvt,
"New dialog callid -- inserted back into table");
8880 if (in_rtp_container) {
8881 ao2_t_link(dialogs_rtpcheck, pvt,
"New dialog callid -- inserted back into table");
8886 if (strcmp(oldid, pvt->
callid)) {
8887 ast_debug(1,
"SIP call-id changed from '%s' to '%s'\n", oldid, pvt->
callid);
8944 const char *
file,
int line,
const char *func)
8956 ao2_t_ref(p, -1,
"failed to string_field_init, drop p");
8961 ao2_t_ref(p, -1,
"Yuck, couldn't allocate cc_params struct. Get rid o' p");
8965 if (logger_callid) {
8981 ao2_t_ref(p, -1,
"Yuck, couldn't allocate format capabilities. Get rid o' p");
9017 p->
method = intended_method;
9062 if (useglobal_nat && addr) {
9096 ao2_t_link(dialogs, p,
"link pvt into dialogs table");
9135 setsockopt(
sipsock, IPPROTO_IP, IP_MULTICAST_TTL, &via->
ttl,
sizeof(via->
ttl));
9179 const char *init_ruri =
NULL;
9193 if (strcmp(arg->
fromtag, sip_pvt_ptr->
tag)) {
9208 char invite_branch[32] = { 0, };
9210 snprintf(invite_branch,
sizeof(invite_branch),
"z9hG4bK%08x", (
unsigned)sip_pvt_ptr->
invite_branch);
9224 if ((arg->
respid == 200) &&
9227 !strcmp(invite_branch, arg->
viabranch)) {
9430 if (pvt->
owner == chan) {
9470 const char *
file,
int line,
const char *func)
9484 (sscanf(cseq,
"%30u", &seqno) != 1)) {
9489 req,
"400 Bad Request");
9501 if (
gettag(req,
"To", totag,
sizeof(totag)))
9503 gettag(req,
"From", fromtag,
sizeof(fromtag));
9505 ast_debug(5,
"= Looking for Call ID: %s (Checking %s) --From tag %s --To-tag %s \n", callid, req->
method==
SIP_RESPONSE ?
"To" :
"From", fromtag, totag);
9528 "find_call in dialogs", file, line, func);
9546 "pedantic ao2_find in dialogs",
9601 __ao2_ref(sip_pvt_ptr, -1,
"pvt did not match incoming SIP msg, unref from search.",
9608 dialog_unref(fork_pvt,
"throwing way pvt to fork off of.");
9609 fork_pvt =
dialog_ref(sip_pvt_ptr,
"this pvt has a forked request, save this off to copy information into new dialog\n");
9613 __ao2_ref(sip_pvt_ptr, -1,
"pvt did not match incoming SIP msg, unref from search",
9632 fork_pvt =
dialog_unref(fork_pvt,
"throwing way pvt to fork off of");
9648 if (!(p =
sip_alloc(callid, addr, 1, intended_method, req, logger_callid))) {
9658 ast_debug(4,
"Failed allocating SIP dialog, sending 500 Server internal error and giving up\n");
9664 ast_debug(2,
"Got a request with unsupported SIP method.\n");
9668 ast_debug(2,
"That's odd... Got a request in unknown dialog. Callid %s\n", callid ? callid :
"<unknown>");
9673 ast_debug(2,
"That's odd... Got a response on a call we don't know about. Callid %s\n", callid ? callid :
"<unknown>");
9685 ao2_t_ref(reg, -1,
"throw away found registry");
9698 ao2_t_ref(reg, -1,
"failed to string_field_init, drop reg");
9704 ao2_t_ref(reg, -1,
"failure to parse, unref the reg pointer");
9713 ao2_t_link(registry_list, reg,
"link reg to registry_list");
9714 ao2_t_ref(reg, -1,
"unref the reg pointer");
9736 if ((hostname = strrchr(buf,
'@'))) {
9742 if ((secret = strchr(username,
':'))) {
9744 if ((authuser = strchr(secret,
':'))) {
9749 if ((mailbox = strchr(hostname,
'/'))) {
9754 ast_log(
LOG_WARNING,
"Format for MWI subscription is user[:secret[:authuser]]@host[:port]/mailbox at line %d\n", lineno);
9758 if ((porta = strchr(hostname,
':'))) {
9760 if (!(portnum = atoi(porta))) {
9773 ao2_t_ref(mwi, -1,
"failed to string_field_init, drop mwi");
9789 ao2_t_link(subscription_mwi_list, mwi,
"link new mwi object");
9790 ao2_t_ref(mwi, -1,
"unref to match ao2_t_alloc");
9797 (*allowed_methods) |= (1 <<
method);
9802 (*allowed_methods) &= ~(1 <<
method);
9808 return ((*allowed_methods) >> method) & 1;
9849 char *
methods = strstr(contact,
";methods=");
9868 return allowed_methods;
9900 int just_read_eol = 0;
9901 int done_with_headers = 0;
9905 if (msgbuf[h] ==
'\r') {
9910 if (msgbuf[h] ==
'\n') {
9911 if (just_read_eol) {
9912 done_with_headers = 1;
9920 if (!done_with_headers
9921 && (msgbuf[h + 1] ==
' ' || msgbuf[h + 1] ==
'\t')) {
9927 msgbuf[t++] = msgbuf[h++];
9933 if (!done_with_headers
9934 && (msgbuf[h] ==
' ' || msgbuf[h] ==
'\t')) {
9939 msgbuf[t++] = msgbuf[h++];
9943 msgbuf[t++] = msgbuf[h++];
9957 ptrdiff_t *dst = req->
header;
9960 unsigned int skipping_headers = 0;
9961 ptrdiff_t current_header_offset = 0;
9962 char *previous_header =
"";
9969 }
else if (*c ==
'\n') {
9973 if (skipping_headers) {
9978 skipping_headers = 0;
9980 dst[i] = current_header_offset;
9985 req->
headers < 0 ?
"Header" :
"Body",
9986 i, (
int) strlen(previous_header), previous_header);
10005 skipping_headers = 1;
10009 dst[i] = current_header_offset;
10022 req->
headers < 0 ?
"Header" :
"Body",
10023 i, (
int) strlen(previous_header), previous_header );
10056 const char *content_type;
10057 const char *content_length;
10058 const char *search;
10061 int boundaryisquoted =
FALSE;
10062 int found_application_sdp =
FALSE;
10063 int found_end_of_headers =
FALSE;
10068 if (sscanf(content_length,
"%30u", &x) != 1) {
10082 if (!strncasecmp(content_type,
"application/sdp", 15)) {
10085 return req->
lines ? 1 : 0;
10089 if (strncasecmp(content_type,
"multipart/mixed", 15))
10093 if ((search =
strcasestr(content_type,
";boundary=")))
10095 else if ((search =
strcasestr(content_type,
"; boundary=")))
10104 if (*search ==
'\"') {
10106 boundaryisquoted =
TRUE;
10112 boundary[0] = boundary[1] =
'-';
10114 if (boundaryisquoted)
10115 boundary[strlen(boundary) - 1] =
'\0';
10120 for (x = 0; x < (req->
lines); x++) {
10122 if (!strncasecmp(line, boundary, strlen(boundary))){
10123 if (found_application_sdp && found_end_of_headers) {
10127 found_application_sdp =
FALSE;
10129 if (!strcasecmp(line,
"Content-Type: application/sdp"))
10130 found_application_sdp =
TRUE;
10133 if (found_application_sdp && !found_end_of_headers){
10135 found_end_of_headers =
TRUE;
10139 if (found_application_sdp && found_end_of_headers) {
10164 else if (sendonly == 2)
10187 if (m == offer->
type) {
10199 if (local_rtcp_mux && remote_rtcp_mux) {
10221 if (local_rtcp_mux && remote_rtcp_mux) {
10239 while ((type =
get_sdp_line(&start, next, req, &value)) !=
'\0') {
10240 if (type ==
'a' && !strcasecmp(value, attr)) {
10260 int iterator = start;
10265 const char *m =
NULL;
10266 const char *nextm =
NULL;
10283 int udptlportno = -1;
10290 int peernoncodeccapability = 0, vpeernoncodeccapability = 0, tpeernoncodeccapability = 0;
10297 int newnoncodeccapability;
10300 unsigned int codec;
10303 int secure_audio =
FALSE;
10304 int secure_video =
FALSE;
10307 int remote_rtcp_mux_audio =
FALSE;
10308 int remote_rtcp_mux_video =
FALSE;
10312 unsigned int numberofports;
10313 int last_rtpmap_codec = 0;
10314 int red_data_pt[10];
10315 int red_num_gen = 0;
10316 char red_fmtp[100] =
"empty";
10328 goto process_sdp_cleanup;
10330 if (!peercapability || !vpeercapability || !tpeercapability || !newpeercapability || !newjointcapability) {
10332 goto process_sdp_cleanup;
10338 goto process_sdp_cleanup;
10351 goto process_sdp_cleanup;
10355 while ((type =
get_sdp_line(&iterator, next - 1, req, &value)) !=
'\0') {
10356 int processed =
FALSE;
10364 goto process_sdp_cleanup;
10385 else if (
process_sdp_a_text(value, p, &newtextrtp, red_fmtp, &red_num_gen, red_data_pt, &last_rtpmap_codec))
10422 ast_debug(3,
"Processing session-level SDP %c=%s... %s\n", type, value, (processed ==
TRUE)?
"OK." :
"UNSUPPORTED OR FAILED.");
10435 int processed_crypto =
FALSE;
10436 int rtcp_mux_offered = 0;
10437 char protocol[18] = {0,};
10448 if (!(offer =
ast_calloc(1,
sizeof(*offer)))) {
10451 goto process_sdp_cleanup;
10460 if (p->
rtp && strncmp(m,
"audio ", 6) == 0) {
10461 if ((sscanf(m,
"audio %30u/%30u %17s %n", &x, &numberofports, protocol, &len) == 3 && len > 0) ||
10462 (sscanf(m,
"audio %30u %17s %n", &x, protocol, &len) == 2 && len > 0)) {
10469 goto process_sdp_cleanup;
10472 sprintf(offer->
decline_m_line,
"m=audio 0 %s %s\r\n", protocol, codecs);
10475 ast_debug(1,
"Ignoring audio media offer because port number is zero\n");
10485 if (numberofports > 1) {
10486 ast_log(
LOG_WARNING,
"%u ports offered for audio media, not supported by Asterisk. Will try anyway...\n", numberofports);
10491 ast_log(
LOG_NOTICE,
"Received SAVPF profle in audio offer but AVPF is not enabled, enabling: %s\n", m);
10497 ast_log(
LOG_WARNING,
"Received SAVPF profle in audio answer but AVPF is not enabled: %s\n", m);
10502 ast_log(
LOG_NOTICE,
"Received SAVP profle in audio offer but AVPF is enabled, disabling: %s\n", m);
10507 ast_log(
LOG_WARNING,
"Received SAVP profile in audio offer but AVPF is enabled: %s\n", m);
10510 }
else if (!strcmp(protocol,
"UDP/TLS/RTP/SAVP") || !strcmp(protocol,
"UDP/TLS/RTP/SAVPF")) {
10513 processed_crypto = 1;
10517 }
else if (!strcmp(protocol,
"RTP/SAVP") || !strcmp(protocol,
"RTP/SAVPF")) {
10521 ast_log(
LOG_NOTICE,
"Received AVPF profile in audio offer but AVPF is not enabled, enabling: %s\n", m);
10525 ast_log(
LOG_WARNING,
"Received AVP profile in audio answer but AVPF is enabled: %s\n", m);
10530 ast_log(
LOG_NOTICE,
"Received AVP profile in audio answer but AVPF is enabled, disabling: %s\n", m);
10534 ast_log(
LOG_WARNING,
"Received AVP profile in audio answer but AVPF is enabled: %s\n", m);
10537 }
else if ((!strcmp(protocol,
"UDP/TLS/RTP/SAVP") || !strcmp(protocol,
"UDP/TLS/RTP/SAVPF")) &&
10539 ast_log(
LOG_WARNING,
"Received UDP/TLS in audio offer but DTLS is not enabled: %s\n", m);
10541 }
else if (strcmp(protocol,
"RTP/AVP") && strcmp(protocol,
"RTP/AVPF")) {
10552 if (sscanf(codecs,
"%30u%n", &codec, &len) != 1) {
10555 goto process_sdp_cleanup;
10558 ast_verbose(
"Found RTP audio format %u\n", codec);
10564 ast_log(
LOG_WARNING,
"Rejecting audio media offer due to invalid or unsupported syntax: %s\n", m);
10566 goto process_sdp_cleanup;
10570 else if (p->
vrtp && strncmp(m,
"video ", 6) == 0) {
10571 if ((sscanf(m,
"video %30u/%30u %17s %n", &x, &numberofports, protocol, &len) == 3 && len > 0) ||
10572 (sscanf(m,
"video %30u %17s %n", &x, protocol, &len) == 2 && len > 0)) {
10579 goto process_sdp_cleanup;
10582 sprintf(offer->
decline_m_line,
"m=video 0 %s %s\r\n", protocol, codecs);
10585 ast_debug(1,
"Ignoring video stream offer because port number is zero\n");
10590 if (numberofports > 1) {
10591 ast_log(
LOG_WARNING,
"%u ports offered for video stream, not supported by Asterisk. Will try anyway...\n", numberofports);
10600 ast_log(
LOG_WARNING,
"Received SAVPF profle in video offer but AVPF is not enabled: %s\n", m);
10603 ast_log(
LOG_WARNING,
"Received SAVP profile in video offer but AVPF is enabled: %s\n", m);
10605 }
else if (!strcmp(protocol,
"UDP/TLS/RTP/SAVP") || !strcmp(protocol,
"UDP/TLS/RTP/SAVPF")) {
10608 processed_crypto = 1;
10612 }
else if (!strcmp(protocol,
"RTP/SAVP") || !strcmp(protocol,
"RTP/SAVPF")) {
10615 ast_log(
LOG_WARNING,
"Received AVPF profile in video offer but AVPF is not enabled: %s\n", m);
10618 ast_log(
LOG_WARNING,
"Received AVP profile in video offer but AVPF is enabled: %s\n", m);
10620 }
else if (strcmp(protocol,
"RTP/AVP") && strcmp(protocol,
"RTP/AVPF")) {
10632 if (sscanf(codecs,
"%30u%n", &codec, &len) != 1) {
10635 goto process_sdp_cleanup;
10638 ast_verbose(
"Found RTP video format %u\n", codec);
10643 ast_log(
LOG_WARNING,
"Rejecting video media offer due to invalid or unsupported syntax: %s\n", m);
10645 goto process_sdp_cleanup;
10649 else if (p->
trtp && strncmp(m,
"text ", 5) == 0) {
10650 if ((sscanf(m,
"text %30u/%30u %17s %n", &x, &numberofports, protocol, &len) == 3 && len > 0) ||
10651 (sscanf(m,
"text %30u %17s %n", &x, protocol, &len) == 2 && len > 0)) {
10658 goto process_sdp_cleanup;
10661 sprintf(offer->
decline_m_line,
"m=text 0 %s %s\r\n", protocol, codecs);
10664 ast_debug(1,
"Ignoring text stream offer because port number is zero\n");
10669 if (numberofports > 1) {
10670 ast_log(
LOG_WARNING,
"%u ports offered for text stream, not supported by Asterisk. Will try anyway...\n", numberofports);
10674 ast_log(
LOG_WARNING,
"Received AVPF profile in text offer but AVPF is not enabled: %s\n", m);
10677 ast_log(
LOG_WARNING,
"Received AVP profile in text offer but AVPF is enabled: %s\n", m);
10679 }
else if (strcmp(protocol,
"RTP/AVP") && strcmp(protocol,
"RTP/AVPF")) {
10696 if (sscanf(codecs,
"%30u%n", &codec, &len) != 1) {
10699 goto process_sdp_cleanup;
10702 ast_verbose(
"Found RTP text format %u\n", codec);
10707 ast_log(
LOG_WARNING,
"Rejecting text stream offer due to invalid or unsupported syntax: %s\n", m);
10709 goto process_sdp_cleanup;
10713 else if (strncmp(m,
"image ", 6) == 0) {
10714 if (((sscanf(m,
"image %30u udptl t38%n", &x, &len) == 1 && len > 0) ||
10715 (sscanf(m,
"image %30u UDPTL t38%n", &x, &len) == 1 && len > 0))) {
10721 goto process_sdp_cleanup;
10727 ast_debug(1,
"Ignoring image stream offer because port number is zero\n");
10756 }
else if (sscanf(m,
"image %30u %17s t38%n", &x, protocol, &len) == 2 && len > 0) {
10757 ast_log(
LOG_WARNING,
"Declining image stream due to unsupported transport: %s\n", m);
10763 goto process_sdp_cleanup;
10766 sprintf(offer->
decline_m_line,
"m=image 0 %s t38\r\n", protocol);
10769 ast_log(
LOG_WARNING,
"Rejecting image media offer due to invalid or unsupported syntax: %s\n", m);
10771 goto process_sdp_cleanup;
10774 char type[20] = {0,};
10775 if ((sscanf(m,
"%19s %30u/%30u %n", type, &x, &numberofports, &len) == 3 && len > 0) ||
10776 (sscanf(m,
"%19s %30u %n", type, &x, &len) == 2 && len > 0)) {
10782 goto process_sdp_cleanup;
10790 goto process_sdp_cleanup;
10795 while ((type =
get_sdp_line(&iterator, next - 1, req, &value)) !=
'\0') {
10796 int processed =
FALSE;
10805 }
else if (video) {
10815 }
else if (image) {
10828 processed_crypto =
TRUE;
10836 processed_crypto =
TRUE;
10838 if (secure_audio ==
FALSE) {
10839 ast_log(
AST_LOG_NOTICE,
"Processed audio crypto attribute without SAVP specified; accepting anyway\n");
10840 secure_audio =
TRUE;
10853 processed_crypto =
TRUE;
10859 processed_crypto =
TRUE;
10861 if (secure_video ==
FALSE) {
10862 ast_log(
AST_LOG_NOTICE,
"Processed video crypto attribute without SAVP specified; accepting anyway\n");
10863 secure_video =
TRUE;
10875 }
else if (
process_sdp_a_text(value, p, &newtextrtp, red_fmtp, &red_num_gen, red_data_pt, &last_rtpmap_codec)) {
10878 processed_crypto =
TRUE;
10890 ast_debug(3,
"Processing media-level (%s) SDP %c=%s... %s\n",
10891 (audio ==
TRUE)?
"audio" : (video ==
TRUE)?
"video" : (text ==
TRUE)?
"text" :
"image",
10893 (processed ==
TRUE)?
"OK." :
"UNSUPPORTED OR FAILED.");
10897 if (audio && secure_audio && !processed_crypto) {
10898 ast_log(
LOG_WARNING,
"Rejecting secure audio stream without encryption details: %s\n", m);
10900 goto process_sdp_cleanup;
10901 }
else if (video && secure_video && !processed_crypto) {
10902 ast_log(
LOG_WARNING,
"Rejecting secure video stream without encryption details: %s\n", m);
10904 goto process_sdp_cleanup;
10909 if (!sa && !vsa && !tsa && !isa) {
10912 goto process_sdp_cleanup;
10915 if ((portno == -1) &&
10918 (udptlportno == -1)) {
10921 goto process_sdp_cleanup;
10924 if (p->
srtp && p->
udptl && udptlportno != -1) {
10925 ast_debug(1,
"Terminating SRTP due to T.38 UDPTL\n");
10933 goto process_sdp_cleanup;
10936 if (!secure_audio && p->
srtp) {
10937 ast_log(
LOG_WARNING,
"Failed to receive SDP offer/answer with required SRTP crypto attributes for audio\n");
10939 goto process_sdp_cleanup;
10945 goto process_sdp_cleanup;
10949 ast_log(
LOG_WARNING,
"Failed to receive SDP offer/answer with required SRTP crypto attributes for video\n");
10951 goto process_sdp_cleanup;
10957 goto process_sdp_cleanup;
10960 if (udptlportno == -1) {
10988 goto process_sdp_cleanup;
11004 ast_verbose(
"Capabilities: us - %s, peer - audio=%s/video=%s/text=%s, combined - %s\n",
11011 ast_verbose(
"Non-codec capabilities (dtmf): us - %s, peer - %s, combined - %s\n",
11023 if ((portno != -1 || vportno != -1 || tportno != -1) &&
ast_format_cap_count(newjointcapability)) {
11026 unsigned int framing;
11049 if (sa && portno > 0) {
11080 }
else if (udptlportno > 0) {
11082 ast_verbose(
"Got T.38 Re-invite without audio. Keeping RTP active during T.38 session.\n");
11102 if (vsa && vportno > 0) {
11122 if (tsa && tportno > 0) {
11146 if (isa && udptlportno > 0) {
11196 ast_debug(1,
"Peer doesn't provide T.38 UDPTL\n");
11201 ast_debug(3,
"Have T.38 but no audio, accepting offer anyway\n");
11203 goto process_sdp_cleanup;
11211 goto process_sdp_cleanup;
11214 ast_debug(4,
"We have an owner, now see if we need to change this call\n");
11217 unsigned int framing;
11223 ast_debug(1,
"Setting native formats after processing SDP. peer joint formats %s, old nativeformats %s\n",
11263 process_sdp_cleanup:
11280 const char *o_copy_start;
11284 int64_t sess_version;
11307 token =
strsep(&o_copy,
" ");
11312 token =
strsep(&o_copy,
" ");
11317 token =
strsep(&o_copy,
" ");
11318 if (!o_copy || !sscanf(token,
"%30" SCNd64, &sess_version)) {
11329 offset = (o_copy - o_copy_start);
11330 if (offset <
sizeof(unique)) {
11332 int sess_version_start = token - o_copy_start;
11333 ast_copy_string(unique + sess_version_start, o + offset,
sizeof(unique) - sess_version_start);
11357 ast_verbose(
"Got SDP version %" PRId64
" and unique parts [%s]\n",
11358 sess_version, unique);
11360 ast_verbose(
"Comparing SDP version %" PRId64
" -> %" PRId64
" and unique parts [%s] -> [%s]\n",
11374 ast_log(
LOG_WARNING,
"Call %s responded to our T.38 reinvite without changing SDP version; 'ignoresdpversion' should be set for this peer.\n", p->
callid);
11377 ast_debug(2,
"Call %s responded to our reinvite without changing SDP version; ignoring SDP.\n", p->
callid);
11387 char proto[4],
host[258];
11391 if (sscanf(c,
"IN %3s %255s", proto, host) == 2) {
11392 if (!strcmp(
"IP4", proto)) {
11394 }
else if (!strcmp(
"IP6", proto)) {
11416 if (!strcasecmp(a,
"sendonly")) {
11417 if (*sendonly == -1)
11420 }
else if (!strcasecmp(a,
"inactive")) {
11421 if (*sendonly == -1)
11424 }
else if (!strcasecmp(a,
"sendrecv")) {
11425 if (*sendonly == -1)
11436 char ufrag[256], pwd[256], foundation[33], transport[4],
address[46], cand_type[6], relay_address[46] =
"";
11438 unsigned int port, relay_port = 0;
11444 if (sscanf(a,
"ice-ufrag: %255s", ufrag) == 1) {
11447 }
else if (sscanf(a,
"ice-pwd: %255s", pwd) == 1) {
11450 }
else if (sscanf(a,
"candidate: %32s %30u %3s %30u %23s %30u typ %5s %*s %23s %*s %30u", foundation, &candidate.
id, transport, (
unsigned *)&candidate.
priority,
11451 address, &port, cand_type, relay_address, &relay_port) >= 7) {
11464 if (!strcasecmp(cand_type,
"host")) {
11466 }
else if (!strcasecmp(cand_type,
"srflx")) {
11468 }
else if (!strcasecmp(cand_type,
"relay")) {
11485 }
else if (!strcasecmp(a,
"ice-lite")) {
11497 if (!strncasecmp(a,
"rtcp-mux", 8)) {
11509 char value[256], hash[32];
11515 if (sscanf(a,
"setup: %255s", value) == 1) {
11518 if (!strcasecmp(value,
"active")) {
11520 }
else if (!strcasecmp(value,
"passive")) {
11522 }
else if (!strcasecmp(value,
"actpass")) {
11524 }
else if (!strcasecmp(value,
"holdconn")) {
11527 ast_log(
LOG_WARNING,
"Unsupported setup attribute value '%s' received on dialog '%s'\n",
11530 }
else if (sscanf(a,
"connection: %255s", value) == 1) {
11533 if (!strcasecmp(value,
"new")) {
11534 dtls->
reset(instance);
11535 }
else if (!strcasecmp(value,
"existing")) {
11538 ast_log(
LOG_WARNING,
"Unsupported connection attribute value '%s' received on dialog '%s'\n",
11541 }
else if (sscanf(a,
"fingerprint: %31s %255s", hash, value) == 2) {
11544 if (!strcasecmp(hash,
"sha-1")) {
11546 }
else if (!strcasecmp(hash,
"sha-256")) {
11549 ast_log(
LOG_WARNING,
"Unsupported fingerprint hash type '%s' received on dialog '%s'\n",
11560 unsigned int codec;
11561 char mimeSubtype[128];
11562 char fmtp_string[256];
11563 unsigned int sample_rate;
11566 if (!strncasecmp(a,
"ptime", 5)) {
11567 char *
tmp = strrchr(a,
':');
11568 long int framing = 0;
11571 framing = strtol(tmp,
NULL, 10);
11572 if (framing == LONG_MIN || framing == LONG_MAX) {
11574 ast_debug(1,
"Can't read framing from SDP: %s\n", a);
11579 ast_debug(1,
"Setting framing to %ld\n", framing);
11584 }
else if (sscanf(a,
"rtpmap: %30u %127[^/]/%30u", &codec, mimeSubtype, &sample_rate) == 3) {
11590 ast_verbose(
"Found audio description format %s for ID %u\n", mimeSubtype, codec);
11592 (*last_rtpmap_codec)++;
11597 ast_verbose(
"Found unknown media description format %s for ID %u\n", mimeSubtype, codec);
11601 ast_verbose(
"Discarded description format %s for ID %u\n", mimeSubtype, codec);
11603 }
else if (sscanf(a,
"fmtp: %30u %255[^\t\n]", &codec, fmtp_string) == 2) {
11607 unsigned int bit_rate;
11611 if (format_parsed) {
11621 if (sscanf(fmtp_string,
"bitrate=%30u", &bit_rate) == 1) {
11622 if (bit_rate != 64000) {
11623 ast_log(
LOG_WARNING,
"Got G.719 offer at %u bps, but only 64000 bps supported; ignoring.\n", bit_rate);
11640 unsigned int codec;
11641 char mimeSubtype[128];
11642 unsigned int sample_rate;
11644 char fmtp_string[256];
11646 if (sscanf(a,
"rtpmap: %30u %127[^/]/%30u", &codec, mimeSubtype, &sample_rate) == 3) {
11650 if (!strncasecmp(mimeSubtype,
"H26", 3) || !strncasecmp(mimeSubtype,
"MP4", 3)
11651 || !strncasecmp(mimeSubtype,
"VP8", 3)) {
11654 ast_verbose(
"Found video description format %s for ID %u\n", mimeSubtype, codec);
11656 (*last_rtpmap_codec)++;
11661 ast_verbose(
"Found unknown media description format %s for ID %u\n", mimeSubtype, codec);
11666 ast_verbose(
"Discarded description format %s for ID %u\n", mimeSubtype, codec);
11668 }
else if (sscanf(a,
"fmtp: %30u %255[^\t\n]", &codec, fmtp_string) == 2) {
11676 if (format_parsed) {
11694 unsigned int codec;
11695 char mimeSubtype[128];
11696 unsigned int sample_rate;
11700 if (sscanf(a,
"rtpmap: %30u %127[^/]/%30u", &codec, mimeSubtype, &sample_rate) == 3) {
11703 if (!strncasecmp(mimeSubtype,
"T140", 4)) {
11709 }
else if (!strncasecmp(mimeSubtype,
"RED", 3)) {
11712 sprintf(red_fmtp,
"fmtp:%u ", codec);
11714 ast_verbose(
"RED submimetype has payload type: %u\n", codec);
11720 ast_verbose(
"Discarded description format %s for ID %u\n", mimeSubtype, codec);
11722 }
else if (!strncmp(a, red_fmtp, strlen(red_fmtp))) {
11725 red_cp = &red_fmtp[strlen(red_fmtp)];
11726 strncpy(red_fmtp, a, 100);
11728 sscanf(red_cp,
"%30u", (
unsigned *)&red_data_pt[*red_num_gen]);
11729 red_cp = strtok_r(red_cp,
"/", &rest);
11731 sscanf(red_cp,
"%30u", (
unsigned *)&red_data_pt[*red_num_gen]);
11732 red_cp = strtok_r(
NULL,
"/", &rest);
11758 for (pos = attrib; *pos; ++pos) {
11759 *pos = tolower(*pos);
11762 if ((sscanf(attrib,
"t38faxmaxbuffer:%30u", &x) == 1)) {
11765 }
else if ((sscanf(attrib,
"t38maxbitrate:%30u", &x) == 1) || (sscanf(attrib,
"t38faxmaxrate:%30u", &x) == 1)) {
11766 ast_debug(3,
"T38MaxBitRate: %u\n", x);
11788 }
else if ((sscanf(attrib,
"t38faxversion:%30u", &x) == 1)) {
11792 }
else if ((sscanf(attrib,
"t38faxmaxdatagram:%30u", &x) == 1) || (sscanf(attrib,
"t38maxdatagram:%30u", &x) == 1)) {
11798 ast_debug(3,
"FaxMaxDatagram: %u\n", x);
11801 }
else if ((strncmp(attrib,
"t38faxfillbitremoval",
sizeof(
"t38faxfillbitremoval") - 1) == 0)) {
11802 if (sscanf(attrib,
"t38faxfillbitremoval:%30u", &x) == 1) {
11803 ast_debug(3,
"FillBitRemoval: %u\n", x);
11812 }
else if ((strncmp(attrib,
"t38faxtranscodingmmr",
sizeof(
"t38faxtranscodingmmr") - 1) == 0)) {
11813 if (sscanf(attrib,
"t38faxtranscodingmmr:%30u", &x) == 1) {
11814 ast_debug(3,
"Transcoding MMR: %u\n", x);
11823 }
else if ((strncmp(attrib,
"t38faxtranscodingjbig",
sizeof(
"t38faxtranscodingjbig") - 1) == 0)) {
11824 if (sscanf(attrib,
"t38faxtranscodingjbig:%30u", &x) == 1) {
11825 ast_debug(3,
"Transcoding JBIG: %u\n", x);
11834 }
else if ((sscanf(attrib,
"t38faxratemanagement:%255s", s) == 1)) {
11835 ast_debug(3,
"RateManagement: %s\n", s);
11836 if (!strcasecmp(s,
"localTCF"))
11838 else if (!strcasecmp(s,
"transferredTCF"))
11841 }
else if ((sscanf(attrib,
"t38faxudpec:%255s", s) == 1)) {
11843 if (!strcasecmp(s,
"t38UDPRedundancy")) {
11845 }
else if (!strcasecmp(s,
"t38UDPFEC")) {
11864 sprintf(supported_value,
"replaces%s%s",
11867 res =
add_header(req,
"Supported", supported_value);
11905 snprintf(clen,
sizeof(clen),
"%d", dialog->
maxforwards);
11907 return add_header(req,
"Max-Forwards", clen);
11916 ast_log(
LOG_WARNING,
"finalize_content() called on a message that has already been finalized\n");
11934 ast_log(
LOG_WARNING,
"Can't add more content when the content has been finalized\n");
11967 return copied ? 0 : -1;
11991 char leftmost[512], *others, *rport;
11995 others = strchr(leftmost,
',');
12000 rport = strstr(leftmost,
";rport");
12001 if (rport && *(rport+6) ==
'=')
12008 rport = strstr(leftmost,
";rport");
12011 end = strchr(rport + 1,
';');
12013 memmove(rport, end, strlen(end) + 1);
12019 snprintf(
new,
sizeof(
new),
"%s;received=%s;rport=%d%s%s",
12022 others ?
"," :
"", others ? others :
"");
12025 snprintf(
new,
sizeof(
new),
"%s;received=%s%s%s",
12027 others ?
"," :
"", others ? others :
"");
12069 char *trans, *maddr,
hostname[256];
12073 int tls_on =
FALSE;
12076 ast_verbose(
"set_destination: Parsing <%s> for address/port to send to\n", uri);
12078 if ((trans =
strcasestr(uri,
";transport="))) {
12079 trans += strlen(
";transport=");
12081 if (!strncasecmp(trans,
"ws", 2)) {
12083 ast_verbose(
"set_destination: URI is for WebSocket, we can't set destination\n");
12089 h = strchr(uri,
'@');
12094 if (!strncasecmp(h,
"sip:", 4)) {
12096 }
else if (!strncasecmp(h,
"sips:", 5)) {
12101 hn = strcspn(h,
";>") + 1;
12102 if (hn >
sizeof(hostname))
12116 maddr = strstr(h,
"maddr=");
12121 hn = strspn(maddr,
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" 12122 "0123456789-.:[]") + 1;
12123 if (hn >
sizeof(hostname))
12145 ast_verbose(
"set_destination: set destination to %s\n",
12154 memset(resp, 0,
sizeof(*resp));
12176 memset(req, 0,
sizeof(*req));
12231 if ((msg[0] >=
'1' && msg[0] <=
'3') || !strncmp(msg,
"485", 3))
12238 if (msg[0] ==
'2' || msg[0] ==
'3' || !strncmp(msg,
"485", 3))
12247 if (msg[0] ==
'3' || !strncmp(msg,
"485", 3))
12253 if (msg[0] >=
'2' && msg[0] <=
'6')
12276 if (msg[0] ==
'1' || msg[0] ==
'2')
12280 if (!
strcasestr(ot,
"tag=") && strncmp(msg,
"100", 3)) {
12284 snprintf(newto,
sizeof(newto),
"%s;tag=%s", ot, p->
theirtag);
12286 snprintf(newto,
sizeof(newto),
"%s;tag=%s", ot, p->
tag);
12304 add_header(resp,
"Session-Expires", se_hdr);
12329 char *brackets = strchr(contact_uri,
'<');
12330 snprintf(contact,
sizeof(contact),
"%s%s%s;expires=%d", brackets ?
"" :
"<", contact_uri, brackets ?
"" :
">", p->
expiry);
12354 ast_log(
LOG_WARNING,
"error processing via header, will send response to originating address\n");
12368 const char *ot, *of;
12369 int is_strict =
FALSE;
12383 }
else if (newbranch && (sipmethod ==
SIP_INVITE)) {
12387 }
else if (newbranch) {
12401 }
else if (sipmethod ==
SIP_ACK) {
12424 snprintf(tmp,
sizeof(tmp),
"%u %s", seqno,
sip_methods[sipmethod].
text);
12460 snprintf(newto,
sizeof(newto),
"%s;tag=%s", ot, p->
theirtag);
12461 else if (!is_outbound)
12462 snprintf(newto,
sizeof(newto),
"%s;tag=%s", ot, p->
tag);
12464 snprintf(newto,
sizeof(newto),
"%s", ot);
12514 uint32_t seqno = 0;
12516 if (reliable && (sscanf(
sip_get_header(req,
"CSeq"),
"%30u ", &seqno) != 1)) {
12524 && (!strncmp(msg,
"180", 3) || !strncmp(msg,
"183", 3))) {
12533 if (!strncmp(msg,
"302", 3)) {
12543 int hangupcause = 0;
12551 if (sscanf(msg,
"%30d ", &respcode))
12556 sprintf(buf,
"Q.850;cause=%i", hangupcause & 0x7f);
12564 add_header(&resp,
"X-Asterisk-HangupCauseCode", buf);
12574 if (need_new_etag) {
12618 p->
method = intended_method;
12631 if (useglobal_nat && addr) {
12666 add_header(&resp,
"Unsupported", unsupported);
12674 char minse_str[20];
12679 snprintf(minse_str,
sizeof(minse_str),
"%d", minse_int);
12698 time_t t = time(
NULL);
12701 strftime(tmp,
sizeof(tmp),
"%a, %d %b %Y %T GMT", &tm);
12710 snprintf(tmp,
sizeof(tmp),
"%d", expires);
12737 add_header(&resp,
"Accept",
"application/sdp");
12747 snprintf(tmp,
sizeof(tmp),
"%d", minexpires);
12758 uint32_t seqno = 0;
12760 if (reliable && (sscanf(
sip_get_header(req,
"CSeq"),
"%30u ", &seqno) != 1)) {
12769 snprintf(tmp,
sizeof(tmp),
"Digest algorithm=MD5, realm=\"%s\", nonce=\"%s\"%s", p->
realm, nonce, stale ?
", stale=true" :
"");
12791 if (strncasecmp(from,
"sip:", 4)) {
12803 if ((a = strchr(from,
';')))
12806 for (a = from; *a !=
'\0'; ++
a) {
12807 if (*a ==
':' && bracket == 0) {
12810 }
else if (*a ==
'[') {
12812 }
else if (*a ==
']') {
12816 if ((a = strchr(from,
'@'))) {
12908 size_t hdr_len_name;
12909 size_t hdr_len_value;
12913 hdr_len_name = strlen(hdr_name) + 1;
12914 hdr_len_value = strlen(hdr_value) + 1;
12916 node =
ast_calloc(1,
sizeof(*node) + hdr_len_name + hdr_len_value);
12922 strcpy(pos, hdr_name);
12923 pos += hdr_len_name;
12925 strcpy(pos, hdr_value);
12933 const char *content_type =
NULL;
12938 if (!strcasecmp(node->
name,
"Content-Type")) {
12940 content_type = node->
value;
12947 content_type =
"text/plain;charset=UTF-8";
12949 add_header(req,
"Content-Type", content_type);
12966 if (
'0' <= digit && digit <=
'9') {
12967 event = digit -
'0';
12968 }
else if (digit ==
'*') {
12970 }
else if (digit ==
'#') {
12972 }
else if (
'A' <= digit && digit <=
'D') {
12973 event = 12 + digit -
'A';
12974 }
else if (
'a' <= digit && digit <=
'd') {
12975 event = 12 + digit -
'a';
12980 snprintf(tmp,
sizeof(tmp),
"%d\r\n", event);
12981 add_header(req,
"Content-Type",
"application/dtmf");
12985 snprintf(tmp,
sizeof(tmp),
"Signal=%c\r\nDuration=%u\r\n", digit, duration);
12986 add_header(req,
"Content-Type",
"application/dtmf-relay");
13000 char lid_name_buf[128];
13004 const char *fromdomain;
13005 const char *privacy =
NULL;
13006 const char *screen =
NULL;
13024 lid_name = lid_num;
13038 !strcmp(
"anonymous.invalid", fromdomain))) {
13050 ast_str_set(&tmp, -1,
"\"%s\" <sip:%s@%s>", lid_name_buf, lid_num, fromdomain);
13058 ast_str_set(&tmp, -1,
"\"%s\" <sip:%s@%s>", lid_name_buf, lid_num, fromdomain);
13065 ast_str_set(&tmp, -1,
"\"%s\" <sip:%s@%s>;party=%s", lid_name_buf, lid_num, fromdomain, p->
outgoing_call ?
"calling" :
"called");
13067 switch (lid_pres) {
13101 ast_str_append(&tmp, -1,
";privacy=%s;screen=%s", privacy, screen);
13113 const char *xml_is_a_huge_waste_of_space =
13114 "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n" 13115 " <media_control>\r\n" 13116 " <vc_primitive>\r\n" 13117 " <to_encoder>\r\n" 13118 " <picture_fast_update>\r\n" 13119 " </picture_fast_update>\r\n" 13120 " </to_encoder>\r\n" 13121 " </vc_primitive>\r\n" 13122 " </media_control>\r\n";
13123 add_header(req,
"Content-Type",
"application/media_control+xml");
13142 if ((username = ice->
get_ufrag(instance))) {
13190 ice->
start(instance);
13198 const char *fingerprint;
13246 int *min_packet_size,
13247 int *max_packet_size)
13251 unsigned int rate, framing;
13265 ast_str_append(a_buf, 0,
"a=rtpmap:%d %s/%u/2\r\n", rtp_code, mime, rate);
13267 ast_str_append(a_buf, 0,
"a=rtpmap:%d %s/%u\r\n", rtp_code, mime, rate);
13279 ast_str_append(a_buf, 0,
"a=fmtp:%d bitrate=64000\r\n", rtp_code);
13287 if (framing && (framing < *min_packet_size)) {
13288 *min_packet_size = framing;
13292 if ((*min_packet_size) == 0 && framing) {
13293 *min_packet_size = framing;
13305 int debug,
int *min_packet_size)
13308 const char *subtype;
13324 ast_str_append(a_buf, 0,
"a=rtpmap:%d %s/%u\r\n", rtp_code, subtype, rate);
13336 int debug,
int *min_packet_size)
13415 int use_externip = 0;
13508 if (!tmp || dtls_enabled) {
13518 char *
copy = a_crypto;
13525 if (
ast_asprintf(&a_crypto,
"%sa=crypto:%s\r\n", copy, orig_crypto) == -1) {
13547 int doing_directmedia =
FALSE;
13562 char connection[256];
13563 char *session_time =
"t=0 0\r\n";
13564 char bandwidth[256] =
"";
13580 int needaudio =
FALSE;
13581 int needvideo =
FALSE;
13582 int needtext =
FALSE;
13584 int min_audio_packet_size = 0;
13585 int max_audio_packet_size = 0;
13586 int min_video_packet_size = 0;
13587 int min_text_packet_size = 0;
13594 if (!alreadysent || !tmpcap) {
13596 goto add_sdp_cleanup;
13601 goto add_sdp_cleanup;
13612 if (oldsdp ==
FALSE)
13619 if (doing_directmedia) {
13632 ast_debug(2,
"This call needs video offers, but caller probably did not offer it!\n");
13633 }
else if (p->
vrtp) {
13635 ast_debug(2,
"This call needs video offers!\n");
13637 ast_debug(2,
"This call needs video offers, but there's no video support enabled!\n");
13650 ast_debug(2,
"This call needs text offers! \n");
13652 ast_debug(2,
"This call needs text offers, but there's no text support enabled ! \n");
13657 ast_debug(1,
"** Our capability: %s Video flag: %s Text flag: %s\n",
13659 p->
novideo ?
"True" :
"False", p->
notext ?
"True" :
"False");
13666 snprintf(owner,
sizeof(owner),
"o=%s %d %d IN %s %s\r\n",
13673 snprintf(connection,
sizeof(connection),
"c=IN %s %s\r\n",
13680 hold =
"a=recvonly\r\n";
13681 doing_directmedia =
FALSE;
13683 hold =
"a=inactive\r\n";
13684 doing_directmedia =
FALSE;
13686 hold =
"a=sendrecv\r\n";
13705 snprintf(bandwidth,
sizeof(bandwidth),
"b=CT:%d\r\n", p->
maxcallbitrate);
13710 if (!doing_directmedia) {
13734 if (!doing_directmedia) {
13774 add_codec_to_sdp(p, tmp_fmt, &m_audio, &a_audio, debug, &min_audio_packet_size, &max_audio_packet_size);
13790 add_codec_to_sdp(p, tmp_fmt, &m_audio, &a_audio, debug, &min_audio_packet_size, &max_audio_packet_size);
13792 add_vcodec_to_sdp(p, tmp_fmt, &m_video, &a_video, debug, &min_video_packet_size);
13809 ast_debug(3,
"-- Done with adding codecs to SDP\n");
13815 if (min_audio_packet_size) {
13816 ast_str_append(&a_audio, 0,
"a=ptime:%d\r\n", min_audio_packet_size);
13820 if (min_video_packet_size) {
13821 ast_str_append(&a_video, 0,
"a=ptime:%d\r\n", min_video_packet_size);
13825 if (min_text_packet_size) {
13826 ast_str_append(&a_text, 0,
"a=ptime:%d\r\n", min_text_packet_size);
13829 if (max_audio_packet_size) {
13830 ast_str_append(&a_audio, 0,
"a=maxptime:%d\r\n", max_audio_packet_size);
13834 ast_debug(1,
"Setting framing on incoming call: %u\n", min_audio_packet_size);
13838 if (!doing_directmedia) {
13894 ast_str_append(&a_modem, 0,
"a=T38FaxRateManagement:transferredTCF\r\n");
13897 ast_str_append(&a_modem, 0,
"a=T38FaxRateManagement:localTCF\r\n");
13908 ast_str_append(&a_modem, 0,
"a=T38FaxUdpEC:t38UDPRedundancy\r\n");
13920 add_header(resp,
"Content-Type",
"application/sdp");
13933 switch (offer->
type) {
14023 ao2_t_unlink(dialogs_rtpcheck, p,
"unlink pvt into dialogs_rtpcheck container");
14024 ao2_t_link(dialogs_rtpcheck, p,
"link pvt into dialogs_rtpcheck container");
14027 ast_debug(3,
"Done building SDP. Settling with this capability: %s\n",
14046 if (sscanf(
sip_get_header(req,
"CSeq"),
"%30u ", &seqno) != 1) {
14054 ast_log(
LOG_ERROR,
"Can't add SDP to response, since we have no UDPTL session allocated. Call-ID %s\n", p->
callid);
14072 dst->
data = duplicate;
14073 dst->
content = duplicate_content;
14117 ast_str_set(&header, 0,
"<%s>;purpose=call-completion;m=%s", uri,
"NR");
14129 if (sscanf(
sip_get_header(req,
"CSeq"),
"%30u ", &seqno) != 1) {
14134 if (rpid ==
TRUE) {
14149 ast_log(
LOG_ERROR,
"Can't add SDP to response, since we have no RTP session allocated. Call-ID %s\n", p->
callid);
14160 char *local_rlpart1;
14175 if (!strcasecmp(local_rlpart1,
"SIP/2.0") ) {
14181 ast_debug(3,
"Oops. Bogus uri in <> %s\n", e);
14191 if (strcasecmp(e,
"SIP/2.0") ) {
14192 ast_debug(3,
"Skipping packet - Bad request protocol %s\n", e);
14244 if (oldsdp ==
TRUE)
14245 add_header(&req,
"X-asterisk-Info",
"SIP re-invite (Session-Timers)");
14247 add_header(&req,
"X-asterisk-Info",
"SIP re-invite (External RTP bridge)");
14278 atsign = strchr(uri,
'@');
14282 atsign = strchr(atsign,
';');
14322 if (record_route) {
14325 if (!strncmp(record_route_uri,
"sips:", 5)) {
14332 if (!strncmp(contact_uri,
"sips:", 5)) {
14362 if (!strncmp(route_uri,
"sips:", 5)) {
14412 #define SIPHEADER 256 14418 const char *l =
NULL;
14419 const char *n =
NULL;
14420 const char *
d =
NULL;
14421 const char *urioptions =
"";
14423 int cid_has_name = 1;
14424 int cid_has_num = 1;
14444 urioptions =
";user=phone";
14517 ret =
ast_str_set(&from, 0,
"<sip:%s@%s:%d>;tag=%s", tmp_l, d, ourport, p->
tag);
14519 ret =
ast_str_set(&from, 0,
"<sip:%s@%s>;tag=%s", tmp_l, d, p->
tag);
14523 ast_log(
LOG_ERROR,
"The From header was truncated in call '%s'. This call setup will fail.\n", p->
callid);
14532 if (cid_has_name || !cid_has_num) {
14539 name_len = strlen(n);
14546 memmove(from_buf + name_len + 3, from_buf, written + 1);
14548 memcpy(from_buf + 1, n, name_len);
14549 from_buf[name_len + 1] =
'"';
14550 from_buf[name_len + 2] =
' ';
14591 if (!strchr(p->
todnid,
'@')) {
14610 ast_log(
LOG_ERROR,
"The To header was truncated in call '%s'. This call setup will fail.\n", p->
callid);
14656 const char *reason;
14657 const char *quote_str;
14658 char header_text[256];
14685 quote_str = *reason ==
'\"' ||
sip_is_token(reason) ?
"" :
"\"";
14690 snprintf(header_text,
sizeof(header_text),
"<sip:%s@%s>;reason=%s%s%s",
14693 quote_str, reason, quote_str);
14701 snprintf(header_text,
sizeof(header_text),
"\"%s\" <sip:%s@%s>;reason=%s%s%s",
14705 quote_str, reason, quote_str);
14727 dialog_unref(pvt,
"create_addr failed in transmit_publish. Unref dialog");
14742 dialog_unref(pvt,
"Done with the sip_pvt allocated for transmitting PUBLISH");
14769 reqprep(&req, p, sipmethod, 0, init ? 0 : 1);
14785 add_header(&req,
"Event",
"message-summary");
14786 add_header(&req,
"Accept",
"application/simple-message-summary");
14788 add_header(&req,
"Event",
"call-completion");
14789 add_header(&req,
"Accept",
"application/call-completion");
14816 add_header(&req,
"Session-Expires", i2astr);
14841 if (!strncmp(
ast_var_name(current),
"SIPADDHEADER", strlen(
"SIPADDHEADER"))) {
14842 char *content, *
end;
14847 if (*headdup ==
'"') {
14850 if ((content = strchr(headdup,
':'))) {
14854 end = content + strlen(content) -1;
14861 ast_debug(1,
"Adding SIP Header \"%s\" with content :%s: \n", headdup, content);
14880 }
else if (p->
rtp) {
14894 add_header(&req,
"Event",
"call-completion");
14901 add_header(&req,
"Content-Type",
"application/pidf+xml");
14929 ao2_t_ref(mwi, -1,
"Scheduled mwi resub complete");
14940 ao2_t_ref(mwi, -1,
"Stop scheduled mwi resub"));
14948 ao2_t_ref(mwi, -1,
"Shutdown MWI subscription action");
14954 ao2_t_ref(mwi, +1,
"Shutdown MWI subscription action");
14957 ao2_t_ref(mwi, -1,
"Failed to schedule shutdown MWI subscription action");
14971 int ms = sched_data->
ms;
14976 ao2_t_ref(mwi, -1,
"Stop scheduled mwi resub"));
14978 ao2_t_ref(mwi, +1,
"Schedule mwi resub");
14980 if (mwi->
resub < 0) {
14982 ao2_t_ref(mwi, -1,
"Failed to schedule mwi resub");
14985 ao2_t_ref(mwi, -1,
"Start MWI subscription action");
14993 sched_data =
ast_malloc(
sizeof(*sched_data));
14998 sched_data->
mwi = mwi;
14999 sched_data->
ms = ms;
15000 ao2_t_ref(mwi, +1,
"Start MWI subscription action");
15003 ao2_t_ref(mwi, -1,
"Failed to schedule start MWI subscription action");
15011 const char *old_str;
15015 ast_debug(1,
"Empty sockaddr change...ignoring!\n");
15032 const char *old_str;
15036 ast_debug(1,
"Empty sockaddr change...ignoring!\n");
15061 const char *old_str;
15065 ast_debug(1,
"Empty sockaddr change...ignoring!\n");
15083 ao2_t_ref(mwi, +1,
"dnsmgr reference to mwi");
15086 ao2_t_ref(mwi, -1,
"dnsmgr disabled, remove reference");
15166 struct timeval tv = {0,};
15189 return (strstr(p->
useragent,
"Digium")) ? 1 : 0;
15196 const char *statestring =
"terminated";
15197 const char *pidfstate =
"--";
15198 const char *pidfnote =
"Ready";
15201 switch (data->
state) {
15205 pidfstate =
"busy";
15206 pidfnote =
"Ringing";
15209 statestring =
"early";
15211 pidfstate =
"busy";
15212 pidfnote =
"Ringing";
15215 statestring =
"confirmed";
15217 pidfstate =
"busy";
15218 pidfnote =
"On the phone";
15221 statestring =
"confirmed";
15223 pidfstate =
"busy";
15224 pidfnote =
"On the phone";
15227 statestring =
"terminated";
15229 pidfstate =
"away";
15230 pidfnote =
"Unavailable";
15233 statestring =
"confirmed";
15235 pidfstate =
"busy";
15236 pidfnote =
"On hold";
15247 char *individual_hint =
NULL;
15248 int hint_count = 0, unavailable_count = 0;
15251 if ((hint2 = strrchr(hint,
','))) {
15256 while ((individual_hint =
strsep(&hint2,
"&"))) {
15260 unavailable_count++;
15266 if (hint_count > 0 && hint_count == unavailable_count) {
15268 pidfstate =
"away";
15269 pidfnote =
"Not online";
15273 switch (subscribed) {
15277 "<?xml version=\"1.0\"?>\n" 15278 "<!DOCTYPE presence PUBLIC \"-//IETF//DTD RFCxxxx XPIDF 1.0//EN\" \"xpidf.dtd\">\n" 15280 ast_str_append(tmp, 0,
"<presentity uri=\"%s;method=SUBSCRIBE\" />\n", mfrom);
15282 ast_str_append(tmp, 0,
"<address uri=\"%s;user=ip\" priority=\"0.800000\">\n", mto);
15289 "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" 15290 "<presence xmlns=\"urn:ietf:params:xml:ns:pidf\" \nxmlns:pp=\"urn:ietf:params:xml:ns:pidf:person\"\nxmlns:es=\"urn:ietf:params:xml:ns:pidf:rpid:status:rpid-status\"\nxmlns:ep=\"urn:ietf:params:xml:ns:pidf:rpid:rpid-person\"\nentity=\"%s\">\n", mfrom);
15292 if (pidfstate[0] !=
'-') {
15293 ast_str_append(tmp, 0,
"<ep:activities><ep:%s/></ep:activities>\n", pidfstate);
15298 ast_str_append(tmp, 0,
"<contact priority=\"1\">%s</contact>\n", mto);
15299 if (pidfstate[0] ==
'b')
15300 ast_str_append(tmp, 0,
"<status><basic>open</basic></status>\n");
15309 ast_str_append(tmp, 0,
"<digium_presence type=\"%s\" subtype=\"%s\">%s</digium_presence>\n",
15315 "PresenceState: %s\r\n" 15326 ast_str_append(tmp, 0,
"<dialog-info xmlns=\"urn:ietf:params:xml:ns:dialog-info\" version=\"%u\" state=\"%s\" entity=\"%s\">\n", p->
dialogver, full ?
"full" :
"partial", mto);
15353 static char *anonymous =
"anonymous";
15354 static char *invalid =
"anonymous.invalid";
15356 char *connected_num;
15358 int cid_num_restricted, connected_num_restricted;
15365 S_COR(cid_num_restricted, anonymous,
15368 need = strlen(cid_num) + (cid_num_restricted ? strlen(invalid) :
15372 snprintf(local_target, need,
"sip:%s@%s", cid_num,
15373 cid_num_restricted ? invalid : p->
fromdomain);
15379 local_display,
sizeof(local_display));
15384 S_COR(connected_num_restricted, anonymous,
15387 need = strlen(connected_num) + (connected_num_restricted ? strlen(invalid) :
15391 snprintf(remote_target, need,
"sip:%s@%s", connected_num,
15392 connected_num_restricted ? invalid : p->
fromdomain);
15398 remote_display,
sizeof(remote_display));
15407 ast_str_append(tmp, 0,
"<dialog id=\"%s\" call-id=\"pickup-%s\" local-tag=\"%s\" remote-tag=\"%s\" direction=\"recipient\">\n",
15410 ast_str_append(tmp, 0,
"<dialog id=\"%s\" call-id=\"pickup-%s\" direction=\"recipient\">\n",
15417 "<identity display=\"%s\">%s</identity>\n" 15418 "<target uri=\"%s\"/>\n" 15421 "<identity display=\"%s\">%s</identity>\n" 15422 "<target uri=\"%s\"/>\n" 15424 remote_display, remote_target, remote_target, local_display, local_target, local_target);
15426 ast_str_append(tmp, 0,
"<dialog id=\"%s\" direction=\"recipient\">\n", exten);
15435 "<param pname=\"+sip.rendering\" pvalue=\"no\"/>\n" 15436 "</target>\n</local>\n", mto);
15450 char uri[
SIPBUFSIZE +
sizeof(
"cc-URI: \r\n") - 1];
15451 char state_str[64];
15452 char subscription_state_hdr[64];
15455 ast_log(
LOG_WARNING,
"Invalid state provided for transmit_cc_notify (%u)\n", state);
15461 add_header(&req,
"Event",
"call-completion");
15462 add_header(&req,
"Content-Type",
"application/call-completion");
15463 snprintf(subscription_state_hdr,
sizeof(subscription_state_hdr),
"active;expires=%d", subscription->
expiry);
15464 add_header(&req,
"Subscription-State", subscription_state_hdr);
15465 if (state == CC_READY) {
15467 snprintf(uri,
sizeof(uri),
"cc-URI: %s\r\n", agent_pvt->
notify_uri);
15470 if (state == CC_READY) {
15480 char from[256], to[256];
15481 char *
c, *mfrom, *mto;
15490 memset(from, 0,
sizeof(from));
15491 memset(to, 0,
sizeof(to));
15497 if (strncasecmp(c,
"sip:", 4) && strncasecmp(c,
"sips:", 5)) {
15506 if (strncasecmp(c,
"sip:", 4) && strncasecmp(c,
"sips:", 5)) {
15514 switch(data->
state) {
15517 add_header(&req,
"Subscription-State",
"terminated;reason=timeout");
15519 add_header(&req,
"Subscription-State",
"terminated;reason=probation");
15524 add_header(&req,
"Subscription-State",
"terminated;reason=noresource");
15528 add_header(&req,
"Subscription-State",
"active");
15530 add_header(&req,
"Subscription-State",
"terminated;reason=timeout");
15593 add_header(&req,
"Event",
"message-summary");
15595 ast_str_append(&out, 0,
"Messages-Waiting: %s\r\n", newmsgs ?
"yes" :
"no");
15602 ast_str_append(&out, 0,
"Message-Account: sip:%s@%s:%d\r\n", exten, domain, ourport);
15608 ast_str_append(&out, 0,
"Message-Account: sip:%s@%s\r\n", exten, domain);
15621 add_header(&req,
"Subscription-State",
"active");
15623 add_header(&req,
"Subscription-State",
"terminated;reason=timeout");
15642 snprintf(tmp,
sizeof(tmp),
"refer;id=%d", cseq);
15644 add_header(&req,
"Subscription-state", terminate ?
"terminated;reason=noresource" :
"active");
15645 add_header(&req,
"Content-Type",
"message/sipfrag;version=2.0");
15649 snprintf(tmp,
sizeof(tmp),
"SIP/2.0 %s\r\n", message);
15673 if (!strncasecmp(channame,
"sip/", 4)) {
15679 struct sip_pvt tmp_dialog = {
15697 astman_send_error(s, m,
"Unable to build sip pvt data for notify (memory/socket error)");
15720 for (var = vars;
var; var = var->
next) {
15721 if (!strcasecmp(var->
name,
"Content")) {
15725 }
else if (!strcasecmp(var->
name,
"Content-Length")) {
15729 header = header->
next;
15746 dialog_unref(p,
"bump down the count of p since we're done with it.");
15804 add_header(&req,
"X-Asterisk-rpid-update",
"Yes");
15849 return map_x_s(regstatestrings, regstate,
"Unknown");
15902 ao2_t_ref(r, -1,
"Scheduled reregister timeout complete");
15927 int ms = sched_data->
ms;
15932 ao2_t_ref(reg, -1,
"Stop scheduled reregister timeout"));
15934 ao2_t_ref(reg, +1,
"Schedule reregister timeout");
15938 ao2_t_ref(reg, -1,
"Failed to schedule reregister timeout");
15941 ao2_t_ref(reg, -1,
"Start reregister timeout action");
15949 sched_data =
ast_malloc(
sizeof(*sched_data));
15954 sched_data->
reg = reg;
15955 sched_data->
ms = ms;
15956 ao2_t_ref(reg, +1,
"Start reregister timeout action");
15959 ao2_t_ref(reg, -1,
"Failed to schedule start reregister timeout action");
15993 ao2_t_ref(r, -1,
"Scheduled register timeout completed early");
16035 ao2_t_ref(r, -1,
"Scheduled register timeout complete");
16045 ao2_t_ref(reg, -1,
"Stop scheduled register timeout"));
16046 ao2_t_ref(reg, -1,
"Stop register timeout action");
16052 ao2_t_ref(reg, +1,
"Stop register timeout action");
16055 ao2_t_ref(reg, -1,
"Failed to schedule stop register timeout action");
16065 ao2_t_ref(reg, -1,
"Stop scheduled register timeout"));
16067 ao2_t_ref(reg, +1,
"Schedule register timeout");
16071 ao2_t_ref(reg, -1,
"Failed to schedule register timeout");
16073 ast_debug(1,
"Scheduled a registration timeout for %s id #%d \n",
16076 ao2_t_ref(reg, -1,
"Start register timeout action");
16082 ao2_t_ref(reg, +1,
"Start register timeout action");
16085 ao2_t_ref(reg, -1,
"Failed to schedule start register timeout action");
16096 memset(&addr, 0,
sizeof(addr));
16137 ao2_t_ref(r, +1,
"add reg ref for dnsmgr");
16141 ao2_t_ref(r, -1,
"remove reg ref, dnsmgr disabled");
16145 peer =
sip_unref_peer(peer,
"removing peer ref for dnsmgr_lookup");
16154 p =
dialog_ref(r->
call,
"getting a copy of the r->call dialog in transmit_register");
16166 ast_log(
LOG_WARNING,
"Unable to allocate registration transaction (memory or socket error)\n");
16203 ast_log(
LOG_WARNING,
"Probably a DNS error for registration to %s@%s, trying REGISTER again (after %d seconds)\n",
16226 r->
call =
dialog_ref(p,
"copying dialog into registry r->call");
16227 p->
registry =
ao2_t_bump(r,
"transmit_register: addref to p->registry in transmit_register");
16263 if (auth ==
NULL) {
16323 memset(digest, 0,
sizeof(digest));
16343 dialog_unref(p,
"p is finished here at the end of transmit_register");
16374 return p->
refer ? 1 : 0;
16394 return p->
notify ? 1 : 0;
16424 if (!strncasecmp(of,
"sip:", 4)) {
16426 }
else if (!strncasecmp(of,
"sips:", 5)) {
16433 if (strchr(dest,
'@')) {
16435 }
else if ((c = strchr(of,
'@'))) {
16439 snprintf(referto,
sizeof(referto),
"<sip%s:%s@%s>", use_tls ?
"s" :
"", dest, c);
16441 snprintf(referto,
sizeof(referto),
"<sip%s:%s>", use_tls ?
"s" :
"", dest);
16480 switch (charging) {
16536 reqprep(&resp, p, sipmethod, seqno, newbranch);
16538 add_header(&resp,
"Reason",
"SIP;cause=200;text=\"Call completed elsewhere\"");
16552 *header =
"WWW-Authenticate";
16553 *respheader =
"Authorization";
16555 *header =
"Proxy-Authenticate";
16556 *respheader =
"Proxy-Authorization";
16558 ast_verbose(
"-- wrong response code %u\n", code);
16559 *header = *respheader =
"Invalid";
16568 reqprep(&resp, p, sipmethod, seqno, newbranch);
16572 memset(digest, 0,
sizeof(digest));
16574 char *
dummy, *response;
16583 switch (sipmethod) {
16593 snprintf(buf,
sizeof(buf),
"Q.850;cause=%d", p->
hangupcause & 0x7f);
16598 snprintf(buf,
sizeof(buf),
"%d", p->
hangupcause);
16599 add_header(&resp,
"X-Asterisk-HangupCauseCode", buf);
16616 char *tablename = (realtimeregs) ?
"sipregs" :
"sippeers";
16620 ast_update_realtime(tablename,
"name", peer->
name,
"fullcontact",
"",
"ipaddr",
"",
"port",
"0",
"regseconds",
"0",
"regserver",
"",
"useragent",
"",
"lastms",
"0",
SENTINEL);
16632 if (socket->
type != transport) {
16634 socket->
type = transport;
16672 "peer_status",
"Unregistered",
16673 "cause",
"Expired");
16683 ast_debug(3,
"-REALTIME- peer expired registration. Name: %s. Realtime peer objects now %d\n", peer->
name,
rpeerobjs);
16688 ao2_t_unlink(peers, peer,
"ao2_unlink of peer from peers table");
16694 ao2_t_unlink(peers_by_ip, peer,
"ao2_unlink of peer from peers_by_ip table");
16699 memset(&peer->
addr, 0,
sizeof(peer->
addr));
16718 }
else if (foundpeer->
name != peer->
name) {
16749 char full_addr[128];
16762 if (
ast_db_get(
"SIP/Registry", peer->
name, data,
sizeof(data))) {
16768 snprintf(full_addr,
sizeof(full_addr),
"%s:%s",
args.addr,
args.port);
16774 if (
args.expiry_str) {
16775 expire = atoi(
args.expiry_str);
16780 if (
args.username) {
16783 if (
args.contact) {
16787 ast_debug(2,
"SIP Seeding peer from astdb: '%s' at %s@%s for %d\n",
16805 if (!
ast_db_get(
"SIP/RegistryPath", peer->
name, path,
sizeof(path))) {
16844 const char *rp, *
rh;
16856 if (strncasecmp(rh,
"Q.850", 5)) {
16862 rp = strstr(rh,
"cause=");
16863 if (rp && sscanf(rp + 6,
"%3d", &cause) == 1) {
16867 ast_verbose(
"Using Reason header for cause code: %d\n",
16882 int ret =
parse_uri(uri, scheme, user, pass, hostport, transport);
16885 if ((p = strchr(uri, (
int)
';'))) {
16894 char *hostport, *transport;
16895 char contact_buf[256];
16900 contact = contact_buf;
16911 ast_log(
LOG_WARNING,
"Invalid contact uri %s (missing sip: or sips:), attempting to use anyway\n", fullcontact);
16930 "resolve in DNS) : '%s'\n", hostport);
16939 !strncasecmp(fullcontact,
"sips", 4)) ?
16966 int expire = atoi(expires);
16967 char *curi =
NULL, *hostport =
NULL, *transport =
NULL;
16968 int transport_type;
16969 const char *useragent;
16971 char *firstcuri =
NULL;
16973 int wildcard_found = 0;
16974 int single_binding_found = 0;
16981 expires =
strsep(&s,
";");
16982 if (sscanf(expires + 9,
"%30d", &expire) != 1) {
17004 if (strchr(contact,
'<') ==
NULL)
17011 if (!strcasecmp(curi,
"*")) {
17012 wildcard_found = 1;
17014 single_binding_found = 1;
17017 if (wildcard_found && (
ast_strlen_zero(expires) || expire != 0 || single_binding_found)) {
17037 }
else if (!strcasecmp(curi,
"*") || !expire) {
17054 ast_log(
LOG_NOTICE,
"Not a valid SIP contact (missing sip:/sips:) trying to use anyway\n");
17069 oldsin = peer->
addr;
17073 ao2_t_unlink(peers_by_ip, peer,
"ao2_unlink of peer from peers_by_ip table");
17079 ast_debug(1,
"Store REGISTER's Contact header for call routing.\n");
17101 ast_debug(1,
"Store REGISTER's src-IP:port for call routing.\n");
17108 ast_log(
LOG_WARNING,
"Domain '%s' disallowed by contact ACL (violating IP %s)\n", hostport,
17125 ao2_t_link(peers_by_ip, peer,
"ao2_link into peers_by_ip table");
17143 if (peer->
expire == -1) {
17169 "peer_status",
"Registered",
17176 ast_verb(3,
"Registered SIP '%s' at %s\n", peer->
name,
17186 if (strcasecmp(useragent, peer->
useragent)) {
17216 if ((resp < 100) || (resp > 199)) {
17228 if (*header ==
'\0') {
17240 if (strchr(header,
'<')) {
17243 len = strlen(header);
17245 if (header && len) {
17265 ast_debug(2,
"build_path: do not use Path headers\n");
17268 ast_debug(2,
"build_path: try to build pre-loaded route-set by parsing Path headers\n");
17275 if (*header ==
'\0') {
17280 }
else if (pathbuf) {
17314 for (i = keys; i->
key !=
NULL; i++) {
17315 const char *separator =
",";
17317 if (strncasecmp(c, i->
key, strlen(i->
key)) != 0) {
17321 c += strlen(i->
key);
17342 const char *secret,
const char *md5secret,
int sipmethod,
17343 const char *uri,
enum xmittype reliable)
17345 const char *response;
17346 char *reqheader, *respheader;
17347 const char *authtoken;
17349 char resp_hash[256]=
"";
17351 int is_bogus_peer = 0;
17352 int wrongnonce =
FALSE;
17354 const char *usednonce = p->
nonce;
17360 [
K_RESP] = {
"response=",
"" },
17361 [
K_URI] = {
"uri=",
"" },
17362 [
K_USER] = {
"username=",
"" },
17363 [
K_NONCE] = {
"nonce=",
"" },
17374 response =
"401 Unauthorized";
17430 if (strcmp(username, keys[
K_USER].s) && !is_bogus_peer) {
17432 username, keys[
K_USER].s);
17451 snprintf(a1,
sizeof(a1),
"%s:%s:%s", username, p->
realm, secret);
17464 snprintf(resp,
sizeof(resp),
"%s:%s:%s", a1_hash, usednonce, a2_hash);
17468 good_response = keys[
K_RESP].
s &&
17469 !strncasecmp(keys[
K_RESP].s, resp_hash, strlen(resp_hash)) &&
17472 if (good_response) {
17497 if (good_response) {
17498 append_history(p,
"AuthOK",
"Auth challenge successful for %s", username);
17549 if (!network_change_sub) {
17564 if (!acl_change_sub) {
17594 ast_verb(1,
"SIP, got a network change message, renewing all SIP registrations.\n");
17604 dialog_unref(p,
"the extensionstate containing this dialog ptr was destroyed");
17614 switch (data->
state) {
17718 const char *response =
"401 Unauthorized";
17719 const char *reqheader =
"Authorization";
17720 const char *respheader =
"WWW-Authenticate";
17721 const char *authtoken;
17731 [
K_NONCE] = {
"nonce=",
"" },
17766 for (i = keys; i->key !=
NULL; i++) {
17767 const char *separator =
",";
17769 if (strncasecmp(c, i->key, strlen(i->key)) != 0) {
17773 c += strlen(i->key);
17782 if (i->key == NULL) {
17818 while (*t && *t >
' ' && *t !=
';') {
17925 int expire = atoi(expires);
17929 expire = atoi(expires + 9);
17948 sip_unref_peer(peer,
"register_verify: sip_unref_peer: from sip_find_peer operation");
17959 ast_log(
LOG_ERROR,
"Peer '%s' is trying to register, but not configured as host=dynamic\n", peer->
name);
18017 ao2_t_ref(peer, -1,
"failed to allocate Stasis endpoint, drop peer");
18021 ao2_t_link(peers, peer,
"link peer into peer table");
18023 ao2_t_link(peers_by_ip, peer,
"link peer into peers-by-ip table");
18052 "peer_status",
"Registered",
18085 "peer_status",
"Rejected",
18086 "cause",
"AUTH_SECRET_FAILED",
18087 "address", peer_addr,
18088 "port", peer_port);
18106 "peer_status",
"Rejected",
18108 "address", peer_addr,
18109 "port", peer_port);
18120 "peer_status",
"Rejected",
18121 "cause",
"AUTH_PEER_NOT_DYNAMIC",
18122 "address", peer_addr,
18123 "port", peer_port);
18132 "peer_status",
"Rejected",
18134 "address", peer_addr,
18135 "port", peer_port);
18150 sip_unref_peer(peer,
"register_verify: sip_unref_peer: tossing stack peer pointer at end of func");
18159 if (!strcmp(reason,
"unknown")) {
18161 }
else if (!strcmp(reason,
"user-busy")) {
18163 }
else if (!strcmp(reason,
"no-answer")) {
18165 }
else if (!strcmp(reason,
"unavailable")) {
18167 }
else if (!strcmp(reason,
"unconditional")) {
18169 }
else if (!strcmp(reason,
"time-of-day")) {
18171 }
else if (!strcmp(reason,
"do-not-disturb")) {
18173 }
else if (!strcmp(reason,
"deflection")) {
18175 }
else if (!strcmp(reason,
"follow-me")) {
18177 }
else if (!strcmp(reason,
"out-of-service")) {
18179 }
else if (!strcmp(reason,
"away")) {
18196 char emptyname[1] =
"";
18199 int is_anonymous = 0, do_update = 1, no_name = 0;
18224 cid_num = (
char *)p->
cid_num;
18233 cid_name = (
char *)emptyname;
18252 if (!is_anonymous) {
18273 char *privacy =
"";
18297 if (*start ==
'"') {
18299 end = strchr(start,
'"');
18308 start = end = strchr(start,
'<');
18313 while (--end >= cid_name && *end < 33) {
18321 end = strchr(start,
'@');
18325 if (strncasecmp(start,
"sip:", 4))
18327 cid_num = start + 4;
18332 end = strchr(start,
'>');
18342 end = strchr(start,
';');
18345 if (!strncasecmp(start,
"privacy=", 8))
18346 privacy = start + 8;
18347 else if (!strncasecmp(start,
"screen=", 7))
18348 screen = start + 7;
18352 if (!strcasecmp(privacy,
"full")) {
18353 if (!strcasecmp(screen,
"yes"))
18355 else if (!strcasecmp(screen,
"no"))
18358 if (!strcasecmp(screen,
"yes"))
18360 else if (!strcasecmp(screen,
"no"))
18396 char tmp[256], *
exten, *rexten, *rdomain, *rname =
NULL;
18397 char *params, *reason_param =
NULL;
18403 req = oreq ? oreq : &p->
initreq;
18409 if ((params = strchr(tmp,
'>'))) {
18410 params = strchr(params,
';');
18414 if (!strncasecmp(exten,
"sip:", 4)) {
18416 }
else if (!strncasecmp(exten,
"sips:", 5)) {
18427 while (*params ==
';' || *params ==
' ')
18430 if ((reason_param =
strcasestr(params,
"reason="))) {
18433 if ((end = strchr(reason_param,
';'))) {
18440 rexten =
strsep(&rdomain,
"@");
18445 ast_verbose(
"RDNIS for this call is %s (reason %s)\n", exten,
S_OR(reason_param,
""));
18449 if (*tmp ==
'\"') {
18452 end_quote = strchr(rname,
'\"');
18462 if (name && rname) {
18470 if (*reason_param ==
'"') {
18475 if (*reason_code < 0) {
18510 char tmp[256] =
"", *uri, *unused_password, *
domain;
18516 const char *pickupexten;
18519 ast_log(
LOG_ERROR,
"Unable to retrieve pickup configuration options. Unable to detect call pickup extension\n");
18523 pickupexten = pickup_cfg->pickupexten;
18586 domain_context[0] =
'\0';
18640 || !strcmp(decoded_uri, pickupexten)) {
18657 if (cc_recall_core_id) {
18658 *cc_recall_core_id = agent->
core_id;
18668 || !strncmp(decoded_uri, pickupexten, strlen(decoded_uri)))) {
18697 struct sip_pvt tmp_dialog = {
18702 ast_debug(4,
"Looking for callid %s (fromtag %s totag %s)\n", callid, fromtag ? fromtag :
"<no fromtag>", totag ? totag :
"<no totag>");
18707 sip_pvt_ptr =
ao2_t_find(dialogs, &tmp_dialog,
OBJ_POINTER,
"ao2_find of dialog in dialogs table");
18712 unsigned char frommismatch = 0, tomismatch = 0;
18715 ast_debug(4,
"Matched %s call for callid=%s - no from tag specified, pedantic check fails\n",
18716 sip_pvt_ptr->outgoing_call ==
TRUE ?
"OUTGOING":
"INCOMING", sip_pvt_ptr->callid);
18721 ast_debug(4,
"Matched %s call for callid=%s - no to tag specified, pedantic check fails\n",
18722 sip_pvt_ptr->outgoing_call ==
TRUE ?
"OUTGOING":
"INCOMING", sip_pvt_ptr->callid);
18739 frommismatch = !!strcmp(fromtag, sip_pvt_ptr->theirtag);
18740 tomismatch = !!strcmp(totag, sip_pvt_ptr->tag);
18746 if (frommismatch) {
18747 ast_debug(4,
"Matched %s call for callid=%s - pedantic from tag check fails; their tag is %s our tag is %s\n",
18748 sip_pvt_ptr->outgoing_call ==
TRUE ?
"OUTGOING":
"INCOMING", sip_pvt_ptr->callid,
18749 fromtag, sip_pvt_ptr->theirtag);
18752 ast_debug(4,
"Matched %s call for callid=%s - pedantic to tag check fails; their tag is %s our tag is %s\n",
18753 sip_pvt_ptr->outgoing_call ==
TRUE ?
"OUTGOING":
"INCOMING", sip_pvt_ptr->callid,
18754 totag, sip_pvt_ptr->tag);
18761 ast_debug(4,
"Matched %s call - their tag is %s Our tag is %s\n",
18762 sip_pvt_ptr->outgoing_call ==
TRUE ?
"OUTGOING":
"INCOMING",
18763 sip_pvt_ptr->theirtag, sip_pvt_ptr->tag);
18765 *out_pvt = sip_pvt_ptr;
18771 if (!sip_pvt_ptr) {
18777 sip_pvt_ptr =
NULL;
18788 if (strcmp(prefix,
"*") == 0) {
18792 for (i = 0; i < req->
headers; i++) {
18795 int hdrlen = strcspn(header,
" \t:");
18797 if (hdrlen > 0 && *val ==
':') {
18798 ast_str_set(&pbxvar, -1,
"~HASH~TRANSFER_DATA~%.*s~", hdrlen, header);
18814 const char *p_referred_by =
NULL;
18815 char *h_refer_to =
NULL;
18816 char *h_referred_by =
NULL;
18818 const char *p_refer_to;
18819 char *referred_by_uri =
NULL;
18822 const char *transfer_context =
NULL;
18825 req = outgoing_req;
18826 refer = transferer->
refer;
18839 if (!strncasecmp(refer_to,
"sip:", 4)) {
18841 }
else if (!strncasecmp(refer_to,
"sips:", 5)) {
18844 ast_log(
LOG_WARNING,
"Can't transfer to non-sip: URI. (Refer-to: %s)?\n", refer_to);
18852 if (transferer->
owner) {
18867 const char *get_xfrdata;
18883 if (!owner_relock) {
18884 ast_debug(3,
"Unable to reacquire owner channel lock, channel is gone\n");
18894 if (!strncasecmp(referred_by_uri,
"sip:", 4)) {
18895 referred_by_uri += 4;
18896 }
else if (!strncasecmp(referred_by_uri,
"sips:", 5)) {
18897 referred_by_uri += 5;
18899 ast_log(
LOG_WARNING,
"Huh? Not a sip: header (Referred-by: %s). Skipping.\n", referred_by_uri);
18900 referred_by_uri =
NULL;
18905 if ((ptr =
strcasestr(refer_to,
"replaces="))) {
18906 char *to =
NULL, *from =
NULL, *callid;
18913 if ((ptr = strchr(callid,
';'))) {
18927 if ((to = strchr(ptr,
'&'))) {
18930 if ((to = strchr(ptr,
';'))) {
18938 if ((from = strchr(ptr,
'&'))) {
18941 if ((from = strchr(ptr,
';'))) {
18956 ast_debug(2,
"Attended transfer: Will use Replace-Call-ID : %s (No check of from/to tags)\n", refer->
replaces_callid);
18962 if ((ptr = strchr(refer_to,
'@'))) {
18967 if ((urioption = strchr(ptr,
';'))) {
18968 *urioption++ =
'\0';
18974 for (; *ptr !=
'\0'; ++ptr) {
18975 if (*ptr ==
':' && bracket == 0) {
18978 }
else if (*ptr ==
'[') {
18980 }
else if (*ptr ==
']') {
18995 if ((ptr = strchr(refer_to,
';')))
19001 if (referred_by_uri) {
19002 if ((ptr = strchr(referred_by_uri,
';')))
19011 if (transferer->
owner) {
19027 ast_verbose(
"SIP transfer to extension %s@%s by %s\n", refer_to, transfer_context,
S_OR(referred_by_uri,
"Unknown"));
19033 ast_verbose(
"Failed SIP Transfer to non-existing extension %s in context %s\n n", refer_to, transfer_context);
19045 char tmp[256] =
"", *
c, *
a;
19048 const char *transfer_context =
NULL;
19088 ast_debug(1,
"SIP Bye-also transfer to Extension %s@%s \n",
c, transfer_context);
19174 if (!strncasecmp(via,
"SIP/2.0/WS", 10)) {
19179 c = strchr(via,
',');
19184 c = strstr(via,
";rport");
19185 if (c && (c[6] !=
'=')) {
19191 maddr = strstr(via,
"maddr=");
19194 c = maddr + strspn(maddr,
"abcdefghijklmnopqrstuvwxyz" 19195 "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-.:[]");
19199 c = strchr(via,
';');
19203 c = strchr(via,
' ');
19207 if (strcasecmp(via,
"SIP/2.0/UDP") && strcasecmp(via,
"SIP/2.0/TCP") && strcasecmp(via,
"SIP/2.0/TLS")) {
19240 enum xmittype reliable,
char *calleridname,
char *uri2)
19258 char *uri_tmp, *callback =
NULL, *
dummy;
19260 parse_uri(uri_tmp,
"sip:,sips:,tel:", &callback, &dummy, &dummy, &dummy);
19271 ast_verbose(
"No matching peer for '%s' from '%s'\n",
19295 ast_debug(2,
"Found peer '%s' for '%s', but fails host access\n", peer->
name, of);
19296 sip_unref_peer(peer,
"sip_unref_peer: check_peer_ok: from sip_find_peer call, early return of AUTH_ACL_FAILED");
19299 if (debug && peer != bogus_peer) {
19300 ast_verbose(
"Found peer '%s' for '%s' from %s\n",
19392 ao2_t_ref(peer, 1,
"copy pointer into (*authpeer)");
19393 (*authpeer) = peer;
19475 sip_unref_peer(peer,
"check_peer_ok: sip_unref_peer: tossing temp ptr to peer from sip_find_peer");
19494 char calleridname[256];
19503 if (!(of = (
char *)
get_calleridname(ofbuf, calleridname,
sizeof(calleridname)))) {
19508 if (calleridname[0]) {
19514 if (!strncasecmp(t,
"sip:", 4)) {
19516 }
else if (!strncasecmp(t,
"sips:", 5)) {
19518 }
else if (!strncasecmp(t,
"tel:", 4)) {
19522 t = strchr(p->
exten,
'@');
19562 tmp =
strsep(&tmp,
";");
19584 namebuf = name =
ast_strdup(hdr + strlen(
"username=\""));
19585 name =
strsep(&name,
"\"");
19590 authpeer, reliable, calleridname, uri2);
19628 const char *response;
19640 response =
"403 Forbidden";
19646 response =
"480 Temporarily Unavailable";
19657 response =
"503 Service Unavailable";
19665 response =
"503 Service Unavailable";
19678 char name_buf[1024];
19679 char val_buf[1024];
19684 for (x = 0; x < req->
headers; x++) {
19687 if ((c = strchr(header,
':'))) {
19717 char from_name[50];
19721 if (strncmp(content_type,
"text/plain", strlen(
"text/plain"))) {
19742 if (buf[--len] !=
'\n') {
19751 ast_verbose(
"SIP Text message received: '%s'\n", buf);
19753 memset(&f, 0,
sizeof(f));
19773 ast_debug(1,
"MESSAGE outside of a call administratively disabled.\n");
19815 peer =
sip_unref_peer(peer,
"from sip_find_peer() in receive_message");
19829 switch (dest_result) {
19859 if (from_name[0]) {
19860 char from_buf[128];
19899 switch (dest_result) {
19918 #define FORMAT "%-25.25s %-15.15s %-15.15s \n" 19919 #define FORMAT2 "%-25.25s %-15.15s %-15.15s \n" 19922 int showall =
FALSE;
19928 e->
command =
"sip show inuse [all]";
19930 "Usage: sip show inuse [all]\n" 19931 " List all SIP devices usage counters and limits.\n" 19932 " Add option \"all\" to show all devices, not only those with a limit.\n";
19941 if (a->
argc == 4 && !strcmp(a->
argv[3],
"all"))
19950 snprintf(ilimits,
sizeof(ilimits),
"%d", peer->
call_limit);
19953 snprintf(iused,
sizeof(iused),
"%d/%d/%d", peer->
inuse, peer->
ringing, peer->
onhold);
19992 return map_x_s(stmodes, m,
"Unknown");
19997 return map_s_x(stmodes, s, -1);
20017 return map_x_s(strefresher_params, r,
"Unknown");
20022 return map_s_x(strefresher_params, s, -1);
20035 return map_x_s(strefreshers, r,
"Unknown");
20040 return map_x_s(autopeermodes, r,
"Unknown");
20050 snprintf(status, statuslen,
"LAGGED (%d ms)", peer->
lastms);
20052 }
else if (peer->
lastms) {
20053 snprintf(status, statuslen,
"OK (%d ms)", peer->
lastms);
20072 #define FORMAT2 "%-47.47s %9.9s %6.6s\n" 20073 #define FORMAT "%-47.47s %-9.9s %-6.6s\n" 20079 "Usage: sip show tcp\n" 20080 " Lists all active TCP/TLS sessions.\n";
20092 while ((th =
ao2_t_iterator_next(&i,
"iterate through tcp threads for 'sip show tcp'"))) {
20097 ao2_t_ref(th, -1,
"decrement ref from iterator");
20110 int havepattern =
FALSE;
20114 #define FORMAT "%-25.25s %-15.15s %-15.15s %-15.15s %-5.5s%-10.10s\n" 20118 e->
command =
"sip show users [like]";
20120 "Usage: sip show users [like <pattern>]\n" 20121 " Lists all known SIP users.\n" 20122 " Optional regular expression pattern is used to filter the user list.\n";
20130 if (!strcasecmp(a->
argv[3],
"like")) {
20131 if (regcomp(®exbuf, a->
argv[4], REG_EXTENDED | REG_NOSUB))
20133 havepattern =
TRUE;
20142 ast_cli(a->
fd,
FORMAT,
"Username",
"Secret",
"Accountcode",
"Def.Context",
"ACL",
"Forcerport");
20153 if (havepattern && regexec(®exbuf, user->
name, 0,
NULL, 0)) {
20171 regfree(®exbuf);
20181 char idtext[256] =
"";
20187 snprintf(idtext,
sizeof(idtext),
"ActionID: %s\r\n",
id);
20196 "Event: RegistryEntry\r\n" 20202 "DomainPort: %d\r\n" 20205 "RegistrationTime: %ld\r\n" 20215 (
long) iterator->
regtime.tv_sec);
20218 ao2_t_ref(iterator, -1,
"manager_show_registry iter");
20234 const char *
a[] = {
"sip",
"show",
"peers"};
20235 char idtext[256] =
"";
20239 snprintf(idtext,
sizeof(idtext),
"ActionID: %s\r\n",
id);
20257 e->
command =
"sip show peers [like]";
20259 "Usage: sip show peers [like <pattern>]\n" 20260 " Lists all known SIP peers.\n" 20261 " Optional regular expression pattern is used to filter the peer list.\n";
20276 return strcmp((*ap)->name, (*bp)->name);
20280 #define PEERS_FORMAT2 "%-25.25s %-39.39s %-3.3s %-10.10s %-10.10s %-3.3s %-8s %-11s %-32.32s %s\n" 20301 .peers_mon_online = 0,
20302 .peers_mon_offline = 0,
20303 .peers_unmon_online = 0,
20304 .peers_unmon_offline = 0,
20310 int total_peers = 0;
20320 snprintf(cont.
idtext,
sizeof(cont.
idtext),
"ActionID: %s\r\n",
id);
20326 if (!strcasecmp(argv[3],
"like")) {
20327 if (regcomp(&cont.
regexbuf, argv[4], REG_EXTENDED | REG_NOSUB)) {
20342 ast_cli(fd,
PEERS_FORMAT2,
"Name/username",
"Host",
"Dyn",
"Forcerport",
"Comedia",
"ACL",
"Port",
"Status",
"Description", (cont.
realtimepeers ?
"Realtime" :
""));
20364 sip_unref_peer(peer,
"unref peer because it's actually a user");
20374 peerarray[total_peers++] = peer;
20379 qsort(peerarray, total_peers,
sizeof(
struct sip_peer *), peercomparefunc);
20381 for(k = 0; k < total_peers; k++) {
20386 ast_cli(fd,
"%d sip peers [Monitored: %d online, %d offline Unmonitored: %d online, %d offline]\n",
20395 *total = total_peers;
20435 snprintf(name,
sizeof(name),
"%s/%s", peer->
name, peer->
username);
20440 pstatus =
peer_status(peer, status,
sizeof(status));
20441 if (pstatus == 1) {
20443 }
else if (pstatus == 0) {
20467 "Event: PeerEntry\r\n%s" 20468 "Channeltype: SIP\r\n" 20469 "ObjectName: %s\r\n" 20470 "ChanObjectType: peer\r\n" 20471 "IPaddress: %s\r\n" 20474 "AutoForcerport: %s\r\n" 20475 "Forcerport: %s\r\n" 20476 "AutoComedia: %s\r\n" 20478 "VideoSupport: %s\r\n" 20479 "TextSupport: %s\r\n" 20482 "RealtimeDevice: %s\r\n" 20483 "Description: %s\r\n" 20484 "Accountcode: %s\r\n" 20507 #undef PEERS_FORMAT2 20515 ast_cli(a->
fd,
"name: %s\ntype: peer\nobjflags: %d\nrefcount: %d\n\n",
20516 peer->
name, 0, refc);
20522 struct sip_pvt *pvt = userobj;
20526 ast_cli(a->
fd,
"name: %s\ntype: dialog\nobjflags: %d\nrefcount: %d\n\n",
20540 e->
command =
"sip show objects";
20542 "Usage: sip show objects\n" 20543 " Lists status of known SIP objects\n";
20553 ast_cli(a->
fd,
"-= Peer objects by IP =-\n\n");
20562 ao2_t_ref(reg, -1,
"sip_show_objects iter");
20566 ast_cli(a->
fd,
"-= Dialog objects:\n\n");
20600 return map_x_s(dtmfstr, mode,
"<error>");
20606 return map_s_x(dtmfstr, str, -1);
20620 return map_x_s(insecurestr, mode,
"<error>");
20633 return map_x_s(allowoverlapstr, mode,
"<error>");
20645 return map_x_s(trust_id_outboundstr, mode,
"<error>");
20653 char *oldcontext, *newcontext, *stalecontext, *stringp, newlist[
AST_MAX_CONTEXT];
20655 while ((oldcontext =
strsep(&old,
"&"))) {
20656 stalecontext =
NULL;
20659 while ((newcontext =
strsep(&stringp,
"&"))) {
20660 if (!strcmp(newcontext, oldcontext)) {
20662 stalecontext =
NULL;
20664 }
else if (strcmp(newcontext, oldcontext)) {
20665 stalecontext = oldcontext;
20683 struct sip_pvt *dialog = dialogobj;
20691 if (dialog->
rtp || dialog->
vrtp) {
20699 return match_status;
20714 struct sip_pvt *dialog = dialogobj;
20756 int prunepeer =
FALSE;
20760 int havepattern = 0;
20762 static const char *
const choices[] = {
"all",
"like",
NULL };
20766 e->
command =
"sip prune realtime [peer|all]";
20768 "Usage: sip prune realtime [peer [<name>|all|like <pattern>]|all]\n" 20769 " Prunes object(s) from the cache.\n" 20770 " Optional regular expression pattern is used to filter the objects.\n";
20773 if (a->
pos == 4 && !strcasecmp(a->
argv[3],
"peer")) {
20779 if (a->
pos == 5 && !strcasecmp(a->
argv[4],
"like"))
20787 if (!strcasecmp(name,
"peer") || !strcasecmp(name,
"like"))
20790 if (!strcasecmp(name,
"all")) {
20799 if (!strcasecmp(a->
argv[3],
"peer"))
20801 else if (!strcasecmp(a->
argv[3],
"like")) {
20806 if (!strcasecmp(name,
"like"))
20808 if (!multi && !strcasecmp(name,
"all")) {
20817 if (strcasecmp(a->
argv[4],
"like"))
20819 if (!strcasecmp(a->
argv[3],
"peer")) {
20828 if (multi && name) {
20829 if (regcomp(®exbuf, name, REG_EXTENDED | REG_NOSUB)) {
20842 if (name && regexec(®exbuf, pi->
name, 0,
NULL, 0)) {
20857 ast_cli(a->
fd,
"%d peers pruned.\n", pruned);
20859 ast_cli(a->
fd,
"No peers found to prune.\n");
20867 ao2_t_unlink(peers_by_ip, peer,
"unlinking peer from peers_by_ip also");
20870 ast_cli(a->
fd,
"Peer '%s' is not a Realtime peer, cannot be pruned.\n", name);
20872 ao2_t_link(peers, peer,
"link peer into peer table");
20874 ao2_t_link(peers_by_ip, peer,
"link peer into peers_by_ip table");
20877 ast_cli(a->
fd,
"Peer '%s' pruned.\n", name);
20878 sip_unref_peer(peer,
"sip_prune_realtime: sip_unref_peer: tossing temp peer ptr");
20880 ast_cli(a->
fd,
"Peer '%s' not found.\n", name);
20885 regfree(®exbuf);
20896 return "[Automatic]";
20898 return "[Configured]";
20908 #define FORMAT "%-40.40s %-20.20s %-16.16s\n" 20912 e->
command =
"sip show domains";
20914 "Usage: sip show domains\n" 20915 " Lists all configured SIP local domains.\n" 20916 " Asterisk only responds to SIP messages to local domains.\n";
20923 ast_cli(a->
fd,
"SIP Domain support not enabled.\n\n");
20926 ast_cli(a->
fd,
FORMAT,
"Our local SIP domains:",
"Context",
"Set by");
20964 e->
command =
"sip show peer";
20966 "Usage: sip show peer <name> [load]\n" 20967 " Shows all details on one SIP peer and the current status.\n" 20968 " Option \"load\" forces lookup of peer in realtime storage.\n";
20972 static const char *
const completions[] = {
"load",
NULL };
20983 char time[128] =
"";
20987 snprintf(status,
sizeof(status),
"PeerStatus: Unreachable\r\n");
20989 snprintf(status,
sizeof(status),
"PeerStatus: Lagged\r\n");
20990 snprintf(time,
sizeof(time),
"Time: %d\r\n", peer->
lastms);
20991 }
else if (peer->
lastms) {
20992 snprintf(status,
sizeof(status),
"PeerStatus: Reachable\r\n");
20993 snprintf(time,
sizeof(time),
"Time: %d\r\n", peer->
lastms);
20995 snprintf(status,
sizeof(status),
"PeerStatus: Unknown\r\n");
20998 snprintf(status,
sizeof(status),
"PeerStatus: Unmonitored\r\n");
21002 "Event: PeerStatus\r\n" 21003 "Privilege: System\r\n" 21004 "ChannelType: SIP\r\n" 21010 peer->
name, status, time, idText);
21024 snprintf(idText,
sizeof(idText),
"ActionID: %s\r\n",
id);
21029 if (strlen(peer_name) >= 4 && !strncasecmp(
"SIP/", peer_name, 4)) {
21074 body =
ast_json_pack(
"{s: s, s: s}",
"Peer", peer,
"ActionID",
id);
21092 load_realtime = (argc == 5 && !strcmp(argv[4],
"load")) ?
TRUE :
FALSE;
21105 }
else if (type == 0) {
21106 ast_cli(fd,
"Peer '%s' not found\n", argv[3]);
21139 e->
command =
"sip qualify peer";
21141 "Usage: sip qualify peer <name> [load]\n" 21142 " Requests a response from one SIP peer and the current status.\n" 21143 " Option \"load\" forces lookup of peer in realtime storage.\n";
21147 static const char *
const completions[] = {
"load",
NULL };
21177 return map_x_s(faxecmodes, faxec,
"Unknown");
21188 int x = 0, load_realtime;
21196 load_realtime = (argc == 5 && !strcmp(argv[4],
"load")) ?
TRUE :
FALSE;
21207 snprintf (cbuf,
sizeof(cbuf),
"Peer %s not found.", argv[3]);
21212 if (peer && type==0 ) {
21218 credentials = peer->
auth;
21220 ao2_t_ref(credentials, +1,
"Ref peer auth for show");
21227 if (realtimepeers) {
21237 ast_cli(fd,
" Realm-auth : Realm %-15.15s User %-10.20s %s\n",
21243 ?
"<MD5secret set>" :
"<Not set>"));
21245 ao2_t_ref(credentials, -1,
"Unref peer auth for show");
21252 ast_cli(fd,
" Tonezone : %s\n", peer->
zone[0] !=
'\0' ? peer->
zone :
"<Not set>");
21262 ast_cli(fd,
" Callgroup : ");
21264 ast_cli(fd,
" Pickupgroup : ");
21266 ast_cli(fd,
" Named Callgr : ");
21268 ast_cli(fd,
" Nam. Pickupgr: ");
21324 ast_cli(fd,
" SIP Options : ");
21326 int lastoption = -1;
21349 ast_cli(fd,
" Variables :\n");
21364 peer =
sip_unref_peer(peer,
"sip_show_peer: sip_unref_peer: done with peer ptr");
21365 }
else if (peer && type == 1) {
21459 peer =
sip_unref_peer(peer,
"sip_show_peer: sip_unref_peer: done with peer");
21462 ast_cli(fd,
"Peer %s not found.\n", argv[3]);
21473 int wordlen = strlen(word);
21487 if (!strncasecmp(word, user->
name, wordlen) && ++which > state) {
21518 e->
command =
"sip show user";
21520 "Usage: sip show user <name> [load]\n" 21521 " Shows all details on one SIP user and the current status.\n" 21522 " Option \"load\" forces lookup of peer in realtime storage.\n";
21526 static const char *
const completions[] = {
"load",
NULL };
21550 ast_cli(a->
fd,
" Tonezone : %s\n", user->
zone[0] !=
'\0' ? user->
zone :
"<Not set>");
21598 "__sip_autodestruct",
21603 "sip_poke_peer_now",
21604 "sip_poke_noanswer",
21606 "sip_reinvite_retry" 21624 e->
command =
"sip show sched";
21626 "Usage: sip show sched\n" 21627 " Shows stats on what's in the sched queue at the moment\n";
21645 #define FORMAT2 "%-39.39s %-6.6s %-12.12s %8.8s %-20.20s %-25.25s\n" 21646 #define FORMAT "%-39.39s %-6.6s %-12.12s %8d %-20.20s %-25.25s\n" 21657 e->
command =
"sip show registry";
21659 "Usage: sip show registry\n" 21660 " Lists all registration requests and status.\n";
21668 ast_cli(a->
fd,
FORMAT2,
"Host",
"dnsmgr",
"Username",
"Refresh",
"State",
"Reg.Time");
21675 snprintf(user,
sizeof(user),
"%s", iterator->
username);
21677 snprintf(tmpdat,
sizeof(tmpdat),
"%s", user);
21678 snprintf(user,
sizeof(user),
"%s@%s", tmpdat, iterator->
regdomain);}
21680 snprintf(tmpdat,
sizeof(tmpdat),
"%s", user);
21681 snprintf(user,
sizeof(user),
"%s:%d", tmpdat, iterator->
regdomainport);}
21682 if (iterator->
regtime.tv_sec) {
21684 ast_strftime(tmpdat,
sizeof(tmpdat),
"%a, %d %b %Y %T", &tm);
21690 ao2_t_ref(iterator, -1,
"sip_show_registry iter");
21695 ast_cli(a->
fd,
"%d SIP registrations.\n", counter);
21708 int load_realtime = 0;
21712 e->
command =
"sip unregister";
21714 "Usage: sip unregister <peer>\n" 21715 " Unregister (force expiration) a SIP peer from the registry\n";
21725 if (peer->
expire > -1) {
21729 ast_cli(a->
fd,
"Unregistered peer \'%s\'\n\n", a->
argv[2]);
21733 sip_unref_peer(peer,
"sip_unregister: sip_unref_peer via sip_unregister: done with peer from sip_find_peer call");
21735 ast_cli(a->
fd,
"Peer unknown: \'%s\'. Not unregistered.\n", a->
argv[2]);
21744 #define FORMAT2 "%-15.15s %-11.11s %-8.8s %-10.10s %-10.10s ( %%) %-6.6s %-10.10s %-10.10s ( %%) %-6.6s\n" 21745 #define FORMAT "%-15.15s %-11.11s %-8.8s %-10.10u%-1.1s %-10.10u (%5.2f%%) %-6.4lf %-10.10u%-1.1s %-10.10u (%5.2f%%) %-6.4lf\n" 21762 ast_cli(fd,
"%-15.15s %-11.11s (inv state: %s) -- %s\n",
21765 "-- No RTP active");
21787 stats.
rxcount > (
unsigned int) 100000 ? (
unsigned int) (stats.
rxcount)/(
unsigned int) 1000 : stats.
rxcount,
21788 stats.
rxcount > (
unsigned int) 100000 ?
"K":
" ",
21792 stats.
txcount > (
unsigned int) 100000 ? (
unsigned int) (stats.
txcount)/(
unsigned int) 1000 : stats.
txcount,
21793 stats.
txcount > (
unsigned int) 100000 ?
"K":
" ",
21813 e->
command =
"sip show channelstats";
21815 "Usage: sip show channelstats\n" 21816 " Lists all currently active SIP channel's RTCP statistics.\n" 21817 " Note that calls in the much optimized RTP P2P bridge mode will not show any packets here.";
21826 ast_cli(a->
fd,
FORMAT2,
"Peer",
"Call ID",
"Duration",
"Recv: Pack",
"Lost",
"Jitter",
"Send: Pack",
"Lost",
"Jitter");
21852 e->
command =
"sip show settings";
21854 "Usage: sip show settings\n" 21855 " Provides detailed list of the configuration of the SIP channel.\n";
21868 credentials =
authl;
21870 ao2_t_ref(credentials, +1,
"Ref global auth for show");
21874 ast_cli(a->
fd,
"\n\nGlobal Settings:\n");
21878 ast_cli(a->
fd,
" ** Additional Info:\n");
21879 ast_cli(a->
fd,
" [::] may include IPv4 in addition to IPv6, if such a feature is enabled in the OS.\n");
21881 ast_cli(a->
fd,
" TCP SIP Bindaddress: %s\n",
21885 ast_cli(a->
fd,
" TLS SIP Bindaddress: %s\n",
21889 ast_cli(a->
fd,
" RTP Bindaddress: %s\n",
21910 ast_cli(a->
fd,
" Realm. auth entry: Realm %-15.15s User %-10.20s %s\n",
21916 ?
"<MD5secret set>" :
"<Not set>"));
21918 ao2_t_ref(credentials, -1,
"Unref global auth for show");
21947 if (!realtimepeers && !realtimeregs)
21948 ast_cli(a->
fd,
" SIP realtime: Disabled\n" );
21950 ast_cli(a->
fd,
" SIP realtime: Enabled\n" );
21954 ast_cli(a->
fd,
"\nNetwork QoS Settings:\n");
21955 ast_cli(a->
fd,
"---------------------------\n");
21976 ast_cli(a->
fd,
"\nNetwork Settings:\n");
21977 ast_cli(a->
fd,
"---------------------------\n");
21979 if (localaddr ==
NULL)
21980 msg =
"Disabled, no localnet list";
21984 msg =
"Enabled using externhost";
21986 msg =
"Enabled using externaddr";
21987 ast_cli(a->
fd,
" SIP address remapping: %s\n", msg);
21993 const char *
prefix =
"Localnet:";
21995 for (d = localaddr;
d ; prefix =
"", d = d->
next) {
21998 ast_cli(a->
fd,
" %-24s%s/%s\n", prefix, addr, mask);
22001 ast_cli(a->
fd,
"\nGlobal Signalling Settings:\n");
22002 ast_cli(a->
fd,
"---------------------------\n");
22044 ast_cli(a->
fd,
"\nDefault Settings:\n");
22065 if (realtimepeers || realtimeregs) {
22066 ast_cli(a->
fd,
"\nRealtime SIP Settings:\n");
22067 ast_cli(a->
fd,
"----------------------\n");
22083 #define FORMAT "%-30.30s %-12.12s %-10.10s %-10.10s\n" 22092 "Usage: sip show mwi\n" 22093 " Provides a list of MWI subscriptions and status.\n";
22107 ao2_t_ref(iterator, -1,
"sip_show_mwi iter");
22149 #define FORMAT4 "%-15.15s %-15.15s %-15.15s %-15.15s %-13.13s %-15.15s %-10.10s %-6.6d\n" 22150 #define FORMAT3 "%-15.15s %-15.15s %-15.15s %-15.15s %-13.13s %-15.15s %-10.10s %-6.6s\n" 22151 #define FORMAT2 "%-15.15s %-15.15s %-15.15s %-15.15s %-7.7s %-15.15s %-10.10s %-10.10s\n" 22152 #define FORMAT "%-15.15s %-15.15s %-15.15s %-15.15s %-3.3s %-3.3s %-15.15s %-10.10s %-10.10s\n" 22212 e->
command =
"sip show {channels|subscriptions}";
22214 "Usage: sip show channels\n" 22215 " Lists all currently active SIP calls (dialogs).\n" 22216 "Usage: sip show subscriptions\n" 22217 " Lists active SIP subscriptions.\n";
22226 ast_cli(arg.
fd,
FORMAT2,
"Peer",
"User/ANR",
"Call ID",
"Format",
"Hold",
"Last Message",
"Expiry",
"Peer");
22228 ast_cli(arg.
fd,
FORMAT3,
"Peer",
"User",
"Call ID",
"Extension",
"Last state",
"Type",
"Mailbox",
"Expiry");
22257 int wordlen = strlen(word);
22267 if (!strncasecmp(word, cur->
callid, wordlen) && ++which > state) {
22285 int wordlen = strlen(word);
22292 if (!strncasecmp(word, peer->
name, wordlen) &&
22309 int wordlen = strlen(word);
22316 if (!strncasecmp(word, peer->
name, wordlen) &&
22318 ++which > state && peer->
expire > -1)
22366 int wordlen = strlen(word);
22374 if (!strncasecmp(word, cat, wordlen) && ++which > state) {
22398 e->
command =
"sip show channel";
22400 "Usage: sip show channel <call-id>\n" 22401 " Provides detailed status on a given SIP dialog (identified by SIP call-id).\n";
22409 len = strlen(a->
argv[3]);
22415 if (!strncasecmp(cur->
callid, a->
argv[3], len)) {
22442 " Audio IP: %s (local)\n",
22446 " Audio IP: %s (Outside bridge)\n",
22485 ast_cli(a->
fd,
" Session-Timer: Uninitiallized\n");
22502 ast_cli(a->
fd,
" Media: %s\n", cur->
srtp ?
"SRTP" : cur->
rtp ?
"RTP" :
"None");
22511 ao2_t_ref(cur, -1,
"toss dialog ptr set by iterator_next");
22516 ast_cli(a->
fd,
"No such SIP Call ID starting with '%s'\n", a->
argv[3]);
22532 e->
command =
"sip show history";
22534 "Usage: sip show history <call-id>\n" 22535 " Provides detailed dialog history on a given SIP call (specified by call-id).\n";
22541 if (a->
argc != 4) {
22546 ast_cli(a->
fd,
"\n***Note: History recording is currently DISABLED. Use 'sip set history on' to ENABLE.\n");
22549 len = strlen(a->
argv[3]);
22554 if (!strncasecmp(cur->
callid, a->
argv[3], len)) {
22574 ao2_t_ref(cur, -1,
"toss dialog ptr from iterator_next");
22579 ast_cli(a->
fd,
"No such SIP Call ID starting with '%s'\n", a->
argv[3]);
22590 static int errmsg = 0;
22598 ast_log(
LOG_NOTICE,
"You must have debugging enabled (SIP or Asterisk) in order to dump SIP history.\n");
22624 const char *
buf =
"";
22625 unsigned int event;
22630 if (!strcasecmp(c,
"application/hook-flash")) {
22635 ast_verbose(
"* DTMF-relay event received: FLASH\n");
22641 if (!strcasecmp(c,
"application/dtmf-relay") ||
22642 !strcasecmp(c,
"application/vnd.nortelnetworks.digits") ||
22643 !strcasecmp(c,
"application/dtmf")) {
22644 unsigned int duration = 0;
22654 if (strcasecmp(c,
"application/dtmf")) {
22660 "call %s\n", p->
callid);
22665 sscanf(tmp,
"%30u", &duration);
22682 if (buf[0] ==
'*') {
22684 }
else if (buf[0] ==
'#') {
22686 }
else if (buf[0] ==
'!') {
22688 }
else if (
'A' <= buf[0] && buf[0] <=
'D') {
22689 event = 12 + buf[0] -
'A';
22690 }
else if (
'a' <= buf[0] && buf[0] <=
'd') {
22691 event = 12 + buf[0] -
'a';
22692 }
else if ((sscanf(buf,
"%30u", &event) != 1) || event > 16) {
22694 "value for INFO message on call %s\n", p->
callid);
22704 ast_verbose(
"* DTMF-relay event received: FLASH\n");
22711 }
else if (event == 10) {
22713 }
else if (event == 11) {
22726 }
else if (!strcasecmp(c,
"application/media_control+xml")) {
22753 int suppress_warning = 0;
22763 if (!strcasecmp(c,
"on")) {
22765 suppress_warning = 1;
22769 }
else if (!strcasecmp(c,
"off")) {
22771 suppress_warning = 1;
22776 ast_log(
LOG_ERROR,
"Received INFO requesting to record with invalid value: %s\n", c);
22780 if (!suppress_warning) {
22781 ast_log(
LOG_WARNING,
"Recording requested, but no One Touch Monitor registered. (See features.conf)\n");