Wed Jan 8 2020 09:49:47

Asterisk developer's documentation


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 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 411313 $")
34 
35 #include "asterisk/module.h"
36 #include "asterisk/channel.h"
37 #include "asterisk/pbx.h"
38 #include "asterisk/app.h"
39 
40 /*** DOCUMENTATION
41  <function name="DIALPLAN_EXISTS" language="en_US">
42  <synopsis>
43  Checks the existence of a dialplan target.
44  </synopsis>
45  <syntax>
46  <parameter name="context" required="true" />
47  <parameter name="extension" />
48  <parameter name="priority" />
49  </syntax>
50  <description>
51  <para>This function returns <literal>1</literal> if the target exits. Otherwise, it returns <literal>0</literal>.</para>
52  </description>
53  </function>
54 
55  ***/
56 
57 static int isexten_function_read(struct ast_channel *chan, const char *cmd, char *data,
58  char *buf, size_t len)
59 {
60  char *parse;
64  AST_APP_ARG(priority);
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(chan->caller.id.number.valid, chan->caller.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(chan->caller.id.number.valid, chan->caller.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(chan->caller.id.number.valid, chan->caller.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 
118 static int unload_module(void)
119 {
120  return ast_custom_function_unregister(&isexten_function);
121 }
122 
123 static int load_module(void)
124 {
125  return ast_custom_function_register(&isexten_function);
126 }
127 
128 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Dialplan Context/Extension/Priority Checking Functions",
129  .load = load_module,
130  .unload = unload_module,
131  .load_pri = AST_MODPRI_APP_DEPEND,
132  );
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:109
Main Channel structure associated with a channel.
Definition: channel.h:742
char * str
Subscriber phone number (Malloced)
Definition: channel.h:241
Asterisk main include file. File version handling, generic pbx functions.
struct ast_party_caller caller
Channel Caller ID information.
Definition: channel.h:804
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
Definition: app.h:572
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
Definition: module.h:374
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
Definition: pbx.c:3814
struct ast_party_id id
Caller party ID.
Definition: channel.h:370
static int unload_module(void)
General Asterisk PBX channel definitions.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
Data structure associated with a custom dialplan function.
Definition: pbx.h:95
#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:83
static int isexten_function_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
Definition: func_dialplan.c:57
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:5400
Core PBX routines and definitions.
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
#define LOG_ERROR
Definition: logger.h:155
static struct @350 args
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:5405
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1858
char data[0]
Definition: astdb.h:33
static struct ast_custom_function isexten_function
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
const char * name
Definition: pbx.h:96
#define AST_APP_ARG(name)
Define an application argument.
Definition: app.h:555
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
Definition: app.h:604
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:38
unsigned char valid
TRUE if the number information is valid/present.
Definition: channel.h:247
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1164
struct ast_context * ast_context_find(const char *name)
Find a context.
Definition: pbx.c:2971
static int load_module(void)
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
Definition: asterisk.h:180
struct ast_party_number number
Subscriber phone number.
Definition: channel.h:292