comparison 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
comparison
equal deleted inserted replaced
48:8117d8ee44a5 49:dec31b1a8b96
11 #include <strings.h> 11 #include <strings.h>
12 #include <syslog.h> 12 #include <syslog.h>
13 #include <unistd.h> 13 #include <unistd.h>
14 #include "../libsip/parse.h" 14 #include "../libsip/parse.h"
15 #include "../libsip/uas_basic.h" 15 #include "../libsip/uas_basic.h"
16 #include "../libsip/req_supp.h"
16 #include "../libsip/out_msg.h" 17 #include "../libsip/out_msg.h"
18
19 extern int cfg_use_100rel;
17 20
18 void 21 void
19 handle_sip_invite(req, ess, sin) 22 handle_sip_invite(req, ess, sin)
20 struct sip_pkt_rx *req; 23 struct sip_pkt_rx *req;
21 struct uas_parse_hdrs *ess; 24 struct uas_parse_hdrs *ess;
22 struct sockaddr_in *sin; 25 struct sockaddr_in *sin;
23 { 26 {
24 char uri_user[13], *called_nanp; 27 char uri_user[13], *called_nanp;
25 struct sip_msg_out resp; 28 struct sip_msg_out resp;
29 struct supported_ext supp_ext;
30 char *unsup_ext;
31 int ext_100rel_req, ext_100rel_sup, use_100rel;
26 int rc; 32 int rc;
27 33
28 /* check for existing Call-ID will go here */ 34 /* check for existing Call-ID will go here */
29 /* extract called number from Request-URI */ 35 /* extract called number from Request-URI */
30 rc = user_from_sip_uri(req->req_uri, uri_user, 12); 36 rc = user_from_sip_uri(req->req_uri, uri_user, 12);
31 if (rc < 0) { 37 if (rc < 0) {
32 not_nanp: start_response_out_msg(&resp, 38 not_nanp: start_response_out_msg(&resp,
33 "416 Request-URI is not a NANP number"); 39 "416 Request-URI is not a NANP number");
34 error_resp: rc = add_resp_basic_headers(&resp, ess, req->req_method); 40 error_resp: rc = add_resp_basic_headers(&resp, ess, req->req_method);
35 if (rc < 0) { 41 if (rc < 0) {
36 syslog(LOG_ERR, 42 error_resp_toolong: syslog(LOG_ERR,
37 "INVITE error response length exceeded"); 43 "INVITE error response length exceeded");
38 return; 44 return;
39 } 45 }
40 out_msg_finish(&resp); 46 out_msg_finish(&resp);
41 sip_tx_packet(&resp, sin); 47 sip_tx_packet(&resp, sin);
65 if (!is_nanp_locally_owned(called_nanp)) { 71 if (!is_nanp_locally_owned(called_nanp)) {
66 start_response_out_msg(&resp, 72 start_response_out_msg(&resp,
67 "404 Called number does not belong here"); 73 "404 Called number does not belong here");
68 goto error_resp; 74 goto error_resp;
69 } 75 }
76 /* check 100rel and catch any unsupported requirements */
77 supp_ext.name = "100rel";
78 supp_ext.req_flag = &ext_100rel_req;
79 supp_ext.sup_flag = &ext_100rel_sup;
80 ext_100rel_req = ext_100rel_sup = 0;
81 rc = parse_require_supported(req, &supp_ext, 1, &unsup_ext);
82 if (rc < 0) {
83 start_response_out_msg(&resp, "420 Extension not supported");
84 rc = out_msg_add_header(&resp, "Unsupported", unsup_ext);
85 if (rc < 0)
86 goto error_resp_toolong;
87 goto error_resp;
88 }
89 if (ext_100rel_req)
90 use_100rel = 1;
91 else if (ext_100rel_sup)
92 use_100rel = cfg_use_100rel;
93 else
94 use_100rel = 0;
70 /* 95 /*
71 * Remaining checks to be implemented: 96 * Remaining checks to be implemented:
72 * Require and Supported headers
73 * SDP message body 97 * SDP message body
74 */ 98 */
75 } 99 }