00001 #pragma once
00002 #ifndef PROBE_CACHE_H
00003 #define PROBE_CACHE_H
00004
00005 #include <stdbool.h>
00006 #include <sexp-types.h>
00007 #include <SEAP/generic/redblack.h>
00008 #include <../../common/util.h>
00009
00010 OSCAP_HIDDEN_START;
00011
00012 DEFRBTREE(pcache, SEXP_t *id; SEXP_t *item);
00013
00014 typedef struct {
00015 TREETYPE(pcache) tree;
00016 } pcache_t;
00017
00018 pcache_t *pcache_new (void);
00019 void pcache_free (pcache_t *cache);
00020
00021 int pcache_sexp_add (pcache_t *cache, const SEXP_t *id, SEXP_t *item);
00022 int pcache_cstr_add (pcache_t *cache, const char *id, SEXP_t *item);
00023
00024 int pcache_sexp_del (pcache_t *cache, const SEXP_t *id);
00025 int pcache_cstr_del (pcache_t *cache, const char *id);
00026
00027 SEXP_t *pcache_sexp_get (pcache_t *cache, const SEXP_t *id);
00028 SEXP_t *pcache_cstr_get (pcache_t *cache, const char *id);
00029
00030
00031 typedef struct {
00032 char *iname;
00033 SEXP_t *names;
00034 uint16_t count;
00035 } ncache_item_t;
00036
00037 #define NCACHE_MAX_ITEMS 8
00038
00039 typedef struct {
00040 ncache_item_t *items[NCACHE_MAX_ITEMS];
00041 uint8_t count;
00042 pthread_rwlock_t lock;
00043 } ncache_t;
00044
00045 ncache_t *ncache_new (void);
00046 void ncache_free (ncache_t *cache);
00047
00048 int ncache_item_add (ncache_t *cache, const char *iname, SEXP_t *names, uint16_t count);
00049 int ncache_name_add (ncache_t *cache, const char *iname, SEXP_t *name);
00050
00051 #define with_ncache_rlocked(c) for (bool __rlk__ = (ncache_rlock (c) == 0 ? true : false); __rlk__; __rlk__ = ncache_runlock (c) == 0 ? false : abort())
00052 #define with_ncache_wlocked(c) for (bool __wlk__ = (ncache_wlock (c) == 0 ? true : false); __wlk__; __wlk__ = ncache_wunlock (c) == 0 ? false : abort())
00053
00054 OSCAP_HIDDEN_END;
00055
00056 #endif