75 static WebdavProperty dav_resourcetype_collection; |
75 static WebdavProperty dav_resourcetype_collection; |
76 static WSXmlData dav_resourcetype_collection_value; |
76 static WSXmlData dav_resourcetype_collection_value; |
77 |
77 |
78 #define WEBDAV_RESOURCE_TYPE_COLLECTION "<D:collection/>" |
78 #define WEBDAV_RESOURCE_TYPE_COLLECTION "<D:collection/>" |
79 |
79 |
|
80 static void webdav_cleanup(void *data) { |
|
81 cxMapDestroy(webdav_type_map); |
|
82 cxMapDestroy(method_handler_map); |
|
83 } |
80 |
84 |
81 static WebdavBackend* default_backend_create(Session *sn, Request *rq, pblock *pb, void *initData) { |
85 static WebdavBackend* default_backend_create(Session *sn, Request *rq, pblock *pb, void *initData) { |
82 WebdavBackend *dav = pool_malloc(sn->pool, sizeof(WebdavBackend)); |
86 WebdavBackend *dav = pool_malloc(sn->pool, sizeof(WebdavBackend)); |
83 if(!dav) { |
87 if(!dav) { |
84 return NULL; |
88 return NULL; |
103 return webdav_register_backend("default", NULL, default_backend_create); |
107 return webdav_register_backend("default", NULL, default_backend_create); |
104 } |
108 } |
105 |
109 |
106 |
110 |
107 int webdav_register_backend(const char *name, webdav_init_func webdavInit, webdav_create_func webdavCreate) { |
111 int webdav_register_backend(const char *name, webdav_init_func webdavInit, webdav_create_func webdavCreate) { |
108 WebdavType *webdavType = malloc(sizeof(WebdavType)); |
112 WebdavType webdavType; |
109 webdavType->init = webdavInit; |
113 webdavType.init = webdavInit; |
110 webdavType->create = webdavCreate; |
114 webdavType.create = webdavCreate; |
111 return cxMapPut(webdav_type_map, cx_hash_key_str(name), webdavType); |
115 return cxMapPut(webdav_type_map, cx_hash_key_str(name), &webdavType); |
112 } |
116 } |
113 |
117 |
114 WebdavType* webdav_get_type(cxstring dav_class) { |
118 WebdavType* webdav_get_type(cxstring dav_class) { |
115 return cxMapGet(webdav_type_map, cx_hash_key_bytes((unsigned const char *)dav_class.ptr, dav_class.length)); |
119 return cxMapGet(webdav_type_map, cx_hash_key_bytes((unsigned const char *)dav_class.ptr, dav_class.length)); |
116 } |
120 } |
144 if(webdav_is_initialized) { |
148 if(webdav_is_initialized) { |
145 return REQ_NOACTION; |
149 return REQ_NOACTION; |
146 } |
150 } |
147 webdav_is_initialized = TRUE; |
151 webdav_is_initialized = TRUE; |
148 |
152 |
149 webdav_type_map = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 8); |
153 webdav_type_map = cxHashMapCreate(cxDefaultAllocator, sizeof(WebdavType), 8); |
150 if(!webdav_type_map) { |
154 if(!webdav_type_map) { |
151 return REQ_ABORTED; |
155 return REQ_ABORTED; |
152 } |
156 } |
153 |
157 |
154 method_handler_map = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 64); |
158 method_handler_map = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 64); |
200 |
204 |
201 dav_resourcetype_collection.namespace = &dav_namespace; |
205 dav_resourcetype_collection.namespace = &dav_namespace; |
202 dav_resourcetype_collection.name = "resourcetype"; |
206 dav_resourcetype_collection.name = "resourcetype"; |
203 dav_resourcetype_collection.value.data = dav_resourcetype_collection_value; |
207 dav_resourcetype_collection.value.data = dav_resourcetype_collection_value; |
204 dav_resourcetype_collection.vtype = WS_VALUE_XML_DATA; |
208 dav_resourcetype_collection.vtype = WS_VALUE_XML_DATA; |
|
209 |
|
210 webserver_atrestart(webdav_cleanup, NULL); |
205 |
211 |
206 return REQ_PROCEED; |
212 return REQ_PROCEED; |
207 } |
213 } |
208 |
214 |
209 |
215 |