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.

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