pop 85fe8f259bfd4a5f252d249d4337834986a9b632
[wine/hacks.git] / dlls / wininet / internet.h
blob07b92d87d5760195aa7742ac111686802baa04c4
1 /*
2 * Wininet
4 * Copyright 1999 Corel Corporation
6 * Ulrich Czekalla
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
28 #endif
30 #include "wine/unicode.h"
31 #include "wine/list.h"
33 #include <time.h>
34 #ifdef HAVE_NETDB_H
35 # include <netdb.h>
36 #endif
37 #ifdef HAVE_NETINET_IN_H
38 # include <sys/types.h>
39 # include <netinet/in.h>
40 #endif
41 #ifdef HAVE_SYS_SOCKET_H
42 # include <sys/socket.h>
43 #endif
45 #if !defined(__MINGW32__) && !defined(_MSC_VER)
46 #define closesocket close
47 #define ioctlsocket ioctl
48 #endif /* __MINGW32__ */
50 /* used for netconnection.c stuff */
51 typedef struct
53 BOOL useSSL;
54 int socketFD;
55 void *ssl_s;
56 } WININET_NETCONNECTION;
58 static inline LPWSTR heap_strdupW(LPCWSTR str)
60 LPWSTR ret = NULL;
62 if(str) {
63 DWORD size;
65 size = (strlenW(str)+1)*sizeof(WCHAR);
66 ret = HeapAlloc(GetProcessHeap(), 0, size);
67 if(ret)
68 memcpy(ret, str, size);
71 return ret;
74 static inline WCHAR *heap_strdupAtoW(const char *str)
76 LPWSTR ret = NULL;
78 if(str) {
79 DWORD len;
81 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
82 ret = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
83 if(ret)
84 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
87 return ret;
90 static inline char *heap_strdupWtoA(LPCWSTR str)
92 char *ret = NULL;
94 if(str) {
95 DWORD size = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
96 ret = HeapAlloc(GetProcessHeap(), 0, size);
97 if(ret)
98 WideCharToMultiByte(CP_ACP, 0, str, -1, ret, size, NULL, NULL);
101 return ret;
104 static inline void WININET_find_data_WtoA(LPWIN32_FIND_DATAW dataW, LPWIN32_FIND_DATAA dataA)
106 dataA->dwFileAttributes = dataW->dwFileAttributes;
107 dataA->ftCreationTime = dataW->ftCreationTime;
108 dataA->ftLastAccessTime = dataW->ftLastAccessTime;
109 dataA->ftLastWriteTime = dataW->ftLastWriteTime;
110 dataA->nFileSizeHigh = dataW->nFileSizeHigh;
111 dataA->nFileSizeLow = dataW->nFileSizeLow;
112 dataA->dwReserved0 = dataW->dwReserved0;
113 dataA->dwReserved1 = dataW->dwReserved1;
114 WideCharToMultiByte(CP_ACP, 0, dataW->cFileName, -1,
115 dataA->cFileName, sizeof(dataA->cFileName),
116 NULL, NULL);
117 WideCharToMultiByte(CP_ACP, 0, dataW->cAlternateFileName, -1,
118 dataA->cAlternateFileName, sizeof(dataA->cAlternateFileName),
119 NULL, NULL);
122 typedef enum
124 WH_HINIT = INTERNET_HANDLE_TYPE_INTERNET,
125 WH_HFTPSESSION = INTERNET_HANDLE_TYPE_CONNECT_FTP,
126 WH_HGOPHERSESSION = INTERNET_HANDLE_TYPE_CONNECT_GOPHER,
127 WH_HHTTPSESSION = INTERNET_HANDLE_TYPE_CONNECT_HTTP,
128 WH_HFILE = INTERNET_HANDLE_TYPE_FTP_FILE,
129 WH_HFTPFINDNEXT = INTERNET_HANDLE_TYPE_FTP_FIND,
130 WH_HHTTPREQ = INTERNET_HANDLE_TYPE_HTTP_REQUEST,
131 } WH_TYPE;
133 #define INET_OPENURL 0x0001
134 #define INET_CALLBACKW 0x0002
136 typedef struct _object_header_t object_header_t;
138 typedef struct {
139 void (*Destroy)(object_header_t*);
140 void (*CloseConnection)(object_header_t*);
141 DWORD (*QueryOption)(object_header_t*,DWORD,void*,DWORD*,BOOL);
142 DWORD (*SetOption)(object_header_t*,DWORD,void*,DWORD);
143 DWORD (*ReadFile)(object_header_t*,void*,DWORD,DWORD*);
144 DWORD (*ReadFileExA)(object_header_t*,INTERNET_BUFFERSA*,DWORD,DWORD_PTR);
145 DWORD (*ReadFileExW)(object_header_t*,INTERNET_BUFFERSW*,DWORD,DWORD_PTR);
146 DWORD (*WriteFile)(object_header_t*,const void*,DWORD,DWORD*);
147 DWORD (*QueryDataAvailable)(object_header_t*,DWORD*,DWORD,DWORD_PTR);
148 DWORD (*FindNextFileW)(object_header_t*,void*);
149 } object_vtbl_t;
151 struct _object_header_t
153 WH_TYPE htype;
154 const object_vtbl_t *vtbl;
155 HINTERNET hInternet;
156 DWORD dwFlags;
157 DWORD_PTR dwContext;
158 DWORD dwError;
159 ULONG ErrorMask;
160 DWORD dwInternalFlags;
161 LONG refs;
162 INTERNET_STATUS_CALLBACK lpfnStatusCB;
163 struct list entry;
164 struct list children;
168 typedef struct
170 object_header_t hdr;
171 LPWSTR lpszAgent;
172 LPWSTR lpszProxy;
173 LPWSTR lpszProxyBypass;
174 LPWSTR lpszProxyUsername;
175 LPWSTR lpszProxyPassword;
176 DWORD dwAccessType;
177 } appinfo_t;
180 typedef struct
182 object_header_t hdr;
183 appinfo_t *lpAppInfo;
184 LPWSTR lpszHostName; /* the final destination of the request */
185 LPWSTR lpszServerName; /* the name of the server we directly connect to */
186 LPWSTR lpszUserName;
187 LPWSTR lpszPassword;
188 INTERNET_PORT nHostPort; /* the final destination port of the request */
189 INTERNET_PORT nServerPort; /* the port of the server we directly connect to */
190 struct sockaddr_storage socketAddress;
191 socklen_t sa_len;
192 } http_session_t;
194 #define HDR_ISREQUEST 0x0001
195 #define HDR_COMMADELIMITED 0x0002
196 #define HDR_SEMIDELIMITED 0x0004
198 typedef struct
200 LPWSTR lpszField;
201 LPWSTR lpszValue;
202 WORD wFlags;
203 WORD wCount;
204 } HTTPHEADERW, *LPHTTPHEADERW;
207 struct HttpAuthInfo;
209 typedef struct gzip_stream_t gzip_stream_t;
211 typedef struct
213 object_header_t hdr;
214 http_session_t *lpHttpSession;
215 LPWSTR lpszPath;
216 LPWSTR lpszVerb;
217 LPWSTR lpszRawHeaders;
218 WININET_NETCONNECTION netConnection;
219 LPWSTR lpszVersion;
220 LPWSTR lpszStatusText;
221 DWORD dwBytesToWrite;
222 DWORD dwBytesWritten;
223 HTTPHEADERW *pCustHeaders;
224 DWORD nCustHeaders;
225 HANDLE hCacheFile;
226 LPWSTR lpszCacheFile;
227 struct HttpAuthInfo *pAuthInfo;
228 struct HttpAuthInfo *pProxyAuthInfo;
230 CRITICAL_SECTION read_section; /* section to protect the following fields */
231 DWORD dwContentLength; /* total number of bytes to be read */
232 DWORD dwContentRead; /* bytes of the content read so far */
233 BOOL read_chunked; /* are we reading in chunked mode? */
234 DWORD read_pos; /* current read position in read_buf */
235 DWORD read_size; /* valid data size in read_buf */
236 BYTE read_buf[4096]; /* buffer for already read but not returned data */
238 BOOL decoding;
239 gzip_stream_t *gzip_stream;
240 } http_request_t;
244 struct WORKREQ_FTPPUTFILEW
246 LPWSTR lpszLocalFile;
247 LPWSTR lpszNewRemoteFile;
248 DWORD dwFlags;
249 DWORD_PTR dwContext;
252 struct WORKREQ_FTPSETCURRENTDIRECTORYW
254 LPWSTR lpszDirectory;
257 struct WORKREQ_FTPCREATEDIRECTORYW
259 LPWSTR lpszDirectory;
262 struct WORKREQ_FTPFINDFIRSTFILEW
264 LPWSTR lpszSearchFile;
265 LPWIN32_FIND_DATAW lpFindFileData;
266 DWORD dwFlags;
267 DWORD_PTR dwContext;
270 struct WORKREQ_FTPGETCURRENTDIRECTORYW
272 LPWSTR lpszDirectory;
273 DWORD *lpdwDirectory;
276 struct WORKREQ_FTPOPENFILEW
278 LPWSTR lpszFilename;
279 DWORD dwAccess;
280 DWORD dwFlags;
281 DWORD_PTR dwContext;
284 struct WORKREQ_FTPGETFILEW
286 LPWSTR lpszRemoteFile;
287 LPWSTR lpszNewFile;
288 BOOL fFailIfExists;
289 DWORD dwLocalFlagsAttribute;
290 DWORD dwFlags;
291 DWORD_PTR dwContext;
294 struct WORKREQ_FTPDELETEFILEW
296 LPWSTR lpszFilename;
299 struct WORKREQ_FTPREMOVEDIRECTORYW
301 LPWSTR lpszDirectory;
304 struct WORKREQ_FTPRENAMEFILEW
306 LPWSTR lpszSrcFile;
307 LPWSTR lpszDestFile;
310 struct WORKREQ_FTPFINDNEXTW
312 LPWIN32_FIND_DATAW lpFindFileData;
315 struct WORKREQ_HTTPSENDREQUESTW
317 LPWSTR lpszHeader;
318 DWORD dwHeaderLength;
319 LPVOID lpOptional;
320 DWORD dwOptionalLength;
321 DWORD dwContentLength;
322 BOOL bEndRequest;
325 struct WORKREQ_HTTPENDREQUESTW
327 DWORD dwFlags;
328 DWORD_PTR dwContext;
331 struct WORKREQ_SENDCALLBACK
333 DWORD_PTR dwContext;
334 DWORD dwInternetStatus;
335 LPVOID lpvStatusInfo;
336 DWORD dwStatusInfoLength;
339 struct WORKREQ_INTERNETOPENURLW
341 HINTERNET hInternet;
342 LPWSTR lpszUrl;
343 LPWSTR lpszHeaders;
344 DWORD dwHeadersLength;
345 DWORD dwFlags;
346 DWORD_PTR dwContext;
349 struct WORKREQ_INTERNETREADFILEEXA
351 LPINTERNET_BUFFERSA lpBuffersOut;
354 struct WORKREQ_INTERNETREADFILEEXW
356 LPINTERNET_BUFFERSW lpBuffersOut;
359 typedef struct WORKREQ
361 void (*asyncproc)(struct WORKREQ*);
362 object_header_t *hdr;
364 union {
365 struct WORKREQ_FTPPUTFILEW FtpPutFileW;
366 struct WORKREQ_FTPSETCURRENTDIRECTORYW FtpSetCurrentDirectoryW;
367 struct WORKREQ_FTPCREATEDIRECTORYW FtpCreateDirectoryW;
368 struct WORKREQ_FTPFINDFIRSTFILEW FtpFindFirstFileW;
369 struct WORKREQ_FTPGETCURRENTDIRECTORYW FtpGetCurrentDirectoryW;
370 struct WORKREQ_FTPOPENFILEW FtpOpenFileW;
371 struct WORKREQ_FTPGETFILEW FtpGetFileW;
372 struct WORKREQ_FTPDELETEFILEW FtpDeleteFileW;
373 struct WORKREQ_FTPREMOVEDIRECTORYW FtpRemoveDirectoryW;
374 struct WORKREQ_FTPRENAMEFILEW FtpRenameFileW;
375 struct WORKREQ_FTPFINDNEXTW FtpFindNextW;
376 struct WORKREQ_HTTPSENDREQUESTW HttpSendRequestW;
377 struct WORKREQ_HTTPENDREQUESTW HttpEndRequestW;
378 struct WORKREQ_SENDCALLBACK SendCallback;
379 struct WORKREQ_INTERNETOPENURLW InternetOpenUrlW;
380 struct WORKREQ_INTERNETREADFILEEXA InternetReadFileExA;
381 struct WORKREQ_INTERNETREADFILEEXW InternetReadFileExW;
382 } u;
384 } WORKREQUEST, *LPWORKREQUEST;
386 HINTERNET WININET_AllocHandle( object_header_t *info );
387 object_header_t *WININET_GetObject( HINTERNET hinternet );
388 object_header_t *WININET_AddRef( object_header_t *info );
389 BOOL WININET_Release( object_header_t *info );
390 BOOL WININET_FreeHandle( HINTERNET hinternet );
392 DWORD INET_QueryOption( object_header_t *, DWORD, void *, DWORD *, BOOL );
394 time_t ConvertTimeString(LPCWSTR asctime);
396 HINTERNET FTP_Connect(appinfo_t *hIC, LPCWSTR lpszServerName,
397 INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
398 LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
399 DWORD dwInternalFlags);
401 DWORD HTTP_Connect(appinfo_t*,LPCWSTR,
402 INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
403 LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
404 DWORD dwInternalFlags, HINTERNET*);
406 BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
407 struct sockaddr *psa, socklen_t *sa_len);
409 void INTERNET_SetLastError(DWORD dwError);
410 DWORD INTERNET_GetLastError(void);
411 DWORD INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest);
412 LPSTR INTERNET_GetResponseBuffer(void);
413 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen);
415 VOID SendAsyncCallback(object_header_t *hdr, DWORD_PTR dwContext,
416 DWORD dwInternetStatus, LPVOID lpvStatusInfo,
417 DWORD dwStatusInfoLength);
419 VOID INTERNET_SendCallback(object_header_t *hdr, DWORD_PTR dwContext,
420 DWORD dwInternetStatus, LPVOID lpvStatusInfo,
421 DWORD dwStatusInfoLength);
422 BOOL INTERNET_FindProxyForProtocol(LPCWSTR szProxy, LPCWSTR proto, WCHAR *foundProxy, DWORD *foundProxyLen);
424 BOOL NETCON_connected(WININET_NETCONNECTION *connection);
425 DWORD NETCON_init(WININET_NETCONNECTION *connnection, BOOL useSSL);
426 void NETCON_unload(void);
427 DWORD NETCON_create(WININET_NETCONNECTION *connection, int domain,
428 int type, int protocol);
429 DWORD NETCON_close(WININET_NETCONNECTION *connection);
430 DWORD NETCON_connect(WININET_NETCONNECTION *connection, const struct sockaddr *serv_addr,
431 unsigned int addrlen);
432 DWORD NETCON_secure_connect(WININET_NETCONNECTION *connection, LPWSTR hostname);
433 DWORD NETCON_send(WININET_NETCONNECTION *connection, const void *msg, size_t len, int flags,
434 int *sent /* out */);
435 DWORD NETCON_recv(WININET_NETCONNECTION *connection, void *buf, size_t len, int flags,
436 int *recvd /* out */);
437 BOOL NETCON_query_data_available(WININET_NETCONNECTION *connection, DWORD *available);
438 LPCVOID NETCON_GetCert(WININET_NETCONNECTION *connection);
439 DWORD NETCON_set_timeout(WININET_NETCONNECTION *connection, BOOL send, int value);
440 int sock_get_error(int);
442 extern void URLCacheContainers_CreateDefaults(void);
443 extern void URLCacheContainers_DeleteAll(void);
445 #define MAX_REPLY_LEN 0x5B4
447 /* Used for debugging - maybe need to be shared in the Wine debugging code ? */
448 typedef struct
450 DWORD val;
451 const char* name;
452 } wininet_flag_info;
454 #endif /* _WINE_INTERNET_H_ */