libidav/session.c

Thu, 12 Dec 2024 16:46:43 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 12 Dec 2024 16:46:43 +0100
changeset 851
55c5d36b82b7
parent 828
e082e5d7d75b
permissions
-rw-r--r--

fix compatibility with older libcurl versions

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 *
404
5c08b8e14df8 updates copyright notice
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 355
diff changeset
4 * Copyright 2018 Olaf Wintermann. All rights reserved.
43
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
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
33 #include <cx/buffer.h>
816
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 806
diff changeset
34 #include <cx/mempool.h>
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
35 #include <cx/hash_map.h>
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 #include "utils.h"
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 #include "session.h"
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 #include "resource.h"
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 #include "methods.h"
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 DavSession* dav_session_new(DavContext *context, char *base_url) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 if(!base_url) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 return NULL;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 }
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
46 cxstring url = cx_str(base_url);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 if(url.length == 0) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 return NULL;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 DavSession *sn = malloc(sizeof(DavSession));
355
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
51 memset(sn, 0, sizeof(DavSession));
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
52 sn->mp = cxBasicMempoolCreate(DAV_SESSION_MEMPOOL_SIZE);
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
53 sn->pathcache = cxHashMapCreate(sn->mp->allocator, CX_STORE_POINTERS, DAV_PATH_CACHE_SIZE);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 sn->key = NULL;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 sn->errorstr = NULL;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 sn->error = DAV_OK;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 sn->flags = 0;
497
411bd1098175 fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 496
diff changeset
58
411bd1098175 fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 496
diff changeset
59 dav_session_set_baseurl(sn, base_url);
411bd1098175 fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 496
diff changeset
60
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 sn->handle = curl_easy_init();
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 curl_easy_setopt(sn->handle, CURLOPT_FOLLOWLOCATION, 1L);
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
63
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
64 // lock manager is created on-demand
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
65 sn->locks = NULL;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 // set proxy
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
68 DavProxy *proxy = cx_strprefix(url, CX_STR("https")) ? context->https_proxy
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 : context->http_proxy;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 if (proxy->url) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 curl_easy_setopt(sn->handle, CURLOPT_PROXY, proxy->url);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 if (proxy->username) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 curl_easy_setopt(sn->handle, CURLOPT_PROXYUSERNAME,
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 proxy->username);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 if (proxy->password) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 curl_easy_setopt(sn->handle, CURLOPT_PROXYPASSWORD,
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 proxy->password);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 } else {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 // TODO: prompt
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 if(proxy->no_proxy) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 curl_easy_setopt(sn->handle, CURLOPT_NOPROXY,
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85 proxy->no_proxy);
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
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89 // set url
420
ad419882e06e sets curl default protocol to http
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
90 #if LIBCURL_VERSION_NUM >= 0x072D00
ad419882e06e sets curl default protocol to http
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
91 curl_easy_setopt(sn->handle, CURLOPT_DEFAULT_PROTOCOL, "http");
ad419882e06e sets curl default protocol to http
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
92 #endif
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93 curl_easy_setopt(sn->handle, CURLOPT_URL, base_url);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94
68
f6d3db6113d3 added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents: 43
diff changeset
95 // add to context
805
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 796
diff changeset
96 dav_context_add_session(context, sn);
68
f6d3db6113d3 added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents: 43
diff changeset
97 sn->context = context;
43
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
806
673a803d2203 fix session dup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 805
diff changeset
116 DavSession* dav_session_clone(DavSession *sn) {
673a803d2203 fix session dup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 805
diff changeset
117 CURL *newhandle = curl_easy_duphandle(sn->handle);
673a803d2203 fix session dup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 805
diff changeset
118
673a803d2203 fix session dup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 805
diff changeset
119 DavSession *newsn = malloc(sizeof(DavSession));
673a803d2203 fix session dup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 805
diff changeset
120 memset(newsn, 0, sizeof(DavSession));
673a803d2203 fix session dup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 805
diff changeset
121 newsn->mp = cxBasicMempoolCreate(DAV_SESSION_MEMPOOL_SIZE);
828
e082e5d7d75b fix dav_session_clone using the wrong allocator for the pathcache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 816
diff changeset
122 newsn->pathcache = cxHashMapCreate(newsn->mp->allocator, CX_STORE_POINTERS, DAV_PATH_CACHE_SIZE);
806
673a803d2203 fix session dup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 805
diff changeset
123 newsn->key = sn->key;
673a803d2203 fix session dup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 805
diff changeset
124 newsn->errorstr = NULL;
673a803d2203 fix session dup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 805
diff changeset
125 newsn->error = DAV_OK;
673a803d2203 fix session dup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 805
diff changeset
126 newsn->flags = 0;
673a803d2203 fix session dup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 805
diff changeset
127
673a803d2203 fix session dup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 805
diff changeset
128 newsn->handle = newhandle;
673a803d2203 fix session dup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 805
diff changeset
129
673a803d2203 fix session dup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 805
diff changeset
130 newsn->base_url = cx_strdup_a(newsn->mp->allocator, cx_str(sn->base_url)).ptr;
673a803d2203 fix session dup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 805
diff changeset
131 newsn->auth_prompt = sn->auth_prompt;
673a803d2203 fix session dup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 805
diff changeset
132 newsn->authprompt_userdata = sn->authprompt_userdata;
673a803d2203 fix session dup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 805
diff changeset
133 newsn->logfunc = sn->logfunc;
673a803d2203 fix session dup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 805
diff changeset
134 newsn->get_progress = sn->get_progress;
673a803d2203 fix session dup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 805
diff changeset
135 newsn->put_progress = sn->put_progress;
673a803d2203 fix session dup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 805
diff changeset
136 newsn->progress_userdata = sn->progress_userdata;
673a803d2203 fix session dup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 805
diff changeset
137
673a803d2203 fix session dup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 805
diff changeset
138 // add to context
673a803d2203 fix session dup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 805
diff changeset
139 dav_context_add_session(sn->context, newsn);
673a803d2203 fix session dup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 805
diff changeset
140 newsn->context = sn->context;
673a803d2203 fix session dup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 805
diff changeset
141
673a803d2203 fix session dup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 805
diff changeset
142 return newsn;
673a803d2203 fix session dup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 805
diff changeset
143 }
673a803d2203 fix session dup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 805
diff changeset
144
796
81e0f67386a6 remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
145 void dav_session_set_auth(DavSession *sn, const char *user, const char *password) {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146 if(user && password) {
796
81e0f67386a6 remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
147 dav_session_set_auth_s(sn, cx_str(user), cx_str(password));
81e0f67386a6 remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
148 }
81e0f67386a6 remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
149 }
81e0f67386a6 remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
150
81e0f67386a6 remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
151 void dav_session_set_auth_s(DavSession *sn, cxstring user, cxstring password) {
81e0f67386a6 remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
152 if(user.length > 0 && password.length > 0) {
81e0f67386a6 remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
153 size_t upwdlen = user.length + password.length + 2;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
154 char *upwdbuf = malloc(upwdlen);
796
81e0f67386a6 remove old config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 790
diff changeset
155 snprintf(upwdbuf, upwdlen, "%.*s:%.*s", (int)user.length, user.ptr, (int)password.length, password.ptr);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
156 curl_easy_setopt(sn->handle, CURLOPT_USERPWD, upwdbuf);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
157 free(upwdbuf);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
158 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
159 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
160
497
411bd1098175 fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 496
diff changeset
161 void dav_session_set_baseurl(DavSession *sn, char *base_url) {
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
162 const CxAllocator *a = sn->mp->allocator;
497
411bd1098175 fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 496
diff changeset
163 if(sn->base_url) {
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
164 cxFree(a, sn->base_url);
497
411bd1098175 fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 496
diff changeset
165 }
411bd1098175 fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 496
diff changeset
166
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
167 cxstring url = cx_str(base_url);
497
411bd1098175 fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 496
diff changeset
168 if(url.ptr[url.length - 1] == '/') {
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
169 cxmutstr url_m = cx_strdup_a(a, cx_str(base_url));
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
170 sn->base_url = url_m.ptr;
497
411bd1098175 fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 496
diff changeset
171 } else {
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
172 char *url_str = cxMalloc(a, url.length + 2);
497
411bd1098175 fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 496
diff changeset
173 memcpy(url_str, base_url, url.length);
411bd1098175 fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 496
diff changeset
174 url_str[url.length] = '/';
411bd1098175 fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 496
diff changeset
175 url_str[url.length + 1] = '\0';
411bd1098175 fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 496
diff changeset
176 sn->base_url = url_str;
411bd1098175 fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 496
diff changeset
177 }
411bd1098175 fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 496
diff changeset
178 }
411bd1098175 fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 496
diff changeset
179
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
180 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
181 sn->key = key;
68
f6d3db6113d3 added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents: 43
diff changeset
182 // TODO: review sanity
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
183 if(flags != 0) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184 sn->flags |= flags;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
185 } else {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
186 sn->flags |= DAV_SESSION_ENCRYPT_CONTENT;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
187 }
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
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 292
diff changeset
190 void dav_session_set_authcallback(DavSession *sn, dav_auth_func func, void *userdata) {
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 292
diff changeset
191 sn->auth_prompt = func;
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 292
diff changeset
192 sn->authprompt_userdata = userdata;
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 292
diff changeset
193 }
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 292
diff changeset
194
355
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
195 void dav_session_set_progresscallback(DavSession *sn, dav_progress_func get, dav_progress_func put, void *userdata) {
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
196 sn->get_progress = get;
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
197 sn->put_progress = put;
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
198 sn->progress_userdata = userdata;
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
199 }
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
200
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 292
diff changeset
201 CURLcode dav_session_curl_perform(DavSession *sn, long *status) {
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 292
diff changeset
202 return dav_session_curl_perform_buf(sn, NULL, NULL, status);
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 292
diff changeset
203 }
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 292
diff changeset
204
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
205 CURLcode dav_session_curl_perform_buf(DavSession *sn, CxBuffer *request, CxBuffer *response, long *status) {
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 292
diff changeset
206 CURLcode ret = curl_easy_perform(sn->handle);
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 292
diff changeset
207 long http_status;
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 292
diff changeset
208 curl_easy_getinfo(sn->handle, CURLINFO_RESPONSE_CODE, &http_status);
788
9b9420041d8e add request/response body to verbose output / add DavSession logfunc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 777
diff changeset
209 if(ret == CURLE_OK) {
9b9420041d8e add request/response body to verbose output / add DavSession logfunc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 777
diff changeset
210 if(sn->logfunc) {
9b9420041d8e add request/response body to verbose output / add DavSession logfunc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 777
diff changeset
211 char *log_method;
9b9420041d8e add request/response body to verbose output / add DavSession logfunc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 777
diff changeset
212 char *log_url;
9b9420041d8e add request/response body to verbose output / add DavSession logfunc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 777
diff changeset
213 curl_easy_getinfo(sn->handle, CURLINFO_EFFECTIVE_URL, &log_url);
851
55c5d36b82b7 fix compatibility with older libcurl versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 828
diff changeset
214 #if LIBCURL_VERSION_NUM >= 0x074800
788
9b9420041d8e add request/response body to verbose output / add DavSession logfunc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 777
diff changeset
215 curl_easy_getinfo(sn->handle, CURLINFO_EFFECTIVE_METHOD , &log_method);
851
55c5d36b82b7 fix compatibility with older libcurl versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 828
diff changeset
216 #else
55c5d36b82b7 fix compatibility with older libcurl versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 828
diff changeset
217 long opt_upload = 0;
55c5d36b82b7 fix compatibility with older libcurl versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 828
diff changeset
218 curl_easy_getinfo(sn->handle, CURLOPT_UPLOAD, &opt_upload);
55c5d36b82b7 fix compatibility with older libcurl versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 828
diff changeset
219 char *opt_custom = NULL;
55c5d36b82b7 fix compatibility with older libcurl versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 828
diff changeset
220 curl_easy_getinfo(sn->handle, CURLOPT_CUSTOMREQUEST, &opt_custom);
55c5d36b82b7 fix compatibility with older libcurl versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 828
diff changeset
221 if(opt_custom) {
55c5d36b82b7 fix compatibility with older libcurl versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 828
diff changeset
222 log_method = opt_custom;
55c5d36b82b7 fix compatibility with older libcurl versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 828
diff changeset
223 } else if(opt_upload) {
55c5d36b82b7 fix compatibility with older libcurl versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 828
diff changeset
224 log_method = "PUT";
55c5d36b82b7 fix compatibility with older libcurl versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 828
diff changeset
225 } else {
55c5d36b82b7 fix compatibility with older libcurl versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 828
diff changeset
226 log_method = "GET";
55c5d36b82b7 fix compatibility with older libcurl versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 828
diff changeset
227 }
55c5d36b82b7 fix compatibility with older libcurl versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 828
diff changeset
228 #endif
788
9b9420041d8e add request/response body to verbose output / add DavSession logfunc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 777
diff changeset
229 char *log_reqbody = NULL;
9b9420041d8e add request/response body to verbose output / add DavSession logfunc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 777
diff changeset
230 size_t log_reqbodylen = 0;
9b9420041d8e add request/response body to verbose output / add DavSession logfunc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 777
diff changeset
231 char *log_rpbody = NULL;
9b9420041d8e add request/response body to verbose output / add DavSession logfunc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 777
diff changeset
232 size_t log_rpbodylen = 0;
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 292
diff changeset
233 if(request) {
788
9b9420041d8e add request/response body to verbose output / add DavSession logfunc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 777
diff changeset
234 log_reqbody = request->space;
9b9420041d8e add request/response body to verbose output / add DavSession logfunc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 777
diff changeset
235 log_reqbodylen = request->size;
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 292
diff changeset
236 }
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 292
diff changeset
237 if(response) {
788
9b9420041d8e add request/response body to verbose output / add DavSession logfunc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 777
diff changeset
238 log_rpbody = response->space;
9b9420041d8e add request/response body to verbose output / add DavSession logfunc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 777
diff changeset
239 log_rpbodylen = response->size;
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 292
diff changeset
240 }
788
9b9420041d8e add request/response body to verbose output / add DavSession logfunc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 777
diff changeset
241 sn->logfunc(sn, log_method, log_url, log_reqbody, log_reqbodylen, http_status, log_rpbody, log_rpbodylen);
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 292
diff changeset
242 }
788
9b9420041d8e add request/response body to verbose output / add DavSession logfunc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 777
diff changeset
243
9b9420041d8e add request/response body to verbose output / add DavSession logfunc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 777
diff changeset
244 if(http_status == 401 && sn->auth_prompt) {
9b9420041d8e add request/response body to verbose output / add DavSession logfunc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 777
diff changeset
245 if(!sn->auth_prompt(sn, sn->authprompt_userdata)) {
9b9420041d8e add request/response body to verbose output / add DavSession logfunc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 777
diff changeset
246 if(request) {
9b9420041d8e add request/response body to verbose output / add DavSession logfunc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 777
diff changeset
247 cxBufferSeek(request, 0, SEEK_SET);
9b9420041d8e add request/response body to verbose output / add DavSession logfunc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 777
diff changeset
248 }
9b9420041d8e add request/response body to verbose output / add DavSession logfunc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 777
diff changeset
249 if(response) {
9b9420041d8e add request/response body to verbose output / add DavSession logfunc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 777
diff changeset
250 cxBufferSeek(response, 0, SEEK_SET);
9b9420041d8e add request/response body to verbose output / add DavSession logfunc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 777
diff changeset
251 }
9b9420041d8e add request/response body to verbose output / add DavSession logfunc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 777
diff changeset
252 ret = curl_easy_perform(sn->handle);
9b9420041d8e add request/response body to verbose output / add DavSession logfunc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 777
diff changeset
253 curl_easy_getinfo(sn->handle, CURLINFO_RESPONSE_CODE, &http_status);
9b9420041d8e add request/response body to verbose output / add DavSession logfunc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 777
diff changeset
254 }
9b9420041d8e add request/response body to verbose output / add DavSession logfunc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 777
diff changeset
255 }
9b9420041d8e add request/response body to verbose output / add DavSession logfunc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 777
diff changeset
256
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 292
diff changeset
257 }
788
9b9420041d8e add request/response body to verbose output / add DavSession logfunc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 777
diff changeset
258
354
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 292
diff changeset
259 if(status) {
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 292
diff changeset
260 *status = http_status;
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 292
diff changeset
261 }
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 292
diff changeset
262 return ret;
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 292
diff changeset
263 }
067ea2315a8a moves auth prompt functionality to libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 292
diff changeset
264
355
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
265 int dav_session_get_progress(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow) {
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
266 DavResource *res = clientp;
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
267 DavSession *sn = res->session;
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
268 if(sn->get_progress) {
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
269 sn->get_progress(res, (int64_t)dltotal, (int64_t)dlnow, sn->progress_userdata);
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
270 }
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
271 return 0;
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
272 }
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
273
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
274 int dav_session_put_progress(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow) {
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
275 DavResource *res = clientp;
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
276 DavSession *sn = res->session;
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
277 if(sn->put_progress) {
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
278 sn->put_progress(res, (int64_t)ultotal, (int64_t)ulnow, sn->progress_userdata);
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
279 }
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
280 return 0;
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
281 }
5da2cf15eb44 adds primitive progress indicator
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 354
diff changeset
282
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
283 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
284 if(status > 0) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
285 switch(status) {
100
f4127c4d1018 improved error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
286 default: {
f4127c4d1018 improved error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
287 switch(c) {
f4127c4d1018 improved error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
288 default: sn->error = DAV_ERROR;
f4127c4d1018 improved error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
289 }
f4127c4d1018 improved error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
290 break;
f4127c4d1018 improved error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
291 }
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
292 case 401: sn->error = DAV_UNAUTHORIZED; break;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
293 case 403: sn->error = DAV_FORBIDDEN; break;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
294 case 404: sn->error = DAV_NOT_FOUND; break;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
295 case 405: sn->error = DAV_METHOD_NOT_ALLOWED; break;
238
b167226fb804 added support for error codes 407,413,414 and 511
Mike Becker <universe@uap-core.de>
parents: 225
diff changeset
296 case 407: sn->error = DAV_PROXY_AUTH_REQUIRED; break;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
297 case 409: sn->error = DAV_CONFLICT; break;
491
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 437
diff changeset
298 case 412: sn->error = DAV_PRECONDITION_FAILED; break;
238
b167226fb804 added support for error codes 407,413,414 and 511
Mike Becker <universe@uap-core.de>
parents: 225
diff changeset
299 case 413: sn->error = DAV_REQUEST_ENTITY_TOO_LARGE; break;
b167226fb804 added support for error codes 407,413,414 and 511
Mike Becker <universe@uap-core.de>
parents: 225
diff changeset
300 case 414: sn->error = DAV_REQUEST_URL_TOO_LONG; break;
207
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
301 case 423: sn->error = DAV_LOCKED; break;
238
b167226fb804 added support for error codes 407,413,414 and 511
Mike Becker <universe@uap-core.de>
parents: 225
diff changeset
302 case 511: sn->error = DAV_NET_AUTH_REQUIRED; break;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
303 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
304 } else {
100
f4127c4d1018 improved error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
305 switch(c) {
f4127c4d1018 improved error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
306 case CURLE_UNSUPPORTED_PROTOCOL: sn->error = DAV_UNSUPPORTED_PROTOCOL; break;
f4127c4d1018 improved error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
307 case CURLE_COULDNT_RESOLVE_PROXY: sn->error = DAV_COULDNT_RESOLVE_PROXY; break;
f4127c4d1018 improved error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
308 case CURLE_COULDNT_RESOLVE_HOST: sn->error = DAV_COULDNT_RESOLVE_HOST; break;
f4127c4d1018 improved error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
309 case CURLE_COULDNT_CONNECT: sn->error = DAV_COULDNT_CONNECT; break;
f4127c4d1018 improved error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
310 case CURLE_OPERATION_TIMEDOUT: sn->error = DAV_TIMEOUT; break;
f4127c4d1018 improved error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
311 case CURLE_SSL_CONNECT_ERROR:
f4127c4d1018 improved error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
312 case CURLE_PEER_FAILED_VERIFICATION:
f4127c4d1018 improved error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
313 case CURLE_SSL_ENGINE_NOTFOUND:
f4127c4d1018 improved error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
314 case CURLE_SSL_ENGINE_SETFAILED:
f4127c4d1018 improved error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
315 case CURLE_SSL_CERTPROBLEM:
f4127c4d1018 improved error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
316 case CURLE_SSL_CIPHER:
742
7e67689241fd new build system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 601
diff changeset
317 //#ifndef CURLE_SSL_CACERT
7e67689241fd new build system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 601
diff changeset
318 // case CURLE_SSL_CACERT:
7e67689241fd new build system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 601
diff changeset
319 //#endif
100
f4127c4d1018 improved error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
320 case CURLE_SSL_CACERT_BADFILE:
f4127c4d1018 improved error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
321 case CURLE_SSL_SHUTDOWN_FAILED:
f4127c4d1018 improved error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
322 case CURLE_SSL_CRL_BADFILE:
f4127c4d1018 improved error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
323 case CURLE_SSL_ISSUER_ERROR: sn->error = DAV_SSL_ERROR; break;
f4127c4d1018 improved error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
324 default: sn->error = DAV_ERROR; break;
f4127c4d1018 improved error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
325 }
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
326 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
327 if(c != CURLE_OK) {
225
a297c2e28fa1 improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
328 dav_session_set_errstr(sn, curl_easy_strerror(c));
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
329 } else {
225
a297c2e28fa1 improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
330 dav_session_set_errstr(sn, NULL);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
331 }
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
225
a297c2e28fa1 improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
334 void dav_session_set_errstr(DavSession *sn, const char *str) {
a297c2e28fa1 improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
335 if(sn->errorstr) {
a297c2e28fa1 improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
336 dav_session_free(sn, sn->errorstr);
a297c2e28fa1 improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
337 }
a297c2e28fa1 improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
338 char *errstr = NULL;
a297c2e28fa1 improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
339 if(str) {
a297c2e28fa1 improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
340 errstr = dav_session_strdup(sn, str);
a297c2e28fa1 improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
341 }
a297c2e28fa1 improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
342 sn->errorstr = errstr;
a297c2e28fa1 improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
343 }
a297c2e28fa1 improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
344
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
345 void dav_session_destroy(DavSession *sn) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
346 // remove session from context
805
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 796
diff changeset
347 if (dav_context_remove_session(sn->context, sn)) {
bff983370565 make DavContext mt-safe
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 796
diff changeset
348 fprintf(stderr, "Error: session not found in ctx->sessions\n");
790
7110b37f2a6b fix dav_context_destroy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 788
diff changeset
349 dav_session_destructor(sn);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
350 }
790
7110b37f2a6b fix dav_context_destroy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 788
diff changeset
351 }
7110b37f2a6b fix dav_context_destroy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 788
diff changeset
352
7110b37f2a6b fix dav_context_destroy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 788
diff changeset
353 void dav_session_destructor(DavSession *sn) {
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
354 cxMempoolDestroy(sn->mp);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
355 curl_easy_cleanup(sn->handle);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
356 free(sn);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
357 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
358
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
359
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
360 void* dav_session_malloc(DavSession *sn, size_t size) {
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
361 return cxMalloc(sn->mp->allocator, size);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
362 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
363
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
364 void* dav_session_calloc(DavSession *sn, size_t nelm, size_t size) {
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
365 return cxCalloc(sn->mp->allocator, nelm, size);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
366 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
367
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
368 void* dav_session_realloc(DavSession *sn, void *ptr, size_t size) {
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
369 return cxRealloc(sn->mp->allocator, ptr, size);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
370 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
371
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
372 void dav_session_free(DavSession *sn, void *ptr) {
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
373 cxFree(sn->mp->allocator, ptr);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
374 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
375
225
a297c2e28fa1 improved error handling in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
376 char* dav_session_strdup(DavSession *sn, const char *str) {
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
377 return cx_strdup_a(sn->mp->allocator, cx_str((char*)str)).ptr;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
378 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
379
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
380
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
381 char* dav_session_create_plain_href(DavSession *sn, const char *path) {
437
70c7d8e437f9 fixes that decrypt-name can decrypt a path and not only the name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 420
diff changeset
382 if(!DAV_ENCRYPT_NAME(sn) && !DAV_DECRYPT_NAME(sn)) {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
383 // non encrypted file names
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
384 char *url = util_path_to_url(sn, path);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
385 char *href = dav_session_strdup(sn, util_url_path(url));
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
386 free(url);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
387 return href;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
388 } else {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
389 return NULL;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
390 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
391 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
392
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
393 char* dav_session_get_href(DavSession *sn, const char *path) {
437
70c7d8e437f9 fixes that decrypt-name can decrypt a path and not only the name
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 420
diff changeset
394 if(DAV_DECRYPT_NAME(sn) || DAV_ENCRYPT_NAME(sn)) {
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
395 cxstring p = cx_str(path);
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
396 CxBuffer href;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
397 CxBuffer pbuf;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
398 cxBufferInit(&href, NULL, 256, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND);
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
399 cxBufferInit(&pbuf, NULL, 256, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND);
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
400
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
401 int start = 0;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
402 int begin = 0;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
403
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
404 // check path cache
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
405 char *cp = strdup(path);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
406 //printf("cp: %s\n", cp);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
407 while(strlen(cp) > 1) {
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
408 char *cached = cxMapGet(sn->pathcache, cx_hash_key_str(cp));
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
409 if(cached) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
410 start = strlen(cp);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
411 begin = start;
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
412 cxBufferPutString(&href, cached);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
413 break;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
414 } else {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
415 // check, if the parent path is cached
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
416 char *f = cp;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
417 cp = util_parent_path(cp);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
418 free(f);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
419 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
420 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
421 free(cp);
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
422 if(href.pos == 0) {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
423 // 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
424 // to the href buffer
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
425 cxBufferPutString(&href, util_url_path(sn->base_url));
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
426 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
427
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
428 // create resource for name lookup
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
429 cxmutstr rp = cx_strdup(cx_strn(path, start));
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
430 DavResource *root = dav_resource_new(sn, rp.ptr);
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
431 free(rp.ptr);
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
432 resource_set_href(root, cx_strn(href.space, href.pos));
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
433
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
434 // create request buffer for propfind requests
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
435 CxBuffer *rqbuf = create_basic_propfind_request();
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
436
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
437 cxstring remaining = cx_strsubs(p, start);
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
438 CxStrtokCtx elms = cx_strtok(remaining, CX_STR("/"), INT_MAX);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
439 DavResource *res = root;
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
440 cxBufferPutString(&pbuf, res->path);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
441 // iterate over all remaining path elements
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
442 cxstring elm;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
443 while(cx_strtok_next(&elms, &elm)) {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
444 if(elm.length > 0) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
445 //printf("elm: %.*s\n", elm.length, elm.ptr);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
446 DavResource *child = dav_find_child(sn, res, rqbuf, elm.ptr);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
447
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
448 // if necessary add a path separator
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
449 if(pbuf.space[pbuf.pos-1] != '/') {
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
450 if(href.space[href.pos-1] != '/') {
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
451 cxBufferPut(&href, '/');
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
452 }
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
453 cxBufferPut(&pbuf, '/');
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
454 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
455 // add last path/href to the cache
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
456 cxstring pp = cx_strn(pbuf.space, pbuf.size);
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
457 cxstring hh = cx_strn(href.space, href.size);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
458 dav_session_cache_path(sn, pp, hh);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
459
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
460 cxBufferWrite(elm.ptr, 1, elm.length, &pbuf);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
461 if(child) {
591
793af8666b3a fixes missing url encoding in dav_session_get_href() with enabled name decryption
Mike Becker <universe@uap-core.de>
parents: 505
diff changeset
462 // href is already URL encoded, so don't encode again
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
463 cxBufferPutString(&href, util_resource_name(child->href));
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
464 res = child;
496
5979ea04175e fixes dav_session_get_href() generating random names when encrypt-name is disabled
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 491
diff changeset
465 } else if(DAV_ENCRYPT_NAME(sn)) {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
466 char *random_name = util_random_str();
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
467 cxBufferPutString(&href, random_name);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
468 free(random_name);
496
5979ea04175e fixes dav_session_get_href() generating random names when encrypt-name is disabled
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 491
diff changeset
469 } else {
591
793af8666b3a fixes missing url encoding in dav_session_get_href() with enabled name decryption
Mike Becker <universe@uap-core.de>
parents: 505
diff changeset
470 // path is not URL encoded, so we have to do this here
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
471 cxstring resname = cx_str(util_resource_name((const char*)path));
600
8e7f02fd7b9b fixes incorrect URL encoding of the trailing slash for collection names
Mike Becker <universe@uap-core.de>
parents: 591
diff changeset
472 // the name of collections ends with
8e7f02fd7b9b fixes incorrect URL encoding of the trailing slash for collection names
Mike Becker <universe@uap-core.de>
parents: 591
diff changeset
473 // a trailing slash, which MUST NOT be encoded
8e7f02fd7b9b fixes incorrect URL encoding of the trailing slash for collection names
Mike Becker <universe@uap-core.de>
parents: 591
diff changeset
474 if(resname.ptr[resname.length-1] == '/') {
8e7f02fd7b9b fixes incorrect URL encoding of the trailing slash for collection names
Mike Becker <universe@uap-core.de>
parents: 591
diff changeset
475 char *esc = curl_easy_escape(sn->handle,
8e7f02fd7b9b fixes incorrect URL encoding of the trailing slash for collection names
Mike Becker <universe@uap-core.de>
parents: 591
diff changeset
476 resname.ptr, resname.length-1);
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
477 cxBufferWrite(esc, 1, strlen(esc), &href);
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
478 cxBufferPut(&href, '/');
600
8e7f02fd7b9b fixes incorrect URL encoding of the trailing slash for collection names
Mike Becker <universe@uap-core.de>
parents: 591
diff changeset
479 curl_free(esc);
8e7f02fd7b9b fixes incorrect URL encoding of the trailing slash for collection names
Mike Becker <universe@uap-core.de>
parents: 591
diff changeset
480 } else {
8e7f02fd7b9b fixes incorrect URL encoding of the trailing slash for collection names
Mike Becker <universe@uap-core.de>
parents: 591
diff changeset
481 char *esc = curl_easy_escape(sn->handle,
8e7f02fd7b9b fixes incorrect URL encoding of the trailing slash for collection names
Mike Becker <universe@uap-core.de>
parents: 591
diff changeset
482 resname.ptr, resname.length);
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
483 cxBufferWrite(esc, 1, strlen(esc), &href);
600
8e7f02fd7b9b fixes incorrect URL encoding of the trailing slash for collection names
Mike Becker <universe@uap-core.de>
parents: 591
diff changeset
484 curl_free(esc);
8e7f02fd7b9b fixes incorrect URL encoding of the trailing slash for collection names
Mike Becker <universe@uap-core.de>
parents: 591
diff changeset
485 }
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
486 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
487 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
488 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
489
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
490 // if necessary add a path separator
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
491 if(p.ptr[p.length-1] == '/') {
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
492 if(href.space[href.pos-1] != '/') {
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
493 cxBufferPut(&href, '/');
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
494 }
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
495 cxBufferPut(&pbuf, '/');
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
496 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
497 // add the final path to the cache
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
498 cxstring pp = cx_strn(pbuf.space, pbuf.size);
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
499 cxstring hh = cx_strn(href.space, href.size);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
500 dav_session_cache_path(sn, pp, hh);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
501
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
502 cxmutstr href_str = cx_strdup_a(
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
503 sn->mp->allocator,
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
504 cx_strn(href.space, href.size));
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
505
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
506 // cleanup
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
507 dav_resource_free_all(root);
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
508 cxBufferFree(rqbuf);
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
509
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
510 cxBufferDestroy(&pbuf);
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
511 cxBufferDestroy(&href);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
512
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
513 return href_str.ptr;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
514 } else {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
515 return dav_session_create_plain_href(sn, path);
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
516 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
517 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
518
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
519 DavResource* dav_find_child(DavSession *sn, DavResource *res, CxBuffer *rqbuf, const char *name) {
135
664aeaec8d25 replaced old davql (still buggy)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 104
diff changeset
520 if(res && !dav_propfind(sn, res, rqbuf)) {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
521 DavResource *child = res->children;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
522 while(child) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
523 if(!strcmp(child->name, name)) {
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
524 return child;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
525 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
526 child = child->next;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
527 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
528 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
529 return NULL;
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
530 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
531
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
532 void dav_session_cache_path(DavSession *sn, cxstring path, cxstring href) {
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
533 CxHashKey path_key = cx_hash_key(path.ptr, path.length);
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
534 char *elm = cxMapGet(sn->pathcache, path_key);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
535 if(!elm) {
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
536 cxmutstr href_s = cx_strdup_a(sn->mp->allocator, href);
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
537 cxMapPut(sn->pathcache, path_key, href_s.ptr);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
538 }
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
539 }
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
540
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
541
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
542 DavLock* dav_create_lock(DavSession *sn, const char *token, char *timeout) {
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
543 DavLock *lock = dav_session_malloc(sn, sizeof(DavLock));
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
544 lock->path = NULL;
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
545 lock->token = dav_session_strdup(sn, token);
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
546
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
547 // TODO: timeout
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
548
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
549 return lock;
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
550 }
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
551
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
552 void dav_destroy_lock(DavSession *sn, DavLock *lock) {
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
553 dav_session_free(sn, lock->token);
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
554 if(lock->path) {
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
555 dav_session_free(sn, lock->path);
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
556 }
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
557 dav_session_free(sn, lock);
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
558 }
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
559
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
560
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
561 static int dav_lock_cmp(void const *left, void const *right) {
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
562 const DavLock *l = left;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
563 const DavLock *r = right;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
564 return strcmp(l->path, r->path);
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
565 }
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
566
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
567 static int create_lock_manager(DavSession *sn) {
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
568 // create lock manager
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
569 DavLockManager *locks = cxMalloc(sn->mp->allocator, sizeof(DavLockManager));
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
570 locks->resource_locks = cxHashMapCreate(sn->mp->allocator, CX_STORE_POINTERS, 16);
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
571 locks->collection_locks = cxLinkedListCreate(sn->mp->allocator, dav_lock_cmp, CX_STORE_POINTERS);
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
572 sn->locks = locks;
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
573 return 0;
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
574 }
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
575
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
576 static DavLockManager* get_lock_manager(DavSession *sn) {
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
577 DavLockManager *locks = sn->locks;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
578 if(!locks) {
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
579 if(create_lock_manager(sn)) {
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
580 return NULL;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
581 }
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
582 locks = sn->locks;
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
583 }
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
584 return locks;
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
585 }
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
586
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
587 int dav_add_resource_lock(DavSession *sn, const char *path, DavLock *lock) {
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
588 DavLockManager *locks = get_lock_manager(sn);
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
589 if(!locks) {
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
590 return -1;
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
591 }
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
592
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
593 CxHashKey path_key = cx_hash_key_str(path);
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
594 if(cxMapGet(locks->resource_locks, path_key)) {
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
595 return -1;
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
596 }
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
597
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
598 cxMapPut(locks->resource_locks, path_key, lock);
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
599 return 0;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
600 }
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
601
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
602 int dav_add_collection_lock(DavSession *sn, const char *path, DavLock *lock) {
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
603 DavLockManager *locks = get_lock_manager(sn);
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
604 if(!locks) {
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
605 return -1;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
606 }
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
607
777
15006651a5d1 fix dav_add_collection_lock() setting the lock path
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 747
diff changeset
608 lock->path = dav_session_strdup(sn, path);
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
609 cxListAdd(locks->collection_locks, lock);
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
610 cxListSort(locks->collection_locks);
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
611
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
612 return 0;
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
613 }
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
614
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
615 DavLock* dav_get_lock(DavSession *sn, const char *path) {
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
616 DavLockManager *locks = get_lock_manager(sn);
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
617 if(!locks) {
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
618 return NULL;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
619 }
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
620
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
621 cxstring p = cx_str(path);
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
622
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
623 DavLock *lock = cxMapGet(locks->resource_locks, cx_hash_key(p.ptr, p.length));
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
624 if(lock) {
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
625 return lock;
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
626 }
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
627
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
628 CxIterator i = cxListIterator(locks->collection_locks);
777
15006651a5d1 fix dav_add_collection_lock() setting the lock path
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 747
diff changeset
629 cx_foreach(DavLock*, col_lock, i) {
15006651a5d1 fix dav_add_collection_lock() setting the lock path
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 747
diff changeset
630 int cmd = strcmp(path, col_lock->path);
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
631 if(cmd == 0) {
777
15006651a5d1 fix dav_add_collection_lock() setting the lock path
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 747
diff changeset
632 return col_lock;
15006651a5d1 fix dav_add_collection_lock() setting the lock path
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 747
diff changeset
633 } else if(cx_strprefix(p, cx_str(col_lock->path))) {
15006651a5d1 fix dav_add_collection_lock() setting the lock path
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 747
diff changeset
634 return col_lock;
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
635 } else if(cmd > 0) {
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
636 break;
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
637 }
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
638 }
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
639
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
640 return NULL;
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
641 }
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
642
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
643 void dav_remove_lock(DavSession *sn, const char *path, DavLock *lock) {
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
644 DavLockManager *locks = get_lock_manager(sn);
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
645 if(!locks) {
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
646 return;
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
647 }
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
648
747
efbd59642577 ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 742
diff changeset
649 if(cxMapRemoveAndGet(locks->resource_locks, cx_hash_key_str(path))) {
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
650 return;
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
651 }
816
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 806
diff changeset
652
839fefbdedc7 compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents: 806
diff changeset
653 cxListFindRemove(locks->collection_locks, lock);
208
1fb26aca5093 added API for webdav locking
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
654 }

mercurial