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.

382 lines
9.9 KiB

  1. /*++
  2. Copyright (C) 1996 Microsoft Corporation
  3. Module Name:
  4. nwatch95.c
  5. Abstract:
  6. Attachment routines for Win95
  7. Author:
  8. Felix Wong [t-felixw] 6-Sep-1996
  9. Revision History:
  10. --*/
  11. #include "procs.h"
  12. #include "nw95.h"
  13. BOOLEAN* NlsMbOemCodePageTag = FALSE;
  14. typedef struct _NWC_SERVER_INFO {
  15. HANDLE hConn ;
  16. UNICODE_STRING ServerString ;
  17. } NWC_SERVER_INFO, *PNWC_SERVER_INFO ;
  18. DWORD
  19. szToWide(
  20. LPWSTR lpszW,
  21. LPCSTR lpszC,
  22. INT nSize
  23. );
  24. HINSTANCE g_hinstDLL = NULL;
  25. // Forwards
  26. NWCCODE
  27. NWAttachToFileServerWin95(
  28. LPCSTR pszServerName,
  29. WORD ScopeFlag,
  30. NW_CONN_HANDLE *phNewConn
  31. );
  32. NWCCODE NWDetachFromFileServerWin95(
  33. NW_CONN_HANDLE hConn
  34. );
  35. DWORD
  36. WideToSz(
  37. LPSTR lpszC,
  38. LPCWSTR lpszW,
  39. INT nSize
  40. )
  41. {
  42. if (!WideCharToMultiByte(CP_ACP,
  43. WC_COMPOSITECHECK | WC_SEPCHARS,
  44. lpszW,
  45. -1,
  46. lpszC,
  47. nSize,
  48. NULL,
  49. NULL))
  50. {
  51. return (GetLastError()) ;
  52. }
  53. return NO_ERROR ;
  54. }
  55. NWCCODE NWAPI DLLEXPORT
  56. NWDetachFromFileServer(
  57. NWCONN_HANDLE hConn
  58. )
  59. {
  60. NWCCODE nwccode;
  61. PNWC_SERVER_INFO pServerInfo;
  62. if (!hConn)
  63. return (NWCCODE)UNSUCCESSFUL;
  64. pServerInfo = (PNWC_SERVER_INFO)hConn ;
  65. // Do not detach server since Win95 does not have reference count. We will just
  66. // wait for it to waitout and disconnect itself.
  67. // This is suggested by VladS.
  68. //nwccode = NWDetachFromFileServerWin95(pServerInfo->hConn);
  69. nwccode = SUCCESSFUL;
  70. if (pServerInfo->ServerString.Buffer != NULL) {
  71. (void) LocalFree (pServerInfo->ServerString.Buffer);
  72. pServerInfo->ServerString.Buffer = NULL;
  73. }
  74. pServerInfo->hConn = NULL ;
  75. (void) LocalFree (pServerInfo) ;
  76. return nwccode;
  77. }
  78. NWCCODE NWAPI DLLEXPORT
  79. NWAttachToFileServerW(
  80. const WCHAR NWFAR *pwszServerName,
  81. NWLOCAL_SCOPE ScopeFlag,
  82. NWCONN_HANDLE NWFAR *phNewConn
  83. )
  84. {
  85. NW_STATUS NwStatus;
  86. LPWSTR lpwszServerName = NULL; // Pointer to buffer for WIDE servername
  87. LPSTR lpszServerName = NULL;
  88. int nSize;
  89. PNWC_SERVER_INFO pServerInfo = NULL;
  90. UNREFERENCED_PARAMETER(ScopeFlag) ;
  91. //
  92. // check parameters and init return result to be null.
  93. //
  94. if (!pwszServerName || !phNewConn)
  95. return INVALID_CONNECTION ;
  96. *phNewConn = NULL ;
  97. // Setup lpszServerName, used to pass into NWAttachToFileServerWin95
  98. nSize = wcslen(pwszServerName) + 1;
  99. if(!(lpszServerName = (LPSTR) LocalAlloc(
  100. LPTR,
  101. nSize * sizeof(CHAR) )))
  102. {
  103. NwStatus = REQUESTER_ERROR ;
  104. goto ExitPoint ;
  105. }
  106. if (WideToSz( lpszServerName,
  107. pwszServerName,
  108. nSize ) != NO_ERROR)
  109. {
  110. NwStatus = REQUESTER_ERROR ;
  111. goto ExitPoint ;
  112. }
  113. // Setup lpwszServerName, used as storage in server handle
  114. nSize = nSize+2 ; // Adding 2 for the '\\'
  115. if(!(lpwszServerName = (LPWSTR) LocalAlloc(
  116. LPTR,
  117. nSize * sizeof(WCHAR) )))
  118. {
  119. NwStatus = REQUESTER_ERROR ;
  120. goto ExitPoint ;
  121. }
  122. wcscpy( lpwszServerName,
  123. L"\\\\" );
  124. wcscat( lpwszServerName,
  125. pwszServerName );
  126. //
  127. // Allocate a buffer for the server info (handle + name pointer). Also
  128. // init the unicode string.
  129. //
  130. if( !(pServerInfo = (PNWC_SERVER_INFO) LocalAlloc(
  131. LPTR,
  132. sizeof(NWC_SERVER_INFO))) )
  133. {
  134. NwStatus = REQUESTER_ERROR ;
  135. goto ExitPoint ;
  136. }
  137. RtlInitUnicodeString(&pServerInfo->ServerString, lpwszServerName) ;
  138. if (wcscmp(pwszServerName,L"*") != 0) {
  139. NwStatus = NWAttachToFileServerWin95(
  140. lpszServerName,
  141. ScopeFlag,
  142. &pServerInfo->hConn
  143. );
  144. }
  145. else {
  146. // hConn of NULL works as nearest server in Win95
  147. pServerInfo->hConn = NULL;
  148. NwStatus = SUCCESSFUL;
  149. }
  150. ExitPoint:
  151. //
  152. // Free the memory allocated above before exiting
  153. //
  154. if (lpszServerName)
  155. (void) LocalFree( (HLOCAL) lpszServerName );
  156. if (NwStatus != SUCCESSFUL) {
  157. // only deallocate if unsucessful, or else it will
  158. // be stored in pServerInfo->ServerString
  159. if (lpwszServerName)
  160. (void) LocalFree( (HLOCAL) lpwszServerName );
  161. if (pServerInfo)
  162. (void) LocalFree( (HLOCAL) pServerInfo );
  163. }
  164. else {
  165. *phNewConn = (HANDLE) pServerInfo ;
  166. }
  167. //
  168. // Return with NWCCODE
  169. //
  170. return( (NWCCODE)NwStatus );
  171. }
  172. NWCCODE NWAPI DLLEXPORT
  173. NWAttachToFileServer(
  174. const CHAR NWFAR *pszServerName,
  175. NWLOCAL_SCOPE ScopeFlag,
  176. NWCONN_HANDLE NWFAR *phNewConn
  177. )
  178. {
  179. NW_STATUS NwStatus;
  180. LPWSTR lpwszServerName = NULL; // Pointer to buffer for WIDE servername
  181. LPWSTR lpwszServerNameTmp = NULL;
  182. int nSize;
  183. PNWC_SERVER_INFO pServerInfo = NULL;
  184. UNREFERENCED_PARAMETER(ScopeFlag) ;
  185. //
  186. // check parameters and init return result to be null.
  187. //
  188. if (!pszServerName || !phNewConn)
  189. return INVALID_CONNECTION ;
  190. *phNewConn = NULL ;
  191. nSize = strlen(pszServerName) + 1;
  192. // Setup lpwszServerNameTmp
  193. if(!(lpwszServerNameTmp = (LPWSTR) LocalAlloc(
  194. LPTR,
  195. nSize * sizeof(WCHAR) )))
  196. {
  197. NwStatus = REQUESTER_ERROR ;
  198. goto ExitPoint ;
  199. }
  200. if (szToWide( lpwszServerNameTmp,
  201. pszServerName,
  202. nSize ) != NO_ERROR)
  203. {
  204. NwStatus = REQUESTER_ERROR ;
  205. goto ExitPoint ;
  206. }
  207. // Setup lpwszServerName for storage in server handle
  208. nSize = nSize + 2;
  209. if(!(lpwszServerName = (LPWSTR) LocalAlloc(
  210. LPTR,
  211. nSize * sizeof(WCHAR) )))
  212. {
  213. NwStatus = REQUESTER_ERROR ;
  214. goto ExitPoint ;
  215. }
  216. wcscpy( lpwszServerName,
  217. L"\\\\" );
  218. wcscat( lpwszServerName,
  219. lpwszServerNameTmp );
  220. //
  221. // Allocate a buffer for the server info (handle + name pointer). Also
  222. // init the unicode string.
  223. //
  224. if( !(pServerInfo = (PNWC_SERVER_INFO) LocalAlloc(
  225. LPTR,
  226. sizeof(NWC_SERVER_INFO))) )
  227. {
  228. NwStatus = REQUESTER_ERROR ;
  229. goto ExitPoint ;
  230. }
  231. RtlInitUnicodeString(&pServerInfo->ServerString, lpwszServerName) ;
  232. if (strcmp(pszServerName,"*") != 0) {
  233. NwStatus = NWAttachToFileServerWin95(
  234. pszServerName,
  235. ScopeFlag,
  236. &pServerInfo->hConn
  237. );
  238. }
  239. else {
  240. // hConn of NULL works as nearest server in Win95
  241. pServerInfo->hConn = NULL;
  242. NwStatus = SUCCESSFUL;
  243. }
  244. ExitPoint:
  245. //
  246. // Free the memory allocated above before exiting
  247. //
  248. if (lpwszServerNameTmp)
  249. (void) LocalFree( (HLOCAL) lpwszServerNameTmp );
  250. if (NwStatus != SUCCESSFUL) {
  251. // only deallocate if unsucessful, or else it will
  252. // be stored in pServerInfo->ServerString
  253. if (lpwszServerName)
  254. (void) LocalFree( (HLOCAL) lpwszServerName );
  255. if (pServerInfo)
  256. (void) LocalFree( (HLOCAL) pServerInfo );
  257. }
  258. else {
  259. *phNewConn = (HANDLE) pServerInfo ;
  260. }
  261. //
  262. // Return with NWCCODE
  263. //
  264. return( (NWCCODE)NwStatus );
  265. }
  266. NWCCODE
  267. NWAttachToFileServerWin95(
  268. LPCSTR pszServerName,
  269. WORD ScopeFlag,
  270. NW_CONN_HANDLE *phNewConn
  271. )
  272. {
  273. NW_STATUS nwstatusReturn = UNSUCCESSFUL;
  274. NW_STATUS (*lpfnAttachToFileServerWin95) (LPCSTR,
  275. WORD,
  276. NW_CONN_HANDLE
  277. );
  278. /* Load the NWAPI32.DLL library module. */
  279. if (g_hinstDLL == NULL)
  280. g_hinstDLL = LoadLibraryA("NWAPI32.DLL");
  281. if (g_hinstDLL == NULL) {
  282. goto Exit;
  283. }
  284. (FARPROC) lpfnAttachToFileServerWin95 =
  285. GetProcAddress(g_hinstDLL, "NWAttachToFileServer");
  286. if (lpfnAttachToFileServerWin95 == NULL)
  287. goto Exit;
  288. nwstatusReturn = (*lpfnAttachToFileServerWin95) (pszServerName,
  289. ScopeFlag,
  290. phNewConn
  291. );
  292. Exit:
  293. //FreeLibrary(hinstDLL);
  294. return (NWCCODE)nwstatusReturn;
  295. }
  296. NWCCODE NWDetachFromFileServerWin95(
  297. NW_CONN_HANDLE hConn
  298. )
  299. {
  300. NW_STATUS nwstatusReturn = UNSUCCESSFUL;
  301. NW_STATUS (*lpfnDetachFromFileServerWin95) (NW_CONN_HANDLE);
  302. /* Load the NWAPI32.DLL library module. */
  303. if (g_hinstDLL == NULL)
  304. g_hinstDLL = LoadLibraryA("NWAPI32.DLL");
  305. if (g_hinstDLL == NULL)
  306. goto Exit;
  307. (FARPROC) lpfnDetachFromFileServerWin95 =
  308. GetProcAddress(g_hinstDLL, "NWDetachFromFileServer");
  309. if (lpfnDetachFromFileServerWin95 == NULL)
  310. goto Exit;
  311. nwstatusReturn = (*lpfnDetachFromFileServerWin95) (hConn);
  312. Exit:
  313. //FreeLibrary(hinstDLL);
  314. return (NWCCODE)nwstatusReturn;
  315. }