libwebsockets
Lightweight C library for HTML5 websockets
lws-map.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 
44 
45 typedef struct lws_map lws_map_t;
46 struct lws_map_item;
47 
48 typedef void * lws_map_key_t;
49 typedef void * lws_map_value_t;
51 
53  size_t kl);
54 typedef int (*lws_map_compare_key_t)(const lws_map_key_t key1, size_t kl1,
55  const lws_map_value_t key2, size_t kl2);
56 typedef void * (*lws_map_alloc_t)(struct lws_map *mo, size_t x);
57 typedef void (*lws_map_free_t)(void *);
58 
59 /*
60  * Creation parameters for the map, copied into the map owner
61  */
62 
63 typedef struct lws_map_info {
66  lws_map_alloc_t _alloc; /* NULL = lws_malloc */
67  lws_map_free_t _free; /* NULL = lws_free */
68 
69  void *opaque;
71  void *aux;
74  size_t modulo;
77 
78 LWS_VISIBLE LWS_EXTERN const void *
79 lws_map_item_key(struct lws_map_item *_item);
80 LWS_VISIBLE LWS_EXTERN const void *
81 lws_map_item_value(struct lws_map_item *_item);
83 lws_map_item_key_len(struct lws_map_item *_item);
85 lws_map_item_value_len(struct lws_map_item *_item);
86 
87 /*
88  * Helpers for C string keys case
89  */
90 
91 #define lws_map_item_create_ks(_map, _str, _v, _vl) \
92  lws_map_item_create(_map, (const lws_map_key_t)_str, \
93  strlen(_str), (const lws_map_value_t)_v, \
94  _vl)
95 #define lws_map_item_lookup_ks(_map, _str) \
96  lws_map_item_lookup(_map, (const lws_map_key_t)_str, strlen(_str))
97 
121 
122 /*
123  * helpers that can be used for info._alloc and info._free if using lwsac
124  * allocation for items, set info.opaque to point to the lwsac pointer, and
125  * aux to (void *)chunksize, or leave zero / NULL for the default
126  */
127 
128 LWS_VISIBLE LWS_EXTERN void *
129 lws_map_alloc_lwsac(struct lws_map *map, size_t x);
130 
133 
144 
161 LWS_VISIBLE LWS_EXTERN struct lws_map_item *
163  const lws_map_key_t key, size_t keylen,
164  const lws_map_value_t value, size_t valuelen);
165 
172 lws_map_item_destroy(struct lws_map_item *item);
173 
185 LWS_VISIBLE LWS_EXTERN struct lws_map_item *
186 lws_map_item_lookup(lws_map_t *map, const lws_map_key_t key, size_t keylen);
187 
unsigned int uint32_t
#define LWS_EXTERN
#define LWS_VISIBLE
lws_map_hash_from_key_t _hash
Definition: lws-map.h:64
lws_map_hash_t(* lws_map_hash_from_key_t)(const lws_map_key_t key, size_t kl)
Definition: lws-map.h:52
uint32_t lws_map_hash_t
Definition: lws-map.h:50
LWS_VISIBLE LWS_EXTERN void * lws_map_alloc_lwsac(struct lws_map *map, size_t x)
LWS_VISIBLE LWS_EXTERN void lws_map_destroy(lws_map_t **pmap)
void *(* lws_map_alloc_t)(struct lws_map *mo, size_t x)
Definition: lws-map.h:56
LWS_VISIBLE LWS_EXTERN size_t lws_map_item_value_len(struct lws_map_item *_item)
lws_map_free_t _free
Definition: lws-map.h:67
void(* lws_map_free_t)(void *)
Definition: lws-map.h:57
LWS_VISIBLE LWS_EXTERN void lws_map_free_lwsac(void *v)
LWS_VISIBLE LWS_EXTERN void lws_map_item_destroy(struct lws_map_item *item)
void * aux
Definition: lws-map.h:71
void * opaque
Definition: lws-map.h:69
LWS_VISIBLE LWS_EXTERN size_t lws_map_item_key_len(struct lws_map_item *_item)
LWS_VISIBLE LWS_EXTERN const void * lws_map_item_key(struct lws_map_item *_item)
LWS_VISIBLE LWS_EXTERN const void * lws_map_item_value(struct lws_map_item *_item)
struct lws_map_info lws_map_info_t
lws_map_alloc_t _alloc
Definition: lws-map.h:66
struct lws_map lws_map_t
Definition: lws-map.h:45
int(* lws_map_compare_key_t)(const lws_map_key_t key1, size_t kl1, const lws_map_value_t key2, size_t kl2)
Definition: lws-map.h:54
LWS_VISIBLE LWS_EXTERN struct lws_map_item * lws_map_item_create(lws_map_t *map, const lws_map_key_t key, size_t keylen, const lws_map_value_t value, size_t valuelen)
lws_map_compare_key_t _compare
Definition: lws-map.h:65
size_t modulo
Definition: lws-map.h:74
void * lws_map_key_t
Definition: lws-map.h:46
LWS_VISIBLE LWS_EXTERN lws_map_t * lws_map_create(const lws_map_info_t *info)
void * lws_map_value_t
Definition: lws-map.h:49
LWS_VISIBLE LWS_EXTERN struct lws_map_item * lws_map_item_lookup(lws_map_t *map, const lws_map_key_t key, size_t keylen)