00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include "asterisk.h"
00038
00039 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 378781 $")
00040
00041 #include <dahdi/user.h>
00042
00043 #include "asterisk/lock.h"
00044 #include "asterisk/file.h"
00045 #include "asterisk/channel.h"
00046 #include "asterisk/pbx.h"
00047 #include "asterisk/module.h"
00048 #include "asterisk/config.h"
00049 #include "asterisk/app.h"
00050 #include "asterisk/dsp.h"
00051 #include "asterisk/musiconhold.h"
00052 #include "asterisk/manager.h"
00053 #include "asterisk/cli.h"
00054 #include "asterisk/say.h"
00055 #include "asterisk/utils.h"
00056 #include "asterisk/translate.h"
00057 #include "asterisk/ulaw.h"
00058 #include "asterisk/astobj2.h"
00059 #include "asterisk/devicestate.h"
00060 #include "asterisk/dial.h"
00061 #include "asterisk/causes.h"
00062 #include "asterisk/paths.h"
00063 #include "asterisk/data.h"
00064 #include "asterisk/test.h"
00065
00066 #include "enter.h"
00067 #include "leave.h"
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516 #define CONFIG_FILE_NAME "meetme.conf"
00517 #define SLA_CONFIG_FILE "sla.conf"
00518 #define STR_CONCISE "concise"
00519
00520
00521 #define DEFAULT_AUDIO_BUFFERS 32
00522
00523
00524 #define DATE_FORMAT "%Y-%m-%d %H:%M:%S"
00525
00526 enum {
00527 ADMINFLAG_MUTED = (1 << 1),
00528 ADMINFLAG_SELFMUTED = (1 << 2),
00529 ADMINFLAG_KICKME = (1 << 3),
00530
00531 ADMINFLAG_T_REQUEST = (1 << 4),
00532 };
00533
00534 #define MEETME_DELAYDETECTTALK 300
00535 #define MEETME_DELAYDETECTENDTALK 1000
00536
00537 #define AST_FRAME_BITS 32
00538
00539 enum volume_action {
00540 VOL_UP,
00541 VOL_DOWN
00542 };
00543
00544 enum entrance_sound {
00545 ENTER,
00546 LEAVE
00547 };
00548
00549 enum recording_state {
00550 MEETME_RECORD_OFF,
00551 MEETME_RECORD_STARTED,
00552 MEETME_RECORD_ACTIVE,
00553 MEETME_RECORD_TERMINATE
00554 };
00555
00556 #define CONF_SIZE 320
00557
00558 enum {
00559
00560 CONFFLAG_ADMIN = (1 << 0),
00561
00562 CONFFLAG_MONITOR = (1 << 1),
00563
00564 CONFFLAG_KEYEXIT = (1 << 2),
00565
00566 CONFFLAG_STARMENU = (1 << 3),
00567
00568 CONFFLAG_TALKER = (1 << 4),
00569
00570 CONFFLAG_QUIET = (1 << 5),
00571
00572
00573 CONFFLAG_ANNOUNCEUSERCOUNT = (1 << 6),
00574
00575 CONFFLAG_AGI = (1 << 7),
00576
00577 CONFFLAG_MOH = (1 << 8),
00578
00579 CONFFLAG_MARKEDEXIT = (1 << 9),
00580
00581 CONFFLAG_WAITMARKED = (1 << 10),
00582
00583 CONFFLAG_EXIT_CONTEXT = (1 << 11),
00584
00585 CONFFLAG_MARKEDUSER = (1 << 12),
00586
00587 CONFFLAG_INTROUSER = (1 << 13),
00588
00589 CONFFLAG_RECORDCONF = (1<< 14),
00590
00591 CONFFLAG_MONITORTALKER = (1 << 15),
00592 CONFFLAG_DYNAMIC = (1 << 16),
00593 CONFFLAG_DYNAMICPIN = (1 << 17),
00594 CONFFLAG_EMPTY = (1 << 18),
00595 CONFFLAG_EMPTYNOPIN = (1 << 19),
00596 CONFFLAG_ALWAYSPROMPT = (1 << 20),
00597
00598 CONFFLAG_OPTIMIZETALKER = (1 << 21),
00599
00600
00601 CONFFLAG_NOONLYPERSON = (1 << 22),
00602
00603
00604 CONFFLAG_INTROUSERNOREVIEW = (1 << 23),
00605
00606 CONFFLAG_STARTMUTED = (1 << 24),
00607
00608 CONFFLAG_PASS_DTMF = (1 << 25),
00609 CONFFLAG_SLA_STATION = (1 << 26),
00610 CONFFLAG_SLA_TRUNK = (1 << 27),
00611
00612 CONFFLAG_KICK_CONTINUE = (1 << 28),
00613 CONFFLAG_DURATION_STOP = (1 << 29),
00614 CONFFLAG_DURATION_LIMIT = (1 << 30),
00615 };
00616
00617
00618 #define CONFFLAG_NO_AUDIO_UNTIL_UP (1ULL << 31)
00619
00620 #define CONFFLAG_INTROMSG (1ULL << 32)
00621
00622 enum {
00623 OPT_ARG_WAITMARKED = 0,
00624 OPT_ARG_EXITKEYS = 1,
00625 OPT_ARG_DURATION_STOP = 2,
00626 OPT_ARG_DURATION_LIMIT = 3,
00627 OPT_ARG_MOH_CLASS = 4,
00628 OPT_ARG_INTROMSG = 5,
00629 OPT_ARG_ARRAY_SIZE = 6,
00630 };
00631
00632 AST_APP_OPTIONS(meetme_opts, BEGIN_OPTIONS
00633 AST_APP_OPTION('A', CONFFLAG_MARKEDUSER ),
00634 AST_APP_OPTION('a', CONFFLAG_ADMIN ),
00635 AST_APP_OPTION('b', CONFFLAG_AGI ),
00636 AST_APP_OPTION('c', CONFFLAG_ANNOUNCEUSERCOUNT ),
00637 AST_APP_OPTION('C', CONFFLAG_KICK_CONTINUE),
00638 AST_APP_OPTION('D', CONFFLAG_DYNAMICPIN ),
00639 AST_APP_OPTION('d', CONFFLAG_DYNAMIC ),
00640 AST_APP_OPTION('E', CONFFLAG_EMPTYNOPIN ),
00641 AST_APP_OPTION('e', CONFFLAG_EMPTY ),
00642 AST_APP_OPTION('F', CONFFLAG_PASS_DTMF ),
00643 AST_APP_OPTION_ARG('G', CONFFLAG_INTROMSG, OPT_ARG_INTROMSG ),
00644 AST_APP_OPTION('i', CONFFLAG_INTROUSER ),
00645 AST_APP_OPTION('I', CONFFLAG_INTROUSERNOREVIEW ),
00646 AST_APP_OPTION_ARG('M', CONFFLAG_MOH, OPT_ARG_MOH_CLASS ),
00647 AST_APP_OPTION('m', CONFFLAG_STARTMUTED ),
00648 AST_APP_OPTION('o', CONFFLAG_OPTIMIZETALKER ),
00649 AST_APP_OPTION('P', CONFFLAG_ALWAYSPROMPT ),
00650 AST_APP_OPTION_ARG('p', CONFFLAG_KEYEXIT, OPT_ARG_EXITKEYS ),
00651 AST_APP_OPTION('q', CONFFLAG_QUIET ),
00652 AST_APP_OPTION('r', CONFFLAG_RECORDCONF ),
00653 AST_APP_OPTION('s', CONFFLAG_STARMENU ),
00654 AST_APP_OPTION('T', CONFFLAG_MONITORTALKER ),
00655 AST_APP_OPTION('l', CONFFLAG_MONITOR ),
00656 AST_APP_OPTION('t', CONFFLAG_TALKER ),
00657 AST_APP_OPTION_ARG('w', CONFFLAG_WAITMARKED, OPT_ARG_WAITMARKED ),
00658 AST_APP_OPTION('X', CONFFLAG_EXIT_CONTEXT ),
00659 AST_APP_OPTION('x', CONFFLAG_MARKEDEXIT ),
00660 AST_APP_OPTION('1', CONFFLAG_NOONLYPERSON ),
00661 AST_APP_OPTION_ARG('S', CONFFLAG_DURATION_STOP, OPT_ARG_DURATION_STOP),
00662 AST_APP_OPTION_ARG('L', CONFFLAG_DURATION_LIMIT, OPT_ARG_DURATION_LIMIT),
00663 END_OPTIONS );
00664
00665 static const char * const app = "MeetMe";
00666 static const char * const app2 = "MeetMeCount";
00667 static const char * const app3 = "MeetMeAdmin";
00668 static const char * const app4 = "MeetMeChannelAdmin";
00669 static const char * const slastation_app = "SLAStation";
00670 static const char * const slatrunk_app = "SLATrunk";
00671
00672
00673 static int rt_schedule;
00674 static int fuzzystart;
00675 static int earlyalert;
00676 static int endalert;
00677 static int extendby;
00678
00679
00680 static int rt_log_members;
00681
00682 #define MAX_CONFNUM 80
00683 #define MAX_PIN 80
00684 #define OPTIONS_LEN 100
00685
00686
00687 #define MAX_SETTINGS (MAX_CONFNUM + MAX_PIN + MAX_PIN + 3)
00688
00689 enum announcetypes {
00690 CONF_HASJOIN,
00691 CONF_HASLEFT
00692 };
00693
00694 struct announce_listitem {
00695 AST_LIST_ENTRY(announce_listitem) entry;
00696 char namerecloc[PATH_MAX];
00697 char language[MAX_LANGUAGE];
00698 struct ast_channel *confchan;
00699 int confusers;
00700 enum announcetypes announcetype;
00701 };
00702
00703
00704 struct ast_conference {
00705 ast_mutex_t playlock;
00706 ast_mutex_t listenlock;
00707 char confno[MAX_CONFNUM];
00708 struct ast_channel *chan;
00709 struct ast_channel *lchan;
00710 int fd;
00711 int dahdiconf;
00712 int users;
00713 int markedusers;
00714 int maxusers;
00715 int endalert;
00716 time_t start;
00717 int refcount;
00718 enum recording_state recording:2;
00719 unsigned int isdynamic:1;
00720 unsigned int locked:1;
00721 unsigned int gmuted:1;
00722 pthread_t recordthread;
00723 ast_mutex_t recordthreadlock;
00724 pthread_attr_t attr;
00725 char *recordingfilename;
00726 char *recordingformat;
00727 char pin[MAX_PIN];
00728 char pinadmin[MAX_PIN];
00729 char uniqueid[32];
00730 long endtime;
00731 const char *useropts;
00732 const char *adminopts;
00733 const char *bookid;
00734 struct ast_frame *transframe[32];
00735 struct ast_frame *origframe;
00736 struct ast_trans_pvt *transpath[32];
00737 struct ao2_container *usercontainer;
00738 AST_LIST_ENTRY(ast_conference) list;
00739
00740 pthread_t announcethread;
00741 ast_mutex_t announcethreadlock;
00742 unsigned int announcethread_stop:1;
00743 ast_cond_t announcelist_addition;
00744 AST_LIST_HEAD_NOLOCK(, announce_listitem) announcelist;
00745 ast_mutex_t announcelistlock;
00746 };
00747
00748 static AST_LIST_HEAD_STATIC(confs, ast_conference);
00749
00750 static unsigned int conf_map[1024] = {0, };
00751
00752 struct volume {
00753 int desired;
00754 int actual;
00755 };
00756
00757
00758 struct ast_conf_user {
00759 int user_no;
00760 struct ast_flags64 userflags;
00761 int adminflags;
00762 struct ast_channel *chan;
00763 int talking;
00764 int dahdichannel;
00765 char usrvalue[50];
00766 char namerecloc[PATH_MAX];
00767 time_t jointime;
00768 time_t kicktime;
00769 struct timeval start_time;
00770 long timelimit;
00771 long play_warning;
00772 long warning_freq;
00773 const char *warning_sound;
00774 const char *end_sound;
00775 struct volume talk;
00776 struct volume listen;
00777 AST_LIST_ENTRY(ast_conf_user) list;
00778 };
00779
00780 enum sla_which_trunk_refs {
00781 ALL_TRUNK_REFS,
00782 INACTIVE_TRUNK_REFS,
00783 };
00784
00785 enum sla_trunk_state {
00786 SLA_TRUNK_STATE_IDLE,
00787 SLA_TRUNK_STATE_RINGING,
00788 SLA_TRUNK_STATE_UP,
00789 SLA_TRUNK_STATE_ONHOLD,
00790 SLA_TRUNK_STATE_ONHOLD_BYME,
00791 };
00792
00793 enum sla_hold_access {
00794
00795
00796 SLA_HOLD_OPEN,
00797
00798
00799 SLA_HOLD_PRIVATE,
00800 };
00801
00802 struct sla_trunk_ref;
00803
00804 struct sla_station {
00805 AST_RWLIST_ENTRY(sla_station) entry;
00806 AST_DECLARE_STRING_FIELDS(
00807 AST_STRING_FIELD(name);
00808 AST_STRING_FIELD(device);
00809 AST_STRING_FIELD(autocontext);
00810 );
00811 AST_LIST_HEAD_NOLOCK(, sla_trunk_ref) trunks;
00812 struct ast_dial *dial;
00813
00814
00815
00816 unsigned int ring_timeout;
00817
00818
00819
00820 unsigned int ring_delay;
00821
00822
00823 unsigned int hold_access:1;
00824
00825 unsigned int ref_count;
00826 };
00827
00828 struct sla_station_ref {
00829 AST_LIST_ENTRY(sla_station_ref) entry;
00830 struct sla_station *station;
00831 };
00832
00833 struct sla_trunk {
00834 AST_RWLIST_ENTRY(sla_trunk) entry;
00835 AST_DECLARE_STRING_FIELDS(
00836 AST_STRING_FIELD(name);
00837 AST_STRING_FIELD(device);
00838 AST_STRING_FIELD(autocontext);
00839 );
00840 AST_LIST_HEAD_NOLOCK(, sla_station_ref) stations;
00841
00842 unsigned int num_stations;
00843
00844 unsigned int active_stations;
00845
00846 unsigned int hold_stations;
00847 struct ast_channel *chan;
00848 unsigned int ring_timeout;
00849
00850
00851 unsigned int barge_disabled:1;
00852
00853
00854 unsigned int hold_access:1;
00855
00856
00857 unsigned int on_hold:1;
00858
00859 unsigned int ref_count;
00860 };
00861
00862 struct sla_trunk_ref {
00863 AST_LIST_ENTRY(sla_trunk_ref) entry;
00864 struct sla_trunk *trunk;
00865 enum sla_trunk_state state;
00866 struct ast_channel *chan;
00867
00868
00869
00870 unsigned int ring_timeout;
00871
00872
00873
00874 unsigned int ring_delay;
00875 };
00876
00877 static AST_RWLIST_HEAD_STATIC(sla_stations, sla_station);
00878 static AST_RWLIST_HEAD_STATIC(sla_trunks, sla_trunk);
00879
00880 static const char sla_registrar[] = "SLA";
00881
00882
00883 enum sla_event_type {
00884
00885 SLA_EVENT_HOLD,
00886
00887 SLA_EVENT_DIAL_STATE,
00888
00889 SLA_EVENT_RINGING_TRUNK,
00890
00891 SLA_EVENT_RELOAD,
00892
00893 SLA_EVENT_CHECK_RELOAD,
00894 };
00895
00896 struct sla_event {
00897 enum sla_event_type type;
00898 struct sla_station *station;
00899 struct sla_trunk_ref *trunk_ref;
00900 AST_LIST_ENTRY(sla_event) entry;
00901 };
00902
00903
00904
00905 struct sla_failed_station {
00906 struct sla_station *station;
00907 struct timeval last_try;
00908 AST_LIST_ENTRY(sla_failed_station) entry;
00909 };
00910
00911
00912 struct sla_ringing_trunk {
00913 struct sla_trunk *trunk;
00914
00915 struct timeval ring_begin;
00916 AST_LIST_HEAD_NOLOCK(, sla_station_ref) timed_out_stations;
00917 AST_LIST_ENTRY(sla_ringing_trunk) entry;
00918 };
00919
00920 enum sla_station_hangup {
00921 SLA_STATION_HANGUP_NORMAL,
00922 SLA_STATION_HANGUP_TIMEOUT,
00923 };
00924
00925
00926 struct sla_ringing_station {
00927 struct sla_station *station;
00928
00929 struct timeval ring_begin;
00930 AST_LIST_ENTRY(sla_ringing_station) entry;
00931 };
00932
00933
00934
00935
00936 static struct {
00937
00938 pthread_t thread;
00939 ast_cond_t cond;
00940 ast_mutex_t lock;
00941 AST_LIST_HEAD_NOLOCK(, sla_ringing_trunk) ringing_trunks;
00942 AST_LIST_HEAD_NOLOCK(, sla_ringing_station) ringing_stations;
00943 AST_LIST_HEAD_NOLOCK(, sla_failed_station) failed_stations;
00944 AST_LIST_HEAD_NOLOCK(, sla_event) event_q;
00945 unsigned int stop:1;
00946
00947
00948 unsigned int attempt_callerid:1;
00949
00950 unsigned int reload:1;
00951 } sla = {
00952 .thread = AST_PTHREADT_NULL,
00953 };
00954
00955
00956
00957 static int audio_buffers;
00958
00959
00960
00961
00962
00963
00964
00965
00966 static const char gain_map[] = {
00967 -15,
00968 -13,
00969 -10,
00970 -6,
00971 0,
00972 0,
00973 0,
00974 6,
00975 10,
00976 13,
00977 15,
00978 };
00979
00980
00981 static int admin_exec(struct ast_channel *chan, const char *data);
00982 static void *recordthread(void *args);
00983
00984 static const char *istalking(int x)
00985 {
00986 if (x > 0)
00987 return "(talking)";
00988 else if (x < 0)
00989 return "(unmonitored)";
00990 else
00991 return "(not talking)";
00992 }
00993
00994 static int careful_write(int fd, unsigned char *data, int len, int block)
00995 {
00996 int res;
00997 int x;
00998
00999 while (len) {
01000 if (block) {
01001 x = DAHDI_IOMUX_WRITE | DAHDI_IOMUX_SIGEVENT;
01002 res = ioctl(fd, DAHDI_IOMUX, &x);
01003 } else
01004 res = 0;
01005 if (res >= 0)
01006 res = write(fd, data, len);
01007 if (res < 1) {
01008 if (errno != EAGAIN) {
01009 ast_log(LOG_WARNING, "Failed to write audio data to conference: %s\n", strerror(errno));
01010 return -1;
01011 } else
01012 return 0;
01013 }
01014 len -= res;
01015 data += res;
01016 }
01017
01018 return 0;
01019 }
01020
01021 static int set_talk_volume(struct ast_conf_user *user, int volume)
01022 {
01023 char gain_adjust;
01024
01025
01026
01027
01028 gain_adjust = gain_map[volume + 5];
01029
01030 return ast_channel_setoption(user->chan, AST_OPTION_RXGAIN, &gain_adjust, sizeof(gain_adjust), 0);
01031 }
01032
01033 static int set_listen_volume(struct ast_conf_user *user, int volume)
01034 {
01035 char gain_adjust;
01036
01037
01038
01039
01040 gain_adjust = gain_map[volume + 5];
01041
01042 return ast_channel_setoption(user->chan, AST_OPTION_TXGAIN, &gain_adjust, sizeof(gain_adjust), 0);
01043 }
01044
01045 static void tweak_volume(struct volume *vol, enum volume_action action)
01046 {
01047 switch (action) {
01048 case VOL_UP:
01049 switch (vol->desired) {
01050 case 5:
01051 break;
01052 case 0:
01053 vol->desired = 2;
01054 break;
01055 case -2:
01056 vol->desired = 0;
01057 break;
01058 default:
01059 vol->desired++;
01060 break;
01061 }
01062 break;
01063 case VOL_DOWN:
01064 switch (vol->desired) {
01065 case -5:
01066 break;
01067 case 2:
01068 vol->desired = 0;
01069 break;
01070 case 0:
01071 vol->desired = -2;
01072 break;
01073 default:
01074 vol->desired--;
01075 break;
01076 }
01077 }
01078 }
01079
01080 static void tweak_talk_volume(struct ast_conf_user *user, enum volume_action action)
01081 {
01082 tweak_volume(&user->talk, action);
01083
01084
01085
01086 if (!set_talk_volume(user, user->talk.desired))
01087 user->talk.actual = 0;
01088 else
01089 user->talk.actual = user->talk.desired;
01090 }
01091
01092 static void tweak_listen_volume(struct ast_conf_user *user, enum volume_action action)
01093 {
01094 tweak_volume(&user->listen, action);
01095
01096
01097
01098 if (!set_listen_volume(user, user->listen.desired))
01099 user->listen.actual = 0;
01100 else
01101 user->listen.actual = user->listen.desired;
01102 }
01103
01104 static void reset_volumes(struct ast_conf_user *user)
01105 {
01106 signed char zero_volume = 0;
01107
01108 ast_channel_setoption(user->chan, AST_OPTION_TXGAIN, &zero_volume, sizeof(zero_volume), 0);
01109 ast_channel_setoption(user->chan, AST_OPTION_RXGAIN, &zero_volume, sizeof(zero_volume), 0);
01110 }
01111
01112 static void conf_play(struct ast_channel *chan, struct ast_conference *conf, enum entrance_sound sound)
01113 {
01114 unsigned char *data;
01115 int len;
01116 int res = -1;
01117
01118 ast_test_suite_event_notify("CONFPLAY", "Channel: %s\r\n"
01119 "Conference: %s\r\n"
01120 "Marked: %d",
01121 chan->name,
01122 conf->confno,
01123 conf->markedusers);
01124
01125 if (!ast_check_hangup(chan))
01126 res = ast_autoservice_start(chan);
01127
01128 AST_LIST_LOCK(&confs);
01129
01130 switch(sound) {
01131 case ENTER:
01132 data = enter;
01133 len = sizeof(enter);
01134 break;
01135 case LEAVE:
01136 data = leave;
01137 len = sizeof(leave);
01138 break;
01139 default:
01140 data = NULL;
01141 len = 0;
01142 }
01143 if (data) {
01144 careful_write(conf->fd, data, len, 1);
01145 }
01146
01147 AST_LIST_UNLOCK(&confs);
01148
01149 if (!res)
01150 ast_autoservice_stop(chan);
01151 }
01152
01153 static int user_no_cmp(void *obj, void *arg, int flags)
01154 {
01155 struct ast_conf_user *user = obj;
01156 int *user_no = arg;
01157
01158 if (user->user_no == *user_no) {
01159 return (CMP_MATCH | CMP_STOP);
01160 }
01161
01162 return 0;
01163 }
01164
01165 static int user_max_cmp(void *obj, void *arg, int flags)
01166 {
01167 struct ast_conf_user *user = obj;
01168 int *max_no = arg;
01169
01170 if (user->user_no > *max_no) {
01171 *max_no = user->user_no;
01172 }
01173
01174 return 0;
01175 }
01176
01177
01178
01179
01180
01181
01182
01183
01184
01185
01186
01187
01188
01189
01190
01191 static struct ast_conference *build_conf(const char *confno, const char *pin,
01192 const char *pinadmin, int make, int dynamic, int refcount,
01193 const struct ast_channel *chan, struct ast_test *test)
01194 {
01195 struct ast_conference *cnf;
01196 struct dahdi_confinfo dahdic = { 0, };
01197 int confno_int = 0;
01198
01199 AST_LIST_LOCK(&confs);
01200
01201 AST_LIST_TRAVERSE(&confs, cnf, list) {
01202 if (!strcmp(confno, cnf->confno))
01203 break;
01204 }
01205
01206 if (cnf || (!make && !dynamic))
01207 goto cnfout;
01208
01209
01210 if (!(cnf = ast_calloc(1, sizeof(*cnf))) ||
01211 !(cnf->usercontainer = ao2_container_alloc(1, NULL, user_no_cmp))) {
01212 goto cnfout;
01213 }
01214
01215 ast_mutex_init(&cnf->playlock);
01216 ast_mutex_init(&cnf->listenlock);
01217 cnf->recordthread = AST_PTHREADT_NULL;
01218 ast_mutex_init(&cnf->recordthreadlock);
01219 cnf->announcethread = AST_PTHREADT_NULL;
01220 ast_mutex_init(&cnf->announcethreadlock);
01221 ast_copy_string(cnf->confno, confno, sizeof(cnf->confno));
01222 ast_copy_string(cnf->pin, pin, sizeof(cnf->pin));
01223 ast_copy_string(cnf->pinadmin, pinadmin, sizeof(cnf->pinadmin));
01224 ast_copy_string(cnf->uniqueid, chan->uniqueid, sizeof(cnf->uniqueid));
01225
01226
01227 dahdic.confno = -1;
01228 dahdic.confmode = DAHDI_CONF_CONFANN | DAHDI_CONF_CONFANNMON;
01229 cnf->fd = open("/dev/dahdi/pseudo", O_RDWR);
01230 if (cnf->fd < 0 || ioctl(cnf->fd, DAHDI_SETCONF, &dahdic)) {
01231 if (test) {
01232
01233
01234
01235 ast_test_status_update(test, "Unable to open DAHDI pseudo device\n");
01236 } else {
01237 ast_log(LOG_WARNING, "Unable to open DAHDI pseudo device\n");
01238 if (cnf->fd >= 0)
01239 close(cnf->fd);
01240 ao2_ref(cnf->usercontainer, -1);
01241 ast_mutex_destroy(&cnf->playlock);
01242 ast_mutex_destroy(&cnf->listenlock);
01243 ast_mutex_destroy(&cnf->recordthreadlock);
01244 ast_mutex_destroy(&cnf->announcethreadlock);
01245 ast_free(cnf);
01246 cnf = NULL;
01247 goto cnfout;
01248 }
01249 }
01250
01251 cnf->dahdiconf = dahdic.confno;
01252
01253
01254 cnf->chan = ast_request("DAHDI", AST_FORMAT_SLINEAR, chan, "pseudo", NULL);
01255 if (cnf->chan) {
01256 ast_set_read_format(cnf->chan, AST_FORMAT_SLINEAR);
01257 ast_set_write_format(cnf->chan, AST_FORMAT_SLINEAR);
01258 dahdic.chan = 0;
01259 dahdic.confno = cnf->dahdiconf;
01260 dahdic.confmode = DAHDI_CONF_CONFANN | DAHDI_CONF_CONFANNMON;
01261 if (ioctl(cnf->chan->fds[0], DAHDI_SETCONF, &dahdic)) {
01262 if (test) {
01263 ast_test_status_update(test, "Error setting conference on pseudo channel\n");
01264 }
01265 ast_log(LOG_WARNING, "Error setting conference\n");
01266 if (cnf->chan)
01267 ast_hangup(cnf->chan);
01268 else
01269 close(cnf->fd);
01270 ao2_ref(cnf->usercontainer, -1);
01271 ast_mutex_destroy(&cnf->playlock);
01272 ast_mutex_destroy(&cnf->listenlock);
01273 ast_mutex_destroy(&cnf->recordthreadlock);
01274 ast_mutex_destroy(&cnf->announcethreadlock);
01275 ast_free(cnf);
01276 cnf = NULL;
01277 goto cnfout;
01278 }
01279 }
01280
01281
01282 cnf->start = time(NULL);
01283 cnf->maxusers = 0x7fffffff;
01284 cnf->isdynamic = dynamic ? 1 : 0;
01285 ast_verb(3, "Created MeetMe conference %d for conference '%s'\n", cnf->dahdiconf, cnf->confno);
01286 AST_LIST_INSERT_HEAD(&confs, cnf, list);
01287
01288
01289 if ((sscanf(cnf->confno, "%30d", &confno_int) == 1) && (confno_int >= 0 && confno_int < 1024))
01290 conf_map[confno_int] = 1;
01291
01292 cnfout:
01293 if (cnf)
01294 ast_atomic_fetchadd_int(&cnf->refcount, refcount);
01295
01296 AST_LIST_UNLOCK(&confs);
01297
01298 return cnf;
01299 }
01300
01301 static char *complete_confno(const char *word, int state)
01302 {
01303 struct ast_conference *cnf;
01304 char *ret = NULL;
01305 int which = 0;
01306 int len = strlen(word);
01307
01308 AST_LIST_LOCK(&confs);
01309 AST_LIST_TRAVERSE(&confs, cnf, list) {
01310 if (!strncmp(word, cnf->confno, len) && ++which > state) {
01311
01312 ret = ast_strdup(cnf->confno);
01313 break;
01314 }
01315 }
01316 AST_LIST_UNLOCK(&confs);
01317 return ret;
01318 }
01319
01320 static char *complete_userno(struct ast_conference *cnf, const char *word, int state)
01321 {
01322 char usrno[50];
01323 struct ao2_iterator iter;
01324 struct ast_conf_user *usr;
01325 char *ret = NULL;
01326 int which = 0;
01327 int len = strlen(word);
01328
01329 iter = ao2_iterator_init(cnf->usercontainer, 0);
01330 for (; (usr = ao2_iterator_next(&iter)); ao2_ref(usr, -1)) {
01331 snprintf(usrno, sizeof(usrno), "%d", usr->user_no);
01332 if (!strncmp(word, usrno, len) && ++which > state) {
01333 ao2_ref(usr, -1);
01334 ret = ast_strdup(usrno);
01335 break;
01336 }
01337 }
01338 ao2_iterator_destroy(&iter);
01339 return ret;
01340 }
01341
01342 static char *complete_meetmecmd_mute_kick(const char *line, const char *word, int pos, int state)
01343 {
01344 if (pos == 2) {
01345 return complete_confno(word, state);
01346 }
01347 if (pos == 3) {
01348 int len = strlen(word);
01349 char *ret = NULL;
01350 char *saved = NULL;
01351 char *myline;
01352 char *confno;
01353 struct ast_conference *cnf;
01354
01355 if (!strncasecmp(word, "all", len)) {
01356 if (state == 0) {
01357 return ast_strdup("all");
01358 }
01359 --state;
01360 }
01361
01362
01363 myline = ast_strdupa(line);
01364 strtok_r(myline, " ", &saved);
01365 strtok_r(NULL, " ", &saved);
01366 confno = strtok_r(NULL, " ", &saved);
01367
01368 AST_LIST_LOCK(&confs);
01369 AST_LIST_TRAVERSE(&confs, cnf, list) {
01370 if (!strcmp(confno, cnf->confno)) {
01371 ret = complete_userno(cnf, word, state);
01372 break;
01373 }
01374 }
01375 AST_LIST_UNLOCK(&confs);
01376
01377 return ret;
01378 }
01379 return NULL;
01380 }
01381
01382 static char *complete_meetmecmd_lock(const char *word, int pos, int state)
01383 {
01384 if (pos == 2) {
01385 return complete_confno(word, state);
01386 }
01387 return NULL;
01388 }
01389
01390 static char *complete_meetmecmd_list(const char *line, const char *word, int pos, int state)
01391 {
01392 int len;
01393
01394 if (pos == 2) {
01395 len = strlen(word);
01396 if (!strncasecmp(word, STR_CONCISE, len)) {
01397 if (state == 0) {
01398 return ast_strdup(STR_CONCISE);
01399 }
01400 --state;
01401 }
01402
01403 return complete_confno(word, state);
01404 }
01405 if (pos == 3 && state == 0) {
01406 char *saved = NULL;
01407 char *myline;
01408 char *confno;
01409
01410
01411 myline = ast_strdupa(line);
01412 strtok_r(myline, " ", &saved);
01413 strtok_r(NULL, " ", &saved);
01414 confno = strtok_r(NULL, " ", &saved);
01415
01416 if (!strcasecmp(confno, STR_CONCISE)) {
01417
01418 return NULL;
01419 }
01420
01421 len = strlen(word);
01422 if (!strncasecmp(word, STR_CONCISE, len)) {
01423 return ast_strdup(STR_CONCISE);
01424 }
01425 }
01426 return NULL;
01427 }
01428
01429 static char *meetme_show_cmd(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
01430 {
01431
01432 struct ast_conf_user *user;
01433 struct ast_conference *cnf;
01434 int hr, min, sec;
01435 int total = 0;
01436 time_t now;
01437 #define MC_HEADER_FORMAT "%-14s %-14s %-10s %-8s %-8s %-6s\n"
01438 #define MC_DATA_FORMAT "%-12.12s %4.4d %4.4s %02d:%02d:%02d %-8s %-6s\n"
01439
01440 switch (cmd) {
01441 case CLI_INIT:
01442 e->command = "meetme list";
01443 e->usage =
01444 "Usage: meetme list [<confno>] [" STR_CONCISE "]\n"
01445 " List all conferences or a specific conference.\n";
01446 return NULL;
01447 case CLI_GENERATE:
01448 return complete_meetmecmd_list(a->line, a->word, a->pos, a->n);
01449 }
01450
01451 if (a->argc == 2 || (a->argc == 3 && !strcasecmp(a->argv[2], STR_CONCISE))) {
01452
01453 int concise = (a->argc == 3);
01454 struct ast_str *marked_users;
01455
01456 if (!(marked_users = ast_str_create(30))) {
01457 return CLI_FAILURE;
01458 }
01459
01460 now = time(NULL);
01461 AST_LIST_LOCK(&confs);
01462 if (AST_LIST_EMPTY(&confs)) {
01463 if (!concise) {
01464 ast_cli(a->fd, "No active MeetMe conferences.\n");
01465 }
01466 AST_LIST_UNLOCK(&confs);
01467 ast_free(marked_users);
01468 return CLI_SUCCESS;
01469 }
01470 if (!concise) {
01471 ast_cli(a->fd, MC_HEADER_FORMAT, "Conf Num", "Parties", "Marked", "Activity", "Creation", "Locked");
01472 }
01473 AST_LIST_TRAVERSE(&confs, cnf, list) {
01474 hr = (now - cnf->start) / 3600;
01475 min = ((now - cnf->start) % 3600) / 60;
01476 sec = (now - cnf->start) % 60;
01477 if (!concise) {
01478 if (cnf->markedusers == 0) {
01479 ast_str_set(&marked_users, 0, "N/A ");
01480 } else {
01481 ast_str_set(&marked_users, 0, "%4.4d", cnf->markedusers);
01482 }
01483 ast_cli(a->fd, MC_DATA_FORMAT, cnf->confno, cnf->users,
01484 ast_str_buffer(marked_users), hr, min, sec,
01485 cnf->isdynamic ? "Dynamic" : "Static", cnf->locked ? "Yes" : "No");
01486 } else {
01487 ast_cli(a->fd, "%s!%d!%d!%02d:%02d:%02d!%d!%d\n",
01488 cnf->confno,
01489 cnf->users,
01490 cnf->markedusers,
01491 hr, min, sec,
01492 cnf->isdynamic,
01493 cnf->locked);
01494 }
01495
01496 total += cnf->users;
01497 }
01498 AST_LIST_UNLOCK(&confs);
01499 if (!concise) {
01500 ast_cli(a->fd, "* Total number of MeetMe users: %d\n", total);
01501 }
01502 ast_free(marked_users);
01503 return CLI_SUCCESS;
01504 }
01505 if (a->argc == 3 || (a->argc == 4 && !strcasecmp(a->argv[3], STR_CONCISE))) {
01506 struct ao2_iterator user_iter;
01507 int concise = (a->argc == 4);
01508
01509
01510 if (AST_LIST_EMPTY(&confs)) {
01511 if (!concise) {
01512 ast_cli(a->fd, "No active MeetMe conferences.\n");
01513 }
01514 return CLI_SUCCESS;
01515 }
01516
01517 AST_LIST_LOCK(&confs);
01518 AST_LIST_TRAVERSE(&confs, cnf, list) {
01519 if (strcmp(cnf->confno, a->argv[2]) == 0) {
01520 break;
01521 }
01522 }
01523 if (!cnf) {
01524 if (!concise)
01525 ast_cli(a->fd, "No such conference: %s.\n", a->argv[2]);
01526 AST_LIST_UNLOCK(&confs);
01527 return CLI_SUCCESS;
01528 }
01529
01530 time(&now);
01531 user_iter = ao2_iterator_init(cnf->usercontainer, 0);
01532 while((user = ao2_iterator_next(&user_iter))) {
01533 hr = (now - user->jointime) / 3600;
01534 min = ((now - user->jointime) % 3600) / 60;
01535 sec = (now - user->jointime) % 60;
01536 if (!concise) {
01537 ast_cli(a->fd, "User #: %-2.2d %12.12s %-20.20s Channel: %s %s %s %s %s %s %02d:%02d:%02d\n",
01538 user->user_no,
01539 S_COR(user->chan->caller.id.number.valid, user->chan->caller.id.number.str, "<unknown>"),
01540 S_COR(user->chan->caller.id.name.valid, user->chan->caller.id.name.str, "<no name>"),
01541 user->chan->name,
01542 ast_test_flag64(&user->userflags, CONFFLAG_ADMIN) ? "(Admin)" : "",
01543 ast_test_flag64(&user->userflags, CONFFLAG_MONITOR) ? "(Listen only)" : "",
01544 user->adminflags & ADMINFLAG_MUTED ? "(Admin Muted)" : user->adminflags & ADMINFLAG_SELFMUTED ? "(Muted)" : "",
01545 user->adminflags & ADMINFLAG_T_REQUEST ? "(Request to Talk)" : "",
01546 istalking(user->talking), hr, min, sec);
01547 } else {
01548 ast_cli(a->fd, "%d!%s!%s!%s!%s!%s!%s!%s!%d!%02d:%02d:%02d\n",
01549 user->user_no,
01550 S_COR(user->chan->caller.id.number.valid, user->chan->caller.id.number.str, ""),
01551 S_COR(user->chan->caller.id.name.valid, user->chan->caller.id.name.str, ""),
01552 user->chan->name,
01553 ast_test_flag64(&user->userflags, CONFFLAG_ADMIN) ? "1" : "",
01554 ast_test_flag64(&user->userflags, CONFFLAG_MONITOR) ? "1" : "",
01555 user->adminflags & (ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED) ? "1" : "",
01556 user->adminflags & ADMINFLAG_T_REQUEST ? "1" : "",
01557 user->talking, hr, min, sec);
01558 }
01559 ao2_ref(user, -1);
01560 }
01561 ao2_iterator_destroy(&user_iter);
01562 if (!concise) {
01563 ast_cli(a->fd, "%d users in that conference.\n", cnf->users);
01564 }
01565 AST_LIST_UNLOCK(&confs);
01566 return CLI_SUCCESS;
01567 }
01568 return CLI_SHOWUSAGE;
01569 }
01570
01571
01572 static char *meetme_cmd_helper(struct ast_cli_args *a)
01573 {
01574
01575 struct ast_str *cmdline;
01576
01577
01578 if (!(cmdline = ast_str_create(MAX_CONFNUM))) {
01579 return CLI_FAILURE;
01580 }
01581
01582 ast_str_set(&cmdline, 0, "%s", a->argv[2]);
01583 if (strcasestr(a->argv[1], "lock")) {
01584 if (strcasecmp(a->argv[1], "lock") == 0) {
01585
01586 ast_str_append(&cmdline, 0, ",L");
01587 } else {
01588
01589 ast_str_append(&cmdline, 0, ",l");
01590 }
01591 } else if (strcasestr(a->argv[1], "mute")) {
01592 if (strcasecmp(a->argv[1], "mute") == 0) {
01593
01594 if (strcasecmp(a->argv[3], "all") == 0) {
01595 ast_str_append(&cmdline, 0, ",N");
01596 } else {
01597 ast_str_append(&cmdline, 0, ",M,%s", a->argv[3]);
01598 }
01599 } else {
01600
01601 if (strcasecmp(a->argv[3], "all") == 0) {
01602 ast_str_append(&cmdline, 0, ",n");
01603 } else {
01604 ast_str_append(&cmdline, 0, ",m,%s", a->argv[3]);
01605 }
01606 }
01607 } else if (strcasecmp(a->argv[1], "kick") == 0) {
01608 if (strcasecmp(a->argv[3], "all") == 0) {
01609
01610 ast_str_append(&cmdline, 0, ",K");
01611 } else {
01612
01613 ast_str_append(&cmdline, 0, ",k,%s", a->argv[3]);
01614 }
01615 } else {
01616
01617
01618
01619
01620 ast_free(cmdline);
01621 return CLI_SHOWUSAGE;
01622 }
01623
01624 ast_debug(1, "Cmdline: %s\n", ast_str_buffer(cmdline));
01625
01626 admin_exec(NULL, ast_str_buffer(cmdline));
01627 ast_free(cmdline);
01628
01629 return CLI_SUCCESS;
01630 }
01631
01632 static char *meetme_lock_cmd(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
01633 {
01634 switch (cmd) {
01635 case CLI_INIT:
01636 e->command = "meetme {lock|unlock}";
01637 e->usage =
01638 "Usage: meetme lock|unlock <confno>\n"
01639 " Lock or unlock a conference to new users.\n";
01640 return NULL;
01641 case CLI_GENERATE:
01642 return complete_meetmecmd_lock(a->word, a->pos, a->n);
01643 }
01644
01645 if (a->argc != 3) {
01646 return CLI_SHOWUSAGE;
01647 }
01648
01649 return meetme_cmd_helper(a);
01650 }
01651
01652 static char *meetme_kick_cmd(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
01653 {
01654 switch (cmd) {
01655 case CLI_INIT:
01656 e->command = "meetme kick";
01657 e->usage =
01658 "Usage: meetme kick <confno> all|<userno>\n"
01659 " Kick a conference or a user in a conference.\n";
01660 return NULL;
01661 case CLI_GENERATE:
01662 return complete_meetmecmd_mute_kick(a->line, a->word, a->pos, a->n);
01663 }
01664
01665 if (a->argc != 4) {
01666 return CLI_SHOWUSAGE;
01667 }
01668
01669 return meetme_cmd_helper(a);
01670 }
01671
01672 static char *meetme_mute_cmd(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
01673 {
01674 switch (cmd) {
01675 case CLI_INIT:
01676 e->command = "meetme {mute|unmute}";
01677 e->usage =
01678 "Usage: meetme mute|unmute <confno> all|<userno>\n"
01679 " Mute or unmute a conference or a user in a conference.\n";
01680 return NULL;
01681 case CLI_GENERATE:
01682 return complete_meetmecmd_mute_kick(a->line, a->word, a->pos, a->n);
01683 }
01684
01685 if (a->argc != 4) {
01686 return CLI_SHOWUSAGE;
01687 }
01688
01689 return meetme_cmd_helper(a);
01690 }
01691
01692 static const char *sla_hold_str(unsigned int hold_access)
01693 {
01694 const char *hold = "Unknown";
01695
01696 switch (hold_access) {
01697 case SLA_HOLD_OPEN:
01698 hold = "Open";
01699 break;
01700 case SLA_HOLD_PRIVATE:
01701 hold = "Private";
01702 default:
01703 break;
01704 }
01705
01706 return hold;
01707 }
01708
01709 static char *sla_show_trunks(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
01710 {
01711 const struct sla_trunk *trunk;
01712
01713 switch (cmd) {
01714 case CLI_INIT:
01715 e->command = "sla show trunks";
01716 e->usage =
01717 "Usage: sla show trunks\n"
01718 " This will list all trunks defined in sla.conf\n";
01719 return NULL;
01720 case CLI_GENERATE:
01721 return NULL;
01722 }
01723
01724 ast_cli(a->fd, "\n"
01725 "=============================================================\n"
01726 "=== Configured SLA Trunks ===================================\n"
01727 "=============================================================\n"
01728 "===\n");
01729 AST_RWLIST_RDLOCK(&sla_trunks);
01730 AST_RWLIST_TRAVERSE(&sla_trunks, trunk, entry) {
01731 struct sla_station_ref *station_ref;
01732 char ring_timeout[16] = "(none)";
01733 if (trunk->ring_timeout)
01734 snprintf(ring_timeout, sizeof(ring_timeout), "%u Seconds", trunk->ring_timeout);
01735 ast_cli(a->fd, "=== ---------------------------------------------------------\n"
01736 "=== Trunk Name: %s\n"
01737 "=== ==> Device: %s\n"
01738 "=== ==> AutoContext: %s\n"
01739 "=== ==> RingTimeout: %s\n"
01740 "=== ==> BargeAllowed: %s\n"
01741 "=== ==> HoldAccess: %s\n"
01742 "=== ==> Stations ...\n",
01743 trunk->name, trunk->device,
01744 S_OR(trunk->autocontext, "(none)"),
01745 ring_timeout,
01746 trunk->barge_disabled ? "No" : "Yes",
01747 sla_hold_str(trunk->hold_access));
01748 AST_RWLIST_RDLOCK(&sla_stations);
01749 AST_LIST_TRAVERSE(&trunk->stations, station_ref, entry)
01750 ast_cli(a->fd, "=== ==> Station name: %s\n", station_ref->station->name);
01751 AST_RWLIST_UNLOCK(&sla_stations);
01752 ast_cli(a->fd, "=== ---------------------------------------------------------\n===\n");
01753 }
01754 AST_RWLIST_UNLOCK(&sla_trunks);
01755 ast_cli(a->fd, "=============================================================\n\n");
01756
01757 return CLI_SUCCESS;
01758 }
01759
01760 static const char *trunkstate2str(enum sla_trunk_state state)
01761 {
01762 #define S(e) case e: return # e;
01763 switch (state) {
01764 S(SLA_TRUNK_STATE_IDLE)
01765 S(SLA_TRUNK_STATE_RINGING)
01766 S(SLA_TRUNK_STATE_UP)
01767 S(SLA_TRUNK_STATE_ONHOLD)
01768 S(SLA_TRUNK_STATE_ONHOLD_BYME)
01769 }
01770 return "Uknown State";
01771 #undef S
01772 }
01773
01774 static char *sla_show_stations(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
01775 {
01776 const struct sla_station *station;
01777
01778 switch (cmd) {
01779 case CLI_INIT:
01780 e->command = "sla show stations";
01781 e->usage =
01782 "Usage: sla show stations\n"
01783 " This will list all stations defined in sla.conf\n";
01784 return NULL;
01785 case CLI_GENERATE:
01786 return NULL;
01787 }
01788
01789 ast_cli(a->fd, "\n"
01790 "=============================================================\n"
01791 "=== Configured SLA Stations =================================\n"
01792 "=============================================================\n"
01793 "===\n");
01794 AST_RWLIST_RDLOCK(&sla_stations);
01795 AST_RWLIST_TRAVERSE(&sla_stations, station, entry) {
01796 struct sla_trunk_ref *trunk_ref;
01797 char ring_timeout[16] = "(none)";
01798 char ring_delay[16] = "(none)";
01799 if (station->ring_timeout) {
01800 snprintf(ring_timeout, sizeof(ring_timeout),
01801 "%u", station->ring_timeout);
01802 }
01803 if (station->ring_delay) {
01804 snprintf(ring_delay, sizeof(ring_delay),
01805 "%u", station->ring_delay);
01806 }
01807 ast_cli(a->fd, "=== ---------------------------------------------------------\n"
01808 "=== Station Name: %s\n"
01809 "=== ==> Device: %s\n"
01810 "=== ==> AutoContext: %s\n"
01811 "=== ==> RingTimeout: %s\n"
01812 "=== ==> RingDelay: %s\n"
01813 "=== ==> HoldAccess: %s\n"
01814 "=== ==> Trunks ...\n",
01815 station->name, station->device,
01816 S_OR(station->autocontext, "(none)"),
01817 ring_timeout, ring_delay,
01818 sla_hold_str(station->hold_access));
01819 AST_RWLIST_RDLOCK(&sla_trunks);
01820 AST_LIST_TRAVERSE(&station->trunks, trunk_ref, entry) {
01821 if (trunk_ref->ring_timeout) {
01822 snprintf(ring_timeout, sizeof(ring_timeout),
01823 "%u", trunk_ref->ring_timeout);
01824 } else
01825 strcpy(ring_timeout, "(none)");
01826 if (trunk_ref->ring_delay) {
01827 snprintf(ring_delay, sizeof(ring_delay),
01828 "%u", trunk_ref->ring_delay);
01829 } else
01830 strcpy(ring_delay, "(none)");
01831 ast_cli(a->fd, "=== ==> Trunk Name: %s\n"
01832 "=== ==> State: %s\n"
01833 "=== ==> RingTimeout: %s\n"
01834 "=== ==> RingDelay: %s\n",
01835 trunk_ref->trunk->name,
01836 trunkstate2str(trunk_ref->state),
01837 ring_timeout, ring_delay);
01838 }
01839 AST_RWLIST_UNLOCK(&sla_trunks);
01840 ast_cli(a->fd, "=== ---------------------------------------------------------\n"
01841 "===\n");
01842 }
01843 AST_RWLIST_UNLOCK(&sla_stations);
01844 ast_cli(a->fd, "============================================================\n"
01845 "\n");
01846
01847 return CLI_SUCCESS;
01848 }
01849
01850 static struct ast_cli_entry cli_meetme[] = {
01851 AST_CLI_DEFINE(meetme_kick_cmd, "Kick a conference or a user in a conference."),
01852 AST_CLI_DEFINE(meetme_show_cmd, "List all conferences or a specific conference."),
01853 AST_CLI_DEFINE(meetme_lock_cmd, "Lock or unlock a conference to new users."),
01854 AST_CLI_DEFINE(meetme_mute_cmd, "Mute or unmute a conference or a user in a conference."),
01855 AST_CLI_DEFINE(sla_show_trunks, "Show SLA Trunks"),
01856 AST_CLI_DEFINE(sla_show_stations, "Show SLA Stations"),
01857 };
01858
01859 static void conf_flush(int fd, struct ast_channel *chan)
01860 {
01861 int x;
01862
01863
01864
01865
01866 if (chan) {
01867 struct ast_frame *f;
01868
01869
01870
01871
01872 while (ast_waitfor(chan, 1) > 0) {
01873 f = ast_read(chan);
01874 if (f)
01875 ast_frfree(f);
01876 else
01877 break;
01878 }
01879 }
01880
01881
01882 x = DAHDI_FLUSH_ALL;
01883 if (ioctl(fd, DAHDI_FLUSH, &x))
01884 ast_log(LOG_WARNING, "Error flushing channel\n");
01885
01886 }
01887
01888
01889
01890
01891 static int conf_free(struct ast_conference *conf)
01892 {
01893 int x;
01894 struct announce_listitem *item;
01895
01896 AST_LIST_REMOVE(&confs, conf, list);
01897 manager_event(EVENT_FLAG_CALL, "MeetmeEnd", "Meetme: %s\r\n", conf->confno);
01898
01899 if (conf->recording == MEETME_RECORD_ACTIVE) {
01900 conf->recording = MEETME_RECORD_TERMINATE;
01901 AST_LIST_UNLOCK(&confs);
01902 while (1) {
01903 usleep(1);
01904 AST_LIST_LOCK(&confs);
01905 if (conf->recording == MEETME_RECORD_OFF)
01906 break;
01907 AST_LIST_UNLOCK(&confs);
01908 }
01909 }
01910
01911 for (x = 0; x < AST_FRAME_BITS; x++) {
01912 if (conf->transframe[x])
01913 ast_frfree(conf->transframe[x]);
01914 if (conf->transpath[x])
01915 ast_translator_free_path(conf->transpath[x]);
01916 }
01917 if (conf->announcethread != AST_PTHREADT_NULL) {
01918 ast_mutex_lock(&conf->announcelistlock);
01919 conf->announcethread_stop = 1;
01920 ast_softhangup(conf->chan, AST_SOFTHANGUP_EXPLICIT);
01921 ast_cond_signal(&conf->announcelist_addition);
01922 ast_mutex_unlock(&conf->announcelistlock);
01923 pthread_join(conf->announcethread, NULL);
01924
01925 while ((item = AST_LIST_REMOVE_HEAD(&conf->announcelist, entry))) {
01926 ast_filedelete(item->namerecloc, NULL);
01927 ao2_ref(item, -1);
01928 }
01929 ast_mutex_destroy(&conf->announcelistlock);
01930 }
01931
01932 if (conf->origframe)
01933 ast_frfree(conf->origframe);
01934 if (conf->lchan)
01935 ast_hangup(conf->lchan);
01936 if (conf->chan)
01937 ast_hangup(conf->chan);
01938 if (conf->fd >= 0)
01939 close(conf->fd);
01940 if (conf->recordingfilename) {
01941 ast_free(conf->recordingfilename);
01942 }
01943 if (conf->usercontainer) {
01944 ao2_ref(conf->usercontainer, -1);
01945 }
01946 if (conf->recordingformat) {
01947 ast_free(conf->recordingformat);
01948 }
01949 ast_mutex_destroy(&conf->playlock);
01950 ast_mutex_destroy(&conf->listenlock);
01951 ast_mutex_destroy(&conf->recordthreadlock);
01952 ast_mutex_destroy(&conf->announcethreadlock);
01953 ast_free(conf);
01954
01955 return 0;
01956 }
01957
01958 static void conf_queue_dtmf(const struct ast_conference *conf,
01959 const struct ast_conf_user *sender, struct ast_frame *f)
01960 {
01961 struct ast_conf_user *user;
01962 struct ao2_iterator user_iter;
01963
01964 user_iter = ao2_iterator_init(conf->usercontainer, 0);
01965 while ((user = ao2_iterator_next(&user_iter))) {
01966 if (user == sender) {
01967 ao2_ref(user, -1);
01968 continue;
01969 }
01970 if (ast_write(user->chan, f) < 0)
01971 ast_log(LOG_WARNING, "Error writing frame to channel %s\n", user->chan->name);
01972 ao2_ref(user, -1);
01973 }
01974 ao2_iterator_destroy(&user_iter);
01975 }
01976
01977 static void sla_queue_event_full(enum sla_event_type type,
01978 struct sla_trunk_ref *trunk_ref, struct sla_station *station, int lock)
01979 {
01980 struct sla_event *event;
01981
01982 if (sla.thread == AST_PTHREADT_NULL) {
01983 return;
01984 }
01985
01986 if (!(event = ast_calloc(1, sizeof(*event))))
01987 return;
01988
01989 event->type = type;
01990 event->trunk_ref = trunk_ref;
01991 event->station = station;
01992
01993 if (!lock) {
01994 AST_LIST_INSERT_TAIL(&sla.event_q, event, entry);
01995 return;
01996 }
01997
01998 ast_mutex_lock(&sla.lock);
01999 AST_LIST_INSERT_TAIL(&sla.event_q, event, entry);
02000 ast_cond_signal(&sla.cond);
02001 ast_mutex_unlock(&sla.lock);
02002 }
02003
02004 static void sla_queue_event_nolock(enum sla_event_type type)
02005 {
02006 sla_queue_event_full(type, NULL, NULL, 0);
02007 }
02008
02009 static void sla_queue_event(enum sla_event_type type)
02010 {
02011 sla_queue_event_full(type, NULL, NULL, 1);
02012 }
02013
02014
02015 static void sla_queue_event_conf(enum sla_event_type type, struct ast_channel *chan,
02016 struct ast_conference *conf)
02017 {
02018 struct sla_station *station;
02019 struct sla_trunk_ref *trunk_ref = NULL;
02020 char *trunk_name;
02021
02022 trunk_name = ast_strdupa(conf->confno);
02023 strsep(&trunk_name, "_");
02024 if (ast_strlen_zero(trunk_name)) {
02025 ast_log(LOG_ERROR, "Invalid conference name for SLA - '%s'!\n", conf->confno);
02026 return;
02027 }
02028
02029 AST_RWLIST_RDLOCK(&sla_stations);
02030 AST_RWLIST_TRAVERSE(&sla_stations, station, entry) {
02031 AST_LIST_TRAVERSE(&station->trunks, trunk_ref, entry) {
02032 if (trunk_ref->chan == chan && !strcmp(trunk_ref->trunk->name, trunk_name))
02033 break;
02034 }
02035 if (trunk_ref)
02036 break;
02037 }
02038 AST_RWLIST_UNLOCK(&sla_stations);
02039
02040 if (!trunk_ref) {
02041 ast_debug(1, "Trunk not found for event!\n");
02042 return;
02043 }
02044
02045 sla_queue_event_full(type, trunk_ref, station, 1);
02046 }
02047
02048
02049 static int dispose_conf(struct ast_conference *conf)
02050 {
02051 int res = 0;
02052 int confno_int = 0;
02053
02054 AST_LIST_LOCK(&confs);
02055 if (ast_atomic_dec_and_test(&conf->refcount)) {
02056
02057 if ((sscanf(conf->confno, "%4d", &confno_int) == 1) && (confno_int >= 0 && confno_int < 1024)) {
02058 conf_map[confno_int] = 0;
02059 }
02060 conf_free(conf);
02061 res = 1;
02062 }
02063 AST_LIST_UNLOCK(&confs);
02064
02065 return res;
02066 }
02067
02068 static int rt_extend_conf(const char *confno)
02069 {
02070 char currenttime[32];
02071 char endtime[32];
02072 struct timeval now;
02073 struct ast_tm tm;
02074 struct ast_variable *var, *orig_var;
02075 char bookid[51];
02076
02077 if (!extendby) {
02078 return 0;
02079 }
02080
02081 now = ast_tvnow();
02082
02083 ast_localtime(&now, &tm, NULL);
02084 ast_strftime(currenttime, sizeof(currenttime), DATE_FORMAT, &tm);
02085
02086 var = ast_load_realtime("meetme", "confno",
02087 confno, "startTime<= ", currenttime,
02088 "endtime>= ", currenttime, NULL);
02089
02090 orig_var = var;
02091
02092
02093 while (var) {
02094 if (!strcasecmp(var->name, "bookid")) {
02095 ast_copy_string(bookid, var->value, sizeof(bookid));
02096 }
02097 if (!strcasecmp(var->name, "endtime")) {
02098 ast_copy_string(endtime, var->value, sizeof(endtime));
02099 }
02100
02101 var = var->next;
02102 }
02103 ast_variables_destroy(orig_var);
02104
02105 ast_strptime(endtime, DATE_FORMAT, &tm);
02106 now = ast_mktime(&tm, NULL);
02107
02108 now.tv_sec += extendby;
02109
02110 ast_localtime(&now, &tm, NULL);
02111 ast_strftime(currenttime, sizeof(currenttime), DATE_FORMAT, &tm);
02112 strcat(currenttime, "0");
02113
02114 var = ast_load_realtime("meetme", "confno",
02115 confno, "startTime<= ", currenttime,
02116 "endtime>= ", currenttime, NULL);
02117
02118
02119 if (!var) {
02120 ast_debug(3, "Trying to update the endtime of Conference %s to %s\n", confno, currenttime);
02121 ast_update_realtime("meetme", "bookid", bookid, "endtime", currenttime, NULL);
02122 return 0;
02123
02124 }
02125
02126 ast_variables_destroy(var);
02127 return -1;
02128 }
02129
02130 static void conf_start_moh(struct ast_channel *chan, const char *musicclass)
02131 {
02132 char *original_moh;
02133
02134 ast_channel_lock(chan);
02135 original_moh = ast_strdupa(chan->musicclass);
02136 ast_string_field_set(chan, musicclass, musicclass);
02137 ast_channel_unlock(chan);
02138
02139 ast_moh_start(chan, original_moh, NULL);
02140
02141 ast_channel_lock(chan);
02142 ast_string_field_set(chan, musicclass, original_moh);
02143 ast_channel_unlock(chan);
02144 }
02145
02146 static const char *get_announce_filename(enum announcetypes type)
02147 {
02148 switch (type) {
02149 case CONF_HASLEFT:
02150 return "conf-hasleft";
02151 break;
02152 case CONF_HASJOIN:
02153 return "conf-hasjoin";
02154 break;
02155 default:
02156 return "";
02157 }
02158 }
02159
02160 static void *announce_thread(void *data)
02161 {
02162 struct announce_listitem *current;
02163 struct ast_conference *conf = data;
02164 int res;
02165 char filename[PATH_MAX] = "";
02166 AST_LIST_HEAD_NOLOCK(, announce_listitem) local_list;
02167 AST_LIST_HEAD_INIT_NOLOCK(&local_list);
02168
02169 while (!conf->announcethread_stop) {
02170 ast_mutex_lock(&conf->announcelistlock);
02171 if (conf->announcethread_stop) {
02172 ast_mutex_unlock(&conf->announcelistlock);
02173 break;
02174 }
02175 if (AST_LIST_EMPTY(&conf->announcelist))
02176 ast_cond_wait(&conf->announcelist_addition, &conf->announcelistlock);
02177
02178 AST_LIST_APPEND_LIST(&local_list, &conf->announcelist, entry);
02179 AST_LIST_HEAD_INIT_NOLOCK(&conf->announcelist);
02180
02181 ast_mutex_unlock(&conf->announcelistlock);
02182 if (conf->announcethread_stop) {
02183 break;
02184 }
02185
02186 for (res = 1; !conf->announcethread_stop && (current = AST_LIST_REMOVE_HEAD(&local_list, entry)); ao2_ref(current, -1)) {
02187 ast_log(LOG_DEBUG, "About to play %s\n", current->namerecloc);
02188 if (!ast_fileexists(current->namerecloc, NULL, NULL))
02189 continue;
02190 if ((current->confchan) && (current->confusers > 1) && !ast_check_hangup(current->confchan)) {
02191 if (!ast_streamfile(current->confchan, current->namerecloc, current->language))
02192 res = ast_waitstream(current->confchan, "");
02193 if (!res) {
02194 ast_copy_string(filename, get_announce_filename(current->announcetype), sizeof(filename));
02195 if (!ast_streamfile(current->confchan, filename, current->language))
02196 ast_waitstream(current->confchan, "");
02197 }
02198 }
02199 if (current->announcetype == CONF_HASLEFT) {
02200 ast_filedelete(current->namerecloc, NULL);
02201 }
02202 }
02203 }
02204
02205
02206 while ((current = AST_LIST_REMOVE_HEAD(&local_list, entry))) {
02207 ast_filedelete(current->namerecloc, NULL);
02208 ao2_ref(current, -1);
02209 }
02210 return NULL;
02211 }
02212
02213 static int can_write(struct ast_channel *chan, struct ast_flags64 *confflags)
02214 {
02215 if (!ast_test_flag64(confflags, CONFFLAG_NO_AUDIO_UNTIL_UP)) {
02216 return 1;
02217 }
02218
02219 return (chan->_state == AST_STATE_UP);
02220 }
02221
02222 static void send_talking_event(struct ast_channel *chan, struct ast_conference *conf, struct ast_conf_user *user, int talking)
02223 {
02224 ast_manager_event(chan, EVENT_FLAG_CALL, "MeetmeTalking",
02225 "Channel: %s\r\n"
02226 "Uniqueid: %s\r\n"
02227 "Meetme: %s\r\n"
02228 "Usernum: %d\r\n"
02229 "Status: %s\r\n",
02230 chan->name, chan->uniqueid, conf->confno, user->user_no, talking ? "on" : "off");
02231 }
02232
02233 static void set_user_talking(struct ast_channel *chan, struct ast_conference *conf, struct ast_conf_user *user, int talking, int monitor)
02234 {
02235 int last_talking = user->talking;
02236 if (last_talking == talking)
02237 return;
02238
02239 user->talking = talking;
02240
02241 if (monitor) {
02242
02243 int was_talking = (last_talking > 0);
02244 int now_talking = (talking > 0);
02245 if (was_talking != now_talking) {
02246 send_talking_event(chan, conf, user, now_talking);
02247 }
02248 }
02249 }
02250
02251 static int user_set_kickme_cb(void *obj, void *check_admin_arg, int flags)
02252 {
02253 struct ast_conf_user *user = obj;
02254
02255
02256 if (!check_admin_arg || (check_admin_arg && !ast_test_flag64(&user->userflags, CONFFLAG_ADMIN))) {
02257 user->adminflags |= ADMINFLAG_KICKME;
02258 }
02259 return 0;
02260 }
02261
02262 static int user_set_unmuted_cb(void *obj, void *check_admin_arg, int flags)
02263 {
02264 struct ast_conf_user *user = obj;
02265
02266
02267 if (!check_admin_arg || !ast_test_flag64(&user->userflags, CONFFLAG_ADMIN)) {
02268 user->adminflags &= ~(ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED | ADMINFLAG_T_REQUEST);
02269 }
02270 return 0;
02271 }
02272
02273 static int user_set_muted_cb(void *obj, void *check_admin_arg, int flags)
02274 {
02275 struct ast_conf_user *user = obj;
02276
02277
02278 if (!check_admin_arg || !ast_test_flag64(&user->userflags, CONFFLAG_ADMIN)) {
02279 user->adminflags |= ADMINFLAG_MUTED;
02280 }
02281 return 0;
02282 }
02283
02284 static int conf_run(struct ast_channel *chan, struct ast_conference *conf, struct ast_flags64 *confflags, char *optargs[])
02285 {
02286 struct ast_conf_user *user = NULL;
02287 int fd;
02288 struct dahdi_confinfo dahdic, dahdic_empty;
02289 struct ast_frame *f;
02290 struct ast_channel *c;
02291 struct ast_frame fr;
02292 int outfd;
02293 int ms;
02294 int nfds;
02295 int res;
02296 int retrydahdi;
02297 int origfd;
02298 int musiconhold = 0, mohtempstopped = 0;
02299 int firstpass = 0;
02300 int lastmarked = 0;
02301 int currentmarked = 0;
02302 int ret = -1;
02303 int x;
02304 int menu_active = 0;
02305 int menu8_active = 0;
02306 int talkreq_manager = 0;
02307 int using_pseudo = 0;
02308 int duration = 20;
02309 int sent_event = 0;
02310 int checked = 0;
02311 int announcement_played = 0;
02312 struct timeval now;
02313 struct ast_dsp *dsp = NULL;
02314 struct ast_app *agi_app;
02315 char *agifile, *mod_speex;
02316 const char *agifiledefault = "conf-background.agi", *tmpvar;
02317 char meetmesecs[30] = "";
02318 char exitcontext[AST_MAX_CONTEXT] = "";
02319 char recordingtmp[AST_MAX_EXTENSION] = "";
02320 char members[10] = "";
02321 int dtmf, opt_waitmarked_timeout = 0;
02322 time_t timeout = 0;
02323 struct dahdi_bufferinfo bi;
02324 char __buf[CONF_SIZE + AST_FRIENDLY_OFFSET];
02325 char *buf = __buf + AST_FRIENDLY_OFFSET;
02326 char *exitkeys = NULL;
02327 unsigned int calldurationlimit = 0;
02328 long timelimit = 0;
02329 long play_warning = 0;
02330 long warning_freq = 0;
02331 const char *warning_sound = NULL;
02332 const char *end_sound = NULL;
02333 char *parse;
02334 long time_left_ms = 0;
02335 struct timeval nexteventts = { 0, };
02336 int to;
02337 int setusercount = 0;
02338 int confsilence = 0, totalsilence = 0;
02339
02340 if (!(user = ao2_alloc(sizeof(*user), NULL))) {
02341 return ret;
02342 }
02343
02344
02345 if (ast_test_flag64(confflags, CONFFLAG_WAITMARKED) &&
02346 !ast_strlen_zero(optargs[OPT_ARG_WAITMARKED]) &&
02347 (sscanf(optargs[OPT_ARG_WAITMARKED], "%30d", &opt_waitmarked_timeout) == 1) &&
02348 (opt_waitmarked_timeout > 0)) {
02349 timeout = time(NULL) + opt_waitmarked_timeout;
02350 }
02351
02352 if (ast_test_flag64(confflags, CONFFLAG_DURATION_STOP) && !ast_strlen_zero(optargs[OPT_ARG_DURATION_STOP])) {
02353 calldurationlimit = atoi(optargs[OPT_ARG_DURATION_STOP]);
02354 ast_verb(3, "Setting call duration limit to %d seconds.\n", calldurationlimit);
02355 }
02356
02357 if (ast_test_flag64(confflags, CONFFLAG_DURATION_LIMIT) && !ast_strlen_zero(optargs[OPT_ARG_DURATION_LIMIT])) {
02358 char *limit_str, *warning_str, *warnfreq_str;
02359 const char *var;
02360
02361 parse = optargs[OPT_ARG_DURATION_LIMIT];
02362 limit_str = strsep(&parse, ":");
02363 warning_str = strsep(&parse, ":");
02364 warnfreq_str = parse;
02365
02366 timelimit = atol(limit_str);
02367 if (warning_str)
02368 play_warning = atol(warning_str);
02369 if (warnfreq_str)
02370 warning_freq = atol(warnfreq_str);
02371
02372 if (!timelimit) {
02373 timelimit = play_warning = warning_freq = 0;
02374 warning_sound = NULL;
02375 } else if (play_warning > timelimit) {
02376 if (!warning_freq) {
02377 play_warning = 0;
02378 } else {
02379 while (play_warning > timelimit)
02380 play_warning -= warning_freq;
02381 if (play_warning < 1)
02382 play_warning = warning_freq = 0;
02383 }
02384 }
02385
02386 ast_verb(3, "Setting conference duration limit to: %ldms.\n", timelimit);
02387 if (play_warning) {
02388 ast_verb(3, "Setting warning time to %ldms from the conference duration limit.\n", play_warning);
02389 }
02390 if (warning_freq) {
02391 ast_verb(3, "Setting warning frequency to %ldms.\n", warning_freq);
02392 }
02393
02394 ast_channel_lock(chan);
02395 if ((var = pbx_builtin_getvar_helper(chan, "CONF_LIMIT_WARNING_FILE"))) {
02396 var = ast_strdupa(var);
02397 }
02398 ast_channel_unlock(chan);
02399
02400 warning_sound = var ? var : "timeleft";
02401
02402 ast_channel_lock(chan);
02403 if ((var = pbx_builtin_getvar_helper(chan, "CONF_LIMIT_TIMEOUT_FILE"))) {
02404 var = ast_strdupa(var);
02405 }
02406 ast_channel_unlock(chan);
02407
02408 end_sound = var ? var : NULL;
02409
02410
02411 calldurationlimit = 0;
02412
02413 if (!play_warning && !end_sound && timelimit) {
02414 calldurationlimit = timelimit / 1000;
02415 timelimit = play_warning = warning_freq = 0;
02416 } else {
02417 ast_debug(2, "Limit Data for this call:\n");
02418 ast_debug(2, "- timelimit = %ld\n", timelimit);
02419 ast_debug(2, "- play_warning = %ld\n", play_warning);
02420 ast_debug(2, "- warning_freq = %ld\n", warning_freq);
02421 ast_debug(2, "- warning_sound = %s\n", warning_sound ? warning_sound : "UNDEF");
02422 ast_debug(2, "- end_sound = %s\n", end_sound ? end_sound : "UNDEF");
02423 }
02424 }
02425
02426
02427 if (ast_test_flag64(confflags, CONFFLAG_KEYEXIT)) {
02428 if (!ast_strlen_zero(optargs[OPT_ARG_EXITKEYS]))
02429 exitkeys = ast_strdupa(optargs[OPT_ARG_EXITKEYS]);
02430 else
02431 exitkeys = ast_strdupa("#");
02432 }
02433
02434 if (ast_test_flag64(confflags, CONFFLAG_RECORDCONF)) {
02435 if (!conf->recordingfilename) {
02436 const char *var;
02437 ast_channel_lock(chan);
02438 if ((var = pbx_builtin_getvar_helper(chan, "MEETME_RECORDINGFILE"))) {
02439 conf->recordingfilename = ast_strdup(var);
02440 }
02441 if ((var = pbx_builtin_getvar_helper(chan, "MEETME_RECORDINGFORMAT"))) {
02442 conf->recordingformat = ast_strdup(var);
02443 }
02444 ast_channel_unlock(chan);
02445 if (!conf->recordingfilename) {
02446 snprintf(recordingtmp, sizeof(recordingtmp), "meetme-conf-rec-%s-%s", conf->confno, chan->uniqueid);
02447 conf->recordingfilename = ast_strdup(recordingtmp);
02448 }
02449 if (!conf->recordingformat) {
02450 conf->recordingformat = ast_strdup("wav");
02451 }
02452 ast_verb(4, "Starting recording of MeetMe Conference %s into file %s.%s.\n",
02453 conf->confno, conf->recordingfilename, conf->recordingformat);
02454 }
02455 }
02456
02457 ast_mutex_lock(&conf->recordthreadlock);
02458 if ((conf->recordthread == AST_PTHREADT_NULL) && ast_test_flag64(confflags, CONFFLAG_RECORDCONF) &&
02459 ((conf->lchan = ast_request("DAHDI", AST_FORMAT_SLINEAR, chan, "pseudo", NULL)))) {
02460 ast_set_read_format(conf->lchan, AST_FORMAT_SLINEAR);
02461 ast_set_write_format(conf->lchan, AST_FORMAT_SLINEAR);
02462 dahdic.chan = 0;
02463 dahdic.confno = conf->dahdiconf;
02464 dahdic.confmode = DAHDI_CONF_CONFANN | DAHDI_CONF_CONFANNMON;
02465 if (ioctl(conf->lchan->fds[0], DAHDI_SETCONF, &dahdic)) {
02466 ast_log(LOG_WARNING, "Error starting listen channel\n");
02467 ast_hangup(conf->lchan);
02468 conf->lchan = NULL;
02469 } else {
02470 ast_pthread_create_detached_background(&conf->recordthread, NULL, recordthread, conf);
02471 }
02472 }
02473 ast_mutex_unlock(&conf->recordthreadlock);
02474
02475 ast_mutex_lock(&conf->announcethreadlock);
02476 if ((conf->announcethread == AST_PTHREADT_NULL) && !ast_test_flag64(confflags, CONFFLAG_QUIET) &&
02477 (ast_test_flag64(confflags, CONFFLAG_INTROUSER) || ast_test_flag64(confflags, CONFFLAG_INTROUSERNOREVIEW))) {
02478 ast_mutex_init(&conf->announcelistlock);
02479 AST_LIST_HEAD_INIT_NOLOCK(&conf->announcelist);
02480 ast_pthread_create_background(&conf->announcethread, NULL, announce_thread, conf);
02481 }
02482 ast_mutex_unlock(&conf->announcethreadlock);
02483
02484 time(&user->jointime);
02485
02486 user->timelimit = timelimit;
02487 user->play_warning = play_warning;
02488 user->warning_freq = warning_freq;
02489 user->warning_sound = warning_sound;
02490 user->end_sound = end_sound;
02491
02492 if (calldurationlimit > 0) {
02493 time(&user->kicktime);
02494 user->kicktime = user->kicktime + calldurationlimit;
02495 }
02496
02497 if (ast_tvzero(user->start_time))
02498 user->start_time = ast_tvnow();
02499 time_left_ms = user->timelimit;
02500
02501 if (user->timelimit) {
02502 nexteventts = ast_tvadd(user->start_time, ast_samp2tv(user->timelimit, 1000));
02503 nexteventts = ast_tvsub(nexteventts, ast_samp2tv(user->play_warning, 1000));
02504 }
02505
02506 if (conf->locked && (!ast_test_flag64(confflags, CONFFLAG_ADMIN))) {
02507
02508 if (!ast_streamfile(chan, "conf-locked", chan->language))
02509 ast_waitstream(chan, "");
02510 goto outrun;
02511 }
02512
02513 ast_mutex_lock(&conf->playlock);
02514
02515 if (rt_schedule && conf->maxusers) {
02516 if (conf->users >= conf->maxusers) {
02517
02518 if (!ast_streamfile(chan, "conf-full", chan->language))
02519 ast_waitstream(chan, "");
02520 ast_mutex_unlock(&conf->playlock);
02521 goto outrun;
02522 }
02523 }
02524
02525 ao2_lock(conf->usercontainer);
02526 ao2_callback(conf->usercontainer, OBJ_NODATA, user_max_cmp, &user->user_no);
02527 user->user_no++;
02528 ao2_link(conf->usercontainer, user);
02529 ao2_unlock(conf->usercontainer);
02530
02531 user->chan = chan;
02532 user->userflags = *confflags;
02533 user->adminflags = ast_test_flag64(confflags, CONFFLAG_STARTMUTED) ? ADMINFLAG_SELFMUTED : 0;
02534 user->adminflags |= (conf->gmuted) ? ADMINFLAG_MUTED : 0;
02535 user->talking = -1;
02536
02537 ast_mutex_unlock(&conf->playlock);
02538
02539 if (!ast_test_flag64(confflags, CONFFLAG_QUIET) && (ast_test_flag64(confflags, CONFFLAG_INTROUSER) ||
02540 ast_test_flag64(confflags, CONFFLAG_INTROUSERNOREVIEW))) {
02541 char destdir[PATH_MAX];
02542
02543 snprintf(destdir, sizeof(destdir), "%s/meetme", ast_config_AST_SPOOL_DIR);
02544
02545 if (ast_mkdir(destdir, 0777) != 0) {
02546 ast_log(LOG_WARNING, "mkdir '%s' failed: %s\n", destdir, strerror(errno));
02547 goto outrun;
02548 }
02549
02550 snprintf(user->namerecloc, sizeof(user->namerecloc),
02551 "%s/meetme-username-%s-%d", destdir,
02552 conf->confno, user->user_no);
02553 if (ast_test_flag64(confflags, CONFFLAG_INTROUSERNOREVIEW))
02554 res = ast_play_and_record(chan, "vm-rec-name", user->namerecloc, 10, "sln", &duration, NULL, ast_dsp_get_threshold_from_settings(THRESHOLD_SILENCE), 0, NULL);
02555 else
02556 res = ast_record_review(chan, "vm-rec-name", user->namerecloc, 10, "sln", &duration, NULL);
02557 if (res == -1)
02558 goto outrun;
02559 }
02560
02561 ast_mutex_lock(&conf->playlock);
02562
02563 if (ast_test_flag64(confflags, CONFFLAG_MARKEDUSER))
02564 conf->markedusers++;
02565 conf->users++;
02566 if (rt_log_members) {
02567
02568 snprintf(members, sizeof(members), "%d", conf->users);
02569 ast_realtime_require_field("meetme",
02570 "confno", strlen(conf->confno) > 7 ? RQ_UINTEGER4 : strlen(conf->confno) > 4 ? RQ_UINTEGER3 : RQ_UINTEGER2, strlen(conf->confno),
02571 "members", RQ_UINTEGER1, strlen(members),
02572 NULL);
02573 ast_update_realtime("meetme", "confno", conf->confno, "members", members, NULL);
02574 }
02575 setusercount = 1;
02576
02577
02578 if (conf->users == 1)
02579 ast_devstate_changed(AST_DEVICE_INUSE, (conf->isdynamic ? AST_DEVSTATE_NOT_CACHABLE : AST_DEVSTATE_CACHABLE), "meetme:%s", conf->confno);
02580
02581 ast_mutex_unlock(&conf->playlock);
02582
02583
02584 pbx_builtin_setvar_helper(chan, "MEETMEUNIQUEID", conf->uniqueid);
02585
02586 if (ast_test_flag64(confflags, CONFFLAG_EXIT_CONTEXT)) {
02587 ast_channel_lock(chan);
02588 if ((tmpvar = pbx_builtin_getvar_helper(chan, "MEETME_EXIT_CONTEXT"))) {
02589 ast_copy_string(exitcontext, tmpvar, sizeof(exitcontext));
02590 } else if (!ast_strlen_zero(chan->macrocontext)) {
02591 ast_copy_string(exitcontext, chan->macrocontext, sizeof(exitcontext));
02592 } else {
02593 ast_copy_string(exitcontext, chan->context, sizeof(exitcontext));
02594 }
02595 ast_channel_unlock(chan);
02596 }
02597
02598
02599 if (ast_test_flag64(confflags, CONFFLAG_INTROMSG) &&
02600 !ast_strlen_zero(optargs[OPT_ARG_INTROMSG])) {
02601 if (!ast_streamfile(chan, optargs[OPT_ARG_INTROMSG], chan->language)) {
02602 ast_waitstream(chan, "");
02603 }
02604 }
02605
02606 if (!ast_test_flag64(confflags, (CONFFLAG_QUIET | CONFFLAG_NOONLYPERSON))) {
02607 if (conf->users == 1 && !ast_test_flag64(confflags, CONFFLAG_WAITMARKED))
02608 if (!ast_streamfile(chan, "conf-onlyperson", chan->language))
02609 ast_waitstream(chan, "");
02610 if (ast_test_flag64(confflags, CONFFLAG_WAITMARKED) && conf->markedusers == 0)
02611 if (!ast_streamfile(chan, "conf-waitforleader", chan->language))
02612 ast_waitstream(chan, "");
02613 }
02614
02615 if (!ast_test_flag64(confflags, CONFFLAG_QUIET) && ast_test_flag64(confflags, CONFFLAG_ANNOUNCEUSERCOUNT) &&
02616 conf->users > 1) {
02617 int keepplaying = 1;
02618
02619 if (conf->users == 2) {
02620 if (!ast_streamfile(chan, "conf-onlyone", chan->language)) {
02621 res = ast_waitstream(chan, AST_DIGIT_ANY);
02622 ast_stopstream(chan);
02623 if (res > 0)
02624 keepplaying = 0;
02625 else if (res == -1)
02626 goto outrun;
02627 }
02628 } else {
02629 if (!ast_streamfile(chan, "conf-thereare", chan->language)) {
02630 res = ast_waitstream(chan, AST_DIGIT_ANY);
02631 ast_stopstream(chan);
02632 if (res > 0)
02633 keepplaying = 0;
02634 else if (res == -1)
02635 goto outrun;
02636 }
02637 if (keepplaying) {
02638 res = ast_say_number(chan, conf->users - 1, AST_DIGIT_ANY, chan->language, (char *) NULL);
02639 if (res > 0)
02640 keepplaying = 0;
02641 else if (res == -1)
02642 goto outrun;
02643 }
02644 if (keepplaying && !ast_streamfile(chan, "conf-otherinparty", chan->language)) {
02645 res = ast_waitstream(chan, AST_DIGIT_ANY);
02646 ast_stopstream(chan);
02647 if (res > 0)
02648 keepplaying = 0;
02649 else if (res == -1)
02650 goto outrun;
02651 }
02652 }
02653 }
02654
02655 if (!ast_test_flag64(confflags, CONFFLAG_NO_AUDIO_UNTIL_UP)) {
02656
02657 ast_indicate(chan, -1);
02658 }
02659
02660 if (ast_set_write_format(chan, AST_FORMAT_SLINEAR) < 0) {
02661 ast_log(LOG_WARNING, "Unable to set '%s' to write linear mode\n", chan->name);
02662 goto outrun;
02663 }
02664
02665 if (ast_set_read_format(chan, AST_FORMAT_SLINEAR) < 0) {
02666 ast_log(LOG_WARNING, "Unable to set '%s' to read linear mode\n", chan->name);
02667 goto outrun;
02668 }
02669
02670
02671 if ((mod_speex = ast_module_helper("", "codec_speex", 0, 0, 0, 0))) {
02672 ast_free(mod_speex);
02673 ast_func_write(chan, "DENOISE(rx)", "on");
02674 }
02675
02676 retrydahdi = (strcasecmp(chan->tech->type, "DAHDI") || (chan->audiohooks || chan->monitor) ? 1 : 0);
02677 user->dahdichannel = !retrydahdi;
02678
02679 dahdiretry:
02680 origfd = chan->fds[0];
02681 if (retrydahdi) {
02682
02683 fd = open("/dev/dahdi/pseudo", O_RDWR | O_NONBLOCK);
02684 if (fd < 0) {
02685 ast_log(LOG_WARNING, "Unable to open DAHDI pseudo channel: %s\n", strerror(errno));
02686 goto outrun;
02687 }
02688 using_pseudo = 1;
02689
02690 memset(&bi, 0, sizeof(bi));
02691 bi.bufsize = CONF_SIZE / 2;
02692 bi.txbufpolicy = DAHDI_POLICY_IMMEDIATE;
02693 bi.rxbufpolicy = DAHDI_POLICY_IMMEDIATE;
02694 bi.numbufs = audio_buffers;
02695 if (ioctl(fd, DAHDI_SET_BUFINFO, &bi)) {
02696 ast_log(LOG_WARNING, "Unable to set buffering information: %s\n", strerror(errno));
02697 close(fd);
02698 goto outrun;
02699 }
02700 x = 1;
02701 if (ioctl(fd, DAHDI_SETLINEAR, &x)) {
02702 ast_log(LOG_WARNING, "Unable to set linear mode: %s\n", strerror(errno));
02703 close(fd);
02704 goto outrun;
02705 }
02706 nfds = 1;
02707 } else {
02708
02709 fd = chan->fds[0];
02710 nfds = 0;
02711 }
02712 memset(&dahdic, 0, sizeof(dahdic));
02713 memset(&dahdic_empty, 0, sizeof(dahdic_empty));
02714
02715 dahdic.chan = 0;
02716 if (ioctl(fd, DAHDI_GETCONF, &dahdic)) {
02717 ast_log(LOG_WARNING, "Error getting conference\n");
02718 close(fd);
02719 goto outrun;
02720 }
02721 if (dahdic.confmode) {
02722
02723 if (!retrydahdi) {
02724 ast_debug(1, "DAHDI channel is in a conference already, retrying with pseudo\n");
02725 retrydahdi = 1;
02726 goto dahdiretry;
02727 }
02728 }
02729 memset(&dahdic, 0, sizeof(dahdic));
02730
02731 dahdic.chan = 0;
02732 dahdic.confno = conf->dahdiconf;
02733
02734 if (!ast_test_flag64(confflags, CONFFLAG_QUIET) && (ast_test_flag64(confflags, CONFFLAG_INTROUSER) ||
02735 ast_test_flag64(confflags, CONFFLAG_INTROUSERNOREVIEW)) && conf->users > 1) {
02736 struct announce_listitem *item;
02737 if (!(item = ao2_alloc(sizeof(*item), NULL)))
02738 goto outrun;
02739 ast_copy_string(item->namerecloc, user->namerecloc, sizeof(item->namerecloc));
02740 ast_copy_string(item->language, chan->language, sizeof(item->language));
02741 item->confchan = conf->chan;
02742 item->confusers = conf->users;
02743 item->announcetype = CONF_HASJOIN;
02744 ast_mutex_lock(&conf->announcelistlock);
02745 ao2_ref(item, +1);
02746 AST_LIST_INSERT_TAIL(&conf->announcelist, item, entry);
02747 ast_cond_signal(&conf->announcelist_addition);
02748 ast_mutex_unlock(&conf->announcelistlock);
02749
02750 while (!ast_check_hangup(conf->chan) && ao2_ref(item, 0) == 2 && !ast_safe_sleep(chan, 1000)) {
02751 ;
02752 }
02753 ao2_ref(item, -1);
02754 }
02755
02756 if (ast_test_flag64(confflags, CONFFLAG_WAITMARKED) && !conf->markedusers)
02757 dahdic.confmode = DAHDI_CONF_CONF;
02758 else if (ast_test_flag64(confflags, CONFFLAG_MONITOR))
02759 dahdic.confmode = DAHDI_CONF_CONFMON | DAHDI_CONF_LISTENER;
02760 else if (ast_test_flag64(confflags, CONFFLAG_TALKER))
02761 dahdic.confmode = DAHDI_CONF_CONF | DAHDI_CONF_TALKER;
02762 else
02763 dahdic.confmode = DAHDI_CONF_CONF | DAHDI_CONF_TALKER | DAHDI_CONF_LISTENER;
02764
02765 if (ioctl(fd, DAHDI_SETCONF, &dahdic)) {
02766 ast_log(LOG_WARNING, "Error setting conference\n");
02767 close(fd);
02768 goto outrun;
02769 }
02770 ast_debug(1, "Placed channel %s in DAHDI conf %d\n", chan->name, conf->dahdiconf);
02771
02772 if (!sent_event) {
02773 ast_manager_event(chan, EVENT_FLAG_CALL, "MeetmeJoin",
02774 "Channel: %s\r\n"
02775 "Uniqueid: %s\r\n"
02776 "Meetme: %s\r\n"
02777 "Usernum: %d\r\n"
02778 "CallerIDnum: %s\r\n"
02779 "CallerIDname: %s\r\n"
02780 "ConnectedLineNum: %s\r\n"
02781 "ConnectedLineName: %s\r\n",
02782 chan->name, chan->uniqueid, conf->confno,
02783 user->user_no,
02784 S_COR(user->chan->caller.id.number.valid, user->chan->caller.id.number.str, "<unknown>"),
02785 S_COR(user->chan->caller.id.name.valid, user->chan->caller.id.name.str, "<unknown>"),
02786 S_COR(user->chan->connected.id.number.valid, user->chan->connected.id.number.str, "<unknown>"),
02787 S_COR(user->chan->connected.id.name.valid, user->chan->connected.id.name.str, "<unknown>")
02788 );
02789 sent_event = 1;
02790 }
02791
02792 if (!firstpass && !ast_test_flag64(confflags, CONFFLAG_MONITOR) &&
02793 !ast_test_flag64(confflags, CONFFLAG_ADMIN)) {
02794 firstpass = 1;
02795 if (!ast_test_flag64(confflags, CONFFLAG_QUIET))
02796 if (!ast_test_flag64(confflags, CONFFLAG_WAITMARKED) || (ast_test_flag64(confflags, CONFFLAG_MARKEDUSER) &&
02797 (conf->markedusers >= 1))) {
02798 conf_play(chan, conf, ENTER);
02799 }
02800 }
02801
02802 conf_flush(fd, chan);
02803
02804 if (dsp)
02805 ast_dsp_free(dsp);
02806
02807 if (!(dsp = ast_dsp_new())) {
02808 ast_log(LOG_WARNING, "Unable to allocate DSP!\n");
02809 res = -1;
02810 }
02811
02812 if (ast_test_flag64(confflags, CONFFLAG_AGI)) {
02813
02814
02815
02816 ast_channel_lock(chan);
02817 if ((tmpvar = pbx_builtin_getvar_helper(chan, "MEETME_AGI_BACKGROUND"))) {
02818 agifile = ast_strdupa(tmpvar);
02819 } else {
02820 agifile = ast_strdupa(agifiledefault);
02821 }
02822 ast_channel_unlock(chan);
02823
02824 if (user->dahdichannel) {
02825
02826 x = 1;
02827 ast_channel_setoption(chan, AST_OPTION_TONE_VERIFY, &x, sizeof(char), 0);
02828 }
02829
02830 agi_app = pbx_findapp("agi");
02831 if (agi_app) {
02832 ret = pbx_exec(chan, agi_app, agifile);
02833 } else {
02834 ast_log(LOG_WARNING, "Could not find application (agi)\n");
02835 ret = -2;
02836 }
02837 if (user->dahdichannel) {
02838
02839 x = 0;
02840 ast_channel_setoption(chan, AST_OPTION_TONE_VERIFY, &x, sizeof(char), 0);
02841 }
02842 } else {
02843 int lastusers = conf->users;
02844 if (user->dahdichannel && ast_test_flag64(confflags, CONFFLAG_STARMENU)) {
02845
02846 x = 1;
02847 ast_channel_setoption(chan, AST_OPTION_TONE_VERIFY, &x, sizeof(char), 0);
02848 }
02849 for (;;) {
02850 int menu_was_active = 0;
02851
02852 outfd = -1;
02853 ms = -1;
02854 now = ast_tvnow();
02855
02856 if (rt_schedule && conf->endtime) {
02857 char currenttime[32];
02858 long localendtime = 0;
02859 int extended = 0;
02860 struct ast_tm tm;
02861 struct ast_variable *var, *origvar;
02862 struct timeval tmp;
02863
02864 if (now.tv_sec % 60 == 0) {
02865 if (!checked) {
02866 ast_localtime(&now, &tm, NULL);
02867 ast_strftime(currenttime, sizeof(currenttime), DATE_FORMAT, &tm);
02868 var = origvar = ast_load_realtime("meetme", "confno",
02869 conf->confno, "starttime <=", currenttime,
02870 "endtime >=", currenttime, NULL);
02871
02872 for ( ; var; var = var->next) {
02873 if (!strcasecmp(var->name, "endtime")) {
02874 struct ast_tm endtime_tm;
02875 ast_strptime(var->value, "%Y-%m-%d %H:%M:%S", &endtime_tm);
02876 tmp = ast_mktime(&endtime_tm, NULL);
02877 localendtime = tmp.tv_sec;
02878 }
02879 }
02880 ast_variables_destroy(origvar);
02881
02882
02883
02884 if (localendtime > conf->endtime){
02885 conf->endtime = localendtime;
02886 extended = 1;
02887 }
02888
02889 if (conf->endtime && (now.tv_sec >= conf->endtime)) {
02890 ast_verbose("Quitting time...\n");
02891 goto outrun;
02892 }
02893
02894 if (!announcement_played && conf->endalert) {
02895 if (now.tv_sec + conf->endalert >= conf->endtime) {
02896 if (!ast_streamfile(chan, "conf-will-end-in", chan->language))
02897 ast_waitstream(chan, "");
02898 ast_say_digits(chan, (conf->endtime - now.tv_sec) / 60, "", chan->language);
02899 if (!ast_streamfile(chan, "minutes", chan->language))
02900 ast_waitstream(chan, "");
02901 if (musiconhold) {
02902 conf_start_moh(chan, optargs[OPT_ARG_MOH_CLASS]);
02903 }
02904 announcement_played = 1;
02905 }
02906 }
02907
02908 if (extended) {
02909 announcement_played = 0;
02910 }
02911
02912 checked = 1;
02913 }
02914 } else {
02915 checked = 0;
02916 }
02917 }
02918
02919 if (user->kicktime && (user->kicktime <= now.tv_sec)) {
02920 if (ast_test_flag64(confflags, CONFFLAG_KICK_CONTINUE)) {
02921 ret = 0;
02922 } else {
02923 ret = -1;
02924 }
02925 break;
02926 }
02927
02928 to = -1;
02929 if (user->timelimit) {
02930 int minutes = 0, seconds = 0, remain = 0;
02931
02932 to = ast_tvdiff_ms(nexteventts, now);
02933 if (to < 0) {
02934 to = 0;
02935 }
02936 time_left_ms = user->timelimit - ast_tvdiff_ms(now, user->start_time);
02937 if (time_left_ms < to) {
02938 to = time_left_ms;
02939 }
02940
02941 if (time_left_ms <= 0) {
02942 if (user->end_sound) {
02943 res = ast_streamfile(chan, user->end_sound, chan->language);
02944 res = ast_waitstream(chan, "");
02945 }
02946 if (ast_test_flag64(confflags, CONFFLAG_KICK_CONTINUE)) {
02947 ret = 0;
02948 } else {
02949 ret = -1;
02950 }
02951 break;
02952 }
02953
02954 if (!to) {
02955 if (time_left_ms >= 5000) {
02956
02957 remain = (time_left_ms + 500) / 1000;
02958 if (remain / 60 >= 1) {
02959 minutes = remain / 60;
02960 seconds = remain % 60;
02961 } else {
02962 seconds = remain;
02963 }
02964
02965
02966 if (user->warning_sound && user->play_warning) {
02967 if (!strcmp(user->warning_sound, "timeleft")) {
02968
02969 res = ast_streamfile(chan, "vm-youhave", chan->language);
02970 res = ast_waitstream(chan, "");
02971 if (minutes) {
02972 res = ast_say_number(chan, minutes, AST_DIGIT_ANY, chan->language, (char *) NULL);
02973 res = ast_streamfile(chan, "queue-minutes", chan->language);
02974 res = ast_waitstream(chan, "");
02975 }
02976 if (seconds) {
02977 res = ast_say_number(chan, seconds, AST_DIGIT_ANY, chan->language, (char *) NULL);
02978 res = ast_streamfile(chan, "queue-seconds", chan->language);
02979 res = ast_waitstream(chan, "");
02980 }
02981 } else {
02982 res = ast_streamfile(chan, user->warning_sound, chan->language);
02983 res = ast_waitstream(chan, "");
02984 }
02985 if (musiconhold) {
02986 conf_start_moh(chan, optargs[OPT_ARG_MOH_CLASS]);
02987 }
02988 }
02989 }
02990 if (user->warning_freq) {
02991 nexteventts = ast_tvadd(nexteventts, ast_samp2tv(user->warning_freq, 1000));
02992 } else {
02993 nexteventts = ast_tvadd(user->start_time, ast_samp2tv(user->timelimit, 1000));
02994 }
02995 }
02996 }
02997
02998 now = ast_tvnow();
02999 if (timeout && now.tv_sec >= timeout) {
03000 if (ast_test_flag64(confflags, CONFFLAG_KICK_CONTINUE)) {
03001 ret = 0;
03002 } else {
03003 ret = -1;
03004 }
03005 break;
03006 }
03007
03008
03009
03010
03011 if (!menu_active && menu_was_active && user->listen.desired && !user->listen.actual) {
03012 set_talk_volume(user, user->listen.desired);
03013 }
03014
03015 menu_was_active = menu_active;
03016
03017 currentmarked = conf->markedusers;
03018 if (!ast_test_flag64(confflags, CONFFLAG_QUIET) &&
03019 ast_test_flag64(confflags, CONFFLAG_MARKEDUSER) &&
03020 ast_test_flag64(confflags, CONFFLAG_WAITMARKED) &&
03021 lastmarked == 0) {
03022 if (currentmarked == 1 && conf->users > 1) {
03023 ast_say_number(chan, conf->users - 1, AST_DIGIT_ANY, chan->language, (char *) NULL);
03024 if (conf->users - 1 == 1) {
03025 if (!ast_streamfile(chan, "conf-userwilljoin", chan->language)) {
03026 ast_waitstream(chan, "");
03027 }
03028 } else {
03029 if (!ast_streamfile(chan, "conf-userswilljoin", chan->language)) {
03030 ast_waitstream(chan, "");
03031 }
03032 }
03033 }
03034 if (conf->users == 1 && !ast_test_flag64(confflags, CONFFLAG_MARKEDUSER)) {
03035 if (!ast_streamfile(chan, "conf-onlyperson", chan->language)) {
03036 ast_waitstream(chan, "");
03037 }
03038 }
03039 }
03040
03041
03042 user->userflags = *confflags;
03043
03044 if (ast_test_flag64(confflags, CONFFLAG_WAITMARKED)) {
03045 if (currentmarked == 0) {
03046 if (lastmarked != 0) {
03047 if (!ast_test_flag64(confflags, CONFFLAG_QUIET)) {
03048 if (!ast_streamfile(chan, "conf-leaderhasleft", chan->language)) {
03049 ast_waitstream(chan, "");
03050 }
03051 }
03052 if (ast_test_flag64(confflags, CONFFLAG_MARKEDEXIT)) {
03053 if (ast_test_flag64(confflags, CONFFLAG_KICK_CONTINUE)) {
03054 ret = 0;
03055 }
03056 break;
03057 } else {
03058 dahdic.confmode = DAHDI_CONF_CONF;
03059 if (ioctl(fd, DAHDI_SETCONF, &dahdic)) {
03060 ast_log(LOG_WARNING, "Error setting conference\n");
03061 close(fd);
03062 goto outrun;
03063 }
03064 }
03065 }
03066 if (!musiconhold && (ast_test_flag64(confflags, CONFFLAG_MOH))) {
03067 conf_start_moh(chan, optargs[OPT_ARG_MOH_CLASS]);
03068 musiconhold = 1;
03069 }
03070 } else if (currentmarked >= 1 && lastmarked == 0) {
03071
03072 timeout = 0;
03073 if (ast_test_flag64(confflags, CONFFLAG_MONITOR)) {
03074 dahdic.confmode = DAHDI_CONF_CONFMON | DAHDI_CONF_LISTENER;
03075 } else if (ast_test_flag64(confflags, CONFFLAG_TALKER)) {
03076 dahdic.confmode = DAHDI_CONF_CONF | DAHDI_CONF_TALKER;
03077 } else {
03078 dahdic.confmode = DAHDI_CONF_CONF | DAHDI_CONF_TALKER | DAHDI_CONF_LISTENER;
03079 }
03080 if (ioctl(fd, DAHDI_SETCONF, &dahdic)) {
03081 ast_log(LOG_WARNING, "Error setting conference\n");
03082 close(fd);
03083 goto outrun;
03084 }
03085 if (musiconhold && (ast_test_flag64(confflags, CONFFLAG_MOH))) {
03086 ast_moh_stop(chan);
03087 musiconhold = 0;
03088 }
03089 if (!ast_test_flag64(confflags, CONFFLAG_QUIET) &&
03090 !ast_test_flag64(confflags, CONFFLAG_MARKEDUSER)) {
03091 if (!ast_streamfile(chan, "conf-placeintoconf", chan->language)) {
03092 ast_waitstream(chan, "");
03093 }
03094 conf_play(chan, conf, ENTER);
03095 }
03096 }
03097 }
03098
03099
03100 if (ast_test_flag64(confflags, CONFFLAG_MOH) && !ast_test_flag64(confflags, CONFFLAG_WAITMARKED)) {
03101 if (conf->users == 1) {
03102 if (!musiconhold) {
03103 conf_start_moh(chan, optargs[OPT_ARG_MOH_CLASS]);
03104 musiconhold = 1;
03105 }
03106 } else {
03107 if (musiconhold) {
03108 ast_moh_stop(chan);
03109 musiconhold = 0;
03110 }
03111 }
03112 }
03113
03114
03115 if (currentmarked == 0 && lastmarked != 0 && ast_test_flag64(confflags, CONFFLAG_MARKEDEXIT)) {
03116 if (ast_test_flag64(confflags, CONFFLAG_KICK_CONTINUE)) {
03117 ret = 0;
03118 } else {
03119 ret = -1;
03120 }
03121 break;
03122 }
03123
03124
03125 if (conf->users != lastusers) {
03126 if (conf->users < lastusers) {
03127 ast_test_suite_event_notify("NOEXIT", "Message: CONFFLAG_MARKEDEXIT\r\nLastUsers: %d\r\nUsers: %d", lastusers, conf->users);
03128 }
03129 lastusers = conf->users;
03130 }
03131
03132
03133
03134
03135 if ((user->adminflags & (ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED)) && (dahdic.confmode & DAHDI_CONF_TALKER)) {
03136 dahdic.confmode ^= DAHDI_CONF_TALKER;
03137 if (ioctl(fd, DAHDI_SETCONF, &dahdic)) {
03138 ast_log(LOG_WARNING, "Error setting conference - Un/Mute \n");
03139 ret = -1;
03140 break;
03141 }
03142
03143
03144 if (ast_test_flag64(confflags, (CONFFLAG_MONITORTALKER | CONFFLAG_OPTIMIZETALKER))) {
03145 set_user_talking(chan, conf, user, -1, ast_test_flag64(confflags, CONFFLAG_MONITORTALKER));
03146 }
03147
03148 ast_manager_event(chan, EVENT_FLAG_CALL, "MeetmeMute",
03149 "Channel: %s\r\n"
03150 "Uniqueid: %s\r\n"
03151 "Meetme: %s\r\n"
03152 "Usernum: %d\r\n"
03153 "Status: on\r\n",
03154 chan->name, chan->uniqueid, conf->confno, user->user_no);
03155 }
03156
03157
03158 if (!(user->adminflags & (ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED)) && !ast_test_flag64(confflags, CONFFLAG_MONITOR) && !(dahdic.confmode & DAHDI_CONF_TALKER)) {
03159 dahdic.confmode |= DAHDI_CONF_TALKER;
03160 if (ioctl(fd, DAHDI_SETCONF, &dahdic)) {
03161 ast_log(LOG_WARNING, "Error setting conference - Un/Mute \n");
03162 ret = -1;
03163 break;
03164 }
03165
03166 ast_manager_event(chan, EVENT_FLAG_CALL, "MeetmeMute",
03167 "Channel: %s\r\n"
03168 "Uniqueid: %s\r\n"
03169 "Meetme: %s\r\n"
03170 "Usernum: %d\r\n"
03171 "Status: off\r\n",
03172 chan->name, chan->uniqueid, conf->confno, user->user_no);
03173 }
03174
03175 if ((user->adminflags & (ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED)) &&
03176 (user->adminflags & ADMINFLAG_T_REQUEST) && !(talkreq_manager)) {
03177 talkreq_manager = 1;
03178
03179 ast_manager_event(chan, EVENT_FLAG_CALL, "MeetmeTalkRequest",
03180 "Channel: %s\r\n"
03181 "Uniqueid: %s\r\n"
03182 "Meetme: %s\r\n"
03183 "Usernum: %d\r\n"
03184 "Status: on\r\n",
03185 chan->name, chan->uniqueid, conf->confno, user->user_no);
03186 }
03187
03188
03189 if (!(user->adminflags & (ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED)) &&
03190 !(user->adminflags & ADMINFLAG_T_REQUEST) && (talkreq_manager)) {
03191 talkreq_manager = 0;
03192 ast_manager_event(chan, EVENT_FLAG_CALL, "MeetmeTalkRequest",
03193 "Channel: %s\r\n"
03194 "Uniqueid: %s\r\n"
03195 "Meetme: %s\r\n"
03196 "Usernum: %d\r\n"
03197 "Status: off\r\n",
03198 chan->name, chan->uniqueid, conf->confno, user->user_no);
03199 }
03200
03201
03202 if (user->adminflags & ADMINFLAG_KICKME) {
03203
03204 if (!ast_test_flag64(confflags, CONFFLAG_QUIET) &&
03205 !ast_streamfile(chan, "conf-kicked", chan->language)) {
03206 ast_waitstream(chan, "");
03207 }
03208 ret = 0;
03209 break;
03210 }
03211
03212
03213 if (ast_check_hangup(chan)) {
03214 break;
03215 }
03216
03217 c = ast_waitfor_nandfds(&chan, 1, &fd, nfds, NULL, &outfd, &ms);
03218
03219 if (c) {
03220 char dtmfstr[2] = "";
03221
03222 if (c->fds[0] != origfd || (user->dahdichannel && (c->audiohooks || c->monitor))) {
03223 if (using_pseudo) {
03224
03225 close(fd);
03226 using_pseudo = 0;
03227 }
03228 ast_debug(1, "Ooh, something swapped out under us, starting over\n");
03229 retrydahdi = (strcasecmp(c->tech->type, "DAHDI") || (c->audiohooks || c->monitor) ? 1 : 0);
03230 user->dahdichannel = !retrydahdi;
03231 goto dahdiretry;
03232 }
03233 if (ast_test_flag64(confflags, CONFFLAG_MONITOR) || (user->adminflags & (ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED))) {
03234 f = ast_read_noaudio(c);
03235 } else {
03236 f = ast_read(c);
03237 }
03238 if (!f) {
03239 break;
03240 }
03241 if (f->frametype == AST_FRAME_DTMF) {
03242 dtmfstr[0] = f->subclass.integer;
03243 dtmfstr[1] = '\0';
03244 }
03245
03246 if ((f->frametype == AST_FRAME_VOICE) && (f->subclass.codec == AST_FORMAT_SLINEAR)) {
03247 if (user->talk.actual) {
03248 ast_frame_adjust_volume(f, user->talk.actual);
03249 }
03250
03251 if (ast_test_flag64(confflags, (CONFFLAG_OPTIMIZETALKER | CONFFLAG_MONITORTALKER))) {
03252 if (user->talking == -1) {
03253 user->talking = 0;
03254 }
03255
03256 res = ast_dsp_silence(dsp, f, &totalsilence);
03257 if (!user->talking && totalsilence < MEETME_DELAYDETECTTALK) {
03258 set_user_talking(chan, conf, user, 1, ast_test_flag64(confflags, CONFFLAG_MONITORTALKER));
03259 }
03260
03261 if (user->talking && totalsilence > MEETME_DELAYDETECTENDTALK) {
03262 set_user_talking(chan, conf, user, 0, ast_test_flag64(confflags, CONFFLAG_MONITORTALKER));
03263 }
03264 }
03265 if (using_pseudo) {
03266
03267
03268
03269
03270
03271
03272
03273
03274
03275
03276
03277
03278 if (user->talking || !ast_test_flag64(confflags, CONFFLAG_OPTIMIZETALKER)) {
03279 careful_write(fd, f->data.ptr, f->datalen, 0);
03280 }
03281 }
03282 } else if (((f->frametype == AST_FRAME_DTMF) && (f->subclass.integer == '*') && ast_test_flag64(confflags, CONFFLAG_STARMENU)) || ((f->frametype == AST_FRAME_DTMF) && menu_active)) {
03283 if (ast_test_flag64(confflags, CONFFLAG_PASS_DTMF)) {
03284 conf_queue_dtmf(conf, user, f);
03285 }
03286 if (ioctl(fd, DAHDI_SETCONF, &dahdic_empty)) {
03287 ast_log(LOG_WARNING, "Error setting conference\n");
03288 close(fd);
03289 ast_frfree(f);
03290 goto outrun;
03291 }
03292
03293
03294
03295
03296 if (!menu_active && user->talk.desired && !user->talk.actual) {
03297 set_talk_volume(user, 0);
03298 }
03299
03300 if (musiconhold) {
03301 ast_moh_stop(chan);
03302 }
03303 if (menu8_active) {
03304
03305 dtmf = f->subclass.integer;
03306 if (dtmf > 0) {
03307 int keepplaying;
03308 int playednamerec;
03309 struct ao2_iterator user_iter;
03310 struct ast_conf_user *usr = NULL;
03311 switch(dtmf) {
03312 case '1':
03313 keepplaying = 1;
03314 playednamerec = 0;
03315 if (conf->users == 1) {
03316 if (keepplaying && !ast_streamfile(chan, "conf-onlyperson", chan->language)) {
03317 res = ast_waitstream(chan, AST_DIGIT_ANY);
03318 ast_stopstream(chan);
03319 if (res > 0)
03320 keepplaying = 0;
03321 }
03322 } else if (conf->users == 2) {
03323 if (keepplaying && !ast_streamfile(chan, "conf-onlyone", chan->language)) {
03324 res = ast_waitstream(chan, AST_DIGIT_ANY);
03325 ast_stopstream(chan);
03326 if (res > 0)
03327 keepplaying = 0;
03328 }
03329 } else {
03330 if (keepplaying && !ast_streamfile(chan, "conf-thereare", chan->language)) {
03331 res = ast_waitstream(chan, AST_DIGIT_ANY);
03332 ast_stopstream(chan);
03333 if (res > 0)
03334 keepplaying = 0;
03335 }
03336 if (keepplaying) {
03337 res = ast_say_number(chan, conf->users - 1, AST_DIGIT_ANY, chan->language, (char *) NULL);
03338 if (res > 0)
03339 keepplaying = 0;
03340 }
03341 if (keepplaying && !ast_streamfile(chan, "conf-otherinparty", chan->language)) {
03342 res = ast_waitstream(chan, AST_DIGIT_ANY);
03343 ast_stopstream(chan);
03344 if (res > 0)
03345 keepplaying = 0;
03346 }
03347 }
03348 user_iter = ao2_iterator_init(conf->usercontainer, 0);
03349 while((usr = ao2_iterator_next(&user_iter))) {
03350 if (ast_fileexists(usr->namerecloc, NULL, NULL)) {
03351 if (keepplaying && !ast_streamfile(chan, usr->namerecloc, chan->language)) {
03352 res = ast_waitstream(chan, AST_DIGIT_ANY);
03353 ast_stopstream(chan);
03354 if (res > 0)
03355 keepplaying = 0;
03356 }
03357 playednamerec = 1;
03358 }
03359 ao2_ref(usr, -1);
03360 }
03361 ao2_iterator_destroy(&user_iter);
03362 if (keepplaying && playednamerec && !ast_streamfile(chan, "conf-roll-callcomplete", chan->language)) {
03363 res = ast_waitstream(chan, AST_DIGIT_ANY);
03364 ast_stopstream(chan);
03365 if (res > 0)
03366 keepplaying = 0;
03367 }
03368 break;
03369 case '2':
03370 if (conf->users == 1) {
03371 if(!ast_streamfile(chan, "conf-errormenu", chan->language))
03372 ast_waitstream(chan, "");
03373 } else {
03374 ao2_callback(conf->usercontainer, OBJ_NODATA, user_set_kickme_cb, &conf);
03375 }
03376 ast_stopstream(chan);
03377 break;
03378 case '3':
03379 if(conf->gmuted) {
03380 conf->gmuted = 0;
03381 ao2_callback(conf->usercontainer, OBJ_NODATA, user_set_unmuted_cb, &conf);
03382 if (!ast_streamfile(chan, "conf-now-unmuted", chan->language))
03383 ast_waitstream(chan, "");
03384 } else {
03385 conf->gmuted = 1;
03386 ao2_callback(conf->usercontainer, OBJ_NODATA, user_set_muted_cb, &conf);
03387 if (!ast_streamfile(chan, "conf-now-muted", chan->language))
03388 ast_waitstream(chan, "");
03389 }
03390 ast_stopstream(chan);
03391 break;
03392 case '4':
03393 if (conf->recording != MEETME_RECORD_ACTIVE) {
03394 ast_set_flag64(confflags, CONFFLAG_RECORDCONF);
03395
03396 if (!conf->recordingfilename) {
03397 const char *var;
03398 ast_channel_lock(chan);
03399 if ((var = pbx_builtin_getvar_helper(chan, "MEETME_RECORDINGFILE"))) {
03400 conf->recordingfilename = ast_strdup(var);
03401 }
03402 if ((var = pbx_builtin_getvar_helper(chan, "MEETME_RECORDINGFORMAT"))) {
03403 conf->recordingformat = ast_strdup(var);
03404 }
03405 ast_channel_unlock(chan);
03406 if (!conf->recordingfilename) {
03407 snprintf(recordingtmp, sizeof(recordingtmp), "meetme-conf-rec-%s-%s", conf->confno, chan->uniqueid);
03408 conf->recordingfilename = ast_strdup(recordingtmp);
03409 }
03410 if (!conf->recordingformat) {
03411 conf->recordingformat = ast_strdup("wav");
03412 }
03413 ast_verb(4, "Starting recording of MeetMe Conference %s into file %s.%s.\n",
03414 conf->confno, conf->recordingfilename, conf->recordingformat);
03415 }
03416
03417 ast_mutex_lock(&conf->recordthreadlock);
03418 if ((conf->recordthread == AST_PTHREADT_NULL) && ast_test_flag64(confflags, CONFFLAG_RECORDCONF) && ((conf->lchan = ast_request("DAHDI", AST_FORMAT_SLINEAR, chan, "pseudo", NULL)))) {
03419 ast_set_read_format(conf->lchan, AST_FORMAT_SLINEAR);
03420 ast_set_write_format(conf->lchan, AST_FORMAT_SLINEAR);
03421 dahdic.chan = 0;
03422 dahdic.confno = conf->dahdiconf;
03423 dahdic.confmode = DAHDI_CONF_CONFANN | DAHDI_CONF_CONFANNMON;
03424 if (ioctl(conf->lchan->fds[0], DAHDI_SETCONF, &dahdic)) {
03425 ast_log(LOG_WARNING, "Error starting listen channel\n");
03426 ast_hangup(conf->lchan);
03427 conf->lchan = NULL;
03428 } else {
03429 ast_pthread_create_detached_background(&conf->recordthread, NULL, recordthread, conf);
03430 }
03431 }
03432 ast_mutex_unlock(&conf->recordthreadlock);
03433
03434 if (!ast_streamfile(chan, "conf-now-recording", chan->language))
03435 ast_waitstream(chan, "");
03436
03437 }
03438
03439 ast_stopstream(chan);
03440 break;
03441 default:
03442 if (!ast_streamfile(chan, "conf-errormenu", chan->language))
03443 ast_waitstream(chan, "");
03444 ast_stopstream(chan);
03445 break;
03446 }
03447 }
03448
03449 menu8_active = 0;
03450 menu_active = 0;
03451 } else if (ast_test_flag64(confflags, CONFFLAG_ADMIN)) {
03452
03453 if (!menu_active) {
03454 menu_active = 1;
03455
03456 if (!ast_streamfile(chan, "conf-adminmenu-162", chan->language)) {
03457 dtmf = ast_waitstream(chan, AST_DIGIT_ANY);
03458 ast_stopstream(chan);
03459 } else {
03460 dtmf = 0;
03461 }
03462 } else {
03463 dtmf = f->subclass.integer;
03464 }
03465 if (dtmf > 0) {
03466 switch(dtmf) {
03467 case '1':
03468 menu_active = 0;
03469
03470
03471 if (user->adminflags & (ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED)) {
03472 user->adminflags &= ~(ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED);
03473 } else {
03474 user->adminflags |= (ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED);
03475 }
03476
03477 if (ast_test_flag64(confflags, CONFFLAG_MONITOR) || (user->adminflags & (ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED))) {
03478 if (!ast_streamfile(chan, "conf-muted", chan->language)) {
03479 ast_waitstream(chan, "");
03480 }
03481 } else {
03482 if (!ast_streamfile(chan, "conf-unmuted", chan->language)) {
03483 ast_waitstream(chan, "");
03484 }
03485 }
03486 break;
03487 case '2':
03488 menu_active = 0;
03489 if (conf->locked) {
03490 conf->locked = 0;
03491 if (!ast_streamfile(chan, "conf-unlockednow", chan->language)) {
03492 ast_waitstream(chan, "");
03493 }
03494 } else {
03495 conf->locked = 1;
03496 if (!ast_streamfile(chan, "conf-lockednow", chan->language)) {
03497 ast_waitstream(chan, "");
03498 }
03499 }
03500 break;
03501 case '3':
03502 {
03503 struct ast_conf_user *usr = NULL;
03504 int max_no = 0;
03505 ao2_callback(conf->usercontainer, OBJ_NODATA, user_max_cmp, &max_no);
03506 menu_active = 0;
03507 usr = ao2_find(conf->usercontainer, &max_no, 0);
03508 if ((usr->chan->name == chan->name) || ast_test_flag64(&usr->userflags, CONFFLAG_ADMIN)) {
03509 if (!ast_streamfile(chan, "conf-errormenu", chan->language)) {
03510 ast_waitstream(chan, "");
03511 }
03512 } else {
03513 usr->adminflags |= ADMINFLAG_KICKME;
03514 }
03515 ao2_ref(usr, -1);
03516 ast_stopstream(chan);
03517 break;
03518 }
03519 case '4':
03520 tweak_listen_volume(user, VOL_DOWN);
03521 break;
03522 case '5':
03523
03524 if (rt_schedule) {
03525 if (!rt_extend_conf(conf->confno)) {
03526 if (!ast_streamfile(chan, "conf-extended", chan->language)) {
03527 ast_waitstream(chan, "");
03528 }
03529 } else {
03530 if (!ast_streamfile(chan, "conf-nonextended", chan->language)) {
03531 ast_waitstream(chan, "");
03532 }
03533 }
03534 ast_stopstream(chan);
03535 }
03536 menu_active = 0;
03537 break;
03538 case '6':
03539 tweak_listen_volume(user, VOL_UP);
03540 break;
03541 case '7':
03542 tweak_talk_volume(user, VOL_DOWN);
03543 break;
03544 case '8':
03545 menu8_active = 1;
03546 break;
03547 case '9':
03548 tweak_talk_volume(user, VOL_UP);
03549 break;
03550 default:
03551 menu_active = 0;
03552
03553 if (!ast_streamfile(chan, "conf-errormenu", chan->language)) {
03554 ast_waitstream(chan, "");
03555 }
03556 break;
03557 }
03558 }
03559 } else {
03560
03561 if (!menu_active) {
03562 menu_active = 1;
03563 if (!ast_streamfile(chan, "conf-usermenu-162", chan->language)) {
03564 dtmf = ast_waitstream(chan, AST_DIGIT_ANY);
03565 ast_stopstream(chan);
03566 } else {
03567 dtmf = 0;
03568 }
03569 } else {
03570 dtmf = f->subclass.integer;
03571 }
03572 if (dtmf > 0) {
03573 switch (dtmf) {
03574 case '1':
03575 menu_active = 0;
03576
03577
03578 user->adminflags ^= ADMINFLAG_SELFMUTED;
03579
03580
03581 if (ast_test_flag64(confflags, CONFFLAG_MONITOR) || (user->adminflags & (ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED))) {
03582 if (!ast_streamfile(chan, "conf-muted", chan->language)) {
03583 ast_waitstream(chan, "");
03584 }
03585 } else {
03586 if (!ast_streamfile(chan, "conf-unmuted", chan->language)) {
03587 ast_waitstream(chan, "");
03588 }
03589 }
03590 break;
03591 case '2':
03592 menu_active = 0;
03593 if (user->adminflags & (ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED)) {
03594 user->adminflags |= ADMINFLAG_T_REQUEST;
03595 }
03596
03597 if (user->adminflags & ADMINFLAG_T_REQUEST) {
03598 if (!ast_streamfile(chan, "beep", chan->language)) {
03599 ast_waitstream(chan, "");
03600 }
03601 }
03602 break;
03603 case '4':
03604 tweak_listen_volume(user, VOL_DOWN);
03605 break;
03606 case '5':
03607
03608 if (rt_schedule) {
03609 rt_extend_conf(conf->confno);
03610 }
03611 menu_active = 0;
03612 break;
03613 case '6':
03614 tweak_listen_volume(user, VOL_UP);
03615 break;
03616 case '7':
03617 tweak_talk_volume(user, VOL_DOWN);
03618 break;
03619 case '8':
03620 menu_active = 0;
03621 break;
03622 case '9':
03623 tweak_talk_volume(user, VOL_UP);
03624 break;
03625 default:
03626 menu_active = 0;
03627 if (!ast_streamfile(chan, "conf-errormenu", chan->language)) {
03628 ast_waitstream(chan, "");
03629 }
03630 break;
03631 }
03632 }
03633 }
03634 if (musiconhold && !menu_active) {
03635 conf_start_moh(chan, optargs[OPT_ARG_MOH_CLASS]);
03636 }
03637
03638 if (ioctl(fd, DAHDI_SETCONF, &dahdic)) {
03639 ast_log(LOG_WARNING, "Error setting conference\n");
03640 close(fd);
03641 ast_frfree(f);
03642 goto outrun;
03643 }
03644
03645 conf_flush(fd, chan);
03646
03647
03648
03649
03650 } else if ((f->frametype == AST_FRAME_DTMF) && ast_test_flag64(confflags, CONFFLAG_EXIT_CONTEXT) && ast_exists_extension(chan, exitcontext, dtmfstr, 1, "")) {
03651 if (ast_test_flag64(confflags, CONFFLAG_PASS_DTMF)) {
03652 conf_queue_dtmf(conf, user, f);
03653 }
03654
03655 if (!ast_goto_if_exists(chan, exitcontext, dtmfstr, 1)) {
03656 ast_debug(1, "Got DTMF %c, goto context %s\n", dtmfstr[0], exitcontext);
03657 ret = 0;
03658 ast_frfree(f);
03659 break;
03660 } else {
03661 ast_debug(2, "Exit by single digit did not work in meetme. Extension %s does not exist in context %s\n", dtmfstr, exitcontext);
03662 }
03663 } else if ((f->frametype == AST_FRAME_DTMF) && ast_test_flag64(confflags, CONFFLAG_KEYEXIT) &&
03664 (strchr(exitkeys, f->subclass.integer))) {
03665 pbx_builtin_setvar_helper(chan, "MEETME_EXIT_KEY", dtmfstr);
03666
03667 if (ast_test_flag64(confflags, CONFFLAG_PASS_DTMF)) {
03668 conf_queue_dtmf(conf, user, f);
03669 }
03670 ret = 0;
03671 ast_frfree(f);
03672 break;
03673 } else if ((f->frametype == AST_FRAME_DTMF_BEGIN || f->frametype == AST_FRAME_DTMF_END)
03674 && ast_test_flag64(confflags, CONFFLAG_PASS_DTMF)) {
03675 conf_queue_dtmf(conf, user, f);
03676 } else if (ast_test_flag64(confflags, CONFFLAG_SLA_STATION) && f->frametype == AST_FRAME_CONTROL) {
03677 switch (f->subclass.integer) {
03678 case AST_CONTROL_HOLD:
03679 sla_queue_event_conf(SLA_EVENT_HOLD, chan, conf);
03680 break;
03681 default:
03682 break;
03683 }
03684 } else if (f->frametype == AST_FRAME_NULL) {
03685
03686 } else if (f->frametype == AST_FRAME_CONTROL) {
03687 switch (f->subclass.integer) {
03688 case AST_CONTROL_BUSY:
03689 case AST_CONTROL_CONGESTION:
03690 ast_frfree(f);
03691 goto outrun;
03692 break;
03693 default:
03694 ast_debug(1,
03695 "Got ignored control frame on channel %s, f->frametype=%d,f->subclass=%d\n",
03696 chan->name, f->frametype, f->subclass.integer);
03697 }
03698 } else {
03699 ast_debug(1,
03700 "Got unrecognized frame on channel %s, f->frametype=%d,f->subclass=%d\n",
03701 chan->name, f->frametype, f->subclass.integer);
03702 }
03703 ast_frfree(f);
03704 } else if (outfd > -1) {
03705 res = read(outfd, buf, CONF_SIZE);
03706 if (res > 0) {
03707 memset(&fr, 0, sizeof(fr));
03708 fr.frametype = AST_FRAME_VOICE;
03709 fr.subclass.codec = AST_FORMAT_SLINEAR;
03710 fr.datalen = res;
03711 fr.samples = res / 2;
03712 fr.data.ptr = buf;
03713 fr.offset = AST_FRIENDLY_OFFSET;
03714 if (!user->listen.actual &&
03715 (ast_test_flag64(confflags, CONFFLAG_MONITOR) ||
03716 (user->adminflags & (ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED)) ||
03717 (!user->talking && ast_test_flag64(confflags, CONFFLAG_OPTIMIZETALKER))
03718 )) {
03719 int idx;
03720 for (idx = 0; idx < AST_FRAME_BITS; idx++) {
03721 if (chan->rawwriteformat & (1 << idx)) {
03722 break;
03723 }
03724 }
03725 if (idx >= AST_FRAME_BITS) {
03726 goto bailoutandtrynormal;
03727 }
03728 ast_mutex_lock(&conf->listenlock);
03729 if (!conf->transframe[idx]) {
03730 if (conf->origframe) {
03731 if (musiconhold && !ast_dsp_silence(dsp, conf->origframe, &confsilence) && confsilence < MEETME_DELAYDETECTTALK) {
03732 ast_moh_stop(chan);
03733 mohtempstopped = 1;
03734 }
03735 if (!conf->transpath[idx]) {
03736 conf->transpath[idx] = ast_translator_build_path((1 << idx), AST_FORMAT_SLINEAR);
03737 }
03738 if (conf->transpath[idx]) {
03739 conf->transframe[idx] = ast_translate(conf->transpath[idx], conf->origframe, 0);
03740 if (!conf->transframe[idx]) {
03741 conf->transframe[idx] = &ast_null_frame;
03742 }
03743 }
03744 }
03745 }
03746 if (conf->transframe[idx]) {
03747 if ((conf->transframe[idx]->frametype != AST_FRAME_NULL) &&
03748 can_write(chan, confflags)) {
03749 struct ast_frame *cur;
03750
03751
03752
03753 for (cur = conf->transframe[idx]; cur; cur = AST_LIST_NEXT(cur, frame_list)) {
03754 if (ast_write(chan, cur)) {
03755 ast_log(LOG_WARNING, "Unable to write frame to channel %s\n", chan->name);
03756 break;
03757 }
03758 }
03759 if (musiconhold && mohtempstopped && confsilence > MEETME_DELAYDETECTENDTALK) {
03760 mohtempstopped = 0;
03761 conf_start_moh(chan, optargs[OPT_ARG_MOH_CLASS]);
03762 }
03763 }
03764 } else {
03765 ast_mutex_unlock(&conf->listenlock);
03766 goto bailoutandtrynormal;
03767 }
03768 ast_mutex_unlock(&conf->listenlock);
03769 } else {
03770 bailoutandtrynormal:
03771 if (musiconhold && !ast_dsp_silence(dsp, &fr, &confsilence) && confsilence < MEETME_DELAYDETECTTALK) {
03772 ast_moh_stop(chan);
03773 mohtempstopped = 1;
03774 }
03775 if (user->listen.actual) {
03776 ast_frame_adjust_volume(&fr, user->listen.actual);
03777 }
03778 if (can_write(chan, confflags) && ast_write(chan, &fr) < 0) {
03779 ast_log(LOG_WARNING, "Unable to write frame to channel %s\n", chan->name);
03780 }
03781 if (musiconhold && mohtempstopped && confsilence > MEETME_DELAYDETECTENDTALK) {
03782 mohtempstopped = 0;
03783 conf_start_moh(chan, optargs[OPT_ARG_MOH_CLASS]);
03784 }
03785 }
03786 } else {
03787 ast_log(LOG_WARNING, "Failed to read frame: %s\n", strerror(errno));
03788 }
03789 }
03790 lastmarked = currentmarked;
03791 }
03792 }
03793
03794 if (musiconhold) {
03795 ast_moh_stop(chan);
03796 }
03797
03798 if (using_pseudo) {
03799 close(fd);
03800 } else {
03801
03802 dahdic.chan = 0;
03803 dahdic.confno = 0;
03804 dahdic.confmode = 0;
03805 if (ioctl(fd, DAHDI_SETCONF, &dahdic)) {
03806 ast_log(LOG_WARNING, "Error setting conference\n");
03807 }
03808 }
03809
03810 reset_volumes(user);
03811
03812 if (!ast_test_flag64(confflags, CONFFLAG_QUIET) && !ast_test_flag64(confflags, CONFFLAG_MONITOR) &&
03813 !ast_test_flag64(confflags, CONFFLAG_ADMIN)) {
03814 conf_play(chan, conf, LEAVE);
03815 }
03816
03817 if (!ast_test_flag64(confflags, CONFFLAG_QUIET) && (ast_test_flag64(confflags, CONFFLAG_INTROUSER) || ast_test_flag64(confflags, CONFFLAG_INTROUSERNOREVIEW)) && conf->users > 1) {
03818 struct announce_listitem *item;
03819 if (!(item = ao2_alloc(sizeof(*item), NULL)))
03820 goto outrun;
03821 ast_copy_string(item->namerecloc, user->namerecloc, sizeof(item->namerecloc));
03822 ast_copy_string(item->language, chan->language, sizeof(item->language));
03823 item->confchan = conf->chan;
03824 item->confusers = conf->users;
03825 item->announcetype = CONF_HASLEFT;
03826 ast_mutex_lock(&conf->announcelistlock);
03827 AST_LIST_INSERT_TAIL(&conf->announcelist, item, entry);
03828 ast_cond_signal(&conf->announcelist_addition);
03829 ast_mutex_unlock(&conf->announcelistlock);
03830 } else if (!ast_test_flag64(confflags, CONFFLAG_QUIET) && (ast_test_flag64(confflags, CONFFLAG_INTROUSER) ||
03831 ast_test_flag64(confflags, CONFFLAG_INTROUSERNOREVIEW)) && conf->users == 1) {
03832
03833 ast_filedelete(user->namerecloc, NULL);
03834 }
03835
03836 outrun:
03837 AST_LIST_LOCK(&confs);
03838
03839 if (dsp) {
03840 ast_dsp_free(dsp);
03841 }
03842
03843 if (user->user_no) {
03844
03845 now = ast_tvnow();
03846
03847 if (sent_event) {
03848 ast_manager_event(chan, EVENT_FLAG_CALL, "MeetmeLeave",
03849 "Channel: %s\r\n"
03850 "Uniqueid: %s\r\n"
03851 "Meetme: %s\r\n"
03852 "Usernum: %d\r\n"
03853 "CallerIDNum: %s\r\n"
03854 "CallerIDName: %s\r\n"
03855 "ConnectedLineNum: %s\r\n"
03856 "ConnectedLineName: %s\r\n"
03857 "Duration: %ld\r\n",
03858 chan->name, chan->uniqueid, conf->confno,
03859 user->user_no,
03860 S_COR(user->chan->caller.id.number.valid, user->chan->caller.id.number.str, "<unknown>"),
03861 S_COR(user->chan->caller.id.name.valid, user->chan->caller.id.name.str, "<unknown>"),
03862 S_COR(user->chan->connected.id.number.valid, user->chan->connected.id.number.str, "<unknown>"),
03863 S_COR(user->chan->connected.id.name.valid, user->chan->connected.id.name.str, "<unknown>"),
03864 (long)(now.tv_sec - user->jointime));
03865 }
03866
03867 if (setusercount) {
03868 conf->users--;
03869 if (rt_log_members) {
03870
03871 snprintf(members, sizeof(members), "%d", conf->users);
03872 ast_realtime_require_field("meetme",
03873 "confno", strlen(conf->confno) > 7 ? RQ_UINTEGER4 : strlen(conf->confno) > 4 ? RQ_UINTEGER3 : RQ_UINTEGER2, strlen(conf->confno),
03874 "members", RQ_UINTEGER1, strlen(members),
03875 NULL);
03876 ast_update_realtime("meetme", "confno", conf->confno, "members", members, NULL);
03877 }
03878 if (ast_test_flag64(confflags, CONFFLAG_MARKEDUSER)) {
03879 conf->markedusers--;
03880 }
03881 }
03882
03883 ao2_unlink(conf->usercontainer, user);
03884
03885
03886 if (!conf->users) {
03887 ast_devstate_changed(AST_DEVICE_NOT_INUSE, (conf->isdynamic ? AST_DEVSTATE_NOT_CACHABLE : AST_DEVSTATE_CACHABLE), "meetme:%s", conf->confno);
03888 }
03889
03890
03891 snprintf(meetmesecs, sizeof(meetmesecs), "%d", (int) (time(NULL) - user->jointime));
03892 pbx_builtin_setvar_helper(chan, "MEETMESECS", meetmesecs);
03893
03894
03895 if (rt_schedule) {
03896 pbx_builtin_setvar_helper(chan, "MEETMEBOOKID", conf->bookid);
03897 }
03898 }
03899 ao2_ref(user, -1);
03900 AST_LIST_UNLOCK(&confs);
03901
03902 return ret;
03903 }
03904
03905 static struct ast_conference *find_conf_realtime(struct ast_channel *chan, char *confno, int make, int dynamic,
03906 char *dynamic_pin, size_t pin_buf_len, int refcount, struct ast_flags64 *confflags, int *too_early, char **optargs)
03907 {
03908 struct ast_variable *var, *origvar;
03909 struct ast_conference *cnf;
03910
03911 *too_early = 0;
03912
03913
03914 AST_LIST_LOCK(&confs);
03915 AST_LIST_TRAVERSE(&confs, cnf, list) {
03916 if (!strcmp(confno, cnf->confno)) {
03917 break;
03918 }
03919 }
03920 if (cnf) {
03921 cnf->refcount += refcount;
03922 }
03923 AST_LIST_UNLOCK(&confs);
03924
03925 if (!cnf) {
03926 char *pin = NULL, *pinadmin = NULL;
03927 int maxusers = 0;
03928 struct timeval now;
03929 char recordingfilename[256] = "";
03930 char recordingformat[11] = "";
03931 char currenttime[32] = "";
03932 char eatime[32] = "";
03933 char bookid[51] = "";
03934 char recordingtmp[AST_MAX_EXTENSION] = "";
03935 char useropts[OPTIONS_LEN + 1] = "";
03936 char adminopts[OPTIONS_LEN + 1] = "";
03937 struct ast_tm tm, etm;
03938 struct timeval endtime = { .tv_sec = 0 };
03939 const char *var2;
03940
03941 if (rt_schedule) {
03942 now = ast_tvnow();
03943
03944 ast_localtime(&now, &tm, NULL);
03945 ast_strftime(currenttime, sizeof(currenttime), DATE_FORMAT, &tm);
03946
03947 ast_debug(1, "Looking for conference %s that starts after %s\n", confno, currenttime);
03948
03949 var = ast_load_realtime("meetme", "confno",
03950 confno, "starttime <= ", currenttime, "endtime >= ",
03951 currenttime, NULL);
03952
03953 if (!var && fuzzystart) {
03954 now = ast_tvnow();
03955 now.tv_sec += fuzzystart;
03956
03957 ast_localtime(&now, &tm, NULL);
03958 ast_strftime(currenttime, sizeof(currenttime), DATE_FORMAT, &tm);
03959 var = ast_load_realtime("meetme", "confno",
03960 confno, "starttime <= ", currenttime, "endtime >= ",
03961 currenttime, NULL);
03962 }
03963
03964 if (!var && earlyalert) {
03965 now = ast_tvnow();
03966 now.tv_sec += earlyalert;
03967 ast_localtime(&now, &etm, NULL);
03968 ast_strftime(eatime, sizeof(eatime), DATE_FORMAT, &etm);
03969 var = ast_load_realtime("meetme", "confno",
03970 confno, "starttime <= ", eatime, "endtime >= ",
03971 currenttime, NULL);
03972 if (var) {
03973 *too_early = 1;
03974 }
03975 }
03976
03977 } else {
03978 var = ast_load_realtime("meetme", "confno", confno, NULL);
03979 }
03980
03981 if (!var) {
03982 return NULL;
03983 }
03984
03985 if (rt_schedule && *too_early) {
03986
03987 if (!ast_streamfile(chan, "conf-has-not-started", chan->language)) {
03988 ast_waitstream(chan, "");
03989 }
03990 ast_variables_destroy(var);
03991 return NULL;
03992 }
03993
03994 for (origvar = var; var; var = var->next) {
03995 if (!strcasecmp(var->name, "pin")) {
03996 pin = ast_strdupa(var->value);
03997 } else if (!strcasecmp(var->name, "adminpin")) {
03998 pinadmin = ast_strdupa(var->value);
03999 } else if (!strcasecmp(var->name, "bookId")) {
04000 ast_copy_string(bookid, var->value, sizeof(bookid));
04001 } else if (!strcasecmp(var->name, "opts")) {
04002 ast_copy_string(useropts, var->value, sizeof(char[OPTIONS_LEN + 1]));
04003 } else if (!strcasecmp(var->name, "maxusers")) {
04004 maxusers = atoi(var->value);
04005 } else if (!strcasecmp(var->name, "adminopts")) {
04006 ast_copy_string(adminopts, var->value, sizeof(char[OPTIONS_LEN + 1]));
04007 } else if (!strcasecmp(var->name, "recordingfilename")) {
04008 ast_copy_string(recordingfilename, var->value, sizeof(recordingfilename));
04009 } else if (!strcasecmp(var->name, "recordingformat")) {
04010 ast_copy_string(recordingformat, var->value, sizeof(recordingformat));
04011 } else if (!strcasecmp(var->name, "endtime")) {
04012 struct ast_tm endtime_tm;
04013 ast_strptime(var->value, "%Y-%m-%d %H:%M:%S", &endtime_tm);
04014 endtime = ast_mktime(&endtime_tm, NULL);
04015 }
04016 }
04017
04018 ast_variables_destroy(origvar);
04019
04020 cnf = build_conf(confno, pin ? pin : "", pinadmin ? pinadmin : "", make, dynamic, refcount, chan, NULL);
04021
04022 if (cnf) {
04023 struct ast_flags64 tmp_flags;
04024
04025 cnf->maxusers = maxusers;
04026 cnf->endalert = endalert;
04027 cnf->endtime = endtime.tv_sec;
04028 cnf->useropts = ast_strdup(useropts);
04029 cnf->adminopts = ast_strdup(adminopts);
04030 cnf->bookid = ast_strdup(bookid);
04031 if (!ast_strlen_zero(recordingfilename)) {
04032 cnf->recordingfilename = ast_strdup(recordingfilename);
04033 }
04034 if (!ast_strlen_zero(recordingformat)) {
04035 cnf->recordingformat = ast_strdup(recordingformat);
04036 }
04037
04038
04039
04040 ast_app_parse_options64(meetme_opts, &tmp_flags, optargs, useropts);
04041 ast_copy_flags64(confflags, &tmp_flags, tmp_flags.flags);
04042
04043 if (strchr(cnf->useropts, 'r')) {
04044 if (ast_strlen_zero(recordingfilename)) {
04045 ast_channel_lock(chan);
04046 if ((var2 = pbx_builtin_getvar_helper(chan, "MEETME_RECORDINGFILE"))) {
04047 ast_free(cnf->recordingfilename);
04048 cnf->recordingfilename = ast_strdup(var2);
04049 }
04050 ast_channel_unlock(chan);
04051 if (ast_strlen_zero(cnf->recordingfilename)) {
04052 snprintf(recordingtmp, sizeof(recordingtmp), "meetme-conf-rec-%s-%s", cnf->confno, chan->uniqueid);
04053 ast_free(cnf->recordingfilename);
04054 cnf->recordingfilename = ast_strdup(recordingtmp);
04055 }
04056 }
04057 if (ast_strlen_zero(cnf->recordingformat)) {
04058 ast_channel_lock(chan);
04059 if ((var2 = pbx_builtin_getvar_helper(chan, "MEETME_RECORDINGFORMAT"))) {
04060 ast_free(cnf->recordingformat);
04061 cnf->recordingformat = ast_strdup(var2);
04062 }
04063 ast_channel_unlock(chan);
04064 if (ast_strlen_zero(cnf->recordingformat)) {
04065 ast_free(cnf->recordingformat);
04066 cnf->recordingformat = ast_strdup("wav");
04067 }
04068 }
04069 ast_verb(4, "Starting recording of MeetMe Conference %s into file %s.%s.\n", cnf->confno, cnf->recordingfilename, cnf->recordingformat);
04070 }
04071 }
04072 }
04073
04074 if (cnf) {
04075 if (confflags->flags && !cnf->chan &&
04076 !ast_test_flag64(confflags, CONFFLAG_QUIET) &&
04077 ast_test_flag64(confflags, CONFFLAG_INTROUSER | CONFFLAG_INTROUSERNOREVIEW)) {
04078 ast_log(LOG_WARNING, "No DAHDI channel available for conference, user introduction disabled (is chan_dahdi loaded?)\n");
04079 ast_clear_flag64(confflags, CONFFLAG_INTROUSER | CONFFLAG_INTROUSERNOREVIEW);
04080 }
04081
04082 if (confflags && !cnf->chan &&
04083 ast_test_flag64(confflags, CONFFLAG_RECORDCONF)) {
04084 ast_log(LOG_WARNING, "No DAHDI channel available for conference, conference recording disabled (is chan_dahdi loaded?)\n");
04085 ast_clear_flag64(confflags, CONFFLAG_RECORDCONF);
04086 }
04087 }
04088
04089 return cnf;
04090 }
04091
04092
04093 static struct ast_conference *find_conf(struct ast_channel *chan, char *confno, int make, int dynamic,
04094 char *dynamic_pin, size_t pin_buf_len, int refcount, struct ast_flags64 *confflags)
04095 {
04096 struct ast_config *cfg;
04097 struct ast_variable *var;
04098 struct ast_flags config_flags = { 0 };
04099 struct ast_conference *cnf;
04100
04101 AST_DECLARE_APP_ARGS(args,
04102 AST_APP_ARG(confno);
04103 AST_APP_ARG(pin);
04104 AST_APP_ARG(pinadmin);
04105 );
04106
04107
04108 ast_debug(1, "The requested confno is '%s'?\n", confno);
04109 AST_LIST_LOCK(&confs);
04110 AST_LIST_TRAVERSE(&confs, cnf, list) {
04111 ast_debug(3, "Does conf %s match %s?\n", confno, cnf->confno);
04112 if (!strcmp(confno, cnf->confno))
04113 break;
04114 }
04115 if (cnf) {
04116 cnf->refcount += refcount;
04117 }
04118 AST_LIST_UNLOCK(&confs);
04119
04120 if (!cnf) {
04121 if (dynamic) {
04122
04123 ast_debug(1, "Building dynamic conference '%s'\n", confno);
04124 if (dynamic_pin) {
04125 if (dynamic_pin[0] == 'q') {
04126
04127 if (ast_app_getdata(chan, "conf-getpin", dynamic_pin, pin_buf_len - 1, 0) < 0)
04128 return NULL;
04129 }
04130 cnf = build_conf(confno, dynamic_pin, "", make, dynamic, refcount, chan, NULL);
04131 } else {
04132 cnf = build_conf(confno, "", "", make, dynamic, refcount, chan, NULL);
04133 }
04134 } else {
04135
04136 cfg = ast_config_load(CONFIG_FILE_NAME, config_flags);
04137 if (!cfg) {
04138 ast_log(LOG_WARNING, "No %s file :(\n", CONFIG_FILE_NAME);
04139 return NULL;
04140 } else if (cfg == CONFIG_STATUS_FILEINVALID) {
04141 ast_log(LOG_ERROR, "Config file " CONFIG_FILE_NAME " is in an invalid format. Aborting.\n");
04142 return NULL;
04143 }
04144
04145 for (var = ast_variable_browse(cfg, "rooms"); var; var = var->next) {
04146 char parse[MAX_SETTINGS];
04147
04148 if (strcasecmp(var->name, "conf"))
04149 continue;
04150
04151 ast_copy_string(parse, var->value, sizeof(parse));
04152
04153 AST_STANDARD_APP_ARGS(args, parse);
04154 ast_debug(3, "Will conf %s match %s?\n", confno, args.confno);
04155 if (!strcasecmp(args.confno, confno)) {
04156
04157 cnf = build_conf(args.confno,
04158 S_OR(args.pin, ""),
04159 S_OR(args.pinadmin, ""),
04160 make, dynamic, refcount, chan, NULL);
04161 break;
04162 }
04163 }
04164 if (!var) {
04165 ast_debug(1, "%s isn't a valid conference\n", confno);
04166 }
04167 ast_config_destroy(cfg);
04168 }
04169 } else if (dynamic_pin) {
04170
04171
04172
04173 if (dynamic_pin[0] == 'q') {
04174 dynamic_pin[0] = '\0';
04175 }
04176 }
04177
04178 if (cnf) {
04179 if (confflags && !cnf->chan &&
04180 !ast_test_flag64(confflags, CONFFLAG_QUIET) &&
04181 ast_test_flag64(confflags, CONFFLAG_INTROUSER | CONFFLAG_INTROUSERNOREVIEW)) {
04182 ast_log(LOG_WARNING, "No DAHDI channel available for conference, user introduction disabled (is chan_dahdi loaded?)\n");
04183 ast_clear_flag64(confflags, CONFFLAG_INTROUSER | CONFFLAG_INTROUSERNOREVIEW);
04184 }
04185
04186 if (confflags && !cnf->chan &&
04187 ast_test_flag64(confflags, CONFFLAG_RECORDCONF)) {
04188 ast_log(LOG_WARNING, "No DAHDI channel available for conference, conference recording disabled (is chan_dahdi loaded?)\n");
04189 ast_clear_flag64(confflags, CONFFLAG_RECORDCONF);
04190 }
04191 }
04192
04193 return cnf;
04194 }
04195
04196
04197 static int count_exec(struct ast_channel *chan, const char *data)
04198 {
04199 int res = 0;
04200 struct ast_conference *conf;
04201 int count;
04202 char *localdata;
04203 char val[80] = "0";
04204 AST_DECLARE_APP_ARGS(args,
04205 AST_APP_ARG(confno);
04206 AST_APP_ARG(varname);
04207 );
04208
04209 if (ast_strlen_zero(data)) {
04210 ast_log(LOG_WARNING, "MeetMeCount requires an argument (conference number)\n");
04211 return -1;
04212 }
04213
04214 localdata = ast_strdupa(data);
04215
04216 AST_STANDARD_APP_ARGS(args, localdata);
04217
04218 conf = find_conf(chan, args.confno, 0, 0, NULL, 0, 1, NULL);
04219
04220 if (conf) {
04221 count = conf->users;
04222 dispose_conf(conf);
04223 conf = NULL;
04224 } else
04225 count = 0;
04226
04227 if (!ast_strlen_zero(args.varname)) {
04228
04229 snprintf(val, sizeof(val), "%d", count);
04230 pbx_builtin_setvar_helper(chan, args.varname, val);
04231 } else {
04232 if (chan->_state != AST_STATE_UP) {
04233 ast_answer(chan);
04234 }
04235 res = ast_say_number(chan, count, "", chan->language, (char *) NULL);
04236 }
04237
04238 return res;
04239 }
04240
04241
04242 static int conf_exec(struct ast_channel *chan, const char *data)
04243 {
04244 int res = -1;
04245 char confno[MAX_CONFNUM] = "";
04246 int allowretry = 0;
04247 int retrycnt = 0;
04248 struct ast_conference *cnf = NULL;
04249 struct ast_flags64 confflags = {0};
04250 struct ast_flags config_flags = { 0 };
04251 int dynamic = 0;
04252 int empty = 0, empty_no_pin = 0;
04253 int always_prompt = 0;
04254 const char *notdata;
04255 char *info, the_pin[MAX_PIN] = "";
04256 AST_DECLARE_APP_ARGS(args,
04257 AST_APP_ARG(confno);
04258 AST_APP_ARG(options);
04259 AST_APP_ARG(pin);
04260 );
04261 char *optargs[OPT_ARG_ARRAY_SIZE] = { NULL, };
04262
04263 if (ast_strlen_zero(data)) {
04264 allowretry = 1;
04265 notdata = "";
04266 } else {
04267 notdata = data;
04268 }
04269
04270 if (chan->_state != AST_STATE_UP)
04271 ast_answer(chan);
04272
04273 info = ast_strdupa(notdata);
04274
04275 AST_STANDARD_APP_ARGS(args, info);
04276
04277 if (args.confno) {
04278 ast_copy_string(confno, args.confno, sizeof(confno));
04279 if (ast_strlen_zero(confno)) {
04280 allowretry = 1;
04281 }
04282 }
04283
04284 if (args.pin)
04285 ast_copy_string(the_pin, args.pin, sizeof(the_pin));
04286
04287 if (args.options) {
04288 ast_app_parse_options64(meetme_opts, &confflags, optargs, args.options);
04289 dynamic = ast_test_flag64(&confflags, CONFFLAG_DYNAMIC | CONFFLAG_DYNAMICPIN);
04290 if (ast_test_flag64(&confflags, CONFFLAG_DYNAMICPIN) && ast_strlen_zero(args.pin))
04291 strcpy(the_pin, "q");
04292
04293 empty = ast_test_flag64(&confflags, CONFFLAG_EMPTY | CONFFLAG_EMPTYNOPIN);
04294 empty_no_pin = ast_test_flag64(&confflags, CONFFLAG_EMPTYNOPIN);
04295 always_prompt = ast_test_flag64(&confflags, CONFFLAG_ALWAYSPROMPT | CONFFLAG_DYNAMICPIN);
04296 }
04297
04298 do {
04299 if (retrycnt > 3)
04300 allowretry = 0;
04301 if (empty) {
04302 int i;
04303 struct ast_config *cfg;
04304 struct ast_variable *var;
04305 int confno_int;
04306
04307
04308 if ((empty_no_pin) || (!dynamic)) {
04309 cfg = ast_config_load(CONFIG_FILE_NAME, config_flags);
04310 if (cfg && cfg != CONFIG_STATUS_FILEINVALID) {
04311 var = ast_variable_browse(cfg, "rooms");
04312 while (var) {
04313 char parse[MAX_SETTINGS], *stringp = parse, *confno_tmp;
04314 if (!strcasecmp(var->name, "conf")) {
04315 int found = 0;
04316 ast_copy_string(parse, var->value, sizeof(parse));
04317 confno_tmp = strsep(&stringp, "|,");
04318 if (!dynamic) {
04319
04320 AST_LIST_LOCK(&confs);
04321 AST_LIST_TRAVERSE(&confs, cnf, list) {
04322 if (!strcmp(confno_tmp, cnf->confno)) {
04323
04324 found = 1;
04325 break;
04326 }
04327 }
04328 AST_LIST_UNLOCK(&confs);
04329 cnf = NULL;
04330 if (!found) {
04331
04332 if ((empty_no_pin && ast_strlen_zero(stringp)) || (!empty_no_pin)) {
04333
04334
04335
04336
04337 ast_copy_string(confno, confno_tmp, sizeof(confno));
04338 break;
04339 }
04340 }
04341 }
04342 }
04343 var = var->next;
04344 }
04345 ast_config_destroy(cfg);
04346 }
04347
04348 if (ast_strlen_zero(confno) && (cfg = ast_load_realtime_multientry("meetme", "confno LIKE", "%", SENTINEL))) {
04349 const char *catg;
04350 for (catg = ast_category_browse(cfg, NULL); catg; catg = ast_category_browse(cfg, catg)) {
04351 const char *confno_tmp = ast_variable_retrieve(cfg, catg, "confno");
04352 const char *pin_tmp = ast_variable_retrieve(cfg, catg, "pin");
04353 if (ast_strlen_zero(confno_tmp)) {
04354 continue;
04355 }
04356 if (!dynamic) {
04357 int found = 0;
04358
04359 AST_LIST_LOCK(&confs);
04360 AST_LIST_TRAVERSE(&confs, cnf, list) {
04361 if (!strcmp(confno_tmp, cnf->confno)) {
04362
04363 found = 1;
04364 break;
04365 }
04366 }
04367 AST_LIST_UNLOCK(&confs);
04368 if (!found) {
04369
04370 if ((empty_no_pin && ast_strlen_zero(pin_tmp)) || (!empty_no_pin)) {
04371
04372
04373
04374
04375 ast_copy_string(confno, confno_tmp, sizeof(confno));
04376 break;
04377 }
04378 }
04379 }
04380 }
04381 ast_config_destroy(cfg);
04382 }
04383 }
04384
04385
04386 if (ast_strlen_zero(confno) && dynamic) {
04387 AST_LIST_LOCK(&confs);
04388 for (i = 0; i < ARRAY_LEN(conf_map); i++) {
04389 if (!conf_map[i]) {
04390 snprintf(confno, sizeof(confno), "%d", i);
04391 conf_map[i] = 1;
04392 break;
04393 }
04394 }
04395 AST_LIST_UNLOCK(&confs);
04396 }
04397
04398
04399 if (ast_strlen_zero(confno)) {
04400 ast_test_suite_event_notify("PLAYBACK", "Message: conf-noempty");
04401 res = ast_streamfile(chan, "conf-noempty", chan->language);
04402 if (!res)
04403 ast_waitstream(chan, "");
04404 } else {
04405 if (sscanf(confno, "%30d", &confno_int) == 1) {
04406 if (!ast_test_flag64(&confflags, CONFFLAG_QUIET)) {
04407 res = ast_streamfile(chan, "conf-enteringno", chan->language);
04408 if (!res) {
04409 ast_waitstream(chan, "");
04410 res = ast_say_digits(chan, confno_int, "", chan->language);
04411 }
04412 }
04413 } else {
04414 ast_log(LOG_ERROR, "Could not scan confno '%s'\n", confno);
04415 }
04416 }
04417 }
04418
04419 while (allowretry && (ast_strlen_zero(confno)) && (++retrycnt < 4)) {
04420
04421 res = ast_app_getdata(chan, "conf-getconfno", confno, sizeof(confno) - 1, 0);
04422 if (res < 0) {
04423
04424 confno[0] = '\0';
04425 allowretry = 0;
04426 break;
04427 }
04428 }
04429 if (!ast_strlen_zero(confno)) {
04430
04431 cnf = find_conf(chan, confno, 1, dynamic, the_pin,
04432 sizeof(the_pin), 1, &confflags);
04433 if (!cnf) {
04434 int too_early = 0;
04435
04436 cnf = find_conf_realtime(chan, confno, 1, dynamic,
04437 the_pin, sizeof(the_pin), 1, &confflags, &too_early, optargs);
04438 if (rt_schedule && too_early)
04439 allowretry = 0;
04440 }
04441
04442 if (!cnf) {
04443 if (allowretry) {
04444 confno[0] = '\0';
04445 res = ast_streamfile(chan, "conf-invalid", chan->language);
04446 if (!res)
04447 ast_waitstream(chan, "");
04448 res = -1;
04449 }
04450 } else {
04451
04452 int req_pin = !ast_strlen_zero(cnf->pin) ||
04453 (!ast_strlen_zero(cnf->pinadmin) &&
04454 ast_test_flag64(&confflags, CONFFLAG_ADMIN));
04455
04456
04457
04458
04459
04460
04461
04462
04463
04464
04465
04466
04467
04468 int not_exempt = !cnf->isdynamic;
04469 not_exempt = not_exempt || (!ast_strlen_zero(args.pin) && ast_test_flag64(&confflags, CONFFLAG_ALWAYSPROMPT));
04470 not_exempt = not_exempt || (ast_strlen_zero(args.pin) && cnf->users);
04471 if (req_pin && not_exempt) {
04472 char pin[MAX_PIN] = "";
04473 int j;
04474
04475
04476 for (j = 0; j < 3; j++) {
04477 if (*the_pin && (always_prompt == 0)) {
04478 ast_copy_string(pin, the_pin, sizeof(pin));
04479 res = 0;
04480 } else {
04481
04482 ast_test_suite_event_notify("PLAYBACK", "Message: conf-getpin\r\n"
04483 "Channel: %s",
04484 chan->name);
04485 res = ast_app_getdata(chan, "conf-getpin", pin + strlen(pin), sizeof(pin) - 1 - strlen(pin), 0);
04486 }
04487 if (res >= 0) {
04488 if ((!strcasecmp(pin, cnf->pin) &&
04489 (ast_strlen_zero(cnf->pinadmin) ||
04490 !ast_test_flag64(&confflags, CONFFLAG_ADMIN))) ||
04491 (!ast_strlen_zero(cnf->pinadmin) &&
04492 !strcasecmp(pin, cnf->pinadmin))) {
04493
04494 allowretry = 0;
04495 if (!ast_strlen_zero(cnf->pinadmin) && !strcasecmp(pin, cnf->pinadmin)) {
04496 if (!ast_strlen_zero(cnf->adminopts)) {
04497 char *opts = ast_strdupa(cnf->adminopts);
04498 ast_app_parse_options64(meetme_opts, &confflags, optargs, opts);
04499 }
04500 } else {
04501 if (!ast_strlen_zero(cnf->useropts)) {
04502 char *opts = ast_strdupa(cnf->useropts);
04503 ast_app_parse_options64(meetme_opts, &confflags, optargs, opts);
04504 }
04505 }
04506
04507 ast_verb(4, "Starting recording of MeetMe Conference %s into file %s.%s.\n", cnf->confno, cnf->recordingfilename, cnf->recordingformat);
04508 res = conf_run(chan, cnf, &confflags, optargs);
04509 break;
04510 } else {
04511
04512 if (!ast_streamfile(chan, "conf-invalidpin", chan->language)) {
04513 res = ast_waitstream(chan, AST_DIGIT_ANY);
04514 ast_stopstream(chan);
04515 } else {
04516 ast_log(LOG_WARNING, "Couldn't play invalid pin msg!\n");
04517 break;
04518 }
04519 if (res < 0)
04520 break;
04521 pin[0] = res;
04522 pin[1] = '\0';
04523 res = -1;
04524 if (allowretry)
04525 confno[0] = '\0';
04526 }
04527 } else {
04528
04529 res = -1;
04530 allowretry = 0;
04531
04532 break;
04533 }
04534
04535
04536 if (*the_pin && (always_prompt == 0)) {
04537 break;
04538 }
04539 }
04540 } else {
04541
04542 allowretry = 0;
04543
04544
04545
04546
04547 if (!ast_strlen_zero(cnf->useropts)) {
04548 char *opts = ast_strdupa(cnf->useropts);
04549 ast_app_parse_options64(meetme_opts, &confflags, optargs, opts);
04550 }
04551
04552
04553 res = conf_run(chan, cnf, &confflags, optargs);
04554 }
04555 dispose_conf(cnf);
04556 cnf = NULL;
04557 }
04558 }
04559 } while (allowretry);
04560
04561 if (cnf)
04562 dispose_conf(cnf);
04563
04564 return res;
04565 }
04566
04567 static struct ast_conf_user *find_user(struct ast_conference *conf, const char *callerident)
04568 {
04569 struct ast_conf_user *user = NULL;
04570 int cid;
04571
04572 if (conf && callerident && sscanf(callerident, "%30d", &cid) == 1) {
04573 user = ao2_find(conf->usercontainer, &cid, 0);
04574
04575 return user;
04576 }
04577 return NULL;
04578 }
04579
04580 static int user_listen_volup_cb(void *obj, void *unused, int flags)
04581 {
04582 struct ast_conf_user *user = obj;
04583 tweak_listen_volume(user, VOL_UP);
04584 return 0;
04585 }
04586
04587 static int user_listen_voldown_cb(void *obj, void *unused, int flags)
04588 {
04589 struct ast_conf_user *user = obj;
04590 tweak_listen_volume(user, VOL_DOWN);
04591 return 0;
04592 }
04593
04594 static int user_talk_volup_cb(void *obj, void *unused, int flags)
04595 {
04596 struct ast_conf_user *user = obj;
04597 tweak_talk_volume(user, VOL_UP);
04598 return 0;
04599 }
04600
04601 static int user_talk_voldown_cb(void *obj, void *unused, int flags)
04602 {
04603 struct ast_conf_user *user = obj;
04604 tweak_talk_volume(user, VOL_DOWN);
04605 return 0;
04606 }
04607
04608 static int user_reset_vol_cb(void *obj, void *unused, int flags)
04609 {
04610 struct ast_conf_user *user = obj;
04611 reset_volumes(user);
04612 return 0;
04613 }
04614
04615 static int user_chan_cb(void *obj, void *args, int flags)
04616 {
04617 struct ast_conf_user *user = obj;
04618 const char *channel = args;
04619
04620 if (!strcmp(user->chan->name, channel)) {
04621 return (CMP_MATCH | CMP_STOP);
04622 }
04623
04624 return 0;
04625 }
04626
04627
04628
04629
04630 static int admin_exec(struct ast_channel *chan, const char *data) {
04631 char *params;
04632 struct ast_conference *cnf;
04633 struct ast_conf_user *user = NULL;
04634 AST_DECLARE_APP_ARGS(args,
04635 AST_APP_ARG(confno);
04636 AST_APP_ARG(command);
04637 AST_APP_ARG(user);
04638 );
04639 int res = 0;
04640
04641 if (ast_strlen_zero(data)) {
04642 ast_log(LOG_WARNING, "MeetMeAdmin requires an argument!\n");
04643 pbx_builtin_setvar_helper(chan, "MEETMEADMINSTATUS", "NOPARSE");
04644 return -1;
04645 }
04646
04647 params = ast_strdupa(data);
04648 AST_STANDARD_APP_ARGS(args, params);
04649
04650 if (!args.command) {
04651 ast_log(LOG_WARNING, "MeetmeAdmin requires a command!\n");
04652 pbx_builtin_setvar_helper(chan, "MEETMEADMINSTATUS", "NOPARSE");
04653 return -1;
04654 }
04655
04656 AST_LIST_LOCK(&confs);
04657 AST_LIST_TRAVERSE(&confs, cnf, list) {
04658 if (!strcmp(cnf->confno, args.confno))
04659 break;
04660 }
04661
04662 if (!cnf) {
04663 ast_log(LOG_WARNING, "Conference number '%s' not found!\n", args.confno);
04664 AST_LIST_UNLOCK(&confs);
04665 pbx_builtin_setvar_helper(chan, "MEETMEADMINSTATUS", "NOTFOUND");
04666 return 0;
04667 }
04668
04669 ast_atomic_fetchadd_int(&cnf->refcount, 1);
04670
04671 if (args.user) {
04672 user = find_user(cnf, args.user);
04673 if (!user) {
04674 ast_log(LOG_NOTICE, "Specified User not found!\n");
04675 res = -2;
04676 goto usernotfound;
04677 }
04678 }
04679
04680 switch (*args.command) {
04681 case 76:
04682 cnf->locked = 1;
04683 break;
04684 case 108:
04685 cnf->locked = 0;
04686 break;
04687 case 75:
04688 ao2_callback(cnf->usercontainer, OBJ_NODATA, user_set_kickme_cb, NULL);
04689 break;
04690 case 101:
04691 {
04692 int max_no = 0;
04693
04694
04695 if (user) {
04696 ao2_ref(user, -1);
04697 }
04698
04699 ao2_callback(cnf->usercontainer, OBJ_NODATA, user_max_cmp, &max_no);
04700 user = ao2_find(cnf->usercontainer, &max_no, 0);
04701 if (!ast_test_flag64(&user->userflags, CONFFLAG_ADMIN))
04702 user->adminflags |= ADMINFLAG_KICKME;
04703 else {
04704 res = -1;
04705 ast_log(LOG_NOTICE, "Not kicking last user, is an Admin!\n");
04706 }
04707 ao2_ref(user, -1);
04708 break;
04709 }
04710 case 77:
04711 user->adminflags |= ADMINFLAG_MUTED;
04712 break;
04713 case 78:
04714 ao2_callback(cnf->usercontainer, OBJ_NODATA, user_set_muted_cb, &cnf);
04715 break;
04716 case 109:
04717 user->adminflags &= ~(ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED | ADMINFLAG_T_REQUEST);
04718 break;
04719 case 110:
04720 ao2_callback(cnf->usercontainer, OBJ_NODATA, user_set_unmuted_cb, NULL);
04721 break;
04722 case 107:
04723 user->adminflags |= ADMINFLAG_KICKME;
04724 break;
04725 case 118:
04726 ao2_callback(cnf->usercontainer, OBJ_NODATA, user_listen_voldown_cb, NULL);
04727 break;
04728 case 86:
04729 ao2_callback(cnf->usercontainer, OBJ_NODATA, user_listen_volup_cb, NULL);
04730 break;
04731 case 115:
04732 ao2_callback(cnf->usercontainer, OBJ_NODATA, user_talk_voldown_cb, NULL);
04733 break;
04734 case 83:
04735 ao2_callback(cnf->usercontainer, OBJ_NODATA, user_talk_volup_cb, NULL);
04736 break;
04737 case 82:
04738 ao2_callback(cnf->usercontainer, OBJ_NODATA, user_reset_vol_cb, NULL);
04739 break;
04740 case 114:
04741 reset_volumes(user);
04742 break;
04743 case 85:
04744 tweak_listen_volume(user, VOL_UP);
04745 break;
04746 case 117:
04747 tweak_listen_volume(user, VOL_DOWN);
04748 break;
04749 case 84:
04750 tweak_talk_volume(user, VOL_UP);
04751 break;
04752 case 116:
04753 tweak_talk_volume(user, VOL_DOWN);
04754 break;
04755 case 'E':
04756 if (rt_extend_conf(args.confno)) {
04757 res = -1;
04758 }
04759 break;
04760 }
04761
04762 if (args.user) {
04763
04764 ao2_ref(user, -1);
04765 }
04766 usernotfound:
04767 AST_LIST_UNLOCK(&confs);
04768
04769 dispose_conf(cnf);
04770 pbx_builtin_setvar_helper(chan, "MEETMEADMINSTATUS", res == -2 ? "NOTFOUND" : res ? "FAILED" : "OK");
04771
04772 return 0;
04773 }
04774
04775
04776
04777 static int channel_admin_exec(struct ast_channel *chan, const char *data) {
04778 char *params;
04779 struct ast_conference *conf = NULL;
04780 struct ast_conf_user *user = NULL;
04781 AST_DECLARE_APP_ARGS(args,
04782 AST_APP_ARG(channel);
04783 AST_APP_ARG(command);
04784 );
04785
04786 if (ast_strlen_zero(data)) {
04787 ast_log(LOG_WARNING, "MeetMeChannelAdmin requires two arguments!\n");
04788 return -1;
04789 }
04790
04791 params = ast_strdupa(data);
04792 AST_STANDARD_APP_ARGS(args, params);
04793
04794 if (!args.channel) {
04795 ast_log(LOG_WARNING, "MeetMeChannelAdmin requires a channel name!\n");
04796 return -1;
04797 }
04798
04799 if (!args.command) {
04800 ast_log(LOG_WARNING, "MeetMeChannelAdmin requires a command!\n");
04801 return -1;
04802 }
04803
04804 AST_LIST_LOCK(&confs);
04805 AST_LIST_TRAVERSE(&confs, conf, list) {
04806 if ((user = ao2_callback(conf->usercontainer, 0, user_chan_cb, args.channel))) {
04807 break;
04808 }
04809 }
04810
04811 if (!user) {
04812 ast_log(LOG_NOTICE, "Specified user (%s) not found\n", args.channel);
04813 AST_LIST_UNLOCK(&confs);
04814 return 0;
04815 }
04816
04817
04818 switch (*args.command) {
04819 case 77:
04820 user->adminflags |= ADMINFLAG_MUTED;
04821 break;
04822 case 109:
04823 user->adminflags &= ~ADMINFLAG_MUTED;
04824 break;
04825 case 107:
04826 user->adminflags |= ADMINFLAG_KICKME;
04827 break;
04828 default:
04829 ast_log(LOG_WARNING, "Unknown MeetMeChannelAdmin command '%s'\n", args.command);
04830 break;
04831 }
04832 ao2_ref(user, -1);
04833 AST_LIST_UNLOCK(&confs);
04834
04835 return 0;
04836 }
04837
04838 static int meetmemute(struct mansession *s, const struct message *m, int mute)
04839 {
04840 struct ast_conference *conf;
04841 struct ast_conf_user *user;
04842 const char *confid = astman_get_header(m, "Meetme");
04843 char *userid = ast_strdupa(astman_get_header(m, "Usernum"));
04844 int userno;
04845
04846 if (ast_strlen_zero(confid)) {
04847 astman_send_error(s, m, "Meetme conference not specified");
04848 return 0;
04849 }
04850
04851 if (ast_strlen_zero(userid)) {
04852 astman_send_error(s, m, "Meetme user number not specified");
04853 return 0;
04854 }
04855
04856 userno = strtoul(userid, &userid, 10);
04857
04858 if (*userid) {
04859 astman_send_error(s, m, "Invalid user number");
04860 return 0;
04861 }
04862
04863
04864 AST_LIST_LOCK(&confs);
04865 AST_LIST_TRAVERSE(&confs, conf, list) {
04866 if (!strcmp(confid, conf->confno))
04867 break;
04868 }
04869
04870 if (!conf) {
04871 AST_LIST_UNLOCK(&confs);
04872 astman_send_error(s, m, "Meetme conference does not exist");
04873 return 0;
04874 }
04875
04876 user = ao2_find(conf->usercontainer, &userno, 0);
04877
04878 if (!user) {
04879 AST_LIST_UNLOCK(&confs);
04880 astman_send_error(s, m, "User number not found");
04881 return 0;
04882 }
04883
04884 if (mute)
04885 user->adminflags |= ADMINFLAG_MUTED;
04886 else
04887 user->adminflags &= ~(ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED | ADMINFLAG_T_REQUEST);
04888
04889 AST_LIST_UNLOCK(&confs);
04890
04891 ast_log(LOG_NOTICE, "Requested to %smute conf %s user %d userchan %s uniqueid %s\n", mute ? "" : "un", conf->confno, user->user_no, user->chan->name, user->chan->uniqueid);
04892
04893 ao2_ref(user, -1);
04894 astman_send_ack(s, m, mute ? "User muted" : "User unmuted");
04895 return 0;
04896 }
04897
04898 static int action_meetmemute(struct mansession *s, const struct message *m)
04899 {
04900 return meetmemute(s, m, 1);
04901 }
04902
04903 static int action_meetmeunmute(struct mansession *s, const struct message *m)
04904 {
04905 return meetmemute(s, m, 0);
04906 }
04907
04908 static int action_meetmelist(struct mansession *s, const struct message *m)
04909 {
04910 const char *actionid = astman_get_header(m, "ActionID");
04911 const char *conference = astman_get_header(m, "Conference");
04912 char idText[80] = "";
04913 struct ast_conference *cnf;
04914 struct ast_conf_user *user;
04915 struct ao2_iterator user_iter;
04916 int total = 0;
04917
04918 if (!ast_strlen_zero(actionid))
04919 snprintf(idText, sizeof(idText), "ActionID: %s\r\n", actionid);
04920
04921 if (AST_LIST_EMPTY(&confs)) {
04922 astman_send_error(s, m, "No active conferences.");
04923 return 0;
04924 }
04925
04926 astman_send_listack(s, m, "Meetme user list will follow", "start");
04927
04928
04929 AST_LIST_LOCK(&confs);
04930 AST_LIST_TRAVERSE(&confs, cnf, list) {
04931
04932 if (!ast_strlen_zero(conference) && strcmp(cnf->confno, conference))
04933 continue;
04934
04935
04936 user_iter = ao2_iterator_init(cnf->usercontainer, 0);
04937 while ((user = ao2_iterator_next(&user_iter))) {
04938 total++;
04939 astman_append(s,
04940 "Event: MeetmeList\r\n"
04941 "%s"
04942 "Conference: %s\r\n"
04943 "UserNumber: %d\r\n"
04944 "CallerIDNum: %s\r\n"
04945 "CallerIDName: %s\r\n"
04946 "ConnectedLineNum: %s\r\n"
04947 "ConnectedLineName: %s\r\n"
04948 "Channel: %s\r\n"
04949 "Admin: %s\r\n"
04950 "Role: %s\r\n"
04951 "MarkedUser: %s\r\n"
04952 "Muted: %s\r\n"
04953 "Talking: %s\r\n"
04954 "\r\n",
04955 idText,
04956 cnf->confno,
04957 user->user_no,
04958 S_COR(user->chan->caller.id.number.valid, user->chan->caller.id.number.str, "<unknown>"),
04959 S_COR(user->chan->caller.id.name.valid, user->chan->caller.id.name.str, "<no name>"),
04960 S_COR(user->chan->connected.id.number.valid, user->chan->connected.id.number.str, "<unknown>"),
04961 S_COR(user->chan->connected.id.name.valid, user->chan->connected.id.name.str, "<no name>"),
04962 user->chan->name,
04963 ast_test_flag64(&user->userflags, CONFFLAG_ADMIN) ? "Yes" : "No",
04964 ast_test_flag64(&user->userflags, CONFFLAG_MONITOR) ? "Listen only" : ast_test_flag64(&user->userflags, CONFFLAG_TALKER) ? "Talk only" : "Talk and listen",
04965 ast_test_flag64(&user->userflags, CONFFLAG_MARKEDUSER) ? "Yes" : "No",
04966 user->adminflags & ADMINFLAG_MUTED ? "By admin" : user->adminflags & ADMINFLAG_SELFMUTED ? "By self" : "No",
04967 user->talking > 0 ? "Yes" : user->talking == 0 ? "No" : "Not monitored");
04968 ao2_ref(user, -1);
04969 }
04970 ao2_iterator_destroy(&user_iter);
04971 }
04972 AST_LIST_UNLOCK(&confs);
04973
04974 astman_append(s,
04975 "Event: MeetmeListComplete\r\n"
04976 "EventList: Complete\r\n"
04977 "ListItems: %d\r\n"
04978 "%s"
04979 "\r\n", total, idText);
04980 return 0;
04981 }
04982
04983
04984
04985
04986
04987
04988
04989 static void filename_parse(char *filename, char *buffer)
04990 {
04991 char *slash;
04992 if (ast_strlen_zero(filename)) {
04993 ast_log(LOG_WARNING, "No file name was provided for a file save option.\n");
04994 } else if (filename[0] != '/') {
04995 snprintf(buffer, PATH_MAX, "%s/meetme/%s", ast_config_AST_SPOOL_DIR, filename);
04996 } else {
04997 ast_copy_string(buffer, filename, PATH_MAX);
04998 }
04999
05000 slash = buffer;
05001 if ((slash = strrchr(slash, '/'))) {
05002 *slash = '\0';
05003 ast_mkdir(buffer, 0777);
05004 *slash = '/';
05005 }
05006 }
05007
05008 static void *recordthread(void *args)
05009 {
05010 struct ast_conference *cnf = args;
05011 struct ast_frame *f = NULL;
05012 int flags;
05013 struct ast_filestream *s = NULL;
05014 int res = 0;
05015 int x;
05016 const char *oldrecordingfilename = NULL;
05017 char filename_buffer[PATH_MAX];
05018
05019 if (!cnf || !cnf->lchan) {
05020 pthread_exit(0);
05021 }
05022
05023 filename_buffer[0] = '\0';
05024 filename_parse(cnf->recordingfilename, filename_buffer);
05025
05026 ast_stopstream(cnf->lchan);
05027 flags = O_CREAT | O_TRUNC | O_WRONLY;
05028
05029
05030 cnf->recording = MEETME_RECORD_ACTIVE;
05031 while (ast_waitfor(cnf->lchan, -1) > -1) {
05032 if (cnf->recording == MEETME_RECORD_TERMINATE) {
05033 AST_LIST_LOCK(&confs);
05034 AST_LIST_UNLOCK(&confs);
05035 break;
05036 }
05037 if (!s && !(ast_strlen_zero(filename_buffer)) && (filename_buffer != oldrecordingfilename)) {
05038 s = ast_writefile(filename_buffer, cnf->recordingformat, NULL, flags, 0, AST_FILE_MODE);
05039 oldrecordingfilename = filename_buffer;
05040 }
05041
05042 f = ast_read(cnf->lchan);
05043 if (!f) {
05044 res = -1;
05045 break;
05046 }
05047 if (f->frametype == AST_FRAME_VOICE) {
05048 ast_mutex_lock(&cnf->listenlock);
05049 for (x = 0; x < AST_FRAME_BITS; x++) {
05050
05051 if (cnf->transframe[x]) {
05052 ast_frfree(cnf->transframe[x]);
05053 cnf->transframe[x] = NULL;
05054 }
05055 }
05056 if (cnf->origframe)
05057 ast_frfree(cnf->origframe);
05058 cnf->origframe = ast_frdup(f);
05059 ast_mutex_unlock(&cnf->listenlock);
05060 if (s)
05061 res = ast_writestream(s, f);
05062 if (res) {
05063 ast_frfree(f);
05064 break;
05065 }
05066 }
05067 ast_frfree(f);
05068 }
05069 cnf->recording = MEETME_RECORD_OFF;
05070 if (s)
05071 ast_closestream(s);
05072
05073 pthread_exit(0);
05074 }
05075
05076
05077 static enum ast_device_state meetmestate(const char *data)
05078 {
05079 struct ast_conference *conf;
05080
05081
05082 AST_LIST_LOCK(&confs);
05083 AST_LIST_TRAVERSE(&confs, conf, list) {
05084 if (!strcmp(data, conf->confno))
05085 break;
05086 }
05087 AST_LIST_UNLOCK(&confs);
05088 if (!conf)
05089 return AST_DEVICE_INVALID;
05090
05091
05092
05093 if (!conf->users)
05094 return AST_DEVICE_NOT_INUSE;
05095
05096 return AST_DEVICE_INUSE;
05097 }
05098
05099 static void load_config_meetme(void)
05100 {
05101 struct ast_config *cfg;
05102 struct ast_flags config_flags = { 0 };
05103 const char *val;
05104
05105 if (!(cfg = ast_config_load(CONFIG_FILE_NAME, config_flags))) {
05106 return;
05107 } else if (cfg == CONFIG_STATUS_FILEINVALID) {
05108 ast_log(LOG_ERROR, "Config file " CONFIG_FILE_NAME " is in an invalid format. Aborting.\n");
05109 return;
05110 }
05111
05112 audio_buffers = DEFAULT_AUDIO_BUFFERS;
05113
05114
05115 rt_schedule = 0;
05116 fuzzystart = 0;
05117 earlyalert = 0;
05118 endalert = 0;
05119 extendby = 0;
05120
05121
05122 rt_log_members = 1;
05123
05124 if ((val = ast_variable_retrieve(cfg, "general", "audiobuffers"))) {
05125 if ((sscanf(val, "%30d", &audio_buffers) != 1)) {
05126 ast_log(LOG_WARNING, "audiobuffers setting must be a number, not '%s'\n", val);
05127 audio_buffers = DEFAULT_AUDIO_BUFFERS;
05128 } else if ((audio_buffers < DAHDI_DEFAULT_NUM_BUFS) || (audio_buffers > DAHDI_MAX_NUM_BUFS)) {
05129 ast_log(LOG_WARNING, "audiobuffers setting must be between %d and %d\n",
05130 DAHDI_DEFAULT_NUM_BUFS, DAHDI_MAX_NUM_BUFS);
05131 audio_buffers = DEFAULT_AUDIO_BUFFERS;
05132 }
05133 if (audio_buffers != DEFAULT_AUDIO_BUFFERS)
05134 ast_log(LOG_NOTICE, "Audio buffers per channel set to %d\n", audio_buffers);
05135 }
05136
05137 if ((val = ast_variable_retrieve(cfg, "general", "schedule")))
05138 rt_schedule = ast_true(val);
05139 if ((val = ast_variable_retrieve(cfg, "general", "logmembercount")))
05140 rt_log_members = ast_true(val);
05141 if ((val = ast_variable_retrieve(cfg, "general", "fuzzystart"))) {
05142 if ((sscanf(val, "%30d", &fuzzystart) != 1)) {
05143 ast_log(LOG_WARNING, "fuzzystart must be a number, not '%s'\n", val);
05144 fuzzystart = 0;
05145 }
05146 }
05147 if ((val = ast_variable_retrieve(cfg, "general", "earlyalert"))) {
05148 if ((sscanf(val, "%30d", &earlyalert) != 1)) {
05149 ast_log(LOG_WARNING, "earlyalert must be a number, not '%s'\n", val);
05150 earlyalert = 0;
05151 }
05152 }
05153 if ((val = ast_variable_retrieve(cfg, "general", "endalert"))) {
05154 if ((sscanf(val, "%30d", &endalert) != 1)) {
05155 ast_log(LOG_WARNING, "endalert must be a number, not '%s'\n", val);
05156 endalert = 0;
05157 }
05158 }
05159 if ((val = ast_variable_retrieve(cfg, "general", "extendby"))) {
05160 if ((sscanf(val, "%30d", &extendby) != 1)) {
05161 ast_log(LOG_WARNING, "extendby must be a number, not '%s'\n", val);
05162 extendby = 0;
05163 }
05164 }
05165
05166 ast_config_destroy(cfg);
05167 }
05168
05169
05170
05171
05172 static struct sla_trunk *sla_find_trunk(const char *name)
05173 {
05174 struct sla_trunk *trunk = NULL;
05175
05176 AST_RWLIST_TRAVERSE(&sla_trunks, trunk, entry) {
05177 if (!strcasecmp(trunk->name, name))
05178 break;
05179 }
05180
05181 return trunk;
05182 }
05183
05184
05185
05186
05187 static struct sla_station *sla_find_station(const char *name)
05188 {
05189 struct sla_station *station = NULL;
05190
05191 AST_RWLIST_TRAVERSE(&sla_stations, station, entry) {
05192 if (!strcasecmp(station->name, name))
05193 break;
05194 }
05195
05196 return station;
05197 }
05198
05199 static int sla_check_station_hold_access(const struct sla_trunk *trunk,
05200 const struct sla_station *station)
05201 {
05202 struct sla_station_ref *station_ref;
05203 struct sla_trunk_ref *trunk_ref;
05204
05205
05206 AST_LIST_TRAVERSE(&trunk->stations, station_ref, entry) {
05207 AST_LIST_TRAVERSE(&station_ref->station->trunks, trunk_ref, entry) {
05208 if (trunk_ref->trunk != trunk || station_ref->station == station)
05209 continue;
05210 if (trunk_ref->state == SLA_TRUNK_STATE_ONHOLD_BYME &&
05211 station_ref->station->hold_access == SLA_HOLD_PRIVATE)
05212 return 1;
05213 return 0;
05214 }
05215 }
05216
05217 return 0;
05218 }
05219
05220
05221
05222
05223
05224
05225
05226
05227 static struct sla_trunk_ref *sla_find_trunk_ref_byname(const struct sla_station *station,
05228 const char *name)
05229 {
05230 struct sla_trunk_ref *trunk_ref = NULL;
05231
05232 AST_LIST_TRAVERSE(&station->trunks, trunk_ref, entry) {
05233 if (strcasecmp(trunk_ref->trunk->name, name))
05234 continue;
05235
05236 if ( (trunk_ref->trunk->barge_disabled
05237 && trunk_ref->state == SLA_TRUNK_STATE_UP) ||
05238 (trunk_ref->trunk->hold_stations
05239 && trunk_ref->trunk->hold_access == SLA_HOLD_PRIVATE
05240 && trunk_ref->state != SLA_TRUNK_STATE_ONHOLD_BYME) ||
05241 sla_check_station_hold_access(trunk_ref->trunk, station) )
05242 {
05243 trunk_ref = NULL;
05244 }
05245
05246 break;
05247 }
05248
05249 return trunk_ref;
05250 }
05251
05252 static struct sla_station_ref *sla_create_station_ref(struct sla_station *station)
05253 {
05254 struct sla_station_ref *station_ref;
05255
05256 if (!(station_ref = ast_calloc(1, sizeof(*station_ref))))
05257 return NULL;
05258
05259 station_ref->station = station;
05260
05261 return station_ref;
05262 }
05263
05264 static struct sla_ringing_station *sla_create_ringing_station(struct sla_station *station)
05265 {
05266 struct sla_ringing_station *ringing_station;
05267
05268 if (!(ringing_station = ast_calloc(1, sizeof(*ringing_station))))
05269 return NULL;
05270
05271 ringing_station->station = station;
05272 ringing_station->ring_begin = ast_tvnow();
05273
05274 return ringing_station;
05275 }
05276
05277 static enum ast_device_state sla_state_to_devstate(enum sla_trunk_state state)
05278 {
05279 switch (state) {
05280 case SLA_TRUNK_STATE_IDLE:
05281 return AST_DEVICE_NOT_INUSE;
05282 case SLA_TRUNK_STATE_RINGING:
05283 return AST_DEVICE_RINGING;
05284 case SLA_TRUNK_STATE_UP:
05285 return AST_DEVICE_INUSE;
05286 case SLA_TRUNK_STATE_ONHOLD:
05287 case SLA_TRUNK_STATE_ONHOLD_BYME:
05288 return AST_DEVICE_ONHOLD;
05289 }
05290
05291 return AST_DEVICE_UNKNOWN;
05292 }
05293
05294 static void sla_change_trunk_state(const struct sla_trunk *trunk, enum sla_trunk_state state,
05295 enum sla_which_trunk_refs inactive_only, const struct sla_trunk_ref *exclude)
05296 {
05297 struct sla_station *station;
05298 struct sla_trunk_ref *trunk_ref;
05299
05300 AST_LIST_TRAVERSE(&sla_stations, station, entry) {
05301 AST_LIST_TRAVERSE(&station->trunks, trunk_ref, entry) {
05302 if (trunk_ref->trunk != trunk || (inactive_only ? trunk_ref->chan : 0)
05303 || trunk_ref == exclude)
05304 continue;
05305 trunk_ref->state = state;
05306 ast_devstate_changed(sla_state_to_devstate(state), AST_DEVSTATE_CACHABLE,
05307 "SLA:%s_%s", station->name, trunk->name);
05308 break;
05309 }
05310 }
05311 }
05312
05313 struct run_station_args {
05314 struct sla_station *station;
05315 struct sla_trunk_ref *trunk_ref;
05316 ast_mutex_t *cond_lock;
05317 ast_cond_t *cond;
05318 };
05319
05320 static void answer_trunk_chan(struct ast_channel *chan)
05321 {
05322 ast_answer(chan);
05323 ast_indicate(chan, -1);
05324 }
05325
05326 static void *run_station(void *data)
05327 {
05328 struct sla_station *station;
05329 struct sla_trunk_ref *trunk_ref;
05330 struct ast_str *conf_name = ast_str_create(16);
05331 struct ast_flags64 conf_flags = { 0 };
05332 struct ast_conference *conf;
05333
05334 {
05335 struct run_station_args *args = data;
05336 station = args->station;
05337 trunk_ref = args->trunk_ref;
05338 ast_mutex_lock(args->cond_lock);
05339 ast_cond_signal(args->cond);
05340 ast_mutex_unlock(args->cond_lock);
05341
05342 }
05343
05344 ast_atomic_fetchadd_int((int *) &trunk_ref->trunk->active_stations, 1);
05345 ast_str_set(&conf_name, 0, "SLA_%s", trunk_ref->trunk->name);
05346 ast_set_flag64(&conf_flags,
05347 CONFFLAG_QUIET | CONFFLAG_MARKEDEXIT | CONFFLAG_PASS_DTMF | CONFFLAG_SLA_STATION);
05348 answer_trunk_chan(trunk_ref->chan);
05349 conf = build_conf(ast_str_buffer(conf_name), "", "", 0, 0, 1, trunk_ref->chan, NULL);
05350 if (conf) {
05351 conf_run(trunk_ref->chan, conf, &conf_flags, NULL);
05352 dispose_conf(conf);
05353 conf = NULL;
05354 }
05355 trunk_ref->chan = NULL;
05356 if (ast_atomic_dec_and_test((int *) &trunk_ref->trunk->active_stations) &&
05357 trunk_ref->state != SLA_TRUNK_STATE_ONHOLD_BYME) {
05358 ast_str_append(&conf_name, 0, ",K");
05359 admin_exec(NULL, ast_str_buffer(conf_name));
05360 trunk_ref->trunk->hold_stations = 0;
05361 sla_change_trunk_state(trunk_ref->trunk, SLA_TRUNK_STATE_IDLE, ALL_TRUNK_REFS, NULL);
05362 }
05363
05364 ast_dial_join(station->dial);
05365 ast_dial_destroy(station->dial);
05366 station->dial = NULL;
05367 ast_free(conf_name);
05368
05369 return NULL;
05370 }
05371
05372 static void sla_stop_ringing_trunk(struct sla_ringing_trunk *ringing_trunk)
05373 {
05374 char buf[80];
05375 struct sla_station_ref *station_ref;
05376
05377 snprintf(buf, sizeof(buf), "SLA_%s,K", ringing_trunk->trunk->name);
05378 admin_exec(NULL, buf);
05379 sla_change_trunk_state(ringing_trunk->trunk, SLA_TRUNK_STATE_IDLE, ALL_TRUNK_REFS, NULL);
05380
05381 while ((station_ref = AST_LIST_REMOVE_HEAD(&ringing_trunk->timed_out_stations, entry)))
05382 ast_free(station_ref);
05383
05384 ast_free(ringing_trunk);
05385 }
05386
05387 static void sla_stop_ringing_station(struct sla_ringing_station *ringing_station,
05388 enum sla_station_hangup hangup)
05389 {
05390 struct sla_ringing_trunk *ringing_trunk;
05391 struct sla_trunk_ref *trunk_ref;
05392 struct sla_station_ref *station_ref;
05393
05394 ast_dial_join(ringing_station->station->dial);
05395 ast_dial_destroy(ringing_station->station->dial);
05396 ringing_station->station->dial = NULL;
05397
05398 if (hangup == SLA_STATION_HANGUP_NORMAL)
05399 goto done;
05400
05401
05402
05403
05404
05405
05406 AST_LIST_TRAVERSE(&sla.ringing_trunks, ringing_trunk, entry) {
05407 AST_LIST_TRAVERSE(&ringing_station->station->trunks, trunk_ref, entry) {
05408 if (ringing_trunk->trunk == trunk_ref->trunk)
05409 break;
05410 }
05411 if (!trunk_ref)
05412 continue;
05413 if (!(station_ref = sla_create_station_ref(ringing_station->station)))
05414 continue;
05415 AST_LIST_INSERT_TAIL(&ringing_trunk->timed_out_stations, station_ref, entry);
05416 }
05417
05418 done:
05419 ast_free(ringing_station);
05420 }
05421
05422 static void sla_dial_state_callback(struct ast_dial *dial)
05423 {
05424 sla_queue_event(SLA_EVENT_DIAL_STATE);
05425 }
05426
05427
05428
05429
05430 static int sla_check_timed_out_station(const struct sla_ringing_trunk *ringing_trunk,
05431 const struct sla_station *station)
05432 {
05433 struct sla_station_ref *timed_out_station;
05434
05435 AST_LIST_TRAVERSE(&ringing_trunk->timed_out_stations, timed_out_station, entry) {
05436 if (station == timed_out_station->station)
05437 return 1;
05438 }
05439
05440 return 0;
05441 }
05442
05443
05444
05445
05446
05447
05448
05449
05450
05451 static struct sla_ringing_trunk *sla_choose_ringing_trunk(struct sla_station *station,
05452 struct sla_trunk_ref **trunk_ref, int rm)
05453 {
05454 struct sla_trunk_ref *s_trunk_ref;
05455 struct sla_ringing_trunk *ringing_trunk = NULL;
05456
05457 AST_LIST_TRAVERSE(&station->trunks, s_trunk_ref, entry) {
05458 AST_LIST_TRAVERSE_SAFE_BEGIN(&sla.ringing_trunks, ringing_trunk, entry) {
05459
05460 if (s_trunk_ref->trunk != ringing_trunk->trunk)
05461 continue;
05462
05463
05464
05465 if (sla_check_timed_out_station(ringing_trunk, station))
05466 continue;
05467
05468 if (rm)
05469 AST_LIST_REMOVE_CURRENT(entry);
05470
05471 if (trunk_ref)
05472 *trunk_ref = s_trunk_ref;
05473
05474 break;
05475 }
05476 AST_LIST_TRAVERSE_SAFE_END;
05477
05478 if (ringing_trunk)
05479 break;
05480 }
05481
05482 return ringing_trunk;
05483 }
05484
05485 static void sla_handle_dial_state_event(void)
05486 {
05487 struct sla_ringing_station *ringing_station;
05488
05489 AST_LIST_TRAVERSE_SAFE_BEGIN(&sla.ringing_stations, ringing_station, entry) {
05490 struct sla_trunk_ref *s_trunk_ref = NULL;
05491 struct sla_ringing_trunk *ringing_trunk = NULL;
05492 struct run_station_args args;
05493 enum ast_dial_result dial_res;
05494 pthread_t dont_care;
05495 ast_mutex_t cond_lock;
05496 ast_cond_t cond;
05497
05498 switch ((dial_res = ast_dial_state(ringing_station->station->dial))) {
05499 case AST_DIAL_RESULT_HANGUP:
05500 case AST_DIAL_RESULT_INVALID:
05501 case AST_DIAL_RESULT_FAILED:
05502 case AST_DIAL_RESULT_TIMEOUT:
05503 case AST_DIAL_RESULT_UNANSWERED:
05504 AST_LIST_REMOVE_CURRENT(entry);
05505 sla_stop_ringing_station(ringing_station, SLA_STATION_HANGUP_NORMAL);
05506 break;
05507 case AST_DIAL_RESULT_ANSWERED:
05508 AST_LIST_REMOVE_CURRENT(entry);
05509
05510 ast_mutex_lock(&sla.lock);
05511 ringing_trunk = sla_choose_ringing_trunk(ringing_station->station, &s_trunk_ref, 1);
05512 ast_mutex_unlock(&sla.lock);
05513 if (!ringing_trunk) {
05514 ast_debug(1, "Found no ringing trunk for station '%s' to answer!\n", ringing_station->station->name);
05515 break;
05516 }
05517
05518 s_trunk_ref->chan = ast_dial_answered(ringing_station->station->dial);
05519
05520 answer_trunk_chan(ringing_trunk->trunk->chan);
05521 sla_change_trunk_state(ringing_trunk->trunk, SLA_TRUNK_STATE_UP, ALL_TRUNK_REFS, NULL);
05522
05523
05524
05525 args.trunk_ref = s_trunk_ref;
05526 args.station = ringing_station->station;
05527 args.cond = &cond;
05528 args.cond_lock = &cond_lock;
05529 ast_free(ringing_trunk);
05530 ast_free(ringing_station);
05531 ast_mutex_init(&cond_lock);
05532 ast_cond_init(&cond, NULL);
05533 ast_mutex_lock(&cond_lock);
05534 ast_pthread_create_detached_background(&dont_care, NULL, run_station, &args);
05535 ast_cond_wait(&cond, &cond_lock);
05536 ast_mutex_unlock(&cond_lock);
05537 ast_mutex_destroy(&cond_lock);
05538 ast_cond_destroy(&cond);
05539 break;
05540 case AST_DIAL_RESULT_TRYING:
05541 case AST_DIAL_RESULT_RINGING:
05542 case AST_DIAL_RESULT_PROGRESS:
05543 case AST_DIAL_RESULT_PROCEEDING:
05544 break;
05545 }
05546 if (dial_res == AST_DIAL_RESULT_ANSWERED) {
05547
05548 sla_queue_event(SLA_EVENT_RINGING_TRUNK);
05549 sla_queue_event(SLA_EVENT_DIAL_STATE);
05550 break;
05551 }
05552 }
05553 AST_LIST_TRAVERSE_SAFE_END;
05554 }
05555
05556
05557
05558
05559 static int sla_check_ringing_station(const struct sla_station *station)
05560 {
05561 struct sla_ringing_station *ringing_station;
05562
05563 AST_LIST_TRAVERSE(&sla.ringing_stations, ringing_station, entry) {
05564 if (station == ringing_station->station)
05565 return 1;
05566 }
05567
05568 return 0;
05569 }
05570
05571
05572
05573
05574 static int sla_check_failed_station(const struct sla_station *station)
05575 {
05576 struct sla_failed_station *failed_station;
05577 int res = 0;
05578
05579 AST_LIST_TRAVERSE_SAFE_BEGIN(&sla.failed_stations, failed_station, entry) {
05580 if (station != failed_station->station)
05581 continue;
05582 if (ast_tvdiff_ms(ast_tvnow(), failed_station->last_try) > 1000) {
05583 AST_LIST_REMOVE_CURRENT(entry);
05584 ast_free(failed_station);
05585 break;
05586 }
05587 res = 1;
05588 }
05589 AST_LIST_TRAVERSE_SAFE_END
05590
05591 return res;
05592 }
05593
05594
05595
05596
05597 static int sla_ring_station(struct sla_ringing_trunk *ringing_trunk, struct sla_station *station)
05598 {
05599 char *tech, *tech_data;
05600 struct ast_dial *dial;
05601 struct sla_ringing_station *ringing_station;
05602 enum ast_dial_result res;
05603 int caller_is_saved;
05604 struct ast_party_caller caller;
05605
05606 if (!(dial = ast_dial_create()))
05607 return -1;
05608
05609 ast_dial_set_state_callback(dial, sla_dial_state_callback);
05610 tech_data = ast_strdupa(station->device);
05611 tech = strsep(&tech_data, "/");
05612
05613 if (ast_dial_append(dial, tech, tech_data) == -1) {
05614 ast_dial_destroy(dial);
05615 return -1;
05616 }
05617
05618
05619 caller_is_saved = 0;
05620 if (!sla.attempt_callerid) {
05621 caller_is_saved = 1;
05622 caller = ringing_trunk->trunk->chan->caller;
05623 ast_party_caller_init(&ringing_trunk->trunk->chan->caller);
05624 }
05625
05626 res = ast_dial_run(dial, ringing_trunk->trunk->chan, 1);
05627
05628
05629 if (caller_is_saved) {
05630 ast_party_caller_free(&ringing_trunk->trunk->chan->caller);
05631 ringing_trunk->trunk->chan->caller = caller;
05632 }
05633
05634 if (res != AST_DIAL_RESULT_TRYING) {
05635 struct sla_failed_station *failed_station;
05636 ast_dial_destroy(dial);
05637 if (!(failed_station = ast_calloc(1, sizeof(*failed_station))))
05638 return -1;
05639 failed_station->station = station;
05640 failed_station->last_try = ast_tvnow();
05641 AST_LIST_INSERT_HEAD(&sla.failed_stations, failed_station, entry);
05642 return -1;
05643 }
05644 if (!(ringing_station = sla_create_ringing_station(station))) {
05645 ast_dial_join(dial);
05646 ast_dial_destroy(dial);
05647 return -1;
05648 }
05649
05650 station->dial = dial;
05651
05652 AST_LIST_INSERT_HEAD(&sla.ringing_stations, ringing_station, entry);
05653
05654 return 0;
05655 }
05656
05657
05658
05659 static int sla_check_inuse_station(const struct sla_station *station)
05660 {
05661 struct sla_trunk_ref *trunk_ref;
05662
05663 AST_LIST_TRAVERSE(&station->trunks, trunk_ref, entry) {
05664 if (trunk_ref->chan)
05665 return 1;
05666 }
05667
05668 return 0;
05669 }
05670
05671 static struct sla_trunk_ref *sla_find_trunk_ref(const struct sla_station *station,
05672 const struct sla_trunk *trunk)
05673 {
05674 struct sla_trunk_ref *trunk_ref = NULL;
05675
05676 AST_LIST_TRAVERSE(&station->trunks, trunk_ref, entry) {
05677 if (trunk_ref->trunk == trunk)
05678 break;
05679 }
05680
05681 return trunk_ref;
05682 }
05683
05684
05685
05686
05687
05688
05689 static int sla_check_station_delay(struct sla_station *station,
05690 struct sla_ringing_trunk *ringing_trunk)
05691 {
05692 struct sla_trunk_ref *trunk_ref;
05693 unsigned int delay = UINT_MAX;
05694 int time_left, time_elapsed;
05695
05696 if (!ringing_trunk)
05697 ringing_trunk = sla_choose_ringing_trunk(station, &trunk_ref, 0);
05698 else
05699 trunk_ref = sla_find_trunk_ref(station, ringing_trunk->trunk);
05700
05701 if (!ringing_trunk || !trunk_ref)
05702 return delay;
05703
05704
05705
05706
05707 delay = trunk_ref->ring_delay;
05708 if (!delay)
05709 delay = station->ring_delay;
05710 if (!delay)
05711 return INT_MAX;
05712
05713 time_elapsed = ast_tvdiff_ms(ast_tvnow(), ringing_trunk->ring_begin);
05714 time_left = (delay * 1000) - time_elapsed;
05715
05716 return time_left;
05717 }
05718
05719
05720
05721
05722 static void sla_ring_stations(void)
05723 {
05724 struct sla_station_ref *station_ref;
05725 struct sla_ringing_trunk *ringing_trunk;
05726
05727
05728
05729 AST_LIST_TRAVERSE(&sla.ringing_trunks, ringing_trunk, entry) {
05730 AST_LIST_TRAVERSE(&ringing_trunk->trunk->stations, station_ref, entry) {
05731 int time_left;
05732
05733
05734 if (sla_check_ringing_station(station_ref->station))
05735 continue;
05736
05737
05738 if (sla_check_inuse_station(station_ref->station))
05739 continue;
05740
05741
05742
05743 if (sla_check_failed_station(station_ref->station))
05744 continue;
05745
05746
05747
05748 if (sla_check_timed_out_station(ringing_trunk, station_ref->station))
05749 continue;
05750
05751
05752 time_left = sla_check_station_delay(station_ref->station, ringing_trunk);
05753 if (time_left != INT_MAX && time_left > 0)
05754 continue;
05755
05756
05757 sla_ring_station(ringing_trunk, station_ref->station);
05758 }
05759 }
05760
05761 }
05762
05763 static void sla_hangup_stations(void)
05764 {
05765 struct sla_trunk_ref *trunk_ref;
05766 struct sla_ringing_station *ringing_station;
05767
05768 AST_LIST_TRAVERSE_SAFE_BEGIN(&sla.ringing_stations, ringing_station, entry) {
05769 AST_LIST_TRAVERSE(&ringing_station->station->trunks, trunk_ref, entry) {
05770 struct sla_ringing_trunk *ringing_trunk;
05771 ast_mutex_lock(&sla.lock);
05772 AST_LIST_TRAVERSE(&sla.ringing_trunks, ringing_trunk, entry) {
05773 if (trunk_ref->trunk == ringing_trunk->trunk)
05774 break;
05775 }
05776 ast_mutex_unlock(&sla.lock);
05777 if (ringing_trunk)
05778 break;
05779 }
05780 if (!trunk_ref) {
05781 AST_LIST_REMOVE_CURRENT(entry);
05782 ast_dial_join(ringing_station->station->dial);
05783 ast_dial_destroy(ringing_station->station->dial);
05784 ringing_station->station->dial = NULL;
05785 ast_free(ringing_station);
05786 }
05787 }
05788 AST_LIST_TRAVERSE_SAFE_END
05789 }
05790
05791 static void sla_handle_ringing_trunk_event(void)
05792 {
05793 ast_mutex_lock(&sla.lock);
05794 sla_ring_stations();
05795 ast_mutex_unlock(&sla.lock);
05796
05797
05798 sla_hangup_stations();
05799 }
05800
05801 static void sla_handle_hold_event(struct sla_event *event)
05802 {
05803 ast_atomic_fetchadd_int((int *) &event->trunk_ref->trunk->hold_stations, 1);
05804 event->trunk_ref->state = SLA_TRUNK_STATE_ONHOLD_BYME;
05805 ast_devstate_changed(AST_DEVICE_ONHOLD, AST_DEVSTATE_CACHABLE, "SLA:%s_%s",
05806 event->station->name, event->trunk_ref->trunk->name);
05807 sla_change_trunk_state(event->trunk_ref->trunk, SLA_TRUNK_STATE_ONHOLD,
05808 INACTIVE_TRUNK_REFS, event->trunk_ref);
05809
05810 if (event->trunk_ref->trunk->active_stations == 1) {
05811
05812
05813 event->trunk_ref->trunk->on_hold = 1;
05814 ast_indicate(event->trunk_ref->trunk->chan, AST_CONTROL_HOLD);
05815 }
05816
05817 ast_softhangup(event->trunk_ref->chan, AST_SOFTHANGUP_DEV);
05818 event->trunk_ref->chan = NULL;
05819 }
05820
05821
05822
05823
05824
05825 static int sla_calc_trunk_timeouts(unsigned int *timeout)
05826 {
05827 struct sla_ringing_trunk *ringing_trunk;
05828 int res = 0;
05829
05830 AST_LIST_TRAVERSE_SAFE_BEGIN(&sla.ringing_trunks, ringing_trunk, entry) {
05831 int time_left, time_elapsed;
05832 if (!ringing_trunk->trunk->ring_timeout)
05833 continue;
05834 time_elapsed = ast_tvdiff_ms(ast_tvnow(), ringing_trunk->ring_begin);
05835 time_left = (ringing_trunk->trunk->ring_timeout * 1000) - time_elapsed;
05836 if (time_left <= 0) {
05837 pbx_builtin_setvar_helper(ringing_trunk->trunk->chan, "SLATRUNK_STATUS", "RINGTIMEOUT");
05838 AST_LIST_REMOVE_CURRENT(entry);
05839 sla_stop_ringing_trunk(ringing_trunk);
05840 res = 1;
05841 continue;
05842 }
05843 if (time_left < *timeout)
05844 *timeout = time_left;
05845 }
05846 AST_LIST_TRAVERSE_SAFE_END;
05847
05848 return res;
05849 }
05850
05851
05852
05853
05854
05855 static int sla_calc_station_timeouts(unsigned int *timeout)
05856 {
05857 struct sla_ringing_trunk *ringing_trunk;
05858 struct sla_ringing_station *ringing_station;
05859 int res = 0;
05860
05861 AST_LIST_TRAVERSE_SAFE_BEGIN(&sla.ringing_stations, ringing_station, entry) {
05862 unsigned int ring_timeout = 0;
05863 int time_elapsed, time_left = INT_MAX, final_trunk_time_left = INT_MIN;
05864 struct sla_trunk_ref *trunk_ref;
05865
05866
05867
05868
05869 AST_LIST_TRAVERSE(&ringing_station->station->trunks, trunk_ref, entry) {
05870 struct sla_station_ref *station_ref;
05871 int trunk_time_elapsed, trunk_time_left;
05872
05873 AST_LIST_TRAVERSE(&sla.ringing_trunks, ringing_trunk, entry) {
05874 if (ringing_trunk->trunk == trunk_ref->trunk)
05875 break;
05876 }
05877 if (!ringing_trunk)
05878 continue;
05879
05880
05881
05882 if (!trunk_ref->ring_timeout)
05883 break;
05884
05885
05886
05887
05888 AST_LIST_TRAVERSE(&ringing_trunk->timed_out_stations, station_ref, entry) {
05889 if (station_ref->station == ringing_station->station)
05890 break;
05891 }
05892 if (station_ref)
05893 continue;
05894
05895 trunk_time_elapsed = ast_tvdiff_ms(ast_tvnow(), ringing_trunk->ring_begin);
05896 trunk_time_left = (trunk_ref->ring_timeout * 1000) - trunk_time_elapsed;
05897 if (trunk_time_left > final_trunk_time_left)
05898 final_trunk_time_left = trunk_time_left;
05899 }
05900
05901
05902 if (final_trunk_time_left == INT_MIN && !ringing_station->station->ring_timeout)
05903 continue;
05904
05905
05906 if (ringing_station->station->ring_timeout) {
05907 ring_timeout = ringing_station->station->ring_timeout;
05908 time_elapsed = ast_tvdiff_ms(ast_tvnow(), ringing_station->ring_begin);
05909 time_left = (ring_timeout * 1000) - time_elapsed;
05910 }
05911
05912
05913
05914 if (final_trunk_time_left > INT_MIN && final_trunk_time_left < time_left)
05915 time_left = final_trunk_time_left;
05916
05917
05918 if (time_left <= 0) {
05919 AST_LIST_REMOVE_CURRENT(entry);
05920 sla_stop_ringing_station(ringing_station, SLA_STATION_HANGUP_TIMEOUT);
05921 res = 1;
05922 continue;
05923 }
05924
05925
05926
05927 if (time_left < *timeout)
05928 *timeout = time_left;
05929 }
05930 AST_LIST_TRAVERSE_SAFE_END;
05931
05932 return res;
05933 }
05934
05935
05936
05937
05938 static int sla_calc_station_delays(unsigned int *timeout)
05939 {
05940 struct sla_station *station;
05941 int res = 0;
05942
05943 AST_LIST_TRAVERSE(&sla_stations, station, entry) {
05944 struct sla_ringing_trunk *ringing_trunk;
05945 int time_left;
05946
05947
05948 if (sla_check_ringing_station(station))
05949 continue;
05950
05951
05952 if (sla_check_inuse_station(station))
05953 continue;
05954
05955
05956 if (!(ringing_trunk = sla_choose_ringing_trunk(station, NULL, 0)))
05957 continue;
05958
05959 if ((time_left = sla_check_station_delay(station, ringing_trunk)) == INT_MAX)
05960 continue;
05961
05962
05963
05964
05965 if (time_left <= 0) {
05966 res = 1;
05967 continue;
05968 }
05969
05970 if (time_left < *timeout)
05971 *timeout = time_left;
05972 }
05973
05974 return res;
05975 }
05976
05977
05978
05979 static int sla_process_timers(struct timespec *ts)
05980 {
05981 unsigned int timeout = UINT_MAX;
05982 struct timeval wait;
05983 unsigned int change_made = 0;
05984
05985
05986 if (sla_calc_trunk_timeouts(&timeout))
05987 change_made = 1;
05988
05989
05990 if (sla_calc_station_timeouts(&timeout))
05991 change_made = 1;
05992
05993
05994 if (sla_calc_station_delays(&timeout))
05995 change_made = 1;
05996
05997
05998 if (change_made)
05999 sla_queue_event_nolock(SLA_EVENT_RINGING_TRUNK);
06000
06001
06002 if (timeout == UINT_MAX)
06003 return 0;
06004
06005 if (ts) {
06006 wait = ast_tvadd(ast_tvnow(), ast_samp2tv(timeout, 1000));
06007 ts->tv_sec = wait.tv_sec;
06008 ts->tv_nsec = wait.tv_usec * 1000;
06009 }
06010
06011 return 1;
06012 }
06013
06014 static int sla_load_config(int reload);
06015
06016
06017 static void sla_check_reload(void)
06018 {
06019 struct sla_station *station;
06020 struct sla_trunk *trunk;
06021
06022 ast_mutex_lock(&sla.lock);
06023
06024 if (!AST_LIST_EMPTY(&sla.event_q) || !AST_LIST_EMPTY(&sla.ringing_trunks)
06025 || !AST_LIST_EMPTY(&sla.ringing_stations)) {
06026 ast_mutex_unlock(&sla.lock);
06027 return;
06028 }
06029
06030 AST_RWLIST_RDLOCK(&sla_stations);
06031 AST_RWLIST_TRAVERSE(&sla_stations, station, entry) {
06032 if (station->ref_count)
06033 break;
06034 }
06035 AST_RWLIST_UNLOCK(&sla_stations);
06036 if (station) {
06037 ast_mutex_unlock(&sla.lock);
06038 return;
06039 }
06040
06041 AST_RWLIST_RDLOCK(&sla_trunks);
06042 AST_RWLIST_TRAVERSE(&sla_trunks, trunk, entry) {
06043 if (trunk->ref_count)
06044 break;
06045 }
06046 AST_RWLIST_UNLOCK(&sla_trunks);
06047 if (trunk) {
06048 ast_mutex_unlock(&sla.lock);
06049 return;
06050 }
06051
06052
06053 sla_load_config(1);
06054 sla.reload = 0;
06055
06056 ast_mutex_unlock(&sla.lock);
06057 }
06058
06059 static void *sla_thread(void *data)
06060 {
06061 struct sla_failed_station *failed_station;
06062 struct sla_ringing_station *ringing_station;
06063
06064 ast_mutex_lock(&sla.lock);
06065
06066 while (!sla.stop) {
06067 struct sla_event *event;
06068 struct timespec ts = { 0, };
06069 unsigned int have_timeout = 0;
06070
06071 if (AST_LIST_EMPTY(&sla.event_q)) {
06072 if ((have_timeout = sla_process_timers(&ts)))
06073 ast_cond_timedwait(&sla.cond, &sla.lock, &ts);
06074 else
06075 ast_cond_wait(&sla.cond, &sla.lock);
06076 if (sla.stop)
06077 break;
06078 }
06079
06080 if (have_timeout)
06081 sla_process_timers(NULL);
06082
06083 while ((event = AST_LIST_REMOVE_HEAD(&sla.event_q, entry))) {
06084 ast_mutex_unlock(&sla.lock);
06085 switch (event->type) {
06086 case SLA_EVENT_HOLD:
06087 sla_handle_hold_event(event);
06088 break;
06089 case SLA_EVENT_DIAL_STATE:
06090 sla_handle_dial_state_event();
06091 break;
06092 case SLA_EVENT_RINGING_TRUNK:
06093 sla_handle_ringing_trunk_event();
06094 break;
06095 case SLA_EVENT_RELOAD:
06096 sla.reload = 1;
06097 case SLA_EVENT_CHECK_RELOAD:
06098 break;
06099 }
06100 ast_free(event);
06101 ast_mutex_lock(&sla.lock);
06102 }
06103
06104 if (sla.reload) {
06105 sla_check_reload();
06106 }
06107 }
06108
06109 ast_mutex_unlock(&sla.lock);
06110
06111 while ((ringing_station = AST_LIST_REMOVE_HEAD(&sla.ringing_stations, entry)))
06112 ast_free(ringing_station);
06113
06114 while ((failed_station = AST_LIST_REMOVE_HEAD(&sla.failed_stations, entry)))
06115 ast_free(failed_station);
06116
06117 return NULL;
06118 }
06119
06120 struct dial_trunk_args {
06121 struct sla_trunk_ref *trunk_ref;
06122 struct sla_station *station;
06123 ast_mutex_t *cond_lock;
06124 ast_cond_t *cond;
06125 };
06126
06127 static void *dial_trunk(void *data)
06128 {
06129 struct dial_trunk_args *args = data;
06130 struct ast_dial *dial;
06131 char *tech, *tech_data;
06132 enum ast_dial_result dial_res;
06133 char conf_name[MAX_CONFNUM];
06134 struct ast_conference *conf;
06135 struct ast_flags64 conf_flags = { 0 };
06136 struct sla_trunk_ref *trunk_ref = args->trunk_ref;
06137 int caller_is_saved;
06138 struct ast_party_caller caller;
06139
06140 if (!(dial = ast_dial_create())) {
06141 ast_mutex_lock(args->cond_lock);
06142 ast_cond_signal(args->cond);
06143 ast_mutex_unlock(args->cond_lock);
06144 return NULL;
06145 }
06146
06147 tech_data = ast_strdupa(trunk_ref->trunk->device);
06148 tech = strsep(&tech_data, "/");
06149 if (ast_dial_append(dial, tech, tech_data) == -1) {
06150 ast_mutex_lock(args->cond_lock);
06151 ast_cond_signal(args->cond);
06152 ast_mutex_unlock(args->cond_lock);
06153 ast_dial_destroy(dial);
06154 return NULL;
06155 }
06156
06157
06158 caller_is_saved = 0;
06159 if (!sla.attempt_callerid) {
06160 caller_is_saved = 1;
06161 caller = trunk_ref->chan->caller;
06162 ast_party_caller_init(&trunk_ref->chan->caller);
06163 }
06164
06165 dial_res = ast_dial_run(dial, trunk_ref->chan, 1);
06166
06167
06168 if (caller_is_saved) {
06169 ast_party_caller_free(&trunk_ref->chan->caller);
06170 trunk_ref->chan->caller = caller;
06171 }
06172
06173 if (dial_res != AST_DIAL_RESULT_TRYING) {
06174 ast_mutex_lock(args->cond_lock);
06175 ast_cond_signal(args->cond);
06176 ast_mutex_unlock(args->cond_lock);
06177 ast_dial_destroy(dial);
06178 return NULL;
06179 }
06180
06181 for (;;) {
06182 unsigned int done = 0;
06183 switch ((dial_res = ast_dial_state(dial))) {
06184 case AST_DIAL_RESULT_ANSWERED:
06185 trunk_ref->trunk->chan = ast_dial_answered(dial);
06186 case AST_DIAL_RESULT_HANGUP:
06187 case AST_DIAL_RESULT_INVALID:
06188 case AST_DIAL_RESULT_FAILED:
06189 case AST_DIAL_RESULT_TIMEOUT:
06190 case AST_DIAL_RESULT_UNANSWERED:
06191 done = 1;
06192 case AST_DIAL_RESULT_TRYING:
06193 case AST_DIAL_RESULT_RINGING:
06194 case AST_DIAL_RESULT_PROGRESS:
06195 case AST_DIAL_RESULT_PROCEEDING:
06196 break;
06197 }
06198 if (done)
06199 break;
06200 }
06201
06202 if (!trunk_ref->trunk->chan) {
06203 ast_mutex_lock(args->cond_lock);
06204 ast_cond_signal(args->cond);
06205 ast_mutex_unlock(args->cond_lock);
06206 ast_dial_join(dial);
06207 ast_dial_destroy(dial);
06208 return NULL;
06209 }
06210
06211 snprintf(conf_name, sizeof(conf_name), "SLA_%s", trunk_ref->trunk->name);
06212 ast_set_flag64(&conf_flags,
06213 CONFFLAG_QUIET | CONFFLAG_MARKEDEXIT | CONFFLAG_MARKEDUSER |
06214 CONFFLAG_PASS_DTMF | CONFFLAG_SLA_TRUNK);
06215 conf = build_conf(conf_name, "", "", 1, 1, 1, trunk_ref->trunk->chan, NULL);
06216
06217 ast_mutex_lock(args->cond_lock);
06218 ast_cond_signal(args->cond);
06219 ast_mutex_unlock(args->cond_lock);
06220
06221 if (conf) {
06222 conf_run(trunk_ref->trunk->chan, conf, &conf_flags, NULL);
06223 dispose_conf(conf);
06224 conf = NULL;
06225 }
06226
06227
06228 sla_change_trunk_state(trunk_ref->trunk, SLA_TRUNK_STATE_IDLE, ALL_TRUNK_REFS, NULL);
06229
06230 trunk_ref->trunk->chan = NULL;
06231 trunk_ref->trunk->on_hold = 0;
06232
06233 ast_dial_join(dial);
06234 ast_dial_destroy(dial);
06235
06236 return NULL;
06237 }
06238
06239
06240
06241 static struct sla_trunk_ref *sla_choose_idle_trunk(const struct sla_station *station)
06242 {
06243 struct sla_trunk_ref *trunk_ref = NULL;
06244
06245 AST_LIST_TRAVERSE(&station->trunks, trunk_ref, entry) {
06246 if (trunk_ref->state == SLA_TRUNK_STATE_IDLE)
06247 break;
06248 }
06249
06250 return trunk_ref;
06251 }
06252
06253 static int sla_station_exec(struct ast_channel *chan, const char *data)
06254 {
06255 char *station_name, *trunk_name;
06256 struct sla_station *station;
06257 struct sla_trunk_ref *trunk_ref = NULL;
06258 char conf_name[MAX_CONFNUM];
06259 struct ast_flags64 conf_flags = { 0 };
06260 struct ast_conference *conf;
06261
06262 if (ast_strlen_zero(data)) {
06263 ast_log(LOG_WARNING, "Invalid Arguments to SLAStation!\n");
06264 pbx_builtin_setvar_helper(chan, "SLASTATION_STATUS", "FAILURE");
06265 return 0;
06266 }
06267
06268 trunk_name = ast_strdupa(data);
06269 station_name = strsep(&trunk_name, "_");
06270
06271 if (ast_strlen_zero(station_name)) {
06272 ast_log(LOG_WARNING, "Invalid Arguments to SLAStation!\n");
06273 pbx_builtin_setvar_helper(chan, "SLASTATION_STATUS", "FAILURE");
06274 return 0;
06275 }
06276
06277 AST_RWLIST_RDLOCK(&sla_stations);
06278 station = sla_find_station(station_name);
06279 if (station)
06280 ast_atomic_fetchadd_int((int *) &station->ref_count, 1);
06281 AST_RWLIST_UNLOCK(&sla_stations);
06282
06283 if (!station) {
06284 ast_log(LOG_WARNING, "Station '%s' not found!\n", station_name);
06285 pbx_builtin_setvar_helper(chan, "SLASTATION_STATUS", "FAILURE");
06286 sla_queue_event(SLA_EVENT_CHECK_RELOAD);
06287 return 0;
06288 }
06289
06290 AST_RWLIST_RDLOCK(&sla_trunks);
06291 if (!ast_strlen_zero(trunk_name)) {
06292 trunk_ref = sla_find_trunk_ref_byname(station, trunk_name);
06293 } else
06294 trunk_ref = sla_choose_idle_trunk(station);
06295 AST_RWLIST_UNLOCK(&sla_trunks);
06296
06297 if (!trunk_ref) {
06298 if (ast_strlen_zero(trunk_name))
06299 ast_log(LOG_NOTICE, "No trunks available for call.\n");
06300 else {
06301 ast_log(LOG_NOTICE, "Can't join existing call on trunk "
06302 "'%s' due to access controls.\n", trunk_name);
06303 }
06304 pbx_builtin_setvar_helper(chan, "SLASTATION_STATUS", "CONGESTION");
06305 ast_atomic_fetchadd_int((int *) &station->ref_count, -1);
06306 sla_queue_event(SLA_EVENT_CHECK_RELOAD);
06307 return 0;
06308 }
06309
06310 if (trunk_ref->state == SLA_TRUNK_STATE_ONHOLD_BYME) {
06311 if (ast_atomic_dec_and_test((int *) &trunk_ref->trunk->hold_stations) == 1)
06312 sla_change_trunk_state(trunk_ref->trunk, SLA_TRUNK_STATE_UP, ALL_TRUNK_REFS, NULL);
06313 else {
06314 trunk_ref->state = SLA_TRUNK_STATE_UP;
06315 ast_devstate_changed(AST_DEVICE_INUSE, AST_DEVSTATE_CACHABLE,
06316 "SLA:%s_%s", station->name, trunk_ref->trunk->name);
06317 }
06318 } else if (trunk_ref->state == SLA_TRUNK_STATE_RINGING) {
06319 struct sla_ringing_trunk *ringing_trunk;
06320
06321 ast_mutex_lock(&sla.lock);
06322 AST_LIST_TRAVERSE_SAFE_BEGIN(&sla.ringing_trunks, ringing_trunk, entry) {
06323 if (ringing_trunk->trunk == trunk_ref->trunk) {
06324 AST_LIST_REMOVE_CURRENT(entry);
06325 break;
06326 }
06327 }
06328 AST_LIST_TRAVERSE_SAFE_END
06329 ast_mutex_unlock(&sla.lock);
06330
06331 if (ringing_trunk) {
06332 answer_trunk_chan(ringing_trunk->trunk->chan);
06333 sla_change_trunk_state(ringing_trunk->trunk, SLA_TRUNK_STATE_UP, ALL_TRUNK_REFS, NULL);
06334
06335 free(ringing_trunk);
06336
06337
06338 sla_queue_event(SLA_EVENT_RINGING_TRUNK);
06339 sla_queue_event(SLA_EVENT_DIAL_STATE);
06340 }
06341 }
06342
06343 trunk_ref->chan = chan;
06344
06345 if (!trunk_ref->trunk->chan) {
06346 ast_mutex_t cond_lock;
06347 ast_cond_t cond;
06348 pthread_t dont_care;
06349 struct dial_trunk_args args = {
06350 .trunk_ref = trunk_ref,
06351 .station = station,
06352 .cond_lock = &cond_lock,
06353 .cond = &cond,
06354 };
06355 sla_change_trunk_state(trunk_ref->trunk, SLA_TRUNK_STATE_UP, ALL_TRUNK_REFS, NULL);
06356
06357
06358
06359 ast_autoservice_start(chan);
06360 ast_mutex_init(&cond_lock);
06361 ast_cond_init(&cond, NULL);
06362 ast_mutex_lock(&cond_lock);
06363 ast_pthread_create_detached_background(&dont_care, NULL, dial_trunk, &args);
06364 ast_cond_wait(&cond, &cond_lock);
06365 ast_mutex_unlock(&cond_lock);
06366 ast_mutex_destroy(&cond_lock);
06367 ast_cond_destroy(&cond);
06368 ast_autoservice_stop(chan);
06369 if (!trunk_ref->trunk->chan) {
06370 ast_debug(1, "Trunk didn't get created. chan: %lx\n", (long) trunk_ref->trunk->chan);
06371 pbx_builtin_setvar_helper(chan, "SLASTATION_STATUS", "CONGESTION");
06372 sla_change_trunk_state(trunk_ref->trunk, SLA_TRUNK_STATE_IDLE, ALL_TRUNK_REFS, NULL);
06373 trunk_ref->chan = NULL;
06374 ast_atomic_fetchadd_int((int *) &station->ref_count, -1);
06375 sla_queue_event(SLA_EVENT_CHECK_RELOAD);
06376 return 0;
06377 }
06378 }
06379
06380 if (ast_atomic_fetchadd_int((int *) &trunk_ref->trunk->active_stations, 1) == 0 &&
06381 trunk_ref->trunk->on_hold) {
06382 trunk_ref->trunk->on_hold = 0;
06383 ast_indicate(trunk_ref->trunk->chan, AST_CONTROL_UNHOLD);
06384 sla_change_trunk_state(trunk_ref->trunk, SLA_TRUNK_STATE_UP, ALL_TRUNK_REFS, NULL);
06385 }
06386
06387 snprintf(conf_name, sizeof(conf_name), "SLA_%s", trunk_ref->trunk->name);
06388 ast_set_flag64(&conf_flags,
06389 CONFFLAG_QUIET | CONFFLAG_MARKEDEXIT | CONFFLAG_PASS_DTMF | CONFFLAG_SLA_STATION);
06390 ast_answer(chan);
06391 conf = build_conf(conf_name, "", "", 0, 0, 1, chan, NULL);
06392 if (conf) {
06393 conf_run(chan, conf, &conf_flags, NULL);
06394 dispose_conf(conf);
06395 conf = NULL;
06396 }
06397 trunk_ref->chan = NULL;
06398 if (ast_atomic_dec_and_test((int *) &trunk_ref->trunk->active_stations) &&
06399 trunk_ref->state != SLA_TRUNK_STATE_ONHOLD_BYME) {
06400 strncat(conf_name, ",K", sizeof(conf_name) - strlen(conf_name) - 1);
06401 admin_exec(NULL, conf_name);
06402 trunk_ref->trunk->hold_stations = 0;
06403 sla_change_trunk_state(trunk_ref->trunk, SLA_TRUNK_STATE_IDLE, ALL_TRUNK_REFS, NULL);
06404 }
06405
06406 pbx_builtin_setvar_helper(chan, "SLASTATION_STATUS", "SUCCESS");
06407
06408 ast_atomic_fetchadd_int((int *) &station->ref_count, -1);
06409 sla_queue_event(SLA_EVENT_CHECK_RELOAD);
06410
06411 return 0;
06412 }
06413
06414 static struct sla_trunk_ref *create_trunk_ref(struct sla_trunk *trunk)
06415 {
06416 struct sla_trunk_ref *trunk_ref;
06417
06418 if (!(trunk_ref = ast_calloc(1, sizeof(*trunk_ref))))
06419 return NULL;
06420
06421 trunk_ref->trunk = trunk;
06422
06423 return trunk_ref;
06424 }
06425
06426 static struct sla_ringing_trunk *queue_ringing_trunk(struct sla_trunk *trunk)
06427 {
06428 struct sla_ringing_trunk *ringing_trunk;
06429
06430 if (!(ringing_trunk = ast_calloc(1, sizeof(*ringing_trunk))))
06431 return NULL;
06432
06433 ringing_trunk->trunk = trunk;
06434 ringing_trunk->ring_begin = ast_tvnow();
06435
06436 sla_change_trunk_state(trunk, SLA_TRUNK_STATE_RINGING, ALL_TRUNK_REFS, NULL);
06437
06438 ast_mutex_lock(&sla.lock);
06439 AST_LIST_INSERT_HEAD(&sla.ringing_trunks, ringing_trunk, entry);
06440 ast_mutex_unlock(&sla.lock);
06441
06442 sla_queue_event(SLA_EVENT_RINGING_TRUNK);
06443
06444 return ringing_trunk;
06445 }
06446
06447 enum {
06448 SLA_TRUNK_OPT_MOH = (1 << 0),
06449 };
06450
06451 enum {
06452 SLA_TRUNK_OPT_ARG_MOH_CLASS = 0,
06453 SLA_TRUNK_OPT_ARG_ARRAY_SIZE = 1,
06454 };
06455
06456 AST_APP_OPTIONS(sla_trunk_opts, BEGIN_OPTIONS
06457 AST_APP_OPTION_ARG('M', SLA_TRUNK_OPT_MOH, SLA_TRUNK_OPT_ARG_MOH_CLASS),
06458 END_OPTIONS );
06459
06460 static int sla_trunk_exec(struct ast_channel *chan, const char *data)
06461 {
06462 char conf_name[MAX_CONFNUM];
06463 struct ast_conference *conf;
06464 struct ast_flags64 conf_flags = { 0 };
06465 struct sla_trunk *trunk;
06466 struct sla_ringing_trunk *ringing_trunk;
06467 AST_DECLARE_APP_ARGS(args,
06468 AST_APP_ARG(trunk_name);
06469 AST_APP_ARG(options);
06470 );
06471 char *opts[SLA_TRUNK_OPT_ARG_ARRAY_SIZE] = { NULL, };
06472 struct ast_flags opt_flags = { 0 };
06473 char *parse;
06474
06475 if (ast_strlen_zero(data)) {
06476 ast_log(LOG_ERROR, "The SLATrunk application requires an argument, the trunk name\n");
06477 return -1;
06478 }
06479
06480 parse = ast_strdupa(data);
06481 AST_STANDARD_APP_ARGS(args, parse);
06482 if (args.argc == 2) {
06483 if (ast_app_parse_options(sla_trunk_opts, &opt_flags, opts, args.options)) {
06484 ast_log(LOG_ERROR, "Error parsing options for SLATrunk\n");
06485 return -1;
06486 }
06487 }
06488
06489 AST_RWLIST_RDLOCK(&sla_trunks);
06490 trunk = sla_find_trunk(args.trunk_name);
06491 if (trunk)
06492 ast_atomic_fetchadd_int((int *) &trunk->ref_count, 1);
06493 AST_RWLIST_UNLOCK(&sla_trunks);
06494
06495 if (!trunk) {
06496 ast_log(LOG_ERROR, "SLA Trunk '%s' not found!\n", args.trunk_name);
06497 pbx_builtin_setvar_helper(chan, "SLATRUNK_STATUS", "FAILURE");
06498 sla_queue_event(SLA_EVENT_CHECK_RELOAD);
06499 return 0;
06500 }
06501
06502 if (trunk->chan) {
06503 ast_log(LOG_ERROR, "Call came in on %s, but the trunk is already in use!\n",
06504 args.trunk_name);
06505 pbx_builtin_setvar_helper(chan, "SLATRUNK_STATUS", "FAILURE");
06506 ast_atomic_fetchadd_int((int *) &trunk->ref_count, -1);
06507 sla_queue_event(SLA_EVENT_CHECK_RELOAD);
06508 return 0;
06509 }
06510
06511 trunk->chan = chan;
06512
06513 if (!(ringing_trunk = queue_ringing_trunk(trunk))) {
06514 pbx_builtin_setvar_helper(chan, "SLATRUNK_STATUS", "FAILURE");
06515 ast_atomic_fetchadd_int((int *) &trunk->ref_count, -1);
06516 sla_queue_event(SLA_EVENT_CHECK_RELOAD);
06517 return 0;
06518 }
06519
06520 snprintf(conf_name, sizeof(conf_name), "SLA_%s", args.trunk_name);
06521 conf = build_conf(conf_name, "", "", 1, 1, 1, chan, NULL);
06522 if (!conf) {
06523 pbx_builtin_setvar_helper(chan, "SLATRUNK_STATUS", "FAILURE");
06524 ast_atomic_fetchadd_int((int *) &trunk->ref_count, -1);
06525 sla_queue_event(SLA_EVENT_CHECK_RELOAD);
06526 return 0;
06527 }
06528 ast_set_flag64(&conf_flags,
06529 CONFFLAG_QUIET | CONFFLAG_MARKEDEXIT | CONFFLAG_MARKEDUSER | CONFFLAG_PASS_DTMF | CONFFLAG_NO_AUDIO_UNTIL_UP);
06530
06531 if (ast_test_flag(&opt_flags, SLA_TRUNK_OPT_MOH)) {
06532 ast_indicate(chan, -1);
06533 ast_set_flag64(&conf_flags, CONFFLAG_MOH);
06534 } else
06535 ast_indicate(chan, AST_CONTROL_RINGING);
06536
06537 conf_run(chan, conf, &conf_flags, opts);
06538 dispose_conf(conf);
06539 conf = NULL;
06540 trunk->chan = NULL;
06541 trunk->on_hold = 0;
06542
06543 sla_change_trunk_state(trunk, SLA_TRUNK_STATE_IDLE, ALL_TRUNK_REFS, NULL);
06544
06545 if (!pbx_builtin_getvar_helper(chan, "SLATRUNK_STATUS"))
06546 pbx_builtin_setvar_helper(chan, "SLATRUNK_STATUS", "SUCCESS");
06547
06548
06549 ast_mutex_lock(&sla.lock);
06550 AST_LIST_TRAVERSE_SAFE_BEGIN(&sla.ringing_trunks, ringing_trunk, entry) {
06551 if (ringing_trunk->trunk == trunk) {
06552 AST_LIST_REMOVE_CURRENT(entry);
06553 break;
06554 }
06555 }
06556 AST_LIST_TRAVERSE_SAFE_END;
06557 ast_mutex_unlock(&sla.lock);
06558 if (ringing_trunk) {
06559 ast_free(ringing_trunk);
06560 pbx_builtin_setvar_helper(chan, "SLATRUNK_STATUS", "UNANSWERED");
06561
06562
06563 sla_queue_event(SLA_EVENT_RINGING_TRUNK);
06564 }
06565
06566 ast_atomic_fetchadd_int((int *) &trunk->ref_count, -1);
06567 sla_queue_event(SLA_EVENT_CHECK_RELOAD);
06568
06569 return 0;
06570 }
06571
06572 static enum ast_device_state sla_state(const char *data)
06573 {
06574 char *buf, *station_name, *trunk_name;
06575 struct sla_station *station;
06576 struct sla_trunk_ref *trunk_ref;
06577 enum ast_device_state res = AST_DEVICE_INVALID;
06578
06579 trunk_name = buf = ast_strdupa(data);
06580 station_name = strsep(&trunk_name, "_");
06581
06582 AST_RWLIST_RDLOCK(&sla_stations);
06583 AST_LIST_TRAVERSE(&sla_stations, station, entry) {
06584 if (strcasecmp(station_name, station->name))
06585 continue;
06586 AST_RWLIST_RDLOCK(&sla_trunks);
06587 AST_LIST_TRAVERSE(&station->trunks, trunk_ref, entry) {
06588 if (!strcasecmp(trunk_name, trunk_ref->trunk->name))
06589 break;
06590 }
06591 if (!trunk_ref) {
06592 AST_RWLIST_UNLOCK(&sla_trunks);
06593 break;
06594 }
06595 res = sla_state_to_devstate(trunk_ref->state);
06596 AST_RWLIST_UNLOCK(&sla_trunks);
06597 }
06598 AST_RWLIST_UNLOCK(&sla_stations);
06599
06600 if (res == AST_DEVICE_INVALID) {
06601 ast_log(LOG_ERROR, "Could not determine state for trunk %s on station %s!\n",
06602 trunk_name, station_name);
06603 }
06604
06605 return res;
06606 }
06607
06608 static void destroy_trunk(struct sla_trunk *trunk)
06609 {
06610 struct sla_station_ref *station_ref;
06611
06612 if (!ast_strlen_zero(trunk->autocontext))
06613 ast_context_remove_extension(trunk->autocontext, "s", 1, sla_registrar);
06614
06615 while ((station_ref = AST_LIST_REMOVE_HEAD(&trunk->stations, entry)))
06616 ast_free(station_ref);
06617
06618 ast_string_field_free_memory(trunk);
06619 ast_free(trunk);
06620 }
06621
06622 static void destroy_station(struct sla_station *station)
06623 {
06624 struct sla_trunk_ref *trunk_ref;
06625
06626 if (!ast_strlen_zero(station->autocontext)) {
06627 AST_RWLIST_RDLOCK(&sla_trunks);
06628 AST_LIST_TRAVERSE(&station->trunks, trunk_ref, entry) {
06629 char exten[AST_MAX_EXTENSION];
06630 char hint[AST_MAX_APP];
06631 snprintf(exten, sizeof(exten), "%s_%s", station->name, trunk_ref->trunk->name);
06632 snprintf(hint, sizeof(hint), "SLA:%s", exten);
06633 ast_context_remove_extension(station->autocontext, exten,
06634 1, sla_registrar);
06635 ast_context_remove_extension(station->autocontext, hint,
06636 PRIORITY_HINT, sla_registrar);
06637 }
06638 AST_RWLIST_UNLOCK(&sla_trunks);
06639 }
06640
06641 while ((trunk_ref = AST_LIST_REMOVE_HEAD(&station->trunks, entry)))
06642 ast_free(trunk_ref);
06643
06644 ast_string_field_free_memory(station);
06645 ast_free(station);
06646 }
06647
06648 static void sla_destroy(void)
06649 {
06650 struct sla_trunk *trunk;
06651 struct sla_station *station;
06652
06653 AST_RWLIST_WRLOCK(&sla_trunks);
06654 while ((trunk = AST_RWLIST_REMOVE_HEAD(&sla_trunks, entry)))
06655 destroy_trunk(trunk);
06656 AST_RWLIST_UNLOCK(&sla_trunks);
06657
06658 AST_RWLIST_WRLOCK(&sla_stations);
06659 while ((station = AST_RWLIST_REMOVE_HEAD(&sla_stations, entry)))
06660 destroy_station(station);
06661 AST_RWLIST_UNLOCK(&sla_stations);
06662
06663 if (sla.thread != AST_PTHREADT_NULL) {
06664 ast_mutex_lock(&sla.lock);
06665 sla.stop = 1;
06666 ast_cond_signal(&sla.cond);
06667 ast_mutex_unlock(&sla.lock);
06668 pthread_join(sla.thread, NULL);
06669 }
06670
06671
06672 ast_context_destroy(NULL, sla_registrar);
06673
06674 ast_mutex_destroy(&sla.lock);
06675 ast_cond_destroy(&sla.cond);
06676 }
06677
06678 static int sla_check_device(const char *device)
06679 {
06680 char *tech, *tech_data;
06681
06682 tech_data = ast_strdupa(device);
06683 tech = strsep(&tech_data, "/");
06684
06685 if (ast_strlen_zero(tech) || ast_strlen_zero(tech_data))
06686 return -1;
06687
06688 return 0;
06689 }
06690
06691 static int sla_build_trunk(struct ast_config *cfg, const char *cat)
06692 {
06693 struct sla_trunk *trunk;
06694 struct ast_variable *var;
06695 const char *dev;
06696
06697 if (!(dev = ast_variable_retrieve(cfg, cat, "device"))) {
06698 ast_log(LOG_ERROR, "SLA Trunk '%s' defined with no device!\n", cat);
06699 return -1;
06700 }
06701
06702 if (sla_check_device(dev)) {
06703 ast_log(LOG_ERROR, "SLA Trunk '%s' define with invalid device '%s'!\n",
06704 cat, dev);
06705 return -1;
06706 }
06707
06708 if (!(trunk = ast_calloc_with_stringfields(1, struct sla_trunk, 32))) {
06709 return -1;
06710 }
06711
06712 ast_string_field_set(trunk, name, cat);
06713 ast_string_field_set(trunk, device, dev);
06714
06715 for (var = ast_variable_browse(cfg, cat); var; var = var->next) {
06716 if (!strcasecmp(var->name, "autocontext"))
06717 ast_string_field_set(trunk, autocontext, var->value);
06718 else if (!strcasecmp(var->name, "ringtimeout")) {
06719 if (sscanf(var->value, "%30u", &trunk->ring_timeout) != 1) {
06720 ast_log(LOG_WARNING, "Invalid ringtimeout '%s' specified for trunk '%s'\n",
06721 var->value, trunk->name);
06722 trunk->ring_timeout = 0;
06723 }
06724 } else if (!strcasecmp(var->name, "barge"))
06725 trunk->barge_disabled = ast_false(var->value);
06726 else if (!strcasecmp(var->name, "hold")) {
06727 if (!strcasecmp(var->value, "private"))
06728 trunk->hold_access = SLA_HOLD_PRIVATE;
06729 else if (!strcasecmp(var->value, "open"))
06730 trunk->hold_access = SLA_HOLD_OPEN;
06731 else {
06732 ast_log(LOG_WARNING, "Invalid value '%s' for hold on trunk %s\n",
06733 var->value, trunk->name);
06734 }
06735 } else if (strcasecmp(var->name, "type") && strcasecmp(var->name, "device")) {
06736 ast_log(LOG_ERROR, "Invalid option '%s' specified at line %d of %s!\n",
06737 var->name, var->lineno, SLA_CONFIG_FILE);
06738 }
06739 }
06740
06741 if (!ast_strlen_zero(trunk->autocontext)) {
06742 struct ast_context *context;
06743 context = ast_context_find_or_create(NULL, NULL, trunk->autocontext, sla_registrar);
06744 if (!context) {
06745 ast_log(LOG_ERROR, "Failed to automatically find or create "
06746 "context '%s' for SLA!\n", trunk->autocontext);
06747 destroy_trunk(trunk);
06748 return -1;
06749 }
06750 if (ast_add_extension2(context, 0 , "s", 1,
06751 NULL, NULL, slatrunk_app, ast_strdup(trunk->name), ast_free_ptr, sla_registrar)) {
06752 ast_log(LOG_ERROR, "Failed to automatically create extension "
06753 "for trunk '%s'!\n", trunk->name);
06754 destroy_trunk(trunk);
06755 return -1;
06756 }
06757 }
06758
06759 AST_RWLIST_WRLOCK(&sla_trunks);
06760 AST_RWLIST_INSERT_TAIL(&sla_trunks, trunk, entry);
06761 AST_RWLIST_UNLOCK(&sla_trunks);
06762
06763 return 0;
06764 }
06765
06766 static void sla_add_trunk_to_station(struct sla_station *station, struct ast_variable *var)
06767 {
06768 struct sla_trunk *trunk;
06769 struct sla_trunk_ref *trunk_ref;
06770 struct sla_station_ref *station_ref;
06771 char *trunk_name, *options, *cur;
06772
06773 options = ast_strdupa(var->value);
06774 trunk_name = strsep(&options, ",");
06775
06776 AST_RWLIST_RDLOCK(&sla_trunks);
06777 AST_RWLIST_TRAVERSE(&sla_trunks, trunk, entry) {
06778 if (!strcasecmp(trunk->name, trunk_name))
06779 break;
06780 }
06781
06782 AST_RWLIST_UNLOCK(&sla_trunks);
06783 if (!trunk) {
06784 ast_log(LOG_ERROR, "Trunk '%s' not found!\n", var->value);
06785 return;
06786 }
06787 if (!(trunk_ref = create_trunk_ref(trunk)))
06788 return;
06789 trunk_ref->state = SLA_TRUNK_STATE_IDLE;
06790
06791 while ((cur = strsep(&options, ","))) {
06792 char *name, *value = cur;
06793 name = strsep(&value, "=");
06794 if (!strcasecmp(name, "ringtimeout")) {
06795 if (sscanf(value, "%30u", &trunk_ref->ring_timeout) != 1) {
06796 ast_log(LOG_WARNING, "Invalid ringtimeout value '%s' for "
06797 "trunk '%s' on station '%s'\n", value, trunk->name, station->name);
06798 trunk_ref->ring_timeout = 0;
06799 }
06800 } else if (!strcasecmp(name, "ringdelay")) {
06801 if (sscanf(value, "%30u", &trunk_ref->ring_delay) != 1) {
06802 ast_log(LOG_WARNING, "Invalid ringdelay value '%s' for "
06803 "trunk '%s' on station '%s'\n", value, trunk->name, station->name);
06804 trunk_ref->ring_delay = 0;
06805 }
06806 } else {
06807 ast_log(LOG_WARNING, "Invalid option '%s' for "
06808 "trunk '%s' on station '%s'\n", name, trunk->name, station->name);
06809 }
06810 }
06811
06812 if (!(station_ref = sla_create_station_ref(station))) {
06813 ast_free(trunk_ref);
06814 return;
06815 }
06816 ast_atomic_fetchadd_int((int *) &trunk->num_stations, 1);
06817 AST_RWLIST_WRLOCK(&sla_trunks);
06818 AST_LIST_INSERT_TAIL(&trunk->stations, station_ref, entry);
06819 AST_RWLIST_UNLOCK(&sla_trunks);
06820 AST_LIST_INSERT_TAIL(&station->trunks, trunk_ref, entry);
06821 }
06822
06823 static int sla_build_station(struct ast_config *cfg, const char *cat)
06824 {
06825 struct sla_station *station;
06826 struct ast_variable *var;
06827 const char *dev;
06828
06829 if (!(dev = ast_variable_retrieve(cfg, cat, "device"))) {
06830 ast_log(LOG_ERROR, "SLA Station '%s' defined with no device!\n", cat);
06831 return -1;
06832 }
06833
06834 if (!(station = ast_calloc_with_stringfields(1, struct sla_station, 32))) {
06835 return -1;
06836 }
06837
06838 ast_string_field_set(station, name, cat);
06839 ast_string_field_set(station, device, dev);
06840
06841 for (var = ast_variable_browse(cfg, cat); var; var = var->next) {
06842 if (!strcasecmp(var->name, "trunk"))
06843 sla_add_trunk_to_station(station, var);
06844 else if (!strcasecmp(var->name, "autocontext"))
06845 ast_string_field_set(station, autocontext, var->value);
06846 else if (!strcasecmp(var->name, "ringtimeout")) {
06847 if (sscanf(var->value, "%30u", &station->ring_timeout) != 1) {
06848 ast_log(LOG_WARNING, "Invalid ringtimeout '%s' specified for station '%s'\n",
06849 var->value, station->name);
06850 station->ring_timeout = 0;
06851 }
06852 } else if (!strcasecmp(var->name, "ringdelay")) {
06853 if (sscanf(var->value, "%30u", &station->ring_delay) != 1) {
06854 ast_log(LOG_WARNING, "Invalid ringdelay '%s' specified for station '%s'\n",
06855 var->value, station->name);
06856 station->ring_delay = 0;
06857 }
06858 } else if (!strcasecmp(var->name, "hold")) {
06859 if (!strcasecmp(var->value, "private"))
06860 station->hold_access = SLA_HOLD_PRIVATE;
06861 else if (!strcasecmp(var->value, "open"))
06862 station->hold_access = SLA_HOLD_OPEN;
06863 else {
06864 ast_log(LOG_WARNING, "Invalid value '%s' for hold on station %s\n",
06865 var->value, station->name);
06866 }
06867
06868 } else if (strcasecmp(var->name, "type") && strcasecmp(var->name, "device")) {
06869 ast_log(LOG_ERROR, "Invalid option '%s' specified at line %d of %s!\n",
06870 var->name, var->lineno, SLA_CONFIG_FILE);
06871 }
06872 }
06873
06874 if (!ast_strlen_zero(station->autocontext)) {
06875 struct ast_context *context;
06876 struct sla_trunk_ref *trunk_ref;
06877 context = ast_context_find_or_create(NULL, NULL, station->autocontext, sla_registrar);
06878 if (!context) {
06879 ast_log(LOG_ERROR, "Failed to automatically find or create "
06880 "context '%s' for SLA!\n", station->autocontext);
06881 destroy_station(station);
06882 return -1;
06883 }
06884
06885
06886 if (ast_add_extension2(context, 0 , station->name, 1,
06887 NULL, NULL, slastation_app, ast_strdup(station->name), ast_free_ptr, sla_registrar)) {
06888 ast_log(LOG_ERROR, "Failed to automatically create extension "
06889 "for trunk '%s'!\n", station->name);
06890 destroy_station(station);
06891 return -1;
06892 }
06893 AST_RWLIST_RDLOCK(&sla_trunks);
06894 AST_LIST_TRAVERSE(&station->trunks, trunk_ref, entry) {
06895 char exten[AST_MAX_EXTENSION];
06896 char hint[AST_MAX_APP];
06897 snprintf(exten, sizeof(exten), "%s_%s", station->name, trunk_ref->trunk->name);
06898 snprintf(hint, sizeof(hint), "SLA:%s", exten);
06899
06900
06901 if (ast_add_extension2(context, 0 , exten, 1,
06902 NULL, NULL, slastation_app, ast_strdup(exten), ast_free_ptr, sla_registrar)) {
06903 ast_log(LOG_ERROR, "Failed to automatically create extension "
06904 "for trunk '%s'!\n", station->name);
06905 destroy_station(station);
06906 return -1;
06907 }
06908
06909
06910 if (ast_add_extension2(context, 0 , exten, PRIORITY_HINT,
06911 NULL, NULL, hint, NULL, NULL, sla_registrar)) {
06912 ast_log(LOG_ERROR, "Failed to automatically create hint "
06913 "for trunk '%s'!\n", station->name);
06914 destroy_station(station);
06915 return -1;
06916 }
06917 }
06918 AST_RWLIST_UNLOCK(&sla_trunks);
06919 }
06920
06921 AST_RWLIST_WRLOCK(&sla_stations);
06922 AST_RWLIST_INSERT_TAIL(&sla_stations, station, entry);
06923 AST_RWLIST_UNLOCK(&sla_stations);
06924
06925 return 0;
06926 }
06927
06928 static int sla_load_config(int reload)
06929 {
06930 struct ast_config *cfg;
06931 struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
06932 const char *cat = NULL;
06933 int res = 0;
06934 const char *val;
06935
06936 if (!reload) {
06937 ast_mutex_init(&sla.lock);
06938 ast_cond_init(&sla.cond, NULL);
06939 }
06940
06941 if (!(cfg = ast_config_load(SLA_CONFIG_FILE, config_flags))) {
06942 return 0;
06943 } else if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
06944 return 0;
06945 } else if (cfg == CONFIG_STATUS_FILEINVALID) {
06946 ast_log(LOG_ERROR, "Config file " SLA_CONFIG_FILE " is in an invalid format. Aborting.\n");
06947 return 0;
06948 }
06949
06950 if (reload) {
06951 struct sla_station *station;
06952 struct sla_trunk *trunk;
06953
06954
06955 AST_RWLIST_TRAVERSE_SAFE_BEGIN(&sla_stations, station, entry) {
06956 AST_RWLIST_REMOVE_CURRENT(entry);
06957 ast_free(station);
06958 }
06959 AST_RWLIST_TRAVERSE_SAFE_END;
06960
06961 AST_RWLIST_TRAVERSE_SAFE_BEGIN(&sla_trunks, trunk, entry) {
06962 AST_RWLIST_REMOVE_CURRENT(entry);
06963 ast_free(trunk);
06964 }
06965 AST_RWLIST_TRAVERSE_SAFE_END;
06966 }
06967
06968 if ((val = ast_variable_retrieve(cfg, "general", "attemptcallerid")))
06969 sla.attempt_callerid = ast_true(val);
06970
06971 while ((cat = ast_category_browse(cfg, cat)) && !res) {
06972 const char *type;
06973 if (!strcasecmp(cat, "general"))
06974 continue;
06975 if (!(type = ast_variable_retrieve(cfg, cat, "type"))) {
06976 ast_log(LOG_WARNING, "Invalid entry in %s defined with no type!\n",
06977 SLA_CONFIG_FILE);
06978 continue;
06979 }
06980 if (!strcasecmp(type, "trunk"))
06981 res = sla_build_trunk(cfg, cat);
06982 else if (!strcasecmp(type, "station"))
06983 res = sla_build_station(cfg, cat);
06984 else {
06985 ast_log(LOG_WARNING, "Entry in %s defined with invalid type '%s'!\n",
06986 SLA_CONFIG_FILE, type);
06987 }
06988 }
06989
06990 ast_config_destroy(cfg);
06991
06992
06993
06994 if (sla.thread == AST_PTHREADT_NULL && (!AST_LIST_EMPTY(&sla_stations) || !AST_LIST_EMPTY(&sla_trunks))) {
06995 ast_pthread_create(&sla.thread, NULL, sla_thread, NULL);
06996 }
06997
06998 return res;
06999 }
07000
07001 static int acf_meetme_info_eval(const char *keyword, const struct ast_conference *conf)
07002 {
07003 if (!strcasecmp("lock", keyword)) {
07004 return conf->locked;
07005 } else if (!strcasecmp("parties", keyword)) {
07006 return conf->users;
07007 } else if (!strcasecmp("activity", keyword)) {
07008 time_t now;
07009 now = time(NULL);
07010 return (now - conf->start);
07011 } else if (!strcasecmp("dynamic", keyword)) {
07012 return conf->isdynamic;
07013 } else {
07014 return -1;
07015 }
07016
07017 }
07018
07019 static int acf_meetme_info(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
07020 {
07021 struct ast_conference *conf;
07022 char *parse;
07023 int result = -2;
07024 AST_DECLARE_APP_ARGS(args,
07025 AST_APP_ARG(keyword);
07026 AST_APP_ARG(confno);
07027 );
07028
07029 if (ast_strlen_zero(data)) {
07030 ast_log(LOG_ERROR, "Syntax: MEETME_INFO() requires two arguments\n");
07031 return -1;
07032 }
07033
07034 parse = ast_strdupa(data);
07035 AST_STANDARD_APP_ARGS(args, parse);
07036
07037 if (ast_strlen_zero(args.keyword)) {
07038 ast_log(LOG_ERROR, "Syntax: MEETME_INFO() requires a keyword\n");
07039 return -1;
07040 }
07041
07042 if (ast_strlen_zero(args.confno)) {
07043 ast_log(LOG_ERROR, "Syntax: MEETME_INFO() requires a conference number\n");
07044 return -1;
07045 }
07046
07047 AST_LIST_LOCK(&confs);
07048 AST_LIST_TRAVERSE(&confs, conf, list) {
07049 if (!strcmp(args.confno, conf->confno)) {
07050 result = acf_meetme_info_eval(args.keyword, conf);
07051 break;
07052 }
07053 }
07054 AST_LIST_UNLOCK(&confs);
07055
07056 if (result > -1) {
07057 snprintf(buf, len, "%d", result);
07058 } else if (result == -1) {
07059 ast_log(LOG_NOTICE, "Error: invalid keyword: '%s'\n", args.keyword);
07060 snprintf(buf, len, "0");
07061 } else if (result == -2) {
07062 ast_log(LOG_NOTICE, "Error: conference (%s) not found\n", args.confno);
07063 snprintf(buf, len, "0");
07064 }
07065
07066 return 0;
07067 }
07068
07069
07070 static struct ast_custom_function meetme_info_acf = {
07071 .name = "MEETME_INFO",
07072 .read = acf_meetme_info,
07073 };
07074
07075
07076 static int load_config(int reload)
07077 {
07078 load_config_meetme();
07079
07080 if (reload && sla.thread != AST_PTHREADT_NULL) {
07081 sla_queue_event(SLA_EVENT_RELOAD);
07082 ast_log(LOG_NOTICE, "A reload of the SLA configuration has been requested "
07083 "and will be completed when the system is idle.\n");
07084 return 0;
07085 }
07086
07087 return sla_load_config(0);
07088 }
07089
07090 #define MEETME_DATA_EXPORT(MEMBER) \
07091 MEMBER(ast_conference, confno, AST_DATA_STRING) \
07092 MEMBER(ast_conference, dahdiconf, AST_DATA_INTEGER) \
07093 MEMBER(ast_conference, users, AST_DATA_INTEGER) \
07094 MEMBER(ast_conference, markedusers, AST_DATA_INTEGER) \
07095 MEMBER(ast_conference, maxusers, AST_DATA_INTEGER) \
07096 MEMBER(ast_conference, isdynamic, AST_DATA_BOOLEAN) \
07097 MEMBER(ast_conference, locked, AST_DATA_BOOLEAN) \
07098 MEMBER(ast_conference, recordingfilename, AST_DATA_STRING) \
07099 MEMBER(ast_conference, recordingformat, AST_DATA_STRING) \
07100 MEMBER(ast_conference, pin, AST_DATA_PASSWORD) \
07101 MEMBER(ast_conference, pinadmin, AST_DATA_PASSWORD) \
07102 MEMBER(ast_conference, start, AST_DATA_TIMESTAMP) \
07103 MEMBER(ast_conference, endtime, AST_DATA_TIMESTAMP)
07104
07105 AST_DATA_STRUCTURE(ast_conference, MEETME_DATA_EXPORT);
07106
07107 #define MEETME_USER_DATA_EXPORT(MEMBER) \
07108 MEMBER(ast_conf_user, user_no, AST_DATA_INTEGER) \
07109 MEMBER(ast_conf_user, talking, AST_DATA_BOOLEAN) \
07110 MEMBER(ast_conf_user, dahdichannel, AST_DATA_BOOLEAN) \
07111 MEMBER(ast_conf_user, jointime, AST_DATA_TIMESTAMP) \
07112 MEMBER(ast_conf_user, kicktime, AST_DATA_TIMESTAMP) \
07113 MEMBER(ast_conf_user, timelimit, AST_DATA_MILLISECONDS) \
07114 MEMBER(ast_conf_user, play_warning, AST_DATA_MILLISECONDS) \
07115 MEMBER(ast_conf_user, warning_freq, AST_DATA_MILLISECONDS)
07116
07117 AST_DATA_STRUCTURE(ast_conf_user, MEETME_USER_DATA_EXPORT);
07118
07119 static int user_add_provider_cb(void *obj, void *arg, int flags)
07120 {
07121 struct ast_data *data_meetme_user;
07122 struct ast_data *data_meetme_user_channel;
07123 struct ast_data *data_meetme_user_volume;
07124
07125 struct ast_conf_user *user = obj;
07126 struct ast_data *data_meetme_users = arg;
07127
07128 data_meetme_user = ast_data_add_node(data_meetme_users, "user");
07129 if (!data_meetme_user) {
07130 return 0;
07131 }
07132
07133 ast_data_add_structure(ast_conf_user, data_meetme_user, user);
07134
07135
07136 data_meetme_user_channel = ast_data_add_node(data_meetme_user, "channel");
07137 if (!data_meetme_user_channel) {
07138 return 0;
07139 }
07140
07141 ast_channel_data_add_structure(data_meetme_user_channel, user->chan, 1);
07142
07143
07144 data_meetme_user_volume = ast_data_add_node(data_meetme_user, "listen-volume");
07145 if (!data_meetme_user_volume) {
07146 return 0;
07147 }
07148 ast_data_add_int(data_meetme_user_volume, "desired", user->listen.desired);
07149 ast_data_add_int(data_meetme_user_volume, "actual", user->listen.actual);
07150
07151 data_meetme_user_volume = ast_data_add_node(data_meetme_user, "talk-volume");
07152 if (!data_meetme_user_volume) {
07153 return 0;
07154 }
07155 ast_data_add_int(data_meetme_user_volume, "desired", user->talk.desired);
07156 ast_data_add_int(data_meetme_user_volume, "actual", user->talk.actual);
07157
07158 return 0;
07159 }
07160
07161
07162
07163
07164
07165 static int meetme_data_provider_get(const struct ast_data_search *search,
07166 struct ast_data *data_root)
07167 {
07168 struct ast_conference *cnf;
07169 struct ast_data *data_meetme, *data_meetme_users;
07170
07171 AST_LIST_LOCK(&confs);
07172 AST_LIST_TRAVERSE(&confs, cnf, list) {
07173 data_meetme = ast_data_add_node(data_root, "meetme");
07174 if (!data_meetme) {
07175 continue;
07176 }
07177
07178 ast_data_add_structure(ast_conference, data_meetme, cnf);
07179
07180 if (ao2_container_count(cnf->usercontainer)) {
07181 data_meetme_users = ast_data_add_node(data_meetme, "users");
07182 if (!data_meetme_users) {
07183 ast_data_remove_node(data_root, data_meetme);
07184 continue;
07185 }
07186
07187 ao2_callback(cnf->usercontainer, OBJ_NODATA, user_add_provider_cb, data_meetme_users);
07188 }
07189
07190 if (!ast_data_search_match(search, data_meetme)) {
07191 ast_data_remove_node(data_root, data_meetme);
07192 }
07193 }
07194 AST_LIST_UNLOCK(&confs);
07195
07196 return 0;
07197 }
07198
07199 static const struct ast_data_handler meetme_data_provider = {
07200 .version = AST_DATA_HANDLER_VERSION,
07201 .get = meetme_data_provider_get
07202 };
07203
07204 static const struct ast_data_entry meetme_data_providers[] = {
07205 AST_DATA_ENTRY("asterisk/application/meetme/list", &meetme_data_provider),
07206 };
07207
07208 #ifdef TEST_FRAMEWORK
07209 AST_TEST_DEFINE(test_meetme_data_provider)
07210 {
07211 struct ast_channel *chan;
07212 struct ast_conference *cnf;
07213 struct ast_data *node;
07214 struct ast_data_query query = {
07215 .path = "/asterisk/application/meetme/list",
07216 .search = "list/meetme/confno=9898"
07217 };
07218
07219 switch (cmd) {
07220 case TEST_INIT:
07221 info->name = "meetme_get_data_test";
07222 info->category = "/main/data/app_meetme/list/";
07223 info->summary = "Meetme data provider unit test";
07224 info->description =
07225 "Tests whether the Meetme data provider implementation works as expected.";
07226 return AST_TEST_NOT_RUN;
07227 case TEST_EXECUTE:
07228 break;
07229 }
07230
07231 chan = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, NULL, NULL, NULL, 0, 0, "MeetMeTest");
07232 if (!chan) {
07233 ast_test_status_update(test, "Channel allocation failed\n");
07234 return AST_TEST_FAIL;
07235 }
07236
07237 cnf = build_conf("9898", "", "1234", 1, 1, 1, chan, test);
07238 if (!cnf) {
07239 ast_test_status_update(test, "Build of test conference 9898 failed\n");
07240 ast_hangup(chan);
07241 return AST_TEST_FAIL;
07242 }
07243
07244 node = ast_data_get(&query);
07245 if (!node) {
07246 ast_test_status_update(test, "Data query for test conference 9898 failed\n");
07247 dispose_conf(cnf);
07248 ast_hangup(chan);
07249 return AST_TEST_FAIL;
07250 }
07251
07252 if (strcmp(ast_data_retrieve_string(node, "meetme/confno"), "9898")) {
07253 ast_test_status_update(test, "Query returned the wrong conference\n");
07254 dispose_conf(cnf);
07255 ast_hangup(chan);
07256 ast_data_free(node);
07257 return AST_TEST_FAIL;
07258 }
07259
07260 ast_data_free(node);
07261 dispose_conf(cnf);
07262 ast_hangup(chan);
07263
07264 return AST_TEST_PASS;
07265 }
07266 #endif
07267
07268 static int unload_module(void)
07269 {
07270 int res = 0;
07271
07272 ast_cli_unregister_multiple(cli_meetme, ARRAY_LEN(cli_meetme));
07273 res = ast_manager_unregister("MeetmeMute");
07274 res |= ast_manager_unregister("MeetmeUnmute");
07275 res |= ast_manager_unregister("MeetmeList");
07276 res |= ast_unregister_application(app4);
07277 res |= ast_unregister_application(app3);
07278 res |= ast_unregister_application(app2);
07279 res |= ast_unregister_application(app);
07280 res |= ast_unregister_application(slastation_app);
07281 res |= ast_unregister_application(slatrunk_app);
07282
07283 #ifdef TEST_FRAMEWORK
07284 AST_TEST_UNREGISTER(test_meetme_data_provider);
07285 #endif
07286 ast_data_unregister(NULL);
07287
07288 ast_devstate_prov_del("Meetme");
07289 ast_devstate_prov_del("SLA");
07290
07291 sla_destroy();
07292
07293 res |= ast_custom_function_unregister(&meetme_info_acf);
07294 ast_unload_realtime("meetme");
07295
07296 return res;
07297 }
07298
07299
07300
07301 static int load_module(void)
07302 {
07303 int res = 0;
07304
07305 res |= load_config(0);
07306
07307 ast_cli_register_multiple(cli_meetme, ARRAY_LEN(cli_meetme));
07308 res |= ast_manager_register_xml("MeetmeMute", EVENT_FLAG_CALL, action_meetmemute);
07309 res |= ast_manager_register_xml("MeetmeUnmute", EVENT_FLAG_CALL, action_meetmeunmute);
07310 res |= ast_manager_register_xml("MeetmeList", EVENT_FLAG_REPORTING, action_meetmelist);
07311 res |= ast_register_application_xml(app4, channel_admin_exec);
07312 res |= ast_register_application_xml(app3, admin_exec);
07313 res |= ast_register_application_xml(app2, count_exec);
07314 res |= ast_register_application_xml(app, conf_exec);
07315 res |= ast_register_application_xml(slastation_app, sla_station_exec);
07316 res |= ast_register_application_xml(slatrunk_app, sla_trunk_exec);
07317
07318 #ifdef TEST_FRAMEWORK
07319 AST_TEST_REGISTER(test_meetme_data_provider);
07320 #endif
07321 ast_data_register_multiple(meetme_data_providers, ARRAY_LEN(meetme_data_providers));
07322
07323 res |= ast_devstate_prov_add("Meetme", meetmestate);
07324 res |= ast_devstate_prov_add("SLA", sla_state);
07325
07326 res |= ast_custom_function_register(&meetme_info_acf);
07327 ast_realtime_require_field("meetme", "confno", RQ_UINTEGER2, 3, "members", RQ_UINTEGER1, 3, NULL);
07328
07329 return res;
07330 }
07331
07332 static int reload(void)
07333 {
07334 ast_unload_realtime("meetme");
07335 return load_config(1);
07336 }
07337
07338 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "MeetMe conference bridge",
07339 .load = load_module,
07340 .unload = unload_module,
07341 .reload = reload,
07342 .load_pri = AST_MODPRI_DEVSTATE_PROVIDER,
07343 );
07344