Asterisk - The Open Source Telephony Project  18.5.0
Functions | Variables
func_dialplan.c File Reference

Dialplan group functions check if a dialplan entry exists. More...

#include "asterisk.h"
#include "asterisk/module.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/app.h"
Include dependency graph for func_dialplan.c:

Go to the source code of this file.

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
static int acf_isexten_exec (struct ast_channel *chan, const char *cmd, char *parse, char *buffer, size_t buflen)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int isexten_function_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
 
static int load_module (void)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Dialplan Context/Extension/Priority Checking Functions" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "30ef0c93b36035ec78c9cfd712d36d9b" , .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_APP_DEPEND, }
 
static struct ast_custom_function acf_isexten
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct ast_custom_function isexten_function
 

Detailed Description

Dialplan group functions check if a dialplan entry exists.

Author
Gregory Nietsky AKA irroot grego.nosp@m.ry@n.nosp@m.etwor.nosp@m.ksen.nosp@m.try.c.nosp@m.o.za
Russell Bryant russe.nosp@m.ll@d.nosp@m.igium.nosp@m..com

Definition in file func_dialplan.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 199 of file func_dialplan.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 199 of file func_dialplan.c.

◆ acf_isexten_exec()

static int acf_isexten_exec ( struct ast_channel chan,
const char *  cmd,
char *  parse,
char *  buffer,
size_t  buflen 
)
static

Definition at line 128 of file func_dialplan.c.

References args, AST_APP_ARG, ast_channel_caller(), ast_channel_context(), ast_copy_string(), AST_DECLARE_APP_ARGS, ast_exists_extension(), ast_log, AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero, context, LOG_WARNING, NULL, priority, and S_COR.

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 }
struct ast_party_caller * ast_channel_caller(struct ast_channel *chan)
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
#define LOG_WARNING
Definition: logger.h:274
const char * args
#define NULL
Definition: resample.c:96
static int priority
#define ast_strlen_zero(foo)
Definition: strings.h:52
Number structure.
Definition: app_followme.c:154
#define ast_log
Definition: astobj2.c:42
structure to hold extensions
#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:85
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
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:4179
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1872
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
const char * ast_channel_context(const struct ast_channel *chan)
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
#define AST_APP_ARG(name)
Define an application argument.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 199 of file func_dialplan.c.

◆ isexten_function_read()

static int isexten_function_read ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  len 
)
static

Definition at line 73 of file func_dialplan.c.

References args, AST_APP_ARG, ast_channel_caller(), ast_context_find(), AST_DECLARE_APP_ARGS, ast_exists_extension(), ast_findlabel_extension(), ast_log, AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero, context, exten, LOG_ERROR, NULL, parse(), priority, and S_COR.

75 {
76  char *parse;
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 }
struct ast_party_caller * ast_channel_caller(struct ast_channel *chan)
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
const char * args
#define NULL
Definition: resample.c:96
static int priority
#define ast_strlen_zero(foo)
Definition: strings.h:52
Number structure.
Definition: app_followme.c:154
#define ast_log
Definition: astobj2.c:42
struct ast_context * ast_context_find(const char *name)
Find a context.
Definition: extconf.c:4174
#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:85
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
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:4179
#define LOG_ERROR
Definition: logger.h:285
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:4184
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1872
char data[0]
Definition: astdb.h:34
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
#define AST_APP_ARG(name)
Define an application argument.

◆ load_module()

static int load_module ( void  )
static

Definition at line 187 of file func_dialplan.c.

References ast_custom_function_register, AST_MODFLAG_LOAD_ORDER, AST_MODPRI_APP_DEPEND, AST_MODULE_INFO(), AST_MODULE_SUPPORT_CORE, ASTERISK_GPL_KEY, and unload_module().

188 {
191  return res;
192 }
static struct ast_custom_function acf_isexten
static struct ast_custom_function isexten_function
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1508

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 180 of file func_dialplan.c.

References ast_custom_function_unregister().

Referenced by load_module().

181 {
184  return res;
185 }
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
static struct ast_custom_function acf_isexten
static struct ast_custom_function isexten_function

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Dialplan Context/Extension/Priority Checking Functions" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "30ef0c93b36035ec78c9cfd712d36d9b" , .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_APP_DEPEND, }
static

Definition at line 199 of file func_dialplan.c.

◆ acf_isexten

struct ast_custom_function acf_isexten
static
Initial value:
= {
.name = "VALID_EXTEN",
}
static int acf_isexten_exec(struct ast_channel *chan, const char *cmd, char *parse, char *buffer, size_t buflen)

Definition at line 175 of file func_dialplan.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 199 of file func_dialplan.c.

◆ isexten_function

struct ast_custom_function isexten_function
static
Initial value:
= {
.name = "DIALPLAN_EXISTS",
.read_max = 2,
}
static int isexten_function_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
Definition: func_dialplan.c:73

Definition at line 169 of file func_dialplan.c.