| 1 |
use std::ffi::CString; |
| 2 |
use std::marker; |
| 3 |
use std::ptr; |
| 4 |
|
| 5 |
use crate::raw; |
| 6 |
use crate::util::Binding; |
| 7 |
|
| 8 |
/// Options which can be specified to various fetch operations. |
| 9 |
#[derive(Default)] |
| 10 |
pub struct ProxyOptions<'a> { |
| 11 |
url: Option<CString>, |
| 12 |
proxy_kind: raw::git_proxy_t, |
| 13 |
_marker: marker::PhantomData<&'a i32>, |
| 14 |
} |
| 15 |
|
| 16 |
impl<'a> ProxyOptions<'a> { |
| 17 |
/// Creates a new set of proxy options ready to be configured. |
| 18 |
pub fn new() -> ProxyOptions<'a> { |
| 19 |
Default::default() |
| 20 |
} |
| 21 |
|
| 22 |
/// Try to auto-detect the proxy from the git configuration. |
| 23 |
/// |
| 24 |
/// Note that this will override `url` specified before. |
| 25 |
pub fn auto(&mut self) -> &mut Self { |
| 26 |
self.proxy_kind = raw::GIT_PROXY_AUTO; |
| 27 |
self |
| 28 |
} |
| 29 |
|
| 30 |
/// Specify the exact URL of the proxy to use. |
| 31 |
/// |
| 32 |
/// Note that this will override `auto` specified before. |
| 33 |
pub fn url(&mut self, url: &str) -> &mut Self { |
| 34 |
self.proxy_kind = raw::GIT_PROXY_SPECIFIED; |
| 35 |
self.url = Some(CString::new(url).unwrap()); |
| 36 |
self |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
impl<'a> Binding for ProxyOptions<'a> { |
| 41 |
type Raw = raw::git_proxy_options; |
| 42 |
unsafe fn from_raw(_raw: raw::git_proxy_options) -> ProxyOptions<'a> { |
| 43 |
panic!("can't create proxy from raw options") |
| 44 |
} |
| 45 |
|
| 46 |
fn raw(&self) -> raw::git_proxy_options { |
| 47 |
raw::git_proxy_options { |
| 48 |
version: raw::GIT_PROXY_OPTIONS_VERSION, |
| 49 |
kind: self.proxy_kind, |
| 50 |
url: self.url.as_ref().map(|s| s.as_ptr()).unwrap_or(ptr::null()), |
| 51 |
credentials: None, |
| 52 |
certificate_check: None, |
| 53 |
payload: ptr::null_mut(), |
| 54 |
} |
| 55 |
} |
| 56 |
} |