Project

General

Profile

1787-webdav.c.patch

giuse_pes, 2013-12-03 22:49

View differences:

src/mod_webdav.c 2013-12-03 21:29:00.720490929 +0100
86 86
	plugin_config conf;
87 87
} plugin_data;
88 88

  
89
typedef struct {
90
	enum {DESTINATION_UNPROCESSED, DESTINATION_PROCESSED} state;
91
	buffer * file_source;
92
} handler_ctx;
93

  
94
static handler_ctx * handler_ctx_init(void) {
95
	handler_ctx * hctx;
96
	hctx = calloc(1, sizeof(*hctx));
97
	hctx->state = DESTINATION_UNPROCESSED;
98
	return hctx;
99
}
100

  
101
static void handler_ctx_free(handler_ctx *hctx) {
102
	free(hctx);
103
}
104

  
105
static buffer * extract_path_from_uri(buffer * uri){
106
  char * pch;
107
  const char *str  = uri->ptr;
108
  int counter =0, position =0;
109
  pch=strchr(str,'/');
110
  while (pch!=NULL && counter < 2) {
111
	counter +=1;
112
	position = pch-str+1;
113
	pch=strchr(pch+1,'/');
114
  }
115
  return buffer_init_string(pch);
116
}
117

  
89 118
/* init the plugin data */
90 119
INIT_FUNC(mod_webdav_init) {
91 120
	plugin_data *p;
......
107 136
	return p;
108 137
}
109 138

  
110
/* detroy the plugin data */
139
/* destroy the plugin data */
111 140
FREE_FUNC(mod_webdav_free) {
112 141
	plugin_data *p = p_d;
113 142

  
......
163 192
	return HANDLER_GO_ON;
164 193
}
165 194

  
195
URIHANDLER_FUNC(mod_webdav_con_reset) {
196
	plugin_data *p = p_d;
197

  
198
	UNUSED(srv);
199

  
200
	if (con->plugin_ctx[p->id]) {
201
		handler_ctx_free(con->plugin_ctx[p->id]);
202
		con->plugin_ctx[p->id] = NULL;
203
	}
204

  
205
	return HANDLER_GO_ON;
206
}
207

  
166 208
/* handle plugin config and check values */
167 209

  
168 210
SETDEFAULTS_FUNC(mod_webdav_set_defaults) {
......
1781 1823
	}
1782 1824
	case HTTP_METHOD_MOVE:
1783 1825
	case HTTP_METHOD_COPY: {
1784
		buffer *destination = NULL;
1826
		buffer *destination = NULL, * tmp = NULL;
1785 1827
		char *sep, *sep2, *start;
1786 1828
		int overwrite = 1;
1829
		handler_ctx *hctx;
1787 1830

  
1788 1831
		if (p->conf.is_readonly) {
1789 1832
			con->http_status = 403;
......
1885 1928
			buffer_append_string_buffer(p->physical.path, p->physical.rel_path);
1886 1929
		}
1887 1930

  
1931
		if (con->plugin_ctx[p->id] == NULL) {
1932
			hctx = handler_ctx_init();
1933
			hctx->file_source = buffer_init_string(con->physical.path->ptr);
1934
			con->plugin_ctx[p->id] = hctx;
1935
			buffer_reset(con->physical.path);
1936
			buffer_reset(con->uri.path);
1937
			buffer_copy_string_buffer(con->request.uri, extract_path_from_uri(destination));
1938
			return HANDLER_COMEBACK;
1939
		} else {
1940
			hctx = con->plugin_ctx[p->id];
1941
			tmp=buffer_init();
1942
			buffer_path_simplify(tmp, con->physical.path);
1943
			buffer_free(p->physical.path);
1944
			p->physical.path = tmp;
1945
			tmp=buffer_init();
1946
			buffer_path_simplify(tmp, hctx->file_source);
1947
			buffer_free(con->physical.path);
1948
			con->physical.path = tmp;
1949
		}
1950

  
1888 1951
		/* let's see if the source is a directory
1889 1952
		 * if yes, we fail with 501 */
1890 1953

  
......
2502 2565
	p->init        = mod_webdav_init;
2503 2566
	p->handle_uri_clean  = mod_webdav_uri_handler;
2504 2567
	p->handle_physical   = mod_webdav_subrequest_handler;
2568
	p->connection_reset  = mod_webdav_con_reset;
2505 2569
	p->set_defaults  = mod_webdav_set_defaults;
2506 2570
	p->cleanup     = mod_webdav_free;
2507 2571