| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#include "asterisk.h" |
| 32 |
|
| 33 |
#include "asterisk/module.h" |
| 34 |
#include "asterisk/channel.h" |
| 35 |
#include "asterisk/pbx.h" |
| 36 |
#include "asterisk/app.h" |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
static int isexten_function_read(struct ast_channel *chan, const char *cmd, char *data, |
| 80 |
char *buf, size_t len) |
| 81 |
{ |
| 82 |
char *parse; |
| 83 |
AST_DECLARE_APP_ARGS(args, |
| 84 |
AST_APP_ARG(context); |
| 85 |
AST_APP_ARG(exten); |
| 86 |
AST_APP_ARG(priority); |
| 87 |
); |
| 88 |
|
| 89 |
strcpy(buf, "0"); |
| 90 |
|
| 91 |
if (ast_strlen_zero(data)) { |
| 92 |
ast_log(LOG_ERROR, "DIALPLAN_EXISTS() requires an argument\n"); |
| 93 |
return -1; |
| 94 |
} |
| 95 |
|
| 96 |
parse = ast_strdupa(data); |
| 97 |
AST_STANDARD_APP_ARGS(args, parse); |
| 98 |
|
| 99 |
if (!ast_strlen_zero(args.priority)) { |
| 100 |
int priority_num; |
| 101 |
if (sscanf(args.priority, "%30d", &priority_num) == 1 && priority_num > 0) { |
| 102 |
int res; |
| 103 |
res = ast_exists_extension(chan, args.context, args.exten, priority_num, |
| 104 |
!chan ? NULL : |
| 105 |
S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL)); |
| 106 |
if (res) |
| 107 |
strcpy(buf, "1"); |
| 108 |
} else { |
| 109 |
int res; |
| 110 |
res = ast_findlabel_extension(chan, args.context, args.exten, args.priority, |
| 111 |
!chan ? NULL : |
| 112 |
S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL)); |
| 113 |
if (res > 0) |
| 114 |
strcpy(buf, "1"); |
| 115 |
} |
| 116 |
} else if (!ast_strlen_zero(args.exten)) { |
| 117 |
int res; |
| 118 |
res = ast_exists_extension(chan, args.context, args.exten, 1, |
| 119 |
!chan ? NULL : |
| 120 |
S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL)); |
| 121 |
if (res) |
| 122 |
strcpy(buf, "1"); |
| 123 |
} else if (!ast_strlen_zero(args.context)) { |
| 124 |
if (ast_context_find(args.context)) |
| 125 |
strcpy(buf, "1"); |
| 126 |
} else { |
| 127 |
ast_log(LOG_ERROR, "Invalid arguments provided to DIALPLAN_EXISTS\n"); |
| 128 |
return -1; |
| 129 |
} |
| 130 |
|
| 131 |
return 0; |
| 132 |
} |
| 133 |
|
| 134 |
static int acf_isexten_exec(struct ast_channel *chan, const char *cmd, char *parse, char *buffer, size_t buflen) |
| 135 |
{ |
| 136 |
int priority_int; |
| 137 |
AST_DECLARE_APP_ARGS(args, |
| 138 |
AST_APP_ARG(context); |
| 139 |
AST_APP_ARG(extension); |
| 140 |
AST_APP_ARG(priority); |
| 141 |
); |
| 142 |
|
| 143 |
if (!chan) { |
| 144 |
ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd); |
| 145 |
return -1; |
| 146 |
} |
| 147 |
|
| 148 |
AST_STANDARD_APP_ARGS(args, parse); |
| 149 |
|
| 150 |
if (ast_strlen_zero(args.context)) { |
| 151 |
args.context = ast_strdupa(ast_channel_context(chan)); |
| 152 |
} |
| 153 |
|
| 154 |
if (ast_strlen_zero(args.extension)) { |
| 155 |
ast_log(LOG_WARNING, "Syntax: VALID_EXTEN([<context>],<extension>[,<priority>]) - missing argument <extension>!\n"); |
| 156 |
return -1; |
| 157 |
} |
| 158 |
|
| 159 |
if (ast_strlen_zero(args.priority)) { |
| 160 |
priority_int = 1; |
| 161 |
} else { |
| 162 |
priority_int = atoi(args.priority); |
| 163 |
} |
| 164 |
|
| 165 |
if (ast_exists_extension(chan, args.context, args.extension, priority_int, |
| 166 |
S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL))) { |
| 167 |
ast_copy_string(buffer, "1", buflen); |
| 168 |
} else { |
| 169 |
ast_copy_string(buffer, "0", buflen); |
| 170 |
} |
| 171 |
|
| 172 |
return 0; |
| 173 |
} |
| 174 |
|
| 175 |
static struct ast_custom_function isexten_function = { |
| 176 |
.name = "DIALPLAN_EXISTS", |
| 177 |
.read = isexten_function_read, |
| 178 |
.read_max = 2, |
| 179 |
}; |
| 180 |
|
| 181 |
static struct ast_custom_function acf_isexten = { |
| 182 |
.name = "VALID_EXTEN", |
| 183 |
.read = acf_isexten_exec, |
| 184 |
}; |
| 185 |
|
| 186 |
static int unload_module(void) |
| 187 |
{ |
| 188 |
int res = ast_custom_function_unregister(&isexten_function); |
| 189 |
res |= ast_custom_function_unregister(&acf_isexten); |
| 190 |
return res; |
| 191 |
} |
| 192 |
|
| 193 |
static int load_module(void) |
| 194 |
{ |
| 195 |
int res = ast_custom_function_register(&isexten_function); |
| 196 |
res |= ast_custom_function_register(&acf_isexten); |
| 197 |
return res; |
| 198 |
} |
| 199 |
|
| 200 |
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Dialplan Context/Extension/Priority Checking Functions", |
| 201 |
.support_level = AST_MODULE_SUPPORT_CORE, |
| 202 |
.load = load_module, |
| 203 |
.unload = unload_module, |
| 204 |
.load_pri = AST_MODPRI_APP_DEPEND, |
| 205 |
); |