FreeCalypso > hg > themwi-system-sw
annotate sip-manual-out/disc_cmd.c @ 192:f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 17 Mar 2023 13:45:31 -0800 |
parents | a36b731bfef9 |
children | 1f9a6cede2c5 |
rev | line source |
---|---|
123
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * In this module we implement user-driven sending of CANCEL and BYE |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * disconnection requests. |
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 |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/types.h> |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <sys/socket.h> |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <netinet/in.h> |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdio.h> |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdlib.h> |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <string.h> |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <strings.h> |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include "../libsip/out_msg.h" |
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 extern struct sockaddr_in sip_dest_sin; |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 extern char to_uri[]; |
192
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
123
diff
changeset
|
17 extern int rtp_out_enable; |
123
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 send_cancel_req() |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 { |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 struct sip_msg_out msg; |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 int rc; |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 |
192
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
123
diff
changeset
|
24 rtp_out_enable = 0; |
123
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 rc = start_request_out_msg(&msg, "CANCEL", to_uri); |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 if (rc < 0) { |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 msg_size_err: fprintf(stderr, "composing CANCEL message: size error\n"); |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 return(-1); |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 } |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 rc = add_req_boilerplate(&msg, "1 CANCEL", 0); |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 if (rc < 0) |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 goto msg_size_err; |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 out_msg_finish(&msg); |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 sip_tx_packet(&msg, &sip_dest_sin); |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 return(0); |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 } |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 send_bye_req() |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 { |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 struct sip_msg_out msg; |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 int rc; |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 |
192
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
123
diff
changeset
|
43 rtp_out_enable = 0; |
123
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 rc = start_request_out_msg(&msg, "BYE", to_uri); |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 if (rc < 0) { |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 msg_size_err: fprintf(stderr, "composing BYE message: size error\n"); |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 return(-1); |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 } |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 rc = add_req_boilerplate(&msg, "2 BYE", 1); |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 if (rc < 0) |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 goto msg_size_err; |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 out_msg_finish(&msg); |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 sip_tx_packet(&msg, &sip_dest_sin); |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 return(0); |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 } |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 void |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 select_stdin() |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 { |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 char buf[256], *cp; |
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 fgets(buf, sizeof buf, stdin); |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 cp = index(buf, '\n'); |
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 while (cp > buf && isspace(cp[-1])) |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 cp--; |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 *cp = '\0'; |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 } |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 for (cp = buf; isspace(*cp); cp++) |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 ; |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 if (!*cp) |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 return; |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 if (!strcmp(cp, "b") || !strcasecmp(cp, "bye")) |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 send_bye_req(); |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 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
|
76 send_cancel_req(); |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 else |
a36b731bfef9
sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 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
|
79 } |