Leaked source code of windows server 2003
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.

160 lines
3.3 KiB

  1. /*++
  2. Copyright (c) 1992-1997 Microsoft Corporation
  3. Module Name:
  4. any.c
  5. Abstract:
  6. Contains routines to manipulate AsnAny structures.
  7. SnmpUtilAsnAnyCpy
  8. SnmpUtilAsnAnyFree
  9. Environment:
  10. User Mode - Win32
  11. Revision History:
  12. --*/
  13. ///////////////////////////////////////////////////////////////////////////////
  14. // //
  15. // Include files //
  16. // //
  17. ///////////////////////////////////////////////////////////////////////////////
  18. #include <snmp.h>
  19. #include <snmputil.h>
  20. ///////////////////////////////////////////////////////////////////////////////
  21. // //
  22. // Public Procedures //
  23. // //
  24. ///////////////////////////////////////////////////////////////////////////////
  25. SNMPAPI
  26. SNMP_FUNC_TYPE
  27. SnmpUtilAsnAnyCpy(
  28. AsnAny * pAnyDst,
  29. AsnAny * pAnySrc
  30. )
  31. /*++
  32. Routine Description:
  33. Copy a variable value.
  34. Arguments:
  35. pAnyDst - pointer to structure to receive value.
  36. pAnySrc - pointer to value to copy.
  37. Return Values:
  38. Returns SNMPAPI_NOERROR if successful.
  39. --*/
  40. {
  41. SNMPAPI nResult = SNMPAPI_NOERROR;
  42. // determine asn type
  43. switch (pAnySrc->asnType) {
  44. case ASN_OBJECTIDENTIFIER:
  45. // copy object identifier
  46. nResult = SnmpUtilOidCpy(
  47. &pAnyDst->asnValue.object,
  48. &pAnySrc->asnValue.object
  49. );
  50. break;
  51. case ASN_OPAQUE:
  52. case ASN_IPADDRESS:
  53. case ASN_OCTETSTRING:
  54. case ASN_BITS:
  55. // copy octet string
  56. nResult = SnmpUtilOctetsCpy(
  57. &pAnyDst->asnValue.string,
  58. &pAnySrc->asnValue.string
  59. );
  60. break;
  61. default:
  62. // simply transfer entire structure
  63. pAnyDst->asnValue = pAnySrc->asnValue;
  64. break;
  65. }
  66. // transfer type to destination
  67. pAnyDst->asnType = pAnySrc->asnType;
  68. return nResult;
  69. }
  70. VOID
  71. SNMP_FUNC_TYPE
  72. SnmpUtilAsnAnyFree(
  73. AsnAny * pAny
  74. )
  75. /*++
  76. Routine Description:
  77. Release memory associated with variable value.
  78. Arguments:
  79. pAny - pointer to variable value to free.
  80. Return Values:
  81. None.
  82. --*/
  83. {
  84. // determine asn type
  85. switch (pAny->asnType) {
  86. case ASN_OBJECTIDENTIFIER:
  87. // free object identifier
  88. SnmpUtilOidFree(&pAny->asnValue.object);
  89. break;
  90. case ASN_OPAQUE:
  91. case ASN_IPADDRESS:
  92. case ASN_OCTETSTRING:
  93. case ASN_BITS:
  94. // free octet string
  95. if (pAny->asnValue.string.dynamic)
  96. {
  97. SnmpUtilOctetsFree(&pAny->asnValue.string);
  98. pAny->asnValue.string.dynamic = FALSE;
  99. pAny->asnValue.string.stream = NULL;
  100. }
  101. break;
  102. default:
  103. break;
  104. }
  105. // re-initialize
  106. pAny->asnType = ASN_NULL;
  107. }