test/ctestfile.c

Tue, 23 Aug 2016 12:05:41 +0200

author
Mike Becker <universe@uap-core.de>
date
Tue, 23 Aug 2016 12:05:41 +0200
changeset 37
1a67185e5496
parent 33
d7b475e4363c
child 66
1b12cf799fee
permissions
-rw-r--r--

adds version number and changes build system

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>
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
37 #include <curl/curl.h>
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
38
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
39 #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
40 #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
41 #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
42 #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
43 #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
44 #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
45
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
46 #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
47 #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
48 #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
49
33
d7b475e4363c fixed macros with digits not highlighted
Mike Becker <universe@uap-core.de>
parents: 31
diff changeset
50 #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
51
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
52 /* -------------------- 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
53 /*
25
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
54 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
55 // 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
56 if(!str) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
57 return 0;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
58 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
59 // TODO
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
60 return 0;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
61 }
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
62 */
25
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
63 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
64 // 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
65 if(!str) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
66 return 0;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
67 } else {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
68 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
69 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
70 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
71
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
72 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
73 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
74 return 1;
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 return 0;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
77 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
78
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
79 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
80 char *end;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
81 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
82 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
83 *value = val;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
84 return 1;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
85 } else {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
86 return 0;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
87 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
88 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
89
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
90 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
91 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
92 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
93 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
94 int slmax;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
95 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
96 slmax = 3;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
97 } 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
98 slmax = 3;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
99 } else {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
100 slmax = 1;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
101 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
102 char c;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
103 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
104 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
105 if(c == '/') {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
106 slashcount++;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
107 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
108 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
109 break;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
110 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
111 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
112 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
113 return path;
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 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
117 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
118 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
119 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
120 return ret;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
121 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
122
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
123 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
124 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
125 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
126 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
127 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
128 char c;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
129 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
130 if(c == '/') {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
131 osi = si;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
132 si = i;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
133 p = 1;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
134 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
135 i++;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
136 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
137
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
138 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
139 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
140 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
141 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
142 return url;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
143 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
144 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
145
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
146 return name;
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 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
150 #ifdef _WIN32
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
151 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
152 #else
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
153 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
154 #endif
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
155 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
156
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
157 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
158 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
159 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
160 if(p) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
161 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
162 } else {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
163 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
164 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
165
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
166 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
167 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
168 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
169 base.length--;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
170 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
171 } else {
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.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
173 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
174 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
175 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
176
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
177 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
178 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
179 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
180 } else {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
181 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
182 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
183
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
184 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
185 }
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 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
188 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
189 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
190
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
191 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
192 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
193
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
194 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
195
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
196 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
197 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
198 }
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 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
201 char *space = malloc(256);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
202 UcxBuffer *url = ucx_buffer_new(space, 256, UCX_BUFFER_AUTOEXTEND);
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 // 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
205 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
206 // 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
207 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
208
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
209 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
210 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
211 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
212
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
213 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
214 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
215 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
216 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
217 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
218 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
219 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
220 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
221 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
222 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
223 free(tks);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
224 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
225 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
226 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
227 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
228
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
229 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
230 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
231
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
232 return space;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
233 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
234
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
235 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
236 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
237 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
238 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
239 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
240 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
241 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
242 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
243 return parent;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
244 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
245
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
246
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
247 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
248 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
249 while(node) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
250 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
251 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
252 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
253 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
254 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
255 return NULL;
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
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 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
260 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
261 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
262 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
263
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
264 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
265 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
266 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
267
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
268 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
269 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
270 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
271 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
272
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
273 *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
274 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
275
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
276 return out;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
277 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
278
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
279 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
280 BIO *b;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
281 BIO *e;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
282 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
283
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
284 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
285 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
286
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
287 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
288 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
289 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
290
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
291 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
292 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
293 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
294 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
295
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
296 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
297
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
298 return out;
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
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
301 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
302 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
303 if(!k) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
304 // 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
305 return NULL;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
306 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
307
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
308 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
309 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
310 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
311 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
312 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
313
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
314 /* 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
315 /*
25
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
316 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
317 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
318 if(!k) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
319 // 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
320 return NULL;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
321 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
322
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
323 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
324 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
325 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
326 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
327 }
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
328 */
25
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
329 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
330 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
331 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
332
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
333 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
334 "01234567890"
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
335 "abcdefghijklmnopqrstuvwxyz"
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
336 "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
337 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
338
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
339 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
340 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
341 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
342 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
343 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
344
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
345 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
346 }
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 * 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
350 * 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
351 * 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
352 */
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
353 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
354 int i;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
355 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
356 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
357 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
358 int c;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
359 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
360 c = ' ';
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
361 } else {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
362 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
363 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
364 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
365 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
366 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
367 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
368 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
369 //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
370 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
371 *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
372 break;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
373 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
374 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
375 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
376 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
377 } else {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
378 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
379 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
380 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
381 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
382 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
383
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
384 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
385 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
386 } else {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
387 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
388 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
389 return str;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
390 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
391 }

mercurial