libwebsockets
Lightweight C library for HTML5 websockets
lws-cache-ttl.h
Go to the documentation of this file.
1 /*
2  * libwebsockets - small server side websockets and web server implementation
3  *
4  * Copyright (C) 2010 - 2021 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 
51 
52 
53 struct lws_cache_ttl_lru;
54 
74 LWS_VISIBLE LWS_EXTERN int /* only valid until return to event loop */
75 lws_cache_write_through(struct lws_cache_ttl_lru *cache,
76  const char *specific_key, const uint8_t *source,
77  size_t size, lws_usec_t expiry, void **ppay);
78 
79 typedef struct lws_cache_match {
82  /* earliest expiry amongst results */
83  size_t payload_size;
87  size_t tag_size;
88 
89  /* tag name + NUL is overcommitted */
91 
132 lws_cache_lookup(struct lws_cache_ttl_lru *cache, const char *wildcard_key,
133  const void **pdata, size_t *psize);
134 
153 lws_cache_item_get(struct lws_cache_ttl_lru *cache, const char *specific_key,
154  const void **pdata, size_t *psize);
155 
169 lws_cache_item_remove(struct lws_cache_ttl_lru *cache, const char *wildcard_key);
170 
178 LWS_VISIBLE LWS_EXTERN uint64_t
179 lws_cache_footprint(struct lws_cache_ttl_lru *cache);
180 
189 lws_cache_debug_dump(struct lws_cache_ttl_lru *cache);
190 
191 typedef struct lws_cache_results {
192  const uint8_t *ptr; /* set before using walk api */
193  size_t size; /* set before using walk api */
194 
195  size_t payload_len;
196  size_t tag_len;
197  const uint8_t *tag;
199 
218 
219 typedef void (*lws_cache_item_destroy_cb)(void *item, size_t size);
221  struct lws_context *cx;
223  const char *name;
227  struct lws_cache_ttl_lru *parent;
229  const struct lws_cache_ops *ops;
233  union {
234  struct {
235  const char *filepath;
237  } nscookiejar;
238  } u;
244  size_t max_items;
247  size_t max_payload;
249  int tsi;
251 };
252 
254  struct lws_cache_ttl_lru *
255  (*create)(const struct lws_cache_creation_info *info);
258  void
259  (*destroy)(struct lws_cache_ttl_lru **_cache);
263  int
264  (*expunge)(struct lws_cache_ttl_lru *cache);
268  int
269  (*write)(struct lws_cache_ttl_lru *cache, const char *specific_key,
270  const uint8_t *source, size_t size, lws_usec_t expiry,
271  void **ppvoid);
273  int
274  (*tag_match)(struct lws_cache_ttl_lru *cache, const char *wc,
275  const char *tag, char lookup_rules);
280  int
281  (*lookup)(struct lws_cache_ttl_lru *cache, const char *wildcard_key,
282  lws_dll2_owner_t *results_owner);
285  int
286  (*invalidate)(struct lws_cache_ttl_lru *cache, const char *wildcard_key);
289  int
290  (*get)(struct lws_cache_ttl_lru *cache, const char *specific_key,
291  const void **pdata, size_t *psize);
295  void
296  (*debug_dump)(struct lws_cache_ttl_lru *cache);
298 };
299 
317 LWS_VISIBLE LWS_EXTERN struct lws_cache_ttl_lru *
319 
329 lws_cache_destroy(struct lws_cache_ttl_lru **cache);
330 
342 lws_cache_expunge(struct lws_cache_ttl_lru *cache);
343 
344 LWS_VISIBLE extern const struct lws_cache_ops lws_cache_ops_heap,
346 
348 
lws_usec_t expiry
Definition: lws-cache-ttl.h:81
struct lws_context * cx
struct lws_cache_ttl_lru * parent
const uint8_t * ptr
const struct lws_cache_ops * ops
lws_dll2_t list
Definition: lws-cache-ttl.h:80
const uint8_t * tag
union lws_cache_creation_info::@1 u
lws_cache_item_destroy_cb cb
LWS_VISIBLE LWS_EXTERN void lws_cache_debug_dump(struct lws_cache_ttl_lru *cache)
LWS_VISIBLE LWS_EXTERN int lws_cache_item_get(struct lws_cache_ttl_lru *cache, const char *specific_key, const void **pdata, size_t *psize)
struct lws_cache_match lws_cache_match_t
LWS_VISIBLE LWS_EXTERN int lws_cache_lookup(struct lws_cache_ttl_lru *cache, const char *wildcard_key, const void **pdata, size_t *psize)
LWS_VISIBLE LWS_EXTERN int lws_cache_expunge(struct lws_cache_ttl_lru *cache)
LWS_VISIBLE LWS_EXTERN struct lws_cache_ttl_lru * lws_cache_create(const struct lws_cache_creation_info *info)
LWS_VISIBLE LWS_EXTERN uint64_t lws_cache_footprint(struct lws_cache_ttl_lru *cache)
LWS_VISIBLE LWS_EXTERN int lws_cache_write_through(struct lws_cache_ttl_lru *cache, const char *specific_key, const uint8_t *source, size_t size, lws_usec_t expiry, void **ppay)
void(* lws_cache_item_destroy_cb)(void *item, size_t size)
LWS_VISIBLE LWS_EXTERN int lws_cache_results_walk(lws_cache_results_t *walk_ctx)
LWS_VISIBLE LWS_EXTERN int lws_cache_item_remove(struct lws_cache_ttl_lru *cache, const char *wildcard_key)
LWS_VISIBLE LWS_EXTERN void lws_cache_destroy(struct lws_cache_ttl_lru **cache)
LWS_VISIBLE const struct lws_cache_ops lws_cache_ops_heap lws_cache_ops_nscookiejar
struct lws_cache_results lws_cache_results_t
#define LWS_EXTERN
int64_t lws_usec_t
unsigned char uint8_t
#define LWS_VISIBLE
int(* get)(struct lws_cache_ttl_lru *cache, const char *specific_key, const void **pdata, size_t *psize)
void(* destroy)(struct lws_cache_ttl_lru **_cache)
int(* lookup)(struct lws_cache_ttl_lru *cache, const char *wildcard_key, lws_dll2_owner_t *results_owner)
void(* debug_dump)(struct lws_cache_ttl_lru *cache)
int(* write)(struct lws_cache_ttl_lru *cache, const char *specific_key, const uint8_t *source, size_t size, lws_usec_t expiry, void **ppvoid)
int(* invalidate)(struct lws_cache_ttl_lru *cache, const char *wildcard_key)
int(* tag_match)(struct lws_cache_ttl_lru *cache, const char *wc, const char *tag, char lookup_rules)
int(* expunge)(struct lws_cache_ttl_lru *cache)