application/config.c

Sun, 27 Oct 2024 18:24:37 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 27 Oct 2024 18:24:37 +0100
changeset 60
ee4e4742391e
parent 55
1ce14068ef31
permissions
-rw-r--r--

add settings window and implement repository editing

55
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
1 /*
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
3 *
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
4 * Copyright 2018 Olaf Wintermann. All rights reserved.
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
5 *
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
6 * Redistribution and use in source and binary forms, with or without
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
7 * modification, are permitted provided that the following conditions are met:
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
8 *
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
10 * notice, this list of conditions and the following disclaimer.
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
11 *
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
14 * documentation and/or other materials provided with the distribution.
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
15 *
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
27 */
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
28
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
29 #include <stdio.h>
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
30 #include <stdlib.h>
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
31 #include <string.h>
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
32 #include <sys/types.h>
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
33 #include <cx/hash_map.h>
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
34 #include <cx/utils.h>
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
35 #include <errno.h>
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
36 #include <libxml/tree.h>
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
37
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
38 #include "config.h"
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
39 #include "pwd.h"
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
40 #include "system.h"
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
41
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
42 #include <libidav/utils.h>
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
43 #include <libidav/config.h>
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
44
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
45 #define xstreq(a,b) xmlStrEqual(BAD_CAST a, BAD_CAST b)
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
46 #define xstrEQ(a,b) !xmlStrcasecmp(BAD_CAST a, BAD_CAST b)
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
47
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
48 #define print_error(lineno, ...) \
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
49 do {\
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
50 fprintf(stderr, "Error (config.xml line %u): ", lineno); \
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
51 fprintf(stderr, __VA_ARGS__); \
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
52 fprintf(stderr, "Abort.\n"); \
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
53 } while(0);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
54 #define print_warning(lineno, ...) \
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
55 do {\
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
56 fprintf(stderr, "Warning (config.xml line %u): ", lineno); \
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
57 fprintf(stderr, __VA_ARGS__); \
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
58 } while(0);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
59
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
60 #ifdef _WIN32
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
61 #define ENV_HOME getenv("USERPROFILE")
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
62 #else
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
63 #define ENV_HOME getenv("HOME")
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
64 #endif /* _WIN32 */
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
65
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
66 static CxMap *repos;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
67 static CxMap *keys;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
68
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
69 static DavConfig *davconfig;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
70 static PwdStore *pstore;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
71
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
72 static char *secretstore_unlock_cmd;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
73 static char *secretstore_lock_cmd;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
74
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
75 int check_config_dir(void) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
76 char *file = util_concat_path(ENV_HOME, ".dav");
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
77 int ret = 0;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
78 if(util_mkdir(file, S_IRWXU)) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
79 if(errno != EEXIST) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
80 ret = 1;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
81 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
82 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
83 free(file);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
84 return ret;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
85 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
86
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
87 static DavContext *context;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
88
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
89 void create_default_config(char *file) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
90 xmlDoc *doc = xmlNewDoc(BAD_CAST "1.0");
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
91 xmlNode *root = xmlNewNode(NULL, BAD_CAST "configuration");
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
92 xmlDocSetRootElement(doc, root);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
93 xmlSaveFormatFileEnc(file, doc, "UTF-8", 1);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
94 xmlFreeDoc(doc);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
95 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
96
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
97 char* config_file_path(char *name) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
98 char *davd = util_concat_path(ENV_HOME, ".dav");
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
99 if(!davd) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
100 return NULL;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
101 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
102 char *path = util_concat_path(davd, name);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
103 free(davd);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
104 return path;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
105 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
106
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
107 cxmutstr config_load_file(const char *path) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
108 FILE *file = sys_fopen(path, "r");
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
109 if(!file) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
110 return (cxmutstr){NULL,0};
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
111 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
112
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
113 CxBuffer buf;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
114 cxBufferInit(&buf, NULL, 1024, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
115 cx_stream_copy(file, &buf, (cx_read_func)fread, (cx_write_func)cxBufferWrite);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
116 fclose(file);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
117
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
118 return cx_mutstrn(buf.space, buf.size);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
119 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
120
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
121 int load_config(DavContext *ctx) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
122 context = ctx;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
123 // TODO: free the config somewhere
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
124 repos = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 16);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
125 keys = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 16);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
126
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
127 char *pwfile = util_concat_path(ENV_HOME, ".dav/secrets.crypt");
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
128 pstore = pwdstore_open(pwfile);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
129 free(pwfile);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
130
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
131 char *file = util_concat_path(ENV_HOME, ".dav/config.xml");
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
132
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
133 struct stat s;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
134 if(stat(file, &s)) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
135 switch(errno) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
136 case ENOENT: {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
137 davconfig = dav_config_new(NULL);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
138 return 0;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
139 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
140 default: {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
141 perror("Cannot load config.xml");
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
142 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
143 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
144 return 1;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
145 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
146
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
147 cxmutstr config_content = config_load_file(file);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
148 int config_error;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
149 davconfig = dav_config_load(config_content, &config_error);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
150 free(config_content.ptr);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
151 free(file);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
152
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
153 if(!davconfig) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
154 fprintf(stderr, "Cannot load config.xml\n");
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
155 return 1;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
156 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
157
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
158 if(dav_config_register_namespaces(davconfig, ctx)) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
159 return 1;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
160 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
161
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
162 return dav_config_register_keys(davconfig, ctx, load_key_file);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
163 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
164
60
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
165 DavConfig* load_config_file(void) {
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
166 char *file = util_concat_path(ENV_HOME, ".dav/config.xml");
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
167
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
168 struct stat s;
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
169 if(stat(file, &s)) {
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
170 switch(errno) {
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
171 case ENOENT: {
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
172 davconfig = dav_config_new(NULL);
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
173 return NULL;
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
174 }
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
175 default: {
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
176 perror("Cannot load config.xml");
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
177 }
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
178 }
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
179 return NULL;
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
180 }
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
181
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
182 cxmutstr config_content = config_load_file(file);
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
183 int config_error;
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
184 DavConfig *cfg = dav_config_load(config_content, &config_error);
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
185 free(config_content.ptr);
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
186 free(file);
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
187 return cfg;
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
188 }
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
189
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
190
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
191 void set_config(DavConfig *cfg) {
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
192 davconfig = cfg;
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
193 }
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
194
55
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
195 DavConfig* get_config(void) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
196 return davconfig;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
197 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
198
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
199 int store_config(void) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
200 if(check_config_dir()) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
201 return 1;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
202 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
203
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
204 CxBuffer *buf = dav_config2buf(davconfig);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
205 if(!buf) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
206 return 1;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
207 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
208
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
209 char *file = util_concat_path(ENV_HOME, ".dav/config.xml");
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
210 FILE *cout = sys_fopen(file, "w");
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
211 if(!cout) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
212 cxBufferFree(buf);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
213 return 1;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
214 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
215
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
216 // should only fail if we run out of disk space or something like that
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
217 // in that case, the config file is only destroyed
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
218 // could only be prevented, if we write to a temp file first and than
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
219 // rename it
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
220 fwrite(buf->space, buf->size, 1, cout);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
221
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
222 cxBufferFree(buf);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
223 fclose(cout);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
224
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
225 return 0;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
226 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
227
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
228 void free_config(void) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
229 if(davconfig) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
230 dav_config_free(davconfig);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
231 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
232 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
233
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
234 cxmutstr load_key_file(const char *filename) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
235 cxmutstr k;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
236 k.ptr = NULL;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
237 k.length = 0;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
238
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
239 FILE *file = NULL;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
240 if(filename[0] == '/') {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
241 file = sys_fopen(filename, "r");
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
242 } else {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
243 char *path = util_concat_path(ENV_HOME, ".dav/");
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
244 char *p2 = util_concat_path(path, filename);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
245 file = sys_fopen(p2, "r");
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
246 free(path);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
247 free(p2);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
248 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
249
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
250 if(!file) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
251 fprintf(stderr, "Error: cannot load keyfile %s\n", filename);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
252 return k;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
253 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
254
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
255 char *data = malloc(256);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
256 size_t r = fread(data, 1, 256, file);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
257 k.ptr = data;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
258 k.length = r;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
259
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
260 fclose(file);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
261 return k;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
262 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
263
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
264 PwdStore* get_pwdstore(void) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
265 return pstore;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
266 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
267
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
268 int pwdstore_save(PwdStore *pwdstore) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
269 if(check_config_dir()) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
270 return 1;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
271 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
272
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
273 char *pwfile = util_concat_path(ENV_HOME, ".dav/secrets.crypt");
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
274 int ret = pwdstore_store(pwdstore, pwfile);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
275 free(pwfile);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
276 return ret;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
277 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
278
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
279 typedef struct CredLocation {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
280 char *id;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
281 char *location;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
282 } CredLocation;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
283
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
284 static int cmp_url_cred_entry(CredLocation *e1, CredLocation *e2, void *n) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
285 return strcmp(e2->location, e1->location);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
286 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
287
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
288 static void free_cred_location(CredLocation *c) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
289 // c->id is not a copy, therefore we don't have to free it
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
290 free(c->location);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
291 free(c);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
292 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
293
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
294 int get_stored_credentials(char *credid, char **user, char **password) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
295 if(!credid) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
296 return 0;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
297 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
298
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
299 PwdStore *secrets = get_pwdstore();
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
300 if(!secrets) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
301 fprintf(stderr, "Error: no secrets store available\n");
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
302 return 0;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
303 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
304
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
305 if(pwdstore_has_id(secrets, credid)) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
306 if(!secrets->isdecrypted) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
307 if(pwdstore_decrypt_secrets(secrets)) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
308 return 0;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
309 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
310 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
311
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
312 PwdEntry *s_cred = pwdstore_get(secrets, credid);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
313 if(s_cred) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
314 *user = s_cred->user;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
315 *password = s_cred->password;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
316 return 1;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
317 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
318 } else {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
319 fprintf(stderr, "Error: credentials id '%s' not found\n", credid);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
320 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
321
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
322 return 0;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
323 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
324
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
325
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
326 int get_location_credentials(DavCfgRepository *repo, const char *path, char **user, char **password) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
327 PwdStore *secrets = get_pwdstore();
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
328 if(!secrets) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
329 return 0;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
330 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
331
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
332 /*
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
333 * The list secrets->location contains urls or repo names as
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
334 * location strings. We need a list, that contains only urls
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
335 */
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
336 CxList *locations = cxLinkedListCreate(cxDefaultAllocator, (cx_compare_func)cmp_url_cred_entry, CX_STORE_POINTERS);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
337 cxDefineDestructor(locations, free_cred_location);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
338 CxIterator i = cxListIterator(secrets->locations);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
339 cx_foreach(PwdIndexEntry*, e, i) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
340 CxIterator entry_iter = cxListIterator(e->locations);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
341 cx_foreach(char *, loc, entry_iter) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
342 cxmutstr rpath;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
343 DavCfgRepository *r = dav_config_url2repo_s(davconfig, cx_str(loc), &rpath);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
344 CredLocation *urlentry = calloc(1, sizeof(CredLocation));
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
345 urlentry->id = e->id;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
346 urlentry->location = util_concat_path_s(cx_strcast(r->url.value), cx_strcast(rpath)).ptr;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
347 cxListAdd(locations, urlentry);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
348 free(rpath.ptr);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
349 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
350 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
351 // the list must be sorted
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
352 cxListSort(locations);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
353
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
354 // create full request url string and remove protocol prefix
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
355 cxmutstr req_url_proto = util_concat_path_s(cx_strcast(repo->url.value), cx_str(path));
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
356 cxstring req_url = cx_strcast(req_url_proto);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
357 if(cx_strprefix(req_url, CX_STR("http://"))) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
358 req_url = cx_strsubs(req_url, 7);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
359 } else if(cx_strprefix(req_url, CX_STR("https://"))) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
360 req_url = cx_strsubs(req_url, 8);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
361 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
362
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
363 // iterate over sorted locations and check if a location is a prefix
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
364 // of the requested url
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
365 char *id = NULL;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
366 int ret = 0;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
367 i = cxListIterator(locations);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
368 cx_foreach(CredLocation*, cred, i) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
369 cxstring cred_url = cx_str(cred->location);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
370
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
371 // remove protocol prefix
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
372 if(cx_strprefix(cred_url, CX_STR("http://"))) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
373 cred_url = cx_strsubs(cred_url, 7);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
374 } else if(cx_strprefix(cred_url, CX_STR("https://"))) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
375 cred_url = cx_strsubs(cred_url, 8);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
376 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
377
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
378 if(cx_strprefix(req_url, cred_url)) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
379 id = cred->id;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
380 break;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
381 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
382 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
383
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
384 // if an id is found and we can access the decrypted secret store
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
385 // we can set the user/password
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
386 if(id && (secrets->isdecrypted || !pwdstore_decrypt_secrets(secrets))) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
387 PwdEntry *cred = pwdstore_get(secrets, id);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
388 if(cred) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
389 *user = cred->user;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
390 *password = cred->password;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
391 ret = 1;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
392 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
393 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
394
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
395 free(req_url_proto.ptr);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
396 cxListDestroy(locations);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
397
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
398 return ret;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
399 }

mercurial