Implemented proper asynchronous InternetOpenUrl handling.
[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 <time.h>
27 #ifdef HAVE_NETDB_H
28 # include <netdb.h>
29 #endif
30 #ifdef HAVE_NETINET_IN_H
31 # include <sys/types.h>
32 # include <netinet/in.h>
33 #endif
34 #ifdef HAVE_OPENSSL_SSL_H
35 #define DSA __ssl_DSA  /* avoid conflict with commctrl.h */
36 #undef FAR
37 # include <openssl/ssl.h>
38 #undef FAR
39 #define FAR do_not_use_this_in_wine
40 #undef DSA
41 #endif
42 #ifdef HAVE_SYS_SOCKET_H
43 # include <sys/socket.h>
44 #endif
45
46 /* used for netconnection.c stuff */
47 typedef struct
48 {
49     BOOL useSSL;
50     int socketFD;
51 #ifdef HAVE_OPENSSL_SSL_H
52     SSL *ssl_s;
53     int ssl_sock;
54 #endif
55 } WININET_NETCONNECTION;
56
57 inline static LPSTR WININET_strdup( LPCSTR str )
58 {
59     LPSTR ret = HeapAlloc( GetProcessHeap(), 0, strlen(str) + 1 );
60     if (ret) strcpy( ret, str );
61     return ret;
62 }
63
64 typedef enum
65 {
66     WH_HINIT = INTERNET_HANDLE_TYPE_INTERNET,
67     WH_HFTPSESSION = INTERNET_HANDLE_TYPE_CONNECT_FTP,
68     WH_HGOPHERSESSION = INTERNET_HANDLE_TYPE_CONNECT_GOPHER,
69     WH_HHTTPSESSION = INTERNET_HANDLE_TYPE_CONNECT_HTTP,
70     WH_HFILE = INTERNET_HANDLE_TYPE_FTP_FILE,
71     WH_HFINDNEXT = INTERNET_HANDLE_TYPE_FTP_FIND,
72     WH_HHTTPREQ = INTERNET_HANDLE_TYPE_HTTP_REQUEST,
73 } WH_TYPE;
74
75 typedef struct _WININETHANDLEHEADER
76 {
77     WH_TYPE htype;
78     DWORD  dwFlags;
79     DWORD  dwContext;
80     DWORD  dwError;
81     struct _WININETHANDLEHEADER *lpwhparent;
82 } WININETHANDLEHEADER, *LPWININETHANDLEHEADER;
83
84
85 typedef struct
86 {
87     WININETHANDLEHEADER hdr;
88     LPSTR  lpszAgent;
89     LPSTR  lpszProxy;
90     LPSTR  lpszProxyBypass;
91     LPSTR  lpszProxyUsername;
92     LPSTR  lpszProxyPassword;
93     DWORD   dwAccessType;
94     INTERNET_STATUS_CALLBACK lpfnStatusCB;
95 } WININETAPPINFOA, *LPWININETAPPINFOA;
96
97
98 typedef struct
99 {
100     WININETHANDLEHEADER hdr;
101     LPSTR  lpszServerName;
102     LPSTR  lpszUserName;
103     INTERNET_PORT nServerPort;
104     struct sockaddr_in socketAddress;
105     struct hostent *phostent;
106 } WININETHTTPSESSIONA, *LPWININETHTTPSESSIONA;
107
108 #define HDR_ISREQUEST           0x0001
109 #define HDR_COMMADELIMITED      0x0002
110 #define HDR_SEMIDELIMITED       0x0004
111
112 typedef struct
113 {
114     LPSTR lpszField;
115     LPSTR lpszValue;
116     WORD wFlags;
117     WORD wCount;
118 } HTTPHEADERA, *LPHTTPHEADERA;
119
120
121 typedef struct
122 {
123     WININETHANDLEHEADER hdr;
124     LPSTR lpszPath;
125     LPSTR lpszVerb;
126     LPSTR lpszHostName;
127     WININET_NETCONNECTION netConnection;
128     HTTPHEADERA StdHeaders[HTTP_QUERY_MAX+1];
129     HTTPHEADERA *pCustHeaders;
130     INT nCustHeaders;
131 } WININETHTTPREQA, *LPWININETHTTPREQA;
132
133
134 typedef struct
135 {
136     WININETHANDLEHEADER hdr;
137     BOOL session_deleted;
138     int nDataSocket;
139 } WININETFILE, *LPWININETFILE;
140
141
142 typedef struct
143 {
144     WININETHANDLEHEADER hdr;
145     int sndSocket;
146     int lstnSocket;
147     int pasvSocket; /* data socket connected by us in case of passive FTP */
148     LPWININETFILE download_in_progress;
149     struct sockaddr_in socketAddress;
150     struct sockaddr_in lstnSocketAddress;
151     struct hostent *phostent;
152     LPSTR  lpszPassword;
153     LPSTR  lpszUserName;
154 } WININETFTPSESSIONA, *LPWININETFTPSESSIONA;
155
156
157 typedef struct
158 {
159     BOOL bIsDirectory;
160     LPSTR lpszName;
161     DWORD nSize;
162     struct tm tmLastModified;
163     unsigned short permissions;
164 } FILEPROPERTIESA, *LPFILEPROPERTIESA;
165
166
167 typedef struct
168 {
169     WININETHANDLEHEADER hdr;
170     int index;
171     DWORD size;
172     LPFILEPROPERTIESA lpafp;
173 } WININETFINDNEXTA, *LPWININETFINDNEXTA;
174
175 typedef enum
176 {
177     FTPPUTFILEA,
178     FTPSETCURRENTDIRECTORYA,
179     FTPCREATEDIRECTORYA,
180     FTPFINDFIRSTFILEA,
181     FTPGETCURRENTDIRECTORYA,
182     FTPOPENFILEA,
183     FTPGETFILEA,
184     FTPDELETEFILEA,
185     FTPREMOVEDIRECTORYA,
186     FTPRENAMEFILEA,
187     INTERNETFINDNEXTA,
188     HTTPSENDREQUESTA,
189     HTTPOPENREQUESTA,
190     SENDCALLBACK,
191     INTERNETOPENURLA,
192 } ASYNC_FUNC;
193
194 struct WORKREQ_FTPPUTFILEA
195 {
196     LPSTR lpszLocalFile;
197     LPSTR lpszNewRemoteFile;
198     DWORD  dwFlags;
199     DWORD  dwContext;
200 };
201
202 struct WORKREQ_FTPSETCURRENTDIRECTORYA
203 {
204     LPSTR lpszDirectory;
205 };
206
207 struct WORKREQ_FTPCREATEDIRECTORYA
208 {
209     LPSTR lpszDirectory;
210 };
211
212 struct WORKREQ_FTPFINDFIRSTFILEA
213 {
214     LPSTR lpszSearchFile;
215     LPWIN32_FIND_DATAA lpFindFileData;
216     DWORD  dwFlags;
217     DWORD  dwContext;
218 };
219
220 struct WORKREQ_FTPGETCURRENTDIRECTORYA
221 {
222     LPSTR lpszDirectory;
223     DWORD *lpdwDirectory;
224 };
225
226 struct WORKREQ_FTPOPENFILEA
227 {
228     LPSTR lpszFilename;
229     DWORD  dwAccess;
230     DWORD  dwFlags;
231     DWORD  dwContext;
232 };
233
234 struct WORKREQ_FTPGETFILEA
235 {
236     LPSTR lpszRemoteFile;
237     LPSTR lpszNewFile;
238     BOOL   fFailIfExists;
239     DWORD  dwLocalFlagsAttribute;
240     DWORD  dwFlags;
241     DWORD  dwContext;
242 };
243
244 struct WORKREQ_FTPDELETEFILEA
245 {
246     LPSTR lpszFilename;
247 };
248
249 struct WORKREQ_FTPREMOVEDIRECTORYA
250 {
251     LPSTR lpszDirectory;
252 };
253
254 struct WORKREQ_FTPRENAMEFILEA
255 {
256     LPSTR lpszSrcFile;
257     LPSTR lpszDestFile;
258 };
259
260 struct WORKREQ_INTERNETFINDNEXTA
261 {
262     LPWIN32_FIND_DATAA lpFindFileData;
263 };
264
265 struct WORKREQ_HTTPOPENREQUESTA
266 {
267     LPSTR lpszVerb;
268     LPSTR lpszObjectName;
269     LPSTR lpszVersion;
270     LPSTR lpszReferrer;
271     LPCSTR *lpszAcceptTypes;
272     DWORD  dwFlags;
273     DWORD  dwContext;
274 };
275
276 struct WORKREQ_HTTPSENDREQUESTA
277 {
278     LPSTR lpszHeader;
279     DWORD  dwHeaderLength;
280     LPVOID lpOptional;
281     DWORD  dwOptionalLength;
282 };
283
284 struct WORKREQ_SENDCALLBACK
285 {
286     HINTERNET hHttpSession;
287     DWORD     dwContext;
288     DWORD     dwInternetStatus;
289     LPVOID    lpvStatusInfo;
290     DWORD     dwStatusInfoLength;
291 };
292
293 struct WORKREQ_INTERNETOPENURLA
294 {
295     HINTERNET hInternet;
296     LPSTR     lpszUrl;
297     LPSTR     lpszHeaders;
298     DWORD     dwHeadersLength;
299     DWORD     dwFlags;
300     DWORD     dwContext;
301 };
302
303 typedef struct WORKREQ
304 {
305     ASYNC_FUNC asyncall;
306     HINTERNET handle;
307
308     union {
309         struct WORKREQ_FTPPUTFILEA              FtpPutFileA;
310         struct WORKREQ_FTPSETCURRENTDIRECTORYA  FtpSetCurrentDirectoryA;
311         struct WORKREQ_FTPCREATEDIRECTORYA      FtpCreateDirectoryA;
312         struct WORKREQ_FTPFINDFIRSTFILEA        FtpFindFirstFileA;
313         struct WORKREQ_FTPGETCURRENTDIRECTORYA  FtpGetCurrentDirectoryA;
314         struct WORKREQ_FTPOPENFILEA             FtpOpenFileA;
315         struct WORKREQ_FTPGETFILEA              FtpGetFileA;
316         struct WORKREQ_FTPDELETEFILEA           FtpDeleteFileA;
317         struct WORKREQ_FTPREMOVEDIRECTORYA      FtpRemoveDirectoryA;
318         struct WORKREQ_FTPRENAMEFILEA           FtpRenameFileA;
319         struct WORKREQ_INTERNETFINDNEXTA        InternetFindNextA;
320         struct WORKREQ_HTTPOPENREQUESTA         HttpOpenRequestA;
321         struct WORKREQ_HTTPSENDREQUESTA         HttpSendRequestA;
322         struct WORKREQ_SENDCALLBACK             SendCallback;
323         struct WORKREQ_INTERNETOPENURLA         InternetOpenUrlA;
324     } u;
325
326     struct WORKREQ *next;
327     struct WORKREQ *prev;
328
329 } WORKREQUEST, *LPWORKREQUEST;
330
331 HINTERNET WININET_AllocHandle( LPWININETHANDLEHEADER info );
332 LPWININETHANDLEHEADER WININET_GetObject( HINTERNET hinternet );
333 BOOL WININET_FreeHandle( HINTERNET hinternet );
334 HINTERNET WININET_FindHandle( LPWININETHANDLEHEADER info );
335
336 time_t ConvertTimeString(LPCSTR asctime);
337
338 HINTERNET FTP_Connect(HINTERNET hInterent, LPCSTR lpszServerName,
339         INTERNET_PORT nServerPort, LPCSTR lpszUserName,
340         LPCSTR lpszPassword, DWORD dwFlags, DWORD dwContext);
341
342 HINTERNET HTTP_Connect(HINTERNET hInterent, LPCSTR lpszServerName,
343         INTERNET_PORT nServerPort, LPCSTR lpszUserName,
344         LPCSTR lpszPassword, DWORD dwFlags, DWORD dwContext);
345
346 BOOL GetAddress(LPCSTR lpszServerName, INTERNET_PORT nServerPort,
347         struct hostent **phe, struct sockaddr_in *psa);
348
349 void INTERNET_SetLastError(DWORD dwError);
350 DWORD INTERNET_GetLastError();
351 BOOL INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest);
352 LPSTR INTERNET_GetResponseBuffer();
353 LPSTR INTERNET_GetNextLine(INT nSocket, LPSTR lpszBuffer, LPDWORD dwBuffer);
354
355 BOOL FTP_CloseSessionHandle(LPWININETFTPSESSIONA lpwfs);
356 BOOL FTP_CloseFindNextHandle(LPWININETFINDNEXTA lpwfn);
357 BOOL FTP_CloseFileTransferHandle(LPWININETFILE lpwfn);
358 BOOLAPI FTP_FtpPutFileA(HINTERNET hConnect, LPCSTR lpszLocalFile,
359     LPCSTR lpszNewRemoteFile, DWORD dwFlags, DWORD dwContext);
360 BOOLAPI FTP_FtpSetCurrentDirectoryA(HINTERNET hConnect, LPCSTR lpszDirectory);
361 BOOLAPI FTP_FtpCreateDirectoryA(HINTERNET hConnect, LPCSTR lpszDirectory);
362 INTERNETAPI HINTERNET WINAPI FTP_FtpFindFirstFileA(HINTERNET hConnect,
363     LPCSTR lpszSearchFile, LPWIN32_FIND_DATAA lpFindFileData, DWORD dwFlags, DWORD dwContext);
364 BOOLAPI FTP_FtpGetCurrentDirectoryA(HINTERNET hFtpSession, LPSTR lpszCurrentDirectory,
365         LPDWORD lpdwCurrentDirectory);
366 BOOL FTP_ConvertFileProp(LPFILEPROPERTIESA lpafp, LPWIN32_FIND_DATAA lpFindFileData);
367 BOOL FTP_FtpRenameFileA(HINTERNET hFtpSession, LPCSTR lpszSrc, LPCSTR lpszDest);
368 BOOL FTP_FtpRemoveDirectoryA(HINTERNET hFtpSession, LPCSTR lpszDirectory);
369 BOOL FTP_FtpDeleteFileA(HINTERNET hFtpSession, LPCSTR lpszFileName);
370 HINTERNET FTP_FtpOpenFileA(HINTERNET hFtpSession, LPCSTR lpszFileName,
371         DWORD fdwAccess, DWORD dwFlags, DWORD dwContext);
372 BOOLAPI FTP_FtpGetFileA(HINTERNET hInternet, LPCSTR lpszRemoteFile, LPCSTR lpszNewFile,
373         BOOL fFailIfExists, DWORD dwLocalFlagsAttribute, DWORD dwInternetFlags,
374         DWORD dwContext);
375
376 BOOLAPI HTTP_HttpSendRequestA(HINTERNET hHttpRequest, LPCSTR lpszHeaders,
377         DWORD dwHeaderLength, LPVOID lpOptional ,DWORD dwOptionalLength);
378 INTERNETAPI HINTERNET WINAPI HTTP_HttpOpenRequestA(HINTERNET hHttpSession,
379         LPCSTR lpszVerb, LPCSTR lpszObjectName, LPCSTR lpszVersion,
380         LPCSTR lpszReferrer , LPCSTR *lpszAcceptTypes,
381         DWORD dwFlags, DWORD dwContext);
382 void HTTP_CloseHTTPSessionHandle(LPWININETHTTPSESSIONA lpwhs);
383 void HTTP_CloseHTTPRequestHandle(LPWININETHTTPREQA lpwhr);
384
385 VOID SendAsyncCallback(LPWININETAPPINFOA hIC, HINTERNET hHttpSession,
386                              DWORD dwContext, DWORD dwInternetStatus, LPVOID
387                              lpvStatusInfo , DWORD dwStatusInfoLength);
388
389 VOID SendAsyncCallbackInt(LPWININETAPPINFOA hIC, HINTERNET hHttpSession,
390                              DWORD dwContext, DWORD dwInternetStatus, LPVOID
391                              lpvStatusInfo , DWORD dwStatusInfoLength);
392
393 BOOL HTTP_InsertProxyAuthorization( LPWININETHTTPREQA lpwhr,
394                        LPCSTR username, LPCSTR password );
395
396 BOOL NETCON_connected(WININET_NETCONNECTION *connection);
397 void NETCON_init(WININET_NETCONNECTION *connnection, BOOL useSSL);
398 BOOL NETCON_create(WININET_NETCONNECTION *connection, int domain,
399               int type, int protocol);
400 BOOL NETCON_close(WININET_NETCONNECTION *connection);
401 BOOL NETCON_connect(WININET_NETCONNECTION *connection, const struct sockaddr *serv_addr,
402                     socklen_t addrlen);
403 BOOL NETCON_send(WININET_NETCONNECTION *connection, const void *msg, size_t len, int flags,
404                 int *sent /* out */);
405 BOOL NETCON_recv(WININET_NETCONNECTION *connection, void *buf, size_t len, int flags,
406                 int *recvd /* out */);
407 BOOL NETCON_getNextLine(WININET_NETCONNECTION *connection, LPSTR lpszBuffer, LPDWORD dwBuffer);
408
409 #define MAX_REPLY_LEN           0x5B4
410
411
412 #endif /* _WINE_INTERNET_H_ */