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>
57 #include "wine/debug.h"
59 #define NO_SHLWAPI_STREAM
62 #include "wine/exception.h"
68 #include "wine/unicode.h"
70 WINE_DEFAULT_DEBUG_CHANNEL(wininet
);
72 #define MAX_IDLE_WORKER 1000*60*1
73 #define MAX_WORKER_THREADS 10
74 #define RESPONSE_TIMEOUT 30
76 #define GET_HWININET_FROM_LPWININETFINDNEXT(lpwh) \
77 (LPWININETAPPINFOW)(((LPWININETFTPSESSIONW)(lpwh->hdr.lpwhparent))->hdr.lpwhparent)
83 CHAR response
[MAX_REPLY_LEN
];
84 } WITHREADERROR
, *LPWITHREADERROR
;
86 static VOID
INTERNET_CloseHandle(LPWININETHANDLEHEADER hdr
);
87 BOOL WINAPI
INTERNET_FindNextFileW(LPWININETFINDNEXTW lpwh
, LPVOID lpvFindData
);
88 HINTERNET WINAPI
INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC
, LPCWSTR lpszUrl
,
89 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD dwContext
);
90 static VOID
INTERNET_ExecuteWork(void);
92 static DWORD g_dwTlsErrIndex
= TLS_OUT_OF_INDEXES
;
93 static LONG dwNumThreads
;
94 static LONG dwNumIdleThreads
;
95 static LONG dwNumJobs
;
96 static HANDLE hEventArray
[2];
97 #define hQuitEvent hEventArray[0]
98 #define hWorkEvent hEventArray[1]
99 static CRITICAL_SECTION csQueue
;
100 static LPWORKREQUEST lpHeadWorkQueue
;
101 static LPWORKREQUEST lpWorkQueueTail
;
102 static HMODULE WININET_hModule
;
104 #define HANDLE_CHUNK_SIZE 0x10
106 static CRITICAL_SECTION WININET_cs
;
107 static CRITICAL_SECTION_DEBUG WININET_cs_debug
=
110 { &WININET_cs_debug
.ProcessLocksList
, &WININET_cs_debug
.ProcessLocksList
},
111 0, 0, { (DWORD_PTR
)(__FILE__
": WININET_cs") }
113 static CRITICAL_SECTION WININET_cs
= { &WININET_cs_debug
, -1, 0, 0, 0, 0 };
115 static LPWININETHANDLEHEADER
*WININET_Handles
;
116 static UINT WININET_dwNextHandle
;
117 static UINT WININET_dwMaxHandles
;
119 HINTERNET
WININET_AllocHandle( LPWININETHANDLEHEADER info
)
121 LPWININETHANDLEHEADER
*p
;
122 UINT handle
= 0, num
;
124 EnterCriticalSection( &WININET_cs
);
125 if( !WININET_dwMaxHandles
)
127 num
= HANDLE_CHUNK_SIZE
;
128 p
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
133 WININET_dwMaxHandles
= num
;
135 if( WININET_dwMaxHandles
== WININET_dwNextHandle
)
137 num
= WININET_dwMaxHandles
+ HANDLE_CHUNK_SIZE
;
138 p
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
139 WININET_Handles
, sizeof (UINT
)* num
);
143 WININET_dwMaxHandles
= num
;
146 handle
= WININET_dwNextHandle
;
147 if( WININET_Handles
[handle
] )
148 ERR("handle isn't free but should be\n");
149 WININET_Handles
[handle
] = WININET_AddRef( info
);
151 while( WININET_Handles
[WININET_dwNextHandle
] &&
152 (WININET_dwNextHandle
< WININET_dwMaxHandles
) )
153 WININET_dwNextHandle
++;
156 LeaveCriticalSection( &WININET_cs
);
158 return (HINTERNET
) (handle
+1);
161 HINTERNET
WININET_FindHandle( LPWININETHANDLEHEADER info
)
165 EnterCriticalSection( &WININET_cs
);
166 for( i
=0; i
<WININET_dwMaxHandles
; i
++ )
168 if( info
== WININET_Handles
[i
] )
170 WININET_AddRef( info
);
175 LeaveCriticalSection( &WININET_cs
);
177 return (HINTERNET
) handle
;
180 LPWININETHANDLEHEADER
WININET_AddRef( LPWININETHANDLEHEADER info
)
183 TRACE("%p -> refcount = %ld\n", info
, info
->dwRefCount
);
187 LPWININETHANDLEHEADER
WININET_GetObject( HINTERNET hinternet
)
189 LPWININETHANDLEHEADER info
= NULL
;
190 UINT handle
= (UINT
) hinternet
;
192 EnterCriticalSection( &WININET_cs
);
194 if( (handle
> 0) && ( handle
<= WININET_dwMaxHandles
) &&
195 WININET_Handles
[handle
-1] )
196 info
= WININET_AddRef( WININET_Handles
[handle
-1] );
198 LeaveCriticalSection( &WININET_cs
);
200 TRACE("handle %d -> %p\n", handle
, info
);
205 BOOL
WININET_Release( LPWININETHANDLEHEADER info
)
208 TRACE( "object %p refcount = %ld\n", info
, info
->dwRefCount
);
209 if( !info
->dwRefCount
)
211 TRACE( "destroying object %p\n", info
);
212 info
->destroy( info
);
217 BOOL
WININET_FreeHandle( HINTERNET hinternet
)
220 UINT handle
= (UINT
) hinternet
;
221 LPWININETHANDLEHEADER info
= NULL
;
223 EnterCriticalSection( &WININET_cs
);
225 if( (handle
> 0) && ( handle
<= WININET_dwMaxHandles
) )
228 if( WININET_Handles
[handle
] )
230 info
= WININET_Handles
[handle
];
231 TRACE( "destroying handle %d for object %p\n", handle
+1, info
);
232 WININET_Handles
[handle
] = NULL
;
234 if( WININET_dwNextHandle
> handle
)
235 WININET_dwNextHandle
= handle
;
239 LeaveCriticalSection( &WININET_cs
);
242 WININET_Release( info
);
247 /***********************************************************************
248 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
251 * hinstDLL [I] handle to the DLL's instance
253 * lpvReserved [I] reserved, must be NULL
260 BOOL WINAPI
DllMain (HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
262 TRACE("%p,%lx,%p\n", hinstDLL
, fdwReason
, lpvReserved
);
265 case DLL_PROCESS_ATTACH
:
267 g_dwTlsErrIndex
= TlsAlloc();
269 if (g_dwTlsErrIndex
== TLS_OUT_OF_INDEXES
)
272 hQuitEvent
= CreateEventW(0, TRUE
, FALSE
, NULL
);
273 hWorkEvent
= CreateEventW(0, FALSE
, FALSE
, NULL
);
274 InitializeCriticalSection(&csQueue
);
276 URLCacheContainers_CreateDefaults();
279 dwNumIdleThreads
= 0;
282 WININET_hModule
= (HMODULE
)hinstDLL
;
284 case DLL_THREAD_ATTACH
:
286 LPWITHREADERROR lpwite
= HeapAlloc(GetProcessHeap(), 0, sizeof(WITHREADERROR
));
290 TlsSetValue(g_dwTlsErrIndex
, (LPVOID
)lpwite
);
294 case DLL_THREAD_DETACH
:
295 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
297 LPVOID lpwite
= TlsGetValue(g_dwTlsErrIndex
);
298 HeapFree(GetProcessHeap(), 0, lpwite
);
302 case DLL_PROCESS_DETACH
:
304 URLCacheContainers_DeleteAll();
306 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
308 HeapFree(GetProcessHeap(), 0, TlsGetValue(g_dwTlsErrIndex
));
309 TlsFree(g_dwTlsErrIndex
);
312 SetEvent(hQuitEvent
);
314 CloseHandle(hQuitEvent
);
315 CloseHandle(hWorkEvent
);
316 DeleteCriticalSection(&csQueue
);
324 /***********************************************************************
325 * InternetInitializeAutoProxyDll (WININET.@)
327 * Setup the internal proxy
336 BOOL WINAPI
InternetInitializeAutoProxyDll(DWORD dwReserved
)
339 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
343 /***********************************************************************
344 * DetectAutoProxyUrl (WININET.@)
346 * Auto detect the proxy url
352 BOOL WINAPI
DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl
,
353 DWORD dwAutoProxyUrlLength
, DWORD dwDetectFlags
)
356 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
361 /***********************************************************************
362 * INTERNET_ConfigureProxyFromReg
365 * The proxy may be specified in the form 'http=proxy.my.org'
366 * Presumably that means there can be ftp=ftpproxy.my.org too.
368 static BOOL
INTERNET_ConfigureProxyFromReg( LPWININETAPPINFOW lpwai
)
371 DWORD r
, keytype
, len
, enabled
;
372 LPCSTR lpszInternetSettings
=
373 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
374 static const WCHAR szProxyServer
[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
376 r
= RegOpenKeyA(HKEY_CURRENT_USER
, lpszInternetSettings
, &key
);
377 if ( r
!= ERROR_SUCCESS
)
380 len
= sizeof enabled
;
381 r
= RegQueryValueExA( key
, "ProxyEnable", NULL
, &keytype
,
382 (BYTE
*)&enabled
, &len
);
383 if( (r
== ERROR_SUCCESS
) && enabled
)
385 TRACE("Proxy is enabled.\n");
387 /* figure out how much memory the proxy setting takes */
388 r
= RegQueryValueExW( key
, szProxyServer
, NULL
, &keytype
,
390 if( (r
== ERROR_SUCCESS
) && len
&& (keytype
== REG_SZ
) )
393 static const WCHAR szHttp
[] = {'h','t','t','p','=',0};
395 szProxy
=HeapAlloc( GetProcessHeap(), 0, len
);
396 RegQueryValueExW( key
, szProxyServer
, NULL
, &keytype
,
397 (BYTE
*)szProxy
, &len
);
399 /* find the http proxy, and strip away everything else */
400 p
= strstrW( szProxy
, szHttp
);
403 p
+= lstrlenW(szHttp
);
404 lstrcpyW( szProxy
, p
);
406 p
= strchrW( szProxy
, ' ' );
410 lpwai
->dwAccessType
= INTERNET_OPEN_TYPE_PROXY
;
411 lpwai
->lpszProxy
= szProxy
;
413 TRACE("http proxy = %s\n", debugstr_w(lpwai
->lpszProxy
));
416 ERR("Couldn't read proxy server settings.\n");
419 TRACE("Proxy is not enabled.\n");
425 /***********************************************************************
426 * dump_INTERNET_FLAGS
428 * Helper function to TRACE the internet flags.
434 static void dump_INTERNET_FLAGS(DWORD dwFlags
)
436 #define FE(x) { x, #x }
437 static const wininet_flag_info flag
[] = {
438 FE(INTERNET_FLAG_RELOAD
),
439 FE(INTERNET_FLAG_RAW_DATA
),
440 FE(INTERNET_FLAG_EXISTING_CONNECT
),
441 FE(INTERNET_FLAG_ASYNC
),
442 FE(INTERNET_FLAG_PASSIVE
),
443 FE(INTERNET_FLAG_NO_CACHE_WRITE
),
444 FE(INTERNET_FLAG_MAKE_PERSISTENT
),
445 FE(INTERNET_FLAG_FROM_CACHE
),
446 FE(INTERNET_FLAG_SECURE
),
447 FE(INTERNET_FLAG_KEEP_CONNECTION
),
448 FE(INTERNET_FLAG_NO_AUTO_REDIRECT
),
449 FE(INTERNET_FLAG_READ_PREFETCH
),
450 FE(INTERNET_FLAG_NO_COOKIES
),
451 FE(INTERNET_FLAG_NO_AUTH
),
452 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL
),
453 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP
),
454 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS
),
455 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID
),
456 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID
),
457 FE(INTERNET_FLAG_RESYNCHRONIZE
),
458 FE(INTERNET_FLAG_HYPERLINK
),
459 FE(INTERNET_FLAG_NO_UI
),
460 FE(INTERNET_FLAG_PRAGMA_NOCACHE
),
461 FE(INTERNET_FLAG_CACHE_ASYNC
),
462 FE(INTERNET_FLAG_FORMS_SUBMIT
),
463 FE(INTERNET_FLAG_NEED_FILE
),
464 FE(INTERNET_FLAG_TRANSFER_ASCII
),
465 FE(INTERNET_FLAG_TRANSFER_BINARY
)
470 for (i
= 0; i
< (sizeof(flag
) / sizeof(flag
[0])); i
++) {
471 if (flag
[i
].val
& dwFlags
) {
472 TRACE(" %s", flag
[i
].name
);
473 dwFlags
&= ~flag
[i
].val
;
477 TRACE(" Unknown flags (%08lx)\n", dwFlags
);
482 /***********************************************************************
483 * InternetOpenW (WININET.@)
485 * Per-application initialization of wininet
488 * HINTERNET on success
492 HINTERNET WINAPI
InternetOpenW(LPCWSTR lpszAgent
, DWORD dwAccessType
,
493 LPCWSTR lpszProxy
, LPCWSTR lpszProxyBypass
, DWORD dwFlags
)
495 LPWININETAPPINFOW lpwai
= NULL
;
496 HINTERNET handle
= NULL
;
498 if (TRACE_ON(wininet
)) {
499 #define FE(x) { x, #x }
500 static const wininet_flag_info access_type
[] = {
501 FE(INTERNET_OPEN_TYPE_PRECONFIG
),
502 FE(INTERNET_OPEN_TYPE_DIRECT
),
503 FE(INTERNET_OPEN_TYPE_PROXY
),
504 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY
)
508 const char *access_type_str
= "Unknown";
510 TRACE("(%s, %li, %s, %s, %li)\n", debugstr_w(lpszAgent
), dwAccessType
,
511 debugstr_w(lpszProxy
), debugstr_w(lpszProxyBypass
), dwFlags
);
512 for (i
= 0; i
< (sizeof(access_type
) / sizeof(access_type
[0])); i
++) {
513 if (access_type
[i
].val
== dwAccessType
) {
514 access_type_str
= access_type
[i
].name
;
518 TRACE(" access type : %s\n", access_type_str
);
520 dump_INTERNET_FLAGS(dwFlags
);
523 /* Clear any error information */
524 INTERNET_SetLastError(0);
526 lpwai
= HeapAlloc(GetProcessHeap(), 0, sizeof(WININETAPPINFOW
));
529 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
533 memset(lpwai
, 0, sizeof(WININETAPPINFOW
));
534 lpwai
->hdr
.htype
= WH_HINIT
;
535 lpwai
->hdr
.lpwhparent
= NULL
;
536 lpwai
->hdr
.dwFlags
= dwFlags
;
537 lpwai
->hdr
.dwRefCount
= 1;
538 lpwai
->hdr
.destroy
= INTERNET_CloseHandle
;
539 lpwai
->dwAccessType
= dwAccessType
;
540 lpwai
->lpszProxyUsername
= NULL
;
541 lpwai
->lpszProxyPassword
= NULL
;
543 handle
= WININET_AllocHandle( &lpwai
->hdr
);
546 HeapFree( GetProcessHeap(), 0, lpwai
);
547 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
551 if (NULL
!= lpszAgent
)
553 lpwai
->lpszAgent
= HeapAlloc( GetProcessHeap(),0,
554 (strlenW(lpszAgent
)+1)*sizeof(WCHAR
));
555 if (lpwai
->lpszAgent
)
556 lstrcpyW( lpwai
->lpszAgent
, lpszAgent
);
558 if(dwAccessType
== INTERNET_OPEN_TYPE_PRECONFIG
)
559 INTERNET_ConfigureProxyFromReg( lpwai
);
560 else if (NULL
!= lpszProxy
)
562 lpwai
->lpszProxy
= HeapAlloc( GetProcessHeap(), 0,
563 (strlenW(lpszProxy
)+1)*sizeof(WCHAR
));
564 if (lpwai
->lpszProxy
)
565 lstrcpyW( lpwai
->lpszProxy
, lpszProxy
);
568 if (NULL
!= lpszProxyBypass
)
570 lpwai
->lpszProxyBypass
= HeapAlloc( GetProcessHeap(), 0,
571 (strlenW(lpszProxyBypass
)+1)*sizeof(WCHAR
));
572 if (lpwai
->lpszProxyBypass
)
573 lstrcpyW( lpwai
->lpszProxyBypass
, lpszProxyBypass
);
578 WININET_Release( &lpwai
->hdr
);
580 TRACE("returning %p\n", lpwai
);
586 /***********************************************************************
587 * InternetOpenA (WININET.@)
589 * Per-application initialization of wininet
592 * HINTERNET on success
596 HINTERNET WINAPI
InternetOpenA(LPCSTR lpszAgent
, DWORD dwAccessType
,
597 LPCSTR lpszProxy
, LPCSTR lpszProxyBypass
, DWORD dwFlags
)
599 HINTERNET rc
= (HINTERNET
)NULL
;
601 WCHAR
*szAgent
= NULL
, *szProxy
= NULL
, *szBypass
= NULL
;
603 TRACE("(%s, 0x%08lx, %s, %s, 0x%08lx)\n", debugstr_a(lpszAgent
),
604 dwAccessType
, debugstr_a(lpszProxy
), debugstr_a(lpszProxyBypass
), dwFlags
);
608 len
= MultiByteToWideChar(CP_ACP
, 0, lpszAgent
, -1, NULL
, 0);
609 szAgent
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
610 MultiByteToWideChar(CP_ACP
, 0, lpszAgent
, -1, szAgent
, len
);
615 len
= MultiByteToWideChar(CP_ACP
, 0, lpszProxy
, -1, NULL
, 0);
616 szProxy
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
617 MultiByteToWideChar(CP_ACP
, 0, lpszProxy
, -1, szProxy
, len
);
620 if( lpszProxyBypass
)
622 len
= MultiByteToWideChar(CP_ACP
, 0, lpszProxyBypass
, -1, NULL
, 0);
623 szBypass
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
624 MultiByteToWideChar(CP_ACP
, 0, lpszProxyBypass
, -1, szBypass
, len
);
627 rc
= InternetOpenW(szAgent
, dwAccessType
, szProxy
, szBypass
, dwFlags
);
629 HeapFree(GetProcessHeap(), 0, szAgent
);
630 HeapFree(GetProcessHeap(), 0, szProxy
);
631 HeapFree(GetProcessHeap(), 0, szBypass
);
636 /***********************************************************************
637 * InternetGetLastResponseInfoA (WININET.@)
639 * Return last wininet error description on the calling thread
642 * TRUE on success of writing to buffer
646 BOOL WINAPI
InternetGetLastResponseInfoA(LPDWORD lpdwError
,
647 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
649 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
653 *lpdwError
= lpwite
->dwError
;
656 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
657 *lpdwBufferLength
= strlen(lpszBuffer
);
660 *lpdwBufferLength
= 0;
665 /***********************************************************************
666 * InternetGetLastResponseInfoW (WININET.@)
668 * Return last wininet error description on the calling thread
671 * TRUE on success of writing to buffer
675 BOOL WINAPI
InternetGetLastResponseInfoW(LPDWORD lpdwError
,
676 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
678 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
682 *lpdwError
= lpwite
->dwError
;
685 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
686 *lpdwBufferLength
= lstrlenW(lpszBuffer
);
689 *lpdwBufferLength
= 0;
694 /***********************************************************************
695 * InternetGetConnectedState (WININET.@)
697 * Return connected state
701 * if lpdwStatus is not null, return the status (off line,
702 * modem, lan...) in it.
703 * FALSE if not connected
705 BOOL WINAPI
InternetGetConnectedState(LPDWORD lpdwStatus
, DWORD dwReserved
)
707 TRACE("(%p, 0x%08lx)\n", lpdwStatus
, dwReserved
);
710 FIXME("always returning LAN connection.\n");
711 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
717 /***********************************************************************
718 * InternetGetConnectedStateExW (WININET.@)
720 * Return connected state
724 * lpdwStatus [O] Flags specifying the status of the internet connection.
725 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
726 * dwNameLen [I] Size of the buffer, in characters.
727 * dwReserved [I] Reserved. Must be set to 0.
731 * if lpdwStatus is not null, return the status (off line,
732 * modem, lan...) in it.
733 * FALSE if not connected
736 * If the system has no available network connections, an empty string is
737 * stored in lpszConnectionName. If there is a LAN connection, a localized
738 * "LAN Connection" string is stored. Presumably, if only a dial-up
739 * connection is available then the name of the dial-up connection is
740 * returned. Why any application, other than the "Internet Settings" CPL,
741 * would want to use this function instead of the simpler InternetGetConnectedStateW
742 * function is beyond me.
744 BOOL WINAPI
InternetGetConnectedStateExW(LPDWORD lpdwStatus
, LPWSTR lpszConnectionName
,
745 DWORD dwNameLen
, DWORD dwReserved
)
747 TRACE("(%p, %p, %ld, 0x%08lx)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
754 FIXME("always returning LAN connection.\n");
755 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
757 return LoadStringW(WININET_hModule
, IDS_LANCONNECTION
, lpszConnectionName
, dwNameLen
);
761 /***********************************************************************
762 * InternetGetConnectedStateExA (WININET.@)
764 BOOL WINAPI
InternetGetConnectedStateExA(LPDWORD lpdwStatus
, LPSTR lpszConnectionName
,
765 DWORD dwNameLen
, DWORD dwReserved
)
767 LPWSTR lpwszConnectionName
= NULL
;
770 TRACE("(%p, %p, %ld, 0x%08lx)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
772 if (lpszConnectionName
&& dwNameLen
> 0)
773 lpwszConnectionName
= HeapAlloc(GetProcessHeap(), 0, dwNameLen
* sizeof(WCHAR
));
775 rc
= InternetGetConnectedStateExW(lpdwStatus
,lpwszConnectionName
, dwNameLen
,
777 if (rc
&& lpwszConnectionName
)
779 WideCharToMultiByte(CP_ACP
,0,lpwszConnectionName
,-1,lpszConnectionName
,
780 dwNameLen
, NULL
, NULL
);
782 HeapFree(GetProcessHeap(),0,lpwszConnectionName
);
789 /***********************************************************************
790 * InternetConnectW (WININET.@)
792 * Open a ftp, gopher or http session
795 * HINTERNET a session handle on success
799 HINTERNET WINAPI
InternetConnectW(HINTERNET hInternet
,
800 LPCWSTR lpszServerName
, INTERNET_PORT nServerPort
,
801 LPCWSTR lpszUserName
, LPCWSTR lpszPassword
,
802 DWORD dwService
, DWORD dwFlags
, DWORD dwContext
)
804 LPWININETAPPINFOW hIC
;
805 HINTERNET rc
= (HINTERNET
) NULL
;
807 TRACE("(%p, %s, %i, %s, %s, %li, %li, %li)\n", hInternet
, debugstr_w(lpszServerName
),
808 nServerPort
, debugstr_w(lpszUserName
), debugstr_w(lpszPassword
),
809 dwService
, dwFlags
, dwContext
);
811 /* Clear any error information */
812 INTERNET_SetLastError(0);
813 hIC
= (LPWININETAPPINFOW
) WININET_GetObject( hInternet
);
814 if ( (hIC
== NULL
) || (hIC
->hdr
.htype
!= WH_HINIT
) )
819 case INTERNET_SERVICE_FTP
:
820 rc
= FTP_Connect(hIC
, lpszServerName
, nServerPort
,
821 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
824 case INTERNET_SERVICE_HTTP
:
825 rc
= HTTP_Connect(hIC
, lpszServerName
, nServerPort
,
826 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
829 case INTERNET_SERVICE_GOPHER
:
835 WININET_Release( &hIC
->hdr
);
837 TRACE("returning %p\n", rc
);
842 /***********************************************************************
843 * InternetConnectA (WININET.@)
845 * Open a ftp, gopher or http session
848 * HINTERNET a session handle on success
852 HINTERNET WINAPI
InternetConnectA(HINTERNET hInternet
,
853 LPCSTR lpszServerName
, INTERNET_PORT nServerPort
,
854 LPCSTR lpszUserName
, LPCSTR lpszPassword
,
855 DWORD dwService
, DWORD dwFlags
, DWORD dwContext
)
857 HINTERNET rc
= (HINTERNET
)NULL
;
859 LPWSTR szServerName
= NULL
;
860 LPWSTR szUserName
= NULL
;
861 LPWSTR szPassword
= NULL
;
865 len
= MultiByteToWideChar(CP_ACP
, 0, lpszServerName
, -1, NULL
, 0);
866 szServerName
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
867 MultiByteToWideChar(CP_ACP
, 0, lpszServerName
, -1, szServerName
, len
);
871 len
= MultiByteToWideChar(CP_ACP
, 0, lpszUserName
, -1, NULL
, 0);
872 szUserName
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
873 MultiByteToWideChar(CP_ACP
, 0, lpszUserName
, -1, szUserName
, len
);
877 len
= MultiByteToWideChar(CP_ACP
, 0, lpszPassword
, -1, NULL
, 0);
878 szPassword
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
879 MultiByteToWideChar(CP_ACP
, 0, lpszPassword
, -1, szPassword
, len
);
883 rc
= InternetConnectW(hInternet
, szServerName
, nServerPort
,
884 szUserName
, szPassword
, dwService
, dwFlags
, dwContext
);
886 HeapFree(GetProcessHeap(), 0, szServerName
);
887 HeapFree(GetProcessHeap(), 0, szUserName
);
888 HeapFree(GetProcessHeap(), 0, szPassword
);
893 /***********************************************************************
894 * InternetFindNextFileA (WININET.@)
896 * Continues a file search from a previous call to FindFirstFile
903 BOOL WINAPI
InternetFindNextFileA(HINTERNET hFind
, LPVOID lpvFindData
)
908 ret
= InternetFindNextFileW(hFind
, lpvFindData
?&fd
:NULL
);
910 WININET_find_data_WtoA(&fd
, (LPWIN32_FIND_DATAA
)lpvFindData
);
914 /***********************************************************************
915 * InternetFindNextFileW (WININET.@)
917 * Continues a file search from a previous call to FindFirstFile
924 BOOL WINAPI
InternetFindNextFileW(HINTERNET hFind
, LPVOID lpvFindData
)
926 LPWININETAPPINFOW hIC
= NULL
;
927 LPWININETFINDNEXTW lpwh
;
928 BOOL bSuccess
= FALSE
;
932 lpwh
= (LPWININETFINDNEXTW
) WININET_GetObject( hFind
);
933 if (NULL
== lpwh
|| lpwh
->hdr
.htype
!= WH_HFINDNEXT
)
935 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
939 hIC
= GET_HWININET_FROM_LPWININETFINDNEXT(lpwh
);
940 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
)
942 WORKREQUEST workRequest
;
943 struct WORKREQ_INTERNETFINDNEXTW
*req
;
945 workRequest
.asyncall
= INTERNETFINDNEXTW
;
946 workRequest
.hdr
= WININET_AddRef( &lpwh
->hdr
);
947 req
= &workRequest
.u
.InternetFindNextW
;
948 req
->lpFindFileData
= lpvFindData
;
950 bSuccess
= INTERNET_AsyncCall(&workRequest
);
954 bSuccess
= INTERNET_FindNextFileW(lpwh
, lpvFindData
);
958 WININET_Release( &lpwh
->hdr
);
962 /***********************************************************************
963 * INTERNET_FindNextFileW (Internal)
965 * Continues a file search from a previous call to FindFirstFile
972 BOOL WINAPI
INTERNET_FindNextFileW(LPWININETFINDNEXTW lpwh
, LPVOID lpvFindData
)
974 BOOL bSuccess
= TRUE
;
975 LPWIN32_FIND_DATAW lpFindFileData
;
979 assert (lpwh
->hdr
.htype
== WH_HFINDNEXT
);
981 /* Clear any error information */
982 INTERNET_SetLastError(0);
984 if (lpwh
->hdr
.lpwhparent
->htype
!= WH_HFTPSESSION
)
986 FIXME("Only FTP find next supported\n");
987 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
991 TRACE("index(%ld) size(%ld)\n", lpwh
->index
, lpwh
->size
);
993 lpFindFileData
= (LPWIN32_FIND_DATAW
) lpvFindData
;
994 ZeroMemory(lpFindFileData
, sizeof(WIN32_FIND_DATAA
));
996 if (lpwh
->index
>= lpwh
->size
)
998 INTERNET_SetLastError(ERROR_NO_MORE_FILES
);
1003 FTP_ConvertFileProp(&lpwh
->lpafp
[lpwh
->index
], lpFindFileData
);
1006 TRACE("\nName: %s\nSize: %ld\n", debugstr_w(lpFindFileData
->cFileName
), lpFindFileData
->nFileSizeLow
);
1010 if (lpwh
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
)
1012 INTERNET_ASYNC_RESULT iar
;
1014 iar
.dwResult
= (DWORD
)bSuccess
;
1015 iar
.dwError
= iar
.dwError
= bSuccess
? ERROR_SUCCESS
:
1016 INTERNET_GetLastError();
1018 INTERNET_SendCallback(&lpwh
->hdr
, lpwh
->hdr
.dwContext
,
1019 INTERNET_STATUS_REQUEST_COMPLETE
, &iar
,
1020 sizeof(INTERNET_ASYNC_RESULT
));
1027 /***********************************************************************
1028 * INTERNET_CloseHandle (internal)
1030 * Close internet handle
1036 static VOID
INTERNET_CloseHandle(LPWININETHANDLEHEADER hdr
)
1038 LPWININETAPPINFOW lpwai
= (LPWININETAPPINFOW
) hdr
;
1040 TRACE("%p\n",lpwai
);
1042 HeapFree(GetProcessHeap(), 0, lpwai
->lpszAgent
);
1043 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxy
);
1044 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxyBypass
);
1045 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxyUsername
);
1046 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxyPassword
);
1047 HeapFree(GetProcessHeap(), 0, lpwai
);
1051 /***********************************************************************
1052 * InternetCloseHandle (WININET.@)
1054 * Generic close handle function
1061 BOOL WINAPI
InternetCloseHandle(HINTERNET hInternet
)
1063 LPWININETHANDLEHEADER lpwh
;
1065 TRACE("%p\n",hInternet
);
1067 lpwh
= WININET_GetObject( hInternet
);
1070 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
1074 /* FIXME: native appears to send this from the equivalent of
1075 * WININET_Release */
1076 INTERNET_SendCallback(lpwh
, lpwh
->dwContext
,
1077 INTERNET_STATUS_HANDLE_CLOSING
, &hInternet
,
1080 if( lpwh
->lpwhparent
)
1081 WININET_Release( lpwh
->lpwhparent
);
1082 WININET_FreeHandle( hInternet
);
1083 WININET_Release( lpwh
);
1089 /***********************************************************************
1090 * ConvertUrlComponentValue (Internal)
1092 * Helper function for InternetCrackUrlW
1095 static void ConvertUrlComponentValue(LPSTR
* lppszComponent
, LPDWORD dwComponentLen
,
1096 LPWSTR lpwszComponent
, DWORD dwwComponentLen
,
1097 LPCSTR lpszStart
, LPCWSTR lpwszStart
)
1099 TRACE("%p %p %p %ld %p %p\n", lppszComponent
, dwComponentLen
, lpwszComponent
, dwwComponentLen
, lpszStart
, lpwszStart
);
1100 if (*dwComponentLen
!= 0)
1102 DWORD nASCIILength
=WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,NULL
,0,NULL
,NULL
);
1103 if (*lppszComponent
== NULL
)
1105 int nASCIIOffset
=WideCharToMultiByte(CP_ACP
,0,lpwszStart
,lpwszComponent
-lpwszStart
,NULL
,0,NULL
,NULL
);
1106 *lppszComponent
= (LPSTR
)lpszStart
+nASCIIOffset
;
1107 *dwComponentLen
= nASCIILength
;
1111 DWORD ncpylen
= min((*dwComponentLen
)-1, nASCIILength
);
1112 WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,*lppszComponent
,ncpylen
+1,NULL
,NULL
);
1113 (*lppszComponent
)[ncpylen
]=0;
1114 *dwComponentLen
= ncpylen
;
1120 /***********************************************************************
1121 * InternetCrackUrlA (WININET.@)
1123 * Break up URL into its components
1125 * TODO: Handle dwFlags
1132 BOOL WINAPI
InternetCrackUrlA(LPCSTR lpszUrl
, DWORD dwUrlLength
, DWORD dwFlags
,
1133 LPURL_COMPONENTSA lpUrlComponents
)
1136 URL_COMPONENTSW UCW
;
1139 TRACE("(%s %lu %lx %p)\n", debugstr_a(lpszUrl
), dwUrlLength
, dwFlags
, lpUrlComponents
);
1142 nLength
=MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,NULL
,0);
1144 /* if dwUrlLength=-1 then nLength includes null but length to
1145 InternetCrackUrlW should not include it */
1146 if (dwUrlLength
== -1) nLength
--;
1148 lpwszUrl
=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WCHAR
)*nLength
);
1149 MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,lpwszUrl
,nLength
);
1151 memset(&UCW
,0,sizeof(UCW
));
1152 if(lpUrlComponents
->dwHostNameLength
!=0)
1153 UCW
.dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
1154 if(lpUrlComponents
->dwUserNameLength
!=0)
1155 UCW
.dwUserNameLength
=lpUrlComponents
->dwUserNameLength
;
1156 if(lpUrlComponents
->dwPasswordLength
!=0)
1157 UCW
.dwPasswordLength
=lpUrlComponents
->dwPasswordLength
;
1158 if(lpUrlComponents
->dwUrlPathLength
!=0)
1159 UCW
.dwUrlPathLength
=lpUrlComponents
->dwUrlPathLength
;
1160 if(lpUrlComponents
->dwSchemeLength
!=0)
1161 UCW
.dwSchemeLength
=lpUrlComponents
->dwSchemeLength
;
1162 if(lpUrlComponents
->dwExtraInfoLength
!=0)
1163 UCW
.dwExtraInfoLength
=lpUrlComponents
->dwExtraInfoLength
;
1164 if(!InternetCrackUrlW(lpwszUrl
,nLength
,dwFlags
,&UCW
))
1166 HeapFree(GetProcessHeap(), 0, lpwszUrl
);
1170 ConvertUrlComponentValue(&lpUrlComponents
->lpszHostName
, &lpUrlComponents
->dwHostNameLength
,
1171 UCW
.lpszHostName
, UCW
.dwHostNameLength
,
1173 ConvertUrlComponentValue(&lpUrlComponents
->lpszUserName
, &lpUrlComponents
->dwUserNameLength
,
1174 UCW
.lpszUserName
, UCW
.dwUserNameLength
,
1176 ConvertUrlComponentValue(&lpUrlComponents
->lpszPassword
, &lpUrlComponents
->dwPasswordLength
,
1177 UCW
.lpszPassword
, UCW
.dwPasswordLength
,
1179 ConvertUrlComponentValue(&lpUrlComponents
->lpszUrlPath
, &lpUrlComponents
->dwUrlPathLength
,
1180 UCW
.lpszUrlPath
, UCW
.dwUrlPathLength
,
1182 ConvertUrlComponentValue(&lpUrlComponents
->lpszScheme
, &lpUrlComponents
->dwSchemeLength
,
1183 UCW
.lpszScheme
, UCW
.dwSchemeLength
,
1185 ConvertUrlComponentValue(&lpUrlComponents
->lpszExtraInfo
, &lpUrlComponents
->dwExtraInfoLength
,
1186 UCW
.lpszExtraInfo
, UCW
.dwExtraInfoLength
,
1188 lpUrlComponents
->nScheme
=UCW
.nScheme
;
1189 lpUrlComponents
->nPort
=UCW
.nPort
;
1190 HeapFree(GetProcessHeap(), 0, lpwszUrl
);
1192 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", lpszUrl
,
1193 debugstr_an(lpUrlComponents
->lpszScheme
,lpUrlComponents
->dwSchemeLength
),
1194 debugstr_an(lpUrlComponents
->lpszHostName
,lpUrlComponents
->dwHostNameLength
),
1195 debugstr_an(lpUrlComponents
->lpszUrlPath
,lpUrlComponents
->dwUrlPathLength
),
1196 debugstr_an(lpUrlComponents
->lpszExtraInfo
,lpUrlComponents
->dwExtraInfoLength
));
1201 /***********************************************************************
1202 * GetInternetSchemeW (internal)
1208 * INTERNET_SCHEME_UNKNOWN on failure
1211 static INTERNET_SCHEME
GetInternetSchemeW(LPCWSTR lpszScheme
, DWORD nMaxCmp
)
1213 INTERNET_SCHEME iScheme
=INTERNET_SCHEME_UNKNOWN
;
1214 static const WCHAR lpszFtp
[]={'f','t','p',0};
1215 static const WCHAR lpszGopher
[]={'g','o','p','h','e','r',0};
1216 static const WCHAR lpszHttp
[]={'h','t','t','p',0};
1217 static const WCHAR lpszHttps
[]={'h','t','t','p','s',0};
1218 static const WCHAR lpszFile
[]={'f','i','l','e',0};
1219 static const WCHAR lpszNews
[]={'n','e','w','s',0};
1220 static const WCHAR lpszMailto
[]={'m','a','i','l','t','o',0};
1221 static const WCHAR lpszRes
[]={'r','e','s',0};
1222 WCHAR
* tempBuffer
=NULL
;
1223 TRACE("%s %ld\n",debugstr_wn(lpszScheme
, nMaxCmp
), nMaxCmp
);
1224 if(lpszScheme
==NULL
)
1225 return INTERNET_SCHEME_UNKNOWN
;
1227 tempBuffer
=HeapAlloc(GetProcessHeap(),0,(nMaxCmp
+1)*sizeof(WCHAR
));
1228 lstrcpynW(tempBuffer
,lpszScheme
,nMaxCmp
+1);
1229 strlwrW(tempBuffer
);
1230 if (nMaxCmp
==strlenW(lpszFtp
) && !strncmpW(lpszFtp
, tempBuffer
, nMaxCmp
))
1231 iScheme
=INTERNET_SCHEME_FTP
;
1232 else if (nMaxCmp
==strlenW(lpszGopher
) && !strncmpW(lpszGopher
, tempBuffer
, nMaxCmp
))
1233 iScheme
=INTERNET_SCHEME_GOPHER
;
1234 else if (nMaxCmp
==strlenW(lpszHttp
) && !strncmpW(lpszHttp
, tempBuffer
, nMaxCmp
))
1235 iScheme
=INTERNET_SCHEME_HTTP
;
1236 else if (nMaxCmp
==strlenW(lpszHttps
) && !strncmpW(lpszHttps
, tempBuffer
, nMaxCmp
))
1237 iScheme
=INTERNET_SCHEME_HTTPS
;
1238 else if (nMaxCmp
==strlenW(lpszFile
) && !strncmpW(lpszFile
, tempBuffer
, nMaxCmp
))
1239 iScheme
=INTERNET_SCHEME_FILE
;
1240 else if (nMaxCmp
==strlenW(lpszNews
) && !strncmpW(lpszNews
, tempBuffer
, nMaxCmp
))
1241 iScheme
=INTERNET_SCHEME_NEWS
;
1242 else if (nMaxCmp
==strlenW(lpszMailto
) && !strncmpW(lpszMailto
, tempBuffer
, nMaxCmp
))
1243 iScheme
=INTERNET_SCHEME_MAILTO
;
1244 else if (nMaxCmp
==strlenW(lpszRes
) && !strncmpW(lpszRes
, tempBuffer
, nMaxCmp
))
1245 iScheme
=INTERNET_SCHEME_RES
;
1246 HeapFree(GetProcessHeap(),0,tempBuffer
);
1250 /***********************************************************************
1251 * SetUrlComponentValueW (Internal)
1253 * Helper function for InternetCrackUrlW
1256 * lppszComponent [O] Holds the returned string
1257 * dwComponentLen [I] Holds the size of lppszComponent
1258 * [O] Holds the length of the string in lppszComponent without '\0'
1259 * lpszStart [I] Holds the string to copy from
1260 * len [I] Holds the length of lpszStart without '\0'
1267 static BOOL
SetUrlComponentValueW(LPWSTR
* lppszComponent
, LPDWORD dwComponentLen
, LPCWSTR lpszStart
, DWORD len
)
1269 TRACE("%s (%ld)\n", debugstr_wn(lpszStart
,len
), len
);
1271 if ( (*dwComponentLen
== 0) && (*lppszComponent
== NULL
) )
1274 if (*dwComponentLen
!= 0 || *lppszComponent
== NULL
)
1276 if (*lppszComponent
== NULL
)
1278 *lppszComponent
= (LPWSTR
)lpszStart
;
1279 *dwComponentLen
= len
;
1283 DWORD ncpylen
= min((*dwComponentLen
)-1, len
);
1284 memcpy(*lppszComponent
, lpszStart
, ncpylen
*sizeof(WCHAR
));
1285 (*lppszComponent
)[ncpylen
] = '\0';
1286 *dwComponentLen
= ncpylen
;
1293 /***********************************************************************
1294 * InternetCrackUrlW (WININET.@)
1296 BOOL WINAPI
InternetCrackUrlW(LPCWSTR lpszUrl_orig
, DWORD dwUrlLength_orig
, DWORD dwFlags
,
1297 LPURL_COMPONENTSW lpUC
)
1301 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1304 LPCWSTR lpszParam
= NULL
;
1305 BOOL bIsAbsolute
= FALSE
;
1306 LPCWSTR lpszap
, lpszUrl
= lpszUrl_orig
;
1307 LPCWSTR lpszcp
= NULL
;
1308 LPWSTR lpszUrl_decode
= NULL
;
1309 DWORD dwUrlLength
= dwUrlLength_orig
;
1310 const WCHAR lpszSeparators
[3]={';','?',0};
1311 const WCHAR lpszSlash
[2]={'/',0};
1313 dwUrlLength
=strlenW(lpszUrl
);
1315 TRACE("(%s %lu %lx %p)\n", debugstr_w(lpszUrl
), dwUrlLength
, dwFlags
, lpUC
);
1316 if (dwFlags
& ICU_DECODE
)
1318 lpszUrl_decode
=HeapAlloc( GetProcessHeap(), 0, dwUrlLength
* sizeof (WCHAR
) );
1319 if( InternetCanonicalizeUrlW(lpszUrl_orig
, lpszUrl_decode
, &dwUrlLength
, dwFlags
))
1321 lpszUrl
= lpszUrl_decode
;
1326 /* Determine if the URI is absolute. */
1327 while (*lpszap
!= '\0')
1329 if (isalnumW(*lpszap
))
1334 if ((*lpszap
== ':') && (lpszap
- lpszUrl
>= 2))
1341 lpszcp
= lpszUrl
; /* Relative url */
1347 /* Parse <params> */
1348 lpszParam
= strpbrkW(lpszap
, lpszSeparators
);
1349 if (lpszParam
!= NULL
)
1351 SetUrlComponentValueW(&lpUC
->lpszExtraInfo
, &lpUC
->dwExtraInfoLength
,
1352 lpszParam
, dwUrlLength
-(lpszParam
-lpszUrl
));
1355 if (bIsAbsolute
) /* Parse <protocol>:[//<net_loc>] */
1358 static const WCHAR wszAbout
[]={'a','b','o','u','t',':',0};
1360 /* Get scheme first. */
1361 lpUC
->nScheme
= GetInternetSchemeW(lpszUrl
, lpszcp
- lpszUrl
);
1362 SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
,
1363 lpszUrl
, lpszcp
- lpszUrl
);
1365 /* Eat ':' in protocol. */
1368 /* if the scheme is "about", there is no host */
1369 if(strncmpW(wszAbout
,lpszUrl
, lpszcp
- lpszUrl
)==0)
1371 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1372 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1373 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1378 /* Skip over slashes. */
1390 lpszNetLoc
= strpbrkW(lpszcp
, lpszSlash
);
1394 lpszNetLoc
= min(lpszNetLoc
, lpszParam
);
1396 lpszNetLoc
= lpszParam
;
1398 else if (!lpszNetLoc
)
1399 lpszNetLoc
= lpszcp
+ dwUrlLength
-(lpszcp
-lpszUrl
);
1407 /* [<user>[<:password>]@]<host>[:<port>] */
1408 /* First find the user and password if they exist */
1410 lpszHost
= strchrW(lpszcp
, '@');
1411 if (lpszHost
== NULL
|| lpszHost
> lpszNetLoc
)
1413 /* username and password not specified. */
1414 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1415 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1417 else /* Parse out username and password */
1419 LPCWSTR lpszUser
= lpszcp
;
1420 LPCWSTR lpszPasswd
= lpszHost
;
1422 while (lpszcp
< lpszHost
)
1425 lpszPasswd
= lpszcp
;
1430 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
,
1431 lpszUser
, lpszPasswd
- lpszUser
);
1433 if (lpszPasswd
!= lpszHost
)
1435 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
,
1436 lpszPasswd
== lpszHost
? NULL
: lpszPasswd
,
1437 lpszHost
- lpszPasswd
);
1439 lpszcp
++; /* Advance to beginning of host */
1442 /* Parse <host><:port> */
1445 lpszPort
= lpszNetLoc
;
1447 /* special case for res:// URLs: there is no port here, so the host is the
1448 entire string up to the first '/' */
1449 if(lpUC
->nScheme
==INTERNET_SCHEME_RES
)
1451 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1452 lpszHost
, lpszPort
- lpszHost
);
1458 while (lpszcp
< lpszNetLoc
)
1466 /* If the scheme is "file" and the host is just one letter, it's not a host */
1467 if(lpUC
->nScheme
==INTERNET_SCHEME_FILE
&& (lpszPort
-lpszHost
)==1)
1470 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1476 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1477 lpszHost
, lpszPort
- lpszHost
);
1478 if (lpszPort
!= lpszNetLoc
)
1479 lpUC
->nPort
= atoiW(++lpszPort
);
1488 /* Here lpszcp points to:
1490 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1491 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1493 if (lpszcp
!= 0 && *lpszcp
!= '\0' && (!lpszParam
|| lpszcp
< lpszParam
))
1497 /* Only truncate the parameter list if it's already been saved
1498 * in lpUC->lpszExtraInfo.
1500 if (lpszParam
&& lpUC
->dwExtraInfoLength
&& lpUC
->lpszExtraInfo
)
1501 len
= lpszParam
- lpszcp
;
1504 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1505 * newlines if necessary.
1507 LPWSTR lpsznewline
= strchrW(lpszcp
, '\n');
1508 if (lpsznewline
!= NULL
)
1509 len
= lpsznewline
- lpszcp
;
1511 len
= dwUrlLength
-(lpszcp
-lpszUrl
);
1513 SetUrlComponentValueW(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
,
1518 lpUC
->dwUrlPathLength
= 0;
1521 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl
,dwUrlLength
),
1522 debugstr_wn(lpUC
->lpszScheme
,lpUC
->dwSchemeLength
),
1523 debugstr_wn(lpUC
->lpszHostName
,lpUC
->dwHostNameLength
),
1524 debugstr_wn(lpUC
->lpszUrlPath
,lpUC
->dwUrlPathLength
),
1525 debugstr_wn(lpUC
->lpszExtraInfo
,lpUC
->dwExtraInfoLength
));
1528 HeapFree(GetProcessHeap(), 0, lpszUrl_decode
);
1532 /***********************************************************************
1533 * InternetAttemptConnect (WININET.@)
1535 * Attempt to make a connection to the internet
1538 * ERROR_SUCCESS on success
1539 * Error value on failure
1542 DWORD WINAPI
InternetAttemptConnect(DWORD dwReserved
)
1545 return ERROR_SUCCESS
;
1549 /***********************************************************************
1550 * InternetCanonicalizeUrlA (WININET.@)
1552 * Escape unsafe characters and spaces
1559 BOOL WINAPI
InternetCanonicalizeUrlA(LPCSTR lpszUrl
, LPSTR lpszBuffer
,
1560 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
1563 DWORD dwURLFlags
= 0x80000000; /* Don't know what this means */
1564 if(dwFlags
& ICU_DECODE
)
1566 dwURLFlags
|= URL_UNESCAPE
;
1567 dwFlags
&= ~ICU_DECODE
;
1570 if(dwFlags
& ICU_ESCAPE
)
1572 dwURLFlags
|= URL_UNESCAPE
;
1573 dwFlags
&= ~ICU_ESCAPE
;
1575 if(dwFlags
& ICU_BROWSER_MODE
)
1577 dwURLFlags
|= URL_BROWSER_MODE
;
1578 dwFlags
&= ~ICU_BROWSER_MODE
;
1581 FIXME("Unhandled flags 0x%08lx\n", dwFlags
);
1582 TRACE("%s %p %p %08lx\n", debugstr_a(lpszUrl
), lpszBuffer
,
1583 lpdwBufferLength
, dwURLFlags
);
1585 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1586 dwFlags
^= ICU_NO_ENCODE
;
1588 hr
= UrlCanonicalizeA(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwURLFlags
);
1590 return (hr
== S_OK
) ? TRUE
: FALSE
;
1593 /***********************************************************************
1594 * InternetCanonicalizeUrlW (WININET.@)
1596 * Escape unsafe characters and spaces
1603 BOOL WINAPI
InternetCanonicalizeUrlW(LPCWSTR lpszUrl
, LPWSTR lpszBuffer
,
1604 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
1607 DWORD dwURLFlags
= 0x80000000; /* Don't know what this means */
1608 if(dwFlags
& ICU_DECODE
)
1610 dwURLFlags
|= URL_UNESCAPE
;
1611 dwFlags
&= ~ICU_DECODE
;
1614 if(dwFlags
& ICU_ESCAPE
)
1616 dwURLFlags
|= URL_UNESCAPE
;
1617 dwFlags
&= ~ICU_ESCAPE
;
1619 if(dwFlags
& ICU_BROWSER_MODE
)
1621 dwURLFlags
|= URL_BROWSER_MODE
;
1622 dwFlags
&= ~ICU_BROWSER_MODE
;
1625 FIXME("Unhandled flags 0x%08lx\n", dwFlags
);
1626 TRACE("%s %p %p %08lx\n", debugstr_w(lpszUrl
), lpszBuffer
,
1627 lpdwBufferLength
, dwURLFlags
);
1629 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1630 dwFlags
^= ICU_NO_ENCODE
;
1632 hr
= UrlCanonicalizeW(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwURLFlags
);
1634 return (hr
== S_OK
) ? TRUE
: FALSE
;
1638 /***********************************************************************
1639 * InternetSetStatusCallbackA (WININET.@)
1641 * Sets up a callback function which is called as progress is made
1642 * during an operation.
1645 * Previous callback or NULL on success
1646 * INTERNET_INVALID_STATUS_CALLBACK on failure
1649 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackA(
1650 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
1652 INTERNET_STATUS_CALLBACK retVal
;
1653 LPWININETHANDLEHEADER lpwh
;
1655 TRACE("0x%08lx\n", (ULONG
)hInternet
);
1657 lpwh
= WININET_GetObject(hInternet
);
1659 return INTERNET_INVALID_STATUS_CALLBACK
;
1661 lpwh
->dwInternalFlags
&= ~INET_CALLBACKW
;
1662 retVal
= lpwh
->lpfnStatusCB
;
1663 lpwh
->lpfnStatusCB
= lpfnIntCB
;
1665 WININET_Release( lpwh
);
1670 /***********************************************************************
1671 * InternetSetStatusCallbackW (WININET.@)
1673 * Sets up a callback function which is called as progress is made
1674 * during an operation.
1677 * Previous callback or NULL on success
1678 * INTERNET_INVALID_STATUS_CALLBACK on failure
1681 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackW(
1682 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
1684 INTERNET_STATUS_CALLBACK retVal
;
1685 LPWININETHANDLEHEADER lpwh
;
1687 TRACE("0x%08lx\n", (ULONG
)hInternet
);
1689 lpwh
= WININET_GetObject(hInternet
);
1691 return INTERNET_INVALID_STATUS_CALLBACK
;
1693 lpwh
->dwInternalFlags
|= INET_CALLBACKW
;
1694 retVal
= lpwh
->lpfnStatusCB
;
1695 lpwh
->lpfnStatusCB
= lpfnIntCB
;
1697 WININET_Release( lpwh
);
1702 /***********************************************************************
1703 * InternetSetFilePointer (WININET.@)
1705 DWORD WINAPI
InternetSetFilePointer(HINTERNET hFile
, LONG lDistanceToMove
,
1706 PVOID pReserved
, DWORD dwMoveContext
, DWORD dwContext
)
1712 /***********************************************************************
1713 * InternetWriteFile (WININET.@)
1715 * Write data to an open internet file
1722 BOOL WINAPI
InternetWriteFile(HINTERNET hFile
, LPCVOID lpBuffer
,
1723 DWORD dwNumOfBytesToWrite
, LPDWORD lpdwNumOfBytesWritten
)
1725 BOOL retval
= FALSE
;
1727 LPWININETHANDLEHEADER lpwh
;
1730 lpwh
= (LPWININETHANDLEHEADER
) WININET_GetObject( hFile
);
1734 switch (lpwh
->htype
)
1738 LPWININETHTTPREQW lpwhr
;
1739 lpwhr
= (LPWININETHTTPREQW
)lpwh
;
1741 TRACE("HTTPREQ %li\n",dwNumOfBytesToWrite
);
1742 retval
= NETCON_send(&lpwhr
->netConnection
, lpBuffer
,
1743 dwNumOfBytesToWrite
, 0, (LPINT
)lpdwNumOfBytesWritten
);
1745 WININET_Release( lpwh
);
1751 nSocket
= ((LPWININETFILE
)lpwh
)->nDataSocket
;
1760 int res
= send(nSocket
, lpBuffer
, dwNumOfBytesToWrite
, 0);
1761 retval
= (res
>= 0);
1762 *lpdwNumOfBytesWritten
= retval
? res
: 0;
1764 WININET_Release( lpwh
);
1770 static BOOL
INTERNET_ReadFile(LPWININETHANDLEHEADER lpwh
, LPVOID lpBuffer
,
1771 DWORD dwNumOfBytesToRead
, LPDWORD pdwNumOfBytesRead
,
1772 BOOL bWait
, BOOL bSendCompletionStatus
)
1774 BOOL retval
= FALSE
;
1777 /* FIXME: this should use NETCON functions! */
1778 switch (lpwh
->htype
)
1781 if (!NETCON_recv(&((LPWININETHTTPREQW
)lpwh
)->netConnection
, lpBuffer
,
1782 dwNumOfBytesToRead
, bWait
? MSG_WAITALL
: 0, (int *)pdwNumOfBytesRead
))
1784 *pdwNumOfBytesRead
= 0;
1785 retval
= TRUE
; /* Under windows, it seems to return 0 even if nothing was read... */
1792 /* FIXME: FTP should use NETCON_ stuff */
1793 nSocket
= ((LPWININETFILE
)lpwh
)->nDataSocket
;
1796 int res
= recv(nSocket
, lpBuffer
, dwNumOfBytesToRead
, bWait
? MSG_WAITALL
: 0);
1797 retval
= (res
>= 0);
1798 *pdwNumOfBytesRead
= retval
? res
: 0;
1806 if (bSendCompletionStatus
)
1808 INTERNET_ASYNC_RESULT iar
;
1810 iar
.dwResult
= retval
;
1811 iar
.dwError
= iar
.dwError
= retval
? ERROR_SUCCESS
:
1812 INTERNET_GetLastError();
1814 INTERNET_SendCallback(lpwh
, lpwh
->dwContext
,
1815 INTERNET_STATUS_REQUEST_COMPLETE
, &iar
,
1816 sizeof(INTERNET_ASYNC_RESULT
));
1821 /***********************************************************************
1822 * InternetReadFile (WININET.@)
1824 * Read data from an open internet file
1831 BOOL WINAPI
InternetReadFile(HINTERNET hFile
, LPVOID lpBuffer
,
1832 DWORD dwNumOfBytesToRead
, LPDWORD pdwNumOfBytesRead
)
1834 LPWININETHANDLEHEADER lpwh
;
1837 TRACE("%p %p %ld %p\n", hFile
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
1839 lpwh
= WININET_GetObject( hFile
);
1842 SetLastError(ERROR_INVALID_HANDLE
);
1846 retval
= INTERNET_ReadFile(lpwh
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
, TRUE
, FALSE
);
1847 WININET_Release( lpwh
);
1849 TRACE("-- %s (bytes read: %ld)\n", retval
? "TRUE": "FALSE", pdwNumOfBytesRead
? *pdwNumOfBytesRead
: -1);
1853 /***********************************************************************
1854 * InternetReadFileExA (WININET.@)
1856 * Read data from an open internet file
1859 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
1860 * lpBuffersOut [I/O] Buffer.
1861 * dwFlags [I] Flags. See notes.
1862 * dwContext [I] Context for callbacks.
1869 * The parameter dwFlags include zero or more of the following flags:
1870 *|IRF_ASYNC - Makes the call asynchronous.
1871 *|IRF_SYNC - Makes the call synchronous.
1872 *|IRF_USE_CONTEXT - Forces dwContext to be used.
1873 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
1875 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
1878 * InternetOpenUrlA(), HttpOpenRequestA()
1880 BOOL WINAPI
InternetReadFileExA(HINTERNET hFile
, LPINTERNET_BUFFERSA lpBuffersOut
,
1881 DWORD dwFlags
, DWORD dwContext
)
1883 BOOL retval
= FALSE
;
1884 LPWININETHANDLEHEADER lpwh
;
1886 TRACE("(%p %p 0x%lx 0x%lx)\n", hFile
, lpBuffersOut
, dwFlags
, dwContext
);
1888 if (dwFlags
& ~(IRF_ASYNC
|IRF_NO_WAIT
))
1889 FIXME("these dwFlags aren't implemented: 0x%lx\n", dwFlags
& ~(IRF_ASYNC
|IRF_NO_WAIT
));
1891 if (lpBuffersOut
->dwStructSize
!= sizeof(*lpBuffersOut
))
1893 SetLastError(ERROR_INVALID_PARAMETER
);
1897 lpwh
= (LPWININETHANDLEHEADER
) WININET_GetObject( hFile
);
1900 SetLastError(ERROR_INVALID_HANDLE
);
1904 /* FIXME: native only does it asynchronously if the amount of data
1905 * requested isn't available. See NtReadFile. */
1906 /* FIXME: IRF_ASYNC may not be the right thing to test here;
1907 * hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC is probably better, but
1908 * we should implement the above first */
1909 if (dwFlags
& IRF_ASYNC
)
1911 WORKREQUEST workRequest
;
1912 struct WORKREQ_INTERNETREADFILEEXA
*req
;
1914 workRequest
.asyncall
= INTERNETREADFILEEXA
;
1915 workRequest
.hdr
= WININET_AddRef( lpwh
);
1916 req
= &workRequest
.u
.InternetReadFileExA
;
1917 req
->lpBuffersOut
= lpBuffersOut
;
1919 retval
= INTERNET_AsyncCall(&workRequest
);
1920 if (!retval
) return FALSE
;
1922 SetLastError(ERROR_IO_PENDING
);
1926 retval
= INTERNET_ReadFile(lpwh
, lpBuffersOut
->lpvBuffer
,
1927 lpBuffersOut
->dwBufferLength
, &lpBuffersOut
->dwBufferLength
,
1928 !(dwFlags
& IRF_NO_WAIT
), FALSE
);
1930 WININET_Release( lpwh
);
1932 TRACE("-- %s (bytes read: %ld)\n", retval
? "TRUE": "FALSE", lpBuffersOut
->dwBufferLength
);
1936 /***********************************************************************
1937 * InternetReadFileExW (WININET.@)
1939 * Read data from an open internet file.
1942 * hFile [I] Handle returned by InternetOpenUrl() or HttpOpenRequest().
1943 * lpBuffersOut [I/O] Buffer.
1944 * dwFlags [I] Flags.
1945 * dwContext [I] Context for callbacks.
1948 * FALSE, last error is set to ERROR_CALL_NOT_IMPLEMENTED
1951 * Not implemented in Wine or native either (as of IE6 SP2).
1954 BOOL WINAPI
InternetReadFileExW(HINTERNET hFile
, LPINTERNET_BUFFERSW lpBuffer
,
1955 DWORD dwFlags
, DWORD dwContext
)
1957 ERR("(%p, %p, 0x%lx, 0x%lx): not implemented in native\n", hFile
, lpBuffer
, dwFlags
, dwContext
);
1959 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1963 /***********************************************************************
1964 * INET_QueryOptionHelper (internal)
1966 static BOOL
INET_QueryOptionHelper(BOOL bIsUnicode
, HINTERNET hInternet
, DWORD dwOption
,
1967 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
1969 LPWININETHANDLEHEADER lpwhh
;
1970 BOOL bSuccess
= FALSE
;
1972 TRACE("(%p, 0x%08lx, %p, %p)\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
1974 lpwhh
= (LPWININETHANDLEHEADER
) WININET_GetObject( hInternet
);
1978 case INTERNET_OPTION_HANDLE_TYPE
:
1984 WARN("Invalid hInternet handle\n");
1985 SetLastError(ERROR_INVALID_HANDLE
);
1989 type
= lpwhh
->htype
;
1991 TRACE("INTERNET_OPTION_HANDLE_TYPE: %ld\n", type
);
1993 if (*lpdwBufferLength
< sizeof(ULONG
))
1994 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1997 memcpy(lpBuffer
, &type
, sizeof(ULONG
));
2000 *lpdwBufferLength
= sizeof(ULONG
);
2004 case INTERNET_OPTION_REQUEST_FLAGS
:
2007 TRACE("INTERNET_OPTION_REQUEST_FLAGS: %ld\n", flags
);
2008 if (*lpdwBufferLength
< sizeof(ULONG
))
2009 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2012 memcpy(lpBuffer
, &flags
, sizeof(ULONG
));
2015 *lpdwBufferLength
= sizeof(ULONG
);
2019 case INTERNET_OPTION_URL
:
2020 case INTERNET_OPTION_DATAFILE_NAME
:
2024 WARN("Invalid hInternet handle\n");
2025 SetLastError(ERROR_INVALID_HANDLE
);
2028 if (lpwhh
->htype
== WH_HHTTPREQ
)
2030 LPWININETHTTPREQW lpreq
= (LPWININETHTTPREQW
) lpwhh
;
2032 static const WCHAR szFmt
[] = {'h','t','t','p',':','/','/','%','s','%','s',0};
2033 static const WCHAR szHost
[] = {'H','o','s','t',0};
2037 Host
= HTTP_GetHeader(lpreq
,szHost
);
2038 sprintfW(url
,szFmt
,Host
->lpszValue
,lpreq
->lpszPath
);
2039 TRACE("INTERNET_OPTION_URL: %s\n",debugstr_w(url
));
2042 sizeRequired
= WideCharToMultiByte(CP_ACP
,0,url
,-1,
2043 lpBuffer
,*lpdwBufferLength
,NULL
,NULL
);
2044 if (sizeRequired
> *lpdwBufferLength
)
2045 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2048 *lpdwBufferLength
= sizeRequired
;
2052 sizeRequired
= (lstrlenW(url
)+1) * sizeof(WCHAR
);
2053 if (*lpdwBufferLength
< sizeRequired
)
2054 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2057 strcpyW(lpBuffer
, url
);
2060 *lpdwBufferLength
= sizeRequired
;
2065 case INTERNET_OPTION_HTTP_VERSION
:
2067 if (*lpdwBufferLength
< sizeof(HTTP_VERSION_INFO
))
2068 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2072 * Presently hardcoded to 1.1
2074 ((HTTP_VERSION_INFO
*)lpBuffer
)->dwMajorVersion
= 1;
2075 ((HTTP_VERSION_INFO
*)lpBuffer
)->dwMinorVersion
= 1;
2078 *lpdwBufferLength
= sizeof(HTTP_VERSION_INFO
);
2081 case INTERNET_OPTION_CONNECTED_STATE
:
2083 DWORD
*pdwConnectedState
= (DWORD
*)lpBuffer
;
2084 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2086 if (*lpdwBufferLength
< sizeof(*pdwConnectedState
))
2087 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2090 *pdwConnectedState
= INTERNET_STATE_CONNECTED
;
2093 *lpdwBufferLength
= sizeof(*pdwConnectedState
);
2096 case INTERNET_OPTION_PROXY
:
2098 LPWININETAPPINFOW lpwai
= (LPWININETAPPINFOW
)lpwhh
;
2099 WININETAPPINFOW wai
;
2103 TRACE("Getting global proxy info\n");
2104 memset(&wai
, 0, sizeof(WININETAPPINFOW
));
2105 INTERNET_ConfigureProxyFromReg( &wai
);
2111 INTERNET_PROXY_INFOW
*pPI
= (INTERNET_PROXY_INFOW
*)lpBuffer
;
2112 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
2114 if (lpwai
->lpszProxy
)
2115 proxyBytesRequired
= (lstrlenW(lpwai
->lpszProxy
) + 1) *
2117 if (lpwai
->lpszProxyBypass
)
2118 proxyBypassBytesRequired
=
2119 (lstrlenW(lpwai
->lpszProxyBypass
) + 1) * sizeof(WCHAR
);
2120 if (*lpdwBufferLength
< sizeof(INTERNET_PROXY_INFOW
) +
2121 proxyBytesRequired
+ proxyBypassBytesRequired
)
2122 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2125 pPI
->dwAccessType
= lpwai
->dwAccessType
;
2126 if (lpwai
->lpszProxy
)
2128 pPI
->lpszProxy
= (LPWSTR
)((LPBYTE
)lpBuffer
+
2129 sizeof(INTERNET_PROXY_INFOW
));
2130 lstrcpyW((LPWSTR
)pPI
->lpszProxy
, lpwai
->lpszProxy
);
2134 pPI
->lpszProxy
= (LPWSTR
)((LPBYTE
)lpBuffer
+
2135 sizeof(INTERNET_PROXY_INFOW
));
2136 *((LPWSTR
)(pPI
->lpszProxy
)) = 0;
2139 if (lpwai
->lpszProxyBypass
)
2141 pPI
->lpszProxyBypass
= (LPWSTR
)((LPBYTE
)lpBuffer
+
2142 sizeof(INTERNET_PROXY_INFOW
) +
2143 proxyBytesRequired
);
2144 lstrcpyW((LPWSTR
)pPI
->lpszProxyBypass
,
2145 lpwai
->lpszProxyBypass
);
2149 pPI
->lpszProxyBypass
= (LPWSTR
)((LPBYTE
)lpBuffer
+
2150 sizeof(INTERNET_PROXY_INFOW
) +
2151 proxyBytesRequired
);
2152 *((LPWSTR
)(pPI
->lpszProxyBypass
)) = 0;
2156 *lpdwBufferLength
= sizeof(INTERNET_PROXY_INFOW
) +
2157 proxyBytesRequired
+ proxyBypassBytesRequired
;
2161 INTERNET_PROXY_INFOA
*pPI
= (INTERNET_PROXY_INFOA
*)lpBuffer
;
2162 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
2164 if (lpwai
->lpszProxy
)
2165 proxyBytesRequired
= WideCharToMultiByte(CP_ACP
, 0,
2166 lpwai
->lpszProxy
, -1, NULL
, 0, NULL
, NULL
);
2167 if (lpwai
->lpszProxyBypass
)
2168 proxyBypassBytesRequired
= WideCharToMultiByte(CP_ACP
, 0,
2169 lpwai
->lpszProxyBypass
, -1, NULL
, 0, NULL
, NULL
);
2170 if (*lpdwBufferLength
< sizeof(INTERNET_PROXY_INFOA
) +
2171 proxyBytesRequired
+ proxyBypassBytesRequired
)
2172 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2175 pPI
->dwAccessType
= lpwai
->dwAccessType
;
2176 if (lpwai
->lpszProxy
)
2178 pPI
->lpszProxy
= (LPSTR
)((LPBYTE
)lpBuffer
+
2179 sizeof(INTERNET_PROXY_INFOA
));
2180 WideCharToMultiByte(CP_ACP
, 0, lpwai
->lpszProxy
, -1,
2181 (LPSTR
)pPI
->lpszProxy
, proxyBytesRequired
, NULL
, NULL
);
2185 pPI
->lpszProxy
= (LPSTR
)((LPBYTE
)lpBuffer
+
2186 sizeof(INTERNET_PROXY_INFOA
));
2187 *((LPSTR
)(pPI
->lpszProxy
)) = '\0';
2190 if (lpwai
->lpszProxyBypass
)
2192 pPI
->lpszProxyBypass
= (LPSTR
)((LPBYTE
)lpBuffer
+
2193 sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
);
2194 WideCharToMultiByte(CP_ACP
, 0, lpwai
->lpszProxyBypass
,
2195 -1, (LPSTR
)pPI
->lpszProxyBypass
,
2196 proxyBypassBytesRequired
,
2201 pPI
->lpszProxyBypass
= (LPSTR
)((LPBYTE
)lpBuffer
+
2202 sizeof(INTERNET_PROXY_INFOA
) +
2203 proxyBytesRequired
);
2204 *((LPSTR
)(pPI
->lpszProxyBypass
)) = '\0';
2208 *lpdwBufferLength
= sizeof(INTERNET_PROXY_INFOA
) +
2209 proxyBytesRequired
+ proxyBypassBytesRequired
;
2213 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2216 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER: %ld\n", conn
);
2217 if (*lpdwBufferLength
< sizeof(ULONG
))
2218 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2221 memcpy(lpBuffer
, &conn
, sizeof(ULONG
));
2224 *lpdwBufferLength
= sizeof(ULONG
);
2227 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2230 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER: %ld\n", conn
);
2231 if (*lpdwBufferLength
< sizeof(ULONG
))
2232 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2235 memcpy(lpBuffer
, &conn
, sizeof(ULONG
));
2238 *lpdwBufferLength
= sizeof(ULONG
);
2241 case INTERNET_OPTION_SECURITY_FLAGS
:
2242 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2246 FIXME("Stub! %ld\n", dwOption
);
2250 WININET_Release( lpwhh
);
2255 /***********************************************************************
2256 * InternetQueryOptionW (WININET.@)
2258 * Queries an options on the specified handle
2265 BOOL WINAPI
InternetQueryOptionW(HINTERNET hInternet
, DWORD dwOption
,
2266 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2268 return INET_QueryOptionHelper(TRUE
, hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2271 /***********************************************************************
2272 * InternetQueryOptionA (WININET.@)
2274 * Queries an options on the specified handle
2281 BOOL WINAPI
InternetQueryOptionA(HINTERNET hInternet
, DWORD dwOption
,
2282 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2284 return INET_QueryOptionHelper(FALSE
, hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2288 /***********************************************************************
2289 * InternetSetOptionW (WININET.@)
2291 * Sets an options on the specified handle
2298 BOOL WINAPI
InternetSetOptionW(HINTERNET hInternet
, DWORD dwOption
,
2299 LPVOID lpBuffer
, DWORD dwBufferLength
)
2301 LPWININETHANDLEHEADER lpwhh
;
2304 TRACE("0x%08lx\n", dwOption
);
2306 lpwhh
= (LPWININETHANDLEHEADER
) WININET_GetObject( hInternet
);
2312 case INTERNET_OPTION_HTTP_VERSION
:
2314 HTTP_VERSION_INFO
* pVersion
=(HTTP_VERSION_INFO
*)lpBuffer
;
2315 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%ld,%ld): STUB\n",pVersion
->dwMajorVersion
,pVersion
->dwMinorVersion
);
2318 case INTERNET_OPTION_ERROR_MASK
:
2320 unsigned long flags
=*(unsigned long*)lpBuffer
;
2321 FIXME("Option INTERNET_OPTION_ERROR_MASK(%ld): STUB\n",flags
);
2324 case INTERNET_OPTION_CODEPAGE
:
2326 unsigned long codepage
=*(unsigned long*)lpBuffer
;
2327 FIXME("Option INTERNET_OPTION_CODEPAGE (%ld): STUB\n",codepage
);
2330 case INTERNET_OPTION_REQUEST_PRIORITY
:
2332 unsigned long priority
=*(unsigned long*)lpBuffer
;
2333 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%ld): STUB\n",priority
);
2336 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2338 unsigned long connecttimeout
=*(unsigned long*)lpBuffer
;
2339 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%ld): STUB\n",connecttimeout
);
2342 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT
:
2344 unsigned long receivetimeout
=*(unsigned long*)lpBuffer
;
2345 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%ld): STUB\n",receivetimeout
);
2348 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2350 unsigned long conns
=*(unsigned long*)lpBuffer
;
2351 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_SERVER (%ld): STUB\n",conns
);
2354 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2356 unsigned long conns
=*(unsigned long*)lpBuffer
;
2357 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER (%ld): STUB\n",conns
);
2360 case INTERNET_OPTION_RESET_URLCACHE_SESSION
:
2361 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2363 case INTERNET_OPTION_END_BROWSER_SESSION
:
2364 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2366 case INTERNET_OPTION_CONNECTED_STATE
:
2367 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2369 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH
:
2370 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2372 case INTERNET_OPTION_RECEIVE_TIMEOUT
:
2373 FIXME("Option INTERNET_OPTION_RECEIVE_TIMEOUT: STUB\n");
2375 case INTERNET_OPTION_SEND_TIMEOUT
:
2376 FIXME("Option INTERNET_OPTION_SEND_TIMEOUT: STUB\n");
2378 case INTERNET_OPTION_CONNECT_RETRIES
:
2379 FIXME("Option INTERNET_OPTION_CONNECT_RETRIES: STUB\n");
2382 FIXME("Option %ld STUB\n",dwOption
);
2383 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
2387 WININET_Release( lpwhh
);
2393 /***********************************************************************
2394 * InternetSetOptionA (WININET.@)
2396 * Sets an options on the specified handle.
2403 BOOL WINAPI
InternetSetOptionA(HINTERNET hInternet
, DWORD dwOption
,
2404 LPVOID lpBuffer
, DWORD dwBufferLength
)
2412 case INTERNET_OPTION_PROXY
:
2414 LPINTERNET_PROXY_INFOA pi
= (LPINTERNET_PROXY_INFOA
) lpBuffer
;
2415 LPINTERNET_PROXY_INFOW piw
;
2416 DWORD proxlen
, prbylen
;
2419 proxlen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, NULL
, 0);
2420 prbylen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, NULL
, 0);
2421 wlen
= sizeof(*piw
) + proxlen
+ prbylen
;
2422 wbuffer
= HeapAlloc( GetProcessHeap(), 0, wlen
*sizeof(WCHAR
) );
2423 piw
= (LPINTERNET_PROXY_INFOW
) wbuffer
;
2424 piw
->dwAccessType
= pi
->dwAccessType
;
2425 prox
= (LPWSTR
) &piw
[1];
2426 prby
= &prox
[proxlen
+1];
2427 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, prox
, proxlen
);
2428 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, prby
, prbylen
);
2429 piw
->lpszProxy
= prox
;
2430 piw
->lpszProxyBypass
= prby
;
2433 case INTERNET_OPTION_USER_AGENT
:
2434 case INTERNET_OPTION_USERNAME
:
2435 case INTERNET_OPTION_PASSWORD
:
2436 wlen
= MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, dwBufferLength
,
2438 wbuffer
= HeapAlloc( GetProcessHeap(), 0, wlen
*sizeof(WCHAR
) );
2439 MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, dwBufferLength
,
2444 wlen
= dwBufferLength
;
2447 r
= InternetSetOptionW(hInternet
,dwOption
, wbuffer
, wlen
);
2449 if( lpBuffer
!= wbuffer
)
2450 HeapFree( GetProcessHeap(), 0, wbuffer
);
2456 /***********************************************************************
2457 * InternetSetOptionExA (WININET.@)
2459 BOOL WINAPI
InternetSetOptionExA(HINTERNET hInternet
, DWORD dwOption
,
2460 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
2462 FIXME("Flags %08lx ignored\n", dwFlags
);
2463 return InternetSetOptionA( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2466 /***********************************************************************
2467 * InternetSetOptionExW (WININET.@)
2469 BOOL WINAPI
InternetSetOptionExW(HINTERNET hInternet
, DWORD dwOption
,
2470 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
2472 FIXME("Flags %08lx ignored\n", dwFlags
);
2473 if( dwFlags
& ~ISO_VALID_FLAGS
)
2475 SetLastError( ERROR_INVALID_PARAMETER
);
2478 return InternetSetOptionW( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2481 static const WCHAR WININET_wkday
[7][4] =
2482 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
2483 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
2484 static const WCHAR WININET_month
[12][4] =
2485 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
2486 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
2487 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
2489 /***********************************************************************
2490 * InternetTimeFromSystemTimeA (WININET.@)
2492 BOOL WINAPI
InternetTimeFromSystemTimeA( const SYSTEMTIME
* time
, DWORD format
, LPSTR string
, DWORD size
)
2495 WCHAR stringW
[INTERNET_RFC1123_BUFSIZE
];
2497 TRACE( "%p 0x%08lx %p 0x%08lx\n", time
, format
, string
, size
);
2499 ret
= InternetTimeFromSystemTimeW( time
, format
, stringW
, sizeof(stringW
) );
2500 if (ret
) WideCharToMultiByte( CP_ACP
, 0, stringW
, -1, string
, size
, NULL
, NULL
);
2505 /***********************************************************************
2506 * InternetTimeFromSystemTimeW (WININET.@)
2508 BOOL WINAPI
InternetTimeFromSystemTimeW( const SYSTEMTIME
* time
, DWORD format
, LPWSTR string
, DWORD size
)
2510 static const WCHAR date
[] =
2511 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
2512 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
2514 TRACE( "%p 0x%08lx %p 0x%08lx\n", time
, format
, string
, size
);
2516 if (!time
|| !string
) return FALSE
;
2518 if (format
!= INTERNET_RFC1123_FORMAT
|| size
< INTERNET_RFC1123_BUFSIZE
* sizeof(WCHAR
))
2521 sprintfW( string
, date
,
2522 WININET_wkday
[time
->wDayOfWeek
],
2524 WININET_month
[time
->wMonth
- 1],
2533 /***********************************************************************
2534 * InternetTimeToSystemTimeA (WININET.@)
2536 BOOL WINAPI
InternetTimeToSystemTimeA( LPCSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
2542 TRACE( "%s %p 0x%08lx\n", debugstr_a(string
), time
, reserved
);
2544 len
= MultiByteToWideChar( CP_ACP
, 0, string
, -1, NULL
, 0 );
2545 stringW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
2549 MultiByteToWideChar( CP_ACP
, 0, string
, -1, stringW
, len
);
2550 ret
= InternetTimeToSystemTimeW( stringW
, time
, reserved
);
2551 HeapFree( GetProcessHeap(), 0, stringW
);
2556 /***********************************************************************
2557 * InternetTimeToSystemTimeW (WININET.@)
2559 BOOL WINAPI
InternetTimeToSystemTimeW( LPCWSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
2562 WCHAR
*s
= (LPWSTR
)string
;
2564 TRACE( "%s %p 0x%08lx\n", debugstr_w(string
), time
, reserved
);
2566 if (!string
|| !time
) return FALSE
;
2568 /* Windows does this too */
2569 GetSystemTime( time
);
2571 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
2572 * a SYSTEMTIME structure.
2575 while (*s
&& !isalphaW( *s
)) s
++;
2576 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
2577 time
->wDayOfWeek
= 7;
2579 for (i
= 0; i
< 7; i
++)
2581 if (toupperW( WININET_wkday
[i
][0] ) == toupperW( s
[0] ) &&
2582 toupperW( WININET_wkday
[i
][1] ) == toupperW( s
[1] ) &&
2583 toupperW( WININET_wkday
[i
][2] ) == toupperW( s
[2] ) )
2585 time
->wDayOfWeek
= i
;
2590 if (time
->wDayOfWeek
> 6) return TRUE
;
2591 while (*s
&& !isdigitW( *s
)) s
++;
2592 time
->wDay
= strtolW( s
, &s
, 10 );
2594 while (*s
&& !isalphaW( *s
)) s
++;
2595 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
2598 for (i
= 0; i
< 12; i
++)
2600 if (toupperW( WININET_month
[i
][0]) == toupperW( s
[0] ) &&
2601 toupperW( WININET_month
[i
][1]) == toupperW( s
[1] ) &&
2602 toupperW( WININET_month
[i
][2]) == toupperW( s
[2] ) )
2604 time
->wMonth
= i
+ 1;
2608 if (time
->wMonth
== 0) return TRUE
;
2610 while (*s
&& !isdigitW( *s
)) s
++;
2611 if (*s
== '\0') return TRUE
;
2612 time
->wYear
= strtolW( s
, &s
, 10 );
2614 while (*s
&& !isdigitW( *s
)) s
++;
2615 if (*s
== '\0') return TRUE
;
2616 time
->wHour
= strtolW( s
, &s
, 10 );
2618 while (*s
&& !isdigitW( *s
)) s
++;
2619 if (*s
== '\0') return TRUE
;
2620 time
->wMinute
= strtolW( s
, &s
, 10 );
2622 while (*s
&& !isdigitW( *s
)) s
++;
2623 if (*s
== '\0') return TRUE
;
2624 time
->wSecond
= strtolW( s
, &s
, 10 );
2626 time
->wMilliseconds
= 0;
2630 /***********************************************************************
2631 * InternetCheckConnectionW (WININET.@)
2633 * Pings a requested host to check internet connection
2636 * TRUE on success and FALSE on failure. If a failure then
2637 * ERROR_NOT_CONNECTED is placed into GetLastError
2640 BOOL WINAPI
InternetCheckConnectionW( LPCWSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
2643 * this is a kludge which runs the resident ping program and reads the output.
2645 * Anyone have a better idea?
2649 static const CHAR ping
[] = "ping -w 1 ";
2650 static const CHAR redirect
[] = " >/dev/null 2>/dev/null";
2651 CHAR
*command
= NULL
;
2659 * Crack or set the Address
2661 if (lpszUrl
== NULL
)
2664 * According to the doc we are supost to use the ip for the next
2665 * server in the WnInet internal server database. I have
2666 * no idea what that is or how to get it.
2668 * So someone needs to implement this.
2670 FIXME("Unimplemented with URL of NULL\n");
2675 URL_COMPONENTSW components
;
2677 ZeroMemory(&components
,sizeof(URL_COMPONENTSW
));
2678 components
.lpszHostName
= (LPWSTR
)&hostW
;
2679 components
.dwHostNameLength
= 1024;
2681 if (!InternetCrackUrlW(lpszUrl
,0,0,&components
))
2684 TRACE("host name : %s\n",debugstr_w(components
.lpszHostName
));
2688 * Build our ping command
2690 len
= WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, NULL
, 0, NULL
, NULL
);
2691 command
= HeapAlloc( GetProcessHeap(), 0, strlen(ping
)+len
+strlen(redirect
) );
2692 strcpy(command
,ping
);
2693 WideCharToMultiByte(CP_UNIXCP
, 0, hostW
, -1, command
+strlen(ping
), len
, NULL
, NULL
);
2694 strcat(command
,redirect
);
2696 TRACE("Ping command is : %s\n",command
);
2698 status
= system(command
);
2700 TRACE("Ping returned a code of %i\n",status
);
2702 /* Ping return code of 0 indicates success */
2708 HeapFree( GetProcessHeap(), 0, command
);
2710 SetLastError(ERROR_NOT_CONNECTED
);
2716 /***********************************************************************
2717 * InternetCheckConnectionA (WININET.@)
2719 * Pings a requested host to check internet connection
2722 * TRUE on success and FALSE on failure. If a failure then
2723 * ERROR_NOT_CONNECTED is placed into GetLastError
2726 BOOL WINAPI
InternetCheckConnectionA(LPCSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
2732 len
= MultiByteToWideChar(CP_ACP
, 0, lpszUrl
, -1, NULL
, 0);
2733 if (!(szUrl
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
))))
2735 MultiByteToWideChar(CP_ACP
, 0, lpszUrl
, -1, szUrl
, len
);
2736 rc
= InternetCheckConnectionW(szUrl
, dwFlags
, dwReserved
);
2737 HeapFree(GetProcessHeap(), 0, szUrl
);
2743 /**********************************************************
2744 * INTERNET_InternetOpenUrlW (internal)
2749 * handle of connection or NULL on failure
2751 HINTERNET WINAPI
INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC
, LPCWSTR lpszUrl
,
2752 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD dwContext
)
2754 URL_COMPONENTSW urlComponents
;
2755 WCHAR protocol
[32], hostName
[MAXHOSTNAME
], userName
[1024];
2756 WCHAR password
[1024], path
[2048], extra
[1024];
2757 HINTERNET client
= NULL
, client1
= NULL
;
2759 TRACE("(%p, %s, %s, %08lx, %08lx, %08lx)\n", hIC
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
2760 dwHeadersLength
, dwFlags
, dwContext
);
2762 urlComponents
.dwStructSize
= sizeof(URL_COMPONENTSW
);
2763 urlComponents
.lpszScheme
= protocol
;
2764 urlComponents
.dwSchemeLength
= 32;
2765 urlComponents
.lpszHostName
= hostName
;
2766 urlComponents
.dwHostNameLength
= MAXHOSTNAME
;
2767 urlComponents
.lpszUserName
= userName
;
2768 urlComponents
.dwUserNameLength
= 1024;
2769 urlComponents
.lpszPassword
= password
;
2770 urlComponents
.dwPasswordLength
= 1024;
2771 urlComponents
.lpszUrlPath
= path
;
2772 urlComponents
.dwUrlPathLength
= 2048;
2773 urlComponents
.lpszExtraInfo
= extra
;
2774 urlComponents
.dwExtraInfoLength
= 1024;
2775 if(!InternetCrackUrlW(lpszUrl
, strlenW(lpszUrl
), 0, &urlComponents
))
2777 switch(urlComponents
.nScheme
) {
2778 case INTERNET_SCHEME_FTP
:
2779 if(urlComponents
.nPort
== 0)
2780 urlComponents
.nPort
= INTERNET_DEFAULT_FTP_PORT
;
2781 client
= FTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
2782 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
);
2785 client1
= FtpOpenFileW(client
, path
, GENERIC_READ
, dwFlags
, dwContext
);
2786 if(client1
== NULL
) {
2787 InternetCloseHandle(client
);
2792 case INTERNET_SCHEME_HTTP
:
2793 case INTERNET_SCHEME_HTTPS
: {
2794 static const WCHAR szStars
[] = { '*','/','*', 0 };
2795 LPCWSTR accept
[2] = { szStars
, NULL
};
2796 if(urlComponents
.nPort
== 0) {
2797 if(urlComponents
.nScheme
== INTERNET_SCHEME_HTTP
)
2798 urlComponents
.nPort
= INTERNET_DEFAULT_HTTP_PORT
;
2800 urlComponents
.nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
2802 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
2803 client
= HTTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
2804 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
);
2807 client1
= HttpOpenRequestW(client
, NULL
, path
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
2808 if(client1
== NULL
) {
2809 InternetCloseHandle(client
);
2812 HttpAddRequestHeadersW(client1
, lpszHeaders
, dwHeadersLength
, HTTP_ADDREQ_FLAG_ADD
);
2813 if (!HttpSendRequestW(client1
, NULL
, 0, NULL
, 0)) {
2814 InternetCloseHandle(client1
);
2819 case INTERNET_SCHEME_GOPHER
:
2820 /* gopher doesn't seem to be implemented in wine, but it's supposed
2821 * to be supported by InternetOpenUrlA. */
2826 TRACE(" %p <--\n", client1
);
2831 /**********************************************************
2832 * InternetOpenUrlW (WININET.@)
2837 * handle of connection or NULL on failure
2839 HINTERNET WINAPI
InternetOpenUrlW(HINTERNET hInternet
, LPCWSTR lpszUrl
,
2840 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD dwContext
)
2842 HINTERNET ret
= NULL
;
2843 LPWININETAPPINFOW hIC
= NULL
;
2845 if (TRACE_ON(wininet
)) {
2846 TRACE("(%p, %s, %s, %08lx, %08lx, %08lx)\n", hInternet
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
2847 dwHeadersLength
, dwFlags
, dwContext
);
2849 dump_INTERNET_FLAGS(dwFlags
);
2852 hIC
= (LPWININETAPPINFOW
) WININET_GetObject( hInternet
);
2853 if (NULL
== hIC
|| hIC
->hdr
.htype
!= WH_HINIT
) {
2854 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2858 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
) {
2859 WORKREQUEST workRequest
;
2860 struct WORKREQ_INTERNETOPENURLW
*req
;
2862 workRequest
.asyncall
= INTERNETOPENURLW
;
2863 workRequest
.hdr
= WININET_AddRef( &hIC
->hdr
);
2864 req
= &workRequest
.u
.InternetOpenUrlW
;
2866 req
->lpszUrl
= WININET_strdupW(lpszUrl
);
2870 req
->lpszHeaders
= WININET_strdupW(lpszHeaders
);
2872 req
->lpszHeaders
= 0;
2873 req
->dwHeadersLength
= dwHeadersLength
;
2874 req
->dwFlags
= dwFlags
;
2875 req
->dwContext
= dwContext
;
2877 INTERNET_AsyncCall(&workRequest
);
2879 * This is from windows.
2881 SetLastError(ERROR_IO_PENDING
);
2883 ret
= INTERNET_InternetOpenUrlW(hIC
, lpszUrl
, lpszHeaders
, dwHeadersLength
, dwFlags
, dwContext
);
2888 WININET_Release( &hIC
->hdr
);
2889 TRACE(" %p <--\n", ret
);
2894 /**********************************************************
2895 * InternetOpenUrlA (WININET.@)
2900 * handle of connection or NULL on failure
2902 HINTERNET WINAPI
InternetOpenUrlA(HINTERNET hInternet
, LPCSTR lpszUrl
,
2903 LPCSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD dwContext
)
2905 HINTERNET rc
= (HINTERNET
)NULL
;
2909 LPWSTR szUrl
= NULL
;
2910 LPWSTR szHeaders
= NULL
;
2915 lenUrl
= MultiByteToWideChar(CP_ACP
, 0, lpszUrl
, -1, NULL
, 0 );
2916 szUrl
= HeapAlloc(GetProcessHeap(), 0, lenUrl
*sizeof(WCHAR
));
2918 return (HINTERNET
)NULL
;
2919 MultiByteToWideChar(CP_ACP
, 0, lpszUrl
, -1, szUrl
, lenUrl
);
2923 lenHeaders
= MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, NULL
, 0 );
2924 szHeaders
= HeapAlloc(GetProcessHeap(), 0, lenHeaders
*sizeof(WCHAR
));
2926 HeapFree(GetProcessHeap(), 0, szUrl
);
2927 return (HINTERNET
)NULL
;
2929 MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, szHeaders
, lenHeaders
);
2932 rc
= InternetOpenUrlW(hInternet
, szUrl
, szHeaders
,
2933 lenHeaders
, dwFlags
, dwContext
);
2935 HeapFree(GetProcessHeap(), 0, szUrl
);
2936 HeapFree(GetProcessHeap(), 0, szHeaders
);
2942 /***********************************************************************
2943 * INTERNET_SetLastError (internal)
2945 * Set last thread specific error
2950 void INTERNET_SetLastError(DWORD dwError
)
2952 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
2954 SetLastError(dwError
);
2956 lpwite
->dwError
= dwError
;
2960 /***********************************************************************
2961 * INTERNET_GetLastError (internal)
2963 * Get last thread specific error
2968 DWORD
INTERNET_GetLastError(void)
2970 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
2971 /* TlsGetValue clears last error, so set it again here */
2972 SetLastError(lpwite
->dwError
);
2973 return lpwite
->dwError
;
2977 /***********************************************************************
2978 * INTERNET_WorkerThreadFunc (internal)
2980 * Worker thread execution function
2985 static DWORD CALLBACK
INTERNET_WorkerThreadFunc(LPVOID lpvParam
)
2992 INTERNET_ExecuteWork();
2995 dwWaitRes
= WaitForMultipleObjects(2, hEventArray
, FALSE
, MAX_IDLE_WORKER
);
2997 if (dwWaitRes
== WAIT_OBJECT_0
+ 1)
2998 INTERNET_ExecuteWork();
3002 InterlockedIncrement(&dwNumIdleThreads
);
3005 InterlockedDecrement(&dwNumIdleThreads
);
3006 InterlockedDecrement(&dwNumThreads
);
3007 TRACE("Worker thread exiting\n");
3012 /***********************************************************************
3013 * INTERNET_InsertWorkRequest (internal)
3015 * Insert work request into queue
3020 static BOOL
INTERNET_InsertWorkRequest(LPWORKREQUEST lpWorkRequest
)
3022 BOOL bSuccess
= FALSE
;
3023 LPWORKREQUEST lpNewRequest
;
3027 lpNewRequest
= HeapAlloc(GetProcessHeap(), 0, sizeof(WORKREQUEST
));
3030 memcpy(lpNewRequest
, lpWorkRequest
, sizeof(WORKREQUEST
));
3031 lpNewRequest
->prev
= NULL
;
3033 EnterCriticalSection(&csQueue
);
3035 lpNewRequest
->next
= lpWorkQueueTail
;
3036 if (lpWorkQueueTail
)
3037 lpWorkQueueTail
->prev
= lpNewRequest
;
3038 lpWorkQueueTail
= lpNewRequest
;
3039 if (!lpHeadWorkQueue
)
3040 lpHeadWorkQueue
= lpWorkQueueTail
;
3042 LeaveCriticalSection(&csQueue
);
3045 InterlockedIncrement(&dwNumJobs
);
3052 /***********************************************************************
3053 * INTERNET_GetWorkRequest (internal)
3055 * Retrieves work request from queue
3060 static BOOL
INTERNET_GetWorkRequest(LPWORKREQUEST lpWorkRequest
)
3062 BOOL bSuccess
= FALSE
;
3063 LPWORKREQUEST lpRequest
= NULL
;
3067 EnterCriticalSection(&csQueue
);
3069 if (lpHeadWorkQueue
)
3071 lpRequest
= lpHeadWorkQueue
;
3072 lpHeadWorkQueue
= lpHeadWorkQueue
->prev
;
3073 if (lpRequest
== lpWorkQueueTail
)
3074 lpWorkQueueTail
= lpHeadWorkQueue
;
3077 LeaveCriticalSection(&csQueue
);
3081 memcpy(lpWorkRequest
, lpRequest
, sizeof(WORKREQUEST
));
3082 HeapFree(GetProcessHeap(), 0, lpRequest
);
3084 InterlockedDecrement(&dwNumJobs
);
3091 /***********************************************************************
3092 * INTERNET_AsyncCall (internal)
3094 * Retrieves work request from queue
3099 BOOL
INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest
)
3103 BOOL bSuccess
= FALSE
;
3107 if (InterlockedDecrement(&dwNumIdleThreads
) < 0)
3109 InterlockedIncrement(&dwNumIdleThreads
);
3111 if (InterlockedIncrement(&dwNumThreads
) > MAX_WORKER_THREADS
||
3112 !(hThread
= CreateThread(NULL
, 0,
3113 INTERNET_WorkerThreadFunc
, NULL
, 0, &dwTID
)))
3115 InterlockedDecrement(&dwNumThreads
);
3116 INTERNET_SetLastError(ERROR_INTERNET_ASYNC_THREAD_FAILED
);
3120 TRACE("Created new thread\n");
3124 INTERNET_InsertWorkRequest(lpWorkRequest
);
3125 SetEvent(hWorkEvent
);
3133 /***********************************************************************
3134 * INTERNET_ExecuteWork (internal)
3139 static VOID
INTERNET_ExecuteWork(void)
3141 WORKREQUEST workRequest
;
3145 if (!INTERNET_GetWorkRequest(&workRequest
))
3148 switch (workRequest
.asyncall
)
3152 struct WORKREQ_FTPPUTFILEW
*req
= &workRequest
.u
.FtpPutFileW
;
3153 LPWININETFTPSESSIONW lpwfs
= (LPWININETFTPSESSIONW
) workRequest
.hdr
;
3155 TRACE("FTPPUTFILEW %p\n", lpwfs
);
3157 FTP_FtpPutFileW(lpwfs
, req
->lpszLocalFile
,
3158 req
->lpszNewRemoteFile
, req
->dwFlags
, req
->dwContext
);
3160 HeapFree(GetProcessHeap(), 0, req
->lpszLocalFile
);
3161 HeapFree(GetProcessHeap(), 0, req
->lpszNewRemoteFile
);
3165 case FTPSETCURRENTDIRECTORYW
:
3167 struct WORKREQ_FTPSETCURRENTDIRECTORYW
*req
;
3168 LPWININETFTPSESSIONW lpwfs
= (LPWININETFTPSESSIONW
) workRequest
.hdr
;
3170 TRACE("FTPSETCURRENTDIRECTORYW %p\n", lpwfs
);
3172 req
= &workRequest
.u
.FtpSetCurrentDirectoryW
;
3173 FTP_FtpSetCurrentDirectoryW(lpwfs
, req
->lpszDirectory
);
3174 HeapFree(GetProcessHeap(), 0, req
->lpszDirectory
);
3178 case FTPCREATEDIRECTORYW
:
3180 struct WORKREQ_FTPCREATEDIRECTORYW
*req
;
3181 LPWININETFTPSESSIONW lpwfs
= (LPWININETFTPSESSIONW
) workRequest
.hdr
;
3183 TRACE("FTPCREATEDIRECTORYW %p\n", lpwfs
);
3185 req
= &workRequest
.u
.FtpCreateDirectoryW
;
3186 FTP_FtpCreateDirectoryW(lpwfs
, req
->lpszDirectory
);
3187 HeapFree(GetProcessHeap(), 0, req
->lpszDirectory
);
3191 case FTPFINDFIRSTFILEW
:
3193 struct WORKREQ_FTPFINDFIRSTFILEW
*req
;
3194 LPWININETFTPSESSIONW lpwfs
= (LPWININETFTPSESSIONW
) workRequest
.hdr
;
3196 TRACE("FTPFINDFIRSTFILEW %p\n", lpwfs
);
3198 req
= &workRequest
.u
.FtpFindFirstFileW
;
3199 FTP_FtpFindFirstFileW(lpwfs
, req
->lpszSearchFile
,
3200 req
->lpFindFileData
, req
->dwFlags
, req
->dwContext
);
3201 HeapFree(GetProcessHeap(), 0, req
->lpszSearchFile
);
3205 case FTPGETCURRENTDIRECTORYW
:
3207 struct WORKREQ_FTPGETCURRENTDIRECTORYW
*req
;
3208 LPWININETFTPSESSIONW lpwfs
= (LPWININETFTPSESSIONW
) workRequest
.hdr
;
3210 TRACE("FTPGETCURRENTDIRECTORYW %p\n", lpwfs
);
3212 req
= &workRequest
.u
.FtpGetCurrentDirectoryW
;
3213 FTP_FtpGetCurrentDirectoryW(lpwfs
,
3214 req
->lpszDirectory
, req
->lpdwDirectory
);
3220 struct WORKREQ_FTPOPENFILEW
*req
= &workRequest
.u
.FtpOpenFileW
;
3221 LPWININETFTPSESSIONW lpwfs
= (LPWININETFTPSESSIONW
) workRequest
.hdr
;
3223 TRACE("FTPOPENFILEW %p\n", lpwfs
);
3225 FTP_FtpOpenFileW(lpwfs
, req
->lpszFilename
,
3226 req
->dwAccess
, req
->dwFlags
, req
->dwContext
);
3227 HeapFree(GetProcessHeap(), 0, req
->lpszFilename
);
3233 struct WORKREQ_FTPGETFILEW
*req
= &workRequest
.u
.FtpGetFileW
;
3234 LPWININETFTPSESSIONW lpwfs
= (LPWININETFTPSESSIONW
) workRequest
.hdr
;
3236 TRACE("FTPGETFILEW %p\n", lpwfs
);
3238 FTP_FtpGetFileW(lpwfs
, req
->lpszRemoteFile
,
3239 req
->lpszNewFile
, req
->fFailIfExists
,
3240 req
->dwLocalFlagsAttribute
, req
->dwFlags
, req
->dwContext
);
3241 HeapFree(GetProcessHeap(), 0, req
->lpszRemoteFile
);
3242 HeapFree(GetProcessHeap(), 0, req
->lpszNewFile
);
3246 case FTPDELETEFILEW
:
3248 struct WORKREQ_FTPDELETEFILEW
*req
= &workRequest
.u
.FtpDeleteFileW
;
3249 LPWININETFTPSESSIONW lpwfs
= (LPWININETFTPSESSIONW
) workRequest
.hdr
;
3251 TRACE("FTPDELETEFILEW %p\n", lpwfs
);
3253 FTP_FtpDeleteFileW(lpwfs
, req
->lpszFilename
);
3254 HeapFree(GetProcessHeap(), 0, req
->lpszFilename
);
3258 case FTPREMOVEDIRECTORYW
:
3260 struct WORKREQ_FTPREMOVEDIRECTORYW
*req
;
3261 LPWININETFTPSESSIONW lpwfs
= (LPWININETFTPSESSIONW
) workRequest
.hdr
;
3263 TRACE("FTPREMOVEDIRECTORYW %p\n", lpwfs
);
3265 req
= &workRequest
.u
.FtpRemoveDirectoryW
;
3266 FTP_FtpRemoveDirectoryW(lpwfs
, req
->lpszDirectory
);
3267 HeapFree(GetProcessHeap(), 0, req
->lpszDirectory
);
3271 case FTPRENAMEFILEW
:
3273 struct WORKREQ_FTPRENAMEFILEW
*req
= &workRequest
.u
.FtpRenameFileW
;
3274 LPWININETFTPSESSIONW lpwfs
= (LPWININETFTPSESSIONW
) workRequest
.hdr
;
3276 TRACE("FTPRENAMEFILEW %p\n", lpwfs
);
3278 FTP_FtpRenameFileW(lpwfs
, req
->lpszSrcFile
, req
->lpszDestFile
);
3279 HeapFree(GetProcessHeap(), 0, req
->lpszSrcFile
);
3280 HeapFree(GetProcessHeap(), 0, req
->lpszDestFile
);
3284 case INTERNETFINDNEXTW
:
3286 struct WORKREQ_INTERNETFINDNEXTW
*req
;
3287 LPWININETFINDNEXTW lpwh
= (LPWININETFINDNEXTW
) workRequest
.hdr
;
3289 TRACE("INTERNETFINDNEXTW %p\n", lpwh
);
3291 req
= &workRequest
.u
.InternetFindNextW
;
3292 INTERNET_FindNextFileW(lpwh
, req
->lpFindFileData
);
3296 case HTTPSENDREQUESTW
:
3298 struct WORKREQ_HTTPSENDREQUESTW
*req
= &workRequest
.u
.HttpSendRequestW
;
3299 LPWININETHTTPREQW lpwhr
= (LPWININETHTTPREQW
) workRequest
.hdr
;
3301 TRACE("HTTPSENDREQUESTW %p\n", lpwhr
);
3303 HTTP_HttpSendRequestW(lpwhr
, req
->lpszHeader
,
3304 req
->dwHeaderLength
, req
->lpOptional
, req
->dwOptionalLength
,
3305 req
->dwContentLength
, req
->bEndRequest
);
3307 HeapFree(GetProcessHeap(), 0, req
->lpszHeader
);
3311 case HTTPOPENREQUESTW
:
3313 struct WORKREQ_HTTPOPENREQUESTW
*req
= &workRequest
.u
.HttpOpenRequestW
;
3314 LPWININETHTTPSESSIONW lpwhs
= (LPWININETHTTPSESSIONW
) workRequest
.hdr
;
3316 TRACE("HTTPOPENREQUESTW %p\n", lpwhs
);
3318 HTTP_HttpOpenRequestW(lpwhs
, req
->lpszVerb
,
3319 req
->lpszObjectName
, req
->lpszVersion
, req
->lpszReferrer
,
3320 req
->lpszAcceptTypes
, req
->dwFlags
, req
->dwContext
);
3322 HeapFree(GetProcessHeap(), 0, req
->lpszVerb
);
3323 HeapFree(GetProcessHeap(), 0, req
->lpszObjectName
);
3324 HeapFree(GetProcessHeap(), 0, req
->lpszVersion
);
3325 HeapFree(GetProcessHeap(), 0, req
->lpszReferrer
);
3331 struct WORKREQ_SENDCALLBACK
*req
= &workRequest
.u
.SendCallback
;
3333 TRACE("SENDCALLBACK %p\n", workRequest
.hdr
);
3335 INTERNET_SendCallback(workRequest
.hdr
,
3336 req
->dwContext
, req
->dwInternetStatus
, req
->lpvStatusInfo
,
3337 req
->dwStatusInfoLength
);
3339 /* And frees the copy of the status info */
3340 HeapFree(GetProcessHeap(), 0, req
->lpvStatusInfo
);
3344 case INTERNETOPENURLW
:
3346 struct WORKREQ_INTERNETOPENURLW
*req
= &workRequest
.u
.InternetOpenUrlW
;
3347 LPWININETAPPINFOW hIC
= (LPWININETAPPINFOW
) workRequest
.hdr
;
3349 TRACE("INTERNETOPENURLW %p\n", hIC
);
3351 INTERNET_InternetOpenUrlW(hIC
, req
->lpszUrl
,
3352 req
->lpszHeaders
, req
->dwHeadersLength
, req
->dwFlags
, req
->dwContext
);
3353 HeapFree(GetProcessHeap(), 0, req
->lpszUrl
);
3354 HeapFree(GetProcessHeap(), 0, req
->lpszHeaders
);
3357 case INTERNETREADFILEEXA
:
3359 struct WORKREQ_INTERNETREADFILEEXA
*req
= &workRequest
.u
.InternetReadFileExA
;
3361 TRACE("INTERNETREADFILEEXA %p\n", workRequest
.hdr
);
3363 INTERNET_ReadFile(workRequest
.hdr
, req
->lpBuffersOut
->lpvBuffer
,
3364 req
->lpBuffersOut
->dwBufferLength
,
3365 &req
->lpBuffersOut
->dwBufferLength
, TRUE
, TRUE
);
3369 WININET_Release( workRequest
.hdr
);
3373 /***********************************************************************
3374 * INTERNET_GetResponseBuffer (internal)
3379 LPSTR
INTERNET_GetResponseBuffer(void)
3381 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
3383 return lpwite
->response
;
3386 /***********************************************************************
3387 * INTERNET_GetNextLine (internal)
3389 * Parse next line in directory string listing
3392 * Pointer to beginning of next line
3397 LPSTR
INTERNET_GetNextLine(INT nSocket
, LPDWORD dwLen
)
3401 BOOL bSuccess
= FALSE
;
3403 LPSTR lpszBuffer
= INTERNET_GetResponseBuffer();
3408 FD_SET(nSocket
, &infd
);
3409 tv
.tv_sec
=RESPONSE_TIMEOUT
;
3412 while (nRecv
< MAX_REPLY_LEN
)
3414 if (select(nSocket
+1,&infd
,NULL
,NULL
,&tv
) > 0)
3416 if (recv(nSocket
, &lpszBuffer
[nRecv
], 1, 0) <= 0)
3418 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS
);
3422 if (lpszBuffer
[nRecv
] == '\n')
3427 if (lpszBuffer
[nRecv
] != '\r')
3432 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT
);
3440 lpszBuffer
[nRecv
] = '\0';
3442 TRACE(":%d %s\n", nRecv
, lpszBuffer
);
3451 /**********************************************************
3452 * InternetQueryDataAvailable (WININET.@)
3454 * Determines how much data is available to be read.
3457 * If there is data available then TRUE, otherwise if there
3458 * is not or an error occurred then FALSE. Use GetLastError() to
3459 * check for ERROR_NO_MORE_FILES to see if it was the former.
3461 BOOL WINAPI
InternetQueryDataAvailable( HINTERNET hFile
,
3462 LPDWORD lpdwNumberOfBytesAvailble
,
3463 DWORD dwFlags
, DWORD dwConext
)
3465 LPWININETHTTPREQW lpwhr
;
3466 BOOL retval
= FALSE
;
3469 lpwhr
= (LPWININETHTTPREQW
) WININET_GetObject( hFile
);
3472 SetLastError(ERROR_NO_MORE_FILES
);
3476 TRACE("--> %p %i\n",lpwhr
,lpwhr
->hdr
.htype
);
3478 switch (lpwhr
->hdr
.htype
)
3481 if (!NETCON_recv(&lpwhr
->netConnection
, buffer
,
3482 4048, MSG_PEEK
, (int *)lpdwNumberOfBytesAvailble
))
3484 SetLastError(ERROR_NO_MORE_FILES
);
3492 FIXME("unsupported file type\n");
3495 WININET_Release( &lpwhr
->hdr
);
3497 TRACE("<-- %i\n",retval
);
3502 /***********************************************************************
3503 * InternetLockRequestFile (WININET.@)
3505 BOOL WINAPI
InternetLockRequestFile( HINTERNET hInternet
, HANDLE
3512 BOOL WINAPI
InternetUnlockRequestFile( HANDLE hLockHandle
)
3519 /***********************************************************************
3520 * InternetAutodial (WININET.@)
3522 * On windows this function is supposed to dial the default internet
3523 * connection. We don't want to have Wine dial out to the internet so
3524 * we return TRUE by default. It might be nice to check if we are connected.
3531 BOOL WINAPI
InternetAutodial(DWORD dwFlags
, HWND hwndParent
)
3535 /* Tell that we are connected to the internet. */
3539 /***********************************************************************
3540 * InternetAutodialHangup (WININET.@)
3542 * Hangs up a connection made with InternetAutodial
3551 BOOL WINAPI
InternetAutodialHangup(DWORD dwReserved
)
3555 /* we didn't dial, we don't disconnect */
3559 /***********************************************************************
3560 * InternetCombineUrlA (WININET.@)
3562 * Combine a base URL with a relative URL
3570 BOOL WINAPI
InternetCombineUrlA(LPCSTR lpszBaseUrl
, LPCSTR lpszRelativeUrl
,
3571 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3576 TRACE("(%s, %s, %p, %p, 0x%08lx)\n", debugstr_a(lpszBaseUrl
), debugstr_a(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3578 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3579 dwFlags
^= ICU_NO_ENCODE
;
3580 hr
=UrlCombineA(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3585 /***********************************************************************
3586 * InternetCombineUrlW (WININET.@)
3588 * Combine a base URL with a relative URL
3596 BOOL WINAPI
InternetCombineUrlW(LPCWSTR lpszBaseUrl
, LPCWSTR lpszRelativeUrl
,
3597 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3602 TRACE("(%s, %s, %p, %p, 0x%08lx)\n", debugstr_w(lpszBaseUrl
), debugstr_w(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3604 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3605 dwFlags
^= ICU_NO_ENCODE
;
3606 hr
=UrlCombineW(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3611 /* max port num is 65535 => 5 digits */
3612 #define MAX_WORD_DIGITS 5
3614 /* we can calculate using ansi strings because we're just
3615 * calculating string length, not size
3617 static BOOL
calc_url_length(LPURL_COMPONENTSW lpUrlComponents
,
3618 LPDWORD lpdwUrlLength
, LPDWORD lpdwSchemeLength
)
3620 static const WCHAR httpW
[] = {'h','t','t','p',0};
3624 switch (lpUrlComponents
->nScheme
)
3626 case INTERNET_SCHEME_FTP
:
3627 case INTERNET_SCHEME_RES
:
3628 *lpdwSchemeLength
= 3;
3630 case INTERNET_SCHEME_HTTP
:
3631 case INTERNET_SCHEME_FILE
:
3632 case INTERNET_SCHEME_NEWS
:
3633 *lpdwSchemeLength
= 4;
3637 *lpdwSchemeLength
= 4;
3641 *lpdwUrlLength
+= *lpdwSchemeLength
;
3642 *lpdwUrlLength
+= strlen("://");
3644 if (lpUrlComponents
->lpszUserName
)
3646 *lpdwUrlLength
+= lpUrlComponents
->dwUserNameLength
;
3647 *lpdwUrlLength
+= strlen("@");
3651 if (lpUrlComponents
->lpszPassword
)
3653 SetLastError(ERROR_INVALID_PARAMETER
);
3658 if (lpUrlComponents
->lpszPassword
)
3660 *lpdwUrlLength
+= strlen(":");
3661 *lpdwUrlLength
+= lpUrlComponents
->dwPasswordLength
;
3664 *lpdwUrlLength
+= lpUrlComponents
->dwHostNameLength
;
3666 if (lpUrlComponents
->nPort
!= 80 ||
3667 (lpUrlComponents
->lpszScheme
&& strncmpW(lpUrlComponents
->lpszScheme
, httpW
, lpUrlComponents
->dwSchemeLength
)))
3669 char szPort
[MAX_WORD_DIGITS
];
3671 sprintf(szPort
, "%d", lpUrlComponents
->nPort
);
3672 *lpdwUrlLength
+= strlen(szPort
);
3673 *lpdwUrlLength
+= strlen(":");
3676 *lpdwUrlLength
+= lpUrlComponents
->dwUrlPathLength
;
3680 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents
, LPURL_COMPONENTSW urlCompW
)
3684 ZeroMemory(urlCompW
, sizeof(URL_COMPONENTSW
));
3686 urlCompW
->dwStructSize
= sizeof(URL_COMPONENTSW
);
3687 urlCompW
->dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
3688 urlCompW
->nScheme
= lpUrlComponents
->nScheme
;
3689 urlCompW
->dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
3690 urlCompW
->nPort
= lpUrlComponents
->nPort
;
3691 urlCompW
->dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
3692 urlCompW
->dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
3693 urlCompW
->dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
3694 urlCompW
->dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
3696 if (lpUrlComponents
->lpszScheme
)
3698 len
= lpUrlComponents
->dwSchemeLength
+ 1;
3699 urlCompW
->lpszScheme
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3700 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszScheme
,
3701 -1, urlCompW
->lpszScheme
, len
);
3704 if (lpUrlComponents
->lpszHostName
)
3706 len
= lpUrlComponents
->dwHostNameLength
+ 1;
3707 urlCompW
->lpszHostName
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3708 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszHostName
,
3709 -1, urlCompW
->lpszHostName
, len
);
3712 if (lpUrlComponents
->lpszUserName
)
3714 len
= lpUrlComponents
->dwUserNameLength
+ 1;
3715 urlCompW
->lpszUserName
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3716 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUserName
,
3717 -1, urlCompW
->lpszUserName
, len
);
3720 if (lpUrlComponents
->lpszPassword
)
3722 len
= lpUrlComponents
->dwPasswordLength
+ 1;
3723 urlCompW
->lpszPassword
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3724 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszPassword
,
3725 -1, urlCompW
->lpszPassword
, len
);
3728 if (lpUrlComponents
->lpszUrlPath
)
3730 len
= lpUrlComponents
->dwUrlPathLength
+ 1;
3731 urlCompW
->lpszUrlPath
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3732 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUrlPath
,
3733 -1, urlCompW
->lpszUrlPath
, len
);
3736 if (lpUrlComponents
->lpszExtraInfo
)
3738 len
= lpUrlComponents
->dwExtraInfoLength
+ 1;
3739 urlCompW
->lpszExtraInfo
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3740 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszExtraInfo
,
3741 -1, urlCompW
->lpszExtraInfo
, len
);
3745 /***********************************************************************
3746 * InternetCreateUrlA (WININET.@)
3753 BOOL WINAPI
InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents
, DWORD dwFlags
,
3754 LPSTR lpszUrl
, LPDWORD lpdwUrlLength
)
3758 URL_COMPONENTSW urlCompW
;
3760 TRACE("(%p,%ld,%s,%p)\n", lpUrlComponents
, dwFlags
, debugstr_a(lpszUrl
), lpdwUrlLength
);
3762 if (!lpUrlComponents
)
3765 if (lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
3767 SetLastError(ERROR_INVALID_PARAMETER
);
3771 convert_urlcomp_atow(lpUrlComponents
, &urlCompW
);
3774 urlW
= HeapAlloc(GetProcessHeap(), 0, *lpdwUrlLength
* sizeof(WCHAR
));
3776 ret
= InternetCreateUrlW(&urlCompW
, dwFlags
, urlW
, lpdwUrlLength
);
3778 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
3779 * minus one, so add one to leave room for NULL terminator
3782 WideCharToMultiByte(CP_ACP
, 0, urlW
, -1, lpszUrl
, *lpdwUrlLength
+ 1, NULL
, NULL
);
3784 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszScheme
);
3785 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszHostName
);
3786 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszUserName
);
3787 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszPassword
);
3788 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszUrlPath
);
3789 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszExtraInfo
);
3790 HeapFree(GetProcessHeap(), 0, urlW
);
3795 /***********************************************************************
3796 * InternetCreateUrlW (WININET.@)
3803 BOOL WINAPI
InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents
, DWORD dwFlags
,
3804 LPWSTR lpszUrl
, LPDWORD lpdwUrlLength
)
3806 DWORD dwLen
, dwSchemeLen
;
3808 static const WCHAR colonSlashW
[] = {':','/','/',0};
3809 static const WCHAR httpW
[] = {'h','t','t','p',0};
3810 static const WCHAR colonW
[] = {':',0};
3811 static const WCHAR atW
[] = {'@',0};
3812 static const WCHAR percentD
[] = {'%','d',0};
3814 TRACE("(%p,%ld,%s,%p)\n", lpUrlComponents
, dwFlags
, debugstr_w(lpszUrl
), lpdwUrlLength
);
3816 if (!lpUrlComponents
)
3819 if (lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
3821 SetLastError(ERROR_INVALID_PARAMETER
);
3825 if (!calc_url_length(lpUrlComponents
, &dwLen
, &dwSchemeLen
))
3828 if (!lpszUrl
|| *lpdwUrlLength
< dwLen
)
3830 *lpdwUrlLength
= dwLen
+ 1; /* terminating null */
3831 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3835 *lpdwUrlLength
= dwLen
;
3838 if (lpUrlComponents
->lpszScheme
)
3839 lstrcpynW(lpszUrl
, lpUrlComponents
->lpszScheme
,
3840 min(lpUrlComponents
->dwSchemeLength
, dwSchemeLen
) + 1);
3842 lstrcatW(lpszUrl
, colonSlashW
);
3844 if (lpUrlComponents
->lpszUserName
)
3846 if (!*lpUrlComponents
->lpszUserName
)
3849 lstrcatW(lpszUrl
, lpUrlComponents
->lpszUserName
);
3851 if (lpUrlComponents
->lpszPassword
)
3853 lstrcatW(lpszUrl
, colonW
);
3855 if (!*lpUrlComponents
->lpszPassword
)
3858 lstrcatW(lpszUrl
, lpUrlComponents
->lpszPassword
);
3861 lstrcatW(lpszUrl
, atW
);
3864 lstrcatW(lpszUrl
, lpUrlComponents
->lpszHostName
);
3866 if (lpUrlComponents
->nPort
!= 80 || (lpUrlComponents
->lpszScheme
&&
3867 strncmpW(lpUrlComponents
->lpszScheme
, httpW
, lpUrlComponents
->dwSchemeLength
)))
3869 WCHAR szPort
[MAX_WORD_DIGITS
];
3871 sprintfW(szPort
, percentD
, lpUrlComponents
->nPort
);
3872 lstrcatW(lpszUrl
, colonW
);
3873 lstrcatW(lpszUrl
, szPort
);
3876 lstrcatW(lpszUrl
, lpUrlComponents
->lpszUrlPath
);
3881 /***********************************************************************
3882 * InternetConfirmZoneCrossingA (WININET.@)
3885 DWORD WINAPI
InternetConfirmZoneCrossingA( HWND hWnd
, LPSTR szUrlPrev
, LPSTR szUrlNew
, BOOL bPost
)
3887 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_a(szUrlPrev
), debugstr_a(szUrlNew
), bPost
);
3888 return ERROR_SUCCESS
;
3891 /***********************************************************************
3892 * InternetConfirmZoneCrossingW (WININET.@)
3895 DWORD WINAPI
InternetConfirmZoneCrossingW( HWND hWnd
, LPWSTR szUrlPrev
, LPWSTR szUrlNew
, BOOL bPost
)
3897 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_w(szUrlPrev
), debugstr_w(szUrlNew
), bPost
);
3898 return ERROR_SUCCESS
;
3901 DWORD WINAPI
InternetDialA( HWND hwndParent
, LPSTR lpszConnectoid
, DWORD dwFlags
,
3902 LPDWORD lpdwConnection
, DWORD dwReserved
)
3904 FIXME("(%p, %p, 0x%08lx, %p, 0x%08lx) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
3905 lpdwConnection
, dwReserved
);
3906 return ERROR_SUCCESS
;
3909 DWORD WINAPI
InternetDialW( HWND hwndParent
, LPWSTR lpszConnectoid
, DWORD dwFlags
,
3910 LPDWORD lpdwConnection
, DWORD dwReserved
)
3912 FIXME("(%p, %p, 0x%08lx, %p, 0x%08lx) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
3913 lpdwConnection
, dwReserved
);
3914 return ERROR_SUCCESS
;
3917 BOOL WINAPI
InternetGoOnlineA( LPSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
3919 FIXME("(%s, %p, 0x%08lx) stub\n", debugstr_a(lpszURL
), hwndParent
, dwReserved
);
3923 BOOL WINAPI
InternetGoOnlineW( LPWSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
3925 FIXME("(%s, %p, 0x%08lx) stub\n", debugstr_w(lpszURL
), hwndParent
, dwReserved
);
3929 DWORD WINAPI
InternetHangUp( DWORD dwConnection
, DWORD dwReserved
)
3931 FIXME("(0x%08lx, 0x%08lx) stub\n", dwConnection
, dwReserved
);
3932 return ERROR_SUCCESS
;
3935 BOOL WINAPI
CreateMD5SSOHash( PWSTR pszChallengeInfo
, PWSTR pwszRealm
, PWSTR pwszTarget
,
3938 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo
), debugstr_w(pwszRealm
),
3939 debugstr_w(pwszTarget
), pbHexHash
);
3943 BOOL WINAPI
InternetClearAllPerSiteCookieDecisions( VOID
)
3949 BOOL WINAPI
InternetEnumPerSiteCookieDecisionA( LPSTR pszSiteName
, unsigned long *pcSiteNameSize
,
3950 unsigned long *pdwDecision
, unsigned long dwIndex
)
3952 FIXME("(%s, %p, %p, 0x%08lx) stub\n",
3953 debugstr_a(pszSiteName
), pcSiteNameSize
, pdwDecision
, dwIndex
);
3957 BOOL WINAPI
InternetEnumPerSiteCookieDecisionW( LPWSTR pszSiteName
, unsigned long *pcSiteNameSize
,
3958 unsigned long *pdwDecision
, unsigned long dwIndex
)
3960 FIXME("(%s, %p, %p, 0x%08lx) stub\n",
3961 debugstr_w(pszSiteName
), pcSiteNameSize
, pdwDecision
, dwIndex
);
3965 BOOL WINAPI
InternetGetCookieExA( LPCSTR pchURL
, LPCSTR pchCookieName
, LPSTR pchCookieData
,
3966 LPDWORD pcchCookieData
, DWORD dwFlags
, LPVOID lpReserved
)
3968 FIXME("(%s, %s, %s, %p, 0x%08lx, %p) stub\n",
3969 debugstr_a(pchURL
), debugstr_a(pchCookieName
), debugstr_a(pchCookieData
),
3970 pcchCookieData
, dwFlags
, lpReserved
);
3974 BOOL WINAPI
InternetGetCookieExW( LPCWSTR pchURL
, LPCWSTR pchCookieName
, LPWSTR pchCookieData
,
3975 LPDWORD pcchCookieData
, DWORD dwFlags
, LPVOID lpReserved
)
3977 FIXME("(%s, %s, %s, %p, 0x%08lx, %p) stub\n",
3978 debugstr_w(pchURL
), debugstr_w(pchCookieName
), debugstr_w(pchCookieData
),
3979 pcchCookieData
, dwFlags
, lpReserved
);
3983 BOOL WINAPI
InternetGetPerSiteCookieDecisionA( LPCSTR pwchHostName
, unsigned long *pResult
)
3985 FIXME("(%s, %p) stub\n", debugstr_a(pwchHostName
), pResult
);
3989 BOOL WINAPI
InternetGetPerSiteCookieDecisionW( LPCWSTR pwchHostName
, unsigned long *pResult
)
3991 FIXME("(%s, %p) stub\n", debugstr_w(pwchHostName
), pResult
);
3995 BOOL WINAPI
InternetSetPerSiteCookieDecisionA( LPCSTR pchHostName
, DWORD dwDecision
)
3997 FIXME("(%s, 0x%08lx) stub\n", debugstr_a(pchHostName
), dwDecision
);
4001 BOOL WINAPI
InternetSetPerSiteCookieDecisionW( LPCWSTR pchHostName
, DWORD dwDecision
)
4003 FIXME("(%s, 0x%08lx) stub\n", debugstr_w(pchHostName
), dwDecision
);
4007 DWORD WINAPI
InternetSetCookieExA( LPCSTR lpszURL
, LPCSTR lpszCookieName
, LPCSTR lpszCookieData
,
4008 DWORD dwFlags
, DWORD_PTR dwReserved
)
4010 FIXME("(%s, %s, %s, 0x%08lx, 0x%08lx) stub\n",
4011 debugstr_a(lpszURL
), debugstr_a(lpszCookieName
), debugstr_a(lpszCookieData
),
4012 dwFlags
, dwReserved
);
4016 DWORD WINAPI
InternetSetCookieExW( LPCWSTR lpszURL
, LPCWSTR lpszCookieName
, LPCWSTR lpszCookieData
,
4017 DWORD dwFlags
, DWORD_PTR dwReserved
)
4019 FIXME("(%s, %s, %s, 0x%08lx, 0x%08lx) stub\n",
4020 debugstr_w(lpszURL
), debugstr_w(lpszCookieName
), debugstr_w(lpszCookieData
),
4021 dwFlags
, dwReserved
);
4025 BOOL WINAPI
ResumeSuspendedDownload( HINTERNET hInternet
, DWORD dwError
)
4027 FIXME("(%p, 0x%08lx) stub\n", hInternet
, dwError
);