Asterisk - The Open Source Telephony Project GIT-master-0deac78
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 <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 ***/
56
57static int isexten_function_read(struct ast_channel *chan, const char *cmd, char *data,
58 char *buf, size_t len)
59{
60 char *parse;
63 AST_APP_ARG(exten);
65 );
66
67 strcpy(buf, "0");
68
69 if (ast_strlen_zero(data)) {
70 ast_log(LOG_ERROR, "DIALPLAN_EXISTS() requires an argument\n");
71 return -1;
72 }
73
74 parse = ast_strdupa(data);
76
77 if (!ast_strlen_zero(args.priority)) {
78 int priority_num;
79 if (sscanf(args.priority, "%30d", &priority_num) == 1 && priority_num > 0) {
80 int res;
81 res = ast_exists_extension(chan, args.context, args.exten, priority_num,
82 !chan ? NULL :
83 S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL));
84 if (res)
85 strcpy(buf, "1");
86 } else {
87 int res;
88 res = ast_findlabel_extension(chan, args.context, args.exten, args.priority,
89 !chan ? NULL :
90 S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL));
91 if (res > 0)
92 strcpy(buf, "1");
93 }
94 } else if (!ast_strlen_zero(args.exten)) {
95 int res;
96 res = ast_exists_extension(chan, args.context, args.exten, 1,
97 !chan ? NULL :
98 S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL));
99 if (res)
100 strcpy(buf, "1");
101 } else if (!ast_strlen_zero(args.context)) {
102 if (ast_context_find(args.context))
103 strcpy(buf, "1");
104 } else {
105 ast_log(LOG_ERROR, "Invalid arguments provided to DIALPLAN_EXISTS\n");
106 return -1;
107 }
108
109 return 0;
110}
111
113 .name = "DIALPLAN_EXISTS",
114 .read = isexten_function_read,
115 .read_max = 2,
116};
117
118static int unload_module(void)
119{
121}
122
123static int load_module(void)
124{
126}
127
128AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Dialplan Context/Extension/Priority Checking Functions",
129 .support_level = AST_MODULE_SUPPORT_CORE,
130 .load = load_module,
131 .unload = unload_module,
132 .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.
struct ast_party_caller * ast_channel_caller(struct ast_channel *chan)
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
static struct ast_custom_function isexten_function
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:57
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
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:4201
struct ast_context * ast_context_find(const char *name)
Find a context.
Definition: extconf.c:4170
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:4196
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1562
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
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
Number structure.
Definition: app_followme.c:157
const char * args