Debian Codegraph @

funcs/func_dialplan.c

raw symbols SCIP
1 /*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2007, Digium, Inc.
5 *
6 * See http://www.asterisk.org for more information about
7 * the Asterisk project. Please do not directly contact
8 * any of the maintainers of this project for assistance;
9 * the project provides a web site, mailing lists and IRC
10 * channels for your use.
11 *
12 * This program is free software, distributed under the terms of
13 * the GNU General Public License Version 2. See the LICENSE file
14 * at the top of the source tree.
15 */
16
17 /*! \file
18 *
19 * \brief Dialplan group functions check if a dialplan entry exists
20 *
21 * \author Gregory Nietsky AKA irroot <[email protected]>
22 * \author Russell Bryant <[email protected]>
23 *
24 * \ingroup functions
25 */
26
27 /*** MODULEINFO
28 <support_level>core</support_level>
29 ***/
30
31 #include "asterisk.h"
32
33 #include "asterisk/module.h"
34 #include "asterisk/channel.h"
35 #include "asterisk/pbx.h"
36 #include "asterisk/app.h"
37
38 /*** DOCUMENTATION
39 <function name="DIALPLAN_EXISTS" language="en_US">
40 <since>
41 <version>1.6.0</version>
42 </since>
43 <synopsis>
44 Checks the existence of a dialplan target.
45 </synopsis>
46 <syntax>
47 <parameter name="context" required="true" />
48 <parameter name="extension" />
49 <parameter name="priority" />
50 </syntax>
51 <description>
52 <para>This function returns <literal>1</literal> if the target exits. Otherwise, it returns <literal>0</literal>.</para>
53 </description>
54 </function>
55 <function name="VALID_EXTEN" language="en_US">
56 <since>
57 <version>11.0.0</version>
58 </since>
59 <synopsis>
60 Determine whether an extension exists or not.
61 </synopsis>
62 <syntax>
63 <parameter name="context">
64 <para>Defaults to the current context</para>
65 </parameter>
66 <parameter name="extension" required="true" />
67 <parameter name="priority">
68 <para>Priority defaults to <literal>1</literal>.</para>
69 </parameter>
70 </syntax>
71 <description>
72 <para>Returns a true value if the indicated <replaceable>context</replaceable>,
73 <replaceable>extension</replaceable>, and <replaceable>priority</replaceable> exist.</para>
74 <warning><para>This function has been deprecated in favor of the <literal>DIALPLAN_EXISTS()</literal> function</para></warning>
75 </description>
76 </function>
77 ***/
78
79 static int isexten_function_read(struct ast_channel *chan, const char *cmd, char *data,
80 char *buf, size_t len)
81 {
82 char *parse;
83 AST_DECLARE_APP_ARGS(args,
84 AST_APP_ARG(context);
85 AST_APP_ARG(exten);
86 AST_APP_ARG(priority);
87 );
88
89 strcpy(buf, "0");
90
91 if (ast_strlen_zero(data)) {
92 ast_log(LOG_ERROR, "DIALPLAN_EXISTS() requires an argument\n");
93 return -1;
94 }
95
96 parse = ast_strdupa(data);
97 AST_STANDARD_APP_ARGS(args, parse);
98
99 if (!ast_strlen_zero(args.priority)) {
100 int priority_num;
101 if (sscanf(args.priority, "%30d", &priority_num) == 1 && priority_num > 0) {
102 int res;
103 res = ast_exists_extension(chan, args.context, args.exten, priority_num,
104 !chan ? NULL :
105 S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL));
106 if (res)
107 strcpy(buf, "1");
108 } else {
109 int res;
110 res = ast_findlabel_extension(chan, args.context, args.exten, args.priority,
111 !chan ? NULL :
112 S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL));
113 if (res > 0)
114 strcpy(buf, "1");
115 }
116 } else if (!ast_strlen_zero(args.exten)) {
117 int res;
118 res = ast_exists_extension(chan, args.context, args.exten, 1,
119 !chan ? NULL :
120 S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL));
121 if (res)
122 strcpy(buf, "1");
123 } else if (!ast_strlen_zero(args.context)) {
124 if (ast_context_find(args.context))
125 strcpy(buf, "1");
126 } else {
127 ast_log(LOG_ERROR, "Invalid arguments provided to DIALPLAN_EXISTS\n");
128 return -1;
129 }
130
131 return 0;
132 }
133
134 static int acf_isexten_exec(struct ast_channel *chan, const char *cmd, char *parse, char *buffer, size_t buflen)
135 {
136 int priority_int;
137 AST_DECLARE_APP_ARGS(args,
138 AST_APP_ARG(context);
139 AST_APP_ARG(extension);
140 AST_APP_ARG(priority);
141 );
142
143 if (!chan) {
144 ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
145 return -1;
146 }
147
148 AST_STANDARD_APP_ARGS(args, parse);
149
150 if (ast_strlen_zero(args.context)) {
151 args.context = ast_strdupa(ast_channel_context(chan));
152 }
153
154 if (ast_strlen_zero(args.extension)) {
155 ast_log(LOG_WARNING, "Syntax: VALID_EXTEN([<context>],<extension>[,<priority>]) - missing argument <extension>!\n");
156 return -1;
157 }
158
159 if (ast_strlen_zero(args.priority)) {
160 priority_int = 1;
161 } else {
162 priority_int = atoi(args.priority);
163 }
164
165 if (ast_exists_extension(chan, args.context, args.extension, priority_int,
166 S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL))) {
167 ast_copy_string(buffer, "1", buflen);
168 } else {
169 ast_copy_string(buffer, "0", buflen);
170 }
171
172 return 0;
173 }
174
175 static struct ast_custom_function isexten_function = {
176 .name = "DIALPLAN_EXISTS",
177 .read = isexten_function_read,
178 .read_max = 2,
179 };
180
181 static struct ast_custom_function acf_isexten = {
182 .name = "VALID_EXTEN",
183 .read = acf_isexten_exec,
184 };
185
186 static int unload_module(void)
187 {
188 int res = ast_custom_function_unregister(&isexten_function);
189 res |= ast_custom_function_unregister(&acf_isexten);
190 return res;
191 }
192
193 static int load_module(void)
194 {
195 int res = ast_custom_function_register(&isexten_function);
196 res |= ast_custom_function_register(&acf_isexten);
197 return res;
198 }
199
200 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Dialplan Context/Extension/Priority Checking Functions",
201 .support_level = AST_MODULE_SUPPORT_CORE,
202 .load = load_module,
203 .unload = unload_module,
204 .load_pri = AST_MODPRI_APP_DEPEND,
205 );