libwebsockets
Lightweight C library for HTML5 websockets
Loading...
Searching...
No Matches
lws-diskcache.h
Go to the documentation of this file.
1/*
2 * libwebsockets - small server side websockets and web server implementation
3 *
4 * Copyright (C) 2010 - 2019 Andy Green <andy@warmcat.com>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 * IN THE SOFTWARE.
23 */
24
60
61struct lws_diskcache_scan;
62
63/*
64 * Cache object names are the caller's hash in hex: up to a SHA-512 hex name
65 * (128 chars) plus the NUL.
66 */
67#define LWS_DISKCACHE_NAME_MAX 129
68/*
69 * The cache dir base with a subdir after it, "<base>/x/y", has to fit in this:
70 * lws_diskcache_create() and lws_diskcache_prepare() refuse a base that does
71 * not.
72 */
73#define LWS_DISKCACHE_DIR_MAX 256
74/*
75 * The longest object path lws_diskcache_query() composes, including the temp
76 * name suffix used while the object is being created. A cache path buffer of
77 * this size works with any base that lws_diskcache_create() accepted.
78 */
79#define LWS_DISKCACHE_PATH_MAX (LWS_DISKCACHE_DIR_MAX + \
80 LWS_DISKCACHE_NAME_MAX + 32)
81
92LWS_VISIBLE LWS_EXTERN struct lws_diskcache_scan *
93lws_diskcache_create(const char *cache_dir_base, uint64_t cache_size_limit);
94
104lws_diskcache_destroy(struct lws_diskcache_scan **lds);
105
122lws_diskcache_prepare(const char *cache_base_dir, int mode, uid_t uid);
123
124#define LWS_DISKCACHE_QUERY_NO_CACHE 0
125#define LWS_DISKCACHE_QUERY_EXISTS 1
126#define LWS_DISKCACHE_QUERY_CREATING 2
127#define LWS_DISKCACHE_QUERY_ONGOING 3 /* something else is creating it */
128
161lws_diskcache_query(struct lws_diskcache_scan *lds, int is_bot,
162 const char *hash_hex, int *_fd, char *cache, int cache_len,
163 size_t *extant_cache_len);
164
177
194lws_diskcache_trim(struct lws_diskcache_scan *lds);
195
196
206lws_diskcache_secs_to_idle(struct lws_diskcache_scan *lds);
LWS_VISIBLE LWS_EXTERN int lws_diskcache_trim(struct lws_diskcache_scan *lds)
LWS_VISIBLE LWS_EXTERN int lws_diskcache_prepare(const char *cache_base_dir, int mode, uid_t uid)
LWS_VISIBLE LWS_EXTERN int lws_diskcache_secs_to_idle(struct lws_diskcache_scan *lds)
LWS_VISIBLE LWS_EXTERN void lws_diskcache_destroy(struct lws_diskcache_scan **lds)
LWS_VISIBLE LWS_EXTERN int lws_diskcache_finalize_name(char *cache)
LWS_VISIBLE LWS_EXTERN struct lws_diskcache_scan * lws_diskcache_create(const char *cache_dir_base, uint64_t cache_size_limit)
LWS_VISIBLE LWS_EXTERN int lws_diskcache_query(struct lws_diskcache_scan *lds, int is_bot, const char *hash_hex, int *_fd, char *cache, int cache_len, size_t *extant_cache_len)
#define LWS_EXTERN
#define LWS_VISIBLE