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: 411314 $")
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 !chan ? NULL :
00101 S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL));
00102 if (res)
00103 strcpy(buf, "1");
00104 } else {
00105 int res;
00106 res = ast_findlabel_extension(chan, args.context, args.exten, args.priority,
00107 !chan ? NULL :
00108 S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL));
00109 if (res > 0)
00110 strcpy(buf, "1");
00111 }
00112 } else if (!ast_strlen_zero(args.exten)) {
00113 int res;
00114 res = ast_exists_extension(chan, args.context, args.exten, 1,
00115 !chan ? NULL :
00116 S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL));
00117 if (res)
00118 strcpy(buf, "1");
00119 } else if (!ast_strlen_zero(args.context)) {
00120 if (ast_context_find(args.context))
00121 strcpy(buf, "1");
00122 } else {
00123 ast_log(LOG_ERROR, "Invalid arguments provided to DIALPLAN_EXISTS\n");
00124 return -1;
00125 }
00126
00127 return 0;
00128 }
00129
00130 static int acf_isexten_exec(struct ast_channel *chan, const char *cmd, char *parse, char *buffer, size_t buflen)
00131 {
00132 int priority_int;
00133 AST_DECLARE_APP_ARGS(args,
00134 AST_APP_ARG(context);
00135 AST_APP_ARG(extension);
00136 AST_APP_ARG(priority);
00137 );
00138
00139 if (!chan) {
00140 ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
00141 return -1;
00142 }
00143
00144 AST_STANDARD_APP_ARGS(args, parse);
00145
00146 if (ast_strlen_zero(args.context)) {
00147 args.context = ast_strdupa(ast_channel_context(chan));
00148 }
00149
00150 if (ast_strlen_zero(args.extension)) {
00151 ast_log(LOG_WARNING, "Syntax: VALID_EXTEN([<context>],<extension>[,<priority>]) - missing argument <extension>!\n");
00152 return -1;
00153 }
00154
00155 if (ast_strlen_zero(args.priority)) {
00156 priority_int = 1;
00157 } else {
00158 priority_int = atoi(args.priority);
00159 }
00160
00161 if (ast_exists_extension(chan, args.context, args.extension, priority_int,
00162 S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL))) {
00163 ast_copy_string(buffer, "1", buflen);
00164 } else {
00165 ast_copy_string(buffer, "0", buflen);
00166 }
00167
00168 return 0;
00169 }
00170
00171 static struct ast_custom_function isexten_function = {
00172 .name = "DIALPLAN_EXISTS",
00173 .read = isexten_function_read,
00174 .read_max = 2,
00175 };
00176
00177 static struct ast_custom_function acf_isexten = {
00178 .name = "VALID_EXTEN",
00179 .read = acf_isexten_exec,
00180 };
00181
00182 static int unload_module(void)
00183 {
00184 int res = ast_custom_function_unregister(&isexten_function);
00185 res |= ast_custom_function_unregister(&acf_isexten);
00186 return res;
00187 }
00188
00189 static int load_module(void)
00190 {
00191 int res = ast_custom_function_register(&isexten_function);
00192 res |= ast_custom_function_register(&acf_isexten);
00193 return res;
00194 }
00195
00196 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Dialplan Context/Extension/Priority Checking Functions",
00197 .load = load_module,
00198 .unload = unload_module,
00199 .load_pri = AST_MODPRI_APP_DEPEND,
00200 );