📄 table_dataset.c
字号:
snmp_log(LOG_WARNING," ignoring '%s'\n", pos); *pos = '\0'; } /* * check for duplicate table */ tables = (data_set_tables *) netsnmp_get_list_data(auto_tables, line); if (NULL != tables) { config_pwarn("duplicate table definition"); return; } /* * parse oid and find tree structure */ if (!snmp_parse_oid(line, table_name, &table_name_length)) { config_pwarn ("can't instatiate table since I can't parse the table name"); return; } if(NULL == (tp = get_tree(table_name, table_name_length, get_tree_head()))) { config_pwarn("can't instatiate table since " "I can't find mib information about it"); return; } if (NULL == (tp = tp->child_list) || NULL == tp->child_list) { config_pwarn("can't instatiate table since it doesn't appear to be " "a proper table (no children)"); return; } /* * check for augments indexes */ if (NULL != tp->augments) { if (!snmp_parse_oid(tp->augments, table_name, &table_name_length)) { config_pwarn("I can't parse the augment tabel name"); snmp_log(LOG_WARNING, " can't parse %s\n", tp->augments); return; } if(NULL == (tp = get_tree(table_name, table_name_length, get_tree_head()))) { config_pwarn("can't instatiate table since " "I can't find mib information about augment table"); snmp_log(LOG_WARNING, " table %s not found in tree\n", tp->augments); return; } table_set = netsnmp_create_table_data_set(line); /* * loop through indexes and add types */ for (index = tp->indexes; index; index = index->next) { if (!snmp_parse_oid(index->ilabel, name, &name_length) || (NULL == (indexnode = get_tree(name, name_length, get_tree_head())))) { config_pwarn("can't instatiate table since " "I don't know anything about one index"); snmp_log(LOG_WARNING, " index %s not found in tree\n", index->ilabel); return; /* xxx mem leak */ } type = mib_to_asn_type(indexnode->type); if (type == (u_char) - 1) { config_pwarn("unknown index type"); return; /* xxx mem leak */ } if (index->isimplied) /* if implied, mark it as such */ type |= ASN_PRIVATE; DEBUGMSGTL(("table_set_add_row", "adding default index of type %d\n", type)); netsnmp_table_dataset_add_index(table_set, type); } } else table_set = netsnmp_create_table_data_set(line); /* * loop through indexes and add types */ for (index = tp->indexes; index; index = index->next) { if (!snmp_parse_oid(index->ilabel, name, &name_length) || (NULL == (indexnode = get_tree(name, name_length, get_tree_head())))) { config_pwarn("can't instatiate table since " "I don't know anything about one index"); snmp_log(LOG_WARNING, " index %s not found in tree\n", index->ilabel); return; /* xxx mem leak */ } type = mib_to_asn_type(indexnode->type); if (type == (u_char) - 1) { config_pwarn("unknown index type"); return; /* xxx mem leak */ } if (index->isimplied) /* if implied, mark it as such */ type |= ASN_PRIVATE; DEBUGMSGTL(("table_set_add_row", "adding default index of type %d\n", type)); netsnmp_table_dataset_add_index(table_set, type); } /* * loop through children and add each column info */ for (tp = tp->child_list; tp; tp = tp->next_peer) { int canwrite = 0; type = mib_to_asn_type(tp->type); if (type == (u_char) - 1) { config_pwarn("unknown column type"); return; /* xxx mem leak */ } DEBUGMSGTL(("table_set_add_row", "adding column %s(%d) of type %d (access %d)\n", tp->label, tp->subid, type, tp->access)); switch (tp->access) { case MIB_ACCESS_CREATE: table_set->allow_creation = 1; case MIB_ACCESS_READWRITE: case MIB_ACCESS_WRITEONLY: canwrite = 1; case MIB_ACCESS_READONLY: DEBUGMSGTL(("table_set_add_row", "adding column %d of type %d\n", tp->subid, type)); netsnmp_table_set_add_default_row(table_set, tp->subid, type, canwrite, NULL, 0); mincol = SNMP_MIN(mincol, tp->subid); maxcol = SNMP_MAX(maxcol, tp->subid); break; case MIB_ACCESS_NOACCESS: case MIB_ACCESS_NOTIFY: break; default: config_pwarn("unknown column access type"); break; } } /* * register the table */ netsnmp_register_table_data_set(netsnmp_create_handler_registration (line, NULL, table_name, table_name_length, HANDLER_CAN_RWRITE), table_set, NULL); netsnmp_register_auto_data_table(table_set, NULL);}#endif /* DISABLE_MIB_LOADING *//** @internal */voidnetsnmp_config_parse_add_row(const char *token, char *line){ char buf[SNMP_MAXBUF_MEDIUM]; char tname[SNMP_MAXBUF_MEDIUM]; size_t buf_size; int rc; data_set_tables *tables; netsnmp_variable_list *vb; /* containing only types */ netsnmp_table_row *row; netsnmp_table_data_set_storage *dr; line = copy_nword(line, tname, SNMP_MAXBUF_MEDIUM); tables = (data_set_tables *) netsnmp_get_list_data(auto_tables, tname); if (!tables) { config_pwarn("Unknown table trying to add a row"); return; } /* * do the indexes first */ row = netsnmp_create_table_data_row(); for (vb = tables->table_set->table->indexes_template; vb; vb = vb->next_variable) { if (!line) { config_pwarn("missing an index value"); return; } DEBUGMSGTL(("table_set_add_row", "adding index of type %d\n", vb->type)); buf_size = SNMP_MAXBUF_MEDIUM; line = read_config_read_memory(vb->type, line, buf, &buf_size); netsnmp_table_row_add_index(row, vb->type, buf, buf_size); } /* * then do the data */ for (dr = tables->table_set->default_row; dr; dr = dr->next) { if (!line) { config_pwarn("missing a data value. " "All columns must be specified."); snmp_log(LOG_WARNING," can't find value for column %d\n", dr->column - 1); return; } buf_size = SNMP_MAXBUF_MEDIUM; line = read_config_read_memory(dr->type, line, buf, &buf_size); DEBUGMSGTL(("table_set_add_row", "adding data at column %d of type %d\n", dr->column, dr->type)); netsnmp_set_row_column(row, dr->column, dr->type, buf, buf_size); if (dr->writable) netsnmp_mark_row_column_writable(row, dr->column, 1); /* make writable */ } rc = netsnmp_table_data_add_row(tables->table_set->table, row); if (SNMPERR_SUCCESS != rc) { config_pwarn("error adding table row"); }}/** adds an index to the table. Call this repeatly for each index. */NETSNMP_INLINE voidnetsnmp_table_dataset_add_index(netsnmp_table_data_set *table, u_char type){ if (!table) return; netsnmp_table_data_add_index(table->table, type);}/** adds a new row to a dataset table */NETSNMP_INLINE voidnetsnmp_table_dataset_add_row(netsnmp_table_data_set *table, netsnmp_table_row *row){ if (!table) return; netsnmp_table_data_add_row(table->table, row);}/** adds a new row to a dataset table */NETSNMP_INLINE voidnetsnmp_table_dataset_replace_row(netsnmp_table_data_set *table, netsnmp_table_row *origrow, netsnmp_table_row *newrow){ if (!table) return; netsnmp_table_data_replace_row(table->table, origrow, newrow);}/** deletes a single dataset table data. * returns the (possibly still good) next pointer of the deleted data object. */NETSNMP_INLINE netsnmp_table_data_set_storage *netsnmp_table_dataset_delete_data(netsnmp_table_data_set_storage *data){ netsnmp_table_data_set_storage *nextPtr = NULL; if (data) { nextPtr = data->next; SNMP_FREE(data->data.voidp); } SNMP_FREE(data); return nextPtr;}/** deletes all the data from this node and beyond in the linked list */NETSNMP_INLINE voidnetsnmp_table_dataset_delete_all_data(netsnmp_table_data_set_storage *data){ while (data) { data = netsnmp_table_dataset_delete_data(data); }}/** deletes all the data from this node and beyond in the linked list */NETSNMP_INLINE voidnetsnmp_table_dataset_delete_row(netsnmp_table_row *row){ netsnmp_table_data_set_storage *data; if (!row) return; data = netsnmp_table_data_delete_row(row); netsnmp_table_dataset_delete_all_data(data);}/** removes a row from the table, but doesn't delete/free anything */NETSNMP_INLINE voidnetsnmp_table_dataset_remove_row(netsnmp_table_data_set *table, netsnmp_table_row *row){ if (!table) return; netsnmp_table_data_remove_and_delete_row(table->table, row);}/** removes a row from the table and then deletes it (and all it's data) */NETSNMP_INLINE voidnetsnmp_table_dataset_remove_and_delete_row(netsnmp_table_data_set *table, netsnmp_table_row *row){ netsnmp_table_data_set_storage *data; if (!table) return; data = (netsnmp_table_data_set_storage *) netsnmp_table_data_remove_and_delete_row(table->table, row); netsnmp_table_dataset_delete_all_data(data);}/** adds multiple data column definitions to each row. Functionally, * this is a wrapper around calling netsnmp_table_set_add_default_row * repeatedly for you. */void#if HAVE_STDARG_Hnetsnmp_table_set_multi_add_default_row(netsnmp_table_data_set *tset, ...)#elsenetsnmp_table_set_multi_add_default_row(va_dcl ) va_dcl#endif{ va_list debugargs; unsigned int column; int type, writable; void *data; size_t data_len;#if HAVE_STDARG_H va_start(debugargs, tset);#else netsnmp_table_data_set *tset; va_start(debugargs); tset = va_arg(debugargs, netsnmp_table_data_set *);#endif while ((column = va_arg(debugargs, unsigned int)) != 0) { type = va_arg(debugargs, int); writable = va_arg(debugargs, int); data = va_arg(debugargs, void *); data_len = va_arg(debugargs, size_t); netsnmp_table_set_add_default_row(tset, column, type, writable, data, data_len); } va_end(debugargs);}/** adds multiple indexes to a table_dataset helper object. * To end the list, use a 0 after the list of ASN index types. */void#if HAVE_STDARG_Hnetsnmp_table_set_add_indexes(netsnmp_table_data_set *tset, ...)#elsenetsnmp_table_set_add_indexes(va_alist) va_dcl#endif{ va_list debugargs; int type;#if HAVE_STDARG_H va_start(debugargs, tset);#else netsnmp_table_data_set *tset; va_start(debugargs); tset = va_arg(debugargs, netsnmp_table_data_set *);#endif while ((type = va_arg(debugargs, int)) != 0) { netsnmp_table_dataset_add_index(tset, (u_char)type); } va_end(debugargs);}intnetsnmp_table_set_num_rows(netsnmp_table_data_set *table){ if (!table) return 0; return netsnmp_table_data_num_rows(table->table);}/* * @} */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -