Skip to content

Commit e940339

Browse files
committed
Add private pointer storage
1 parent fe97c9e commit e940339

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

src/easy.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1963,6 +1963,23 @@ impl<'a> Easy<'a> {
19631963
enable as c_long)
19641964
}
19651965

1966+
/// Stores a private pointer-sized piece of data.
1967+
///
1968+
/// This can be retrieved through the `private` function and otherwise
1969+
/// libcurl does not tamper with this value. This corresponds to
1970+
/// `CURLOPT_PRIVATE` and defaults to 0.
1971+
pub fn set_private(&mut self, private: usize) -> Result<(), Error> {
1972+
self.setopt_ptr(curl_sys::CURLOPT_PRIVATE, private as *const _)
1973+
}
1974+
1975+
/// Fetches this handle's private pointer-sized piece of data.
1976+
///
1977+
/// This corresponds to
1978+
/// `CURLINFO_PRIVATE` and defaults to 0.
1979+
pub fn private(&mut self) -> Result<usize, Error> {
1980+
self.getopt_ptr(curl_sys::CURLINFO_PRIVATE).map(|p| p as usize)
1981+
}
1982+
19661983
// =========================================================================
19671984
// getters
19681985

@@ -2395,8 +2412,7 @@ impl<'a> Easy<'a> {
23952412
fn getopt_bytes(&mut self, opt: curl_sys::CURLINFO)
23962413
-> Result<Option<&[u8]>, Error> {
23972414
unsafe {
2398-
let mut p = 0 as *const c_char;
2399-
try!(cvt(curl_sys::curl_easy_getinfo(self.handle, opt, &mut p)));
2415+
let p = try!(self.getopt_ptr(opt));
24002416
if p.is_null() {
24012417
Ok(None)
24022418
} else {
@@ -2405,6 +2421,15 @@ impl<'a> Easy<'a> {
24052421
}
24062422
}
24072423

2424+
fn getopt_ptr(&mut self, opt: curl_sys::CURLINFO)
2425+
-> Result<*const c_char, Error> {
2426+
unsafe {
2427+
let mut p = 0 as *const c_char;
2428+
try!(cvt(curl_sys::curl_easy_getinfo(self.handle, opt, &mut p)));
2429+
Ok(p)
2430+
}
2431+
}
2432+
24082433
fn getopt_str(&mut self, opt: curl_sys::CURLINFO)
24092434
-> Result<Option<&str>, Error> {
24102435
match self.getopt_bytes(opt) {

0 commit comments

Comments
 (0)