//********************************************************************* //* Microsoft Windows ** //* Copyright(c) Microsoft Corp., 1996 ** //********************************************************************* /*Included Files------------------------------------------------------------*/ #include "msrating.h" #pragma hdrstop #include #include #include "ratings.h" #include "mslubase.h" #include "parselbl.h" #include "rors.h" #include "wininet.h" typedef HINTERNET (WINAPI *PFNInternetOpen)( IN LPCTSTR lpszCallerName, IN DWORD dwAccessType, IN LPCTSTR lpszServerName OPTIONAL, IN INTERNET_PORT nServerPort, IN DWORD dwFlags ); typedef BOOL (WINAPI *PFNInternetCloseHandle)( IN HINTERNET hInternet ); typedef HINTERNET (WINAPI *PFNInternetConnect)( IN HINTERNET hInternet, IN LPCTSTR lpszServerName, IN INTERNET_PORT nServerPort, IN LPCTSTR lpszUsername OPTIONAL, IN LPCTSTR lpszPassword OPTIONAL, IN DWORD dwService, IN DWORD dwFlags, IN DWORD_PTR dwContext ); typedef BOOL (WINAPI *PFNInternetReadFile)( IN HINTERNET hFile, IN LPVOID lpBuffer, IN DWORD dwNumberOfBytesToRead, OUT LPDWORD lpdwNumberOfBytesRead ); typedef INTERNET_STATUS_CALLBACK (WINAPI *PFNInternetSetStatusCallback)( IN HINTERNET hInternet, IN INTERNET_STATUS_CALLBACK lpfnInternetCallback ); typedef HINTERNET (WINAPI *PFNHttpOpenRequest)( IN HINTERNET hHttpSession, IN LPCTSTR lpszVerb, IN LPCTSTR lpszObjectName, IN LPCTSTR lpszVersion, IN LPCTSTR lpszReferrer OPTIONAL, IN LPCTSTR FAR * lplpszAcceptTypes OPTIONAL, IN DWORD dwFlags, IN DWORD_PTR dwContext ); typedef BOOL (WINAPI *PFNHttpSendRequest)( IN HINTERNET hHttpRequest, IN LPCTSTR lpszHeaders OPTIONAL, IN DWORD dwHeadersLength, IN LPVOID lpOptional OPTIONAL, IN DWORD dwOptionalLength ); typedef BOOL (WINAPI *PFNInternetCrackUrl)( IN LPCTSTR lpszUrl, IN DWORD dwUrlLength, IN DWORD dwFlags, IN OUT LPURL_COMPONENTS lpUrlComponents ); typedef BOOL (WINAPI *PFNInternetCanonicalizeUrl)( IN LPCSTR lpszUrl, OUT LPSTR lpszBuffer, IN OUT LPDWORD lpdwBufferLength, IN DWORD dwFlags ); PFNInternetReadFile pfnInternetReadFile = NULL; PFNHttpSendRequest pfnHttpSendRequest = NULL; PFNInternetOpen pfnInternetOpen = NULL; PFNInternetSetStatusCallback pfnInternetSetStatusCallback = NULL; PFNInternetConnect pfnInternetConnect = NULL; PFNHttpOpenRequest pfnHttpOpenRequest = NULL; PFNInternetCloseHandle pfnInternetCloseHandle = NULL; PFNInternetCrackUrl pfnInternetCrackUrl = NULL; PFNInternetCanonicalizeUrl pfnInternetCanonicalizeUrl = NULL; #undef InternetReadFile #undef HttpSendRequest #undef InternetOpen #undef InternetSetStatusCallback #undef InternetConnect #undef HttpOpenRequest #undef InternetCloseHandle #undef InternetCrackUrl #undef InternetCanonicalizeUrl #define InternetReadFile pfnInternetReadFile #define HttpSendRequest pfnHttpSendRequest #define InternetOpen pfnInternetOpen #define InternetSetStatusCallback pfnInternetSetStatusCallback #define InternetConnect pfnInternetConnect #define HttpOpenRequest pfnHttpOpenRequest #define InternetCloseHandle pfnInternetCloseHandle #define InternetCrackUrl pfnInternetCrackUrl #define InternetCanonicalizeUrl pfnInternetCanonicalizeUrl struct { FARPROC *ppfn; LPCSTR pszName; } aImports[] = { #ifndef UNICODE { (FARPROC *)&pfnInternetReadFile, "InternetReadFile" }, { (FARPROC *)&pfnHttpSendRequest, "HttpSendRequestA" }, { (FARPROC *)&pfnInternetOpen, "InternetOpenA" }, { (FARPROC *)&pfnInternetSetStatusCallback, "InternetSetStatusCallback" }, { (FARPROC *)&pfnInternetConnect, "InternetConnectA" }, { (FARPROC *)&pfnHttpOpenRequest, "HttpOpenRequestA" }, { (FARPROC *)&pfnInternetCloseHandle, "InternetCloseHandle" }, { (FARPROC *)&pfnInternetCrackUrl, "InternetCrackUrlA" }, { (FARPROC *)&pfnInternetCanonicalizeUrl, "InternetCanonicalizeUrlA" }, #else { (FARPROC *)&pfnInternetReadFile, "InternetReadFile" }, { (FARPROC *)&pfnHttpSendRequest, "HttpSendRequestW" }, { (FARPROC *)&pfnInternetOpen, "InternetOpenW" }, { (FARPROC *)&pfnInternetSetStatusCallback, "InternetSetStatusCallback" }, { (FARPROC *)&pfnInternetConnect, "InternetConnectW" }, { (FARPROC *)&pfnHttpOpenRequest, "HttpOpenRequestW" }, { (FARPROC *)&pfnInternetCloseHandle, "InternetCloseHandle" }, { (FARPROC *)&pfnInternetCrackUrl, "InternetCrackUrlW" }, { (FARPROC *)&pfnInternetCanonicalizeUrl, "InternetCanonicalizeUrlW" }, #endif }; const UINT cImports = sizeof(aImports) / sizeof(aImports[0]); HINSTANCE hWinINet = NULL; BOOL fTriedLoad = FALSE; HINTERNET hI = NULL; void _stdcall WinInetCallbackProc(HINTERNET hInternet, DWORD_PTR Context, DWORD Status, LPVOID Info, DWORD Length); #define USER_AGENT_STRING "Batcave(bcrs)" BOOL LoadWinINet(void) { if (fTriedLoad) { return (hWinINet != NULL); } fTriedLoad = TRUE; hWinINet = ::LoadLibrary("WININET.DLL"); if (hWinINet == NULL) { return FALSE; } for (UINT i=0; ietstrRatingBureau.fIsInit()) { return hrRet; } if (!LoadWinINet()) { return hrRet; } pszRatingServer = gPRSI->etstrRatingBureau.Get(); BUFFER bufBureauHostName(INTERNET_MAX_HOST_NAME_LENGTH); BUFFER bufBureauPath(INTERNET_MAX_PATH_LENGTH); if (!bufBureauHostName.QueryPtr() || !bufBureauPath.QueryPtr()) { return E_OUTOFMEMORY; } URL_COMPONENTS uc; uc.dwStructSize = sizeof(uc); uc.lpszScheme = NULL; uc.dwSchemeLength = 0; uc.lpszHostName = (LPSTR)bufBureauHostName.QueryPtr(); uc.dwHostNameLength = bufBureauHostName.QuerySize(); uc.lpszUserName = NULL; uc.dwUserNameLength = 0; uc.lpszPassword = NULL; uc.dwPasswordLength = 0; uc.lpszUrlPath = (LPSTR)bufBureauPath.QueryPtr(); uc.dwUrlPathLength = bufBureauPath.QuerySize(); uc.lpszExtraInfo = NULL; uc.dwExtraInfoLength = 0; if (!InternetCrackUrl(pszRatingServer, 0, 0, &uc)) { return HRESULT_FROM_WIN32(GetLastError()); } BUFFER bufRequest(INTERNET_MAX_URL_LENGTH + uc.dwUrlPathLength + cchRequestTemplate); LPSTR pszRequest = (LPSTR)bufRequest.QueryPtr(); if (pszRequest == NULL) { return E_OUTOFMEMORY; } LPSTR pszCurrent = pszRequest; ::strcpyf(pszCurrent, uc.lpszUrlPath); pszCurrent += uc.dwUrlPathLength; ::strcpyf(pszCurrent, szRequestTemplate); pszCurrent += ::strlenf(pszCurrent); /* Encode the target URL. */ EncodeUrl(pszTargetUrl, pszCurrent); ::strcatf(pszCurrent, "\""); hIC = hH = NULL; rgEvents[ABORT_EVENT] = hAbortEvent; rgEvents[ASYNC_EVENT] = CreateEvent(NULL, FALSE, FALSE, NULL); if (!rgEvents[ASYNC_EVENT]) { goto STATE_CLEANUP; } hIC = InternetConnect(hI, uc.lpszHostName, uc.nPort, NULL, NULL, INTERNET_SERVICE_HTTP, 0, (DWORD_PTR) rgEvents[ASYNC_EVENT]); if (hIC == NULL || ShouldAbort(hAbortEvent)) { goto STATE_CLEANUP; } hH = HttpOpenRequest(hIC, "GET", pszRequest, NULL, NULL, NULL, INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_RELOAD, (DWORD_PTR) rgEvents[ASYNC_EVENT]); if (hH == NULL || ShouldAbort(hAbortEvent)) { goto STATE_CLEANUP; } fRet = HttpSendRequest(hH, NULL, (DWORD) 0, NULL, 0); if (!fRet && !WaitForAsync(rgEvents)) { goto STATE_CLEANUP; } pBuf = rgBuf; nRead = 0; do { fRet = InternetReadFile(hH, pBuf, nBuf-nRead, &nRead); if (!fRet && !WaitForAsync(rgEvents)) { goto STATE_CLEANUP; } if (nRead) { pBuf += nRead; hrRet = NOERROR; } } while (nRead); STATE_CLEANUP: if (hH) InternetCloseHandle(hH); if (hIC) InternetCloseHandle(hIC); if (rgEvents[ASYNC_EVENT]) { CloseHandle(rgEvents[ASYNC_EVENT]); } if (hrRet == NOERROR) { (*ppRatingOut) = (char*) pAllocator->Alloc((int)(pBuf - rgBuf + 1)); if (*ppRatingOut != NULL) { *pBuf = '\0'; LPSTR pszLabel = FindRatingLabel(rgBuf); strcpyf(*ppRatingOut, pszLabel); } else { hrRet = ResultFromScode(E_OUTOFMEMORY); } } if (hrRet == NOERROR) { hrRet = S_RATING_FOUND; } return hrRet; } STDMETHODIMP_(ULONG) CRORemoteSite::GetSortOrder(THIS) { return RATING_ORDER_REMOTESITE; }