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