Merge "res_pjsip: Use sorcery prefix operation for contact lookup" into 13

This commit is contained in:
Joshua Colp
2017-11-20 16:53:25 -06:00
committed by Gerrit Code Review

View File

@@ -71,16 +71,17 @@ static void aor_deleted_observer(const void *object)
{ {
const struct ast_sip_aor *aor = object; const struct ast_sip_aor *aor = object;
const char *aor_id = ast_sorcery_object_get_id(object); const char *aor_id = ast_sorcery_object_get_id(object);
/* Give enough space for ^ at the beginning and ;@ at the end, since that is our object naming scheme */ /* Give enough space for ;@ at the end, since that is our object naming scheme */
char regex[strlen(aor_id) + 4]; size_t prefix_len = strlen(aor_id) + sizeof(";@") - 1;
char prefix[prefix_len + 1];
struct ao2_container *contacts; struct ao2_container *contacts;
if (aor->permanent_contacts) { if (aor->permanent_contacts) {
ao2_callback(aor->permanent_contacts, OBJ_NODATA | OBJ_MULTIPLE | OBJ_UNLINK, destroy_contact, NULL); ao2_callback(aor->permanent_contacts, OBJ_NODATA | OBJ_MULTIPLE | OBJ_UNLINK, destroy_contact, NULL);
} }
snprintf(regex, sizeof(regex), "^%s;@", aor_id); sprintf(prefix, "%s;@", aor_id); /* Safe */
if (!(contacts = ast_sorcery_retrieve_by_regex(ast_sip_get_sorcery(), "contact", regex))) { if (!(contacts = ast_sorcery_retrieve_by_prefix(ast_sip_get_sorcery(), "contact", prefix, prefix_len))) {
return; return;
} }
/* Destroy any contacts that may still exist that were made for this AoR */ /* Destroy any contacts that may still exist that were made for this AoR */
@@ -217,13 +218,13 @@ struct ao2_container *ast_sip_location_retrieve_aor_contacts_nolock(const struct
struct ao2_container *ast_sip_location_retrieve_aor_contacts_nolock_filtered(const struct ast_sip_aor *aor, struct ao2_container *ast_sip_location_retrieve_aor_contacts_nolock_filtered(const struct ast_sip_aor *aor,
unsigned int flags) unsigned int flags)
{ {
/* Give enough space for ^ at the beginning and ;@ at the end, since that is our object naming scheme */ /* Give enough space for ;@ at the end, since that is our object naming scheme */
char regex[strlen(ast_sorcery_object_get_id(aor)) + 4]; size_t prefix_len = strlen(ast_sorcery_object_get_id(aor)) + sizeof(";@") - 1;
char prefix[prefix_len + 1];
struct ao2_container *contacts; struct ao2_container *contacts;
snprintf(regex, sizeof(regex), "^%s;@", ast_sorcery_object_get_id(aor)); sprintf(prefix, "%s;@", ast_sorcery_object_get_id(aor)); /* Safe */
if (!(contacts = ast_sorcery_retrieve_by_prefix(ast_sip_get_sorcery(), "contact", prefix, prefix_len))) {
if (!(contacts = ast_sorcery_retrieve_by_regex(ast_sip_get_sorcery(), "contact", regex))) {
return NULL; return NULL;
} }