func_dialplan.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "asterisk.h"
00028
00029 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 211569 $")
00030
00031 #include "asterisk/module.h"
00032 #include "asterisk/channel.h"
00033 #include "asterisk/pbx.h"
00034 #include "asterisk/app.h"
00035
00036 static int isexten_function_read(struct ast_channel *chan, const char *cmd, char *data,
00037 char *buf, size_t len)
00038 {
00039 char *parse;
00040 AST_DECLARE_APP_ARGS(args,
00041 AST_APP_ARG(context);
00042 AST_APP_ARG(exten);
00043 AST_APP_ARG(priority);
00044 );
00045
00046 strcpy(buf, "0");
00047
00048 if (ast_strlen_zero(data)) {
00049 ast_log(LOG_ERROR, "DIALPLAN_EXISTS() requires an argument\n");
00050 return -1;
00051 }
00052
00053 parse = ast_strdupa(data);
00054 AST_STANDARD_APP_ARGS(args, parse);
00055
00056 if (!ast_strlen_zero(args.priority)) {
00057 int priority_num;
00058 if (sscanf(args.priority, "%30d", &priority_num) == 1 && priority_num > 0) {
00059 int res;
00060 res = ast_exists_extension(chan, args.context, args.exten, priority_num,
00061 chan->cid.cid_num);
00062 if (res)
00063 strcpy(buf, "1");
00064 } else {
00065 int res;
00066 res = ast_findlabel_extension(chan, args.context, args.exten,
00067 args.priority, chan->cid.cid_num);
00068 if (res > 0)
00069 strcpy(buf, "1");
00070 }
00071 } else if (!ast_strlen_zero(args.exten)) {
00072 int res;
00073 res = ast_exists_extension(chan, args.context, args.exten, 1,
00074 chan->cid.cid_num);
00075 if (res)
00076 strcpy(buf, "1");
00077 } else if (!ast_strlen_zero(args.context)) {
00078 if (ast_context_find(args.context))
00079 strcpy(buf, "1");
00080 } else {
00081 ast_log(LOG_ERROR, "Invalid arguments provided to DIALPLAN_EXISTS\n");
00082 return -1;
00083 }
00084
00085 return 0;
00086 }
00087
00088 static struct ast_custom_function isexten_function = {
00089 .name = "DIALPLAN_EXISTS",
00090 .syntax = "DIALPLAN_EXISTS(context[,extension[,priority]])",
00091 .synopsis = "Checks the existence of a dialplan target.",
00092 .desc = "This function returns 1 if the target exits. Otherwise, it returns 0.\n",
00093 .read = isexten_function_read,
00094 };
00095
00096 static int unload_module(void)
00097 {
00098 return ast_custom_function_unregister(&isexten_function);
00099 }
00100
00101 static int load_module(void)
00102 {
00103 return ast_custom_function_register(&isexten_function);
00104 }
00105
00106 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Dialplan Context/Extension/Priority Checking Functions");