Debian Codegraph @

funcs/func_pjsip_endpoint.c

raw symbols SCIP
1 /*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2013, Digium, Inc.
5 *
6 * Matt Jordan <[email protected]>
7 *
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.
13 *
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.
17 */
18
19 /*! \file
20 *
21 * \brief Get information about a PJSIP endpoint
22 *
23 * \author \verbatim Matt Jordan <[email protected]> \endverbatim
24 *
25 * \ingroup functions
26 *
27 */
28
29 /*** MODULEINFO
30 <depend>pjproject</depend>
31 <depend>res_pjsip</depend>
32 <support_level>core</support_level>
33 ***/
34
35 #include "asterisk.h"
36
37 #include <pjsip.h>
38 #include <pjlib.h>
39
40 #include "asterisk/app.h"
41 #include "asterisk/pbx.h"
42 #include "asterisk/module.h"
43 #include "asterisk/channel.h"
44 #include "asterisk/sorcery.h"
45 #include "asterisk/res_pjsip.h"
46
47 /*** DOCUMENTATION
48 <function name="PJSIP_ENDPOINT" language="en_US">
49 <since>
50 <version>12.0.0</version>
51 </since>
52 <synopsis>
53 Get information about a PJSIP endpoint
54 </synopsis>
55 <syntax>
56 <parameter name="name" required="true">
57 <para>The name of the endpoint to query.</para>
58 </parameter>
59 <parameter name="field" required="true">
60 <para>The configuration option for the endpoint to query for.
61 Supported options are those fields on the
62 <replaceable>endpoint</replaceable> object in
63 <filename>pjsip.conf</filename>.</para>
64 <enumlist>
65 <configOptionToEnum>
66 <xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption)"/>
67 </configOptionToEnum>
68 </enumlist>
69 </parameter>
70 </syntax>
71 </function>
72 ***/
73
74 static int pjsip_endpoint_function_read(struct ast_channel *chan,
75 const char *cmd, char *data, struct ast_str **buf, ssize_t len)
76 {
77 struct ast_sorcery *pjsip_sorcery;
78 char *parsed_data = ast_strdupa(data);
79 RAII_VAR(void *, endpoint_obj, NULL, ao2_cleanup);
80 struct ast_variable *change_set;
81 struct ast_variable *it_change_set;
82 int res;
83
84 AST_DECLARE_APP_ARGS(args,
85 AST_APP_ARG(endpoint_name);
86 AST_APP_ARG(field_name);
87 );
88
89 /* Check for zero arguments */
90 if (ast_strlen_zero(parsed_data)) {
91 ast_log(AST_LOG_ERROR, "Cannot call %s without arguments\n", cmd);
92 return -1;
93 }
94
95 AST_STANDARD_APP_ARGS(args, parsed_data);
96
97 if (ast_strlen_zero(args.endpoint_name)) {
98 ast_log(AST_LOG_ERROR, "Cannot call %s without an endpoint name to query\n", cmd);
99 return -1;
100 }
101
102 if (ast_strlen_zero(args.field_name)) {
103 ast_log(AST_LOG_ERROR, "Cannot call %s with an empty field name to query\n", cmd);
104 return -1;
105 }
106
107 pjsip_sorcery = ast_sip_get_sorcery();
108 if (!pjsip_sorcery) {
109 ast_log(AST_LOG_ERROR, "Unable to retrieve PJSIP configuration: sorcery object is NULL\n");
110 return -1;
111 }
112
113 endpoint_obj = ast_sorcery_retrieve_by_id(pjsip_sorcery, "endpoint", args.endpoint_name);
114 if (!endpoint_obj) {
115 ast_log(AST_LOG_WARNING, "Failed to retrieve information for endpoint '%s'\n", args.endpoint_name);
116 return -1;
117 }
118
119 change_set = ast_sorcery_objectset_create(pjsip_sorcery, endpoint_obj);
120 if (!change_set) {
121 ast_log(AST_LOG_WARNING, "Failed to retrieve information for endpoint '%s': change set is NULL\n", args.endpoint_name);
122 return -1;
123 }
124
125 for (it_change_set = change_set; it_change_set; it_change_set = it_change_set->next) {
126 if (!strcmp(it_change_set->name, args.field_name)) {
127 if (!strcmp(it_change_set->name, "disallow")) {
128 ast_str_set(buf, len, "!%s", it_change_set->value);
129 } else {
130 ast_str_set(buf, len, "%s", it_change_set->value);
131 }
132 break;
133 }
134 }
135
136 res = it_change_set ? 0 : 1;
137 if (res) {
138 ast_log(AST_LOG_WARNING, "Unknown property '%s' for PJSIP endpoint\n", args.field_name);
139 }
140
141 ast_variables_destroy(change_set);
142
143 return res;
144 }
145
146
147 static struct ast_custom_function pjsip_endpoint_function = {
148 .name = "PJSIP_ENDPOINT",
149 .read2 = pjsip_endpoint_function_read,
150 };
151
152 static int unload_module(void)
153 {
154 return ast_custom_function_unregister(&pjsip_endpoint_function);
155 }
156
157 static int load_module(void)
158 {
159 return ast_custom_function_register(&pjsip_endpoint_function);
160 }
161
162 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Get information about a PJSIP endpoint",
163 .support_level = AST_MODULE_SUPPORT_CORE,
164 .load = load_module,
165 .unload = unload_module,
166 .requires = "res_pjsip",
167 );