syslog-ng source
cache.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002-2013 Balabit
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * As an additional exemption you are allowed to compile & link against the
19  * OpenSSL libraries as published by the OpenSSL project. See the file
20  * COPYING for details.
21  *
22  */
23 #ifndef CACHE_H_INCLUDED
24 #define CACHE_H_INCLUDED
25 
26 #include "syslog-ng.h"
27 
28 typedef struct _CacheResolver CacheResolver;
29 typedef struct _Cache Cache;
30 
32 {
33  gpointer (*resolve_elem)(CacheResolver *self, const gchar *key);
34 
35  /* NOTE: free_elem lacks a self argument as we are using it as a
36  * GDestroyNotify callback for hashtables. Lacking a better solution
37  * (e.g. curried functions) this means that we can't pass self here.
38  */
39  void (*free_elem)(gpointer value);
40  void (*free_fn)(CacheResolver *self);
41 };
42 
43 static inline gpointer
44 cache_resolver_resolve_elem(CacheResolver *self, const gchar *key)
45 {
46  if (self->resolve_elem)
47  {
48  return self->resolve_elem(self, key);
49  }
50  return NULL;
51 }
52 
53 static inline void
54 cache_resolver_free(CacheResolver *self)
55 {
56  if (self->free_fn)
57  {
58  self->free_fn(self);
59  }
60  g_free(self);
61 }
62 
63 void cache_populate(Cache *self, const gchar *key, const gchar *value);
64 void *cache_resolve(Cache *self, const gchar *key);
65 gpointer cache_lookup(Cache *self, const gchar *key);
66 void cache_clear(Cache *self);
67 
68 Cache *cache_new(CacheResolver *resolver);
69 void cache_free(Cache *self);
70 
71 #endif
gpointer cache_lookup(Cache *self, const gchar *key)
Definition: cache.c:38
Cache * cache_new(CacheResolver *resolver)
Definition: cache.c:70
void cache_populate(Cache *self, const gchar *key, const gchar *value)
Definition: cache.c:54
void * cache_resolve(Cache *self, const gchar *key)
Definition: cache.c:32
void cache_free(Cache *self)
Definition: cache.c:80
void cache_clear(Cache *self)
Definition: cache.c:63
#define self
Definition: rcptid.c:38
Definition: cache.h:32
void(* free_fn)(CacheResolver *self)
Definition: cache.h:40
gpointer(* resolve_elem)(CacheResolver *self, const gchar *key)
Definition: cache.h:33
void(* free_elem)(gpointer value)
Definition: cache.h:39
Definition: cache.c:26
GString * value
Definition: test_decode.c:28
struct tm key
Definition: cache.c:63