Apache2
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 
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 
104 apr_status_t md_util_exec(apr_pool_t *p, const char *cmd, const char * const *argv,
105  struct apr_array_header_t *env, int *exit_code);
106 
107 /**************************************************************************************************/
108 /* dns name check */
109 
116 int md_dns_is_name(apr_pool_t *p, const char *domain, int need_fqdn);
117 
123 int md_dns_is_wildcard(apr_pool_t *p, const char *domain);
124 
130 int md_dns_matches(const char *pattern, const char *domain);
131 
138  struct apr_array_header_t *domains);
139 
144 int md_dns_domains_match(const apr_array_header_t *domains, const char *name);
145 
146 /**************************************************************************************************/
147 /* file system related */
148 
149 struct apr_file_t;
150 struct apr_finfo_t;
151 
152 apr_status_t md_util_fopen(FILE **pf, const char *fn, const char *mode);
153 
154 apr_status_t md_util_fcreatex(struct apr_file_t **pf, const char *fn,
155  apr_fileperms_t perms, apr_pool_t *p);
156 
157 apr_status_t md_util_path_merge(const char **ppath, apr_pool_t *p, ...);
158 
159 apr_status_t md_util_is_dir(const char *path, apr_pool_t *pool);
160 apr_status_t md_util_is_file(const char *path, apr_pool_t *pool);
161 int md_file_exists(const char *fname, apr_pool_t *p);
162 
163 typedef apr_status_t md_util_file_cb(void *baton, struct apr_file_t *f, apr_pool_t *p);
164 
165 apr_status_t md_util_freplace(const char *fpath, apr_fileperms_t perms, apr_pool_t *p,
166  md_util_file_cb *write, void *baton);
167 
172 apr_status_t md_util_rm_recursive(const char *fpath, apr_pool_t *p, int max_level);
173 
174 typedef apr_status_t md_util_fdo_cb(void *baton, apr_pool_t *p, apr_pool_t *ptemp,
175  const char *dir, const char *name,
176  apr_filetype_e ftype);
177 
179  const char *path, ...);
180 
185  const char *path, int follow_links);
186 
187 apr_status_t md_util_ftree_remove(const char *path, apr_pool_t *p);
188 
189 apr_status_t md_text_fread8k(const char **ptext, apr_pool_t *p, const char *fpath);
191  perms, apr_pool_t *p, const char *text);
192 apr_status_t md_text_freplace(const char *fpath, apr_fileperms_t perms,
193  apr_pool_t *p, const char *text);
194 
195 /**************************************************************************************************/
196 /* base64 url encodings */
198 apr_size_t md_util_base64url_decode(md_data_t *decoded, const char *encoded,
199  apr_pool_t *pool);
200 
201 /**************************************************************************************************/
202 /* http/url related */
203 const char *md_util_schemify(apr_pool_t *p, const char *s, const char *def_scheme);
204 
205 apr_status_t md_util_abs_uri_check(apr_pool_t *p, const char *s, const char **perr);
206 apr_status_t md_util_abs_http_uri_check(apr_pool_t *p, const char *uri, const char **perr);
207 
208 const char *md_link_find_relation(const struct apr_table_t *headers,
209  apr_pool_t *pool, const char *relation);
210 
211 const char *md_util_parse_ct(apr_pool_t *pool, const char *cth);
212 /**************************************************************************************************/
213 /* retry logic */
214 
215 typedef apr_status_t md_util_try_fn(void *baton, int i);
216 
217 apr_status_t md_util_try(md_util_try_fn *fn, void *baton, int ignore_errs,
218  apr_interval_time_t timeout, apr_interval_time_t start_delay,
219  apr_interval_time_t max_delay, int backoff);
220 
221 #endif /* md_util_h */
size_t apr_size_t
Definition: apr.h:393
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)
apr_status_t md_util_exec(apr_pool_t *p, const char *cmd, const char *const *argv, struct apr_array_header_t *env, int *exit_code)
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:174
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)
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:215
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)
const char * md_util_parse_ct(apr_pool_t *pool, const char *cth)
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:163
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