summaryrefslogtreecommitdiff
path: root/res
diff options
context:
space:
mode:
Diffstat (limited to 'res')
-rw-r--r--res/res_musiconhold.c26
-rw-r--r--res/res_pjsip/include/res_pjsip_private.h5
-rw-r--r--res/res_pjsip/location.c22
-rw-r--r--res/res_pjsip/pjsip_options.c13
-rw-r--r--res/res_rtp_asterisk.c6
5 files changed, 42 insertions, 30 deletions
diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c
index 24a3a280f..eaf1f4ea8 100644
--- a/res/res_musiconhold.c
+++ b/res/res_musiconhold.c
@@ -210,7 +210,7 @@ static int reload(void);
#define mohclass_ref(class,string) (ao2_t_ref((class), +1, (string)), class)
-#ifndef REF_DEBUG
+#ifndef AST_DEVMODE
#define mohclass_unref(class,string) ({ ao2_t_ref((class), -1, (string)); (struct mohclass *) NULL; })
#else
#define mohclass_unref(class,string) _mohclass_unref(class, string, __FILE__,__LINE__,__PRETTY_FUNCTION__)
@@ -219,14 +219,14 @@ static struct mohclass *_mohclass_unref(struct mohclass *class, const char *tag,
struct mohclass *dup = ao2_callback(mohclasses, OBJ_POINTER, ao2_match_by_addr, class);
if (dup) {
- if (__ao2_ref_debug(dup, -1, (char *) tag, (char *) file, line, funcname) == 2) {
+ if (__ao2_ref(dup, -1, tag, file, line, funcname) == 2) {
ast_log(LOG_WARNING, "Attempt to unref mohclass %p (%s) when only 1 ref remained, and class is still in a container! (at %s:%d (%s))\n",
class, class->name, file, line, funcname);
} else {
ao2_ref(class, -1);
}
} else {
- __ao2_ref_debug(class, -1, (char *) tag, (char *) file, line, funcname);
+ __ao2_ref(class, -1, tag, file, line, funcname);
}
return NULL;
}
@@ -877,12 +877,8 @@ static struct mohclass *_get_mohbyname(const char *name, int warn, int flags, co
ast_copy_string(tmp_class.name, name, sizeof(tmp_class.name));
-#ifdef REF_DEBUG
- moh = __ao2_find_debug(mohclasses, &tmp_class, flags,
+ moh = __ao2_find(mohclasses, &tmp_class, flags,
"get_mohbyname", file, lineno, funcname);
-#else
- moh = __ao2_find(mohclasses, &tmp_class, flags);
-#endif
if (!moh && warn) {
ast_debug(1, "Music on Hold class '%s' not found in memory\n", name);
@@ -1373,17 +1369,9 @@ static struct mohclass *_moh_class_malloc(const char *file, int line, const char
{
struct mohclass *class;
- if ((class =
-#ifdef REF_DEBUG
- __ao2_alloc_debug(sizeof(*class), moh_class_destructor,
- AO2_ALLOC_OPT_LOCK_MUTEX, "Allocating new moh class", file, line, funcname, 1)
-#elif defined(__AST_DEBUG_MALLOC)
- __ao2_alloc_debug(sizeof(*class), moh_class_destructor,
- AO2_ALLOC_OPT_LOCK_MUTEX, "Allocating new moh class", file, line, funcname, 0)
-#else
- ao2_alloc(sizeof(*class), moh_class_destructor)
-#endif
- )) {
+ class = __ao2_alloc(sizeof(*class), moh_class_destructor, AO2_ALLOC_OPT_LOCK_MUTEX,
+ "Allocating new moh class", file, line, funcname);
+ if (class) {
class->format = ao2_bump(ast_format_slin);
class->srcfd = -1;
}
diff --git a/res/res_pjsip/include/res_pjsip_private.h b/res/res_pjsip/include/res_pjsip_private.h
index a8b94112b..5120fc6c9 100644
--- a/res/res_pjsip/include/res_pjsip_private.h
+++ b/res/res_pjsip/include/res_pjsip_private.h
@@ -319,4 +319,9 @@ void internal_sip_register_endpoint_formatter(struct ast_sip_endpoint_formatter
*/
int internal_sip_unregister_endpoint_formatter(struct ast_sip_endpoint_formatter *obj);
+/*!
+ * \internal
+ * \brief Finds or creates contact_status for a contact
+ */
+struct ast_sip_contact_status *ast_res_pjsip_find_or_create_contact_status(const struct ast_sip_contact *contact);
#endif /* RES_PJSIP_PRIVATE_H_ */
diff --git a/res/res_pjsip/location.c b/res/res_pjsip/location.c
index 45370dd24..887053b07 100644
--- a/res/res_pjsip/location.c
+++ b/res/res_pjsip/location.c
@@ -376,6 +376,11 @@ static int permanent_uri_handler(const struct aco_option *opt, struct ast_variab
return -1;
}
+ if (!ast_res_pjsip_find_or_create_contact_status(contact)) {
+ ao2_ref(contact, -1);
+ return -1;
+ }
+
ast_string_field_set(contact, uri, contact_uri);
ao2_link(aor->permanent_contacts, contact);
ao2_ref(contact, -1);
@@ -750,8 +755,8 @@ static int cli_contact_print_body(void *obj, void *arg, int flags)
"Contact",
flexwidth, flexwidth,
wrapper->contact_id,
- ast_sip_get_contact_short_status_label(status->status),
- (status->status != UNKNOWN ? ((long long) status->rtt) / 1000.0 : NAN));
+ ast_sip_get_contact_short_status_label(status ? status->status : UNKNOWN),
+ (status && (status->status != UNKNOWN) ? ((long long) status->rtt) / 1000.0 : NAN));
return 0;
}
@@ -874,6 +879,17 @@ static struct ast_cli_entry cli_commands[] = {
struct ast_sip_cli_formatter_entry *contact_formatter;
struct ast_sip_cli_formatter_entry *aor_formatter;
+/*! \brief Always create a contact_status for each contact */
+static int contact_apply_handler(const struct ast_sorcery *sorcery, void *object)
+{
+ struct ast_sip_contact_status *status;
+ struct ast_sip_contact *contact = object;
+
+ status = ast_res_pjsip_find_or_create_contact_status(contact);
+
+ return status ? 0 : -1;
+}
+
/*! \brief Initialize sorcery with location support */
int ast_sip_initialize_sorcery_location(void)
{
@@ -881,7 +897,7 @@ int ast_sip_initialize_sorcery_location(void)
ast_sorcery_apply_default(sorcery, "contact", "astdb", "registrar");
ast_sorcery_apply_default(sorcery, "aor", "config", "pjsip.conf,criteria=type=aor");
- if (ast_sorcery_object_register(sorcery, "contact", contact_alloc, NULL, NULL) ||
+ if (ast_sorcery_object_register(sorcery, "contact", contact_alloc, NULL, contact_apply_handler) ||
ast_sorcery_object_register(sorcery, "aor", aor_alloc, NULL, NULL)) {
return -1;
}
diff --git a/res/res_pjsip/pjsip_options.c b/res/res_pjsip/pjsip_options.c
index 40b6f7b4c..8ffb88c49 100644
--- a/res/res_pjsip/pjsip_options.c
+++ b/res/res_pjsip/pjsip_options.c
@@ -76,11 +76,10 @@ static void *contact_status_alloc(const char *name)
}
/*!
- * \internal
* \brief Retrieve a ast_sip_contact_status object from sorcery creating
* one if not found.
*/
-static struct ast_sip_contact_status *find_or_create_contact_status(const struct ast_sip_contact *contact)
+struct ast_sip_contact_status *ast_res_pjsip_find_or_create_contact_status(const struct ast_sip_contact *contact)
{
struct ast_sip_contact_status *status;
@@ -98,6 +97,10 @@ static struct ast_sip_contact_status *find_or_create_contact_status(const struct
return NULL;
}
+ status->status = UNKNOWN;
+ status->rtt_start = ast_tv(0, 0);
+ status->rtt = 0;
+
if (ast_sorcery_create(ast_sip_get_sorcery(), status)) {
ast_log(LOG_ERROR, "Unable to persist ast_sip_contact_status for contact %s\n",
contact->uri);
@@ -118,7 +121,7 @@ static void update_contact_status(const struct ast_sip_contact *contact,
struct ast_sip_contact_status *status;
struct ast_sip_contact_status *update;
- status = find_or_create_contact_status(contact);
+ status = ast_res_pjsip_find_or_create_contact_status(contact);
if (!status) {
ast_log(LOG_ERROR, "Unable to find ast_sip_contact_status for contact %s\n",
contact->uri);
@@ -143,8 +146,6 @@ static void update_contact_status(const struct ast_sip_contact *contact,
update->rtt_start = ast_tv(0, 0);
-
-
ast_test_suite_event_notify("AOR_CONTACT_QUALIFY_RESULT",
"Contact: %s\r\n"
"Status: %s\r\n"
@@ -172,7 +173,7 @@ static void init_start_time(const struct ast_sip_contact *contact)
struct ast_sip_contact_status *status;
struct ast_sip_contact_status *update;
- status = find_or_create_contact_status(contact);
+ status = ast_res_pjsip_find_or_create_contact_status(contact);
if (!status) {
ast_log(LOG_ERROR, "Unable to find ast_sip_contact_status for contact %s\n",
contact->uri);
diff --git a/res/res_rtp_asterisk.c b/res/res_rtp_asterisk.c
index 0513c1127..62601dcad 100644
--- a/res/res_rtp_asterisk.c
+++ b/res/res_rtp_asterisk.c
@@ -1869,6 +1869,7 @@ static int dtls_srtp_setup(struct ast_rtp *rtp, struct ast_srtp *srtp, struct as
unsigned char *local_key, *local_salt, *remote_key, *remote_salt;
struct ast_srtp_policy *local_policy, *remote_policy = NULL;
struct ast_rtp_instance_stats stats = { 0, };
+ int res = -1;
/* If a fingerprint is present in the SDP make sure that the peer certificate matches it */
if (rtp->dtls_verify & AST_RTP_DTLS_VERIFY_FINGERPRINT) {
@@ -1983,16 +1984,17 @@ static int dtls_srtp_setup(struct ast_rtp *rtp, struct ast_srtp *srtp, struct as
}
}
- return 0;
+ res = 0;
error:
+ /* policy->destroy() called even on success to release local reference to these resources */
res_srtp_policy->destroy(local_policy);
if (remote_policy) {
res_srtp_policy->destroy(remote_policy);
}
- return -1;
+ return res;
}
#endif