Fri, 16 Aug 2013 12:41:30 +0200
added mkdir command
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | * Copyright 2013 Olaf Wintermann. All rights reserved. |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
29 | #include <stdio.h> |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | #include <stdlib.h> |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
31 | #include <string.h> |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
32 | #include <libxml/tree.h> |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
33 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | #include "utils.h" |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | #include "webdav.h" |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | #include "methods.h" |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | #include "ucx/buffer.h" |
16
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
38 | #include "ucx/utils.h" |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | #define xstreq(a,b) xmlStrEqual(BAD_CAST a, BAD_CAST b) |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | DavContext* dav_context_new() { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | DavContext *context = malloc(sizeof(DavContext)); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | if(!context) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | return NULL; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | context->namespaces = ucx_map_new(16); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | if(!context->namespaces) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | free(context); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | return NULL; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
52 | DavNamespace *davns = malloc(sizeof(DavNamespace)); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | if(!davns) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | ucx_map_free(context->namespaces); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | free(context); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | return NULL; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | davns->prefix = "D"; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | davns->name = "DAV:"; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | if(ucx_map_cstr_put(context->namespaces, "D", davns)) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | free(davns); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | ucx_map_free(context->namespaces); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | free(context); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | return NULL; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | return context; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69 | |
16
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
70 | void dav_context_destroy(DavContext *ctx) { |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
71 | // destroy all sessions assoziated with this context |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
72 | UCX_FOREACH(elm, ctx->sessions) { |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
73 | dav_session_destroy(elm->data); |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
74 | } |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
75 | |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
76 | UcxMapIterator i = ucx_map_iterator(ctx->namespaces); |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
77 | UcxKey k; |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
78 | DavNamespace *ns; |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
79 | UCX_MAP_FOREACH(k, ns, i) { |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
80 | free(ns->prefix); |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
81 | free(ns->name); |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
82 | free(ns); |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
83 | } |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
84 | ucx_map_free(ctx->namespaces); |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
85 | free(ctx); |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
86 | } |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
87 | |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
88 | int dav_add_namespace(DavContext *context, char *prefix, char *name) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
89 | DavNamespace *namespace = malloc(sizeof(DavNamespace)); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
90 | if(!namespace) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
91 | return 1; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
92 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
93 | namespace->prefix = strdup(prefix); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
94 | namespace->name = strdup(name); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
95 | return ucx_map_cstr_put(context->namespaces, prefix, namespace); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
96 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
97 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
98 | DavNamespace* dav_get_namespace(DavContext *context, char *prefix) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
99 | return ucx_map_cstr_get(context->namespaces, prefix); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
100 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
101 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
102 | DavNamespace* dav_get_namespace_s(DavContext *context, sstr_t prefix) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
103 | return ucx_map_sstr_get(context->namespaces, prefix); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
104 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
105 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
106 | DavSession* dav_session_new(DavContext *context, char *base_url) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
107 | if(!base_url) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
108 | return NULL; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
109 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
110 | sstr_t url = sstr(base_url); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
111 | if(url.length == 0) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
112 | return NULL; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
113 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
114 | DavSession *sn = malloc(sizeof(DavSession)); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
115 | if(url.ptr[url.length - 1] == '/') { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
116 | sn->base_url = strdup(base_url); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
117 | } else { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
118 | char *url_str = malloc(url.length + 2); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
119 | memcpy(url_str, base_url, url.length); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
120 | url_str[url.length] = '/'; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
121 | url_str[url.length + 1] = '\0'; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
122 | sn->base_url = url_str; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
123 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
124 | sn->context = context; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
125 | sn->handle = curl_easy_init(); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
126 | curl_easy_setopt(sn->handle, CURLOPT_URL, base_url); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
127 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
128 | sn->mp = ucx_mempool_new(1024); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
129 | sn->allocator = ucx_mempool_allocator(sn->mp); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
130 | |
16
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
131 | context->sessions = ucx_list_append(context->sessions, sn); |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
132 | |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
133 | return sn; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
134 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
135 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
136 | DavSession* dav_session_new_auth(DavContext *context, char *base_url, char *user, char *password) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
137 | DavSession *sn = dav_session_new(context, base_url); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
138 | if(!sn) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
139 | return NULL; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
140 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
141 | dav_session_set_auth(sn, user, password); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
142 | return sn; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
143 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
144 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
145 | void dav_session_set_auth(DavSession *sn, char *user, char *password) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
146 | if(user && password) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
147 | size_t ulen = strlen(user); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
148 | size_t plen = strlen(password); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
149 | size_t upwdlen = ulen + plen + 2; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
150 | char *upwdbuf = malloc(upwdlen); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
151 | snprintf(upwdbuf, upwdlen, "%s:%s\0", user, password); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
152 | curl_easy_setopt(sn->handle, CURLOPT_USERPWD, upwdbuf); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
153 | free(upwdbuf); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
154 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
155 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
156 | |
13
8a0cc4d90de7
added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
157 | void session_set_error(DavSession *sn, CURLcode c, int status) { |
8a0cc4d90de7
added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
158 | if(status > 0) { |
8a0cc4d90de7
added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
159 | switch(status) { |
8a0cc4d90de7
added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
160 | default: sn->error = DAV_ERROR; break; |
8a0cc4d90de7
added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
161 | case 401: sn->error = DAV_UNAUTHORIZED; break; |
8a0cc4d90de7
added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
162 | case 403: sn->error = DAV_FORBIDDEN; break; |
8a0cc4d90de7
added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
163 | case 404: sn->error = DAV_NOT_FOUND; break; |
16
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
164 | case 405: sn->error = DAV_METHOD_NOT_ALLOWED; break; |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
165 | case 409: sn->error = DAV_CONFLICT; break; |
13
8a0cc4d90de7
added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
166 | } |
8a0cc4d90de7
added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
167 | } else { |
8a0cc4d90de7
added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
168 | sn->error = DAV_ERROR; |
8a0cc4d90de7
added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
169 | } |
8a0cc4d90de7
added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
170 | } |
8a0cc4d90de7
added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
171 | |
16
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
172 | void dav_session_destroy(DavSession *sn) { |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
173 | // remove session from context |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
174 | UcxList *sessions = sn->context->sessions; |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
175 | ssize_t i = ucx_list_find(sessions, sn, ucx_ptrcmp, NULL); |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
176 | if(i > 0) { |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
177 | UcxList *elm = ucx_list_get(sessions, i); |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
178 | if(elm) { |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
179 | sn->context->sessions = ucx_list_remove(sessions, elm); |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
180 | } |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
181 | } |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
182 | |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
183 | ucx_mempool_destroy(sn->mp); |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
184 | curl_easy_cleanup(sn->handle); |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
185 | free(sn->base_url); |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
186 | free(sn); |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
187 | } |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
188 | |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
189 | DavResource* dav_get(DavSession *sn, char *path, char *properties) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
190 | char *url = util_concat_path(sn->base_url, path); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
191 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
192 | CURL *handle = sn->handle; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
193 | curl_easy_setopt(handle, CURLOPT_URL, url); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
194 | free(url); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
195 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
196 | UcxList *proplist = NULL; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
197 | if(properties) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
198 | proplist = parse_properties_string(sn->context, sstr(properties)); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
199 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
200 | UcxBuffer *rqbuf = create_propfind_request(proplist); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
201 | UcxBuffer *rpbuf = ucx_buffer_new(NULL, 4096, UCX_BUFFER_AUTOEXTEND); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
202 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
203 | //fwrite(rqbuf->space, 1, rqbuf->size, stdout); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
204 | //printf("\n"); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
205 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
206 | DavResource *resource = NULL; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
207 | CURLcode ret = do_propfind_request(handle, rqbuf, rpbuf); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
208 | int status = 0; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
209 | curl_easy_getinfo (handle, CURLINFO_RESPONSE_CODE, &status); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
210 | if(ret == CURLE_OK && status == 207) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
211 | //printf("response\n%s\n", rpbuf->space); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
212 | resource = parse_propfind_response(sn, rpbuf); |
13
8a0cc4d90de7
added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
213 | sn->error = DAV_OK; |
8a0cc4d90de7
added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
214 | } else { |
8a0cc4d90de7
added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
215 | session_set_error(sn, ret, status); |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
216 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
217 | return resource; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
218 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
219 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
220 | UcxList* parse_properties_string(DavContext *context, sstr_t str) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
221 | UcxList *proplist = NULL; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
222 | size_t nprops; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
223 | sstr_t *props = sstrsplit(str, S(","), &nprops); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
224 | for(int i=0;i<nprops;i++) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
225 | sstr_t s = props[i]; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
226 | sstr_t nsname = sstrchr(s, ':'); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
227 | if(nsname.length > 0) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
228 | sstr_t nspre = sstrsubsl(s, 0, nsname.ptr - s.ptr); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
229 | nsname.ptr++; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
230 | nsname.length--; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
231 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
232 | DavProperty *dp = malloc(sizeof(DavProperty)); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
233 | sstr_t pre = sstrdup(sstrtrim(nspre)); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
234 | dp->ns = dav_get_namespace(context, pre.ptr); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
235 | free(pre.ptr); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
236 | dp->name = sstrdup(nsname).ptr; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
237 | if(dp->ns && dp->name) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
238 | proplist = ucx_list_append(proplist, dp); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
239 | } else { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
240 | free(dp->name); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
241 | free(dp); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
242 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
243 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
244 | free(s.ptr); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
245 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
246 | free(props); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
247 | return proplist; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
248 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
249 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
250 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
251 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
252 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
253 | DavResource* dav_resource_new(DavSession *sn, char *path) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
254 | char *url = util_concat_path(sn->base_url, path); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
255 | char *href = util_url_path(url); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
256 | DavResource *res = resource_new_href(sn, href); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
257 | free(url); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
258 | return res; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
259 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
260 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
261 | DavResource* resource_new_href(DavSession *sn, char *href) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
262 | UcxMempool *mp = sn->mp; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
263 | UcxAllocator *a = sn->allocator; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
264 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
265 | DavResource *res = ucx_mempool_calloc(mp, 1, sizeof(DavResource)); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
266 | res->session = sn; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
267 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
268 | // set name, path and href |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
269 | resource_set_info(res, href); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
270 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
271 | // initialize node data |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
272 | res->data = node_data_new(sn); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
273 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
274 | return res; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
275 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
276 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
277 | void resource_add_property(DavResource *res, char *ns, char *name, char *value) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
278 | if(!value) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
279 | return; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
280 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
281 | UcxMempool *mp = res->session->mp; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
282 | UcxAllocator *a = res->session->allocator; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
283 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
284 | UcxKey key = dav_property_key(ns, name); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
285 | sstr_t v = sstrdup_a(a, sstr(value)); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
286 | ucx_map_put(res->data->properties, key, v.ptr); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
287 | free(key.data); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
288 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
289 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
290 | char* resource_get_property(DavResource *res, char *ns, char *name) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
291 | UcxKey key = dav_property_key(ns, name); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
292 | return ucx_map_get(res->data->properties, key); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
293 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
294 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
295 | UcxKey dav_property_key(char *ns, char *name) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
296 | sstr_t ns_str = sstr(ns); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
297 | sstr_t name_str = sstr(name); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
298 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
299 | sstr_t key; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
300 | key.length = ns_str.length + name_str.length + 1; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
301 | key.ptr = malloc(key.length + 1); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
302 | key = sstrncat(key, 3, ns_str, S(" "), name_str); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
303 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
304 | return ucx_key(key.ptr, key.length); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
305 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
306 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
307 | void resource_add_child(DavResource *parent, DavResource *child) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
308 | child->next = NULL; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
309 | if(parent->children) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
310 | DavResource *last = parent->children; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
311 | while(last->next) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
312 | last = last->next; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
313 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
314 | last->next = child; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
315 | child->prev = last; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
316 | } else { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
317 | child->prev = NULL; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
318 | parent->children = child; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
319 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
320 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
321 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
322 | void resource_set_info(DavResource *res, char *href_str) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
323 | char *url_str = NULL; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
324 | curl_easy_getinfo(res->session->handle, CURLINFO_EFFECTIVE_URL, &url_str); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
325 | sstr_t name = sstr(util_resource_name(href_str)); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
326 | sstr_t href = sstr(href_str); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
327 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
328 | sstr_t base_href = sstr(util_url_path(res->session->base_url)); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
329 | sstr_t path = sstrsubs(href, base_href.length - 1); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
330 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
331 | UcxAllocator *a = res->session->allocator; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
332 | res->name = sstrdup_a(a, name).ptr; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
333 | res->href = sstrdup_a(a, href).ptr; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
334 | res->path = sstrdup_a(a, path).ptr; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
335 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
336 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
337 | DavNodeData* node_data_new(DavSession *sn) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
338 | DavNodeData *data = ucx_mempool_malloc(sn->mp, sizeof(DavNodeData)); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
339 | if(!data) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
340 | return NULL; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
341 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
342 | data->properties = ucx_map_new_a(sn->allocator, 32); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
343 | data->set = NULL; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
344 | data->remove = NULL; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
345 | data->content = NULL; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
346 | data->read = NULL; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
347 | data->length = 0; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
348 | return data; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
349 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
350 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
351 | int dav_load(DavResource *res) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
352 | DavSession *sn = res->session; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
353 | // clean map |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
354 | UcxKey key; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
355 | void *value; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
356 | UcxMapIterator i = ucx_map_iterator(res->data->properties); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
357 | UCX_MAP_FOREACH(key, value, i) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
358 | ucx_map_remove(res->data->properties, key); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
359 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
360 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
361 | char *url = util_concat_path(sn->base_url, res->path); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
362 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
363 | CURL *handle = sn->handle; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
364 | curl_easy_setopt(handle, CURLOPT_URL, url); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
365 | free(url); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
366 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
367 | UcxBuffer *rqbuf = create_allprop_propfind_request(); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
368 | UcxBuffer *rpbuf = ucx_buffer_new(NULL, 4096, UCX_BUFFER_AUTOEXTEND); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
369 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
370 | //fwrite(rpbuf->space, 1, rpbuf->size, stdout); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
371 | //printf("\n"); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
372 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
373 | CURLcode ret = do_propfind_request(handle, rqbuf, rpbuf); |
13
8a0cc4d90de7
added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
374 | int status = 0; |
8a0cc4d90de7
added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
375 | curl_easy_getinfo (handle, CURLINFO_RESPONSE_CODE, &status); |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
376 | if(ret == CURLE_OK) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
377 | //printf("response\n%s\n", rpbuf->space); |
11 | 378 | // TODO: use parse_propfind_response() |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
379 | xmlDoc *doc = xmlReadMemory(rpbuf->space, rpbuf->size, url, NULL, 0); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
380 | if(!doc) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
381 | return 1; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
382 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
383 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
384 | xmlNode *xml_root = xmlDocGetRootElement(doc); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
385 | xmlNode *node = xml_root->children; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
386 | while(node) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
387 | if(node->type == XML_ELEMENT_NODE) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
388 | if(xstreq(node->name, "response")) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
389 | parse_response_tag(res, node); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
390 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
391 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
392 | node = node->next; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
393 | } |
11 | 394 | |
395 | set_davprops(res); | |
13
8a0cc4d90de7
added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
396 | } else { |
8a0cc4d90de7
added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
397 | session_set_error(sn, ret, status); |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
398 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
399 | return 0; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
400 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
401 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
402 | int dav_store(DavResource *res) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
403 | DavSession *sn = res->session; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
404 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
405 | char *url = util_concat_path(sn->base_url, res->path); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
406 | CURL *handle = res->session->handle; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
407 | curl_easy_setopt(handle, CURLOPT_URL, url); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
408 | free(url); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
409 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
410 | DavNodeData *data = res->data; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
411 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
412 | // store content |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
413 | if(data->content) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
414 | CURLcode ret = do_put_request(handle, data->content, data->read, data->length); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
415 | int status = 0; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
416 | curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, &status); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
417 | if(ret == CURLE_OK && (status >= 200 && status < 300)) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
418 | res->session->error = 0; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
419 | // cleanup node data |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
420 | if(!data->read) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
421 | ucx_mempool_free(sn->mp, data->content); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
422 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
423 | data->content = NULL; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
424 | data->read = NULL; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
425 | data->length = 0; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
426 | } else { |
13
8a0cc4d90de7
added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
427 | session_set_error(sn, ret, status); |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
428 | return 1; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
429 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
430 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
431 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
432 | // store properties |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
433 | if(data->set || data->remove) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
434 | UcxBuffer *request = create_proppatch_request(data); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
435 | UcxBuffer *response = ucx_buffer_new(NULL, 1024, UCX_BUFFER_AUTOEXTEND); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
436 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
437 | CURLcode ret = do_proppatch_request(handle, request, response); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
438 | int status = 0; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
439 | curl_easy_getinfo (handle, CURLINFO_RESPONSE_CODE, &status); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
440 | if(ret == CURLE_OK && status == 207) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
441 | //printf("%s\n", response->space); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
442 | // TODO: parse response |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
443 | // TODO: cleanup node data correctly |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
444 | data->set = NULL; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
445 | data->remove = NULL; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
446 | } else { |
13
8a0cc4d90de7
added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
447 | session_set_error(sn, ret, status); |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
448 | return 1; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
449 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
450 | } |
13
8a0cc4d90de7
added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
451 | sn->error = DAV_OK; |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
452 | return 0; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
453 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
454 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
455 | char* dav_get_property_ns(DavResource *res, char *ns, char *name) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
456 | char *property = resource_get_property(res, ns, name); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
457 | if(property && res->data->remove) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
458 | // TODO |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
459 | } else if(!property && res->data->set) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
460 | // TODO |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
461 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
462 | return property; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
463 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
464 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
465 | void dav_set_property_ns(DavResource *res, char *ns, char *name, char *value) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
466 | UcxAllocator *a = res->session->allocator; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
467 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
468 | DavProperty *property = a->malloc(a->pool, sizeof(DavProperty)); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
469 | property->name = sstrdup_a(a, sstr(name)).ptr; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
470 | property->value = sstrdup_a(a, sstr(value)).ptr; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
471 | DavNamespace *namespace = a->malloc(a->pool, sizeof(DavNamespace)); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
472 | namespace->prefix = NULL; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
473 | namespace->name = sstrdup_a(a, sstr(ns)).ptr; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
474 | property->ns = namespace; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
475 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
476 | res->data->set = ucx_list_append_a(a, res->data->set, property); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
477 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
478 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
479 | void dav_remove_property_ns(DavResource *res, char *ns, char *name, char *value) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
480 | UcxAllocator *a = res->session->allocator; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
481 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
482 | DavProperty *property = a->malloc(a->pool, sizeof(DavProperty)); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
483 | property->name = sstrdup_a(a, sstr(name)).ptr; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
484 | property->value = NULL; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
485 | DavNamespace *namespace = a->malloc(a->pool, sizeof(DavNamespace)); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
486 | namespace->prefix = NULL; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
487 | namespace->name = sstrdup_a(a, sstr(ns)).ptr; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
488 | property->ns = namespace; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
489 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
490 | res->data->remove = ucx_list_append_a(a, res->data->remove, property); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
491 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
492 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
493 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
494 | void dav_set_content(DavResource *res, void *stream, dav_read_func read_func) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
495 | DavNodeData *data = res->data; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
496 | data->content = stream; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
497 | data->read = read_func; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
498 | data->length = 0; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
499 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
500 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
501 | void dav_set_content_data(DavResource *res, char *content, size_t length) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
502 | DavSession *sn = res->session; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
503 | DavNodeData *data = res->data; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
504 | data->content = content; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
505 | data->read = NULL; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
506 | data->length = length; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
507 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
508 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
509 | int dav_get_content(DavResource *res, void *stream, dav_write_func write_func) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
510 | char *url = util_concat_path(res->session->base_url, res->path); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
511 | CURL *handle = res->session->handle; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
512 | curl_easy_setopt(handle, CURLOPT_URL, url); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
513 | free(url); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
514 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
515 | curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
516 | curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, NULL); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
517 | curl_easy_setopt(handle, CURLOPT_PUT, 0L); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
518 | curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
519 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
520 | curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, write_func); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
521 | curl_easy_setopt(handle, CURLOPT_WRITEDATA, stream); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
522 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
523 | CURLcode ret = curl_easy_perform(handle); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
524 | int status = 0; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
525 | curl_easy_getinfo (handle, CURLINFO_RESPONSE_CODE, &status); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
526 | if(ret == CURLE_OK && (status >= 200 && status < 300)) { |
13
8a0cc4d90de7
added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
527 | res->session->error = DAV_OK; |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
528 | return 0; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
529 | } else { |
13
8a0cc4d90de7
added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
530 | session_set_error(res->session, ret, status); |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
531 | return 1; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
532 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
533 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
534 | |
15
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
535 | int dav_delete(DavResource *res) { |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
536 | char *url = util_concat_path(res->session->base_url, res->path); |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
537 | CURL *handle = res->session->handle; |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
538 | curl_easy_setopt(handle, CURLOPT_URL, url); |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
539 | free(url); |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
540 | |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
541 | UcxBuffer *response = ucx_buffer_new(NULL, 4096, UCX_BUFFER_AUTOEXTEND); |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
542 | CURLcode ret = do_delete_request(handle, response); |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
543 | int status = 0; |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
544 | curl_easy_getinfo (handle, CURLINFO_RESPONSE_CODE, &status); |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
545 | if(ret == CURLE_OK && (status >= 200 && status < 300)) { |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
546 | res->session->error = DAV_OK; |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
547 | |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
548 | // TODO: parse response |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
549 | // TODO: free res |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
550 | |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
551 | return 0; |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
552 | } else { |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
553 | session_set_error(res->session, ret, status); |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
554 | return 1; |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
555 | } |
182af08b4813
added remove command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
13
diff
changeset
|
556 | } |
16
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
557 | |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
558 | int dav_create(DavResource *res) { |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
559 | char *url = util_concat_path(res->session->base_url, res->path); |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
560 | char *parent = util_parent_path(res->path); |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
561 | |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
562 | DavSession *sn = res->session; |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
563 | DavResource *parent_res = dav_get(sn, parent, NULL); |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
564 | if(!parent_res && sn->error == DAV_NOT_FOUND) { |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
565 | parent_res = dav_resource_new(sn, parent); |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
566 | parent_res->iscollection = 1; |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
567 | int r = dav_create(parent_res); |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
568 | if(r) { |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
569 | free(parent); |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
570 | return r; |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
571 | } |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
572 | } else if(parent_res && !res->iscollection) { |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
573 | sn->error = DAV_FORBIDDEN; |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
574 | return 1; |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
575 | } else if(sn->error != DAV_OK) { |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
576 | return 1; |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
577 | } |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
578 | |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
579 | CURL *handle = res->session->handle; |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
580 | curl_easy_setopt(handle, CURLOPT_URL, url); |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
581 | free(url); |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
582 | free(parent); |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
583 | |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
584 | // TODO: check iscollection and create empty resource or collection |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
585 | |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
586 | CURLcode ret = do_mkcol_request(handle); |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
587 | int status = 0; |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
588 | curl_easy_getinfo (handle, CURLINFO_RESPONSE_CODE, &status); |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
589 | if(ret == CURLE_OK && (status >= 200 && status < 300)) { |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
590 | res->session->error = DAV_OK; |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
591 | return 0; |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
592 | } else { |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
593 | session_set_error(res->session, ret, status); |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
594 | return 1; |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
595 | } |
5dbef9e07376
added mkdir command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
15
diff
changeset
|
596 | } |