src/server/ucx/dlist.c

Tue, 25 Jun 2013 15:45:13 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 25 Jun 2013 15:45:13 +0200
changeset 77
f1cff81e425a
parent 71
069c152f6272
permissions
-rw-r--r--

some fixes

71
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
1 /*
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
3 *
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
4 * Copyright 2013 Olaf Wintermann. All rights reserved.
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
5 *
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
6 * Redistribution and use in source and binary forms, with or without
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
7 * modification, are permitted provided that the following conditions are met:
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
8 *
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
10 * notice, this list of conditions and the following disclaimer.
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
11 *
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
14 * documentation and/or other materials provided with the distribution.
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
15 *
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
27 */
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
28
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include "dlist.h"
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30
15
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
31 UcxDlist *ucx_dlist_clone(UcxDlist *l, copy_func fnc, void *data) {
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
32 UcxDlist *ret = NULL;
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
33 while (l != NULL) {
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
34 if (fnc != NULL) {
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
35 ret = ucx_dlist_append(ret, fnc(l->data, data));
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
36 } else {
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
37 ret = ucx_dlist_append(ret, l->data);
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
38 }
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
39 l = l->next;
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
40 }
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
41 return ret;
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
42 }
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
43
71
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
44 int ucx_dlist_equals(const UcxDlist *l1, const UcxDlist *l2,
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
45 cmp_func fnc, void* data) {
15
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
46 if (l1 == l2) return 1;
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
47
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
48 while (l1 != NULL && l2 != NULL) {
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
49 if (fnc == NULL) {
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
50 if (l1->data != l2->data) return 0;
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
51 } else {
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
52 if (fnc(l1->data, l2->data, data) != 0) return 0;
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
53 }
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
54 l1 = l1->next;
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
55 l2 = l2->next;
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
56 }
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
57
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
58 return (l1 == NULL && l2 == NULL);
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
59 }
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
60
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 void ucx_dlist_free(UcxDlist *l) {
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 UcxDlist *e = l, *f;
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 while (e != NULL) {
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 f = e;
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 e = e->next;
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 free(f);
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 }
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 }
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 UcxDlist *ucx_dlist_append(UcxDlist *l, void *data) {
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 UcxDlist *nl = (UcxDlist*) malloc(sizeof(UcxDlist));
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 if (nl == NULL) return NULL;
15
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
73
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 nl->data = data;
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 nl->next = NULL;
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 if (l == NULL) {
30
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
77 nl->prev = NULL;
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 return nl;
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 } else {
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 UcxDlist *t = ucx_dlist_last(l);
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 t->next = nl;
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 nl->prev = t;
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 return l;
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 }
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85 }
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 UcxDlist *ucx_dlist_prepend(UcxDlist *l, void *data) {
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 UcxDlist *nl = ucx_dlist_append(NULL, data);
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89 if (nl == NULL) return NULL;
15
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
90
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91 if (l != NULL) {
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 nl->next = l;
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93 l->prev = nl;
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 }
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 return nl;
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96 }
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98 UcxDlist *ucx_dlist_concat(UcxDlist *l1, UcxDlist *l2) {
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99 if (l1 == NULL) {
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 return l2;
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101 } else {
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 UcxDlist *last = ucx_dlist_last(l1);
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 last->next = l2;
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 l2->prev = last;
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 return l1;
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106 }
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107 }
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108
71
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
109 UcxDlist *ucx_dlist_last(const UcxDlist *l) {
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 if (l == NULL) return NULL;
15
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
111
71
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
112 const UcxDlist *e = l;
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113 while (e->next != NULL) {
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114 e = e->next;
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115 }
71
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
116 return (UcxDlist*)e;
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 }
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118
71
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
119 UcxDlist *ucx_dlist_get(const UcxDlist *l, int index) {
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120 if (l == NULL) return NULL;
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121
71
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
122 const UcxDlist *e = l;
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123 while (e->next != NULL && index > 0) {
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124 e = e->next;
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125 index--;
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 }
15
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
127
71
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
128 return (UcxDlist*)(index == 0 ? e : NULL);
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 }
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130
71
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
131 int ucx_dlist_contains(UcxDlist *l, void *elem, cmp_func fnc, void *cmpdata) {
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
132 UCX_FOREACH(UcxDlist*, l, e) {
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
133 if (!fnc(elem, e->data, cmpdata)) {
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
134 return 1;
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
135 }
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
136 }
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
137 return 0;
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
138 }
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
139
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
140 size_t ucx_dlist_size(const UcxDlist *l) {
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141 if (l == NULL) return 0;
15
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
142
71
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
143 const UcxDlist *e = l;
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
144 size_t s = 1;
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145 while (e->next != NULL) {
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146 e = e->next;
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
147 s++;
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
148 }
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
149
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
150 return s;
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
151 }
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
152
36
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
153 UcxDlist *ucx_dlist_sort_merge(int length,
71
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
154 UcxDlist* restrict ls, UcxDlist* restrict le, UcxDlist* restrict re,
36
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
155 cmp_func fnc, void* data) {
71
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
156
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
157 UcxDlist** sorted = (UcxDlist**) malloc(sizeof(UcxDlist*)*length);
36
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
158 UcxDlist *rc, *lc;
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
159
71
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
160 lc = ls; rc = le;
36
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
161 int n = 0;
71
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
162 while (lc && lc != le && rc != re) {
36
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
163 if (fnc(lc->data, rc->data, data) <= 0) {
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
164 sorted[n] = lc;
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
165 lc = lc->next;
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
166 } else {
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
167 sorted[n] = rc;
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
168 rc = rc->next;
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
169 }
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
170 n++;
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
171 }
71
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
172 while (lc && lc != le) {
36
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
173 sorted[n] = lc;
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
174 lc = lc->next;
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
175 n++;
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
176 }
71
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
177 while (rc && rc != re) {
36
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
178 sorted[n] = rc;
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
179 rc = rc->next;
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
180 n++;
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
181 }
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
182
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
183 // Update pointer
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
184 sorted[0]->prev = NULL;
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
185 for (int i = 0 ; i < length-1 ; i++) {
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
186 sorted[i]->next = sorted[i+1];
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
187 sorted[i+1]->prev = sorted[i];
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
188 }
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
189 sorted[length-1]->next = NULL;
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
190
71
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
191 UcxDlist *ret = sorted[0];
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
192 free(sorted);
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
193 return ret;
36
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
194 }
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
195
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
196 UcxDlist *ucx_dlist_sort(UcxDlist *l, cmp_func fnc, void *data) {
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
197 if (l == NULL) {
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
198 return NULL;
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
199 }
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
200
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
201 UcxDlist *lc;
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
202 int ln = 1;
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
203
71
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
204 UcxDlist *restrict ls = l, *restrict le, *restrict re;
36
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
205 lc = ls;
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
206 while (lc->next != NULL && fnc(lc->next->data, lc->data, data) > 0) {
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
207 lc = lc->next;
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
208 ln++;
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
209 }
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
210 le = lc->next;
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
211
71
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
212 if (le == NULL) {
36
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
213 return l; // this list is already sorted :)
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
214 } else {
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
215 UcxDlist *rc;
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
216 int rn = 1;
71
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
217 rc = le;
36
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
218 while (rc->next != NULL && fnc(rc->next->data, rc->data, data) > 0) {
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
219 rc = rc->next;
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
220 rn++;
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
221 }
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
222 re = rc->next;
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
223
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
224 // Something left? Sort it!
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
225 UcxDlist *remainder = re;
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
226 size_t remainder_length = ucx_dlist_size(remainder);
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
227 if (remainder != NULL) {
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
228 remainder = ucx_dlist_sort(remainder, fnc, data);
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
229 }
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
230
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
231 // {ls,...,le->prev} and {rs,...,re->prev} are sorted - merge them
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
232 UcxDlist *sorted = ucx_dlist_sort_merge(ln+rn,
71
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
233 ls, le, re,
36
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
234 fnc, data);
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
235
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
236 // merge sorted list with (also sorted) remainder
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
237 l = ucx_dlist_sort_merge(ln+rn+remainder_length,
71
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
238 sorted, remainder, NULL, fnc, data);
36
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
239
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
240 return l;
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
241 }
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
242 }
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
243
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
244 /* dlist specific functions */
71
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
245 UcxDlist *ucx_dlist_first(const UcxDlist *l) {
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
246 if (l == NULL) return NULL;
15
cff9c4101dd7 Replaced old utils with ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 14
diff changeset
247
71
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
248 const UcxDlist *e = l;
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
249 while (e->prev != NULL) {
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
250 e = e->prev;
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
251 }
71
069c152f6272 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
252 return (UcxDlist *)e;
13
1fdbf4170ef4 Added webdav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
253 }
30
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
254
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
255 UcxDlist *ucx_dlist_remove(UcxDlist *l, UcxDlist *e) {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
256 if (e->prev == NULL) {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
257 if(e->next != NULL) {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
258 e->next->prev = NULL;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
259 l = e->next;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
260 } else {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
261 l = NULL;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
262 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
263
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
264 } else {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
265 e->prev->next = e->next;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
266 e->next->prev = e->prev;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
267 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
268 free(e);
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
269 return l;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
270 }

mercurial