4 * Copyright 1999 Corel Corporation
5 * Copyright 2002 CodeWeavers Inc.
10 * Copyright 2002 Jaco Greeff
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2.1 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #define MAXHOSTNAME 100 /* from http.c */
33 #include <sys/types.h>
34 #ifdef HAVE_SYS_SOCKET_H
35 # include <sys/socket.h>
37 #ifdef HAVE_SYS_TIME_H
38 # include <sys/time.h>
51 #include "wine/debug.h"
53 #define NO_SHLWAPI_STREAM
56 #include "wine/exception.h"
57 #include "msvcrt/excpt.h"
61 WINE_DEFAULT_DEBUG_CHANNEL(wininet);
63 #define MAX_IDLE_WORKER 1000*60*1
64 #define MAX_WORKER_THREADS 10
65 #define RESPONSE_TIMEOUT 30
67 #define GET_HWININET_FROM_LPWININETFINDNEXT(lpwh) \
68 (LPWININETAPPINFOA)(((LPWININETFTPSESSIONA)(lpwh->hdr.lpwhparent))->hdr.lpwhparent)
70 /* filter for page-fault exceptions */
71 static WINE_EXCEPTION_FILTER(page_fault)
73 if (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION ||
74 GetExceptionCode() == EXCEPTION_PRIV_INSTRUCTION)
75 return EXCEPTION_EXECUTE_HANDLER;
76 return EXCEPTION_CONTINUE_SEARCH;
82 CHAR response[MAX_REPLY_LEN];
83 } WITHREADERROR, *LPWITHREADERROR;
85 INTERNET_SCHEME GetInternetScheme(LPCSTR lpszScheme, INT nMaxCmp);
86 BOOL WINAPI INTERNET_FindNextFileA(HINTERNET hFind, LPVOID lpvFindData);
87 VOID INTERNET_ExecuteWork();
89 DWORD g_dwTlsErrIndex = TLS_OUT_OF_INDEXES;
91 DWORD dwNumIdleThreads;
92 HANDLE hEventArray[2];
93 #define hQuitEvent hEventArray[0]
94 #define hWorkEvent hEventArray[1]
95 CRITICAL_SECTION csQueue;
96 LPWORKREQUEST lpHeadWorkQueue;
97 LPWORKREQUEST lpWorkQueueTail;
99 /***********************************************************************
100 * WININET_LibMain [Internal] Initializes the internal 'WININET.DLL'.
103 * hinstDLL [I] handle to the DLL's instance
105 * lpvReserved [I] reserved, must be NULL
113 WININET_LibMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
115 TRACE("%p,%lx,%p\n", hinstDLL, fdwReason, lpvReserved);
118 case DLL_PROCESS_ATTACH:
120 g_dwTlsErrIndex = TlsAlloc();
122 if (g_dwTlsErrIndex == TLS_OUT_OF_INDEXES)
125 hQuitEvent = CreateEventA(0, TRUE, FALSE, NULL);
126 hWorkEvent = CreateEventA(0, FALSE, FALSE, NULL);
127 InitializeCriticalSection(&csQueue);
130 dwNumIdleThreads = 0;
132 case DLL_THREAD_ATTACH:
134 LPWITHREADERROR lpwite = HeapAlloc(GetProcessHeap(), 0, sizeof(WITHREADERROR));
138 TlsSetValue(g_dwTlsErrIndex, (LPVOID)lpwite);
142 case DLL_THREAD_DETACH:
143 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
145 LPVOID lpwite = TlsGetValue(g_dwTlsErrIndex);
147 HeapFree(GetProcessHeap(), 0, lpwite);
151 case DLL_PROCESS_DETACH:
153 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
155 HeapFree(GetProcessHeap(), 0, TlsGetValue(g_dwTlsErrIndex));
156 TlsFree(g_dwTlsErrIndex);
159 SetEvent(hQuitEvent);
161 CloseHandle(hQuitEvent);
162 CloseHandle(hWorkEvent);
163 DeleteCriticalSection(&csQueue);
171 /***********************************************************************
172 * InternetInitializeAutoProxyDll (WININET.@)
174 * Setup the internal proxy
183 BOOL InternetInitializeAutoProxyDll(DWORD dwReserved)
186 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
191 /***********************************************************************
192 * InternetOpenA (WININET.@)
194 * Per-application initialization of wininet
197 * HINTERNET on success
201 HINTERNET WINAPI InternetOpenA(LPCSTR lpszAgent, DWORD dwAccessType,
202 LPCSTR lpszProxy, LPCSTR lpszProxyBypass, DWORD dwFlags)
204 LPWININETAPPINFOA lpwai = NULL;
208 /* Clear any error information */
209 INTERNET_SetLastError(0);
211 lpwai = HeapAlloc(GetProcessHeap(), 0, sizeof(WININETAPPINFOA));
213 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
216 memset(lpwai, 0, sizeof(WININETAPPINFOA));
217 lpwai->hdr.htype = WH_HINIT;
218 lpwai->hdr.lpwhparent = NULL;
219 lpwai->hdr.dwFlags = dwFlags;
220 if (NULL != lpszAgent)
222 if ((lpwai->lpszAgent = HeapAlloc( GetProcessHeap(),0,strlen(lpszAgent)+1)))
223 strcpy( lpwai->lpszAgent, lpszAgent );
225 if (NULL != lpszProxy)
227 if ((lpwai->lpszProxy = HeapAlloc( GetProcessHeap(), 0, strlen(lpszProxy)+1 )))
228 strcpy( lpwai->lpszProxy, lpszProxy );
230 if (NULL != lpszProxyBypass)
232 if ((lpwai->lpszProxyBypass = HeapAlloc( GetProcessHeap(), 0, strlen(lpszProxyBypass)+1)))
233 strcpy( lpwai->lpszProxyBypass, lpszProxyBypass );
235 lpwai->dwAccessType = dwAccessType;
238 return (HINTERNET)lpwai;
242 /***********************************************************************
243 * InternetOpenW (WININET.@)
245 * Per-application initialization of wininet
248 * HINTERNET on success
252 HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType,
253 LPCWSTR lpszProxy, LPCWSTR lpszProxyBypass, DWORD dwFlags)
255 HINTERNET rc = (HINTERNET)NULL;
256 INT lenAgent = lstrlenW(lpszAgent)+1;
257 INT lenProxy = lstrlenW(lpszProxy)+1;
258 INT lenBypass = lstrlenW(lpszProxyBypass)+1;
259 CHAR *szAgent = (CHAR *)malloc(lenAgent*sizeof(CHAR));
260 CHAR *szProxy = (CHAR *)malloc(lenProxy*sizeof(CHAR));
261 CHAR *szBypass = (CHAR *)malloc(lenBypass*sizeof(CHAR));
263 if (!szAgent || !szProxy || !szBypass)
271 return (HINTERNET)NULL;
274 WideCharToMultiByte(CP_ACP, -1, lpszAgent, -1, szAgent, lenAgent,
276 WideCharToMultiByte(CP_ACP, -1, lpszProxy, -1, szProxy, lenProxy,
278 WideCharToMultiByte(CP_ACP, -1, lpszProxyBypass, -1, szBypass, lenBypass,
281 rc = InternetOpenA(szAgent, dwAccessType, szProxy, szBypass, dwFlags);
290 /***********************************************************************
291 * InternetGetLastResponseInfoA (WININET.@)
293 * Return last wininet error description on the calling thread
296 * TRUE on success of writting to buffer
300 BOOL WINAPI InternetGetLastResponseInfoA(LPDWORD lpdwError,
301 LPSTR lpszBuffer, LPDWORD lpdwBufferLength)
303 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
307 *lpdwError = lpwite->dwError;
310 strncpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
311 *lpdwBufferLength = strlen(lpszBuffer);
314 *lpdwBufferLength = 0;
320 /***********************************************************************
321 * InternetGetConnectedState (WININET.@)
323 * Return connected state
327 * if lpdwStatus is not null, return the status (off line,
328 * modem, lan...) in it.
329 * FALSE if not connected
331 BOOL WINAPI InternetGetConnectedState(LPDWORD lpdwStatus, DWORD dwReserved)
334 FIXME("always returning LAN connection.\n");
335 *lpdwStatus = INTERNET_CONNECTION_LAN;
341 /***********************************************************************
342 * InternetConnectA (WININET.@)
344 * Open a ftp, gopher or http session
347 * HINTERNET a session handle on success
351 HINTERNET WINAPI InternetConnectA(HINTERNET hInternet,
352 LPCSTR lpszServerName, INTERNET_PORT nServerPort,
353 LPCSTR lpszUserName, LPCSTR lpszPassword,
354 DWORD dwService, DWORD dwFlags, DWORD dwContext)
356 HINTERNET rc = (HINTERNET) NULL;
358 TRACE("ServerPort %i\n",nServerPort);
360 /* Clear any error information */
361 INTERNET_SetLastError(0);
365 case INTERNET_SERVICE_FTP:
366 rc = FTP_Connect(hInternet, lpszServerName, nServerPort,
367 lpszUserName, lpszPassword, dwFlags, dwContext);
370 case INTERNET_SERVICE_HTTP:
371 rc = HTTP_Connect(hInternet, lpszServerName, nServerPort,
372 lpszUserName, lpszPassword, dwFlags, dwContext);
375 case INTERNET_SERVICE_GOPHER:
384 /***********************************************************************
385 * InternetConnectW (WININET.@)
387 * Open a ftp, gopher or http session
390 * HINTERNET a session handle on success
394 HINTERNET WINAPI InternetConnectW(HINTERNET hInternet,
395 LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
396 LPCWSTR lpszUserName, LPCWSTR lpszPassword,
397 DWORD dwService, DWORD dwFlags, DWORD dwContext)
399 HINTERNET rc = (HINTERNET)NULL;
400 INT lenServer = lstrlenW(lpszServerName)+1;
401 INT lenUser = lstrlenW(lpszUserName)+1;
402 INT lenPass = lstrlenW(lpszPassword)+1;
403 CHAR *szServerName = (CHAR *)malloc(lenServer*sizeof(CHAR));
404 CHAR *szUserName = (CHAR *)malloc(lenUser*sizeof(CHAR));
405 CHAR *szPassword = (CHAR *)malloc(lenPass*sizeof(CHAR));
407 if (!szServerName || !szUserName || !szPassword)
415 return (HINTERNET)NULL;
418 WideCharToMultiByte(CP_ACP, -1, lpszServerName, -1, szServerName, lenServer,
420 WideCharToMultiByte(CP_ACP, -1, lpszUserName, -1, szUserName, lenUser,
422 WideCharToMultiByte(CP_ACP, -1, lpszPassword, -1, szPassword, lenPass,
425 rc = InternetConnectA(hInternet, szServerName, nServerPort,
426 szUserName, szPassword, dwService, dwFlags, dwContext);
435 /***********************************************************************
436 * InternetFindNextFileA (WININET.@)
438 * Continues a file search from a previous call to FindFirstFile
445 BOOL WINAPI InternetFindNextFileA(HINTERNET hFind, LPVOID lpvFindData)
447 LPWININETAPPINFOA hIC = NULL;
448 LPWININETFINDNEXTA lpwh = (LPWININETFINDNEXTA) hFind;
452 if (NULL == lpwh || lpwh->hdr.htype != WH_HFINDNEXT)
454 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
458 hIC = GET_HWININET_FROM_LPWININETFINDNEXT(lpwh);
459 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
461 WORKREQUEST workRequest;
463 workRequest.asyncall = INTERNETFINDNEXTA;
464 workRequest.HFTPSESSION = (DWORD)hFind;
465 workRequest.LPFINDFILEDATA = (DWORD)lpvFindData;
467 return INTERNET_AsyncCall(&workRequest);
471 return INTERNET_FindNextFileA(hFind, lpvFindData);
475 /***********************************************************************
476 * INTERNET_FindNextFileA (Internal)
478 * Continues a file search from a previous call to FindFirstFile
485 BOOL WINAPI INTERNET_FindNextFileA(HINTERNET hFind, LPVOID lpvFindData)
487 BOOL bSuccess = TRUE;
488 LPWININETAPPINFOA hIC = NULL;
489 LPWIN32_FIND_DATAA lpFindFileData;
490 LPWININETFINDNEXTA lpwh = (LPWININETFINDNEXTA) hFind;
494 if (NULL == lpwh || lpwh->hdr.htype != WH_HFINDNEXT)
496 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
500 /* Clear any error information */
501 INTERNET_SetLastError(0);
503 if (lpwh->hdr.lpwhparent->htype != WH_HFTPSESSION)
505 FIXME("Only FTP find next supported\n");
506 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
510 TRACE("index(%d) size(%ld)\n", lpwh->index, lpwh->size);
512 lpFindFileData = (LPWIN32_FIND_DATAA) lpvFindData;
513 ZeroMemory(lpFindFileData, sizeof(WIN32_FIND_DATAA));
515 if (lpwh->index >= lpwh->size)
517 INTERNET_SetLastError(ERROR_NO_MORE_FILES);
522 FTP_ConvertFileProp(&lpwh->lpafp[lpwh->index], lpFindFileData);
525 TRACE("\nName: %s\nSize: %ld\n", lpFindFileData->cFileName, lpFindFileData->nFileSizeLow);
529 hIC = GET_HWININET_FROM_LPWININETFINDNEXT(lpwh);
530 if (hIC->lpfnStatusCB)
532 INTERNET_ASYNC_RESULT iar;
534 iar.dwResult = (DWORD)bSuccess;
535 iar.dwError = iar.dwError = bSuccess ? ERROR_SUCCESS :
536 INTERNET_GetLastError();
538 SendAsyncCallback(hIC, hFind, lpwh->hdr.dwContext,
539 INTERNET_STATUS_REQUEST_COMPLETE, &iar,
540 sizeof(INTERNET_ASYNC_RESULT));
547 /***********************************************************************
548 * INTERNET_CloseHandle (internal)
550 * Close internet handle
556 VOID INTERNET_CloseHandle(LPWININETAPPINFOA lpwai)
560 SendAsyncCallback(lpwai, lpwai, lpwai->hdr.dwContext,
561 INTERNET_STATUS_HANDLE_CLOSING, lpwai,
564 if (lpwai->lpszAgent)
565 HeapFree(GetProcessHeap(), 0, lpwai->lpszAgent);
567 if (lpwai->lpszProxy)
568 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxy);
570 if (lpwai->lpszProxyBypass)
571 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyBypass);
573 HeapFree(GetProcessHeap(), 0, lpwai);
577 /***********************************************************************
578 * InternetCloseHandle (WININET.@)
580 * Generic close handle function
587 BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
590 LPWININETHANDLEHEADER lpwh = (LPWININETHANDLEHEADER) hInternet;
592 TRACE("%p\n",hInternet);
597 /* Clear any error information */
598 INTERNET_SetLastError(0);
604 INTERNET_CloseHandle((LPWININETAPPINFOA) lpwh);
608 case WH_HHTTPSESSION:
609 HTTP_CloseHTTPSessionHandle((LPWININETHTTPSESSIONA) lpwh);
614 HTTP_CloseHTTPRequestHandle((LPWININETHTTPREQA) lpwh);
619 retval = FTP_CloseSessionHandle((LPWININETFTPSESSIONA) lpwh);
623 retval = FTP_CloseFindNextHandle((LPWININETFINDNEXTA) lpwh);
629 } __EXCEPT(page_fault) {
630 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
639 /***********************************************************************
640 * SetUrlComponentValue (Internal)
642 * Helper function for InternetCrackUrlA
649 BOOL SetUrlComponentValue(LPSTR* lppszComponent, LPDWORD dwComponentLen,
650 LPCSTR lpszStart, INT len)
652 TRACE("%s (%d)\n", lpszStart, len);
654 if (*dwComponentLen != 0)
656 if (*lppszComponent == NULL)
658 *lppszComponent = (LPSTR)lpszStart;
659 *dwComponentLen = len;
663 INT ncpylen = min((*dwComponentLen)-1, len);
664 strncpy(*lppszComponent, lpszStart, ncpylen);
665 (*lppszComponent)[ncpylen] = '\0';
666 *dwComponentLen = ncpylen;
674 /***********************************************************************
675 * InternetCrackUrlA (WININET.@)
677 * Break up URL into its components
679 * TODO: Handle dwFlags
686 BOOL WINAPI InternetCrackUrlA(LPCSTR lpszUrl, DWORD dwUrlLength, DWORD dwFlags,
687 LPURL_COMPONENTSA lpUrlComponents)
691 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
694 LPSTR lpszParam = NULL;
695 BOOL bIsAbsolute = FALSE;
696 LPSTR lpszap = (char*)lpszUrl;
701 /* Determine if the URI is absolute. */
702 while (*lpszap != '\0')
704 if (isalnum(*lpszap))
709 if ((*lpszap == ':') && (lpszap - lpszUrl >= 2))
716 lpszcp = (LPSTR)lpszUrl; /* Relative url */
723 lpszParam = strpbrk(lpszap, ";?");
724 if (lpszParam != NULL)
726 if (!SetUrlComponentValue(&lpUrlComponents->lpszExtraInfo,
727 &lpUrlComponents->dwExtraInfoLength, lpszParam+1, strlen(lpszParam+1)))
733 if (bIsAbsolute) /* Parse <protocol>:[//<net_loc>] */
737 /* Get scheme first. */
738 lpUrlComponents->nScheme = GetInternetScheme(lpszUrl, lpszcp - lpszUrl);
739 if (!SetUrlComponentValue(&lpUrlComponents->lpszScheme,
740 &lpUrlComponents->dwSchemeLength, lpszUrl, lpszcp - lpszUrl))
743 /* Eat ':' in protocol. */
746 /* Skip over slashes. */
758 lpszNetLoc = strpbrk(lpszcp, "/");
762 lpszNetLoc = min(lpszNetLoc, lpszParam);
764 lpszNetLoc = lpszParam;
766 else if (!lpszNetLoc)
767 lpszNetLoc = lpszcp + strlen(lpszcp);
775 /* [<user>[<:password>]@]<host>[:<port>] */
776 /* First find the user and password if they exist */
778 lpszHost = strchr(lpszcp, '@');
779 if (lpszHost == NULL || lpszHost > lpszNetLoc)
781 /* username and password not specified. */
782 SetUrlComponentValue(&lpUrlComponents->lpszUserName,
783 &lpUrlComponents->dwUserNameLength, NULL, 0);
784 SetUrlComponentValue(&lpUrlComponents->lpszPassword,
785 &lpUrlComponents->dwPasswordLength, NULL, 0);
787 else /* Parse out username and password */
789 LPSTR lpszUser = lpszcp;
790 LPSTR lpszPasswd = lpszHost;
792 while (lpszcp < lpszHost)
800 SetUrlComponentValue(&lpUrlComponents->lpszUserName,
801 &lpUrlComponents->dwUserNameLength, lpszUser, lpszPasswd - lpszUser);
803 if (lpszPasswd != lpszHost)
805 SetUrlComponentValue(&lpUrlComponents->lpszPassword,
806 &lpUrlComponents->dwPasswordLength,
807 lpszPasswd == lpszHost ? NULL : lpszPasswd,
808 lpszHost - lpszPasswd);
810 lpszcp++; /* Advance to beginning of host */
813 /* Parse <host><:port> */
816 lpszPort = lpszNetLoc;
818 while (lpszcp < lpszNetLoc)
826 SetUrlComponentValue(&lpUrlComponents->lpszHostName,
827 &lpUrlComponents->dwHostNameLength, lpszHost, lpszPort - lpszHost);
829 if (lpszPort != lpszNetLoc)
830 lpUrlComponents->nPort = atoi(++lpszPort);
832 lpUrlComponents->nPort = 0;
836 /* Here lpszcp points to:
838 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
839 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
841 if (lpszcp != 0 && *lpszcp != '\0' && (!lpszParam || lpszcp < lpszParam))
845 /* Only truncate the parameter list if it's already been saved
846 * in lpUrlComponents->lpszExtraInfo.
848 if (lpszParam && lpUrlComponents->dwExtraInfoLength)
849 len = lpszParam - lpszcp;
852 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
853 * newlines if necessary.
855 LPSTR lpsznewline = strchr (lpszcp, '\n');
856 if (lpsznewline != NULL)
857 len = lpsznewline - lpszcp;
859 len = strlen(lpszcp);
862 if (!SetUrlComponentValue(&lpUrlComponents->lpszUrlPath,
863 &lpUrlComponents->dwUrlPathLength, lpszcp, len))
868 lpUrlComponents->dwUrlPathLength = 0;
871 TRACE("%s: host(%s) path(%s) extra(%s)\n", lpszUrl, lpUrlComponents->lpszHostName,
872 lpUrlComponents->lpszUrlPath, lpUrlComponents->lpszExtraInfo);
878 /***********************************************************************
879 * GetUrlCacheEntryInfoA (WININET.@)
882 BOOL WINAPI GetUrlCacheEntryInfoA(LPCSTR lpszUrl,
883 LPINTERNET_CACHE_ENTRY_INFOA lpCacheEntry,
884 LPDWORD lpCacheEntrySize)
890 /***********************************************************************
891 * CommitUrlCacheEntryA (WININET.@)
894 BOOL WINAPI CommitUrlCacheEntryA(LPCSTR lpszUrl, LPCSTR lpszLocalName,
895 FILETIME ExpireTime, FILETIME lastModified, DWORD cacheEntryType,
896 LPBYTE lpHeaderInfo, DWORD headerSize, LPCSTR fileExtension,
903 /***********************************************************************
904 * InternetAttemptConnect (WININET.@)
906 * Attempt to make a connection to the internet
909 * ERROR_SUCCESS on success
910 * Error value on failure
913 DWORD WINAPI InternetAttemptConnect(DWORD dwReserved)
916 return ERROR_SUCCESS;
920 /***********************************************************************
921 * InternetCanonicalizeUrlA (WININET.@)
923 * Escape unsafe characters and spaces
930 BOOL WINAPI InternetCanonicalizeUrlA(LPCSTR lpszUrl, LPSTR lpszBuffer,
931 LPDWORD lpdwBufferLength, DWORD dwFlags)
934 TRACE("%s %p %p %08lx\n",debugstr_a(lpszUrl), lpszBuffer,
935 lpdwBufferLength, dwFlags);
937 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
938 dwFlags ^= ICU_NO_ENCODE;
940 dwFlags |= 0x80000000; /* Don't know what this means */
942 hr = UrlCanonicalizeA(lpszUrl, lpszBuffer, lpdwBufferLength, dwFlags);
944 return (hr == S_OK) ? TRUE : FALSE;
947 /***********************************************************************
948 * InternetCanonicalizeUrlW (WININET.@)
950 * Escape unsafe characters and spaces
957 BOOL WINAPI InternetCanonicalizeUrlW(LPCWSTR lpszUrl, LPWSTR lpszBuffer,
958 LPDWORD lpdwBufferLength, DWORD dwFlags)
961 TRACE("%s %p %p %08lx\n", debugstr_w(lpszUrl), lpszBuffer,
962 lpdwBufferLength, dwFlags);
964 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
965 dwFlags ^= ICU_NO_ENCODE;
967 dwFlags |= 0x80000000; /* Don't know what this means */
969 hr = UrlCanonicalizeW(lpszUrl, lpszBuffer, lpdwBufferLength, dwFlags);
971 return (hr == S_OK) ? TRUE : FALSE;
975 /***********************************************************************
976 * InternetSetStatusCallback (WININET.@)
978 * Sets up a callback function which is called as progress is made
979 * during an operation.
982 * Previous callback or NULL on success
983 * INTERNET_INVALID_STATUS_CALLBACK on failure
986 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallback(
987 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
989 INTERNET_STATUS_CALLBACK retVal;
990 LPWININETAPPINFOA lpwai = (LPWININETAPPINFOA)hInternet;
992 TRACE("0x%08lx\n", (ULONG)hInternet);
993 if (lpwai->hdr.htype != WH_HINIT)
994 return INTERNET_INVALID_STATUS_CALLBACK;
996 retVal = lpwai->lpfnStatusCB;
997 lpwai->lpfnStatusCB = lpfnIntCB;
1003 /***********************************************************************
1004 * InternetWriteFile (WININET.@)
1006 * Write data to an open internet file
1013 BOOL WINAPI InternetWriteFile(HINTERNET hFile, LPCVOID lpBuffer ,
1014 DWORD dwNumOfBytesToWrite, LPDWORD lpdwNumOfBytesWritten)
1016 BOOL retval = FALSE;
1018 LPWININETHANDLEHEADER lpwh = (LPWININETHANDLEHEADER) hFile;
1024 switch (lpwh->htype)
1027 nSocket = ((LPWININETHTTPREQA)hFile)->nSocketFD;
1031 nSocket = ((LPWININETFILE)hFile)->nDataSocket;
1040 int res = send(nSocket, lpBuffer, dwNumOfBytesToWrite, 0);
1041 retval = (res >= 0);
1042 *lpdwNumOfBytesWritten = retval ? res : 0;
1049 /***********************************************************************
1050 * InternetReadFile (WININET.@)
1052 * Read data from an open internet file
1059 BOOL WINAPI InternetReadFile(HINTERNET hFile, LPVOID lpBuffer,
1060 DWORD dwNumOfBytesToRead, LPDWORD dwNumOfBytesRead)
1062 BOOL retval = FALSE;
1064 LPWININETHANDLEHEADER lpwh = (LPWININETHANDLEHEADER) hFile;
1071 switch (lpwh->htype)
1074 nSocket = ((LPWININETHTTPREQA)hFile)->nSocketFD;
1078 nSocket = ((LPWININETFILE)hFile)->nDataSocket;
1087 int res = recv(nSocket, lpBuffer, dwNumOfBytesToRead, 0);
1088 retval = (res >= 0);
1089 *dwNumOfBytesRead = retval ? res : 0;
1094 /***********************************************************************
1095 * InternetReadFileExA (WININET.@)
1097 * Read data from an open internet file
1104 BOOL WINAPI InternetReadFileExA(HINTERNET hFile, LPINTERNET_BUFFERSA lpBuffer,
1105 DWORD dwFlags, DWORD dwContext)
1111 /***********************************************************************
1112 * InternetReadFileExW (WININET.@)
1114 * Read data from an open internet file
1121 BOOL WINAPI InternetReadFileExW(HINTERNET hFile, LPINTERNET_BUFFERSW lpBuffer,
1122 DWORD dwFlags, DWORD dwContext)
1126 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1130 /***********************************************************************
1131 * InternetQueryOptionA (WININET.@)
1133 * Queries an options on the specified handle
1140 BOOL WINAPI InternetQueryOptionA(HINTERNET hInternet, DWORD dwOption,
1141 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
1143 LPWININETHANDLEHEADER lpwhh;
1144 BOOL bSuccess = FALSE;
1146 TRACE("0x%08lx\n", dwOption);
1148 if (NULL == hInternet)
1150 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
1154 lpwhh = (LPWININETHANDLEHEADER) hInternet;
1158 case INTERNET_OPTION_HANDLE_TYPE:
1160 ULONG type = lpwhh->htype;
1161 TRACE("INTERNET_OPTION_HANDLE_TYPE: %ld\n", type);
1163 if (*lpdwBufferLength < sizeof(ULONG))
1164 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1167 memcpy(lpBuffer, &type, sizeof(ULONG));
1168 *lpdwBufferLength = sizeof(ULONG);
1174 case INTERNET_OPTION_REQUEST_FLAGS:
1177 TRACE("INTERNET_OPTION_REQUEST_FLAGS: %ld\n", flags);
1178 if (*lpdwBufferLength < sizeof(ULONG))
1179 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1182 memcpy(lpBuffer, &flags, sizeof(ULONG));
1183 *lpdwBufferLength = sizeof(ULONG);
1189 case INTERNET_OPTION_URL:
1190 case INTERNET_OPTION_DATAFILE_NAME:
1192 ULONG type = lpwhh->htype;
1193 if (type == WH_HHTTPREQ)
1195 LPWININETHTTPREQA lpreq = hInternet;
1198 sprintf(url,"http://%s%s",lpreq->lpszHostName,lpreq->lpszPath);
1199 TRACE("INTERNET_OPTION_URL: %s\n",url);
1200 if (*lpdwBufferLength < strlen(url)+1)
1201 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1204 memcpy(lpBuffer, url, strlen(url)+1);
1205 *lpdwBufferLength = strlen(url)+1;
1211 case INTERNET_OPTION_HTTP_VERSION:
1214 * Presently hardcoded to 1.1
1216 ((HTTP_VERSION_INFO*)lpBuffer)->dwMajorVersion = 1;
1217 ((HTTP_VERSION_INFO*)lpBuffer)->dwMinorVersion = 1;
1223 FIXME("Stub! %ld \n",dwOption);
1231 /***********************************************************************
1232 * InternetSetOptionW (WININET.@)
1234 * Sets an options on the specified handle
1241 BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption,
1242 LPVOID lpBuffer, DWORD dwBufferLength)
1244 LPWININETHANDLEHEADER lpwhh;
1245 BOOL bSuccess = FALSE;
1247 TRACE("0x%08lx\n", dwOption);
1249 if (NULL == hInternet)
1251 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
1255 lpwhh = (LPWININETHANDLEHEADER) hInternet;
1260 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1269 /***********************************************************************
1270 * InternetSetOptionA (WININET.@)
1272 * Sets an options on the specified handle.
1279 BOOL WINAPI InternetSetOptionA(HINTERNET hInternet, DWORD dwOption,
1280 LPVOID lpBuffer, DWORD dwBufferLength)
1282 /* FIXME!!! implement if lpBuffer is a string, dwBufferLength is
1284 return InternetSetOptionW(hInternet,dwOption, lpBuffer,
1289 /***********************************************************************
1290 * InternetGetCookieA (WININET.@)
1292 * Retrieve cookie from the specified url
1299 BOOL WINAPI InternetGetCookieA(LPCSTR lpszUrl, LPCSTR lpszCookieName,
1300 LPSTR lpCookieData, LPDWORD lpdwSize)
1303 TRACE("(%s,%s,%p)\n", debugstr_a(lpszUrl),debugstr_a(lpszCookieName),
1309 /***********************************************************************
1310 * InternetGetCookieW (WININET.@)
1312 * Retrieve cookie from the specified url
1319 BOOL WINAPI InternetGetCookieW(LPCSTR lpszUrl, LPCWSTR lpszCookieName,
1320 LPWSTR lpCookieData, LPDWORD lpdwSize)
1323 TRACE("(%s,%s,%p)\n", debugstr_a(lpszUrl), debugstr_w(lpszCookieName),
1329 /***********************************************************************
1330 * InternetSetCookieA (WININET.@)
1332 * Sets cookie for the specified url
1339 BOOL WINAPI InternetSetCookieA(LPCSTR lpszUrl, LPCSTR lpszCookieName,
1340 LPCSTR lpCookieData)
1343 TRACE("(%s,%s,%s)\n", debugstr_a(lpszUrl),
1344 debugstr_a(lpszCookieName), debugstr_a(lpCookieData));
1349 /***********************************************************************
1350 * InternetSetCookieW (WININET.@)
1352 * Sets cookie for the specified url
1359 BOOL WINAPI InternetSetCookieW(LPCSTR lpszUrl, LPCWSTR lpszCookieName,
1360 LPCWSTR lpCookieData)
1363 TRACE("(%s,%s,%s)\n", debugstr_a(lpszUrl),
1364 debugstr_w(lpszCookieName), debugstr_w(lpCookieData));
1369 /***********************************************************************
1370 * GetInternetScheme (internal)
1376 * INTERNET_SCHEME_UNKNOWN on failure
1379 INTERNET_SCHEME GetInternetScheme(LPCSTR lpszScheme, INT nMaxCmp)
1382 if(lpszScheme==NULL)
1383 return INTERNET_SCHEME_UNKNOWN;
1385 if (!strncasecmp("ftp", lpszScheme, nMaxCmp))
1386 return INTERNET_SCHEME_FTP;
1387 else if (!strncasecmp("gopher", lpszScheme, nMaxCmp))
1388 return INTERNET_SCHEME_GOPHER;
1389 else if (!strncasecmp("http", lpszScheme, nMaxCmp))
1390 return INTERNET_SCHEME_HTTP;
1391 else if (!strncasecmp("https", lpszScheme, nMaxCmp))
1392 return INTERNET_SCHEME_HTTPS;
1393 else if (!strncasecmp("file", lpszScheme, nMaxCmp))
1394 return INTERNET_SCHEME_FILE;
1395 else if (!strncasecmp("news", lpszScheme, nMaxCmp))
1396 return INTERNET_SCHEME_NEWS;
1397 else if (!strncasecmp("mailto", lpszScheme, nMaxCmp))
1398 return INTERNET_SCHEME_MAILTO;
1400 return INTERNET_SCHEME_UNKNOWN;
1403 /***********************************************************************
1404 * InternetCheckConnectionA (WININET.@)
1406 * Pings a requested host to check internet connection
1409 * TRUE on success and FALSE on failure. If a failure then
1410 * ERROR_NOT_CONNECTED is placesd into GetLastError
1413 BOOL WINAPI InternetCheckConnectionA( LPCSTR lpszUrl, DWORD dwFlags, DWORD dwReserved )
1416 * this is a kludge which runs the resident ping program and reads the output.
1418 * Anyone have a better idea?
1429 * Crack or set the Address
1431 if (lpszUrl == NULL)
1434 * According to the doc we are supost to use the ip for the next
1435 * server in the WnInet internal server database. I have
1436 * no idea what that is or how to get it.
1438 * So someone needs to implement this.
1440 FIXME("Unimplemented with URL of NULL\n");
1445 URL_COMPONENTSA componets;
1447 ZeroMemory(&componets,sizeof(URL_COMPONENTSA));
1448 componets.lpszHostName = (LPSTR)&host;
1449 componets.dwHostNameLength = 1024;
1451 if (!InternetCrackUrlA(lpszUrl,0,0,&componets))
1454 TRACE("host name : %s\n",componets.lpszHostName);
1458 * Build our ping command
1460 strcpy(command,"ping -w 1 ");
1461 strcat(command,host);
1462 strcat(command," >/dev/null 2>/dev/null");
1464 TRACE("Ping command is : %s\n",command);
1466 status = system(command);
1468 TRACE("Ping returned a code of %i \n",status);
1470 /* Ping return code of 0 indicates success */
1477 SetLastError(ERROR_NOT_CONNECTED);
1483 /***********************************************************************
1484 * InternetCheckConnectionW (WININET.@)
1486 * Pings a requested host to check internet connection
1489 * TRUE on success and FALSE on failure. If a failure then
1490 * ERROR_NOT_CONNECTED is placed into GetLastError
1493 BOOL WINAPI InternetCheckConnectionW(LPCWSTR lpszUrl, DWORD dwFlags, DWORD dwReserved)
1499 len = lstrlenW(lpszUrl)+1;
1500 if (!(szUrl = (CHAR *)malloc(len*sizeof(CHAR))))
1502 WideCharToMultiByte(CP_ACP, -1, lpszUrl, -1, szUrl, len, NULL, NULL);
1503 rc = InternetCheckConnectionA((LPCSTR)szUrl, dwFlags, dwReserved);
1510 /**********************************************************
1511 * InternetOpenUrlA (WININET.@)
1516 * handle of connection or NULL on failure
1518 HINTERNET WINAPI InternetOpenUrlA(HINTERNET hInternet, LPCSTR lpszUrl,
1519 LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)
1521 URL_COMPONENTSA urlComponents;
1522 char protocol[32], hostName[MAXHOSTNAME], userName[1024];
1523 char password[1024], path[2048], extra[1024];
1524 HINTERNET client = NULL, client1 = NULL;
1525 urlComponents.dwStructSize = sizeof(URL_COMPONENTSA);
1526 urlComponents.lpszScheme = protocol;
1527 urlComponents.dwSchemeLength = 32;
1528 urlComponents.lpszHostName = hostName;
1529 urlComponents.dwHostNameLength = MAXHOSTNAME;
1530 urlComponents.lpszUserName = userName;
1531 urlComponents.dwUserNameLength = 1024;
1532 urlComponents.lpszPassword = password;
1533 urlComponents.dwPasswordLength = 1024;
1534 urlComponents.lpszUrlPath = path;
1535 urlComponents.dwUrlPathLength = 2048;
1536 urlComponents.lpszExtraInfo = extra;
1537 urlComponents.dwExtraInfoLength = 1024;
1538 if(!InternetCrackUrlA(lpszUrl, strlen(lpszUrl), 0, &urlComponents))
1540 switch(urlComponents.nScheme) {
1541 case INTERNET_SCHEME_FTP:
1542 if(urlComponents.nPort == 0)
1543 urlComponents.nPort = INTERNET_DEFAULT_FTP_PORT;
1544 client = InternetConnectA(hInternet, hostName, urlComponents.nPort,
1545 userName, password, INTERNET_SERVICE_FTP, dwFlags, dwContext);
1546 return FtpOpenFileA(client, path, GENERIC_READ, dwFlags, dwContext);
1548 case INTERNET_SCHEME_HTTP:
1549 case INTERNET_SCHEME_HTTPS:
1551 LPCSTR accept[2] = { "*/*", NULL };
1552 char *hostreq=(char*)malloc(strlen(hostName)+9);
1553 sprintf(hostreq, "Host: %s\r\n", hostName);
1554 if(urlComponents.nPort == 0) {
1555 if(urlComponents.nScheme == INTERNET_SCHEME_HTTP)
1556 urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
1558 urlComponents.nPort = INTERNET_DEFAULT_HTTPS_PORT;
1560 client = InternetConnectA(hInternet, hostName, urlComponents.nPort, userName,
1561 password, INTERNET_SERVICE_HTTP, dwFlags, dwContext);
1564 client1 = HttpOpenRequestA(hInternet, NULL, path, NULL, NULL, accept, dwFlags, dwContext);
1565 if(client1 == NULL) {
1566 InternetCloseHandle(client);
1569 HttpAddRequestHeadersA(client1, lpszHeaders, dwHeadersLength, HTTP_ADDREQ_FLAG_ADD);
1570 HttpAddRequestHeadersA(client1, hostreq, -1L, HTTP_ADDREQ_FLAG_ADD_IF_NEW);
1571 if(!HttpSendRequestA(client1, NULL, 0, NULL, 0)) {
1572 InternetCloseHandle(client1);
1573 InternetCloseHandle(client);
1579 case INTERNET_SCHEME_GOPHER:
1580 /* gopher doesn't seem to be implemented in wine, but it's supposed
1581 * to be supported by InternetOpenUrlA. */
1586 InternetCloseHandle(client);
1590 /**********************************************************
1591 * InternetOpenUrlW (WININET.@)
1596 * handle of connection or NULL on failure
1598 HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
1599 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)
1601 HINTERNET rc = (HINTERNET)NULL;
1603 INT lenUrl = lstrlenW(lpszUrl)+1;
1604 INT lenHeaders = lstrlenW(lpszHeaders)+1;
1605 CHAR *szUrl = (CHAR *)malloc(lenUrl*sizeof(CHAR));
1606 CHAR *szHeaders = (CHAR *)malloc(lenHeaders*sizeof(CHAR));
1608 if (!szUrl || !szHeaders)
1614 return (HINTERNET)NULL;
1617 WideCharToMultiByte(CP_ACP, -1, lpszUrl, -1, szUrl, lenUrl,
1619 WideCharToMultiByte(CP_ACP, -1, lpszHeaders, -1, szHeaders, lenHeaders,
1622 rc = InternetOpenUrlA(hInternet, szUrl, szHeaders,
1623 dwHeadersLength, dwFlags, dwContext);
1632 /***********************************************************************
1633 * INTERNET_SetLastError (internal)
1635 * Set last thread specific error
1640 void INTERNET_SetLastError(DWORD dwError)
1642 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
1644 SetLastError(dwError);
1645 lpwite->dwError = dwError;
1649 /***********************************************************************
1650 * INTERNET_GetLastError (internal)
1652 * Get last thread specific error
1657 DWORD INTERNET_GetLastError()
1659 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
1660 return lpwite->dwError;
1664 /***********************************************************************
1665 * INTERNET_WorkerThreadFunc (internal)
1667 * Worker thread execution function
1672 DWORD INTERNET_WorkerThreadFunc(LPVOID *lpvParam)
1678 dwWaitRes = WaitForMultipleObjects(2, hEventArray, FALSE, MAX_IDLE_WORKER);
1680 if (dwWaitRes == WAIT_OBJECT_0 + 1)
1681 INTERNET_ExecuteWork();
1685 InterlockedIncrement(&dwNumIdleThreads);
1688 InterlockedDecrement(&dwNumIdleThreads);
1689 InterlockedDecrement(&dwNumThreads);
1690 TRACE("Worker thread exiting\n");
1695 /***********************************************************************
1696 * INTERNET_InsertWorkRequest (internal)
1698 * Insert work request into queue
1703 BOOL INTERNET_InsertWorkRequest(LPWORKREQUEST lpWorkRequest)
1705 BOOL bSuccess = FALSE;
1706 LPWORKREQUEST lpNewRequest;
1710 lpNewRequest = HeapAlloc(GetProcessHeap(), 0, sizeof(WORKREQUEST));
1713 memcpy(lpNewRequest, lpWorkRequest, sizeof(WORKREQUEST));
1714 lpNewRequest->prev = NULL;
1716 EnterCriticalSection(&csQueue);
1718 lpNewRequest->next = lpWorkQueueTail;
1719 if (lpWorkQueueTail)
1720 lpWorkQueueTail->prev = lpNewRequest;
1721 lpWorkQueueTail = lpNewRequest;
1722 if (!lpHeadWorkQueue)
1723 lpHeadWorkQueue = lpWorkQueueTail;
1725 LeaveCriticalSection(&csQueue);
1734 /***********************************************************************
1735 * INTERNET_GetWorkRequest (internal)
1737 * Retrieves work request from queue
1742 BOOL INTERNET_GetWorkRequest(LPWORKREQUEST lpWorkRequest)
1744 BOOL bSuccess = FALSE;
1745 LPWORKREQUEST lpRequest = NULL;
1749 EnterCriticalSection(&csQueue);
1751 if (lpHeadWorkQueue)
1753 lpRequest = lpHeadWorkQueue;
1754 lpHeadWorkQueue = lpHeadWorkQueue->prev;
1755 if (lpRequest == lpWorkQueueTail)
1756 lpWorkQueueTail = lpHeadWorkQueue;
1759 LeaveCriticalSection(&csQueue);
1763 memcpy(lpWorkRequest, lpRequest, sizeof(WORKREQUEST));
1764 HeapFree(GetProcessHeap(), 0, lpRequest);
1772 /***********************************************************************
1773 * INTERNET_AsyncCall (internal)
1775 * Retrieves work request from queue
1780 BOOL INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest)
1784 BOOL bSuccess = FALSE;
1788 if (InterlockedDecrement(&dwNumIdleThreads) < 0)
1790 InterlockedIncrement(&dwNumIdleThreads);
1792 if (InterlockedIncrement(&dwNumThreads) > MAX_WORKER_THREADS ||
1793 !(hThread = CreateThread(NULL, 0,
1794 (LPTHREAD_START_ROUTINE)INTERNET_WorkerThreadFunc, NULL, 0, &dwTID)))
1796 InterlockedDecrement(&dwNumThreads);
1797 INTERNET_SetLastError(ERROR_INTERNET_ASYNC_THREAD_FAILED);
1801 TRACE("Created new thread\n");
1805 INTERNET_InsertWorkRequest(lpWorkRequest);
1806 SetEvent(hWorkEvent);
1814 /***********************************************************************
1815 * INTERNET_ExecuteWork (internal)
1820 VOID INTERNET_ExecuteWork()
1822 WORKREQUEST workRequest;
1826 if (INTERNET_GetWorkRequest(&workRequest))
1828 switch (workRequest.asyncall)
1831 FTP_FtpPutFileA((HINTERNET)workRequest.HFTPSESSION, (LPCSTR)workRequest.LPSZLOCALFILE,
1832 (LPCSTR)workRequest.LPSZNEWREMOTEFILE, workRequest.DWFLAGS, workRequest.DWCONTEXT);
1833 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZLOCALFILE);
1834 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZNEWREMOTEFILE);
1837 case FTPSETCURRENTDIRECTORYA:
1838 FTP_FtpSetCurrentDirectoryA((HINTERNET)workRequest.HFTPSESSION,
1839 (LPCSTR)workRequest.LPSZDIRECTORY);
1840 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZDIRECTORY);
1843 case FTPCREATEDIRECTORYA:
1844 FTP_FtpCreateDirectoryA((HINTERNET)workRequest.HFTPSESSION,
1845 (LPCSTR)workRequest.LPSZDIRECTORY);
1846 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZDIRECTORY);
1849 case FTPFINDFIRSTFILEA:
1850 FTP_FtpFindFirstFileA((HINTERNET)workRequest.HFTPSESSION,
1851 (LPCSTR)workRequest.LPSZSEARCHFILE,
1852 (LPWIN32_FIND_DATAA)workRequest.LPFINDFILEDATA, workRequest.DWFLAGS,
1853 workRequest.DWCONTEXT);
1854 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZSEARCHFILE);
1857 case FTPGETCURRENTDIRECTORYA:
1858 FTP_FtpGetCurrentDirectoryA((HINTERNET)workRequest.HFTPSESSION,
1859 (LPSTR)workRequest.LPSZDIRECTORY, (LPDWORD)workRequest.LPDWDIRECTORY);
1863 FTP_FtpOpenFileA((HINTERNET)workRequest.HFTPSESSION,
1864 (LPCSTR)workRequest.LPSZFILENAME,
1865 workRequest.FDWACCESS,
1866 workRequest.DWFLAGS,
1867 workRequest.DWCONTEXT);
1868 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZFILENAME);
1872 FTP_FtpGetFileA((HINTERNET)workRequest.HFTPSESSION,
1873 (LPCSTR)workRequest.LPSZREMOTEFILE,
1874 (LPCSTR)workRequest.LPSZNEWFILE,
1875 (BOOL)workRequest.FFAILIFEXISTS,
1876 workRequest.DWLOCALFLAGSATTRIBUTE,
1877 workRequest.DWFLAGS,
1878 workRequest.DWCONTEXT);
1879 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZREMOTEFILE);
1880 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZNEWFILE);
1883 case FTPDELETEFILEA:
1884 FTP_FtpDeleteFileA((HINTERNET)workRequest.HFTPSESSION,
1885 (LPCSTR)workRequest.LPSZFILENAME);
1886 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZFILENAME);
1889 case FTPREMOVEDIRECTORYA:
1890 FTP_FtpRemoveDirectoryA((HINTERNET)workRequest.HFTPSESSION,
1891 (LPCSTR)workRequest.LPSZDIRECTORY);
1892 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZDIRECTORY);
1895 case FTPRENAMEFILEA:
1896 FTP_FtpRenameFileA((HINTERNET)workRequest.HFTPSESSION,
1897 (LPCSTR)workRequest.LPSZSRCFILE,
1898 (LPCSTR)workRequest.LPSZDESTFILE);
1899 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZSRCFILE);
1900 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZDESTFILE);
1903 case INTERNETFINDNEXTA:
1904 INTERNET_FindNextFileA((HINTERNET)workRequest.HFTPSESSION,
1905 (LPWIN32_FIND_DATAA)workRequest.LPFINDFILEDATA);
1908 case HTTPSENDREQUESTA:
1909 HTTP_HttpSendRequestA((HINTERNET)workRequest.HFTPSESSION,
1910 (LPCSTR)workRequest.LPSZHEADER,
1911 workRequest.DWHEADERLENGTH,
1912 (LPVOID)workRequest.LPOPTIONAL,
1913 workRequest.DWOPTIONALLENGTH);
1914 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZHEADER);
1917 case HTTPOPENREQUESTA:
1918 HTTP_HttpOpenRequestA((HINTERNET)workRequest.HFTPSESSION,
1919 (LPCSTR)workRequest.LPSZVERB,
1920 (LPCSTR)workRequest.LPSZOBJECTNAME,
1921 (LPCSTR)workRequest.LPSZVERSION,
1922 (LPCSTR)workRequest.LPSZREFERRER,
1923 (LPCSTR*)workRequest.LPSZACCEPTTYPES,
1924 workRequest.DWFLAGS,
1925 workRequest.DWCONTEXT);
1926 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZVERB);
1927 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZOBJECTNAME);
1928 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZVERSION);
1929 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZREFERRER);
1933 SendAsyncCallbackInt((LPWININETAPPINFOA)workRequest.param1,
1934 (HINTERNET)workRequest.param2, workRequest.param3,
1935 workRequest.param4, (LPVOID)workRequest.param5,
1936 workRequest.param6);
1943 /***********************************************************************
1944 * INTERNET_GetResponseBuffer
1949 LPSTR INTERNET_GetResponseBuffer()
1951 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
1953 return lpwite->response;
1957 /***********************************************************************
1958 * INTERNET_GetNextLine (internal)
1960 * Parse next line in directory string listing
1963 * Pointer to beginning of next line
1968 LPSTR INTERNET_GetNextLine(INT nSocket, LPSTR lpszBuffer, LPDWORD dwBuffer)
1972 BOOL bSuccess = FALSE;
1978 FD_SET(nSocket, &infd);
1979 tv.tv_sec=RESPONSE_TIMEOUT;
1982 while (nRecv < *dwBuffer)
1984 if (select(nSocket+1,&infd,NULL,NULL,&tv) > 0)
1986 if (recv(nSocket, &lpszBuffer[nRecv], 1, 0) <= 0)
1988 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
1992 if (lpszBuffer[nRecv] == '\n')
1997 if (lpszBuffer[nRecv] != '\r')
2002 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT);
2010 lpszBuffer[nRecv] = '\0';
2011 *dwBuffer = nRecv - 1;
2012 TRACE(":%d %s\n", nRecv, lpszBuffer);
2021 /***********************************************************************
2024 BOOL WINAPI InternetQueryDataAvailable( HINTERNET hFile,
2025 LPDWORD lpdwNumberOfBytesAvailble,
2026 DWORD dwFlags, DWORD dwConext)
2028 LPWININETHTTPREQA lpwhr = (LPWININETHTTPREQA) hFile;
2035 SetLastError(ERROR_NO_MORE_FILES);
2039 TRACE("--> %p %i %i\n",lpwhr,lpwhr->hdr.htype,lpwhr->nSocketFD);
2041 switch (lpwhr->hdr.htype)
2044 nSocket = lpwhr->nSocketFD;
2055 retval = recv(nSocket,buffer,4048,MSG_PEEK);
2059 SetLastError(ERROR_NO_MORE_FILES);
2062 if (lpdwNumberOfBytesAvailble)
2064 (*lpdwNumberOfBytesAvailble) = retval;
2067 TRACE("<-- %i\n",retval);
2072 /***********************************************************************
2075 BOOL WINAPI InternetLockRequestFile( HINTERNET hInternet, HANDLE
2082 BOOL WINAPI InternetUnlockRequestFile( HANDLE hLockHandle)
2089 /***********************************************************************
2092 * On windows this function is supposed to dial the default internet
2093 * connection. We don't want to have Wine dial out to the internet so
2094 * we return TRUE by default. It might be nice to check if we are connected.
2101 BOOL WINAPI InternetAutoDial(DWORD dwFlags, HWND hwndParent)
2105 /* Tell that we are connected to the internet. */
2109 /***********************************************************************
2110 * InternetAutoDialHangup
2112 * Hangs up an connection made with InternetAutoDial
2121 BOOL WINAPI InternetAutodialHangup(DWORD dwReserved)
2125 /* we didn't dial, we don't disconnect */