File: | src/mod/applications/mod_voicemail/mod_voicemail.c |
Location: | line 4508, column 10 |
Description: | Potential leak of memory pointed to by '__retval' |
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 | * Bret McDanel <trixter AT 0xdecafbad.com> | ||||||
28 | * John Wehle (john@feith.com) | ||||||
29 | * Raymond Chandler <intralanman@gmail.com> | ||||||
30 | * Kristin King <kristin.king@quentustech.com> | ||||||
31 | * Emmanuel Schmidbauer <e.schmidbauer@gmail.com> | ||||||
32 | * | ||||||
33 | * mod_voicemail.c -- Voicemail Module | ||||||
34 | * | ||||||
35 | */ | ||||||
36 | #include <switch.h> | ||||||
37 | |||||||
38 | #ifdef _MSC_VER /* compilers are stupid sometimes */ | ||||||
39 | #define TRY_CODE(code)do { status = code; if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) { goto end; } break;} while(status ) for(;;) {status = code; if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) { goto end; } break;} | ||||||
40 | #else | ||||||
41 | #define TRY_CODE(code)do { status = code; if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) { goto end; } break;} while(status ) do { status = code; if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) { goto end; } break;} while(status) | ||||||
42 | #endif | ||||||
43 | |||||||
44 | |||||||
45 | #define xml_safe_free(_x)if (_x) switch_xml_free(_x); _x = ((void*)0) if (_x) switch_xml_free(_x); _x = NULL((void*)0) | ||||||
46 | |||||||
47 | SWITCH_MODULE_LOAD_FUNCTION(mod_voicemail_load)switch_status_t mod_voicemail_load (switch_loadable_module_interface_t **module_interface, switch_memory_pool_t *pool); | ||||||
48 | SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_voicemail_shutdown)switch_status_t mod_voicemail_shutdown (void); | ||||||
49 | SWITCH_MODULE_DEFINITION(mod_voicemail, mod_voicemail_load, mod_voicemail_shutdown, NULL)static const char modname[] = "mod_voicemail" ; __attribute__ ((visibility("default"))) switch_loadable_module_function_table_t mod_voicemail_module_interface = { 5, mod_voicemail_load, mod_voicemail_shutdown , ((void*)0), SMODF_NONE }; | ||||||
50 | #define VM_EVENT_MAINT"vm::maintenance" "vm::maintenance" | ||||||
51 | |||||||
52 | #define VM_MAX_GREETINGS9 9 | ||||||
53 | #define VM_EVENT_QUEUE_SIZE50000 50000 | ||||||
54 | |||||||
55 | static switch_status_t voicemail_inject(const char *data, switch_core_session_t *session); | ||||||
56 | |||||||
57 | static const char *global_cf = "voicemail.conf"; | ||||||
58 | static struct { | ||||||
59 | switch_hash_t *profile_hash; | ||||||
60 | int debug; | ||||||
61 | int message_query_exact_match; | ||||||
62 | int32_t threads; | ||||||
63 | int32_t running; | ||||||
64 | switch_queue_t *event_queue; | ||||||
65 | switch_mutex_t *mutex; | ||||||
66 | switch_memory_pool_t *pool; | ||||||
67 | } globals; | ||||||
68 | |||||||
69 | typedef enum { | ||||||
70 | VM_DATE_FIRST, | ||||||
71 | VM_DATE_LAST, | ||||||
72 | VM_DATE_NEVER | ||||||
73 | } date_location_t; | ||||||
74 | |||||||
75 | typedef enum { | ||||||
76 | PFLAG_DESTROY = 1 << 0 | ||||||
77 | } vm_flags_t; | ||||||
78 | |||||||
79 | typedef enum { | ||||||
80 | VM_MOVE_NEXT, | ||||||
81 | VM_MOVE_PREV, | ||||||
82 | VM_MOVE_SAME | ||||||
83 | } msg_move_t; | ||||||
84 | |||||||
85 | typedef enum { | ||||||
86 | MWI_REASON_UNKNOWN = 0, | ||||||
87 | MWI_REASON_NEW = 1, | ||||||
88 | MWI_REASON_DELETE = 2, | ||||||
89 | MWI_REASON_SAVE = 3, | ||||||
90 | MWI_REASON_PURGE = 4, | ||||||
91 | MWI_REASON_READ = 5 | ||||||
92 | } mwi_reason_t; | ||||||
93 | |||||||
94 | struct mwi_reason_table { | ||||||
95 | const char *name; | ||||||
96 | int state; | ||||||
97 | }; | ||||||
98 | |||||||
99 | static struct mwi_reason_table MWI_REASON_CHART[] = { | ||||||
100 | {"UNKNOWN", MWI_REASON_UNKNOWN}, | ||||||
101 | {"NEW", MWI_REASON_NEW}, | ||||||
102 | {"DELETE", MWI_REASON_DELETE}, | ||||||
103 | {"SAVE", MWI_REASON_SAVE}, | ||||||
104 | {"PURGE", MWI_REASON_PURGE}, | ||||||
105 | {"READ", MWI_REASON_READ}, | ||||||
106 | {NULL((void*)0), 0} | ||||||
107 | }; | ||||||
108 | |||||||
109 | #define VM_PROFILE_CONFIGITEM_COUNT100 100 | ||||||
110 | |||||||
111 | struct vm_profile { | ||||||
112 | char *name; | ||||||
113 | char *dbname; | ||||||
114 | char *odbc_dsn; | ||||||
115 | char *play_new_messages_lifo; | ||||||
116 | char *play_saved_messages_lifo; | ||||||
117 | char terminator_key[2]; | ||||||
118 | char play_new_messages_key[2]; | ||||||
119 | char play_saved_messages_key[2]; | ||||||
120 | |||||||
121 | char login_keys[16]; | ||||||
122 | char main_menu_key[2]; | ||||||
123 | char skip_greet_key[2]; | ||||||
124 | char skip_info_key[2]; | ||||||
125 | char config_menu_key[2]; | ||||||
126 | char record_greeting_key[2]; | ||||||
127 | char choose_greeting_key[2]; | ||||||
128 | char record_name_key[2]; | ||||||
129 | char change_pass_key[2]; | ||||||
130 | |||||||
131 | char record_file_key[2]; | ||||||
132 | char listen_file_key[2]; | ||||||
133 | char save_file_key[2]; | ||||||
134 | char delete_file_key[2]; | ||||||
135 | char undelete_file_key[2]; | ||||||
136 | char email_key[2]; | ||||||
137 | char callback_key[2]; | ||||||
138 | char pause_key[2]; | ||||||
139 | char restart_key[2]; | ||||||
140 | char ff_key[2]; | ||||||
141 | char rew_key[2]; | ||||||
142 | char prev_msg_key[2]; | ||||||
143 | char next_msg_key[2]; | ||||||
144 | char repeat_msg_key[2]; | ||||||
145 | char urgent_key[2]; | ||||||
146 | char operator_key[2]; | ||||||
147 | char vmain_key[2]; | ||||||
148 | char forward_key[2]; | ||||||
149 | char prepend_key[2]; | ||||||
150 | char file_ext[10]; | ||||||
151 | char *record_title; | ||||||
152 | char *record_comment; | ||||||
153 | char *record_copyright; | ||||||
154 | char *operator_ext; | ||||||
155 | char *vmain_ext; | ||||||
156 | char *tone_spec; | ||||||
157 | char *storage_dir; | ||||||
158 | switch_bool_t storage_dir_shared; | ||||||
159 | char *callback_dialplan; | ||||||
160 | char *callback_context; | ||||||
161 | char *email_body; | ||||||
162 | char *email_headers; | ||||||
163 | char *notify_email_body; | ||||||
164 | char *notify_email_headers; | ||||||
165 | char *web_head; | ||||||
166 | char *web_tail; | ||||||
167 | char *email_from; | ||||||
168 | char *date_fmt; | ||||||
169 | char *convert_cmd; | ||||||
170 | char *convert_ext; | ||||||
171 | date_location_t play_date_announcement; | ||||||
172 | uint32_t digit_timeout; | ||||||
173 | uint32_t max_login_attempts; | ||||||
174 | uint32_t min_record_len; | ||||||
175 | uint32_t max_record_len; | ||||||
176 | uint32_t max_retries; | ||||||
177 | switch_mutex_t *mutex; | ||||||
178 | uint32_t record_threshold; | ||||||
179 | uint32_t record_silence_hits; | ||||||
180 | uint32_t record_sample_rate; | ||||||
181 | switch_bool_t auto_playback_recordings; | ||||||
182 | switch_bool_t db_password_override; | ||||||
183 | switch_bool_t allow_empty_password_auth; | ||||||
184 | switch_thread_rwlock_t *rwlock; | ||||||
185 | switch_memory_pool_t *pool; | ||||||
186 | uint32_t flags; | ||||||
187 | |||||||
188 | switch_xml_config_item_t config[VM_PROFILE_CONFIGITEM_COUNT100]; | ||||||
189 | switch_xml_config_string_options_t config_str_pool; | ||||||
190 | }; | ||||||
191 | typedef struct vm_profile vm_profile_t; | ||||||
192 | |||||||
193 | const char * mwi_reason2str(mwi_reason_t state) | ||||||
194 | { | ||||||
195 | uint8_t x; | ||||||
196 | const char *str = "UNKNOWN"; | ||||||
197 | |||||||
198 | for (x = 0; x < (sizeof(MWI_REASON_CHART) / sizeof(struct mwi_reason_table)) - 1; x++) { | ||||||
199 | if (MWI_REASON_CHART[x].state == state) { | ||||||
200 | str = MWI_REASON_CHART[x].name; | ||||||
201 | break; | ||||||
202 | } | ||||||
203 | } | ||||||
204 | |||||||
205 | return str; | ||||||
206 | } | ||||||
207 | |||||||
208 | switch_cache_db_handle_t *vm_get_db_handle(vm_profile_t *profile) | ||||||
209 | { | ||||||
210 | |||||||
211 | switch_cache_db_handle_t *dbh = NULL((void*)0); | ||||||
212 | char *dsn; | ||||||
213 | |||||||
214 | if (!zstr(profile->odbc_dsn)_zstr(profile->odbc_dsn)) { | ||||||
215 | dsn = profile->odbc_dsn; | ||||||
216 | } else { | ||||||
217 | dsn = profile->dbname; | ||||||
218 | } | ||||||
219 | |||||||
220 | if (switch_cache_db_get_db_handle_dsn(&dbh, dsn)_switch_cache_db_get_db_handle_dsn(&dbh, dsn, "mod_voicemail.c" , (const char *)__func__, 220) != SWITCH_STATUS_SUCCESS) { | ||||||
221 | dbh = NULL((void*)0); | ||||||
222 | } | ||||||
223 | |||||||
224 | return dbh; | ||||||
225 | } | ||||||
226 | |||||||
227 | |||||||
228 | static switch_status_t vm_execute_sql(vm_profile_t *profile, char *sql, switch_mutex_t *mutex) | ||||||
229 | { | ||||||
230 | switch_cache_db_handle_t *dbh = NULL((void*)0); | ||||||
231 | switch_status_t status = SWITCH_STATUS_FALSE; | ||||||
232 | |||||||
233 | if (mutex) { | ||||||
234 | switch_mutex_lock(mutex); | ||||||
235 | } | ||||||
236 | |||||||
237 | if (!(dbh = vm_get_db_handle(profile))) { | ||||||
238 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 238, ((void*)0), SWITCH_LOG_ERROR, "Error Opening DB\n"); | ||||||
239 | goto end; | ||||||
240 | } | ||||||
241 | |||||||
242 | status = switch_cache_db_execute_sql(dbh, sql, NULL((void*)0)); | ||||||
243 | |||||||
244 | end: | ||||||
245 | |||||||
246 | switch_cache_db_release_db_handle(&dbh); | ||||||
247 | |||||||
248 | if (mutex) { | ||||||
249 | switch_mutex_unlock(mutex); | ||||||
250 | } | ||||||
251 | |||||||
252 | return status; | ||||||
253 | } | ||||||
254 | |||||||
255 | char *vm_execute_sql2str(vm_profile_t *profile, switch_mutex_t *mutex, char *sql, char *resbuf, size_t len) | ||||||
256 | { | ||||||
257 | switch_cache_db_handle_t *dbh = NULL((void*)0); | ||||||
258 | |||||||
259 | char *ret = NULL((void*)0); | ||||||
260 | |||||||
261 | if (mutex) { | ||||||
262 | switch_mutex_lock(mutex); | ||||||
263 | } | ||||||
264 | |||||||
265 | if (!(dbh = vm_get_db_handle(profile))) { | ||||||
266 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 266, ((void*)0), SWITCH_LOG_ERROR, "Error Opening DB\n"); | ||||||
267 | goto end; | ||||||
268 | } | ||||||
269 | |||||||
270 | ret = switch_cache_db_execute_sql2str(dbh, sql, resbuf, len, NULL((void*)0)); | ||||||
271 | |||||||
272 | end: | ||||||
273 | |||||||
274 | switch_cache_db_release_db_handle(&dbh); | ||||||
275 | |||||||
276 | if (mutex) { | ||||||
277 | switch_mutex_unlock(mutex); | ||||||
278 | } | ||||||
279 | |||||||
280 | return ret; | ||||||
281 | |||||||
282 | } | ||||||
283 | |||||||
284 | |||||||
285 | static switch_bool_t vm_execute_sql_callback(vm_profile_t *profile, switch_mutex_t *mutex, char *sql, switch_core_db_callback_func_t callback, | ||||||
286 | void *pdata) | ||||||
287 | { | ||||||
288 | switch_bool_t ret = SWITCH_FALSE; | ||||||
289 | char *errmsg = NULL((void*)0); | ||||||
290 | switch_cache_db_handle_t *dbh = NULL((void*)0); | ||||||
291 | |||||||
292 | if (mutex) { | ||||||
293 | switch_mutex_lock(mutex); | ||||||
294 | } | ||||||
295 | |||||||
296 | if (!(dbh = vm_get_db_handle(profile))) { | ||||||
297 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 297, ((void*)0), SWITCH_LOG_ERROR, "Error Opening DB\n"); | ||||||
298 | goto end; | ||||||
299 | } | ||||||
300 | |||||||
301 | switch_cache_db_execute_sql_callback(dbh, sql, callback, pdata, &errmsg); | ||||||
302 | |||||||
303 | if (errmsg) { | ||||||
304 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 304, ((void*)0), SWITCH_LOG_ERROR, "SQL ERR: [%s] %s\n", sql, errmsg); | ||||||
305 | free(errmsg); | ||||||
306 | } | ||||||
307 | |||||||
308 | end: | ||||||
309 | |||||||
310 | switch_cache_db_release_db_handle(&dbh); | ||||||
311 | |||||||
312 | if (mutex) { | ||||||
313 | switch_mutex_unlock(mutex); | ||||||
314 | } | ||||||
315 | |||||||
316 | return ret; | ||||||
317 | } | ||||||
318 | |||||||
319 | |||||||
320 | |||||||
321 | static char vm_sql[] = | ||||||
322 | "CREATE TABLE voicemail_msgs (\n" | ||||||
323 | " created_epoch INTEGER,\n" | ||||||
324 | " read_epoch INTEGER,\n" | ||||||
325 | " username VARCHAR(255),\n" | ||||||
326 | " domain VARCHAR(255),\n" | ||||||
327 | " uuid VARCHAR(255),\n" | ||||||
328 | " cid_name VARCHAR(255),\n" | ||||||
329 | " cid_number VARCHAR(255),\n" | ||||||
330 | " in_folder VARCHAR(255),\n" | ||||||
331 | " file_path VARCHAR(255),\n" | ||||||
332 | " message_len INTEGER,\n" " flags VARCHAR(255),\n" " read_flags VARCHAR(255),\n" " forwarded_by VARCHAR(255)\n" ");\n"; | ||||||
333 | |||||||
334 | static char vm_pref_sql[] = | ||||||
335 | "CREATE TABLE voicemail_prefs (\n" | ||||||
336 | " username VARCHAR(255),\n" | ||||||
337 | " domain VARCHAR(255),\n" | ||||||
338 | " name_path VARCHAR(255),\n" " greeting_path VARCHAR(255),\n" " password VARCHAR(255)\n" ");\n"; | ||||||
339 | |||||||
340 | static char *vm_index_list[] = { | ||||||
341 | "create index voicemail_msgs_idx1 on voicemail_msgs(created_epoch)", | ||||||
342 | "create index voicemail_msgs_idx2 on voicemail_msgs(username)", | ||||||
343 | "create index voicemail_msgs_idx3 on voicemail_msgs(domain)", | ||||||
344 | "create index voicemail_msgs_idx4 on voicemail_msgs(uuid)", | ||||||
345 | "create index voicemail_msgs_idx5 on voicemail_msgs(in_folder)", | ||||||
346 | "create index voicemail_msgs_idx6 on voicemail_msgs(read_flags)", | ||||||
347 | "create index voicemail_msgs_idx7 on voicemail_msgs(forwarded_by)", | ||||||
348 | "create index voicemail_msgs_idx8 on voicemail_msgs(read_epoch)", | ||||||
349 | "create index voicemail_msgs_idx9 on voicemail_msgs(flags)", | ||||||
350 | "create index voicemail_prefs_idx1 on voicemail_prefs(username)", | ||||||
351 | "create index voicemail_prefs_idx2 on voicemail_prefs(domain)", | ||||||
352 | NULL((void*)0) | ||||||
353 | }; | ||||||
354 | |||||||
355 | static void free_profile(vm_profile_t *profile) | ||||||
356 | { | ||||||
357 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 357, ((void*)0), SWITCH_LOG_DEBUG, "Destroying Profile %s\n", profile->name); | ||||||
358 | switch_core_destroy_memory_pool(&profile->pool)switch_core_perform_destroy_memory_pool(&profile->pool , "mod_voicemail.c", (const char *)__func__, 358); | ||||||
359 | } | ||||||
360 | |||||||
361 | static void destroy_profile(const char *profile_name, switch_bool_t block) | ||||||
362 | { | ||||||
363 | vm_profile_t *profile = NULL((void*)0); | ||||||
364 | switch_mutex_lock(globals.mutex); | ||||||
365 | if ((profile = switch_core_hash_find(globals.profile_hash, profile_name))) { | ||||||
366 | switch_core_hash_delete(globals.profile_hash, profile_name); | ||||||
367 | } | ||||||
368 | switch_mutex_unlock(globals.mutex); | ||||||
369 | |||||||
370 | if (!profile) { | ||||||
371 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 371, ((void*)0), SWITCH_LOG_ERROR, "[%s] Invalid Profile\n", profile_name); | ||||||
372 | return; | ||||||
373 | } | ||||||
374 | |||||||
375 | if (block) { | ||||||
376 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 376, ((void*)0), SWITCH_LOG_DEBUG, "[%s] Waiting for write lock\n", profile->name); | ||||||
377 | switch_thread_rwlock_wrlock(profile->rwlock); | ||||||
378 | } else { | ||||||
379 | if (switch_thread_rwlock_trywrlock(profile->rwlock) != SWITCH_STATUS_SUCCESS) { | ||||||
380 | /* Lock failed, set the destroy flag so it'll be destroyed whenever its not in use anymore */ | ||||||
381 | switch_set_flag(profile, PFLAG_DESTROY)(profile)->flags |= (PFLAG_DESTROY); | ||||||
382 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 382, ((void*)0), SWITCH_LOG_DEBUG, "[%s] Profile is in use, memory will be freed whenever its no longer in use\n", | ||||||
383 | profile->name); | ||||||
384 | return; | ||||||
385 | } | ||||||
386 | } | ||||||
387 | |||||||
388 | free_profile(profile); | ||||||
389 | } | ||||||
390 | |||||||
391 | |||||||
392 | /* Static buffer, 2 bytes */ | ||||||
393 | static switch_xml_config_string_options_t config_dtmf = { NULL((void*)0), 2, "[0-9#\\*]" }; | ||||||
394 | static switch_xml_config_string_options_t config_dtmf_optional = { NULL((void*)0), 2, "[0-9#\\*]?" }; | ||||||
395 | static switch_xml_config_string_options_t config_login_keys = { NULL((void*)0), 16, "[0-9#\\*]*" }; | ||||||
396 | static switch_xml_config_string_options_t config_file_ext = { NULL((void*)0), 10, NULL((void*)0) }; | ||||||
397 | static switch_xml_config_int_options_t config_int_0_10000 = { SWITCH_TRUE, 0, SWITCH_TRUE, 10000 }; | ||||||
398 | static switch_xml_config_int_options_t config_int_0_1000 = { SWITCH_TRUE, 0, SWITCH_TRUE, 1000 }; | ||||||
399 | static switch_xml_config_int_options_t config_int_digit_timeout = { SWITCH_TRUE, 0, SWITCH_TRUE, 30000 }; | ||||||
400 | static switch_xml_config_int_options_t config_int_max_logins = { SWITCH_TRUE, 0, SWITCH_TRUE, 10 }; | ||||||
401 | static switch_xml_config_int_options_t config_int_ht_0 = { SWITCH_TRUE, 0 }; | ||||||
402 | |||||||
403 | static switch_xml_config_enum_item_t config_play_date_announcement[] = { | ||||||
404 | {"first", VM_DATE_FIRST}, | ||||||
405 | {"last", VM_DATE_LAST}, | ||||||
406 | {"never", VM_DATE_NEVER}, | ||||||
407 | {NULL((void*)0), 0} | ||||||
408 | }; | ||||||
409 | |||||||
410 | |||||||
411 | static switch_status_t vm_config_email_callback(switch_xml_config_item_t *item, const char *newvalue, switch_config_callback_type_t callback_type, | ||||||
412 | switch_bool_t changed) | ||||||
413 | { | ||||||
414 | vm_profile_t *profile = (vm_profile_t *) item->data; | ||||||
415 | |||||||
416 | switch_assert(profile)((profile) ? (void) (0) : __assert_fail ("profile", "mod_voicemail.c" , 416, __PRETTY_FUNCTION__)); | ||||||
417 | |||||||
418 | if (callback_type == CONFIG_LOAD || callback_type == CONFIG_RELOAD) { | ||||||
419 | char *email_headers = NULL((void*)0), *email_body = NULL((void*)0); | ||||||
420 | if (newvalue) { | ||||||
421 | switch_stream_handle_t stream; | ||||||
422 | SWITCH_STANDARD_STREAM(stream)memset(&stream, 0, sizeof(stream)); stream.data = malloc( 1024); ((stream.data) ? (void) (0) : __assert_fail ("stream.data" , "mod_voicemail.c", 422, __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; | ||||||
423 | if (switch_stream_write_file_contents(&stream, newvalue) == SWITCH_STATUS_SUCCESS) { | ||||||
424 | email_headers = switch_core_strdup(profile->pool, stream.data)switch_core_perform_strdup(profile->pool, stream.data, "mod_voicemail.c" , (const char *)__func__, 424); | ||||||
425 | if ((email_body = strstr(email_headers, "\n\n"))) { | ||||||
426 | *email_body = '\0'; | ||||||
427 | email_body += 2; | ||||||
428 | } else if ((email_body = strstr(email_headers, "\r\n\r\n"))) { | ||||||
429 | *email_body = '\0'; | ||||||
430 | email_body += 4; | ||||||
431 | } | ||||||
432 | } | ||||||
433 | |||||||
434 | free(stream.data); | ||||||
435 | } | ||||||
436 | |||||||
437 | if (email_headers) { | ||||||
438 | profile->email_headers = email_headers; | ||||||
439 | } | ||||||
440 | if (email_body) { | ||||||
441 | profile->email_body = email_body; | ||||||
442 | } | ||||||
443 | } | ||||||
444 | |||||||
445 | return SWITCH_STATUS_SUCCESS; | ||||||
446 | } | ||||||
447 | |||||||
448 | static switch_status_t vm_config_notify_callback(switch_xml_config_item_t *item, const char *newvalue, switch_config_callback_type_t callback_type, | ||||||
449 | switch_bool_t changed) | ||||||
450 | { | ||||||
451 | vm_profile_t *profile = (vm_profile_t *) item->data; | ||||||
452 | |||||||
453 | switch_assert(profile)((profile) ? (void) (0) : __assert_fail ("profile", "mod_voicemail.c" , 453, __PRETTY_FUNCTION__)); | ||||||
454 | |||||||
455 | if (callback_type == CONFIG_LOAD || callback_type == CONFIG_RELOAD) { | ||||||
456 | char *email_headers = NULL((void*)0), *email_body = NULL((void*)0); | ||||||
457 | if (newvalue) { | ||||||
458 | switch_stream_handle_t stream; | ||||||
459 | SWITCH_STANDARD_STREAM(stream)memset(&stream, 0, sizeof(stream)); stream.data = malloc( 1024); ((stream.data) ? (void) (0) : __assert_fail ("stream.data" , "mod_voicemail.c", 459, __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; | ||||||
460 | if (switch_stream_write_file_contents(&stream, newvalue) == SWITCH_STATUS_SUCCESS) { | ||||||
461 | email_headers = switch_core_strdup(profile->pool, stream.data)switch_core_perform_strdup(profile->pool, stream.data, "mod_voicemail.c" , (const char *)__func__, 461); | ||||||
462 | if ((email_body = strstr(email_headers, "\n\n"))) { | ||||||
463 | *email_body = '\0'; | ||||||
464 | email_body += 2; | ||||||
465 | } else if ((email_body = strstr(email_headers, "\r\n\r\n"))) { | ||||||
466 | *email_body = '\0'; | ||||||
467 | email_body += 4; | ||||||
468 | } | ||||||
469 | } | ||||||
470 | |||||||
471 | free(stream.data); | ||||||
472 | } | ||||||
473 | |||||||
474 | if (email_headers) { | ||||||
475 | profile->notify_email_headers = email_headers; | ||||||
476 | } | ||||||
477 | if (email_body) { | ||||||
478 | profile->notify_email_body = email_body; | ||||||
479 | } | ||||||
480 | } | ||||||
481 | |||||||
482 | return SWITCH_STATUS_SUCCESS; | ||||||
483 | } | ||||||
484 | |||||||
485 | static switch_status_t vm_config_web_callback(switch_xml_config_item_t *item, const char *newvalue, switch_config_callback_type_t callback_type, | ||||||
486 | switch_bool_t changed) | ||||||
487 | { | ||||||
488 | vm_profile_t *profile = (vm_profile_t *) item->data; | ||||||
489 | |||||||
490 | switch_assert(profile)((profile) ? (void) (0) : __assert_fail ("profile", "mod_voicemail.c" , 490, __PRETTY_FUNCTION__)); | ||||||
491 | |||||||
492 | if (callback_type == CONFIG_LOAD || callback_type == CONFIG_RELOAD) { | ||||||
493 | char *web_head = NULL((void*)0), *web_tail = NULL((void*)0); | ||||||
494 | if (newvalue) { | ||||||
495 | switch_stream_handle_t stream; | ||||||
496 | SWITCH_STANDARD_STREAM(stream)memset(&stream, 0, sizeof(stream)); stream.data = malloc( 1024); ((stream.data) ? (void) (0) : __assert_fail ("stream.data" , "mod_voicemail.c", 496, __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; | ||||||
497 | if (switch_stream_write_file_contents(&stream, newvalue) == SWITCH_STATUS_SUCCESS) { | ||||||
498 | web_head = switch_core_strdup(profile->pool, stream.data)switch_core_perform_strdup(profile->pool, stream.data, "mod_voicemail.c" , (const char *)__func__, 498); | ||||||
499 | |||||||
500 | if ((web_tail = strstr(web_head, "<!break>\n"))) { | ||||||
501 | *web_tail = '\0'; | ||||||
502 | web_tail += 9; | ||||||
503 | } else if ((web_tail = strstr(web_head, "<!break>\r\n"))) { | ||||||
504 | *web_tail = '\0'; | ||||||
505 | web_tail += 10; | ||||||
506 | } | ||||||
507 | } | ||||||
508 | |||||||
509 | free(stream.data); | ||||||
510 | } | ||||||
511 | |||||||
512 | if (web_head) { | ||||||
513 | profile->web_head = web_head; | ||||||
514 | } | ||||||
515 | |||||||
516 | if (web_tail) { | ||||||
517 | profile->web_tail = web_tail; | ||||||
518 | } | ||||||
519 | } | ||||||
520 | |||||||
521 | return SWITCH_STATUS_SUCCESS; | ||||||
522 | } | ||||||
523 | |||||||
524 | static switch_status_t vm_config_validate_samplerate(switch_xml_config_item_t *item, const char *newvalue, switch_config_callback_type_t callback_type, | ||||||
525 | switch_bool_t changed) | ||||||
526 | { | ||||||
527 | if ((callback_type == CONFIG_LOAD || callback_type == CONFIG_RELOAD) && newvalue) { | ||||||
528 | int val = *(int *) item->ptr; | ||||||
529 | if (val != 0 && !switch_is_valid_rate(val)(val == 8000 || val == 12000 || val == 16000 || val == 24000 || val == 32000 || val == 11025 || val == 22050 || val == 44100 || val == 48000)) { | ||||||
530 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 530, ((void*)0), SWITCH_LOG_WARNING, "Invalid samplerate %s\n", newvalue); | ||||||
531 | return SWITCH_STATUS_FALSE; | ||||||
532 | } | ||||||
533 | } | ||||||
534 | |||||||
535 | return SWITCH_STATUS_SUCCESS; | ||||||
536 | } | ||||||
537 | |||||||
538 | /*! | ||||||
539 | * \brief Sets the profile's configuration instructions | ||||||
540 | */ | ||||||
541 | vm_profile_t *profile_set_config(vm_profile_t *profile) | ||||||
542 | { | ||||||
543 | int i = 0; | ||||||
544 | |||||||
545 | profile->config_str_pool.pool = profile->pool; | ||||||
546 | |||||||
547 | /* | ||||||
548 | SWITCH _CONFIG_SET_ITEM(item, "key", type, flags, | ||||||
549 | pointer, default, options, help_syntax, help_description) | ||||||
550 | */ | ||||||
551 | |||||||
552 | /* DTMFs */ | ||||||
553 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "terminator-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "terminator-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->terminator_key, (void*)("#"), &config_dtmf, ( (void*)0), ((void*)0), ((void*)0)) | ||||||
554 | &profile->terminator_key, "#", &config_dtmf, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "terminator-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->terminator_key, (void*)("#"), &config_dtmf, ( (void*)0), ((void*)0), ((void*)0)); | ||||||
555 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "play-new-messages-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "play-new-messages-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE , &profile->play_new_messages_key, (void*)("1"), & config_dtmf, ((void*)0), ((void*)0), ((void*)0)) | ||||||
556 | &profile->play_new_messages_key, "1", &config_dtmf, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "play-new-messages-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE , &profile->play_new_messages_key, (void*)("1"), & config_dtmf, ((void*)0), ((void*)0), ((void*)0)); | ||||||
557 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "play-saved-messages-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "play-saved-messages-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE , &profile->play_saved_messages_key, (void*)("2"), & config_dtmf, ((void*)0), ((void*)0), ((void*)0)) | ||||||
558 | &profile->play_saved_messages_key, "2", &config_dtmf, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "play-saved-messages-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE , &profile->play_saved_messages_key, (void*)("2"), & config_dtmf, ((void*)0), ((void*)0), ((void*)0)); | ||||||
559 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "play-new-messages-lifo", SWITCH_CONFIG_BOOL, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "play-new-messages-lifo", SWITCH_CONFIG_BOOL, CONFIG_RELOADABLE , &profile->play_new_messages_lifo, (void*)(SWITCH_FALSE ), ((void*)0), ((void*)0), ((void*)0), ((void*)0)) | ||||||
560 | &profile->play_new_messages_lifo, SWITCH_FALSE, NULL, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "play-new-messages-lifo", SWITCH_CONFIG_BOOL, CONFIG_RELOADABLE , &profile->play_new_messages_lifo, (void*)(SWITCH_FALSE ), ((void*)0), ((void*)0), ((void*)0), ((void*)0)); | ||||||
561 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "play-saved-messages-lifo", SWITCH_CONFIG_BOOL, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "play-saved-messages-lifo", SWITCH_CONFIG_BOOL, CONFIG_RELOADABLE , &profile->play_saved_messages_lifo, (void*)(SWITCH_FALSE ), ((void*)0), ((void*)0), ((void*)0), ((void*)0)) | ||||||
562 | &profile->play_saved_messages_lifo, SWITCH_FALSE, NULL, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "play-saved-messages-lifo", SWITCH_CONFIG_BOOL, CONFIG_RELOADABLE , &profile->play_saved_messages_lifo, (void*)(SWITCH_FALSE ), ((void*)0), ((void*)0), ((void*)0), ((void*)0)); | ||||||
563 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "login-keys", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "login-keys", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->login_keys, (void*)("0"), &config_login_keys, ((void*)0), ((void*)0), ((void*)0)) | ||||||
564 | &profile->login_keys, "0", &config_login_keys, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "login-keys", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->login_keys, (void*)("0"), &config_login_keys, ((void*)0), ((void*)0), ((void*)0)); | ||||||
565 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "main-menu-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "main-menu-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->main_menu_key, (void*)("0"), &config_dtmf, (( void*)0), ((void*)0), ((void*)0)) | ||||||
566 | &profile->main_menu_key, "0", &config_dtmf, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "main-menu-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->main_menu_key, (void*)("0"), &config_dtmf, (( void*)0), ((void*)0), ((void*)0)); | ||||||
567 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "skip-greet-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "skip-greet-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->skip_greet_key, (void*)("#"), &config_dtmf, ( (void*)0), ((void*)0), ((void*)0)) | ||||||
568 | &profile->skip_greet_key, "#", &config_dtmf, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "skip-greet-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->skip_greet_key, (void*)("#"), &config_dtmf, ( (void*)0), ((void*)0), ((void*)0)); | ||||||
569 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "skip-info-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "skip-info-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->skip_info_key, (void*)("*"), &config_dtmf, (( void*)0), ((void*)0), ((void*)0)) | ||||||
570 | &profile->skip_info_key, "*", &config_dtmf, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "skip-info-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->skip_info_key, (void*)("*"), &config_dtmf, (( void*)0), ((void*)0), ((void*)0)); | ||||||
571 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "config-menu-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "config-menu-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &profile->config_menu_key, (void*)("5"), &config_dtmf , ((void*)0), ((void*)0), ((void*)0)) | ||||||
572 | &profile->config_menu_key, "5", &config_dtmf, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "config-menu-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &profile->config_menu_key, (void*)("5"), &config_dtmf , ((void*)0), ((void*)0), ((void*)0)); | ||||||
573 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "record-greeting-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "record-greeting-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE , &profile->record_greeting_key, (void*)("1"), &config_dtmf , ((void*)0), ((void*)0), ((void*)0)) | ||||||
574 | &profile->record_greeting_key, "1", &config_dtmf, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "record-greeting-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE , &profile->record_greeting_key, (void*)("1"), &config_dtmf , ((void*)0), ((void*)0), ((void*)0)); | ||||||
575 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "choose-greeting-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "choose-greeting-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE , &profile->choose_greeting_key, (void*)("2"), &config_dtmf , ((void*)0), ((void*)0), ((void*)0)) | ||||||
576 | &profile->choose_greeting_key, "2", &config_dtmf, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "choose-greeting-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE , &profile->choose_greeting_key, (void*)("2"), &config_dtmf , ((void*)0), ((void*)0), ((void*)0)); | ||||||
577 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "record-name-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "record-name-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &profile->record_name_key, (void*)("3"), &config_dtmf , ((void*)0), ((void*)0), ((void*)0)) | ||||||
578 | &profile->record_name_key, "3", &config_dtmf, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "record-name-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &profile->record_name_key, (void*)("3"), &config_dtmf , ((void*)0), ((void*)0), ((void*)0)); | ||||||
579 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "change-pass-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "change-pass-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &profile->change_pass_key, (void*)("6"), &config_dtmf , ((void*)0), ((void*)0), ((void*)0)) | ||||||
580 | &profile->change_pass_key, "6", &config_dtmf, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "change-pass-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &profile->change_pass_key, (void*)("6"), &config_dtmf , ((void*)0), ((void*)0), ((void*)0)); | ||||||
581 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "record-file-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "record-file-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &profile->record_file_key, (void*)("3"), &config_dtmf , ((void*)0), ((void*)0), ((void*)0)) | ||||||
582 | &profile->record_file_key, "3", &config_dtmf, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "record-file-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &profile->record_file_key, (void*)("3"), &config_dtmf , ((void*)0), ((void*)0), ((void*)0)); | ||||||
583 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "listen-file-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "listen-file-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &profile->listen_file_key, (void*)("1"), &config_dtmf , ((void*)0), ((void*)0), ((void*)0)) | ||||||
584 | &profile->listen_file_key, "1", &config_dtmf, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "listen-file-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &profile->listen_file_key, (void*)("1"), &config_dtmf , ((void*)0), ((void*)0), ((void*)0)); | ||||||
585 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "save-file-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "save-file-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->save_file_key, (void*)("2"), &config_dtmf, (( void*)0), ((void*)0), ((void*)0)) | ||||||
586 | &profile->save_file_key, "2", &config_dtmf, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "save-file-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->save_file_key, (void*)("2"), &config_dtmf, (( void*)0), ((void*)0), ((void*)0)); | ||||||
587 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "delete-file-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "delete-file-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &profile->delete_file_key, (void*)("7"), &config_dtmf , ((void*)0), ((void*)0), ((void*)0)) | ||||||
588 | &profile->delete_file_key, "7", &config_dtmf, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "delete-file-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &profile->delete_file_key, (void*)("7"), &config_dtmf , ((void*)0), ((void*)0), ((void*)0)); | ||||||
589 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "undelete-file-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "undelete-file-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE , &profile->undelete_file_key, (void*)("8"), &config_dtmf , ((void*)0), ((void*)0), ((void*)0)) | ||||||
590 | &profile->undelete_file_key, "8", &config_dtmf, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "undelete-file-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE , &profile->undelete_file_key, (void*)("8"), &config_dtmf , ((void*)0), ((void*)0), ((void*)0)); | ||||||
591 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "email-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &profile->email_key, "4", &config_dtmf, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "email-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->email_key, (void*)("4"), &config_dtmf, ((void *)0), ((void*)0), ((void*)0)); | ||||||
592 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "callback-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "callback-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->callback_key, (void*)("5"), &config_dtmf, ((void *)0), ((void*)0), ((void*)0)) | ||||||
593 | &profile->callback_key, "5", &config_dtmf, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "callback-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->callback_key, (void*)("5"), &config_dtmf, ((void *)0), ((void*)0), ((void*)0)); | ||||||
594 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "pause-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &profile->pause_key, "0", &config_dtmf, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "pause-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->pause_key, (void*)("0"), &config_dtmf, ((void *)0), ((void*)0), ((void*)0)); | ||||||
595 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "restart-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "restart-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->restart_key, (void*)("1"), &config_dtmf, ((void *)0), ((void*)0), ((void*)0)) | ||||||
596 | &profile->restart_key, "1", &config_dtmf, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "restart-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->restart_key, (void*)("1"), &config_dtmf, ((void *)0), ((void*)0), ((void*)0)); | ||||||
597 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "ff-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &profile->ff_key, "6", &config_dtmf, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "ff-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &profile ->ff_key, (void*)("6"), &config_dtmf, ((void*)0), ((void *)0), ((void*)0)); | ||||||
598 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "rew-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &profile->rew_key, "4", &config_dtmf, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "rew-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &profile ->rew_key, (void*)("4"), &config_dtmf, ((void*)0), ((void *)0), ((void*)0)); | ||||||
599 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "previous-message-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "previous-message-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE , &profile->prev_msg_key, (void*)("1"), &config_dtmf , ((void*)0), ((void*)0), ((void*)0)) | ||||||
600 | &profile->prev_msg_key, "1", &config_dtmf, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "previous-message-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE , &profile->prev_msg_key, (void*)("1"), &config_dtmf , ((void*)0), ((void*)0), ((void*)0)); | ||||||
601 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "next-message-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "next-message-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE , &profile->next_msg_key, (void*)("3"), &config_dtmf , ((void*)0), ((void*)0), ((void*)0)) | ||||||
602 | &profile->next_msg_key, "3", &config_dtmf, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "next-message-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE , &profile->next_msg_key, (void*)("3"), &config_dtmf , ((void*)0), ((void*)0), ((void*)0)); | ||||||
603 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "repeat-message-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "repeat-message-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE , &profile->repeat_msg_key, (void*)("0"), &config_dtmf , ((void*)0), ((void*)0), ((void*)0)) | ||||||
604 | &profile->repeat_msg_key, "0", &config_dtmf, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "repeat-message-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE , &profile->repeat_msg_key, (void*)("0"), &config_dtmf , ((void*)0), ((void*)0), ((void*)0)); | ||||||
605 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "urgent-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "urgent-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->urgent_key, (void*)("*"), &config_dtmf, ((void *)0), ((void*)0), ((void*)0)) | ||||||
606 | &profile->urgent_key, "*", &config_dtmf, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "urgent-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->urgent_key, (void*)("*"), &config_dtmf, ((void *)0), ((void*)0), ((void*)0)); | ||||||
607 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "operator-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "operator-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->operator_key, (void*)(""), &config_dtmf_optional , ((void*)0), ((void*)0), ((void*)0)) | ||||||
608 | &profile->operator_key, "", &config_dtmf_optional, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "operator-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->operator_key, (void*)(""), &config_dtmf_optional , ((void*)0), ((void*)0), ((void*)0)); | ||||||
609 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "vmain-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &profile->vmain_key, "", &config_dtmf_optional, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "vmain-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->vmain_key, (void*)(""), &config_dtmf_optional , ((void*)0), ((void*)0), ((void*)0)); | ||||||
610 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "vmain-extension", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "vmain-extension", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &profile->vmain_ext, (void*)(""), &profile->config_str_pool , ((void*)0), ((void*)0), ((void*)0)) | ||||||
611 | &profile->vmain_ext, "", &profile->config_str_pool, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "vmain-extension", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &profile->vmain_ext, (void*)(""), &profile->config_str_pool , ((void*)0), ((void*)0), ((void*)0)); | ||||||
612 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "forward-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "forward-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->forward_key, (void*)("8"), &config_dtmf, ((void *)0), ((void*)0), ((void*)0)) | ||||||
613 | &profile->forward_key, "8", &config_dtmf, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "forward-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->forward_key, (void*)("8"), &config_dtmf, ((void *)0), ((void*)0), ((void*)0)); | ||||||
614 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "prepend-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "prepend-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->prepend_key, (void*)("1"), &config_dtmf, ((void *)0), ((void*)0), ((void*)0)) | ||||||
615 | &profile->prepend_key, "1", &config_dtmf, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "prepend-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->prepend_key, (void*)("1"), &config_dtmf, ((void *)0), ((void*)0), ((void*)0)); | ||||||
616 | |||||||
617 | /* Other settings */ | ||||||
618 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "file-extension", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "file-extension", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->file_ext, (void*)("wav"), &config_file_ext, ( (void*)0), ((void*)0), ((void*)0)) | ||||||
619 | &profile->file_ext, "wav", &config_file_ext, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "file-extension", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->file_ext, (void*)("wav"), &config_file_ext, ( (void*)0), ((void*)0), ((void*)0)); | ||||||
620 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "record-title", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "record-title", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->record_title, (void*)("FreeSWITCH Voicemail"), & profile->config_str_pool, ((void*)0), ((void*)0), ((void*) 0)) | ||||||
621 | &profile->record_title, "FreeSWITCH Voicemail", &profile->config_str_pool, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "record-title", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->record_title, (void*)("FreeSWITCH Voicemail"), & profile->config_str_pool, ((void*)0), ((void*)0), ((void*) 0)); | ||||||
622 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "record-comment", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "record-comment", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->record_comment, (void*)("FreeSWITCH Voicemail"), & profile->config_str_pool, ((void*)0), ((void*)0), ((void*) 0)) | ||||||
623 | &profile->record_comment, "FreeSWITCH Voicemail", &profile->config_str_pool, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "record-comment", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->record_comment, (void*)("FreeSWITCH Voicemail"), & profile->config_str_pool, ((void*)0), ((void*)0), ((void*) 0)); | ||||||
624 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "record-copyright", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "record-copyright", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE , &profile->record_copyright, (void*)("http://www.freeswitch.org" ), &profile->config_str_pool, ((void*)0), ((void*)0), ( (void*)0)) | ||||||
625 | &profile->record_copyright, "http://www.freeswitch.org", &profile->config_str_pool, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "record-copyright", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE , &profile->record_copyright, (void*)("http://www.freeswitch.org" ), &profile->config_str_pool, ((void*)0), ((void*)0), ( (void*)0)); | ||||||
626 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "operator-extension", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "operator-extension", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE , &profile->operator_ext, (void*)(""), &profile-> config_str_pool, ((void*)0), ((void*)0), ((void*)0)) | ||||||
627 | &profile->operator_ext, "", &profile->config_str_pool, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "operator-extension", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE , &profile->operator_ext, (void*)(""), &profile-> config_str_pool, ((void*)0), ((void*)0), ((void*)0)); | ||||||
628 | |||||||
629 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "tone-spec", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "tone-spec", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->tone_spec, (void*)("%(1000, 0, 640)"), &profile ->config_str_pool, ((void*)0), ((void*)0), ((void*)0)) | ||||||
630 | &profile->tone_spec, "%(1000, 0, 640)", &profile->config_str_pool, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "tone-spec", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->tone_spec, (void*)("%(1000, 0, 640)"), &profile ->config_str_pool, ((void*)0), ((void*)0), ((void*)0)); | ||||||
631 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "storage-dir", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "storage-dir", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->storage_dir, (void*)(""), &profile->config_str_pool , ((void*)0), ((void*)0), ((void*)0)) | ||||||
632 | &profile->storage_dir, "", &profile->config_str_pool, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "storage-dir", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->storage_dir, (void*)(""), &profile->config_str_pool , ((void*)0), ((void*)0), ((void*)0)); | ||||||
633 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "storage-dir-shared", SWITCH_CONFIG_BOOL, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "storage-dir-shared", SWITCH_CONFIG_BOOL, CONFIG_RELOADABLE , &profile->storage_dir_shared, (void*)(SWITCH_FALSE), ((void*)0), ((void*)0), ((void*)0), ((void*)0)) | ||||||
634 | &profile->storage_dir_shared, SWITCH_FALSE, NULL, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "storage-dir-shared", SWITCH_CONFIG_BOOL, CONFIG_RELOADABLE , &profile->storage_dir_shared, (void*)(SWITCH_FALSE), ((void*)0), ((void*)0), ((void*)0), ((void*)0)); | ||||||
635 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "callback-dialplan", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "callback-dialplan", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE , &profile->callback_dialplan, (void*)("XML"), &profile ->config_str_pool, ((void*)0), ((void*)0), ((void*)0)) | ||||||
636 | &profile->callback_dialplan, "XML", &profile->config_str_pool, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "callback-dialplan", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE , &profile->callback_dialplan, (void*)("XML"), &profile ->config_str_pool, ((void*)0), ((void*)0), ((void*)0)); | ||||||
637 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "callback-context", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "callback-context", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE , &profile->callback_context, (void*)("default"), & profile->config_str_pool, ((void*)0), ((void*)0), ((void*) 0)) | ||||||
638 | &profile->callback_context, "default", &profile->config_str_pool, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "callback-context", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE , &profile->callback_context, (void*)("default"), & profile->config_str_pool, ((void*)0), ((void*)0), ((void*) 0)); | ||||||
639 | |||||||
640 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "notify-email-body", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "notify-email-body", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE , &profile->notify_email_body, (void*)(((void*)0)), & profile->config_str_pool, ((void*)0), ((void*)0), ((void*) 0)) | ||||||
641 | &profile->notify_email_body, NULL, &profile->config_str_pool, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "notify-email-body", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE , &profile->notify_email_body, (void*)(((void*)0)), & profile->config_str_pool, ((void*)0), ((void*)0), ((void*) 0)); | ||||||
642 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "notify-email-headers", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "notify-email-headers", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE , &profile->notify_email_headers, (void*)(((void*)0)), &profile->config_str_pool, ((void*)0), ((void*)0), (( void*)0)) | ||||||
643 | &profile->notify_email_headers, NULL, &profile->config_str_pool, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "notify-email-headers", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE , &profile->notify_email_headers, (void*)(((void*)0)), &profile->config_str_pool, ((void*)0), ((void*)0), (( void*)0)); | ||||||
644 | |||||||
645 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "play-date-announcement", SWITCH_CONFIG_ENUM, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "play-date-announcement", SWITCH_CONFIG_ENUM, CONFIG_RELOADABLE , &profile->play_date_announcement, (void*)(VM_DATE_FIRST ), &config_play_date_announcement, ((void*)0), ((void*)0) , ((void*)0)) | ||||||
646 | &profile->play_date_announcement, VM_DATE_FIRST, &config_play_date_announcement, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "play-date-announcement", SWITCH_CONFIG_ENUM, CONFIG_RELOADABLE , &profile->play_date_announcement, (void*)(VM_DATE_FIRST ), &config_play_date_announcement, ((void*)0), ((void*)0) , ((void*)0)); | ||||||
647 | |||||||
648 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "convert-cmd", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "convert-cmd", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->convert_cmd, (void*)(((void*)0)), &profile-> config_str_pool, ((void*)0), ((void*)0), ((void*)0)) | ||||||
649 | &profile->convert_cmd, NULL, &profile->config_str_pool, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "convert-cmd", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->convert_cmd, (void*)(((void*)0)), &profile-> config_str_pool, ((void*)0), ((void*)0), ((void*)0)); | ||||||
650 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "convert-ext", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "convert-ext", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->convert_ext, (void*)(((void*)0)), &profile-> config_str_pool, ((void*)0), ((void*)0), ((void*)0)) | ||||||
651 | &profile->convert_ext, NULL, &profile->config_str_pool, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "convert-ext", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->convert_ext, (void*)(((void*)0)), &profile-> config_str_pool, ((void*)0), ((void*)0), ((void*)0)); | ||||||
652 | |||||||
653 | |||||||
654 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "digit-timeout", SWITCH_CONFIG_INT, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "digit-timeout", SWITCH_CONFIG_INT, CONFIG_RELOADABLE, & profile->digit_timeout, (void*)(10000), &config_int_digit_timeout , ((void*)0), ((void*)0), ((void*)0)) | ||||||
655 | &profile->digit_timeout, 10000, &config_int_digit_timeout, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "digit-timeout", SWITCH_CONFIG_INT, CONFIG_RELOADABLE, & profile->digit_timeout, (void*)(10000), &config_int_digit_timeout , ((void*)0), ((void*)0), ((void*)0)); | ||||||
656 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "max-login-attempts", SWITCH_CONFIG_INT, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "max-login-attempts", SWITCH_CONFIG_INT, CONFIG_RELOADABLE, &profile->max_login_attempts, (void*)(3), &config_int_max_logins , ((void*)0), ((void*)0), ((void*)0)) | ||||||
657 | &profile->max_login_attempts, 3, &config_int_max_logins, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "max-login-attempts", SWITCH_CONFIG_INT, CONFIG_RELOADABLE, &profile->max_login_attempts, (void*)(3), &config_int_max_logins , ((void*)0), ((void*)0), ((void*)0)); | ||||||
658 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "min-record-len", SWITCH_CONFIG_INT, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "min-record-len", SWITCH_CONFIG_INT, CONFIG_RELOADABLE, & profile->min_record_len, (void*)(3), &config_int_0_10000 , ((void*)0), "seconds", ((void*)0)) | ||||||
659 | &profile->min_record_len, 3, &config_int_0_10000, "seconds", NULL)switch_config_perform_set_item(&(profile->config[i++]) , "min-record-len", SWITCH_CONFIG_INT, CONFIG_RELOADABLE, & profile->min_record_len, (void*)(3), &config_int_0_10000 , ((void*)0), "seconds", ((void*)0)); | ||||||
660 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "max-record-len", SWITCH_CONFIG_INT, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "max-record-len", SWITCH_CONFIG_INT, CONFIG_RELOADABLE, & profile->max_record_len, (void*)(300), &config_int_0_1000 , ((void*)0), "seconds", ((void*)0)) | ||||||
661 | &profile->max_record_len, 300, &config_int_0_1000, "seconds", NULL)switch_config_perform_set_item(&(profile->config[i++]) , "max-record-len", SWITCH_CONFIG_INT, CONFIG_RELOADABLE, & profile->max_record_len, (void*)(300), &config_int_0_1000 , ((void*)0), "seconds", ((void*)0)); | ||||||
662 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "max-retries", SWITCH_CONFIG_INT, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "max-retries", SWITCH_CONFIG_INT, CONFIG_RELOADABLE, &profile ->max_retries, (void*)(3), &config_int_ht_0, ((void*)0 ), ((void*)0), ((void*)0)) | ||||||
663 | &profile->max_retries, 3, &config_int_ht_0, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "max-retries", SWITCH_CONFIG_INT, CONFIG_RELOADABLE, &profile ->max_retries, (void*)(3), &config_int_ht_0, ((void*)0 ), ((void*)0), ((void*)0)); | ||||||
664 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "record-silence-threshold", SWITCH_CONFIG_INT, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "record-silence-threshold", SWITCH_CONFIG_INT, CONFIG_RELOADABLE , &profile->record_threshold, (void*)(200), &config_int_0_10000 , ((void*)0), ((void*)0), ((void*)0)) | ||||||
665 | &profile->record_threshold, 200, &config_int_0_10000, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "record-silence-threshold", SWITCH_CONFIG_INT, CONFIG_RELOADABLE , &profile->record_threshold, (void*)(200), &config_int_0_10000 , ((void*)0), ((void*)0), ((void*)0)); | ||||||
666 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "record-silence-hits", SWITCH_CONFIG_INT, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "record-silence-hits", SWITCH_CONFIG_INT, CONFIG_RELOADABLE , &profile->record_silence_hits, (void*)(2), &config_int_0_1000 , ((void*)0), ((void*)0), ((void*)0)) | ||||||
667 | &profile->record_silence_hits, 2, &config_int_0_1000, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "record-silence-hits", SWITCH_CONFIG_INT, CONFIG_RELOADABLE , &profile->record_silence_hits, (void*)(2), &config_int_0_1000 , ((void*)0), ((void*)0), ((void*)0)); | ||||||
668 | SWITCH_CONFIG_SET_ITEM_CALLBACK(profile->config[i++], "record-sample-rate", SWITCH_CONFIG_INT, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "record-sample-rate", SWITCH_CONFIG_INT, CONFIG_RELOADABLE, &profile->record_sample_rate, (void*)(0), ((void*)0), vm_config_validate_samplerate, ((void*)0), ((void*)0)) | ||||||
669 | &profile->record_sample_rate, 0, NULL, vm_config_validate_samplerate, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "record-sample-rate", SWITCH_CONFIG_INT, CONFIG_RELOADABLE, &profile->record_sample_rate, (void*)(0), ((void*)0), vm_config_validate_samplerate, ((void*)0), ((void*)0)); | ||||||
670 | |||||||
671 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "email_headers", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "email_headers", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->email_headers, (void*)(((void*)0)), &profile-> config_str_pool, ((void*)0), ((void*)0), ((void*)0)) | ||||||
672 | &profile->email_headers, NULL, &profile->config_str_pool, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "email_headers", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->email_headers, (void*)(((void*)0)), &profile-> config_str_pool, ((void*)0), ((void*)0), ((void*)0)); | ||||||
673 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "email_body", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "email_body", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->email_body, (void*)(((void*)0)), &profile-> config_str_pool, ((void*)0), ((void*)0), ((void*)0)) | ||||||
674 | &profile->email_body, NULL, &profile->config_str_pool, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "email_body", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->email_body, (void*)(((void*)0)), &profile-> config_str_pool, ((void*)0), ((void*)0), ((void*)0)); | ||||||
675 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "email_email-from", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "email_email-from", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE , &profile->email_from, (void*)(((void*)0)), &profile ->config_str_pool, ((void*)0), ((void*)0), ((void*)0)) | ||||||
676 | &profile->email_from, NULL, &profile->config_str_pool, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "email_email-from", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE , &profile->email_from, (void*)(((void*)0)), &profile ->config_str_pool, ((void*)0), ((void*)0), ((void*)0)); | ||||||
677 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "email_date-fmt", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "email_date-fmt", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->date_fmt, (void*)("%A, %B %d %Y, %I:%M %p"), & profile->config_str_pool, ((void*)0), ((void*)0), ((void*) 0)) | ||||||
678 | &profile->date_fmt, "%A, %B %d %Y, %I:%M %p", &profile->config_str_pool, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "email_date-fmt", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, & profile->date_fmt, (void*)("%A, %B %d %Y, %I:%M %p"), & profile->config_str_pool, ((void*)0), ((void*)0), ((void*) 0)); | ||||||
679 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "odbc-dsn", SWITCH_CONFIG_STRING, 0, &profile->odbc_dsn, NULL, &profile->config_str_pool, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "odbc-dsn", SWITCH_CONFIG_STRING, 0, &profile->odbc_dsn , (void*)(((void*)0)), &profile->config_str_pool, ((void *)0), ((void*)0), ((void*)0)); | ||||||
680 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "dbname", SWITCH_CONFIG_STRING, 0, &profile->dbname, NULL, &profile->config_str_pool, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "dbname", SWITCH_CONFIG_STRING, 0, &profile->dbname, (void*)(((void*)0)), &profile->config_str_pool, ((void *)0), ((void*)0), ((void*)0)); | ||||||
681 | SWITCH_CONFIG_SET_ITEM_CALLBACK(profile->config[i++], "email_template-file", SWITCH_CONFIG_CUSTOM, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "email_template-file", SWITCH_CONFIG_CUSTOM, CONFIG_RELOADABLE , ((void*)0), (void*)(((void*)0)), profile, vm_config_email_callback , ((void*)0), ((void*)0)) | ||||||
682 | NULL, NULL, profile, vm_config_email_callback, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "email_template-file", SWITCH_CONFIG_CUSTOM, CONFIG_RELOADABLE , ((void*)0), (void*)(((void*)0)), profile, vm_config_email_callback , ((void*)0), ((void*)0)); | ||||||
683 | SWITCH_CONFIG_SET_ITEM_CALLBACK(profile->config[i++], "email_notify-template-file", SWITCH_CONFIG_CUSTOM, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "email_notify-template-file", SWITCH_CONFIG_CUSTOM, CONFIG_RELOADABLE , ((void*)0), (void*)(((void*)0)), profile, vm_config_notify_callback , ((void*)0), ((void*)0)) | ||||||
684 | NULL, NULL, profile, vm_config_notify_callback, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "email_notify-template-file", SWITCH_CONFIG_CUSTOM, CONFIG_RELOADABLE , ((void*)0), (void*)(((void*)0)), profile, vm_config_notify_callback , ((void*)0), ((void*)0)); | ||||||
685 | SWITCH_CONFIG_SET_ITEM_CALLBACK(profile->config[i++], "web-template-file", SWITCH_CONFIG_CUSTOM, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "web-template-file", SWITCH_CONFIG_CUSTOM, CONFIG_RELOADABLE , ((void*)0), (void*)(((void*)0)), profile, vm_config_web_callback , ((void*)0), ((void*)0)) | ||||||
686 | NULL, NULL, profile, vm_config_web_callback, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "web-template-file", SWITCH_CONFIG_CUSTOM, CONFIG_RELOADABLE , ((void*)0), (void*)(((void*)0)), profile, vm_config_web_callback , ((void*)0), ((void*)0)); | ||||||
687 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "db-password-override", SWITCH_CONFIG_BOOL, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "db-password-override", SWITCH_CONFIG_BOOL, CONFIG_RELOADABLE , &profile->db_password_override, (void*)(SWITCH_FALSE ), ((void*)0), ((void*)0), ((void*)0), ((void*)0)) | ||||||
688 | &profile->db_password_override, SWITCH_FALSE, NULL, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "db-password-override", SWITCH_CONFIG_BOOL, CONFIG_RELOADABLE , &profile->db_password_override, (void*)(SWITCH_FALSE ), ((void*)0), ((void*)0), ((void*)0), ((void*)0)); | ||||||
689 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "allow-empty-password-auth", SWITCH_CONFIG_BOOL, CONFIG_RELOADABLE,switch_config_perform_set_item(&(profile->config[i++]) , "allow-empty-password-auth", SWITCH_CONFIG_BOOL, CONFIG_RELOADABLE , &profile->allow_empty_password_auth, (void*)(SWITCH_TRUE ), ((void*)0), ((void*)0), ((void*)0), ((void*)0)) | ||||||
690 | &profile->allow_empty_password_auth, SWITCH_TRUE, NULL, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "allow-empty-password-auth", SWITCH_CONFIG_BOOL, CONFIG_RELOADABLE , &profile->allow_empty_password_auth, (void*)(SWITCH_TRUE ), ((void*)0), ((void*)0), ((void*)0), ((void*)0)); | ||||||
691 | SWITCH_CONFIG_SET_ITEM(profile->config[i++], "auto-playback-recordings", SWITCH_CONFIG_BOOL, CONFIG_RELOADABLE, &profile->auto_playback_recordings, SWITCH_FALSE, NULL, NULL, NULL)switch_config_perform_set_item(&(profile->config[i++]) , "auto-playback-recordings", SWITCH_CONFIG_BOOL, CONFIG_RELOADABLE , &profile->auto_playback_recordings, (void*)(SWITCH_FALSE ), ((void*)0), ((void*)0), ((void*)0), ((void*)0)); | ||||||
692 | |||||||
693 | switch_assert(i < VM_PROFILE_CONFIGITEM_COUNT)((i < 100) ? (void) (0) : __assert_fail ("i < 100", "mod_voicemail.c" , 693, __PRETTY_FUNCTION__)); | ||||||
694 | |||||||
695 | return profile; | ||||||
696 | |||||||
697 | } | ||||||
698 | |||||||
699 | static vm_profile_t *load_profile(const char *profile_name) | ||||||
700 | { | ||||||
701 | vm_profile_t *profile = NULL((void*)0); | ||||||
702 | switch_xml_t x_profiles, x_profile, cfg, xml, x_email, param; | ||||||
703 | switch_event_t *event = NULL((void*)0); | ||||||
704 | switch_cache_db_handle_t *dbh = NULL((void*)0); | ||||||
705 | |||||||
706 | if (!(xml = switch_xml_open_cfg(global_cf, &cfg, NULL((void*)0)))) { | ||||||
707 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 707, ((void*)0), SWITCH_LOG_ERROR, "Open of %s failed\n", global_cf); | ||||||
708 | return profile; | ||||||
709 | } | ||||||
710 | if (!(x_profiles = switch_xml_child(cfg, "profiles"))) { | ||||||
711 | goto end; | ||||||
712 | } | ||||||
713 | |||||||
714 | if ((x_profile = switch_xml_find_child(x_profiles, "profile", "name", profile_name))) { | ||||||
715 | switch_memory_pool_t *pool; | ||||||
716 | int x; | ||||||
717 | switch_size_t count; | ||||||
718 | char *errmsg; | ||||||
719 | |||||||
720 | if (switch_core_new_memory_pool(&pool)switch_core_perform_new_memory_pool(&pool, "mod_voicemail.c" , (const char *)__func__, 720) != SWITCH_STATUS_SUCCESS) { | ||||||
721 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 721, ((void*)0), SWITCH_LOG_CRIT, "Pool Failure\n"); | ||||||
722 | goto end; | ||||||
723 | } | ||||||
724 | |||||||
725 | if (!(profile = switch_core_alloc(pool, sizeof(vm_profile_t))switch_core_perform_alloc(pool, sizeof(vm_profile_t), "mod_voicemail.c" , (const char *)__func__, 725))) { | ||||||
726 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 726, ((void*)0), SWITCH_LOG_CRIT, "Alloc Failure\n"); | ||||||
727 | switch_core_destroy_memory_pool(&pool)switch_core_perform_destroy_memory_pool(&pool, "mod_voicemail.c" , (const char *)__func__, 727); | ||||||
728 | goto end; | ||||||
729 | } | ||||||
730 | |||||||
731 | profile->pool = pool; | ||||||
732 | profile_set_config(profile); | ||||||
733 | |||||||
734 | /* Add the params to the event structure */ | ||||||
735 | count = switch_event_import_xml(switch_xml_child(x_profile, "param"), "name", "value", &event); | ||||||
736 | |||||||
737 | /* Take care of the custom config structure */ | ||||||
738 | if ((x_email = switch_xml_child(x_profile, "email"))) { | ||||||
739 | if ((param = switch_xml_child(x_email, "body"))) { | ||||||
740 | switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "email_body", param->txt); | ||||||
741 | } | ||||||
742 | if ((param = switch_xml_child(x_email, "headers"))) { | ||||||
743 | switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "email_headers", param->txt); | ||||||
744 | } | ||||||
745 | |||||||
746 | for (param = switch_xml_child(x_email, "param"); param; param = param->next) { | ||||||
747 | char *var, *val; | ||||||
748 | char buf[2048]; | ||||||
749 | |||||||
750 | if ((var = (char *) switch_xml_attr_soft(param, "name")) && (val = (char *) switch_xml_attr_soft(param, "value"))) { | ||||||
751 | switch_snprintf(buf, 2048, "email_%s", var); | ||||||
752 | switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, buf, val); | ||||||
753 | } | ||||||
754 | } | ||||||
755 | } | ||||||
756 | |||||||
757 | |||||||
758 | if (switch_xml_config_parse_event(event, (int)count, SWITCH_FALSE, profile->config) != SWITCH_STATUS_SUCCESS) { | ||||||
759 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 759, ((void*)0), SWITCH_LOG_ERROR, "Failed to process configuration\n"); | ||||||
760 | switch_core_destroy_memory_pool(&pool)switch_core_perform_destroy_memory_pool(&pool, "mod_voicemail.c" , (const char *)__func__, 760); | ||||||
761 | goto end; | ||||||
762 | } | ||||||
763 | |||||||
764 | switch_thread_rwlock_create(&profile->rwlock, pool); | ||||||
765 | profile->name = switch_core_strdup(pool, profile_name)switch_core_perform_strdup(pool, profile_name, "mod_voicemail.c" , (const char *)__func__, 765); | ||||||
766 | |||||||
767 | if (zstr(profile->dbname)_zstr(profile->dbname)) { | ||||||
768 | profile->dbname = switch_core_sprintf(profile->pool, "voicemail_%s", profile_name); | ||||||
769 | } | ||||||
770 | |||||||
771 | if (!(dbh = vm_get_db_handle(profile))) { | ||||||
772 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 772, ((void*)0), SWITCH_LOG_CRIT, "Cannot open DB!\n"); | ||||||
773 | goto end; | ||||||
774 | } | ||||||
775 | |||||||
776 | switch_cache_db_test_reactive(dbh, "select count(forwarded_by) from voicemail_msgs", NULL((void*)0), | ||||||
777 | "alter table voicemail_msgs add forwarded_by varchar(255)"); | ||||||
778 | switch_cache_db_test_reactive(dbh, "select count(forwarded_by) from voicemail_msgs", "drop table voicemail_msgs", vm_sql); | ||||||
779 | |||||||
780 | switch_cache_db_test_reactive(dbh, "select count(username) from voicemail_prefs", "drop table voicemail_prefs", vm_pref_sql); | ||||||
781 | switch_cache_db_test_reactive(dbh, "select count(password) from voicemail_prefs", NULL((void*)0), "alter table voicemail_prefs add password varchar(255)"); | ||||||
782 | |||||||
783 | for (x = 0; vm_index_list[x]; x++) { | ||||||
784 | errmsg = NULL((void*)0); | ||||||
785 | switch_cache_db_execute_sql(dbh, vm_index_list[x], &errmsg); | ||||||
786 | switch_safe_free(errmsg)if (errmsg) {free(errmsg);errmsg=((void*)0);}; | ||||||
787 | } | ||||||
788 | |||||||
789 | switch_cache_db_release_db_handle(&dbh); | ||||||
790 | |||||||
791 | switch_mutex_init(&profile->mutex, SWITCH_MUTEX_NESTED0x1, profile->pool); | ||||||
792 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 792, ((void*)0), SWITCH_LOG_INFO, "Added Profile %s\n", profile->name); | ||||||
793 | switch_core_hash_insert(globals.profile_hash, profile->name, profile)switch_core_hash_insert_destructor(globals.profile_hash, profile ->name, profile, ((void*)0)); | ||||||
794 | } | ||||||
795 | |||||||
796 | end: | ||||||
797 | |||||||
798 | switch_cache_db_release_db_handle(&dbh); | ||||||
799 | |||||||
800 | if (xml) { | ||||||
801 | switch_xml_free(xml); | ||||||
802 | } | ||||||
803 | if (event) { | ||||||
804 | switch_event_destroy(&event); | ||||||
805 | } | ||||||
806 | return profile; | ||||||
807 | } | ||||||
808 | |||||||
809 | |||||||
810 | static vm_profile_t *get_profile(const char *profile_name) | ||||||
811 | { | ||||||
812 | vm_profile_t *profile = NULL((void*)0); | ||||||
813 | |||||||
814 | switch_mutex_lock(globals.mutex); | ||||||
815 | if (!(profile = switch_core_hash_find(globals.profile_hash, profile_name))) { | ||||||
816 | profile = load_profile(profile_name); | ||||||
817 | } | ||||||
818 | if (profile) { | ||||||
819 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 819, ((void*)0), SWITCH_LOG_DEBUG10, "[%s] rwlock\n", profile->name); | ||||||
820 | |||||||
821 | switch_thread_rwlock_rdlock(profile->rwlock); | ||||||
822 | } | ||||||
823 | switch_mutex_unlock(globals.mutex); | ||||||
824 | |||||||
825 | return profile; | ||||||
826 | } | ||||||
827 | |||||||
828 | static void profile_rwunlock(vm_profile_t *profile) | ||||||
829 | { | ||||||
830 | switch_thread_rwlock_unlock(profile->rwlock); | ||||||
831 | if (switch_test_flag(profile, PFLAG_DESTROY)((profile)->flags & PFLAG_DESTROY)) { | ||||||
832 | if (switch_thread_rwlock_trywrlock(profile->rwlock) == SWITCH_STATUS_SUCCESS) { | ||||||
833 | switch_thread_rwlock_unlock(profile->rwlock); | ||||||
834 | free_profile(profile); | ||||||
835 | } | ||||||
836 | } | ||||||
837 | } | ||||||
838 | |||||||
839 | |||||||
840 | static switch_status_t load_config(void) | ||||||
841 | { | ||||||
842 | switch_xml_t cfg, xml, settings, param, x_profiles, x_profile; | ||||||
843 | |||||||
844 | if (!(xml = switch_xml_open_cfg(global_cf, &cfg, NULL((void*)0)))) { | ||||||
845 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 845, ((void*)0), SWITCH_LOG_ERROR, "Open of %s failed\n", global_cf); | ||||||
846 | return SWITCH_STATUS_TERM; | ||||||
847 | } | ||||||
848 | |||||||
849 | switch_mutex_lock(globals.mutex); | ||||||
850 | if ((settings = switch_xml_child(cfg, "settings"))) { | ||||||
851 | for (param = switch_xml_child(settings, "param"); param; param = param->next) { | ||||||
852 | char *var = (char *) switch_xml_attr_soft(param, "name"); | ||||||
853 | char *val = (char *) switch_xml_attr_soft(param, "value"); | ||||||
854 | |||||||
855 | if (!strcasecmp(var, "debug")) { | ||||||
856 | globals.debug = atoi(val); | ||||||
857 | } else if (!strcasecmp(var, "message-query-exact-match")) { | ||||||
858 | globals.message_query_exact_match = switch_true(val); | ||||||
859 | } | ||||||
860 | } | ||||||
861 | } | ||||||
862 | |||||||
863 | if ((x_profiles = switch_xml_child(cfg, "profiles"))) { | ||||||
864 | for (x_profile = switch_xml_child(x_profiles, "profile"); x_profile; x_profile = x_profile->next) { | ||||||
865 | load_profile(switch_xml_attr_soft(x_profile, "name")); | ||||||
866 | } | ||||||
867 | } | ||||||
868 | switch_mutex_unlock(globals.mutex); | ||||||
869 | |||||||
870 | switch_xml_free(xml); | ||||||
871 | return SWITCH_STATUS_SUCCESS; | ||||||
872 | } | ||||||
873 | |||||||
874 | |||||||
875 | static switch_status_t cancel_on_dtmf(switch_core_session_t *session, void *input, switch_input_type_t itype, void *buf, unsigned int buflen) | ||||||
876 | { | ||||||
877 | switch (itype) { | ||||||
878 | case SWITCH_INPUT_TYPE_DTMF: | ||||||
879 | { | ||||||
880 | switch_dtmf_t *dtmf = (switch_dtmf_t *) input; | ||||||
881 | if (buf && buflen) { | ||||||
882 | char *bp = (char *) buf; | ||||||
883 | bp[0] = dtmf->digit; | ||||||
884 | bp[1] = '\0'; | ||||||
885 | } | ||||||
886 | return SWITCH_STATUS_BREAK; | ||||||
887 | } | ||||||
888 | break; | ||||||
889 | default: | ||||||
890 | break; | ||||||
891 | } | ||||||
892 | |||||||
893 | return SWITCH_STATUS_SUCCESS; | ||||||
894 | } | ||||||
895 | |||||||
896 | |||||||
897 | struct call_control { | ||||||
898 | vm_profile_t *profile; | ||||||
899 | switch_file_handle_t *fh; | ||||||
900 | char buf[4]; | ||||||
901 | int noexit; | ||||||
902 | int playback_controls_active; | ||||||
903 | }; | ||||||
904 | typedef struct call_control cc_t; | ||||||
905 | |||||||
906 | static switch_status_t control_playback(switch_core_session_t *session, void *input, switch_input_type_t itype, void *buf, unsigned int buflen) | ||||||
907 | { | ||||||
908 | switch (itype) { | ||||||
909 | case SWITCH_INPUT_TYPE_DTMF: | ||||||
910 | { | ||||||
911 | switch_dtmf_t *dtmf = (switch_dtmf_t *) input; | ||||||
912 | cc_t *cc = (cc_t *) buf; | ||||||
913 | switch_file_handle_t *fh = cc->fh; | ||||||
914 | uint32_t pos = 0; | ||||||
915 | |||||||
916 | if (!cc->noexit | ||||||
917 | && (dtmf->digit == *cc->profile->delete_file_key || dtmf->digit == *cc->profile->save_file_key | ||||||
918 | || dtmf->digit == *cc->profile->prev_msg_key || dtmf->digit == *cc->profile->next_msg_key | ||||||
919 | || dtmf->digit == *cc->profile->repeat_msg_key | ||||||
920 | || dtmf->digit == *cc->profile->terminator_key || dtmf->digit == *cc->profile->skip_info_key | ||||||
921 | || dtmf->digit == *cc->profile->forward_key)) { | ||||||
922 | *cc->buf = dtmf->digit; | ||||||
923 | return SWITCH_STATUS_BREAK; | ||||||
924 | } | ||||||
925 | |||||||
926 | if (!cc->playback_controls_active | ||||||
927 | && (dtmf->digit == *cc->profile->email_key)) { | ||||||
928 | *cc->buf = dtmf->digit; | ||||||
929 | return SWITCH_STATUS_BREAK; | ||||||
930 | } | ||||||
931 | |||||||
932 | if (!(fh && fh->file_interface && switch_test_flag(fh, SWITCH_FILE_OPEN)((fh)->flags & SWITCH_FILE_OPEN))) { | ||||||
933 | return SWITCH_STATUS_SUCCESS; | ||||||
934 | } | ||||||
935 | |||||||
936 | if (dtmf->digit == *cc->profile->pause_key) { | ||||||
937 | if (switch_test_flag(fh, SWITCH_FILE_PAUSE)((fh)->flags & SWITCH_FILE_PAUSE)) { | ||||||
938 | switch_clear_flag(fh, SWITCH_FILE_PAUSE)(fh)->flags &= ~(SWITCH_FILE_PAUSE); | ||||||
939 | } else { | ||||||
940 | switch_set_flag(fh, SWITCH_FILE_PAUSE)(fh)->flags |= (SWITCH_FILE_PAUSE); | ||||||
941 | } | ||||||
942 | return SWITCH_STATUS_SUCCESS; | ||||||
943 | } | ||||||
944 | |||||||
945 | if (dtmf->digit == *cc->profile->restart_key) { | ||||||
946 | unsigned int seekpos = 0; | ||||||
947 | fh->speed = 0; | ||||||
948 | switch_core_file_seek(fh, &seekpos, 0, SEEK_SET0); | ||||||
949 | return SWITCH_STATUS_SUCCESS; | ||||||
950 | } | ||||||
951 | |||||||
952 | if (dtmf->digit == *cc->profile->ff_key) { | ||||||
953 | int samps = 24000; | ||||||
954 | switch_core_file_seek(fh, &pos, samps, SEEK_CUR1); | ||||||
955 | return SWITCH_STATUS_SUCCESS; | ||||||
956 | } | ||||||
957 | |||||||
958 | if (dtmf->digit == *cc->profile->rew_key) { | ||||||
959 | int samps = -48000; | ||||||
960 | int target_pos = fh->offset_pos + samps; | ||||||
961 | if (target_pos < 1) { | ||||||
962 | /* too close to beginning of the file, just restart instead of rewind */ | ||||||
963 | unsigned int seekpos = 0; | ||||||
964 | fh->speed = 0; | ||||||
965 | switch_core_file_seek(fh, &seekpos, 0, SEEK_SET0); | ||||||
966 | return SWITCH_STATUS_SUCCESS; | ||||||
967 | } else { | ||||||
968 | switch_core_file_seek(fh, &pos, samps, SEEK_CUR1); | ||||||
969 | return SWITCH_STATUS_SUCCESS; | ||||||
970 | } | ||||||
971 | } | ||||||
972 | } | ||||||
973 | break; | ||||||
974 | default: | ||||||
975 | break; | ||||||
976 | } | ||||||
977 | |||||||
978 | return SWITCH_STATUS_SUCCESS; | ||||||
979 | } | ||||||
980 | |||||||
981 | struct prefs_callback { | ||||||
982 | char name_path[255]; | ||||||
983 | char greeting_path[255]; | ||||||
984 | char password[255]; | ||||||
985 | }; | ||||||
986 | typedef struct prefs_callback prefs_callback_t; | ||||||
987 | |||||||
988 | static int prefs_callback(void *pArg, int argc, char **argv, char **columnNames) | ||||||
989 | { | ||||||
990 | prefs_callback_t *cbt = (prefs_callback_t *) pArg; | ||||||
991 | |||||||
992 | switch_copy_string(cbt->name_path, argv[2], sizeof(cbt->name_path)); | ||||||
993 | switch_copy_string(cbt->greeting_path, argv[3], sizeof(cbt->greeting_path)); | ||||||
994 | switch_copy_string(cbt->password, argv[4], sizeof(cbt->password)); | ||||||
995 | |||||||
996 | return 0; | ||||||
997 | } | ||||||
998 | |||||||
999 | |||||||
1000 | typedef enum { | ||||||
1001 | VM_CHECK_START, | ||||||
1002 | VM_CHECK_AUTH, | ||||||
1003 | VM_CHECK_MENU, | ||||||
1004 | VM_CHECK_CONFIG, | ||||||
1005 | VM_CHECK_PLAY_MESSAGES, | ||||||
1006 | VM_CHECK_FOLDER_SUMMARY, | ||||||
1007 | VM_CHECK_LISTEN | ||||||
1008 | } vm_check_state_t; | ||||||
1009 | |||||||
1010 | |||||||
1011 | #define VM_INVALID_EXTENSION_MACRO"voicemail_invalid_extension" "voicemail_invalid_extension" | ||||||
1012 | #define VM_FORWARD_MESSAGE_ENTER_EXTENSION_MACRO"voicemail_forward_message_enter_extension" "voicemail_forward_message_enter_extension" | ||||||
1013 | #define VM_ACK_MACRO"voicemail_ack" "voicemail_ack" | ||||||
1014 | #define VM_SAY_DATE_MACRO"voicemail_say_date" "voicemail_say_date" | ||||||
1015 | #define VM_PLAY_GREETING_MACRO"voicemail_play_greeting" "voicemail_play_greeting" | ||||||
1016 | #define VM_SAY_MESSAGE_NUMBER_MACRO"voicemail_say_message_number" "voicemail_say_message_number" | ||||||
1017 | #define VM_SAY_NUMBER_MACRO"voicemail_say_number" "voicemail_say_number" | ||||||
1018 | #define VM_SAY_PHONE_NUMBER_MACRO"voicemail_say_phone_number" "voicemail_say_phone_number" | ||||||
1019 | #define VM_SAY_NAME_MACRO"voicemail_say_name" "voicemail_say_name" | ||||||
1020 | |||||||
1021 | #define VM_FORWARD_PREPEND_MACRO"voicemail_forward_prepend" "voicemail_forward_prepend" | ||||||
1022 | #define VM_RECORD_MESSAGE_MACRO"voicemail_record_message" "voicemail_record_message" | ||||||
1023 | #define VM_CHOOSE_GREETING_MACRO"voicemail_choose_greeting" "voicemail_choose_greeting" | ||||||
1024 | #define VM_CHOOSE_GREETING_FAIL_MACRO"voicemail_choose_greeting_fail" "voicemail_choose_greeting_fail" | ||||||
1025 | #define VM_CHOOSE_GREETING_SELECTED_MACRO"voicemail_greeting_selected" "voicemail_greeting_selected" | ||||||
1026 | #define VM_RECORD_GREETING_MACRO"voicemail_record_greeting" "voicemail_record_greeting" | ||||||
1027 | #define VM_RECORD_NAME_MACRO"voicemail_record_name" "voicemail_record_name" | ||||||
1028 | #define VM_LISTEN_FILE_CHECK_MACRO"voicemail_listen_file_check" "voicemail_listen_file_check" | ||||||
1029 | #define VM_RECORD_FILE_CHECK_MACRO"voicemail_record_file_check" "voicemail_record_file_check" | ||||||
1030 | #define VM_RECORD_URGENT_CHECK_MACRO"voicemail_record_urgent_check" "voicemail_record_urgent_check" | ||||||
1031 | #define VM_MENU_MACRO"voicemail_menu" "voicemail_menu" | ||||||
1032 | #define VM_CONFIG_MENU_MACRO"voicemail_config_menu" "voicemail_config_menu" | ||||||
1033 | #define VM_ENTER_ID_MACRO"voicemail_enter_id" "voicemail_enter_id" | ||||||
1034 | #define VM_ENTER_PASS_MACRO"voicemail_enter_pass" "voicemail_enter_pass" | ||||||
1035 | #define VM_FAIL_AUTH_MACRO"voicemail_fail_auth" "voicemail_fail_auth" | ||||||
1036 | #define VM_CHANGE_PASS_SUCCESS_MACRO"voicemail_change_pass_success" "voicemail_change_pass_success" | ||||||
1037 | #define VM_CHANGE_PASS_FAIL_MACRO"voicemail_change_pass_fail" "voicemail_change_pass_fail" | ||||||
1038 | #define VM_ABORT_MACRO"voicemail_abort" "voicemail_abort" | ||||||
1039 | #define VM_HELLO_MACRO"voicemail_hello" "voicemail_hello" | ||||||
1040 | #define VM_GOODBYE_MACRO"voicemail_goodbye" "voicemail_goodbye" | ||||||
1041 | #define VM_MESSAGE_COUNT_MACRO"voicemail_message_count" "voicemail_message_count" | ||||||
1042 | #define VM_DISK_QUOTA_EXCEEDED_MACRO"voicemail_disk_quota_exceeded" "voicemail_disk_quota_exceeded" | ||||||
1043 | #define URGENT_FLAG_STRING"A_URGENT" "A_URGENT" | ||||||
1044 | #define NORMAL_FLAG_STRING"B_NORMAL" "B_NORMAL" | ||||||
1045 | |||||||
1046 | static switch_status_t vm_macro_get(switch_core_session_t *session, | ||||||
1047 | char *macro, | ||||||
1048 | char *macro_arg, | ||||||
1049 | char *buf, switch_size_t buflen, switch_size_t maxlen, char *term_chars, char *terminator_key, uint32_t timeout) | ||||||
1050 | { | ||||||
1051 | switch_input_args_t args = { 0 }, *ap = NULL((void*)0); | ||||||
1052 | switch_status_t status = SWITCH_STATUS_SUCCESS; | ||||||
1053 | switch_size_t bslen; | ||||||
1054 | |||||||
1055 | if (buf && buflen) { | ||||||
1056 | memset(buf, 0, buflen); | ||||||
1057 | args.input_callback = cancel_on_dtmf; | ||||||
1058 | args.buf = buf; | ||||||
1059 | args.buflen = (uint32_t) buflen; | ||||||
1060 | ap = &args; | ||||||
1061 | } | ||||||
1062 | |||||||
1063 | status = switch_ivr_phrase_macro(session, macro, macro_arg, NULL, ap)switch_ivr_phrase_macro_event(session, macro, macro_arg, ((void *)0), ((void*)0), ap); | ||||||
1064 | |||||||
1065 | if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) { | ||||||
1066 | if (buf) { | ||||||
1067 | memset(buf, 0, buflen); | ||||||
1068 | } | ||||||
1069 | return status; | ||||||
1070 | } | ||||||
1071 | |||||||
1072 | if (!buf) { | ||||||
1073 | return status; | ||||||
1074 | } | ||||||
1075 | |||||||
1076 | bslen = strlen(buf); | ||||||
1077 | |||||||
1078 | if (maxlen == 0 || maxlen > buflen - 1) { | ||||||
1079 | maxlen = buflen - 1; | ||||||
1080 | } | ||||||
1081 | |||||||
1082 | if (bslen < maxlen) { | ||||||
1083 | status = switch_ivr_collect_digits_count(session, buf + bslen, buflen, maxlen - bslen, term_chars, terminator_key, timeout, 0, 0); | ||||||
1084 | if (status == SWITCH_STATUS_TIMEOUT) { | ||||||
1085 | status = SWITCH_STATUS_SUCCESS; | ||||||
1086 | } | ||||||
1087 | } | ||||||
1088 | |||||||
1089 | return status; | ||||||
1090 | } | ||||||
1091 | |||||||
1092 | struct callback { | ||||||
1093 | char *buf; | ||||||
1094 | size_t len; | ||||||
1095 | int matches; | ||||||
1096 | }; | ||||||
1097 | typedef struct callback callback_t; | ||||||
1098 | |||||||
1099 | struct msg_cnt_callback { | ||||||
1100 | char *buf; | ||||||
1101 | size_t len; | ||||||
1102 | int matches; | ||||||
1103 | int total_new_messages; | ||||||
1104 | int total_new_urgent_messages; | ||||||
1105 | int total_saved_messages; | ||||||
1106 | int total_saved_urgent_messages; | ||||||
1107 | }; | ||||||
1108 | typedef struct msg_cnt_callback msg_cnt_callback_t; | ||||||
1109 | |||||||
1110 | |||||||
1111 | static int message_count_callback(void *pArg, int argc, char **argv, char **columnNames) | ||||||
1112 | { | ||||||
1113 | msg_cnt_callback_t *cbt = (msg_cnt_callback_t *) pArg; | ||||||
1114 | |||||||
1115 | if (argc < 3 || zstr(argv[0])_zstr(argv[0]) || zstr(argv[1])_zstr(argv[1]) || zstr(argv[2])_zstr(argv[2])) { | ||||||
1116 | return -1; | ||||||
1117 | } | ||||||
1118 | |||||||
1119 | if (atoi(argv[0]) == 1) { /* UnRead */ | ||||||
1120 | if (!strcasecmp(argv[1], "A_URGENT")) { /* Urgent */ | ||||||
1121 | cbt->total_new_urgent_messages = atoi(argv[2]); | ||||||
1122 | } else { /* Normal */ | ||||||
1123 | cbt->total_new_messages = atoi(argv[2]); | ||||||
1124 | } | ||||||
1125 | } else { /* Already Read */ | ||||||
1126 | if (!strcasecmp(argv[1], "A_URGENT")) { /* Urgent */ | ||||||
1127 | cbt->total_saved_urgent_messages = atoi(argv[2]); | ||||||
1128 | } else { /* Normal */ | ||||||
1129 | cbt->total_saved_messages = atoi(argv[2]); | ||||||
1130 | } | ||||||
1131 | } | ||||||
1132 | |||||||
1133 | return 0; | ||||||
1134 | } | ||||||
1135 | |||||||
1136 | static int sql2str_callback(void *pArg, int argc, char **argv, char **columnNames) | ||||||
1137 | { | ||||||
1138 | callback_t *cbt = (callback_t *) pArg; | ||||||
1139 | |||||||
1140 | switch_copy_string(cbt->buf, argv[0], cbt->len); | ||||||
1141 | cbt->matches++; | ||||||
1142 | return 0; | ||||||
1143 | } | ||||||
1144 | |||||||
1145 | |||||||
1146 | static int unlink_callback(void *pArg, int argc, char **argv, char **columnNames) | ||||||
1147 | { | ||||||
1148 | if (argv[0]) { | ||||||
1149 | if (unlink(argv[0]) != 0) { | ||||||
1150 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 1150, ((void*)0), SWITCH_LOG_WARNING, "Failed to delete file [%s]\n", argv[0]); | ||||||
1151 | } | ||||||
1152 | } | ||||||
1153 | return 0; | ||||||
1154 | } | ||||||
1155 | |||||||
1156 | |||||||
1157 | typedef enum { | ||||||
1158 | MSG_NONE, | ||||||
1159 | MSG_NEW, | ||||||
1160 | MSG_SAVED | ||||||
1161 | } msg_type_t; | ||||||
1162 | |||||||
1163 | |||||||
1164 | switch_status_t measure_file_len(const char *path, switch_size_t *message_len) | ||||||
1165 | { | ||||||
1166 | |||||||
1167 | switch_file_handle_t fh = { 0 }; | ||||||
1168 | uint32_t pos = 0; | ||||||
1169 | switch_status_t status = SWITCH_STATUS_FALSE; | ||||||
1170 | |||||||
1171 | if (switch_core_file_open(&fh, path, 0, 0, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL)switch_core_perform_file_open("mod_voicemail.c", (const char * )__func__, 1171, &fh, path, 0, 0, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, ((void*)0)) == SWITCH_STATUS_SUCCESS) { | ||||||
1172 | |||||||
1173 | if (switch_core_file_seek(&fh, &pos, 0, SEEK_END2) == SWITCH_STATUS_SUCCESS) { | ||||||
1174 | *message_len = pos / fh.samplerate; | ||||||
1175 | status = SWITCH_STATUS_SUCCESS; | ||||||
1176 | } | ||||||
1177 | switch_core_file_close(&fh); | ||||||
1178 | } | ||||||
1179 | |||||||
1180 | return status; | ||||||
1181 | |||||||
1182 | } | ||||||
1183 | |||||||
1184 | static switch_status_t create_file(switch_core_session_t *session, vm_profile_t *profile, | ||||||
1185 | char *macro_name, char *file_path, switch_size_t *message_len, switch_bool_t limit, | ||||||
1186 | const char *exit_keys, char *key_pressed) | ||||||
1187 | { | ||||||
1188 | switch_channel_t *channel = switch_core_session_get_channel(session); | ||||||
1189 | switch_status_t status = SWITCH_STATUS_SUCCESS; | ||||||
1190 | switch_file_handle_t fh = { 0 }; | ||||||
1191 | switch_input_args_t args = { 0 }; | ||||||
1192 | char term; | ||||||
1193 | char input[10] = "", key_buf[80] = ""; | ||||||
1194 | cc_t cc = { 0 }; | ||||||
1195 | switch_codec_implementation_t read_impl = { 0 }; | ||||||
1196 | int got_file = 0; | ||||||
1197 | switch_bool_t skip_record_check = switch_true(switch_channel_get_variable(channel, "skip_record_check")switch_channel_get_variable_dup(channel, "skip_record_check", SWITCH_TRUE, -1)); | ||||||
1198 | |||||||
1199 | switch_core_session_get_read_impl(session, &read_impl); | ||||||
1200 | |||||||
1201 | |||||||
1202 | if (exit_keys) { | ||||||
1203 | *key_pressed = '\0'; | ||||||
1204 | } | ||||||
1205 | |||||||
1206 | while (switch_channel_ready(channel)switch_channel_test_ready(channel, SWITCH_TRUE, SWITCH_FALSE)) { | ||||||
1207 | uint32_t counter = 0; | ||||||
1208 | switch_snprintf(key_buf, sizeof(key_buf), "%s:%s:%s", profile->listen_file_key, profile->save_file_key, profile->record_file_key); | ||||||
1209 | |||||||
1210 | record_file: | ||||||
1211 | *message_len = 0; | ||||||
1212 | |||||||
1213 | if (macro_name) | ||||||
1214 | TRY_CODE(switch_ivr_phrase_macro(session, macro_name, NULL, NULL, NULL))do { status = switch_ivr_phrase_macro_event(session, macro_name , ((void*)0), ((void*)0), ((void*)0), ((void*)0)); if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK ) { goto end; } break;} while(status); | ||||||
1215 | switch_channel_flush_dtmf(channel); | ||||||
1216 | TRY_CODE(switch_ivr_gentones(session, profile->tone_spec, 0, NULL))do { status = switch_ivr_gentones(session, profile->tone_spec , 0, ((void*)0)); if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) { goto end; } break;} while(status ); | ||||||
1217 | |||||||
1218 | memset(&fh, 0, sizeof(fh)); | ||||||
1219 | fh.thresh = profile->record_threshold; | ||||||
1220 | fh.silence_hits = profile->record_silence_hits; | ||||||
1221 | fh.samplerate = profile->record_sample_rate; | ||||||
1222 | |||||||
1223 | memset(input, 0, sizeof(input)); | ||||||
1224 | args.input_callback = cancel_on_dtmf; | ||||||
1225 | args.buf = input; | ||||||
1226 | args.buflen = sizeof(input); | ||||||
1227 | |||||||
1228 | unlink(file_path); | ||||||
1229 | |||||||
1230 | switch_ivr_record_file(session, &fh, file_path, &args, profile->max_record_len); | ||||||
1231 | |||||||
1232 | if (switch_file_exists(file_path, switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) { | ||||||
1233 | got_file = 1; | ||||||
1234 | } | ||||||
1235 | |||||||
1236 | if (limit && (*message_len = fh.samples_out / (fh.samplerate ? fh.samplerate : 8000)) < profile->min_record_len) { | ||||||
1237 | if (unlink(file_path) != 0) { | ||||||
1238 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "mod_voicemail.c", (const char *)__func__ , 1238, (const char*)(session), SWITCH_LOG_WARNING, "Failed to delete file [%s]\n", file_path); | ||||||
1239 | } | ||||||
1240 | got_file = 0; | ||||||
1241 | if (exit_keys && input[0] && strchr(exit_keys, input[0])(__extension__ (__builtin_constant_p (input[0]) && !__builtin_constant_p (exit_keys) && (input[0]) == '\0' ? (char *) __rawmemchr (exit_keys, input[0]) : __builtin_strchr (exit_keys, input[0 ])))) { | ||||||
1242 | *key_pressed = input[0]; | ||||||
1243 | return SWITCH_STATUS_SUCCESS; | ||||||
1244 | } | ||||||
1245 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "mod_voicemail.c", (const char *)__func__ , 1245, (const char*)(session), SWITCH_LOG_DEBUG, "Message is less than minimum record length: %d, discarding it.\n", | ||||||
1246 | profile->min_record_len); | ||||||
1247 | if (switch_channel_ready(channel)switch_channel_test_ready(channel, SWITCH_TRUE, SWITCH_FALSE) && counter < profile->max_retries) { | ||||||
1248 | TRY_CODE(switch_ivr_phrase_macro(session, VM_ACK_MACRO, "too-small", NULL, NULL))do { status = switch_ivr_phrase_macro_event(session, "voicemail_ack" , "too-small", ((void*)0), ((void*)0), ((void*)0)); if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK ) { goto end; } break;} while(status); | ||||||
1249 | counter++; | ||||||
1250 | goto record_file; | ||||||
1251 | } else { | ||||||
1252 | status = SWITCH_STATUS_NOTFOUND; | ||||||
1253 | goto end; | ||||||
1254 | } | ||||||
1255 | } else { | ||||||
1256 | status = SWITCH_STATUS_SUCCESS; | ||||||
1257 | } | ||||||
1258 | |||||||
1259 | if (profile->auto_playback_recordings) { | ||||||
1260 | play_file: | ||||||
1261 | memset(&fh, 0, sizeof(fh)); | ||||||
1262 | args.input_callback = control_playback; | ||||||
1263 | memset(&cc, 0, sizeof(cc)); | ||||||
1264 | cc.profile = profile; | ||||||
1265 | cc.fh = &fh; | ||||||
1266 | args.buf = &cc; | ||||||
1267 | switch_ivr_play_file(session, &fh, file_path, &args); | ||||||
1268 | } | ||||||
1269 | while (switch_channel_ready(channel)switch_channel_test_ready(channel, SWITCH_TRUE, SWITCH_FALSE)) { | ||||||
1270 | *input = '\0'; | ||||||
1271 | |||||||
1272 | if (*cc.buf && *cc.buf != *profile->terminator_key) { | ||||||
1273 | *input = *cc.buf; | ||||||
1274 | *(input + 1) = '\0'; | ||||||
1275 | status = SWITCH_STATUS_SUCCESS; | ||||||
1276 | *cc.buf = '\0'; | ||||||
1277 | } else if (skip_record_check) { | ||||||
1278 | /* Skip the record check and simply return */ | ||||||
1279 | goto end; | ||||||
1280 | } else { | ||||||
1281 | (void) vm_macro_get(session, VM_RECORD_FILE_CHECK_MACRO"voicemail_record_file_check", key_buf, input, sizeof(input), 1, "", &term, profile->digit_timeout); | ||||||
1282 | if (!switch_channel_ready(channel)switch_channel_test_ready(channel, SWITCH_TRUE, SWITCH_FALSE)) goto end; | ||||||
1283 | } | ||||||
1284 | |||||||
1285 | if (!strcmp(input, profile->listen_file_key)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (input) && __builtin_constant_p (profile->listen_file_key ) && (__s1_len = __builtin_strlen (input), __s2_len = __builtin_strlen (profile->listen_file_key), (!((size_t)( const void *)((input) + 1) - (size_t)(const void *)(input) == 1) || __s1_len >= 4) && (!((size_t)(const void *) ((profile->listen_file_key) + 1) - (size_t)(const void *)( profile->listen_file_key) == 1) || __s2_len >= 4)) ? __builtin_strcmp (input, profile->listen_file_key) : (__builtin_constant_p (input) && ((size_t)(const void *)((input) + 1) - (size_t )(const void *)(input) == 1) && (__s1_len = __builtin_strlen (input), __s1_len < 4) ? (__builtin_constant_p (profile-> listen_file_key) && ((size_t)(const void *)((profile-> listen_file_key) + 1) - (size_t)(const void *)(profile->listen_file_key ) == 1) ? __builtin_strcmp (input, profile->listen_file_key ) : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (profile->listen_file_key); int __result = (((const unsigned char *) (const char *) (input))[0] - __s2 [0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (input))[1] - __s2 [1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (input))[2] - __s2 [2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (input))[3] - __s2[ 3]); } } __result; }))) : (__builtin_constant_p (profile-> listen_file_key) && ((size_t)(const void *)((profile-> listen_file_key) + 1) - (size_t)(const void *)(profile->listen_file_key ) == 1) && (__s2_len = __builtin_strlen (profile-> listen_file_key), __s2_len < 4) ? (__builtin_constant_p (input ) && ((size_t)(const void *)((input) + 1) - (size_t)( const void *)(input) == 1) ? __builtin_strcmp (input, profile ->listen_file_key) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (input); int __result = (((const unsigned char *) (const char *) (profile->listen_file_key ))[0] - __s2[0]); if (__s2_len > 0 && __result == 0 ) { __result = (((const unsigned char *) (const char *) (profile ->listen_file_key))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (profile->listen_file_key))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (profile->listen_file_key))[3] - __s2 [3]); } } __result; })))) : __builtin_strcmp (input, profile-> listen_file_key)))); })) { | ||||||
1286 | goto play_file; | ||||||
1287 | } else if (!strcmp(input, profile->record_file_key)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (input) && __builtin_constant_p (profile->record_file_key ) && (__s1_len = __builtin_strlen (input), __s2_len = __builtin_strlen (profile->record_file_key), (!((size_t)( const void *)((input) + 1) - (size_t)(const void *)(input) == 1) || __s1_len >= 4) && (!((size_t)(const void *) ((profile->record_file_key) + 1) - (size_t)(const void *)( profile->record_file_key) == 1) || __s2_len >= 4)) ? __builtin_strcmp (input, profile->record_file_key) : (__builtin_constant_p (input) && ((size_t)(const void *)((input) + 1) - (size_t )(const void *)(input) == 1) && (__s1_len = __builtin_strlen (input), __s1_len < 4) ? (__builtin_constant_p (profile-> record_file_key) && ((size_t)(const void *)((profile-> record_file_key) + 1) - (size_t)(const void *)(profile->record_file_key ) == 1) ? __builtin_strcmp (input, profile->record_file_key ) : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (profile->record_file_key); int __result = (((const unsigned char *) (const char *) (input))[0] - __s2 [0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (input))[1] - __s2 [1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (input))[2] - __s2 [2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (input))[3] - __s2[ 3]); } } __result; }))) : (__builtin_constant_p (profile-> record_file_key) && ((size_t)(const void *)((profile-> record_file_key) + 1) - (size_t)(const void *)(profile->record_file_key ) == 1) && (__s2_len = __builtin_strlen (profile-> record_file_key), __s2_len < 4) ? (__builtin_constant_p (input ) && ((size_t)(const void *)((input) + 1) - (size_t)( const void *)(input) == 1) ? __builtin_strcmp (input, profile ->record_file_key) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (input); int __result = (((const unsigned char *) (const char *) (profile->record_file_key ))[0] - __s2[0]); if (__s2_len > 0 && __result == 0 ) { __result = (((const unsigned char *) (const char *) (profile ->record_file_key))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (profile->record_file_key))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (profile->record_file_key))[3] - __s2 [3]); } } __result; })))) : __builtin_strcmp (input, profile-> record_file_key)))); })) { | ||||||
1288 | goto record_file; | ||||||
1289 | } else { | ||||||
1290 | (void) switch_ivr_phrase_macro(session, VM_ACK_MACRO, "saved", NULL, NULL)switch_ivr_phrase_macro_event(session, "voicemail_ack", "saved" , ((void*)0), ((void*)0), ((void*)0)); | ||||||
1291 | goto end; | ||||||
1292 | } | ||||||
1293 | } | ||||||
1294 | } | ||||||
1295 | |||||||
1296 | end: | ||||||
1297 | |||||||
1298 | if (!got_file) { | ||||||
1299 | status = SWITCH_STATUS_NOTFOUND; | ||||||
1300 | } | ||||||
1301 | |||||||
1302 | return status; | ||||||
1303 | } | ||||||
1304 | |||||||
1305 | |||||||
1306 | struct listen_callback { | ||||||
1307 | char created_epoch[255]; | ||||||
1308 | char read_epoch[255]; | ||||||
1309 | char user[255]; | ||||||
1310 | char domain[255]; | ||||||
1311 | char uuid[255]; | ||||||
1312 | char cid_name[255]; | ||||||
1313 | char cid_number[255]; | ||||||
1314 | char in_folder[255]; | ||||||
1315 | char file_path[255]; | ||||||
1316 | char message_len[255]; | ||||||
1317 | char flags[255]; | ||||||
1318 | char read_flags[255]; | ||||||
1319 | char forwarded_by[255]; | ||||||
1320 | char *email; | ||||||
1321 | int index; | ||||||
1322 | int want; | ||||||
1323 | msg_type_t type; | ||||||
1324 | msg_move_t move; | ||||||
1325 | char *convert_cmd; | ||||||
1326 | char *convert_ext; | ||||||
1327 | }; | ||||||
1328 | typedef struct listen_callback listen_callback_t; | ||||||
1329 | |||||||
1330 | static int listen_callback(void *pArg, int argc, char **argv, char **columnNames) | ||||||
1331 | { | ||||||
1332 | listen_callback_t *cbt = (listen_callback_t *) pArg; | ||||||
1333 | |||||||
1334 | if (cbt->index++ != cbt->want) { | ||||||
1335 | return 0; | ||||||
1336 | } | ||||||
1337 | |||||||
1338 | switch_copy_string(cbt->created_epoch, argv[0], 255); | ||||||
1339 | switch_copy_string(cbt->read_epoch, argv[1], 255); | ||||||
1340 | switch_copy_string(cbt->user, argv[2], 255); | ||||||
1341 | switch_copy_string(cbt->domain, argv[3], 255); | ||||||
1342 | switch_copy_string(cbt->uuid, argv[4], 255); | ||||||
1343 | switch_copy_string(cbt->cid_name, argv[5], 255); | ||||||
1344 | switch_copy_string(cbt->cid_number, argv[6], 255); | ||||||
1345 | switch_copy_string(cbt->in_folder, argv[7], 255); | ||||||
1346 | switch_copy_string(cbt->file_path, argv[8], 255); | ||||||
1347 | switch_copy_string(cbt->message_len, argv[9], 255); | ||||||
1348 | switch_copy_string(cbt->flags, argv[10], 255); | ||||||
1349 | switch_copy_string(cbt->read_flags, argv[11], 255); | ||||||
1350 | switch_copy_string(cbt->forwarded_by, argv[12], 255); | ||||||
1351 | |||||||
1352 | return -1; | ||||||
1353 | } | ||||||
1354 | |||||||
1355 | static char *resolve_id(const char *myid, const char *domain_name, const char *action) | ||||||
1356 | { | ||||||
1357 | switch_xml_t xx_user; | ||||||
1358 | switch_event_t *params; | ||||||
1359 | char *ret = (char *) myid; | ||||||
1360 | |||||||
1361 | switch_event_create(¶ms, SWITCH_EVENT_GENERAL)switch_event_create_subclass_detailed("mod_voicemail.c", (const char * )(const char *)__func__, 1361, ¶ms, SWITCH_EVENT_GENERAL , ((void*)0)); | ||||||
1362 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "action", action); | ||||||
1363 | |||||||
1364 | if (switch_xml_locate_user_merged("id:number-alias", myid, domain_name, NULL((void*)0), &xx_user, params) == SWITCH_STATUS_SUCCESS) { | ||||||
1365 | ret = strdup(switch_xml_attr(xx_user, "id"))(__extension__ (__builtin_constant_p (switch_xml_attr(xx_user , "id")) && ((size_t)(const void *)((switch_xml_attr( xx_user, "id")) + 1) - (size_t)(const void *)(switch_xml_attr (xx_user, "id")) == 1) ? (((const char *) (switch_xml_attr(xx_user , "id")))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1 ) : ({ size_t __len = strlen (switch_xml_attr(xx_user, "id")) + 1; char *__retval = (char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, switch_xml_attr (xx_user, "id"), __len); __retval; })) : __strdup (switch_xml_attr (xx_user, "id")))); | ||||||
1366 | switch_xml_free(xx_user); | ||||||
1367 | } | ||||||
1368 | |||||||
1369 | switch_event_destroy(¶ms); | ||||||
1370 | return ret; | ||||||
1371 | } | ||||||
1372 | |||||||
1373 | static void message_count(vm_profile_t *profile, const char *id_in, const char *domain_name, const char *myfolder, int *total_new_messages, | ||||||
1374 | int *total_saved_messages, int *total_new_urgent_messages, int *total_saved_urgent_messages) | ||||||
1375 | { | ||||||
1376 | char msg_count[80] = ""; | ||||||
1377 | msg_cnt_callback_t cbt = { 0 }; | ||||||
1378 | char *sql; | ||||||
1379 | char *myid = NULL((void*)0); | ||||||
1380 | |||||||
1381 | |||||||
1382 | cbt.buf = msg_count; | ||||||
1383 | cbt.len = sizeof(msg_count); | ||||||
1384 | |||||||
1385 | cbt.total_new_messages = 0; | ||||||
1386 | cbt.total_new_urgent_messages = 0; | ||||||
1387 | cbt.total_saved_messages = 0; | ||||||
1388 | cbt.total_saved_urgent_messages = 0; | ||||||
1389 | |||||||
1390 | myid = resolve_id(id_in, domain_name, "message-count"); | ||||||
1391 | |||||||
1392 | sql = switch_mprintf( | ||||||
1393 | "select 1, read_flags, count(read_epoch) from voicemail_msgs where " | ||||||
1394 | "username='%q' and domain='%q' and in_folder='%q' and read_epoch=0 " | ||||||
1395 | "group by read_flags " | ||||||
1396 | "union " | ||||||
1397 | "select 0, read_flags, count(read_epoch) from voicemail_msgs where " | ||||||
1398 | "username='%q' and domain='%q' and in_folder='%q' and read_epoch<>0 " | ||||||
1399 | "group by read_flags;", | ||||||
1400 | |||||||
1401 | myid, domain_name, myfolder, | ||||||
1402 | myid, domain_name, myfolder); | ||||||
1403 | |||||||
1404 | vm_execute_sql_callback(profile, profile->mutex, sql, message_count_callback, &cbt); | ||||||
1405 | free(sql); | ||||||
1406 | |||||||
1407 | *total_new_messages = cbt.total_new_messages + cbt.total_new_urgent_messages; | ||||||
1408 | *total_new_urgent_messages = cbt.total_new_urgent_messages; | ||||||
1409 | *total_saved_messages = cbt.total_saved_messages + cbt.total_saved_urgent_messages; | ||||||
1410 | *total_saved_urgent_messages = cbt.total_saved_urgent_messages; | ||||||
1411 | |||||||
1412 | if (myid != id_in) { | ||||||
1413 | free(myid); | ||||||
1414 | } | ||||||
1415 | } | ||||||
1416 | |||||||
1417 | /* TODO Port this as switch_ core function */ | ||||||
1418 | switch_status_t vm_merge_media_files(const char** inputs, const char *output) { | ||||||
1419 | switch_status_t status = SWITCH_STATUS_SUCCESS; | ||||||
1420 | switch_file_handle_t fh_output = { 0 }; | ||||||
1421 | int channels = 1; | ||||||
1422 | int rate = 8000; /* TODO Make this configurable */ | ||||||
1423 | int j = 0; | ||||||
1424 | |||||||
1425 | if (switch_core_file_open(&fh_output, output, channels, rate, SWITCH_FILE_FLAG_WRITE | SWITCH_FILE_DATA_SHORT, NULL)switch_core_perform_file_open("mod_voicemail.c", (const char * )__func__, 1425, &fh_output, output, channels, rate, SWITCH_FILE_FLAG_WRITE | SWITCH_FILE_DATA_SHORT, ((void*)0)) != SWITCH_STATUS_SUCCESS) { | ||||||
1426 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 1426, ((void*)0), SWITCH_LOG_ERROR, "Couldn't open %s\n", output); | ||||||
1427 | goto end; | ||||||
1428 | } | ||||||
1429 | |||||||
1430 | for (j = 0; inputs[j] != NULL((void*)0) && j < 128 && status == SWITCH_STATUS_SUCCESS; j++) { | ||||||
1431 | switch_file_handle_t fh_input = { 0 }; | ||||||
1432 | char buf[2048]; | ||||||
1433 | switch_size_t len = sizeof(buf) / 2; | ||||||
1434 | |||||||
1435 | if (switch_core_file_open(&fh_input, inputs[j], channels, rate, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL)switch_core_perform_file_open("mod_voicemail.c", (const char * )__func__, 1435, &fh_input, inputs[j], channels, rate, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, ((void*)0)) != SWITCH_STATUS_SUCCESS) { | ||||||
1436 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 1436, ((void*)0), SWITCH_LOG_ERROR, "Couldn't open %s\n", inputs[j]); | ||||||
1437 | status = SWITCH_STATUS_GENERR; | ||||||
1438 | break; | ||||||
1439 | } | ||||||
1440 | |||||||
1441 | while (switch_core_file_read(&fh_input, buf, &len) == SWITCH_STATUS_SUCCESS) { | ||||||
1442 | if (switch_core_file_write(&fh_output, buf, &len) != SWITCH_STATUS_SUCCESS) { | ||||||
1443 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 1443, ((void*)0), SWITCH_LOG_ERROR, "Write error\n"); | ||||||
1444 | status = SWITCH_STATUS_GENERR; | ||||||
1445 | break; | ||||||
1446 | } | ||||||
1447 | } | ||||||
1448 | |||||||
1449 | if (fh_input.file_interface) { | ||||||
1450 | switch_core_file_close(&fh_input); | ||||||
1451 | } | ||||||
1452 | } | ||||||
1453 | |||||||
1454 | if (fh_output.file_interface) { | ||||||
1455 | switch_core_file_close(&fh_output); | ||||||
1456 | } | ||||||
1457 | end: | ||||||
1458 | return status; | ||||||
1459 | } | ||||||
1460 | |||||||
1461 | #define VM_STARTSAMPLES1024 * 32 1024 * 32 | ||||||
1462 | |||||||
1463 | static char *vm_merge_file(switch_core_session_t *session, vm_profile_t *profile, const char *announce, const char *orig) | ||||||
1464 | { | ||||||
1465 | switch_channel_t *channel = switch_core_session_get_channel(session); | ||||||
1466 | switch_file_handle_t lrfh = { 0 }, *rfh = NULL((void*)0), lfh = { | ||||||
1467 | 0}, *fh = NULL((void*)0); | ||||||
1468 | char *tmp_path; | ||||||
1469 | switch_uuid_t uuid; | ||||||
1470 | char uuid_str[SWITCH_UUID_FORMATTED_LENGTH256 + 1]; | ||||||
1471 | char *ret = NULL((void*)0); | ||||||
1472 | int16_t *abuf = NULL((void*)0); | ||||||
1473 | switch_size_t olen = 0; | ||||||
1474 | int asis = 0; | ||||||
1475 | switch_codec_implementation_t read_impl = { 0 }; | ||||||
1476 | switch_core_session_get_read_impl(session, &read_impl); | ||||||
1477 | |||||||
1478 | switch_uuid_get(&uuid); | ||||||
1479 | switch_uuid_format(uuid_str, &uuid); | ||||||
1480 | |||||||
1481 | lfh.channels = read_impl.number_of_channels; | ||||||
1482 | lfh.native_rate = read_impl.actual_samples_per_second; | ||||||
1483 | |||||||
1484 | tmp_path = switch_core_session_sprintf(session, "%s%smsg_%s.%s", SWITCH_GLOBAL_dirs.temp_dir, SWITCH_PATH_SEPARATOR"/", uuid_str, profile->file_ext); | ||||||
1485 | |||||||
1486 | if (switch_core_file_open(&lfh,switch_core_perform_file_open("mod_voicemail.c", (const char * )__func__, 1489, &lfh, tmp_path, lfh.channels, read_impl. actual_samples_per_second, SWITCH_FILE_FLAG_WRITE | SWITCH_FILE_DATA_SHORT , ((void*)0)) | ||||||
1487 | tmp_path,switch_core_perform_file_open("mod_voicemail.c", (const char * )__func__, 1489, &lfh, tmp_path, lfh.channels, read_impl. actual_samples_per_second, SWITCH_FILE_FLAG_WRITE | SWITCH_FILE_DATA_SHORT , ((void*)0)) | ||||||
1488 | lfh.channels,switch_core_perform_file_open("mod_voicemail.c", (const char * )__func__, 1489, &lfh, tmp_path, lfh.channels, read_impl. actual_samples_per_second, SWITCH_FILE_FLAG_WRITE | SWITCH_FILE_DATA_SHORT , ((void*)0)) | ||||||
1489 | read_impl.actual_samples_per_second, SWITCH_FILE_FLAG_WRITE | SWITCH_FILE_DATA_SHORT, NULL)switch_core_perform_file_open("mod_voicemail.c", (const char * )__func__, 1489, &lfh, tmp_path, lfh.channels, read_impl. actual_samples_per_second, SWITCH_FILE_FLAG_WRITE | SWITCH_FILE_DATA_SHORT , ((void*)0)) != SWITCH_STATUS_SUCCESS) { | ||||||
1490 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "mod_voicemail.c", (const char *)__func__ , 1490, (const char*)(session), SWITCH_LOG_ERROR, "Failed to open file %s\n", tmp_path); | ||||||
1491 | goto end; | ||||||
1492 | } | ||||||
1493 | |||||||
1494 | fh = &lfh; | ||||||
1495 | |||||||
1496 | |||||||
1497 | if (switch_core_file_open(&lrfh,switch_core_perform_file_open("mod_voicemail.c", (const char * )__func__, 1500, &lrfh, announce, lfh.channels, read_impl .actual_samples_per_second, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT , ((void*)0)) | ||||||
1498 | announce,switch_core_perform_file_open("mod_voicemail.c", (const char * )__func__, 1500, &lrfh, announce, lfh.channels, read_impl .actual_samples_per_second, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT , ((void*)0)) | ||||||
1499 | lfh.channels,switch_core_perform_file_open("mod_voicemail.c", (const char * )__func__, 1500, &lrfh, announce, lfh.channels, read_impl .actual_samples_per_second, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT , ((void*)0)) | ||||||
1500 | read_impl.actual_samples_per_second, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL)switch_core_perform_file_open("mod_voicemail.c", (const char * )__func__, 1500, &lrfh, announce, lfh.channels, read_impl .actual_samples_per_second, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT , ((void*)0)) != SWITCH_STATUS_SUCCESS) { | ||||||
1501 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "mod_voicemail.c", (const char *)__func__ , 1501, (const char*)(session), SWITCH_LOG_ERROR, "Failed to open file %s\n", announce); | ||||||
1502 | goto end; | ||||||
1503 | } | ||||||
1504 | |||||||
1505 | rfh = &lrfh; | ||||||
1506 | |||||||
1507 | switch_zmalloc(abuf, VM_STARTSAMPLES * sizeof(*abuf))(void)((((abuf = calloc(1, (1024 * 32 * sizeof(*abuf))))) ? ( void) (0) : __assert_fail ("(abuf = calloc(1, (1024 * 32 * sizeof(*abuf))))" , "mod_voicemail.c", 1507, __PRETTY_FUNCTION__)),abuf); | ||||||
1508 | |||||||
1509 | if (switch_test_flag(fh, SWITCH_FILE_NATIVE)((fh)->flags & SWITCH_FILE_NATIVE)) { | ||||||
1510 | asis = 1; | ||||||
1511 | } | ||||||
1512 | |||||||
1513 | while (switch_channel_ready(channel)switch_channel_test_ready(channel, SWITCH_TRUE, SWITCH_FALSE)) { | ||||||
1514 | olen = VM_STARTSAMPLES1024 * 32; | ||||||
1515 | |||||||
1516 | if (!asis) { | ||||||
1517 | olen /= 2; | ||||||
1518 | } | ||||||
1519 | |||||||
1520 | if (switch_core_file_read(rfh, abuf, &olen) != SWITCH_STATUS_SUCCESS || !olen) { | ||||||
1521 | break; | ||||||
1522 | } | ||||||
1523 | |||||||
1524 | switch_core_file_write(fh, abuf, &olen); | ||||||
1525 | |||||||
1526 | } | ||||||
1527 | |||||||
1528 | if (rfh) { | ||||||
1529 | switch_core_file_close(rfh); | ||||||
1530 | rfh = NULL((void*)0); | ||||||
1531 | } | ||||||
1532 | |||||||
1533 | if (switch_core_file_open(&lrfh,switch_core_perform_file_open("mod_voicemail.c", (const char * )__func__, 1536, &lrfh, orig, lfh.channels, read_impl.actual_samples_per_second , SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, ((void*)0)) | ||||||
1534 | orig,switch_core_perform_file_open("mod_voicemail.c", (const char * )__func__, 1536, &lrfh, orig, lfh.channels, read_impl.actual_samples_per_second , SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, ((void*)0)) | ||||||
1535 | lfh.channels,switch_core_perform_file_open("mod_voicemail.c", (const char * )__func__, 1536, &lrfh, orig, lfh.channels, read_impl.actual_samples_per_second , SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, ((void*)0)) | ||||||
1536 | read_impl.actual_samples_per_second, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL)switch_core_perform_file_open("mod_voicemail.c", (const char * )__func__, 1536, &lrfh, orig, lfh.channels, read_impl.actual_samples_per_second , SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, ((void*)0)) != SWITCH_STATUS_SUCCESS) { | ||||||
1537 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "mod_voicemail.c", (const char *)__func__ , 1537, (const char*)(session), SWITCH_LOG_ERROR, "Failed to open file %s\n", orig); | ||||||
1538 | goto end; | ||||||
1539 | } | ||||||
1540 | |||||||
1541 | rfh = &lrfh; | ||||||
1542 | |||||||
1543 | while (switch_channel_ready(channel)switch_channel_test_ready(channel, SWITCH_TRUE, SWITCH_FALSE)) { | ||||||
1544 | olen = VM_STARTSAMPLES1024 * 32; | ||||||
1545 | |||||||
1546 | if (!asis) { | ||||||
1547 | olen /= 2; | ||||||
1548 | } | ||||||
1549 | |||||||
1550 | if (switch_core_file_read(rfh, abuf, &olen) != SWITCH_STATUS_SUCCESS || !olen) { | ||||||
1551 | break; | ||||||
1552 | } | ||||||
1553 | |||||||
1554 | switch_core_file_write(fh, abuf, &olen); | ||||||
1555 | |||||||
1556 | } | ||||||
1557 | |||||||
1558 | if (unlink(announce) != 0) { | ||||||
1559 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "mod_voicemail.c", (const char *)__func__ , 1559, (const char*)(session), SWITCH_LOG_WARNING, "Failed to delete file [%s]\n", announce); | ||||||
1560 | } | ||||||
1561 | ret = tmp_path; | ||||||
1562 | |||||||
1563 | end: | ||||||
1564 | |||||||
1565 | if (fh) { | ||||||
1566 | switch_core_file_close(fh); | ||||||
1567 | fh = NULL((void*)0); | ||||||
1568 | } | ||||||
1569 | |||||||
1570 | if (rfh) { | ||||||
1571 | switch_core_file_close(rfh); | ||||||
1572 | rfh = NULL((void*)0); | ||||||
1573 | } | ||||||
1574 | |||||||
1575 | switch_safe_free(abuf)if (abuf) {free(abuf);abuf=((void*)0);}; | ||||||
1576 | |||||||
1577 | return ret; | ||||||
1578 | |||||||
1579 | } | ||||||
1580 | |||||||
1581 | |||||||
1582 | static switch_status_t listen_file(switch_core_session_t *session, vm_profile_t *profile, listen_callback_t *cbt) | ||||||
1583 | { | ||||||
1584 | switch_channel_t *channel = switch_core_session_get_channel(session); | ||||||
1585 | switch_status_t status = SWITCH_STATUS_SUCCESS; | ||||||
1586 | switch_input_args_t args = { 0 }; | ||||||
1587 | char term; | ||||||
1588 | char input[10] = "", key_buf[80] = ""; | ||||||
1589 | switch_file_handle_t fh = { 0 }; | ||||||
1590 | cc_t cc = { 0 }; | ||||||
1591 | char *forward_file_path = NULL((void*)0); | ||||||
1592 | switch_core_session_message_t msg = { 0 }; | ||||||
1593 | char cid_buf[1024] = ""; | ||||||
1594 | |||||||
1595 | if (switch_channel_ready(channel)switch_channel_test_ready(channel, SWITCH_TRUE, SWITCH_FALSE)) { | ||||||
1596 | switch_snprintf(cid_buf, sizeof(cid_buf), "%s|%s", cbt->cid_name, cbt->cid_number); | ||||||
1597 | |||||||
1598 | msg.from = __FILE__"mod_voicemail.c"; | ||||||
1599 | msg.string_arg = cid_buf; | ||||||
1600 | msg.message_id = SWITCH_MESSAGE_INDICATE_DISPLAY; | ||||||
1601 | |||||||
1602 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "mod_voicemail.c", (const char *)__func__ , 1602, (const char*)(session), SWITCH_LOG_DEBUG, "Sending display update [%s] to %s\n", | ||||||
1603 | cid_buf, switch_channel_get_name(channel)); | ||||||
1604 | switch_core_session_receive_message(session, &msg)switch_core_session_perform_receive_message(session, &msg , "mod_voicemail.c", (const char *)__func__, 1604); | ||||||
1605 | |||||||
1606 | if (!zstr(cbt->cid_number)_zstr(cbt->cid_number) && (switch_true(switch_channel_get_variable(channel, "vm_announce_cid")switch_channel_get_variable_dup(channel, "vm_announce_cid", SWITCH_TRUE , -1)))) { | ||||||
1607 | TRY_CODE(switch_ivr_phrase_macro(session, VM_SAY_PHONE_NUMBER_MACRO, cbt->cid_number, NULL, NULL))do { status = switch_ivr_phrase_macro_event(session, "voicemail_say_phone_number" , cbt->cid_number, ((void*)0), ((void*)0), ((void*)0)); if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK ) { goto end; } break;} while(status); | ||||||
1608 | } | ||||||
1609 | |||||||
1610 | args.input_callback = cancel_on_dtmf; | ||||||
1611 | |||||||
1612 | switch_snprintf(key_buf, sizeof(key_buf), "%s:%s:%s:%s:%s:%s%s%s", profile->repeat_msg_key, profile->save_file_key, | ||||||
1613 | profile->delete_file_key, profile->email_key, profile->callback_key, | ||||||
1614 | profile->forward_key, cbt->email ? ":" : "", cbt->email ? cbt->email : ""); | ||||||
1615 | |||||||
1616 | |||||||
1617 | switch_snprintf(input, sizeof(input), "%s:%d", cbt->type == MSG_NEW ? "new" : "saved", cbt->want + 1); | ||||||
1618 | memset(&cc, 0, sizeof(cc)); | ||||||
1619 | cc.profile = profile; | ||||||
1620 | args.buf = &cc; | ||||||
1621 | args.input_callback = control_playback; | ||||||
1622 | TRY_CODE(switch_ivr_phrase_macro(session, VM_SAY_MESSAGE_NUMBER_MACRO, input, NULL, &args))do { status = switch_ivr_phrase_macro_event(session, "voicemail_say_message_number" , input, ((void*)0), ((void*)0), &args); if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) { goto end; } break ;} while(status); | ||||||
1623 | |||||||
1624 | play_file: | ||||||
1625 | |||||||
1626 | if (!*cc.buf && (profile->play_date_announcement == VM_DATE_FIRST)) { | ||||||
1627 | cc.fh = NULL((void*)0); | ||||||
1628 | TRY_CODE(switch_ivr_phrase_macro(session, VM_SAY_DATE_MACRO, cbt->created_epoch, NULL, &args))do { status = switch_ivr_phrase_macro_event(session, "voicemail_say_date" , cbt->created_epoch, ((void*)0), ((void*)0), &args); if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK ) { goto end; } break;} while(status); | ||||||
1629 | } | ||||||
1630 | |||||||
1631 | if (!*cc.buf || *cc.buf == *cc.profile->skip_info_key) { | ||||||
1632 | *cc.buf = '\0'; | ||||||
1633 | memset(&fh, 0, sizeof(fh)); | ||||||
1634 | cc.fh = &fh; | ||||||
1635 | cc.playback_controls_active = 1; | ||||||
1636 | if (switch_file_exists(cbt->file_path, switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) { | ||||||
1637 | TRY_CODE(switch_ivr_play_file(session, &fh, cbt->file_path, &args))do { status = switch_ivr_play_file(session, &fh, cbt-> file_path, &args); if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) { goto end; } break;} while(status ); | ||||||
1638 | } | ||||||
1639 | cc.playback_controls_active = 0; | ||||||
1640 | } | ||||||
1641 | |||||||
1642 | if (!*cc.buf && (profile->play_date_announcement == VM_DATE_LAST)) { | ||||||
1643 | cc.fh = NULL((void*)0); | ||||||
1644 | TRY_CODE(switch_ivr_phrase_macro(session, VM_SAY_DATE_MACRO, cbt->created_epoch, NULL, &args))do { status = switch_ivr_phrase_macro_event(session, "voicemail_say_date" , cbt->created_epoch, ((void*)0), ((void*)0), &args); if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK ) { goto end; } break;} while(status); | ||||||
1645 | } | ||||||
1646 | |||||||
1647 | if (switch_channel_ready(channel)switch_channel_test_ready(channel, SWITCH_TRUE, SWITCH_FALSE)) { | ||||||
1648 | if (*cc.buf && *cc.buf != *profile->terminator_key) { | ||||||
1649 | *input = *cc.buf; | ||||||
1650 | *(input + 1) = '\0'; | ||||||
1651 | status = SWITCH_STATUS_SUCCESS; | ||||||
1652 | *cc.buf = '\0'; | ||||||
1653 | } else { | ||||||
1654 | TRY_CODE(vm_macro_get(session, VM_LISTEN_FILE_CHECK_MACRO, key_buf, input, sizeof(input), 1, "", &term, profile->digit_timeout))do { status = vm_macro_get(session, "voicemail_listen_file_check" , key_buf, input, sizeof(input), 1, "", &term, profile-> digit_timeout); if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) { goto end; } break;} while(status ); | ||||||
1655 | } | ||||||
1656 | if (!strcmp(input, profile->prev_msg_key)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (input) && __builtin_constant_p (profile->prev_msg_key ) && (__s1_len = __builtin_strlen (input), __s2_len = __builtin_strlen (profile->prev_msg_key), (!((size_t)(const void *)((input) + 1) - (size_t)(const void *)(input) == 1) || __s1_len >= 4) && (!((size_t)(const void *)((profile ->prev_msg_key) + 1) - (size_t)(const void *)(profile-> prev_msg_key) == 1) || __s2_len >= 4)) ? __builtin_strcmp ( input, profile->prev_msg_key) : (__builtin_constant_p (input ) && ((size_t)(const void *)((input) + 1) - (size_t)( const void *)(input) == 1) && (__s1_len = __builtin_strlen (input), __s1_len < 4) ? (__builtin_constant_p (profile-> prev_msg_key) && ((size_t)(const void *)((profile-> prev_msg_key) + 1) - (size_t)(const void *)(profile->prev_msg_key ) == 1) ? __builtin_strcmp (input, profile->prev_msg_key) : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (profile->prev_msg_key); int __result = (((const unsigned char *) (const char *) (input))[0] - __s2 [0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (input))[1] - __s2 [1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (input))[2] - __s2 [2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (input))[3] - __s2[ 3]); } } __result; }))) : (__builtin_constant_p (profile-> prev_msg_key) && ((size_t)(const void *)((profile-> prev_msg_key) + 1) - (size_t)(const void *)(profile->prev_msg_key ) == 1) && (__s2_len = __builtin_strlen (profile-> prev_msg_key), __s2_len < 4) ? (__builtin_constant_p (input ) && ((size_t)(const void *)((input) + 1) - (size_t)( const void *)(input) == 1) ? __builtin_strcmp (input, profile ->prev_msg_key) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (input); int __result = (((const unsigned char *) (const char *) (profile->prev_msg_key ))[0] - __s2[0]); if (__s2_len > 0 && __result == 0 ) { __result = (((const unsigned char *) (const char *) (profile ->prev_msg_key))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (profile->prev_msg_key))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (profile->prev_msg_key))[3] - __s2 [3]); } } __result; })))) : __builtin_strcmp (input, profile-> prev_msg_key)))); })) { | ||||||
1657 | cbt->move = VM_MOVE_PREV; | ||||||
1658 | } else if (!strcmp(input, profile->repeat_msg_key)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (input) && __builtin_constant_p (profile->repeat_msg_key ) && (__s1_len = __builtin_strlen (input), __s2_len = __builtin_strlen (profile->repeat_msg_key), (!((size_t)(const void *)((input) + 1) - (size_t)(const void *)(input) == 1) || __s1_len >= 4) && (!((size_t)(const void *)((profile ->repeat_msg_key) + 1) - (size_t)(const void *)(profile-> repeat_msg_key) == 1) || __s2_len >= 4)) ? __builtin_strcmp (input, profile->repeat_msg_key) : (__builtin_constant_p ( input) && ((size_t)(const void *)((input) + 1) - (size_t )(const void *)(input) == 1) && (__s1_len = __builtin_strlen (input), __s1_len < 4) ? (__builtin_constant_p (profile-> repeat_msg_key) && ((size_t)(const void *)((profile-> repeat_msg_key) + 1) - (size_t)(const void *)(profile->repeat_msg_key ) == 1) ? __builtin_strcmp (input, profile->repeat_msg_key ) : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (profile->repeat_msg_key); int __result = (((const unsigned char *) (const char *) (input))[0] - __s2 [0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (input))[1] - __s2 [1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (input))[2] - __s2 [2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (input))[3] - __s2[ 3]); } } __result; }))) : (__builtin_constant_p (profile-> repeat_msg_key) && ((size_t)(const void *)((profile-> repeat_msg_key) + 1) - (size_t)(const void *)(profile->repeat_msg_key ) == 1) && (__s2_len = __builtin_strlen (profile-> repeat_msg_key), __s2_len < 4) ? (__builtin_constant_p (input ) && ((size_t)(const void *)((input) + 1) - (size_t)( const void *)(input) == 1) ? __builtin_strcmp (input, profile ->repeat_msg_key) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (input); int __result = (((const unsigned char *) (const char *) (profile->repeat_msg_key ))[0] - __s2[0]); if (__s2_len > 0 && __result == 0 ) { __result = (((const unsigned char *) (const char *) (profile ->repeat_msg_key))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (profile->repeat_msg_key))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (profile->repeat_msg_key))[3] - __s2 [3]); } } __result; })))) : __builtin_strcmp (input, profile-> repeat_msg_key)))); })) { | ||||||
1659 | cbt->move = VM_MOVE_SAME; | ||||||
1660 | } else if (!strcmp(input, profile->next_msg_key)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (input) && __builtin_constant_p (profile->next_msg_key ) && (__s1_len = __builtin_strlen (input), __s2_len = __builtin_strlen (profile->next_msg_key), (!((size_t)(const void *)((input) + 1) - (size_t)(const void *)(input) == 1) || __s1_len >= 4) && (!((size_t)(const void *)((profile ->next_msg_key) + 1) - (size_t)(const void *)(profile-> next_msg_key) == 1) || __s2_len >= 4)) ? __builtin_strcmp ( input, profile->next_msg_key) : (__builtin_constant_p (input ) && ((size_t)(const void *)((input) + 1) - (size_t)( const void *)(input) == 1) && (__s1_len = __builtin_strlen (input), __s1_len < 4) ? (__builtin_constant_p (profile-> next_msg_key) && ((size_t)(const void *)((profile-> next_msg_key) + 1) - (size_t)(const void *)(profile->next_msg_key ) == 1) ? __builtin_strcmp (input, profile->next_msg_key) : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (profile->next_msg_key); int __result = (((const unsigned char *) (const char *) (input))[0] - __s2 [0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (input))[1] - __s2 [1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (input))[2] - __s2 [2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (input))[3] - __s2[ 3]); } } __result; }))) : (__builtin_constant_p (profile-> next_msg_key) && ((size_t)(const void *)((profile-> next_msg_key) + 1) - (size_t)(const void *)(profile->next_msg_key ) == 1) && (__s2_len = __builtin_strlen (profile-> next_msg_key), __s2_len < 4) ? (__builtin_constant_p (input ) && ((size_t)(const void *)((input) + 1) - (size_t)( const void *)(input) == 1) ? __builtin_strcmp (input, profile ->next_msg_key) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (input); int __result = (((const unsigned char *) (const char *) (profile->next_msg_key ))[0] - __s2[0]); if (__s2_len > 0 && __result == 0 ) { __result = (((const unsigned char *) (const char *) (profile ->next_msg_key))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (profile->next_msg_key))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (profile->next_msg_key))[3] - __s2 [3]); } } __result; })))) : __builtin_strcmp (input, profile-> next_msg_key)))); })) { | ||||||
1661 | cbt->move = VM_MOVE_NEXT; | ||||||
1662 | } else if (!strcmp(input, profile->listen_file_key)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (input) && __builtin_constant_p (profile->listen_file_key ) && (__s1_len = __builtin_strlen (input), __s2_len = __builtin_strlen (profile->listen_file_key), (!((size_t)( const void *)((input) + 1) - (size_t)(const void *)(input) == 1) || __s1_len >= 4) && (!((size_t)(const void *) ((profile->listen_file_key) + 1) - (size_t)(const void *)( profile->listen_file_key) == 1) || __s2_len >= 4)) ? __builtin_strcmp (input, profile->listen_file_key) : (__builtin_constant_p (input) && ((size_t)(const void *)((input) + 1) - (size_t )(const void *)(input) == 1) && (__s1_len = __builtin_strlen (input), __s1_len < 4) ? (__builtin_constant_p (profile-> listen_file_key) && ((size_t)(const void *)((profile-> listen_file_key) + 1) - (size_t)(const void *)(profile->listen_file_key ) == 1) ? __builtin_strcmp (input, profile->listen_file_key ) : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (profile->listen_file_key); int __result = (((const unsigned char *) (const char *) (input))[0] - __s2 [0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (input))[1] - __s2 [1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (input))[2] - __s2 [2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (input))[3] - __s2[ 3]); } } __result; }))) : (__builtin_constant_p (profile-> listen_file_key) && ((size_t)(const void *)((profile-> listen_file_key) + 1) - (size_t)(const void *)(profile->listen_file_key ) == 1) && (__s2_len = __builtin_strlen (profile-> listen_file_key), __s2_len < 4) ? (__builtin_constant_p (input ) && ((size_t)(const void *)((input) + 1) - (size_t)( const void *)(input) == 1) ? __builtin_strcmp (input, profile ->listen_file_key) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (input); int __result = (((const unsigned char *) (const char *) (profile->listen_file_key ))[0] - __s2[0]); if (__s2_len > 0 && __result == 0 ) { __result = (((const unsigned char *) (const char *) (profile ->listen_file_key))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (profile->listen_file_key))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (profile->listen_file_key))[3] - __s2 [3]); } } __result; })))) : __builtin_strcmp (input, profile-> listen_file_key)))); })) { | ||||||
1663 | *cc.buf = '\0'; | ||||||
1664 | goto play_file; | ||||||
1665 | } else if (!strcmp(input, profile->callback_key)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (input) && __builtin_constant_p (profile->callback_key ) && (__s1_len = __builtin_strlen (input), __s2_len = __builtin_strlen (profile->callback_key), (!((size_t)(const void *)((input) + 1) - (size_t)(const void *)(input) == 1) || __s1_len >= 4) && (!((size_t)(const void *)((profile ->callback_key) + 1) - (size_t)(const void *)(profile-> callback_key) == 1) || __s2_len >= 4)) ? __builtin_strcmp ( input, profile->callback_key) : (__builtin_constant_p (input ) && ((size_t)(const void *)((input) + 1) - (size_t)( const void *)(input) == 1) && (__s1_len = __builtin_strlen (input), __s1_len < 4) ? (__builtin_constant_p (profile-> callback_key) && ((size_t)(const void *)((profile-> callback_key) + 1) - (size_t)(const void *)(profile->callback_key ) == 1) ? __builtin_strcmp (input, profile->callback_key) : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (profile->callback_key); int __result = (((const unsigned char *) (const char *) (input))[0] - __s2 [0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (input))[1] - __s2 [1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (input))[2] - __s2 [2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (input))[3] - __s2[ 3]); } } __result; }))) : (__builtin_constant_p (profile-> callback_key) && ((size_t)(const void *)((profile-> callback_key) + 1) - (size_t)(const void *)(profile->callback_key ) == 1) && (__s2_len = __builtin_strlen (profile-> callback_key), __s2_len < 4) ? (__builtin_constant_p (input ) && ((size_t)(const void *)((input) + 1) - (size_t)( const void *)(input) == 1) ? __builtin_strcmp (input, profile ->callback_key) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (input); int __result = (((const unsigned char *) (const char *) (profile->callback_key ))[0] - __s2[0]); if (__s2_len > 0 && __result == 0 ) { __result = (((const unsigned char *) (const char *) (profile ->callback_key))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (profile->callback_key))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (profile->callback_key))[3] - __s2 [3]); } } __result; })))) : __builtin_strcmp (input, profile-> callback_key)))); })) { | ||||||
1666 | const char *callback_dialplan; | ||||||
1667 | const char *callback_context; | ||||||
1668 | |||||||
1669 | if (!(callback_dialplan = switch_channel_get_variable(channel, "voicemail_callback_dialplan")switch_channel_get_variable_dup(channel, "voicemail_callback_dialplan" , SWITCH_TRUE, -1))) { | ||||||
1670 | callback_dialplan = profile->callback_dialplan; | ||||||
1671 | } | ||||||
1672 | |||||||
1673 | if (!(callback_context = switch_channel_get_variable(channel, "voicemail_callback_context")switch_channel_get_variable_dup(channel, "voicemail_callback_context" , SWITCH_TRUE, -1))) { | ||||||
1674 | callback_context = profile->callback_context; | ||||||
1675 | } | ||||||
1676 | |||||||
1677 | switch_core_session_execute_exten(session, cbt->cid_number, callback_dialplan, callback_context); | ||||||
1678 | } else if (!strcmp(input, profile->forward_key)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (input) && __builtin_constant_p (profile->forward_key ) && (__s1_len = __builtin_strlen (input), __s2_len = __builtin_strlen (profile->forward_key), (!((size_t)(const void *)((input) + 1) - (size_t)(const void *)(input) == 1) || __s1_len >= 4) && (!((size_t)(const void *)((profile ->forward_key) + 1) - (size_t)(const void *)(profile->forward_key ) == 1) || __s2_len >= 4)) ? __builtin_strcmp (input, profile ->forward_key) : (__builtin_constant_p (input) && ( (size_t)(const void *)((input) + 1) - (size_t)(const void *)( input) == 1) && (__s1_len = __builtin_strlen (input), __s1_len < 4) ? (__builtin_constant_p (profile->forward_key ) && ((size_t)(const void *)((profile->forward_key ) + 1) - (size_t)(const void *)(profile->forward_key) == 1 ) ? __builtin_strcmp (input, profile->forward_key) : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (profile->forward_key); int __result = (((const unsigned char *) (const char *) (input))[0] - __s2[0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (input))[1] - __s2[1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (input))[2] - __s2[2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char * ) (const char *) (input))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p (profile->forward_key) && ( (size_t)(const void *)((profile->forward_key) + 1) - (size_t )(const void *)(profile->forward_key) == 1) && (__s2_len = __builtin_strlen (profile->forward_key), __s2_len < 4 ) ? (__builtin_constant_p (input) && ((size_t)(const void *)((input) + 1) - (size_t)(const void *)(input) == 1) ? __builtin_strcmp (input, profile->forward_key) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (input); int __result = (((const unsigned char *) (const char *) (profile->forward_key))[0] - __s2[0]); if (__s2_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (profile->forward_key))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (profile->forward_key))[2 ] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (profile->forward_key ))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (input , profile->forward_key)))); })) { | ||||||
1679 | char *cmd = NULL((void*)0); | ||||||
1680 | char *new_file_path = NULL((void*)0); | ||||||
1681 | char vm_cc[256] = ""; | ||||||
1682 | char macro_buf[80] = ""; | ||||||
1683 | int ok = 0; | ||||||
1684 | |||||||
1685 | switch_xml_t x_param, x_params, x_user = NULL((void*)0); | ||||||
1686 | switch_event_t *my_params = NULL((void*)0); | ||||||
1687 | switch_bool_t vm_enabled = SWITCH_TRUE; | ||||||
1688 | |||||||
1689 | switch_snprintf(key_buf, sizeof(key_buf), "%s:%s", profile->prepend_key, profile->forward_key); | ||||||
1690 | TRY_CODE(vm_macro_get(session, VM_FORWARD_PREPEND_MACRO, key_buf, input, sizeof(input), 1, "", &term, profile->digit_timeout))do { status = vm_macro_get(session, "voicemail_forward_prepend" , key_buf, input, sizeof(input), 1, "", &term, profile-> digit_timeout); if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) { goto end; } break;} while(status ); | ||||||
1691 | if (!strcmp(input, profile->prepend_key)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (input) && __builtin_constant_p (profile->prepend_key ) && (__s1_len = __builtin_strlen (input), __s2_len = __builtin_strlen (profile->prepend_key), (!((size_t)(const void *)((input) + 1) - (size_t)(const void *)(input) == 1) || __s1_len >= 4) && (!((size_t)(const void *)((profile ->prepend_key) + 1) - (size_t)(const void *)(profile->prepend_key ) == 1) || __s2_len >= 4)) ? __builtin_strcmp (input, profile ->prepend_key) : (__builtin_constant_p (input) && ( (size_t)(const void *)((input) + 1) - (size_t)(const void *)( input) == 1) && (__s1_len = __builtin_strlen (input), __s1_len < 4) ? (__builtin_constant_p (profile->prepend_key ) && ((size_t)(const void *)((profile->prepend_key ) + 1) - (size_t)(const void *)(profile->prepend_key) == 1 ) ? __builtin_strcmp (input, profile->prepend_key) : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (profile->prepend_key); int __result = (((const unsigned char *) (const char *) (input))[0] - __s2[0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (input))[1] - __s2[1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (input))[2] - __s2[2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char * ) (const char *) (input))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p (profile->prepend_key) && ( (size_t)(const void *)((profile->prepend_key) + 1) - (size_t )(const void *)(profile->prepend_key) == 1) && (__s2_len = __builtin_strlen (profile->prepend_key), __s2_len < 4 ) ? (__builtin_constant_p (input) && ((size_t)(const void *)((input) + 1) - (size_t)(const void *)(input) == 1) ? __builtin_strcmp (input, profile->prepend_key) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (input); int __result = (((const unsigned char *) (const char *) (profile->prepend_key))[0] - __s2[0]); if (__s2_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (profile->prepend_key))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (profile->prepend_key))[2 ] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (profile->prepend_key ))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (input , profile->prepend_key)))); })) { | ||||||
1692 | switch_uuid_t uuid; | ||||||
1693 | char uuid_str[SWITCH_UUID_FORMATTED_LENGTH256 + 1]; | ||||||
1694 | switch_size_t message_len = 0; | ||||||
1695 | char *new_path = NULL((void*)0); | ||||||
1696 | |||||||
1697 | switch_uuid_get(&uuid); | ||||||
1698 | switch_uuid_format(uuid_str, &uuid); | ||||||
1699 | |||||||
1700 | forward_file_path = | ||||||
1701 | switch_core_session_sprintf(session, "%s%smsg_%s.wav", SWITCH_GLOBAL_dirs.temp_dir, SWITCH_PATH_SEPARATOR"/", uuid_str); | ||||||
1702 | TRY_CODE(create_file(session, profile, VM_RECORD_MESSAGE_MACRO, forward_file_path, &message_len, SWITCH_TRUE, NULL, NULL))do { status = create_file(session, profile, "voicemail_record_message" , forward_file_path, &message_len, SWITCH_TRUE, ((void*)0 ), ((void*)0)); if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) { goto end; } break;} while(status ); | ||||||
1703 | if ((new_path = vm_merge_file(session, profile, forward_file_path, cbt->file_path))) { | ||||||
1704 | switch_ivr_sleep(session, 1500, SWITCH_TRUE, NULL((void*)0)); | ||||||
1705 | forward_file_path = new_path; | ||||||
1706 | } else { | ||||||
1707 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "mod_voicemail.c", (const char *)__func__ , 1707, (const char*)(session), SWITCH_LOG_ERROR, "Error merging files\n"); | ||||||
1708 | TRY_CODE(switch_ivr_phrase_macro(session, VM_ACK_MACRO, "deleted", NULL, NULL))do { status = switch_ivr_phrase_macro_event(session, "voicemail_ack" , "deleted", ((void*)0), ((void*)0), ((void*)0)); if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK ) { goto end; } break;} while(status); | ||||||
1709 | goto end; | ||||||
1710 | } | ||||||
1711 | |||||||
1712 | new_file_path = forward_file_path; | ||||||
1713 | } else { | ||||||
1714 | new_file_path = cbt->file_path; | ||||||
1715 | } | ||||||
1716 | |||||||
1717 | while (!ok) { | ||||||
1718 | |||||||
1719 | xml_safe_free(x_user)if (x_user) switch_xml_free(x_user); x_user = ((void*)0); | ||||||
1720 | |||||||
1721 | switch_snprintf(macro_buf, sizeof(macro_buf), "phrase:%s:%s", VM_FORWARD_MESSAGE_ENTER_EXTENSION_MACRO"voicemail_forward_message_enter_extension", profile->terminator_key); | ||||||
1722 | vm_cc[0] = '\0'; | ||||||
1723 | |||||||
1724 | TRY_CODE(switch_ivr_readdo { status = switch_ivr_read (session, 0, sizeof(vm_cc), macro_buf , ((void*)0), vm_cc, sizeof(vm_cc), profile->digit_timeout , profile->terminator_key, 0); if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) { goto end; } break ;} while(status) | ||||||
1725 | (session, 0, sizeof(vm_cc), macro_buf, NULL, vm_cc, sizeof(vm_cc), profile->digit_timeout, profile->terminator_key, 0))do { status = switch_ivr_read (session, 0, sizeof(vm_cc), macro_buf , ((void*)0), vm_cc, sizeof(vm_cc), profile->digit_timeout , profile->terminator_key, 0); if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) { goto end; } break ;} while(status); | ||||||
1726 | |||||||
1727 | cmd = switch_core_session_sprintf(session, "%s@%s@%s %s %s '%s'", vm_cc, cbt->domain, profile->name, | ||||||
1728 | new_file_path, cbt->cid_number, cbt->cid_name); | ||||||
1729 | |||||||
1730 | switch_event_create(&my_params, SWITCH_EVENT_REQUEST_PARAMS)switch_event_create_subclass_detailed("mod_voicemail.c", (const char * )(const char *)__func__, 1730, &my_params, SWITCH_EVENT_REQUEST_PARAMS , ((void*)0)); | ||||||
1731 | switch_assert(my_params)((my_params) ? (void) (0) : __assert_fail ("my_params", "mod_voicemail.c" , 1731, __PRETTY_FUNCTION__)); | ||||||
1732 | |||||||
1733 | status = switch_xml_locate_user_merged("id:number-alias", vm_cc, cbt->domain, NULL((void*)0), &x_user, my_params); | ||||||
1734 | switch_event_destroy(&my_params); | ||||||
1735 | |||||||
1736 | if (status != SWITCH_STATUS_SUCCESS) { | ||||||
1737 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "mod_voicemail.c", (const char *)__func__ , 1737, (const char*)(session), SWITCH_LOG_WARNING, | ||||||
1738 | "Failed to forward message - Cannot locate user %s@%s\n", vm_cc, cbt->domain); | ||||||
1739 | TRY_CODE(switch_ivr_phrase_macro(session, VM_INVALID_EXTENSION_MACRO, vm_cc, NULL, NULL))do { status = switch_ivr_phrase_macro_event(session, "voicemail_invalid_extension" , vm_cc, ((void*)0), ((void*)0), ((void*)0)); if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) { goto end; } break ;} while(status); | ||||||
1740 | continue; | ||||||
1741 | } else { | ||||||
1742 | x_params = switch_xml_child(x_user, "params"); | ||||||
1743 | |||||||
1744 | for (x_param = switch_xml_child(x_params, "param"); x_param; x_param = x_param->next) { | ||||||
1745 | const char *var = switch_xml_attr_soft(x_param, "name"); | ||||||
1746 | const char *val = switch_xml_attr_soft(x_param, "value"); | ||||||
1747 | if (zstr(var)_zstr(var) || zstr(val)_zstr(val)) { | ||||||
1748 | continue; /* Ignore empty entires */ | ||||||
1749 | } | ||||||
1750 | |||||||
1751 | if (!strcasecmp(var, "vm-enabled")) { | ||||||
1752 | vm_enabled = !switch_false(val); | ||||||
1753 | } | ||||||
1754 | } | ||||||
1755 | |||||||
1756 | if (!vm_enabled) { | ||||||
1757 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "mod_voicemail.c", (const char *)__func__ , 1757, (const char*)(session), SWITCH_LOG_WARNING, "Failed to forward message - Voicemail is disabled for user %s@%s\n", vm_cc, cbt->domain); | ||||||
1758 | TRY_CODE(switch_ivr_phrase_macro(session, VM_INVALID_EXTENSION_MACRO, vm_cc, NULL, NULL))do { status = switch_ivr_phrase_macro_event(session, "voicemail_invalid_extension" , vm_cc, ((void*)0), ((void*)0), ((void*)0)); if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) { goto end; } break ;} while(status); | ||||||
1759 | continue; | ||||||
1760 | } else { | ||||||
1761 | if (voicemail_inject(cmd, session) == SWITCH_STATUS_SUCCESS) { | ||||||
1762 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "mod_voicemail.c", (const char *)__func__ , 1762, (const char*)(session), SWITCH_LOG_NOTICE, "Forwarded message to %s\n", vm_cc); | ||||||
1763 | TRY_CODE(switch_ivr_phrase_macro(session, VM_ACK_MACRO, "saved", NULL, NULL))do { status = switch_ivr_phrase_macro_event(session, "voicemail_ack" , "saved", ((void*)0), ((void*)0), ((void*)0)); if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK ) { goto end; } break;} while(status); | ||||||
1764 | cbt->move = VM_MOVE_SAME; | ||||||
1765 | } else { | ||||||
1766 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "mod_voicemail.c", (const char *)__func__ , 1766, (const char*)(session), SWITCH_LOG_ERROR, "Failed to forward message to %s\n", vm_cc); | ||||||
1767 | TRY_CODE(switch_ivr_phrase_macro(session, VM_INVALID_EXTENSION_MACRO, vm_cc, NULL, NULL))do { status = switch_ivr_phrase_macro_event(session, "voicemail_invalid_extension" , vm_cc, ((void*)0), ((void*)0), ((void*)0)); if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) { goto end; } break ;} while(status); | ||||||
1768 | continue; | ||||||
1769 | } | ||||||
1770 | } | ||||||
1771 | } | ||||||
1772 | |||||||
1773 | xml_safe_free(x_user)if (x_user) switch_xml_free(x_user); x_user = ((void*)0); | ||||||
1774 | |||||||
1775 | break; | ||||||
1776 | } | ||||||
1777 | |||||||
1778 | } else if (!strcmp(input, profile->delete_file_key)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (input) && __builtin_constant_p (profile->delete_file_key ) && (__s1_len = __builtin_strlen (input), __s2_len = __builtin_strlen (profile->delete_file_key), (!((size_t)( const void *)((input) + 1) - (size_t)(const void *)(input) == 1) || __s1_len >= 4) && (!((size_t)(const void *) ((profile->delete_file_key) + 1) - (size_t)(const void *)( profile->delete_file_key) == 1) || __s2_len >= 4)) ? __builtin_strcmp (input, profile->delete_file_key) : (__builtin_constant_p (input) && ((size_t)(const void *)((input) + 1) - (size_t )(const void *)(input) == 1) && (__s1_len = __builtin_strlen (input), __s1_len < 4) ? (__builtin_constant_p (profile-> delete_file_key) && ((size_t)(const void *)((profile-> delete_file_key) + 1) - (size_t)(const void *)(profile->delete_file_key ) == 1) ? __builtin_strcmp (input, profile->delete_file_key ) : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (profile->delete_file_key); int __result = (((const unsigned char *) (const char *) (input))[0] - __s2 [0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (input))[1] - __s2 [1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (input))[2] - __s2 [2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (input))[3] - __s2[ 3]); } } __result; }))) : (__builtin_constant_p (profile-> delete_file_key) && ((size_t)(const void *)((profile-> delete_file_key) + 1) - (size_t)(const void *)(profile->delete_file_key ) == 1) && (__s2_len = __builtin_strlen (profile-> delete_file_key), __s2_len < 4) ? (__builtin_constant_p (input ) && ((size_t)(const void *)((input) + 1) - (size_t)( const void *)(input) == 1) ? __builtin_strcmp (input, profile ->delete_file_key) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (input); int __result = (((const unsigned char *) (const char *) (profile->delete_file_key ))[0] - __s2[0]); if (__s2_len > 0 && __result == 0 ) { __result = (((const unsigned char *) (const char *) (profile ->delete_file_key))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (profile->delete_file_key))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (profile->delete_file_key))[3] - __s2 [3]); } } __result; })))) : __builtin_strcmp (input, profile-> delete_file_key)))); }) || (!strcmp(input, profile->email_key)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (input) && __builtin_constant_p (profile->email_key ) && (__s1_len = __builtin_strlen (input), __s2_len = __builtin_strlen (profile->email_key), (!((size_t)(const void *)((input) + 1) - (size_t)(const void *)(input) == 1) || __s1_len >= 4) && (!((size_t)(const void *)((profile->email_key ) + 1) - (size_t)(const void *)(profile->email_key) == 1) || __s2_len >= 4)) ? __builtin_strcmp (input, profile->email_key ) : (__builtin_constant_p (input) && ((size_t)(const void *)((input) + 1) - (size_t)(const void *)(input) == 1) && (__s1_len = __builtin_strlen (input), __s1_len < 4) ? (__builtin_constant_p (profile->email_key) && ((size_t)(const void *)(( profile->email_key) + 1) - (size_t)(const void *)(profile-> email_key) == 1) ? __builtin_strcmp (input, profile->email_key ) : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (profile->email_key); int __result = (((const unsigned char *) (const char *) (input))[0] - __s2 [0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (input))[1] - __s2 [1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (input))[2] - __s2 [2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (input))[3] - __s2[ 3]); } } __result; }))) : (__builtin_constant_p (profile-> email_key) && ((size_t)(const void *)((profile->email_key ) + 1) - (size_t)(const void *)(profile->email_key) == 1) && (__s2_len = __builtin_strlen (profile->email_key), __s2_len < 4) ? (__builtin_constant_p (input) && ((size_t) (const void *)((input) + 1) - (size_t)(const void *)(input) == 1) ? __builtin_strcmp (input, profile->email_key) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (input); int __result = (((const unsigned char *) (const char *) (profile->email_key))[0] - __s2[0]); if (__s2_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (profile->email_key))[1] - __s2[1] ); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (profile->email_key ))[2] - __s2[2]); if (__s2_len > 2 && __result == 0 ) __result = (((const unsigned char *) (const char *) (profile ->email_key))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (input, profile->email_key)))); }) && !zstr(cbt->email)_zstr(cbt->email))) { | ||||||
1779 | char *sql = switch_mprintf("update voicemail_msgs set flags='delete' where uuid='%s'", cbt->uuid); | ||||||
1780 | vm_execute_sql(profile, sql, profile->mutex); | ||||||
1781 | switch_safe_free(sql)if (sql) {free(sql);sql=((void*)0);}; | ||||||
1782 | if (!strcmp(input, profile->email_key)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (input) && __builtin_constant_p (profile->email_key ) && (__s1_len = __builtin_strlen (input), __s2_len = __builtin_strlen (profile->email_key), (!((size_t)(const void *)((input) + 1) - (size_t)(const void *)(input) == 1) || __s1_len >= 4) && (!((size_t)(const void *)((profile->email_key ) + 1) - (size_t)(const void *)(profile->email_key) == 1) || __s2_len >= 4)) ? __builtin_strcmp (input, profile->email_key ) : (__builtin_constant_p (input) && ((size_t)(const void *)((input) + 1) - (size_t)(const void *)(input) == 1) && (__s1_len = __builtin_strlen (input), __s1_len < 4) ? (__builtin_constant_p (profile->email_key) && ((size_t)(const void *)(( profile->email_key) + 1) - (size_t)(const void *)(profile-> email_key) == 1) ? __builtin_strcmp (input, profile->email_key ) : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (profile->email_key); int __result = (((const unsigned char *) (const char *) (input))[0] - __s2 [0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (input))[1] - __s2 [1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (input))[2] - __s2 [2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (input))[3] - __s2[ 3]); } } __result; }))) : (__builtin_constant_p (profile-> email_key) && ((size_t)(const void *)((profile->email_key ) + 1) - (size_t)(const void *)(profile->email_key) == 1) && (__s2_len = __builtin_strlen (profile->email_key), __s2_len < 4) ? (__builtin_constant_p (input) && ((size_t) (const void *)((input) + 1) - (size_t)(const void *)(input) == 1) ? __builtin_strcmp (input, profile->email_key) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (input); int __result = (((const unsigned char *) (const char *) (profile->email_key))[0] - __s2[0]); if (__s2_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (profile->email_key))[1] - __s2[1] ); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (profile->email_key ))[2] - __s2[2]); if (__s2_len > 2 && __result == 0 ) __result = (((const unsigned char *) (const char *) (profile ->email_key))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (input, profile->email_key)))); }) && !zstr(cbt->email)_zstr(cbt->email)) { | ||||||
1783 | switch_event_t *event; | ||||||
1784 | char *from; | ||||||
1785 | char *headers, *header_string; | ||||||
1786 | char *body; | ||||||
1787 | int priority = 3; | ||||||
1788 | switch_size_t retsize; | ||||||
1789 | switch_time_exp_t tm; | ||||||
1790 | char date[80] = ""; | ||||||
1791 | char tmp[50] = ""; | ||||||
1792 | int total_new_messages = 0; | ||||||
1793 | int total_saved_messages = 0; | ||||||
1794 | int total_new_urgent_messages = 0; | ||||||
1795 | int total_saved_urgent_messages = 0; | ||||||
1796 | int32_t message_len = 0; | ||||||
1797 | char *p; | ||||||
1798 | switch_time_t l_duration = 0; | ||||||
1799 | switch_core_time_duration_t duration; | ||||||
1800 | char duration_str[80]; | ||||||
1801 | char *formatted_cid_num = NULL((void*)0); | ||||||
1802 | if (!strcasecmp(cbt->read_flags, URGENT_FLAG_STRING"A_URGENT")) { | ||||||
1803 | priority = 1; | ||||||
1804 | } | ||||||
1805 | |||||||
1806 | message_count(profile, cbt->user, cbt->domain, cbt->in_folder, &total_new_messages, &total_saved_messages, | ||||||
1807 | &total_new_urgent_messages, &total_saved_urgent_messages); | ||||||
1808 | |||||||
1809 | switch_time_exp_lt(&tm, switch_time_make(atol(cbt->created_epoch), 0)); | ||||||
1810 | switch_strftime(date, &retsize, sizeof(date), profile->date_fmt, &tm); | ||||||
1811 | |||||||
1812 | formatted_cid_num = switch_format_number(cbt->cid_number); | ||||||
1813 | |||||||
1814 | switch_snprintf(tmp, sizeof(tmp), "%d", total_new_messages); | ||||||
1815 | switch_channel_set_variable(channel, "voicemail_total_new_messages", tmp)switch_channel_set_variable_var_check(channel, "voicemail_total_new_messages" , tmp, SWITCH_TRUE); | ||||||
1816 | switch_snprintf(tmp, sizeof(tmp), "%d", total_saved_messages); | ||||||
1817 | switch_channel_set_variable(channel, "voicemail_total_saved_messages", tmp)switch_channel_set_variable_var_check(channel, "voicemail_total_saved_messages" , tmp, SWITCH_TRUE); | ||||||
1818 | switch_snprintf(tmp, sizeof(tmp), "%d", total_new_urgent_messages); | ||||||
1819 | switch_channel_set_variable(channel, "voicemail_urgent_new_messages", tmp)switch_channel_set_variable_var_check(channel, "voicemail_urgent_new_messages" , tmp, SWITCH_TRUE); | ||||||
1820 | switch_snprintf(tmp, sizeof(tmp), "%d", total_saved_urgent_messages); | ||||||
1821 | switch_channel_set_variable(channel, "voicemail_urgent_saved_messages", tmp)switch_channel_set_variable_var_check(channel, "voicemail_urgent_saved_messages" , tmp, SWITCH_TRUE); | ||||||
1822 | switch_channel_set_variable(channel, "voicemail_current_folder", cbt->in_folder)switch_channel_set_variable_var_check(channel, "voicemail_current_folder" , cbt->in_folder, SWITCH_TRUE); | ||||||
1823 | switch_channel_set_variable(channel, "voicemail_account", cbt->user)switch_channel_set_variable_var_check(channel, "voicemail_account" , cbt->user, SWITCH_TRUE); | ||||||
1824 | switch_channel_set_variable(channel, "voicemail_domain", cbt->domain)switch_channel_set_variable_var_check(channel, "voicemail_domain" , cbt->domain, SWITCH_TRUE); | ||||||
1825 | switch_channel_set_variable(channel, "voicemail_caller_id_number", cbt->cid_number)switch_channel_set_variable_var_check(channel, "voicemail_caller_id_number" , cbt->cid_number, SWITCH_TRUE); | ||||||
1826 | switch_channel_set_variable(channel, "voicemail_formatted_caller_id_number", formatted_cid_num)switch_channel_set_variable_var_check(channel, "voicemail_formatted_caller_id_number" , formatted_cid_num, SWITCH_TRUE); | ||||||
1827 | switch_channel_set_variable(channel, "voicemail_caller_id_name", cbt->cid_name)switch_channel_set_variable_var_check(channel, "voicemail_caller_id_name" , cbt->cid_name, SWITCH_TRUE); | ||||||
1828 | switch_channel_set_variable(channel, "voicemail_file_path", cbt->file_path)switch_channel_set_variable_var_check(channel, "voicemail_file_path" , cbt->file_path, SWITCH_TRUE); | ||||||
1829 | switch_channel_set_variable(channel, "voicemail_read_flags", cbt->read_flags)switch_channel_set_variable_var_check(channel, "voicemail_read_flags" , cbt->read_flags, SWITCH_TRUE); | ||||||
1830 | switch_channel_set_variable(channel, "voicemail_time", date)switch_channel_set_variable_var_check(channel, "voicemail_time" , date, SWITCH_TRUE); | ||||||
1831 | switch_snprintf(tmp, sizeof(tmp), "%d", priority); | ||||||
1832 | switch_channel_set_variable(channel, "voicemail_priority", tmp)switch_channel_set_variable_var_check(channel, "voicemail_priority" , tmp, SWITCH_TRUE); | ||||||
1833 | message_len = atoi(cbt->message_len); | ||||||
1834 | switch_safe_free(formatted_cid_num)if (formatted_cid_num) {free(formatted_cid_num);formatted_cid_num =((void*)0);}; | ||||||
1835 | |||||||
1836 | l_duration = switch_time_make(atol(cbt->message_len), 0); | ||||||
1837 | switch_core_measure_time(l_duration, &duration); | ||||||
1838 | duration.day += duration.yr * 365; | ||||||
1839 | duration.hr += duration.day * 24; | ||||||
1840 | |||||||
1841 | switch_snprintf(duration_str, sizeof(duration_str), "%.2u:%.2u:%.2u", duration.hr, duration.min, duration.sec); | ||||||
1842 | |||||||
1843 | switch_channel_set_variable(channel, "voicemail_message_len", duration_str)switch_channel_set_variable_var_check(channel, "voicemail_message_len" , duration_str, SWITCH_TRUE); | ||||||
1844 | switch_channel_set_variable(channel, "voicemail_email", cbt->email)switch_channel_set_variable_var_check(channel, "voicemail_email" , cbt->email, SWITCH_TRUE); | ||||||
1845 | |||||||
1846 | if (zstr(profile->email_headers)_zstr(profile->email_headers)) { | ||||||
1847 | from = switch_core_session_sprintf(session, "%s@%s", cbt->user, cbt->domain); | ||||||
1848 | } else { | ||||||
1849 | from = switch_channel_expand_variables(channel, profile->email_from)switch_channel_expand_variables_check(channel, profile->email_from , ((void*)0), ((void*)0), 0); | ||||||
1850 | } | ||||||
1851 | |||||||
1852 | if (zstr(profile->email_headers)_zstr(profile->email_headers)) { | ||||||
1853 | headers = switch_core_session_sprintf(session, | ||||||
1854 | "From: FreeSWITCH mod_voicemail <%s@%s>\nSubject: Voicemail from %s %s\nX-Priority: %d", | ||||||
1855 | cbt->user, cbt->domain, cbt->cid_name, cbt->cid_number, priority); | ||||||
1856 | } else { | ||||||
1857 | headers = switch_channel_expand_variables(channel, profile->email_headers)switch_channel_expand_variables_check(channel, profile->email_headers , ((void*)0), ((void*)0), 0); | ||||||
1858 | } | ||||||
1859 | |||||||
1860 | p = headers + (strlen(headers) - 1); | ||||||
1861 | if (*p == '\n') { | ||||||
1862 | if (*(p - 1) == '\r') { | ||||||
1863 | p--; | ||||||
1864 | } | ||||||
1865 | *p = '\0'; | ||||||
1866 | } | ||||||
1867 | |||||||
1868 | header_string = switch_core_session_sprintf(session, "%s\nX-Voicemail-Length: %u", headers, message_len); | ||||||
1869 | |||||||
1870 | if (switch_event_create(&event, SWITCH_EVENT_GENERAL)switch_event_create_subclass_detailed("mod_voicemail.c", (const char * )(const char *)__func__, 1870, &event, SWITCH_EVENT_GENERAL , ((void*)0)) == SWITCH_STATUS_SUCCESS) { | ||||||
1871 | /* this isn't done? it was in the other place | ||||||
1872 | * switch_channel_event_set_data(channel, event); | ||||||
1873 | */ | ||||||
1874 | switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Message-Type", "forwarded-voicemail"); | ||||||
1875 | switch_event_fire(&event)switch_event_fire_detailed("mod_voicemail.c", (const char * ) (const char *)__func__, 1875, &event, ((void*)0)); | ||||||
1876 | } | ||||||
1877 | |||||||
1878 | if (profile->email_body) { | ||||||
1879 | body = switch_channel_expand_variables(channel, profile->email_body)switch_channel_expand_variables_check(channel, profile->email_body , ((void*)0), ((void*)0), 0); | ||||||
1880 | } else { | ||||||
1881 | body = switch_mprintf("%u second Voicemail from %s %s", message_len, cbt->cid_name, cbt->cid_number); | ||||||
1882 | } | ||||||
1883 | |||||||
1884 | switch_simple_email(cbt->email, from, header_string, body, cbt->file_path, cbt->convert_cmd, cbt->convert_ext); | ||||||
1885 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "mod_voicemail.c", (const char *)__func__ , 1885, (const char*)(session), SWITCH_LOG_DEBUG, "Sending message to %s\n", cbt->email); | ||||||
1886 | switch_safe_free(body)if (body) {free(body);body=((void*)0);}; | ||||||
1887 | TRY_CODE(switch_ivr_phrase_macro(session, VM_ACK_MACRO, "emailed", NULL, NULL))do { status = switch_ivr_phrase_macro_event(session, "voicemail_ack" , "emailed", ((void*)0), ((void*)0), ((void*)0)); if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK ) { goto end; } break;} while(status); | ||||||
1888 | } else { | ||||||
1889 | TRY_CODE(switch_ivr_phrase_macro(session, VM_ACK_MACRO, "deleted", NULL, NULL))do { status = switch_ivr_phrase_macro_event(session, "voicemail_ack" , "deleted", ((void*)0), ((void*)0), ((void*)0)); if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK ) { goto end; } break;} while(status); | ||||||
1890 | } | ||||||
1891 | } else { | ||||||
1892 | char *sql = switch_mprintf("update voicemail_msgs set flags='save' where uuid='%s'", cbt->uuid); | ||||||
1893 | vm_execute_sql(profile, sql, profile->mutex); | ||||||
1894 | switch_safe_free(sql)if (sql) {free(sql);sql=((void*)0);}; | ||||||
1895 | TRY_CODE(switch_ivr_phrase_macro(session, VM_ACK_MACRO, "saved", NULL, NULL))do { status = switch_ivr_phrase_macro_event(session, "voicemail_ack" , "saved", ((void*)0), ((void*)0), ((void*)0)); if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK ) { goto end; } break;} while(status); | ||||||
1896 | } | ||||||
1897 | } | ||||||
1898 | } | ||||||
1899 | |||||||
1900 | end: | ||||||
1901 | |||||||
1902 | if (forward_file_path) { | ||||||
1903 | if (unlink(forward_file_path) != 0) { | ||||||
1904 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "mod_voicemail.c", (const char *)__func__ , 1904, (const char*)(session), SWITCH_LOG_WARNING, "Failed to delete file [%s]\n", forward_file_path); | ||||||
1905 | } | ||||||
1906 | } | ||||||
1907 | |||||||
1908 | return status; | ||||||
1909 | } | ||||||
1910 | |||||||
1911 | |||||||
1912 | static void update_mwi(vm_profile_t *profile, const char *id, const char *domain_name, const char *myfolder, mwi_reason_t reason) | ||||||
1913 | { | ||||||
1914 | const char *yn = "no"; | ||||||
1915 | const char *update_reason = mwi_reason2str(reason); | ||||||
1916 | int total_new_messages = 0; | ||||||
1917 | int total_saved_messages = 0; | ||||||
1918 | int total_new_urgent_messages = 0; | ||||||
1919 | int total_saved_urgent_messages = 0; | ||||||
1920 | switch_event_t *event; | ||||||
1921 | switch_event_t *message_event; | ||||||
1922 | |||||||
1923 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 1923, ((void*)0), SWITCH_LOG_DEBUG, "Update MWI: Processing for %s@%s in %s\n", id, domain_name, myfolder); | ||||||
1924 | |||||||
1925 | message_count(profile, id, domain_name, myfolder, &total_new_messages, &total_saved_messages, &total_new_urgent_messages, | ||||||
1926 | &total_saved_urgent_messages); | ||||||
1927 | |||||||
1928 | if (switch_event_create(&event, SWITCH_EVENT_MESSAGE_WAITING)switch_event_create_subclass_detailed("mod_voicemail.c", (const char * )(const char *)__func__, 1928, &event, SWITCH_EVENT_MESSAGE_WAITING , ((void*)0)) != SWITCH_STATUS_SUCCESS) { | ||||||
1929 | return; | ||||||
1930 | } | ||||||
1931 | |||||||
1932 | if (total_new_messages || total_new_urgent_messages) { | ||||||
1933 | yn = "yes"; | ||||||
1934 | } | ||||||
1935 | switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "MWI-Messages-Waiting", yn); | ||||||
1936 | switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Update-Reason", update_reason); | ||||||
1937 | switch_event_add_header(event, SWITCH_STACK_BOTTOM, "MWI-Message-Account", "%s@%s", id, domain_name); | ||||||
1938 | /* | ||||||
1939 | switch_event_add_header(event, SWITCH_STACK_BOTTOM, "MWI-Voice-Message", "%d/%d (%d/%d)", total_new_messages, total_saved_messages, | ||||||
1940 | total_new_urgent_messages, total_saved_urgent_messages); | ||||||
1941 | */ | ||||||
1942 | switch_event_add_header(event, SWITCH_STACK_BOTTOM, "MWI-Voice-Message", "%d/%d", total_new_messages, total_saved_messages); | ||||||
1943 | |||||||
1944 | switch_event_fire(&event)switch_event_fire_detailed("mod_voicemail.c", (const char * ) (const char *)__func__, 1944, &event, ((void*)0)); | ||||||
1945 | |||||||
1946 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 1946, ((void*)0), SWITCH_LOG_DEBUG, "Update MWI: Messages Waiting %s\n", yn); | ||||||
1947 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 1947, ((void*)0), SWITCH_LOG_DEBUG, "Update MWI: Update Reason %s\n", update_reason); | ||||||
1948 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 1948, ((void*)0), SWITCH_LOG_DEBUG, "Update MWI: Message Account %s@%s\n", id, domain_name); | ||||||
1949 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 1949, ((void*)0), SWITCH_LOG_DEBUG, "Update MWI: Voice Message %d/%d\n", total_new_messages, total_saved_messages); | ||||||
1950 | |||||||
1951 | switch_event_create_subclass(&message_event, SWITCH_EVENT_CUSTOM, VM_EVENT_MAINT)switch_event_create_subclass_detailed("mod_voicemail.c", (const char * )(const char *)__func__, 1951, &message_event, SWITCH_EVENT_CUSTOM , "vm::maintenance"); | ||||||
1952 | switch_event_add_header_string(message_event, SWITCH_STACK_BOTTOM, "VM-Action", "mwi-update"); | ||||||
1953 | switch_event_add_header_string(message_event, SWITCH_STACK_BOTTOM, "VM-User", id); | ||||||
1954 | switch_event_add_header_string(message_event, SWITCH_STACK_BOTTOM, "VM-Domain", domain_name); | ||||||
1955 | switch_event_add_header(message_event, SWITCH_STACK_BOTTOM, "VM-Total-New", "%d", total_new_messages); | ||||||
1956 | switch_event_add_header(message_event, SWITCH_STACK_BOTTOM, "VM-Total-Saved", "%d", total_saved_messages); | ||||||
1957 | switch_event_add_header(message_event, SWITCH_STACK_BOTTOM, "VM-Total-New-Urgent", "%d", total_new_urgent_messages); | ||||||
1958 | switch_event_add_header(message_event, SWITCH_STACK_BOTTOM, "VM-Total-Saved-Urgent", "%d", total_saved_urgent_messages); | ||||||
1959 | |||||||
1960 | switch_event_fire(&message_event)switch_event_fire_detailed("mod_voicemail.c", (const char * ) (const char *)__func__, 1960, &message_event, ((void*)0)); | ||||||
1961 | } | ||||||
1962 | |||||||
1963 | static void voicemail_check_main(switch_core_session_t *session, vm_profile_t *profile, const char *domain_name, const char *id, int auth, const char *uuid_in) | ||||||
1964 | { | ||||||
1965 | vm_check_state_t vm_check_state = VM_CHECK_START; | ||||||
1966 | switch_channel_t *channel = switch_core_session_get_channel(session); | ||||||
1967 | switch_caller_profile_t *caller_profile = switch_channel_get_caller_profile(channel); | ||||||
1968 | switch_xml_t x_user = NULL((void*)0), x_params, x_param; | ||||||
1969 | switch_status_t status; | ||||||
1970 | char pass_buf[80] = "", *mypass = NULL((void*)0), id_buf[80] = "", *myfolder = NULL((void*)0); | ||||||
1971 | const char *thepass = NULL((void*)0), *myid = id, *thehash = NULL((void*)0), *vmhash = NULL((void*)0); | ||||||
1972 | char term = 0; | ||||||
1973 | uint32_t timeout, attempts = 0, retries = 0; | ||||||
1974 | int failed = 0; | ||||||
1975 | msg_type_t play_msg_type = MSG_NONE; | ||||||
1976 | char *dir_path = NULL((void*)0), *file_path = NULL((void*)0), *tmp_file_path = NULL((void*)0); | ||||||
1977 | int total_new_messages = 0; | ||||||
1978 | int total_saved_messages = 0; | ||||||
1979 | int total_new_urgent_messages = 0; | ||||||
1980 | int total_saved_urgent_messages = 0; | ||||||
1981 | int heard_auto_new = 0; | ||||||
1982 | char *vm_email = NULL((void*)0), *email_addr = NULL((void*)0); | ||||||
1983 | char *convert_cmd = profile->convert_cmd; | ||||||
1984 | char *convert_ext = profile->convert_ext; | ||||||
1985 | char *vm_storage_dir = NULL((void*)0); | ||||||
1986 | char *storage_dir = NULL((void*)0); | ||||||
1987 | char global_buf[2] = ""; | ||||||
1988 | switch_input_args_t args = { 0 }; | ||||||
1989 | const char *caller_id_number = NULL((void*)0); | ||||||
1990 | int auth_only = 0, authed = 0; | ||||||
1991 | switch_event_t *event; | ||||||
1992 | |||||||
1993 | if (!(caller_id_number = switch_channel_get_variable(channel, "effective_caller_id_number")switch_channel_get_variable_dup(channel, "effective_caller_id_number" , SWITCH_TRUE, -1))) { | ||||||
1994 | caller_id_number = caller_profile->caller_id_number; | ||||||
1995 | } | ||||||
1996 | |||||||
1997 | if (auth == 2) { | ||||||
1998 | auth_only = 1; | ||||||
1999 | auth = 0; | ||||||
2000 | } else { | ||||||
2001 | auth_only = switch_true(switch_channel_get_variable(channel, "vm_auth_only")switch_channel_get_variable_dup(channel, "vm_auth_only", SWITCH_TRUE , -1)); | ||||||
2002 | } | ||||||
2003 | |||||||
2004 | timeout = profile->digit_timeout; | ||||||
2005 | attempts = profile->max_login_attempts; | ||||||
2006 | switch_ivr_phrase_macro(session, VM_HELLO_MACRO, NULL, NULL, &args)switch_ivr_phrase_macro_event(session, "voicemail_hello", ((void *)0), ((void*)0), ((void*)0), &args); | ||||||
2007 | *global_buf = '\0'; | ||||||
2008 | |||||||
2009 | while (switch_channel_ready(channel)switch_channel_test_ready(channel, SWITCH_TRUE, SWITCH_FALSE)) { | ||||||
2010 | switch_ivr_sleep(session, 100, SWITCH_TRUE, NULL((void*)0)); | ||||||
2011 | |||||||
2012 | switch (vm_check_state) { | ||||||
2013 | case VM_CHECK_START: | ||||||
2014 | { | ||||||
2015 | total_new_messages = 0; | ||||||
2016 | total_saved_messages = 0; | ||||||
2017 | total_new_urgent_messages = 0; | ||||||
2018 | total_saved_urgent_messages = 0; | ||||||
2019 | heard_auto_new = 0; | ||||||
2020 | play_msg_type = MSG_NONE; | ||||||
2021 | attempts = profile->max_login_attempts; | ||||||
2022 | retries = profile->max_retries; | ||||||
2023 | myid = id; | ||||||
2024 | mypass = NULL((void*)0); | ||||||
2025 | myfolder = "inbox"; | ||||||
2026 | vm_check_state = VM_CHECK_AUTH; | ||||||
2027 | xml_safe_free(x_user)if (x_user) switch_xml_free(x_user); x_user = ((void*)0); | ||||||
2028 | } | ||||||
2029 | break; | ||||||
2030 | case VM_CHECK_FOLDER_SUMMARY: | ||||||
2031 | { | ||||||
2032 | int informed = 0; | ||||||
2033 | char msg_count[80] = ""; | ||||||
2034 | switch_input_args_t folder_args = { 0 }; | ||||||
2035 | switch_event_t *params; | ||||||
2036 | const char *vm_auto_play = switch_channel_get_variable(channel, "vm_auto_play")switch_channel_get_variable_dup(channel, "vm_auto_play", SWITCH_TRUE , -1); | ||||||
2037 | int auto_play = 1; | ||||||
2038 | |||||||
2039 | if (vm_auto_play && !switch_true(vm_auto_play)) { | ||||||
2040 | auto_play = 0; | ||||||
2041 | } | ||||||
2042 | |||||||
2043 | folder_args.input_callback = cancel_on_dtmf; | ||||||
2044 | folder_args.buf = &global_buf; | ||||||
2045 | folder_args.buflen = sizeof(global_buf); | ||||||
2046 | |||||||
2047 | switch_channel_set_variable(channel, "voicemail_current_folder", myfolder)switch_channel_set_variable_var_check(channel, "voicemail_current_folder" , myfolder, SWITCH_TRUE); | ||||||
2048 | message_count(profile, myid, domain_name, myfolder, &total_new_messages, &total_saved_messages, | ||||||
2049 | &total_new_urgent_messages, &total_saved_urgent_messages); | ||||||
2050 | |||||||
2051 | |||||||
2052 | switch_event_create_subclass(¶ms, SWITCH_EVENT_CUSTOM, VM_EVENT_MAINT)switch_event_create_subclass_detailed("mod_voicemail.c", (const char * )(const char *)__func__, 2052, ¶ms, SWITCH_EVENT_CUSTOM , "vm::maintenance"); | ||||||
2053 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "VM-Action", "folder-summary"); | ||||||
2054 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "VM-User", myid); | ||||||
2055 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "VM-Domain", domain_name); | ||||||
2056 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "VM-Folder", myfolder); | ||||||
2057 | switch_event_add_header(params, SWITCH_STACK_BOTTOM, "VM-Total-New-Messages", "%u", total_new_messages); | ||||||
2058 | switch_event_add_header(params, SWITCH_STACK_BOTTOM, "VM-Total-Saved-Messages", "%u", total_saved_messages); | ||||||
2059 | switch_event_add_header(params, SWITCH_STACK_BOTTOM, "VM-Total-New-Urgent-Messages", "%u", total_new_urgent_messages); | ||||||
2060 | switch_event_add_header(params, SWITCH_STACK_BOTTOM, "VM-Total-Saved-Urgent-Messages", "%u", total_saved_urgent_messages); | ||||||
2061 | switch_event_fire(¶ms)switch_event_fire_detailed("mod_voicemail.c", (const char * ) (const char *)__func__, 2061, ¶ms, ((void*)0)); | ||||||
2062 | |||||||
2063 | if (total_new_urgent_messages > 0) { | ||||||
2064 | switch_snprintf(msg_count, sizeof(msg_count), "%d:urgent-new", total_new_urgent_messages); | ||||||
2065 | TRY_CODE(switch_ivr_phrase_macro(session, VM_MESSAGE_COUNT_MACRO, msg_count, NULL, &folder_args))do { status = switch_ivr_phrase_macro_event(session, "voicemail_message_count" , msg_count, ((void*)0), ((void*)0), &folder_args); if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK ) { goto end; } break;} while(status); | ||||||
2066 | informed++; | ||||||
2067 | if (auto_play && !zstr_buf(global_buf)(*(global_buf) == '\0')) { | ||||||
2068 | vm_check_state = VM_CHECK_MENU; | ||||||
2069 | continue; | ||||||
2070 | } | ||||||
2071 | } | ||||||
2072 | |||||||
2073 | if (total_new_messages > 0 && total_new_messages != total_new_urgent_messages) { | ||||||
2074 | switch_snprintf(msg_count, sizeof(msg_count), "%d:new", total_new_messages); | ||||||
2075 | TRY_CODE(switch_ivr_phrase_macro(session, VM_MESSAGE_COUNT_MACRO, msg_count, NULL, &folder_args))do { status = switch_ivr_phrase_macro_event(session, "voicemail_message_count" , msg_count, ((void*)0), ((void*)0), &folder_args); if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK ) { goto end; } break;} while(status); | ||||||
2076 | informed++; | ||||||
2077 | if (auto_play && !zstr_buf(global_buf)(*(global_buf) == '\0')) { | ||||||
2078 | vm_check_state = VM_CHECK_MENU; | ||||||
2079 | continue; | ||||||
2080 | } | ||||||
2081 | } | ||||||
2082 | |||||||
2083 | if (auto_play && !heard_auto_new && total_new_messages + total_new_urgent_messages > 0) { | ||||||
2084 | heard_auto_new = 1; | ||||||
2085 | play_msg_type = MSG_NEW; | ||||||
2086 | vm_check_state = VM_CHECK_PLAY_MESSAGES; | ||||||
2087 | continue; | ||||||
2088 | } | ||||||
2089 | |||||||
2090 | if (!informed) { | ||||||
2091 | switch_snprintf(msg_count, sizeof(msg_count), "0:new"); | ||||||
2092 | TRY_CODE(switch_ivr_phrase_macro(session, VM_MESSAGE_COUNT_MACRO, msg_count, NULL, &folder_args))do { status = switch_ivr_phrase_macro_event(session, "voicemail_message_count" , msg_count, ((void*)0), ((void*)0), &folder_args); if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK ) { goto end; } break;} while(status); | ||||||
2093 | switch_snprintf(msg_count, sizeof(msg_count), "%d:saved", total_saved_messages); | ||||||
2094 | TRY_CODE(switch_ivr_phrase_macro(session, VM_MESSAGE_COUNT_MACRO, msg_count, NULL, &folder_args))do { status = switch_ivr_phrase_macro_event(session, "voicemail_message_count" , msg_count, ((void*)0), ((void*)0), &folder_args); if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK ) { goto end; } break;} while(status); | ||||||
2095 | informed++; | ||||||
2096 | } | ||||||
2097 | |||||||
2098 | vm_check_state = VM_CHECK_MENU; | ||||||
2099 | } | ||||||
2100 | break; | ||||||
2101 | case VM_CHECK_PLAY_MESSAGES: | ||||||
2102 | { | ||||||
2103 | listen_callback_t cbt; | ||||||
2104 | char sql[512]; | ||||||
2105 | int cur_message, total_messages; | ||||||
2106 | |||||||
2107 | message_count(profile, myid, domain_name, myfolder, &total_new_messages, &total_saved_messages, | ||||||
2108 | &total_new_urgent_messages, &total_saved_urgent_messages); | ||||||
2109 | memset(&cbt, 0, sizeof(cbt)); | ||||||
2110 | cbt.email = vm_email ? vm_email : email_addr; | ||||||
2111 | cbt.convert_cmd = convert_cmd; | ||||||
2112 | cbt.convert_ext = convert_ext; | ||||||
2113 | cbt.move = VM_MOVE_NEXT; | ||||||
2114 | switch (play_msg_type) { | ||||||
2115 | case MSG_NEW: | ||||||
2116 | { | ||||||
2117 | switch_snprintf(sql, sizeof(sql), | ||||||
2118 | "select created_epoch, read_epoch, username, domain, uuid, cid_name, cid_number, in_folder, file_path, message_len, flags, read_flags, forwarded_by from voicemail_msgs where username='%s' and domain='%s' and read_epoch=0" | ||||||
2119 | " order by read_flags, created_epoch %s", myid, domain_name, | ||||||
2120 | profile->play_new_messages_lifo ? "desc" : "asc"); | ||||||
2121 | total_messages = total_new_messages; | ||||||
2122 | heard_auto_new = 1; | ||||||
2123 | } | ||||||
2124 | break; | ||||||
2125 | case MSG_SAVED: | ||||||
2126 | default: | ||||||
2127 | { | ||||||
2128 | switch_snprintf(sql, sizeof(sql), | ||||||
2129 | "select created_epoch, read_epoch, username, domain, uuid, cid_name, cid_number, in_folder, file_path, message_len, flags, read_flags, forwarded_by from voicemail_msgs where username='%s' and domain='%s' and read_epoch !=0" | ||||||
2130 | " order by read_flags, created_epoch %s", myid, domain_name, | ||||||
2131 | profile->play_saved_messages_lifo ? "desc" : "asc"); | ||||||
2132 | total_messages = total_saved_messages; | ||||||
2133 | heard_auto_new = 1; | ||||||
2134 | } | ||||||
2135 | break; | ||||||
2136 | } | ||||||
2137 | for (cur_message = 0; cur_message < total_messages; cur_message++) { | ||||||
2138 | cbt.index = 0; | ||||||
2139 | cbt.want = cur_message; | ||||||
2140 | cbt.type = play_msg_type; | ||||||
2141 | cbt.move = VM_MOVE_NEXT; | ||||||
2142 | vm_execute_sql_callback(profile, profile->mutex, sql, listen_callback, &cbt); | ||||||
2143 | if (!zstr(uuid_in)_zstr(uuid_in) && strcmp(cbt.uuid, uuid_in)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (cbt.uuid) && __builtin_constant_p (uuid_in) && (__s1_len = __builtin_strlen (cbt.uuid), __s2_len = __builtin_strlen (uuid_in), (!((size_t)(const void *)((cbt.uuid) + 1) - (size_t )(const void *)(cbt.uuid) == 1) || __s1_len >= 4) && (!((size_t)(const void *)((uuid_in) + 1) - (size_t)(const void *)(uuid_in) == 1) || __s2_len >= 4)) ? __builtin_strcmp ( cbt.uuid, uuid_in) : (__builtin_constant_p (cbt.uuid) && ((size_t)(const void *)((cbt.uuid) + 1) - (size_t)(const void *)(cbt.uuid) == 1) && (__s1_len = __builtin_strlen ( cbt.uuid), __s1_len < 4) ? (__builtin_constant_p (uuid_in) && ((size_t)(const void *)((uuid_in) + 1) - (size_t) (const void *)(uuid_in) == 1) ? __builtin_strcmp (cbt.uuid, uuid_in ) : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (uuid_in); int __result = (((const unsigned char *) (const char *) (cbt.uuid))[0] - __s2[0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (cbt.uuid))[1] - __s2[1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (cbt.uuid))[2] - __s2[2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (cbt.uuid))[3] - __s2[3]); } } __result ; }))) : (__builtin_constant_p (uuid_in) && ((size_t) (const void *)((uuid_in) + 1) - (size_t)(const void *)(uuid_in ) == 1) && (__s2_len = __builtin_strlen (uuid_in), __s2_len < 4) ? (__builtin_constant_p (cbt.uuid) && ((size_t )(const void *)((cbt.uuid) + 1) - (size_t)(const void *)(cbt. uuid) == 1) ? __builtin_strcmp (cbt.uuid, uuid_in) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (cbt.uuid); int __result = (((const unsigned char *) (const char *) (uuid_in))[0] - __s2[0]); if (__s2_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (uuid_in))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (uuid_in))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (uuid_in))[3] - __s2[3]); } } __result; }) ))) : __builtin_strcmp (cbt.uuid, uuid_in)))); })) { | ||||||
2144 | continue; | ||||||
2145 | } | ||||||
2146 | status = listen_file(session, profile, &cbt); | ||||||
2147 | if (cbt.move == VM_MOVE_PREV) { | ||||||
2148 | if (cur_message <= 0) { | ||||||
2149 | cur_message = -1; | ||||||
2150 | } else { | ||||||
2151 | cur_message -= 2; | ||||||
2152 | } | ||||||
2153 | } else if (cbt.move == VM_MOVE_SAME) { | ||||||
2154 | cur_message -= 1; | ||||||
2155 | } | ||||||
2156 | |||||||
2157 | if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) { | ||||||
2158 | break; | ||||||
2159 | } | ||||||
2160 | } | ||||||
2161 | switch_snprintf(sql, sizeof(sql), "update voicemail_msgs set read_epoch=%ld where read_epoch=0 and " | ||||||
2162 | "username='%s' and domain='%s' and flags='save'", | ||||||
2163 | (long) switch_epoch_time_now(NULL((void*)0)), myid, domain_name); | ||||||
2164 | vm_execute_sql(profile, sql, profile->mutex); | ||||||
2165 | switch_snprintfv(sql, sizeof(sql), "select file_path from voicemail_msgs where username='%q' and domain='%q' and flags='delete'", myid, | ||||||
2166 | domain_name); | ||||||
2167 | vm_execute_sql_callback(profile, profile->mutex, sql, unlink_callback, NULL((void*)0)); | ||||||
2168 | switch_snprintfv(sql, sizeof(sql), "delete from voicemail_msgs where username='%q' and domain='%q' and flags='delete'", myid, domain_name); | ||||||
2169 | vm_execute_sql(profile, sql, profile->mutex); | ||||||
2170 | vm_check_state = VM_CHECK_FOLDER_SUMMARY; | ||||||
2171 | |||||||
2172 | update_mwi(profile, myid, domain_name, myfolder, MWI_REASON_PURGE); | ||||||
2173 | } | ||||||
2174 | break; | ||||||
2175 | case VM_CHECK_CONFIG: | ||||||
2176 | { | ||||||
2177 | char *sql = NULL((void*)0); | ||||||
2178 | char input[10] = ""; | ||||||
2179 | char key_buf[80] = ""; | ||||||
2180 | callback_t cbt = { 0 }; | ||||||
2181 | char msg_count[80] = ""; | ||||||
2182 | cc_t cc = { 0 }; | ||||||
2183 | switch_size_t message_len = 0; | ||||||
2184 | |||||||
2185 | cbt.buf = msg_count; | ||||||
2186 | cbt.len = sizeof(msg_count); | ||||||
2187 | sql = switch_mprintf("select count(*) from voicemail_prefs where username='%q' and domain = '%q'", myid, domain_name); | ||||||
2188 | vm_execute_sql_callback(profile, profile->mutex, sql, sql2str_callback, &cbt); | ||||||
2189 | switch_safe_free(sql)if (sql) {free(sql);sql=((void*)0);}; | ||||||
2190 | if (*msg_count == '\0' || !atoi(msg_count)) { | ||||||
2191 | sql = switch_mprintf("insert into voicemail_prefs values('%q','%q','','','')", myid, domain_name); | ||||||
2192 | vm_execute_sql(profile, sql, profile->mutex); | ||||||
2193 | switch_safe_free(sql)if (sql) {free(sql);sql=((void*)0);}; | ||||||
2194 | } | ||||||
2195 | |||||||
2196 | switch_snprintf(key_buf, sizeof(key_buf), "%s:%s:%s:%s:%s", | ||||||
2197 | profile->record_greeting_key, | ||||||
2198 | profile->choose_greeting_key, profile->record_name_key, profile->change_pass_key, profile->main_menu_key); | ||||||
2199 | |||||||
2200 | |||||||
2201 | TRY_CODE(vm_macro_get(session, VM_CONFIG_MENU_MACRO, key_buf, input, sizeof(input), 1, "", &term, timeout))do { status = vm_macro_get(session, "voicemail_config_menu", key_buf , input, sizeof(input), 1, "", &term, timeout); if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK ) { goto end; } break;} while(status); | ||||||
2202 | if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) { | ||||||
2203 | goto end; | ||||||
2204 | } | ||||||
2205 | |||||||
2206 | if (!strcmp(input, profile->main_menu_key)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (input) && __builtin_constant_p (profile->main_menu_key ) && (__s1_len = __builtin_strlen (input), __s2_len = __builtin_strlen (profile->main_menu_key), (!((size_t)(const void *)((input) + 1) - (size_t)(const void *)(input) == 1) || __s1_len >= 4) && (!((size_t)(const void *)((profile ->main_menu_key) + 1) - (size_t)(const void *)(profile-> main_menu_key) == 1) || __s2_len >= 4)) ? __builtin_strcmp (input, profile->main_menu_key) : (__builtin_constant_p ( input) && ((size_t)(const void *)((input) + 1) - (size_t )(const void *)(input) == 1) && (__s1_len = __builtin_strlen (input), __s1_len < 4) ? (__builtin_constant_p (profile-> main_menu_key) && ((size_t)(const void *)((profile-> main_menu_key) + 1) - (size_t)(const void *)(profile->main_menu_key ) == 1) ? __builtin_strcmp (input, profile->main_menu_key) : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (profile->main_menu_key); int __result = (((const unsigned char *) (const char *) (input))[0] - __s2 [0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (input))[1] - __s2 [1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (input))[2] - __s2 [2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (input))[3] - __s2[ 3]); } } __result; }))) : (__builtin_constant_p (profile-> main_menu_key) && ((size_t)(const void *)((profile-> main_menu_key) + 1) - (size_t)(const void *)(profile->main_menu_key ) == 1) && (__s2_len = __builtin_strlen (profile-> main_menu_key), __s2_len < 4) ? (__builtin_constant_p (input ) && ((size_t)(const void *)((input) + 1) - (size_t)( const void *)(input) == 1) ? __builtin_strcmp (input, profile ->main_menu_key) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (input); int __result = (((const unsigned char *) (const char *) (profile->main_menu_key ))[0] - __s2[0]); if (__s2_len > 0 && __result == 0 ) { __result = (((const unsigned char *) (const char *) (profile ->main_menu_key))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (profile->main_menu_key))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (profile->main_menu_key))[3] - __s2 [3]); } } __result; })))) : __builtin_strcmp (input, profile-> main_menu_key)))); })) { | ||||||
2207 | vm_check_state = VM_CHECK_MENU; | ||||||
2208 | } else if (!strcmp(input, profile->choose_greeting_key)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (input) && __builtin_constant_p (profile->choose_greeting_key ) && (__s1_len = __builtin_strlen (input), __s2_len = __builtin_strlen (profile->choose_greeting_key), (!((size_t )(const void *)((input) + 1) - (size_t)(const void *)(input) == 1) || __s1_len >= 4) && (!((size_t)(const void *) ((profile->choose_greeting_key) + 1) - (size_t)(const void *)(profile->choose_greeting_key) == 1) || __s2_len >= 4 )) ? __builtin_strcmp (input, profile->choose_greeting_key ) : (__builtin_constant_p (input) && ((size_t)(const void *)((input) + 1) - (size_t)(const void *)(input) == 1) && (__s1_len = __builtin_strlen (input), __s1_len < 4) ? (__builtin_constant_p (profile->choose_greeting_key) && ((size_t)(const void *)((profile->choose_greeting_key) + 1) - (size_t)(const void *)(profile->choose_greeting_key) == 1) ? __builtin_strcmp (input, profile->choose_greeting_key) : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (profile->choose_greeting_key); int __result = (((const unsigned char *) (const char *) (input))[0] - __s2[0]); if ( __s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (input))[1] - __s2[1]); if ( __s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (input))[2] - __s2[2]); if ( __s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (input))[3] - __s2[3]); } } __result ; }))) : (__builtin_constant_p (profile->choose_greeting_key ) && ((size_t)(const void *)((profile->choose_greeting_key ) + 1) - (size_t)(const void *)(profile->choose_greeting_key ) == 1) && (__s2_len = __builtin_strlen (profile-> choose_greeting_key), __s2_len < 4) ? (__builtin_constant_p (input) && ((size_t)(const void *)((input) + 1) - (size_t )(const void *)(input) == 1) ? __builtin_strcmp (input, profile ->choose_greeting_key) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (input); int __result = (((const unsigned char *) (const char *) (profile ->choose_greeting_key))[0] - __s2[0]); if (__s2_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (profile->choose_greeting_key))[1] - __s2 [1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (profile->choose_greeting_key ))[2] - __s2[2]); if (__s2_len > 2 && __result == 0 ) __result = (((const unsigned char *) (const char *) (profile ->choose_greeting_key))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (input, profile->choose_greeting_key)) )); })) { | ||||||
2209 | int num; | ||||||
2210 | switch_input_args_t greeting_args = { 0 }; | ||||||
2211 | greeting_args.input_callback = cancel_on_dtmf; | ||||||
2212 | |||||||
2213 | TRY_CODE(vm_macro_get(session, VM_CHOOSE_GREETING_MACRO, key_buf, input, sizeof(input), 1, "", &term, timeout))do { status = vm_macro_get(session, "voicemail_choose_greeting" , key_buf, input, sizeof(input), 1, "", &term, timeout); if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK ) { goto end; } break;} while(status); | ||||||
2214 | |||||||
2215 | |||||||
2216 | num = atoi(input); | ||||||
2217 | file_path = switch_mprintf("%s%sgreeting_%d.%s", dir_path, SWITCH_PATH_SEPARATOR"/", num, profile->file_ext); | ||||||
2218 | if (num < 1 || num > VM_MAX_GREETINGS9) { | ||||||
2219 | status = SWITCH_STATUS_FALSE; | ||||||
2220 | } else { | ||||||
2221 | switch_file_handle_t fh = { 0 }; | ||||||
2222 | memset(&fh, 0, sizeof(fh)); | ||||||
2223 | greeting_args.input_callback = control_playback; | ||||||
2224 | memset(&cc, 0, sizeof(cc)); | ||||||
2225 | cc.profile = profile; | ||||||
2226 | cc.fh = &fh; | ||||||
2227 | cc.noexit = 1; | ||||||
2228 | greeting_args.buf = &cc; | ||||||
2229 | status = switch_ivr_play_file(session, &fh, file_path, &greeting_args); | ||||||
2230 | } | ||||||
2231 | if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) { | ||||||
2232 | TRY_CODE(switch_ivr_phrase_macro(session, VM_CHOOSE_GREETING_FAIL_MACRO, NULL, NULL, NULL))do { status = switch_ivr_phrase_macro_event(session, "voicemail_choose_greeting_fail" , ((void*)0), ((void*)0), ((void*)0), ((void*)0)); if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK ) { goto end; } break;} while(status); | ||||||
2233 | } else { | ||||||
2234 | switch_event_t *params; | ||||||
2235 | |||||||
2236 | TRY_CODE(switch_ivr_phrase_macro(session, VM_CHOOSE_GREETING_SELECTED_MACRO, input, NULL, NULL))do { status = switch_ivr_phrase_macro_event(session, "voicemail_greeting_selected" , input, ((void*)0), ((void*)0), ((void*)0)); if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) { goto end; } break ;} while(status); | ||||||
2237 | sql = | ||||||
2238 | switch_mprintf("update voicemail_prefs set greeting_path='%s' where username='%s' and domain='%s'", file_path, myid, | ||||||
2239 | domain_name); | ||||||
2240 | vm_execute_sql(profile, sql, profile->mutex); | ||||||
2241 | switch_safe_free(sql)if (sql) {free(sql);sql=((void*)0);}; | ||||||
2242 | |||||||
2243 | switch_event_create_subclass(¶ms, SWITCH_EVENT_CUSTOM, VM_EVENT_MAINT)switch_event_create_subclass_detailed("mod_voicemail.c", (const char * )(const char *)__func__, 2243, ¶ms, SWITCH_EVENT_CUSTOM , "vm::maintenance"); | ||||||
2244 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "VM-Action", "change-greeting"); | ||||||
2245 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "VM-Greeting-Path", file_path); | ||||||
2246 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "VM-User", myid); | ||||||
2247 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "VM-Domain", domain_name); | ||||||
2248 | switch_channel_event_set_data(channel, params); | ||||||
2249 | switch_event_fire(¶ms)switch_event_fire_detailed("mod_voicemail.c", (const char * ) (const char *)__func__, 2249, ¶ms, ((void*)0)); | ||||||
2250 | } | ||||||
2251 | switch_safe_free(file_path)if (file_path) {free(file_path);file_path=((void*)0);}; | ||||||
2252 | } else if (!strcmp(input, profile->record_greeting_key)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (input) && __builtin_constant_p (profile->record_greeting_key ) && (__s1_len = __builtin_strlen (input), __s2_len = __builtin_strlen (profile->record_greeting_key), (!((size_t )(const void *)((input) + 1) - (size_t)(const void *)(input) == 1) || __s1_len >= 4) && (!((size_t)(const void *) ((profile->record_greeting_key) + 1) - (size_t)(const void *)(profile->record_greeting_key) == 1) || __s2_len >= 4 )) ? __builtin_strcmp (input, profile->record_greeting_key ) : (__builtin_constant_p (input) && ((size_t)(const void *)((input) + 1) - (size_t)(const void *)(input) == 1) && (__s1_len = __builtin_strlen (input), __s1_len < 4) ? (__builtin_constant_p (profile->record_greeting_key) && ((size_t)(const void *)((profile->record_greeting_key) + 1) - (size_t)(const void *)(profile->record_greeting_key) == 1) ? __builtin_strcmp (input, profile->record_greeting_key) : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (profile->record_greeting_key); int __result = (((const unsigned char *) (const char *) (input))[0] - __s2[0]); if ( __s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (input))[1] - __s2[1]); if ( __s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (input))[2] - __s2[2]); if ( __s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (input))[3] - __s2[3]); } } __result ; }))) : (__builtin_constant_p (profile->record_greeting_key ) && ((size_t)(const void *)((profile->record_greeting_key ) + 1) - (size_t)(const void *)(profile->record_greeting_key ) == 1) && (__s2_len = __builtin_strlen (profile-> record_greeting_key), __s2_len < 4) ? (__builtin_constant_p (input) && ((size_t)(const void *)((input) + 1) - (size_t )(const void *)(input) == 1) ? __builtin_strcmp (input, profile ->record_greeting_key) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (input); int __result = (((const unsigned char *) (const char *) (profile ->record_greeting_key))[0] - __s2[0]); if (__s2_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (profile->record_greeting_key))[1] - __s2 [1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (profile->record_greeting_key ))[2] - __s2[2]); if (__s2_len > 2 && __result == 0 ) __result = (((const unsigned char *) (const char *) (profile ->record_greeting_key))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (input, profile->record_greeting_key)) )); })) { | ||||||
2253 | int num; | ||||||
2254 | TRY_CODE(vm_macro_get(session, VM_CHOOSE_GREETING_MACRO, key_buf, input, sizeof(input), 1, "", &term, timeout))do { status = vm_macro_get(session, "voicemail_choose_greeting" , key_buf, input, sizeof(input), 1, "", &term, timeout); if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK ) { goto end; } break;} while(status); | ||||||
2255 | |||||||
2256 | num = atoi(input); | ||||||
2257 | if (num < 1 || num > VM_MAX_GREETINGS9) { | ||||||
2258 | TRY_CODE(switch_ivr_phrase_macro(session, VM_CHOOSE_GREETING_FAIL_MACRO, NULL, NULL, NULL))do { status = switch_ivr_phrase_macro_event(session, "voicemail_choose_greeting_fail" , ((void*)0), ((void*)0), ((void*)0), ((void*)0)); if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK ) { goto end; } break;} while(status); | ||||||
2259 | } else { | ||||||
2260 | switch_event_t *params; | ||||||
2261 | file_path = switch_mprintf("%s%sgreeting_%d.%s", dir_path, SWITCH_PATH_SEPARATOR"/", num, profile->file_ext); | ||||||
2262 | tmp_file_path = switch_mprintf("%s%sgreeting_%d_TMP.%s", dir_path, SWITCH_PATH_SEPARATOR"/", num, profile->file_ext); | ||||||
2263 | unlink(tmp_file_path); | ||||||
2264 | |||||||
2265 | TRY_CODE(create_file(session, profile, VM_RECORD_GREETING_MACRO, file_path, &message_len, SWITCH_TRUE, NULL, NULL))do { status = create_file(session, profile, "voicemail_record_greeting" , file_path, &message_len, SWITCH_TRUE, ((void*)0), ((void *)0)); if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) { goto end; } break;} while(status); | ||||||
2266 | switch_file_rename(tmp_file_path, file_path, switch_core_session_get_pool(session)); | ||||||
2267 | |||||||
2268 | sql = | ||||||
2269 | switch_mprintf("update voicemail_prefs set greeting_path='%s' where username='%s' and domain='%s'", file_path, myid, | ||||||
2270 | domain_name); | ||||||
2271 | vm_execute_sql(profile, sql, profile->mutex); | ||||||
2272 | switch_safe_free(sql)if (sql) {free(sql);sql=((void*)0);}; | ||||||
2273 | switch_safe_free(file_path)if (file_path) {free(file_path);file_path=((void*)0);}; | ||||||
2274 | switch_safe_free(tmp_file_path)if (tmp_file_path) {free(tmp_file_path);tmp_file_path=((void* )0);}; | ||||||
2275 | |||||||
2276 | switch_event_create_subclass(¶ms, SWITCH_EVENT_CUSTOM, VM_EVENT_MAINT)switch_event_create_subclass_detailed("mod_voicemail.c", (const char * )(const char *)__func__, 2276, ¶ms, SWITCH_EVENT_CUSTOM , "vm::maintenance"); | ||||||
2277 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "VM-Action", "record-greeting"); | ||||||
2278 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "VM-Greeting-Path", file_path); | ||||||
2279 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "VM-User", myid); | ||||||
2280 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "VM-Domain", domain_name); | ||||||
2281 | switch_channel_event_set_data(channel, params); | ||||||
2282 | switch_event_fire(¶ms)switch_event_fire_detailed("mod_voicemail.c", (const char * ) (const char *)__func__, 2282, ¶ms, ((void*)0)); | ||||||
2283 | } | ||||||
2284 | |||||||
2285 | } else if (!strcmp(input, profile->change_pass_key)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (input) && __builtin_constant_p (profile->change_pass_key ) && (__s1_len = __builtin_strlen (input), __s2_len = __builtin_strlen (profile->change_pass_key), (!((size_t)( const void *)((input) + 1) - (size_t)(const void *)(input) == 1) || __s1_len >= 4) && (!((size_t)(const void *) ((profile->change_pass_key) + 1) - (size_t)(const void *)( profile->change_pass_key) == 1) || __s2_len >= 4)) ? __builtin_strcmp (input, profile->change_pass_key) : (__builtin_constant_p (input) && ((size_t)(const void *)((input) + 1) - (size_t )(const void *)(input) == 1) && (__s1_len = __builtin_strlen (input), __s1_len < 4) ? (__builtin_constant_p (profile-> change_pass_key) && ((size_t)(const void *)((profile-> change_pass_key) + 1) - (size_t)(const void *)(profile->change_pass_key ) == 1) ? __builtin_strcmp (input, profile->change_pass_key ) : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (profile->change_pass_key); int __result = (((const unsigned char *) (const char *) (input))[0] - __s2 [0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (input))[1] - __s2 [1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (input))[2] - __s2 [2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (input))[3] - __s2[ 3]); } } __result; }))) : (__builtin_constant_p (profile-> change_pass_key) && ((size_t)(const void *)((profile-> change_pass_key) + 1) - (size_t)(const void *)(profile->change_pass_key ) == 1) && (__s2_len = __builtin_strlen (profile-> change_pass_key), __s2_len < 4) ? (__builtin_constant_p (input ) && ((size_t)(const void *)((input) + 1) - (size_t)( const void *)(input) == 1) ? __builtin_strcmp (input, profile ->change_pass_key) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (input); int __result = (((const unsigned char *) (const char *) (profile->change_pass_key ))[0] - __s2[0]); if (__s2_len > 0 && __result == 0 ) { __result = (((const unsigned char *) (const char *) (profile ->change_pass_key))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (profile->change_pass_key))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (profile->change_pass_key))[3] - __s2 [3]); } } __result; })))) : __builtin_strcmp (input, profile-> change_pass_key)))); })) { | ||||||
2286 | char buf[256] = ""; | ||||||
2287 | char macro[256] = ""; | ||||||
2288 | switch_event_t *params; | ||||||
2289 | switch_xml_t xx_user, xx_domain, xx_domain_root; | ||||||
2290 | int fail = 0; | ||||||
2291 | int ok = 0; | ||||||
2292 | |||||||
2293 | while (!ok) { | ||||||
2294 | fail = 0; | ||||||
2295 | switch_snprintf(macro, sizeof(macro), "phrase:%s:%s", VM_ENTER_PASS_MACRO"voicemail_enter_pass", profile->terminator_key); | ||||||
2296 | TRY_CODE(switch_ivr_read(session, 0, 255, macro, NULL, buf, sizeof(buf), 10000, profile->terminator_key, 0))do { status = switch_ivr_read(session, 0, 255, macro, ((void* )0), buf, sizeof(buf), 10000, profile->terminator_key, 0); if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK ) { goto end; } break;} while(status); | ||||||
2297 | |||||||
2298 | |||||||
2299 | switch_event_create_subclass(¶ms, SWITCH_EVENT_CUSTOM, VM_EVENT_MAINT)switch_event_create_subclass_detailed("mod_voicemail.c", (const char * )(const char *)__func__, 2299, ¶ms, SWITCH_EVENT_CUSTOM , "vm::maintenance"); | ||||||
2300 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "VM-Action", "change-password"); | ||||||
2301 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "VM-User-Password", buf); | ||||||
2302 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "VM-User", myid); | ||||||
2303 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "VM-Domain", domain_name); | ||||||
2304 | switch_channel_event_set_data(channel, params); | ||||||
2305 | |||||||
2306 | if (switch_xml_locate_user("id", myid, domain_name, switch_channel_get_variable(channel, "network_addr")switch_channel_get_variable_dup(channel, "network_addr", SWITCH_TRUE , -1), | ||||||
2307 | &xx_domain_root, &xx_domain, &xx_user, NULL((void*)0), params) == SWITCH_STATUS_SUCCESS) { | ||||||
2308 | switch_xml_t x_result; | ||||||
2309 | |||||||
2310 | if ((x_result = switch_xml_child(xx_user, "result"))) { | ||||||
2311 | if (!switch_true(switch_xml_attr_soft(x_result, "success"))) { | ||||||
2312 | fail = 1; | ||||||
2313 | } | ||||||
2314 | } | ||||||
2315 | |||||||
2316 | switch_xml_free(xx_domain_root); | ||||||
2317 | } | ||||||
2318 | |||||||
2319 | if (fail) { | ||||||
2320 | /* add feedback for user - let him/her know that the password they tried to change to is not allowed */ | ||||||
2321 | switch_ivr_phrase_macro(session, VM_CHANGE_PASS_FAIL_MACRO, NULL, NULL, NULL)switch_ivr_phrase_macro_event(session, "voicemail_change_pass_fail" , ((void*)0), ((void*)0), ((void*)0), ((void*)0)); | ||||||
2322 | } else { | ||||||
2323 | sql = switch_mprintf("update voicemail_prefs set password='%s' where username='%s' and domain='%s'", buf, myid, domain_name); | ||||||
2324 | vm_execute_sql(profile, sql, profile->mutex); | ||||||
2325 | switch_safe_free(file_path)if (file_path) {free(file_path);file_path=((void*)0);}; | ||||||
2326 | switch_safe_free(sql)if (sql) {free(sql);sql=((void*)0);}; | ||||||
2327 | ok = 1; | ||||||
2328 | /* add feedback for user - let him/her know that password change was successful */ | ||||||
2329 | switch_ivr_phrase_macro(session, VM_CHANGE_PASS_SUCCESS_MACRO, NULL, NULL, NULL)switch_ivr_phrase_macro_event(session, "voicemail_change_pass_success" , ((void*)0), ((void*)0), ((void*)0), ((void*)0)); | ||||||
2330 | } | ||||||
2331 | |||||||
2332 | switch_event_destroy(¶ms); | ||||||
2333 | } | ||||||
2334 | |||||||
2335 | } else if (!strcmp(input, profile->record_name_key)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (input) && __builtin_constant_p (profile->record_name_key ) && (__s1_len = __builtin_strlen (input), __s2_len = __builtin_strlen (profile->record_name_key), (!((size_t)( const void *)((input) + 1) - (size_t)(const void *)(input) == 1) || __s1_len >= 4) && (!((size_t)(const void *) ((profile->record_name_key) + 1) - (size_t)(const void *)( profile->record_name_key) == 1) || __s2_len >= 4)) ? __builtin_strcmp (input, profile->record_name_key) : (__builtin_constant_p (input) && ((size_t)(const void *)((input) + 1) - (size_t )(const void *)(input) == 1) && (__s1_len = __builtin_strlen (input), __s1_len < 4) ? (__builtin_constant_p (profile-> record_name_key) && ((size_t)(const void *)((profile-> record_name_key) + 1) - (size_t)(const void *)(profile->record_name_key ) == 1) ? __builtin_strcmp (input, profile->record_name_key ) : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (profile->record_name_key); int __result = (((const unsigned char *) (const char *) (input))[0] - __s2 [0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (input))[1] - __s2 [1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (input))[2] - __s2 [2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (input))[3] - __s2[ 3]); } } __result; }))) : (__builtin_constant_p (profile-> record_name_key) && ((size_t)(const void *)((profile-> record_name_key) + 1) - (size_t)(const void *)(profile->record_name_key ) == 1) && (__s2_len = __builtin_strlen (profile-> record_name_key), __s2_len < 4) ? (__builtin_constant_p (input ) && ((size_t)(const void *)((input) + 1) - (size_t)( const void *)(input) == 1) ? __builtin_strcmp (input, profile ->record_name_key) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (input); int __result = (((const unsigned char *) (const char *) (profile->record_name_key ))[0] - __s2[0]); if (__s2_len > 0 && __result == 0 ) { __result = (((const unsigned char *) (const char *) (profile ->record_name_key))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (profile->record_name_key))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (profile->record_name_key))[3] - __s2 [3]); } } __result; })))) : __builtin_strcmp (input, profile-> record_name_key)))); })) { | ||||||
2336 | switch_event_t *params; | ||||||
2337 | file_path = switch_mprintf("%s%srecorded_name.%s", dir_path, SWITCH_PATH_SEPARATOR"/", profile->file_ext); | ||||||
2338 | tmp_file_path = switch_mprintf("%s%srecorded_name_TMP.%s", dir_path, SWITCH_PATH_SEPARATOR"/", profile->file_ext); | ||||||
2339 | unlink(tmp_file_path); | ||||||
2340 | TRY_CODE(create_file(session, profile, VM_RECORD_NAME_MACRO, file_path, &message_len, SWITCH_FALSE, NULL, NULL))do { status = create_file(session, profile, "voicemail_record_name" , file_path, &message_len, SWITCH_FALSE, ((void*)0), ((void *)0)); if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) { goto end; } break;} while(status); | ||||||
2341 | switch_file_rename(tmp_file_path, file_path, switch_core_session_get_pool(session)); | ||||||
2342 | sql = switch_mprintf("update voicemail_prefs set name_path='%s' where username='%s' and domain='%s'", file_path, myid, domain_name); | ||||||
2343 | vm_execute_sql(profile, sql, profile->mutex); | ||||||
2344 | switch_safe_free(file_path)if (file_path) {free(file_path);file_path=((void*)0);}; | ||||||
2345 | switch_safe_free(tmp_file_path)if (tmp_file_path) {free(tmp_file_path);tmp_file_path=((void* )0);}; | ||||||
2346 | switch_safe_free(sql)if (sql) {free(sql);sql=((void*)0);}; | ||||||
2347 | |||||||
2348 | switch_event_create_subclass(¶ms, SWITCH_EVENT_CUSTOM, VM_EVENT_MAINT)switch_event_create_subclass_detailed("mod_voicemail.c", (const char * )(const char *)__func__, 2348, ¶ms, SWITCH_EVENT_CUSTOM , "vm::maintenance"); | ||||||
2349 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "VM-Action", "record-name"); | ||||||
2350 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "VM-Name-Path", file_path); | ||||||
2351 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "VM-User", myid); | ||||||
2352 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "VM-Domain", domain_name); | ||||||
2353 | switch_channel_event_set_data(channel, params); | ||||||
2354 | switch_event_fire(¶ms)switch_event_fire_detailed("mod_voicemail.c", (const char * ) (const char *)__func__, 2354, ¶ms, ((void*)0)); | ||||||
2355 | } | ||||||
2356 | continue; | ||||||
2357 | } | ||||||
2358 | break; | ||||||
2359 | case VM_CHECK_MENU: | ||||||
2360 | { | ||||||
2361 | char input[10] = ""; | ||||||
2362 | char key_buf[80] = ""; | ||||||
2363 | play_msg_type = MSG_NONE; | ||||||
2364 | |||||||
2365 | if (!retries) { | ||||||
2366 | goto end; | ||||||
2367 | } | ||||||
2368 | |||||||
2369 | retries--; | ||||||
2370 | |||||||
2371 | if (!zstr_buf(global_buf)(*(global_buf) == '\0')) { | ||||||
2372 | switch_set_string(input, global_buf)switch_copy_string(input, global_buf, sizeof(input)); | ||||||
2373 | *global_buf = '\0'; | ||||||
2374 | status = SWITCH_STATUS_SUCCESS; | ||||||
2375 | } else { | ||||||
2376 | switch_snprintf(key_buf, sizeof(key_buf), "%s:%s:%s:%s", | ||||||
2377 | profile->play_new_messages_key, profile->play_saved_messages_key, profile->config_menu_key, profile->terminator_key); | ||||||
2378 | |||||||
2379 | status = vm_macro_get(session, VM_MENU_MACRO"voicemail_menu", key_buf, input, sizeof(input), 1, "", &term, timeout); | ||||||
2380 | } | ||||||
2381 | |||||||
2382 | if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) { | ||||||
2383 | goto end; | ||||||
2384 | } | ||||||
2385 | |||||||
2386 | if (!strcmp(input, profile->play_new_messages_key)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (input) && __builtin_constant_p (profile->play_new_messages_key ) && (__s1_len = __builtin_strlen (input), __s2_len = __builtin_strlen (profile->play_new_messages_key), (!((size_t )(const void *)((input) + 1) - (size_t)(const void *)(input) == 1) || __s1_len >= 4) && (!((size_t)(const void *) ((profile->play_new_messages_key) + 1) - (size_t)(const void *)(profile->play_new_messages_key) == 1) || __s2_len >= 4)) ? __builtin_strcmp (input, profile->play_new_messages_key ) : (__builtin_constant_p (input) && ((size_t)(const void *)((input) + 1) - (size_t)(const void *)(input) == 1) && (__s1_len = __builtin_strlen (input), __s1_len < 4) ? (__builtin_constant_p (profile->play_new_messages_key) && ((size_t)(const void *)((profile->play_new_messages_key) + 1) - (size_t)( const void *)(profile->play_new_messages_key) == 1) ? __builtin_strcmp (input, profile->play_new_messages_key) : (__extension__ ( { const unsigned char *__s2 = (const unsigned char *) (const char *) (profile->play_new_messages_key); int __result = (((const unsigned char *) (const char *) (input))[0] - __s2[0]); if ( __s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (input))[1] - __s2[1]); if ( __s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (input))[2] - __s2[2]); if ( __s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (input))[3] - __s2[3]); } } __result ; }))) : (__builtin_constant_p (profile->play_new_messages_key ) && ((size_t)(const void *)((profile->play_new_messages_key ) + 1) - (size_t)(const void *)(profile->play_new_messages_key ) == 1) && (__s2_len = __builtin_strlen (profile-> play_new_messages_key), __s2_len < 4) ? (__builtin_constant_p (input) && ((size_t)(const void *)((input) + 1) - (size_t )(const void *)(input) == 1) ? __builtin_strcmp (input, profile ->play_new_messages_key) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (input); int __result = (((const unsigned char *) (const char *) (profile ->play_new_messages_key))[0] - __s2[0]); if (__s2_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (profile->play_new_messages_key))[1] - __s2 [1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (profile->play_new_messages_key ))[2] - __s2[2]); if (__s2_len > 2 && __result == 0 ) __result = (((const unsigned char *) (const char *) (profile ->play_new_messages_key))[3] - __s2[3]); } } __result; })) )) : __builtin_strcmp (input, profile->play_new_messages_key )))); })) { | ||||||
2387 | play_msg_type = MSG_NEW; | ||||||
2388 | } else if (!strcmp(input, profile->play_saved_messages_key)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (input) && __builtin_constant_p (profile->play_saved_messages_key ) && (__s1_len = __builtin_strlen (input), __s2_len = __builtin_strlen (profile->play_saved_messages_key), (!(( size_t)(const void *)((input) + 1) - (size_t)(const void *)(input ) == 1) || __s1_len >= 4) && (!((size_t)(const void *)((profile->play_saved_messages_key) + 1) - (size_t)(const void *)(profile->play_saved_messages_key) == 1) || __s2_len >= 4)) ? __builtin_strcmp (input, profile->play_saved_messages_key ) : (__builtin_constant_p (input) && ((size_t)(const void *)((input) + 1) - (size_t)(const void *)(input) == 1) && (__s1_len = __builtin_strlen (input), __s1_len < 4) ? (__builtin_constant_p (profile->play_saved_messages_key) && ((size_t)(const void *)((profile->play_saved_messages_key) + 1) - (size_t )(const void *)(profile->play_saved_messages_key) == 1) ? __builtin_strcmp (input, profile->play_saved_messages_key) : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (profile->play_saved_messages_key); int __result = (((const unsigned char *) (const char *) (input))[0] - __s2[ 0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (input))[1] - __s2 [1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (input))[2] - __s2 [2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (input))[3] - __s2[ 3]); } } __result; }))) : (__builtin_constant_p (profile-> play_saved_messages_key) && ((size_t)(const void *)(( profile->play_saved_messages_key) + 1) - (size_t)(const void *)(profile->play_saved_messages_key) == 1) && (__s2_len = __builtin_strlen (profile->play_saved_messages_key), __s2_len < 4) ? (__builtin_constant_p (input) && ((size_t) (const void *)((input) + 1) - (size_t)(const void *)(input) == 1) ? __builtin_strcmp (input, profile->play_saved_messages_key ) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (input); int __result = (((const unsigned char *) (const char *) (profile->play_saved_messages_key) )[0] - __s2[0]); if (__s2_len > 0 && __result == 0 ) { __result = (((const unsigned char *) (const char *) (profile ->play_saved_messages_key))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (profile->play_saved_messages_key))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (profile->play_saved_messages_key ))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (input , profile->play_saved_messages_key)))); })) { | ||||||
2389 | play_msg_type = MSG_SAVED; | ||||||
2390 | } else if (!strcmp(input, profile->terminator_key)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (input) && __builtin_constant_p (profile->terminator_key ) && (__s1_len = __builtin_strlen (input), __s2_len = __builtin_strlen (profile->terminator_key), (!((size_t)(const void *)((input) + 1) - (size_t)(const void *)(input) == 1) || __s1_len >= 4) && (!((size_t)(const void *)((profile ->terminator_key) + 1) - (size_t)(const void *)(profile-> terminator_key) == 1) || __s2_len >= 4)) ? __builtin_strcmp (input, profile->terminator_key) : (__builtin_constant_p ( input) && ((size_t)(const void *)((input) + 1) - (size_t )(const void *)(input) == 1) && (__s1_len = __builtin_strlen (input), __s1_len < 4) ? (__builtin_constant_p (profile-> terminator_key) && ((size_t)(const void *)((profile-> terminator_key) + 1) - (size_t)(const void *)(profile->terminator_key ) == 1) ? __builtin_strcmp (input, profile->terminator_key ) : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (profile->terminator_key); int __result = (((const unsigned char *) (const char *) (input))[0] - __s2 [0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (input))[1] - __s2 [1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (input))[2] - __s2 [2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (input))[3] - __s2[ 3]); } } __result; }))) : (__builtin_constant_p (profile-> terminator_key) && ((size_t)(const void *)((profile-> terminator_key) + 1) - (size_t)(const void *)(profile->terminator_key ) == 1) && (__s2_len = __builtin_strlen (profile-> terminator_key), __s2_len < 4) ? (__builtin_constant_p (input ) && ((size_t)(const void *)((input) + 1) - (size_t)( const void *)(input) == 1) ? __builtin_strcmp (input, profile ->terminator_key) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (input); int __result = (((const unsigned char *) (const char *) (profile->terminator_key ))[0] - __s2[0]); if (__s2_len > 0 && __result == 0 ) { __result = (((const unsigned char *) (const char *) (profile ->terminator_key))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (profile->terminator_key))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (profile->terminator_key))[3] - __s2 [3]); } } __result; })))) : __builtin_strcmp (input, profile-> terminator_key)))); })) { | ||||||
2391 | goto end; | ||||||
2392 | } else if (!strcmp(input, profile->config_menu_key)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (input) && __builtin_constant_p (profile->config_menu_key ) && (__s1_len = __builtin_strlen (input), __s2_len = __builtin_strlen (profile->config_menu_key), (!((size_t)( const void *)((input) + 1) - (size_t)(const void *)(input) == 1) || __s1_len >= 4) && (!((size_t)(const void *) ((profile->config_menu_key) + 1) - (size_t)(const void *)( profile->config_menu_key) == 1) || __s2_len >= 4)) ? __builtin_strcmp (input, profile->config_menu_key) : (__builtin_constant_p (input) && ((size_t)(const void *)((input) + 1) - (size_t )(const void *)(input) == 1) && (__s1_len = __builtin_strlen (input), __s1_len < 4) ? (__builtin_constant_p (profile-> config_menu_key) && ((size_t)(const void *)((profile-> config_menu_key) + 1) - (size_t)(const void *)(profile->config_menu_key ) == 1) ? __builtin_strcmp (input, profile->config_menu_key ) : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (profile->config_menu_key); int __result = (((const unsigned char *) (const char *) (input))[0] - __s2 [0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (input))[1] - __s2 [1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (input))[2] - __s2 [2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (input))[3] - __s2[ 3]); } } __result; }))) : (__builtin_constant_p (profile-> config_menu_key) && ((size_t)(const void *)((profile-> config_menu_key) + 1) - (size_t)(const void *)(profile->config_menu_key ) == 1) && (__s2_len = __builtin_strlen (profile-> config_menu_key), __s2_len < 4) ? (__builtin_constant_p (input ) && ((size_t)(const void *)((input) + 1) - (size_t)( const void *)(input) == 1) ? __builtin_strcmp (input, profile ->config_menu_key) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (input); int __result = (((const unsigned char *) (const char *) (profile->config_menu_key ))[0] - __s2[0]); if (__s2_len > 0 && __result == 0 ) { __result = (((const unsigned char *) (const char *) (profile ->config_menu_key))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (profile->config_menu_key))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (profile->config_menu_key))[3] - __s2 [3]); } } __result; })))) : __builtin_strcmp (input, profile-> config_menu_key)))); })) { | ||||||
2393 | vm_check_state = VM_CHECK_CONFIG; | ||||||
2394 | } | ||||||
2395 | |||||||
2396 | if (play_msg_type) { | ||||||
2397 | vm_check_state = VM_CHECK_PLAY_MESSAGES; | ||||||
2398 | retries = profile->max_retries; | ||||||
2399 | } | ||||||
2400 | |||||||
2401 | continue; | ||||||
2402 | } | ||||||
2403 | break; | ||||||
2404 | case VM_CHECK_AUTH: | ||||||
2405 | { | ||||||
2406 | prefs_callback_t cbt = { {0} | ||||||
2407 | }; | ||||||
2408 | char sql[512] = ""; | ||||||
2409 | |||||||
2410 | if (!attempts) { | ||||||
2411 | failed = 1; | ||||||
2412 | goto end; | ||||||
2413 | } | ||||||
2414 | |||||||
2415 | attempts--; | ||||||
2416 | |||||||
2417 | if (!myid) { | ||||||
2418 | status = vm_macro_get(session, VM_ENTER_ID_MACRO"voicemail_enter_id", profile->terminator_key, id_buf, sizeof(id_buf), 0, | ||||||
2419 | profile->terminator_key, &term, timeout); | ||||||
2420 | if (status != SWITCH_STATUS_SUCCESS) { | ||||||
2421 | goto end; | ||||||
2422 | } | ||||||
2423 | |||||||
2424 | if (*id_buf == '\0') { | ||||||
2425 | continue; | ||||||
2426 | } else { | ||||||
2427 | myid = id_buf; | ||||||
2428 | } | ||||||
2429 | } | ||||||
2430 | |||||||
2431 | if (!x_user) { | ||||||
2432 | switch_event_t *params; | ||||||
2433 | int ok = 1; | ||||||
2434 | |||||||
2435 | switch_event_create(¶ms, SWITCH_EVENT_GENERAL)switch_event_create_subclass_detailed("mod_voicemail.c", (const char * )(const char *)__func__, 2435, ¶ms, SWITCH_EVENT_GENERAL , ((void*)0)); | ||||||
2436 | switch_assert(params)((params) ? (void) (0) : __assert_fail ("params", "mod_voicemail.c" , 2436, __PRETTY_FUNCTION__)); | ||||||
2437 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "action", "voicemail-lookup"); | ||||||
2438 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "destination_number", caller_profile->destination_number); | ||||||
2439 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "caller_id_number", caller_id_number); | ||||||
2440 | |||||||
2441 | if (switch_xml_locate_user_merged("id:number-alias", myid, domain_name, switch_channel_get_variable(channel, "network_addr")switch_channel_get_variable_dup(channel, "network_addr", SWITCH_TRUE , -1), | ||||||
2442 | &x_user, params) != SWITCH_STATUS_SUCCESS) { | ||||||
2443 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "mod_voicemail.c", (const char *)__func__ , 2443, (const char*)(session), SWITCH_LOG_WARNING, "Can't find user [%s@%s]\n", myid, domain_name); | ||||||
2444 | ok = 0; | ||||||
2445 | } else { | ||||||
2446 | switch_bool_t vm_enabled = SWITCH_TRUE; | ||||||
2447 | |||||||
2448 | x_params = switch_xml_child(x_user, "params"); | ||||||
2449 | |||||||
2450 | for (x_param = switch_xml_child(x_params, "param"); x_param; x_param = x_param->next) { | ||||||
2451 | const char *var = switch_xml_attr_soft(x_param, "name"); | ||||||
2452 | const char *val = switch_xml_attr_soft(x_param, "value"); | ||||||
2453 | |||||||
2454 | if (zstr(var)_zstr(var) || zstr(val)_zstr(val)) { | ||||||
2455 | continue; /* Ignore empty entires */ | ||||||
2456 | } | ||||||
2457 | |||||||
2458 | if (!strcasecmp(var, "vm-enabled")) { | ||||||
2459 | vm_enabled = !switch_false(val); | ||||||
2460 | } | ||||||
2461 | } | ||||||
2462 | |||||||
2463 | if (!vm_enabled) { | ||||||
2464 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "mod_voicemail.c", (const char *)__func__ , 2464, (const char*)(session), SWITCH_LOG_WARNING, "User [%s@%s] have voicemail disabled\n", myid, domain_name); | ||||||
2465 | ok = 0; | ||||||
2466 | } | ||||||
2467 | myid = switch_core_session_strdup(session, switch_xml_attr(x_user, "id"))switch_core_perform_session_strdup(session, switch_xml_attr(x_user , "id"), "mod_voicemail.c", (const char *)__func__, 2467); | ||||||
2468 | } | ||||||
2469 | |||||||
2470 | switch_event_destroy(¶ms); | ||||||
2471 | |||||||
2472 | if (!ok) { | ||||||
2473 | goto end; | ||||||
2474 | } | ||||||
2475 | } | ||||||
2476 | |||||||
2477 | thepass = thehash = NULL((void*)0); | ||||||
2478 | switch_snprintfv(sql, sizeof(sql), "select * from voicemail_prefs where username='%q' and domain='%q'", myid, domain_name); | ||||||
2479 | vm_execute_sql_callback(profile, profile->mutex, sql, prefs_callback, &cbt); | ||||||
2480 | |||||||
2481 | x_params = switch_xml_child(x_user, "variables"); | ||||||
2482 | for (x_param = switch_xml_child(x_params, "variable"); x_param; x_param = x_param->next) { | ||||||
2483 | const char *var = switch_xml_attr_soft(x_param, "name"); | ||||||
2484 | const char *val = switch_xml_attr_soft(x_param, "value"); | ||||||
2485 | |||||||
2486 | if (!strcasecmp(var, "timezone")) { | ||||||
2487 | switch_channel_set_variable(channel, var, val)switch_channel_set_variable_var_check(channel, var, val, SWITCH_TRUE ); | ||||||
2488 | } | ||||||
2489 | } | ||||||
2490 | |||||||
2491 | x_params = switch_xml_child(x_user, "params"); | ||||||
2492 | for (x_param = switch_xml_child(x_params, "param"); x_param; x_param = x_param->next) { | ||||||
2493 | const char *var = switch_xml_attr_soft(x_param, "name"); | ||||||
2494 | const char *val = switch_xml_attr_soft(x_param, "value"); | ||||||
2495 | |||||||
2496 | if (!strcasecmp(var, "a1-hash")) { | ||||||
2497 | thehash = switch_core_session_strdup(session, val)switch_core_perform_session_strdup(session, val, "mod_voicemail.c" , (const char *)__func__, 2497); | ||||||
2498 | } else if (!strcasecmp(var, "vm-a1-hash")) { | ||||||
2499 | vmhash = switch_core_session_strdup(session, val)switch_core_perform_session_strdup(session, val, "mod_voicemail.c" , (const char *)__func__, 2499); | ||||||
2500 | } else if (!auth && !thepass && !strcasecmp(var, "password")) { | ||||||
2501 | thepass = switch_core_session_strdup(session, val)switch_core_perform_session_strdup(session, val, "mod_voicemail.c" , (const char *)__func__, 2501); | ||||||
2502 | } else if (!auth && !strcasecmp(var, "vm-password")) { | ||||||
2503 | if (!zstr(val)_zstr(val) && !strcasecmp(val, "user-choose")) { | ||||||
2504 | if (zstr(cbt.password)_zstr(cbt.password)) { | ||||||
2505 | if (profile->allow_empty_password_auth) { | ||||||
2506 | auth = 1; | ||||||
2507 | } | ||||||
2508 | } else { | ||||||
2509 | thepass = switch_core_session_strdup(session, val)switch_core_perform_session_strdup(session, val, "mod_voicemail.c" , (const char *)__func__, 2509); | ||||||
2510 | } | ||||||
2511 | } else { | ||||||
2512 | thepass = switch_core_session_strdup(session, val)switch_core_perform_session_strdup(session, val, "mod_voicemail.c" , (const char *)__func__, 2512); | ||||||
2513 | } | ||||||
2514 | } else if (!strcasecmp(var, "vm-mailto")) { | ||||||
2515 | vm_email = switch_core_session_strdup(session, val)switch_core_perform_session_strdup(session, val, "mod_voicemail.c" , (const char *)__func__, 2515); | ||||||
2516 | email_addr = switch_core_session_strdup(session, val)switch_core_perform_session_strdup(session, val, "mod_voicemail.c" , (const char *)__func__, 2516); | ||||||
2517 | } else if (!strcasecmp(var, "email-addr")) { | ||||||
2518 | email_addr = switch_core_session_strdup(session, val)switch_core_perform_session_strdup(session, val, "mod_voicemail.c" , (const char *)__func__, 2518); | ||||||
2519 | } else if (!strcasecmp(var, "vm-convert-cmd")) { | ||||||
2520 | convert_cmd = switch_core_session_strdup(session, val)switch_core_perform_session_strdup(session, val, "mod_voicemail.c" , (const char *)__func__, 2520); | ||||||
2521 | } else if (!strcasecmp(var, "vm-convert-ext")) { | ||||||
2522 | convert_ext = switch_core_session_strdup(session, val)switch_core_perform_session_strdup(session, val, "mod_voicemail.c" , (const char *)__func__, 2522); | ||||||
2523 | } else if (!strcasecmp(var, "vm-storage-dir")) { | ||||||
2524 | vm_storage_dir = switch_core_session_strdup(session, val)switch_core_perform_session_strdup(session, val, "mod_voicemail.c" , (const char *)__func__, 2524); | ||||||
2525 | } else if (!strcasecmp(var, "vm-domain-storage-dir")) { | ||||||
2526 | storage_dir = switch_core_session_strdup(session, val)switch_core_perform_session_strdup(session, val, "mod_voicemail.c" , (const char *)__func__, 2526); | ||||||
2527 | } else if (!strcasecmp(var, "storage-dir")) { | ||||||
2528 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "mod_voicemail.c", (const char *)__func__ , 2528, (const char*)(session), SWITCH_LOG_WARNING, | ||||||
2529 | "Using deprecated 'storage-dir' directory variable: Please use 'vm-domain-storage-dir'.\n"); | ||||||
2530 | storage_dir = switch_core_session_strdup(session, val)switch_core_perform_session_strdup(session, val, "mod_voicemail.c" , (const char *)__func__, 2530); | ||||||
2531 | } else if (!strcasecmp(var, "timezone")) { | ||||||
2532 | switch_channel_set_variable(channel, var, val)switch_channel_set_variable_var_check(channel, var, val, SWITCH_TRUE ); | ||||||
2533 | } | ||||||
2534 | |||||||
2535 | } | ||||||
2536 | |||||||
2537 | if (!mypass) { | ||||||
2538 | if (auth) { | ||||||
2539 | mypass = "OK"; | ||||||
2540 | } else { | ||||||
2541 | status = vm_macro_get(session, VM_ENTER_PASS_MACRO"voicemail_enter_pass", profile->terminator_key, | ||||||
2542 | pass_buf, sizeof(pass_buf), 0, profile->terminator_key, &term, timeout); | ||||||
2543 | if (status != SWITCH_STATUS_SUCCESS) { | ||||||
2544 | goto end; | ||||||
2545 | } | ||||||
2546 | if (*pass_buf == '\0') { | ||||||
2547 | continue; | ||||||
2548 | } else { | ||||||
2549 | mypass = pass_buf; | ||||||
2550 | } | ||||||
2551 | } | ||||||
2552 | } | ||||||
2553 | |||||||
2554 | if (vmhash) { | ||||||
2555 | thehash = vmhash; | ||||||
2556 | } | ||||||
2557 | |||||||
2558 | if (!auth && !thepass && !zstr(cbt.password)_zstr(cbt.password)) { | ||||||
2559 | thepass = cbt.password; | ||||||
2560 | } | ||||||
2561 | |||||||
2562 | if (!auth) { | ||||||
2563 | if (!zstr(cbt.password)_zstr(cbt.password) && !strcmp(cbt.password, mypass)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (cbt.password) && __builtin_constant_p (mypass) && (__s1_len = __builtin_strlen (cbt.password), __s2_len = __builtin_strlen (mypass), (!((size_t)(const void *)((cbt.password) + 1) - (size_t )(const void *)(cbt.password) == 1) || __s1_len >= 4) && (!((size_t)(const void *)((mypass) + 1) - (size_t)(const void *)(mypass) == 1) || __s2_len >= 4)) ? __builtin_strcmp (cbt .password, mypass) : (__builtin_constant_p (cbt.password) && ((size_t)(const void *)((cbt.password) + 1) - (size_t)(const void *)(cbt.password) == 1) && (__s1_len = __builtin_strlen (cbt.password), __s1_len < 4) ? (__builtin_constant_p (mypass ) && ((size_t)(const void *)((mypass) + 1) - (size_t) (const void *)(mypass) == 1) ? __builtin_strcmp (cbt.password , mypass) : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (mypass); int __result = ((( const unsigned char *) (const char *) (cbt.password))[0] - __s2 [0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (cbt.password))[1 ] - __s2[1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (cbt.password ))[2] - __s2[2]); if (__s1_len > 2 && __result == 0 ) __result = (((const unsigned char *) (const char *) (cbt.password ))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p ( mypass) && ((size_t)(const void *)((mypass) + 1) - (size_t )(const void *)(mypass) == 1) && (__s2_len = __builtin_strlen (mypass), __s2_len < 4) ? (__builtin_constant_p (cbt.password ) && ((size_t)(const void *)((cbt.password) + 1) - (size_t )(const void *)(cbt.password) == 1) ? __builtin_strcmp (cbt.password , mypass) : (- (__extension__ ({ const unsigned char *__s2 = ( const unsigned char *) (const char *) (cbt.password); int __result = (((const unsigned char *) (const char *) (mypass))[0] - __s2 [0]); if (__s2_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (mypass))[1] - __s2 [1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (mypass))[2] - __s2 [2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (mypass))[3] - __s2 [3]); } } __result; })))) : __builtin_strcmp (cbt.password, mypass )))); })) { | ||||||
2564 | auth++; | ||||||
2565 | } else if (!thepass && profile->allow_empty_password_auth) { | ||||||
2566 | auth++; | ||||||
2567 | } | ||||||
2568 | |||||||
2569 | if (!auth && (!profile->db_password_override || (profile->db_password_override && zstr(cbt.password)_zstr(cbt.password))) && (thepass || thehash) && mypass) { | ||||||
2570 | if (thehash) { | ||||||
2571 | char digest[SWITCH_MD5_DIGEST_STRING_SIZE33] = { 0 }; | ||||||
2572 | char *lpbuf = switch_mprintf("%s:%s:%s", myid, domain_name, mypass); | ||||||
2573 | switch_md5_string(digest, (void *) lpbuf, strlen(lpbuf)); | ||||||
2574 | if (!strcmp(digest, thehash)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (digest) && __builtin_constant_p (thehash) && (__s1_len = __builtin_strlen (digest), __s2_len = __builtin_strlen (thehash), (!((size_t)(const void *)((digest) + 1) - (size_t )(const void *)(digest) == 1) || __s1_len >= 4) && (!((size_t)(const void *)((thehash) + 1) - (size_t)(const void *)(thehash) == 1) || __s2_len >= 4)) ? __builtin_strcmp ( digest, thehash) : (__builtin_constant_p (digest) && ( (size_t)(const void *)((digest) + 1) - (size_t)(const void *) (digest) == 1) && (__s1_len = __builtin_strlen (digest ), __s1_len < 4) ? (__builtin_constant_p (thehash) && ((size_t)(const void *)((thehash) + 1) - (size_t)(const void *)(thehash) == 1) ? __builtin_strcmp (digest, thehash) : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (thehash); int __result = (((const unsigned char *) ( const char *) (digest))[0] - __s2[0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (digest))[1] - __s2[1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (digest))[2] - __s2[2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (digest))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p (thehash) && ((size_t)(const void *)((thehash) + 1) - (size_t)(const void *)(thehash) == 1) && (__s2_len = __builtin_strlen (thehash), __s2_len < 4) ? (__builtin_constant_p (digest) && ((size_t)(const void *)((digest) + 1) - ( size_t)(const void *)(digest) == 1) ? __builtin_strcmp (digest , thehash) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (digest); int __result = (((const unsigned char *) (const char *) (thehash))[0] - __s2 [0]); if (__s2_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (thehash))[1] - __s2 [1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (thehash))[2] - __s2 [2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (thehash))[3] - __s2 [3]); } } __result; })))) : __builtin_strcmp (digest, thehash )))); })) { | ||||||
2575 | auth++; | ||||||
2576 | } | ||||||
2577 | switch_safe_free(lpbuf)if (lpbuf) {free(lpbuf);lpbuf=((void*)0);}; | ||||||
2578 | } | ||||||
2579 | |||||||
2580 | if (!auth && thepass && !strcmp(thepass, mypass)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (thepass) && __builtin_constant_p (mypass) && (__s1_len = __builtin_strlen (thepass), __s2_len = __builtin_strlen (mypass), (!((size_t)(const void *)((thepass) + 1) - (size_t )(const void *)(thepass) == 1) || __s1_len >= 4) && (!((size_t)(const void *)((mypass) + 1) - (size_t)(const void *)(mypass) == 1) || __s2_len >= 4)) ? __builtin_strcmp (thepass , mypass) : (__builtin_constant_p (thepass) && ((size_t )(const void *)((thepass) + 1) - (size_t)(const void *)(thepass ) == 1) && (__s1_len = __builtin_strlen (thepass), __s1_len < 4) ? (__builtin_constant_p (mypass) && ((size_t )(const void *)((mypass) + 1) - (size_t)(const void *)(mypass ) == 1) ? __builtin_strcmp (thepass, mypass) : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (mypass); int __result = (((const unsigned char *) ( const char *) (thepass))[0] - __s2[0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (thepass))[1] - __s2[1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (thepass))[2] - __s2[2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (thepass))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p (mypass) && ((size_t)(const void *)((mypass) + 1) - ( size_t)(const void *)(mypass) == 1) && (__s2_len = __builtin_strlen (mypass), __s2_len < 4) ? (__builtin_constant_p (thepass) && ((size_t)(const void *)((thepass) + 1) - (size_t) (const void *)(thepass) == 1) ? __builtin_strcmp (thepass, mypass ) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (thepass); int __result = (((const unsigned char *) (const char *) (mypass))[0] - __s2[0]); if (__s2_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (mypass))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (mypass))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (mypass))[3] - __s2[3]); } } __result ; })))) : __builtin_strcmp (thepass, mypass)))); })) { | ||||||
2581 | auth++; | ||||||
2582 | } | ||||||
2583 | } | ||||||
2584 | } | ||||||
2585 | |||||||
2586 | switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, VM_EVENT_MAINT)switch_event_create_subclass_detailed("mod_voicemail.c", (const char * )(const char *)__func__, 2586, &event, SWITCH_EVENT_CUSTOM , "vm::maintenance"); | ||||||
2587 | switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "VM-Action", "authentication"); | ||||||
2588 | switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "VM-Auth-Result", auth ? "success" : "fail"); | ||||||
2589 | switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "VM-User", myid); | ||||||
2590 | switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "VM-Domain", domain_name); | ||||||
2591 | switch_channel_event_set_data(channel, event); | ||||||
2592 | switch_event_fire(&event)switch_event_fire_detailed("mod_voicemail.c", (const char * ) (const char *)__func__, 2592, &event, ((void*)0)); | ||||||
2593 | |||||||
2594 | xml_safe_free(x_user)if (x_user) switch_xml_free(x_user); x_user = ((void*)0); | ||||||
2595 | |||||||
2596 | if (auth) { | ||||||
2597 | if (!dir_path) { | ||||||
2598 | if (!zstr(vm_storage_dir)_zstr(vm_storage_dir)) { | ||||||
2599 | /* check for absolute or relative path */ | ||||||
2600 | if (switch_is_file_path(vm_storage_dir)) { | ||||||
2601 | dir_path = switch_core_session_strdup(session, vm_storage_dir)switch_core_perform_session_strdup(session, vm_storage_dir, "mod_voicemail.c" , (const char *)__func__, 2601); | ||||||
2602 | } else { | ||||||
2603 | dir_path = switch_core_session_sprintf(session, "%s%svoicemail%s%s", SWITCH_GLOBAL_dirs.storage_dir, | ||||||
2604 | SWITCH_PATH_SEPARATOR"/", SWITCH_PATH_SEPARATOR"/", vm_storage_dir); | ||||||
2605 | } | ||||||
2606 | } else if (!zstr(storage_dir)_zstr(storage_dir)) { | ||||||
2607 | dir_path = switch_core_session_sprintf(session, "%s%s%s", storage_dir, SWITCH_PATH_SEPARATOR"/", myid); | ||||||
2608 | } else if (!zstr(profile->storage_dir)_zstr(profile->storage_dir)) { | ||||||
2609 | if (profile->storage_dir_shared) { | ||||||
2610 | dir_path = | ||||||
2611 | switch_core_session_sprintf(session, "%s%s%s%s%s%s%s", profile->storage_dir, SWITCH_PATH_SEPARATOR"/", domain_name, | ||||||
2612 | SWITCH_PATH_SEPARATOR"/", "voicemail", | ||||||
2613 | SWITCH_PATH_SEPARATOR"/", myid); | ||||||
2614 | } else { | ||||||
2615 | dir_path = | ||||||
2616 | switch_core_session_sprintf(session, "%s%s%s%s%s", profile->storage_dir, SWITCH_PATH_SEPARATOR"/", domain_name, | ||||||
2617 | SWITCH_PATH_SEPARATOR"/", myid); | ||||||
2618 | } | ||||||
2619 | } else { | ||||||
2620 | dir_path = switch_core_session_sprintf(session, "%s%svoicemail%s%s%s%s%s%s", SWITCH_GLOBAL_dirs.storage_dir, | ||||||
2621 | SWITCH_PATH_SEPARATOR"/", | ||||||
2622 | SWITCH_PATH_SEPARATOR"/", | ||||||
2623 | profile->name, SWITCH_PATH_SEPARATOR"/", domain_name, SWITCH_PATH_SEPARATOR"/", myid); | ||||||
2624 | } | ||||||
2625 | |||||||
2626 | if (switch_dir_make_recursive(dir_path, SWITCH_DEFAULT_DIR_PERMS0x0400 | 0x0200 | 0x0100 | 0x0040 | 0x0010, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) { | ||||||
2627 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "mod_voicemail.c", (const char *)__func__ , 2627, (const char*)(session), SWITCH_LOG_ERROR, "Error creating %s\n", dir_path); | ||||||
2628 | goto end; | ||||||
2629 | } | ||||||
2630 | } | ||||||
2631 | |||||||
2632 | authed = 1; | ||||||
2633 | |||||||
2634 | if (auth_only) goto end; | ||||||
2635 | |||||||
2636 | vm_check_state = VM_CHECK_FOLDER_SUMMARY; | ||||||
2637 | } else { | ||||||
2638 | goto failed; | ||||||
2639 | } | ||||||
2640 | |||||||
2641 | continue; | ||||||
2642 | |||||||
2643 | failed: | ||||||
2644 | |||||||
2645 | xml_safe_free(x_user)if (x_user) switch_xml_free(x_user); x_user = ((void*)0); | ||||||
2646 | |||||||
2647 | switch_ivr_phrase_macro(session, VM_FAIL_AUTH_MACRO, NULL, NULL, NULL)switch_ivr_phrase_macro_event(session, "voicemail_fail_auth", ((void*)0), ((void*)0), ((void*)0), ((void*)0)); | ||||||
2648 | myid = id; | ||||||
2649 | mypass = NULL((void*)0); | ||||||
2650 | continue; | ||||||
2651 | } | ||||||
2652 | break; | ||||||
2653 | default: | ||||||
2654 | break; | ||||||
2655 | } | ||||||
2656 | } | ||||||
2657 | |||||||
2658 | end: | ||||||
2659 | |||||||
2660 | switch_safe_free(file_path)if (file_path) {free(file_path);file_path=((void*)0);}; | ||||||
2661 | |||||||
2662 | if (tmp_file_path) { | ||||||
2663 | unlink(tmp_file_path); | ||||||
2664 | free(tmp_file_path); | ||||||
2665 | tmp_file_path = NULL((void*)0); | ||||||
2666 | } | ||||||
2667 | |||||||
2668 | if (switch_channel_ready(channel)switch_channel_test_ready(channel, SWITCH_TRUE, SWITCH_FALSE) && (!auth_only || !authed)) { | ||||||
2669 | if (failed) { | ||||||
2670 | switch_ivr_phrase_macro(session, VM_ABORT_MACRO, NULL, NULL, NULL)switch_ivr_phrase_macro_event(session, "voicemail_abort", ((void *)0), ((void*)0), ((void*)0), ((void*)0)); | ||||||
2671 | } | ||||||
2672 | switch_ivr_phrase_macro(session, VM_GOODBYE_MACRO, NULL, NULL, NULL)switch_ivr_phrase_macro_event(session, "voicemail_goodbye", ( (void*)0), ((void*)0), ((void*)0), ((void*)0)); | ||||||
2673 | } | ||||||
2674 | |||||||
2675 | if (auth_only) { | ||||||
2676 | if (authed) { | ||||||
2677 | switch_channel_set_variable(channel, "user_pin_authenticated", "true")switch_channel_set_variable_var_check(channel, "user_pin_authenticated" , "true", SWITCH_TRUE); | ||||||
2678 | switch_channel_set_variable(channel, "user_pin_authenticated_user", myid)switch_channel_set_variable_var_check(channel, "user_pin_authenticated_user" , myid, SWITCH_TRUE); | ||||||
2679 | if (!zstr(myid)_zstr(myid) && !zstr(domain_name)_zstr(domain_name)) { | ||||||
2680 | char *account = switch_core_session_sprintf(session, "%s@%s", myid, domain_name); | ||||||
2681 | switch_ivr_set_user(session, account); | ||||||
2682 | } | ||||||
2683 | } else { | ||||||
2684 | switch_channel_hangup(channel, SWITCH_CAUSE_USER_CHALLENGE)switch_channel_perform_hangup(channel, "mod_voicemail.c", (const char *)__func__, 2684, SWITCH_CAUSE_USER_CHALLENGE); | ||||||
2685 | } | ||||||
2686 | } | ||||||
2687 | |||||||
2688 | xml_safe_free(x_user)if (x_user) switch_xml_free(x_user); x_user = ((void*)0); | ||||||
2689 | } | ||||||
2690 | |||||||
2691 | |||||||
2692 | static switch_status_t deliver_vm(vm_profile_t *profile, | ||||||
2693 | switch_xml_t x_user, | ||||||
2694 | const char *domain_name, | ||||||
2695 | const char *path, | ||||||
2696 | uint32_t message_len, | ||||||
2697 | const char *read_flags, | ||||||
2698 | switch_event_t *params, | ||||||
2699 | switch_memory_pool_t *pool, | ||||||
2700 | const char *caller_id_name, | ||||||
2701 | const char *caller_id_number, | ||||||
2702 | const char *forwarded_by, | ||||||
2703 | switch_bool_t copy, const char *use_uuid, switch_core_session_t *session) | ||||||
2704 | { | ||||||
2705 | char *file_path = NULL((void*)0), *dir_path = NULL((void*)0); | ||||||
2706 | const char *myid = switch_xml_attr(x_user, "id"); | ||||||
2707 | switch_uuid_t uuid; | ||||||
2708 | char uuid_str[SWITCH_UUID_FORMATTED_LENGTH256 + 1]; | ||||||
2709 | const char *filename; | ||||||
2710 | switch_xml_t x_param, x_params; | ||||||
2711 | const char *vm_cc = NULL((void*)0), *vm_cc_tmp = NULL((void*)0); | ||||||
2712 | char *vm_email = NULL((void*)0); | ||||||
2713 | char *vm_email_from = NULL((void*)0); | ||||||
2714 | char *vm_notify_email = NULL((void*)0); | ||||||
2715 | char *vm_timezone = NULL((void*)0); | ||||||
2716 | int send_mail = 0; | ||||||
2717 | int send_main = 0; | ||||||
2718 | int send_notify = 0; | ||||||
2719 | int insert_db = 1; | ||||||
2720 | int email_attach = 0; | ||||||
2721 | char *vm_storage_dir = NULL((void*)0); | ||||||
2722 | char *storage_dir = NULL((void*)0); | ||||||
2723 | char *myfolder = "inbox"; | ||||||
2724 | int priority = 3; | ||||||
2725 | const char *tmp; | ||||||
2726 | switch_event_t *local_event = NULL((void*)0); | ||||||
2727 | switch_status_t ret = SWITCH_STATUS_SUCCESS; | ||||||
2728 | char *convert_cmd = profile->convert_cmd; | ||||||
2729 | char *convert_ext = profile->convert_ext; | ||||||
2730 | |||||||
2731 | if (!params) { | ||||||
2732 | switch_event_create(&local_event, SWITCH_EVENT_REQUEST_PARAMS)switch_event_create_subclass_detailed("mod_voicemail.c", (const char * )(const char *)__func__, 2732, &local_event, SWITCH_EVENT_REQUEST_PARAMS , ((void*)0)); | ||||||
2733 | params = local_event; | ||||||
2734 | } | ||||||
2735 | |||||||
2736 | if ((tmp = switch_event_get_header(params, "effective_caller_id_name")switch_event_get_header_idx(params, "effective_caller_id_name" , -1))) { | ||||||
2737 | caller_id_name = tmp; | ||||||
2738 | } | ||||||
2739 | |||||||
2740 | if ((tmp = switch_event_get_header(params, "effective_caller_id_number")switch_event_get_header_idx(params, "effective_caller_id_number" , -1))) { | ||||||
2741 | caller_id_number = tmp; | ||||||
2742 | } | ||||||
2743 | |||||||
2744 | if (!use_uuid) { | ||||||
2745 | switch_uuid_get(&uuid); | ||||||
2746 | switch_uuid_format(uuid_str, &uuid); | ||||||
2747 | use_uuid = uuid_str; | ||||||
2748 | } | ||||||
2749 | |||||||
2750 | if ((filename = strrchr(path, *SWITCH_PATH_SEPARATOR"/"))) { | ||||||
2751 | filename++; | ||||||
2752 | } else { | ||||||
2753 | filename = path; | ||||||
2754 | } | ||||||
2755 | |||||||
2756 | x_params = switch_xml_child(x_user, "variables"); | ||||||
2757 | for (x_param = switch_xml_child(x_params, "variable"); x_param; x_param = x_param->next) { | ||||||
2758 | const char *var = switch_xml_attr_soft(x_param, "name"); | ||||||
2759 | const char *val = switch_xml_attr_soft(x_param, "value"); | ||||||
2760 | |||||||
2761 | if (!strcasecmp(var, "timezone")) { | ||||||
2762 | vm_timezone = switch_core_strdup(pool, val)switch_core_perform_strdup(pool, val, "mod_voicemail.c", (const char *)__func__, 2762); | ||||||
2763 | } | ||||||
2764 | } | ||||||
2765 | |||||||
2766 | x_params = switch_xml_child(x_user, "params"); | ||||||
2767 | |||||||
2768 | for (x_param = switch_xml_child(x_params, "param"); x_param; x_param = x_param->next) { | ||||||
2769 | const char *var = switch_xml_attr_soft(x_param, "name"); | ||||||
2770 | const char *val = switch_xml_attr_soft(x_param, "value"); | ||||||
2771 | |||||||
2772 | if (!strcasecmp(var, "vm-cc")) { | ||||||
2773 | vm_cc = switch_core_strdup(pool, val)switch_core_perform_strdup(pool, val, "mod_voicemail.c", (const char *)__func__, 2773); | ||||||
2774 | } else if (!strcasecmp(var, "vm-mailto")) { | ||||||
2775 | vm_email = switch_core_strdup(pool, val)switch_core_perform_strdup(pool, val, "mod_voicemail.c", (const char *)__func__, 2775); | ||||||
2776 | } else if (!strcasecmp(var, "vm-notify-mailto")) { | ||||||
2777 | vm_notify_email = switch_core_strdup(pool, val)switch_core_perform_strdup(pool, val, "mod_voicemail.c", (const char *)__func__, 2777); | ||||||
2778 | } else if (!strcasecmp(var, "vm-mailfrom")) { | ||||||
2779 | vm_email_from = switch_core_strdup(pool, val)switch_core_perform_strdup(pool, val, "mod_voicemail.c", (const char *)__func__, 2779); | ||||||
2780 | } else if (!strcasecmp(var, "vm-email-all-messages") && (send_main = switch_true(val))) { | ||||||
2781 | send_mail++; | ||||||
2782 | } else if (!strcasecmp(var, "vm-storage-dir")) { | ||||||
2783 | vm_storage_dir = switch_core_strdup(pool, val)switch_core_perform_strdup(pool, val, "mod_voicemail.c", (const char *)__func__, 2783); | ||||||
2784 | } else if (!strcasecmp(var, "vm-domain-storage-dir")) { | ||||||
2785 | storage_dir = switch_core_strdup(pool, val)switch_core_perform_strdup(pool, val, "mod_voicemail.c", (const char *)__func__, 2785); | ||||||
2786 | } else if (!strcasecmp(var, "storage-dir")) { | ||||||
2787 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 2787, ((void*)0), SWITCH_LOG_WARNING, | ||||||
2788 | "Using deprecated 'storage-dir' directory variable: Please use 'vm-domain-storage-dir'.\n"); | ||||||
2789 | storage_dir = switch_core_strdup(pool, val)switch_core_perform_strdup(pool, val, "mod_voicemail.c", (const char *)__func__, 2789); | ||||||
2790 | } else if (!strcasecmp(var, "vm-notify-email-all-messages") && (send_notify = switch_true(val))) { | ||||||
2791 | send_mail++; | ||||||
2792 | } else if (!strcasecmp(var, "vm-keep-local-after-email")) { | ||||||
2793 | insert_db = switch_true(val); | ||||||
2794 | } else if (!strcasecmp(var, "vm-attach-file")) { | ||||||
2795 | email_attach = switch_true(val); | ||||||
2796 | } else if (!strcasecmp(var, "vm-convert-cmd")) { | ||||||
2797 | convert_cmd = switch_core_strdup(pool, val)switch_core_perform_strdup(pool, val, "mod_voicemail.c", (const char *)__func__, 2797); | ||||||
2798 | } else if (!strcasecmp(var, "vm-convert-ext")) { | ||||||
2799 | convert_ext = switch_core_strdup(pool, val)switch_core_perform_strdup(pool, val, "mod_voicemail.c", (const char *)__func__, 2799); | ||||||
2800 | } else if (!strcasecmp(var, "timezone")) { | ||||||
2801 | vm_timezone = switch_core_strdup(pool, val)switch_core_perform_strdup(pool, val, "mod_voicemail.c", (const char *)__func__, 2801); | ||||||
2802 | } | ||||||
2803 | /*switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Send mail is %d, var is %s\n", send_mail, var); */ | ||||||
2804 | } | ||||||
2805 | |||||||
2806 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 2806, ((void*)0), SWITCH_LOG_DEBUG, "Deliver VM to %s@%s\n", myid, domain_name); | ||||||
2807 | |||||||
2808 | if (!zstr(vm_storage_dir)_zstr(vm_storage_dir)) { | ||||||
2809 | /* check for absolute or relative path */ | ||||||
2810 | if (switch_is_file_path(vm_storage_dir)) { | ||||||
2811 | dir_path = strdup(vm_storage_dir)(__extension__ (__builtin_constant_p (vm_storage_dir) && ((size_t)(const void *)((vm_storage_dir) + 1) - (size_t)(const void *)(vm_storage_dir) == 1) ? (((const char *) (vm_storage_dir ))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen (vm_storage_dir) + 1; char *__retval = (char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, vm_storage_dir, __len); __retval ; })) : __strdup (vm_storage_dir))); | ||||||
2812 | } else { | ||||||
2813 | dir_path = switch_mprintf("%s%svoicemail%s%s", SWITCH_GLOBAL_dirs.storage_dir, | ||||||
2814 | SWITCH_PATH_SEPARATOR"/", SWITCH_PATH_SEPARATOR"/", vm_storage_dir); | ||||||
2815 | } | ||||||
2816 | } else if (!zstr(storage_dir)_zstr(storage_dir)) { | ||||||
2817 | dir_path = switch_mprintf("%s%s%s", storage_dir, SWITCH_PATH_SEPARATOR"/", myid); | ||||||
2818 | } else if (!zstr(profile->storage_dir)_zstr(profile->storage_dir)) { | ||||||
2819 | if (profile->storage_dir_shared) { | ||||||
2820 | dir_path = switch_mprintf("%s%s%s%s%s%s%s", profile->storage_dir, SWITCH_PATH_SEPARATOR"/", domain_name, SWITCH_PATH_SEPARATOR"/", "voicemail", SWITCH_PATH_SEPARATOR"/", myid); | ||||||
2821 | } else { | ||||||
2822 | dir_path = switch_mprintf("%s%s%s%s%s", profile->storage_dir, SWITCH_PATH_SEPARATOR"/", domain_name, SWITCH_PATH_SEPARATOR"/", myid); | ||||||
2823 | } | ||||||
2824 | } else { | ||||||
2825 | dir_path = switch_mprintf("%s%svoicemail%s%s%s%s%s%s", SWITCH_GLOBAL_dirs.storage_dir, | ||||||
2826 | SWITCH_PATH_SEPARATOR"/", | ||||||
2827 | SWITCH_PATH_SEPARATOR"/", profile->name, SWITCH_PATH_SEPARATOR"/", domain_name, SWITCH_PATH_SEPARATOR"/", myid); | ||||||
2828 | } | ||||||
2829 | |||||||
2830 | if (switch_dir_make_recursive(dir_path, SWITCH_DEFAULT_DIR_PERMS0x0400 | 0x0200 | 0x0100 | 0x0040 | 0x0010, pool) != SWITCH_STATUS_SUCCESS) { | ||||||
2831 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 2831, ((void*)0), SWITCH_LOG_ERROR, "Error creating %s\n", dir_path); | ||||||
2832 | ret = SWITCH_STATUS_FALSE; | ||||||
2833 | goto failed; | ||||||
2834 | } | ||||||
2835 | |||||||
2836 | if (copy) { | ||||||
2837 | file_path = switch_mprintf("%s%smsg_%s_broadcast_%s", dir_path, SWITCH_PATH_SEPARATOR"/", use_uuid, filename); | ||||||
2838 | |||||||
2839 | if (strlen(file_path) >= 250 /* Max size of the SQL field */) { | ||||||
2840 | char *ext; | ||||||
2841 | switch_safe_free(file_path)if (file_path) {free(file_path);file_path=((void*)0);}; | ||||||
2842 | |||||||
2843 | if (!(ext = strrchr(filename, '.'))) { | ||||||
2844 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 2844, ((void*)0), SWITCH_LOG_ERROR, "Filename doesn't include a file format %s\n", filename); | ||||||
2845 | ret = SWITCH_STATUS_FALSE; | ||||||
2846 | goto failed; | ||||||
2847 | } | ||||||
2848 | |||||||
2849 | ext++; | ||||||
2850 | |||||||
2851 | file_path = switch_mprintf("%s%smsg_%s_broadcast_%" SWITCH_TIME_T_FMT"ld" ".%s", dir_path, SWITCH_PATH_SEPARATOR"/", use_uuid, switch_micro_time_now(), ext); | ||||||
2852 | } | ||||||
2853 | |||||||
2854 | switch_file_copy(path, file_path, SWITCH_FPROT_FILE_SOURCE_PERMS0x1000, pool); | ||||||
2855 | } else { | ||||||
2856 | file_path = (char *) path; | ||||||
2857 | } | ||||||
2858 | |||||||
2859 | if (!message_len) { | ||||||
2860 | size_t len = 0; | ||||||
2861 | if (measure_file_len(file_path, &len) == SWITCH_STATUS_SUCCESS) { | ||||||
2862 | message_len = (uint32_t)len; | ||||||
2863 | } | ||||||
2864 | } | ||||||
2865 | |||||||
2866 | if (insert_db && switch_file_exists(file_path, pool) == SWITCH_STATUS_SUCCESS) { | ||||||
2867 | char *usql; | ||||||
2868 | switch_event_t *message_event; | ||||||
2869 | |||||||
2870 | switch_event_create_subclass(&message_event, SWITCH_EVENT_CUSTOM, VM_EVENT_MAINT)switch_event_create_subclass_detailed("mod_voicemail.c", (const char * )(const char *)__func__, 2870, &message_event, SWITCH_EVENT_CUSTOM , "vm::maintenance"); | ||||||
2871 | switch_event_add_header_string(message_event, SWITCH_STACK_BOTTOM, "VM-Action", "leave-message"); | ||||||
2872 | switch_event_add_header_string(message_event, SWITCH_STACK_BOTTOM, "VM-User", myid); | ||||||
2873 | switch_event_add_header_string(message_event, SWITCH_STACK_BOTTOM, "VM-Domain", domain_name); | ||||||
2874 | switch_event_add_header_string(message_event, SWITCH_STACK_BOTTOM, "VM-Caller-ID-Name", caller_id_name); | ||||||
2875 | switch_event_add_header_string(message_event, SWITCH_STACK_BOTTOM, "VM-Caller-ID-Number", caller_id_number); | ||||||
2876 | switch_event_add_header_string(message_event, SWITCH_STACK_BOTTOM, "VM-File-Path", file_path); | ||||||
2877 | switch_event_add_header_string(message_event, SWITCH_STACK_BOTTOM, "VM-Flags", read_flags); | ||||||
2878 | switch_event_add_header_string(message_event, SWITCH_STACK_BOTTOM, "VM-Folder", myfolder); | ||||||
2879 | switch_event_add_header_string(message_event, SWITCH_STACK_BOTTOM, "VM-UUID", use_uuid); | ||||||
2880 | switch_event_add_header(message_event, SWITCH_STACK_BOTTOM, "VM-Message-Len", "%u", message_len); | ||||||
2881 | switch_event_add_header(message_event, SWITCH_STACK_BOTTOM, "VM-Timestamp", "%lu", (unsigned long) switch_epoch_time_now(NULL((void*)0))); | ||||||
2882 | |||||||
2883 | switch_event_fire(&message_event)switch_event_fire_detailed("mod_voicemail.c", (const char * ) (const char *)__func__, 2883, &message_event, ((void*)0)); | ||||||
2884 | |||||||
2885 | usql = switch_mprintf("insert into voicemail_msgs(created_epoch, read_epoch, username, domain, uuid, cid_name, " | ||||||
2886 | "cid_number, in_folder, file_path, message_len, flags, read_flags, forwarded_by) " | ||||||
2887 | "values(%ld,0,'%q','%q','%q','%q','%q','%q','%q','%u','','%q','%q')", (long) switch_epoch_time_now(NULL((void*)0)), | ||||||
2888 | myid, domain_name, use_uuid, caller_id_name, caller_id_number, | ||||||
2889 | myfolder, file_path, message_len, read_flags, switch_str_nil(forwarded_by)(forwarded_by ? forwarded_by : "")); | ||||||
2890 | |||||||
2891 | vm_execute_sql(profile, usql, profile->mutex); | ||||||
2892 | switch_safe_free(usql)if (usql) {free(usql);usql=((void*)0);}; | ||||||
2893 | |||||||
2894 | update_mwi(profile, myid, domain_name, myfolder, MWI_REASON_NEW); | ||||||
2895 | } | ||||||
2896 | |||||||
2897 | if (send_mail && (!zstr(vm_email)_zstr(vm_email) || !zstr(vm_notify_email)_zstr(vm_notify_email)) && switch_file_exists(file_path, pool) == SWITCH_STATUS_SUCCESS) { | ||||||
2898 | switch_event_t *event; | ||||||
2899 | char *from; | ||||||
2900 | char *body; | ||||||
2901 | char *headers; | ||||||
2902 | char *header_string; | ||||||
2903 | char tmpvar[50] = ""; | ||||||
2904 | int total_new_messages = 0; | ||||||
2905 | int total_saved_messages = 0; | ||||||
2906 | int total_new_urgent_messages = 0; | ||||||
2907 | int total_saved_urgent_messages = 0; | ||||||
2908 | char *p; | ||||||
2909 | switch_time_t l_duration = 0; | ||||||
2910 | switch_core_time_duration_t duration; | ||||||
2911 | char duration_str[80]; | ||||||
2912 | switch_time_exp_t tm; | ||||||
2913 | char date[80] = ""; | ||||||
2914 | switch_size_t retsize; | ||||||
2915 | char *formatted_cid_num = NULL((void*)0); | ||||||
2916 | |||||||
2917 | message_count(profile, myid, domain_name, myfolder, &total_new_messages, &total_saved_messages, | ||||||
2918 | &total_new_urgent_messages, &total_saved_urgent_messages); | ||||||
2919 | |||||||
2920 | if (zstr(vm_timezone)_zstr(vm_timezone) || (switch_strftime_tz(vm_timezone, profile->date_fmt, date, sizeof(date), 0) != SWITCH_STATUS_SUCCESS)) { | ||||||
2921 | switch_time_exp_lt(&tm, switch_micro_time_now()); | ||||||
2922 | switch_strftime(date, &retsize, sizeof(date), profile->date_fmt, &tm); | ||||||
2923 | } | ||||||
2924 | |||||||
2925 | formatted_cid_num = switch_format_number(caller_id_number); | ||||||
2926 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "voicemail_current_folder", myfolder); | ||||||
2927 | switch_snprintf(tmpvar, sizeof(tmpvar), "%d", total_new_messages); | ||||||
2928 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "voicemail_total_new_messages", tmpvar); | ||||||
2929 | switch_snprintf(tmpvar, sizeof(tmpvar), "%d", total_saved_messages); | ||||||
2930 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "voicemail_total_saved_messages", tmpvar); | ||||||
2931 | switch_snprintf(tmpvar, sizeof(tmpvar), "%d", total_new_urgent_messages); | ||||||
2932 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "voicemail_urgent_new_messages", tmpvar); | ||||||
2933 | switch_snprintf(tmpvar, sizeof(tmpvar), "%d", total_saved_urgent_messages); | ||||||
2934 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "voicemail_urgent_saved_messages", tmpvar); | ||||||
2935 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "voicemail_account", myid); | ||||||
2936 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "voicemail_domain", domain_name); | ||||||
2937 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "voicemail_caller_id_number", caller_id_number); | ||||||
2938 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "voicemail_formatted_caller_id_number", formatted_cid_num); | ||||||
2939 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "voicemail_caller_id_name", caller_id_name); | ||||||
2940 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "voicemail_file_path", file_path); | ||||||
2941 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "voicemail_read_flags", read_flags); | ||||||
2942 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "voicemail_time", date); | ||||||
2943 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "voicemail_uuid", use_uuid); | ||||||
2944 | |||||||
2945 | switch_safe_free(formatted_cid_num)if (formatted_cid_num) {free(formatted_cid_num);formatted_cid_num =((void*)0);}; | ||||||
2946 | |||||||
2947 | switch_snprintf(tmpvar, sizeof(tmpvar), "%d", priority); | ||||||
2948 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "voicemail_priority", tmpvar); | ||||||
2949 | if (vm_email) { | ||||||
2950 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "voicemail_email", vm_email); | ||||||
2951 | } | ||||||
2952 | if (vm_email_from) { | ||||||
2953 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "voicemail_email_from", vm_email_from); | ||||||
2954 | } | ||||||
2955 | if (vm_notify_email) { | ||||||
2956 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "voicemail_notify_email", vm_notify_email); | ||||||
2957 | } | ||||||
2958 | l_duration = switch_time_make(message_len, 0); | ||||||
2959 | switch_core_measure_time(l_duration, &duration); | ||||||
2960 | duration.day += duration.yr * 365; | ||||||
2961 | duration.hr += duration.day * 24; | ||||||
2962 | switch_snprintf(duration_str, sizeof(duration_str), "%.2u:%.2u:%.2u", duration.hr, duration.min, duration.sec); | ||||||
2963 | |||||||
2964 | switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "voicemail_message_len", duration_str); | ||||||
2965 | |||||||
2966 | if (!zstr(vm_email_from)_zstr(vm_email_from)) { | ||||||
2967 | from = switch_core_strdup(pool, vm_email_from)switch_core_perform_strdup(pool, vm_email_from, "mod_voicemail.c" , (const char *)__func__, 2967); | ||||||
2968 | } else if (zstr(profile->email_from)_zstr(profile->email_from)) { | ||||||
2969 | from = switch_core_sprintf(pool, "%s@%s", myid, domain_name); | ||||||
2970 | } else { | ||||||
2971 | from = switch_event_expand_headers(params, profile->email_from)switch_event_expand_headers_check(params, profile->email_from , ((void*)0), ((void*)0), 0); | ||||||
2972 | } | ||||||
2973 | |||||||
2974 | |||||||
2975 | if (send_main) { | ||||||
2976 | if (zstr(profile->email_headers)_zstr(profile->email_headers)) { | ||||||
2977 | headers = switch_mprintf("From: FreeSWITCH mod_voicemail <%s@%s>\n" | ||||||
2978 | "Subject: Voicemail from %s %s\nX-Priority: %d", myid, domain_name, caller_id_name, caller_id_number, priority); | ||||||
2979 | } else { | ||||||
2980 | headers = switch_event_expand_headers(params, profile->email_headers)switch_event_expand_headers_check(params, profile->email_headers , ((void*)0), ((void*)0), 0); | ||||||
2981 | } | ||||||
2982 | |||||||
2983 | p = headers + (strlen(headers) - 1); | ||||||
2984 | |||||||
2985 | if (*p == '\n') { | ||||||
2986 | if (*(p - 1) == '\r') { | ||||||
2987 | p--; | ||||||
2988 | } | ||||||
2989 | *p = '\0'; | ||||||
2990 | } | ||||||
2991 | |||||||
2992 | header_string = switch_core_sprintf(pool, "%s\nX-Voicemail-Length: %u", headers, message_len); | ||||||
2993 | |||||||
2994 | switch_event_dup(&event, params); | ||||||
2995 | |||||||
2996 | if (event) { | ||||||
2997 | switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Message-Type", "voicemail"); | ||||||
2998 | switch_event_fire(&event)switch_event_fire_detailed("mod_voicemail.c", (const char * ) (const char *)__func__, 2998, &event, ((void*)0)); | ||||||
2999 | } | ||||||
3000 | |||||||
3001 | if (profile->email_body) { | ||||||
3002 | body = switch_event_expand_headers(params, profile->email_body)switch_event_expand_headers_check(params, profile->email_body , ((void*)0), ((void*)0), 0); | ||||||
3003 | } else { | ||||||
3004 | body = switch_mprintf("%u second Voicemail from %s %s", message_len, caller_id_name, caller_id_number); | ||||||
3005 | } | ||||||
3006 | |||||||
3007 | if (email_attach) { | ||||||
3008 | switch_simple_email(vm_email, from, header_string, body, file_path, convert_cmd, convert_ext); | ||||||
3009 | } else { | ||||||
3010 | switch_simple_email(vm_email, from, header_string, body, NULL((void*)0), NULL((void*)0), NULL((void*)0)); | ||||||
3011 | } | ||||||
3012 | |||||||
3013 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 3013, ((void*)0), SWITCH_LOG_DEBUG, "Sending message to %s\n", vm_email); | ||||||
3014 | |||||||
3015 | if (body != profile->email_body) { | ||||||
3016 | switch_safe_free(body)if (body) {free(body);body=((void*)0);}; | ||||||
3017 | } | ||||||
3018 | |||||||
3019 | if (headers != profile->email_headers) { | ||||||
3020 | switch_safe_free(headers)if (headers) {free(headers);headers=((void*)0);}; | ||||||
3021 | } | ||||||
3022 | } | ||||||
3023 | |||||||
3024 | |||||||
3025 | if (send_notify) { | ||||||
3026 | if (zstr(vm_notify_email)_zstr(vm_notify_email)) { | ||||||
3027 | vm_notify_email = vm_email; | ||||||
3028 | } | ||||||
3029 | |||||||
3030 | if (zstr(profile->notify_email_headers)_zstr(profile->notify_email_headers)) { | ||||||
3031 | headers = switch_mprintf("From: FreeSWITCH mod_voicemail <%s@%s>\n" | ||||||
3032 | "Subject: Voicemail from %s %s\nX-Priority: %d", myid, domain_name, caller_id_name, caller_id_number, priority); | ||||||
3033 | } else { | ||||||
3034 | headers = switch_event_expand_headers(params, profile->notify_email_headers)switch_event_expand_headers_check(params, profile->notify_email_headers , ((void*)0), ((void*)0), 0); | ||||||
3035 | } | ||||||
3036 | |||||||
3037 | p = headers + (strlen(headers) - 1); | ||||||
3038 | |||||||
3039 | if (*p == '\n') { | ||||||
3040 | if (*(p - 1) == '\r') { | ||||||
3041 | p--; | ||||||
3042 | } | ||||||
3043 | *p = '\0'; | ||||||
3044 | } | ||||||
3045 | |||||||
3046 | header_string = switch_core_sprintf(pool, "%s\nX-Voicemail-Length: %u", headers, message_len); | ||||||
3047 | |||||||
3048 | switch_event_dup(&event, params); | ||||||
3049 | |||||||
3050 | if (event) { | ||||||
3051 | switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Message-Type", "voicemail-notify"); | ||||||
3052 | switch_event_fire(&event)switch_event_fire_detailed("mod_voicemail.c", (const char * ) (const char *)__func__, 3052, &event, ((void*)0)); | ||||||
3053 | } | ||||||
3054 | |||||||
3055 | if (profile->notify_email_body) { | ||||||
3056 | body = switch_event_expand_headers(params, profile->notify_email_body)switch_event_expand_headers_check(params, profile->notify_email_body , ((void*)0), ((void*)0), 0); | ||||||
3057 | } else { | ||||||
3058 | body = switch_mprintf("%u second Voicemail from %s %s", message_len, caller_id_name, caller_id_number); | ||||||
3059 | } | ||||||
3060 | |||||||
3061 | switch_simple_email(vm_notify_email, from, header_string, body, NULL((void*)0), NULL((void*)0), NULL((void*)0)); | ||||||
3062 | |||||||
3063 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 3063, ((void*)0), SWITCH_LOG_DEBUG, "Sending notify message to %s\n", vm_notify_email); | ||||||
3064 | |||||||
3065 | if (body != profile->notify_email_body) { | ||||||
3066 | switch_safe_free(body)if (body) {free(body);body=((void*)0);}; | ||||||
3067 | } | ||||||
3068 | |||||||
3069 | if (headers != profile->notify_email_headers) { | ||||||
3070 | switch_safe_free(headers)if (headers) {free(headers);headers=((void*)0);}; | ||||||
3071 | } | ||||||
3072 | } | ||||||
3073 | } | ||||||
3074 | |||||||
3075 | if (session) { | ||||||
3076 | switch_channel_t *channel = switch_core_session_get_channel(session); | ||||||
3077 | if (channel && (vm_cc_tmp = switch_channel_get_variable(channel, "vm_cc")switch_channel_get_variable_dup(channel, "vm_cc", SWITCH_TRUE , -1))) { | ||||||
3078 | vm_cc = vm_cc_tmp; | ||||||
3079 | } | ||||||
3080 | } | ||||||
3081 | |||||||
3082 | if (vm_cc) { | ||||||
3083 | char *vm_cc_dup; | ||||||
3084 | int vm_cc_num = 0; | ||||||
3085 | char *vm_cc_list[256] = { 0 }; | ||||||
3086 | int vm_cc_i; | ||||||
3087 | |||||||
3088 | vm_cc_dup = strdup(vm_cc)(__extension__ (__builtin_constant_p (vm_cc) && ((size_t )(const void *)((vm_cc) + 1) - (size_t)(const void *)(vm_cc) == 1) ? (((const char *) (vm_cc))[0] == '\0' ? (char *) calloc ( (size_t) 1, (size_t) 1) : ({ size_t __len = strlen (vm_cc) + 1 ; char *__retval = (char *) malloc (__len); if (__retval != ( (void*)0)) __retval = (char *) memcpy (__retval, vm_cc, __len ); __retval; })) : __strdup (vm_cc))); | ||||||
3089 | vm_cc_num = switch_separate_string(vm_cc_dup, ',', vm_cc_list, (sizeof(vm_cc_list) / sizeof(vm_cc_list[0]))); | ||||||
3090 | |||||||
3091 | for (vm_cc_i=0; vm_cc_i<vm_cc_num; vm_cc_i++) { | ||||||
3092 | char *cmd, *val; | ||||||
3093 | const char *vm_cc_current = vm_cc_list[vm_cc_i]; | ||||||
3094 | |||||||
3095 | val = strdup(caller_id_name)(__extension__ (__builtin_constant_p (caller_id_name) && ((size_t)(const void *)((caller_id_name) + 1) - (size_t)(const void *)(caller_id_name) == 1) ? (((const char *) (caller_id_name ))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen (caller_id_name) + 1; char *__retval = (char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, caller_id_name, __len); __retval ; })) : __strdup (caller_id_name))); | ||||||
3096 | switch_url_decode(val); | ||||||
3097 | |||||||
3098 | cmd = switch_mprintf("%s %s %s '%s' %s@%s %s", | ||||||
3099 | vm_cc_current, file_path, caller_id_number, | ||||||
3100 | val, myid, domain_name, read_flags); | ||||||
3101 | |||||||
3102 | free(val); | ||||||
3103 | |||||||
3104 | if (voicemail_inject(cmd, session) == SWITCH_STATUS_SUCCESS) { | ||||||
3105 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "mod_voicemail.c", (const char *)__func__ , 3105, (const char*)(session), SWITCH_LOG_NOTICE, "Sent Carbon Copy to %s\n", vm_cc_current); | ||||||
3106 | } else { | ||||||
3107 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "mod_voicemail.c", (const char *)__func__ , 3107, (const char*)(session), SWITCH_LOG_ERROR, "Failed to Carbon Copy to %s\n", vm_cc_current); | ||||||
3108 | } | ||||||
3109 | switch_safe_free(cmd)if (cmd) {free(cmd);cmd=((void*)0);}; | ||||||
3110 | } | ||||||
3111 | |||||||
3112 | switch_safe_free(vm_cc_dup)if (vm_cc_dup) {free(vm_cc_dup);vm_cc_dup=((void*)0);}; | ||||||
3113 | } | ||||||
3114 | |||||||
3115 | |||||||
3116 | failed: | ||||||
3117 | |||||||
3118 | if (!insert_db && file_path && switch_file_exists(file_path, pool) == SWITCH_STATUS_SUCCESS) { | ||||||
3119 | if (unlink(file_path) != 0) { | ||||||
3120 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 3120, ((void*)0), SWITCH_LOG_WARNING, "Failed to delete file [%s]\n", file_path); | ||||||
3121 | } | ||||||
3122 | } | ||||||
3123 | |||||||
3124 | switch_event_destroy(&local_event); | ||||||
3125 | |||||||
3126 | switch_safe_free(dir_path)if (dir_path) {free(dir_path);dir_path=((void*)0);}; | ||||||
3127 | |||||||
3128 | if (file_path != path) { | ||||||
3129 | switch_safe_free(file_path)if (file_path) {free(file_path);file_path=((void*)0);}; | ||||||
3130 | } | ||||||
3131 | |||||||
3132 | return ret; | ||||||
3133 | |||||||
3134 | } | ||||||
3135 | |||||||
3136 | static switch_status_t voicemail_inject(const char *data, switch_core_session_t *session) | ||||||
3137 | { | ||||||
3138 | vm_profile_t *profile; | ||||||
3139 | char *dup = NULL((void*)0), *user = NULL((void*)0), *domain = NULL((void*)0), *profile_name = NULL((void*)0); | ||||||
3140 | switch_status_t status = SWITCH_STATUS_SUCCESS; | ||||||
3141 | int isgroup = 0, isall = 0; | ||||||
3142 | int argc = 0; | ||||||
3143 | char *argv[6] = { 0 }; | ||||||
3144 | char *box, *path, *cid_num, *cid_name; | ||||||
3145 | switch_memory_pool_t *pool = NULL((void*)0); | ||||||
3146 | char *forwarded_by = NULL((void*)0); | ||||||
3147 | char *read_flags = NORMAL_FLAG_STRING"B_NORMAL"; | ||||||
3148 | char *dup_domain = NULL((void*)0); | ||||||
3149 | |||||||
3150 | if (zstr(data)_zstr(data)) { | ||||||
3151 | status = SWITCH_STATUS_FALSE; | ||||||
3152 | goto end; | ||||||
3153 | } | ||||||
3154 | |||||||
3155 | dup = 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))); | ||||||
3156 | switch_assert(dup)((dup) ? (void) (0) : __assert_fail ("dup", "mod_voicemail.c" , 3156, __PRETTY_FUNCTION__)); | ||||||
3157 | |||||||
3158 | if ((argc = switch_separate_string(dup, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) < 2) { | ||||||
3159 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 3159, ((void*)0), SWITCH_LOG_ERROR, "Not enough args [%s]\n", data); | ||||||
3160 | status = SWITCH_STATUS_FALSE; | ||||||
3161 | goto end; | ||||||
3162 | } | ||||||
3163 | |||||||
3164 | box = argv[0]; | ||||||
3165 | path = argv[1]; | ||||||
3166 | cid_num = argv[2] ? argv[2] : "anonymous"; | ||||||
3167 | cid_name = argv[3] ? argv[3] : "anonymous"; | ||||||
3168 | forwarded_by = argv[4]; | ||||||
3169 | if (!zstr(argv[5])_zstr(argv[5])) { | ||||||
3170 | read_flags = argv[5]; | ||||||
3171 | } | ||||||
3172 | |||||||
3173 | user = box; | ||||||
3174 | |||||||
3175 | if ((domain = strchr(user, '@')(__extension__ (__builtin_constant_p ('@') && !__builtin_constant_p (user) && ('@') == '\0' ? (char *) __rawmemchr (user , '@') : __builtin_strchr (user, '@'))))) { | ||||||
3176 | *domain++ = '\0'; | ||||||
3177 | |||||||
3178 | if ((profile_name = strchr(domain, '@')(__extension__ (__builtin_constant_p ('@') && !__builtin_constant_p (domain) && ('@') == '\0' ? (char *) __rawmemchr (domain , '@') : __builtin_strchr (domain, '@'))))) { | ||||||
3179 | *profile_name++ = '\0'; | ||||||
3180 | } else { | ||||||
3181 | profile_name = domain; | ||||||
3182 | } | ||||||
3183 | } | ||||||
3184 | |||||||
3185 | if (switch_stristr("group=", user)) { | ||||||
3186 | user += 6; | ||||||
3187 | isgroup++; | ||||||
3188 | } else if (switch_stristr("domain=", user)) { | ||||||
3189 | user += 7; | ||||||
3190 | domain = user; | ||||||
3191 | profile_name = domain; | ||||||
3192 | isall++; | ||||||
3193 | } | ||||||
3194 | |||||||
3195 | if (zstr(domain)_zstr(domain)) { | ||||||
3196 | if ((dup_domain = switch_core_get_domain(SWITCH_TRUE))) { | ||||||
3197 | domain = dup_domain; | ||||||
3198 | } | ||||||
3199 | profile_name = domain; | ||||||
3200 | } | ||||||
3201 | |||||||
3202 | if (!domain) { | ||||||
3203 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 3203, ((void*)0), SWITCH_LOG_ERROR, "Invalid syntax [%s][%s]\n", switch_str_nil(user)(user ? user : ""), switch_str_nil(domain)(domain ? domain : "")); | ||||||
3204 | status = SWITCH_STATUS_FALSE; | ||||||
3205 | goto end; | ||||||
3206 | } | ||||||
3207 | |||||||
3208 | if (!(profile = get_profile(profile_name))) { | ||||||
3209 | if (!(profile = get_profile(domain))) { | ||||||
3210 | profile = get_profile("default"); | ||||||
3211 | } | ||||||
3212 | } | ||||||
3213 | |||||||
3214 | if (!profile) { | ||||||
3215 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 3215, ((void*)0), SWITCH_LOG_ERROR, "Can't find profile\n"); | ||||||
3216 | status = SWITCH_STATUS_FALSE; | ||||||
3217 | } else { | ||||||
3218 | switch_xml_t x_domain, xml_root; | ||||||
3219 | switch_event_t *my_params = NULL((void*)0); | ||||||
3220 | switch_xml_t ut; | ||||||
3221 | |||||||
3222 | switch_event_create(&my_params, SWITCH_EVENT_REQUEST_PARAMS)switch_event_create_subclass_detailed("mod_voicemail.c", (const char * )(const char *)__func__, 3222, &my_params, SWITCH_EVENT_REQUEST_PARAMS , ((void*)0)); | ||||||
3223 | switch_assert(my_params)((my_params) ? (void) (0) : __assert_fail ("my_params", "mod_voicemail.c" , 3223, __PRETTY_FUNCTION__)); | ||||||
3224 | |||||||
3225 | if (isgroup) { | ||||||
3226 | switch_event_add_header_string(my_params, SWITCH_STACK_BOTTOM, "group", user); | ||||||
3227 | } else { | ||||||
3228 | if (isall) { | ||||||
3229 | switch_event_add_header_string(my_params, SWITCH_STACK_BOTTOM, "user", "_all_"); | ||||||
3230 | } else { | ||||||
3231 | switch_event_add_header_string(my_params, SWITCH_STACK_BOTTOM, "user", user); | ||||||
3232 | } | ||||||
3233 | } | ||||||
3234 | |||||||
3235 | if (forwarded_by) { | ||||||
3236 | switch_event_add_header_string(my_params, SWITCH_STACK_BOTTOM, "Forwarded-By", forwarded_by); | ||||||
3237 | } | ||||||
3238 | switch_event_add_header_string(my_params, SWITCH_STACK_BOTTOM, "domain", domain); | ||||||
3239 | switch_event_add_header_string(my_params, SWITCH_STACK_BOTTOM, "purpose", "publish-vm"); | ||||||
3240 | |||||||
3241 | if (switch_xml_locate_domain(domain, my_params, &xml_root, &x_domain) != SWITCH_STATUS_SUCCESS) { | ||||||
3242 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 3242, ((void*)0), SWITCH_LOG_WARNING, "Cannot locate domain %s\n", domain); | ||||||
3243 | status = SWITCH_STATUS_FALSE; | ||||||
3244 | switch_event_destroy(&my_params); | ||||||
3245 | profile_rwunlock(profile); | ||||||
3246 | goto end; | ||||||
3247 | } | ||||||
3248 | |||||||
3249 | switch_event_destroy(&my_params); | ||||||
3250 | |||||||
3251 | switch_core_new_memory_pool(&pool)switch_core_perform_new_memory_pool(&pool, "mod_voicemail.c" , (const char *)__func__, 3251); | ||||||
3252 | |||||||
3253 | |||||||
3254 | if (isgroup) { | ||||||
3255 | switch_xml_t group = NULL((void*)0), groups = NULL((void*)0), users = NULL((void*)0); | ||||||
3256 | if ((groups = switch_xml_child(x_domain, "groups"))) { | ||||||
3257 | if ((group = switch_xml_find_child_multi(groups, "group", "name", user, NULL((void*)0)))) { | ||||||
3258 | if ((users = switch_xml_child(group, "users"))) { | ||||||
3259 | for (ut = switch_xml_child(users, "user"); ut; ut = ut->next) { | ||||||
3260 | const char *type = switch_xml_attr_soft(ut, "type"); | ||||||
3261 | |||||||
3262 | if (!strcasecmp(type, "pointer")) { | ||||||
3263 | const char *uname = switch_xml_attr_soft(ut, "id"); | ||||||
3264 | switch_xml_t ux; | ||||||
3265 | |||||||
3266 | if (switch_xml_locate_user_in_domain(uname, x_domain, &ux, NULL((void*)0)) == SWITCH_STATUS_SUCCESS) { | ||||||
3267 | switch_xml_merge_user(ux, x_domain, group); | ||||||
3268 | switch_event_create(&my_params, SWITCH_EVENT_REQUEST_PARAMS)switch_event_create_subclass_detailed("mod_voicemail.c", (const char * )(const char *)__func__, 3268, &my_params, SWITCH_EVENT_REQUEST_PARAMS , ((void*)0)); | ||||||
3269 | status = | ||||||
3270 | deliver_vm(profile, ux, domain, path, 0, read_flags, my_params, pool, cid_name, cid_num, forwarded_by, | ||||||
3271 | SWITCH_TRUE, session ? switch_core_session_get_uuid(session) : NULL((void*)0), NULL((void*)0)); | ||||||
3272 | switch_event_destroy(&my_params); | ||||||
3273 | } | ||||||
3274 | continue; | ||||||
3275 | } | ||||||
3276 | |||||||
3277 | switch_xml_merge_user(ut, x_domain, group); | ||||||
3278 | switch_event_create(&my_params, SWITCH_EVENT_REQUEST_PARAMS)switch_event_create_subclass_detailed("mod_voicemail.c", (const char * )(const char *)__func__, 3278, &my_params, SWITCH_EVENT_REQUEST_PARAMS , ((void*)0)); | ||||||
3279 | status = deliver_vm(profile, ut, domain, path, 0, read_flags, | ||||||
3280 | my_params, pool, cid_name, cid_num, forwarded_by, SWITCH_TRUE, | ||||||
3281 | session ? switch_core_session_get_uuid(session) : NULL((void*)0), NULL((void*)0)); | ||||||
3282 | switch_event_destroy(&my_params); | ||||||
3283 | } | ||||||
3284 | } | ||||||
3285 | } else { | ||||||
3286 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 3286, ((void*)0), SWITCH_LOG_WARNING, "Cannot locate group %s\n", user); | ||||||
3287 | } | ||||||
3288 | } | ||||||
3289 | } else if (isall) { | ||||||
3290 | switch_xml_t group = NULL((void*)0), groups = NULL((void*)0), users = NULL((void*)0); | ||||||
3291 | if ((groups = switch_xml_child(x_domain, "groups"))) { | ||||||
3292 | for (group = switch_xml_child(groups, "group"); group; group = group->next) { | ||||||
3293 | if ((users = switch_xml_child(group, "users"))) { | ||||||
3294 | for (ut = switch_xml_child(users, "user"); ut; ut = ut->next) { | ||||||
3295 | const char *type = switch_xml_attr_soft(ut, "type"); | ||||||
3296 | |||||||
3297 | if (!strcasecmp(type, "pointer")) { | ||||||
3298 | continue; | ||||||
3299 | } | ||||||
3300 | |||||||
3301 | switch_xml_merge_user(ut, x_domain, group); | ||||||
3302 | switch_event_create(&my_params, SWITCH_EVENT_REQUEST_PARAMS)switch_event_create_subclass_detailed("mod_voicemail.c", (const char * )(const char *)__func__, 3302, &my_params, SWITCH_EVENT_REQUEST_PARAMS , ((void*)0)); | ||||||
3303 | status = deliver_vm(profile, ut, domain, path, 0, read_flags, | ||||||
3304 | my_params, pool, cid_name, cid_num, forwarded_by, SWITCH_TRUE, | ||||||
3305 | session ? switch_core_session_get_uuid(session) : NULL((void*)0), NULL((void*)0)); | ||||||
3306 | switch_event_destroy(&my_params); | ||||||
3307 | } | ||||||
3308 | } | ||||||
3309 | } | ||||||
3310 | } | ||||||
3311 | |||||||
3312 | } else { | ||||||
3313 | switch_xml_t x_group = NULL((void*)0); | ||||||
3314 | |||||||
3315 | if ((status = switch_xml_locate_user_in_domain(user, x_domain, &ut, &x_group)) == SWITCH_STATUS_SUCCESS) { | ||||||
3316 | switch_xml_merge_user(ut, x_domain, x_group); | ||||||
3317 | switch_event_create(&my_params, SWITCH_EVENT_REQUEST_PARAMS)switch_event_create_subclass_detailed("mod_voicemail.c", (const char * )(const char *)__func__, 3317, &my_params, SWITCH_EVENT_REQUEST_PARAMS , ((void*)0)); | ||||||
3318 | status = deliver_vm(profile, ut, domain, path, 0, read_flags, | ||||||
3319 | my_params, pool, cid_name, cid_num, forwarded_by, SWITCH_TRUE, | ||||||
3320 | session ? switch_core_session_get_uuid(session) : NULL((void*)0), NULL((void*)0)); | ||||||
3321 | switch_event_destroy(&my_params); | ||||||
3322 | } else { | ||||||
3323 | status = SWITCH_STATUS_FALSE; | ||||||
3324 | } | ||||||
3325 | } | ||||||
3326 | profile_rwunlock(profile); | ||||||
3327 | |||||||
3328 | switch_core_destroy_memory_pool(&pool)switch_core_perform_destroy_memory_pool(&pool, "mod_voicemail.c" , (const char *)__func__, 3328); | ||||||
3329 | |||||||
3330 | switch_xml_free(xml_root); | ||||||
3331 | } | ||||||
3332 | |||||||
3333 | end: | ||||||
3334 | |||||||
3335 | switch_safe_free(dup)if (dup) {free(dup);dup=((void*)0);}; | ||||||
3336 | switch_safe_free(dup_domain)if (dup_domain) {free(dup_domain);dup_domain=((void*)0);}; | ||||||
3337 | |||||||
3338 | return status; | ||||||
3339 | } | ||||||
3340 | |||||||
3341 | static switch_status_t voicemail_leave_main(switch_core_session_t *session, vm_profile_t *profile, const char *domain_name, const char *id) | ||||||
3342 | { | ||||||
3343 | switch_channel_t *channel = switch_core_session_get_channel(session); | ||||||
3344 | char sql[256]; | ||||||
3345 | prefs_callback_t cbt; | ||||||
3346 | switch_uuid_t tmp_uuid; | ||||||
3347 | char tmp_uuid_str[SWITCH_UUID_FORMATTED_LENGTH256 + 1]; | ||||||
3348 | char *file_path = NULL((void*)0); | ||||||
3349 | char *dir_path = NULL((void*)0); | ||||||
3350 | switch_status_t status = SWITCH_STATUS_SUCCESS; | ||||||
3351 | switch_caller_profile_t *caller_profile = switch_channel_get_caller_profile(channel); | ||||||
3352 | switch_file_handle_t fh = { 0 }; | ||||||
3353 | switch_input_args_t args = { 0 }; | ||||||
3354 | char *vm_email = NULL((void*)0); | ||||||
3355 | char *vm_notify_email = NULL((void*)0); | ||||||
3356 | cc_t cc = { 0 }; | ||||||
3357 | char *read_flags = NORMAL_FLAG_STRING"B_NORMAL"; | ||||||
3358 | const char *operator_ext = switch_channel_get_variable(channel, "vm_operator_extension")switch_channel_get_variable_dup(channel, "vm_operator_extension" , SWITCH_TRUE, -1); | ||||||
3359 | char buf[2]; | ||||||
3360 | char key_buf[80]; | ||||||
3361 | char *greet_path = NULL((void*)0); | ||||||
3362 | const char *voicemail_greeting_number = NULL((void*)0); | ||||||
3363 | switch_size_t message_len = 0; | ||||||
3364 | switch_time_exp_t tm; | ||||||
3365 | char date[80] = ""; | ||||||
3366 | switch_size_t retsize; | ||||||
3367 | switch_time_t ts = switch_micro_time_now(); | ||||||
3368 | char *vm_storage_dir = NULL((void*)0); | ||||||
3369 | char *storage_dir = NULL((void*)0); | ||||||
3370 | char *record_macro = VM_RECORD_MESSAGE_MACRO"voicemail_record_message"; | ||||||
3371 | int send_main = 0; | ||||||
3372 | int send_notify = 0; | ||||||
3373 | const char *read_id = NULL((void*)0); | ||||||
3374 | const char *caller_id_name = NULL((void*)0); | ||||||
3375 | const char *caller_id_number = NULL((void*)0); | ||||||
3376 | switch_xml_t x_user = NULL((void*)0), x_params = NULL((void*)0), x_param = NULL((void*)0); | ||||||
3377 | switch_event_t *vars = NULL((void*)0); | ||||||
3378 | const char *vtmp, *vm_ext = NULL((void*)0); | ||||||
3379 | int disk_quota = 0; | ||||||
3380 | switch_bool_t skip_greeting = switch_true(switch_channel_get_variable(channel, "skip_greeting")switch_channel_get_variable_dup(channel, "skip_greeting", SWITCH_TRUE , -1)); | ||||||
3381 | switch_bool_t skip_instructions = switch_true(switch_channel_get_variable(channel, "skip_instructions")switch_channel_get_variable_dup(channel, "skip_instructions", SWITCH_TRUE, -1)); | ||||||
3382 | switch_bool_t skip_record_urgent_check = switch_true(switch_channel_get_variable(channel, "skip_record_urgent_check")switch_channel_get_variable_dup(channel, "skip_record_urgent_check" , SWITCH_TRUE, -1)); | ||||||
3383 | switch_bool_t vm_enabled = SWITCH_TRUE; | ||||||
3384 | |||||||
3385 | switch_channel_set_variable(channel, "skip_greeting", NULL)switch_channel_set_variable_var_check(channel, "skip_greeting" , ((void*)0), SWITCH_TRUE); | ||||||
3386 | switch_channel_set_variable(channel, "skip_instructions", NULL)switch_channel_set_variable_var_check(channel, "skip_instructions" , ((void*)0), SWITCH_TRUE); | ||||||
3387 | switch_channel_set_variable(channel, "skip_record_urgent_check", NULL)switch_channel_set_variable_var_check(channel, "skip_record_urgent_check" , ((void*)0), SWITCH_TRUE); | ||||||
3388 | |||||||
3389 | memset(&cbt, 0, sizeof(cbt)); | ||||||
3390 | |||||||
3391 | if (id) { | ||||||
3392 | int ok = 1; | ||||||
3393 | switch_event_t *locate_params = NULL((void*)0); | ||||||
3394 | const char *email_addr = NULL((void*)0); | ||||||
3395 | |||||||
3396 | switch_event_create(&locate_params, SWITCH_EVENT_REQUEST_PARAMS)switch_event_create_subclass_detailed("mod_voicemail.c", (const char * )(const char *)__func__, 3396, &locate_params, SWITCH_EVENT_REQUEST_PARAMS , ((void*)0)); | ||||||
3397 | switch_assert(locate_params)((locate_params) ? (void) (0) : __assert_fail ("locate_params" , "mod_voicemail.c", 3397, __PRETTY_FUNCTION__)); | ||||||
3398 | switch_event_add_header_string(locate_params, SWITCH_STACK_BOTTOM, "action", "voicemail-lookup"); | ||||||
3399 | |||||||
3400 | if (switch_xml_locate_user_merged("id:number-alias", id, domain_name, switch_channel_get_variable(channel, "network_addr")switch_channel_get_variable_dup(channel, "network_addr", SWITCH_TRUE , -1), | ||||||
3401 | &x_user, locate_params) == SWITCH_STATUS_SUCCESS) { | ||||||
3402 | id = switch_core_session_strdup(session, switch_xml_attr(x_user, "id"))switch_core_perform_session_strdup(session, switch_xml_attr(x_user , "id"), "mod_voicemail.c", (const char *)__func__, 3402); | ||||||
3403 | |||||||
3404 | if ((x_params = switch_xml_child(x_user, "params"))) { | ||||||
3405 | for (x_param = switch_xml_child(x_params, "param"); x_param; x_param = x_param->next) { | ||||||
3406 | const char *var = switch_xml_attr_soft(x_param, "name"); | ||||||
3407 | const char *val = switch_xml_attr_soft(x_param, "value"); | ||||||
3408 | |||||||
3409 | if (!strcasecmp(var, "vm-mailto")) { | ||||||
3410 | vm_email = switch_core_session_strdup(session, val)switch_core_perform_session_strdup(session, val, "mod_voicemail.c" , (const char *)__func__, 3410); | ||||||
3411 | } else if (!strcasecmp(var, "vm-notify-mailto")) { | ||||||
3412 | vm_notify_email = switch_core_session_strdup(session, val)switch_core_perform_session_strdup(session, val, "mod_voicemail.c" , (const char *)__func__, 3412); | ||||||
3413 | } else if (!strcasecmp(var, "vm-skip-instructions")) { | ||||||
3414 | skip_instructions = switch_true(val); | ||||||
3415 | } else if (!strcasecmp(var, "email-addr")) { | ||||||
3416 | email_addr = switch_core_session_strdup(session, val)switch_core_perform_session_strdup(session, val, "mod_voicemail.c" , (const char *)__func__, 3416); | ||||||
3417 | } else if (!strcasecmp(var, "vm-storage-dir")) { | ||||||
3418 | vm_storage_dir = switch_core_session_strdup(session, val)switch_core_perform_session_strdup(session, val, "mod_voicemail.c" , (const char *)__func__, 3418); | ||||||
3419 | } else if (!strcasecmp(var, "vm-domain-storage-dir")) { | ||||||
3420 | storage_dir = switch_core_session_strdup(session, val)switch_core_perform_session_strdup(session, val, "mod_voicemail.c" , (const char *)__func__, 3420); | ||||||
3421 | } else if (!strcasecmp(var, "storage-dir")) { | ||||||
3422 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "mod_voicemail.c", (const char *)__func__ , 3422, (const char*)(session), SWITCH_LOG_WARNING, | ||||||
3423 | "Using deprecated 'storage-dir' directory variable: Please use 'vm-domain-storage-dir'.\n"); | ||||||
3424 | storage_dir = switch_core_session_strdup(session, val)switch_core_perform_session_strdup(session, val, "mod_voicemail.c" , (const char *)__func__, 3424); | ||||||
3425 | } else if (!strcasecmp(var, "vm-disk-quota")) { | ||||||
3426 | disk_quota = atoi(val); | ||||||
3427 | } else if (!strcasecmp(var, "vm-alternate-greet-id")) { | ||||||
3428 | read_id = switch_core_session_strdup(session, val)switch_core_perform_session_strdup(session, val, "mod_voicemail.c" , (const char *)__func__, 3428); | ||||||
3429 | } else if (!strcasecmp(var, "vm-enabled")) { | ||||||
3430 | vm_enabled = !switch_false(val); | ||||||
3431 | } else if (!strcasecmp(var, "vm-message-ext")) { | ||||||
3432 | vm_ext = switch_core_session_strdup(session, val)switch_core_perform_session_strdup(session, val, "mod_voicemail.c" , (const char *)__func__, 3432); | ||||||
3433 | } else if (!strcasecmp(var, "vm-operator-extension") && (zstr(operator_ext)_zstr(operator_ext))) { | ||||||
3434 | operator_ext = switch_core_session_strdup(session, val)switch_core_perform_session_strdup(session, val, "mod_voicemail.c" , (const char *)__func__, 3434); | ||||||
3435 | } | ||||||
3436 | } | ||||||
3437 | } | ||||||
3438 | |||||||
3439 | if (!vm_enabled) { | ||||||
3440 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "mod_voicemail.c", (const char *)__func__ , 3440, (const char*)(session), SWITCH_LOG_WARNING, "User [%s@%s] have voicemail disabled\n", id, domain_name); | ||||||
3441 | ok = 0; | ||||||
3442 | } | ||||||
3443 | |||||||
3444 | if (send_main && zstr(vm_email)_zstr(vm_email) && !zstr(email_addr)_zstr(email_addr)) { | ||||||
3445 | vm_email = switch_core_session_strdup(session, email_addr)switch_core_perform_session_strdup(session, email_addr, "mod_voicemail.c" , (const char *)__func__, 3445); | ||||||
3446 | if (zstr(vm_email)_zstr(vm_email)) { | ||||||
3447 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "mod_voicemail.c", (const char *)__func__ , 3447, (const char*)(session), SWITCH_LOG_WARNING, "No email address, not going to send email.\n"); | ||||||
3448 | send_main = 0; | ||||||
3449 | } | ||||||
3450 | } | ||||||
3451 | |||||||
3452 | if (send_notify && zstr(vm_notify_email)_zstr(vm_notify_email)) { | ||||||
3453 | vm_notify_email = vm_email; | ||||||
3454 | if (zstr(vm_notify_email)_zstr(vm_notify_email)) { | ||||||
3455 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "mod_voicemail.c", (const char *)__func__ , 3455, (const char*)(session), SWITCH_LOG_WARNING, "No notify email address, not going to notify.\n"); | ||||||
3456 | send_notify = 0; | ||||||
3457 | } | ||||||
3458 | } | ||||||
3459 | |||||||
3460 | } else { | ||||||
3461 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "mod_voicemail.c", (const char *)__func__ , 3461, (const char*)(session), SWITCH_LOG_WARNING, "Can't find user [%s@%s]\n", id, domain_name); | ||||||
3462 | ok = 0; | ||||||
3463 | } | ||||||
3464 | |||||||
3465 | switch_event_destroy(&locate_params); | ||||||
3466 | |||||||
3467 | if (!ok) { | ||||||
3468 | goto end; | ||||||
3469 | } | ||||||
3470 | } | ||||||
3471 | |||||||
3472 | if (!zstr(vm_storage_dir)_zstr(vm_storage_dir)) { | ||||||
3473 | /* check for absolute or relative path */ | ||||||
3474 | if (switch_is_file_path(vm_storage_dir)) { | ||||||
3475 | dir_path = switch_core_session_strdup(session, vm_storage_dir)switch_core_perform_session_strdup(session, vm_storage_dir, "mod_voicemail.c" , (const char *)__func__, 3475); | ||||||
3476 | } else { | ||||||
3477 | dir_path = switch_core_session_sprintf(session, "%s%svoicemail%s%s", SWITCH_GLOBAL_dirs.storage_dir, | ||||||
3478 | SWITCH_PATH_SEPARATOR"/", SWITCH_PATH_SEPARATOR"/", vm_storage_dir); | ||||||
3479 | } | ||||||
3480 | } else if (!zstr(storage_dir)_zstr(storage_dir)) { | ||||||
3481 | dir_path = switch_core_session_sprintf(session, "%s%s%s", storage_dir, SWITCH_PATH_SEPARATOR"/", id); | ||||||
3482 | } else if (!zstr(profile->storage_dir)_zstr(profile->storage_dir)) { | ||||||
3483 | if (profile->storage_dir_shared) { | ||||||
3484 | dir_path = switch_core_session_sprintf(session, "%s%s%s%s%s%s%s", profile->storage_dir, SWITCH_PATH_SEPARATOR"/", domain_name, SWITCH_PATH_SEPARATOR"/", "voicemail", SWITCH_PATH_SEPARATOR"/", id); | ||||||
3485 | } else { | ||||||
3486 | dir_path = switch_core_session_sprintf(session, "%s%s%s%s%s", profile->storage_dir, SWITCH_PATH_SEPARATOR"/", domain_name, SWITCH_PATH_SEPARATOR"/", id); | ||||||
3487 | } | ||||||
3488 | } else { | ||||||
3489 | dir_path = switch_core_session_sprintf(session, "%s%svoicemail%s%s%s%s%s%s", SWITCH_GLOBAL_dirs.storage_dir, | ||||||
3490 | SWITCH_PATH_SEPARATOR"/", | ||||||
3491 | SWITCH_PATH_SEPARATOR"/", profile->name, SWITCH_PATH_SEPARATOR"/", domain_name, SWITCH_PATH_SEPARATOR"/", id); | ||||||
3492 | } | ||||||
3493 | |||||||
3494 | if (switch_dir_make_recursive(dir_path, SWITCH_DEFAULT_DIR_PERMS0x0400 | 0x0200 | 0x0100 | 0x0040 | 0x0010, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) { | ||||||
3495 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "mod_voicemail.c", (const char *)__func__ , 3495, (const char*)(session), SWITCH_LOG_ERROR, "Error creating %s\n", dir_path); | ||||||
3496 | goto end; | ||||||
3497 | } | ||||||
3498 | |||||||
3499 | switch_snprintfv(sql, sizeof(sql), "select * from voicemail_prefs where username='%q' and domain='%q'", id, domain_name); | ||||||
3500 | vm_execute_sql_callback(profile, profile->mutex, sql, prefs_callback, &cbt); | ||||||
3501 | |||||||
3502 | if (!vm_ext) { | ||||||
3503 | vm_ext = profile->file_ext; | ||||||
3504 | } | ||||||
3505 | if ((vtmp = switch_channel_get_variable(channel, "vm_message_ext")switch_channel_get_variable_dup(channel, "vm_message_ext", SWITCH_TRUE , -1))) { | ||||||
3506 | vm_ext = vtmp; | ||||||
3507 | } | ||||||
3508 | |||||||
3509 | switch_uuid_get(&tmp_uuid); | ||||||
3510 | switch_uuid_format(tmp_uuid_str, &tmp_uuid); | ||||||
3511 | |||||||
3512 | file_path = switch_mprintf("%s%smsg_%s.%s", dir_path, SWITCH_PATH_SEPARATOR"/", tmp_uuid_str, vm_ext); | ||||||
3513 | |||||||
3514 | if ((voicemail_greeting_number = switch_channel_get_variable(channel, "voicemail_greeting_number")switch_channel_get_variable_dup(channel, "voicemail_greeting_number" , SWITCH_TRUE, -1))) { | ||||||
3515 | int num = atoi(voicemail_greeting_number); | ||||||
3516 | if (num > 0 && num <= VM_MAX_GREETINGS9) { | ||||||
3517 | greet_path = switch_mprintf("%s%sgreeting_%d.%s", dir_path, SWITCH_PATH_SEPARATOR"/", num, profile->file_ext); | ||||||
3518 | } | ||||||
3519 | } else if (!(greet_path = (char *) switch_channel_get_variable(channel, "voicemail_greeting_path")switch_channel_get_variable_dup(channel, "voicemail_greeting_path" , SWITCH_TRUE, -1))) { | ||||||
3520 | greet_path = cbt.greeting_path; | ||||||
3521 | } | ||||||
3522 | |||||||
3523 | greet: | ||||||
3524 | if (!skip_greeting) { | ||||||
3525 | memset(buf, 0, sizeof(buf)); | ||||||
3526 | args.input_callback = cancel_on_dtmf; | ||||||
3527 | args.buf = buf; | ||||||
3528 | args.buflen = sizeof(buf); | ||||||
3529 | |||||||
3530 | switch_ivr_sleep(session, 100, SWITCH_TRUE, NULL((void*)0)); | ||||||
3531 | |||||||
3532 | if (switch_file_exists(greet_path, switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) { | ||||||
3533 | memset(buf, 0, sizeof(buf)); | ||||||
3534 | TRY_CODE(switch_ivr_play_file(session, NULL, greet_path, &args))do { status = switch_ivr_play_file(session, ((void*)0), greet_path , &args); if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) { goto end; } break;} while(status); | ||||||
3535 | } else { | ||||||
3536 | if (switch_file_exists(cbt.name_path, switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) { | ||||||
3537 | memset(buf, 0, sizeof(buf)); | ||||||
3538 | TRY_CODE(switch_ivr_play_file(session, NULL, cbt.name_path, &args))do { status = switch_ivr_play_file(session, ((void*)0), cbt.name_path , &args); if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) { goto end; } break;} while(status); | ||||||
3539 | } | ||||||
3540 | if (*buf == '\0') { | ||||||
3541 | if (!read_id) { | ||||||
3542 | if (!(read_id = switch_channel_get_variable(channel, "voicemail_alternate_greet_id")switch_channel_get_variable_dup(channel, "voicemail_alternate_greet_id" , SWITCH_TRUE, -1))) { | ||||||
3543 | read_id = id; | ||||||
3544 | } | ||||||
3545 | } | ||||||
3546 | memset(buf, 0, sizeof(buf)); | ||||||
3547 | TRY_CODE(switch_ivr_phrase_macro(session, VM_PLAY_GREETING_MACRO, read_id, NULL, &args))do { status = switch_ivr_phrase_macro_event(session, "voicemail_play_greeting" , read_id, ((void*)0), ((void*)0), &args); if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) { goto end; } break ;} while(status); | ||||||
3548 | } | ||||||
3549 | } | ||||||
3550 | |||||||
3551 | if (*buf != '\0') { | ||||||
3552 | greet_key_press: | ||||||
3553 | if (switch_stristr(buf, profile->login_keys)) { | ||||||
3554 | voicemail_check_main(session, profile, domain_name, id, 0, NULL((void*)0)); | ||||||
3555 | } else if ((!zstr(profile->operator_ext)_zstr(profile->operator_ext) || !zstr(operator_ext)_zstr(operator_ext)) && !zstr(profile->operator_key)_zstr(profile->operator_key) && !strcasecmp(buf, profile->operator_key) ) { | ||||||
3556 | int argc; | ||||||
3557 | char *argv[4]; | ||||||
3558 | char *mycmd; | ||||||
3559 | |||||||
3560 | if ((!zstr(operator_ext)_zstr(operator_ext) && (mycmd = switch_core_session_strdup(session, operator_ext)switch_core_perform_session_strdup(session, operator_ext, "mod_voicemail.c" , (const char *)__func__, 3560))) || | ||||||
3561 | (!zstr(profile->operator_ext)_zstr(profile->operator_ext) && (mycmd = switch_core_session_strdup(session, profile->operator_ext)switch_core_perform_session_strdup(session, profile->operator_ext , "mod_voicemail.c", (const char *)__func__, 3561)))) { | ||||||
3562 | argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | ||||||
3563 | if (argc >= 1 && argc <= 4) { | ||||||
3564 | switch_ivr_session_transfer(session, argv[0], argv[1], argv[2]); | ||||||
3565 | /* the application still runs after we leave it so we need to make sure that we don't do anything evil */ | ||||||
3566 | goto end; | ||||||
3567 | } | ||||||
3568 | } | ||||||
3569 | } else if (!strcasecmp(buf, profile->vmain_key) && !zstr(profile->vmain_key)_zstr(profile->vmain_key)) { | ||||||
3570 | int argc; | ||||||
3571 | char *argv[4]; | ||||||
3572 | char *mycmd; | ||||||
3573 | |||||||
3574 | if (!zstr(profile->vmain_ext)_zstr(profile->vmain_ext) && (mycmd = switch_core_session_strdup(session, profile->vmain_ext)switch_core_perform_session_strdup(session, profile->vmain_ext , "mod_voicemail.c", (const char *)__func__, 3574))) { | ||||||
3575 | argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | ||||||
3576 | if (argc >= 1 && argc <= 4) { | ||||||
3577 | switch_ivr_session_transfer(session, argv[0], argv[1], argv[2]); | ||||||
3578 | /* the application still runs after we leave it so we need to make sure that we don't do anything evil */ | ||||||
3579 | goto end; | ||||||
3580 | } | ||||||
3581 | } | ||||||
3582 | } else if (*profile->skip_greet_key && !strcasecmp(buf, profile->skip_greet_key)) { | ||||||
3583 | skip_instructions = SWITCH_TRUE; | ||||||
3584 | } else { | ||||||
3585 | goto greet; | ||||||
3586 | } | ||||||
3587 | } | ||||||
3588 | } | ||||||
3589 | |||||||
3590 | if (skip_instructions) { | ||||||
3591 | record_macro = NULL((void*)0); | ||||||
3592 | } | ||||||
3593 | |||||||
3594 | if (disk_quota) { | ||||||
3595 | callback_t callback = { 0 }; | ||||||
3596 | char sqlstmt[256]; | ||||||
3597 | char disk_usage[256] = ""; | ||||||
3598 | |||||||
3599 | callback.buf = disk_usage; | ||||||
3600 | callback.len = sizeof(disk_usage); | ||||||
3601 | |||||||
3602 | switch_snprintfv(sqlstmt, sizeof(sqlstmt), "select sum(message_len) from voicemail_msgs where username='%q' and domain='%q'", id, domain_name); | ||||||
3603 | vm_execute_sql_callback(profile, profile->mutex, sqlstmt, sql2str_callback, &callback); | ||||||
3604 | |||||||
3605 | if (atoi(disk_usage) >= disk_quota) { | ||||||
3606 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "mod_voicemail.c", (const char *)__func__ , 3606, (const char*)(session), SWITCH_LOG_NOTICE, "Voicemail disk quota is exceeded for %s\n", id); | ||||||
3607 | TRY_CODE(switch_ivr_phrase_macro(session, VM_DISK_QUOTA_EXCEEDED_MACRO, NULL, NULL, NULL))do { status = switch_ivr_phrase_macro_event(session, "voicemail_disk_quota_exceeded" , ((void*)0), ((void*)0), ((void*)0), ((void*)0)); if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK ) { goto end; } break;} while(status); | ||||||
3608 | goto end; | ||||||
3609 | } | ||||||
3610 | } | ||||||
3611 | |||||||
3612 | |||||||
3613 | memset(&fh, 0, sizeof(fh)); | ||||||
3614 | args.input_callback = control_playback; | ||||||
3615 | memset(&cc, 0, sizeof(cc)); | ||||||
3616 | cc.profile = profile; | ||||||
3617 | cc.fh = &fh; | ||||||
3618 | cc.noexit = 1; | ||||||
3619 | args.buf = &cc; | ||||||
3620 | |||||||
3621 | if (!(caller_id_name = switch_channel_get_variable(channel, "effective_caller_id_name")switch_channel_get_variable_dup(channel, "effective_caller_id_name" , SWITCH_TRUE, -1))) { | ||||||
3622 | caller_id_name = caller_profile->caller_id_name; | ||||||
3623 | } | ||||||
3624 | |||||||
3625 | if (!(caller_id_number = switch_channel_get_variable(channel, "effective_caller_id_number")switch_channel_get_variable_dup(channel, "effective_caller_id_number" , SWITCH_TRUE, -1))) { | ||||||
3626 | caller_id_number = caller_profile->caller_id_number; | ||||||
3627 | } | ||||||
3628 | |||||||
3629 | switch_channel_set_variable_printf(channel, "RECORD_ARTIST", "%s (%s)", caller_id_name, caller_id_number); | ||||||
3630 | |||||||
3631 | switch_time_exp_lt(&tm, ts); | ||||||
3632 | switch_strftime_nocheck(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm); | ||||||
3633 | switch_channel_set_variable(channel, "RECORD_DATE", date)switch_channel_set_variable_var_check(channel, "RECORD_DATE", date, SWITCH_TRUE); | ||||||
3634 | switch_channel_set_variable(channel, "RECORD_SOFTWARE", "FreeSWITCH")switch_channel_set_variable_var_check(channel, "RECORD_SOFTWARE" , "FreeSWITCH", SWITCH_TRUE); | ||||||
3635 | switch_channel_set_variable(channel, "RECORD_TITLE", profile->record_title)switch_channel_set_variable_var_check(channel, "RECORD_TITLE" , profile->record_title, SWITCH_TRUE); | ||||||
3636 | switch_channel_set_variable(channel, "RECORD_COMMENT", profile->record_comment)switch_channel_set_variable_var_check(channel, "RECORD_COMMENT" , profile->record_comment, SWITCH_TRUE); | ||||||
3637 | switch_channel_set_variable(channel, "RECORD_COPYRIGHT", profile->record_copyright)switch_channel_set_variable_var_check(channel, "RECORD_COPYRIGHT" , profile->record_copyright, SWITCH_TRUE); | ||||||
3638 | |||||||
3639 | switch_snprintf(key_buf, sizeof(key_buf), "%s:%s", profile->operator_key, profile->vmain_key); | ||||||
3640 | memset(buf, 0, sizeof(buf)); | ||||||
3641 | |||||||
3642 | status = create_file(session, profile, record_macro, file_path, &message_len, SWITCH_TRUE, key_buf, buf); | ||||||
3643 | |||||||
3644 | if (status == SWITCH_STATUS_NOTFOUND) { | ||||||
3645 | goto end; | ||||||
3646 | } | ||||||
3647 | |||||||
3648 | if (buf[0]) { | ||||||
3649 | goto greet_key_press; | ||||||
3650 | } | ||||||
3651 | |||||||
3652 | if ((status == SWITCH_STATUS_SUCCESS || status == SWITCH_STATUS_BREAK) && switch_channel_ready(channel)switch_channel_test_ready(channel, SWITCH_TRUE, SWITCH_FALSE)) { | ||||||
3653 | char input[10] = "", term = 0; | ||||||
3654 | |||||||
3655 | switch_snprintf(key_buf, sizeof(key_buf), "%s:%s", profile->urgent_key, profile->terminator_key); | ||||||
3656 | if (!skip_record_urgent_check) { | ||||||
3657 | (void) vm_macro_get(session, VM_RECORD_URGENT_CHECK_MACRO"voicemail_record_urgent_check", key_buf, input, sizeof(input), 1, "", &term, profile->digit_timeout); | ||||||
3658 | if (!switch_channel_ready(channel)switch_channel_test_ready(channel, SWITCH_TRUE, SWITCH_FALSE)) goto deliver; | ||||||
3659 | if (*profile->urgent_key == *input) { | ||||||
3660 | read_flags = URGENT_FLAG_STRING"A_URGENT"; | ||||||
3661 | (void) switch_ivr_phrase_macro(session, VM_ACK_MACRO, "marked-urgent", NULL, NULL)switch_ivr_phrase_macro_event(session, "voicemail_ack", "marked-urgent" , ((void*)0), ((void*)0), ((void*)0)); | ||||||
3662 | } else { | ||||||
3663 | (void) switch_ivr_phrase_macro(session, VM_ACK_MACRO, "saved", NULL, NULL)switch_ivr_phrase_macro_event(session, "voicemail_ack", "saved" , ((void*)0), ((void*)0), ((void*)0)); | ||||||
3664 | } | ||||||
3665 | } | ||||||
3666 | } | ||||||
3667 | |||||||
3668 | deliver: | ||||||
3669 | if (x_user) { | ||||||
3670 | switch_channel_get_variables(channel, &vars); | ||||||
3671 | status = deliver_vm(profile, x_user, domain_name, file_path, (uint32_t)message_len, read_flags, vars, | ||||||
3672 | switch_core_session_get_pool(session), caller_id_name, caller_id_number, NULL((void*)0), SWITCH_FALSE, | ||||||
3673 | switch_core_session_get_uuid(session), session); | ||||||
3674 | switch_event_destroy(&vars); | ||||||
3675 | if (status == SWITCH_STATUS_SUCCESS) { | ||||||
3676 | switch_core_time_duration_t duration; | ||||||
3677 | char duration_str[80]; | ||||||
3678 | switch_time_t l_duration = switch_time_make(message_len, 0); | ||||||
3679 | |||||||
3680 | switch_core_measure_time(l_duration, &duration); | ||||||
3681 | duration.day += duration.yr * 365; | ||||||
3682 | duration.hr += duration.day * 24; | ||||||
3683 | |||||||
3684 | switch_snprintf(duration_str, sizeof(duration_str), "%.2u:%.2u:%.2u", duration.hr, duration.min, duration.sec); | ||||||
3685 | |||||||
3686 | switch_channel_set_variable(channel, "voicemail_account", id)switch_channel_set_variable_var_check(channel, "voicemail_account" , id, SWITCH_TRUE); | ||||||
3687 | switch_channel_set_variable(channel, "voicemail_domain", domain_name)switch_channel_set_variable_var_check(channel, "voicemail_domain" , domain_name, SWITCH_TRUE); | ||||||
3688 | switch_channel_set_variable(channel, "voicemail_file_path", file_path)switch_channel_set_variable_var_check(channel, "voicemail_file_path" , file_path, SWITCH_TRUE); | ||||||
3689 | switch_channel_set_variable(channel, "voicemail_read_flags", read_flags)switch_channel_set_variable_var_check(channel, "voicemail_read_flags" , read_flags, SWITCH_TRUE); | ||||||
3690 | switch_channel_set_variable(channel, "voicemail_message_len", duration_str)switch_channel_set_variable_var_check(channel, "voicemail_message_len" , duration_str, SWITCH_TRUE); | ||||||
3691 | } else { | ||||||
3692 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "mod_voicemail.c", (const char *)__func__ , 3692, (const char*)(session), SWITCH_LOG_ERROR, "Failed to deliver message\n"); | ||||||
3693 | TRY_CODE(switch_ivr_phrase_macro(session, VM_ACK_MACRO, "deleted", NULL, NULL))do { status = switch_ivr_phrase_macro_event(session, "voicemail_ack" , "deleted", ((void*)0), ((void*)0), ((void*)0)); if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK ) { goto end; } break;} while(status); | ||||||
3694 | } | ||||||
3695 | |||||||
3696 | } | ||||||
3697 | |||||||
3698 | end: | ||||||
3699 | |||||||
3700 | xml_safe_free(x_user)if (x_user) switch_xml_free(x_user); x_user = ((void*)0); | ||||||
3701 | |||||||
3702 | switch_safe_free(file_path)if (file_path) {free(file_path);file_path=((void*)0);}; | ||||||
3703 | |||||||
3704 | if (switch_channel_ready(channel)switch_channel_test_ready(channel, SWITCH_TRUE, SWITCH_FALSE) && vm_enabled) { | ||||||
3705 | status = switch_ivr_phrase_macro(session, VM_GOODBYE_MACRO, NULL, NULL, NULL)switch_ivr_phrase_macro_event(session, "voicemail_goodbye", ( (void*)0), ((void*)0), ((void*)0), ((void*)0)); | ||||||
3706 | } | ||||||
3707 | |||||||
3708 | return status; | ||||||
3709 | } | ||||||
3710 | |||||||
3711 | |||||||
3712 | #define VM_DESC"voicemail" "voicemail" | ||||||
3713 | #define VM_USAGE"[check] [auth] <profile_name> <domain_name> [<id>] [uuid]" "[check] [auth] <profile_name> <domain_name> [<id>] [uuid]" | ||||||
3714 | |||||||
3715 | SWITCH_STANDARD_APP(voicemail_function)static void voicemail_function (switch_core_session_t *session , const char *data) | ||||||
3716 | { | ||||||
3717 | char *argv[6] = { 0 }; | ||||||
3718 | char *mydata = NULL((void*)0); | ||||||
3719 | vm_profile_t *profile = NULL((void*)0); | ||||||
3720 | const char *profile_name = NULL((void*)0); | ||||||
3721 | const char *domain_name = NULL((void*)0); | ||||||
3722 | const char *id = NULL((void*)0); | ||||||
3723 | const char *auth_var = NULL((void*)0); | ||||||
3724 | const char *uuid = NULL((void*)0); | ||||||
3725 | int x = 0, check = 0, auth = 0; | ||||||
3726 | switch_channel_t *channel = switch_core_session_get_channel(session); | ||||||
3727 | |||||||
3728 | if (!zstr(data)_zstr(data)) { | ||||||
3729 | mydata = switch_core_session_strdup(session, data)switch_core_perform_session_strdup(session, data, "mod_voicemail.c" , (const char *)__func__, 3729); | ||||||
3730 | switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | ||||||
3731 | } | ||||||
3732 | |||||||
3733 | for (;;) { | ||||||
3734 | if (argv[x] && !strcasecmp(argv[x], "check")) { | ||||||
3735 | check++; | ||||||
3736 | x++; | ||||||
3737 | } else if (argv[x] && !strcasecmp(argv[x], "auth_only")) { | ||||||
3738 | auth = 2; | ||||||
3739 | x++; | ||||||
3740 | } else if (argv[x] && !strcasecmp(argv[x], "auth")) { | ||||||
3741 | auth++; | ||||||
3742 | x++; | ||||||
3743 | } else { | ||||||
3744 | break; | ||||||
3745 | } | ||||||
3746 | } | ||||||
3747 | |||||||
3748 | if (argv[x]) { | ||||||
3749 | profile_name = argv[x++]; | ||||||
3750 | } | ||||||
3751 | |||||||
3752 | if (argv[x]) { | ||||||
3753 | domain_name = argv[x++]; | ||||||
3754 | } | ||||||
3755 | |||||||
3756 | if (argv[x]) { | ||||||
3757 | id = argv[x++]; | ||||||
3758 | } | ||||||
3759 | |||||||
3760 | if ((auth_var = switch_channel_get_variable(channel, "voicemail_authorized")switch_channel_get_variable_dup(channel, "voicemail_authorized" , SWITCH_TRUE, -1)) && switch_true(auth_var)) { | ||||||
3761 | auth = 1; | ||||||
3762 | } | ||||||
3763 | |||||||
3764 | if (zstr(profile_name)_zstr(profile_name)) { | ||||||
3765 | profile_name = switch_channel_get_variable(channel, "voicemail_profile_name")switch_channel_get_variable_dup(channel, "voicemail_profile_name" , SWITCH_TRUE, -1); | ||||||
3766 | } | ||||||
3767 | |||||||
3768 | if (zstr(domain_name)_zstr(domain_name)) { | ||||||
3769 | domain_name = switch_channel_get_variable(channel, "voicemail_domain_name")switch_channel_get_variable_dup(channel, "voicemail_domain_name" , SWITCH_TRUE, -1); | ||||||
3770 | } | ||||||
3771 | |||||||
3772 | if (zstr(id)_zstr(id)) { | ||||||
3773 | id = switch_channel_get_variable(channel, "voicemail_id")switch_channel_get_variable_dup(channel, "voicemail_id", SWITCH_TRUE , -1); | ||||||
3774 | } | ||||||
3775 | |||||||
3776 | if (zstr(profile_name)_zstr(profile_name) || zstr(domain_name)_zstr(domain_name)) { | ||||||
3777 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "mod_voicemail.c", (const char *)__func__ , 3777, (const char*)(session), SWITCH_LOG_ERROR, "Error Usage: %s\n", VM_USAGE"[check] [auth] <profile_name> <domain_name> [<id>] [uuid]"); | ||||||
3778 | return; | ||||||
3779 | } | ||||||
3780 | |||||||
3781 | if (!(profile = get_profile(profile_name))) { | ||||||
3782 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "mod_voicemail.c", (const char *)__func__ , 3782, (const char*)(session), SWITCH_LOG_ERROR, "Error invalid profile %s\n", profile_name); | ||||||
3783 | return; | ||||||
3784 | } | ||||||
3785 | |||||||
3786 | if (check || auth == 2) { | ||||||
3787 | if (argv[x]) { | ||||||
3788 | uuid = argv[x++]; | ||||||
3789 | } | ||||||
3790 | voicemail_check_main(session, profile, domain_name, id, auth, uuid); | ||||||
3791 | } else { | ||||||
3792 | voicemail_leave_main(session, profile, domain_name, id); | ||||||
3793 | } | ||||||
3794 | |||||||
3795 | profile_rwunlock(profile); | ||||||
3796 | |||||||
3797 | } | ||||||
3798 | |||||||
3799 | #define BOXCOUNT_SYNTAX"[profile/]<user>@<domain>[|[new|saved|new-urgent|saved-urgent|all]]" "[profile/]<user>@<domain>[|[new|saved|new-urgent|saved-urgent|all]]" | ||||||
3800 | SWITCH_STANDARD_API(boxcount_api_function)static switch_status_t boxcount_api_function ( const char *cmd , switch_core_session_t *session, switch_stream_handle_t *stream ) | ||||||
3801 | { | ||||||
3802 | char *dup; | ||||||
3803 | const char *how = "new"; | ||||||
3804 | int total_new_messages = 0; | ||||||
3805 | int total_saved_messages = 0; | ||||||
3806 | int total_new_urgent_messages = 0; | ||||||
3807 | int total_saved_urgent_messages = 0; | ||||||
3808 | vm_profile_t *profile; | ||||||
3809 | char *id, *domain, *p, *profilename = NULL((void*)0); | ||||||
3810 | |||||||
3811 | if (zstr(cmd)_zstr(cmd)) { | ||||||
3812 | stream->write_function(stream, "%d", 0); | ||||||
3813 | return SWITCH_STATUS_SUCCESS; | ||||||
3814 | } | ||||||
3815 | |||||||
3816 | id = 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))); | ||||||
3817 | |||||||
3818 | if ((p = strchr(dup, '/')(__extension__ (__builtin_constant_p ('/') && !__builtin_constant_p (dup) && ('/') == '\0' ? (char *) __rawmemchr (dup, '/' ) : __builtin_strchr (dup, '/'))))) { | ||||||
3819 | *p++ = '\0'; | ||||||
3820 | id = p; | ||||||
3821 | profilename = dup; | ||||||
3822 | } | ||||||
3823 | |||||||
3824 | if (!strncasecmp(id, "sip:", 4)) { | ||||||
3825 | id += 4; | ||||||
3826 | } | ||||||
3827 | |||||||
3828 | if (zstr(id)_zstr(id)) { | ||||||
3829 | stream->write_function(stream, "%d", 0); | ||||||
3830 | goto done; | ||||||
3831 | } | ||||||
3832 | |||||||
3833 | if ((domain = strchr(id, '@')(__extension__ (__builtin_constant_p ('@') && !__builtin_constant_p (id) && ('@') == '\0' ? (char *) __rawmemchr (id, '@' ) : __builtin_strchr (id, '@'))))) { | ||||||
3834 | *domain++ = '\0'; | ||||||
3835 | if ((p = strchr(domain, '|')(__extension__ (__builtin_constant_p ('|') && !__builtin_constant_p (domain) && ('|') == '\0' ? (char *) __rawmemchr (domain , '|') : __builtin_strchr (domain, '|'))))) { | ||||||
3836 | *p++ = '\0'; | ||||||
3837 | how = p; | ||||||
3838 | } | ||||||
3839 | |||||||
3840 | if (!zstr(profilename)_zstr(profilename)) { | ||||||
3841 | if ((profile = get_profile(profilename))) { | ||||||
3842 | message_count(profile, id, domain, "inbox", &total_new_messages, &total_saved_messages, | ||||||
3843 | &total_new_urgent_messages, &total_saved_urgent_messages); | ||||||
3844 | profile_rwunlock(profile); | ||||||
3845 | } else { | ||||||
3846 | stream->write_function(stream, "-ERR No such profile\n"); | ||||||
3847 | goto done; | ||||||
3848 | } | ||||||
3849 | } else { | ||||||
3850 | /* Kept for backwards-compatibility */ | ||||||
3851 | switch_hash_index_t *hi; | ||||||
3852 | switch_mutex_lock(globals.mutex); | ||||||
3853 | if ((hi = switch_core_hash_first(globals.profile_hash)switch_core_hash_first_iter(globals.profile_hash, ((void*)0)))) { | ||||||
3854 | void *val; | ||||||
3855 | switch_core_hash_this(hi, NULL((void*)0), NULL((void*)0), &val); | ||||||
3856 | profile = (vm_profile_t *) val; | ||||||
3857 | total_new_messages = total_saved_messages = 0; | ||||||
3858 | message_count(profile, id, domain, "inbox", &total_new_messages, &total_saved_messages, | ||||||
3859 | &total_new_urgent_messages, &total_saved_urgent_messages); | ||||||
3860 | } | ||||||
3861 | switch_mutex_unlock(globals.mutex); | ||||||
3862 | } | ||||||
3863 | } | ||||||
3864 | |||||||
3865 | if (!strcasecmp(how, "saved")) { | ||||||
3866 | stream->write_function(stream, "%d", total_saved_messages); | ||||||
3867 | } else if (!strcasecmp(how, "new-urgent")) { | ||||||
3868 | stream->write_function(stream, "%d", total_new_urgent_messages); | ||||||
3869 | } else if (!strcasecmp(how, "new-saved")) { | ||||||
3870 | stream->write_function(stream, "%d", total_saved_urgent_messages); | ||||||
3871 | } else if (!strcasecmp(how, "all")) { | ||||||
3872 | stream->write_function(stream, "%d:%d:%d:%d", total_new_messages, total_saved_messages, total_new_urgent_messages, total_saved_urgent_messages); | ||||||
3873 | } else { | ||||||
3874 | stream->write_function(stream, "%d", total_new_messages); | ||||||
3875 | } | ||||||
3876 | |||||||
3877 | done: | ||||||
3878 | switch_safe_free(dup)if (dup) {free(dup);dup=((void*)0);}; | ||||||
3879 | return SWITCH_STATUS_SUCCESS; | ||||||
3880 | } | ||||||
3881 | |||||||
3882 | #define PREFS_SYNTAX"[profile/]<user>@<domain>[|[name_path|greeting_path|password]]" "[profile/]<user>@<domain>[|[name_path|greeting_path|password]]" | ||||||
3883 | SWITCH_STANDARD_API(prefs_api_function)static switch_status_t prefs_api_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | ||||||
3884 | { | ||||||
3885 | char *dup = NULL((void*)0); | ||||||
3886 | const char *how = "greeting_path"; | ||||||
3887 | vm_profile_t *profile = NULL((void*)0); | ||||||
3888 | char *id, *domain, *p, *profilename = NULL((void*)0); | ||||||
3889 | char sql[256]; | ||||||
3890 | prefs_callback_t cbt = { {0} }; | ||||||
3891 | |||||||
3892 | if (zstr(cmd)_zstr(cmd)) { | ||||||
3893 | stream->write_function(stream, "%d", 0); | ||||||
3894 | goto done; | ||||||
3895 | } | ||||||
3896 | |||||||
3897 | id = 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))); | ||||||
3898 | |||||||
3899 | if ((p = strchr(dup, '/')(__extension__ (__builtin_constant_p ('/') && !__builtin_constant_p (dup) && ('/') == '\0' ? (char *) __rawmemchr (dup, '/' ) : __builtin_strchr (dup, '/'))))) { | ||||||
3900 | *p++ = '\0'; | ||||||
3901 | id = p; | ||||||
3902 | profilename = dup; | ||||||
3903 | } | ||||||
3904 | |||||||
3905 | if (!strncasecmp(id, "sip:", 4)) { | ||||||
3906 | id += 4; | ||||||
3907 | } | ||||||
3908 | |||||||
3909 | if (zstr(id)_zstr(id)) { | ||||||
3910 | stream->write_function(stream, "%d", 0); | ||||||
3911 | goto done; | ||||||
3912 | } | ||||||
3913 | |||||||
3914 | if ((domain = strchr(id, '@')(__extension__ (__builtin_constant_p ('@') && !__builtin_constant_p (id) && ('@') == '\0' ? (char *) __rawmemchr (id, '@' ) : __builtin_strchr (id, '@'))))) { | ||||||
3915 | *domain++ = '\0'; | ||||||
3916 | if ((p = strchr(domain, '|')(__extension__ (__builtin_constant_p ('|') && !__builtin_constant_p (domain) && ('|') == '\0' ? (char *) __rawmemchr (domain , '|') : __builtin_strchr (domain, '|'))))) { | ||||||
3917 | *p++ = '\0'; | ||||||
3918 | how = p; | ||||||
3919 | } | ||||||
3920 | |||||||
3921 | if (!zstr(profilename)_zstr(profilename) && !(profile = get_profile(profilename))) { | ||||||
3922 | stream->write_function(stream, "-ERR No such profile\n"); | ||||||
3923 | goto done; | ||||||
3924 | } | ||||||
3925 | if (!profile && !(profile = get_profile("default"))) { | ||||||
3926 | stream->write_function(stream, "-ERR profile 'default' doesn't exist\n"); | ||||||
3927 | goto done; | ||||||
3928 | } | ||||||
3929 | } else { | ||||||
3930 | stream->write_function(stream, "-ERR No domain specified\n"); | ||||||
3931 | goto done; | ||||||
3932 | |||||||
3933 | } | ||||||
3934 | |||||||
3935 | switch_snprintfv(sql, sizeof(sql), "select * from voicemail_prefs where username='%q' and domain='%q'", id, domain); | ||||||
3936 | vm_execute_sql_callback(profile, profile->mutex, sql, prefs_callback, &cbt); | ||||||
3937 | |||||||
3938 | if (!strcasecmp(how, "greeting_path")) { | ||||||
3939 | stream->write_function(stream, "%s", cbt.greeting_path); | ||||||
3940 | } else if (!strcasecmp(how, "name_path")) { | ||||||
3941 | stream->write_function(stream, "%s", cbt.name_path); | ||||||
3942 | } else if (!strcasecmp(how, "password")) { | ||||||
3943 | stream->write_function(stream, "%s", cbt.password); | ||||||
3944 | } else { | ||||||
3945 | stream->write_function(stream, "%s:%s:%s", cbt.greeting_path, cbt.name_path, cbt.password); | ||||||
3946 | } | ||||||
3947 | profile_rwunlock(profile); | ||||||
3948 | done: | ||||||
3949 | switch_safe_free(dup)if (dup) {free(dup);dup=((void*)0);}; | ||||||
3950 | return SWITCH_STATUS_SUCCESS; | ||||||
3951 | } | ||||||
3952 | |||||||
3953 | #define parse_profile(){ total_new_messages = total_saved_messages = 0; message_count (profile, id, domain, "inbox", &total_new_messages, & total_saved_messages, &total_new_urgent_messages, &total_saved_urgent_messages ); if (total_new_messages || total_saved_messages) { if (switch_event_create_subclass_detailed ("mod_voicemail.c", (const char * )(const char *)__func__, 3953 , &new_event, SWITCH_EVENT_MESSAGE_WAITING, ((void*)0)) == SWITCH_STATUS_SUCCESS) { const char *yn = "no"; if (total_new_messages || total_new_urgent_messages) { yn = "yes"; } switch_event_add_header_string (new_event, SWITCH_STACK_BOTTOM, "MWI-Messages-Waiting", yn); switch_event_add_header_string(new_event, SWITCH_STACK_BOTTOM , "MWI-Message-Account", account); switch_event_add_header(new_event , SWITCH_STACK_BOTTOM, "MWI-Voice-Message", "%d/%d (%d/%d)", + total_new_messages, total_saved_messages, total_new_urgent_messages , total_saved_urgent_messages); } } } {\ | ||||||
3954 | total_new_messages = total_saved_messages = 0; \ | ||||||
3955 | message_count(profile, id, domain, "inbox", &total_new_messages, &total_saved_messages, \ | ||||||
3956 | &total_new_urgent_messages, &total_saved_urgent_messages); \ | ||||||
3957 | if (total_new_messages || total_saved_messages) { \ | ||||||
3958 | if (switch_event_create(&new_event, SWITCH_EVENT_MESSAGE_WAITING)switch_event_create_subclass_detailed("mod_voicemail.c", (const char * )(const char *)__func__, 3958, &new_event, SWITCH_EVENT_MESSAGE_WAITING , ((void*)0)) == SWITCH_STATUS_SUCCESS) { \ | ||||||
3959 | const char *yn = "no"; \ | ||||||
3960 | if (total_new_messages || total_new_urgent_messages) { \ | ||||||
3961 | yn = "yes"; \ | ||||||
3962 | } \ | ||||||
3963 | switch_event_add_header_string(new_event, SWITCH_STACK_BOTTOM, "MWI-Messages-Waiting", yn); \ | ||||||
3964 | switch_event_add_header_string(new_event, SWITCH_STACK_BOTTOM, "MWI-Message-Account", account); \ | ||||||
3965 | switch_event_add_header(new_event, SWITCH_STACK_BOTTOM, "MWI-Voice-Message", "%d/%d (%d/%d)", \ | ||||||
3966 | +total_new_messages, total_saved_messages, total_new_urgent_messages, total_saved_urgent_messages); \ | ||||||
3967 | } \ | ||||||
3968 | } \ | ||||||
3969 | } | ||||||
3970 | |||||||
3971 | |||||||
3972 | static void actual_message_query_handler(switch_event_t *event) | ||||||
3973 | { | ||||||
3974 | char *account = switch_event_get_header(event, "message-account")switch_event_get_header_idx(event, "message-account", -1); | ||||||
3975 | switch_event_t *new_event = NULL((void*)0); | ||||||
3976 | char *dup = NULL((void*)0); | ||||||
3977 | int total_new_messages = 0; | ||||||
3978 | int total_saved_messages = 0; | ||||||
3979 | int total_new_urgent_messages = 0; | ||||||
3980 | int total_saved_urgent_messages = 0; | ||||||
3981 | |||||||
3982 | if (account) { | ||||||
3983 | switch_hash_index_t *hi; | ||||||
3984 | void *val; | ||||||
3985 | vm_profile_t *profile; | ||||||
3986 | char *id, *domain; | ||||||
3987 | |||||||
3988 | dup = strdup(account)(__extension__ (__builtin_constant_p (account) && ((size_t )(const void *)((account) + 1) - (size_t)(const void *)(account ) == 1) ? (((const char *) (account))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen (account ) + 1; char *__retval = (char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, account , __len); __retval; })) : __strdup (account))); | ||||||
3989 | |||||||
3990 | switch_split_user_domain(dup, &id, &domain); | ||||||
3991 | |||||||
3992 | if (!id || !domain) { | ||||||
3993 | free(dup); | ||||||
3994 | return; | ||||||
3995 | } | ||||||
3996 | |||||||
3997 | profile = NULL((void*)0); | ||||||
3998 | |||||||
3999 | if (globals.message_query_exact_match) { | ||||||
4000 | if ((profile = (vm_profile_t *) switch_core_hash_find(globals.profile_hash, domain))) { | ||||||
4001 | parse_profile(){ total_new_messages = total_saved_messages = 0; message_count (profile, id, domain, "inbox", &total_new_messages, & total_saved_messages, &total_new_urgent_messages, &total_saved_urgent_messages ); if (total_new_messages || total_saved_messages) { if (switch_event_create_subclass_detailed ("mod_voicemail.c", (const char * )(const char *)__func__, 4001 , &new_event, SWITCH_EVENT_MESSAGE_WAITING, ((void*)0)) == SWITCH_STATUS_SUCCESS) { const char *yn = "no"; if (total_new_messages || total_new_urgent_messages) { yn = "yes"; } switch_event_add_header_string (new_event, SWITCH_STACK_BOTTOM, "MWI-Messages-Waiting", yn); switch_event_add_header_string(new_event, SWITCH_STACK_BOTTOM , "MWI-Message-Account", account); switch_event_add_header(new_event , SWITCH_STACK_BOTTOM, "MWI-Voice-Message", "%d/%d (%d/%d)", + total_new_messages, total_saved_messages, total_new_urgent_messages , total_saved_urgent_messages); } } }; | ||||||
4002 | } else { | ||||||
4003 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 4003, ((void*)0), SWITCH_LOG_WARNING, | ||||||
4004 | "Cound not find a profile for domain: [%s] Returning 0 messages\nWhen message-query-exact-match is enabled you must have a dedicated vm profile per distinct domain name you wish to use.\n", domain); | ||||||
4005 | } | ||||||
4006 | } else { | ||||||
4007 | for (hi = switch_core_hash_first(globals.profile_hash)switch_core_hash_first_iter(globals.profile_hash, ((void*)0)); hi; hi = switch_core_hash_next(&hi)) { | ||||||
4008 | switch_core_hash_this(hi, NULL((void*)0), NULL((void*)0), &val); | ||||||
4009 | profile = (vm_profile_t *) val; | ||||||
4010 | parse_profile(){ total_new_messages = total_saved_messages = 0; message_count (profile, id, domain, "inbox", &total_new_messages, & total_saved_messages, &total_new_urgent_messages, &total_saved_urgent_messages ); if (total_new_messages || total_saved_messages) { if (switch_event_create_subclass_detailed ("mod_voicemail.c", (const char * )(const char *)__func__, 4010 , &new_event, SWITCH_EVENT_MESSAGE_WAITING, ((void*)0)) == SWITCH_STATUS_SUCCESS) { const char *yn = "no"; if (total_new_messages || total_new_urgent_messages) { yn = "yes"; } switch_event_add_header_string (new_event, SWITCH_STACK_BOTTOM, "MWI-Messages-Waiting", yn); switch_event_add_header_string(new_event, SWITCH_STACK_BOTTOM , "MWI-Message-Account", account); switch_event_add_header(new_event , SWITCH_STACK_BOTTOM, "MWI-Voice-Message", "%d/%d (%d/%d)", + total_new_messages, total_saved_messages, total_new_urgent_messages , total_saved_urgent_messages); } } }; | ||||||
4011 | |||||||
4012 | if (new_event) { | ||||||
4013 | break; | ||||||
4014 | } | ||||||
4015 | } | ||||||
4016 | switch_safe_free(hi)if (hi) {free(hi);hi=((void*)0);}; | ||||||
4017 | } | ||||||
4018 | |||||||
4019 | switch_safe_free(dup)if (dup) {free(dup);dup=((void*)0);}; | ||||||
4020 | |||||||
4021 | } | ||||||
4022 | |||||||
4023 | if (!new_event) { | ||||||
4024 | if (switch_event_create(&new_event, SWITCH_EVENT_MESSAGE_WAITING)switch_event_create_subclass_detailed("mod_voicemail.c", (const char * )(const char *)__func__, 4024, &new_event, SWITCH_EVENT_MESSAGE_WAITING , ((void*)0)) == SWITCH_STATUS_SUCCESS) { | ||||||
4025 | switch_event_add_header_string(new_event, SWITCH_STACK_BOTTOM, "MWI-Messages-Waiting", "no"); | ||||||
4026 | switch_event_add_header_string(new_event, SWITCH_STACK_BOTTOM, "MWI-Message-Account", account); | ||||||
4027 | } | ||||||
4028 | } | ||||||
4029 | |||||||
4030 | if (new_event) { | ||||||
4031 | switch_event_header_t *hp; | ||||||
4032 | |||||||
4033 | for (hp = event->headers; hp; hp = hp->next) { | ||||||
4034 | if (!strncasecmp(hp->name, "vm-", 3)) { | ||||||
4035 | switch_event_add_header_string(new_event, SWITCH_STACK_BOTTOM, hp->name + 3, hp->value); | ||||||
4036 | } | ||||||
4037 | } | ||||||
4038 | |||||||
4039 | switch_event_fire(&new_event)switch_event_fire_detailed("mod_voicemail.c", (const char * ) (const char *)__func__, 4039, &new_event, ((void*)0)); | ||||||
4040 | } | ||||||
4041 | |||||||
4042 | |||||||
4043 | } | ||||||
4044 | |||||||
4045 | static int EVENT_THREAD_RUNNING = 0; | ||||||
4046 | static int EVENT_THREAD_STARTED = 0; | ||||||
4047 | |||||||
4048 | void *SWITCH_THREAD_FUNC vm_event_thread_run(switch_thread_t *thread, void *obj) | ||||||
4049 | { | ||||||
4050 | void *pop; | ||||||
4051 | int done = 0; | ||||||
4052 | |||||||
4053 | switch_mutex_lock(globals.mutex); | ||||||
4054 | if (!EVENT_THREAD_RUNNING) { | ||||||
4055 | EVENT_THREAD_RUNNING++; | ||||||
4056 | globals.threads++; | ||||||
4057 | } else { | ||||||
4058 | done = 1; | ||||||
4059 | } | ||||||
4060 | switch_mutex_unlock(globals.mutex); | ||||||
4061 | |||||||
4062 | if (done) { | ||||||
4063 | return NULL((void*)0); | ||||||
4064 | } | ||||||
4065 | |||||||
4066 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 4066, ((void*)0), SWITCH_LOG_CONSOLE, "Event Thread Started\n"); | ||||||
4067 | |||||||
4068 | while (globals.running == 1) { | ||||||
4069 | int count = 0; | ||||||
4070 | |||||||
4071 | if (switch_queue_trypop(globals.event_queue, &pop) == SWITCH_STATUS_SUCCESS) { | ||||||
4072 | switch_event_t *event = (switch_event_t *) pop; | ||||||
4073 | |||||||
4074 | if (!pop) { | ||||||
4075 | break; | ||||||
4076 | } | ||||||
4077 | actual_message_query_handler(event); | ||||||
4078 | switch_event_destroy(&event); | ||||||
4079 | count++; | ||||||
4080 | } | ||||||
4081 | |||||||
4082 | if (!count) { | ||||||
4083 | switch_yield(100000)switch_sleep(100000);; | ||||||
4084 | } | ||||||
4085 | } | ||||||
4086 | |||||||
4087 | while (switch_queue_trypop(globals.event_queue, &pop) == SWITCH_STATUS_SUCCESS && pop) { | ||||||
4088 | switch_event_t *event = (switch_event_t *) pop; | ||||||
4089 | switch_event_destroy(&event); | ||||||
4090 | } | ||||||
4091 | |||||||
4092 | |||||||
4093 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 4093, ((void*)0), SWITCH_LOG_CONSOLE, "Event Thread Ended\n"); | ||||||
4094 | |||||||
4095 | switch_mutex_lock(globals.mutex); | ||||||
4096 | globals.threads--; | ||||||
4097 | EVENT_THREAD_RUNNING = EVENT_THREAD_STARTED = 0; | ||||||
4098 | switch_mutex_unlock(globals.mutex); | ||||||
4099 | |||||||
4100 | return NULL((void*)0); | ||||||
4101 | } | ||||||
4102 | |||||||
4103 | void vm_event_thread_start(void) | ||||||
4104 | { | ||||||
4105 | switch_thread_t *thread; | ||||||
4106 | switch_threadattr_t *thd_attr = NULL((void*)0); | ||||||
4107 | int done = 0; | ||||||
4108 | |||||||
4109 | switch_mutex_lock(globals.mutex); | ||||||
4110 | if (!EVENT_THREAD_STARTED) { | ||||||
4111 | EVENT_THREAD_STARTED++; | ||||||
4112 | } else { | ||||||
4113 | done = 1; | ||||||
4114 | } | ||||||
4115 | switch_mutex_unlock(globals.mutex); | ||||||
4116 | |||||||
4117 | if (done) { | ||||||
4118 | return; | ||||||
4119 | } | ||||||
4120 | |||||||
4121 | switch_threadattr_create(&thd_attr, globals.pool); | ||||||
4122 | switch_threadattr_detach_set(thd_attr, 1); | ||||||
4123 | switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE240 * 1024); | ||||||
4124 | switch_threadattr_priority_set(thd_attr, SWITCH_PRI_IMPORTANT); | ||||||
4125 | switch_thread_create(&thread, thd_attr, vm_event_thread_run, NULL((void*)0), globals.pool); | ||||||
4126 | } | ||||||
4127 | |||||||
4128 | void vm_event_handler(switch_event_t *event) | ||||||
4129 | { | ||||||
4130 | switch_event_t *cloned_event; | ||||||
4131 | |||||||
4132 | switch_event_dup(&cloned_event, event); | ||||||
4133 | switch_assert(cloned_event)((cloned_event) ? (void) (0) : __assert_fail ("cloned_event", "mod_voicemail.c", 4133, __PRETTY_FUNCTION__)); | ||||||
4134 | switch_queue_push(globals.event_queue, cloned_event); | ||||||
4135 | |||||||
4136 | if (!EVENT_THREAD_STARTED) { | ||||||
4137 | vm_event_thread_start(); | ||||||
4138 | } | ||||||
4139 | } | ||||||
4140 | |||||||
4141 | struct holder { | ||||||
4142 | vm_profile_t *profile; | ||||||
4143 | switch_memory_pool_t *pool; | ||||||
4144 | switch_stream_handle_t *stream; | ||||||
4145 | switch_xml_t xml; | ||||||
4146 | switch_xml_t x_item; | ||||||
4147 | switch_xml_t x_channel; | ||||||
4148 | int items; | ||||||
4149 | const char *user; | ||||||
4150 | const char *domain; | ||||||
4151 | const char *host; | ||||||
4152 | const char *port; | ||||||
4153 | const char *uri; | ||||||
4154 | }; | ||||||
4155 | |||||||
4156 | |||||||
4157 | static int del_callback(void *pArg, int argc, char **argv, char **columnNames) | ||||||
4158 | { | ||||||
4159 | if (argc > 8) { | ||||||
4160 | if (unlink(argv[8]) != 0) { | ||||||
4161 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 4161, ((void*)0), SWITCH_LOG_WARNING, "Failed to delete file [%s]\n", argv[8]); | ||||||
4162 | } | ||||||
4163 | } | ||||||
4164 | return 0; | ||||||
4165 | } | ||||||
4166 | |||||||
4167 | static int play_callback(void *pArg, int argc, char **argv, char **columnNames) | ||||||
4168 | { | ||||||
4169 | switch_file_t *fd; | ||||||
4170 | struct holder *holder = (struct holder *) pArg; | ||||||
4171 | char *fname, *ext; | ||||||
4172 | switch_size_t flen; | ||||||
4173 | uint8_t chunk[1024]; | ||||||
4174 | const char *mime_type = "audio/inline", *new_type; | ||||||
4175 | |||||||
4176 | if ((fname = strrchr(argv[8], '/'))) { | ||||||
4177 | fname++; | ||||||
4178 | } else { | ||||||
4179 | fname = argv[8]; | ||||||
4180 | } | ||||||
4181 | |||||||
4182 | if ((ext = strrchr(fname, '.'))) { | ||||||
4183 | ext++; | ||||||
4184 | if ((new_type = switch_core_mime_ext2type(ext))) { | ||||||
4185 | mime_type = new_type; | ||||||
4186 | } | ||||||
4187 | } | ||||||
4188 | |||||||
4189 | if (switch_file_open(&fd, argv[8], SWITCH_FOPEN_READ0x00001, SWITCH_FPROT_UREAD0x0400 | SWITCH_FPROT_UWRITE0x0200, holder->pool) == SWITCH_STATUS_SUCCESS) { | ||||||
4190 | flen = switch_file_get_size(fd); | ||||||
4191 | holder->stream->write_function(holder->stream, "Content-type: %s\n", mime_type); | ||||||
4192 | holder->stream->write_function(holder->stream, "Content-length: %ld\n\n", (long) flen); | ||||||
4193 | for (;;) { | ||||||
4194 | switch_status_t status; | ||||||
4195 | |||||||
4196 | flen = sizeof(chunk); | ||||||
4197 | status = switch_file_read(fd, chunk, &flen); | ||||||
4198 | if (status != SWITCH_STATUS_SUCCESS || flen == 0) { | ||||||
4199 | break; | ||||||
4200 | } | ||||||
4201 | |||||||
4202 | holder->stream->raw_write_function(holder->stream, chunk, flen); | ||||||
4203 | } | ||||||
4204 | switch_file_close(fd); | ||||||
4205 | } | ||||||
4206 | return 0; | ||||||
4207 | } | ||||||
4208 | |||||||
4209 | static void do_play(vm_profile_t *profile, char *user_in, char *domain, char *file, switch_stream_handle_t *stream) | ||||||
4210 | { | ||||||
4211 | char *sql; | ||||||
4212 | struct holder holder; | ||||||
4213 | char *user; | ||||||
4214 | |||||||
4215 | user = resolve_id(user_in, domain, "web-vm"); | ||||||
4216 | |||||||
4217 | sql = switch_mprintf("update voicemail_msgs set read_epoch=%ld where username='%s' and domain='%s' and file_path like '%%%s'", | ||||||
4218 | (long) switch_epoch_time_now(NULL((void*)0)), user, domain, file); | ||||||
4219 | |||||||
4220 | vm_execute_sql(profile, sql, profile->mutex); | ||||||
4221 | free(sql); | ||||||
4222 | |||||||
4223 | sql = switch_mprintf("select created_epoch, read_epoch, username, domain, uuid, cid_name, cid_number, in_folder, file_path, message_len, flags, read_flags, forwarded_by from voicemail_msgs where username='%s' and domain='%s' and file_path like '%%%s' order by created_epoch", | ||||||
4224 | user, domain, file); | ||||||
4225 | memset(&holder, 0, sizeof(holder)); | ||||||
4226 | holder.profile = profile; | ||||||
4227 | holder.stream = stream; | ||||||
4228 | switch_core_new_memory_pool(&holder.pool)switch_core_perform_new_memory_pool(&holder.pool, "mod_voicemail.c" , (const char *)__func__, 4228); | ||||||
4229 | vm_execute_sql_callback(profile, profile->mutex, sql, play_callback, &holder); | ||||||
4230 | switch_core_destroy_memory_pool(&holder.pool)switch_core_perform_destroy_memory_pool(&holder.pool, "mod_voicemail.c" , (const char *)__func__, 4230); | ||||||
4231 | switch_safe_free(sql)if (sql) {free(sql);sql=((void*)0);}; | ||||||
4232 | } | ||||||
4233 | |||||||
4234 | |||||||
4235 | static void do_del(vm_profile_t *profile, char *user_in, char *domain, char *file, switch_stream_handle_t *stream) | ||||||
4236 | { | ||||||
4237 | char *myfolder = "inbox"; | ||||||
4238 | char *sql; | ||||||
4239 | struct holder holder; | ||||||
4240 | char *ref = NULL((void*)0); | ||||||
4241 | char *user; | ||||||
4242 | |||||||
4243 | user = resolve_id(user_in, domain, "web-vm"); | ||||||
4244 | |||||||
4245 | if (stream->param_event) { | ||||||
4246 | ref = switch_event_get_header(stream->param_event, "http-referer")switch_event_get_header_idx(stream->param_event, "http-referer" , -1); | ||||||
4247 | } | ||||||
4248 | |||||||
4249 | sql = switch_mprintf("select created_epoch, read_epoch, username, domain, uuid, cid_name, cid_number, in_folder, file_path, message_len, flags, read_flags, forwarded_by from voicemail_msgs where username='%s' and domain='%s' and file_path like '%%%s' order by created_epoch", | ||||||
4250 | user, domain, file); | ||||||
4251 | memset(&holder, 0, sizeof(holder)); | ||||||
4252 | holder.profile = profile; | ||||||
4253 | holder.stream = stream; | ||||||
4254 | vm_execute_sql_callback(profile, profile->mutex, sql, del_callback, &holder); | ||||||
4255 | |||||||
4256 | switch_safe_free(sql)if (sql) {free(sql);sql=((void*)0);}; | ||||||
4257 | sql = switch_mprintf("delete from voicemail_msgs where username='%s' and domain='%s' and file_path like '%%%s'", user, domain, file); | ||||||
4258 | vm_execute_sql(profile, sql, profile->mutex); | ||||||
4259 | free(sql); | ||||||
4260 | |||||||
4261 | update_mwi(profile, user, domain, myfolder, MWI_REASON_DELETE); | ||||||
4262 | |||||||
4263 | if (ref) { | ||||||
4264 | stream->write_function(stream, "Content-type: text/html\n\n<h2>Message Deleted</h2>\n" "<META http-equiv=\"refresh\" content=\"1;URL=%s\">", ref); | ||||||
4265 | } | ||||||
4266 | } | ||||||
4267 | |||||||
4268 | |||||||
4269 | static int web_callback(void *pArg, int argc, char **argv, char **columnNames) | ||||||
4270 | { | ||||||
4271 | struct holder *holder = (struct holder *) pArg; | ||||||
4272 | char *del, *get, *fname, *ext; | ||||||
4273 | switch_time_exp_t tm; | ||||||
4274 | char create_date[80] = ""; | ||||||
4275 | char read_date[80] = ""; | ||||||
4276 | char rss_date[80] = ""; | ||||||
4277 | switch_size_t retsize; | ||||||
4278 | switch_time_t l_created = 0; | ||||||
4279 | switch_time_t l_read = 0; | ||||||
4280 | switch_time_t l_duration = 0; | ||||||
4281 | switch_core_time_duration_t duration; | ||||||
4282 | char duration_str[80]; | ||||||
4283 | const char *fmt = "%a, %e %b %Y %T %z"; | ||||||
4284 | char heard[80]; | ||||||
4285 | char title_b4[128] = ""; | ||||||
4286 | char title_aft[128 * 3 + 1] = ""; | ||||||
4287 | |||||||
4288 | if (argc > 0) { | ||||||
4289 | l_created = switch_time_make(atol(argv[0]), 0); | ||||||
4290 | } | ||||||
4291 | |||||||
4292 | if (argc > 1) { | ||||||
4293 | l_read = switch_time_make(atol(argv[1]), 0); | ||||||
4294 | } | ||||||
4295 | |||||||
4296 | if (argc > 9) { | ||||||
4297 | l_duration = switch_time_make(atol(argv[9]), 0); | ||||||
4298 | } | ||||||
4299 | |||||||
4300 | if ((fname = strrchr(argv[8], '/'))) { | ||||||
4301 | fname++; | ||||||
4302 | } else { | ||||||
4303 | fname = argv[8]; | ||||||
4304 | } | ||||||
4305 | |||||||
4306 | if ((ext = strrchr(fname, '.'))) { | ||||||
4307 | ext++; | ||||||
4308 | } | ||||||
4309 | |||||||
4310 | switch_core_measure_time(l_duration, &duration); | ||||||
4311 | duration.day += duration.yr * 365; | ||||||
4312 | duration.hr += duration.day * 24; | ||||||
4313 | |||||||
4314 | switch_snprintf(duration_str, sizeof(duration_str), "%.2u:%.2u:%.2u", duration.hr, duration.min, duration.sec); | ||||||
4315 | |||||||
4316 | if (l_created) { | ||||||
4317 | switch_time_exp_lt(&tm, l_created); | ||||||
4318 | switch_strftime_nocheck(create_date, &retsize, sizeof(create_date), fmt, &tm); | ||||||
4319 | switch_strftime_nocheck(rss_date, &retsize, sizeof(create_date), "%D %T", &tm); | ||||||
4320 | } | ||||||
4321 | |||||||
4322 | if (l_read) { | ||||||
4323 | switch_time_exp_lt(&tm, l_read); | ||||||
4324 | switch_strftime_nocheck(read_date, &retsize, sizeof(read_date), fmt, &tm); | ||||||
4325 | } | ||||||
4326 | |||||||
4327 | switch_snprintf(heard, sizeof(heard), *read_date == '\0' ? "never" : read_date); | ||||||
4328 | |||||||
4329 | get = switch_mprintf("http://%s:%s%s/get/%s", holder->host, holder->port, holder->uri, fname); | ||||||
4330 | del = switch_mprintf("http://%s:%s%s/del/%s", holder->host, holder->port, holder->uri, fname); | ||||||
4331 | |||||||
4332 | holder->stream->write_function(holder->stream, "<font face=tahoma><div class=title><b>Message from %s %s</b></div><hr noshade size=1>\n", | ||||||
4333 | argv[5], argv[6]); | ||||||
4334 | holder->stream->write_function(holder->stream, "Priority: %s<br>\n" "Created: %s<br>\n" "Last Heard: %s<br>\n" "Duration: %s<br>\n", | ||||||
4335 | //"<a href=%s>Delete This Message</a><br><hr noshade size=1>", | ||||||
4336 | strcmp(argv[10], URGENT_FLAG_STRING)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (argv[10]) && __builtin_constant_p ("A_URGENT") && (__s1_len = __builtin_strlen (argv[10]), __s2_len = __builtin_strlen ("A_URGENT"), (!((size_t)(const void *)((argv[10]) + 1) - (size_t )(const void *)(argv[10]) == 1) || __s1_len >= 4) && (!((size_t)(const void *)(("A_URGENT") + 1) - (size_t)(const void *)("A_URGENT") == 1) || __s2_len >= 4)) ? __builtin_strcmp (argv[10], "A_URGENT") : (__builtin_constant_p (argv[10]) && ((size_t)(const void *)((argv[10]) + 1) - (size_t)(const void *)(argv[10]) == 1) && (__s1_len = __builtin_strlen ( argv[10]), __s1_len < 4) ? (__builtin_constant_p ("A_URGENT" ) && ((size_t)(const void *)(("A_URGENT") + 1) - (size_t )(const void *)("A_URGENT") == 1) ? __builtin_strcmp (argv[10 ], "A_URGENT") : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) ("A_URGENT"); int __result = (((const unsigned char *) (const char *) (argv[10]))[0] - __s2 [0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (argv[10]))[1] - __s2 [1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (argv[10]))[2] - __s2 [2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (argv[10]))[3] - __s2 [3]); } } __result; }))) : (__builtin_constant_p ("A_URGENT") && ((size_t)(const void *)(("A_URGENT") + 1) - (size_t )(const void *)("A_URGENT") == 1) && (__s2_len = __builtin_strlen ("A_URGENT"), __s2_len < 4) ? (__builtin_constant_p (argv [10]) && ((size_t)(const void *)((argv[10]) + 1) - (size_t )(const void *)(argv[10]) == 1) ? __builtin_strcmp (argv[10], "A_URGENT") : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (argv[10]); int __result = (((const unsigned char *) (const char *) ("A_URGENT"))[0] - __s2[0]); if (__s2_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) ("A_URGENT"))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) ("A_URGENT"))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) ("A_URGENT"))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (argv[10], "A_URGENT" )))); }) ? "normal" : "urgent", create_date, heard, duration_str); | ||||||
4337 | |||||||
4338 | switch_snprintf(title_b4, sizeof(title_b4), "%s <%s> %s", argv[5], argv[6], rss_date); | ||||||
4339 | switch_url_encode(title_b4, title_aft, sizeof(title_aft)); | ||||||
4340 | |||||||
4341 | holder->stream->write_function(holder->stream, | ||||||
4342 | "<br><object width=550 height=15 \n" | ||||||
4343 | "type=\"application/x-shockwave-flash\" \n" | ||||||
4344 | "data=\"http://%s:%s/pub/slim.swf?song_url=%s&player_title=%s\">\n" | ||||||
4345 | "<param name=movie value=\"http://%s:%s/pub/slim.swf?song_url=%s&player_title=%s\"></object><br><br>\n" | ||||||
4346 | "[<a href=%s>delete</a>] [<a href=%s>download</a>] [<a href=tel:%s>call</a>] <br><br><br></font>\n", | ||||||
4347 | holder->host, holder->port, get, title_aft, holder->host, holder->port, get, title_aft, del, get, argv[6]); | ||||||
4348 | |||||||
4349 | free(get); | ||||||
4350 | free(del); | ||||||
4351 | |||||||
4352 | return 0; | ||||||
4353 | } | ||||||
4354 | |||||||
4355 | static int rss_callback(void *pArg, int argc, char **argv, char **columnNames) | ||||||
4356 | { | ||||||
4357 | struct holder *holder = (struct holder *) pArg; | ||||||
4358 | switch_xml_t x_tmp, x_link; | ||||||
4359 | char *tmp, *del, *get; | ||||||
4360 | switch_time_exp_t tm; | ||||||
4361 | char create_date[80] = ""; | ||||||
4362 | char read_date[80] = ""; | ||||||
4363 | char rss_date[80] = ""; | ||||||
4364 | switch_size_t retsize; | ||||||
4365 | const char *mime_type = "audio/inline", *new_type; | ||||||
4366 | char *ext; | ||||||
4367 | char *fname; | ||||||
4368 | switch_size_t flen; | ||||||
4369 | switch_file_t *fd; | ||||||
4370 | switch_time_t l_created = 0; | ||||||
4371 | switch_time_t l_read = 0; | ||||||
4372 | switch_time_t l_duration = 0; | ||||||
4373 | switch_core_time_duration_t duration; | ||||||
4374 | char duration_str[80]; | ||||||
4375 | const char *fmt = "%a, %e %b %Y %T %z"; | ||||||
4376 | char heard[80]; | ||||||
4377 | |||||||
4378 | if (argc > 0) { | ||||||
4379 | l_created = switch_time_make(atol(argv[0]), 0); | ||||||
4380 | } | ||||||
4381 | |||||||
4382 | if (argc > 1) { | ||||||
4383 | l_read = switch_time_make(atol(argv[1]), 0); | ||||||
4384 | } | ||||||
4385 | |||||||
4386 | if (argc > 9) { | ||||||
4387 | l_duration = switch_time_make(atol(argv[9]), 0); | ||||||
4388 | } | ||||||
4389 | |||||||
4390 | switch_core_measure_time(l_duration, &duration); | ||||||
4391 | duration.day += duration.yr * 365; | ||||||
4392 | duration.hr += duration.day * 24; | ||||||
4393 | |||||||
4394 | switch_snprintf(duration_str, sizeof(duration_str), "%.2u:%.2u:%.2u", duration.hr, duration.min, duration.sec); | ||||||
4395 | |||||||
4396 | if (l_created) { | ||||||
4397 | switch_time_exp_lt(&tm, l_created); | ||||||
4398 | switch_strftime_nocheck(create_date, &retsize, sizeof(create_date), fmt, &tm); | ||||||
4399 | switch_strftime_nocheck(rss_date, &retsize, sizeof(create_date), fmt, &tm); | ||||||
4400 | } | ||||||
4401 | |||||||
4402 | if (l_read) { | ||||||
4403 | switch_time_exp_lt(&tm, l_read); | ||||||
4404 | switch_strftime_nocheck(read_date, &retsize, sizeof(read_date), fmt, &tm); | ||||||
4405 | } | ||||||
4406 | |||||||
4407 | holder->x_item = switch_xml_add_child_d(holder->x_channel, "item", holder->items++)switch_xml_set_flag(switch_xml_add_child(holder->x_channel , (__extension__ (__builtin_constant_p ("item") && (( size_t)(const void *)(("item") + 1) - (size_t)(const void *)( "item") == 1) ? (((const char *) ("item"))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen ("item") + 1; char *__retval = (char *) malloc (__len); if ( __retval != ((void*)0)) __retval = (char *) memcpy (__retval, "item", __len); __retval; })) : __strdup ("item"))), holder-> items++), SWITCH_XML_NAMEM); | ||||||
4408 | |||||||
4409 | x_tmp = switch_xml_add_child_d(holder->x_item, "title", 0)switch_xml_set_flag(switch_xml_add_child(holder->x_item, ( __extension__ (__builtin_constant_p ("title") && ((size_t )(const void *)(("title") + 1) - (size_t)(const void *)("title" ) == 1) ? (((const char *) ("title"))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen ("title" ) + 1; char *__retval = (char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, "title" , __len); __retval; })) : __strdup ("title"))), 0), SWITCH_XML_NAMEM ); | ||||||
4410 | tmp = switch_mprintf("Message from %s %s on %s", argv[5], argv[6], create_date); | ||||||
4411 | switch_xml_set_txt_d(x_tmp, tmp)switch_xml_set_flag(switch_xml_set_txt(x_tmp, (__extension__ ( __builtin_constant_p (tmp) && ((size_t)(const void *) ((tmp) + 1) - (size_t)(const void *)(tmp) == 1) ? (((const char *) (tmp))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen (tmp) + 1; char *__retval = (char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, tmp, __len); __retval; })) : __strdup ( tmp)))), SWITCH_XML_TXTM); | ||||||
4412 | free(tmp); | ||||||
4413 | |||||||
4414 | x_tmp = switch_xml_add_child_d(holder->x_item, "description", 0)switch_xml_set_flag(switch_xml_add_child(holder->x_item, ( __extension__ (__builtin_constant_p ("description") && ((size_t)(const void *)(("description") + 1) - (size_t)(const void *)("description") == 1) ? (((const char *) ("description" ))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen ("description") + 1; char *__retval = ( char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, "description", __len); __retval; } )) : __strdup ("description"))), 0), SWITCH_XML_NAMEM); | ||||||
4415 | |||||||
4416 | switch_snprintf(heard, sizeof(heard), *read_date == '\0' ? "never" : read_date); | ||||||
4417 | |||||||
4418 | if ((fname = strrchr(argv[8], '/'))) { | ||||||
4419 | fname++; | ||||||
4420 | } else { | ||||||
4421 | fname = argv[8]; | ||||||
4422 | } | ||||||
4423 | |||||||
4424 | get = switch_mprintf("http://%s:%s%s/get/%s", holder->host, holder->port, holder->uri, fname); | ||||||
4425 | del = switch_mprintf("http://%s:%s%s/del/%s", holder->host, holder->port, holder->uri, fname); | ||||||
4426 | x_link = switch_xml_add_child_d(holder->x_item, "fsvm:rmlink", 0)switch_xml_set_flag(switch_xml_add_child(holder->x_item, ( __extension__ (__builtin_constant_p ("fsvm:rmlink") && ((size_t)(const void *)(("fsvm:rmlink") + 1) - (size_t)(const void *)("fsvm:rmlink") == 1) ? (((const char *) ("fsvm:rmlink" ))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen ("fsvm:rmlink") + 1; char *__retval = ( char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, "fsvm:rmlink", __len); __retval; } )) : __strdup ("fsvm:rmlink"))), 0), SWITCH_XML_NAMEM); | ||||||
4427 | switch_xml_set_txt_d(x_link, del)switch_xml_set_flag(switch_xml_set_txt(x_link, (__extension__ (__builtin_constant_p (del) && ((size_t)(const void * )((del) + 1) - (size_t)(const void *)(del) == 1) ? (((const char *) (del))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen (del) + 1; char *__retval = (char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, del, __len); __retval; })) : __strdup ( del)))), SWITCH_XML_TXTM); | ||||||
4428 | |||||||
4429 | tmp = switch_mprintf("<![CDATA[Priority: %s<br>" | ||||||
4430 | "Last Heard: %s<br>Duration: %s<br>" | ||||||
4431 | "<a href=%s>Delete This Message</a><br>" | ||||||
4432 | "]]>", strcmp(argv[10], URGENT_FLAG_STRING)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (argv[10]) && __builtin_constant_p ("A_URGENT") && (__s1_len = __builtin_strlen (argv[10]), __s2_len = __builtin_strlen ("A_URGENT"), (!((size_t)(const void *)((argv[10]) + 1) - (size_t )(const void *)(argv[10]) == 1) || __s1_len >= 4) && (!((size_t)(const void *)(("A_URGENT") + 1) - (size_t)(const void *)("A_URGENT") == 1) || __s2_len >= 4)) ? __builtin_strcmp (argv[10], "A_URGENT") : (__builtin_constant_p (argv[10]) && ((size_t)(const void *)((argv[10]) + 1) - (size_t)(const void *)(argv[10]) == 1) && (__s1_len = __builtin_strlen ( argv[10]), __s1_len < 4) ? (__builtin_constant_p ("A_URGENT" ) && ((size_t)(const void *)(("A_URGENT") + 1) - (size_t )(const void *)("A_URGENT") == 1) ? __builtin_strcmp (argv[10 ], "A_URGENT") : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) ("A_URGENT"); int __result = (((const unsigned char *) (const char *) (argv[10]))[0] - __s2 [0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (argv[10]))[1] - __s2 [1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (argv[10]))[2] - __s2 [2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (argv[10]))[3] - __s2 [3]); } } __result; }))) : (__builtin_constant_p ("A_URGENT") && ((size_t)(const void *)(("A_URGENT") + 1) - (size_t )(const void *)("A_URGENT") == 1) && (__s2_len = __builtin_strlen ("A_URGENT"), __s2_len < 4) ? (__builtin_constant_p (argv [10]) && ((size_t)(const void *)((argv[10]) + 1) - (size_t )(const void *)(argv[10]) == 1) ? __builtin_strcmp (argv[10], "A_URGENT") : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (argv[10]); int __result = (((const unsigned char *) (const char *) ("A_URGENT"))[0] - __s2[0]); if (__s2_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) ("A_URGENT"))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) ("A_URGENT"))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) ("A_URGENT"))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (argv[10], "A_URGENT" )))); }) ? "normal" : "urgent", heard, duration_str, del); | ||||||
4433 | |||||||
4434 | switch_xml_set_txt_d(x_tmp, tmp)switch_xml_set_flag(switch_xml_set_txt(x_tmp, (__extension__ ( __builtin_constant_p (tmp) && ((size_t)(const void *) ((tmp) + 1) - (size_t)(const void *)(tmp) == 1) ? (((const char *) (tmp))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen (tmp) + 1; char *__retval = (char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, tmp, __len); __retval; })) : __strdup ( tmp)))), SWITCH_XML_TXTM); | ||||||
4435 | free(tmp); | ||||||
4436 | free(del); | ||||||
4437 | |||||||
4438 | x_tmp = switch_xml_add_child_d(holder->x_item, "pubDate", 0)switch_xml_set_flag(switch_xml_add_child(holder->x_item, ( __extension__ (__builtin_constant_p ("pubDate") && (( size_t)(const void *)(("pubDate") + 1) - (size_t)(const void * )("pubDate") == 1) ? (((const char *) ("pubDate"))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen ("pubDate") + 1; char *__retval = (char *) malloc ( __len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, "pubDate", __len); __retval; })) : __strdup ("pubDate" ))), 0), SWITCH_XML_NAMEM); | ||||||
4439 | switch_xml_set_txt_d(x_tmp, rss_date)switch_xml_set_flag(switch_xml_set_txt(x_tmp, (__extension__ ( __builtin_constant_p (rss_date) && ((size_t)(const void *)((rss_date) + 1) - (size_t)(const void *)(rss_date) == 1) ? (((const char *) (rss_date))[0] == '\0' ? (char *) calloc (( size_t) 1, (size_t) 1) : ({ size_t __len = strlen (rss_date) + 1; char *__retval = (char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, rss_date, __len ); __retval; })) : __strdup (rss_date)))), SWITCH_XML_TXTM); | ||||||
4440 | |||||||
4441 | x_tmp = switch_xml_add_child_d(holder->x_item, "itunes:duration", 0)switch_xml_set_flag(switch_xml_add_child(holder->x_item, ( __extension__ (__builtin_constant_p ("itunes:duration") && ((size_t)(const void *)(("itunes:duration") + 1) - (size_t)( const void *)("itunes:duration") == 1) ? (((const char *) ("itunes:duration" ))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen ("itunes:duration") + 1; char *__retval = (char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, "itunes:duration", __len); __retval ; })) : __strdup ("itunes:duration"))), 0), SWITCH_XML_NAMEM); | ||||||
4442 | switch_xml_set_txt_d(x_tmp, duration_str)switch_xml_set_flag(switch_xml_set_txt(x_tmp, (__extension__ ( __builtin_constant_p (duration_str) && ((size_t)(const void *)((duration_str) + 1) - (size_t)(const void *)(duration_str ) == 1) ? (((const char *) (duration_str))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen (duration_str) + 1; char *__retval = (char *) malloc (__len) ; if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval , duration_str, __len); __retval; })) : __strdup (duration_str )))), SWITCH_XML_TXTM); | ||||||
4443 | |||||||
4444 | x_tmp = switch_xml_add_child_d(holder->x_item, "guid", 0)switch_xml_set_flag(switch_xml_add_child(holder->x_item, ( __extension__ (__builtin_constant_p ("guid") && ((size_t )(const void *)(("guid") + 1) - (size_t)(const void *)("guid" ) == 1) ? (((const char *) ("guid"))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen ("guid") + 1; char *__retval = (char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, "guid", __len ); __retval; })) : __strdup ("guid"))), 0), SWITCH_XML_NAMEM); | ||||||
4445 | switch_xml_set_txt_d(x_tmp, get)switch_xml_set_flag(switch_xml_set_txt(x_tmp, (__extension__ ( __builtin_constant_p (get) && ((size_t)(const void *) ((get) + 1) - (size_t)(const void *)(get) == 1) ? (((const char *) (get))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen (get) + 1; char *__retval = (char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, get, __len); __retval; })) : __strdup ( get)))), SWITCH_XML_TXTM); | ||||||
4446 | |||||||
4447 | x_link = switch_xml_add_child_d(holder->x_item, "link", 0)switch_xml_set_flag(switch_xml_add_child(holder->x_item, ( __extension__ (__builtin_constant_p ("link") && ((size_t )(const void *)(("link") + 1) - (size_t)(const void *)("link" ) == 1) ? (((const char *) ("link"))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen ("link") + 1; char *__retval = (char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, "link", __len ); __retval; })) : __strdup ("link"))), 0), SWITCH_XML_NAMEM); | ||||||
4448 | switch_xml_set_txt_d(x_link, get)switch_xml_set_flag(switch_xml_set_txt(x_link, (__extension__ (__builtin_constant_p (get) && ((size_t)(const void * )((get) + 1) - (size_t)(const void *)(get) == 1) ? (((const char *) (get))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen (get) + 1; char *__retval = (char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, get, __len); __retval; })) : __strdup ( get)))), SWITCH_XML_TXTM); | ||||||
4449 | |||||||
4450 | x_tmp = switch_xml_add_child_d(holder->x_item, "enclosure", 0)switch_xml_set_flag(switch_xml_add_child(holder->x_item, ( __extension__ (__builtin_constant_p ("enclosure") && ( (size_t)(const void *)(("enclosure") + 1) - (size_t)(const void *)("enclosure") == 1) ? (((const char *) ("enclosure"))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen ("enclosure") + 1; char *__retval = (char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, "enclosure", __len); __retval; })) : __strdup ("enclosure" ))), 0), SWITCH_XML_NAMEM); | ||||||
4451 | switch_xml_set_attr_d(x_tmp, "url", get)switch_xml_set_attr(switch_xml_set_flag(x_tmp, SWITCH_XML_DUP ), (__extension__ (__builtin_constant_p ("url") && (( size_t)(const void *)(("url") + 1) - (size_t)(const void *)("url" ) == 1) ? (((const char *) ("url"))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen ("url") + 1; char *__retval = (char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, "url", __len ); __retval; })) : __strdup ("url"))), (__extension__ (__builtin_constant_p ((get ? get : "")) && ((size_t)(const void *)(((get ? get : "")) + 1) - (size_t)(const void *)((get ? get : "")) == 1) ? (((const char *) ((get ? get : "")))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen ((get ? get : "")) + 1; char *__retval = (char *) malloc (__len ); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval , (get ? get : ""), __len); __retval; })) : __strdup ((get ? get : ""))))); | ||||||
4452 | free(get); | ||||||
4453 | |||||||
4454 | if (switch_file_open(&fd, argv[8], SWITCH_FOPEN_READ0x00001, SWITCH_FPROT_UREAD0x0400 | SWITCH_FPROT_UWRITE0x0200, holder->pool) == SWITCH_STATUS_SUCCESS) { | ||||||
4455 | flen = switch_file_get_size(fd); | ||||||
4456 | tmp = switch_mprintf("%ld", (long) flen); | ||||||
4457 | switch_xml_set_attr_d(x_tmp, "length", tmp)switch_xml_set_attr(switch_xml_set_flag(x_tmp, SWITCH_XML_DUP ), (__extension__ (__builtin_constant_p ("length") && ((size_t)(const void *)(("length") + 1) - (size_t)(const void *)("length") == 1) ? (((const char *) ("length"))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen ("length") + 1; char *__retval = (char *) malloc (__len ); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval , "length", __len); __retval; })) : __strdup ("length"))), (__extension__ (__builtin_constant_p ((tmp ? tmp : "")) && ((size_t )(const void *)(((tmp ? tmp : "")) + 1) - (size_t)(const void *)((tmp ? tmp : "")) == 1) ? (((const char *) ((tmp ? tmp : "" )))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ( { size_t __len = strlen ((tmp ? tmp : "")) + 1; char *__retval = (char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, (tmp ? tmp : ""), __len); __retval ; })) : __strdup ((tmp ? tmp : ""))))); | ||||||
4458 | free(tmp); | ||||||
4459 | switch_file_close(fd); | ||||||
4460 | } | ||||||
4461 | |||||||
4462 | if ((ext = strrchr(fname, '.'))) { | ||||||
4463 | ext++; | ||||||
4464 | if ((new_type = switch_core_mime_ext2type(ext))) { | ||||||
4465 | mime_type = new_type; | ||||||
4466 | } | ||||||
4467 | } | ||||||
4468 | switch_xml_set_attr_d(x_tmp, "type", mime_type)switch_xml_set_attr(switch_xml_set_flag(x_tmp, SWITCH_XML_DUP ), (__extension__ (__builtin_constant_p ("type") && ( (size_t)(const void *)(("type") + 1) - (size_t)(const void *) ("type") == 1) ? (((const char *) ("type"))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen ("type") + 1; char *__retval = (char *) malloc (__len); if ( __retval != ((void*)0)) __retval = (char *) memcpy (__retval, "type", __len); __retval; })) : __strdup ("type"))), (__extension__ (__builtin_constant_p ((mime_type ? mime_type : "")) && ((size_t)(const void *)(((mime_type ? mime_type : "")) + 1) - (size_t)(const void *)((mime_type ? mime_type : "")) == 1) ? (((const char *) ((mime_type ? mime_type : "")))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen ((mime_type ? mime_type : "")) + 1; char *__retval = ( char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, (mime_type ? mime_type : ""), __len ); __retval; })) : __strdup ((mime_type ? mime_type : ""))))); | ||||||
4469 | |||||||
4470 | return 0; | ||||||
4471 | } | ||||||
4472 | |||||||
4473 | |||||||
4474 | static void do_rss(vm_profile_t *profile, char *user, char *domain, char *host, char *port, char *uri, switch_stream_handle_t *stream) | ||||||
4475 | { | ||||||
4476 | struct holder holder; | ||||||
4477 | switch_xml_t x_tmp; | ||||||
4478 | char *sql, *xmlstr; | ||||||
4479 | char *tmp = NULL((void*)0); | ||||||
4480 | |||||||
4481 | stream->write_function(stream, "Content-type: text/xml\n\n"); | ||||||
4482 | memset(&holder, 0, sizeof(holder)); | ||||||
4483 | holder.profile = profile; | ||||||
4484 | holder.stream = stream; | ||||||
4485 | holder.xml = switch_xml_new("rss"); | ||||||
4486 | holder.user = user; | ||||||
4487 | holder.domain = domain; | ||||||
4488 | holder.host = host; | ||||||
4489 | holder.port = port; | ||||||
4490 | holder.uri = uri; | ||||||
4491 | |||||||
4492 | switch_core_new_memory_pool(&holder.pool)switch_core_perform_new_memory_pool(&holder.pool, "mod_voicemail.c" , (const char *)__func__, 4492); | ||||||
4493 | switch_assert(holder.xml)((holder.xml) ? (void) (0) : __assert_fail ("holder.xml", "mod_voicemail.c" , 4493, __PRETTY_FUNCTION__)); | ||||||
4494 | |||||||
4495 | switch_xml_set_attr_d(holder.xml, "xmlns:itunes", "http://www.itunes.com/dtds/podcast-1.0.dtd")switch_xml_set_attr(switch_xml_set_flag(holder.xml, SWITCH_XML_DUP ), (__extension__ (__builtin_constant_p ("xmlns:itunes") && ((size_t)(const void *)(("xmlns:itunes") + 1) - (size_t)(const void *)("xmlns:itunes") == 1) ? (((const char *) ("xmlns:itunes" ))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen ("xmlns:itunes") + 1; char *__retval = (char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, "xmlns:itunes", __len); __retval ; })) : __strdup ("xmlns:itunes"))), (__extension__ (__builtin_constant_p (("http://www.itunes.com/dtds/podcast-1.0.dtd" ? "http://www.itunes.com/dtds/podcast-1.0.dtd" : "")) && ((size_t)(const void *)((("http://www.itunes.com/dtds/podcast-1.0.dtd" ? "http://www.itunes.com/dtds/podcast-1.0.dtd" : "")) + 1) - (size_t)(const void *)(("http://www.itunes.com/dtds/podcast-1.0.dtd" ? "http://www.itunes.com/dtds/podcast-1.0.dtd" : "")) == 1) ? (((const char *) (("http://www.itunes.com/dtds/podcast-1.0.dtd" ? "http://www.itunes.com/dtds/podcast-1.0.dtd" : "")))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen (("http://www.itunes.com/dtds/podcast-1.0.dtd" ? "http://www.itunes.com/dtds/podcast-1.0.dtd" : "")) + 1; char *__retval = (char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, ("http://www.itunes.com/dtds/podcast-1.0.dtd" ? "http://www.itunes.com/dtds/podcast-1.0.dtd" : ""), __len) ; __retval; })) : __strdup (("http://www.itunes.com/dtds/podcast-1.0.dtd" ? "http://www.itunes.com/dtds/podcast-1.0.dtd" : ""))))); | ||||||
4496 | switch_xml_set_attr_d(holder.xml, "xmlns:fsvm", "http://www.freeswitch.org/dtd/fsvm.dtd")switch_xml_set_attr(switch_xml_set_flag(holder.xml, SWITCH_XML_DUP ), (__extension__ (__builtin_constant_p ("xmlns:fsvm") && ((size_t)(const void *)(("xmlns:fsvm") + 1) - (size_t)(const void *)("xmlns:fsvm") == 1) ? (((const char *) ("xmlns:fsvm" ))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen ("xmlns:fsvm") + 1; char *__retval = ( char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, "xmlns:fsvm", __len); __retval; } )) : __strdup ("xmlns:fsvm"))), (__extension__ (__builtin_constant_p (("http://www.freeswitch.org/dtd/fsvm.dtd" ? "http://www.freeswitch.org/dtd/fsvm.dtd" : "")) && ((size_t)(const void *)((("http://www.freeswitch.org/dtd/fsvm.dtd" ? "http://www.freeswitch.org/dtd/fsvm.dtd" : "")) + 1) - (size_t )(const void *)(("http://www.freeswitch.org/dtd/fsvm.dtd" ? "http://www.freeswitch.org/dtd/fsvm.dtd" : "")) == 1) ? (((const char *) (("http://www.freeswitch.org/dtd/fsvm.dtd" ? "http://www.freeswitch.org/dtd/fsvm.dtd" : "")))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen (("http://www.freeswitch.org/dtd/fsvm.dtd" ? "http://www.freeswitch.org/dtd/fsvm.dtd" : "")) + 1; char *__retval = (char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, ("http://www.freeswitch.org/dtd/fsvm.dtd" ? "http://www.freeswitch.org/dtd/fsvm.dtd" : ""), __len); __retval ; })) : __strdup (("http://www.freeswitch.org/dtd/fsvm.dtd" ? "http://www.freeswitch.org/dtd/fsvm.dtd" : ""))))); | ||||||
4497 | switch_xml_set_attr_d(holder.xml, "version", "2.0")switch_xml_set_attr(switch_xml_set_flag(holder.xml, SWITCH_XML_DUP ), (__extension__ (__builtin_constant_p ("version") && ((size_t)(const void *)(("version") + 1) - (size_t)(const void *)("version") == 1) ? (((const char *) ("version"))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen ("version") + 1; char *__retval = (char *) malloc ( __len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, "version", __len); __retval; })) : __strdup ("version" ))), (__extension__ (__builtin_constant_p (("2.0" ? "2.0" : "" )) && ((size_t)(const void *)((("2.0" ? "2.0" : "")) + 1) - (size_t)(const void *)(("2.0" ? "2.0" : "")) == 1) ? (( (const char *) (("2.0" ? "2.0" : "")))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen (("2.0" ? "2.0" : "")) + 1; char *__retval = (char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval , ("2.0" ? "2.0" : ""), __len); __retval; })) : __strdup (("2.0" ? "2.0" : ""))))); | ||||||
4498 | holder.x_channel = switch_xml_add_child_d(holder.xml, "channel", 0)switch_xml_set_flag(switch_xml_add_child(holder.xml, (__extension__ (__builtin_constant_p ("channel") && ((size_t)(const void *)(("channel") + 1) - (size_t)(const void *)("channel") == 1) ? (((const char *) ("channel"))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen ("channel" ) + 1; char *__retval = (char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, "channel" , __len); __retval; })) : __strdup ("channel"))), 0), SWITCH_XML_NAMEM ); | ||||||
4499 | |||||||
4500 | x_tmp = switch_xml_add_child_d(holder.x_channel, "title", 0)switch_xml_set_flag(switch_xml_add_child(holder.x_channel, (__extension__ (__builtin_constant_p ("title") && ((size_t)(const void *)(("title") + 1) - (size_t)(const void *)("title") == 1) ? ( ((const char *) ("title"))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen ("title") + 1; char *__retval = (char *) malloc (__len); if (__retval != ((void* )0)) __retval = (char *) memcpy (__retval, "title", __len); __retval ; })) : __strdup ("title"))), 0), SWITCH_XML_NAMEM); | ||||||
4501 | tmp = switch_mprintf("FreeSWITCH Voicemail for %s@%s", user, domain); | ||||||
4502 | switch_xml_set_txt_d(x_tmp, tmp)switch_xml_set_flag(switch_xml_set_txt(x_tmp, (__extension__ ( __builtin_constant_p (tmp) && ((size_t)(const void *) ((tmp) + 1) - (size_t)(const void *)(tmp) == 1) ? (((const char *) (tmp))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen (tmp) + 1; char *__retval = (char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, tmp, __len); __retval; })) : __strdup ( tmp)))), SWITCH_XML_TXTM); | ||||||
4503 | free(tmp); | ||||||
4504 | |||||||
4505 | x_tmp = switch_xml_add_child_d(holder.x_channel, "link", 0)switch_xml_set_flag(switch_xml_add_child(holder.x_channel, (__extension__ (__builtin_constant_p ("link") && ((size_t)(const void *)(("link") + 1) - (size_t)(const void *)("link") == 1) ? (( (const char *) ("link"))[0] == '\0' ? (char *) calloc ((size_t ) 1, (size_t) 1) : ({ size_t __len = strlen ("link") + 1; char *__retval = (char *) malloc (__len); if (__retval != ((void* )0)) __retval = (char *) memcpy (__retval, "link", __len); __retval ; })) : __strdup ("link"))), 0), SWITCH_XML_NAMEM); | ||||||
4506 | switch_xml_set_txt_d(x_tmp, "http://www.freeswitch.org")switch_xml_set_flag(switch_xml_set_txt(x_tmp, (__extension__ ( __builtin_constant_p ("http://www.freeswitch.org") && ((size_t)(const void *)(("http://www.freeswitch.org") + 1) - (size_t)(const void *)("http://www.freeswitch.org") == 1) ? ( ((const char *) ("http://www.freeswitch.org"))[0] == '\0' ? ( char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen ("http://www.freeswitch.org") + 1; char *__retval = (char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, "http://www.freeswitch.org", __len); __retval ; })) : __strdup ("http://www.freeswitch.org")))), SWITCH_XML_TXTM ); | ||||||
4507 | |||||||
4508 | x_tmp = switch_xml_add_child_d(holder.x_channel, "description", 0)switch_xml_set_flag(switch_xml_add_child(holder.x_channel, (__extension__ (__builtin_constant_p ("description") && ((size_t)(const void *)(("description") + 1) - (size_t)(const void *)("description" ) == 1) ? (((const char *) ("description"))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen ("description") + 1; char *__retval = (char *) malloc (__len ); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval , "description", __len); __retval; })) : __strdup ("description" ))), 0), SWITCH_XML_NAMEM); | ||||||
Within the expansion of the macro 'switch_xml_add_child_d':
| |||||||
4509 | switch_xml_set_txt_d(x_tmp, "http://www.freeswitch.org")switch_xml_set_flag(switch_xml_set_txt(x_tmp, (__extension__ ( __builtin_constant_p ("http://www.freeswitch.org") && ((size_t)(const void *)(("http://www.freeswitch.org") + 1) - (size_t)(const void *)("http://www.freeswitch.org") == 1) ? ( ((const char *) ("http://www.freeswitch.org"))[0] == '\0' ? ( char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen ("http://www.freeswitch.org") + 1; char *__retval = (char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, "http://www.freeswitch.org", __len); __retval ; })) : __strdup ("http://www.freeswitch.org")))), SWITCH_XML_TXTM ); | ||||||
4510 | |||||||
4511 | x_tmp = switch_xml_add_child_d(holder.x_channel, "ttl", 0)switch_xml_set_flag(switch_xml_add_child(holder.x_channel, (__extension__ (__builtin_constant_p ("ttl") && ((size_t)(const void *)(("ttl") + 1) - (size_t)(const void *)("ttl") == 1) ? (((const char *) ("ttl"))[0] == '\0' ? (char *) calloc ((size_t) 1, ( size_t) 1) : ({ size_t __len = strlen ("ttl") + 1; char *__retval = (char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, "ttl", __len); __retval; })) : __strdup ("ttl"))), 0), SWITCH_XML_NAMEM); | ||||||
4512 | switch_xml_set_txt_d(x_tmp, "15")switch_xml_set_flag(switch_xml_set_txt(x_tmp, (__extension__ ( __builtin_constant_p ("15") && ((size_t)(const void * )(("15") + 1) - (size_t)(const void *)("15") == 1) ? (((const char *) ("15"))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t ) 1) : ({ size_t __len = strlen ("15") + 1; char *__retval = ( char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, "15", __len); __retval; })) : __strdup ("15")))), SWITCH_XML_TXTM); | ||||||
4513 | |||||||
4514 | sql = switch_mprintf("select created_epoch, read_epoch, username, domain, uuid, cid_name, cid_number, in_folder, file_path, message_len, flags, read_flags, forwarded_by from voicemail_msgs where username='%s' and domain='%s' order by read_flags, created_epoch", user, domain); | ||||||
4515 | vm_execute_sql_callback(profile, profile->mutex, sql, rss_callback, &holder); | ||||||
4516 | |||||||
4517 | xmlstr = switch_xml_toxml(holder.xml, SWITCH_TRUE); | ||||||
4518 | |||||||
4519 | stream->write_function(stream, "%s", xmlstr); | ||||||
4520 | |||||||
4521 | switch_safe_free(sql)if (sql) {free(sql);sql=((void*)0);}; | ||||||
4522 | switch_safe_free(xmlstr)if (xmlstr) {free(xmlstr);xmlstr=((void*)0);}; | ||||||
4523 | switch_xml_free(holder.xml); | ||||||
4524 | switch_core_destroy_memory_pool(&holder.pool)switch_core_perform_destroy_memory_pool(&holder.pool, "mod_voicemail.c" , (const char *)__func__, 4524); | ||||||
4525 | } | ||||||
4526 | |||||||
4527 | |||||||
4528 | static void do_web(vm_profile_t *profile, const char *user_in, const char *domain, const char *host, const char *port, const char *uri, | ||||||
4529 | switch_stream_handle_t *stream) | ||||||
4530 | { | ||||||
4531 | char buf[80] = ""; | ||||||
4532 | struct holder holder; | ||||||
4533 | char *sql; | ||||||
4534 | callback_t cbt = { 0 }; | ||||||
4535 | int ttl = 0; | ||||||
4536 | char *user; | ||||||
4537 | |||||||
4538 | user = resolve_id(user_in, domain, "web-vm"); | ||||||
4539 | |||||||
4540 | stream->write_function(stream, "Content-type: text/html\n\n"); | ||||||
4541 | memset(&holder, 0, sizeof(holder)); | ||||||
4542 | holder.profile = profile; | ||||||
4543 | holder.stream = stream; | ||||||
4544 | holder.user = user; | ||||||
4545 | holder.domain = domain; | ||||||
4546 | holder.host = host; | ||||||
4547 | holder.port = port; | ||||||
4548 | holder.uri = uri; | ||||||
4549 | |||||||
4550 | if (profile->web_head) { | ||||||
4551 | stream->raw_write_function(stream, (uint8_t *) profile->web_head, strlen(profile->web_head)); | ||||||
4552 | } | ||||||
4553 | |||||||
4554 | cbt.buf = buf; | ||||||
4555 | cbt.len = sizeof(buf); | ||||||
4556 | |||||||
4557 | sql = switch_mprintf("select created_epoch, read_epoch, username, domain, uuid, cid_name, cid_number, in_folder, file_path, message_len, flags, read_flags, forwarded_by from voicemail_msgs where username='%s' and domain='%s' order by read_flags, created_epoch", user, domain); | ||||||
4558 | vm_execute_sql_callback(profile, profile->mutex, sql, web_callback, &holder); | ||||||
4559 | switch_safe_free(sql)if (sql) {free(sql);sql=((void*)0);}; | ||||||
4560 | |||||||
4561 | sql = switch_mprintf("select count(*) from voicemail_msgs where username='%s' and domain='%s' order by read_flags", user, domain); | ||||||
4562 | vm_execute_sql_callback(profile, profile->mutex, sql, sql2str_callback, &cbt); | ||||||
4563 | switch_safe_free(sql)if (sql) {free(sql);sql=((void*)0);}; | ||||||
4564 | |||||||
4565 | ttl = atoi(buf); | ||||||
4566 | stream->write_function(stream, "%d message%s<br>", ttl, ttl == 1 ? "" : "s"); | ||||||
4567 | |||||||
4568 | if (profile->web_tail) { | ||||||
4569 | stream->raw_write_function(stream, (uint8_t *) profile->web_tail, strlen(profile->web_tail)); | ||||||
4570 | } | ||||||
4571 | |||||||
4572 | if (user != user_in) { | ||||||
4573 | free(user); | ||||||
4574 | } | ||||||
4575 | } | ||||||
4576 | |||||||
4577 | #define VM_INJECT_USAGE"[group=<group>[@domain]|domain=<domain>|<box>[@<domain>]] <sound_file> [<cid_num>] [<cid_name>]" "[group=<group>[@domain]|domain=<domain>|<box>[@<domain>]] <sound_file> [<cid_num>] [<cid_name>]" | ||||||
4578 | SWITCH_STANDARD_API(voicemail_inject_api_function)static switch_status_t voicemail_inject_api_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | ||||||
4579 | { | ||||||
4580 | if (voicemail_inject(cmd, session) == SWITCH_STATUS_SUCCESS) { | ||||||
4581 | stream->write_function(stream, "%s", "+OK\n"); | ||||||
4582 | } else { | ||||||
4583 | stream->write_function(stream, "Error: %s\n", VM_INJECT_USAGE"[group=<group>[@domain]|domain=<domain>|<box>[@<domain>]] <sound_file> [<cid_num>] [<cid_name>]"); | ||||||
4584 | } | ||||||
4585 | return SWITCH_STATUS_SUCCESS; | ||||||
4586 | } | ||||||
4587 | |||||||
4588 | |||||||
4589 | static int api_del_callback(void *pArg, int argc, char **argv, char **columnNames) | ||||||
4590 | { | ||||||
4591 | |||||||
4592 | unlink(argv[3]); | ||||||
4593 | |||||||
4594 | return 0; | ||||||
4595 | } | ||||||
4596 | |||||||
4597 | |||||||
4598 | #define VM_DELETE_USAGE"<id>@<domain>[/profile] [<uuid>]" "<id>@<domain>[/profile] [<uuid>]" | ||||||
4599 | SWITCH_STANDARD_API(voicemail_delete_api_function)static switch_status_t voicemail_delete_api_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | ||||||
4600 | { | ||||||
4601 | char *sql; | ||||||
4602 | char *id = NULL((void*)0), *domain = NULL((void*)0), *uuid = NULL((void*)0), *profile_name = "default"; | ||||||
4603 | char *p, *e = NULL((void*)0); | ||||||
4604 | vm_profile_t *profile; | ||||||
4605 | |||||||
4606 | if (zstr(cmd)_zstr(cmd)) { | ||||||
4607 | stream->write_function(stream, "Usage: %s\n", VM_DELETE_USAGE"<id>@<domain>[/profile] [<uuid>]"); | ||||||
4608 | return SWITCH_STATUS_SUCCESS; | ||||||
4609 | } | ||||||
4610 | |||||||
4611 | id = 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))); | ||||||
4612 | |||||||
4613 | if (!id) { | ||||||
4614 | stream->write_function(stream, "Allocation Error\n"); | ||||||
4615 | return SWITCH_STATUS_SUCCESS; | ||||||
4616 | } | ||||||
4617 | |||||||
4618 | if ((p = strchr(id, '@')(__extension__ (__builtin_constant_p ('@') && !__builtin_constant_p (id) && ('@') == '\0' ? (char *) __rawmemchr (id, '@' ) : __builtin_strchr (id, '@'))))) { | ||||||
4619 | *p++ = '\0'; | ||||||
4620 | domain = e = p; | ||||||
4621 | } | ||||||
4622 | |||||||
4623 | if (domain && (p = strchr(domain, '/')(__extension__ (__builtin_constant_p ('/') && !__builtin_constant_p (domain) && ('/') == '\0' ? (char *) __rawmemchr (domain , '/') : __builtin_strchr (domain, '/'))))) { | ||||||
4624 | *p++ = '\0'; | ||||||
4625 | profile_name = e = p; | ||||||
4626 | } | ||||||
4627 | |||||||
4628 | if (e && (p = strchr(e, ' ')(__extension__ (__builtin_constant_p (' ') && !__builtin_constant_p (e) && (' ') == '\0' ? (char *) __rawmemchr (e, ' ') : __builtin_strchr (e, ' '))))) { | ||||||
4629 | *p++ = '\0'; | ||||||
4630 | uuid = p; | ||||||
4631 | } | ||||||
4632 | |||||||
4633 | |||||||
4634 | if (domain && profile_name && (profile = get_profile(profile_name))) { | ||||||
4635 | |||||||
4636 | if (uuid) { | ||||||
4637 | sql = switch_mprintf("select username, domain, in_folder, file_path from voicemail_msgs where uuid='%q'", uuid); | ||||||
4638 | } else { | ||||||
4639 | sql = switch_mprintf("select username, domain, in_folder, file_path from voicemail_msgs where username='%q' and domain='%q'", id, domain); | ||||||
4640 | } | ||||||
4641 | |||||||
4642 | vm_execute_sql_callback(profile, profile->mutex, sql, api_del_callback, profile); | ||||||
4643 | switch_safe_free(sql)if (sql) {free(sql);sql=((void*)0);}; | ||||||
4644 | |||||||
4645 | if (uuid) { | ||||||
4646 | sql = switch_mprintf("delete from voicemail_msgs where uuid='%q'", uuid); | ||||||
4647 | } else { | ||||||
4648 | sql = switch_mprintf("delete from voicemail_msgs where username='%q' and domain='%q'", id, domain); | ||||||
4649 | } | ||||||
4650 | |||||||
4651 | vm_execute_sql(profile, sql, profile->mutex); | ||||||
4652 | switch_safe_free(sql)if (sql) {free(sql);sql=((void*)0);}; | ||||||
4653 | |||||||
4654 | update_mwi(profile, id, domain, "inbox", MWI_REASON_DELETE); | ||||||
4655 | |||||||
4656 | stream->write_function(stream, "%s", "+OK\n"); | ||||||
4657 | profile_rwunlock(profile); | ||||||
4658 | } else { | ||||||
4659 | stream->write_function(stream, "%s", "-ERR can't find user or profile.\n"); | ||||||
4660 | } | ||||||
4661 | |||||||
4662 | switch_safe_free(id)if (id) {free(id);id=((void*)0);}; | ||||||
4663 | |||||||
4664 | return SWITCH_STATUS_SUCCESS; | ||||||
4665 | } | ||||||
4666 | |||||||
4667 | |||||||
4668 | |||||||
4669 | |||||||
4670 | #define VM_READ_USAGE"<id>@<domain>[/profile] <read|unread> [<uuid>]" "<id>@<domain>[/profile] <read|unread> [<uuid>]" | ||||||
4671 | SWITCH_STANDARD_API(voicemail_read_api_function)static switch_status_t voicemail_read_api_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | ||||||
4672 | { | ||||||
4673 | char *sql; | ||||||
4674 | char *id = NULL((void*)0), *domain = NULL((void*)0), *uuid = NULL((void*)0), *profile_name = "default"; | ||||||
4675 | char *ru = NULL((void*)0), *p, *e = NULL((void*)0); | ||||||
4676 | vm_profile_t *profile; | ||||||
4677 | int mread = -1; | ||||||
4678 | |||||||
4679 | if (zstr(cmd)_zstr(cmd)) { | ||||||
4680 | stream->write_function(stream, "Usage: %s\n", VM_READ_USAGE"<id>@<domain>[/profile] <read|unread> [<uuid>]"); | ||||||
4681 | return SWITCH_STATUS_SUCCESS; | ||||||
4682 | } | ||||||
4683 | |||||||
4684 | id = 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))); | ||||||
4685 | |||||||
4686 | if (!id) { | ||||||
4687 | stream->write_function(stream, "Allocation failure\n"); | ||||||
4688 | return SWITCH_STATUS_SUCCESS; | ||||||
4689 | } | ||||||
4690 | |||||||
4691 | if ((p = strchr(id, '@')(__extension__ (__builtin_constant_p ('@') && !__builtin_constant_p (id) && ('@') == '\0' ? (char *) __rawmemchr (id, '@' ) : __builtin_strchr (id, '@'))))) { | ||||||
4692 | *p++ = '\0'; | ||||||
4693 | domain = e = p; | ||||||
4694 | } | ||||||
4695 | |||||||
4696 | if (domain && (p = strchr(domain, '/')(__extension__ (__builtin_constant_p ('/') && !__builtin_constant_p (domain) && ('/') == '\0' ? (char *) __rawmemchr (domain , '/') : __builtin_strchr (domain, '/'))))) { | ||||||
4697 | *p++ = '\0'; | ||||||
4698 | profile_name = e = p; | ||||||
4699 | } | ||||||
4700 | |||||||
4701 | if (e && (p = strchr(e, ' ')(__extension__ (__builtin_constant_p (' ') && !__builtin_constant_p (e) && (' ') == '\0' ? (char *) __rawmemchr (e, ' ') : __builtin_strchr (e, ' '))))) { | ||||||
4702 | *p++ = '\0'; | ||||||
4703 | ru = e = p; | ||||||
4704 | } | ||||||
4705 | |||||||
4706 | if (e && (p = strchr(e, ' ')(__extension__ (__builtin_constant_p (' ') && !__builtin_constant_p (e) && (' ') == '\0' ? (char *) __rawmemchr (e, ' ') : __builtin_strchr (e, ' '))))) { | ||||||
4707 | *p++ = '\0'; | ||||||
4708 | uuid = p; | ||||||
4709 | } | ||||||
4710 | |||||||
4711 | if (ru) { | ||||||
4712 | if (!strcasecmp(ru, "read")) { | ||||||
4713 | mread = 1; | ||||||
4714 | } else if (!strcasecmp(ru, "unread")) { | ||||||
4715 | mread = 0; | ||||||
4716 | } else { | ||||||
4717 | mread = -1; | ||||||
4718 | } | ||||||
4719 | } | ||||||
4720 | |||||||
4721 | |||||||
4722 | if (mread > -1 && domain && profile_name && (profile = get_profile(profile_name))) { | ||||||
4723 | |||||||
4724 | if (mread) { | ||||||
4725 | if (uuid) { | ||||||
4726 | sql = switch_mprintf("update voicemail_msgs set read_epoch=%ld where uuid='%q'", (long) switch_epoch_time_now(NULL((void*)0)), uuid); | ||||||
4727 | } else { | ||||||
4728 | sql = switch_mprintf("update voicemail_msgs set read_epoch=%ld where domain='%q'", (long) switch_epoch_time_now(NULL((void*)0)), domain); | ||||||
4729 | } | ||||||
4730 | } else{ | ||||||
4731 | if (uuid) { | ||||||
4732 | sql = switch_mprintf("update voicemail_msgs set read_epoch=0,flags='' where uuid='%q'", uuid); | ||||||
4733 | } else { | ||||||
4734 | sql = switch_mprintf("update voicemail_msgs set read_epoch=0,flags='' where domain='%q'", domain); | ||||||
4735 | } | ||||||
4736 | } | ||||||
4737 | |||||||
4738 | vm_execute_sql(profile, sql, profile->mutex); | ||||||
4739 | switch_safe_free(sql)if (sql) {free(sql);sql=((void*)0);}; | ||||||
4740 | |||||||
4741 | update_mwi(profile, id, domain, "inbox", MWI_REASON_READ); | ||||||
4742 | |||||||
4743 | stream->write_function(stream, "%s", "+OK\n"); | ||||||
4744 | |||||||
4745 | profile_rwunlock(profile); | ||||||
4746 | } else { | ||||||
4747 | stream->write_function(stream, "%s", "-ERR can't find user or profile.\n"); | ||||||
4748 | } | ||||||
4749 | |||||||
4750 | switch_safe_free(id)if (id) {free(id);id=((void*)0);}; | ||||||
4751 | |||||||
4752 | return SWITCH_STATUS_SUCCESS; | ||||||
4753 | } | ||||||
4754 | |||||||
4755 | |||||||
4756 | |||||||
4757 | static int api_list_callback(void *pArg, int argc, char **argv, char **columnNames) | ||||||
4758 | { | ||||||
4759 | switch_stream_handle_t *stream = (switch_stream_handle_t *) pArg; | ||||||
4760 | |||||||
4761 | if (!strcasecmp(argv[10], "xml")) { | ||||||
4762 | stream->write_function(stream, " <message>\n"); | ||||||
4763 | stream->write_function(stream, " <created_epoch>%s</created_epoch>\n", argv[0]); | ||||||
4764 | stream->write_function(stream, " <read_epoch>%s</read_epoch>\n", argv[1]); | ||||||
4765 | stream->write_function(stream, " <username>%s</username>\n", argv[2]); | ||||||
4766 | stream->write_function(stream, " <domain>%s</domain>\n", argv[3]); | ||||||
4767 | stream->write_function(stream, " <folder>%s</folder>\n", argv[4]); | ||||||
4768 | stream->write_function(stream, " <path>%s</path>\n", argv[5]); | ||||||
4769 | stream->write_function(stream, " <uuid>%s</uuid>\n", argv[6]); | ||||||
4770 | stream->write_function(stream, " <cid-name>%s</cid-name>\n", argv[7]); | ||||||
4771 | stream->write_function(stream, " <cid-number>%s</cid-number>\n", argv[8]); | ||||||
4772 | stream->write_function(stream, " <message-len>%s</message-len>\n", argv[9]); | ||||||
4773 | stream->write_function(stream, " </message>\n"); | ||||||
4774 | } else { | ||||||
4775 | stream->write_function(stream, "%s:%s:%s:%s:%s:%s:%s:%s:%s:%s\n", argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9]); | ||||||
4776 | } | ||||||
4777 | |||||||
4778 | return 0; | ||||||
4779 | } | ||||||
4780 | |||||||
4781 | |||||||
4782 | #define VM_LIST_USAGE"<id>@<domain>[/profile] [xml]" "<id>@<domain>[/profile] [xml]" | ||||||
4783 | SWITCH_STANDARD_API(voicemail_list_api_function)static switch_status_t voicemail_list_api_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | ||||||
4784 | { | ||||||
4785 | char *sql; | ||||||
4786 | char *id = NULL((void*)0), *uuid = NULL((void*)0), *domain = NULL((void*)0), *format = "text", *profile_name = "default"; | ||||||
4787 | char *p, *e = NULL((void*)0); | ||||||
4788 | vm_profile_t *profile; | ||||||
4789 | |||||||
4790 | if (zstr(cmd)_zstr(cmd)) { | ||||||
4791 | stream->write_function(stream, "Usage: %s\n", VM_LIST_USAGE"<id>@<domain>[/profile] [xml]"); | ||||||
4792 | return SWITCH_STATUS_SUCCESS; | ||||||
4793 | } | ||||||
4794 | |||||||
4795 | id = 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))); | ||||||
4796 | |||||||
4797 | if (!id) { | ||||||
4798 | stream->write_function(stream, "Allocation Error\n"); | ||||||
4799 | return SWITCH_STATUS_SUCCESS; | ||||||
4800 | } | ||||||
4801 | |||||||
4802 | if ((p = strchr(id, '@')(__extension__ (__builtin_constant_p ('@') && !__builtin_constant_p (id) && ('@') == '\0' ? (char *) __rawmemchr (id, '@' ) : __builtin_strchr (id, '@'))))) { | ||||||
4803 | *p++ = '\0'; | ||||||
4804 | domain = e = p; | ||||||
4805 | } | ||||||
4806 | |||||||
4807 | if (domain && (p = strchr(domain, '/')(__extension__ (__builtin_constant_p ('/') && !__builtin_constant_p (domain) && ('/') == '\0' ? (char *) __rawmemchr (domain , '/') : __builtin_strchr (domain, '/'))))) { | ||||||
4808 | *p++ = '\0'; | ||||||
4809 | profile_name = e = p; | ||||||
4810 | } | ||||||
4811 | |||||||
4812 | if (e && (p = strchr(e, ' ')(__extension__ (__builtin_constant_p (' ') && !__builtin_constant_p (e) && (' ') == '\0' ? (char *) __rawmemchr (e, ' ') : __builtin_strchr (e, ' '))))) { | ||||||
4813 | *p++ = '\0'; | ||||||
4814 | format = e = p; | ||||||
4815 | } | ||||||
4816 | |||||||
4817 | if (e && (p = strchr(e, ' ')(__extension__ (__builtin_constant_p (' ') && !__builtin_constant_p (e) && (' ') == '\0' ? (char *) __rawmemchr (e, ' ') : __builtin_strchr (e, ' '))))) { | ||||||
4818 | *p++ = '\0'; | ||||||
4819 | uuid = p; | ||||||
4820 | } | ||||||
4821 | |||||||
4822 | if (domain && profile_name && (profile = get_profile(profile_name))) { | ||||||
4823 | if (uuid) { | ||||||
4824 | sql = switch_mprintf("select created_epoch, read_epoch, username, domain, in_folder, file_path, uuid, cid_name, cid_number, message_len, " | ||||||
4825 | "'%q' from voicemail_msgs where username='%q' and domain='%q' and uuid='%q'", | ||||||
4826 | format, id, domain, uuid); | ||||||
4827 | } else { | ||||||
4828 | sql = switch_mprintf("select created_epoch, read_epoch, username, domain, in_folder, file_path, uuid, cid_name, cid_number, message_len, " | ||||||
4829 | "'%q' from voicemail_msgs where username='%q' and domain='%q'", | ||||||
4830 | format, id, domain); | ||||||
4831 | } | ||||||
4832 | |||||||
4833 | if (!strcasecmp(format, "xml")) { | ||||||
4834 | stream->write_function(stream, "<voicemail>\n"); | ||||||
4835 | } | ||||||
4836 | |||||||
4837 | vm_execute_sql_callback(profile, profile->mutex, sql, api_list_callback, stream); | ||||||
4838 | switch_safe_free(sql)if (sql) {free(sql);sql=((void*)0);}; | ||||||
4839 | |||||||
4840 | if (!strcasecmp(format, "xml")) { | ||||||
4841 | stream->write_function(stream, "</voicemail>\n"); | ||||||
4842 | } | ||||||
4843 | |||||||
4844 | profile_rwunlock(profile); | ||||||
4845 | } else { | ||||||
4846 | stream->write_function(stream, "%s", "-ERR can't find user or profile.\n"); | ||||||
4847 | } | ||||||
4848 | |||||||
4849 | switch_safe_free(id)if (id) {free(id);id=((void*)0);}; | ||||||
4850 | |||||||
4851 | return SWITCH_STATUS_SUCCESS; | ||||||
4852 | } | ||||||
4853 | |||||||
4854 | #define VOICEMAIL_SYNTAX"rss [<host> <port> <uri> <user> <domain>] | [load|unload|reload] <profile> [reloadxml]" "rss [<host> <port> <uri> <user> <domain>] | [load|unload|reload] <profile> [reloadxml]" | ||||||
4855 | SWITCH_STANDARD_API(voicemail_api_function)static switch_status_t voicemail_api_function ( const char *cmd , switch_core_session_t *session, switch_stream_handle_t *stream ) | ||||||
4856 | { | ||||||
4857 | char *mydata = NULL((void*)0), *argv[6]; | ||||||
4858 | char *host = NULL((void*)0), *port = NULL((void*)0), *uri = NULL((void*)0); | ||||||
4859 | char *user = NULL((void*)0), *domain = NULL((void*)0); | ||||||
4860 | int ct = 0; | ||||||
4861 | vm_profile_t *profile = NULL((void*)0); | ||||||
4862 | char *path_info = NULL((void*)0); | ||||||
4863 | int rss = 0, xarg = 0; | ||||||
4864 | switch_hash_index_t *hi; | ||||||
4865 | void *val = NULL((void*)0); | ||||||
4866 | switch_xml_t xml_root; | ||||||
4867 | const char *err; | ||||||
4868 | int argc = 0; | ||||||
4869 | |||||||
4870 | if (session) { | ||||||
4871 | return SWITCH_STATUS_FALSE; | ||||||
4872 | } | ||||||
4873 | |||||||
4874 | if (stream->param_event) { | ||||||
4875 | host = switch_event_get_header(stream->param_event, "http-host")switch_event_get_header_idx(stream->param_event, "http-host" , -1); | ||||||
4876 | port = switch_event_get_header(stream->param_event, "http-port")switch_event_get_header_idx(stream->param_event, "http-port" , -1); | ||||||
4877 | uri = switch_event_get_header(stream->param_event, "http-uri")switch_event_get_header_idx(stream->param_event, "http-uri" , -1); | ||||||
4878 | user = switch_event_get_header(stream->param_event, "freeswitch-user")switch_event_get_header_idx(stream->param_event, "freeswitch-user" , -1); | ||||||
4879 | domain = switch_event_get_header(stream->param_event, "freeswitch-domain")switch_event_get_header_idx(stream->param_event, "freeswitch-domain" , -1); | ||||||
4880 | path_info = switch_event_get_header(stream->param_event, "http-path-info")switch_event_get_header_idx(stream->param_event, "http-path-info" , -1); | ||||||
4881 | } | ||||||
4882 | |||||||
4883 | if (!zstr(cmd)_zstr(cmd)) { | ||||||
4884 | 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))); | ||||||
4885 | switch_assert(mydata)((mydata) ? (void) (0) : __assert_fail ("mydata", "mod_voicemail.c" , 4885, __PRETTY_FUNCTION__)); | ||||||
4886 | argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | ||||||
4887 | } | ||||||
4888 | |||||||
4889 | if (argc > 0) { | ||||||
4890 | if (!strcasecmp(argv[0], "rss")) { | ||||||
4891 | rss++; | ||||||
4892 | xarg++; | ||||||
4893 | } else if (argc > 1 && !strcasecmp(argv[0], "load")) { | ||||||
4894 | if (argc > 2 && !strcasecmp(argv[2], "reloadxml")) { | ||||||
4895 | if ((xml_root = switch_xml_open_root(1, &err))) { | ||||||
4896 | switch_xml_free(xml_root); | ||||||
4897 | } | ||||||
4898 | stream->write_function(stream, "Reload XML [%s]\n", err); | ||||||
4899 | } | ||||||
4900 | if ((profile = get_profile(argv[1]))) { | ||||||
4901 | profile_rwunlock(profile); | ||||||
4902 | } | ||||||
4903 | stream->write_function(stream, "+OK load complete\n"); | ||||||
4904 | goto done; | ||||||
4905 | } else if (argc > 1 && !strcasecmp(argv[0], "unload")) { | ||||||
4906 | destroy_profile(argv[1], SWITCH_FALSE); | ||||||
4907 | stream->write_function(stream, "+OK unload complete\n"); | ||||||
4908 | goto done; | ||||||
4909 | } else if (argc > 1 && !strcasecmp(argv[0], "reload")) { | ||||||
4910 | destroy_profile(argv[1], SWITCH_FALSE); | ||||||
4911 | if (argc > 2 && !strcasecmp(argv[2], "reloadxml")) { | ||||||
4912 | if ((xml_root = switch_xml_open_root(1, &err))) { | ||||||
4913 | switch_xml_free(xml_root); | ||||||
4914 | } | ||||||
4915 | stream->write_function(stream, "Reload XML [%s]\n", err); | ||||||
4916 | } | ||||||
4917 | if ((profile = get_profile(argv[1]))) { | ||||||
4918 | profile_rwunlock(profile); | ||||||
4919 | } | ||||||
4920 | stream->write_function(stream, "+OK reload complete\n"); | ||||||
4921 | goto done; | ||||||
4922 | |||||||
4923 | } else if (!strcasecmp(argv[0], "status")) { | ||||||
4924 | stream->write_function(stream, "============================\n"); | ||||||
4925 | switch_mutex_lock(globals.mutex); | ||||||
4926 | for (hi = switch_core_hash_first(globals.profile_hash)switch_core_hash_first_iter(globals.profile_hash, ((void*)0)); hi; hi = switch_core_hash_next(&hi)) { | ||||||
4927 | switch_core_hash_this(hi, NULL((void*)0), NULL((void*)0), &val); | ||||||
4928 | profile = (vm_profile_t *) val; | ||||||
4929 | stream->write_function(stream, "Profile: %s\n", profile->name); | ||||||
4930 | } | ||||||
4931 | switch_mutex_unlock(globals.mutex); | ||||||
4932 | stream->write_function(stream, "============================\n"); | ||||||
4933 | goto done; | ||||||
4934 | } | ||||||
4935 | } | ||||||
4936 | |||||||
4937 | if (!host) { | ||||||
4938 | if (argc - rss < 5) { | ||||||
4939 | goto error; | ||||||
4940 | } | ||||||
4941 | host = argv[xarg++]; | ||||||
4942 | port = argv[xarg++]; | ||||||
4943 | uri = argv[xarg++]; | ||||||
4944 | user = argv[xarg++]; | ||||||
4945 | domain = argv[xarg++]; | ||||||
4946 | } | ||||||
4947 | |||||||
4948 | if (!(host && port && uri && user && domain)) { | ||||||
4949 | goto error; | ||||||
4950 | } | ||||||
4951 | |||||||
4952 | if (!(profile = get_profile(domain))) { | ||||||
4953 | profile = get_profile("default"); | ||||||
4954 | } | ||||||
4955 | |||||||
4956 | if (!profile) { | ||||||
4957 | switch_hash_index_t *index; | ||||||
4958 | void *value; | ||||||
4959 | |||||||
4960 | switch_mutex_lock(globals.mutex); | ||||||
4961 | for (index = switch_core_hash_first(globals.profile_hash)switch_core_hash_first_iter(globals.profile_hash, ((void*)0)); index; index = switch_core_hash_next(&index)) { | ||||||
4962 | switch_core_hash_this(index, NULL((void*)0), NULL((void*)0), &value); | ||||||
4963 | profile = (vm_profile_t *) value; | ||||||
4964 | if (profile) { | ||||||
4965 | switch_thread_rwlock_rdlock(profile->rwlock); | ||||||
4966 | break; | ||||||
4967 | } | ||||||
4968 | } | ||||||
4969 | switch_safe_free(index)if (index) {free(index);index=((void*)0);}; | ||||||
4970 | switch_mutex_unlock(globals.mutex); | ||||||
4971 | } | ||||||
4972 | |||||||
4973 | if (!profile) { | ||||||
4974 | stream->write_function(stream, "Can't find profile.\n"); | ||||||
4975 | goto error; | ||||||
4976 | } | ||||||
4977 | |||||||
4978 | if (path_info) { | ||||||
4979 | if (!strncasecmp(path_info, "get/", 4)) { | ||||||
4980 | do_play(profile, user, domain, path_info + 4, stream); | ||||||
4981 | } else if (!strncasecmp(path_info, "del/", 4)) { | ||||||
4982 | do_del(profile, user, domain, path_info + 4, stream); | ||||||
4983 | } else if (!strncasecmp(path_info, "web", 3)) { | ||||||
4984 | do_web(profile, user, domain, host, port, uri, stream); | ||||||
4985 | } | ||||||
4986 | } | ||||||
4987 | |||||||
4988 | if (rss || (path_info && !strncasecmp(path_info, "rss", 3))) { | ||||||
4989 | do_rss(profile, user, domain, host, port, uri, stream); | ||||||
4990 | } | ||||||
4991 | |||||||
4992 | profile_rwunlock(profile); | ||||||
4993 | goto done; | ||||||
4994 | |||||||
4995 | error: | ||||||
4996 | if (host) { | ||||||
4997 | if (!ct) { | ||||||
4998 | stream->write_function(stream, "Content-type: text/html\n\n<h2>"); | ||||||
4999 | } | ||||||
5000 | } | ||||||
5001 | stream->write_function(stream, "Error: %s\n", VOICEMAIL_SYNTAX"rss [<host> <port> <uri> <user> <domain>] | [load|unload|reload] <profile> [reloadxml]"); | ||||||
5002 | |||||||
5003 | done: | ||||||
5004 | switch_safe_free(mydata)if (mydata) {free(mydata);mydata=((void*)0);}; | ||||||
5005 | return SWITCH_STATUS_SUCCESS; | ||||||
5006 | } | ||||||
5007 | |||||||
5008 | struct msg_get_callback { | ||||||
5009 | switch_event_t *my_params; | ||||||
5010 | }; | ||||||
5011 | typedef struct msg_get_callback msg_get_callback_t; | ||||||
5012 | |||||||
5013 | static int message_get_callback(void *pArg, int argc, char **argv, char **columnNames) | ||||||
5014 | { | ||||||
5015 | msg_get_callback_t *cbt = (msg_get_callback_t *) pArg; | ||||||
5016 | |||||||
5017 | switch_event_add_header(cbt->my_params, SWITCH_STACK_BOTTOM, "VM-Message-Received-Epoch", "%s", argv[0]); | ||||||
5018 | switch_event_add_header(cbt->my_params, SWITCH_STACK_BOTTOM, "VM-Message-Read-Epoch", "%s", argv[1]); | ||||||
5019 | /* switch_event_add_header(cbt->my_params, SWITCH_STACK_BOTTOM, user, argv[2], 255); */ | ||||||
5020 | /* switch_event_add_header(cbt->my_params, SWITCH_STACK_BOTTOM, domain, argv[3], 255); */ | ||||||
5021 | switch_event_add_header(cbt->my_params, SWITCH_STACK_BOTTOM, "VM-Message-UUID", "%s", argv[4]); | ||||||
5022 | switch_event_add_header(cbt->my_params, SWITCH_STACK_BOTTOM, "VM-Message-Caller-Name", "%s", argv[5]); | ||||||
5023 | switch_event_add_header(cbt->my_params, SWITCH_STACK_BOTTOM, "VM-Message-Caller-Number", "%s", argv[6]); | ||||||
5024 | switch_event_add_header(cbt->my_params, SWITCH_STACK_BOTTOM, "VM-Message-Folder", "%s", argv[7]); | ||||||
5025 | switch_event_add_header(cbt->my_params, SWITCH_STACK_BOTTOM, "VM-Message-File-Path", "%s", argv[8]); | ||||||
5026 | switch_event_add_header(cbt->my_params, SWITCH_STACK_BOTTOM, "VM-Message-Duration", "%s", argv[9]); | ||||||
5027 | switch_event_add_header(cbt->my_params, SWITCH_STACK_BOTTOM, "VM-Message-Flags", "%s", argv[10]); | ||||||
5028 | switch_event_add_header(cbt->my_params, SWITCH_STACK_BOTTOM, "VM-Message-Read-Flags", "%s", argv[11]); | ||||||
5029 | switch_event_add_header(cbt->my_params, SWITCH_STACK_BOTTOM, "VM-Message-Forwarded-By", "%s", argv[12]); | ||||||
5030 | |||||||
5031 | return 0; | ||||||
5032 | } | ||||||
5033 | |||||||
5034 | struct msg_lst_callback { | ||||||
5035 | char *buf; | ||||||
5036 | size_t len; | ||||||
5037 | switch_event_t *my_params; | ||||||
5038 | }; | ||||||
5039 | typedef struct msg_lst_callback msg_lst_callback_t; | ||||||
5040 | |||||||
5041 | static int message_list_callback(void *pArg, int argc, char **argv, char **columnNames) | ||||||
5042 | { | ||||||
5043 | msg_lst_callback_t *cbt = (msg_lst_callback_t *) pArg; | ||||||
5044 | char *varname = NULL((void*)0); | ||||||
5045 | /* Message # never start with 0 */ | ||||||
5046 | varname = switch_mprintf("VM-List-Message-%ld-UUID", ++cbt->len); | ||||||
5047 | switch_event_add_header(cbt->my_params, SWITCH_STACK_BOTTOM, varname, "%s", argv[0]); | ||||||
5048 | switch_safe_free(varname)if (varname) {free(varname);varname=((void*)0);}; | ||||||
5049 | return 0; | ||||||
5050 | } | ||||||
5051 | |||||||
5052 | static int message_purge_callback(void *pArg, int argc, char **argv, char **columnNames) | ||||||
5053 | { | ||||||
5054 | const char *profile_name = argv[0]; | ||||||
5055 | const char *uuid = argv[1]; | ||||||
5056 | const char *id = argv[2]; | ||||||
5057 | const char *domain = argv[3]; | ||||||
5058 | const char *file_path = argv[4]; | ||||||
5059 | char *sql; | ||||||
5060 | vm_profile_t *profile = get_profile(profile_name); | ||||||
5061 | |||||||
5062 | if (unlink(file_path) != 0) { | ||||||
5063 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 5063, ((void*)0), SWITCH_LOG_WARNING, "Failed to delete file [%s]\n", file_path); | ||||||
5064 | } else { | ||||||
5065 | sql = switch_mprintf("DELETE FROM voicemail_msgs WHERE username='%q' AND domain='%q' AND uuid = '%q'", id, domain, uuid); | ||||||
5066 | vm_execute_sql(profile, sql, profile->mutex); | ||||||
5067 | switch_safe_free(sql)if (sql) {free(sql);sql=((void*)0);}; | ||||||
5068 | } | ||||||
5069 | profile_rwunlock(profile); | ||||||
5070 | |||||||
5071 | return 0; | ||||||
5072 | } | ||||||
5073 | |||||||
5074 | /* Preference API */ | ||||||
5075 | #define VM_FSDB_PREF_GREETING_SET_USAGE"<profile> <domain> <user> <slot> [file-path]" "<profile> <domain> <user> <slot> [file-path]" | ||||||
5076 | SWITCH_STANDARD_API(vm_fsdb_pref_greeting_set_function)static switch_status_t vm_fsdb_pref_greeting_set_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | ||||||
5077 | { | ||||||
5078 | int slot = -1; | ||||||
5079 | const char *file_path = NULL((void*)0); | ||||||
5080 | char *sql = NULL((void*)0); | ||||||
5081 | char res[254] = ""; | ||||||
5082 | |||||||
5083 | char *id = NULL((void*)0), *domain = NULL((void*)0), *profile_name = NULL((void*)0); | ||||||
5084 | vm_profile_t *profile = NULL((void*)0); | ||||||
5085 | |||||||
5086 | char *argv[6] = { 0 }; | ||||||
5087 | char *mycmd = NULL((void*)0); | ||||||
5088 | |||||||
5089 | switch_memory_pool_t *pool; | ||||||
5090 | |||||||
5091 | switch_core_new_memory_pool(&pool)switch_core_perform_new_memory_pool(&pool, "mod_voicemail.c" , (const char *)__func__, 5091); | ||||||
5092 | |||||||
5093 | if (!zstr(cmd)_zstr(cmd)) { | ||||||
5094 | mycmd = switch_core_strdup(pool, cmd)switch_core_perform_strdup(pool, cmd, "mod_voicemail.c", (const char *)__func__, 5094); | ||||||
5095 | switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | ||||||
5096 | } | ||||||
5097 | |||||||
5098 | if (argv[0]) | ||||||
5099 | profile_name = argv[0]; | ||||||
5100 | if (argv[1]) | ||||||
5101 | domain = argv[1]; | ||||||
5102 | if (argv[2]) | ||||||
5103 | id = argv[2]; | ||||||
5104 | if (argv[3]) | ||||||
5105 | slot = atoi(argv[3]); | ||||||
5106 | if (argv[4]) | ||||||
5107 | file_path = argv[4]; | ||||||
5108 | |||||||
5109 | if (!profile_name || !domain || !id || !slot) { | ||||||
5110 | stream->write_function(stream, "-ERR Missing Arguments\n"); | ||||||
5111 | goto done; | ||||||
5112 | } | ||||||
5113 | |||||||
5114 | if (!(profile = get_profile(profile_name))) { | ||||||
5115 | stream->write_function(stream, "-ERR Profile not found\n"); | ||||||
5116 | goto done; | ||||||
5117 | } else { | ||||||
5118 | char *dir_path = switch_core_sprintf(pool, "%s%svoicemail%s%s%s%s%s%s", SWITCH_GLOBAL_dirs.storage_dir, | ||||||
5119 | SWITCH_PATH_SEPARATOR"/", | ||||||
5120 | SWITCH_PATH_SEPARATOR"/", | ||||||
5121 | profile->name, SWITCH_PATH_SEPARATOR"/", domain, SWITCH_PATH_SEPARATOR"/", id); | ||||||
5122 | char *final_file_path = switch_core_sprintf(pool, "%s%sgreeting_%d.%s", dir_path, SWITCH_PATH_SEPARATOR"/", slot, profile->file_ext); | ||||||
5123 | |||||||
5124 | switch_dir_make_recursive(dir_path, SWITCH_DEFAULT_DIR_PERMS0x0400 | 0x0200 | 0x0100 | 0x0040 | 0x0010, pool); | ||||||
5125 | |||||||
5126 | if (file_path) { | ||||||
5127 | if (switch_file_exists(file_path, pool) != SWITCH_STATUS_SUCCESS) { | ||||||
5128 | stream->write_function(stream, "-ERR Filename doesn't exist\n"); | ||||||
5129 | profile_rwunlock(profile); | ||||||
5130 | goto done; | ||||||
5131 | } | ||||||
5132 | |||||||
5133 | switch_file_rename(file_path, final_file_path, pool); | ||||||
5134 | } | ||||||
5135 | |||||||
5136 | if (switch_file_exists(final_file_path, pool) == SWITCH_STATUS_SUCCESS) { | ||||||
5137 | |||||||
5138 | sql = switch_mprintf("SELECT count(*) FROM voicemail_prefs WHERE username = '%q' AND domain = '%q'", id, domain); | ||||||
5139 | vm_execute_sql2str(profile, profile->mutex, sql, res, sizeof(res)); | ||||||
5140 | switch_safe_free(sql)if (sql) {free(sql);sql=((void*)0);}; | ||||||
5141 | |||||||
5142 | if (atoi(res) == 0) { | ||||||
5143 | sql = switch_mprintf("INSERT INTO voicemail_prefs (username, domain, greeting_path) VALUES('%q', '%q', '%q')", id, domain, final_file_path); | ||||||
5144 | } else { | ||||||
5145 | sql = switch_mprintf("UPDATE voicemail_prefs SET greeting_path = '%q' WHERE username = '%q' AND domain = '%q'", final_file_path, id, domain); | ||||||
5146 | } | ||||||
5147 | vm_execute_sql(profile, sql, profile->mutex); | ||||||
5148 | switch_safe_free(sql)if (sql) {free(sql);sql=((void*)0);}; | ||||||
5149 | } else { | ||||||
5150 | stream->write_function(stream, "-ERR Recording doesn't exist [%s]\n", final_file_path); | ||||||
5151 | } | ||||||
5152 | profile_rwunlock(profile); | ||||||
5153 | } | ||||||
5154 | |||||||
5155 | stream->write_function(stream, "-OK\n"); | ||||||
5156 | done: | ||||||
5157 | switch_core_destroy_memory_pool(&pool)switch_core_perform_destroy_memory_pool(&pool, "mod_voicemail.c" , (const char *)__func__, 5157); | ||||||
5158 | return SWITCH_STATUS_SUCCESS; | ||||||
5159 | } | ||||||
5160 | |||||||
5161 | #define VM_FSDB_PREF_GREETING_GET_USAGE"<format> <profile> <domain> <user> [slot]" "<format> <profile> <domain> <user> [slot]" | ||||||
5162 | SWITCH_STANDARD_API(vm_fsdb_pref_greeting_get_function)static switch_status_t vm_fsdb_pref_greeting_get_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | ||||||
5163 | { | ||||||
5164 | /* int slot = -1; not implemented yet */ | ||||||
5165 | char *sql = NULL((void*)0); | ||||||
5166 | char res[254] = ""; | ||||||
5167 | |||||||
5168 | char *id = NULL((void*)0), *domain = NULL((void*)0), *profile_name = NULL((void*)0); | ||||||
5169 | vm_profile_t *profile = NULL((void*)0); | ||||||
5170 | |||||||
5171 | char *argv[6] = { 0 }; | ||||||
5172 | char *mycmd = NULL((void*)0); | ||||||
5173 | |||||||
5174 | switch_memory_pool_t *pool; | ||||||
5175 | |||||||
5176 | switch_core_new_memory_pool(&pool)switch_core_perform_new_memory_pool(&pool, "mod_voicemail.c" , (const char *)__func__, 5176); | ||||||
5177 | |||||||
5178 | if (!zstr(cmd)_zstr(cmd)) { | ||||||
5179 | mycmd = switch_core_strdup(pool, cmd)switch_core_perform_strdup(pool, cmd, "mod_voicemail.c", (const char *)__func__, 5179); | ||||||
5180 | switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | ||||||
5181 | } | ||||||
5182 | |||||||
5183 | if (argv[1]) | ||||||
5184 | profile_name = argv[1]; | ||||||
5185 | if (argv[2]) | ||||||
5186 | domain = argv[2]; | ||||||
5187 | if (argv[3]) | ||||||
5188 | id = argv[3]; | ||||||
5189 | /* if (argv[4]) | ||||||
5190 | slot = atoi(argv[4]); | ||||||
5191 | not implemented yet | ||||||
5192 | */ | ||||||
5193 | |||||||
5194 | if (!profile_name || !domain || !id) { | ||||||
5195 | stream->write_function(stream, "-ERR Missing Arguments\n"); | ||||||
5196 | goto done; | ||||||
5197 | } | ||||||
5198 | |||||||
5199 | if (!(profile = get_profile(profile_name))) { | ||||||
5200 | stream->write_function(stream, "-ERR Profile not found\n"); | ||||||
5201 | goto done; | ||||||
5202 | } | ||||||
5203 | sql = switch_mprintf("select greeting_path from voicemail_prefs WHERE domain = '%q' AND username = '%q'", domain, id); | ||||||
5204 | |||||||
5205 | vm_execute_sql2str(profile, profile->mutex, sql, res, sizeof(res)); | ||||||
5206 | |||||||
5207 | switch_safe_free(sql)if (sql) {free(sql);sql=((void*)0);}; | ||||||
5208 | |||||||
5209 | profile_rwunlock(profile); | ||||||
5210 | |||||||
5211 | /* TODO If no slot requested, returned currently selected and figure out the slot number from the file name. | ||||||
5212 | * IF slot provided, check if file exist, check if it currently selected */ | ||||||
5213 | if (zstr(res)_zstr(res)) { | ||||||
5214 | stream->write_function(stream, "-ERR No greeting found\n"); | ||||||
5215 | } else { | ||||||
5216 | switch_event_t *my_params = NULL((void*)0); | ||||||
5217 | char *ebuf = NULL((void*)0); | ||||||
5218 | |||||||
5219 | switch_event_create(&my_params, SWITCH_EVENT_REQUEST_PARAMS)switch_event_create_subclass_detailed("mod_voicemail.c", (const char * )(const char *)__func__, 5219, &my_params, SWITCH_EVENT_REQUEST_PARAMS , ((void*)0)); | ||||||
5220 | switch_event_add_header(my_params, SWITCH_STACK_BOTTOM, "VM-Preference-Greeting-File-Path", "%s", res); | ||||||
5221 | switch_event_add_header(my_params, SWITCH_STACK_BOTTOM, "VM-Preference-Greeting-Slot", "%s", "Not Implemented yet"); | ||||||
5222 | switch_event_add_header(my_params, SWITCH_STACK_BOTTOM, "VM-Preference-Greeting-Selected", "%s", "True"); | ||||||
5223 | switch_event_serialize_json(my_params, &ebuf); | ||||||
5224 | switch_event_destroy(&my_params); | ||||||
5225 | |||||||
5226 | stream->write_function(stream, "%s", ebuf); | ||||||
5227 | switch_safe_free(ebuf)if (ebuf) {free(ebuf);ebuf=((void*)0);}; | ||||||
5228 | |||||||
5229 | } | ||||||
5230 | done: | ||||||
5231 | switch_core_destroy_memory_pool(&pool)switch_core_perform_destroy_memory_pool(&pool, "mod_voicemail.c" , (const char *)__func__, 5231); | ||||||
5232 | return SWITCH_STATUS_SUCCESS; | ||||||
5233 | } | ||||||
5234 | |||||||
5235 | #define VM_FSDB_PREF_RECNAME_SET_USAGE"<profile> <domain> <user> <file-path>" "<profile> <domain> <user> <file-path>" | ||||||
5236 | SWITCH_STANDARD_API(vm_fsdb_pref_recname_set_function)static switch_status_t vm_fsdb_pref_recname_set_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | ||||||
5237 | { | ||||||
5238 | const char *file_path = NULL((void*)0); | ||||||
5239 | |||||||
5240 | char *sql = NULL((void*)0); | ||||||
5241 | char res[254] = ""; | ||||||
5242 | |||||||
5243 | char *id = NULL((void*)0), *domain = NULL((void*)0), *profile_name = NULL((void*)0); | ||||||
5244 | vm_profile_t *profile = NULL((void*)0); | ||||||
5245 | |||||||
5246 | char *argv[6] = { 0 }; | ||||||
5247 | char *mycmd = NULL((void*)0); | ||||||
5248 | |||||||
5249 | switch_memory_pool_t *pool; | ||||||
5250 | |||||||
5251 | switch_core_new_memory_pool(&pool)switch_core_perform_new_memory_pool(&pool, "mod_voicemail.c" , (const char *)__func__, 5251); | ||||||
5252 | |||||||
5253 | if (!zstr(cmd)_zstr(cmd)) { | ||||||
5254 | mycmd = switch_core_strdup(pool, cmd)switch_core_perform_strdup(pool, cmd, "mod_voicemail.c", (const char *)__func__, 5254); | ||||||
5255 | switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | ||||||
5256 | } | ||||||
5257 | |||||||
5258 | if (argv[0]) | ||||||
5259 | profile_name = argv[0]; | ||||||
5260 | if (argv[1]) | ||||||
5261 | domain = argv[1]; | ||||||
5262 | if (argv[2]) | ||||||
5263 | id = argv[2]; | ||||||
5264 | if (argv[3]) | ||||||
5265 | file_path = argv[3]; | ||||||
5266 | |||||||
5267 | if (!profile_name || !domain || !id || !file_path) { | ||||||
5268 | stream->write_function(stream, "-ERR Missing Arguments\n"); | ||||||
5269 | goto done; | ||||||
5270 | } | ||||||
5271 | |||||||
5272 | if (!(profile = get_profile(profile_name))) { | ||||||
5273 | stream->write_function(stream, "-ERR Profile not found\n"); | ||||||
5274 | goto done; | ||||||
5275 | } | ||||||
5276 | |||||||
5277 | if (switch_file_exists(file_path, pool) != SWITCH_STATUS_SUCCESS) { | ||||||
5278 | stream->write_function(stream, "-ERR Filename doesn't exist\n"); | ||||||
5279 | profile_rwunlock(profile); | ||||||
5280 | goto done; | ||||||
5281 | } | ||||||
5282 | |||||||
5283 | sql = switch_mprintf("SELECT count(*) FROM voicemail_prefs WHERE username = '%q' AND domain = '%q'", id, domain); | ||||||
5284 | vm_execute_sql2str(profile, profile->mutex, sql, res, sizeof(res)); | ||||||
5285 | switch_safe_free(sql)if (sql) {free(sql);sql=((void*)0);}; | ||||||
5286 | |||||||
5287 | { | ||||||
5288 | char *dir_path = switch_core_sprintf(pool, "%s%svoicemail%s%s%s%s%s%s", SWITCH_GLOBAL_dirs.storage_dir, | ||||||
5289 | SWITCH_PATH_SEPARATOR"/", | ||||||
5290 | SWITCH_PATH_SEPARATOR"/", | ||||||
5291 | profile->name, SWITCH_PATH_SEPARATOR"/", domain, SWITCH_PATH_SEPARATOR"/", id); | ||||||
5292 | char *final_file_path = switch_core_sprintf(pool, "%s%srecorded_name.%s", dir_path, SWITCH_PATH_SEPARATOR"/", profile->file_ext); | ||||||
5293 | |||||||
5294 | switch_dir_make_recursive(dir_path, SWITCH_DEFAULT_DIR_PERMS0x0400 | 0x0200 | 0x0100 | 0x0040 | 0x0010, pool); | ||||||
5295 | |||||||
5296 | if (switch_file_exists(file_path, pool) != SWITCH_STATUS_SUCCESS) { | ||||||
5297 | stream->write_function(stream, "-ERR Filename doesn't exist\n"); | ||||||
5298 | profile_rwunlock(profile); | ||||||
5299 | goto done; | ||||||
5300 | } | ||||||
5301 | |||||||
5302 | switch_file_rename(file_path, final_file_path, pool); | ||||||
5303 | |||||||
5304 | if (atoi(res) == 0) { | ||||||
5305 | sql = switch_mprintf("INSERT INTO voicemail_prefs (username, domain, name_path) VALUES('%q', '%q', '%q')", id, domain, final_file_path); | ||||||
5306 | } else { | ||||||
5307 | sql = switch_mprintf("UPDATE voicemail_prefs SET name_path = '%q' WHERE username = '%q' AND domain = '%q'", final_file_path, id, domain); | ||||||
5308 | } | ||||||
5309 | vm_execute_sql(profile, sql, profile->mutex); | ||||||
5310 | switch_safe_free(sql)if (sql) {free(sql);sql=((void*)0);}; | ||||||
5311 | |||||||
5312 | |||||||
5313 | } | ||||||
5314 | profile_rwunlock(profile); | ||||||
5315 | stream->write_function(stream, "-OK\n"); | ||||||
5316 | done: | ||||||
5317 | switch_core_destroy_memory_pool(&pool)switch_core_perform_destroy_memory_pool(&pool, "mod_voicemail.c" , (const char *)__func__, 5317); | ||||||
5318 | return SWITCH_STATUS_SUCCESS; | ||||||
5319 | } | ||||||
5320 | |||||||
5321 | #define VM_FSDB_PREF_PASSWORD_SET_USAGE"<profile> <domain> <user> <password>" "<profile> <domain> <user> <password>" | ||||||
5322 | SWITCH_STANDARD_API(vm_fsdb_pref_password_set_function)static switch_status_t vm_fsdb_pref_password_set_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | ||||||
5323 | { | ||||||
5324 | const char *password = NULL((void*)0); | ||||||
5325 | |||||||
5326 | char *sql = NULL((void*)0); | ||||||
5327 | char res[254] = ""; | ||||||
5328 | |||||||
5329 | const char *id = NULL((void*)0), *domain = NULL((void*)0), *profile_name = NULL((void*)0); | ||||||
5330 | vm_profile_t *profile = NULL((void*)0); | ||||||
5331 | |||||||
5332 | char *argv[6] = { 0 }; | ||||||
5333 | char *mycmd = NULL((void*)0); | ||||||
5334 | |||||||
5335 | switch_memory_pool_t *pool; | ||||||
5336 | |||||||
5337 | switch_core_new_memory_pool(&pool)switch_core_perform_new_memory_pool(&pool, "mod_voicemail.c" , (const char *)__func__, 5337); | ||||||
5338 | |||||||
5339 | if (!zstr(cmd)_zstr(cmd)) { | ||||||
5340 | mycmd = switch_core_strdup(pool, cmd)switch_core_perform_strdup(pool, cmd, "mod_voicemail.c", (const char *)__func__, 5340); | ||||||
5341 | switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | ||||||
5342 | } | ||||||
5343 | |||||||
5344 | if (argv[0]) | ||||||
5345 | profile_name = argv[0]; | ||||||
5346 | if (argv[1]) | ||||||
5347 | domain = argv[1]; | ||||||
5348 | if (argv[2]) | ||||||
5349 | id = argv[2]; | ||||||
5350 | if (argv[3]) | ||||||
5351 | password = argv[3]; | ||||||
5352 | |||||||
5353 | if (!profile_name || !domain || !id || !password) { | ||||||
5354 | stream->write_function(stream, "-ERR Missing Arguments\n"); | ||||||
5355 | goto done; | ||||||
5356 | } | ||||||
5357 | |||||||
5358 | if (!(profile = get_profile(profile_name))) { | ||||||
5359 | stream->write_function(stream, "-ERR Profile not found\n"); | ||||||
5360 | goto done; | ||||||
5361 | } | ||||||
5362 | |||||||
5363 | sql = switch_mprintf("SELECT count(*) FROM voicemail_prefs WHERE username = '%q' AND domain = '%q'", id, domain); | ||||||
5364 | vm_execute_sql2str(profile, profile->mutex, sql, res, sizeof(res)); | ||||||
5365 | switch_safe_free(sql)if (sql) {free(sql);sql=((void*)0);}; | ||||||
5366 | |||||||
5367 | if (atoi(res) == 0) { | ||||||
5368 | sql = switch_mprintf("INSERT INTO voicemail_prefs (username, domain, password) VALUES('%q', '%q', '%q')", id, domain, password); | ||||||
5369 | } else { | ||||||
5370 | sql = switch_mprintf("UPDATE voicemail_prefs SET password = '%q' WHERE username = '%q' AND domain = '%q'", password, id, domain); | ||||||
5371 | } | ||||||
5372 | vm_execute_sql(profile, sql, profile->mutex); | ||||||
5373 | switch_safe_free(sql)if (sql) {free(sql);sql=((void*)0);}; | ||||||
5374 | profile_rwunlock(profile); | ||||||
5375 | |||||||
5376 | stream->write_function(stream, "-OK\n"); | ||||||
5377 | done: | ||||||
5378 | switch_core_destroy_memory_pool(&pool)switch_core_perform_destroy_memory_pool(&pool, "mod_voicemail.c" , (const char *)__func__, 5378); | ||||||
5379 | return SWITCH_STATUS_SUCCESS; | ||||||
5380 | } | ||||||
5381 | |||||||
5382 | |||||||
5383 | |||||||
5384 | /* Message API */ | ||||||
5385 | |||||||
5386 | #define VM_FSDB_MSG_LIST_USAGE"<format> <profile> <domain> <user> <folder> <filter> [msg-order = ASC | DESC]" "<format> <profile> <domain> <user> <folder> <filter> [msg-order = ASC | DESC]" | ||||||
5387 | SWITCH_STANDARD_API(vm_fsdb_msg_list_function)static switch_status_t vm_fsdb_msg_list_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | ||||||
5388 | { | ||||||
5389 | char *sql; | ||||||
5390 | msg_lst_callback_t cbt = { 0 }; | ||||||
5391 | char *ebuf = NULL((void*)0); | ||||||
5392 | |||||||
5393 | const char *id = NULL((void*)0), *domain = NULL((void*)0), *profile_name = NULL((void*)0), *folder = NULL((void*)0), *msg_type = NULL((void*)0), *msg_order = NULL((void*)0); | ||||||
5394 | vm_profile_t *profile = NULL((void*)0); | ||||||
5395 | |||||||
5396 | char *argv[7] = { 0 }; | ||||||
5397 | char *mycmd = NULL((void*)0); | ||||||
5398 | |||||||
5399 | switch_memory_pool_t *pool; | ||||||
5400 | |||||||
5401 | switch_core_new_memory_pool(&pool)switch_core_perform_new_memory_pool(&pool, "mod_voicemail.c" , (const char *)__func__, 5401); | ||||||
5402 | |||||||
5403 | if (!zstr(cmd)_zstr(cmd)) { | ||||||
5404 | mycmd = switch_core_strdup(pool, cmd)switch_core_perform_strdup(pool, cmd, "mod_voicemail.c", (const char *)__func__, 5404); | ||||||
5405 | switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | ||||||
5406 | } | ||||||
5407 | |||||||
5408 | if (argv[1]) | ||||||
5409 | profile_name = argv[1]; | ||||||
5410 | if (argv[2]) | ||||||
5411 | domain = argv[2]; | ||||||
5412 | if (argv[3]) | ||||||
5413 | id = argv[3]; | ||||||
5414 | if (argv[4]) | ||||||
5415 | folder = argv[4]; /* TODO add Support */ | ||||||
5416 | if (argv[5]) | ||||||
5417 | msg_type = argv[5]; | ||||||
5418 | if (argv[6]) | ||||||
5419 | msg_order = argv[6]; | ||||||
5420 | |||||||
5421 | if (!profile_name || !domain || !id || !folder || !msg_type) { | ||||||
5422 | stream->write_function(stream, "-ERR Missing Arguments\n"); | ||||||
5423 | goto done; | ||||||
5424 | } | ||||||
5425 | |||||||
5426 | if (!msg_order) { | ||||||
5427 | msg_order = "ASC"; | ||||||
5428 | } else if (strcasecmp(msg_order, "ASC") || strcasecmp(msg_order, "DESC")) { | ||||||
5429 | stream->write_function(stream, "-ERR Bad Argument: '%s'\n", msg_order); | ||||||
5430 | goto done; | ||||||
5431 | } | ||||||
5432 | |||||||
5433 | if (!(profile = get_profile(profile_name))) { | ||||||
5434 | stream->write_function(stream, "-ERR Profile not found\n"); | ||||||
5435 | goto done; | ||||||
5436 | } | ||||||
5437 | if (!strcasecmp(msg_type, "not-read")) { | ||||||
5438 | sql = switch_mprintf("SELECT uuid FROM voicemail_msgs WHERE username = '%q' AND domain = '%q' AND read_epoch = 0 ORDER BY read_flags, created_epoch %q", id, domain, msg_order); | ||||||
5439 | } else if (!strcasecmp(msg_type, "new")) { | ||||||
5440 | sql = switch_mprintf("SELECT uuid FROM voicemail_msgs WHERE username = '%q' AND domain = '%q' AND flags='' ORDER BY read_flags, created_epoch %q", id, domain, msg_order); | ||||||
5441 | } else if (!strcasecmp(msg_type, "save")) { | ||||||
5442 | sql = switch_mprintf("SELECT uuid FROM voicemail_msgs WHERE username = '%q' AND domain = '%q' AND flags='save' ORDER BY read_flags, created_epoch %q", id, domain, msg_order); | ||||||
5443 | } else { | ||||||
5444 | sql = switch_mprintf("SELECT uuid FROM voicemail_msgs WHERE username = '%q' AND domain = '%q' AND read_epoch != 0 ORDER BY read_flags, created_epoch %q", id, domain, msg_order); | ||||||
5445 | } | ||||||
5446 | memset(&cbt, 0, sizeof(cbt)); | ||||||
5447 | |||||||
5448 | switch_event_create(&cbt.my_params, SWITCH_EVENT_REQUEST_PARAMS)switch_event_create_subclass_detailed("mod_voicemail.c", (const char * )(const char *)__func__, 5448, &cbt.my_params, SWITCH_EVENT_REQUEST_PARAMS , ((void*)0)); | ||||||
5449 | |||||||
5450 | vm_execute_sql_callback(profile, profile->mutex, sql, message_list_callback, &cbt); | ||||||
5451 | |||||||
5452 | profile_rwunlock(profile); | ||||||
5453 | |||||||
5454 | switch_event_add_header(cbt.my_params, SWITCH_STACK_BOTTOM, "VM-List-Count", "%"SWITCH_SIZE_T_FMT"ld", cbt.len); | ||||||
5455 | switch_event_serialize_json(cbt.my_params, &ebuf); | ||||||
5456 | switch_event_destroy(&cbt.my_params); | ||||||
5457 | |||||||
5458 | switch_safe_free(sql)if (sql) {free(sql);sql=((void*)0);}; | ||||||
5459 | stream->write_function(stream, "%s", ebuf); | ||||||
5460 | switch_safe_free(ebuf)if (ebuf) {free(ebuf);ebuf=((void*)0);}; | ||||||
5461 | done: | ||||||
5462 | switch_core_destroy_memory_pool(&pool)switch_core_perform_destroy_memory_pool(&pool, "mod_voicemail.c" , (const char *)__func__, 5462); | ||||||
5463 | return SWITCH_STATUS_SUCCESS; | ||||||
5464 | } | ||||||
5465 | |||||||
5466 | #define VM_FSDB_MSG_PURGE_USAGE"<profile> <domain> <user>" "<profile> <domain> <user>" | ||||||
5467 | SWITCH_STANDARD_API(vm_fsdb_msg_purge_function)static switch_status_t vm_fsdb_msg_purge_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | ||||||
5468 | { | ||||||
5469 | char *sql; | ||||||
5470 | const char *id = NULL((void*)0), *domain = NULL((void*)0), *profile_name = NULL((void*)0); | ||||||
5471 | vm_profile_t *profile = NULL((void*)0); | ||||||
5472 | |||||||
5473 | char *argv[6] = { 0 }; | ||||||
5474 | char *mycmd = NULL((void*)0); | ||||||
5475 | |||||||
5476 | switch_memory_pool_t *pool; | ||||||
5477 | |||||||
5478 | switch_core_new_memory_pool(&pool)switch_core_perform_new_memory_pool(&pool, "mod_voicemail.c" , (const char *)__func__, 5478); | ||||||
5479 | |||||||
5480 | if (!zstr(cmd)_zstr(cmd)) { | ||||||
5481 | mycmd = switch_core_strdup(pool, cmd)switch_core_perform_strdup(pool, cmd, "mod_voicemail.c", (const char *)__func__, 5481); | ||||||
5482 | switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | ||||||
5483 | } | ||||||
5484 | |||||||
5485 | if (argv[0]) | ||||||
5486 | profile_name = argv[0]; | ||||||
5487 | if (argv[1]) | ||||||
5488 | domain = argv[1]; | ||||||
5489 | if (argv[2]) | ||||||
5490 | id = argv[2]; | ||||||
5491 | |||||||
5492 | if (!profile_name || !domain || !id) { | ||||||
5493 | stream->write_function(stream, "-ERR Missing Arguments\n"); | ||||||
5494 | goto done; | ||||||
5495 | } | ||||||
5496 | |||||||
5497 | if (!(profile = get_profile(profile_name))) { | ||||||
5498 | stream->write_function(stream, "-ERR Profile not found\n"); | ||||||
5499 | goto done; | ||||||
5500 | } | ||||||
5501 | |||||||
5502 | sql = switch_mprintf("SELECT '%q', uuid, username, domain, file_path FROM voicemail_msgs WHERE username = '%q' AND domain = '%q' AND flags = 'delete'", profile_name, id, domain); | ||||||
5503 | vm_execute_sql_callback(profile, profile->mutex, sql, message_purge_callback, NULL((void*)0)); | ||||||
5504 | update_mwi(profile, id, domain, "inbox", MWI_REASON_PURGE); /* TODO Make inbox value configurable */ | ||||||
5505 | |||||||
5506 | profile_rwunlock(profile); | ||||||
5507 | |||||||
5508 | stream->write_function(stream, "-OK\n"); | ||||||
5509 | |||||||
5510 | done: | ||||||
5511 | switch_core_destroy_memory_pool(&pool)switch_core_perform_destroy_memory_pool(&pool, "mod_voicemail.c" , (const char *)__func__, 5511); | ||||||
5512 | return SWITCH_STATUS_SUCCESS; | ||||||
5513 | } | ||||||
5514 | |||||||
5515 | #define VM_FSDB_MSG_DELETE_USAGE"<profile> <domain> <user> <uuid>" "<profile> <domain> <user> <uuid>" | ||||||
5516 | SWITCH_STANDARD_API(vm_fsdb_msg_delete_function)static switch_status_t vm_fsdb_msg_delete_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | ||||||
5517 | { | ||||||
5518 | char *sql; | ||||||
5519 | const char *uuid = NULL((void*)0); | ||||||
5520 | |||||||
5521 | const char *id = NULL((void*)0), *domain = NULL((void*)0), *profile_name = NULL((void*)0); | ||||||
5522 | vm_profile_t *profile = NULL((void*)0); | ||||||
5523 | |||||||
5524 | char *argv[6] = { 0 }; | ||||||
5525 | char *mycmd = NULL((void*)0); | ||||||
5526 | |||||||
5527 | switch_memory_pool_t *pool; | ||||||
5528 | |||||||
5529 | switch_core_new_memory_pool(&pool)switch_core_perform_new_memory_pool(&pool, "mod_voicemail.c" , (const char *)__func__, 5529); | ||||||
5530 | |||||||
5531 | if (!zstr(cmd)_zstr(cmd)) { | ||||||
5532 | mycmd = switch_core_strdup(pool, cmd)switch_core_perform_strdup(pool, cmd, "mod_voicemail.c", (const char *)__func__, 5532); | ||||||
5533 | switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | ||||||
5534 | } | ||||||
5535 | |||||||
5536 | if (argv[0]) | ||||||
5537 | profile_name = argv[0]; | ||||||
5538 | if (argv[1]) | ||||||
5539 | domain = argv[1]; | ||||||
5540 | if (argv[2]) | ||||||
5541 | id = argv[2]; | ||||||
5542 | if (argv[3]) | ||||||
5543 | uuid = argv[3]; | ||||||
5544 | |||||||
5545 | if (!profile_name || !domain || !id || !uuid) { | ||||||
5546 | stream->write_function(stream, "-ERR Missing Arguments\n"); | ||||||
5547 | goto done; | ||||||
5548 | } | ||||||
5549 | |||||||
5550 | if (!(profile = get_profile(profile_name))) { | ||||||
5551 | stream->write_function(stream, "-ERR Profile not found\n"); | ||||||
5552 | goto done; | ||||||
5553 | } | ||||||
5554 | |||||||
5555 | sql = switch_mprintf("UPDATE voicemail_msgs SET flags = 'delete' WHERE username = '%q' AND domain = '%q' AND uuid = '%q'", id, domain, uuid); | ||||||
5556 | vm_execute_sql(profile, sql, profile->mutex); | ||||||
5557 | profile_rwunlock(profile); | ||||||
5558 | |||||||
5559 | stream->write_function(stream, "-OK\n"); | ||||||
5560 | |||||||
5561 | done: | ||||||
5562 | switch_core_destroy_memory_pool(&pool)switch_core_perform_destroy_memory_pool(&pool, "mod_voicemail.c" , (const char *)__func__, 5562); | ||||||
5563 | return SWITCH_STATUS_SUCCESS; | ||||||
5564 | } | ||||||
5565 | |||||||
5566 | #define VM_FSDB_MSG_SAVE_USAGE"<profile> <domain> <user> <uuid>" "<profile> <domain> <user> <uuid>" | ||||||
5567 | SWITCH_STANDARD_API(vm_fsdb_msg_save_function)static switch_status_t vm_fsdb_msg_save_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | ||||||
5568 | { | ||||||
5569 | char *sql; | ||||||
5570 | const char *uuid = NULL((void*)0); | ||||||
5571 | |||||||
5572 | const char *id = NULL((void*)0), *domain = NULL((void*)0), *profile_name = NULL((void*)0); | ||||||
5573 | vm_profile_t *profile = NULL((void*)0); | ||||||
5574 | |||||||
5575 | char *argv[6] = { 0 }; | ||||||
5576 | char *mycmd = NULL((void*)0); | ||||||
5577 | |||||||
5578 | switch_memory_pool_t *pool; | ||||||
5579 | |||||||
5580 | switch_core_new_memory_pool(&pool)switch_core_perform_new_memory_pool(&pool, "mod_voicemail.c" , (const char *)__func__, 5580); | ||||||
5581 | |||||||
5582 | if (!zstr(cmd)_zstr(cmd)) { | ||||||
5583 | mycmd = switch_core_strdup(pool, cmd)switch_core_perform_strdup(pool, cmd, "mod_voicemail.c", (const char *)__func__, 5583); | ||||||
5584 | switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | ||||||
5585 | } | ||||||
5586 | |||||||
5587 | if (argv[0]) | ||||||
5588 | profile_name = argv[0]; | ||||||
5589 | if (argv[1]) | ||||||
5590 | domain = argv[1]; | ||||||
5591 | if (argv[2]) | ||||||
5592 | id = argv[2]; | ||||||
5593 | if (argv[3]) | ||||||
5594 | uuid = argv[3]; | ||||||
5595 | |||||||
5596 | if (!profile_name || !domain || !id || !uuid) { | ||||||
5597 | stream->write_function(stream, "-ERR Missing Arguments\n"); | ||||||
5598 | goto done; | ||||||
5599 | } | ||||||
5600 | |||||||
5601 | if (!(profile = get_profile(profile_name))) { | ||||||
5602 | stream->write_function(stream, "-ERR Profile not found\n"); | ||||||
5603 | goto done; | ||||||
5604 | } | ||||||
5605 | |||||||
5606 | sql = switch_mprintf("UPDATE voicemail_msgs SET flags='save' WHERE username='%q' AND domain='%q' AND uuid = '%q'", id, domain, uuid); | ||||||
5607 | vm_execute_sql(profile, sql, profile->mutex); | ||||||
5608 | profile_rwunlock(profile); | ||||||
5609 | |||||||
5610 | stream->write_function(stream, "-OK\n"); | ||||||
5611 | done: | ||||||
5612 | switch_core_destroy_memory_pool(&pool)switch_core_perform_destroy_memory_pool(&pool, "mod_voicemail.c" , (const char *)__func__, 5612); | ||||||
5613 | return SWITCH_STATUS_SUCCESS; | ||||||
5614 | } | ||||||
5615 | |||||||
5616 | #define VM_FSDB_MSG_UNDELETE_USAGE"<profile> <domain> <user> <uuid>" "<profile> <domain> <user> <uuid>" | ||||||
5617 | SWITCH_STANDARD_API(vm_fsdb_msg_undelete_function)static switch_status_t vm_fsdb_msg_undelete_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | ||||||
5618 | { | ||||||
5619 | char *sql; | ||||||
5620 | const char *uuid = NULL((void*)0); | ||||||
5621 | |||||||
5622 | const char *id = NULL((void*)0), *domain = NULL((void*)0), *profile_name = NULL((void*)0); | ||||||
5623 | vm_profile_t *profile = NULL((void*)0); | ||||||
5624 | |||||||
5625 | char *argv[6] = { 0 }; | ||||||
5626 | char *mycmd = NULL((void*)0); | ||||||
5627 | |||||||
5628 | switch_memory_pool_t *pool; | ||||||
5629 | |||||||
5630 | switch_core_new_memory_pool(&pool)switch_core_perform_new_memory_pool(&pool, "mod_voicemail.c" , (const char *)__func__, 5630); | ||||||
5631 | |||||||
5632 | if (!zstr(cmd)_zstr(cmd)) { | ||||||
5633 | mycmd = switch_core_strdup(pool, cmd)switch_core_perform_strdup(pool, cmd, "mod_voicemail.c", (const char *)__func__, 5633); | ||||||
5634 | switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | ||||||
5635 | } | ||||||
5636 | |||||||
5637 | if (argv[0]) | ||||||
5638 | profile_name = argv[0]; | ||||||
5639 | if (argv[1]) | ||||||
5640 | domain = argv[1]; | ||||||
5641 | if (argv[2]) | ||||||
5642 | id = argv[2]; | ||||||
5643 | if (argv[3]) | ||||||
5644 | uuid = argv[3]; | ||||||
5645 | |||||||
5646 | if (!profile_name || !domain || !id || !uuid) { | ||||||
5647 | stream->write_function(stream, "-ERR Missing Arguments\n"); | ||||||
5648 | goto done; | ||||||
5649 | } | ||||||
5650 | |||||||
5651 | if (!(profile = get_profile(profile_name))) { | ||||||
5652 | stream->write_function(stream, "-ERR Profile not found\n"); | ||||||
5653 | goto done; | ||||||
5654 | } | ||||||
5655 | |||||||
5656 | sql = switch_mprintf("UPDATE voicemail_msgs SET flags='' WHERE username='%q' AND domain='%q' AND uuid = '%q'", id, domain, uuid); | ||||||
5657 | vm_execute_sql(profile, sql, profile->mutex); | ||||||
5658 | profile_rwunlock(profile); | ||||||
5659 | |||||||
5660 | stream->write_function(stream, "-OK\n"); | ||||||
5661 | done: | ||||||
5662 | switch_core_destroy_memory_pool(&pool)switch_core_perform_destroy_memory_pool(&pool, "mod_voicemail.c" , (const char *)__func__, 5662); | ||||||
5663 | return SWITCH_STATUS_SUCCESS; | ||||||
5664 | } | ||||||
5665 | |||||||
5666 | #define VM_FSDB_AUTH_LOGIN_USAGE"<profile> <domain> <user> <password>" "<profile> <domain> <user> <password>" | ||||||
5667 | SWITCH_STANDARD_API(vm_fsdb_auth_login_function)static switch_status_t vm_fsdb_auth_login_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | ||||||
5668 | { | ||||||
5669 | char *sql; | ||||||
5670 | char *password = NULL((void*)0); | ||||||
5671 | |||||||
5672 | const char *id = NULL((void*)0), *domain = NULL((void*)0), *profile_name = NULL((void*)0); | ||||||
5673 | vm_profile_t *profile = NULL((void*)0); | ||||||
5674 | |||||||
5675 | char *argv[6] = { 0 }; | ||||||
5676 | char *mycmd = NULL((void*)0); | ||||||
5677 | |||||||
5678 | char user_db_password[64] = { 0 }; | ||||||
5679 | const char *user_xml_password = NULL((void*)0); | ||||||
5680 | switch_bool_t authorized = SWITCH_FALSE; | ||||||
5681 | switch_event_t *params = NULL((void*)0); | ||||||
5682 | switch_xml_t x_user = NULL((void*)0); | ||||||
5683 | switch_bool_t vm_enabled = SWITCH_TRUE; | ||||||
5684 | |||||||
5685 | switch_memory_pool_t *pool; | ||||||
5686 | |||||||
5687 | switch_core_new_memory_pool(&pool)switch_core_perform_new_memory_pool(&pool, "mod_voicemail.c" , (const char *)__func__, 5687); | ||||||
5688 | |||||||
5689 | if (!zstr(cmd)_zstr(cmd)) { | ||||||
5690 | mycmd = switch_core_strdup(pool, cmd)switch_core_perform_strdup(pool, cmd, "mod_voicemail.c", (const char *)__func__, 5690); | ||||||
5691 | switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | ||||||
5692 | } | ||||||
5693 | |||||||
5694 | if (argv[0]) | ||||||
5695 | profile_name = argv[0]; | ||||||
5696 | if (argv[1]) | ||||||
5697 | domain = argv[1]; | ||||||
5698 | if (argv[2]) | ||||||
5699 | id = argv[2]; | ||||||
5700 | if (argv[3]) | ||||||
5701 | password = argv[3]; | ||||||
5702 | |||||||
5703 | if (!profile_name || !domain || !id || !password) { | ||||||
5704 | stream->write_function(stream, "-ERR Missing Arguments\n"); | ||||||
5705 | goto done; | ||||||
5706 | } | ||||||
5707 | |||||||
5708 | if (!(profile = get_profile(profile_name))) { | ||||||
5709 | stream->write_function(stream, "-ERR Profile not found\n"); | ||||||
5710 | goto done; | ||||||
5711 | } | ||||||
5712 | |||||||
5713 | switch_event_create(¶ms, SWITCH_EVENT_GENERAL)switch_event_create_subclass_detailed("mod_voicemail.c", (const char * )(const char *)__func__, 5713, ¶ms, SWITCH_EVENT_GENERAL , ((void*)0)); | ||||||
5714 | if (switch_xml_locate_user_merged("id:number-alias", id, domain, NULL((void*)0), &x_user, params) != SWITCH_STATUS_SUCCESS) { | ||||||
5715 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "mod_voicemail.c", (const char *)__func__ , 5715, (const char*)(session), SWITCH_LOG_WARNING, "Can't find user [%s@%s]\n", id, domain); | ||||||
5716 | stream->write_function(stream, "-ERR User not found\n"); | ||||||
5717 | } else { | ||||||
5718 | switch_xml_t x_param, x_params; | ||||||
5719 | |||||||
5720 | x_params = switch_xml_child(x_user, "params"); | ||||||
5721 | |||||||
5722 | for (x_param = switch_xml_child(x_params, "param"); x_param; x_param = x_param->next) { | ||||||
5723 | const char *var = switch_xml_attr_soft(x_param, "name"); | ||||||
5724 | const char *val = switch_xml_attr_soft(x_param, "value"); | ||||||
5725 | if (zstr(var)_zstr(var) || zstr(val)_zstr(val)) { | ||||||
5726 | continue; /* Ignore empty entires */ | ||||||
5727 | } | ||||||
5728 | |||||||
5729 | if (!strcasecmp(var, "vm-enabled")) { | ||||||
5730 | vm_enabled = !switch_false(val); | ||||||
5731 | } | ||||||
5732 | if (!strcasecmp(var, "vm-password")) { | ||||||
5733 | user_xml_password = val; | ||||||
5734 | } | ||||||
5735 | } | ||||||
5736 | |||||||
5737 | sql = switch_mprintf("SELECT password FROM voicemail_prefs WHERE username = '%q' AND domain = '%q'", id, domain); | ||||||
5738 | vm_execute_sql2str(profile, profile->mutex, sql, user_db_password, sizeof(user_db_password)); | ||||||
5739 | switch_safe_free(sql)if (sql) {free(sql);sql=((void*)0);}; | ||||||
5740 | |||||||
5741 | if (vm_enabled == SWITCH_FALSE) { | ||||||
5742 | stream->write_function(stream, "%s", "-ERR Login Denied"); | ||||||
5743 | } else { | ||||||
5744 | if (!zstr(user_db_password)_zstr(user_db_password)) { | ||||||
5745 | if (!strcasecmp(user_db_password, password)) { | ||||||
5746 | authorized = SWITCH_TRUE; | ||||||
5747 | } | ||||||
5748 | if (!profile->db_password_override && !zstr(user_xml_password)_zstr(user_xml_password) && !strcasecmp(user_xml_password, password)) { | ||||||
5749 | authorized = SWITCH_TRUE; | ||||||
5750 | } | ||||||
5751 | } else { | ||||||
5752 | if (!zstr(user_xml_password)_zstr(user_xml_password)) { | ||||||
5753 | if (!strcasecmp(user_xml_password, password)) { | ||||||
5754 | authorized = SWITCH_TRUE; | ||||||
5755 | } | ||||||
5756 | } | ||||||
5757 | } | ||||||
5758 | if (profile->allow_empty_password_auth && zstr(user_db_password)_zstr(user_db_password) && zstr(user_xml_password)_zstr(user_xml_password)) { | ||||||
5759 | authorized = SWITCH_TRUE; | ||||||
5760 | } | ||||||
5761 | if (authorized) { | ||||||
5762 | stream->write_function(stream, "%s", "-OK"); | ||||||
5763 | } else { | ||||||
5764 | stream->write_function(stream, "%s", "-ERR"); | ||||||
5765 | } | ||||||
5766 | } | ||||||
5767 | } | ||||||
5768 | |||||||
5769 | xml_safe_free(x_user)if (x_user) switch_xml_free(x_user); x_user = ((void*)0); | ||||||
5770 | |||||||
5771 | profile_rwunlock(profile); | ||||||
5772 | done: | ||||||
5773 | switch_core_destroy_memory_pool(&pool)switch_core_perform_destroy_memory_pool(&pool, "mod_voicemail.c" , (const char *)__func__, 5773); | ||||||
5774 | return SWITCH_STATUS_SUCCESS; | ||||||
5775 | } | ||||||
5776 | |||||||
5777 | #define VM_FSDB_MSG_FORWARD_USAGE"<profile> <domain> <user> <uuid> <dst_domain> <dst_user> [prepend_file_location]" "<profile> <domain> <user> <uuid> <dst_domain> <dst_user> [prepend_file_location]" | ||||||
5778 | SWITCH_STANDARD_API(vm_fsdb_msg_forward_function)static switch_status_t vm_fsdb_msg_forward_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | ||||||
5779 | { | ||||||
5780 | const char *id = NULL((void*)0), *domain = NULL((void*)0), *profile_name = NULL((void*)0), *uuid = NULL((void*)0), *dst_domain = NULL((void*)0), *dst_id = NULL((void*)0), *prepend_file_path = NULL((void*)0); | ||||||
5781 | vm_profile_t *profile = NULL((void*)0); | ||||||
5782 | char *argv[7] = { 0 }; | ||||||
5783 | char *mycmd = NULL((void*)0); | ||||||
5784 | msg_get_callback_t cbt = { 0 }; | ||||||
5785 | char *sql; | ||||||
5786 | switch_memory_pool_t *pool; | ||||||
5787 | |||||||
5788 | switch_core_new_memory_pool(&pool)switch_core_perform_new_memory_pool(&pool, "mod_voicemail.c" , (const char *)__func__, 5788); | ||||||
5789 | |||||||
5790 | if (!zstr(cmd)_zstr(cmd)) { | ||||||
5791 | mycmd = switch_core_strdup(pool, cmd)switch_core_perform_strdup(pool, cmd, "mod_voicemail.c", (const char *)__func__, 5791); | ||||||
5792 | switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | ||||||
5793 | } | ||||||
5794 | |||||||
5795 | if (argv[0]) | ||||||
5796 | profile_name = argv[0]; | ||||||
5797 | if (argv[1]) | ||||||
5798 | domain = argv[1]; | ||||||
5799 | if (argv[2]) | ||||||
5800 | id = argv[2]; | ||||||
5801 | if (argv[3]) | ||||||
5802 | uuid = argv[3]; | ||||||
5803 | if (argv[4]) | ||||||
5804 | dst_domain = argv[4]; | ||||||
5805 | if (argv[5]) | ||||||
5806 | dst_id = argv[5]; | ||||||
5807 | if (argv[6]) | ||||||
5808 | prepend_file_path = argv[6]; | ||||||
5809 | |||||||
5810 | if (!profile_name || !domain || !id || !uuid || !dst_domain || !dst_id) { | ||||||
5811 | stream->write_function(stream, "-ERR Missing Arguments\n"); | ||||||
5812 | goto done; | ||||||
5813 | } | ||||||
5814 | |||||||
5815 | if (!(profile = get_profile(profile_name))) { | ||||||
5816 | stream->write_function(stream, "-ERR Profile not found\n"); | ||||||
5817 | goto done; | ||||||
5818 | } else { | ||||||
5819 | const char *file_path = NULL((void*)0); | ||||||
5820 | sql = switch_mprintf("select created_epoch, read_epoch, username, domain, uuid, cid_name, cid_number, in_folder, file_path, message_len, flags, read_flags, forwarded_by from voicemail_msgs WHERE username = '%q' AND domain = '%q' AND uuid = '%q' ORDER BY read_flags, created_epoch", id, domain, uuid); | ||||||
5821 | memset(&cbt, 0, sizeof(cbt)); | ||||||
5822 | switch_event_create(&cbt.my_params, SWITCH_EVENT_REQUEST_PARAMS)switch_event_create_subclass_detailed("mod_voicemail.c", (const char * )(const char *)__func__, 5822, &cbt.my_params, SWITCH_EVENT_REQUEST_PARAMS , ((void*)0)); | ||||||
5823 | vm_execute_sql_callback(profile, profile->mutex, sql, message_get_callback, &cbt); | ||||||
5824 | switch_safe_free(sql)if (sql) {free(sql);sql=((void*)0);}; | ||||||
5825 | file_path = switch_event_get_header(cbt.my_params, "VM-Message-File-Path")switch_event_get_header_idx(cbt.my_params, "VM-Message-File-Path" , -1); | ||||||
5826 | if (file_path && switch_file_exists(file_path, pool) == SWITCH_STATUS_SUCCESS) { | ||||||
5827 | const char *new_file_path = file_path; | ||||||
5828 | const char *cmd = NULL((void*)0); | ||||||
5829 | |||||||
5830 | |||||||
5831 | if (prepend_file_path && switch_file_exists(prepend_file_path, pool) == SWITCH_STATUS_SUCCESS) { | ||||||
5832 | switch_uuid_t tmp_uuid; | ||||||
5833 | char tmp_uuid_str[SWITCH_UUID_FORMATTED_LENGTH256 + 1]; | ||||||
5834 | const char *test[3] = { NULL((void*)0) }; | ||||||
5835 | test[0] = prepend_file_path; | ||||||
5836 | test[1] = file_path; | ||||||
5837 | |||||||
5838 | switch_uuid_get(&tmp_uuid); | ||||||
5839 | switch_uuid_format(tmp_uuid_str, &tmp_uuid); | ||||||
5840 | |||||||
5841 | new_file_path = switch_core_sprintf(pool, "%s%smsg_%s.wav", SWITCH_GLOBAL_dirs.temp_dir, SWITCH_PATH_SEPARATOR"/", tmp_uuid_str); | ||||||
5842 | |||||||
5843 | if (vm_merge_media_files(test, new_file_path) != SWITCH_STATUS_SUCCESS) { | ||||||
5844 | stream->write_function(stream, "-ERR Error Merging the file\n"); | ||||||
5845 | switch_event_destroy(&cbt.my_params); | ||||||
5846 | profile_rwunlock(profile); | ||||||
5847 | goto done; | ||||||
5848 | } | ||||||
5849 | |||||||
5850 | } | ||||||
5851 | cmd = switch_core_sprintf(pool, "%s@%s %s %s '%s'", dst_id, dst_domain, new_file_path, switch_event_get_header(cbt.my_params, "VM-Message-Caller-Number")switch_event_get_header_idx(cbt.my_params, "VM-Message-Caller-Number" , -1), switch_event_get_header(cbt.my_params, "VM-Message-Caller-Name")switch_event_get_header_idx(cbt.my_params, "VM-Message-Caller-Name" , -1)); | ||||||
5852 | if (voicemail_inject(cmd, NULL((void*)0)) == SWITCH_STATUS_SUCCESS) { | ||||||
5853 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 5853, ((void*)0), SWITCH_LOG_NOTICE, "Sent Carbon Copy to %s@%s\n", dst_id, dst_domain); | ||||||
5854 | } else { | ||||||
5855 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 5855, ((void*)0), SWITCH_LOG_ERROR, "Failed to Carbon Copy to %s@%s\n", dst_id, dst_domain); | ||||||
5856 | stream->write_function(stream, "-ERR Error Forwarding Message\n"); | ||||||
5857 | switch_event_destroy(&cbt.my_params); | ||||||
5858 | profile_rwunlock(profile); | ||||||
5859 | goto done; | ||||||
5860 | } | ||||||
5861 | if (new_file_path != file_path) { | ||||||
5862 | /* TODO UNLINK new-file-path */ | ||||||
5863 | } | ||||||
5864 | } else { | ||||||
5865 | stream->write_function(stream, "-ERR Cannot find source msg to forward: %s\n", file_path); | ||||||
5866 | switch_event_destroy(&cbt.my_params); | ||||||
5867 | profile_rwunlock(profile); | ||||||
5868 | goto done; | ||||||
5869 | } | ||||||
5870 | |||||||
5871 | switch_event_destroy(&cbt.my_params); | ||||||
5872 | |||||||
5873 | profile_rwunlock(profile); | ||||||
5874 | } | ||||||
5875 | stream->write_function(stream, "-OK\n"); | ||||||
5876 | done: | ||||||
5877 | switch_core_destroy_memory_pool(&pool)switch_core_perform_destroy_memory_pool(&pool, "mod_voicemail.c" , (const char *)__func__, 5877); | ||||||
5878 | |||||||
5879 | |||||||
5880 | return SWITCH_STATUS_SUCCESS; | ||||||
5881 | } | ||||||
5882 | |||||||
5883 | #define VM_FSDB_MSG_GET_USAGE"<format> <profile> <domain> <user> <uuid>" "<format> <profile> <domain> <user> <uuid>" | ||||||
5884 | SWITCH_STANDARD_API(vm_fsdb_msg_get_function)static switch_status_t vm_fsdb_msg_get_function ( const char * cmd, switch_core_session_t *session, switch_stream_handle_t * stream) | ||||||
5885 | { | ||||||
5886 | char *sql; | ||||||
5887 | msg_get_callback_t cbt = { 0 }; | ||||||
5888 | char *ebuf = NULL((void*)0); | ||||||
5889 | char *uuid = NULL((void*)0); | ||||||
5890 | |||||||
5891 | const char *id = NULL((void*)0), *domain = NULL((void*)0), *profile_name = NULL((void*)0); | ||||||
5892 | vm_profile_t *profile = NULL((void*)0); | ||||||
5893 | |||||||
5894 | char *argv[6] = { 0 }; | ||||||
5895 | char *mycmd = NULL((void*)0); | ||||||
5896 | |||||||
5897 | switch_memory_pool_t *pool; | ||||||
5898 | |||||||
5899 | switch_core_new_memory_pool(&pool)switch_core_perform_new_memory_pool(&pool, "mod_voicemail.c" , (const char *)__func__, 5899); | ||||||
5900 | |||||||
5901 | if (!zstr(cmd)_zstr(cmd)) { | ||||||
5902 | mycmd = switch_core_strdup(pool, cmd)switch_core_perform_strdup(pool, cmd, "mod_voicemail.c", (const char *)__func__, 5902); | ||||||
5903 | switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | ||||||
5904 | } | ||||||
5905 | |||||||
5906 | if (argv[1]) | ||||||
5907 | profile_name = argv[1]; | ||||||
5908 | if (argv[2]) | ||||||
5909 | domain = argv[2]; | ||||||
5910 | if (argv[3]) | ||||||
5911 | id = argv[3]; | ||||||
5912 | if (argv[4]) | ||||||
5913 | uuid = argv[4]; | ||||||
5914 | |||||||
5915 | if (!profile_name || !domain || !id || !uuid) { | ||||||
5916 | stream->write_function(stream, "-ERR Missing Arguments\n"); | ||||||
5917 | goto done; | ||||||
5918 | } | ||||||
5919 | |||||||
5920 | if (!(profile = get_profile(profile_name))) { | ||||||
5921 | stream->write_function(stream, "-ERR Profile not found\n"); | ||||||
5922 | goto done; | ||||||
5923 | } | ||||||
5924 | |||||||
5925 | sql = switch_mprintf("select created_epoch, read_epoch, username, domain, uuid, cid_name, cid_number, in_folder, file_path, message_len, flags, read_flags, forwarded_by from voicemail_msgs WHERE username = '%q' AND domain = '%q' AND uuid = '%q' ORDER BY read_flags, created_epoch", id, domain, uuid); | ||||||
5926 | |||||||
5927 | memset(&cbt, 0, sizeof(cbt)); | ||||||
5928 | |||||||
5929 | switch_event_create(&cbt.my_params, SWITCH_EVENT_REQUEST_PARAMS)switch_event_create_subclass_detailed("mod_voicemail.c", (const char * )(const char *)__func__, 5929, &cbt.my_params, SWITCH_EVENT_REQUEST_PARAMS , ((void*)0)); | ||||||
5930 | |||||||
5931 | vm_execute_sql_callback(profile, profile->mutex, sql, message_get_callback, &cbt); | ||||||
5932 | |||||||
5933 | profile_rwunlock(profile); | ||||||
5934 | |||||||
5935 | switch_event_serialize_json(cbt.my_params, &ebuf); | ||||||
5936 | switch_event_destroy(&cbt.my_params); | ||||||
5937 | |||||||
5938 | switch_safe_free(sql)if (sql) {free(sql);sql=((void*)0);}; | ||||||
5939 | stream->write_function(stream, "%s", ebuf); | ||||||
5940 | switch_safe_free(ebuf)if (ebuf) {free(ebuf);ebuf=((void*)0);}; | ||||||
5941 | done: | ||||||
5942 | switch_core_destroy_memory_pool(&pool)switch_core_perform_destroy_memory_pool(&pool, "mod_voicemail.c" , (const char *)__func__, 5942); | ||||||
5943 | return SWITCH_STATUS_SUCCESS; | ||||||
5944 | } | ||||||
5945 | |||||||
5946 | #define VM_FSDB_MSG_EMAIL_USAGE"<profile> <domain> <user> <uuid> <email>" "<profile> <domain> <user> <uuid> <email>" | ||||||
5947 | SWITCH_STANDARD_API(vm_fsdb_msg_email_function)static switch_status_t vm_fsdb_msg_email_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | ||||||
5948 | { | ||||||
5949 | const char *id = NULL((void*)0), *domain = NULL((void*)0), *profile_name = NULL((void*)0), *uuid = NULL((void*)0), *email = NULL((void*)0); | ||||||
5950 | vm_profile_t *profile = NULL((void*)0); | ||||||
5951 | char *argv[7] = { 0 }; | ||||||
5952 | char *mycmd = NULL((void*)0); | ||||||
5953 | msg_get_callback_t cbt = { 0 }; | ||||||
5954 | char *sql; | ||||||
5955 | switch_memory_pool_t *pool; | ||||||
5956 | |||||||
5957 | switch_core_new_memory_pool(&pool)switch_core_perform_new_memory_pool(&pool, "mod_voicemail.c" , (const char *)__func__, 5957); | ||||||
5958 | |||||||
5959 | if (!zstr(cmd)_zstr(cmd)) { | ||||||
5960 | mycmd = switch_core_strdup(pool, cmd)switch_core_perform_strdup(pool, cmd, "mod_voicemail.c", (const char *)__func__, 5960); | ||||||
5961 | switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | ||||||
5962 | } | ||||||
5963 | |||||||
5964 | if (argv[0]) | ||||||
5965 | profile_name = argv[0]; | ||||||
5966 | if (argv[1]) | ||||||
5967 | domain = argv[1]; | ||||||
5968 | if (argv[2]) | ||||||
5969 | id = argv[2]; | ||||||
5970 | if (argv[3]) | ||||||
5971 | uuid = argv[3]; | ||||||
5972 | if (argv[4]) | ||||||
5973 | email = argv[4]; | ||||||
5974 | |||||||
5975 | if (!profile_name || !domain || !id || !uuid || !email) { | ||||||
5976 | stream->write_function(stream, "-ERR Missing Arguments\n"); | ||||||
5977 | goto done; | ||||||
5978 | } | ||||||
5979 | |||||||
5980 | if (!(profile = get_profile(profile_name))) { | ||||||
5981 | stream->write_function(stream, "-ERR Profile not found\n"); | ||||||
5982 | goto done; | ||||||
5983 | } else { | ||||||
5984 | char *from; | ||||||
5985 | char *headers, *header_string; | ||||||
5986 | char *body; | ||||||
5987 | int priority = 3; | ||||||
5988 | switch_size_t retsize; | ||||||
5989 | switch_time_exp_t tm; | ||||||
5990 | char date[80] = ""; | ||||||
5991 | int total_new_messages = 0; | ||||||
5992 | int total_saved_messages = 0; | ||||||
5993 | int total_new_urgent_messages = 0; | ||||||
5994 | int total_saved_urgent_messages = 0; | ||||||
5995 | int32_t message_len = 0; | ||||||
5996 | char *p; | ||||||
5997 | switch_time_t l_duration = 0; | ||||||
5998 | switch_core_time_duration_t duration; | ||||||
5999 | char duration_str[80]; | ||||||
6000 | char *formatted_cid_num = NULL((void*)0); | ||||||
6001 | |||||||
6002 | sql = switch_mprintf("select created_epoch, read_epoch, username, domain, uuid, cid_name, cid_number, in_folder, file_path, message_len, flags, read_flags, forwarded_by from voicemail_msgs WHERE username = '%q' AND domain = '%q' AND uuid = '%q' ORDER BY read_flags, created_epoch", id, domain, uuid); | ||||||
6003 | memset(&cbt, 0, sizeof(cbt)); | ||||||
6004 | switch_event_create(&cbt.my_params, SWITCH_EVENT_GENERAL)switch_event_create_subclass_detailed("mod_voicemail.c", (const char * )(const char *)__func__, 6004, &cbt.my_params, SWITCH_EVENT_GENERAL , ((void*)0)); | ||||||
6005 | vm_execute_sql_callback(profile, profile->mutex, sql, message_get_callback, &cbt); | ||||||
6006 | switch_safe_free(sql)if (sql) {free(sql);sql=((void*)0);}; | ||||||
6007 | |||||||
6008 | if (!strcasecmp(switch_event_get_header(cbt.my_params, "VM-Message-Read-Flags")switch_event_get_header_idx(cbt.my_params, "VM-Message-Read-Flags" , -1), URGENT_FLAG_STRING"A_URGENT")) { | ||||||
6009 | priority = 1; | ||||||
6010 | } | ||||||
6011 | |||||||
6012 | message_count(profile, id, domain, switch_event_get_header(cbt.my_params, "VM-Message-Folder")switch_event_get_header_idx(cbt.my_params, "VM-Message-Folder" , -1), &total_new_messages, &total_saved_messages, | ||||||
6013 | &total_new_urgent_messages, &total_saved_urgent_messages); | ||||||
6014 | |||||||
6015 | switch_time_exp_lt(&tm, switch_time_make(atol(switch_event_get_header(cbt.my_params, "VM-Message-Received-Epoch")switch_event_get_header_idx(cbt.my_params, "VM-Message-Received-Epoch" , -1)), 0)); | ||||||
6016 | switch_strftime(date, &retsize, sizeof(date), profile->date_fmt, &tm); | ||||||
6017 | |||||||
6018 | formatted_cid_num = switch_format_number(switch_event_get_header(cbt.my_params, "VM-Message-Caller-Number")switch_event_get_header_idx(cbt.my_params, "VM-Message-Caller-Number" , -1)); | ||||||
6019 | |||||||
6020 | /* Legacy Mod_VoiceMail variable */ | ||||||
6021 | switch_event_add_header_string(cbt.my_params, SWITCH_STACK_BOTTOM, "Message-Type", "forwarded-voicemail"); | ||||||
6022 | switch_event_add_header(cbt.my_params, SWITCH_STACK_BOTTOM, "voicemail_total_new_messages", "%d", total_new_messages); | ||||||
6023 | switch_event_add_header(cbt.my_params, SWITCH_STACK_BOTTOM, "voicemail_total_saved_messages", "%d", total_saved_messages); | ||||||
6024 | switch_event_add_header(cbt.my_params, SWITCH_STACK_BOTTOM, "voicemail_urgent_new_messages", "%d", total_new_urgent_messages); | ||||||
6025 | switch_event_add_header(cbt.my_params, SWITCH_STACK_BOTTOM, "voicemail_urgent_saved_messages", "%d", total_saved_urgent_messages); | ||||||
6026 | switch_event_add_header_string(cbt.my_params, SWITCH_STACK_BOTTOM, "voicemail_current_folder", switch_event_get_header(cbt.my_params, "VM-Message-Folder")switch_event_get_header_idx(cbt.my_params, "VM-Message-Folder" , -1)); | ||||||
6027 | switch_event_add_header_string(cbt.my_params, SWITCH_STACK_BOTTOM, "voicemail_account", id); | ||||||
6028 | switch_event_add_header_string(cbt.my_params, SWITCH_STACK_BOTTOM, "voicemail_domain", domain); | ||||||
6029 | switch_event_add_header_string(cbt.my_params, SWITCH_STACK_BOTTOM, "voicemail_caller_id_number", switch_event_get_header(cbt.my_params, "VM-Message-Caller-Number")switch_event_get_header_idx(cbt.my_params, "VM-Message-Caller-Number" , -1)); | ||||||
6030 | switch_event_add_header_string(cbt.my_params, SWITCH_STACK_BOTTOM, "voicemail_formatted_caller_id_number", formatted_cid_num); | ||||||
6031 | switch_event_add_header_string(cbt.my_params, SWITCH_STACK_BOTTOM, "voicemail_caller_id_name", switch_event_get_header(cbt.my_params, "VM-Message-Caller-Name")switch_event_get_header_idx(cbt.my_params, "VM-Message-Caller-Name" , -1)); | ||||||
6032 | switch_event_add_header_string(cbt.my_params, SWITCH_STACK_BOTTOM, "voicemail_file_path", switch_event_get_header(cbt.my_params, "VM-Message-File-Path")switch_event_get_header_idx(cbt.my_params, "VM-Message-File-Path" , -1)); | ||||||
6033 | switch_event_add_header_string(cbt.my_params, SWITCH_STACK_BOTTOM, "voicemail_read_flags", switch_event_get_header(cbt.my_params, "VM-Message-Read-Flags")switch_event_get_header_idx(cbt.my_params, "VM-Message-Read-Flags" , -1)); | ||||||
6034 | switch_event_add_header_string(cbt.my_params, SWITCH_STACK_BOTTOM, "voicemail_time", date); | ||||||
6035 | switch_event_add_header(cbt.my_params, SWITCH_STACK_BOTTOM, "voicemail_priority", "%d", priority); | ||||||
6036 | |||||||
6037 | |||||||
6038 | message_len = atoi(switch_event_get_header(cbt.my_params, "VM-Message-Duration")switch_event_get_header_idx(cbt.my_params, "VM-Message-Duration" , -1)); | ||||||
6039 | switch_safe_free(formatted_cid_num)if (formatted_cid_num) {free(formatted_cid_num);formatted_cid_num =((void*)0);}; | ||||||
6040 | |||||||
6041 | l_duration = switch_time_make(atol(switch_event_get_header(cbt.my_params, "VM-Message-Duration")switch_event_get_header_idx(cbt.my_params, "VM-Message-Duration" , -1)), 0); | ||||||
6042 | switch_core_measure_time(l_duration, &duration); | ||||||
6043 | duration.day += duration.yr * 365; | ||||||
6044 | duration.hr += duration.day * 24; | ||||||
6045 | |||||||
6046 | switch_snprintf(duration_str, sizeof(duration_str), "%.2u:%.2u:%.2u", duration.hr, duration.min, duration.sec); | ||||||
6047 | |||||||
6048 | switch_event_add_header_string(cbt.my_params, SWITCH_STACK_BOTTOM, "voicemail_message_len", duration_str); | ||||||
6049 | switch_event_add_header_string(cbt.my_params, SWITCH_STACK_BOTTOM, "voicemail_email", email); | ||||||
6050 | |||||||
6051 | if (zstr(profile->email_from)_zstr(profile->email_from)) { | ||||||
6052 | from = switch_core_sprintf(pool, "%s@%s", id, domain); | ||||||
6053 | } else { | ||||||
6054 | from = switch_event_expand_headers(cbt.my_params, profile->email_from)switch_event_expand_headers_check(cbt.my_params, profile-> email_from, ((void*)0), ((void*)0), 0);; | ||||||
6055 | } | ||||||
6056 | |||||||
6057 | if (zstr(profile->email_headers)_zstr(profile->email_headers)) { | ||||||
6058 | headers = switch_core_sprintf(pool, | ||||||
6059 | "From: FreeSWITCH mod_voicemail <%s@%s>\nSubject: Voicemail from %s %s\nX-Priority: %d", | ||||||
6060 | id, domain, switch_event_get_header(cbt.my_params, "VM-Message-Caller-Name")switch_event_get_header_idx(cbt.my_params, "VM-Message-Caller-Name" , -1), | ||||||
6061 | switch_event_get_header(cbt.my_params, "VM-Message-Caller-Number")switch_event_get_header_idx(cbt.my_params, "VM-Message-Caller-Number" , -1), priority); | ||||||
6062 | } else { | ||||||
6063 | headers = switch_event_expand_headers(cbt.my_params, profile->email_headers)switch_event_expand_headers_check(cbt.my_params, profile-> email_headers, ((void*)0), ((void*)0), 0); | ||||||
6064 | } | ||||||
6065 | |||||||
6066 | p = headers + (strlen(headers) - 1); | ||||||
6067 | if (*p == '\n') { | ||||||
6068 | if (*(p - 1) == '\r') { | ||||||
6069 | p--; | ||||||
6070 | } | ||||||
6071 | *p = '\0'; | ||||||
6072 | } | ||||||
6073 | |||||||
6074 | header_string = switch_core_sprintf(pool, "%s\nX-Voicemail-Length: %u", headers, message_len); | ||||||
6075 | |||||||
6076 | if (profile->email_body) { | ||||||
6077 | body = switch_event_expand_headers(cbt.my_params, profile->email_body)switch_event_expand_headers_check(cbt.my_params, profile-> email_body, ((void*)0), ((void*)0), 0); | ||||||
6078 | } else { | ||||||
6079 | body = switch_mprintf("%u second Voicemail from %s %s", message_len, switch_event_get_header(cbt.my_params, "VM-Message-Caller-Name")switch_event_get_header_idx(cbt.my_params, "VM-Message-Caller-Name" , -1), switch_event_get_header(cbt.my_params, "VM-Message-Caller-Number")switch_event_get_header_idx(cbt.my_params, "VM-Message-Caller-Number" , -1)); | ||||||
6080 | } | ||||||
6081 | |||||||
6082 | switch_simple_email(email, from, header_string, body, switch_event_get_header(cbt.my_params, "VM-Message-File-Path")switch_event_get_header_idx(cbt.my_params, "VM-Message-File-Path" , -1), profile->convert_cmd, profile->convert_ext); | ||||||
6083 | switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session)SWITCH_CHANNEL_ID_SESSION, "mod_voicemail.c", (const char *)__func__ , 6083, (const char*)(session), SWITCH_LOG_DEBUG, "Sending message to %s\n", email); | ||||||
6084 | switch_safe_free(body)if (body) {free(body);body=((void*)0);}; | ||||||
6085 | |||||||
6086 | switch_event_fire(&cbt.my_params)switch_event_fire_detailed("mod_voicemail.c", (const char * ) (const char *)__func__, 6086, &cbt.my_params, ((void*)0)); | ||||||
6087 | |||||||
6088 | |||||||
6089 | profile_rwunlock(profile); | ||||||
6090 | } | ||||||
6091 | stream->write_function(stream, "-OK\n"); | ||||||
6092 | done: | ||||||
6093 | switch_core_destroy_memory_pool(&pool)switch_core_perform_destroy_memory_pool(&pool, "mod_voicemail.c" , (const char *)__func__, 6093); | ||||||
6094 | |||||||
6095 | return SWITCH_STATUS_SUCCESS; | ||||||
6096 | } | ||||||
6097 | |||||||
6098 | #define VM_FSDB_MSG_COUNT_USAGE"<format> <profile> <domain> <user> <folder>" "<format> <profile> <domain> <user> <folder>" | ||||||
6099 | SWITCH_STANDARD_API(vm_fsdb_msg_count_function)static switch_status_t vm_fsdb_msg_count_function ( const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) | ||||||
6100 | { | ||||||
6101 | char *sql; | ||||||
6102 | msg_cnt_callback_t cbt = { 0 }; | ||||||
6103 | switch_event_t *my_params = NULL((void*)0); | ||||||
6104 | char *ebuf = NULL((void*)0); | ||||||
6105 | |||||||
6106 | const char *id = NULL((void*)0), *domain = NULL((void*)0), *profile_name = NULL((void*)0), *folder = NULL((void*)0); | ||||||
6107 | vm_profile_t *profile = NULL((void*)0); | ||||||
6108 | |||||||
6109 | char *argv[6] = { 0 }; | ||||||
6110 | char *mycmd = NULL((void*)0); | ||||||
6111 | |||||||
6112 | switch_memory_pool_t *pool; | ||||||
6113 | |||||||
6114 | switch_core_new_memory_pool(&pool)switch_core_perform_new_memory_pool(&pool, "mod_voicemail.c" , (const char *)__func__, 6114); | ||||||
6115 | |||||||
6116 | if (!zstr(cmd)_zstr(cmd)) { | ||||||
6117 | mycmd = switch_core_strdup(pool, cmd)switch_core_perform_strdup(pool, cmd, "mod_voicemail.c", (const char *)__func__, 6117); | ||||||
6118 | switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); | ||||||
6119 | } | ||||||
6120 | |||||||
6121 | if (argv[1]) | ||||||
6122 | profile_name = argv[1]; | ||||||
6123 | if (argv[2]) | ||||||
6124 | domain = argv[2]; | ||||||
6125 | if (argv[3]) | ||||||
6126 | id = argv[3]; | ||||||
6127 | if (argv[4]) | ||||||
6128 | folder = argv[4]; | ||||||
6129 | |||||||
6130 | if (!profile_name || !domain || !id || !folder) { | ||||||
6131 | stream->write_function(stream, "-ERR Missing Arguments\n"); | ||||||
6132 | goto done; | ||||||
6133 | } | ||||||
6134 | |||||||
6135 | if (!(profile = get_profile(profile_name))) { | ||||||
6136 | stream->write_function(stream, "-ERR Profile not found\n"); | ||||||
6137 | goto done; | ||||||
6138 | } | ||||||
6139 | |||||||
6140 | sql = switch_mprintf( | ||||||
6141 | "SELECT 1, read_flags, count(read_epoch) FROM voicemail_msgs WHERE username = '%q' AND domain = '%q' AND in_folder = '%q' AND flags = '' AND in_folder = '%q' GROUP BY read_flags " | ||||||
6142 | "UNION " | ||||||
6143 | "SELECT 0, read_flags, count(read_epoch) FROM voicemail_msgs WHERE username = '%q' AND domain = '%q' AND in_folder = '%q' AND flags = 'save' AND in_folder= '%q' GROUP BY read_flags;", | ||||||
6144 | id, domain, "inbox", folder, | ||||||
6145 | id, domain, "inbox", folder); | ||||||
6146 | |||||||
6147 | |||||||
6148 | vm_execute_sql_callback(profile, profile->mutex, sql, message_count_callback, &cbt); | ||||||
6149 | |||||||
6150 | profile_rwunlock(profile); | ||||||
6151 | |||||||
6152 | switch_event_create(&my_params, SWITCH_EVENT_REQUEST_PARAMS)switch_event_create_subclass_detailed("mod_voicemail.c", (const char * )(const char *)__func__, 6152, &my_params, SWITCH_EVENT_REQUEST_PARAMS , ((void*)0)); | ||||||
6153 | switch_event_add_header(my_params, SWITCH_STACK_BOTTOM, "VM-Total-New-Messages", "%d", cbt.total_new_messages + cbt.total_new_urgent_messages); | ||||||
6154 | switch_event_add_header(my_params, SWITCH_STACK_BOTTOM, "VM-Total-New-Urgent-Messages", "%d", cbt.total_new_urgent_messages); | ||||||
6155 | switch_event_add_header(my_params, SWITCH_STACK_BOTTOM, "VM-Total-Saved-Messages", "%d", cbt.total_saved_messages + cbt.total_saved_urgent_messages); | ||||||
6156 | switch_event_add_header(my_params, SWITCH_STACK_BOTTOM, "VM-Total-Saved-Urgent-Messages", "%d", cbt.total_saved_urgent_messages); | ||||||
6157 | switch_event_serialize_json(my_params, &ebuf); | ||||||
6158 | switch_event_destroy(&my_params); | ||||||
6159 | |||||||
6160 | switch_safe_free(sql)if (sql) {free(sql);sql=((void*)0);}; | ||||||
6161 | stream->write_function(stream, "%s", ebuf); | ||||||
6162 | switch_safe_free(ebuf)if (ebuf) {free(ebuf);ebuf=((void*)0);}; | ||||||
6163 | done: | ||||||
6164 | switch_core_destroy_memory_pool(&pool)switch_core_perform_destroy_memory_pool(&pool, "mod_voicemail.c" , (const char *)__func__, 6164); | ||||||
6165 | return SWITCH_STATUS_SUCCESS; | ||||||
6166 | } | ||||||
6167 | |||||||
6168 | SWITCH_MODULE_LOAD_FUNCTION(mod_voicemail_load)switch_status_t mod_voicemail_load (switch_loadable_module_interface_t **module_interface, switch_memory_pool_t *pool) | ||||||
6169 | { | ||||||
6170 | switch_application_interface_t *app_interface; | ||||||
6171 | switch_api_interface_t *commands_api_interface; | ||||||
6172 | switch_status_t status; | ||||||
6173 | |||||||
6174 | /* create/register custom event message type */ | ||||||
6175 | if (switch_event_reserve_subclass(VM_EVENT_MAINT)switch_event_reserve_subclass_detailed("mod_voicemail.c", "vm::maintenance" ) != SWITCH_STATUS_SUCCESS) { | ||||||
6176 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 6176, ((void*)0), SWITCH_LOG_ERROR, "Couldn't register subclass %s!\n", VM_EVENT_MAINT"vm::maintenance"); | ||||||
6177 | return SWITCH_STATUS_TERM; | ||||||
6178 | } | ||||||
6179 | |||||||
6180 | memset(&globals, 0, sizeof(globals)); | ||||||
6181 | globals.pool = pool; | ||||||
6182 | |||||||
6183 | switch_core_hash_init(&globals.profile_hash)switch_core_hash_init_case(&globals.profile_hash, SWITCH_TRUE ); | ||||||
6184 | switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED0x1, globals.pool); | ||||||
6185 | |||||||
6186 | switch_mutex_lock(globals.mutex); | ||||||
6187 | globals.running = 1; | ||||||
6188 | switch_mutex_unlock(globals.mutex); | ||||||
6189 | |||||||
6190 | switch_queue_create(&globals.event_queue, VM_EVENT_QUEUE_SIZE50000, globals.pool); | ||||||
6191 | |||||||
6192 | if ((status = load_config()) != SWITCH_STATUS_SUCCESS) { | ||||||
6193 | globals.running = 0; | ||||||
6194 | return status; | ||||||
6195 | } | ||||||
6196 | /* connect my internal structure to the blank pointer passed to me */ | ||||||
6197 | *module_interface = switch_loadable_module_create_module_interface(pool, modname); | ||||||
6198 | |||||||
6199 | if (switch_event_bind(modname, SWITCH_EVENT_MESSAGE_QUERY, SWITCH_EVENT_SUBCLASS_ANY((void*)0), vm_event_handler, NULL((void*)0)) | ||||||
6200 | != SWITCH_STATUS_SUCCESS) { | ||||||
6201 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 6201, ((void*)0), SWITCH_LOG_ERROR, "Couldn't bind!\n"); | ||||||
6202 | return SWITCH_STATUS_GENERR; | ||||||
6203 | } | ||||||
6204 | |||||||
6205 | SWITCH_ADD_APP(app_interface, "voicemail", "Voicemail", VM_DESC, voicemail_function, VM_USAGE, SAF_NONE)for (;;) { app_interface = (switch_application_interface_t *) switch_loadable_module_create_interface(*module_interface, SWITCH_APPLICATION_INTERFACE ); app_interface->interface_name = "voicemail"; app_interface ->application_function = voicemail_function; app_interface ->short_desc = "Voicemail"; app_interface->long_desc = "voicemail" ; app_interface->syntax = "[check] [auth] <profile_name> <domain_name> [<id>] [uuid]" ; app_interface->flags = SAF_NONE; break; }; | ||||||
6206 | SWITCH_ADD_API(commands_api_interface, "voicemail", "voicemail", voicemail_api_function, VOICEMAIL_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "voicemail"; commands_api_interface ->desc = "voicemail"; commands_api_interface->function = voicemail_api_function; commands_api_interface->syntax = "rss [<host> <port> <uri> <user> <domain>] | [load|unload|reload] <profile> [reloadxml]" ; break; }; | ||||||
6207 | SWITCH_ADD_API(commands_api_interface, "voicemail_inject", "voicemail_inject", voicemail_inject_api_function, VM_INJECT_USAGE)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "voicemail_inject" ; commands_api_interface->desc = "voicemail_inject"; commands_api_interface ->function = voicemail_inject_api_function; commands_api_interface ->syntax = "[group=<group>[@domain]|domain=<domain>|<box>[@<domain>]] <sound_file> [<cid_num>] [<cid_name>]" ; break; }; | ||||||
6208 | SWITCH_ADD_API(commands_api_interface, "vm_inject", "vm_inject", voicemail_inject_api_function, VM_INJECT_USAGE)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "vm_inject"; commands_api_interface ->desc = "vm_inject"; commands_api_interface->function = voicemail_inject_api_function; commands_api_interface->syntax = "[group=<group>[@domain]|domain=<domain>|<box>[@<domain>]] <sound_file> [<cid_num>] [<cid_name>]" ; break; }; | ||||||
6209 | SWITCH_ADD_API(commands_api_interface, "vm_boxcount", "vm_boxcount", boxcount_api_function, BOXCOUNT_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "vm_boxcount"; commands_api_interface->desc = "vm_boxcount"; commands_api_interface ->function = boxcount_api_function; commands_api_interface ->syntax = "[profile/]<user>@<domain>[|[new|saved|new-urgent|saved-urgent|all]]" ; break; }; | ||||||
6210 | SWITCH_ADD_API(commands_api_interface, "vm_prefs", "vm_prefs", prefs_api_function, PREFS_SYNTAX)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "vm_prefs"; commands_api_interface ->desc = "vm_prefs"; commands_api_interface->function = prefs_api_function; commands_api_interface->syntax = "[profile/]<user>@<domain>[|[name_path|greeting_path|password]]" ; break; }; | ||||||
6211 | SWITCH_ADD_API(commands_api_interface, "vm_delete", "vm_delete", voicemail_delete_api_function, VM_DELETE_USAGE)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "vm_delete"; commands_api_interface ->desc = "vm_delete"; commands_api_interface->function = voicemail_delete_api_function; commands_api_interface->syntax = "<id>@<domain>[/profile] [<uuid>]"; break ; }; | ||||||
6212 | SWITCH_ADD_API(commands_api_interface, "vm_read", "vm_read", voicemail_read_api_function, VM_READ_USAGE)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "vm_read"; commands_api_interface ->desc = "vm_read"; commands_api_interface->function = voicemail_read_api_function ; commands_api_interface->syntax = "<id>@<domain>[/profile] <read|unread> [<uuid>]" ; break; }; | ||||||
6213 | SWITCH_ADD_API(commands_api_interface, "vm_list", "vm_list", voicemail_list_api_function, VM_LIST_USAGE)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "vm_list"; commands_api_interface ->desc = "vm_list"; commands_api_interface->function = voicemail_list_api_function ; commands_api_interface->syntax = "<id>@<domain>[/profile] [xml]" ; break; }; | ||||||
6214 | |||||||
6215 | /* Auth API */ | ||||||
6216 | SWITCH_ADD_API(commands_api_interface, "vm_fsdb_auth_login", "vm_fsdb_auth_login", vm_fsdb_auth_login_function, VM_FSDB_AUTH_LOGIN_USAGE)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "vm_fsdb_auth_login" ; commands_api_interface->desc = "vm_fsdb_auth_login"; commands_api_interface ->function = vm_fsdb_auth_login_function; commands_api_interface ->syntax = "<profile> <domain> <user> <password>" ; break; }; | ||||||
6217 | |||||||
6218 | /* Message Targeted API */ | ||||||
6219 | SWITCH_ADD_API(commands_api_interface, "vm_fsdb_msg_count", "vm_fsdb_msg_count", vm_fsdb_msg_count_function, VM_FSDB_MSG_COUNT_USAGE)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "vm_fsdb_msg_count" ; commands_api_interface->desc = "vm_fsdb_msg_count"; commands_api_interface ->function = vm_fsdb_msg_count_function; commands_api_interface ->syntax = "<format> <profile> <domain> <user> <folder>" ; break; }; | ||||||
6220 | SWITCH_ADD_API(commands_api_interface, "vm_fsdb_msg_list", "vm_fsdb_msg_list", vm_fsdb_msg_list_function, VM_FSDB_MSG_LIST_USAGE)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "vm_fsdb_msg_list" ; commands_api_interface->desc = "vm_fsdb_msg_list"; commands_api_interface ->function = vm_fsdb_msg_list_function; commands_api_interface ->syntax = "<format> <profile> <domain> <user> <folder> <filter> [msg-order = ASC | DESC]" ; break; }; | ||||||
6221 | SWITCH_ADD_API(commands_api_interface, "vm_fsdb_msg_get", "vm_fsdb_msg_get", vm_fsdb_msg_get_function, VM_FSDB_MSG_GET_USAGE)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "vm_fsdb_msg_get" ; commands_api_interface->desc = "vm_fsdb_msg_get"; commands_api_interface ->function = vm_fsdb_msg_get_function; commands_api_interface ->syntax = "<format> <profile> <domain> <user> <uuid>" ; break; }; | ||||||
6222 | SWITCH_ADD_API(commands_api_interface, "vm_fsdb_msg_delete", "vm_fsdb_msg_delete", vm_fsdb_msg_delete_function, VM_FSDB_MSG_DELETE_USAGE)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "vm_fsdb_msg_delete" ; commands_api_interface->desc = "vm_fsdb_msg_delete"; commands_api_interface ->function = vm_fsdb_msg_delete_function; commands_api_interface ->syntax = "<profile> <domain> <user> <uuid>" ; break; }; | ||||||
6223 | SWITCH_ADD_API(commands_api_interface, "vm_fsdb_msg_undelete", "vm_fsdb_msg_undelete", vm_fsdb_msg_undelete_function, VM_FSDB_MSG_UNDELETE_USAGE)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "vm_fsdb_msg_undelete" ; commands_api_interface->desc = "vm_fsdb_msg_undelete"; commands_api_interface ->function = vm_fsdb_msg_undelete_function; commands_api_interface ->syntax = "<profile> <domain> <user> <uuid>" ; break; }; | ||||||
6224 | SWITCH_ADD_API(commands_api_interface, "vm_fsdb_msg_email", "vm_fsdb_msg_email", vm_fsdb_msg_email_function, VM_FSDB_MSG_EMAIL_USAGE)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "vm_fsdb_msg_email" ; commands_api_interface->desc = "vm_fsdb_msg_email"; commands_api_interface ->function = vm_fsdb_msg_email_function; commands_api_interface ->syntax = "<profile> <domain> <user> <uuid> <email>" ; break; }; | ||||||
6225 | SWITCH_ADD_API(commands_api_interface, "vm_fsdb_msg_purge", "vm_fsdb_msg_purge", vm_fsdb_msg_purge_function, VM_FSDB_MSG_PURGE_USAGE)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "vm_fsdb_msg_purge" ; commands_api_interface->desc = "vm_fsdb_msg_purge"; commands_api_interface ->function = vm_fsdb_msg_purge_function; commands_api_interface ->syntax = "<profile> <domain> <user>"; break ; }; | ||||||
6226 | SWITCH_ADD_API(commands_api_interface, "vm_fsdb_msg_save", "vm_fsdb_msg_save", vm_fsdb_msg_save_function, VM_FSDB_MSG_SAVE_USAGE)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "vm_fsdb_msg_save" ; commands_api_interface->desc = "vm_fsdb_msg_save"; commands_api_interface ->function = vm_fsdb_msg_save_function; commands_api_interface ->syntax = "<profile> <domain> <user> <uuid>" ; break; }; | ||||||
6227 | SWITCH_ADD_API(commands_api_interface, "vm_fsdb_msg_forward", "vm_fsdb_msg_forward", vm_fsdb_msg_forward_function, VM_FSDB_MSG_FORWARD_USAGE)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "vm_fsdb_msg_forward" ; commands_api_interface->desc = "vm_fsdb_msg_forward"; commands_api_interface ->function = vm_fsdb_msg_forward_function; commands_api_interface ->syntax = "<profile> <domain> <user> <uuid> <dst_domain> <dst_user> [prepend_file_location]" ; break; }; | ||||||
6228 | |||||||
6229 | /* Preferences */ | ||||||
6230 | SWITCH_ADD_API(commands_api_interface, "vm_fsdb_pref_greeting_set", "vm_fsdb_pref_greeting_set", vm_fsdb_pref_greeting_set_function, VM_FSDB_PREF_GREETING_SET_USAGE)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "vm_fsdb_pref_greeting_set" ; commands_api_interface->desc = "vm_fsdb_pref_greeting_set" ; commands_api_interface->function = vm_fsdb_pref_greeting_set_function ; commands_api_interface->syntax = "<profile> <domain> <user> <slot> [file-path]" ; break; }; | ||||||
6231 | SWITCH_ADD_API(commands_api_interface, "vm_fsdb_pref_greeting_get", "vm_fsdb_pref_greeting_get", vm_fsdb_pref_greeting_get_function, VM_FSDB_PREF_GREETING_GET_USAGE)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "vm_fsdb_pref_greeting_get" ; commands_api_interface->desc = "vm_fsdb_pref_greeting_get" ; commands_api_interface->function = vm_fsdb_pref_greeting_get_function ; commands_api_interface->syntax = "<format> <profile> <domain> <user> [slot]" ; break; }; | ||||||
6232 | SWITCH_ADD_API(commands_api_interface, "vm_fsdb_pref_recname_set", "vm_fsdb_pref_recname_set", vm_fsdb_pref_recname_set_function, VM_FSDB_PREF_RECNAME_SET_USAGE)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "vm_fsdb_pref_recname_set" ; commands_api_interface->desc = "vm_fsdb_pref_recname_set" ; commands_api_interface->function = vm_fsdb_pref_recname_set_function ; commands_api_interface->syntax = "<profile> <domain> <user> <file-path>" ; break; }; | ||||||
6233 | SWITCH_ADD_API(commands_api_interface, "vm_fsdb_pref_password_set", "vm_fsdb_pref_password_set", vm_fsdb_pref_password_set_function, VM_FSDB_PREF_PASSWORD_SET_USAGE)for (;;) { commands_api_interface = (switch_api_interface_t * )switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE ); commands_api_interface->interface_name = "vm_fsdb_pref_password_set" ; commands_api_interface->desc = "vm_fsdb_pref_password_set" ; commands_api_interface->function = vm_fsdb_pref_password_set_function ; commands_api_interface->syntax = "<profile> <domain> <user> <password>" ; break; }; | ||||||
6234 | |||||||
6235 | return SWITCH_STATUS_SUCCESS; | ||||||
6236 | } | ||||||
6237 | |||||||
6238 | |||||||
6239 | SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_voicemail_shutdown)switch_status_t mod_voicemail_shutdown (void) | ||||||
6240 | { | ||||||
6241 | switch_hash_index_t *hi = NULL((void*)0); | ||||||
6242 | vm_profile_t *profile; | ||||||
6243 | void *val = NULL((void*)0); | ||||||
6244 | const void *key; | ||||||
6245 | switch_ssize_t keylen; | ||||||
6246 | int sanity = 0; | ||||||
6247 | |||||||
6248 | switch_mutex_lock(globals.mutex); | ||||||
6249 | if (globals.running == 1) { | ||||||
6250 | globals.running = 0; | ||||||
6251 | } | ||||||
6252 | switch_mutex_unlock(globals.mutex); | ||||||
6253 | |||||||
6254 | switch_event_free_subclass(VM_EVENT_MAINT)switch_event_free_subclass_detailed("mod_voicemail.c", "vm::maintenance" ); | ||||||
6255 | switch_event_unbind_callback(vm_event_handler); | ||||||
6256 | |||||||
6257 | while (globals.threads) { | ||||||
6258 | switch_cond_next(); | ||||||
6259 | if (++sanity >= 60000) { | ||||||
6260 | break; | ||||||
6261 | } | ||||||
6262 | } | ||||||
6263 | |||||||
6264 | switch_mutex_lock(globals.mutex); | ||||||
6265 | while ((hi = switch_core_hash_first_iter( globals.profile_hash, hi))) { | ||||||
6266 | switch_core_hash_this(hi, &key, &keylen, &val); | ||||||
6267 | profile = (vm_profile_t *) val; | ||||||
6268 | |||||||
6269 | switch_core_hash_delete(globals.profile_hash, profile->name); | ||||||
6270 | |||||||
6271 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 6271, ((void*)0), SWITCH_LOG_DEBUG, "Waiting for write lock (Profile %s)\n", profile->name); | ||||||
6272 | switch_thread_rwlock_wrlock(profile->rwlock); | ||||||
6273 | |||||||
6274 | switch_log_printf(SWITCH_CHANNEL_LOGSWITCH_CHANNEL_ID_LOG, "mod_voicemail.c", (const char *)__func__ , 6274, ((void*)0), SWITCH_LOG_DEBUG, "Destroying Profile %s\n", profile->name); | ||||||
6275 | |||||||
6276 | switch_core_destroy_memory_pool(&profile->pool)switch_core_perform_destroy_memory_pool(&profile->pool , "mod_voicemail.c", (const char *)__func__, 6276); | ||||||
6277 | profile = NULL((void*)0); | ||||||
6278 | } | ||||||
6279 | switch_core_hash_destroy(&globals.profile_hash); | ||||||
6280 | switch_mutex_unlock(globals.mutex); | ||||||
6281 | switch_mutex_destroy(globals.mutex); | ||||||
6282 | |||||||
6283 | return SWITCH_STATUS_SUCCESS; | ||||||
6284 | } | ||||||
6285 | |||||||
6286 | |||||||
6287 | /* For Emacs: | ||||||
6288 | * Local Variables: | ||||||
6289 | * mode:c | ||||||
6290 | * indent-tabs-mode:t | ||||||
6291 | * tab-width:4 | ||||||
6292 | * c-basic-offset:4 | ||||||
6293 | * End: | ||||||
6294 | * For VIM: | ||||||
6295 | * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet: | ||||||
6296 | */ |