libonion
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Typedefs | Enumerations | Functions
webdav.c File Reference
#include <assert.h>
#include <errno.h>
#include <libxml/xmlmemory.h>
#include <libxml/xmlwriter.h>
#include <onion/log.h>
#include <onion/response.h>
#include <onion/block.h>
#include <onion/shortcuts.h>
#include <onion/low.h>
#include "webdav.h"
#include <string.h>
#include <dirent.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <libgen.h>

Data Structures

struct  onion_webdav_t

Typedefs

typedef struct onion_webdav_t onion_webdav
typedef enum onion_webdav_props_e onion_webdav_props

Enumerations

enum  onion_webdav_props_e {
  WD_RESOURCE_TYPE = (1<<0), WD_CONTENT_LENGTH = (1<<1), WD_LAST_MODIFIED = (1<<2), WD_CREATION_DATE = (1<<3),
  WD_ETAG = (1<<4), WD_CONTENT_TYPE = (1<<5), WD_DISPLAY_NAME = (1<<6), WD_EXECUTABLE = (1<<7)
}
 Flags of props as queried. More...

Functions

onion_connection_status onion_webdav_get (const char *filename, onion_webdav *wd, onion_request *req, onion_response *res)
 Simple get on webdav is just a simple get on a default path.
onion_connection_status onion_webdav_put (const char *filename, onion_webdav *wd, onion_request *req, onion_response *res)
 Simple put on webdav is just move a file from tmp to the final destination (or copy if could not move).
onion_connection_status onion_webdav_mkcol (const char *filename, onion_webdav *wd, onion_request *req, onion_response *res)
 Creates a collection / directory.
onion_connection_status onion_webdav_move (const char *filename, onion_webdav *wd, onion_request *req, onion_response *res)
 Moves a resource.
onion_connection_status onion_webdav_delete (const char *filename, onion_webdav *wd, onion_request *req, onion_response *res)
 Deletes a resource.
onion_connection_status onion_webdav_options (const char *filename, onion_webdav *wd, onion_request *req, onion_response *res)
 Returns known options.
onion_connection_status onion_webdav_propfind (const char *filename, onion_webdav *wd, onion_request *req, onion_response *res)
 Handles a propfind.
onion_connection_status onion_webdav_proppatch (const char *filename, onion_webdav *wd, onion_request *req, onion_response *res)
 Allows to change some properties of the file.
onion_connection_status onion_webdav_handler (onion_webdav *wd, onion_request *req, onion_response *res)
 Main webdav handler, just redirects to the proper handler depending on headers and method.
int onion_webdav_write_props (xmlTextWriterPtr writer, const char *basepath, const char *realpath, const char *urlpath, const char *filename, int props)
 Write the properties of a path.
onion_blockonion_webdav_write_propfind (const char *basepath, const char *realpath, const char *urlpath, int depth, int props)
 Prepares the response for propfinds.
void onion_webdav_free (onion_webdav *wd)
 Frees the webdav data.
int onion_webdav_default_check_permissions (const char *exported_path, const char *filename, onion_request *req)
 Default permission checker.
onion_handleronion_handler_webdav (const char *path, onion_webdav_permissions_check perm)
 Creates a webdav handler.

Typedef Documentation

typedef struct onion_webdav_t onion_webdav

Enumeration Type Documentation

Flags of props as queried.

Enumerator:
WD_RESOURCE_TYPE 
WD_CONTENT_LENGTH 
WD_LAST_MODIFIED 
WD_CREATION_DATE 
WD_ETAG 
WD_CONTENT_TYPE 
WD_DISPLAY_NAME 
WD_EXECUTABLE 

Function Documentation

onion_handler* onion_handler_webdav ( const char *  path,
onion_webdav_permissions_check  perm 
)

Creates a webdav handler.

Exports the given path through webdav.

The check_permissions parameter, if set, sets a custom security permission checker.

If not set, the default permissions apply, that will try to do not access files out of the restricted area.

This permission checker gets the exported path, the path to the file that wants to be exported/checked/moved.., and the request as it arrived to the handler.

The exported path and file path might be relative, if onion_handler_webdav was initialized so.

On move it will check for both the original and final files, on other methods, it will check just the file, and the semantics is that the user is allowed to do that method.

It should return 0 on success, any other if error/not allowed.

Parameters
pathPath to share
Returns
The onion handler.

References onion_webdav_t::check_permissions, onion_handler_t::onion_handler_new(), onion_low_malloc(), onion_low_strdup(), onion_webdav_default_check_permissions(), onion_webdav_free(), onion_webdav_handler(), and onion_webdav_t::path.

int onion_webdav_default_check_permissions ( const char *  exported_path,
const char *  filename,
onion_request req 
)

Default permission checker.

It checks the given path complies with the exported area.

References ONION_DEBUG0, ONION_ERROR, and onion_low_free().

Referenced by onion_handler_webdav().

onion_connection_status onion_webdav_delete ( const char *  filename,
onion_webdav wd,
onion_request req,
onion_response res 
)
void onion_webdav_free ( onion_webdav wd)

Frees the webdav data.

References onion_low_free(), and onion_webdav_t::path.

Referenced by onion_handler_webdav().

onion_connection_status onion_webdav_get ( const char *  filename,
onion_webdav wd,
onion_request req,
onion_response res 
)

Simple get on webdav is just a simple get on a default path.

References ONION_DEBUG, and onion_shortcut_response_file().

Referenced by onion_webdav_handler().

onion_connection_status onion_webdav_handler ( onion_webdav wd,
onion_request req,
onion_response res 
)
onion_connection_status onion_webdav_mkcol ( const char *  filename,
onion_webdav wd,
onion_request req,
onion_response res 
)

Creates a collection / directory.

Spec says it must create only if the parent exists.

References HTTP_FORBIDDEN, and onion_shortcut_response().

Referenced by onion_webdav_handler().

onion_connection_status onion_webdav_move ( const char *  filename,
onion_webdav wd,
onion_request req,
onion_response res 
)
onion_connection_status onion_webdav_options ( const char *  filename,
onion_webdav wd,
onion_request req,
onion_response res 
)

Returns known options.

Just known options, no more. I think many clients ignore this. (without PUT, gnome's file manager was trying).

References OCS_PROCESSED, onion_response_t::onion_response_set_header(), onion_response_t::onion_response_set_length(), and onion_response_t::onion_response_write_headers().

Referenced by onion_webdav_handler().

onion_connection_status onion_webdav_propfind ( const char *  filename,
onion_webdav wd,
onion_request req,
onion_response res 
)
onion_connection_status onion_webdav_proppatch ( const char *  filename,
onion_webdav wd,
onion_request req,
onion_response res 
)
onion_connection_status onion_webdav_put ( const char *  filename,
onion_webdav wd,
onion_request req,
onion_response res 
)

Simple put on webdav is just move a file from tmp to the final destination (or copy if could not move).

References HTTP_FORBIDDEN, onion_block_t::onion_block_data(), ONION_DEBUG, ONION_ERROR, onion_request_t::onion_request_get_data(), onion_shortcut_rename(), and onion_shortcut_response().

Referenced by onion_webdav_handler().

onion_block* onion_webdav_write_propfind ( const char *  basepath,
const char *  realpath,
const char *  urlpath,
int  depth,
int  props 
)

Prepares the response for propfinds.

Parameters
realpathShared folder
urlpathURL of the requested propfind
depthDepth of query, 0 or 1.
propsProperties of the query
Returns
An onion_block with the XML data.

References onion_block_t::onion_block_add_str(), onion_block_t::onion_block_free(), onion_block_t::onion_block_new(), ONION_DEBUG, ONION_ERROR, and onion_webdav_write_props().

Referenced by onion_webdav_propfind().

int onion_webdav_write_props ( xmlTextWriterPtr  writer,
const char *  basepath,
const char *  realpath,
const char *  urlpath,
const char *  filename,
int  props 
)

Write the properties of a path.

Given a path, and optionally a file at that path, writes the XML of its properties.

If no file given, data is for that path, else it is for the path+filename.

Parameters
writerXML writer to write the data to
realpathThe real path on the file server, used to check permissions and read data TODO
urlpathThe base URL of the element, needed in the response. Composed with filename if filename!=NULL.
filenameNULL if that element itself, else the subelement (file in path).
propsBitmask of the properties the user asked for.
Returns
0 is ok, 1 if could not stat file.

OK

NOT FOUND

References ONION_DEBUG, ONION_DEBUG0, ONION_ERROR, onion_shortcut_date_string(), onion_shortcut_date_string_iso(), onion_shortcut_etag(), WD_CONTENT_LENGTH, WD_CONTENT_TYPE, WD_CREATION_DATE, WD_DISPLAY_NAME, WD_ETAG, WD_EXECUTABLE, WD_LAST_MODIFIED, and WD_RESOURCE_TYPE.

Referenced by onion_webdav_write_propfind().