2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 2007, Digium, Inc.
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.
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.
19 * \brief Dialplan group functions check if a dialplan entry exists
21 * \author Gregory Nietsky AKA irroot <gregory@networksentry.co.za>
22 * \author Russell Bryant <russell@digium.com>
29 ASTERISK_FILE_VERSION(__FILE__
, "$Revision$")
31 #include "asterisk/module.h"
32 #include "asterisk/channel.h"
33 #include "asterisk/pbx.h"
34 #include "asterisk/app.h"
36 static int isexten_function_read(struct ast_channel
*chan
, const char *cmd
, char *data
,
37 char *buf
, size_t len
)
40 AST_DECLARE_APP_ARGS(args
,
43 AST_APP_ARG(priority
);
48 if (ast_strlen_zero(data
)) {
49 ast_log(LOG_ERROR
, "DIALPLAN_EXISTS() requires an argument\n");
53 parse
= ast_strdupa(data
);
54 AST_STANDARD_APP_ARGS(args
, parse
);
56 if (!ast_strlen_zero(args
.priority
)) {
58 if (sscanf(args
.priority
, "%d", &priority_num
) == 1 && priority_num
> 0) {
60 res
= ast_exists_extension(chan
, args
.context
, args
.exten
, priority_num
,
66 res
= ast_findlabel_extension(chan
, args
.context
, args
.exten
,
67 args
.priority
, chan
->cid
.cid_num
);
71 } else if (!ast_strlen_zero(args
.exten
)) {
73 res
= ast_exists_extension(chan
, args
.context
, args
.exten
, 1,
77 } else if (!ast_strlen_zero(args
.context
)) {
78 if (ast_context_find(args
.context
))
81 ast_log(LOG_ERROR
, "Invalid arguments provided to DIALPLAN_EXISTS\n");
88 static struct ast_custom_function isexten_function
= {
89 .name
= "DIALPLAN_EXISTS",
90 .syntax
= "DIALPLAN_EXISTS(context[,extension[,priority]])",
91 .synopsis
= "Checks the existence of a dialplan target.",
92 .desc
= "This function returns 1 if the target exits. Otherwise, it returns 0.\n",
93 .read
= isexten_function_read
,
96 static int unload_module(void)
98 return ast_custom_function_unregister(&isexten_function
);
101 static int load_module(void)
103 return ast_custom_function_register(&isexten_function
);
106 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY
, "Dialplan Context/Extension/Priority Checking Functions");