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