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
00028
00029
00030
00031 #include "asterisk.h"
00032
00033 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 358812 $")
00034
00035 #include "asterisk/module.h"
00036 #include "asterisk/channel.h"
00037 #include "asterisk/pbx.h"
00038 #include "asterisk/app.h"
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 static int isexten_function_read(struct ast_channel *chan, const char *cmd, char *data,
00076 char *buf, size_t len)
00077 {
00078 char *parse;
00079 AST_DECLARE_APP_ARGS(args,
00080 AST_APP_ARG(context);
00081 AST_APP_ARG(exten);
00082 AST_APP_ARG(priority);
00083 );
00084
00085 strcpy(buf, "0");
00086
00087 if (ast_strlen_zero(data)) {
00088 ast_log(LOG_ERROR, "DIALPLAN_EXISTS() requires an argument\n");
00089 return -1;
00090 }
00091
00092 parse = ast_strdupa(data);
00093 AST_STANDARD_APP_ARGS(args, parse);
00094
00095 if (!ast_strlen_zero(args.priority)) {
00096 int priority_num;
00097 if (sscanf(args.priority, "%30d", &priority_num) == 1 && priority_num > 0) {
00098 int res;
00099 res = ast_exists_extension(chan, args.context, args.exten, priority_num,
00100 S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL));
00101 if (res)
00102 strcpy(buf, "1");
00103 } else {
00104 int res;
00105 res = ast_findlabel_extension(chan, args.context, args.exten, args.priority,
00106 S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL));
00107 if (res > 0)
00108 strcpy(buf, "1");
00109 }
00110 } else if (!ast_strlen_zero(args.exten)) {
00111 int res;
00112 res = ast_exists_extension(chan, args.context, args.exten, 1,
00113 S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL));
00114 if (res)
00115 strcpy(buf, "1");
00116 } else if (!ast_strlen_zero(args.context)) {
00117 if (ast_context_find(args.context))
00118 strcpy(buf, "1");
00119 } else {
00120 ast_log(LOG_ERROR, "Invalid arguments provided to DIALPLAN_EXISTS\n");
00121 return -1;
00122 }
00123
00124 return 0;
00125 }
00126
00127 static int acf_isexten_exec(struct ast_channel *chan, const char *cmd, char *parse, char *buffer, size_t buflen)
00128 {
00129 int priority_int;
00130 AST_DECLARE_APP_ARGS(args,
00131 AST_APP_ARG(context);
00132 AST_APP_ARG(extension);
00133 AST_APP_ARG(priority);
00134 );
00135
00136 AST_STANDARD_APP_ARGS(args, parse);
00137
00138 if (ast_strlen_zero(args.context)) {
00139 args.context = ast_strdupa(ast_channel_context(chan));
00140 }
00141
00142 if (ast_strlen_zero(args.extension)) {
00143 ast_log(LOG_WARNING, "Syntax: VALID_EXTEN([<context>],<extension>[,<priority>]) - missing argument <extension>!\n");
00144 return -1;
00145 }
00146
00147 if (ast_strlen_zero(args.priority)) {
00148 priority_int = 1;
00149 } else {
00150 priority_int = atoi(args.priority);
00151 }
00152
00153 if (ast_exists_extension(chan, args.context, args.extension, priority_int,
00154 S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL))) {
00155 ast_copy_string(buffer, "1", buflen);
00156 } else {
00157 ast_copy_string(buffer, "0", buflen);
00158 }
00159
00160 return 0;
00161 }
00162
00163 static struct ast_custom_function isexten_function = {
00164 .name = "DIALPLAN_EXISTS",
00165 .read = isexten_function_read,
00166 .read_max = 2,
00167 };
00168
00169 static struct ast_custom_function acf_isexten = {
00170 .name = "VALID_EXTEN",
00171 .read = acf_isexten_exec,
00172 };
00173
00174 static int unload_module(void)
00175 {
00176 int res = ast_custom_function_unregister(&isexten_function);
00177 res |= ast_custom_function_unregister(&acf_isexten);
00178 return res;
00179 }
00180
00181 static int load_module(void)
00182 {
00183 int res = ast_custom_function_register(&isexten_function);
00184 res |= ast_custom_function_register(&acf_isexten);
00185 return res;
00186 }
00187
00188 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Dialplan Context/Extension/Priority Checking Functions",
00189 .load = load_module,
00190 .unload = unload_module,
00191 .load_pri = AST_MODPRI_APP_DEPEND,
00192 );