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>
58 #include "wine/debug.h"
60 #define NO_SHLWAPI_STREAM
63 #include "wine/exception.h"
69 #include "wine/unicode.h"
71 WINE_DEFAULT_DEBUG_CHANNEL(wininet
);
73 #define MAX_IDLE_WORKER 1000*60*1
74 #define MAX_WORKER_THREADS 10
75 #define RESPONSE_TIMEOUT 30
77 #define GET_HWININET_FROM_LPWININETFINDNEXT(lpwh) \
78 (LPWININETAPPINFOW)(((LPWININETFTPSESSIONW)(lpwh->hdr.lpwhparent))->hdr.lpwhparent)
84 CHAR response
[MAX_REPLY_LEN
];
85 } WITHREADERROR
, *LPWITHREADERROR
;
87 static VOID
INTERNET_CloseHandle(LPWININETHANDLEHEADER hdr
);
88 BOOL WINAPI
INTERNET_FindNextFileW(LPWININETFINDNEXTW lpwh
, LPVOID lpvFindData
);
89 HINTERNET WINAPI
INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC
, LPCWSTR lpszUrl
,
90 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD dwContext
);
91 static VOID
INTERNET_ExecuteWork(void);
93 static DWORD g_dwTlsErrIndex
= TLS_OUT_OF_INDEXES
;
94 static DWORD dwNumThreads
;
95 static DWORD dwNumIdleThreads
;
96 static DWORD dwNumJobs
;
97 static HANDLE hEventArray
[2];
98 #define hQuitEvent hEventArray[0]
99 #define hWorkEvent hEventArray[1]
100 static CRITICAL_SECTION csQueue
;
101 static LPWORKREQUEST lpHeadWorkQueue
;
102 static LPWORKREQUEST lpWorkQueueTail
;
103 static HMODULE WININET_hModule
;
105 extern void URLCacheContainers_CreateDefaults(void);
106 extern void URLCacheContainers_DeleteAll(void);
108 #define HANDLE_CHUNK_SIZE 0x10
110 static CRITICAL_SECTION WININET_cs
;
111 static CRITICAL_SECTION_DEBUG WININET_cs_debug
=
114 { &WININET_cs_debug
.ProcessLocksList
, &WININET_cs_debug
.ProcessLocksList
},
115 0, 0, { 0, (DWORD
)(__FILE__
": WININET_cs") }
117 static CRITICAL_SECTION WININET_cs
= { &WININET_cs_debug
, -1, 0, 0, 0, 0 };
119 static LPWININETHANDLEHEADER
*WININET_Handles
;
120 static UINT WININET_dwNextHandle
;
121 static UINT WININET_dwMaxHandles
;
123 HINTERNET
WININET_AllocHandle( LPWININETHANDLEHEADER info
)
125 LPWININETHANDLEHEADER
*p
;
126 UINT handle
= 0, num
;
128 EnterCriticalSection( &WININET_cs
);
129 if( !WININET_dwMaxHandles
)
131 num
= HANDLE_CHUNK_SIZE
;
132 p
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
137 WININET_dwMaxHandles
= num
;
139 if( WININET_dwMaxHandles
== WININET_dwNextHandle
)
141 num
= WININET_dwMaxHandles
+ HANDLE_CHUNK_SIZE
;
142 p
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
143 WININET_Handles
, sizeof (UINT
)* num
);
147 WININET_dwMaxHandles
= num
;
150 handle
= WININET_dwNextHandle
;
151 if( WININET_Handles
[handle
] )
152 ERR("handle isn't free but should be\n");
153 WININET_Handles
[handle
] = WININET_AddRef( info
);
155 while( WININET_Handles
[WININET_dwNextHandle
] &&
156 (WININET_dwNextHandle
< WININET_dwMaxHandles
) )
157 WININET_dwNextHandle
++;
160 LeaveCriticalSection( &WININET_cs
);
162 return (HINTERNET
) (handle
+1);
165 HINTERNET
WININET_FindHandle( LPWININETHANDLEHEADER info
)
169 EnterCriticalSection( &WININET_cs
);
170 for( i
=0; i
<WININET_dwMaxHandles
; i
++ )
172 if( info
== WININET_Handles
[i
] )
174 WININET_AddRef( info
);
179 LeaveCriticalSection( &WININET_cs
);
181 return (HINTERNET
) handle
;
184 LPWININETHANDLEHEADER
WININET_AddRef( LPWININETHANDLEHEADER info
)
187 TRACE("%p -> refcount = %ld\n", info
, info
->dwRefCount
);
191 LPWININETHANDLEHEADER
WININET_GetObject( HINTERNET hinternet
)
193 LPWININETHANDLEHEADER info
= NULL
;
194 UINT handle
= (UINT
) hinternet
;
196 EnterCriticalSection( &WININET_cs
);
198 if( (handle
> 0) && ( handle
<= WININET_dwMaxHandles
) &&
199 WININET_Handles
[handle
-1] )
200 info
= WININET_AddRef( WININET_Handles
[handle
-1] );
202 LeaveCriticalSection( &WININET_cs
);
204 TRACE("handle %d -> %p\n", handle
, info
);
209 BOOL
WININET_Release( LPWININETHANDLEHEADER info
)
212 TRACE( "object %p refcount = %ld\n", info
, info
->dwRefCount
);
213 if( !info
->dwRefCount
)
215 TRACE( "destroying object %p\n", info
);
216 info
->destroy( info
);
221 BOOL
WININET_FreeHandle( HINTERNET hinternet
)
224 UINT handle
= (UINT
) hinternet
;
225 LPWININETHANDLEHEADER info
= NULL
;
227 EnterCriticalSection( &WININET_cs
);
229 if( (handle
> 0) && ( handle
<= WININET_dwMaxHandles
) )
232 if( WININET_Handles
[handle
] )
234 info
= WININET_Handles
[handle
];
235 TRACE( "destroying handle %d for object %p\n", handle
+1, info
);
236 WININET_Handles
[handle
] = NULL
;
238 if( WININET_dwNextHandle
> handle
)
239 WININET_dwNextHandle
= handle
;
243 LeaveCriticalSection( &WININET_cs
);
246 WININET_Release( info
);
251 /***********************************************************************
252 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
255 * hinstDLL [I] handle to the DLL's instance
257 * lpvReserved [I] reserved, must be NULL
264 BOOL WINAPI
DllMain (HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
266 TRACE("%p,%lx,%p\n", hinstDLL
, fdwReason
, lpvReserved
);
269 case DLL_PROCESS_ATTACH
:
271 g_dwTlsErrIndex
= TlsAlloc();
273 if (g_dwTlsErrIndex
== TLS_OUT_OF_INDEXES
)
276 hQuitEvent
= CreateEventW(0, TRUE
, FALSE
, NULL
);
277 hWorkEvent
= CreateEventW(0, FALSE
, FALSE
, NULL
);
278 InitializeCriticalSection(&csQueue
);
280 URLCacheContainers_CreateDefaults();
283 dwNumIdleThreads
= 0;
286 WININET_hModule
= (HMODULE
)hinstDLL
;
288 case DLL_THREAD_ATTACH
:
290 LPWITHREADERROR lpwite
= HeapAlloc(GetProcessHeap(), 0, sizeof(WITHREADERROR
));
294 TlsSetValue(g_dwTlsErrIndex
, (LPVOID
)lpwite
);
298 case DLL_THREAD_DETACH
:
299 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
301 LPVOID lpwite
= TlsGetValue(g_dwTlsErrIndex
);
302 HeapFree(GetProcessHeap(), 0, lpwite
);
306 case DLL_PROCESS_DETACH
:
308 URLCacheContainers_DeleteAll();
310 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
312 HeapFree(GetProcessHeap(), 0, TlsGetValue(g_dwTlsErrIndex
));
313 TlsFree(g_dwTlsErrIndex
);
316 SetEvent(hQuitEvent
);
318 CloseHandle(hQuitEvent
);
319 CloseHandle(hWorkEvent
);
320 DeleteCriticalSection(&csQueue
);
328 /***********************************************************************
329 * InternetInitializeAutoProxyDll (WININET.@)
331 * Setup the internal proxy
340 BOOL WINAPI
InternetInitializeAutoProxyDll(DWORD dwReserved
)
343 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
347 /***********************************************************************
348 * DetectAutoProxyUrl (WININET.@)
350 * Auto detect the proxy url
356 BOOL WINAPI
DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl
,
357 DWORD dwAutoProxyUrlLength
, DWORD dwDetectFlags
)
360 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
365 /***********************************************************************
366 * INTERNET_ConfigureProxyFromReg
369 * The proxy may be specified in the form 'http=proxy.my.org'
370 * Presumably that means there can be ftp=ftpproxy.my.org too.
372 static BOOL
INTERNET_ConfigureProxyFromReg( LPWININETAPPINFOW lpwai
)
375 DWORD r
, keytype
, len
, enabled
;
376 LPSTR lpszInternetSettings
=
377 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
378 static const WCHAR szProxyServer
[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
380 r
= RegOpenKeyA(HKEY_CURRENT_USER
, lpszInternetSettings
, &key
);
381 if ( r
!= ERROR_SUCCESS
)
384 len
= sizeof enabled
;
385 r
= RegQueryValueExA( key
, "ProxyEnable", NULL
, &keytype
,
386 (BYTE
*)&enabled
, &len
);
387 if( (r
== ERROR_SUCCESS
) && enabled
)
389 TRACE("Proxy is enabled.\n");
391 /* figure out how much memory the proxy setting takes */
392 r
= RegQueryValueExW( key
, szProxyServer
, NULL
, &keytype
,
394 if( (r
== ERROR_SUCCESS
) && len
&& (keytype
== REG_SZ
) )
397 static const WCHAR szHttp
[] = {'h','t','t','p','=',0};
399 szProxy
=HeapAlloc( GetProcessHeap(), 0, len
);
400 RegQueryValueExW( key
, szProxyServer
, NULL
, &keytype
,
401 (BYTE
*)szProxy
, &len
);
403 /* find the http proxy, and strip away everything else */
404 p
= strstrW( szProxy
, szHttp
);
407 p
+= lstrlenW(szHttp
);
408 lstrcpyW( szProxy
, p
);
410 p
= strchrW( szProxy
, ' ' );
414 lpwai
->dwAccessType
= INTERNET_OPEN_TYPE_PROXY
;
415 lpwai
->lpszProxy
= szProxy
;
417 TRACE("http proxy = %s\n", debugstr_w(lpwai
->lpszProxy
));
420 ERR("Couldn't read proxy server settings.\n");
423 TRACE("Proxy is not enabled.\n");
429 /***********************************************************************
430 * InternetOpenW (WININET.@)
432 * Per-application initialization of wininet
435 * HINTERNET on success
439 HINTERNET WINAPI
InternetOpenW(LPCWSTR lpszAgent
, DWORD dwAccessType
,
440 LPCWSTR lpszProxy
, LPCWSTR lpszProxyBypass
, DWORD dwFlags
)
442 LPWININETAPPINFOW lpwai
= NULL
;
443 HINTERNET handle
= NULL
;
445 if (TRACE_ON(wininet
)) {
446 #define FE(x) { x, #x }
447 static const wininet_flag_info access_type
[] = {
448 FE(INTERNET_OPEN_TYPE_PRECONFIG
),
449 FE(INTERNET_OPEN_TYPE_DIRECT
),
450 FE(INTERNET_OPEN_TYPE_PROXY
),
451 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY
)
455 const char *access_type_str
= "Unknown";
457 TRACE("(%s, %li, %s, %s, %li)\n", debugstr_w(lpszAgent
), dwAccessType
,
458 debugstr_w(lpszProxy
), debugstr_w(lpszProxyBypass
), dwFlags
);
459 for (i
= 0; i
< (sizeof(access_type
) / sizeof(access_type
[0])); i
++) {
460 if (access_type
[i
].val
== dwAccessType
) {
461 access_type_str
= access_type
[i
].name
;
465 TRACE(" access type : %s\n", access_type_str
);
467 dump_INTERNET_FLAGS(dwFlags
);
470 /* Clear any error information */
471 INTERNET_SetLastError(0);
473 lpwai
= HeapAlloc(GetProcessHeap(), 0, sizeof(WININETAPPINFOW
));
476 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
480 memset(lpwai
, 0, sizeof(WININETAPPINFOW
));
481 lpwai
->hdr
.htype
= WH_HINIT
;
482 lpwai
->hdr
.lpwhparent
= NULL
;
483 lpwai
->hdr
.dwFlags
= dwFlags
;
484 lpwai
->hdr
.dwRefCount
= 1;
485 lpwai
->hdr
.destroy
= INTERNET_CloseHandle
;
486 lpwai
->dwAccessType
= dwAccessType
;
487 lpwai
->lpszProxyUsername
= NULL
;
488 lpwai
->lpszProxyPassword
= NULL
;
490 handle
= WININET_AllocHandle( &lpwai
->hdr
);
493 HeapFree( GetProcessHeap(), 0, lpwai
);
494 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
498 if (NULL
!= lpszAgent
)
500 lpwai
->lpszAgent
= HeapAlloc( GetProcessHeap(),0,
501 (strlenW(lpszAgent
)+1)*sizeof(WCHAR
));
502 if (lpwai
->lpszAgent
)
503 lstrcpyW( lpwai
->lpszAgent
, lpszAgent
);
505 if(dwAccessType
== INTERNET_OPEN_TYPE_PRECONFIG
)
506 INTERNET_ConfigureProxyFromReg( lpwai
);
507 else if (NULL
!= lpszProxy
)
509 lpwai
->lpszProxy
= HeapAlloc( GetProcessHeap(), 0,
510 (strlenW(lpszProxy
)+1)*sizeof(WCHAR
));
511 if (lpwai
->lpszProxy
)
512 lstrcpyW( lpwai
->lpszProxy
, lpszProxy
);
515 if (NULL
!= lpszProxyBypass
)
517 lpwai
->lpszProxyBypass
= HeapAlloc( GetProcessHeap(), 0,
518 (strlenW(lpszProxyBypass
)+1)*sizeof(WCHAR
));
519 if (lpwai
->lpszProxyBypass
)
520 lstrcpyW( lpwai
->lpszProxyBypass
, lpszProxyBypass
);
525 WININET_Release( &lpwai
->hdr
);
527 TRACE("returning %p\n", lpwai
);
533 /***********************************************************************
534 * InternetOpenA (WININET.@)
536 * Per-application initialization of wininet
539 * HINTERNET on success
543 HINTERNET WINAPI
InternetOpenA(LPCSTR lpszAgent
, DWORD dwAccessType
,
544 LPCSTR lpszProxy
, LPCSTR lpszProxyBypass
, DWORD dwFlags
)
546 HINTERNET rc
= (HINTERNET
)NULL
;
548 WCHAR
*szAgent
= NULL
, *szProxy
= NULL
, *szBypass
= NULL
;
550 TRACE("(%s, 0x%08lx, %s, %s, 0x%08lx)\n", debugstr_a(lpszAgent
),
551 dwAccessType
, debugstr_a(lpszProxy
), debugstr_a(lpszProxyBypass
), dwFlags
);
555 len
= MultiByteToWideChar(CP_ACP
, 0, lpszAgent
, -1, NULL
, 0);
556 szAgent
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
557 MultiByteToWideChar(CP_ACP
, 0, lpszAgent
, -1, szAgent
, len
);
562 len
= MultiByteToWideChar(CP_ACP
, 0, lpszProxy
, -1, NULL
, 0);
563 szProxy
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
564 MultiByteToWideChar(CP_ACP
, 0, lpszProxy
, -1, szProxy
, len
);
567 if( lpszProxyBypass
)
569 len
= MultiByteToWideChar(CP_ACP
, 0, lpszProxyBypass
, -1, NULL
, 0);
570 szBypass
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
571 MultiByteToWideChar(CP_ACP
, 0, lpszProxyBypass
, -1, szBypass
, len
);
574 rc
= InternetOpenW(szAgent
, dwAccessType
, szProxy
, szBypass
, dwFlags
);
576 HeapFree(GetProcessHeap(), 0, szAgent
);
577 HeapFree(GetProcessHeap(), 0, szProxy
);
578 HeapFree(GetProcessHeap(), 0, szBypass
);
583 /***********************************************************************
584 * InternetGetLastResponseInfoA (WININET.@)
586 * Return last wininet error description on the calling thread
589 * TRUE on success of writing to buffer
593 BOOL WINAPI
InternetGetLastResponseInfoA(LPDWORD lpdwError
,
594 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
596 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
600 *lpdwError
= lpwite
->dwError
;
603 strncpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
604 *lpdwBufferLength
= strlen(lpszBuffer
);
607 *lpdwBufferLength
= 0;
613 /***********************************************************************
614 * InternetGetConnectedState (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
InternetGetConnectedState(LPDWORD lpdwStatus
, DWORD dwReserved
)
626 TRACE("(%p, 0x%08lx)\n", lpdwStatus
, dwReserved
);
629 FIXME("always returning LAN connection.\n");
630 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
636 /***********************************************************************
637 * InternetGetConnectedStateExW (WININET.@)
639 * Return connected state
643 * lpdwStatus [O] Flags specifying the status of the internet connection.
644 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
645 * dwNameLen [I] Size of the buffer, in characters.
646 * dwReserved [I] Reserved. Must be set to 0.
650 * if lpdwStatus is not null, return the status (off line,
651 * modem, lan...) in it.
652 * FALSE if not connected
655 * If the system has no available network connections, an empty string is
656 * stored in lpszConnectionName. If there is a LAN connection, a localized
657 * "LAN Connection" string is stored. Presumably, if only a dial-up
658 * connection is available then the name of the dial-up connection is
659 * returned. Why any application, other than the "Internet Settings" CPL,
660 * would want to use this function instead of the simpler InternetGetConnectedStateW
661 * function is beyond me.
663 BOOL WINAPI
InternetGetConnectedStateExW(LPDWORD lpdwStatus
, LPWSTR lpszConnectionName
,
664 DWORD dwNameLen
, DWORD dwReserved
)
666 TRACE("(%p, %p, %ld, 0x%08lx)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
673 FIXME("always returning LAN connection.\n");
674 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
676 return LoadStringW(WININET_hModule
, IDS_LANCONNECTION
, lpszConnectionName
, dwNameLen
);
680 /***********************************************************************
681 * InternetGetConnectedStateExA (WININET.@)
683 BOOL WINAPI
InternetGetConnectedStateExA(LPDWORD lpdwStatus
, LPSTR lpszConnectionName
,
684 DWORD dwNameLen
, DWORD dwReserved
)
686 LPWSTR lpwszConnectionName
= NULL
;
689 TRACE("(%p, %p, %ld, 0x%08lx)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
691 if (lpszConnectionName
&& dwNameLen
> 0)
692 lpwszConnectionName
= HeapAlloc(GetProcessHeap(), 0, dwNameLen
* sizeof(WCHAR
));
694 rc
= InternetGetConnectedStateExW(lpdwStatus
,lpwszConnectionName
, dwNameLen
,
696 if (rc
&& lpwszConnectionName
)
698 WideCharToMultiByte(CP_ACP
,0,lpwszConnectionName
,-1,lpszConnectionName
,
699 dwNameLen
, NULL
, NULL
);
701 HeapFree(GetProcessHeap(),0,lpwszConnectionName
);
708 /***********************************************************************
709 * InternetConnectW (WININET.@)
711 * Open a ftp, gopher or http session
714 * HINTERNET a session handle on success
718 HINTERNET WINAPI
InternetConnectW(HINTERNET hInternet
,
719 LPCWSTR lpszServerName
, INTERNET_PORT nServerPort
,
720 LPCWSTR lpszUserName
, LPCWSTR lpszPassword
,
721 DWORD dwService
, DWORD dwFlags
, DWORD dwContext
)
723 LPWININETAPPINFOW hIC
;
724 HINTERNET rc
= (HINTERNET
) NULL
;
726 TRACE("(%p, %s, %i, %s, %s, %li, %li, %li)\n", hInternet
, debugstr_w(lpszServerName
),
727 nServerPort
, debugstr_w(lpszUserName
), debugstr_w(lpszPassword
),
728 dwService
, dwFlags
, dwContext
);
730 /* Clear any error information */
731 INTERNET_SetLastError(0);
732 hIC
= (LPWININETAPPINFOW
) WININET_GetObject( hInternet
);
733 if ( (hIC
== NULL
) || (hIC
->hdr
.htype
!= WH_HINIT
) )
738 case INTERNET_SERVICE_FTP
:
739 rc
= FTP_Connect(hIC
, lpszServerName
, nServerPort
,
740 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
743 case INTERNET_SERVICE_HTTP
:
744 rc
= HTTP_Connect(hIC
, lpszServerName
, nServerPort
,
745 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
748 case INTERNET_SERVICE_GOPHER
:
754 WININET_Release( &hIC
->hdr
);
756 TRACE("returning %p\n", rc
);
761 /***********************************************************************
762 * InternetConnectA (WININET.@)
764 * Open a ftp, gopher or http session
767 * HINTERNET a session handle on success
771 HINTERNET WINAPI
InternetConnectA(HINTERNET hInternet
,
772 LPCSTR lpszServerName
, INTERNET_PORT nServerPort
,
773 LPCSTR lpszUserName
, LPCSTR lpszPassword
,
774 DWORD dwService
, DWORD dwFlags
, DWORD dwContext
)
776 HINTERNET rc
= (HINTERNET
)NULL
;
778 LPWSTR szServerName
= NULL
;
779 LPWSTR szUserName
= NULL
;
780 LPWSTR szPassword
= NULL
;
784 len
= MultiByteToWideChar(CP_ACP
, 0, lpszServerName
, -1, NULL
, 0);
785 szServerName
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
786 MultiByteToWideChar(CP_ACP
, 0, lpszServerName
, -1, szServerName
, len
);
790 len
= MultiByteToWideChar(CP_ACP
, 0, lpszUserName
, -1, NULL
, 0);
791 szUserName
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
792 MultiByteToWideChar(CP_ACP
, 0, lpszUserName
, -1, szUserName
, len
);
796 len
= MultiByteToWideChar(CP_ACP
, 0, lpszPassword
, -1, NULL
, 0);
797 szPassword
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
798 MultiByteToWideChar(CP_ACP
, 0, lpszPassword
, -1, szPassword
, len
);
802 rc
= InternetConnectW(hInternet
, szServerName
, nServerPort
,
803 szUserName
, szPassword
, dwService
, dwFlags
, dwContext
);
805 HeapFree(GetProcessHeap(), 0, szServerName
);
806 HeapFree(GetProcessHeap(), 0, szUserName
);
807 HeapFree(GetProcessHeap(), 0, szPassword
);
812 /***********************************************************************
813 * InternetFindNextFileA (WININET.@)
815 * Continues a file search from a previous call to FindFirstFile
822 BOOL WINAPI
InternetFindNextFileA(HINTERNET hFind
, LPVOID lpvFindData
)
827 ret
= InternetFindNextFileW(hFind
, lpvFindData
?&fd
:NULL
);
829 WININET_find_data_WtoA(&fd
, (LPWIN32_FIND_DATAA
)lpvFindData
);
833 /***********************************************************************
834 * InternetFindNextFileW (WININET.@)
836 * Continues a file search from a previous call to FindFirstFile
843 BOOL WINAPI
InternetFindNextFileW(HINTERNET hFind
, LPVOID lpvFindData
)
845 LPWININETAPPINFOW hIC
= NULL
;
846 LPWININETFINDNEXTW lpwh
;
847 BOOL bSuccess
= FALSE
;
851 lpwh
= (LPWININETFINDNEXTW
) WININET_GetObject( hFind
);
852 if (NULL
== lpwh
|| lpwh
->hdr
.htype
!= WH_HFINDNEXT
)
854 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
858 hIC
= GET_HWININET_FROM_LPWININETFINDNEXT(lpwh
);
859 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
)
861 WORKREQUEST workRequest
;
862 struct WORKREQ_INTERNETFINDNEXTW
*req
;
864 workRequest
.asyncall
= INTERNETFINDNEXTW
;
865 workRequest
.hdr
= WININET_AddRef( &lpwh
->hdr
);
866 req
= &workRequest
.u
.InternetFindNextW
;
867 req
->lpFindFileData
= lpvFindData
;
869 bSuccess
= INTERNET_AsyncCall(&workRequest
);
873 bSuccess
= INTERNET_FindNextFileW(lpwh
, lpvFindData
);
877 WININET_Release( &lpwh
->hdr
);
881 /***********************************************************************
882 * INTERNET_FindNextFileW (Internal)
884 * Continues a file search from a previous call to FindFirstFile
891 BOOL WINAPI
INTERNET_FindNextFileW(LPWININETFINDNEXTW lpwh
, LPVOID lpvFindData
)
893 BOOL bSuccess
= TRUE
;
894 LPWIN32_FIND_DATAW lpFindFileData
;
898 assert (lpwh
->hdr
.htype
== WH_HFINDNEXT
);
900 /* Clear any error information */
901 INTERNET_SetLastError(0);
903 if (lpwh
->hdr
.lpwhparent
->htype
!= WH_HFTPSESSION
)
905 FIXME("Only FTP find next supported\n");
906 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
910 TRACE("index(%ld) size(%ld)\n", lpwh
->index
, lpwh
->size
);
912 lpFindFileData
= (LPWIN32_FIND_DATAW
) lpvFindData
;
913 ZeroMemory(lpFindFileData
, sizeof(WIN32_FIND_DATAA
));
915 if (lpwh
->index
>= lpwh
->size
)
917 INTERNET_SetLastError(ERROR_NO_MORE_FILES
);
922 FTP_ConvertFileProp(&lpwh
->lpafp
[lpwh
->index
], lpFindFileData
);
925 TRACE("\nName: %s\nSize: %ld\n", debugstr_w(lpFindFileData
->cFileName
), lpFindFileData
->nFileSizeLow
);
929 if (lpwh
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
&& lpwh
->hdr
.lpfnStatusCB
)
931 INTERNET_ASYNC_RESULT iar
;
933 iar
.dwResult
= (DWORD
)bSuccess
;
934 iar
.dwError
= iar
.dwError
= bSuccess
? ERROR_SUCCESS
:
935 INTERNET_GetLastError();
937 SendAsyncCallback(&lpwh
->hdr
, lpwh
->hdr
.dwContext
,
938 INTERNET_STATUS_REQUEST_COMPLETE
, &iar
,
939 sizeof(INTERNET_ASYNC_RESULT
));
946 /***********************************************************************
947 * INTERNET_CloseHandle (internal)
949 * Close internet handle
955 static VOID
INTERNET_CloseHandle(LPWININETHANDLEHEADER hdr
)
957 LPWININETAPPINFOW lpwai
= (LPWININETAPPINFOW
) hdr
;
961 HeapFree(GetProcessHeap(), 0, lpwai
->lpszAgent
);
962 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxy
);
963 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxyBypass
);
964 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxyUsername
);
965 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxyPassword
);
966 HeapFree(GetProcessHeap(), 0, lpwai
);
970 /***********************************************************************
971 * InternetCloseHandle (WININET.@)
973 * Generic close handle function
980 BOOL WINAPI
InternetCloseHandle(HINTERNET hInternet
)
982 LPWININETHANDLEHEADER lpwh
;
984 TRACE("%p\n",hInternet
);
986 lpwh
= WININET_GetObject( hInternet
);
989 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
993 SendAsyncCallback(lpwh
, lpwh
->dwContext
,
994 INTERNET_STATUS_HANDLE_CLOSING
, &hInternet
,
997 if( lpwh
->lpwhparent
)
998 WININET_Release( lpwh
->lpwhparent
);
999 WININET_FreeHandle( hInternet
);
1000 WININET_Release( lpwh
);
1006 /***********************************************************************
1007 * ConvertUrlComponentValue (Internal)
1009 * Helper function for InternetCrackUrlW
1012 static void ConvertUrlComponentValue(LPSTR
* lppszComponent
, LPDWORD dwComponentLen
,
1013 LPWSTR lpwszComponent
, DWORD dwwComponentLen
,
1014 LPCSTR lpszStart
, LPCWSTR lpwszStart
)
1016 if (*dwComponentLen
!= 0)
1018 DWORD nASCIILength
=WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,NULL
,0,NULL
,NULL
);
1019 if (*lppszComponent
== NULL
)
1021 int nASCIIOffset
=WideCharToMultiByte(CP_ACP
,0,lpwszStart
,lpwszComponent
-lpwszStart
,NULL
,0,NULL
,NULL
);
1022 *lppszComponent
= (LPSTR
)lpszStart
+nASCIIOffset
;
1023 *dwComponentLen
= nASCIILength
;
1027 DWORD ncpylen
= min((*dwComponentLen
)-1, nASCIILength
);
1028 WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,*lppszComponent
,ncpylen
+1,NULL
,NULL
);
1029 (*lppszComponent
)[ncpylen
]=0;
1030 *dwComponentLen
= ncpylen
;
1036 /***********************************************************************
1037 * InternetCrackUrlA (WININET.@)
1039 * Break up URL into its components
1041 * TODO: Handle dwFlags
1048 BOOL WINAPI
InternetCrackUrlA(LPCSTR lpszUrl
, DWORD dwUrlLength
, DWORD dwFlags
,
1049 LPURL_COMPONENTSA lpUrlComponents
)
1052 URL_COMPONENTSW UCW
;
1057 nLength
=MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,NULL
,0);
1058 lpwszUrl
=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WCHAR
)*nLength
);
1059 MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,lpwszUrl
,nLength
);
1061 memset(&UCW
,0,sizeof(UCW
));
1062 if(lpUrlComponents
->dwHostNameLength
!=0)
1063 UCW
.dwHostNameLength
=1;
1064 if(lpUrlComponents
->dwUserNameLength
!=0)
1065 UCW
.dwUserNameLength
=1;
1066 if(lpUrlComponents
->dwPasswordLength
!=0)
1067 UCW
.dwPasswordLength
=1;
1068 if(lpUrlComponents
->dwUrlPathLength
!=0)
1069 UCW
.dwUrlPathLength
=1;
1070 if(lpUrlComponents
->dwSchemeLength
!=0)
1071 UCW
.dwSchemeLength
=1;
1072 if(lpUrlComponents
->dwExtraInfoLength
!=0)
1073 UCW
.dwExtraInfoLength
=1;
1074 if(!InternetCrackUrlW(lpwszUrl
,nLength
,dwFlags
,&UCW
))
1076 HeapFree(GetProcessHeap(), 0, lpwszUrl
);
1080 ConvertUrlComponentValue(&lpUrlComponents
->lpszHostName
, &lpUrlComponents
->dwHostNameLength
,
1081 UCW
.lpszHostName
, UCW
.dwHostNameLength
,
1083 ConvertUrlComponentValue(&lpUrlComponents
->lpszUserName
, &lpUrlComponents
->dwUserNameLength
,
1084 UCW
.lpszUserName
, UCW
.dwUserNameLength
,
1086 ConvertUrlComponentValue(&lpUrlComponents
->lpszPassword
, &lpUrlComponents
->dwPasswordLength
,
1087 UCW
.lpszPassword
, UCW
.dwPasswordLength
,
1089 ConvertUrlComponentValue(&lpUrlComponents
->lpszUrlPath
, &lpUrlComponents
->dwUrlPathLength
,
1090 UCW
.lpszUrlPath
, UCW
.dwUrlPathLength
,
1092 ConvertUrlComponentValue(&lpUrlComponents
->lpszScheme
, &lpUrlComponents
->dwSchemeLength
,
1093 UCW
.lpszScheme
, UCW
.dwSchemeLength
,
1095 ConvertUrlComponentValue(&lpUrlComponents
->lpszExtraInfo
, &lpUrlComponents
->dwExtraInfoLength
,
1096 UCW
.lpszExtraInfo
, UCW
.dwExtraInfoLength
,
1098 lpUrlComponents
->nScheme
=UCW
.nScheme
;
1099 lpUrlComponents
->nPort
=UCW
.nPort
;
1100 HeapFree(GetProcessHeap(), 0, lpwszUrl
);
1102 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", lpszUrl
,
1103 debugstr_an(lpUrlComponents
->lpszScheme
,lpUrlComponents
->dwSchemeLength
),
1104 debugstr_an(lpUrlComponents
->lpszHostName
,lpUrlComponents
->dwHostNameLength
),
1105 debugstr_an(lpUrlComponents
->lpszUrlPath
,lpUrlComponents
->dwUrlPathLength
),
1106 debugstr_an(lpUrlComponents
->lpszExtraInfo
,lpUrlComponents
->dwExtraInfoLength
));
1111 /***********************************************************************
1112 * GetInternetSchemeW (internal)
1118 * INTERNET_SCHEME_UNKNOWN on failure
1121 static INTERNET_SCHEME
GetInternetSchemeW(LPCWSTR lpszScheme
, DWORD nMaxCmp
)
1123 INTERNET_SCHEME iScheme
=INTERNET_SCHEME_UNKNOWN
;
1124 static const WCHAR lpszFtp
[]={'f','t','p',0};
1125 static const WCHAR lpszGopher
[]={'g','o','p','h','e','r',0};
1126 static const WCHAR lpszHttp
[]={'h','t','t','p',0};
1127 static const WCHAR lpszHttps
[]={'h','t','t','p','s',0};
1128 static const WCHAR lpszFile
[]={'f','i','l','e',0};
1129 static const WCHAR lpszNews
[]={'n','e','w','s',0};
1130 static const WCHAR lpszMailto
[]={'m','a','i','l','t','o',0};
1131 static const WCHAR lpszRes
[]={'r','e','s',0};
1132 WCHAR
* tempBuffer
=NULL
;
1134 if(lpszScheme
==NULL
)
1135 return INTERNET_SCHEME_UNKNOWN
;
1137 tempBuffer
=HeapAlloc(GetProcessHeap(),0,(nMaxCmp
+1)*sizeof(WCHAR
));
1138 strncpyW(tempBuffer
,lpszScheme
,nMaxCmp
);
1139 tempBuffer
[nMaxCmp
]=0;
1140 strlwrW(tempBuffer
);
1141 if (nMaxCmp
==strlenW(lpszFtp
) && !strncmpW(lpszFtp
, tempBuffer
, nMaxCmp
))
1142 iScheme
=INTERNET_SCHEME_FTP
;
1143 else if (nMaxCmp
==strlenW(lpszGopher
) && !strncmpW(lpszGopher
, tempBuffer
, nMaxCmp
))
1144 iScheme
=INTERNET_SCHEME_GOPHER
;
1145 else if (nMaxCmp
==strlenW(lpszHttp
) && !strncmpW(lpszHttp
, tempBuffer
, nMaxCmp
))
1146 iScheme
=INTERNET_SCHEME_HTTP
;
1147 else if (nMaxCmp
==strlenW(lpszHttps
) && !strncmpW(lpszHttps
, tempBuffer
, nMaxCmp
))
1148 iScheme
=INTERNET_SCHEME_HTTPS
;
1149 else if (nMaxCmp
==strlenW(lpszFile
) && !strncmpW(lpszFile
, tempBuffer
, nMaxCmp
))
1150 iScheme
=INTERNET_SCHEME_FILE
;
1151 else if (nMaxCmp
==strlenW(lpszNews
) && !strncmpW(lpszNews
, tempBuffer
, nMaxCmp
))
1152 iScheme
=INTERNET_SCHEME_NEWS
;
1153 else if (nMaxCmp
==strlenW(lpszMailto
) && !strncmpW(lpszMailto
, tempBuffer
, nMaxCmp
))
1154 iScheme
=INTERNET_SCHEME_MAILTO
;
1155 else if (nMaxCmp
==strlenW(lpszRes
) && !strncmpW(lpszRes
, tempBuffer
, nMaxCmp
))
1156 iScheme
=INTERNET_SCHEME_RES
;
1157 HeapFree(GetProcessHeap(),0,tempBuffer
);
1161 /***********************************************************************
1162 * SetUrlComponentValueW (Internal)
1164 * Helper function for InternetCrackUrlW
1171 static BOOL
SetUrlComponentValueW(LPWSTR
* lppszComponent
, LPDWORD dwComponentLen
, LPCWSTR lpszStart
, DWORD len
)
1173 TRACE("%s (%ld)\n", debugstr_wn(lpszStart
,len
), len
);
1175 if ( (*dwComponentLen
== 0) && (*lppszComponent
== NULL
) )
1178 if (*dwComponentLen
!= 0 || *lppszComponent
== NULL
)
1180 if (*lppszComponent
== NULL
)
1182 *lppszComponent
= (LPWSTR
)lpszStart
;
1183 *dwComponentLen
= len
;
1187 DWORD ncpylen
= min((*dwComponentLen
)-1, len
);
1188 strncpyW(*lppszComponent
, lpszStart
, ncpylen
);
1189 (*lppszComponent
)[ncpylen
] = '\0';
1190 *dwComponentLen
= ncpylen
;
1197 /***********************************************************************
1198 * InternetCrackUrlW (WININET.@)
1200 BOOL WINAPI
InternetCrackUrlW(LPCWSTR lpszUrl
, DWORD dwUrlLength
, DWORD dwFlags
,
1201 LPURL_COMPONENTSW lpUC
)
1205 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1208 LPCWSTR lpszParam
= NULL
;
1209 BOOL bIsAbsolute
= FALSE
;
1210 LPCWSTR lpszap
= lpszUrl
;
1211 LPCWSTR lpszcp
= NULL
;
1212 const WCHAR lpszSeparators
[3]={';','?',0};
1213 const WCHAR lpszSlash
[2]={'/',0};
1215 dwUrlLength
=strlenW(lpszUrl
);
1217 TRACE("(%s %lu %lx %p)\n", debugstr_w(lpszUrl
), dwUrlLength
, dwFlags
, lpUC
);
1219 /* Determine if the URI is absolute. */
1220 while (*lpszap
!= '\0')
1222 if (isalnumW(*lpszap
))
1227 if ((*lpszap
== ':') && (lpszap
- lpszUrl
>= 2))
1234 lpszcp
= lpszUrl
; /* Relative url */
1240 /* Parse <params> */
1241 lpszParam
= strpbrkW(lpszap
, lpszSeparators
);
1242 if (lpszParam
!= NULL
)
1244 SetUrlComponentValueW(&lpUC
->lpszExtraInfo
, &lpUC
->dwExtraInfoLength
,
1245 lpszParam
, dwUrlLength
-(lpszParam
-lpszUrl
));
1248 if (bIsAbsolute
) /* Parse <protocol>:[//<net_loc>] */
1251 static const WCHAR wszAbout
[]={'a','b','o','u','t',':',0};
1253 /* Get scheme first. */
1254 lpUC
->nScheme
= GetInternetSchemeW(lpszUrl
, lpszcp
- lpszUrl
);
1255 SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
,
1256 lpszUrl
, lpszcp
- lpszUrl
);
1258 /* Eat ':' in protocol. */
1261 /* if the scheme is "about", there is no host */
1262 if(strncmpW(wszAbout
,lpszUrl
, lpszcp
- lpszUrl
)==0)
1264 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1265 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1266 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1271 /* Skip over slashes. */
1283 lpszNetLoc
= strpbrkW(lpszcp
, lpszSlash
);
1287 lpszNetLoc
= min(lpszNetLoc
, lpszParam
);
1289 lpszNetLoc
= lpszParam
;
1291 else if (!lpszNetLoc
)
1292 lpszNetLoc
= lpszcp
+ dwUrlLength
-(lpszcp
-lpszUrl
);
1300 /* [<user>[<:password>]@]<host>[:<port>] */
1301 /* First find the user and password if they exist */
1303 lpszHost
= strchrW(lpszcp
, '@');
1304 if (lpszHost
== NULL
|| lpszHost
> lpszNetLoc
)
1306 /* username and password not specified. */
1307 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1308 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1310 else /* Parse out username and password */
1312 LPCWSTR lpszUser
= lpszcp
;
1313 LPCWSTR lpszPasswd
= lpszHost
;
1315 while (lpszcp
< lpszHost
)
1318 lpszPasswd
= lpszcp
;
1323 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
,
1324 lpszUser
, lpszPasswd
- lpszUser
);
1326 if (lpszPasswd
!= lpszHost
)
1328 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
,
1329 lpszPasswd
== lpszHost
? NULL
: lpszPasswd
,
1330 lpszHost
- lpszPasswd
);
1332 lpszcp
++; /* Advance to beginning of host */
1335 /* Parse <host><:port> */
1338 lpszPort
= lpszNetLoc
;
1340 /* special case for res:// URLs: there is no port here, so the host is the
1341 entire string up to the first '/' */
1342 if(lpUC
->nScheme
==INTERNET_SCHEME_RES
)
1344 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1345 lpszHost
, lpszPort
- lpszHost
);
1351 while (lpszcp
< lpszNetLoc
)
1359 /* If the scheme is "file" and the host is just one letter, it's not a host */
1360 if(lpUC
->nScheme
==INTERNET_SCHEME_FILE
&& (lpszPort
-lpszHost
)==1)
1363 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1369 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1370 lpszHost
, lpszPort
- lpszHost
);
1371 if (lpszPort
!= lpszNetLoc
)
1372 lpUC
->nPort
= atoiW(++lpszPort
);
1381 /* Here lpszcp points to:
1383 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1384 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1386 if (lpszcp
!= 0 && *lpszcp
!= '\0' && (!lpszParam
|| lpszcp
< lpszParam
))
1390 /* Only truncate the parameter list if it's already been saved
1391 * in lpUC->lpszExtraInfo.
1393 if (lpszParam
&& lpUC
->dwExtraInfoLength
&& lpUC
->lpszExtraInfo
)
1394 len
= lpszParam
- lpszcp
;
1397 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1398 * newlines if necessary.
1400 LPWSTR lpsznewline
= strchrW(lpszcp
, '\n');
1401 if (lpsznewline
!= NULL
)
1402 len
= lpsznewline
- lpszcp
;
1404 len
= dwUrlLength
-(lpszcp
-lpszUrl
);
1407 SetUrlComponentValueW(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
,
1412 lpUC
->dwUrlPathLength
= 0;
1415 TRACE("%s: host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl
,dwUrlLength
),
1416 debugstr_wn(lpUC
->lpszHostName
,lpUC
->dwHostNameLength
),
1417 debugstr_wn(lpUC
->lpszUrlPath
,lpUC
->dwUrlPathLength
),
1418 debugstr_wn(lpUC
->lpszExtraInfo
,lpUC
->dwExtraInfoLength
));
1423 /***********************************************************************
1424 * InternetAttemptConnect (WININET.@)
1426 * Attempt to make a connection to the internet
1429 * ERROR_SUCCESS on success
1430 * Error value on failure
1433 DWORD WINAPI
InternetAttemptConnect(DWORD dwReserved
)
1436 return ERROR_SUCCESS
;
1440 /***********************************************************************
1441 * InternetCanonicalizeUrlA (WININET.@)
1443 * Escape unsafe characters and spaces
1450 BOOL WINAPI
InternetCanonicalizeUrlA(LPCSTR lpszUrl
, LPSTR lpszBuffer
,
1451 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
1454 TRACE("%s %p %p %08lx\n",debugstr_a(lpszUrl
), lpszBuffer
,
1455 lpdwBufferLength
, dwFlags
);
1457 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1458 dwFlags
^= ICU_NO_ENCODE
;
1460 dwFlags
|= 0x80000000; /* Don't know what this means */
1462 hr
= UrlCanonicalizeA(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwFlags
);
1464 return (hr
== S_OK
) ? TRUE
: FALSE
;
1467 /***********************************************************************
1468 * InternetCanonicalizeUrlW (WININET.@)
1470 * Escape unsafe characters and spaces
1477 BOOL WINAPI
InternetCanonicalizeUrlW(LPCWSTR lpszUrl
, LPWSTR lpszBuffer
,
1478 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
1481 TRACE("%s %p %p %08lx\n", debugstr_w(lpszUrl
), lpszBuffer
,
1482 lpdwBufferLength
, dwFlags
);
1484 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1485 dwFlags
^= ICU_NO_ENCODE
;
1487 dwFlags
|= 0x80000000; /* Don't know what this means */
1489 hr
= UrlCanonicalizeW(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwFlags
);
1491 return (hr
== S_OK
) ? TRUE
: FALSE
;
1495 /***********************************************************************
1496 * InternetSetStatusCallbackA (WININET.@)
1498 * Sets up a callback function which is called as progress is made
1499 * during an operation.
1502 * Previous callback or NULL on success
1503 * INTERNET_INVALID_STATUS_CALLBACK on failure
1506 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackA(
1507 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
1509 INTERNET_STATUS_CALLBACK retVal
;
1510 LPWININETHANDLEHEADER lpwh
;
1512 TRACE("0x%08lx\n", (ULONG
)hInternet
);
1514 lpwh
= WININET_GetObject(hInternet
);
1516 return INTERNET_INVALID_STATUS_CALLBACK
;
1518 lpwh
->dwInternalFlags
&= ~INET_CALLBACKW
;
1519 retVal
= lpwh
->lpfnStatusCB
;
1520 lpwh
->lpfnStatusCB
= lpfnIntCB
;
1522 WININET_Release( lpwh
);
1527 /***********************************************************************
1528 * InternetSetStatusCallbackW (WININET.@)
1530 * Sets up a callback function which is called as progress is made
1531 * during an operation.
1534 * Previous callback or NULL on success
1535 * INTERNET_INVALID_STATUS_CALLBACK on failure
1538 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackW(
1539 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
1541 INTERNET_STATUS_CALLBACK retVal
;
1542 LPWININETHANDLEHEADER lpwh
;
1544 TRACE("0x%08lx\n", (ULONG
)hInternet
);
1546 lpwh
= WININET_GetObject(hInternet
);
1548 return INTERNET_INVALID_STATUS_CALLBACK
;
1550 lpwh
->dwInternalFlags
|= INET_CALLBACKW
;
1551 retVal
= lpwh
->lpfnStatusCB
;
1552 lpwh
->lpfnStatusCB
= lpfnIntCB
;
1554 WININET_Release( lpwh
);
1559 /***********************************************************************
1560 * InternetSetFilePointer (WININET.@)
1562 DWORD WINAPI
InternetSetFilePointer(HINTERNET f1
, LONG f2
, PVOID f3
, DWORD f4
, DWORD f5
)
1568 /***********************************************************************
1569 * InternetWriteFile (WININET.@)
1571 * Write data to an open internet file
1578 BOOL WINAPI
InternetWriteFile(HINTERNET hFile
, LPCVOID lpBuffer
,
1579 DWORD dwNumOfBytesToWrite
, LPDWORD lpdwNumOfBytesWritten
)
1581 BOOL retval
= FALSE
;
1583 LPWININETHANDLEHEADER lpwh
;
1586 lpwh
= (LPWININETHANDLEHEADER
) WININET_GetObject( hFile
);
1590 switch (lpwh
->htype
)
1593 FIXME("This shouldn't be here! We don't support this kind"
1594 " of connection anymore. Must use NETCON functions,"
1595 " especially if using SSL\n");
1596 nSocket
= ((LPWININETHTTPREQW
)lpwh
)->netConnection
.socketFD
;
1600 nSocket
= ((LPWININETFILE
)lpwh
)->nDataSocket
;
1609 int res
= send(nSocket
, lpBuffer
, dwNumOfBytesToWrite
, 0);
1610 retval
= (res
>= 0);
1611 *lpdwNumOfBytesWritten
= retval
? res
: 0;
1613 WININET_Release( lpwh
);
1619 /***********************************************************************
1620 * InternetReadFile (WININET.@)
1622 * Read data from an open internet file
1629 BOOL WINAPI
InternetReadFile(HINTERNET hFile
, LPVOID lpBuffer
,
1630 DWORD dwNumOfBytesToRead
, LPDWORD dwNumOfBytesRead
)
1632 BOOL retval
= FALSE
;
1634 LPWININETHANDLEHEADER lpwh
;
1636 TRACE("%p %p %ld %p\n", hFile
, lpBuffer
, dwNumOfBytesToRead
, dwNumOfBytesRead
);
1638 lpwh
= (LPWININETHANDLEHEADER
) WININET_GetObject( hFile
);
1642 /* FIXME: this should use NETCON functions! */
1643 switch (lpwh
->htype
)
1646 if (!NETCON_recv(&((LPWININETHTTPREQW
)lpwh
)->netConnection
, lpBuffer
,
1647 dwNumOfBytesToRead
, MSG_WAITALL
, (int *)dwNumOfBytesRead
))
1649 *dwNumOfBytesRead
= 0;
1650 retval
= TRUE
; /* Under windows, it seems to return 0 even if nothing was read... */
1657 /* FIXME: FTP should use NETCON_ stuff */
1658 nSocket
= ((LPWININETFILE
)lpwh
)->nDataSocket
;
1661 int res
= recv(nSocket
, lpBuffer
, dwNumOfBytesToRead
, MSG_WAITALL
);
1662 retval
= (res
>= 0);
1663 *dwNumOfBytesRead
= retval
? res
: 0;
1670 WININET_Release( lpwh
);
1672 TRACE("-- %s (bytes read: %ld)\n", retval
? "TRUE": "FALSE", dwNumOfBytesRead
? *dwNumOfBytesRead
: -1);
1676 /***********************************************************************
1677 * InternetReadFileExA (WININET.@)
1679 * Read data from an open internet file
1686 BOOL WINAPI
InternetReadFileExA(HINTERNET hFile
, LPINTERNET_BUFFERSA lpBuffer
,
1687 DWORD dwFlags
, DWORD dwContext
)
1693 /***********************************************************************
1694 * InternetReadFileExW (WININET.@)
1696 * Read data from an open internet file
1703 BOOL WINAPI
InternetReadFileExW(HINTERNET hFile
, LPINTERNET_BUFFERSW lpBuffer
,
1704 DWORD dwFlags
, DWORD dwContext
)
1708 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1712 /***********************************************************************
1713 * INET_QueryOptionHelper (internal)
1715 static BOOL
INET_QueryOptionHelper(BOOL bIsUnicode
, HINTERNET hInternet
, DWORD dwOption
,
1716 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
1718 LPWININETHANDLEHEADER lpwhh
;
1719 BOOL bSuccess
= FALSE
;
1721 TRACE("(%p, 0x%08lx, %p, %p)\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
1723 lpwhh
= (LPWININETHANDLEHEADER
) WININET_GetObject( hInternet
);
1727 case INTERNET_OPTION_HANDLE_TYPE
:
1733 WARN("Invalid hInternet handle\n");
1734 SetLastError(ERROR_INVALID_HANDLE
);
1738 type
= lpwhh
->htype
;
1740 TRACE("INTERNET_OPTION_HANDLE_TYPE: %ld\n", type
);
1742 if (*lpdwBufferLength
< sizeof(ULONG
))
1743 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1746 memcpy(lpBuffer
, &type
, sizeof(ULONG
));
1747 *lpdwBufferLength
= sizeof(ULONG
);
1753 case INTERNET_OPTION_REQUEST_FLAGS
:
1756 TRACE("INTERNET_OPTION_REQUEST_FLAGS: %ld\n", flags
);
1757 if (*lpdwBufferLength
< sizeof(ULONG
))
1758 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1761 memcpy(lpBuffer
, &flags
, sizeof(ULONG
));
1762 *lpdwBufferLength
= sizeof(ULONG
);
1768 case INTERNET_OPTION_URL
:
1769 case INTERNET_OPTION_DATAFILE_NAME
:
1773 WARN("Invalid hInternet handle\n");
1774 SetLastError(ERROR_INVALID_HANDLE
);
1777 if (lpwhh
->htype
== WH_HHTTPREQ
)
1779 LPWININETHTTPREQW lpreq
= (LPWININETHTTPREQW
) lpwhh
;
1781 static const WCHAR szFmt
[] = {'h','t','t','p',':','/','/','%','s','%','s',0};
1783 sprintfW(url
,szFmt
,lpreq
->StdHeaders
[HTTP_QUERY_HOST
].lpszValue
,lpreq
->lpszPath
);
1784 TRACE("INTERNET_OPTION_URL: %s\n",debugstr_w(url
));
1785 if (*lpdwBufferLength
< strlenW(url
)+1)
1786 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1791 *lpdwBufferLength
=WideCharToMultiByte(CP_ACP
,0,url
,-1,lpBuffer
,*lpdwBufferLength
,NULL
,NULL
);
1795 strcpyW(lpBuffer
, url
);
1796 *lpdwBufferLength
= strlenW(url
)+1;
1803 case INTERNET_OPTION_HTTP_VERSION
:
1806 * Presently hardcoded to 1.1
1808 ((HTTP_VERSION_INFO
*)lpBuffer
)->dwMajorVersion
= 1;
1809 ((HTTP_VERSION_INFO
*)lpBuffer
)->dwMinorVersion
= 1;
1813 case INTERNET_OPTION_CONNECTED_STATE
:
1815 INTERNET_CONNECTED_INFO
* pCi
= (INTERNET_CONNECTED_INFO
*)lpBuffer
;
1816 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
1817 pCi
->dwConnectedState
= INTERNET_STATE_CONNECTED
;
1822 case INTERNET_OPTION_SECURITY_FLAGS
:
1823 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
1827 FIXME("Stub! %ld \n",dwOption
);
1831 WININET_Release( lpwhh
);
1836 /***********************************************************************
1837 * InternetQueryOptionW (WININET.@)
1839 * Queries an options on the specified handle
1846 BOOL WINAPI
InternetQueryOptionW(HINTERNET hInternet
, DWORD dwOption
,
1847 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
1849 return INET_QueryOptionHelper(TRUE
, hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
1852 /***********************************************************************
1853 * InternetQueryOptionA (WININET.@)
1855 * Queries an options on the specified handle
1862 BOOL WINAPI
InternetQueryOptionA(HINTERNET hInternet
, DWORD dwOption
,
1863 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
1865 return INET_QueryOptionHelper(FALSE
, hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
1869 /***********************************************************************
1870 * InternetSetOptionW (WININET.@)
1872 * Sets an options on the specified handle
1879 BOOL WINAPI
InternetSetOptionW(HINTERNET hInternet
, DWORD dwOption
,
1880 LPVOID lpBuffer
, DWORD dwBufferLength
)
1882 LPWININETHANDLEHEADER lpwhh
;
1885 TRACE("0x%08lx\n", dwOption
);
1887 lpwhh
= (LPWININETHANDLEHEADER
) WININET_GetObject( hInternet
);
1893 case INTERNET_OPTION_HTTP_VERSION
:
1895 HTTP_VERSION_INFO
* pVersion
=(HTTP_VERSION_INFO
*)lpBuffer
;
1896 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%ld,%ld): STUB\n",pVersion
->dwMajorVersion
,pVersion
->dwMinorVersion
);
1899 case INTERNET_OPTION_ERROR_MASK
:
1901 unsigned long flags
=*(unsigned long*)lpBuffer
;
1902 FIXME("Option INTERNET_OPTION_ERROR_MASK(%ld): STUB\n",flags
);
1905 case INTERNET_OPTION_CODEPAGE
:
1907 unsigned long codepage
=*(unsigned long*)lpBuffer
;
1908 FIXME("Option INTERNET_OPTION_CODEPAGE (%ld): STUB\n",codepage
);
1911 case INTERNET_OPTION_REQUEST_PRIORITY
:
1913 unsigned long priority
=*(unsigned long*)lpBuffer
;
1914 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%ld): STUB\n",priority
);
1917 case INTERNET_OPTION_CONNECT_TIMEOUT
:
1919 unsigned long connecttimeout
=*(unsigned long*)lpBuffer
;
1920 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%ld): STUB\n",connecttimeout
);
1923 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT
:
1925 unsigned long receivetimeout
=*(unsigned long*)lpBuffer
;
1926 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%ld): STUB\n",receivetimeout
);
1929 case INTERNET_OPTION_RESET_URLCACHE_SESSION
:
1930 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
1932 case INTERNET_OPTION_END_BROWSER_SESSION
:
1933 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
1935 case INTERNET_OPTION_CONNECTED_STATE
:
1936 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
1939 FIXME("Option %ld STUB\n",dwOption
);
1940 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1944 WININET_Release( lpwhh
);
1950 /***********************************************************************
1951 * InternetSetOptionA (WININET.@)
1953 * Sets an options on the specified handle.
1960 BOOL WINAPI
InternetSetOptionA(HINTERNET hInternet
, DWORD dwOption
,
1961 LPVOID lpBuffer
, DWORD dwBufferLength
)
1969 case INTERNET_OPTION_PROXY
:
1971 LPINTERNET_PROXY_INFOA pi
= (LPINTERNET_PROXY_INFOA
) lpBuffer
;
1972 LPINTERNET_PROXY_INFOW piw
;
1973 DWORD proxlen
, prbylen
;
1976 proxlen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, NULL
, 0);
1977 prbylen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, NULL
, 0);
1978 wlen
= sizeof(*piw
) + proxlen
+ prbylen
;
1979 wbuffer
= HeapAlloc( GetProcessHeap(), 0, wlen
*sizeof(WCHAR
) );
1980 piw
= (LPINTERNET_PROXY_INFOW
) wbuffer
;
1981 piw
->dwAccessType
= pi
->dwAccessType
;
1982 prox
= (LPWSTR
) &piw
[1];
1983 prby
= &prox
[proxlen
+1];
1984 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, prox
, proxlen
);
1985 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, prby
, prbylen
);
1986 piw
->lpszProxy
= prox
;
1987 piw
->lpszProxyBypass
= prby
;
1990 case INTERNET_OPTION_USER_AGENT
:
1991 case INTERNET_OPTION_USERNAME
:
1992 case INTERNET_OPTION_PASSWORD
:
1993 wlen
= MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, dwBufferLength
,
1995 wbuffer
= HeapAlloc( GetProcessHeap(), 0, wlen
*sizeof(WCHAR
) );
1996 MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, dwBufferLength
,
2001 wlen
= dwBufferLength
;
2004 r
= InternetSetOptionW(hInternet
,dwOption
, wbuffer
, wlen
);
2006 if( lpBuffer
!= wbuffer
)
2007 HeapFree( GetProcessHeap(), 0, wbuffer
);
2013 /***********************************************************************
2014 * InternetSetOptionExA (WININET.@)
2016 BOOL WINAPI
InternetSetOptionExA(HINTERNET hInternet
, DWORD dwOption
,
2017 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
2019 FIXME("Flags %08lx ignored\n", dwFlags
);
2020 return InternetSetOptionA( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2023 /***********************************************************************
2024 * InternetSetOptionExW (WININET.@)
2026 BOOL WINAPI
InternetSetOptionExW(HINTERNET hInternet
, DWORD dwOption
,
2027 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
2029 FIXME("Flags %08lx ignored\n", dwFlags
);
2030 if( dwFlags
& ~ISO_VALID_FLAGS
)
2032 SetLastError( ERROR_INVALID_PARAMETER
);
2035 return InternetSetOptionW( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2038 static const WCHAR WININET_wkday
[7][4] =
2039 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
2040 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
2041 static const WCHAR WININET_month
[12][4] =
2042 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
2043 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
2044 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
2046 /***********************************************************************
2047 * InternetTimeFromSystemTimeA (WININET.@)
2049 BOOL WINAPI
InternetTimeFromSystemTimeA( const SYSTEMTIME
* time
, DWORD format
, LPSTR string
, DWORD size
)
2052 WCHAR stringW
[INTERNET_RFC1123_BUFSIZE
];
2054 TRACE( "%p 0x%08lx %p 0x%08lx\n", time
, format
, string
, size
);
2056 ret
= InternetTimeFromSystemTimeW( time
, format
, stringW
, sizeof(stringW
) );
2057 if (ret
) WideCharToMultiByte( CP_ACP
, 0, stringW
, -1, string
, size
, NULL
, NULL
);
2062 /***********************************************************************
2063 * InternetTimeFromSystemTimeW (WININET.@)
2065 BOOL WINAPI
InternetTimeFromSystemTimeW( const SYSTEMTIME
* time
, DWORD format
, LPWSTR string
, DWORD size
)
2067 static const WCHAR date
[] =
2068 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
2069 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
2071 TRACE( "%p 0x%08lx %p 0x%08lx\n", time
, format
, string
, size
);
2073 if (!time
|| !string
) return FALSE
;
2075 if (format
!= INTERNET_RFC1123_FORMAT
|| size
< INTERNET_RFC1123_BUFSIZE
* sizeof(WCHAR
))
2078 sprintfW( string
, date
,
2079 WININET_wkday
[time
->wDayOfWeek
],
2081 WININET_month
[time
->wMonth
- 1],
2090 /***********************************************************************
2091 * InternetTimeToSystemTimeA (WININET.@)
2093 BOOL WINAPI
InternetTimeToSystemTimeA( LPCSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
2099 TRACE( "%s %p 0x%08lx\n", debugstr_a(string
), time
, reserved
);
2101 len
= MultiByteToWideChar( CP_ACP
, 0, string
, -1, NULL
, 0 );
2102 stringW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
2106 MultiByteToWideChar( CP_ACP
, 0, string
, -1, stringW
, len
);
2107 ret
= InternetTimeToSystemTimeW( stringW
, time
, reserved
);
2108 HeapFree( GetProcessHeap(), 0, stringW
);
2113 /***********************************************************************
2114 * InternetTimeToSystemTimeW (WININET.@)
2116 BOOL WINAPI
InternetTimeToSystemTimeW( LPCWSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
2119 WCHAR
*s
= (LPWSTR
)string
;
2121 TRACE( "%s %p 0x%08lx\n", debugstr_w(string
), time
, reserved
);
2123 if (!string
|| !time
|| reserved
!= 0) return FALSE
;
2125 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
2126 * a SYSTEMTIME structure.
2129 while (*s
&& !isalphaW( *s
)) s
++;
2130 if (*s
== '\0' || *(s
+ 1) == '\0' || *(s
+ 2) == '\0') return FALSE
;
2131 time
->wDayOfWeek
= 7;
2133 for (i
= 0; i
< 7; i
++)
2135 if (toupperW( WININET_wkday
[i
][0] ) == toupperW( *s
) &&
2136 toupperW( WININET_wkday
[i
][1] ) == toupperW( *(s
+ 1) ) &&
2137 toupperW( WININET_wkday
[i
][2] ) == toupperW( *(s
+ 2) ) )
2139 time
->wDayOfWeek
= i
;
2144 if (time
->wDayOfWeek
> 6) return FALSE
;
2145 while (*s
&& !isdigitW( *s
)) s
++;
2146 time
->wDay
= strtolW( s
, &s
, 10 );
2148 while (*s
&& !isalphaW( *s
)) s
++;
2149 if (*s
== '\0' || *(s
+ 1) == '\0' || *(s
+ 2) == '\0') return FALSE
;
2152 for (i
= 0; i
< 12; i
++)
2154 if (toupperW( WININET_month
[i
][0]) == toupperW( *s
) &&
2155 toupperW( WININET_month
[i
][1]) == toupperW( *(s
+ 1) ) &&
2156 toupperW( WININET_month
[i
][2]) == toupperW( *(s
+ 2) ) )
2158 time
->wMonth
= i
+ 1;
2162 if (time
->wMonth
== 0) return FALSE
;
2164 while (*s
&& !isdigitW( *s
)) s
++;
2165 if (*s
== '\0') return FALSE
;
2166 time
->wYear
= strtolW( s
, &s
, 10 );
2168 while (*s
&& !isdigitW( *s
)) s
++;
2169 if (*s
== '\0') return FALSE
;
2170 time
->wHour
= strtolW( s
, &s
, 10 );
2172 while (*s
&& !isdigitW( *s
)) s
++;
2173 if (*s
== '\0') return FALSE
;
2174 time
->wMinute
= strtolW( s
, &s
, 10 );
2176 while (*s
&& !isdigitW( *s
)) s
++;
2177 if (*s
== '\0') return FALSE
;
2178 time
->wSecond
= strtolW( s
, &s
, 10 );
2180 time
->wMilliseconds
= 0;
2184 /***********************************************************************
2185 * InternetCheckConnectionA (WININET.@)
2187 * Pings a requested host to check internet connection
2190 * TRUE on success and FALSE on failure. If a failure then
2191 * ERROR_NOT_CONNECTED is placesd into GetLastError
2194 BOOL WINAPI
InternetCheckConnectionA( LPCSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
2197 * this is a kludge which runs the resident ping program and reads the output.
2199 * Anyone have a better idea?
2210 * Crack or set the Address
2212 if (lpszUrl
== NULL
)
2215 * According to the doc we are supost to use the ip for the next
2216 * server in the WnInet internal server database. I have
2217 * no idea what that is or how to get it.
2219 * So someone needs to implement this.
2221 FIXME("Unimplemented with URL of NULL\n");
2226 URL_COMPONENTSA components
;
2228 ZeroMemory(&components
,sizeof(URL_COMPONENTSA
));
2229 components
.lpszHostName
= (LPSTR
)&host
;
2230 components
.dwHostNameLength
= 1024;
2232 if (!InternetCrackUrlA(lpszUrl
,0,0,&components
))
2235 TRACE("host name : %s\n",components
.lpszHostName
);
2239 * Build our ping command
2241 strcpy(command
,"ping -w 1 ");
2242 strcat(command
,host
);
2243 strcat(command
," >/dev/null 2>/dev/null");
2245 TRACE("Ping command is : %s\n",command
);
2247 status
= system(command
);
2249 TRACE("Ping returned a code of %i \n",status
);
2251 /* Ping return code of 0 indicates success */
2258 SetLastError(ERROR_NOT_CONNECTED
);
2264 /***********************************************************************
2265 * InternetCheckConnectionW (WININET.@)
2267 * Pings a requested host to check internet connection
2270 * TRUE on success and FALSE on failure. If a failure then
2271 * ERROR_NOT_CONNECTED is placed into GetLastError
2274 BOOL WINAPI
InternetCheckConnectionW(LPCWSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
2280 len
= WideCharToMultiByte(CP_ACP
, 0, lpszUrl
, -1, NULL
, 0, NULL
, NULL
);
2281 if (!(szUrl
= (CHAR
*)HeapAlloc(GetProcessHeap(), 0, len
*sizeof(CHAR
))))
2283 WideCharToMultiByte(CP_ACP
, 0, lpszUrl
, -1, szUrl
, len
, NULL
, NULL
);
2284 rc
= InternetCheckConnectionA((LPCSTR
)szUrl
, dwFlags
, dwReserved
);
2285 HeapFree(GetProcessHeap(), 0, szUrl
);
2291 /**********************************************************
2292 * INTERNET_InternetOpenUrlW (internal)
2297 * handle of connection or NULL on failure
2299 HINTERNET WINAPI
INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC
, LPCWSTR lpszUrl
,
2300 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD dwContext
)
2302 URL_COMPONENTSW urlComponents
;
2303 WCHAR protocol
[32], hostName
[MAXHOSTNAME
], userName
[1024];
2304 WCHAR password
[1024], path
[2048], extra
[1024];
2305 HINTERNET client
= NULL
, client1
= NULL
;
2307 TRACE("(%p, %s, %s, %08lx, %08lx, %08lx)\n", hIC
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
2308 dwHeadersLength
, dwFlags
, dwContext
);
2310 urlComponents
.dwStructSize
= sizeof(URL_COMPONENTSW
);
2311 urlComponents
.lpszScheme
= protocol
;
2312 urlComponents
.dwSchemeLength
= 32;
2313 urlComponents
.lpszHostName
= hostName
;
2314 urlComponents
.dwHostNameLength
= MAXHOSTNAME
;
2315 urlComponents
.lpszUserName
= userName
;
2316 urlComponents
.dwUserNameLength
= 1024;
2317 urlComponents
.lpszPassword
= password
;
2318 urlComponents
.dwPasswordLength
= 1024;
2319 urlComponents
.lpszUrlPath
= path
;
2320 urlComponents
.dwUrlPathLength
= 2048;
2321 urlComponents
.lpszExtraInfo
= extra
;
2322 urlComponents
.dwExtraInfoLength
= 1024;
2323 if(!InternetCrackUrlW(lpszUrl
, strlenW(lpszUrl
), 0, &urlComponents
))
2325 switch(urlComponents
.nScheme
) {
2326 case INTERNET_SCHEME_FTP
:
2327 if(urlComponents
.nPort
== 0)
2328 urlComponents
.nPort
= INTERNET_DEFAULT_FTP_PORT
;
2329 client
= FTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
2330 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
);
2333 client1
= FtpOpenFileW(client
, path
, GENERIC_READ
, dwFlags
, dwContext
);
2334 if(client1
== NULL
) {
2335 InternetCloseHandle(client
);
2340 case INTERNET_SCHEME_HTTP
:
2341 case INTERNET_SCHEME_HTTPS
: {
2342 static const WCHAR szStars
[] = { '*','/','*', 0 };
2343 LPCWSTR accept
[2] = { szStars
, NULL
};
2344 if(urlComponents
.nPort
== 0) {
2345 if(urlComponents
.nScheme
== INTERNET_SCHEME_HTTP
)
2346 urlComponents
.nPort
= INTERNET_DEFAULT_HTTP_PORT
;
2348 urlComponents
.nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
2350 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
2351 client
= HTTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
2352 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
);
2355 client1
= HttpOpenRequestW(client
, NULL
, path
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
2356 if(client1
== NULL
) {
2357 InternetCloseHandle(client
);
2360 HttpAddRequestHeadersW(client1
, lpszHeaders
, dwHeadersLength
, HTTP_ADDREQ_FLAG_ADD
);
2361 if (!HttpSendRequestW(client1
, NULL
, 0, NULL
, 0)) {
2362 InternetCloseHandle(client1
);
2367 case INTERNET_SCHEME_GOPHER
:
2368 /* gopher doesn't seem to be implemented in wine, but it's supposed
2369 * to be supported by InternetOpenUrlA. */
2374 TRACE(" %p <--\n", client1
);
2379 /**********************************************************
2380 * InternetOpenUrlW (WININET.@)
2385 * handle of connection or NULL on failure
2387 HINTERNET WINAPI
InternetOpenUrlW(HINTERNET hInternet
, LPCWSTR lpszUrl
,
2388 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD dwContext
)
2390 HINTERNET ret
= NULL
;
2391 LPWININETAPPINFOW hIC
= NULL
;
2393 if (TRACE_ON(wininet
)) {
2394 TRACE("(%p, %s, %s, %08lx, %08lx, %08lx)\n", hInternet
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
2395 dwHeadersLength
, dwFlags
, dwContext
);
2397 dump_INTERNET_FLAGS(dwFlags
);
2400 hIC
= (LPWININETAPPINFOW
) WININET_GetObject( hInternet
);
2401 if (NULL
== hIC
|| hIC
->hdr
.htype
!= WH_HINIT
) {
2402 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2406 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
) {
2407 WORKREQUEST workRequest
;
2408 struct WORKREQ_INTERNETOPENURLW
*req
;
2410 workRequest
.asyncall
= INTERNETOPENURLW
;
2411 workRequest
.hdr
= WININET_AddRef( &hIC
->hdr
);
2412 req
= &workRequest
.u
.InternetOpenUrlW
;
2414 req
->lpszUrl
= WININET_strdupW(lpszUrl
);
2418 req
->lpszHeaders
= WININET_strdupW(lpszHeaders
);
2420 req
->lpszHeaders
= 0;
2421 req
->dwHeadersLength
= dwHeadersLength
;
2422 req
->dwFlags
= dwFlags
;
2423 req
->dwContext
= dwContext
;
2425 INTERNET_AsyncCall(&workRequest
);
2427 * This is from windows.
2429 SetLastError(ERROR_IO_PENDING
);
2431 ret
= INTERNET_InternetOpenUrlW(hIC
, lpszUrl
, lpszHeaders
, dwHeadersLength
, dwFlags
, dwContext
);
2436 WININET_Release( &hIC
->hdr
);
2437 TRACE(" %p <--\n", ret
);
2442 /**********************************************************
2443 * InternetOpenUrlA (WININET.@)
2448 * handle of connection or NULL on failure
2450 HINTERNET WINAPI
InternetOpenUrlA(HINTERNET hInternet
, LPCSTR lpszUrl
,
2451 LPCSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD dwContext
)
2453 HINTERNET rc
= (HINTERNET
)NULL
;
2457 LPWSTR szUrl
= NULL
;
2458 LPWSTR szHeaders
= NULL
;
2463 lenUrl
= MultiByteToWideChar(CP_ACP
, 0, lpszUrl
, -1, NULL
, 0 );
2464 szUrl
= HeapAlloc(GetProcessHeap(), 0, lenUrl
*sizeof(WCHAR
));
2466 return (HINTERNET
)NULL
;
2467 MultiByteToWideChar(CP_ACP
, 0, lpszUrl
, -1, szUrl
, lenUrl
);
2471 lenHeaders
= MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, NULL
, 0 );
2472 szHeaders
= HeapAlloc(GetProcessHeap(), 0, lenHeaders
*sizeof(WCHAR
));
2474 HeapFree(GetProcessHeap(), 0, szUrl
);
2475 return (HINTERNET
)NULL
;
2477 MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, szHeaders
, lenHeaders
);
2480 rc
= InternetOpenUrlW(hInternet
, szUrl
, szHeaders
,
2481 lenHeaders
, dwFlags
, dwContext
);
2483 HeapFree(GetProcessHeap(), 0, szUrl
);
2484 HeapFree(GetProcessHeap(), 0, szHeaders
);
2490 /***********************************************************************
2491 * INTERNET_SetLastError (internal)
2493 * Set last thread specific error
2498 void INTERNET_SetLastError(DWORD dwError
)
2500 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
2502 SetLastError(dwError
);
2504 lpwite
->dwError
= dwError
;
2508 /***********************************************************************
2509 * INTERNET_GetLastError (internal)
2511 * Get last thread specific error
2516 DWORD
INTERNET_GetLastError(void)
2518 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
2519 return lpwite
->dwError
;
2523 /***********************************************************************
2524 * INTERNET_WorkerThreadFunc (internal)
2526 * Worker thread execution function
2531 static DWORD
INTERNET_WorkerThreadFunc(LPVOID
*lpvParam
)
2538 INTERNET_ExecuteWork();
2541 dwWaitRes
= WaitForMultipleObjects(2, hEventArray
, FALSE
, MAX_IDLE_WORKER
);
2543 if (dwWaitRes
== WAIT_OBJECT_0
+ 1)
2544 INTERNET_ExecuteWork();
2548 InterlockedIncrement(&dwNumIdleThreads
);
2551 InterlockedDecrement(&dwNumIdleThreads
);
2552 InterlockedDecrement(&dwNumThreads
);
2553 TRACE("Worker thread exiting\n");
2558 /***********************************************************************
2559 * INTERNET_InsertWorkRequest (internal)
2561 * Insert work request into queue
2566 static BOOL
INTERNET_InsertWorkRequest(LPWORKREQUEST lpWorkRequest
)
2568 BOOL bSuccess
= FALSE
;
2569 LPWORKREQUEST lpNewRequest
;
2573 lpNewRequest
= HeapAlloc(GetProcessHeap(), 0, sizeof(WORKREQUEST
));
2576 memcpy(lpNewRequest
, lpWorkRequest
, sizeof(WORKREQUEST
));
2577 lpNewRequest
->prev
= NULL
;
2579 EnterCriticalSection(&csQueue
);
2581 lpNewRequest
->next
= lpWorkQueueTail
;
2582 if (lpWorkQueueTail
)
2583 lpWorkQueueTail
->prev
= lpNewRequest
;
2584 lpWorkQueueTail
= lpNewRequest
;
2585 if (!lpHeadWorkQueue
)
2586 lpHeadWorkQueue
= lpWorkQueueTail
;
2588 LeaveCriticalSection(&csQueue
);
2591 InterlockedIncrement(&dwNumJobs
);
2598 /***********************************************************************
2599 * INTERNET_GetWorkRequest (internal)
2601 * Retrieves work request from queue
2606 static BOOL
INTERNET_GetWorkRequest(LPWORKREQUEST lpWorkRequest
)
2608 BOOL bSuccess
= FALSE
;
2609 LPWORKREQUEST lpRequest
= NULL
;
2613 EnterCriticalSection(&csQueue
);
2615 if (lpHeadWorkQueue
)
2617 lpRequest
= lpHeadWorkQueue
;
2618 lpHeadWorkQueue
= lpHeadWorkQueue
->prev
;
2619 if (lpRequest
== lpWorkQueueTail
)
2620 lpWorkQueueTail
= lpHeadWorkQueue
;
2623 LeaveCriticalSection(&csQueue
);
2627 memcpy(lpWorkRequest
, lpRequest
, sizeof(WORKREQUEST
));
2628 HeapFree(GetProcessHeap(), 0, lpRequest
);
2630 InterlockedDecrement(&dwNumJobs
);
2637 /***********************************************************************
2638 * INTERNET_AsyncCall (internal)
2640 * Retrieves work request from queue
2645 BOOL
INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest
)
2649 BOOL bSuccess
= FALSE
;
2653 if (InterlockedDecrement(&dwNumIdleThreads
) < 0)
2655 InterlockedIncrement(&dwNumIdleThreads
);
2657 if (InterlockedIncrement(&dwNumThreads
) > MAX_WORKER_THREADS
||
2658 !(hThread
= CreateThread(NULL
, 0,
2659 (LPTHREAD_START_ROUTINE
)INTERNET_WorkerThreadFunc
, NULL
, 0, &dwTID
)))
2661 InterlockedDecrement(&dwNumThreads
);
2662 INTERNET_SetLastError(ERROR_INTERNET_ASYNC_THREAD_FAILED
);
2666 TRACE("Created new thread\n");
2670 INTERNET_InsertWorkRequest(lpWorkRequest
);
2671 SetEvent(hWorkEvent
);
2679 /***********************************************************************
2680 * INTERNET_ExecuteWork (internal)
2685 static VOID
INTERNET_ExecuteWork(void)
2687 WORKREQUEST workRequest
;
2691 if (!INTERNET_GetWorkRequest(&workRequest
))
2694 switch (workRequest
.asyncall
)
2698 struct WORKREQ_FTPPUTFILEW
*req
= &workRequest
.u
.FtpPutFileW
;
2699 LPWININETFTPSESSIONW lpwfs
= (LPWININETFTPSESSIONW
) workRequest
.hdr
;
2701 TRACE("FTPPUTFILEW %p\n", lpwfs
);
2703 FTP_FtpPutFileW(lpwfs
, req
->lpszLocalFile
,
2704 req
->lpszNewRemoteFile
, req
->dwFlags
, req
->dwContext
);
2706 HeapFree(GetProcessHeap(), 0, req
->lpszLocalFile
);
2707 HeapFree(GetProcessHeap(), 0, req
->lpszNewRemoteFile
);
2711 case FTPSETCURRENTDIRECTORYW
:
2713 struct WORKREQ_FTPSETCURRENTDIRECTORYW
*req
;
2714 LPWININETFTPSESSIONW lpwfs
= (LPWININETFTPSESSIONW
) workRequest
.hdr
;
2716 TRACE("FTPSETCURRENTDIRECTORYW %p\n", lpwfs
);
2718 req
= &workRequest
.u
.FtpSetCurrentDirectoryW
;
2719 FTP_FtpSetCurrentDirectoryW(lpwfs
, req
->lpszDirectory
);
2720 HeapFree(GetProcessHeap(), 0, req
->lpszDirectory
);
2724 case FTPCREATEDIRECTORYW
:
2726 struct WORKREQ_FTPCREATEDIRECTORYW
*req
;
2727 LPWININETFTPSESSIONW lpwfs
= (LPWININETFTPSESSIONW
) workRequest
.hdr
;
2729 TRACE("FTPCREATEDIRECTORYW %p\n", lpwfs
);
2731 req
= &workRequest
.u
.FtpCreateDirectoryW
;
2732 FTP_FtpCreateDirectoryW(lpwfs
, req
->lpszDirectory
);
2733 HeapFree(GetProcessHeap(), 0, req
->lpszDirectory
);
2737 case FTPFINDFIRSTFILEW
:
2739 struct WORKREQ_FTPFINDFIRSTFILEW
*req
;
2740 LPWININETFTPSESSIONW lpwfs
= (LPWININETFTPSESSIONW
) workRequest
.hdr
;
2742 TRACE("FTPFINDFIRSTFILEW %p\n", lpwfs
);
2744 req
= &workRequest
.u
.FtpFindFirstFileW
;
2745 FTP_FtpFindFirstFileW(lpwfs
, req
->lpszSearchFile
,
2746 req
->lpFindFileData
, req
->dwFlags
, req
->dwContext
);
2747 HeapFree(GetProcessHeap(), 0, req
->lpszSearchFile
);
2751 case FTPGETCURRENTDIRECTORYW
:
2753 struct WORKREQ_FTPGETCURRENTDIRECTORYW
*req
;
2754 LPWININETFTPSESSIONW lpwfs
= (LPWININETFTPSESSIONW
) workRequest
.hdr
;
2756 TRACE("FTPGETCURRENTDIRECTORYW %p\n", lpwfs
);
2758 req
= &workRequest
.u
.FtpGetCurrentDirectoryW
;
2759 FTP_FtpGetCurrentDirectoryW(lpwfs
,
2760 req
->lpszDirectory
, req
->lpdwDirectory
);
2766 struct WORKREQ_FTPOPENFILEW
*req
= &workRequest
.u
.FtpOpenFileW
;
2767 LPWININETFTPSESSIONW lpwfs
= (LPWININETFTPSESSIONW
) workRequest
.hdr
;
2769 TRACE("FTPOPENFILEW %p\n", lpwfs
);
2771 FTP_FtpOpenFileW(lpwfs
, req
->lpszFilename
,
2772 req
->dwAccess
, req
->dwFlags
, req
->dwContext
);
2773 HeapFree(GetProcessHeap(), 0, req
->lpszFilename
);
2779 struct WORKREQ_FTPGETFILEW
*req
= &workRequest
.u
.FtpGetFileW
;
2780 LPWININETFTPSESSIONW lpwfs
= (LPWININETFTPSESSIONW
) workRequest
.hdr
;
2782 TRACE("FTPGETFILEW %p\n", lpwfs
);
2784 FTP_FtpGetFileW(lpwfs
, req
->lpszRemoteFile
,
2785 req
->lpszNewFile
, req
->fFailIfExists
,
2786 req
->dwLocalFlagsAttribute
, req
->dwFlags
, req
->dwContext
);
2787 HeapFree(GetProcessHeap(), 0, req
->lpszRemoteFile
);
2788 HeapFree(GetProcessHeap(), 0, req
->lpszNewFile
);
2792 case FTPDELETEFILEW
:
2794 struct WORKREQ_FTPDELETEFILEW
*req
= &workRequest
.u
.FtpDeleteFileW
;
2795 LPWININETFTPSESSIONW lpwfs
= (LPWININETFTPSESSIONW
) workRequest
.hdr
;
2797 TRACE("FTPDELETEFILEW %p\n", lpwfs
);
2799 FTP_FtpDeleteFileW(lpwfs
, req
->lpszFilename
);
2800 HeapFree(GetProcessHeap(), 0, req
->lpszFilename
);
2804 case FTPREMOVEDIRECTORYW
:
2806 struct WORKREQ_FTPREMOVEDIRECTORYW
*req
;
2807 LPWININETFTPSESSIONW lpwfs
= (LPWININETFTPSESSIONW
) workRequest
.hdr
;
2809 TRACE("FTPREMOVEDIRECTORYW %p\n", lpwfs
);
2811 req
= &workRequest
.u
.FtpRemoveDirectoryW
;
2812 FTP_FtpRemoveDirectoryW(lpwfs
, req
->lpszDirectory
);
2813 HeapFree(GetProcessHeap(), 0, req
->lpszDirectory
);
2817 case FTPRENAMEFILEW
:
2819 struct WORKREQ_FTPRENAMEFILEW
*req
= &workRequest
.u
.FtpRenameFileW
;
2820 LPWININETFTPSESSIONW lpwfs
= (LPWININETFTPSESSIONW
) workRequest
.hdr
;
2822 TRACE("FTPRENAMEFILEW %p\n", lpwfs
);
2824 FTP_FtpRenameFileW(lpwfs
, req
->lpszSrcFile
, req
->lpszDestFile
);
2825 HeapFree(GetProcessHeap(), 0, req
->lpszSrcFile
);
2826 HeapFree(GetProcessHeap(), 0, req
->lpszDestFile
);
2830 case INTERNETFINDNEXTW
:
2832 struct WORKREQ_INTERNETFINDNEXTW
*req
;
2833 LPWININETFINDNEXTW lpwh
= (LPWININETFINDNEXTW
) workRequest
.hdr
;
2835 TRACE("INTERNETFINDNEXTW %p\n", lpwh
);
2837 req
= &workRequest
.u
.InternetFindNextW
;
2838 INTERNET_FindNextFileW(lpwh
, req
->lpFindFileData
);
2842 case HTTPSENDREQUESTW
:
2844 struct WORKREQ_HTTPSENDREQUESTW
*req
= &workRequest
.u
.HttpSendRequestW
;
2845 LPWININETHTTPREQW lpwhr
= (LPWININETHTTPREQW
) workRequest
.hdr
;
2847 TRACE("HTTPSENDREQUESTW %p\n", lpwhr
);
2849 HTTP_HttpSendRequestW(lpwhr
, req
->lpszHeader
,
2850 req
->dwHeaderLength
, req
->lpOptional
, req
->dwOptionalLength
);
2852 HeapFree(GetProcessHeap(), 0, req
->lpszHeader
);
2856 case HTTPOPENREQUESTW
:
2858 struct WORKREQ_HTTPOPENREQUESTW
*req
= &workRequest
.u
.HttpOpenRequestW
;
2859 LPWININETHTTPSESSIONW lpwhs
= (LPWININETHTTPSESSIONW
) workRequest
.hdr
;
2861 TRACE("HTTPOPENREQUESTW %p\n", lpwhs
);
2863 HTTP_HttpOpenRequestW(lpwhs
, req
->lpszVerb
,
2864 req
->lpszObjectName
, req
->lpszVersion
, req
->lpszReferrer
,
2865 req
->lpszAcceptTypes
, req
->dwFlags
, req
->dwContext
);
2867 HeapFree(GetProcessHeap(), 0, req
->lpszVerb
);
2868 HeapFree(GetProcessHeap(), 0, req
->lpszObjectName
);
2869 HeapFree(GetProcessHeap(), 0, req
->lpszVersion
);
2870 HeapFree(GetProcessHeap(), 0, req
->lpszReferrer
);
2876 struct WORKREQ_SENDCALLBACK
*req
= &workRequest
.u
.SendCallback
;
2878 TRACE("SENDCALLBACK %p\n", workRequest
.hdr
);
2880 SendSyncCallback(workRequest
.hdr
,
2881 req
->dwContext
, req
->dwInternetStatus
, req
->lpvStatusInfo
,
2882 req
->dwStatusInfoLength
);
2884 /* And frees the copy of the status info */
2885 HeapFree(GetProcessHeap(), 0, req
->lpvStatusInfo
);
2889 case INTERNETOPENURLW
:
2891 struct WORKREQ_INTERNETOPENURLW
*req
= &workRequest
.u
.InternetOpenUrlW
;
2892 LPWININETAPPINFOW hIC
= (LPWININETAPPINFOW
) workRequest
.hdr
;
2894 TRACE("INTERNETOPENURLW %p\n", hIC
);
2896 INTERNET_InternetOpenUrlW(hIC
, req
->lpszUrl
,
2897 req
->lpszHeaders
, req
->dwHeadersLength
, req
->dwFlags
, req
->dwContext
);
2898 HeapFree(GetProcessHeap(), 0, req
->lpszUrl
);
2899 HeapFree(GetProcessHeap(), 0, req
->lpszHeaders
);
2903 WININET_Release( workRequest
.hdr
);
2907 /***********************************************************************
2908 * INTERNET_GetResponseBuffer
2913 LPSTR
INTERNET_GetResponseBuffer(void)
2915 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
2917 return lpwite
->response
;
2920 /***********************************************************************
2921 * INTERNET_GetNextLine (internal)
2923 * Parse next line in directory string listing
2926 * Pointer to beginning of next line
2931 LPSTR
INTERNET_GetNextLine(INT nSocket
, LPDWORD dwLen
)
2935 BOOL bSuccess
= FALSE
;
2937 LPSTR lpszBuffer
= INTERNET_GetResponseBuffer();
2942 FD_SET(nSocket
, &infd
);
2943 tv
.tv_sec
=RESPONSE_TIMEOUT
;
2946 while (nRecv
< MAX_REPLY_LEN
)
2948 if (select(nSocket
+1,&infd
,NULL
,NULL
,&tv
) > 0)
2950 if (recv(nSocket
, &lpszBuffer
[nRecv
], 1, 0) <= 0)
2952 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS
);
2956 if (lpszBuffer
[nRecv
] == '\n')
2961 if (lpszBuffer
[nRecv
] != '\r')
2966 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT
);
2974 lpszBuffer
[nRecv
] = '\0';
2976 TRACE(":%d %s\n", nRecv
, lpszBuffer
);
2985 /***********************************************************************
2988 BOOL WINAPI
InternetQueryDataAvailable( HINTERNET hFile
,
2989 LPDWORD lpdwNumberOfBytesAvailble
,
2990 DWORD dwFlags
, DWORD dwConext
)
2992 LPWININETHTTPREQW lpwhr
;
2996 lpwhr
= (LPWININETHTTPREQW
) WININET_GetObject( hFile
);
2999 SetLastError(ERROR_NO_MORE_FILES
);
3003 TRACE("--> %p %i\n",lpwhr
,lpwhr
->hdr
.htype
);
3005 switch (lpwhr
->hdr
.htype
)
3008 if (!NETCON_recv(&lpwhr
->netConnection
, buffer
,
3009 4048, MSG_PEEK
, (int *)lpdwNumberOfBytesAvailble
))
3011 SetLastError(ERROR_NO_MORE_FILES
);
3019 FIXME("unsupported file type\n");
3022 WININET_Release( &lpwhr
->hdr
);
3024 TRACE("<-- %i\n",retval
);
3029 /***********************************************************************
3032 BOOL WINAPI
InternetLockRequestFile( HINTERNET hInternet
, HANDLE
3039 BOOL WINAPI
InternetUnlockRequestFile( HANDLE hLockHandle
)
3046 /***********************************************************************
3049 * On windows this function is supposed to dial the default internet
3050 * connection. We don't want to have Wine dial out to the internet so
3051 * we return TRUE by default. It might be nice to check if we are connected.
3058 BOOL WINAPI
InternetAutodial(DWORD dwFlags
, HWND hwndParent
)
3062 /* Tell that we are connected to the internet. */
3066 /***********************************************************************
3067 * InternetAutodialHangup
3069 * Hangs up an connection made with InternetAutodial
3078 BOOL WINAPI
InternetAutodialHangup(DWORD dwReserved
)
3082 /* we didn't dial, we don't disconnect */
3086 /***********************************************************************
3088 * InternetCombineUrlA
3090 * Combine a base URL with a relative URL
3098 BOOL WINAPI
InternetCombineUrlA(LPCSTR lpszBaseUrl
, LPCSTR lpszRelativeUrl
,
3099 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3104 TRACE("(%s, %s, %p, %p, 0x%08lx)\n", debugstr_a(lpszBaseUrl
), debugstr_a(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3106 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3107 dwFlags
^= ICU_NO_ENCODE
;
3108 hr
=UrlCombineA(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3113 /***********************************************************************
3115 * InternetCombineUrlW
3117 * Combine a base URL with a relative URL
3125 BOOL WINAPI
InternetCombineUrlW(LPCWSTR lpszBaseUrl
, LPCWSTR lpszRelativeUrl
,
3126 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3131 TRACE("(%s, %s, %p, %p, 0x%08lx)\n", debugstr_w(lpszBaseUrl
), debugstr_w(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3133 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3134 dwFlags
^= ICU_NO_ENCODE
;
3135 hr
=UrlCombineW(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3140 /***********************************************************************
3142 * InternetCreateUrlA
3149 BOOL WINAPI
InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents
, DWORD dwFlags
,
3150 LPSTR lpszUrl
, LPDWORD lpdwUrlLength
)
3156 /***********************************************************************
3158 * InternetCreateUrlW
3165 BOOL WINAPI
InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents
, DWORD dwFlags
,
3166 LPWSTR lpszUrl
, LPDWORD lpdwUrlLength
)
3172 /***********************************************************************
3173 * dump_INTERNET_FLAGS
3175 * Helper function to TRACE the internet flags.
3181 void dump_INTERNET_FLAGS(DWORD dwFlags
)
3183 #define FE(x) { x, #x }
3184 static const wininet_flag_info flag
[] = {
3185 FE(INTERNET_FLAG_RELOAD
),
3186 FE(INTERNET_FLAG_RAW_DATA
),
3187 FE(INTERNET_FLAG_EXISTING_CONNECT
),
3188 FE(INTERNET_FLAG_ASYNC
),
3189 FE(INTERNET_FLAG_PASSIVE
),
3190 FE(INTERNET_FLAG_NO_CACHE_WRITE
),
3191 FE(INTERNET_FLAG_MAKE_PERSISTENT
),
3192 FE(INTERNET_FLAG_FROM_CACHE
),
3193 FE(INTERNET_FLAG_SECURE
),
3194 FE(INTERNET_FLAG_KEEP_CONNECTION
),
3195 FE(INTERNET_FLAG_NO_AUTO_REDIRECT
),
3196 FE(INTERNET_FLAG_READ_PREFETCH
),
3197 FE(INTERNET_FLAG_NO_COOKIES
),
3198 FE(INTERNET_FLAG_NO_AUTH
),
3199 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL
),
3200 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP
),
3201 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS
),
3202 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID
),
3203 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID
),
3204 FE(INTERNET_FLAG_RESYNCHRONIZE
),
3205 FE(INTERNET_FLAG_HYPERLINK
),
3206 FE(INTERNET_FLAG_NO_UI
),
3207 FE(INTERNET_FLAG_PRAGMA_NOCACHE
),
3208 FE(INTERNET_FLAG_CACHE_ASYNC
),
3209 FE(INTERNET_FLAG_FORMS_SUBMIT
),
3210 FE(INTERNET_FLAG_NEED_FILE
),
3211 FE(INTERNET_FLAG_TRANSFER_ASCII
),
3212 FE(INTERNET_FLAG_TRANSFER_BINARY
)
3217 for (i
= 0; i
< (sizeof(flag
) / sizeof(flag
[0])); i
++) {
3218 if (flag
[i
].val
& dwFlags
) {
3219 TRACE(" %s", flag
[i
].name
);
3220 dwFlags
&= ~flag
[i
].val
;
3224 TRACE(" Unknown flags (%08lx)\n", dwFlags
);