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.

228 lines
9.9 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 2000-2002 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: dplegacy.cpp
  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. #include "dnaddri.h"
  17. #ifndef DPNBUILD_NOLEGACYDP
  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. #ifndef DPNBUILD_NOPARAMVAL
  50. // TODO: MASONB: Are these supposed to all be using element 1?
  51. if( !DNVALID_STRING_A( (char *) &pdpAddressElement[1] ) )
  52. {
  53. hr = DPNERR_INVALIDADDRESSFORMAT;
  54. }
  55. else
  56. #endif // !DPNBUILD_NOPARAMVAL
  57. {
  58. WCHAR * pwszTemp;
  59. pwszTemp = (WCHAR*) DNMalloc(pdpAddressElement->dwDataSize * 2);
  60. if (pwszTemp == NULL)
  61. {
  62. DPFX(DPFPREP, 0, "Error allocating memory for conversion");
  63. hr = DPNERR_OUTOFMEMORY;
  64. break;
  65. }
  66. hr = STR_jkAnsiToWide(pwszTemp, (const char * const) &pdpAddressElement[1], pdpAddressElement->dwDataSize);
  67. if( FAILED( hr ) )
  68. {
  69. DPFX(DPFPREP, 0, "Error unable to convert element ANSI->Unicode 0x%x", hr );
  70. hr = DPNERR_CONVERSION;
  71. }
  72. else
  73. {
  74. hr = pdpAddress->SetElement( dpLegacyMap[dwIndex].m_wszKeyName, pwszTemp, (pdpAddressElement->dwDataSize * 2), DPNA_DATATYPE_STRING );
  75. }
  76. DNFree(pwszTemp);
  77. }
  78. break;
  79. case DPNA_DATATYPE_DPCOMPORTADDRESS:
  80. pPortAddress = (PDPCOMPORTADDRESS) &pdpAddressElement[1];
  81. swprintf( chPortBuffer, L"COM%u", pPortAddress->dwComPort );
  82. hr = pdpAddress->SetElement( DPNA_KEY_STOPBITS, chPortBuffer, (wcslen( chPortBuffer )+1)*sizeof(WCHAR), DPNA_DATATYPE_STRING );
  83. if( FAILED( hr ) )
  84. {
  85. DPFX(DPFPREP, 0, "Unable to specify port element hr=[0x%lx]", hr );
  86. break;
  87. }
  88. hr = pdpAddress->SetElement( DPNA_KEY_BAUD, &pPortAddress->dwBaudRate, sizeof( DWORD ), DPNA_DATATYPE_DWORD );
  89. if( FAILED( hr ) )
  90. {
  91. DPFX(DPFPREP, 0, "Unable to specify baudrate element hr=[0x%lx]", hr );
  92. break;
  93. }
  94. switch( pPortAddress->dwStopBits )
  95. {
  96. case ONESTOPBIT:
  97. hr = pdpAddress->SetElement( DPNA_KEY_STOPBITS, &DPNA_STOP_BITS_ONE, (wcslen( DPNA_STOP_BITS_ONE )+1)*sizeof(WCHAR), DPNA_DATATYPE_STRING );
  98. break;
  99. case ONE5STOPBITS:
  100. hr = pdpAddress->SetElement( DPNA_KEY_STOPBITS, &DPNA_STOP_BITS_ONE_FIVE, (wcslen( DPNA_STOP_BITS_ONE_FIVE )+1)*sizeof(WCHAR), DPNA_DATATYPE_STRING );
  101. break;
  102. case TWOSTOPBITS:
  103. hr = pdpAddress->SetElement( DPNA_KEY_STOPBITS, &DPNA_STOP_BITS_TWO, (wcslen( DPNA_STOP_BITS_TWO )+1)*sizeof(WCHAR), DPNA_DATATYPE_STRING );
  104. break;
  105. default:
  106. hr = DPNERR_INVALIDADDRESSFORMAT;
  107. }
  108. if( FAILED( hr ) )
  109. {
  110. DPFX(DPFPREP, 0, "Error converting stopbits element hr=[0x%lx]", hr );
  111. break;
  112. }
  113. switch( pPortAddress->dwParity )
  114. {
  115. case NOPARITY:
  116. hr = pdpAddress->SetElement( DPNA_KEY_PARITY, &DPNA_PARITY_NONE, (wcslen( DPNA_PARITY_NONE )+1)*sizeof(WCHAR), DPNA_DATATYPE_STRING );
  117. break;
  118. case ODDPARITY:
  119. hr = pdpAddress->SetElement( DPNA_KEY_PARITY, &DPNA_PARITY_ODD, (wcslen( DPNA_PARITY_ODD )+1)*sizeof(WCHAR), DPNA_DATATYPE_STRING );
  120. break;
  121. case EVENPARITY:
  122. hr = pdpAddress->SetElement( DPNA_KEY_PARITY, &DPNA_PARITY_EVEN, (wcslen( DPNA_PARITY_EVEN )+1)*sizeof(WCHAR), DPNA_DATATYPE_STRING );
  123. break;
  124. case MARKPARITY:
  125. hr = pdpAddress->SetElement( DPNA_KEY_PARITY, &DPNA_PARITY_MARK, (wcslen( DPNA_PARITY_MARK )+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 parity element hr=[0x%lx]", hr );
  133. break;
  134. }
  135. switch( pPortAddress->dwFlowControl )
  136. {
  137. case DPCPA_NOFLOW:
  138. hr = pdpAddress->SetElement( DPNA_KEY_FLOWCONTROL, &DPNA_FLOW_CONTROL_NONE, (wcslen( DPNA_KEY_FLOWCONTROL )+1)*sizeof(WCHAR), DPNA_DATATYPE_STRING );
  139. break;
  140. case DPCPA_XONXOFFFLOW:
  141. hr = pdpAddress->SetElement( DPNA_KEY_FLOWCONTROL, &DPNA_FLOW_CONTROL_XONXOFF, (wcslen( DPNA_FLOW_CONTROL_XONXOFF )+1)*sizeof(WCHAR), DPNA_DATATYPE_STRING );
  142. break;
  143. case DPCPA_RTSFLOW:
  144. hr = pdpAddress->SetElement( DPNA_KEY_FLOWCONTROL, &DPNA_FLOW_CONTROL_RTS, (wcslen( DPNA_FLOW_CONTROL_RTS )+1)*sizeof(WCHAR), DPNA_DATATYPE_STRING );
  145. break;
  146. case DPCPA_DTRFLOW:
  147. hr = pdpAddress->SetElement( DPNA_KEY_FLOWCONTROL, &DPNA_FLOW_CONTROL_DTR, (wcslen( DPNA_FLOW_CONTROL_DTR )+1)*sizeof(WCHAR), DPNA_DATATYPE_STRING );
  148. break;
  149. case DPCPA_RTSDTRFLOW:
  150. hr = pdpAddress->SetElement( DPNA_KEY_FLOWCONTROL, &DPNA_FLOW_CONTROL_RTSDTR, (wcslen( DPNA_FLOW_CONTROL_RTSDTR )+1)*sizeof(WCHAR), DPNA_DATATYPE_STRING );
  151. break;
  152. default:
  153. hr = DPNERR_INVALIDADDRESSFORMAT;
  154. }
  155. if( FAILED( hr ) )
  156. {
  157. DPFX(DPFPREP, 0, "Error converting flow control element hr=[0x%lx]", hr );
  158. break;
  159. }
  160. break;
  161. case DPNA_DATATYPE_DWORD:
  162. if( pdpAddressElement->dwDataSize != sizeof( DWORD ) )
  163. hr = DPNERR_INVALIDADDRESSFORMAT;
  164. else
  165. hr = pdpAddress->SetElement( dpLegacyMap[dwIndex].m_wszKeyName, (LPVOID) &pdpAddressElement[1], pdpAddressElement->dwDataSize, DPNA_DATATYPE_DWORD );
  166. break;
  167. case DPNA_DATATYPE_GUID:
  168. if( pdpAddressElement->dwDataSize != sizeof( GUID ) )
  169. hr = DPNERR_INVALIDADDRESSFORMAT;
  170. else
  171. hr = pdpAddress->SetElement( dpLegacyMap[dwIndex].m_wszKeyName, (LPVOID) &pdpAddressElement[1], pdpAddressElement->dwDataSize, DPNA_DATATYPE_GUID );
  172. break;
  173. case DPNA_DATATYPE_STRING:
  174. #ifndef DPNBUILD_NOPARAMVAL
  175. if( !DNVALID_STRING_W( (WCHAR *) &pdpAddressElement[1] ) )
  176. hr = DPNERR_INVALIDADDRESSFORMAT;
  177. else
  178. #endif // !DPNBUILD_NOPARAMVAL
  179. hr = pdpAddress->SetElement( dpLegacyMap[dwIndex].m_wszKeyName, (LPVOID) &pdpAddressElement[1], pdpAddressElement->dwDataSize, DPNA_DATATYPE_STRING );
  180. break;
  181. case DPNA_DATATYPE_NOP:
  182. hr = DPN_OK;
  183. break;
  184. default:
  185. hr = DPNERR_INVALIDADDRESSFORMAT;
  186. break;
  187. }
  188. break;
  189. }
  190. }
  191. if( dwIndex == DPLEGACY_ELEMENTS )
  192. {
  193. DPFX(DPFPREP, 0, "Address contains an element which cannot be mapped" );
  194. return DPNERR_INVALIDADDRESSFORMAT;
  195. }
  196. return hr;
  197. }
  198. #endif // ! DPNBUILD_NOLEGACYDP