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