/src/suricata7/rust/src/sip/detect.rs
Line | Count | Source |
1 | | /* Copyright (C) 2019 Open Information Security Foundation |
2 | | * |
3 | | * You can copy, redistribute or modify this Program under the terms of |
4 | | * the GNU General Public License version 2 as published by the Free |
5 | | * Software Foundation. |
6 | | * |
7 | | * This program is distributed in the hope that it will be useful, |
8 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
9 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
10 | | * GNU General Public License for more details. |
11 | | * |
12 | | * You should have received a copy of the GNU General Public License |
13 | | * version 2 along with this program; if not, write to the Free Software |
14 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
15 | | * 02110-1301, USA. |
16 | | */ |
17 | | |
18 | | // written by Giuseppe Longo <giuseppe@glongo.it> |
19 | | |
20 | | use crate::core::Direction; |
21 | | use crate::sip::sip::SIPTransaction; |
22 | | use std::ptr; |
23 | | |
24 | | #[no_mangle] |
25 | 749 | pub unsafe extern "C" fn rs_sip_tx_get_method( |
26 | 749 | tx: &mut SIPTransaction, buffer: *mut *const u8, buffer_len: *mut u32, |
27 | 749 | ) -> u8 { |
28 | 749 | if let Some(ref r) = tx.request { |
29 | 475 | let m = &r.method; |
30 | 475 | if !m.is_empty() { |
31 | 475 | *buffer = m.as_ptr(); |
32 | 475 | *buffer_len = m.len() as u32; |
33 | 475 | return 1; |
34 | 0 | } |
35 | 274 | } |
36 | | |
37 | 274 | *buffer = ptr::null(); |
38 | 274 | *buffer_len = 0; |
39 | | |
40 | 274 | return 0; |
41 | 749 | } |
42 | | |
43 | | #[no_mangle] |
44 | 0 | pub unsafe extern "C" fn rs_sip_tx_get_uri( |
45 | 0 | tx: &mut SIPTransaction, buffer: *mut *const u8, buffer_len: *mut u32, |
46 | 0 | ) -> u8 { |
47 | 0 | if let Some(ref r) = tx.request { |
48 | 0 | let p = &r.path; |
49 | 0 | if !p.is_empty() { |
50 | 0 | *buffer = p.as_ptr(); |
51 | 0 | *buffer_len = p.len() as u32; |
52 | 0 | return 1; |
53 | 0 | } |
54 | 0 | } |
55 | | |
56 | 0 | *buffer = ptr::null(); |
57 | 0 | *buffer_len = 0; |
58 | | |
59 | 0 | return 0; |
60 | 0 | } |
61 | | |
62 | | #[no_mangle] |
63 | 0 | pub unsafe extern "C" fn rs_sip_tx_get_protocol( |
64 | 0 | tx: &mut SIPTransaction, buffer: *mut *const u8, buffer_len: *mut u32, direction: u8, |
65 | 0 | ) -> u8 { |
66 | 0 | match direction.into() { |
67 | | Direction::ToServer => { |
68 | 0 | if let Some(ref r) = tx.request { |
69 | 0 | let v = &r.version; |
70 | 0 | if !v.is_empty() { |
71 | 0 | *buffer = v.as_ptr(); |
72 | 0 | *buffer_len = v.len() as u32; |
73 | 0 | return 1; |
74 | 0 | } |
75 | 0 | } |
76 | | } |
77 | | Direction::ToClient => { |
78 | 0 | if let Some(ref r) = tx.response { |
79 | 0 | let v = &r.version; |
80 | 0 | if !v.is_empty() { |
81 | 0 | *buffer = v.as_ptr(); |
82 | 0 | *buffer_len = v.len() as u32; |
83 | 0 | return 1; |
84 | 0 | } |
85 | 0 | } |
86 | | } |
87 | | } |
88 | | |
89 | 0 | *buffer = ptr::null(); |
90 | 0 | *buffer_len = 0; |
91 | | |
92 | 0 | return 0; |
93 | 0 | } |
94 | | |
95 | | #[no_mangle] |
96 | 96 | pub unsafe extern "C" fn rs_sip_tx_get_stat_code( |
97 | 96 | tx: &mut SIPTransaction, buffer: *mut *const u8, buffer_len: *mut u32, |
98 | 96 | ) -> u8 { |
99 | 96 | if let Some(ref r) = tx.response { |
100 | 43 | let c = &r.code; |
101 | 43 | if !c.is_empty() { |
102 | 43 | *buffer = c.as_ptr(); |
103 | 43 | *buffer_len = c.len() as u32; |
104 | 43 | return 1; |
105 | 0 | } |
106 | 53 | } |
107 | | |
108 | 53 | *buffer = ptr::null(); |
109 | 53 | *buffer_len = 0; |
110 | | |
111 | 53 | return 0; |
112 | 96 | } |
113 | | |
114 | | #[no_mangle] |
115 | 0 | pub unsafe extern "C" fn rs_sip_tx_get_stat_msg( |
116 | 0 | tx: &mut SIPTransaction, buffer: *mut *const u8, buffer_len: *mut u32, |
117 | 0 | ) -> u8 { |
118 | 0 | if let Some(ref r) = tx.response { |
119 | 0 | let re = &r.reason; |
120 | 0 | if !re.is_empty() { |
121 | 0 | *buffer = re.as_ptr(); |
122 | 0 | *buffer_len = re.len() as u32; |
123 | 0 | return 1; |
124 | 0 | } |
125 | 0 | } |
126 | | |
127 | 0 | *buffer = ptr::null(); |
128 | 0 | *buffer_len = 0; |
129 | | |
130 | 0 | return 0; |
131 | 0 | } |
132 | | |
133 | | #[no_mangle] |
134 | 0 | pub unsafe extern "C" fn rs_sip_tx_get_request_line( |
135 | 0 | tx: &mut SIPTransaction, buffer: *mut *const u8, buffer_len: *mut u32, |
136 | 0 | ) -> u8 { |
137 | 0 | if let Some(ref r) = tx.request_line { |
138 | 0 | if !r.is_empty() { |
139 | 0 | *buffer = r.as_ptr(); |
140 | 0 | *buffer_len = r.len() as u32; |
141 | 0 | return 1; |
142 | 0 | } |
143 | 0 | } |
144 | | |
145 | 0 | *buffer = ptr::null(); |
146 | 0 | *buffer_len = 0; |
147 | | |
148 | 0 | return 0; |
149 | 0 | } |
150 | | |
151 | | #[no_mangle] |
152 | 0 | pub unsafe extern "C" fn rs_sip_tx_get_response_line( |
153 | 0 | tx: &mut SIPTransaction, buffer: *mut *const u8, buffer_len: *mut u32, |
154 | 0 | ) -> u8 { |
155 | 0 | if let Some(ref r) = tx.response_line { |
156 | 0 | if !r.is_empty() { |
157 | 0 | *buffer = r.as_ptr(); |
158 | 0 | *buffer_len = r.len() as u32; |
159 | 0 | return 1; |
160 | 0 | } |
161 | 0 | } |
162 | | |
163 | 0 | *buffer = ptr::null(); |
164 | 0 | *buffer_len = 0; |
165 | | |
166 | 0 | return 0; |
167 | 0 | } |