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 * InternetCrackUrlW (WININET.@)
882 BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl, DWORD dwUrlLength, DWORD dwFlags,
883 LPURL_COMPONENTSW lpUrlComponents)
889 /***********************************************************************
890 * InternetAttemptConnect (WININET.@)
892 * Attempt to make a connection to the internet
895 * ERROR_SUCCESS on success
896 * Error value on failure
899 DWORD WINAPI InternetAttemptConnect(DWORD dwReserved)
902 return ERROR_SUCCESS;
906 /***********************************************************************
907 * InternetCanonicalizeUrlA (WININET.@)
909 * Escape unsafe characters and spaces
916 BOOL WINAPI InternetCanonicalizeUrlA(LPCSTR lpszUrl, LPSTR lpszBuffer,
917 LPDWORD lpdwBufferLength, DWORD dwFlags)
920 TRACE("%s %p %p %08lx\n",debugstr_a(lpszUrl), lpszBuffer,
921 lpdwBufferLength, dwFlags);
923 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
924 dwFlags ^= ICU_NO_ENCODE;
926 dwFlags |= 0x80000000; /* Don't know what this means */
928 hr = UrlCanonicalizeA(lpszUrl, lpszBuffer, lpdwBufferLength, dwFlags);
930 return (hr == S_OK) ? TRUE : FALSE;
933 /***********************************************************************
934 * InternetCanonicalizeUrlW (WININET.@)
936 * Escape unsafe characters and spaces
943 BOOL WINAPI InternetCanonicalizeUrlW(LPCWSTR lpszUrl, LPWSTR lpszBuffer,
944 LPDWORD lpdwBufferLength, DWORD dwFlags)
947 TRACE("%s %p %p %08lx\n", debugstr_w(lpszUrl), lpszBuffer,
948 lpdwBufferLength, dwFlags);
950 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
951 dwFlags ^= ICU_NO_ENCODE;
953 dwFlags |= 0x80000000; /* Don't know what this means */
955 hr = UrlCanonicalizeW(lpszUrl, lpszBuffer, lpdwBufferLength, dwFlags);
957 return (hr == S_OK) ? TRUE : FALSE;
961 /***********************************************************************
962 * InternetSetStatusCallback (WININET.@)
964 * Sets up a callback function which is called as progress is made
965 * during an operation.
968 * Previous callback or NULL on success
969 * INTERNET_INVALID_STATUS_CALLBACK on failure
972 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallback(
973 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
975 INTERNET_STATUS_CALLBACK retVal;
976 LPWININETAPPINFOA lpwai = (LPWININETAPPINFOA)hInternet;
978 TRACE("0x%08lx\n", (ULONG)hInternet);
979 if (lpwai->hdr.htype != WH_HINIT)
980 return INTERNET_INVALID_STATUS_CALLBACK;
982 retVal = lpwai->lpfnStatusCB;
983 lpwai->lpfnStatusCB = lpfnIntCB;
989 /***********************************************************************
990 * InternetWriteFile (WININET.@)
992 * Write data to an open internet file
999 BOOL WINAPI InternetWriteFile(HINTERNET hFile, LPCVOID lpBuffer ,
1000 DWORD dwNumOfBytesToWrite, LPDWORD lpdwNumOfBytesWritten)
1002 BOOL retval = FALSE;
1004 LPWININETHANDLEHEADER lpwh = (LPWININETHANDLEHEADER) hFile;
1010 switch (lpwh->htype)
1013 nSocket = ((LPWININETHTTPREQA)hFile)->nSocketFD;
1017 nSocket = ((LPWININETFILE)hFile)->nDataSocket;
1026 int res = send(nSocket, lpBuffer, dwNumOfBytesToWrite, 0);
1027 retval = (res >= 0);
1028 *lpdwNumOfBytesWritten = retval ? res : 0;
1035 /***********************************************************************
1036 * InternetReadFile (WININET.@)
1038 * Read data from an open internet file
1045 BOOL WINAPI InternetReadFile(HINTERNET hFile, LPVOID lpBuffer,
1046 DWORD dwNumOfBytesToRead, LPDWORD dwNumOfBytesRead)
1048 BOOL retval = FALSE;
1050 LPWININETHANDLEHEADER lpwh = (LPWININETHANDLEHEADER) hFile;
1057 switch (lpwh->htype)
1060 nSocket = ((LPWININETHTTPREQA)hFile)->nSocketFD;
1064 nSocket = ((LPWININETFILE)hFile)->nDataSocket;
1073 int res = recv(nSocket, lpBuffer, dwNumOfBytesToRead, 0);
1074 retval = (res >= 0);
1075 *dwNumOfBytesRead = retval ? res : 0;
1080 /***********************************************************************
1081 * InternetReadFileExA (WININET.@)
1083 * Read data from an open internet file
1090 BOOL WINAPI InternetReadFileExA(HINTERNET hFile, LPINTERNET_BUFFERSA lpBuffer,
1091 DWORD dwFlags, DWORD dwContext)
1097 /***********************************************************************
1098 * InternetReadFileExW (WININET.@)
1100 * Read data from an open internet file
1107 BOOL WINAPI InternetReadFileExW(HINTERNET hFile, LPINTERNET_BUFFERSW lpBuffer,
1108 DWORD dwFlags, DWORD dwContext)
1112 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1116 /***********************************************************************
1117 * INET_QueryOptionHelper (internal)
1119 static BOOL INET_QueryOptionHelper(BOOL bIsUnicode, HINTERNET hInternet, DWORD dwOption,
1120 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
1122 LPWININETHANDLEHEADER lpwhh;
1123 BOOL bSuccess = FALSE;
1125 TRACE("0x%08lx\n", dwOption);
1127 if (NULL == hInternet)
1129 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
1133 lpwhh = (LPWININETHANDLEHEADER) hInternet;
1137 case INTERNET_OPTION_HANDLE_TYPE:
1139 ULONG type = lpwhh->htype;
1140 TRACE("INTERNET_OPTION_HANDLE_TYPE: %ld\n", type);
1142 if (*lpdwBufferLength < sizeof(ULONG))
1143 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1146 memcpy(lpBuffer, &type, sizeof(ULONG));
1147 *lpdwBufferLength = sizeof(ULONG);
1153 case INTERNET_OPTION_REQUEST_FLAGS:
1156 TRACE("INTERNET_OPTION_REQUEST_FLAGS: %ld\n", flags);
1157 if (*lpdwBufferLength < sizeof(ULONG))
1158 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1161 memcpy(lpBuffer, &flags, sizeof(ULONG));
1162 *lpdwBufferLength = sizeof(ULONG);
1168 case INTERNET_OPTION_URL:
1169 case INTERNET_OPTION_DATAFILE_NAME:
1171 ULONG type = lpwhh->htype;
1172 if (type == WH_HHTTPREQ)
1174 LPWININETHTTPREQA lpreq = hInternet;
1177 sprintf(url,"http://%s%s",lpreq->lpszHostName,lpreq->lpszPath);
1178 TRACE("INTERNET_OPTION_URL: %s\n",url);
1179 if (*lpdwBufferLength < strlen(url)+1)
1180 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1185 *lpdwBufferLength=MultiByteToWideChar(CP_ACP,0,url,-1,lpBuffer,*lpdwBufferLength);
1189 memcpy(lpBuffer, url, strlen(url)+1);
1190 *lpdwBufferLength = strlen(url)+1;
1197 case INTERNET_OPTION_HTTP_VERSION:
1200 * Presently hardcoded to 1.1
1202 ((HTTP_VERSION_INFO*)lpBuffer)->dwMajorVersion = 1;
1203 ((HTTP_VERSION_INFO*)lpBuffer)->dwMinorVersion = 1;
1209 FIXME("Stub! %ld \n",dwOption);
1216 /***********************************************************************
1217 * InternetQueryOptionW (WININET.@)
1219 * Queries an options on the specified handle
1226 BOOL WINAPI InternetQueryOptionW(HINTERNET hInternet, DWORD dwOption,
1227 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
1229 return INET_QueryOptionHelper(TRUE, hInternet, dwOption, lpBuffer, lpdwBufferLength);
1232 /***********************************************************************
1233 * InternetQueryOptionA (WININET.@)
1235 * Queries an options on the specified handle
1242 BOOL WINAPI InternetQueryOptionA(HINTERNET hInternet, DWORD dwOption,
1243 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
1245 return INET_QueryOptionHelper(FALSE, hInternet, dwOption, lpBuffer, lpdwBufferLength);
1249 /***********************************************************************
1250 * InternetSetOptionW (WININET.@)
1252 * Sets an options on the specified handle
1259 BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption,
1260 LPVOID lpBuffer, DWORD dwBufferLength)
1262 LPWININETHANDLEHEADER lpwhh;
1264 TRACE("0x%08lx\n", dwOption);
1266 if (NULL == hInternet)
1268 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
1272 lpwhh = (LPWININETHANDLEHEADER) hInternet;
1276 case INTERNET_OPTION_HTTP_VERSION:
1278 HTTP_VERSION_INFO* pVersion=(HTTP_VERSION_INFO*)lpBuffer;
1279 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%ld,%ld): STUB\n",pVersion->dwMajorVersion,pVersion->dwMinorVersion);
1282 case INTERNET_OPTION_ERROR_MASK:
1284 unsigned long flags=*(unsigned long*)lpBuffer;
1285 FIXME("Option INTERNET_OPTION_ERROR_MASK(%ld): STUB\n",flags);
1288 case INTERNET_OPTION_CODEPAGE:
1290 unsigned long codepage=*(unsigned long*)lpBuffer;
1291 FIXME("Option INTERNET_OPTION_CODEPAGE (%ld): STUB\n",codepage);
1294 case INTERNET_OPTION_REQUEST_PRIORITY:
1296 unsigned long priority=*(unsigned long*)lpBuffer;
1297 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%ld): STUB\n",priority);
1301 FIXME("Option %ld STUB\n",dwOption);
1302 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1310 /***********************************************************************
1311 * InternetSetOptionA (WININET.@)
1313 * Sets an options on the specified handle.
1320 BOOL WINAPI InternetSetOptionA(HINTERNET hInternet, DWORD dwOption,
1321 LPVOID lpBuffer, DWORD dwBufferLength)
1323 /* FIXME!!! implement if lpBuffer is a string, dwBufferLength is
1325 return InternetSetOptionW(hInternet,dwOption, lpBuffer,
1330 /***********************************************************************
1331 * InternetGetCookieA (WININET.@)
1333 * Retrieve cookie from the specified url
1340 BOOL WINAPI InternetGetCookieA(LPCSTR lpszUrl, LPCSTR lpszCookieName,
1341 LPSTR lpCookieData, LPDWORD lpdwSize)
1344 TRACE("(%s,%s,%p)\n", debugstr_a(lpszUrl),debugstr_a(lpszCookieName),
1350 /***********************************************************************
1351 * InternetGetCookieW (WININET.@)
1353 * Retrieve cookie from the specified url
1360 BOOL WINAPI InternetGetCookieW(LPCSTR lpszUrl, LPCWSTR lpszCookieName,
1361 LPWSTR lpCookieData, LPDWORD lpdwSize)
1364 TRACE("(%s,%s,%p)\n", debugstr_a(lpszUrl), debugstr_w(lpszCookieName),
1370 /***********************************************************************
1371 * InternetSetCookieA (WININET.@)
1373 * Sets cookie for the specified url
1380 BOOL WINAPI InternetSetCookieA(LPCSTR lpszUrl, LPCSTR lpszCookieName,
1381 LPCSTR lpCookieData)
1384 TRACE("(%s,%s,%s)\n", debugstr_a(lpszUrl),
1385 debugstr_a(lpszCookieName), debugstr_a(lpCookieData));
1390 /***********************************************************************
1391 * InternetSetCookieW (WININET.@)
1393 * Sets cookie for the specified url
1400 BOOL WINAPI InternetSetCookieW(LPCSTR lpszUrl, LPCWSTR lpszCookieName,
1401 LPCWSTR lpCookieData)
1404 TRACE("(%s,%s,%s)\n", debugstr_a(lpszUrl),
1405 debugstr_w(lpszCookieName), debugstr_w(lpCookieData));
1410 /***********************************************************************
1411 * GetInternetScheme (internal)
1417 * INTERNET_SCHEME_UNKNOWN on failure
1420 INTERNET_SCHEME GetInternetScheme(LPCSTR lpszScheme, INT nMaxCmp)
1423 if(lpszScheme==NULL)
1424 return INTERNET_SCHEME_UNKNOWN;
1426 if (!strncasecmp("ftp", lpszScheme, nMaxCmp))
1427 return INTERNET_SCHEME_FTP;
1428 else if (!strncasecmp("gopher", lpszScheme, nMaxCmp))
1429 return INTERNET_SCHEME_GOPHER;
1430 else if (!strncasecmp("http", lpszScheme, nMaxCmp))
1431 return INTERNET_SCHEME_HTTP;
1432 else if (!strncasecmp("https", lpszScheme, nMaxCmp))
1433 return INTERNET_SCHEME_HTTPS;
1434 else if (!strncasecmp("file", lpszScheme, nMaxCmp))
1435 return INTERNET_SCHEME_FILE;
1436 else if (!strncasecmp("news", lpszScheme, nMaxCmp))
1437 return INTERNET_SCHEME_NEWS;
1438 else if (!strncasecmp("mailto", lpszScheme, nMaxCmp))
1439 return INTERNET_SCHEME_MAILTO;
1441 return INTERNET_SCHEME_UNKNOWN;
1444 /***********************************************************************
1445 * InternetCheckConnectionA (WININET.@)
1447 * Pings a requested host to check internet connection
1450 * TRUE on success and FALSE on failure. If a failure then
1451 * ERROR_NOT_CONNECTED is placesd into GetLastError
1454 BOOL WINAPI InternetCheckConnectionA( LPCSTR lpszUrl, DWORD dwFlags, DWORD dwReserved )
1457 * this is a kludge which runs the resident ping program and reads the output.
1459 * Anyone have a better idea?
1470 * Crack or set the Address
1472 if (lpszUrl == NULL)
1475 * According to the doc we are supost to use the ip for the next
1476 * server in the WnInet internal server database. I have
1477 * no idea what that is or how to get it.
1479 * So someone needs to implement this.
1481 FIXME("Unimplemented with URL of NULL\n");
1486 URL_COMPONENTSA componets;
1488 ZeroMemory(&componets,sizeof(URL_COMPONENTSA));
1489 componets.lpszHostName = (LPSTR)&host;
1490 componets.dwHostNameLength = 1024;
1492 if (!InternetCrackUrlA(lpszUrl,0,0,&componets))
1495 TRACE("host name : %s\n",componets.lpszHostName);
1499 * Build our ping command
1501 strcpy(command,"ping -w 1 ");
1502 strcat(command,host);
1503 strcat(command," >/dev/null 2>/dev/null");
1505 TRACE("Ping command is : %s\n",command);
1507 status = system(command);
1509 TRACE("Ping returned a code of %i \n",status);
1511 /* Ping return code of 0 indicates success */
1518 SetLastError(ERROR_NOT_CONNECTED);
1524 /***********************************************************************
1525 * InternetCheckConnectionW (WININET.@)
1527 * Pings a requested host to check internet connection
1530 * TRUE on success and FALSE on failure. If a failure then
1531 * ERROR_NOT_CONNECTED is placed into GetLastError
1534 BOOL WINAPI InternetCheckConnectionW(LPCWSTR lpszUrl, DWORD dwFlags, DWORD dwReserved)
1540 len = lstrlenW(lpszUrl)+1;
1541 if (!(szUrl = (CHAR *)malloc(len*sizeof(CHAR))))
1543 WideCharToMultiByte(CP_ACP, -1, lpszUrl, -1, szUrl, len, NULL, NULL);
1544 rc = InternetCheckConnectionA((LPCSTR)szUrl, dwFlags, dwReserved);
1551 /**********************************************************
1552 * InternetOpenUrlA (WININET.@)
1557 * handle of connection or NULL on failure
1559 HINTERNET WINAPI InternetOpenUrlA(HINTERNET hInternet, LPCSTR lpszUrl,
1560 LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)
1562 URL_COMPONENTSA urlComponents;
1563 char protocol[32], hostName[MAXHOSTNAME], userName[1024];
1564 char password[1024], path[2048], extra[1024];
1565 HINTERNET client = NULL, client1 = NULL;
1566 urlComponents.dwStructSize = sizeof(URL_COMPONENTSA);
1567 urlComponents.lpszScheme = protocol;
1568 urlComponents.dwSchemeLength = 32;
1569 urlComponents.lpszHostName = hostName;
1570 urlComponents.dwHostNameLength = MAXHOSTNAME;
1571 urlComponents.lpszUserName = userName;
1572 urlComponents.dwUserNameLength = 1024;
1573 urlComponents.lpszPassword = password;
1574 urlComponents.dwPasswordLength = 1024;
1575 urlComponents.lpszUrlPath = path;
1576 urlComponents.dwUrlPathLength = 2048;
1577 urlComponents.lpszExtraInfo = extra;
1578 urlComponents.dwExtraInfoLength = 1024;
1579 if(!InternetCrackUrlA(lpszUrl, strlen(lpszUrl), 0, &urlComponents))
1581 switch(urlComponents.nScheme) {
1582 case INTERNET_SCHEME_FTP:
1583 if(urlComponents.nPort == 0)
1584 urlComponents.nPort = INTERNET_DEFAULT_FTP_PORT;
1585 client = InternetConnectA(hInternet, hostName, urlComponents.nPort,
1586 userName, password, INTERNET_SERVICE_FTP, dwFlags, dwContext);
1587 return FtpOpenFileA(client, path, GENERIC_READ, dwFlags, dwContext);
1589 case INTERNET_SCHEME_HTTP:
1590 case INTERNET_SCHEME_HTTPS:
1592 LPCSTR accept[2] = { "*/*", NULL };
1593 char *hostreq=(char*)malloc(strlen(hostName)+9);
1594 sprintf(hostreq, "Host: %s\r\n", hostName);
1595 if(urlComponents.nPort == 0) {
1596 if(urlComponents.nScheme == INTERNET_SCHEME_HTTP)
1597 urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
1599 urlComponents.nPort = INTERNET_DEFAULT_HTTPS_PORT;
1601 client = InternetConnectA(hInternet, hostName, urlComponents.nPort, userName,
1602 password, INTERNET_SERVICE_HTTP, dwFlags, dwContext);
1605 client1 = HttpOpenRequestA(hInternet, NULL, path, NULL, NULL, accept, dwFlags, dwContext);
1606 if(client1 == NULL) {
1607 InternetCloseHandle(client);
1610 HttpAddRequestHeadersA(client1, lpszHeaders, dwHeadersLength, HTTP_ADDREQ_FLAG_ADD);
1611 HttpAddRequestHeadersA(client1, hostreq, -1L, HTTP_ADDREQ_FLAG_ADD_IF_NEW);
1612 if(!HttpSendRequestA(client1, NULL, 0, NULL, 0)) {
1613 InternetCloseHandle(client1);
1614 InternetCloseHandle(client);
1620 case INTERNET_SCHEME_GOPHER:
1621 /* gopher doesn't seem to be implemented in wine, but it's supposed
1622 * to be supported by InternetOpenUrlA. */
1627 InternetCloseHandle(client);
1631 /**********************************************************
1632 * InternetOpenUrlW (WININET.@)
1637 * handle of connection or NULL on failure
1639 HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
1640 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)
1642 HINTERNET rc = (HINTERNET)NULL;
1644 INT lenUrl = lstrlenW(lpszUrl)+1;
1645 INT lenHeaders = lstrlenW(lpszHeaders)+1;
1646 CHAR *szUrl = (CHAR *)malloc(lenUrl*sizeof(CHAR));
1647 CHAR *szHeaders = (CHAR *)malloc(lenHeaders*sizeof(CHAR));
1649 if (!szUrl || !szHeaders)
1655 return (HINTERNET)NULL;
1658 WideCharToMultiByte(CP_ACP, -1, lpszUrl, -1, szUrl, lenUrl,
1660 WideCharToMultiByte(CP_ACP, -1, lpszHeaders, -1, szHeaders, lenHeaders,
1663 rc = InternetOpenUrlA(hInternet, szUrl, szHeaders,
1664 dwHeadersLength, dwFlags, dwContext);
1673 /***********************************************************************
1674 * INTERNET_SetLastError (internal)
1676 * Set last thread specific error
1681 void INTERNET_SetLastError(DWORD dwError)
1683 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
1685 SetLastError(dwError);
1687 lpwite->dwError = dwError;
1691 /***********************************************************************
1692 * INTERNET_GetLastError (internal)
1694 * Get last thread specific error
1699 DWORD INTERNET_GetLastError()
1701 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
1702 return lpwite->dwError;
1706 /***********************************************************************
1707 * INTERNET_WorkerThreadFunc (internal)
1709 * Worker thread execution function
1714 DWORD INTERNET_WorkerThreadFunc(LPVOID *lpvParam)
1721 INTERNET_ExecuteWork();
1724 dwWaitRes = WaitForMultipleObjects(2, hEventArray, FALSE, MAX_IDLE_WORKER);
1726 if (dwWaitRes == WAIT_OBJECT_0 + 1)
1727 INTERNET_ExecuteWork();
1731 InterlockedIncrement(&dwNumIdleThreads);
1734 InterlockedDecrement(&dwNumIdleThreads);
1735 InterlockedDecrement(&dwNumThreads);
1736 TRACE("Worker thread exiting\n");
1741 /***********************************************************************
1742 * INTERNET_InsertWorkRequest (internal)
1744 * Insert work request into queue
1749 BOOL INTERNET_InsertWorkRequest(LPWORKREQUEST lpWorkRequest)
1751 BOOL bSuccess = FALSE;
1752 LPWORKREQUEST lpNewRequest;
1756 lpNewRequest = HeapAlloc(GetProcessHeap(), 0, sizeof(WORKREQUEST));
1759 memcpy(lpNewRequest, lpWorkRequest, sizeof(WORKREQUEST));
1760 lpNewRequest->prev = NULL;
1762 EnterCriticalSection(&csQueue);
1764 lpNewRequest->next = lpWorkQueueTail;
1765 if (lpWorkQueueTail)
1766 lpWorkQueueTail->prev = lpNewRequest;
1767 lpWorkQueueTail = lpNewRequest;
1768 if (!lpHeadWorkQueue)
1769 lpHeadWorkQueue = lpWorkQueueTail;
1771 LeaveCriticalSection(&csQueue);
1774 InterlockedIncrement(&dwNumJobs);
1781 /***********************************************************************
1782 * INTERNET_GetWorkRequest (internal)
1784 * Retrieves work request from queue
1789 BOOL INTERNET_GetWorkRequest(LPWORKREQUEST lpWorkRequest)
1791 BOOL bSuccess = FALSE;
1792 LPWORKREQUEST lpRequest = NULL;
1796 EnterCriticalSection(&csQueue);
1798 if (lpHeadWorkQueue)
1800 lpRequest = lpHeadWorkQueue;
1801 lpHeadWorkQueue = lpHeadWorkQueue->prev;
1802 if (lpRequest == lpWorkQueueTail)
1803 lpWorkQueueTail = lpHeadWorkQueue;
1806 LeaveCriticalSection(&csQueue);
1810 memcpy(lpWorkRequest, lpRequest, sizeof(WORKREQUEST));
1811 HeapFree(GetProcessHeap(), 0, lpRequest);
1813 InterlockedDecrement(&dwNumJobs);
1820 /***********************************************************************
1821 * INTERNET_AsyncCall (internal)
1823 * Retrieves work request from queue
1828 BOOL INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest)
1832 BOOL bSuccess = FALSE;
1836 if (InterlockedDecrement(&dwNumIdleThreads) < 0)
1838 InterlockedIncrement(&dwNumIdleThreads);
1840 if (InterlockedIncrement(&dwNumThreads) > MAX_WORKER_THREADS ||
1841 !(hThread = CreateThread(NULL, 0,
1842 (LPTHREAD_START_ROUTINE)INTERNET_WorkerThreadFunc, NULL, 0, &dwTID)))
1844 InterlockedDecrement(&dwNumThreads);
1845 INTERNET_SetLastError(ERROR_INTERNET_ASYNC_THREAD_FAILED);
1849 TRACE("Created new thread\n");
1853 INTERNET_InsertWorkRequest(lpWorkRequest);
1854 SetEvent(hWorkEvent);
1862 /***********************************************************************
1863 * INTERNET_ExecuteWork (internal)
1868 VOID INTERNET_ExecuteWork()
1870 WORKREQUEST workRequest;
1874 if (INTERNET_GetWorkRequest(&workRequest))
1876 TRACE("Got work %d\n", workRequest.asyncall);
1877 switch (workRequest.asyncall)
1880 FTP_FtpPutFileA((HINTERNET)workRequest.HFTPSESSION, (LPCSTR)workRequest.LPSZLOCALFILE,
1881 (LPCSTR)workRequest.LPSZNEWREMOTEFILE, workRequest.DWFLAGS, workRequest.DWCONTEXT);
1882 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZLOCALFILE);
1883 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZNEWREMOTEFILE);
1886 case FTPSETCURRENTDIRECTORYA:
1887 FTP_FtpSetCurrentDirectoryA((HINTERNET)workRequest.HFTPSESSION,
1888 (LPCSTR)workRequest.LPSZDIRECTORY);
1889 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZDIRECTORY);
1892 case FTPCREATEDIRECTORYA:
1893 FTP_FtpCreateDirectoryA((HINTERNET)workRequest.HFTPSESSION,
1894 (LPCSTR)workRequest.LPSZDIRECTORY);
1895 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZDIRECTORY);
1898 case FTPFINDFIRSTFILEA:
1899 FTP_FtpFindFirstFileA((HINTERNET)workRequest.HFTPSESSION,
1900 (LPCSTR)workRequest.LPSZSEARCHFILE,
1901 (LPWIN32_FIND_DATAA)workRequest.LPFINDFILEDATA, workRequest.DWFLAGS,
1902 workRequest.DWCONTEXT);
1903 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZSEARCHFILE);
1906 case FTPGETCURRENTDIRECTORYA:
1907 FTP_FtpGetCurrentDirectoryA((HINTERNET)workRequest.HFTPSESSION,
1908 (LPSTR)workRequest.LPSZDIRECTORY, (LPDWORD)workRequest.LPDWDIRECTORY);
1912 FTP_FtpOpenFileA((HINTERNET)workRequest.HFTPSESSION,
1913 (LPCSTR)workRequest.LPSZFILENAME,
1914 workRequest.FDWACCESS,
1915 workRequest.DWFLAGS,
1916 workRequest.DWCONTEXT);
1917 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZFILENAME);
1921 FTP_FtpGetFileA((HINTERNET)workRequest.HFTPSESSION,
1922 (LPCSTR)workRequest.LPSZREMOTEFILE,
1923 (LPCSTR)workRequest.LPSZNEWFILE,
1924 (BOOL)workRequest.FFAILIFEXISTS,
1925 workRequest.DWLOCALFLAGSATTRIBUTE,
1926 workRequest.DWFLAGS,
1927 workRequest.DWCONTEXT);
1928 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZREMOTEFILE);
1929 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZNEWFILE);
1932 case FTPDELETEFILEA:
1933 FTP_FtpDeleteFileA((HINTERNET)workRequest.HFTPSESSION,
1934 (LPCSTR)workRequest.LPSZFILENAME);
1935 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZFILENAME);
1938 case FTPREMOVEDIRECTORYA:
1939 FTP_FtpRemoveDirectoryA((HINTERNET)workRequest.HFTPSESSION,
1940 (LPCSTR)workRequest.LPSZDIRECTORY);
1941 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZDIRECTORY);
1944 case FTPRENAMEFILEA:
1945 FTP_FtpRenameFileA((HINTERNET)workRequest.HFTPSESSION,
1946 (LPCSTR)workRequest.LPSZSRCFILE,
1947 (LPCSTR)workRequest.LPSZDESTFILE);
1948 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZSRCFILE);
1949 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZDESTFILE);
1952 case INTERNETFINDNEXTA:
1953 INTERNET_FindNextFileA((HINTERNET)workRequest.HFTPSESSION,
1954 (LPWIN32_FIND_DATAA)workRequest.LPFINDFILEDATA);
1957 case HTTPSENDREQUESTA:
1958 HTTP_HttpSendRequestA((HINTERNET)workRequest.HFTPSESSION,
1959 (LPCSTR)workRequest.LPSZHEADER,
1960 workRequest.DWHEADERLENGTH,
1961 (LPVOID)workRequest.LPOPTIONAL,
1962 workRequest.DWOPTIONALLENGTH);
1963 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZHEADER);
1966 case HTTPOPENREQUESTA:
1967 HTTP_HttpOpenRequestA((HINTERNET)workRequest.HFTPSESSION,
1968 (LPCSTR)workRequest.LPSZVERB,
1969 (LPCSTR)workRequest.LPSZOBJECTNAME,
1970 (LPCSTR)workRequest.LPSZVERSION,
1971 (LPCSTR)workRequest.LPSZREFERRER,
1972 (LPCSTR*)workRequest.LPSZACCEPTTYPES,
1973 workRequest.DWFLAGS,
1974 workRequest.DWCONTEXT);
1975 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZVERB);
1976 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZOBJECTNAME);
1977 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZVERSION);
1978 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZREFERRER);
1982 SendAsyncCallbackInt((LPWININETAPPINFOA)workRequest.param1,
1983 (HINTERNET)workRequest.param2, workRequest.param3,
1984 workRequest.param4, (LPVOID)workRequest.param5,
1985 workRequest.param6);
1992 /***********************************************************************
1993 * INTERNET_GetResponseBuffer
1998 LPSTR INTERNET_GetResponseBuffer()
2000 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
2002 return lpwite->response;
2006 /***********************************************************************
2007 * INTERNET_GetNextLine (internal)
2009 * Parse next line in directory string listing
2012 * Pointer to beginning of next line
2017 LPSTR INTERNET_GetNextLine(INT nSocket, LPSTR lpszBuffer, LPDWORD dwBuffer)
2021 BOOL bSuccess = FALSE;
2027 FD_SET(nSocket, &infd);
2028 tv.tv_sec=RESPONSE_TIMEOUT;
2031 while (nRecv < *dwBuffer)
2033 if (select(nSocket+1,&infd,NULL,NULL,&tv) > 0)
2035 if (recv(nSocket, &lpszBuffer[nRecv], 1, 0) <= 0)
2037 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
2041 if (lpszBuffer[nRecv] == '\n')
2046 if (lpszBuffer[nRecv] != '\r')
2051 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT);
2059 lpszBuffer[nRecv] = '\0';
2060 *dwBuffer = nRecv - 1;
2061 TRACE(":%d %s\n", nRecv, lpszBuffer);
2070 /***********************************************************************
2073 BOOL WINAPI InternetQueryDataAvailable( HINTERNET hFile,
2074 LPDWORD lpdwNumberOfBytesAvailble,
2075 DWORD dwFlags, DWORD dwConext)
2077 LPWININETHTTPREQA lpwhr = (LPWININETHTTPREQA) hFile;
2084 SetLastError(ERROR_NO_MORE_FILES);
2088 TRACE("--> %p %i %i\n",lpwhr,lpwhr->hdr.htype,lpwhr->nSocketFD);
2090 switch (lpwhr->hdr.htype)
2093 nSocket = lpwhr->nSocketFD;
2104 retval = recv(nSocket,buffer,4048,MSG_PEEK);
2108 SetLastError(ERROR_NO_MORE_FILES);
2111 if (lpdwNumberOfBytesAvailble)
2113 (*lpdwNumberOfBytesAvailble) = retval;
2116 TRACE("<-- %i\n",retval);
2121 /***********************************************************************
2124 BOOL WINAPI InternetLockRequestFile( HINTERNET hInternet, HANDLE
2131 BOOL WINAPI InternetUnlockRequestFile( HANDLE hLockHandle)
2138 /***********************************************************************
2141 * On windows this function is supposed to dial the default internet
2142 * connection. We don't want to have Wine dial out to the internet so
2143 * we return TRUE by default. It might be nice to check if we are connected.
2150 BOOL WINAPI InternetAutoDial(DWORD dwFlags, HWND hwndParent)
2154 /* Tell that we are connected to the internet. */
2158 /***********************************************************************
2159 * InternetAutoDialHangup
2161 * Hangs up an connection made with InternetAutoDial
2170 BOOL WINAPI InternetAutodialHangup(DWORD dwReserved)
2174 /* we didn't dial, we don't disconnect */
2178 /***********************************************************************
2180 * InternetCombineUrlA
2182 * Combine a base URL with a relative URL
2190 BOOL WINAPI InternetCombineUrlA(LPCSTR lpszBaseUrl, LPCSTR lpszRelativeUrl,
2191 LPSTR lpszBuffer, LPDWORD lpdwBufferLength,
2195 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
2196 dwFlags ^= ICU_NO_ENCODE;
2197 hr=UrlCombineA(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
2202 /***********************************************************************
2204 * InternetCombineUrlW
2206 * Combine a base URL with a relative URL
2214 BOOL WINAPI InternetCombineUrlW(LPCWSTR lpszBaseUrl, LPCWSTR lpszRelativeUrl,
2215 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength,
2219 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
2220 dwFlags ^= ICU_NO_ENCODE;
2221 hr=UrlCombineW(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);