1use std::os::raw::{c_char, c_int, c_uint, c_void};
2
3pub type switch_size_t = usize;
4pub type switch_bool_t = c_uint;
5pub type switch_module_flag_t = u32;
6
7pub const SWITCH_FALSE: switch_bool_t = 0;
8pub const SWITCH_TRUE: switch_bool_t = 1;
9pub const SWITCH_API_VERSION: c_int = 5;
10
11#[repr(C)]
12#[derive(Debug, Copy, Clone, PartialEq, Eq)]
13pub enum switch_status_t {
14 SWITCH_STATUS_SUCCESS = 0,
15 SWITCH_STATUS_FALSE = 1,
16 SWITCH_STATUS_TIMEOUT = 2,
17 SWITCH_STATUS_RESTART = 3,
18 SWITCH_STATUS_INTR = 4,
19 SWITCH_STATUS_NOTIMPL = 5,
20 SWITCH_STATUS_MEMERR = 6,
21 SWITCH_STATUS_NOOP = 7,
22 SWITCH_STATUS_RESAMPLE = 8,
23 SWITCH_STATUS_GENERR = 9,
24 SWITCH_STATUS_INUSE = 10,
25 SWITCH_STATUS_BREAK = 11,
26 SWITCH_STATUS_SOCKERR = 12,
27 SWITCH_STATUS_MORE_DATA = 13,
28 SWITCH_STATUS_NOTFOUND = 14,
29 SWITCH_STATUS_UNLOAD = 15,
30 SWITCH_STATUS_NOUNLOAD = 16,
31 SWITCH_STATUS_IGNORE = 17,
32 SWITCH_STATUS_TOO_SMALL = 18,
33 SWITCH_STATUS_FOUND = 19,
34 SWITCH_STATUS_CONTINUE = 20,
35 SWITCH_STATUS_TERM = 21,
36 SWITCH_STATUS_NOT_INITALIZED = 22,
37 SWITCH_STATUS_TOO_LATE = 23,
38 SWITCH_STATUS_XBREAK = 35,
39 SWITCH_STATUS_WINBREAK = 730035,
40}
41
42#[repr(C)]
43#[derive(Debug, Copy, Clone, PartialEq, Eq)]
44pub enum switch_module_interface_name_t {
45 SWITCH_ENDPOINT_INTERFACE = 0,
46 SWITCH_TIMER_INTERFACE = 1,
47 SWITCH_DIALPLAN_INTERFACE = 2,
48 SWITCH_CODEC_INTERFACE = 3,
49 SWITCH_APPLICATION_INTERFACE = 4,
50 SWITCH_API_INTERFACE = 5,
51 SWITCH_FILE_INTERFACE = 6,
52 SWITCH_SPEECH_INTERFACE = 7,
53 SWITCH_DIRECTORY_INTERFACE = 8,
54 SWITCH_CHAT_INTERFACE = 9,
55 SWITCH_SAY_INTERFACE = 10,
56 SWITCH_ASR_INTERFACE = 11,
57 SWITCH_MANAGEMENT_INTERFACE = 12,
58 SWITCH_LIMIT_INTERFACE = 13,
59 SWITCH_CHAT_APPLICATION_INTERFACE = 14,
60 SWITCH_JSON_API_INTERFACE = 15,
61 SWITCH_DATABASE_INTERFACE = 16,
62}
63
64#[repr(C)]
65#[derive(Debug, Copy, Clone, PartialEq, Eq)]
66pub enum switch_stack_t {
67 SWITCH_STACK_BOTTOM = 1,
68 SWITCH_STACK_TOP = 2,
69 SWITCH_STACK_UNSHIFT = 4,
70 SWITCH_STACK_PUSH = 8,
71}
72
73#[repr(C)]
74#[derive(Debug, Copy, Clone, PartialEq, Eq)]
75pub enum switch_event_types_t {
76 SWITCH_EVENT_CUSTOM = 0,
77 SWITCH_EVENT_CLONE = 1,
78 SWITCH_EVENT_CHANNEL_CREATE = 2,
79 SWITCH_EVENT_CHANNEL_DESTROY = 3,
80 SWITCH_EVENT_CHANNEL_STATE = 4,
81 SWITCH_EVENT_CHANNEL_CALLSTATE = 5,
82 SWITCH_EVENT_CHANNEL_ANSWER = 6,
83 SWITCH_EVENT_CHANNEL_HANGUP = 7,
84 SWITCH_EVENT_CHANNEL_HANGUP_COMPLETE = 8,
85 SWITCH_EVENT_CHANNEL_EXECUTE = 9,
86 SWITCH_EVENT_CHANNEL_EXECUTE_COMPLETE = 10,
87}
88
89#[repr(C)]
90pub struct switch_memory_pool_t {
91 _private: [u8; 0],
92}
93
94#[repr(C)]
95pub struct switch_core_session_t {
96 _private: [u8; 0],
97}
98
99#[repr(C)]
100pub struct switch_event_t {
101 _private: [u8; 0],
102}
103
104#[repr(C)]
105pub struct switch_thread_rwlock_t {
106 _private: [u8; 0],
107}
108
109#[repr(C)]
110pub struct switch_mutex_t {
111 _private: [u8; 0],
112}
113
114pub type switch_stream_handle_read_function_t =
115 Option<unsafe extern "C" fn(handle: *mut switch_stream_handle_t, len: *mut c_int) -> *mut u8>;
116pub type switch_stream_handle_write_function_t = Option<
117 unsafe extern "C" fn(
118 handle: *mut switch_stream_handle_t,
119 fmt: *const c_char,
120 ...
121 ) -> switch_status_t,
122>;
123pub type switch_stream_handle_raw_write_function_t = Option<
124 unsafe extern "C" fn(
125 handle: *mut switch_stream_handle_t,
126 data: *mut u8,
127 datalen: switch_size_t,
128 ) -> switch_status_t,
129>;
130
131#[repr(C)]
132pub struct switch_stream_handle_t {
133 pub read_function: switch_stream_handle_read_function_t,
134 pub write_function: switch_stream_handle_write_function_t,
135 pub raw_write_function: switch_stream_handle_raw_write_function_t,
136 pub data: *mut c_void,
137 pub end: *mut c_void,
138 pub data_size: switch_size_t,
139 pub data_len: switch_size_t,
140 pub alloc_len: switch_size_t,
141 pub alloc_chunk: switch_size_t,
142 pub param_event: *mut switch_event_t,
143}
144
145pub type switch_api_function_t = Option<
146 unsafe extern "C" fn(
147 cmd: *const c_char,
148 session: *mut switch_core_session_t,
149 stream: *mut switch_stream_handle_t,
150 ) -> switch_status_t,
151>;
152
153pub type switch_module_load_t = Option<
154 unsafe extern "C" fn(
155 module_interface: *mut *mut switch_loadable_module_interface_t,
156 pool: *mut switch_memory_pool_t,
157 ) -> switch_status_t,
158>;
159pub type switch_module_runtime_t = Option<unsafe extern "C" fn() -> switch_status_t>;
160pub type switch_module_shutdown_t = Option<unsafe extern "C" fn() -> switch_status_t>;
161
162#[repr(C)]
163pub struct switch_loadable_module_function_table_t {
164 pub switch_api_version: c_int,
165 pub load: switch_module_load_t,
166 pub shutdown: switch_module_shutdown_t,
167 pub runtime: switch_module_runtime_t,
168 pub flags: switch_module_flag_t,
169}
170
171#[repr(C)]
172pub struct switch_loadable_module_interface_t {
173 pub module_name: *const c_char,
174 pub endpoint_interface: *mut c_void,
175 pub timer_interface: *mut c_void,
176 pub dialplan_interface: *mut c_void,
177 pub codec_interface: *mut c_void,
178 pub application_interface: *mut c_void,
179 pub chat_application_interface: *mut c_void,
180 pub api_interface: *mut switch_api_interface_t,
181 pub json_api_interface: *mut c_void,
182 pub file_interface: *mut c_void,
183 pub speech_interface: *mut c_void,
184 pub directory_interface: *mut c_void,
185 pub chat_interface: *mut c_void,
186 pub say_interface: *mut c_void,
187 pub asr_interface: *mut c_void,
188 pub management_interface: *mut c_void,
189 pub limit_interface: *mut c_void,
190 pub database_interface: *mut c_void,
191 pub rwlock: *mut switch_thread_rwlock_t,
192 pub refs: c_int,
193 pub pool: *mut switch_memory_pool_t,
194}
195
196#[repr(C)]
197pub struct switch_api_interface_t {
198 pub interface_name: *const c_char,
199 pub desc: *const c_char,
200 pub function: switch_api_function_t,
201 pub syntax: *const c_char,
202 pub rwlock: *mut switch_thread_rwlock_t,
203 pub refs: c_int,
204 pub reflock: *mut switch_mutex_t,
205 pub parent: *mut switch_loadable_module_interface_t,
206 pub next: *mut switch_api_interface_t,
207}
208
209unsafe extern "C" {
210 pub fn switch_loadable_module_create_module_interface(
211 pool: *mut switch_memory_pool_t,
212 name: *const c_char,
213 ) -> *mut switch_loadable_module_interface_t;
214
215 pub fn switch_loadable_module_create_interface(
216 module: *mut switch_loadable_module_interface_t,
217 iname: switch_module_interface_name_t,
218 ) -> *mut c_void;
219
220 pub fn switch_event_create_subclass_detailed(
221 file: *const c_char,
222 func: *const c_char,
223 line: c_int,
224 event: *mut *mut switch_event_t,
225 event_id: switch_event_types_t,
226 subclass_name: *const c_char,
227 ) -> switch_status_t;
228
229 pub fn switch_event_add_header_string(
230 event: *mut switch_event_t,
231 stack: switch_stack_t,
232 header_name: *const c_char,
233 data: *const c_char,
234 ) -> switch_status_t;
235
236 pub fn switch_event_fire_detailed(
237 file: *const c_char,
238 func: *const c_char,
239 line: c_int,
240 event: *mut *mut switch_event_t,
241 user_data: *mut c_void,
242 ) -> switch_status_t;
243}