| Wireshark 4.7.0 The Wireshark network protocol analyzer

Loading...
Searching...
No Matches
fifo_string_cache.h
1/* fifo_string_cache.h
2 * A string cache, possibly with a bounded size, using FIFO order to control
3 * the size.
4 *
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
8 *
9 * SPDX-License-Identifier: GPL-2.0-or-later
10 */
11#ifndef __FIFO_STRING_CACHE_H__
12#define __FIFO_STRING_CACHE_H__
13
14#include <stdbool.h>
15
16#include <glib.h>
17
18#include "ws_symbol_export.h"
19
20#ifdef __cplusplus
21extern "C" {
22#endif /* __cplusplus */
23
24 typedef struct {
25 GHashTable *set;
26 GSList *head;
27 GSList *tail;
28 unsigned max_entries;
29} fifo_string_cache_t;
30
31// These functions are marked with WS_DLL_PUBLIC so they can be unit-tested
32
33// Initialize an object. If string_free_func is given, then the
34// fifo_string_cache owns the string data, and will call this string_free_func
35// during fifo_string_cache_free().
36// If string_free_func is NULL, then the caller owns the string data, and it is
37// the caller that is responsible for freeing the data.
38WS_DLL_PUBLIC void
39fifo_string_cache_init(fifo_string_cache_t *fcache, unsigned max_entries, GDestroyNotify string_free_func);
40
41// Free all memory owned by the fifo_string_cache. Whether or not the
42// fifoe_string_cache owns the actual strings depends on whether a
43// string_free_func was passed in during fifo_string_cache_init().
44WS_DLL_PUBLIC void
45fifo_string_cache_free(fifo_string_cache_t *fcache);
46
47// Does the cache contain a specific string?
48WS_DLL_PUBLIC bool
49fifo_string_cache_contains(fifo_string_cache_t *fcache, const char *entry);
50
51// Insert a string. The return value indicates whether the string was already
52// in the cache before this function was called. If the string was newly
53// inserted, and max_entries is > 0, and inserting the string would have caused
54// max_entries to be exceeded, the oldest inserted key is removed (FIFO order).
55WS_DLL_PUBLIC bool
56fifo_string_cache_insert(fifo_string_cache_t *fcache, const char *entry);
57
58#ifdef __cplusplus
59}
60#endif /* __cplusplus */
61
62#endif /* __FIFO_STRING_CACHE_H__ */
fifo_string_cache_t
Definition fifo_string_cache.h:24