2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 2013, Digium, Inc.
6 * Matt Jordan <mjordan@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 endpoint
23 * \author \verbatim Matt Jordan <mjordan@digium.com> \endverbatim
30 <support_level>core</support_level>
31 <depend>pjproject</depend>
32 <depend>res_pjsip</depend>
37 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
42 #include "asterisk/app.h"
43 #include "asterisk/pbx.h"
44 #include "asterisk/module.h"
45 #include "asterisk/channel.h"
46 #include "asterisk/sorcery.h"
47 #include "asterisk/res_pjsip.h"
50 <function name="PJSIP_ENDPOINT" language="en_US">
52 Get information about a PJSIP endpoint
55 <parameter name="name" required="true">
56 <para>The name of the endpoint to query.</para>
58 <parameter name="field" required="true">
59 <para>The configuration option for the endpoint to query for.
60 Supported options are those fields on the
61 <replaceable>endpoint</replaceable> object in
62 <filename>pjsip.conf</filename>.</para>
65 <xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption)"/>
73 static int pjsip_endpoint_function_read(struct ast_channel *chan,
74 const char *cmd, char *data, struct ast_str **buf, ssize_t len)
76 struct ast_sorcery *pjsip_sorcery;
77 char *parsed_data = ast_strdupa(data);
78 RAII_VAR(void *, endpoint_obj, NULL, ao2_cleanup);
79 struct ast_variable *change_set;
80 struct ast_variable *it_change_set;
83 AST_DECLARE_APP_ARGS(args,
84 AST_APP_ARG(endpoint_name);
85 AST_APP_ARG(field_name);
88 /* Check for zero arguments */
89 if (ast_strlen_zero(parsed_data)) {
90 ast_log(AST_LOG_ERROR, "Cannot call %s without arguments\n", cmd);
94 AST_STANDARD_APP_ARGS(args, parsed_data);
96 if (ast_strlen_zero(args.endpoint_name)) {
97 ast_log(AST_LOG_ERROR, "Cannot call %s without an endpoint name to query\n", cmd);
101 if (ast_strlen_zero(args.field_name)) {
102 ast_log(AST_LOG_ERROR, "Cannot call %s with an empty field name to query\n", cmd);
106 pjsip_sorcery = ast_sip_get_sorcery();
107 if (!pjsip_sorcery) {
108 ast_log(AST_LOG_ERROR, "Unable to retrieve PJSIP configuration: sorcery object is NULL\n");
112 endpoint_obj = ast_sorcery_retrieve_by_id(pjsip_sorcery, "endpoint", args.endpoint_name);
114 ast_log(AST_LOG_WARNING, "Failed to retrieve information for endpoint '%s'\n", args.endpoint_name);
118 change_set = ast_sorcery_objectset_create(pjsip_sorcery, endpoint_obj);
120 ast_log(AST_LOG_WARNING, "Failed to retrieve information for endpoint '%s': change set is NULL\n", args.endpoint_name);
124 for (it_change_set = change_set; it_change_set; it_change_set = it_change_set->next) {
125 if (!strcmp(it_change_set->name, args.field_name)) {
126 if (!strcmp(it_change_set->name, "disallow")) {
127 ast_str_set(buf, len, "!%s", it_change_set->value);
129 ast_str_set(buf, len, "%s", it_change_set->value);
135 res = it_change_set ? 0 : 1;
137 ast_log(AST_LOG_WARNING, "Unknown property '%s' for PJSIP endpoint\n", args.field_name);
140 ast_variables_destroy(change_set);
146 static struct ast_custom_function pjsip_endpoint_function = {
147 .name = "PJSIP_ENDPOINT",
148 .read2 = pjsip_endpoint_function_read,
151 static int unload_module(void)
153 return ast_custom_function_unregister(&pjsip_endpoint_function);
156 static int load_module(void)
158 return ast_custom_function_register(&pjsip_endpoint_function);
161 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Get information about a PJSIP endpoint");