From 53b5c00e625bf700a21be1a3e2070d3b23f1bef4 Mon Sep 17 00:00:00 2001 From: Yves Fischer Date: Sat, 3 Sep 2016 02:00:54 +0200 Subject: first test version --- rust/src/sendxmpp.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 rust/src/sendxmpp.rs (limited to 'rust/src/sendxmpp.rs') diff --git a/rust/src/sendxmpp.rs b/rust/src/sendxmpp.rs new file mode 100644 index 0000000..2db471e --- /dev/null +++ b/rust/src/sendxmpp.rs @@ -0,0 +1,21 @@ +///! Interface for the C implementation oof sending xmpp message + +use std::ffi::{CString, NulError}; +use std::os::raw::c_char; + +pub fn send_message(jid: &str, password: &str, message: &str, to: &str) -> Result<(), NulError> { + extern { + pub fn send_message(jid: *const c_char, + password: *const c_char, + message: *const c_char, + to: *const c_char); + } + let cjid = try!(CString::new(jid)); + let cpassword = try!(CString::new(password)); + let cmessage = try!(CString::new(message)); + let cto = try!(CString::new(to)); + unsafe { + send_message(cjid.as_ptr(), cpassword.as_ptr(), cmessage.as_ptr(), cto.as_ptr()); + } + Ok(()) +} \ No newline at end of file -- cgit v1.2.1