FreeCalypso > hg > themwi-system-sw
annotate sip-manual-out/user_cmd.c @ 193:1f9a6cede2c5
sip-manual-out: split user_cmd.c from disc_cmd.c
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 17 Mar 2023 14:31:54 -0800 |
parents | sip-manual-out/disc_cmd.c@f8a33603288f |
children | a3d71489672f |
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 |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 void |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 select_stdin() |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 { |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 char buf[256], *cp; |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 fgets(buf, sizeof buf, stdin); |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 cp = index(buf, '\n'); |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 if (cp) { |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 while (cp > buf && isspace(cp[-1])) |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 cp--; |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 *cp = '\0'; |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 } |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 for (cp = buf; isspace(*cp); cp++) |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 ; |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 if (!*cp) |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 return; |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 if (!strcmp(cp, "b") || !strcasecmp(cp, "bye")) |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 send_bye_req(); |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 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
|
31 send_cancel_req(); |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 else |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 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
|
34 } |