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