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.

195 lines
8.6 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 2000 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: dplegacy.h
  6. * Content: Definitions for old DirectPlay's address type
  7. *@@BEGIN_MSINTERNAL
  8. * History:
  9. * Date By Reason
  10. * ==== == ======
  11. * 03/21/2000 rmt Created
  12. * 07/21/2000 rmt Minor bug fixes to dplay4 address parsing.
  13. *@@END_MSINTERNAL
  14. *
  15. ***************************************************************************/
  16. // XBOX! This module shouldn't be needed for XBOX
  17. #include "dnaddri.h"
  18. #define DPLEGACY_ELEMENTS 11
  19. DPLEGACYMAPGUIDTOSTRING dpLegacyMap [DPLEGACY_ELEMENTS] =
  20. {
  21. DPLEGACYMAPGUIDTOSTRING( DPAID_ServiceProvider, DPNA_KEY_PROVIDER, DPNA_DATATYPE_GUID ),
  22. DPLEGACYMAPGUIDTOSTRING( DPAID_ComPort, DPNA_KEY_PORT, DPNA_DATATYPE_DPCOMPORTADDRESS ),
  23. DPLEGACYMAPGUIDTOSTRING( DPAID_INet, DPNA_KEY_HOSTNAME, DPNA_DATATYPE_STRING_ANSI ),
  24. DPLEGACYMAPGUIDTOSTRING( DPAID_INetW, DPNA_KEY_HOSTNAME, DPNA_DATATYPE_STRING ),
  25. DPLEGACYMAPGUIDTOSTRING( DPAID_INetPort, DPNA_KEY_PORT, DPNA_DATATYPE_DWORD ),
  26. DPLEGACYMAPGUIDTOSTRING( DPAID_LobbyProvider, L"lobbyprovider", DPNA_DATATYPE_GUID ),
  27. DPLEGACYMAPGUIDTOSTRING( DPAID_Modem, L"modemname", DPNA_DATATYPE_STRING_ANSI ),
  28. DPLEGACYMAPGUIDTOSTRING( DPAID_ModemW, L"modemname", DPNA_DATATYPE_STRING ),
  29. DPLEGACYMAPGUIDTOSTRING( DPAID_Phone, DPNA_KEY_PHONENUMBER, DPNA_DATATYPE_STRING_ANSI ),
  30. DPLEGACYMAPGUIDTOSTRING( DPAID_PhoneW, DPNA_KEY_PHONENUMBER, DPNA_DATATYPE_STRING ),
  31. DPLEGACYMAPGUIDTOSTRING( DPAID_TotalSize, DPNA_KEY_PORT, DPNA_DATATYPE_NOP )
  32. };
  33. #undef DPF_MODNAME
  34. #define DPF_MODNAME "AddDP4Element"
  35. HRESULT AddDP4Element( PDPADDRESS pdpAddressElement, PDP8ADDRESSOBJECT pdpAddress )
  36. {
  37. DWORD dwIndex;
  38. HRESULT hr = DPN_OK;
  39. PDPCOMPORTADDRESS pPortAddress;
  40. WCHAR chPortBuffer[30];
  41. // Loop through entries
  42. for( dwIndex = 0 ; dwIndex < sizeof( dpLegacyMap ) / sizeof( DPLEGACYMAPGUIDTOSTRING ); dwIndex++ )
  43. {
  44. if( dpLegacyMap[dwIndex].m_guidType == pdpAddressElement->guidDataType )
  45. {
  46. switch( dpLegacyMap[dwIndex].m_dwDataType )
  47. {
  48. case DPNA_DATATYPE_STRING_ANSI:
  49. if( !DNVALID_STRING_A( (char *) &pdpAddressElement[1] ) )
  50. hr = DPNERR_INVALIDADDRESSFORMAT;
  51. else
  52. hr = pdpAddress->SetElement( dpLegacyMap[dwIndex].m_wszKeyName, (LPVOID) &pdpAddressElement[1], pdpAddressElement->dwDataSize, DPNA_DATATYPE_STRING_ANSI );
  53. break;
  54. case DPNA_DATATYPE_DPCOMPORTADDRESS:
  55. pPortAddress = (PDPCOMPORTADDRESS) &pdpAddressElement[1];
  56. swprintf( chPortBuffer, L"COM%u", pPortAddress->dwComPort );
  57. hr = pdpAddress->SetElement( DPNA_KEY_STOPBITS, chPortBuffer, (wcslen( chPortBuffer )+1)*sizeof(WCHAR), DPNA_DATATYPE_STRING );
  58. if( FAILED( hr ) )
  59. {
  60. DPFX(DPFPREP, 0, "Unable to specify port element hr=[0x%lx]", hr );
  61. break;
  62. }
  63. hr = pdpAddress->SetElement( DPNA_KEY_BAUD, &pPortAddress->dwBaudRate, sizeof( DWORD ), DPNA_DATATYPE_DWORD );
  64. if( FAILED( hr ) )
  65. {
  66. DPFX(DPFPREP, 0, "Unable to specify baudrate element hr=[0x%lx]", hr );
  67. break;
  68. }
  69. switch( pPortAddress->dwStopBits )
  70. {
  71. case ONESTOPBIT:
  72. hr = pdpAddress->SetElement( DPNA_KEY_STOPBITS, &DPNA_STOP_BITS_ONE, (wcslen( DPNA_STOP_BITS_ONE )+1)*sizeof(WCHAR), DPNA_DATATYPE_STRING );
  73. break;
  74. case ONE5STOPBITS:
  75. hr = pdpAddress->SetElement( DPNA_KEY_STOPBITS, &DPNA_STOP_BITS_ONE_FIVE, (wcslen( DPNA_STOP_BITS_ONE_FIVE )+1)*sizeof(WCHAR), DPNA_DATATYPE_STRING );
  76. break;
  77. case TWOSTOPBITS:
  78. hr = pdpAddress->SetElement( DPNA_KEY_STOPBITS, &DPNA_STOP_BITS_TWO, (wcslen( DPNA_STOP_BITS_TWO )+1)*sizeof(WCHAR), DPNA_DATATYPE_STRING );
  79. break;
  80. default:
  81. hr = DPNERR_INVALIDADDRESSFORMAT;
  82. }
  83. if( FAILED( hr ) )
  84. {
  85. DPFX(DPFPREP, 0, "Error converting stopbits element hr=[0x%lx]", hr );
  86. break;
  87. }
  88. switch( pPortAddress->dwParity )
  89. {
  90. case NOPARITY:
  91. hr = pdpAddress->SetElement( DPNA_KEY_PARITY, &DPNA_PARITY_NONE, (wcslen( DPNA_PARITY_NONE )+1)*sizeof(WCHAR), DPNA_DATATYPE_STRING );
  92. break;
  93. case ODDPARITY:
  94. hr = pdpAddress->SetElement( DPNA_KEY_PARITY, &DPNA_PARITY_ODD, (wcslen( DPNA_PARITY_ODD )+1)*sizeof(WCHAR), DPNA_DATATYPE_STRING );
  95. break;
  96. case EVENPARITY:
  97. hr = pdpAddress->SetElement( DPNA_KEY_PARITY, &DPNA_PARITY_EVEN, (wcslen( DPNA_PARITY_EVEN )+1)*sizeof(WCHAR), DPNA_DATATYPE_STRING );
  98. break;
  99. case MARKPARITY:
  100. hr = pdpAddress->SetElement( DPNA_KEY_PARITY, &DPNA_PARITY_MARK, (wcslen( DPNA_PARITY_MARK )+1)*sizeof(WCHAR), DPNA_DATATYPE_STRING );
  101. break;
  102. default:
  103. hr = DPNERR_INVALIDADDRESSFORMAT;
  104. }
  105. if( FAILED( hr ) )
  106. {
  107. DPFX(DPFPREP, 0, "Error converting parity element hr=[0x%lx]", hr );
  108. break;
  109. }
  110. switch( pPortAddress->dwFlowControl )
  111. {
  112. case DPCPA_NOFLOW:
  113. hr = pdpAddress->SetElement( DPNA_KEY_FLOWCONTROL, &DPNA_FLOW_CONTROL_NONE, (wcslen( DPNA_KEY_FLOWCONTROL )+1)*sizeof(WCHAR), DPNA_DATATYPE_STRING );
  114. break;
  115. case DPCPA_XONXOFFFLOW:
  116. hr = pdpAddress->SetElement( DPNA_KEY_FLOWCONTROL, &DPNA_FLOW_CONTROL_XONXOFF, (wcslen( DPNA_FLOW_CONTROL_XONXOFF )+1)*sizeof(WCHAR), DPNA_DATATYPE_STRING );
  117. break;
  118. case DPCPA_RTSFLOW:
  119. hr = pdpAddress->SetElement( DPNA_KEY_FLOWCONTROL, &DPNA_FLOW_CONTROL_RTS, (wcslen( DPNA_FLOW_CONTROL_RTS )+1)*sizeof(WCHAR), DPNA_DATATYPE_STRING );
  120. break;
  121. case DPCPA_DTRFLOW:
  122. hr = pdpAddress->SetElement( DPNA_KEY_FLOWCONTROL, &DPNA_FLOW_CONTROL_DTR, (wcslen( DPNA_FLOW_CONTROL_DTR )+1)*sizeof(WCHAR), DPNA_DATATYPE_STRING );
  123. break;
  124. case DPCPA_RTSDTRFLOW:
  125. hr = pdpAddress->SetElement( DPNA_KEY_FLOWCONTROL, &DPNA_FLOW_CONTROL_RTSDTR, (wcslen( DPNA_FLOW_CONTROL_RTSDTR )+1)*sizeof(WCHAR), DPNA_DATATYPE_STRING );
  126. break;
  127. default:
  128. hr = DPNERR_INVALIDADDRESSFORMAT;
  129. }
  130. if( FAILED( hr ) )
  131. {
  132. DPFX(DPFPREP, 0, "Error converting flow control element hr=[0x%lx]", hr );
  133. break;
  134. }
  135. break;
  136. case DPNA_DATATYPE_DWORD:
  137. if( pdpAddressElement->dwDataSize != sizeof( DWORD ) )
  138. hr = DPNERR_INVALIDADDRESSFORMAT;
  139. else
  140. hr = pdpAddress->SetElement( dpLegacyMap[dwIndex].m_wszKeyName, (LPVOID) &pdpAddressElement[1], pdpAddressElement->dwDataSize, DPNA_DATATYPE_DWORD );
  141. break;
  142. case DPNA_DATATYPE_GUID:
  143. if( pdpAddressElement->dwDataSize != sizeof( GUID ) )
  144. hr = DPNERR_INVALIDADDRESSFORMAT;
  145. else
  146. hr = pdpAddress->SetElement( dpLegacyMap[dwIndex].m_wszKeyName, (LPVOID) &pdpAddressElement[1], pdpAddressElement->dwDataSize, DPNA_DATATYPE_GUID );
  147. break;
  148. case DPNA_DATATYPE_STRING:
  149. if( !DNVALID_STRING_W( (WCHAR *) &pdpAddressElement[1] ) )
  150. hr = DPNERR_INVALIDADDRESSFORMAT;
  151. else
  152. hr = pdpAddress->SetElement( dpLegacyMap[dwIndex].m_wszKeyName, (LPVOID) &pdpAddressElement[1], pdpAddressElement->dwDataSize, DPNA_DATATYPE_STRING );
  153. break;
  154. case DPNA_DATATYPE_NOP:
  155. hr = DPN_OK;
  156. break;
  157. default:
  158. hr = DPNERR_INVALIDADDRESSFORMAT;
  159. break;
  160. }
  161. break;
  162. }
  163. }
  164. if( dwIndex == DPLEGACY_ELEMENTS )
  165. {
  166. DPFX(DPFPREP, 0, "Address contains an element which cannot be mapped" );
  167. return DPNERR_INVALIDADDRESSFORMAT;
  168. }
  169. return hr;
  170. }