libqaeda

Unnamed repository; edit this file 'description' to name the repository.
Info | Log | Files | Refs | README | LICENSE

store.h (2467B)


      1 #ifndef LIBQAEDA_STORE_H_
      2 #define  LIBQAEDA_STORE_H_
      3 
      4 #include <stddef.h>
      5 
      6 #ifndef LQ_STORE_KEY_MAX
      7 #define LQ_STORE_KEY_MAX 256
      8 #endif
      9 
     10 #ifndef LQ_STORE_VAL_MAX
     11 #define LQ_STORE_VAL_MAX 65536
     12 #endif
     13 
     14 /// Payload type hint to control how and what a store implementation executes persistence.
     15 /// Not currently in active use.
     16 enum payload_e {
     17 	LQ_CONTENT_RAW, ///< Arbitrary data.
     18 	LQ_CONTENT_MSG, ///< Data is a message type.
     19 	LQ_CONTENT_CERT, ///< Data is a cert type.
     20 	LQ_CONTENT_KEY, ///< Data is a private key type.
     21 	LQ_CONTENT_KEY_PUBLIC, ///< Data is a public key type.
     22 };
     23 
     24 /**
     25  * \struct LQStore
     26  *
     27  * \brief Store interface, implemented by all IO backends; network, db, filesystem and memory.
     28  * 
     29  * \see lq_store_t
     30  */
     31 typedef struct lq_store_t LQStore;
     32 struct lq_store_t {
     33 	int store_typ; ///< Store type identifier, used for implementation methods to ensure that the correct version of a store structure has been passed.
     34 	void *userdata; ///< Implementation specific data required by the specific store.
     35 	int (*get)(enum payload_e typ, LQStore *store, const char *key, size_t key_len, char *value, size_t *value_len); ///< Interface for retrieving data corresponding to a key.
     36 	int (*put)(enum payload_e typ, LQStore *store, const char *key, size_t *key_len, char *value, size_t value_len); ///< Interface for storing data corresponding to a key.
     37 	int (*count)(enum payload_e typ, LQStore *store, const char *key, size_t key_len); ///< Interface for returning number of entries under a key.
     38 	void (*free)(LQStore *store); ///< Interface for cleaning up implementation specific resources in use by the store.
     39 };
     40 
     41 
     42 /**
     43  * \struct LQResolve
     44  *
     45  * \brief A linked list of stores that should be used for a specific context or action.
     46  * 
     47  * \see lq_resolve_t 
     48  * 
     49  * \todo Add a list of content types, for while store action will be taken and otherwise ignored.
     50  */
     51 typedef struct lq_resolve_t LQResolve;
     52 struct lq_resolve_t {
     53 	LQStore *store; ///< Store interface implementation.
     54 	LQResolve *next; ///< Provides access to next store implementation to store to or retrieve from. Setting to NULL stops any further action.
     55 };
     56 
     57 /**
     58  * \brief Instantiate a new store from the given path or connection spec.
     59  * 
     60  * Caller must free the store after use with lq_store_free.
     61  *
     62  * \param[in] Connection string or path.
     63  * \return A new store object, or NULL by failure.
     64  *
     65  * \see lq_store_free
     66  */
     67 LQStore* lq_store_new(const char *spec);
     68 
     69 #endif // LIBQAEDA_STORE_H_