File: | src/mod/applications/mod_commands/mod_commands.c |
Location: | line 5098, column 21 |
Description: | Null pointer passed as an argument to a 'nonnull' parameter |
1 | /* | |||
2 | * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application | |||
3 | * Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org> | |||
4 | * | |||
5 | * Version: MPL 1.1 | |||
6 | * | |||
7 | * The contents of this file are subject to the Mozilla Public License Version | |||
8 | * 1.1 (the "License"); you may not use this file except in compliance with | |||
9 | * the License. You may obtain a copy of the License at | |||
10 | * http://www.mozilla.org/MPL/ | |||
11 | * | |||
12 | * Software distributed under the License is distributed on an "AS IS" basis, | |||
13 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | |||
14 | * for the specific language governing rights and limitations under the | |||
15 | * License. | |||
16 | * | |||
17 | * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application | |||
18 | * | |||
19 | * The Initial Developer of the Original Code is | |||
20 | * Anthony Minessale II <anthm@freeswitch.org> | |||
21 | * Portions created by the Initial Developer are Copyright (C) | |||
22 | * the Initial Developer. All Rights Reserved. | |||
23 | * | |||
24 | * Contributor(s): | |||
25 | * | |||
26 | * Anthony Minessale II <anthm@freeswitch.org> | |||
27 | * Michael Jerris <mike@jerris.com> | |||
28 | * Johny Kadarisman <jkr888@gmail.com> | |||
29 | * Paul Tinsley <jackhammer@gmail.com> | |||
30 | * Marcel Barbulescu <marcelbarbulescu@gmail.com> | |||
31 | * Bret McDanel <trixter AT 0xdecafbad.com> | |||
32 | * Cesar Cepeda <cesar@auronix.com> | |||
33 | * Massimo Cetra <devel@navynet.it> | |||
34 | * Rupa Schomaker <rupa@rupa.com> | |||
35 | * Joseph Sullivan <jossulli@amazon.com> | |||
36 | * Raymond Chandler <intralanman@freeswitch.org> | |||
37 | * Seven Du <dujinfang@gmail.com> | |||
38 | * Garmt Boekholt <garmt@cimico.com> | |||
39 | * | |||
40 | * mod_commands.c -- Misc. Command Module | |||
41 | * | |||
42 | */ | |||
43 | #include <switch.h> | |||
44 | #include <switch_stun.h> | |||
45 | ||||
46 | SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)switch_status_t mod_commands_load (switch_loadable_module_interface_t **module_interface, switch_memory_pool_t *pool); | |||
47 | SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_commands_shutdown)switch_status_t mod_commands_shutdown (void); | |||
48 | SWITCH_MODULE_DEFINITION(mod_commands, mod_commands_load, mod_commands_shutdown, NULL)static const char modname[] = "mod_commands" ; __attribute__( (visibility("default"))) switch_loadable_module_function_table_t mod_commands_module_interface = { 5, mod_commands_load, mod_commands_shutdown , ((void*)0), SMODF_NONE }; | |||
49 | ||||
50 | static switch_mutex_t *reload_mutex = NULL((void*)0); | |||
51 | ||||
52 | struct cb_helper { | |||
53 | uint32_t row_process; | |||
54 | switch_stream_handle_t *stream; | |||
55 | }; | |||
56 | ||||
57 | struct stream_format { | |||
58 | char *http; /* http cmd (from xmlrpc) */ | |||
59 | char *query; /* http query (cmd args) */ | |||
60 | switch_bool_t api; /* flag: define content type for http reply e.g. text/html or text/xml */ | |||
61 | switch_bool_t html; /* flag: format as html */ | |||
62 | char *nl; /* newline to use: html "<br>\n" or just "\n" */ | |||
63 | }; | |||
64 | typedef struct stream_format stream_format; | |||
65 | ||||
66 | static int url_callback(void *pArg, int argc, char **argv, char **columnNames) | |||
67 | { | |||
68 | struct cb_helper *cb = (struct cb_helper *) pArg; | |||
69 | ||||
70 | cb->row_process++; | |||
71 | ||||
72 | if (!zstr(argv[0])_zstr(argv[0])) { | |||
73 | cb->stream->write_function(cb->stream, "%s,", argv[0]); | |||
74 | } | |||
75 | ||||
76 | return 0; | |||
77 | } | |||
78 | ||||
79 | static switch_status_t select_url(const char *user, | |||
80 | const char *domain, | |||
81 | const char *concat, | |||
82 | const char *exclude_contact, | |||
83 | switch_stream_handle_t *stream) | |||
84 | { | |||
85 | struct cb_helper cb; | |||
86 | char *sql, *errmsg = NULL((void*)0); | |||
87 | switch_core_flag_t cflags = switch_core_flags(); | |||
88 | switch_cache_db_handle_t *db = NULL((void*)0); | |||
89 | ||||
90 | if (!(cflags & SCF_USE_SQL)) { | |||
91 | stream->write_function(stream, "-ERR SQL disabled, no data available!\n"); | |||
92 | return SWITCH_STATUS_SUCCESS; | |||
93 | } | |||
94 | ||||
95 | if (switch_core_db_handle(&db)_switch_core_db_handle(&db, "mod_commands.c", (const char *)__func__, 95) != SWITCH_STATUS_SUCCESS) { | |||
96 | stream->write_function(stream, "%s", "-ERR Database error!\n"); | |||
97 | return SWITCH_STATUS_SUCCESS; | |||
98 | } | |||
99 | ||||
100 | cb.row_process = 0; | |||
101 | cb.stream = stream; | |||
102 | ||||
103 | if (exclude_contact) { | |||
104 | sql = switch_mprintf("select url, '%q' " | |||
105 | "from registrations where reg_user='%q' and realm='%q' " | |||
106 | "and url not like '%%%s%%'", (concat != NULL((void*)0)) ? concat : "", user, domain, exclude_contact); | |||
107 | } else { | |||
108 | sql = switch_mprintf("select url, '%q' " | |||
109 | "from registrations where reg_user='%q' and realm='%q'", | |||
110 | (concat != NULL((void*)0)) ? concat : "", user, domain); | |||
111 | } | |||
112 | ||||
113 | switch_assert(sql)((sql) ? (void) (0) : __assert_fail ("sql", "mod_commands.c", 113, __PRETTY_FUNCTION__)); | |||
114 | switch_cache_db_execute_sql_callback(db, sql, url_callback, &cb, &errmsg); | |||
115 | ||||
116 | if (errmsg) { | |||
117 | stream->write_function(stream, "-ERR SQL error [%s]\n", errmsg); | |||
118 | free(errmsg); | |||
119 | errmsg = NULL((void*)0); | |||
120 | } | |||
121 | ||||
122 | switch_safe_free(sql)if (sql) {free(sql);sql=((void*)0);}; | |||
123 | switch_cache_db_release_db_handle(&db); | |||
124 | ||||
125 | return SWITCH_STATUS_SUCCESS; | |||
126 | } | |||
127 | ||||
128 | static stream_format set_format(stream_format *format, switch_stream_handle_t *stream) | |||
129 | { | |||
130 | format->nl = "\n"; | |||
131 | if (stream->param_event && (format->http = switch_event_get_header(stream->param_event, "HTTP-URI")switch_event_get_header_idx(stream->param_event, "HTTP-URI" , -1))) { | |||
132 | format->query = switch_event_get_header(stream->param_event, "HTTP-QUERY")switch_event_get_header_idx(stream->param_event, "HTTP-QUERY" , -1); | |||
133 | if (switch_event_get_header(stream->param_event, "HTTP-API")switch_event_get_header_idx(stream->param_event, "HTTP-API" , -1)) { | |||
134 | format->api = SWITCH_TRUE; | |||
135 | } | |||
136 | if (!strncasecmp(format->http, "/webapi/", 8)) { | |||
137 | format->nl = "<br>\n"; | |||
138 | format->html = SWITCH_TRUE; | |||
139 | } | |||
140 | } | |||
141 | ||||
142 | return *format; | |||
143 | } | |||
144 | ||||
145 | #define SAY_STRING_SYNTAX"<module_name>[.<ext>] <lang>[.<ext>] <say_type> <say_method> [<say_gender>] <text>" "<module_name>[.<ext>] <lang>[.<ext>] <say_type> <say_method> [<say_gender>] <text>" | |||
146 | SWITCH_STANDARD_API(say_string_function)static switch_status_t say_string_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream ) | |||
147 | { | |||
148 | char *argv[6] = { 0 }; | |||
149 | int argc; | |||
150 | char *lbuf = NULL((void*)0), *string = NULL((void*)0); | |||
151 | int err = 1, par = 0; | |||
152 | char *p, *ext = "wav"; | |||
153 | char *tosay = NULL((void*)0); | |||
154 | int strip = 0; | |||
155 | ||||
156 | if (cmd) { | |||
157 | lbuf = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))); | |||
158 | } | |||
159 | ||||
160 | if (lbuf && (argc = switch_separate_string(lbuf, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) && (argc == 5 || argc == 6)) { | |||
161 | ||||
162 | if ((p = strchr(argv[0], '.')(__extension__ (__builtin_constant_p ('.') && !__builtin_constant_p (argv[0]) && ('.') == '\0' ? (char *) __rawmemchr (argv [0], '.') : __builtin_strchr (argv[0], '.'))))) { | |||
163 | *p++ = '\0'; | |||
164 | ext = p; | |||
165 | par++; | |||
166 | } | |||
167 | ||||
168 | if (!par && (p = strchr(argv[1], '.')(__extension__ (__builtin_constant_p ('.') && !__builtin_constant_p (argv[1]) && ('.') == '\0' ? (char *) __rawmemchr (argv [1], '.') : __builtin_strchr (argv[1], '.'))))) { | |||
169 | *p++ = '\0'; | |||
170 | ext = p; | |||
171 | } | |||
172 | ||||
173 | tosay = (argc == 5) ? argv[4] : argv[5]; | |||
174 | ||||
175 | if (*tosay == '~') { | |||
176 | tosay++; | |||
177 | strip++; | |||
178 | } | |||
179 | ||||
180 | switch_ivr_say_string(session, | |||
181 | argv[1], | |||
182 | ext, | |||
183 | tosay, | |||
184 | argv[0], | |||
185 | argv[2], | |||
186 | argv[3], | |||
187 | (argc == 6) ? argv[4] : NULL((void*)0) , | |||
188 | &string); | |||
189 | if (string) { | |||
190 | stream->write_function(stream, "%s", strip ? string + 14 : string); | |||
191 | free(string); | |||
192 | err = 0; | |||
193 | } | |||
194 | } | |||
195 | ||||
196 | if (err) { | |||
197 | stream->write_function(stream, "-ERR Usage: %s\n", SAY_STRING_SYNTAX"<module_name>[.<ext>] <lang>[.<ext>] <say_type> <say_method> [<say_gender>] <text>"); | |||
198 | } | |||
199 | ||||
200 | free(lbuf); | |||
201 | ||||
202 | return SWITCH_STATUS_SUCCESS; | |||
203 | ||||
204 | } | |||
205 | ||||
206 | struct user_struct { | |||
207 | char *dname; | |||
208 | char *gname; | |||
209 | char *effective_caller_id_name; | |||
210 | char *effective_caller_id_number; | |||
211 | char *callgroup; | |||
212 | switch_xml_t x_user_tag; | |||
213 | switch_stream_handle_t *stream; | |||
214 | char *search_context; | |||
215 | char *context; | |||
216 | switch_xml_t x_domain_tag; | |||
217 | }; | |||
218 | ||||
219 | static void dump_user(struct user_struct *us) | |||
220 | { | |||
221 | switch_xml_t x_vars, x_var, ux, x_user_tag, x_domain_tag; | |||
222 | switch_status_t status; | |||
223 | switch_stream_handle_t apistream = { 0 }, *stream; | |||
224 | char *user_context = NULL((void*)0), *search_context = NULL((void*)0), *context = NULL((void*)0); | |||
225 | char *effective_caller_id_name = NULL((void*)0); | |||
226 | char *effective_caller_id_number = NULL((void*)0); | |||
227 | char *dname = NULL((void*)0), *gname = NULL((void*)0), *callgroup = NULL((void*)0); | |||
228 | char *utype = NULL((void*)0), *uname = NULL((void*)0); | |||
229 | char *apip = NULL((void*)0); | |||
230 | ||||
231 | x_user_tag = us->x_user_tag; | |||
232 | x_domain_tag = us->x_domain_tag; | |||
233 | effective_caller_id_name = us->effective_caller_id_name; | |||
234 | effective_caller_id_number = us->effective_caller_id_number; | |||
235 | callgroup = us->callgroup; | |||
236 | dname = us->dname; | |||
237 | gname = us->gname; | |||
238 | stream = us->stream; | |||
239 | context = us->context; | |||
240 | search_context = us->search_context; | |||
241 | ||||
242 | if (!x_user_tag) { | |||
243 | return; | |||
244 | } | |||
245 | ||||
246 | utype = (char *)switch_xml_attr_soft(us->x_user_tag, "type"); | |||
247 | uname = (char *)switch_xml_attr_soft(us->x_user_tag, "id"); | |||
248 | ||||
249 | if (!strcasecmp(utype, "pointer")) { | |||
250 | if (switch_xml_locate_user_in_domain(uname, x_domain_tag, &ux, NULL((void*)0)) == SWITCH_STATUS_SUCCESS) { | |||
251 | x_user_tag = ux; | |||
252 | } | |||
253 | } | |||
254 | ||||
255 | user_context = (char *)context; | |||
256 | ||||
257 | if ((x_vars = switch_xml_child(x_user_tag, "variables"))) { | |||
258 | for (x_var = switch_xml_child(x_vars, "variable"); x_var; x_var = x_var->next) { | |||
259 | const char *key = switch_xml_attr_soft(x_var, "name"); | |||
260 | const char *val = switch_xml_attr_soft(x_var, "value"); | |||
261 | ||||
262 | if (!strcasecmp(key, "user_context")) { | |||
263 | user_context = (char*) val; | |||
264 | } else if (!strcasecmp(key, "effective_caller_id_name")) { | |||
265 | effective_caller_id_name = (char*) val; | |||
266 | } else if (!strcasecmp(key, "effective_caller_id_number")) { | |||
267 | effective_caller_id_number = (char*) val; | |||
268 | } else if (!strcasecmp(key, "callgroup")) { | |||
269 | callgroup = (char*) val; | |||
270 | } else { | |||
271 | continue; | |||
272 | } | |||
273 | } | |||
274 | } | |||
275 | ||||
276 | if (search_context) { | |||
277 | if (zstr(user_context)_zstr(user_context) || strcasecmp(search_context, user_context)) { | |||
278 | return; | |||
279 | } | |||
280 | } | |||
281 | ||||
282 | if(zstr(dname)_zstr(dname)) { | |||
283 | apip = switch_mprintf("*/%s",switch_xml_attr_soft(x_user_tag, "id")); | |||
284 | } else { | |||
285 | apip = switch_mprintf("*/%s@%s",switch_xml_attr_soft(x_user_tag, "id"), dname); | |||
286 | } | |||
287 | ||||
288 | SWITCH_STANDARD_STREAM(apistream)memset(&apistream, 0, sizeof(apistream)); apistream.data = malloc(1024); ((apistream.data) ? (void) (0) : __assert_fail ("apistream.data", "mod_commands.c", 288, __PRETTY_FUNCTION__ )); memset(apistream.data, 0, 1024); apistream.end = apistream .data; apistream.data_size = 1024; apistream.write_function = switch_console_stream_write; apistream.raw_write_function = switch_console_stream_raw_write ; apistream.alloc_len = 1024; apistream.alloc_chunk = 1024; | |||
289 | if ((status = switch_api_execute("sofia_contact", apip, NULL((void*)0), &apistream)) != SWITCH_STATUS_SUCCESS) { | |||
290 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_commands.c", (const char *)__func__ , 290, ((void*)0), SWITCH_LOG_DEBUG, "sofia_contact '%s' failed. status: %d \n", apip, status ); | |||
291 | goto end; | |||
292 | } | |||
293 | stream->write_function(stream, "%s|%s|%s|%s|%s|%s|%s|%s\n", switch_xml_attr_soft(x_user_tag, "id"), user_context, dname, gname, apistream.data, callgroup, effective_caller_id_name, effective_caller_id_number); | |||
294 | ||||
295 | end: | |||
296 | switch_safe_free(apistream.data)if (apistream.data) {free(apistream.data);apistream.data=((void *)0);}; | |||
297 | switch_safe_free(apip)if (apip) {free(apip);apip=((void*)0);}; | |||
298 | ||||
299 | return; | |||
300 | } | |||
301 | ||||
302 | #define LIST_USERS_SYNTAX"[group <group>] [domain <domain>] [user <user>] [context <context>]" "[group <group>] [domain <domain>] [user <user>] [context <context>]" | |||
303 | SWITCH_STANDARD_API(list_users_function)static switch_status_t list_users_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream ) | |||
304 | { | |||
305 | int argc; | |||
306 | char *pdata, *argv[9]; | |||
307 | int32_t arg = 0; | |||
308 | switch_xml_t xml_root, x_domains, x_domain_tag; | |||
309 | switch_xml_t gts, gt, uts, ut; | |||
310 | char *_user = NULL((void*)0), *_domain = NULL((void*)0), *_search_context = NULL((void*)0), *_group = NULL((void*)0); | |||
311 | ||||
312 | ||||
313 | if ((pdata = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))))) { | |||
314 | argc = switch_separate_string(pdata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | |||
315 | ||||
316 | if (argc >= 9) { | |||
317 | stream->write_function(stream, "-USAGE: %s\n", LIST_USERS_SYNTAX"[group <group>] [domain <domain>] [user <user>] [context <context>]"); | |||
318 | goto done; | |||
319 | } | |||
320 | ||||
321 | for (arg = 0; arg < argc; arg++) { | |||
322 | if (!strcasecmp(argv[arg], "user")) { | |||
323 | _user = argv[arg + 1]; | |||
324 | } | |||
325 | if (!strcasecmp(argv[arg], "context")) { | |||
326 | _search_context = argv[arg + 1]; | |||
327 | } | |||
328 | if (!strcasecmp(argv[arg], "domain")) { | |||
329 | _domain = argv[arg + 1]; | |||
330 | } | |||
331 | if (!strcasecmp(argv[arg], "group")) { | |||
332 | _group = argv[arg + 1]; | |||
333 | } | |||
334 | } | |||
335 | } | |||
336 | ||||
337 | stream->write_function(stream, "userid|context|domain|group|contact|callgroup|effective_caller_id_name|effective_caller_id_number\n"); | |||
338 | ||||
339 | if (switch_xml_locate("directory", NULL((void*)0), NULL((void*)0), NULL((void*)0), &xml_root, &x_domains, NULL((void*)0), SWITCH_FALSE) == SWITCH_STATUS_SUCCESS) { | |||
340 | struct user_struct us = { 0 }; | |||
341 | ||||
342 | for (x_domain_tag = switch_xml_child(x_domains, "domain"); x_domain_tag; x_domain_tag = x_domain_tag->next) { | |||
343 | switch_xml_t x_vars, x_var; | |||
344 | ||||
345 | us.dname = (char*)switch_xml_attr_soft(x_domain_tag, "name"); | |||
346 | ||||
347 | if (_domain && strcasecmp(_domain, us.dname)) { | |||
348 | continue; | |||
349 | } | |||
350 | ||||
351 | if ((x_vars = switch_xml_child(x_domain_tag, "variables"))) { | |||
352 | if ((x_var = switch_xml_find_child_multi(x_vars, "variable", "name", "user_context", NULL((void*)0)))) { | |||
353 | us.context = (char*)switch_xml_attr_soft(x_var, "value"); | |||
354 | } | |||
355 | if ((x_var = switch_xml_find_child_multi(x_vars, "variable", "name", "callgroup", NULL((void*)0)))) { | |||
356 | us.callgroup = (char*)switch_xml_attr_soft(x_var, "value"); | |||
357 | } | |||
358 | if ((x_var = switch_xml_find_child_multi(x_vars, "variable", "name", "effective_caller_id_name", NULL((void*)0)))) { | |||
359 | us.effective_caller_id_name = (char*)switch_xml_attr_soft(x_var, "value"); | |||
360 | } | |||
361 | if ((x_var = switch_xml_find_child_multi(x_vars, "variable", "name", "effective_caller_id_number", NULL((void*)0)))) { | |||
362 | us.effective_caller_id_number = (char*)switch_xml_attr_soft(x_var, "value"); | |||
363 | } | |||
364 | } | |||
365 | ||||
366 | if ((gts = switch_xml_child(x_domain_tag, "groups"))) { | |||
367 | for (gt = switch_xml_child(gts, "group"); gt; gt = gt->next) { | |||
368 | us.gname = (char*)switch_xml_attr_soft(gt, "name"); | |||
369 | ||||
370 | if (_group && strcasecmp(_group, us.gname)) { | |||
371 | continue; | |||
372 | } | |||
373 | ||||
374 | if ((x_vars = switch_xml_child(gt, "variables"))) { | |||
375 | if ((x_var = switch_xml_find_child_multi(x_vars, "variable", "name", "user_context", NULL((void*)0)))) { | |||
376 | us.context = (char*)switch_xml_attr_soft(x_var, "value"); | |||
377 | } | |||
378 | if ((x_var = switch_xml_find_child_multi(x_vars, "variable", "name", "callgroup", NULL((void*)0)))) { | |||
379 | us.callgroup = (char*)switch_xml_attr_soft(x_var, "value"); | |||
380 | } | |||
381 | if ((x_var = switch_xml_find_child_multi(x_vars, "variable", "name", "effective_caller_id_name", NULL((void*)0)))) { | |||
382 | us.effective_caller_id_name = (char*)switch_xml_attr_soft(x_var, "value"); | |||
383 | } | |||
384 | if ((x_var = switch_xml_find_child_multi(x_vars, "variable", "name", "effective_caller_id_number", NULL((void*)0)))) { | |||
385 | us.effective_caller_id_number = (char*)switch_xml_attr_soft(x_var, "value"); | |||
386 | } | |||
387 | } | |||
388 | ||||
389 | for (uts = switch_xml_child(gt, "users"); uts; uts = uts->next) { | |||
390 | for (ut = switch_xml_child(uts, "user"); ut; ut = ut->next) { | |||
391 | if (_user && strcasecmp(_user, switch_xml_attr_soft(ut, "id"))) { | |||
392 | continue; | |||
393 | } | |||
394 | us.x_user_tag = ut; | |||
395 | us.x_domain_tag = x_domain_tag; | |||
396 | us.stream = stream; | |||
397 | us.search_context = _search_context; | |||
398 | dump_user(&us); | |||
399 | } | |||
400 | } | |||
401 | } | |||
402 | } else { | |||
403 | for (uts = switch_xml_child(x_domain_tag, "users"); uts; uts = uts->next) { | |||
404 | for (ut = switch_xml_child(uts, "user"); ut; ut = ut->next) { | |||
405 | if (_user && strcasecmp(_user, switch_xml_attr_soft(ut, "id"))) { | |||
406 | continue; | |||
407 | } | |||
408 | us.x_user_tag = ut; | |||
409 | us.x_domain_tag = x_domain_tag; | |||
410 | us.stream = stream; | |||
411 | us.search_context = _search_context; | |||
412 | dump_user(&us); | |||
413 | } | |||
414 | } | |||
415 | } | |||
416 | } | |||
417 | switch_xml_free(xml_root); | |||
418 | } | |||
419 | ||||
420 | stream->write_function(stream, "\n+OK\n"); | |||
421 | ||||
422 | done: | |||
423 | switch_safe_free(pdata)if (pdata) {free(pdata);pdata=((void*)0);}; | |||
424 | return SWITCH_STATUS_SUCCESS; | |||
425 | } | |||
426 | ||||
427 | SWITCH_STANDARD_API(reg_url_function)static switch_status_t reg_url_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
428 | { | |||
429 | char *data; | |||
430 | char *user = NULL((void*)0); | |||
431 | char *domain = NULL((void*)0), *dup_domain = NULL((void*)0); | |||
432 | char *concat = NULL((void*)0); | |||
433 | const char *exclude_contact = NULL((void*)0); | |||
434 | char *reply = "error/facility_not_subscribed"; | |||
435 | switch_stream_handle_t mystream = { 0 }; | |||
436 | ||||
437 | ||||
438 | if (!cmd) { | |||
439 | stream->write_function(stream, "%s", ""); | |||
440 | return SWITCH_STATUS_SUCCESS; | |||
441 | } | |||
442 | ||||
443 | if (session) { | |||
444 | switch_channel_t *channel = switch_core_session_get_channel(session); | |||
445 | exclude_contact = switch_channel_get_variable(channel, "sip_exclude_contact")switch_channel_get_variable_dup(channel, "sip_exclude_contact" , SWITCH_TRUE, -1); | |||
446 | } | |||
447 | ||||
448 | ||||
449 | data = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))); | |||
450 | switch_assert(data)((data) ? (void) (0) : __assert_fail ("data", "mod_commands.c" , 450, __PRETTY_FUNCTION__)); | |||
451 | ||||
452 | user = data; | |||
453 | ||||
454 | if ((domain = strchr(user, '@')(__extension__ (__builtin_constant_p ('@') && !__builtin_constant_p (user) && ('@') == '\0' ? (char *) __rawmemchr (user , '@') : __builtin_strchr (user, '@'))))) { | |||
455 | *domain++ = '\0'; | |||
456 | if ((concat = strchr(domain, '/')(__extension__ (__builtin_constant_p ('/') && !__builtin_constant_p (domain) && ('/') == '\0' ? (char *) __rawmemchr (domain , '/') : __builtin_strchr (domain, '/'))))) { | |||
457 | *concat++ = '\0'; | |||
458 | } | |||
459 | } else { | |||
460 | if ((concat = strchr(user, '/')(__extension__ (__builtin_constant_p ('/') && !__builtin_constant_p (user) && ('/') == '\0' ? (char *) __rawmemchr (user , '/') : __builtin_strchr (user, '/'))))) { | |||
461 | *concat++ = '\0'; | |||
462 | } | |||
463 | } | |||
464 | ||||
465 | if (zstr(domain)_zstr(domain)) { | |||
466 | dup_domain = switch_core_get_domain(SWITCH_TRUE); | |||
467 | domain = dup_domain; | |||
468 | } | |||
469 | ||||
470 | if (!user) goto end; | |||
471 | ||||
472 | ||||
473 | SWITCH_STANDARD_STREAM(mystream)memset(&mystream, 0, sizeof(mystream)); mystream.data = malloc (1024); ((mystream.data) ? (void) (0) : __assert_fail ("mystream.data" , "mod_commands.c", 473, __PRETTY_FUNCTION__)); memset(mystream .data, 0, 1024); mystream.end = mystream.data; mystream.data_size = 1024; mystream.write_function = switch_console_stream_write ; mystream.raw_write_function = switch_console_stream_raw_write ; mystream.alloc_len = 1024; mystream.alloc_chunk = 1024; | |||
474 | switch_assert(mystream.data)((mystream.data) ? (void) (0) : __assert_fail ("mystream.data" , "mod_commands.c", 474, __PRETTY_FUNCTION__)); | |||
475 | ||||
476 | select_url(user, domain, concat, exclude_contact, &mystream); | |||
477 | reply = mystream.data; | |||
478 | ||||
479 | ||||
480 | end: | |||
481 | ||||
482 | if (zstr(reply)_zstr(reply)) { | |||
483 | reply = "error/user_not_registered"; | |||
484 | } else if (end_of(reply)*(*reply == '\0' ? reply : reply + strlen(reply) - 1) == ',') { | |||
485 | end_of(reply)*(*reply == '\0' ? reply : reply + strlen(reply) - 1) = '\0'; | |||
486 | } | |||
487 | ||||
488 | stream->write_function(stream, "%s", reply); | |||
489 | reply = NULL((void*)0); | |||
490 | ||||
491 | switch_safe_free(mystream.data)if (mystream.data) {free(mystream.data);mystream.data=((void* )0);}; | |||
492 | ||||
493 | switch_safe_free(data)if (data) {free(data);data=((void*)0);}; | |||
494 | switch_safe_free(dup_domain)if (dup_domain) {free(dup_domain);dup_domain=((void*)0);}; | |||
495 | ||||
496 | return SWITCH_STATUS_SUCCESS; | |||
497 | } | |||
498 | ||||
499 | SWITCH_STANDARD_API(banner_function)static switch_status_t banner_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
500 | { | |||
501 | stream->write_function(stream, "%s", switch_core_banner()); | |||
502 | return SWITCH_STATUS_SUCCESS; | |||
503 | } | |||
504 | ||||
505 | SWITCH_STANDARD_API(hostname_api_function)static switch_status_t hostname_api_function ( const char *cmd , switch_core_session_t *session, switch_stream_handle_t *stream ) | |||
506 | { | |||
507 | stream->write_function(stream, "%s", switch_core_get_hostname()); | |||
508 | return SWITCH_STATUS_SUCCESS; | |||
509 | } | |||
510 | ||||
511 | SWITCH_STANDARD_API(switchname_api_function)static switch_status_t switchname_api_function ( const char * cmd, switch_core_session_t *session, switch_stream_handle_t * stream) | |||
512 | { | |||
513 | stream->write_function(stream, "%s", switch_core_get_switchname()); | |||
514 | return SWITCH_STATUS_SUCCESS; | |||
515 | } | |||
516 | ||||
517 | SWITCH_STANDARD_API(gethost_api_function)static switch_status_t gethost_api_function ( const char *cmd , switch_core_session_t *session, switch_stream_handle_t *stream ) | |||
518 | { | |||
519 | struct sockaddr_in sa; | |||
520 | struct hostent *he; | |||
521 | const char *ip; | |||
522 | char buf[50] = ""; | |||
523 | ||||
524 | if (!zstr(cmd)_zstr(cmd)) { | |||
525 | he = gethostbyname(cmd); | |||
526 | ||||
527 | if (he) { | |||
528 | memcpy(&sa.sin_addr, he->h_addrh_addr_list[0], sizeof(struct in_addr)); | |||
529 | ip = switch_inet_ntopinet_ntop(AF_INET2, &sa.sin_addr, buf, sizeof(buf)); | |||
530 | stream->write_function(stream, "%s", ip); | |||
531 | return SWITCH_STATUS_SUCCESS; | |||
532 | } | |||
533 | } | |||
534 | ||||
535 | stream->write_function(stream, "-ERR"); | |||
536 | ||||
537 | return SWITCH_STATUS_SUCCESS; | |||
538 | } | |||
539 | ||||
540 | ||||
541 | SWITCH_STANDARD_API(shutdown_function)static switch_status_t shutdown_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
542 | { | |||
543 | switch_session_ctl_t command = SCSC_SHUTDOWN; | |||
544 | int arg = 0; | |||
545 | ||||
546 | stream->write_function(stream, "+OK\n"); | |||
547 | switch_core_session_ctl(command, &arg); | |||
548 | ||||
549 | return SWITCH_STATUS_SUCCESS; | |||
550 | } | |||
551 | ||||
552 | SWITCH_STANDARD_API(version_function)static switch_status_t version_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
553 | { | |||
554 | int argc; | |||
555 | char *mydata = NULL((void*)0), *argv[2]; | |||
556 | ||||
557 | if (zstr(cmd)_zstr(cmd)) { | |||
558 | stream->write_function(stream, "FreeSWITCH Version %s (%s)\n", switch_version_full(), switch_version_revision_human()); | |||
559 | goto end; | |||
560 | } | |||
561 | ||||
562 | mydata = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))); | |||
563 | switch_assert(mydata)((mydata) ? (void) (0) : __assert_fail ("mydata", "mod_commands.c" , 563, __PRETTY_FUNCTION__)); | |||
564 | ||||
565 | argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | |||
566 | ||||
567 | if (argc > 0 && switch_stristr("short", argv[0])) { | |||
568 | stream->write_function(stream, "%s.%s.%s\n", switch_version_major(),switch_version_minor(),switch_version_micro()); | |||
569 | } else { | |||
570 | stream->write_function(stream, "FreeSWITCH Version %s (%s)\n", switch_version_full(), switch_version_full_human()); | |||
571 | } | |||
572 | ||||
573 | switch_safe_free(mydata)if (mydata) {free(mydata);mydata=((void*)0);}; | |||
574 | ||||
575 | end: | |||
576 | return SWITCH_STATUS_SUCCESS; | |||
577 | } | |||
578 | ||||
579 | SWITCH_STANDARD_API(db_cache_function)static switch_status_t db_cache_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
580 | { | |||
581 | int argc; | |||
582 | char *mydata = NULL((void*)0), *argv[2]; | |||
583 | ||||
584 | if (zstr(cmd)_zstr(cmd)) { | |||
585 | goto error; | |||
586 | } | |||
587 | ||||
588 | mydata = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))); | |||
589 | switch_assert(mydata)((mydata) ? (void) (0) : __assert_fail ("mydata", "mod_commands.c" , 589, __PRETTY_FUNCTION__)); | |||
590 | ||||
591 | argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | |||
592 | ||||
593 | if (argc < 1) { | |||
594 | goto error; | |||
595 | } | |||
596 | if (argv[0] && switch_stristr("status", argv[0])) { | |||
597 | switch_cache_db_status(stream); | |||
598 | goto ok; | |||
599 | } else { | |||
600 | goto error; | |||
601 | } | |||
602 | ||||
603 | error: | |||
604 | stream->write_function(stream, "%s", "parameter missing\n"); | |||
605 | ok: | |||
606 | switch_safe_free(mydata)if (mydata) {free(mydata);mydata=((void*)0);}; | |||
607 | return SWITCH_STATUS_SUCCESS; | |||
608 | } | |||
609 | ||||
610 | SWITCH_STANDARD_API(host_lookup_function)static switch_status_t host_lookup_function ( const char *cmd , switch_core_session_t *session, switch_stream_handle_t *stream ) | |||
611 | { | |||
612 | char host[256] = ""; | |||
613 | ||||
614 | if (zstr(cmd)_zstr(cmd)) { | |||
615 | stream->write_function(stream, "%s", "parameter missing\n"); | |||
616 | } else { | |||
617 | if (switch_resolve_host(cmd, host, sizeof(host)) == SWITCH_STATUS_SUCCESS) { | |||
618 | stream->write_function(stream, "%s", host); | |||
619 | } else { | |||
620 | stream->write_function(stream, "%s", "!err!"); | |||
621 | } | |||
622 | } | |||
623 | ||||
624 | return SWITCH_STATUS_SUCCESS; | |||
625 | } | |||
626 | ||||
627 | SWITCH_STANDARD_API(nat_map_function)static switch_status_t nat_map_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
628 | { | |||
629 | int argc; | |||
630 | char *mydata = NULL((void*)0), *argv[5]; | |||
631 | switch_nat_ip_proto_t proto = SWITCH_NAT_UDP; | |||
632 | switch_port_t external_port = 0; | |||
633 | char *tmp = NULL((void*)0); | |||
634 | switch_bool_t sticky = SWITCH_FALSE; | |||
635 | switch_bool_t mapping = SWITCH_TRUE; | |||
636 | ||||
637 | if (!cmd) { | |||
638 | goto usage; | |||
639 | } | |||
640 | ||||
641 | if (!switch_nat_is_initialized()) { | |||
642 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_commands.c", (const char *)__func__ , 642, ((void*)0), SWITCH_LOG_ERROR, "nat_map API called while NAT not initialized\n"); | |||
643 | goto error; | |||
644 | } | |||
645 | ||||
646 | mydata = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))); | |||
647 | switch_assert(mydata)((mydata) ? (void) (0) : __assert_fail ("mydata", "mod_commands.c" , 647, __PRETTY_FUNCTION__)); | |||
648 | ||||
649 | argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | |||
650 | if (argc < 1) { | |||
651 | goto usage; | |||
652 | } | |||
653 | if (argv[0] && switch_stristr("status", argv[0])) { | |||
654 | tmp = switch_nat_status(); | |||
655 | stream->write_function(stream, tmp); | |||
656 | switch_safe_free(tmp)if (tmp) {free(tmp);tmp=((void*)0);}; | |||
657 | goto ok; | |||
658 | } else if (argv[0] && switch_stristr("republish", argv[0])) { | |||
659 | switch_nat_republish(); | |||
660 | stream->write_function(stream, "true"); | |||
661 | goto ok; | |||
662 | } else if (argv[0] && switch_stristr("reinit", argv[0])) { | |||
663 | switch_nat_reinit(); | |||
664 | tmp = switch_nat_status(); | |||
665 | stream->write_function(stream, tmp); | |||
666 | switch_safe_free(tmp)if (tmp) {free(tmp);tmp=((void*)0);}; | |||
667 | goto ok; | |||
668 | } | |||
669 | ||||
670 | if (argc < 2) { | |||
671 | goto usage; | |||
672 | } | |||
673 | ||||
674 | if (argv[0] && switch_stristr("mapping", argv[0])) { | |||
675 | if (argv[1] && switch_stristr("enable", argv[1])) { | |||
676 | mapping = SWITCH_TRUE; | |||
677 | } else if (argv[1] && switch_stristr("disable", argv[1])) { | |||
678 | mapping = SWITCH_FALSE; | |||
679 | } | |||
680 | ||||
681 | switch_nat_set_mapping(mapping); | |||
682 | tmp = switch_nat_status(); | |||
683 | stream->write_function(stream, tmp); | |||
684 | switch_safe_free(tmp)if (tmp) {free(tmp);tmp=((void*)0);}; | |||
685 | goto ok; | |||
686 | } | |||
687 | ||||
688 | if (argc < 3) { | |||
689 | goto error; | |||
690 | } | |||
691 | ||||
692 | if (argv[2] && switch_stristr("tcp", argv[2])) { | |||
693 | proto = SWITCH_NAT_TCP; | |||
694 | } else if (argv[2] && switch_stristr("udp", argv[2])) { | |||
695 | proto = SWITCH_NAT_UDP; | |||
696 | } | |||
697 | ||||
698 | if (argv[3] && switch_stristr("sticky", argv[3])) { | |||
699 | sticky = SWITCH_TRUE; | |||
700 | } | |||
701 | ||||
702 | if (argv[0] && switch_stristr("add", argv[0])) { | |||
703 | if (switch_nat_add_mapping((switch_port_t) atoi(argv[1]), proto, &external_port, sticky) == SWITCH_STATUS_SUCCESS) { | |||
704 | stream->write_function(stream, "true"); /* still return true */ | |||
705 | goto ok; | |||
706 | } | |||
707 | } else if (argv[0] && switch_stristr("del", argv[0])) { | |||
708 | if (switch_nat_del_mapping((switch_port_t) atoi(argv[1]), proto) == SWITCH_STATUS_SUCCESS) { | |||
709 | stream->write_function(stream, "true"); | |||
710 | goto ok; | |||
711 | } | |||
712 | } | |||
713 | ||||
714 | error: | |||
715 | ||||
716 | stream->write_function(stream, "false"); | |||
717 | goto ok; | |||
718 | ||||
719 | usage: | |||
720 | stream->write_function(stream, "USAGE: nat_map [status|reinit|republish] | [add|del] <port> [tcp|udp] [sticky] | [mapping] <enable|disable>"); | |||
721 | ||||
722 | ok: | |||
723 | ||||
724 | switch_safe_free(mydata)if (mydata) {free(mydata);mydata=((void*)0);}; | |||
725 | ||||
726 | return SWITCH_STATUS_SUCCESS; | |||
727 | } | |||
728 | ||||
729 | SWITCH_STANDARD_API(time_test_function)static switch_status_t time_test_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
730 | { | |||
731 | switch_time_t now, then; | |||
732 | int x; | |||
733 | long mss; | |||
734 | uint32_t total = 0; | |||
735 | int diff; | |||
736 | int max = 10, a = 0; | |||
737 | char *p; | |||
738 | if (zstr(cmd)_zstr(cmd)) { | |||
739 | stream->write_function(stream, "parameter missing\n"); | |||
740 | return SWITCH_STATUS_SUCCESS; | |||
741 | } | |||
742 | ||||
743 | mss = atol(cmd); | |||
744 | ||||
745 | if (mss > 1000000) { | |||
746 | mss = 1000000; | |||
747 | } | |||
748 | ||||
749 | if ((p = strchr(cmd, ' ')(__extension__ (__builtin_constant_p (' ') && !__builtin_constant_p (cmd) && (' ') == '\0' ? (char *) __rawmemchr (cmd, ' ' ) : __builtin_strchr (cmd, ' '))))) { | |||
750 | if ((a = atoi(p + 1)) > 0) { | |||
751 | max = a; | |||
752 | if (max > 100) { | |||
753 | max = 100; | |||
754 | } | |||
755 | } | |||
756 | } | |||
757 | ||||
758 | for (x = 1; x <= max; x++) { | |||
759 | then = switch_time_ref(); | |||
760 | switch_yield(mss)switch_sleep(mss);; | |||
761 | now = switch_time_ref(); | |||
762 | diff = (int) (now - then); | |||
763 | stream->write_function(stream, "test %d sleep %ld %d\n", x, mss, diff); | |||
764 | total += diff; | |||
765 | } | |||
766 | stream->write_function(stream, "avg %d\n", total / (x > 1 ? x - 1 : 1)); | |||
767 | ||||
768 | return SWITCH_STATUS_SUCCESS; | |||
769 | } | |||
770 | ||||
771 | SWITCH_STANDARD_API(msleep_function)static switch_status_t msleep_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
772 | { | |||
773 | if (cmd) { | |||
774 | long ms = atol(cmd); | |||
775 | switch_yield(ms * 1000)switch_sleep(ms * 1000);; | |||
776 | } | |||
777 | ||||
778 | stream->write_function(stream, "+OK"); | |||
779 | ||||
780 | return SWITCH_STATUS_SUCCESS; | |||
781 | } | |||
782 | ||||
783 | ||||
784 | #define TIMER_TEST_SYNTAX"<10|20|40|60|120> [<1..200>] [<timer_name>]" "<10|20|40|60|120> [<1..200>] [<timer_name>]" | |||
785 | ||||
786 | SWITCH_STANDARD_API(timer_test_function)static switch_status_t timer_test_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream ) | |||
787 | { | |||
788 | switch_time_t now, then, start, end; | |||
789 | int x; | |||
790 | int mss = 20; | |||
791 | uint32_t total = 0; | |||
792 | int diff; | |||
793 | int max = 50; | |||
794 | switch_timer_t timer = { 0 }; | |||
795 | int argc = 0; | |||
796 | char *argv[5] = { 0 }; | |||
797 | const char *timer_name = "soft"; | |||
798 | switch_memory_pool_t *pool; | |||
799 | char *mycmd = NULL((void*)0); | |||
800 | ||||
801 | switch_core_new_memory_pool(&pool)switch_core_perform_new_memory_pool(&pool, "mod_commands.c" , (const char *)__func__, 801); | |||
802 | ||||
803 | if (zstr(cmd)_zstr(cmd)) { | |||
804 | mycmd = ""; | |||
805 | } else { | |||
806 | mycmd = switch_core_strdup(pool, cmd)switch_core_perform_strdup(pool, cmd, "mod_commands.c", (const char *)__func__, 806); | |||
807 | } | |||
808 | ||||
809 | argc = switch_split(mycmd, ' ', argv)switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof (argv[0]))); | |||
810 | ||||
811 | if (argc > 0) { | |||
812 | mss = atoi(argv[0]); | |||
813 | } | |||
814 | ||||
815 | if (argc > 1) { | |||
816 | int tmp = atoi(argv[1]); | |||
817 | if (tmp > 0 && tmp <= 400) { | |||
818 | max = tmp; | |||
819 | } | |||
820 | } | |||
821 | ||||
822 | if (argc > 2) { | |||
823 | timer_name = argv[2]; | |||
824 | } | |||
825 | ||||
826 | if (mss != 10 && mss != 20 && mss != 30 && mss != 32 && mss != 40 && mss != 60 && mss != 120) { | |||
827 | stream->write_function(stream, "parameter missing: %s\n", TIMER_TEST_SYNTAX"<10|20|40|60|120> [<1..200>] [<timer_name>]"); | |||
828 | goto end; | |||
829 | } | |||
830 | ||||
831 | if (switch_core_timer_init(&timer, timer_name, mss, 1, pool) != SWITCH_STATUS_SUCCESS) { | |||
832 | stream->write_function(stream, "Timer Error!\n"); | |||
833 | goto end; | |||
834 | } | |||
835 | ||||
836 | switch_core_timer_next(&timer); /* Step timer once before testing results below, to get first timestamp as accurate as possible */ | |||
837 | ||||
838 | start = then = switch_time_ref(); | |||
839 | ||||
840 | for (x = 1; x <= max; x++) { | |||
841 | switch_core_timer_next(&timer); | |||
842 | now = switch_time_ref(); | |||
843 | diff = (int) (now - then); | |||
844 | total += diff; | |||
845 | then = now; | |||
846 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_commands.c", (const char *)__func__ , 846, ((void*)0), SWITCH_LOG_CONSOLE, "Timer Test: %d sleep %d %d\n", x, mss, diff); | |||
847 | } | |||
848 | end = then; | |||
849 | ||||
850 | switch_yield(250000)switch_sleep(250000);; | |||
851 | ||||
852 | stream->write_function(stream, "Avg: %0.3fms Total Time: %0.3fms\n", (float) ((float) (total / (x - 1)) / 1000), | |||
853 | (float) ((float) (end - start) / 1000)); | |||
854 | ||||
855 | end: | |||
856 | ||||
857 | switch_core_destroy_memory_pool(&pool)switch_core_perform_destroy_memory_pool(&pool, "mod_commands.c" , (const char *)__func__, 857); | |||
858 | ||||
859 | ||||
860 | return SWITCH_STATUS_SUCCESS; | |||
861 | } | |||
862 | ||||
863 | SWITCH_STANDARD_API(group_call_function)static switch_status_t group_call_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream ) | |||
864 | { | |||
865 | char *domain, *dup_domain = NULL((void*)0); | |||
866 | char *group_name = NULL((void*)0); | |||
867 | char *flags; | |||
868 | int ok = 0; | |||
869 | switch_channel_t *channel = NULL((void*)0); | |||
870 | char *fp = NULL((void*)0); | |||
871 | const char *call_delim = ","; | |||
872 | ||||
873 | if (zstr(cmd)_zstr(cmd)) { | |||
874 | goto end; | |||
875 | } | |||
876 | ||||
877 | if (session) { | |||
878 | channel = switch_core_session_get_channel(session); | |||
879 | } | |||
880 | ||||
881 | group_name = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))); | |||
882 | switch_assert(group_name)((group_name) ? (void) (0) : __assert_fail ("group_name", "mod_commands.c" , 882, __PRETTY_FUNCTION__)); | |||
883 | ||||
884 | if ((flags = strchr(group_name, '+')(__extension__ (__builtin_constant_p ('+') && !__builtin_constant_p (group_name) && ('+') == '\0' ? (char *) __rawmemchr (group_name, '+') : __builtin_strchr (group_name, '+'))))) { | |||
885 | *flags++ = '\0'; | |||
886 | for (fp = flags; fp && *fp; fp++) { | |||
887 | switch (*fp) { | |||
888 | case 'F': | |||
889 | call_delim = "|"; | |||
890 | break; | |||
891 | case 'A': | |||
892 | call_delim = ","; | |||
893 | break; | |||
894 | case 'E': | |||
895 | call_delim = SWITCH_ENT_ORIGINATE_DELIM":_:"; | |||
896 | break; | |||
897 | default: | |||
898 | break; | |||
899 | } | |||
900 | } | |||
901 | } | |||
902 | ||||
903 | domain = strchr(group_name, '@')(__extension__ (__builtin_constant_p ('@') && !__builtin_constant_p (group_name) && ('@') == '\0' ? (char *) __rawmemchr (group_name, '@') : __builtin_strchr (group_name, '@'))); | |||
904 | ||||
905 | if (domain) { | |||
906 | *domain++ = '\0'; | |||
907 | } else { | |||
908 | if ((dup_domain = switch_core_get_domain(SWITCH_TRUE))) { | |||
909 | domain = dup_domain; | |||
910 | } | |||
911 | } | |||
912 | ||||
913 | if (!zstr(domain)_zstr(domain)) { | |||
914 | switch_xml_t xml, x_domain, x_group; | |||
915 | switch_event_t *params; | |||
916 | switch_stream_handle_t dstream = { 0 }; | |||
917 | ||||
918 | SWITCH_STANDARD_STREAM(dstream)memset(&dstream, 0, sizeof(dstream)); dstream.data = malloc (1024); ((dstream.data) ? (void) (0) : __assert_fail ("dstream.data" , "mod_commands.c", 918, __PRETTY_FUNCTION__)); memset(dstream .data, 0, 1024); dstream.end = dstream.data; dstream.data_size = 1024; dstream.write_function = switch_console_stream_write ; dstream.raw_write_function = switch_console_stream_raw_write ; dstream.alloc_len = 1024; dstream.alloc_chunk = 1024; | |||
919 | ||||
920 | switch_event_create(¶ms, SWITCH_EVENT_REQUEST_PARAMS)switch_event_create_subclass_detailed("mod_commands.c", (const char * )(const char *)__func__, 920, ¶ms, SWITCH_EVENT_REQUEST_PARAMS , ((void*)0)); | |||
921 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "group", group_name); | |||
922 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "domain", domain); | |||
923 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "action", "group_call"); | |||
924 | ||||
925 | if (switch_xml_locate_group(group_name, domain, &xml, &x_domain, &x_group, params) == SWITCH_STATUS_SUCCESS) { | |||
926 | switch_xml_t x_user, x_users, x_param, x_params, my_x_user; | |||
927 | ||||
928 | if ((x_users = switch_xml_child(x_group, "users"))) { | |||
929 | ok++; | |||
930 | ||||
931 | for (x_user = switch_xml_child(x_users, "user"); x_user; x_user = x_user->next) { | |||
932 | const char *id = switch_xml_attr_soft(x_user, "id"); | |||
933 | const char *x_user_type = switch_xml_attr_soft(x_user, "type"); | |||
934 | const char *dest = NULL((void*)0); | |||
935 | char *d_dest = NULL((void*)0); | |||
936 | switch_xml_t xml_for_pointer = NULL((void*)0), x_domain_for_pointer = NULL((void*)0), x_group_for_pointer = NULL((void*)0), x_user_for_pointer = NULL((void*)0); | |||
937 | ||||
938 | my_x_user = x_user; | |||
939 | ||||
940 | if (!strcmp(x_user_type, "pointer")__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (x_user_type) && __builtin_constant_p ("pointer") && (__s1_len = __builtin_strlen (x_user_type), __s2_len = __builtin_strlen ("pointer"), (!((size_t)(const void *)((x_user_type) + 1) - ( size_t)(const void *)(x_user_type) == 1) || __s1_len >= 4) && (!((size_t)(const void *)(("pointer") + 1) - (size_t )(const void *)("pointer") == 1) || __s2_len >= 4)) ? __builtin_strcmp (x_user_type, "pointer") : (__builtin_constant_p (x_user_type ) && ((size_t)(const void *)((x_user_type) + 1) - (size_t )(const void *)(x_user_type) == 1) && (__s1_len = __builtin_strlen (x_user_type), __s1_len < 4) ? (__builtin_constant_p ("pointer" ) && ((size_t)(const void *)(("pointer") + 1) - (size_t )(const void *)("pointer") == 1) ? __builtin_strcmp (x_user_type , "pointer") : (__extension__ ({ const unsigned char *__s2 = ( const unsigned char *) (const char *) ("pointer"); int __result = (((const unsigned char *) (const char *) (x_user_type))[0] - __s2[0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (x_user_type))[1] - __s2[1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (x_user_type))[2] - __s2[2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (x_user_type))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p ("pointer" ) && ((size_t)(const void *)(("pointer") + 1) - (size_t )(const void *)("pointer") == 1) && (__s2_len = __builtin_strlen ("pointer"), __s2_len < 4) ? (__builtin_constant_p (x_user_type ) && ((size_t)(const void *)((x_user_type) + 1) - (size_t )(const void *)(x_user_type) == 1) ? __builtin_strcmp (x_user_type , "pointer") : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (x_user_type); int __result = (((const unsigned char *) (const char *) ("pointer"))[0] - __s2[0]); if (__s2_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) ("pointer"))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) ("pointer"))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) ("pointer"))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (x_user_type , "pointer")))); })) { | |||
941 | if (switch_xml_locate_user("id", id, domain, NULL((void*)0), | |||
942 | &xml_for_pointer, &x_domain_for_pointer, | |||
943 | &x_user_for_pointer, &x_group_for_pointer, params) != SWITCH_STATUS_SUCCESS) { | |||
944 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "mod_commands.c", (const char *)__func__ , 944, (const char*)(session), SWITCH_LOG_WARNING, "Can't find user [%s@%s]\n", id, domain); | |||
945 | goto done_x_user; | |||
946 | } | |||
947 | my_x_user = x_user_for_pointer; | |||
948 | } | |||
949 | ||||
950 | if ((x_params = switch_xml_child(x_domain, "params"))) { | |||
951 | for (x_param = switch_xml_child(x_params, "param"); x_param; x_param = x_param->next) { | |||
952 | const char *var = switch_xml_attr(x_param, "name"); | |||
953 | const char *val = switch_xml_attr(x_param, "value"); | |||
954 | ||||
955 | if (!strcasecmp(var, "group-dial-string")) { | |||
956 | dest = val; | |||
957 | break; | |||
958 | } | |||
959 | ||||
960 | if (!strcasecmp(var, "dial-string")) { | |||
961 | dest = val; | |||
962 | } | |||
963 | } | |||
964 | } | |||
965 | ||||
966 | if ((x_params = switch_xml_child(x_group, "params"))) { | |||
967 | for (x_param = switch_xml_child(x_params, "param"); x_param; x_param = x_param->next) { | |||
968 | const char *var = switch_xml_attr(x_param, "name"); | |||
969 | const char *val = switch_xml_attr(x_param, "value"); | |||
970 | ||||
971 | if (!strcasecmp(var, "group-dial-string")) { | |||
972 | dest = val; | |||
973 | break; | |||
974 | } | |||
975 | ||||
976 | if (!strcasecmp(var, "dial-string")) { | |||
977 | dest = val; | |||
978 | } | |||
979 | } | |||
980 | } | |||
981 | ||||
982 | if ((x_params = switch_xml_child(my_x_user, "params"))) { | |||
983 | for (x_param = switch_xml_child(x_params, "param"); x_param; x_param = x_param->next) { | |||
984 | const char *var = switch_xml_attr(x_param, "name"); | |||
985 | const char *val = switch_xml_attr(x_param, "value"); | |||
986 | ||||
987 | if (!strcasecmp(var, "group-dial-string")) { | |||
988 | dest = val; | |||
989 | break; | |||
990 | } | |||
991 | ||||
992 | if (!strcasecmp(var, "dial-string")) { | |||
993 | dest = val; | |||
994 | } | |||
995 | } | |||
996 | } | |||
997 | ||||
998 | if (dest) { | |||
999 | if (channel) { | |||
1000 | switch_channel_set_variable(channel, "dialed_group", group_name)switch_channel_set_variable_var_check(channel, "dialed_group" , group_name, SWITCH_TRUE); | |||
1001 | switch_channel_set_variable(channel, "dialed_user", id)switch_channel_set_variable_var_check(channel, "dialed_user", id, SWITCH_TRUE); | |||
1002 | switch_channel_set_variable(channel, "dialed_domain", domain)switch_channel_set_variable_var_check(channel, "dialed_domain" , domain, SWITCH_TRUE); | |||
1003 | d_dest = switch_channel_expand_variables(channel, dest)switch_channel_expand_variables_check(channel, dest, ((void*) 0), ((void*)0), 0); | |||
1004 | } else { | |||
1005 | switch_event_del_header(params, "dialed_user")switch_event_del_header_val(params, "dialed_user", ((void*)0) ); | |||
1006 | switch_event_del_header(params, "dialed_group")switch_event_del_header_val(params, "dialed_group", ((void*)0 )); | |||
1007 | switch_event_del_header(params, "dialed_domain")switch_event_del_header_val(params, "dialed_domain", ((void*) 0)); | |||
1008 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "dialed_user", id); | |||
1009 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "dialed_group", group_name); | |||
1010 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "dialed_domain", domain); | |||
1011 | d_dest = switch_event_expand_headers(params, dest)switch_event_expand_headers_check(params, dest, ((void*)0), ( (void*)0), 0); | |||
1012 | } | |||
1013 | } else { | |||
1014 | d_dest = switch_mprintf("user/%s@%s", id, domain); | |||
1015 | } | |||
1016 | ||||
1017 | if (d_dest) { | |||
1018 | dstream.write_function(&dstream, "%s%s", d_dest, call_delim); | |||
1019 | ||||
1020 | if (d_dest != dest) { | |||
1021 | free(d_dest); | |||
1022 | } | |||
1023 | } | |||
1024 | ||||
1025 | done_x_user: | |||
1026 | if (xml_for_pointer) { | |||
1027 | switch_xml_free(xml_for_pointer); | |||
1028 | xml_for_pointer = NULL((void*)0); | |||
1029 | } | |||
1030 | } | |||
1031 | ||||
1032 | if (ok && dstream.data) { | |||
1033 | char *data = (char *) dstream.data; | |||
1034 | char *p; | |||
1035 | ||||
1036 | if ((p = strstr(end_of_p(data)(*data == '\0' ? data : data + strlen(data) - 1) - 3, call_delim))) { | |||
1037 | *p = '\0'; | |||
1038 | } | |||
1039 | ||||
1040 | for (p = data; p && *p; p++) { | |||
1041 | if (*p == '{') { | |||
1042 | *p = '['; | |||
1043 | } else if (*p == '}') { | |||
1044 | *p = ']'; | |||
1045 | } | |||
1046 | } | |||
1047 | ||||
1048 | ||||
1049 | stream->write_function(stream, "%s", data); | |||
1050 | free(dstream.data); | |||
1051 | } else { | |||
1052 | ok = 0; | |||
1053 | } | |||
1054 | ||||
1055 | } | |||
1056 | } | |||
1057 | switch_xml_free(xml); | |||
1058 | switch_event_destroy(¶ms); | |||
1059 | } | |||
1060 | ||||
1061 | end: | |||
1062 | ||||
1063 | switch_safe_free(group_name)if (group_name) {free(group_name);group_name=((void*)0);}; | |||
1064 | switch_safe_free(dup_domain)if (dup_domain) {free(dup_domain);dup_domain=((void*)0);}; | |||
1065 | ||||
1066 | if (!ok) { | |||
1067 | stream->write_function(stream, "error/NO_ROUTE_DESTINATION"); | |||
1068 | } | |||
1069 | ||||
1070 | return SWITCH_STATUS_SUCCESS; | |||
1071 | } | |||
1072 | ||||
1073 | ||||
1074 | SWITCH_STANDARD_API(in_group_function)static switch_status_t in_group_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
1075 | { | |||
1076 | switch_xml_t x_domain, xml = NULL((void*)0), x_group; | |||
1077 | int argc; | |||
1078 | char *mydata = NULL((void*)0), *argv[2], *user, *domain, *dup_domain = NULL((void*)0); | |||
1079 | char delim = ','; | |||
1080 | switch_event_t *params = NULL((void*)0); | |||
1081 | const char *rval = "false"; | |||
1082 | char *group; | |||
1083 | ||||
1084 | if (zstr(cmd)_zstr(cmd) || !(mydata = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))))) { | |||
1085 | goto end; | |||
1086 | } | |||
1087 | ||||
1088 | if ((argc = switch_separate_string(mydata, delim, argv, (sizeof(argv) / sizeof(argv[0])))) < 2) { | |||
1089 | goto end; | |||
1090 | } | |||
1091 | ||||
1092 | user = argv[0]; | |||
1093 | group = argv[1]; | |||
1094 | ||||
1095 | if ((domain = strchr(user, '@')(__extension__ (__builtin_constant_p ('@') && !__builtin_constant_p (user) && ('@') == '\0' ? (char *) __rawmemchr (user , '@') : __builtin_strchr (user, '@'))))) { | |||
1096 | *domain++ = '\0'; | |||
1097 | } else { | |||
1098 | if ((dup_domain = switch_core_get_domain(SWITCH_TRUE))) { | |||
1099 | domain = dup_domain; | |||
1100 | } | |||
1101 | } | |||
1102 | ||||
1103 | switch_event_create(¶ms, SWITCH_EVENT_REQUEST_PARAMS)switch_event_create_subclass_detailed("mod_commands.c", (const char * )(const char *)__func__, 1103, ¶ms, SWITCH_EVENT_REQUEST_PARAMS , ((void*)0)); | |||
1104 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "user", user); | |||
1105 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "domain", domain); | |||
1106 | ||||
1107 | if (switch_xml_locate_group(group, domain, &xml, &x_domain, &x_group, params) == SWITCH_STATUS_SUCCESS) { | |||
1108 | switch_xml_t x_users; | |||
1109 | if ((x_users = switch_xml_child(x_group, "users"))) { | |||
1110 | if (switch_xml_find_child(x_users, "user", "id", user)) { | |||
1111 | rval = "true"; | |||
1112 | } | |||
1113 | } | |||
1114 | } | |||
1115 | ||||
1116 | end: | |||
1117 | ||||
1118 | stream->write_function(stream, "%s", rval); | |||
1119 | ||||
1120 | switch_xml_free(xml); | |||
1121 | switch_safe_free(mydata)if (mydata) {free(mydata);mydata=((void*)0);}; | |||
1122 | switch_safe_free(dup_domain)if (dup_domain) {free(dup_domain);dup_domain=((void*)0);}; | |||
1123 | switch_event_destroy(¶ms); | |||
1124 | ||||
1125 | return SWITCH_STATUS_SUCCESS; | |||
1126 | } | |||
1127 | ||||
1128 | SWITCH_STANDARD_API(user_data_function)static switch_status_t user_data_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
1129 | { | |||
1130 | switch_xml_t x_user = NULL((void*)0), x_param, x_params; | |||
1131 | int argc; | |||
1132 | char *mydata = NULL((void*)0), *argv[3], *key = NULL((void*)0), *type = NULL((void*)0), *user, *domain, *dup_domain = NULL((void*)0); | |||
1133 | char delim = ' '; | |||
1134 | const char *container = "params", *elem = "param"; | |||
1135 | const char *result = NULL((void*)0); | |||
1136 | switch_event_t *params = NULL((void*)0); | |||
1137 | ||||
1138 | if (zstr(cmd)_zstr(cmd) || !(mydata = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))))) { | |||
1139 | goto end; | |||
1140 | } | |||
1141 | ||||
1142 | if ((argc = switch_separate_string(mydata, delim, argv, (sizeof(argv) / sizeof(argv[0])))) < 3) { | |||
1143 | goto end; | |||
1144 | } | |||
1145 | ||||
1146 | user = argv[0]; | |||
1147 | type = argv[1]; | |||
1148 | key = argv[2]; | |||
1149 | ||||
1150 | if ((domain = strchr(user, '@')(__extension__ (__builtin_constant_p ('@') && !__builtin_constant_p (user) && ('@') == '\0' ? (char *) __rawmemchr (user , '@') : __builtin_strchr (user, '@'))))) { | |||
1151 | *domain++ = '\0'; | |||
1152 | } else { | |||
1153 | if ((dup_domain = switch_core_get_domain(SWITCH_TRUE))) { | |||
1154 | domain = dup_domain; | |||
1155 | } else { | |||
1156 | domain = "cluecon.com"; | |||
1157 | } | |||
1158 | } | |||
1159 | ||||
1160 | switch_event_create(¶ms, SWITCH_EVENT_REQUEST_PARAMS)switch_event_create_subclass_detailed("mod_commands.c", (const char * )(const char *)__func__, 1160, ¶ms, SWITCH_EVENT_REQUEST_PARAMS , ((void*)0)); | |||
1161 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "user", user); | |||
1162 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "domain", domain); | |||
1163 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "type", type); | |||
1164 | ||||
1165 | if (key && type && switch_xml_locate_user_merged("id:number-alias", user, domain, NULL((void*)0), &x_user, params) == SWITCH_STATUS_SUCCESS) { | |||
1166 | if (!strcmp(type, "attr")__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (type) && __builtin_constant_p ("attr") && ( __s1_len = __builtin_strlen (type), __s2_len = __builtin_strlen ("attr"), (!((size_t)(const void *)((type) + 1) - (size_t)(const void *)(type) == 1) || __s1_len >= 4) && (!((size_t )(const void *)(("attr") + 1) - (size_t)(const void *)("attr" ) == 1) || __s2_len >= 4)) ? __builtin_strcmp (type, "attr" ) : (__builtin_constant_p (type) && ((size_t)(const void *)((type) + 1) - (size_t)(const void *)(type) == 1) && (__s1_len = __builtin_strlen (type), __s1_len < 4) ? (__builtin_constant_p ("attr") && ((size_t)(const void *)(("attr") + 1) - ( size_t)(const void *)("attr") == 1) ? __builtin_strcmp (type, "attr") : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) ("attr"); int __result = ((( const unsigned char *) (const char *) (type))[0] - __s2[0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (type))[1] - __s2[1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (type))[2] - __s2[2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (type))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p ("attr") && ((size_t)(const void *)(("attr") + 1) - (size_t)(const void *)("attr") == 1) && (__s2_len = __builtin_strlen ("attr"), __s2_len < 4) ? (__builtin_constant_p (type) && ((size_t)(const void *)((type) + 1) - (size_t )(const void *)(type) == 1) ? __builtin_strcmp (type, "attr") : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (type); int __result = (((const unsigned char *) (const char *) ("attr"))[0] - __s2[0]); if (__s2_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) ("attr"))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) ("attr"))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) ("attr"))[3] - __s2[3]); } } __result ; })))) : __builtin_strcmp (type, "attr")))); })) { | |||
1167 | const char *attr = switch_xml_attr_soft(x_user, key); | |||
1168 | result = attr; | |||
1169 | goto end; | |||
1170 | } | |||
1171 | ||||
1172 | if (!strcmp(type, "var")__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (type) && __builtin_constant_p ("var") && (__s1_len = __builtin_strlen (type), __s2_len = __builtin_strlen ("var" ), (!((size_t)(const void *)((type) + 1) - (size_t)(const void *)(type) == 1) || __s1_len >= 4) && (!((size_t)(const void *)(("var") + 1) - (size_t)(const void *)("var") == 1) || __s2_len >= 4)) ? __builtin_strcmp (type, "var") : (__builtin_constant_p (type) && ((size_t)(const void *)((type) + 1) - (size_t )(const void *)(type) == 1) && (__s1_len = __builtin_strlen (type), __s1_len < 4) ? (__builtin_constant_p ("var") && ((size_t)(const void *)(("var") + 1) - (size_t)(const void * )("var") == 1) ? __builtin_strcmp (type, "var") : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) ("var"); int __result = (((const unsigned char *) (const char *) (type))[0] - __s2[0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (type))[1] - __s2[1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (type))[2] - __s2[2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (type))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p ("var") && ((size_t)(const void *)(("var") + 1) - (size_t )(const void *)("var") == 1) && (__s2_len = __builtin_strlen ("var"), __s2_len < 4) ? (__builtin_constant_p (type) && ((size_t)(const void *)((type) + 1) - (size_t)(const void *) (type) == 1) ? __builtin_strcmp (type, "var") : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (type); int __result = (((const unsigned char *) (const char *) ("var"))[0] - __s2[0]); if (__s2_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) ("var"))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) ("var"))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) ("var"))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (type, "var")))); })) { | |||
1173 | container = "variables"; | |||
1174 | elem = "variable"; | |||
1175 | } | |||
1176 | ||||
1177 | if ((x_params = switch_xml_child(x_user, container))) { | |||
1178 | for (x_param = switch_xml_child(x_params, elem); x_param; x_param = x_param->next) { | |||
1179 | const char *var = switch_xml_attr(x_param, "name"); | |||
1180 | const char *val = switch_xml_attr(x_param, "value"); | |||
1181 | ||||
1182 | if (var && val && !strcasecmp(var, key)) { | |||
1183 | result = val; | |||
1184 | } | |||
1185 | } | |||
1186 | } | |||
1187 | } | |||
1188 | ||||
1189 | end: | |||
1190 | if (result) { | |||
1191 | stream->write_function(stream, "%s", result); | |||
1192 | } | |||
1193 | switch_xml_free(x_user); | |||
1194 | switch_safe_free(mydata)if (mydata) {free(mydata);mydata=((void*)0);}; | |||
1195 | switch_safe_free(dup_domain)if (dup_domain) {free(dup_domain);dup_domain=((void*)0);}; | |||
1196 | switch_event_destroy(¶ms); | |||
1197 | ||||
1198 | return SWITCH_STATUS_SUCCESS; | |||
1199 | } | |||
1200 | ||||
1201 | static switch_status_t _find_user(const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream, switch_bool_t tf) | |||
1202 | { | |||
1203 | switch_xml_t x_user = NULL((void*)0); | |||
1204 | int argc; | |||
1205 | char *mydata = NULL((void*)0), *argv[3]; | |||
1206 | char *key, *user, *domain; | |||
1207 | char *xmlstr; | |||
1208 | char delim = ' '; | |||
1209 | const char *err = NULL((void*)0); | |||
1210 | ||||
1211 | stream_format format = { 0 }; | |||
1212 | set_format(&format, stream); | |||
1213 | ||||
1214 | if (!tf && format.api) { | |||
1215 | stream->write_function(stream, "Content-Type: text/xml\r\n\r\n"); | |||
1216 | format.html = SWITCH_FALSE; | |||
1217 | } | |||
1218 | ||||
1219 | if (!cmd) { | |||
1220 | err = "bad args"; | |||
1221 | goto end; | |||
1222 | } | |||
1223 | ||||
1224 | mydata = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))); | |||
1225 | switch_assert(mydata)((mydata) ? (void) (0) : __assert_fail ("mydata", "mod_commands.c" , 1225, __PRETTY_FUNCTION__)); | |||
1226 | ||||
1227 | argc = switch_separate_string(mydata, delim, argv, (sizeof(argv) / sizeof(argv[0]))); | |||
1228 | ||||
1229 | if (argc < 3) { | |||
1230 | err = "bad args"; | |||
1231 | goto end; | |||
1232 | } | |||
1233 | ||||
1234 | key = argv[0]; | |||
1235 | user = argv[1]; | |||
1236 | domain = argv[2]; | |||
1237 | ||||
1238 | if (!(key && user && domain)) { | |||
1239 | err = "bad args"; | |||
1240 | goto end; | |||
1241 | } | |||
1242 | ||||
1243 | if (switch_xml_locate_user_merged(key, user, domain, NULL((void*)0), &x_user, NULL((void*)0)) != SWITCH_STATUS_SUCCESS) { | |||
1244 | err = "can't find user"; | |||
1245 | goto end; | |||
1246 | } | |||
1247 | ||||
1248 | end: | |||
1249 | if (session || tf) { | |||
1250 | stream->write_function(stream, err ? "false" : "true"); | |||
1251 | } else { | |||
1252 | if (err) { | |||
1253 | if (format.api) { | |||
1254 | stream->write_function(stream, "<error>%s</error>\n", err); | |||
1255 | } else { | |||
1256 | stream->write_function(stream, "-ERR %s\n", err); | |||
1257 | } | |||
1258 | } | |||
1259 | ||||
1260 | if (x_user) { | |||
1261 | /* print header if request to show xml on webpage */ | |||
1262 | if (format.html) { | |||
1263 | xmlstr = switch_xml_tohtml(x_user, SWITCH_TRUE); | |||
1264 | } else { | |||
1265 | xmlstr = switch_xml_toxml(x_user, SWITCH_FALSE); | |||
1266 | } | |||
1267 | switch_assert(xmlstr)((xmlstr) ? (void) (0) : __assert_fail ("xmlstr", "mod_commands.c" , 1267, __PRETTY_FUNCTION__)); | |||
1268 | stream->write_function(stream, "%s%s%s", format.html?"<pre>":"", xmlstr, format.html?"</pre>":""); | |||
1269 | switch_safe_free(xmlstr)if (xmlstr) {free(xmlstr);xmlstr=((void*)0);}; | |||
1270 | } | |||
1271 | } | |||
1272 | ||||
1273 | switch_xml_free(x_user); | |||
1274 | switch_safe_free(mydata)if (mydata) {free(mydata);mydata=((void*)0);}; | |||
1275 | return SWITCH_STATUS_SUCCESS; | |||
1276 | } | |||
1277 | ||||
1278 | ||||
1279 | ||||
1280 | SWITCH_STANDARD_API(md5_function)static switch_status_t md5_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
1281 | { | |||
1282 | char digest[SWITCH_MD5_DIGEST_STRING_SIZE33] = { 0 }; | |||
1283 | ||||
1284 | if (zstr(cmd)_zstr(cmd)) { | |||
1285 | stream->write_function(stream, "%s", "!err!"); | |||
1286 | } else { | |||
1287 | switch_md5_string(digest, (void *) cmd, strlen(cmd)); | |||
1288 | stream->write_function(stream, "%s", digest); | |||
1289 | } | |||
1290 | ||||
1291 | return SWITCH_STATUS_SUCCESS; | |||
1292 | } | |||
1293 | ||||
1294 | SWITCH_STANDARD_API(url_decode_function)static switch_status_t url_decode_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream ) | |||
1295 | { | |||
1296 | char *reply = ""; | |||
1297 | char *data = NULL((void*)0); | |||
1298 | ||||
1299 | if (!zstr(cmd)_zstr(cmd)) { | |||
1300 | data = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))); | |||
1301 | switch_url_decode(data); | |||
1302 | reply = data; | |||
1303 | } | |||
1304 | ||||
1305 | stream->write_function(stream, "%s", reply); | |||
1306 | ||||
1307 | switch_safe_free(data)if (data) {free(data);data=((void*)0);}; | |||
1308 | return SWITCH_STATUS_SUCCESS; | |||
1309 | } | |||
1310 | ||||
1311 | SWITCH_STANDARD_API(echo_function)static switch_status_t echo_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
1312 | { | |||
1313 | stream->write_function(stream, "%s", cmd); | |||
1314 | return SWITCH_STATUS_SUCCESS; | |||
1315 | } | |||
1316 | ||||
1317 | SWITCH_STANDARD_API(stun_function)static switch_status_t stun_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
1318 | { | |||
1319 | char *stun_ip = NULL((void*)0); | |||
1320 | char *src_ip = NULL((void*)0); | |||
1321 | switch_port_t stun_port = (switch_port_t) SWITCH_STUN_DEFAULT_PORT3478; | |||
1322 | char *p; | |||
1323 | char ip_buf[256] = ""; | |||
1324 | char *ip = NULL((void*)0); | |||
1325 | switch_port_t port = 0; | |||
1326 | switch_memory_pool_t *pool = NULL((void*)0); | |||
1327 | char *error = ""; | |||
1328 | char *argv[3] = { 0 }; | |||
1329 | char *mycmd = NULL((void*)0); | |||
1330 | ||||
1331 | ip = ip_buf; | |||
1332 | ||||
1333 | if (zstr(cmd)_zstr(cmd)) { | |||
1334 | stream->write_function(stream, "%s", "-STUN Failed! NO STUN SERVER\n"); | |||
1335 | return SWITCH_STATUS_SUCCESS; | |||
1336 | } | |||
1337 | ||||
1338 | mycmd = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))); | |||
1339 | switch_split(mycmd, ' ', argv)switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof (argv[0]))); | |||
1340 | ||||
1341 | stun_ip = argv[0]; | |||
1342 | ||||
1343 | switch_assert(stun_ip)((stun_ip) ? (void) (0) : __assert_fail ("stun_ip", "mod_commands.c" , 1343, __PRETTY_FUNCTION__)); | |||
1344 | ||||
1345 | src_ip = argv[1]; | |||
1346 | ||||
1347 | if ((p = strchr(stun_ip, ':')(__extension__ (__builtin_constant_p (':') && !__builtin_constant_p (stun_ip) && (':') == '\0' ? (char *) __rawmemchr (stun_ip , ':') : __builtin_strchr (stun_ip, ':'))))) { | |||
1348 | int iport; | |||
1349 | *p++ = '\0'; | |||
1350 | iport = atoi(p); | |||
1351 | if (iport > 0 && iport < 0xFFFF) { | |||
1352 | stun_port = (switch_port_t) iport; | |||
1353 | } | |||
1354 | } else { | |||
1355 | p = stun_ip; | |||
1356 | } | |||
1357 | ||||
1358 | if (!zstr(src_ip)_zstr(src_ip) && (p = strchr(src_ip, ':')(__extension__ (__builtin_constant_p (':') && !__builtin_constant_p (src_ip) && (':') == '\0' ? (char *) __rawmemchr (src_ip , ':') : __builtin_strchr (src_ip, ':'))))) { | |||
1359 | int iport; | |||
1360 | *p++ = '\0'; | |||
1361 | iport = atoi(p); | |||
1362 | if (iport > 0 && iport < 0xFFFF) { | |||
1363 | port = (switch_port_t) iport; | |||
1364 | } | |||
1365 | } else if (!zstr(src_ip)_zstr(src_ip)) { | |||
1366 | ip = src_ip; | |||
1367 | } | |||
1368 | ||||
1369 | if ( !zstr(src_ip)_zstr(src_ip) ) { | |||
1370 | switch_copy_string(ip_buf, src_ip, sizeof(ip_buf)); | |||
1371 | } else { | |||
1372 | switch_find_local_ip(ip_buf, sizeof(ip_buf), NULL((void*)0), AF_INET2); | |||
1373 | } | |||
1374 | ||||
1375 | switch_core_new_memory_pool(&pool)switch_core_perform_new_memory_pool(&pool, "mod_commands.c" , (const char *)__func__, 1375); | |||
1376 | ||||
1377 | if (zstr(stun_ip)_zstr(stun_ip)) { | |||
1378 | stream->write_function(stream, "%s", "-STUN Failed! NO STUN SERVER\n"); | |||
1379 | } else { | |||
1380 | if ((switch_stun_lookup(&ip, &port, stun_ip, stun_port, &error, pool)) == SWITCH_STATUS_SUCCESS && ip && port) { | |||
1381 | stream->write_function(stream, "%s:%u\n", ip, port); | |||
1382 | } else { | |||
1383 | stream->write_function(stream, "-STUN Failed! [%s]\n", error); | |||
1384 | } | |||
1385 | } | |||
1386 | ||||
1387 | switch_core_destroy_memory_pool(&pool)switch_core_perform_destroy_memory_pool(&pool, "mod_commands.c" , (const char *)__func__, 1387); | |||
1388 | switch_safe_free(mycmd)if (mycmd) {free(mycmd);mycmd=((void*)0);}; | |||
1389 | return SWITCH_STATUS_SUCCESS; | |||
1390 | } | |||
1391 | ||||
1392 | SWITCH_STANDARD_API(expand_function)static switch_status_t expand_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
1393 | { | |||
1394 | char *expanded; | |||
1395 | char *dup; | |||
1396 | char *arg = NULL((void*)0); | |||
1397 | char *mycmd; | |||
1398 | switch_status_t status; | |||
1399 | const char *p; | |||
1400 | switch_core_session_t *xsession; | |||
1401 | char uuid[80] = ""; | |||
1402 | ||||
1403 | if (zstr(cmd)_zstr(cmd)) { | |||
1404 | stream->write_function(stream, "-ERR No input\n"); | |||
1405 | return SWITCH_STATUS_SUCCESS; | |||
1406 | } | |||
1407 | ||||
1408 | dup = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))); | |||
1409 | mycmd = dup; | |||
1410 | ||||
1411 | if (!strncasecmp(mycmd, "uuid:", 5)) { | |||
1412 | p = cmd + 5; | |||
1413 | if ((mycmd = strchr(p, ' ')(__extension__ (__builtin_constant_p (' ') && !__builtin_constant_p (p) && (' ') == '\0' ? (char *) __rawmemchr (p, ' ') : __builtin_strchr (p, ' ')))) && *mycmd++) { | |||
1414 | switch_copy_string(uuid, p, mycmd - p); | |||
1415 | } | |||
1416 | } | |||
1417 | ||||
1418 | if (zstr(mycmd)_zstr(mycmd)) { | |||
1419 | stream->write_function(stream, "-ERR No input\n"); | |||
1420 | switch_safe_free(dup)if (dup) {free(dup);dup=((void*)0);}; | |||
1421 | return SWITCH_STATUS_SUCCESS; | |||
1422 | } | |||
1423 | ||||
1424 | if (*uuid) { | |||
1425 | if ((xsession = switch_core_session_locate(uuid)switch_core_session_perform_locate(uuid, "mod_commands.c", (const char *)__func__, 1425))) { | |||
1426 | switch_channel_event_set_data(switch_core_session_get_channel(xsession), stream->param_event); | |||
1427 | switch_core_session_rwunlock(xsession); | |||
1428 | } | |||
1429 | } | |||
1430 | ||||
1431 | if (mycmd && (arg = strchr(mycmd, ' ')(__extension__ (__builtin_constant_p (' ') && !__builtin_constant_p (mycmd) && (' ') == '\0' ? (char *) __rawmemchr (mycmd , ' ') : __builtin_strchr (mycmd, ' '))))) { | |||
1432 | *arg++ = '\0'; | |||
1433 | } | |||
1434 | ||||
1435 | expanded = arg ? switch_event_expand_headers(stream->param_event, arg)switch_event_expand_headers_check(stream->param_event, arg , ((void*)0), ((void*)0), 0) : arg; | |||
1436 | if ((status = switch_api_execute(mycmd, expanded, session, stream)) != SWITCH_STATUS_SUCCESS) { | |||
1437 | stream->write_function(stream, "-ERR Cannot execute command\n"); | |||
1438 | } | |||
1439 | ||||
1440 | if (expanded != arg) { | |||
1441 | free(expanded); | |||
1442 | expanded = NULL((void*)0); | |||
1443 | } | |||
1444 | ||||
1445 | free(dup); | |||
1446 | dup = NULL((void*)0); | |||
1447 | ||||
1448 | return SWITCH_STATUS_SUCCESS; | |||
1449 | } | |||
1450 | ||||
1451 | SWITCH_STANDARD_API(console_complete_function)static switch_status_t console_complete_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
1452 | { | |||
1453 | const char *p, *cursor = NULL((void*)0); | |||
1454 | int c; | |||
1455 | ||||
1456 | if (zstr(cmd)_zstr(cmd)) { | |||
1457 | cmd = " "; | |||
1458 | } | |||
1459 | ||||
1460 | if ((p = strstr(cmd, "c="))) { | |||
1461 | p += 2; | |||
1462 | c = atoi(p); | |||
1463 | if ((p = strchr(p, ';')(__extension__ (__builtin_constant_p (';') && !__builtin_constant_p (p) && (';') == '\0' ? (char *) __rawmemchr (p, ';') : __builtin_strchr (p, ';'))))) { | |||
1464 | cmd = p + 1; | |||
1465 | cursor = cmd + c; | |||
1466 | } | |||
1467 | } | |||
1468 | ||||
1469 | switch_console_complete(cmd, cursor, NULL((void*)0), stream, NULL((void*)0)); | |||
1470 | return SWITCH_STATUS_SUCCESS; | |||
1471 | } | |||
1472 | ||||
1473 | SWITCH_STANDARD_API(console_complete_xml_function)static switch_status_t console_complete_xml_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
1474 | { | |||
1475 | const char *p, *cursor = NULL((void*)0); | |||
1476 | int c; | |||
1477 | switch_xml_t xml = switch_xml_new("complete"); | |||
1478 | char *sxml; | |||
1479 | ||||
1480 | if (zstr(cmd)_zstr(cmd)) { | |||
1481 | cmd = " "; | |||
1482 | } | |||
1483 | ||||
1484 | if ((p = strstr(cmd, "c="))) { | |||
1485 | p += 2; | |||
1486 | c = atoi(p); | |||
1487 | if ((p = strchr(p, ';')(__extension__ (__builtin_constant_p (';') && !__builtin_constant_p (p) && (';') == '\0' ? (char *) __rawmemchr (p, ';') : __builtin_strchr (p, ';'))))) { | |||
1488 | cmd = p + 1; | |||
1489 | cursor = cmd + c; | |||
1490 | } | |||
1491 | } | |||
1492 | ||||
1493 | switch_console_complete(cmd, cursor, NULL((void*)0), NULL((void*)0), xml); | |||
1494 | ||||
1495 | sxml = switch_xml_toxml(xml, SWITCH_TRUE); | |||
1496 | stream->write_function(stream, "%s", sxml); | |||
1497 | free(sxml); | |||
1498 | ||||
1499 | switch_xml_free(xml); | |||
1500 | ||||
1501 | return SWITCH_STATUS_SUCCESS; | |||
1502 | } | |||
1503 | ||||
1504 | SWITCH_STANDARD_API(eval_function)static switch_status_t eval_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
1505 | { | |||
1506 | char *expanded; | |||
1507 | switch_event_t *event; | |||
1508 | char uuid[80] = ""; | |||
1509 | const char *p, *input = cmd; | |||
1510 | ||||
1511 | if (zstr(cmd)_zstr(cmd)) { | |||
1512 | stream->write_function(stream, "%s", ""); | |||
1513 | return SWITCH_STATUS_SUCCESS; | |||
1514 | } | |||
1515 | ||||
1516 | if (!strncasecmp(cmd, "uuid:", 5)) { | |||
1517 | p = cmd + 5; | |||
1518 | if ((input = strchr(p, ' ')(__extension__ (__builtin_constant_p (' ') && !__builtin_constant_p (p) && (' ') == '\0' ? (char *) __rawmemchr (p, ' ') : __builtin_strchr (p, ' ')))) && *input++) { | |||
1519 | switch_copy_string(uuid, p, input - p); | |||
1520 | } | |||
1521 | } | |||
1522 | ||||
1523 | if (zstr(input)_zstr(input)) { | |||
1524 | stream->write_function(stream, "%s", ""); | |||
1525 | return SWITCH_STATUS_SUCCESS; | |||
1526 | } | |||
1527 | ||||
1528 | ||||
1529 | switch_event_create(&event, SWITCH_EVENT_CHANNEL_DATA)switch_event_create_subclass_detailed("mod_commands.c", (const char * )(const char *)__func__, 1529, &event, SWITCH_EVENT_CHANNEL_DATA , ((void*)0)); | |||
1530 | if (*uuid) { | |||
1531 | if ((session = switch_core_session_locate(uuid)switch_core_session_perform_locate(uuid, "mod_commands.c", (const char *)__func__, 1531))) { | |||
1532 | switch_channel_event_set_data(switch_core_session_get_channel(session), event); | |||
1533 | switch_core_session_rwunlock(session); | |||
1534 | } | |||
1535 | } | |||
1536 | ||||
1537 | expanded = switch_event_expand_headers(event, input)switch_event_expand_headers_check(event, input, ((void*)0), ( (void*)0), 0); | |||
1538 | ||||
1539 | stream->write_function(stream, "%s", expanded); | |||
1540 | ||||
1541 | if (expanded != input) { | |||
1542 | free(expanded); | |||
1543 | } | |||
1544 | ||||
1545 | switch_event_destroy(&event); | |||
1546 | ||||
1547 | ||||
1548 | return SWITCH_STATUS_SUCCESS; | |||
1549 | } | |||
1550 | ||||
1551 | SWITCH_STANDARD_API(module_exists_function)static switch_status_t module_exists_function ( const char *cmd , switch_core_session_t *session, switch_stream_handle_t *stream ) | |||
1552 | { | |||
1553 | if (!zstr(cmd)_zstr(cmd)) { | |||
1554 | if (switch_loadable_module_exists(cmd) == SWITCH_STATUS_SUCCESS) { | |||
1555 | stream->write_function(stream, "true"); | |||
1556 | } else { | |||
1557 | stream->write_function(stream, "false"); | |||
1558 | } | |||
1559 | } | |||
1560 | ||||
1561 | return SWITCH_STATUS_SUCCESS; | |||
1562 | } | |||
1563 | ||||
1564 | SWITCH_STANDARD_API(domain_exists_function)static switch_status_t domain_exists_function ( const char *cmd , switch_core_session_t *session, switch_stream_handle_t *stream ) | |||
1565 | { | |||
1566 | switch_xml_t root = NULL((void*)0), domain = NULL((void*)0); | |||
1567 | ||||
1568 | if (!zstr(cmd)_zstr(cmd)) { | |||
1569 | if (switch_xml_locate_domain(cmd, NULL((void*)0), &root, &domain) == SWITCH_STATUS_SUCCESS) { | |||
1570 | stream->write_function(stream, "true"); | |||
1571 | switch_xml_free(root); | |||
1572 | } else { | |||
1573 | stream->write_function(stream, "false"); | |||
1574 | } | |||
1575 | } | |||
1576 | ||||
1577 | return SWITCH_STATUS_SUCCESS; | |||
1578 | } | |||
1579 | ||||
1580 | SWITCH_STANDARD_API(url_encode_function)static switch_status_t url_encode_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream ) | |||
1581 | { | |||
1582 | char *reply = ""; | |||
1583 | char *data = NULL((void*)0); | |||
1584 | int len = 0; | |||
1585 | ||||
1586 | if (!zstr(cmd)_zstr(cmd)) { | |||
1587 | len = (int)(strlen(cmd) * 3) + 1; | |||
1588 | switch_zmalloc(data, len)(void)((((data = calloc(1, (len)))) ? (void) (0) : __assert_fail ("(data = calloc(1, (len)))", "mod_commands.c", 1588, __PRETTY_FUNCTION__ )),data); | |||
1589 | switch_url_encode(cmd, data, len); | |||
1590 | reply = data; | |||
1591 | } | |||
1592 | ||||
1593 | stream->write_function(stream, "%s", reply); | |||
1594 | ||||
1595 | switch_safe_free(data)if (data) {free(data);data=((void*)0);}; | |||
1596 | return SWITCH_STATUS_SUCCESS; | |||
1597 | ||||
1598 | } | |||
1599 | ||||
1600 | SWITCH_STANDARD_API(user_exists_function)static switch_status_t user_exists_function ( const char *cmd , switch_core_session_t *session, switch_stream_handle_t *stream ) | |||
1601 | { | |||
1602 | return _find_user(cmd, session, stream, SWITCH_TRUE); | |||
1603 | } | |||
1604 | ||||
1605 | SWITCH_STANDARD_API(find_user_function)static switch_status_t find_user_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
1606 | { | |||
1607 | return _find_user(cmd, session, stream, SWITCH_FALSE); | |||
1608 | } | |||
1609 | ||||
1610 | SWITCH_STANDARD_API(xml_locate_function)static switch_status_t xml_locate_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream ) | |||
1611 | { | |||
1612 | switch_xml_t xml = NULL((void*)0), obj = NULL((void*)0); | |||
1613 | int argc; | |||
1614 | char *mydata = NULL((void*)0), *argv[4] = { 0 } ; | |||
1615 | char *section, *tag, *tag_attr_name, *tag_attr_val; | |||
1616 | switch_event_t *params = NULL((void*)0); | |||
1617 | char *xmlstr; | |||
1618 | char delim = ' '; | |||
1619 | const char *err = NULL((void*)0); | |||
1620 | ||||
1621 | stream_format format = { 0 }; | |||
1622 | set_format(&format, stream); | |||
1623 | if (format.api) { | |||
1624 | stream->write_function(stream, "Content-Type: text/xml\r\n\r\n"); | |||
1625 | cmd = format.query; | |||
1626 | delim = '/'; | |||
1627 | } | |||
1628 | ||||
1629 | if (!cmd) { | |||
1630 | err = "bad args"; | |||
1631 | goto end; | |||
1632 | } | |||
1633 | ||||
1634 | mydata = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))); | |||
1635 | switch_assert(mydata)((mydata) ? (void) (0) : __assert_fail ("mydata", "mod_commands.c" , 1635, __PRETTY_FUNCTION__)); | |||
1636 | ||||
1637 | argc = switch_separate_string(mydata, delim, argv, (sizeof(argv) / sizeof(argv[0]))); | |||
1638 | ||||
1639 | if (argc == 1 && argv[0] && !strcasecmp(argv[0], "root")) { | |||
1640 | const char *error; | |||
1641 | xml = switch_xml_open_root(0, &error); | |||
1642 | obj = xml; | |||
1643 | goto end; | |||
1644 | } | |||
1645 | ||||
1646 | if (argc != 1 && argc != 4) { | |||
1647 | err = "bad args"; | |||
1648 | goto end; | |||
1649 | } | |||
1650 | ||||
1651 | section = argv[0]; | |||
1652 | tag = argv[1]; | |||
1653 | tag_attr_name = argv[2]; | |||
1654 | tag_attr_val = argv[3]; | |||
1655 | ||||
1656 | switch_event_create(¶ms, SWITCH_EVENT_REQUEST_PARAMS)switch_event_create_subclass_detailed("mod_commands.c", (const char * )(const char *)__func__, 1656, ¶ms, SWITCH_EVENT_REQUEST_PARAMS , ((void*)0)); | |||
1657 | switch_assert(params)((params) ? (void) (0) : __assert_fail ("params", "mod_commands.c" , 1657, __PRETTY_FUNCTION__)); | |||
1658 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "section", section); | |||
1659 | ||||
1660 | if (tag) { | |||
1661 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "tag", tag); | |||
1662 | } | |||
1663 | ||||
1664 | if (tag_attr_name) { | |||
1665 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "tag_attr_name", tag_attr_name); | |||
1666 | } | |||
1667 | ||||
1668 | if (tag_attr_val) { | |||
1669 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "tag_attr_val", tag_attr_val); | |||
1670 | } | |||
1671 | ||||
1672 | if (switch_xml_locate(section, tag, tag_attr_name, tag_attr_val, &xml, &obj, params, SWITCH_FALSE) != SWITCH_STATUS_SUCCESS) { | |||
1673 | stream->write_function(stream, "can't find anything\n"); | |||
1674 | goto end; | |||
1675 | } | |||
1676 | ||||
1677 | end: | |||
1678 | if (err) { | |||
1679 | stream->write_function(stream, "-ERR %s\n", err); | |||
1680 | } | |||
1681 | ||||
1682 | if (obj) { | |||
1683 | xmlstr = switch_xml_toxml(obj, SWITCH_FALSE); | |||
1684 | switch_assert(xmlstr)((xmlstr) ? (void) (0) : __assert_fail ("xmlstr", "mod_commands.c" , 1684, __PRETTY_FUNCTION__)); | |||
1685 | stream->write_function(stream, "%s", xmlstr); | |||
1686 | free(xmlstr); | |||
1687 | } | |||
1688 | ||||
1689 | switch_xml_free(xml); | |||
1690 | switch_event_destroy(¶ms); | |||
1691 | free(mydata); | |||
1692 | ||||
1693 | return SWITCH_STATUS_SUCCESS; | |||
1694 | } | |||
1695 | ||||
1696 | SWITCH_STANDARD_API(reload_acl_function)static switch_status_t reload_acl_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream ) | |||
1697 | { | |||
1698 | const char *err; | |||
1699 | ||||
1700 | if (cmd && !strcasecmp(cmd, "reloadxml")) { | |||
1701 | stream->write_function(stream, "This option is deprecated, we now always reloadxml.\n"); | |||
1702 | } | |||
1703 | ||||
1704 | if (switch_xml_reload(&err) == SWITCH_STATUS_SUCCESS) { | |||
1705 | switch_load_network_lists(SWITCH_TRUE); | |||
1706 | stream->write_function(stream, "+OK acl reloaded\n"); | |||
1707 | } else { | |||
1708 | stream->write_function(stream, "-ERR [%s]\n", err); | |||
1709 | } | |||
1710 | ||||
1711 | return SWITCH_STATUS_SUCCESS; | |||
1712 | } | |||
1713 | ||||
1714 | SWITCH_STANDARD_API(acl_function)static switch_status_t acl_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
1715 | { | |||
1716 | int argc; | |||
1717 | char *mydata = NULL((void*)0), *argv[3]; | |||
1718 | ||||
1719 | if (!cmd) { | |||
1720 | goto error; | |||
1721 | } | |||
1722 | ||||
1723 | mydata = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))); | |||
1724 | switch_assert(mydata)((mydata) ? (void) (0) : __assert_fail ("mydata", "mod_commands.c" , 1724, __PRETTY_FUNCTION__)); | |||
1725 | ||||
1726 | argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | |||
1727 | ||||
1728 | if (argc < 2) { | |||
1729 | goto error; | |||
1730 | } | |||
1731 | ||||
1732 | if (switch_check_network_list_ip(argv[0], argv[1])switch_check_network_list_ip_token(argv[0], argv[1], ((void*) 0))) { | |||
1733 | stream->write_function(stream, "true"); | |||
1734 | goto ok; | |||
1735 | } | |||
1736 | ||||
1737 | error: | |||
1738 | ||||
1739 | stream->write_function(stream, "false"); | |||
1740 | ||||
1741 | ok: | |||
1742 | ||||
1743 | switch_safe_free(mydata)if (mydata) {free(mydata);mydata=((void*)0);}; | |||
1744 | ||||
1745 | return SWITCH_STATUS_SUCCESS; | |||
1746 | } | |||
1747 | ||||
1748 | SWITCH_STANDARD_API(replace_function)static switch_status_t replace_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
1749 | { | |||
1750 | char delim = '|'; | |||
1751 | char *mydata = NULL((void*)0), *argv[3], *d, *replace; | |||
1752 | int argc = 0; | |||
1753 | ||||
1754 | if (!cmd) { | |||
1755 | goto error; | |||
1756 | } | |||
1757 | ||||
1758 | mydata = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))); | |||
1759 | d = mydata; | |||
1760 | ||||
1761 | if (*d == 'm' && *(d + 1) == ':' && *(d + 2)) { | |||
1762 | char t = *(d + 2); | |||
1763 | ||||
1764 | switch (t) { | |||
1765 | case '|': | |||
1766 | case '~': | |||
1767 | case '/': | |||
1768 | d += 3; | |||
1769 | delim = t; | |||
1770 | break; | |||
1771 | default: | |||
1772 | break; | |||
1773 | } | |||
1774 | } | |||
1775 | ||||
1776 | argc = switch_separate_string(d, delim, argv, (sizeof(argv) / sizeof(argv[0]))); | |||
1777 | ||||
1778 | if (argc < 3) { | |||
1779 | goto error; | |||
1780 | } | |||
1781 | ||||
1782 | replace = switch_string_replace(argv[0], argv[1], argv[2]); | |||
1783 | stream->write_function(stream, "%s", replace); | |||
1784 | free(replace); | |||
1785 | ||||
1786 | goto ok; | |||
1787 | ||||
1788 | ||||
1789 | error: | |||
1790 | stream->write_function(stream, "-ERR"); | |||
1791 | ok: | |||
1792 | switch_safe_free(mydata)if (mydata) {free(mydata);mydata=((void*)0);}; | |||
1793 | return SWITCH_STATUS_SUCCESS; | |||
1794 | ||||
1795 | ||||
1796 | } | |||
1797 | ||||
1798 | SWITCH_STANDARD_API(regex_function)static switch_status_t regex_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
1799 | { | |||
1800 | switch_regex_t *re = NULL((void*)0); | |||
1801 | int ovector[30]; | |||
1802 | int argc; | |||
1803 | char *mydata = NULL((void*)0), *argv[4]; | |||
1804 | size_t len = 0; | |||
1805 | char *substituted = NULL((void*)0); | |||
1806 | int proceed = 0; | |||
1807 | char *d; | |||
1808 | char delim = '|'; | |||
1809 | ||||
1810 | if (!cmd) { | |||
1811 | goto error; | |||
1812 | } | |||
1813 | ||||
1814 | mydata = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))); | |||
1815 | switch_assert(mydata)((mydata) ? (void) (0) : __assert_fail ("mydata", "mod_commands.c" , 1815, __PRETTY_FUNCTION__)); | |||
1816 | ||||
1817 | d = mydata; | |||
1818 | ||||
1819 | if (*d == 'm' && *(d + 1) == ':' && *(d + 2)) { | |||
1820 | char t = *(d + 2); | |||
1821 | ||||
1822 | switch (t) { | |||
1823 | case '|': | |||
1824 | case '~': | |||
1825 | case '/': | |||
1826 | d += 3; | |||
1827 | delim = t; | |||
1828 | break; | |||
1829 | default: | |||
1830 | break; | |||
1831 | } | |||
1832 | } | |||
1833 | ||||
1834 | ||||
1835 | argc = switch_separate_string(d, delim, argv, (sizeof(argv) / sizeof(argv[0]))); | |||
1836 | ||||
1837 | if (argc < 2) { | |||
1838 | goto error; | |||
1839 | } | |||
1840 | ||||
1841 | proceed = switch_regex_perform(argv[0], argv[1], &re, ovector, sizeof(ovector) / sizeof(ovector[0])); | |||
1842 | ||||
1843 | if (argc > 2) { | |||
1844 | char *flags = ""; | |||
1845 | ||||
1846 | if (argc > 3) { | |||
1847 | flags = argv[3]; | |||
1848 | } | |||
1849 | ||||
1850 | if (proceed) { | |||
1851 | len = (strlen(argv[0]) + strlen(argv[2]) + 10) * proceed; | |||
1852 | substituted = malloc(len); | |||
1853 | switch_assert(substituted)((substituted) ? (void) (0) : __assert_fail ("substituted", "mod_commands.c" , 1853, __PRETTY_FUNCTION__)); | |||
1854 | memset(substituted, 0, len); | |||
1855 | switch_replace_char(argv[2], '%', '$', SWITCH_FALSE); | |||
1856 | switch_perform_substitution(re, proceed, argv[2], argv[0], substituted, len, ovector); | |||
1857 | ||||
1858 | stream->write_function(stream, "%s", substituted); | |||
1859 | free(substituted); | |||
1860 | } else { | |||
1861 | if (strchr(flags, 'n')(__extension__ (__builtin_constant_p ('n') && !__builtin_constant_p (flags) && ('n') == '\0' ? (char *) __rawmemchr (flags , 'n') : __builtin_strchr (flags, 'n')))) { | |||
1862 | stream->write_function(stream, "%s", ""); | |||
1863 | } else if (strchr(flags, 'b')(__extension__ (__builtin_constant_p ('b') && !__builtin_constant_p (flags) && ('b') == '\0' ? (char *) __rawmemchr (flags , 'b') : __builtin_strchr (flags, 'b')))) { | |||
1864 | stream->write_function(stream, "%s", "false"); | |||
1865 | } else { | |||
1866 | stream->write_function(stream, "%s", argv[0]); | |||
1867 | } | |||
1868 | } | |||
1869 | } else { | |||
1870 | stream->write_function(stream, proceed ? "true" : "false"); | |||
1871 | } | |||
1872 | ||||
1873 | goto ok; | |||
1874 | ||||
1875 | error: | |||
1876 | stream->write_function(stream, "-ERR"); | |||
1877 | ok: | |||
1878 | switch_regex_safe_free(re)if (re) { switch_regex_free(re); re = ((void*)0); }; | |||
1879 | switch_safe_free(mydata)if (mydata) {free(mydata);mydata=((void*)0);}; | |||
1880 | return SWITCH_STATUS_SUCCESS; | |||
1881 | } | |||
1882 | ||||
1883 | typedef enum { | |||
1884 | O_NONE, | |||
1885 | O_EQ, | |||
1886 | O_NE, | |||
1887 | O_GT, | |||
1888 | O_GE, | |||
1889 | O_LT, | |||
1890 | O_LE | |||
1891 | } o_t; | |||
1892 | ||||
1893 | SWITCH_STANDARD_API(cond_function)static switch_status_t cond_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
1894 | { | |||
1895 | int argc; | |||
1896 | char *mydata = NULL((void*)0), *argv[3]; | |||
1897 | char *expr; | |||
1898 | char *a, *b; | |||
1899 | double a_f = 0.0, b_f = 0.0; | |||
1900 | o_t o = O_NONE; | |||
1901 | int is_true = 0; | |||
1902 | char *p; | |||
1903 | ||||
1904 | if (!cmd) { | |||
1905 | goto error; | |||
1906 | } | |||
1907 | ||||
1908 | mydata = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))); | |||
1909 | switch_assert(mydata)((mydata) ? (void) (0) : __assert_fail ("mydata", "mod_commands.c" , 1909, __PRETTY_FUNCTION__)); | |||
1910 | ||||
1911 | if ((p = strchr(mydata, '?')(__extension__ (__builtin_constant_p ('?') && !__builtin_constant_p (mydata) && ('?') == '\0' ? (char *) __rawmemchr (mydata , '?') : __builtin_strchr (mydata, '?'))))) { | |||
1912 | *p = ':'; | |||
1913 | } else { | |||
1914 | goto error; | |||
1915 | } | |||
1916 | ||||
1917 | argc = switch_separate_string(mydata, ':', argv, (sizeof(argv) / sizeof(argv[0]))); | |||
1918 | ||||
1919 | if (! (argc >= 2 && argc <= 3)) { | |||
1920 | goto error; | |||
1921 | } | |||
1922 | ||||
1923 | a = argv[0]; | |||
1924 | while(*a == ' ' || *a == '\t') a++; | |||
1925 | ||||
1926 | if (*a == '\'') { | |||
1927 | if ((expr = switch_find_end_paren(a, '\'', '\''))) { | |||
1928 | a++; | |||
1929 | *expr++ = '\0'; | |||
1930 | } else { | |||
1931 | goto error; | |||
1932 | } | |||
1933 | } else { | |||
1934 | if ((expr = strchr(a, ' ')(__extension__ (__builtin_constant_p (' ') && !__builtin_constant_p (a) && (' ') == '\0' ? (char *) __rawmemchr (a, ' ') : __builtin_strchr (a, ' '))))) { | |||
1935 | *expr++ = '\0'; | |||
1936 | } else { | |||
1937 | expr = a; | |||
1938 | } | |||
1939 | } | |||
1940 | ||||
1941 | if (strspn(a, "!<>=")__extension__ ({ char __a0, __a1, __a2; (__builtin_constant_p ("!<>=") && ((size_t)(const void *)(("!<>=" ) + 1) - (size_t)(const void *)("!<>=") == 1) ? ((__builtin_constant_p (a) && ((size_t)(const void *)((a) + 1) - (size_t)(const void *)(a) == 1)) ? __builtin_strspn (a, "!<>=") : ((__a0 = ((const char *) ("!<>="))[0], __a0 == '\0') ? ((void ) (a), (size_t) 0) : ((__a1 = ((const char *) ("!<>=")) [1], __a1 == '\0') ? __strspn_c1 (a, __a0) : ((__a2 = ((const char *) ("!<>="))[2], __a2 == '\0') ? __strspn_c2 (a, __a0 , __a1) : (((const char *) ("!<>="))[3] == '\0' ? __strspn_c3 (a, __a0, __a1, __a2) : __builtin_strspn (a, "!<>="))) ))) : __builtin_strspn (a, "!<>=")); })) { | |||
1942 | expr = a; | |||
1943 | } | |||
1944 | ||||
1945 | if (expr == a) { | |||
1946 | a = ""; | |||
1947 | } | |||
1948 | ||||
1949 | while (*expr == ' ') expr++; | |||
1950 | ||||
1951 | while(expr && *expr) { | |||
1952 | switch(*expr) { | |||
1953 | case '!': | |||
1954 | case '<': | |||
1955 | case '>': | |||
1956 | case '=': | |||
1957 | goto done; | |||
1958 | default: | |||
1959 | expr++; | |||
1960 | break; | |||
1961 | } | |||
1962 | } | |||
1963 | ||||
1964 | done: | |||
1965 | ||||
1966 | switch(*expr) { | |||
1967 | case '!': | |||
1968 | *expr++ = '\0'; | |||
1969 | if (*expr == '=') { | |||
1970 | o = O_NE; | |||
1971 | *expr++ = '\0'; | |||
1972 | } | |||
1973 | break; | |||
1974 | ||||
1975 | case '>': | |||
1976 | *expr++ = '\0'; | |||
1977 | if (*expr == '=') { | |||
1978 | o = O_GE; | |||
1979 | *expr++ = '\0'; | |||
1980 | } else { | |||
1981 | o = O_GT; | |||
1982 | } | |||
1983 | break; | |||
1984 | ||||
1985 | case '<': | |||
1986 | *expr++ = '\0'; | |||
1987 | if (*expr == '=') { | |||
1988 | o = O_LE; | |||
1989 | *expr++ = '\0'; | |||
1990 | } else { | |||
1991 | o = O_LT; | |||
1992 | } | |||
1993 | break; | |||
1994 | ||||
1995 | case '=': | |||
1996 | *expr++ = '\0'; | |||
1997 | if (*expr == '=') { | |||
1998 | o = O_EQ; | |||
1999 | *expr++ = '\0'; | |||
2000 | } | |||
2001 | break; | |||
2002 | ||||
2003 | default: | |||
2004 | goto error; | |||
2005 | } | |||
2006 | ||||
2007 | ||||
2008 | if (o) { | |||
2009 | char *s_a = NULL((void*)0), *s_b = NULL((void*)0); | |||
2010 | int a_is_num, b_is_num; | |||
2011 | ||||
2012 | expr++; | |||
2013 | b = expr; | |||
2014 | ||||
2015 | s_a = switch_strip_spaces(a, SWITCH_TRUE); | |||
2016 | s_b = switch_strip_spaces(b, SWITCH_TRUE); | |||
2017 | ||||
2018 | ||||
2019 | a_is_num = switch_is_number(s_a); | |||
2020 | b_is_num = switch_is_number(s_b); | |||
2021 | ||||
2022 | a_f = a_is_num ? atof(s_a) : (float) strlen(s_a); | |||
2023 | b_f = b_is_num ? atof(s_b) : (float) strlen(s_b); | |||
2024 | ||||
2025 | switch (o) { | |||
2026 | case O_EQ: | |||
2027 | if (!a_is_num && !b_is_num) { | |||
2028 | is_true = !strcmp(s_a, s_b)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (s_a) && __builtin_constant_p (s_b) && (__s1_len = __builtin_strlen (s_a), __s2_len = __builtin_strlen (s_b), (!((size_t)(const void *)((s_a) + 1) - (size_t)(const void * )(s_a) == 1) || __s1_len >= 4) && (!((size_t)(const void *)((s_b) + 1) - (size_t)(const void *)(s_b) == 1) || __s2_len >= 4)) ? __builtin_strcmp (s_a, s_b) : (__builtin_constant_p (s_a) && ((size_t)(const void *)((s_a) + 1) - (size_t )(const void *)(s_a) == 1) && (__s1_len = __builtin_strlen (s_a), __s1_len < 4) ? (__builtin_constant_p (s_b) && ((size_t)(const void *)((s_b) + 1) - (size_t)(const void *)( s_b) == 1) ? __builtin_strcmp (s_a, s_b) : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (s_b); int __result = (((const unsigned char *) (const char * ) (s_a))[0] - __s2[0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) ( s_a))[1] - __s2[1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (s_a ))[2] - __s2[2]); if (__s1_len > 2 && __result == 0 ) __result = (((const unsigned char *) (const char *) (s_a))[ 3] - __s2[3]); } } __result; }))) : (__builtin_constant_p (s_b ) && ((size_t)(const void *)((s_b) + 1) - (size_t)(const void *)(s_b) == 1) && (__s2_len = __builtin_strlen ( s_b), __s2_len < 4) ? (__builtin_constant_p (s_a) && ((size_t)(const void *)((s_a) + 1) - (size_t)(const void *)( s_a) == 1) ? __builtin_strcmp (s_a, s_b) : (- (__extension__ ( { const unsigned char *__s2 = (const unsigned char *) (const char *) (s_a); int __result = (((const unsigned char *) (const char *) (s_b))[0] - __s2[0]); if (__s2_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) ( s_b))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (s_b ))[2] - __s2[2]); if (__s2_len > 2 && __result == 0 ) __result = (((const unsigned char *) (const char *) (s_b))[ 3] - __s2[3]); } } __result; })))) : __builtin_strcmp (s_a, s_b )))); }); | |||
2029 | } else { | |||
2030 | is_true = a_f == b_f; | |||
2031 | } | |||
2032 | break; | |||
2033 | case O_NE: | |||
2034 | if (!a_is_num && !b_is_num) { | |||
2035 | is_true = strcmp(s_a, s_b)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (s_a) && __builtin_constant_p (s_b) && (__s1_len = __builtin_strlen (s_a), __s2_len = __builtin_strlen (s_b), (!((size_t)(const void *)((s_a) + 1) - (size_t)(const void * )(s_a) == 1) || __s1_len >= 4) && (!((size_t)(const void *)((s_b) + 1) - (size_t)(const void *)(s_b) == 1) || __s2_len >= 4)) ? __builtin_strcmp (s_a, s_b) : (__builtin_constant_p (s_a) && ((size_t)(const void *)((s_a) + 1) - (size_t )(const void *)(s_a) == 1) && (__s1_len = __builtin_strlen (s_a), __s1_len < 4) ? (__builtin_constant_p (s_b) && ((size_t)(const void *)((s_b) + 1) - (size_t)(const void *)( s_b) == 1) ? __builtin_strcmp (s_a, s_b) : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (s_b); int __result = (((const unsigned char *) (const char * ) (s_a))[0] - __s2[0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) ( s_a))[1] - __s2[1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (s_a ))[2] - __s2[2]); if (__s1_len > 2 && __result == 0 ) __result = (((const unsigned char *) (const char *) (s_a))[ 3] - __s2[3]); } } __result; }))) : (__builtin_constant_p (s_b ) && ((size_t)(const void *)((s_b) + 1) - (size_t)(const void *)(s_b) == 1) && (__s2_len = __builtin_strlen ( s_b), __s2_len < 4) ? (__builtin_constant_p (s_a) && ((size_t)(const void *)((s_a) + 1) - (size_t)(const void *)( s_a) == 1) ? __builtin_strcmp (s_a, s_b) : (- (__extension__ ( { const unsigned char *__s2 = (const unsigned char *) (const char *) (s_a); int __result = (((const unsigned char *) (const char *) (s_b))[0] - __s2[0]); if (__s2_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) ( s_b))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (s_b ))[2] - __s2[2]); if (__s2_len > 2 && __result == 0 ) __result = (((const unsigned char *) (const char *) (s_b))[ 3] - __s2[3]); } } __result; })))) : __builtin_strcmp (s_a, s_b )))); }); | |||
2036 | } else { | |||
2037 | is_true = a_f != b_f; | |||
2038 | } | |||
2039 | break; | |||
2040 | case O_GT: | |||
2041 | is_true = a_f > b_f; | |||
2042 | break; | |||
2043 | case O_GE: | |||
2044 | is_true = a_f >= b_f; | |||
2045 | break; | |||
2046 | case O_LT: | |||
2047 | is_true = a_f < b_f; | |||
2048 | break; | |||
2049 | case O_LE: | |||
2050 | is_true = a_f <= b_f; | |||
2051 | break; | |||
2052 | default: | |||
2053 | break; | |||
2054 | } | |||
2055 | switch_safe_free(s_a)if (s_a) {free(s_a);s_a=((void*)0);}; | |||
2056 | switch_safe_free(s_b)if (s_b) {free(s_b);s_b=((void*)0);}; | |||
2057 | ||||
2058 | if ((argc == 2 && !is_true)) { | |||
2059 | stream->write_function(stream, ""); | |||
2060 | } else { | |||
2061 | stream->write_function(stream, "%s", is_true ? argv[1] : argv[2]); | |||
2062 | } | |||
2063 | goto ok; | |||
2064 | } | |||
2065 | ||||
2066 | error: | |||
2067 | stream->write_function(stream, "-ERR"); | |||
2068 | ok: | |||
2069 | ||||
2070 | switch_safe_free(mydata)if (mydata) {free(mydata);mydata=((void*)0);}; | |||
2071 | return SWITCH_STATUS_SUCCESS; | |||
2072 | } | |||
2073 | ||||
2074 | SWITCH_STANDARD_API(lan_addr_function)static switch_status_t lan_addr_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
2075 | { | |||
2076 | stream->write_function(stream, "%s", switch_is_lan_addr(cmd) ? "true" : "false"); | |||
2077 | return SWITCH_STATUS_SUCCESS; | |||
2078 | } | |||
2079 | ||||
2080 | SWITCH_STANDARD_API(status_function)static switch_status_t status_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
2081 | { | |||
2082 | switch_core_time_duration_t duration = { 0 }; | |||
2083 | int sps = 0, last_sps = 0, max_sps = 0, max_sps_fivemin = 0; | |||
2084 | int sessions_peak = 0, sessions_peak_fivemin = 0; /* Max Concurrent Sessions buffers */ | |||
2085 | switch_bool_t html = SWITCH_FALSE; /* shortcut to format.html */ | |||
2086 | char * nl = "\n"; /* shortcut to format.nl */ | |||
2087 | stream_format format = { 0 }; | |||
2088 | switch_size_t cur = 0, max = 0; | |||
2089 | ||||
2090 | set_format(&format, stream); | |||
2091 | ||||
2092 | if (format.api) { | |||
2093 | format.html = SWITCH_TRUE; | |||
2094 | format.nl = "<br>\n"; | |||
2095 | } | |||
2096 | ||||
2097 | if (format.html) { | |||
2098 | /* set flag to allow refresh of webpage if web request contained kv-pair refresh=xx */ | |||
2099 | switch_event_add_header_string(stream->param_event, SWITCH_STACK_BOTTOM, "HTTP-REFRESH", "true"); | |||
2100 | if (format.api) { | |||
2101 | /* "Overwrite" default "api" Content-Type: text/plain */ | |||
2102 | stream->write_function(stream, "Content-Type: text/html\r\n\r\n"); | |||
2103 | } | |||
2104 | } | |||
2105 | ||||
2106 | html = format.html; | |||
2107 | nl = format.nl; | |||
2108 | ||||
2109 | if (html) { | |||
2110 | /* don't bother cli with heading and timestamp */ | |||
2111 | stream->write_function(stream, "%sFreeSWITCH Status%s", "<h1>", "</h1>\n"); | |||
2112 | stream->write_function(stream, "%s%s", switch_event_get_header(stream->param_event,"Event-Date-Local")switch_event_get_header_idx(stream->param_event, "Event-Date-Local" , -1), nl); | |||
2113 | } | |||
2114 | ||||
2115 | ||||
2116 | switch_core_measure_time(switch_core_uptime(), &duration); | |||
2117 | stream->write_function(stream, | |||
2118 | "UP %u year%s, %u day%s, %u hour%s, %u minute%s, %u second%s, %u millisecond%s, %u microsecond%s%s", | |||
2119 | duration.yr, duration.yr == 1 ? "" : "s", duration.day, duration.day == 1 ? "" : "s", | |||
2120 | duration.hr, duration.hr == 1 ? "" : "s", duration.min, duration.min == 1 ? "" : "s", | |||
2121 | duration.sec, duration.sec == 1 ? "" : "s", duration.ms , duration.ms == 1 ? "" : "s", duration.mms, | |||
2122 | duration.mms == 1 ? "" : "s", nl); | |||
2123 | ||||
2124 | stream->write_function(stream, "FreeSWITCH (Version %s) is %s%s", switch_version_full_human(), | |||
2125 | switch_core_ready() ? "ready" : "not ready", nl); | |||
2126 | ||||
2127 | stream->write_function(stream, "%" SWITCH_SIZE_T_FMT"ld" " session(s) since startup%s", switch_core_session_id() - 1, nl); | |||
2128 | switch_core_session_ctl(SCSC_SESSIONS_PEAK, &sessions_peak); | |||
2129 | switch_core_session_ctl(SCSC_SESSIONS_PEAK_FIVEMIN, &sessions_peak_fivemin); | |||
2130 | stream->write_function(stream, "%d session(s) - peak %d, last 5min %d %s", switch_core_session_count(), sessions_peak, sessions_peak_fivemin, nl); | |||
2131 | switch_core_session_ctl(SCSC_LAST_SPS, &last_sps); | |||
2132 | switch_core_session_ctl(SCSC_SPS, &sps); | |||
2133 | switch_core_session_ctl(SCSC_SPS_PEAK, &max_sps); | |||
2134 | switch_core_session_ctl(SCSC_SPS_PEAK_FIVEMIN, &max_sps_fivemin); | |||
2135 | stream->write_function(stream, "%d session(s) per Sec out of max %d, peak %d, last 5min %d %s", last_sps, sps, max_sps, max_sps_fivemin, nl); | |||
2136 | stream->write_function(stream, "%d session(s) max%s", switch_core_session_limit(0), nl); | |||
2137 | stream->write_function(stream, "min idle cpu %0.2f/%0.2f%s", switch_core_min_idle_cpu(-1.0), switch_core_idle_cpu(), nl); | |||
2138 | ||||
2139 | if (switch_core_get_stacksizes(&cur, &max) == SWITCH_STATUS_SUCCESS) { stream->write_function(stream, "Current Stack Size/Max %ldK/%ldK\n", cur / 1024, max / 1024); | |||
2140 | } | |||
2141 | return SWITCH_STATUS_SUCCESS; | |||
2142 | } | |||
2143 | ||||
2144 | #define UPTIME_SYNTAX"[us|ms|s|m|h|d|microseconds|milliseconds|seconds|minutes|hours|days]" "[us|ms|s|m|h|d|microseconds|milliseconds|seconds|minutes|hours|days]" | |||
2145 | SWITCH_STANDARD_API(uptime_function)static switch_status_t uptime_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
2146 | { | |||
2147 | switch_time_t scale; | |||
2148 | ||||
2149 | if (zstr(cmd)_zstr(cmd)) { | |||
2150 | /* default to seconds */ | |||
2151 | scale = 1000000; | |||
2152 | } | |||
2153 | else if (!strcasecmp(cmd, "microseconds") || !strcasecmp(cmd, "us")) { | |||
2154 | scale = 1; | |||
2155 | } | |||
2156 | else if (!strcasecmp(cmd, "milliseconds") || !strcasecmp(cmd, "ms")) { | |||
2157 | scale = 1000; | |||
2158 | } | |||
2159 | else if (!strcasecmp(cmd, "seconds") || !strcasecmp(cmd, "s")) { | |||
2160 | scale = 1000000; | |||
2161 | } | |||
2162 | else if (!strcasecmp(cmd, "minutes") || !strcasecmp(cmd, "m")) { | |||
2163 | scale = 60000000; | |||
2164 | } | |||
2165 | else if (!strcasecmp(cmd, "hours") || !strcasecmp(cmd, "h")) { | |||
2166 | scale = 3600000000; | |||
2167 | } | |||
2168 | else if (!strcasecmp(cmd, "days") || !strcasecmp(cmd, "d")) { | |||
2169 | scale = 86400000000; | |||
2170 | } | |||
2171 | else { | |||
2172 | stream->write_function(stream, "-USAGE: %s\n", UPTIME_SYNTAX"[us|ms|s|m|h|d|microseconds|milliseconds|seconds|minutes|hours|days]"); | |||
2173 | return SWITCH_STATUS_SUCCESS; | |||
2174 | } | |||
2175 | ||||
2176 | stream->write_function(stream, "%u\n", switch_core_uptime() / scale); | |||
2177 | return SWITCH_STATUS_SUCCESS; | |||
2178 | } | |||
2179 | ||||
2180 | #define CTL_SYNTAX"[recover|send_sighup|hupall|pause [inbound|outbound]|resume [inbound|outbound]|shutdown [cancel|elegant|asap|now|restart]|sps|sps_peak_reset|sync_clock|sync_clock_when_idle|reclaim_mem|max_sessions|min_dtmf_duration [num]|max_dtmf_duration [num]|default_dtmf_duration [num]|min_idle_cpu|loglevel [level]|debug_level [level]]" "[recover|send_sighup|hupall|pause [inbound|outbound]|resume [inbound|outbound]|shutdown [cancel|elegant|asap|now|restart]|sps|sps_peak_reset|sync_clock|sync_clock_when_idle|reclaim_mem|max_sessions|min_dtmf_duration [num]|max_dtmf_duration [num]|default_dtmf_duration [num]|min_idle_cpu|loglevel [level]|debug_level [level]]" | |||
2181 | SWITCH_STANDARD_API(ctl_function)static switch_status_t ctl_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
2182 | { | |||
2183 | int argc; | |||
2184 | char *mydata, *argv[5]; | |||
2185 | int32_t arg = 0; | |||
2186 | ||||
2187 | if (zstr(cmd)_zstr(cmd)) { | |||
2188 | stream->write_function(stream, "-USAGE: %s\n", CTL_SYNTAX"[recover|send_sighup|hupall|pause [inbound|outbound]|resume [inbound|outbound]|shutdown [cancel|elegant|asap|now|restart]|sps|sps_peak_reset|sync_clock|sync_clock_when_idle|reclaim_mem|max_sessions|min_dtmf_duration [num]|max_dtmf_duration [num]|default_dtmf_duration [num]|min_idle_cpu|loglevel [level]|debug_level [level]]"); | |||
2189 | return SWITCH_STATUS_SUCCESS; | |||
2190 | } | |||
2191 | ||||
2192 | if ((mydata = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))))) { | |||
2193 | argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | |||
2194 | ||||
2195 | if (!strcasecmp(argv[0], "hupall")) { | |||
2196 | arg = 1; | |||
2197 | switch_core_session_ctl(SCSC_HUPALL, &arg); | |||
2198 | stream->write_function(stream, "+OK\n"); | |||
2199 | } else if (!strcasecmp(argv[0], "recover")) { | |||
2200 | int r = switch_core_session_ctl(SCSC_RECOVER, argv[1]); | |||
2201 | if (r < 0){ | |||
2202 | stream->write_function(stream, "+OK flushed\n"); | |||
2203 | } else { | |||
2204 | stream->write_function(stream, "+OK %d session(s) recovered in total\n", r); | |||
2205 | } | |||
2206 | } else if (!strcasecmp(argv[0], "flush_db_handles")) { | |||
2207 | switch_core_session_ctl(SCSC_FLUSH_DB_HANDLES, NULL((void*)0)); | |||
2208 | stream->write_function(stream, "+OK\n"); | |||
2209 | } else if (!strcasecmp(argv[0], "pause")) { | |||
2210 | switch_session_ctl_t command = SCSC_PAUSE_ALL; | |||
2211 | arg = 1; | |||
2212 | if (argv[1]) { | |||
2213 | if (!strcasecmp(argv[1], "inbound")) { | |||
2214 | command = SCSC_PAUSE_INBOUND; | |||
2215 | } else if (!strcasecmp(argv[1], "outbound")) { | |||
2216 | command = SCSC_PAUSE_OUTBOUND; | |||
2217 | } | |||
2218 | } | |||
2219 | switch_core_session_ctl(command, &arg); | |||
2220 | stream->write_function(stream, "+OK\n"); | |||
2221 | } else if (!strcasecmp(argv[0], "send_sighup")) { | |||
2222 | arg = 1; | |||
2223 | switch_core_session_ctl(SCSC_SEND_SIGHUP, &arg); | |||
2224 | stream->write_function(stream, "+OK\n"); | |||
2225 | } else if (!strcasecmp(argv[0], "resume")) { | |||
2226 | switch_session_ctl_t command = SCSC_PAUSE_ALL; | |||
2227 | arg = 0; | |||
2228 | if (argv[1]) { | |||
2229 | if (!strcasecmp(argv[1], "inbound")) { | |||
2230 | command = SCSC_PAUSE_INBOUND; | |||
2231 | } else if (!strcasecmp(argv[1], "outbound")) { | |||
2232 | command = SCSC_PAUSE_OUTBOUND; | |||
2233 | } | |||
2234 | } | |||
2235 | switch_core_session_ctl(command, &arg); | |||
2236 | stream->write_function(stream, "+OK\n"); | |||
2237 | } else if (!strcasecmp(argv[0], "calibrate_clock")) { | |||
2238 | switch_core_session_ctl(SCSC_CALIBRATE_CLOCK, NULL((void*)0)); | |||
2239 | stream->write_function(stream, "+OK\n"); | |||
2240 | } else if (!strcasecmp(argv[0], "crash")) { | |||
2241 | switch_core_session_ctl(SCSC_CRASH, NULL((void*)0)); | |||
2242 | stream->write_function(stream, "+OK\n"); | |||
2243 | } else if (!strcasecmp(argv[0], "verbose_events")) { | |||
2244 | arg = -1; | |||
2245 | if (argv[1]) { | |||
2246 | arg = switch_true(argv[1]); | |||
2247 | } | |||
2248 | ||||
2249 | switch_core_session_ctl(SCSC_VERBOSE_EVENTS, &arg); | |||
2250 | ||||
2251 | stream->write_function(stream, "+OK verbose_events is %s \n", arg ? "on" : "off"); | |||
2252 | } else if (!strcasecmp(argv[0], "api_expansion")) { | |||
2253 | arg = -1; | |||
2254 | if (argv[1]) { | |||
2255 | arg = switch_true(argv[1]); | |||
2256 | } | |||
2257 | ||||
2258 | switch_core_session_ctl(SCSC_API_EXPANSION, &arg); | |||
2259 | ||||
2260 | stream->write_function(stream, "+OK api_expansion is %s \n", arg ? "on" : "off"); | |||
2261 | } else if (!strcasecmp(argv[0], "threaded_system_exec")) { | |||
2262 | arg = -1; | |||
2263 | if (argv[1]) { | |||
2264 | arg = switch_true(argv[1]); | |||
2265 | } | |||
2266 | ||||
2267 | switch_core_session_ctl(SCSC_THREADED_SYSTEM_EXEC, &arg); | |||
2268 | ||||
2269 | stream->write_function(stream, "+OK threaded_system_exec is %s \n", arg ? "true" : "false"); | |||
2270 | ||||
2271 | } else if (!strcasecmp(argv[0], "save_history")) { | |||
2272 | switch_core_session_ctl(SCSC_SAVE_HISTORY, NULL((void*)0)); | |||
2273 | stream->write_function(stream, "+OK\n"); | |||
2274 | } else if (!strcasecmp(argv[0], "pause_check")) { | |||
2275 | switch_session_ctl_t command = SCSC_PAUSE_CHECK; | |||
2276 | if (argv[1]) { | |||
2277 | if (!strcasecmp(argv[1], "inbound")) { | |||
2278 | command = SCSC_PAUSE_INBOUND_CHECK; | |||
2279 | } else if (!strcasecmp(argv[1], "outbound")) { | |||
2280 | command = SCSC_PAUSE_OUTBOUND_CHECK; | |||
2281 | } | |||
2282 | } | |||
2283 | switch_core_session_ctl(command, &arg); | |||
2284 | stream->write_function(stream, arg ? "true" : "false"); | |||
2285 | } else if (!strcasecmp(argv[0], "ready_check")) { | |||
2286 | switch_core_session_ctl(SCSC_READY_CHECK, &arg); | |||
2287 | stream->write_function(stream, arg ? "true" : "false"); | |||
2288 | } else if (!strcasecmp(argv[0], "shutdown_check")) { | |||
2289 | switch_core_session_ctl(SCSC_SHUTDOWN_CHECK, &arg); | |||
2290 | stream->write_function(stream, arg ? "true" : "false"); | |||
2291 | } else if (!strcasecmp(argv[0], "shutdown")) { | |||
2292 | switch_session_ctl_t command = SCSC_SHUTDOWN; | |||
2293 | int x = 0; | |||
2294 | arg = 0; | |||
2295 | for (x = 1; x < 5; x++) { | |||
2296 | if (argv[x]) { | |||
2297 | if (!strcasecmp(argv[x], "cancel")) { | |||
2298 | arg = 0; | |||
2299 | command = SCSC_CANCEL_SHUTDOWN; | |||
2300 | break; | |||
2301 | } else if (!strcasecmp(argv[x], "elegant")) { | |||
2302 | command = SCSC_SHUTDOWN_ELEGANT; | |||
2303 | } else if (!strcasecmp(argv[x], "now")) { | |||
2304 | command = SCSC_SHUTDOWN_NOW; | |||
2305 | } else if (!strcasecmp(argv[x], "asap")) { | |||
2306 | command = SCSC_SHUTDOWN_ASAP; | |||
2307 | } else if (!strcasecmp(argv[x], "reincarnate") | |||
2308 | && (x+1 < argc) && argv[x+1] && !strcasecmp(argv[x+1], "now")) { | |||
2309 | ++x; | |||
2310 | command = SCSC_REINCARNATE_NOW; | |||
2311 | } else if (!strcasecmp(argv[x], "restart")) { | |||
2312 | arg = 1; | |||
2313 | } | |||
2314 | } else { | |||
2315 | break; | |||
2316 | } | |||
2317 | } | |||
2318 | switch_core_session_ctl(command, &arg); | |||
2319 | stream->write_function(stream, "+OK\n"); | |||
2320 | ||||
2321 | } else if (!strcasecmp(argv[0], "debug_pool")) { | |||
2322 | switch_core_session_debug_pool(stream); | |||
2323 | ||||
2324 | } else if (!strcasecmp(argv[0], "debug_sql")) { | |||
2325 | int x = 0; | |||
2326 | switch_core_session_ctl(SCSC_DEBUG_SQL, &x); | |||
2327 | stream->write_function(stream, "+OK SQL DEBUG [%s]\n", x ? "on" : "off"); | |||
2328 | ||||
2329 | } else if (!strcasecmp(argv[0], "sql")) { | |||
2330 | if (argv[1]) { | |||
2331 | int x = 0; | |||
2332 | if (!strcasecmp(argv[1], "start")) { | |||
2333 | x = 1; | |||
2334 | } | |||
2335 | switch_core_session_ctl(SCSC_SQL, &x); | |||
2336 | stream->write_function(stream, "+OK\n"); | |||
2337 | } | |||
2338 | ||||
2339 | } else if (!strcasecmp(argv[0], "reclaim_mem")) { | |||
2340 | switch_core_session_ctl(SCSC_RECLAIM, &arg); | |||
2341 | stream->write_function(stream, "+OK\n"); | |||
2342 | } else if (!strcasecmp(argv[0], "max_sessions")) { | |||
2343 | if (argc > 1) { | |||
2344 | arg = atoi(argv[1]); | |||
2345 | } | |||
2346 | switch_core_session_ctl(SCSC_MAX_SESSIONS, &arg); | |||
2347 | stream->write_function(stream, "+OK max sessions: %d\n", arg); | |||
2348 | } else if (!strcasecmp(argv[0], "min_idle_cpu")) { | |||
2349 | double d = -1; | |||
2350 | ||||
2351 | if (argc > 1) { | |||
2352 | d = atof(argv[1]); | |||
2353 | } | |||
2354 | ||||
2355 | switch_core_session_ctl(SCSC_MIN_IDLE_CPU, &d); | |||
2356 | ||||
2357 | if (d) { | |||
2358 | stream->write_function(stream, "+OK min idle cpu: %0.2f%\n", d); | |||
2359 | } else { | |||
2360 | stream->write_function(stream, "+OK min idle cpu: DISABLED\n", d); | |||
2361 | } | |||
2362 | ||||
2363 | ||||
2364 | } else if (!strcasecmp(argv[0], "max_dtmf_duration")) { | |||
2365 | if (argc > 1) { | |||
2366 | arg = atoi(argv[1]); | |||
2367 | } | |||
2368 | switch_core_session_ctl(SCSC_MAX_DTMF_DURATION, &arg); | |||
2369 | stream->write_function(stream, "+OK max dtmf duration: %d\n", arg); | |||
2370 | } else if (!strcasecmp(argv[0], "min_dtmf_duration")) { | |||
2371 | if (argc > 1) { | |||
2372 | arg = atoi(argv[1]); | |||
2373 | } | |||
2374 | switch_core_session_ctl(SCSC_MIN_DTMF_DURATION, &arg); | |||
2375 | stream->write_function(stream, "+OK min dtmf duration: %d\n", arg); | |||
2376 | } else if (!strcasecmp(argv[0], "default_dtmf_duration")) { | |||
2377 | if (argc > 1) { | |||
2378 | arg = atoi(argv[1]); | |||
2379 | } | |||
2380 | switch_core_session_ctl(SCSC_DEFAULT_DTMF_DURATION, &arg); | |||
2381 | stream->write_function(stream, "+OK default dtmf duration: %d\n", arg); | |||
2382 | } else if (!strcasecmp(argv[0], "loglevel")) { | |||
2383 | if (argc > 1) { | |||
2384 | if (*argv[1] > 47 && *argv[1] < 58) { | |||
2385 | arg = atoi(argv[1]); | |||
2386 | } else { | |||
2387 | arg = switch_log_str2level(argv[1]); | |||
2388 | } | |||
2389 | } else { | |||
2390 | arg = -1; | |||
2391 | } | |||
2392 | ||||
2393 | if (arg == SWITCH_LOG_INVALID) { | |||
2394 | stream->write_function(stream, "-ERR syntax error, log level not set!\n"); | |||
2395 | } else { | |||
2396 | switch_core_session_ctl(SCSC_LOGLEVEL, &arg); | |||
2397 | stream->write_function(stream, "+OK log level: %s [%d]\n", switch_log_level2str(arg), arg); | |||
2398 | } | |||
2399 | } else if (!strcasecmp(argv[0], "debug_level")) { | |||
2400 | if (argc > 1) { | |||
2401 | arg = atoi(argv[1]); | |||
2402 | } else { | |||
2403 | arg = -1; | |||
2404 | } | |||
2405 | ||||
2406 | switch_core_session_ctl(SCSC_DEBUG_LEVEL, &arg); | |||
2407 | stream->write_function(stream, "+OK DEBUG level: %d\n", arg); | |||
2408 | ||||
2409 | } else if (!strcasecmp(argv[0], "sps_peak_reset")) { | |||
2410 | arg = -1; | |||
2411 | switch_core_session_ctl(SCSC_SPS_PEAK, &arg); | |||
2412 | stream->write_function(stream, "+OK max sessions per second counter reset\n"); | |||
2413 | } else if (!strcasecmp(argv[0], "last_sps")) { | |||
2414 | switch_core_session_ctl(SCSC_LAST_SPS, &arg); | |||
2415 | stream->write_function(stream, "+OK last sessions per second: %d\n", arg); | |||
2416 | } else if (!strcasecmp(argv[0], "sps")) { | |||
2417 | if (argc > 1) { | |||
2418 | arg = atoi(argv[1]); | |||
2419 | } else { | |||
2420 | arg = 0; | |||
2421 | } | |||
2422 | switch_core_session_ctl(SCSC_SPS, &arg); | |||
2423 | stream->write_function(stream, "+OK sessions per second: %d\n", arg); | |||
2424 | } else if (!strcasecmp(argv[0], "sync_clock")) { | |||
2425 | arg = 0; | |||
2426 | switch_core_session_ctl(SCSC_SYNC_CLOCK, &arg); | |||
2427 | stream->write_function(stream, "+OK clock synchronized\n"); | |||
2428 | } else if (!strcasecmp(argv[0], "sync_clock_when_idle")) { | |||
2429 | arg = 0; | |||
2430 | switch_core_session_ctl(SCSC_SYNC_CLOCK_WHEN_IDLE, &arg); | |||
2431 | if (arg) { | |||
2432 | stream->write_function(stream, "+OK clock synchronized\n"); | |||
2433 | } else { | |||
2434 | stream->write_function(stream, "+OK clock will synchronize when there are no more calls\n"); | |||
2435 | } | |||
2436 | } else { | |||
2437 | stream->write_function(stream, "-ERR Invalid command\nUSAGE: fsctl %s\n", CTL_SYNTAX"[recover|send_sighup|hupall|pause [inbound|outbound]|resume [inbound|outbound]|shutdown [cancel|elegant|asap|now|restart]|sps|sps_peak_reset|sync_clock|sync_clock_when_idle|reclaim_mem|max_sessions|min_dtmf_duration [num]|max_dtmf_duration [num]|default_dtmf_duration [num]|min_idle_cpu|loglevel [level]|debug_level [level]]"); | |||
2438 | goto end; | |||
2439 | } | |||
2440 | ||||
2441 | end: | |||
2442 | free(mydata); | |||
2443 | } else { | |||
2444 | stream->write_function(stream, "-ERR Memory error\n"); | |||
2445 | } | |||
2446 | ||||
2447 | return SWITCH_STATUS_SUCCESS; | |||
2448 | } | |||
2449 | ||||
2450 | #define LOAD_SYNTAX"<mod_name>" "<mod_name>" | |||
2451 | SWITCH_STANDARD_API(load_function)static switch_status_t load_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
2452 | { | |||
2453 | const char *err; | |||
2454 | ||||
2455 | if (zstr(cmd)_zstr(cmd)) { | |||
2456 | stream->write_function(stream, "-USAGE: %s\n", LOAD_SYNTAX"<mod_name>"); | |||
2457 | return SWITCH_STATUS_SUCCESS; | |||
2458 | } | |||
2459 | ||||
2460 | switch_mutex_lock(reload_mutex); | |||
2461 | ||||
2462 | if (switch_xml_reload(&err) == SWITCH_STATUS_SUCCESS) { | |||
2463 | stream->write_function(stream, "+OK Reloading XML\n"); | |||
2464 | } | |||
2465 | ||||
2466 | if (switch_loadable_module_load_module((char *) SWITCH_GLOBAL_dirs.mod_dir, (char *) cmd, SWITCH_TRUE, &err) == SWITCH_STATUS_SUCCESS) { | |||
2467 | stream->write_function(stream, "+OK\n"); | |||
2468 | } else { | |||
2469 | stream->write_function(stream, "-ERR [%s]\n", err); | |||
2470 | } | |||
2471 | ||||
2472 | switch_mutex_unlock(reload_mutex); | |||
2473 | ||||
2474 | return SWITCH_STATUS_SUCCESS; | |||
2475 | } | |||
2476 | ||||
2477 | #define UNLOAD_SYNTAX"[-f] <mod_name>" "[-f] <mod_name>" | |||
2478 | SWITCH_STANDARD_API(unload_function)static switch_status_t unload_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
2479 | { | |||
2480 | const char *err; | |||
2481 | switch_bool_t force = SWITCH_FALSE; | |||
2482 | const char *p = cmd; | |||
2483 | ||||
2484 | if (zstr(cmd)_zstr(cmd)) { | |||
2485 | stream->write_function(stream, "-USAGE: %s\n", UNLOAD_SYNTAX"[-f] <mod_name>"); | |||
2486 | return SWITCH_STATUS_SUCCESS; | |||
2487 | } | |||
2488 | ||||
2489 | ||||
2490 | if (*p == '-') { | |||
2491 | p++; | |||
2492 | while (p && *p) { | |||
2493 | switch (*p) { | |||
2494 | case ' ': | |||
2495 | cmd = p + 1; | |||
2496 | goto end; | |||
2497 | case 'f': | |||
2498 | force = SWITCH_TRUE; | |||
2499 | break; | |||
2500 | default: | |||
2501 | break; | |||
2502 | } | |||
2503 | p++; | |||
2504 | } | |||
2505 | } | |||
2506 | end: | |||
2507 | ||||
2508 | if (zstr(cmd)_zstr(cmd)) { | |||
2509 | stream->write_function(stream, "-USAGE: %s\n", UNLOAD_SYNTAX"[-f] <mod_name>"); | |||
2510 | return SWITCH_STATUS_SUCCESS; | |||
2511 | } | |||
2512 | ||||
2513 | switch_mutex_lock(reload_mutex); | |||
2514 | ||||
2515 | if (switch_loadable_module_unload_module((char *) SWITCH_GLOBAL_dirs.mod_dir, (char *) cmd, force, &err) == SWITCH_STATUS_SUCCESS) { | |||
2516 | stream->write_function(stream, "+OK\n"); | |||
2517 | } else { | |||
2518 | stream->write_function(stream, "-ERR [%s]\n", err); | |||
2519 | } | |||
2520 | ||||
2521 | switch_mutex_unlock(reload_mutex); | |||
2522 | ||||
2523 | return SWITCH_STATUS_SUCCESS; | |||
2524 | } | |||
2525 | ||||
2526 | SWITCH_STANDARD_API(reload_function)static switch_status_t reload_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
2527 | { | |||
2528 | const char *err; | |||
2529 | switch_bool_t force = SWITCH_FALSE; | |||
2530 | const char *p = cmd; | |||
2531 | ||||
2532 | if (zstr(cmd)_zstr(cmd)) { | |||
2533 | stream->write_function(stream, "-USAGE: %s\n", UNLOAD_SYNTAX"[-f] <mod_name>"); | |||
2534 | return SWITCH_STATUS_SUCCESS; | |||
2535 | } | |||
2536 | ||||
2537 | if (*p == '-') { | |||
2538 | p++; | |||
2539 | while (p && *p) { | |||
2540 | switch (*p) { | |||
2541 | case ' ': | |||
2542 | cmd = p + 1; | |||
2543 | goto end; | |||
2544 | case 'f': | |||
2545 | force = SWITCH_TRUE; | |||
2546 | break; | |||
2547 | default: | |||
2548 | break; | |||
2549 | } | |||
2550 | p++; | |||
2551 | } | |||
2552 | } | |||
2553 | end: | |||
2554 | ||||
2555 | if (zstr(cmd)_zstr(cmd)) { | |||
2556 | stream->write_function(stream, "-USAGE: %s\n", UNLOAD_SYNTAX"[-f] <mod_name>"); | |||
2557 | return SWITCH_STATUS_SUCCESS; | |||
2558 | } | |||
2559 | ||||
2560 | switch_mutex_lock(reload_mutex); | |||
2561 | ||||
2562 | if (switch_xml_reload(&err) == SWITCH_STATUS_SUCCESS) { | |||
2563 | stream->write_function(stream, "+OK Reloading XML\n"); | |||
2564 | } | |||
2565 | ||||
2566 | if (switch_loadable_module_unload_module((char *) SWITCH_GLOBAL_dirs.mod_dir, (char *) cmd, force, &err) == SWITCH_STATUS_SUCCESS) { | |||
2567 | stream->write_function(stream, "+OK module unloaded\n"); | |||
2568 | } else { | |||
2569 | stream->write_function(stream, "-ERR unloading module [%s]\n", err); | |||
2570 | } | |||
2571 | ||||
2572 | if (switch_loadable_module_load_module((char *) SWITCH_GLOBAL_dirs.mod_dir, (char *) cmd, SWITCH_TRUE, &err) == SWITCH_STATUS_SUCCESS) { | |||
2573 | stream->write_function(stream, "+OK module loaded\n"); | |||
2574 | } else { | |||
2575 | stream->write_function(stream, "-ERR loading module [%s]\n", err); | |||
2576 | } | |||
2577 | ||||
2578 | switch_mutex_unlock(reload_mutex); | |||
2579 | ||||
2580 | return SWITCH_STATUS_SUCCESS; | |||
2581 | } | |||
2582 | ||||
2583 | SWITCH_STANDARD_API(reload_xml_function)static switch_status_t reload_xml_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream ) | |||
2584 | { | |||
2585 | const char *err = ""; | |||
2586 | ||||
2587 | switch_xml_reload(&err); | |||
2588 | stream->write_function(stream, "+OK [%s]\n", err); | |||
2589 | ||||
2590 | return SWITCH_STATUS_SUCCESS; | |||
2591 | } | |||
2592 | ||||
2593 | #define KILL_SYNTAX"<uuid> [cause]" "<uuid> [cause]" | |||
2594 | SWITCH_STANDARD_API(kill_function)static switch_status_t kill_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
2595 | { | |||
2596 | char *mycmd = NULL((void*)0), *kcause = NULL((void*)0); | |||
2597 | switch_call_cause_t cause = SWITCH_CAUSE_NORMAL_CLEARING; | |||
2598 | ||||
2599 | if (zstr(cmd)_zstr(cmd) || !(mycmd = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))))) { | |||
2600 | stream->write_function(stream, "-USAGE: %s\n", KILL_SYNTAX"<uuid> [cause]"); | |||
2601 | return SWITCH_STATUS_SUCCESS; | |||
2602 | } | |||
2603 | ||||
2604 | if ((kcause = strchr(mycmd, ' ')(__extension__ (__builtin_constant_p (' ') && !__builtin_constant_p (mycmd) && (' ') == '\0' ? (char *) __rawmemchr (mycmd , ' ') : __builtin_strchr (mycmd, ' '))))) { | |||
2605 | *kcause++ = '\0'; | |||
2606 | if (!zstr(kcause)_zstr(kcause)) { | |||
2607 | cause = switch_channel_str2cause(kcause); | |||
2608 | } | |||
2609 | } | |||
2610 | ||||
2611 | if (switch_ivr_kill_uuid(mycmd, cause) != SWITCH_STATUS_SUCCESS) { | |||
2612 | stream->write_function(stream, "-ERR No such channel!\n"); | |||
2613 | } else { | |||
2614 | stream->write_function(stream, "+OK\n"); | |||
2615 | } | |||
2616 | ||||
2617 | switch_safe_free(mycmd)if (mycmd) {free(mycmd);mycmd=((void*)0);}; | |||
2618 | return SWITCH_STATUS_SUCCESS; | |||
2619 | } | |||
2620 | ||||
2621 | #define OUTGOING_ANSWER_SYNTAX"<uuid>" "<uuid>" | |||
2622 | SWITCH_STANDARD_API(outgoing_answer_function)static switch_status_t outgoing_answer_function ( const char * cmd, switch_core_session_t *session, switch_stream_handle_t * stream) | |||
2623 | { | |||
2624 | switch_core_session_t *outgoing_session = NULL((void*)0); | |||
2625 | char *mycmd = NULL((void*)0); | |||
2626 | ||||
2627 | if (zstr(cmd)_zstr(cmd) || !(mycmd = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))))) { | |||
2628 | stream->write_function(stream, "-USAGE: %s\n", OUTGOING_ANSWER_SYNTAX"<uuid>"); | |||
2629 | return SWITCH_STATUS_SUCCESS; | |||
2630 | } | |||
2631 | ||||
2632 | if (zstr(mycmd)_zstr(mycmd) || !(outgoing_session = switch_core_session_locate(mycmd)switch_core_session_perform_locate(mycmd, "mod_commands.c", ( const char *)__func__, 2632))) { | |||
2633 | stream->write_function(stream, "-ERR No such channel!\n"); | |||
2634 | } else { | |||
2635 | switch_channel_t *channel = switch_core_session_get_channel(outgoing_session); | |||
2636 | if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND) { | |||
2637 | switch_channel_mark_answered(channel)switch_channel_perform_mark_answered(channel, "mod_commands.c" , (const char *)__func__, 2637); | |||
2638 | stream->write_function(stream, "+OK\n"); | |||
2639 | } else { | |||
2640 | stream->write_function(stream, "-ERR Not an outbound channel!\n"); | |||
2641 | } | |||
2642 | switch_core_session_rwunlock(outgoing_session); | |||
2643 | } | |||
2644 | ||||
2645 | switch_safe_free(mycmd)if (mycmd) {free(mycmd);mycmd=((void*)0);}; | |||
2646 | return SWITCH_STATUS_SUCCESS; | |||
2647 | } | |||
2648 | ||||
2649 | #define PREPROCESS_SYNTAX"<>" "<>" | |||
2650 | SWITCH_STANDARD_API(preprocess_function)static switch_status_t preprocess_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream ) | |||
2651 | { | |||
2652 | switch_core_session_t *ksession = NULL((void*)0); | |||
2653 | char *mycmd = NULL((void*)0), *argv[3] = { 0 }; | |||
2654 | int argc = 0; | |||
2655 | ||||
2656 | if (zstr(cmd)_zstr(cmd) || !(mycmd = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))))) { | |||
2657 | goto usage; | |||
2658 | } | |||
2659 | ||||
2660 | argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | |||
2661 | ||||
2662 | if (argc < 2) { | |||
2663 | goto usage; | |||
2664 | } | |||
2665 | ||||
2666 | if (!(ksession = switch_core_session_locate(argv[0])switch_core_session_perform_locate(argv[0], "mod_commands.c", (const char *)__func__, 2666))) { | |||
2667 | stream->write_function(stream, "-ERR No such channel!\n"); | |||
2668 | goto done; | |||
2669 | } else { | |||
2670 | switch_ivr_preprocess_session(ksession, (char *) argv[1]); | |||
2671 | switch_core_session_rwunlock(ksession); | |||
2672 | stream->write_function(stream, "+OK\n"); | |||
2673 | goto done; | |||
2674 | } | |||
2675 | ||||
2676 | usage: | |||
2677 | stream->write_function(stream, "-USAGE: %s\n", PREPROCESS_SYNTAX"<>"); | |||
2678 | ||||
2679 | done: | |||
2680 | switch_safe_free(mycmd)if (mycmd) {free(mycmd);mycmd=((void*)0);}; | |||
2681 | return SWITCH_STATUS_SUCCESS; | |||
2682 | } | |||
2683 | ||||
2684 | #define PARK_SYNTAX"<uuid>" "<uuid>" | |||
2685 | SWITCH_STANDARD_API(park_function)static switch_status_t park_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
2686 | { | |||
2687 | switch_core_session_t *ksession = NULL((void*)0); | |||
2688 | ||||
2689 | if (!cmd) { | |||
2690 | stream->write_function(stream, "-USAGE: %s\n", PARK_SYNTAX"<uuid>"); | |||
2691 | } else if ((ksession = switch_core_session_locate(cmd)switch_core_session_perform_locate(cmd, "mod_commands.c", (const char *)__func__, 2691))) { | |||
2692 | switch_ivr_park_session(ksession); | |||
2693 | switch_core_session_rwunlock(ksession); | |||
2694 | stream->write_function(stream, "+OK\n"); | |||
2695 | } else { | |||
2696 | stream->write_function(stream, "-ERR No such channel!\n"); | |||
2697 | } | |||
2698 | ||||
2699 | return SWITCH_STATUS_SUCCESS; | |||
2700 | } | |||
2701 | ||||
2702 | #define TRANSFER_SYNTAX"<uuid> [-bleg|-both] <dest-exten> [<dialplan>] [<context>]" "<uuid> [-bleg|-both] <dest-exten> [<dialplan>] [<context>]" | |||
2703 | SWITCH_STANDARD_API(transfer_function)static switch_status_t transfer_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
2704 | { | |||
2705 | switch_core_session_t *tsession = NULL((void*)0), *other_session = NULL((void*)0); | |||
2706 | char *mycmd = NULL((void*)0), *argv[5] = { 0 }; | |||
2707 | int argc = 0; | |||
2708 | char *tuuid, *dest, *dp, *context, *arg = NULL((void*)0); | |||
2709 | ||||
2710 | if (zstr(cmd)_zstr(cmd) || !(mycmd = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))))) { | |||
2711 | stream->write_function(stream, "-USAGE: %s\n", TRANSFER_SYNTAX"<uuid> [-bleg|-both] <dest-exten> [<dialplan>] [<context>]"); | |||
2712 | return SWITCH_STATUS_SUCCESS; | |||
2713 | } | |||
2714 | ||||
2715 | argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | |||
2716 | if (argc < 2 || argc > 5) { | |||
2717 | stream->write_function(stream, "-USAGE: %s\n", TRANSFER_SYNTAX"<uuid> [-bleg|-both] <dest-exten> [<dialplan>] [<context>]"); | |||
2718 | goto done; | |||
2719 | } | |||
2720 | ||||
2721 | tuuid = argv[0]; | |||
2722 | dest = argv[1]; | |||
2723 | dp = argv[2]; | |||
2724 | context = argv[3]; | |||
2725 | ||||
2726 | if (zstr(tuuid)_zstr(tuuid) || !(tsession = switch_core_session_locate(tuuid)switch_core_session_perform_locate(tuuid, "mod_commands.c", ( const char *)__func__, 2726))) { | |||
2727 | stream->write_function(stream, "-ERR No such channel!\n"); | |||
2728 | goto done; | |||
2729 | } | |||
2730 | ||||
2731 | if (*dest == '-') { | |||
2732 | arg = dest; | |||
2733 | dest = argv[2]; | |||
2734 | dp = argv[3]; | |||
2735 | context = argv[4]; | |||
2736 | } | |||
2737 | ||||
2738 | if (arg) { | |||
2739 | switch_channel_t *channel = switch_core_session_get_channel(tsession); | |||
2740 | const char *uuid = switch_channel_get_variable(channel, SWITCH_BRIDGE_VARIABLE)switch_channel_get_variable_dup(channel, "bridge_to", SWITCH_TRUE , -1); | |||
2741 | arg++; | |||
2742 | if (!strcasecmp(arg, "bleg")) { | |||
2743 | if (uuid && (other_session = switch_core_session_locate(uuid)switch_core_session_perform_locate(uuid, "mod_commands.c", (const char *)__func__, 2743))) { | |||
2744 | switch_core_session_t *tmp = tsession; | |||
2745 | tsession = other_session; | |||
2746 | other_session = NULL((void*)0); | |||
2747 | switch_core_session_rwunlock(tmp); | |||
2748 | } | |||
2749 | } else if (!strcasecmp(arg, "both")) { | |||
2750 | if (uuid && (other_session = switch_core_session_locate(uuid)switch_core_session_perform_locate(uuid, "mod_commands.c", (const char *)__func__, 2750))) { | |||
2751 | switch_channel_t *other_channel = switch_core_session_get_channel(other_session); | |||
2752 | switch_channel_set_flag(other_channel, CF_REDIRECT)switch_channel_set_flag_value(other_channel, CF_REDIRECT, 1); | |||
2753 | switch_channel_set_flag(channel, CF_REDIRECT)switch_channel_set_flag_value(channel, CF_REDIRECT, 1); | |||
2754 | switch_ivr_session_transfer(other_session, dest, dp, context); | |||
2755 | switch_core_session_rwunlock(other_session); | |||
2756 | } | |||
2757 | } | |||
2758 | } | |||
2759 | ||||
2760 | if (switch_ivr_session_transfer(tsession, dest, dp, context) == SWITCH_STATUS_SUCCESS) { | |||
2761 | stream->write_function(stream, "+OK\n"); | |||
2762 | } else { | |||
2763 | stream->write_function(stream, "-ERR\n"); | |||
2764 | } | |||
2765 | ||||
2766 | switch_core_session_rwunlock(tsession); | |||
2767 | ||||
2768 | done: | |||
2769 | switch_safe_free(mycmd)if (mycmd) {free(mycmd);mycmd=((void*)0);}; | |||
2770 | return SWITCH_STATUS_SUCCESS; | |||
2771 | } | |||
2772 | ||||
2773 | ||||
2774 | #define DUAL_TRANSFER_SYNTAX"<uuid> <A-dest-exten>[/<A-dialplan>][/<A-context>] <B-dest-exten>[/<B-dialplan>][/<B-context>]" "<uuid> <A-dest-exten>[/<A-dialplan>][/<A-context>] <B-dest-exten>[/<B-dialplan>][/<B-context>]" | |||
2775 | SWITCH_STANDARD_API(dual_transfer_function)static switch_status_t dual_transfer_function ( const char *cmd , switch_core_session_t *session, switch_stream_handle_t *stream ) | |||
2776 | { | |||
2777 | switch_core_session_t *tsession = NULL((void*)0), *other_session = NULL((void*)0); | |||
2778 | char *mycmd = NULL((void*)0), *argv[5] = { 0 }; | |||
2779 | int argc = 0; | |||
2780 | char *tuuid, *dest1, *dest2, *dp1 = NULL((void*)0), *dp2 = NULL((void*)0), *context1 = NULL((void*)0), *context2 = NULL((void*)0); | |||
2781 | ||||
2782 | if (zstr(cmd)_zstr(cmd) || !(mycmd = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))))) { | |||
2783 | stream->write_function(stream, "-USAGE: %s\n", DUAL_TRANSFER_SYNTAX"<uuid> <A-dest-exten>[/<A-dialplan>][/<A-context>] <B-dest-exten>[/<B-dialplan>][/<B-context>]"); | |||
2784 | return SWITCH_STATUS_SUCCESS; | |||
2785 | } | |||
2786 | ||||
2787 | argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | |||
2788 | ||||
2789 | if (argc != 3) { | |||
2790 | stream->write_function(stream, "-USAGE: %s\n", DUAL_TRANSFER_SYNTAX"<uuid> <A-dest-exten>[/<A-dialplan>][/<A-context>] <B-dest-exten>[/<B-dialplan>][/<B-context>]"); | |||
2791 | goto done; | |||
2792 | } | |||
2793 | ||||
2794 | tuuid = argv[0]; | |||
2795 | dest1 = argv[1]; | |||
2796 | dest2= argv[2]; | |||
2797 | ||||
2798 | if ((dp1 = strstr(dest1, "/inline")) && *(dp1 + 7) == '\0') { | |||
2799 | *dp1++ = '\0'; | |||
2800 | } else { | |||
2801 | if ((dp1 = strchr(dest1, '/')(__extension__ (__builtin_constant_p ('/') && !__builtin_constant_p (dest1) && ('/') == '\0' ? (char *) __rawmemchr (dest1 , '/') : __builtin_strchr (dest1, '/'))))) { | |||
2802 | *dp1++ = '\0'; | |||
2803 | if ((context1 = strchr(dp1, '/')(__extension__ (__builtin_constant_p ('/') && !__builtin_constant_p (dp1) && ('/') == '\0' ? (char *) __rawmemchr (dp1, '/' ) : __builtin_strchr (dp1, '/'))))) { | |||
2804 | *context1++ = '\0'; | |||
2805 | } | |||
2806 | } | |||
2807 | } | |||
2808 | ||||
2809 | if ((dp2 = strstr(dest2, "/inline")) && *(dp2 + 7) == '\0') { | |||
2810 | *dp2++ = '\0'; | |||
2811 | } else { | |||
2812 | if ((dp2 = strchr(dest2, '/')(__extension__ (__builtin_constant_p ('/') && !__builtin_constant_p (dest2) && ('/') == '\0' ? (char *) __rawmemchr (dest2 , '/') : __builtin_strchr (dest2, '/'))))) { | |||
2813 | *dp2++ = '\0'; | |||
2814 | if ((context2 = strchr(dp2, '/')(__extension__ (__builtin_constant_p ('/') && !__builtin_constant_p (dp2) && ('/') == '\0' ? (char *) __rawmemchr (dp2, '/' ) : __builtin_strchr (dp2, '/'))))) { | |||
2815 | *context2++ = '\0'; | |||
2816 | } | |||
2817 | } | |||
2818 | } | |||
2819 | ||||
2820 | if (zstr(tuuid)_zstr(tuuid) || !(tsession = switch_core_session_locate(tuuid)switch_core_session_perform_locate(tuuid, "mod_commands.c", ( const char *)__func__, 2820))) { | |||
2821 | stream->write_function(stream, "-ERR No such channel!\n"); | |||
2822 | goto done; | |||
2823 | } | |||
2824 | ||||
2825 | if (switch_core_session_get_partner(tsession, &other_session)switch_core_session_perform_get_partner(tsession, &other_session , "mod_commands.c", (const char *)__func__, 2825) == SWITCH_STATUS_SUCCESS) { | |||
2826 | switch_ivr_session_transfer(other_session, dest2, dp2, context2); | |||
2827 | switch_core_session_rwunlock(other_session); | |||
2828 | } | |||
2829 | ||||
2830 | switch_ivr_session_transfer(tsession, dest1, dp1, context1); | |||
2831 | ||||
2832 | stream->write_function(stream, "+OK\n"); | |||
2833 | ||||
2834 | switch_core_session_rwunlock(tsession); | |||
2835 | ||||
2836 | done: | |||
2837 | switch_safe_free(mycmd)if (mycmd) {free(mycmd);mycmd=((void*)0);}; | |||
2838 | return SWITCH_STATUS_SUCCESS; | |||
2839 | } | |||
2840 | ||||
2841 | #define TONE_DETECT_SYNTAX"<uuid> <key> <tone_spec> [<flags> <timeout> <app> <args> <hits>]" "<uuid> <key> <tone_spec> [<flags> <timeout> <app> <args> <hits>]" | |||
2842 | SWITCH_STANDARD_API(tone_detect_session_function)static switch_status_t tone_detect_session_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
2843 | { | |||
2844 | char *argv[8] = { 0 }; | |||
2845 | int argc; | |||
2846 | char *mydata = NULL((void*)0); | |||
2847 | time_t to = 0; | |||
2848 | switch_core_session_t *rsession; | |||
2849 | int hits = 1; | |||
2850 | ||||
2851 | if (!cmd) { | |||
2852 | stream->write_function(stream, "-USAGE: %s\n", TONE_DETECT_SYNTAX"<uuid> <key> <tone_spec> [<flags> <timeout> <app> <args> <hits>]"); | |||
2853 | return SWITCH_STATUS_SUCCESS; | |||
2854 | } | |||
2855 | ||||
2856 | mydata = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))); | |||
2857 | switch_assert(mydata != NULL)((mydata != ((void*)0)) ? (void) (0) : __assert_fail ("mydata != ((void*)0)" , "mod_commands.c", 2857, __PRETTY_FUNCTION__)); | |||
2858 | ||||
2859 | if ((argc = switch_separate_string(mydata, ' ', argv, sizeof(argv) / sizeof(argv[0]))) < 3 || !argv[0]) { | |||
2860 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "mod_commands.c", (const char *)__func__ , 2860, (const char*)(session), SWITCH_LOG_ERROR, "-ERR INVALID ARGS!\n"); | |||
2861 | return SWITCH_STATUS_SUCCESS; | |||
2862 | } | |||
2863 | ||||
2864 | if (!(rsession = switch_core_session_locate(argv[0])switch_core_session_perform_locate(argv[0], "mod_commands.c", (const char *)__func__, 2864))) { | |||
2865 | stream->write_function(stream, "-ERR Cannot locate session!\n"); | |||
2866 | return SWITCH_STATUS_SUCCESS; | |||
2867 | } | |||
2868 | ||||
2869 | if (argv[4]) { | |||
2870 | uint32_t mto; | |||
2871 | if (*argv[4] == '+') { | |||
2872 | if ((mto = atoi(argv[4] + 1)) > 0) { | |||
2873 | to = switch_epoch_time_now(NULL((void*)0)) + mto; | |||
2874 | } else { | |||
2875 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "mod_commands.c", (const char *)__func__ , 2875, (const char*)(session), SWITCH_LOG_ERROR, "INVALID Timeout!\n"); | |||
2876 | goto done; | |||
2877 | } | |||
2878 | } else { | |||
2879 | if ((to = atoi(argv[4])) < switch_epoch_time_now(NULL((void*)0))) { | |||
2880 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "mod_commands.c", (const char *)__func__ , 2880, (const char*)(session), SWITCH_LOG_ERROR, "INVALID Timeout!\n"); | |||
2881 | to = 0; | |||
2882 | goto done; | |||
2883 | } | |||
2884 | } | |||
2885 | } | |||
2886 | ||||
2887 | if (argv[7]) { | |||
2888 | hits = atoi(argv[7]); | |||
2889 | if (hits < 0) { | |||
2890 | hits = 1; | |||
2891 | } | |||
2892 | } | |||
2893 | ||||
2894 | switch_ivr_tone_detect_session(rsession, argv[1], argv[2], argv[3], to, hits, argv[5], argv[6], NULL((void*)0)); | |||
2895 | stream->write_function(stream, "+OK Enabling tone detection '%s' '%s' '%s'\n", argv[1], argv[2], argv[3]); | |||
2896 | ||||
2897 | done: | |||
2898 | ||||
2899 | free(mydata); | |||
2900 | switch_core_session_rwunlock(rsession); | |||
2901 | ||||
2902 | return SWITCH_STATUS_SUCCESS; | |||
2903 | } | |||
2904 | ||||
2905 | SWITCH_STANDARD_API(uuid_function)static switch_status_t uuid_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
2906 | { | |||
2907 | char uuid_str[SWITCH_UUID_FORMATTED_LENGTH256 + 1]; | |||
2908 | ||||
2909 | switch_uuid_str(uuid_str, sizeof(uuid_str)); | |||
2910 | ||||
2911 | stream->write_function(stream, "%s", uuid_str); | |||
2912 | return SWITCH_STATUS_SUCCESS; | |||
2913 | } | |||
2914 | ||||
2915 | #define UUID_CHAT_SYNTAX"<uuid> <text>" "<uuid> <text>" | |||
2916 | SWITCH_STANDARD_API(uuid_chat)static switch_status_t uuid_chat ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
2917 | { | |||
2918 | switch_core_session_t *tsession = NULL((void*)0); | |||
2919 | char *uuid = NULL((void*)0), *text = NULL((void*)0); | |||
2920 | ||||
2921 | if (!zstr(cmd)_zstr(cmd) && (uuid = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))))) { | |||
2922 | if ((text = strchr(uuid, ' ')(__extension__ (__builtin_constant_p (' ') && !__builtin_constant_p (uuid) && (' ') == '\0' ? (char *) __rawmemchr (uuid , ' ') : __builtin_strchr (uuid, ' '))))) { | |||
2923 | *text++ = '\0'; | |||
2924 | } | |||
2925 | } | |||
2926 | ||||
2927 | if (zstr(uuid)_zstr(uuid) || zstr(text)_zstr(text)) { | |||
2928 | stream->write_function(stream, "-USAGE: %s\n", UUID_CHAT_SYNTAX"<uuid> <text>"); | |||
2929 | } else { | |||
2930 | if ((tsession = switch_core_session_locate(uuid)switch_core_session_perform_locate(uuid, "mod_commands.c", (const char *)__func__, 2930))) { | |||
2931 | switch_event_t *event; | |||
2932 | if (switch_event_create(&event, SWITCH_EVENT_COMMAND)switch_event_create_subclass_detailed("mod_commands.c", (const char * )(const char *)__func__, 2932, &event, SWITCH_EVENT_COMMAND , ((void*)0)) == SWITCH_STATUS_SUCCESS) { | |||
2933 | switch_event_add_body(event, "%s", text); | |||
2934 | if (switch_core_session_receive_event(tsession, &event) != SWITCH_STATUS_SUCCESS) { | |||
2935 | switch_event_destroy(&event); | |||
2936 | stream->write_function(stream, "-ERR Send failed\n"); | |||
2937 | } else { | |||
2938 | stream->write_function(stream, "+OK\n"); | |||
2939 | } | |||
2940 | } | |||
2941 | switch_core_session_rwunlock(tsession); | |||
2942 | } else { | |||
2943 | stream->write_function(stream, "-ERR No such channel %s!\n", uuid); | |||
2944 | } | |||
2945 | } | |||
2946 | ||||
2947 | switch_safe_free(uuid)if (uuid) {free(uuid);uuid=((void*)0);}; | |||
2948 | return SWITCH_STATUS_SUCCESS; | |||
2949 | } | |||
2950 | ||||
2951 | #define UUID_DROP_DTMF_SYNTAX"<uuid> [on | off ] [ mask_digits <digits> | mask_file <file>]" "<uuid> [on | off ] [ mask_digits <digits> | mask_file <file>]" | |||
2952 | SWITCH_STANDARD_API(uuid_drop_dtmf)static switch_status_t uuid_drop_dtmf ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
2953 | { | |||
2954 | switch_core_session_t *tsession = NULL((void*)0); | |||
2955 | char *uuid = NULL((void*)0), *action = NULL((void*)0), *mask_action = NULL((void*)0), *mask_arg = NULL((void*)0); | |||
2956 | char *argv[5] = { 0 }; | |||
2957 | char *dup; | |||
2958 | int argc = 0; | |||
2959 | ||||
2960 | if (zstr(cmd)_zstr(cmd)) { | |||
2961 | stream->write_function(stream, "-USAGE: %s\n", UUID_DROP_DTMF_SYNTAX"<uuid> [on | off ] [ mask_digits <digits> | mask_file <file>]"); | |||
2962 | return SWITCH_STATUS_SUCCESS; | |||
2963 | } | |||
2964 | ||||
2965 | dup = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))); | |||
2966 | argc = switch_split(dup, ' ', argv)switch_separate_string(dup, ' ', argv, (sizeof(argv) / sizeof (argv[0]))); | |||
2967 | ||||
2968 | if ( argc < 4 ) { | |||
2969 | stream->write_function(stream, "-USAGE: %s\n", UUID_DROP_DTMF_SYNTAX"<uuid> [on | off ] [ mask_digits <digits> | mask_file <file>]"); | |||
2970 | goto end; | |||
2971 | } | |||
2972 | ||||
2973 | if (argv[0]) { | |||
2974 | uuid = argv[0]; | |||
2975 | } | |||
2976 | ||||
2977 | if (argv[1]) { | |||
2978 | action = argv[1]; | |||
2979 | } | |||
2980 | ||||
2981 | if (argv[2]) { | |||
2982 | mask_action = argv[2]; | |||
2983 | } | |||
2984 | ||||
2985 | if (argv[3]) { | |||
2986 | mask_arg = argv[3]; | |||
2987 | } | |||
2988 | ||||
2989 | if (zstr(uuid)_zstr(uuid)) { | |||
2990 | stream->write_function(stream, "-USAGE: %s\n", UUID_DROP_DTMF_SYNTAX"<uuid> [on | off ] [ mask_digits <digits> | mask_file <file>]"); | |||
2991 | } else { | |||
2992 | if ((tsession = switch_core_session_locate(uuid)switch_core_session_perform_locate(uuid, "mod_commands.c", (const char *)__func__, 2992))) { | |||
2993 | switch_channel_t *channel = switch_core_session_get_channel(tsession); | |||
2994 | int is_on = 0; | |||
2995 | const char *file, *digits; | |||
2996 | ||||
2997 | if (!zstr(mask_action)_zstr(mask_action) && !zstr(mask_arg)_zstr(mask_arg)) { | |||
2998 | if (!strcasecmp(mask_action, "mask_digits")) { | |||
2999 | switch_channel_set_variable(channel, "drop_dtmf_masking_digits", mask_arg)switch_channel_set_variable_var_check(channel, "drop_dtmf_masking_digits" , mask_arg, SWITCH_TRUE); | |||
3000 | } else if (!strcasecmp(mask_action, "mask_file")) { | |||
3001 | switch_channel_set_variable(channel, "drop_dtmf_masking_file", mask_arg)switch_channel_set_variable_var_check(channel, "drop_dtmf_masking_file" , mask_arg, SWITCH_TRUE); | |||
3002 | } else { | |||
3003 | stream->write_function(stream, "-USAGE: %s\n", UUID_DROP_DTMF_SYNTAX"<uuid> [on | off ] [ mask_digits <digits> | mask_file <file>]"); | |||
3004 | goto end; | |||
3005 | } | |||
3006 | } | |||
3007 | ||||
3008 | if (!zstr(action)_zstr(action)) { | |||
3009 | if (!strcasecmp(action, "on")) { | |||
3010 | switch_channel_set_flag(channel, CF_DROP_DTMF)switch_channel_set_flag_value(channel, CF_DROP_DTMF, 1); | |||
3011 | switch_channel_set_variable(channel, "drop_dtmf", "true")switch_channel_set_variable_var_check(channel, "drop_dtmf", "true" , SWITCH_TRUE); | |||
3012 | } else { | |||
3013 | switch_channel_clear_flag(channel, CF_DROP_DTMF); | |||
3014 | switch_channel_set_variable(channel, "drop_dtmf", "false")switch_channel_set_variable_var_check(channel, "drop_dtmf", "false" , SWITCH_TRUE); | |||
3015 | } | |||
3016 | } | |||
3017 | ||||
3018 | is_on = switch_channel_test_flag(channel, CF_DROP_DTMF); | |||
3019 | file = switch_channel_get_variable_dup(channel, "drop_dtmf_masking_file", SWITCH_FALSE, -1); | |||
3020 | digits = switch_channel_get_variable_dup(channel, "drop_dtmf_masking_digits", SWITCH_FALSE, -1); | |||
3021 | ||||
3022 | stream->write_function(stream, "+OK %s is %s DTMF. mask_file: %s mask_digits: %s\n", uuid, is_on ? "dropping" : "not dropping", | |||
3023 | file ? file : "NONE", | |||
3024 | digits ? digits : "NONE"); | |||
3025 | ||||
3026 | switch_core_session_rwunlock(tsession); | |||
3027 | } else { | |||
3028 | stream->write_function(stream, "-ERR No such channel %s!\n", uuid); | |||
3029 | } | |||
3030 | } | |||
3031 | ||||
3032 | end: | |||
3033 | ||||
3034 | switch_safe_free(dup)if (dup) {free(dup);dup=((void*)0);}; | |||
3035 | return SWITCH_STATUS_SUCCESS; | |||
3036 | ||||
3037 | } | |||
3038 | ||||
3039 | #define UUID_DEFLECT_SYNTAX"<uuid> <uri>" "<uuid> <uri>" | |||
3040 | SWITCH_STANDARD_API(uuid_deflect)static switch_status_t uuid_deflect ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
3041 | { | |||
3042 | switch_core_session_t *tsession = NULL((void*)0); | |||
3043 | char *uuid = NULL((void*)0), *text = NULL((void*)0); | |||
3044 | ||||
3045 | if (!zstr(cmd)_zstr(cmd) && (uuid = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))))) { | |||
3046 | if ((text = strchr(uuid, ' ')(__extension__ (__builtin_constant_p (' ') && !__builtin_constant_p (uuid) && (' ') == '\0' ? (char *) __rawmemchr (uuid , ' ') : __builtin_strchr (uuid, ' '))))) { | |||
3047 | *text++ = '\0'; | |||
3048 | } | |||
3049 | } | |||
3050 | ||||
3051 | if (zstr(uuid)_zstr(uuid) || zstr(text)_zstr(text)) { | |||
3052 | stream->write_function(stream, "-USAGE: %s\n", UUID_DEFLECT_SYNTAX"<uuid> <uri>"); | |||
3053 | } else { | |||
3054 | if ((tsession = switch_core_session_locate(uuid)switch_core_session_perform_locate(uuid, "mod_commands.c", (const char *)__func__, 3054))) { | |||
3055 | switch_core_session_message_t msg = { 0 }; | |||
3056 | ||||
3057 | /* Tell the channel to deflect the call */ | |||
3058 | msg.from = __FILE__"mod_commands.c"; | |||
3059 | msg.string_arg = text; | |||
3060 | msg.message_id = SWITCH_MESSAGE_INDICATE_DEFLECT; | |||
3061 | switch_core_session_receive_message(tsession, &msg)switch_core_session_perform_receive_message(tsession, &msg , "mod_commands.c", (const char *)__func__, 3061); | |||
3062 | stream->write_function(stream, "+OK:%s\n", msg.string_reply); | |||
3063 | switch_core_session_rwunlock(tsession); | |||
3064 | } else { | |||
3065 | stream->write_function(stream, "-ERR No such channel %s!\n", uuid); | |||
3066 | } | |||
3067 | } | |||
3068 | ||||
3069 | switch_safe_free(uuid)if (uuid) {free(uuid);uuid=((void*)0);}; | |||
3070 | return SWITCH_STATUS_SUCCESS; | |||
3071 | } | |||
3072 | ||||
3073 | ||||
3074 | #define UUID_MEDIA_STATS_SYNTAX"<uuid>" "<uuid>" | |||
3075 | SWITCH_STANDARD_API(uuid_set_media_stats)static switch_status_t uuid_set_media_stats ( const char *cmd , switch_core_session_t *session, switch_stream_handle_t *stream ) | |||
3076 | { | |||
3077 | switch_core_session_t *tsession = NULL((void*)0); | |||
3078 | const char *uuid = cmd; | |||
3079 | ||||
3080 | if (zstr(uuid)_zstr(uuid)) { | |||
3081 | stream->write_function(stream, "-USAGE: %s\n", UUID_MEDIA_STATS_SYNTAX"<uuid>"); | |||
3082 | } else { | |||
3083 | if ((tsession = switch_core_session_locate(uuid)switch_core_session_perform_locate(uuid, "mod_commands.c", (const char *)__func__, 3083))) { | |||
3084 | switch_core_media_set_stats(tsession); | |||
3085 | stream->write_function(stream, "+OK:\n"); | |||
3086 | switch_core_session_rwunlock(tsession); | |||
3087 | } else { | |||
3088 | stream->write_function(stream, "-ERR No such channel %s!\n", uuid); | |||
3089 | } | |||
3090 | } | |||
3091 | ||||
3092 | return SWITCH_STATUS_SUCCESS; | |||
3093 | } | |||
3094 | ||||
3095 | #define add_stat(_i, _s)cJSON_AddItemToObject(jstats, _s, cJSON_CreateNumber(((double )_i))) cJSON_AddItemToObject(jstats, _s, cJSON_CreateNumber(((double)_i))) | |||
3096 | ||||
3097 | static void jsonify_stats(cJSON *json, const char *name, switch_rtp_stats_t *stats) | |||
3098 | { | |||
3099 | cJSON *jstats = cJSON_CreateObject(); | |||
3100 | cJSON_AddItemToObject(json, name, jstats); | |||
3101 | ||||
3102 | stats->inbound.std_deviation = sqrt(stats->inbound.variance); | |||
3103 | ||||
3104 | add_stat(stats->inbound.raw_bytes, "in_raw_bytes")cJSON_AddItemToObject(jstats, "in_raw_bytes", cJSON_CreateNumber (((double)stats->inbound.raw_bytes))); | |||
3105 | add_stat(stats->inbound.media_bytes, "in_media_bytes")cJSON_AddItemToObject(jstats, "in_media_bytes", cJSON_CreateNumber (((double)stats->inbound.media_bytes))); | |||
3106 | add_stat(stats->inbound.packet_count, "in_packet_count")cJSON_AddItemToObject(jstats, "in_packet_count", cJSON_CreateNumber (((double)stats->inbound.packet_count))); | |||
3107 | add_stat(stats->inbound.media_packet_count, "in_media_packet_count")cJSON_AddItemToObject(jstats, "in_media_packet_count", cJSON_CreateNumber (((double)stats->inbound.media_packet_count))); | |||
3108 | add_stat(stats->inbound.skip_packet_count, "in_skip_packet_count")cJSON_AddItemToObject(jstats, "in_skip_packet_count", cJSON_CreateNumber (((double)stats->inbound.skip_packet_count))); | |||
3109 | add_stat(stats->inbound.jb_packet_count, "in_jitter_packet_count")cJSON_AddItemToObject(jstats, "in_jitter_packet_count", cJSON_CreateNumber (((double)stats->inbound.jb_packet_count))); | |||
3110 | add_stat(stats->inbound.dtmf_packet_count, "in_dtmf_packet_count")cJSON_AddItemToObject(jstats, "in_dtmf_packet_count", cJSON_CreateNumber (((double)stats->inbound.dtmf_packet_count))); | |||
3111 | add_stat(stats->inbound.cng_packet_count, "in_cng_packet_count")cJSON_AddItemToObject(jstats, "in_cng_packet_count", cJSON_CreateNumber (((double)stats->inbound.cng_packet_count))); | |||
3112 | add_stat(stats->inbound.flush_packet_count, "in_flush_packet_count")cJSON_AddItemToObject(jstats, "in_flush_packet_count", cJSON_CreateNumber (((double)stats->inbound.flush_packet_count))); | |||
3113 | add_stat(stats->inbound.largest_jb_size, "in_largest_jb_size")cJSON_AddItemToObject(jstats, "in_largest_jb_size", cJSON_CreateNumber (((double)stats->inbound.largest_jb_size))); | |||
3114 | ||||
3115 | add_stat (stats->inbound.min_variance, "in_jitter_min_variance")cJSON_AddItemToObject(jstats, "in_jitter_min_variance", cJSON_CreateNumber (((double)stats->inbound.min_variance))); | |||
3116 | add_stat (stats->inbound.max_variance, "in_jitter_max_variance")cJSON_AddItemToObject(jstats, "in_jitter_max_variance", cJSON_CreateNumber (((double)stats->inbound.max_variance))); | |||
3117 | add_stat (stats->inbound.lossrate, "in_jitter_loss_rate")cJSON_AddItemToObject(jstats, "in_jitter_loss_rate", cJSON_CreateNumber (((double)stats->inbound.lossrate))); | |||
3118 | add_stat (stats->inbound.burstrate, "in_jitter_burst_rate")cJSON_AddItemToObject(jstats, "in_jitter_burst_rate", cJSON_CreateNumber (((double)stats->inbound.burstrate))); | |||
3119 | add_stat (stats->inbound.mean_interval, "in_mean_interval")cJSON_AddItemToObject(jstats, "in_mean_interval", cJSON_CreateNumber (((double)stats->inbound.mean_interval))); | |||
3120 | ||||
3121 | add_stat(stats->inbound.flaws, "in_flaw_total")cJSON_AddItemToObject(jstats, "in_flaw_total", cJSON_CreateNumber (((double)stats->inbound.flaws))); | |||
3122 | ||||
3123 | add_stat (stats->inbound.R, "in_quality_percentage")cJSON_AddItemToObject(jstats, "in_quality_percentage", cJSON_CreateNumber (((double)stats->inbound.R))); | |||
3124 | add_stat (stats->inbound.mos, "in_mos")cJSON_AddItemToObject(jstats, "in_mos", cJSON_CreateNumber((( double)stats->inbound.mos))); | |||
3125 | ||||
3126 | ||||
3127 | add_stat(stats->outbound.raw_bytes, "out_raw_bytes")cJSON_AddItemToObject(jstats, "out_raw_bytes", cJSON_CreateNumber (((double)stats->outbound.raw_bytes))); | |||
3128 | add_stat(stats->outbound.media_bytes, "out_media_bytes")cJSON_AddItemToObject(jstats, "out_media_bytes", cJSON_CreateNumber (((double)stats->outbound.media_bytes))); | |||
3129 | add_stat(stats->outbound.packet_count, "out_packet_count")cJSON_AddItemToObject(jstats, "out_packet_count", cJSON_CreateNumber (((double)stats->outbound.packet_count))); | |||
3130 | add_stat(stats->outbound.media_packet_count, "out_media_packet_count")cJSON_AddItemToObject(jstats, "out_media_packet_count", cJSON_CreateNumber (((double)stats->outbound.media_packet_count))); | |||
3131 | add_stat(stats->outbound.skip_packet_count, "out_skip_packet_count")cJSON_AddItemToObject(jstats, "out_skip_packet_count", cJSON_CreateNumber (((double)stats->outbound.skip_packet_count))); | |||
3132 | add_stat(stats->outbound.dtmf_packet_count, "out_dtmf_packet_count")cJSON_AddItemToObject(jstats, "out_dtmf_packet_count", cJSON_CreateNumber (((double)stats->outbound.dtmf_packet_count))); | |||
3133 | add_stat(stats->outbound.cng_packet_count, "out_cng_packet_count")cJSON_AddItemToObject(jstats, "out_cng_packet_count", cJSON_CreateNumber (((double)stats->outbound.cng_packet_count))); | |||
3134 | ||||
3135 | add_stat(stats->rtcp.packet_count, "rtcp_packet_count")cJSON_AddItemToObject(jstats, "rtcp_packet_count", cJSON_CreateNumber (((double)stats->rtcp.packet_count))); | |||
3136 | add_stat(stats->rtcp.octet_count, "rtcp_octet_count")cJSON_AddItemToObject(jstats, "rtcp_octet_count", cJSON_CreateNumber (((double)stats->rtcp.octet_count))); | |||
3137 | ||||
3138 | } | |||
3139 | ||||
3140 | static switch_bool_t true_enough(cJSON *json) | |||
3141 | { | |||
3142 | if (json && (json->type == cJSON_True1 || json->valueint || json->valuedouble || json->valuestring)) { | |||
3143 | return SWITCH_TRUE; | |||
3144 | } | |||
3145 | ||||
3146 | return SWITCH_FALSE; | |||
3147 | } | |||
3148 | ||||
3149 | SWITCH_STANDARD_JSON_API(json_stats_function)static switch_status_t json_stats_function (const cJSON *json , switch_core_session_t *session, cJSON **json_reply) | |||
3150 | { | |||
3151 | cJSON *reply, *data = cJSON_GetObjectItem(json, "data"); | |||
3152 | switch_status_t status = SWITCH_STATUS_FALSE; | |||
3153 | const char *uuid = cJSON_GetObjectCstr(data, "uuid"); | |||
3154 | cJSON *cdata = cJSON_GetObjectItem(data, "channelData"); | |||
3155 | ||||
3156 | switch_core_session_t *tsession; | |||
3157 | ||||
3158 | reply = cJSON_CreateObject(); | |||
3159 | *json_reply = reply; | |||
3160 | ||||
3161 | if (zstr(uuid)_zstr(uuid)) { | |||
3162 | cJSON_AddItemToObject(reply, "response", cJSON_CreateString("INVALID INPUT")); | |||
3163 | goto end; | |||
3164 | } | |||
3165 | ||||
3166 | ||||
3167 | if ((tsession = switch_core_session_locate(uuid)switch_core_session_perform_locate(uuid, "mod_commands.c", (const char *)__func__, 3167))) { | |||
3168 | cJSON *jevent; | |||
3169 | switch_rtp_stats_t *audio_stats = NULL((void*)0), *video_stats = NULL((void*)0); | |||
3170 | ||||
3171 | switch_core_media_set_stats(tsession); | |||
3172 | ||||
3173 | audio_stats = switch_core_media_get_stats(tsession, SWITCH_MEDIA_TYPE_AUDIO, switch_core_session_get_pool(tsession)); | |||
3174 | video_stats = switch_core_media_get_stats(tsession, SWITCH_MEDIA_TYPE_VIDEO, switch_core_session_get_pool(tsession)); | |||
3175 | ||||
3176 | jsonify_stats(reply, "audio", audio_stats); | |||
3177 | jsonify_stats(reply, "video", video_stats); | |||
3178 | ||||
3179 | if (true_enough(cdata) && switch_ivr_generate_json_cdr(tsession, &jevent, SWITCH_FALSE) == SWITCH_STATUS_SUCCESS) { | |||
3180 | cJSON_AddItemToObject(reply, "channelData", jevent); | |||
3181 | } | |||
3182 | ||||
3183 | switch_core_session_rwunlock(tsession); | |||
3184 | ||||
3185 | status = SWITCH_STATUS_SUCCESS; | |||
3186 | } else { | |||
3187 | cJSON_AddItemToObject(reply, "response", cJSON_CreateString("Session does not exist")); | |||
3188 | goto end; | |||
3189 | } | |||
3190 | ||||
3191 | end: | |||
3192 | ||||
3193 | return status; | |||
3194 | } | |||
3195 | ||||
3196 | ||||
3197 | #define UUID_RECOVERY_REFRESH_SYNTAX"<uuid> <uri>" "<uuid> <uri>" | |||
3198 | SWITCH_STANDARD_API(uuid_recovery_refresh)static switch_status_t uuid_recovery_refresh ( const char *cmd , switch_core_session_t *session, switch_stream_handle_t *stream ) | |||
3199 | { | |||
3200 | switch_core_session_t *tsession = NULL((void*)0); | |||
3201 | char *uuid = NULL((void*)0), *text = NULL((void*)0); | |||
3202 | ||||
3203 | if (!zstr(cmd)_zstr(cmd) && (uuid = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))))) { | |||
3204 | if ((text = strchr(uuid, ' ')(__extension__ (__builtin_constant_p (' ') && !__builtin_constant_p (uuid) && (' ') == '\0' ? (char *) __rawmemchr (uuid , ' ') : __builtin_strchr (uuid, ' '))))) { | |||
3205 | *text++ = '\0'; | |||
3206 | } | |||
3207 | } | |||
3208 | ||||
3209 | if (zstr(uuid)_zstr(uuid) || zstr(text)_zstr(text)) { | |||
3210 | stream->write_function(stream, "-USAGE: %s\n", UUID_RECOVERY_REFRESH_SYNTAX"<uuid> <uri>"); | |||
3211 | } else { | |||
3212 | if ((tsession = switch_core_session_locate(uuid)switch_core_session_perform_locate(uuid, "mod_commands.c", (const char *)__func__, 3212))) { | |||
3213 | switch_core_session_message_t msg = { 0 }; | |||
3214 | ||||
3215 | /* Tell the channel to recovery_refresh the call */ | |||
3216 | msg.from = __FILE__"mod_commands.c"; | |||
3217 | msg.string_arg = text; | |||
3218 | msg.message_id = SWITCH_MESSAGE_INDICATE_RECOVERY_REFRESH; | |||
3219 | switch_core_session_receive_message(tsession, &msg)switch_core_session_perform_receive_message(tsession, &msg , "mod_commands.c", (const char *)__func__, 3219); | |||
3220 | stream->write_function(stream, "+OK:%s\n", msg.string_reply); | |||
3221 | switch_core_session_rwunlock(tsession); | |||
3222 | } else { | |||
3223 | stream->write_function(stream, "-ERR No such channel %s!\n", uuid); | |||
3224 | } | |||
3225 | } | |||
3226 | ||||
3227 | switch_safe_free(uuid)if (uuid) {free(uuid);uuid=((void*)0);}; | |||
3228 | return SWITCH_STATUS_SUCCESS; | |||
3229 | } | |||
3230 | ||||
3231 | #define SCHED_TRANSFER_SYNTAX"[+]<time> <uuid> <extension> [<dialplan>] [<context>]" "[+]<time> <uuid> <extension> [<dialplan>] [<context>]" | |||
3232 | SWITCH_STANDARD_API(sched_transfer_function)static switch_status_t sched_transfer_function ( const char * cmd, switch_core_session_t *session, switch_stream_handle_t * stream) | |||
3233 | { | |||
3234 | switch_core_session_t *tsession = NULL((void*)0); | |||
3235 | char *mycmd = NULL((void*)0), *argv[6] = { 0 }; | |||
3236 | int argc = 0; | |||
3237 | ||||
3238 | if (!zstr(cmd)_zstr(cmd) && (mycmd = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))))) { | |||
3239 | argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | |||
3240 | } | |||
3241 | ||||
3242 | if (zstr(cmd)_zstr(cmd) || argc < 2 || argc > 5 || zstr(argv[0])_zstr(argv[0])) { | |||
3243 | stream->write_function(stream, "-USAGE: %s\n", SCHED_TRANSFER_SYNTAX"[+]<time> <uuid> <extension> [<dialplan>] [<context>]"); | |||
3244 | } else { | |||
3245 | char *uuid = argv[1]; | |||
3246 | char *dest = argv[2]; | |||
3247 | char *dp = argv[3]; | |||
3248 | char *context = argv[4]; | |||
3249 | time_t when; | |||
3250 | ||||
3251 | if (*argv[0] == '+') { | |||
3252 | when = switch_epoch_time_now(NULL((void*)0)) + atol(argv[0] + 1); | |||
3253 | } else { | |||
3254 | when = atol(argv[0]); | |||
3255 | } | |||
3256 | ||||
3257 | if ((tsession = switch_core_session_locate(uuid)switch_core_session_perform_locate(uuid, "mod_commands.c", (const char *)__func__, 3257))) { | |||
3258 | switch_ivr_schedule_transfer(when, uuid, dest, dp, context); | |||
3259 | stream->write_function(stream, "+OK\n"); | |||
3260 | switch_core_session_rwunlock(tsession); | |||
3261 | } else { | |||
3262 | stream->write_function(stream, "-ERR No such channel!\n"); | |||
3263 | } | |||
3264 | } | |||
3265 | ||||
3266 | switch_safe_free(mycmd)if (mycmd) {free(mycmd);mycmd=((void*)0);}; | |||
3267 | return SWITCH_STATUS_SUCCESS; | |||
3268 | } | |||
3269 | ||||
3270 | #define SCHED_HANGUP_SYNTAX"[+]<time> <uuid> [<cause>]" "[+]<time> <uuid> [<cause>]" | |||
3271 | SWITCH_STANDARD_API(sched_hangup_function)static switch_status_t sched_hangup_function ( const char *cmd , switch_core_session_t *session, switch_stream_handle_t *stream ) | |||
3272 | { | |||
3273 | switch_core_session_t *hsession = NULL((void*)0); | |||
3274 | char *mycmd = NULL((void*)0), *argv[4] = { 0 }; | |||
3275 | int argc = 0; | |||
3276 | ||||
3277 | if (!zstr(cmd)_zstr(cmd) && (mycmd = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))))) { | |||
3278 | argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | |||
3279 | } | |||
3280 | ||||
3281 | if (zstr(cmd)_zstr(cmd) || argc < 1 || zstr(argv[0])_zstr(argv[0])) { | |||
3282 | stream->write_function(stream, "-USAGE: %s\n", SCHED_HANGUP_SYNTAX"[+]<time> <uuid> [<cause>]"); | |||
3283 | } else { | |||
3284 | char *uuid = argv[1]; | |||
3285 | char *cause_str = argv[2]; | |||
3286 | time_t when; | |||
3287 | switch_call_cause_t cause = SWITCH_CAUSE_ALLOTTED_TIMEOUT; | |||
3288 | int sec = atol(argv[0] + 1); | |||
3289 | ||||
3290 | if (*argv[0] == '+') { | |||
3291 | when = switch_epoch_time_now(NULL((void*)0)) + sec; | |||
3292 | } else { | |||
3293 | when = atol(argv[0]); | |||
3294 | } | |||
3295 | ||||
3296 | if (cause_str) { | |||
3297 | cause = switch_channel_str2cause(cause_str); | |||
3298 | } | |||
3299 | ||||
3300 | if ((hsession = switch_core_session_locate(uuid)switch_core_session_perform_locate(uuid, "mod_commands.c", (const char *)__func__, 3300))) { | |||
3301 | if (sec == 0) { | |||
3302 | switch_channel_t *hchannel = switch_core_session_get_channel(hsession); | |||
3303 | switch_channel_hangup(hchannel, cause)switch_channel_perform_hangup(hchannel, "mod_commands.c", (const char *)__func__, 3303, cause); | |||
3304 | } else { | |||
3305 | switch_ivr_schedule_hangup(when, uuid, cause, SWITCH_FALSE); | |||
3306 | } | |||
3307 | ||||
3308 | stream->write_function(stream, "+OK\n"); | |||
3309 | switch_core_session_rwunlock(hsession); | |||
3310 | } else { | |||
3311 | stream->write_function(stream, "-ERR No such channel!\n"); | |||
3312 | } | |||
3313 | } | |||
3314 | ||||
3315 | switch_safe_free(mycmd)if (mycmd) {free(mycmd);mycmd=((void*)0);}; | |||
3316 | return SWITCH_STATUS_SUCCESS; | |||
3317 | } | |||
3318 | ||||
3319 | #define MEDIA_SYNTAX"[off] <uuid>" "[off] <uuid>" | |||
3320 | SWITCH_STANDARD_API(uuid_media_function)static switch_status_t uuid_media_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream ) | |||
3321 | { | |||
3322 | char *mycmd = NULL((void*)0), *argv[4] = { 0 }; | |||
3323 | int argc = 0; | |||
3324 | switch_status_t status = SWITCH_STATUS_FALSE; | |||
3325 | ||||
3326 | if (!zstr(cmd)_zstr(cmd) && (mycmd = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))))) { | |||
3327 | argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | |||
3328 | } | |||
3329 | ||||
3330 | if (zstr(cmd)_zstr(cmd) || argc < 1 || zstr(argv[0])_zstr(argv[0])) { | |||
3331 | stream->write_function(stream, "-USAGE: %s\n", MEDIA_SYNTAX"[off] <uuid>"); | |||
3332 | } else { | |||
3333 | if (!strcasecmp(argv[0], "off")) { | |||
3334 | status = switch_ivr_nomedia(argv[1], SMF_REBRIDGE); | |||
3335 | } else { | |||
3336 | status = switch_ivr_media(argv[0], SMF_REBRIDGE); | |||
3337 | } | |||
3338 | } | |||
3339 | ||||
3340 | if (status == SWITCH_STATUS_SUCCESS) { | |||
3341 | stream->write_function(stream, "+OK Success\n"); | |||
3342 | } else { | |||
3343 | stream->write_function(stream, "-ERR Operation failed\n"); | |||
3344 | } | |||
3345 | ||||
3346 | switch_safe_free(mycmd)if (mycmd) {free(mycmd);mycmd=((void*)0);}; | |||
3347 | return SWITCH_STATUS_SUCCESS; | |||
3348 | } | |||
3349 | ||||
3350 | #define MEDIA_RENEG_SYNTAX"<uuid>[ <codec_string>]" "<uuid>[ <codec_string>]" | |||
3351 | SWITCH_STANDARD_API(uuid_media_neg_function)static switch_status_t uuid_media_neg_function ( const char * cmd, switch_core_session_t *session, switch_stream_handle_t * stream) | |||
3352 | { | |||
3353 | char *mycmd = NULL((void*)0), *argv[2] = { 0 }; | |||
3354 | int argc = 0; | |||
3355 | switch_status_t status = SWITCH_STATUS_FALSE; | |||
3356 | ||||
3357 | if (!zstr(cmd)_zstr(cmd) && (mycmd = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))))) { | |||
3358 | argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | |||
3359 | } | |||
3360 | ||||
3361 | if (zstr(cmd)_zstr(cmd) || argc < 1 || zstr(argv[0])_zstr(argv[0])) { | |||
3362 | stream->write_function(stream, "-USAGE: %s\n", MEDIA_RENEG_SYNTAX"<uuid>[ <codec_string>]"); | |||
3363 | } else { | |||
3364 | switch_core_session_message_t msg = { 0 }; | |||
3365 | switch_core_session_t *lsession = NULL((void*)0); | |||
3366 | char *uuid = argv[0]; | |||
3367 | ||||
3368 | msg.message_id = SWITCH_MESSAGE_INDICATE_MEDIA_RENEG; | |||
3369 | msg.string_arg = argv[1]; | |||
3370 | msg.from = __FILE__"mod_commands.c"; | |||
3371 | ||||
3372 | if (*uuid == '+') { | |||
3373 | msg.numeric_arg++; | |||
3374 | uuid++; | |||
3375 | } | |||
3376 | ||||
3377 | if ((lsession = switch_core_session_locate(uuid)switch_core_session_perform_locate(uuid, "mod_commands.c", (const char *)__func__, 3377))) { | |||
3378 | status = switch_core_session_receive_message(lsession, &msg)switch_core_session_perform_receive_message(lsession, &msg , "mod_commands.c", (const char *)__func__, 3378); | |||
3379 | switch_core_session_rwunlock(lsession); | |||
3380 | } | |||
3381 | } | |||
3382 | ||||
3383 | if (status == SWITCH_STATUS_SUCCESS) { | |||
3384 | stream->write_function(stream, "+OK Success\n"); | |||
3385 | } else { | |||
3386 | stream->write_function(stream, "-ERR Operation Failed\n"); | |||
3387 | } | |||
3388 | ||||
3389 | switch_safe_free(mycmd)if (mycmd) {free(mycmd);mycmd=((void*)0);}; | |||
3390 | return SWITCH_STATUS_SUCCESS; | |||
3391 | } | |||
3392 | ||||
3393 | SWITCH_STANDARD_API(uuid_early_ok_function)static switch_status_t uuid_early_ok_function ( const char *cmd , switch_core_session_t *session, switch_stream_handle_t *stream ) | |||
3394 | { | |||
3395 | char *uuid = (char *) cmd; | |||
3396 | switch_core_session_t *xsession; | |||
3397 | ||||
3398 | if (uuid && (xsession = switch_core_session_locate(uuid)switch_core_session_perform_locate(uuid, "mod_commands.c", (const char *)__func__, 3398))) { | |||
3399 | switch_channel_t *channel = switch_core_session_get_channel(xsession); | |||
3400 | switch_channel_set_flag(channel, CF_EARLY_OK)switch_channel_set_flag_value(channel, CF_EARLY_OK, 1); | |||
3401 | switch_core_session_rwunlock(xsession); | |||
3402 | } else { | |||
3403 | stream->write_function(stream, "-ERROR\n"); | |||
3404 | } | |||
3405 | ||||
3406 | return SWITCH_STATUS_SUCCESS; | |||
3407 | } | |||
3408 | ||||
3409 | #define RING_READY_SYNTAX"<uuid> [queued]" "<uuid> [queued]" | |||
3410 | SWITCH_STANDARD_API(uuid_ring_ready_function)static switch_status_t uuid_ring_ready_function ( const char * cmd, switch_core_session_t *session, switch_stream_handle_t * stream) | |||
3411 | { | |||
3412 | char *uuid = NULL((void*)0), *mycmd = NULL((void*)0), *argv[2] = { 0 }; | |||
3413 | switch_core_session_t *xsession; | |||
3414 | int argc = 0, queued = 0; | |||
3415 | ||||
3416 | if (!zstr(cmd)_zstr(cmd) && (mycmd = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))))) { | |||
3417 | argc = switch_separate_string(mycmd, ' ', argv, | |||
3418 | (sizeof(argv) / sizeof(argv[0]))); | |||
3419 | } | |||
3420 | if (zstr(cmd)_zstr(cmd) || argc < 1) goto usage; | |||
3421 | uuid = argv[0]; | |||
3422 | if (argc > 1) { | |||
3423 | if (!strcasecmp(argv[1], "queued")) { | |||
3424 | queued = 1; | |||
3425 | } else goto usage; | |||
3426 | } | |||
3427 | if (!uuid || !(xsession = switch_core_session_locate(uuid)switch_core_session_perform_locate(uuid, "mod_commands.c", (const char *)__func__, 3427))) | |||
3428 | goto error; | |||
3429 | switch_channel_ring_ready_value(switch_core_session_get_channel(xsession),switch_channel_perform_ring_ready_value(switch_core_session_get_channel (xsession), queued ? SWITCH_RING_READY_QUEUED : SWITCH_RING_READY_RINGING , "mod_commands.c", (const char *)__func__, 3431) | |||
3430 | queued ? SWITCH_RING_READY_QUEUEDswitch_channel_perform_ring_ready_value(switch_core_session_get_channel (xsession), queued ? SWITCH_RING_READY_QUEUED : SWITCH_RING_READY_RINGING , "mod_commands.c", (const char *)__func__, 3431) | |||
3431 | : SWITCH_RING_READY_RINGING)switch_channel_perform_ring_ready_value(switch_core_session_get_channel (xsession), queued ? SWITCH_RING_READY_QUEUED : SWITCH_RING_READY_RINGING , "mod_commands.c", (const char *)__func__, 3431); | |||
3432 | switch_core_session_rwunlock(xsession); | |||
3433 | stream->write_function(stream, "+OK\n"); | |||
3434 | goto done; | |||
3435 | usage: | |||
3436 | stream->write_function(stream, "-USAGE: %s\n", RING_READY_SYNTAX"<uuid> [queued]"); | |||
3437 | goto done; | |||
3438 | error: | |||
3439 | stream->write_function(stream, "-ERROR\n"); | |||
3440 | goto done; | |||
3441 | done: | |||
3442 | switch_safe_free(mycmd)if (mycmd) {free(mycmd);mycmd=((void*)0);}; | |||
3443 | return SWITCH_STATUS_SUCCESS; | |||
3444 | } | |||
3445 | ||||
3446 | SWITCH_STANDARD_API(uuid_pre_answer_function)static switch_status_t uuid_pre_answer_function ( const char * cmd, switch_core_session_t *session, switch_stream_handle_t * stream) | |||
3447 | { | |||
3448 | char *uuid = (char *) cmd; | |||
3449 | switch_core_session_t *xsession; | |||
3450 | ||||
3451 | if (uuid && (xsession = switch_core_session_locate(uuid)switch_core_session_perform_locate(uuid, "mod_commands.c", (const char *)__func__, 3451))) { | |||
3452 | switch_channel_t *channel = switch_core_session_get_channel(xsession); | |||
3453 | switch_channel_pre_answer(channel)switch_channel_perform_pre_answer(channel, "mod_commands.c", ( const char *)__func__, 3453); | |||
3454 | switch_core_session_rwunlock(xsession); | |||
3455 | } else { | |||
3456 | stream->write_function(stream, "-ERROR\n"); | |||
3457 | } | |||
3458 | ||||
3459 | return SWITCH_STATUS_SUCCESS; | |||
3460 | } | |||
3461 | ||||
3462 | SWITCH_STANDARD_API(uuid_answer_function)static switch_status_t uuid_answer_function ( const char *cmd , switch_core_session_t *session, switch_stream_handle_t *stream ) | |||
3463 | { | |||
3464 | char *uuid = (char *) cmd; | |||
3465 | switch_core_session_t *xsession; | |||
3466 | ||||
3467 | if (uuid && (xsession = switch_core_session_locate(uuid)switch_core_session_perform_locate(uuid, "mod_commands.c", (const char *)__func__, 3467))) { | |||
3468 | switch_channel_t *channel = switch_core_session_get_channel(xsession); | |||
3469 | switch_status_t status = switch_channel_answer(channel)switch_channel_perform_answer(channel, "mod_commands.c", (const char *)__func__, 3469); | |||
3470 | switch_core_session_rwunlock(xsession); | |||
3471 | if (status == SWITCH_STATUS_SUCCESS) { | |||
3472 | stream->write_function(stream, "+OK\n"); | |||
3473 | } else { | |||
3474 | stream->write_function(stream, "-ERROR\n"); | |||
3475 | } | |||
3476 | } else { | |||
3477 | stream->write_function(stream, "-ERROR\n"); | |||
3478 | } | |||
3479 | ||||
3480 | return SWITCH_STATUS_SUCCESS; | |||
3481 | } | |||
3482 | ||||
3483 | ||||
3484 | #define BROADCAST_SYNTAX"<uuid> <path> [aleg|bleg|holdb|both]" "<uuid> <path> [aleg|bleg|holdb|both]" | |||
3485 | SWITCH_STANDARD_API(uuid_broadcast_function)static switch_status_t uuid_broadcast_function ( const char * cmd, switch_core_session_t *session, switch_stream_handle_t * stream) | |||
3486 | { | |||
3487 | char *mycmd = NULL((void*)0), *argv[4] = { 0 }; | |||
3488 | int argc = 0; | |||
3489 | ||||
3490 | if (!zstr(cmd)_zstr(cmd) && (mycmd = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))))) { | |||
3491 | argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | |||
3492 | } | |||
3493 | ||||
3494 | if (zstr(cmd)_zstr(cmd) || argc < 2) { | |||
3495 | stream->write_function(stream, "-USAGE: %s\n", BROADCAST_SYNTAX"<uuid> <path> [aleg|bleg|holdb|both]"); | |||
3496 | } else { | |||
3497 | switch_media_flag_t flags = SMF_NONE; | |||
3498 | ||||
3499 | if (argv[2]) { | |||
3500 | if (switch_stristr("both", (argv[2]))) { | |||
3501 | flags |= (SMF_ECHO_ALEG | SMF_ECHO_BLEG); | |||
3502 | } | |||
3503 | ||||
3504 | if (switch_stristr("aleg", argv[2])) { | |||
3505 | flags |= SMF_ECHO_ALEG; | |||
3506 | } | |||
3507 | ||||
3508 | if (switch_stristr("bleg", argv[2])) { | |||
3509 | flags &= ~SMF_HOLD_BLEG; | |||
3510 | flags |= SMF_ECHO_BLEG; | |||
3511 | } | |||
3512 | ||||
3513 | if (switch_stristr("holdb", argv[2])) { | |||
3514 | flags &= ~SMF_ECHO_BLEG; | |||
3515 | flags |= SMF_HOLD_BLEG; | |||
3516 | } | |||
3517 | ||||
3518 | } else { | |||
3519 | flags = SMF_ECHO_ALEG | SMF_HOLD_BLEG; | |||
3520 | } | |||
3521 | ||||
3522 | switch_ivr_broadcast(argv[0], argv[1], flags); | |||
3523 | stream->write_function(stream, "+OK Message sent\n"); | |||
3524 | } | |||
3525 | ||||
3526 | switch_safe_free(mycmd)if (mycmd) {free(mycmd);mycmd=((void*)0);}; | |||
3527 | return SWITCH_STATUS_SUCCESS; | |||
3528 | } | |||
3529 | ||||
3530 | #define SCHED_BROADCAST_SYNTAX"[[+]<time>|@time] <uuid> <path> [aleg|bleg|both]" "[[+]<time>|@time] <uuid> <path> [aleg|bleg|both]" | |||
3531 | SWITCH_STANDARD_API(sched_broadcast_function)static switch_status_t sched_broadcast_function ( const char * cmd, switch_core_session_t *session, switch_stream_handle_t * stream) | |||
3532 | { | |||
3533 | char *mycmd = NULL((void*)0), *argv[4] = { 0 }; | |||
3534 | int argc = 0; | |||
3535 | ||||
3536 | if (!zstr(cmd)_zstr(cmd) && (mycmd = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))))) { | |||
3537 | argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | |||
3538 | } | |||
3539 | ||||
3540 | if (zstr(cmd)_zstr(cmd) || argc < 3 || zstr(argv[0])_zstr(argv[0])) { | |||
3541 | stream->write_function(stream, "-USAGE: %s\n", SCHED_BROADCAST_SYNTAX"[[+]<time>|@time] <uuid> <path> [aleg|bleg|both]"); | |||
3542 | } else { | |||
3543 | switch_media_flag_t flags = SMF_NONE; | |||
3544 | time_t when; | |||
3545 | ||||
3546 | if (*argv[0] == '@') { | |||
3547 | when = atol(argv[0] + 1); | |||
3548 | } else if (*argv[0] == '+') { | |||
3549 | when = switch_epoch_time_now(NULL((void*)0)) + atol(argv[0] + 1); | |||
3550 | } else { | |||
3551 | when = atol(argv[0]); | |||
3552 | } | |||
3553 | ||||
3554 | if (argv[3]) { | |||
3555 | if (!strcasecmp(argv[3], "both")) { | |||
3556 | flags |= (SMF_ECHO_ALEG | SMF_ECHO_BLEG); | |||
3557 | } else if (!strcasecmp(argv[3], "aleg")) { | |||
3558 | flags |= SMF_ECHO_ALEG; | |||
3559 | } else if (!strcasecmp(argv[3], "bleg")) { | |||
3560 | flags |= SMF_ECHO_BLEG; | |||
3561 | } | |||
3562 | } else { | |||
3563 | flags |= SMF_ECHO_ALEG; | |||
3564 | } | |||
3565 | ||||
3566 | switch_ivr_schedule_broadcast(when, argv[1], argv[2], flags); | |||
3567 | stream->write_function(stream, "+OK Message scheduled\n"); | |||
3568 | } | |||
3569 | ||||
3570 | switch_safe_free(mycmd)if (mycmd) {free(mycmd);mycmd=((void*)0);}; | |||
3571 | return SWITCH_STATUS_SUCCESS; | |||
3572 | } | |||
3573 | ||||
3574 | #define HOLD_SYNTAX"[off|toggle] <uuid> [<display>]" "[off|toggle] <uuid> [<display>]" | |||
3575 | SWITCH_STANDARD_API(uuid_hold_function)static switch_status_t uuid_hold_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
3576 | { | |||
3577 | char *mycmd = NULL((void*)0), *argv[4] = { 0 }; | |||
3578 | int argc = 0; | |||
3579 | switch_status_t status = SWITCH_STATUS_FALSE; | |||
3580 | ||||
3581 | if (!zstr(cmd)_zstr(cmd) && (mycmd = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))))) { | |||
3582 | argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | |||
3583 | } | |||
3584 | ||||
3585 | if (zstr(cmd)_zstr(cmd) || argc < 1 || zstr(argv[0])_zstr(argv[0])) { | |||
3586 | stream->write_function(stream, "-USAGE: %s\n", HOLD_SYNTAX"[off|toggle] <uuid> [<display>]"); | |||
3587 | } else { | |||
3588 | if (!strcasecmp(argv[0], "off")) { | |||
3589 | status = switch_ivr_unhold_uuid(argv[1]); | |||
3590 | } else if (!strcasecmp(argv[0], "toggle")) { | |||
3591 | status = switch_ivr_hold_toggle_uuid(argv[1], argv[2], 1); | |||
3592 | } else { | |||
3593 | status = switch_ivr_hold_uuid(argv[0], argv[1], 1); | |||
3594 | } | |||
3595 | } | |||
3596 | ||||
3597 | if (status == SWITCH_STATUS_SUCCESS) { | |||
3598 | stream->write_function(stream, "+OK Success\n"); | |||
3599 | } else { | |||
3600 | stream->write_function(stream, "-ERR Operation failed\n"); | |||
3601 | } | |||
3602 | ||||
3603 | switch_safe_free(mycmd)if (mycmd) {free(mycmd);mycmd=((void*)0);}; | |||
3604 | return SWITCH_STATUS_SUCCESS; | |||
3605 | } | |||
3606 | ||||
3607 | #define DISPLAY_SYNTAX"<uuid> <display>" "<uuid> <display>" | |||
3608 | SWITCH_STANDARD_API(uuid_display_function)static switch_status_t uuid_display_function ( const char *cmd , switch_core_session_t *session, switch_stream_handle_t *stream ) | |||
3609 | { | |||
3610 | char *mycmd = NULL((void*)0), *argv[2] = { 0 }; | |||
3611 | int argc = 0; | |||
3612 | switch_status_t status = SWITCH_STATUS_FALSE; | |||
3613 | ||||
3614 | if (!zstr(cmd)_zstr(cmd) && (mycmd = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))))) { | |||
3615 | argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | |||
3616 | } | |||
3617 | ||||
3618 | if (zstr(cmd)_zstr(cmd) || argc < 2 || zstr(argv[0])_zstr(argv[0]) || zstr(argv[1])_zstr(argv[1])) { | |||
3619 | stream->write_function(stream, "-USAGE: %s\n", DISPLAY_SYNTAX"<uuid> <display>"); | |||
3620 | goto end; | |||
3621 | } else { | |||
3622 | switch_core_session_message_t msg = { 0 }; | |||
3623 | switch_core_session_t *lsession = NULL((void*)0); | |||
3624 | ||||
3625 | msg.message_id = SWITCH_MESSAGE_INDICATE_DISPLAY; | |||
3626 | msg.string_arg = argv[1]; | |||
3627 | msg.from = __FILE__"mod_commands.c"; | |||
3628 | ||||
3629 | if ((lsession = switch_core_session_locate(argv[0])switch_core_session_perform_locate(argv[0], "mod_commands.c", (const char *)__func__, 3629))) { | |||
3630 | status = switch_core_session_receive_message(lsession, &msg)switch_core_session_perform_receive_message(lsession, &msg , "mod_commands.c", (const char *)__func__, 3630); | |||
3631 | switch_core_session_rwunlock(lsession); | |||
3632 | } | |||
3633 | } | |||
3634 | ||||
3635 | if (status == SWITCH_STATUS_SUCCESS) { | |||
3636 | stream->write_function(stream, "+OK Success\n"); | |||
3637 | } else { | |||
3638 | stream->write_function(stream, "-ERR Operation failed\n"); | |||
3639 | } | |||
3640 | ||||
3641 | end: | |||
3642 | ||||
3643 | switch_safe_free(mycmd)if (mycmd) {free(mycmd);mycmd=((void*)0);}; | |||
3644 | return SWITCH_STATUS_SUCCESS; | |||
3645 | } | |||
3646 | ||||
3647 | #define BUGLIST_SYNTAX"<uuid>" "<uuid>" | |||
3648 | SWITCH_STANDARD_API(uuid_buglist_function)static switch_status_t uuid_buglist_function ( const char *cmd , switch_core_session_t *session, switch_stream_handle_t *stream ) | |||
3649 | { | |||
3650 | char *mydata = NULL((void*)0), *argv[2] = { 0 }; | |||
3651 | int argc = 0; | |||
3652 | ||||
3653 | if (zstr(cmd)_zstr(cmd)) { | |||
3654 | goto error; | |||
3655 | } | |||
3656 | ||||
3657 | mydata = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))); | |||
3658 | switch_assert(mydata)((mydata) ? (void) (0) : __assert_fail ("mydata", "mod_commands.c" , 3658, __PRETTY_FUNCTION__)); | |||
3659 | ||||
3660 | argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | |||
3661 | ||||
3662 | if (argc < 1) { | |||
3663 | goto error; | |||
3664 | } | |||
3665 | if (argv[0]) { | |||
3666 | switch_core_session_t *lsession = NULL((void*)0); | |||
3667 | ||||
3668 | if ((lsession = switch_core_session_locate(argv[0])switch_core_session_perform_locate(argv[0], "mod_commands.c", (const char *)__func__, 3668))) { | |||
3669 | switch_core_media_bug_enumerate(lsession, stream); | |||
3670 | switch_core_session_rwunlock(lsession); | |||
3671 | } | |||
3672 | goto ok; | |||
3673 | } else { | |||
3674 | goto error; | |||
3675 | } | |||
3676 | ||||
3677 | error: | |||
3678 | stream->write_function(stream, "-USAGE: %s\n", BUGLIST_SYNTAX"<uuid>"); | |||
3679 | switch_safe_free(mydata)if (mydata) {free(mydata);mydata=((void*)0);}; | |||
3680 | return SWITCH_STATUS_SUCCESS; | |||
3681 | ok: | |||
3682 | switch_safe_free(mydata)if (mydata) {free(mydata);mydata=((void*)0);}; | |||
3683 | ||||
3684 | return SWITCH_STATUS_SUCCESS; | |||
3685 | } | |||
3686 | ||||
3687 | #define SIMPLIFY_SYNTAX"<uuid>" "<uuid>" | |||
3688 | SWITCH_STANDARD_API(uuid_simplify_function)static switch_status_t uuid_simplify_function ( const char *cmd , switch_core_session_t *session, switch_stream_handle_t *stream ) | |||
3689 | { | |||
3690 | char *mydata = NULL((void*)0), *argv[2] = { 0 }; | |||
3691 | int argc = 0; | |||
3692 | ||||
3693 | switch_status_t status = SWITCH_STATUS_FALSE; | |||
3694 | ||||
3695 | if (zstr(cmd)_zstr(cmd)) { | |||
3696 | goto error; | |||
3697 | } | |||
3698 | ||||
3699 | mydata = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))); | |||
3700 | switch_assert(mydata)((mydata) ? (void) (0) : __assert_fail ("mydata", "mod_commands.c" , 3700, __PRETTY_FUNCTION__)); | |||
3701 | ||||
3702 | argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | |||
3703 | ||||
3704 | if (argc < 1) { | |||
3705 | goto error; | |||
3706 | } | |||
3707 | if (argv[0]) { | |||
3708 | switch_core_session_message_t msg = { 0 }; | |||
3709 | switch_core_session_t *lsession = NULL((void*)0); | |||
3710 | ||||
3711 | msg.message_id = SWITCH_MESSAGE_INDICATE_SIMPLIFY; | |||
3712 | msg.string_arg = argv[0]; | |||
3713 | msg.from = __FILE__"mod_commands.c"; | |||
3714 | ||||
3715 | if ((lsession = switch_core_session_locate(argv[0])switch_core_session_perform_locate(argv[0], "mod_commands.c", (const char *)__func__, 3715))) { | |||
3716 | status = switch_core_session_receive_message(lsession, &msg)switch_core_session_perform_receive_message(lsession, &msg , "mod_commands.c", (const char *)__func__, 3716); | |||
3717 | switch_core_session_rwunlock(lsession); | |||
3718 | } | |||
3719 | goto ok; | |||
3720 | } else { | |||
3721 | goto error; | |||
3722 | } | |||
3723 | ||||
3724 | error: | |||
3725 | stream->write_function(stream, "-USAGE: %s\n", SIMPLIFY_SYNTAX"<uuid>"); | |||
3726 | switch_safe_free(mydata)if (mydata) {free(mydata);mydata=((void*)0);}; | |||
3727 | return SWITCH_STATUS_SUCCESS; | |||
3728 | ok: | |||
3729 | switch_safe_free(mydata)if (mydata) {free(mydata);mydata=((void*)0);}; | |||
3730 | ||||
3731 | if (status == SWITCH_STATUS_SUCCESS) { | |||
3732 | stream->write_function(stream, "+OK Success\n"); | |||
3733 | } else { | |||
3734 | stream->write_function(stream, "-ERR Operation failed\n"); | |||
3735 | } | |||
3736 | ||||
3737 | return SWITCH_STATUS_SUCCESS; | |||
3738 | } | |||
3739 | ||||
3740 | #define JITTERBUFFER_SYNTAX"<uuid> [0|<min_msec>[:<max_msec>]]" "<uuid> [0|<min_msec>[:<max_msec>]]" | |||
3741 | SWITCH_STANDARD_API(uuid_jitterbuffer_function)static switch_status_t uuid_jitterbuffer_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
3742 | { | |||
3743 | char *mydata = NULL((void*)0), *argv[2] = { 0 }; | |||
3744 | int argc = 0; | |||
3745 | ||||
3746 | switch_status_t status = SWITCH_STATUS_FALSE; | |||
3747 | ||||
3748 | if (zstr(cmd)_zstr(cmd)) { | |||
3749 | goto error; | |||
3750 | } | |||
3751 | ||||
3752 | mydata = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))); | |||
3753 | switch_assert(mydata)((mydata) ? (void) (0) : __assert_fail ("mydata", "mod_commands.c" , 3753, __PRETTY_FUNCTION__)); | |||
3754 | ||||
3755 | argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | |||
3756 | ||||
3757 | if (argc < 2) { | |||
3758 | goto error; | |||
3759 | } | |||
3760 | if (argv[1]) { | |||
3761 | switch_core_session_message_t msg = { 0 }; | |||
3762 | switch_core_session_t *lsession = NULL((void*)0); | |||
3763 | ||||
3764 | msg.message_id = SWITCH_MESSAGE_INDICATE_JITTER_BUFFER; | |||
3765 | msg.string_arg = argv[1]; | |||
3766 | msg.from = __FILE__"mod_commands.c"; | |||
3767 | ||||
3768 | if ((lsession = switch_core_session_locate(argv[0])switch_core_session_perform_locate(argv[0], "mod_commands.c", (const char *)__func__, 3768))) { | |||
3769 | status = switch_core_session_receive_message(lsession, &msg)switch_core_session_perform_receive_message(lsession, &msg , "mod_commands.c", (const char *)__func__, 3769); | |||
3770 | switch_core_session_rwunlock(lsession); | |||
3771 | } | |||
3772 | goto ok; | |||
3773 | } else { | |||
3774 | goto error; | |||
3775 | } | |||
3776 | ||||
3777 | error: | |||
3778 | stream->write_function(stream, "-USAGE: %s\n", JITTERBUFFER_SYNTAX"<uuid> [0|<min_msec>[:<max_msec>]]"); | |||
3779 | switch_safe_free(mydata)if (mydata) {free(mydata);mydata=((void*)0);}; | |||
3780 | return SWITCH_STATUS_SUCCESS; | |||
3781 | ok: | |||
3782 | switch_safe_free(mydata)if (mydata) {free(mydata);mydata=((void*)0);}; | |||
3783 | ||||
3784 | if (status == SWITCH_STATUS_SUCCESS) { | |||
3785 | stream->write_function(stream, "+OK Success\n"); | |||
3786 | } else { | |||
3787 | stream->write_function(stream, "-ERR Operation failed\n"); | |||
3788 | } | |||
3789 | ||||
3790 | return SWITCH_STATUS_SUCCESS; | |||
3791 | } | |||
3792 | ||||
3793 | ||||
3794 | #define PHONE_EVENT_SYNTAX"<uuid>" "<uuid>" | |||
3795 | SWITCH_STANDARD_API(uuid_phone_event_function)static switch_status_t uuid_phone_event_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
3796 | { | |||
3797 | switch_status_t status = SWITCH_STATUS_FALSE; | |||
3798 | char *mycmd = NULL((void*)0), *argv[2] = { 0 }; | |||
3799 | int argc = 0; | |||
3800 | ||||
3801 | if (!zstr(cmd)_zstr(cmd) && (mycmd = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))))) { | |||
3802 | argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | |||
3803 | } | |||
3804 | ||||
3805 | if (argc < 1) { | |||
3806 | stream->write_function(stream, "-USAGE: %s\n", PHONE_EVENT_SYNTAX"<uuid>"); | |||
3807 | } else { | |||
3808 | switch_core_session_message_t msg = { 0 }; | |||
3809 | switch_core_session_t *lsession = NULL((void*)0); | |||
3810 | ||||
3811 | msg.message_id = SWITCH_MESSAGE_INDICATE_PHONE_EVENT; | |||
3812 | msg.string_arg = argv[1]; | |||
3813 | msg.from = __FILE__"mod_commands.c"; | |||
3814 | ||||
3815 | if ((lsession = switch_core_session_locate(argv[0])switch_core_session_perform_locate(argv[0], "mod_commands.c", (const char *)__func__, 3815))) { | |||
3816 | status = switch_core_session_receive_message(lsession, &msg)switch_core_session_perform_receive_message(lsession, &msg , "mod_commands.c", (const char *)__func__, 3816); | |||
3817 | switch_core_session_rwunlock(lsession); | |||
3818 | } | |||
3819 | } | |||
3820 | ||||
3821 | if (status == SWITCH_STATUS_SUCCESS) { | |||
3822 | stream->write_function(stream, "+OK Success\n"); | |||
3823 | } else { | |||
3824 | stream->write_function(stream, "-ERR Operation failed\n"); | |||
3825 | } | |||
3826 | ||||
3827 | switch_safe_free(mycmd)if (mycmd) {free(mycmd);mycmd=((void*)0);}; | |||
3828 | ||||
3829 | return SWITCH_STATUS_SUCCESS; | |||
3830 | } | |||
3831 | ||||
3832 | #define SEND_MESSAGE_SYNTAX"<uuid> <message>" "<uuid> <message>" | |||
3833 | SWITCH_STANDARD_API(uuid_send_message_function)static switch_status_t uuid_send_message_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
3834 | { | |||
3835 | switch_status_t status = SWITCH_STATUS_FALSE; | |||
3836 | char *mycmd = NULL((void*)0), *argv[2] = { 0 }; | |||
3837 | int argc = 0; | |||
3838 | ||||
3839 | if (!zstr(cmd)_zstr(cmd) && (mycmd = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))))) { | |||
3840 | argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | |||
3841 | } | |||
3842 | ||||
3843 | if (argc < 2) { | |||
3844 | stream->write_function(stream, "-USAGE: %s\n", SEND_MESSAGE_SYNTAX"<uuid> <message>"); | |||
3845 | goto end; | |||
3846 | } else { | |||
3847 | switch_core_session_message_t msg = { 0 }; | |||
3848 | switch_core_session_t *lsession = NULL((void*)0); | |||
3849 | ||||
3850 | msg.message_id = SWITCH_MESSAGE_INDICATE_MESSAGE; | |||
3851 | msg.string_array_arg[2] = argv[1]; | |||
3852 | msg.from = __FILE__"mod_commands.c"; | |||
3853 | ||||
3854 | if ((lsession = switch_core_session_locate(argv[0])switch_core_session_perform_locate(argv[0], "mod_commands.c", (const char *)__func__, 3854))) { | |||
3855 | status = switch_core_session_receive_message(lsession, &msg)switch_core_session_perform_receive_message(lsession, &msg , "mod_commands.c", (const char *)__func__, 3855); | |||
3856 | switch_core_session_rwunlock(lsession); | |||
3857 | } else { | |||
3858 | stream->write_function(stream, "-ERR Unable to find session for UUID\n"); | |||
3859 | goto end; | |||
3860 | } | |||
3861 | } | |||
3862 | ||||
3863 | if (status == SWITCH_STATUS_SUCCESS) { | |||
3864 | stream->write_function(stream, "+OK Success\n"); | |||
3865 | } else { | |||
3866 | stream->write_function(stream, "-ERR Operation Failed\n"); | |||
3867 | } | |||
3868 | ||||
3869 | end: | |||
3870 | switch_safe_free(mycmd)if (mycmd) {free(mycmd);mycmd=((void*)0);}; | |||
3871 | ||||
3872 | return SWITCH_STATUS_SUCCESS; | |||
3873 | } | |||
3874 | ||||
3875 | #define INFO_SYNTAX"<uuid> [<mime_type> <mime_subtype>] <message>" "<uuid> [<mime_type> <mime_subtype>] <message>" | |||
3876 | SWITCH_STANDARD_API(uuid_send_info_function)static switch_status_t uuid_send_info_function ( const char * cmd, switch_core_session_t *session, switch_stream_handle_t * stream) | |||
3877 | { | |||
3878 | switch_status_t status = SWITCH_STATUS_FALSE; | |||
3879 | char *mycmd = NULL((void*)0), *argv[4] = { 0 }; | |||
3880 | int argc = 0; | |||
3881 | ||||
3882 | if (!zstr(cmd)_zstr(cmd) && (mycmd = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))))) { | |||
3883 | argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | |||
3884 | } | |||
3885 | ||||
3886 | if (argc < 1 || argc == 3) { | |||
3887 | stream->write_function(stream, "-USAGE: %s\n", INFO_SYNTAX"<uuid> [<mime_type> <mime_subtype>] <message>"); | |||
3888 | } else { | |||
3889 | switch_core_session_message_t msg = { 0 }; | |||
3890 | switch_core_session_t *lsession = NULL((void*)0); | |||
3891 | ||||
3892 | msg.message_id = SWITCH_MESSAGE_INDICATE_INFO; | |||
3893 | if (argc > 3) { | |||
3894 | msg.string_array_arg[0] = argv[1]; | |||
3895 | msg.string_array_arg[1] = argv[2]; | |||
3896 | msg.string_array_arg[2] = argv[3]; | |||
3897 | } else { | |||
3898 | msg.string_array_arg[2] = argv[1]; | |||
3899 | } | |||
3900 | msg.from = __FILE__"mod_commands.c"; | |||
3901 | ||||
3902 | if ((lsession = switch_core_session_locate(argv[0])switch_core_session_perform_locate(argv[0], "mod_commands.c", (const char *)__func__, 3902))) { | |||
3903 | status = switch_core_session_receive_message(lsession, &msg)switch_core_session_perform_receive_message(lsession, &msg , "mod_commands.c", (const char *)__func__, 3903); | |||
3904 | switch_core_session_rwunlock(lsession); | |||
3905 | } | |||
3906 | } | |||
3907 | ||||
3908 | if (status == SWITCH_STATUS_SUCCESS) { | |||
3909 | stream->write_function(stream, "+OK Success\n"); | |||
3910 | } else { | |||
3911 | stream->write_function(stream, "-ERR Operation Failed\n"); | |||
3912 | } | |||
3913 | ||||
3914 | switch_safe_free(mycmd)if (mycmd) {free(mycmd);mycmd=((void*)0);}; | |||
3915 | ||||
3916 | return SWITCH_STATUS_SUCCESS; | |||
3917 | } | |||
3918 | ||||
3919 | ||||
3920 | #define VIDEO_REFRESH_SYNTAX"<uuid>" "<uuid>" | |||
3921 | SWITCH_STANDARD_API(uuid_video_refresh_function)static switch_status_t uuid_video_refresh_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
3922 | { | |||
3923 | switch_status_t status = SWITCH_STATUS_FALSE; | |||
3924 | char *mycmd = NULL((void*)0), *argv[2] = { 0 }; | |||
3925 | int argc = 0; | |||
3926 | ||||
3927 | if (!zstr(cmd)_zstr(cmd) && (mycmd = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))))) { | |||
3928 | argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | |||
3929 | } | |||
3930 | ||||
3931 | if (argc < 1) { | |||
3932 | stream->write_function(stream, "-USAGE: %s\n", VIDEO_REFRESH_SYNTAX"<uuid>"); | |||
3933 | } else { | |||
3934 | switch_core_session_message_t msg = { 0 }; | |||
3935 | switch_core_session_t *lsession = NULL((void*)0); | |||
3936 | ||||
3937 | msg.message_id = SWITCH_MESSAGE_INDICATE_VIDEO_REFRESH_REQ; | |||
3938 | msg.string_array_arg[2] = argv[1]; | |||
3939 | msg.from = __FILE__"mod_commands.c"; | |||
3940 | ||||
3941 | if ((lsession = switch_core_session_locate(argv[0])switch_core_session_perform_locate(argv[0], "mod_commands.c", (const char *)__func__, 3941))) { | |||
3942 | status = switch_core_session_receive_message(lsession, &msg)switch_core_session_perform_receive_message(lsession, &msg , "mod_commands.c", (const char *)__func__, 3942); | |||
3943 | switch_core_session_rwunlock(lsession); | |||
3944 | } | |||
3945 | } | |||
3946 | ||||
3947 | if (status == SWITCH_STATUS_SUCCESS) { | |||
3948 | stream->write_function(stream, "+OK Success\n"); | |||
3949 | } else { | |||
3950 | stream->write_function(stream, "-ERR Operation Failed\n"); | |||
3951 | } | |||
3952 | ||||
3953 | switch_safe_free(mycmd)if (mycmd) {free(mycmd);mycmd=((void*)0);}; | |||
3954 | ||||
3955 | return SWITCH_STATUS_SUCCESS; | |||
3956 | } | |||
3957 | ||||
3958 | ||||
3959 | #define DEBUG_MEDIA_SYNTAX"<uuid> <read|write|both|vread|vwrite|vboth|all> <on|off>" "<uuid> <read|write|both|vread|vwrite|vboth|all> <on|off>" | |||
3960 | SWITCH_STANDARD_API(uuid_debug_media_function)static switch_status_t uuid_debug_media_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
3961 | { | |||
3962 | char *mycmd = NULL((void*)0), *argv[3] = { 0 }; | |||
3963 | int argc = 0; | |||
3964 | switch_status_t status = SWITCH_STATUS_FALSE; | |||
3965 | ||||
3966 | if (!zstr(cmd)_zstr(cmd) && (mycmd = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))))) { | |||
3967 | argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | |||
3968 | } | |||
3969 | ||||
3970 | if (zstr(cmd)_zstr(cmd) || argc < 3 || zstr(argv[0])_zstr(argv[0]) || zstr(argv[1])_zstr(argv[1]) || zstr(argv[2])_zstr(argv[2])) { | |||
3971 | stream->write_function(stream, "-USAGE: %s\n", DEBUG_MEDIA_SYNTAX"<uuid> <read|write|both|vread|vwrite|vboth|all> <on|off>"); | |||
3972 | goto done; | |||
3973 | } else { | |||
3974 | switch_core_session_message_t msg = { 0 }; | |||
3975 | switch_core_session_t *lsession = NULL((void*)0); | |||
3976 | ||||
3977 | msg.message_id = SWITCH_MESSAGE_INDICATE_DEBUG_MEDIA; | |||
3978 | msg.string_array_arg[0] = argv[1]; | |||
3979 | msg.string_array_arg[1] = argv[2]; | |||
3980 | msg.from = __FILE__"mod_commands.c"; | |||
3981 | ||||
3982 | if ((lsession = switch_core_session_locate(argv[0])switch_core_session_perform_locate(argv[0], "mod_commands.c", (const char *)__func__, 3982))) { | |||
3983 | if (!strcasecmp(argv[1], "all")) { | |||
3984 | msg.string_array_arg[0] = "both"; | |||
3985 | } | |||
3986 | ||||
3987 | again: | |||
3988 | status = switch_core_session_receive_message(lsession, &msg)switch_core_session_perform_receive_message(lsession, &msg , "mod_commands.c", (const char *)__func__, 3988); | |||
3989 | ||||
3990 | if (status == SWITCH_STATUS_SUCCESS && !strcasecmp(argv[1], "all") && !strcmp(msg.string_array_arg[0], "both")__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (msg.string_array_arg[0]) && __builtin_constant_p ("both" ) && (__s1_len = __builtin_strlen (msg.string_array_arg [0]), __s2_len = __builtin_strlen ("both"), (!((size_t)(const void *)((msg.string_array_arg[0]) + 1) - (size_t)(const void *)(msg.string_array_arg[0]) == 1) || __s1_len >= 4) && (!((size_t)(const void *)(("both") + 1) - (size_t)(const void *)("both") == 1) || __s2_len >= 4)) ? __builtin_strcmp (msg .string_array_arg[0], "both") : (__builtin_constant_p (msg.string_array_arg [0]) && ((size_t)(const void *)((msg.string_array_arg [0]) + 1) - (size_t)(const void *)(msg.string_array_arg[0]) == 1) && (__s1_len = __builtin_strlen (msg.string_array_arg [0]), __s1_len < 4) ? (__builtin_constant_p ("both") && ((size_t)(const void *)(("both") + 1) - (size_t)(const void * )("both") == 1) ? __builtin_strcmp (msg.string_array_arg[0], "both" ) : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) ("both"); int __result = (((const unsigned char *) (const char *) (msg.string_array_arg[0]))[0] - __s2[ 0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (msg.string_array_arg [0]))[1] - __s2[1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (msg .string_array_arg[0]))[2] - __s2[2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (msg.string_array_arg[0]))[3] - __s2[3]); } } __result; } ))) : (__builtin_constant_p ("both") && ((size_t)(const void *)(("both") + 1) - (size_t)(const void *)("both") == 1) && (__s2_len = __builtin_strlen ("both"), __s2_len < 4) ? (__builtin_constant_p (msg.string_array_arg[0]) && ((size_t)(const void *)((msg.string_array_arg[0]) + 1) - (size_t )(const void *)(msg.string_array_arg[0]) == 1) ? __builtin_strcmp (msg.string_array_arg[0], "both") : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (msg.string_array_arg[0]); int __result = (((const unsigned char *) (const char *) ("both"))[0] - __s2[0]); if (__s2_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) ("both"))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) ("both"))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) ("both"))[3] - __s2[3]); } } __result; })) )) : __builtin_strcmp (msg.string_array_arg[0], "both")))); } )) { | |||
3991 | msg.string_array_arg[0] = "vboth"; | |||
3992 | goto again; | |||
3993 | } | |||
3994 | ||||
3995 | switch_core_session_rwunlock(lsession); | |||
3996 | } | |||
3997 | } | |||
3998 | ||||
3999 | if (status == SWITCH_STATUS_SUCCESS) { | |||
4000 | stream->write_function(stream, "+OK Success\n"); | |||
4001 | } else { | |||
4002 | stream->write_function(stream, "-ERR Operation failed\n"); | |||
4003 | } | |||
4004 | ||||
4005 | done: | |||
4006 | ||||
4007 | switch_safe_free(mycmd)if (mycmd) {free(mycmd);mycmd=((void*)0);}; | |||
4008 | return SWITCH_STATUS_SUCCESS; | |||
4009 | } | |||
4010 | ||||
4011 | #define UUID_SYNTAX"<uuid> <other_uuid>" "<uuid> <other_uuid>" | |||
4012 | SWITCH_STANDARD_API(uuid_bridge_function)static switch_status_t uuid_bridge_function ( const char *cmd , switch_core_session_t *session, switch_stream_handle_t *stream ) | |||
4013 | { | |||
4014 | char *mycmd = NULL((void*)0), *argv[4] = { 0 }; | |||
4015 | int argc = 0; | |||
4016 | ||||
4017 | if (!zstr(cmd)_zstr(cmd) && (mycmd = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))))) { | |||
4018 | argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | |||
4019 | } | |||
4020 | ||||
4021 | if (zstr(cmd)_zstr(cmd) || argc < 2) { | |||
4022 | stream->write_function(stream, "-USAGE: %s\n", UUID_SYNTAX"<uuid> <other_uuid>"); | |||
4023 | } else { | |||
4024 | switch_status_t status; | |||
4025 | char *who = NULL((void*)0); | |||
4026 | ||||
4027 | if ((status = switch_ivr_uuid_bridge(argv[0], argv[1])) != SWITCH_STATUS_SUCCESS) { | |||
4028 | if (argv[2]) { | |||
4029 | if ((status = switch_ivr_uuid_bridge(argv[0], argv[2])) == SWITCH_STATUS_SUCCESS) { | |||
4030 | who = argv[2]; | |||
4031 | } | |||
4032 | } | |||
4033 | } else { | |||
4034 | who = argv[1]; | |||
4035 | } | |||
4036 | ||||
4037 | if (status == SWITCH_STATUS_SUCCESS) { | |||
4038 | stream->write_function(stream, "+OK %s\n", who); | |||
4039 | } else { | |||
4040 | stream->write_function(stream, "-ERR Invalid uuid\n"); | |||
4041 | } | |||
4042 | } | |||
4043 | ||||
4044 | switch_safe_free(mycmd)if (mycmd) {free(mycmd);mycmd=((void*)0);}; | |||
4045 | return SWITCH_STATUS_SUCCESS; | |||
4046 | } | |||
4047 | ||||
4048 | #define SESS_REC_SYNTAX"<uuid> [start|stop|mask|unmask] <path> [<limit>]" "<uuid> [start|stop|mask|unmask] <path> [<limit>]" | |||
4049 | SWITCH_STANDARD_API(session_record_function)static switch_status_t session_record_function ( const char * cmd, switch_core_session_t *session, switch_stream_handle_t * stream) | |||
4050 | { | |||
4051 | switch_core_session_t *rsession = NULL((void*)0); | |||
4052 | char *mycmd = NULL((void*)0), *argv[4] = { 0 }; | |||
4053 | char *uuid = NULL((void*)0), *action = NULL((void*)0), *path = NULL((void*)0); | |||
4054 | int argc = 0; | |||
4055 | uint32_t limit = 0; | |||
4056 | ||||
4057 | if (zstr(cmd)_zstr(cmd)) { | |||
4058 | goto usage; | |||
4059 | } | |||
4060 | ||||
4061 | if (!(mycmd = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))))) { | |||
4062 | goto usage; | |||
4063 | } | |||
4064 | ||||
4065 | if ((argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) < 3) { | |||
4066 | goto usage; | |||
4067 | } | |||
4068 | ||||
4069 | uuid = argv[0]; | |||
4070 | action = argv[1]; | |||
4071 | path = argv[2]; | |||
4072 | limit = argv[3] ? atoi(argv[3]) : 0; | |||
4073 | ||||
4074 | if (zstr(uuid)_zstr(uuid) || zstr(action)_zstr(action) || zstr(path)_zstr(path)) { | |||
4075 | goto usage; | |||
4076 | } | |||
4077 | ||||
4078 | if (!(rsession = switch_core_session_locate(uuid)switch_core_session_perform_locate(uuid, "mod_commands.c", (const char *)__func__, 4078))) { | |||
4079 | stream->write_function(stream, "-ERR Cannot locate session!\n"); | |||
4080 | goto done; | |||
4081 | } | |||
4082 | ||||
4083 | if (!strcasecmp(action, "start")) { | |||
4084 | if (switch_ivr_record_session(rsession, path, limit, NULL((void*)0)) != SWITCH_STATUS_SUCCESS) { | |||
4085 | stream->write_function(stream, "-ERR Cannot record session!\n"); | |||
4086 | } else { | |||
4087 | stream->write_function(stream, "+OK Success\n"); | |||
4088 | } | |||
4089 | } else if (!strcasecmp(action, "stop")) { | |||
4090 | if (switch_ivr_stop_record_session(rsession, path) != SWITCH_STATUS_SUCCESS) { | |||
4091 | stream->write_function(stream, "-ERR Cannot stop record session!\n"); | |||
4092 | } else { | |||
4093 | stream->write_function(stream, "+OK Success\n"); | |||
4094 | } | |||
4095 | } else if (!strcasecmp(action, "mask")) { | |||
4096 | if (switch_ivr_record_session_mask(rsession, path, SWITCH_TRUE) != SWITCH_STATUS_SUCCESS) { | |||
4097 | stream->write_function(stream, "-ERR Cannot mask recording session!\n"); | |||
4098 | } else { | |||
4099 | stream->write_function(stream, "+OK Success\n"); | |||
4100 | } | |||
4101 | } else if (!strcasecmp(action, "unmask")) { | |||
4102 | if (switch_ivr_record_session_mask(rsession, path, SWITCH_FALSE) != SWITCH_STATUS_SUCCESS) { | |||
4103 | stream->write_function(stream, "-ERR Cannot unmask recording session!\n"); | |||
4104 | } else { | |||
4105 | stream->write_function(stream, "+OK Success\n"); | |||
4106 | } | |||
4107 | } else { | |||
4108 | goto usage; | |||
4109 | } | |||
4110 | ||||
4111 | goto done; | |||
4112 | ||||
4113 | usage: | |||
4114 | stream->write_function(stream, "-USAGE: %s\n", SESS_REC_SYNTAX"<uuid> [start|stop|mask|unmask] <path> [<limit>]"); | |||
4115 | ||||
4116 | done: | |||
4117 | if (rsession) { | |||
4118 | switch_core_session_rwunlock(rsession); | |||
4119 | } | |||
4120 | ||||
4121 | switch_safe_free(mycmd)if (mycmd) {free(mycmd);mycmd=((void*)0);}; | |||
4122 | return SWITCH_STATUS_SUCCESS; | |||
4123 | } | |||
4124 | ||||
4125 | #define DISPLACE_SYNTAX"<uuid> [start|stop] <path> [<limit>] [mux]" "<uuid> [start|stop] <path> [<limit>] [mux]" | |||
4126 | SWITCH_STANDARD_API(session_displace_function)static switch_status_t session_displace_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
4127 | { | |||
4128 | switch_core_session_t *rsession = NULL((void*)0); | |||
4129 | char *mycmd = NULL((void*)0), *argv[5] = { 0 }; | |||
4130 | char *uuid = NULL((void*)0), *action = NULL((void*)0), *path = NULL((void*)0); | |||
4131 | int argc = 0; | |||
4132 | uint32_t limit = 0; | |||
4133 | char *flags = NULL((void*)0); | |||
4134 | ||||
4135 | if (zstr(cmd)_zstr(cmd) || !(mycmd = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))))) { | |||
4136 | goto usage; | |||
4137 | } | |||
4138 | ||||
4139 | if ((argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) < 3) { | |||
4140 | goto usage; | |||
4141 | } | |||
4142 | ||||
4143 | uuid = argv[0]; | |||
4144 | action = argv[1]; | |||
4145 | path = argv[2]; | |||
4146 | limit = argv[3] ? atoi(argv[3]) : 0; | |||
4147 | flags = argv[4]; | |||
4148 | ||||
4149 | if (zstr(uuid)_zstr(uuid) || zstr(action)_zstr(action) || zstr(path)_zstr(path)) { | |||
4150 | goto usage; | |||
4151 | } | |||
4152 | ||||
4153 | if (!(rsession = switch_core_session_locate(uuid)switch_core_session_perform_locate(uuid, "mod_commands.c", (const char *)__func__, 4153))) { | |||
4154 | stream->write_function(stream, "-ERR Cannot locate session!\n"); | |||
4155 | goto done; | |||
4156 | } | |||
4157 | ||||
4158 | if (!strcasecmp(action, "start")) { | |||
4159 | if (switch_ivr_displace_session(rsession, path, limit, flags) != SWITCH_STATUS_SUCCESS) { | |||
4160 | stream->write_function(stream, "-ERR Cannot displace session!\n"); | |||
4161 | } else { | |||
4162 | stream->write_function(stream, "+OK Success\n"); | |||
4163 | } | |||
4164 | } else if (!strcasecmp(action, "stop")) { | |||
4165 | if (switch_ivr_stop_displace_session(rsession, path) != SWITCH_STATUS_SUCCESS) { | |||
4166 | stream->write_function(stream, "-ERR Cannot stop displace session!\n"); | |||
4167 | } else { | |||
4168 | stream->write_function(stream, "+OK Success\n"); | |||
4169 | } | |||
4170 | } else { | |||
4171 | goto usage; | |||
4172 | } | |||
4173 | ||||
4174 | goto done; | |||
4175 | ||||
4176 | usage: | |||
4177 | stream->write_function(stream, "-USAGE: %s\n", DISPLACE_SYNTAX"<uuid> [start|stop] <path> [<limit>] [mux]"); | |||
4178 | ||||
4179 | done: | |||
4180 | if (rsession) { | |||
4181 | switch_core_session_rwunlock(rsession); | |||
4182 | } | |||
4183 | ||||
4184 | switch_safe_free(mycmd)if (mycmd) {free(mycmd);mycmd=((void*)0);}; | |||
4185 | return SWITCH_STATUS_SUCCESS; | |||
4186 | } | |||
4187 | ||||
4188 | ||||
4189 | #define AUDIO_SYNTAX"<uuid> [start [read|write] [mute|level <level>]|stop]" "<uuid> [start [read|write] [mute|level <level>]|stop]" | |||
4190 | SWITCH_STANDARD_API(session_audio_function)static switch_status_t session_audio_function ( const char *cmd , switch_core_session_t *session, switch_stream_handle_t *stream ) | |||
4191 | { | |||
4192 | switch_core_session_t *u_session = NULL((void*)0); | |||
4193 | char *mycmd = NULL((void*)0); | |||
4194 | int fail = 0; | |||
4195 | int nochannel = 0; | |||
4196 | int argc = 0; | |||
4197 | char *argv[5] = { 0 }; | |||
4198 | int level; | |||
4199 | ||||
4200 | if (zstr(cmd)_zstr(cmd)) { | |||
4201 | fail++; | |||
4202 | goto done; | |||
4203 | } | |||
4204 | ||||
4205 | mycmd = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))); | |||
4206 | argc = switch_split(mycmd, ' ', argv)switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof (argv[0]))); | |||
4207 | ||||
4208 | if (argc < 2) { | |||
4209 | fail++; | |||
4210 | goto done; | |||
4211 | } | |||
4212 | ||||
4213 | if (!(u_session = switch_core_session_locate(argv[0])switch_core_session_perform_locate(argv[0], "mod_commands.c", (const char *)__func__, 4213))) { | |||
4214 | nochannel++; | |||
4215 | goto done; | |||
4216 | } | |||
4217 | ||||
4218 | if (!strcasecmp(argv[1], "stop")) { | |||
4219 | switch_ivr_stop_session_audio(u_session); | |||
4220 | goto done; | |||
4221 | } | |||
4222 | ||||
4223 | if (strcasecmp(argv[1], "start") || argc < 5 || (strcasecmp(argv[2], "read") && strcasecmp(argv[2], "write"))) { | |||
4224 | fail++; | |||
4225 | goto done; | |||
4226 | } | |||
4227 | ||||
4228 | level = atoi(argv[4]); | |||
4229 | ||||
4230 | if (!strcasecmp(argv[3], "mute")) { | |||
4231 | switch_ivr_session_audio(u_session, "mute", argv[2], level); | |||
4232 | } else if (!strcasecmp(argv[3], "level")) { | |||
4233 | switch_ivr_session_audio(u_session, "level", argv[2], level); | |||
4234 | } else { | |||
4235 | fail++; | |||
4236 | } | |||
4237 | ||||
4238 | done: | |||
4239 | ||||
4240 | if (u_session) { | |||
4241 | switch_core_session_rwunlock(u_session); | |||
4242 | } | |||
4243 | ||||
4244 | switch_safe_free(mycmd)if (mycmd) {free(mycmd);mycmd=((void*)0);}; | |||
4245 | ||||
4246 | if (nochannel) { | |||
4247 | stream->write_function(stream, "-ERR No such channel!\n"); | |||
4248 | } else if (fail) { | |||
4249 | stream->write_function(stream, "-USAGE: %s\n", AUDIO_SYNTAX"<uuid> [start [read|write] [mute|level <level>]|stop]"); | |||
4250 | } else { | |||
4251 | stream->write_function(stream, "+OK\n"); | |||
4252 | } | |||
4253 | ||||
4254 | return SWITCH_STATUS_SUCCESS; | |||
4255 | } | |||
4256 | ||||
4257 | #define BREAK_SYNTAX"<uuid> [all]" "<uuid> [all]" | |||
4258 | SWITCH_STANDARD_API(break_function)static switch_status_t break_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
4259 | { | |||
4260 | switch_core_session_t *psession = NULL((void*)0), *qsession = NULL((void*)0); | |||
4261 | char *mycmd = NULL((void*)0), *flag; | |||
4262 | switch_channel_t *channel = NULL((void*)0), *qchannel = NULL((void*)0); | |||
4263 | switch_status_t status = SWITCH_STATUS_SUCCESS; | |||
4264 | int all = 0; | |||
4265 | int both = 0; | |||
4266 | ||||
4267 | if (zstr(cmd)_zstr(cmd)) { | |||
4268 | stream->write_function(stream, "-USAGE: %s\n", BREAK_SYNTAX"<uuid> [all]"); | |||
4269 | goto done; | |||
4270 | } | |||
4271 | ||||
4272 | mycmd = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))); | |||
4273 | switch_assert(mycmd)((mycmd) ? (void) (0) : __assert_fail ("mycmd", "mod_commands.c" , 4273, __PRETTY_FUNCTION__)); | |||
4274 | ||||
4275 | if ((flag = strchr(mycmd, ' ')(__extension__ (__builtin_constant_p (' ') && !__builtin_constant_p (mycmd) && (' ') == '\0' ? (char *) __rawmemchr (mycmd , ' ') : __builtin_strchr (mycmd, ' '))))) { | |||
4276 | *flag++ = '\0'; | |||
4277 | } | |||
4278 | ||||
4279 | if (!(psession = switch_core_session_locate(mycmd)switch_core_session_perform_locate(mycmd, "mod_commands.c", ( const char *)__func__, 4279))) { | |||
4280 | stream->write_function(stream, "-ERR No such channel!\n"); | |||
4281 | goto done; | |||
4282 | } | |||
4283 | ||||
4284 | if (flag) { | |||
4285 | if (strstr(flag, "all")) { | |||
4286 | all++; | |||
4287 | } | |||
4288 | if (strstr(flag, "both")) { | |||
4289 | both++; | |||
4290 | } | |||
4291 | } | |||
4292 | ||||
4293 | channel = switch_core_session_get_channel(psession); | |||
4294 | ||||
4295 | if (both) { | |||
4296 | const char *quuid = switch_channel_get_partner_uuid(channel); | |||
4297 | if (quuid && (qsession = switch_core_session_locate(quuid)switch_core_session_perform_locate(quuid, "mod_commands.c", ( const char *)__func__, 4297))) { | |||
4298 | qchannel = switch_core_session_get_channel(qsession); | |||
4299 | } | |||
4300 | } | |||
4301 | ||||
4302 | if (all) { | |||
4303 | switch_core_session_flush_private_events(psession); | |||
4304 | if (qsession) { | |||
4305 | switch_core_session_flush_private_events(qsession); | |||
4306 | } | |||
4307 | } | |||
4308 | ||||
4309 | ||||
4310 | ||||
4311 | if (switch_channel_test_flag(channel, CF_BROADCAST)) { | |||
4312 | switch_channel_stop_broadcast(channel)for(;;) {if (switch_channel_test_flag(channel, CF_BROADCAST)) {switch_channel_set_flag_value(channel, CF_STOP_BROADCAST, 1 ); switch_channel_set_flag_value(channel, CF_BREAK, 1); } break ;}; | |||
4313 | } else { | |||
4314 | switch_channel_set_flag_value(channel, CF_BREAK, all ? 2 : 1); | |||
4315 | } | |||
4316 | ||||
4317 | if (qchannel) { | |||
4318 | if (switch_channel_test_flag(qchannel, CF_BROADCAST)) { | |||
4319 | switch_channel_stop_broadcast(qchannel)for(;;) {if (switch_channel_test_flag(qchannel, CF_BROADCAST) ) {switch_channel_set_flag_value(qchannel, CF_STOP_BROADCAST, 1); switch_channel_set_flag_value(qchannel, CF_BREAK, 1); } break ;}; | |||
4320 | } else { | |||
4321 | switch_channel_set_flag_value(qchannel, CF_BREAK, all ? 2 : 1); | |||
4322 | } | |||
4323 | } | |||
4324 | ||||
4325 | done: | |||
4326 | ||||
4327 | if (psession) { | |||
4328 | switch_core_session_rwunlock(psession); | |||
4329 | } | |||
4330 | ||||
4331 | if (qsession) { | |||
4332 | switch_core_session_rwunlock(qsession); | |||
4333 | } | |||
4334 | ||||
4335 | switch_safe_free(mycmd)if (mycmd) {free(mycmd);mycmd=((void*)0);}; | |||
4336 | ||||
4337 | return status; | |||
4338 | } | |||
4339 | ||||
4340 | #define PAUSE_SYNTAX"<uuid> <on|off>" "<uuid> <on|off>" | |||
4341 | SWITCH_STANDARD_API(pause_function)static switch_status_t pause_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
4342 | { | |||
4343 | switch_core_session_t *psession = NULL((void*)0); | |||
4344 | char *mycmd = NULL((void*)0), *argv[4] = { 0 }; | |||
4345 | int argc = 0; | |||
4346 | ||||
4347 | if (!zstr(cmd)_zstr(cmd) && (mycmd = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))))) { | |||
4348 | argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | |||
4349 | } | |||
4350 | ||||
4351 | if (zstr(cmd)_zstr(cmd) || argc < 2 || zstr(argv[0])_zstr(argv[0])) { | |||
4352 | stream->write_function(stream, "-USAGE: %s\n", PAUSE_SYNTAX"<uuid> <on|off>"); | |||
4353 | } else { | |||
4354 | char *uuid = argv[0]; | |||
4355 | char *dest = argv[1]; | |||
4356 | ||||
4357 | if ((psession = switch_core_session_locate(uuid)switch_core_session_perform_locate(uuid, "mod_commands.c", (const char *)__func__, 4357))) { | |||
4358 | switch_channel_t *channel = switch_core_session_get_channel(psession); | |||
4359 | ||||
4360 | if (!strcasecmp(dest, "on")) { | |||
4361 | switch_channel_set_flag(channel, CF_HOLD)switch_channel_set_flag_value(channel, CF_HOLD, 1); | |||
4362 | } else { | |||
4363 | switch_channel_clear_flag(channel, CF_HOLD); | |||
4364 | } | |||
4365 | ||||
4366 | switch_core_session_rwunlock(psession); | |||
4367 | ||||
4368 | } else { | |||
4369 | stream->write_function(stream, "-ERR No such channel!\n"); | |||
4370 | } | |||
4371 | } | |||
4372 | ||||
4373 | switch_safe_free(mycmd)if (mycmd) {free(mycmd);mycmd=((void*)0);}; | |||
4374 | return SWITCH_STATUS_SUCCESS; | |||
4375 | } | |||
4376 | ||||
4377 | #define ORIGINATE_SYNTAX"<call url> <exten>|&<application_name>(<app_args>) [<dialplan>] [<context>] [<cid_name>] [<cid_num>] [<timeout_sec>]" "<call url> <exten>|&<application_name>(<app_args>) [<dialplan>] [<context>] [<cid_name>] [<cid_num>] [<timeout_sec>]" | |||
4378 | SWITCH_STANDARD_API(originate_function)static switch_status_t originate_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
4379 | { | |||
4380 | switch_channel_t *caller_channel; | |||
4381 | switch_core_session_t *caller_session = NULL((void*)0); | |||
4382 | char *mycmd = NULL((void*)0), *argv[10] = { 0 }; | |||
4383 | int i = 0, x, argc = 0; | |||
4384 | char *aleg, *exten, *dp, *context, *cid_name, *cid_num; | |||
4385 | uint32_t timeout = 60; | |||
4386 | switch_call_cause_t cause = SWITCH_CAUSE_NORMAL_CLEARING; | |||
4387 | switch_status_t status = SWITCH_STATUS_SUCCESS; | |||
4388 | ||||
4389 | if (zstr(cmd)_zstr(cmd)) { | |||
4390 | stream->write_function(stream, "-USAGE: %s\n", ORIGINATE_SYNTAX"<call url> <exten>|&<application_name>(<app_args>) [<dialplan>] [<context>] [<cid_name>] [<cid_num>] [<timeout_sec>]"); | |||
4391 | return SWITCH_STATUS_SUCCESS; | |||
4392 | } | |||
4393 | ||||
4394 | /* log warning if part of ongoing session, as we'll block the session */ | |||
4395 | if (session){ | |||
4396 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "mod_commands.c", (const char *)__func__ , 4396, (const char*)(session), SWITCH_LOG_NOTICE, "Originate can take 60 seconds to complete, and blocks the existing session. Do not confuse with a lockup.\n"); | |||
4397 | } | |||
4398 | ||||
4399 | mycmd = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))); | |||
4400 | switch_assert(mycmd)((mycmd) ? (void) (0) : __assert_fail ("mycmd", "mod_commands.c" , 4400, __PRETTY_FUNCTION__)); | |||
4401 | argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | |||
4402 | ||||
4403 | if (argc < 2 || argc > 7) { | |||
4404 | stream->write_function(stream, "-USAGE: %s\n", ORIGINATE_SYNTAX"<call url> <exten>|&<application_name>(<app_args>) [<dialplan>] [<context>] [<cid_name>] [<cid_num>] [<timeout_sec>]"); | |||
4405 | goto done; | |||
4406 | } | |||
4407 | ||||
4408 | for (x = 0; x < argc && argv[x]; x++) { | |||
4409 | if (!strcasecmp(argv[x], "undef")) { | |||
4410 | argv[x] = NULL((void*)0); | |||
4411 | } | |||
4412 | } | |||
4413 | ||||
4414 | aleg = argv[i++]; | |||
4415 | exten = argv[i++]; | |||
4416 | dp = argv[i++]; | |||
4417 | context = argv[i++]; | |||
4418 | cid_name = argv[i++]; | |||
4419 | cid_num = argv[i++]; | |||
4420 | ||||
4421 | if (!dp) { | |||
4422 | dp = "XML"; | |||
4423 | } | |||
4424 | ||||
4425 | if (!context) { | |||
4426 | context = "default"; | |||
4427 | } | |||
4428 | ||||
4429 | if (argv[6]) { | |||
4430 | timeout = atoi(argv[6]); | |||
4431 | } | |||
4432 | ||||
4433 | if (switch_ivr_originate(NULL((void*)0), &caller_session, &cause, aleg, timeout, NULL((void*)0), cid_name, cid_num, NULL((void*)0), NULL((void*)0), SOF_NONE, NULL((void*)0)) != SWITCH_STATUS_SUCCESS | |||
4434 | || !caller_session) { | |||
4435 | stream->write_function(stream, "-ERR %s\n", switch_channel_cause2str(cause)); | |||
4436 | goto done; | |||
4437 | } | |||
4438 | ||||
4439 | caller_channel = switch_core_session_get_channel(caller_session); | |||
4440 | ||||
4441 | if (*exten == '&' && *(exten + 1)) { | |||
4442 | switch_caller_extension_t *extension = NULL((void*)0); | |||
4443 | char *app_name = switch_core_session_strdup(caller_session, (exten + 1))switch_core_perform_session_strdup(caller_session, (exten + 1 ), "mod_commands.c", (const char *)__func__, 4443); | |||
4444 | char *arg = NULL((void*)0), *e; | |||
4445 | ||||
4446 | if ((e = strchr(app_name, ')')(__extension__ (__builtin_constant_p (')') && !__builtin_constant_p (app_name) && (')') == '\0' ? (char *) __rawmemchr ( app_name, ')') : __builtin_strchr (app_name, ')'))))) { | |||
4447 | *e = '\0'; | |||
4448 | } | |||
4449 | ||||
4450 | if ((arg = strchr(app_name, '(')(__extension__ (__builtin_constant_p ('(') && !__builtin_constant_p (app_name) && ('(') == '\0' ? (char *) __rawmemchr ( app_name, '(') : __builtin_strchr (app_name, '('))))) { | |||
4451 | *arg++ = '\0'; | |||
4452 | } | |||
4453 | ||||
4454 | if ((extension = switch_caller_extension_new(caller_session, app_name, arg)) == 0) { | |||
4455 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "mod_commands.c", (const char *)__func__ , 4455, (const char*)(session), SWITCH_LOG_CRIT, "Memory Error!\n"); | |||
4456 | abort(); | |||
4457 | } | |||
4458 | switch_caller_extension_add_application(caller_session, extension, app_name, arg); | |||
4459 | switch_channel_set_caller_extension(caller_channel, extension); | |||
4460 | switch_channel_set_state(caller_channel, CS_EXECUTE)switch_channel_perform_set_state(caller_channel, "mod_commands.c" , (const char *)__func__, 4460, CS_EXECUTE); | |||
4461 | } else { | |||
4462 | switch_ivr_session_transfer(caller_session, exten, dp, context); | |||
4463 | } | |||
4464 | ||||
4465 | stream->write_function(stream, "+OK %s\n", switch_core_session_get_uuid(caller_session)); | |||
4466 | ||||
4467 | switch_core_session_rwunlock(caller_session); | |||
4468 | ||||
4469 | done: | |||
4470 | switch_safe_free(mycmd)if (mycmd) {free(mycmd);mycmd=((void*)0);}; | |||
4471 | return status; | |||
4472 | } | |||
4473 | ||||
4474 | SWITCH_STANDARD_API(sched_del_function)static switch_status_t sched_del_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
4475 | { | |||
4476 | uint32_t cnt = 0; | |||
4477 | ||||
4478 | if (!cmd) { | |||
4479 | stream->write_function(stream, "-ERR Invalid syntax\n"); | |||
4480 | return SWITCH_STATUS_SUCCESS; | |||
4481 | } | |||
4482 | ||||
4483 | if (switch_is_digit_string(cmd)) { | |||
4484 | int64_t tmp; | |||
4485 | tmp = (uint32_t) atoi(cmd); | |||
4486 | if (tmp > 0) { | |||
4487 | cnt = switch_scheduler_del_task_id((uint32_t) tmp); | |||
4488 | } | |||
4489 | } else { | |||
4490 | cnt = switch_scheduler_del_task_group(cmd); | |||
4491 | } | |||
4492 | ||||
4493 | stream->write_function(stream, "+OK Deleted: %u\n", cnt); | |||
4494 | ||||
4495 | return SWITCH_STATUS_SUCCESS; | |||
4496 | } | |||
4497 | ||||
4498 | SWITCH_STANDARD_API(xml_wrap_api_function)static switch_status_t xml_wrap_api_function ( const char *cmd , switch_core_session_t *session, switch_stream_handle_t *stream ) | |||
4499 | { | |||
4500 | char *dcommand, *edata = NULL((void*)0), *send = NULL((void*)0), *command, *arg = NULL((void*)0); | |||
4501 | switch_stream_handle_t mystream = { 0 }; | |||
4502 | int encoded = 0, elen = 0; | |||
4503 | ||||
4504 | if (!cmd) { | |||
4505 | stream->write_function(stream, "-ERR Invalid syntax\n"); | |||
4506 | return SWITCH_STATUS_SUCCESS; | |||
4507 | } | |||
4508 | ||||
4509 | if ((dcommand = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))))) { | |||
4510 | if (!strncasecmp(dcommand, "encoded ", 8)) { | |||
4511 | encoded++; | |||
4512 | command = dcommand + 8; | |||
4513 | } else { | |||
4514 | command = dcommand; | |||
4515 | } | |||
4516 | ||||
4517 | if ((arg = strchr(command, ' ')(__extension__ (__builtin_constant_p (' ') && !__builtin_constant_p (command) && (' ') == '\0' ? (char *) __rawmemchr (command , ' ') : __builtin_strchr (command, ' '))))) { | |||
4518 | *arg++ = '\0'; | |||
4519 | } | |||
4520 | SWITCH_STANDARD_STREAM(mystream)memset(&mystream, 0, sizeof(mystream)); mystream.data = malloc (1024); ((mystream.data) ? (void) (0) : __assert_fail ("mystream.data" , "mod_commands.c", 4520, __PRETTY_FUNCTION__)); memset(mystream .data, 0, 1024); mystream.end = mystream.data; mystream.data_size = 1024; mystream.write_function = switch_console_stream_write ; mystream.raw_write_function = switch_console_stream_raw_write ; mystream.alloc_len = 1024; mystream.alloc_chunk = 1024; | |||
4521 | switch_api_execute(command, arg, NULL((void*)0), &mystream); | |||
4522 | ||||
4523 | if (mystream.data) { | |||
4524 | if (encoded) { | |||
4525 | elen = (int) strlen(mystream.data) * 3 + 1; | |||
4526 | edata = malloc(elen); | |||
4527 | switch_assert(edata != NULL)((edata != ((void*)0)) ? (void) (0) : __assert_fail ("edata != ((void*)0)" , "mod_commands.c", 4527, __PRETTY_FUNCTION__)); | |||
4528 | memset(edata, 0, elen); | |||
4529 | switch_url_encode(mystream.data, edata, elen); | |||
4530 | send = edata; | |||
4531 | } else { | |||
4532 | send = mystream.data; | |||
4533 | } | |||
4534 | } | |||
4535 | ||||
4536 | stream->write_function(stream, "<result>\n" " <row id=\"1\">\n" " <data>%s</data>\n" " </row>\n" "</result>\n", send ? send : "ERROR"); | |||
4537 | switch_safe_free(mystream.data)if (mystream.data) {free(mystream.data);mystream.data=((void* )0);}; | |||
4538 | switch_safe_free(edata)if (edata) {free(edata);edata=((void*)0);}; | |||
4539 | free(dcommand); | |||
4540 | } | |||
4541 | ||||
4542 | return SWITCH_STATUS_SUCCESS; | |||
4543 | } | |||
4544 | ||||
4545 | struct api_task { | |||
4546 | uint32_t recur; | |||
4547 | char cmd[]; | |||
4548 | }; | |||
4549 | ||||
4550 | static void sch_api_callback(switch_scheduler_task_t *task) | |||
4551 | { | |||
4552 | char *cmd, *arg = NULL((void*)0); | |||
4553 | switch_stream_handle_t stream = { 0 }; | |||
4554 | struct api_task *api_task = (struct api_task *) task->cmd_arg; | |||
4555 | switch_assert(task)((task) ? (void) (0) : __assert_fail ("task", "mod_commands.c" , 4555, __PRETTY_FUNCTION__)); | |||
4556 | ||||
4557 | cmd = strdup(api_task->cmd)(__extension__ (__builtin_constant_p (api_task->cmd) && ((size_t)(const void *)((api_task->cmd) + 1) - (size_t)(const void *)(api_task->cmd) == 1) ? (((const char *) (api_task ->cmd))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen (api_task->cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, api_task->cmd, __len ); __retval; })) : __strdup (api_task->cmd))); | |||
4558 | switch_assert(cmd)((cmd) ? (void) (0) : __assert_fail ("cmd", "mod_commands.c", 4558, __PRETTY_FUNCTION__)); | |||
4559 | ||||
4560 | if ((arg = strchr(cmd, ' ')(__extension__ (__builtin_constant_p (' ') && !__builtin_constant_p (cmd) && (' ') == '\0' ? (char *) __rawmemchr (cmd, ' ' ) : __builtin_strchr (cmd, ' '))))) { | |||
4561 | *arg++ = '\0'; | |||
4562 | } | |||
4563 | ||||
4564 | SWITCH_STANDARD_STREAM(stream)memset(&stream, 0, sizeof(stream)); stream.data = malloc( 1024); ((stream.data) ? (void) (0) : __assert_fail ("stream.data" , "mod_commands.c", 4564, __PRETTY_FUNCTION__)); memset(stream .data, 0, 1024); stream.end = stream.data; stream.data_size = 1024; stream.write_function = switch_console_stream_write; stream .raw_write_function = switch_console_stream_raw_write; stream .alloc_len = 1024; stream.alloc_chunk = 1024; | |||
4565 | switch_api_execute(cmd, arg, NULL((void*)0), &stream); | |||
4566 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_commands.c", (const char *)__func__ , 4566, ((void*)0), SWITCH_LOG_DEBUG, "Command %s(%s):\n%s\n", cmd, switch_str_nil(arg)(arg ? arg : ""), switch_str_nil((char *) stream.data)((char *) stream.data ? (char *) stream.data : "")); | |||
4567 | switch_safe_free(stream.data)if (stream.data) {free(stream.data);stream.data=((void*)0);}; | |||
4568 | switch_safe_free(cmd)if (cmd) {free(cmd);cmd=((void*)0);}; | |||
4569 | ||||
4570 | if (api_task->recur) { | |||
4571 | task->runtime = switch_epoch_time_now(NULL((void*)0)) + api_task->recur; | |||
4572 | } | |||
4573 | } | |||
4574 | ||||
4575 | #define UNSCHED_SYNTAX"<task_id>" "<task_id>" | |||
4576 | SWITCH_STANDARD_API(unsched_api_function)static switch_status_t unsched_api_function ( const char *cmd , switch_core_session_t *session, switch_stream_handle_t *stream ) | |||
4577 | { | |||
4578 | uint32_t id; | |||
4579 | ||||
4580 | if (!cmd) { | |||
4581 | stream->write_function(stream, "-ERR Invalid syntax. USAGE: %s\n", UNSCHED_SYNTAX"<task_id>"); | |||
4582 | return SWITCH_STATUS_SUCCESS; | |||
4583 | } | |||
4584 | ||||
4585 | if ((id = (uint32_t) atol(cmd))) { | |||
4586 | stream->write_function(stream, "%s\n", switch_scheduler_del_task_id(id) ? "+OK" : "-ERR No such id"); | |||
4587 | } | |||
4588 | ||||
4589 | return SWITCH_STATUS_SUCCESS; | |||
4590 | } | |||
4591 | ||||
4592 | #define SCHED_SYNTAX"[+@]<time> <group_name> <command_string>[&]" "[+@]<time> <group_name> <command_string>[&]" | |||
4593 | SWITCH_STANDARD_API(sched_api_function)static switch_status_t sched_api_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
4594 | { | |||
4595 | char *tm = NULL((void*)0), *dcmd, *group; | |||
4596 | time_t when; | |||
4597 | struct api_task *api_task = NULL((void*)0); | |||
4598 | uint32_t recur = 0; | |||
4599 | int flags = SSHF_FREE_ARG; | |||
4600 | ||||
4601 | if (!cmd) { | |||
4602 | goto bad; | |||
4603 | } | |||
4604 | tm = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))); | |||
4605 | switch_assert(tm != NULL)((tm != ((void*)0)) ? (void) (0) : __assert_fail ("tm != ((void*)0)" , "mod_commands.c", 4605, __PRETTY_FUNCTION__)); | |||
4606 | ||||
4607 | if ((group = strchr(tm, ' ')(__extension__ (__builtin_constant_p (' ') && !__builtin_constant_p (tm) && (' ') == '\0' ? (char *) __rawmemchr (tm, ' ' ) : __builtin_strchr (tm, ' '))))) { | |||
4608 | uint32_t id; | |||
4609 | ||||
4610 | *group++ = '\0'; | |||
4611 | ||||
4612 | if ((dcmd = strchr(group, ' ')(__extension__ (__builtin_constant_p (' ') && !__builtin_constant_p (group) && (' ') == '\0' ? (char *) __rawmemchr (group , ' ') : __builtin_strchr (group, ' '))))) { | |||
4613 | *dcmd++ = '\0'; | |||
4614 | ||||
4615 | if (*tm == '+') { | |||
4616 | when = switch_epoch_time_now(NULL((void*)0)) + atol(tm + 1); | |||
4617 | } else if (*tm == '@') { | |||
4618 | recur = (uint32_t) atol(tm + 1); | |||
4619 | when = switch_epoch_time_now(NULL((void*)0)) + recur; | |||
4620 | } else { | |||
4621 | when = atol(tm); | |||
4622 | } | |||
4623 | ||||
4624 | switch_zmalloc(api_task, sizeof(*api_task) + strlen(dcmd) + 1)(void)((((api_task = calloc(1, (sizeof(*api_task) + strlen(dcmd ) + 1)))) ? (void) (0) : __assert_fail ("(api_task = calloc(1, (sizeof(*api_task) + strlen(dcmd) + 1)))" , "mod_commands.c", 4624, __PRETTY_FUNCTION__)),api_task); | |||
4625 | switch_copy_string(api_task->cmd, dcmd, strlen(dcmd) + 1); | |||
4626 | api_task->recur = recur; | |||
4627 | if (end_of(api_task->cmd)*(*api_task->cmd == '\0' ? api_task->cmd : api_task-> cmd + strlen(api_task->cmd) - 1) == '&') { | |||
4628 | end_of(api_task->cmd)*(*api_task->cmd == '\0' ? api_task->cmd : api_task-> cmd + strlen(api_task->cmd) - 1) = '\0'; | |||
4629 | flags |= SSHF_OWN_THREAD; | |||
4630 | } | |||
4631 | ||||
4632 | ||||
4633 | id = switch_scheduler_add_task(when, sch_api_callback, (char *) __SWITCH_FUNC__(const char *)__func__, group, 0, api_task, flags); | |||
4634 | stream->write_function(stream, "+OK Added: %u\n", id); | |||
4635 | goto good; | |||
4636 | } | |||
4637 | } | |||
4638 | ||||
4639 | bad: | |||
4640 | ||||
4641 | stream->write_function(stream, "-ERR Invalid syntax. USAGE: %s\n", SCHED_SYNTAX"[+@]<time> <group_name> <command_string>[&]"); | |||
4642 | ||||
4643 | good: | |||
4644 | ||||
4645 | switch_safe_free(tm)if (tm) {free(tm);tm=((void*)0);}; | |||
4646 | return SWITCH_STATUS_SUCCESS; | |||
4647 | } | |||
4648 | ||||
4649 | static switch_thread_rwlock_t *bgapi_rwlock = NULL((void*)0); | |||
4650 | ||||
4651 | struct bg_job { | |||
4652 | char *cmd; | |||
4653 | char *arg; | |||
4654 | char uuid_str[SWITCH_UUID_FORMATTED_LENGTH256 + 1]; | |||
4655 | switch_memory_pool_t *pool; | |||
4656 | }; | |||
4657 | ||||
4658 | static void *SWITCH_THREAD_FUNC bgapi_exec(switch_thread_t *thread, void *obj) | |||
4659 | { | |||
4660 | struct bg_job *job = (struct bg_job *) obj; | |||
4661 | switch_stream_handle_t stream = { 0 }; | |||
4662 | switch_status_t status; | |||
4663 | char *reply, *freply = NULL((void*)0); | |||
4664 | switch_event_t *event; | |||
4665 | char *arg; | |||
4666 | switch_memory_pool_t *pool; | |||
4667 | ||||
4668 | if (!job) { | |||
4669 | return NULL((void*)0); | |||
4670 | } | |||
4671 | ||||
4672 | switch_thread_rwlock_rdlock(bgapi_rwlock); | |||
4673 | ||||
4674 | pool = job->pool; | |||
4675 | ||||
4676 | SWITCH_STANDARD_STREAM(stream)memset(&stream, 0, sizeof(stream)); stream.data = malloc( 1024); ((stream.data) ? (void) (0) : __assert_fail ("stream.data" , "mod_commands.c", 4676, __PRETTY_FUNCTION__)); memset(stream .data, 0, 1024); stream.end = stream.data; stream.data_size = 1024; stream.write_function = switch_console_stream_write; stream .raw_write_function = switch_console_stream_raw_write; stream .alloc_len = 1024; stream.alloc_chunk = 1024; | |||
4677 | ||||
4678 | if ((arg = strchr(job->cmd, ' ')(__extension__ (__builtin_constant_p (' ') && !__builtin_constant_p (job->cmd) && (' ') == '\0' ? (char *) __rawmemchr (job->cmd, ' ') : __builtin_strchr (job->cmd, ' '))))) { | |||
4679 | *arg++ = '\0'; | |||
4680 | } | |||
4681 | ||||
4682 | if ((status = switch_api_execute(job->cmd, arg, NULL((void*)0), &stream)) == SWITCH_STATUS_SUCCESS) { | |||
4683 | reply = stream.data; | |||
4684 | } else { | |||
4685 | freply = switch_mprintf("%s: Command not found!\n", job->cmd); | |||
4686 | reply = freply; | |||
4687 | } | |||
4688 | ||||
4689 | if (!reply) { | |||
4690 | reply = "Command returned no output!"; | |||
4691 | } | |||
4692 | ||||
4693 | if (switch_event_create(&event, SWITCH_EVENT_BACKGROUND_JOB)switch_event_create_subclass_detailed("mod_commands.c", (const char * )(const char *)__func__, 4693, &event, SWITCH_EVENT_BACKGROUND_JOB , ((void*)0)) == SWITCH_STATUS_SUCCESS) { | |||
4694 | switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Job-UUID", job->uuid_str); | |||
4695 | switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Job-Command", job->cmd); | |||
4696 | if (arg) { | |||
4697 | switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Job-Command-Arg", arg); | |||
4698 | } | |||
4699 | ||||
4700 | switch_event_add_body(event, "%s", reply); | |||
4701 | switch_event_fire(&event)switch_event_fire_detailed("mod_commands.c", (const char * )( const char *)__func__, 4701, &event, ((void*)0)); | |||
4702 | } | |||
4703 | ||||
4704 | switch_safe_free(stream.data)if (stream.data) {free(stream.data);stream.data=((void*)0);}; | |||
4705 | switch_safe_free(freply)if (freply) {free(freply);freply=((void*)0);}; | |||
4706 | ||||
4707 | job = NULL((void*)0); | |||
4708 | switch_core_destroy_memory_pool(&pool)switch_core_perform_destroy_memory_pool(&pool, "mod_commands.c" , (const char *)__func__, 4708); | |||
4709 | pool = NULL((void*)0); | |||
4710 | ||||
4711 | switch_thread_rwlock_unlock(bgapi_rwlock); | |||
4712 | ||||
4713 | return NULL((void*)0); | |||
4714 | } | |||
4715 | ||||
4716 | SWITCH_STANDARD_API(bgapi_function)static switch_status_t bgapi_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
4717 | { | |||
4718 | struct bg_job *job; | |||
4719 | switch_uuid_t uuid; | |||
4720 | switch_memory_pool_t *pool; | |||
4721 | switch_thread_t *thread; | |||
4722 | switch_threadattr_t *thd_attr = NULL((void*)0); | |||
4723 | ||||
4724 | if (!cmd) { | |||
4725 | stream->write_function(stream, "-ERR Invalid syntax\n"); | |||
4726 | return SWITCH_STATUS_SUCCESS; | |||
4727 | } | |||
4728 | ||||
4729 | switch_core_new_memory_pool(&pool)switch_core_perform_new_memory_pool(&pool, "mod_commands.c" , (const char *)__func__, 4729); | |||
4730 | job = switch_core_alloc(pool, sizeof(*job))switch_core_perform_alloc(pool, sizeof(*job), "mod_commands.c" , (const char *)__func__, 4730); | |||
4731 | job->cmd = switch_core_strdup(pool, cmd)switch_core_perform_strdup(pool, cmd, "mod_commands.c", (const char *)__func__, 4731); | |||
4732 | job->pool = pool; | |||
4733 | ||||
4734 | switch_uuid_get(&uuid); | |||
4735 | switch_uuid_format(job->uuid_str, &uuid); | |||
4736 | ||||
4737 | switch_threadattr_create(&thd_attr, job->pool); | |||
4738 | switch_threadattr_detach_set(thd_attr, 1); | |||
4739 | switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE240 * 1024); | |||
4740 | stream->write_function(stream, "+OK Job-UUID: %s\n", job->uuid_str); | |||
4741 | switch_thread_create(&thread, thd_attr, bgapi_exec, job, job->pool); | |||
4742 | ||||
4743 | return SWITCH_STATUS_SUCCESS; | |||
4744 | } | |||
4745 | ||||
4746 | struct holder { | |||
4747 | char * delim; | |||
4748 | switch_stream_handle_t *stream; | |||
4749 | uint32_t count; | |||
4750 | int print_title; | |||
4751 | switch_xml_t xml; | |||
4752 | cJSON *json; | |||
4753 | int rows; | |||
4754 | int justcount; | |||
4755 | stream_format *format; | |||
4756 | }; | |||
4757 | ||||
4758 | static int show_as_json_callback(void *pArg, int argc, char **argv, char **columnNames) | |||
4759 | { | |||
4760 | struct holder *holder = (struct holder *) pArg; | |||
4761 | cJSON *row; | |||
4762 | int x; | |||
4763 | ||||
4764 | if (holder->count == 0) { | |||
4765 | if (!(holder->json = cJSON_CreateArray())) { | |||
4766 | return -1; | |||
4767 | } | |||
4768 | } | |||
4769 | ||||
4770 | if (holder->justcount) { | |||
4771 | if (zstr(argv[0])_zstr(argv[0])) { | |||
4772 | holder->count = 0; | |||
4773 | } else { | |||
4774 | holder->count = (uint32_t) atoi(argv[0]); | |||
4775 | } | |||
4776 | return 0; | |||
4777 | } | |||
4778 | ||||
4779 | if (!(row = cJSON_CreateObject())) { | |||
4780 | return -1; | |||
4781 | } | |||
4782 | ||||
4783 | cJSON_AddItemToArray(holder->json, row); | |||
4784 | ||||
4785 | for (x = 0; x < argc; x++) { | |||
4786 | char *name = columnNames[x]; | |||
4787 | char *val = switch_str_nil(argv[x])(argv[x] ? argv[x] : ""); | |||
4788 | ||||
4789 | if (!name) { | |||
4790 | name = "undefined"; | |||
4791 | } | |||
4792 | ||||
4793 | cJSON_AddItemToObject(row, name, cJSON_CreateString(val)); | |||
4794 | } | |||
4795 | ||||
4796 | holder->count++; | |||
4797 | ||||
4798 | return 0; | |||
4799 | } | |||
4800 | ||||
4801 | static int show_as_xml_callback(void *pArg, int argc, char **argv, char **columnNames) | |||
4802 | { | |||
4803 | struct holder *holder = (struct holder *) pArg; | |||
4804 | switch_xml_t row, field; | |||
4805 | int x, f_off = 0; | |||
4806 | char id[50]; | |||
4807 | ||||
4808 | if (holder->count == 0) { | |||
4809 | if (!(holder->xml = switch_xml_new("result"))) { | |||
4810 | return -1; | |||
4811 | } | |||
4812 | } | |||
4813 | ||||
4814 | if (holder->justcount) { | |||
4815 | if (zstr(argv[0])_zstr(argv[0])) { | |||
4816 | holder->count = 0; | |||
4817 | } else { | |||
4818 | holder->count = (uint32_t) atoi(argv[0]); | |||
4819 | } | |||
4820 | return 0; | |||
4821 | } | |||
4822 | ||||
4823 | if (!(row = switch_xml_add_child_d(holder->xml, "row", holder->rows++)switch_xml_set_flag(switch_xml_add_child(holder->xml, (__extension__ (__builtin_constant_p ("row") && ((size_t)(const void *)(("row") + 1) - (size_t)(const void *)("row") == 1) ? (((const char *) ("row"))[0] == '\0' ? (char *) calloc ((size_t) 1, ( size_t) 1) : ({ size_t __len = strlen ("row") + 1; char *__retval = (char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, "row", __len); __retval; })) : __strdup ("row"))), holder->rows++), SWITCH_XML_NAMEM))) { | |||
4824 | return -1; | |||
4825 | } | |||
4826 | ||||
4827 | switch_snprintf(id, sizeof(id), "%d", holder->rows); | |||
4828 | ||||
4829 | switch_xml_set_attr(switch_xml_set_flag(row, SWITCH_XML_DUP), strdup("row_id")(__extension__ (__builtin_constant_p ("row_id") && (( size_t)(const void *)(("row_id") + 1) - (size_t)(const void * )("row_id") == 1) ? (((const char *) ("row_id"))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen ("row_id") + 1; char *__retval = (char *) malloc (__len ); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval , "row_id", __len); __retval; })) : __strdup ("row_id"))), strdup(id)(__extension__ (__builtin_constant_p (id) && ((size_t )(const void *)((id) + 1) - (size_t)(const void *)(id) == 1) ? (((const char *) (id))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (id) + 1; char *__retval = (char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, id, __len); __retval; })) : __strdup (id)))); | |||
4830 | ||||
4831 | for (x = 0; x < argc; x++) { | |||
4832 | char *name = columnNames[x]; | |||
4833 | char *val = switch_str_nil(argv[x])(argv[x] ? argv[x] : ""); | |||
4834 | ||||
4835 | if (!name) { | |||
4836 | name = "undefined"; | |||
4837 | } | |||
4838 | ||||
4839 | if ((field = switch_xml_add_child_d(row, name, f_off++)switch_xml_set_flag(switch_xml_add_child(row, (__extension__ ( __builtin_constant_p (name) && ((size_t)(const void * )((name) + 1) - (size_t)(const void *)(name) == 1) ? (((const char *) (name))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t ) 1) : ({ size_t __len = strlen (name) + 1; char *__retval = ( char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, name, __len); __retval; })) : __strdup (name))), f_off++), SWITCH_XML_NAMEM))) { | |||
4840 | switch_xml_set_txt_d(field, val)switch_xml_set_flag(switch_xml_set_txt(field, (__extension__ ( __builtin_constant_p (val) && ((size_t)(const void *) ((val) + 1) - (size_t)(const void *)(val) == 1) ? (((const char *) (val))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen (val) + 1; char *__retval = (char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, val, __len); __retval; })) : __strdup ( val)))), SWITCH_XML_TXTM); | |||
4841 | } else { | |||
4842 | return -1; | |||
4843 | } | |||
4844 | } | |||
4845 | ||||
4846 | holder->count++; | |||
4847 | ||||
4848 | return 0; | |||
4849 | } | |||
4850 | ||||
4851 | static int show_callback(void *pArg, int argc, char **argv, char **columnNames) | |||
4852 | { | |||
4853 | struct holder *holder = (struct holder *) pArg; | |||
4854 | int x; | |||
4855 | ||||
4856 | if (holder->justcount) { | |||
4857 | if (zstr(argv[0])_zstr(argv[0])) { | |||
4858 | holder->count = 0; | |||
4859 | } else { | |||
4860 | holder->count = (uint32_t) atoi(argv[0]); | |||
4861 | } | |||
4862 | return 0; | |||
4863 | } | |||
4864 | ||||
4865 | if (holder->print_title && holder->count == 0) { | |||
4866 | if (holder->format && holder->format->html) { | |||
4867 | holder->stream->write_function(holder->stream, "\n<tr>"); | |||
4868 | } | |||
4869 | ||||
4870 | for (x = 0; x < argc; x++) { | |||
4871 | char *name = columnNames[x]; | |||
4872 | if (!name) { | |||
4873 | name = "undefined"; | |||
4874 | } | |||
4875 | ||||
4876 | if (holder->format && holder->format->html) { | |||
4877 | holder->stream->write_function(holder->stream, "<td>"); | |||
4878 | holder->stream->write_function(holder->stream, "<b>%s</b>%s", name, x == (argc - 1) ? "</td></tr>\n" : "</td><td>"); | |||
4879 | } else { | |||
4880 | holder->stream->write_function(holder->stream, "%s%s", name, x == (argc - 1) ? "\n" : holder->delim); | |||
4881 | } | |||
4882 | } | |||
4883 | } | |||
4884 | ||||
4885 | if (holder->format && holder->format->html) { | |||
4886 | holder->stream->write_function(holder->stream, "<tr bgcolor=%s>", holder->count % 2 == 0 ? "eeeeee" : "ffffff"); | |||
4887 | } | |||
4888 | ||||
4889 | for (x = 0; x < argc; x++) { | |||
4890 | char *val = switch_str_nil(argv[x])(argv[x] ? argv[x] : ""); | |||
4891 | ||||
4892 | ||||
4893 | if (holder->format && holder->format->html) { | |||
4894 | char aval[512]; | |||
4895 | ||||
4896 | switch_amp_encode(val, aval, sizeof(aval)); | |||
4897 | holder->stream->write_function(holder->stream, "<td>"); | |||
4898 | holder->stream->write_function(holder->stream, "%s%s", aval, x == (argc - 1) ? "</td></tr>\n" : "</td><td>"); | |||
4899 | } else { | |||
4900 | holder->stream->write_function(holder->stream, "%s%s", val, x == (argc - 1) ? "\n" : holder->delim); | |||
4901 | } | |||
4902 | } | |||
4903 | ||||
4904 | holder->count++; | |||
4905 | return 0; | |||
4906 | } | |||
4907 | ||||
4908 | #define COMPLETE_SYNTAX"add <word>|del [<word>|*]" "add <word>|del [<word>|*]" | |||
4909 | SWITCH_STANDARD_API(complete_function)static switch_status_t complete_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
4910 | { | |||
4911 | switch_status_t status; | |||
4912 | ||||
4913 | if ((status = switch_console_set_complete(cmd)) == SWITCH_STATUS_SUCCESS) { | |||
4914 | stream->write_function(stream, "+OK\n"); | |||
4915 | } else { | |||
4916 | stream->write_function(stream, "-USAGE: %s\n", COMPLETE_SYNTAX"add <word>|del [<word>|*]"); | |||
4917 | } | |||
4918 | ||||
4919 | return SWITCH_STATUS_SUCCESS; | |||
4920 | } | |||
4921 | ||||
4922 | #define ALIAS_SYNTAX"[add|stickyadd] <alias> <command> | del [<alias>|*]" "[add|stickyadd] <alias> <command> | del [<alias>|*]" | |||
4923 | SWITCH_STANDARD_API(alias_function)static switch_status_t alias_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
4924 | { | |||
4925 | switch_status_t status; | |||
4926 | ||||
4927 | if ((status = switch_console_set_alias(cmd)) == SWITCH_STATUS_SUCCESS) { | |||
4928 | stream->write_function(stream, "+OK\n"); | |||
4929 | } else { | |||
4930 | stream->write_function(stream, "-USAGE: %s\n", ALIAS_SYNTAX"[add|stickyadd] <alias> <command> | del [<alias>|*]"); | |||
4931 | } | |||
4932 | ||||
4933 | return SWITCH_STATUS_SUCCESS; | |||
4934 | } | |||
4935 | ||||
4936 | #define COALESCE_SYNTAX"[^^<delim>]<value1>,<value2>,..." "[^^<delim>]<value1>,<value2>,..." | |||
4937 | SWITCH_STANDARD_API(coalesce_function)static switch_status_t coalesce_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
4938 | { | |||
4939 | switch_status_t status = SWITCH_STATUS_FALSE; | |||
4940 | char *data = (char *) cmd; | |||
4941 | char *mydata = NULL((void*)0), *argv[256] = { 0 }; | |||
4942 | int argc = -1; | |||
4943 | ||||
4944 | if (data && *data && (mydata = strdup(data)(__extension__ (__builtin_constant_p (data) && ((size_t )(const void *)((data) + 1) - (size_t)(const void *)(data) == 1) ? (((const char *) (data))[0] == '\0' ? (char *) calloc ( (size_t) 1, (size_t) 1) : ({ size_t __len = strlen (data) + 1 ; char *__retval = (char *) malloc (__len); if (__retval != ( (void*)0)) __retval = (char *) memcpy (__retval, data, __len) ; __retval; })) : __strdup (data))))) { | |||
4945 | argc = switch_separate_string(mydata, ',', argv, | |||
4946 | (sizeof(argv) / sizeof(argv[0]))); | |||
4947 | } | |||
4948 | ||||
4949 | if (argc > 0) { | |||
4950 | int i; | |||
4951 | for (i = 0; i < argc; i++) { | |||
4952 | if (argv[i] && *argv[i]) { | |||
4953 | stream->write_function(stream, argv[i]); | |||
4954 | status = SWITCH_STATUS_SUCCESS; | |||
4955 | break; | |||
4956 | } | |||
4957 | } | |||
4958 | } else if (argc <= 0){ | |||
4959 | stream->write_function(stream, "-USAGE: %s\n", COALESCE_SYNTAX"[^^<delim>]<value1>,<value2>,..."); | |||
4960 | } | |||
4961 | ||||
4962 | return status; | |||
4963 | } | |||
4964 | ||||
4965 | #define SHOW_SYNTAX"codec|endpoint|application|api|dialplan|file|timer|calls [count]|channels [count|like <match string>]|calls|detailed_calls|bridged_calls|detailed_bridged_calls|aliases|complete|chat|management|modules|nat_map|say|interfaces|interface_types|tasks|limits|status" "codec|endpoint|application|api|dialplan|file|timer|calls [count]|channels [count|like <match string>]|calls|detailed_calls|bridged_calls|detailed_bridged_calls|aliases|complete|chat|management|modules|nat_map|say|interfaces|interface_types|tasks|limits|status" | |||
4966 | SWITCH_STANDARD_API(show_function)static switch_status_t show_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
4967 | { | |||
4968 | char sql[1024]; | |||
4969 | char *errmsg; | |||
4970 | switch_cache_db_handle_t *db; | |||
4971 | struct holder holder = { 0 }; | |||
4972 | int help = 0; | |||
4973 | char *mydata = NULL((void*)0), *argv[6] = { 0 }; | |||
4974 | char *command = NULL((void*)0), *as = NULL((void*)0); | |||
4975 | switch_core_flag_t cflags = switch_core_flags(); | |||
4976 | switch_status_t status = SWITCH_STATUS_SUCCESS; | |||
4977 | int html = 0; | |||
4978 | char *nl = "\n"; | |||
4979 | stream_format format = { 0 }; | |||
4980 | ||||
4981 | holder.format = &format; | |||
4982 | set_format(holder.format, stream); | |||
4983 | html = holder.format->html; /* html is just a shortcut */ | |||
4984 | ||||
4985 | if (!(cflags & SCF_USE_SQL)) { | |||
| ||||
4986 | stream->write_function(stream, "-ERR SQL disabled, no data available!\n"); | |||
4987 | return SWITCH_STATUS_SUCCESS; | |||
4988 | } | |||
4989 | ||||
4990 | if (switch_core_db_handle(&db)_switch_core_db_handle(&db, "mod_commands.c", (const char *)__func__, 4990) != SWITCH_STATUS_SUCCESS) { | |||
4991 | stream->write_function(stream, "%s", "-ERR Database error!\n"); | |||
4992 | return SWITCH_STATUS_SUCCESS; | |||
4993 | } | |||
4994 | ||||
4995 | holder.justcount = 0; | |||
4996 | ||||
4997 | if (cmd && *cmd && (mydata = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))))) { | |||
4998 | switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | |||
4999 | command = argv[0]; | |||
5000 | if (argv[2] && !strcasecmp(argv[1], "as")) { | |||
5001 | as = argv[2]; | |||
5002 | } | |||
5003 | } | |||
5004 | ||||
5005 | holder.print_title = 1; | |||
5006 | ||||
5007 | if (!command) { | |||
5008 | stream->write_function(stream, "-USAGE: %s\n", SHOW_SYNTAX"codec|endpoint|application|api|dialplan|file|timer|calls [count]|channels [count|like <match string>]|calls|detailed_calls|bridged_calls|detailed_bridged_calls|aliases|complete|chat|management|modules|nat_map|say|interfaces|interface_types|tasks|limits|status"); | |||
5009 | goto end; | |||
5010 | /* for those of us that keep on typing at the CLI: "show status" instead of "status" */ | |||
5011 | } else if (!strncasecmp(command, "status", 6)) { | |||
5012 | if (!as) { | |||
5013 | as = argv[1]; | |||
5014 | } | |||
5015 | switch_api_execute(command, as, NULL((void*)0), stream); | |||
5016 | goto end; | |||
5017 | /* If you change the field qty or order of any of these select */ | |||
5018 | /* statements, you must also change show_callback and friends to match! */ | |||
5019 | } else if (!strncasecmp(command, "codec", 5) || | |||
5020 | !strncasecmp(command, "dialplan", 8) || | |||
5021 | !strncasecmp(command, "file", 4) || | |||
5022 | !strncasecmp(command, "timer", 5) || | |||
5023 | !strncasecmp(command, "chat", 4) || | |||
5024 | !strncasecmp(command, "limit", 5) || | |||
5025 | !strncasecmp(command, "say", 3) || !strncasecmp(command, "management", 10) || !strncasecmp(command, "endpoint", 8)) { | |||
5026 | if (end_of(command)*(*command == '\0' ? command : command + strlen(command) - 1) == 's') { | |||
5027 | end_of(command)*(*command == '\0' ? command : command + strlen(command) - 1) = '\0'; | |||
5028 | } | |||
5029 | sprintf(sql, "select type, name, ikey from interfaces where hostname='%s' and type = '%s' order by type,name", switch_core_get_hostname(), command); | |||
5030 | } else if (!strncasecmp(command, "module", 6)) { | |||
5031 | if (argv[1] && strcasecmp(argv[1], "as")) { | |||
5032 | sprintf(sql, "select distinct type, name, ikey, filename from interfaces where hostname='%s' and ikey = '%s' order by type,name", | |||
5033 | switch_core_get_hostname(), argv[1]); | |||
5034 | } else { | |||
5035 | sprintf(sql, "select distinct type, name, ikey, filename from interfaces where hostname='%s' order by type,name", switch_core_get_hostname()); | |||
5036 | } | |||
5037 | } else if (!strcasecmp(command, "interfaces")) { | |||
5038 | sprintf(sql, "select type, name, ikey from interfaces where hostname='%s' order by type,name", switch_core_get_hostname()); | |||
5039 | } else if (!strcasecmp(command, "interface_types")) { | |||
5040 | sprintf(sql, "select type,count(type) as total from interfaces where hostname='%s' group by type order by type", switch_core_get_switchname()); | |||
5041 | } else if (!strcasecmp(command, "tasks")) { | |||
5042 | sprintf(sql, "select * from %s where hostname='%s'", command, switch_core_get_hostname()); | |||
5043 | } else if (!strcasecmp(command, "application") || !strcasecmp(command, "api")) { | |||
5044 | if (argv[1] && strcasecmp(argv[1], "as")) { | |||
5045 | sprintf(sql, | |||
5046 | "select name, description, syntax, ikey from interfaces where hostname='%s' and type = '%s' and description != '' and name = '%s' order by type,name", | |||
5047 | switch_core_get_hostname(), command, argv[1]); | |||
5048 | } else { | |||
5049 | sprintf(sql, "select name, description, syntax, ikey from interfaces where hostname='%s' and type = '%s' and description != '' order by type,name", switch_core_get_hostname(), command); | |||
5050 | } | |||
5051 | /* moved refreshable webpage show commands i.e. show calls|registrations|channels||detailed_calls|bridged_calls|detailed_bridged_calls */ | |||
5052 | } else if (!strcasecmp(command, "aliases")) { | |||
5053 | sprintf(sql, "select * from aliases where hostname='%s' order by alias", switch_core_get_switchname()); | |||
5054 | } else if (!strcasecmp(command, "complete")) { | |||
5055 | sprintf(sql, "select * from complete where hostname='%s' order by a1,a2,a3,a4,a5,a6,a7,a8,a9,a10", switch_core_get_switchname()); | |||
5056 | } else if (!strncasecmp(command, "help", 4)) { | |||
5057 | char *cmdname = NULL((void*)0); | |||
5058 | ||||
5059 | help = 1; | |||
5060 | holder.print_title = 0; | |||
5061 | if ((cmdname = strchr(command, ' ')(__extension__ (__builtin_constant_p (' ') && !__builtin_constant_p (command) && (' ') == '\0' ? (char *) __rawmemchr (command , ' ') : __builtin_strchr (command, ' ')))) && strcasecmp(cmdname, "as")) { | |||
5062 | *cmdname++ = '\0'; | |||
5063 | switch_snprintfv(sql, sizeof(sql), | |||
5064 | "select name, syntax, description, ikey from interfaces where hostname='%s' and type = 'api' and name = '%q' order by name", | |||
5065 | switch_core_get_hostname(), cmdname); | |||
5066 | } else { | |||
5067 | switch_snprintfv(sql, sizeof(sql), "select name, syntax, description, ikey from interfaces where hostname='%q' and type = 'api' order by name", switch_core_get_hostname()); | |||
5068 | } | |||
5069 | } else if (!strcasecmp(command, "nat_map")) { | |||
5070 | switch_snprintf(sql, sizeof(sql) - 1, | |||
5071 | "SELECT port, " | |||
5072 | " CASE proto " | |||
5073 | " WHEN 0 THEN 'udp' " | |||
5074 | " WHEN 1 THEN 'tcp' " | |||
5075 | " ELSE 'unknown' " " END AS proto, " " proto AS proto_num, " " sticky " " FROM nat where hostname='%s' ORDER BY port, proto", switch_core_get_hostname()); | |||
5076 | } else { | |||
5077 | /* from here on refreshable commands: calls|registrations|channels||detailed_calls|bridged_calls|detailed_bridged_calls */ | |||
5078 | if (holder.format->api) { | |||
5079 | holder.format->html = SWITCH_TRUE; | |||
5080 | holder.format->nl = "<br>\n"; | |||
5081 | } | |||
5082 | ||||
5083 | html = holder.format->html; | |||
5084 | if (html) { | |||
5085 | /* set flag to allow refresh of webpage if web request contained kv-pair refresh=xx */ | |||
5086 | switch_event_add_header_string(stream->param_event, SWITCH_STACK_BOTTOM, "HTTP-REFRESH", "true"); | |||
5087 | if (holder.format->api) { | |||
5088 | /* "Overwrite" default "api" Content-Type: text/plain */ | |||
5089 | stream->write_function(stream, "Content-Type: text/html\r\n\r\n"); | |||
5090 | } | |||
5091 | } | |||
5092 | ||||
5093 | if (!strcasecmp(command, "calls")) { | |||
5094 | sprintf(sql, "select * from basic_calls where hostname='%s' order by call_created_epoch", switch_core_get_switchname()); | |||
5095 | if (argv[1] && !strcasecmp(argv[1], "count")) { | |||
5096 | sprintf(sql, "select count(*) from basic_calls where hostname='%s'", switch_core_get_switchname()); | |||
5097 | holder.justcount = 1; | |||
5098 | if (argv[3] && !strcasecmp(argv[2], "as")) { | |||
| ||||
5099 | as = argv[3]; | |||
5100 | } | |||
5101 | } | |||
5102 | } else if (!strcasecmp(command, "registrations")) { | |||
5103 | sprintf(sql, "select * from registrations where hostname='%s'", switch_core_get_switchname()); | |||
5104 | if (argv[1] && !strcasecmp(argv[1], "count")) { | |||
5105 | sprintf(sql, "select count(*) from registrations where hostname='%s'", switch_core_get_switchname()); | |||
5106 | holder.justcount = 1; | |||
5107 | if (argv[3] && !strcasecmp(argv[2], "as")) { | |||
5108 | as = argv[3]; | |||
5109 | } | |||
5110 | } | |||
5111 | } else if (!strcasecmp(command, "channels") && argv[1] && !strcasecmp(argv[1], "like")) { | |||
5112 | if (argv[2]) { | |||
5113 | char *p; | |||
5114 | for (p = argv[2]; p && *p; p++) { | |||
5115 | if (*p == '\'' || *p == ';') { | |||
5116 | *p = ' '; | |||
5117 | } | |||
5118 | } | |||
5119 | if (strchr(argv[2], '%')(__extension__ (__builtin_constant_p ('%') && !__builtin_constant_p (argv[2]) && ('%') == '\0' ? (char *) __rawmemchr (argv [2], '%') : __builtin_strchr (argv[2], '%')))) { | |||
5120 | sprintf(sql, | |||
5121 | "select * from channels where hostname='%s' and uuid like '%s' or name like '%s' or cid_name like '%s' or cid_num like '%s' or presence_data like '%s' order by created_epoch", | |||
5122 | switch_core_get_switchname(), argv[2], argv[2], argv[2], argv[2], argv[2]); | |||
5123 | } else { | |||
5124 | sprintf(sql, | |||
5125 | "select * from channels where hostname='%s' and uuid like '%%%s%%' or name like '%%%s%%' or cid_name like '%%%s%%' or cid_num like '%%%s%%' or presence_data like '%%%s%%' order by created_epoch", | |||
5126 | switch_core_get_switchname(), argv[2], argv[2], argv[2], argv[2], argv[2]); | |||
5127 | } | |||
5128 | if (argv[4] && !strcasecmp(argv[3], "as")) { | |||
5129 | as = argv[4]; | |||
5130 | } | |||
5131 | } else { | |||
5132 | sprintf(sql, "select * from channels where hostname='%s' order by created_epoch", switch_core_get_switchname()); | |||
5133 | } | |||
5134 | } else if (!strcasecmp(command, "channels")) { | |||
5135 | sprintf(sql, "select * from channels where hostname='%s' order by created_epoch", switch_core_get_switchname()); | |||
5136 | if (argv[1] && !strcasecmp(argv[1], "count")) { | |||
5137 | sprintf(sql, "select count(*) from channels where hostname='%s'", switch_core_get_switchname()); | |||
5138 | holder.justcount = 1; | |||
5139 | if (argv[3] && !strcasecmp(argv[2], "as")) { | |||
5140 | as = argv[3]; | |||
5141 | } | |||
5142 | } | |||
5143 | } else if (!strcasecmp(command, "detailed_calls")) { | |||
5144 | sprintf(sql, "select * from detailed_calls where hostname='%s' order by created_epoch", switch_core_get_switchname()); | |||
5145 | if (argv[2] && !strcasecmp(argv[1], "as")) { | |||
5146 | as = argv[2]; | |||
5147 | } | |||
5148 | } else if (!strcasecmp(command, "bridged_calls")) { | |||
5149 | sprintf(sql, "select * from basic_calls where b_uuid is not null and hostname='%s' order by created_epoch", switch_core_get_switchname()); | |||
5150 | if (argv[2] && !strcasecmp(argv[1], "as")) { | |||
5151 | as = argv[2]; | |||
5152 | } | |||
5153 | } else if (!strcasecmp(command, "detailed_bridged_calls")) { | |||
5154 | sprintf(sql, "select * from detailed_calls where b_uuid is not null and hostname='%s' order by created_epoch", switch_core_get_switchname()); | |||
5155 | if (argv[2] && !strcasecmp(argv[1], "as")) { | |||
5156 | as = argv[2]; | |||
5157 | } | |||
5158 | } else { | |||
5159 | ||||
5160 | stream->write_function(stream, "-USAGE: %s\n", SHOW_SYNTAX"codec|endpoint|application|api|dialplan|file|timer|calls [count]|channels [count|like <match string>]|calls|detailed_calls|bridged_calls|detailed_bridged_calls|aliases|complete|chat|management|modules|nat_map|say|interfaces|interface_types|tasks|limits|status"); | |||
5161 | goto end; | |||
5162 | } | |||
5163 | } | |||
5164 | ||||
5165 | holder.stream = stream; | |||
5166 | holder.count = 0; | |||
5167 | ||||
5168 | if (html) { | |||
5169 | nl = holder.format->nl; | |||
5170 | if (!as || strcasecmp(as,"xml")) { | |||
5171 | /* don't bother cli with heading and timestamp */ | |||
5172 | stream->write_function(stream, "<h1>FreeSWITCH %s %s</h1>\n", command, holder.justcount?"(count)":""); | |||
5173 | stream->write_function(stream, "%s%s", switch_event_get_header(stream->param_event,"Event-Date-Local")switch_event_get_header_idx(stream->param_event, "Event-Date-Local" , -1), nl); | |||
5174 | } | |||
5175 | holder.stream->write_function(holder.stream, "<table cellpadding=1 cellspacing=4 border=1>\n"); | |||
5176 | } | |||
5177 | ||||
5178 | if (!as) { | |||
5179 | as = "delim"; | |||
5180 | holder.delim = ","; | |||
5181 | } | |||
5182 | ||||
5183 | /* switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "SQL: %s\n", sql); */ | |||
5184 | ||||
5185 | if (!strcasecmp(as, "delim") || !strcasecmp(as, "csv")) { | |||
5186 | if (zstr(holder.delim)_zstr(holder.delim)) { | |||
5187 | if (!(holder.delim = argv[3])) { | |||
5188 | holder.delim = ","; | |||
5189 | } | |||
5190 | } | |||
5191 | switch_cache_db_execute_sql_callback(db, sql, show_callback, &holder, &errmsg); | |||
5192 | if (html) { | |||
5193 | holder.stream->write_function(holder.stream, "</table>"); | |||
5194 | } | |||
5195 | ||||
5196 | if (errmsg) { | |||
5197 | stream->write_function(stream, "-ERR SQL error [%s]\n", errmsg); | |||
5198 | free(errmsg); | |||
5199 | errmsg = NULL((void*)0); | |||
5200 | } else if (help) { | |||
5201 | if (holder.count == 0) | |||
5202 | stream->write_function(stream, "-ERR No such command\n"); | |||
5203 | } else { | |||
5204 | stream->write_function(stream, "%s%u total.%s", nl, holder.count, nl); | |||
5205 | } | |||
5206 | } else if (!strcasecmp(as, "xml")) { | |||
5207 | switch_cache_db_execute_sql_callback(db, sql, show_as_xml_callback, &holder, &errmsg); | |||
5208 | ||||
5209 | if (errmsg) { | |||
5210 | stream->write_function(stream, "-ERR SQL error [%s]\n", errmsg); | |||
5211 | free(errmsg); | |||
5212 | errmsg = NULL((void*)0); | |||
5213 | } | |||
5214 | ||||
5215 | if (holder.xml) { | |||
5216 | char count[50]; | |||
5217 | char *xmlstr; | |||
5218 | switch_snprintf(count, sizeof(count), "%d", holder.count); | |||
5219 | ||||
5220 | switch_xml_set_attr(switch_xml_set_flag(holder.xml, SWITCH_XML_DUP), strdup("row_count")(__extension__ (__builtin_constant_p ("row_count") && ((size_t)(const void *)(("row_count") + 1) - (size_t)(const void *)("row_count") == 1) ? (((const char *) ("row_count"))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen ("row_count") + 1; char *__retval = (char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, "row_count", __len); __retval; })) : __strdup ("row_count" ))), strdup(count)(__extension__ (__builtin_constant_p (count) && ((size_t )(const void *)((count) + 1) - (size_t)(const void *)(count) == 1) ? (((const char *) (count))[0] == '\0' ? (char *) calloc ( (size_t) 1, (size_t) 1) : ({ size_t __len = strlen (count) + 1 ; char *__retval = (char *) malloc (__len); if (__retval != ( (void*)0)) __retval = (char *) memcpy (__retval, count, __len ); __retval; })) : __strdup (count)))); | |||
5221 | xmlstr = switch_xml_toxml(holder.xml, SWITCH_FALSE); | |||
5222 | switch_xml_free(holder.xml); | |||
5223 | ||||
5224 | if (xmlstr) { | |||
5225 | holder.stream->write_function(holder.stream, "%s", xmlstr); | |||
5226 | free(xmlstr); | |||
5227 | } else { | |||
5228 | holder.stream->write_function(holder.stream, "<result row_count=\"0\"/>\n"); | |||
5229 | } | |||
5230 | } else { | |||
5231 | holder.stream->write_function(holder.stream, "<result row_count=\"0\"/>\n"); | |||
5232 | } | |||
5233 | } else if (!strcasecmp(as, "json")) { | |||
5234 | ||||
5235 | switch_cache_db_execute_sql_callback(db, sql, show_as_json_callback, &holder, &errmsg); | |||
5236 | ||||
5237 | if (errmsg) { | |||
5238 | stream->write_function(stream, "-ERR SQL Error [%s]\n", errmsg); | |||
5239 | free(errmsg); | |||
5240 | errmsg = NULL((void*)0); | |||
5241 | } | |||
5242 | ||||
5243 | if (holder.json) { | |||
5244 | cJSON *result; | |||
5245 | ||||
5246 | if (!(result = cJSON_CreateObject())) { | |||
5247 | cJSON_Delete(holder.json); | |||
5248 | holder.json = NULL((void*)0); | |||
5249 | holder.stream->write_function(holder.stream, "-ERR Error creating json object!\n"); | |||
5250 | } else { | |||
5251 | char *json_text; | |||
5252 | ||||
5253 | cJSON_AddItemToObject(result, "row_count", cJSON_CreateNumber(holder.count)); | |||
5254 | cJSON_AddItemToObject(result, "rows", holder.json); | |||
5255 | ||||
5256 | json_text = cJSON_PrintUnformatted(result); | |||
5257 | ||||
5258 | if (!json_text) { | |||
5259 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_commands.c", (const char *)__func__ , 5259, ((void*)0), SWITCH_LOG_CRIT, "Memory Error!\n"); | |||
5260 | holder.stream->write_function(holder.stream, "-ERR Memory Error!\n"); | |||
5261 | } else { | |||
5262 | holder.stream->write_function(holder.stream, "%s", json_text); | |||
5263 | } | |||
5264 | cJSON_Delete(result); | |||
5265 | switch_safe_free(json_text)if (json_text) {free(json_text);json_text=((void*)0);}; | |||
5266 | } | |||
5267 | ||||
5268 | } else { | |||
5269 | holder.stream->write_function(holder.stream, "{\"row_count\": 0}\n"); | |||
5270 | } | |||
5271 | ||||
5272 | } else { | |||
5273 | holder.stream->write_function(holder.stream, "-ERR Cannot find format %s\n", as); | |||
5274 | goto end; | |||
5275 | } | |||
5276 | ||||
5277 | end: | |||
5278 | ||||
5279 | switch_safe_free(mydata)if (mydata) {free(mydata);mydata=((void*)0);}; | |||
5280 | switch_cache_db_release_db_handle(&db); | |||
5281 | ||||
5282 | return status; | |||
5283 | } | |||
5284 | ||||
5285 | SWITCH_STANDARD_API(help_function)static switch_status_t help_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
5286 | { | |||
5287 | char showcmd[1024]; | |||
5288 | int all = 0; | |||
5289 | if (zstr(cmd)_zstr(cmd)) { | |||
5290 | sprintf(showcmd, "help"); | |||
5291 | all = 1; | |||
5292 | } else { | |||
5293 | switch_snprintf(showcmd, sizeof(showcmd) - 1, "help %s", cmd); | |||
5294 | } | |||
5295 | ||||
5296 | if (all) { | |||
5297 | stream->write_function(stream, "\nValid Commands:\n\n"); | |||
5298 | } | |||
5299 | ||||
5300 | show_function(showcmd, session, stream); | |||
5301 | ||||
5302 | return SWITCH_STATUS_SUCCESS; | |||
5303 | } | |||
5304 | ||||
5305 | #define HEARTBEAT_SYNTAX"<uuid> [sched] [0|<seconds>]" "<uuid> [sched] [0|<seconds>]" | |||
5306 | SWITCH_STANDARD_API(uuid_session_heartbeat_function)static switch_status_t uuid_session_heartbeat_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
5307 | { | |||
5308 | char *mycmd = NULL((void*)0), *argv[3] = { 0 }; | |||
5309 | uint32_t seconds = 60; | |||
5310 | int argc, tmp; | |||
5311 | switch_core_session_t *l_session = NULL((void*)0); | |||
5312 | int x = 0, sched = 0; | |||
5313 | ||||
5314 | if (zstr(cmd)_zstr(cmd) || !(mycmd = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))))) { | |||
5315 | goto error; | |||
5316 | } | |||
5317 | ||||
5318 | argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | |||
5319 | ||||
5320 | if (argc < 2 || !argv[0]) { | |||
5321 | goto error; | |||
5322 | } | |||
5323 | ||||
5324 | if (!(l_session = switch_core_session_locate(argv[0])switch_core_session_perform_locate(argv[0], "mod_commands.c", (const char *)__func__, 5324))) { | |||
5325 | stream->write_function(stream, "-ERR Cannot locate session. USAGE: uuid_session_heartbeat %s\n", HEARTBEAT_SYNTAX"<uuid> [sched] [0|<seconds>]"); | |||
5326 | return SWITCH_STATUS_SUCCESS; | |||
5327 | } | |||
5328 | ||||
5329 | if (!strcasecmp(argv[1], "sched")) { | |||
5330 | x = 2; | |||
5331 | sched++; | |||
5332 | } else { | |||
5333 | x = 1; | |||
5334 | } | |||
5335 | ||||
5336 | if (switch_is_number(argv[x])) { | |||
5337 | tmp = atoi(argv[x]); | |||
5338 | if (tmp > 0) { | |||
5339 | seconds = tmp; | |||
5340 | } | |||
5341 | } else if (!switch_true(argv[x])) { | |||
5342 | seconds = 0; | |||
5343 | } | |||
5344 | ||||
5345 | if (seconds) { | |||
5346 | if (sched) { | |||
5347 | switch_core_session_sched_heartbeat(l_session, seconds); | |||
5348 | } else { | |||
5349 | switch_core_session_enable_heartbeat(l_session, seconds); | |||
5350 | } | |||
5351 | ||||
5352 | } else { | |||
5353 | switch_core_session_disable_heartbeat(l_session); | |||
5354 | } | |||
5355 | ||||
5356 | switch_core_session_rwunlock(l_session); | |||
5357 | ||||
5358 | switch_safe_free(mycmd)if (mycmd) {free(mycmd);mycmd=((void*)0);}; | |||
5359 | stream->write_function(stream, "+OK\n"); | |||
5360 | return SWITCH_STATUS_SUCCESS; | |||
5361 | ||||
5362 | error: | |||
5363 | switch_safe_free(mycmd)if (mycmd) {free(mycmd);mycmd=((void*)0);}; | |||
5364 | stream->write_function(stream, "-USAGE: uuid_session_heartbeat %s\n", HEARTBEAT_SYNTAX"<uuid> [sched] [0|<seconds>]"); | |||
5365 | return SWITCH_STATUS_SUCCESS; | |||
5366 | } | |||
5367 | ||||
5368 | SWITCH_STANDARD_API(uuid_flush_dtmf_function)static switch_status_t uuid_flush_dtmf_function ( const char * cmd, switch_core_session_t *session, switch_stream_handle_t * stream) | |||
5369 | { | |||
5370 | switch_core_session_t *fsession; | |||
5371 | ||||
5372 | if (!zstr(cmd)_zstr(cmd) && (fsession = switch_core_session_locate(cmd)switch_core_session_perform_locate(cmd, "mod_commands.c", (const char *)__func__, 5372))) { | |||
5373 | switch_channel_flush_dtmf(switch_core_session_get_channel(fsession)); | |||
5374 | switch_core_session_rwunlock(fsession); | |||
5375 | stream->write_function(stream, "+OK\n"); | |||
5376 | } else { | |||
5377 | stream->write_function(stream, "-ERR No such session\n"); | |||
5378 | } | |||
5379 | ||||
5380 | return SWITCH_STATUS_SUCCESS; | |||
5381 | } | |||
5382 | ||||
5383 | SWITCH_STANDARD_API(uuid_zombie_exec_function)static switch_status_t uuid_zombie_exec_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
5384 | { | |||
5385 | switch_core_session_t *fsession; | |||
5386 | ||||
5387 | if (!zstr(cmd)_zstr(cmd) && (fsession = switch_core_session_locate(cmd)switch_core_session_perform_locate(cmd, "mod_commands.c", (const char *)__func__, 5387))) { | |||
5388 | switch_channel_set_flag(switch_core_session_get_channel(fsession), CF_ZOMBIE_EXEC)switch_channel_set_flag_value(switch_core_session_get_channel (fsession), CF_ZOMBIE_EXEC, 1); | |||
5389 | switch_core_session_rwunlock(fsession); | |||
5390 | stream->write_function(stream, "+OK MMM Brains...\n"); | |||
5391 | } else { | |||
5392 | stream->write_function(stream, "-ERR no such session\n"); | |||
5393 | } | |||
5394 | ||||
5395 | return SWITCH_STATUS_SUCCESS; | |||
5396 | } | |||
5397 | ||||
5398 | #define SETVAR_SYNTAX"<uuid> <var> [value]" "<uuid> <var> [value]" | |||
5399 | SWITCH_STANDARD_API(uuid_setvar_function)static switch_status_t uuid_setvar_function ( const char *cmd , switch_core_session_t *session, switch_stream_handle_t *stream ) | |||
5400 | { | |||
5401 | switch_core_session_t *psession = NULL((void*)0); | |||
5402 | char *mycmd = NULL((void*)0), *argv[3] = { 0 }; | |||
5403 | int argc = 0; | |||
5404 | ||||
5405 | if (!zstr(cmd)_zstr(cmd) && (mycmd = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))))) { | |||
5406 | argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | |||
5407 | if ((argc == 2 || argc == 3) && !zstr(argv[0])_zstr(argv[0])) { | |||
5408 | char *uuid = argv[0]; | |||
5409 | char *var_name = argv[1]; | |||
5410 | char *var_value = NULL((void*)0); | |||
5411 | ||||
5412 | if (argc == 3) { | |||
5413 | var_value = argv[2]; | |||
5414 | } | |||
5415 | ||||
5416 | if ((psession = switch_core_session_locate(uuid)switch_core_session_perform_locate(uuid, "mod_commands.c", (const char *)__func__, 5416))) { | |||
5417 | switch_channel_t *channel; | |||
5418 | channel = switch_core_session_get_channel(psession); | |||
5419 | ||||
5420 | if (zstr(var_name)_zstr(var_name)) { | |||
5421 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "mod_commands.c", (const char *)__func__ , 5421, (const char*)(session), SWITCH_LOG_ERROR, "No variable name specified.\n"); | |||
5422 | stream->write_function(stream, "-ERR No variable specified\n"); | |||
5423 | } else { | |||
5424 | switch_channel_set_variable(channel, var_name, var_value)switch_channel_set_variable_var_check(channel, var_name, var_value , SWITCH_TRUE); | |||
5425 | stream->write_function(stream, "+OK\n"); | |||
5426 | } | |||
5427 | ||||
5428 | switch_core_session_rwunlock(psession); | |||
5429 | ||||
5430 | } else { | |||
5431 | stream->write_function(stream, "-ERR No such channel!\n"); | |||
5432 | } | |||
5433 | goto done; | |||
5434 | } | |||
5435 | } | |||
5436 | ||||
5437 | stream->write_function(stream, "-USAGE: %s\n", SETVAR_SYNTAX"<uuid> <var> [value]"); | |||
5438 | ||||
5439 | done: | |||
5440 | switch_safe_free(mycmd)if (mycmd) {free(mycmd);mycmd=((void*)0);}; | |||
5441 | return SWITCH_STATUS_SUCCESS; | |||
5442 | } | |||
5443 | ||||
5444 | ||||
5445 | #define SETVAR_MULTI_SYNTAX"<uuid> <var>=<value>;<var>=<value>..." "<uuid> <var>=<value>;<var>=<value>..." | |||
5446 | SWITCH_STANDARD_API(uuid_setvar_multi_function)static switch_status_t uuid_setvar_multi_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
5447 | { | |||
5448 | switch_core_session_t *psession = NULL((void*)0); | |||
5449 | char *mycmd = NULL((void*)0), *vars, *argv[64] = { 0 }; | |||
5450 | int argc = 0; | |||
5451 | char *var_name, *var_value = NULL((void*)0); | |||
5452 | ||||
5453 | if (!zstr(cmd)_zstr(cmd) && (mycmd = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))))) { | |||
5454 | char *uuid = mycmd; | |||
5455 | if (!(vars = strchr(uuid, ' ')(__extension__ (__builtin_constant_p (' ') && !__builtin_constant_p (uuid) && (' ') == '\0' ? (char *) __rawmemchr (uuid , ' ') : __builtin_strchr (uuid, ' '))))) { | |||
5456 | goto done; | |||
5457 | } | |||
5458 | *vars++ = '\0'; | |||
5459 | ||||
5460 | if ((psession = switch_core_session_locate(uuid)switch_core_session_perform_locate(uuid, "mod_commands.c", (const char *)__func__, 5460))) { | |||
5461 | switch_channel_t *channel = switch_core_session_get_channel(psession); | |||
5462 | int x, y = 0; | |||
5463 | argc = switch_separate_string(vars, ';', argv, (sizeof(argv) / sizeof(argv[0]))); | |||
5464 | ||||
5465 | for (x = 0; x < argc; x++) { | |||
5466 | var_name = argv[x]; | |||
5467 | if (var_name && (var_value = strchr(var_name, '=')(__extension__ (__builtin_constant_p ('=') && !__builtin_constant_p (var_name) && ('=') == '\0' ? (char *) __rawmemchr ( var_name, '=') : __builtin_strchr (var_name, '='))))) { | |||
5468 | *var_value++ = '\0'; | |||
5469 | } | |||
5470 | if (zstr(var_name)_zstr(var_name)) { | |||
5471 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "mod_commands.c", (const char *)__func__ , 5471, (const char*)(session), SWITCH_LOG_ERROR, "No variable name specified.\n"); | |||
5472 | stream->write_function(stream, "-ERR No variable specified\n"); | |||
5473 | } else { | |||
5474 | switch_channel_set_variable(channel, var_name, var_value)switch_channel_set_variable_var_check(channel, var_name, var_value , SWITCH_TRUE); | |||
5475 | y++; | |||
5476 | } | |||
5477 | } | |||
5478 | ||||
5479 | switch_core_session_rwunlock(psession); | |||
5480 | if (y) { | |||
5481 | stream->write_function(stream, "+OK\n"); | |||
5482 | goto done; | |||
5483 | } | |||
5484 | } else { | |||
5485 | stream->write_function(stream, "-ERR No such channel!\n"); | |||
5486 | } | |||
5487 | } | |||
5488 | ||||
5489 | stream->write_function(stream, "-USAGE: %s\n", SETVAR_MULTI_SYNTAX"<uuid> <var>=<value>;<var>=<value>..."); | |||
5490 | ||||
5491 | done: | |||
5492 | switch_safe_free(mycmd)if (mycmd) {free(mycmd);mycmd=((void*)0);}; | |||
5493 | return SWITCH_STATUS_SUCCESS; | |||
5494 | } | |||
5495 | ||||
5496 | #define EXISTS_SYNTAX"<uuid>" "<uuid>" | |||
5497 | SWITCH_STANDARD_API(uuid_exists_function)static switch_status_t uuid_exists_function ( const char *cmd , switch_core_session_t *session, switch_stream_handle_t *stream ) | |||
5498 | { | |||
5499 | switch_bool_t exists = SWITCH_FALSE; | |||
5500 | ||||
5501 | if (cmd) { | |||
5502 | exists = switch_ivr_uuid_exists(cmd); | |||
5503 | } | |||
5504 | ||||
5505 | stream->write_function(stream, "%s", exists ? "true" : "false"); | |||
5506 | ||||
5507 | return SWITCH_STATUS_SUCCESS; | |||
5508 | } | |||
5509 | ||||
5510 | ||||
5511 | #define GETVAR_SYNTAX"<uuid> <var>" "<uuid> <var>" | |||
5512 | SWITCH_STANDARD_API(uuid_getvar_function)static switch_status_t uuid_getvar_function ( const char *cmd , switch_core_session_t *session, switch_stream_handle_t *stream ) | |||
5513 | { | |||
5514 | switch_core_session_t *psession = NULL((void*)0); | |||
5515 | char *mycmd = NULL((void*)0), *argv[4] = { 0 }; | |||
5516 | int argc = 0; | |||
5517 | ||||
5518 | if (!zstr(cmd)_zstr(cmd) && (mycmd = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))))) { | |||
5519 | argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | |||
5520 | if (argc >= 2 && !zstr(argv[0])_zstr(argv[0])) { | |||
5521 | char *uuid = argv[0]; | |||
5522 | char *var_name = argv[1]; | |||
5523 | const char *var_value = NULL((void*)0); | |||
5524 | ||||
5525 | if ((psession = switch_core_session_locate(uuid)switch_core_session_perform_locate(uuid, "mod_commands.c", (const char *)__func__, 5525))) { | |||
5526 | switch_channel_t *channel; | |||
5527 | channel = switch_core_session_get_channel(psession); | |||
5528 | ||||
5529 | if (zstr(var_name)_zstr(var_name)) { | |||
5530 | stream->write_function(stream, "-ERR No variable name specified!\n"); | |||
5531 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "mod_commands.c", (const char *)__func__ , 5531, (const char*)(session), SWITCH_LOG_ERROR, "No variable name specified.\n"); | |||
5532 | } else { | |||
5533 | var_value = switch_channel_get_variable(channel, var_name)switch_channel_get_variable_dup(channel, var_name, SWITCH_TRUE , -1); | |||
5534 | if (var_value != NULL((void*)0)) { | |||
5535 | stream->write_function(stream, "%s", var_value); | |||
5536 | } else { | |||
5537 | stream->write_function(stream, "_undef_"); | |||
5538 | } | |||
5539 | } | |||
5540 | ||||
5541 | switch_core_session_rwunlock(psession); | |||
5542 | ||||
5543 | } else { | |||
5544 | stream->write_function(stream, "-ERR No such channel!\n"); | |||
5545 | } | |||
5546 | goto done; | |||
5547 | } | |||
5548 | } | |||
5549 | ||||
5550 | stream->write_function(stream, "-USAGE: %s\n", GETVAR_SYNTAX"<uuid> <var>"); | |||
5551 | ||||
5552 | done: | |||
5553 | switch_safe_free(mycmd)if (mycmd) {free(mycmd);mycmd=((void*)0);}; | |||
5554 | return SWITCH_STATUS_SUCCESS; | |||
5555 | } | |||
5556 | ||||
5557 | ||||
5558 | #define FILEMAN_SYNTAX"<uuid> <cmd>:<val>" "<uuid> <cmd>:<val>" | |||
5559 | SWITCH_STANDARD_API(uuid_fileman_function)static switch_status_t uuid_fileman_function ( const char *cmd , switch_core_session_t *session, switch_stream_handle_t *stream ) | |||
5560 | { | |||
5561 | switch_core_session_t *psession = NULL((void*)0); | |||
5562 | char *mycmd = NULL((void*)0), *argv[4] = { 0 }; | |||
5563 | int argc = 0; | |||
5564 | ||||
5565 | if (!zstr(cmd)_zstr(cmd) && (mycmd = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))))) { | |||
5566 | argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | |||
5567 | if (argc >= 2 && !zstr(argv[0])_zstr(argv[0])) { | |||
5568 | char *uuid = argv[0]; | |||
5569 | char *cmd = argv[1]; | |||
5570 | ||||
5571 | if ((psession = switch_core_session_locate(uuid)switch_core_session_perform_locate(uuid, "mod_commands.c", (const char *)__func__, 5571))) { | |||
5572 | //switch_channel_t *channel; | |||
5573 | switch_file_handle_t *fh = NULL((void*)0); | |||
5574 | ||||
5575 | //channel = switch_core_session_get_channel(psession); | |||
5576 | ||||
5577 | if (switch_ivr_get_file_handle(psession, &fh) == SWITCH_STATUS_SUCCESS) { | |||
5578 | switch_ivr_process_fh(psession, cmd, fh); | |||
5579 | switch_ivr_release_file_handle(psession, &fh); | |||
5580 | stream->write_function(stream, "+OK\n"); | |||
5581 | } else { | |||
5582 | stream->write_function(stream, "-ERR No file handle!\n"); | |||
5583 | } | |||
5584 | ||||
5585 | switch_core_session_rwunlock(psession); | |||
5586 | ||||
5587 | } else { | |||
5588 | stream->write_function(stream, "-ERR No such channel!\n"); | |||
5589 | } | |||
5590 | goto done; | |||
5591 | } | |||
5592 | } | |||
5593 | ||||
5594 | stream->write_function(stream, "-USAGE: %s\n", FILEMAN_SYNTAX"<uuid> <cmd>:<val>"); | |||
5595 | ||||
5596 | done: | |||
5597 | switch_safe_free(mycmd)if (mycmd) {free(mycmd);mycmd=((void*)0);}; | |||
5598 | return SWITCH_STATUS_SUCCESS; | |||
5599 | } | |||
5600 | ||||
5601 | #define UUID_SEND_DTMF_SYNTAX"<uuid> <dtmf_data>" "<uuid> <dtmf_data>" | |||
5602 | SWITCH_STANDARD_API(uuid_send_dtmf_function)static switch_status_t uuid_send_dtmf_function ( const char * cmd, switch_core_session_t *session, switch_stream_handle_t * stream) | |||
5603 | { | |||
5604 | switch_core_session_t *psession = NULL((void*)0); | |||
5605 | char *mycmd = NULL((void*)0), *argv[2] = { 0 }; | |||
5606 | char *uuid = NULL((void*)0), *dtmf_data = NULL((void*)0); | |||
5607 | int argc = 0; | |||
5608 | ||||
5609 | if (zstr(cmd)_zstr(cmd)) { | |||
5610 | goto usage; | |||
5611 | } | |||
5612 | ||||
5613 | if (!(mycmd = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))))) { | |||
5614 | goto usage; | |||
5615 | } | |||
5616 | ||||
5617 | if ((argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) < 2) { | |||
5618 | goto usage; | |||
5619 | } | |||
5620 | ||||
5621 | uuid = argv[0]; | |||
5622 | dtmf_data = argv[1]; | |||
5623 | if (zstr(uuid)_zstr(uuid) || zstr(dtmf_data)_zstr(dtmf_data)) { | |||
5624 | goto usage; | |||
5625 | } | |||
5626 | ||||
5627 | if (!(psession = switch_core_session_locate(uuid)switch_core_session_perform_locate(uuid, "mod_commands.c", (const char *)__func__, 5627))) { | |||
5628 | stream->write_function(stream, "-ERR Cannot locate session!\n"); | |||
5629 | return SWITCH_STATUS_SUCCESS; | |||
5630 | } | |||
5631 | ||||
5632 | switch_core_session_send_dtmf_string(psession, (const char *) dtmf_data); | |||
5633 | goto done; | |||
5634 | ||||
5635 | usage: | |||
5636 | stream->write_function(stream, "-USAGE: %s\n", UUID_SEND_DTMF_SYNTAX"<uuid> <dtmf_data>"); | |||
5637 | ||||
5638 | done: | |||
5639 | if (psession) { | |||
5640 | switch_core_session_rwunlock(psession); | |||
5641 | } | |||
5642 | ||||
5643 | switch_safe_free(mycmd)if (mycmd) {free(mycmd);mycmd=((void*)0);}; | |||
5644 | return SWITCH_STATUS_SUCCESS; | |||
5645 | } | |||
5646 | ||||
5647 | ||||
5648 | ||||
5649 | #define UUID_RECV_DTMF_SYNTAX"<uuid> <dtmf_data>" "<uuid> <dtmf_data>" | |||
5650 | SWITCH_STANDARD_API(uuid_recv_dtmf_function)static switch_status_t uuid_recv_dtmf_function ( const char * cmd, switch_core_session_t *session, switch_stream_handle_t * stream) | |||
5651 | { | |||
5652 | switch_core_session_t *psession = NULL((void*)0); | |||
5653 | char *mycmd = NULL((void*)0), *argv[2] = { 0 }; | |||
5654 | char *uuid = NULL((void*)0), *dtmf_data = NULL((void*)0); | |||
5655 | int argc = 0; | |||
5656 | ||||
5657 | if (zstr(cmd)_zstr(cmd)) { | |||
5658 | goto usage; | |||
5659 | } | |||
5660 | ||||
5661 | if (!(mycmd = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))))) { | |||
5662 | goto usage; | |||
5663 | } | |||
5664 | ||||
5665 | if ((argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) < 2) { | |||
5666 | goto usage; | |||
5667 | } | |||
5668 | ||||
5669 | uuid = argv[0]; | |||
5670 | dtmf_data = argv[1]; | |||
5671 | if (zstr(uuid)_zstr(uuid) || zstr(dtmf_data)_zstr(dtmf_data)) { | |||
5672 | goto usage; | |||
5673 | } | |||
5674 | ||||
5675 | if (!(psession = switch_core_session_locate(uuid)switch_core_session_perform_locate(uuid, "mod_commands.c", (const char *)__func__, 5675))) { | |||
5676 | stream->write_function(stream, "-ERR Cannot locate session!\n"); | |||
5677 | return SWITCH_STATUS_SUCCESS; | |||
5678 | } | |||
5679 | ||||
5680 | switch_channel_queue_dtmf_string(switch_core_session_get_channel(psession), dtmf_data); | |||
5681 | goto done; | |||
5682 | ||||
5683 | usage: | |||
5684 | stream->write_function(stream, "-USAGE: %s\n", UUID_RECV_DTMF_SYNTAX"<uuid> <dtmf_data>"); | |||
5685 | ||||
5686 | done: | |||
5687 | if (psession) { | |||
5688 | switch_core_session_rwunlock(psession); | |||
5689 | } | |||
5690 | ||||
5691 | switch_safe_free(mycmd)if (mycmd) {free(mycmd);mycmd=((void*)0);}; | |||
5692 | return SWITCH_STATUS_SUCCESS; | |||
5693 | } | |||
5694 | ||||
5695 | #define DUMP_SYNTAX"<uuid> [format]" "<uuid> [format]" | |||
5696 | SWITCH_STANDARD_API(uuid_dump_function)static switch_status_t uuid_dump_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
5697 | { | |||
5698 | switch_core_session_t *psession = NULL((void*)0); | |||
5699 | char *mycmd = NULL((void*)0), *argv[2] = { 0 }; | |||
5700 | int argc = 0; | |||
5701 | ||||
5702 | if (!zstr(cmd)_zstr(cmd) && (mycmd = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))))) { | |||
5703 | argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | |||
5704 | if (argc >= 0 && !zstr(argv[0])_zstr(argv[0])) { | |||
5705 | char *uuid = argv[0]; | |||
5706 | char *format = argv[1]; | |||
5707 | ||||
5708 | if (!format) { | |||
5709 | format = "txt"; | |||
5710 | } | |||
5711 | ||||
5712 | if ((psession = switch_core_session_locate(uuid)switch_core_session_perform_locate(uuid, "mod_commands.c", (const char *)__func__, 5712))) { | |||
5713 | switch_channel_t *channel; | |||
5714 | switch_event_t *event; | |||
5715 | char *buf; | |||
5716 | ||||
5717 | channel = switch_core_session_get_channel(psession); | |||
5718 | ||||
5719 | if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_DATA)switch_event_create_subclass_detailed("mod_commands.c", (const char * )(const char *)__func__, 5719, &event, SWITCH_EVENT_CHANNEL_DATA , ((void*)0)) == SWITCH_STATUS_SUCCESS) { | |||
5720 | switch_xml_t xml; | |||
5721 | switch_channel_event_set_data(channel, event); | |||
5722 | if (!strcasecmp(format, "xml")) { | |||
5723 | if ((xml = switch_event_xmlize(event, SWITCH_VA_NONE"%s", ""))) { | |||
5724 | buf = switch_xml_toxml(xml, SWITCH_FALSE); | |||
5725 | switch_xml_free(xml); | |||
5726 | } else { | |||
5727 | stream->write_function(stream, "-ERR Unable to create xml!\n"); | |||
5728 | switch_event_destroy(&event); | |||
5729 | switch_core_session_rwunlock(psession); | |||
5730 | goto done; | |||
5731 | } | |||
5732 | } else if (!strcasecmp(format, "json")) { | |||
5733 | switch_event_serialize_json(event, &buf); | |||
5734 | } else { | |||
5735 | switch_event_serialize(event, &buf, (switch_bool_t) strcasecmp(format, "plain")); | |||
5736 | } | |||
5737 | ||||
5738 | switch_assert(buf)((buf) ? (void) (0) : __assert_fail ("buf", "mod_commands.c", 5738, __PRETTY_FUNCTION__)); | |||
5739 | stream->raw_write_function(stream, (unsigned char *) buf, strlen(buf)); | |||
5740 | switch_event_destroy(&event); | |||
5741 | free(buf); | |||
5742 | } else { | |||
5743 | stream->write_function(stream, "-ERR Allocation error\n"); | |||
5744 | } | |||
5745 | ||||
5746 | switch_core_session_rwunlock(psession); | |||
5747 | ||||
5748 | } else { | |||
5749 | stream->write_function(stream, "-ERR No such channel!\n"); | |||
5750 | } | |||
5751 | goto done; | |||
5752 | } | |||
5753 | } | |||
5754 | ||||
5755 | stream->write_function(stream, "-USAGE: %s\n", DUMP_SYNTAX"<uuid> [format]"); | |||
5756 | ||||
5757 | done: | |||
5758 | switch_safe_free(mycmd)if (mycmd) {free(mycmd);mycmd=((void*)0);}; | |||
5759 | return SWITCH_STATUS_SUCCESS; | |||
5760 | } | |||
5761 | ||||
5762 | #define GLOBAL_SETVAR_SYNTAX"<var>=<value> [=<value2>]" "<var>=<value> [=<value2>]" | |||
5763 | SWITCH_STANDARD_API(global_setvar_function)static switch_status_t global_setvar_function ( const char *cmd , switch_core_session_t *session, switch_stream_handle_t *stream ) | |||
5764 | { | |||
5765 | char *mycmd = NULL((void*)0), *argv[3] = { 0 }; | |||
5766 | int argc = 0; | |||
5767 | ||||
5768 | if (!zstr(cmd)_zstr(cmd) && (mycmd = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))))) { | |||
5769 | argc = switch_separate_string(mycmd, '=', argv, (sizeof(argv) / sizeof(argv[0]))); | |||
5770 | if (argc > 0 && !zstr(argv[0])_zstr(argv[0])) { | |||
5771 | char *var_name = argv[0]; | |||
5772 | char *var_value = argv[1]; | |||
5773 | char *var_value2 = argv[2]; | |||
5774 | ||||
5775 | if (zstr(var_value)_zstr(var_value)) { | |||
5776 | var_value = NULL((void*)0); | |||
5777 | } | |||
5778 | ||||
5779 | if (zstr(var_value2)_zstr(var_value2)) { | |||
5780 | var_value2 = NULL((void*)0); | |||
5781 | } | |||
5782 | ||||
5783 | if (var_value2) { | |||
5784 | switch_core_set_var_conditional(var_name, var_value, var_value2); | |||
5785 | } else { | |||
5786 | switch_core_set_variable(var_name, var_value); | |||
5787 | } | |||
5788 | stream->write_function(stream, "+OK"); | |||
5789 | goto done; | |||
5790 | } | |||
5791 | } | |||
5792 | ||||
5793 | stream->write_function(stream, "-USAGE: %s\n", GLOBAL_SETVAR_SYNTAX"<var>=<value> [=<value2>]"); | |||
5794 | ||||
5795 | done: | |||
5796 | switch_safe_free(mycmd)if (mycmd) {free(mycmd);mycmd=((void*)0);}; | |||
5797 | return SWITCH_STATUS_SUCCESS; | |||
5798 | } | |||
5799 | ||||
5800 | #define GLOBAL_GETVAR_SYNTAX"<var>" "<var>" | |||
5801 | SWITCH_STANDARD_API(global_getvar_function)static switch_status_t global_getvar_function ( const char *cmd , switch_core_session_t *session, switch_stream_handle_t *stream ) | |||
5802 | { | |||
5803 | if (zstr(cmd)_zstr(cmd)) { | |||
5804 | switch_core_dump_variables(stream); | |||
5805 | } else { | |||
5806 | char *var = switch_core_get_variable_dup(cmd); | |||
5807 | stream->write_function(stream, "%s", switch_str_nil(var)(var ? var : "")); | |||
5808 | switch_safe_free(var)if (var) {free(var);var=((void*)0);}; | |||
5809 | } | |||
5810 | return SWITCH_STATUS_SUCCESS; | |||
5811 | } | |||
5812 | ||||
5813 | #define SYSTEM_SYNTAX"<command>" "<command>" | |||
5814 | SWITCH_STANDARD_API(system_function)static switch_status_t system_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
5815 | { | |||
5816 | if (zstr(cmd)_zstr(cmd)) { | |||
5817 | stream->write_function(stream, "-USAGE: %s\n", SYSTEM_SYNTAX"<command>"); | |||
5818 | return SWITCH_STATUS_SUCCESS; | |||
5819 | } | |||
5820 | ||||
5821 | if (switch_stream_system(cmd, stream) < 0) { | |||
5822 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "mod_commands.c", (const char *)__func__ , 5822, (const char*)(session), SWITCH_LOG_NOTICE, "Failed to execute command: %s\n", cmd); | |||
5823 | } | |||
5824 | ||||
5825 | return SWITCH_STATUS_SUCCESS; | |||
5826 | } | |||
5827 | ||||
5828 | ||||
5829 | #define SYSTEM_SYNTAX"<command>" "<command>" | |||
5830 | SWITCH_STANDARD_API(bg_system_function)static switch_status_t bg_system_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
5831 | { | |||
5832 | if (zstr(cmd)_zstr(cmd)) { | |||
5833 | stream->write_function(stream, "-USAGE: %s\n", SYSTEM_SYNTAX"<command>"); | |||
5834 | return SWITCH_STATUS_SUCCESS; | |||
5835 | } | |||
5836 | ||||
5837 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "mod_commands.c", (const char *)__func__ , 5837, (const char*)(session), SWITCH_LOG_NOTICE, "Executing command: %s\n", cmd); | |||
5838 | if (switch_system(cmd, SWITCH_FALSE) < 0) { | |||
5839 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "mod_commands.c", (const char *)__func__ , 5839, (const char*)(session), SWITCH_LOG_NOTICE, "Failed to execute command: %s\n", cmd); | |||
5840 | } | |||
5841 | stream->write_function(stream, "+OK\n"); | |||
5842 | return SWITCH_STATUS_SUCCESS; | |||
5843 | } | |||
5844 | ||||
5845 | SWITCH_STANDARD_API(strftime_tz_api_function)static switch_status_t strftime_tz_api_function ( const char * cmd, switch_core_session_t *session, switch_stream_handle_t * stream) | |||
5846 | { | |||
5847 | char *format = NULL((void*)0); | |||
5848 | const char *tz_name = NULL((void*)0); | |||
5849 | char date[80] = ""; | |||
5850 | char *mycmd = NULL((void*)0), *p; | |||
5851 | switch_time_t when = 0; | |||
5852 | ||||
5853 | if (cmd) mycmd = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))); | |||
5854 | ||||
5855 | if (!zstr(mycmd)_zstr(mycmd)) { | |||
5856 | tz_name = mycmd; | |||
5857 | ||||
5858 | if ((format = strchr(mycmd, ' ')(__extension__ (__builtin_constant_p (' ') && !__builtin_constant_p (mycmd) && (' ') == '\0' ? (char *) __rawmemchr (mycmd , ' ') : __builtin_strchr (mycmd, ' '))))) { | |||
5859 | *format++ = '\0'; | |||
5860 | ||||
5861 | if (format && (p = strchr(format, '|')(__extension__ (__builtin_constant_p ('|') && !__builtin_constant_p (format) && ('|') == '\0' ? (char *) __rawmemchr (format , '|') : __builtin_strchr (format, '|'))))) { | |||
5862 | *p++ = '\0'; | |||
5863 | when = atol(format); | |||
5864 | format = p; | |||
5865 | } | |||
5866 | } | |||
5867 | } | |||
5868 | ||||
5869 | if (zstr(format)_zstr(format)) { | |||
5870 | format = "%Y-%m-%d %T"; | |||
5871 | } | |||
5872 | ||||
5873 | if (format && switch_strftime_tz(tz_name, format, date, sizeof(date), when * 1000000) == SWITCH_STATUS_SUCCESS) { /* The lookup of the zone may fail. */ | |||
5874 | stream->write_function(stream, "%s", date); | |||
5875 | } else { | |||
5876 | stream->write_function(stream, "-ERR Invalid timezone/format\n"); | |||
5877 | } | |||
5878 | ||||
5879 | switch_safe_free(mycmd)if (mycmd) {free(mycmd);mycmd=((void*)0);}; | |||
5880 | ||||
5881 | return SWITCH_STATUS_SUCCESS; | |||
5882 | } | |||
5883 | ||||
5884 | SWITCH_STANDARD_API(hupall_api_function)static switch_status_t hupall_api_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream ) | |||
5885 | { | |||
5886 | char *mycmd = NULL((void*)0), *argv[3] = { 0 }; | |||
5887 | char *var = NULL((void*)0); | |||
5888 | char *val = NULL((void*)0); | |||
5889 | switch_call_cause_t cause = SWITCH_CAUSE_MANAGER_REQUEST; | |||
5890 | ||||
5891 | if (!zstr(cmd)_zstr(cmd) && (mycmd = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))))) { | |||
5892 | switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | |||
5893 | switch_assert(argv[0])((argv[0]) ? (void) (0) : __assert_fail ("argv[0]", "mod_commands.c" , 5893, __PRETTY_FUNCTION__)); | |||
5894 | if ((cause = switch_channel_str2cause(argv[0])) == SWITCH_CAUSE_NONE) { | |||
5895 | cause = SWITCH_CAUSE_MANAGER_REQUEST; | |||
5896 | } | |||
5897 | var = argv[1]; | |||
5898 | val = argv[2]; | |||
5899 | } | |||
5900 | ||||
5901 | if (!val) { | |||
5902 | var = NULL((void*)0); | |||
5903 | } | |||
5904 | ||||
5905 | if (zstr(var)_zstr(var)) { | |||
5906 | switch_core_session_hupall(cause); | |||
5907 | } else { | |||
5908 | switch_core_session_hupall_matching_var(var, val, cause)switch_core_session_hupall_matching_var_ans(var, val, cause, SHT_UNANSWERED | SHT_ANSWERED); | |||
5909 | } | |||
5910 | ||||
5911 | if (zstr(var)_zstr(var)) { | |||
5912 | stream->write_function(stream, "+OK hangup all channels with cause %s\n", switch_channel_cause2str(cause)); | |||
5913 | } else { | |||
5914 | stream->write_function(stream, "+OK hangup all channels matching [%s]=[%s] with cause: %s\n", var, val, switch_channel_cause2str(cause)); | |||
5915 | } | |||
5916 | ||||
5917 | switch_safe_free(mycmd)if (mycmd) {free(mycmd);mycmd=((void*)0);}; | |||
5918 | return SWITCH_STATUS_SUCCESS; | |||
5919 | } | |||
5920 | ||||
5921 | ||||
5922 | SWITCH_STANDARD_API(xml_flush_function)static switch_status_t xml_flush_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
5923 | { | |||
5924 | char *mycmd = NULL((void*)0), *argv[3] = { 0 }; | |||
5925 | int argc = 0; | |||
5926 | int r = 0; | |||
5927 | ||||
5928 | if (!zstr(cmd)_zstr(cmd) && (mycmd = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))))) { | |||
5929 | argc = switch_split(mycmd, ' ', argv)switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof (argv[0]))); | |||
5930 | } | |||
5931 | ||||
5932 | if (argc == 3) { | |||
5933 | r = switch_xml_clear_user_cache(argv[0], argv[1], argv[2]); | |||
5934 | } else { | |||
5935 | r = switch_xml_clear_user_cache(NULL((void*)0), NULL((void*)0), NULL((void*)0)); | |||
5936 | } | |||
5937 | ||||
5938 | ||||
5939 | stream->write_function(stream, "+OK cleared %u entr%s\n", r, r == 1 ? "y" : "ies"); | |||
5940 | ||||
5941 | switch_safe_free(mycmd)if (mycmd) {free(mycmd);mycmd=((void*)0);}; | |||
5942 | return SWITCH_STATUS_SUCCESS; | |||
5943 | } | |||
5944 | ||||
5945 | SWITCH_STANDARD_API(escape_function)static switch_status_t escape_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
5946 | { | |||
5947 | int len; | |||
5948 | char *mycmd; | |||
5949 | ||||
5950 | if (zstr(cmd)_zstr(cmd)) { | |||
5951 | return SWITCH_STATUS_SUCCESS; | |||
5952 | } | |||
5953 | ||||
5954 | len = (int)strlen(cmd) * 2 + 1; | |||
5955 | mycmd = malloc(len); | |||
5956 | ||||
5957 | stream->write_function(stream, "%s", switch_escape_string(cmd, mycmd, len)); | |||
5958 | ||||
5959 | switch_safe_free(mycmd)if (mycmd) {free(mycmd);mycmd=((void*)0);}; | |||
5960 | return SWITCH_STATUS_SUCCESS; | |||
5961 | } | |||
5962 | ||||
5963 | SWITCH_STANDARD_API(quote_shell_arg_function)static switch_status_t quote_shell_arg_function ( const char * cmd, switch_core_session_t *session, switch_stream_handle_t * stream) | |||
5964 | { | |||
5965 | switch_memory_pool_t *pool; | |||
5966 | ||||
5967 | if (zstr(cmd)_zstr(cmd)) { | |||
5968 | return SWITCH_STATUS_SUCCESS; | |||
5969 | } | |||
5970 | ||||
5971 | switch_core_new_memory_pool(&pool)switch_core_perform_new_memory_pool(&pool, "mod_commands.c" , (const char *)__func__, 5971); | |||
5972 | ||||
5973 | stream->write_function(stream, "%s", switch_util_quote_shell_arg_pool(cmd, pool)); | |||
5974 | ||||
5975 | switch_core_destroy_memory_pool(&pool)switch_core_perform_destroy_memory_pool(&pool, "mod_commands.c" , (const char *)__func__, 5975); | |||
5976 | return SWITCH_STATUS_SUCCESS; | |||
5977 | } | |||
5978 | ||||
5979 | #define UUID_LOGLEVEL_SYNTAX"<uuid> <level>" "<uuid> <level>" | |||
5980 | SWITCH_STANDARD_API(uuid_loglevel)static switch_status_t uuid_loglevel ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
5981 | { | |||
5982 | switch_core_session_t *tsession = NULL((void*)0), *bsession = NULL((void*)0); | |||
5983 | char *uuid = NULL((void*)0), *text = NULL((void*)0); | |||
5984 | int b = 0; | |||
5985 | ||||
5986 | if (!zstr(cmd)_zstr(cmd) && (uuid = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))))) { | |||
5987 | if ((text = strchr(uuid, ' ')(__extension__ (__builtin_constant_p (' ') && !__builtin_constant_p (uuid) && (' ') == '\0' ? (char *) __rawmemchr (uuid , ' ') : __builtin_strchr (uuid, ' '))))) { | |||
5988 | *text++ = '\0'; | |||
5989 | ||||
5990 | if (!strncasecmp(text, "-b", 2)) { | |||
5991 | b++; | |||
5992 | if ((text = strchr(text, ' ')(__extension__ (__builtin_constant_p (' ') && !__builtin_constant_p (text) && (' ') == '\0' ? (char *) __rawmemchr (text , ' ') : __builtin_strchr (text, ' '))))) { | |||
5993 | *text++ = '\0'; | |||
5994 | } | |||
5995 | } | |||
5996 | } | |||
5997 | } | |||
5998 | ||||
5999 | if (zstr(uuid)_zstr(uuid) || zstr(text)_zstr(text)) { | |||
6000 | stream->write_function(stream, "-USAGE: %s\n", UUID_LOGLEVEL_SYNTAX"<uuid> <level>"); | |||
6001 | } else { | |||
6002 | switch_log_level_t level = switch_log_str2level(text); | |||
6003 | ||||
6004 | if (level == SWITCH_LOG_INVALID) { | |||
6005 | stream->write_function(stream, "-ERR Invalid log level!\n"); | |||
6006 | } else if ((tsession = switch_core_session_locate(uuid)switch_core_session_perform_locate(uuid, "mod_commands.c", (const char *)__func__, 6006))) { | |||
6007 | ||||
6008 | switch_core_session_set_loglevel(tsession, level); | |||
6009 | ||||
6010 | if (b && switch_core_session_get_partner(tsession, &bsession)switch_core_session_perform_get_partner(tsession, &bsession , "mod_commands.c", (const char *)__func__, 6010) == SWITCH_STATUS_SUCCESS) { | |||
6011 | switch_core_session_set_loglevel(bsession, level); | |||
6012 | switch_core_session_rwunlock(bsession); | |||
6013 | } | |||
6014 | ||||
6015 | stream->write_function(stream, "+OK\n"); | |||
6016 | switch_core_session_rwunlock(tsession); | |||
6017 | } else { | |||
6018 | stream->write_function(stream, "-ERR No such channel %s!\n", uuid); | |||
6019 | } | |||
6020 | } | |||
6021 | ||||
6022 | switch_safe_free(uuid)if (uuid) {free(uuid);uuid=((void*)0);}; | |||
6023 | return SWITCH_STATUS_SUCCESS; | |||
6024 | } | |||
6025 | ||||
6026 | #define SQL_ESCAPE_SYNTAX"<string>" "<string>" | |||
6027 | SWITCH_STANDARD_API(sql_escape)static switch_status_t sql_escape ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
6028 | { | |||
6029 | if (!cmd) { | |||
6030 | stream->write_function(stream, "-USAGE: %s\n", SQL_ESCAPE_SYNTAX"<string>"); | |||
6031 | } else { | |||
6032 | stream->write_function(stream, "%q", cmd); | |||
6033 | } | |||
6034 | ||||
6035 | return SWITCH_STATUS_SUCCESS; | |||
6036 | } | |||
6037 | ||||
6038 | /* LIMIT Stuff */ | |||
6039 | #define LIMIT_USAGE_SYNTAX"<backend> <realm> <id> [rate]" "<backend> <realm> <id> [rate]" | |||
6040 | SWITCH_STANDARD_API(limit_usage_function)static switch_status_t limit_usage_function ( const char *cmd , switch_core_session_t *session, switch_stream_handle_t *stream ) | |||
6041 | { | |||
6042 | int argc = 0; | |||
6043 | char *argv[5] = { 0 }; | |||
6044 | char *mydata = NULL((void*)0); | |||
6045 | uint32_t count = 0; | |||
6046 | uint32_t rcount = 0; | |||
6047 | switch_bool_t dorate = SWITCH_FALSE; | |||
6048 | ||||
6049 | if (!zstr(cmd)_zstr(cmd)) { | |||
6050 | mydata = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))); | |||
6051 | switch_assert(mydata)((mydata) ? (void) (0) : __assert_fail ("mydata", "mod_commands.c" , 6051, __PRETTY_FUNCTION__)); | |||
6052 | argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | |||
6053 | } | |||
6054 | ||||
6055 | /* backwards compat version */ | |||
6056 | if (argc == 2) { | |||
6057 | switch_safe_free(mydata)if (mydata) {free(mydata);mydata=((void*)0);}; | |||
6058 | /* allocate space for "db " */ | |||
6059 | mydata = malloc(strlen(cmd) + 10); | |||
6060 | switch_assert(mydata)((mydata) ? (void) (0) : __assert_fail ("mydata", "mod_commands.c" , 6060, __PRETTY_FUNCTION__)); | |||
6061 | sprintf(mydata, "db %s", cmd); | |||
6062 | argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | |||
6063 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_commands.c", (const char *)__func__ , 6063, ((void*)0), SWITCH_LOG_WARNING, "Using deprecated limit api: Please specify backend. Defaulting to 'db' backend.\n"); | |||
6064 | } | |||
6065 | ||||
6066 | if (argc < 3) { | |||
6067 | stream->write_function(stream, "USAGE: limit_usage %s\n", LIMIT_USAGE_SYNTAX"<backend> <realm> <id> [rate]"); | |||
6068 | goto end; | |||
6069 | } | |||
6070 | ||||
6071 | if (argc > 3) { | |||
6072 | if (!strcasecmp("rate", argv[3])) { | |||
6073 | dorate = SWITCH_TRUE; | |||
6074 | } | |||
6075 | } | |||
6076 | ||||
6077 | count = switch_limit_usage(argv[0], argv[1], argv[2], &rcount); | |||
6078 | ||||
6079 | if (dorate == SWITCH_TRUE) { | |||
6080 | stream->write_function(stream, "%d/%d", count, rcount); | |||
6081 | } else { | |||
6082 | stream->write_function(stream, "%d", count); | |||
6083 | } | |||
6084 | ||||
6085 | end: | |||
6086 | switch_safe_free(mydata)if (mydata) {free(mydata);mydata=((void*)0);}; | |||
6087 | ||||
6088 | return SWITCH_STATUS_SUCCESS; | |||
6089 | } | |||
6090 | ||||
6091 | #define LIMIT_HASH_USAGE_SYNTAX"<realm> <id> [rate] (Using deprecated limit api, check limit_usage with backend param)" "<realm> <id> [rate] (Using deprecated limit api, check limit_usage with backend param)" | |||
6092 | SWITCH_STANDARD_API(limit_hash_usage_function)static switch_status_t limit_hash_usage_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
6093 | { | |||
6094 | char *mydata = NULL((void*)0); | |||
6095 | switch_status_t ret = SWITCH_STATUS_SUCCESS; | |||
6096 | if (!zstr(cmd)_zstr(cmd)) { | |||
6097 | mydata = switch_mprintf("hash %s", cmd); | |||
6098 | ret = limit_usage_function(mydata, session, stream); | |||
6099 | switch_safe_free(mydata)if (mydata) {free(mydata);mydata=((void*)0);}; | |||
6100 | return ret; | |||
6101 | } else { | |||
6102 | stream->write_function(stream, "USAGE: limit_hash_usage %s\n", LIMIT_HASH_USAGE_SYNTAX"<realm> <id> [rate] (Using deprecated limit api, check limit_usage with backend param)"); | |||
6103 | return SWITCH_STATUS_SUCCESS; | |||
6104 | } | |||
6105 | } | |||
6106 | ||||
6107 | #define LIMIT_STATUS_SYNTAX"<backend>" "<backend>" | |||
6108 | SWITCH_STANDARD_API(limit_status_function)static switch_status_t limit_status_function ( const char *cmd , switch_core_session_t *session, switch_stream_handle_t *stream ) | |||
6109 | { | |||
6110 | int argc = 0; | |||
6111 | char *argv[2] = { 0 }; | |||
6112 | char *mydata = NULL((void*)0); | |||
6113 | char *ret = NULL((void*)0); | |||
6114 | ||||
6115 | if (!zstr(cmd)_zstr(cmd)) { | |||
6116 | mydata = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))); | |||
6117 | switch_assert(mydata)((mydata) ? (void) (0) : __assert_fail ("mydata", "mod_commands.c" , 6117, __PRETTY_FUNCTION__)); | |||
6118 | argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | |||
6119 | } | |||
6120 | ||||
6121 | if (argc < 1) { | |||
6122 | stream->write_function(stream, "USAGE: limit_status %s\n", LIMIT_STATUS_SYNTAX"<backend>"); | |||
6123 | goto end; | |||
6124 | } | |||
6125 | ||||
6126 | ret = switch_limit_status(argv[0]); | |||
6127 | ||||
6128 | stream->write_function(stream, "%s", ret); | |||
6129 | ||||
6130 | end: | |||
6131 | switch_safe_free(mydata)if (mydata) {free(mydata);mydata=((void*)0);}; | |||
6132 | switch_safe_free(ret)if (ret) {free(ret);ret=((void*)0);}; | |||
6133 | ||||
6134 | return SWITCH_STATUS_SUCCESS; | |||
6135 | } | |||
6136 | ||||
6137 | #define LIMIT_RESET_SYNTAX"<backend>" "<backend>" | |||
6138 | SWITCH_STANDARD_API(limit_reset_function)static switch_status_t limit_reset_function ( const char *cmd , switch_core_session_t *session, switch_stream_handle_t *stream ) | |||
6139 | { | |||
6140 | int argc = 0; | |||
6141 | char *argv[2] = { 0 }; | |||
6142 | char *mydata = NULL((void*)0); | |||
6143 | switch_status_t ret = SWITCH_STATUS_SUCCESS; | |||
6144 | ||||
6145 | if (!zstr(cmd)_zstr(cmd)) { | |||
6146 | mydata = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))); | |||
6147 | switch_assert(mydata)((mydata) ? (void) (0) : __assert_fail ("mydata", "mod_commands.c" , 6147, __PRETTY_FUNCTION__)); | |||
6148 | argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | |||
6149 | } | |||
6150 | ||||
6151 | if (argc < 1) { | |||
6152 | stream->write_function(stream, "USAGE: limit_reset %s\n", LIMIT_RESET_SYNTAX"<backend>"); | |||
6153 | goto end; | |||
6154 | } | |||
6155 | ||||
6156 | ret = switch_limit_reset(argv[0]); | |||
6157 | ||||
6158 | stream->write_function(stream, "%s", (ret == SWITCH_STATUS_SUCCESS) ? "+OK" : "-ERR"); | |||
6159 | ||||
6160 | end: | |||
6161 | switch_safe_free(mydata)if (mydata) {free(mydata);mydata=((void*)0);}; | |||
6162 | ||||
6163 | return SWITCH_STATUS_SUCCESS; | |||
6164 | } | |||
6165 | ||||
6166 | #define LIMIT_SYNTAX"<uuid> <backend> <realm> <resource> [<max>[/interval]] [number [dialplan [context]]]" "<uuid> <backend> <realm> <resource> [<max>[/interval]] [number [dialplan [context]]]" | |||
6167 | SWITCH_STANDARD_API(uuid_limit_function)static switch_status_t uuid_limit_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream ) | |||
6168 | { | |||
6169 | int argc = 0; | |||
6170 | char *argv[8] = { 0 }; | |||
6171 | char *mydata = NULL((void*)0); | |||
6172 | char *realm = NULL((void*)0); | |||
6173 | char *resource = NULL((void*)0); | |||
6174 | char *xfer_exten = NULL((void*)0); | |||
6175 | int max = -1; | |||
6176 | int interval = 0; | |||
6177 | switch_core_session_t *sess = NULL((void*)0); | |||
6178 | switch_status_t res = SWITCH_STATUS_SUCCESS; | |||
6179 | ||||
6180 | if (!zstr(cmd)_zstr(cmd)) { | |||
6181 | mydata = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))); | |||
6182 | switch_assert(mydata)((mydata) ? (void) (0) : __assert_fail ("mydata", "mod_commands.c" , 6182, __PRETTY_FUNCTION__)); | |||
6183 | argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | |||
6184 | } | |||
6185 | ||||
6186 | if (argc < 4) { | |||
6187 | stream->write_function(stream, "USAGE: uuid_limit %s\n", LIMIT_SYNTAX"<uuid> <backend> <realm> <resource> [<max>[/interval]] [number [dialplan [context]]]"); | |||
6188 | goto end; | |||
6189 | } | |||
6190 | ||||
6191 | realm = argv[2]; | |||
6192 | resource = argv[3]; | |||
6193 | ||||
6194 | /* If max is omitted or negative, only act as a counter and skip maximum checks */ | |||
6195 | if (argc > 4) { | |||
6196 | if (argv[4][0] == '-') { | |||
6197 | max = -1; | |||
6198 | } else { | |||
6199 | char *szinterval = NULL((void*)0); | |||
6200 | if ((szinterval = strchr(argv[4], '/')(__extension__ (__builtin_constant_p ('/') && !__builtin_constant_p (argv[4]) && ('/') == '\0' ? (char *) __rawmemchr (argv [4], '/') : __builtin_strchr (argv[4], '/'))))) { | |||
6201 | *szinterval++ = '\0'; | |||
6202 | interval = atoi(szinterval); | |||
6203 | } | |||
6204 | ||||
6205 | max = atoi(argv[4]); | |||
6206 | ||||
6207 | if (max < 0) { | |||
6208 | max = 0; | |||
6209 | } | |||
6210 | } | |||
6211 | } | |||
6212 | ||||
6213 | if (argc > 5) { | |||
6214 | xfer_exten = argv[5]; | |||
6215 | } else { | |||
6216 | xfer_exten = LIMIT_DEF_XFER_EXTEN"limit_exceeded"; | |||
6217 | } | |||
6218 | ||||
6219 | sess = switch_core_session_locate(argv[0])switch_core_session_perform_locate(argv[0], "mod_commands.c", (const char *)__func__, 6219); | |||
6220 | if (!sess) { | |||
6221 | stream->write_function(stream, "-ERR Cannot find session with uuid %s\n", argv[0]); | |||
6222 | goto end; | |||
6223 | } | |||
6224 | ||||
6225 | res = switch_limit_incr(argv[1], sess, realm, resource, max, interval); | |||
6226 | ||||
6227 | if (res != SWITCH_STATUS_SUCCESS) { | |||
6228 | /* Limit exceeded */ | |||
6229 | if (*xfer_exten == '!') { | |||
6230 | switch_channel_t *channel = switch_core_session_get_channel(sess); | |||
6231 | switch_channel_hangup(channel, switch_channel_str2cause(xfer_exten + 1))switch_channel_perform_hangup(channel, "mod_commands.c", (const char *)__func__, 6231, switch_channel_str2cause(xfer_exten + 1)); | |||
6232 | } else { | |||
6233 | switch_ivr_session_transfer(sess, xfer_exten, argv[6], argv[7]); | |||
6234 | } | |||
6235 | } | |||
6236 | ||||
6237 | switch_core_session_rwunlock(sess); | |||
6238 | ||||
6239 | stream->write_function(stream, "+OK"); | |||
6240 | ||||
6241 | end: | |||
6242 | switch_safe_free(mydata)if (mydata) {free(mydata);mydata=((void*)0);}; | |||
6243 | ||||
6244 | return SWITCH_STATUS_SUCCESS; | |||
6245 | } | |||
6246 | ||||
6247 | #define LIMIT_RELEASE_SYNTAX"<uuid> <backend> [realm] [resource]" "<uuid> <backend> [realm] [resource]" | |||
6248 | SWITCH_STANDARD_API(uuid_limit_release_function)static switch_status_t uuid_limit_release_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
6249 | { | |||
6250 | int argc = 0; | |||
6251 | char *argv[5] = { 0 }; | |||
6252 | char *mydata = NULL((void*)0); | |||
6253 | char *realm = NULL((void*)0); | |||
6254 | char *resource = NULL((void*)0); | |||
6255 | switch_core_session_t *sess = NULL((void*)0); | |||
6256 | ||||
6257 | if (!zstr(cmd)_zstr(cmd)) { | |||
6258 | mydata = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))); | |||
6259 | switch_assert(mydata)((mydata) ? (void) (0) : __assert_fail ("mydata", "mod_commands.c" , 6259, __PRETTY_FUNCTION__)); | |||
6260 | argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | |||
6261 | } | |||
6262 | ||||
6263 | if (argc < 2) { | |||
6264 | stream->write_function(stream, "USAGE: uuid_limit_release %s\n", LIMIT_RELEASE_SYNTAX"<uuid> <backend> [realm] [resource]"); | |||
6265 | goto end; | |||
6266 | } | |||
6267 | ||||
6268 | if (argc > 2) { | |||
6269 | realm = argv[2]; | |||
6270 | } | |||
6271 | ||||
6272 | if (argc > 3) { | |||
6273 | resource = argv[3]; | |||
6274 | } | |||
6275 | ||||
6276 | sess = switch_core_session_locate(argv[0])switch_core_session_perform_locate(argv[0], "mod_commands.c", (const char *)__func__, 6276); | |||
6277 | if (!sess) { | |||
6278 | stream->write_function(stream, "-ERR Cannot find session with uuid %s\n", argv[0]); | |||
6279 | goto end; | |||
6280 | } | |||
6281 | ||||
6282 | switch_limit_release(argv[1], sess, realm, resource); | |||
6283 | ||||
6284 | switch_core_session_rwunlock(sess); | |||
6285 | ||||
6286 | stream->write_function(stream, "+OK"); | |||
6287 | ||||
6288 | end: | |||
6289 | switch_safe_free(mydata)if (mydata) {free(mydata);mydata=((void*)0);}; | |||
6290 | ||||
6291 | return SWITCH_STATUS_SUCCESS; | |||
6292 | } | |||
6293 | ||||
6294 | #define LIMIT_INTERVAL_RESET_SYNTAX"<backend> <realm> <resource>" "<backend> <realm> <resource>" | |||
6295 | SWITCH_STANDARD_API(limit_interval_reset_function)static switch_status_t limit_interval_reset_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
6296 | { | |||
6297 | int argc = 0; | |||
6298 | char *argv[5] = { 0 }; | |||
6299 | char *mydata = NULL((void*)0); | |||
6300 | ||||
6301 | if (!zstr(cmd)_zstr(cmd)) { | |||
6302 | mydata = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))); | |||
6303 | switch_assert(mydata)((mydata) ? (void) (0) : __assert_fail ("mydata", "mod_commands.c" , 6303, __PRETTY_FUNCTION__)); | |||
6304 | argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | |||
6305 | } | |||
6306 | ||||
6307 | if (argc < 3) { | |||
6308 | stream->write_function(stream, "USAGE: limit_interval_reset %s\n", LIMIT_INTERVAL_RESET_SYNTAX"<backend> <realm> <resource>"); | |||
6309 | goto end; | |||
6310 | } | |||
6311 | ||||
6312 | switch_limit_interval_reset(argv[0], argv[1], argv[2]); | |||
6313 | ||||
6314 | stream->write_function(stream, "+OK"); | |||
6315 | ||||
6316 | end: | |||
6317 | switch_safe_free(mydata)if (mydata) {free(mydata);mydata=((void*)0);}; | |||
6318 | ||||
6319 | return SWITCH_STATUS_SUCCESS; | |||
6320 | } | |||
6321 | ||||
6322 | SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_commands_shutdown)switch_status_t mod_commands_shutdown (void) | |||
6323 | { | |||
6324 | int x; | |||
6325 | ||||
6326 | for (x = 30; x > 0; x--) { | |||
6327 | if (switch_thread_rwlock_trywrlock(bgapi_rwlock) == SWITCH_STATUS_SUCCESS) { | |||
6328 | switch_thread_rwlock_unlock(bgapi_rwlock); | |||
6329 | break; | |||
6330 | } | |||
6331 | if (x == 30) { | |||
6332 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_commands.c", (const char *)__func__ , 6332, ((void*)0), SWITCH_LOG_DEBUG, "Waiting for bgapi threads.\n"); | |||
6333 | } | |||
6334 | switch_yield(1000000)switch_sleep(1000000);; | |||
6335 | } | |||
6336 | ||||
6337 | if (!x) { | |||
6338 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_commands.c", (const char *)__func__ , 6338, ((void*)0), SWITCH_LOG_CRIT, "Giving up waiting for bgapi threads.\n"); | |||
6339 | } | |||
6340 | ||||
6341 | return SWITCH_STATUS_SUCCESS; | |||
6342 | } | |||
6343 | ||||
6344 | #define LOG_SYNTAX"<level> <message>" "<level> <message>" | |||
6345 | SWITCH_STANDARD_API(log_function)static switch_status_t log_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
6346 | { | |||
6347 | char *level, *log_str; | |||
6348 | ||||
6349 | if (cmd && (level = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))))) { | |||
6350 | switch_log_level_t ltype = SWITCH_LOG_DEBUG; | |||
6351 | ||||
6352 | if ((log_str = strchr(level, ' ')(__extension__ (__builtin_constant_p (' ') && !__builtin_constant_p (level) && (' ') == '\0' ? (char *) __rawmemchr (level , ' ') : __builtin_strchr (level, ' '))))) { | |||
6353 | *log_str++ = '\0'; | |||
6354 | ltype = switch_log_str2level(level); | |||
6355 | } else { | |||
6356 | log_str = level; | |||
6357 | } | |||
6358 | if (ltype == SWITCH_LOG_INVALID) { | |||
6359 | ltype = SWITCH_LOG_DEBUG; | |||
6360 | } | |||
6361 | ||||
6362 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "mod_commands.c", (const char *)__func__ , 6362, (const char*)(session), ltype, "%s\n", log_str); | |||
6363 | switch_safe_free(level)if (level) {free(level);level=((void*)0);}; | |||
6364 | stream->write_function(stream, "+OK\n"); | |||
6365 | } else { | |||
6366 | stream->write_function(stream, "-ERR\n"); | |||
6367 | } | |||
6368 | ||||
6369 | return SWITCH_STATUS_SUCCESS; | |||
6370 | } | |||
6371 | ||||
6372 | SWITCH_STANDARD_API(file_exists_function)static switch_status_t file_exists_function ( const char *cmd , switch_core_session_t *session, switch_stream_handle_t *stream ) | |||
6373 | { | |||
6374 | if (!zstr(cmd)_zstr(cmd)) { | |||
6375 | switch_memory_pool_t *pool; | |||
6376 | ||||
6377 | switch_core_new_memory_pool(&pool)switch_core_perform_new_memory_pool(&pool, "mod_commands.c" , (const char *)__func__, 6377); | |||
6378 | ||||
6379 | if (switch_file_exists(cmd, pool) == SWITCH_STATUS_SUCCESS) { | |||
6380 | stream->write_function(stream, "true"); | |||
6381 | } else { | |||
6382 | stream->write_function(stream, "false"); | |||
6383 | } | |||
6384 | ||||
6385 | switch_core_destroy_memory_pool(&pool)switch_core_perform_destroy_memory_pool(&pool, "mod_commands.c" , (const char *)__func__, 6385); | |||
6386 | } else { | |||
6387 | stream->write_function(stream, "false"); | |||
6388 | } | |||
6389 | ||||
6390 | return SWITCH_STATUS_SUCCESS; | |||
6391 | } | |||
6392 | ||||
6393 | #define INTERFACE_IP_SYNTAX"[auto|ipv4|ipv6] <ifname>" "[auto|ipv4|ipv6] <ifname>" | |||
6394 | SWITCH_STANDARD_API(interface_ip_function)static switch_status_t interface_ip_function ( const char *cmd , switch_core_session_t *session, switch_stream_handle_t *stream ) | |||
6395 | { | |||
6396 | char *mydata = NULL((void*)0), *argv[3] = { 0 }; | |||
6397 | int argc = 0; | |||
6398 | char addr[INET6_ADDRSTRLEN46]; | |||
6399 | ||||
6400 | if (!zstr(cmd)_zstr(cmd)) { | |||
6401 | mydata = strdup(cmd)(__extension__ (__builtin_constant_p (cmd) && ((size_t )(const void *)((cmd) + 1) - (size_t)(const void *)(cmd) == 1 ) ? (((const char *) (cmd))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen (cmd) + 1; char * __retval = (char *) malloc (__len); if (__retval != ((void*)0 )) __retval = (char *) memcpy (__retval, cmd, __len); __retval ; })) : __strdup (cmd))); | |||
6402 | switch_assert(mydata)((mydata) ? (void) (0) : __assert_fail ("mydata", "mod_commands.c" , 6402, __PRETTY_FUNCTION__)); | |||
6403 | argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | |||
6404 | } | |||
6405 | ||||
6406 | if (argc < 2) { | |||
6407 | stream->write_function(stream, "USAGE: interface_ip %s\n", INTERFACE_IP_SYNTAX"[auto|ipv4|ipv6] <ifname>"); | |||
6408 | goto end; | |||
6409 | } | |||
6410 | ||||
6411 | if (!strcasecmp(argv[0], "ipv4")) { | |||
6412 | if (switch_find_interface_ip(addr, sizeof(addr), NULL((void*)0), argv[1], AF_INET2) == SWITCH_STATUS_SUCCESS) { | |||
6413 | stream->write_function(stream, "%s", addr); | |||
6414 | } | |||
6415 | } | |||
6416 | else if (!strcasecmp(argv[0], "ipv6")) { | |||
6417 | if (switch_find_interface_ip(addr, sizeof(addr), NULL((void*)0), argv[1], AF_INET610) == SWITCH_STATUS_SUCCESS) { | |||
6418 | stream->write_function(stream, "%s", addr); | |||
6419 | } | |||
6420 | } | |||
6421 | else if (!strcasecmp(argv[0], "auto")) { | |||
6422 | if (switch_find_interface_ip(addr, sizeof(addr), NULL((void*)0), argv[1], AF_UNSPEC0) == SWITCH_STATUS_SUCCESS) { | |||
6423 | stream->write_function(stream, "%s", addr); | |||
6424 | } | |||
6425 | } | |||
6426 | else { | |||
6427 | stream->write_function(stream, "USAGE: interface_ip %s\n", INTERFACE_IP_SYNTAX"[auto|ipv4|ipv6] <ifname>"); | |||
6428 | } | |||
6429 | ||||
6430 | end: | |||
6431 | switch_safe_free(mydata)if (mydata) {free(mydata);mydata=((void*)0);}; | |||
6432 | ||||
6433 | return SWITCH_STATUS_SUCCESS; | |||
6434 | } | |||
6435 | ||||
6436 | SWITCH_STANDARD_JSON_API(json_channel_data_function)static switch_status_t json_channel_data_function (const cJSON *json, switch_core_session_t *session, cJSON **json_reply) | |||
6437 | { | |||
6438 | cJSON *reply, *data = cJSON_GetObjectItem(json, "data"); | |||
6439 | switch_status_t status = SWITCH_STATUS_FALSE; | |||
6440 | const char *uuid = cJSON_GetObjectCstr(data, "uuid"); | |||
6441 | switch_core_session_t *tsession; | |||
6442 | ||||
6443 | ||||
6444 | reply = cJSON_CreateObject(); | |||
6445 | *json_reply = reply; | |||
6446 | ||||
6447 | if (zstr(uuid)_zstr(uuid)) { | |||
6448 | cJSON_AddItemToObject(reply, "response", cJSON_CreateString("INVALID INPUT")); | |||
6449 | goto end; | |||
6450 | } | |||
6451 | ||||
6452 | ||||
6453 | if ((tsession = switch_core_session_locate(uuid)switch_core_session_perform_locate(uuid, "mod_commands.c", (const char *)__func__, 6453))) { | |||
6454 | cJSON *jevent; | |||
6455 | ||||
6456 | if (switch_ivr_generate_json_cdr(tsession, &jevent, SWITCH_FALSE) == SWITCH_STATUS_SUCCESS) { | |||
6457 | cJSON_AddItemToObject(reply, "channelData", jevent); | |||
6458 | } | |||
6459 | ||||
6460 | switch_core_session_rwunlock(tsession); | |||
6461 | ||||
6462 | status = SWITCH_STATUS_SUCCESS; | |||
6463 | } else { | |||
6464 | cJSON_AddItemToObject(reply, "response", cJSON_CreateString("Session does not exist")); | |||
6465 | goto end; | |||
6466 | } | |||
6467 | ||||
6468 | end: | |||
6469 | ||||
6470 | return status; | |||
6471 | } | |||
6472 | ||||
6473 | SWITCH_STANDARD_JSON_API(json_execute_function)static switch_status_t json_execute_function (const cJSON *json , switch_core_session_t *session, cJSON **json_reply) | |||
6474 | { | |||
6475 | cJSON *reply, *data = cJSON_GetObjectItem(json, "data"); | |||
6476 | switch_status_t status = SWITCH_STATUS_FALSE; | |||
6477 | const char *uuid = cJSON_GetObjectCstr(data, "uuid"); | |||
6478 | const char *app = cJSON_GetObjectCstr(data, "app"); | |||
6479 | const char *arg = cJSON_GetObjectCstr(data, "arg"); | |||
6480 | const char *einline = cJSON_GetObjectCstr(data, "inline"); | |||
6481 | const char *edata = cJSON_GetObjectCstr(data, "extendedData"); | |||
6482 | switch_core_session_t *tsession; | |||
6483 | ||||
6484 | ||||
6485 | reply = cJSON_CreateObject(); | |||
6486 | *json_reply = reply; | |||
6487 | ||||
6488 | if (!(uuid && app)) { | |||
6489 | cJSON_AddItemToObject(reply, "response", cJSON_CreateString("INVALID INPUT")); | |||
6490 | goto end; | |||
6491 | } | |||
6492 | ||||
6493 | ||||
6494 | if ((tsession = switch_core_session_locate(uuid)switch_core_session_perform_locate(uuid, "mod_commands.c", (const char *)__func__, 6494))) { | |||
6495 | if (switch_true(edata)) { | |||
6496 | cJSON *jevent = NULL((void*)0); | |||
6497 | ||||
6498 | if (switch_ivr_generate_json_cdr(tsession, &jevent, SWITCH_FALSE) == SWITCH_STATUS_SUCCESS) { | |||
6499 | cJSON_AddItemToObject(reply, "channelData", jevent); | |||
6500 | } | |||
6501 | } else { | |||
6502 | cJSON_AddItemToObject(reply, "channelName", cJSON_CreateString(switch_core_session_get_name(tsession)switch_channel_get_name(switch_core_session_get_channel(tsession )))); | |||
6503 | } | |||
6504 | ||||
6505 | if (switch_true(einline)) { | |||
6506 | switch_core_session_execute_application(tsession, app, arg)switch_core_session_execute_application_get_flags(tsession, app , arg, ((void*)0)); | |||
6507 | } else { | |||
6508 | switch_core_session_execute_application_async(tsession, app, arg); | |||
6509 | } | |||
6510 | status = SWITCH_STATUS_SUCCESS; | |||
6511 | ||||
6512 | switch_core_session_rwunlock(tsession); | |||
6513 | ||||
6514 | } else { | |||
6515 | cJSON_AddItemToObject(reply, "response", cJSON_CreateString("Session does not exist")); | |||
6516 | goto end; | |||
6517 | } | |||
6518 | ||||
6519 | ||||
6520 | end: | |||
6521 | ||||
6522 | return status; | |||
6523 | } | |||
6524 | ||||
6525 | SWITCH_STANDARD_JSON_API(json_api_function)static switch_status_t json_api_function (const cJSON *json, switch_core_session_t *session, cJSON **json_reply) | |||
6526 | { | |||
6527 | cJSON *data, *cmd, *arg, *reply; | |||
6528 | switch_stream_handle_t stream = { 0 }; | |||
6529 | switch_status_t status = SWITCH_STATUS_SUCCESS; | |||
6530 | ||||
6531 | data = cJSON_GetObjectItem(json, "data"); | |||
6532 | ||||
6533 | cmd = cJSON_GetObjectItem(data, "cmd"); | |||
6534 | arg = cJSON_GetObjectItem(data, "arg"); | |||
6535 | ||||
6536 | if (cmd && !cmd->valuestring) { | |||
6537 | cmd = NULL((void*)0); | |||
6538 | } | |||
6539 | ||||
6540 | if (arg && !arg->valuestring) { | |||
6541 | arg = NULL((void*)0); | |||
6542 | } | |||
6543 | ||||
6544 | reply = cJSON_CreateObject(); | |||
6545 | ||||
6546 | SWITCH_STANDARD_STREAM(stream)memset(&stream, 0, sizeof(stream)); stream.data = malloc( 1024); ((stream.data) ? (void) (0) : __assert_fail ("stream.data" , "mod_commands.c", 6546, __PRETTY_FUNCTION__)); memset(stream .data, 0, 1024); stream.end = stream.data; stream.data_size = 1024; stream.write_function = switch_console_stream_write; stream .raw_write_function = switch_console_stream_raw_write; stream .alloc_len = 1024; stream.alloc_chunk = 1024; | |||
6547 | ||||
6548 | if (cmd && (status = switch_api_execute(cmd->valuestring, arg ? arg->valuestring : NULL((void*)0), session, &stream)) == SWITCH_STATUS_SUCCESS) { | |||
6549 | cJSON_AddItemToObject(reply, "message", cJSON_CreateString((char *) stream.data)); | |||
6550 | } else { | |||
6551 | cJSON_AddItemToObject(reply, "message", cJSON_CreateString("INVALID CALL")); | |||
6552 | } | |||
6553 | ||||
6554 | switch_safe_free(stream.data)if (stream.data) {free(stream.data);stream.data=((void*)0);}; | |||
6555 | ||||
6556 | *json_reply = reply; | |||
6557 | ||||
6558 | return status; | |||
6559 | ||||
6560 | } | |||
6561 | ||||
6562 | ||||
6563 | SWITCH_STANDARD_JSON_API(json_status_function)static switch_status_t json_status_function (const cJSON *json , switch_core_session_t *session, cJSON **json_reply) | |||
6564 | { | |||
6565 | cJSON *o, *oo, *reply = cJSON_CreateObject(); | |||
6566 | switch_core_time_duration_t duration = { 0 }; | |||
6567 | int sps = 0, last_sps = 0, max_sps = 0, max_sps_fivemin = 0; | |||
6568 | int sessions_peak = 0, sessions_peak_fivemin = 0; /* Max Concurrent Sessions buffers */ | |||
6569 | switch_size_t cur = 0, max = 0; | |||
6570 | ||||
6571 | switch_core_measure_time(switch_core_uptime(), &duration); | |||
6572 | ||||
6573 | switch_core_session_ctl(SCSC_SESSIONS_PEAK, &sessions_peak); | |||
6574 | switch_core_session_ctl(SCSC_SESSIONS_PEAK_FIVEMIN, &sessions_peak_fivemin); | |||
6575 | switch_core_session_ctl(SCSC_LAST_SPS, &last_sps); | |||
6576 | switch_core_session_ctl(SCSC_SPS, &sps); | |||
6577 | switch_core_session_ctl(SCSC_SPS_PEAK, &max_sps); | |||
6578 | switch_core_session_ctl(SCSC_SPS_PEAK_FIVEMIN, &max_sps_fivemin); | |||
6579 | ||||
6580 | cJSON_AddItemToObject(reply, "systemStatus", cJSON_CreateString(switch_core_ready() ? "ready" : "not ready")); | |||
6581 | ||||
6582 | o = cJSON_CreateObject(); | |||
6583 | cJSON_AddItemToObject(o, "years", cJSON_CreateNumber(duration.yr)); | |||
6584 | cJSON_AddItemToObject(o, "days", cJSON_CreateNumber(duration.day)); | |||
6585 | cJSON_AddItemToObject(o, "hours", cJSON_CreateNumber(duration.hr)); | |||
6586 | cJSON_AddItemToObject(o, "minutes", cJSON_CreateNumber(duration.min)); | |||
6587 | cJSON_AddItemToObject(o, "seconds", cJSON_CreateNumber(duration.sec)); | |||
6588 | cJSON_AddItemToObject(o, "milliseconds", cJSON_CreateNumber(duration.ms)); | |||
6589 | cJSON_AddItemToObject(o, "microseconds", cJSON_CreateNumber(duration.mms)); | |||
6590 | ||||
6591 | cJSON_AddItemToObject(reply, "uptime", o); | |||
6592 | cJSON_AddItemToObject(reply, "version", cJSON_CreateString(switch_version_full_human())); | |||
6593 | ||||
6594 | o = cJSON_CreateObject(); | |||
6595 | cJSON_AddItemToObject(reply, "sessions", o); | |||
6596 | ||||
6597 | oo = cJSON_CreateObject(); | |||
6598 | cJSON_AddItemToObject(o, "count", oo); | |||
6599 | ||||
6600 | cJSON_AddItemToObject(oo, "total", cJSON_CreateNumber((double)(switch_core_session_id() - 1))); | |||
6601 | cJSON_AddItemToObject(oo, "active", cJSON_CreateNumber(switch_core_session_count())); | |||
6602 | cJSON_AddItemToObject(oo, "peak", cJSON_CreateNumber(sessions_peak)); | |||
6603 | cJSON_AddItemToObject(oo, "peak5Min", cJSON_CreateNumber(sessions_peak_fivemin)); | |||
6604 | cJSON_AddItemToObject(oo, "limit", cJSON_CreateNumber(switch_core_session_limit(0))); | |||
6605 | ||||
6606 | ||||
6607 | ||||
6608 | oo = cJSON_CreateObject(); | |||
6609 | cJSON_AddItemToObject(o, "rate", oo); | |||
6610 | cJSON_AddItemToObject(oo, "current", cJSON_CreateNumber(last_sps)); | |||
6611 | cJSON_AddItemToObject(oo, "max", cJSON_CreateNumber(sps)); | |||
6612 | cJSON_AddItemToObject(oo, "peak", cJSON_CreateNumber(max_sps)); | |||
6613 | cJSON_AddItemToObject(oo, "peak5Min", cJSON_CreateNumber(max_sps_fivemin)); | |||
6614 | ||||
6615 | ||||
6616 | o = cJSON_CreateObject(); | |||
6617 | cJSON_AddItemToObject(reply, "idleCPU", o); | |||
6618 | ||||
6619 | cJSON_AddItemToObject(o, "used", cJSON_CreateNumber(switch_core_min_idle_cpu(-1.0))); | |||
6620 | cJSON_AddItemToObject(o, "allowed", cJSON_CreateNumber(switch_core_idle_cpu())); | |||
6621 | ||||
6622 | ||||
6623 | if (switch_core_get_stacksizes(&cur, &max) == SWITCH_STATUS_SUCCESS) { | |||
6624 | o = cJSON_CreateObject(); | |||
6625 | cJSON_AddItemToObject(reply, "stackSizeKB", o); | |||
6626 | ||||
6627 | cJSON_AddItemToObject(o, "current", cJSON_CreateNumber((double)(cur / 1024))); | |||
6628 | cJSON_AddItemToObject(o, "max", cJSON_CreateNumber((double)(max / 1024))); | |||
6629 | } | |||
6630 | ||||
6631 | ||||
6632 | *json_reply = reply; | |||
6633 | ||||
6634 | return SWITCH_STATUS_SUCCESS; | |||
6635 | } | |||
6636 | ||||
6637 | SWITCH_STANDARD_API(json_function)static switch_status_t json_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | |||
6638 | { | |||
6639 | cJSON *jcmd = NULL((void*)0), *format = NULL((void*)0); | |||
6640 | const char *message = ""; | |||
6641 | char *response = NULL((void*)0); | |||
6642 | ||||
6643 | if (zstr(cmd)_zstr(cmd)) { | |||
6644 | message = "No JSON supplied."; | |||
6645 | goto err; | |||
6646 | } | |||
6647 | ||||
6648 | jcmd = cJSON_Parse(cmd); | |||
6649 | ||||
6650 | if (!jcmd) { | |||
6651 | message = "Parse error."; | |||
6652 | goto err; | |||
6653 | } | |||
6654 | ||||
6655 | format = cJSON_GetObjectItem(jcmd, "format"); | |||
6656 | ||||
6657 | switch_json_api_execute(jcmd, session, NULL((void*)0)); | |||
6658 | ||||
6659 | ||||
6660 | if (format && format->valuestring && !strcasecmp(format->valuestring, "pretty")) { | |||
6661 | response = cJSON_Print(jcmd); | |||
6662 | } else { | |||
6663 | response = cJSON_PrintUnformatted(jcmd); | |||
6664 | } | |||
6665 | ||||
6666 | stream->write_function(stream, "%s\n", switch_str_nil(response)(response ? response : "")); | |||
6667 | ||||
6668 | switch_safe_free(response)if (response) {free(response);response=((void*)0);}; | |||
6669 | ||||
6670 | cJSON_Delete(jcmd); | |||
6671 | ||||
6672 | return SWITCH_STATUS_SUCCESS; | |||
6673 | ||||
6674 | err: | |||
6675 | ||||
6676 | stream->write_function(stream, "-ERR %s\n", message); | |||
6677 | ||||
6678 | ||||
6679 | return SWITCH_STATUS_SUCCESS; | |||
6680 | } | |||
6681 | ||||
6682 | SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)switch_status_t mod_commands_load (switch_loadable_module_interface_t **module_interface, switch_memory_pool_t *pool) | |||
6683 | { | |||
6684 | switch_api_interface_t *commands_api_interface; | |||
6685 | switch_json_api_interface_t *json_api_interface; | |||
6686 | int use_system_commands = 1; | |||
6687 | ||||
6688 | if (switch_true(switch_core_get_variable("disable_system_api_commands"))) { | |||
6689 | use_system_commands = 0; | |||
6690 | } | |||
6691 | ||||
6692 | *module_interface = switch_loadable_module_create_module_interface(pool, modname); | |||
6693 | ||||
6694 | switch_thread_rwlock_create(&bgapi_rwlock, pool); | |||
6695 | switch_mutex_init(&reload_mutex, SWITCH_MUTEX_NESTED0x1, pool); | |||
6696 | ||||
6697 | if (use_system_commands) { | |||
6698 | SWITCH_ADD_API(commands_api_interface, "bg_system", "Execute a system command in the background", bg_system_function, SYSTEM_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "bg_system"; commands_api_interface ->desc = "Execute a system command in the background"; commands_api_interface ->function = bg_system_function; commands_api_interface-> syntax = "<command>"; break; }; | |||
6699 | SWITCH_ADD_API(commands_api_interface, "system", "Execute a system command", system_function, SYSTEM_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "system"; commands_api_interface ->desc = "Execute a system command"; commands_api_interface ->function = system_function; commands_api_interface->syntax = "<command>"; break; }; | |||
6700 | } | |||
6701 | ||||
6702 | SWITCH_ADD_API(commands_api_interface, "acl", "Compare an ip to an acl list", acl_function, "<ip> <list_name>")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "acl"; commands_api_interface ->desc = "Compare an ip to an acl list"; commands_api_interface ->function = acl_function; commands_api_interface->syntax = "<ip> <list_name>"; break; }; | |||
6703 | SWITCH_ADD_API(commands_api_interface, "alias", "Alias", alias_function, ALIAS_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "alias"; commands_api_interface ->desc = "Alias"; commands_api_interface->function = alias_function ; commands_api_interface->syntax = "[add|stickyadd] <alias> <command> | del [<alias>|*]" ; break; }; SWITCH_ADD_API(commands_api_interface, "coalesce", "Return first nonempty parameter", coalesce_function, COALESCE_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "coalesce"; commands_api_interface ->desc = "Return first nonempty parameter"; commands_api_interface ->function = coalesce_function; commands_api_interface-> syntax = "[^^<delim>]<value1>,<value2>,..." ; break; }; | |||
6704 | SWITCH_ADD_API(commands_api_interface, "banner", "Return the system banner", banner_function, "")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "banner"; commands_api_interface ->desc = "Return the system banner"; commands_api_interface ->function = banner_function; commands_api_interface->syntax = ""; break; }; | |||
6705 | SWITCH_ADD_API(commands_api_interface, "bgapi", "Execute an api command in a thread", bgapi_function, "<command>[ <arg>]")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "bgapi"; commands_api_interface ->desc = "Execute an api command in a thread"; commands_api_interface ->function = bgapi_function; commands_api_interface->syntax = "<command>[ <arg>]"; break; }; | |||
6706 | SWITCH_ADD_API(commands_api_interface, "break", "uuid_break", break_function, BREAK_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "break"; commands_api_interface ->desc = "uuid_break"; commands_api_interface->function = break_function; commands_api_interface->syntax = "<uuid> [all]" ; break; }; | |||
6707 | SWITCH_ADD_API(commands_api_interface, "complete", "Complete", complete_function, COMPLETE_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "complete"; commands_api_interface ->desc = "Complete"; commands_api_interface->function = complete_function; commands_api_interface->syntax = "add <word>|del [<word>|*]" ; break; }; | |||
6708 | SWITCH_ADD_API(commands_api_interface, "cond", "Evaluate a conditional", cond_function, "<expr> ? <true val> : <false val>")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "cond"; commands_api_interface ->desc = "Evaluate a conditional"; commands_api_interface-> function = cond_function; commands_api_interface->syntax = "<expr> ? <true val> : <false val>"; break ; }; | |||
6709 | SWITCH_ADD_API(commands_api_interface, "console_complete", "", console_complete_function, "<line>")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "console_complete" ; commands_api_interface->desc = ""; commands_api_interface ->function = console_complete_function; commands_api_interface ->syntax = "<line>"; break; }; | |||
6710 | SWITCH_ADD_API(commands_api_interface, "console_complete_xml", "", console_complete_xml_function, "<line>")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "console_complete_xml" ; commands_api_interface->desc = ""; commands_api_interface ->function = console_complete_xml_function; commands_api_interface ->syntax = "<line>"; break; }; | |||
6711 | SWITCH_ADD_API(commands_api_interface, "create_uuid", "Create a uuid", uuid_function, UUID_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "create_uuid"; commands_api_interface->desc = "Create a uuid"; commands_api_interface ->function = uuid_function; commands_api_interface->syntax = "<uuid> <other_uuid>"; break; }; | |||
6712 | SWITCH_ADD_API(commands_api_interface, "db_cache", "Manage db cache", db_cache_function, "status")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "db_cache"; commands_api_interface ->desc = "Manage db cache"; commands_api_interface->function = db_cache_function; commands_api_interface->syntax = "status" ; break; }; | |||
6713 | SWITCH_ADD_API(commands_api_interface, "domain_exists", "Check if a domain exists", domain_exists_function, "<domain>")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "domain_exists" ; commands_api_interface->desc = "Check if a domain exists" ; commands_api_interface->function = domain_exists_function ; commands_api_interface->syntax = "<domain>"; break ; }; | |||
6714 | SWITCH_ADD_API(commands_api_interface, "echo", "Echo", echo_function, "<data>")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "echo"; commands_api_interface ->desc = "Echo"; commands_api_interface->function = echo_function ; commands_api_interface->syntax = "<data>"; break; }; | |||
6715 | SWITCH_ADD_API(commands_api_interface, "escape", "Escape a string", escape_function, "<data>")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "escape"; commands_api_interface ->desc = "Escape a string"; commands_api_interface->function = escape_function; commands_api_interface->syntax = "<data>" ; break; }; | |||
6716 | SWITCH_ADD_API(commands_api_interface, "eval", "eval (noop)", eval_function, "[uuid:<uuid> ]<expression>")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "eval"; commands_api_interface ->desc = "eval (noop)"; commands_api_interface->function = eval_function; commands_api_interface->syntax = "[uuid:<uuid> ]<expression>" ; break; }; | |||
6717 | SWITCH_ADD_API(commands_api_interface, "expand", "Execute an api with variable expansion", expand_function, "[uuid:<uuid> ]<cmd> <args>")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "expand"; commands_api_interface ->desc = "Execute an api with variable expansion"; commands_api_interface ->function = expand_function; commands_api_interface->syntax = "[uuid:<uuid> ]<cmd> <args>"; break; }; | |||
6718 | SWITCH_ADD_API(commands_api_interface, "find_user_xml", "Find a user", find_user_function, "<key> <user> <domain>")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "find_user_xml" ; commands_api_interface->desc = "Find a user"; commands_api_interface ->function = find_user_function; commands_api_interface-> syntax = "<key> <user> <domain>"; break; }; | |||
6719 | SWITCH_ADD_API(commands_api_interface, "fsctl", "FS control messages", ctl_function, CTL_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "fsctl"; commands_api_interface ->desc = "FS control messages"; commands_api_interface-> function = ctl_function; commands_api_interface->syntax = "[recover|send_sighup|hupall|pause [inbound|outbound]|resume [inbound|outbound]|shutdown [cancel|elegant|asap|now|restart]|sps|sps_peak_reset|sync_clock|sync_clock_when_idle|reclaim_mem|max_sessions|min_dtmf_duration [num]|max_dtmf_duration [num]|default_dtmf_duration [num]|min_idle_cpu|loglevel [level]|debug_level [level]]" ; break; }; | |||
6720 | SWITCH_ADD_API(commands_api_interface, "...", "Shutdown", shutdown_function, "")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "..."; commands_api_interface ->desc = "Shutdown"; commands_api_interface->function = shutdown_function; commands_api_interface->syntax = ""; break ; }; | |||
6721 | SWITCH_ADD_API(commands_api_interface, "shutdown", "Shutdown", shutdown_function, "")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "shutdown"; commands_api_interface ->desc = "Shutdown"; commands_api_interface->function = shutdown_function; commands_api_interface->syntax = ""; break ; }; | |||
6722 | SWITCH_ADD_API(commands_api_interface, "version", "Version", version_function, "[short]")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "version"; commands_api_interface ->desc = "Version"; commands_api_interface->function = version_function ; commands_api_interface->syntax = "[short]"; break; }; | |||
6723 | SWITCH_ADD_API(commands_api_interface, "global_getvar", "Get global var", global_getvar_function, GLOBAL_GETVAR_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "global_getvar" ; commands_api_interface->desc = "Get global var"; commands_api_interface ->function = global_getvar_function; commands_api_interface ->syntax = "<var>"; break; }; | |||
6724 | SWITCH_ADD_API(commands_api_interface, "global_setvar", "Set global var", global_setvar_function, GLOBAL_SETVAR_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "global_setvar" ; commands_api_interface->desc = "Set global var"; commands_api_interface ->function = global_setvar_function; commands_api_interface ->syntax = "<var>=<value> [=<value2>]"; break ; }; | |||
6725 | SWITCH_ADD_API(commands_api_interface, "group_call", "Generate a dial string to call a group", group_call_function, "<group>[@<domain>]")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "group_call"; commands_api_interface ->desc = "Generate a dial string to call a group"; commands_api_interface ->function = group_call_function; commands_api_interface-> syntax = "<group>[@<domain>]"; break; }; | |||
6726 | SWITCH_ADD_API(commands_api_interface, "help", "Show help for all the api commands", help_function, "")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "help"; commands_api_interface ->desc = "Show help for all the api commands"; commands_api_interface ->function = help_function; commands_api_interface->syntax = ""; break; }; | |||
6727 | SWITCH_ADD_API(commands_api_interface, "host_lookup", "Lookup host", host_lookup_function, "<hostname>")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "host_lookup"; commands_api_interface->desc = "Lookup host"; commands_api_interface ->function = host_lookup_function; commands_api_interface-> syntax = "<hostname>"; break; }; | |||
6728 | SWITCH_ADD_API(commands_api_interface, "hostname", "Return the system hostname", hostname_api_function, "")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "hostname"; commands_api_interface ->desc = "Return the system hostname"; commands_api_interface ->function = hostname_api_function; commands_api_interface ->syntax = ""; break; }; | |||
6729 | SWITCH_ADD_API(commands_api_interface, "interface_ip", "Return the primary IP of an interface", interface_ip_function, INTERFACE_IP_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "interface_ip" ; commands_api_interface->desc = "Return the primary IP of an interface" ; commands_api_interface->function = interface_ip_function ; commands_api_interface->syntax = "[auto|ipv4|ipv6] <ifname>" ; break; }; | |||
6730 | SWITCH_ADD_API(commands_api_interface, "switchname", "Return the switch name", switchname_api_function, "")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "switchname"; commands_api_interface ->desc = "Return the switch name"; commands_api_interface-> function = switchname_api_function; commands_api_interface-> syntax = ""; break; }; | |||
6731 | SWITCH_ADD_API(commands_api_interface, "gethost", "gethostbyname", gethost_api_function, "")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "gethost"; commands_api_interface ->desc = "gethostbyname"; commands_api_interface->function = gethost_api_function; commands_api_interface->syntax = "" ; break; }; | |||
6732 | SWITCH_ADD_API(commands_api_interface, "hupall", "hupall", hupall_api_function, "<cause> [<var> <value>]")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "hupall"; commands_api_interface ->desc = "hupall"; commands_api_interface->function = hupall_api_function ; commands_api_interface->syntax = "<cause> [<var> <value>]" ; break; }; | |||
6733 | SWITCH_ADD_API(commands_api_interface, "in_group", "Determine if a user is in a group", in_group_function, "<user>[@<domain>] <group_name>")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "in_group"; commands_api_interface ->desc = "Determine if a user is in a group"; commands_api_interface ->function = in_group_function; commands_api_interface-> syntax = "<user>[@<domain>] <group_name>"; break ; }; | |||
6734 | SWITCH_ADD_API(commands_api_interface, "is_lan_addr", "See if an ip is a lan addr", lan_addr_function, "<ip>")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "is_lan_addr"; commands_api_interface->desc = "See if an ip is a lan addr" ; commands_api_interface->function = lan_addr_function; commands_api_interface ->syntax = "<ip>"; break; }; | |||
6735 | SWITCH_ADD_API(commands_api_interface, "limit_usage", "Get the usage count of a limited resource", limit_usage_function, "<backend> <realm> <id>")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "limit_usage"; commands_api_interface->desc = "Get the usage count of a limited resource" ; commands_api_interface->function = limit_usage_function; commands_api_interface->syntax = "<backend> <realm> <id>" ; break; }; | |||
6736 | SWITCH_ADD_API(commands_api_interface, "limit_hash_usage", "Deprecated: gets the usage count of a limited resource", limit_hash_usage_function, "<realm> <id>")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "limit_hash_usage" ; commands_api_interface->desc = "Deprecated: gets the usage count of a limited resource" ; commands_api_interface->function = limit_hash_usage_function ; commands_api_interface->syntax = "<realm> <id>" ; break; }; | |||
6737 | SWITCH_ADD_API(commands_api_interface, "limit_status", "Get the status of a limit backend", limit_status_function, "<backend>")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "limit_status" ; commands_api_interface->desc = "Get the status of a limit backend" ; commands_api_interface->function = limit_status_function ; commands_api_interface->syntax = "<backend>"; break ; }; | |||
6738 | SWITCH_ADD_API(commands_api_interface, "limit_reset", "Reset the counters of a limit backend", limit_reset_function, "<backend>")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "limit_reset"; commands_api_interface->desc = "Reset the counters of a limit backend" ; commands_api_interface->function = limit_reset_function; commands_api_interface->syntax = "<backend>"; break ; }; | |||
6739 | SWITCH_ADD_API(commands_api_interface, "limit_interval_reset", "Reset the interval counter for a limited resource", limit_interval_reset_function, LIMIT_INTERVAL_RESET_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "limit_interval_reset" ; commands_api_interface->desc = "Reset the interval counter for a limited resource" ; commands_api_interface->function = limit_interval_reset_function ; commands_api_interface->syntax = "<backend> <realm> <resource>" ; break; }; | |||
6740 | SWITCH_ADD_API(commands_api_interface, "list_users", "List Users configured in Directory", list_users_function, LIST_USERS_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "list_users"; commands_api_interface ->desc = "List Users configured in Directory"; commands_api_interface ->function = list_users_function; commands_api_interface-> syntax = "[group <group>] [domain <domain>] [user <user>] [context <context>]" ; break; }; | |||
6741 | SWITCH_ADD_API(commands_api_interface, "load", "Load Module", load_function, LOAD_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "load"; commands_api_interface ->desc = "Load Module"; commands_api_interface->function = load_function; commands_api_interface->syntax = "<mod_name>" ; break; }; | |||
6742 | SWITCH_ADD_API(commands_api_interface, "log", "Log", log_function, LOG_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "log"; commands_api_interface ->desc = "Log"; commands_api_interface->function = log_function ; commands_api_interface->syntax = "<level> <message>" ; break; }; | |||
6743 | SWITCH_ADD_API(commands_api_interface, "md5", "Return md5 hash", md5_function, "<data>")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "md5"; commands_api_interface ->desc = "Return md5 hash"; commands_api_interface->function = md5_function; commands_api_interface->syntax = "<data>" ; break; }; | |||
6744 | SWITCH_ADD_API(commands_api_interface, "module_exists", "Check if module exists", module_exists_function, "<module>")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "module_exists" ; commands_api_interface->desc = "Check if module exists"; commands_api_interface->function = module_exists_function ; commands_api_interface->syntax = "<module>"; break ; }; | |||
6745 | SWITCH_ADD_API(commands_api_interface, "msleep", "Sleep N milliseconds", msleep_function, "<milliseconds>")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "msleep"; commands_api_interface ->desc = "Sleep N milliseconds"; commands_api_interface-> function = msleep_function; commands_api_interface->syntax = "<milliseconds>"; break; }; | |||
6746 | SWITCH_ADD_API(commands_api_interface, "nat_map", "Manage NAT", nat_map_function, "[status|republish|reinit] | [add|del] <port> [tcp|udp] [static]")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "nat_map"; commands_api_interface ->desc = "Manage NAT"; commands_api_interface->function = nat_map_function; commands_api_interface->syntax = "[status|republish|reinit] | [add|del] <port> [tcp|udp] [static]" ; break; }; | |||
6747 | SWITCH_ADD_API(commands_api_interface, "originate", "Originate a call", originate_function, ORIGINATE_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "originate"; commands_api_interface ->desc = "Originate a call"; commands_api_interface->function = originate_function; commands_api_interface->syntax = "<call url> <exten>|&<application_name>(<app_args>) [<dialplan>] [<context>] [<cid_name>] [<cid_num>] [<timeout_sec>]" ; break; }; | |||
6748 | SWITCH_ADD_API(commands_api_interface, "pause", "Pause media on a channel", pause_function, PAUSE_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "pause"; commands_api_interface ->desc = "Pause media on a channel"; commands_api_interface ->function = pause_function; commands_api_interface->syntax = "<uuid> <on|off>"; break; }; | |||
6749 | SWITCH_ADD_API(commands_api_interface, "quote_shell_arg", "Quote/escape a string for use on shell command line", quote_shell_arg_function, "<data>")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "quote_shell_arg" ; commands_api_interface->desc = "Quote/escape a string for use on shell command line" ; commands_api_interface->function = quote_shell_arg_function ; commands_api_interface->syntax = "<data>"; break; }; | |||
6750 | SWITCH_ADD_API(commands_api_interface, "regex", "Evaluate a regex", regex_function, "<data>|<pattern>[|<subst string>][n|b]")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "regex"; commands_api_interface ->desc = "Evaluate a regex"; commands_api_interface->function = regex_function; commands_api_interface->syntax = "<data>|<pattern>[|<subst string>][n|b]" ; break; }; | |||
6751 | SWITCH_ADD_API(commands_api_interface, "reloadacl", "Reload XML", reload_acl_function, "")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "reloadacl"; commands_api_interface ->desc = "Reload XML"; commands_api_interface->function = reload_acl_function; commands_api_interface->syntax = "" ; break; }; | |||
6752 | SWITCH_ADD_API(commands_api_interface, "reload", "Reload module", reload_function, UNLOAD_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "reload"; commands_api_interface ->desc = "Reload module"; commands_api_interface->function = reload_function; commands_api_interface->syntax = "[-f] <mod_name>" ; break; }; | |||
6753 | SWITCH_ADD_API(commands_api_interface, "reloadxml", "Reload XML", reload_xml_function, "")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "reloadxml"; commands_api_interface ->desc = "Reload XML"; commands_api_interface->function = reload_xml_function; commands_api_interface->syntax = "" ; break; }; | |||
6754 | SWITCH_ADD_API(commands_api_interface, "replace", "Replace a string", replace_function, "<data>|<string1>|<string2>")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "replace"; commands_api_interface ->desc = "Replace a string"; commands_api_interface->function = replace_function; commands_api_interface->syntax = "<data>|<string1>|<string2>" ; break; }; | |||
6755 | SWITCH_ADD_API(commands_api_interface, "say_string", "", say_string_function, SAY_STRING_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "say_string"; commands_api_interface ->desc = ""; commands_api_interface->function = say_string_function ; commands_api_interface->syntax = "<module_name>[.<ext>] <lang>[.<ext>] <say_type> <say_method> [<say_gender>] <text>" ; break; }; | |||
6756 | SWITCH_ADD_API(commands_api_interface, "sched_api", "Schedule an api command", sched_api_function, SCHED_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "sched_api"; commands_api_interface ->desc = "Schedule an api command"; commands_api_interface ->function = sched_api_function; commands_api_interface-> syntax = "[+@]<time> <group_name> <command_string>[&]" ; break; }; | |||
6757 | SWITCH_ADD_API(commands_api_interface, "sched_broadcast", "Schedule a broadcast event to a running call", sched_broadcast_function, SCHED_BROADCAST_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "sched_broadcast" ; commands_api_interface->desc = "Schedule a broadcast event to a running call" ; commands_api_interface->function = sched_broadcast_function ; commands_api_interface->syntax = "[[+]<time>|@time] <uuid> <path> [aleg|bleg|both]" ; break; }; | |||
6758 | SWITCH_ADD_API(commands_api_interface, "sched_del", "Delete a scheduled task", sched_del_function, "<task_id>|<group_id>")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "sched_del"; commands_api_interface ->desc = "Delete a scheduled task"; commands_api_interface ->function = sched_del_function; commands_api_interface-> syntax = "<task_id>|<group_id>"; break; }; | |||
6759 | SWITCH_ADD_API(commands_api_interface, "sched_hangup", "Schedule a running call to hangup", sched_hangup_function, SCHED_HANGUP_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "sched_hangup" ; commands_api_interface->desc = "Schedule a running call to hangup" ; commands_api_interface->function = sched_hangup_function ; commands_api_interface->syntax = "[+]<time> <uuid> [<cause>]" ; break; }; | |||
6760 | SWITCH_ADD_API(commands_api_interface, "sched_transfer", "Schedule a transfer for a running call", sched_transfer_function, SCHED_TRANSFER_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "sched_transfer" ; commands_api_interface->desc = "Schedule a transfer for a running call" ; commands_api_interface->function = sched_transfer_function ; commands_api_interface->syntax = "[+]<time> <uuid> <extension> [<dialplan>] [<context>]" ; break; }; | |||
6761 | SWITCH_ADD_API(commands_api_interface, "show", "Show various reports", show_function, SHOW_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "show"; commands_api_interface ->desc = "Show various reports"; commands_api_interface-> function = show_function; commands_api_interface->syntax = "codec|endpoint|application|api|dialplan|file|timer|calls [count]|channels [count|like <match string>]|calls|detailed_calls|bridged_calls|detailed_bridged_calls|aliases|complete|chat|management|modules|nat_map|say|interfaces|interface_types|tasks|limits|status" ; break; }; | |||
6762 | SWITCH_ADD_API(commands_api_interface, "sql_escape", "Escape a string to prevent sql injection", sql_escape, SQL_ESCAPE_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "sql_escape"; commands_api_interface ->desc = "Escape a string to prevent sql injection"; commands_api_interface ->function = sql_escape; commands_api_interface->syntax = "<string>"; break; }; | |||
6763 | SWITCH_ADD_API(commands_api_interface, "status", "Show current status", status_function, "")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "status"; commands_api_interface ->desc = "Show current status"; commands_api_interface-> function = status_function; commands_api_interface->syntax = ""; break; }; | |||
6764 | SWITCH_ADD_API(commands_api_interface, "strftime_tz", "Display formatted time of timezone", strftime_tz_api_function, "<timezone_name> [<epoch>|][format string]")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "strftime_tz"; commands_api_interface->desc = "Display formatted time of timezone" ; commands_api_interface->function = strftime_tz_api_function ; commands_api_interface->syntax = "<timezone_name> [<epoch>|][format string]" ; break; }; | |||
6765 | SWITCH_ADD_API(commands_api_interface, "stun", "Execute STUN lookup", stun_function, "<stun_server>[:port] [<source_ip>[:<source_port]]")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "stun"; commands_api_interface ->desc = "Execute STUN lookup"; commands_api_interface-> function = stun_function; commands_api_interface->syntax = "<stun_server>[:port] [<source_ip>[:<source_port]]" ; break; }; | |||
6766 | SWITCH_ADD_API(commands_api_interface, "time_test", "Show time jitter", time_test_function, "<mss> [count]")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "time_test"; commands_api_interface ->desc = "Show time jitter"; commands_api_interface->function = time_test_function; commands_api_interface->syntax = "<mss> [count]" ; break; }; | |||
6767 | SWITCH_ADD_API(commands_api_interface, "timer_test", "Exercise FS timer", timer_test_function, TIMER_TEST_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "timer_test"; commands_api_interface ->desc = "Exercise FS timer"; commands_api_interface->function = timer_test_function; commands_api_interface->syntax = "<10|20|40|60|120> [<1..200>] [<timer_name>]" ; break; }; | |||
6768 | SWITCH_ADD_API(commands_api_interface, "tone_detect", "Start tone detection on a channel", tone_detect_session_function, TONE_DETECT_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "tone_detect"; commands_api_interface->desc = "Start tone detection on a channel" ; commands_api_interface->function = tone_detect_session_function ; commands_api_interface->syntax = "<uuid> <key> <tone_spec> [<flags> <timeout> <app> <args> <hits>]" ; break; }; | |||
6769 | SWITCH_ADD_API(commands_api_interface, "unload", "Unload module", unload_function, UNLOAD_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "unload"; commands_api_interface ->desc = "Unload module"; commands_api_interface->function = unload_function; commands_api_interface->syntax = "[-f] <mod_name>" ; break; }; | |||
6770 | SWITCH_ADD_API(commands_api_interface, "unsched_api", "Unschedule an api command", unsched_api_function, UNSCHED_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "unsched_api"; commands_api_interface->desc = "Unschedule an api command" ; commands_api_interface->function = unsched_api_function; commands_api_interface->syntax = "<task_id>"; break ; }; | |||
6771 | SWITCH_ADD_API(commands_api_interface, "uptime", "Show uptime", uptime_function, UPTIME_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uptime"; commands_api_interface ->desc = "Show uptime"; commands_api_interface->function = uptime_function; commands_api_interface->syntax = "[us|ms|s|m|h|d|microseconds|milliseconds|seconds|minutes|hours|days]" ; break; }; | |||
6772 | SWITCH_ADD_API(commands_api_interface, "reg_url", "", reg_url_function, "<user>@<realm>")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "reg_url"; commands_api_interface ->desc = ""; commands_api_interface->function = reg_url_function ; commands_api_interface->syntax = "<user>@<realm>" ; break; }; | |||
6773 | SWITCH_ADD_API(commands_api_interface, "url_decode", "Url decode a string", url_decode_function, "<string>")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "url_decode"; commands_api_interface ->desc = "Url decode a string"; commands_api_interface-> function = url_decode_function; commands_api_interface->syntax = "<string>"; break; }; | |||
6774 | SWITCH_ADD_API(commands_api_interface, "url_encode", "Url encode a string", url_encode_function, "<string>")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "url_encode"; commands_api_interface ->desc = "Url encode a string"; commands_api_interface-> function = url_encode_function; commands_api_interface->syntax = "<string>"; break; }; | |||
6775 | SWITCH_ADD_API(commands_api_interface, "user_data", "Find user data", user_data_function, "<user>@<domain> [var|param|attr] <name>")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "user_data"; commands_api_interface ->desc = "Find user data"; commands_api_interface->function = user_data_function; commands_api_interface->syntax = "<user>@<domain> [var|param|attr] <name>" ; break; }; | |||
6776 | SWITCH_ADD_API(commands_api_interface, "uuid_early_ok", "stop ignoring early media", uuid_early_ok_function, "<uuid>")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_early_ok" ; commands_api_interface->desc = "stop ignoring early media" ; commands_api_interface->function = uuid_early_ok_function ; commands_api_interface->syntax = "<uuid>"; break; }; | |||
6777 | SWITCH_ADD_API(commands_api_interface, "user_exists", "Find a user", user_exists_function, "<key> <user> <domain>")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "user_exists"; commands_api_interface->desc = "Find a user"; commands_api_interface ->function = user_exists_function; commands_api_interface-> syntax = "<key> <user> <domain>"; break; }; | |||
6778 | SWITCH_ADD_API(commands_api_interface, "uuid_answer", "answer", uuid_answer_function, "<uuid>")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_answer"; commands_api_interface->desc = "answer"; commands_api_interface ->function = uuid_answer_function; commands_api_interface-> syntax = "<uuid>"; break; }; | |||
6779 | SWITCH_ADD_API(commands_api_interface, "uuid_audio", "uuid_audio", session_audio_function, AUDIO_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_audio"; commands_api_interface ->desc = "uuid_audio"; commands_api_interface->function = session_audio_function; commands_api_interface->syntax = "<uuid> [start [read|write] [mute|level <level>]|stop]" ; break; }; | |||
6780 | SWITCH_ADD_API(commands_api_interface, "uuid_break", "Break out of media sent to channel", break_function, BREAK_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_break"; commands_api_interface ->desc = "Break out of media sent to channel"; commands_api_interface ->function = break_function; commands_api_interface->syntax = "<uuid> [all]"; break; }; | |||
6781 | SWITCH_ADD_API(commands_api_interface, "uuid_bridge", "Bridge call legs", uuid_bridge_function, "")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_bridge"; commands_api_interface->desc = "Bridge call legs"; commands_api_interface ->function = uuid_bridge_function; commands_api_interface-> syntax = ""; break; }; | |||
6782 | SWITCH_ADD_API(commands_api_interface, "uuid_broadcast", "Execute dialplan application", uuid_broadcast_function, BROADCAST_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_broadcast" ; commands_api_interface->desc = "Execute dialplan application" ; commands_api_interface->function = uuid_broadcast_function ; commands_api_interface->syntax = "<uuid> <path> [aleg|bleg|holdb|both]" ; break; }; | |||
6783 | SWITCH_ADD_API(commands_api_interface, "uuid_buglist", "List media bugs on a session", uuid_buglist_function, BUGLIST_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_buglist" ; commands_api_interface->desc = "List media bugs on a session" ; commands_api_interface->function = uuid_buglist_function ; commands_api_interface->syntax = "<uuid>"; break; }; | |||
6784 | SWITCH_ADD_API(commands_api_interface, "uuid_chat", "Send a chat message", uuid_chat, UUID_CHAT_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_chat"; commands_api_interface ->desc = "Send a chat message"; commands_api_interface-> function = uuid_chat; commands_api_interface->syntax = "<uuid> <text>" ; break; }; | |||
6785 | SWITCH_ADD_API(commands_api_interface, "uuid_debug_media", "Debug media", uuid_debug_media_function, DEBUG_MEDIA_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_debug_media" ; commands_api_interface->desc = "Debug media"; commands_api_interface ->function = uuid_debug_media_function; commands_api_interface ->syntax = "<uuid> <read|write|both|vread|vwrite|vboth|all> <on|off>" ; break; }; | |||
6786 | SWITCH_ADD_API(commands_api_interface, "uuid_deflect", "Send a deflect", uuid_deflect, UUID_DEFLECT_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_deflect" ; commands_api_interface->desc = "Send a deflect"; commands_api_interface ->function = uuid_deflect; commands_api_interface->syntax = "<uuid> <uri>"; break; }; | |||
6787 | SWITCH_ADD_API(commands_api_interface, "uuid_displace", "Displace audio", session_displace_function, "<uuid> [start|stop] <path> [<limit>] [mux]")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_displace" ; commands_api_interface->desc = "Displace audio"; commands_api_interface ->function = session_displace_function; commands_api_interface ->syntax = "<uuid> [start|stop] <path> [<limit>] [mux]" ; break; }; | |||
6788 | SWITCH_ADD_API(commands_api_interface, "uuid_display", "Update phone display", uuid_display_function, DISPLAY_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_display" ; commands_api_interface->desc = "Update phone display"; commands_api_interface ->function = uuid_display_function; commands_api_interface ->syntax = "<uuid> <display>"; break; }; | |||
6789 | SWITCH_ADD_API(commands_api_interface, "uuid_drop_dtmf", "Drop all DTMF or replace it with a mask", uuid_drop_dtmf, UUID_DROP_DTMF_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_drop_dtmf" ; commands_api_interface->desc = "Drop all DTMF or replace it with a mask" ; commands_api_interface->function = uuid_drop_dtmf; commands_api_interface ->syntax = "<uuid> [on | off ] [ mask_digits <digits> | mask_file <file>]" ; break; }; | |||
6790 | SWITCH_ADD_API(commands_api_interface, "uuid_dump", "Dump session vars", uuid_dump_function, DUMP_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_dump"; commands_api_interface ->desc = "Dump session vars"; commands_api_interface->function = uuid_dump_function; commands_api_interface->syntax = "<uuid> [format]" ; break; }; | |||
6791 | SWITCH_ADD_API(commands_api_interface, "uuid_exists", "Check if a uuid exists", uuid_exists_function, EXISTS_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_exists"; commands_api_interface->desc = "Check if a uuid exists"; commands_api_interface ->function = uuid_exists_function; commands_api_interface-> syntax = "<uuid>"; break; }; | |||
6792 | SWITCH_ADD_API(commands_api_interface, "uuid_fileman", "Manage session audio", uuid_fileman_function, FILEMAN_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_fileman" ; commands_api_interface->desc = "Manage session audio"; commands_api_interface ->function = uuid_fileman_function; commands_api_interface ->syntax = "<uuid> <cmd>:<val>"; break; }; | |||
6793 | SWITCH_ADD_API(commands_api_interface, "uuid_flush_dtmf", "Flush dtmf on a given uuid", uuid_flush_dtmf_function, "<uuid>")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_flush_dtmf" ; commands_api_interface->desc = "Flush dtmf on a given uuid" ; commands_api_interface->function = uuid_flush_dtmf_function ; commands_api_interface->syntax = "<uuid>"; break; }; | |||
6794 | SWITCH_ADD_API(commands_api_interface, "uuid_getvar", "Get a variable from a channel", uuid_getvar_function, GETVAR_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_getvar"; commands_api_interface->desc = "Get a variable from a channel" ; commands_api_interface->function = uuid_getvar_function; commands_api_interface->syntax = "<uuid> <var>" ; break; }; | |||
6795 | SWITCH_ADD_API(commands_api_interface, "uuid_hold", "Place call on hold", uuid_hold_function, HOLD_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_hold"; commands_api_interface ->desc = "Place call on hold"; commands_api_interface-> function = uuid_hold_function; commands_api_interface->syntax = "[off|toggle] <uuid> [<display>]"; break; }; | |||
6796 | SWITCH_ADD_API(commands_api_interface, "uuid_kill", "Kill channel", kill_function, KILL_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_kill"; commands_api_interface ->desc = "Kill channel"; commands_api_interface->function = kill_function; commands_api_interface->syntax = "<uuid> [cause]" ; break; }; | |||
6797 | SWITCH_ADD_API(commands_api_interface, "uuid_send_message", "Send MESSAGE to the endpoint", uuid_send_message_function, SEND_MESSAGE_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_send_message" ; commands_api_interface->desc = "Send MESSAGE to the endpoint" ; commands_api_interface->function = uuid_send_message_function ; commands_api_interface->syntax = "<uuid> <message>" ; break; }; | |||
6798 | SWITCH_ADD_API(commands_api_interface, "uuid_send_info", "Send info to the endpoint", uuid_send_info_function, INFO_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_send_info" ; commands_api_interface->desc = "Send info to the endpoint" ; commands_api_interface->function = uuid_send_info_function ; commands_api_interface->syntax = "<uuid> [<mime_type> <mime_subtype>] <message>" ; break; }; | |||
6799 | SWITCH_ADD_API(commands_api_interface, "uuid_set_media_stats", "Set media stats", uuid_set_media_stats, UUID_MEDIA_STATS_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_set_media_stats" ; commands_api_interface->desc = "Set media stats"; commands_api_interface ->function = uuid_set_media_stats; commands_api_interface-> syntax = "<uuid>"; break; }; | |||
6800 | SWITCH_ADD_API(commands_api_interface, "uuid_video_refresh", "Send video refresh.", uuid_video_refresh_function, VIDEO_REFRESH_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_video_refresh" ; commands_api_interface->desc = "Send video refresh."; commands_api_interface ->function = uuid_video_refresh_function; commands_api_interface ->syntax = "<uuid>"; break; }; | |||
6801 | SWITCH_ADD_API(commands_api_interface, "uuid_outgoing_answer", "Answer outgoing channel", outgoing_answer_function, OUTGOING_ANSWER_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_outgoing_answer" ; commands_api_interface->desc = "Answer outgoing channel" ; commands_api_interface->function = outgoing_answer_function ; commands_api_interface->syntax = "<uuid>"; break; }; | |||
6802 | SWITCH_ADD_API(commands_api_interface, "uuid_limit", "Increase limit resource", uuid_limit_function, LIMIT_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_limit"; commands_api_interface ->desc = "Increase limit resource"; commands_api_interface ->function = uuid_limit_function; commands_api_interface-> syntax = "<uuid> <backend> <realm> <resource> [<max>[/interval]] [number [dialplan [context]]]" ; break; }; | |||
6803 | SWITCH_ADD_API(commands_api_interface, "uuid_limit_release", "Release limit resource", uuid_limit_release_function, LIMIT_RELEASE_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_limit_release" ; commands_api_interface->desc = "Release limit resource"; commands_api_interface->function = uuid_limit_release_function ; commands_api_interface->syntax = "<uuid> <backend> [realm] [resource]" ; break; }; | |||
6804 | SWITCH_ADD_API(commands_api_interface, "uuid_limit_release", "Release limit resource", uuid_limit_release_function, LIMIT_RELEASE_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_limit_release" ; commands_api_interface->desc = "Release limit resource"; commands_api_interface->function = uuid_limit_release_function ; commands_api_interface->syntax = "<uuid> <backend> [realm] [resource]" ; break; }; | |||
6805 | SWITCH_ADD_API(commands_api_interface, "uuid_loglevel", "Set loglevel on session", uuid_loglevel, UUID_LOGLEVEL_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_loglevel" ; commands_api_interface->desc = "Set loglevel on session" ; commands_api_interface->function = uuid_loglevel; commands_api_interface ->syntax = "<uuid> <level>"; break; }; | |||
6806 | SWITCH_ADD_API(commands_api_interface, "uuid_media", "Reinvite FS in or out of media path", uuid_media_function, MEDIA_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_media"; commands_api_interface ->desc = "Reinvite FS in or out of media path"; commands_api_interface ->function = uuid_media_function; commands_api_interface-> syntax = "[off] <uuid>"; break; }; | |||
6807 | SWITCH_ADD_API(commands_api_interface, "uuid_media_reneg", "Media negotiation", uuid_media_neg_function, MEDIA_RENEG_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_media_reneg" ; commands_api_interface->desc = "Media negotiation"; commands_api_interface ->function = uuid_media_neg_function; commands_api_interface ->syntax = "<uuid>[ <codec_string>]"; break; }; | |||
6808 | SWITCH_ADD_API(commands_api_interface, "uuid_park", "Park channel", park_function, PARK_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_park"; commands_api_interface ->desc = "Park channel"; commands_api_interface->function = park_function; commands_api_interface->syntax = "<uuid>" ; break; }; | |||
6809 | SWITCH_ADD_API(commands_api_interface, "uuid_pause", "Pause media on a channel", pause_function, PAUSE_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_pause"; commands_api_interface ->desc = "Pause media on a channel"; commands_api_interface ->function = pause_function; commands_api_interface->syntax = "<uuid> <on|off>"; break; }; | |||
6810 | SWITCH_ADD_API(commands_api_interface, "uuid_phone_event", "Send an event to the phone", uuid_phone_event_function, PHONE_EVENT_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_phone_event" ; commands_api_interface->desc = "Send an event to the phone" ; commands_api_interface->function = uuid_phone_event_function ; commands_api_interface->syntax = "<uuid>"; break; }; | |||
6811 | SWITCH_ADD_API(commands_api_interface, "uuid_ring_ready", "Sending ringing to a channel", uuid_ring_ready_function, RING_READY_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_ring_ready" ; commands_api_interface->desc = "Sending ringing to a channel" ; commands_api_interface->function = uuid_ring_ready_function ; commands_api_interface->syntax = "<uuid> [queued]" ; break; }; | |||
6812 | SWITCH_ADD_API(commands_api_interface, "uuid_pre_answer", "pre_answer", uuid_pre_answer_function, "<uuid>")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_pre_answer" ; commands_api_interface->desc = "pre_answer"; commands_api_interface ->function = uuid_pre_answer_function; commands_api_interface ->syntax = "<uuid>"; break; }; | |||
6813 | SWITCH_ADD_API(commands_api_interface, "uuid_preprocess", "Pre-process Channel", preprocess_function, PREPROCESS_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_preprocess" ; commands_api_interface->desc = "Pre-process Channel"; commands_api_interface ->function = preprocess_function; commands_api_interface-> syntax = "<>"; break; }; | |||
6814 | SWITCH_ADD_API(commands_api_interface, "uuid_record", "Record session audio", session_record_function, SESS_REC_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_record"; commands_api_interface->desc = "Record session audio"; commands_api_interface ->function = session_record_function; commands_api_interface ->syntax = "<uuid> [start|stop|mask|unmask] <path> [<limit>]" ; break; }; | |||
6815 | SWITCH_ADD_API(commands_api_interface, "uuid_recovery_refresh", "Send a recovery_refresh", uuid_recovery_refresh, UUID_RECOVERY_REFRESH_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_recovery_refresh" ; commands_api_interface->desc = "Send a recovery_refresh" ; commands_api_interface->function = uuid_recovery_refresh ; commands_api_interface->syntax = "<uuid> <uri>" ; break; }; | |||
6816 | SWITCH_ADD_API(commands_api_interface, "uuid_recv_dtmf", "Receive dtmf digits", uuid_recv_dtmf_function, UUID_RECV_DTMF_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_recv_dtmf" ; commands_api_interface->desc = "Receive dtmf digits"; commands_api_interface ->function = uuid_recv_dtmf_function; commands_api_interface ->syntax = "<uuid> <dtmf_data>"; break; }; | |||
6817 | SWITCH_ADD_API(commands_api_interface, "uuid_send_dtmf", "Send dtmf digits", uuid_send_dtmf_function, UUID_SEND_DTMF_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_send_dtmf" ; commands_api_interface->desc = "Send dtmf digits"; commands_api_interface ->function = uuid_send_dtmf_function; commands_api_interface ->syntax = "<uuid> <dtmf_data>"; break; }; | |||
6818 | SWITCH_ADD_API(commands_api_interface, "uuid_session_heartbeat", "uuid_session_heartbeat", uuid_session_heartbeat_function, HEARTBEAT_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_session_heartbeat" ; commands_api_interface->desc = "uuid_session_heartbeat"; commands_api_interface->function = uuid_session_heartbeat_function ; commands_api_interface->syntax = "<uuid> [sched] [0|<seconds>]" ; break; }; | |||
6819 | SWITCH_ADD_API(commands_api_interface, "uuid_setvar_multi", "Set multiple variables", uuid_setvar_multi_function, SETVAR_MULTI_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_setvar_multi" ; commands_api_interface->desc = "Set multiple variables"; commands_api_interface->function = uuid_setvar_multi_function ; commands_api_interface->syntax = "<uuid> <var>=<value>;<var>=<value>..." ; break; }; | |||
6820 | SWITCH_ADD_API(commands_api_interface, "uuid_setvar", "Set a variable", uuid_setvar_function, SETVAR_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_setvar"; commands_api_interface->desc = "Set a variable"; commands_api_interface ->function = uuid_setvar_function; commands_api_interface-> syntax = "<uuid> <var> [value]"; break; }; | |||
6821 | SWITCH_ADD_API(commands_api_interface, "uuid_transfer", "Transfer a session", transfer_function, TRANSFER_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_transfer" ; commands_api_interface->desc = "Transfer a session"; commands_api_interface ->function = transfer_function; commands_api_interface-> syntax = "<uuid> [-bleg|-both] <dest-exten> [<dialplan>] [<context>]" ; break; }; | |||
6822 | SWITCH_ADD_API(commands_api_interface, "uuid_dual_transfer", "Transfer a session and its partner", dual_transfer_function, DUAL_TRANSFER_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_dual_transfer" ; commands_api_interface->desc = "Transfer a session and its partner" ; commands_api_interface->function = dual_transfer_function ; commands_api_interface->syntax = "<uuid> <A-dest-exten>[/<A-dialplan>][/<A-context>] <B-dest-exten>[/<B-dialplan>][/<B-context>]" ; break; }; | |||
6823 | SWITCH_ADD_API(commands_api_interface, "uuid_simplify", "Try to cut out of a call path / attended xfer", uuid_simplify_function, SIMPLIFY_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_simplify" ; commands_api_interface->desc = "Try to cut out of a call path / attended xfer" ; commands_api_interface->function = uuid_simplify_function ; commands_api_interface->syntax = "<uuid>"; break; }; | |||
6824 | SWITCH_ADD_API(commands_api_interface, "uuid_jitterbuffer", "uuid_jitterbuffer", uuid_jitterbuffer_function, JITTERBUFFER_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_jitterbuffer" ; commands_api_interface->desc = "uuid_jitterbuffer"; commands_api_interface ->function = uuid_jitterbuffer_function; commands_api_interface ->syntax = "<uuid> [0|<min_msec>[:<max_msec>]]" ; break; }; | |||
6825 | SWITCH_ADD_API(commands_api_interface, "uuid_zombie_exec", "Set zombie_exec flag on the specified uuid", uuid_zombie_exec_function, "<uuid>")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "uuid_zombie_exec" ; commands_api_interface->desc = "Set zombie_exec flag on the specified uuid" ; commands_api_interface->function = uuid_zombie_exec_function ; commands_api_interface->syntax = "<uuid>"; break; }; | |||
6826 | SWITCH_ADD_API(commands_api_interface, "xml_flush_cache", "Clear xml cache", xml_flush_function, "<id> <key> <val>")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "xml_flush_cache" ; commands_api_interface->desc = "Clear xml cache"; commands_api_interface ->function = xml_flush_function; commands_api_interface-> syntax = "<id> <key> <val>"; break; }; | |||
6827 | SWITCH_ADD_API(commands_api_interface, "xml_locate", "Find some xml", xml_locate_function, "[root | <section> <tag> <tag_attr_name> <tag_attr_val>]")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "xml_locate"; commands_api_interface ->desc = "Find some xml"; commands_api_interface->function = xml_locate_function; commands_api_interface->syntax = "[root | <section> <tag> <tag_attr_name> <tag_attr_val>]" ; break; }; | |||
6828 | SWITCH_ADD_API(commands_api_interface, "xml_wrap", "Wrap another api command in xml", xml_wrap_api_function, "<command> <args>")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "xml_wrap"; commands_api_interface ->desc = "Wrap another api command in xml"; commands_api_interface ->function = xml_wrap_api_function; commands_api_interface ->syntax = "<command> <args>"; break; }; | |||
6829 | SWITCH_ADD_API(commands_api_interface, "file_exists", "Check if a file exists on server", file_exists_function, "<file>")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "file_exists"; commands_api_interface->desc = "Check if a file exists on server" ; commands_api_interface->function = file_exists_function; commands_api_interface->syntax = "<file>"; break; }; | |||
6830 | SWITCH_ADD_API(commands_api_interface, "json", "JSON API", json_function, "JSON")for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "json"; commands_api_interface ->desc = "JSON API"; commands_api_interface->function = json_function; commands_api_interface->syntax = "JSON"; break ; }; | |||
6831 | ||||
6832 | SWITCH_ADD_JSON_API(json_api_interface, "mediaStats", "JSON Media Stats", json_stats_function, "")for (;;) { json_api_interface = (switch_json_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_JSON_API_INTERFACE ); json_api_interface->interface_name = "mediaStats"; json_api_interface ->desc = "JSON Media Stats"; json_api_interface->function = json_stats_function; json_api_interface->syntax = ""; break ; }; | |||
6833 | ||||
6834 | SWITCH_ADD_JSON_API(json_api_interface, "status", "JSON status API", json_status_function, "")for (;;) { json_api_interface = (switch_json_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_JSON_API_INTERFACE ); json_api_interface->interface_name = "status"; json_api_interface ->desc = "JSON status API"; json_api_interface->function = json_status_function; json_api_interface->syntax = ""; break ; }; | |||
6835 | SWITCH_ADD_JSON_API(json_api_interface, "fsapi", "JSON FSAPI Gateway", json_api_function, "")for (;;) { json_api_interface = (switch_json_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_JSON_API_INTERFACE ); json_api_interface->interface_name = "fsapi"; json_api_interface ->desc = "JSON FSAPI Gateway"; json_api_interface->function = json_api_function; json_api_interface->syntax = ""; break ; }; | |||
6836 | SWITCH_ADD_JSON_API(json_api_interface, "execute", "JSON session execute application", json_execute_function, "")for (;;) { json_api_interface = (switch_json_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_JSON_API_INTERFACE ); json_api_interface->interface_name = "execute"; json_api_interface ->desc = "JSON session execute application"; json_api_interface ->function = json_execute_function; json_api_interface-> syntax = ""; break; }; | |||
6837 | SWITCH_ADD_JSON_API(json_api_interface, "channelData", "JSON channel data application", json_channel_data_function, "")for (;;) { json_api_interface = (switch_json_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_JSON_API_INTERFACE ); json_api_interface->interface_name = "channelData"; json_api_interface ->desc = "JSON channel data application"; json_api_interface ->function = json_channel_data_function; json_api_interface ->syntax = ""; break; }; | |||
6838 | ||||
6839 | ||||
6840 | ||||
6841 | switch_console_set_complete("add alias add"); | |||
6842 | switch_console_set_complete("add alias stickyadd"); | |||
6843 | switch_console_set_complete("add alias del"); | |||
6844 | switch_console_set_complete("add coalesce"); | |||
6845 | switch_console_set_complete("add complete add"); | |||
6846 | switch_console_set_complete("add complete del"); | |||
6847 | switch_console_set_complete("add db_cache status"); | |||
6848 | switch_console_set_complete("add fsctl debug_level"); | |||
6849 | switch_console_set_complete("add fsctl debug_pool"); | |||
6850 | switch_console_set_complete("add fsctl debug_sql"); | |||
6851 | switch_console_set_complete("add fsctl last_sps"); | |||
6852 | switch_console_set_complete("add fsctl default_dtmf_duration"); | |||
6853 | switch_console_set_complete("add fsctl hupall"); | |||
6854 | switch_console_set_complete("add fsctl loglevel"); | |||
6855 | switch_console_set_complete("add fsctl loglevel console"); | |||
6856 | switch_console_set_complete("add fsctl loglevel alert"); | |||
6857 | switch_console_set_complete("add fsctl loglevel crit"); | |||
6858 | switch_console_set_complete("add fsctl loglevel err"); | |||
6859 | switch_console_set_complete("add fsctl loglevel warning"); | |||
6860 | switch_console_set_complete("add fsctl loglevel notice"); | |||
6861 | switch_console_set_complete("add fsctl loglevel info"); | |||
6862 | switch_console_set_complete("add fsctl loglevel debug"); | |||
6863 | switch_console_set_complete("add fsctl max_dtmf_duration"); | |||
6864 | switch_console_set_complete("add fsctl max_sessions"); | |||
6865 | switch_console_set_complete("add fsctl min_dtmf_duration"); | |||
6866 | switch_console_set_complete("add fsctl pause"); | |||
6867 | switch_console_set_complete("add fsctl pause inbound"); | |||
6868 | switch_console_set_complete("add fsctl pause outbound"); | |||
6869 | switch_console_set_complete("add fsctl reclaim_mem"); | |||
6870 | switch_console_set_complete("add fsctl resume"); | |||
6871 | switch_console_set_complete("add fsctl resume inbound"); | |||
6872 | switch_console_set_complete("add fsctl resume outbound"); | |||
6873 | switch_console_set_complete("add fsctl calibrate_clock"); | |||
6874 | switch_console_set_complete("add fsctl crash"); | |||
6875 | switch_console_set_complete("add fsctl verbose_events"); | |||
6876 | switch_console_set_complete("add fsctl save_history"); | |||
6877 | switch_console_set_complete("add fsctl pause_check"); | |||
6878 | switch_console_set_complete("add fsctl pause_check inbound"); | |||
6879 | switch_console_set_complete("add fsctl pause_check outbound"); | |||
6880 | switch_console_set_complete("add fsctl ready_check"); | |||
6881 | switch_console_set_complete("add fsctl recover"); | |||
6882 | switch_console_set_complete("add fsctl shutdown_check"); | |||
6883 | switch_console_set_complete("add fsctl shutdown"); | |||
6884 | switch_console_set_complete("add fsctl shutdown asap"); | |||
6885 | switch_console_set_complete("add fsctl shutdown now"); | |||
6886 | switch_console_set_complete("add fsctl shutdown asap restart"); | |||
6887 | switch_console_set_complete("add fsctl shutdown cancel"); | |||
6888 | switch_console_set_complete("add fsctl shutdown elegant"); | |||
6889 | switch_console_set_complete("add fsctl shutdown elegant restart"); | |||
6890 | switch_console_set_complete("add fsctl shutdown reincarnate now"); | |||
6891 | switch_console_set_complete("add fsctl shutdown restart"); | |||
6892 | switch_console_set_complete("add fsctl shutdown restart asap"); | |||
6893 | switch_console_set_complete("add fsctl shutdown restart elegant"); | |||
6894 | switch_console_set_complete("add fsctl sps"); | |||
6895 | switch_console_set_complete("add fsctl sync_clock"); | |||
6896 | switch_console_set_complete("add fsctl flush_db_handles"); | |||
6897 | switch_console_set_complete("add fsctl min_idle_cpu"); | |||
6898 | switch_console_set_complete("add fsctl send_sighup"); | |||
6899 | switch_console_set_complete("add interface_ip auto ::console::list_interfaces"); | |||
6900 | switch_console_set_complete("add interface_ip ipv4 ::console::list_interfaces"); | |||
6901 | switch_console_set_complete("add interface_ip ipv6 ::console::list_interfaces"); | |||
6902 | switch_console_set_complete("add load ::console::list_available_modules"); | |||
6903 | switch_console_set_complete("add nat_map reinit"); | |||
6904 | switch_console_set_complete("add nat_map republish"); | |||
6905 | switch_console_set_complete("add nat_map status"); | |||
6906 | switch_console_set_complete("add reload ::console::list_loaded_modules"); | |||
6907 | switch_console_set_complete("add reloadacl reloadxml"); | |||
6908 | switch_console_set_complete("add show aliases"); | |||
6909 | switch_console_set_complete("add show api"); | |||
6910 | switch_console_set_complete("add show application"); | |||
6911 | switch_console_set_complete("add show calls"); | |||
6912 | switch_console_set_complete("add show channels"); | |||
6913 | switch_console_set_complete("add show channels count"); | |||
6914 | switch_console_set_complete("add show chat"); | |||
6915 | switch_console_set_complete("add show codec"); | |||
6916 | switch_console_set_complete("add show complete"); | |||
6917 | switch_console_set_complete("add show dialplan"); | |||
6918 | switch_console_set_complete("add show detailed_calls"); | |||
6919 | switch_console_set_complete("add show bridged_calls"); | |||
6920 | switch_console_set_complete("add show detailed_bridged_calls"); | |||
6921 | switch_console_set_complete("add show endpoint"); | |||
6922 | switch_console_set_complete("add show file"); | |||
6923 | switch_console_set_complete("add show interfaces"); | |||
6924 | switch_console_set_complete("add show interface_types"); | |||
6925 | switch_console_set_complete("add show tasks"); | |||
6926 | switch_console_set_complete("add show management"); | |||
6927 | switch_console_set_complete("add show modules"); | |||
6928 | switch_console_set_complete("add show nat_map"); | |||
6929 | switch_console_set_complete("add show registrations"); | |||
6930 | switch_console_set_complete("add show say"); | |||
6931 | switch_console_set_complete("add show status"); | |||
6932 | switch_console_set_complete("add show timer"); | |||
6933 | switch_console_set_complete("add shutdown"); | |||
6934 | switch_console_set_complete("add sql_escape"); | |||
6935 | switch_console_set_complete("add unload ::console::list_loaded_modules"); | |||
6936 | switch_console_set_complete("add uptime ms"); | |||
6937 | switch_console_set_complete("add uptime s"); | |||
6938 | switch_console_set_complete("add uptime m"); | |||
6939 | switch_console_set_complete("add uptime h"); | |||
6940 | switch_console_set_complete("add uptime d"); | |||
6941 | switch_console_set_complete("add uptime microseconds"); | |||
6942 | switch_console_set_complete("add uptime milliseconds"); | |||
6943 | switch_console_set_complete("add uptime seconds"); | |||
6944 | switch_console_set_complete("add uptime minutes"); | |||
6945 | switch_console_set_complete("add uptime hours"); | |||
6946 | switch_console_set_complete("add uptime days"); | |||
6947 | switch_console_set_complete("add uuid_audio ::console::list_uuid start read mute"); | |||
6948 | switch_console_set_complete("add uuid_audio ::console::list_uuid start read level"); | |||
6949 | switch_console_set_complete("add uuid_audio ::console::list_uuid start write mute"); | |||
6950 | switch_console_set_complete("add uuid_audio ::console::list_uuid start write level"); | |||
6951 | switch_console_set_complete("add uuid_audio ::console::list_uuid stop"); | |||
6952 | switch_console_set_complete("add uuid_break ::console::list_uuid all"); | |||
6953 | switch_console_set_complete("add uuid_break ::console::list_uuid both"); | |||
6954 | switch_console_set_complete("add uuid_bridge ::console::list_uuid ::console::list_uuid"); | |||
6955 | switch_console_set_complete("add uuid_broadcast ::console::list_uuid"); | |||
6956 | switch_console_set_complete("add uuid_buglist ::console::list_uuid"); | |||
6957 | switch_console_set_complete("add uuid_chat ::console::list_uuid"); | |||
6958 | switch_console_set_complete("add uuid_debug_media ::console::list_uuid"); | |||
6959 | switch_console_set_complete("add uuid_deflect ::console::list_uuid"); | |||
6960 | switch_console_set_complete("add uuid_displace ::console::list_uuid"); | |||
6961 | switch_console_set_complete("add uuid_display ::console::list_uuid"); | |||
6962 | switch_console_set_complete("add uuid_drop_dtmf ::console::list_uuid"); | |||
6963 | switch_console_set_complete("add uuid_dump ::console::list_uuid"); | |||
6964 | switch_console_set_complete("add uuid_answer ::console::list_uuid"); | |||
6965 | switch_console_set_complete("add uuid_ring_ready ::console::list_uuid queued"); | |||
6966 | switch_console_set_complete("add uuid_pre_answer ::console::list_uuid"); | |||
6967 | switch_console_set_complete("add uuid_early_ok ::console::list_uuid"); | |||
6968 | switch_console_set_complete("add uuid_exists ::console::list_uuid"); | |||
6969 | switch_console_set_complete("add uuid_fileman ::console::list_uuid"); | |||
6970 | switch_console_set_complete("add uuid_flush_dtmf ::console::list_uuid"); | |||
6971 | switch_console_set_complete("add uuid_getvar ::console::list_uuid"); | |||
6972 | switch_console_set_complete("add uuid_hold ::console::list_uuid"); | |||
6973 | switch_console_set_complete("add uuid_send_info ::console::list_uuid"); | |||
6974 | switch_console_set_complete("add uuid_jitterbuffer ::console::list_uuid"); | |||
6975 | switch_console_set_complete("add uuid_kill ::console::list_uuid"); | |||
6976 | switch_console_set_complete("add uuid_outgoing_answer ::console::list_uuid"); | |||
6977 | switch_console_set_complete("add uuid_limit ::console::list_uuid"); | |||
6978 | switch_console_set_complete("add uuid_limit_release ::console::list_uuid"); | |||
6979 | switch_console_set_complete("add uuid_loglevel ::console::list_uuid console"); | |||
6980 | switch_console_set_complete("add uuid_loglevel ::console::list_uuid alert"); | |||
6981 | switch_console_set_complete("add uuid_loglevel ::console::list_uuid crit"); | |||
6982 | switch_console_set_complete("add uuid_loglevel ::console::list_uuid err"); | |||
6983 | switch_console_set_complete("add uuid_loglevel ::console::list_uuid warning"); | |||
6984 | switch_console_set_complete("add uuid_loglevel ::console::list_uuid notice"); | |||
6985 | switch_console_set_complete("add uuid_loglevel ::console::list_uuid info"); | |||
6986 | switch_console_set_complete("add uuid_loglevel ::console::list_uuid debug"); | |||
6987 | switch_console_set_complete("add uuid_media ::console::list_uuid"); | |||
6988 | switch_console_set_complete("add uuid_media off ::console::list_uuid"); | |||
6989 | switch_console_set_complete("add uuid_park ::console::list_uuid"); | |||
6990 | switch_console_set_complete("add uuid_media_reneg ::console::list_uuid"); | |||
6991 | switch_console_set_complete("add uuid_phone_event ::console::list_uuid talk"); | |||
6992 | switch_console_set_complete("add uuid_phone_event ::console::list_uuid hold"); | |||
6993 | switch_console_set_complete("add uuid_preprocess ::console::list_uuid"); | |||
6994 | switch_console_set_complete("add uuid_record ::console::list_uuid ::[start:stop"); | |||
6995 | switch_console_set_complete("add uuid_recovery_refresh ::console::list_uuid"); | |||
6996 | switch_console_set_complete("add uuid_recv_dtmf ::console::list_uuid"); | |||
6997 | switch_console_set_complete("add uuid_send_dtmf ::console::list_uuid"); | |||
6998 | switch_console_set_complete("add uuid_session_heartbeat ::console::list_uuid"); | |||
6999 | switch_console_set_complete("add uuid_setvar_multi ::console::list_uuid"); | |||
7000 | switch_console_set_complete("add uuid_setvar ::console::list_uuid"); | |||
7001 | switch_console_set_complete("add uuid_simplify ::console::list_uuid"); | |||
7002 | switch_console_set_complete("add uuid_transfer ::console::list_uuid"); | |||
7003 | switch_console_set_complete("add uuid_dual_transfer ::console::list_uuid"); | |||
7004 | switch_console_set_complete("add uuid_video_refresh ::console::list_uuid"); | |||
7005 | switch_console_set_complete("add version"); | |||
7006 | switch_console_set_complete("add uuid_warning ::console::list_uuid"); | |||
7007 | switch_console_set_complete("add ..."); | |||
7008 | switch_console_set_complete("add file_exists"); | |||
7009 | ||||
7010 | /* indicate that the module should continue to be loaded */ | |||
7011 | return SWITCH_STATUS_NOUNLOAD; | |||
7012 | } | |||
7013 | ||||
7014 | /* For Emacs: | |||
7015 | * Local Variables: | |||
7016 | * mode:c | |||
7017 | * indent-tabs-mode:t | |||
7018 | * tab-width:4 | |||
7019 | * c-basic-offset:4 | |||
7020 | * End: | |||
7021 | * For VIM: | |||
7022 | * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet: | |||
7023 | */ |