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 /* used for netconnection.c stuff */
56 } WININET_NETCONNECTION;
58 static inline LPWSTR heap_strdupW(LPCWSTR str)
65 size = (strlenW(str)+1)*sizeof(WCHAR);
66 ret = HeapAlloc(GetProcessHeap(), 0, size);
68 memcpy(ret, str, size);
74 static inline LPWSTR heap_strndupW(LPCWSTR str, UINT max_len)
82 for(len=0; len<max_len; len++)
86 ret = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*(len+1));
88 memcpy(ret, str, sizeof(WCHAR)*len);
95 static inline WCHAR *heap_strdupAtoW(const char *str)
102 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
103 ret = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
105 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
111 static inline char *heap_strdupWtoA(LPCWSTR str)
116 DWORD size = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
117 ret = HeapAlloc(GetProcessHeap(), 0, size);
119 WideCharToMultiByte(CP_ACP, 0, str, -1, ret, size, NULL, NULL);
125 static inline void WININET_find_data_WtoA(LPWIN32_FIND_DATAW dataW, LPWIN32_FIND_DATAA dataA)
127 dataA->dwFileAttributes = dataW->dwFileAttributes;
128 dataA->ftCreationTime = dataW->ftCreationTime;
129 dataA->ftLastAccessTime = dataW->ftLastAccessTime;
130 dataA->ftLastWriteTime = dataW->ftLastWriteTime;
131 dataA->nFileSizeHigh = dataW->nFileSizeHigh;
132 dataA->nFileSizeLow = dataW->nFileSizeLow;
133 dataA->dwReserved0 = dataW->dwReserved0;
134 dataA->dwReserved1 = dataW->dwReserved1;
135 WideCharToMultiByte(CP_ACP, 0, dataW->cFileName, -1,
136 dataA->cFileName, sizeof(dataA->cFileName),
138 WideCharToMultiByte(CP_ACP, 0, dataW->cAlternateFileName, -1,
139 dataA->cAlternateFileName, sizeof(dataA->cAlternateFileName),
145 WH_HINIT = INTERNET_HANDLE_TYPE_INTERNET,
146 WH_HFTPSESSION = INTERNET_HANDLE_TYPE_CONNECT_FTP,
147 WH_HGOPHERSESSION = INTERNET_HANDLE_TYPE_CONNECT_GOPHER,
148 WH_HHTTPSESSION = INTERNET_HANDLE_TYPE_CONNECT_HTTP,
149 WH_HFILE = INTERNET_HANDLE_TYPE_FTP_FILE,
150 WH_HFTPFINDNEXT = INTERNET_HANDLE_TYPE_FTP_FIND,
151 WH_HHTTPREQ = INTERNET_HANDLE_TYPE_HTTP_REQUEST,
154 #define INET_OPENURL 0x0001
155 #define INET_CALLBACKW 0x0002
157 typedef struct _object_header_t object_header_t;
160 void (*Destroy)(object_header_t*);
161 void (*CloseConnection)(object_header_t*);
162 DWORD (*QueryOption)(object_header_t*,DWORD,void*,DWORD*,BOOL);
163 DWORD (*SetOption)(object_header_t*,DWORD,void*,DWORD);
164 DWORD (*ReadFile)(object_header_t*,void*,DWORD,DWORD*);
165 DWORD (*ReadFileExA)(object_header_t*,INTERNET_BUFFERSA*,DWORD,DWORD_PTR);
166 DWORD (*ReadFileExW)(object_header_t*,INTERNET_BUFFERSW*,DWORD,DWORD_PTR);
167 DWORD (*WriteFile)(object_header_t*,const void*,DWORD,DWORD*);
168 DWORD (*QueryDataAvailable)(object_header_t*,DWORD*,DWORD,DWORD_PTR);
169 DWORD (*FindNextFileW)(object_header_t*,void*);
172 #define INTERNET_HANDLE_IN_USE 1
174 struct _object_header_t
177 const object_vtbl_t *vtbl;
183 DWORD dwInternalFlags;
185 INTERNET_STATUS_CALLBACK lpfnStatusCB;
187 struct list children;
196 LPWSTR lpszProxyBypass;
197 LPWSTR lpszProxyUsername;
198 LPWSTR lpszProxyPassword;
206 appinfo_t *lpAppInfo;
207 LPWSTR lpszHostName; /* the final destination of the request */
208 LPWSTR lpszServerName; /* the name of the server we directly connect to */
211 INTERNET_PORT nHostPort; /* the final destination port of the request */
212 INTERNET_PORT nServerPort; /* the port of the server we directly connect to */
213 struct sockaddr_storage socketAddress;
217 #define HDR_ISREQUEST 0x0001
218 #define HDR_COMMADELIMITED 0x0002
219 #define HDR_SEMIDELIMITED 0x0004
227 } HTTPHEADERW, *LPHTTPHEADERW;
232 typedef struct gzip_stream_t gzip_stream_t;
237 http_session_t *lpHttpSession;
240 LPWSTR lpszRawHeaders;
241 WININET_NETCONNECTION netConnection;
243 LPWSTR lpszStatusText;
244 DWORD dwBytesToWrite;
245 DWORD dwBytesWritten;
246 HTTPHEADERW *pCustHeaders;
249 LPWSTR lpszCacheFile;
250 struct HttpAuthInfo *pAuthInfo;
251 struct HttpAuthInfo *pProxyAuthInfo;
253 CRITICAL_SECTION read_section; /* section to protect the following fields */
254 DWORD dwContentLength; /* total number of bytes to be read */
255 DWORD dwContentRead; /* bytes of the content read so far */
256 BOOL read_chunked; /* are we reading in chunked mode? */
257 DWORD read_pos; /* current read position in read_buf */
258 DWORD read_size; /* valid data size in read_buf */
259 BYTE read_buf[4096]; /* buffer for already read but not returned data */
262 gzip_stream_t *gzip_stream;
267 struct WORKREQ_FTPPUTFILEW
269 LPWSTR lpszLocalFile;
270 LPWSTR lpszNewRemoteFile;
275 struct WORKREQ_FTPSETCURRENTDIRECTORYW
277 LPWSTR lpszDirectory;
280 struct WORKREQ_FTPCREATEDIRECTORYW
282 LPWSTR lpszDirectory;
285 struct WORKREQ_FTPFINDFIRSTFILEW
287 LPWSTR lpszSearchFile;
288 LPWIN32_FIND_DATAW lpFindFileData;
293 struct WORKREQ_FTPGETCURRENTDIRECTORYW
295 LPWSTR lpszDirectory;
296 DWORD *lpdwDirectory;
299 struct WORKREQ_FTPOPENFILEW
307 struct WORKREQ_FTPGETFILEW
309 LPWSTR lpszRemoteFile;
312 DWORD dwLocalFlagsAttribute;
317 struct WORKREQ_FTPDELETEFILEW
322 struct WORKREQ_FTPREMOVEDIRECTORYW
324 LPWSTR lpszDirectory;
327 struct WORKREQ_FTPRENAMEFILEW
333 struct WORKREQ_FTPFINDNEXTW
335 LPWIN32_FIND_DATAW lpFindFileData;
338 struct WORKREQ_HTTPSENDREQUESTW
341 DWORD dwHeaderLength;
343 DWORD dwOptionalLength;
344 DWORD dwContentLength;
348 struct WORKREQ_HTTPENDREQUESTW
354 struct WORKREQ_SENDCALLBACK
357 DWORD dwInternetStatus;
358 LPVOID lpvStatusInfo;
359 DWORD dwStatusInfoLength;
362 struct WORKREQ_INTERNETOPENURLW
367 DWORD dwHeadersLength;
372 struct WORKREQ_INTERNETREADFILEEXA
374 LPINTERNET_BUFFERSA lpBuffersOut;
377 struct WORKREQ_INTERNETREADFILEEXW
379 LPINTERNET_BUFFERSW lpBuffersOut;
382 typedef struct WORKREQ
384 void (*asyncproc)(struct WORKREQ*);
385 object_header_t *hdr;
388 struct WORKREQ_FTPPUTFILEW FtpPutFileW;
389 struct WORKREQ_FTPSETCURRENTDIRECTORYW FtpSetCurrentDirectoryW;
390 struct WORKREQ_FTPCREATEDIRECTORYW FtpCreateDirectoryW;
391 struct WORKREQ_FTPFINDFIRSTFILEW FtpFindFirstFileW;
392 struct WORKREQ_FTPGETCURRENTDIRECTORYW FtpGetCurrentDirectoryW;
393 struct WORKREQ_FTPOPENFILEW FtpOpenFileW;
394 struct WORKREQ_FTPGETFILEW FtpGetFileW;
395 struct WORKREQ_FTPDELETEFILEW FtpDeleteFileW;
396 struct WORKREQ_FTPREMOVEDIRECTORYW FtpRemoveDirectoryW;
397 struct WORKREQ_FTPRENAMEFILEW FtpRenameFileW;
398 struct WORKREQ_FTPFINDNEXTW FtpFindNextW;
399 struct WORKREQ_HTTPSENDREQUESTW HttpSendRequestW;
400 struct WORKREQ_HTTPENDREQUESTW HttpEndRequestW;
401 struct WORKREQ_SENDCALLBACK SendCallback;
402 struct WORKREQ_INTERNETOPENURLW InternetOpenUrlW;
403 struct WORKREQ_INTERNETREADFILEEXA InternetReadFileExA;
404 struct WORKREQ_INTERNETREADFILEEXW InternetReadFileExW;
407 } WORKREQUEST, *LPWORKREQUEST;
409 HINTERNET WININET_AllocHandle( object_header_t *info );
410 object_header_t *WININET_GetObject( HINTERNET hinternet );
411 object_header_t *WININET_AddRef( object_header_t *info );
412 BOOL WININET_Release( object_header_t *info );
413 BOOL WININET_FreeHandle( HINTERNET hinternet );
415 DWORD INET_QueryOption( object_header_t *, DWORD, void *, DWORD *, BOOL );
417 time_t ConvertTimeString(LPCWSTR asctime);
419 HINTERNET FTP_Connect(appinfo_t *hIC, LPCWSTR lpszServerName,
420 INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
421 LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
422 DWORD dwInternalFlags);
424 DWORD HTTP_Connect(appinfo_t*,LPCWSTR,
425 INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
426 LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
427 DWORD dwInternalFlags, HINTERNET*);
429 BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
430 struct sockaddr *psa, socklen_t *sa_len);
432 void INTERNET_SetLastError(DWORD dwError);
433 DWORD INTERNET_GetLastError(void);
434 DWORD INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest);
435 LPSTR INTERNET_GetResponseBuffer(void);
436 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen);
438 VOID SendAsyncCallback(object_header_t *hdr, DWORD_PTR dwContext,
439 DWORD dwInternetStatus, LPVOID lpvStatusInfo,
440 DWORD dwStatusInfoLength);
442 VOID INTERNET_SendCallback(object_header_t *hdr, DWORD_PTR dwContext,
443 DWORD dwInternetStatus, LPVOID lpvStatusInfo,
444 DWORD dwStatusInfoLength);
445 BOOL INTERNET_FindProxyForProtocol(LPCWSTR szProxy, LPCWSTR proto, WCHAR *foundProxy, DWORD *foundProxyLen);
447 BOOL NETCON_connected(WININET_NETCONNECTION *connection);
448 DWORD NETCON_init(WININET_NETCONNECTION *connnection, BOOL useSSL);
449 void NETCON_unload(void);
450 DWORD NETCON_create(WININET_NETCONNECTION *connection, int domain,
451 int type, int protocol);
452 DWORD NETCON_close(WININET_NETCONNECTION *connection);
453 DWORD NETCON_connect(WININET_NETCONNECTION *connection, const struct sockaddr *serv_addr,
454 unsigned int addrlen);
455 DWORD NETCON_secure_connect(WININET_NETCONNECTION *connection, LPWSTR hostname);
456 DWORD NETCON_send(WININET_NETCONNECTION *connection, const void *msg, size_t len, int flags,
457 int *sent /* out */);
458 DWORD NETCON_recv(WININET_NETCONNECTION *connection, void *buf, size_t len, int flags,
459 int *recvd /* out */);
460 BOOL NETCON_query_data_available(WININET_NETCONNECTION *connection, DWORD *available);
461 LPCVOID NETCON_GetCert(WININET_NETCONNECTION *connection);
462 DWORD NETCON_set_timeout(WININET_NETCONNECTION *connection, BOOL send, int value);
463 int sock_get_error(int);
465 extern void URLCacheContainers_CreateDefaults(void);
466 extern void URLCacheContainers_DeleteAll(void);
468 #define MAX_REPLY_LEN 0x5B4
470 /* Used for debugging - maybe need to be shared in the Wine debugging code ? */
477 #endif /* _WINE_INTERNET_H_ */