/
mod_voicemail.c
6319 lines (5216 loc) · 214 KB
/
mod_voicemail.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
*
* The Initial Developer of the Original Code is
* Anthony Minessale II <anthm@freeswitch.org>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Anthony Minessale II <anthm@freeswitch.org>
* Bret McDanel <trixter AT 0xdecafbad.com>
* John Wehle (john@feith.com)
* Raymond Chandler <intralanman@gmail.com>
* Kristin King <kristin.king@quentustech.com>
* Emmanuel Schmidbauer <eschmidbauer@gmail.com>
*
* mod_voicemail.c -- Voicemail Module
*
*/
#include <switch.h>
#ifdef _MSC_VER /* compilers are stupid sometimes */
#define TRY_CODE(code) for(;;) {status = code; if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) { goto end; } break;}
#else
#define TRY_CODE(code) do { status = code; if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) { goto end; } break;} while(status)
#endif
#define xml_safe_free(_x) if (_x) switch_xml_free(_x); _x = NULL
SWITCH_MODULE_LOAD_FUNCTION(mod_voicemail_load);
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_voicemail_shutdown);
SWITCH_MODULE_DEFINITION(mod_voicemail, mod_voicemail_load, mod_voicemail_shutdown, NULL);
#define VM_EVENT_MAINT "vm::maintenance"
#define VM_MAX_GREETINGS 9
#define VM_EVENT_QUEUE_SIZE 50000
static switch_status_t voicemail_inject(const char *data, switch_core_session_t *session);
static const char *global_cf = "voicemail.conf";
static struct {
switch_hash_t *profile_hash;
int debug;
int message_query_exact_match;
int32_t threads;
int32_t running;
switch_queue_t *event_queue;
switch_mutex_t *mutex;
switch_memory_pool_t *pool;
} globals;
typedef enum {
VM_DATE_FIRST,
VM_DATE_LAST,
VM_DATE_NEVER
} date_location_t;
typedef enum {
PFLAG_DESTROY = 1 << 0
} vm_flags_t;
typedef enum {
VM_MOVE_NEXT,
VM_MOVE_PREV,
VM_MOVE_SAME
} msg_move_t;
typedef enum {
MWI_REASON_UNKNOWN = 0,
MWI_REASON_NEW = 1,
MWI_REASON_DELETE = 2,
MWI_REASON_SAVE = 3,
MWI_REASON_PURGE = 4,
MWI_REASON_READ = 5
} mwi_reason_t;
struct mwi_reason_table {
const char *name;
int state;
};
static struct mwi_reason_table MWI_REASON_CHART[] = {
{"UNKNOWN", MWI_REASON_UNKNOWN},
{"NEW", MWI_REASON_NEW},
{"DELETE", MWI_REASON_DELETE},
{"SAVE", MWI_REASON_SAVE},
{"PURGE", MWI_REASON_PURGE},
{"READ", MWI_REASON_READ},
{NULL, 0}
};
#define VM_PROFILE_CONFIGITEM_COUNT 100
struct vm_profile {
char *name;
char *dbname;
char *odbc_dsn;
char *play_new_messages_lifo;
char *play_saved_messages_lifo;
char terminator_key[2];
char play_new_messages_key[2];
char play_saved_messages_key[2];
char login_keys[16];
char main_menu_key[2];
char skip_greet_key[2];
char skip_info_key[2];
char config_menu_key[2];
char record_greeting_key[2];
char choose_greeting_key[2];
char record_name_key[2];
char change_pass_key[2];
char record_file_key[2];
char listen_file_key[2];
char save_file_key[2];
char delete_file_key[2];
char undelete_file_key[2];
char email_key[2];
char callback_key[2];
char pause_key[2];
char restart_key[2];
char ff_key[2];
char rew_key[2];
char prev_msg_key[2];
char next_msg_key[2];
char repeat_msg_key[2];
char urgent_key[2];
char operator_key[2];
char vmain_key[2];
char forward_key[2];
char prepend_key[2];
char file_ext[10];
char *record_title;
char *record_comment;
char *record_copyright;
char *operator_ext;
char *vmain_ext;
char *tone_spec;
char *storage_dir;
switch_bool_t storage_dir_shared;
char *callback_dialplan;
char *callback_context;
char *email_body;
char *email_headers;
char *notify_email_body;
char *notify_email_headers;
char *web_head;
char *web_tail;
char *email_from;
char *date_fmt;
char *convert_cmd;
char *convert_ext;
date_location_t play_date_announcement;
uint32_t digit_timeout;
uint32_t max_login_attempts;
uint32_t min_record_len;
uint32_t max_record_len;
uint32_t max_retries;
switch_mutex_t *mutex;
uint32_t record_threshold;
uint32_t record_silence_hits;
uint32_t record_sample_rate;
switch_bool_t auto_playback_recordings;
switch_bool_t db_password_override;
switch_bool_t allow_empty_password_auth;
switch_bool_t send_full_vm_header;
switch_thread_rwlock_t *rwlock;
switch_memory_pool_t *pool;
uint32_t flags;
switch_xml_config_item_t config[VM_PROFILE_CONFIGITEM_COUNT];
switch_xml_config_string_options_t config_str_pool;
};
typedef struct vm_profile vm_profile_t;
const char * mwi_reason2str(mwi_reason_t state)
{
uint8_t x;
const char *str = "UNKNOWN";
for (x = 0; x < (sizeof(MWI_REASON_CHART) / sizeof(struct mwi_reason_table)) - 1; x++) {
if (MWI_REASON_CHART[x].state == state) {
str = MWI_REASON_CHART[x].name;
break;
}
}
return str;
}
switch_cache_db_handle_t *vm_get_db_handle(vm_profile_t *profile)
{
switch_cache_db_handle_t *dbh = NULL;
char *dsn;
if (!zstr(profile->odbc_dsn)) {
dsn = profile->odbc_dsn;
} else {
dsn = profile->dbname;
}
if (switch_cache_db_get_db_handle_dsn(&dbh, dsn) != SWITCH_STATUS_SUCCESS) {
dbh = NULL;
}
return dbh;
}
static switch_status_t vm_execute_sql(vm_profile_t *profile, char *sql, switch_mutex_t *mutex)
{
switch_cache_db_handle_t *dbh = NULL;
switch_status_t status = SWITCH_STATUS_FALSE;
if (mutex) {
switch_mutex_lock(mutex);
}
if (!(dbh = vm_get_db_handle(profile))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB\n");
goto end;
}
status = switch_cache_db_execute_sql(dbh, sql, NULL);
end:
switch_cache_db_release_db_handle(&dbh);
if (mutex) {
switch_mutex_unlock(mutex);
}
return status;
}
char *vm_execute_sql2str(vm_profile_t *profile, switch_mutex_t *mutex, char *sql, char *resbuf, size_t len)
{
switch_cache_db_handle_t *dbh = NULL;
char *ret = NULL;
if (mutex) {
switch_mutex_lock(mutex);
}
if (!(dbh = vm_get_db_handle(profile))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB\n");
goto end;
}
ret = switch_cache_db_execute_sql2str(dbh, sql, resbuf, len, NULL);
end:
switch_cache_db_release_db_handle(&dbh);
if (mutex) {
switch_mutex_unlock(mutex);
}
return ret;
}
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,
void *pdata)
{
switch_bool_t ret = SWITCH_FALSE;
char *errmsg = NULL;
switch_cache_db_handle_t *dbh = NULL;
if (mutex) {
switch_mutex_lock(mutex);
}
if (!(dbh = vm_get_db_handle(profile))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB\n");
goto end;
}
switch_cache_db_execute_sql_callback(dbh, sql, callback, pdata, &errmsg);
if (errmsg) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR: [%s] %s\n", sql, errmsg);
free(errmsg);
}
end:
switch_cache_db_release_db_handle(&dbh);
if (mutex) {
switch_mutex_unlock(mutex);
}
return ret;
}
static char vm_sql[] =
"CREATE TABLE voicemail_msgs (\n"
" created_epoch INTEGER,\n"
" read_epoch INTEGER,\n"
" username VARCHAR(255),\n"
" domain VARCHAR(255),\n"
" uuid VARCHAR(255),\n"
" cid_name VARCHAR(255),\n"
" cid_number VARCHAR(255),\n"
" in_folder VARCHAR(255),\n"
" file_path VARCHAR(255),\n"
" message_len INTEGER,\n" " flags VARCHAR(255),\n" " read_flags VARCHAR(255),\n" " forwarded_by VARCHAR(255)\n" ");\n";
static char vm_pref_sql[] =
"CREATE TABLE voicemail_prefs (\n"
" username VARCHAR(255),\n"
" domain VARCHAR(255),\n"
" name_path VARCHAR(255),\n" " greeting_path VARCHAR(255),\n" " password VARCHAR(255)\n" ");\n";
static char *vm_index_list[] = {
"create index voicemail_msgs_idx1 on voicemail_msgs(created_epoch)",
"create index voicemail_msgs_idx2 on voicemail_msgs(username)",
"create index voicemail_msgs_idx3 on voicemail_msgs(domain)",
"create index voicemail_msgs_idx4 on voicemail_msgs(uuid)",
"create index voicemail_msgs_idx5 on voicemail_msgs(in_folder)",
"create index voicemail_msgs_idx6 on voicemail_msgs(read_flags)",
"create index voicemail_msgs_idx7 on voicemail_msgs(forwarded_by)",
"create index voicemail_msgs_idx8 on voicemail_msgs(read_epoch)",
"create index voicemail_msgs_idx9 on voicemail_msgs(flags)",
"create index voicemail_prefs_idx1 on voicemail_prefs(username)",
"create index voicemail_prefs_idx2 on voicemail_prefs(domain)",
NULL
};
static void free_profile(vm_profile_t *profile)
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Destroying Profile %s\n", profile->name);
switch_core_destroy_memory_pool(&profile->pool);
}
static void destroy_profile(const char *profile_name, switch_bool_t block)
{
vm_profile_t *profile = NULL;
switch_mutex_lock(globals.mutex);
if ((profile = switch_core_hash_find(globals.profile_hash, profile_name))) {
switch_core_hash_delete(globals.profile_hash, profile_name);
}
switch_mutex_unlock(globals.mutex);
if (!profile) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "[%s] Invalid Profile\n", profile_name);
return;
}
if (block) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "[%s] Waiting for write lock\n", profile->name);
switch_thread_rwlock_wrlock(profile->rwlock);
} else {
if (switch_thread_rwlock_trywrlock(profile->rwlock) != SWITCH_STATUS_SUCCESS) {
/* Lock failed, set the destroy flag so it'll be destroyed whenever its not in use anymore */
switch_set_flag(profile, PFLAG_DESTROY);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "[%s] Profile is in use, memory will be freed whenever its no longer in use\n",
profile->name);
return;
}
}
free_profile(profile);
}
/* Static buffer, 2 bytes */
static switch_xml_config_string_options_t config_dtmf = { NULL, 2, "[0-9#\\*]" };
static switch_xml_config_string_options_t config_dtmf_optional = { NULL, 2, "[0-9#\\*]?" };
static switch_xml_config_string_options_t config_login_keys = { NULL, 16, "[0-9#\\*]*" };
static switch_xml_config_string_options_t config_file_ext = { NULL, 10, NULL };
static switch_xml_config_int_options_t config_int_0_10000 = { SWITCH_TRUE, 0, SWITCH_TRUE, 10000 };
static switch_xml_config_int_options_t config_int_0_1000 = { SWITCH_TRUE, 0, SWITCH_TRUE, 1000 };
static switch_xml_config_int_options_t config_int_digit_timeout = { SWITCH_TRUE, 0, SWITCH_TRUE, 30000 };
static switch_xml_config_int_options_t config_int_max_logins = { SWITCH_TRUE, 0, SWITCH_TRUE, 10 };
static switch_xml_config_int_options_t config_int_ht_0 = { SWITCH_TRUE, 0 };
static switch_xml_config_enum_item_t config_play_date_announcement[] = {
{"first", VM_DATE_FIRST},
{"last", VM_DATE_LAST},
{"never", VM_DATE_NEVER},
{NULL, 0}
};
static switch_status_t vm_config_email_callback(switch_xml_config_item_t *item, const char *newvalue, switch_config_callback_type_t callback_type,
switch_bool_t changed)
{
vm_profile_t *profile = (vm_profile_t *) item->data;
switch_assert(profile);
if (callback_type == CONFIG_LOAD || callback_type == CONFIG_RELOAD) {
char *email_headers = NULL, *email_body = NULL;
if (newvalue) {
switch_stream_handle_t stream;
SWITCH_STANDARD_STREAM(stream);
if (switch_stream_write_file_contents(&stream, newvalue) == SWITCH_STATUS_SUCCESS) {
email_headers = switch_core_strdup(profile->pool, stream.data);
if ((email_body = strstr(email_headers, "\n\n"))) {
*email_body = '\0';
email_body += 2;
} else if ((email_body = strstr(email_headers, "\r\n\r\n"))) {
*email_body = '\0';
email_body += 4;
}
}
free(stream.data);
}
if (email_headers) {
profile->email_headers = email_headers;
}
if (email_body) {
profile->email_body = email_body;
}
}
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t vm_config_notify_callback(switch_xml_config_item_t *item, const char *newvalue, switch_config_callback_type_t callback_type,
switch_bool_t changed)
{
vm_profile_t *profile = (vm_profile_t *) item->data;
switch_assert(profile);
if (callback_type == CONFIG_LOAD || callback_type == CONFIG_RELOAD) {
char *email_headers = NULL, *email_body = NULL;
if (newvalue) {
switch_stream_handle_t stream;
SWITCH_STANDARD_STREAM(stream);
if (switch_stream_write_file_contents(&stream, newvalue) == SWITCH_STATUS_SUCCESS) {
email_headers = switch_core_strdup(profile->pool, stream.data);
if ((email_body = strstr(email_headers, "\n\n"))) {
*email_body = '\0';
email_body += 2;
} else if ((email_body = strstr(email_headers, "\r\n\r\n"))) {
*email_body = '\0';
email_body += 4;
}
}
free(stream.data);
}
if (email_headers) {
profile->notify_email_headers = email_headers;
}
if (email_body) {
profile->notify_email_body = email_body;
}
}
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t vm_config_web_callback(switch_xml_config_item_t *item, const char *newvalue, switch_config_callback_type_t callback_type,
switch_bool_t changed)
{
vm_profile_t *profile = (vm_profile_t *) item->data;
switch_assert(profile);
if (callback_type == CONFIG_LOAD || callback_type == CONFIG_RELOAD) {
char *web_head = NULL, *web_tail = NULL;
if (newvalue) {
switch_stream_handle_t stream;
SWITCH_STANDARD_STREAM(stream);
if (switch_stream_write_file_contents(&stream, newvalue) == SWITCH_STATUS_SUCCESS) {
web_head = switch_core_strdup(profile->pool, stream.data);
if ((web_tail = strstr(web_head, "<!break>\n"))) {
*web_tail = '\0';
web_tail += 9;
} else if ((web_tail = strstr(web_head, "<!break>\r\n"))) {
*web_tail = '\0';
web_tail += 10;
}
}
free(stream.data);
}
if (web_head) {
profile->web_head = web_head;
}
if (web_tail) {
profile->web_tail = web_tail;
}
}
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t vm_config_validate_samplerate(switch_xml_config_item_t *item, const char *newvalue, switch_config_callback_type_t callback_type,
switch_bool_t changed)
{
if ((callback_type == CONFIG_LOAD || callback_type == CONFIG_RELOAD) && newvalue) {
int val = *(int *) item->ptr;
if (val != 0 && !switch_is_valid_rate(val)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid samplerate %s\n", newvalue);
return SWITCH_STATUS_FALSE;
}
}
return SWITCH_STATUS_SUCCESS;
}
/*!
* \brief Sets the profile's configuration instructions
*/
vm_profile_t *profile_set_config(vm_profile_t *profile)
{
int i = 0;
profile->config_str_pool.pool = profile->pool;
/*
SWITCH _CONFIG_SET_ITEM(item, "key", type, flags,
pointer, default, options, help_syntax, help_description)
*/
/* DTMFs */
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "terminator-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->terminator_key, "#", &config_dtmf, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "play-new-messages-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->play_new_messages_key, "1", &config_dtmf, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "play-saved-messages-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->play_saved_messages_key, "2", &config_dtmf, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "play-new-messages-lifo", SWITCH_CONFIG_BOOL, CONFIG_RELOADABLE,
&profile->play_new_messages_lifo, SWITCH_FALSE, NULL, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "play-saved-messages-lifo", SWITCH_CONFIG_BOOL, CONFIG_RELOADABLE,
&profile->play_saved_messages_lifo, SWITCH_FALSE, NULL, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "login-keys", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->login_keys, "0", &config_login_keys, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "main-menu-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->main_menu_key, "0", &config_dtmf, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "skip-greet-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->skip_greet_key, "#", &config_dtmf, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "skip-info-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->skip_info_key, "*", &config_dtmf, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "config-menu-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->config_menu_key, "5", &config_dtmf, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "record-greeting-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->record_greeting_key, "1", &config_dtmf, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "choose-greeting-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->choose_greeting_key, "2", &config_dtmf, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "record-name-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->record_name_key, "3", &config_dtmf, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "change-pass-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->change_pass_key, "6", &config_dtmf, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "record-file-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->record_file_key, "3", &config_dtmf, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "listen-file-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->listen_file_key, "1", &config_dtmf, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "save-file-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->save_file_key, "2", &config_dtmf, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "delete-file-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->delete_file_key, "7", &config_dtmf, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "undelete-file-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->undelete_file_key, "8", &config_dtmf, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "email-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &profile->email_key, "4", &config_dtmf, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "callback-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->callback_key, "5", &config_dtmf, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "pause-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &profile->pause_key, "0", &config_dtmf, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "restart-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->restart_key, "1", &config_dtmf, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "ff-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &profile->ff_key, "6", &config_dtmf, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "rew-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &profile->rew_key, "4", &config_dtmf, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "previous-message-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->prev_msg_key, "1", &config_dtmf, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "next-message-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->next_msg_key, "3", &config_dtmf, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "repeat-message-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->repeat_msg_key, "0", &config_dtmf, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "urgent-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->urgent_key, "*", &config_dtmf, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "operator-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->operator_key, "", &config_dtmf_optional, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "vmain-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &profile->vmain_key, "", &config_dtmf_optional, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "vmain-extension", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->vmain_ext, "", &profile->config_str_pool, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "forward-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->forward_key, "8", &config_dtmf, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "prepend-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->prepend_key, "1", &config_dtmf, NULL, NULL);
/* Other settings */
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "file-extension", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->file_ext, "wav", &config_file_ext, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "record-title", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->record_title, "FreeSWITCH Voicemail", &profile->config_str_pool, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "record-comment", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->record_comment, "FreeSWITCH Voicemail", &profile->config_str_pool, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "record-copyright", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->record_copyright, "http://www.freeswitch.org", &profile->config_str_pool, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "operator-extension", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->operator_ext, "", &profile->config_str_pool, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "tone-spec", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->tone_spec, "%(1000, 0, 640)", &profile->config_str_pool, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "storage-dir", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->storage_dir, "", &profile->config_str_pool, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "storage-dir-shared", SWITCH_CONFIG_BOOL, CONFIG_RELOADABLE,
&profile->storage_dir_shared, SWITCH_FALSE, NULL, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "callback-dialplan", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->callback_dialplan, "XML", &profile->config_str_pool, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "callback-context", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->callback_context, "default", &profile->config_str_pool, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "notify-email-body", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->notify_email_body, NULL, &profile->config_str_pool, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "notify-email-headers", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->notify_email_headers, NULL, &profile->config_str_pool, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "play-date-announcement", SWITCH_CONFIG_ENUM, CONFIG_RELOADABLE,
&profile->play_date_announcement, VM_DATE_FIRST, &config_play_date_announcement, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "convert-cmd", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->convert_cmd, NULL, &profile->config_str_pool, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "convert-ext", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->convert_ext, NULL, &profile->config_str_pool, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "digit-timeout", SWITCH_CONFIG_INT, CONFIG_RELOADABLE,
&profile->digit_timeout, 10000, &config_int_digit_timeout, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "max-login-attempts", SWITCH_CONFIG_INT, CONFIG_RELOADABLE,
&profile->max_login_attempts, 3, &config_int_max_logins, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "min-record-len", SWITCH_CONFIG_INT, CONFIG_RELOADABLE,
&profile->min_record_len, 3, &config_int_0_10000, "seconds", NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "max-record-len", SWITCH_CONFIG_INT, CONFIG_RELOADABLE,
&profile->max_record_len, 300, &config_int_0_1000, "seconds", NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "max-retries", SWITCH_CONFIG_INT, CONFIG_RELOADABLE,
&profile->max_retries, 3, &config_int_ht_0, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "record-silence-threshold", SWITCH_CONFIG_INT, CONFIG_RELOADABLE,
&profile->record_threshold, 200, &config_int_0_10000, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "record-silence-hits", SWITCH_CONFIG_INT, CONFIG_RELOADABLE,
&profile->record_silence_hits, 2, &config_int_0_1000, NULL, NULL);
SWITCH_CONFIG_SET_ITEM_CALLBACK(profile->config[i++], "record-sample-rate", SWITCH_CONFIG_INT, CONFIG_RELOADABLE,
&profile->record_sample_rate, 0, NULL, vm_config_validate_samplerate, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "email_headers", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->email_headers, NULL, &profile->config_str_pool, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "email_body", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->email_body, NULL, &profile->config_str_pool, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "email_email-from", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->email_from, NULL, &profile->config_str_pool, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "email_date-fmt", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->date_fmt, "%A, %B %d %Y, %I:%M %p", &profile->config_str_pool, NULL, NULL);
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_SET_ITEM(profile->config[i++], "dbname", SWITCH_CONFIG_STRING, 0, &profile->dbname, NULL, &profile->config_str_pool, NULL, NULL);
SWITCH_CONFIG_SET_ITEM_CALLBACK(profile->config[i++], "email_template-file", SWITCH_CONFIG_CUSTOM, CONFIG_RELOADABLE,
NULL, NULL, profile, vm_config_email_callback, NULL, NULL);
SWITCH_CONFIG_SET_ITEM_CALLBACK(profile->config[i++], "email_notify-template-file", SWITCH_CONFIG_CUSTOM, CONFIG_RELOADABLE,
NULL, NULL, profile, vm_config_notify_callback, NULL, NULL);
SWITCH_CONFIG_SET_ITEM_CALLBACK(profile->config[i++], "web-template-file", SWITCH_CONFIG_CUSTOM, CONFIG_RELOADABLE,
NULL, NULL, profile, vm_config_web_callback, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "db-password-override", SWITCH_CONFIG_BOOL, CONFIG_RELOADABLE,
&profile->db_password_override, SWITCH_FALSE, NULL, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "allow-empty-password-auth", SWITCH_CONFIG_BOOL, CONFIG_RELOADABLE,
&profile->allow_empty_password_auth, SWITCH_TRUE, NULL, NULL, NULL);
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_SET_ITEM(profile->config[i++], "send-full-vm-header", SWITCH_CONFIG_BOOL, CONFIG_RELOADABLE, &profile->send_full_vm_header, SWITCH_FALSE, NULL, NULL, NULL);
switch_assert(i < VM_PROFILE_CONFIGITEM_COUNT);
return profile;
}
static vm_profile_t *load_profile(const char *profile_name)
{
vm_profile_t *profile = NULL;
switch_xml_t x_profiles, x_profile, cfg, xml, x_email, param;
switch_event_t *event = NULL;
switch_cache_db_handle_t *dbh = NULL;
if (!(xml = switch_xml_open_cfg(global_cf, &cfg, NULL))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of %s failed\n", global_cf);
return profile;
}
if (!(x_profiles = switch_xml_child(cfg, "profiles"))) {
goto end;
}
if ((x_profile = switch_xml_find_child(x_profiles, "profile", "name", profile_name))) {
switch_memory_pool_t *pool;
int x;
switch_size_t count;
char *errmsg;
if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Pool Failure\n");
goto end;
}
if (!(profile = switch_core_alloc(pool, sizeof(vm_profile_t)))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Alloc Failure\n");
switch_core_destroy_memory_pool(&pool);
goto end;
}
profile->pool = pool;
profile_set_config(profile);
/* Add the params to the event structure */
count = switch_event_import_xml(switch_xml_child(x_profile, "param"), "name", "value", &event);
/* Take care of the custom config structure */
if ((x_email = switch_xml_child(x_profile, "email"))) {
if ((param = switch_xml_child(x_email, "body"))) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "email_body", param->txt);
}
if ((param = switch_xml_child(x_email, "headers"))) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "email_headers", param->txt);
}
for (param = switch_xml_child(x_email, "param"); param; param = param->next) {
char *var, *val;
char buf[2048];
if ((var = (char *) switch_xml_attr_soft(param, "name")) && (val = (char *) switch_xml_attr_soft(param, "value"))) {
switch_snprintf(buf, 2048, "email_%s", var);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, buf, val);
}
}
}
if (switch_xml_config_parse_event(event, (int)count, SWITCH_FALSE, profile->config) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to process configuration\n");
switch_core_destroy_memory_pool(&pool);
goto end;
}
switch_thread_rwlock_create(&profile->rwlock, pool);
profile->name = switch_core_strdup(pool, profile_name);
if (zstr(profile->dbname)) {
profile->dbname = switch_core_sprintf(profile->pool, "voicemail_%s", profile_name);
}
if (!(dbh = vm_get_db_handle(profile))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot open DB!\n");
goto end;
}
switch_cache_db_test_reactive(dbh, "select count(forwarded_by) from voicemail_msgs", NULL,
"alter table voicemail_msgs add forwarded_by varchar(255)");
switch_cache_db_test_reactive(dbh, "select count(forwarded_by) from voicemail_msgs", "drop table voicemail_msgs", vm_sql);
switch_cache_db_test_reactive(dbh, "select count(username) from voicemail_prefs", "drop table voicemail_prefs", vm_pref_sql);
switch_cache_db_test_reactive(dbh, "select count(password) from voicemail_prefs", NULL, "alter table voicemail_prefs add password varchar(255)");
for (x = 0; vm_index_list[x]; x++) {
errmsg = NULL;
switch_cache_db_create_schema(dbh, vm_index_list[x], &errmsg);
switch_safe_free(errmsg);
}
switch_cache_db_release_db_handle(&dbh);
switch_mutex_init(&profile->mutex, SWITCH_MUTEX_NESTED, profile->pool);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Added Profile %s\n", profile->name);
switch_core_hash_insert(globals.profile_hash, profile->name, profile);
}
end:
switch_cache_db_release_db_handle(&dbh);
if (xml) {
switch_xml_free(xml);
}
if (event) {
switch_event_destroy(&event);
}
return profile;
}
static vm_profile_t *get_profile(const char *profile_name)
{
vm_profile_t *profile = NULL;
switch_mutex_lock(globals.mutex);
if (!(profile = switch_core_hash_find(globals.profile_hash, profile_name))) {
profile = load_profile(profile_name);
}
if (profile) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG10, "[%s] rwlock\n", profile->name);
switch_thread_rwlock_rdlock(profile->rwlock);
}
switch_mutex_unlock(globals.mutex);
return profile;
}
static void profile_rwunlock(vm_profile_t *profile)
{
switch_thread_rwlock_unlock(profile->rwlock);
if (switch_test_flag(profile, PFLAG_DESTROY)) {
if (switch_thread_rwlock_trywrlock(profile->rwlock) == SWITCH_STATUS_SUCCESS) {
switch_thread_rwlock_unlock(profile->rwlock);
free_profile(profile);
}
}
}
static switch_status_t load_config(void)
{
switch_xml_t cfg, xml, settings, param, x_profiles, x_profile;
if (!(xml = switch_xml_open_cfg(global_cf, &cfg, NULL))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of %s failed\n", global_cf);
return SWITCH_STATUS_TERM;
}
switch_mutex_lock(globals.mutex);
if ((settings = switch_xml_child(cfg, "settings"))) {
for (param = switch_xml_child(settings, "param"); param; param = param->next) {
char *var = (char *) switch_xml_attr_soft(param, "name");
char *val = (char *) switch_xml_attr_soft(param, "value");
if (!strcasecmp(var, "debug")) {
globals.debug = atoi(val);
} else if (!strcasecmp(var, "message-query-exact-match")) {
globals.message_query_exact_match = switch_true(val);
}
}
}
if ((x_profiles = switch_xml_child(cfg, "profiles"))) {
for (x_profile = switch_xml_child(x_profiles, "profile"); x_profile; x_profile = x_profile->next) {
load_profile(switch_xml_attr_soft(x_profile, "name"));
}
}
switch_mutex_unlock(globals.mutex);
switch_xml_free(xml);
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t cancel_on_dtmf(switch_core_session_t *session, void *input, switch_input_type_t itype, void *buf, unsigned int buflen)
{
switch (itype) {
case SWITCH_INPUT_TYPE_DTMF:
{
switch_dtmf_t *dtmf = (switch_dtmf_t *) input;
if (buf && buflen) {
char *bp = (char *) buf;
bp[0] = dtmf->digit;
bp[1] = '\0';
}
return SWITCH_STATUS_BREAK;
}
break;
default:
break;
}
return SWITCH_STATUS_SUCCESS;
}
struct call_control {
vm_profile_t *profile;
switch_file_handle_t *fh;
char buf[4];
int noexit;
int playback_controls_active;
};
typedef struct call_control switch_cc_t;
static switch_status_t control_playback(switch_core_session_t *session, void *input, switch_input_type_t itype, void *buf, unsigned int buflen)
{
switch (itype) {
case SWITCH_INPUT_TYPE_DTMF:
{
switch_dtmf_t *dtmf = (switch_dtmf_t *) input;
switch_cc_t *cc = (switch_cc_t *) buf;
switch_file_handle_t *fh = cc->fh;
uint32_t pos = 0;
if (!cc->noexit
&& (dtmf->digit == *cc->profile->delete_file_key || dtmf->digit == *cc->profile->save_file_key
|| dtmf->digit == *cc->profile->prev_msg_key || dtmf->digit == *cc->profile->next_msg_key
|| dtmf->digit == *cc->profile->repeat_msg_key
|| dtmf->digit == *cc->profile->terminator_key || dtmf->digit == *cc->profile->skip_info_key
|| dtmf->digit == *cc->profile->forward_key)) {
*cc->buf = dtmf->digit;
return SWITCH_STATUS_BREAK;
}
if (!cc->playback_controls_active
&& (dtmf->digit == *cc->profile->email_key)) {
*cc->buf = dtmf->digit;
return SWITCH_STATUS_BREAK;
}
if (!(fh && fh->file_interface && switch_test_flag(fh, SWITCH_FILE_OPEN))) {
return SWITCH_STATUS_SUCCESS;
}
if (dtmf->digit == *cc->profile->pause_key) {
if (switch_test_flag(fh, SWITCH_FILE_PAUSE)) {
switch_clear_flag_locked(fh, SWITCH_FILE_PAUSE);
} else {
switch_set_flag_locked(fh, SWITCH_FILE_PAUSE);
}
return SWITCH_STATUS_SUCCESS;
}
if (dtmf->digit == *cc->profile->restart_key) {
unsigned int seekpos = 0;
fh->speed = 0;
switch_core_file_seek(fh, &seekpos, 0, SEEK_SET);
return SWITCH_STATUS_SUCCESS;
}
if (dtmf->digit == *cc->profile->ff_key) {
int samps = 24000;
switch_core_file_seek(fh, &pos, samps, SEEK_CUR);
return SWITCH_STATUS_SUCCESS;
}
if (dtmf->digit == *cc->profile->rew_key) {
int samps = -48000;
int target_pos = fh->offset_pos + samps;
if (target_pos < 1) {
/* too close to beginning of the file, just restart instead of rewind */
unsigned int seekpos = 0;
fh->speed = 0;
switch_core_file_seek(fh, &seekpos, 0, SEEK_SET);
return SWITCH_STATUS_SUCCESS;
} else {
switch_core_file_seek(fh, &pos, samps, SEEK_CUR);
return SWITCH_STATUS_SUCCESS;
}
}
}
break;
default:
break;
}
return SWITCH_STATUS_SUCCESS;
}
struct prefs_callback {
char name_path[255];
char greeting_path[255];
char password[255];
};
typedef struct prefs_callback prefs_callback_t;
static int prefs_callback(void *pArg, int argc, char **argv, char **columnNames)
{
prefs_callback_t *cbt = (prefs_callback_t *) pArg;
switch_copy_string(cbt->name_path, argv[2], sizeof(cbt->name_path));
switch_copy_string(cbt->greeting_path, argv[3], sizeof(cbt->greeting_path));
switch_copy_string(cbt->password, argv[4], sizeof(cbt->password));
return 0;
}