Bug #1787 ยป 1787-webdav.c.patch
src/mod_webdav.c 2013-12-03 21:29:00.720490929 +0100 | ||
---|---|---|
plugin_config conf;
|
||
} plugin_data;
|
||
typedef struct {
|
||
enum {DESTINATION_UNPROCESSED, DESTINATION_PROCESSED} state;
|
||
buffer * file_source;
|
||
} handler_ctx;
|
||
static handler_ctx * handler_ctx_init(void) {
|
||
handler_ctx * hctx;
|
||
hctx = calloc(1, sizeof(*hctx));
|
||
hctx->state = DESTINATION_UNPROCESSED;
|
||
return hctx;
|
||
}
|
||
static void handler_ctx_free(handler_ctx *hctx) {
|
||
free(hctx);
|
||
}
|
||
static buffer * extract_path_from_uri(buffer * uri){
|
||
char * pch;
|
||
const char *str = uri->ptr;
|
||
int counter =0, position =0;
|
||
pch=strchr(str,'/');
|
||
while (pch!=NULL && counter < 2) {
|
||
counter +=1;
|
||
position = pch-str+1;
|
||
pch=strchr(pch+1,'/');
|
||
}
|
||
return buffer_init_string(pch);
|
||
}
|
||
/* init the plugin data */
|
||
INIT_FUNC(mod_webdav_init) {
|
||
plugin_data *p;
|
||
... | ... | |
return p;
|
||
}
|
||
/* detroy the plugin data */
|
||
/* destroy the plugin data */
|
||
FREE_FUNC(mod_webdav_free) {
|
||
plugin_data *p = p_d;
|
||
... | ... | |
return HANDLER_GO_ON;
|
||
}
|
||
URIHANDLER_FUNC(mod_webdav_con_reset) {
|
||
plugin_data *p = p_d;
|
||
UNUSED(srv);
|
||
if (con->plugin_ctx[p->id]) {
|
||
handler_ctx_free(con->plugin_ctx[p->id]);
|
||
con->plugin_ctx[p->id] = NULL;
|
||
}
|
||
return HANDLER_GO_ON;
|
||
}
|
||
/* handle plugin config and check values */
|
||
SETDEFAULTS_FUNC(mod_webdav_set_defaults) {
|
||
... | ... | |
}
|
||
case HTTP_METHOD_MOVE:
|
||
case HTTP_METHOD_COPY: {
|
||
buffer *destination = NULL;
|
||
buffer *destination = NULL, * tmp = NULL;
|
||
char *sep, *sep2, *start;
|
||
int overwrite = 1;
|
||
handler_ctx *hctx;
|
||
if (p->conf.is_readonly) {
|
||
con->http_status = 403;
|
||
... | ... | |
buffer_append_string_buffer(p->physical.path, p->physical.rel_path);
|
||
}
|
||
if (con->plugin_ctx[p->id] == NULL) {
|
||
hctx = handler_ctx_init();
|
||
hctx->file_source = buffer_init_string(con->physical.path->ptr);
|
||
con->plugin_ctx[p->id] = hctx;
|
||
buffer_reset(con->physical.path);
|
||
buffer_reset(con->uri.path);
|
||
buffer_copy_string_buffer(con->request.uri, extract_path_from_uri(destination));
|
||
return HANDLER_COMEBACK;
|
||
} else {
|
||
hctx = con->plugin_ctx[p->id];
|
||
tmp=buffer_init();
|
||
buffer_path_simplify(tmp, con->physical.path);
|
||
buffer_free(p->physical.path);
|
||
p->physical.path = tmp;
|
||
tmp=buffer_init();
|
||
buffer_path_simplify(tmp, hctx->file_source);
|
||
buffer_free(con->physical.path);
|
||
con->physical.path = tmp;
|
||
}
|
||
/* let's see if the source is a directory
|
||
* if yes, we fail with 501 */
|
||
... | ... | |
p->init = mod_webdav_init;
|
||
p->handle_uri_clean = mod_webdav_uri_handler;
|
||
p->handle_physical = mod_webdav_subrequest_handler;
|
||
p->connection_reset = mod_webdav_con_reset;
|
||
p->set_defaults = mod_webdav_set_defaults;
|
||
p->cleanup = mod_webdav_free;
|
||