⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 event.c

📁 snmp的源代码,已经在我的ubuntu下编译通过
💻 C
📖 第 1 页 / 共 2 页
字号:
/************************************************************** * Copyright (C) 2001 Alex Rozin, Optical Access * *                     All Rights Reserved * * Permission to use, copy, modify and distribute this software and its * documentation for any purpose and without fee is hereby granted, * provided that the above copyright notice appear in all copies and that * both that copyright notice and this permission notice appear in * supporting documentation. * * ALEX ROZIN DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL * ALEX ROZIN BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS * SOFTWARE. ******************************************************************/#include <net-snmp/net-snmp-config.h>#if HAVE_STDLIB_H#include <stdlib.h>#endif#if TIME_WITH_SYS_TIME# ifdef WIN32#  include <sys/timeb.h># else#  include <sys/time.h># endif# include <time.h>#else# if HAVE_SYS_TIME_H#  include <sys/time.h># else#  include <time.h># endif#endif#if HAVE_UNISTD_H#include <unistd.h>#endif#include <ctype.h>#include <net-snmp/net-snmp-includes.h>#include <net-snmp/agent/net-snmp-agent-includes.h>#include "util_funcs.h"#include "event.h"/* * Implementation headers  */#include "agutil_api.h"#include "row_api.h"/* * File scope definitions section  *//* * from MIB compilation  */#define eventEntryFirstIndexBegin       11#define EVENTINDEX            3#define EVENTDESCRIPTION      4#define EVENTTYPE             5#define EVENTCOMMUNITY        6#define EVENTLASTTIMESENT     7#define EVENTOWNER            8#define EVENTSTATUS           9#define Leaf_event_description  2#define MIN_event_description   0#define MAX_event_description   127#define Leaf_event_type         3#define Leaf_event_community    4#define MIN_event_community     0#define MAX_event_community     127#define Leaf_event_last_time_sent 5#define Leaf_eventOwner        6#define Leaf_eventStatus       7#define LOGEVENTINDEX         3#define LOGINDEX              4#define LOGTIME               5#define LOGDESCRIPTION        6/* * defaults & limitations  */#define MAX_LOG_ENTRIES_PER_CTRL	200typedef struct data_struct_t {    struct data_struct_t *next;    u_long          data_index;    u_long          log_time;    char           *log_description;} DATA_ENTRY_T;typedef enum {    EVENT_NONE = 1,    EVENT_LOG,    EVENT_TRAP,    EVENT_LOG_AND_TRAP} EVENT_TYPE_T;typedef struct {    char           *event_description;    char           *event_community;    EVENT_TYPE_T    event_type;    u_long          event_last_time_sent;    SCROLLER_T      scrlr;#if 0    u_long          event_last_logged_index;    u_long          event_number_of_log_entries;    DATA_ENTRY_T   *log_list;    DATA_ENTRY_T   *last_log_ptr;#endif} CRTL_ENTRY_T;/* * Main section  */static TABLE_DEFINTION_T EventCtrlTable;static TABLE_DEFINTION_T *table_ptr = &EventCtrlTable;/* * Control Table RowApi Callbacks  */static intdata_destructor(SCROLLER_T * scrlr, void *free_me){    DATA_ENTRY_T   *lptr = free_me;    if (lptr->log_description)        AGFREE(lptr->log_description);    return 0;}intevent_Create(RMON_ENTRY_T * eptr){                               /* create the body: alloc it and set defaults */    CRTL_ENTRY_T   *body;    eptr->body = AGMALLOC(sizeof(CRTL_ENTRY_T));    if (!eptr->body)        return -3;    body = (CRTL_ENTRY_T *) eptr->body;    /*     * set defaults      */    body->event_description = NULL;    body->event_community = AGSTRDUP("public");    /*     * ag_trace ("Dbg: created event_community=<%s>", body->event_community);      */    body->event_type = EVENT_NONE;    ROWDATAAPI_init(&body->scrlr,                    MAX_LOG_ENTRIES_PER_CTRL,                    MAX_LOG_ENTRIES_PER_CTRL,                    sizeof(DATA_ENTRY_T), &data_destructor);    return 0;}intevent_Clone(RMON_ENTRY_T * eptr){                               /* copy entry_bod -> clone */    CRTL_ENTRY_T   *body = (CRTL_ENTRY_T *) eptr->body;    CRTL_ENTRY_T   *clone = (CRTL_ENTRY_T *) eptr->tmp;    if (body->event_description)        clone->event_description = AGSTRDUP(body->event_description);    if (body->event_community)        clone->event_community = AGSTRDUP(body->event_community);    return 0;}intevent_Copy(RMON_ENTRY_T * eptr){    CRTL_ENTRY_T   *body = (CRTL_ENTRY_T *) eptr->body;    CRTL_ENTRY_T   *clone = (CRTL_ENTRY_T *) eptr->tmp;    if (body->event_type != clone->event_type) {        body->event_type = clone->event_type;    }    if (clone->event_description) {        if (body->event_description)            AGFREE(body->event_description);        body->event_description = AGSTRDUP(clone->event_description);    }    if (clone->event_community) {        if (body->event_community)            AGFREE(body->event_community);        body->event_community = AGSTRDUP(clone->event_community);    }    return 0;}intevent_Delete(RMON_ENTRY_T * eptr){    CRTL_ENTRY_T   *body = (CRTL_ENTRY_T *) eptr;    if (body->event_description)        AGFREE(body->event_description);    if (body->event_community)        AGFREE(body->event_community);    return 0;}intevent_Activate(RMON_ENTRY_T * eptr){                               /* init logTable */    CRTL_ENTRY_T   *body = (CRTL_ENTRY_T *) eptr->body;    ROWDATAAPI_set_size(&body->scrlr,                        body->scrlr.data_requested,                        (u_char)(RMON1_ENTRY_VALID == eptr->status) );    return 0;}intevent_Deactivate(RMON_ENTRY_T * eptr){                               /* free logTable */    CRTL_ENTRY_T   *body = (CRTL_ENTRY_T *) eptr->body;    /*     * free data list      */    ROWDATAAPI_descructor(&body->scrlr);    return 0;}static intwrite_eventControl(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){    long            long_temp;    char           *char_temp;    int             leaf_id, snmp_status;    static int      prev_action = COMMIT;    RMON_ENTRY_T   *hdr;    CRTL_ENTRY_T   *cloned_body;    CRTL_ENTRY_T   *body;    switch (action) {    case RESERVE1:    case FREE:    case UNDO:    case ACTION:    case COMMIT:    default:        return ROWAPI_do_another_action(name, eventEntryFirstIndexBegin,                                        action, &prev_action,                                        table_ptr, sizeof(CRTL_ENTRY_T));    case RESERVE2:        /*         * get values from PDU, check them and save them in the cloned entry          */        long_temp = name[eventEntryFirstIndexBegin];        leaf_id = (int) name[eventEntryFirstIndexBegin - 1];        hdr = ROWAPI_find(table_ptr, long_temp);        /* it MUST be OK */        cloned_body = (CRTL_ENTRY_T *) hdr->tmp;        body = (CRTL_ENTRY_T *) hdr->body;        switch (leaf_id) {        case Leaf_event_description:            char_temp = AGMALLOC(1 + MAX_event_description);            if (!char_temp)                return SNMP_ERR_TOOBIG;            snmp_status = AGUTIL_get_string_value(var_val, var_val_type,                                                  var_val_len,                                                  MAX_event_description,                                                  1, NULL, char_temp);            if (SNMP_ERR_NOERROR != snmp_status) {                AGFREE(char_temp);                return snmp_status;            }            if (cloned_body->event_description)                AGFREE(cloned_body->event_description);            cloned_body->event_description = AGSTRDUP(char_temp);            /*             * ag_trace ("rx: event_description=<%s>", cloned_body->event_description);              */            AGFREE(char_temp);            break;        case Leaf_event_type:            snmp_status = AGUTIL_get_int_value(var_val, var_val_type,                                               var_val_len,                                               EVENT_NONE,                                               EVENT_LOG_AND_TRAP,                                               &long_temp);            if (SNMP_ERR_NOERROR != snmp_status) {                return snmp_status;            }            cloned_body->event_type = long_temp;            break;        case Leaf_event_community:            char_temp = AGMALLOC(1 + MAX_event_community);            if (!char_temp)                return SNMP_ERR_TOOBIG;            snmp_status = AGUTIL_get_string_value(var_val, var_val_type,                                                  var_val_len,                                                  MAX_event_community,                                                  1, NULL, char_temp);            if (SNMP_ERR_NOERROR != snmp_status) {                AGFREE(char_temp);                return snmp_status;            }            if (cloned_body->event_community)                AGFREE(cloned_body->event_community);            cloned_body->event_community = AGSTRDUP(char_temp);            AGFREE(char_temp);            break;        case Leaf_eventOwner:            if (hdr->new_owner)                AGFREE(hdr->new_owner);            hdr->new_owner = AGMALLOC(MAX_OWNERSTRING);;            if (!hdr->new_owner)                return SNMP_ERR_TOOBIG;            snmp_status = AGUTIL_get_string_value(var_val, var_val_type,                                                  var_val_len,                                                  MAX_OWNERSTRING,                                                  1, NULL, hdr->new_owner);            if (SNMP_ERR_NOERROR != snmp_status) {                return snmp_status;            }            break;        case Leaf_eventStatus:            snmp_status = AGUTIL_get_int_value(var_val, var_val_type,                                               var_val_len,                                               RMON1_ENTRY_VALID,                                               RMON1_ENTRY_INVALID,                                               &long_temp);            if (SNMP_ERR_NOERROR != snmp_status) {                return snmp_status;            }            hdr->new_status = long_temp;            break;        default:            ag_trace("%s:unknown leaf_id=%d\n", table_ptr->name,                     (int) leaf_id);            return SNMP_ERR_NOSUCHNAME;        }                       /* of switch by 'leaf_id' */        break;    }                           /* of switch by actions */    prev_action = action;    return SNMP_ERR_NOERROR;}unsigned char  *var_eventTable(struct variable *vp,               oid * name,               size_t * length,               int exact, size_t * var_len, WriteMethod ** write_method){    static long     long_ret;    static CRTL_ENTRY_T theEntry;    RMON_ENTRY_T   *hdr;    *write_method = write_eventControl;    hdr = ROWAPI_header_ControlEntry(vp, name, length, exact, var_len,                                     table_ptr,                                     &theEntry, sizeof(CRTL_ENTRY_T));    if (!hdr)        return NULL;    *var_len = sizeof(long);    /* default */    switch (vp->magic) {    case EVENTINDEX:        long_ret = hdr->ctrl_index;        return (unsigned char *) &long_ret;    case EVENTDESCRIPTION:        if (theEntry.event_description) {            *var_len = strlen(theEntry.event_description);            return (unsigned char *) theEntry.event_description;        } else {            *var_len = 0;            return (unsigned char *) "";        }    case EVENTTYPE:        long_ret = theEntry.event_type;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -