4 * Copyright 1999 Corel Corporation
5 * Copyright 2002 CodeWeavers Inc.
10 * Copyright 2002 Jaco Greeff
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2.1 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #define MAXHOSTNAME 100 /* from http.c */
33 #include <sys/types.h>
34 #ifdef HAVE_SYS_SOCKET_H
35 # include <sys/socket.h>
37 #ifdef HAVE_SYS_TIME_H
38 # include <sys/time.h>
51 #include "wine/debug.h"
53 #define NO_SHLWAPI_STREAM
56 #include "wine/exception.h"
57 #include "msvcrt/excpt.h"
61 WINE_DEFAULT_DEBUG_CHANNEL(wininet
);
63 #define MAX_IDLE_WORKER 1000*60*1
64 #define MAX_WORKER_THREADS 10
65 #define RESPONSE_TIMEOUT 30
67 #define GET_HWININET_FROM_LPWININETFINDNEXT(lpwh) \
68 (LPWININETAPPINFOA)(((LPWININETFTPSESSIONA)(lpwh->hdr.lpwhparent))->hdr.lpwhparent)
70 /* filter for page-fault exceptions */
71 static WINE_EXCEPTION_FILTER(page_fault
)
73 if (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION
||
74 GetExceptionCode() == EXCEPTION_PRIV_INSTRUCTION
)
75 return EXCEPTION_EXECUTE_HANDLER
;
76 return EXCEPTION_CONTINUE_SEARCH
;
82 CHAR response
[MAX_REPLY_LEN
];
83 } WITHREADERROR
, *LPWITHREADERROR
;
85 INTERNET_SCHEME
GetInternetScheme(LPCSTR lpszScheme
, INT nMaxCmp
);
86 BOOL WINAPI
INTERNET_FindNextFileA(HINTERNET hFind
, LPVOID lpvFindData
);
87 VOID
INTERNET_ExecuteWork();
89 DWORD g_dwTlsErrIndex
= TLS_OUT_OF_INDEXES
;
91 DWORD dwNumIdleThreads
;
93 HANDLE hEventArray
[2];
94 #define hQuitEvent hEventArray[0]
95 #define hWorkEvent hEventArray[1]
96 CRITICAL_SECTION csQueue
;
97 LPWORKREQUEST lpHeadWorkQueue
;
98 LPWORKREQUEST lpWorkQueueTail
;
100 /***********************************************************************
101 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
104 * hinstDLL [I] handle to the DLL's instance
106 * lpvReserved [I] reserved, must be NULL
113 BOOL WINAPI
DllMain (HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
115 TRACE("%p,%lx,%p\n", hinstDLL
, fdwReason
, lpvReserved
);
118 case DLL_PROCESS_ATTACH
:
120 g_dwTlsErrIndex
= TlsAlloc();
122 if (g_dwTlsErrIndex
== TLS_OUT_OF_INDEXES
)
125 hQuitEvent
= CreateEventA(0, TRUE
, FALSE
, NULL
);
126 hWorkEvent
= CreateEventA(0, FALSE
, FALSE
, NULL
);
127 InitializeCriticalSection(&csQueue
);
130 dwNumIdleThreads
= 0;
133 case DLL_THREAD_ATTACH
:
135 LPWITHREADERROR lpwite
= HeapAlloc(GetProcessHeap(), 0, sizeof(WITHREADERROR
));
139 TlsSetValue(g_dwTlsErrIndex
, (LPVOID
)lpwite
);
143 case DLL_THREAD_DETACH
:
144 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
146 LPVOID lpwite
= TlsGetValue(g_dwTlsErrIndex
);
148 HeapFree(GetProcessHeap(), 0, lpwite
);
152 case DLL_PROCESS_DETACH
:
154 if (g_dwTlsErrIndex
!= TLS_OUT_OF_INDEXES
)
156 HeapFree(GetProcessHeap(), 0, TlsGetValue(g_dwTlsErrIndex
));
157 TlsFree(g_dwTlsErrIndex
);
160 SetEvent(hQuitEvent
);
162 CloseHandle(hQuitEvent
);
163 CloseHandle(hWorkEvent
);
164 DeleteCriticalSection(&csQueue
);
172 /***********************************************************************
173 * InternetInitializeAutoProxyDll (WININET.@)
175 * Setup the internal proxy
184 BOOL WINAPI
InternetInitializeAutoProxyDll(DWORD dwReserved
)
187 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
192 /***********************************************************************
193 * InternetOpenA (WININET.@)
195 * Per-application initialization of wininet
198 * HINTERNET on success
202 HINTERNET WINAPI
InternetOpenA(LPCSTR lpszAgent
, DWORD dwAccessType
,
203 LPCSTR lpszProxy
, LPCSTR lpszProxyBypass
, DWORD dwFlags
)
205 LPWININETAPPINFOA lpwai
= NULL
;
209 /* Clear any error information */
210 INTERNET_SetLastError(0);
212 lpwai
= HeapAlloc(GetProcessHeap(), 0, sizeof(WININETAPPINFOA
));
214 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
217 memset(lpwai
, 0, sizeof(WININETAPPINFOA
));
218 lpwai
->hdr
.htype
= WH_HINIT
;
219 lpwai
->hdr
.lpwhparent
= NULL
;
220 lpwai
->hdr
.dwFlags
= dwFlags
;
221 if (NULL
!= lpszAgent
)
223 if ((lpwai
->lpszAgent
= HeapAlloc( GetProcessHeap(),0,strlen(lpszAgent
)+1)))
224 strcpy( lpwai
->lpszAgent
, lpszAgent
);
226 if (NULL
!= lpszProxy
)
228 if ((lpwai
->lpszProxy
= HeapAlloc( GetProcessHeap(), 0, strlen(lpszProxy
)+1 )))
229 strcpy( lpwai
->lpszProxy
, lpszProxy
);
231 if (NULL
!= lpszProxyBypass
)
233 if ((lpwai
->lpszProxyBypass
= HeapAlloc( GetProcessHeap(), 0, strlen(lpszProxyBypass
)+1)))
234 strcpy( lpwai
->lpszProxyBypass
, lpszProxyBypass
);
236 lpwai
->dwAccessType
= dwAccessType
;
239 return (HINTERNET
)lpwai
;
243 /***********************************************************************
244 * InternetOpenW (WININET.@)
246 * Per-application initialization of wininet
249 * HINTERNET on success
253 HINTERNET WINAPI
InternetOpenW(LPCWSTR lpszAgent
, DWORD dwAccessType
,
254 LPCWSTR lpszProxy
, LPCWSTR lpszProxyBypass
, DWORD dwFlags
)
256 HINTERNET rc
= (HINTERNET
)NULL
;
257 INT lenAgent
= lstrlenW(lpszAgent
)+1;
258 INT lenProxy
= lstrlenW(lpszProxy
)+1;
259 INT lenBypass
= lstrlenW(lpszProxyBypass
)+1;
260 CHAR
*szAgent
= (CHAR
*)malloc(lenAgent
*sizeof(CHAR
));
261 CHAR
*szProxy
= (CHAR
*)malloc(lenProxy
*sizeof(CHAR
));
262 CHAR
*szBypass
= (CHAR
*)malloc(lenBypass
*sizeof(CHAR
));
264 if (!szAgent
|| !szProxy
|| !szBypass
)
272 return (HINTERNET
)NULL
;
275 WideCharToMultiByte(CP_ACP
, -1, lpszAgent
, -1, szAgent
, lenAgent
,
277 WideCharToMultiByte(CP_ACP
, -1, lpszProxy
, -1, szProxy
, lenProxy
,
279 WideCharToMultiByte(CP_ACP
, -1, lpszProxyBypass
, -1, szBypass
, lenBypass
,
282 rc
= InternetOpenA(szAgent
, dwAccessType
, szProxy
, szBypass
, dwFlags
);
291 /***********************************************************************
292 * InternetGetLastResponseInfoA (WININET.@)
294 * Return last wininet error description on the calling thread
297 * TRUE on success of writting to buffer
301 BOOL WINAPI
InternetGetLastResponseInfoA(LPDWORD lpdwError
,
302 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
304 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
308 *lpdwError
= lpwite
->dwError
;
311 strncpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
312 *lpdwBufferLength
= strlen(lpszBuffer
);
315 *lpdwBufferLength
= 0;
321 /***********************************************************************
322 * InternetGetConnectedState (WININET.@)
324 * Return connected state
328 * if lpdwStatus is not null, return the status (off line,
329 * modem, lan...) in it.
330 * FALSE if not connected
332 BOOL WINAPI
InternetGetConnectedState(LPDWORD lpdwStatus
, DWORD dwReserved
)
335 FIXME("always returning LAN connection.\n");
336 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
342 /***********************************************************************
343 * InternetConnectA (WININET.@)
345 * Open a ftp, gopher or http session
348 * HINTERNET a session handle on success
352 HINTERNET WINAPI
InternetConnectA(HINTERNET hInternet
,
353 LPCSTR lpszServerName
, INTERNET_PORT nServerPort
,
354 LPCSTR lpszUserName
, LPCSTR lpszPassword
,
355 DWORD dwService
, DWORD dwFlags
, DWORD dwContext
)
357 HINTERNET rc
= (HINTERNET
) NULL
;
359 TRACE("ServerPort %i\n",nServerPort
);
361 /* Clear any error information */
362 INTERNET_SetLastError(0);
366 case INTERNET_SERVICE_FTP
:
367 rc
= FTP_Connect(hInternet
, lpszServerName
, nServerPort
,
368 lpszUserName
, lpszPassword
, dwFlags
, dwContext
);
371 case INTERNET_SERVICE_HTTP
:
372 rc
= HTTP_Connect(hInternet
, lpszServerName
, nServerPort
,
373 lpszUserName
, lpszPassword
, dwFlags
, dwContext
);
376 case INTERNET_SERVICE_GOPHER
:
385 /***********************************************************************
386 * InternetConnectW (WININET.@)
388 * Open a ftp, gopher or http session
391 * HINTERNET a session handle on success
395 HINTERNET WINAPI
InternetConnectW(HINTERNET hInternet
,
396 LPCWSTR lpszServerName
, INTERNET_PORT nServerPort
,
397 LPCWSTR lpszUserName
, LPCWSTR lpszPassword
,
398 DWORD dwService
, DWORD dwFlags
, DWORD dwContext
)
400 HINTERNET rc
= (HINTERNET
)NULL
;
401 INT lenServer
= lstrlenW(lpszServerName
)+1;
402 INT lenUser
= lstrlenW(lpszUserName
)+1;
403 INT lenPass
= lstrlenW(lpszPassword
)+1;
404 CHAR
*szServerName
= (CHAR
*)malloc(lenServer
*sizeof(CHAR
));
405 CHAR
*szUserName
= (CHAR
*)malloc(lenUser
*sizeof(CHAR
));
406 CHAR
*szPassword
= (CHAR
*)malloc(lenPass
*sizeof(CHAR
));
408 if (!szServerName
|| !szUserName
|| !szPassword
)
416 return (HINTERNET
)NULL
;
419 WideCharToMultiByte(CP_ACP
, -1, lpszServerName
, -1, szServerName
, lenServer
,
421 WideCharToMultiByte(CP_ACP
, -1, lpszUserName
, -1, szUserName
, lenUser
,
423 WideCharToMultiByte(CP_ACP
, -1, lpszPassword
, -1, szPassword
, lenPass
,
426 rc
= InternetConnectA(hInternet
, szServerName
, nServerPort
,
427 szUserName
, szPassword
, dwService
, dwFlags
, dwContext
);
436 /***********************************************************************
437 * InternetFindNextFileA (WININET.@)
439 * Continues a file search from a previous call to FindFirstFile
446 BOOL WINAPI
InternetFindNextFileA(HINTERNET hFind
, LPVOID lpvFindData
)
448 LPWININETAPPINFOA hIC
= NULL
;
449 LPWININETFINDNEXTA lpwh
= (LPWININETFINDNEXTA
) hFind
;
453 if (NULL
== lpwh
|| lpwh
->hdr
.htype
!= WH_HFINDNEXT
)
455 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
459 hIC
= GET_HWININET_FROM_LPWININETFINDNEXT(lpwh
);
460 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
)
462 WORKREQUEST workRequest
;
464 workRequest
.asyncall
= INTERNETFINDNEXTA
;
465 workRequest
.HFTPSESSION
= (DWORD
)hFind
;
466 workRequest
.LPFINDFILEDATA
= (DWORD
)lpvFindData
;
468 return INTERNET_AsyncCall(&workRequest
);
472 return INTERNET_FindNextFileA(hFind
, lpvFindData
);
476 /***********************************************************************
477 * INTERNET_FindNextFileA (Internal)
479 * Continues a file search from a previous call to FindFirstFile
486 BOOL WINAPI
INTERNET_FindNextFileA(HINTERNET hFind
, LPVOID lpvFindData
)
488 BOOL bSuccess
= TRUE
;
489 LPWININETAPPINFOA hIC
= NULL
;
490 LPWIN32_FIND_DATAA lpFindFileData
;
491 LPWININETFINDNEXTA lpwh
= (LPWININETFINDNEXTA
) hFind
;
495 if (NULL
== lpwh
|| lpwh
->hdr
.htype
!= WH_HFINDNEXT
)
497 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
501 /* Clear any error information */
502 INTERNET_SetLastError(0);
504 if (lpwh
->hdr
.lpwhparent
->htype
!= WH_HFTPSESSION
)
506 FIXME("Only FTP find next supported\n");
507 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
511 TRACE("index(%d) size(%ld)\n", lpwh
->index
, lpwh
->size
);
513 lpFindFileData
= (LPWIN32_FIND_DATAA
) lpvFindData
;
514 ZeroMemory(lpFindFileData
, sizeof(WIN32_FIND_DATAA
));
516 if (lpwh
->index
>= lpwh
->size
)
518 INTERNET_SetLastError(ERROR_NO_MORE_FILES
);
523 FTP_ConvertFileProp(&lpwh
->lpafp
[lpwh
->index
], lpFindFileData
);
526 TRACE("\nName: %s\nSize: %ld\n", lpFindFileData
->cFileName
, lpFindFileData
->nFileSizeLow
);
530 hIC
= GET_HWININET_FROM_LPWININETFINDNEXT(lpwh
);
531 if (hIC
->lpfnStatusCB
)
533 INTERNET_ASYNC_RESULT iar
;
535 iar
.dwResult
= (DWORD
)bSuccess
;
536 iar
.dwError
= iar
.dwError
= bSuccess
? ERROR_SUCCESS
:
537 INTERNET_GetLastError();
539 SendAsyncCallback(hIC
, hFind
, lpwh
->hdr
.dwContext
,
540 INTERNET_STATUS_REQUEST_COMPLETE
, &iar
,
541 sizeof(INTERNET_ASYNC_RESULT
));
548 /***********************************************************************
549 * INTERNET_CloseHandle (internal)
551 * Close internet handle
557 VOID
INTERNET_CloseHandle(LPWININETAPPINFOA lpwai
)
561 SendAsyncCallback(lpwai
, lpwai
, lpwai
->hdr
.dwContext
,
562 INTERNET_STATUS_HANDLE_CLOSING
, lpwai
,
565 if (lpwai
->lpszAgent
)
566 HeapFree(GetProcessHeap(), 0, lpwai
->lpszAgent
);
568 if (lpwai
->lpszProxy
)
569 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxy
);
571 if (lpwai
->lpszProxyBypass
)
572 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxyBypass
);
574 HeapFree(GetProcessHeap(), 0, lpwai
);
578 /***********************************************************************
579 * InternetCloseHandle (WININET.@)
581 * Generic close handle function
588 BOOL WINAPI
InternetCloseHandle(HINTERNET hInternet
)
591 LPWININETHANDLEHEADER lpwh
= (LPWININETHANDLEHEADER
) hInternet
;
593 TRACE("%p\n",hInternet
);
598 /* Clear any error information */
599 INTERNET_SetLastError(0);
605 INTERNET_CloseHandle((LPWININETAPPINFOA
) lpwh
);
609 case WH_HHTTPSESSION
:
610 HTTP_CloseHTTPSessionHandle((LPWININETHTTPSESSIONA
) lpwh
);
615 HTTP_CloseHTTPRequestHandle((LPWININETHTTPREQA
) lpwh
);
620 retval
= FTP_CloseSessionHandle((LPWININETFTPSESSIONA
) lpwh
);
624 retval
= FTP_CloseFindNextHandle((LPWININETFINDNEXTA
) lpwh
);
630 } __EXCEPT(page_fault
) {
631 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
640 /***********************************************************************
641 * SetUrlComponentValue (Internal)
643 * Helper function for InternetCrackUrlA
650 BOOL
SetUrlComponentValue(LPSTR
* lppszComponent
, LPDWORD dwComponentLen
,
651 LPCSTR lpszStart
, INT len
)
653 TRACE("%s (%d)\n", lpszStart
, len
);
655 if (*dwComponentLen
!= 0)
657 if (*lppszComponent
== NULL
)
659 *lppszComponent
= (LPSTR
)lpszStart
;
660 *dwComponentLen
= len
;
664 INT ncpylen
= min((*dwComponentLen
)-1, len
);
665 strncpy(*lppszComponent
, lpszStart
, ncpylen
);
666 (*lppszComponent
)[ncpylen
] = '\0';
667 *dwComponentLen
= ncpylen
;
675 /***********************************************************************
676 * InternetCrackUrlA (WININET.@)
678 * Break up URL into its components
680 * TODO: Handle dwFlags
687 BOOL WINAPI
InternetCrackUrlA(LPCSTR lpszUrl
, DWORD dwUrlLength
, DWORD dwFlags
,
688 LPURL_COMPONENTSA lpUrlComponents
)
692 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
695 LPSTR lpszParam
= NULL
;
696 BOOL bIsAbsolute
= FALSE
;
697 LPSTR lpszap
= (char*)lpszUrl
;
702 /* Determine if the URI is absolute. */
703 while (*lpszap
!= '\0')
705 if (isalnum(*lpszap
))
710 if ((*lpszap
== ':') && (lpszap
- lpszUrl
>= 2))
717 lpszcp
= (LPSTR
)lpszUrl
; /* Relative url */
724 lpszParam
= strpbrk(lpszap
, ";?");
725 if (lpszParam
!= NULL
)
727 if (!SetUrlComponentValue(&lpUrlComponents
->lpszExtraInfo
,
728 &lpUrlComponents
->dwExtraInfoLength
, lpszParam
+1, strlen(lpszParam
+1)))
734 if (bIsAbsolute
) /* Parse <protocol>:[//<net_loc>] */
738 /* Get scheme first. */
739 lpUrlComponents
->nScheme
= GetInternetScheme(lpszUrl
, lpszcp
- lpszUrl
);
740 if (!SetUrlComponentValue(&lpUrlComponents
->lpszScheme
,
741 &lpUrlComponents
->dwSchemeLength
, lpszUrl
, lpszcp
- lpszUrl
))
744 /* Eat ':' in protocol. */
747 /* Skip over slashes. */
759 lpszNetLoc
= strpbrk(lpszcp
, "/");
763 lpszNetLoc
= min(lpszNetLoc
, lpszParam
);
765 lpszNetLoc
= lpszParam
;
767 else if (!lpszNetLoc
)
768 lpszNetLoc
= lpszcp
+ strlen(lpszcp
);
776 /* [<user>[<:password>]@]<host>[:<port>] */
777 /* First find the user and password if they exist */
779 lpszHost
= strchr(lpszcp
, '@');
780 if (lpszHost
== NULL
|| lpszHost
> lpszNetLoc
)
782 /* username and password not specified. */
783 SetUrlComponentValue(&lpUrlComponents
->lpszUserName
,
784 &lpUrlComponents
->dwUserNameLength
, NULL
, 0);
785 SetUrlComponentValue(&lpUrlComponents
->lpszPassword
,
786 &lpUrlComponents
->dwPasswordLength
, NULL
, 0);
788 else /* Parse out username and password */
790 LPSTR lpszUser
= lpszcp
;
791 LPSTR lpszPasswd
= lpszHost
;
793 while (lpszcp
< lpszHost
)
801 SetUrlComponentValue(&lpUrlComponents
->lpszUserName
,
802 &lpUrlComponents
->dwUserNameLength
, lpszUser
, lpszPasswd
- lpszUser
);
804 if (lpszPasswd
!= lpszHost
)
806 SetUrlComponentValue(&lpUrlComponents
->lpszPassword
,
807 &lpUrlComponents
->dwPasswordLength
,
808 lpszPasswd
== lpszHost
? NULL
: lpszPasswd
,
809 lpszHost
- lpszPasswd
);
811 lpszcp
++; /* Advance to beginning of host */
814 /* Parse <host><:port> */
817 lpszPort
= lpszNetLoc
;
819 while (lpszcp
< lpszNetLoc
)
827 SetUrlComponentValue(&lpUrlComponents
->lpszHostName
,
828 &lpUrlComponents
->dwHostNameLength
, lpszHost
, lpszPort
- lpszHost
);
830 if (lpszPort
!= lpszNetLoc
)
831 lpUrlComponents
->nPort
= atoi(++lpszPort
);
833 lpUrlComponents
->nPort
= 0;
837 /* Here lpszcp points to:
839 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
840 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
842 if (lpszcp
!= 0 && *lpszcp
!= '\0' && (!lpszParam
|| lpszcp
< lpszParam
))
846 /* Only truncate the parameter list if it's already been saved
847 * in lpUrlComponents->lpszExtraInfo.
849 if (lpszParam
&& lpUrlComponents
->dwExtraInfoLength
)
850 len
= lpszParam
- lpszcp
;
853 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
854 * newlines if necessary.
856 LPSTR lpsznewline
= strchr (lpszcp
, '\n');
857 if (lpsznewline
!= NULL
)
858 len
= lpsznewline
- lpszcp
;
860 len
= strlen(lpszcp
);
863 if (!SetUrlComponentValue(&lpUrlComponents
->lpszUrlPath
,
864 &lpUrlComponents
->dwUrlPathLength
, lpszcp
, len
))
869 lpUrlComponents
->dwUrlPathLength
= 0;
872 TRACE("%s: host(%s) path(%s) extra(%s)\n", lpszUrl
, lpUrlComponents
->lpszHostName
,
873 lpUrlComponents
->lpszUrlPath
, lpUrlComponents
->lpszExtraInfo
);
879 /***********************************************************************
880 * GetUrlCacheEntryInfoA (WININET.@)
883 BOOL WINAPI
GetUrlCacheEntryInfoA(LPCSTR lpszUrl
,
884 LPINTERNET_CACHE_ENTRY_INFOA lpCacheEntry
,
885 LPDWORD lpCacheEntrySize
)
891 /***********************************************************************
892 * CommitUrlCacheEntryA (WININET.@)
895 BOOL WINAPI
CommitUrlCacheEntryA(LPCSTR lpszUrl
, LPCSTR lpszLocalName
,
896 FILETIME ExpireTime
, FILETIME lastModified
, DWORD cacheEntryType
,
897 LPBYTE lpHeaderInfo
, DWORD headerSize
, LPCSTR fileExtension
,
904 /***********************************************************************
905 * InternetAttemptConnect (WININET.@)
907 * Attempt to make a connection to the internet
910 * ERROR_SUCCESS on success
911 * Error value on failure
914 DWORD WINAPI
InternetAttemptConnect(DWORD dwReserved
)
917 return ERROR_SUCCESS
;
921 /***********************************************************************
922 * InternetCanonicalizeUrlA (WININET.@)
924 * Escape unsafe characters and spaces
931 BOOL WINAPI
InternetCanonicalizeUrlA(LPCSTR lpszUrl
, LPSTR lpszBuffer
,
932 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
935 TRACE("%s %p %p %08lx\n",debugstr_a(lpszUrl
), lpszBuffer
,
936 lpdwBufferLength
, dwFlags
);
938 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
939 dwFlags
^= ICU_NO_ENCODE
;
941 dwFlags
|= 0x80000000; /* Don't know what this means */
943 hr
= UrlCanonicalizeA(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwFlags
);
945 return (hr
== S_OK
) ? TRUE
: FALSE
;
948 /***********************************************************************
949 * InternetCanonicalizeUrlW (WININET.@)
951 * Escape unsafe characters and spaces
958 BOOL WINAPI
InternetCanonicalizeUrlW(LPCWSTR lpszUrl
, LPWSTR lpszBuffer
,
959 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
962 TRACE("%s %p %p %08lx\n", debugstr_w(lpszUrl
), lpszBuffer
,
963 lpdwBufferLength
, dwFlags
);
965 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
966 dwFlags
^= ICU_NO_ENCODE
;
968 dwFlags
|= 0x80000000; /* Don't know what this means */
970 hr
= UrlCanonicalizeW(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwFlags
);
972 return (hr
== S_OK
) ? TRUE
: FALSE
;
976 /***********************************************************************
977 * InternetSetStatusCallback (WININET.@)
979 * Sets up a callback function which is called as progress is made
980 * during an operation.
983 * Previous callback or NULL on success
984 * INTERNET_INVALID_STATUS_CALLBACK on failure
987 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallback(
988 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
990 INTERNET_STATUS_CALLBACK retVal
;
991 LPWININETAPPINFOA lpwai
= (LPWININETAPPINFOA
)hInternet
;
993 TRACE("0x%08lx\n", (ULONG
)hInternet
);
994 if (lpwai
->hdr
.htype
!= WH_HINIT
)
995 return INTERNET_INVALID_STATUS_CALLBACK
;
997 retVal
= lpwai
->lpfnStatusCB
;
998 lpwai
->lpfnStatusCB
= lpfnIntCB
;
1004 /***********************************************************************
1005 * InternetWriteFile (WININET.@)
1007 * Write data to an open internet file
1014 BOOL WINAPI
InternetWriteFile(HINTERNET hFile
, LPCVOID lpBuffer
,
1015 DWORD dwNumOfBytesToWrite
, LPDWORD lpdwNumOfBytesWritten
)
1017 BOOL retval
= FALSE
;
1019 LPWININETHANDLEHEADER lpwh
= (LPWININETHANDLEHEADER
) hFile
;
1025 switch (lpwh
->htype
)
1028 nSocket
= ((LPWININETHTTPREQA
)hFile
)->nSocketFD
;
1032 nSocket
= ((LPWININETFILE
)hFile
)->nDataSocket
;
1041 int res
= send(nSocket
, lpBuffer
, dwNumOfBytesToWrite
, 0);
1042 retval
= (res
>= 0);
1043 *lpdwNumOfBytesWritten
= retval
? res
: 0;
1050 /***********************************************************************
1051 * InternetReadFile (WININET.@)
1053 * Read data from an open internet file
1060 BOOL WINAPI
InternetReadFile(HINTERNET hFile
, LPVOID lpBuffer
,
1061 DWORD dwNumOfBytesToRead
, LPDWORD dwNumOfBytesRead
)
1063 BOOL retval
= FALSE
;
1065 LPWININETHANDLEHEADER lpwh
= (LPWININETHANDLEHEADER
) hFile
;
1072 switch (lpwh
->htype
)
1075 nSocket
= ((LPWININETHTTPREQA
)hFile
)->nSocketFD
;
1079 nSocket
= ((LPWININETFILE
)hFile
)->nDataSocket
;
1088 int res
= recv(nSocket
, lpBuffer
, dwNumOfBytesToRead
, 0);
1089 retval
= (res
>= 0);
1090 *dwNumOfBytesRead
= retval
? res
: 0;
1095 /***********************************************************************
1096 * InternetReadFileExA (WININET.@)
1098 * Read data from an open internet file
1105 BOOL WINAPI
InternetReadFileExA(HINTERNET hFile
, LPINTERNET_BUFFERSA lpBuffer
,
1106 DWORD dwFlags
, DWORD dwContext
)
1112 /***********************************************************************
1113 * InternetReadFileExW (WININET.@)
1115 * Read data from an open internet file
1122 BOOL WINAPI
InternetReadFileExW(HINTERNET hFile
, LPINTERNET_BUFFERSW lpBuffer
,
1123 DWORD dwFlags
, DWORD dwContext
)
1127 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1131 /***********************************************************************
1132 * InternetQueryOptionA (WININET.@)
1134 * Queries an options on the specified handle
1141 BOOL WINAPI
InternetQueryOptionA(HINTERNET hInternet
, DWORD dwOption
,
1142 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
1144 LPWININETHANDLEHEADER lpwhh
;
1145 BOOL bSuccess
= FALSE
;
1147 TRACE("0x%08lx\n", dwOption
);
1149 if (NULL
== hInternet
)
1151 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
1155 lpwhh
= (LPWININETHANDLEHEADER
) hInternet
;
1159 case INTERNET_OPTION_HANDLE_TYPE
:
1161 ULONG type
= lpwhh
->htype
;
1162 TRACE("INTERNET_OPTION_HANDLE_TYPE: %ld\n", type
);
1164 if (*lpdwBufferLength
< sizeof(ULONG
))
1165 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1168 memcpy(lpBuffer
, &type
, sizeof(ULONG
));
1169 *lpdwBufferLength
= sizeof(ULONG
);
1175 case INTERNET_OPTION_REQUEST_FLAGS
:
1178 TRACE("INTERNET_OPTION_REQUEST_FLAGS: %ld\n", flags
);
1179 if (*lpdwBufferLength
< sizeof(ULONG
))
1180 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1183 memcpy(lpBuffer
, &flags
, sizeof(ULONG
));
1184 *lpdwBufferLength
= sizeof(ULONG
);
1190 case INTERNET_OPTION_URL
:
1191 case INTERNET_OPTION_DATAFILE_NAME
:
1193 ULONG type
= lpwhh
->htype
;
1194 if (type
== WH_HHTTPREQ
)
1196 LPWININETHTTPREQA lpreq
= hInternet
;
1199 sprintf(url
,"http://%s%s",lpreq
->lpszHostName
,lpreq
->lpszPath
);
1200 TRACE("INTERNET_OPTION_URL: %s\n",url
);
1201 if (*lpdwBufferLength
< strlen(url
)+1)
1202 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1205 memcpy(lpBuffer
, url
, strlen(url
)+1);
1206 *lpdwBufferLength
= strlen(url
)+1;
1212 case INTERNET_OPTION_HTTP_VERSION
:
1215 * Presently hardcoded to 1.1
1217 ((HTTP_VERSION_INFO
*)lpBuffer
)->dwMajorVersion
= 1;
1218 ((HTTP_VERSION_INFO
*)lpBuffer
)->dwMinorVersion
= 1;
1224 FIXME("Stub! %ld \n",dwOption
);
1232 /***********************************************************************
1233 * InternetSetOptionW (WININET.@)
1235 * Sets an options on the specified handle
1242 BOOL WINAPI
InternetSetOptionW(HINTERNET hInternet
, DWORD dwOption
,
1243 LPVOID lpBuffer
, DWORD dwBufferLength
)
1245 LPWININETHANDLEHEADER lpwhh
;
1246 BOOL bSuccess
= FALSE
;
1248 TRACE("0x%08lx\n", dwOption
);
1250 if (NULL
== hInternet
)
1252 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
1256 lpwhh
= (LPWININETHANDLEHEADER
) hInternet
;
1261 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1270 /***********************************************************************
1271 * InternetSetOptionA (WININET.@)
1273 * Sets an options on the specified handle.
1280 BOOL WINAPI
InternetSetOptionA(HINTERNET hInternet
, DWORD dwOption
,
1281 LPVOID lpBuffer
, DWORD dwBufferLength
)
1283 /* FIXME!!! implement if lpBuffer is a string, dwBufferLength is
1285 return InternetSetOptionW(hInternet
,dwOption
, lpBuffer
,
1290 /***********************************************************************
1291 * InternetGetCookieA (WININET.@)
1293 * Retrieve cookie from the specified url
1300 BOOL WINAPI
InternetGetCookieA(LPCSTR lpszUrl
, LPCSTR lpszCookieName
,
1301 LPSTR lpCookieData
, LPDWORD lpdwSize
)
1304 TRACE("(%s,%s,%p)\n", debugstr_a(lpszUrl
),debugstr_a(lpszCookieName
),
1310 /***********************************************************************
1311 * InternetGetCookieW (WININET.@)
1313 * Retrieve cookie from the specified url
1320 BOOL WINAPI
InternetGetCookieW(LPCSTR lpszUrl
, LPCWSTR lpszCookieName
,
1321 LPWSTR lpCookieData
, LPDWORD lpdwSize
)
1324 TRACE("(%s,%s,%p)\n", debugstr_a(lpszUrl
), debugstr_w(lpszCookieName
),
1330 /***********************************************************************
1331 * InternetSetCookieA (WININET.@)
1333 * Sets cookie for the specified url
1340 BOOL WINAPI
InternetSetCookieA(LPCSTR lpszUrl
, LPCSTR lpszCookieName
,
1341 LPCSTR lpCookieData
)
1344 TRACE("(%s,%s,%s)\n", debugstr_a(lpszUrl
),
1345 debugstr_a(lpszCookieName
), debugstr_a(lpCookieData
));
1350 /***********************************************************************
1351 * InternetSetCookieW (WININET.@)
1353 * Sets cookie for the specified url
1360 BOOL WINAPI
InternetSetCookieW(LPCSTR lpszUrl
, LPCWSTR lpszCookieName
,
1361 LPCWSTR lpCookieData
)
1364 TRACE("(%s,%s,%s)\n", debugstr_a(lpszUrl
),
1365 debugstr_w(lpszCookieName
), debugstr_w(lpCookieData
));
1370 /***********************************************************************
1371 * GetInternetScheme (internal)
1377 * INTERNET_SCHEME_UNKNOWN on failure
1380 INTERNET_SCHEME
GetInternetScheme(LPCSTR lpszScheme
, INT nMaxCmp
)
1383 if(lpszScheme
==NULL
)
1384 return INTERNET_SCHEME_UNKNOWN
;
1386 if (!strncasecmp("ftp", lpszScheme
, nMaxCmp
))
1387 return INTERNET_SCHEME_FTP
;
1388 else if (!strncasecmp("gopher", lpszScheme
, nMaxCmp
))
1389 return INTERNET_SCHEME_GOPHER
;
1390 else if (!strncasecmp("http", lpszScheme
, nMaxCmp
))
1391 return INTERNET_SCHEME_HTTP
;
1392 else if (!strncasecmp("https", lpszScheme
, nMaxCmp
))
1393 return INTERNET_SCHEME_HTTPS
;
1394 else if (!strncasecmp("file", lpszScheme
, nMaxCmp
))
1395 return INTERNET_SCHEME_FILE
;
1396 else if (!strncasecmp("news", lpszScheme
, nMaxCmp
))
1397 return INTERNET_SCHEME_NEWS
;
1398 else if (!strncasecmp("mailto", lpszScheme
, nMaxCmp
))
1399 return INTERNET_SCHEME_MAILTO
;
1401 return INTERNET_SCHEME_UNKNOWN
;
1404 /***********************************************************************
1405 * InternetCheckConnectionA (WININET.@)
1407 * Pings a requested host to check internet connection
1410 * TRUE on success and FALSE on failure. If a failure then
1411 * ERROR_NOT_CONNECTED is placesd into GetLastError
1414 BOOL WINAPI
InternetCheckConnectionA( LPCSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
1417 * this is a kludge which runs the resident ping program and reads the output.
1419 * Anyone have a better idea?
1430 * Crack or set the Address
1432 if (lpszUrl
== NULL
)
1435 * According to the doc we are supost to use the ip for the next
1436 * server in the WnInet internal server database. I have
1437 * no idea what that is or how to get it.
1439 * So someone needs to implement this.
1441 FIXME("Unimplemented with URL of NULL\n");
1446 URL_COMPONENTSA componets
;
1448 ZeroMemory(&componets
,sizeof(URL_COMPONENTSA
));
1449 componets
.lpszHostName
= (LPSTR
)&host
;
1450 componets
.dwHostNameLength
= 1024;
1452 if (!InternetCrackUrlA(lpszUrl
,0,0,&componets
))
1455 TRACE("host name : %s\n",componets
.lpszHostName
);
1459 * Build our ping command
1461 strcpy(command
,"ping -w 1 ");
1462 strcat(command
,host
);
1463 strcat(command
," >/dev/null 2>/dev/null");
1465 TRACE("Ping command is : %s\n",command
);
1467 status
= system(command
);
1469 TRACE("Ping returned a code of %i \n",status
);
1471 /* Ping return code of 0 indicates success */
1478 SetLastError(ERROR_NOT_CONNECTED
);
1484 /***********************************************************************
1485 * InternetCheckConnectionW (WININET.@)
1487 * Pings a requested host to check internet connection
1490 * TRUE on success and FALSE on failure. If a failure then
1491 * ERROR_NOT_CONNECTED is placed into GetLastError
1494 BOOL WINAPI
InternetCheckConnectionW(LPCWSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
1500 len
= lstrlenW(lpszUrl
)+1;
1501 if (!(szUrl
= (CHAR
*)malloc(len
*sizeof(CHAR
))))
1503 WideCharToMultiByte(CP_ACP
, -1, lpszUrl
, -1, szUrl
, len
, NULL
, NULL
);
1504 rc
= InternetCheckConnectionA((LPCSTR
)szUrl
, dwFlags
, dwReserved
);
1511 /**********************************************************
1512 * InternetOpenUrlA (WININET.@)
1517 * handle of connection or NULL on failure
1519 HINTERNET WINAPI
InternetOpenUrlA(HINTERNET hInternet
, LPCSTR lpszUrl
,
1520 LPCSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD dwContext
)
1522 URL_COMPONENTSA urlComponents
;
1523 char protocol
[32], hostName
[MAXHOSTNAME
], userName
[1024];
1524 char password
[1024], path
[2048], extra
[1024];
1525 HINTERNET client
= NULL
, client1
= NULL
;
1526 urlComponents
.dwStructSize
= sizeof(URL_COMPONENTSA
);
1527 urlComponents
.lpszScheme
= protocol
;
1528 urlComponents
.dwSchemeLength
= 32;
1529 urlComponents
.lpszHostName
= hostName
;
1530 urlComponents
.dwHostNameLength
= MAXHOSTNAME
;
1531 urlComponents
.lpszUserName
= userName
;
1532 urlComponents
.dwUserNameLength
= 1024;
1533 urlComponents
.lpszPassword
= password
;
1534 urlComponents
.dwPasswordLength
= 1024;
1535 urlComponents
.lpszUrlPath
= path
;
1536 urlComponents
.dwUrlPathLength
= 2048;
1537 urlComponents
.lpszExtraInfo
= extra
;
1538 urlComponents
.dwExtraInfoLength
= 1024;
1539 if(!InternetCrackUrlA(lpszUrl
, strlen(lpszUrl
), 0, &urlComponents
))
1541 switch(urlComponents
.nScheme
) {
1542 case INTERNET_SCHEME_FTP
:
1543 if(urlComponents
.nPort
== 0)
1544 urlComponents
.nPort
= INTERNET_DEFAULT_FTP_PORT
;
1545 client
= InternetConnectA(hInternet
, hostName
, urlComponents
.nPort
,
1546 userName
, password
, INTERNET_SERVICE_FTP
, dwFlags
, dwContext
);
1547 return FtpOpenFileA(client
, path
, GENERIC_READ
, dwFlags
, dwContext
);
1549 case INTERNET_SCHEME_HTTP
:
1550 case INTERNET_SCHEME_HTTPS
:
1552 LPCSTR accept
[2] = { "*/*", NULL
};
1553 char *hostreq
=(char*)malloc(strlen(hostName
)+9);
1554 sprintf(hostreq
, "Host: %s\r\n", hostName
);
1555 if(urlComponents
.nPort
== 0) {
1556 if(urlComponents
.nScheme
== INTERNET_SCHEME_HTTP
)
1557 urlComponents
.nPort
= INTERNET_DEFAULT_HTTP_PORT
;
1559 urlComponents
.nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
1561 client
= InternetConnectA(hInternet
, hostName
, urlComponents
.nPort
, userName
,
1562 password
, INTERNET_SERVICE_HTTP
, dwFlags
, dwContext
);
1565 client1
= HttpOpenRequestA(hInternet
, NULL
, path
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
1566 if(client1
== NULL
) {
1567 InternetCloseHandle(client
);
1570 HttpAddRequestHeadersA(client1
, lpszHeaders
, dwHeadersLength
, HTTP_ADDREQ_FLAG_ADD
);
1571 HttpAddRequestHeadersA(client1
, hostreq
, -1L, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
1572 if(!HttpSendRequestA(client1
, NULL
, 0, NULL
, 0)) {
1573 InternetCloseHandle(client1
);
1574 InternetCloseHandle(client
);
1580 case INTERNET_SCHEME_GOPHER
:
1581 /* gopher doesn't seem to be implemented in wine, but it's supposed
1582 * to be supported by InternetOpenUrlA. */
1587 InternetCloseHandle(client
);
1591 /**********************************************************
1592 * InternetOpenUrlW (WININET.@)
1597 * handle of connection or NULL on failure
1599 HINTERNET WINAPI
InternetOpenUrlW(HINTERNET hInternet
, LPCWSTR lpszUrl
,
1600 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD dwContext
)
1602 HINTERNET rc
= (HINTERNET
)NULL
;
1604 INT lenUrl
= lstrlenW(lpszUrl
)+1;
1605 INT lenHeaders
= lstrlenW(lpszHeaders
)+1;
1606 CHAR
*szUrl
= (CHAR
*)malloc(lenUrl
*sizeof(CHAR
));
1607 CHAR
*szHeaders
= (CHAR
*)malloc(lenHeaders
*sizeof(CHAR
));
1609 if (!szUrl
|| !szHeaders
)
1615 return (HINTERNET
)NULL
;
1618 WideCharToMultiByte(CP_ACP
, -1, lpszUrl
, -1, szUrl
, lenUrl
,
1620 WideCharToMultiByte(CP_ACP
, -1, lpszHeaders
, -1, szHeaders
, lenHeaders
,
1623 rc
= InternetOpenUrlA(hInternet
, szUrl
, szHeaders
,
1624 dwHeadersLength
, dwFlags
, dwContext
);
1633 /***********************************************************************
1634 * INTERNET_SetLastError (internal)
1636 * Set last thread specific error
1641 void INTERNET_SetLastError(DWORD dwError
)
1643 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
1645 SetLastError(dwError
);
1646 lpwite
->dwError
= dwError
;
1650 /***********************************************************************
1651 * INTERNET_GetLastError (internal)
1653 * Get last thread specific error
1658 DWORD
INTERNET_GetLastError()
1660 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
1661 return lpwite
->dwError
;
1665 /***********************************************************************
1666 * INTERNET_WorkerThreadFunc (internal)
1668 * Worker thread execution function
1673 DWORD
INTERNET_WorkerThreadFunc(LPVOID
*lpvParam
)
1680 INTERNET_ExecuteWork();
1683 dwWaitRes
= WaitForMultipleObjects(2, hEventArray
, FALSE
, MAX_IDLE_WORKER
);
1685 if (dwWaitRes
== WAIT_OBJECT_0
+ 1)
1686 INTERNET_ExecuteWork();
1690 InterlockedIncrement(&dwNumIdleThreads
);
1693 InterlockedDecrement(&dwNumIdleThreads
);
1694 InterlockedDecrement(&dwNumThreads
);
1695 TRACE("Worker thread exiting\n");
1700 /***********************************************************************
1701 * INTERNET_InsertWorkRequest (internal)
1703 * Insert work request into queue
1708 BOOL
INTERNET_InsertWorkRequest(LPWORKREQUEST lpWorkRequest
)
1710 BOOL bSuccess
= FALSE
;
1711 LPWORKREQUEST lpNewRequest
;
1715 lpNewRequest
= HeapAlloc(GetProcessHeap(), 0, sizeof(WORKREQUEST
));
1718 memcpy(lpNewRequest
, lpWorkRequest
, sizeof(WORKREQUEST
));
1719 lpNewRequest
->prev
= NULL
;
1721 EnterCriticalSection(&csQueue
);
1723 lpNewRequest
->next
= lpWorkQueueTail
;
1724 if (lpWorkQueueTail
)
1725 lpWorkQueueTail
->prev
= lpNewRequest
;
1726 lpWorkQueueTail
= lpNewRequest
;
1727 if (!lpHeadWorkQueue
)
1728 lpHeadWorkQueue
= lpWorkQueueTail
;
1730 LeaveCriticalSection(&csQueue
);
1733 InterlockedIncrement(&dwNumJobs
);
1740 /***********************************************************************
1741 * INTERNET_GetWorkRequest (internal)
1743 * Retrieves work request from queue
1748 BOOL
INTERNET_GetWorkRequest(LPWORKREQUEST lpWorkRequest
)
1750 BOOL bSuccess
= FALSE
;
1751 LPWORKREQUEST lpRequest
= NULL
;
1755 EnterCriticalSection(&csQueue
);
1757 if (lpHeadWorkQueue
)
1759 lpRequest
= lpHeadWorkQueue
;
1760 lpHeadWorkQueue
= lpHeadWorkQueue
->prev
;
1761 if (lpRequest
== lpWorkQueueTail
)
1762 lpWorkQueueTail
= lpHeadWorkQueue
;
1765 LeaveCriticalSection(&csQueue
);
1769 memcpy(lpWorkRequest
, lpRequest
, sizeof(WORKREQUEST
));
1770 HeapFree(GetProcessHeap(), 0, lpRequest
);
1772 InterlockedDecrement(&dwNumJobs
);
1779 /***********************************************************************
1780 * INTERNET_AsyncCall (internal)
1782 * Retrieves work request from queue
1787 BOOL
INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest
)
1791 BOOL bSuccess
= FALSE
;
1795 if (InterlockedDecrement(&dwNumIdleThreads
) < 0)
1797 InterlockedIncrement(&dwNumIdleThreads
);
1799 if (InterlockedIncrement(&dwNumThreads
) > MAX_WORKER_THREADS
||
1800 !(hThread
= CreateThread(NULL
, 0,
1801 (LPTHREAD_START_ROUTINE
)INTERNET_WorkerThreadFunc
, NULL
, 0, &dwTID
)))
1803 InterlockedDecrement(&dwNumThreads
);
1804 INTERNET_SetLastError(ERROR_INTERNET_ASYNC_THREAD_FAILED
);
1808 TRACE("Created new thread\n");
1812 INTERNET_InsertWorkRequest(lpWorkRequest
);
1813 SetEvent(hWorkEvent
);
1821 /***********************************************************************
1822 * INTERNET_ExecuteWork (internal)
1827 VOID
INTERNET_ExecuteWork()
1829 WORKREQUEST workRequest
;
1833 if (INTERNET_GetWorkRequest(&workRequest
))
1835 TRACE("Got work %d\n", workRequest
.asyncall
);
1836 switch (workRequest
.asyncall
)
1839 FTP_FtpPutFileA((HINTERNET
)workRequest
.HFTPSESSION
, (LPCSTR
)workRequest
.LPSZLOCALFILE
,
1840 (LPCSTR
)workRequest
.LPSZNEWREMOTEFILE
, workRequest
.DWFLAGS
, workRequest
.DWCONTEXT
);
1841 HeapFree(GetProcessHeap(), 0, (LPVOID
)workRequest
.LPSZLOCALFILE
);
1842 HeapFree(GetProcessHeap(), 0, (LPVOID
)workRequest
.LPSZNEWREMOTEFILE
);
1845 case FTPSETCURRENTDIRECTORYA
:
1846 FTP_FtpSetCurrentDirectoryA((HINTERNET
)workRequest
.HFTPSESSION
,
1847 (LPCSTR
)workRequest
.LPSZDIRECTORY
);
1848 HeapFree(GetProcessHeap(), 0, (LPVOID
)workRequest
.LPSZDIRECTORY
);
1851 case FTPCREATEDIRECTORYA
:
1852 FTP_FtpCreateDirectoryA((HINTERNET
)workRequest
.HFTPSESSION
,
1853 (LPCSTR
)workRequest
.LPSZDIRECTORY
);
1854 HeapFree(GetProcessHeap(), 0, (LPVOID
)workRequest
.LPSZDIRECTORY
);
1857 case FTPFINDFIRSTFILEA
:
1858 FTP_FtpFindFirstFileA((HINTERNET
)workRequest
.HFTPSESSION
,
1859 (LPCSTR
)workRequest
.LPSZSEARCHFILE
,
1860 (LPWIN32_FIND_DATAA
)workRequest
.LPFINDFILEDATA
, workRequest
.DWFLAGS
,
1861 workRequest
.DWCONTEXT
);
1862 HeapFree(GetProcessHeap(), 0, (LPVOID
)workRequest
.LPSZSEARCHFILE
);
1865 case FTPGETCURRENTDIRECTORYA
:
1866 FTP_FtpGetCurrentDirectoryA((HINTERNET
)workRequest
.HFTPSESSION
,
1867 (LPSTR
)workRequest
.LPSZDIRECTORY
, (LPDWORD
)workRequest
.LPDWDIRECTORY
);
1871 FTP_FtpOpenFileA((HINTERNET
)workRequest
.HFTPSESSION
,
1872 (LPCSTR
)workRequest
.LPSZFILENAME
,
1873 workRequest
.FDWACCESS
,
1874 workRequest
.DWFLAGS
,
1875 workRequest
.DWCONTEXT
);
1876 HeapFree(GetProcessHeap(), 0, (LPVOID
)workRequest
.LPSZFILENAME
);
1880 FTP_FtpGetFileA((HINTERNET
)workRequest
.HFTPSESSION
,
1881 (LPCSTR
)workRequest
.LPSZREMOTEFILE
,
1882 (LPCSTR
)workRequest
.LPSZNEWFILE
,
1883 (BOOL
)workRequest
.FFAILIFEXISTS
,
1884 workRequest
.DWLOCALFLAGSATTRIBUTE
,
1885 workRequest
.DWFLAGS
,
1886 workRequest
.DWCONTEXT
);
1887 HeapFree(GetProcessHeap(), 0, (LPVOID
)workRequest
.LPSZREMOTEFILE
);
1888 HeapFree(GetProcessHeap(), 0, (LPVOID
)workRequest
.LPSZNEWFILE
);
1891 case FTPDELETEFILEA
:
1892 FTP_FtpDeleteFileA((HINTERNET
)workRequest
.HFTPSESSION
,
1893 (LPCSTR
)workRequest
.LPSZFILENAME
);
1894 HeapFree(GetProcessHeap(), 0, (LPVOID
)workRequest
.LPSZFILENAME
);
1897 case FTPREMOVEDIRECTORYA
:
1898 FTP_FtpRemoveDirectoryA((HINTERNET
)workRequest
.HFTPSESSION
,
1899 (LPCSTR
)workRequest
.LPSZDIRECTORY
);
1900 HeapFree(GetProcessHeap(), 0, (LPVOID
)workRequest
.LPSZDIRECTORY
);
1903 case FTPRENAMEFILEA
:
1904 FTP_FtpRenameFileA((HINTERNET
)workRequest
.HFTPSESSION
,
1905 (LPCSTR
)workRequest
.LPSZSRCFILE
,
1906 (LPCSTR
)workRequest
.LPSZDESTFILE
);
1907 HeapFree(GetProcessHeap(), 0, (LPVOID
)workRequest
.LPSZSRCFILE
);
1908 HeapFree(GetProcessHeap(), 0, (LPVOID
)workRequest
.LPSZDESTFILE
);
1911 case INTERNETFINDNEXTA
:
1912 INTERNET_FindNextFileA((HINTERNET
)workRequest
.HFTPSESSION
,
1913 (LPWIN32_FIND_DATAA
)workRequest
.LPFINDFILEDATA
);
1916 case HTTPSENDREQUESTA
:
1917 HTTP_HttpSendRequestA((HINTERNET
)workRequest
.HFTPSESSION
,
1918 (LPCSTR
)workRequest
.LPSZHEADER
,
1919 workRequest
.DWHEADERLENGTH
,
1920 (LPVOID
)workRequest
.LPOPTIONAL
,
1921 workRequest
.DWOPTIONALLENGTH
);
1922 HeapFree(GetProcessHeap(), 0, (LPVOID
)workRequest
.LPSZHEADER
);
1925 case HTTPOPENREQUESTA
:
1926 HTTP_HttpOpenRequestA((HINTERNET
)workRequest
.HFTPSESSION
,
1927 (LPCSTR
)workRequest
.LPSZVERB
,
1928 (LPCSTR
)workRequest
.LPSZOBJECTNAME
,
1929 (LPCSTR
)workRequest
.LPSZVERSION
,
1930 (LPCSTR
)workRequest
.LPSZREFERRER
,
1931 (LPCSTR
*)workRequest
.LPSZACCEPTTYPES
,
1932 workRequest
.DWFLAGS
,
1933 workRequest
.DWCONTEXT
);
1934 HeapFree(GetProcessHeap(), 0, (LPVOID
)workRequest
.LPSZVERB
);
1935 HeapFree(GetProcessHeap(), 0, (LPVOID
)workRequest
.LPSZOBJECTNAME
);
1936 HeapFree(GetProcessHeap(), 0, (LPVOID
)workRequest
.LPSZVERSION
);
1937 HeapFree(GetProcessHeap(), 0, (LPVOID
)workRequest
.LPSZREFERRER
);
1941 SendAsyncCallbackInt((LPWININETAPPINFOA
)workRequest
.param1
,
1942 (HINTERNET
)workRequest
.param2
, workRequest
.param3
,
1943 workRequest
.param4
, (LPVOID
)workRequest
.param5
,
1944 workRequest
.param6
);
1951 /***********************************************************************
1952 * INTERNET_GetResponseBuffer
1957 LPSTR
INTERNET_GetResponseBuffer()
1959 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
1961 return lpwite
->response
;
1965 /***********************************************************************
1966 * INTERNET_GetNextLine (internal)
1968 * Parse next line in directory string listing
1971 * Pointer to beginning of next line
1976 LPSTR
INTERNET_GetNextLine(INT nSocket
, LPSTR lpszBuffer
, LPDWORD dwBuffer
)
1980 BOOL bSuccess
= FALSE
;
1986 FD_SET(nSocket
, &infd
);
1987 tv
.tv_sec
=RESPONSE_TIMEOUT
;
1990 while (nRecv
< *dwBuffer
)
1992 if (select(nSocket
+1,&infd
,NULL
,NULL
,&tv
) > 0)
1994 if (recv(nSocket
, &lpszBuffer
[nRecv
], 1, 0) <= 0)
1996 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS
);
2000 if (lpszBuffer
[nRecv
] == '\n')
2005 if (lpszBuffer
[nRecv
] != '\r')
2010 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT
);
2018 lpszBuffer
[nRecv
] = '\0';
2019 *dwBuffer
= nRecv
- 1;
2020 TRACE(":%d %s\n", nRecv
, lpszBuffer
);
2029 /***********************************************************************
2032 BOOL WINAPI
InternetQueryDataAvailable( HINTERNET hFile
,
2033 LPDWORD lpdwNumberOfBytesAvailble
,
2034 DWORD dwFlags
, DWORD dwConext
)
2036 LPWININETHTTPREQA lpwhr
= (LPWININETHTTPREQA
) hFile
;
2043 SetLastError(ERROR_NO_MORE_FILES
);
2047 TRACE("--> %p %i %i\n",lpwhr
,lpwhr
->hdr
.htype
,lpwhr
->nSocketFD
);
2049 switch (lpwhr
->hdr
.htype
)
2052 nSocket
= lpwhr
->nSocketFD
;
2063 retval
= recv(nSocket
,buffer
,4048,MSG_PEEK
);
2067 SetLastError(ERROR_NO_MORE_FILES
);
2070 if (lpdwNumberOfBytesAvailble
)
2072 (*lpdwNumberOfBytesAvailble
) = retval
;
2075 TRACE("<-- %i\n",retval
);
2080 /***********************************************************************
2083 BOOL WINAPI
InternetLockRequestFile( HINTERNET hInternet
, HANDLE
2090 BOOL WINAPI
InternetUnlockRequestFile( HANDLE hLockHandle
)
2097 /***********************************************************************
2100 * On windows this function is supposed to dial the default internet
2101 * connection. We don't want to have Wine dial out to the internet so
2102 * we return TRUE by default. It might be nice to check if we are connected.
2109 BOOL WINAPI
InternetAutoDial(DWORD dwFlags
, HWND hwndParent
)
2113 /* Tell that we are connected to the internet. */
2117 /***********************************************************************
2118 * InternetAutoDialHangup
2120 * Hangs up an connection made with InternetAutoDial
2129 BOOL WINAPI
InternetAutodialHangup(DWORD dwReserved
)
2133 /* we didn't dial, we don't disconnect */