📄 mfd-interface.m2c
字号:
void_${context}_shutdown_interface(${context}_registration * reg_ptr){ /* * shutdown the container */ _${context}_container_shutdown(&${context}_if_ctx);}void${context}_valid_columns_set(netsnmp_column_info *vc){ ${context}_if_ctx.tbl_info.valid_columns = vc;} /* ${context}_valid_columns_set */@include generic-table-indexes-to-oid.m2i@@include generic-table-indexes-from-oid.m2i@##########################################################################@ if (($m2c_data_allocate == 1) || ($m2c_undo_embed == 0)) && ("$m2c_data_context" eq "generated")@@ eval $m2c_gda_todo_suppress = 1@ # no todo comments@ include generic-data-allocate.m2i@ # resets suppress@ end@########################################################################/* ********************************************************************* * @internal * allocate resources for a ${context}_rowreq_ctx */${context}_rowreq_ctx *@if $m2c_data_allocate == 1@@ eval $m2c_tmp = "${context}_data *data"@@ if $m2c_data_init == 1@@ eval $m2c_tmp = "$m2c_tmp, void *user_init_ctx"@@ end@@elsif $m2c_data_init == 1@@ eval $m2c_tmp = "void *user_init_ctx"@@else@@ eval $m2c_tmp = "void"@@end@${context}_allocate_rowreq_ctx($m2c_tmp){ ${context}_rowreq_ctx *rowreq_ctx = SNMP_MALLOC_TYPEDEF(${context}_rowreq_ctx); DEBUGMSGTL(("internal:${context}:${context}_allocate_rowreq_ctx","called\n")); if(NULL == rowreq_ctx) { snmp_log(LOG_ERR,"Couldn't allocate memory for a " "${context}_rowreq_ctx.\n"); return NULL; }@if $m2c_data_allocate == 1@ else { if(NULL != data) { /* * track if we got data from user */ rowreq_ctx->rowreq_flags |= MFD_ROW_DATA_FROM_USER; rowreq_ctx->data = data; } else if (NULL == (rowreq_ctx->data = ${context}_allocate_data())) { SNMP_FREE(rowreq_ctx); return NULL; } } /* * undo context will be allocated when needed (in *_undo_setup) */@end@ rowreq_ctx->oid_idx.oids = rowreq_ctx->oid_tmp; rowreq_ctx->${context}_data_list = NULL;@if $m2c_data_init == 1@ /* * if we allocated data, call init routine */ if (!(rowreq_ctx->rowreq_flags & MFD_ROW_DATA_FROM_USER)) { if(SNMPERR_SUCCESS != ${context}_rowreq_ctx_init(rowreq_ctx, user_init_ctx)) { ${context}_release_rowreq_ctx(rowreq_ctx); rowreq_ctx = NULL; } }@end@ return rowreq_ctx;} /* ${context}_allocate_rowreq_ctx *//* * @internal * release resources for a ${context}_rowreq_ctx */void${context}_release_rowreq_ctx(${context}_rowreq_ctx *rowreq_ctx){ DEBUGMSGTL(("internal:${context}:${context}_release_rowreq_ctx","called\n")); netsnmp_assert(NULL != rowreq_ctx); @if $m2c_data_init == 1@ ${context}_rowreq_ctx_cleanup(rowreq_ctx);@end@@if $m2c_data_allocate == 1@ /* * for non-transient data, don't free data we got from the user */ if ((rowreq_ctx->data) && !(rowreq_ctx->rowreq_flags & MFD_ROW_DATA_FROM_USER)) ${context}_release_data(rowreq_ctx->data); @end@ @if $m2c_undo_embed == 0@ if(rowreq_ctx->undo) ${context}_release_data(rowreq_ctx->undo); @end@ /* * free index oid pointer */ if(rowreq_ctx->oid_idx.oids != rowreq_ctx->oid_tmp) free(rowreq_ctx->oid_idx.oids); SNMP_FREE(rowreq_ctx);} /* ${context}_release_rowreq_ctx */##########################################################################/** * @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; DEBUGMSGTL(("internal:${context}:_mfd_${context}_pre_request", "called\n")); if (1 != netsnmp_row_merge_status_first(reginfo, agtreq_info)) { DEBUGMSGTL(("internal:${context}", "skipping additional pre_request\n")); return SNMP_ERR_NOERROR; } rc = ${context}_pre_request(${context}_if_ctx.user_ctx); if (MFD_SUCCESS != rc) { /* * nothing we can do about it but log it */ DEBUGMSGTL(("${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 = netsnmp_container_table_row_extract(requests); int rc, packet_rc; DEBUGMSGTL(("internal:${context}:_mfd_${context}_post_request", "called\n")); /* * release row context, if deleted */ if (rowreq_ctx && (rowreq_ctx->rowreq_flags & MFD_ROW_DELETED)) ${context}_release_rowreq_ctx(rowreq_ctx); /* * wait for last call before calling user */ if (1 != netsnmp_row_merge_status_last(reginfo, agtreq_info)) { DEBUGMSGTL(("internal:${context}", "waiting for last post_request\n")); return SNMP_ERR_NOERROR; } packet_rc = netsnmp_check_all_requests_error(agtreq_info->asp, 0);@ if $m2c_table_settable@ if ((MFD_SUCCESS != packet_rc) && ${context}_dirty_get()) { /* * we shouldn't get here. the undo steps should also clear * the dirty flags. */ snmp_log(LOG_WARNING, "${context} dirty flag set in post_request " "but status != SUCCESS.\n"); }@ end@ rc = ${context}_post_request(${context}_if_ctx.user_ctx,packet_rc); if (MFD_SUCCESS != rc) { /* * nothing we can do about it but log it */ DEBUGMSGTL(("${context}","error %d from " "${context}_post_request\n", rc)); } return SNMP_ERR_NOERROR;} /* _mfd_${context}_post_request */##########################################################################@if ($m2c_table_row_creation == 1) || ($m2c_table_persistent == 1)@/** * @internal * wrapper */static ${table}_rowreq_ctx *_mfd_${context}_rowreq_from_index(netsnmp_index *oid_idx, int * rc_ptr){ ${context}_rowreq_ctx * rowreq_ctx; ${context}_mib_index mib_idx; int rc; DEBUGMSGTL(("internal:${context}:_mfd_${context}_rowreq_from_index", "called\n")); if (NULL == rc_ptr) rc_ptr = &rc; *rc_ptr = MFD_SUCCESS; memset(&mib_idx, 0x0, sizeof(mib_idx)); /* * try to parse oid */ *rc_ptr = ${context}_index_from_oid(oid_idx, &mib_idx); if(MFD_SUCCESS != *rc_ptr) { DEBUGMSGT(("$context", "error parsing index\n")); return NULL; } /* * 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) { *rc_ptr = MFD_ERROR; return NULL; /* msg already logged */ } memcpy(&rowreq_ctx->tbl_idx, &mib_idx, sizeof(mib_idx)); /* * check indexes */ *rc_ptr = _${context}_check_indexes(rowreq_ctx); if(MFD_SUCCESS != *rc_ptr) { netsnmp_assert((*rc_ptr == SNMP_ERR_NOCREATION) || (*rc_ptr == SNMP_ERR_INCONSISTENTNAME)); ${context}_release_rowreq_ctx(rowreq_ctx); return NULL; } /* * copy indexes */ rowreq_ctx->oid_idx.len = oid_idx->len; memcpy(rowreq_ctx->oid_idx.oids, oid_idx->oids, oid_idx->len * sizeof(oid)); return rowreq_ctx;} /* _mfd_${context}_rowreq_from_index */@end@ # row creation/** * @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){ int rc = SNMP_ERR_NOERROR; ${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@ rc = SNMP_ERR_NOCREATION;@ else@ netsnmp_table_request_info *tblreq_info; netsnmp_index oid_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 create rowreq */ oid_idx.oids = tblreq_info->index_oid; oid_idx.len = tblreq_info->index_oid_len; rowreq_ctx = _mfd_${context}_rowreq_from_index(&oid_idx, &rc); if(MFD_SUCCESS == rc) { netsnmp_assert(NULL != rowreq_ctx); rowreq_ctx->rowreq_flags |= MFD_ROW_CREATED; /* * add rowreq_ctx to request data lists */ netsnmp_container_table_row_insert(requests, (netsnmp_index*)rowreq_ctx); }@ end@ // row creation } if (MFD_SUCCESS != rc) netsnmp_request_set_error_all(requests, rc); else ${context}_row_prep(rowreq_ctx); return SNMP_VALIDATE_ERR(rc);} /* _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 for %d\n", column)); 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_table_sparse == 1@ if (! (COLUMN_$node.uc_FLAG & rowreq_ctx->column_exists_flags)) { DEBUGMSGTL(("internal:${context}:_mfd_${context}_get_column", "column %d ($node) doesn't exist\n", column)); return MFD_SKIP; }@ end@## use sizeof except for BITS@ if $m2c_node_needlength == 0@@ if "$node.perltype" eq "BITS"@ { $m2c_decl mask = 0xff << ((sizeof($m2c_decl) - 1) * 8); int idx = 0;@ else@ var->val_len = sizeof($m2c_decl);@ end@@ end@ var->type = $node.type;rc = ${node}_get(rowreq_ctx, $m2c_node_var_ref );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -