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.

217 lines
5.5 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1999-2000 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: ParseClass.cpp
  6. * Content: Parsing class
  7. *
  8. *
  9. * History:
  10. * Date By Reason
  11. * ==== == ======
  12. * 121/02/99 jtk Derived from IPXAddress.cpp
  13. * 01/10/20000 rmt Updated to build with Millenium build process
  14. ***************************************************************************/
  15. #include "dnmdmi.h"
  16. //**********************************************************************
  17. // Constant definitions
  18. //**********************************************************************
  19. //
  20. // default buffer size to use when parsing address components
  21. //
  22. #define DEFAULT_COMPONENT_BUFFER_SIZE 1000
  23. //**********************************************************************
  24. // Macro definitions
  25. //**********************************************************************
  26. //**********************************************************************
  27. // Structure definitions
  28. //**********************************************************************
  29. //**********************************************************************
  30. // Variable definitions
  31. //**********************************************************************
  32. //**********************************************************************
  33. // Function prototypes
  34. //**********************************************************************
  35. //**********************************************************************
  36. // Function definitions
  37. //**********************************************************************
  38. //**********************************************************************
  39. // ------------------------------
  40. // CParseClass::ParseDP8Address - parse a DirectPlay8 address
  41. //
  42. // Entry: Pointer to DP8Address
  43. // Pointer to expected SP guid
  44. // Pointer to parse keys
  45. // Count of parse keys
  46. //
  47. // Exit: Error code
  48. // ------------------------------
  49. #undef DPF_MODNAME
  50. #define DPF_MODNAME "CParseClass::ParseDP8Address"
  51. HRESULT CParseClass::ParseDP8Address( IDirectPlay8Address *const pDP8Address,
  52. const GUID *const pSPGuid,
  53. const PARSE_KEY *const pParseKeys,
  54. const UINT_PTR uParseKeyCount )
  55. {
  56. HRESULT hr;
  57. BOOL fParsing;
  58. #ifndef DPNBUILD_ONLYONESP
  59. GUID Guid;
  60. #endif // ! DPNBUILD_ONLYONESP
  61. void *pAddressComponent;
  62. DWORD dwComponentSize;
  63. DWORD dwAllocatedComponentSize;
  64. UINT_PTR uIndex;
  65. DNASSERT( pDP8Address != NULL );
  66. DNASSERT( pSPGuid != NULL );
  67. DNASSERT( pParseKeys != NULL );
  68. DNASSERT( uParseKeyCount != 0 );
  69. //
  70. // initialize
  71. //
  72. hr = DPN_OK;
  73. fParsing = TRUE;
  74. dwAllocatedComponentSize = DEFAULT_COMPONENT_BUFFER_SIZE;
  75. uIndex = uParseKeyCount;
  76. pAddressComponent = DNMalloc( dwAllocatedComponentSize );
  77. if ( pAddressComponent == NULL )
  78. {
  79. hr = DPNERR_OUTOFMEMORY;
  80. DPFX(DPFPREP, 0, "ParseClass: failed to allocate temp buffer for parsing" );
  81. goto Exit;
  82. }
  83. #ifndef DPNBUILD_ONLYONESP
  84. //
  85. // verify SPType
  86. //
  87. hr = IDirectPlay8Address_GetSP( pDP8Address, &Guid );
  88. if ( hr != DPN_OK )
  89. {
  90. DPFX(DPFPREP, 0, "ParseClass: failed to verify service provider type!" );
  91. DisplayDNError( 0, hr );
  92. goto Exit;
  93. }
  94. if ( IsEqualCLSID( *pSPGuid, Guid ) == FALSE )
  95. {
  96. hr = DPNERR_ADDRESSING;
  97. DPFX(DPFPREP, 0, "Service provider guid mismatch during parse!" );
  98. goto Exit;
  99. }
  100. #endif // ! DPNBUILD_ONLYONESP
  101. //
  102. // parse
  103. //
  104. while ( uIndex != 0 )
  105. {
  106. HRESULT hTempResult;
  107. DWORD dwDataType;
  108. uIndex--;
  109. DNASSERT( pAddressComponent != NULL );
  110. dwComponentSize = dwAllocatedComponentSize;
  111. Reparse:
  112. hTempResult = IDirectPlay8Address_GetComponentByName( pDP8Address, // pointer to address
  113. pParseKeys[ uIndex ].pKey, // pointer to key to search for
  114. pAddressComponent, // pointer to value destination
  115. &dwComponentSize, // pointer to value destination size
  116. &dwDataType ); // pointer to data type
  117. switch ( hTempResult )
  118. {
  119. //
  120. // component parsed successfully, figure out what it is by checking
  121. // key length and then comparing key strings
  122. //
  123. case DPN_OK:
  124. {
  125. hr = pParseKeys[ uIndex ].pParseFunc( pAddressComponent,
  126. dwComponentSize,
  127. dwDataType,
  128. pParseKeys[ uIndex ].pContext
  129. );
  130. if ( hr != DPN_OK )
  131. {
  132. goto Exit;
  133. }
  134. break;
  135. }
  136. //
  137. // buffer too small, reallocate and try again
  138. //
  139. case DPNERR_BUFFERTOOSMALL:
  140. {
  141. DNASSERT( dwComponentSize > dwAllocatedComponentSize );
  142. DNASSERT( pAddressComponent != NULL );
  143. DNFree( pAddressComponent );
  144. pAddressComponent = DNMalloc( dwComponentSize );
  145. if ( pAddressComponent == NULL )
  146. {
  147. hr = DPNERR_OUTOFMEMORY;
  148. goto Exit;
  149. }
  150. dwAllocatedComponentSize = dwComponentSize;
  151. goto Reparse;
  152. break;
  153. }
  154. //
  155. // Missing component. Skip this component and
  156. // look for other parsing errors.
  157. //
  158. case DPNERR_DOESNOTEXIST:
  159. {
  160. break;
  161. }
  162. //
  163. // error
  164. //
  165. default:
  166. {
  167. hr = hTempResult;
  168. DPFX(DPFPREP, 0, "ParseClass: Problem parsing address!" );
  169. DisplayDNError( 0, hr );
  170. DNASSERT( FALSE );
  171. goto Exit;
  172. break;
  173. }
  174. }
  175. }
  176. Exit:
  177. if ( pAddressComponent != NULL )
  178. {
  179. DNFree( pAddressComponent );
  180. pAddressComponent = NULL;
  181. }
  182. return hr;
  183. }
  184. //**********************************************************************