aboutsummaryrefslogtreecommitdiffstats
path: root/channels/chan_sip.c
diff options
context:
space:
mode:
Diffstat (limited to 'channels/chan_sip.c')
-rw-r--r--channels/chan_sip.c104
1 files changed, 56 insertions, 48 deletions
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index 18eba23..a0b9cb0 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -164,6 +164,7 @@
/*** MODULEINFO
<use type="module">res_crypto</use>
<depend>chan_local</depend>
+ <support_level>core</support_level>
***/
/*! \page sip_session_timers SIP Session Timers in Asterisk Chan_sip
@@ -1350,7 +1351,7 @@ static int attempt_transfer(struct sip_dual *transferer, struct sip_dual *target
static int do_magic_pickup(struct ast_channel *channel, const char *extension, const char *context);
/*--- Device monitoring and Device/extension state/event handling */
-static int cb_extensionstate(char *context, char* exten, int state, void *data);
+static int cb_extensionstate(const char *context, const char *exten, enum ast_extension_states state, void *data);
static int sip_devicestate(void *data);
static int sip_poke_noanswer(const void *data);
static int sip_poke_peer(struct sip_peer *peer, int force);
@@ -4227,10 +4228,11 @@ static void enable_dsp_detect(struct sip_pvt *p)
}
if ((ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_INBAND) ||
- (ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_AUTO)) {
- if (!p->rtp || ast_rtp_instance_dtmf_mode_set(p->rtp, AST_RTP_DTMF_MODE_INBAND)) {
- features |= DSP_FEATURE_DIGIT_DETECT;
- }
+ (ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_AUTO)) {
+ if (p->rtp) {
+ ast_rtp_instance_dtmf_mode_set(p->rtp, AST_RTP_DTMF_MODE_INBAND);
+ }
+ features |= DSP_FEATURE_DIGIT_DETECT;
}
if (ast_test_flag(&p->flags[1], SIP_PAGE2_FAX_DETECT_CNG)) {
@@ -4265,6 +4267,11 @@ static int sip_setoption(struct ast_channel *chan, int option, void *data, int d
int res = -1;
struct sip_pvt *p = chan->tech_pvt;
+ if (!p) {
+ ast_log(LOG_ERROR, "Attempt to Ref a null pointer. sip private structure is gone!\n");
+ return -1;
+ }
+
sip_pvt_lock(p);
switch (option) {
@@ -6529,11 +6536,7 @@ static int sip_senddigit_begin(struct ast_channel *ast, char digit)
sip_pvt_lock(p);
switch (ast_test_flag(&p->flags[0], SIP_DTMF)) {
case SIP_DTMF_INBAND:
- if (p->rtp && ast_rtp_instance_dtmf_mode_get(p->rtp) == AST_RTP_DTMF_MODE_INBAND) {
- ast_rtp_instance_dtmf_begin(p->rtp, digit);
- } else {
- res = -1; /* Tell Asterisk to generate inband indications */
- }
+ res = -1; /* Tell Asterisk to generate inband indications */
break;
case SIP_DTMF_RFC2833:
if (p->rtp)
@@ -6565,11 +6568,7 @@ static int sip_senddigit_end(struct ast_channel *ast, char digit, unsigned int d
ast_rtp_instance_dtmf_end_with_duration(p->rtp, digit, duration);
break;
case SIP_DTMF_INBAND:
- if (p->rtp && ast_rtp_instance_dtmf_mode_get(p->rtp) == AST_RTP_DTMF_MODE_INBAND) {
- ast_rtp_instance_dtmf_end(p->rtp, digit);
- } else {
- res = -1; /* Tell Asterisk to stop inband indications */
- }
+ res = -1; /* Tell Asterisk to stop inband indications */
break;
}
sip_pvt_unlock(p);
@@ -6926,8 +6925,8 @@ static struct ast_channel *sip_new(struct sip_pvt *i, int state, const char *tit
if ((ast_test_flag(&i->flags[0], SIP_DTMF) == SIP_DTMF_INBAND) ||
(ast_test_flag(&i->flags[0], SIP_DTMF) == SIP_DTMF_AUTO)) {
- if (!i->rtp || ast_rtp_instance_dtmf_mode_set(i->rtp, AST_RTP_DTMF_MODE_INBAND)) {
- enable_dsp_detect(i);
+ if (i->rtp) {
+ ast_rtp_instance_dtmf_mode_set(i->rtp, AST_RTP_DTMF_MODE_INBAND);
}
} else if (ast_test_flag(&i->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833) {
if (i->rtp) {
@@ -9468,6 +9467,7 @@ static int process_sdp_a_audio(const char *a, struct sip_pvt *p, struct ast_rtp_
if ((format = ast_rtp_codecs_get_payload_format(newaudiortp, codec))) {
unsigned int bit_rate;
+ int val = 0;
switch ((int) format->id) {
case AST_FORMAT_SIREN7:
@@ -9500,20 +9500,21 @@ static int process_sdp_a_audio(const char *a, struct sip_pvt *p, struct ast_rtp_
}
}
break;
+ case AST_FORMAT_CELT:
+ if (sscanf(fmtp_string, "framesize=%30u", &val) == 1) {
+ ast_format_append(format, CELT_ATTR_KEY_FRAME_SIZE, val, AST_FORMAT_ATTR_END);
+ }
case AST_FORMAT_SILK:
- {
- int val = 0;
- if (sscanf(fmtp_string, "maxaveragebitrate=%30u", &val) == 1) {
- ast_format_append(format, SILK_ATTR_KEY_MAX_BITRATE, val, AST_FORMAT_ATTR_END);
- }
- if (sscanf(fmtp_string, "usedtx=%30u", &val) == 1) {
- ast_format_append(format, SILK_ATTR_KEY_DTX, val ? 1 : 0, AST_FORMAT_ATTR_END);
- }
- if (sscanf(fmtp_string, "useinbandfec=%30u", &val) == 1) {
- ast_format_append(format, SILK_ATTR_KEY_FEC, val ? 1 : 0, AST_FORMAT_ATTR_END);
- }
- break;
+ if (sscanf(fmtp_string, "maxaveragebitrate=%30u", &val) == 1) {
+ ast_format_append(format, SILK_ATTR_KEY_MAX_BITRATE, val, AST_FORMAT_ATTR_END);
+ }
+ if (sscanf(fmtp_string, "usedtx=%30u", &val) == 1) {
+ ast_format_append(format, SILK_ATTR_KEY_DTX, val ? 1 : 0, AST_FORMAT_ATTR_END);
}
+ if (sscanf(fmtp_string, "useinbandfec=%30u", &val) == 1) {
+ ast_format_append(format, SILK_ATTR_KEY_FEC, val ? 1 : 0, AST_FORMAT_ATTR_END);
+ }
+ break;
}
}
}
@@ -10829,7 +10830,7 @@ static void add_codec_to_sdp(const struct sip_pvt *p,
{
int rtp_code;
struct ast_format_list fmt;
-
+ int val = 0;
if (debug)
ast_verbose("Adding codec %d (%s) to SDP\n", format->id, ast_getformatname(format));
@@ -10872,20 +10873,22 @@ static void add_codec_to_sdp(const struct sip_pvt *p,
/* Indicate that we only expect 64Kbps */
ast_str_append(a_buf, 0, "a=fmtp:%d bitrate=64000\r\n", rtp_code);
break;
+ case AST_FORMAT_CELT:
+ if (!ast_format_get_value(format, CELT_ATTR_KEY_FRAME_SIZE, &val) && val > 0) {
+ ast_str_append(a_buf, 0, "a=fmtp:%d framesize=%u\r\n", rtp_code, val);
+ }
+ break;
case AST_FORMAT_SILK:
- {
- int val = 0;
- if (!ast_format_get_value(format, SILK_ATTR_KEY_MAX_BITRATE, &val) && val > 5000 && val < 40000) {
- ast_str_append(a_buf, 0, "a=fmtp:%d maxaveragebitrate=%u\r\n", rtp_code, val);
- }
- if (!ast_format_get_value(format, SILK_ATTR_KEY_DTX, &val)) {
- ast_str_append(a_buf, 0, "a=fmtp:%d usedtx=%u\r\n", rtp_code, val ? 1 : 0);
- }
- if (!ast_format_get_value(format, SILK_ATTR_KEY_FEC, &val)) {
- ast_str_append(a_buf, 0, "a=fmtp:%d useinbandfec=%u\r\n", rtp_code, val ? 1 : 0);
- }
- break;
+ if (!ast_format_get_value(format, SILK_ATTR_KEY_MAX_BITRATE, &val) && val > 5000 && val < 40000) {
+ ast_str_append(a_buf, 0, "a=fmtp:%d maxaveragebitrate=%u\r\n", rtp_code, val);
+ }
+ if (!ast_format_get_value(format, SILK_ATTR_KEY_DTX, &val)) {
+ ast_str_append(a_buf, 0, "a=fmtp:%d usedtx=%u\r\n", rtp_code, val ? 1 : 0);
+ }
+ if (!ast_format_get_value(format, SILK_ATTR_KEY_FEC, &val)) {
+ ast_str_append(a_buf, 0, "a=fmtp:%d useinbandfec=%u\r\n", rtp_code, val ? 1 : 0);
}
+ break;
}
if (fmt.cur_ms && (fmt.cur_ms < *min_packet_size))
@@ -14341,7 +14344,7 @@ static void network_change_event_cb(const struct ast_event *event, void *userdat
/*! \brief Callback for the devicestate notification (SUBSCRIBE) support subsystem
\note If you add an "hint" priority to the extension in the dial plan,
you will get notifications on device state changes */
-static int cb_extensionstate(char *context, char* exten, int state, void *data)
+static int cb_extensionstate(const char *context, const char *exten, enum ast_extension_states state, void *data)
{
struct sip_pvt *p = data;
@@ -16079,7 +16082,11 @@ static void receive_message(struct sip_pvt *p, struct sip_request *req, struct a
return;
}
- if (get_msg_text2(&buf, req, FALSE)) {
+ /* If this is an out of dialog msg, add back newlines, otherwise strip the new lines.
+ * In dialog msg's newlines are stripped to preserve the behavior of how Asterisk has worked
+ * in the past. If it is found later that new lines can be added into in dialog msgs as well,
+ * then change this. */
+ if (get_msg_text2(&buf, req, p->owner ? FALSE : TRUE)) {
ast_log(LOG_WARNING, "Unable to retrieve text from %s\n", p->callid);
transmit_response(p, "202 Accepted", req);
if (!p->owner)
@@ -19133,11 +19140,11 @@ static int build_reply_digest(struct sip_pvt *p, int method, char* digest, int d
struct sip_auth_container *credentials;
if (!ast_strlen_zero(p->domain))
- ast_copy_string(uri, p->domain, sizeof(uri));
+ snprintf(uri, sizeof(uri), "%s:%s", p->socket.type == SIP_TRANSPORT_TLS ? "sips" : "sip", p->domain);
else if (!ast_strlen_zero(p->uri))
ast_copy_string(uri, p->uri, sizeof(uri));
else
- snprintf(uri, sizeof(uri), "sip:%s@%s", p->username, ast_sockaddr_stringify_host_remote(&p->sa));
+ snprintf(uri, sizeof(uri), "%s:%s@%s", p->socket.type == SIP_TRANSPORT_TLS ? "sips" : "sip", p->username, ast_sockaddr_stringify_host_remote(&p->sa));
snprintf(cnonce, sizeof(cnonce), "%08lx", ast_random());
@@ -22515,7 +22522,6 @@ static int handle_request_invite(struct sip_pvt *p, struct sip_request *req, int
}
p->invitestate = INV_COMPLETED;
sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
- ast_string_field_set(p, theirtag, NULL);
res = 0;
goto request_invite_cleanup;
}
@@ -29067,7 +29073,9 @@ static int sip_set_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance *i
if ((instance || vinstance || tinstance) &&
!ast_bridged_channel(chan) &&
!sip_cfg.directrtpsetup) {
- return 0;
+ sip_pvt_unlock(p);
+ ast_channel_unlock(chan);
+ return 0;
}
if (p->alreadygone) {