-
Notifications
You must be signed in to change notification settings - Fork 52
/
userintf.cpp
3649 lines (3073 loc) · 87.7 KB
/
userintf.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (C) 2005-2009 Michel de Boer <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <iostream>
#include <cstdlib>
#include <errno.h>
#include <fcntl.h>
#include <readline/readline.h>
#include <readline/history.h>
#include <signal.h>
#include <stdio.h>
#include <string>
#include <sys/select.h>
#include <unistd.h>
#include "address_book.h"
#include "events.h"
#include "line.h"
#include "log.h"
#include "sys_settings.h"
#include "translator.h"
#include "userintf.h"
#include "util.h"
#include "user.h"
#include "audio/rtp_telephone_event.h"
#include "parser/parse_ctrl.h"
#include "sockets/interfaces.h"
#include "audits/memman.h"
#include "utils/file_utils.h"
#include "utils/mime_database.h"
#define CLI_PROMPT "Twinkle> "
#define CLI_MAX_HISTORY_LENGTH 1000
extern string user_host;
extern t_event_queue *evq_trans_layer;
using namespace utils;
////////////////////////
// GNU Readline helpers
////////////////////////
char ** tw_completion (const char *text, int start, int end);
char * tw_command_generator (const char *text, int state);
char ** tw_completion (const char *text, int start, int end)
{
char **matches;
matches = (char **)NULL;
if (start == 0)
matches = rl_completion_matches (text, tw_command_generator);
return (matches);
}
char * tw_command_generator (const char *text, int state)
{
static int len;
static list<string>::const_iterator i;
if (!state){
len = strlen(text);
i = ui->get_all_commands().begin();
}
for (; i != ui->get_all_commands().end(); i++){
const char * s = i->c_str();
//cout << s << endl;
if ( s && strncmp(s, text, len) == 0 ){
i++;
return strdup(s);
}
}
/* If no names matched, then return NULL. */
return ((char *)NULL);
}
// Ugly hack to allow invoking methods on our object from within a C-style
// callback function. This relies on the object being a singleton.
static t_userintf *cb_user_intf;
// Callback method (a.k.a. "line handler") that will be invoked by Readline
// once a complete line has been read.
static void tw_readline_cb(char *line)
{
if (!line) {
// EOF
cout << endl;
// Calling this from the line handler prevents one extra
// prompt from being displayed. (The duplicate call later on
// will not be an issue.)
rl_callback_handler_remove();
cb_user_intf->cmd_quit();
} else {
if (*line) {
add_history(line);
cb_user_intf->exec_command(line);
}
free(line);
}
}
// SIGWINCH handler to help us relay that information to Readline
static int sigwinch_received;
static void sigwinch_handler(int signum)
{
sigwinch_received = 1;
signal(SIGWINCH, sigwinch_handler);
}
/////////////////////////////
// Private
/////////////////////////////
string t_userintf::expand_destination(t_user *user_config, const string &dst, const string &scheme) {
assert(user_config);
string s = dst;
// Apply number conversion rules if applicable
// Add domain if it is missing from a sip-uri
if (s.find('@') == string::npos) {
bool is_tel_uri = (s.substr(0, 4) == "tel:");
// Strip tel-scheme
if (is_tel_uri) s = s.substr(4);
// Remove white space
s = remove_white_space(s);
// Remove special phone symbols
if (user_config->get_remove_special_phone_symbols() &&
looks_like_phone(s, user_config->get_special_phone_symbols()))
{
s = remove_symbols(s, user_config->get_special_phone_symbols());
}
// Convert number according to the number conversion rules
s = user_config->convert_number(s);
if (is_tel_uri) {
// Add tel-scheme again.
s = "tel:" + s;
} else if (s.substr(0, 4) != "sip:" &&
(user_config->get_use_tel_uri_for_phone() || scheme == "tel") &&
user_config->get_numerical_user_is_phone() &&
looks_like_phone(s, user_config->get_special_phone_symbols()))
{
// Add tel-scheme if a telephone number must be expanded
// to a tel-uri according to user profile settings.
s = "tel:" + s;
} else {
// Add domain
s += '@';
s += user_config->get_domain();
}
}
// Add sip-scheme if a scheme is missing
if (s.substr(0, 4) != "sip:" && s.substr(0, 4) != "tel:") {
s = "sip:" + s;
}
// RFC 3261 19.1.1
// Add user=phone for telehpone numbers in a SIP-URI
// If the SIP-URI contains a telephone number it SHOULD contain
// the user=phone parameter.
if (user_config->get_numerical_user_is_phone() && s.substr(0, 4) == "sip:") {
t_url u(s);
if (u.get_user_param().empty() &&
u.user_looks_like_phone(user_config->get_special_phone_symbols())) {
s += ";user=phone";
}
}
return s;
}
void t_userintf::expand_destination(t_user *user_config,
const string &dst, string &display, string &dst_url)
{
display.clear();
dst_url.clear();
if (dst.empty()) {
return;
}
// If there is a display name then the url part is between angle
// brackets.
if (dst[dst.size() - 1] != '>') {
dst_url = expand_destination(user_config, dst);
return;
}
// Find start of url
string::size_type i = dst.rfind('<');
if (i == string::npos) {
// It seems the string is invalid.
return;
}
dst_url = expand_destination(user_config, dst.substr(i + 1, dst.size() - i - 2));
if (i > 0) {
display = unquote(trim(dst.substr(0, i)));
}
}
void t_userintf::expand_destination(t_user *user_config,
const string &dst, t_display_url &display_url)
{
string url_str;
expand_destination(user_config, dst, display_url.display, url_str);
display_url.url.set_url(url_str);
}
void t_userintf::expand_destination(t_user *user_config,
const string &dst, t_display_url &display_url, string &subject,
string &dst_no_headers)
{
string headers;
dst_no_headers = dst;
t_url u(dst);
// Split headers from URI
if (u.is_valid()) {
// destination is a valid URI. Strip off the headers if any
headers = u.get_headers();
// Cut off headers
// Note that a separator (?) will be in front of the
// headers string
if (!headers.empty()) {
string::size_type i = dst.find(headers);
if (i != string::npos) {
dst_no_headers = dst.substr(0, i - 1);
}
}
expand_destination(user_config, dst_no_headers, display_url);
} else {
// destination may be a short URI.
// Split at a '?' to find any headers.
// NOTE: this is not fool proof. A user name may contain a '?'
vector<string> l = split_on_first(dst, '?');
dst_no_headers = l[0];
expand_destination(user_config, dst_no_headers, display_url);
if (display_url.is_valid() && l.size() == 2) {
headers = l[1];
}
}
// Parse headers to find subject header
subject.clear();
if (!headers.empty()) {
try {
list<string> parse_errors;
t_sip_message *m = t_parser::parse_headers(headers, parse_errors);
if (m->hdr_subject.is_populated()) {
subject = m->hdr_subject.subject;
}
MEMMAN_DELETE(m);
delete m;
} catch (int) {
// ignore invalid headers
}
}
}
bool t_userintf::parse_args(const list<string> command_list,
list<t_command_arg> &al)
{
t_command_arg arg;
bool parsed_flag = false;
al.clear();
arg.flag = 0;
arg.value = "";
for (list<string>::const_iterator i = command_list.begin();
i != command_list.end(); i++)
{
if (i == command_list.begin()) continue;
const string &s = *i;
if (s[0] == '-') {
if (s.size() == 1) return false;
if (parsed_flag) al.push_back(arg);
arg.flag = s[1];
if (s.size() > 2) {
arg.value = unquote(s.substr(2));
al.push_back(arg);
arg.flag = 0;
arg.value = "";
parsed_flag = false;
} else {
arg.value = "";
parsed_flag = true;
}
} else {
if (parsed_flag) {
arg.value = unquote(s);
} else {
arg.flag = 0;
arg.value = unquote(s);
}
al.push_back(arg);
parsed_flag = false;
arg.flag = 0;
arg.value = "";
}
}
// Last parsed argument was a flag only
if (parsed_flag) al.push_back(arg);
return true;
}
bool t_userintf::exec_invite(const list<string> command_list, bool immediate) {
list<t_command_arg> al;
string display;
string subject;
string destination;
bool hide_user = false;
if (!parse_args(command_list, al)) {
exec_command("help call");
return false;
}
for (list<t_command_arg>::iterator i = al.begin(); i != al.end(); i++) {
switch (i->flag) {
case 'd':
display = i->value;
break;
case 's':
subject = i->value;
break;
case 'h':
hide_user = true;
break;
case 0:
destination = i->value;
break;
default:
exec_command("help call");
return false;
break;
}
}
return do_invite(destination, display, subject, immediate, hide_user);
}
bool t_userintf::do_invite(const string &destination, const string &display,
const string &subject, bool immediate, bool anonymous)
{
t_url dest_url(expand_destination(active_user, destination));
if (!dest_url.is_valid()) {
exec_command("help call");
return false;
}
t_url vm_url(expand_destination(active_user, active_user->get_mwi_vm_address()));
if (dest_url != vm_url) {
// Keep call information for redial
last_called_url = dest_url;
last_called_display = display;
last_called_subject = subject;
last_called_profile = active_user->get_profile_name();
last_called_hide_user = anonymous;
}
phone->pub_invite(active_user, dest_url, display, subject, anonymous);
return true;
}
bool t_userintf::exec_redial(const list<string> command_list) {
if (can_redial()) {
do_redial();
return true;
}
return false;
}
void t_userintf::do_redial(void) {
t_user *user_config = phone->ref_user_profile(last_called_profile);
phone->pub_invite(user_config, last_called_url, last_called_display,
last_called_subject, last_called_hide_user);
}
bool t_userintf::exec_answer(const list<string> command_list) {
do_answer();
return true;
}
void t_userintf::do_answer(void) {
cb_stop_call_notification(phone->get_active_line());
phone->pub_answer();
}
bool t_userintf::exec_answerbye(const list<string> command_list) {
do_answerbye();
return true;
}
void t_userintf::do_answerbye(void) {
unsigned short line = phone->get_active_line();
switch (phone->get_line_substate(line)) {
case LSSUB_INCOMING_PROGRESS:
do_answer();
break;
case LSSUB_OUTGOING_PROGRESS:
case LSSUB_ESTABLISHED:
do_bye();
break;
default:
break;
}
}
bool t_userintf::exec_reject(const list<string> command_list) {
do_reject();
return true;
}
void t_userintf::do_reject(void) {
cb_stop_call_notification(phone->get_active_line());
phone->pub_reject();
cout << endl;
cout << "Line " << phone->get_active_line() + 1 << ": call rejected.\n";
cout << endl;
}
bool t_userintf::exec_redirect(const list<string> command_list, bool immediate) {
list<t_command_arg> al;
list<string> dest_list;
int num_redirections = 0;
bool show_status = false;
bool action_present = false;
bool enable = true;
bool type_present = false;
t_cf_type cf_type = CF_ALWAYS;
if (!parse_args(command_list, al)) {
exec_command("help redirect");
return false;
}
for (list<t_command_arg>::iterator i = al.begin(); i != al.end(); i++) {
switch (i->flag) {
case 's':
show_status = true;
break;
case 't':
if (i->value == "always") {
cf_type = CF_ALWAYS;
} else if (i->value == "busy") {
cf_type = CF_BUSY;
} else if (i->value == "noanswer") {
cf_type = CF_NOANSWER;
} else {
exec_command("help redirect");
return false;
}
type_present = true;
break;
case 'a':
if (i->value == "on") {
enable = true;
} else if (i->value == "off") {
enable = false;
} else {
exec_command("help redirect");
return false;
}
action_present = true;
break;
case 0:
dest_list.push_back(i->value);
num_redirections++;
break;
default:
exec_command("help redirect");
return false;
break;
}
}
if (type_present && enable && (num_redirections == 0 || num_redirections > 5)) {
exec_command("help redirect");
return false;
}
if (!type_present && action_present && enable) {
exec_command("help redirect");
return false;
}
if (!type_present && !action_present &&
(num_redirections == 0 || num_redirections > 5))
{
exec_command("help redirect");
return false;
}
do_redirect(show_status, type_present, cf_type, action_present, enable,
num_redirections, dest_list, immediate);
return true;
}
void t_userintf::do_redirect(bool show_status, bool type_present, t_cf_type cf_type,
bool action_present, bool enable, int num_redirections,
const list<string> &dest_strlist, bool immediate)
{
list<t_display_url> dest_list;
for (list<string>::const_iterator i = dest_strlist.begin();
i != dest_strlist.end(); i++)
{
t_display_url du;
du.url = expand_destination(active_user, *i);
du.display.clear();
if (!du.is_valid()) return;
dest_list.push_back(du);
}
if (show_status) {
list<t_display_url> cf_dest; // call forwarding destinations
cout << endl;
cout << "Redirect always: ";
if (phone->ref_service(active_user)->get_cf_active(CF_ALWAYS, cf_dest)) {
for (list<t_display_url>::iterator i = cf_dest.begin();
i != cf_dest.end(); i++)
{
if (i != cf_dest.begin()) cout << ", ";
cout << i->encode();
}
} else {
cout << "not active";
}
cout << endl;
cout << "Redirect busy: ";
if (phone->ref_service(active_user)->get_cf_active(CF_BUSY, cf_dest)) {
for (list<t_display_url>::iterator i = cf_dest.begin();
i != cf_dest.end(); i++)
{
if (i != cf_dest.begin()) cout << ", ";
cout << i->encode();
}
} else {
cout << "not active";
}
cout << endl;
cout << "Redirect noanswer: ";
if (phone->ref_service(active_user)->get_cf_active(CF_NOANSWER, cf_dest)) {
for (list<t_display_url>::iterator i = cf_dest.begin();
i != cf_dest.end(); i++)
{
if (i != cf_dest.begin()) cout << ", ";
cout << i->encode();
}
} else {
cout << "not active";
}
cout << endl;
cout << endl;
return;
}
// Enable/disable permanent redirections
if (type_present) {
if (enable) {
phone->ref_service(active_user)->enable_cf(cf_type, dest_list);
cout << "Redirection enabled.\n\n";
} else {
phone->ref_service(active_user)->disable_cf(cf_type);
cout << "Redirection disabled.\n\n";
}
return;
} else {
if (action_present) {
if (!enable) {
phone->ref_service(active_user)->disable_cf(CF_ALWAYS);
phone->ref_service(active_user)->disable_cf(CF_BUSY);
phone->ref_service(active_user)->disable_cf(CF_NOANSWER);
cout << "All redirections disabled.\n\n";
return;
}
return;
}
}
// Redirect current call
cb_stop_call_notification(phone->get_active_line());
phone->pub_redirect(dest_list, 302);
cout << endl;
cout << "Line " << phone->get_active_line() + 1 << ": call redirected.\n";
cout << endl;
}
bool t_userintf::exec_dnd(const list<string> command_list) {
list<t_command_arg> al;
bool show_status = false;
bool toggle = true;
bool enable = false;
if (!parse_args(command_list, al)) {
exec_command("help dnd");
return false;
}
for (list<t_command_arg>::iterator i = al.begin(); i != al.end(); i++) {
switch (i->flag) {
case 's':
show_status = true;
break;
case 'a':
if (i->value == "on") {
enable = true;
} else if (i->value == "off") {
enable = false;
} else {
exec_command("help dnd");
return false;
}
toggle = false;
break;
default:
exec_command("help dnd");
return false;
break;
}
}
do_dnd(show_status, toggle, enable);
return true;
}
void t_userintf::do_dnd(bool show_status, bool toggle, bool enable) {
if (show_status) {
cout << endl;
cout << "Do not disturb: ";
if (phone->ref_service(active_user)->is_dnd_active()) {
cout << "active";
} else {
cout << "not active";
}
cout << endl;
return;
}
if (toggle) {
enable = !phone->ref_service(active_user)->is_dnd_active();
}
if (enable) {
phone->ref_service(active_user)->enable_dnd();
cout << "Do not disturb enabled.\n\n";
return;
} else {
phone->ref_service(active_user)->disable_dnd();
cout << "Do not disturb disabled.\n\n";
return;
}
}
bool t_userintf::exec_auto_answer(const list<string> command_list) {
list<t_command_arg> al;
bool show_status = false;
bool toggle = true;
bool enable = false;
if (!parse_args(command_list, al)) {
exec_command("help auto_answer");
return false;
}
for (list<t_command_arg>::iterator i = al.begin(); i != al.end(); i++) {
switch (i->flag) {
case 's':
show_status = true;
break;
case 'a':
if (i->value == "on") {
enable = true;
} else if (i->value == "off") {
enable = false;
} else {
exec_command("help auto_answer");
return false;
}
toggle = false;
break;
default:
exec_command("help auto_answer");
return false;
break;
}
}
do_auto_answer(show_status, toggle, enable);
return true;
}
void t_userintf::do_auto_answer(bool show_status, bool toggle, bool enable) {
if (show_status) {
cout << endl;
cout << "Auto answer: ";
if (phone->ref_service(active_user)->is_auto_answer_active()) {
cout << "active";
} else {
cout << "not active";
}
cout << endl;
return;
}
if (toggle) {
enable = !phone->ref_service(active_user)->is_auto_answer_active();
}
if (enable) {
phone->ref_service(active_user)->enable_auto_answer(true);
cout << "Auto answer enabled.\n\n";
return;
} else {
phone->ref_service(active_user)->enable_auto_answer(false);
cout << "Auto answer disabled.\n\n";
return;
}
}
bool t_userintf::exec_bye(const list<string> command_list) {
do_bye();
return true;
}
void t_userintf::do_bye(void) {
phone->pub_end_call();
}
bool t_userintf::exec_hold(const list<string> command_list) {
list<t_command_arg> al;
bool toggle = false;
if (!parse_args(command_list, al)) {
exec_command("help hold");
return false;
}
for (list<t_command_arg>::iterator i = al.begin(); i != al.end(); i++) {
switch (i->flag) {
case 't':
toggle = true;
break;
default:
exec_command("help hold");
return false;
break;
}
}
do_hold(toggle);
return true;
}
void t_userintf::do_hold(bool toggle) {
if (toggle && phone->is_line_on_hold(phone->get_active_line()))
phone->pub_retrieve();
else
phone->pub_hold();
}
bool t_userintf::exec_retrieve(const list<string> command_list) {
do_retrieve();
return true;
}
void t_userintf::do_retrieve(void) {
phone->pub_retrieve();
}
bool t_userintf::exec_refer(const list<string> command_list, bool immediate) {
list<t_command_arg> al;
string destination;
bool dest_set = false;
t_transfer_type transfer_type = TRANSFER_BASIC;
if (!parse_args(command_list, al)) {
exec_command("help transfer");
return false;
}
for (list<t_command_arg>::iterator i = al.begin(); i != al.end(); i++) {
switch (i->flag) {
case 'c':
if (transfer_type != TRANSFER_BASIC) {
exec_command("help transfer");
return false;
}
transfer_type = TRANSFER_CONSULT;
if (!i->value.empty()) {
destination = i->value;
dest_set = true;
}
break;
case 'l':
if (transfer_type != TRANSFER_BASIC) {
exec_command("help transfer");
return false;
}
transfer_type = TRANSFER_OTHER_LINE;
break;
case 0:
destination = i->value;
dest_set = true;
break;
default:
exec_command("help transfer");
return false;
break;
}
}
if (!dest_set && transfer_type == TRANSFER_BASIC) {
exec_command("help transfer");
return false;
}
return do_refer(destination, transfer_type, immediate);
}
bool t_userintf::do_refer(const string &destination, t_transfer_type transfer_type,
bool immediate)
{
t_url dest_url;
if (transfer_type == TRANSFER_BASIC ||
(transfer_type == TRANSFER_CONSULT && !destination.empty()))
{
dest_url.set_url(expand_destination(active_user, destination));
if (!dest_url.is_valid()) {
exec_command("help transfer");
return false;
}
}
unsigned short active_line;
unsigned short other_line;
unsigned short line_to_be_transferred;
switch (transfer_type) {
case TRANSFER_BASIC:
phone->pub_refer(dest_url, "");
break;
case TRANSFER_CONSULT:
if (destination.empty()) {
active_line = phone->get_active_line();
if (!phone->is_line_transfer_consult(active_line,
line_to_be_transferred))
{
// There is no call to transfer
return false;
}
phone->pub_refer(line_to_be_transferred, active_line);
} else {
phone->pub_setup_consultation_call(dest_url, "");
}
break;
case TRANSFER_OTHER_LINE:
active_line = phone->get_active_line();
other_line = (active_line == 0 ? 1 : 0);
phone->pub_refer(active_line, other_line);
break;
}
return true;
}
bool t_userintf::exec_conference(const list<string> command_list) {
do_conference();
return true;
}
void t_userintf::do_conference(void) {
if (phone->join_3way(0, 1)) {
cout << endl;
cout << "Started 3-way conference.\n";
cout << endl;
} else {
cout << endl;
cout << "Failed to start 3-way conference.\n";
cout << endl;
}
}
bool t_userintf::exec_mute(const list<string> command_list) {
list<t_command_arg> al;
bool show_status = false;
bool toggle = true;
bool enable = true;
if (!parse_args(command_list, al)) {
exec_command("help mute");
return false;
}
for (list<t_command_arg>::iterator i = al.begin(); i != al.end(); i++) {
switch (i->flag) {
case 's':
show_status = true;
break;
case 'a':
if (i->value == "on") {
enable = true;
} else if (i->value == "off") {
enable = false;
} else {
exec_command("help mute");
return false;
}
toggle = false;
break;
default:
exec_command("help mute");
return false;
break;
}
}
do_mute(show_status, toggle, enable);
return true;
}
void t_userintf::do_mute(bool show_status, bool toggle, bool enable) {
if (show_status) {
cout << endl;
cout << "Line is ";
if (phone->is_line_muted(phone->get_active_line())) {
cout << "muted.";
} else {
cout << "not muted.";
}
cout << endl;
return;
}
if (toggle) enable = !phone->is_line_muted(phone->get_active_line());
if (enable) {
phone->mute(enable);
cout << "Line muted.\n\n";
return;
} else {
phone->mute(enable);
cout << "Line unmuted.\n\n";
return;
}
}
bool t_userintf::exec_dtmf(const list<string> command_list) {
list<t_command_arg> al;
string digits;