inetimpl.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1997 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10. #include "stdafx.h"
  11. #include <afxinet.h>
  12. #include "inetimpl.h"
  13. #ifdef AFX_INIT_SEG
  14. #pragma code_seg(AFX_INIT_SEG)
  15. #endif
  16. /////////////////////////////////////////////////////////////////////////////
  17. // for dynamic load of WININET.DLL
  18. #ifdef _AFXDLL
  19. #ifndef _MAC
  20. static const char szINetDLL[] = "WININET.DLL";
  21. #else
  22. #error WinINet isn't available on MPPC
  23. #endif
  24. /////////////////////////////////////////////////////////////////////////////
  25. //
  26. inline void PASCAL AfxINetLoad(FARPROC* pProcPtr, LPCSTR pstrEntry)
  27. {
  28. HINSTANCE hInst;
  29. TRY
  30. {
  31. // attempt to load but catch error for custom message
  32. hInst = AfxLoadDll(&_afxExtDllState->m_hInstInternet, szINetDLL);
  33. }
  34. CATCH_ALL(e)
  35. {
  36. TRACE1("Error: Couldn't load %s!\n", szINetDLL);
  37. // Note: DELETE_EXCEPTION(e) not necessary
  38. AfxThrowInternetException(GetLastError());
  39. }
  40. END_CATCH_ALL
  41. ASSERT(hInst != NULL);
  42. // cache the procedure pointer
  43. ASSERT(pProcPtr != NULL);
  44. *pProcPtr = GetProcAddress(hInst, pstrEntry);
  45. if (*pProcPtr == NULL)
  46. {
  47. TRACE2("Error: Couldn't find %s in %s!\n", pstrEntry, szINetDLL);
  48. AfxThrowInternetException(GetLastError());
  49. }
  50. }
  51. #define INETLOAD(x) AfxINetLoad((FARPROC*)&_afxWinINet.pfn##x, #x)
  52. #ifdef _UNICODE
  53. #define INETLOADT(x) AfxINetLoad((FARPROC*)&_afxWinINet.pfn##x, #x"W")
  54. #else
  55. #define INETLOADT(x) AfxINetLoad((FARPROC*)&_afxWinINet.pfn##x, #x"A")
  56. #endif
  57. // generic connection
  58. HINTERNET WINAPI AfxThunkINetInternetOpen(
  59. LPCTSTR lpszAgent,
  60. DWORD dwAccessType,
  61. LPCTSTR lpszProxy,
  62. LPCTSTR lpszProxyBypass,
  63. DWORD dwFlags)
  64. {
  65. INETLOADT(InternetOpen);
  66. return _afxWinINet.pfnInternetOpen(lpszAgent, dwAccessType,
  67. lpszProxy, lpszProxyBypass, dwFlags);
  68. }
  69. HINTERNET WINAPI AfxThunkINetInternetCloseHandle(HINTERNET hInternet)
  70. {
  71. INETLOAD(InternetCloseHandle);
  72. return _afxWinINet.pfnInternetCloseHandle(hInternet);
  73. }
  74. HINTERNET WINAPI AfxThunkINetInternetOpenUrl(HINTERNET hInternet,
  75. LPCTSTR pstrUrl, LPCTSTR pstrHeaders, DWORD dwHeadersLength,
  76. DWORD dwFlags, DWORD dwContext)
  77. {
  78. INETLOADT(InternetOpenUrl);
  79. return _afxWinINet.pfnInternetOpenUrl(hInternet,
  80. pstrUrl, pstrHeaders, dwHeadersLength, dwFlags, dwContext);
  81. }
  82. HINTERNET WINAPI AfxThunkINetInternetReadFile(HINTERNET hInternet,
  83. LPVOID lpBuffer, DWORD dwNumberOfBytesToRead,
  84. LPDWORD lpdwNumberOfBytesRead)
  85. {
  86. INETLOAD(InternetReadFile);
  87. return _afxWinINet.pfnInternetReadFile(hInternet, lpBuffer,
  88. dwNumberOfBytesToRead, lpdwNumberOfBytesRead);
  89. }
  90. HINTERNET WINAPI AfxThunkINetInternetWriteFile(HINTERNET hInternet,
  91. LPCVOID lpBuffer, DWORD dwNumberOfBytesToWrite,
  92. LPDWORD lpdwNumberOfBytesWritten)
  93. {
  94. INETLOAD(InternetWriteFile);
  95. return _afxWinINet.pfnInternetWriteFile(hInternet, lpBuffer,
  96. dwNumberOfBytesToWrite, lpdwNumberOfBytesWritten);
  97. }
  98. INTERNET_STATUS_CALLBACK WINAPI AfxThunkINetInternetSetStatusCallback(
  99. HINTERNET hInternet, INTERNET_STATUS_CALLBACK lpfnInternetCallback)
  100. {
  101. INETLOAD(InternetSetStatusCallback);
  102. return _afxWinINet.pfnInternetSetStatusCallback(hInternet,
  103. lpfnInternetCallback);
  104. }
  105. BOOL WINAPI AfxThunkINetInternetQueryOption(HINTERNET hInternet,
  106. DWORD dwOption, LPVOID lpBuffer, LPDWORD lpdwBufferLength)
  107. {
  108. INETLOADT(InternetQueryOption);
  109. return _afxWinINet.pfnInternetQueryOption(hInternet, dwOption,
  110. lpBuffer, lpdwBufferLength);
  111. }
  112. BOOL WINAPI AfxThunkINetInternetSetOption(HINTERNET hInternet,
  113. DWORD dwOption, LPVOID lpBuffer, DWORD dwBufferLength)
  114. {
  115. INETLOADT(InternetSetOption);
  116. return _afxWinINet.pfnInternetSetOption(hInternet, dwOption, lpBuffer,
  117. dwBufferLength);
  118. }
  119. BOOL WINAPI AfxThunkINetInternetSetOptionEx(HINTERNET hInternet,
  120. DWORD dwOption, LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
  121. {
  122. INETLOADT(InternetSetOptionEx);
  123. return _afxWinINet.pfnInternetSetOptionEx(hInternet, dwOption, lpBuffer,
  124. dwBufferLength, dwFlags);
  125. }
  126. BOOL WINAPI AfxThunkINetInternetGetLastResponseInfo(LPDWORD lpdwError,
  127. LPTSTR pstrBuffer, LPDWORD lpdwBufferLength)
  128. {
  129. INETLOADT(InternetGetLastResponseInfo);
  130. return _afxWinINet.pfnInternetGetLastResponseInfo(lpdwError,
  131. pstrBuffer, lpdwBufferLength);
  132. }
  133. BOOL WINAPI AfxThunkINetInternetFindNextFile(HINTERNET hFind,
  134. LPVOID lpvFindData)
  135. {
  136. INETLOADT(InternetFindNextFile);
  137. return _afxWinINet.pfnInternetFindNextFile(hFind, lpvFindData);
  138. }
  139. HINTERNET WINAPI AfxThunkINetInternetConnect(HINTERNET hInternet,
  140. LPCTSTR pstrServerName, INTERNET_PORT nServerPort, LPCTSTR pstrUsername,
  141. LPCTSTR pstrPassword, DWORD dwService, DWORD dwFlags, DWORD dwContext)
  142. {
  143. INETLOADT(InternetConnect);
  144. return _afxWinINet.pfnInternetConnect(hInternet, pstrServerName,
  145. nServerPort, pstrUsername, pstrPassword, dwService, dwFlags,
  146. dwContext);
  147. }
  148. DWORD WINAPI AfxThunkINetInternetSetFilePointer(HINTERNET hFile,
  149. LONG lDistanceToMove, PVOID reserved, DWORD dwMoveMethod, DWORD dwContext)
  150. {
  151. INETLOAD(InternetSetFilePointer);
  152. return _afxWinINet.pfnInternetSetFilePointer(hFile, lDistanceToMove,
  153. reserved, dwMoveMethod, dwContext);
  154. }
  155. BOOL WINAPI AfxThunkINetInternetQueryDataAvailable(HINTERNET hFile,
  156. LPDWORD lpdwNumberOfBytesAvailable, DWORD dwFlags, DWORD dwContext)
  157. {
  158. INETLOAD(InternetQueryDataAvailable);
  159. return _afxWinINet.pfnInternetQueryDataAvailable(hFile,
  160. lpdwNumberOfBytesAvailable, dwFlags, dwContext);
  161. }
  162. // ftp
  163. HINTERNET WINAPI AfxThunkINetFtpFindFirstFile(HINTERNET hFtpSession,
  164. LPCTSTR pstrSearchFile, LPWIN32_FIND_DATA lpFindFileData,
  165. DWORD dwFlags, DWORD dwContext)
  166. {
  167. INETLOADT(FtpFindFirstFile);
  168. return _afxWinINet.pfnFtpFindFirstFile(hFtpSession,
  169. pstrSearchFile, lpFindFileData, dwFlags, dwContext);
  170. }
  171. BOOL WINAPI AfxThunkINetFtpGetFile(HINTERNET hFtpSession,
  172. LPCTSTR pstrRemoteFile, LPCTSTR pstrNewFile, BOOL fFailIfExists,
  173. DWORD dwFlagsAndAttributes, DWORD dwFlags, DWORD dwContext)
  174. {
  175. INETLOADT(FtpGetFile);
  176. return _afxWinINet.pfnFtpGetFile(hFtpSession, pstrRemoteFile,
  177. pstrNewFile, fFailIfExists, dwFlagsAndAttributes, dwFlags,
  178. dwContext);
  179. }
  180. BOOL WINAPI AfxThunkINetFtpPutFile(HINTERNET hFtpSession,
  181. LPCTSTR pstrLocalFile, LPCTSTR pstrNewRemoteFile, DWORD dwFlags,
  182. DWORD dwContext)
  183. {
  184. INETLOADT(FtpPutFile);
  185. return _afxWinINet.pfnFtpPutFile(hFtpSession, pstrLocalFile,
  186. pstrNewRemoteFile, dwFlags, dwContext);
  187. }
  188. BOOL WINAPI AfxThunkINetFtpDeleteFile(HINTERNET hFtpSession,
  189. LPCTSTR pstrFileName)
  190. {
  191. INETLOADT(FtpDeleteFile);
  192. return _afxWinINet.pfnFtpDeleteFile(hFtpSession, pstrFileName);
  193. }
  194. BOOL WINAPI AfxThunkINetFtpRenameFile(HINTERNET hFtpSession,
  195. LPCTSTR pstrExisting, LPCTSTR pstrNew)
  196. {
  197. INETLOADT(FtpRenameFile);
  198. return _afxWinINet.pfnFtpRenameFile(hFtpSession, pstrExisting, pstrNew);
  199. }
  200. BOOL WINAPI AfxThunkINetFtpCreateDirectory(HINTERNET hFtpSession,
  201. LPCTSTR pstrDirectory)
  202. {
  203. INETLOADT(FtpCreateDirectory);
  204. return _afxWinINet.pfnFtpCreateDirectory(hFtpSession, pstrDirectory);
  205. }
  206. BOOL WINAPI AfxThunkINetFtpRemoveDirectory(HINTERNET hFtpSession,
  207. LPCTSTR pstrDirectory)
  208. {
  209. INETLOADT(FtpRemoveDirectory);
  210. return _afxWinINet.pfnFtpRemoveDirectory(hFtpSession, pstrDirectory);
  211. }
  212. BOOL WINAPI AfxThunkINetFtpSetCurrentDirectory(HINTERNET hFtpSession,
  213. LPCTSTR pstrDirectory)
  214. {
  215. INETLOADT(FtpSetCurrentDirectory);
  216. return _afxWinINet.pfnFtpSetCurrentDirectory(hFtpSession, pstrDirectory);
  217. }
  218. BOOL WINAPI AfxThunkINetFtpGetCurrentDirectory(HINTERNET hFtpSession,
  219. LPCTSTR pstrCurrentDirectory, LPDWORD lpdwCurrentDirectory)
  220. {
  221. INETLOADT(FtpGetCurrentDirectory);
  222. return _afxWinINet.pfnFtpGetCurrentDirectory(hFtpSession,
  223. pstrCurrentDirectory, lpdwCurrentDirectory);
  224. }
  225. BOOL WINAPI AfxThunkINetFtpCommand(HINTERNET hFtpSession,
  226. BOOL fExpectResponse, DWORD dwFlags, LPCTSTR pstrCommand,
  227. DWORD dwContext)
  228. {
  229. INETLOADT(FtpCommand);
  230. return _afxWinINet.pfnFtpCommand(hFtpSession, fExpectResponse,
  231. dwFlags, pstrCommand, dwContext);
  232. }
  233. HINTERNET WINAPI AfxThunkINetFtpOpenFile(HINTERNET hFtpSession,
  234. LPCTSTR pstrFileName, DWORD dwAccess, DWORD dwFlags,
  235. DWORD dwContext)
  236. {
  237. INETLOADT(FtpOpenFile);
  238. return _afxWinINet.pfnFtpOpenFile(hFtpSession, pstrFileName,
  239. dwAccess, dwFlags, dwContext);
  240. }
  241. // gopher
  242. HINTERNET WINAPI AfxThunkINetGopherFindFirstFile(HINTERNET hGopherSession,
  243. LPCTSTR pstrLocator, LPCTSTR pstrSearchString,
  244. LPGOPHER_FIND_DATA lpFindData, DWORD dwFlags, DWORD dwContext)
  245. {
  246. INETLOADT(GopherFindFirstFile);
  247. return _afxWinINet.pfnGopherFindFirstFile(hGopherSession,
  248. pstrLocator, pstrSearchString, lpFindData, dwFlags, dwContext);
  249. }
  250. HINTERNET WINAPI AfxThunkINetGopherOpenFile(HINTERNET hGopherSession,
  251. LPCTSTR pstrLocator, LPCTSTR pstrView, DWORD dwFlags,
  252. DWORD dwContext)
  253. {
  254. INETLOADT(GopherOpenFile);
  255. return _afxWinINet.pfnGopherOpenFile(hGopherSession, pstrLocator,
  256. pstrView, dwFlags, dwContext);
  257. }
  258. BOOL WINAPI AfxThunkINetGopherCreateLocator(LPCTSTR pstrHost,
  259. INTERNET_PORT nServerPort, LPCTSTR pstrDisplayString,
  260. LPCTSTR pstrSelectorString, DWORD dwGopherType,
  261. LPTSTR pstrLocator, LPDWORD lpdwBufferLength)
  262. {
  263. INETLOADT(GopherCreateLocator);
  264. return _afxWinINet.pfnGopherCreateLocator(pstrHost, nServerPort,
  265. pstrDisplayString, pstrSelectorString, dwGopherType,
  266. pstrLocator, lpdwBufferLength);
  267. }
  268. BOOL WINAPI AfxThunkINetGopherGetAttribute(HINTERNET hGopherSession,
  269. LPCTSTR pstrLocator, LPCTSTR pstrAttributeName, LPBYTE lpBuffer,
  270. DWORD dwBufferLength, LPDWORD lpdwCharactersReturned,
  271. GOPHER_ATTRIBUTE_ENUMERATOR lpfnEnumerator, DWORD dwContext)
  272. {
  273. INETLOADT(GopherGetAttribute);
  274. return _afxWinINet.pfnGopherGetAttribute(hGopherSession, pstrLocator,
  275. pstrAttributeName, lpBuffer, dwBufferLength, lpdwCharactersReturned,
  276. lpfnEnumerator, dwContext);
  277. }
  278. BOOL WINAPI AfxThunkINetGopherGetLocatorType(LPCTSTR pstrLocator,
  279. LPDWORD pdwGopherType)
  280. {
  281. INETLOADT(GopherGetLocatorType);
  282. return _afxWinINet.pfnGopherGetLocatorType(pstrLocator, pdwGopherType);
  283. }
  284. // http
  285. HINTERNET WINAPI AfxThunkINetHttpOpenRequest(HINTERNET hHttpSession,
  286. LPCTSTR pstrVerb, LPCTSTR pstrObjectName, LPCTSTR pstrVersion,
  287. LPCTSTR pstrReferrer, LPCTSTR FAR * lppstrAcceptTypes,
  288. DWORD dwFlags, DWORD dwContext)
  289. {
  290. INETLOADT(HttpOpenRequest);
  291. return _afxWinINet.pfnHttpOpenRequest(hHttpSession, pstrVerb,
  292. pstrObjectName, pstrVersion, pstrReferrer, lppstrAcceptTypes,
  293. dwFlags, dwContext);
  294. }
  295. BOOL WINAPI AfxThunkINetHttpAddRequestHeaders(HINTERNET hHttpRequest,
  296. LPCTSTR pstrHeaders, DWORD dwHeadersLength, DWORD dwModifiers)
  297. {
  298. INETLOADT(HttpAddRequestHeaders);
  299. return _afxWinINet.pfnHttpAddRequestHeaders(hHttpRequest,
  300. pstrHeaders, dwHeadersLength, dwModifiers);
  301. }
  302. BOOL WINAPI AfxThunkINetHttpSendRequest(HINTERNET hHttpRequest,
  303. LPCTSTR pstrHeaders, DWORD dwHeadersLength, LPVOID lpOptional,
  304. DWORD dwOptionalLength)
  305. {
  306. INETLOADT(HttpSendRequest);
  307. return _afxWinINet.pfnHttpSendRequest(hHttpRequest, pstrHeaders,
  308. dwHeadersLength, lpOptional, dwOptionalLength);
  309. }
  310. BOOL WINAPI AfxThunkINetHttpQueryInfo(HINTERNET hHttpRequest,
  311. DWORD dwInfoLevel, LPVOID lpvBuffer, LPDWORD lpdwBufferLength,
  312. LPDWORD lpdwIndex)
  313. {
  314. INETLOADT(HttpQueryInfo);
  315. return _afxWinINet.pfnHttpQueryInfo(hHttpRequest, dwInfoLevel,
  316. lpvBuffer, lpdwBufferLength, lpdwIndex);
  317. }
  318. DWORD WINAPI AfxThunkINetInternetErrorDlg(HWND hWnd, HINTERNET hRequest,
  319. DWORD dwError, DWORD dwFlags, LPVOID * lppvData)
  320. {
  321. INETLOADT(InternetErrorDlg);
  322. return _afxWinINet.pfnInternetErrorDlg(hWnd, hRequest,
  323. dwError, dwFlags, lppvData);
  324. }
  325. // parsers
  326. BOOL WINAPI AfxThunkINetCrackUrl(LPCTSTR lpszUrl, DWORD dwUrlLength,
  327. DWORD dwFlags, LPURL_COMPONENTS lpUrlComponents)
  328. {
  329. INETLOADT(InternetCrackUrl);
  330. return _afxWinINet.pfnInternetCrackUrl(lpszUrl, dwUrlLength,
  331. dwFlags, lpUrlComponents);
  332. }
  333. BOOL WINAPI AfxThunkINetCanonicalizeUrl(LPCTSTR lpszUrl,
  334. LPTSTR lpszBuffer, LPDWORD lpdwBufferLength, DWORD dwFlags)
  335. {
  336. INETLOADT(InternetCanonicalizeUrl);
  337. return _afxWinINet.pfnInternetCanonicalizeUrl(lpszUrl,
  338. lpszBuffer, lpdwBufferLength, dwFlags);
  339. }
  340. /////////////////////////////////////////////////////////////////////////////
  341. //
  342. AFX_DATADEF AFX_WININET_CALL _afxWinINet =
  343. {
  344. // generic connection
  345. { AfxThunkINetInternetOpen, },
  346. { AfxThunkINetInternetCloseHandle, },
  347. { AfxThunkINetInternetOpenUrl, },
  348. { AfxThunkINetInternetReadFile, },
  349. { AfxThunkINetInternetWriteFile, },
  350. { AfxThunkINetInternetSetStatusCallback, },
  351. { AfxThunkINetInternetQueryOption, },
  352. { AfxThunkINetInternetSetOption, },
  353. { AfxThunkINetInternetSetOptionEx, },
  354. { AfxThunkINetInternetGetLastResponseInfo, },
  355. { AfxThunkINetInternetFindNextFile, },
  356. { AfxThunkINetInternetConnect, },
  357. { AfxThunkINetInternetSetFilePointer, },
  358. { AfxThunkINetInternetQueryDataAvailable, },
  359. // ftp
  360. { AfxThunkINetFtpFindFirstFile, },
  361. { AfxThunkINetFtpGetFile, },
  362. { AfxThunkINetFtpPutFile, },
  363. { AfxThunkINetFtpDeleteFile, },
  364. { AfxThunkINetFtpRenameFile, },
  365. { AfxThunkINetFtpCreateDirectory, },
  366. { AfxThunkINetFtpRemoveDirectory, },
  367. { AfxThunkINetFtpSetCurrentDirectory, },
  368. { AfxThunkINetFtpGetCurrentDirectory, },
  369. { AfxThunkINetFtpCommand, },
  370. { AfxThunkINetFtpOpenFile, },
  371. // gopher
  372. { AfxThunkINetGopherFindFirstFile, },
  373. { AfxThunkINetGopherOpenFile, },
  374. { AfxThunkINetGopherCreateLocator, },
  375. { AfxThunkINetGopherGetAttribute, },
  376. { AfxThunkINetGopherGetLocatorType, },
  377. // html
  378. { AfxThunkINetHttpOpenRequest, },
  379. { AfxThunkINetHttpAddRequestHeaders, },
  380. { AfxThunkINetHttpSendRequest, },
  381. { AfxThunkINetHttpQueryInfo, },
  382. { AfxThunkINetInternetErrorDlg, },
  383. // parsers
  384. { AfxThunkINetCrackUrl, },
  385. { AfxThunkINetCanonicalizeUrl, },
  386. };
  387. #endif //_AFXDLL (the whole file)