test/ctest.c

Thu, 11 Jul 2024 19:37:36 +0200

author
Mike Becker <universe@uap-core.de>
date
Thu, 11 Jul 2024 19:37:36 +0200
changeset 78
719e3c6d4c9b
parent 75
c72b250866ab
permissions
-rw-r--r--

release version 3.1

and fixes that every version was marked
unstable in the version output

25
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1 /*
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
3 *
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
4 * Copyright 2015 Olaf Wintermann. All rights reserved.
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
5 *
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
8 *
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
11 *
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
15 *
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
27 */
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
28
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
29 #include <time.h>
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
30 #include <stdio.h>
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
31 #include <stdlib.h>
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
32 #include <string.h>
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
33 #include <ucx/string.h>
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
34 #include <ucx/buffer.h>
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
35 #include <ucx/utils.h>
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
36 #include <libxml/tree.h>
75
c72b250866ab add basic support for line continuations in C highlighter
Mike Becker <universe@uap-core.de>
parents: 70
diff changeset
37 #include <curl\
c72b250866ab add basic support for line continuations in C highlighter
Mike Becker <universe@uap-core.de>
parents: 70
diff changeset
38 /curl.h>
25
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
39
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
40 #include <openssl/sha.h>
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
41 #include <openssl/hmac.h>
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
42 #include <openssl/evp.h>
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
43 #include <openssl/bio.h>
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
44 #include <openssl/buffer.h>
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
45 #include <openssl/rand.h>
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
46
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
47 #include "utils.h"
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
48 #include "crypto.h"
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
49 #include "webdav.h"
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
50
33
d7b475e4363c fixed macros with digits not highlighted
Mike Becker <universe@uap-core.de>
parents: 31
diff changeset
51 #define MACRO1337 1337L
25
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
52
75
c72b250866ab add basic support for line continuations in C highlighter
Mike Becker <universe@uap-core.de>
parents: 70
diff changeset
53 static const char* continuation_test = "this is a string\
c72b250866ab add basic support for line continuations in C highlighter
Mike Becker <universe@uap-core.de>
parents: 70
diff changeset
54 with a continuation";
c72b250866ab add basic support for line continuations in C highlighter
Mike Becker <universe@uap-core.de>
parents: 70
diff changeset
55
31
50ae611a785c fixed corrupted multi line comments, when a blank line (containing only white spaces) is present in the comment
universe
parents: 25
diff changeset
56 /* -------------------- This is a testing file. -------------------------- */
50ae611a785c fixed corrupted multi line comments, when a blank line (containing only white spaces) is present in the comment
universe
parents: 25
diff changeset
57 /*
25
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
58 time_t util_parse_creationdate(char *str) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
59 // example: 2012-11-29T21:35:35Z
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
60 if(!str) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
61 return 0;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
62 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
63 // TODO
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
64 return 0;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
65 }
31
50ae611a785c fixed corrupted multi line comments, when a blank line (containing only white spaces) is present in the comment
universe
parents: 25
diff changeset
66 */
25
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
67 time_t util_parse_lastmodified(char *str) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
68 // example: Thu, 29 Nov 2012 21:35:35 GMT
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
69 if(!str) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
70 return 0;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
71 } else {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
72 return curl_getdate(str, NULL);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
73 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
74 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
75
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
76 int util_getboolean(char *v) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
77 if(v[0] == 'T' || v[0] == 't') {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
78 return 1;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
79 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
80 return 0;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
81 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
82
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
83 int util_strtoint(char *str, int64_t *value) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
84 char *end;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
85 int64_t val = strtoll(str, &end, 0);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
86 if(strlen(end) == 0) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
87 *value = val;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
88 return 1;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
89 } else {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
90 return 0;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
91 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
92 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
93
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
94 char* util_url_path(char *url) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
95 char *path = NULL;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
96 size_t len = strlen(url);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
97 int slashcount = 0;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
98 int slmax;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
99 if(len > 7 && !strncasecmp(url, "http://", 7)) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
100 slmax = 3;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
101 } else if(len > 8 && !strncasecmp(url, "https://", 8)) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
102 slmax = 3;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
103 } else {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
104 slmax = 1;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
105 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
106 char c;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
107 for(int i=0;i<len;i++) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
108 c = url[i];
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
109 if(c == '/') {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
110 slashcount++;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
111 if(slashcount == slmax) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
112 path = url + i;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
113 break;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
114 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
115 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
116 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
117 return path;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
118 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
119
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
120 char* util_url_decode(DavSession *sn, char *url) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
121 char *unesc = curl_easy_unescape(sn->handle, url, strlen(url), NULL);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
122 char *ret = strdup(unesc);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
123 curl_free(unesc);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
124 return ret;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
125 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
126
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
127 char* util_resource_name(char *url) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
128 int si = 0;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
129 int osi = 0;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
130 int i = 0;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
131 int p = 0;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
132 char c;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
133 while((c = url[i]) != 0) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
134 if(c == '/') {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
135 osi = si;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
136 si = i;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
137 p = 1;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
138 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
139 i++;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
140 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
141
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
142 char *name = url + si + p;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
143 if(name[0] == 0) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
144 name = url + osi + p;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
145 if(name[0] == 0) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
146 return url;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
147 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
148 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
149
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
150 return name;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
151 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
152
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
153 int util_mkdir(char *path, mode_t mode) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
154 #ifdef _WIN32
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
155 return mkdir(path);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
156 #else
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
157 return mkdir(path, mode);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
158 #endif
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
159 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
160
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
161 char* util_concat_path(char *url_base, char *p) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
162 sstr_t base = sstr(url_base);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
163 sstr_t path;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
164 if(p) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
165 path = sstr(p);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
166 } else {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
167 path = sstrn("", 0);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
168 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
169
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
170 int add_separator = 0;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
171 if(base.ptr[base.length-1] == '/') {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
172 if(path.ptr[0] == '/') {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
173 base.length--;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
174 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
175 } else {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
176 if(path.length == 0 || path.ptr[0] != '/') {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
177 add_separator = 1;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
178 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
179 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
180
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
181 sstr_t url;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
182 if(add_separator) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
183 url = sstrcat(3, base, sstr("/"), path);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
184 } else {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
185 url = sstrcat(2, base, path);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
186 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
187
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
188 return url.ptr;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
189 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
190
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
191 void util_set_url(DavSession *sn, char *href) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
192 sstr_t base = sstr(sn->base_url);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
193 sstr_t href_str = sstr(href);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
194
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
195 char *base_path = util_url_path(sn->base_url);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
196 base.length -= strlen(base_path);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
197
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
198 sstr_t url = sstrcat(2, base, href_str);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
199
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
200 curl_easy_setopt(sn->handle, CURLOPT_URL, url.ptr);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
201 free(url.ptr);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
202 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
203
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
204 char* util_path_to_url(DavSession *sn, char *path) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
205 char *space = malloc(256);
66
1b12cf799fee upgrade to ucx 3.0
Mike Becker <universe@uap-core.de>
parents: 33
diff changeset
206 UcxBuffer *url = ucx_buffer_new(space, 256, CX_BUFFER_AUTO_EXTEND);
25
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
207
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
208 // add base url
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
209 ucx_buffer_write(sn->base_url, 1, strlen(sn->base_url), url);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
210 // remove trailing slash
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
211 ucx_buffer_seek(url, -1, SEEK_CUR);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
212
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
213 sstr_t p = sstr(path);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
214 ssize_t ntk = 0;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
215 sstr_t *tks = sstrsplit(p, S("/"), &ntk);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
216
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
217 for(int i=0;i<ntk;i++) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
218 sstr_t node = tks[i];
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
219 if(node.length > 0) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
220 char *esc = curl_easy_escape(sn->handle, node.ptr, node.length);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
221 ucx_buffer_putc(url, '/');
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
222 ucx_buffer_write(esc, 1, strlen(esc), url);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
223 curl_free(esc);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
224 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
225 free(node.ptr);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
226 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
227 free(tks);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
228 if(path[p.length-1] == '/') {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
229 ucx_buffer_putc(url, '/');
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
230 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
231 ucx_buffer_putc(url, 0);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
232
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
233 space = url->space;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
234 ucx_buffer_free(url);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
235
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
236 return space;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
237 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
238
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
239 char* util_parent_path(char *path) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
240 char *name = util_resource_name(path);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
241 size_t namelen = strlen(name);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
242 size_t pathlen = strlen(path);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
243 size_t parentlen = pathlen - namelen;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
244 char *parent = malloc(parentlen + 1);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
245 memcpy(parent, path, parentlen);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
246 parent[parentlen] = '\0';
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
247 return parent;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
248 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
249
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
250
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
251 char* util_xml_get_text(xmlNode *elm) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
252 xmlNode *node = elm->children;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
253 while(node) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
254 if(node->type == XML_TEXT_NODE) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
255 return (char*)node->content;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
256 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
257 node = node->next;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
258 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
259 return NULL;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
260 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
261
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
262
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
263 char* util_base64decode(char *in) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
264 int len = 0;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
265 return util_base64decode_len(in, &len);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
266 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
267
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
268 char* util_base64decode_len(char* in, int *outlen) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
269 size_t len = strlen(in);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
270 char *out = calloc(1, len);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
271
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
272 BIO* b = BIO_new_mem_buf(in, len);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
273 BIO *d = BIO_new(BIO_f_base64());
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
274 BIO_set_flags(d, BIO_FLAGS_BASE64_NO_NL);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
275 b = BIO_push(d, b);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
276
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
277 *outlen = BIO_read(b, out, len);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
278 BIO_free_all(b);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
279
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
280 return out;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
281 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
282
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
283 char* util_base64encode(char *in, size_t len) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
284 BIO *b;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
285 BIO *e;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
286 BUF_MEM *mem;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
287
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
288 e = BIO_new(BIO_f_base64());
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
289 b = BIO_new(BIO_s_mem());
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
290
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
291 e = BIO_push(e, b);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
292 BIO_write(e, in, len);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
293 BIO_flush(e);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
294
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
295 BIO_get_mem_ptr(e, &mem);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
296 char *out = malloc(mem->length);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
297 memcpy(out, mem->data, mem->length -1);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
298 out[mem->length - 1] = '\0';
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
299
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
300 BIO_free_all(e);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
301
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
302 return out;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
303 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
304
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
305 char* util_encrypt_str(DavSession *sn, char *str, char *key) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
306 DavKey *k = dav_context_get_key(sn->context, key);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
307 if(!k) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
308 // TODO: session error
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
309 return NULL;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
310 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
311
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
312 char *enc_str = aes_encrypt(str, k);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
313 char *ret_str = dav_session_strdup(sn, enc_str);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
314 free(enc_str);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
315 return ret_str;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
316 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
317
31
50ae611a785c fixed corrupted multi line comments, when a blank line (containing only white spaces) is present in the comment
universe
parents: 25
diff changeset
318 /* commented out for testing reasons */
50ae611a785c fixed corrupted multi line comments, when a blank line (containing only white spaces) is present in the comment
universe
parents: 25
diff changeset
319 /*
25
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
320 char* util_decrypt_str(DavSession *sn, char *str, char *key) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
321 DavKey *k = dav_context_get_key(sn->context, key);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
322 if(!k) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
323 // TODO: session error
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
324 return NULL;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
325 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
326
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
327 char *dec_str = aes_decrypt(str, k);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
328 char *ret_str = dav_session_strdup(sn, dec_str);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
329 free(dec_str);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
330 return ret_str;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
331 }
31
50ae611a785c fixed corrupted multi line comments, when a blank line (containing only white spaces) is present in the comment
universe
parents: 25
diff changeset
332 */
25
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
333 char* util_random_str() {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
334 unsigned char *str = malloc(25);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
335 str[24] = '\0';
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
336
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
337 sstr_t t = S(
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
338 "01234567890"
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
339 "abcdefghijklmnopqrstuvwxyz"
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
340 "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
341 const unsigned char *table = (const unsigned char*)t.ptr;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
342
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
343 RAND_pseudo_bytes(str, 24);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
344 for(int i=0;i<24;i++) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
345 int c = str[i] % t.length;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
346 str[i] = table[c];
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
347 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
348
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
349 return (char*)str;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
350 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
351
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
352 /*
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
353 * gets a substring from 0 to the appearance of the token
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
354 * tokens are separated by space
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
355 * sets sub to the substring and returns the remaining string
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
356 */
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
357 sstr_t util_getsubstr_until_token(sstr_t str, sstr_t token, sstr_t *sub) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
358 int i;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
359 int token_start = -1;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
360 int token_end = -1;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
361 for(i=0;i<=str.length;i++) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
362 int c;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
363 if(i == str.length) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
364 c = ' ';
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
365 } else {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
366 c = str.ptr[i];
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
367 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
368 if(c < 33) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
369 if(token_start != -1) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
370 token_end = i;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
371 size_t len = token_end - token_start;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
372 sstr_t tk = sstrsubsl(str, token_start, len);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
373 //printf("token: {%.*s}\n", token.length, token.ptr);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
374 if(!sstrcmp(tk, token)) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
375 *sub = sstrtrim(sstrsubsl(str, 0, token_start));
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
376 break;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
377 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
378 token_start = -1;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
379 token_end = -1;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
380 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
381 } else {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
382 if(token_start == -1) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
383 token_start = i;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
384 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
385 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
386 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
387
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
388 if(i < str.length) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
389 return sstrtrim(sstrsubs(str, i));
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
390 } else {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
391 str.ptr = NULL;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
392 str.length = 0;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
393 return str;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
394 }
70
60cecca5e484 fix illegal memory access when input file does not end with line break
Mike Becker <universe@uap-core.de>
parents: 67
diff changeset
395 }

mercurial