summaryrefslogtreecommitdiff
path: root/res
diff options
context:
space:
mode:
Diffstat (limited to 'res')
-rw-r--r--res/res_hep.c34
-rw-r--r--res/res_pjsip_sdp_rtp.c18
-rw-r--r--res/res_pjsip_session.c137
3 files changed, 114 insertions, 75 deletions
diff --git a/res/res_hep.c b/res/res_hep.c
index 41a558141..25b4d13b1 100644
--- a/res/res_hep.c
+++ b/res/res_hep.c
@@ -69,7 +69,7 @@
</enumlist>
</description>
</configOption>
- <configOption name="capture_address" default="192.168.1.1:9061">
+ <configOption name="capture_address">
<synopsis>The address and port of the Homer server to send packets to.</synopsis>
</configOption>
<configOption name="capture_password">
@@ -96,8 +96,6 @@
#include <netinet/udp.h>
#include <netinet/ip6.h>
-#define DEFAULT_HEP_SERVER ""
-
/*! Generic vendor ID. Used for HEPv3 standard packets */
#define GENERIC_VENDOR_ID 0x0000
@@ -280,11 +278,13 @@ static AO2_GLOBAL_OBJ_STATIC(global_data);
static struct ast_taskprocessor *hep_queue_tp;
static void *module_config_alloc(void);
+static int hepv3_config_pre_apply(void);
static void hepv3_config_post_apply(void);
/*! \brief Register information about the configs being processed by this module */
CONFIG_INFO_STANDARD(cfg_info, global_config, module_config_alloc,
.files = ACO_FILES(&hepv3_conf),
+ .pre_apply_config = hepv3_config_pre_apply,
.post_apply_config = hepv3_config_post_apply,
);
@@ -377,6 +377,8 @@ static struct hepv3_runtime_data *hepv3_data_alloc(struct hepv3_global_config *c
return NULL;
}
+ data->sockfd = -1;
+
if (!ast_sockaddr_parse(&data->remote_addr, config->capture_address, PARSE_PORT_REQUIRE)) {
ast_log(AST_LOG_WARNING, "Failed to create address from %s\n", config->capture_address);
ao2_ref(data, -1);
@@ -594,11 +596,33 @@ int hepv3_send_packet(struct hepv3_capture_info *capture_info)
}
/*!
+ * \brief Pre-apply callback for the config framework.
+ *
+ * This validates that required fields exist and are populated.
+ */
+static int hepv3_config_pre_apply(void)
+{
+ struct module_config *config = aco_pending_config(&cfg_info);
+
+ if (!config->general->enabled) {
+ /* If we're not enabled, we don't care about anything else */
+ return 0;
+ }
+
+ if (ast_strlen_zero(config->general->capture_address)) {
+ ast_log(AST_LOG_ERROR, "Missing required configuration option 'capture_address'\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+/*!
* \brief Post-apply callback for the config framework.
*
* This will create the run-time information from the supplied
* configuration.
-*/
+ */
static void hepv3_config_post_apply(void)
{
RAII_VAR(struct module_config *, mod_cfg, ao2_global_obj_ref(global_config), ao2_cleanup);
@@ -653,7 +677,7 @@ static int load_module(void)
}
aco_option_register(&cfg_info, "enabled", ACO_EXACT, global_options, "yes", OPT_BOOL_T, 1, FLDSET(struct hepv3_global_config, enabled));
- aco_option_register(&cfg_info, "capture_address", ACO_EXACT, global_options, DEFAULT_HEP_SERVER, OPT_STRINGFIELD_T, 0, STRFLDSET(struct hepv3_global_config, capture_address));
+ aco_option_register(&cfg_info, "capture_address", ACO_EXACT, global_options, "", OPT_STRINGFIELD_T, 1, STRFLDSET(struct hepv3_global_config, capture_address));
aco_option_register(&cfg_info, "capture_password", ACO_EXACT, global_options, "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct hepv3_global_config, capture_password));
aco_option_register(&cfg_info, "capture_id", ACO_EXACT, global_options, "0", OPT_UINT_T, 0, STRFLDSET(struct hepv3_global_config, capture_id));
aco_option_register_custom(&cfg_info, "uuid_type", ACO_EXACT, global_options, "call-id", uuid_type_handler, 0);
diff --git a/res/res_pjsip_sdp_rtp.c b/res/res_pjsip_sdp_rtp.c
index dfa6957c7..97e365c10 100644
--- a/res/res_pjsip_sdp_rtp.c
+++ b/res/res_pjsip_sdp_rtp.c
@@ -453,6 +453,7 @@ static int set_caps(struct ast_sip_session *session,
static pjmedia_sdp_attr* generate_rtpmap_attr(struct ast_sip_session *session, pjmedia_sdp_media *media, pj_pool_t *pool,
int rtp_code, int asterisk_format, struct ast_format *format, int code)
{
+ extern pj_bool_t pjsip_use_compact_form;
pjmedia_sdp_rtpmap rtpmap;
pjmedia_sdp_attr *attr = NULL;
char tmp[64];
@@ -461,6 +462,11 @@ static pjmedia_sdp_attr* generate_rtpmap_attr(struct ast_sip_session *session, p
snprintf(tmp, sizeof(tmp), "%d", rtp_code);
pj_strdup2(pool, &media->desc.fmt[media->desc.fmt_count++], tmp);
+
+ if (rtp_code <= AST_RTP_PT_LAST_STATIC && pjsip_use_compact_form) {
+ return NULL;
+ }
+
rtpmap.pt = media->desc.fmt[media->desc.fmt_count - 1];
rtpmap.clock_rate = ast_rtp_lookup_sample_rate2(asterisk_format, format, code);
pj_strdup2(pool, &rtpmap.enc_name, ast_rtp_lookup_mime_subtype2(asterisk_format, format, code, options));
@@ -1260,11 +1266,9 @@ static int create_outgoing_sdp_stream(struct ast_sip_session *session, struct as
continue;
}
- if (!(attr = generate_rtpmap_attr(session, media, pool, rtp_code, 1, format, 0))) {
- ao2_ref(format, -1);
- continue;
+ if ((attr = generate_rtpmap_attr(session, media, pool, rtp_code, 1, format, 0))) {
+ media->attr[media->attr_count++] = attr;
}
- media->attr[media->attr_count++] = attr;
if ((attr = generate_fmtp_attr(pool, format, rtp_code))) {
media->attr[media->attr_count++] = attr;
@@ -1293,12 +1297,10 @@ static int create_outgoing_sdp_stream(struct ast_sip_session *session, struct as
continue;
}
- if (!(attr = generate_rtpmap_attr(session, media, pool, rtp_code, 0, NULL, index))) {
- continue;
+ if ((attr = generate_rtpmap_attr(session, media, pool, rtp_code, 0, NULL, index))) {
+ media->attr[media->attr_count++] = attr;
}
- media->attr[media->attr_count++] = attr;
-
if (index == AST_RTP_DTMF) {
snprintf(tmp, sizeof(tmp), "%d 0-16", rtp_code);
attr = pjmedia_sdp_attr_create(pool, "fmtp", pj_cstr(&stmp, tmp));
diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c
index 560b3903d..3034652a5 100644
--- a/res/res_pjsip_session.c
+++ b/res/res_pjsip_session.c
@@ -1328,9 +1328,7 @@ static void session_destructor(void *obj)
ao2_cleanup(session->req_caps);
ao2_cleanup(session->direct_media_cap);
- if (session->dsp) {
- ast_dsp_free(session->dsp);
- }
+ ast_dsp_free(session->dsp);
if (session->inv_session) {
pjsip_dlg_dec_session(session->inv_session->dlg, &session_module);
@@ -1400,6 +1398,7 @@ struct ast_sip_session *ast_sip_session_alloc(struct ast_sip_endpoint *endpoint,
struct ast_sip_contact *contact, pjsip_inv_session *inv_session, pjsip_rx_data *rdata)
{
RAII_VAR(struct ast_sip_session *, session, NULL, ao2_cleanup);
+ struct ast_sip_session *ret_session;
struct ast_sip_session_supplement *iter;
int dsp_features = 0;
@@ -1407,12 +1406,39 @@ struct ast_sip_session *ast_sip_session_alloc(struct ast_sip_endpoint *endpoint,
if (!session) {
return NULL;
}
+
AST_LIST_HEAD_INIT(&session->supplements);
+ AST_LIST_HEAD_INIT_NOLOCK(&session->delayed_requests);
+ ast_party_id_init(&session->id);
+
+ session->direct_media_cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+ if (!session->direct_media_cap) {
+ return NULL;
+ }
+ session->req_caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+ if (!session->req_caps) {
+ return NULL;
+ }
session->datastores = ao2_container_alloc(DATASTORE_BUCKETS, datastore_hash, datastore_cmp);
if (!session->datastores) {
return NULL;
}
+ if (endpoint->dtmf == AST_SIP_DTMF_INBAND || endpoint->dtmf == AST_SIP_DTMF_AUTO) {
+ dsp_features |= DSP_FEATURE_DIGIT_DETECT;
+ }
+ if (endpoint->faxdetect) {
+ dsp_features |= DSP_FEATURE_FAX_DETECT;
+ }
+ if (dsp_features) {
+ session->dsp = ast_dsp_new();
+ if (!session->dsp) {
+ return NULL;
+ }
+
+ ast_dsp_set_features(session->dsp, dsp_features);
+ }
+
session->endpoint = ao2_bump(endpoint);
session->media = ao2_container_alloc(MEDIA_BUCKETS, session_media_hash, session_media_cmp);
@@ -1449,30 +1475,6 @@ struct ast_sip_session *ast_sip_session_alloc(struct ast_sip_endpoint *endpoint,
inv_session->mod_data[session_module.id] = ao2_bump(session);
session->contact = ao2_bump(contact);
session->inv_session = inv_session;
- session->req_caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
- if (!session->req_caps) {
- /* Release the ref held by session->inv_session */
- ao2_ref(session, -1);
- return NULL;
- }
-
- if ((endpoint->dtmf == AST_SIP_DTMF_INBAND) || (endpoint->dtmf == AST_SIP_DTMF_AUTO)) {
- dsp_features |= DSP_FEATURE_DIGIT_DETECT;
- }
-
- if (endpoint->faxdetect) {
- dsp_features |= DSP_FEATURE_FAX_DETECT;
- }
-
- if (dsp_features) {
- if (!(session->dsp = ast_dsp_new())) {
- /* Release the ref held by session->inv_session */
- ao2_ref(session, -1);
- return NULL;
- }
-
- ast_dsp_set_features(session->dsp, dsp_features);
- }
if (add_supplements(session)) {
/* Release the ref held by session->inv_session */
@@ -1484,11 +1486,11 @@ struct ast_sip_session *ast_sip_session_alloc(struct ast_sip_endpoint *endpoint,
iter->session_begin(session);
}
}
- session->direct_media_cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
- AST_LIST_HEAD_INIT_NOLOCK(&session->delayed_requests);
- ast_party_id_init(&session->id);
- ao2_ref(session, +1);
- return session;
+
+ /* Avoid unnecessary ref manipulation to return a session */
+ ret_session = session;
+ session = NULL;
+ return ret_session;
}
/*! \brief struct controlling the suspension of the session's serializer. */
@@ -1704,6 +1706,7 @@ struct ast_sip_session *ast_sip_session_create_outgoing(struct ast_sip_endpoint
pjsip_dialog *dlg;
struct pjsip_inv_session *inv_session;
RAII_VAR(struct ast_sip_session *, session, NULL, ao2_cleanup);
+ struct ast_sip_session *ret_session;
/* If no location has been provided use the AOR list from the endpoint itself */
if (location || !contact) {
@@ -1760,14 +1763,17 @@ struct ast_sip_session *ast_sip_session_create_outgoing(struct ast_sip_endpoint
if (ast_format_cap_count(req_caps)) {
/* get joint caps between req_caps and endpoint caps */
struct ast_format_cap *joint_caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
- ast_format_cap_get_compatible(req_caps, session->endpoint->media.codecs, joint_caps);
+
+ ast_format_cap_get_compatible(req_caps, endpoint->media.codecs, joint_caps);
/* if joint caps */
if (ast_format_cap_count(joint_caps)) {
/* copy endpoint caps into session->req_caps */
- ast_format_cap_append_from_cap(session->req_caps, session->endpoint->media.codecs, AST_MEDIA_TYPE_UNKNOWN);
+ ast_format_cap_append_from_cap(session->req_caps,
+ endpoint->media.codecs, AST_MEDIA_TYPE_UNKNOWN);
/* replace instances of joint caps equivalents in session->req_caps */
- ast_format_cap_replace_from_cap(session->req_caps, joint_caps, AST_MEDIA_TYPE_UNKNOWN);
+ ast_format_cap_replace_from_cap(session->req_caps, joint_caps,
+ AST_MEDIA_TYPE_UNKNOWN);
}
ao2_cleanup(joint_caps);
}
@@ -1781,8 +1787,10 @@ struct ast_sip_session *ast_sip_session_create_outgoing(struct ast_sip_endpoint
return NULL;
}
- ao2_ref(session, +1);
- return session;
+ /* Avoid unnecessary ref manipulation to return a session */
+ ret_session = session;
+ session = NULL;
+ return ret_session;
}
void ast_sip_session_terminate(struct ast_sip_session *session, int response)
@@ -2142,12 +2150,29 @@ static int new_invite(void *data)
goto end;
};
- if ((sdp_info = pjsip_rdata_get_sdp_info(invite->rdata)) && (sdp_info->sdp_err == PJ_SUCCESS) && sdp_info->sdp) {
+ pjsip_timer_setting_default(&timer);
+ timer.min_se = invite->session->endpoint->extensions.timer.min_se;
+ timer.sess_expires = invite->session->endpoint->extensions.timer.sess_expires;
+ pjsip_timer_init_session(invite->session->inv_session, &timer);
+
+ /*
+ * At this point, we've verified what we can that won't take awhile,
+ * so let's go ahead and send a 100 Trying out to stop any
+ * retransmissions.
+ */
+ if (pjsip_inv_initial_answer(invite->session->inv_session, invite->rdata, 100, NULL, NULL, &tdata) != PJ_SUCCESS) {
+ pjsip_inv_terminate(invite->session->inv_session, 500, PJ_TRUE);
+ goto end;
+ }
+ ast_sip_session_send_response(invite->session, tdata);
+
+ sdp_info = pjsip_rdata_get_sdp_info(invite->rdata);
+ if (sdp_info && (sdp_info->sdp_err == PJ_SUCCESS) && sdp_info->sdp) {
if (handle_incoming_sdp(invite->session, sdp_info->sdp)) {
- if (pjsip_inv_initial_answer(invite->session->inv_session, invite->rdata, 488, NULL, NULL, &tdata) == PJ_SUCCESS) {
+ tdata = NULL;
+ if (pjsip_inv_end_session(invite->session->inv_session, 488, NULL, &tdata) == PJ_SUCCESS
+ && tdata) {
ast_sip_session_send_response(invite->session, tdata);
- } else {
- pjsip_inv_terminate(invite->session->inv_session, 488, PJ_TRUE);
}
goto end;
}
@@ -2160,33 +2185,21 @@ static int new_invite(void *data)
/* If we were unable to create a local SDP terminate the session early, it won't go anywhere */
if (!local) {
- if (pjsip_inv_initial_answer(invite->session->inv_session, invite->rdata, 500, NULL, NULL, &tdata) == PJ_SUCCESS) {
+ tdata = NULL;
+ if (pjsip_inv_end_session(invite->session->inv_session, 500, NULL, &tdata) == PJ_SUCCESS
+ && tdata) {
ast_sip_session_send_response(invite->session, tdata);
- } else {
- pjsip_inv_terminate(invite->session->inv_session, 500, PJ_TRUE);
}
goto end;
- } else {
- pjsip_inv_set_local_sdp(invite->session->inv_session, local);
- pjmedia_sdp_neg_set_prefer_remote_codec_order(invite->session->inv_session->neg, PJ_FALSE);
-#ifdef PJMEDIA_SDP_NEG_ANSWER_MULTIPLE_CODECS
- if (!invite->session->endpoint->preferred_codec_only) {
- pjmedia_sdp_neg_set_answer_multiple_codecs(invite->session->inv_session->neg, PJ_TRUE);
- }
-#endif
}
- pjsip_timer_setting_default(&timer);
- timer.min_se = invite->session->endpoint->extensions.timer.min_se;
- timer.sess_expires = invite->session->endpoint->extensions.timer.sess_expires;
- pjsip_timer_init_session(invite->session->inv_session, &timer);
-
- /* At this point, we've verified what we can, so let's go ahead and send a 100 Trying out */
- if (pjsip_inv_initial_answer(invite->session->inv_session, invite->rdata, 100, NULL, NULL, &tdata) != PJ_SUCCESS) {
- pjsip_inv_terminate(invite->session->inv_session, 500, PJ_TRUE);
- goto end;
+ pjsip_inv_set_local_sdp(invite->session->inv_session, local);
+ pjmedia_sdp_neg_set_prefer_remote_codec_order(invite->session->inv_session->neg, PJ_FALSE);
+#ifdef PJMEDIA_SDP_NEG_ANSWER_MULTIPLE_CODECS
+ if (!invite->session->endpoint->preferred_codec_only) {
+ pjmedia_sdp_neg_set_answer_multiple_codecs(invite->session->inv_session->neg, PJ_TRUE);
}
- ast_sip_session_send_response(invite->session, tdata);
+#endif
handle_incoming_request(invite->session, invite->rdata);