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
);
193 /***********************************************************************
194 * InternetOpenA (WININET.@)
196 * Per-application initialization of wininet
199 * HINTERNET on success
203 HINTERNET WINAPI
InternetOpenA(LPCSTR lpszAgent
, DWORD dwAccessType
,
204 LPCSTR lpszProxy
, LPCSTR lpszProxyBypass
, DWORD dwFlags
)
206 LPWININETAPPINFOA lpwai
= NULL
;
210 /* Clear any error information */
211 INTERNET_SetLastError(0);
213 lpwai
= HeapAlloc(GetProcessHeap(), 0, sizeof(WININETAPPINFOA
));
215 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
218 memset(lpwai
, 0, sizeof(WININETAPPINFOA
));
219 lpwai
->hdr
.htype
= WH_HINIT
;
220 lpwai
->hdr
.lpwhparent
= NULL
;
221 lpwai
->hdr
.dwFlags
= dwFlags
;
222 if (NULL
!= lpszAgent
)
224 if ((lpwai
->lpszAgent
= HeapAlloc( GetProcessHeap(),0,strlen(lpszAgent
)+1)))
225 strcpy( lpwai
->lpszAgent
, lpszAgent
);
227 if (NULL
!= lpszProxy
)
229 if ((lpwai
->lpszProxy
= HeapAlloc( GetProcessHeap(), 0, strlen(lpszProxy
)+1 )))
230 strcpy( lpwai
->lpszProxy
, lpszProxy
);
232 if (NULL
!= lpszProxyBypass
)
234 if ((lpwai
->lpszProxyBypass
= HeapAlloc( GetProcessHeap(), 0, strlen(lpszProxyBypass
)+1)))
235 strcpy( lpwai
->lpszProxyBypass
, lpszProxyBypass
);
237 lpwai
->dwAccessType
= dwAccessType
;
240 return (HINTERNET
)lpwai
;
244 /***********************************************************************
245 * InternetOpenW (WININET.@)
247 * Per-application initialization of wininet
250 * HINTERNET on success
254 HINTERNET WINAPI
InternetOpenW(LPCWSTR lpszAgent
, DWORD dwAccessType
,
255 LPCWSTR lpszProxy
, LPCWSTR lpszProxyBypass
, DWORD dwFlags
)
257 HINTERNET rc
= (HINTERNET
)NULL
;
258 INT lenAgent
= lstrlenW(lpszAgent
)+1;
259 INT lenProxy
= lstrlenW(lpszProxy
)+1;
260 INT lenBypass
= lstrlenW(lpszProxyBypass
)+1;
261 CHAR
*szAgent
= (CHAR
*)malloc(lenAgent
*sizeof(CHAR
));
262 CHAR
*szProxy
= (CHAR
*)malloc(lenProxy
*sizeof(CHAR
));
263 CHAR
*szBypass
= (CHAR
*)malloc(lenBypass
*sizeof(CHAR
));
265 if (!szAgent
|| !szProxy
|| !szBypass
)
273 return (HINTERNET
)NULL
;
276 WideCharToMultiByte(CP_ACP
, -1, lpszAgent
, -1, szAgent
, lenAgent
,
278 WideCharToMultiByte(CP_ACP
, -1, lpszProxy
, -1, szProxy
, lenProxy
,
280 WideCharToMultiByte(CP_ACP
, -1, lpszProxyBypass
, -1, szBypass
, lenBypass
,
283 rc
= InternetOpenA(szAgent
, dwAccessType
, szProxy
, szBypass
, dwFlags
);
292 /***********************************************************************
293 * InternetGetLastResponseInfoA (WININET.@)
295 * Return last wininet error description on the calling thread
298 * TRUE on success of writting to buffer
302 BOOL WINAPI
InternetGetLastResponseInfoA(LPDWORD lpdwError
,
303 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
)
305 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
309 *lpdwError
= lpwite
->dwError
;
312 strncpy(lpszBuffer
, lpwite
->response
, *lpdwBufferLength
);
313 *lpdwBufferLength
= strlen(lpszBuffer
);
316 *lpdwBufferLength
= 0;
322 /***********************************************************************
323 * InternetGetConnectedState (WININET.@)
325 * Return connected state
329 * if lpdwStatus is not null, return the status (off line,
330 * modem, lan...) in it.
331 * FALSE if not connected
333 BOOL WINAPI
InternetGetConnectedState(LPDWORD lpdwStatus
, DWORD dwReserved
)
336 FIXME("always returning LAN connection.\n");
337 *lpdwStatus
= INTERNET_CONNECTION_LAN
;
343 /***********************************************************************
344 * InternetConnectA (WININET.@)
346 * Open a ftp, gopher or http session
349 * HINTERNET a session handle on success
353 HINTERNET WINAPI
InternetConnectA(HINTERNET hInternet
,
354 LPCSTR lpszServerName
, INTERNET_PORT nServerPort
,
355 LPCSTR lpszUserName
, LPCSTR lpszPassword
,
356 DWORD dwService
, DWORD dwFlags
, DWORD dwContext
)
358 HINTERNET rc
= (HINTERNET
) NULL
;
360 TRACE("ServerPort %i\n",nServerPort
);
362 /* Clear any error information */
363 INTERNET_SetLastError(0);
367 case INTERNET_SERVICE_FTP
:
368 rc
= FTP_Connect(hInternet
, lpszServerName
, nServerPort
,
369 lpszUserName
, lpszPassword
, dwFlags
, dwContext
);
372 case INTERNET_SERVICE_HTTP
:
373 rc
= HTTP_Connect(hInternet
, lpszServerName
, nServerPort
,
374 lpszUserName
, lpszPassword
, dwFlags
, dwContext
);
377 case INTERNET_SERVICE_GOPHER
:
386 /***********************************************************************
387 * InternetConnectW (WININET.@)
389 * Open a ftp, gopher or http session
392 * HINTERNET a session handle on success
396 HINTERNET WINAPI
InternetConnectW(HINTERNET hInternet
,
397 LPCWSTR lpszServerName
, INTERNET_PORT nServerPort
,
398 LPCWSTR lpszUserName
, LPCWSTR lpszPassword
,
399 DWORD dwService
, DWORD dwFlags
, DWORD dwContext
)
401 HINTERNET rc
= (HINTERNET
)NULL
;
402 INT lenServer
= lstrlenW(lpszServerName
)+1;
403 INT lenUser
= lstrlenW(lpszUserName
)+1;
404 INT lenPass
= lstrlenW(lpszPassword
)+1;
405 CHAR
*szServerName
= (CHAR
*)malloc(lenServer
*sizeof(CHAR
));
406 CHAR
*szUserName
= (CHAR
*)malloc(lenUser
*sizeof(CHAR
));
407 CHAR
*szPassword
= (CHAR
*)malloc(lenPass
*sizeof(CHAR
));
409 if (!szServerName
|| !szUserName
|| !szPassword
)
417 return (HINTERNET
)NULL
;
420 WideCharToMultiByte(CP_ACP
, -1, lpszServerName
, -1, szServerName
, lenServer
,
422 WideCharToMultiByte(CP_ACP
, -1, lpszUserName
, -1, szUserName
, lenUser
,
424 WideCharToMultiByte(CP_ACP
, -1, lpszPassword
, -1, szPassword
, lenPass
,
427 rc
= InternetConnectA(hInternet
, szServerName
, nServerPort
,
428 szUserName
, szPassword
, dwService
, dwFlags
, dwContext
);
437 /***********************************************************************
438 * InternetFindNextFileA (WININET.@)
440 * Continues a file search from a previous call to FindFirstFile
447 BOOL WINAPI
InternetFindNextFileA(HINTERNET hFind
, LPVOID lpvFindData
)
449 LPWININETAPPINFOA hIC
= NULL
;
450 LPWININETFINDNEXTA lpwh
= (LPWININETFINDNEXTA
) hFind
;
454 if (NULL
== lpwh
|| lpwh
->hdr
.htype
!= WH_HFINDNEXT
)
456 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
460 hIC
= GET_HWININET_FROM_LPWININETFINDNEXT(lpwh
);
461 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
)
463 WORKREQUEST workRequest
;
465 workRequest
.asyncall
= INTERNETFINDNEXTA
;
466 workRequest
.HFTPSESSION
= (DWORD
)hFind
;
467 workRequest
.LPFINDFILEDATA
= (DWORD
)lpvFindData
;
469 return INTERNET_AsyncCall(&workRequest
);
473 return INTERNET_FindNextFileA(hFind
, lpvFindData
);
477 /***********************************************************************
478 * INTERNET_FindNextFileA (Internal)
480 * Continues a file search from a previous call to FindFirstFile
487 BOOL WINAPI
INTERNET_FindNextFileA(HINTERNET hFind
, LPVOID lpvFindData
)
489 BOOL bSuccess
= TRUE
;
490 LPWININETAPPINFOA hIC
= NULL
;
491 LPWIN32_FIND_DATAA lpFindFileData
;
492 LPWININETFINDNEXTA lpwh
= (LPWININETFINDNEXTA
) hFind
;
496 if (NULL
== lpwh
|| lpwh
->hdr
.htype
!= WH_HFINDNEXT
)
498 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
502 /* Clear any error information */
503 INTERNET_SetLastError(0);
505 if (lpwh
->hdr
.lpwhparent
->htype
!= WH_HFTPSESSION
)
507 FIXME("Only FTP find next supported\n");
508 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
512 TRACE("index(%d) size(%ld)\n", lpwh
->index
, lpwh
->size
);
514 lpFindFileData
= (LPWIN32_FIND_DATAA
) lpvFindData
;
515 ZeroMemory(lpFindFileData
, sizeof(WIN32_FIND_DATAA
));
517 if (lpwh
->index
>= lpwh
->size
)
519 INTERNET_SetLastError(ERROR_NO_MORE_FILES
);
524 FTP_ConvertFileProp(&lpwh
->lpafp
[lpwh
->index
], lpFindFileData
);
527 TRACE("\nName: %s\nSize: %ld\n", lpFindFileData
->cFileName
, lpFindFileData
->nFileSizeLow
);
531 hIC
= GET_HWININET_FROM_LPWININETFINDNEXT(lpwh
);
532 if (hIC
->lpfnStatusCB
)
534 INTERNET_ASYNC_RESULT iar
;
536 iar
.dwResult
= (DWORD
)bSuccess
;
537 iar
.dwError
= iar
.dwError
= bSuccess
? ERROR_SUCCESS
:
538 INTERNET_GetLastError();
540 SendAsyncCallback(hIC
, hFind
, lpwh
->hdr
.dwContext
,
541 INTERNET_STATUS_REQUEST_COMPLETE
, &iar
,
542 sizeof(INTERNET_ASYNC_RESULT
));
549 /***********************************************************************
550 * INTERNET_CloseHandle (internal)
552 * Close internet handle
558 VOID
INTERNET_CloseHandle(LPWININETAPPINFOA lpwai
)
562 SendAsyncCallback(lpwai
, lpwai
, lpwai
->hdr
.dwContext
,
563 INTERNET_STATUS_HANDLE_CLOSING
, lpwai
,
566 if (lpwai
->lpszAgent
)
567 HeapFree(GetProcessHeap(), 0, lpwai
->lpszAgent
);
569 if (lpwai
->lpszProxy
)
570 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxy
);
572 if (lpwai
->lpszProxyBypass
)
573 HeapFree(GetProcessHeap(), 0, lpwai
->lpszProxyBypass
);
575 HeapFree(GetProcessHeap(), 0, lpwai
);
579 /***********************************************************************
580 * InternetCloseHandle (WININET.@)
582 * Generic close handle function
589 BOOL WINAPI
InternetCloseHandle(HINTERNET hInternet
)
592 LPWININETHANDLEHEADER lpwh
= (LPWININETHANDLEHEADER
) hInternet
;
594 TRACE("%p\n",hInternet
);
599 /* Clear any error information */
600 INTERNET_SetLastError(0);
606 INTERNET_CloseHandle((LPWININETAPPINFOA
) lpwh
);
610 case WH_HHTTPSESSION
:
611 HTTP_CloseHTTPSessionHandle((LPWININETHTTPSESSIONA
) lpwh
);
616 HTTP_CloseHTTPRequestHandle((LPWININETHTTPREQA
) lpwh
);
621 retval
= FTP_CloseSessionHandle((LPWININETFTPSESSIONA
) lpwh
);
625 retval
= FTP_CloseFindNextHandle((LPWININETFINDNEXTA
) lpwh
);
631 } __EXCEPT(page_fault
) {
632 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
641 /***********************************************************************
642 * ConvertUrlComponentValue (Internal)
644 * Helper function for InternetCrackUrlA
647 void ConvertUrlComponentValue(LPSTR
* lppszComponent
, LPDWORD dwComponentLen
,
648 LPWSTR lpwszComponent
, DWORD dwwComponentLen
,
652 if (*dwComponentLen
!= 0)
654 int nASCIILength
=WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,NULL
,0,NULL
,NULL
);
655 if (*lppszComponent
== NULL
)
657 int nASCIIOffset
=WideCharToMultiByte(CP_ACP
,0,lpwszStart
,lpwszComponent
-lpwszStart
,NULL
,0,NULL
,NULL
);
658 *lppszComponent
= (LPSTR
)lpszStart
+nASCIIOffset
;
659 *dwComponentLen
= nASCIILength
;
663 INT ncpylen
= min((*dwComponentLen
)-1, nASCIILength
);
664 WideCharToMultiByte(CP_ACP
,0,lpwszComponent
,dwwComponentLen
,*lppszComponent
,ncpylen
+1,NULL
,NULL
);
665 (*lppszComponent
)[ncpylen
]=0;
666 *dwComponentLen
= ncpylen
;
672 /***********************************************************************
673 * InternetCrackUrlA (WININET.@)
675 * Break up URL into its components
677 * TODO: Handle dwFlags
684 BOOL WINAPI
InternetCrackUrlA(LPCSTR lpszUrl
, DWORD dwUrlLength
, DWORD dwFlags
,
685 LPURL_COMPONENTSA lpUrlComponents
)
691 dwUrlLength
=strlen(lpszUrl
);
692 lpwszUrl
=HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
)*(dwUrlLength
+1));
693 memset(lpwszUrl
,0,sizeof(WCHAR
)*(dwUrlLength
+1));
694 nLength
=MultiByteToWideChar(CP_ACP
,0,lpszUrl
,dwUrlLength
,lpwszUrl
,dwUrlLength
+1);
695 memset(&UCW
,0,sizeof(UCW
));
696 if(lpUrlComponents
->dwHostNameLength
!=0)
697 UCW
.dwHostNameLength
=1;
698 if(lpUrlComponents
->dwUserNameLength
!=0)
699 UCW
.dwUserNameLength
=1;
700 if(lpUrlComponents
->dwPasswordLength
!=0)
701 UCW
.dwPasswordLength
=1;
702 if(lpUrlComponents
->dwUrlPathLength
!=0)
703 UCW
.dwUrlPathLength
=1;
704 if(lpUrlComponents
->dwSchemeLength
!=0)
705 UCW
.dwSchemeLength
=1;
706 if(lpUrlComponents
->dwExtraInfoLength
!=0)
707 UCW
.dwExtraInfoLength
=1;
708 if(!InternetCrackUrlW(lpwszUrl
,nLength
,dwFlags
,&UCW
))
710 HeapFree(GetProcessHeap(), 0, lpwszUrl
);
713 ConvertUrlComponentValue(&lpUrlComponents
->lpszHostName
, &lpUrlComponents
->dwHostNameLength
,
714 UCW
.lpszHostName
, UCW
.dwHostNameLength
,
716 ConvertUrlComponentValue(&lpUrlComponents
->lpszUserName
, &lpUrlComponents
->dwUserNameLength
,
717 UCW
.lpszUserName
, UCW
.dwUserNameLength
,
719 ConvertUrlComponentValue(&lpUrlComponents
->lpszPassword
, &lpUrlComponents
->dwPasswordLength
,
720 UCW
.lpszPassword
, UCW
.dwPasswordLength
,
722 ConvertUrlComponentValue(&lpUrlComponents
->lpszUrlPath
, &lpUrlComponents
->dwUrlPathLength
,
723 UCW
.lpszUrlPath
, UCW
.dwUrlPathLength
,
725 ConvertUrlComponentValue(&lpUrlComponents
->lpszScheme
, &lpUrlComponents
->dwSchemeLength
,
726 UCW
.lpszScheme
, UCW
.dwSchemeLength
,
728 ConvertUrlComponentValue(&lpUrlComponents
->lpszExtraInfo
, &lpUrlComponents
->dwExtraInfoLength
,
729 UCW
.lpszExtraInfo
, UCW
.dwExtraInfoLength
,
731 lpUrlComponents
->nScheme
=UCW
.nScheme
;
732 lpUrlComponents
->nPort
=UCW
.nPort
;
733 HeapFree(GetProcessHeap(), 0, lpwszUrl
);
735 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", lpszUrl
,
736 debugstr_an(lpUrlComponents
->lpszScheme
,lpUrlComponents
->dwSchemeLength
),
737 debugstr_an(lpUrlComponents
->lpszHostName
,lpUrlComponents
->dwHostNameLength
),
738 debugstr_an(lpUrlComponents
->lpszUrlPath
,lpUrlComponents
->dwUrlPathLength
),
739 debugstr_an(lpUrlComponents
->lpszExtraInfo
,lpUrlComponents
->dwExtraInfoLength
));
744 /***********************************************************************
745 * GetInternetSchemeW (internal)
751 * INTERNET_SCHEME_UNKNOWN on failure
754 INTERNET_SCHEME
GetInternetSchemeW(LPCWSTR lpszScheme
, INT nMaxCmp
)
756 INTERNET_SCHEME iScheme
=INTERNET_SCHEME_UNKNOWN
;
757 WCHAR lpszFtp
[]={'f','t','p',0};
758 WCHAR lpszGopher
[]={'g','o','p','h','e','r',0};
759 WCHAR lpszHttp
[]={'h','t','t','p',0};
760 WCHAR lpszHttps
[]={'h','t','t','p','s',0};
761 WCHAR lpszFile
[]={'f','i','l','e',0};
762 WCHAR lpszNews
[]={'n','e','w','s',0};
763 WCHAR lpszMailto
[]={'m','a','i','l','t','o',0};
764 WCHAR lpszRes
[]={'r','e','s',0};
765 WCHAR
* tempBuffer
=NULL
;
768 return INTERNET_SCHEME_UNKNOWN
;
770 tempBuffer
=malloc(nMaxCmp
+1);
771 strncpyW(tempBuffer
,lpszScheme
,nMaxCmp
);
772 tempBuffer
[nMaxCmp
]=0;
774 if (nMaxCmp
==strlenW(lpszFtp
) && !strncmpW(lpszFtp
, tempBuffer
, nMaxCmp
))
775 iScheme
=INTERNET_SCHEME_FTP
;
776 else if (nMaxCmp
==strlenW(lpszGopher
) && !strncmpW(lpszGopher
, tempBuffer
, nMaxCmp
))
777 iScheme
=INTERNET_SCHEME_GOPHER
;
778 else if (nMaxCmp
==strlenW(lpszHttp
) && !strncmpW(lpszHttp
, tempBuffer
, nMaxCmp
))
779 iScheme
=INTERNET_SCHEME_HTTP
;
780 else if (nMaxCmp
==strlenW(lpszHttps
) && !strncmpW(lpszHttps
, tempBuffer
, nMaxCmp
))
781 iScheme
=INTERNET_SCHEME_HTTPS
;
782 else if (nMaxCmp
==strlenW(lpszFile
) && !strncmpW(lpszFile
, tempBuffer
, nMaxCmp
))
783 iScheme
=INTERNET_SCHEME_FILE
;
784 else if (nMaxCmp
==strlenW(lpszNews
) && !strncmpW(lpszNews
, tempBuffer
, nMaxCmp
))
785 iScheme
=INTERNET_SCHEME_NEWS
;
786 else if (nMaxCmp
==strlenW(lpszMailto
) && !strncmpW(lpszMailto
, tempBuffer
, nMaxCmp
))
787 iScheme
=INTERNET_SCHEME_MAILTO
;
788 else if (nMaxCmp
==strlenW(lpszRes
) && !strncmpW(lpszRes
, tempBuffer
, nMaxCmp
))
789 iScheme
=INTERNET_SCHEME_RES
;
794 /***********************************************************************
795 * SetUrlComponentValueW (Internal)
797 * Helper function for InternetCrackUrlW
804 BOOL
SetUrlComponentValueW(LPWSTR
* lppszComponent
, LPDWORD dwComponentLen
, LPCWSTR lpszStart
, INT len
)
806 TRACE("%s (%d)\n", debugstr_wn(lpszStart
,len
), len
);
808 if (*dwComponentLen
!= 0)
810 if (*lppszComponent
== NULL
)
812 *lppszComponent
= (LPWSTR
)lpszStart
;
813 *dwComponentLen
= len
;
817 INT ncpylen
= min((*dwComponentLen
)-1, len
);
818 strncpyW(*lppszComponent
, lpszStart
, ncpylen
);
819 (*lppszComponent
)[ncpylen
] = '\0';
820 *dwComponentLen
= ncpylen
;
827 /***********************************************************************
828 * InternetCrackUrlW (WININET.@)
830 BOOL WINAPI
InternetCrackUrlW(LPCWSTR lpszUrl
, DWORD dwUrlLength
, DWORD dwFlags
,
831 LPURL_COMPONENTSW lpUC
)
835 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
838 LPWSTR lpszParam
= NULL
;
839 BOOL bIsAbsolute
= FALSE
;
840 LPWSTR lpszap
= (WCHAR
*)lpszUrl
;
841 LPWSTR lpszcp
= NULL
;
842 WCHAR lpszSeparators
[3]={';','?',0};
843 WCHAR lpszSlash
[2]={'/',0};
845 dwUrlLength
=strlenW(lpszUrl
);
849 /* Determine if the URI is absolute. */
850 while (*lpszap
!= '\0')
852 if (isalnumW(*lpszap
))
857 if ((*lpszap
== ':') && (lpszap
- lpszUrl
>= 2))
864 lpszcp
= (LPWSTR
)lpszUrl
; /* Relative url */
871 lpszParam
= strpbrkW(lpszap
, lpszSeparators
);
872 if (lpszParam
!= NULL
)
874 if (!SetUrlComponentValueW(&lpUC
->lpszExtraInfo
, &lpUC
->dwExtraInfoLength
,
875 lpszParam
, dwUrlLength
-(lpszParam
-lpszUrl
)))
881 if (bIsAbsolute
) /* Parse <protocol>:[//<net_loc>] */
884 WCHAR wszAbout
[]={'a','b','o','u','t',':',0};
886 /* Get scheme first. */
887 lpUC
->nScheme
= GetInternetSchemeW(lpszUrl
, lpszcp
- lpszUrl
);
888 if (!SetUrlComponentValueW(&lpUC
->lpszScheme
, &lpUC
->dwSchemeLength
,
889 lpszUrl
, lpszcp
- lpszUrl
))
892 /* Eat ':' in protocol. */
895 /* if the scheme is "about", there is no host */
896 if(strncmpW(wszAbout
,lpszUrl
, lpszcp
- lpszUrl
)==0)
898 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
899 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
900 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
, NULL
, 0);
905 /* Skip over slashes. */
917 lpszNetLoc
= strpbrkW(lpszcp
, lpszSlash
);
921 lpszNetLoc
= min(lpszNetLoc
, lpszParam
);
923 lpszNetLoc
= lpszParam
;
925 else if (!lpszNetLoc
)
926 lpszNetLoc
= lpszcp
+ dwUrlLength
-(lpszcp
-lpszUrl
);
934 /* [<user>[<:password>]@]<host>[:<port>] */
935 /* First find the user and password if they exist */
937 lpszHost
= strchrW(lpszcp
, '@');
938 if (lpszHost
== NULL
|| lpszHost
> lpszNetLoc
)
940 /* username and password not specified. */
941 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
, NULL
, 0);
942 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
, NULL
, 0);
944 else /* Parse out username and password */
946 LPWSTR lpszUser
= lpszcp
;
947 LPWSTR lpszPasswd
= lpszHost
;
949 while (lpszcp
< lpszHost
)
957 SetUrlComponentValueW(&lpUC
->lpszUserName
, &lpUC
->dwUserNameLength
,
958 lpszUser
, lpszPasswd
- lpszUser
);
960 if (lpszPasswd
!= lpszHost
)
962 SetUrlComponentValueW(&lpUC
->lpszPassword
, &lpUC
->dwPasswordLength
,
963 lpszPasswd
== lpszHost
? NULL
: lpszPasswd
,
964 lpszHost
- lpszPasswd
);
966 lpszcp
++; /* Advance to beginning of host */
969 /* Parse <host><:port> */
972 lpszPort
= lpszNetLoc
;
974 /* special case for res:// URLs: there is no port here, so the host is the
975 entire string up to the first '/' */
976 if(lpUC
->nScheme
==INTERNET_SCHEME_RES
)
978 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
979 lpszHost
, lpszPort
- lpszHost
);
985 while (lpszcp
< lpszNetLoc
)
993 /* If the scheme is "file" and the host is just one letter, it's not a host */
994 if(lpUC
->nScheme
==INTERNET_SCHEME_FILE
&& (lpszPort
-lpszHost
)==1)
997 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1003 SetUrlComponentValueW(&lpUC
->lpszHostName
, &lpUC
->dwHostNameLength
,
1004 lpszHost
, lpszPort
- lpszHost
);
1005 if (lpszPort
!= lpszNetLoc
)
1006 lpUC
->nPort
= atoiW(++lpszPort
);
1015 /* Here lpszcp points to:
1017 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1018 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1020 if (lpszcp
!= 0 && *lpszcp
!= '\0' && (!lpszParam
|| lpszcp
< lpszParam
))
1024 /* Only truncate the parameter list if it's already been saved
1025 * in lpUC->lpszExtraInfo.
1027 if (lpszParam
&& lpUC
->dwExtraInfoLength
)
1028 len
= lpszParam
- lpszcp
;
1031 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1032 * newlines if necessary.
1034 LPWSTR lpsznewline
= strchrW(lpszcp
, '\n');
1035 if (lpsznewline
!= NULL
)
1036 len
= lpsznewline
- lpszcp
;
1038 len
= dwUrlLength
-(lpszcp
-lpszUrl
);
1041 if (!SetUrlComponentValueW(&lpUC
->lpszUrlPath
, &lpUC
->dwUrlPathLength
,
1047 lpUC
->dwUrlPathLength
= 0;
1050 TRACE("%s: host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl
,dwUrlLength
),
1051 debugstr_wn(lpUC
->lpszHostName
,lpUC
->dwHostNameLength
),
1052 debugstr_wn(lpUC
->lpszUrlPath
,lpUC
->dwUrlPathLength
),
1053 debugstr_wn(lpUC
->lpszExtraInfo
,lpUC
->dwExtraInfoLength
));
1058 /***********************************************************************
1059 * InternetAttemptConnect (WININET.@)
1061 * Attempt to make a connection to the internet
1064 * ERROR_SUCCESS on success
1065 * Error value on failure
1068 DWORD WINAPI
InternetAttemptConnect(DWORD dwReserved
)
1071 return ERROR_SUCCESS
;
1075 /***********************************************************************
1076 * InternetCanonicalizeUrlA (WININET.@)
1078 * Escape unsafe characters and spaces
1085 BOOL WINAPI
InternetCanonicalizeUrlA(LPCSTR lpszUrl
, LPSTR lpszBuffer
,
1086 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
1089 TRACE("%s %p %p %08lx\n",debugstr_a(lpszUrl
), lpszBuffer
,
1090 lpdwBufferLength
, dwFlags
);
1092 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1093 dwFlags
^= ICU_NO_ENCODE
;
1095 dwFlags
|= 0x80000000; /* Don't know what this means */
1097 hr
= UrlCanonicalizeA(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwFlags
);
1099 return (hr
== S_OK
) ? TRUE
: FALSE
;
1102 /***********************************************************************
1103 * InternetCanonicalizeUrlW (WININET.@)
1105 * Escape unsafe characters and spaces
1112 BOOL WINAPI
InternetCanonicalizeUrlW(LPCWSTR lpszUrl
, LPWSTR lpszBuffer
,
1113 LPDWORD lpdwBufferLength
, DWORD dwFlags
)
1116 TRACE("%s %p %p %08lx\n", debugstr_w(lpszUrl
), lpszBuffer
,
1117 lpdwBufferLength
, dwFlags
);
1119 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1120 dwFlags
^= ICU_NO_ENCODE
;
1122 dwFlags
|= 0x80000000; /* Don't know what this means */
1124 hr
= UrlCanonicalizeW(lpszUrl
, lpszBuffer
, lpdwBufferLength
, dwFlags
);
1126 return (hr
== S_OK
) ? TRUE
: FALSE
;
1130 /***********************************************************************
1131 * InternetSetStatusCallback (WININET.@)
1133 * Sets up a callback function which is called as progress is made
1134 * during an operation.
1137 * Previous callback or NULL on success
1138 * INTERNET_INVALID_STATUS_CALLBACK on failure
1141 INTERNET_STATUS_CALLBACK WINAPI
InternetSetStatusCallback(
1142 HINTERNET hInternet
,INTERNET_STATUS_CALLBACK lpfnIntCB
)
1144 INTERNET_STATUS_CALLBACK retVal
;
1145 LPWININETAPPINFOA lpwai
= (LPWININETAPPINFOA
)hInternet
;
1147 TRACE("0x%08lx\n", (ULONG
)hInternet
);
1148 if (lpwai
->hdr
.htype
!= WH_HINIT
)
1149 return INTERNET_INVALID_STATUS_CALLBACK
;
1151 retVal
= lpwai
->lpfnStatusCB
;
1152 lpwai
->lpfnStatusCB
= lpfnIntCB
;
1158 /***********************************************************************
1159 * InternetWriteFile (WININET.@)
1161 * Write data to an open internet file
1168 BOOL WINAPI
InternetWriteFile(HINTERNET hFile
, LPCVOID lpBuffer
,
1169 DWORD dwNumOfBytesToWrite
, LPDWORD lpdwNumOfBytesWritten
)
1171 BOOL retval
= FALSE
;
1173 LPWININETHANDLEHEADER lpwh
= (LPWININETHANDLEHEADER
) hFile
;
1179 switch (lpwh
->htype
)
1182 nSocket
= ((LPWININETHTTPREQA
)hFile
)->nSocketFD
;
1186 nSocket
= ((LPWININETFILE
)hFile
)->nDataSocket
;
1195 int res
= send(nSocket
, lpBuffer
, dwNumOfBytesToWrite
, 0);
1196 retval
= (res
>= 0);
1197 *lpdwNumOfBytesWritten
= retval
? res
: 0;
1204 /***********************************************************************
1205 * InternetReadFile (WININET.@)
1207 * Read data from an open internet file
1214 BOOL WINAPI
InternetReadFile(HINTERNET hFile
, LPVOID lpBuffer
,
1215 DWORD dwNumOfBytesToRead
, LPDWORD dwNumOfBytesRead
)
1217 BOOL retval
= FALSE
;
1219 LPWININETHANDLEHEADER lpwh
= (LPWININETHANDLEHEADER
) hFile
;
1226 switch (lpwh
->htype
)
1229 nSocket
= ((LPWININETHTTPREQA
)hFile
)->nSocketFD
;
1233 nSocket
= ((LPWININETFILE
)hFile
)->nDataSocket
;
1242 int res
= recv(nSocket
, lpBuffer
, dwNumOfBytesToRead
, 0);
1243 retval
= (res
>= 0);
1244 *dwNumOfBytesRead
= retval
? res
: 0;
1249 /***********************************************************************
1250 * InternetReadFileExA (WININET.@)
1252 * Read data from an open internet file
1259 BOOL WINAPI
InternetReadFileExA(HINTERNET hFile
, LPINTERNET_BUFFERSA lpBuffer
,
1260 DWORD dwFlags
, DWORD dwContext
)
1266 /***********************************************************************
1267 * InternetReadFileExW (WININET.@)
1269 * Read data from an open internet file
1276 BOOL WINAPI
InternetReadFileExW(HINTERNET hFile
, LPINTERNET_BUFFERSW lpBuffer
,
1277 DWORD dwFlags
, DWORD dwContext
)
1281 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1285 /***********************************************************************
1286 * INET_QueryOptionHelper (internal)
1288 static BOOL
INET_QueryOptionHelper(BOOL bIsUnicode
, HINTERNET hInternet
, DWORD dwOption
,
1289 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
1291 LPWININETHANDLEHEADER lpwhh
;
1292 BOOL bSuccess
= FALSE
;
1294 TRACE("0x%08lx\n", dwOption
);
1296 if (NULL
== hInternet
)
1298 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
1302 lpwhh
= (LPWININETHANDLEHEADER
) hInternet
;
1306 case INTERNET_OPTION_HANDLE_TYPE
:
1308 ULONG type
= lpwhh
->htype
;
1309 TRACE("INTERNET_OPTION_HANDLE_TYPE: %ld\n", type
);
1311 if (*lpdwBufferLength
< sizeof(ULONG
))
1312 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1315 memcpy(lpBuffer
, &type
, sizeof(ULONG
));
1316 *lpdwBufferLength
= sizeof(ULONG
);
1322 case INTERNET_OPTION_REQUEST_FLAGS
:
1325 TRACE("INTERNET_OPTION_REQUEST_FLAGS: %ld\n", flags
);
1326 if (*lpdwBufferLength
< sizeof(ULONG
))
1327 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1330 memcpy(lpBuffer
, &flags
, sizeof(ULONG
));
1331 *lpdwBufferLength
= sizeof(ULONG
);
1337 case INTERNET_OPTION_URL
:
1338 case INTERNET_OPTION_DATAFILE_NAME
:
1340 ULONG type
= lpwhh
->htype
;
1341 if (type
== WH_HHTTPREQ
)
1343 LPWININETHTTPREQA lpreq
= hInternet
;
1346 sprintf(url
,"http://%s%s",lpreq
->lpszHostName
,lpreq
->lpszPath
);
1347 TRACE("INTERNET_OPTION_URL: %s\n",url
);
1348 if (*lpdwBufferLength
< strlen(url
)+1)
1349 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1354 *lpdwBufferLength
=MultiByteToWideChar(CP_ACP
,0,url
,-1,lpBuffer
,*lpdwBufferLength
);
1358 memcpy(lpBuffer
, url
, strlen(url
)+1);
1359 *lpdwBufferLength
= strlen(url
)+1;
1366 case INTERNET_OPTION_HTTP_VERSION
:
1369 * Presently hardcoded to 1.1
1371 ((HTTP_VERSION_INFO
*)lpBuffer
)->dwMajorVersion
= 1;
1372 ((HTTP_VERSION_INFO
*)lpBuffer
)->dwMinorVersion
= 1;
1378 FIXME("Stub! %ld \n",dwOption
);
1385 /***********************************************************************
1386 * InternetQueryOptionW (WININET.@)
1388 * Queries an options on the specified handle
1395 BOOL WINAPI
InternetQueryOptionW(HINTERNET hInternet
, DWORD dwOption
,
1396 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
1398 return INET_QueryOptionHelper(TRUE
, hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
1401 /***********************************************************************
1402 * InternetQueryOptionA (WININET.@)
1404 * Queries an options on the specified handle
1411 BOOL WINAPI
InternetQueryOptionA(HINTERNET hInternet
, DWORD dwOption
,
1412 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
)
1414 return INET_QueryOptionHelper(FALSE
, hInternet
, dwOption
, lpBuffer
, lpdwBufferLength
);
1418 /***********************************************************************
1419 * InternetSetOptionW (WININET.@)
1421 * Sets an options on the specified handle
1428 BOOL WINAPI
InternetSetOptionW(HINTERNET hInternet
, DWORD dwOption
,
1429 LPVOID lpBuffer
, DWORD dwBufferLength
)
1431 LPWININETHANDLEHEADER lpwhh
;
1433 TRACE("0x%08lx\n", dwOption
);
1435 if (NULL
== hInternet
)
1437 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
1441 lpwhh
= (LPWININETHANDLEHEADER
) hInternet
;
1445 case INTERNET_OPTION_HTTP_VERSION
:
1447 HTTP_VERSION_INFO
* pVersion
=(HTTP_VERSION_INFO
*)lpBuffer
;
1448 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%ld,%ld): STUB\n",pVersion
->dwMajorVersion
,pVersion
->dwMinorVersion
);
1451 case INTERNET_OPTION_ERROR_MASK
:
1453 unsigned long flags
=*(unsigned long*)lpBuffer
;
1454 FIXME("Option INTERNET_OPTION_ERROR_MASK(%ld): STUB\n",flags
);
1457 case INTERNET_OPTION_CODEPAGE
:
1459 unsigned long codepage
=*(unsigned long*)lpBuffer
;
1460 FIXME("Option INTERNET_OPTION_CODEPAGE (%ld): STUB\n",codepage
);
1463 case INTERNET_OPTION_REQUEST_PRIORITY
:
1465 unsigned long priority
=*(unsigned long*)lpBuffer
;
1466 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%ld): STUB\n",priority
);
1470 FIXME("Option %ld STUB\n",dwOption
);
1471 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1479 /***********************************************************************
1480 * InternetSetOptionA (WININET.@)
1482 * Sets an options on the specified handle.
1489 BOOL WINAPI
InternetSetOptionA(HINTERNET hInternet
, DWORD dwOption
,
1490 LPVOID lpBuffer
, DWORD dwBufferLength
)
1492 /* FIXME!!! implement if lpBuffer is a string, dwBufferLength is
1494 return InternetSetOptionW(hInternet
,dwOption
, lpBuffer
,
1499 /***********************************************************************
1500 * InternetGetCookieA (WININET.@)
1502 * Retrieve cookie from the specified url
1509 BOOL WINAPI
InternetGetCookieA(LPCSTR lpszUrl
, LPCSTR lpszCookieName
,
1510 LPSTR lpCookieData
, LPDWORD lpdwSize
)
1513 TRACE("(%s,%s,%p)\n", debugstr_a(lpszUrl
),debugstr_a(lpszCookieName
),
1519 /***********************************************************************
1520 * InternetGetCookieW (WININET.@)
1522 * Retrieve cookie from the specified url
1529 BOOL WINAPI
InternetGetCookieW(LPCSTR lpszUrl
, LPCWSTR lpszCookieName
,
1530 LPWSTR lpCookieData
, LPDWORD lpdwSize
)
1533 TRACE("(%s,%s,%p)\n", debugstr_a(lpszUrl
), debugstr_w(lpszCookieName
),
1539 /***********************************************************************
1540 * InternetSetCookieA (WININET.@)
1542 * Sets cookie for the specified url
1549 BOOL WINAPI
InternetSetCookieA(LPCSTR lpszUrl
, LPCSTR lpszCookieName
,
1550 LPCSTR lpCookieData
)
1553 TRACE("(%s,%s,%s)\n", debugstr_a(lpszUrl
),
1554 debugstr_a(lpszCookieName
), debugstr_a(lpCookieData
));
1559 /***********************************************************************
1560 * InternetSetCookieW (WININET.@)
1562 * Sets cookie for the specified url
1569 BOOL WINAPI
InternetSetCookieW(LPCSTR lpszUrl
, LPCWSTR lpszCookieName
,
1570 LPCWSTR lpCookieData
)
1573 TRACE("(%s,%s,%s)\n", debugstr_a(lpszUrl
),
1574 debugstr_w(lpszCookieName
), debugstr_w(lpCookieData
));
1579 /***********************************************************************
1580 * InternetCheckConnectionA (WININET.@)
1582 * Pings a requested host to check internet connection
1585 * TRUE on success and FALSE on failure. If a failure then
1586 * ERROR_NOT_CONNECTED is placesd into GetLastError
1589 BOOL WINAPI
InternetCheckConnectionA( LPCSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
1592 * this is a kludge which runs the resident ping program and reads the output.
1594 * Anyone have a better idea?
1605 * Crack or set the Address
1607 if (lpszUrl
== NULL
)
1610 * According to the doc we are supost to use the ip for the next
1611 * server in the WnInet internal server database. I have
1612 * no idea what that is or how to get it.
1614 * So someone needs to implement this.
1616 FIXME("Unimplemented with URL of NULL\n");
1621 URL_COMPONENTSA componets
;
1623 ZeroMemory(&componets
,sizeof(URL_COMPONENTSA
));
1624 componets
.lpszHostName
= (LPSTR
)&host
;
1625 componets
.dwHostNameLength
= 1024;
1627 if (!InternetCrackUrlA(lpszUrl
,0,0,&componets
))
1630 TRACE("host name : %s\n",componets
.lpszHostName
);
1634 * Build our ping command
1636 strcpy(command
,"ping -w 1 ");
1637 strcat(command
,host
);
1638 strcat(command
," >/dev/null 2>/dev/null");
1640 TRACE("Ping command is : %s\n",command
);
1642 status
= system(command
);
1644 TRACE("Ping returned a code of %i \n",status
);
1646 /* Ping return code of 0 indicates success */
1653 SetLastError(ERROR_NOT_CONNECTED
);
1659 /***********************************************************************
1660 * InternetCheckConnectionW (WININET.@)
1662 * Pings a requested host to check internet connection
1665 * TRUE on success and FALSE on failure. If a failure then
1666 * ERROR_NOT_CONNECTED is placed into GetLastError
1669 BOOL WINAPI
InternetCheckConnectionW(LPCWSTR lpszUrl
, DWORD dwFlags
, DWORD dwReserved
)
1675 len
= lstrlenW(lpszUrl
)+1;
1676 if (!(szUrl
= (CHAR
*)malloc(len
*sizeof(CHAR
))))
1678 WideCharToMultiByte(CP_ACP
, -1, lpszUrl
, -1, szUrl
, len
, NULL
, NULL
);
1679 rc
= InternetCheckConnectionA((LPCSTR
)szUrl
, dwFlags
, dwReserved
);
1686 /**********************************************************
1687 * InternetOpenUrlA (WININET.@)
1692 * handle of connection or NULL on failure
1694 HINTERNET WINAPI
InternetOpenUrlA(HINTERNET hInternet
, LPCSTR lpszUrl
,
1695 LPCSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD dwContext
)
1697 URL_COMPONENTSA urlComponents
;
1698 char protocol
[32], hostName
[MAXHOSTNAME
], userName
[1024];
1699 char password
[1024], path
[2048], extra
[1024];
1700 HINTERNET client
= NULL
, client1
= NULL
;
1701 urlComponents
.dwStructSize
= sizeof(URL_COMPONENTSA
);
1702 urlComponents
.lpszScheme
= protocol
;
1703 urlComponents
.dwSchemeLength
= 32;
1704 urlComponents
.lpszHostName
= hostName
;
1705 urlComponents
.dwHostNameLength
= MAXHOSTNAME
;
1706 urlComponents
.lpszUserName
= userName
;
1707 urlComponents
.dwUserNameLength
= 1024;
1708 urlComponents
.lpszPassword
= password
;
1709 urlComponents
.dwPasswordLength
= 1024;
1710 urlComponents
.lpszUrlPath
= path
;
1711 urlComponents
.dwUrlPathLength
= 2048;
1712 urlComponents
.lpszExtraInfo
= extra
;
1713 urlComponents
.dwExtraInfoLength
= 1024;
1714 if(!InternetCrackUrlA(lpszUrl
, strlen(lpszUrl
), 0, &urlComponents
))
1716 switch(urlComponents
.nScheme
) {
1717 case INTERNET_SCHEME_FTP
:
1718 if(urlComponents
.nPort
== 0)
1719 urlComponents
.nPort
= INTERNET_DEFAULT_FTP_PORT
;
1720 client
= InternetConnectA(hInternet
, hostName
, urlComponents
.nPort
,
1721 userName
, password
, INTERNET_SERVICE_FTP
, dwFlags
, dwContext
);
1722 return FtpOpenFileA(client
, path
, GENERIC_READ
, dwFlags
, dwContext
);
1724 case INTERNET_SCHEME_HTTP
:
1725 case INTERNET_SCHEME_HTTPS
:
1727 LPCSTR accept
[2] = { "*/*", NULL
};
1728 char *hostreq
=(char*)malloc(strlen(hostName
)+9);
1729 sprintf(hostreq
, "Host: %s\r\n", hostName
);
1730 if(urlComponents
.nPort
== 0) {
1731 if(urlComponents
.nScheme
== INTERNET_SCHEME_HTTP
)
1732 urlComponents
.nPort
= INTERNET_DEFAULT_HTTP_PORT
;
1734 urlComponents
.nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
1736 client
= InternetConnectA(hInternet
, hostName
, urlComponents
.nPort
, userName
,
1737 password
, INTERNET_SERVICE_HTTP
, dwFlags
, dwContext
);
1740 client1
= HttpOpenRequestA(hInternet
, NULL
, path
, NULL
, NULL
, accept
, dwFlags
, dwContext
);
1741 if(client1
== NULL
) {
1742 InternetCloseHandle(client
);
1745 HttpAddRequestHeadersA(client1
, lpszHeaders
, dwHeadersLength
, HTTP_ADDREQ_FLAG_ADD
);
1746 HttpAddRequestHeadersA(client1
, hostreq
, -1L, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
1747 if(!HttpSendRequestA(client1
, NULL
, 0, NULL
, 0)) {
1748 InternetCloseHandle(client1
);
1749 InternetCloseHandle(client
);
1755 case INTERNET_SCHEME_GOPHER
:
1756 /* gopher doesn't seem to be implemented in wine, but it's supposed
1757 * to be supported by InternetOpenUrlA. */
1762 InternetCloseHandle(client
);
1766 /**********************************************************
1767 * InternetOpenUrlW (WININET.@)
1772 * handle of connection or NULL on failure
1774 HINTERNET WINAPI
InternetOpenUrlW(HINTERNET hInternet
, LPCWSTR lpszUrl
,
1775 LPCWSTR lpszHeaders
, DWORD dwHeadersLength
, DWORD dwFlags
, DWORD dwContext
)
1777 HINTERNET rc
= (HINTERNET
)NULL
;
1779 INT lenUrl
= lstrlenW(lpszUrl
)+1;
1780 INT lenHeaders
= lstrlenW(lpszHeaders
)+1;
1781 CHAR
*szUrl
= (CHAR
*)malloc(lenUrl
*sizeof(CHAR
));
1782 CHAR
*szHeaders
= (CHAR
*)malloc(lenHeaders
*sizeof(CHAR
));
1784 if (!szUrl
|| !szHeaders
)
1790 return (HINTERNET
)NULL
;
1793 WideCharToMultiByte(CP_ACP
, -1, lpszUrl
, -1, szUrl
, lenUrl
,
1795 WideCharToMultiByte(CP_ACP
, -1, lpszHeaders
, -1, szHeaders
, lenHeaders
,
1798 rc
= InternetOpenUrlA(hInternet
, szUrl
, szHeaders
,
1799 dwHeadersLength
, dwFlags
, dwContext
);
1808 /***********************************************************************
1809 * INTERNET_SetLastError (internal)
1811 * Set last thread specific error
1816 void INTERNET_SetLastError(DWORD dwError
)
1818 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
1820 SetLastError(dwError
);
1822 lpwite
->dwError
= dwError
;
1826 /***********************************************************************
1827 * INTERNET_GetLastError (internal)
1829 * Get last thread specific error
1834 DWORD
INTERNET_GetLastError()
1836 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
1837 return lpwite
->dwError
;
1841 /***********************************************************************
1842 * INTERNET_WorkerThreadFunc (internal)
1844 * Worker thread execution function
1849 DWORD
INTERNET_WorkerThreadFunc(LPVOID
*lpvParam
)
1856 INTERNET_ExecuteWork();
1859 dwWaitRes
= WaitForMultipleObjects(2, hEventArray
, FALSE
, MAX_IDLE_WORKER
);
1861 if (dwWaitRes
== WAIT_OBJECT_0
+ 1)
1862 INTERNET_ExecuteWork();
1866 InterlockedIncrement(&dwNumIdleThreads
);
1869 InterlockedDecrement(&dwNumIdleThreads
);
1870 InterlockedDecrement(&dwNumThreads
);
1871 TRACE("Worker thread exiting\n");
1876 /***********************************************************************
1877 * INTERNET_InsertWorkRequest (internal)
1879 * Insert work request into queue
1884 BOOL
INTERNET_InsertWorkRequest(LPWORKREQUEST lpWorkRequest
)
1886 BOOL bSuccess
= FALSE
;
1887 LPWORKREQUEST lpNewRequest
;
1891 lpNewRequest
= HeapAlloc(GetProcessHeap(), 0, sizeof(WORKREQUEST
));
1894 memcpy(lpNewRequest
, lpWorkRequest
, sizeof(WORKREQUEST
));
1895 lpNewRequest
->prev
= NULL
;
1897 EnterCriticalSection(&csQueue
);
1899 lpNewRequest
->next
= lpWorkQueueTail
;
1900 if (lpWorkQueueTail
)
1901 lpWorkQueueTail
->prev
= lpNewRequest
;
1902 lpWorkQueueTail
= lpNewRequest
;
1903 if (!lpHeadWorkQueue
)
1904 lpHeadWorkQueue
= lpWorkQueueTail
;
1906 LeaveCriticalSection(&csQueue
);
1909 InterlockedIncrement(&dwNumJobs
);
1916 /***********************************************************************
1917 * INTERNET_GetWorkRequest (internal)
1919 * Retrieves work request from queue
1924 BOOL
INTERNET_GetWorkRequest(LPWORKREQUEST lpWorkRequest
)
1926 BOOL bSuccess
= FALSE
;
1927 LPWORKREQUEST lpRequest
= NULL
;
1931 EnterCriticalSection(&csQueue
);
1933 if (lpHeadWorkQueue
)
1935 lpRequest
= lpHeadWorkQueue
;
1936 lpHeadWorkQueue
= lpHeadWorkQueue
->prev
;
1937 if (lpRequest
== lpWorkQueueTail
)
1938 lpWorkQueueTail
= lpHeadWorkQueue
;
1941 LeaveCriticalSection(&csQueue
);
1945 memcpy(lpWorkRequest
, lpRequest
, sizeof(WORKREQUEST
));
1946 HeapFree(GetProcessHeap(), 0, lpRequest
);
1948 InterlockedDecrement(&dwNumJobs
);
1955 /***********************************************************************
1956 * INTERNET_AsyncCall (internal)
1958 * Retrieves work request from queue
1963 BOOL
INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest
)
1967 BOOL bSuccess
= FALSE
;
1971 if (InterlockedDecrement(&dwNumIdleThreads
) < 0)
1973 InterlockedIncrement(&dwNumIdleThreads
);
1975 if (InterlockedIncrement(&dwNumThreads
) > MAX_WORKER_THREADS
||
1976 !(hThread
= CreateThread(NULL
, 0,
1977 (LPTHREAD_START_ROUTINE
)INTERNET_WorkerThreadFunc
, NULL
, 0, &dwTID
)))
1979 InterlockedDecrement(&dwNumThreads
);
1980 INTERNET_SetLastError(ERROR_INTERNET_ASYNC_THREAD_FAILED
);
1984 TRACE("Created new thread\n");
1988 INTERNET_InsertWorkRequest(lpWorkRequest
);
1989 SetEvent(hWorkEvent
);
1997 /***********************************************************************
1998 * INTERNET_ExecuteWork (internal)
2003 VOID
INTERNET_ExecuteWork()
2005 WORKREQUEST workRequest
;
2009 if (INTERNET_GetWorkRequest(&workRequest
))
2011 TRACE("Got work %d\n", workRequest
.asyncall
);
2012 switch (workRequest
.asyncall
)
2015 FTP_FtpPutFileA((HINTERNET
)workRequest
.HFTPSESSION
, (LPCSTR
)workRequest
.LPSZLOCALFILE
,
2016 (LPCSTR
)workRequest
.LPSZNEWREMOTEFILE
, workRequest
.DWFLAGS
, workRequest
.DWCONTEXT
);
2017 HeapFree(GetProcessHeap(), 0, (LPVOID
)workRequest
.LPSZLOCALFILE
);
2018 HeapFree(GetProcessHeap(), 0, (LPVOID
)workRequest
.LPSZNEWREMOTEFILE
);
2021 case FTPSETCURRENTDIRECTORYA
:
2022 FTP_FtpSetCurrentDirectoryA((HINTERNET
)workRequest
.HFTPSESSION
,
2023 (LPCSTR
)workRequest
.LPSZDIRECTORY
);
2024 HeapFree(GetProcessHeap(), 0, (LPVOID
)workRequest
.LPSZDIRECTORY
);
2027 case FTPCREATEDIRECTORYA
:
2028 FTP_FtpCreateDirectoryA((HINTERNET
)workRequest
.HFTPSESSION
,
2029 (LPCSTR
)workRequest
.LPSZDIRECTORY
);
2030 HeapFree(GetProcessHeap(), 0, (LPVOID
)workRequest
.LPSZDIRECTORY
);
2033 case FTPFINDFIRSTFILEA
:
2034 FTP_FtpFindFirstFileA((HINTERNET
)workRequest
.HFTPSESSION
,
2035 (LPCSTR
)workRequest
.LPSZSEARCHFILE
,
2036 (LPWIN32_FIND_DATAA
)workRequest
.LPFINDFILEDATA
, workRequest
.DWFLAGS
,
2037 workRequest
.DWCONTEXT
);
2038 HeapFree(GetProcessHeap(), 0, (LPVOID
)workRequest
.LPSZSEARCHFILE
);
2041 case FTPGETCURRENTDIRECTORYA
:
2042 FTP_FtpGetCurrentDirectoryA((HINTERNET
)workRequest
.HFTPSESSION
,
2043 (LPSTR
)workRequest
.LPSZDIRECTORY
, (LPDWORD
)workRequest
.LPDWDIRECTORY
);
2047 FTP_FtpOpenFileA((HINTERNET
)workRequest
.HFTPSESSION
,
2048 (LPCSTR
)workRequest
.LPSZFILENAME
,
2049 workRequest
.FDWACCESS
,
2050 workRequest
.DWFLAGS
,
2051 workRequest
.DWCONTEXT
);
2052 HeapFree(GetProcessHeap(), 0, (LPVOID
)workRequest
.LPSZFILENAME
);
2056 FTP_FtpGetFileA((HINTERNET
)workRequest
.HFTPSESSION
,
2057 (LPCSTR
)workRequest
.LPSZREMOTEFILE
,
2058 (LPCSTR
)workRequest
.LPSZNEWFILE
,
2059 (BOOL
)workRequest
.FFAILIFEXISTS
,
2060 workRequest
.DWLOCALFLAGSATTRIBUTE
,
2061 workRequest
.DWFLAGS
,
2062 workRequest
.DWCONTEXT
);
2063 HeapFree(GetProcessHeap(), 0, (LPVOID
)workRequest
.LPSZREMOTEFILE
);
2064 HeapFree(GetProcessHeap(), 0, (LPVOID
)workRequest
.LPSZNEWFILE
);
2067 case FTPDELETEFILEA
:
2068 FTP_FtpDeleteFileA((HINTERNET
)workRequest
.HFTPSESSION
,
2069 (LPCSTR
)workRequest
.LPSZFILENAME
);
2070 HeapFree(GetProcessHeap(), 0, (LPVOID
)workRequest
.LPSZFILENAME
);
2073 case FTPREMOVEDIRECTORYA
:
2074 FTP_FtpRemoveDirectoryA((HINTERNET
)workRequest
.HFTPSESSION
,
2075 (LPCSTR
)workRequest
.LPSZDIRECTORY
);
2076 HeapFree(GetProcessHeap(), 0, (LPVOID
)workRequest
.LPSZDIRECTORY
);
2079 case FTPRENAMEFILEA
:
2080 FTP_FtpRenameFileA((HINTERNET
)workRequest
.HFTPSESSION
,
2081 (LPCSTR
)workRequest
.LPSZSRCFILE
,
2082 (LPCSTR
)workRequest
.LPSZDESTFILE
);
2083 HeapFree(GetProcessHeap(), 0, (LPVOID
)workRequest
.LPSZSRCFILE
);
2084 HeapFree(GetProcessHeap(), 0, (LPVOID
)workRequest
.LPSZDESTFILE
);
2087 case INTERNETFINDNEXTA
:
2088 INTERNET_FindNextFileA((HINTERNET
)workRequest
.HFTPSESSION
,
2089 (LPWIN32_FIND_DATAA
)workRequest
.LPFINDFILEDATA
);
2092 case HTTPSENDREQUESTA
:
2093 HTTP_HttpSendRequestA((HINTERNET
)workRequest
.HFTPSESSION
,
2094 (LPCSTR
)workRequest
.LPSZHEADER
,
2095 workRequest
.DWHEADERLENGTH
,
2096 (LPVOID
)workRequest
.LPOPTIONAL
,
2097 workRequest
.DWOPTIONALLENGTH
);
2098 HeapFree(GetProcessHeap(), 0, (LPVOID
)workRequest
.LPSZHEADER
);
2101 case HTTPOPENREQUESTA
:
2102 HTTP_HttpOpenRequestA((HINTERNET
)workRequest
.HFTPSESSION
,
2103 (LPCSTR
)workRequest
.LPSZVERB
,
2104 (LPCSTR
)workRequest
.LPSZOBJECTNAME
,
2105 (LPCSTR
)workRequest
.LPSZVERSION
,
2106 (LPCSTR
)workRequest
.LPSZREFERRER
,
2107 (LPCSTR
*)workRequest
.LPSZACCEPTTYPES
,
2108 workRequest
.DWFLAGS
,
2109 workRequest
.DWCONTEXT
);
2110 HeapFree(GetProcessHeap(), 0, (LPVOID
)workRequest
.LPSZVERB
);
2111 HeapFree(GetProcessHeap(), 0, (LPVOID
)workRequest
.LPSZOBJECTNAME
);
2112 HeapFree(GetProcessHeap(), 0, (LPVOID
)workRequest
.LPSZVERSION
);
2113 HeapFree(GetProcessHeap(), 0, (LPVOID
)workRequest
.LPSZREFERRER
);
2117 SendAsyncCallbackInt((LPWININETAPPINFOA
)workRequest
.param1
,
2118 (HINTERNET
)workRequest
.param2
, workRequest
.param3
,
2119 workRequest
.param4
, (LPVOID
)workRequest
.param5
,
2120 workRequest
.param6
);
2127 /***********************************************************************
2128 * INTERNET_GetResponseBuffer
2133 LPSTR
INTERNET_GetResponseBuffer()
2135 LPWITHREADERROR lpwite
= (LPWITHREADERROR
)TlsGetValue(g_dwTlsErrIndex
);
2137 return lpwite
->response
;
2141 /***********************************************************************
2142 * INTERNET_GetNextLine (internal)
2144 * Parse next line in directory string listing
2147 * Pointer to beginning of next line
2152 LPSTR
INTERNET_GetNextLine(INT nSocket
, LPSTR lpszBuffer
, LPDWORD dwBuffer
)
2156 BOOL bSuccess
= FALSE
;
2162 FD_SET(nSocket
, &infd
);
2163 tv
.tv_sec
=RESPONSE_TIMEOUT
;
2166 while (nRecv
< *dwBuffer
)
2168 if (select(nSocket
+1,&infd
,NULL
,NULL
,&tv
) > 0)
2170 if (recv(nSocket
, &lpszBuffer
[nRecv
], 1, 0) <= 0)
2172 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS
);
2176 if (lpszBuffer
[nRecv
] == '\n')
2181 if (lpszBuffer
[nRecv
] != '\r')
2186 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT
);
2194 lpszBuffer
[nRecv
] = '\0';
2195 *dwBuffer
= nRecv
- 1;
2196 TRACE(":%d %s\n", nRecv
, lpszBuffer
);
2205 /***********************************************************************
2208 BOOL WINAPI
InternetQueryDataAvailable( HINTERNET hFile
,
2209 LPDWORD lpdwNumberOfBytesAvailble
,
2210 DWORD dwFlags
, DWORD dwConext
)
2212 LPWININETHTTPREQA lpwhr
= (LPWININETHTTPREQA
) hFile
;
2219 SetLastError(ERROR_NO_MORE_FILES
);
2223 TRACE("--> %p %i %i\n",lpwhr
,lpwhr
->hdr
.htype
,lpwhr
->nSocketFD
);
2225 switch (lpwhr
->hdr
.htype
)
2228 nSocket
= lpwhr
->nSocketFD
;
2239 retval
= recv(nSocket
,buffer
,4048,MSG_PEEK
);
2243 SetLastError(ERROR_NO_MORE_FILES
);
2246 if (lpdwNumberOfBytesAvailble
)
2248 (*lpdwNumberOfBytesAvailble
) = retval
;
2251 TRACE("<-- %i\n",retval
);
2256 /***********************************************************************
2259 BOOL WINAPI
InternetLockRequestFile( HINTERNET hInternet
, HANDLE
2266 BOOL WINAPI
InternetUnlockRequestFile( HANDLE hLockHandle
)
2273 /***********************************************************************
2276 * On windows this function is supposed to dial the default internet
2277 * connection. We don't want to have Wine dial out to the internet so
2278 * we return TRUE by default. It might be nice to check if we are connected.
2285 BOOL WINAPI
InternetAutoDial(DWORD dwFlags
, HWND hwndParent
)
2289 /* Tell that we are connected to the internet. */
2293 /***********************************************************************
2294 * InternetAutoDialHangup
2296 * Hangs up an connection made with InternetAutoDial
2305 BOOL WINAPI
InternetAutodialHangup(DWORD dwReserved
)
2309 /* we didn't dial, we don't disconnect */
2313 /***********************************************************************
2315 * InternetCombineUrlA
2317 * Combine a base URL with a relative URL
2325 BOOL WINAPI
InternetCombineUrlA(LPCSTR lpszBaseUrl
, LPCSTR lpszRelativeUrl
,
2326 LPSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
2330 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
2331 dwFlags
^= ICU_NO_ENCODE
;
2332 hr
=UrlCombineA(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);
2337 /***********************************************************************
2339 * InternetCombineUrlW
2341 * Combine a base URL with a relative URL
2349 BOOL WINAPI
InternetCombineUrlW(LPCWSTR lpszBaseUrl
, LPCWSTR lpszRelativeUrl
,
2350 LPWSTR lpszBuffer
, LPDWORD lpdwBufferLength
,
2354 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
2355 dwFlags
^= ICU_NO_ENCODE
;
2356 hr
=UrlCombineW(lpszBaseUrl
,lpszRelativeUrl
,lpszBuffer
,lpdwBufferLength
,dwFlags
);