summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2015-01-03 14:28:59 -0800
committerAlex Crichton <alex@alexcrichton.com>2015-01-03 14:29:14 -0800
commit763fcce23a4d6736be609d0e758ca667299b7547 (patch)
treee664833a72ff0214bb29544ba7f66a31c32494d1 /src
parent09e6152c628a4cd2ad0706d9ad94c5b73ff3aee2 (diff)
downloadssh2-rs-763fcce23a4d6736be609d0e758ca667299b7547.zip
Update to rust master
Diffstat (limited to 'src')
-rw-r--r--src/agent.rs10
-rw-r--r--src/channel.rs4
-rw-r--r--src/knownhosts.rs1
-rw-r--r--src/lib.rs32
-rw-r--r--src/session.rs17
-rw-r--r--src/sftp.rs2
6 files changed, 29 insertions, 37 deletions
diff --git a/src/agent.rs b/src/agent.rs
index 0083443..3303b1a 100644
--- a/src/agent.rs
+++ b/src/agent.rs
@@ -1,6 +1,6 @@
+use std::c_str::ToCStr;
use std::kinds::marker;
-use std::mem;
-use std::raw as stdraw;
+use std::slice;
use std::str;
use {raw, Session, Error};
@@ -120,10 +120,8 @@ impl<'agent> PublicKey<'agent> {
/// Return the data of this public key.
pub fn blob(&self) -> &[u8] {
unsafe {
- mem::transmute(stdraw::Slice {
- data: (*self.raw).blob as *const u8,
- len: (*self.raw).blob_len as uint,
- })
+ slice::from_raw_mut_buf(&(*self.raw).blob,
+ (*self.raw).blob_len as uint)
}
}
diff --git a/src/channel.rs b/src/channel.rs
index bed303f..25227c6 100644
--- a/src/channel.rs
+++ b/src/channel.rs
@@ -29,7 +29,7 @@ pub struct ExitSignal {
}
/// Description of the read window as returned by `Channel::read_window`
-#[deriving(Copy)]
+#[derive(Copy)]
pub struct ReadWindow {
/// The number of bytes which the remote end may send without overflowing
/// the window limit.
@@ -41,7 +41,7 @@ pub struct ReadWindow {
}
/// Description of the write window as returned by `Channel::write_window`
-#[deriving(Copy)]
+#[derive(Copy)]
pub struct WriteWindow {
/// The number of bytes which may be safely written on the channel without
/// blocking.
diff --git a/src/knownhosts.rs b/src/knownhosts.rs
index 6fec25e..3a0635f 100644
--- a/src/knownhosts.rs
+++ b/src/knownhosts.rs
@@ -1,3 +1,4 @@
+use std::c_str::ToCStr;
use std::kinds::marker;
use std::str;
use libc::{c_int, size_t};
diff --git a/src/lib.rs b/src/lib.rs
index 4999a0f..9bcef9e 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -96,7 +96,6 @@ extern crate libc;
use std::c_str::CString;
use std::mem;
-use std::rt;
use std::sync::{Once, ONCE_INIT};
pub use agent::{Agent, Identities, PublicKey};
@@ -127,15 +126,12 @@ mod sftp;
///
/// This is optional, it is lazily invoked.
pub fn init() {
- static mut INIT: Once = ONCE_INIT;
- unsafe {
- INIT.doit(|| {
- assert_eq!(raw::libssh2_init(0), 0);
- rt::at_exit(|| {
- raw::libssh2_exit();
- });
- })
- }
+ static INIT: Once = ONCE_INIT;
+ INIT.call_once(|| unsafe {
+ assert_eq!(raw::libssh2_init(0), 0);
+ assert_eq!(libc::atexit(shutdown), 0);
+ });
+ extern fn shutdown() { unsafe { raw::libssh2_exit(); } }
}
unsafe fn opt_bytes<'a, T>(_: &'a T,
@@ -149,7 +145,7 @@ unsafe fn opt_bytes<'a, T>(_: &'a T,
}
#[allow(missing_docs)]
-#[deriving(Copy)]
+#[derive(Copy)]
pub enum DisconnectCode {
HostNotAllowedToConnect =
raw::SSH_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT as int,
@@ -172,7 +168,7 @@ pub enum DisconnectCode {
}
/// Flags to be enabled/disabled on a Session
-#[deriving(Copy)]
+#[derive(Copy)]
pub enum SessionFlag {
/// If set, libssh2 will not attempt to block SIGPIPEs but will let them
/// trigger from the underlying socket layer.
@@ -185,7 +181,7 @@ pub enum SessionFlag {
}
#[allow(missing_docs)]
-#[deriving(Copy)]
+#[derive(Copy)]
pub enum HostKeyType {
Unknown = raw::LIBSSH2_HOSTKEY_TYPE_UNKNOWN as int,
Rsa = raw::LIBSSH2_HOSTKEY_TYPE_RSA as int,
@@ -193,7 +189,7 @@ pub enum HostKeyType {
}
#[allow(missing_docs)]
-#[deriving(Copy)]
+#[derive(Copy)]
pub enum MethodType {
Kex = raw::LIBSSH2_METHOD_KEX as int,
HostKey = raw::LIBSSH2_METHOD_HOSTKEY as int,
@@ -216,20 +212,20 @@ pub static FLUSH_ALL: uint = -2;
pub static EXTENDED_DATA_STDERR: uint = 1;
#[allow(missing_docs)]
-#[deriving(Copy)]
+#[derive(Copy)]
pub enum HashType {
Md5 = raw::LIBSSH2_HOSTKEY_HASH_MD5 as int,
Sha1 = raw:: LIBSSH2_HOSTKEY_HASH_SHA1 as int,
}
#[allow(missing_docs)]
-#[deriving(Copy)]
+#[derive(Copy)]
pub enum KnownHostFileKind {
OpenSSH = raw::LIBSSH2_KNOWNHOST_FILE_OPENSSH as int,
}
/// Possible results of a call to `KnownHosts::check`
-#[deriving(Copy)]
+#[derive(Copy)]
pub enum CheckResult {
/// Hosts and keys match
Match = raw::LIBSSH2_KNOWNHOST_CHECK_MATCH as int,
@@ -242,7 +238,7 @@ pub enum CheckResult {
}
#[allow(missing_docs)]
-#[deriving(Copy)]
+#[derive(Copy)]
pub enum KnownHostKeyFormat {
Rsa1 = raw::LIBSSH2_KNOWNHOST_KEY_RSA1 as int,
SshRsa = raw::LIBSSH2_KNOWNHOST_KEY_SSHRSA as int,
diff --git a/src/session.rs b/src/session.rs
index 7d983cb..c62bb91 100644
--- a/src/session.rs
+++ b/src/session.rs
@@ -1,9 +1,10 @@
+use std::c_str::ToCStr;
use std::io;
use std::kinds::marker;
use std::mem;
-use std::raw as stdraw;
+use std::slice;
use std::str;
-use libc::{mod, c_uint, c_int, c_void, c_long};
+use libc::{self, c_uint, c_int, c_void, c_long};
use {raw, Error, DisconnectCode, ByApplication, SessionFlag, HostKeyType};
use {MethodType, Agent, Channel, Listener, HashType, KnownHosts, Sftp};
@@ -148,10 +149,8 @@ impl Session {
unsafe {
let ret = raw::libssh2_session_hostkey(self.raw, &mut len, &mut kind);
if ret.is_null() { return None }
- let data: &[u8] = mem::transmute(stdraw::Slice {
- data: ret as *const u8,
- len: len as uint,
- });
+ let ret = ret as *const u8;
+ let data = mem::transmute(slice::from_raw_buf(&ret, len as uint));
let kind = match kind {
raw::LIBSSH2_HOSTKEY_TYPE_RSA => HostKeyType::Rsa,
raw::LIBSSH2_HOSTKEY_TYPE_DSS => HostKeyType::Dss,
@@ -175,10 +174,8 @@ impl Session {
if ret.is_null() {
None
} else {
- Some(mem::transmute(stdraw::Slice {
- data: ret as *const u8,
- len: len,
- }))
+ let ret = ret as *const u8;
+ Some(mem::transmute(slice::from_raw_buf(&ret, len)))
}
}
}
diff --git a/src/sftp.rs b/src/sftp.rs
index 173b755..789ca00 100644
--- a/src/sftp.rs
+++ b/src/sftp.rs
@@ -89,7 +89,7 @@ bitflags! {
}
/// How to open a file handle with libssh2.
-#[deriving(Copy)]
+#[derive(Copy)]
pub enum OpenType {
/// Specify that a file shoud be opened.
File = raw::LIBSSH2_SFTP_OPENFILE as int,