⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 table_data.c

📁 开发snmp的开发包有两个开放的SNMP开发库
💻 C
📖 第 1 页 / 共 3 页
字号:
        return NULL;}/** inserts a newly created table_data row into a request */NETSNMP_INLINE voidnetsnmp_insert_table_row(netsnmp_request_info *request,                         netsnmp_table_row *row){    netsnmp_request_info       *req;    netsnmp_table_request_info *table_info = NULL;    netsnmp_variable_list      *this_index = NULL;    netsnmp_variable_list      *that_index = NULL;    oid      base_oid[] = {0, 0};	/* Make sure index OIDs are legal! */    oid      this_oid[MAX_OID_LEN];    oid      that_oid[MAX_OID_LEN];    size_t   this_oid_len, that_oid_len;    if (!request)        return;    /*     * We'll add the new row information to any request     * structure with the same index values as the request     * passed in (which includes that one!).     *     * So construct an OID based on these index values.     */    table_info = netsnmp_extract_table_info(request);    this_index = table_info->indexes;    build_oid_noalloc(this_oid, MAX_OID_LEN, &this_oid_len,                      base_oid, 2, this_index);    /*     * We need to look through the whole of the request list     * (as received by the current handler), as there's no     * guarantee that this routine will be called by the first     * varbind that refers to this row.     *   In particular, a RowStatus controlled row creation     * may easily occur later in the variable list.     *     * So first, we rewind to the head of the list....     */    for (req=request; req->prev; req=req->prev)        ;    /*     * ... and then start looking for matching indexes     * (by constructing OIDs from these index values)     */    for (; req; req=req->next) {        table_info = netsnmp_extract_table_info(req);        that_index = table_info->indexes;        build_oid_noalloc(that_oid, MAX_OID_LEN, &that_oid_len,                          base_oid, 2, that_index);              /*         * This request has the same index values,         * so add the newly-created row information.         */        if (snmp_oid_compare(this_oid, this_oid_len,                             that_oid, that_oid_len) == 0) {            netsnmp_request_add_list_data(req,                netsnmp_create_data_list(TABLE_DATA_ROW, row, NULL));        }    }}/* builds a result given a row, a varbind to set and the data */intnetsnmp_table_data_build_result(netsnmp_handler_registration *reginfo,                                netsnmp_agent_request_info *reqinfo,                                netsnmp_request_info *request,                                netsnmp_table_row *row,                                int column,                                u_char type,                                u_char * result_data,                                size_t result_data_len){    oid             build_space[MAX_OID_LEN];    if (!reginfo || !reqinfo || !request)        return SNMPERR_GENERR;    if (reqinfo->mode == MODE_GETNEXT || reqinfo->mode == MODE_GETBULK) {        /*         * only need to do this for getnext type cases where oid is changing          */        memcpy(build_space, reginfo->rootoid,   /* registered oid */               reginfo->rootoid_len * sizeof(oid));        build_space[reginfo->rootoid_len] = 1;  /* entry */        build_space[reginfo->rootoid_len + 1] = column; /* column */        memcpy(build_space + reginfo->rootoid_len + 2,  /* index data */               row->index_oid, row->index_oid_len * sizeof(oid));        snmp_set_var_objid(request->requestvb, build_space,                           reginfo->rootoid_len + 2 + row->index_oid_len);    }    snmp_set_var_typed_value(request->requestvb, type,                             result_data, result_data_len);    return SNMPERR_SUCCESS;     /* WWWXXX: check for bounds */}/* ================================== * * Table Data API: Row operations *     (table-independent rows) * * ================================== *//** returns the first row in the table */netsnmp_table_row *netsnmp_table_data_get_first_row(netsnmp_table_data *table){    if (!table)        return NULL;    return table->first_row;}/** returns the next row in the table */netsnmp_table_row *netsnmp_table_data_get_next_row(netsnmp_table_data *table,                                netsnmp_table_row  *row){    if (!row)        return NULL;    return row->next;}/** finds the data in "datalist" stored at "indexes" */netsnmp_table_row *netsnmp_table_data_get(netsnmp_table_data *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_table_data_get_from_oid(table, searchfor,                                           searchfor_len);}/** finds the data in "datalist" stored at the searchfor oid */netsnmp_table_row *netsnmp_table_data_get_from_oid(netsnmp_table_data *table,                                oid * searchfor, size_t searchfor_len){    netsnmp_table_row *row;    if (!table)        return NULL;    for (row = table->first_row; row != NULL; row = row->next) {        if (row->index_oid &&            snmp_oid_compare(searchfor, searchfor_len,                             row->index_oid, row->index_oid_len) == 0)            return row;    }    return NULL;}intnetsnmp_table_data_num_rows(netsnmp_table_data *table){    int i=0;    netsnmp_table_row *row;    if (!table)        return 0;    for (row = table->first_row; row; row = row->next) {        i++;    }    return i;}    /* =====================================     * Generic API - mostly renamed wrappers     * ===================================== */netsnmp_table_row *netsnmp_table_data_row_first(netsnmp_table_data *table){    return netsnmp_table_data_get_first_row(table);}netsnmp_table_row *netsnmp_table_data_row_get(  netsnmp_table_data *table,                             netsnmp_table_row  *row){    if (!table || !row)        return NULL;    return netsnmp_table_data_get_from_oid(table, row->index_oid,                                                  row->index_oid_len);}netsnmp_table_row *netsnmp_table_data_row_next( netsnmp_table_data *table,                             netsnmp_table_row  *row){    return netsnmp_table_data_get_next_row(table, row);}netsnmp_table_row *netsnmp_table_data_row_get_byoid( netsnmp_table_data *table,                                  oid *instance, size_t len){    return netsnmp_table_data_get_from_oid(table, instance, len);}netsnmp_table_row *netsnmp_table_data_row_next_byoid(netsnmp_table_data *table,                                  oid *instance, size_t len){    netsnmp_table_row *row;    if (!table || !instance)        return NULL;        for (row = table->first_row; row; row = row->next) {        if (snmp_oid_compare(row->index_oid,                             row->index_oid_len,                             instance, len) > 0)            return row;    }    return NULL;}netsnmp_table_row *netsnmp_table_data_row_get_byidx( netsnmp_table_data    *table,                                  netsnmp_variable_list *indexes){    return netsnmp_table_data_get(table, indexes);}netsnmp_table_row *netsnmp_table_data_row_next_byidx(netsnmp_table_data    *table,                                  netsnmp_variable_list *indexes){    oid    instance[MAX_OID_LEN];    size_t len    = MAX_OID_LEN;    if (!table || !indexes)        return NULL;    build_oid_noalloc(instance, MAX_OID_LEN, &len, NULL, 0, indexes);    return netsnmp_table_data_row_next_byoid(table, instance, len);}intnetsnmp_table_data_row_count(netsnmp_table_data *table){    return netsnmp_table_data_num_rows(table);}/* ================================== * * Table Data API: Row operations *     (table-specific rows) * * ================================== */void *netsnmp_table_data_entry_first(netsnmp_table_data *table){    netsnmp_table_row *row =        netsnmp_table_data_get_first_row(table);    return (row ? row->data : NULL );}void *netsnmp_table_data_entry_get(  netsnmp_table_data *table,                               netsnmp_table_row  *row){    return (row ? row->data : NULL );}void *netsnmp_table_data_entry_next( netsnmp_table_data *table,                               netsnmp_table_row  *row){    row =        netsnmp_table_data_row_next(table, row);    return (row ? row->data : NULL );}void *netsnmp_table_data_entry_get_byidx( netsnmp_table_data    *table,                                    netsnmp_variable_list *indexes){    netsnmp_table_row *row =        netsnmp_table_data_row_get_byidx(table, indexes);    return (row ? row->data : NULL );}void *netsnmp_table_data_entry_next_byidx(netsnmp_table_data    *table,                                    netsnmp_variable_list *indexes){    netsnmp_table_row *row =        netsnmp_table_data_row_next_byidx(table, indexes);    return (row ? row->data : NULL );}void *netsnmp_table_data_entry_get_byoid( netsnmp_table_data *table,                                    oid *instance, size_t len){    netsnmp_table_row *row =        netsnmp_table_data_row_get_byoid(table, instance, len);    return (row ? row->data : NULL );}void *netsnmp_table_data_entry_next_byoid(netsnmp_table_data *table,                                    oid *instance, size_t len){    netsnmp_table_row *row =        netsnmp_table_data_row_next_byoid(table, instance, len);    return (row ? row->data : NULL );}    /* =====================================     * Generic API - mostly renamed wrappers     * ===================================== *//* ================================== * * Table Data API: Index operations * * ================================== *//** @}  */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -