1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
|
extern crate libc;
use std::os::raw::{c_char, c_int, c_void, c_uint};
use libc::{time_t, timespec};
use super::{rexmpp_jid, rexmpp_xml, rexmpp_dns, rexmpp_tcp, rexmpp_socks};
#[derive(PartialEq)]
#[repr(C)]
pub enum ResolverState {
Ready,
SRV,
SRV2,
Failure
}
#[derive(PartialEq)]
#[repr(C)]
pub enum TCPState {
None,
Connecting,
SOCKS,
Connected,
Closed,
ConnectionFailure,
Error
}
#[derive(PartialEq)]
#[repr(C)]
pub enum StreamState {
None,
Opening,
StartTLS,
SASL,
Bind,
SMFull,
SMAcks,
SMResume,
Ready,
CloseRequested,
Closing,
Closed,
Error,
ErrorReconnect
}
#[derive(PartialEq)]
#[repr(C)]
pub enum TLSState {
Inactive,
AwaitingDirect,
Handshake,
Active,
Closing,
Closed,
Error
}
#[derive(PartialEq)]
#[repr(C)]
pub enum SASLState {
Inactive,
Negotiation,
Active,
Error
}
#[derive(PartialEq)]
#[repr(C)]
pub enum SMState {
Inactive,
Negotiation,
Active
}
#[derive(PartialEq)]
#[repr(C)]
pub enum CarbonsState {
Inactive,
Negotiation,
Active
}
#[derive(PartialEq)]
#[repr(C)]
pub enum TLSPolicy {
Require,
Prefer,
Avoid
}
type IQCallback = unsafe extern "C"
fn (s: *mut Rexmpp, cb_data: *mut c_void,
request: *mut rexmpp_xml::RexmppXML, response: *mut rexmpp_xml::RexmppXML,
success: c_int) -> ();
type SocketCallback = unsafe extern "C"
fn (s: *mut Rexmpp, socket: c_int) -> ();
#[repr(C)]
pub struct RexmppIQ {
pub requset: *mut rexmpp_xml::RexmppXML,
pub cb: IQCallback,
pub cb_data: *const c_void,
pub next: *mut RexmppIQ
}
#[repr(C)]
pub struct RexmppMUCPing {
pub jid: *mut c_char,
pub password: *mut c_char,
pub delay: c_uint,
pub requested: bool,
pub last_activity: timespec,
pub next: *mut RexmppMUCPing
}
#[repr(C)]
pub struct Rexmpp {
pub resolver_state: ResolverState,
pub tcp_state: TCPState,
pub stream_state: StreamState,
pub tls_state: TLSState,
pub sasl_state: SASLState,
pub sm_state: SMState,
pub carbons_state: CarbonsState,
// Basic configuration
pub initial_jid: rexmpp_jid::RexmppJID,
// Manual host/port configuration
pub manual_host: *const c_char,
pub manual_port: u16,
pub manual_direct_tls: bool,
// Miscellaneous settings
pub disco_node: *const c_char,
// SOCKS settings
pub socks_host: *const c_char,
pub socks_port: u16,
// Various knobs (these are used instead of loadable modules)
pub enable_carbons: bool, // XEP-0280
pub manage_roster: bool,
pub roster_cache_file: *const c_char,
pub track_roster_presence: bool,
pub track_roster_events: bool, // XEP-0163
pub nick_notifications: bool, // XEP-0172
pub retrieve_openpgp_keys: bool, // XEP-0373
pub autojoin_bookmarked_mucs: bool, // XEP-0402
pub tls_policy: TLSPolicy,
pub enable_jingle: bool,
pub client_name: *const c_char, // XEP-0030, XEP-0092
pub client_type: *const c_char, // XEP-0030
pub client_version: *const c_char, // XEP-0092
pub local_address: *const c_char, // For ICE, XEP-0176
pub jingle_prefer_rtcp_mux: bool,
// A delay in seconds, to use for MUC self-ping by default
pub muc_ping_default_delay: c_uint,
// Resource limits
pub stanza_queue_size: u32,
pub send_queue_size: u32,
pub iq_queue_size: u32,
pub iq_cache_size: u32,
pub max_jingle_sessions: u32,
// X.509 settings (for TLS and DTLS)
pub x509_key_file: *const c_char,
pub x509_cert_file: *const c_char,
pub x509_trust_file: *const c_char,
// Callbacks
// c_variadic is experimental and cannot be used on the stable
// release channel, so skipping the log function callback.
pub log_function: *const c_void,
// Actually skipping proper definitions of others for now as well
// (TODO: add them).
pub sasl_property_cb: *const c_void,
pub xml_in_cb: *const c_void,
pub xml_out_cb: *const c_void,
pub roster_modify_cb: *const c_void,
pub console_print_cb: *const c_void,
pub socket_cb: Option<SocketCallback>,
// Stream-related state
pub assigned_jid: rexmpp_jid::RexmppJID,
pub stream_features: *mut rexmpp_xml::RexmppXML,
pub roster_items: *mut rexmpp_xml::RexmppXML,
pub roster_ver: *mut c_char,
pub roster_presence: *mut rexmpp_xml::RexmppXML,
pub roster_events: *mut rexmpp_xml::RexmppXML,
// Other dynamic data
pub disco_info: *mut rexmpp_xml::RexmppXML,
// Includes Jingle RTP session candidates; rexmpp prioritizes the
// ones listed earlier on incoming calls
pub jingle_rtp_description: *mut rexmpp_xml::RexmppXML,
// IQs we're waiting for responses to
pub active_iq: *mut RexmppIQ,
pub iq_cache: *mut rexmpp_xml::RexmppXML,
// Jingle context
pub jingle: *const c_void, // TODO
// Connection and stream management
pub reconnect_number: c_uint,
pub reconnect_seconds: time_t,
pub next_reconnect_time: timespec,
pub stanza_queue: *mut rexmpp_xml::RexmppXML,
pub stanzas_out_count: u32,
pub stanzas_out_acknowledged: u32,
pub stanzas_in_count: u32,
pub stream_id: *mut c_char,
// Server ping configuration and state
pub ping_delay: c_uint,
pub ping_requested: bool,
pub last_network_activity: timespec,
// MUC self-ping
pub muc_ping: *mut RexmppMUCPing,
// DNS-related structures
pub resolver: *mut c_void,
pub server_srv: *mut rexmpp_dns::RexmppDNSResult,
pub server_srv_cur: c_int,
pub server_srv_tls: *mut rexmpp_dns::RexmppDNSResult,
pub server_srv_tls_cur: c_int,
pub server_active_srv: *mut rexmpp_dns::RexmppDNSSRV,
// The XMPP server we are connecting to
pub server_host: *const c_char,
pub server_port: u16,
// The primary socket used for communication with the server
pub server_socket: c_int,
// Whether the address it's connected to was verified with DNSSEC
pub server_socket_dns_secure: bool,
// A structure used to establish a TCP connection
pub server_connection: rexmpp_tcp::RexmppTCPConnection,
pub server_socks_conn: rexmpp_socks::RexmppSocks,
// Send buffer. NULL if there is nothing to send (and must not be
// NULL if there is anything in the send queue). Not appending
// data to it, see send_queue for queuing.
pub send_buffer: *mut c_char,
pub send_buffer_len: isize,
pub send_buffer_sent: isize,
// A queue of XML elements to send
pub send_queue: *mut rexmpp_xml::RexmppXML,
// An input queue of parsed XML structures
pub input_queue: *mut rexmpp_xml::RexmppXML,
pub input_queue_last: *mut rexmpp_xml::RexmppXML,
// XML parser context, and current element pointer for building
// XML nodes with a SAX2 parser interface
pub xml_parser: *mut c_void,
// The children are stored in reverse order during building
pub current_element_root: *mut rexmpp_xml::RexmppXML,
pub current_element: *mut rexmpp_xml::RexmppXML,
// TLS structures
pub tls: *mut c_void,
// SASL structures
pub sasl: *mut c_void,
// OpenPGP structures
pub pgp_ctx: *mut c_void,
// curl structures
pub curl_multi: *mut c_void
}
|