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.

310 lines
6.7 KiB

  1. /*++
  2. * File name:
  3. * scfuncsa.c
  4. * Contents:
  5. * Ascii version of the functions exported by scfuncs.c
  6. * Used by the perl extension
  7. *
  8. * Copyright (C) 1998-1999 Microsoft Corp.
  9. *
  10. --*/
  11. #include <windows.h>
  12. #include <string.h>
  13. #include <malloc.h>
  14. #define PROTOCOLAPI
  15. #include "protocol.h"
  16. #include "tclient.h"
  17. #include "scfuncs.h"
  18. /*
  19. * External functions definitions
  20. */
  21. #include "extraexp.h"
  22. /*
  23. * Internal functions definitions
  24. */
  25. LPWSTR _Ascii2Wide(char *ascii);
  26. /*++
  27. * Function:
  28. * SCConnectExA
  29. * Description:
  30. * Ascii version of SCConnectEx. Converts LPSTR params to LPWSTR
  31. * Arguments:
  32. * same as SCConnect
  33. * Return value:
  34. * the return value of SCConnect
  35. * Called by:
  36. * unknown (exported)
  37. --*/
  38. PROTOCOLAPI
  39. LPCSTR
  40. SMCAPI
  41. SCConnectExA (
  42. char *lpszServerName,
  43. char *lpszUserName,
  44. char *lpszPassword,
  45. char *lpszDomain,
  46. char *lpszShell,
  47. int xResolution,
  48. int yResolution,
  49. int ConnectinFlags,
  50. int Bpp,
  51. int AudioOpts,
  52. PCONNECTINFO *ppConnectData)
  53. {
  54. LPWSTR wszServerName, wszUserName, wszPassword, wszDomain;
  55. LPWSTR wszShell;
  56. LPCSTR rv = NULL;
  57. wszServerName = _Ascii2Wide(lpszServerName);
  58. wszUserName = _Ascii2Wide(lpszUserName);
  59. wszPassword = _Ascii2Wide(lpszPassword);
  60. wszDomain = _Ascii2Wide(lpszDomain);
  61. wszShell = _Ascii2Wide(lpszShell);
  62. if (wszServerName &&
  63. wszUserName &&
  64. wszPassword &&
  65. wszDomain)
  66. rv = SCConnectEx(wszServerName,
  67. wszUserName,
  68. wszPassword,
  69. wszDomain,
  70. wszShell, // NULL is default shell
  71. xResolution,
  72. yResolution,
  73. ConnectinFlags,
  74. Bpp,
  75. AudioOpts,
  76. (PCONNECTINFO *) ppConnectData);
  77. else
  78. rv = ERR_ALLOCATING_MEMORY;
  79. if (wszServerName)
  80. free(wszServerName);
  81. if (wszUserName)
  82. free(wszUserName);
  83. if (wszPassword)
  84. free(wszPassword);
  85. if (wszDomain)
  86. free(wszDomain);
  87. if (wszShell)
  88. free(wszShell);
  89. return rv;
  90. }
  91. /*++
  92. * Function:
  93. * SCConnectA
  94. * Description:
  95. * Ascii version of SCConnect. Converts LPSTR params to LPWSTR
  96. * Arguments:
  97. * same as SCConnect
  98. * Return value:
  99. * the return value of SCConnect
  100. * Called by:
  101. * !tclntpll.xs
  102. --*/
  103. PROTOCOLAPI
  104. LPCSTR
  105. SMCAPI
  106. SCConnectA (char *lpszServerName,
  107. char *lpszUserName,
  108. char *lpszPassword,
  109. char *lpszDomain,
  110. int xResolution,
  111. int yResolution,
  112. PCONNECTINFO *ppConnectData)
  113. {
  114. LPWSTR wszServerName, wszUserName, wszPassword, wszDomain;
  115. LPCSTR rv = NULL;
  116. wszServerName = _Ascii2Wide(lpszServerName);
  117. wszUserName = _Ascii2Wide(lpszUserName);
  118. wszPassword = _Ascii2Wide(lpszPassword);
  119. wszDomain = _Ascii2Wide(lpszDomain);
  120. if (wszServerName &&
  121. wszUserName &&
  122. wszPassword &&
  123. wszDomain)
  124. rv = SCConnect(wszServerName,
  125. wszUserName,
  126. wszPassword,
  127. wszDomain,
  128. xResolution,
  129. yResolution,
  130. (PCONNECTINFO *) ppConnectData);
  131. else
  132. rv = ERR_ALLOCATING_MEMORY;
  133. if (wszServerName)
  134. free(wszServerName);
  135. if (wszUserName)
  136. free(wszUserName);
  137. if (wszPassword)
  138. free(wszPassword);
  139. if (wszDomain)
  140. free(wszDomain);
  141. return rv;
  142. }
  143. /*++
  144. * Function:
  145. * SCStartA
  146. * Description:
  147. * Ascii version of SCStart
  148. * Arguments:
  149. * same as SCStart
  150. * Return value:
  151. * return value from SCStart
  152. * Called by:
  153. * !tclntpll.xs
  154. --*/
  155. PROTOCOLAPI
  156. LPCSTR
  157. SMCAPI
  158. SCStartA( PCONNECTINFO pConnectData, char *command)
  159. {
  160. LPWSTR wcmd;
  161. LPCSTR rv = NULL;
  162. wcmd = _Ascii2Wide(command);
  163. if (wcmd)
  164. {
  165. rv = SCStart( (PCONNECTINFO) pConnectData, wcmd);
  166. } else {
  167. rv = ERR_ALLOCATING_MEMORY;
  168. }
  169. if (wcmd)
  170. free(wcmd);
  171. return rv;
  172. }
  173. /*++
  174. * Function:
  175. * SCCheckA
  176. * Description:
  177. * Ascii version of SCCheck
  178. * Arguments:
  179. * same as SCCheck
  180. * Return value:
  181. * return value from SCCheck
  182. * Called by:
  183. * !tclntpll.xs
  184. --*/
  185. PROTOCOLAPI
  186. LPCSTR
  187. SMCAPI
  188. SCCheckA( PCONNECTINFO pConnectData, char *command, char *param)
  189. {
  190. LPWSTR wparam;
  191. LPCSTR rv = NULL;
  192. wparam = _Ascii2Wide(param);
  193. if (wparam)
  194. {
  195. rv = SCCheck( (PCONNECTINFO) pConnectData, command, wparam);
  196. } else {
  197. rv = ERR_ALLOCATING_MEMORY;
  198. }
  199. if (wparam)
  200. free(wparam);
  201. return rv;
  202. }
  203. /*++
  204. * Function:
  205. * SCSendtextAsMsgsA
  206. * Description:
  207. * Ascii version of SCSendtextAsMsgs
  208. * Arguments:
  209. * same as SCSendtextAsMsgs
  210. * Return value:
  211. * return value from SCSendtextAsMsgs
  212. * Called by:
  213. * !tclntpll.xs
  214. --*/
  215. PROTOCOLAPI
  216. LPCSTR
  217. SMCAPI
  218. SCSendtextAsMsgsA( PCONNECTINFO pConnectData, char *line)
  219. {
  220. LPWSTR wline;
  221. LPCSTR rv = NULL;
  222. wline = _Ascii2Wide(line);
  223. if (wline)
  224. rv = SCSendtextAsMsgs( (PCONNECTINFO) pConnectData, wline);
  225. else
  226. rv = ERR_ALLOCATING_MEMORY;
  227. if (wline)
  228. free(wline);
  229. return rv;
  230. }
  231. /*++
  232. * Function:
  233. * _Ascii2Wide
  234. * Description:
  235. * Allocates buffer and converts an ascii string
  236. * to unicode
  237. * Arguments:
  238. * ascii - the input string
  239. * Return value:
  240. * pointer to converted string
  241. * Called by:
  242. * SCConnectA, SCStartA, SCCheckA, SCSendtextAsMsgsA
  243. --*/
  244. LPWSTR _Ascii2Wide(char *ascii)
  245. {
  246. LPWSTR wszWide = NULL;
  247. INT_PTR wsize;
  248. INT_PTR ccLen;
  249. if (!ascii)
  250. goto exitpt;
  251. ccLen = strlen(ascii);
  252. wsize = (ccLen + 1) * sizeof(WCHAR);
  253. wszWide = (LPWSTR) malloc(wsize);
  254. //
  255. // MultiByteToWideChar uses an int for the character count, which is
  256. // theoretically insufficient on Win64.
  257. //
  258. if (wszWide)
  259. MultiByteToWideChar(
  260. CP_UTF8,
  261. 0,
  262. ascii,
  263. -1,
  264. wszWide,
  265. (int)(ccLen + 1));
  266. exitpt:
  267. return wszWide;
  268. }