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.

143 lines
3.0 KiB

  1. //+-----------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (c) Microsoft Corporation
  6. //
  7. // File: kpcontext.cxx
  8. //
  9. // Contents: Routines for managing contexts.
  10. //
  11. // History: 10-Jul-2001 t-ryanj Created
  12. //
  13. //------------------------------------------------------------------------
  14. #include "kpcontext.h"
  15. //+-------------------------------------------------------------------------
  16. //
  17. // Function: KpAcquireContext
  18. //
  19. // Synopsis: Creates a context for the http session associated with
  20. // pECB. This context should be released with KpReleaseContext.
  21. //
  22. // Effects:
  23. //
  24. // Arguments: pECB - Extension control block provided by ISAPI
  25. //
  26. // Requires:
  27. //
  28. // Returns: The context.
  29. //
  30. // Notes:
  31. //
  32. //--------------------------------------------------------------------------
  33. PKPCONTEXT
  34. KpAcquireContext(
  35. LPEXTENSION_CONTROL_BLOCK pECB
  36. )
  37. {
  38. DebugLog( DEB_TRACE, "%s(%d): Acquiring context.\n", __FILE__, __LINE__ );
  39. //
  40. // Alloc memory for the context.
  41. //
  42. PKPCONTEXT pContext = (PKPCONTEXT)KpAlloc( sizeof( KPCONTEXT ) );
  43. ZeroMemory( pContext, sizeof( KPCONTEXT ) );
  44. if( pContext )
  45. {
  46. pContext->databuf = (LPBYTE)KpAlloc( pECB->cbTotalBytes );
  47. if( !pContext->databuf )
  48. goto Error;
  49. //
  50. // Populate with initial context settings.
  51. //
  52. pContext->pECB = pECB;
  53. pContext->buflen = pECB->cbTotalBytes;
  54. pContext->dwStatus = KP_HTTP_READ;
  55. //
  56. // Copy the data we have
  57. //
  58. memcpy( pContext->databuf, pECB->lpbData, pECB->cbAvailable );
  59. //
  60. // Remember how much more data we have.
  61. //
  62. pContext->emptybytes = pContext->buflen - pECB->cbAvailable;
  63. }
  64. Cleanup:
  65. return pContext;
  66. Error:
  67. if( pContext )
  68. {
  69. if( pContext->databuf )
  70. KpFree( pContext->databuf );
  71. KpFree( pContext );
  72. pContext = NULL;
  73. }
  74. goto Cleanup;
  75. }
  76. //+-------------------------------------------------------------------------
  77. //
  78. // Function: KpReleaseContext
  79. //
  80. // Synopsis: Releases a context and frees its resources.
  81. //
  82. // Effects:
  83. //
  84. // Arguments: pContext
  85. //
  86. // Requires:
  87. //
  88. // Returns:
  89. //
  90. // Notes:
  91. //
  92. //--------------------------------------------------------------------------
  93. VOID
  94. KpReleaseContext(
  95. PKPCONTEXT pContext
  96. )
  97. {
  98. DebugLog( DEB_TRACE, "%s(%d): Releasing context.\n", __FILE__, __LINE__ );
  99. if( pContext->KdcSock )
  100. closesocket(pContext->KdcSock);
  101. //
  102. // Release the HTTP connection.
  103. //
  104. if( pContext->pECB )
  105. {
  106. pContext->pECB->ServerSupportFunction( pContext->pECB->ConnID,
  107. HSE_REQ_DONE_WITH_SESSION,
  108. NULL,
  109. NULL,
  110. NULL );
  111. pContext->pECB = NULL;
  112. }
  113. if( pContext->databuf )
  114. KpFree( pContext->databuf );
  115. //
  116. // Free the memory.
  117. //
  118. KpFree( pContext );
  119. }