Asterisk - The Open Source Telephony Project GIT-master-f36a736
func_dialplan.c
Go to the documentation of this file.
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 <gregory@networksentry.co.za>
22 * \author Russell Bryant <russell@digium.com>
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 <synopsis>
41 Checks the existence of a dialplan target.
42 </synopsis>
43 <syntax>
44 <parameter name="context" required="true" />
45 <parameter name="extension" />
46 <parameter name="priority" />
47 </syntax>
48 <description>
49 <para>This function returns <literal>1</literal> if the target exits. Otherwise, it returns <literal>0</literal>.</para>
50 </description>
51 </function>
52 <function name="VALID_EXTEN" language="en_US">
53 <synopsis>
54 Determine whether an extension exists or not.
55 </synopsis>
56 <syntax>
57 <parameter name="context">
58 <para>Defaults to the current context</para>
59 </parameter>
60 <parameter name="extension" required="true" />
61 <parameter name="priority">
62 <para>Priority defaults to <literal>1</literal>.</para>
63 </parameter>
64 </syntax>
65 <description>
66 <para>Returns a true value if the indicated <replaceable>context</replaceable>,
67 <replaceable>extension</replaceable>, and <replaceable>priority</replaceable> exist.</para>
68 <warning><para>This function has been deprecated in favor of the <literal>DIALPLAN_EXISTS()</literal> function</para></warning>
69 </description>
70 </function>
71 ***/
72
73static int isexten_function_read(struct ast_channel *chan, const char *cmd, char *data,
74 char *buf, size_t len)
75{
76 char *parse;
79 AST_APP_ARG(exten);
81 );
82
83 strcpy(buf, "0");
84
85 if (ast_strlen_zero(data)) {
86 ast_log(LOG_ERROR, "DIALPLAN_EXISTS() requires an argument\n");
87 return -1;
88 }
89
90 parse = ast_strdupa(data);
92
93 if (!ast_strlen_zero(args.priority)) {
94 int priority_num;
95 if (sscanf(args.priority, "%30d", &priority_num) == 1 && priority_num > 0) {
96 int res;
97 res = ast_exists_extension(chan, args.context, args.exten, priority_num,
98 !chan ? NULL :
99 S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL));
100 if (res)
101 strcpy(buf, "1");
102 } else {
103 int res;
104 res = ast_findlabel_extension(chan, args.context, args.exten, args.priority,
105 !chan ? NULL :
106 S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL));
107 if (res > 0)
108 strcpy(buf, "1");
109 }
110 } else if (!ast_strlen_zero(args.exten)) {
111 int res;
112 res = ast_exists_extension(chan, args.context, args.exten, 1,
113 !chan ? NULL :
114 S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL));
115 if (res)
116 strcpy(buf, "1");
117 } else if (!ast_strlen_zero(args.context)) {
118 if (ast_context_find(args.context))
119 strcpy(buf, "1");
120 } else {
121 ast_log(LOG_ERROR, "Invalid arguments provided to DIALPLAN_EXISTS\n");
122 return -1;
123 }
124
125 return 0;
126}
127
128static int acf_isexten_exec(struct ast_channel *chan, const char *cmd, char *parse, char *buffer, size_t buflen)
129{
130 int priority_int;
135 );
136
137 if (!chan) {
138 ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
139 return -1;
140 }
141
143
144 if (ast_strlen_zero(args.context)) {
145 args.context = ast_strdupa(ast_channel_context(chan));
146 }
147
148 if (ast_strlen_zero(args.extension)) {
149 ast_log(LOG_WARNING, "Syntax: VALID_EXTEN([<context>],<extension>[,<priority>]) - missing argument <extension>!\n");
150 return -1;
151 }
152
153 if (ast_strlen_zero(args.priority)) {
154 priority_int = 1;
155 } else {
156 priority_int = atoi(args.priority);
157 }
158
159 if (ast_exists_extension(chan, args.context, args.extension, priority_int,
160 S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL))) {
161 ast_copy_string(buffer, "1", buflen);
162 } else {
163 ast_copy_string(buffer, "0", buflen);
164 }
165
166 return 0;
167}
168
170 .name = "DIALPLAN_EXISTS",
171 .read = isexten_function_read,
172 .read_max = 2,
173};
174
176 .name = "VALID_EXTEN",
177 .read = acf_isexten_exec,
178};
179
180static int unload_module(void)
181{
184 return res;
185}
186
187static int load_module(void)
188{
191 return res;
192}
193
194AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Dialplan Context/Extension/Priority Checking Functions",
195 .support_level = AST_MODULE_SUPPORT_CORE,
196 .load = load_module,
197 .unload = unload_module,
198 .load_pri = AST_MODPRI_APP_DEPEND,
Asterisk main include file. File version handling, generic pbx functions.
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define ast_log
Definition: astobj2.c:42
static int priority
General Asterisk PBX channel definitions.
const char * ast_channel_context(const struct ast_channel *chan)
struct ast_party_caller * ast_channel_caller(struct ast_channel *chan)
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
static int acf_isexten_exec(struct ast_channel *chan, const char *cmd, char *parse, char *buffer, size_t buflen)
static struct ast_custom_function isexten_function
static struct ast_custom_function acf_isexten
static int load_module(void)
static int unload_module(void)
static int isexten_function_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
Definition: func_dialplan.c:73
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
Application convenience functions, designed to give consistent look and feel to Asterisk apps.
#define AST_APP_ARG(name)
Define an application argument.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
#define LOG_ERROR
#define LOG_WARNING
Asterisk module definitions.
@ AST_MODFLAG_LOAD_ORDER
Definition: module.h:331
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
Definition: module.h:557
@ AST_MODPRI_APP_DEPEND
Definition: module.h:342
@ AST_MODULE_SUPPORT_CORE
Definition: module.h:121
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
Core PBX routines and definitions.
int ast_findlabel_extension(struct ast_channel *c, const char *context, const char *exten, const char *label, const char *callerid)
Find the priority of an extension that has the specified label.
Definition: pbx.c:4180
struct ast_context * ast_context_find(const char *name)
Find a context.
Definition: extconf.c:4172
int ast_exists_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Determine whether an extension exists.
Definition: pbx.c:4175
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1558
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
#define NULL
Definition: resample.c:96
#define S_COR(a, b, c)
returns the equivalent of logic or for strings, with an additional boolean check: second one if not e...
Definition: strings.h:87
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425
Main Channel structure associated with a channel.
Data structure associated with a custom dialplan function.
Definition: pbx.h:118
const char * name
Definition: pbx.h:119
structure to hold extensions
Number structure.
Definition: app_followme.c:154
const char * args