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.

441 lines
11 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. gfrapiw.cxx
  5. Abstract:
  6. UNICODE versions of Windows Internet Extensions (WINX) Gopher Protocol APIs
  7. (in gfrapia.c)
  8. Contents:
  9. GopherCreateLocatorW
  10. GopherGetLocatorType
  11. GopherFindFirstFileW
  12. GopherFindNextW
  13. GopherOpenFileW
  14. GopherGetAttributeW
  15. GopherSendDataW
  16. Author:
  17. Richard L Firth (rfirth) 31-Oct-1994
  18. Environment:
  19. Win32 user-level DLL
  20. Revision History:
  21. 31-Oct-1994 rfirth
  22. Created
  23. --*/
  24. #include <wininetp.h>
  25. #include "gfrapih.h"
  26. //
  27. // functions
  28. //
  29. INTERNETAPI_(BOOL) GopherCreateLocatorW(
  30. IN LPCWSTR lpszHost,
  31. IN INTERNET_PORT nServerPort,
  32. IN LPCWSTR lpszDisplayString OPTIONAL,
  33. IN LPCWSTR lpszSelectorString OPTIONAL,
  34. IN DWORD dwGopherType,
  35. OUT LPWSTR lpszLocator,
  36. IN OUT LPDWORD lpdwBufferLength
  37. )
  38. {
  39. DEBUG_ENTER_API((DBG_API,
  40. Bool,
  41. "GopherCreateLocatorW",
  42. "%wq, %d, %wq, %wq, %#x, %#x, %#x [%d]",
  43. lpszHost,
  44. nServerPort,
  45. lpszDisplayString,
  46. lpszSelectorString,
  47. dwGopherType,
  48. lpszLocator,
  49. lpdwBufferLength,
  50. lpdwBufferLength ? *lpdwBufferLength : 0
  51. ));
  52. DWORD dwErr = ERROR_SUCCESS;
  53. MEMORYPACKET mpLocator,mpDisplay,mpSelector,mpHost;
  54. BOOL fResult = FALSE;
  55. if (!lpszHost || !lpdwBufferLength
  56. || (IsBadStringPtrW(lpszHost, INTERNET_MAX_PATH_LENGTH + 1))
  57. || (IsBadWritePtr(lpdwBufferLength, sizeof(*lpdwBufferLength))))
  58. {
  59. dwErr = ERROR_INVALID_PARAMETER;
  60. goto cleanup;
  61. }
  62. ALLOC_MB(lpszHost,0,mpHost);
  63. if (!mpHost.psStr)
  64. {
  65. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  66. goto cleanup;
  67. }
  68. UNICODE_TO_ANSI(lpszHost,mpHost);
  69. if (lpszDisplayString)
  70. {
  71. ALLOC_MB(lpszDisplayString,0,mpDisplay);
  72. if (!mpDisplay.psStr)
  73. {
  74. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  75. goto cleanup;
  76. }
  77. UNICODE_TO_ANSI(lpszDisplayString,mpDisplay);
  78. }
  79. if (lpszSelectorString)
  80. {
  81. ALLOC_MB(lpszSelectorString,0,mpSelector);
  82. if (!mpSelector.psStr)
  83. {
  84. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  85. goto cleanup;
  86. }
  87. UNICODE_TO_ANSI(lpszSelectorString,mpSelector);
  88. }
  89. mpLocator.dwSize = *lpdwBufferLength;
  90. if (lpszLocator)
  91. {
  92. mpLocator.dwAlloc = *lpdwBufferLength*sizeof(CHAR);
  93. mpLocator.psStr = (LPSTR)ALLOC_BYTES(mpLocator.dwAlloc);
  94. if (!mpLocator.psStr)
  95. {
  96. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  97. goto cleanup;
  98. }
  99. }
  100. fResult = GopherCreateLocatorA(mpHost.psStr,nServerPort,mpDisplay.psStr,mpSelector.psStr,
  101. dwGopherType,mpLocator.psStr,&mpLocator.dwSize);
  102. *lpdwBufferLength = mpLocator.dwSize*sizeof(WCHAR);
  103. if (fResult && (*lpdwBufferLength <= mpLocator.dwAlloc))
  104. {
  105. *lpdwBufferLength = (MultiByteToWideChar(CP_ACP, 0, mpLocator.psStr, -1,
  106. lpszLocator, mpLocator.dwAlloc/sizeof(WCHAR))+1)*sizeof(WCHAR);
  107. }
  108. cleanup:
  109. if (dwErr!=ERROR_SUCCESS)
  110. {
  111. SetLastError(dwErr);
  112. DEBUG_ERROR(API, dwErr);
  113. }
  114. DEBUG_LEAVE_API(fResult);
  115. return fResult;
  116. }
  117. INTERNETAPI_(BOOL) GopherGetLocatorTypeW(
  118. IN LPCWSTR lpszLocator,
  119. OUT LPDWORD lpdwGopherType
  120. )
  121. {
  122. DEBUG_ENTER_API((DBG_API,
  123. Bool,
  124. "GopherGetLocatorTypeW",
  125. "%wq, %#x",
  126. lpszLocator,
  127. lpdwGopherType
  128. ));
  129. DWORD dwErr = ERROR_SUCCESS;
  130. BOOL fResult = FALSE;
  131. MEMORYPACKET mpLocator;
  132. if (!lpszLocator)
  133. {
  134. dwErr = ERROR_INVALID_PARAMETER;
  135. goto cleanup;
  136. }
  137. ALLOC_MB(lpszLocator,0,mpLocator);
  138. if (!mpLocator.psStr)
  139. {
  140. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  141. goto cleanup;
  142. }
  143. UNICODE_TO_ANSI(lpszLocator,mpLocator);
  144. fResult = GopherGetLocatorTypeA(mpLocator.psStr,lpdwGopherType);
  145. cleanup:
  146. if (dwErr!=ERROR_SUCCESS)
  147. {
  148. SetLastError(dwErr);
  149. DEBUG_ERROR(API, dwErr);
  150. }
  151. DEBUG_LEAVE_API(fResult);
  152. return fResult;
  153. }
  154. BOOL
  155. TransformGopherFindDataToW(LPGOPHER_FIND_DATAA pgfdA, LPGOPHER_FIND_DATAW pgfdW)
  156. {
  157. pgfdW->GopherType = pgfdA->GopherType;
  158. pgfdW->SizeLow = pgfdA->SizeLow;
  159. pgfdW->SizeHigh = pgfdA->SizeHigh;
  160. pgfdW->LastModificationTime = pgfdA->LastModificationTime;
  161. MultiByteToWideChar(CP_ACP, 0, pgfdA->DisplayString, -1,
  162. pgfdW->DisplayString, MAX_GOPHER_DISPLAY_TEXT + 1);
  163. MultiByteToWideChar(CP_ACP, 0, pgfdA->Locator, -1,
  164. pgfdW->Locator, MAX_GOPHER_LOCATOR_LENGTH + 1);
  165. return TRUE;
  166. }
  167. INTERNETAPI_(HINTERNET) GopherFindFirstFileW(
  168. IN HINTERNET hGopherSession,
  169. IN LPCWSTR lpszLocator OPTIONAL,
  170. IN LPCWSTR lpszSearchString OPTIONAL,
  171. OUT LPGOPHER_FIND_DATAW lpBuffer OPTIONAL,
  172. IN DWORD dwFlags,
  173. IN DWORD_PTR dwContext
  174. )
  175. {
  176. DEBUG_ENTER_API((DBG_API,
  177. Handle,
  178. "GopherFindFirstFileW",
  179. "%#x, %wq, %wq, %#x, %#x, %$x",
  180. hGopherSession,
  181. lpszLocator,
  182. lpszSearchString,
  183. lpBuffer,
  184. dwFlags,
  185. dwContext
  186. ));
  187. DWORD dwErr = ERROR_SUCCESS;
  188. HINTERNET hInternet=NULL;
  189. MEMORYPACKET mpLocator, mpSearch;
  190. GOPHER_FIND_DATAA gfda;
  191. if (lpszLocator && (IsBadStringPtrW(lpszLocator, INTERNET_MAX_PATH_LENGTH + 1)))
  192. {
  193. dwErr = ERROR_GOPHER_INVALID_LOCATOR;
  194. goto cleanup;
  195. }
  196. if ((lpszSearchString && (IsBadStringPtrW(lpszSearchString, INTERNET_MAX_PATH_LENGTH + 1)))
  197. || (lpBuffer && (IsBadWritePtr(lpBuffer, sizeof(*lpBuffer)))))
  198. {
  199. dwErr = ERROR_INVALID_PARAMETER;
  200. goto cleanup;
  201. }
  202. if (lpszLocator)
  203. {
  204. ALLOC_MB(lpszLocator,0,mpLocator);
  205. if (!mpLocator.psStr)
  206. {
  207. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  208. goto cleanup;
  209. }
  210. UNICODE_TO_ANSI(lpszLocator,mpLocator);
  211. }
  212. if (lpszSearchString)
  213. {
  214. ALLOC_MB(lpszSearchString,0,mpSearch);
  215. if (!mpSearch.psStr)
  216. {
  217. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  218. goto cleanup;
  219. }
  220. UNICODE_TO_ANSI(lpszSearchString,mpSearch);
  221. }
  222. hInternet = GopherFindFirstFileA(hGopherSession, mpLocator.psStr, mpSearch.psStr,
  223. &gfda, dwFlags, dwContext);
  224. if (hInternet && lpBuffer)
  225. {
  226. TransformGopherFindDataToW(&gfda, lpBuffer);
  227. }
  228. cleanup:
  229. if (dwErr!=ERROR_SUCCESS)
  230. {
  231. SetLastError(dwErr);
  232. DEBUG_ERROR(API, dwErr);
  233. }
  234. DEBUG_LEAVE_API(hInternet);
  235. return hInternet;
  236. }
  237. BOOL
  238. GopherFindNextW(
  239. IN HINTERNET hFind,
  240. OUT LPGOPHER_FIND_DATA lpBuffer
  241. )
  242. {
  243. SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
  244. return FALSE;
  245. }
  246. INTERNETAPI_(HINTERNET) GopherOpenFileW(
  247. IN HINTERNET hGopherSession,
  248. IN LPCWSTR lpszLocator,
  249. IN LPCWSTR lpszView OPTIONAL,
  250. IN DWORD dwFlags,
  251. IN DWORD_PTR dwContext
  252. )
  253. {
  254. DEBUG_ENTER_API((DBG_API,
  255. Handle,
  256. "GopherOpenFileW",
  257. "%#x, %wq, %wq, %#x, %#x",
  258. hGopherSession,
  259. lpszLocator,
  260. lpszView,
  261. dwFlags,
  262. dwContext
  263. ));
  264. DWORD dwErr = ERROR_SUCCESS;
  265. HINTERNET hInternet = NULL;
  266. MEMORYPACKET mpLocator,mpView;
  267. if (!lpszLocator)
  268. {
  269. dwErr = ERROR_INVALID_PARAMETER;
  270. goto cleanup;
  271. }
  272. ALLOC_MB(lpszLocator,0,mpLocator);
  273. if (!mpLocator.psStr)
  274. {
  275. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  276. goto cleanup;
  277. }
  278. UNICODE_TO_ANSI(lpszLocator,mpLocator);
  279. if (lpszView)
  280. {
  281. ALLOC_MB(lpszView,0,mpView);
  282. if (!mpView.psStr)
  283. {
  284. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  285. goto cleanup;
  286. }
  287. UNICODE_TO_ANSI(lpszView,mpView);
  288. }
  289. hInternet = GopherOpenFileA(hGopherSession,mpLocator.psStr,mpView.psStr,dwFlags,dwContext);
  290. cleanup:
  291. if (dwErr!=ERROR_SUCCESS)
  292. {
  293. SetLastError(dwErr);
  294. DEBUG_ERROR(API, dwErr);
  295. }
  296. DEBUG_LEAVE_API(hInternet);
  297. return hInternet;
  298. }
  299. INTERNETAPI_(BOOL) GopherGetAttributeW(
  300. IN HINTERNET hGopherSession,
  301. IN LPCWSTR lpszLocator,
  302. IN LPCWSTR lpszAttributeName OPTIONAL,
  303. OUT LPBYTE lpBuffer,
  304. IN DWORD dwBufferLength,
  305. OUT LPDWORD lpdwCharactersReturned,
  306. IN GOPHER_ATTRIBUTE_ENUMERATOR lpfnEnumerator OPTIONAL,
  307. IN DWORD_PTR dwContext
  308. )
  309. {
  310. #if !defined(GOPHER_ATTRIBUTE_SUPPORT)
  311. SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
  312. return FALSE;
  313. #else
  314. DEBUG_ENTER_API((DBG_API,
  315. Bool,
  316. "GopherGetAttributeW",
  317. "%#x, %wq, %wq, %#x, %d, %#x, %#x, %#x",
  318. hGopherSession,
  319. lpszLocator,
  320. lpszAttributeName,
  321. lpBuffer,
  322. dwBufferLength,
  323. lpdwCharactersReturned,
  324. lpfnEnumerator,
  325. dwContext
  326. ));
  327. // WARNING: This function may not function after all; You've been warned.
  328. DWORD dwErr = ERROR_SUCCESS;
  329. BOOL fResult = FALSE;
  330. MEMORYPACKET mpLocator,mpAttribute;
  331. ALLOC_MB(lpszLocator,0,mpLocator);
  332. if (!mpLocator.psStr)
  333. {
  334. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  335. goto cleanup;
  336. }
  337. UNICODE_TO_ANSI(lpszLocator,mpLocator);
  338. if (lpszAttributeName)
  339. {
  340. ALLOC_MB(lpszAttributeName,0,mpAttribute);
  341. if (!mpAttribute.psStr)
  342. {
  343. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  344. goto cleanup;
  345. }
  346. UNICODE_TO_ANSI(lpszAttributeName,mpAttribute);
  347. }
  348. fResult = GopherGetAttributeA(hGopherSession,mpLocator.psStr,mpAttribute.psStr,
  349. lpBuffer,dwBufferLength,lpdwCharactersReturned, lpfnEnumerator, dwContext);
  350. cleanup:
  351. if (dwErr!=ERROR_SUCCESS)
  352. {
  353. DEBUG_ERROR(API, dwErr);
  354. SetLastError(dwErr);
  355. }
  356. DEBUG_LEAVE_API(fResult);
  357. return fResult;
  358. #endif // defined(GOPHER_ATTRIBUTE_SUPPORT)
  359. }
  360. //
  361. //INTERNETAPI_(BOOL) GopherSendDataW(
  362. // IN HINTERNET hGopherSession,
  363. // IN LPCWSTR lpszLocator,
  364. // IN LPCWSTR lpszBuffer,
  365. // IN DWORD dwNumberOfCharactersToSend,
  366. // OUT LPDWORD lpdwNumberOfCharactersSent,
  367. // IN DWORD dwContext
  368. // )
  369. //{
  370. //#if 1
  371. // SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
  372. // return FALSE;
  373. //#else
  374. // DWORD dwErr;
  375. // MEMORYPACKET mpLocator,mpView;
  376. //
  377. // MAKE_ANSI(lpszLocator,0,mpLocator);
  378. // if (lpszView)
  379. // {
  380. // MAKE_ANSI(lpszView,0,mpView);
  381. // }
  382. // return GopherSendDataA(hGopherSession,mpLocator.psStr,mpView.psStr,dwFlags);
  383. //
  384. // LEAVE_API_CALL(FALSE);
  385. //#endif
  386. //}