test/ctestfile.c

Wed, 10 Feb 2016 12:34:31 +0100

author
universe
date
Wed, 10 Feb 2016 12:34:31 +0100
changeset 31
50ae611a785c
parent 25
f82aa7afe872
child 33
d7b475e4363c
permissions
-rw-r--r--

fixed corrupted multi line comments, when a blank line (containing only white spaces) is present in the comment

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
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
50
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
51 /* -------------------- 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
52 /*
25
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
53 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
54 // 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
55 if(!str) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
56 return 0;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
57 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
58 // TODO
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
59 return 0;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
60 }
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
61 */
25
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
62 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
63 // 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
64 if(!str) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
65 return 0;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
66 } else {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
67 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
68 }
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 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
72 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
73 return 1;
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 return 0;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
76 }
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 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
79 char *end;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
80 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
81 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
82 *value = val;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
83 return 1;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
84 } else {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
85 return 0;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
86 }
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 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
90 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
91 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
92 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
93 int slmax;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
94 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
95 slmax = 3;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
96 } 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
97 slmax = 3;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
98 } else {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
99 slmax = 1;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
100 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
101 char c;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
102 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
103 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
104 if(c == '/') {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
105 slashcount++;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
106 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
107 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
108 break;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
109 }
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 return path;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
113 }
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 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
116 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
117 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
118 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
119 return ret;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
120 }
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 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
123 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
124 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
125 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
126 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
127 char c;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
128 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
129 if(c == '/') {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
130 osi = si;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
131 si = i;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
132 p = 1;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
133 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
134 i++;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
135 }
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 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
138 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
139 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
140 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
141 return url;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
142 }
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 return name;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
146 }
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 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
149 #ifdef _WIN32
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
150 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
151 #else
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
152 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
153 #endif
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
154 }
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 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
157 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
158 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
159 if(p) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
160 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
161 } else {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
162 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
163 }
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 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
166 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
167 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
168 base.length--;
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 } else {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
171 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
172 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
173 }
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 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
177 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
178 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
179 } else {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
180 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
181 }
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 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
184 }
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 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
187 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
188 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
189
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
190 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
191 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
192
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 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
194
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
195 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
196 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
197 }
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 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
200 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
201 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
202
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
203 // 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
204 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
205 // 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
206 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
207
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
208 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
209 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
210 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
211
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
212 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
213 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
214 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
215 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
216 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
217 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
218 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
219 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
220 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
221 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
222 free(tks);
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
223 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
224 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
225 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
226 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
227
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
228 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
229 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
230
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
231 return space;
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
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
234 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
235 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
236 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
237 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
238 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
239 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
240 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
241 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
242 return parent;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
243 }
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 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
247 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
248 while(node) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
249 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
250 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
251 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
252 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
253 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
254 return NULL;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
255 }
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 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
259 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
260 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
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_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
264 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
265 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
266
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
267 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
268 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
269 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
270 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
271
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
272 *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
273 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
274
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
275 return out;
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
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
278 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
279 BIO *b;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
280 BIO *e;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
281 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
282
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
283 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
284 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
285
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
286 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
287 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
288 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
289
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
290 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
291 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
292 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
293 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
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_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
296
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
297 return out;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
298 }
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 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
301 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
302 if(!k) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
303 // 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
304 return NULL;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
305 }
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 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
308 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
309 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
310 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
311 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
312
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
313 /* 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
314 /*
25
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
315 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
316 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
317 if(!k) {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
318 // 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
319 return NULL;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
320 }
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 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
323 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
324 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
325 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
326 }
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
327 */
25
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
328 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
329 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
330 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
331
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
332 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
333 "01234567890"
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
334 "abcdefghijklmnopqrstuvwxyz"
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 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
337
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
338 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
339 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
340 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
341 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
342 }
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 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
345 }
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 * 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
349 * 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
350 * 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
351 */
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
352 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
353 int i;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
354 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
355 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
356 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
357 int c;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
358 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
359 c = ' ';
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
360 } else {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
361 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
362 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
363 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
364 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
365 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
366 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
367 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
368 //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
369 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
370 *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
371 break;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
372 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
373 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
374 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
375 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
376 } else {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
377 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
378 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
379 }
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 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
384 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
385 } else {
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
386 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
387 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
388 return str;
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
389 }
f82aa7afe872 more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff changeset
390 }

mercurial