msctf: Use FAILED instead of !SUCCEDED.
[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
187 {
188     WININETHANDLEHEADER hdr;
189     WININETHTTPSESSIONW *lpHttpSession;
190     LPWSTR lpszPath;
191     LPWSTR lpszVerb;
192     LPWSTR lpszRawHeaders;
193     WININET_NETCONNECTION netConnection;
194     LPWSTR lpszVersion;
195     LPWSTR lpszStatusText;
196     DWORD dwContentLength; /* total number of bytes to be read */
197     DWORD dwContentRead; /* bytes of the content read so far */
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     BOOL  read_chunked;   /* are we reading in chunked mode? */
207     DWORD read_pos;       /* current read position in read_buf */
208     DWORD read_size;      /* valid data size in read_buf */
209     char  read_buf[4096]; /* buffer for already read but not returned data */
210 } WININETHTTPREQW, *LPWININETHTTPREQW;
211
212
213
214 struct WORKREQ_FTPPUTFILEW
215 {
216     LPWSTR lpszLocalFile;
217     LPWSTR lpszNewRemoteFile;
218     DWORD  dwFlags;
219     DWORD_PTR dwContext;
220 };
221
222 struct WORKREQ_FTPSETCURRENTDIRECTORYW
223 {
224     LPWSTR lpszDirectory;
225 };
226
227 struct WORKREQ_FTPCREATEDIRECTORYW
228 {
229     LPWSTR lpszDirectory;
230 };
231
232 struct WORKREQ_FTPFINDFIRSTFILEW
233 {
234     LPWSTR lpszSearchFile;
235     LPWIN32_FIND_DATAW lpFindFileData;
236     DWORD  dwFlags;
237     DWORD_PTR dwContext;
238 };
239
240 struct WORKREQ_FTPGETCURRENTDIRECTORYW
241 {
242     LPWSTR lpszDirectory;
243     DWORD *lpdwDirectory;
244 };
245
246 struct WORKREQ_FTPOPENFILEW
247 {
248     LPWSTR lpszFilename;
249     DWORD  dwAccess;
250     DWORD  dwFlags;
251     DWORD_PTR dwContext;
252 };
253
254 struct WORKREQ_FTPGETFILEW
255 {
256     LPWSTR lpszRemoteFile;
257     LPWSTR lpszNewFile;
258     BOOL   fFailIfExists;
259     DWORD  dwLocalFlagsAttribute;
260     DWORD  dwFlags;
261     DWORD_PTR dwContext;
262 };
263
264 struct WORKREQ_FTPDELETEFILEW
265 {
266     LPWSTR lpszFilename;
267 };
268
269 struct WORKREQ_FTPREMOVEDIRECTORYW
270 {
271     LPWSTR lpszDirectory;
272 };
273
274 struct WORKREQ_FTPRENAMEFILEW
275 {
276     LPWSTR lpszSrcFile;
277     LPWSTR lpszDestFile;
278 };
279
280 struct WORKREQ_FTPFINDNEXTW
281 {
282     LPWIN32_FIND_DATAW lpFindFileData;
283 };
284
285 struct WORKREQ_HTTPSENDREQUESTW
286 {
287     LPWSTR lpszHeader;
288     DWORD  dwHeaderLength;
289     LPVOID lpOptional;
290     DWORD  dwOptionalLength;
291     DWORD  dwContentLength;
292     BOOL   bEndRequest;
293 };
294
295 struct WORKREQ_HTTPENDREQUESTW
296 {
297     DWORD     dwFlags;
298     DWORD_PTR dwContext;
299 };
300
301 struct WORKREQ_SENDCALLBACK
302 {
303     DWORD_PTR dwContext;
304     DWORD     dwInternetStatus;
305     LPVOID    lpvStatusInfo;
306     DWORD     dwStatusInfoLength;
307 };
308
309 struct WORKREQ_INTERNETOPENURLW
310 {
311     HINTERNET hInternet;
312     LPWSTR     lpszUrl;
313     LPWSTR     lpszHeaders;
314     DWORD     dwHeadersLength;
315     DWORD     dwFlags;
316     DWORD_PTR dwContext;
317 };
318
319 struct WORKREQ_INTERNETREADFILEEXA
320 {
321     LPINTERNET_BUFFERSA lpBuffersOut;
322 };
323
324 struct WORKREQ_INTERNETREADFILEEXW
325 {
326     LPINTERNET_BUFFERSW lpBuffersOut;
327 };
328
329 typedef struct WORKREQ
330 {
331     void (*asyncproc)(struct WORKREQ*);
332     WININETHANDLEHEADER *hdr;
333
334     union {
335         struct WORKREQ_FTPPUTFILEW              FtpPutFileW;
336         struct WORKREQ_FTPSETCURRENTDIRECTORYW  FtpSetCurrentDirectoryW;
337         struct WORKREQ_FTPCREATEDIRECTORYW      FtpCreateDirectoryW;
338         struct WORKREQ_FTPFINDFIRSTFILEW        FtpFindFirstFileW;
339         struct WORKREQ_FTPGETCURRENTDIRECTORYW  FtpGetCurrentDirectoryW;
340         struct WORKREQ_FTPOPENFILEW             FtpOpenFileW;
341         struct WORKREQ_FTPGETFILEW              FtpGetFileW;
342         struct WORKREQ_FTPDELETEFILEW           FtpDeleteFileW;
343         struct WORKREQ_FTPREMOVEDIRECTORYW      FtpRemoveDirectoryW;
344         struct WORKREQ_FTPRENAMEFILEW           FtpRenameFileW;
345         struct WORKREQ_FTPFINDNEXTW             FtpFindNextW;
346         struct WORKREQ_HTTPSENDREQUESTW         HttpSendRequestW;
347         struct WORKREQ_HTTPENDREQUESTW          HttpEndRequestW;
348         struct WORKREQ_SENDCALLBACK             SendCallback;
349         struct WORKREQ_INTERNETOPENURLW         InternetOpenUrlW;
350         struct WORKREQ_INTERNETREADFILEEXA      InternetReadFileExA;
351         struct WORKREQ_INTERNETREADFILEEXW      InternetReadFileExW;
352     } u;
353
354 } WORKREQUEST, *LPWORKREQUEST;
355
356 HINTERNET WININET_AllocHandle( LPWININETHANDLEHEADER info );
357 LPWININETHANDLEHEADER WININET_GetObject( HINTERNET hinternet );
358 LPWININETHANDLEHEADER WININET_AddRef( LPWININETHANDLEHEADER info );
359 BOOL WININET_Release( LPWININETHANDLEHEADER info );
360 BOOL WININET_FreeHandle( HINTERNET hinternet );
361
362 DWORD INET_QueryOption(DWORD,void*,DWORD*,BOOL);
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
393 VOID SendAsyncCallback(LPWININETHANDLEHEADER hdr, DWORD_PTR dwContext,
394                        DWORD dwInternetStatus, LPVOID lpvStatusInfo,
395                        DWORD dwStatusInfoLength);
396
397 VOID INTERNET_SendCallback(LPWININETHANDLEHEADER hdr, DWORD_PTR dwContext,
398                            DWORD dwInternetStatus, LPVOID lpvStatusInfo,
399                            DWORD dwStatusInfoLength);
400
401 BOOL NETCON_connected(WININET_NETCONNECTION *connection);
402 BOOL NETCON_init(WININET_NETCONNECTION *connnection, BOOL useSSL);
403 BOOL NETCON_create(WININET_NETCONNECTION *connection, int domain,
404               int type, int protocol);
405 BOOL NETCON_close(WININET_NETCONNECTION *connection);
406 BOOL NETCON_connect(WININET_NETCONNECTION *connection, const struct sockaddr *serv_addr,
407                     unsigned int addrlen);
408 BOOL NETCON_secure_connect(WININET_NETCONNECTION *connection, LPCWSTR hostname);
409 BOOL NETCON_send(WININET_NETCONNECTION *connection, const void *msg, size_t len, int flags,
410                 int *sent /* out */);
411 BOOL NETCON_recv(WININET_NETCONNECTION *connection, void *buf, size_t len, int flags,
412                 int *recvd /* out */);
413 BOOL NETCON_query_data_available(WININET_NETCONNECTION *connection, DWORD *available);
414 LPCVOID NETCON_GetCert(WININET_NETCONNECTION *connection);
415 DWORD NETCON_set_timeout(WININET_NETCONNECTION *connection, BOOL send, int value);
416
417 extern void URLCacheContainers_CreateDefaults(void);
418 extern void URLCacheContainers_DeleteAll(void);
419
420 #define MAX_REPLY_LEN           0x5B4
421
422 /* Used for debugging - maybe need to be shared in the Wine debugging code ? */
423 typedef struct
424 {
425     DWORD val;
426     const char* name;
427 } wininet_flag_info;
428
429 #endif /* _WINE_INTERNET_H_ */