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