Fri, 04 Jul 2014 12:09:48 +0200
dav-sync deletes removed files
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
5
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 | * |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
4 | * Copyright 2013 Olaf Wintermann. All rights reserved. |
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. |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
5
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. |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
29 | #include <stdlib.h> |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | #include <string.h> |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
31 | #include <stdarg.h> |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
32 | |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
33 | #include "string.h" |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
34 | #include "allocator.h" |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
36 | sstr_t sstr(char *cstring) { |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | sstr_t string; |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
38 | string.ptr = cstring; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
39 | string.length = strlen(cstring); |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | return string; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
43 | sstr_t sstrn(char *cstring, size_t length) { |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | sstr_t string; |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
45 | string.ptr = cstring; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
46 | string.length = length; |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | return string; |
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 | |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | size_t sstrnlen(size_t n, sstr_t s, ...) { |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | va_list ap; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
52 | size_t size = s.length; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | va_start(ap, s); |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
55 | for (size_t i = 1 ; i < n ; i++) { |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | sstr_t str = va_arg(ap, sstr_t); |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | size += str.length; |
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 | va_end(ap); |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | return size; |
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 | |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
64 | sstr_t sstrncat(sstr_t s, size_t n, sstr_t c1, ...) { |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | va_list ap; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | va_start(ap, c1); |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | s.ptr[0] = 0; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69 | size_t len = s.length; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | size_t cplen = c1.length > len ? len : c1.length; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71 | char *ptr = s.ptr; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
72 | |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
73 | memcpy(ptr, c1.ptr, cplen); |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74 | len -= cplen; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
75 | ptr += cplen; |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
76 | for (size_t i = 1 ; i < n ; i++) { |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
77 | sstr_t str = va_arg (ap, sstr_t); |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
78 | cplen = str.length > len ? len : str.length; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
79 | if(cplen <= 0) { |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
80 | va_end(ap); |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
81 | return s; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
82 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
83 | memcpy(ptr, str.ptr, cplen); |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
84 | len -= cplen; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
85 | ptr += cplen; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
86 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
87 | va_end(ap); |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
88 | s.length = ptr - s.ptr; |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
89 | |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
90 | return s; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
91 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
92 | |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
93 | sstr_t sstrsubs(sstr_t s, size_t start) { |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
94 | return sstrsubsl (s, start, s.length-start); |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
95 | } |
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 | sstr_t sstrsubsl(sstr_t s, size_t start, size_t length) { |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
98 | sstr_t new_sstr; |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
99 | if (start >= s.length) { |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
100 | //return s; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
101 | new_sstr.ptr = NULL; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
102 | new_sstr.length = 0; |
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
103 | return new_sstr; |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
104 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
105 | if (length > s.length-start) { |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
106 | length = s.length-start; |
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 | new_sstr.ptr = &s.ptr[start]; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
109 | new_sstr.length = length; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
110 | return new_sstr; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
111 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
112 | |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
113 | sstr_t sstrchr(sstr_t s, int c) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
114 | for(size_t i=0;i<s.length;i++) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
115 | if(s.ptr[i] == c) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
116 | return sstrsubs(s, i); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
117 | } |
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 | sstr_t n; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
120 | n.ptr = NULL; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
121 | n.length = 0; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
122 | return n; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
123 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
124 | |
39
3e55bed345f9
added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
125 | sstr_t sstrrchr(sstr_t s, int c) { |
3e55bed345f9
added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
126 | if (s.length > 0) { |
3e55bed345f9
added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
127 | for(size_t i=s.length;i>0;i--) { |
3e55bed345f9
added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
128 | if(s.ptr[i-1] == c) { |
3e55bed345f9
added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
129 | return sstrsubs(s, i-1); |
3e55bed345f9
added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
130 | } |
3e55bed345f9
added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
131 | } |
3e55bed345f9
added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
132 | } |
3e55bed345f9
added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
133 | sstr_t n; |
3e55bed345f9
added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
134 | n.ptr = NULL; |
3e55bed345f9
added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
135 | n.length = 0; |
3e55bed345f9
added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
136 | return n; |
3e55bed345f9
added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
137 | } |
3e55bed345f9
added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
138 | |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
139 | sstr_t* sstrsplit(sstr_t s, sstr_t d, size_t *n) { |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
140 | return sstrsplit_a(ucx_default_allocator(), s, d, n); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
141 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
142 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
143 | sstr_t* sstrsplit_a(UcxAllocator *allocator, sstr_t s, sstr_t d, size_t *n) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
144 | if (s.length == 0 || d.length == 0) { |
43
03076907b58a
added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
39
diff
changeset
|
145 | *n = 0; |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
146 | return NULL; |
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 | |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
149 | sstr_t* result; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
150 | size_t nmax = *n; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
151 | *n = 1; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
152 | |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
153 | /* special case: exact match - no processing needed */ |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
154 | if (sstrcmp(s, d) == 0) { |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
155 | *n = 0; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
156 | return NULL; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
157 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
158 | sstr_t sv = sstrdup(s); |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
159 | if (sv.length == 0) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
160 | *n = -2; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
161 | return NULL; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
162 | } |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
163 | |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
164 | for (size_t i = 0 ; i < s.length ; i++) { |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
165 | if (sv.ptr[i] == d.ptr[0]) { |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
166 | _Bool match = 1; |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
167 | for (size_t j = 1 ; j < d.length ; j++) { |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
168 | if (j+i < s.length) { |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
169 | match &= (sv.ptr[i+j] == d.ptr[j]); |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
170 | } else { |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
171 | match = 0; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
172 | break; |
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 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
175 | if (match) { |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
176 | (*n)++; |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
177 | for (size_t j = 0 ; j < d.length ; j++) { |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
178 | sv.ptr[i+j] = 0; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
179 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
180 | i += d.length; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
181 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
182 | } |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
183 | if ((*n) == nmax) break; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
184 | } |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
185 | result = (sstr_t*) allocator->malloc(allocator->pool, sizeof(sstr_t)*(*n)); |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
186 | |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
187 | if (result) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
188 | char *pptr = sv.ptr; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
189 | for (size_t i = 0 ; i < *n ; i++) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
190 | size_t l = strlen(pptr); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
191 | char* ptr = (char*) allocator->malloc(allocator->pool, l + 1); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
192 | memcpy(ptr, pptr, l); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
193 | ptr[l] = 0; |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
194 | |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
195 | result[i] = sstrn(ptr, l); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
196 | pptr += l + d.length; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
197 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
198 | } else { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
199 | *n = -2; |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
200 | } |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
201 | |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
202 | free(sv.ptr); |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
203 | |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
204 | return result; |
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 | |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
207 | int sstrcmp(sstr_t s1, sstr_t s2) { |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
208 | if (s1.length == s2.length) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
209 | return memcmp(s1.ptr, s2.ptr, s1.length); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
210 | } else if (s1.length > s2.length) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
211 | return 1; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
212 | } else { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
213 | return -1; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
214 | } |
1
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 | |
39
3e55bed345f9
added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
217 | int sstrcasecmp(sstr_t s1, sstr_t s2) { |
3e55bed345f9
added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
218 | if (s1.length == s2.length) { |
3e55bed345f9
added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
219 | #ifdef _WIN32 |
3e55bed345f9
added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
220 | return _strnicmp(s1.ptr, s2.ptr, s1.length); |
3e55bed345f9
added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
221 | #else |
3e55bed345f9
added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
222 | return strncasecmp(s1.ptr, s2.ptr, s1.length); |
3e55bed345f9
added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
223 | #endif |
3e55bed345f9
added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
224 | } else if (s1.length > s2.length) { |
3e55bed345f9
added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
225 | return 1; |
3e55bed345f9
added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
226 | } else { |
3e55bed345f9
added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
227 | return -1; |
3e55bed345f9
added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
228 | } |
3e55bed345f9
added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
229 | } |
3e55bed345f9
added some aes functions + ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
17
diff
changeset
|
230 | |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
231 | sstr_t sstrdup(sstr_t s) { |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
232 | return sstrdup_a(ucx_default_allocator(), s); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
233 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
234 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
235 | sstr_t sstrdup_a(UcxAllocator *allocator, sstr_t s) { |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
236 | sstr_t newstring; |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
237 | newstring.ptr = (char*)allocator->malloc(allocator->pool, s.length + 1); |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
238 | if (newstring.ptr) { |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
239 | newstring.length = s.length; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
240 | newstring.ptr[newstring.length] = 0; |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
241 | |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
242 | memcpy(newstring.ptr, s.ptr, s.length); |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
243 | } else { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
244 | newstring.length = 0; |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
245 | } |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
246 | |
1
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
247 | return newstring; |
1bcaac272cdf
added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
248 | } |
5
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
249 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
250 | sstr_t sstrtrim(sstr_t string) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
251 | sstr_t newstr = string; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
252 | if (string.length == 0) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
253 | return newstr; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
254 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
255 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
256 | size_t i; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
257 | for(i=0;i<string.length;i++) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
258 | char c = string.ptr[i]; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
259 | if(c > 32) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
260 | break; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
261 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
262 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
263 | newstr.ptr = &string.ptr[i]; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
264 | newstr.length = string.length - i; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
265 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
266 | if(newstr.length == 0) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
267 | return newstr; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
268 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
269 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
270 | i = newstr.length - 1; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
271 | for(;;) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
272 | char c = newstr.ptr[i]; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
273 | if(c > 32) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
274 | break; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
275 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
276 | if(i > 0) { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
277 | i--; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
278 | } else { |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
279 | break; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
280 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
281 | } |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
282 | newstr.length = i + 1; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
283 | |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
284 | return newstr; |
88625853ae74
new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
285 | } |
17
11dffb40cd91
new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
286 | |
11dffb40cd91
new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
287 | int sstrprefix(sstr_t string, sstr_t prefix) { |
11dffb40cd91
new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
288 | if (string.length == 0) { |
11dffb40cd91
new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
289 | return prefix.length == 0; |
11dffb40cd91
new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
290 | } |
11dffb40cd91
new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
291 | if (prefix.length == 0) { |
11dffb40cd91
new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
292 | return 1; |
11dffb40cd91
new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
293 | } |
11dffb40cd91
new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
294 | |
11dffb40cd91
new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
295 | if (prefix.length > string.length) { |
11dffb40cd91
new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
296 | return 0; |
11dffb40cd91
new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
297 | } else { |
11dffb40cd91
new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
298 | return memcmp(string.ptr, prefix.ptr, prefix.length) == 0; |
11dffb40cd91
new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
299 | } |
11dffb40cd91
new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
300 | } |
11dffb40cd91
new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
301 | |
11dffb40cd91
new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
302 | int sstrsuffix(sstr_t string, sstr_t suffix) { |
11dffb40cd91
new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
303 | if (string.length == 0) { |
11dffb40cd91
new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
304 | return suffix.length == 0; |
11dffb40cd91
new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
305 | } |
11dffb40cd91
new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
306 | if (suffix.length == 0) { |
11dffb40cd91
new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
307 | return 1; |
11dffb40cd91
new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
308 | } |
11dffb40cd91
new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
309 | |
11dffb40cd91
new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
310 | if (suffix.length > string.length) { |
11dffb40cd91
new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
311 | return 0; |
11dffb40cd91
new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
312 | } else { |
11dffb40cd91
new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
313 | return memcmp(string.ptr+string.length-suffix.length, |
11dffb40cd91
new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
314 | suffix.ptr, suffix.length) == 0; |
11dffb40cd91
new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
315 | } |
11dffb40cd91
new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
316 | } |