📄 mfd-interface.m2c
字号:
@ if ($m2c_node_needlength == 0) && ("$node.perltype" eq "BITS")@ /* * check for length of bits string */ var->val_len = 0; while( 0 != mask ) { ++idx; if ( *(($m2c_decl *) var->val.string) & mask ) var->val_len = idx; mask = mask >> 8; } }@ end@ break; @ end@ # accessible@ end@ # for each column default: if ($context.uc_MIN_COL <= column && column <= $context.uc_MAX_COL) { DEBUGMSGTL(("internal:${context}:_mfd_${context}_get_column", "assume column %d is reserved\n", column)); rc = MFD_SKIP; } else { 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); @if $m2c_table_sparse == 1@ DEBUGMSGTL(("9:${context}:_mfd_${context}_get_values", "exists %p\n", (void*)rowreq_ctx->column_exists_flags));@end@ 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 = SNMP_NOSUCHINSTANCE; 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 */##----------------------------------------------------------------------@if ($m2c_table_row_creation == 1) || ($m2c_table_persistent == 1)@NETSNMP_STATIC_INLINE int_${context}_check_indexes(${context}_rowreq_ctx * rowreq_ctx){ int rc = SNMPERR_SUCCESS; DEBUGMSGTL(("internal:${context}:_${context}_check_indexes","called\n")); netsnmp_assert(NULL != rowreq_ctx);##@if $m2c_table_external_indexes != 0@ /* * check that the corresponding EXTERNAL 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 */@ eval $m2c_nv_val = "rowreq_ctx->tbl_idx.$node"@@ eval $m2c_nv_len = "rowreq_ctx->tbl_idx.${node}_len"@@ eval $m2c_nv_str = "rowreq_ctx->tbl_idx.$node"@@ include node-validate.m2i@ if (MFD_SUCCESS != rc) return rc; 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( ${context}_if_ctx.user_ctx, rowreq_ctx );} /* _${context}_check_indexes */@end@ # $m2c_table_row_creation##########################################################################/*********************************************************************** * * SET processing * ***********************************************************************/@if $m2c_table_settable == 0@/* * SET PROCESSING 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 for %d\n", column)); netsnmp_assert(NULL != rowreq_ctx); switch(column) {@ eval $m2c_nvv_item = "${m2c_context_item}tbl_idx."@@ foreach $node internalindex@@ include m2c_setup_node.m2i@ /* (INDEX) $m2c_node_summary */ case COLUMN_$node.uc: rc = SNMP_ERR_NOTWRITABLE; /* can not change index of active row */ break;@ end@ ## index@ eval $m2c_nvv_item = "$m2c_data_item"@@ foreach $node nonindex@@ include m2c_setup_node.m2i@@ if $node.settable == 0@ /* $m2c_node_summary */ case COLUMN_$node.uc: rc = SNMP_ERR_NOTWRITABLE; break;@ next@@ end@ /* $m2c_node_summary */ case COLUMN_$node.uc:@ include node-varbind-validate.m2i@ if(SNMPERR_SUCCESS != rc) { DEBUGMSGTL(("${context}:_${context}_check_column:$node", "varbind validation failed (eg bad type or size)\n")); } else { 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_dependencies == 1@/*---------------------------------------------------------------------- * * SET: check dependencies * *---------------------------------------------------------------------*//* * @internal * Check dependencies wrapper */static int_mfd_${context}_check_dependencies(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *agtreq_info, netsnmp_request_info *requests){ int rc; ${context}_rowreq_ctx *rowreq_ctx = netsnmp_container_table_row_extract(requests); DEBUGMSGTL(("internal:${context}:_mfd_${context}_check_dependencies","called\n")); netsnmp_assert(NULL != rowreq_ctx); rc = ${context}_check_dependencies(rowreq_ctx); if(rc){ DEBUGMSGTL(("${context}:mfd","error %d from " "${context}_check_dependencies\n", rc)); netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc)); } return SNMP_ERR_NOERROR;} /* _mfd_${context}_check_dependencies */@end@ // dependencies/*---------------------------------------------------------------------- * * SET: Undo setup * *---------------------------------------------------------------------*//* * @internal * Set the value for a particular column */NETSNMP_STATIC_INLINE int_${context}_undo_setup_column( ${context}_rowreq_ctx *rowreq_ctx, int column ){ int rc = SNMPERR_SUCCESS; DEBUGMSGTL(("internal:${context}:_${context}_undo_setup_column", "called for %d\n", column)); netsnmp_assert(NULL != rowreq_ctx); switch(column) {@ foreach $node nonindex@@ include m2c_setup_node.m2i@@ if $node.settable == 1@ /* $m2c_node_summary */ case COLUMN_$node.uc: rowreq_ctx->column_set_flags |= COLUMN_$node.uc_FLAG; rc = ${node}_undo_setup(rowreq_ctx ); break; @ end@ # settable@ end@ # for each column default: snmp_log(LOG_ERR,"unknown column %d in _${context}_undo_setup_column\n", column); break; } return rc;} /* _${context}_undo_setup_column */##----------------------------------------------------------------------/** * @internal * undo setup */int_mfd_${context}_undo_setup(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *agtreq_info, netsnmp_request_info *requests){ int rc; ${context}_rowreq_ctx *rowreq_ctx = netsnmp_container_table_row_extract(requests); DEBUGMSGTL(("internal:${context}:_mfd_${context}_undo_setup","called\n")); netsnmp_assert(NULL != rowreq_ctx);@if $m2c_undo_embed == 0@ /* * allocate undo context */ rowreq_ctx->undo = ${context}_allocate_data(); if(NULL == rowreq_ctx->undo) { /** msg already logged */ netsnmp_request_set_error_all(requests, SNMP_ERR_RESOURCEUNAVAILABLE); return SNMP_ERR_NOERROR; }@end@ /* * row undo setup */ rowreq_ctx->column_set_flags = 0; rc = ${context}_undo_setup(rowreq_ctx); if (MFD_SUCCESS != rc) { DEBUGMSGTL(("${context}:mfd","error %d from " "${context}_undo_setup\n", rc)); netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc)); } else { /* * column undo setup */ netsnmp_table_request_info * tri; for(;requests; requests = requests->next) { /* * set column data */ tri = netsnmp_extract_table_info(requests); if(NULL == tri) continue; rc = _${context}_undo_setup_column(rowreq_ctx, tri->colnum); if(MFD_SUCCESS != rc) { DEBUGMSGTL(("${context}:mfd","error %d from " "${context}_undo_setup_column\n", rc)); netsnmp_set_request_error(agtreq_info, requests, SNMP_VALIDATE_ERR(rc)); } } /* for results */ } return SNMP_ERR_NOERROR;} /* _mfd_${context}_undo_setup *//** * @internal * undo setup */int_mfd_${context}_undo_cleanup(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); int rc; DEBUGMSGTL(("internal:${context}:_mfd_${context}_undo_cleanup","called\n"));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -