libonion
|
#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_block * | onion_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_handler * | onion_handler_webdav (const char *path, onion_webdav_permissions_check perm) |
Creates a webdav handler. |
typedef struct onion_webdav_t onion_webdav |
typedef enum onion_webdav_props_e onion_webdav_props |
enum onion_webdav_props_e |
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.
path | Path to share |
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 | ||
) |
Deletes a resource.
References HTTP_INTERNAL_ERROR, HTTP_OK, ONION_DEBUG, ONION_ERROR, and onion_shortcut_response().
Referenced by onion_webdav_handler().
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 | ||
) |
Main webdav handler, just redirects to the proper handler depending on headers and method.
References onion_webdav_t::check_permissions, HTTP_FORBIDDEN, HTTP_NOT_IMPLEMENTED, OCS_PROCESSED, onion_block_t::onion_block_data(), ONION_DEBUG, ONION_DEBUG0, onion_request_t::onion_request_get_data(), onion_request_t::onion_request_get_flags(), onion_request_t::onion_request_get_path(), onion_response_t::onion_response_set_code(), onion_response_t::onion_response_set_header(), onion_response_write0(), onion_shortcut_response(), onion_webdav_delete(), onion_webdav_get(), onion_webdav_mkcol(), onion_webdav_move(), onion_webdav_options(), onion_webdav_propfind(), onion_webdav_proppatch(), onion_webdav_put(), OR_DELETE, OR_GET, OR_HEAD, OR_METHODS, OR_MKCOL, OR_MOVE, OR_OPTIONS, OR_PROPFIND, OR_PROPPATCH, OR_PUT, and onion_webdav_t::path.
Referenced by onion_handler_webdav().
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 | ||
) |
Moves a resource.
References onion_webdav_t::check_permissions, HTTP_FORBIDDEN, OCS_INTERNAL_ERROR, ONION_DEBUG, ONION_ERROR, ONION_INFO, onion_request_t::onion_request_get_fullpath(), onion_request_t::onion_request_get_header(), onion_request_t::onion_request_get_path(), onion_shortcut_rename(), onion_shortcut_response(), ONION_WARNING, and onion_webdav_t::path.
Referenced by onion_webdav_handler().
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 | ||
) |
Handles a propfind.
path | the shared path. |
References HTTP_MULTI_STATUS, HTTP_NOT_FOUND, OCS_INTERNAL_ERROR, OCS_PROCESSED, onion_block_t::onion_block_data(), onion_block_t::onion_block_free(), onion_block_t::onion_block_size(), ONION_DEBUG, ONION_DEBUG0, ONION_ERROR, onion_request_t::onion_request_get_data(), onion_request_t::onion_request_get_fullpath(), onion_request_t::onion_request_get_header(), onion_request_t::onion_request_get_path(), onion_response_flush(), onion_response_t::onion_response_set_code(), onion_response_t::onion_response_set_header(), onion_response_t::onion_response_set_length(), onion_response_t::onion_response_write(), onion_response_t::onion_response_write_headers(), onion_shortcut_response(), and onion_webdav_write_propfind().
Referenced by onion_webdav_handler().
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.
References OCS_INTERNAL_ERROR, OCS_PROCESSED, onion_block_t::onion_block_data(), onion_block_t::onion_block_size(), ONION_DEBUG, onion_request_t::onion_request_get_data(), and onion_response_t::onion_response_write_headers().
Referenced by onion_webdav_handler().
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.
realpath | Shared folder |
urlpath | URL of the requested propfind |
depth | Depth of query, 0 or 1. |
props | Properties of the query |
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.
writer | XML writer to write the data to |
realpath | The real path on the file server, used to check permissions and read data TODO |
urlpath | The base URL of the element, needed in the response. Composed with filename if filename!=NULL. |
filename | NULL if that element itself, else the subelement (file in path). |
props | Bitmask of the properties the user asked for. |
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().