📄 table_array.c
字号:
} return SNMP_ERR_NOERROR;}/** @} */#ifndef DOXYGEN_SHOULD_SKIP_THIS/********************************************************************** ********************************************************************** ********************************************************************** ********************************************************************** * * * * * * * * * EVERYTHING BELOW THIS IS PRIVATE IMPLEMENTATION DETAILS. * * * * * * * * * ********************************************************************** ********************************************************************** ********************************************************************** **********************************************************************//********************************************************************** ********************************************************************** * * * * * Structures, Utility/convenience functions * * * * * ********************************************************************** **********************************************************************//* * context info for SET requests */typedef struct set_context_s { netsnmp_agent_request_info *agtreq_info; table_container_data *tad; int status;} set_context;static voidrelease_netsnmp_request_group(netsnmp_index *g, void *v){ netsnmp_request_group_item *tmp; netsnmp_request_group *group = (netsnmp_request_group *) g; if (!g) return; while (group->list) { tmp = group->list; group->list = tmp->next; free(tmp); } free(group);}static voidrelease_netsnmp_request_groups(void *vp){ netsnmp_container *c = (netsnmp_container*)vp; CONTAINER_FOR_EACH(c, (netsnmp_container_obj_func*) release_netsnmp_request_group, NULL); CONTAINER_FREE(c);}voidbuild_new_oid(netsnmp_handler_registration *reginfo, netsnmp_table_request_info *tblreq_info, netsnmp_index *row, netsnmp_request_info *current){ oid coloid[MAX_OID_LEN]; int coloid_len; if (!tblreq_info || !reginfo || !row || !current) return; coloid_len = reginfo->rootoid_len + 2; memcpy(coloid, reginfo->rootoid, reginfo->rootoid_len * sizeof(oid)); /** table.entry */ coloid[reginfo->rootoid_len] = 1; /** table.entry.column */ coloid[reginfo->rootoid_len + 1] = tblreq_info->colnum; /** table.entry.column.index */ memcpy(&coloid[reginfo->rootoid_len + 2], row->oids, row->len * sizeof(oid)); snmp_set_var_objid(current->requestvb, coloid, reginfo->rootoid_len + 2 + row->len);}/********************************************************************** ********************************************************************** * * * * * GET procession functions * * * * * ********************************************************************** **********************************************************************/intprocess_get_requests(netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *agtreq_info, netsnmp_request_info *requests, table_container_data * tad){ int rc = SNMP_ERR_NOERROR; netsnmp_request_info *current; netsnmp_index *row = NULL; netsnmp_table_request_info *tblreq_info; netsnmp_variable_list *var; /* * Loop through each of the requests, and * try to find the appropriate row from the container. */ for (current = requests; current; current = current->next) { var = current->requestvb; DEBUGMSGTL(("table_array:get", " process_get_request oid:")); DEBUGMSGOID(("table_array:get", var->name, var->name_length)); DEBUGMSG(("table_array:get", "\n")); /* * skip anything that doesn't need processing. */ if (current->processed != 0) { DEBUGMSGTL(("table_array:get", "already processed\n")); continue; } /* * Get pointer to the table information for this request. This * information was saved by table_helper_handler. When * debugging, we double check a few assumptions. For example, * the table_helper_handler should enforce column boundaries. */ tblreq_info = netsnmp_extract_table_info(current); netsnmp_assert(tblreq_info->colnum <= tad->tblreg_info->max_column); if ((agtreq_info->mode == MODE_GETNEXT) || (agtreq_info->mode == MODE_GETBULK)) { /* * find the row */ row = netsnmp_table_index_find_next_row(tad->table, tblreq_info); if (!row) { /* * no results found. * * xxx-rks: how do we skip this entry for the next handler, * but still allow it a chance to hit another handler? */ DEBUGMSGTL(("table_array:get", "no row found\n")); netsnmp_set_request_error(agtreq_info, current, SNMP_ENDOFMIBVIEW); continue; } /* * * if data was found, make sure it has the column we want *//* xxx-rks: add suport for sparse tables */ /* * build new oid */ build_new_oid(reginfo, tblreq_info, row, current); } /** GETNEXT/GETBULK */ else { netsnmp_index index; index.oids = tblreq_info->index_oid; index.len = tblreq_info->index_oid_len; row = CONTAINER_FIND(tad->table, &index); if (!row) { DEBUGMSGTL(("table_array:get", "no row found\n")); netsnmp_set_request_error(agtreq_info, current, SNMP_NOSUCHINSTANCE); continue; } } /** GET */ /* * get the data */ rc = tad->cb->get_value(current, row, tblreq_info); } /** for ( ... requests ... ) */ return rc;}/********************************************************************** ********************************************************************** * * * * * SET procession functions * * * * * ********************************************************************** **********************************************************************/voidgroup_requests(netsnmp_agent_request_info *agtreq_info, netsnmp_request_info *requests, netsnmp_container *request_group, table_container_data * tad){ netsnmp_table_request_info *tblreq_info; netsnmp_variable_list *var; netsnmp_index *row, *tmp, index; netsnmp_request_info *current; netsnmp_request_group *g; netsnmp_request_group_item *i; for (current = requests; current; current = current->next) { var = current->requestvb; /* * skip anything that doesn't need processing. */ if (current->processed != 0) { DEBUGMSGTL(("table_array:group", "already processed\n")); continue; } /* * 3.2.1 Setup and paranoia * * * * Get pointer to the table information for this request. This * * information was saved by table_helper_handler. When * * debugging, we double check a few assumptions. For example, * * the table_helper_handler should enforce column boundaries. */ row = NULL; tblreq_info = netsnmp_extract_table_info(current); netsnmp_assert(tblreq_info->colnum <= tad->tblreg_info->max_column); /* * search for index */ index.oids = tblreq_info->index_oid; index.len = tblreq_info->index_oid_len; tmp = CONTAINER_FIND(request_group, &index); if (tmp) { DEBUGMSGTL(("table_array:group", " existing group:")); DEBUGMSGOID(("table_array:group", index.oids, index.len)); DEBUGMSG(("table_array:group", "\n")); g = (netsnmp_request_group *) tmp; i = SNMP_MALLOC_TYPEDEF(netsnmp_request_group_item); i->ri = current; i->tri = tblreq_info; i->next = g->list; g->list = i; /** xxx-rks: store map of colnum to request */ continue; } DEBUGMSGTL(("table_array:group", " new group")); DEBUGMSGOID(("table_array:group", index.oids, index.len)); DEBUGMSG(("table_array:group", "\n")); g = SNMP_MALLOC_TYPEDEF(netsnmp_request_group); i = SNMP_MALLOC_TYPEDEF(netsnmp_request_group_item); g->list = i; g->table = tad->table; i->ri = current; i->tri = tblreq_info; /** xxx-rks: store map of colnum to request */ /* * search for row. all changes are made to the original row, * later, we'll make a copy in undo_info before we start processing. */ row = g->existing_row = CONTAINER_FIND(tad->table, &index); if (!g->existing_row) { if (!tad->cb->create_row) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -