4 * Copyright 1999 Corel Corporation
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #ifndef _WINE_INTERNET_H_
24 #define _WINE_INTERNET_H_
26 #ifndef __WINE_CONFIG_H
27 # error You must include config.h to use this header
30 #include "wine/unicode.h"
31 #include "wine/list.h"
37 #ifdef HAVE_NETINET_IN_H
38 # include <sys/types.h>
39 # include <netinet/in.h>
41 #ifdef HAVE_SYS_SOCKET_H
42 # include <sys/socket.h>
45 #if !defined(__MINGW32__) && !defined(_MSC_VER)
46 #define closesocket close
47 #define ioctlsocket ioctl
48 #endif /* __MINGW32__ */
50 extern HMODULE WININET_hModule;
52 /* used for netconnection.c stuff */
59 } WININET_NETCONNECTION;
61 static inline LPWSTR heap_strdupW(LPCWSTR str)
68 size = (strlenW(str)+1)*sizeof(WCHAR);
69 ret = HeapAlloc(GetProcessHeap(), 0, size);
71 memcpy(ret, str, size);
77 static inline LPWSTR heap_strndupW(LPCWSTR str, UINT max_len)
85 for(len=0; len<max_len; len++)
89 ret = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*(len+1));
91 memcpy(ret, str, sizeof(WCHAR)*len);
98 static inline WCHAR *heap_strdupAtoW(const char *str)
105 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
106 ret = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
108 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
114 static inline char *heap_strdupWtoA(LPCWSTR str)
119 DWORD size = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
120 ret = HeapAlloc(GetProcessHeap(), 0, size);
122 WideCharToMultiByte(CP_ACP, 0, str, -1, ret, size, NULL, NULL);
128 static inline void WININET_find_data_WtoA(LPWIN32_FIND_DATAW dataW, LPWIN32_FIND_DATAA dataA)
130 dataA->dwFileAttributes = dataW->dwFileAttributes;
131 dataA->ftCreationTime = dataW->ftCreationTime;
132 dataA->ftLastAccessTime = dataW->ftLastAccessTime;
133 dataA->ftLastWriteTime = dataW->ftLastWriteTime;
134 dataA->nFileSizeHigh = dataW->nFileSizeHigh;
135 dataA->nFileSizeLow = dataW->nFileSizeLow;
136 dataA->dwReserved0 = dataW->dwReserved0;
137 dataA->dwReserved1 = dataW->dwReserved1;
138 WideCharToMultiByte(CP_ACP, 0, dataW->cFileName, -1,
139 dataA->cFileName, sizeof(dataA->cFileName),
141 WideCharToMultiByte(CP_ACP, 0, dataW->cAlternateFileName, -1,
142 dataA->cAlternateFileName, sizeof(dataA->cAlternateFileName),
148 WH_HINIT = INTERNET_HANDLE_TYPE_INTERNET,
149 WH_HFTPSESSION = INTERNET_HANDLE_TYPE_CONNECT_FTP,
150 WH_HGOPHERSESSION = INTERNET_HANDLE_TYPE_CONNECT_GOPHER,
151 WH_HHTTPSESSION = INTERNET_HANDLE_TYPE_CONNECT_HTTP,
152 WH_HFILE = INTERNET_HANDLE_TYPE_FTP_FILE,
153 WH_HFTPFINDNEXT = INTERNET_HANDLE_TYPE_FTP_FIND,
154 WH_HHTTPREQ = INTERNET_HANDLE_TYPE_HTTP_REQUEST,
157 #define INET_OPENURL 0x0001
158 #define INET_CALLBACKW 0x0002
160 typedef struct _object_header_t object_header_t;
163 void (*Destroy)(object_header_t*);
164 void (*CloseConnection)(object_header_t*);
165 DWORD (*QueryOption)(object_header_t*,DWORD,void*,DWORD*,BOOL);
166 DWORD (*SetOption)(object_header_t*,DWORD,void*,DWORD);
167 DWORD (*ReadFile)(object_header_t*,void*,DWORD,DWORD*);
168 DWORD (*ReadFileExA)(object_header_t*,INTERNET_BUFFERSA*,DWORD,DWORD_PTR);
169 DWORD (*ReadFileExW)(object_header_t*,INTERNET_BUFFERSW*,DWORD,DWORD_PTR);
170 DWORD (*WriteFile)(object_header_t*,const void*,DWORD,DWORD*);
171 DWORD (*QueryDataAvailable)(object_header_t*,DWORD*,DWORD,DWORD_PTR);
172 DWORD (*FindNextFileW)(object_header_t*,void*);
175 #define INTERNET_HANDLE_IN_USE 1
177 struct _object_header_t
180 const object_vtbl_t *vtbl;
186 DWORD dwInternalFlags;
188 INTERNET_STATUS_CALLBACK lpfnStatusCB;
190 struct list children;
199 LPWSTR lpszProxyBypass;
200 LPWSTR lpszProxyUsername;
201 LPWSTR lpszProxyPassword;
209 appinfo_t *lpAppInfo;
210 LPWSTR lpszHostName; /* the final destination of the request */
211 LPWSTR lpszServerName; /* the name of the server we directly connect to */
214 INTERNET_PORT nHostPort; /* the final destination port of the request */
215 INTERNET_PORT nServerPort; /* the port of the server we directly connect to */
216 struct sockaddr_storage socketAddress;
220 #define HDR_ISREQUEST 0x0001
221 #define HDR_COMMADELIMITED 0x0002
222 #define HDR_SEMIDELIMITED 0x0004
230 } HTTPHEADERW, *LPHTTPHEADERW;
235 typedef struct gzip_stream_t gzip_stream_t;
240 http_session_t *lpHttpSession;
243 LPWSTR lpszRawHeaders;
244 WININET_NETCONNECTION netConnection;
246 LPWSTR lpszStatusText;
247 DWORD dwBytesToWrite;
248 DWORD dwBytesWritten;
249 HTTPHEADERW *pCustHeaders;
252 LPWSTR lpszCacheFile;
253 struct HttpAuthInfo *pAuthInfo;
254 struct HttpAuthInfo *pProxyAuthInfo;
256 CRITICAL_SECTION read_section; /* section to protect the following fields */
257 DWORD dwContentLength; /* total number of bytes to be read */
258 DWORD dwContentRead; /* bytes of the content read so far */
259 BOOL read_chunked; /* are we reading in chunked mode? */
260 DWORD read_pos; /* current read position in read_buf */
261 DWORD read_size; /* valid data size in read_buf */
262 BYTE read_buf[4096]; /* buffer for already read but not returned data */
265 gzip_stream_t *gzip_stream;
270 struct WORKREQ_FTPPUTFILEW
272 LPWSTR lpszLocalFile;
273 LPWSTR lpszNewRemoteFile;
278 struct WORKREQ_FTPSETCURRENTDIRECTORYW
280 LPWSTR lpszDirectory;
283 struct WORKREQ_FTPCREATEDIRECTORYW
285 LPWSTR lpszDirectory;
288 struct WORKREQ_FTPFINDFIRSTFILEW
290 LPWSTR lpszSearchFile;
291 LPWIN32_FIND_DATAW lpFindFileData;
296 struct WORKREQ_FTPGETCURRENTDIRECTORYW
298 LPWSTR lpszDirectory;
299 DWORD *lpdwDirectory;
302 struct WORKREQ_FTPOPENFILEW
310 struct WORKREQ_FTPGETFILEW
312 LPWSTR lpszRemoteFile;
315 DWORD dwLocalFlagsAttribute;
320 struct WORKREQ_FTPDELETEFILEW
325 struct WORKREQ_FTPREMOVEDIRECTORYW
327 LPWSTR lpszDirectory;
330 struct WORKREQ_FTPRENAMEFILEW
336 struct WORKREQ_FTPFINDNEXTW
338 LPWIN32_FIND_DATAW lpFindFileData;
341 struct WORKREQ_HTTPSENDREQUESTW
344 DWORD dwHeaderLength;
346 DWORD dwOptionalLength;
347 DWORD dwContentLength;
351 struct WORKREQ_HTTPENDREQUESTW
357 struct WORKREQ_SENDCALLBACK
360 DWORD dwInternetStatus;
361 LPVOID lpvStatusInfo;
362 DWORD dwStatusInfoLength;
365 struct WORKREQ_INTERNETOPENURLW
370 DWORD dwHeadersLength;
375 struct WORKREQ_INTERNETREADFILEEXA
377 LPINTERNET_BUFFERSA lpBuffersOut;
380 struct WORKREQ_INTERNETREADFILEEXW
382 LPINTERNET_BUFFERSW lpBuffersOut;
385 typedef struct WORKREQ
387 void (*asyncproc)(struct WORKREQ*);
388 object_header_t *hdr;
391 struct WORKREQ_FTPPUTFILEW FtpPutFileW;
392 struct WORKREQ_FTPSETCURRENTDIRECTORYW FtpSetCurrentDirectoryW;
393 struct WORKREQ_FTPCREATEDIRECTORYW FtpCreateDirectoryW;
394 struct WORKREQ_FTPFINDFIRSTFILEW FtpFindFirstFileW;
395 struct WORKREQ_FTPGETCURRENTDIRECTORYW FtpGetCurrentDirectoryW;
396 struct WORKREQ_FTPOPENFILEW FtpOpenFileW;
397 struct WORKREQ_FTPGETFILEW FtpGetFileW;
398 struct WORKREQ_FTPDELETEFILEW FtpDeleteFileW;
399 struct WORKREQ_FTPREMOVEDIRECTORYW FtpRemoveDirectoryW;
400 struct WORKREQ_FTPRENAMEFILEW FtpRenameFileW;
401 struct WORKREQ_FTPFINDNEXTW FtpFindNextW;
402 struct WORKREQ_HTTPSENDREQUESTW HttpSendRequestW;
403 struct WORKREQ_HTTPENDREQUESTW HttpEndRequestW;
404 struct WORKREQ_SENDCALLBACK SendCallback;
405 struct WORKREQ_INTERNETOPENURLW InternetOpenUrlW;
406 struct WORKREQ_INTERNETREADFILEEXA InternetReadFileExA;
407 struct WORKREQ_INTERNETREADFILEEXW InternetReadFileExW;
410 } WORKREQUEST, *LPWORKREQUEST;
412 HINTERNET WININET_AllocHandle( object_header_t *info );
413 object_header_t *WININET_GetObject( HINTERNET hinternet );
414 object_header_t *WININET_AddRef( object_header_t *info );
415 BOOL WININET_Release( object_header_t *info );
416 BOOL WININET_FreeHandle( HINTERNET hinternet );
418 DWORD INET_QueryOption( object_header_t *, DWORD, void *, DWORD *, BOOL );
420 time_t ConvertTimeString(LPCWSTR asctime);
422 HINTERNET FTP_Connect(appinfo_t *hIC, LPCWSTR lpszServerName,
423 INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
424 LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
425 DWORD dwInternalFlags);
427 DWORD HTTP_Connect(appinfo_t*,LPCWSTR,
428 INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
429 LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
430 DWORD dwInternalFlags, HINTERNET*);
432 BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
433 struct sockaddr *psa, socklen_t *sa_len);
435 void INTERNET_SetLastError(DWORD dwError);
436 DWORD INTERNET_GetLastError(void);
437 DWORD INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest);
438 LPSTR INTERNET_GetResponseBuffer(void);
439 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen);
441 VOID SendAsyncCallback(object_header_t *hdr, DWORD_PTR dwContext,
442 DWORD dwInternetStatus, LPVOID lpvStatusInfo,
443 DWORD dwStatusInfoLength);
445 VOID INTERNET_SendCallback(object_header_t *hdr, DWORD_PTR dwContext,
446 DWORD dwInternetStatus, LPVOID lpvStatusInfo,
447 DWORD dwStatusInfoLength);
448 BOOL INTERNET_FindProxyForProtocol(LPCWSTR szProxy, LPCWSTR proto, WCHAR *foundProxy, DWORD *foundProxyLen);
450 BOOL NETCON_connected(WININET_NETCONNECTION *connection);
451 DWORD NETCON_init(WININET_NETCONNECTION *connnection, BOOL useSSL);
452 void NETCON_unload(void);
453 DWORD NETCON_create(WININET_NETCONNECTION *connection, int domain,
454 int type, int protocol);
455 DWORD NETCON_close(WININET_NETCONNECTION *connection);
456 DWORD NETCON_connect(WININET_NETCONNECTION *connection, const struct sockaddr *serv_addr,
457 unsigned int addrlen);
458 DWORD NETCON_secure_connect(WININET_NETCONNECTION *connection, LPWSTR hostname);
459 DWORD NETCON_send(WININET_NETCONNECTION *connection, const void *msg, size_t len, int flags,
460 int *sent /* out */);
461 DWORD NETCON_recv(WININET_NETCONNECTION *connection, void *buf, size_t len, int flags,
462 int *recvd /* out */);
463 BOOL NETCON_query_data_available(WININET_NETCONNECTION *connection, DWORD *available);
464 LPCVOID NETCON_GetCert(WININET_NETCONNECTION *connection);
465 int NETCON_GetCipherStrength(WININET_NETCONNECTION *connection);
466 DWORD NETCON_set_timeout(WININET_NETCONNECTION *connection, BOOL send, int value);
467 int sock_get_error(int);
469 extern void URLCacheContainers_CreateDefaults(void);
470 extern void URLCacheContainers_DeleteAll(void);
472 #define MAX_REPLY_LEN 0x5B4
474 /* Used for debugging - maybe need to be shared in the Wine debugging code ? */
481 #endif /* _WINE_INTERNET_H_ */