comparison 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
comparison
equal deleted inserted replaced
47:62f39c7cee15 48:8117d8ee44a5
1 /*
2 * Here we implement our handling of SIP INVITE method.
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 void
19 handle_sip_invite(req, ess, sin)
20 struct sip_pkt_rx *req;
21 struct uas_parse_hdrs *ess;
22 struct sockaddr_in *sin;
23 {
24 char uri_user[13], *called_nanp;
25 struct sip_msg_out resp;
26 int rc;
27
28 /* check for existing Call-ID will go here */
29 /* extract called number from Request-URI */
30 rc = user_from_sip_uri(req->req_uri, uri_user, 12);
31 if (rc < 0) {
32 not_nanp: start_response_out_msg(&resp,
33 "416 Request-URI is not a NANP number");
34 error_resp: rc = add_resp_basic_headers(&resp, ess, req->req_method);
35 if (rc < 0) {
36 syslog(LOG_ERR,
37 "INVITE error response length exceeded");
38 return;
39 }
40 out_msg_finish(&resp);
41 sip_tx_packet(&resp, sin);
42 return;
43 }
44 if (uri_user[0] == '+') {
45 if (grok_number_string(uri_user+1, 0) != 11 ||
46 uri_user[1] != '1')
47 goto not_nanp;
48 called_nanp = uri_user + 2;
49 } else switch (grok_number_string(uri_user)) {
50 case 10:
51 called_nanp = uri_user;
52 break;
53 case 11:
54 if (uri_user[0] != '1')
55 goto not_nanp;
56 called_nanp = uri_user + 1;
57 break;
58 default:
59 goto not_nanp;
60 }
61 if (!is_nanp_valid_prefix(called_nanp))
62 goto not_nanp;
63 /* it is valid NANP - but is it one of ours? */
64 refresh_number_db();
65 if (!is_nanp_locally_owned(called_nanp)) {
66 start_response_out_msg(&resp,
67 "404 Called number does not belong here");
68 goto error_resp;
69 }
70 /*
71 * Remaining checks to be implemented:
72 * Require and Supported headers
73 * SDP message body
74 */
75 }