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.

263 lines
5.1 KiB

  1. /*++
  2. Copyright (c) 1999-2000 Microsoft Corporation
  3. Module Name:
  4. RemoteDesktopUtils
  5. Abstract:
  6. Misc. RD Utils
  7. Author:
  8. Tad Brockway 02/00
  9. Revision History:
  10. --*/
  11. #ifdef TRC_FILE
  12. #undef TRC_FILE
  13. #endif
  14. #define TRC_FILE "_rdutl"
  15. #include <RemoteDesktop.h>
  16. #include <atlbase.h>
  17. #include "RemoteDesktopUtils.h"
  18. BSTR
  19. CreateConnectParmsString(
  20. IN DWORD protocolType,
  21. IN CComBSTR &machineName,
  22. IN CComBSTR &assistantAccount,
  23. IN CComBSTR &assistantAccountPwd,
  24. IN LONG helpSessionID,
  25. IN CComBSTR &helpSessionName,
  26. IN CComBSTR &helpSessionPwd,
  27. IN CComBSTR &protocolSpecificParms
  28. )
  29. /*++
  30. Routine Description:
  31. Create a connect parms string. Format is:
  32. "protocolType,machineName,assistantAccount,assistantAccountPwd,helpSessionName,helpSessionPwd,protocolSpecificParms"
  33. Arguments:
  34. protocolType - Identifies the protocol type.
  35. See RemoteDesktopChannels.h
  36. machineName - Identifies network address of server machine.
  37. assistantAccountName - Account name for initial log in to server
  38. machine.
  39. assistantAccountNamePwd - Password for assistantAccountName
  40. helpSessionID - Help session identifier.
  41. helpSessionName - Help session name.
  42. helpSessionPwd - Password to help session once logged in to server
  43. machine.
  44. protocolSpecificParms - Parameters specific to a particular protocol.
  45. Return Value:
  46. --*/
  47. {
  48. DC_BEGIN_FN("CreateConnectParmsString");
  49. CComBSTR result;
  50. WCHAR buf[256];
  51. wsprintf(buf, TEXT("%ld"), protocolType);
  52. result = buf;
  53. result += TEXT(",");
  54. result += machineName;
  55. result += TEXT(",");
  56. result += assistantAccount;
  57. result += TEXT(",");
  58. result += assistantAccountPwd;
  59. result += TEXT(",");
  60. wsprintf(buf, TEXT("%ld"), helpSessionID);
  61. result += buf;
  62. result += TEXT(",");
  63. result += helpSessionName;
  64. result += TEXT(",");
  65. result += helpSessionPwd;
  66. if (protocolSpecificParms.Length() > 0) {
  67. result += TEXT(",");
  68. result += protocolSpecificParms;
  69. }
  70. DC_END_FN();
  71. return result.Detach();
  72. }
  73. DWORD
  74. ParseConnectParmsString(
  75. IN BSTR parmsString,
  76. OUT DWORD *protocolType,
  77. OUT CComBSTR &machineName,
  78. OUT CComBSTR &assistantAccount,
  79. OUT CComBSTR &assistantAccountPwd,
  80. OUT LONG *helpSessionID,
  81. OUT CComBSTR &helpSessionName,
  82. OUT CComBSTR &helpSessionPwd,
  83. OUT CComBSTR &protocolSpecificParms
  84. )
  85. /*++
  86. Routine Description:
  87. Parse a connect string created by a call to CreateConnectParmsString.
  88. Arguments:
  89. Return Value:
  90. ERROR_SUCCESS on success. Otherwise, an error code is returned.
  91. --*/
  92. {
  93. DC_BEGIN_FN("ParseConnectParmsString");
  94. BSTR tmp;
  95. WCHAR *tok;
  96. DWORD result = ERROR_SUCCESS;
  97. DWORD len;
  98. //
  99. // Make a copy of the input string so we can parse it.
  100. //
  101. tmp = SysAllocString(parmsString);
  102. if (tmp == NULL) {
  103. TRC_ERR((TB, TEXT("Can't allocate parms string.")));
  104. result = ERROR_OUTOFMEMORY;
  105. goto CLEANUPANDEXIT;
  106. }
  107. //
  108. // Protocol.
  109. //
  110. tok = wcstok(tmp, L",");
  111. if (tok != NULL) {
  112. *protocolType = _wtoi(tok);
  113. }
  114. //
  115. // Machine Name
  116. //
  117. tok = wcstok(NULL, L",");
  118. if (tok != NULL) {
  119. machineName = tok;
  120. }
  121. else {
  122. result = ERROR_INVALID_USER_BUFFER;
  123. goto CLEANUPANDEXIT;
  124. }
  125. //
  126. // Assistant Account
  127. //
  128. tok = wcstok(NULL, L",");
  129. if (tok != NULL) {
  130. assistantAccount = tok;
  131. }
  132. else {
  133. result = ERROR_INVALID_USER_BUFFER;
  134. goto CLEANUPANDEXIT;
  135. }
  136. //
  137. // Assistant Account Password
  138. //
  139. tok = wcstok(NULL, L",");
  140. if (tok != NULL) {
  141. assistantAccountPwd = tok;
  142. }
  143. else {
  144. result = ERROR_INVALID_USER_BUFFER;
  145. goto CLEANUPANDEXIT;
  146. }
  147. //
  148. // Help Session ID
  149. //
  150. tok = wcstok(NULL, L",");
  151. if (tok != NULL) {
  152. *helpSessionID = _wtoi(tok);
  153. }
  154. else {
  155. result = ERROR_INVALID_USER_BUFFER;
  156. goto CLEANUPANDEXIT;
  157. }
  158. //
  159. // Help Session Name
  160. //
  161. tok = wcstok(NULL, L",");
  162. if (tok != NULL) {
  163. helpSessionName = tok;
  164. }
  165. else {
  166. result = ERROR_INVALID_USER_BUFFER;
  167. goto CLEANUPANDEXIT;
  168. }
  169. //
  170. // Help Session Password
  171. //
  172. tok = wcstok(NULL, L",");
  173. if (tok != NULL) {
  174. helpSessionPwd = tok;
  175. }
  176. else {
  177. result = ERROR_INVALID_USER_BUFFER;
  178. goto CLEANUPANDEXIT;
  179. }
  180. //
  181. // Protocol-Specific Parms
  182. //
  183. len = wcslen(parmsString);
  184. if (tok < (tmp + len)) {
  185. tok += wcslen(tok);
  186. tok += 1;
  187. if (*tok != L'\0') {
  188. protocolSpecificParms = tok;
  189. }
  190. else {
  191. protocolSpecificParms = L"";
  192. }
  193. }
  194. else {
  195. protocolSpecificParms = L"";
  196. }
  197. CLEANUPANDEXIT:
  198. if (result != ERROR_SUCCESS) {
  199. TRC_ERR((TB, TEXT("Error parsing %s"), parmsString));
  200. }
  201. if (tmp != NULL) {
  202. SysFreeString(tmp);
  203. }
  204. DC_END_FN();
  205. return result;
  206. }