2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 2015, Digium, Inc.
6 * Joshua Colp <jcolp@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
21 * \brief Get information about a PJSIP AOR
23 * \author \verbatim Joshua Colp <jcolp@digium.com> \endverbatim
30 <support_level>core</support_level>
31 <depend>pjproject</depend>
32 <depend>res_pjsip</depend>
37 ASTERISK_REGISTER_FILE()
42 #include "asterisk/app.h"
43 #include "asterisk/pbx.h"
44 #include "asterisk/module.h"
45 #include "asterisk/sorcery.h"
46 #include "asterisk/res_pjsip.h"
49 <function name="PJSIP_AOR" language="en_US">
51 Get information about a PJSIP AOR
54 <parameter name="name" required="true">
55 <para>The name of the AOR to query.</para>
57 <parameter name="field" required="true">
58 <para>The configuration option for the AOR to query for.
59 Supported options are those fields on the
60 <replaceable>aor</replaceable> object in
61 <filename>pjsip.conf</filename>.</para>
64 <xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='aor']/configOption)"/>
72 static int pjsip_aor_function_read(struct ast_channel *chan,
73 const char *cmd, char *data, struct ast_str **buf, ssize_t len)
75 struct ast_sorcery *pjsip_sorcery;
76 char *parsed_data = ast_strdupa(data);
77 RAII_VAR(struct ast_sip_aor *, aor_obj, NULL, ao2_cleanup);
80 AST_DECLARE_APP_ARGS(args,
81 AST_APP_ARG(aor_name);
82 AST_APP_ARG(field_name);
85 /* Check for zero arguments */
86 if (ast_strlen_zero(parsed_data)) {
87 ast_log(AST_LOG_ERROR, "Cannot call %s without arguments\n", cmd);
91 AST_STANDARD_APP_ARGS(args, parsed_data);
93 if (ast_strlen_zero(args.aor_name)) {
94 ast_log(AST_LOG_ERROR, "Cannot call %s without an AOR name to query\n", cmd);
98 if (ast_strlen_zero(args.field_name)) {
99 ast_log(AST_LOG_ERROR, "Cannot call %s with an empty field name to query\n", cmd);
103 pjsip_sorcery = ast_sip_get_sorcery();
104 if (!pjsip_sorcery) {
105 ast_log(AST_LOG_ERROR, "Unable to retrieve PJSIP configuration: sorcery object is NULL\n");
109 aor_obj = ast_sorcery_retrieve_by_id(pjsip_sorcery, "aor", args.aor_name);
111 ast_log(AST_LOG_WARNING, "Failed to retrieve information for AOR '%s'\n", args.aor_name);
115 if (!strcmp(args.field_name, "contact")) {
116 /* The multiple fields handler for contact does not provide a list of contact object names, which is what we want, so we
117 * handle contact specifically to provide this.
119 RAII_VAR(struct ao2_container *, contacts, NULL, ao2_cleanup);
120 struct ao2_iterator i;
121 struct ast_sip_contact *contact;
124 contacts = ast_sip_location_retrieve_aor_contacts(aor_obj);
126 ast_log(LOG_WARNING, "Failed to retrieve contacts for AOR '%s'\n", args.aor_name);
130 i = ao2_iterator_init(contacts, 0);
131 while ((contact = ao2_iterator_next(&i))) {
133 ast_str_append(buf, len, "%s", ",");
136 ast_str_append(buf, len, "%s", ast_sorcery_object_get_id(contact));
139 ao2_iterator_destroy(&i);
141 struct ast_variable *change_set;
142 struct ast_variable *it_change_set;
144 change_set = ast_sorcery_objectset_create(pjsip_sorcery, aor_obj);
146 ast_log(AST_LOG_WARNING, "Failed to retrieve information for AOR '%s': change set is NULL\n", args.aor_name);
150 for (it_change_set = change_set; it_change_set; it_change_set = it_change_set->next) {
151 if (!strcmp(it_change_set->name, args.field_name)) {
152 ast_str_set(buf, len, "%s", it_change_set->value);
157 if (!it_change_set) {
158 ast_log(AST_LOG_WARNING, "Unknown property '%s' for PJSIP AOR\n", args.field_name);
162 ast_variables_destroy(change_set);
169 static struct ast_custom_function pjsip_aor_function = {
171 .read2 = pjsip_aor_function_read,
174 static int unload_module(void)
176 return ast_custom_function_unregister(&pjsip_aor_function);
179 static int load_module(void)
181 return ast_custom_function_register(&pjsip_aor_function);
184 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Get information about a PJSIP AOR");