wined3d: Eliminate a redundant local variable in get_loop_control_const().
[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 _WININETHANDLEHEADER WININETHANDLEHEADER, *LPWININETHANDLEHEADER;
116
117 typedef struct {
118     void (*Destroy)(WININETHANDLEHEADER*);
119     void (*CloseConnection)(WININETHANDLEHEADER*);
120     DWORD (*QueryOption)(WININETHANDLEHEADER*,DWORD,void*,DWORD*,BOOL);
121     DWORD (*SetOption)(WININETHANDLEHEADER*,DWORD,void*,DWORD);
122     DWORD (*ReadFile)(WININETHANDLEHEADER*,void*,DWORD,DWORD*);
123     DWORD (*ReadFileExA)(WININETHANDLEHEADER*,INTERNET_BUFFERSA*,DWORD,DWORD_PTR);
124     DWORD (*ReadFileExW)(WININETHANDLEHEADER*,INTERNET_BUFFERSW*,DWORD,DWORD_PTR);
125     BOOL (*WriteFile)(WININETHANDLEHEADER*,const void*,DWORD,DWORD*);
126     DWORD (*QueryDataAvailable)(WININETHANDLEHEADER*,DWORD*,DWORD,DWORD_PTR);
127     DWORD (*FindNextFileW)(WININETHANDLEHEADER*,void*);
128 } HANDLEHEADERVtbl;
129
130 struct _WININETHANDLEHEADER
131 {
132     WH_TYPE htype;
133     const HANDLEHEADERVtbl *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     WININETHANDLEHEADER hdr;
149     LPWSTR  lpszAgent;
150     LPWSTR  lpszProxy;
151     LPWSTR  lpszProxyBypass;
152     LPWSTR  lpszProxyUsername;
153     LPWSTR  lpszProxyPassword;
154     DWORD   dwAccessType;
155 } WININETAPPINFOW, *LPWININETAPPINFOW;
156
157
158 typedef struct
159 {
160     WININETHANDLEHEADER hdr;
161     WININETAPPINFOW *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_in socketAddress;
169 } WININETHTTPSESSIONW, *LPWININETHTTPSESSIONW;
170
171 #define HDR_ISREQUEST           0x0001
172 #define HDR_COMMADELIMITED      0x0002
173 #define HDR_SEMIDELIMITED       0x0004
174
175 typedef struct
176 {
177     LPWSTR lpszField;
178     LPWSTR lpszValue;
179     WORD wFlags;
180     WORD wCount;
181 } HTTPHEADERW, *LPHTTPHEADERW;
182
183
184 struct HttpAuthInfo;
185
186 typedef struct gzip_stream_t gzip_stream_t;
187
188 typedef struct
189 {
190     WININETHANDLEHEADER hdr;
191     WININETHTTPSESSIONW *lpHttpSession;
192     LPWSTR lpszPath;
193     LPWSTR lpszVerb;
194     LPWSTR lpszRawHeaders;
195     WININET_NETCONNECTION netConnection;
196     LPWSTR lpszVersion;
197     LPWSTR lpszStatusText;
198     DWORD dwBytesToWrite;
199     DWORD dwBytesWritten;
200     HTTPHEADERW *pCustHeaders;
201     DWORD nCustHeaders;
202     HANDLE hCacheFile;
203     LPWSTR lpszCacheFile;
204     struct HttpAuthInfo *pAuthInfo;
205     struct HttpAuthInfo *pProxyAuthInfo;
206
207     CRITICAL_SECTION read_section;  /* section to protect the following fields */
208     DWORD dwContentLength; /* total number of bytes to be read */
209     DWORD dwContentRead;  /* bytes of the content read so far */
210     BOOL  read_chunked;   /* are we reading in chunked mode? */
211     DWORD read_pos;       /* current read position in read_buf */
212     DWORD read_size;      /* valid data size in read_buf */
213     BYTE  read_buf[4096]; /* buffer for already read but not returned data */
214
215     BOOL decoding;
216     gzip_stream_t *gzip_stream;
217 } WININETHTTPREQW, *LPWININETHTTPREQW;
218
219
220
221 struct WORKREQ_FTPPUTFILEW
222 {
223     LPWSTR lpszLocalFile;
224     LPWSTR lpszNewRemoteFile;
225     DWORD  dwFlags;
226     DWORD_PTR dwContext;
227 };
228
229 struct WORKREQ_FTPSETCURRENTDIRECTORYW
230 {
231     LPWSTR lpszDirectory;
232 };
233
234 struct WORKREQ_FTPCREATEDIRECTORYW
235 {
236     LPWSTR lpszDirectory;
237 };
238
239 struct WORKREQ_FTPFINDFIRSTFILEW
240 {
241     LPWSTR lpszSearchFile;
242     LPWIN32_FIND_DATAW lpFindFileData;
243     DWORD  dwFlags;
244     DWORD_PTR dwContext;
245 };
246
247 struct WORKREQ_FTPGETCURRENTDIRECTORYW
248 {
249     LPWSTR lpszDirectory;
250     DWORD *lpdwDirectory;
251 };
252
253 struct WORKREQ_FTPOPENFILEW
254 {
255     LPWSTR lpszFilename;
256     DWORD  dwAccess;
257     DWORD  dwFlags;
258     DWORD_PTR dwContext;
259 };
260
261 struct WORKREQ_FTPGETFILEW
262 {
263     LPWSTR lpszRemoteFile;
264     LPWSTR lpszNewFile;
265     BOOL   fFailIfExists;
266     DWORD  dwLocalFlagsAttribute;
267     DWORD  dwFlags;
268     DWORD_PTR dwContext;
269 };
270
271 struct WORKREQ_FTPDELETEFILEW
272 {
273     LPWSTR lpszFilename;
274 };
275
276 struct WORKREQ_FTPREMOVEDIRECTORYW
277 {
278     LPWSTR lpszDirectory;
279 };
280
281 struct WORKREQ_FTPRENAMEFILEW
282 {
283     LPWSTR lpszSrcFile;
284     LPWSTR lpszDestFile;
285 };
286
287 struct WORKREQ_FTPFINDNEXTW
288 {
289     LPWIN32_FIND_DATAW lpFindFileData;
290 };
291
292 struct WORKREQ_HTTPSENDREQUESTW
293 {
294     LPWSTR lpszHeader;
295     DWORD  dwHeaderLength;
296     LPVOID lpOptional;
297     DWORD  dwOptionalLength;
298     DWORD  dwContentLength;
299     BOOL   bEndRequest;
300 };
301
302 struct WORKREQ_HTTPENDREQUESTW
303 {
304     DWORD     dwFlags;
305     DWORD_PTR dwContext;
306 };
307
308 struct WORKREQ_SENDCALLBACK
309 {
310     DWORD_PTR dwContext;
311     DWORD     dwInternetStatus;
312     LPVOID    lpvStatusInfo;
313     DWORD     dwStatusInfoLength;
314 };
315
316 struct WORKREQ_INTERNETOPENURLW
317 {
318     HINTERNET hInternet;
319     LPWSTR     lpszUrl;
320     LPWSTR     lpszHeaders;
321     DWORD     dwHeadersLength;
322     DWORD     dwFlags;
323     DWORD_PTR dwContext;
324 };
325
326 struct WORKREQ_INTERNETREADFILEEXA
327 {
328     LPINTERNET_BUFFERSA lpBuffersOut;
329 };
330
331 struct WORKREQ_INTERNETREADFILEEXW
332 {
333     LPINTERNET_BUFFERSW lpBuffersOut;
334 };
335
336 typedef struct WORKREQ
337 {
338     void (*asyncproc)(struct WORKREQ*);
339     WININETHANDLEHEADER *hdr;
340
341     union {
342         struct WORKREQ_FTPPUTFILEW              FtpPutFileW;
343         struct WORKREQ_FTPSETCURRENTDIRECTORYW  FtpSetCurrentDirectoryW;
344         struct WORKREQ_FTPCREATEDIRECTORYW      FtpCreateDirectoryW;
345         struct WORKREQ_FTPFINDFIRSTFILEW        FtpFindFirstFileW;
346         struct WORKREQ_FTPGETCURRENTDIRECTORYW  FtpGetCurrentDirectoryW;
347         struct WORKREQ_FTPOPENFILEW             FtpOpenFileW;
348         struct WORKREQ_FTPGETFILEW              FtpGetFileW;
349         struct WORKREQ_FTPDELETEFILEW           FtpDeleteFileW;
350         struct WORKREQ_FTPREMOVEDIRECTORYW      FtpRemoveDirectoryW;
351         struct WORKREQ_FTPRENAMEFILEW           FtpRenameFileW;
352         struct WORKREQ_FTPFINDNEXTW             FtpFindNextW;
353         struct WORKREQ_HTTPSENDREQUESTW         HttpSendRequestW;
354         struct WORKREQ_HTTPENDREQUESTW          HttpEndRequestW;
355         struct WORKREQ_SENDCALLBACK             SendCallback;
356         struct WORKREQ_INTERNETOPENURLW         InternetOpenUrlW;
357         struct WORKREQ_INTERNETREADFILEEXA      InternetReadFileExA;
358         struct WORKREQ_INTERNETREADFILEEXW      InternetReadFileExW;
359     } u;
360
361 } WORKREQUEST, *LPWORKREQUEST;
362
363 HINTERNET WININET_AllocHandle( LPWININETHANDLEHEADER info );
364 LPWININETHANDLEHEADER WININET_GetObject( HINTERNET hinternet );
365 LPWININETHANDLEHEADER WININET_AddRef( LPWININETHANDLEHEADER info );
366 BOOL WININET_Release( LPWININETHANDLEHEADER info );
367 BOOL WININET_FreeHandle( HINTERNET hinternet );
368
369 DWORD INET_QueryOption(DWORD,void*,DWORD*,BOOL);
370
371 time_t ConvertTimeString(LPCWSTR asctime);
372
373 HINTERNET FTP_Connect(LPWININETAPPINFOW hIC, LPCWSTR lpszServerName,
374         INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
375         LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
376         DWORD dwInternalFlags);
377
378 HINTERNET HTTP_Connect(LPWININETAPPINFOW hIC, LPCWSTR lpszServerName,
379         INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
380         LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
381         DWORD dwInternalFlags);
382
383 BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
384         struct sockaddr_in *psa);
385
386 void INTERNET_SetLastError(DWORD dwError);
387 DWORD INTERNET_GetLastError(void);
388 BOOL INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest);
389 LPSTR INTERNET_GetResponseBuffer(void);
390 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen);
391
392 BOOLAPI HTTP_HttpSendRequestW(LPWININETHTTPREQW lpwhr, LPCWSTR lpszHeaders,
393         DWORD dwHeaderLength, LPVOID lpOptional, DWORD dwOptionalLength,
394         DWORD dwContentLength, BOOL bEndRequest);
395 INTERNETAPI HINTERNET WINAPI HTTP_HttpOpenRequestW(LPWININETHTTPSESSIONW lpwhs,
396         LPCWSTR lpszVerb, LPCWSTR lpszObjectName, LPCWSTR lpszVersion,
397         LPCWSTR lpszReferrer , LPCWSTR *lpszAcceptTypes,
398         DWORD dwFlags, DWORD_PTR dwContext);
399
400 VOID SendAsyncCallback(LPWININETHANDLEHEADER hdr, DWORD_PTR dwContext,
401                        DWORD dwInternetStatus, LPVOID lpvStatusInfo,
402                        DWORD dwStatusInfoLength);
403
404 VOID INTERNET_SendCallback(LPWININETHANDLEHEADER hdr, DWORD_PTR dwContext,
405                            DWORD dwInternetStatus, LPVOID lpvStatusInfo,
406                            DWORD dwStatusInfoLength);
407
408 BOOL NETCON_connected(WININET_NETCONNECTION *connection);
409 BOOL NETCON_init(WININET_NETCONNECTION *connnection, BOOL useSSL);
410 BOOL NETCON_create(WININET_NETCONNECTION *connection, int domain,
411               int type, int protocol);
412 BOOL NETCON_close(WININET_NETCONNECTION *connection);
413 BOOL NETCON_connect(WININET_NETCONNECTION *connection, const struct sockaddr *serv_addr,
414                     unsigned int addrlen);
415 BOOL NETCON_secure_connect(WININET_NETCONNECTION *connection, LPCWSTR hostname);
416 BOOL NETCON_send(WININET_NETCONNECTION *connection, const void *msg, size_t len, int flags,
417                 int *sent /* out */);
418 BOOL NETCON_recv(WININET_NETCONNECTION *connection, void *buf, size_t len, int flags,
419                 int *recvd /* out */);
420 BOOL NETCON_query_data_available(WININET_NETCONNECTION *connection, DWORD *available);
421 LPCVOID NETCON_GetCert(WININET_NETCONNECTION *connection);
422 DWORD NETCON_set_timeout(WININET_NETCONNECTION *connection, BOOL send, int value);
423
424 extern void URLCacheContainers_CreateDefaults(void);
425 extern void URLCacheContainers_DeleteAll(void);
426
427 #define MAX_REPLY_LEN           0x5B4
428
429 /* Used for debugging - maybe need to be shared in the Wine debugging code ? */
430 typedef struct
431 {
432     DWORD val;
433     const char* name;
434 } wininet_flag_info;
435
436 #endif /* _WINE_INTERNET_H_ */