annotate sip-out/sip_uas.c @ 198:cf1ba5d65188

mgw: start using project-global rtp_defs.h
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 29 Mar 2023 20:06:40 -0800
parents e54b0a9e322f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
47
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
154
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 108
diff changeset
2 * Basic UAS functions for themwi-sip-out.
47
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/socket.h>
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <netinet/in.h>
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdlib.h>
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <string.h>
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <strings.h>
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <syslog.h>
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include "../libsip/parse.h"
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include "../libsip/uas_basic.h"
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include "../libsip/out_msg.h"
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 static void
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 unsupported_method(req, ess, sin)
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 struct sip_pkt_rx *req;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 struct uas_parse_hdrs *ess;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 struct sockaddr_in *sin;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 {
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 struct sip_msg_out resp;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 int rc;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25
48
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 47
diff changeset
26 start_response_out_msg(&resp, "501 Method not supported");
47
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 rc = add_resp_basic_headers(&resp, ess, req->req_method);
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 if (rc < 0) {
48
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents: 47
diff changeset
29 too_long: syslog(LOG_ERR, "sending 501 error: response length exceeded");
47
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 return;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 }
154
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 108
diff changeset
32 rc = out_msg_add_header(&resp, "Allow", "INVITE,ACK,BYE");
47
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 if (rc < 0)
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 goto too_long;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 out_msg_finish(&resp);
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 sip_tx_packet(&resp, sin);
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 }
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 void
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 process_sip_request(msg, sin)
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 struct sip_pkt_rx *msg;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 struct sockaddr_in *sin;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 {
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 struct uas_parse_hdrs ess;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 int rc;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 rc = uas_get_basic_headers(msg, &ess);
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 if (rc < 0) {
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 syslog(LOG_ERR, "SIP %.16s request: bad or missing %s header",
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 msg->req_method, ess.error_field);
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 return;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 }
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 /* dispatch by method */
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 if (!strcmp(msg->req_method, "INVITE"))
154
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 108
diff changeset
55 handle_invite_req(msg, &ess, sin);
47
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 else if (!strcmp(msg->req_method, "ACK"))
154
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 108
diff changeset
57 return; /* no handling required */
47
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 else if (!strcmp(msg->req_method, "BYE"))
154
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 108
diff changeset
59 handle_bye_req(msg, &ess, sin);
47
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 else
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 unsupported_method(msg, &ess, sin);
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 }