annotate sip-manual-out/user_cmd.c @ 195:a3d71489672f

sip-manual-out: implement tfo-req command
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 17 Mar 2023 17:22:42 -0800
parents 1f9a6cede2c5
children f3164f732b84
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 193
diff changeset
13 tfo_req_cmd(args)
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 193
diff changeset
14 char *args;
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 193
diff changeset
15 {
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 193
diff changeset
16 char *cp;
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 193
diff changeset
17 unsigned sig, codec;
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 193
diff changeset
18
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 193
diff changeset
19 for (cp = args; isspace(*cp); cp++)
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 193
diff changeset
20 ;
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 193
diff changeset
21 if (!isdigit(*cp)) {
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 193
diff changeset
22 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
23 return;
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 193
diff changeset
24 }
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 193
diff changeset
25 sig = strtoul(cp, &cp, 0);
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 193
diff changeset
26 if (!isspace(*cp))
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 193
diff changeset
27 goto inv_syntax;
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 193
diff changeset
28 if (sig > 0xFF) {
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 193
diff changeset
29 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
30 return;
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 193
diff changeset
31 }
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 193
diff changeset
32 while (isspace(*cp))
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 193
diff changeset
33 cp++;
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 193
diff changeset
34 if (!isdigit(*cp))
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 193
diff changeset
35 goto inv_syntax;
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 193
diff changeset
36 codec = strtoul(cp, &cp, 0);
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 193
diff changeset
37 if (*cp && !isspace(*cp))
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 193
diff changeset
38 goto inv_syntax;
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 193
diff changeset
39 if (codec > 14) {
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 193
diff changeset
40 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
41 return;
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 while (isspace(*cp))
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 193
diff changeset
44 cp++;
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 193
diff changeset
45 if (*cp)
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 193
diff changeset
46 goto inv_syntax;
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 193
diff changeset
47 send_tfo_req(sig, codec);
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
123
a36b731bfef9 sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 void
a36b731bfef9 sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 select_stdin()
a36b731bfef9 sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 {
a36b731bfef9 sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 char buf[256], *cp;
a36b731bfef9 sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54
a36b731bfef9 sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 fgets(buf, sizeof buf, stdin);
a36b731bfef9 sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 cp = index(buf, '\n');
a36b731bfef9 sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 if (cp) {
a36b731bfef9 sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 while (cp > buf && isspace(cp[-1]))
a36b731bfef9 sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 cp--;
a36b731bfef9 sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 *cp = '\0';
a36b731bfef9 sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 }
a36b731bfef9 sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 for (cp = buf; isspace(*cp); cp++)
a36b731bfef9 sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 ;
a36b731bfef9 sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 if (!*cp)
a36b731bfef9 sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 return;
a36b731bfef9 sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 if (!strcmp(cp, "b") || !strcasecmp(cp, "bye"))
a36b731bfef9 sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 send_bye_req();
a36b731bfef9 sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 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
69 send_cancel_req();
195
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 193
diff changeset
70 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
71 tfo_req_cmd(cp + 8);
123
a36b731bfef9 sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 else
a36b731bfef9 sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 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
74 }