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

📄 table_array.c

📁 snmp的源代码,已经在我的ubuntu下编译通过
💻 C
📖 第 1 页 / 共 3 页
字号:
                if(MODE_IS_SET(agtreq_info->mode))                    netsnmp_set_request_error(agtreq_info, current,                                              SNMP_ERR_NOTWRITABLE);                else                    netsnmp_set_request_error(agtreq_info, current,                                              SNMP_NOSUCHINSTANCE);                free(g);                free(i);                continue;            }            /** use undo_info temporarily */            row = g->existing_row = tad->cb->create_row(&index);            if (!row) {                /* xxx-rks : parameter to create_row to allow                 * for better error reporting. */                netsnmp_set_request_error(agtreq_info, current,                                          SNMP_ERR_GENERR);                free(g);                free(i);                continue;            }            g->row_created = 1;        }        g->index.oids = row->oids;        g->index.len = row->len;        CONTAINER_INSERT(request_group, g);    } /** for( current ... ) */}static voidprocess_set_group(netsnmp_index *o, void *c){    /* xxx-rks: should we continue processing after an error?? */    set_context           *context = (set_context *) c;    netsnmp_request_group *ag = (netsnmp_request_group *) o;    int                    rc = SNMP_ERR_NOERROR;    switch (context->agtreq_info->mode) {    case MODE_SET_RESERVE1:/** -> SET_RESERVE2 || SET_FREE */        /*         * if not a new row, save undo info         */        if (ag->row_created == 0) {            if (context->tad->cb->duplicate_row)                ag->undo_info = context->tad->cb->duplicate_row(ag->existing_row);            else                ag->undo_info = NULL;            if (NULL == ag->undo_info) {                rc = SNMP_ERR_RESOURCEUNAVAILABLE;                break;            }        }                if (context->tad->cb->set_reserve1)            context->tad->cb->set_reserve1(ag);        break;    case MODE_SET_RESERVE2:/** -> SET_ACTION || SET_FREE */        if (context->tad->cb->set_reserve2)            context->tad->cb->set_reserve2(ag);        break;    case MODE_SET_ACTION:/** -> SET_COMMIT || SET_UNDO */        if (context->tad->cb->set_action)            context->tad->cb->set_action(ag);        break;    case MODE_SET_COMMIT:/** FINAL CHANCE ON SUCCESS */        if (ag->row_created == 0) {            /*             * this is an existing row, has it been deleted?             */            if (ag->row_deleted == 1) {                DEBUGMSGT((TABLE_ARRAY_NAME, "action: deleting row\n"));                if (CONTAINER_REMOVE(ag->table, ag->existing_row) != 0) {                    rc = SNMP_ERR_COMMITFAILED;                    break;                }            }        } else if (ag->row_deleted == 0) {            /*             * new row (that hasn't been deleted) should be inserted             */            DEBUGMSGT((TABLE_ARRAY_NAME, "action: inserting row\n"));            if (CONTAINER_INSERT(ag->table, ag->existing_row) != 0) {                rc = SNMP_ERR_COMMITFAILED;                break;            }        }        if (context->tad->cb->set_commit)            context->tad->cb->set_commit(ag);        /** no more use for undo_info, so free it */        if (ag->undo_info) {            context->tad->cb->delete_row(ag->undo_info);            ag->undo_info = NULL;        }#if 0        /* XXX-rks: finish row cooperative notifications         * if the table has requested it, send cooperative notifications         * for row operations.         */        if (context->tad->notifications) {            if (ag->undo_info) {                if (!ag->existing_row)                    netsnmp_monitor_notify(EVENT_ROW_DEL);                else                    netsnmp_monitor_notify(EVENT_ROW_MOD);            }            else                netsnmp_monitor_notify(EVENT_ROW_ADD);        }#endif        if ((ag->row_created == 0) && (ag->row_deleted == 1)) {            context->tad->cb->delete_row(ag->existing_row);            ag->existing_row = NULL;        }        break;    case MODE_SET_FREE:/** FINAL CHANCE ON FAILURE */        if (context->tad->cb->set_free)            context->tad->cb->set_free(ag);        /** no more use for undo_info, so free it */        if (ag->row_created == 1) {            if (context->tad->cb->delete_row)                context->tad->cb->delete_row(ag->existing_row);            ag->existing_row = NULL;        }        else {            if (context->tad->cb->delete_row)                context->tad->cb->delete_row(ag->undo_info);            ag->undo_info = NULL;        }        break;    case MODE_SET_UNDO:/** FINAL CHANCE ON FAILURE */        /*         * status already set - don't change it now         */        if (context->tad->cb->set_undo)            context->tad->cb->set_undo(ag);        /*         * no more use for undo_info, so free it         */        if (ag->row_created == 0) {            /*             * restore old values             */            context->tad->cb->row_copy(ag->existing_row, ag->undo_info);            context->tad->cb->delete_row(ag->undo_info);            ag->undo_info = NULL;        }        else {            context->tad->cb->delete_row(ag->existing_row);            ag->existing_row = NULL;        }        break;    default:        snmp_log(LOG_ERR, "unknown mode processing SET for "                 "netsnmp_table_array_helper_handler\n");        rc = SNMP_ERR_GENERR;        break;    }        if (rc)        netsnmp_set_request_error(context->agtreq_info,                                  ag->list->ri, rc);                                               }intprocess_set_requests(netsnmp_agent_request_info *agtreq_info,                     netsnmp_request_info *requests,                     table_container_data * tad, char *handler_name){    set_context         context;    netsnmp_container  *request_group;    /*     * create and save structure for set info     */    request_group = (netsnmp_container*) netsnmp_agent_get_list_data        (agtreq_info, handler_name);    if (request_group == NULL) {        netsnmp_data_list *tmp;        request_group = netsnmp_container_find("request_group:"                                               "table_container");        request_group->compare = netsnmp_compare_netsnmp_index;        request_group->ncompare = netsnmp_ncompare_netsnmp_index;        DEBUGMSGTL(("table_array", "Grouping requests by oid\n"));        tmp = netsnmp_create_data_list(handler_name,                                       request_group,                                       release_netsnmp_request_groups);        netsnmp_agent_add_list_data(agtreq_info, tmp);        /*         * group requests.         */        group_requests(agtreq_info, requests, request_group, tad);    }    /*     * process each group one at a time     */    context.agtreq_info = agtreq_info;    context.tad = tad;    context.status = SNMP_ERR_NOERROR;    CONTAINER_FOR_EACH(request_group,                       (netsnmp_container_obj_func*)process_set_group,                       &context);    return context.status;}/********************************************************************** ********************************************************************** *                                                                    * *                                                                    * * netsnmp_table_array_helper_handler()                               * *                                                                    * *                                                                    * ********************************************************************** **********************************************************************/intnetsnmp_table_array_helper_handler(netsnmp_mib_handler *handler,                                   netsnmp_handler_registration *reginfo,                                   netsnmp_agent_request_info *agtreq_info,                                   netsnmp_request_info *requests){    /*     * First off, get our pointer from the handler. This     * lets us get to the table registration information we     * saved in get_table_array_handler(), as well as the     * container where the actual table data is stored.     */    int             rc = SNMP_ERR_NOERROR;    table_container_data *tad = (table_container_data *)handler->myvoid;    if (agtreq_info->mode < 0 || agtreq_info->mode > 5) {        DEBUGMSGTL(("table_array", "Mode %d, Got request:\n",                    agtreq_info->mode));    } else {        DEBUGMSGTL(("table_array", "Mode %s, Got request:\n",                    mode_name[agtreq_info->mode]));    }    if (MODE_IS_SET(agtreq_info->mode)) {        /*         * netsnmp_mutex_lock(&tad->lock);         */        rc = process_set_requests(agtreq_info, requests,                                  tad, handler->handler_name);        /*         * netsnmp_mutex_unlock(&tad->lock);         */    } else        rc = process_get_requests(reginfo, agtreq_info, requests, tad);    if (rc != SNMP_ERR_NOERROR) {        DEBUGMSGTL(("table_array", "processing returned rc %d\n", rc));    }        /*     * Now we've done our processing. If there is another handler below us,     * call them.     */    if (handler->next) {        rc = netsnmp_call_next_handler(handler, reginfo, agtreq_info, requests);        if (rc != SNMP_ERR_NOERROR) {            DEBUGMSGTL(("table_array", "next handler returned rc %d\n", rc));        }    }        return rc;}#endif /** DOXYGEN_SHOULD_SKIP_THIS */

⌨️ 快捷键说明

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