Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.5 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1998, Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // snmpoid.cpp
  8. //
  9. // SYNOPSIS
  10. //
  11. // Defines the class SnmpOid.
  12. //
  13. // MODIFICATION HISTORY
  14. //
  15. // 09/10/1998 Original version.
  16. //
  17. ///////////////////////////////////////////////////////////////////////////////
  18. #include <ias.h>
  19. #include <snmpoid.h>
  20. SnmpOid& SnmpOid::operator=(const AsnObjectIdentifier& a)
  21. {
  22. // Note: self-assignment is benign, so we don't bother to check.
  23. resize(a.idLength);
  24. memcpy(oid.ids, a.ids, length() * sizeof(UINT));
  25. return *this;
  26. }
  27. bool SnmpOid::isChildOf(const AsnObjectIdentifier& parent) const throw ()
  28. {
  29. if (length() < parent.idLength)
  30. {
  31. return false;
  32. }
  33. return SnmpUtilOidNCmp(
  34. *this,
  35. const_cast<AsnObjectIdentifier*>(&parent),
  36. parent.idLength
  37. ) == 0;
  38. }
  39. void SnmpOid::resize(UINT newLength)
  40. {
  41. if (newLength <= length())
  42. {
  43. // Truncation is easy.
  44. oid.idLength = newLength;
  45. }
  46. else
  47. {
  48. // Try to extend our buffer.
  49. PVOID p = SnmpUtilMemReAlloc(oid.ids, newLength * sizeof(UINT));
  50. if (p == NULL) { throw (AsnInteger32)SNMP_MEM_ALLOC_ERROR; }
  51. // Swap in the extended buffer.
  52. oid.ids = (UINT*)p;
  53. // Zero out the added ID's.
  54. memset(oid.ids + length(), 0, (newLength - length()) * sizeof(UINT));
  55. // Update our length.
  56. oid.idLength = newLength;
  57. }
  58. }