FreeCalypso > hg > themwi-system-sw
annotate sip-manual-out/user_cmd.c @ 256:63252528a56c
sip-out: add CDR log line
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 15 Aug 2023 10:11:51 -0800 |
parents | b3aeacc5722a |
children |
rev | line source |
---|---|
123
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
193
1f9a6cede2c5
sip-manual-out: split user_cmd.c from disc_cmd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
192
diff
changeset
|
2 * In this module we implement stdin command handling, supporting |
1f9a6cede2c5
sip-manual-out: split user_cmd.c from disc_cmd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
192
diff
changeset
|
3 * user-initiated CANCEL and BYE as well as TFO testing commands. |
123
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
193
1f9a6cede2c5
sip-manual-out: split user_cmd.c from disc_cmd.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
192
diff
changeset
|
6 #include <ctype.h> |
123
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdio.h> |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdlib.h> |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <string.h> |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <strings.h> |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 |
195
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
193
diff
changeset
|
12 static void |
212
b3aeacc5722a
sip-manual-out: add pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
202
diff
changeset
|
13 pcm_fill_cmd(arg) |
b3aeacc5722a
sip-manual-out: add pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
202
diff
changeset
|
14 char *arg; |
b3aeacc5722a
sip-manual-out: add pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
202
diff
changeset
|
15 { |
b3aeacc5722a
sip-manual-out: add pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
202
diff
changeset
|
16 char *cp; |
b3aeacc5722a
sip-manual-out: add pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
202
diff
changeset
|
17 unsigned octet; |
b3aeacc5722a
sip-manual-out: add pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
202
diff
changeset
|
18 |
b3aeacc5722a
sip-manual-out: add pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
202
diff
changeset
|
19 for (cp = arg; isspace(*cp); cp++) |
b3aeacc5722a
sip-manual-out: add pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
202
diff
changeset
|
20 ; |
b3aeacc5722a
sip-manual-out: add pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
202
diff
changeset
|
21 if (!isxdigit(*cp)) { |
b3aeacc5722a
sip-manual-out: add pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
202
diff
changeset
|
22 inv_syntax: fprintf(stderr, "error: pcm-fill command invalid syntax\n"); |
b3aeacc5722a
sip-manual-out: add pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
202
diff
changeset
|
23 return; |
b3aeacc5722a
sip-manual-out: add pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
202
diff
changeset
|
24 } |
b3aeacc5722a
sip-manual-out: add pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
202
diff
changeset
|
25 octet = strtoul(cp, &cp, 16); |
b3aeacc5722a
sip-manual-out: add pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
202
diff
changeset
|
26 if (*cp) |
b3aeacc5722a
sip-manual-out: add pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
202
diff
changeset
|
27 goto inv_syntax; |
b3aeacc5722a
sip-manual-out: add pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
202
diff
changeset
|
28 if (octet > 0xFF) { |
b3aeacc5722a
sip-manual-out: add pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
202
diff
changeset
|
29 fprintf(stderr, |
b3aeacc5722a
sip-manual-out: add pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
202
diff
changeset
|
30 "error: pcm-fill octet argument out of range\n"); |
b3aeacc5722a
sip-manual-out: add pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
202
diff
changeset
|
31 return; |
b3aeacc5722a
sip-manual-out: add pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
202
diff
changeset
|
32 } |
b3aeacc5722a
sip-manual-out: add pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
202
diff
changeset
|
33 set_pcm_fill_octet(octet); |
b3aeacc5722a
sip-manual-out: add pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
202
diff
changeset
|
34 } |
b3aeacc5722a
sip-manual-out: add pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
202
diff
changeset
|
35 |
b3aeacc5722a
sip-manual-out: add pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
202
diff
changeset
|
36 static void |
195
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
193
diff
changeset
|
37 tfo_req_cmd(args) |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
193
diff
changeset
|
38 char *args; |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
193
diff
changeset
|
39 { |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
193
diff
changeset
|
40 char *cp; |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
193
diff
changeset
|
41 unsigned sig, codec; |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
193
diff
changeset
|
42 |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
193
diff
changeset
|
43 for (cp = args; isspace(*cp); cp++) |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
193
diff
changeset
|
44 ; |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
193
diff
changeset
|
45 if (!isdigit(*cp)) { |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
193
diff
changeset
|
46 inv_syntax: fprintf(stderr, "error: tfo-req command invalid syntax\n"); |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
193
diff
changeset
|
47 return; |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
193
diff
changeset
|
48 } |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
193
diff
changeset
|
49 sig = strtoul(cp, &cp, 0); |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
193
diff
changeset
|
50 if (!isspace(*cp)) |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
193
diff
changeset
|
51 goto inv_syntax; |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
193
diff
changeset
|
52 if (sig > 0xFF) { |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
193
diff
changeset
|
53 fprintf(stderr, "error: Sig argument out of range\n"); |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
193
diff
changeset
|
54 return; |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
193
diff
changeset
|
55 } |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
193
diff
changeset
|
56 while (isspace(*cp)) |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
193
diff
changeset
|
57 cp++; |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
193
diff
changeset
|
58 if (!isdigit(*cp)) |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
193
diff
changeset
|
59 goto inv_syntax; |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
193
diff
changeset
|
60 codec = strtoul(cp, &cp, 0); |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
193
diff
changeset
|
61 if (*cp && !isspace(*cp)) |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
193
diff
changeset
|
62 goto inv_syntax; |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
193
diff
changeset
|
63 if (codec > 14) { |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
193
diff
changeset
|
64 fprintf(stderr, "error: Codec_Type argument out of range\n"); |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
193
diff
changeset
|
65 return; |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
193
diff
changeset
|
66 } |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
193
diff
changeset
|
67 while (isspace(*cp)) |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
193
diff
changeset
|
68 cp++; |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
193
diff
changeset
|
69 if (*cp) |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
193
diff
changeset
|
70 goto inv_syntax; |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
193
diff
changeset
|
71 send_tfo_req(sig, codec); |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
193
diff
changeset
|
72 } |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
193
diff
changeset
|
73 |
123
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 void |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 select_stdin() |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 { |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 char buf[256], *cp; |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 fgets(buf, sizeof buf, stdin); |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 cp = index(buf, '\n'); |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 if (cp) { |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 while (cp > buf && isspace(cp[-1])) |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 cp--; |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 *cp = '\0'; |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 } |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 for (cp = buf; isspace(*cp); cp++) |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 ; |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 if (!*cp) |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 return; |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 if (!strcmp(cp, "b") || !strcasecmp(cp, "bye")) |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 send_bye_req(); |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 else if (!strcmp(cp, "c") || !strcasecmp(cp, "cancel")) |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 send_cancel_req(); |
212
b3aeacc5722a
sip-manual-out: add pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
202
diff
changeset
|
94 else if (!strncmp(cp, "pcm-fill", 8) && isspace(cp[8])) |
b3aeacc5722a
sip-manual-out: add pcm-fill command
Mychaela Falconia <falcon@freecalypso.org>
parents:
202
diff
changeset
|
95 pcm_fill_cmd(cp + 9); |
195
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
193
diff
changeset
|
96 else if (!strncmp(cp, "tfo-req", 7) && isspace(cp[7])) |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
193
diff
changeset
|
97 tfo_req_cmd(cp + 8); |
202
f3164f732b84
sip-manual-out: add tfo-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
195
diff
changeset
|
98 else if (!strcmp(cp, "tfo-stop")) |
f3164f732b84
sip-manual-out: add tfo-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
195
diff
changeset
|
99 stop_tfo_out(); |
123
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 else |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 fprintf(stderr, "error: non-understood stdin command\n"); |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 } |