home *** CD-ROM | disk | FTP | other *** search
/ Supercompiler 1997 / SUPERCOMPILER97.iso / MS_VC.50 / VC / MFC / SRC / INETIMPL.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-01  |  13.8 KB  |  459 lines

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