|
1 /* |
|
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
|
3 * |
|
4 * Copyright 2019 Olaf Wintermann. All rights reserved. |
|
5 * |
|
6 * Redistribution and use in source and binary forms, with or without |
|
7 * modification, are permitted provided that the following conditions are met: |
|
8 * |
|
9 * 1. Redistributions of source code must retain the above copyright |
|
10 * notice, this list of conditions and the following disclaimer. |
|
11 * |
|
12 * 2. Redistributions in binary form must reproduce the above copyright |
|
13 * notice, this list of conditions and the following disclaimer in the |
|
14 * documentation and/or other materials provided with the distribution. |
|
15 * |
|
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
26 * POSSIBILITY OF SUCH DAMAGE. |
|
27 */ |
|
28 |
|
29 #ifndef UTILS_H |
|
30 #define UTILS_H |
|
31 |
|
32 #ifdef _WIN32 |
|
33 #include <winsock2.h> |
|
34 #include <io.h> |
|
35 #endif /* _WIN32 */ |
|
36 |
|
37 #include <sys/types.h> |
|
38 #include <libxml/tree.h> |
|
39 #include <cx/string.h> |
|
40 #include <cx/buffer.h> |
|
41 #include <sys/stat.h> |
|
42 #include <inttypes.h> |
|
43 |
|
44 #include <curl/curl.h> |
|
45 #include "webdav.h" |
|
46 |
|
47 #ifdef _WIN32 |
|
48 #ifndef mode_t |
|
49 #define mode_t int |
|
50 #endif |
|
51 #endif |
|
52 |
|
53 #ifndef S_IRWXG |
|
54 /* if one is not defined, the others are probably also not defined */ |
|
55 #define S_IRWXU 0700 |
|
56 #define S_IRWXG 070 |
|
57 #define S_IRGRP 040 |
|
58 #define S_IWGRP 020 |
|
59 #define S_IXGRP 010 |
|
60 #define S_IRWXO 07 |
|
61 #define S_IROTH 04 |
|
62 #define S_IWOTH 02 |
|
63 #define S_IXOTH 01 |
|
64 #endif /* S_IRWXG */ |
|
65 |
|
66 #ifdef __cplusplus |
|
67 extern "C" { |
|
68 #endif |
|
69 |
|
70 time_t util_parse_creationdate(char *str); |
|
71 time_t util_parse_lastmodified(char *str); |
|
72 |
|
73 int util_mkdir(char *path, mode_t mode); |
|
74 |
|
75 char* util_url_base(char *url); |
|
76 char* util_url_base_s(cxstring url); |
|
77 const char* util_url_path(const char *url); |
|
78 char* util_url_decode(DavSession *sn, const char *url); |
|
79 const char* util_resource_name(const char *url); |
|
80 char* util_concat_path(const char *url_base, const char *path); |
|
81 char* util_get_url(DavSession *sn, const char *href); |
|
82 void util_set_url(DavSession *sn, const char *href); |
|
83 |
|
84 /* |
|
85 * returns true if path1 and path2 are equal or if path2 is a child of path1 |
|
86 */ |
|
87 int util_path_isrelated(const char *path1, const char *path2); |
|
88 |
|
89 int util_path_isabsolut(const char *path); |
|
90 |
|
91 char* util_path_normalize(const char *path); |
|
92 char* util_create_relative_path(const char *abspath, const char *base); |
|
93 |
|
94 void util_capture_header(CURL *handle, CxMap* map); |
|
95 |
|
96 char* util_path_to_url(DavSession *sn, const char *path); |
|
97 char* util_parent_path(const char *path); |
|
98 |
|
99 char* util_size_str(DavBool iscollection, uint64_t contentlength); |
|
100 char* util_date_str(time_t tm); |
|
101 |
|
102 int util_getboolean(const char *v); |
|
103 int util_strtouint(const char *str, uint64_t *value); |
|
104 int util_strtoint(const char *str, int64_t *value); |
|
105 int util_szstrtouint(const char *str, uint64_t *value); |
|
106 |
|
107 int util_uint_mul(uint64_t a, uint64_t b, uint64_t *result); |
|
108 |
|
109 char* util_xml_get_text(const xmlNode *elm); |
|
110 |
|
111 char* util_base64decode(const char *in); |
|
112 char* util_base64decode_len(const char *in, int *outlen); |
|
113 char* util_base64encode(const char *in, size_t len); |
|
114 |
|
115 char* util_encrypt_str(DavSession *sn, const char *str, const char *key); |
|
116 char* util_encrypt_str_k(DavSession *sn, const char *str, DavKey *key); |
|
117 char* util_decrypt_str(DavSession *sn, const char *str, const char *key); |
|
118 char* util_decrypt_str_k(DavSession *sn, const char *str, DavKey *key); |
|
119 |
|
120 char* util_random_str(); |
|
121 |
|
122 //sstr_t util_getsubstr_until_token(sstr_t str, sstr_t token, sstr_t *sub); |
|
123 |
|
124 cxmutstr util_readline(FILE *stream); |
|
125 char* util_password_input(char *prompt); |
|
126 |
|
127 int util_exec_command(char *command, CxBuffer *outbuf); |
|
128 |
|
129 char* util_hexstr(const unsigned char *data, size_t len); |
|
130 |
|
131 void util_remove_trailing_pathseparator(char *path); |
|
132 |
|
133 char* util_file_hash(const char *path); |
|
134 |
|
135 |
|
136 #ifdef __cplusplus |
|
137 } |
|
138 #endif |
|
139 |
|
140 #endif /* UTILS_H */ |
|
141 |