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.

150 lines
3.2 KiB

  1. /*++
  2. Copyright (c) 1992-1997 Microsoft Corporation
  3. Module Name:
  4. vb.c
  5. Abstract:
  6. Contains routines to manipulate variable bindings.
  7. SnmpUtilVarBindCpy
  8. SnmpUtilVarBindFree
  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. SnmpUtilVarBindCpy(
  28. SnmpVarBind * pVbDst,
  29. SnmpVarBind * pVbSrc
  30. )
  31. /*++
  32. Routine Description:
  33. Copies a variable binding.
  34. Arguments:
  35. pVbDst - pointer to structure to receive VarBind.
  36. pVbSrc - pointer to VarBind to copy.
  37. Return Values:
  38. Returns SNMPAPI_NOERROR if successful.
  39. --*/
  40. {
  41. SNMPAPI nResult = SNMPAPI_ERROR;
  42. // validate pointer
  43. if (pVbDst != NULL) {
  44. // initialize destination
  45. pVbDst->value.asnType = ASN_NULL;
  46. // validate pointer
  47. if (pVbSrc != NULL) {
  48. // copy the variable's name from source to destination
  49. nResult = SnmpUtilOidCpy(&pVbDst->name, &pVbSrc->name);
  50. // validate return code
  51. if (nResult == SNMPAPI_NOERROR) {
  52. // copy the variable's value from source to destination
  53. nResult = SnmpUtilAsnAnyCpy(&pVbDst->value, &pVbSrc->value);
  54. }
  55. } else {
  56. SNMPDBG((
  57. SNMP_LOG_WARNING,
  58. "SNMP: API: copying null varbind.\n"
  59. ));
  60. nResult = SNMPAPI_NOERROR; // success..,
  61. }
  62. } else {
  63. SNMPDBG((
  64. SNMP_LOG_ERROR,
  65. "SNMP: API: null varbind pointer.\n"
  66. ));
  67. SetLastError(ERROR_INVALID_PARAMETER);
  68. }
  69. // validate return code
  70. if (nResult == SNMPAPI_ERROR) {
  71. // release new variable
  72. SnmpUtilVarBindFree(pVbDst);
  73. }
  74. return nResult;
  75. }
  76. VOID
  77. SNMP_FUNC_TYPE
  78. SnmpUtilVarBindFree(
  79. SnmpVarBind * pVb
  80. )
  81. /*++
  82. Routine Description:
  83. Releases memory associated with variable binding.
  84. Arguments:
  85. pVb - pointer to VarBind to release.
  86. Return Values:
  87. None.
  88. --*/
  89. {
  90. // validate
  91. if (pVb != NULL) {
  92. // release variable name
  93. SnmpUtilOidFree(&pVb->name);
  94. // release variable value
  95. SnmpUtilAsnAnyFree(&pVb->value);
  96. }
  97. }