📄 table_tdata.c
字号:
/** Creates a tdata handler and returns it */netsnmp_mib_handler *netsnmp_get_tdata_handler(netsnmp_tdata *table){ netsnmp_mib_handler *ret = NULL; if (!table) { snmp_log(LOG_INFO, "netsnmp_get_tdata_handler(NULL) called\n"); return NULL; } ret = netsnmp_create_handler(TABLE_TDATA_NAME, _netsnmp_tdata_helper_handler); if (ret) { ret->flags |= MIB_HANDLER_AUTO_NEXT; ret->myvoid = (void *) table; } return ret;}/* * The helper handler that takes care of passing a specific row of * data down to the lower handler(s). The table_container helper * has already taken care of identifying the appropriate row of the * table (and converting GETNEXT requests into an equivalent GET request) * So all we need to do here is make sure that the row is accessible * using tdata-style retrieval techniques as well. */int_netsnmp_tdata_helper_handler(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests){ netsnmp_tdata *table = (netsnmp_tdata *) handler->myvoid; netsnmp_request_info *request; netsnmp_table_request_info *table_info; netsnmp_tdata_row *row; switch ( reqinfo->mode ) { case MODE_GET: case MODE_SET_RESERVE1: for (request = requests; request; request = request->next) { if (request->processed) continue; table_info = netsnmp_extract_table_info(request); if (!table_info) continue; /* ack */ row = netsnmp_container_table_row_extract( request ); netsnmp_request_add_list_data(request, netsnmp_create_data_list( TABLE_TDATA_TABLE, table, NULL)); netsnmp_request_add_list_data(request, netsnmp_create_data_list( TABLE_TDATA_ROW, row, NULL)); } } /* next handler called automatically - 'AUTO_NEXT' */ return SNMP_ERR_NOERROR;}/** registers a tdata-based MIB table */intnetsnmp_tdata_register(netsnmp_handler_registration *reginfo, netsnmp_tdata *table, netsnmp_table_registration_info *table_info){ netsnmp_inject_handler(reginfo, netsnmp_get_tdata_handler(table)); return netsnmp_container_table_register(reginfo, table_info, table->container, TABLE_CONTAINER_KEY_NETSNMP_INDEX);}/** extracts the tdata table from the request structure */netsnmp_tdata *netsnmp_tdata_extract_table(netsnmp_request_info *request){ return (netsnmp_tdata *) netsnmp_request_get_list_data(request, TABLE_TDATA_TABLE);}/** extracts the tdata container from the request structure */netsnmp_container *netsnmp_tdata_extract_container(netsnmp_request_info *request){ netsnmp_tdata *tdata = netsnmp_request_get_list_data(request, TABLE_TDATA_TABLE); return ( tdata ? tdata->container : NULL );}/** extracts the tdata row being accessed from the request structure */netsnmp_tdata_row *netsnmp_tdata_extract_row(netsnmp_request_info *request){ return (netsnmp_tdata_row *) netsnmp_container_table_row_extract(request);}/** extracts the (table-specific) entry being accessed from the * request structure */void *netsnmp_tdata_extract_entry(netsnmp_request_info *request){ netsnmp_tdata_row *row = (netsnmp_tdata_row *) netsnmp_tdata_extract_row(request); if (row) return row->data; else return NULL;}/** inserts a newly created tdata row into a request */NETSNMP_INLINE voidnetsnmp_insert_tdata_row(netsnmp_request_info *request, netsnmp_tdata_row *row){ netsnmp_container_table_row_insert(request, (netsnmp_index *)row);}/* ================================== * * Generic API: Row operations * * ================================== *//** returns the (table-specific) entry data for a given row */void *netsnmp_tdata_row_entry( netsnmp_tdata_row *row ){ if (row) return row->data; else return NULL;}/** returns the first row in the table */netsnmp_tdata_row *netsnmp_tdata_row_first(netsnmp_tdata *table){ return (netsnmp_tdata_row *)CONTAINER_FIRST( table->container );}/** finds a row in the 'tdata' table given another row */netsnmp_tdata_row *netsnmp_tdata_row_get( netsnmp_tdata *table, netsnmp_tdata_row *row){ return CONTAINER_FIND( table->container, row );}/** returns the next row in the table */netsnmp_tdata_row *netsnmp_tdata_row_next( netsnmp_tdata *table, netsnmp_tdata_row *row){ return (netsnmp_tdata_row *)CONTAINER_NEXT( table->container, row );}/** finds a row in the 'tdata' table given the index values */netsnmp_tdata_row *netsnmp_tdata_row_get_byidx(netsnmp_tdata *table, netsnmp_variable_list *indexes){ oid searchfor[ MAX_OID_LEN]; size_t searchfor_len = MAX_OID_LEN; build_oid_noalloc(searchfor, MAX_OID_LEN, &searchfor_len, NULL, 0, indexes); return netsnmp_tdata_row_get_byoid(table, searchfor, searchfor_len);}/** finds a row in the 'tdata' table given the index OID */netsnmp_tdata_row *netsnmp_tdata_row_get_byoid(netsnmp_tdata *table, oid * searchfor, size_t searchfor_len){ netsnmp_index index; if (!table) return NULL; index.oids = searchfor; index.len = searchfor_len; return CONTAINER_FIND( table->container, &index );}/** finds the lexically next row in the 'tdata' table given the index values */netsnmp_tdata_row *netsnmp_tdata_row_next_byidx(netsnmp_tdata *table, netsnmp_variable_list *indexes){ oid searchfor[ MAX_OID_LEN]; size_t searchfor_len = MAX_OID_LEN; build_oid_noalloc(searchfor, MAX_OID_LEN, &searchfor_len, NULL, 0, indexes); return netsnmp_tdata_row_next_byoid(table, searchfor, searchfor_len);}/** finds the lexically next row in the 'tdata' table given the index OID */netsnmp_tdata_row *netsnmp_tdata_row_next_byoid(netsnmp_tdata *table, oid * searchfor, size_t searchfor_len){ netsnmp_index index; if (!table) return NULL; index.oids = searchfor; index.len = searchfor_len; return CONTAINER_NEXT( table->container, &index );}intnetsnmp_tdata_row_count(netsnmp_tdata *table){ if (!table) return 0; return CONTAINER_SIZE( table->container );}/* ================================== * * Generic API: Index operations on a 'tdata' table * * ================================== *//** compare a row with the given index values */intnetsnmp_tdata_compare_idx(netsnmp_tdata_row *row, netsnmp_variable_list *indexes){ oid searchfor[ MAX_OID_LEN]; size_t searchfor_len = MAX_OID_LEN; build_oid_noalloc(searchfor, MAX_OID_LEN, &searchfor_len, NULL, 0, indexes); return netsnmp_tdata_compare_oid(row, searchfor, searchfor_len);}/** compare a row with the given index OID */intnetsnmp_tdata_compare_oid(netsnmp_tdata_row *row, oid * compareto, size_t compareto_len){ netsnmp_index *index = (netsnmp_index *)row; return snmp_oid_compare( index->oids, index->len, compareto, compareto_len);}intnetsnmp_tdata_compare_subtree_idx(netsnmp_tdata_row *row, netsnmp_variable_list *indexes){ oid searchfor[ MAX_OID_LEN]; size_t searchfor_len = MAX_OID_LEN; build_oid_noalloc(searchfor, MAX_OID_LEN, &searchfor_len, NULL, 0, indexes); return netsnmp_tdata_compare_subtree_oid(row, searchfor, searchfor_len);}intnetsnmp_tdata_compare_subtree_oid(netsnmp_tdata_row *row, oid * compareto, size_t compareto_len){ netsnmp_index *index = (netsnmp_index *)row; return snmp_oidtree_compare( index->oids, index->len, compareto, compareto_len);}/** @} */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -