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
)
264 TRACE("%p,%lx,%p\n", hinstDLL
, fdwReason
, lpvReserved
);
267 case DLL_PROCESS_ATTACH
:
269 if (0 != WSAStartup(MAKEWORD(1, 1), &wsaData
)) {
273 g_dwTlsErrIndex
= TlsAlloc();
275 if (g_dwTlsErrIndex
== TLS_OUT_OF_INDEXES
) {
280 hQuitEvent
= CreateEventW(0, TRUE
, FALSE
, NULL
);
281 hWorkEvent
= CreateEventW(0, FALSE
, FALSE
, NULL
);
282 InitializeCriticalSection(&csQueue
);
284 URLCacheContainers_CreateDefaults();
287 dwNumIdleThreads
= 0;
290 WININET_hModule
= (HMODULE
)hinstDLL
;
292 case DLL_THREAD_ATTACH
:
294 LPWITHREADERROR lpwite
= HeapAlloc(GetProcessHeap(), 0, sizeof(WITHREADERROR
));
298 TlsSetValue(g_dwTlsErrIndex
, (LPVOID
)lpwite
);
302 case DLL_THREAD_DETACH
:
303 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
305 LPVOID lpwite
= TlsGetValue(g_dwTlsErrIndex
);
306 HeapFree(GetProcessHeap(), 0, lpwite
);
310 case DLL_PROCESS_DETACH
:
312 URLCacheContainers_DeleteAll();
314 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
316 HeapFree(GetProcessHeap(), 0, TlsGetValue(g_dwTlsErrIndex
));
317 TlsFree(g_dwTlsErrIndex
);
320 SetEvent(hQuitEvent
);
322 CloseHandle(hQuitEvent
);
323 CloseHandle(hWorkEvent
);
324 DeleteCriticalSection(&csQueue
);
333 /***********************************************************************
334 * InternetInitializeAutoProxyDll (WININET.@)
336 * Setup the internal proxy
345 BOOL WINAPI
InternetInitializeAutoProxyDll(DWORD dwReserved
)
348 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
352 /***********************************************************************
353 * DetectAutoProxyUrl (WININET.@)
355 * Auto detect the proxy url
361 BOOL WINAPI
DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl
,
362 DWORD dwAutoProxyUrlLength
, DWORD dwDetectFlags
)
365 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
370 /***********************************************************************
371 * INTERNET_ConfigureProxyFromReg
374 * The proxy may be specified in the form 'http=proxy.my.org'
375 * Presumably that means there can be ftp=ftpproxy.my.org too.
377 static BOOL
INTERNET_ConfigureProxyFromReg( LPWININETAPPINFOW lpwai
)
380 DWORD r
, keytype
, len
, enabled
;
381 LPCSTR lpszInternetSettings
=
382 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
383 static const WCHAR szProxyServer
[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
385 r
= RegOpenKeyA(HKEY_CURRENT_USER
, lpszInternetSettings
, &key
);
386 if ( r
!= ERROR_SUCCESS
)
389 len
= sizeof enabled
;
390 r
= RegQueryValueExA( key
, "ProxyEnable", NULL
, &keytype
,
391 (BYTE
*)&enabled
, &len
);
392 if( (r
== ERROR_SUCCESS
) && enabled
)
394 TRACE("Proxy is enabled.\n");
396 /* figure out how much memory the proxy setting takes */
397 r
= RegQueryValueExW( key
, szProxyServer
, NULL
, &keytype
,
399 if( (r
== ERROR_SUCCESS
) && len
&& (keytype
== REG_SZ
) )
402 static const WCHAR szHttp
[] = {'h','t','t','p','=',0};
404 szProxy
=HeapAlloc( GetProcessHeap(), 0, len
);
405 RegQueryValueExW( key
, szProxyServer
, NULL
, &keytype
,
406 (BYTE
*)szProxy
, &len
);
408 /* find the http proxy, and strip away everything else */
409 p
= strstrW( szProxy
, szHttp
);
412 p
+= lstrlenW(szHttp
);
413 lstrcpyW( szProxy
, p
);
415 p
= strchrW( szProxy
, ' ' );
419 lpwai
->dwAccessType
= INTERNET_OPEN_TYPE_PROXY
;
420 lpwai
->lpszProxy
= szProxy
;
422 TRACE("http proxy = %s\n", debugstr_w(lpwai
->lpszProxy
));
425 ERR("Couldn't read proxy server settings.\n");
428 TRACE("Proxy is not enabled.\n");
434 /***********************************************************************
435 * dump_INTERNET_FLAGS
437 * Helper function to TRACE the internet flags.
443 static void dump_INTERNET_FLAGS(DWORD dwFlags
)
445 #define FE(x) { x, #x }
446 static const wininet_flag_info flag
[] = {
447 FE(INTERNET_FLAG_RELOAD
),
448 FE(INTERNET_FLAG_RAW_DATA
),
449 FE(INTERNET_FLAG_EXISTING_CONNECT
),
450 FE(INTERNET_FLAG_ASYNC
),
451 FE(INTERNET_FLAG_PASSIVE
),
452 FE(INTERNET_FLAG_NO_CACHE_WRITE
),
453 FE(INTERNET_FLAG_MAKE_PERSISTENT
),
454 FE(INTERNET_FLAG_FROM_CACHE
),
455 FE(INTERNET_FLAG_SECURE
),
456 FE(INTERNET_FLAG_KEEP_CONNECTION
),
457 FE(INTERNET_FLAG_NO_AUTO_REDIRECT
),
458 FE(INTERNET_FLAG_READ_PREFETCH
),
459 FE(INTERNET_FLAG_NO_COOKIES
),
460 FE(INTERNET_FLAG_NO_AUTH
),
461 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL
),
462 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP
),
463 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS
),
464 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID
),
465 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID
),
466 FE(INTERNET_FLAG_RESYNCHRONIZE
),
467 FE(INTERNET_FLAG_HYPERLINK
),
468 FE(INTERNET_FLAG_NO_UI
),
469 FE(INTERNET_FLAG_PRAGMA_NOCACHE
),
470 FE(INTERNET_FLAG_CACHE_ASYNC
),
471 FE(INTERNET_FLAG_FORMS_SUBMIT
),
472 FE(INTERNET_FLAG_NEED_FILE
),
473 FE(INTERNET_FLAG_TRANSFER_ASCII
),
474 FE(INTERNET_FLAG_TRANSFER_BINARY
)
479 for (i
= 0; i
< (sizeof(flag
) / sizeof(flag
[0])); i
++) {
480 if (flag
[i
].val
& dwFlags
) {
481 TRACE(" %s", flag
[i
].name
);
482 dwFlags
&= ~flag
[i
].val
;
486 TRACE(" Unknown flags (%08lx)\n", dwFlags
);
491 /***********************************************************************
492 * InternetOpenW (WININET.@)
494 * Per-application initialization of wininet
497 * HINTERNET on success
501 HINTERNET WINAPI
InternetOpenW(LPCWSTR lpszAgent
, DWORD dwAccessType
,
502 LPCWSTR lpszProxy
, LPCWSTR lpszProxyBypass
, DWORD dwFlags
)
504 LPWININETAPPINFOW lpwai
= NULL
;
505 HINTERNET handle
= NULL
;
507 if (TRACE_ON(wininet
)) {
508 #define FE(x) { x, #x }
509 static const wininet_flag_info access_type
[] = {
510 FE(INTERNET_OPEN_TYPE_PRECONFIG
),
511 FE(INTERNET_OPEN_TYPE_DIRECT
),
512 FE(INTERNET_OPEN_TYPE_PROXY
),
513 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY
)
517 const char *access_type_str
= "Unknown";
519 TRACE("(%s, %li, %s, %s, %li)\n", debugstr_w(lpszAgent
), dwAccessType
,
520 debugstr_w(lpszProxy
), debugstr_w(lpszProxyBypass
), dwFlags
);
521 for (i
= 0; i
< (sizeof(access_type
) / sizeof(access_type
[0])); i
++) {
522 if (access_type
[i
].val
== dwAccessType
) {
523 access_type_str
= access_type
[i
].name
;
527 TRACE(" access type : %s\n", access_type_str
);
529 dump_INTERNET_FLAGS(dwFlags
);
532 /* Clear any error information */
533 INTERNET_SetLastError(0);
535 lpwai
= HeapAlloc(GetProcessHeap(), 0, sizeof(WININETAPPINFOW
));
538 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
542 memset(lpwai
, 0, sizeof(WININETAPPINFOW
));
543 lpwai
->hdr
.htype
= WH_HINIT
;
544 lpwai
->hdr
.lpwhparent
= NULL
;
545 lpwai
->hdr
.dwFlags
= dwFlags
;
546 lpwai
->hdr
.dwRefCount
= 1;
547 lpwai
->hdr
.destroy
= INTERNET_CloseHandle
;
548 lpwai
->dwAccessType
= dwAccessType
;
549 lpwai
->lpszProxyUsername
= NULL
;
550 lpwai
->lpszProxyPassword
= NULL
;
552 handle
= WININET_AllocHandle( &lpwai
->hdr
);
555 HeapFree( GetProcessHeap(), 0, lpwai
);
556 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
560 if (NULL
!= lpszAgent
)
562 lpwai
->lpszAgent
= HeapAlloc( GetProcessHeap(),0,
563 (strlenW(lpszAgent
)+1)*sizeof(WCHAR
));
564 if (lpwai
->lpszAgent
)
565 lstrcpyW( lpwai
->lpszAgent
, lpszAgent
);
567 if(dwAccessType
== INTERNET_OPEN_TYPE_PRECONFIG
)
568 INTERNET_ConfigureProxyFromReg( lpwai
);
569 else if (NULL
!= lpszProxy
)
571 lpwai
->lpszProxy
= HeapAlloc( GetProcessHeap(), 0,
572 (strlenW(lpszProxy
)+1)*sizeof(WCHAR
));
573 if (lpwai
->lpszProxy
)
574 lstrcpyW( lpwai
->lpszProxy
, lpszProxy
);
577 if (NULL
!= lpszProxyBypass
)
579 lpwai
->lpszProxyBypass
= HeapAlloc( GetProcessHeap(), 0,
580 (strlenW(lpszProxyBypass
)+1)*sizeof(WCHAR
));
581 if (lpwai
->lpszProxyBypass
)
582 lstrcpyW( lpwai
->lpszProxyBypass
, lpszProxyBypass
);
587 WININET_Release( &lpwai
->hdr
);
589 TRACE("returning %p\n", lpwai
);
595 /***********************************************************************
596 * InternetOpenA (WININET.@)
598 * Per-application initialization of wininet
601 * HINTERNET on success
605 HINTERNET WINAPI
InternetOpenA(LPCSTR lpszAgent
, DWORD dwAccessType
,
606 LPCSTR lpszProxy
, LPCSTR lpszProxyBypass
, DWORD dwFlags
)
608 HINTERNET rc
= (HINTERNET
)NULL
;
610 WCHAR
*szAgent
= NULL
, *szProxy
= NULL
, *szBypass
= NULL
;
612 TRACE("(%s, 0x%08lx, %s, %s, 0x%08lx)\n", debugstr_a(lpszAgent
),
613 dwAccessType
, debugstr_a(lpszProxy
), debugstr_a(lpszProxyBypass
), dwFlags
);
617 len
= MultiByteToWideChar(CP_ACP
, 0, lpszAgent
, -1, NULL
, 0);
618 szAgent
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
619 MultiByteToWideChar(CP_ACP
, 0, lpszAgent
, -1, szAgent
, len
);
624 len
= MultiByteToWideChar(CP_ACP
, 0, lpszProxy
, -1, NULL
, 0);
625 szProxy
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
626 MultiByteToWideChar(CP_ACP
, 0, lpszProxy
, -1, szProxy
, len
);
629 if( lpszProxyBypass
)
631 len
= MultiByteToWideChar(CP_ACP
, 0, lpszProxyBypass
, -1, NULL
, 0);
632 szBypass
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
633 MultiByteToWideChar(CP_ACP
, 0, lpszProxyBypass
, -1, szBypass
, len
);
636 rc
= InternetOpenW(szAgent
, dwAccessType
, szProxy
, szBypass
, dwFlags
);
638 HeapFree(GetProcessHeap(), 0, szAgent
);
639 HeapFree(GetProcessHeap(), 0, szProxy
);
640 HeapFree(GetProcessHeap(), 0, szBypass
);
645 /***********************************************************************
646 * InternetGetLastResponseInfoA (WININET.@)
648 * Return last wininet error description on the calling thread
651 * TRUE on success of writing to buffer
655 BOOL WINAPI
InternetGetLastResponseInfoA(LPDWORD lpdwError
,
656 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
658 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
662 *lpdwError
= lpwite
->dwError
;
665 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
666 *lpdwBufferLength
= strlen(lpszBuffer
);
669 *lpdwBufferLength
= 0;
674 /***********************************************************************
675 * InternetGetLastResponseInfoW (WININET.@)
677 * Return last wininet error description on the calling thread
680 * TRUE on success of writing to buffer
684 BOOL WINAPI
InternetGetLastResponseInfoW(LPDWORD lpdwError
,
685 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
687 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
691 *lpdwError
= lpwite
->dwError
;
694 memcpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
695 *lpdwBufferLength
= lstrlenW(lpszBuffer
);
698 *lpdwBufferLength
= 0;
703 /***********************************************************************
704 * InternetGetConnectedState (WININET.@)
706 * Return connected state
710 * if lpdwStatus is not null, return the status (off line,
711 * modem, lan...) in it.
712 * FALSE if not connected
714 BOOL WINAPI
InternetGetConnectedState(LPDWORD lpdwStatus
, DWORD dwReserved
)
716 TRACE("(%p, 0x%08lx)\n", lpdwStatus
, dwReserved
);
719 FIXME("always returning LAN connection.\n");
720 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
726 /***********************************************************************
727 * InternetGetConnectedStateExW (WININET.@)
729 * Return connected state
733 * lpdwStatus [O] Flags specifying the status of the internet connection.
734 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
735 * dwNameLen [I] Size of the buffer, in characters.
736 * dwReserved [I] Reserved. Must be set to 0.
740 * if lpdwStatus is not null, return the status (off line,
741 * modem, lan...) in it.
742 * FALSE if not connected
745 * If the system has no available network connections, an empty string is
746 * stored in lpszConnectionName. If there is a LAN connection, a localized
747 * "LAN Connection" string is stored. Presumably, if only a dial-up
748 * connection is available then the name of the dial-up connection is
749 * returned. Why any application, other than the "Internet Settings" CPL,
750 * would want to use this function instead of the simpler InternetGetConnectedStateW
751 * function is beyond me.
753 BOOL WINAPI
InternetGetConnectedStateExW(LPDWORD lpdwStatus
, LPWSTR lpszConnectionName
,
754 DWORD dwNameLen
, DWORD dwReserved
)
756 TRACE("(%p, %p, %ld, 0x%08lx)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
763 FIXME("always returning LAN connection.\n");
764 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
766 return LoadStringW(WININET_hModule
, IDS_LANCONNECTION
, lpszConnectionName
, dwNameLen
);
770 /***********************************************************************
771 * InternetGetConnectedStateExA (WININET.@)
773 BOOL WINAPI
InternetGetConnectedStateExA(LPDWORD lpdwStatus
, LPSTR lpszConnectionName
,
774 DWORD dwNameLen
, DWORD dwReserved
)
776 LPWSTR lpwszConnectionName
= NULL
;
779 TRACE("(%p, %p, %ld, 0x%08lx)\n", lpdwStatus
, lpszConnectionName
, dwNameLen
, dwReserved
);
781 if (lpszConnectionName
&& dwNameLen
> 0)
782 lpwszConnectionName
= HeapAlloc(GetProcessHeap(), 0, dwNameLen
* sizeof(WCHAR
));
784 rc
= InternetGetConnectedStateExW(lpdwStatus
,lpwszConnectionName
, dwNameLen
,
786 if (rc
&& lpwszConnectionName
)
788 WideCharToMultiByte(CP_ACP
,0,lpwszConnectionName
,-1,lpszConnectionName
,
789 dwNameLen
, NULL
, NULL
);
791 HeapFree(GetProcessHeap(),0,lpwszConnectionName
);
798 /***********************************************************************
799 * InternetConnectW (WININET.@)
801 * Open a ftp, gopher or http session
804 * HINTERNET a session handle on success
808 HINTERNET WINAPI
InternetConnectW(HINTERNET hInternet
,
809 LPCWSTR lpszServerName
, INTERNET_PORT nServerPort
,
810 LPCWSTR lpszUserName
, LPCWSTR lpszPassword
,
811 DWORD dwService
, DWORD dwFlags
, DWORD dwContext
)
813 LPWININETAPPINFOW hIC
;
814 HINTERNET rc
= (HINTERNET
) NULL
;
816 TRACE("(%p, %s, %i, %s, %s, %li, %li, %li)\n", hInternet
, debugstr_w(lpszServerName
),
817 nServerPort
, debugstr_w(lpszUserName
), debugstr_w(lpszPassword
),
818 dwService
, dwFlags
, dwContext
);
820 /* Clear any error information */
821 INTERNET_SetLastError(0);
822 hIC
= (LPWININETAPPINFOW
) WININET_GetObject( hInternet
);
823 if ( (hIC
== NULL
) || (hIC
->hdr
.htype
!= WH_HINIT
) )
828 case INTERNET_SERVICE_FTP
:
829 rc
= FTP_Connect(hIC
, lpszServerName
, nServerPort
,
830 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
833 case INTERNET_SERVICE_HTTP
:
834 rc
= HTTP_Connect(hIC
, lpszServerName
, nServerPort
,
835 lpszUserName
, lpszPassword
, dwFlags
, dwContext
, 0);
838 case INTERNET_SERVICE_GOPHER
:
844 WININET_Release( &hIC
->hdr
);
846 TRACE("returning %p\n", rc
);
851 /***********************************************************************
852 * InternetConnectA (WININET.@)
854 * Open a ftp, gopher or http session
857 * HINTERNET a session handle on success
861 HINTERNET WINAPI
InternetConnectA(HINTERNET hInternet
,
862 LPCSTR lpszServerName
, INTERNET_PORT nServerPort
,
863 LPCSTR lpszUserName
, LPCSTR lpszPassword
,
864 DWORD dwService
, DWORD dwFlags
, DWORD dwContext
)
866 HINTERNET rc
= (HINTERNET
)NULL
;
868 LPWSTR szServerName
= NULL
;
869 LPWSTR szUserName
= NULL
;
870 LPWSTR szPassword
= NULL
;
874 len
= MultiByteToWideChar(CP_ACP
, 0, lpszServerName
, -1, NULL
, 0);
875 szServerName
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
876 MultiByteToWideChar(CP_ACP
, 0, lpszServerName
, -1, szServerName
, len
);
880 len
= MultiByteToWideChar(CP_ACP
, 0, lpszUserName
, -1, NULL
, 0);
881 szUserName
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
882 MultiByteToWideChar(CP_ACP
, 0, lpszUserName
, -1, szUserName
, len
);
886 len
= MultiByteToWideChar(CP_ACP
, 0, lpszPassword
, -1, NULL
, 0);
887 szPassword
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
888 MultiByteToWideChar(CP_ACP
, 0, lpszPassword
, -1, szPassword
, len
);
892 rc
= InternetConnectW(hInternet
, szServerName
, nServerPort
,
893 szUserName
, szPassword
, dwService
, dwFlags
, dwContext
);
895 HeapFree(GetProcessHeap(), 0, szServerName
);
896 HeapFree(GetProcessHeap(), 0, szUserName
);
897 HeapFree(GetProcessHeap(), 0, szPassword
);
902 /***********************************************************************
903 * InternetFindNextFileA (WININET.@)
905 * Continues a file search from a previous call to FindFirstFile
912 BOOL WINAPI
InternetFindNextFileA(HINTERNET hFind
, LPVOID lpvFindData
)
917 ret
= InternetFindNextFileW(hFind
, lpvFindData
?&fd
:NULL
);
919 WININET_find_data_WtoA(&fd
, (LPWIN32_FIND_DATAA
)lpvFindData
);
923 /***********************************************************************
924 * InternetFindNextFileW (WININET.@)
926 * Continues a file search from a previous call to FindFirstFile
933 BOOL WINAPI
InternetFindNextFileW(HINTERNET hFind
, LPVOID lpvFindData
)
935 LPWININETAPPINFOW hIC
= NULL
;
936 LPWININETFINDNEXTW lpwh
;
937 BOOL bSuccess
= FALSE
;
941 lpwh
= (LPWININETFINDNEXTW
) WININET_GetObject( hFind
);
942 if (NULL
== lpwh
|| lpwh
->hdr
.htype
!= WH_HFINDNEXT
)
944 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
948 hIC
= GET_HWININET_FROM_LPWININETFINDNEXT(lpwh
);
949 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
)
951 WORKREQUEST workRequest
;
952 struct WORKREQ_INTERNETFINDNEXTW
*req
;
954 workRequest
.asyncall
= INTERNETFINDNEXTW
;
955 workRequest
.hdr
= WININET_AddRef( &lpwh
->hdr
);
956 req
= &workRequest
.u
.InternetFindNextW
;
957 req
->lpFindFileData
= lpvFindData
;
959 bSuccess
= INTERNET_AsyncCall(&workRequest
);
963 bSuccess
= INTERNET_FindNextFileW(lpwh
, lpvFindData
);
967 WININET_Release( &lpwh
->hdr
);
971 /***********************************************************************
972 * INTERNET_FindNextFileW (Internal)
974 * Continues a file search from a previous call to FindFirstFile
981 BOOL WINAPI
INTERNET_FindNextFileW(LPWININETFINDNEXTW lpwh
, LPVOID lpvFindData
)
983 BOOL bSuccess
= TRUE
;
984 LPWIN32_FIND_DATAW lpFindFileData
;
988 assert (lpwh
->hdr
.htype
== WH_HFINDNEXT
);
990 /* Clear any error information */
991 INTERNET_SetLastError(0);
993 if (lpwh
->hdr
.lpwhparent
->htype
!= WH_HFTPSESSION
)
995 FIXME("Only FTP find next supported\n");
996 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
1000 TRACE("index(%ld) size(%ld)\n", lpwh
->index
, lpwh
->size
);
1002 lpFindFileData
= (LPWIN32_FIND_DATAW
) lpvFindData
;
1003 ZeroMemory(lpFindFileData
, sizeof(WIN32_FIND_DATAA
));
1005 if (lpwh
->index
>= lpwh
->size
)
1007 INTERNET_SetLastError(ERROR_NO_MORE_FILES
);
1012 FTP_ConvertFileProp(&lpwh
->lpafp
[lpwh
->index
], lpFindFileData
);
1015 TRACE("\nName: %s\nSize: %ld\n", debugstr_w(lpFindFileData
->cFileName
), lpFindFileData
->nFileSizeLow
);
1019 if (lpwh
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
)
1021 INTERNET_ASYNC_RESULT iar
;
1023 iar
.dwResult
= (DWORD
)bSuccess
;
1024 iar
.dwError
= iar
.dwError
= bSuccess
? ERROR_SUCCESS
:
1025 INTERNET_GetLastError();
1027 INTERNET_SendCallback(&lpwh
->hdr
, lpwh
->hdr
.dwContext
,
1028 INTERNET_STATUS_REQUEST_COMPLETE
, &iar
,
1029 sizeof(INTERNET_ASYNC_RESULT
));
1036 /***********************************************************************
1037 * INTERNET_CloseHandle (internal)
1039 * Close internet handle
1045 static VOID
INTERNET_CloseHandle(LPWININETHANDLEHEADER hdr
)
1047 LPWININETAPPINFOW lpwai
= (LPWININETAPPINFOW
) hdr
;
1049 TRACE("%p\n",lpwai
);
1051 HeapFree(GetProcessHeap(), 0, lpwai
->lpszAgent
);
1052 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxy
);
1053 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxyBypass
);
1054 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxyUsername
);
1055 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxyPassword
);
1056 HeapFree(GetProcessHeap(), 0, lpwai
);
1060 /***********************************************************************
1061 * InternetCloseHandle (WININET.@)
1063 * Generic close handle function
1070 BOOL WINAPI
InternetCloseHandle(HINTERNET hInternet
)
1072 LPWININETHANDLEHEADER lpwh
;
1074 TRACE("%p\n",hInternet
);
1076 lpwh
= WININET_GetObject( hInternet
);
1079 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
1083 /* FIXME: native appears to send this from the equivalent of
1084 * WININET_Release */
1085 INTERNET_SendCallback(lpwh
, lpwh
->dwContext
,
1086 INTERNET_STATUS_HANDLE_CLOSING
, &hInternet
,
1089 if( lpwh
->lpwhparent
)
1090 WININET_Release( lpwh
->lpwhparent
);
1091 WININET_FreeHandle( hInternet
);
1092 WININET_Release( lpwh
);
1098 /***********************************************************************
1099 * ConvertUrlComponentValue (Internal)
1101 * Helper function for InternetCrackUrlW
1104 static void ConvertUrlComponentValue(LPSTR
* lppszComponent
, LPDWORD dwComponentLen
,
1105 LPWSTR lpwszComponent
, DWORD dwwComponentLen
,
1106 LPCSTR lpszStart
, LPCWSTR lpwszStart
)
1108 TRACE("%p %p %p %ld %p %p\n", lppszComponent
, dwComponentLen
, lpwszComponent
, dwwComponentLen
, lpszStart
, lpwszStart
);
1109 if (*dwComponentLen
!= 0)
1111 DWORD nASCIILength
=WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,NULL
,0,NULL
,NULL
);
1112 if (*lppszComponent
== NULL
)
1114 int nASCIIOffset
=WideCharToMultiByte(CP_ACP
,0,lpwszStart
,lpwszComponent
-lpwszStart
,NULL
,0,NULL
,NULL
);
1115 *lppszComponent
= (LPSTR
)lpszStart
+nASCIIOffset
;
1116 *dwComponentLen
= nASCIILength
;
1120 DWORD ncpylen
= min((*dwComponentLen
)-1, nASCIILength
);
1121 WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,*lppszComponent
,ncpylen
+1,NULL
,NULL
);
1122 (*lppszComponent
)[ncpylen
]=0;
1123 *dwComponentLen
= ncpylen
;
1129 /***********************************************************************
1130 * InternetCrackUrlA (WININET.@)
1132 * Break up URL into its components
1134 * TODO: Handle dwFlags
1141 BOOL WINAPI
InternetCrackUrlA(LPCSTR lpszUrl
, DWORD dwUrlLength
, DWORD dwFlags
,
1142 LPURL_COMPONENTSA lpUrlComponents
)
1145 URL_COMPONENTSW UCW
;
1148 TRACE("(%s %lu %lx %p)\n", debugstr_a(lpszUrl
), dwUrlLength
, dwFlags
, lpUrlComponents
);
1151 nLength
=MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,NULL
,0);
1153 /* if dwUrlLength=-1 then nLength includes null but length to
1154 InternetCrackUrlW should not include it */
1155 if (dwUrlLength
== -1) nLength
--;
1157 lpwszUrl
=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WCHAR
)*nLength
);
1158 MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,lpwszUrl
,nLength
);
1160 memset(&UCW
,0,sizeof(UCW
));
1161 if(lpUrlComponents
->dwHostNameLength
!=0)
1162 UCW
.dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
1163 if(lpUrlComponents
->dwUserNameLength
!=0)
1164 UCW
.dwUserNameLength
=lpUrlComponents
->dwUserNameLength
;
1165 if(lpUrlComponents
->dwPasswordLength
!=0)
1166 UCW
.dwPasswordLength
=lpUrlComponents
->dwPasswordLength
;
1167 if(lpUrlComponents
->dwUrlPathLength
!=0)
1168 UCW
.dwUrlPathLength
=lpUrlComponents
->dwUrlPathLength
;
1169 if(lpUrlComponents
->dwSchemeLength
!=0)
1170 UCW
.dwSchemeLength
=lpUrlComponents
->dwSchemeLength
;
1171 if(lpUrlComponents
->dwExtraInfoLength
!=0)
1172 UCW
.dwExtraInfoLength
=lpUrlComponents
->dwExtraInfoLength
;
1173 if(!InternetCrackUrlW(lpwszUrl
,nLength
,dwFlags
,&UCW
))
1175 HeapFree(GetProcessHeap(), 0, lpwszUrl
);
1179 ConvertUrlComponentValue(&lpUrlComponents
->lpszHostName
, &lpUrlComponents
->dwHostNameLength
,
1180 UCW
.lpszHostName
, UCW
.dwHostNameLength
,
1182 ConvertUrlComponentValue(&lpUrlComponents
->lpszUserName
, &lpUrlComponents
->dwUserNameLength
,
1183 UCW
.lpszUserName
, UCW
.dwUserNameLength
,
1185 ConvertUrlComponentValue(&lpUrlComponents
->lpszPassword
, &lpUrlComponents
->dwPasswordLength
,
1186 UCW
.lpszPassword
, UCW
.dwPasswordLength
,
1188 ConvertUrlComponentValue(&lpUrlComponents
->lpszUrlPath
, &lpUrlComponents
->dwUrlPathLength
,
1189 UCW
.lpszUrlPath
, UCW
.dwUrlPathLength
,
1191 ConvertUrlComponentValue(&lpUrlComponents
->lpszScheme
, &lpUrlComponents
->dwSchemeLength
,
1192 UCW
.lpszScheme
, UCW
.dwSchemeLength
,
1194 ConvertUrlComponentValue(&lpUrlComponents
->lpszExtraInfo
, &lpUrlComponents
->dwExtraInfoLength
,
1195 UCW
.lpszExtraInfo
, UCW
.dwExtraInfoLength
,
1197 lpUrlComponents
->nScheme
=UCW
.nScheme
;
1198 lpUrlComponents
->nPort
=UCW
.nPort
;
1199 HeapFree(GetProcessHeap(), 0, lpwszUrl
);
1201 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", lpszUrl
,
1202 debugstr_an(lpUrlComponents
->lpszScheme
,lpUrlComponents
->dwSchemeLength
),
1203 debugstr_an(lpUrlComponents
->lpszHostName
,lpUrlComponents
->dwHostNameLength
),
1204 debugstr_an(lpUrlComponents
->lpszUrlPath
,lpUrlComponents
->dwUrlPathLength
),
1205 debugstr_an(lpUrlComponents
->lpszExtraInfo
,lpUrlComponents
->dwExtraInfoLength
));
1210 /***********************************************************************
1211 * GetInternetSchemeW (internal)
1217 * INTERNET_SCHEME_UNKNOWN on failure
1220 static INTERNET_SCHEME
GetInternetSchemeW(LPCWSTR lpszScheme
, DWORD nMaxCmp
)
1222 INTERNET_SCHEME iScheme
=INTERNET_SCHEME_UNKNOWN
;
1223 static const WCHAR lpszFtp
[]={'f','t','p',0};
1224 static const WCHAR lpszGopher
[]={'g','o','p','h','e','r',0};
1225 static const WCHAR lpszHttp
[]={'h','t','t','p',0};
1226 static const WCHAR lpszHttps
[]={'h','t','t','p','s',0};
1227 static const WCHAR lpszFile
[]={'f','i','l','e',0};
1228 static const WCHAR lpszNews
[]={'n','e','w','s',0};
1229 static const WCHAR lpszMailto
[]={'m','a','i','l','t','o',0};
1230 static const WCHAR lpszRes
[]={'r','e','s',0};
1231 WCHAR
* tempBuffer
=NULL
;
1232 TRACE("%s %ld\n",debugstr_wn(lpszScheme
, nMaxCmp
), nMaxCmp
);
1233 if(lpszScheme
==NULL
)
1234 return INTERNET_SCHEME_UNKNOWN
;
1236 tempBuffer
=HeapAlloc(GetProcessHeap(),0,(nMaxCmp
+1)*sizeof(WCHAR
));
1237 lstrcpynW(tempBuffer
,lpszScheme
,nMaxCmp
+1);
1238 strlwrW(tempBuffer
);
1239 if (nMaxCmp
==strlenW(lpszFtp
) && !strncmpW(lpszFtp
, tempBuffer
, nMaxCmp
))
1240 iScheme
=INTERNET_SCHEME_FTP
;
1241 else if (nMaxCmp
==strlenW(lpszGopher
) && !strncmpW(lpszGopher
, tempBuffer
, nMaxCmp
))
1242 iScheme
=INTERNET_SCHEME_GOPHER
;
1243 else if (nMaxCmp
==strlenW(lpszHttp
) && !strncmpW(lpszHttp
, tempBuffer
, nMaxCmp
))
1244 iScheme
=INTERNET_SCHEME_HTTP
;
1245 else if (nMaxCmp
==strlenW(lpszHttps
) && !strncmpW(lpszHttps
, tempBuffer
, nMaxCmp
))
1246 iScheme
=INTERNET_SCHEME_HTTPS
;
1247 else if (nMaxCmp
==strlenW(lpszFile
) && !strncmpW(lpszFile
, tempBuffer
, nMaxCmp
))
1248 iScheme
=INTERNET_SCHEME_FILE
;
1249 else if (nMaxCmp
==strlenW(lpszNews
) && !strncmpW(lpszNews
, tempBuffer
, nMaxCmp
))
1250 iScheme
=INTERNET_SCHEME_NEWS
;
1251 else if (nMaxCmp
==strlenW(lpszMailto
) && !strncmpW(lpszMailto
, tempBuffer
, nMaxCmp
))
1252 iScheme
=INTERNET_SCHEME_MAILTO
;
1253 else if (nMaxCmp
==strlenW(lpszRes
) && !strncmpW(lpszRes
, tempBuffer
, nMaxCmp
))
1254 iScheme
=INTERNET_SCHEME_RES
;
1255 HeapFree(GetProcessHeap(),0,tempBuffer
);
1259 /***********************************************************************
1260 * SetUrlComponentValueW (Internal)
1262 * Helper function for InternetCrackUrlW
1265 * lppszComponent [O] Holds the returned string
1266 * dwComponentLen [I] Holds the size of lppszComponent
1267 * [O] Holds the length of the string in lppszComponent without '\0'
1268 * lpszStart [I] Holds the string to copy from
1269 * len [I] Holds the length of lpszStart without '\0'
1276 static BOOL
SetUrlComponentValueW(LPWSTR
* lppszComponent
, LPDWORD dwComponentLen
, LPCWSTR lpszStart
, DWORD len
)
1278 TRACE("%s (%ld)\n", debugstr_wn(lpszStart
,len
), len
);
1280 if ( (*dwComponentLen
== 0) && (*lppszComponent
== NULL
) )
1283 if (*dwComponentLen
!= 0 || *lppszComponent
== NULL
)
1285 if (*lppszComponent
== NULL
)
1287 *lppszComponent
= (LPWSTR
)lpszStart
;
1288 *dwComponentLen
= len
;
1292 DWORD ncpylen
= min((*dwComponentLen
)-1, len
);
1293 memcpy(*lppszComponent
, lpszStart
, ncpylen
*sizeof(WCHAR
));
1294 (*lppszComponent
)[ncpylen
] = '\0';
1295 *dwComponentLen
= ncpylen
;
1302 /***********************************************************************
1303 * InternetCrackUrlW (WININET.@)
1305 BOOL WINAPI
InternetCrackUrlW(LPCWSTR lpszUrl_orig
, DWORD dwUrlLength_orig
, DWORD dwFlags
,
1306 LPURL_COMPONENTSW lpUC
)
1310 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1313 LPCWSTR lpszParam
= NULL
;
1314 BOOL bIsAbsolute
= FALSE
;
1315 LPCWSTR lpszap
, lpszUrl
= lpszUrl_orig
;
1316 LPCWSTR lpszcp
= NULL
;
1317 LPWSTR lpszUrl_decode
= NULL
;
1318 DWORD dwUrlLength
= dwUrlLength_orig
;
1319 const WCHAR lpszSeparators
[3]={';','?',0};
1320 const WCHAR lpszSlash
[2]={'/',0};
1322 dwUrlLength
=strlenW(lpszUrl
);
1324 TRACE("(%s %lu %lx %p)\n", debugstr_w(lpszUrl
), dwUrlLength
, dwFlags
, lpUC
);
1325 if (dwFlags
& ICU_DECODE
)
1327 lpszUrl_decode
=HeapAlloc( GetProcessHeap(), 0, dwUrlLength
* sizeof (WCHAR
) );
1328 if( InternetCanonicalizeUrlW(lpszUrl_orig
, lpszUrl_decode
, &dwUrlLength
, dwFlags
))
1330 lpszUrl
= lpszUrl_decode
;
1335 /* Determine if the URI is absolute. */
1336 while (*lpszap
!= '\0')
1338 if (isalnumW(*lpszap
))
1343 if ((*lpszap
== ':') && (lpszap
- lpszUrl
>= 2))
1350 lpszcp
= lpszUrl
; /* Relative url */
1356 /* Parse <params> */
1357 lpszParam
= strpbrkW(lpszap
, lpszSeparators
);
1358 if (lpszParam
!= NULL
)
1360 SetUrlComponentValueW(&lpUC
->lpszExtraInfo
, &lpUC
->dwExtraInfoLength
,
1361 lpszParam
, dwUrlLength
-(lpszParam
-lpszUrl
));
1364 if (bIsAbsolute
) /* Parse <protocol>:[//<net_loc>] */
1367 static const WCHAR wszAbout
[]={'a','b','o','u','t',':',0};
1369 /* Get scheme first. */
1370 lpUC
->nScheme
= GetInternetSchemeW(lpszUrl
, lpszcp
- lpszUrl
);
1371 SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
,
1372 lpszUrl
, lpszcp
- lpszUrl
);
1374 /* Eat ':' in protocol. */
1377 /* if the scheme is "about", there is no host */
1378 if(strncmpW(wszAbout
,lpszUrl
, lpszcp
- lpszUrl
)==0)
1380 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1381 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1382 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
1387 /* Skip over slashes. */
1399 lpszNetLoc
= strpbrkW(lpszcp
, lpszSlash
);
1403 lpszNetLoc
= min(lpszNetLoc
, lpszParam
);
1405 lpszNetLoc
= lpszParam
;
1407 else if (!lpszNetLoc
)
1408 lpszNetLoc
= lpszcp
+ dwUrlLength
-(lpszcp
-lpszUrl
);
1416 /* [<user>[<:password>]@]<host>[:<port>] */
1417 /* First find the user and password if they exist */
1419 lpszHost
= strchrW(lpszcp
, '@');
1420 if (lpszHost
== NULL
|| lpszHost
> lpszNetLoc
)
1422 /* username and password not specified. */
1423 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
1424 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
1426 else /* Parse out username and password */
1428 LPCWSTR lpszUser
= lpszcp
;
1429 LPCWSTR lpszPasswd
= lpszHost
;
1431 while (lpszcp
< lpszHost
)
1434 lpszPasswd
= lpszcp
;
1439 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
,
1440 lpszUser
, lpszPasswd
- lpszUser
);
1442 if (lpszPasswd
!= lpszHost
)
1444 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
,
1445 lpszPasswd
== lpszHost
? NULL
: lpszPasswd
,
1446 lpszHost
- lpszPasswd
);
1448 lpszcp
++; /* Advance to beginning of host */
1451 /* Parse <host><:port> */
1454 lpszPort
= lpszNetLoc
;
1456 /* special case for res:// URLs: there is no port here, so the host is the
1457 entire string up to the first '/' */
1458 if(lpUC
->nScheme
==INTERNET_SCHEME_RES
)
1460 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1461 lpszHost
, lpszPort
- lpszHost
);
1467 while (lpszcp
< lpszNetLoc
)
1475 /* If the scheme is "file" and the host is just one letter, it's not a host */
1476 if(lpUC
->nScheme
==INTERNET_SCHEME_FILE
&& (lpszPort
-lpszHost
)==1)
1479 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1485 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1486 lpszHost
, lpszPort
- lpszHost
);
1487 if (lpszPort
!= lpszNetLoc
)
1488 lpUC
->nPort
= atoiW(++lpszPort
);
1497 /* Here lpszcp points to:
1499 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1500 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1502 if (lpszcp
!= 0 && *lpszcp
!= '\0' && (!lpszParam
|| lpszcp
< lpszParam
))
1506 /* Only truncate the parameter list if it's already been saved
1507 * in lpUC->lpszExtraInfo.
1509 if (lpszParam
&& lpUC
->dwExtraInfoLength
&& lpUC
->lpszExtraInfo
)
1510 len
= lpszParam
- lpszcp
;
1513 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1514 * newlines if necessary.
1516 LPWSTR lpsznewline
= strchrW(lpszcp
, '\n');
1517 if (lpsznewline
!= NULL
)
1518 len
= lpsznewline
- lpszcp
;
1520 len
= dwUrlLength
-(lpszcp
-lpszUrl
);
1522 SetUrlComponentValueW(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
,
1527 lpUC
->dwUrlPathLength
= 0;
1530 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl
,dwUrlLength
),
1531 debugstr_wn(lpUC
->lpszScheme
,lpUC
->dwSchemeLength
),
1532 debugstr_wn(lpUC
->lpszHostName
,lpUC
->dwHostNameLength
),
1533 debugstr_wn(lpUC
->lpszUrlPath
,lpUC
->dwUrlPathLength
),
1534 debugstr_wn(lpUC
->lpszExtraInfo
,lpUC
->dwExtraInfoLength
));
1537 HeapFree(GetProcessHeap(), 0, lpszUrl_decode
);
1541 /***********************************************************************
1542 * InternetAttemptConnect (WININET.@)
1544 * Attempt to make a connection to the internet
1547 * ERROR_SUCCESS on success
1548 * Error value on failure
1551 DWORD WINAPI
InternetAttemptConnect(DWORD dwReserved
)
1554 return ERROR_SUCCESS
;
1558 /***********************************************************************
1559 * InternetCanonicalizeUrlA (WININET.@)
1561 * Escape unsafe characters and spaces
1568 BOOL WINAPI
InternetCanonicalizeUrlA(LPCSTR lpszUrl
, LPSTR lpszBuffer
,
1569 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
1572 DWORD dwURLFlags
= 0x80000000; /* Don't know what this means */
1573 if(dwFlags
& ICU_DECODE
)
1575 dwURLFlags
|= URL_UNESCAPE
;
1576 dwFlags
&= ~ICU_DECODE
;
1579 if(dwFlags
& ICU_ESCAPE
)
1581 dwURLFlags
|= URL_UNESCAPE
;
1582 dwFlags
&= ~ICU_ESCAPE
;
1584 if(dwFlags
& ICU_BROWSER_MODE
)
1586 dwURLFlags
|= URL_BROWSER_MODE
;
1587 dwFlags
&= ~ICU_BROWSER_MODE
;
1590 FIXME("Unhandled flags 0x%08lx\n", dwFlags
);
1591 TRACE("%s %p %p %08lx\n", debugstr_a(lpszUrl
), lpszBuffer
,
1592 lpdwBufferLength
, dwURLFlags
);
1594 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1595 dwFlags
^= ICU_NO_ENCODE
;
1597 hr
= UrlCanonicalizeA(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwURLFlags
);
1599 return (hr
== S_OK
) ? TRUE
: FALSE
;
1602 /***********************************************************************
1603 * InternetCanonicalizeUrlW (WININET.@)
1605 * Escape unsafe characters and spaces
1612 BOOL WINAPI
InternetCanonicalizeUrlW(LPCWSTR lpszUrl
, LPWSTR lpszBuffer
,
1613 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
1616 DWORD dwURLFlags
= 0x80000000; /* Don't know what this means */
1617 if(dwFlags
& ICU_DECODE
)
1619 dwURLFlags
|= URL_UNESCAPE
;
1620 dwFlags
&= ~ICU_DECODE
;
1623 if(dwFlags
& ICU_ESCAPE
)
1625 dwURLFlags
|= URL_UNESCAPE
;
1626 dwFlags
&= ~ICU_ESCAPE
;
1628 if(dwFlags
& ICU_BROWSER_MODE
)
1630 dwURLFlags
|= URL_BROWSER_MODE
;
1631 dwFlags
&= ~ICU_BROWSER_MODE
;
1634 FIXME("Unhandled flags 0x%08lx\n", dwFlags
);
1635 TRACE("%s %p %p %08lx\n", debugstr_w(lpszUrl
), lpszBuffer
,
1636 lpdwBufferLength
, dwURLFlags
);
1638 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1639 dwFlags
^= ICU_NO_ENCODE
;
1641 hr
= UrlCanonicalizeW(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwURLFlags
);
1643 return (hr
== S_OK
) ? TRUE
: FALSE
;
1647 /***********************************************************************
1648 * InternetSetStatusCallbackA (WININET.@)
1650 * Sets up a callback function which is called as progress is made
1651 * during an operation.
1654 * Previous callback or NULL on success
1655 * INTERNET_INVALID_STATUS_CALLBACK on failure
1658 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackA(
1659 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
1661 INTERNET_STATUS_CALLBACK retVal
;
1662 LPWININETHANDLEHEADER lpwh
;
1664 TRACE("0x%08lx\n", (ULONG
)hInternet
);
1666 lpwh
= WININET_GetObject(hInternet
);
1668 return INTERNET_INVALID_STATUS_CALLBACK
;
1670 lpwh
->dwInternalFlags
&= ~INET_CALLBACKW
;
1671 retVal
= lpwh
->lpfnStatusCB
;
1672 lpwh
->lpfnStatusCB
= lpfnIntCB
;
1674 WININET_Release( lpwh
);
1679 /***********************************************************************
1680 * InternetSetStatusCallbackW (WININET.@)
1682 * Sets up a callback function which is called as progress is made
1683 * during an operation.
1686 * Previous callback or NULL on success
1687 * INTERNET_INVALID_STATUS_CALLBACK on failure
1690 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallbackW(
1691 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
1693 INTERNET_STATUS_CALLBACK retVal
;
1694 LPWININETHANDLEHEADER lpwh
;
1696 TRACE("0x%08lx\n", (ULONG
)hInternet
);
1698 lpwh
= WININET_GetObject(hInternet
);
1700 return INTERNET_INVALID_STATUS_CALLBACK
;
1702 lpwh
->dwInternalFlags
|= INET_CALLBACKW
;
1703 retVal
= lpwh
->lpfnStatusCB
;
1704 lpwh
->lpfnStatusCB
= lpfnIntCB
;
1706 WININET_Release( lpwh
);
1711 /***********************************************************************
1712 * InternetSetFilePointer (WININET.@)
1714 DWORD WINAPI
InternetSetFilePointer(HINTERNET hFile
, LONG lDistanceToMove
,
1715 PVOID pReserved
, DWORD dwMoveContext
, DWORD dwContext
)
1721 /***********************************************************************
1722 * InternetWriteFile (WININET.@)
1724 * Write data to an open internet file
1731 BOOL WINAPI
InternetWriteFile(HINTERNET hFile
, LPCVOID lpBuffer
,
1732 DWORD dwNumOfBytesToWrite
, LPDWORD lpdwNumOfBytesWritten
)
1734 BOOL retval
= FALSE
;
1736 LPWININETHANDLEHEADER lpwh
;
1739 lpwh
= (LPWININETHANDLEHEADER
) WININET_GetObject( hFile
);
1743 switch (lpwh
->htype
)
1747 LPWININETHTTPREQW lpwhr
;
1748 lpwhr
= (LPWININETHTTPREQW
)lpwh
;
1750 TRACE("HTTPREQ %li\n",dwNumOfBytesToWrite
);
1751 retval
= NETCON_send(&lpwhr
->netConnection
, lpBuffer
,
1752 dwNumOfBytesToWrite
, 0, (LPINT
)lpdwNumOfBytesWritten
);
1754 WININET_Release( lpwh
);
1760 nSocket
= ((LPWININETFILE
)lpwh
)->nDataSocket
;
1769 int res
= send(nSocket
, lpBuffer
, dwNumOfBytesToWrite
, 0);
1770 retval
= (res
>= 0);
1771 *lpdwNumOfBytesWritten
= retval
? res
: 0;
1773 WININET_Release( lpwh
);
1779 static BOOL
INTERNET_ReadFile(LPWININETHANDLEHEADER lpwh
, LPVOID lpBuffer
,
1780 DWORD dwNumOfBytesToRead
, LPDWORD pdwNumOfBytesRead
,
1781 BOOL bWait
, BOOL bSendCompletionStatus
)
1783 BOOL retval
= FALSE
;
1786 /* FIXME: this should use NETCON functions! */
1787 switch (lpwh
->htype
)
1790 if (!NETCON_recv(&((LPWININETHTTPREQW
)lpwh
)->netConnection
, lpBuffer
,
1791 dwNumOfBytesToRead
, bWait
? MSG_WAITALL
: 0, (int *)pdwNumOfBytesRead
))
1793 *pdwNumOfBytesRead
= 0;
1794 retval
= TRUE
; /* Under windows, it seems to return 0 even if nothing was read... */
1801 /* FIXME: FTP should use NETCON_ stuff */
1802 nSocket
= ((LPWININETFILE
)lpwh
)->nDataSocket
;
1805 int res
= recv(nSocket
, lpBuffer
, dwNumOfBytesToRead
, bWait
? MSG_WAITALL
: 0);
1806 retval
= (res
>= 0);
1807 *pdwNumOfBytesRead
= retval
? res
: 0;
1815 if (bSendCompletionStatus
)
1817 INTERNET_ASYNC_RESULT iar
;
1819 iar
.dwResult
= retval
;
1820 iar
.dwError
= iar
.dwError
= retval
? ERROR_SUCCESS
:
1821 INTERNET_GetLastError();
1823 INTERNET_SendCallback(lpwh
, lpwh
->dwContext
,
1824 INTERNET_STATUS_REQUEST_COMPLETE
, &iar
,
1825 sizeof(INTERNET_ASYNC_RESULT
));
1830 /***********************************************************************
1831 * InternetReadFile (WININET.@)
1833 * Read data from an open internet file
1840 BOOL WINAPI
InternetReadFile(HINTERNET hFile
, LPVOID lpBuffer
,
1841 DWORD dwNumOfBytesToRead
, LPDWORD pdwNumOfBytesRead
)
1843 LPWININETHANDLEHEADER lpwh
;
1846 TRACE("%p %p %ld %p\n", hFile
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
);
1848 lpwh
= WININET_GetObject( hFile
);
1851 SetLastError(ERROR_INVALID_HANDLE
);
1855 retval
= INTERNET_ReadFile(lpwh
, lpBuffer
, dwNumOfBytesToRead
, pdwNumOfBytesRead
, TRUE
, FALSE
);
1856 WININET_Release( lpwh
);
1858 TRACE("-- %s (bytes read: %ld)\n", retval
? "TRUE": "FALSE", pdwNumOfBytesRead
? *pdwNumOfBytesRead
: -1);
1862 /***********************************************************************
1863 * InternetReadFileExA (WININET.@)
1865 * Read data from an open internet file
1868 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
1869 * lpBuffersOut [I/O] Buffer.
1870 * dwFlags [I] Flags. See notes.
1871 * dwContext [I] Context for callbacks.
1878 * The parameter dwFlags include zero or more of the following flags:
1879 *|IRF_ASYNC - Makes the call asynchronous.
1880 *|IRF_SYNC - Makes the call synchronous.
1881 *|IRF_USE_CONTEXT - Forces dwContext to be used.
1882 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
1884 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
1887 * InternetOpenUrlA(), HttpOpenRequestA()
1889 BOOL WINAPI
InternetReadFileExA(HINTERNET hFile
, LPINTERNET_BUFFERSA lpBuffersOut
,
1890 DWORD dwFlags
, DWORD dwContext
)
1892 BOOL retval
= FALSE
;
1893 LPWININETHANDLEHEADER lpwh
;
1895 TRACE("(%p %p 0x%lx 0x%lx)\n", hFile
, lpBuffersOut
, dwFlags
, dwContext
);
1897 if (dwFlags
& ~(IRF_ASYNC
|IRF_NO_WAIT
))
1898 FIXME("these dwFlags aren't implemented: 0x%lx\n", dwFlags
& ~(IRF_ASYNC
|IRF_NO_WAIT
));
1900 if (lpBuffersOut
->dwStructSize
!= sizeof(*lpBuffersOut
))
1902 SetLastError(ERROR_INVALID_PARAMETER
);
1906 lpwh
= (LPWININETHANDLEHEADER
) WININET_GetObject( hFile
);
1909 SetLastError(ERROR_INVALID_HANDLE
);
1913 /* FIXME: native only does it asynchronously if the amount of data
1914 * requested isn't available. See NtReadFile. */
1915 /* FIXME: IRF_ASYNC may not be the right thing to test here;
1916 * hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC is probably better, but
1917 * we should implement the above first */
1918 if (dwFlags
& IRF_ASYNC
)
1920 WORKREQUEST workRequest
;
1921 struct WORKREQ_INTERNETREADFILEEXA
*req
;
1923 workRequest
.asyncall
= INTERNETREADFILEEXA
;
1924 workRequest
.hdr
= WININET_AddRef( lpwh
);
1925 req
= &workRequest
.u
.InternetReadFileExA
;
1926 req
->lpBuffersOut
= lpBuffersOut
;
1928 retval
= INTERNET_AsyncCall(&workRequest
);
1929 if (!retval
) return FALSE
;
1931 SetLastError(ERROR_IO_PENDING
);
1935 retval
= INTERNET_ReadFile(lpwh
, lpBuffersOut
->lpvBuffer
,
1936 lpBuffersOut
->dwBufferLength
, &lpBuffersOut
->dwBufferLength
,
1937 !(dwFlags
& IRF_NO_WAIT
), FALSE
);
1939 WININET_Release( lpwh
);
1941 TRACE("-- %s (bytes read: %ld)\n", retval
? "TRUE": "FALSE", lpBuffersOut
->dwBufferLength
);
1945 /***********************************************************************
1946 * InternetReadFileExW (WININET.@)
1948 * Read data from an open internet file.
1951 * hFile [I] Handle returned by InternetOpenUrl() or HttpOpenRequest().
1952 * lpBuffersOut [I/O] Buffer.
1953 * dwFlags [I] Flags.
1954 * dwContext [I] Context for callbacks.
1957 * FALSE, last error is set to ERROR_CALL_NOT_IMPLEMENTED
1960 * Not implemented in Wine or native either (as of IE6 SP2).
1963 BOOL WINAPI
InternetReadFileExW(HINTERNET hFile
, LPINTERNET_BUFFERSW lpBuffer
,
1964 DWORD dwFlags
, DWORD dwContext
)
1966 ERR("(%p, %p, 0x%lx, 0x%lx): not implemented in native\n", hFile
, lpBuffer
, dwFlags
, dwContext
);
1968 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1972 /***********************************************************************
1973 * INET_QueryOptionHelper (internal)
1975 static BOOL
INET_QueryOptionHelper(BOOL bIsUnicode
, HINTERNET hInternet
, DWORD dwOption
,
1976 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
1978 LPWININETHANDLEHEADER lpwhh
;
1979 BOOL bSuccess
= FALSE
;
1981 TRACE("(%p, 0x%08lx, %p, %p)\n", hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
1983 lpwhh
= (LPWININETHANDLEHEADER
) WININET_GetObject( hInternet
);
1987 case INTERNET_OPTION_HANDLE_TYPE
:
1993 WARN("Invalid hInternet handle\n");
1994 SetLastError(ERROR_INVALID_HANDLE
);
1998 type
= lpwhh
->htype
;
2000 TRACE("INTERNET_OPTION_HANDLE_TYPE: %ld\n", type
);
2002 if (*lpdwBufferLength
< sizeof(ULONG
))
2003 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2006 memcpy(lpBuffer
, &type
, sizeof(ULONG
));
2009 *lpdwBufferLength
= sizeof(ULONG
);
2013 case INTERNET_OPTION_REQUEST_FLAGS
:
2016 TRACE("INTERNET_OPTION_REQUEST_FLAGS: %ld\n", flags
);
2017 if (*lpdwBufferLength
< sizeof(ULONG
))
2018 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2021 memcpy(lpBuffer
, &flags
, sizeof(ULONG
));
2024 *lpdwBufferLength
= sizeof(ULONG
);
2028 case INTERNET_OPTION_URL
:
2029 case INTERNET_OPTION_DATAFILE_NAME
:
2033 WARN("Invalid hInternet handle\n");
2034 SetLastError(ERROR_INVALID_HANDLE
);
2037 if (lpwhh
->htype
== WH_HHTTPREQ
)
2039 LPWININETHTTPREQW lpreq
= (LPWININETHTTPREQW
) lpwhh
;
2041 static const WCHAR szFmt
[] = {'h','t','t','p',':','/','/','%','s','%','s',0};
2042 static const WCHAR szHost
[] = {'H','o','s','t',0};
2046 Host
= HTTP_GetHeader(lpreq
,szHost
);
2047 sprintfW(url
,szFmt
,Host
->lpszValue
,lpreq
->lpszPath
);
2048 TRACE("INTERNET_OPTION_URL: %s\n",debugstr_w(url
));
2051 sizeRequired
= WideCharToMultiByte(CP_ACP
,0,url
,-1,
2052 lpBuffer
,*lpdwBufferLength
,NULL
,NULL
);
2053 if (sizeRequired
> *lpdwBufferLength
)
2054 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2057 *lpdwBufferLength
= sizeRequired
;
2061 sizeRequired
= (lstrlenW(url
)+1) * sizeof(WCHAR
);
2062 if (*lpdwBufferLength
< sizeRequired
)
2063 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2066 strcpyW(lpBuffer
, url
);
2069 *lpdwBufferLength
= sizeRequired
;
2074 case INTERNET_OPTION_HTTP_VERSION
:
2076 if (*lpdwBufferLength
< sizeof(HTTP_VERSION_INFO
))
2077 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2081 * Presently hardcoded to 1.1
2083 ((HTTP_VERSION_INFO
*)lpBuffer
)->dwMajorVersion
= 1;
2084 ((HTTP_VERSION_INFO
*)lpBuffer
)->dwMinorVersion
= 1;
2087 *lpdwBufferLength
= sizeof(HTTP_VERSION_INFO
);
2090 case INTERNET_OPTION_CONNECTED_STATE
:
2092 DWORD
*pdwConnectedState
= (DWORD
*)lpBuffer
;
2093 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2095 if (*lpdwBufferLength
< sizeof(*pdwConnectedState
))
2096 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2099 *pdwConnectedState
= INTERNET_STATE_CONNECTED
;
2102 *lpdwBufferLength
= sizeof(*pdwConnectedState
);
2105 case INTERNET_OPTION_PROXY
:
2107 LPWININETAPPINFOW lpwai
= (LPWININETAPPINFOW
)lpwhh
;
2108 WININETAPPINFOW wai
;
2112 TRACE("Getting global proxy info\n");
2113 memset(&wai
, 0, sizeof(WININETAPPINFOW
));
2114 INTERNET_ConfigureProxyFromReg( &wai
);
2120 INTERNET_PROXY_INFOW
*pPI
= (INTERNET_PROXY_INFOW
*)lpBuffer
;
2121 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
2123 if (lpwai
->lpszProxy
)
2124 proxyBytesRequired
= (lstrlenW(lpwai
->lpszProxy
) + 1) *
2126 if (lpwai
->lpszProxyBypass
)
2127 proxyBypassBytesRequired
=
2128 (lstrlenW(lpwai
->lpszProxyBypass
) + 1) * sizeof(WCHAR
);
2129 if (*lpdwBufferLength
< sizeof(INTERNET_PROXY_INFOW
) +
2130 proxyBytesRequired
+ proxyBypassBytesRequired
)
2131 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2134 pPI
->dwAccessType
= lpwai
->dwAccessType
;
2135 if (lpwai
->lpszProxy
)
2137 pPI
->lpszProxy
= (LPWSTR
)((LPBYTE
)lpBuffer
+
2138 sizeof(INTERNET_PROXY_INFOW
));
2139 lstrcpyW((LPWSTR
)pPI
->lpszProxy
, lpwai
->lpszProxy
);
2143 pPI
->lpszProxy
= (LPWSTR
)((LPBYTE
)lpBuffer
+
2144 sizeof(INTERNET_PROXY_INFOW
));
2145 *((LPWSTR
)(pPI
->lpszProxy
)) = 0;
2148 if (lpwai
->lpszProxyBypass
)
2150 pPI
->lpszProxyBypass
= (LPWSTR
)((LPBYTE
)lpBuffer
+
2151 sizeof(INTERNET_PROXY_INFOW
) +
2152 proxyBytesRequired
);
2153 lstrcpyW((LPWSTR
)pPI
->lpszProxyBypass
,
2154 lpwai
->lpszProxyBypass
);
2158 pPI
->lpszProxyBypass
= (LPWSTR
)((LPBYTE
)lpBuffer
+
2159 sizeof(INTERNET_PROXY_INFOW
) +
2160 proxyBytesRequired
);
2161 *((LPWSTR
)(pPI
->lpszProxyBypass
)) = 0;
2165 *lpdwBufferLength
= sizeof(INTERNET_PROXY_INFOW
) +
2166 proxyBytesRequired
+ proxyBypassBytesRequired
;
2170 INTERNET_PROXY_INFOA
*pPI
= (INTERNET_PROXY_INFOA
*)lpBuffer
;
2171 DWORD proxyBytesRequired
= 0, proxyBypassBytesRequired
= 0;
2173 if (lpwai
->lpszProxy
)
2174 proxyBytesRequired
= WideCharToMultiByte(CP_ACP
, 0,
2175 lpwai
->lpszProxy
, -1, NULL
, 0, NULL
, NULL
);
2176 if (lpwai
->lpszProxyBypass
)
2177 proxyBypassBytesRequired
= WideCharToMultiByte(CP_ACP
, 0,
2178 lpwai
->lpszProxyBypass
, -1, NULL
, 0, NULL
, NULL
);
2179 if (*lpdwBufferLength
< sizeof(INTERNET_PROXY_INFOA
) +
2180 proxyBytesRequired
+ proxyBypassBytesRequired
)
2181 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2184 pPI
->dwAccessType
= lpwai
->dwAccessType
;
2185 if (lpwai
->lpszProxy
)
2187 pPI
->lpszProxy
= (LPSTR
)((LPBYTE
)lpBuffer
+
2188 sizeof(INTERNET_PROXY_INFOA
));
2189 WideCharToMultiByte(CP_ACP
, 0, lpwai
->lpszProxy
, -1,
2190 (LPSTR
)pPI
->lpszProxy
, proxyBytesRequired
, NULL
, NULL
);
2194 pPI
->lpszProxy
= (LPSTR
)((LPBYTE
)lpBuffer
+
2195 sizeof(INTERNET_PROXY_INFOA
));
2196 *((LPSTR
)(pPI
->lpszProxy
)) = '\0';
2199 if (lpwai
->lpszProxyBypass
)
2201 pPI
->lpszProxyBypass
= (LPSTR
)((LPBYTE
)lpBuffer
+
2202 sizeof(INTERNET_PROXY_INFOA
) + proxyBytesRequired
);
2203 WideCharToMultiByte(CP_ACP
, 0, lpwai
->lpszProxyBypass
,
2204 -1, (LPSTR
)pPI
->lpszProxyBypass
,
2205 proxyBypassBytesRequired
,
2210 pPI
->lpszProxyBypass
= (LPSTR
)((LPBYTE
)lpBuffer
+
2211 sizeof(INTERNET_PROXY_INFOA
) +
2212 proxyBytesRequired
);
2213 *((LPSTR
)(pPI
->lpszProxyBypass
)) = '\0';
2217 *lpdwBufferLength
= sizeof(INTERNET_PROXY_INFOA
) +
2218 proxyBytesRequired
+ proxyBypassBytesRequired
;
2222 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2225 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER: %ld\n", conn
);
2226 if (*lpdwBufferLength
< sizeof(ULONG
))
2227 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2230 memcpy(lpBuffer
, &conn
, sizeof(ULONG
));
2233 *lpdwBufferLength
= sizeof(ULONG
);
2236 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2239 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER: %ld\n", conn
);
2240 if (*lpdwBufferLength
< sizeof(ULONG
))
2241 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2244 memcpy(lpBuffer
, &conn
, sizeof(ULONG
));
2247 *lpdwBufferLength
= sizeof(ULONG
);
2250 case INTERNET_OPTION_SECURITY_FLAGS
:
2251 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2255 FIXME("Stub! %ld\n", dwOption
);
2259 WININET_Release( lpwhh
);
2264 /***********************************************************************
2265 * InternetQueryOptionW (WININET.@)
2267 * Queries an options on the specified handle
2274 BOOL WINAPI
InternetQueryOptionW(HINTERNET hInternet
, DWORD dwOption
,
2275 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2277 return INET_QueryOptionHelper(TRUE
, hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2280 /***********************************************************************
2281 * InternetQueryOptionA (WININET.@)
2283 * Queries an options on the specified handle
2290 BOOL WINAPI
InternetQueryOptionA(HINTERNET hInternet
, DWORD dwOption
,
2291 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
2293 return INET_QueryOptionHelper(FALSE
, hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
2297 /***********************************************************************
2298 * InternetSetOptionW (WININET.@)
2300 * Sets an options on the specified handle
2307 BOOL WINAPI
InternetSetOptionW(HINTERNET hInternet
, DWORD dwOption
,
2308 LPVOID lpBuffer
, DWORD dwBufferLength
)
2310 LPWININETHANDLEHEADER lpwhh
;
2313 TRACE("0x%08lx\n", dwOption
);
2315 lpwhh
= (LPWININETHANDLEHEADER
) WININET_GetObject( hInternet
);
2321 case INTERNET_OPTION_HTTP_VERSION
:
2323 HTTP_VERSION_INFO
* pVersion
=(HTTP_VERSION_INFO
*)lpBuffer
;
2324 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%ld,%ld): STUB\n",pVersion
->dwMajorVersion
,pVersion
->dwMinorVersion
);
2327 case INTERNET_OPTION_ERROR_MASK
:
2329 unsigned long flags
=*(unsigned long*)lpBuffer
;
2330 FIXME("Option INTERNET_OPTION_ERROR_MASK(%ld): STUB\n",flags
);
2333 case INTERNET_OPTION_CODEPAGE
:
2335 unsigned long codepage
=*(unsigned long*)lpBuffer
;
2336 FIXME("Option INTERNET_OPTION_CODEPAGE (%ld): STUB\n",codepage
);
2339 case INTERNET_OPTION_REQUEST_PRIORITY
:
2341 unsigned long priority
=*(unsigned long*)lpBuffer
;
2342 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%ld): STUB\n",priority
);
2345 case INTERNET_OPTION_CONNECT_TIMEOUT
:
2347 unsigned long connecttimeout
=*(unsigned long*)lpBuffer
;
2348 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%ld): STUB\n",connecttimeout
);
2351 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT
:
2353 unsigned long receivetimeout
=*(unsigned long*)lpBuffer
;
2354 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%ld): STUB\n",receivetimeout
);
2357 case INTERNET_OPTION_MAX_CONNS_PER_SERVER
:
2359 unsigned long conns
=*(unsigned long*)lpBuffer
;
2360 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_SERVER (%ld): STUB\n",conns
);
2363 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER
:
2365 unsigned long conns
=*(unsigned long*)lpBuffer
;
2366 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER (%ld): STUB\n",conns
);
2369 case INTERNET_OPTION_RESET_URLCACHE_SESSION
:
2370 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2372 case INTERNET_OPTION_END_BROWSER_SESSION
:
2373 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2375 case INTERNET_OPTION_CONNECTED_STATE
:
2376 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2378 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH
:
2379 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2381 case INTERNET_OPTION_RECEIVE_TIMEOUT
:
2382 FIXME("Option INTERNET_OPTION_RECEIVE_TIMEOUT: STUB\n");
2384 case INTERNET_OPTION_SEND_TIMEOUT
:
2385 FIXME("Option INTERNET_OPTION_SEND_TIMEOUT: STUB\n");
2387 case INTERNET_OPTION_CONNECT_RETRIES
:
2388 FIXME("Option INTERNET_OPTION_CONNECT_RETRIES: STUB\n");
2391 FIXME("Option %ld STUB\n",dwOption
);
2392 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
2396 WININET_Release( lpwhh
);
2402 /***********************************************************************
2403 * InternetSetOptionA (WININET.@)
2405 * Sets an options on the specified handle.
2412 BOOL WINAPI
InternetSetOptionA(HINTERNET hInternet
, DWORD dwOption
,
2413 LPVOID lpBuffer
, DWORD dwBufferLength
)
2421 case INTERNET_OPTION_PROXY
:
2423 LPINTERNET_PROXY_INFOA pi
= (LPINTERNET_PROXY_INFOA
) lpBuffer
;
2424 LPINTERNET_PROXY_INFOW piw
;
2425 DWORD proxlen
, prbylen
;
2428 proxlen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, NULL
, 0);
2429 prbylen
= MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, NULL
, 0);
2430 wlen
= sizeof(*piw
) + proxlen
+ prbylen
;
2431 wbuffer
= HeapAlloc( GetProcessHeap(), 0, wlen
*sizeof(WCHAR
) );
2432 piw
= (LPINTERNET_PROXY_INFOW
) wbuffer
;
2433 piw
->dwAccessType
= pi
->dwAccessType
;
2434 prox
= (LPWSTR
) &piw
[1];
2435 prby
= &prox
[proxlen
+1];
2436 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxy
, -1, prox
, proxlen
);
2437 MultiByteToWideChar( CP_ACP
, 0, pi
->lpszProxyBypass
, -1, prby
, prbylen
);
2438 piw
->lpszProxy
= prox
;
2439 piw
->lpszProxyBypass
= prby
;
2442 case INTERNET_OPTION_USER_AGENT
:
2443 case INTERNET_OPTION_USERNAME
:
2444 case INTERNET_OPTION_PASSWORD
:
2445 wlen
= MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, dwBufferLength
,
2447 wbuffer
= HeapAlloc( GetProcessHeap(), 0, wlen
*sizeof(WCHAR
) );
2448 MultiByteToWideChar( CP_ACP
, 0, lpBuffer
, dwBufferLength
,
2453 wlen
= dwBufferLength
;
2456 r
= InternetSetOptionW(hInternet
,dwOption
, wbuffer
, wlen
);
2458 if( lpBuffer
!= wbuffer
)
2459 HeapFree( GetProcessHeap(), 0, wbuffer
);
2465 /***********************************************************************
2466 * InternetSetOptionExA (WININET.@)
2468 BOOL WINAPI
InternetSetOptionExA(HINTERNET hInternet
, DWORD dwOption
,
2469 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
2471 FIXME("Flags %08lx ignored\n", dwFlags
);
2472 return InternetSetOptionA( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2475 /***********************************************************************
2476 * InternetSetOptionExW (WININET.@)
2478 BOOL WINAPI
InternetSetOptionExW(HINTERNET hInternet
, DWORD dwOption
,
2479 LPVOID lpBuffer
, DWORD dwBufferLength
, DWORD dwFlags
)
2481 FIXME("Flags %08lx ignored\n", dwFlags
);
2482 if( dwFlags
& ~ISO_VALID_FLAGS
)
2484 SetLastError( ERROR_INVALID_PARAMETER
);
2487 return InternetSetOptionW( hInternet
, dwOption
, lpBuffer
, dwBufferLength
);
2490 static const WCHAR WININET_wkday
[7][4] =
2491 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
2492 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
2493 static const WCHAR WININET_month
[12][4] =
2494 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
2495 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
2496 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
2498 /***********************************************************************
2499 * InternetTimeFromSystemTimeA (WININET.@)
2501 BOOL WINAPI
InternetTimeFromSystemTimeA( const SYSTEMTIME
* time
, DWORD format
, LPSTR string
, DWORD size
)
2504 WCHAR stringW
[INTERNET_RFC1123_BUFSIZE
];
2506 TRACE( "%p 0x%08lx %p 0x%08lx\n", time
, format
, string
, size
);
2508 ret
= InternetTimeFromSystemTimeW( time
, format
, stringW
, sizeof(stringW
) );
2509 if (ret
) WideCharToMultiByte( CP_ACP
, 0, stringW
, -1, string
, size
, NULL
, NULL
);
2514 /***********************************************************************
2515 * InternetTimeFromSystemTimeW (WININET.@)
2517 BOOL WINAPI
InternetTimeFromSystemTimeW( const SYSTEMTIME
* time
, DWORD format
, LPWSTR string
, DWORD size
)
2519 static const WCHAR date
[] =
2520 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
2521 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
2523 TRACE( "%p 0x%08lx %p 0x%08lx\n", time
, format
, string
, size
);
2525 if (!time
|| !string
) return FALSE
;
2527 if (format
!= INTERNET_RFC1123_FORMAT
|| size
< INTERNET_RFC1123_BUFSIZE
* sizeof(WCHAR
))
2530 sprintfW( string
, date
,
2531 WININET_wkday
[time
->wDayOfWeek
],
2533 WININET_month
[time
->wMonth
- 1],
2542 /***********************************************************************
2543 * InternetTimeToSystemTimeA (WININET.@)
2545 BOOL WINAPI
InternetTimeToSystemTimeA( LPCSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
2551 TRACE( "%s %p 0x%08lx\n", debugstr_a(string
), time
, reserved
);
2553 len
= MultiByteToWideChar( CP_ACP
, 0, string
, -1, NULL
, 0 );
2554 stringW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
2558 MultiByteToWideChar( CP_ACP
, 0, string
, -1, stringW
, len
);
2559 ret
= InternetTimeToSystemTimeW( stringW
, time
, reserved
);
2560 HeapFree( GetProcessHeap(), 0, stringW
);
2565 /***********************************************************************
2566 * InternetTimeToSystemTimeW (WININET.@)
2568 BOOL WINAPI
InternetTimeToSystemTimeW( LPCWSTR string
, SYSTEMTIME
* time
, DWORD reserved
)
2571 WCHAR
*s
= (LPWSTR
)string
;
2573 TRACE( "%s %p 0x%08lx\n", debugstr_w(string
), time
, reserved
);
2575 if (!string
|| !time
) return FALSE
;
2577 /* Windows does this too */
2578 GetSystemTime( time
);
2580 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
2581 * a SYSTEMTIME structure.
2584 while (*s
&& !isalphaW( *s
)) s
++;
2585 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
2586 time
->wDayOfWeek
= 7;
2588 for (i
= 0; i
< 7; i
++)
2590 if (toupperW( WININET_wkday
[i
][0] ) == toupperW( s
[0] ) &&
2591 toupperW( WININET_wkday
[i
][1] ) == toupperW( s
[1] ) &&
2592 toupperW( WININET_wkday
[i
][2] ) == toupperW( s
[2] ) )
2594 time
->wDayOfWeek
= i
;
2599 if (time
->wDayOfWeek
> 6) return TRUE
;
2600 while (*s
&& !isdigitW( *s
)) s
++;
2601 time
->wDay
= strtolW( s
, &s
, 10 );
2603 while (*s
&& !isalphaW( *s
)) s
++;
2604 if (s
[0] == '\0' || s
[1] == '\0' || s
[2] == '\0') return TRUE
;
2607 for (i
= 0; i
< 12; i
++)
2609 if (toupperW( WININET_month
[i
][0]) == toupperW( s
[0] ) &&
2610 toupperW( WININET_month
[i
][1]) == toupperW( s
[1] ) &&
2611 toupperW( WININET_month
[i
][2]) == toupperW( s
[2] ) )
2613 time
->wMonth
= i
+ 1;
2617 if (time
->wMonth
== 0) return TRUE
;
2619 while (*s
&& !isdigitW( *s
)) s
++;
2620 if (*s
== '\0') return TRUE
;
2621 time
->wYear
= strtolW( s
, &s
, 10 );
2623 while (*s
&& !isdigitW( *s
)) s
++;
2624 if (*s
== '\0') return TRUE
;
2625 time
->wHour
= strtolW( s
, &s
, 10 );
2627 while (*s
&& !isdigitW( *s
)) s
++;
2628 if (*s
== '\0') return TRUE
;
2629 time
->wMinute
= strtolW( s
, &s
, 10 );
2631 while (*s
&& !isdigitW( *s
)) s
++;
2632 if (*s
== '\0') return TRUE
;
2633 time
->wSecond
= strtolW( s
, &s
, 10 );
2635 time
->wMilliseconds
= 0;
2639 /***********************************************************************
2640 * InternetCheckConnectionW (WININET.@)
2642 * Pings a requested host to check internet connection
2645 * TRUE on success and FALSE on failure. If a failure then
2646 * ERROR_NOT_CONNECTED is placed into GetLastError
2649 BOOL WINAPI
InternetCheckConnectionW( LPCWSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
2652 * this is a kludge which runs the resident ping program and reads the output.
2654 * Anyone have a better idea?
2658 static const CHAR ping
[] = "ping -w 1 ";
2659 static const CHAR redirect
[] = " >/dev/null 2>/dev/null";
2660 CHAR
*command
= NULL
;
2668 * Crack or set the Address
2670 if (lpszUrl
== NULL
)
2673 * According to the doc we are supost to use the ip for the next
2674 * server in the WnInet internal server database. I have
2675 * no idea what that is or how to get it.
2677 * So someone needs to implement this.
2679 FIXME("Unimplemented with URL of NULL\n");
2684 URL_COMPONENTSW components
;
2686 ZeroMemory(&components
,sizeof(URL_COMPONENTSW
));
2687 components
.lpszHostName
= (LPWSTR
)&hostW
;
2688 components
.dwHostNameLength
= 1024;
2690 if (!InternetCrackUrlW(lpszUrl
,0,0,&components
))
2693 TRACE("host name : %s\n",debugstr_w(components
.lpszHostName
));
2697 * Build our ping command
2699 len
= WideCharToMultiByte(CP_THREAD_ACP
, 0, hostW
, -1, NULL
, 0, NULL
, NULL
);
2700 command
= HeapAlloc( GetProcessHeap(), 0, strlen(ping
)+len
+strlen(redirect
) );
2701 strcpy(command
,ping
);
2702 WideCharToMultiByte(CP_THREAD_ACP
, 0, hostW
, -1, command
+strlen(ping
), len
, NULL
, NULL
);
2703 strcat(command
,redirect
);
2705 TRACE("Ping command is : %s\n",command
);
2707 status
= system(command
);
2709 TRACE("Ping returned a code of %i\n",status
);
2711 /* Ping return code of 0 indicates success */
2717 HeapFree( GetProcessHeap(), 0, command
);
2719 SetLastError(ERROR_NOT_CONNECTED
);
2725 /***********************************************************************
2726 * InternetCheckConnectionA (WININET.@)
2728 * Pings a requested host to check internet connection
2731 * TRUE on success and FALSE on failure. If a failure then
2732 * ERROR_NOT_CONNECTED is placed into GetLastError
2735 BOOL WINAPI
InternetCheckConnectionA(LPCSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
2741 len
= MultiByteToWideChar(CP_ACP
, 0, lpszUrl
, -1, NULL
, 0);
2742 if (!(szUrl
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
))))
2744 MultiByteToWideChar(CP_ACP
, 0, lpszUrl
, -1, szUrl
, len
);
2745 rc
= InternetCheckConnectionW(szUrl
, dwFlags
, dwReserved
);
2746 HeapFree(GetProcessHeap(), 0, szUrl
);
2752 /**********************************************************
2753 * INTERNET_InternetOpenUrlW (internal)
2758 * handle of connection or NULL on failure
2760 HINTERNET WINAPI
INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC
, LPCWSTR lpszUrl
,
2761 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD dwContext
)
2763 URL_COMPONENTSW urlComponents
;
2764 WCHAR protocol
[32], hostName
[MAXHOSTNAME
], userName
[1024];
2765 WCHAR password
[1024], path
[2048], extra
[1024];
2766 HINTERNET client
= NULL
, client1
= NULL
;
2768 TRACE("(%p, %s, %s, %08lx, %08lx, %08lx)\n", hIC
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
2769 dwHeadersLength
, dwFlags
, dwContext
);
2771 urlComponents
.dwStructSize
= sizeof(URL_COMPONENTSW
);
2772 urlComponents
.lpszScheme
= protocol
;
2773 urlComponents
.dwSchemeLength
= 32;
2774 urlComponents
.lpszHostName
= hostName
;
2775 urlComponents
.dwHostNameLength
= MAXHOSTNAME
;
2776 urlComponents
.lpszUserName
= userName
;
2777 urlComponents
.dwUserNameLength
= 1024;
2778 urlComponents
.lpszPassword
= password
;
2779 urlComponents
.dwPasswordLength
= 1024;
2780 urlComponents
.lpszUrlPath
= path
;
2781 urlComponents
.dwUrlPathLength
= 2048;
2782 urlComponents
.lpszExtraInfo
= extra
;
2783 urlComponents
.dwExtraInfoLength
= 1024;
2784 if(!InternetCrackUrlW(lpszUrl
, strlenW(lpszUrl
), 0, &urlComponents
))
2786 switch(urlComponents
.nScheme
) {
2787 case INTERNET_SCHEME_FTP
:
2788 if(urlComponents
.nPort
== 0)
2789 urlComponents
.nPort
= INTERNET_DEFAULT_FTP_PORT
;
2790 client
= FTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
2791 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
);
2794 client1
= FtpOpenFileW(client
, path
, GENERIC_READ
, dwFlags
, dwContext
);
2795 if(client1
== NULL
) {
2796 InternetCloseHandle(client
);
2801 case INTERNET_SCHEME_HTTP
:
2802 case INTERNET_SCHEME_HTTPS
: {
2803 static const WCHAR szStars
[] = { '*','/','*', 0 };
2804 LPCWSTR accept
[2] = { szStars
, NULL
};
2805 if(urlComponents
.nPort
== 0) {
2806 if(urlComponents
.nScheme
== INTERNET_SCHEME_HTTP
)
2807 urlComponents
.nPort
= INTERNET_DEFAULT_HTTP_PORT
;
2809 urlComponents
.nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
2811 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
2812 client
= HTTP_Connect(hIC
, hostName
, urlComponents
.nPort
,
2813 userName
, password
, dwFlags
, dwContext
, INET_OPENURL
);
2816 client1
= HttpOpenRequestW(client
, NULL
, path
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
2817 if(client1
== NULL
) {
2818 InternetCloseHandle(client
);
2821 HttpAddRequestHeadersW(client1
, lpszHeaders
, dwHeadersLength
, HTTP_ADDREQ_FLAG_ADD
);
2822 if (!HttpSendRequestW(client1
, NULL
, 0, NULL
, 0)) {
2823 InternetCloseHandle(client1
);
2828 case INTERNET_SCHEME_GOPHER
:
2829 /* gopher doesn't seem to be implemented in wine, but it's supposed
2830 * to be supported by InternetOpenUrlA. */
2835 TRACE(" %p <--\n", client1
);
2840 /**********************************************************
2841 * InternetOpenUrlW (WININET.@)
2846 * handle of connection or NULL on failure
2848 HINTERNET WINAPI
InternetOpenUrlW(HINTERNET hInternet
, LPCWSTR lpszUrl
,
2849 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD dwContext
)
2851 HINTERNET ret
= NULL
;
2852 LPWININETAPPINFOW hIC
= NULL
;
2854 if (TRACE_ON(wininet
)) {
2855 TRACE("(%p, %s, %s, %08lx, %08lx, %08lx)\n", hInternet
, debugstr_w(lpszUrl
), debugstr_w(lpszHeaders
),
2856 dwHeadersLength
, dwFlags
, dwContext
);
2858 dump_INTERNET_FLAGS(dwFlags
);
2861 hIC
= (LPWININETAPPINFOW
) WININET_GetObject( hInternet
);
2862 if (NULL
== hIC
|| hIC
->hdr
.htype
!= WH_HINIT
) {
2863 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2867 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
) {
2868 WORKREQUEST workRequest
;
2869 struct WORKREQ_INTERNETOPENURLW
*req
;
2871 workRequest
.asyncall
= INTERNETOPENURLW
;
2872 workRequest
.hdr
= WININET_AddRef( &hIC
->hdr
);
2873 req
= &workRequest
.u
.InternetOpenUrlW
;
2875 req
->lpszUrl
= WININET_strdupW(lpszUrl
);
2879 req
->lpszHeaders
= WININET_strdupW(lpszHeaders
);
2881 req
->lpszHeaders
= 0;
2882 req
->dwHeadersLength
= dwHeadersLength
;
2883 req
->dwFlags
= dwFlags
;
2884 req
->dwContext
= dwContext
;
2886 INTERNET_AsyncCall(&workRequest
);
2888 * This is from windows.
2890 SetLastError(ERROR_IO_PENDING
);
2892 ret
= INTERNET_InternetOpenUrlW(hIC
, lpszUrl
, lpszHeaders
, dwHeadersLength
, dwFlags
, dwContext
);
2897 WININET_Release( &hIC
->hdr
);
2898 TRACE(" %p <--\n", ret
);
2903 /**********************************************************
2904 * InternetOpenUrlA (WININET.@)
2909 * handle of connection or NULL on failure
2911 HINTERNET WINAPI
InternetOpenUrlA(HINTERNET hInternet
, LPCSTR lpszUrl
,
2912 LPCSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD dwContext
)
2914 HINTERNET rc
= (HINTERNET
)NULL
;
2918 LPWSTR szUrl
= NULL
;
2919 LPWSTR szHeaders
= NULL
;
2924 lenUrl
= MultiByteToWideChar(CP_ACP
, 0, lpszUrl
, -1, NULL
, 0 );
2925 szUrl
= HeapAlloc(GetProcessHeap(), 0, lenUrl
*sizeof(WCHAR
));
2927 return (HINTERNET
)NULL
;
2928 MultiByteToWideChar(CP_ACP
, 0, lpszUrl
, -1, szUrl
, lenUrl
);
2932 lenHeaders
= MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, NULL
, 0 );
2933 szHeaders
= HeapAlloc(GetProcessHeap(), 0, lenHeaders
*sizeof(WCHAR
));
2935 HeapFree(GetProcessHeap(), 0, szUrl
);
2936 return (HINTERNET
)NULL
;
2938 MultiByteToWideChar(CP_ACP
, 0, lpszHeaders
, dwHeadersLength
, szHeaders
, lenHeaders
);
2941 rc
= InternetOpenUrlW(hInternet
, szUrl
, szHeaders
,
2942 lenHeaders
, dwFlags
, dwContext
);
2944 HeapFree(GetProcessHeap(), 0, szUrl
);
2945 HeapFree(GetProcessHeap(), 0, szHeaders
);
2951 /***********************************************************************
2952 * INTERNET_SetLastError (internal)
2954 * Set last thread specific error
2959 void INTERNET_SetLastError(DWORD dwError
)
2961 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
2963 SetLastError(dwError
);
2965 lpwite
->dwError
= dwError
;
2969 /***********************************************************************
2970 * INTERNET_GetLastError (internal)
2972 * Get last thread specific error
2977 DWORD
INTERNET_GetLastError(void)
2979 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
2980 /* TlsGetValue clears last error, so set it again here */
2981 SetLastError(lpwite
->dwError
);
2982 return lpwite
->dwError
;
2986 /***********************************************************************
2987 * INTERNET_WorkerThreadFunc (internal)
2989 * Worker thread execution function
2994 static DWORD CALLBACK
INTERNET_WorkerThreadFunc(LPVOID lpvParam
)
3001 INTERNET_ExecuteWork();
3004 dwWaitRes
= WaitForMultipleObjects(2, hEventArray
, FALSE
, MAX_IDLE_WORKER
);
3006 if (dwWaitRes
== WAIT_OBJECT_0
+ 1)
3007 INTERNET_ExecuteWork();
3011 InterlockedIncrement(&dwNumIdleThreads
);
3014 InterlockedDecrement(&dwNumIdleThreads
);
3015 InterlockedDecrement(&dwNumThreads
);
3016 TRACE("Worker thread exiting\n");
3021 /***********************************************************************
3022 * INTERNET_InsertWorkRequest (internal)
3024 * Insert work request into queue
3029 static BOOL
INTERNET_InsertWorkRequest(LPWORKREQUEST lpWorkRequest
)
3031 BOOL bSuccess
= FALSE
;
3032 LPWORKREQUEST lpNewRequest
;
3036 lpNewRequest
= HeapAlloc(GetProcessHeap(), 0, sizeof(WORKREQUEST
));
3039 memcpy(lpNewRequest
, lpWorkRequest
, sizeof(WORKREQUEST
));
3040 lpNewRequest
->prev
= NULL
;
3042 EnterCriticalSection(&csQueue
);
3044 lpNewRequest
->next
= lpWorkQueueTail
;
3045 if (lpWorkQueueTail
)
3046 lpWorkQueueTail
->prev
= lpNewRequest
;
3047 lpWorkQueueTail
= lpNewRequest
;
3048 if (!lpHeadWorkQueue
)
3049 lpHeadWorkQueue
= lpWorkQueueTail
;
3051 LeaveCriticalSection(&csQueue
);
3054 InterlockedIncrement(&dwNumJobs
);
3061 /***********************************************************************
3062 * INTERNET_GetWorkRequest (internal)
3064 * Retrieves work request from queue
3069 static BOOL
INTERNET_GetWorkRequest(LPWORKREQUEST lpWorkRequest
)
3071 BOOL bSuccess
= FALSE
;
3072 LPWORKREQUEST lpRequest
= NULL
;
3076 EnterCriticalSection(&csQueue
);
3078 if (lpHeadWorkQueue
)
3080 lpRequest
= lpHeadWorkQueue
;
3081 lpHeadWorkQueue
= lpHeadWorkQueue
->prev
;
3082 if (lpRequest
== lpWorkQueueTail
)
3083 lpWorkQueueTail
= lpHeadWorkQueue
;
3086 LeaveCriticalSection(&csQueue
);
3090 memcpy(lpWorkRequest
, lpRequest
, sizeof(WORKREQUEST
));
3091 HeapFree(GetProcessHeap(), 0, lpRequest
);
3093 InterlockedDecrement(&dwNumJobs
);
3100 /***********************************************************************
3101 * INTERNET_AsyncCall (internal)
3103 * Retrieves work request from queue
3108 BOOL
INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest
)
3112 BOOL bSuccess
= FALSE
;
3116 if (InterlockedDecrement(&dwNumIdleThreads
) < 0)
3118 InterlockedIncrement(&dwNumIdleThreads
);
3120 if (InterlockedIncrement(&dwNumThreads
) > MAX_WORKER_THREADS
||
3121 !(hThread
= CreateThread(NULL
, 0,
3122 INTERNET_WorkerThreadFunc
, NULL
, 0, &dwTID
)))
3124 InterlockedDecrement(&dwNumThreads
);
3125 INTERNET_SetLastError(ERROR_INTERNET_ASYNC_THREAD_FAILED
);
3129 TRACE("Created new thread\n");
3133 INTERNET_InsertWorkRequest(lpWorkRequest
);
3134 SetEvent(hWorkEvent
);
3142 /***********************************************************************
3143 * INTERNET_ExecuteWork (internal)
3148 static VOID
INTERNET_ExecuteWork(void)
3150 WORKREQUEST workRequest
;
3154 if (!INTERNET_GetWorkRequest(&workRequest
))
3157 switch (workRequest
.asyncall
)
3161 struct WORKREQ_FTPPUTFILEW
*req
= &workRequest
.u
.FtpPutFileW
;
3162 LPWININETFTPSESSIONW lpwfs
= (LPWININETFTPSESSIONW
) workRequest
.hdr
;
3164 TRACE("FTPPUTFILEW %p\n", lpwfs
);
3166 FTP_FtpPutFileW(lpwfs
, req
->lpszLocalFile
,
3167 req
->lpszNewRemoteFile
, req
->dwFlags
, req
->dwContext
);
3169 HeapFree(GetProcessHeap(), 0, req
->lpszLocalFile
);
3170 HeapFree(GetProcessHeap(), 0, req
->lpszNewRemoteFile
);
3174 case FTPSETCURRENTDIRECTORYW
:
3176 struct WORKREQ_FTPSETCURRENTDIRECTORYW
*req
;
3177 LPWININETFTPSESSIONW lpwfs
= (LPWININETFTPSESSIONW
) workRequest
.hdr
;
3179 TRACE("FTPSETCURRENTDIRECTORYW %p\n", lpwfs
);
3181 req
= &workRequest
.u
.FtpSetCurrentDirectoryW
;
3182 FTP_FtpSetCurrentDirectoryW(lpwfs
, req
->lpszDirectory
);
3183 HeapFree(GetProcessHeap(), 0, req
->lpszDirectory
);
3187 case FTPCREATEDIRECTORYW
:
3189 struct WORKREQ_FTPCREATEDIRECTORYW
*req
;
3190 LPWININETFTPSESSIONW lpwfs
= (LPWININETFTPSESSIONW
) workRequest
.hdr
;
3192 TRACE("FTPCREATEDIRECTORYW %p\n", lpwfs
);
3194 req
= &workRequest
.u
.FtpCreateDirectoryW
;
3195 FTP_FtpCreateDirectoryW(lpwfs
, req
->lpszDirectory
);
3196 HeapFree(GetProcessHeap(), 0, req
->lpszDirectory
);
3200 case FTPFINDFIRSTFILEW
:
3202 struct WORKREQ_FTPFINDFIRSTFILEW
*req
;
3203 LPWININETFTPSESSIONW lpwfs
= (LPWININETFTPSESSIONW
) workRequest
.hdr
;
3205 TRACE("FTPFINDFIRSTFILEW %p\n", lpwfs
);
3207 req
= &workRequest
.u
.FtpFindFirstFileW
;
3208 FTP_FtpFindFirstFileW(lpwfs
, req
->lpszSearchFile
,
3209 req
->lpFindFileData
, req
->dwFlags
, req
->dwContext
);
3210 HeapFree(GetProcessHeap(), 0, req
->lpszSearchFile
);
3214 case FTPGETCURRENTDIRECTORYW
:
3216 struct WORKREQ_FTPGETCURRENTDIRECTORYW
*req
;
3217 LPWININETFTPSESSIONW lpwfs
= (LPWININETFTPSESSIONW
) workRequest
.hdr
;
3219 TRACE("FTPGETCURRENTDIRECTORYW %p\n", lpwfs
);
3221 req
= &workRequest
.u
.FtpGetCurrentDirectoryW
;
3222 FTP_FtpGetCurrentDirectoryW(lpwfs
,
3223 req
->lpszDirectory
, req
->lpdwDirectory
);
3229 struct WORKREQ_FTPOPENFILEW
*req
= &workRequest
.u
.FtpOpenFileW
;
3230 LPWININETFTPSESSIONW lpwfs
= (LPWININETFTPSESSIONW
) workRequest
.hdr
;
3232 TRACE("FTPOPENFILEW %p\n", lpwfs
);
3234 FTP_FtpOpenFileW(lpwfs
, req
->lpszFilename
,
3235 req
->dwAccess
, req
->dwFlags
, req
->dwContext
);
3236 HeapFree(GetProcessHeap(), 0, req
->lpszFilename
);
3242 struct WORKREQ_FTPGETFILEW
*req
= &workRequest
.u
.FtpGetFileW
;
3243 LPWININETFTPSESSIONW lpwfs
= (LPWININETFTPSESSIONW
) workRequest
.hdr
;
3245 TRACE("FTPGETFILEW %p\n", lpwfs
);
3247 FTP_FtpGetFileW(lpwfs
, req
->lpszRemoteFile
,
3248 req
->lpszNewFile
, req
->fFailIfExists
,
3249 req
->dwLocalFlagsAttribute
, req
->dwFlags
, req
->dwContext
);
3250 HeapFree(GetProcessHeap(), 0, req
->lpszRemoteFile
);
3251 HeapFree(GetProcessHeap(), 0, req
->lpszNewFile
);
3255 case FTPDELETEFILEW
:
3257 struct WORKREQ_FTPDELETEFILEW
*req
= &workRequest
.u
.FtpDeleteFileW
;
3258 LPWININETFTPSESSIONW lpwfs
= (LPWININETFTPSESSIONW
) workRequest
.hdr
;
3260 TRACE("FTPDELETEFILEW %p\n", lpwfs
);
3262 FTP_FtpDeleteFileW(lpwfs
, req
->lpszFilename
);
3263 HeapFree(GetProcessHeap(), 0, req
->lpszFilename
);
3267 case FTPREMOVEDIRECTORYW
:
3269 struct WORKREQ_FTPREMOVEDIRECTORYW
*req
;
3270 LPWININETFTPSESSIONW lpwfs
= (LPWININETFTPSESSIONW
) workRequest
.hdr
;
3272 TRACE("FTPREMOVEDIRECTORYW %p\n", lpwfs
);
3274 req
= &workRequest
.u
.FtpRemoveDirectoryW
;
3275 FTP_FtpRemoveDirectoryW(lpwfs
, req
->lpszDirectory
);
3276 HeapFree(GetProcessHeap(), 0, req
->lpszDirectory
);
3280 case FTPRENAMEFILEW
:
3282 struct WORKREQ_FTPRENAMEFILEW
*req
= &workRequest
.u
.FtpRenameFileW
;
3283 LPWININETFTPSESSIONW lpwfs
= (LPWININETFTPSESSIONW
) workRequest
.hdr
;
3285 TRACE("FTPRENAMEFILEW %p\n", lpwfs
);
3287 FTP_FtpRenameFileW(lpwfs
, req
->lpszSrcFile
, req
->lpszDestFile
);
3288 HeapFree(GetProcessHeap(), 0, req
->lpszSrcFile
);
3289 HeapFree(GetProcessHeap(), 0, req
->lpszDestFile
);
3293 case INTERNETFINDNEXTW
:
3295 struct WORKREQ_INTERNETFINDNEXTW
*req
;
3296 LPWININETFINDNEXTW lpwh
= (LPWININETFINDNEXTW
) workRequest
.hdr
;
3298 TRACE("INTERNETFINDNEXTW %p\n", lpwh
);
3300 req
= &workRequest
.u
.InternetFindNextW
;
3301 INTERNET_FindNextFileW(lpwh
, req
->lpFindFileData
);
3305 case HTTPSENDREQUESTW
:
3307 struct WORKREQ_HTTPSENDREQUESTW
*req
= &workRequest
.u
.HttpSendRequestW
;
3308 LPWININETHTTPREQW lpwhr
= (LPWININETHTTPREQW
) workRequest
.hdr
;
3310 TRACE("HTTPSENDREQUESTW %p\n", lpwhr
);
3312 HTTP_HttpSendRequestW(lpwhr
, req
->lpszHeader
,
3313 req
->dwHeaderLength
, req
->lpOptional
, req
->dwOptionalLength
,
3314 req
->dwContentLength
, req
->bEndRequest
);
3316 HeapFree(GetProcessHeap(), 0, req
->lpszHeader
);
3320 case HTTPOPENREQUESTW
:
3322 struct WORKREQ_HTTPOPENREQUESTW
*req
= &workRequest
.u
.HttpOpenRequestW
;
3323 LPWININETHTTPSESSIONW lpwhs
= (LPWININETHTTPSESSIONW
) workRequest
.hdr
;
3325 TRACE("HTTPOPENREQUESTW %p\n", lpwhs
);
3327 HTTP_HttpOpenRequestW(lpwhs
, req
->lpszVerb
,
3328 req
->lpszObjectName
, req
->lpszVersion
, req
->lpszReferrer
,
3329 req
->lpszAcceptTypes
, req
->dwFlags
, req
->dwContext
);
3331 HeapFree(GetProcessHeap(), 0, req
->lpszVerb
);
3332 HeapFree(GetProcessHeap(), 0, req
->lpszObjectName
);
3333 HeapFree(GetProcessHeap(), 0, req
->lpszVersion
);
3334 HeapFree(GetProcessHeap(), 0, req
->lpszReferrer
);
3340 struct WORKREQ_SENDCALLBACK
*req
= &workRequest
.u
.SendCallback
;
3342 TRACE("SENDCALLBACK %p\n", workRequest
.hdr
);
3344 INTERNET_SendCallback(workRequest
.hdr
,
3345 req
->dwContext
, req
->dwInternetStatus
, req
->lpvStatusInfo
,
3346 req
->dwStatusInfoLength
);
3348 /* And frees the copy of the status info */
3349 HeapFree(GetProcessHeap(), 0, req
->lpvStatusInfo
);
3353 case INTERNETOPENURLW
:
3355 struct WORKREQ_INTERNETOPENURLW
*req
= &workRequest
.u
.InternetOpenUrlW
;
3356 LPWININETAPPINFOW hIC
= (LPWININETAPPINFOW
) workRequest
.hdr
;
3358 TRACE("INTERNETOPENURLW %p\n", hIC
);
3360 INTERNET_InternetOpenUrlW(hIC
, req
->lpszUrl
,
3361 req
->lpszHeaders
, req
->dwHeadersLength
, req
->dwFlags
, req
->dwContext
);
3362 HeapFree(GetProcessHeap(), 0, req
->lpszUrl
);
3363 HeapFree(GetProcessHeap(), 0, req
->lpszHeaders
);
3366 case INTERNETREADFILEEXA
:
3368 struct WORKREQ_INTERNETREADFILEEXA
*req
= &workRequest
.u
.InternetReadFileExA
;
3370 TRACE("INTERNETREADFILEEXA %p\n", workRequest
.hdr
);
3372 INTERNET_ReadFile(workRequest
.hdr
, req
->lpBuffersOut
->lpvBuffer
,
3373 req
->lpBuffersOut
->dwBufferLength
,
3374 &req
->lpBuffersOut
->dwBufferLength
, TRUE
, TRUE
);
3378 WININET_Release( workRequest
.hdr
);
3382 /***********************************************************************
3383 * INTERNET_GetResponseBuffer (internal)
3388 LPSTR
INTERNET_GetResponseBuffer(void)
3390 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
3392 return lpwite
->response
;
3395 /***********************************************************************
3396 * INTERNET_GetNextLine (internal)
3398 * Parse next line in directory string listing
3401 * Pointer to beginning of next line
3406 LPSTR
INTERNET_GetNextLine(INT nSocket
, LPDWORD dwLen
)
3410 BOOL bSuccess
= FALSE
;
3412 LPSTR lpszBuffer
= INTERNET_GetResponseBuffer();
3417 FD_SET(nSocket
, &infd
);
3418 tv
.tv_sec
=RESPONSE_TIMEOUT
;
3421 while (nRecv
< MAX_REPLY_LEN
)
3423 if (select(nSocket
+1,&infd
,NULL
,NULL
,&tv
) > 0)
3425 if (recv(nSocket
, &lpszBuffer
[nRecv
], 1, 0) <= 0)
3427 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS
);
3431 if (lpszBuffer
[nRecv
] == '\n')
3436 if (lpszBuffer
[nRecv
] != '\r')
3441 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT
);
3449 lpszBuffer
[nRecv
] = '\0';
3451 TRACE(":%d %s\n", nRecv
, lpszBuffer
);
3460 /**********************************************************
3461 * InternetQueryDataAvailable (WININET.@)
3463 * Determines how much data is available to be read.
3466 * If there is data available then TRUE, otherwise if there
3467 * is not or an error occurred then FALSE. Use GetLastError() to
3468 * check for ERROR_NO_MORE_FILES to see if it was the former.
3470 BOOL WINAPI
InternetQueryDataAvailable( HINTERNET hFile
,
3471 LPDWORD lpdwNumberOfBytesAvailble
,
3472 DWORD dwFlags
, DWORD dwConext
)
3474 LPWININETHTTPREQW lpwhr
;
3475 BOOL retval
= FALSE
;
3478 lpwhr
= (LPWININETHTTPREQW
) WININET_GetObject( hFile
);
3481 SetLastError(ERROR_NO_MORE_FILES
);
3485 TRACE("--> %p %i\n",lpwhr
,lpwhr
->hdr
.htype
);
3487 switch (lpwhr
->hdr
.htype
)
3490 if (!NETCON_recv(&lpwhr
->netConnection
, buffer
,
3491 4048, MSG_PEEK
, (int *)lpdwNumberOfBytesAvailble
))
3493 SetLastError(ERROR_NO_MORE_FILES
);
3501 FIXME("unsupported file type\n");
3504 WININET_Release( &lpwhr
->hdr
);
3506 TRACE("<-- %i\n",retval
);
3511 /***********************************************************************
3512 * InternetLockRequestFile (WININET.@)
3514 BOOL WINAPI
InternetLockRequestFile( HINTERNET hInternet
, HANDLE
3521 BOOL WINAPI
InternetUnlockRequestFile( HANDLE hLockHandle
)
3528 /***********************************************************************
3529 * InternetAutodial (WININET.@)
3531 * On windows this function is supposed to dial the default internet
3532 * connection. We don't want to have Wine dial out to the internet so
3533 * we return TRUE by default. It might be nice to check if we are connected.
3540 BOOL WINAPI
InternetAutodial(DWORD dwFlags
, HWND hwndParent
)
3544 /* Tell that we are connected to the internet. */
3548 /***********************************************************************
3549 * InternetAutodialHangup (WININET.@)
3551 * Hangs up a connection made with InternetAutodial
3560 BOOL WINAPI
InternetAutodialHangup(DWORD dwReserved
)
3564 /* we didn't dial, we don't disconnect */
3568 /***********************************************************************
3569 * InternetCombineUrlA (WININET.@)
3571 * Combine a base URL with a relative URL
3579 BOOL WINAPI
InternetCombineUrlA(LPCSTR lpszBaseUrl
, LPCSTR lpszRelativeUrl
,
3580 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3585 TRACE("(%s, %s, %p, %p, 0x%08lx)\n", debugstr_a(lpszBaseUrl
), debugstr_a(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3587 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3588 dwFlags
^= ICU_NO_ENCODE
;
3589 hr
=UrlCombineA(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3594 /***********************************************************************
3595 * InternetCombineUrlW (WININET.@)
3597 * Combine a base URL with a relative URL
3605 BOOL WINAPI
InternetCombineUrlW(LPCWSTR lpszBaseUrl
, LPCWSTR lpszRelativeUrl
,
3606 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
3611 TRACE("(%s, %s, %p, %p, 0x%08lx)\n", debugstr_w(lpszBaseUrl
), debugstr_w(lpszRelativeUrl
), lpszBuffer
, lpdwBufferLength
, dwFlags
);
3613 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3614 dwFlags
^= ICU_NO_ENCODE
;
3615 hr
=UrlCombineW(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
3620 /* max port num is 65535 => 5 digits */
3621 #define MAX_WORD_DIGITS 5
3623 /* we can calculate using ansi strings because we're just
3624 * calculating string length, not size
3626 static BOOL
calc_url_length(LPURL_COMPONENTSW lpUrlComponents
,
3627 LPDWORD lpdwUrlLength
, LPDWORD lpdwSchemeLength
)
3629 static const WCHAR httpW
[] = {'h','t','t','p',0};
3633 switch (lpUrlComponents
->nScheme
)
3635 case INTERNET_SCHEME_FTP
:
3636 case INTERNET_SCHEME_RES
:
3637 *lpdwSchemeLength
= 3;
3639 case INTERNET_SCHEME_HTTP
:
3640 case INTERNET_SCHEME_FILE
:
3641 case INTERNET_SCHEME_NEWS
:
3642 *lpdwSchemeLength
= 4;
3646 *lpdwSchemeLength
= 4;
3650 *lpdwUrlLength
+= *lpdwSchemeLength
;
3651 *lpdwUrlLength
+= strlen("://");
3653 if (lpUrlComponents
->lpszUserName
)
3655 *lpdwUrlLength
+= lpUrlComponents
->dwUserNameLength
;
3656 *lpdwUrlLength
+= strlen("@");
3660 if (lpUrlComponents
->lpszPassword
)
3662 SetLastError(ERROR_INVALID_PARAMETER
);
3667 if (lpUrlComponents
->lpszPassword
)
3669 *lpdwUrlLength
+= strlen(":");
3670 *lpdwUrlLength
+= lpUrlComponents
->dwPasswordLength
;
3673 *lpdwUrlLength
+= lpUrlComponents
->dwHostNameLength
;
3675 if (lpUrlComponents
->nPort
!= 80 ||
3676 (lpUrlComponents
->lpszScheme
&& strncmpW(lpUrlComponents
->lpszScheme
, httpW
, lpUrlComponents
->dwSchemeLength
)))
3678 char szPort
[MAX_WORD_DIGITS
];
3680 sprintf(szPort
, "%d", lpUrlComponents
->nPort
);
3681 *lpdwUrlLength
+= strlen(szPort
);
3682 *lpdwUrlLength
+= strlen(":");
3685 *lpdwUrlLength
+= lpUrlComponents
->dwUrlPathLength
;
3689 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents
, LPURL_COMPONENTSW urlCompW
)
3693 ZeroMemory(urlCompW
, sizeof(URL_COMPONENTSW
));
3695 urlCompW
->dwStructSize
= sizeof(URL_COMPONENTSW
);
3696 urlCompW
->dwSchemeLength
= lpUrlComponents
->dwSchemeLength
;
3697 urlCompW
->nScheme
= lpUrlComponents
->nScheme
;
3698 urlCompW
->dwHostNameLength
= lpUrlComponents
->dwHostNameLength
;
3699 urlCompW
->nPort
= lpUrlComponents
->nPort
;
3700 urlCompW
->dwUserNameLength
= lpUrlComponents
->dwUserNameLength
;
3701 urlCompW
->dwPasswordLength
= lpUrlComponents
->dwPasswordLength
;
3702 urlCompW
->dwUrlPathLength
= lpUrlComponents
->dwUrlPathLength
;
3703 urlCompW
->dwExtraInfoLength
= lpUrlComponents
->dwExtraInfoLength
;
3705 if (lpUrlComponents
->lpszScheme
)
3707 len
= lpUrlComponents
->dwSchemeLength
+ 1;
3708 urlCompW
->lpszScheme
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3709 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszScheme
,
3710 -1, urlCompW
->lpszScheme
, len
);
3713 if (lpUrlComponents
->lpszHostName
)
3715 len
= lpUrlComponents
->dwHostNameLength
+ 1;
3716 urlCompW
->lpszHostName
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3717 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszHostName
,
3718 -1, urlCompW
->lpszHostName
, len
);
3721 if (lpUrlComponents
->lpszUserName
)
3723 len
= lpUrlComponents
->dwUserNameLength
+ 1;
3724 urlCompW
->lpszUserName
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3725 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUserName
,
3726 -1, urlCompW
->lpszUserName
, len
);
3729 if (lpUrlComponents
->lpszPassword
)
3731 len
= lpUrlComponents
->dwPasswordLength
+ 1;
3732 urlCompW
->lpszPassword
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3733 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszPassword
,
3734 -1, urlCompW
->lpszPassword
, len
);
3737 if (lpUrlComponents
->lpszUrlPath
)
3739 len
= lpUrlComponents
->dwUrlPathLength
+ 1;
3740 urlCompW
->lpszUrlPath
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3741 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszUrlPath
,
3742 -1, urlCompW
->lpszUrlPath
, len
);
3745 if (lpUrlComponents
->lpszExtraInfo
)
3747 len
= lpUrlComponents
->dwExtraInfoLength
+ 1;
3748 urlCompW
->lpszExtraInfo
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3749 MultiByteToWideChar(CP_ACP
, 0, lpUrlComponents
->lpszExtraInfo
,
3750 -1, urlCompW
->lpszExtraInfo
, len
);
3754 /***********************************************************************
3755 * InternetCreateUrlA (WININET.@)
3762 BOOL WINAPI
InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents
, DWORD dwFlags
,
3763 LPSTR lpszUrl
, LPDWORD lpdwUrlLength
)
3767 URL_COMPONENTSW urlCompW
;
3769 TRACE("(%p,%ld,%s,%p)\n", lpUrlComponents
, dwFlags
, debugstr_a(lpszUrl
), lpdwUrlLength
);
3771 if (!lpUrlComponents
)
3774 if (lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
3776 SetLastError(ERROR_INVALID_PARAMETER
);
3780 convert_urlcomp_atow(lpUrlComponents
, &urlCompW
);
3783 urlW
= HeapAlloc(GetProcessHeap(), 0, *lpdwUrlLength
* sizeof(WCHAR
));
3785 ret
= InternetCreateUrlW(&urlCompW
, dwFlags
, urlW
, lpdwUrlLength
);
3787 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
3788 * minus one, so add one to leave room for NULL terminator
3791 WideCharToMultiByte(CP_ACP
, 0, urlW
, -1, lpszUrl
, *lpdwUrlLength
+ 1, NULL
, NULL
);
3793 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszScheme
);
3794 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszHostName
);
3795 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszUserName
);
3796 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszPassword
);
3797 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszUrlPath
);
3798 HeapFree(GetProcessHeap(), 0, urlCompW
.lpszExtraInfo
);
3799 HeapFree(GetProcessHeap(), 0, urlW
);
3804 /***********************************************************************
3805 * InternetCreateUrlW (WININET.@)
3812 BOOL WINAPI
InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents
, DWORD dwFlags
,
3813 LPWSTR lpszUrl
, LPDWORD lpdwUrlLength
)
3815 DWORD dwLen
, dwSchemeLen
;
3817 static const WCHAR colonSlashW
[] = {':','/','/',0};
3818 static const WCHAR httpW
[] = {'h','t','t','p',0};
3819 static const WCHAR colonW
[] = {':',0};
3820 static const WCHAR atW
[] = {'@',0};
3821 static const WCHAR percentD
[] = {'%','d',0};
3823 TRACE("(%p,%ld,%s,%p)\n", lpUrlComponents
, dwFlags
, debugstr_w(lpszUrl
), lpdwUrlLength
);
3825 if (!lpUrlComponents
)
3828 if (lpUrlComponents
->dwStructSize
!= sizeof(URL_COMPONENTSW
) || !lpdwUrlLength
)
3830 SetLastError(ERROR_INVALID_PARAMETER
);
3834 if (!calc_url_length(lpUrlComponents
, &dwLen
, &dwSchemeLen
))
3837 if (!lpszUrl
|| *lpdwUrlLength
< dwLen
)
3839 *lpdwUrlLength
= dwLen
+ 1; /* terminating null */
3840 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
3844 *lpdwUrlLength
= dwLen
;
3847 if (lpUrlComponents
->lpszScheme
)
3848 lstrcpynW(lpszUrl
, lpUrlComponents
->lpszScheme
,
3849 min(lpUrlComponents
->dwSchemeLength
, dwSchemeLen
) + 1);
3851 lstrcatW(lpszUrl
, colonSlashW
);
3853 if (lpUrlComponents
->lpszUserName
)
3855 if (!*lpUrlComponents
->lpszUserName
)
3858 lstrcatW(lpszUrl
, lpUrlComponents
->lpszUserName
);
3860 if (lpUrlComponents
->lpszPassword
)
3862 lstrcatW(lpszUrl
, colonW
);
3864 if (!*lpUrlComponents
->lpszPassword
)
3867 lstrcatW(lpszUrl
, lpUrlComponents
->lpszPassword
);
3870 lstrcatW(lpszUrl
, atW
);
3873 lstrcatW(lpszUrl
, lpUrlComponents
->lpszHostName
);
3875 if (lpUrlComponents
->nPort
!= 80 || (lpUrlComponents
->lpszScheme
&&
3876 strncmpW(lpUrlComponents
->lpszScheme
, httpW
, lpUrlComponents
->dwSchemeLength
)))
3878 WCHAR szPort
[MAX_WORD_DIGITS
];
3880 sprintfW(szPort
, percentD
, lpUrlComponents
->nPort
);
3881 lstrcatW(lpszUrl
, colonW
);
3882 lstrcatW(lpszUrl
, szPort
);
3885 lstrcatW(lpszUrl
, lpUrlComponents
->lpszUrlPath
);
3890 /***********************************************************************
3891 * InternetConfirmZoneCrossingA (WININET.@)
3894 DWORD WINAPI
InternetConfirmZoneCrossingA( HWND hWnd
, LPSTR szUrlPrev
, LPSTR szUrlNew
, BOOL bPost
)
3896 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_a(szUrlPrev
), debugstr_a(szUrlNew
), bPost
);
3897 return ERROR_SUCCESS
;
3900 /***********************************************************************
3901 * InternetConfirmZoneCrossingW (WININET.@)
3904 DWORD WINAPI
InternetConfirmZoneCrossingW( HWND hWnd
, LPWSTR szUrlPrev
, LPWSTR szUrlNew
, BOOL bPost
)
3906 FIXME("(%p, %s, %s, %x) stub\n", hWnd
, debugstr_w(szUrlPrev
), debugstr_w(szUrlNew
), bPost
);
3907 return ERROR_SUCCESS
;
3910 DWORD WINAPI
InternetDialA( HWND hwndParent
, LPSTR lpszConnectoid
, DWORD dwFlags
,
3911 LPDWORD lpdwConnection
, DWORD dwReserved
)
3913 FIXME("(%p, %p, 0x%08lx, %p, 0x%08lx) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
3914 lpdwConnection
, dwReserved
);
3915 return ERROR_SUCCESS
;
3918 DWORD WINAPI
InternetDialW( HWND hwndParent
, LPWSTR lpszConnectoid
, DWORD dwFlags
,
3919 LPDWORD lpdwConnection
, DWORD dwReserved
)
3921 FIXME("(%p, %p, 0x%08lx, %p, 0x%08lx) stub\n", hwndParent
, lpszConnectoid
, dwFlags
,
3922 lpdwConnection
, dwReserved
);
3923 return ERROR_SUCCESS
;
3926 BOOL WINAPI
InternetGoOnlineA( LPSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
3928 FIXME("(%s, %p, 0x%08lx) stub\n", debugstr_a(lpszURL
), hwndParent
, dwReserved
);
3932 BOOL WINAPI
InternetGoOnlineW( LPWSTR lpszURL
, HWND hwndParent
, DWORD dwReserved
)
3934 FIXME("(%s, %p, 0x%08lx) stub\n", debugstr_w(lpszURL
), hwndParent
, dwReserved
);
3938 DWORD WINAPI
InternetHangUp( DWORD dwConnection
, DWORD dwReserved
)
3940 FIXME("(0x%08lx, 0x%08lx) stub\n", dwConnection
, dwReserved
);
3941 return ERROR_SUCCESS
;
3944 BOOL WINAPI
CreateMD5SSOHash( PWSTR pszChallengeInfo
, PWSTR pwszRealm
, PWSTR pwszTarget
,
3947 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo
), debugstr_w(pwszRealm
),
3948 debugstr_w(pwszTarget
), pbHexHash
);
3952 BOOL WINAPI
InternetClearAllPerSiteCookieDecisions( VOID
)
3958 BOOL WINAPI
InternetEnumPerSiteCookieDecisionA( LPSTR pszSiteName
, unsigned long *pcSiteNameSize
,
3959 unsigned long *pdwDecision
, unsigned long dwIndex
)
3961 FIXME("(%s, %p, %p, 0x%08lx) stub\n",
3962 debugstr_a(pszSiteName
), pcSiteNameSize
, pdwDecision
, dwIndex
);
3966 BOOL WINAPI
InternetEnumPerSiteCookieDecisionW( LPWSTR pszSiteName
, unsigned long *pcSiteNameSize
,
3967 unsigned long *pdwDecision
, unsigned long dwIndex
)
3969 FIXME("(%s, %p, %p, 0x%08lx) stub\n",
3970 debugstr_w(pszSiteName
), pcSiteNameSize
, pdwDecision
, dwIndex
);
3974 BOOL WINAPI
InternetGetCookieExA( LPCSTR pchURL
, LPCSTR pchCookieName
, LPSTR pchCookieData
,
3975 LPDWORD pcchCookieData
, DWORD dwFlags
, LPVOID lpReserved
)
3977 FIXME("(%s, %s, %s, %p, 0x%08lx, %p) stub\n",
3978 debugstr_a(pchURL
), debugstr_a(pchCookieName
), debugstr_a(pchCookieData
),
3979 pcchCookieData
, dwFlags
, lpReserved
);
3983 BOOL WINAPI
InternetGetCookieExW( LPCWSTR pchURL
, LPCWSTR pchCookieName
, LPWSTR pchCookieData
,
3984 LPDWORD pcchCookieData
, DWORD dwFlags
, LPVOID lpReserved
)
3986 FIXME("(%s, %s, %s, %p, 0x%08lx, %p) stub\n",
3987 debugstr_w(pchURL
), debugstr_w(pchCookieName
), debugstr_w(pchCookieData
),
3988 pcchCookieData
, dwFlags
, lpReserved
);
3992 BOOL WINAPI
InternetGetPerSiteCookieDecisionA( LPCSTR pwchHostName
, unsigned long *pResult
)
3994 FIXME("(%s, %p) stub\n", debugstr_a(pwchHostName
), pResult
);
3998 BOOL WINAPI
InternetGetPerSiteCookieDecisionW( LPCWSTR pwchHostName
, unsigned long *pResult
)
4000 FIXME("(%s, %p) stub\n", debugstr_w(pwchHostName
), pResult
);
4004 BOOL WINAPI
InternetSetPerSiteCookieDecisionA( LPCSTR pchHostName
, DWORD dwDecision
)
4006 FIXME("(%s, 0x%08lx) stub\n", debugstr_a(pchHostName
), dwDecision
);
4010 BOOL WINAPI
InternetSetPerSiteCookieDecisionW( LPCWSTR pchHostName
, DWORD dwDecision
)
4012 FIXME("(%s, 0x%08lx) stub\n", debugstr_w(pchHostName
), dwDecision
);
4016 DWORD WINAPI
InternetSetCookieExA( LPCSTR lpszURL
, LPCSTR lpszCookieName
, LPCSTR lpszCookieData
,
4017 DWORD dwFlags
, DWORD_PTR dwReserved
)
4019 FIXME("(%s, %s, %s, 0x%08lx, 0x%08lx) stub\n",
4020 debugstr_a(lpszURL
), debugstr_a(lpszCookieName
), debugstr_a(lpszCookieData
),
4021 dwFlags
, dwReserved
);
4025 DWORD WINAPI
InternetSetCookieExW( LPCWSTR lpszURL
, LPCWSTR lpszCookieName
, LPCWSTR lpszCookieData
,
4026 DWORD dwFlags
, DWORD_PTR dwReserved
)
4028 FIXME("(%s, %s, %s, 0x%08lx, 0x%08lx) stub\n",
4029 debugstr_w(lpszURL
), debugstr_w(lpszCookieName
), debugstr_w(lpszCookieData
),
4030 dwFlags
, dwReserved
);
4034 BOOL WINAPI
ResumeSuspendedDownload( HINTERNET hInternet
, DWORD dwError
)
4036 FIXME("(%p, 0x%08lx) stub\n", hInternet
, dwError
);