*/
#![allow(dead_code)]
-use std::ffi::{c_char, c_int, c_long, c_void, CString};
+use std::ffi::{c_char, c_int, c_long, c_void, CStr, CString};
use std::io::{Read, Seek, SeekFrom, Write};
use std::marker::PhantomData;
use std::ops::Deref;
+use std::time::{Duration, SystemTime, UNIX_EPOCH};
use libc::size_t;
use crate::dav::context::DavContext;
use crate::dav::ffi;
}
}
+fn cstr2str(cstr: *const c_char) -> String {
+ if cstr.is_null() {
+ String::new()
+ } else {
+ unsafe {
+ CStr::from_ptr(cstr)
+ .to_string_lossy()
+ .into_owned()
+ }
+ }
+}
impl<'a> ResourceRef<'a> {
+
+ pub fn name(&self) -> String {
+ unsafe {
+ cstr2str((*self.ptr).name)
+ }
+ }
+
+ pub fn path(&self) -> String {
+ unsafe {
+ cstr2str((*self.ptr).path)
+ }
+ }
+
+ pub fn href(&self) -> String {
+ unsafe {
+ cstr2str((*self.ptr).href)
+ }
+ }
+
+ pub fn content_type(&self) -> String {
+ unsafe {
+ cstr2str((*self.ptr).contenttype)
+ }
+ }
+
+ pub fn content_length(&self) -> usize {
+ unsafe {
+ (*self.ptr).contentlength as usize
+ }
+ }
+
+ pub fn is_collection(&self) -> bool {
+ unsafe {
+ (*self.ptr).iscollection != 0
+ }
+ }
+
+ pub fn lastmodified(&self) -> SystemTime {
+ unsafe {
+ UNIX_EPOCH + Duration::from_secs((*self.ptr).lastmodified as u64)
+ }
+ }
+
+ pub fn creationdate(&self) -> SystemTime {
+ unsafe {
+ UNIX_EPOCH + Duration::from_secs((*self.ptr).lastmodified as u64)
+ }
+ }
+
fn resource_ref(&self, ptr: *mut ffi::DavResource) -> Option<ResourceRef<'_>> {
if ptr.is_null() {
return None;