wininet: Update the Dutch translation.
[wine] / dlls / wininet / internet.h
1 /*
2  * Wininet
3  *
4  * Copyright 1999 Corel Corporation
5  *
6  * Ulrich Czekalla
7  *
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.
12  *
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.
17  *
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
21  */
22
23 #ifndef _WINE_INTERNET_H_
24 #define _WINE_INTERNET_H_
25
26 #ifndef __WINE_CONFIG_H
27 # error You must include config.h to use this header
28 #endif
29
30 #include "wine/unicode.h"
31 #include "wine/list.h"
32
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
44
45 #if !defined(__MINGW32__) && !defined(_MSC_VER)
46 #define closesocket close
47 #define ioctlsocket ioctl
48 #endif /* __MINGW32__ */
49
50 extern HMODULE WININET_hModule;
51
52 /* used for netconnection.c stuff */
53 typedef struct
54 {
55     BOOL useSSL;
56     int socketFD;
57     void *ssl_s;
58     DWORD security_flags;
59 } WININET_NETCONNECTION;
60
61 static inline LPWSTR heap_strdupW(LPCWSTR str)
62 {
63     LPWSTR ret = NULL;
64
65     if(str) {
66         DWORD size;
67
68         size = (strlenW(str)+1)*sizeof(WCHAR);
69         ret = HeapAlloc(GetProcessHeap(), 0, size);
70         if(ret)
71             memcpy(ret, str, size);
72     }
73
74     return ret;
75 }
76
77 static inline LPWSTR heap_strndupW(LPCWSTR str, UINT max_len)
78 {
79     LPWSTR ret;
80     UINT len;
81
82     if(!str)
83         return NULL;
84
85     for(len=0; len<max_len; len++)
86         if(str[len] == '\0')
87             break;
88
89     ret = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*(len+1));
90     if(ret) {
91         memcpy(ret, str, sizeof(WCHAR)*len);
92         ret[len] = '\0';
93     }
94
95     return ret;
96 }
97
98 static inline WCHAR *heap_strdupAtoW(const char *str)
99 {
100     LPWSTR ret = NULL;
101
102     if(str) {
103         DWORD len;
104
105         len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
106         ret = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
107         if(ret)
108             MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
109     }
110
111     return ret;
112 }
113
114 static inline char *heap_strdupWtoA(LPCWSTR str)
115 {
116     char *ret = NULL;
117
118     if(str) {
119         DWORD size = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
120         ret = HeapAlloc(GetProcessHeap(), 0, size);
121         if(ret)
122             WideCharToMultiByte(CP_ACP, 0, str, -1, ret, size, NULL, NULL);
123     }
124
125     return ret;
126 }
127
128 static inline void WININET_find_data_WtoA(LPWIN32_FIND_DATAW dataW, LPWIN32_FIND_DATAA dataA)
129 {
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),
140         NULL, NULL);
141     WideCharToMultiByte(CP_ACP, 0, dataW->cAlternateFileName, -1, 
142         dataA->cAlternateFileName, sizeof(dataA->cAlternateFileName),
143         NULL, NULL);
144 }
145
146 typedef enum
147 {
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,
155 } WH_TYPE;
156
157 #define INET_OPENURL 0x0001
158 #define INET_CALLBACKW 0x0002
159
160 typedef struct _object_header_t object_header_t;
161
162 typedef struct {
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*);
173 } object_vtbl_t;
174
175 #define INTERNET_HANDLE_IN_USE 1
176
177 struct _object_header_t
178 {
179     WH_TYPE htype;
180     const object_vtbl_t *vtbl;
181     HINTERNET hInternet;
182     DWORD  dwFlags;
183     DWORD_PTR dwContext;
184     DWORD  dwError;
185     ULONG  ErrorMask;
186     DWORD  dwInternalFlags;
187     LONG   refs;
188     INTERNET_STATUS_CALLBACK lpfnStatusCB;
189     struct list entry;
190     struct list children;
191 };
192
193
194 typedef struct
195 {
196     object_header_t hdr;
197     LPWSTR  lpszAgent;
198     LPWSTR  lpszProxy;
199     LPWSTR  lpszProxyBypass;
200     LPWSTR  lpszProxyUsername;
201     LPWSTR  lpszProxyPassword;
202     DWORD   dwAccessType;
203 } appinfo_t;
204
205
206 typedef struct
207 {
208     object_header_t hdr;
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 */
212     LPWSTR  lpszUserName;
213     LPWSTR  lpszPassword;
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;
217     socklen_t sa_len;
218 } http_session_t;
219
220 #define HDR_ISREQUEST           0x0001
221 #define HDR_COMMADELIMITED      0x0002
222 #define HDR_SEMIDELIMITED       0x0004
223
224 typedef struct
225 {
226     LPWSTR lpszField;
227     LPWSTR lpszValue;
228     WORD wFlags;
229     WORD wCount;
230 } HTTPHEADERW, *LPHTTPHEADERW;
231
232
233 struct HttpAuthInfo;
234
235 typedef struct gzip_stream_t gzip_stream_t;
236
237 typedef struct
238 {
239     object_header_t hdr;
240     http_session_t *lpHttpSession;
241     LPWSTR lpszPath;
242     LPWSTR lpszVerb;
243     LPWSTR lpszRawHeaders;
244     WININET_NETCONNECTION netConnection;
245     LPWSTR lpszVersion;
246     LPWSTR lpszStatusText;
247     DWORD dwBytesToWrite;
248     DWORD dwBytesWritten;
249     HTTPHEADERW *pCustHeaders;
250     DWORD nCustHeaders;
251     HANDLE hCacheFile;
252     LPWSTR lpszCacheFile;
253     struct HttpAuthInfo *pAuthInfo;
254     struct HttpAuthInfo *pProxyAuthInfo;
255
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 */
263
264     BOOL decoding;
265     gzip_stream_t *gzip_stream;
266 } http_request_t;
267
268
269
270 struct WORKREQ_FTPPUTFILEW
271 {
272     LPWSTR lpszLocalFile;
273     LPWSTR lpszNewRemoteFile;
274     DWORD  dwFlags;
275     DWORD_PTR dwContext;
276 };
277
278 struct WORKREQ_FTPSETCURRENTDIRECTORYW
279 {
280     LPWSTR lpszDirectory;
281 };
282
283 struct WORKREQ_FTPCREATEDIRECTORYW
284 {
285     LPWSTR lpszDirectory;
286 };
287
288 struct WORKREQ_FTPFINDFIRSTFILEW
289 {
290     LPWSTR lpszSearchFile;
291     LPWIN32_FIND_DATAW lpFindFileData;
292     DWORD  dwFlags;
293     DWORD_PTR dwContext;
294 };
295
296 struct WORKREQ_FTPGETCURRENTDIRECTORYW
297 {
298     LPWSTR lpszDirectory;
299     DWORD *lpdwDirectory;
300 };
301
302 struct WORKREQ_FTPOPENFILEW
303 {
304     LPWSTR lpszFilename;
305     DWORD  dwAccess;
306     DWORD  dwFlags;
307     DWORD_PTR dwContext;
308 };
309
310 struct WORKREQ_FTPGETFILEW
311 {
312     LPWSTR lpszRemoteFile;
313     LPWSTR lpszNewFile;
314     BOOL   fFailIfExists;
315     DWORD  dwLocalFlagsAttribute;
316     DWORD  dwFlags;
317     DWORD_PTR dwContext;
318 };
319
320 struct WORKREQ_FTPDELETEFILEW
321 {
322     LPWSTR lpszFilename;
323 };
324
325 struct WORKREQ_FTPREMOVEDIRECTORYW
326 {
327     LPWSTR lpszDirectory;
328 };
329
330 struct WORKREQ_FTPRENAMEFILEW
331 {
332     LPWSTR lpszSrcFile;
333     LPWSTR lpszDestFile;
334 };
335
336 struct WORKREQ_FTPFINDNEXTW
337 {
338     LPWIN32_FIND_DATAW lpFindFileData;
339 };
340
341 struct WORKREQ_HTTPSENDREQUESTW
342 {
343     LPWSTR lpszHeader;
344     DWORD  dwHeaderLength;
345     LPVOID lpOptional;
346     DWORD  dwOptionalLength;
347     DWORD  dwContentLength;
348     BOOL   bEndRequest;
349 };
350
351 struct WORKREQ_HTTPENDREQUESTW
352 {
353     DWORD     dwFlags;
354     DWORD_PTR dwContext;
355 };
356
357 struct WORKREQ_SENDCALLBACK
358 {
359     DWORD_PTR dwContext;
360     DWORD     dwInternetStatus;
361     LPVOID    lpvStatusInfo;
362     DWORD     dwStatusInfoLength;
363 };
364
365 struct WORKREQ_INTERNETOPENURLW
366 {
367     HINTERNET hInternet;
368     LPWSTR     lpszUrl;
369     LPWSTR     lpszHeaders;
370     DWORD     dwHeadersLength;
371     DWORD     dwFlags;
372     DWORD_PTR dwContext;
373 };
374
375 struct WORKREQ_INTERNETREADFILEEXA
376 {
377     LPINTERNET_BUFFERSA lpBuffersOut;
378 };
379
380 struct WORKREQ_INTERNETREADFILEEXW
381 {
382     LPINTERNET_BUFFERSW lpBuffersOut;
383 };
384
385 typedef struct WORKREQ
386 {
387     void (*asyncproc)(struct WORKREQ*);
388     object_header_t *hdr;
389
390     union {
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;
408     } u;
409
410 } WORKREQUEST, *LPWORKREQUEST;
411
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 );
417
418 DWORD INET_QueryOption( object_header_t *, DWORD, void *, DWORD *, BOOL );
419
420 time_t ConvertTimeString(LPCWSTR asctime);
421
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);
426
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*);
431
432 BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
433         struct sockaddr *psa, socklen_t *sa_len);
434
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);
440
441 VOID SendAsyncCallback(object_header_t *hdr, DWORD_PTR dwContext,
442                        DWORD dwInternetStatus, LPVOID lpvStatusInfo,
443                        DWORD dwStatusInfoLength);
444
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);
449
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);
468
469 extern void URLCacheContainers_CreateDefaults(void);
470 extern void URLCacheContainers_DeleteAll(void);
471
472 #define MAX_REPLY_LEN           0x5B4
473
474 /* Used for debugging - maybe need to be shared in the Wine debugging code ? */
475 typedef struct
476 {
477     DWORD val;
478     const char* name;
479 } wininet_flag_info;
480
481 #endif /* _WINE_INTERNET_H_ */