annotate sip-in/invite.c @ 48:8117d8ee44a5

sip-in: beginning of INVITE handling
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 06 Sep 2022 22:07:51 -0800
parents
children dec31b1a8b96
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
48
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * Here we implement our handling of SIP INVITE method.
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/socket.h>
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <netinet/in.h>
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdlib.h>
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <string.h>
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <strings.h>
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <syslog.h>
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <unistd.h>
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include "../libsip/parse.h"
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include "../libsip/uas_basic.h"
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 #include "../libsip/out_msg.h"
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 void
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 handle_sip_invite(req, ess, sin)
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 struct sip_pkt_rx *req;
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 struct uas_parse_hdrs *ess;
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 struct sockaddr_in *sin;
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 {
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 char uri_user[13], *called_nanp;
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 struct sip_msg_out resp;
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 int rc;
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 /* check for existing Call-ID will go here */
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 /* extract called number from Request-URI */
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 rc = user_from_sip_uri(req->req_uri, uri_user, 12);
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 if (rc < 0) {
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 not_nanp: start_response_out_msg(&resp,
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 "416 Request-URI is not a NANP number");
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 error_resp: rc = add_resp_basic_headers(&resp, ess, req->req_method);
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 if (rc < 0) {
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 syslog(LOG_ERR,
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 "INVITE error response length exceeded");
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 return;
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 }
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 out_msg_finish(&resp);
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 sip_tx_packet(&resp, sin);
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 return;
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 }
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 if (uri_user[0] == '+') {
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 if (grok_number_string(uri_user+1, 0) != 11 ||
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 uri_user[1] != '1')
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 goto not_nanp;
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 called_nanp = uri_user + 2;
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 } else switch (grok_number_string(uri_user)) {
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 case 10:
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 called_nanp = uri_user;
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 break;
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 case 11:
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 if (uri_user[0] != '1')
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 goto not_nanp;
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 called_nanp = uri_user + 1;
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 break;
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 default:
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 goto not_nanp;
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 }
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 if (!is_nanp_valid_prefix(called_nanp))
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 goto not_nanp;
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 /* it is valid NANP - but is it one of ours? */
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 refresh_number_db();
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 if (!is_nanp_locally_owned(called_nanp)) {
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 start_response_out_msg(&resp,
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 "404 Called number does not belong here");
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 goto error_resp;
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 }
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 /*
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 * Remaining checks to be implemented:
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 * Require and Supported headers
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 * SDP message body
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 */
8117d8ee44a5 sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 }