jscript: Make String_slice generic.
[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 /* used for netconnection.c stuff */
51 typedef struct
52 {
53     BOOL useSSL;
54     int socketFD;
55     void *ssl_s;
56 } WININET_NETCONNECTION;
57
58 static inline LPWSTR WININET_strdupW( LPCWSTR str )
59 {
60     LPWSTR ret = HeapAlloc( GetProcessHeap(), 0, (strlenW(str) + 1)*sizeof(WCHAR) );
61     if (ret) strcpyW( ret, str );
62     return ret;
63 }
64
65 static inline LPWSTR WININET_strdup_AtoW( LPCSTR str )
66 {
67     int len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0);
68     LPWSTR ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
69     if (ret)
70         MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len);
71     return ret;
72 }
73
74 static inline LPSTR WININET_strdup_WtoA( LPCWSTR str )
75 {
76     int len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
77     LPSTR ret = HeapAlloc( GetProcessHeap(), 0, len );
78     if (ret)
79         WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL);
80     return ret;
81 }
82
83 static inline void WININET_find_data_WtoA(LPWIN32_FIND_DATAW dataW, LPWIN32_FIND_DATAA dataA)
84 {
85     dataA->dwFileAttributes = dataW->dwFileAttributes;
86     dataA->ftCreationTime   = dataW->ftCreationTime;
87     dataA->ftLastAccessTime = dataW->ftLastAccessTime;
88     dataA->ftLastWriteTime  = dataW->ftLastWriteTime;
89     dataA->nFileSizeHigh    = dataW->nFileSizeHigh;
90     dataA->nFileSizeLow     = dataW->nFileSizeLow;
91     dataA->dwReserved0      = dataW->dwReserved0;
92     dataA->dwReserved1      = dataW->dwReserved1;
93     WideCharToMultiByte(CP_ACP, 0, dataW->cFileName, -1, 
94         dataA->cFileName, sizeof(dataA->cFileName),
95         NULL, NULL);
96     WideCharToMultiByte(CP_ACP, 0, dataW->cAlternateFileName, -1, 
97         dataA->cAlternateFileName, sizeof(dataA->cAlternateFileName),
98         NULL, NULL);
99 }
100
101 typedef enum
102 {
103     WH_HINIT = INTERNET_HANDLE_TYPE_INTERNET,
104     WH_HFTPSESSION = INTERNET_HANDLE_TYPE_CONNECT_FTP,
105     WH_HGOPHERSESSION = INTERNET_HANDLE_TYPE_CONNECT_GOPHER,
106     WH_HHTTPSESSION = INTERNET_HANDLE_TYPE_CONNECT_HTTP,
107     WH_HFILE = INTERNET_HANDLE_TYPE_FTP_FILE,
108     WH_HFTPFINDNEXT = INTERNET_HANDLE_TYPE_FTP_FIND,
109     WH_HHTTPREQ = INTERNET_HANDLE_TYPE_HTTP_REQUEST,
110 } WH_TYPE;
111
112 #define INET_OPENURL 0x0001
113 #define INET_CALLBACKW 0x0002
114
115 typedef struct _object_header_t object_header_t;
116
117 typedef struct {
118     void (*Destroy)(object_header_t*);
119     void (*CloseConnection)(object_header_t*);
120     DWORD (*QueryOption)(object_header_t*,DWORD,void*,DWORD*,BOOL);
121     DWORD (*SetOption)(object_header_t*,DWORD,void*,DWORD);
122     DWORD (*ReadFile)(object_header_t*,void*,DWORD,DWORD*);
123     DWORD (*ReadFileExA)(object_header_t*,INTERNET_BUFFERSA*,DWORD,DWORD_PTR);
124     DWORD (*ReadFileExW)(object_header_t*,INTERNET_BUFFERSW*,DWORD,DWORD_PTR);
125     BOOL (*WriteFile)(object_header_t*,const void*,DWORD,DWORD*);
126     DWORD (*QueryDataAvailable)(object_header_t*,DWORD*,DWORD,DWORD_PTR);
127     DWORD (*FindNextFileW)(object_header_t*,void*);
128 } object_vtbl_t;
129
130 struct _object_header_t
131 {
132     WH_TYPE htype;
133     const object_vtbl_t *vtbl;
134     HINTERNET hInternet;
135     DWORD  dwFlags;
136     DWORD_PTR dwContext;
137     DWORD  dwError;
138     DWORD  dwInternalFlags;
139     LONG   refs;
140     INTERNET_STATUS_CALLBACK lpfnStatusCB;
141     struct list entry;
142     struct list children;
143 };
144
145
146 typedef struct
147 {
148     object_header_t hdr;
149     LPWSTR  lpszAgent;
150     LPWSTR  lpszProxy;
151     LPWSTR  lpszProxyBypass;
152     LPWSTR  lpszProxyUsername;
153     LPWSTR  lpszProxyPassword;
154     DWORD   dwAccessType;
155 } appinfo_t;
156
157
158 typedef struct
159 {
160     object_header_t hdr;
161     appinfo_t *lpAppInfo;
162     LPWSTR  lpszHostName; /* the final destination of the request */
163     LPWSTR  lpszServerName; /* the name of the server we directly connect to */
164     LPWSTR  lpszUserName;
165     LPWSTR  lpszPassword;
166     INTERNET_PORT nHostPort; /* the final destination port of the request */
167     INTERNET_PORT nServerPort; /* the port of the server we directly connect to */
168     struct sockaddr_storage socketAddress;
169     socklen_t sa_len;
170 } http_session_t;
171
172 #define HDR_ISREQUEST           0x0001
173 #define HDR_COMMADELIMITED      0x0002
174 #define HDR_SEMIDELIMITED       0x0004
175
176 typedef struct
177 {
178     LPWSTR lpszField;
179     LPWSTR lpszValue;
180     WORD wFlags;
181     WORD wCount;
182 } HTTPHEADERW, *LPHTTPHEADERW;
183
184
185 struct HttpAuthInfo;
186
187 typedef struct gzip_stream_t gzip_stream_t;
188
189 typedef struct
190 {
191     object_header_t hdr;
192     http_session_t *lpHttpSession;
193     LPWSTR lpszPath;
194     LPWSTR lpszVerb;
195     LPWSTR lpszRawHeaders;
196     WININET_NETCONNECTION netConnection;
197     LPWSTR lpszVersion;
198     LPWSTR lpszStatusText;
199     DWORD dwBytesToWrite;
200     DWORD dwBytesWritten;
201     HTTPHEADERW *pCustHeaders;
202     DWORD nCustHeaders;
203     HANDLE hCacheFile;
204     LPWSTR lpszCacheFile;
205     struct HttpAuthInfo *pAuthInfo;
206     struct HttpAuthInfo *pProxyAuthInfo;
207
208     CRITICAL_SECTION read_section;  /* section to protect the following fields */
209     DWORD dwContentLength; /* total number of bytes to be read */
210     DWORD dwContentRead;  /* bytes of the content read so far */
211     BOOL  read_chunked;   /* are we reading in chunked mode? */
212     DWORD read_pos;       /* current read position in read_buf */
213     DWORD read_size;      /* valid data size in read_buf */
214     BYTE  read_buf[4096]; /* buffer for already read but not returned data */
215
216     BOOL decoding;
217     gzip_stream_t *gzip_stream;
218 } http_request_t;
219
220
221
222 struct WORKREQ_FTPPUTFILEW
223 {
224     LPWSTR lpszLocalFile;
225     LPWSTR lpszNewRemoteFile;
226     DWORD  dwFlags;
227     DWORD_PTR dwContext;
228 };
229
230 struct WORKREQ_FTPSETCURRENTDIRECTORYW
231 {
232     LPWSTR lpszDirectory;
233 };
234
235 struct WORKREQ_FTPCREATEDIRECTORYW
236 {
237     LPWSTR lpszDirectory;
238 };
239
240 struct WORKREQ_FTPFINDFIRSTFILEW
241 {
242     LPWSTR lpszSearchFile;
243     LPWIN32_FIND_DATAW lpFindFileData;
244     DWORD  dwFlags;
245     DWORD_PTR dwContext;
246 };
247
248 struct WORKREQ_FTPGETCURRENTDIRECTORYW
249 {
250     LPWSTR lpszDirectory;
251     DWORD *lpdwDirectory;
252 };
253
254 struct WORKREQ_FTPOPENFILEW
255 {
256     LPWSTR lpszFilename;
257     DWORD  dwAccess;
258     DWORD  dwFlags;
259     DWORD_PTR dwContext;
260 };
261
262 struct WORKREQ_FTPGETFILEW
263 {
264     LPWSTR lpszRemoteFile;
265     LPWSTR lpszNewFile;
266     BOOL   fFailIfExists;
267     DWORD  dwLocalFlagsAttribute;
268     DWORD  dwFlags;
269     DWORD_PTR dwContext;
270 };
271
272 struct WORKREQ_FTPDELETEFILEW
273 {
274     LPWSTR lpszFilename;
275 };
276
277 struct WORKREQ_FTPREMOVEDIRECTORYW
278 {
279     LPWSTR lpszDirectory;
280 };
281
282 struct WORKREQ_FTPRENAMEFILEW
283 {
284     LPWSTR lpszSrcFile;
285     LPWSTR lpszDestFile;
286 };
287
288 struct WORKREQ_FTPFINDNEXTW
289 {
290     LPWIN32_FIND_DATAW lpFindFileData;
291 };
292
293 struct WORKREQ_HTTPSENDREQUESTW
294 {
295     LPWSTR lpszHeader;
296     DWORD  dwHeaderLength;
297     LPVOID lpOptional;
298     DWORD  dwOptionalLength;
299     DWORD  dwContentLength;
300     BOOL   bEndRequest;
301 };
302
303 struct WORKREQ_HTTPENDREQUESTW
304 {
305     DWORD     dwFlags;
306     DWORD_PTR dwContext;
307 };
308
309 struct WORKREQ_SENDCALLBACK
310 {
311     DWORD_PTR dwContext;
312     DWORD     dwInternetStatus;
313     LPVOID    lpvStatusInfo;
314     DWORD     dwStatusInfoLength;
315 };
316
317 struct WORKREQ_INTERNETOPENURLW
318 {
319     HINTERNET hInternet;
320     LPWSTR     lpszUrl;
321     LPWSTR     lpszHeaders;
322     DWORD     dwHeadersLength;
323     DWORD     dwFlags;
324     DWORD_PTR dwContext;
325 };
326
327 struct WORKREQ_INTERNETREADFILEEXA
328 {
329     LPINTERNET_BUFFERSA lpBuffersOut;
330 };
331
332 struct WORKREQ_INTERNETREADFILEEXW
333 {
334     LPINTERNET_BUFFERSW lpBuffersOut;
335 };
336
337 typedef struct WORKREQ
338 {
339     void (*asyncproc)(struct WORKREQ*);
340     object_header_t *hdr;
341
342     union {
343         struct WORKREQ_FTPPUTFILEW              FtpPutFileW;
344         struct WORKREQ_FTPSETCURRENTDIRECTORYW  FtpSetCurrentDirectoryW;
345         struct WORKREQ_FTPCREATEDIRECTORYW      FtpCreateDirectoryW;
346         struct WORKREQ_FTPFINDFIRSTFILEW        FtpFindFirstFileW;
347         struct WORKREQ_FTPGETCURRENTDIRECTORYW  FtpGetCurrentDirectoryW;
348         struct WORKREQ_FTPOPENFILEW             FtpOpenFileW;
349         struct WORKREQ_FTPGETFILEW              FtpGetFileW;
350         struct WORKREQ_FTPDELETEFILEW           FtpDeleteFileW;
351         struct WORKREQ_FTPREMOVEDIRECTORYW      FtpRemoveDirectoryW;
352         struct WORKREQ_FTPRENAMEFILEW           FtpRenameFileW;
353         struct WORKREQ_FTPFINDNEXTW             FtpFindNextW;
354         struct WORKREQ_HTTPSENDREQUESTW         HttpSendRequestW;
355         struct WORKREQ_HTTPENDREQUESTW          HttpEndRequestW;
356         struct WORKREQ_SENDCALLBACK             SendCallback;
357         struct WORKREQ_INTERNETOPENURLW         InternetOpenUrlW;
358         struct WORKREQ_INTERNETREADFILEEXA      InternetReadFileExA;
359         struct WORKREQ_INTERNETREADFILEEXW      InternetReadFileExW;
360     } u;
361
362 } WORKREQUEST, *LPWORKREQUEST;
363
364 HINTERNET WININET_AllocHandle( object_header_t *info );
365 object_header_t *WININET_GetObject( HINTERNET hinternet );
366 object_header_t *WININET_AddRef( object_header_t *info );
367 BOOL WININET_Release( object_header_t *info );
368 BOOL WININET_FreeHandle( HINTERNET hinternet );
369
370 DWORD INET_QueryOption(DWORD,void*,DWORD*,BOOL);
371
372 time_t ConvertTimeString(LPCWSTR asctime);
373
374 HINTERNET FTP_Connect(appinfo_t *hIC, LPCWSTR lpszServerName,
375         INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
376         LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
377         DWORD dwInternalFlags);
378
379 HINTERNET HTTP_Connect(appinfo_t *hIC, LPCWSTR lpszServerName,
380         INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
381         LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
382         DWORD dwInternalFlags);
383
384 BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
385         struct sockaddr *psa, socklen_t *sa_len);
386
387 void INTERNET_SetLastError(DWORD dwError);
388 DWORD INTERNET_GetLastError(void);
389 BOOL INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest);
390 LPSTR INTERNET_GetResponseBuffer(void);
391 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen);
392
393 BOOLAPI HTTP_HttpSendRequestW(http_request_t *req, LPCWSTR lpszHeaders,
394         DWORD dwHeaderLength, LPVOID lpOptional, DWORD dwOptionalLength,
395         DWORD dwContentLength, BOOL bEndRequest);
396 INTERNETAPI HINTERNET WINAPI HTTP_HttpOpenRequestW(http_session_t *session,
397         LPCWSTR lpszVerb, LPCWSTR lpszObjectName, LPCWSTR lpszVersion,
398         LPCWSTR lpszReferrer , LPCWSTR *lpszAcceptTypes,
399         DWORD dwFlags, DWORD_PTR dwContext);
400
401 VOID SendAsyncCallback(object_header_t *hdr, DWORD_PTR dwContext,
402                        DWORD dwInternetStatus, LPVOID lpvStatusInfo,
403                        DWORD dwStatusInfoLength);
404
405 VOID INTERNET_SendCallback(object_header_t *hdr, DWORD_PTR dwContext,
406                            DWORD dwInternetStatus, LPVOID lpvStatusInfo,
407                            DWORD dwStatusInfoLength);
408
409 BOOL NETCON_connected(WININET_NETCONNECTION *connection);
410 BOOL NETCON_init(WININET_NETCONNECTION *connnection, BOOL useSSL);
411 BOOL NETCON_create(WININET_NETCONNECTION *connection, int domain,
412               int type, int protocol);
413 BOOL NETCON_close(WININET_NETCONNECTION *connection);
414 BOOL NETCON_connect(WININET_NETCONNECTION *connection, const struct sockaddr *serv_addr,
415                     unsigned int addrlen);
416 BOOL NETCON_secure_connect(WININET_NETCONNECTION *connection, LPCWSTR hostname);
417 BOOL NETCON_send(WININET_NETCONNECTION *connection, const void *msg, size_t len, int flags,
418                 int *sent /* out */);
419 BOOL NETCON_recv(WININET_NETCONNECTION *connection, void *buf, size_t len, int flags,
420                 int *recvd /* out */);
421 BOOL NETCON_query_data_available(WININET_NETCONNECTION *connection, DWORD *available);
422 LPCVOID NETCON_GetCert(WININET_NETCONNECTION *connection);
423 DWORD NETCON_set_timeout(WININET_NETCONNECTION *connection, BOOL send, int value);
424
425 extern void URLCacheContainers_CreateDefaults(void);
426 extern void URLCacheContainers_DeleteAll(void);
427
428 #define MAX_REPLY_LEN           0x5B4
429
430 /* Used for debugging - maybe need to be shared in the Wine debugging code ? */
431 typedef struct
432 {
433     DWORD val;
434     const char* name;
435 } wininet_flag_info;
436
437 #endif /* _WINE_INTERNET_H_ */