Commit 1c9b8a02 authored by Alex Crichton's avatar Alex Crichton
Browse files

Cut down on unstable features in openssl-sys

* Move from `old_path` to `path` (leveraging the `fs` feature as well)
* Move from `StaticMutex` to `Mutex<()>` as they're dynamically initialized
parent 5154581c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
#![feature(env, path)]
#![feature(path)]

extern crate "pkg-config" as pkg_config;
extern crate gcc;
+5 −5
Original line number Diff line number Diff line
#![allow(non_camel_case_types, non_upper_case_globals, non_snake_case)]
#![allow(dead_code)]
#![feature(core, old_io, old_path, std_misc, env)]
#![feature(path, fs)]
#![doc(html_root_url="https://sfackler.github.io/rust-openssl/doc/openssl-sys")]

extern crate libc;
@@ -11,7 +11,7 @@ extern crate "libressl-pnacl-sys" as _for_linkage;
use libc::{c_void, c_int, c_char, c_ulong, c_long, c_uint, c_uchar, size_t};
use std::mem;
use std::ptr;
use std::sync::{StaticMutex, MutexGuard, MUTEX_INIT};
use std::sync::{Mutex, MutexGuard};
use std::sync::{Once, ONCE_INIT};

pub type ASN1_INTEGER = c_void;
@@ -193,7 +193,7 @@ pub const X509_V_ERR_UNSUPPORTED_EXTENSION_FEATURE: c_int = 45;
pub const X509_V_ERR_UNSUPPORTED_NAME_SYNTAX: c_int = 53;
pub const X509_V_OK: c_int = 0;

static mut MUTEXES: *mut Vec<StaticMutex> = 0 as *mut Vec<StaticMutex>;
static mut MUTEXES: *mut Vec<Mutex<()>> = 0 as *mut Vec<Mutex<()>>;
static mut GUARDS: *mut Vec<Option<MutexGuard<'static, ()>>> = 0 as *mut Vec<Option<MutexGuard<'static, ()>>>;

extern fn locking_function(mode: c_int, n: c_int, _file: *const c_char,
@@ -220,11 +220,11 @@ pub fn init() {
            let num_locks = CRYPTO_num_locks();
            let mut mutexes = Box::new(Vec::new());
            for _ in 0..num_locks {
                mutexes.push(MUTEX_INIT);
                mutexes.push(Mutex::new(()));
            }
            MUTEXES = mem::transmute(mutexes);
            let guards: Box<Vec<Option<MutexGuard<()>>>> =
                Box::new(range(0, num_locks).map(|_| None).collect());
                Box::new((0..num_locks).map(|_| None).collect());
            GUARDS = mem::transmute(guards);

            CRYPTO_set_locking_callback(locking_function);
+10 −9
Original line number Diff line number Diff line
use std::env;
use std::old_io::fs::PathExtensions;
use std::fs::PathExt;
use std::path::PathBuf;

pub struct ProbeResult {
    pub cert_file: Option<Path>,
    pub cert_dir: Option<Path>,
    pub cert_file: Option<PathBuf>,
    pub cert_dir: Option<PathBuf>,
}

/// Probe the system for the directory in which CA certificates should likely be
/// found.
///
/// This will only search known system locations.
pub fn find_certs_dirs() -> Vec<Path> {
pub fn find_certs_dirs() -> Vec<PathBuf> {
    // see http://gagravarr.org/writing/openssl-certs/others.shtml
    [
        "/var/ssl",
@@ -23,7 +24,7 @@ pub fn find_certs_dirs() -> Vec<Path> {
        "/etc/openssl",
        "/etc/pki/tls",
        "/etc/ssl",
    ].iter().map(|s| Path::new(*s)).filter(|p| {
    ].iter().map(|s| PathBuf::new(*s)).filter(|p| {
        p.exists()
    }).collect()
}
@@ -39,7 +40,7 @@ pub fn init_ssl_cert_env_vars() {
        None => {}
    }

    fn put(var: &str, path: Path) {
    fn put(var: &str, path: PathBuf) {
        // Don't stomp over what anyone else has set
        match env::var(var) {
            Ok(..) => {}
@@ -50,8 +51,8 @@ pub fn init_ssl_cert_env_vars() {

pub fn probe() -> ProbeResult {
    let mut result = ProbeResult {
        cert_file: env::var("SSL_CERT_FILE").ok().map(Path::new),
        cert_dir: env::var("SSL_CERT_DIR").ok().map(Path::new),
        cert_file: env::var_os("SSL_CERT_FILE").map(|s| PathBuf::new(&s)),
        cert_dir: env::var_os("SSL_CERT_DIR").map(|s| PathBuf::new(&s)),
    };
    for certs_dir in find_certs_dirs().iter() {
        // cert.pem looks to be an openssl 1.0.1 thing, while
@@ -65,7 +66,7 @@ pub fn probe() -> ProbeResult {
    result
}

fn try(dst: &mut Option<Path>, val: Path) {
fn try(dst: &mut Option<PathBuf>, val: PathBuf) {
    if dst.is_none() && val.exists() {
        *dst = Some(val);
    }