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

📄 snmpnotifyfilterprofiletable.c

📁 开发snmp的开发包有两个开放的SNMP开发库
💻 C
📖 第 1 页 / 共 2 页
字号:
    case ACTION:        /*         * The variable has been stored in string 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          */        memcpy(StorageTmp->snmpNotifyFilterProfileName, var_val, var_val_len);        StorageTmp->snmpNotifyFilterProfileNameLen = var_val_len;        break;    case UNDO:        /*         * Back out any changes made in the ACTION case          */        SNMP_FREE(StorageTmp->snmpNotifyFilterProfileName);        StorageTmp->snmpNotifyFilterProfileName = tmpvar;        StorageTmp->snmpNotifyFilterProfileNameLen = 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_snmpNotifyFilterProfileStorType(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;    long            value = *((long *) var_val);    struct snmpNotifyFilterProfileTable_data *StorageTmp = NULL;    size_t          newlen =        name_len -        (sizeof(snmpNotifyFilterProfileTable_variables_oid) / sizeof(oid) +         3 - 1);    DEBUGMSGTL(("snmpNotifyFilterProfileTable",                "write_snmpNotifyFilterProfileStorType entering action=%d...  \n",                action));    if (action != RESERVE1 &&        (StorageTmp = (struct snmpNotifyFilterProfileTable_data *)         header_complex((struct header_complex_index *)                        snmpNotifyFilterProfileTableStorage, NULL,                        &name[sizeof                              (snmpNotifyFilterProfileTable_variables_oid)                              / sizeof(oid) + 3 - 1], &newlen, 1, NULL,                        NULL)) == NULL) {        if ((StorageTmp = StorageNew) == NULL)            return SNMP_ERR_NOSUCHNAME;     /* remove if you support creation here */    }    switch (action) {    case RESERVE1:        if (var_val_type != ASN_INTEGER) {            return SNMP_ERR_WRONGTYPE;        }        if (var_val_len != sizeof(long)) {            return SNMP_ERR_WRONGLENGTH;        }        if (value != SNMP_STORAGE_OTHER && value != SNMP_STORAGE_VOLATILE            && value != SNMP_STORAGE_NONVOLATILE) {            return SNMP_ERR_WRONGVALUE;        }        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 long_ret 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->snmpNotifyFilterProfileStorType;        StorageTmp->snmpNotifyFilterProfileStorType = *((long *) var_val);        break;    case UNDO:        /*         * Back out any changes made in the ACTION case          */        StorageTmp->snmpNotifyFilterProfileStorType = tmpvar;        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!          */        break;    }    return SNMP_ERR_NOERROR;}intwrite_snmpNotifyFilterProfileRowStatus(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){    struct snmpNotifyFilterProfileTable_data *StorageTmp = NULL;    static struct snmpNotifyFilterProfileTable_data *StorageDel;    size_t          newlen =        name_len -        (sizeof(snmpNotifyFilterProfileTable_variables_oid) / sizeof(oid) +         3 - 1);    static int      old_value;    int             set_value = *((long *) var_val);    netsnmp_variable_list *vars;    struct header_complex_index *hciptr;    DEBUGMSGTL(("snmpNotifyFilterProfileTable",                "write_snmpNotifyFilterProfileRowStatus entering action=%d...  \n",                action));    StorageTmp = (struct snmpNotifyFilterProfileTable_data *)        header_complex((struct header_complex_index *)                       snmpNotifyFilterProfileTableStorage, NULL,                       &name[sizeof                             (snmpNotifyFilterProfileTable_variables_oid) /                             sizeof(oid) + 3 - 1], &newlen, 1, NULL, NULL);    switch (action) {    case RESERVE1:        if (var_val_type != ASN_INTEGER || var_val == NULL) {            return SNMP_ERR_WRONGTYPE;        }        if (var_val_len != sizeof(long)) {            return SNMP_ERR_WRONGLENGTH;        }        if (set_value < 1 || set_value > 6 || set_value == RS_NOTREADY) {            return SNMP_ERR_WRONGVALUE;        }        /*         * stage one: test validity          */        if (StorageTmp == NULL) {            /*             * create the row now?              */            /*             * ditch illegal values now              */            if (set_value == RS_ACTIVE || set_value == RS_NOTINSERVICE) {                return SNMP_ERR_INCONSISTENTVALUE;            }        } else {            /*             * row exists.  Check for a valid state change              */            if (set_value == RS_CREATEANDGO                || set_value == RS_CREATEANDWAIT) {                /*                 * can't create a row that exists                  */                return SNMP_ERR_INCONSISTENTVALUE;            }            if ((set_value == RS_ACTIVE || set_value == RS_NOTINSERVICE) &&                StorageTmp->snmpNotifyFilterProfileNameLen == 0) {                /*                 * can't activate row without a profile name                 */                return SNMP_ERR_INCONSISTENTVALUE;            }            /*             * XXX: interaction with row storage type needed              */        }        /*         * memory reseveration, final preparation...          */        if (StorageTmp == NULL &&            (set_value == RS_CREATEANDGO             || set_value == RS_CREATEANDWAIT)) {            /*             * creation              */            vars = NULL;            snmp_varlist_add_variable(&vars, NULL, 0,                                      ASN_PRIV_IMPLIED_OCTET_STR, NULL, 0);            if (header_complex_parse_oid                (&                 (name                  [sizeof(snmpNotifyFilterProfileTable_variables_oid) /                   sizeof(oid) + 2]), newlen, vars) != SNMPERR_SUCCESS) {                snmp_free_var(vars);                return SNMP_ERR_INCONSISTENTNAME;            }            StorageNew =                SNMP_MALLOC_STRUCT(snmpNotifyFilterProfileTable_data);            memdup((u_char **) & (StorageNew->snmpTargetParamsName),                   vars->val.string, vars->val_len);            StorageNew->snmpTargetParamsNameLen = vars->val_len;            StorageNew->snmpNotifyFilterProfileStorType = ST_NONVOLATILE;            StorageNew->snmpNotifyFilterProfileRowStatus = RS_NOTREADY;            snmp_free_var(vars);        }        break;    case RESERVE2:        break;    case FREE:        /*         * XXX: free, zero vars          */        /*         * Release any resources that have been allocated          */        if (StorageNew != NULL) {            SNMP_FREE(StorageNew->snmpTargetParamsName);            SNMP_FREE(StorageNew->snmpNotifyFilterProfileName);            free(StorageNew);            StorageNew = NULL;        }        break;    case ACTION:        /*         * The variable has been stored in set_value 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          */        if (StorageTmp == NULL &&            (set_value == RS_CREATEANDGO ||             set_value == RS_CREATEANDWAIT)) {            /*             * row creation, so add it              */            if (StorageNew != NULL)                snmpNotifyFilterProfileTable_add(StorageNew);            /*             * XXX: ack, and if it is NULL?              */        } else if (set_value != RS_DESTROY) {            /*             * set the flag?              */            if (StorageTmp == NULL)                return SNMP_ERR_GENERR; /* should never ever get here */                        old_value = StorageTmp->snmpNotifyFilterProfileRowStatus;            StorageTmp->snmpNotifyFilterProfileRowStatus =                *((long *) var_val);        } else {            /*             * destroy...  extract it for now              */            if (StorageTmp) {                hciptr =                    header_complex_find_entry                    (snmpNotifyFilterProfileTableStorage, StorageTmp);                StorageDel = (struct snmpNotifyFilterProfileTable_data *)                    header_complex_extract_entry((struct                                                  header_complex_index **)                                                 &snmpNotifyFilterProfileTableStorage,                                                 hciptr);            }        }        break;    case UNDO:        /*         * Back out any changes made in the ACTION case          */        if (StorageTmp == NULL &&            (set_value == RS_CREATEANDGO ||             set_value == RS_CREATEANDWAIT)) {            /*             * row creation, so remove it again              */            hciptr =                header_complex_find_entry                (snmpNotifyFilterProfileTableStorage, StorageNew);            StorageDel = (struct snmpNotifyFilterProfileTable_data *)                header_complex_extract_entry((struct header_complex_index                                              **)                                             &snmpNotifyFilterProfileTableStorage,                                             hciptr);            /*             * XXX: free it              */        } else if (StorageDel != NULL) {            /*             * row deletion, so add it again              */            snmpNotifyFilterProfileTable_add(StorageDel);            StorageDel = NULL;        } else if (set_value != RS_DESTROY) {            if (StorageTmp)                StorageTmp->snmpNotifyFilterProfileRowStatus = old_value;        }        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!          */        if (StorageDel != NULL) {            SNMP_FREE(StorageDel->snmpTargetParamsName);            SNMP_FREE(StorageDel->snmpNotifyFilterProfileName);            free(StorageDel);            StorageDel = NULL;        }        if (StorageTmp && set_value == RS_CREATEANDGO) {            if (StorageTmp->snmpNotifyFilterProfileNameLen)                StorageTmp->snmpNotifyFilterProfileRowStatus = RS_ACTIVE;            StorageNew = NULL;        } else if (StorageTmp && set_value == RS_CREATEANDWAIT) {            if (StorageTmp->snmpNotifyFilterProfileNameLen)                StorageTmp->snmpNotifyFilterProfileRowStatus = RS_NOTINSERVICE;            StorageNew = NULL;        }        break;    }    return SNMP_ERR_NOERROR;}char           *get_FilterProfileName(const char *paramName, size_t paramName_len,               size_t * profileName_len){    netsnmp_variable_list *vars = NULL;    struct snmpNotifyFilterProfileTable_data *data;    /*     * put requested info into var structure      */    snmp_varlist_add_variable(&vars, NULL, 0, ASN_PRIV_IMPLIED_OCTET_STR,                              (u_char *) paramName, paramName_len);    /*     * get the data from the header_complex storage      */    data = (struct snmpNotifyFilterProfileTable_data *)        header_complex_get(snmpNotifyFilterProfileTableStorage, vars);    /*     * free search index      */    snmp_free_var(vars);    /*     * return the requested information (if this row is active)      */    if (data && data->snmpNotifyFilterProfileRowStatus == RS_ACTIVE) {        *profileName_len = data->snmpNotifyFilterProfileNameLen;        return data->snmpNotifyFilterProfileName;    }    *profileName_len = 0;    return NULL;}

⌨️ 快捷键说明

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