void * header_hrstoreEntry(struct variable *vp, oid * name, size_t * length, int exact, size_t * var_len, WriteMethod ** write_method) { #define HRSTORE_ENTRY_NAME_LENGTH 11 oid newname[MAX_OID_LEN]; int storage_idx, LowIndex = -1; int result; int idx = -1; netsnmp_memory_info *mem = NULL; DEBUGMSGTL(("host/hr_storage", "var_hrstoreEntry: request ")); DEBUGMSGOID(("host/hr_storage", name, *length)); DEBUGMSG(("host/hr_storage", " exact=%d\n", exact)); memcpy((char *) newname, (char *) vp->name, (int) vp->namelen * sizeof(oid)); result = snmp_oid_compare(name, *length, vp->name, vp->namelen); DEBUGMSGTL(("host/hr_storage", "var_hrstoreEntry: compare ")); DEBUGMSGOID(("host/hr_storage", vp->name, vp->namelen)); DEBUGMSG(("host/hr_storage", " => %d\n", result)); if (result < 0 || *length <= HRSTORE_ENTRY_NAME_LENGTH ) { /* * Requested OID too early or too short to refer * to a valid row (for the current column object). * GET requests should fail, GETNEXT requests * should use the first row. */ if ( exact ) return NULL; netsnmp_memory_load(); mem = netsnmp_memory_get_first( 0 ); } else { /* * Otherwise, retrieve the requested * (or following) row as appropriate. */ if ( exact && *length > HRSTORE_ENTRY_NAME_LENGTH+1 ) return NULL; /* Too long for a valid instance */ idx = name[ HRSTORE_ENTRY_NAME_LENGTH ]; if ( idx < NETSNMP_MEM_TYPE_MAX ) { netsnmp_memory_load(); mem = ( exact ? netsnmp_memory_get_byIdx( idx, 0 ) : netsnmp_memory_get_next_byIdx( idx, 0 )); } } /* * If this matched a memory-based entry, then * update the OID parameter(s) for GETNEXT requests. */ if ( mem ) { if ( !exact ) { newname[ HRSTORE_ENTRY_NAME_LENGTH ] = mem->idx; memcpy((char *) name, (char *) newname, ((int) vp->namelen + 1) * sizeof(oid)); *length = vp->namelen + 1; } } /* * If this didn't match a memory-based entry, * then consider the disk-based storage. */ else { Init_HR_Store(); for (;;) { storage_idx = Get_Next_HR_Store(); DEBUGMSG(("host/hr_storage", "(index %d ....", storage_idx)); if (storage_idx == -1) break; newname[HRSTORE_ENTRY_NAME_LENGTH] = storage_idx; DEBUGMSGOID(("host/hr_storage", newname, *length)); DEBUGMSG(("host/hr_storage", "\n")); result = snmp_oid_compare(name, *length, newname, vp->namelen + 1); if (exact && (result == 0)) { LowIndex = storage_idx; /* * Save storage status information */ break; } if ((!exact && (result < 0)) && (LowIndex == -1 || storage_idx < LowIndex)) { LowIndex = storage_idx; /* * Save storage status information */ #ifdef HRSTORE_MONOTONICALLY_INCREASING break; #endif } } if ( LowIndex != -1 ) { if ( !exact ) { newname[ HRSTORE_ENTRY_NAME_LENGTH ] = LowIndex; memcpy((char *) name, (char *) newname, ((int) vp->namelen + 1) * sizeof(oid)); *length = vp->namelen + 1; } mem = (netsnmp_memory_info*)0xffffffff; /* To indicate 'success' */ } } *write_method = (WriteMethod*)0; *var_len = sizeof(long); /* default to 'long' results */ /* * ... and return the appropriate row */ DEBUGMSGTL(("host/hr_storage", "var_hrstoreEntry: process ")); DEBUGMSGOID(("host/hr_storage", name, *length)); DEBUGMSG(("host/hr_storage", " (%p)\n", mem)); return (void*)mem; }
int header_hrstoreEntry(struct variable *vp, oid * name, size_t * length, int exact, size_t * var_len, WriteMethod ** write_method) { #define HRSTORE_ENTRY_NAME_LENGTH 11 oid newname[MAX_OID_LEN]; int storage_idx, LowIndex = -1; int result; DEBUGMSGTL(("host/hr_storage", "var_hrstoreEntry: ")); DEBUGMSGOID(("host/hr_storage", name, *length)); DEBUGMSG(("host/hr_storage", " %d\n", exact)); memcpy((char *) newname, (char *) vp->name, (int) vp->namelen * sizeof(oid)); /* * Find "next" storage entry */ Init_HR_Store(); for (;;) { storage_idx = Get_Next_HR_Store(); DEBUGMSG(("host/hr_storage", "(index %d ....", storage_idx)); if (storage_idx == -1) break; newname[HRSTORE_ENTRY_NAME_LENGTH] = storage_idx; DEBUGMSGOID(("host/hr_storage", newname, *length)); DEBUGMSG(("host/hr_storage", "\n")); result = snmp_oid_compare(name, *length, newname, vp->namelen + 1); if (exact && (result == 0)) { LowIndex = storage_idx; /* * Save storage status information */ break; } if ((!exact && (result < 0)) && (LowIndex == -1 || storage_idx < LowIndex)) { LowIndex = storage_idx; /* * Save storage status information */ #ifdef HRSTORE_MONOTONICALLY_INCREASING break; #endif } } if (LowIndex == -1) { DEBUGMSGTL(("host/hr_storage", "... index out of range\n")); return (MATCH_FAILED); } memcpy((char *) name, (char *) newname, ((int) vp->namelen + 1) * sizeof(oid)); *length = vp->namelen + 1; *write_method = 0; *var_len = sizeof(long); /* default to 'long' results */ DEBUGMSGTL(("host/hr_storage", "... get storage stats ")); DEBUGMSGOID(("host/hr_storage", name, *length)); DEBUGMSG(("host/hr_storage", "\n")); return LowIndex; }