application/config.c

Mon, 11 Nov 2024 20:45:34 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 11 Nov 2024 20:45:34 +0100
changeset 77
5de33c2d94c6
parent 76
641dcc79e0ef
permissions
-rw-r--r--

fix text/image preview loading

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 "system.h"
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
40
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
41 #include <libidav/utils.h>
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
42 #include <libidav/config.h>
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
43
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
44 #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
45 #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
46
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
47 #define print_error(lineno, ...) \
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
48 do {\
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
49 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
50 fprintf(stderr, __VA_ARGS__); \
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
51 fprintf(stderr, "Abort.\n"); \
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
52 } while(0);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
53 #define print_warning(lineno, ...) \
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
54 do {\
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
55 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
56 fprintf(stderr, __VA_ARGS__); \
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
57 } while(0);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
58
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
59 #ifdef _WIN32
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
60 #define ENV_HOME getenv("USERPROFILE")
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
61 #else
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
62 #define ENV_HOME getenv("HOME")
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
63 #endif /* _WIN32 */
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
64
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
65 static CxMap *repos;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
66 static CxMap *keys;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
67
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
68 static DavConfig *davconfig;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
69 static PwdStore *pstore;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
70
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
71 static char *secretstore_unlock_cmd;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
72 static char *secretstore_lock_cmd;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
73
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
74 int check_config_dir(void) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
75 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
76 int ret = 0;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
77 if(util_mkdir(file, S_IRWXU)) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
78 if(errno != EEXIST) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
79 ret = 1;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
80 }
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 free(file);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
83 return ret;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
84 }
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 static DavContext *context;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
87
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
88 void create_default_config(char *file) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
89 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
90 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
91 xmlDocSetRootElement(doc, root);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
92 xmlSaveFormatFileEnc(file, doc, "UTF-8", 1);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
93 xmlFreeDoc(doc);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
94 }
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 char* config_file_path(char *name) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
97 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
98 if(!davd) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
99 return NULL;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
100 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
101 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
102 free(davd);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
103 return path;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
104 }
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 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
107 FILE *file = sys_fopen(path, "r");
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
108 if(!file) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
109 return (cxmutstr){NULL,0};
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
110 }
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 CxBuffer buf;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
113 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
114 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
115 fclose(file);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
116
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
117 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
118 }
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 int load_config(DavContext *ctx) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
121 context = ctx;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
122 // TODO: free the config somewhere
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
123 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
124 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
125
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
126 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
127 pstore = pwdstore_open(pwfile);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
128 free(pwfile);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
129
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
130 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
131
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
132 struct stat s;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
133 if(stat(file, &s)) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
134 switch(errno) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
135 case ENOENT: {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
136 davconfig = dav_config_new(NULL);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
137 return 0;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
138 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
139 default: {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
140 perror("Cannot load config.xml");
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
141 }
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 return 1;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
144 }
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 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
147 int config_error;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
148 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
149 free(config_content.ptr);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
150 free(file);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
151
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
152 if(!davconfig) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
153 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
154 return 1;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
155 }
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 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
158 return 1;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
159 }
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 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
162 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
163
60
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
164 DavConfig* load_config_file(void) {
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
165 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
166
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
167 struct stat s;
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
168 if(stat(file, &s)) {
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
169 switch(errno) {
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
170 case ENOENT: {
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
171 davconfig = dav_config_new(NULL);
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
172 return NULL;
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
173 }
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
174 default: {
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
175 perror("Cannot load config.xml");
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
176 }
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 return NULL;
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
179 }
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 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
182 int config_error;
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
183 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
184 free(config_content.ptr);
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
185 free(file);
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
186 return cfg;
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
187 }
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 void set_config(DavConfig *cfg) {
72
d5307e9ee384 implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 65
diff changeset
191 if(davconfig) {
d5307e9ee384 implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 65
diff changeset
192 dav_config_free(davconfig);
d5307e9ee384 implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 65
diff changeset
193 }
60
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
194 davconfig = cfg;
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
195 }
ee4e4742391e add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
196
55
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
197 DavConfig* get_config(void) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
198 return davconfig;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
199 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
200
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
201 int store_config(void) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
202 if(check_config_dir()) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
203 return 1;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
204 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
205
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
206 CxBuffer *buf = dav_config2buf(davconfig);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
207 if(!buf) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
208 return 1;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
209 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
210
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
211 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
212 FILE *cout = sys_fopen(file, "w");
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
213 if(!cout) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
214 cxBufferFree(buf);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
215 return 1;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
216 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
217
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
218 // should only fail if we run out of disk space or something like that
72
d5307e9ee384 implement key management UI
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 65
diff changeset
219 // in that case, the config file is destroyed
55
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
220 // 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
221 // rename it
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
222 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
223
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
224 cxBufferFree(buf);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
225 fclose(cout);
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 return 0;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
228 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
229
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
230 void free_config(void) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
231 if(davconfig) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
232 dav_config_free(davconfig);
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 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
235
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
236 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
237 cxmutstr k;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
238 k.ptr = NULL;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
239 k.length = 0;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
240
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
241 FILE *file = NULL;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
242 if(filename[0] == '/') {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
243 file = sys_fopen(filename, "r");
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
244 } else {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
245 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
246 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
247 file = sys_fopen(p2, "r");
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
248 free(path);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
249 free(p2);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
250 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
251
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
252 if(!file) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
253 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
254 return k;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
255 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
256
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
257 char *data = malloc(256);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
258 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
259 k.ptr = data;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
260 k.length = r;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
261
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
262 fclose(file);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
263 return k;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
264 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
265
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
266 PwdStore* get_pwdstore(void) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
267 return pstore;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
268 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
269
65
48f43130b4a2 implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
270 void set_pwdstore(PwdStore *newstore) {
48f43130b4a2 implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
271 if(pstore) {
48f43130b4a2 implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
272 // TODO: free
48f43130b4a2 implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
273 }
48f43130b4a2 implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
274 pstore = newstore;
48f43130b4a2 implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
275 }
48f43130b4a2 implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
276
55
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
277 int pwdstore_save(PwdStore *pwdstore) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
278 if(check_config_dir()) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
279 return 1;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
280 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
281
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
282 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
283 int ret = pwdstore_store(pwdstore, pwfile);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
284 free(pwfile);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
285 return ret;
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 typedef struct CredLocation {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
289 char *id;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
290 char *location;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
291 } CredLocation;
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 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
294 return strcmp(e2->location, e1->location);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
295 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
296
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
297 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
298 // 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
299 free(c->location);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
300 free(c);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
301 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
302
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
303 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
304 if(!credid) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
305 return 0;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
306 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
307
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
308 PwdStore *secrets = get_pwdstore();
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
309 if(!secrets) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
310 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
311 return 0;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
312 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
313
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
314 if(pwdstore_has_id(secrets, credid)) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
315 if(!secrets->isdecrypted) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
316 if(pwdstore_decrypt_secrets(secrets)) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
317 return 0;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
318 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
319 }
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 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
322 if(s_cred) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
323 *user = s_cred->user;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
324 *password = s_cred->password;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
325 return 1;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
326 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
327 } else {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
328 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
329 }
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 return 0;
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
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
334
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
335 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
336 PwdStore *secrets = get_pwdstore();
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
337 if(!secrets) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
338 return 0;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
339 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
340
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
341 /*
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
342 * 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
343 * 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
344 */
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
345 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
346 cxDefineDestructor(locations, free_cred_location);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
347 CxIterator i = cxListIterator(secrets->locations);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
348 cx_foreach(PwdIndexEntry*, e, i) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
349 CxIterator entry_iter = cxListIterator(e->locations);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
350 cx_foreach(char *, loc, entry_iter) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
351 cxmutstr rpath;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
352 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
353 CredLocation *urlentry = calloc(1, sizeof(CredLocation));
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
354 urlentry->id = e->id;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
355 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
356 cxListAdd(locations, urlentry);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
357 free(rpath.ptr);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
358 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
359 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
360 // the list must be sorted
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
361 cxListSort(locations);
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 // 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
364 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
365 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
366 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
367 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
368 } 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
369 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
370 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
371
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
372 // 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
373 // of the requested url
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
374 char *id = NULL;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
375 int ret = 0;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
376 i = cxListIterator(locations);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
377 cx_foreach(CredLocation*, cred, i) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
378 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
379
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
380 // remove protocol prefix
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
381 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
382 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
383 } 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
384 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
385 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
386
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
387 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
388 id = cred->id;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
389 break;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
390 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
391 }
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 // 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
394 // we can set the user/password
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
395 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
396 PwdEntry *cred = pwdstore_get(secrets, id);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
397 if(cred) {
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
398 *user = cred->user;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
399 *password = cred->password;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
400 ret = 1;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
401 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
402 }
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
403
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
404 free(req_url_proto.ptr);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
405 cxListDestroy(locations);
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
406
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
407 return ret;
1ce14068ef31 update libidav, unify config.c with cmdutils
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
408 }

mercurial