📄 mteobjectstable.c
字号:
/* * This file was generated by mib2c and is intended for use as * a mib module for the ucd-snmp snmpd agent. *//* * This should always be included first before anything else */#include <net-snmp/net-snmp-config.h>#if HAVE_STDLIB_H#include <stdlib.h>#endif#if HAVE_STRING_H#include <string.h>#else#include <strings.h>#endif/* * minimal include directives */#include <net-snmp/net-snmp-includes.h>#include <net-snmp/agent/net-snmp-agent-includes.h>#include "header_complex.h"#include "mteTriggerTable.h"#include "mteObjectsTable.h"/* * mteObjectsTable_variables_oid: * this is the top level oid that we want to register under. This * is essentially a prefix, with the suffix appearing in the * variable below. */oid mteObjectsTable_variables_oid[] = { 1, 3, 6, 1, 2, 1, 88, 1, 3, 1 };/* * variable2 mteObjectsTable_variables: * this variable defines function callbacks and type return information * for the mteObjectsTable mib section */struct variable2 mteObjectsTable_variables[] = { /* * magic number , variable type , ro/rw , callback fn , L, oidsuffix */#define MTEOBJECTSID 5 {MTEOBJECTSID, ASN_OBJECT_ID, RWRITE, var_mteObjectsTable, 2, {1, 3}},#define MTEOBJECTSIDWILDCARD 6 {MTEOBJECTSIDWILDCARD, ASN_INTEGER, RWRITE, var_mteObjectsTable, 2, {1, 4}},#define MTEOBJECTSENTRYSTATUS 7 {MTEOBJECTSENTRYSTATUS, ASN_INTEGER, RWRITE, var_mteObjectsTable, 2, {1, 5}},};/* * (L = length of the oidsuffix) *//* * global storage of our data, saved in and configured by header_complex() */static struct header_complex_index *mteObjectsTableStorage = NULL;/* * init_mteObjectsTable(): * Initialization routine. This is called when the agent starts up. * At a minimum, registration of your variables should take place here. */voidinit_mteObjectsTable(void){ DEBUGMSGTL(("mteObjectsTable", "initializing... ")); /* * register ourselves with the agent to handle our mib tree */ REGISTER_MIB("mteObjectsTable", mteObjectsTable_variables, variable2, mteObjectsTable_variables_oid); /* * register our config handler(s) to deal with registrations */ snmpd_register_config_handler("mteObjectsTable", parse_mteObjectsTable, NULL, NULL); /* * we need to be called back later to store our data */ snmp_register_callback(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_STORE_DATA, store_mteObjectsTable, NULL); /* * place any other initialization junk you need here */ DEBUGMSGTL(("mteObjectsTable", "done.\n"));}/* * mteObjectsTable_add(): adds a structure node to our data set */intmteObjectsTable_add(struct mteObjectsTable_data *thedata){ netsnmp_variable_list *vars = NULL; DEBUGMSGTL(("mteObjectsTable", "adding data... ")); /* * add the index variables to the varbind list, which is * used by header_complex to index the data */ snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, (char *) thedata->mteOwner, thedata->mteOwnerLen); /* mteOwner */ snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, (char *) thedata->mteObjectsName, thedata->mteObjectsNameLen); /* mteObjectsName */ snmp_varlist_add_variable(&vars, NULL, 0, ASN_UNSIGNED, (char *) &thedata->mteObjectsIndex, sizeof(thedata->mteObjectsIndex)); /* mteObjectsIndex */ header_complex_add_data(&mteObjectsTableStorage, vars, thedata); DEBUGMSGTL(("mteObjectsTable", "registered an entry\n")); DEBUGMSGTL(("mteObjectsTable", "done.\n")); return SNMPERR_SUCCESS;}/* * parse_mteObjectsTable(): * parses .conf file entries needed to configure the mib. */voidparse_mteObjectsTable(const char *token, char *line){ size_t tmpint; struct mteObjectsTable_data *StorageTmp = SNMP_MALLOC_STRUCT(mteObjectsTable_data); DEBUGMSGTL(("mteObjectsTable", "parsing config... ")); if (StorageTmp == NULL) { config_perror("malloc failure"); return; } line = read_config_read_data(ASN_OCTET_STR, line, &StorageTmp->mteOwner, &StorageTmp->mteOwnerLen); if (StorageTmp->mteOwner == NULL) { config_perror("invalid specification for mteOwner"); return; } line = read_config_read_data(ASN_OCTET_STR, line, &StorageTmp->mteObjectsName, &StorageTmp->mteObjectsNameLen); if (StorageTmp->mteObjectsName == NULL) { config_perror("invalid specification for mteObjectsName"); return; } line = read_config_read_data(ASN_UNSIGNED, line, &StorageTmp->mteObjectsIndex, &tmpint); line = read_config_read_data(ASN_OBJECT_ID, line, &StorageTmp->mteObjectsID, &StorageTmp->mteObjectsIDLen); if (StorageTmp->mteObjectsID == NULL) { config_perror("invalid specification for mteObjectsID"); return; } line = read_config_read_data(ASN_INTEGER, line, &StorageTmp->mteObjectsIDWildcard, &tmpint); line = read_config_read_data(ASN_INTEGER, line, &StorageTmp->mteObjectsEntryStatus, &tmpint); mteObjectsTable_add(StorageTmp); DEBUGMSGTL(("mteObjectsTable", "done.\n"));}/* * store_mteObjectsTable(): * stores .conf file entries needed to configure the mib. */intstore_mteObjectsTable(int majorID, int minorID, void *serverarg, void *clientarg){ char line[SNMP_MAXBUF]; char *cptr; size_t tmpint; struct mteObjectsTable_data *StorageTmp; struct header_complex_index *hcindex; DEBUGMSGTL(("mteObjectsTable", "storing data... ")); for (hcindex = mteObjectsTableStorage; hcindex != NULL; hcindex = hcindex->next) { StorageTmp = (struct mteObjectsTable_data *) hcindex->data; if (StorageTmp->storagetype != ST_READONLY) { memset(line, 0, sizeof(line)); strcat(line, "mteObjectsTable "); cptr = line + strlen(line); cptr = read_config_store_data(ASN_OCTET_STR, cptr, &StorageTmp->mteOwner, &StorageTmp->mteOwnerLen); cptr = read_config_store_data(ASN_OCTET_STR, cptr, &StorageTmp->mteObjectsName, &StorageTmp->mteObjectsNameLen); cptr = read_config_store_data(ASN_UNSIGNED, cptr, &StorageTmp->mteObjectsIndex, &tmpint); cptr = read_config_store_data(ASN_OBJECT_ID, cptr, &StorageTmp->mteObjectsID, &StorageTmp->mteObjectsIDLen); cptr = read_config_store_data(ASN_INTEGER, cptr, &StorageTmp->mteObjectsIDWildcard, &tmpint); cptr = read_config_store_data(ASN_INTEGER, cptr, &StorageTmp->mteObjectsEntryStatus, &tmpint); snmpd_store_config(line); } } DEBUGMSGTL(("mteObjectsTable", "done.\n")); return SNMPERR_SUCCESS;}/* * var_mteObjectsTable(): * Handle this table separately from the scalar value case. * The workings of this are basically the same as for var_mteObjectsTable above. */unsigned char *var_mteObjectsTable(struct variable *vp, oid * name, size_t * length, int exact, size_t * var_len, WriteMethod ** write_method){ struct mteObjectsTable_data *StorageTmp = NULL; DEBUGMSGTL(("mteObjectsTable", "var_mteObjectsTable: Entering... \n")); /* * this assumes you have registered all your data properly */ if ((StorageTmp = header_complex(mteObjectsTableStorage, vp, name, length, exact, var_len, write_method)) == NULL) { if (vp->magic == MTEOBJECTSENTRYSTATUS) *write_method = write_mteObjectsEntryStatus; return NULL; } /* * this is where we do the value assignments for the mib results. */ switch (vp->magic) { case MTEOBJECTSID: *write_method = write_mteObjectsID; *var_len = (StorageTmp->mteObjectsIDLen) * sizeof(oid); return (u_char *) StorageTmp->mteObjectsID; case MTEOBJECTSIDWILDCARD: *write_method = write_mteObjectsIDWildcard; *var_len = sizeof(StorageTmp->mteObjectsIDWildcard); return (u_char *) & StorageTmp->mteObjectsIDWildcard; case MTEOBJECTSENTRYSTATUS: *write_method = write_mteObjectsEntryStatus; *var_len = sizeof(StorageTmp->mteObjectsEntryStatus); return (u_char *) & StorageTmp->mteObjectsEntryStatus; default: ERROR_MSG(""); } return NULL;}intwrite_mteObjectsID(int action, u_char * var_val, u_char var_val_type, size_t var_val_len, u_char * statP, oid * name, size_t name_len){ static oid *tmpvar; struct mteObjectsTable_data *StorageTmp = NULL; static size_t tmplen; size_t newlen = name_len - (sizeof(mteObjectsTable_variables_oid) / sizeof(oid) + 3 - 1); DEBUGMSGTL(("mteObjectsTable", "write_mteObjectsID entering action=%d... \n", action)); if ((StorageTmp = header_complex(mteObjectsTableStorage, NULL, &name[sizeof(mteObjectsTable_variables_oid) / sizeof(oid) + 3 - 1], &newlen, 1, NULL, NULL)) == NULL) return SNMP_ERR_NOSUCHNAME; /* remove if you support creation here */ if (StorageTmp && StorageTmp->storagetype == ST_READONLY) { return SNMP_ERR_NOTWRITABLE; } switch (action) { case RESERVE1: if (var_val_type != ASN_OBJECT_ID) { snmp_log(LOG_ERR, "write to mteObjectsID not ASN_OBJECT_ID\n"); return SNMP_ERR_WRONGTYPE; } break; case RESERVE2: /* * memory reseveration, final preparation... */ break; case FREE: /* * Release any resources that have been allocated */ break; case ACTION: /* * The variable has been stored in objid for * you to use, and you have just been asked to do something with * it. Note that anything done here must be reversable in the UNDO case */ tmpvar = StorageTmp->mteObjectsID; tmplen = StorageTmp->mteObjectsIDLen; memdup((u_char **) & StorageTmp->mteObjectsID, var_val, var_val_len); StorageTmp->mteObjectsIDLen = var_val_len / sizeof(oid); break; case UNDO: /* * Back out any changes made in the ACTION case */ SNMP_FREE(StorageTmp->mteObjectsID); StorageTmp->mteObjectsID = tmpvar; StorageTmp->mteObjectsIDLen = tmplen; break; case COMMIT: /* * Things are working well, so it's now safe to make the change * permanently. Make sure that anything done here can't fail! */ SNMP_FREE(tmpvar); break; } return SNMP_ERR_NOERROR;}intwrite_mteObjectsIDWildcard(int action, u_char * var_val, u_char var_val_type, size_t var_val_len, u_char * statP, oid * name, size_t name_len){ static int tmpvar; struct mteObjectsTable_data *StorageTmp = NULL; size_t newlen = name_len - (sizeof(mteObjectsTable_variables_oid) / sizeof(oid) + 3 - 1); DEBUGMSGTL(("mteObjectsTable", "write_mteObjectsIDWildcard entering action=%d... \n", action)); if ((StorageTmp = header_complex(mteObjectsTableStorage, NULL, &name[sizeof(mteObjectsTable_variables_oid) / sizeof(oid) + 3 - 1], &newlen, 1, NULL, NULL)) == NULL) return SNMP_ERR_NOSUCHNAME; /* remove if you support creation here */ if (StorageTmp && StorageTmp->storagetype == ST_READONLY) { return SNMP_ERR_NOTWRITABLE; } switch (action) { case RESERVE1: if (var_val_type != ASN_INTEGER) { snmp_log(LOG_ERR, "write to mteObjectsIDWildcard not ASN_INTEGER\n"); return SNMP_ERR_WRONGTYPE; } break; case RESERVE2: /* * memory reseveration, final preparation...
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -