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: 358810 $")
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 static int isexten_function_read(struct ast_channel *chan, const char *cmd, char *data,
00058 char *buf, size_t len)
00059 {
00060 char *parse;
00061 AST_DECLARE_APP_ARGS(args,
00062 AST_APP_ARG(context);
00063 AST_APP_ARG(exten);
00064 AST_APP_ARG(priority);
00065 );
00066
00067 strcpy(buf, "0");
00068
00069 if (ast_strlen_zero(data)) {
00070 ast_log(LOG_ERROR, "DIALPLAN_EXISTS() requires an argument\n");
00071 return -1;
00072 }
00073
00074 parse = ast_strdupa(data);
00075 AST_STANDARD_APP_ARGS(args, parse);
00076
00077 if (!ast_strlen_zero(args.priority)) {
00078 int priority_num;
00079 if (sscanf(args.priority, "%30d", &priority_num) == 1 && priority_num > 0) {
00080 int res;
00081 res = ast_exists_extension(chan, args.context, args.exten, priority_num,
00082 S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, NULL));
00083 if (res)
00084 strcpy(buf, "1");
00085 } else {
00086 int res;
00087 res = ast_findlabel_extension(chan, args.context, args.exten, args.priority,
00088 S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, NULL));
00089 if (res > 0)
00090 strcpy(buf, "1");
00091 }
00092 } else if (!ast_strlen_zero(args.exten)) {
00093 int res;
00094 res = ast_exists_extension(chan, args.context, args.exten, 1,
00095 S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, NULL));
00096 if (res)
00097 strcpy(buf, "1");
00098 } else if (!ast_strlen_zero(args.context)) {
00099 if (ast_context_find(args.context))
00100 strcpy(buf, "1");
00101 } else {
00102 ast_log(LOG_ERROR, "Invalid arguments provided to DIALPLAN_EXISTS\n");
00103 return -1;
00104 }
00105
00106 return 0;
00107 }
00108
00109 static struct ast_custom_function isexten_function = {
00110 .name = "DIALPLAN_EXISTS",
00111 .read = isexten_function_read,
00112 .read_max = 2,
00113 };
00114
00115 static int unload_module(void)
00116 {
00117 return ast_custom_function_unregister(&isexten_function);
00118 }
00119
00120 static int load_module(void)
00121 {
00122 return ast_custom_function_register(&isexten_function);
00123 }
00124
00125 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Dialplan Context/Extension/Priority Checking Functions",
00126 .load = load_module,
00127 .unload = unload_module,
00128 .load_pri = AST_MODPRI_APP_DEPEND,
00129 );