]> uap-core.de Git - note.git/commitdiff
extend dav Resource API
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Tue, 23 Jun 2026 19:21:01 +0000 (21:21 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Tue, 23 Jun 2026 19:21:01 +0000 (21:21 +0200)
dav-rs/src/dav/resource.rs

index 084e5e737f2ea84edb00f8b49d4ce02d2d58fa4a..e0e6485a8cf04c9fb5668aa7d0b219ed04e141a3 100644 (file)
  */
 #![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;
@@ -62,8 +63,68 @@ impl<'a> Deref for Resource<'a> {
     }
 }
 
+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;