Apache2
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
md_util.h
Go to the documentation of this file.
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2  * contributor license agreements. See the NOTICE file distributed with
3  * this work for additional information regarding copyright ownership.
4  * The ASF licenses this file to You under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef mod_md_md_util_h
18 #define mod_md_md_util_h
19 
20 #include <stdio.h>
21 #include <apr_file_io.h>
22 
23 struct apr_array_header_t;
24 struct apr_table_t;
25 
26 /**************************************************************************************************/
27 /* pool utils */
28 
29 typedef apr_status_t md_util_action(void *baton, apr_pool_t *p, apr_pool_t *ptemp);
30 typedef apr_status_t md_util_vaction(void *baton, apr_pool_t *p, apr_pool_t *ptemp, va_list ap);
31 
33 apr_status_t md_util_pool_vdo(md_util_vaction *cb, void *baton, apr_pool_t *p, ...);
34 
35 /**************************************************************************************************/
36 /* data chunks */
37 
38 typedef struct md_data_t md_data_t;
39 struct md_data_t {
40  const char *data;
42 };
43 
44 #define MD_DATA_CWRAP(d, buffer) md_data_t d = { buffer, sizeof(buffer) }
45 
47 md_data_t *md_data_create(apr_pool_t *p, const char *data, apr_size_t len);
48 
50 
51 apr_status_t md_data_to_hex(const char **phex, char separator,
52  apr_pool_t *p, const md_data_t *data);
53 
54 /**************************************************************************************************/
55 /* generic arrays */
56 
61 int md_array_remove(struct apr_array_header_t *a, void *elem);
62 
63 /*
64  * Remove the ith entry from the array.
65  * @return != 0 iff an entry was removed, e.g. idx was not outside range
66  */
67 int md_array_remove_at(struct apr_array_header_t *a, int idx);
68 
69 /**************************************************************************************************/
70 /* string related */
71 char *md_util_str_tolower(char *s);
72 
76 int md_array_is_empty(const struct apr_array_header_t *array);
77 
78 int md_array_str_index(const struct apr_array_header_t *array, const char *s,
79  int start, int case_sensitive);
80 
81 int md_array_str_eq(const struct apr_array_header_t *a1,
82  const struct apr_array_header_t *a2, int case_sensitive);
83 
85 
90  int case_sensitive);
91 
96  const char *exclude, int case_sensitive);
97 
99  struct apr_array_header_t *src, int case_sensitive);
100 
101 /**************************************************************************************************/
102 /* process execution */
103 apr_status_t md_util_exec(apr_pool_t *p, const char *cmd, const char * const *argv,
104  int *exit_code);
105 
106 /**************************************************************************************************/
107 /* dns name check */
108 
115 int md_dns_is_name(apr_pool_t *p, const char *domain, int need_fqdn);
116 
122 int md_dns_is_wildcard(apr_pool_t *p, const char *domain);
123 
129 int md_dns_matches(const char *pattern, const char *domain);
130 
137  struct apr_array_header_t *domains);
138 
143 int md_dns_domains_match(const apr_array_header_t *domains, const char *name);
144 
145 /**************************************************************************************************/
146 /* file system related */
147 
148 struct apr_file_t;
149 struct apr_finfo_t;
150 
151 apr_status_t md_util_fopen(FILE **pf, const char *fn, const char *mode);
152 
153 apr_status_t md_util_fcreatex(struct apr_file_t **pf, const char *fn,
154  apr_fileperms_t perms, apr_pool_t *p);
155 
156 apr_status_t md_util_path_merge(const char **ppath, apr_pool_t *p, ...);
157 
158 apr_status_t md_util_is_dir(const char *path, apr_pool_t *pool);
159 apr_status_t md_util_is_file(const char *path, apr_pool_t *pool);
160 int md_file_exists(const char *fname, apr_pool_t *p);
161 
162 typedef apr_status_t md_util_file_cb(void *baton, struct apr_file_t *f, apr_pool_t *p);
163 
164 apr_status_t md_util_freplace(const char *fpath, apr_fileperms_t perms, apr_pool_t *p,
165  md_util_file_cb *write, void *baton);
166 
171 apr_status_t md_util_rm_recursive(const char *fpath, apr_pool_t *p, int max_level);
172 
173 typedef apr_status_t md_util_fdo_cb(void *baton, apr_pool_t *p, apr_pool_t *ptemp,
174  const char *dir, const char *name,
175  apr_filetype_e ftype);
176 
178  const char *path, ...);
179 
184  const char *path, int follow_links);
185 
186 apr_status_t md_util_ftree_remove(const char *path, apr_pool_t *p);
187 
188 apr_status_t md_text_fread8k(const char **ptext, apr_pool_t *p, const char *fpath);
190  perms, apr_pool_t *p, const char *text);
191 apr_status_t md_text_freplace(const char *fpath, apr_fileperms_t perms,
192  apr_pool_t *p, const char *text);
193 
194 /**************************************************************************************************/
195 /* base64 url encodings */
196 const char *md_util_base64url_encode(const md_data_t *data, apr_pool_t *pool);
197 apr_size_t md_util_base64url_decode(md_data_t *decoded, const char *encoded,
198  apr_pool_t *pool);
199 
200 /**************************************************************************************************/
201 /* http/url related */
202 const char *md_util_schemify(apr_pool_t *p, const char *s, const char *def_scheme);
203 
204 apr_status_t md_util_abs_uri_check(apr_pool_t *p, const char *s, const char **perr);
205 apr_status_t md_util_abs_http_uri_check(apr_pool_t *p, const char *uri, const char **perr);
206 
207 const char *md_link_find_relation(const struct apr_table_t *headers,
208  apr_pool_t *pool, const char *relation);
209 
210 /**************************************************************************************************/
211 /* retry logic */
212 
213 typedef apr_status_t md_util_try_fn(void *baton, int i);
214 
215 apr_status_t md_util_try(md_util_try_fn *fn, void *baton, int ignore_errs,
216  apr_interval_time_t timeout, apr_interval_time_t start_delay,
217  apr_interval_time_t max_delay, int backoff);
218 
219 #endif /* md_util_h */
size_t apr_size_t
Definition: apr.h:397
const char * fname
Definition: apr_file_info.h:208
int md_dns_matches(const char *pattern, const char *domain)
apr_status_t md_util_pool_vdo(md_util_vaction *cb, void *baton, apr_pool_t *p,...)
md_data_t * md_data_create(apr_pool_t *p, const char *data, apr_size_t len)
apr_status_t md_util_action(void *baton, apr_pool_t *p, apr_pool_t *ptemp)
Definition: md_util.h:29
char * md_util_str_tolower(char *s)
Definition: apr_arch_file_io.h:107
Definition: apr_tables.h:62
apr_status_t md_util_rm_recursive(const char *fpath, apr_pool_t *p, int max_level)
apr_status_t md_util_fdo_cb(void *baton, apr_pool_t *p, apr_pool_t *ptemp, const char *dir, const char *name, apr_filetype_e ftype)
Definition: md_util.h:173
struct apr_array_header_t * md_array_str_compact(apr_pool_t *p, struct apr_array_header_t *src, int case_sensitive)
md_data_t * md_data_make(apr_pool_t *p, apr_size_t len)
Definition: md_util.h:39
apr_bucket_brigade request_rec apr_pool_t * pool
Definition: mod_dav.h:555
int md_array_remove_at(struct apr_array_header_t *a, int idx)
int md_dns_is_name(apr_pool_t *p, const char *domain, int need_fqdn)
apr_status_t md_util_path_merge(const char **ppath, apr_pool_t *p,...)
void md_data_assign_pcopy(md_data_t *dest, const md_data_t *src, apr_pool_t *p)
apr_status_t md_text_fread8k(const char **ptext, apr_pool_t *p, const char *fpath)
apr_status_t md_util_files_do(md_util_fdo_cb *cb, void *baton, apr_pool_t *p, const char *path,...)
apr_status_t md_util_abs_http_uri_check(apr_pool_t *p, const char *uri, const char **perr)
apr_status_t md_util_tree_do(md_util_fdo_cb *cb, void *baton, apr_pool_t *p, const char *path, int follow_links)
apr_status_t md_util_freplace(const char *fpath, apr_fileperms_t perms, apr_pool_t *p, md_util_file_cb *write, void *baton)
apr_status_t md_util_is_file(const char *path, apr_pool_t *pool)
apr_status_t md_util_vaction(void *baton, apr_pool_t *p, apr_pool_t *ptemp, va_list ap)
Definition: md_util.h:30
const char const char * uri
Definition: mod_dav.h:631
struct apr_array_header_t * md_dns_make_minimal(apr_pool_t *p, struct apr_array_header_t *domains)
APR File I/O Handling.
apr_int64_t apr_interval_time_t
Definition: apr_time.h:55
int md_array_str_index(const struct apr_array_header_t *array, const char *s, int start, int case_sensitive)
apr_status_t md_util_exec(apr_pool_t *p, const char *cmd, const char *const *argv, int *exit_code)
int md_dns_domains_match(const apr_array_header_t *domains, const char *name)
apr_size_t len
Definition: md_util.h:41
int md_array_str_eq(const struct apr_array_header_t *a1, const struct apr_array_header_t *a2, int case_sensitive)
struct apr_array_header_t * md_array_str_remove(apr_pool_t *p, struct apr_array_header_t *src, const char *exclude, int case_sensitive)
apr_status_t md_util_ftree_remove(const char *path, apr_pool_t *p)
int md_array_remove(struct apr_array_header_t *a, void *elem)
apr_int32_t apr_fileperms_t
Definition: apr_file_info.h:125
const char * md_util_base64url_encode(const md_data_t *data, apr_pool_t *pool)
dav_error * src
Definition: mod_dav.h:186
apr_status_t md_util_try(md_util_try_fn *fn, void *baton, int ignore_errs, apr_interval_time_t timeout, apr_interval_time_t start_delay, apr_interval_time_t max_delay, int backoff)
apr_status_t md_util_fcreatex(struct apr_file_t **pf, const char *fn, apr_fileperms_t perms, apr_pool_t *p)
const char * md_link_find_relation(const struct apr_table_t *headers, apr_pool_t *pool, const char *relation)
apr_size_t md_util_base64url_decode(md_data_t *decoded, const char *encoded, apr_pool_t *pool)
apr_pool_t * p
int md_file_exists(const char *fname, apr_pool_t *p)
apr_status_t md_util_try_fn(void *baton, int i)
Definition: md_util.h:213
apr_status_t md_util_pool_do(md_util_action *cb, void *baton, apr_pool_t *p)
apr_status_t md_util_abs_uri_check(apr_pool_t *p, const char *s, const char **perr)
apr_status_t md_text_fcreatex(const char *fpath, apr_fileperms_t perms, apr_pool_t *p, const char *text)
int md_dns_is_wildcard(apr_pool_t *p, const char *domain)
int md_array_str_add_missing(struct apr_array_header_t *dest, struct apr_array_header_t *src, int case_sensitive)
struct apr_table_t apr_table_t
Definition: apr_tables.h:56
const char * name
Definition: mod_dav.h:805
int md_array_is_empty(const struct apr_array_header_t *array)
struct apr_pool_t apr_pool_t
Definition: apr_pools.h:60
apr_status_t md_text_freplace(const char *fpath, apr_fileperms_t perms, apr_pool_t *p, const char *text)
int apr_status_t
Definition: apr_errno.h:44
apr_status_t md_data_to_hex(const char **phex, char separator, apr_pool_t *p, const md_data_t *data)
apr_status_t md_util_file_cb(void *baton, struct apr_file_t *f, apr_pool_t *p)
Definition: md_util.h:162
apr_status_t md_util_fopen(FILE **pf, const char *fn, const char *mode)
apr_status_t md_util_is_dir(const char *path, apr_pool_t *pool)
struct apr_array_header_t * md_array_str_clone(apr_pool_t *p, struct apr_array_header_t *array)
const char * md_util_schemify(apr_pool_t *p, const char *s, const char *def_scheme)
apr_filetype_e
Definition: apr_file_info.h:62
Definition: apr_file_info.h:174
const char * data
Definition: md_util.h:40