📄 mfd-interface.m2c
字号:
##########################################################################/** * @internal * wrapper */static int_mfd_${context}_pre_request(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *agtreq_info, netsnmp_request_info *requests){ int rc = ${context}_pre_request(${context}_if_ctx.user_ctx); if (MFD_SUCCESS != rc) { /* * nothing we can do about it but log it */ DEBUGMSGTL(("internal:${context}","error %d from " "${context}_pre_request\n", rc)); netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc)); } return SNMP_ERR_NOERROR;} /* _mfd_${context}_pre_request *//** * @internal * wrapper */static int_mfd_${context}_post_request(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *agtreq_info, netsnmp_request_info *requests){ ${context}_rowreq_ctx *rowreq_ctx; int rc = ${context}_post_request(${context}_if_ctx.user_ctx); if (MFD_SUCCESS != rc) { /* * nothing we can do about it but log it */ DEBUGMSGTL(("internal:${context}","error %d from " "${context}_post_request\n", rc)); } /* * if there are no errors, check for and handle row creation/deletion */ rc = netsnmp_check_requests_error(requests); if ((SNMP_ERR_NOERROR == rc) && (NULL != (rowreq_ctx = netsnmp_container_table_row_extract(requests)))) { if (rowreq_ctx->rowreq_flags & MFD_ROW_CREATED) { rowreq_ctx->rowreq_flags &= ~MFD_ROW_CREATED; CONTAINER_INSERT(${context}_if_ctx.container, rowreq_ctx); } else if (rowreq_ctx->rowreq_flags & MFD_ROW_DELETED) { CONTAINER_REMOVE(${context}_if_ctx.container, rowreq_ctx); ${context}_release_rowreq_ctx(rowreq_ctx); } } return SNMP_ERR_NOERROR;} /* _mfd_${context}_post_request */##########################################################################/** * @internal * wrapper */static int_mfd_${context}_object_lookup(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *agtreq_info, netsnmp_request_info *requests){ ${context}_rowreq_ctx *rowreq_ctx = netsnmp_container_table_row_extract(requests); DEBUGMSGTL(("internal:${context}:_mfd_${context}_object_lookup","called\n")); /* * get our context from mfd * ${context}_interface_ctx *if_ctx = * (${context}_interface_ctx *)reginfo->my_reg_void; */ if(NULL == rowreq_ctx) {@ if $m2c_table_row_creation == 0@ netsnmp_request_set_error_all(requests, SNMP_ERR_NOCREATION);@ else@ int rc = MFD_SUCCESS; netsnmp_table_request_info *tblreq_info; netsnmp_index oid_idx; ${context}_mib_index mib_idx; tblreq_info = netsnmp_extract_table_info(requests); if(NULL == tblreq_info) { snmp_log(LOG_ERR, "request had no table info\n"); return MFD_ERROR; } /* * try to parse oid */ oid_idx.oids = tblreq_info->index_oid; oid_idx.len = tblreq_info->index_oid_len; rc = ${context}_index_from_oid(&oid_idx, &mib_idx); if(MFD_SUCCESS != rc) { DEBUGMSGT(("$context", "error parsing index\n")); netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc)); } else { /* * allocate new context */@ eval $m2c_tmp = ""@@ if ($m2c_data_allocate == 1) || ($m2c_data_init == 1)@@ eval $m2c_tmp = "NULL"@@ if ($m2c_data_allocate == 1) && ($m2c_data_init == 1)@@ eval $m2c_tmp = "$m2c_tmp, NULL"@@ @end@@ end@ rowreq_ctx = ${context}_allocate_rowreq_ctx($m2c_tmp); if (NULL == rowreq_ctx) return MFD_ERROR; /* msg already logged */ memcpy(&rowreq_ctx->tbl_idx, &mib_idx, sizeof(mib_idx)); /* * check indexes */ rc = _${context}_check_indexes(rowreq_ctx); if(MFD_SUCCESS != rc) { netsnmp_assert((rc == SNMP_ERR_NOCREATION) || (rc == SNMP_ERR_INCONSISTENTNAME)); netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc)); ${context}_release_rowreq_ctx(rowreq_ctx); } else { rowreq_ctx->rowreq_flags |= MFD_ROW_CREATED; netsnmp_container_table_row_insert(requests, rowreq_ctx); } }@ end@ // row creation } else { ${context}_row_prep(rowreq_ctx); } return SNMP_ERR_NOERROR;} /* _mfd_${context}_object_lookup */##########################################################################/*********************************************************************** * * GET processing * ***********************************************************************//* * @internal * Retrieve the value for a particular column */NETSNMP_STATIC_INLINE int_${context}_get_column( ${context}_rowreq_ctx *rowreq_ctx, netsnmp_variable_list *var, int column ){ int rc = SNMPERR_SUCCESS; DEBUGMSGTL(("internal:${context}:_mfd_${context}_get_column","called\n")); netsnmp_assert(NULL != rowreq_ctx); switch(column) {@ foreach $node internalindex@@ include m2c_setup_node.m2i@@ if $node.accessible == 1@ /* (INDEX) $m2c_node_summary */ case COLUMN_$node.uc: var->type = $node.type;@ if $m2c_node_needlength == 1@ /* * NOTE: val_len is in bytes, ${node}_len might not be (e.g. oids) */ if (var->val_len < (rowreq_ctx->tbl_idx.${node}_len * sizeof(rowreq_ctx->tbl_idx.${node}[0]))) { var->val.string = malloc(rowreq_ctx->tbl_idx.${node}_len * sizeof(rowreq_ctx->tbl_idx.${node}[0])); } var->val_len = rowreq_ctx->tbl_idx.${node}_len * sizeof(rowreq_ctx->tbl_idx.${node}[0]); memcpy( var->val.string, rowreq_ctx->tbl_idx.$node, var->val_len );@ else@ var->val_len = sizeof($m2c_decl); (*var->val.integer) = rowreq_ctx->tbl_idx.$node;@ end@ break;@ end@ ## accessible@ end@ ## index@ foreach $node nonindex@@ include m2c_setup_node.m2i@@ if $node.accessible == 1@ /* $m2c_node_summary */ case COLUMN_$node.uc:@ if $m2c_node_needlength == 0@ var->val_len = sizeof($m2c_decl);@ end@ var->type = $node.type;rc = ${node}_get(rowreq_ctx, $m2c_node_var_ref ); break; @ end@ # accessible@ end@ # for each column default: snmp_log(LOG_ERR,"unknown column %d in _${context}_get_column\n", column); break; } return rc;} /* _${context}_get_column */##########################################################################int_mfd_${context}_get_values(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *agtreq_info, netsnmp_request_info *requests){ ${context}_rowreq_ctx *rowreq_ctx = netsnmp_container_table_row_extract(requests); netsnmp_table_request_info * tri; u_char * old_string; void (*dataFreeHook)(void *); int rc; DEBUGMSGTL(("internal:${context}:_mfd_${context}_get_values","called\n")); netsnmp_assert(NULL != rowreq_ctx); for(;requests; requests = requests->next) { /* * save old pointer, so we can free it if replaced */ old_string = requests->requestvb->val.string; dataFreeHook = requests->requestvb->dataFreeHook; if(NULL == requests->requestvb->val.string) { requests->requestvb->val.string = requests->requestvb->buf; requests->requestvb->val_len = sizeof(requests->requestvb->buf); } else if(requests->requestvb->buf == requests->requestvb->val.string) { if(requests->requestvb->val_len != sizeof(requests->requestvb->buf)) requests->requestvb->val_len = sizeof(requests->requestvb->buf); } /* * get column data */ tri = netsnmp_extract_table_info(requests); if(NULL == tri) continue; rc = _${context}_get_column(rowreq_ctx, requests->requestvb, tri->colnum); if(rc) { if(MFD_SKIP == rc) { requests->requestvb->type = ASN_PRIV_RETRY; rc = SNMP_ERR_NOERROR; } } else if (NULL == requests->requestvb->val.string) { snmp_log(LOG_ERR,"NULL varbind data pointer!\n"); rc = SNMP_ERR_GENERR; } if(rc) netsnmp_request_set_error(requests, SNMP_VALIDATE_ERR(rc)); /* * if the buffer wasn't used previously for the old data (i.e. it * was allcoated memory) and the get routine replaced the pointer, * we need to free the previous pointer. */ if(old_string && (old_string != requests->requestvb->buf) && (requests->requestvb->val.string != old_string)) { if(dataFreeHook) (*dataFreeHook)(old_string); else free(old_string); } } /* for results */ return SNMP_ERR_NOERROR;} /* _mfd_${context}_get_values */##########################################################################/*********************************************************************** * * SET processing * ***********************************************************************/@if $m2c_table_settable == 0@/* * NOT APPLICABLE (per MIB or user setting) */@else@/*---------------------------------------------------------------------- * * SET: Syntax checks * *---------------------------------------------------------------------*//* * @internal * Check the syntax for a particular column */NETSNMP_STATIC_INLINE int_${context}_check_column( ${context}_rowreq_ctx *rowreq_ctx, netsnmp_variable_list *var, int column ){ int rc = SNMPERR_SUCCESS; DEBUGMSGTL(("internal:${context}:_${context}_check_column","called\n")); netsnmp_assert(NULL != rowreq_ctx); switch(column) {@ foreach $node internalindex@@ include m2c_setup_node.m2i@@ if $node.settable == 1@ /* (INDEX) $m2c_node_summary */ case COLUMN_$node.uc: return SNMP_ERR_NOTWRITABLE; /* can not change index of active row */ break;@ end@ ## settable@ end@ ## index@ foreach $node nonindex@@ include m2c_setup_node.m2i@@ if $node.settable == 0@@ next@@ end@ /* $m2c_node_summary */ case COLUMN_$node.uc:@ include node-varbind-validate.m2i@ if(SNMPERR_SUCCESS == rc) { rc = ${node}_check_value( rowreq_ctx, $m2c_node_var_val ); if((MFD_SUCCESS != rc) && (MFD_NOT_VALID_EVER != rc) && (MFD_NOT_VALID_NOW != rc)) { snmp_log(LOG_ERR, "bad rc %d from ${node}_check_value\n", rc); rc = SNMP_ERR_GENERR; } } break;@ end@ # for each nonindex default: /** We shouldn't get here */ rc = SNMP_ERR_GENERR; snmp_log(LOG_ERR, "unknown column %d in _${context}_check_column\n", column); } return rc;} /* _${context}_check_column */##----------------------------------------------------------------------int_mfd_${context}_check_objects(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *agtreq_info, netsnmp_request_info *requests){ ${context}_rowreq_ctx *rowreq_ctx = netsnmp_container_table_row_extract(requests); netsnmp_table_request_info * tri; int rc; DEBUGMSGTL(("internal:${context}:_mfd_${context}_check_objects","called\n")); netsnmp_assert(NULL != rowreq_ctx); for(;requests; requests = requests->next) { /* * get column number from table request info, and check that column */ tri = netsnmp_extract_table_info(requests); if(NULL == tri) continue; rc = _${context}_check_column(rowreq_ctx, requests->requestvb, tri->colnum); if(rc) { netsnmp_request_set_error(requests, SNMP_VALIDATE_ERR(rc)); break; } } /* for results */ return SNMP_ERR_NOERROR;} /* _mfd_${context}_check_objects */##----------------------------------------------------------------------@if $m2c_table_row_creation == 1@NETSNMP_STATIC_INLINE int_${context}_check_indexes(${context}_rowreq_ctx * rowreq_ctx){ int rc; DEBUGMSGTL(("internal:${context}:_${context}_check_indexes","called\n")); netsnmp_assert(NULL != rowreq_ctx);##@if $m2c_table_external_indexes != 0@ /* * check that the corresponding row exists */@ foreach $node externalindex@@ include m2c_setup_node.m2i@ /* (INDEX) $m2c_node_summary */ rc = ${context}_${node}_check_index( rowreq_ctx ); if(MFD_SUCCESS != rc) return SNMP_ERR_NOCREATION;@ end@ # for each nonindex@end@ # external index@ foreach $node internalindex@@ include m2c_setup_node.m2i@ /* (INDEX) $m2c_node_summary */ rc = ${node}_check_index( rowreq_ctx ); if(MFD_SUCCESS != rc) return SNMP_ERR_NOCREATION;@ end@ # for each internalindex /* * if individual parts look ok, check them as a whole */ return ${context}_validate_index( rowreq_ctx->${context}_reg, rowreq_ctx );} /* _${context}_check_indexes */@end@ # $m2c_table_row_creation@ if $m2c_table_dependencies == 1@/*---------------------------------------------------------------------- * * SET: check dependencies * *---------------------------------------------------------------------*//* * @internal * Check dependencies wrapper
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -