Commit 8481b8e7ae for asterisk.org
commit 8481b8e7aec24862f93db60bd5eb0cebc3c7f254
Author: Cetin Cem <cetincem@gaga.dev>
Date: Mon Oct 5 22:55:40 2026 +0300
res_pjsip: Include permanent contacts in PJSIPShowContacts.
Include contacts stored on AORs as well as registered contacts in the
AMI contact list. Permanent contacts were omitted because they are not
stored as sorcery contact objects.
Use a qualified AOR query so this also works when realtime disables
unqualified fetches.
AI assistance: Codex generated the code, tests, validation scripts
and text.
Fixes: #807
diff --git a/res/res_pjsip/pjsip_options.c b/res/res_pjsip/pjsip_options.c
index 7d425990e2..1507b2bf5c 100644
--- a/res/res_pjsip/pjsip_options.c
+++ b/res/res_pjsip/pjsip_options.c
@@ -2818,12 +2818,51 @@ static char *cli_qualify(struct ast_cli_entry *e, int cmd, struct ast_cli_args *
return CLI_SUCCESS;
}
+/* Retrieve registered and permanent contacts for the AMI contact list. */
static struct ao2_container *get_all_contacts(void)
{
+ struct ast_variable *fields;
struct ao2_container *contacts;
+ struct ao2_container *aors;
+ struct ao2_iterator aor_iter;
+ struct ast_sip_aor *aor;
contacts = ast_sorcery_retrieve_by_fields(ast_sip_get_sorcery(), "contact",
AST_RETRIEVE_FLAG_MULTIPLE | AST_RETRIEVE_FLAG_ALL, NULL);
+ if (!contacts) {
+ return NULL;
+ }
+
+ fields = ast_variable_new("contact !=", "", "");
+ if (!fields) {
+ ao2_ref(contacts, -1);
+ return NULL;
+ }
+
+ aors = ast_sorcery_retrieve_by_fields(ast_sip_get_sorcery(), "aor",
+ AST_RETRIEVE_FLAG_MULTIPLE, fields);
+ ast_variables_destroy(fields);
+ if (!aors) {
+ ao2_ref(contacts, -1);
+ return NULL;
+ }
+
+ aor_iter = ao2_iterator_init(aors, 0);
+ while ((aor = ao2_iterator_next(&aor_iter))) {
+ if (aor->permanent_contacts) {
+ /* The destination is temporary, so emptying it on error is fine. */
+ if (ao2_container_dup(contacts, aor->permanent_contacts, 0) == -1) {
+ ao2_ref(aor, -1);
+ ao2_ref(contacts, -1);
+ contacts = NULL;
+ goto done;
+ }
+ }
+ ao2_ref(aor, -1);
+ }
+done:
+ ao2_iterator_destroy(&aor_iter);
+ ao2_ref(aors, -1);
return contacts;
}