comparison sip-manual-out/disc_cmd.c @ 123:a36b731bfef9

sip-manual-out: implement sending BYE and CANCEL
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 29 Sep 2022 17:21:11 -0800
parents
children f8a33603288f
comparison
equal deleted inserted replaced
122:07e4cc5f824c 123:a36b731bfef9
1 /*
2 * In this module we implement user-driven sending of CANCEL and BYE
3 * disconnection requests.
4 */
5
6 #include <sys/types.h>
7 #include <sys/socket.h>
8 #include <netinet/in.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <strings.h>
13 #include "../libsip/out_msg.h"
14
15 extern struct sockaddr_in sip_dest_sin;
16 extern char to_uri[];
17
18 send_cancel_req()
19 {
20 struct sip_msg_out msg;
21 int rc;
22
23 rc = start_request_out_msg(&msg, "CANCEL", to_uri);
24 if (rc < 0) {
25 msg_size_err: fprintf(stderr, "composing CANCEL message: size error\n");
26 return(-1);
27 }
28 rc = add_req_boilerplate(&msg, "1 CANCEL", 0);
29 if (rc < 0)
30 goto msg_size_err;
31 out_msg_finish(&msg);
32 sip_tx_packet(&msg, &sip_dest_sin);
33 return(0);
34 }
35
36 send_bye_req()
37 {
38 struct sip_msg_out msg;
39 int rc;
40
41 rc = start_request_out_msg(&msg, "BYE", to_uri);
42 if (rc < 0) {
43 msg_size_err: fprintf(stderr, "composing BYE message: size error\n");
44 return(-1);
45 }
46 rc = add_req_boilerplate(&msg, "2 BYE", 1);
47 if (rc < 0)
48 goto msg_size_err;
49 out_msg_finish(&msg);
50 sip_tx_packet(&msg, &sip_dest_sin);
51 return(0);
52 }
53
54 void
55 select_stdin()
56 {
57 char buf[256], *cp;
58
59 fgets(buf, sizeof buf, stdin);
60 cp = index(buf, '\n');
61 if (cp) {
62 while (cp > buf && isspace(cp[-1]))
63 cp--;
64 *cp = '\0';
65 }
66 for (cp = buf; isspace(*cp); cp++)
67 ;
68 if (!*cp)
69 return;
70 if (!strcmp(cp, "b") || !strcasecmp(cp, "bye"))
71 send_bye_req();
72 else if (!strcmp(cp, "c") || !strcasecmp(cp, "cancel"))
73 send_cancel_req();
74 else
75 fprintf(stderr, "error: non-understood stdin command\n");
76 }