Merged revisions 121078 via svnmerge from
[asterisk-bristuff.git] / funcs / func_dialplan.c
blob6d4c488f6068c9fd9458cde2a04665e0ba504924
1 /*
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.
17 /*! \file
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>
24 * \ingroup functions
27 #include "asterisk.h"
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)
39 char *parse;
40 AST_DECLARE_APP_ARGS(args,
41 AST_APP_ARG(context);
42 AST_APP_ARG(exten);
43 AST_APP_ARG(priority);
46 strcpy(buf, "0");
48 if (ast_strlen_zero(data)) {
49 ast_log(LOG_ERROR, "DIALPLAN_EXISTS() requires an argument\n");
50 return -1;
53 parse = ast_strdupa(data);
54 AST_STANDARD_APP_ARGS(args, parse);
56 if (!ast_strlen_zero(args.priority)) {
57 int priority_num;
58 if (sscanf(args.priority, "%d", &priority_num) == 1 && priority_num > 0) {
59 int res;
60 res = ast_exists_extension(chan, args.context, args.exten, priority_num,
61 chan->cid.cid_num);
62 if (res)
63 strcpy(buf, "1");
64 } else {
65 int res;
66 res = ast_findlabel_extension(chan, args.context, args.exten,
67 args.priority, chan->cid.cid_num);
68 if (res > 0)
69 strcpy(buf, "1");
71 } else if (!ast_strlen_zero(args.exten)) {
72 int res;
73 res = ast_exists_extension(chan, args.context, args.exten, 1,
74 chan->cid.cid_num);
75 if (res)
76 strcpy(buf, "1");
77 } else if (!ast_strlen_zero(args.context)) {
78 if (ast_context_find(args.context))
79 strcpy(buf, "1");
80 } else {
81 ast_log(LOG_ERROR, "Invalid arguments provided to DIALPLAN_EXISTS\n");
82 return -1;
85 return 0;
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");