Sat, 12 Oct 2019 18:41:10 +0200
add test for testing transition from config without hashing to config with enabled hashing
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
1 | /* |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
3 | * |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
4 | * Copyright 2017 Mike Becker, Olaf Wintermann All rights reserved. |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
5 | * |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
8 | * |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
11 | * |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
15 | * |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
27 | */ |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
28 | |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
29 | #include "ucx/list.h" |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
31 | UcxList *ucx_list_clone(UcxList *l, copy_func fnc, void *data) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
32 | return ucx_list_clone_a(ucx_default_allocator(), l, fnc, data); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
33 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
34 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
35 | UcxList *ucx_list_clone_a(UcxAllocator *alloc, UcxList *l, |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | copy_func fnc, void *data) { |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | UcxList *ret = NULL; |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
38 | while (l) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
39 | if (fnc) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
40 | ret = ucx_list_append_a(alloc, ret, fnc(l->data, data)); |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | } else { |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
42 | ret = ucx_list_append_a(alloc, ret, l->data); |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | l = l->next; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | return ret; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | int ucx_list_equals(const UcxList *l1, const UcxList *l2, |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | cmp_func fnc, void* data) { |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | if (l1 == l2) return 1; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
52 | |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | while (l1 != NULL && l2 != NULL) { |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | if (fnc == NULL) { |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | if (l1->data != l2->data) return 0; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | } else { |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | if (fnc(l1->data, l2->data, data) != 0) return 0; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | l1 = l1->next; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | l2 = l2->next; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | return (l1 == NULL && l2 == NULL); |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | void ucx_list_free(UcxList *l) { |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
67 | ucx_list_free_a(ucx_default_allocator(), l); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
68 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
69 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
70 | void ucx_list_free_a(UcxAllocator *alloc, UcxList *l) { |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71 | UcxList *e = l, *f; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
72 | while (e != NULL) { |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
73 | f = e; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74 | e = e->next; |
70 | 75 | alfree(alloc, f); |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
76 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
77 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
78 | |
255
bf19378aed58
updates UCX to version 0.11
Mike Becker <universe@uap-core.de>
parents:
110
diff
changeset
|
79 | void ucx_list_free_content(UcxList* list, ucx_destructor destr) { |
505 | 80 | if (!destr) destr = free; |
255
bf19378aed58
updates UCX to version 0.11
Mike Becker <universe@uap-core.de>
parents:
110
diff
changeset
|
81 | while (list != NULL) { |
bf19378aed58
updates UCX to version 0.11
Mike Becker <universe@uap-core.de>
parents:
110
diff
changeset
|
82 | destr(list->data); |
bf19378aed58
updates UCX to version 0.11
Mike Becker <universe@uap-core.de>
parents:
110
diff
changeset
|
83 | list = list->next; |
bf19378aed58
updates UCX to version 0.11
Mike Becker <universe@uap-core.de>
parents:
110
diff
changeset
|
84 | } |
bf19378aed58
updates UCX to version 0.11
Mike Becker <universe@uap-core.de>
parents:
110
diff
changeset
|
85 | } |
bf19378aed58
updates UCX to version 0.11
Mike Becker <universe@uap-core.de>
parents:
110
diff
changeset
|
86 | |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
87 | UcxList *ucx_list_append(UcxList *l, void *data) { |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
88 | return ucx_list_append_a(ucx_default_allocator(), l, data); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
89 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
90 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
91 | UcxList *ucx_list_append_a(UcxAllocator *alloc, UcxList *l, void *data) { |
70 | 92 | UcxList *nl = (UcxList*) almalloc(alloc, sizeof(UcxList)); |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
93 | if (!nl) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
94 | return NULL; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
95 | } |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
96 | |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
97 | nl->data = data; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
98 | nl->next = NULL; |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
99 | if (l) { |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
100 | UcxList *t = ucx_list_last(l); |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
101 | t->next = nl; |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
102 | nl->prev = t; |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
103 | return l; |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
104 | } else { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
105 | nl->prev = NULL; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
106 | return nl; |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
107 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
108 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
109 | |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
110 | UcxList *ucx_list_prepend(UcxList *l, void *data) { |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
111 | return ucx_list_prepend_a(ucx_default_allocator(), l, data); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
112 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
113 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
114 | UcxList *ucx_list_prepend_a(UcxAllocator *alloc, UcxList *l, void *data) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
115 | UcxList *nl = ucx_list_append_a(alloc, NULL, data); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
116 | if (!nl) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
117 | return NULL; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
118 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
119 | l = ucx_list_first(l); |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
120 | |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
121 | if (l) { |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
122 | nl->next = l; |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
123 | l->prev = nl; |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
124 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
125 | return nl; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
126 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
127 | |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
128 | UcxList *ucx_list_concat(UcxList *l1, UcxList *l2) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
129 | if (l1) { |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
130 | UcxList *last = ucx_list_last(l1); |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
131 | last->next = l2; |
70 | 132 | if (l2) { |
133 | l2->prev = last; | |
134 | } | |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
135 | return l1; |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
136 | } else { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
137 | return l2; |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
138 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
139 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
140 | |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
141 | UcxList *ucx_list_last(const UcxList *l) { |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
142 | if (l == NULL) return NULL; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
143 | |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
144 | const UcxList *e = l; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
145 | while (e->next != NULL) { |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
146 | e = e->next; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
147 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
148 | return (UcxList*)e; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
149 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
150 | |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
151 | ssize_t ucx_list_indexof(const UcxList *list, const UcxList *elem) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
152 | ssize_t index = 0; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
153 | while (list) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
154 | if (list == elem) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
155 | return index; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
156 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
157 | list = list->next; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
158 | index++; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
159 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
160 | return -1; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
161 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
162 | |
70 | 163 | UcxList *ucx_list_get(const UcxList *l, size_t index) { |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
164 | if (l == NULL) return NULL; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
165 | |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
166 | const UcxList *e = l; |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
167 | while (e->next && index > 0) { |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
168 | e = e->next; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
169 | index--; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
170 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
171 | |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
172 | return (UcxList*)(index == 0 ? e : NULL); |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
173 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
174 | |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
175 | ssize_t ucx_list_find(UcxList *l, void *elem, cmp_func fnc, void *cmpdata) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
176 | ssize_t index = 0; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
177 | UCX_FOREACH(e, l) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
178 | if (fnc) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
179 | if (fnc(elem, e->data, cmpdata) == 0) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
180 | return index; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
181 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
182 | } else { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
183 | if (elem == e->data) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
184 | return index; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
185 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
186 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
187 | index++; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
188 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
189 | return -1; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
190 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
191 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
192 | int ucx_list_contains(UcxList *l, void *elem, cmp_func fnc, void *cmpdata) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
193 | return ucx_list_find(l, elem, fnc, cmpdata) > -1; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
194 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
195 | |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
196 | size_t ucx_list_size(const UcxList *l) { |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
197 | if (l == NULL) return 0; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
198 | |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
199 | const UcxList *e = l; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
200 | size_t s = 1; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
201 | while (e->next != NULL) { |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
202 | e = e->next; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
203 | s++; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
204 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
205 | |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
206 | return s; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
207 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
208 | |
70 | 209 | static UcxList *ucx_list_sort_merge(int length, |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
210 | UcxList* ls, UcxList* le, UcxList* re, |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
211 | cmp_func fnc, void* data) { |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
212 | |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
213 | UcxList** sorted = (UcxList**) malloc(sizeof(UcxList*)*length); |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
214 | UcxList *rc, *lc; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
215 | |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
216 | lc = ls; rc = le; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
217 | int n = 0; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
218 | while (lc && lc != le && rc != re) { |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
219 | if (fnc(lc->data, rc->data, data) <= 0) { |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
220 | sorted[n] = lc; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
221 | lc = lc->next; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
222 | } else { |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
223 | sorted[n] = rc; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
224 | rc = rc->next; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
225 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
226 | n++; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
227 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
228 | while (lc && lc != le) { |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
229 | sorted[n] = lc; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
230 | lc = lc->next; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
231 | n++; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
232 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
233 | while (rc && rc != re) { |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
234 | sorted[n] = rc; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
235 | rc = rc->next; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
236 | n++; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
237 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
238 | |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
239 | // Update pointer |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
240 | sorted[0]->prev = NULL; |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
241 | for (int i = 0 ; i < length-1 ; i++) { |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
242 | sorted[i]->next = sorted[i+1]; |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
243 | sorted[i+1]->prev = sorted[i]; |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
244 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
245 | sorted[length-1]->next = NULL; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
246 | |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
247 | UcxList *ret = sorted[0]; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
248 | free(sorted); |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
249 | return ret; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
250 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
251 | |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
252 | UcxList *ucx_list_sort(UcxList *l, cmp_func fnc, void *data) { |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
253 | if (l == NULL) { |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
254 | return NULL; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
255 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
256 | |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
257 | UcxList *lc; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
258 | int ln = 1; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
259 | |
335
c1bc13faadaa
updates ucx to version 1.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
260 | UcxList *ls = l, *le, *re; |
70 | 261 | |
262 | // check how many elements are already sorted | |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
263 | lc = ls; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
264 | while (lc->next != NULL && fnc(lc->next->data, lc->data, data) > 0) { |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
265 | lc = lc->next; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
266 | ln++; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
267 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
268 | le = lc->next; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
269 | |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
270 | if (le == NULL) { |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
271 | return l; // this list is already sorted :) |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
272 | } else { |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
273 | UcxList *rc; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
274 | int rn = 1; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
275 | rc = le; |
70 | 276 | // skip already sorted elements |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
277 | while (rc->next != NULL && fnc(rc->next->data, rc->data, data) > 0) { |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
278 | rc = rc->next; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
279 | rn++; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
280 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
281 | re = rc->next; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
282 | |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
283 | // {ls,...,le->prev} and {rs,...,re->prev} are sorted - merge them |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
284 | UcxList *sorted = ucx_list_sort_merge(ln+rn, |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
285 | ls, le, re, |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
286 | fnc, data); |
70 | 287 | |
288 | // Something left? Sort it! | |
289 | size_t remainder_length = ucx_list_size(re); | |
290 | if (remainder_length > 0) { | |
291 | UcxList *remainder = ucx_list_sort(re, fnc, data); | |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
292 | |
70 | 293 | // merge sorted list with (also sorted) remainder |
294 | l = ucx_list_sort_merge(ln+rn+remainder_length, | |
295 | sorted, remainder, NULL, fnc, data); | |
296 | } else { | |
297 | // no remainder - we've got our sorted list | |
298 | l = sorted; | |
299 | } | |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
300 | |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
301 | return l; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
302 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
303 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
304 | |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
305 | UcxList *ucx_list_first(const UcxList *l) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
306 | if (!l) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
307 | return NULL; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
308 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
309 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
310 | const UcxList *e = l; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
311 | while (e->prev) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
312 | e = e->prev; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
313 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
314 | return (UcxList *)e; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
315 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
316 | |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
317 | UcxList *ucx_list_remove(UcxList *l, UcxList *e) { |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
318 | return ucx_list_remove_a(ucx_default_allocator(), l, e); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
319 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
320 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
321 | UcxList *ucx_list_remove_a(UcxAllocator *alloc, UcxList *l, UcxList *e) { |
70 | 322 | if (l == e) { |
323 | l = e->next; | |
324 | } | |
325 | ||
326 | if (e->next) { | |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
327 | e->next->prev = e->prev; |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
328 | } |
70 | 329 | |
330 | if (e->prev) { | |
331 | e->prev->next = e->next; | |
332 | } | |
333 | ||
334 | alfree(alloc, e); | |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
335 | return l; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
336 | } |