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

📄 snmpnotifytable.c

📁 Snmp(简单网管协议)软件包。
💻 C
📖 第 1 页 / 共 2 页
字号:
          DEBUGMSGTL(("snmpNotifyTable", "var_snmpNotifyTable: create?...  \n"));          *write_method = write_snmpNotifyRowStatus;      }      return NULL;  }  /*    * this is where we do the value assignments for the mib results.   */  switch(vp->magic) {    case SNMPNOTIFYTAG:        *write_method = write_snmpNotifyTag;        *var_len = StorageTmp->snmpNotifyTagLen;        return (u_char *) StorageTmp->snmpNotifyTag;    case SNMPNOTIFYTYPE:        *write_method = write_snmpNotifyType;        *var_len = sizeof(StorageTmp->snmpNotifyType);        return (u_char *) &StorageTmp->snmpNotifyType;    case SNMPNOTIFYSTORAGETYPE:        *write_method = write_snmpNotifyStorageType;        *var_len = sizeof(StorageTmp->snmpNotifyStorageType);        return (u_char *) &StorageTmp->snmpNotifyStorageType;    case SNMPNOTIFYROWSTATUS:        *write_method = write_snmpNotifyRowStatus;        *var_len = sizeof(StorageTmp->snmpNotifyRowStatus);        return (u_char *) &StorageTmp->snmpNotifyRowStatus;    default:      ERROR_MSG("");  }  return NULL;}intwrite_snmpNotifyTag(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 char * tmpvar;  struct snmpNotifyTable_data *StorageTmp = NULL;  static size_t tmplen;  size_t newlen=name_len - (sizeof(snmpNotifyTable_variables_oid)/sizeof(oid) + 3 - 1);  DEBUGMSGTL(("snmpNotifyTable", "write_snmpNotifyTag entering action=%d...  \n", action));  if ((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)      return SNMP_ERR_NOSUCHNAME; /* remove if you support creation here */  switch ( action ) {        case RESERVE1:          if (var_val_type != ASN_OCTET_STR){              fprintf(stderr, "write to snmpNotifyTag not ASN_OCTET_STR\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 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 */             tmpvar = StorageTmp->snmpNotifyTag;             tmplen = StorageTmp->snmpNotifyTagLen;             memdup((u_char **) &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;  size_t newlen=name_len - (sizeof(snmpNotifyTable_variables_oid)/sizeof(oid) + 3 - 1);  DEBUGMSGTL(("snmpNotifyTable", "write_snmpNotifyType entering action=%d...  \n", action));  if ((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)      return SNMP_ERR_NOSUCHNAME; /* remove if you support creation here */  switch ( action ) {        case RESERVE1:          if (var_val_type != ASN_INTEGER){              fprintf(stderr, "write to snmpNotifyType not ASN_INTEGER\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 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->snmpNotifyType;             StorageTmp->snmpNotifyType = *((long *) var_val);          break;        case UNDO:             /* Back out any changes made in the ACTION case */             StorageTmp->snmpNotifyType = 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_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;  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 ((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)      return SNMP_ERR_NOSUCHNAME; /* remove if you support creation here */  switch ( action ) {        case RESERVE1:          if (var_val_type != ASN_INTEGER){              fprintf(stderr, "write to snmpNotifyStorageType not ASN_INTEGER\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 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->snmpNotifyStorageType;             StorageTmp->snmpNotifyStorageType = *((long *) var_val);          break;        case UNDO:             /* Back out any changes made in the ACTION case */             StorageTmp->snmpNotifyStorageType = 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_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 *StorageNew, *StorageDel;  size_t newlen=name_len - (sizeof(snmpNotifyTable_variables_oid)/sizeof(oid) + 3 - 1);  static int old_value;  int set_value;  static struct 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);      if (var_val_type != ASN_INTEGER || var_val == NULL){    fprintf(stderr, "write to snmpNotifyRowStatus not ASN_INTEGER\n");    return SNMP_ERR_WRONGTYPE;  }  set_value = *((long *) var_val);  /* check legal range, and notReady is reserved for us, not a user */  if (set_value < 1 || set_value > 6 || set_value == RS_NOTREADY)    return SNMP_ERR_INCONSISTENTVALUE;      switch ( action ) {        case RESERVE1:  /* 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;            }    /* XXX: interaction with row storage type needed */          }          break;        case RESERVE2:          /* 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);            memdup((u_char **) &(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 *)malloc(1); /* bogus pointer */            StorageNew->snmpNotifyRowStatus = set_value;            snmp_free_var(vars);          }                    break;        case FREE:          /* XXX: free, zero vars */          /* Release any resources that have been allocated */          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)                 snmpNotifyTable_add(StorageNew);               /* XXX: ack, and if it is NULL? */             } else if (set_value != RS_DESTROY) {               /* set the flag? */               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) {               StorageTmp->snmpNotifyRowStatus = 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) {            StorageDel = NULL;            /* XXX: free it, its dead */          }          if (StorageTmp && StorageTmp->snmpNotifyRowStatus == RS_CREATEANDGO) {              StorageTmp->snmpNotifyRowStatus = RS_ACTIVE;          } else if (StorageTmp &&                     StorageTmp->snmpNotifyRowStatus == RS_CREATEANDWAIT) {              StorageTmp->snmpNotifyRowStatus = RS_NOTINSERVICE;          }          break;  }  return SNMP_ERR_NOERROR;}

⌨️ 快捷键说明

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