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.

202 lines
3.9 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. testdll.c
  5. Abstract:
  6. Sample SNMP subagent.
  7. --*/
  8. #include "precomp.h"
  9. #pragma hdrstop
  10. #if defined( MIB_DEBUG )
  11. DWORD g_dwTraceId = INVALID_TRACEID;
  12. #endif
  13. MIB_SERVER_HANDLE g_hMIBServer = ( MIB_SERVER_HANDLE) NULL;
  14. //
  15. // Critical Section to control access to variable g_hMIBServer
  16. //
  17. CRITICAL_SECTION g_CS;
  18. // Extension Agent DLLs need access to elapsed time agent has been active.
  19. // This is implemented by initializing the Extension Agent with a time zero
  20. // reference, and allowing the agent to compute elapsed time by subtracting
  21. // the time zero reference from the current system time.
  22. DWORD g_uptimeReference = 0;
  23. //
  24. // Handle to Subagent Framework
  25. //
  26. SnmpTfxHandle g_tfxHandle;
  27. ///////////////////////////////////////////////////////////////////////////////
  28. // //
  29. // Subagent entry points //
  30. // //
  31. ///////////////////////////////////////////////////////////////////////////////
  32. BOOL
  33. SnmpExtensionInit(
  34. IN DWORD uptimeReference,
  35. OUT HANDLE * lpPollForTrapEvent,
  36. OUT AsnObjectIdentifier * lpFirstSupportedView
  37. )
  38. {
  39. DWORD dwRes = (DWORD) -1;
  40. #if defined( MIB_DEBUG )
  41. //
  42. // tracing for DEBUG
  43. //
  44. g_dwTraceId = TraceRegister( "BOOTP Subagent" );
  45. #endif
  46. // save uptime reference
  47. g_uptimeReference = uptimeReference;
  48. // obtain handle to subagent framework
  49. g_tfxHandle = SnmpTfxOpen(1,&v_msipbootp);
  50. // validate handle
  51. if (g_tfxHandle == NULL) {
  52. return FALSE;
  53. }
  54. // pass back first view identifier to master
  55. *lpFirstSupportedView = v_msipbootp.viewOid;
  56. // traps not supported yet
  57. *lpPollForTrapEvent = NULL;
  58. //
  59. // Verify router service is running
  60. //
  61. if ( !MprAdminIsServiceRunning( NULL ) )
  62. {
  63. return TRUE;
  64. }
  65. //
  66. // Connect to router
  67. //
  68. dwRes = MprAdminMIBServerConnect(
  69. NULL,
  70. &g_hMIBServer
  71. );
  72. if ( dwRes != NO_ERROR )
  73. {
  74. return FALSE;
  75. }
  76. return TRUE;
  77. }
  78. BOOL
  79. SnmpExtensionQuery(
  80. IN BYTE requestType,
  81. IN OUT RFC1157VarBindList * variableBindings,
  82. OUT AsnInteger * errorStatus,
  83. OUT AsnInteger * errorIndex
  84. )
  85. {
  86. // forward to framework
  87. return SnmpTfxQuery(
  88. g_tfxHandle,
  89. requestType,
  90. variableBindings,
  91. errorStatus,
  92. errorIndex
  93. );
  94. }
  95. BOOL
  96. SnmpExtensionTrap(
  97. OUT AsnObjectIdentifier *enterprise,
  98. OUT AsnInteger *genericTrap,
  99. OUT AsnInteger *specificTrap,
  100. OUT AsnTimeticks *timeStamp,
  101. OUT RFC1157VarBindList *variableBindings
  102. )
  103. {
  104. // no traps
  105. return FALSE;
  106. }
  107. BOOL WINAPI
  108. DllMain(
  109. HINSTANCE hInstDLL,
  110. DWORD fdwReason,
  111. LPVOID pReserved
  112. )
  113. {
  114. switch ( fdwReason )
  115. {
  116. case DLL_PROCESS_ATTACH :
  117. {
  118. DisableThreadLibraryCalls( hInstDLL );
  119. InitializeCriticalSection( &g_CS );
  120. break;
  121. }
  122. case DLL_PROCESS_DETACH :
  123. {
  124. //
  125. // Disconnect from router
  126. //
  127. if ( g_hMIBServer )
  128. {
  129. MprAdminMIBServerDisconnect( g_hMIBServer );
  130. }
  131. DeleteCriticalSection( &g_CS );
  132. #if defined( MIB_DEBUG )
  133. if ( g_dwTraceId != INVALID_TRACEID )
  134. {
  135. TraceDeregister( g_dwTraceId );
  136. }
  137. #endif
  138. break;
  139. }
  140. default :
  141. {
  142. break;
  143. }
  144. }
  145. return TRUE;
  146. }