📄 mteobjectstable.c
字号:
*/ 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->mteObjectsIDWildcard; StorageTmp->mteObjectsIDWildcard = *((long *) var_val); break; case UNDO: /* * Back out any changes made in the ACTION case */ StorageTmp->mteObjectsIDWildcard = 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_mteObjectsEntryStatus(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 mteObjectsTable_data *StorageTmp = NULL; static struct mteObjectsTable_data *StorageNew, *StorageDel; size_t newlen = name_len - (sizeof(mteObjectsTable_variables_oid) / sizeof(oid) + 3 - 1); static int old_value; int set_value; static netsnmp_variable_list *vars, *vp; struct header_complex_index *hciptr; StorageTmp = header_complex(mteObjectsTableStorage, NULL, &name[sizeof(mteObjectsTable_variables_oid) / sizeof(oid) + 3 - 1], &newlen, 1, NULL, NULL); if (var_val_type != ASN_INTEGER || var_val == NULL) { snmp_log(LOG_ERR, "write to mteObjectsEntryStatus not ASN_INTEGER\n"); return SNMP_ERR_WRONGTYPE; } if (StorageTmp && StorageTmp->storagetype == ST_READONLY) { return SNMP_ERR_NOTWRITABLE; } 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; /* * destroying a non-existent row is actually legal */ if (set_value == RS_DESTROY) { return SNMP_ERR_NOERROR; } /* * illegal creation values */ 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) { /* * creation */ vars = NULL; snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, NULL, 0); /* mteOwner */ snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, NULL, 0); /* mteObjectsName */ snmp_varlist_add_variable(&vars, NULL, 0, ASN_UNSIGNED, NULL, 0); /* mteObjectsIndex */ if (header_complex_parse_oid (& (name [sizeof(mteObjectsTable_variables_oid) / sizeof(oid) + 2]), newlen, vars) != SNMPERR_SUCCESS) { /* * XXX: free, zero vars */ return SNMP_ERR_INCONSISTENTNAME; } vp = vars; StorageNew = SNMP_MALLOC_STRUCT(mteObjectsTable_data); StorageNew->mteOwner = netsnmp_strdup_and_null(vp->val.string, vp->val_len); StorageNew->mteOwnerLen = vp->val_len; vp = vp->next_variable; StorageNew->mteObjectsName = netsnmp_strdup_and_null(vp->val.string, vp->val_len); StorageNew->mteObjectsNameLen = vp->val_len; vp = vp->next_variable; StorageNew->mteObjectsIndex = *(vp->val.integer); /* * XXX: fill in default row values here into StorageNew */ StorageNew->mteObjectsID = calloc(1, sizeof(oid) * sizeof(2)); /* 0.0 */ StorageNew->mteObjectsIDLen = 2; StorageNew->mteObjectsIDWildcard = MTEOBJECTSIDWILDCARD_FALSE; StorageNew->mteObjectsEntryStatus = set_value; /* * XXX: free, zero vars, no longer needed? */ } 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) { /* * row creation, so add it */ if (StorageNew != NULL) mteObjectsTable_add(StorageNew); /* * XXX: ack, and if it is NULL? */ } else if (set_value != RS_DESTROY) { /* * set the flag? */ old_value = StorageTmp->mteObjectsEntryStatus; StorageTmp->mteObjectsEntryStatus = *((long *) var_val); } else { /* * destroy... extract it for now */ hciptr = header_complex_find_entry(mteObjectsTableStorage, StorageTmp); StorageDel = header_complex_extract_entry(&mteObjectsTableStorage, hciptr); } break; case UNDO: /* * Back out any changes made in the ACTION case */ if (StorageTmp == NULL) { /* * row creation, so remove it again */ hciptr = header_complex_find_entry(mteObjectsTableStorage, StorageTmp); StorageDel = header_complex_extract_entry(&mteObjectsTableStorage, hciptr); /* * XXX: free it */ } else if (StorageDel != NULL) { /* * row deletion, so add it again */ mteObjectsTable_add(StorageDel); } else { StorageTmp->mteObjectsEntryStatus = 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 = 0; /* * XXX: free it, its dead */ } else { if (StorageTmp && StorageTmp->mteObjectsEntryStatus == RS_CREATEANDGO) { StorageTmp->mteObjectsEntryStatus = RS_ACTIVE; } else if (StorageTmp && StorageTmp->mteObjectsEntryStatus == RS_CREATEANDWAIT) { StorageTmp->mteObjectsEntryStatus = RS_NOTINSERVICE; } } break; } return SNMP_ERR_NOERROR;}voidmte_add_objects(netsnmp_variable_list * vars, struct mteTriggerTable_data *item, const char *owner, const char *name, oid * suffix, size_t suffix_len){ struct header_complex_index *hcptr = mteObjectsTableStorage; DEBUGMSGTL(("mteObjectsTable", "Searching for objects to add for owner=%s / name=%s\n", owner, name)); if (vars == NULL || item == NULL || owner == NULL || name == NULL || hcptr == NULL) return; /* * get to end of variable chain */ while (vars->next_variable != NULL) vars = vars->next_variable; /* * get to start of objects list */ while (hcptr && (strcmp(((struct mteObjectsTable_data *) hcptr->data)->mteOwner, owner) != 0 || strcmp(((struct mteObjectsTable_data *) hcptr->data)-> mteObjectsName, name) != 0)) hcptr = hcptr->next; /* * add all objects */ while (hcptr && strcmp(((struct mteObjectsTable_data *) hcptr->data)->mteOwner, owner) == 0 && strcmp(((struct mteObjectsTable_data *) hcptr->data)-> mteObjectsName, name) == 0) { /* * loop through objects */ netsnmp_pdu *pdu = NULL, *response = NULL; struct mteObjectsTable_data *node = (struct mteObjectsTable_data *) hcptr->data; oid theoid[MAX_OID_LEN]; size_t theoid_len; /* * copy in the suffix */ memcpy(theoid, node->mteObjectsID, node->mteObjectsIDLen * sizeof(oid)); theoid_len = node->mteObjectsIDLen; if (node->mteObjectsIDWildcard == MTEOBJECTSIDWILDCARD_TRUE && suffix && suffix_len > 0) { theoid_len += suffix_len; if (theoid_len > MAX_OID_LEN) { break; /* XXX: properly send trap or something? */ } memcpy(&theoid[node->mteObjectsIDLen], suffix, suffix_len * sizeof(oid)); } /* * retrieve the value */ pdu = snmp_pdu_create(SNMP_MSG_GET); snmp_add_null_var(pdu, theoid, theoid_len); response = mte_get_response(item, pdu); if (response) { if (vars) { vars->next_variable = response->variables; vars = vars->next_variable; DEBUGMSGTL(("mteObjectsTable", "Adding: ")); DEBUGMSGOID(("mteObjectsTable", response->variables->name, response->variables->name_length)); DEBUGMSG(("mteObjectsTable", "\n")); } else { vars = response->variables; } /* * erase response notion of the values we stole from it */ response->variables = NULL; snmp_free_pdu(response); } /* * move along */ hcptr = hcptr->next; } DEBUGMSGTL(("mteObjectsTable", "Done adding objects\n"));}intmte_add_object_to_table(const char *owner, const char *objname, oid * oidname, size_t oidname_len, int iswild){ struct header_complex_index *hcptr = mteObjectsTableStorage, *lastnode; static struct mteObjectsTable_data *StorageNew; /* * malloc initial struct */ StorageNew = SNMP_MALLOC_STRUCT(mteObjectsTable_data); StorageNew->mteOwner = netsnmp_strdup_and_null(owner, strlen(owner)); StorageNew->mteOwnerLen = strlen(owner); StorageNew->mteObjectsName = netsnmp_strdup_and_null(objname, strlen(objname)); StorageNew->mteObjectsNameLen = strlen(objname); /* * find the next number */ /* * get to start of objects list */ while (hcptr && (strcmp(((struct mteObjectsTable_data *) hcptr->data)->mteOwner, owner) != 0 || strcmp(((struct mteObjectsTable_data *) hcptr->data)-> mteObjectsName, objname) != 0)) hcptr = hcptr->next; if (hcptr) { /* * an object existed. Find the first one past and increment * the previous number */ lastnode = hcptr; while (hcptr && strcmp(((struct mteObjectsTable_data *) hcptr->data)-> mteOwner, owner) == 0 && strcmp(((struct mteObjectsTable_data *) hcptr->data)-> mteObjectsName, objname) == 0) { lastnode = hcptr; hcptr = hcptr->next; } StorageNew->mteObjectsIndex = ((struct mteObjectsTable_data *) lastnode->data)-> mteObjectsIndex + 1; } else { StorageNew->mteObjectsIndex = 1; } /* * XXX: fill in default row values here into StorageNew */ StorageNew->mteObjectsID = snmp_duplicate_objid(oidname, oidname_len); StorageNew->mteObjectsIDLen = oidname_len; if (iswild) StorageNew->mteObjectsIDWildcard = MTEOBJECTSIDWILDCARD_TRUE; else StorageNew->mteObjectsIDWildcard = MTEOBJECTSIDWILDCARD_FALSE; StorageNew->mteObjectsEntryStatus = RS_ACTIVE; StorageNew->storagetype = ST_READONLY; return mteObjectsTable_add(StorageNew);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -