📄 mfd-persistence.m2i
字号:
/* * store the line */ pos += sprintf(pos, "%c", LINE_TERM_CHAR); if(pos > max) { snmp_log(LOG_ERR,"error saving ${context} row " "to persistent file (too long)\n"); return SNMP_ERR_GENERR; } read_config_store((char*)type, buf); DEBUGMSGTL(("internal:${context}:_${context}_container_row_save", "saving line '%s'\n", buf)); return SNMP_ERR_NOERROR;}static void_${context}_container_row_restore(const char *token, char *buf){ ${context}_rowreq_ctx * rowreq_ctx; netsnmp_index index; oid tmp_oid[ MAX_${context}_IDX_LEN]; u_int col = 0, found = 0; if (strncmp(token, row_token, sizeof(row_token)) != 0) { snmp_log(LOG_ERR, "unknown token in _${context}_container_row_restore\n"); return; } DEBUGMSGTL(("internal:${context}:_${context}_container_row_restore", "parsing line '%s'\n", buf)); /* * pull out index and create default row */ index.oids = tmp_oid; index.len = OID_LENGTH(tmp_oid); buf = read_config_read_objid(buf, &index.oids, &index.len); if (NULL == buf) { snmp_log(LOG_ERR, "error reading row index in " "_${context}_container_row_restore\n"); return; } rowreq_ctx = _mfd_${context}_rowreq_from_index( &index, NULL ); if (NULL == rowreq_ctx) { snmp_log(LOG_ERR, "error creating row index in " "_${context}_container_row_restore\n"); return; } /* * loop through and get each column */ buf = skip_white(buf); while ( (NULL != buf) && isdigit(*buf) ) { /* * extract column, skip ':' */ col = (u_int)strtol(buf, &buf, 10); if (NULL == buf) break; if (*buf != ':') { buf = NULL; break; } ++buf; /* skip : */ /* * parse value */ DEBUGMSGTL(("_${context}_container_row_restore", "parsing column %d\n", col)); buf = _${context}_container_col_restore( rowreq_ctx, col, buf ); ++found; } if (0 == found) { snmp_log(LOG_ERR, "error parsing ${context} row; no columns found\n"); ${context}_release_rowreq_ctx( rowreq_ctx ); return; } /* * if you added any non-column data, this is where * you should handle it. */ /* * if the pointer is NULL and we didn't reach the * end of the line, something went wrong. Log message, * delete the row and bail. */ if ((buf == NULL) || (*buf != LINE_TERM_CHAR)) { snmp_log(LOG_ERR, "error parsing ${context} row around column %d\n", col); ${context}_release_rowreq_ctx( rowreq_ctx ); return; } DEBUGMSGTL(("internal:${context}:_${context}_container_row_restore", "inserting row\n")); /* * copy oid index and insert row */ rowreq_ctx->oid_idx.len = index.len; memcpy(rowreq_ctx->oid_idx.oids, index.oids, index.len * sizeof(oid)); CONTAINER_INSERT(${context}_if_ctx.container, rowreq_ctx);}/************************************************************ * _${context}_container_col_save */static char *_${context}_container_col_save( ${context}_rowreq_ctx *rowreq_ctx, u_int col, char* buf){ if( ( NULL == rowreq_ctx ) || ( NULL == buf )) { snmp_log(LOG_ERR, "bad parameter in " "_${context}_container_col_save\n"); return NULL; } DEBUGMSGTL(("internal:${context}:_${context}_container_col_save", "processing column %d\n", col)); /* * prefix with column number, so we don't ever depend on * order saved. */ buf += sprintf(buf, "%u:", col); /* * save data for the column */ switch(col) {@ foreach $node nonindex@@ include m2c_setup_node.m2i@ case COLUMN_$node.uc: /** $node.syntax = $node.type */@ if $m2c_node_needlength == 1@@ if "$node.type" eq "ASN_OBJECT_ID"@ buf = read_config_save_objid(buf, ${m2c_ctx_rh}, ${m2c_ctx_rhs} );@ else@ # "$node.type" eq "ASN_OCTET_STR"@ buf = read_config_save_octet_string(buf, ${m2c_ctx_rh}, ${m2c_ctx_rhs} );@ end@@ elsif "$node.type" eq "ASN_INTEGER"@ buf += sprintf(buf,"%ld",${m2c_ctx_rh});@ else@ buf += sprintf(buf,"%lu",${m2c_ctx_rh});@ end@ break; @ end@ # for each default: /** We shouldn't get here */ snmp_log(LOG_ERR, "unknown column %d in " "_${context}_container_col_save\n", col); return NULL; } return buf;}/************************************************************ * _${context}_container_col_restore */static char *_${context}_container_col_restore( ${context}_rowreq_ctx *rowreq_ctx, u_int col, char* buf){ size_t len; if( ( NULL == rowreq_ctx ) || ( NULL == buf )) { snmp_log(LOG_ERR, "bad parameter in " "_${context}_container_col_restore\n"); return NULL; } DEBUGMSGTL(("verbose:${context}:_${context}_container_col_restore", "processing column %d\n", col)); /* * restore data for the column */ switch(col) {@ foreach $node nonindex@@ include m2c_setup_node.m2i@ case COLUMN_$node.uc: /** $node.syntax = $node.type */@ if $m2c_node_needlength == 1@ ${m2c_ctx_rhs} = sizeof(${m2c_ctx_rh}); buf = read_config_read_memory($node.type,buf, (char*)&${m2c_ctx_rh}, (size_t*)&${m2c_ctx_rhs} );@ if "$node.type" eq "ASN_OBJECT_ID"@ ${m2c_ctx_rhs} /= sizeof(oid);@ end@@ else@ len = sizeof(${m2c_ctx_rh});@ if "$node.type" eq "ASN_OCTET_STR"@ # BITS@ eval $m2c_tmp = "ASN_INTEGER"@@ else@@ eval $m2c_tmp = $node.type@@ end@ buf = read_config_read_memory($m2c_tmp, buf, (char*)&${m2c_ctx_rh}, &len);@ end@@ if $m2c_table_sparse == 1@ if (NULL != buf) rowreq_ctx->column_exists_flags |= COLUMN_$node.uc_FLAG;@ end@ # table sparse break; @ end@ # foreach col default: /** We shouldn't get here */ snmp_log(LOG_ERR, "unknown column %d in " "_${context}_container_col_restore\n", col); return NULL; } return buf;}##@end@ // $m2c_processing_type eq 'i'########################################################################@if $m2c_mark_boundary == 1@/** END code generated by $RCSfile$ $Revision: 15990 $ */@end@
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -