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