wined3d: Properly initialize a variable.
[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 #include "wine/unicode.h"
27
28 #include <time.h>
29 #ifdef HAVE_NETDB_H
30 # include <netdb.h>
31 #endif
32 #ifdef HAVE_NETINET_IN_H
33 # include <sys/types.h>
34 # include <netinet/in.h>
35 #endif
36 #ifdef HAVE_OPENSSL_SSL_H
37 #define DSA __ssl_DSA  /* avoid conflict with commctrl.h */
38 #undef FAR
39 # include <openssl/ssl.h>
40 #undef FAR
41 #define FAR do_not_use_this_in_wine
42 #undef DSA
43 #endif
44 #ifdef HAVE_SYS_SOCKET_H
45 # include <sys/socket.h>
46 #endif
47
48 #if defined(__MINGW32__) || defined (_MSC_VER)
49 #include "winsock2.h"
50 #ifndef MSG_WAITALL
51 #define MSG_WAITALL 0
52 #endif
53 #else
54 #define closesocket close
55 #endif /* __MINGW32__ */
56
57 /* used for netconnection.c stuff */
58 typedef struct
59 {
60     BOOL useSSL;
61     int socketFD;
62 #ifdef HAVE_OPENSSL_SSL_H
63     SSL *ssl_s;
64     char *peek_msg;
65     char *peek_msg_mem;
66     size_t peek_len;
67 #endif
68 } WININET_NETCONNECTION;
69
70 inline static LPSTR WININET_strdup( LPCSTR str )
71 {
72     LPSTR ret = HeapAlloc( GetProcessHeap(), 0, strlen(str) + 1 );
73     if (ret) strcpy( ret, str );
74     return ret;
75 }
76
77 inline static LPWSTR WININET_strdupW( LPCWSTR str )
78 {
79     LPWSTR ret = HeapAlloc( GetProcessHeap(), 0, (strlenW(str) + 1)*sizeof(WCHAR) );
80     if (ret) strcpyW( ret, str );
81     return ret;
82 }
83
84 inline static LPWSTR WININET_strdup_AtoW( LPCSTR str )
85 {
86     int len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0);
87     LPWSTR ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
88     if (ret)
89         MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len);
90     return ret;
91 }
92
93 inline static LPSTR WININET_strdup_WtoA( LPCWSTR str )
94 {
95     int len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
96     LPSTR ret = HeapAlloc( GetProcessHeap(), 0, len );
97     if (ret)
98         WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL);
99     return ret;
100 }
101
102 inline static void WININET_find_data_WtoA(LPWIN32_FIND_DATAW dataW, LPWIN32_FIND_DATAA dataA)
103 {
104     dataA->dwFileAttributes = dataW->dwFileAttributes;
105     dataA->ftCreationTime   = dataW->ftCreationTime;
106     dataA->ftLastAccessTime = dataW->ftLastAccessTime;
107     dataA->ftLastWriteTime  = dataW->ftLastWriteTime;
108     dataA->nFileSizeHigh    = dataW->nFileSizeHigh;
109     dataA->nFileSizeLow     = dataW->nFileSizeLow;
110     dataA->dwReserved0      = dataW->dwReserved0;
111     dataA->dwReserved1      = dataW->dwReserved1;
112     WideCharToMultiByte(CP_ACP, 0, dataW->cFileName, -1, 
113         dataA->cFileName, sizeof(dataA->cFileName),
114         NULL, NULL);
115     WideCharToMultiByte(CP_ACP, 0, dataW->cAlternateFileName, -1, 
116         dataA->cAlternateFileName, sizeof(dataA->cAlternateFileName),
117         NULL, NULL);
118 }
119
120 typedef enum
121 {
122     WH_HINIT = INTERNET_HANDLE_TYPE_INTERNET,
123     WH_HFTPSESSION = INTERNET_HANDLE_TYPE_CONNECT_FTP,
124     WH_HGOPHERSESSION = INTERNET_HANDLE_TYPE_CONNECT_GOPHER,
125     WH_HHTTPSESSION = INTERNET_HANDLE_TYPE_CONNECT_HTTP,
126     WH_HFILE = INTERNET_HANDLE_TYPE_FTP_FILE,
127     WH_HFINDNEXT = INTERNET_HANDLE_TYPE_FTP_FIND,
128     WH_HHTTPREQ = INTERNET_HANDLE_TYPE_HTTP_REQUEST,
129 } WH_TYPE;
130
131 #define INET_OPENURL 0x0001
132 #define INET_CALLBACKW 0x0002
133
134 struct _WININETHANDLEHEADER;
135 typedef struct _WININETHANDLEHEADER WININETHANDLEHEADER, *LPWININETHANDLEHEADER;
136
137 typedef void (*WININET_object_destructor)( LPWININETHANDLEHEADER );
138
139 struct _WININETHANDLEHEADER
140 {
141     WH_TYPE htype;
142     DWORD  dwFlags;
143     DWORD  dwContext;
144     DWORD  dwError;
145     DWORD  dwInternalFlags;
146     DWORD  dwRefCount;
147     WININET_object_destructor destroy;
148     INTERNET_STATUS_CALLBACK lpfnStatusCB;
149     struct _WININETHANDLEHEADER *lpwhparent;
150 };
151
152
153 typedef struct
154 {
155     WININETHANDLEHEADER hdr;
156     LPWSTR  lpszAgent;
157     LPWSTR  lpszProxy;
158     LPWSTR  lpszProxyBypass;
159     LPWSTR  lpszProxyUsername;
160     LPWSTR  lpszProxyPassword;
161     DWORD   dwAccessType;
162 } WININETAPPINFOW, *LPWININETAPPINFOW;
163
164
165 typedef struct
166 {
167     WININETHANDLEHEADER hdr;
168     LPWSTR  lpszHostName; /* the final destination of the request */
169     LPWSTR  lpszServerName; /* the name of the server we directly connect to */
170     LPWSTR  lpszUserName;
171     INTERNET_PORT nHostPort; /* the final destination port of the request */
172     INTERNET_PORT nServerPort; /* the port of the server we directly connect to */
173     struct sockaddr_in socketAddress;
174 } WININETHTTPSESSIONW, *LPWININETHTTPSESSIONW;
175
176 #define HDR_ISREQUEST           0x0001
177 #define HDR_COMMADELIMITED      0x0002
178 #define HDR_SEMIDELIMITED       0x0004
179
180 typedef struct
181 {
182     LPWSTR lpszField;
183     LPWSTR lpszValue;
184     WORD wFlags;
185     WORD wCount;
186 } HTTPHEADERW, *LPHTTPHEADERW;
187
188
189 typedef struct
190 {
191     WININETHANDLEHEADER hdr;
192     LPWSTR lpszPath;
193     LPWSTR lpszVerb;
194     LPWSTR lpszRawHeaders;
195     WININET_NETCONNECTION netConnection;
196     LPWSTR lpszVersion;
197     LPWSTR lpszStatusText;
198     HTTPHEADERW *pCustHeaders;
199     DWORD nCustHeaders;
200 } WININETHTTPREQW, *LPWININETHTTPREQW;
201
202
203 typedef struct
204 {
205     WININETHANDLEHEADER hdr;
206     BOOL session_deleted;
207     int nDataSocket;
208 } WININETFILE, *LPWININETFILE;
209
210
211 typedef struct
212 {
213     WININETHANDLEHEADER hdr;
214     int sndSocket;
215     int lstnSocket;
216     int pasvSocket; /* data socket connected by us in case of passive FTP */
217     LPWININETFILE download_in_progress;
218     struct sockaddr_in socketAddress;
219     struct sockaddr_in lstnSocketAddress;
220     LPWSTR  lpszPassword;
221     LPWSTR  lpszUserName;
222 } WININETFTPSESSIONW, *LPWININETFTPSESSIONW;
223
224
225 typedef struct
226 {
227     BOOL bIsDirectory;
228     LPWSTR lpszName;
229     DWORD nSize;
230     struct tm tmLastModified;
231     unsigned short permissions;
232 } FILEPROPERTIESW, *LPFILEPROPERTIESW;
233
234
235 typedef struct
236 {
237     WININETHANDLEHEADER hdr;
238     DWORD index;
239     DWORD size;
240     LPFILEPROPERTIESW lpafp;
241 } WININETFINDNEXTW, *LPWININETFINDNEXTW;
242
243 typedef enum
244 {
245     FTPPUTFILEW,
246     FTPSETCURRENTDIRECTORYW,
247     FTPCREATEDIRECTORYW,
248     FTPFINDFIRSTFILEW,
249     FTPGETCURRENTDIRECTORYW,
250     FTPOPENFILEW,
251     FTPGETFILEW,
252     FTPDELETEFILEW,
253     FTPREMOVEDIRECTORYW,
254     FTPRENAMEFILEW,
255     INTERNETFINDNEXTW,
256     HTTPSENDREQUESTW,
257     HTTPOPENREQUESTW,
258     SENDCALLBACK,
259     INTERNETOPENURLW,
260     INTERNETREADFILEEXA,
261 } ASYNC_FUNC;
262
263 struct WORKREQ_FTPPUTFILEW
264 {
265     LPWSTR lpszLocalFile;
266     LPWSTR lpszNewRemoteFile;
267     DWORD  dwFlags;
268     DWORD  dwContext;
269 };
270
271 struct WORKREQ_FTPSETCURRENTDIRECTORYW
272 {
273     LPWSTR lpszDirectory;
274 };
275
276 struct WORKREQ_FTPCREATEDIRECTORYW
277 {
278     LPWSTR lpszDirectory;
279 };
280
281 struct WORKREQ_FTPFINDFIRSTFILEW
282 {
283     LPWSTR lpszSearchFile;
284     LPWIN32_FIND_DATAW lpFindFileData;
285     DWORD  dwFlags;
286     DWORD  dwContext;
287 };
288
289 struct WORKREQ_FTPGETCURRENTDIRECTORYW
290 {
291     LPWSTR lpszDirectory;
292     DWORD *lpdwDirectory;
293 };
294
295 struct WORKREQ_FTPOPENFILEW
296 {
297     LPWSTR lpszFilename;
298     DWORD  dwAccess;
299     DWORD  dwFlags;
300     DWORD  dwContext;
301 };
302
303 struct WORKREQ_FTPGETFILEW
304 {
305     LPWSTR lpszRemoteFile;
306     LPWSTR lpszNewFile;
307     BOOL   fFailIfExists;
308     DWORD  dwLocalFlagsAttribute;
309     DWORD  dwFlags;
310     DWORD  dwContext;
311 };
312
313 struct WORKREQ_FTPDELETEFILEW
314 {
315     LPWSTR lpszFilename;
316 };
317
318 struct WORKREQ_FTPREMOVEDIRECTORYW
319 {
320     LPWSTR lpszDirectory;
321 };
322
323 struct WORKREQ_FTPRENAMEFILEW
324 {
325     LPWSTR lpszSrcFile;
326     LPWSTR lpszDestFile;
327 };
328
329 struct WORKREQ_INTERNETFINDNEXTW
330 {
331     LPWIN32_FIND_DATAW lpFindFileData;
332 };
333
334 struct WORKREQ_HTTPOPENREQUESTW
335 {
336     LPWSTR lpszVerb;
337     LPWSTR lpszObjectName;
338     LPWSTR lpszVersion;
339     LPWSTR lpszReferrer;
340     LPCWSTR *lpszAcceptTypes;
341     DWORD  dwFlags;
342     DWORD  dwContext;
343 };
344
345 struct WORKREQ_HTTPSENDREQUESTW
346 {
347     LPWSTR lpszHeader;
348     DWORD  dwHeaderLength;
349     LPVOID lpOptional;
350     DWORD  dwOptionalLength;
351     DWORD  dwContentLength;
352     BOOL   bEndRequest;
353 };
354
355 struct WORKREQ_SENDCALLBACK
356 {
357     DWORD     dwContext;
358     DWORD     dwInternetStatus;
359     LPVOID    lpvStatusInfo;
360     DWORD     dwStatusInfoLength;
361 };
362
363 struct WORKREQ_INTERNETOPENURLW
364 {
365     HINTERNET hInternet;
366     LPWSTR     lpszUrl;
367     LPWSTR     lpszHeaders;
368     DWORD     dwHeadersLength;
369     DWORD     dwFlags;
370     DWORD     dwContext;
371 };
372
373 struct WORKREQ_INTERNETREADFILEEXA
374 {
375     LPINTERNET_BUFFERSA lpBuffersOut;
376 };
377
378 typedef struct WORKREQ
379 {
380     ASYNC_FUNC asyncall;
381     WININETHANDLEHEADER *hdr;
382
383     union {
384         struct WORKREQ_FTPPUTFILEW              FtpPutFileW;
385         struct WORKREQ_FTPSETCURRENTDIRECTORYW  FtpSetCurrentDirectoryW;
386         struct WORKREQ_FTPCREATEDIRECTORYW      FtpCreateDirectoryW;
387         struct WORKREQ_FTPFINDFIRSTFILEW        FtpFindFirstFileW;
388         struct WORKREQ_FTPGETCURRENTDIRECTORYW  FtpGetCurrentDirectoryW;
389         struct WORKREQ_FTPOPENFILEW             FtpOpenFileW;
390         struct WORKREQ_FTPGETFILEW              FtpGetFileW;
391         struct WORKREQ_FTPDELETEFILEW           FtpDeleteFileW;
392         struct WORKREQ_FTPREMOVEDIRECTORYW      FtpRemoveDirectoryW;
393         struct WORKREQ_FTPRENAMEFILEW           FtpRenameFileW;
394         struct WORKREQ_INTERNETFINDNEXTW        InternetFindNextW;
395         struct WORKREQ_HTTPOPENREQUESTW         HttpOpenRequestW;
396         struct WORKREQ_HTTPSENDREQUESTW         HttpSendRequestW;
397         struct WORKREQ_SENDCALLBACK             SendCallback;
398         struct WORKREQ_INTERNETOPENURLW         InternetOpenUrlW;
399         struct WORKREQ_INTERNETREADFILEEXA      InternetReadFileExA;
400     } u;
401
402     struct WORKREQ *next;
403     struct WORKREQ *prev;
404
405 } WORKREQUEST, *LPWORKREQUEST;
406
407 HINTERNET WININET_AllocHandle( LPWININETHANDLEHEADER info );
408 LPWININETHANDLEHEADER WININET_GetObject( HINTERNET hinternet );
409 LPWININETHANDLEHEADER WININET_AddRef( LPWININETHANDLEHEADER info );
410 BOOL WININET_Release( LPWININETHANDLEHEADER info );
411 BOOL WININET_FreeHandle( HINTERNET hinternet );
412 HINTERNET WININET_FindHandle( LPWININETHANDLEHEADER info );
413
414 time_t ConvertTimeString(LPCWSTR asctime);
415
416 HINTERNET FTP_Connect(LPWININETAPPINFOW hIC, LPCWSTR lpszServerName,
417         INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
418         LPCWSTR lpszPassword, DWORD dwFlags, DWORD dwContext,
419         DWORD dwInternalFlags);
420
421 HINTERNET HTTP_Connect(LPWININETAPPINFOW hIC, LPCWSTR lpszServerName,
422         INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
423         LPCWSTR lpszPassword, DWORD dwFlags, DWORD dwContext,
424         DWORD dwInternalFlags);
425
426 BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
427         struct sockaddr_in *psa);
428
429 void INTERNET_SetLastError(DWORD dwError);
430 DWORD INTERNET_GetLastError(void);
431 BOOL INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest);
432 LPSTR INTERNET_GetResponseBuffer(void);
433 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen);
434
435 BOOLAPI FTP_FtpPutFileW(LPWININETFTPSESSIONW lpwfs, LPCWSTR lpszLocalFile,
436     LPCWSTR lpszNewRemoteFile, DWORD dwFlags, DWORD dwContext);
437 BOOLAPI FTP_FtpSetCurrentDirectoryW(LPWININETFTPSESSIONW lpwfs, LPCWSTR lpszDirectory);
438 BOOLAPI FTP_FtpCreateDirectoryW(LPWININETFTPSESSIONW lpwfs, LPCWSTR lpszDirectory);
439 INTERNETAPI HINTERNET WINAPI FTP_FtpFindFirstFileW(LPWININETFTPSESSIONW lpwfs,
440     LPCWSTR lpszSearchFile, LPWIN32_FIND_DATAW lpFindFileData, DWORD dwFlags, DWORD dwContext);
441 BOOLAPI FTP_FtpGetCurrentDirectoryW(LPWININETFTPSESSIONW lpwfs, LPWSTR lpszCurrentDirectory,
442         LPDWORD lpdwCurrentDirectory);
443 BOOL FTP_ConvertFileProp(LPFILEPROPERTIESW lpafp, LPWIN32_FIND_DATAW lpFindFileData);
444 BOOL FTP_FtpRenameFileW(LPWININETFTPSESSIONW lpwfs, LPCWSTR lpszSrc, LPCWSTR lpszDest);
445 BOOL FTP_FtpRemoveDirectoryW(LPWININETFTPSESSIONW lpwfs, LPCWSTR lpszDirectory);
446 BOOL FTP_FtpDeleteFileW(LPWININETFTPSESSIONW lpwfs, LPCWSTR lpszFileName);
447 HINTERNET FTP_FtpOpenFileW(LPWININETFTPSESSIONW lpwfs, LPCWSTR lpszFileName,
448         DWORD fdwAccess, DWORD dwFlags, DWORD dwContext);
449 BOOLAPI FTP_FtpGetFileW(LPWININETFTPSESSIONW lpwfs, LPCWSTR lpszRemoteFile, LPCWSTR lpszNewFile,
450         BOOL fFailIfExists, DWORD dwLocalFlagsAttribute, DWORD dwInternetFlags,
451         DWORD dwContext);
452
453 BOOLAPI HTTP_HttpSendRequestW(LPWININETHTTPREQW lpwhr, LPCWSTR lpszHeaders,
454         DWORD dwHeaderLength, LPVOID lpOptional, DWORD dwOptionalLength,
455         DWORD dwContentLength, BOOL bEndRequest);
456 INTERNETAPI HINTERNET WINAPI HTTP_HttpOpenRequestW(LPWININETHTTPSESSIONW lpwhs,
457         LPCWSTR lpszVerb, LPCWSTR lpszObjectName, LPCWSTR lpszVersion,
458         LPCWSTR lpszReferrer , LPCWSTR *lpszAcceptTypes,
459         DWORD dwFlags, DWORD dwContext);
460
461 VOID SendAsyncCallback(LPWININETHANDLEHEADER hdr, DWORD dwContext,
462                        DWORD dwInternetStatus, LPVOID lpvStatusInfo,
463                        DWORD dwStatusInfoLength);
464
465 VOID INTERNET_SendCallback(LPWININETHANDLEHEADER hdr, DWORD dwContext,
466                            DWORD dwInternetStatus, LPVOID lpvStatusInfo,
467                            DWORD dwStatusInfoLength);
468
469 LPHTTPHEADERW HTTP_GetHeader(LPWININETHTTPREQW lpwhr, LPCWSTR header);
470
471 BOOL NETCON_connected(WININET_NETCONNECTION *connection);
472 BOOL NETCON_init(WININET_NETCONNECTION *connnection, BOOL useSSL);
473 BOOL NETCON_create(WININET_NETCONNECTION *connection, int domain,
474               int type, int protocol);
475 BOOL NETCON_close(WININET_NETCONNECTION *connection);
476 BOOL NETCON_connect(WININET_NETCONNECTION *connection, const struct sockaddr *serv_addr,
477                     unsigned int addrlen);
478 BOOL NETCON_secure_connect(WININET_NETCONNECTION *connection, LPCWSTR hostname);
479 BOOL NETCON_send(WININET_NETCONNECTION *connection, const void *msg, size_t len, int flags,
480                 int *sent /* out */);
481 BOOL NETCON_recv(WININET_NETCONNECTION *connection, void *buf, size_t len, int flags,
482                 int *recvd /* out */);
483 BOOL NETCON_getNextLine(WININET_NETCONNECTION *connection, LPSTR lpszBuffer, LPDWORD dwBuffer);
484 LPCVOID NETCON_GetCert(WININET_NETCONNECTION *connection);
485 BOOL NETCON_set_timeout(WININET_NETCONNECTION *connection, BOOL send, int value);
486
487 extern void URLCacheContainers_CreateDefaults(void);
488 extern void URLCacheContainers_DeleteAll(void);
489
490 #define MAX_REPLY_LEN           0x5B4
491
492 /* Used for debugging - maybe need to be shared in the Wine debugging code ? */
493 typedef struct
494 {
495     DWORD val;
496     const char* name;
497 } wininet_flag_info;
498
499 #endif /* _WINE_INTERNET_H_ */