chore: add Makefile, headers, and source stubs for fusedav WebDAV FUSE3 client
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
/* retoor <retoor@molodetz.nl> */
|
||||
|
||||
#ifndef FUSEDAV_CACHE_H
|
||||
#define FUSEDAV_CACHE_H
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
|
||||
typedef struct cache_entry {
|
||||
char *key;
|
||||
void *value;
|
||||
size_t value_size;
|
||||
time_t created_at;
|
||||
int ttl_ms;
|
||||
struct cache_entry *next;
|
||||
} cache_entry_t;
|
||||
|
||||
typedef struct {
|
||||
cache_entry_t *head;
|
||||
int max_entries;
|
||||
int current_entries;
|
||||
int default_ttl_ms;
|
||||
pthread_mutex_t lock;
|
||||
} cache_t;
|
||||
|
||||
typedef struct {
|
||||
char *name;
|
||||
int is_directory;
|
||||
off_t size;
|
||||
time_t mtime;
|
||||
} dir_entry_t;
|
||||
|
||||
typedef struct {
|
||||
dir_entry_t *entries;
|
||||
int count;
|
||||
} dir_listing_t;
|
||||
|
||||
cache_t *cache_init(int max_entries, int default_ttl_ms);
|
||||
void cache_destroy(cache_t *cache);
|
||||
|
||||
int cache_get_stat(cache_t *cache, const char *key, struct stat *st);
|
||||
int cache_put_stat(cache_t *cache, const char *key, const struct stat *st);
|
||||
|
||||
int cache_get_dir(cache_t *cache, const char *key, dir_listing_t **listing);
|
||||
int cache_put_dir(cache_t *cache, const char *key, const dir_listing_t *listing);
|
||||
|
||||
void cache_invalidate(cache_t *cache, const char *key);
|
||||
void cache_invalidate_prefix(cache_t *cache, const char *prefix);
|
||||
void cache_clear(cache_t *cache);
|
||||
|
||||
void dir_listing_free(dir_listing_t *listing);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,28 @@
|
||||
/* retoor <retoor@molodetz.nl> */
|
||||
|
||||
#ifndef FUSEDAV_CONFIG_H
|
||||
#define FUSEDAV_CONFIG_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define DEFAULT_CACHE_TTL_MS 30000
|
||||
#define DEFAULT_TIMEOUT_SEC 10
|
||||
#define DEFAULT_MAX_CACHE_ENTRIES 1024
|
||||
#define DEFAULT_WRITE_BUFFER_SIZE (1024 * 1024)
|
||||
|
||||
typedef struct {
|
||||
char *webdav_url;
|
||||
char *username;
|
||||
char *password;
|
||||
char *mount_point;
|
||||
int cache_ttl_ms;
|
||||
int request_timeout_sec;
|
||||
int foreground;
|
||||
int debug;
|
||||
} config_t;
|
||||
|
||||
int config_parse(int argc, char *argv[], config_t *cfg);
|
||||
void config_free(config_t *cfg);
|
||||
void config_print_usage(const char *program_name);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,15 @@
|
||||
/* retoor <retoor@molodetz.nl> */
|
||||
|
||||
#ifndef FUSEDAV_OPERATIONS_H
|
||||
#define FUSEDAV_OPERATIONS_H
|
||||
|
||||
#define FUSE_USE_VERSION 31
|
||||
|
||||
#include <fuse3/fuse.h>
|
||||
#include "webdav.h"
|
||||
|
||||
extern struct fuse_operations fusedav_operations;
|
||||
|
||||
void operations_init(webdav_context_t *ctx);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,28 @@
|
||||
/* retoor <retoor@molodetz.nl> */
|
||||
|
||||
#ifndef FUSEDAV_UTILS_H
|
||||
#define FUSEDAV_UTILS_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <sys/stat.h>
|
||||
#include <libxml/parser.h>
|
||||
#include "cache.h"
|
||||
|
||||
char *url_encode(const char *str);
|
||||
char *url_decode(const char *str);
|
||||
char *path_join(const char *base, const char *path);
|
||||
char *path_parent(const char *path);
|
||||
char *path_basename(const char *path);
|
||||
int path_is_root(const char *path);
|
||||
|
||||
int http_status_to_errno(long http_code);
|
||||
|
||||
int parse_propfind_response(const char *xml_data, size_t xml_len,
|
||||
struct stat *st, dir_listing_t *listing);
|
||||
|
||||
time_t parse_http_date(const char *date_str);
|
||||
|
||||
char *xml_get_text(xmlNodePtr node);
|
||||
int xml_is_collection(xmlNodePtr node);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,56 @@
|
||||
/* retoor <retoor@molodetz.nl> */
|
||||
|
||||
#ifndef FUSEDAV_WEBDAV_H
|
||||
#define FUSEDAV_WEBDAV_H
|
||||
|
||||
#include <curl/curl.h>
|
||||
#include <pthread.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/stat.h>
|
||||
#include "cache.h"
|
||||
#include "config.h"
|
||||
|
||||
typedef struct {
|
||||
char *webdav_url;
|
||||
char *username;
|
||||
char *password;
|
||||
CURL *curl_handle;
|
||||
cache_t *metadata_cache;
|
||||
cache_t *dir_cache;
|
||||
int cache_ttl_ms;
|
||||
int request_timeout_sec;
|
||||
int debug;
|
||||
pthread_mutex_t lock;
|
||||
} webdav_context_t;
|
||||
|
||||
typedef struct {
|
||||
char *path;
|
||||
char *etag;
|
||||
off_t file_size;
|
||||
time_t last_modified;
|
||||
uint8_t *write_buffer;
|
||||
size_t write_buffer_pos;
|
||||
size_t write_buffer_size;
|
||||
int dirty;
|
||||
} file_handle_t;
|
||||
|
||||
int webdav_init(webdav_context_t *ctx, const config_t *cfg);
|
||||
void webdav_cleanup(webdav_context_t *ctx);
|
||||
|
||||
int webdav_get_stat(webdav_context_t *ctx, const char *path, struct stat *st);
|
||||
int webdav_list_directory(webdav_context_t *ctx, const char *path, dir_listing_t *listing);
|
||||
ssize_t webdav_read_file(webdav_context_t *ctx, const char *path,
|
||||
off_t offset, size_t size, uint8_t *buffer);
|
||||
ssize_t webdav_write_file(webdav_context_t *ctx, const char *path,
|
||||
off_t offset, size_t size, const uint8_t *buffer);
|
||||
int webdav_create_file(webdav_context_t *ctx, const char *path);
|
||||
int webdav_mkdir(webdav_context_t *ctx, const char *path);
|
||||
int webdav_delete(webdav_context_t *ctx, const char *path);
|
||||
int webdav_rename(webdav_context_t *ctx, const char *old_path, const char *new_path);
|
||||
int webdav_truncate(webdav_context_t *ctx, const char *path, off_t size);
|
||||
|
||||
file_handle_t *file_handle_create(const char *path);
|
||||
void file_handle_destroy(file_handle_t *fh);
|
||||
int file_handle_flush(webdav_context_t *ctx, file_handle_t *fh);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user