4 * Copyright 1999 Corel Corporation
5 * Copyright 2002 CodeWeavers Inc.
6 * Copyright 2002 Jaco Greeff
7 * Copyright 2002 TransGaming Technologies Inc.
8 * Copyright 2004 Mike McCormack for CodeWeavers
14 * This library is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include "wine/port.h"
32 #define MAXHOSTNAME 100 /* from http.c */
37 #include <sys/types.h>
38 #ifdef HAVE_SYS_SOCKET_H
39 # include <sys/socket.h>
41 #ifdef HAVE_SYS_TIME_H
42 # include <sys/time.h>
56 #include "wine/debug.h"
58 #define NO_SHLWAPI_STREAM
61 #include "wine/exception.h"
66 #include "wine/unicode.h"
68 WINE_DEFAULT_DEBUG_CHANNEL(wininet);
70 #define MAX_IDLE_WORKER 1000*60*1
71 #define MAX_WORKER_THREADS 10
72 #define RESPONSE_TIMEOUT 30
74 #define GET_HWININET_FROM_LPWININETFINDNEXT(lpwh) \
75 (LPWININETAPPINFOW)(((LPWININETFTPSESSIONA)(lpwh->hdr.lpwhparent))->hdr.lpwhparent)
81 CHAR response[MAX_REPLY_LEN];
82 } WITHREADERROR, *LPWITHREADERROR;
84 BOOL WINAPI INTERNET_FindNextFileA(HINTERNET hFind, LPVOID lpvFindData);
85 HINTERNET WINAPI INTERNET_InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
86 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext);
87 VOID INTERNET_ExecuteWork();
89 DWORD g_dwTlsErrIndex = TLS_OUT_OF_INDEXES;
91 DWORD dwNumIdleThreads;
93 HANDLE hEventArray[2];
94 #define hQuitEvent hEventArray[0]
95 #define hWorkEvent hEventArray[1]
96 CRITICAL_SECTION csQueue;
97 LPWORKREQUEST lpHeadWorkQueue;
98 LPWORKREQUEST lpWorkQueueTail;
100 extern void URLCacheContainers_CreateDefaults();
101 extern void URLCacheContainers_DeleteAll();
103 #define HANDLE_CHUNK_SIZE 0x10
105 static CRITICAL_SECTION WININET_cs;
106 static CRITICAL_SECTION_DEBUG WININET_cs_debug =
109 { &WININET_cs_debug.ProcessLocksList, &WININET_cs_debug.ProcessLocksList },
110 0, 0, { 0, (DWORD)(__FILE__ ": WININET_cs") }
112 static CRITICAL_SECTION WININET_cs = { &WININET_cs_debug, -1, 0, 0, 0, 0 };
114 static LPWININETHANDLEHEADER *WININET_Handles;
115 static UINT WININET_dwNextHandle;
116 static UINT WININET_dwMaxHandles;
118 HINTERNET WININET_AllocHandle( LPWININETHANDLEHEADER info )
120 LPWININETHANDLEHEADER *p;
121 UINT handle = 0, num;
123 EnterCriticalSection( &WININET_cs );
124 if( !WININET_dwMaxHandles )
126 num = HANDLE_CHUNK_SIZE;
127 p = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
132 WININET_dwMaxHandles = num;
134 if( WININET_dwMaxHandles == WININET_dwNextHandle )
136 num = WININET_dwMaxHandles + HANDLE_CHUNK_SIZE;
137 p = HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
138 WININET_Handles, sizeof (UINT)* num);
142 WININET_dwMaxHandles = num;
145 handle = WININET_dwNextHandle;
146 if( WININET_Handles[handle] )
147 ERR("handle isn't free but should be\n");
148 WININET_Handles[handle] = info;
150 while( WININET_Handles[WININET_dwNextHandle] &&
151 (WININET_dwNextHandle < WININET_dwMaxHandles ) )
152 WININET_dwNextHandle++;
155 LeaveCriticalSection( &WININET_cs );
157 return (HINTERNET) (handle+1);
160 HINTERNET WININET_FindHandle( LPWININETHANDLEHEADER info )
164 EnterCriticalSection( &WININET_cs );
165 for( i=0; i<WININET_dwMaxHandles; i++ )
167 if( info == WININET_Handles[i] )
173 LeaveCriticalSection( &WININET_cs );
175 return (HINTERNET) handle;
178 LPWININETHANDLEHEADER WININET_GetObject( HINTERNET hinternet )
180 LPWININETHANDLEHEADER info = NULL;
181 UINT handle = (UINT) hinternet;
183 EnterCriticalSection( &WININET_cs );
185 if( (handle > 0) && ( handle <= WININET_dwMaxHandles ) )
186 info = WININET_Handles[handle-1];
188 LeaveCriticalSection( &WININET_cs );
190 TRACE("handle %d -> %p\n", handle, info);
195 BOOL WININET_FreeHandle( HINTERNET hinternet )
198 UINT handle = (UINT) hinternet;
200 EnterCriticalSection( &WININET_cs );
202 if( (handle > 1) && ( handle < WININET_dwMaxHandles ) )
205 if( WININET_Handles[handle] )
207 WININET_Handles[handle] = NULL;
209 if( WININET_dwNextHandle > handle )
210 WININET_dwNextHandle = handle;
214 LeaveCriticalSection( &WININET_cs );
219 /***********************************************************************
220 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
223 * hinstDLL [I] handle to the DLL's instance
225 * lpvReserved [I] reserved, must be NULL
232 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
234 TRACE("%p,%lx,%p\n", hinstDLL, fdwReason, lpvReserved);
237 case DLL_PROCESS_ATTACH:
239 g_dwTlsErrIndex = TlsAlloc();
241 if (g_dwTlsErrIndex == TLS_OUT_OF_INDEXES)
244 hQuitEvent = CreateEventA(0, TRUE, FALSE, NULL);
245 hWorkEvent = CreateEventA(0, FALSE, FALSE, NULL);
246 InitializeCriticalSection(&csQueue);
248 URLCacheContainers_CreateDefaults();
251 dwNumIdleThreads = 0;
254 case DLL_THREAD_ATTACH:
256 LPWITHREADERROR lpwite = HeapAlloc(GetProcessHeap(), 0, sizeof(WITHREADERROR));
260 TlsSetValue(g_dwTlsErrIndex, (LPVOID)lpwite);
264 case DLL_THREAD_DETACH:
265 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
267 LPVOID lpwite = TlsGetValue(g_dwTlsErrIndex);
269 HeapFree(GetProcessHeap(), 0, lpwite);
273 case DLL_PROCESS_DETACH:
275 URLCacheContainers_DeleteAll();
277 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
279 HeapFree(GetProcessHeap(), 0, TlsGetValue(g_dwTlsErrIndex));
280 TlsFree(g_dwTlsErrIndex);
283 SetEvent(hQuitEvent);
285 CloseHandle(hQuitEvent);
286 CloseHandle(hWorkEvent);
287 DeleteCriticalSection(&csQueue);
295 /***********************************************************************
296 * InternetInitializeAutoProxyDll (WININET.@)
298 * Setup the internal proxy
307 BOOL WINAPI InternetInitializeAutoProxyDll(DWORD dwReserved)
310 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
314 /***********************************************************************
315 * DetectAutoProxyUrl (WININET.@)
317 * Auto detect the proxy url
323 BOOL WINAPI DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl,
324 DWORD dwAutoProxyUrlLength, DWORD dwDetectFlags)
327 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
332 /***********************************************************************
333 * INTERNET_ConfigureProxyFromReg
336 * The proxy may be specified in the form 'http=proxy.my.org'
337 * Presumably that means there can be ftp=ftpproxy.my.org too.
339 static BOOL INTERNET_ConfigureProxyFromReg( LPWININETAPPINFOW lpwai )
342 DWORD r, keytype, len, enabled;
343 LPSTR lpszInternetSettings =
344 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
345 static const WCHAR szProxyServer[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
347 r = RegOpenKeyA(HKEY_CURRENT_USER, lpszInternetSettings, &key);
348 if ( r != ERROR_SUCCESS )
351 len = sizeof enabled;
352 r = RegQueryValueExA( key, "ProxyEnable", NULL, &keytype,
353 (BYTE*)&enabled, &len);
354 if( (r == ERROR_SUCCESS) && enabled )
356 TRACE("Proxy is enabled.\n");
358 /* figure out how much memory the proxy setting takes */
359 r = RegQueryValueExW( key, szProxyServer, NULL, &keytype,
361 if( (r == ERROR_SUCCESS) && len && (keytype == REG_SZ) )
364 static const WCHAR szHttp[] = {'h','t','t','p','=',0};
366 szProxy=HeapAlloc( GetProcessHeap(), 0, len );
367 RegQueryValueExW( key, szProxyServer, NULL, &keytype,
368 (BYTE*)szProxy, &len);
370 /* find the http proxy, and strip away everything else */
371 p = strstrW( szProxy, szHttp );
374 p += lstrlenW(szHttp);
375 lstrcpyW( szProxy, p );
377 p = strchrW( szProxy, ' ' );
381 lpwai->dwAccessType = INTERNET_OPEN_TYPE_PROXY;
382 lpwai->lpszProxy = szProxy;
384 TRACE("http proxy = %s\n", debugstr_w(lpwai->lpszProxy));
387 ERR("Couldn't read proxy server settings.\n");
390 TRACE("Proxy is not enabled.\n");
396 /***********************************************************************
397 * InternetOpenA (WININET.@)
399 * Per-application initialization of wininet
402 * HINTERNET on success
406 HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType,
407 LPCWSTR lpszProxy, LPCWSTR lpszProxyBypass, DWORD dwFlags)
409 LPWININETAPPINFOW lpwai = NULL;
410 HINTERNET handle = NULL;
412 if (TRACE_ON(wininet)) {
413 #define FE(x) { x, #x }
414 static const wininet_flag_info access_type[] = {
415 FE(INTERNET_OPEN_TYPE_PRECONFIG),
416 FE(INTERNET_OPEN_TYPE_DIRECT),
417 FE(INTERNET_OPEN_TYPE_PROXY),
418 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY)
420 static const wininet_flag_info flag[] = {
421 FE(INTERNET_FLAG_ASYNC),
422 FE(INTERNET_FLAG_FROM_CACHE),
423 FE(INTERNET_FLAG_OFFLINE)
427 const char *access_type_str = "Unknown";
428 DWORD flag_val = dwFlags;
430 TRACE("(%s, %li, %s, %s, %li)\n", debugstr_w(lpszAgent), dwAccessType,
431 debugstr_w(lpszProxy), debugstr_w(lpszProxyBypass), dwFlags);
432 for (i = 0; i < (sizeof(access_type) / sizeof(access_type[0])); i++) {
433 if (access_type[i].val == dwAccessType) {
434 access_type_str = access_type[i].name;
438 TRACE(" access type : %s\n", access_type_str);
440 for (i = 0; i < (sizeof(flag) / sizeof(flag[0])); i++) {
441 if (flag[i].val & flag_val) {
442 DPRINTF(" %s", flag[i].name);
443 flag_val &= ~flag[i].val;
446 if (flag_val) DPRINTF(" Unknown flags (%08lx)", flag_val);
450 /* Clear any error information */
451 INTERNET_SetLastError(0);
453 lpwai = HeapAlloc(GetProcessHeap(), 0, sizeof(WININETAPPINFOW));
456 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
460 memset(lpwai, 0, sizeof(WININETAPPINFOW));
461 lpwai->hdr.htype = WH_HINIT;
462 lpwai->hdr.lpwhparent = NULL;
463 lpwai->hdr.dwFlags = dwFlags;
464 lpwai->dwAccessType = dwAccessType;
465 lpwai->lpszProxyUsername = NULL;
466 lpwai->lpszProxyPassword = NULL;
468 handle = WININET_AllocHandle( &lpwai->hdr );
471 HeapFree( GetProcessHeap(), 0, lpwai );
472 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
476 if (NULL != lpszAgent)
478 lpwai->lpszAgent = HeapAlloc( GetProcessHeap(),0,
479 (strlenW(lpszAgent)+1)*sizeof(WCHAR));
480 if (lpwai->lpszAgent)
481 lstrcpyW( lpwai->lpszAgent, lpszAgent );
483 if(dwAccessType == INTERNET_OPEN_TYPE_PRECONFIG)
484 INTERNET_ConfigureProxyFromReg( lpwai );
485 else if (NULL != lpszProxy)
487 lpwai->lpszProxy = HeapAlloc( GetProcessHeap(), 0,
488 (strlenW(lpszProxy)+1)*sizeof(WCHAR));
489 if (lpwai->lpszProxy)
490 lstrcpyW( lpwai->lpszProxy, lpszProxy );
493 if (NULL != lpszProxyBypass)
495 lpwai->lpszProxyBypass = HeapAlloc( GetProcessHeap(), 0,
496 (strlenW(lpszProxyBypass)+1)*sizeof(WCHAR));
497 if (lpwai->lpszProxyBypass)
498 lstrcpyW( lpwai->lpszProxyBypass, lpszProxyBypass );
502 TRACE("returning %p\n", (HINTERNET)lpwai);
508 /***********************************************************************
509 * InternetOpenW (WININET.@)
511 * Per-application initialization of wininet
514 * HINTERNET on success
518 HINTERNET WINAPI InternetOpenA(LPCSTR lpszAgent, DWORD dwAccessType,
519 LPCSTR lpszProxy, LPCSTR lpszProxyBypass, DWORD dwFlags)
521 HINTERNET rc = (HINTERNET)NULL;
523 WCHAR *szAgent = NULL, *szProxy = NULL, *szBypass = NULL;
525 TRACE("(%s, 0x%08lx, %s, %s, 0x%08lx)\n", debugstr_a(lpszAgent),
526 dwAccessType, debugstr_a(lpszProxy), debugstr_a(lpszProxyBypass), dwFlags);
530 len = MultiByteToWideChar(CP_ACP, 0, lpszAgent, -1, NULL, 0);
531 szAgent = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
532 MultiByteToWideChar(CP_ACP, 0, lpszAgent, -1, szAgent, len);
537 len = MultiByteToWideChar(CP_ACP, 0, lpszProxy, -1, NULL, 0);
538 szProxy = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
539 MultiByteToWideChar(CP_ACP, 0, lpszProxy, -1, szProxy, len);
542 if( lpszProxyBypass )
544 len = MultiByteToWideChar(CP_ACP, 0, lpszProxyBypass, -1, NULL, 0);
545 szBypass = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
546 MultiByteToWideChar(CP_ACP, 0, lpszProxyBypass, -1, szBypass, len);
549 rc = InternetOpenW(szAgent, dwAccessType, szProxy, szBypass, dwFlags);
552 HeapFree(GetProcessHeap(), 0, szAgent);
554 HeapFree(GetProcessHeap(), 0, szProxy);
556 HeapFree(GetProcessHeap(), 0, szBypass);
561 /***********************************************************************
562 * InternetGetLastResponseInfoA (WININET.@)
564 * Return last wininet error description on the calling thread
567 * TRUE on success of writing to buffer
571 BOOL WINAPI InternetGetLastResponseInfoA(LPDWORD lpdwError,
572 LPSTR lpszBuffer, LPDWORD lpdwBufferLength)
574 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
578 *lpdwError = lpwite->dwError;
581 strncpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
582 *lpdwBufferLength = strlen(lpszBuffer);
585 *lpdwBufferLength = 0;
591 /***********************************************************************
592 * InternetGetConnectedState (WININET.@)
594 * Return connected state
598 * if lpdwStatus is not null, return the status (off line,
599 * modem, lan...) in it.
600 * FALSE if not connected
602 BOOL WINAPI InternetGetConnectedState(LPDWORD lpdwStatus, DWORD dwReserved)
604 TRACE("(%p, 0x%08lx)\n", lpdwStatus, dwReserved);
607 FIXME("always returning LAN connection.\n");
608 *lpdwStatus = INTERNET_CONNECTION_LAN;
613 /***********************************************************************
614 * InternetGetConnectedStateEx (WININET.@)
616 * Return connected state
620 * if lpdwStatus is not null, return the status (off line,
621 * modem, lan...) in it.
622 * FALSE if not connected
624 BOOL WINAPI InternetGetConnectedStateExW(LPDWORD lpdwStatus, LPWSTR lpszConnectionName,
625 DWORD dwNameLen, DWORD dwReserved)
627 TRACE("(%p, %s, %ld, 0x%08lx)\n", lpdwStatus, debugstr_w(lpszConnectionName), dwNameLen, dwReserved);
634 FIXME("always returning LAN connection.\n");
635 *lpdwStatus = INTERNET_CONNECTION_LAN;
640 /***********************************************************************
641 * InternetConnectA (WININET.@)
643 * Open a ftp, gopher or http session
646 * HINTERNET a session handle on success
650 HINTERNET WINAPI InternetConnectW(HINTERNET hInternet,
651 LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
652 LPCWSTR lpszUserName, LPCWSTR lpszPassword,
653 DWORD dwService, DWORD dwFlags, DWORD dwContext)
655 HINTERNET rc = (HINTERNET) NULL;
657 TRACE("(%p, %s, %i, %s, %s, %li, %li, %li)\n", hInternet, debugstr_w(lpszServerName),
658 nServerPort, debugstr_w(lpszUserName), debugstr_w(lpszPassword),
659 dwService, dwFlags, dwContext);
661 /* Clear any error information */
662 INTERNET_SetLastError(0);
666 case INTERNET_SERVICE_FTP:
667 rc = FTP_Connect(hInternet, lpszServerName, nServerPort,
668 lpszUserName, lpszPassword, dwFlags, dwContext);
671 case INTERNET_SERVICE_HTTP:
672 rc = HTTP_Connect(hInternet, lpszServerName, nServerPort,
673 lpszUserName, lpszPassword, dwFlags, dwContext);
676 case INTERNET_SERVICE_GOPHER:
681 TRACE("returning %p\n", rc);
686 /***********************************************************************
687 * InternetConnectA (WININET.@)
689 * Open a ftp, gopher or http session
692 * HINTERNET a session handle on success
696 HINTERNET WINAPI InternetConnectA(HINTERNET hInternet,
697 LPCSTR lpszServerName, INTERNET_PORT nServerPort,
698 LPCSTR lpszUserName, LPCSTR lpszPassword,
699 DWORD dwService, DWORD dwFlags, DWORD dwContext)
701 HINTERNET rc = (HINTERNET)NULL;
703 LPWSTR szServerName = NULL;
704 LPWSTR szUserName = NULL;
705 LPWSTR szPassword = NULL;
709 len = MultiByteToWideChar(CP_ACP, 0, lpszServerName, -1, NULL, 0);
710 szServerName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
711 MultiByteToWideChar(CP_ACP, 0, lpszServerName, -1, szServerName, len);
715 len = MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, NULL, 0);
716 szUserName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
717 MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, szUserName, len);
721 len = MultiByteToWideChar(CP_ACP, 0, lpszPassword, -1, NULL, 0);
722 szPassword = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
723 MultiByteToWideChar(CP_ACP, 0, lpszPassword, -1, szPassword, len);
727 rc = InternetConnectW(hInternet, szServerName, nServerPort,
728 szUserName, szPassword, dwService, dwFlags, dwContext);
730 if (szServerName) HeapFree(GetProcessHeap(), 0, szServerName);
731 if (szUserName) HeapFree(GetProcessHeap(), 0, szUserName);
732 if (szPassword) HeapFree(GetProcessHeap(), 0, szPassword);
737 /***********************************************************************
738 * InternetFindNextFileA (WININET.@)
740 * Continues a file search from a previous call to FindFirstFile
747 BOOL WINAPI InternetFindNextFileA(HINTERNET hFind, LPVOID lpvFindData)
749 LPWININETAPPINFOW hIC = NULL;
750 LPWININETFINDNEXTA lpwh;
754 lpwh = (LPWININETFINDNEXTA) WININET_GetObject( hFind );
756 if (NULL == lpwh || lpwh->hdr.htype != WH_HFINDNEXT)
758 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
762 hIC = GET_HWININET_FROM_LPWININETFINDNEXT(lpwh);
763 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
765 WORKREQUEST workRequest;
766 struct WORKREQ_INTERNETFINDNEXTA *req;
768 workRequest.asyncall = INTERNETFINDNEXTA;
769 workRequest.handle = hFind;
770 req = &workRequest.u.InternetFindNextA;
771 req->lpFindFileData = lpvFindData;
773 return INTERNET_AsyncCall(&workRequest);
777 return INTERNET_FindNextFileA(hFind, lpvFindData);
781 /***********************************************************************
782 * INTERNET_FindNextFileA (Internal)
784 * Continues a file search from a previous call to FindFirstFile
791 BOOL WINAPI INTERNET_FindNextFileA(HINTERNET hFind, LPVOID lpvFindData)
793 BOOL bSuccess = TRUE;
794 LPWININETAPPINFOW hIC = NULL;
795 LPWIN32_FIND_DATAA lpFindFileData;
796 LPWININETFINDNEXTA lpwh;
800 lpwh = (LPWININETFINDNEXTA) WININET_GetObject( hFind );
801 if (NULL == lpwh || lpwh->hdr.htype != WH_HFINDNEXT)
803 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
807 /* Clear any error information */
808 INTERNET_SetLastError(0);
810 if (lpwh->hdr.lpwhparent->htype != WH_HFTPSESSION)
812 FIXME("Only FTP find next supported\n");
813 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
817 TRACE("index(%d) size(%ld)\n", lpwh->index, lpwh->size);
819 lpFindFileData = (LPWIN32_FIND_DATAA) lpvFindData;
820 ZeroMemory(lpFindFileData, sizeof(WIN32_FIND_DATAA));
822 if (lpwh->index >= lpwh->size)
824 INTERNET_SetLastError(ERROR_NO_MORE_FILES);
829 FTP_ConvertFileProp(&lpwh->lpafp[lpwh->index], lpFindFileData);
832 TRACE("\nName: %s\nSize: %ld\n", lpFindFileData->cFileName, lpFindFileData->nFileSizeLow);
836 hIC = GET_HWININET_FROM_LPWININETFINDNEXT(lpwh);
837 if (hIC->lpfnStatusCB)
839 INTERNET_ASYNC_RESULT iar;
841 iar.dwResult = (DWORD)bSuccess;
842 iar.dwError = iar.dwError = bSuccess ? ERROR_SUCCESS :
843 INTERNET_GetLastError();
845 SendAsyncCallback(hIC, hFind, lpwh->hdr.dwContext,
846 INTERNET_STATUS_REQUEST_COMPLETE, &iar,
847 sizeof(INTERNET_ASYNC_RESULT));
854 /***********************************************************************
855 * INTERNET_CloseHandle (internal)
857 * Close internet handle
863 VOID INTERNET_CloseHandle(LPWININETAPPINFOW lpwai)
867 SendAsyncCallback(lpwai, lpwai, lpwai->hdr.dwContext,
868 INTERNET_STATUS_HANDLE_CLOSING, lpwai,
871 if (lpwai->lpszAgent)
872 HeapFree(GetProcessHeap(), 0, lpwai->lpszAgent);
874 if (lpwai->lpszProxy)
875 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxy);
877 if (lpwai->lpszProxyBypass)
878 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyBypass);
880 if (lpwai->lpszProxyUsername)
881 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyUsername);
883 if (lpwai->lpszProxyPassword)
884 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyPassword);
886 HeapFree(GetProcessHeap(), 0, lpwai);
890 /***********************************************************************
891 * InternetCloseHandle (WININET.@)
893 * Generic close handle function
900 BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
903 LPWININETHANDLEHEADER lpwh;
905 TRACE("%p\n",hInternet);
907 lpwh = WININET_GetObject( hInternet );
910 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
914 /* Clear any error information */
915 INTERNET_SetLastError(0);
921 INTERNET_CloseHandle((LPWININETAPPINFOW) lpwh);
925 case WH_HHTTPSESSION:
926 HTTP_CloseHTTPSessionHandle((LPWININETHTTPSESSIONW) lpwh);
931 HTTP_CloseHTTPRequestHandle((LPWININETHTTPREQW) lpwh);
936 retval = FTP_CloseSessionHandle((LPWININETFTPSESSIONA) lpwh);
940 retval = FTP_CloseFindNextHandle((LPWININETFINDNEXTA) lpwh);
944 retval = FTP_CloseFileTransferHandle((LPWININETFILE) lpwh);
951 WININET_FreeHandle( hInternet );
957 /***********************************************************************
958 * ConvertUrlComponentValue (Internal)
960 * Helper function for InternetCrackUrlW
963 void ConvertUrlComponentValue(LPSTR* lppszComponent, LPDWORD dwComponentLen,
964 LPWSTR lpwszComponent, DWORD dwwComponentLen,
968 if (*dwComponentLen != 0)
970 int nASCIILength=WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,NULL,0,NULL,NULL);
971 if (*lppszComponent == NULL)
973 int nASCIIOffset=WideCharToMultiByte(CP_ACP,0,lpwszStart,lpwszComponent-lpwszStart,NULL,0,NULL,NULL);
974 *lppszComponent = (LPSTR)lpszStart+nASCIIOffset;
975 *dwComponentLen = nASCIILength;
979 INT ncpylen = min((*dwComponentLen)-1, nASCIILength);
980 WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,*lppszComponent,ncpylen+1,NULL,NULL);
981 (*lppszComponent)[ncpylen]=0;
982 *dwComponentLen = ncpylen;
988 /***********************************************************************
989 * InternetCrackUrlA (WININET.@)
991 * Break up URL into its components
993 * TODO: Handle dwFlags
1000 BOOL WINAPI InternetCrackUrlA(LPCSTR lpszUrl, DWORD dwUrlLength, DWORD dwFlags,
1001 LPURL_COMPONENTSA lpUrlComponents)
1004 URL_COMPONENTSW UCW;
1007 dwUrlLength=strlen(lpszUrl);
1008 lpwszUrl=HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*(dwUrlLength+1));
1009 memset(lpwszUrl,0,sizeof(WCHAR)*(dwUrlLength+1));
1010 nLength=MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,lpwszUrl,dwUrlLength+1);
1011 memset(&UCW,0,sizeof(UCW));
1012 if(lpUrlComponents->dwHostNameLength!=0)
1013 UCW.dwHostNameLength=1;
1014 if(lpUrlComponents->dwUserNameLength!=0)
1015 UCW.dwUserNameLength=1;
1016 if(lpUrlComponents->dwPasswordLength!=0)
1017 UCW.dwPasswordLength=1;
1018 if(lpUrlComponents->dwUrlPathLength!=0)
1019 UCW.dwUrlPathLength=1;
1020 if(lpUrlComponents->dwSchemeLength!=0)
1021 UCW.dwSchemeLength=1;
1022 if(lpUrlComponents->dwExtraInfoLength!=0)
1023 UCW.dwExtraInfoLength=1;
1024 if(!InternetCrackUrlW(lpwszUrl,nLength,dwFlags,&UCW))
1026 HeapFree(GetProcessHeap(), 0, lpwszUrl);
1029 ConvertUrlComponentValue(&lpUrlComponents->lpszHostName, &lpUrlComponents->dwHostNameLength,
1030 UCW.lpszHostName, UCW.dwHostNameLength,
1032 ConvertUrlComponentValue(&lpUrlComponents->lpszUserName, &lpUrlComponents->dwUserNameLength,
1033 UCW.lpszUserName, UCW.dwUserNameLength,
1035 ConvertUrlComponentValue(&lpUrlComponents->lpszPassword, &lpUrlComponents->dwPasswordLength,
1036 UCW.lpszPassword, UCW.dwPasswordLength,
1038 ConvertUrlComponentValue(&lpUrlComponents->lpszUrlPath, &lpUrlComponents->dwUrlPathLength,
1039 UCW.lpszUrlPath, UCW.dwUrlPathLength,
1041 ConvertUrlComponentValue(&lpUrlComponents->lpszScheme, &lpUrlComponents->dwSchemeLength,
1042 UCW.lpszScheme, UCW.dwSchemeLength,
1044 ConvertUrlComponentValue(&lpUrlComponents->lpszExtraInfo, &lpUrlComponents->dwExtraInfoLength,
1045 UCW.lpszExtraInfo, UCW.dwExtraInfoLength,
1047 lpUrlComponents->nScheme=UCW.nScheme;
1048 lpUrlComponents->nPort=UCW.nPort;
1049 HeapFree(GetProcessHeap(), 0, lpwszUrl);
1051 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", lpszUrl,
1052 debugstr_an(lpUrlComponents->lpszScheme,lpUrlComponents->dwSchemeLength),
1053 debugstr_an(lpUrlComponents->lpszHostName,lpUrlComponents->dwHostNameLength),
1054 debugstr_an(lpUrlComponents->lpszUrlPath,lpUrlComponents->dwUrlPathLength),
1055 debugstr_an(lpUrlComponents->lpszExtraInfo,lpUrlComponents->dwExtraInfoLength));
1060 /***********************************************************************
1061 * GetInternetSchemeW (internal)
1067 * INTERNET_SCHEME_UNKNOWN on failure
1070 INTERNET_SCHEME GetInternetSchemeW(LPCWSTR lpszScheme, INT nMaxCmp)
1072 INTERNET_SCHEME iScheme=INTERNET_SCHEME_UNKNOWN;
1073 static const WCHAR lpszFtp[]={'f','t','p',0};
1074 static const WCHAR lpszGopher[]={'g','o','p','h','e','r',0};
1075 static const WCHAR lpszHttp[]={'h','t','t','p',0};
1076 static const WCHAR lpszHttps[]={'h','t','t','p','s',0};
1077 static const WCHAR lpszFile[]={'f','i','l','e',0};
1078 static const WCHAR lpszNews[]={'n','e','w','s',0};
1079 static const WCHAR lpszMailto[]={'m','a','i','l','t','o',0};
1080 static const WCHAR lpszRes[]={'r','e','s',0};
1081 WCHAR* tempBuffer=NULL;
1083 if(lpszScheme==NULL)
1084 return INTERNET_SCHEME_UNKNOWN;
1086 tempBuffer=HeapAlloc(GetProcessHeap(),0,(nMaxCmp+1)*sizeof(WCHAR));
1087 strncpyW(tempBuffer,lpszScheme,nMaxCmp);
1088 tempBuffer[nMaxCmp]=0;
1089 strlwrW(tempBuffer);
1090 if (nMaxCmp==strlenW(lpszFtp) && !strncmpW(lpszFtp, tempBuffer, nMaxCmp))
1091 iScheme=INTERNET_SCHEME_FTP;
1092 else if (nMaxCmp==strlenW(lpszGopher) && !strncmpW(lpszGopher, tempBuffer, nMaxCmp))
1093 iScheme=INTERNET_SCHEME_GOPHER;
1094 else if (nMaxCmp==strlenW(lpszHttp) && !strncmpW(lpszHttp, tempBuffer, nMaxCmp))
1095 iScheme=INTERNET_SCHEME_HTTP;
1096 else if (nMaxCmp==strlenW(lpszHttps) && !strncmpW(lpszHttps, tempBuffer, nMaxCmp))
1097 iScheme=INTERNET_SCHEME_HTTPS;
1098 else if (nMaxCmp==strlenW(lpszFile) && !strncmpW(lpszFile, tempBuffer, nMaxCmp))
1099 iScheme=INTERNET_SCHEME_FILE;
1100 else if (nMaxCmp==strlenW(lpszNews) && !strncmpW(lpszNews, tempBuffer, nMaxCmp))
1101 iScheme=INTERNET_SCHEME_NEWS;
1102 else if (nMaxCmp==strlenW(lpszMailto) && !strncmpW(lpszMailto, tempBuffer, nMaxCmp))
1103 iScheme=INTERNET_SCHEME_MAILTO;
1104 else if (nMaxCmp==strlenW(lpszRes) && !strncmpW(lpszRes, tempBuffer, nMaxCmp))
1105 iScheme=INTERNET_SCHEME_RES;
1106 HeapFree(GetProcessHeap(),0,tempBuffer);
1110 /***********************************************************************
1111 * SetUrlComponentValueW (Internal)
1113 * Helper function for InternetCrackUrlW
1120 BOOL SetUrlComponentValueW(LPWSTR* lppszComponent, LPDWORD dwComponentLen, LPCWSTR lpszStart, INT len)
1122 TRACE("%s (%d)\n", debugstr_wn(lpszStart,len), len);
1124 if (*dwComponentLen != 0 || *lppszComponent == NULL)
1126 if (*lppszComponent == NULL)
1128 *lppszComponent = (LPWSTR)lpszStart;
1129 *dwComponentLen = len;
1133 INT ncpylen = min((*dwComponentLen)-1, len);
1134 strncpyW(*lppszComponent, lpszStart, ncpylen);
1135 (*lppszComponent)[ncpylen] = '\0';
1136 *dwComponentLen = ncpylen;
1143 /***********************************************************************
1144 * InternetCrackUrlW (WININET.@)
1146 BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl, DWORD dwUrlLength, DWORD dwFlags,
1147 LPURL_COMPONENTSW lpUC)
1151 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1154 LPWSTR lpszParam = NULL;
1155 BOOL bIsAbsolute = FALSE;
1156 LPWSTR lpszap = (WCHAR*)lpszUrl;
1157 LPWSTR lpszcp = NULL;
1158 const WCHAR lpszSeparators[3]={';','?',0};
1159 const WCHAR lpszSlash[2]={'/',0};
1161 dwUrlLength=strlenW(lpszUrl);
1165 /* Determine if the URI is absolute. */
1166 while (*lpszap != '\0')
1168 if (isalnumW(*lpszap))
1173 if ((*lpszap == ':') && (lpszap - lpszUrl >= 2))
1180 lpszcp = (LPWSTR)lpszUrl; /* Relative url */
1186 /* Parse <params> */
1187 lpszParam = strpbrkW(lpszap, lpszSeparators);
1188 if (lpszParam != NULL)
1190 if (!SetUrlComponentValueW(&lpUC->lpszExtraInfo, &lpUC->dwExtraInfoLength,
1191 lpszParam, dwUrlLength-(lpszParam-lpszUrl)))
1197 if (bIsAbsolute) /* Parse <protocol>:[//<net_loc>] */
1200 static const WCHAR wszAbout[]={'a','b','o','u','t',':',0};
1202 /* Get scheme first. */
1203 lpUC->nScheme = GetInternetSchemeW(lpszUrl, lpszcp - lpszUrl);
1204 if (!SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength,
1205 lpszUrl, lpszcp - lpszUrl))
1208 /* Eat ':' in protocol. */
1211 /* if the scheme is "about", there is no host */
1212 if(strncmpW(wszAbout,lpszUrl, lpszcp - lpszUrl)==0)
1214 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1215 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1216 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1221 /* Skip over slashes. */
1233 lpszNetLoc = strpbrkW(lpszcp, lpszSlash);
1237 lpszNetLoc = min(lpszNetLoc, lpszParam);
1239 lpszNetLoc = lpszParam;
1241 else if (!lpszNetLoc)
1242 lpszNetLoc = lpszcp + dwUrlLength-(lpszcp-lpszUrl);
1250 /* [<user>[<:password>]@]<host>[:<port>] */
1251 /* First find the user and password if they exist */
1253 lpszHost = strchrW(lpszcp, '@');
1254 if (lpszHost == NULL || lpszHost > lpszNetLoc)
1256 /* username and password not specified. */
1257 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1258 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1260 else /* Parse out username and password */
1262 LPWSTR lpszUser = lpszcp;
1263 LPWSTR lpszPasswd = lpszHost;
1265 while (lpszcp < lpszHost)
1268 lpszPasswd = lpszcp;
1273 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength,
1274 lpszUser, lpszPasswd - lpszUser);
1276 if (lpszPasswd != lpszHost)
1278 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength,
1279 lpszPasswd == lpszHost ? NULL : lpszPasswd,
1280 lpszHost - lpszPasswd);
1282 lpszcp++; /* Advance to beginning of host */
1285 /* Parse <host><:port> */
1288 lpszPort = lpszNetLoc;
1290 /* special case for res:// URLs: there is no port here, so the host is the
1291 entire string up to the first '/' */
1292 if(lpUC->nScheme==INTERNET_SCHEME_RES)
1294 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1295 lpszHost, lpszPort - lpszHost);
1301 while (lpszcp < lpszNetLoc)
1309 /* If the scheme is "file" and the host is just one letter, it's not a host */
1310 if(lpUC->nScheme==INTERNET_SCHEME_FILE && (lpszPort-lpszHost)==1)
1313 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1319 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1320 lpszHost, lpszPort - lpszHost);
1321 if (lpszPort != lpszNetLoc)
1322 lpUC->nPort = atoiW(++lpszPort);
1331 /* Here lpszcp points to:
1333 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1334 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1336 if (lpszcp != 0 && *lpszcp != '\0' && (!lpszParam || lpszcp < lpszParam))
1340 /* Only truncate the parameter list if it's already been saved
1341 * in lpUC->lpszExtraInfo.
1343 if (lpszParam && lpUC->dwExtraInfoLength)
1344 len = lpszParam - lpszcp;
1347 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1348 * newlines if necessary.
1350 LPWSTR lpsznewline = strchrW(lpszcp, '\n');
1351 if (lpsznewline != NULL)
1352 len = lpsznewline - lpszcp;
1354 len = dwUrlLength-(lpszcp-lpszUrl);
1357 if (!SetUrlComponentValueW(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength,
1363 lpUC->dwUrlPathLength = 0;
1366 TRACE("%s: host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl,dwUrlLength),
1367 debugstr_wn(lpUC->lpszHostName,lpUC->dwHostNameLength),
1368 debugstr_wn(lpUC->lpszUrlPath,lpUC->dwUrlPathLength),
1369 debugstr_wn(lpUC->lpszExtraInfo,lpUC->dwExtraInfoLength));
1374 /***********************************************************************
1375 * InternetAttemptConnect (WININET.@)
1377 * Attempt to make a connection to the internet
1380 * ERROR_SUCCESS on success
1381 * Error value on failure
1384 DWORD WINAPI InternetAttemptConnect(DWORD dwReserved)
1387 return ERROR_SUCCESS;
1391 /***********************************************************************
1392 * InternetCanonicalizeUrlA (WININET.@)
1394 * Escape unsafe characters and spaces
1401 BOOL WINAPI InternetCanonicalizeUrlA(LPCSTR lpszUrl, LPSTR lpszBuffer,
1402 LPDWORD lpdwBufferLength, DWORD dwFlags)
1405 TRACE("%s %p %p %08lx\n",debugstr_a(lpszUrl), lpszBuffer,
1406 lpdwBufferLength, dwFlags);
1408 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1409 dwFlags ^= ICU_NO_ENCODE;
1411 dwFlags |= 0x80000000; /* Don't know what this means */
1413 hr = UrlCanonicalizeA(lpszUrl, lpszBuffer, lpdwBufferLength, dwFlags);
1415 return (hr == S_OK) ? TRUE : FALSE;
1418 /***********************************************************************
1419 * InternetCanonicalizeUrlW (WININET.@)
1421 * Escape unsafe characters and spaces
1428 BOOL WINAPI InternetCanonicalizeUrlW(LPCWSTR lpszUrl, LPWSTR lpszBuffer,
1429 LPDWORD lpdwBufferLength, DWORD dwFlags)
1432 TRACE("%s %p %p %08lx\n", debugstr_w(lpszUrl), lpszBuffer,
1433 lpdwBufferLength, dwFlags);
1435 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1436 dwFlags ^= ICU_NO_ENCODE;
1438 dwFlags |= 0x80000000; /* Don't know what this means */
1440 hr = UrlCanonicalizeW(lpszUrl, lpszBuffer, lpdwBufferLength, dwFlags);
1442 return (hr == S_OK) ? TRUE : FALSE;
1446 /***********************************************************************
1447 * InternetSetStatusCallbackA (WININET.@)
1449 * Sets up a callback function which is called as progress is made
1450 * during an operation.
1453 * Previous callback or NULL on success
1454 * INTERNET_INVALID_STATUS_CALLBACK on failure
1457 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackA(
1458 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
1460 INTERNET_STATUS_CALLBACK retVal;
1461 LPWININETAPPINFOW lpwai;
1463 lpwai = (LPWININETAPPINFOW)WININET_GetObject(hInternet);
1467 TRACE("0x%08lx\n", (ULONG)hInternet);
1468 if (lpwai->hdr.htype != WH_HINIT)
1469 return INTERNET_INVALID_STATUS_CALLBACK;
1471 retVal = lpwai->lpfnStatusCB;
1472 lpwai->lpfnStatusCB = lpfnIntCB;
1477 /***********************************************************************
1478 * InternetSetFilePointer (WININET.@)
1480 DWORD WINAPI InternetSetFilePointer(HINTERNET f1, LONG f2, PVOID f3, DWORD f4, DWORD f5)
1486 /***********************************************************************
1487 * InternetWriteFile (WININET.@)
1489 * Write data to an open internet file
1496 BOOL WINAPI InternetWriteFile(HINTERNET hFile, LPCVOID lpBuffer ,
1497 DWORD dwNumOfBytesToWrite, LPDWORD lpdwNumOfBytesWritten)
1499 BOOL retval = FALSE;
1501 LPWININETHANDLEHEADER lpwh;
1504 lpwh = (LPWININETHANDLEHEADER) WININET_GetObject( hFile );
1508 switch (lpwh->htype)
1511 FIXME("This shouldn't be here! We don't support this kind"
1512 " of connection anymore. Must use NETCON functions,"
1513 " especially if using SSL\n");
1514 nSocket = ((LPWININETHTTPREQW)lpwh)->netConnection.socketFD;
1518 nSocket = ((LPWININETFILE)lpwh)->nDataSocket;
1527 int res = send(nSocket, lpBuffer, dwNumOfBytesToWrite, 0);
1528 retval = (res >= 0);
1529 *lpdwNumOfBytesWritten = retval ? res : 0;
1536 /***********************************************************************
1537 * InternetReadFile (WININET.@)
1539 * Read data from an open internet file
1546 BOOL WINAPI InternetReadFile(HINTERNET hFile, LPVOID lpBuffer,
1547 DWORD dwNumOfBytesToRead, LPDWORD dwNumOfBytesRead)
1549 BOOL retval = FALSE;
1551 LPWININETHANDLEHEADER lpwh;
1555 lpwh = (LPWININETHANDLEHEADER) WININET_GetObject( hFile );
1559 /* FIXME: this should use NETCON functions! */
1560 switch (lpwh->htype)
1563 if (!NETCON_recv(&((LPWININETHTTPREQW)lpwh)->netConnection, lpBuffer,
1564 dwNumOfBytesToRead, 0, (int *)dwNumOfBytesRead))
1566 *dwNumOfBytesRead = 0;
1567 retval = TRUE; /* Under windows, it seems to return 0 even if nothing was read... */
1574 /* FIXME: FTP should use NETCON_ stuff */
1575 nSocket = ((LPWININETFILE)lpwh)->nDataSocket;
1578 int res = recv(nSocket, lpBuffer, dwNumOfBytesToRead, 0);
1579 retval = (res >= 0);
1580 *dwNumOfBytesRead = retval ? res : 0;
1591 /***********************************************************************
1592 * InternetReadFileExA (WININET.@)
1594 * Read data from an open internet file
1601 BOOL WINAPI InternetReadFileExA(HINTERNET hFile, LPINTERNET_BUFFERSA lpBuffer,
1602 DWORD dwFlags, DWORD dwContext)
1608 /***********************************************************************
1609 * InternetReadFileExW (WININET.@)
1611 * Read data from an open internet file
1618 BOOL WINAPI InternetReadFileExW(HINTERNET hFile, LPINTERNET_BUFFERSW lpBuffer,
1619 DWORD dwFlags, DWORD dwContext)
1623 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1627 /***********************************************************************
1628 * INET_QueryOptionHelper (internal)
1630 static BOOL INET_QueryOptionHelper(BOOL bIsUnicode, HINTERNET hInternet, DWORD dwOption,
1631 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
1633 LPWININETHANDLEHEADER lpwhh;
1634 BOOL bSuccess = FALSE;
1636 TRACE("(%p, 0x%08lx, %p, %p)\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
1638 lpwhh = (LPWININETHANDLEHEADER) WININET_GetObject( hInternet );
1644 case INTERNET_OPTION_HANDLE_TYPE:
1646 ULONG type = lpwhh->htype;
1647 TRACE("INTERNET_OPTION_HANDLE_TYPE: %ld\n", type);
1649 if (*lpdwBufferLength < sizeof(ULONG))
1650 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1653 memcpy(lpBuffer, &type, sizeof(ULONG));
1654 *lpdwBufferLength = sizeof(ULONG);
1660 case INTERNET_OPTION_REQUEST_FLAGS:
1663 TRACE("INTERNET_OPTION_REQUEST_FLAGS: %ld\n", flags);
1664 if (*lpdwBufferLength < sizeof(ULONG))
1665 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1668 memcpy(lpBuffer, &flags, sizeof(ULONG));
1669 *lpdwBufferLength = sizeof(ULONG);
1675 case INTERNET_OPTION_URL:
1676 case INTERNET_OPTION_DATAFILE_NAME:
1678 ULONG type = lpwhh->htype;
1679 if (type == WH_HHTTPREQ)
1681 LPWININETHTTPREQW lpreq = (LPWININETHTTPREQW) lpwhh;
1683 static const WCHAR szFmt[] = {'h','t','t','p',':','/','/','%','s','%','s',0};
1685 sprintfW(url,szFmt,lpreq->lpszHostName,lpreq->lpszPath);
1686 TRACE("INTERNET_OPTION_URL: %s\n",debugstr_w(url));
1687 if (*lpdwBufferLength < strlenW(url)+1)
1688 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1693 *lpdwBufferLength=WideCharToMultiByte(CP_ACP,0,url,-1,lpBuffer,*lpdwBufferLength,NULL,NULL);
1697 strcpyW(lpBuffer, url);
1698 *lpdwBufferLength = strlenW(url)+1;
1705 case INTERNET_OPTION_HTTP_VERSION:
1708 * Presently hardcoded to 1.1
1710 ((HTTP_VERSION_INFO*)lpBuffer)->dwMajorVersion = 1;
1711 ((HTTP_VERSION_INFO*)lpBuffer)->dwMinorVersion = 1;
1715 case INTERNET_OPTION_SECURITY_FLAGS:
1716 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
1720 FIXME("Stub! %ld \n",dwOption);
1727 /***********************************************************************
1728 * InternetQueryOptionW (WININET.@)
1730 * Queries an options on the specified handle
1737 BOOL WINAPI InternetQueryOptionW(HINTERNET hInternet, DWORD dwOption,
1738 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
1740 return INET_QueryOptionHelper(TRUE, hInternet, dwOption, lpBuffer, lpdwBufferLength);
1743 /***********************************************************************
1744 * InternetQueryOptionA (WININET.@)
1746 * Queries an options on the specified handle
1753 BOOL WINAPI InternetQueryOptionA(HINTERNET hInternet, DWORD dwOption,
1754 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
1756 return INET_QueryOptionHelper(FALSE, hInternet, dwOption, lpBuffer, lpdwBufferLength);
1760 /***********************************************************************
1761 * InternetSetOptionW (WININET.@)
1763 * Sets an options on the specified handle
1770 BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption,
1771 LPVOID lpBuffer, DWORD dwBufferLength)
1773 LPWININETHANDLEHEADER lpwhh;
1775 TRACE("0x%08lx\n", dwOption);
1777 lpwhh = (LPWININETHANDLEHEADER) WININET_GetObject( hInternet );
1783 case INTERNET_OPTION_HTTP_VERSION:
1785 HTTP_VERSION_INFO* pVersion=(HTTP_VERSION_INFO*)lpBuffer;
1786 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%ld,%ld): STUB\n",pVersion->dwMajorVersion,pVersion->dwMinorVersion);
1789 case INTERNET_OPTION_ERROR_MASK:
1791 unsigned long flags=*(unsigned long*)lpBuffer;
1792 FIXME("Option INTERNET_OPTION_ERROR_MASK(%ld): STUB\n",flags);
1795 case INTERNET_OPTION_CODEPAGE:
1797 unsigned long codepage=*(unsigned long*)lpBuffer;
1798 FIXME("Option INTERNET_OPTION_CODEPAGE (%ld): STUB\n",codepage);
1801 case INTERNET_OPTION_REQUEST_PRIORITY:
1803 unsigned long priority=*(unsigned long*)lpBuffer;
1804 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%ld): STUB\n",priority);
1807 case INTERNET_OPTION_CONNECT_TIMEOUT:
1809 unsigned long connecttimeout=*(unsigned long*)lpBuffer;
1810 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%ld): STUB\n",connecttimeout);
1813 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT:
1815 unsigned long receivetimeout=*(unsigned long*)lpBuffer;
1816 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%ld): STUB\n",receivetimeout);
1819 case INTERNET_OPTION_RESET_URLCACHE_SESSION:
1820 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
1822 case INTERNET_OPTION_END_BROWSER_SESSION:
1823 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
1825 case INTERNET_OPTION_CONNECTED_STATE:
1826 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
1829 FIXME("Option %ld STUB\n",dwOption);
1830 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1838 /***********************************************************************
1839 * InternetSetOptionA (WININET.@)
1841 * Sets an options on the specified handle.
1848 BOOL WINAPI InternetSetOptionA(HINTERNET hInternet, DWORD dwOption,
1849 LPVOID lpBuffer, DWORD dwBufferLength)
1857 case INTERNET_OPTION_PROXY:
1859 LPINTERNET_PROXY_INFOA pi = (LPINTERNET_PROXY_INFOA) lpBuffer;
1860 LPINTERNET_PROXY_INFOW piw;
1861 DWORD proxlen, prbylen;
1864 proxlen = MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, NULL, 0);
1865 prbylen= MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, NULL, 0);
1866 wlen = sizeof(*piw) + proxlen + prbylen;
1867 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
1868 piw = (LPINTERNET_PROXY_INFOW) wbuffer;
1869 piw->dwAccessType = pi->dwAccessType;
1870 prox = (LPWSTR) &piw[1];
1871 prby = &prox[proxlen+1];
1872 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, prox, proxlen);
1873 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, prby, prbylen);
1874 piw->lpszProxy = prox;
1875 piw->lpszProxyBypass = prby;
1878 case INTERNET_OPTION_USER_AGENT:
1879 case INTERNET_OPTION_USERNAME:
1880 case INTERNET_OPTION_PASSWORD:
1881 wlen = MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
1883 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
1884 MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
1889 wlen = dwBufferLength;
1892 r = InternetSetOptionW(hInternet,dwOption, wbuffer, wlen);
1894 if( lpBuffer != wbuffer )
1895 HeapFree( GetProcessHeap(), 0, wbuffer );
1901 /***********************************************************************
1902 * InternetSetOptionExA (WININET.@)
1904 BOOL WINAPI InternetSetOptionExA(HINTERNET hInternet, DWORD dwOption,
1905 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
1907 FIXME("Flags %08lx ignored\n", dwFlags);
1908 return InternetSetOptionA( hInternet, dwOption, lpBuffer, dwBufferLength );
1911 /***********************************************************************
1912 * InternetSetOptionExW (WININET.@)
1914 BOOL WINAPI InternetSetOptionExW(HINTERNET hInternet, DWORD dwOption,
1915 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
1917 FIXME("Flags %08lx ignored\n", dwFlags);
1918 if( dwFlags & ~ISO_VALID_FLAGS )
1920 SetLastError( ERROR_INVALID_PARAMETER );
1923 return InternetSetOptionW( hInternet, dwOption, lpBuffer, dwBufferLength );
1927 /***********************************************************************
1928 * InternetCheckConnectionA (WININET.@)
1930 * Pings a requested host to check internet connection
1933 * TRUE on success and FALSE on failure. If a failure then
1934 * ERROR_NOT_CONNECTED is placesd into GetLastError
1937 BOOL WINAPI InternetCheckConnectionA( LPCSTR lpszUrl, DWORD dwFlags, DWORD dwReserved )
1940 * this is a kludge which runs the resident ping program and reads the output.
1942 * Anyone have a better idea?
1953 * Crack or set the Address
1955 if (lpszUrl == NULL)
1958 * According to the doc we are supost to use the ip for the next
1959 * server in the WnInet internal server database. I have
1960 * no idea what that is or how to get it.
1962 * So someone needs to implement this.
1964 FIXME("Unimplemented with URL of NULL\n");
1969 URL_COMPONENTSA componets;
1971 ZeroMemory(&componets,sizeof(URL_COMPONENTSA));
1972 componets.lpszHostName = (LPSTR)&host;
1973 componets.dwHostNameLength = 1024;
1975 if (!InternetCrackUrlA(lpszUrl,0,0,&componets))
1978 TRACE("host name : %s\n",componets.lpszHostName);
1982 * Build our ping command
1984 strcpy(command,"ping -w 1 ");
1985 strcat(command,host);
1986 strcat(command," >/dev/null 2>/dev/null");
1988 TRACE("Ping command is : %s\n",command);
1990 status = system(command);
1992 TRACE("Ping returned a code of %i \n",status);
1994 /* Ping return code of 0 indicates success */
2001 SetLastError(ERROR_NOT_CONNECTED);
2007 /***********************************************************************
2008 * InternetCheckConnectionW (WININET.@)
2010 * Pings a requested host to check internet connection
2013 * TRUE on success and FALSE on failure. If a failure then
2014 * ERROR_NOT_CONNECTED is placed into GetLastError
2017 BOOL WINAPI InternetCheckConnectionW(LPCWSTR lpszUrl, DWORD dwFlags, DWORD dwReserved)
2023 len = WideCharToMultiByte(CP_ACP, 0, lpszUrl, -1, NULL, 0, NULL, NULL);
2024 if (!(szUrl = (CHAR *)HeapAlloc(GetProcessHeap(), 0, len*sizeof(CHAR))))
2026 WideCharToMultiByte(CP_ACP, 0, lpszUrl, -1, szUrl, len, NULL, NULL);
2027 rc = InternetCheckConnectionA((LPCSTR)szUrl, dwFlags, dwReserved);
2028 HeapFree(GetProcessHeap(), 0, szUrl);
2034 /**********************************************************
2035 * INTERNET_InternetOpenUrlW (internal)
2040 * handle of connection or NULL on failure
2042 HINTERNET WINAPI INTERNET_InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
2043 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)
2045 URL_COMPONENTSW urlComponents;
2046 WCHAR protocol[32], hostName[MAXHOSTNAME], userName[1024];
2047 WCHAR password[1024], path[2048], extra[1024];
2048 HINTERNET client = NULL, client1 = NULL;
2050 TRACE("(%p, %s, %s, %08lx, %08lx, %08lx\n", hInternet, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
2051 dwHeadersLength, dwFlags, dwContext);
2053 urlComponents.dwStructSize = sizeof(URL_COMPONENTSW);
2054 urlComponents.lpszScheme = protocol;
2055 urlComponents.dwSchemeLength = 32;
2056 urlComponents.lpszHostName = hostName;
2057 urlComponents.dwHostNameLength = MAXHOSTNAME;
2058 urlComponents.lpszUserName = userName;
2059 urlComponents.dwUserNameLength = 1024;
2060 urlComponents.lpszPassword = password;
2061 urlComponents.dwPasswordLength = 1024;
2062 urlComponents.lpszUrlPath = path;
2063 urlComponents.dwUrlPathLength = 2048;
2064 urlComponents.lpszExtraInfo = extra;
2065 urlComponents.dwExtraInfoLength = 1024;
2066 if(!InternetCrackUrlW(lpszUrl, strlenW(lpszUrl), 0, &urlComponents))
2068 switch(urlComponents.nScheme) {
2069 case INTERNET_SCHEME_FTP:
2070 if(urlComponents.nPort == 0)
2071 urlComponents.nPort = INTERNET_DEFAULT_FTP_PORT;
2072 client = InternetConnectW(hInternet, hostName, urlComponents.nPort,
2073 userName, password, INTERNET_SERVICE_FTP, dwFlags, dwContext);
2074 client1 = FtpOpenFileW(client, path, GENERIC_READ, dwFlags, dwContext);
2077 case INTERNET_SCHEME_HTTP:
2078 case INTERNET_SCHEME_HTTPS: {
2079 static const WCHAR szStars[] = { '*','/','*', 0 };
2080 LPCWSTR accept[2] = { szStars, NULL };
2081 if(urlComponents.nPort == 0) {
2082 if(urlComponents.nScheme == INTERNET_SCHEME_HTTP)
2083 urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
2085 urlComponents.nPort = INTERNET_DEFAULT_HTTPS_PORT;
2087 client = InternetConnectW(hInternet, hostName, urlComponents.nPort, userName,
2088 password, INTERNET_SERVICE_HTTP, dwFlags, dwContext);
2091 client1 = HttpOpenRequestW(client, NULL, path, NULL, NULL, accept, dwFlags, dwContext);
2092 if(client1 == NULL) {
2093 InternetCloseHandle(client);
2096 HttpAddRequestHeadersW(client1, lpszHeaders, dwHeadersLength, HTTP_ADDREQ_FLAG_ADD);
2097 if (!HTTP_HttpSendRequestW(client1, NULL, 0, NULL, 0)) {
2098 InternetCloseHandle(client1);
2099 InternetCloseHandle(client);
2104 case INTERNET_SCHEME_GOPHER:
2105 /* gopher doesn't seem to be implemented in wine, but it's supposed
2106 * to be supported by InternetOpenUrlA. */
2111 TRACE(" %p <--\n", client1);
2116 /**********************************************************
2117 * InternetOpenUrlW (WININET.@)
2122 * handle of connection or NULL on failure
2124 HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
2125 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)
2127 HINTERNET ret = NULL;
2128 LPWININETAPPINFOW hIC = NULL;
2130 TRACE("(%p, %s, %s, %08lx, %08lx, %08lx\n", hInternet, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
2131 dwHeadersLength, dwFlags, dwContext);
2133 hIC = (LPWININETAPPINFOW) WININET_GetObject( hInternet );
2134 if (NULL == hIC || hIC->hdr.htype != WH_HINIT) {
2135 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2139 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC) {
2140 WORKREQUEST workRequest;
2141 struct WORKREQ_INTERNETOPENURLW *req;
2143 workRequest.asyncall = INTERNETOPENURLW;
2144 workRequest.handle = hInternet;
2145 req = &workRequest.u.InternetOpenUrlW;
2147 req->lpszUrl = WININET_strdupW(lpszUrl);
2151 req->lpszHeaders = WININET_strdupW(lpszHeaders);
2153 req->lpszHeaders = 0;
2154 req->dwHeadersLength = dwHeadersLength;
2155 req->dwFlags = dwFlags;
2156 req->dwContext = dwContext;
2158 INTERNET_AsyncCall(&workRequest);
2160 * This is from windows.
2162 SetLastError(ERROR_IO_PENDING);
2164 ret = INTERNET_InternetOpenUrlW(hInternet, lpszUrl, lpszHeaders, dwHeadersLength, dwFlags, dwContext);
2168 TRACE(" %p <--\n", ret);
2173 /**********************************************************
2174 * InternetOpenUrlA (WININET.@)
2179 * handle of connection or NULL on failure
2181 HINTERNET WINAPI InternetOpenUrlA(HINTERNET hInternet, LPCSTR lpszUrl,
2182 LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)
2184 HINTERNET rc = (HINTERNET)NULL;
2188 LPWSTR szUrl = NULL;
2189 LPWSTR szHeaders = NULL;
2194 lenUrl = MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, NULL, 0 );
2195 szUrl = HeapAlloc(GetProcessHeap(), 0, lenUrl*sizeof(WCHAR));
2197 return (HINTERNET)NULL;
2198 MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, szUrl, lenUrl);
2202 lenHeaders = MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, NULL, 0 );
2203 szHeaders = HeapAlloc(GetProcessHeap(), 0, lenHeaders*sizeof(WCHAR));
2205 if(szUrl) HeapFree(GetProcessHeap(), 0, szUrl);
2206 return (HINTERNET)NULL;
2208 MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, szHeaders, lenHeaders);
2211 rc = InternetOpenUrlW(hInternet, szUrl, szHeaders,
2212 lenHeaders, dwFlags, dwContext);
2214 if(szUrl) HeapFree(GetProcessHeap(), 0, szUrl);
2215 if(szHeaders) HeapFree(GetProcessHeap(), 0, szHeaders);
2221 /***********************************************************************
2222 * INTERNET_SetLastError (internal)
2224 * Set last thread specific error
2229 void INTERNET_SetLastError(DWORD dwError)
2231 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
2233 SetLastError(dwError);
2235 lpwite->dwError = dwError;
2239 /***********************************************************************
2240 * INTERNET_GetLastError (internal)
2242 * Get last thread specific error
2247 DWORD INTERNET_GetLastError()
2249 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
2250 return lpwite->dwError;
2254 /***********************************************************************
2255 * INTERNET_WorkerThreadFunc (internal)
2257 * Worker thread execution function
2262 DWORD INTERNET_WorkerThreadFunc(LPVOID *lpvParam)
2269 INTERNET_ExecuteWork();
2272 dwWaitRes = WaitForMultipleObjects(2, hEventArray, FALSE, MAX_IDLE_WORKER);
2274 if (dwWaitRes == WAIT_OBJECT_0 + 1)
2275 INTERNET_ExecuteWork();
2279 InterlockedIncrement(&dwNumIdleThreads);
2282 InterlockedDecrement(&dwNumIdleThreads);
2283 InterlockedDecrement(&dwNumThreads);
2284 TRACE("Worker thread exiting\n");
2289 /***********************************************************************
2290 * INTERNET_InsertWorkRequest (internal)
2292 * Insert work request into queue
2297 BOOL INTERNET_InsertWorkRequest(LPWORKREQUEST lpWorkRequest)
2299 BOOL bSuccess = FALSE;
2300 LPWORKREQUEST lpNewRequest;
2304 lpNewRequest = HeapAlloc(GetProcessHeap(), 0, sizeof(WORKREQUEST));
2307 memcpy(lpNewRequest, lpWorkRequest, sizeof(WORKREQUEST));
2308 lpNewRequest->prev = NULL;
2310 EnterCriticalSection(&csQueue);
2312 lpNewRequest->next = lpWorkQueueTail;
2313 if (lpWorkQueueTail)
2314 lpWorkQueueTail->prev = lpNewRequest;
2315 lpWorkQueueTail = lpNewRequest;
2316 if (!lpHeadWorkQueue)
2317 lpHeadWorkQueue = lpWorkQueueTail;
2319 LeaveCriticalSection(&csQueue);
2322 InterlockedIncrement(&dwNumJobs);
2329 /***********************************************************************
2330 * INTERNET_GetWorkRequest (internal)
2332 * Retrieves work request from queue
2337 BOOL INTERNET_GetWorkRequest(LPWORKREQUEST lpWorkRequest)
2339 BOOL bSuccess = FALSE;
2340 LPWORKREQUEST lpRequest = NULL;
2344 EnterCriticalSection(&csQueue);
2346 if (lpHeadWorkQueue)
2348 lpRequest = lpHeadWorkQueue;
2349 lpHeadWorkQueue = lpHeadWorkQueue->prev;
2350 if (lpRequest == lpWorkQueueTail)
2351 lpWorkQueueTail = lpHeadWorkQueue;
2354 LeaveCriticalSection(&csQueue);
2358 memcpy(lpWorkRequest, lpRequest, sizeof(WORKREQUEST));
2359 HeapFree(GetProcessHeap(), 0, lpRequest);
2361 InterlockedDecrement(&dwNumJobs);
2368 /***********************************************************************
2369 * INTERNET_AsyncCall (internal)
2371 * Retrieves work request from queue
2376 BOOL INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest)
2380 BOOL bSuccess = FALSE;
2384 if (InterlockedDecrement(&dwNumIdleThreads) < 0)
2386 InterlockedIncrement(&dwNumIdleThreads);
2388 if (InterlockedIncrement(&dwNumThreads) > MAX_WORKER_THREADS ||
2389 !(hThread = CreateThread(NULL, 0,
2390 (LPTHREAD_START_ROUTINE)INTERNET_WorkerThreadFunc, NULL, 0, &dwTID)))
2392 InterlockedDecrement(&dwNumThreads);
2393 INTERNET_SetLastError(ERROR_INTERNET_ASYNC_THREAD_FAILED);
2397 TRACE("Created new thread\n");
2401 INTERNET_InsertWorkRequest(lpWorkRequest);
2402 SetEvent(hWorkEvent);
2410 /***********************************************************************
2411 * INTERNET_ExecuteWork (internal)
2416 VOID INTERNET_ExecuteWork()
2418 WORKREQUEST workRequest;
2422 if (!INTERNET_GetWorkRequest(&workRequest))
2425 if (TRACE_ON(wininet)) {
2426 static const wininet_flag_info work_request_types[] = {
2427 #define FE(x) { x, #x }
2429 FE(FTPSETCURRENTDIRECTORYA),
2430 FE(FTPCREATEDIRECTORYA),
2431 FE(FTPFINDFIRSTFILEA),
2432 FE(FTPGETCURRENTDIRECTORYA),
2436 FE(FTPREMOVEDIRECTORYA),
2438 FE(INTERNETFINDNEXTA),
2439 FE(HTTPSENDREQUESTW),
2440 FE(HTTPOPENREQUESTW),
2442 FE(INTERNETOPENURLW)
2446 const char *val = "Unknown";
2448 for (i = 0; i < (sizeof(work_request_types) / sizeof(work_request_types[0])); i++) {
2449 if (work_request_types[i].val == workRequest.asyncall) {
2450 val = work_request_types[i].name;
2455 TRACE("Got work %d (%s)\n", workRequest.asyncall, val);
2457 switch (workRequest.asyncall)
2461 struct WORKREQ_FTPPUTFILEA *req = &workRequest.u.FtpPutFileA;
2463 FTP_FtpPutFileA(workRequest.handle, req->lpszLocalFile,
2464 req->lpszNewRemoteFile, req->dwFlags, req->dwContext);
2466 HeapFree(GetProcessHeap(), 0, req->lpszLocalFile);
2467 HeapFree(GetProcessHeap(), 0, req->lpszNewRemoteFile);
2471 case FTPSETCURRENTDIRECTORYA:
2473 struct WORKREQ_FTPSETCURRENTDIRECTORYA *req;
2475 req = &workRequest.u.FtpSetCurrentDirectoryA;
2476 FTP_FtpSetCurrentDirectoryA(workRequest.handle, req->lpszDirectory);
2477 HeapFree(GetProcessHeap(), 0, req->lpszDirectory);
2481 case FTPCREATEDIRECTORYA:
2483 struct WORKREQ_FTPCREATEDIRECTORYA *req;
2485 req = &workRequest.u.FtpCreateDirectoryA;
2486 FTP_FtpCreateDirectoryA(workRequest.handle, req->lpszDirectory);
2487 HeapFree(GetProcessHeap(), 0, req->lpszDirectory);
2491 case FTPFINDFIRSTFILEA:
2493 struct WORKREQ_FTPFINDFIRSTFILEA *req;
2495 req = &workRequest.u.FtpFindFirstFileA;
2496 FTP_FtpFindFirstFileA(workRequest.handle, req->lpszSearchFile,
2497 req->lpFindFileData, req->dwFlags, req->dwContext);
2498 HeapFree(GetProcessHeap(), 0, req->lpszSearchFile);
2502 case FTPGETCURRENTDIRECTORYA:
2504 struct WORKREQ_FTPGETCURRENTDIRECTORYA *req;
2506 req = &workRequest.u.FtpGetCurrentDirectoryA;
2507 FTP_FtpGetCurrentDirectoryA(workRequest.handle,
2508 req->lpszDirectory, req->lpdwDirectory);
2514 struct WORKREQ_FTPOPENFILEA *req = &workRequest.u.FtpOpenFileA;
2516 FTP_FtpOpenFileA(workRequest.handle, req->lpszFilename,
2517 req->dwAccess, req->dwFlags, req->dwContext);
2518 HeapFree(GetProcessHeap(), 0, req->lpszFilename);
2524 struct WORKREQ_FTPGETFILEA *req = &workRequest.u.FtpGetFileA;
2526 FTP_FtpGetFileA(workRequest.handle, req->lpszRemoteFile,
2527 req->lpszNewFile, req->fFailIfExists,
2528 req->dwLocalFlagsAttribute, req->dwFlags, req->dwContext);
2529 HeapFree(GetProcessHeap(), 0, req->lpszRemoteFile);
2530 HeapFree(GetProcessHeap(), 0, req->lpszNewFile);
2534 case FTPDELETEFILEA:
2536 struct WORKREQ_FTPDELETEFILEA *req = &workRequest.u.FtpDeleteFileA;
2538 FTP_FtpDeleteFileA(workRequest.handle, req->lpszFilename);
2539 HeapFree(GetProcessHeap(), 0, req->lpszFilename);
2543 case FTPREMOVEDIRECTORYA:
2545 struct WORKREQ_FTPREMOVEDIRECTORYA *req;
2547 req = &workRequest.u.FtpRemoveDirectoryA;
2548 FTP_FtpRemoveDirectoryA(workRequest.handle, req->lpszDirectory);
2549 HeapFree(GetProcessHeap(), 0, req->lpszDirectory);
2553 case FTPRENAMEFILEA:
2555 struct WORKREQ_FTPRENAMEFILEA *req = &workRequest.u.FtpRenameFileA;
2557 FTP_FtpRenameFileA(workRequest.handle, req->lpszSrcFile, req->lpszDestFile);
2558 HeapFree(GetProcessHeap(), 0, req->lpszSrcFile);
2559 HeapFree(GetProcessHeap(), 0, req->lpszDestFile);
2563 case INTERNETFINDNEXTA:
2565 struct WORKREQ_INTERNETFINDNEXTA *req;
2567 req = &workRequest.u.InternetFindNextA;
2568 INTERNET_FindNextFileA(workRequest.handle, req->lpFindFileData);
2572 case HTTPSENDREQUESTW:
2574 struct WORKREQ_HTTPSENDREQUESTW *req = &workRequest.u.HttpSendRequestW;
2576 HTTP_HttpSendRequestW(workRequest.handle, req->lpszHeader,
2577 req->dwHeaderLength, req->lpOptional, req->dwOptionalLength);
2579 HeapFree(GetProcessHeap(), 0, req->lpszHeader);
2583 case HTTPOPENREQUESTW:
2585 struct WORKREQ_HTTPOPENREQUESTW *req = &workRequest.u.HttpOpenRequestW;
2587 HTTP_HttpOpenRequestW(workRequest.handle, req->lpszVerb,
2588 req->lpszObjectName, req->lpszVersion, req->lpszReferrer,
2589 req->lpszAcceptTypes, req->dwFlags, req->dwContext);
2591 HeapFree(GetProcessHeap(), 0, req->lpszVerb);
2592 HeapFree(GetProcessHeap(), 0, req->lpszObjectName);
2593 HeapFree(GetProcessHeap(), 0, req->lpszVersion);
2594 HeapFree(GetProcessHeap(), 0, req->lpszReferrer);
2600 struct WORKREQ_SENDCALLBACK *req = &workRequest.u.SendCallback;
2602 SendAsyncCallbackInt(workRequest.handle, req->hHttpSession,
2603 req->dwContext, req->dwInternetStatus, req->lpvStatusInfo,
2604 req->dwStatusInfoLength);
2608 case INTERNETOPENURLW:
2610 struct WORKREQ_INTERNETOPENURLW *req = &workRequest.u.InternetOpenUrlW;
2612 INTERNET_InternetOpenUrlW(workRequest.handle, req->lpszUrl,
2613 req->lpszHeaders, req->dwHeadersLength, req->dwFlags, req->dwContext);
2614 HeapFree(GetProcessHeap(), 0, req->lpszUrl);
2615 HeapFree(GetProcessHeap(), 0, req->lpszHeaders);
2622 /***********************************************************************
2623 * INTERNET_GetResponseBuffer
2628 LPSTR INTERNET_GetResponseBuffer()
2630 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
2632 return lpwite->response;
2635 /***********************************************************************
2636 * INTERNET_GetNextLine (internal)
2638 * Parse next line in directory string listing
2641 * Pointer to beginning of next line
2646 LPSTR INTERNET_GetNextLine(INT nSocket, LPSTR lpszBuffer, LPDWORD dwBuffer)
2650 BOOL bSuccess = FALSE;
2656 FD_SET(nSocket, &infd);
2657 tv.tv_sec=RESPONSE_TIMEOUT;
2660 while (nRecv < *dwBuffer)
2662 if (select(nSocket+1,&infd,NULL,NULL,&tv) > 0)
2664 if (recv(nSocket, &lpszBuffer[nRecv], 1, 0) <= 0)
2666 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
2670 if (lpszBuffer[nRecv] == '\n')
2675 if (lpszBuffer[nRecv] != '\r')
2680 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT);
2688 lpszBuffer[nRecv] = '\0';
2689 *dwBuffer = nRecv - 1;
2690 TRACE(":%d %s\n", nRecv, lpszBuffer);
2699 /***********************************************************************
2702 BOOL WINAPI InternetQueryDataAvailable( HINTERNET hFile,
2703 LPDWORD lpdwNumberOfBytesAvailble,
2704 DWORD dwFlags, DWORD dwConext)
2706 LPWININETHTTPREQW lpwhr;
2711 lpwhr = (LPWININETHTTPREQW) WININET_GetObject( hFile );
2714 SetLastError(ERROR_NO_MORE_FILES);
2718 TRACE("--> %p %i\n",lpwhr,lpwhr->hdr.htype);
2720 switch (lpwhr->hdr.htype)
2723 if (!NETCON_recv(&lpwhr->netConnection, buffer,
2724 4048, MSG_PEEK, (int *)lpdwNumberOfBytesAvailble))
2726 SetLastError(ERROR_NO_MORE_FILES);
2734 FIXME("unsupported file type\n");
2738 TRACE("<-- %i\n",retval);
2743 /***********************************************************************
2746 BOOL WINAPI InternetLockRequestFile( HINTERNET hInternet, HANDLE
2753 BOOL WINAPI InternetUnlockRequestFile( HANDLE hLockHandle)
2760 /***********************************************************************
2763 * On windows this function is supposed to dial the default internet
2764 * connection. We don't want to have Wine dial out to the internet so
2765 * we return TRUE by default. It might be nice to check if we are connected.
2772 BOOL WINAPI InternetAutodial(DWORD dwFlags, HWND hwndParent)
2776 /* Tell that we are connected to the internet. */
2780 /***********************************************************************
2781 * InternetAutodialHangup
2783 * Hangs up an connection made with InternetAutodial
2792 BOOL WINAPI InternetAutodialHangup(DWORD dwReserved)
2796 /* we didn't dial, we don't disconnect */
2800 /***********************************************************************
2802 * InternetCombineUrlA
2804 * Combine a base URL with a relative URL
2812 BOOL WINAPI InternetCombineUrlA(LPCSTR lpszBaseUrl, LPCSTR lpszRelativeUrl,
2813 LPSTR lpszBuffer, LPDWORD lpdwBufferLength,
2818 TRACE("(%s, %s, %p, %p, 0x%08lx)\n", debugstr_a(lpszBaseUrl), debugstr_a(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
2820 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
2821 dwFlags ^= ICU_NO_ENCODE;
2822 hr=UrlCombineA(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
2827 /***********************************************************************
2829 * InternetCombineUrlW
2831 * Combine a base URL with a relative URL
2839 BOOL WINAPI InternetCombineUrlW(LPCWSTR lpszBaseUrl, LPCWSTR lpszRelativeUrl,
2840 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength,
2845 TRACE("(%s, %s, %p, %p, 0x%08lx)\n", debugstr_w(lpszBaseUrl), debugstr_w(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
2847 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
2848 dwFlags ^= ICU_NO_ENCODE;
2849 hr=UrlCombineW(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
2854 /***********************************************************************
2856 * InternetCreateUrlA
2863 BOOL WINAPI InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags,
2864 LPSTR lpszUrl, LPDWORD lpdwUrlLength)
2870 /***********************************************************************
2872 * InternetCreateUrlW
2879 BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags,
2880 LPWSTR lpszUrl, LPDWORD lpdwUrlLength)