FreeCalypso > hg > themwi-system-sw
annotate sip-in/invite.c @ 49:dec31b1a8b96
sip-in: check Require and Supported
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 06 Sep 2022 22:57:16 -0800 |
parents | 8117d8ee44a5 |
children | daf1c26d7ae2 |
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" |
49
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
16 #include "../libsip/req_supp.h" |
48
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 #include "../libsip/out_msg.h" |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
49
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
19 extern int cfg_use_100rel; |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
20 |
48
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 void |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 handle_sip_invite(req, ess, sin) |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 struct sip_pkt_rx *req; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 struct uas_parse_hdrs *ess; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 struct sockaddr_in *sin; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 { |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 char uri_user[13], *called_nanp; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 struct sip_msg_out resp; |
49
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
29 struct supported_ext supp_ext; |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
30 char *unsup_ext; |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
31 int ext_100rel_req, ext_100rel_sup, use_100rel; |
48
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 int rc; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 /* check for existing Call-ID will go here */ |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 /* extract called number from Request-URI */ |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 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
|
37 if (rc < 0) { |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 not_nanp: start_response_out_msg(&resp, |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 "416 Request-URI is not a NANP number"); |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 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
|
41 if (rc < 0) { |
49
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
42 error_resp_toolong: syslog(LOG_ERR, |
48
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 "INVITE error response length exceeded"); |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 return; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 } |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 out_msg_finish(&resp); |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 sip_tx_packet(&resp, sin); |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 return; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 } |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 if (uri_user[0] == '+') { |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 if (grok_number_string(uri_user+1, 0) != 11 || |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 uri_user[1] != '1') |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 goto not_nanp; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 called_nanp = uri_user + 2; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 } else switch (grok_number_string(uri_user)) { |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 case 10: |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 called_nanp = uri_user; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 break; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 case 11: |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 if (uri_user[0] != '1') |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 goto not_nanp; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 called_nanp = uri_user + 1; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 break; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 default: |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 goto not_nanp; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 } |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 if (!is_nanp_valid_prefix(called_nanp)) |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 goto not_nanp; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 /* 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
|
70 refresh_number_db(); |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 if (!is_nanp_locally_owned(called_nanp)) { |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 start_response_out_msg(&resp, |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 "404 Called number does not belong here"); |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 goto error_resp; |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 } |
49
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
76 /* check 100rel and catch any unsupported requirements */ |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
77 supp_ext.name = "100rel"; |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
78 supp_ext.req_flag = &ext_100rel_req; |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
79 supp_ext.sup_flag = &ext_100rel_sup; |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
80 ext_100rel_req = ext_100rel_sup = 0; |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
81 rc = parse_require_supported(req, &supp_ext, 1, &unsup_ext); |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
82 if (rc < 0) { |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
83 start_response_out_msg(&resp, "420 Extension not supported"); |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
84 rc = out_msg_add_header(&resp, "Unsupported", unsup_ext); |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
85 if (rc < 0) |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
86 goto error_resp_toolong; |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
87 goto error_resp; |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
88 } |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
89 if (ext_100rel_req) |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
90 use_100rel = 1; |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
91 else if (ext_100rel_sup) |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
92 use_100rel = cfg_use_100rel; |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
93 else |
dec31b1a8b96
sip-in: check Require and Supported
Mychaela Falconia <falcon@freecalypso.org>
parents:
48
diff
changeset
|
94 use_100rel = 0; |
48
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 /* |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 * Remaining checks to be implemented: |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 * SDP message body |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 */ |
8117d8ee44a5
sip-in: beginning of INVITE handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 } |