1 /* 2 * table_iterator.h 3 */ 4 #ifndef _TABLE_DATA_SET_HANDLER_H_ 5 #define _TABLE_DATA_SET_HANDLER_H_ 6 7 #ifdef __cplusplus 8 extern "C" { 9 #endif 10 11 /* 12 * This helper is designed to completely automate the task of storing 13 * tables of data within the agent that are not tied to external data 14 * sources (like the kernel, hardware, or other processes, etc). IE, 15 * all rows within a table are expected to be added manually using 16 * functions found below. 17 */ 18 19 void netsnmp_init_table_dataset(void); 20 21 #define TABLE_DATA_SET_NAME "netsnmp_table_data_set" 22 23 /* 24 * return SNMP_ERR_NOERROR or some SNMP specific protocol error id 25 */ 26 typedef int (Netsnmp_Value_Change_Ok) (char *old_value, 27 size_t old_value_len, 28 char *new_value, 29 size_t new_value_len, 30 void *mydata); 31 32 /* 33 * stored within a given row 34 */ 35 typedef struct netsnmp_table_data_set_storage_s { 36 unsigned int column; 37 38 /* 39 * info about it? 40 */ 41 char writable; 42 Netsnmp_Value_Change_Ok *change_ok_fn; 43 void *my_change_data; 44 45 /* 46 * data actually stored 47 */ 48 u_char type; 49 union { /* value of variable */ 50 void *voidp; 51 long *integer; 52 u_char *string; 53 oid *objid; 54 u_char *bitstring; 55 struct counter64 *counter64; 56 #ifdef NETSNMP_WITH_OPAQUE_SPECIAL_TYPES 57 float *floatVal; 58 double *doubleVal; 59 #endif /* NETSNMP_WITH_OPAQUE_SPECIAL_TYPES */ 60 } data; 61 u_long data_len; 62 63 struct netsnmp_table_data_set_storage_s *next; 64 } netsnmp_table_data_set_storage; 65 66 typedef struct netsnmp_table_data_set_s { 67 netsnmp_table_data *table; 68 netsnmp_table_data_set_storage *default_row; 69 int allow_creation; /* set to 1 to allow creation of new rows */ 70 unsigned int rowstatus_column; 71 } netsnmp_table_data_set; 72 73 74 /* ============================ 75 * DataSet API: Table maintenance 76 * ============================ */ 77 78 netsnmp_table_data_set *netsnmp_create_table_data_set(const char *); 79 netsnmp_table_row *netsnmp_table_data_set_clone_row( netsnmp_table_row *row); 80 void netsnmp_table_dataset_delete_all_data( 81 netsnmp_table_data_set_storage *data); 82 void netsnmp_table_dataset_delete_row(netsnmp_table_row *row); 83 84 void netsnmp_table_dataset_add_row(netsnmp_table_data_set 85 *table, 86 netsnmp_table_row *row); 87 void 88 netsnmp_table_dataset_replace_row(netsnmp_table_data_set *table, 89 netsnmp_table_row *origrow, 90 netsnmp_table_row *newrow); 91 void netsnmp_table_dataset_remove_row(netsnmp_table_data_set 92 *table, 93 netsnmp_table_row *row); 94 void 95 netsnmp_table_dataset_remove_and_delete_row(netsnmp_table_data_set 96 *table, 97 netsnmp_table_row *row); 98 void netsnmp_delete_table_data_set(netsnmp_table_data_set *table_set); 99 100 /* ============================ 101 * DataSet API: Default row operations 102 * ============================ */ 103 104 /* 105 * to set, add column, type, (writable) ? 1 : 0 106 */ 107 /* 108 * default value, if not NULL, is the default value used in row 109 * creation. It is copied into the storage template (free your 110 * calling argument). 111 */ 112 int netsnmp_table_set_add_default_row(netsnmp_table_data_set *, 113 unsigned int, int, int, 114 void *default_value, 115 size_t default_value_len); 116 void netsnmp_table_set_multi_add_default_row(netsnmp_table_data_set *, 117 ...); 118 119 120 /* ============================ 121 * DataSet API: MIB maintenance 122 * ============================ */ 123 124 netsnmp_mib_handler 125 *netsnmp_get_table_data_set_handler(netsnmp_table_data_set *); 126 Netsnmp_Node_Handler netsnmp_table_data_set_helper_handler; 127 int netsnmp_register_table_data_set(netsnmp_handler_registration *, 128 netsnmp_table_data_set *, 129 netsnmp_table_registration_info *); 130 netsnmp_table_data_set 131 *netsnmp_extract_table_data_set(netsnmp_request_info *request); 132 netsnmp_table_data_set_storage 133 *netsnmp_extract_table_data_set_column(netsnmp_request_info *, 134 unsigned int); 135 netsnmp_oid_stash_node ** 136 netsnmp_table_dataset_get_or_create_stash(netsnmp_agent_request_info *ari, 137 netsnmp_table_data_set *tds, 138 netsnmp_table_request_info *tri); 139 netsnmp_table_row * 140 netsnmp_table_dataset_get_newrow(netsnmp_request_info *request, 141 netsnmp_agent_request_info *reqinfo, 142 int rootoid_len, 143 netsnmp_table_data_set *datatable, 144 netsnmp_table_request_info *table_info); 145 146 147 /* ============================ 148 * DataSet API: Config-based operations 149 * ============================ */ 150 151 void netsnmp_register_auto_data_table(netsnmp_table_data_set *table_set, 152 char *registration_name); 153 void netsnmp_unregister_auto_data_table(netsnmp_table_data_set *table_set, 154 char *registration_name); 155 void netsnmp_config_parse_table_set(const char *token, char *line); 156 void netsnmp_config_parse_add_row( const char *token, char *line); 157 158 159 /* ============================ 160 * DataSet API: Row operations 161 * ============================ */ 162 163 netsnmp_table_row *netsnmp_table_data_set_get_first_row(netsnmp_table_data_set *table); 164 netsnmp_table_row *netsnmp_table_data_set_get_next_row( netsnmp_table_data_set *table, 165 netsnmp_table_row *row); 166 int netsnmp_table_set_num_rows(netsnmp_table_data_set *table); 167 168 169 /* ============================ 170 * DataSet API: Column operations 171 * ============================ */ 172 173 netsnmp_table_data_set_storage 174 *netsnmp_table_data_set_find_column(netsnmp_table_data_set_storage *, 175 unsigned int); 176 int netsnmp_mark_row_column_writable( netsnmp_table_row *row, 177 int column, int writable); 178 int netsnmp_set_row_column( netsnmp_table_row *, 179 unsigned int, int, const void *, 180 size_t); 181 182 /* ============================ 183 * DataSet API: Index operations 184 * ============================ */ 185 186 void netsnmp_table_dataset_add_index(netsnmp_table_data_set 187 *table, u_char type); 188 void netsnmp_table_set_add_indexes(netsnmp_table_data_set *tset, ...); 189 190 #ifdef __cplusplus 191 } 192 #endif 193 194 #define netsnmp_table_row_add_column(row, type, value, value_len) snmp_varlist_add_variable(&row->indexes, NULL, 0, type, (u_char *) value, value_len) 195 196 #endif /* _TABLE_DATA_SET_HANDLER_H_ */ 197