comparison sip-in/sip_uas.c @ 47:62f39c7cee15

themwi-sip-in skeleton started
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 06 Sep 2022 20:33:56 -0800
parents
children 8117d8ee44a5
comparison
equal deleted inserted replaced
46:5427b26525cd 47:62f39c7cee15
1 /*
2 * Basic UAS functions for themwi-sip-in.
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 <syslog.h>
13 #include <unistd.h>
14 #include "../libsip/parse.h"
15 #include "../libsip/uas_basic.h"
16 #include "../libsip/out_msg.h"
17
18 static void
19 method_tbi(req, ess, sin)
20 struct sip_pkt_rx *req;
21 struct uas_parse_hdrs *ess;
22 struct sockaddr_in *sin;
23 {
24 syslog(LOG_ERR, "SIP method %s remains to be implemented",
25 req->req_method);
26 }
27
28 static void
29 unsupported_method(req, ess, sin)
30 struct sip_pkt_rx *req;
31 struct uas_parse_hdrs *ess;
32 struct sockaddr_in *sin;
33 {
34 struct sip_msg_out resp;
35 int rc;
36
37 start_response_out_msg(&resp, "405 Method not supported");
38 rc = add_resp_basic_headers(&resp, ess, req->req_method);
39 if (rc < 0) {
40 too_long: syslog(LOG_ERR, "sending 405 error: response length exceeded");
41 return;
42 }
43 rc = out_msg_add_header(&resp, "Allow", "INVITE,ACK,CANCEL,BYE");
44 if (rc < 0)
45 goto too_long;
46 out_msg_finish(&resp);
47 sip_tx_packet(&resp, sin);
48 }
49
50 void
51 process_sip_request(msg, sin)
52 struct sip_pkt_rx *msg;
53 struct sockaddr_in *sin;
54 {
55 struct uas_parse_hdrs ess;
56 int rc;
57
58 rc = uas_get_basic_headers(msg, &ess);
59 if (rc < 0) {
60 syslog(LOG_ERR, "SIP %.16s request: bad or missing %s header",
61 msg->req_method, ess.error_field);
62 return;
63 }
64 /* dispatch by method */
65 if (!strcmp(msg->req_method, "INVITE"))
66 method_tbi(msg, &ess, sin);
67 else if (!strcmp(msg->req_method, "ACK"))
68 method_tbi(msg, &ess, sin);
69 else if (!strcmp(msg->req_method, "CANCEL"))
70 method_tbi(msg, &ess, sin);
71 else if (!strcmp(msg->req_method, "BYE"))
72 method_tbi(msg, &ess, sin);
73 else
74 unsupported_method(msg, &ess, sin);
75 }