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"
61 #include "wine/unicode.h"
63 WINE_DEFAULT_DEBUG_CHANNEL(wininet);
65 #define MAX_IDLE_WORKER 1000*60*1
66 #define MAX_WORKER_THREADS 10
67 #define RESPONSE_TIMEOUT 30
69 #define GET_HWININET_FROM_LPWININETFINDNEXT(lpwh) \
70 (LPWININETAPPINFOA)(((LPWININETFTPSESSIONA)(lpwh->hdr.lpwhparent))->hdr.lpwhparent)
72 /* filter for page-fault exceptions */
73 static WINE_EXCEPTION_FILTER(page_fault)
75 if (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION ||
76 GetExceptionCode() == EXCEPTION_PRIV_INSTRUCTION)
77 return EXCEPTION_EXECUTE_HANDLER;
78 return EXCEPTION_CONTINUE_SEARCH;
84 CHAR response[MAX_REPLY_LEN];
85 } WITHREADERROR, *LPWITHREADERROR;
87 BOOL WINAPI INTERNET_FindNextFileA(HINTERNET hFind, LPVOID lpvFindData);
88 VOID INTERNET_ExecuteWork();
90 DWORD g_dwTlsErrIndex = TLS_OUT_OF_INDEXES;
92 DWORD dwNumIdleThreads;
94 HANDLE hEventArray[2];
95 #define hQuitEvent hEventArray[0]
96 #define hWorkEvent hEventArray[1]
97 CRITICAL_SECTION csQueue;
98 LPWORKREQUEST lpHeadWorkQueue;
99 LPWORKREQUEST lpWorkQueueTail;
101 /***********************************************************************
102 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
105 * hinstDLL [I] handle to the DLL's instance
107 * lpvReserved [I] reserved, must be NULL
114 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
116 TRACE("%p,%lx,%p\n", hinstDLL, fdwReason, lpvReserved);
119 case DLL_PROCESS_ATTACH:
121 g_dwTlsErrIndex = TlsAlloc();
123 if (g_dwTlsErrIndex == TLS_OUT_OF_INDEXES)
126 hQuitEvent = CreateEventA(0, TRUE, FALSE, NULL);
127 hWorkEvent = CreateEventA(0, FALSE, FALSE, NULL);
128 InitializeCriticalSection(&csQueue);
131 dwNumIdleThreads = 0;
134 case DLL_THREAD_ATTACH:
136 LPWITHREADERROR lpwite = HeapAlloc(GetProcessHeap(), 0, sizeof(WITHREADERROR));
140 TlsSetValue(g_dwTlsErrIndex, (LPVOID)lpwite);
144 case DLL_THREAD_DETACH:
145 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
147 LPVOID lpwite = TlsGetValue(g_dwTlsErrIndex);
149 HeapFree(GetProcessHeap(), 0, lpwite);
153 case DLL_PROCESS_DETACH:
155 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
157 HeapFree(GetProcessHeap(), 0, TlsGetValue(g_dwTlsErrIndex));
158 TlsFree(g_dwTlsErrIndex);
161 SetEvent(hQuitEvent);
163 CloseHandle(hQuitEvent);
164 CloseHandle(hWorkEvent);
165 DeleteCriticalSection(&csQueue);
173 /***********************************************************************
174 * InternetInitializeAutoProxyDll (WININET.@)
176 * Setup the internal proxy
185 BOOL WINAPI InternetInitializeAutoProxyDll(DWORD dwReserved)
188 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
192 /***********************************************************************
193 * DetectAutoProxyUrl (WININET.@)
195 * Auto detect the proxy url
201 BOOL WINAPI DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl,
202 DWORD dwAutoProxyUrlLength, DWORD dwDetectFlags)
205 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
210 /***********************************************************************
211 * InternetOpenA (WININET.@)
213 * Per-application initialization of wininet
216 * HINTERNET on success
220 HINTERNET WINAPI InternetOpenA(LPCSTR lpszAgent, DWORD dwAccessType,
221 LPCSTR lpszProxy, LPCSTR lpszProxyBypass, DWORD dwFlags)
223 LPWININETAPPINFOA lpwai = NULL;
227 /* Clear any error information */
228 INTERNET_SetLastError(0);
230 lpwai = HeapAlloc(GetProcessHeap(), 0, sizeof(WININETAPPINFOA));
232 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
235 memset(lpwai, 0, sizeof(WININETAPPINFOA));
236 lpwai->hdr.htype = WH_HINIT;
237 lpwai->hdr.lpwhparent = NULL;
238 lpwai->hdr.dwFlags = dwFlags;
239 if (NULL != lpszAgent)
241 if ((lpwai->lpszAgent = HeapAlloc( GetProcessHeap(),0,strlen(lpszAgent)+1)))
242 strcpy( lpwai->lpszAgent, lpszAgent );
244 if(dwAccessType == INTERNET_OPEN_TYPE_PRECONFIG)
247 if (!RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", &key))
249 DWORD keytype, len, enabled;
250 RegQueryValueExA(key, "ProxyEnable", NULL, NULL, (BYTE*)&enabled, NULL);
253 if(!RegQueryValueExA(key, "ProxyServer", NULL, &keytype, NULL, &len) && len && keytype == REG_SZ)
255 lpwai->lpszProxy=HeapAlloc( GetProcessHeap(), 0, len+1 );
256 RegQueryValueExA(key, "ProxyServer", NULL, &keytype, (BYTE*)lpwai->lpszProxy, &len);
257 TRACE("Proxy = %s\n", lpwai->lpszProxy);
258 dwAccessType = INTERNET_OPEN_TYPE_PROXY;
263 TRACE("Proxy is not enabled.\n");
268 else if (NULL != lpszProxy)
270 if ((lpwai->lpszProxy = HeapAlloc( GetProcessHeap(), 0, strlen(lpszProxy)+1 )))
271 strcpy( lpwai->lpszProxy, lpszProxy );
273 if (NULL != lpszProxyBypass)
275 if ((lpwai->lpszProxyBypass = HeapAlloc( GetProcessHeap(), 0, strlen(lpszProxyBypass)+1)))
276 strcpy( lpwai->lpszProxyBypass, lpszProxyBypass );
278 lpwai->dwAccessType = dwAccessType;
281 return (HINTERNET)lpwai;
285 /***********************************************************************
286 * InternetOpenW (WININET.@)
288 * Per-application initialization of wininet
291 * HINTERNET on success
295 HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType,
296 LPCWSTR lpszProxy, LPCWSTR lpszProxyBypass, DWORD dwFlags)
298 HINTERNET rc = (HINTERNET)NULL;
299 INT lenAgent = lstrlenW(lpszAgent)+1;
300 INT lenProxy = lstrlenW(lpszProxy)+1;
301 INT lenBypass = lstrlenW(lpszProxyBypass)+1;
302 CHAR *szAgent = (CHAR *)malloc(lenAgent*sizeof(CHAR));
303 CHAR *szProxy = (CHAR *)malloc(lenProxy*sizeof(CHAR));
304 CHAR *szBypass = (CHAR *)malloc(lenBypass*sizeof(CHAR));
306 if (!szAgent || !szProxy || !szBypass)
314 return (HINTERNET)NULL;
317 WideCharToMultiByte(CP_ACP, -1, lpszAgent, -1, szAgent, lenAgent,
319 WideCharToMultiByte(CP_ACP, -1, lpszProxy, -1, szProxy, lenProxy,
321 WideCharToMultiByte(CP_ACP, -1, lpszProxyBypass, -1, szBypass, lenBypass,
324 rc = InternetOpenA(szAgent, dwAccessType, szProxy, szBypass, dwFlags);
333 /***********************************************************************
334 * InternetGetLastResponseInfoA (WININET.@)
336 * Return last wininet error description on the calling thread
339 * TRUE on success of writting to buffer
343 BOOL WINAPI InternetGetLastResponseInfoA(LPDWORD lpdwError,
344 LPSTR lpszBuffer, LPDWORD lpdwBufferLength)
346 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
350 *lpdwError = lpwite->dwError;
353 strncpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
354 *lpdwBufferLength = strlen(lpszBuffer);
357 *lpdwBufferLength = 0;
363 /***********************************************************************
364 * InternetGetConnectedState (WININET.@)
366 * Return connected state
370 * if lpdwStatus is not null, return the status (off line,
371 * modem, lan...) in it.
372 * FALSE if not connected
374 BOOL WINAPI InternetGetConnectedState(LPDWORD lpdwStatus, DWORD dwReserved)
377 FIXME("always returning LAN connection.\n");
378 *lpdwStatus = INTERNET_CONNECTION_LAN;
383 /***********************************************************************
384 * InternetGetConnectedStateEx (WININET.@)
386 * Return connected state
390 * if lpdwStatus is not null, return the status (off line,
391 * modem, lan...) in it.
392 * FALSE if not connected
394 BOOL WINAPI InternetGetConnectedStateExW(LPDWORD lpdwStatus, LPWSTR lpszConnectionName,
395 DWORD dwNameLen, DWORD dwReserved)
402 FIXME("always returning LAN connection.\n");
403 *lpdwStatus = INTERNET_CONNECTION_LAN;
408 /***********************************************************************
409 * InternetConnectA (WININET.@)
411 * Open a ftp, gopher or http session
414 * HINTERNET a session handle on success
418 HINTERNET WINAPI InternetConnectA(HINTERNET hInternet,
419 LPCSTR lpszServerName, INTERNET_PORT nServerPort,
420 LPCSTR lpszUserName, LPCSTR lpszPassword,
421 DWORD dwService, DWORD dwFlags, DWORD dwContext)
423 HINTERNET rc = (HINTERNET) NULL;
425 TRACE("ServerPort %i\n",nServerPort);
427 /* Clear any error information */
428 INTERNET_SetLastError(0);
432 case INTERNET_SERVICE_FTP:
433 rc = FTP_Connect(hInternet, lpszServerName, nServerPort,
434 lpszUserName, lpszPassword, dwFlags, dwContext);
437 case INTERNET_SERVICE_HTTP:
438 rc = HTTP_Connect(hInternet, lpszServerName, nServerPort,
439 lpszUserName, lpszPassword, dwFlags, dwContext);
442 case INTERNET_SERVICE_GOPHER:
451 /***********************************************************************
452 * InternetConnectW (WININET.@)
454 * Open a ftp, gopher or http session
457 * HINTERNET a session handle on success
461 HINTERNET WINAPI InternetConnectW(HINTERNET hInternet,
462 LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
463 LPCWSTR lpszUserName, LPCWSTR lpszPassword,
464 DWORD dwService, DWORD dwFlags, DWORD dwContext)
466 HINTERNET rc = (HINTERNET)NULL;
467 INT lenServer = lstrlenW(lpszServerName)+1;
468 INT lenUser = lstrlenW(lpszUserName)+1;
469 INT lenPass = lstrlenW(lpszPassword)+1;
470 CHAR *szServerName = (CHAR *)malloc(lenServer*sizeof(CHAR));
471 CHAR *szUserName = (CHAR *)malloc(lenUser*sizeof(CHAR));
472 CHAR *szPassword = (CHAR *)malloc(lenPass*sizeof(CHAR));
474 if (!szServerName || !szUserName || !szPassword)
482 return (HINTERNET)NULL;
485 WideCharToMultiByte(CP_ACP, -1, lpszServerName, -1, szServerName, lenServer,
487 WideCharToMultiByte(CP_ACP, -1, lpszUserName, -1, szUserName, lenUser,
489 WideCharToMultiByte(CP_ACP, -1, lpszPassword, -1, szPassword, lenPass,
492 rc = InternetConnectA(hInternet, szServerName, nServerPort,
493 szUserName, szPassword, dwService, dwFlags, dwContext);
502 /***********************************************************************
503 * InternetFindNextFileA (WININET.@)
505 * Continues a file search from a previous call to FindFirstFile
512 BOOL WINAPI InternetFindNextFileA(HINTERNET hFind, LPVOID lpvFindData)
514 LPWININETAPPINFOA hIC = NULL;
515 LPWININETFINDNEXTA lpwh = (LPWININETFINDNEXTA) hFind;
519 if (NULL == lpwh || lpwh->hdr.htype != WH_HFINDNEXT)
521 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
525 hIC = GET_HWININET_FROM_LPWININETFINDNEXT(lpwh);
526 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
528 WORKREQUEST workRequest;
530 workRequest.asyncall = INTERNETFINDNEXTA;
531 workRequest.HFTPSESSION = (DWORD)hFind;
532 workRequest.LPFINDFILEDATA = (DWORD)lpvFindData;
534 return INTERNET_AsyncCall(&workRequest);
538 return INTERNET_FindNextFileA(hFind, lpvFindData);
542 /***********************************************************************
543 * INTERNET_FindNextFileA (Internal)
545 * Continues a file search from a previous call to FindFirstFile
552 BOOL WINAPI INTERNET_FindNextFileA(HINTERNET hFind, LPVOID lpvFindData)
554 BOOL bSuccess = TRUE;
555 LPWININETAPPINFOA hIC = NULL;
556 LPWIN32_FIND_DATAA lpFindFileData;
557 LPWININETFINDNEXTA lpwh = (LPWININETFINDNEXTA) hFind;
561 if (NULL == lpwh || lpwh->hdr.htype != WH_HFINDNEXT)
563 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
567 /* Clear any error information */
568 INTERNET_SetLastError(0);
570 if (lpwh->hdr.lpwhparent->htype != WH_HFTPSESSION)
572 FIXME("Only FTP find next supported\n");
573 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
577 TRACE("index(%d) size(%ld)\n", lpwh->index, lpwh->size);
579 lpFindFileData = (LPWIN32_FIND_DATAA) lpvFindData;
580 ZeroMemory(lpFindFileData, sizeof(WIN32_FIND_DATAA));
582 if (lpwh->index >= lpwh->size)
584 INTERNET_SetLastError(ERROR_NO_MORE_FILES);
589 FTP_ConvertFileProp(&lpwh->lpafp[lpwh->index], lpFindFileData);
592 TRACE("\nName: %s\nSize: %ld\n", lpFindFileData->cFileName, lpFindFileData->nFileSizeLow);
596 hIC = GET_HWININET_FROM_LPWININETFINDNEXT(lpwh);
597 if (hIC->lpfnStatusCB)
599 INTERNET_ASYNC_RESULT iar;
601 iar.dwResult = (DWORD)bSuccess;
602 iar.dwError = iar.dwError = bSuccess ? ERROR_SUCCESS :
603 INTERNET_GetLastError();
605 SendAsyncCallback(hIC, hFind, lpwh->hdr.dwContext,
606 INTERNET_STATUS_REQUEST_COMPLETE, &iar,
607 sizeof(INTERNET_ASYNC_RESULT));
614 /***********************************************************************
615 * INTERNET_CloseHandle (internal)
617 * Close internet handle
623 VOID INTERNET_CloseHandle(LPWININETAPPINFOA lpwai)
627 SendAsyncCallback(lpwai, lpwai, lpwai->hdr.dwContext,
628 INTERNET_STATUS_HANDLE_CLOSING, lpwai,
631 if (lpwai->lpszAgent)
632 HeapFree(GetProcessHeap(), 0, lpwai->lpszAgent);
634 if (lpwai->lpszProxy)
635 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxy);
637 if (lpwai->lpszProxyBypass)
638 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyBypass);
640 HeapFree(GetProcessHeap(), 0, lpwai);
644 /***********************************************************************
645 * InternetCloseHandle (WININET.@)
647 * Generic close handle function
654 BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
657 LPWININETHANDLEHEADER lpwh = (LPWININETHANDLEHEADER) hInternet;
659 TRACE("%p\n",hInternet);
664 /* Clear any error information */
665 INTERNET_SetLastError(0);
671 INTERNET_CloseHandle((LPWININETAPPINFOA) lpwh);
675 case WH_HHTTPSESSION:
676 HTTP_CloseHTTPSessionHandle((LPWININETHTTPSESSIONA) lpwh);
681 HTTP_CloseHTTPRequestHandle((LPWININETHTTPREQA) lpwh);
686 retval = FTP_CloseSessionHandle((LPWININETFTPSESSIONA) lpwh);
690 retval = FTP_CloseFindNextHandle((LPWININETFINDNEXTA) lpwh);
696 } __EXCEPT(page_fault) {
697 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
706 /***********************************************************************
707 * ConvertUrlComponentValue (Internal)
709 * Helper function for InternetCrackUrlW
712 void ConvertUrlComponentValue(LPSTR* lppszComponent, LPDWORD dwComponentLen,
713 LPWSTR lpwszComponent, DWORD dwwComponentLen,
717 if (*dwComponentLen != 0)
719 int nASCIILength=WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,NULL,0,NULL,NULL);
720 if (*lppszComponent == NULL)
722 int nASCIIOffset=WideCharToMultiByte(CP_ACP,0,lpwszStart,lpwszComponent-lpwszStart,NULL,0,NULL,NULL);
723 *lppszComponent = (LPSTR)lpszStart+nASCIIOffset;
724 *dwComponentLen = nASCIILength;
728 INT ncpylen = min((*dwComponentLen)-1, nASCIILength);
729 WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,*lppszComponent,ncpylen+1,NULL,NULL);
730 (*lppszComponent)[ncpylen]=0;
731 *dwComponentLen = ncpylen;
737 /***********************************************************************
738 * InternetCrackUrlA (WININET.@)
740 * Break up URL into its components
742 * TODO: Handle dwFlags
749 BOOL WINAPI InternetCrackUrlA(LPCSTR lpszUrl, DWORD dwUrlLength, DWORD dwFlags,
750 LPURL_COMPONENTSA lpUrlComponents)
756 dwUrlLength=strlen(lpszUrl);
757 lpwszUrl=HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*(dwUrlLength+1));
758 memset(lpwszUrl,0,sizeof(WCHAR)*(dwUrlLength+1));
759 nLength=MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,lpwszUrl,dwUrlLength+1);
760 memset(&UCW,0,sizeof(UCW));
761 if(lpUrlComponents->dwHostNameLength!=0)
762 UCW.dwHostNameLength=1;
763 if(lpUrlComponents->dwUserNameLength!=0)
764 UCW.dwUserNameLength=1;
765 if(lpUrlComponents->dwPasswordLength!=0)
766 UCW.dwPasswordLength=1;
767 if(lpUrlComponents->dwUrlPathLength!=0)
768 UCW.dwUrlPathLength=1;
769 if(lpUrlComponents->dwSchemeLength!=0)
770 UCW.dwSchemeLength=1;
771 if(lpUrlComponents->dwExtraInfoLength!=0)
772 UCW.dwExtraInfoLength=1;
773 if(!InternetCrackUrlW(lpwszUrl,nLength,dwFlags,&UCW))
775 HeapFree(GetProcessHeap(), 0, lpwszUrl);
778 ConvertUrlComponentValue(&lpUrlComponents->lpszHostName, &lpUrlComponents->dwHostNameLength,
779 UCW.lpszHostName, UCW.dwHostNameLength,
781 ConvertUrlComponentValue(&lpUrlComponents->lpszUserName, &lpUrlComponents->dwUserNameLength,
782 UCW.lpszUserName, UCW.dwUserNameLength,
784 ConvertUrlComponentValue(&lpUrlComponents->lpszPassword, &lpUrlComponents->dwPasswordLength,
785 UCW.lpszPassword, UCW.dwPasswordLength,
787 ConvertUrlComponentValue(&lpUrlComponents->lpszUrlPath, &lpUrlComponents->dwUrlPathLength,
788 UCW.lpszUrlPath, UCW.dwUrlPathLength,
790 ConvertUrlComponentValue(&lpUrlComponents->lpszScheme, &lpUrlComponents->dwSchemeLength,
791 UCW.lpszScheme, UCW.dwSchemeLength,
793 ConvertUrlComponentValue(&lpUrlComponents->lpszExtraInfo, &lpUrlComponents->dwExtraInfoLength,
794 UCW.lpszExtraInfo, UCW.dwExtraInfoLength,
796 lpUrlComponents->nScheme=UCW.nScheme;
797 lpUrlComponents->nPort=UCW.nPort;
798 HeapFree(GetProcessHeap(), 0, lpwszUrl);
800 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", lpszUrl,
801 debugstr_an(lpUrlComponents->lpszScheme,lpUrlComponents->dwSchemeLength),
802 debugstr_an(lpUrlComponents->lpszHostName,lpUrlComponents->dwHostNameLength),
803 debugstr_an(lpUrlComponents->lpszUrlPath,lpUrlComponents->dwUrlPathLength),
804 debugstr_an(lpUrlComponents->lpszExtraInfo,lpUrlComponents->dwExtraInfoLength));
809 /***********************************************************************
810 * GetInternetSchemeW (internal)
816 * INTERNET_SCHEME_UNKNOWN on failure
819 INTERNET_SCHEME GetInternetSchemeW(LPCWSTR lpszScheme, INT nMaxCmp)
821 INTERNET_SCHEME iScheme=INTERNET_SCHEME_UNKNOWN;
822 WCHAR lpszFtp[]={'f','t','p',0};
823 WCHAR lpszGopher[]={'g','o','p','h','e','r',0};
824 WCHAR lpszHttp[]={'h','t','t','p',0};
825 WCHAR lpszHttps[]={'h','t','t','p','s',0};
826 WCHAR lpszFile[]={'f','i','l','e',0};
827 WCHAR lpszNews[]={'n','e','w','s',0};
828 WCHAR lpszMailto[]={'m','a','i','l','t','o',0};
829 WCHAR lpszRes[]={'r','e','s',0};
830 WCHAR* tempBuffer=NULL;
833 return INTERNET_SCHEME_UNKNOWN;
835 tempBuffer=malloc(nMaxCmp+1);
836 strncpyW(tempBuffer,lpszScheme,nMaxCmp);
837 tempBuffer[nMaxCmp]=0;
839 if (nMaxCmp==strlenW(lpszFtp) && !strncmpW(lpszFtp, tempBuffer, nMaxCmp))
840 iScheme=INTERNET_SCHEME_FTP;
841 else if (nMaxCmp==strlenW(lpszGopher) && !strncmpW(lpszGopher, tempBuffer, nMaxCmp))
842 iScheme=INTERNET_SCHEME_GOPHER;
843 else if (nMaxCmp==strlenW(lpszHttp) && !strncmpW(lpszHttp, tempBuffer, nMaxCmp))
844 iScheme=INTERNET_SCHEME_HTTP;
845 else if (nMaxCmp==strlenW(lpszHttps) && !strncmpW(lpszHttps, tempBuffer, nMaxCmp))
846 iScheme=INTERNET_SCHEME_HTTPS;
847 else if (nMaxCmp==strlenW(lpszFile) && !strncmpW(lpszFile, tempBuffer, nMaxCmp))
848 iScheme=INTERNET_SCHEME_FILE;
849 else if (nMaxCmp==strlenW(lpszNews) && !strncmpW(lpszNews, tempBuffer, nMaxCmp))
850 iScheme=INTERNET_SCHEME_NEWS;
851 else if (nMaxCmp==strlenW(lpszMailto) && !strncmpW(lpszMailto, tempBuffer, nMaxCmp))
852 iScheme=INTERNET_SCHEME_MAILTO;
853 else if (nMaxCmp==strlenW(lpszRes) && !strncmpW(lpszRes, tempBuffer, nMaxCmp))
854 iScheme=INTERNET_SCHEME_RES;
859 /***********************************************************************
860 * SetUrlComponentValueW (Internal)
862 * Helper function for InternetCrackUrlW
869 BOOL SetUrlComponentValueW(LPWSTR* lppszComponent, LPDWORD dwComponentLen, LPCWSTR lpszStart, INT len)
871 TRACE("%s (%d)\n", debugstr_wn(lpszStart,len), len);
873 if (*dwComponentLen != 0)
875 if (*lppszComponent == NULL)
877 *lppszComponent = (LPWSTR)lpszStart;
878 *dwComponentLen = len;
882 INT ncpylen = min((*dwComponentLen)-1, len);
883 strncpyW(*lppszComponent, lpszStart, ncpylen);
884 (*lppszComponent)[ncpylen] = '\0';
885 *dwComponentLen = ncpylen;
892 /***********************************************************************
893 * InternetCrackUrlW (WININET.@)
895 BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl, DWORD dwUrlLength, DWORD dwFlags,
896 LPURL_COMPONENTSW lpUC)
900 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
903 LPWSTR lpszParam = NULL;
904 BOOL bIsAbsolute = FALSE;
905 LPWSTR lpszap = (WCHAR*)lpszUrl;
906 LPWSTR lpszcp = NULL;
907 WCHAR lpszSeparators[3]={';','?',0};
908 WCHAR lpszSlash[2]={'/',0};
910 dwUrlLength=strlenW(lpszUrl);
914 /* Determine if the URI is absolute. */
915 while (*lpszap != '\0')
917 if (isalnumW(*lpszap))
922 if ((*lpszap == ':') && (lpszap - lpszUrl >= 2))
929 lpszcp = (LPWSTR)lpszUrl; /* Relative url */
936 lpszParam = strpbrkW(lpszap, lpszSeparators);
937 if (lpszParam != NULL)
939 if (!SetUrlComponentValueW(&lpUC->lpszExtraInfo, &lpUC->dwExtraInfoLength,
940 lpszParam, dwUrlLength-(lpszParam-lpszUrl)))
946 if (bIsAbsolute) /* Parse <protocol>:[//<net_loc>] */
949 WCHAR wszAbout[]={'a','b','o','u','t',':',0};
951 /* Get scheme first. */
952 lpUC->nScheme = GetInternetSchemeW(lpszUrl, lpszcp - lpszUrl);
953 if (!SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength,
954 lpszUrl, lpszcp - lpszUrl))
957 /* Eat ':' in protocol. */
960 /* if the scheme is "about", there is no host */
961 if(strncmpW(wszAbout,lpszUrl, lpszcp - lpszUrl)==0)
963 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
964 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
965 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
970 /* Skip over slashes. */
982 lpszNetLoc = strpbrkW(lpszcp, lpszSlash);
986 lpszNetLoc = min(lpszNetLoc, lpszParam);
988 lpszNetLoc = lpszParam;
990 else if (!lpszNetLoc)
991 lpszNetLoc = lpszcp + dwUrlLength-(lpszcp-lpszUrl);
999 /* [<user>[<:password>]@]<host>[:<port>] */
1000 /* First find the user and password if they exist */
1002 lpszHost = strchrW(lpszcp, '@');
1003 if (lpszHost == NULL || lpszHost > lpszNetLoc)
1005 /* username and password not specified. */
1006 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1007 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1009 else /* Parse out username and password */
1011 LPWSTR lpszUser = lpszcp;
1012 LPWSTR lpszPasswd = lpszHost;
1014 while (lpszcp < lpszHost)
1017 lpszPasswd = lpszcp;
1022 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength,
1023 lpszUser, lpszPasswd - lpszUser);
1025 if (lpszPasswd != lpszHost)
1027 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength,
1028 lpszPasswd == lpszHost ? NULL : lpszPasswd,
1029 lpszHost - lpszPasswd);
1031 lpszcp++; /* Advance to beginning of host */
1034 /* Parse <host><:port> */
1037 lpszPort = lpszNetLoc;
1039 /* special case for res:// URLs: there is no port here, so the host is the
1040 entire string up to the first '/' */
1041 if(lpUC->nScheme==INTERNET_SCHEME_RES)
1043 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1044 lpszHost, lpszPort - lpszHost);
1050 while (lpszcp < lpszNetLoc)
1058 /* If the scheme is "file" and the host is just one letter, it's not a host */
1059 if(lpUC->nScheme==INTERNET_SCHEME_FILE && (lpszPort-lpszHost)==1)
1062 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1068 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1069 lpszHost, lpszPort - lpszHost);
1070 if (lpszPort != lpszNetLoc)
1071 lpUC->nPort = atoiW(++lpszPort);
1080 /* Here lpszcp points to:
1082 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1083 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1085 if (lpszcp != 0 && *lpszcp != '\0' && (!lpszParam || lpszcp < lpszParam))
1089 /* Only truncate the parameter list if it's already been saved
1090 * in lpUC->lpszExtraInfo.
1092 if (lpszParam && lpUC->dwExtraInfoLength)
1093 len = lpszParam - lpszcp;
1096 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1097 * newlines if necessary.
1099 LPWSTR lpsznewline = strchrW(lpszcp, '\n');
1100 if (lpsznewline != NULL)
1101 len = lpsznewline - lpszcp;
1103 len = dwUrlLength-(lpszcp-lpszUrl);
1106 if (!SetUrlComponentValueW(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength,
1112 lpUC->dwUrlPathLength = 0;
1115 TRACE("%s: host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl,dwUrlLength),
1116 debugstr_wn(lpUC->lpszHostName,lpUC->dwHostNameLength),
1117 debugstr_wn(lpUC->lpszUrlPath,lpUC->dwUrlPathLength),
1118 debugstr_wn(lpUC->lpszExtraInfo,lpUC->dwExtraInfoLength));
1123 /***********************************************************************
1124 * InternetAttemptConnect (WININET.@)
1126 * Attempt to make a connection to the internet
1129 * ERROR_SUCCESS on success
1130 * Error value on failure
1133 DWORD WINAPI InternetAttemptConnect(DWORD dwReserved)
1136 return ERROR_SUCCESS;
1140 /***********************************************************************
1141 * InternetCanonicalizeUrlA (WININET.@)
1143 * Escape unsafe characters and spaces
1150 BOOL WINAPI InternetCanonicalizeUrlA(LPCSTR lpszUrl, LPSTR lpszBuffer,
1151 LPDWORD lpdwBufferLength, DWORD dwFlags)
1154 TRACE("%s %p %p %08lx\n",debugstr_a(lpszUrl), lpszBuffer,
1155 lpdwBufferLength, dwFlags);
1157 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1158 dwFlags ^= ICU_NO_ENCODE;
1160 dwFlags |= 0x80000000; /* Don't know what this means */
1162 hr = UrlCanonicalizeA(lpszUrl, lpszBuffer, lpdwBufferLength, dwFlags);
1164 return (hr == S_OK) ? TRUE : FALSE;
1167 /***********************************************************************
1168 * InternetCanonicalizeUrlW (WININET.@)
1170 * Escape unsafe characters and spaces
1177 BOOL WINAPI InternetCanonicalizeUrlW(LPCWSTR lpszUrl, LPWSTR lpszBuffer,
1178 LPDWORD lpdwBufferLength, DWORD dwFlags)
1181 TRACE("%s %p %p %08lx\n", debugstr_w(lpszUrl), lpszBuffer,
1182 lpdwBufferLength, dwFlags);
1184 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1185 dwFlags ^= ICU_NO_ENCODE;
1187 dwFlags |= 0x80000000; /* Don't know what this means */
1189 hr = UrlCanonicalizeW(lpszUrl, lpszBuffer, lpdwBufferLength, dwFlags);
1191 return (hr == S_OK) ? TRUE : FALSE;
1195 /***********************************************************************
1196 * InternetSetStatusCallbackA (WININET.@)
1198 * Sets up a callback function which is called as progress is made
1199 * during an operation.
1202 * Previous callback or NULL on success
1203 * INTERNET_INVALID_STATUS_CALLBACK on failure
1206 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackA(
1207 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
1209 INTERNET_STATUS_CALLBACK retVal;
1210 LPWININETAPPINFOA lpwai = (LPWININETAPPINFOA)hInternet;
1212 TRACE("0x%08lx\n", (ULONG)hInternet);
1213 if (lpwai->hdr.htype != WH_HINIT)
1214 return INTERNET_INVALID_STATUS_CALLBACK;
1216 retVal = lpwai->lpfnStatusCB;
1217 lpwai->lpfnStatusCB = lpfnIntCB;
1223 /***********************************************************************
1224 * InternetWriteFile (WININET.@)
1226 * Write data to an open internet file
1233 BOOL WINAPI InternetWriteFile(HINTERNET hFile, LPCVOID lpBuffer ,
1234 DWORD dwNumOfBytesToWrite, LPDWORD lpdwNumOfBytesWritten)
1236 BOOL retval = FALSE;
1238 LPWININETHANDLEHEADER lpwh = (LPWININETHANDLEHEADER) hFile;
1244 switch (lpwh->htype)
1247 nSocket = ((LPWININETHTTPREQA)hFile)->nSocketFD;
1251 nSocket = ((LPWININETFILE)hFile)->nDataSocket;
1260 int res = send(nSocket, lpBuffer, dwNumOfBytesToWrite, 0);
1261 retval = (res >= 0);
1262 *lpdwNumOfBytesWritten = retval ? res : 0;
1269 /***********************************************************************
1270 * InternetReadFile (WININET.@)
1272 * Read data from an open internet file
1279 BOOL WINAPI InternetReadFile(HINTERNET hFile, LPVOID lpBuffer,
1280 DWORD dwNumOfBytesToRead, LPDWORD dwNumOfBytesRead)
1282 BOOL retval = FALSE;
1284 LPWININETHANDLEHEADER lpwh = (LPWININETHANDLEHEADER) hFile;
1291 switch (lpwh->htype)
1294 nSocket = ((LPWININETHTTPREQA)hFile)->nSocketFD;
1298 nSocket = ((LPWININETFILE)hFile)->nDataSocket;
1307 int res = recv(nSocket, lpBuffer, dwNumOfBytesToRead, 0);
1308 retval = (res >= 0);
1309 *dwNumOfBytesRead = retval ? res : 0;
1314 /***********************************************************************
1315 * InternetReadFileExA (WININET.@)
1317 * Read data from an open internet file
1324 BOOL WINAPI InternetReadFileExA(HINTERNET hFile, LPINTERNET_BUFFERSA lpBuffer,
1325 DWORD dwFlags, DWORD dwContext)
1331 /***********************************************************************
1332 * InternetReadFileExW (WININET.@)
1334 * Read data from an open internet file
1341 BOOL WINAPI InternetReadFileExW(HINTERNET hFile, LPINTERNET_BUFFERSW lpBuffer,
1342 DWORD dwFlags, DWORD dwContext)
1346 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1350 /***********************************************************************
1351 * INET_QueryOptionHelper (internal)
1353 static BOOL INET_QueryOptionHelper(BOOL bIsUnicode, HINTERNET hInternet, DWORD dwOption,
1354 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
1356 LPWININETHANDLEHEADER lpwhh;
1357 BOOL bSuccess = FALSE;
1359 TRACE("0x%08lx\n", dwOption);
1361 if (NULL == hInternet)
1363 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
1367 lpwhh = (LPWININETHANDLEHEADER) hInternet;
1371 case INTERNET_OPTION_HANDLE_TYPE:
1373 ULONG type = lpwhh->htype;
1374 TRACE("INTERNET_OPTION_HANDLE_TYPE: %ld\n", type);
1376 if (*lpdwBufferLength < sizeof(ULONG))
1377 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1380 memcpy(lpBuffer, &type, sizeof(ULONG));
1381 *lpdwBufferLength = sizeof(ULONG);
1387 case INTERNET_OPTION_REQUEST_FLAGS:
1390 TRACE("INTERNET_OPTION_REQUEST_FLAGS: %ld\n", flags);
1391 if (*lpdwBufferLength < sizeof(ULONG))
1392 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1395 memcpy(lpBuffer, &flags, sizeof(ULONG));
1396 *lpdwBufferLength = sizeof(ULONG);
1402 case INTERNET_OPTION_URL:
1403 case INTERNET_OPTION_DATAFILE_NAME:
1405 ULONG type = lpwhh->htype;
1406 if (type == WH_HHTTPREQ)
1408 LPWININETHTTPREQA lpreq = hInternet;
1411 sprintf(url,"http://%s%s",lpreq->lpszHostName,lpreq->lpszPath);
1412 TRACE("INTERNET_OPTION_URL: %s\n",url);
1413 if (*lpdwBufferLength < strlen(url)+1)
1414 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1419 *lpdwBufferLength=MultiByteToWideChar(CP_ACP,0,url,-1,lpBuffer,*lpdwBufferLength);
1423 memcpy(lpBuffer, url, strlen(url)+1);
1424 *lpdwBufferLength = strlen(url)+1;
1431 case INTERNET_OPTION_HTTP_VERSION:
1434 * Presently hardcoded to 1.1
1436 ((HTTP_VERSION_INFO*)lpBuffer)->dwMajorVersion = 1;
1437 ((HTTP_VERSION_INFO*)lpBuffer)->dwMinorVersion = 1;
1443 FIXME("Stub! %ld \n",dwOption);
1450 /***********************************************************************
1451 * InternetQueryOptionW (WININET.@)
1453 * Queries an options on the specified handle
1460 BOOL WINAPI InternetQueryOptionW(HINTERNET hInternet, DWORD dwOption,
1461 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
1463 return INET_QueryOptionHelper(TRUE, hInternet, dwOption, lpBuffer, lpdwBufferLength);
1466 /***********************************************************************
1467 * InternetQueryOptionA (WININET.@)
1469 * Queries an options on the specified handle
1476 BOOL WINAPI InternetQueryOptionA(HINTERNET hInternet, DWORD dwOption,
1477 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
1479 return INET_QueryOptionHelper(FALSE, hInternet, dwOption, lpBuffer, lpdwBufferLength);
1483 /***********************************************************************
1484 * InternetSetOptionW (WININET.@)
1486 * Sets an options on the specified handle
1493 BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption,
1494 LPVOID lpBuffer, DWORD dwBufferLength)
1496 LPWININETHANDLEHEADER lpwhh;
1498 TRACE("0x%08lx\n", dwOption);
1500 if (NULL == hInternet)
1502 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
1506 lpwhh = (LPWININETHANDLEHEADER) hInternet;
1510 case INTERNET_OPTION_HTTP_VERSION:
1512 HTTP_VERSION_INFO* pVersion=(HTTP_VERSION_INFO*)lpBuffer;
1513 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%ld,%ld): STUB\n",pVersion->dwMajorVersion,pVersion->dwMinorVersion);
1516 case INTERNET_OPTION_ERROR_MASK:
1518 unsigned long flags=*(unsigned long*)lpBuffer;
1519 FIXME("Option INTERNET_OPTION_ERROR_MASK(%ld): STUB\n",flags);
1522 case INTERNET_OPTION_CODEPAGE:
1524 unsigned long codepage=*(unsigned long*)lpBuffer;
1525 FIXME("Option INTERNET_OPTION_CODEPAGE (%ld): STUB\n",codepage);
1528 case INTERNET_OPTION_REQUEST_PRIORITY:
1530 unsigned long priority=*(unsigned long*)lpBuffer;
1531 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%ld): STUB\n",priority);
1535 FIXME("Option %ld STUB\n",dwOption);
1536 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1544 /***********************************************************************
1545 * InternetSetOptionA (WININET.@)
1547 * Sets an options on the specified handle.
1554 BOOL WINAPI InternetSetOptionA(HINTERNET hInternet, DWORD dwOption,
1555 LPVOID lpBuffer, DWORD dwBufferLength)
1563 case INTERNET_OPTION_PROXY:
1565 LPINTERNET_PROXY_INFOA pi = (LPINTERNET_PROXY_INFOA) lpBuffer;
1566 LPINTERNET_PROXY_INFOW piw;
1567 DWORD proxlen, prbylen;
1570 proxlen = MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, NULL, 0);
1571 prbylen= MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, NULL, 0);
1572 wlen = sizeof *piw + proxlen + prbylen;
1573 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen );
1574 piw = (LPINTERNET_PROXY_INFOW) wbuffer;
1575 piw->dwAccessType = pi->dwAccessType;
1576 prox = (LPWSTR) &piw[1];
1577 prby = &prox[proxlen+1];
1578 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, prox, proxlen);
1579 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, prby, prbylen);
1580 piw->lpszProxy = prox;
1581 piw->lpszProxyBypass = prby;
1584 case INTERNET_OPTION_USER_AGENT:
1585 case INTERNET_OPTION_USERNAME:
1586 case INTERNET_OPTION_PASSWORD:
1587 wlen = MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
1589 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen );
1590 MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
1595 wlen = dwBufferLength;
1598 r = InternetSetOptionW(hInternet,dwOption, wbuffer, wlen);
1600 if( lpBuffer != wbuffer )
1601 HeapFree( GetProcessHeap(), 0, wbuffer );
1607 /***********************************************************************
1608 * InternetSetOptionExA (WININET.@)
1610 BOOL WINAPI InternetSetOptionExA(HINTERNET hInternet, DWORD dwOption,
1611 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
1613 FIXME("Flags %08lx ignored\n", dwFlags);
1614 return InternetSetOptionA( hInternet, dwOption, lpBuffer, dwBufferLength );
1617 /***********************************************************************
1618 * InternetSetOptionExW (WININET.@)
1620 BOOL WINAPI InternetSetOptionExW(HINTERNET hInternet, DWORD dwOption,
1621 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
1623 FIXME("Flags %08lx ignored\n", dwFlags);
1624 if( dwFlags & ~ISO_VALID_FLAGS )
1626 SetLastError( ERROR_INVALID_PARAMETER );
1629 return InternetSetOptionW( hInternet, dwOption, lpBuffer, dwBufferLength );
1633 /***********************************************************************
1634 * InternetGetCookieA (WININET.@)
1636 * Retrieve cookie from the specified url
1643 BOOL WINAPI InternetGetCookieA(LPCSTR lpszUrl, LPCSTR lpszCookieName,
1644 LPSTR lpCookieData, LPDWORD lpdwSize)
1647 TRACE("(%s,%s,%p)\n", debugstr_a(lpszUrl),debugstr_a(lpszCookieName),
1653 /***********************************************************************
1654 * InternetGetCookieW (WININET.@)
1656 * Retrieve cookie from the specified url
1663 BOOL WINAPI InternetGetCookieW(LPCSTR lpszUrl, LPCWSTR lpszCookieName,
1664 LPWSTR lpCookieData, LPDWORD lpdwSize)
1667 TRACE("(%s,%s,%p)\n", debugstr_a(lpszUrl), debugstr_w(lpszCookieName),
1673 /***********************************************************************
1674 * InternetSetCookieA (WININET.@)
1676 * Sets cookie for the specified url
1683 BOOL WINAPI InternetSetCookieA(LPCSTR lpszUrl, LPCSTR lpszCookieName,
1684 LPCSTR lpCookieData)
1687 TRACE("(%s,%s,%s)\n", debugstr_a(lpszUrl),
1688 debugstr_a(lpszCookieName), debugstr_a(lpCookieData));
1693 /***********************************************************************
1694 * InternetSetCookieW (WININET.@)
1696 * Sets cookie for the specified url
1703 BOOL WINAPI InternetSetCookieW(LPCSTR lpszUrl, LPCWSTR lpszCookieName,
1704 LPCWSTR lpCookieData)
1707 TRACE("(%s,%s,%s)\n", debugstr_a(lpszUrl),
1708 debugstr_w(lpszCookieName), debugstr_w(lpCookieData));
1713 /***********************************************************************
1714 * InternetCheckConnectionA (WININET.@)
1716 * Pings a requested host to check internet connection
1719 * TRUE on success and FALSE on failure. If a failure then
1720 * ERROR_NOT_CONNECTED is placesd into GetLastError
1723 BOOL WINAPI InternetCheckConnectionA( LPCSTR lpszUrl, DWORD dwFlags, DWORD dwReserved )
1726 * this is a kludge which runs the resident ping program and reads the output.
1728 * Anyone have a better idea?
1739 * Crack or set the Address
1741 if (lpszUrl == NULL)
1744 * According to the doc we are supost to use the ip for the next
1745 * server in the WnInet internal server database. I have
1746 * no idea what that is or how to get it.
1748 * So someone needs to implement this.
1750 FIXME("Unimplemented with URL of NULL\n");
1755 URL_COMPONENTSA componets;
1757 ZeroMemory(&componets,sizeof(URL_COMPONENTSA));
1758 componets.lpszHostName = (LPSTR)&host;
1759 componets.dwHostNameLength = 1024;
1761 if (!InternetCrackUrlA(lpszUrl,0,0,&componets))
1764 TRACE("host name : %s\n",componets.lpszHostName);
1768 * Build our ping command
1770 strcpy(command,"ping -w 1 ");
1771 strcat(command,host);
1772 strcat(command," >/dev/null 2>/dev/null");
1774 TRACE("Ping command is : %s\n",command);
1776 status = system(command);
1778 TRACE("Ping returned a code of %i \n",status);
1780 /* Ping return code of 0 indicates success */
1787 SetLastError(ERROR_NOT_CONNECTED);
1793 /***********************************************************************
1794 * InternetCheckConnectionW (WININET.@)
1796 * Pings a requested host to check internet connection
1799 * TRUE on success and FALSE on failure. If a failure then
1800 * ERROR_NOT_CONNECTED is placed into GetLastError
1803 BOOL WINAPI InternetCheckConnectionW(LPCWSTR lpszUrl, DWORD dwFlags, DWORD dwReserved)
1809 len = lstrlenW(lpszUrl)+1;
1810 if (!(szUrl = (CHAR *)malloc(len*sizeof(CHAR))))
1812 WideCharToMultiByte(CP_ACP, -1, lpszUrl, -1, szUrl, len, NULL, NULL);
1813 rc = InternetCheckConnectionA((LPCSTR)szUrl, dwFlags, dwReserved);
1820 /**********************************************************
1821 * InternetOpenUrlA (WININET.@)
1826 * handle of connection or NULL on failure
1828 HINTERNET WINAPI InternetOpenUrlA(HINTERNET hInternet, LPCSTR lpszUrl,
1829 LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)
1831 URL_COMPONENTSA urlComponents;
1832 char protocol[32], hostName[MAXHOSTNAME], userName[1024];
1833 char password[1024], path[2048], extra[1024];
1834 HINTERNET client = NULL, client1 = NULL;
1835 urlComponents.dwStructSize = sizeof(URL_COMPONENTSA);
1836 urlComponents.lpszScheme = protocol;
1837 urlComponents.dwSchemeLength = 32;
1838 urlComponents.lpszHostName = hostName;
1839 urlComponents.dwHostNameLength = MAXHOSTNAME;
1840 urlComponents.lpszUserName = userName;
1841 urlComponents.dwUserNameLength = 1024;
1842 urlComponents.lpszPassword = password;
1843 urlComponents.dwPasswordLength = 1024;
1844 urlComponents.lpszUrlPath = path;
1845 urlComponents.dwUrlPathLength = 2048;
1846 urlComponents.lpszExtraInfo = extra;
1847 urlComponents.dwExtraInfoLength = 1024;
1848 if(!InternetCrackUrlA(lpszUrl, strlen(lpszUrl), 0, &urlComponents))
1850 switch(urlComponents.nScheme) {
1851 case INTERNET_SCHEME_FTP:
1852 if(urlComponents.nPort == 0)
1853 urlComponents.nPort = INTERNET_DEFAULT_FTP_PORT;
1854 client = InternetConnectA(hInternet, hostName, urlComponents.nPort,
1855 userName, password, INTERNET_SERVICE_FTP, dwFlags, dwContext);
1856 return FtpOpenFileA(client, path, GENERIC_READ, dwFlags, dwContext);
1857 case INTERNET_SCHEME_HTTP:
1858 case INTERNET_SCHEME_HTTPS:
1860 LPCSTR accept[2] = { "*/*", NULL };
1861 char *hostreq=(char*)malloc(strlen(hostName)+9);
1862 sprintf(hostreq, "Host: %s\r\n", hostName);
1863 if(urlComponents.nPort == 0) {
1864 if(urlComponents.nScheme == INTERNET_SCHEME_HTTP)
1865 urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
1867 urlComponents.nPort = INTERNET_DEFAULT_HTTPS_PORT;
1869 client = InternetConnectA(hInternet, hostName, urlComponents.nPort, userName,
1870 password, INTERNET_SERVICE_HTTP, dwFlags, dwContext);
1873 client1 = HttpOpenRequestA(client, NULL, path, NULL, NULL, accept, dwFlags, dwContext);
1874 if(client1 == NULL) {
1875 InternetCloseHandle(client);
1878 HttpAddRequestHeadersA(client1, lpszHeaders, dwHeadersLength, HTTP_ADDREQ_FLAG_ADD);
1879 if(!HttpSendRequestA(client1, NULL, 0, NULL, 0)) {
1880 InternetCloseHandle(client1);
1881 InternetCloseHandle(client);
1886 case INTERNET_SCHEME_GOPHER:
1887 /* gopher doesn't seem to be implemented in wine, but it's supposed
1888 * to be supported by InternetOpenUrlA. */
1895 /**********************************************************
1896 * InternetOpenUrlW (WININET.@)
1901 * handle of connection or NULL on failure
1903 HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
1904 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)
1906 HINTERNET rc = (HINTERNET)NULL;
1908 INT lenUrl = lstrlenW(lpszUrl)+1;
1909 INT lenHeaders = lstrlenW(lpszHeaders)+1;
1910 CHAR *szUrl = (CHAR *)malloc(lenUrl*sizeof(CHAR));
1911 CHAR *szHeaders = (CHAR *)malloc(lenHeaders*sizeof(CHAR));
1913 if (!szUrl || !szHeaders)
1919 return (HINTERNET)NULL;
1922 WideCharToMultiByte(CP_ACP, -1, lpszUrl, -1, szUrl, lenUrl,
1924 WideCharToMultiByte(CP_ACP, -1, lpszHeaders, -1, szHeaders, lenHeaders,
1927 rc = InternetOpenUrlA(hInternet, szUrl, szHeaders,
1928 dwHeadersLength, dwFlags, dwContext);
1937 /***********************************************************************
1938 * INTERNET_SetLastError (internal)
1940 * Set last thread specific error
1945 void INTERNET_SetLastError(DWORD dwError)
1947 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
1949 SetLastError(dwError);
1951 lpwite->dwError = dwError;
1955 /***********************************************************************
1956 * INTERNET_GetLastError (internal)
1958 * Get last thread specific error
1963 DWORD INTERNET_GetLastError()
1965 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
1966 return lpwite->dwError;
1970 /***********************************************************************
1971 * INTERNET_WorkerThreadFunc (internal)
1973 * Worker thread execution function
1978 DWORD INTERNET_WorkerThreadFunc(LPVOID *lpvParam)
1985 INTERNET_ExecuteWork();
1988 dwWaitRes = WaitForMultipleObjects(2, hEventArray, FALSE, MAX_IDLE_WORKER);
1990 if (dwWaitRes == WAIT_OBJECT_0 + 1)
1991 INTERNET_ExecuteWork();
1995 InterlockedIncrement(&dwNumIdleThreads);
1998 InterlockedDecrement(&dwNumIdleThreads);
1999 InterlockedDecrement(&dwNumThreads);
2000 TRACE("Worker thread exiting\n");
2005 /***********************************************************************
2006 * INTERNET_InsertWorkRequest (internal)
2008 * Insert work request into queue
2013 BOOL INTERNET_InsertWorkRequest(LPWORKREQUEST lpWorkRequest)
2015 BOOL bSuccess = FALSE;
2016 LPWORKREQUEST lpNewRequest;
2020 lpNewRequest = HeapAlloc(GetProcessHeap(), 0, sizeof(WORKREQUEST));
2023 memcpy(lpNewRequest, lpWorkRequest, sizeof(WORKREQUEST));
2024 lpNewRequest->prev = NULL;
2026 EnterCriticalSection(&csQueue);
2028 lpNewRequest->next = lpWorkQueueTail;
2029 if (lpWorkQueueTail)
2030 lpWorkQueueTail->prev = lpNewRequest;
2031 lpWorkQueueTail = lpNewRequest;
2032 if (!lpHeadWorkQueue)
2033 lpHeadWorkQueue = lpWorkQueueTail;
2035 LeaveCriticalSection(&csQueue);
2038 InterlockedIncrement(&dwNumJobs);
2045 /***********************************************************************
2046 * INTERNET_GetWorkRequest (internal)
2048 * Retrieves work request from queue
2053 BOOL INTERNET_GetWorkRequest(LPWORKREQUEST lpWorkRequest)
2055 BOOL bSuccess = FALSE;
2056 LPWORKREQUEST lpRequest = NULL;
2060 EnterCriticalSection(&csQueue);
2062 if (lpHeadWorkQueue)
2064 lpRequest = lpHeadWorkQueue;
2065 lpHeadWorkQueue = lpHeadWorkQueue->prev;
2066 if (lpRequest == lpWorkQueueTail)
2067 lpWorkQueueTail = lpHeadWorkQueue;
2070 LeaveCriticalSection(&csQueue);
2074 memcpy(lpWorkRequest, lpRequest, sizeof(WORKREQUEST));
2075 HeapFree(GetProcessHeap(), 0, lpRequest);
2077 InterlockedDecrement(&dwNumJobs);
2084 /***********************************************************************
2085 * INTERNET_AsyncCall (internal)
2087 * Retrieves work request from queue
2092 BOOL INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest)
2096 BOOL bSuccess = FALSE;
2100 if (InterlockedDecrement(&dwNumIdleThreads) < 0)
2102 InterlockedIncrement(&dwNumIdleThreads);
2104 if (InterlockedIncrement(&dwNumThreads) > MAX_WORKER_THREADS ||
2105 !(hThread = CreateThread(NULL, 0,
2106 (LPTHREAD_START_ROUTINE)INTERNET_WorkerThreadFunc, NULL, 0, &dwTID)))
2108 InterlockedDecrement(&dwNumThreads);
2109 INTERNET_SetLastError(ERROR_INTERNET_ASYNC_THREAD_FAILED);
2113 TRACE("Created new thread\n");
2117 INTERNET_InsertWorkRequest(lpWorkRequest);
2118 SetEvent(hWorkEvent);
2126 /***********************************************************************
2127 * INTERNET_ExecuteWork (internal)
2132 VOID INTERNET_ExecuteWork()
2134 WORKREQUEST workRequest;
2138 if (INTERNET_GetWorkRequest(&workRequest))
2140 TRACE("Got work %d\n", workRequest.asyncall);
2141 switch (workRequest.asyncall)
2144 FTP_FtpPutFileA((HINTERNET)workRequest.HFTPSESSION, (LPCSTR)workRequest.LPSZLOCALFILE,
2145 (LPCSTR)workRequest.LPSZNEWREMOTEFILE, workRequest.DWFLAGS, workRequest.DWCONTEXT);
2146 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZLOCALFILE);
2147 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZNEWREMOTEFILE);
2150 case FTPSETCURRENTDIRECTORYA:
2151 FTP_FtpSetCurrentDirectoryA((HINTERNET)workRequest.HFTPSESSION,
2152 (LPCSTR)workRequest.LPSZDIRECTORY);
2153 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZDIRECTORY);
2156 case FTPCREATEDIRECTORYA:
2157 FTP_FtpCreateDirectoryA((HINTERNET)workRequest.HFTPSESSION,
2158 (LPCSTR)workRequest.LPSZDIRECTORY);
2159 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZDIRECTORY);
2162 case FTPFINDFIRSTFILEA:
2163 FTP_FtpFindFirstFileA((HINTERNET)workRequest.HFTPSESSION,
2164 (LPCSTR)workRequest.LPSZSEARCHFILE,
2165 (LPWIN32_FIND_DATAA)workRequest.LPFINDFILEDATA, workRequest.DWFLAGS,
2166 workRequest.DWCONTEXT);
2167 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZSEARCHFILE);
2170 case FTPGETCURRENTDIRECTORYA:
2171 FTP_FtpGetCurrentDirectoryA((HINTERNET)workRequest.HFTPSESSION,
2172 (LPSTR)workRequest.LPSZDIRECTORY, (LPDWORD)workRequest.LPDWDIRECTORY);
2176 FTP_FtpOpenFileA((HINTERNET)workRequest.HFTPSESSION,
2177 (LPCSTR)workRequest.LPSZFILENAME,
2178 workRequest.FDWACCESS,
2179 workRequest.DWFLAGS,
2180 workRequest.DWCONTEXT);
2181 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZFILENAME);
2185 FTP_FtpGetFileA((HINTERNET)workRequest.HFTPSESSION,
2186 (LPCSTR)workRequest.LPSZREMOTEFILE,
2187 (LPCSTR)workRequest.LPSZNEWFILE,
2188 (BOOL)workRequest.FFAILIFEXISTS,
2189 workRequest.DWLOCALFLAGSATTRIBUTE,
2190 workRequest.DWFLAGS,
2191 workRequest.DWCONTEXT);
2192 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZREMOTEFILE);
2193 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZNEWFILE);
2196 case FTPDELETEFILEA:
2197 FTP_FtpDeleteFileA((HINTERNET)workRequest.HFTPSESSION,
2198 (LPCSTR)workRequest.LPSZFILENAME);
2199 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZFILENAME);
2202 case FTPREMOVEDIRECTORYA:
2203 FTP_FtpRemoveDirectoryA((HINTERNET)workRequest.HFTPSESSION,
2204 (LPCSTR)workRequest.LPSZDIRECTORY);
2205 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZDIRECTORY);
2208 case FTPRENAMEFILEA:
2209 FTP_FtpRenameFileA((HINTERNET)workRequest.HFTPSESSION,
2210 (LPCSTR)workRequest.LPSZSRCFILE,
2211 (LPCSTR)workRequest.LPSZDESTFILE);
2212 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZSRCFILE);
2213 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZDESTFILE);
2216 case INTERNETFINDNEXTA:
2217 INTERNET_FindNextFileA((HINTERNET)workRequest.HFTPSESSION,
2218 (LPWIN32_FIND_DATAA)workRequest.LPFINDFILEDATA);
2221 case HTTPSENDREQUESTA:
2222 HTTP_HttpSendRequestA((HINTERNET)workRequest.HFTPSESSION,
2223 (LPCSTR)workRequest.LPSZHEADER,
2224 workRequest.DWHEADERLENGTH,
2225 (LPVOID)workRequest.LPOPTIONAL,
2226 workRequest.DWOPTIONALLENGTH);
2227 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZHEADER);
2230 case HTTPOPENREQUESTA:
2231 HTTP_HttpOpenRequestA((HINTERNET)workRequest.HFTPSESSION,
2232 (LPCSTR)workRequest.LPSZVERB,
2233 (LPCSTR)workRequest.LPSZOBJECTNAME,
2234 (LPCSTR)workRequest.LPSZVERSION,
2235 (LPCSTR)workRequest.LPSZREFERRER,
2236 (LPCSTR*)workRequest.LPSZACCEPTTYPES,
2237 workRequest.DWFLAGS,
2238 workRequest.DWCONTEXT);
2239 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZVERB);
2240 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZOBJECTNAME);
2241 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZVERSION);
2242 HeapFree(GetProcessHeap(), 0, (LPVOID)workRequest.LPSZREFERRER);
2246 SendAsyncCallbackInt((LPWININETAPPINFOA)workRequest.param1,
2247 (HINTERNET)workRequest.param2, workRequest.param3,
2248 workRequest.param4, (LPVOID)workRequest.param5,
2249 workRequest.param6);
2256 /***********************************************************************
2257 * INTERNET_GetResponseBuffer
2262 LPSTR INTERNET_GetResponseBuffer()
2264 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
2266 return lpwite->response;
2270 /***********************************************************************
2271 * INTERNET_GetNextLine (internal)
2273 * Parse next line in directory string listing
2276 * Pointer to beginning of next line
2281 LPSTR INTERNET_GetNextLine(INT nSocket, LPSTR lpszBuffer, LPDWORD dwBuffer)
2285 BOOL bSuccess = FALSE;
2291 FD_SET(nSocket, &infd);
2292 tv.tv_sec=RESPONSE_TIMEOUT;
2295 while (nRecv < *dwBuffer)
2297 if (select(nSocket+1,&infd,NULL,NULL,&tv) > 0)
2299 if (recv(nSocket, &lpszBuffer[nRecv], 1, 0) <= 0)
2301 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
2305 if (lpszBuffer[nRecv] == '\n')
2310 if (lpszBuffer[nRecv] != '\r')
2315 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT);
2323 lpszBuffer[nRecv] = '\0';
2324 *dwBuffer = nRecv - 1;
2325 TRACE(":%d %s\n", nRecv, lpszBuffer);
2334 /***********************************************************************
2337 BOOL WINAPI InternetQueryDataAvailable( HINTERNET hFile,
2338 LPDWORD lpdwNumberOfBytesAvailble,
2339 DWORD dwFlags, DWORD dwConext)
2341 LPWININETHTTPREQA lpwhr = (LPWININETHTTPREQA) hFile;
2348 SetLastError(ERROR_NO_MORE_FILES);
2352 TRACE("--> %p %i %i\n",lpwhr,lpwhr->hdr.htype,lpwhr->nSocketFD);
2354 switch (lpwhr->hdr.htype)
2357 nSocket = lpwhr->nSocketFD;
2368 retval = recv(nSocket,buffer,4048,MSG_PEEK);
2372 SetLastError(ERROR_NO_MORE_FILES);
2375 if (lpdwNumberOfBytesAvailble)
2377 (*lpdwNumberOfBytesAvailble) = retval;
2380 TRACE("<-- %i\n",retval);
2385 /***********************************************************************
2388 BOOL WINAPI InternetLockRequestFile( HINTERNET hInternet, HANDLE
2395 BOOL WINAPI InternetUnlockRequestFile( HANDLE hLockHandle)
2402 /***********************************************************************
2405 * On windows this function is supposed to dial the default internet
2406 * connection. We don't want to have Wine dial out to the internet so
2407 * we return TRUE by default. It might be nice to check if we are connected.
2414 BOOL WINAPI InternetAutodial(DWORD dwFlags, HWND hwndParent)
2418 /* Tell that we are connected to the internet. */
2422 /***********************************************************************
2423 * InternetAutodialHangup
2425 * Hangs up an connection made with InternetAutodial
2434 BOOL WINAPI InternetAutodialHangup(DWORD dwReserved)
2438 /* we didn't dial, we don't disconnect */
2442 /***********************************************************************
2444 * InternetCombineUrlA
2446 * Combine a base URL with a relative URL
2454 BOOL WINAPI InternetCombineUrlA(LPCSTR lpszBaseUrl, LPCSTR lpszRelativeUrl,
2455 LPSTR lpszBuffer, LPDWORD lpdwBufferLength,
2459 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
2460 dwFlags ^= ICU_NO_ENCODE;
2461 hr=UrlCombineA(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
2466 /***********************************************************************
2468 * InternetCombineUrlW
2470 * Combine a base URL with a relative URL
2478 BOOL WINAPI InternetCombineUrlW(LPCWSTR lpszBaseUrl, LPCWSTR lpszRelativeUrl,
2479 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength,
2483 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
2484 dwFlags ^= ICU_NO_ENCODE;
2485 hr=UrlCombineW(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);