📄 sm.h
字号:
} mod_ret_t;/** module chain types */typedef enum { chain_SESS_START, /**< session start, load per-session data */ chain_SESS_END, /**< session ended, save & free per-session data */ chain_IN_SESS, /**< packet from an active session */ chain_IN_ROUTER, /**< packet from the router */ chain_OUT_SESS, /**< packet to an active session */ chain_OUT_ROUTER, /**< packet to a router */ chain_PKT_SM, /**< packet for the sm itself */ chain_PKT_USER, /**< packet for a user */ chain_PKT_ROUTER, /**< packet from the router (special purpose) */ chain_USER_LOAD, /**< user loaded, load per-user data */ chain_USER_CREATE, /**< user creation, generate and save per-user data */ chain_USER_DELETE /**< user deletion, delete saved per-user data */} mod_chain_t;typedef struct module_st *module_t;typedef struct mod_instance_st *mod_instance_t;/** module manager date */struct mm_st { sm_t sm; /**< sm context */ xht modules; /**< pointers to module data (key is module name) */ int nindex; /**< counter for module instance sequence (!!! should be local to mm_new) */ /** sess-start chain */ mod_instance_t *sess_start; int nsess_start; /** sess-end chain */ mod_instance_t *sess_end; int nsess_end; /** in-sess chain */ mod_instance_t *in_sess; int nin_sess; /** in-router chain */ mod_instance_t *in_router; int nin_router; /** out-sess chain */ mod_instance_t *out_sess; int nout_sess; /** out-router chain */ mod_instance_t *out_router; int nout_router; /** pkt-sm chain */ mod_instance_t *pkt_sm; int npkt_sm; /** pkt-user chain */ mod_instance_t *pkt_user; int npkt_user; /** pkt-router chain */ mod_instance_t *pkt_router; int npkt_router; /** user-load chain */ mod_instance_t *user_load; int nuser_load; /** user-create chain */ mod_instance_t *user_create; int nuser_create; /** user-delete chain */ mod_instance_t *user_delete; int nuser_delete;};/** data for a single module */struct module_st { mm_t mm; /**< module manager */ char *name; /**< name of module */ int index; /**< module index. this is the index into user->module_data and sess->module_data where the module can store its own per-user/per-session data */ int init; /**< number of times the module intialiser has been called */ void *private; /**< module private data */ int (*sess_start)(mod_instance_t mi, sess_t sess); /**< sess-start handler */ void (*sess_end)(mod_instance_t mi, sess_t sess); /**< sess-end handler */ mod_ret_t (*in_sess)(mod_instance_t mi, sess_t sess, pkt_t pkt); /**< in-sess handler */ mod_ret_t (*in_router)(mod_instance_t mi, pkt_t pkt); /**< in-router handler */ mod_ret_t (*out_sess)(mod_instance_t mi, sess_t sess, pkt_t pkt); /**< out-sess handler */ mod_ret_t (*out_router)(mod_instance_t mi, pkt_t pkt); /**< out-router handler */ mod_ret_t (*pkt_sm)(mod_instance_t mi, pkt_t pkt); /**< pkt-sm handler */ mod_ret_t (*pkt_user)(mod_instance_t mi, user_t user, pkt_t pkt); /**< pkt-user handler */ mod_ret_t (*pkt_router)(mod_instance_t mi, pkt_t pkt); /**< pkt-router handler */ int (*user_load)(mod_instance_t mi, user_t user); /**< user-load handler */ int (*user_create)(mod_instance_t mi, jid_t jid); /**< user-create handler */ void (*user_delete)(mod_instance_t mi, jid_t jid); /**< user-delete handler */ void (*free)(module_t mod); /**< called when module is freed */};/** single instance of a module in a chain */struct mod_instance_st { sm_t sm; /**< sm context */ module_t mod; /**< module that this is an instance of */ int seq; /**< number of this instance */ mod_chain_t chain; /**< chain this instance is in */ char *arg; /**< option arg that this instance was started with */};/** allocate a module manager instance, and loads the modules */mm_t mm_new(sm_t sm);/** free a mm instance */void mm_free(mm_t mm);/** fire sess-start chain */int mm_sess_start(mm_t mm, sess_t sess);/** fire sess-end chain */void mm_sess_end(mm_t mm, sess_t sess);/** fire in-sess chain */mod_ret_t mm_in_sess(mm_t mm, sess_t sess, pkt_t pkt);/** fire in-router chain */mod_ret_t mm_in_router(mm_t mm, pkt_t pkt);/** fire out-sess chain */mod_ret_t mm_out_sess(mm_t mm, sess_t sess, pkt_t pkt);/** fire out-router chain */mod_ret_t mm_out_router(mm_t mm, pkt_t pkt);/** fire pkt-sm chain */mod_ret_t mm_pkt_sm(mm_t mm, pkt_t pkt);/** fire pkt-user chain */mod_ret_t mm_pkt_user(mm_t mm, user_t user, pkt_t pkt);/** fire pkt-router chain */mod_ret_t mm_pkt_router(mm_t mm, pkt_t pkt);/** fire user-load chain */int mm_user_load(mm_t mm, user_t user);/** fire user-create chain */int mm_user_create(mm_t mm, jid_t jid);/** fire user-delete chain */void mm_user_delete(mm_t mm, jid_t jid);/** type for the module init function */typedef int (*module_init_fn)(mod_instance_t);/* object sets *//** object types */typedef enum { os_type_BOOLEAN, /**< boolean (0 or 1) */ os_type_INTEGER, /**< integer */ os_type_STRING, /**< string */ os_type_NAD, /**< XML */ os_type_UNKNOWN /**< unknown */} os_type_t;/** a single tuple (value) within an object */ typedef struct os_field_st { char *key; /**< field name */ void *val; /**< field value */ os_type_t type; /**< field type */} *os_field_t;typedef struct os_st *os_t;typedef struct os_object_st *os_object_t;/** object set (ie group of several objects) */struct os_st { pool p; /**< pool the objects are allocated from */ os_object_t head; /**< first object in the list */ os_object_t tail; /**< last object in the list */ int count; /**< number of objects in this set */ os_object_t iter; /**< pointer for iteration */};/** an object */struct os_object_st { /** object set this object is part of */ os_t os; /** fields (key is field name) */ xht hash; os_object_t next; /**< next object in the list */ os_object_t prev; /**< previous object in the list */};/** create a new object set */os_t os_new(void);/** free an object set */void os_free(os_t os);/** number of objects in a set */int os_count(os_t os);/** set iterator to first object (1 = exists, 0 = doesn't exist) */int os_iter_first(os_t os);/** set iterator to next object (1 = exists, 0 = doesn't exist) */int os_iter_next(os_t os);/** get the object currently under the iterator */os_object_t os_iter_object(os_t os);/** create a new object in this set */os_object_t os_object_new(os_t os);/** free an object (remove it from its set) */void os_object_free(os_object_t o);/** add a field to the object */void os_object_put(os_object_t o, const char *key, const void *val, os_type_t type);/** get a field from the object of type type (result in val), ret 0 == not found */int os_object_get(os_t os, os_object_t o, const char *key, void **val, os_type_t type, os_type_t *ot);/** set field iterator to first field (1 = exists, 0 = doesn't exist) */int os_object_iter_first(os_object_t o);/** set field iterator to next field (1 = exists, 0 = doesn't exist) */int os_object_iter_next(os_object_t o);/** extract field values from field currently under the iterator */void os_object_iter_get(os_object_t o, char **key, void **val, os_type_t *type);/* storage manager *//** storage driver return values */typedef enum { st_SUCCESS, /**< call completed successful */ st_FAILED, /**< call failed (driver internal error) */ st_NOTFOUND, /**< no matching objects were found */ st_NOTIMPL /**< call not implemented */} st_ret_t;typedef struct st_driver_st *st_driver_t;/** storage manager data */struct storage_st { sm_t sm; /**< sm context */ xht drivers; /**< pointers to drivers (key is driver name) */ xht types; /**< pointers to drivers (key is type name) */ st_driver_t default_drv; /**< default driver (used when there is no module explicitly registered for a type) */};/** data for a single storage driver */struct st_driver_st { storage_t st; /**< storage manager context */ char *name; /**< name of driver */ void *private; /**< driver private data */ /** called to find out if this driver can handle a particular type */ st_ret_t (*add_type)(st_driver_t drv, const char *type); /** put handler */ st_ret_t (*put)(st_driver_t drv, const char *type, const char *owner, os_t os); /** get handler */ st_ret_t (*get)(st_driver_t drv, const char *type, const char *owner, const char *filter, os_t *os); /** delete handler */ st_ret_t (*delete)(st_driver_t drv, const char *type, const char *owner, const char *filter); /** replace handler */ st_ret_t (*replace)(st_driver_t drv, const char *type, const char *owner, const char *filter, os_t os); /** called when driver is freed */ void (*free)(st_driver_t drv);};/** allocate a storage manager instance */storage_t storage_new(sm_t sm);/** free a storage manager instance */void storage_free(storage_t st);/** associate this data type with this driver */st_ret_t storage_add_type(storage_t st, const char *driver, const char *type);/** store objects in this set */st_ret_t storage_put(storage_t st, const char *type, const char *owner, os_t os);/** get objects matching this filter */st_ret_t storage_get(storage_t st, const char *type, const char *owner, const char *filter, os_t *os);/** delete objects matching this filter */st_ret_t storage_delete(storage_t st, const char *type, const char *owner, const char *filter);/** replace objects matching this filter with objects in this set (atomic delete + get) */st_ret_t storage_replace(storage_t st, const char *type, const char *owner, const char *filter, os_t os);/** type for the driver init function */typedef st_ret_t (*st_driver_init_fn)(st_driver_t);/** storage filter types */typedef enum { st_filter_type_PAIR, /**< key=value pair */ st_filter_type_AND, /**< and operator */ st_filter_type_OR, /**< or operator */ st_filter_type_NOT /**< not operator */} st_filter_type_t;typedef struct st_filter_st *st_filter_t;/** filter abstraction */struct st_filter_st { pool p; /**< pool that filter is allocated from */ st_filter_type_t type; /**< type of this filter */ char *key; /**< key for PAIR filters */ char *val; /**< value for PAIR filters */ st_filter_t sub; /**< sub-filter for operator filters */ st_filter_t next; /**< next filter in a group */};/** create a filter abstraction from a LDAP-like filter string */st_filter_t storage_filter(const char *filter);/** see if the object matches the filter */int storage_match(st_filter_t filter, os_object_t o, os_t os);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -