📄 container.h
字号:
/** first data element is a 'char *' */ int netsnmp_compare_cstring(const void * lhs, const void * rhs); int netsnmp_ncompare_cstring(const void * lhs, const void * rhs); /** useful for octet strings */ int netsnmp_compare_mem(const char * lhs, size_t lhs_len, const char * rhs, size_t rhs_len); /** for_each callback to call free on data item */ void netsnmp_container_simple_free(void *data, void *context);/* * container optionflags */#define CONTAINER_KEY_ALLOW_DUPLICATES 0x00000001#define CONTAINER_KEY_UNSORTED 0x00000002#define CONTAINER_SET_OPTIONS(x,o,rc) do { \ if (NULL==(x)->options) \ rc = -1; \ else \ rc = (x)->options(x, 1, o); \ } while(0)#define CONTAINER_CHECK_OPTION(x,o,rc) do { \ if (NULL==(x)->options) \ rc = -1; \ else \ rc = (x)->options(x,0, o); \ } while(0) /* * useful macros (x = container; k = key; c = user context) */#define CONTAINER_FIRST(x) (x)->find_next(x,NULL)#define CONTAINER_FIND(x,k) (x)->find(x,k)#define CONTAINER_NEXT(x,k) (x)->find_next(x,k)/* * GET_SUBSET returns allocated memory (netsnmp_void_array). User is responsible * for releasing this memory (free(array->array), free(array)). * DO NOT FREE ELEMENTS OF THE ARRAY, because they are the same pointers * stored in the container. */#define CONTAINER_GET_SUBSET(x,k) (x)->get_subset(x,k)#define CONTAINER_SIZE(x) (x)->get_size(x)#define CONTAINER_ITERATOR(x) (x)->get_iterator(x)#define CONTAINER_COMPARE(x,l,r) (x)->compare(l,r)#define CONTAINER_FOR_EACH(x,f,c) (x)->for_each(x,f,c) /* * if you are getting multiple definitions of these three * inline functions, you most likely have optimizations turned off. * Either turn them back on, or define NETSNMP_NO_INLINE */#ifndef NETSNMP_USE_INLINE /* default is to inline */ /* * insert k into all containers */ int CONTAINER_INSERT(netsnmp_container *x, const void *k); /* * remove k from all containers */ int CONTAINER_REMOVE(netsnmp_container *x, const void *k); /* * clear all containers. When clearing the *first* container, and * *only* the first container, call the function f for each item. * After calling this function, all containers should be empty. */ void CONTAINER_CLEAR(netsnmp_container *x, netsnmp_container_obj_func *f, void *c); /* * free all containers */ int CONTAINER_FREE(netsnmp_container *x);#else /*------------------------------------------------------------------ * These functions should EXACTLY match the function version in * container.c. If you change one, change them both. */ NETSNMP_STATIC_INLINE /* gcc docs recommend static w/inline */ int CONTAINER_INSERT(netsnmp_container *x, const void *k) { int rc2, rc = 0; /** start at first container */ while(x->prev) x = x->prev; for(; x; x = x->next) { if ((NULL != x->insert_filter) && (x->insert_filter(x,k) == 1)) continue; rc2 = x->insert(x,k); if (rc2) { snmp_log(LOG_ERR,"error on subcontainer '%s' insert (%d)\n", x->container_name ? x->container_name : "", rc2); rc = rc2; } } return rc; } /*------------------------------------------------------------------ * These functions should EXACTLY match the function version in * container.c. If you change one, change them both. */ NETSNMP_STATIC_INLINE /* gcc docs recommend static w/inline */ int CONTAINER_REMOVE(netsnmp_container *x, const void *k) { int rc2, rc = 0; /** start at last container */ while(x->next) x = x->next; while(x) { rc2 = x->remove(x,k); /** ignore remove errors if there is a filter in place */ if ((rc2) && (NULL == x->insert_filter)) { snmp_log(LOG_ERR,"error on subcontainer remove (%d)\n", rc2); rc = rc2; } x = x->prev; } return rc; } /*------------------------------------------------------------------ * These functions should EXACTLY match the function version in * container.c. If you change one, change them both. */ NETSNMP_STATIC_INLINE /* gcc docs recommend static w/inline */ int CONTAINER_FREE(netsnmp_container *x) { int rc2, rc = 0; /** start at last container */ while(x->next) x = x->next; while(x) { netsnmp_container *tmp; tmp = x->prev; if (NULL != x->container_name) SNMP_FREE(x->container_name); rc2 = x->cfree(x); if (rc2) { snmp_log(LOG_ERR,"error on subcontainer cfree (%d)\n", rc2); rc = rc2; } x = tmp; } return rc; } /*------------------------------------------------------------------ * These functions should EXACTLY match the function version in * container.c. If you change one, change them both. */ /* * clear all containers. When clearing the *first* container, and * *only* the first container, call the function f for each item. * After calling this function, all containers should be empty. */ NETSNMP_STATIC_INLINE /* gcc docs recommend static w/inline */ void CONTAINER_CLEAR(netsnmp_container *x, netsnmp_container_obj_func *f, void *c) { /** start at last container */ while(x->next) x = x->next; while(x->prev) { x->clear(x, NULL, c); x = x->prev; } x->clear(x, f, c); } /*------------------------------------------------------------------ * These functions should EXACTLY match the function version in * container.c. If you change one, change them both. */ /* * Find a sub-container with the given name */ NETSNMP_STATIC_INLINE /* gcc docs recommend static w/inline */ netsnmp_container *SUBCONTAINER_FIND(netsnmp_container *x, const char* name) { if ((NULL == x) || (NULL == name)) return NULL; /** start at first container */ while(x->prev) x = x->prev; while(x) { if ((NULL != x->container_name) && (0 == strcmp(name,x->container_name))) break; x = x->next; } return x; }#endif /************************************************************************* * * container iterator * *************************************************************************/ /* * function returning an int for an operation on an iterator */ typedef int (netsnmp_iterator_rc)(struct netsnmp_iterator_s *); /* * function returning an oject for an operation on an iterator */ typedef void * (netsnmp_iterator_rtn)(struct netsnmp_iterator_s *); /* * iterator structure */ typedef struct netsnmp_iterator_s { netsnmp_container *container; /* * sync from container when iterator created. used to invalidate * the iterator when the container changes. */ u_long sync; /* * reset iterator position to beginning of container. */ netsnmp_iterator_rc *reset; /* * release iterator and memory it uses */ netsnmp_iterator_rc *release; /* * first, last and current DO NOT advance the iterator */ netsnmp_iterator_rtn *first; netsnmp_iterator_rtn *curr; netsnmp_iterator_rtn *last; netsnmp_iterator_rtn *next; } netsnmp_iterator;#define ITERATOR_FIRST(x) x->first(x)#define ITERATOR_NEXT(x) x->next(x)#define ITERATOR_LAST(x) x->last(x)#define ITERATOR_RELEASE(x) do { x->release(x); x = NULL; } while(0) #ifdef __cplusplus}#endif#endif /** NETSNMP_CONTAINER_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -