Home | History | Annotate | Download | only in src
      1 /* Copyright (C) 2005 Red Hat, Inc. */
      2 
      3 #ifndef _SEMANAGE_DATABASE_LLIST_INTERNAL_H_
      4 #define _SEMANAGE_DATABASE_LLIST_INTERNAL_H_
      5 
      6 #include "database.h"
      7 #include "handle.h"
      8 
      9 /* Representation of the database once loaded in memory */
     10 typedef struct cache_entry {
     11 	record_t *data;
     12 	struct cache_entry *prev;
     13 	struct cache_entry *next;
     14 } cache_entry_t;
     15 
     16 /* LLIST dbase */
     17 typedef struct dbase_llist {
     18 
     19 	/* Method tables */
     20 	record_table_t *rtable;
     21 	dbase_table_t *dtable;
     22 
     23 	/* In-memory representation (cache) */
     24 	cache_entry_t *cache;
     25 	cache_entry_t *cache_tail;
     26 
     27 	unsigned int cache_sz;
     28 	int cache_serial;
     29 	int modified;
     30 } dbase_llist_t;
     31 
     32 /* Helpers for internal use only */
     33 
     34 static inline void dbase_llist_cache_init(dbase_llist_t * dbase)
     35 {
     36 
     37 	dbase->cache = NULL;
     38 	dbase->cache_tail = NULL;
     39 	dbase->cache_sz = 0;
     40 	dbase->cache_serial = -1;
     41 	dbase->modified = 0;
     42 }
     43 
     44 static inline void dbase_llist_init(dbase_llist_t * dbase,
     45 				    record_table_t * rtable,
     46 				    dbase_table_t * dtable)
     47 {
     48 
     49 	dbase->rtable = rtable;
     50 	dbase->dtable = dtable;
     51 	dbase_llist_cache_init(dbase);
     52 }
     53 
     54 extern int dbase_llist_cache_prepend(semanage_handle_t * handle,
     55 				     dbase_llist_t * dbase,
     56 				     const record_t * data);
     57 
     58 extern int dbase_llist_needs_resync(semanage_handle_t * handle,
     59 				    dbase_llist_t * dbase);
     60 
     61 extern int dbase_llist_set_serial(semanage_handle_t * handle,
     62 				  dbase_llist_t * dbase);
     63 
     64 static inline void dbase_llist_set_modified(dbase_llist_t * dbase, int status)
     65 {
     66 	dbase->modified = status;
     67 }
     68 
     69 /* LLIST - cache/transactions */
     70 extern void dbase_llist_drop_cache(dbase_llist_t * dbase);
     71 
     72 static inline int dbase_llist_is_modified(dbase_llist_t * dbase)
     73 {
     74 
     75 	return dbase->modified;
     76 }
     77 
     78 /* LLIST - polymorphism */
     79 static inline record_table_t *dbase_llist_get_rtable(dbase_llist_t * dbase)
     80 {
     81 	return dbase->rtable;
     82 }
     83 
     84 /* LLIST - dbase API */
     85 extern int dbase_llist_exists(semanage_handle_t * handle,
     86 			      dbase_llist_t * dbase,
     87 			      const record_key_t * key, int *response);
     88 
     89 extern int dbase_llist_add(semanage_handle_t * handle,
     90 			   dbase_llist_t * dbase,
     91 			   const record_key_t * key, const record_t * data);
     92 
     93 extern int dbase_llist_set(semanage_handle_t * handle,
     94 			   dbase_llist_t * dbase,
     95 			   const record_key_t * key, const record_t * data);
     96 
     97 extern int dbase_llist_modify(semanage_handle_t * handle,
     98 			      dbase_llist_t * dbase,
     99 			      const record_key_t * key, const record_t * data);
    100 
    101 extern int dbase_llist_count(semanage_handle_t * handle,
    102 			     dbase_llist_t * dbase, unsigned int *response);
    103 
    104 extern int dbase_llist_query(semanage_handle_t * handle,
    105 			     dbase_llist_t * dbase,
    106 			     const record_key_t * key, record_t ** response);
    107 
    108 extern int dbase_llist_iterate(semanage_handle_t * handle,
    109 			       dbase_llist_t * dbase,
    110 			       int (*fn) (const record_t * record,
    111 					  void *fn_arg), void *arg);
    112 
    113 extern int dbase_llist_del(semanage_handle_t * handle,
    114 			   dbase_llist_t * dbase, const record_key_t * key);
    115 
    116 extern int dbase_llist_clear(semanage_handle_t * handle, dbase_llist_t * dbase);
    117 
    118 extern int dbase_llist_list(semanage_handle_t * handle,
    119 			    dbase_llist_t * dbase,
    120 			    record_t *** records, unsigned int *count);
    121 
    122 #endif
    123