FreeCalypso > hg > sipout-test-utils
comparison test-fsk/uas.c @ 2:26383ed8b79f
test-fsk: starting as a copy of test-voice
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 04 Mar 2024 21:03:19 -0800 |
parents | test-voice/uas.c@35c0d9f03c0a |
children |
comparison
equal
deleted
inserted
replaced
1:38c4d09882f6 | 2:26383ed8b79f |
---|---|
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 static void | |
17 unsupported_method(req, ess, sin) | |
18 struct sip_pkt_rx *req; | |
19 struct uas_parse_hdrs *ess; | |
20 struct sockaddr_in *sin; | |
21 { | |
22 struct sip_msg_out resp; | |
23 int rc; | |
24 | |
25 printf("SIP %.16s request: unsupported method\n", req->req_method); | |
26 start_response_out_msg(&resp, "501 Method not supported"); | |
27 rc = add_resp_basic_headers(&resp, ess, req->req_method); | |
28 if (rc < 0) { | |
29 too_long: fprintf(stderr, | |
30 "sending 501 error: response length exceeded\n"); | |
31 return; | |
32 } | |
33 rc = out_msg_add_header(&resp, "Allow", "INVITE,ACK,BYE"); | |
34 if (rc < 0) | |
35 goto too_long; | |
36 out_msg_finish(&resp); | |
37 sip_tx_packet(&resp, sin); | |
38 } | |
39 | |
40 void | |
41 process_sip_request(msg, sin) | |
42 struct sip_pkt_rx *msg; | |
43 struct sockaddr_in *sin; | |
44 { | |
45 struct uas_parse_hdrs ess; | |
46 int rc; | |
47 | |
48 rc = uas_get_basic_headers(msg, &ess); | |
49 if (rc < 0) { | |
50 printf("SIP %.16s request: bad or missing %s header\n", | |
51 msg->req_method, ess.error_field); | |
52 return; | |
53 } | |
54 /* dispatch by method */ | |
55 if (!strcmp(msg->req_method, "INVITE")) | |
56 handle_invite_req(msg, &ess, sin); | |
57 else if (!strcmp(msg->req_method, "ACK")) | |
58 printf("Received ACK request, swallowing it\n"); | |
59 else if (!strcmp(msg->req_method, "BYE")) | |
60 handle_bye_req(msg, &ess, sin); | |
61 else | |
62 unsupported_method(msg, &ess, sin); | |
63 } |