//! A WebDAV filesystem provider for Memona, speaking only the host's HTTP.
mod dav;
mod sdk;
use sdk::host;
use sdk::{
Capabilities, ChangePage, Entry, EntryKind, ErrorCode, FileInfo, Guest,
GuestReader, GuestWriter, ListPage, Locator, Reader, Setting, WriteCondition,
Writer,
};
use std::cell::{Cell, RefCell};
/// The PROPFIND body. Asking for named properties rather than allprop keeps
/// replies small on servers that store a great many of them.
const PROPS: &str = concat!(
r#""#,
r#""#,
"",
"",
);
const MAX_CHUNK: u32 = 1024 * 1024;
struct Session {
root: String,
authorization: Option,
}
impl Session {
fn from_config(config: &[(String, Setting)]) -> Result {
let lookup = |wanted: &str| {
config
.iter()
.find(|(key, _)| key == wanted)
.and_then(|(_, value)| text(Some(value.clone())))
};
let root = lookup("url").ok_or(ErrorCode::InvalidInput)?;
if !root.starts_with("https://") && !root.starts_with("http://") {
return Err(ErrorCode::InvalidInput);
}
let authorization = lookup("username").map(|username| {
dav::basic(&username, &lookup("password").unwrap_or_default())
});
Ok(Self {
root,
authorization,
})
}
}
thread_local! {
static SESSION: RefCell