libidav/session.c

Fri, 13 Jun 2014 13:52:59 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Fri, 13 Jun 2014 13:52:59 +0200
changeset 46
0542668d0f26
parent 43
03076907b58a
child 68
f6d3db6113d3
permissions
-rw-r--r--

added new sync tool

43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2014 Olaf Wintermann. All rights reserved.
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
03076907b58a added file name 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
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include <stdio.h>
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include <stdlib.h>
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #include <string.h>
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include <ucx/buffer.h>
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 #include <ucx/utils.h>
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 #include "utils.h"
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 #include "session.h"
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 #include "resource.h"
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 #include "methods.h"
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 DavSession* dav_session_new(DavContext *context, char *base_url) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 if(!base_url) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 return NULL;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 sstr_t url = sstr(base_url);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 if(url.length == 0) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 return NULL;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 DavSession *sn = malloc(sizeof(DavSession));
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 sn->mp = ucx_mempool_new(DAV_SESSION_MEMPOOL_SIZE);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 sn->pathcache = ucx_map_new_a(sn->mp->allocator, DAV_PATH_CACHE_SIZE);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 sn->key = NULL;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 sn->errorstr = NULL;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 sn->error = DAV_OK;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 sn->flags = 0;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 if(url.ptr[url.length - 1] == '/') {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 sstr_t url = sstrdup_a(sn->mp->allocator, sstr(base_url));
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 sn->base_url = url.ptr;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 } else {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 char *url_str = malloc(url.length + 2);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 memcpy(url_str, base_url, url.length);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 url_str[url.length] = '/';
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 url_str[url.length + 1] = '\0';
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 sn->base_url = url_str;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 sn->context = context;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 sn->handle = curl_easy_init();
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 //curl_easy_setopt(sn->handle, CURLOPT_VERBOSE, 1L);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 //curl_easy_setopt(sn->handle, CURLOPT_STDERR, stderr);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 curl_easy_setopt(sn->handle, CURLOPT_FOLLOWLOCATION, 1L);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 // set proxy
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 DavProxy *proxy = sstrprefix(url, S("https")) ? context->https_proxy
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 : context->http_proxy;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 if (proxy->url) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 curl_easy_setopt(sn->handle, CURLOPT_PROXY, proxy->url);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 if (proxy->username) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 curl_easy_setopt(sn->handle, CURLOPT_PROXYUSERNAME,
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 proxy->username);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 if (proxy->password) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 curl_easy_setopt(sn->handle, CURLOPT_PROXYPASSWORD,
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 proxy->password);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 } else {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85 // TODO: prompt
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 if(proxy->no_proxy) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89 curl_easy_setopt(sn->handle, CURLOPT_NOPROXY,
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 proxy->no_proxy);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 // set url
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 curl_easy_setopt(sn->handle, CURLOPT_URL, base_url);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97 context->sessions = ucx_list_append(context->sessions, sn);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99 return sn;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 DavSession* dav_session_new_auth(
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 DavContext *context,
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 char *base_url,
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 char *user,
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106 char *password)
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107 {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108 DavSession *sn = dav_session_new(context, base_url);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109 if(!sn) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 return NULL;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112 dav_session_set_auth(sn, user, password);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113 return sn;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 void dav_session_set_auth(DavSession *sn, char *user, char *password) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 if(user && password) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118 size_t ulen = strlen(user);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119 size_t plen = strlen(password);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120 size_t upwdlen = ulen + plen + 2;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121 char *upwdbuf = malloc(upwdlen);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122 snprintf(upwdbuf, upwdlen, "%s:%s\0", user, password);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123 curl_easy_setopt(sn->handle, CURLOPT_USERPWD, upwdbuf);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124 free(upwdbuf);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128 void dav_session_set_flags(DavSession *sn, uint32_t flags) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 sn->flags = flags;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132 uint32_t dav_session_get_flags(DavSession *sn) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133 return sn->flags;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136 void dav_session_enable_encryption(DavSession *sn, DavKey *key, int flags) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137 sn->key = key;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
138 if(flags != 0) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139 sn->flags |= flags;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140 } else {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141 sn->flags |= DAV_SESSION_ENCRYPT_CONTENT;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
142 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
143 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
144
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145 void dav_session_set_error(DavSession *sn, CURLcode c, int status) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146 if(status > 0) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
147 switch(status) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
148 default: sn->error = DAV_ERROR; break;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
149 case 401: sn->error = DAV_UNAUTHORIZED; break;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
150 case 403: sn->error = DAV_FORBIDDEN; break;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
151 case 404: sn->error = DAV_NOT_FOUND; break;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
152 case 405: sn->error = DAV_METHOD_NOT_ALLOWED; break;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
153 case 409: sn->error = DAV_CONFLICT; break;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
154 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
155 } else {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
156 sn->error = DAV_ERROR;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
157 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
158 if(c != CURLE_OK) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
159 sn->errorstr = curl_easy_strerror(c);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
160 } else {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
161 sn->errorstr = NULL;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
162 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
164
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
165 void dav_session_destroy(DavSession *sn) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
166 // remove session from context
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
167 UcxList *sessions = sn->context->sessions;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
168 ssize_t i = ucx_list_find(sessions, sn, ucx_ptrcmp, NULL);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
169 if(i > 0) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
170 UcxList *elm = ucx_list_get(sessions, i);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
171 if(elm) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
172 sn->context->sessions = ucx_list_remove(sessions, elm);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
173 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
174 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
175
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
176 ucx_mempool_destroy(sn->mp);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
177 curl_easy_cleanup(sn->handle);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
178 free(sn);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
179 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
180
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
181
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
182 void* dav_session_malloc(DavSession *sn, size_t size) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
183 return ucx_mempool_malloc(sn->mp, size);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
185
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
186 void* dav_session_calloc(DavSession *sn, size_t nelm, size_t size) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
187 return ucx_mempool_calloc(sn->mp, nelm, size);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
188 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
189
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
190 void* dav_session_realloc(DavSession *sn, void *ptr, size_t size) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
191 return ucx_mempool_realloc(sn->mp, ptr, size);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
192 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
193
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
194 void dav_session_free(DavSession *sn, void *ptr) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
195 ucx_mempool_free(sn->mp, ptr);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
196 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
197
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
198 char* dav_session_strdup(DavSession *sn, char *str) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
199 return sstrdup_a(sn->mp->allocator, sstr(str)).ptr;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
200 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
201
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
202
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
203 char* dav_session_create_plain_href(DavSession *sn, char *path) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
204 if(!DAV_ENCRYPT_NAME(sn)) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
205 // non encrypted file names
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
206 char *url = util_path_to_url(sn, path);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
207 char *href = dav_session_strdup(sn, util_url_path(url));
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
208 free(url);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
209 return href;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
210 } else {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
211 return NULL;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
212 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
213 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
214
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
215 char* dav_session_get_href(DavSession *sn, char *path) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
216 if(DAV_ENCRYPT_NAME(sn)) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
217 sstr_t p = sstr(path);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
218 UcxBuffer *href = ucx_buffer_new(NULL, 256, UCX_BUFFER_AUTOEXTEND);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
219 UcxBuffer *pbuf = ucx_buffer_new(NULL, 256, UCX_BUFFER_AUTOEXTEND);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
220 int start = 0;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
221 int begin = 0;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
222
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
223 // check path cache
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
224 char *cp = strdup(path);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
225 //printf("cp: %s\n", cp);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
226 while(strlen(cp) > 1) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
227 char *cached = ucx_map_cstr_get(sn->pathcache, cp);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
228 if(cached) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
229 start = strlen(cp);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
230 begin = start;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
231 ucx_buffer_puts(href, cached);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
232 break;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
233 } else {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
234 // check, if the parent path is cached
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
235 char *f = cp;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
236 cp = util_parent_path(cp);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
237 free(f);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
238 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
239 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
240 free(cp);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
241 if(href->pos == 0) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
242 // if there are no cached elements we have to add the base url path
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
243 // to the href buffer
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
244 ucx_buffer_puts(href, util_url_path(sn->base_url));
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
245 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
246
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
247 // create resource for name lookup
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
248 sstr_t rp = sstrdup(sstrn(path, start));
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
249 DavResource *root = dav_resource_new(sn, rp.ptr);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
250 resource_set_href(root, sstrn(href->space, href->pos));
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
251
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
252 // create request buffer for propfind requests
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
253 UcxBuffer *rqbuf = create_basic_propfind_request();
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
254
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
255 sstr_t remaining = sstrsubs(p, start);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
256 size_t nelm = 0;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
257 sstr_t *elms = sstrsplit(remaining, S("/"), &nelm);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
258 DavResource *res = root;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
259 ucx_buffer_puts(pbuf, res->path);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
260 // iterate over all remaining path elements
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
261 for(int i=0;i<nelm;i++) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
262 sstr_t elm = elms[i];
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
263 if(elm.length > 0) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
264 //printf("elm: %.*s\n", elm.length, elm.ptr);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
265 DavResource *child = dav_find_child(sn, res, rqbuf, elm.ptr);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
266
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
267 // if necessary add a path separator
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
268 if(pbuf->space[pbuf->pos-1] != '/') {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
269 if(href->space[href->pos-1] != '/') {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
270 ucx_buffer_putc(href, '/');
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
271 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
272 ucx_buffer_putc(pbuf, '/');
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
273 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
274 // add last path/href to the cache
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
275 sstr_t pp = sstrn(pbuf->space, pbuf->size);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
276 sstr_t hh = sstrn(href->space, href->size);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
277 dav_session_cache_path(sn, pp, hh);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
278
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
279 ucx_buffer_write(elm.ptr, 1, elm.length, pbuf);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
280 if(child) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
281 ucx_buffer_puts(href, util_resource_name(child->href));
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
282 res = child;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
283 } else {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
284 //printf("random\n");
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
285 char *random_name = util_random_str();
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
286 ucx_buffer_puts(href, random_name);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
287 free(random_name);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
288 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
289
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
290 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
291 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
292
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
293 // if necessary add a path separator
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
294 if(p.ptr[p.length-1] == '/') {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
295 if(href->space[href->pos-1] != '/') {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
296 ucx_buffer_putc(href, '/');
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
297 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
298 ucx_buffer_putc(pbuf, '/');
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
299 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
300 // add the final path to the cache
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
301 sstr_t pp = sstrn(pbuf->space, pbuf->size);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
302 sstr_t hh = sstrn(href->space, href->size);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
303 dav_session_cache_path(sn, pp, hh);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
304
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
305 sstr_t href_str = sstrdup_a(
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
306 sn->mp->allocator,
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
307 sstrn(href->space,
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
308 href->size));
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
309
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
310 // cleanup
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
311 dav_resource_free_all(root);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
312 ucx_buffer_free(pbuf);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
313 ucx_buffer_free(href);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
314
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
315 return href_str.ptr;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
316 } else {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
317 return dav_session_create_plain_href(sn, path);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
318 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
319 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
320
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
321 DavResource* dav_find_child(DavSession *sn, DavResource *res, UcxBuffer *rqbuf, char *name) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
322 if(res && !dav_propfind(sn, res, rqbuf, NULL, 0)) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
323 DavResource *child = res->children;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
324 while(child) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
325 if(!strcmp(child->name, name)) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
326 return child;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
327 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
328 child = child->next;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
329 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
330 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
331 return NULL;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
332 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
333
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
334 void dav_session_cache_path(DavSession *sn, sstr_t path, sstr_t href) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
335 char *elm = ucx_map_sstr_get(sn->pathcache, path);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
336 if(!elm) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
337 href = sstrdup_a(sn->mp->allocator, href);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
338 ucx_map_sstr_put(sn->pathcache, path, href.ptr);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
339 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
340 }

mercurial