wininet: Make the reference count of WININETHANDLEHEADER thread-safe by using Interlo...
[wine/multimedia.git] / dlls / wininet / internet.h
blob106b054dbfa23ce4157ccbedcd4e2edf748dee2c
1 /*
2 * Wininet
4 * Copyright 1999 Corel Corporation
6 * Ulrich Czekalla
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.
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.
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
23 #ifndef _WINE_INTERNET_H_
24 #define _WINE_INTERNET_H_
26 #ifndef __WINE_CONFIG_H
27 # error You must include config.h to use this header
28 #endif
30 #include "wine/unicode.h"
31 #include "wine/list.h"
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_OPENSSL_SSL_H
42 #define DSA __ssl_DSA /* avoid conflict with commctrl.h */
43 #undef FAR
44 /* avoid conflict with wincrypt.h */
45 #undef PKCS7_SIGNER_INFO
46 #undef X509_NAME
47 #undef X509_CERT_PAIR
48 # include <openssl/ssl.h>
49 #undef FAR
50 #define FAR do_not_use_this_in_wine
51 #undef DSA
52 #endif
53 #ifdef HAVE_SYS_SOCKET_H
54 # include <sys/socket.h>
55 #endif
57 #if defined(__MINGW32__) || defined (_MSC_VER)
58 #include "ws2tcpip.h"
59 #ifndef MSG_WAITALL
60 #define MSG_WAITALL 0
61 #endif
62 #else
63 #define closesocket close
64 #define ioctlsocket ioctl
65 #endif /* __MINGW32__ */
67 /* used for netconnection.c stuff */
68 typedef struct
70 BOOL useSSL;
71 int socketFD;
72 #ifdef HAVE_OPENSSL_SSL_H
73 SSL *ssl_s;
74 char *peek_msg;
75 char *peek_msg_mem;
76 size_t peek_len;
77 #endif
78 } WININET_NETCONNECTION;
80 static inline LPWSTR WININET_strdupW( LPCWSTR str )
82 LPWSTR ret = HeapAlloc( GetProcessHeap(), 0, (strlenW(str) + 1)*sizeof(WCHAR) );
83 if (ret) strcpyW( ret, str );
84 return ret;
87 static inline LPWSTR WININET_strdup_AtoW( LPCSTR str )
89 int len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0);
90 LPWSTR ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
91 if (ret)
92 MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len);
93 return ret;
96 static inline LPSTR WININET_strdup_WtoA( LPCWSTR str )
98 int len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
99 LPSTR ret = HeapAlloc( GetProcessHeap(), 0, len );
100 if (ret)
101 WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL);
102 return ret;
105 static inline void WININET_find_data_WtoA(LPWIN32_FIND_DATAW dataW, LPWIN32_FIND_DATAA dataA)
107 dataA->dwFileAttributes = dataW->dwFileAttributes;
108 dataA->ftCreationTime = dataW->ftCreationTime;
109 dataA->ftLastAccessTime = dataW->ftLastAccessTime;
110 dataA->ftLastWriteTime = dataW->ftLastWriteTime;
111 dataA->nFileSizeHigh = dataW->nFileSizeHigh;
112 dataA->nFileSizeLow = dataW->nFileSizeLow;
113 dataA->dwReserved0 = dataW->dwReserved0;
114 dataA->dwReserved1 = dataW->dwReserved1;
115 WideCharToMultiByte(CP_ACP, 0, dataW->cFileName, -1,
116 dataA->cFileName, sizeof(dataA->cFileName),
117 NULL, NULL);
118 WideCharToMultiByte(CP_ACP, 0, dataW->cAlternateFileName, -1,
119 dataA->cAlternateFileName, sizeof(dataA->cAlternateFileName),
120 NULL, NULL);
123 typedef enum
125 WH_HINIT = INTERNET_HANDLE_TYPE_INTERNET,
126 WH_HFTPSESSION = INTERNET_HANDLE_TYPE_CONNECT_FTP,
127 WH_HGOPHERSESSION = INTERNET_HANDLE_TYPE_CONNECT_GOPHER,
128 WH_HHTTPSESSION = INTERNET_HANDLE_TYPE_CONNECT_HTTP,
129 WH_HFILE = INTERNET_HANDLE_TYPE_FTP_FILE,
130 WH_HFTPFINDNEXT = INTERNET_HANDLE_TYPE_FTP_FIND,
131 WH_HHTTPREQ = INTERNET_HANDLE_TYPE_HTTP_REQUEST,
132 } WH_TYPE;
134 #define INET_OPENURL 0x0001
135 #define INET_CALLBACKW 0x0002
137 typedef struct _WININETHANDLEHEADER WININETHANDLEHEADER, *LPWININETHANDLEHEADER;
139 typedef struct {
140 void (*Destroy)(WININETHANDLEHEADER*);
141 void (*CloseConnection)(WININETHANDLEHEADER*);
142 DWORD (*SetOption)(WININETHANDLEHEADER*,DWORD,void*,DWORD);
143 DWORD (*ReadFile)(WININETHANDLEHEADER*,void*,DWORD,DWORD*);
144 DWORD (*ReadFileExA)(WININETHANDLEHEADER*,INTERNET_BUFFERSA*,DWORD,DWORD_PTR);
145 BOOL (*WriteFile)(WININETHANDLEHEADER*,const void*,DWORD,DWORD*);
146 DWORD (*QueryDataAvailable)(WININETHANDLEHEADER*,DWORD*,DWORD,DWORD_PTR);
147 DWORD (*FindNextFileW)(WININETHANDLEHEADER*,void*);
148 } HANDLEHEADERVtbl;
150 struct _WININETHANDLEHEADER
152 WH_TYPE htype;
153 const HANDLEHEADERVtbl *vtbl;
154 HINTERNET hInternet;
155 DWORD dwFlags;
156 DWORD_PTR dwContext;
157 DWORD dwError;
158 DWORD dwInternalFlags;
159 LONG refs;
160 INTERNET_STATUS_CALLBACK lpfnStatusCB;
161 struct list entry;
162 struct list children;
166 typedef struct
168 WININETHANDLEHEADER hdr;
169 LPWSTR lpszAgent;
170 LPWSTR lpszProxy;
171 LPWSTR lpszProxyBypass;
172 LPWSTR lpszProxyUsername;
173 LPWSTR lpszProxyPassword;
174 DWORD dwAccessType;
175 } WININETAPPINFOW, *LPWININETAPPINFOW;
178 typedef struct
180 WININETHANDLEHEADER hdr;
181 WININETAPPINFOW *lpAppInfo;
182 LPWSTR lpszHostName; /* the final destination of the request */
183 LPWSTR lpszServerName; /* the name of the server we directly connect to */
184 LPWSTR lpszUserName;
185 LPWSTR lpszPassword;
186 INTERNET_PORT nHostPort; /* the final destination port of the request */
187 INTERNET_PORT nServerPort; /* the port of the server we directly connect to */
188 struct sockaddr_in socketAddress;
189 } WININETHTTPSESSIONW, *LPWININETHTTPSESSIONW;
191 #define HDR_ISREQUEST 0x0001
192 #define HDR_COMMADELIMITED 0x0002
193 #define HDR_SEMIDELIMITED 0x0004
195 typedef struct
197 LPWSTR lpszField;
198 LPWSTR lpszValue;
199 WORD wFlags;
200 WORD wCount;
201 } HTTPHEADERW, *LPHTTPHEADERW;
204 struct HttpAuthInfo;
206 typedef struct
208 WININETHANDLEHEADER hdr;
209 WININETHTTPSESSIONW *lpHttpSession;
210 LPWSTR lpszPath;
211 LPWSTR lpszVerb;
212 LPWSTR lpszRawHeaders;
213 WININET_NETCONNECTION netConnection;
214 LPWSTR lpszVersion;
215 LPWSTR lpszStatusText;
216 DWORD dwContentLength; /* total number of bytes to be read */
217 DWORD dwContentRead; /* bytes of the content read so far */
218 HTTPHEADERW *pCustHeaders;
219 DWORD nCustHeaders;
220 HANDLE hCacheFile;
221 LPWSTR lpszCacheFile;
222 struct HttpAuthInfo *pAuthInfo;
223 struct HttpAuthInfo *pProxyAuthInfo;
224 } WININETHTTPREQW, *LPWININETHTTPREQW;
228 struct WORKREQ_FTPPUTFILEW
230 LPWSTR lpszLocalFile;
231 LPWSTR lpszNewRemoteFile;
232 DWORD dwFlags;
233 DWORD_PTR dwContext;
236 struct WORKREQ_FTPSETCURRENTDIRECTORYW
238 LPWSTR lpszDirectory;
241 struct WORKREQ_FTPCREATEDIRECTORYW
243 LPWSTR lpszDirectory;
246 struct WORKREQ_FTPFINDFIRSTFILEW
248 LPWSTR lpszSearchFile;
249 LPWIN32_FIND_DATAW lpFindFileData;
250 DWORD dwFlags;
251 DWORD_PTR dwContext;
254 struct WORKREQ_FTPGETCURRENTDIRECTORYW
256 LPWSTR lpszDirectory;
257 DWORD *lpdwDirectory;
260 struct WORKREQ_FTPOPENFILEW
262 LPWSTR lpszFilename;
263 DWORD dwAccess;
264 DWORD dwFlags;
265 DWORD_PTR dwContext;
268 struct WORKREQ_FTPGETFILEW
270 LPWSTR lpszRemoteFile;
271 LPWSTR lpszNewFile;
272 BOOL fFailIfExists;
273 DWORD dwLocalFlagsAttribute;
274 DWORD dwFlags;
275 DWORD_PTR dwContext;
278 struct WORKREQ_FTPDELETEFILEW
280 LPWSTR lpszFilename;
283 struct WORKREQ_FTPREMOVEDIRECTORYW
285 LPWSTR lpszDirectory;
288 struct WORKREQ_FTPRENAMEFILEW
290 LPWSTR lpszSrcFile;
291 LPWSTR lpszDestFile;
294 struct WORKREQ_FTPFINDNEXTW
296 LPWIN32_FIND_DATAW lpFindFileData;
299 struct WORKREQ_HTTPSENDREQUESTW
301 LPWSTR lpszHeader;
302 DWORD dwHeaderLength;
303 LPVOID lpOptional;
304 DWORD dwOptionalLength;
305 DWORD dwContentLength;
306 BOOL bEndRequest;
309 struct WORKREQ_SENDCALLBACK
311 DWORD_PTR dwContext;
312 DWORD dwInternetStatus;
313 LPVOID lpvStatusInfo;
314 DWORD dwStatusInfoLength;
317 struct WORKREQ_INTERNETOPENURLW
319 HINTERNET hInternet;
320 LPWSTR lpszUrl;
321 LPWSTR lpszHeaders;
322 DWORD dwHeadersLength;
323 DWORD dwFlags;
324 DWORD_PTR dwContext;
327 struct WORKREQ_INTERNETREADFILEEXA
329 LPINTERNET_BUFFERSA lpBuffersOut;
332 typedef struct WORKREQ
334 void (*asyncproc)(struct WORKREQ*);
335 WININETHANDLEHEADER *hdr;
337 union {
338 struct WORKREQ_FTPPUTFILEW FtpPutFileW;
339 struct WORKREQ_FTPSETCURRENTDIRECTORYW FtpSetCurrentDirectoryW;
340 struct WORKREQ_FTPCREATEDIRECTORYW FtpCreateDirectoryW;
341 struct WORKREQ_FTPFINDFIRSTFILEW FtpFindFirstFileW;
342 struct WORKREQ_FTPGETCURRENTDIRECTORYW FtpGetCurrentDirectoryW;
343 struct WORKREQ_FTPOPENFILEW FtpOpenFileW;
344 struct WORKREQ_FTPGETFILEW FtpGetFileW;
345 struct WORKREQ_FTPDELETEFILEW FtpDeleteFileW;
346 struct WORKREQ_FTPREMOVEDIRECTORYW FtpRemoveDirectoryW;
347 struct WORKREQ_FTPRENAMEFILEW FtpRenameFileW;
348 struct WORKREQ_FTPFINDNEXTW FtpFindNextW;
349 struct WORKREQ_HTTPSENDREQUESTW HttpSendRequestW;
350 struct WORKREQ_SENDCALLBACK SendCallback;
351 struct WORKREQ_INTERNETOPENURLW InternetOpenUrlW;
352 struct WORKREQ_INTERNETREADFILEEXA InternetReadFileExA;
353 } u;
355 } WORKREQUEST, *LPWORKREQUEST;
357 HINTERNET WININET_AllocHandle( LPWININETHANDLEHEADER info );
358 LPWININETHANDLEHEADER WININET_GetObject( HINTERNET hinternet );
359 LPWININETHANDLEHEADER WININET_AddRef( LPWININETHANDLEHEADER info );
360 BOOL WININET_Release( LPWININETHANDLEHEADER info );
361 BOOL WININET_FreeHandle( HINTERNET hinternet );
363 time_t ConvertTimeString(LPCWSTR asctime);
365 HINTERNET FTP_Connect(LPWININETAPPINFOW hIC, LPCWSTR lpszServerName,
366 INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
367 LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
368 DWORD dwInternalFlags);
370 HINTERNET HTTP_Connect(LPWININETAPPINFOW hIC, LPCWSTR lpszServerName,
371 INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
372 LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
373 DWORD dwInternalFlags);
375 BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
376 struct sockaddr_in *psa);
378 void INTERNET_SetLastError(DWORD dwError);
379 DWORD INTERNET_GetLastError(void);
380 BOOL INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest);
381 LPSTR INTERNET_GetResponseBuffer(void);
382 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen);
384 BOOLAPI HTTP_HttpSendRequestW(LPWININETHTTPREQW lpwhr, LPCWSTR lpszHeaders,
385 DWORD dwHeaderLength, LPVOID lpOptional, DWORD dwOptionalLength,
386 DWORD dwContentLength, BOOL bEndRequest);
387 INTERNETAPI HINTERNET WINAPI HTTP_HttpOpenRequestW(LPWININETHTTPSESSIONW lpwhs,
388 LPCWSTR lpszVerb, LPCWSTR lpszObjectName, LPCWSTR lpszVersion,
389 LPCWSTR lpszReferrer , LPCWSTR *lpszAcceptTypes,
390 DWORD dwFlags, DWORD_PTR dwContext);
391 BOOL HTTP_FinishedReading(LPWININETHTTPREQW lpwhr);
393 VOID SendAsyncCallback(LPWININETHANDLEHEADER hdr, DWORD_PTR dwContext,
394 DWORD dwInternetStatus, LPVOID lpvStatusInfo,
395 DWORD dwStatusInfoLength);
397 VOID INTERNET_SendCallback(LPWININETHANDLEHEADER hdr, DWORD_PTR dwContext,
398 DWORD dwInternetStatus, LPVOID lpvStatusInfo,
399 DWORD dwStatusInfoLength);
401 LPHTTPHEADERW HTTP_GetHeader(LPWININETHTTPREQW lpwhr, LPCWSTR header);
403 BOOL NETCON_connected(WININET_NETCONNECTION *connection);
404 BOOL NETCON_init(WININET_NETCONNECTION *connnection, BOOL useSSL);
405 BOOL NETCON_create(WININET_NETCONNECTION *connection, int domain,
406 int type, int protocol);
407 BOOL NETCON_close(WININET_NETCONNECTION *connection);
408 BOOL NETCON_connect(WININET_NETCONNECTION *connection, const struct sockaddr *serv_addr,
409 unsigned int addrlen);
410 BOOL NETCON_secure_connect(WININET_NETCONNECTION *connection, LPCWSTR hostname);
411 BOOL NETCON_send(WININET_NETCONNECTION *connection, const void *msg, size_t len, int flags,
412 int *sent /* out */);
413 BOOL NETCON_recv(WININET_NETCONNECTION *connection, void *buf, size_t len, int flags,
414 int *recvd /* out */);
415 BOOL NETCON_query_data_available(WININET_NETCONNECTION *connection, DWORD *available);
416 BOOL NETCON_getNextLine(WININET_NETCONNECTION *connection, LPSTR lpszBuffer, LPDWORD dwBuffer);
417 LPCVOID NETCON_GetCert(WININET_NETCONNECTION *connection);
418 DWORD NETCON_set_timeout(WININET_NETCONNECTION *connection, BOOL send, int value);
420 extern void URLCacheContainers_CreateDefaults(void);
421 extern void URLCacheContainers_DeleteAll(void);
423 #define MAX_REPLY_LEN 0x5B4
425 /* Used for debugging - maybe need to be shared in the Wine debugging code ? */
426 typedef struct
428 DWORD val;
429 const char* name;
430 } wininet_flag_info;
432 #endif /* _WINE_INTERNET_H_ */