FreeCalypso > hg > themwi-system-sw
comparison sip-manual-out/uas.c @ 71:d74b545a3c2a
sip-manual-out: new test program
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 20 Sep 2022 10:14:18 -0800 |
parents | sip-in/sip_uas.c@8cf85edca543 |
children | dd845c4933e1 |
comparison
equal
deleted
inserted
replaced
70:47976db01894 | 71:d74b545a3c2a |
---|---|
1 /* | |
2 * UAS for sip-manual-out. | |
3 */ | |
4 | |
5 #include <sys/types.h> | |
6 #include <sys/socket.h> | |
7 #include <netinet/in.h> | |
8 #include <stdio.h> | |
9 #include <stdlib.h> | |
10 #include <string.h> | |
11 #include <strings.h> | |
12 #include "../libsip/parse.h" | |
13 #include "../libsip/uas_basic.h" | |
14 #include "../libsip/out_msg.h" | |
15 | |
16 extern char call_id[]; | |
17 | |
18 static void | |
19 bye_correct_call(req, ess, sin) | |
20 struct sip_pkt_rx *req; | |
21 struct uas_parse_hdrs *ess; | |
22 struct sockaddr_in *sin; | |
23 { | |
24 struct sip_msg_out resp; | |
25 int rc; | |
26 | |
27 printf("Received BYE for our call, responding with 200\n"); | |
28 start_response_out_msg(&resp, "200 OK"); | |
29 rc = add_resp_basic_headers(&resp, ess, req->req_method); | |
30 if (rc < 0) { | |
31 fprintf(stderr, "sending 200 response: msg length exceeded\n"); | |
32 return; | |
33 } | |
34 out_msg_finish(&resp); | |
35 sip_tx_packet(&resp, sin); | |
36 } | |
37 | |
38 static void | |
39 bye_unknown_call(req, ess, sin) | |
40 struct sip_pkt_rx *req; | |
41 struct uas_parse_hdrs *ess; | |
42 struct sockaddr_in *sin; | |
43 { | |
44 struct sip_msg_out resp; | |
45 int rc; | |
46 | |
47 printf("Received BYE for unknown call, responding with 481\n"); | |
48 start_response_out_msg(&resp, "481 Call-ID not found"); | |
49 rc = add_resp_basic_headers(&resp, ess, req->req_method); | |
50 if (rc < 0) { | |
51 fprintf(stderr, "sending 481 response: msg length exceeded\n"); | |
52 return; | |
53 } | |
54 out_msg_finish(&resp); | |
55 sip_tx_packet(&resp, sin); | |
56 } | |
57 | |
58 static void | |
59 handle_bye(req, ess, sin) | |
60 struct sip_pkt_rx *req; | |
61 struct uas_parse_hdrs *ess; | |
62 struct sockaddr_in *sin; | |
63 { | |
64 if (!strcmp(ess->call_id, call_id)) | |
65 bye_correct_call(req, ess, sin); | |
66 else | |
67 bye_unknown_call(req, ess, sin); | |
68 } | |
69 | |
70 static void | |
71 unsupported_method(req, ess, sin) | |
72 struct sip_pkt_rx *req; | |
73 struct uas_parse_hdrs *ess; | |
74 struct sockaddr_in *sin; | |
75 { | |
76 struct sip_msg_out resp; | |
77 int rc; | |
78 | |
79 printf("SIP %.16s request: unsupported method\n", req->req_method); | |
80 start_response_out_msg(&resp, "501 Method not supported"); | |
81 rc = add_resp_basic_headers(&resp, ess, req->req_method); | |
82 if (rc < 0) { | |
83 too_long: fprintf(stderr, | |
84 "sending 501 error: response length exceeded\n"); | |
85 return; | |
86 } | |
87 rc = out_msg_add_header(&resp, "Allow", "BYE"); | |
88 if (rc < 0) | |
89 goto too_long; | |
90 out_msg_finish(&resp); | |
91 sip_tx_packet(&resp, sin); | |
92 } | |
93 | |
94 void | |
95 process_sip_request(msg, sin) | |
96 struct sip_pkt_rx *msg; | |
97 struct sockaddr_in *sin; | |
98 { | |
99 struct uas_parse_hdrs ess; | |
100 int rc; | |
101 | |
102 rc = uas_get_basic_headers(msg, &ess); | |
103 if (rc < 0) { | |
104 printf("SIP %.16s request: bad or missing %s header\n", | |
105 msg->req_method, ess.error_field); | |
106 return; | |
107 } | |
108 /* dispatch by method */ | |
109 if (!strcmp(msg->req_method, "BYE")) | |
110 handle_bye(msg, &ess, sin); | |
111 else | |
112 unsupported_method(msg, &ess, sin); | |
113 } |