📄 snmpnotifytable.c
字号:
* memory reseveration, final preparation... */ tmpvar = StorageTmp->snmpNotifyTag; tmplen = StorageTmp->snmpNotifyTagLen; StorageTmp->snmpNotifyTag = calloc(1, var_val_len + 1); if (NULL == StorageTmp->snmpNotifyTag) return SNMP_ERR_RESOURCEUNAVAILABLE; break; case FREE: /* * Release any resources that have been allocated */ break; case ACTION: memcpy(StorageTmp->snmpNotifyTag, var_val, var_val_len); StorageTmp->snmpNotifyTagLen = var_val_len; break; case UNDO: /* * Back out any changes made in the ACTION case */ SNMP_FREE(StorageTmp->snmpNotifyTag); StorageTmp->snmpNotifyTag = tmpvar; StorageTmp->snmpNotifyTagLen = tmplen; tmpvar = NULL; 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_snmpNotifyType(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 snmpNotifyTable_data *StorageTmp = NULL; long value = *((long *) var_val); size_t newlen = name_len - (sizeof(snmpNotifyTable_variables_oid) / sizeof(oid) + 3 - 1); DEBUGMSGTL(("snmpNotifyTable", "write_snmpNotifyType entering action=%d... \n", action)); if (action != RESERVE1 && (StorageTmp = (struct snmpNotifyTable_data *) header_complex((struct header_complex_index *) snmpNotifyTableStorage, NULL, &name[sizeof(snmpNotifyTable_variables_oid) / sizeof(oid) + 3 - 1], &newlen, 1, NULL, NULL)) == NULL) { if ((StorageTmp = StorageNew) == NULL) return SNMP_ERR_NOSUCHNAME; } 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 < 1 || value > 2) { return SNMP_ERR_WRONGVALUE; } break; case ACTION: tmpvar = StorageTmp->snmpNotifyType; StorageTmp->snmpNotifyType = value; break; case UNDO: /* * Back out any changes made in the ACTION case */ StorageTmp->snmpNotifyType = tmpvar; break; } return SNMP_ERR_NOERROR;}intwrite_snmpNotifyStorageType(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 snmpNotifyTable_data *StorageTmp = NULL; size_t newlen = name_len - (sizeof(snmpNotifyTable_variables_oid) / sizeof(oid) + 3 - 1); DEBUGMSGTL(("snmpNotifyTable", "write_snmpNotifyStorageType entering action=%d... \n", action)); if (action != RESERVE1 && (StorageTmp = (struct snmpNotifyTable_data *) header_complex((struct header_complex_index *) snmpNotifyTableStorage, NULL, &name[sizeof(snmpNotifyTable_variables_oid) / sizeof(oid) + 3 - 1], &newlen, 1, NULL, NULL)) == NULL) { if ((StorageTmp = StorageNew) == NULL) return SNMP_ERR_NOSUCHNAME; } 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 ACTION: tmpvar = StorageTmp->snmpNotifyStorageType; StorageTmp->snmpNotifyStorageType = value; break; case UNDO: StorageTmp->snmpNotifyStorageType = tmpvar; break; } return SNMP_ERR_NOERROR;}intwrite_snmpNotifyRowStatus(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 snmpNotifyTable_data *StorageTmp = NULL; static struct snmpNotifyTable_data *StorageDel; size_t newlen = name_len - (sizeof(snmpNotifyTable_variables_oid) / sizeof(oid) + 3 - 1); static int old_value; int set_value = *((long *) var_val); static netsnmp_variable_list *vars, *vp; struct header_complex_index *hciptr; DEBUGMSGTL(("snmpNotifyTable", "write_snmpNotifyRowStatus entering action=%d... \n", action)); StorageTmp = (struct snmpNotifyTable_data *) header_complex((struct header_complex_index *) snmpNotifyTableStorage, NULL, &name[sizeof(snmpNotifyTable_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; } 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; } /* * 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); /* snmpNotifyName */ if (header_complex_parse_oid (& (name [sizeof(snmpNotifyTable_variables_oid) / sizeof(oid) + 2]), newlen, vars) != SNMPERR_SUCCESS) { /* * XXX: free, zero vars */ snmp_free_var(vars); return SNMP_ERR_INCONSISTENTNAME; } vp = vars; StorageNew = SNMP_MALLOC_STRUCT(snmpNotifyTable_data); if (StorageNew == NULL) { return SNMP_ERR_RESOURCEUNAVAILABLE; } StorageNew->snmpNotifyName = calloc( 1, vp->val_len + 1 ); if (StorageNew->snmpNotifyName == NULL) { return SNMP_ERR_RESOURCEUNAVAILABLE; } memcpy(StorageNew->snmpNotifyName, vp->val.string, vp->val_len); StorageNew->snmpNotifyNameLen = vp->val_len; vp = vp->next_variable; /* * default values */ StorageNew->snmpNotifyStorageType = ST_NONVOLATILE; StorageNew->snmpNotifyType = SNMPNOTIFYTYPE_TRAP; StorageNew->snmpNotifyTagLen = 0; StorageNew->snmpNotifyTag = (char *) calloc(sizeof(char), 1); if (StorageNew->snmpNotifyTag == NULL) { return SNMP_ERR_RESOURCEUNAVAILABLE; } StorageNew->snmpNotifyRowStatus = set_value; snmp_free_var(vars); } break; case RESERVE2: break; case FREE: if (StorageNew != NULL) { SNMP_FREE(StorageNew->snmpNotifyTag); SNMP_FREE(StorageNew->snmpNotifyName); free(StorageNew); StorageNew = NULL; } break; case ACTION: if (StorageTmp == NULL && (set_value == RS_CREATEANDGO || set_value == RS_CREATEANDWAIT)) { /* * row creation, so add it */ if (StorageNew != NULL) { snmpNotifyTable_add(StorageNew); } } else if (set_value != RS_DESTROY) { /* * set the flag? */ if (StorageTmp == NULL) return SNMP_ERR_GENERR; /* should never ever get here */ old_value = StorageTmp->snmpNotifyRowStatus; StorageTmp->snmpNotifyRowStatus = *((long *) var_val); } else { /* * destroy... extract it for now */ if (StorageTmp) { hciptr = header_complex_find_entry(snmpNotifyTableStorage, StorageTmp); StorageDel = (struct snmpNotifyTable_data *) header_complex_extract_entry((struct header_complex_index **) &snmpNotifyTableStorage, 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(snmpNotifyTableStorage, StorageNew); StorageDel = (struct snmpNotifyTable_data *) header_complex_extract_entry((struct header_complex_index **) &snmpNotifyTableStorage, hciptr); /* * XXX: free it */ } else if (StorageDel != NULL) { /* * row deletion, so add it again */ snmpNotifyTable_add(StorageDel); } else if (set_value != RS_DESTROY) { if (StorageTmp) StorageTmp->snmpNotifyRowStatus = old_value; } break; case COMMIT: if (StorageDel != NULL) { SNMP_FREE(StorageDel->snmpNotifyTag); SNMP_FREE(StorageDel->snmpNotifyName); free(StorageDel); StorageDel = NULL; } if (StorageTmp && StorageTmp->snmpNotifyRowStatus == RS_CREATEANDGO) { StorageTmp->snmpNotifyRowStatus = RS_ACTIVE; StorageNew = NULL; } else if (StorageTmp && StorageTmp->snmpNotifyRowStatus == RS_CREATEANDWAIT) { StorageTmp->snmpNotifyRowStatus = RS_NOTINSERVICE; StorageNew = NULL; } break; } return SNMP_ERR_NOERROR;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -