1 /* Portions of this file are subject to the following copyright(s). See 2 * the Net-SNMP's COPYING file for more details and other copyrights 3 * that may apply: 4 */ 5 /* 6 * Portions of this file are copyrighted by: 7 * Copyright (C) 2007 Apple, Inc. All rights reserved. 8 * Use is subject to license terms specified in the COPYING file 9 * distributed with the Net-SNMP package. 10 */ 11 #ifndef NETSNMP_CACHE_HANDLER_H 12 #define NETSNMP_CACHE_HANDLER_H 13 14 /* 15 * This caching helper provides a generalised (SNMP-manageable) caching 16 * mechanism. Individual SNMP table and scalar/scalar group MIB 17 * implementations can use data caching in a consistent manner, without 18 * needing to handle the generic caching details themselves. 19 */ 20 21 #include <net-snmp/library/tools.h> 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 #define CACHE_NAME "cache_info" 28 29 typedef struct netsnmp_cache_s netsnmp_cache; 30 31 typedef int (NetsnmpCacheLoad)(netsnmp_cache *, void*); 32 typedef void (NetsnmpCacheFree)(netsnmp_cache *, void*); 33 34 struct netsnmp_cache_s { 35 /** Number of handlers whose myvoid member points at this structure. */ 36 int refcnt; 37 /* 38 * For operation of the data caches 39 */ 40 int flags; 41 int enabled; 42 int valid; 43 char expired; 44 int timeout; /* Length of time the cache is valid (in s) */ 45 marker_t timestampM; /* When the cache was last loaded */ 46 u_long timer_id; /* periodic timer id */ 47 48 NetsnmpCacheLoad *load_cache; 49 NetsnmpCacheFree *free_cache; 50 51 /* 52 * void pointer for the user that created the cache. 53 * You never know when it might not come in useful .... 54 */ 55 void *magic; 56 57 /* 58 * hint from the cache helper. contains the standard 59 * handler arguments. 60 */ 61 netsnmp_handler_args *cache_hint; 62 63 /* 64 * For SNMP-management of the data caches 65 */ 66 netsnmp_cache *next, *prev; 67 oid *rootoid; 68 int rootoid_len; 69 70 }; 71 72 73 void netsnmp_cache_reqinfo_insert(netsnmp_cache* cache, 74 netsnmp_agent_request_info * reqinfo, 75 const char *name); 76 netsnmp_cache * 77 netsnmp_cache_reqinfo_extract(netsnmp_agent_request_info * reqinfo, 78 const char *name); 79 netsnmp_cache* netsnmp_extract_cache_info(netsnmp_agent_request_info *); 80 81 int netsnmp_cache_check_and_reload(netsnmp_cache * cache); 82 int netsnmp_cache_check_expired(netsnmp_cache *cache); 83 int netsnmp_cache_is_valid( netsnmp_agent_request_info *, 84 const char *name); 85 /** for backwards compat */ 86 int netsnmp_is_cache_valid( netsnmp_agent_request_info *); 87 netsnmp_mib_handler *netsnmp_get_cache_handler(int, NetsnmpCacheLoad *, 88 NetsnmpCacheFree *, 89 const oid*, int); 90 int netsnmp_register_cache_handler(netsnmp_handler_registration *reginfo, 91 int, NetsnmpCacheLoad *, 92 NetsnmpCacheFree *); 93 94 Netsnmp_Node_Handler netsnmp_cache_helper_handler; 95 96 netsnmp_cache * 97 netsnmp_cache_create(int timeout, NetsnmpCacheLoad * load_hook, 98 NetsnmpCacheFree * free_hook, 99 const oid * rootoid, int rootoid_len); 100 int netsnmp_cache_remove(netsnmp_cache *cache); 101 int netsnmp_cache_free(netsnmp_cache *cache); 102 103 netsnmp_mib_handler * 104 netsnmp_cache_handler_get(netsnmp_cache* cache); 105 void netsnmp_cache_handler_owns_cache(netsnmp_mib_handler *handler); 106 107 netsnmp_cache * netsnmp_cache_find_by_oid(const oid * rootoid, 108 int rootoid_len); 109 110 unsigned int netsnmp_cache_timer_start(netsnmp_cache *cache); 111 void netsnmp_cache_timer_stop(netsnmp_cache *cache); 112 113 /* 114 * Flags affecting cache handler operation 115 */ 116 #define NETSNMP_CACHE_DONT_INVALIDATE_ON_SET 0x0001 117 #define NETSNMP_CACHE_DONT_FREE_BEFORE_LOAD 0x0002 118 #define NETSNMP_CACHE_DONT_FREE_EXPIRED 0x0004 119 #define NETSNMP_CACHE_DONT_AUTO_RELEASE 0x0008 120 #define NETSNMP_CACHE_PRELOAD 0x0010 121 #define NETSNMP_CACHE_AUTO_RELOAD 0x0020 122 #define NETSNMP_CACHE_RESET_TIMER_ON_USE 0x0040 123 124 #define NETSNMP_CACHE_HINT_HANDLER_ARGS 0x1000 125 126 127 #ifdef __cplusplus 128 } 129 #endif 130 #endif /* NETSNMP_CACHE_HANDLER_H */ 131