wininet: Moved creation of an object and allocating handles to common function.
[wine/multimedia.git] / dlls / wininet / internet.h
blobd9fa71604f6ebce6f10ea898670ea7d631c0fe9f
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_SYS_SOCKET_H
42 # include <sys/socket.h>
43 #endif
45 #if !defined(__MINGW32__) && !defined(_MSC_VER)
46 #define closesocket close
47 #define ioctlsocket ioctl
48 #endif /* __MINGW32__ */
50 extern HMODULE WININET_hModule;
52 /* used for netconnection.c stuff */
53 typedef struct
55 BOOL useSSL;
56 int socketFD;
57 void *ssl_s;
58 DWORD security_flags;
59 } WININET_NETCONNECTION;
61 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc(size_t len)
63 return HeapAlloc(GetProcessHeap(), 0, len);
66 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc_zero(size_t len)
68 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
71 static inline void * __WINE_ALLOC_SIZE(2) heap_realloc(void *mem, size_t len)
73 return HeapReAlloc(GetProcessHeap(), 0, mem, len);
76 static inline void * __WINE_ALLOC_SIZE(2) heap_realloc_zero(void *mem, size_t len)
78 return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, mem, len);
81 static inline BOOL heap_free(void *mem)
83 return HeapFree(GetProcessHeap(), 0, mem);
86 static inline LPWSTR heap_strdupW(LPCWSTR str)
88 LPWSTR ret = NULL;
90 if(str) {
91 DWORD size;
93 size = (strlenW(str)+1)*sizeof(WCHAR);
94 ret = HeapAlloc(GetProcessHeap(), 0, size);
95 if(ret)
96 memcpy(ret, str, size);
99 return ret;
102 static inline LPWSTR heap_strndupW(LPCWSTR str, UINT max_len)
104 LPWSTR ret;
105 UINT len;
107 if(!str)
108 return NULL;
110 for(len=0; len<max_len; len++)
111 if(str[len] == '\0')
112 break;
114 ret = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*(len+1));
115 if(ret) {
116 memcpy(ret, str, sizeof(WCHAR)*len);
117 ret[len] = '\0';
120 return ret;
123 static inline WCHAR *heap_strdupAtoW(const char *str)
125 LPWSTR ret = NULL;
127 if(str) {
128 DWORD len;
130 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
131 ret = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
132 if(ret)
133 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
136 return ret;
139 static inline char *heap_strdupWtoA(LPCWSTR str)
141 char *ret = NULL;
143 if(str) {
144 DWORD size = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
145 ret = HeapAlloc(GetProcessHeap(), 0, size);
146 if(ret)
147 WideCharToMultiByte(CP_ACP, 0, str, -1, ret, size, NULL, NULL);
150 return ret;
153 static inline void WININET_find_data_WtoA(LPWIN32_FIND_DATAW dataW, LPWIN32_FIND_DATAA dataA)
155 dataA->dwFileAttributes = dataW->dwFileAttributes;
156 dataA->ftCreationTime = dataW->ftCreationTime;
157 dataA->ftLastAccessTime = dataW->ftLastAccessTime;
158 dataA->ftLastWriteTime = dataW->ftLastWriteTime;
159 dataA->nFileSizeHigh = dataW->nFileSizeHigh;
160 dataA->nFileSizeLow = dataW->nFileSizeLow;
161 dataA->dwReserved0 = dataW->dwReserved0;
162 dataA->dwReserved1 = dataW->dwReserved1;
163 WideCharToMultiByte(CP_ACP, 0, dataW->cFileName, -1,
164 dataA->cFileName, sizeof(dataA->cFileName),
165 NULL, NULL);
166 WideCharToMultiByte(CP_ACP, 0, dataW->cAlternateFileName, -1,
167 dataA->cAlternateFileName, sizeof(dataA->cAlternateFileName),
168 NULL, NULL);
171 typedef enum
173 WH_HINIT = INTERNET_HANDLE_TYPE_INTERNET,
174 WH_HFTPSESSION = INTERNET_HANDLE_TYPE_CONNECT_FTP,
175 WH_HGOPHERSESSION = INTERNET_HANDLE_TYPE_CONNECT_GOPHER,
176 WH_HHTTPSESSION = INTERNET_HANDLE_TYPE_CONNECT_HTTP,
177 WH_HFILE = INTERNET_HANDLE_TYPE_FTP_FILE,
178 WH_HFTPFINDNEXT = INTERNET_HANDLE_TYPE_FTP_FIND,
179 WH_HHTTPREQ = INTERNET_HANDLE_TYPE_HTTP_REQUEST,
180 } WH_TYPE;
182 #define INET_OPENURL 0x0001
183 #define INET_CALLBACKW 0x0002
185 typedef struct _object_header_t object_header_t;
187 typedef struct {
188 void (*Destroy)(object_header_t*);
189 void (*CloseConnection)(object_header_t*);
190 DWORD (*QueryOption)(object_header_t*,DWORD,void*,DWORD*,BOOL);
191 DWORD (*SetOption)(object_header_t*,DWORD,void*,DWORD);
192 DWORD (*ReadFile)(object_header_t*,void*,DWORD,DWORD*);
193 DWORD (*ReadFileExA)(object_header_t*,INTERNET_BUFFERSA*,DWORD,DWORD_PTR);
194 DWORD (*ReadFileExW)(object_header_t*,INTERNET_BUFFERSW*,DWORD,DWORD_PTR);
195 DWORD (*WriteFile)(object_header_t*,const void*,DWORD,DWORD*);
196 DWORD (*QueryDataAvailable)(object_header_t*,DWORD*,DWORD,DWORD_PTR);
197 DWORD (*FindNextFileW)(object_header_t*,void*);
198 } object_vtbl_t;
200 #define INTERNET_HANDLE_IN_USE 1
202 struct _object_header_t
204 WH_TYPE htype;
205 const object_vtbl_t *vtbl;
206 HINTERNET hInternet;
207 BOOL valid_handle;
208 DWORD dwFlags;
209 DWORD_PTR dwContext;
210 DWORD dwError;
211 ULONG ErrorMask;
212 DWORD dwInternalFlags;
213 LONG refs;
214 INTERNET_STATUS_CALLBACK lpfnStatusCB;
215 struct list entry;
216 struct list children;
220 typedef struct
222 object_header_t hdr;
223 LPWSTR lpszAgent;
224 LPWSTR lpszProxy;
225 LPWSTR lpszProxyBypass;
226 LPWSTR lpszProxyUsername;
227 LPWSTR lpszProxyPassword;
228 DWORD dwAccessType;
229 } appinfo_t;
232 typedef struct
234 object_header_t hdr;
235 appinfo_t *lpAppInfo;
236 LPWSTR lpszHostName; /* the final destination of the request */
237 LPWSTR lpszServerName; /* the name of the server we directly connect to */
238 LPWSTR lpszUserName;
239 LPWSTR lpszPassword;
240 INTERNET_PORT nHostPort; /* the final destination port of the request */
241 INTERNET_PORT nServerPort; /* the port of the server we directly connect to */
242 struct sockaddr_storage socketAddress;
243 socklen_t sa_len;
244 } http_session_t;
246 #define HDR_ISREQUEST 0x0001
247 #define HDR_COMMADELIMITED 0x0002
248 #define HDR_SEMIDELIMITED 0x0004
250 typedef struct
252 LPWSTR lpszField;
253 LPWSTR lpszValue;
254 WORD wFlags;
255 WORD wCount;
256 } HTTPHEADERW, *LPHTTPHEADERW;
259 struct HttpAuthInfo;
261 typedef struct gzip_stream_t gzip_stream_t;
263 typedef struct
265 object_header_t hdr;
266 http_session_t *lpHttpSession;
267 LPWSTR lpszPath;
268 LPWSTR lpszVerb;
269 LPWSTR lpszRawHeaders;
270 WININET_NETCONNECTION netConnection;
271 LPWSTR lpszVersion;
272 LPWSTR lpszStatusText;
273 DWORD dwBytesToWrite;
274 DWORD dwBytesWritten;
275 HTTPHEADERW *pCustHeaders;
276 DWORD nCustHeaders;
277 HANDLE hCacheFile;
278 LPWSTR lpszCacheFile;
279 struct HttpAuthInfo *pAuthInfo;
280 struct HttpAuthInfo *pProxyAuthInfo;
282 CRITICAL_SECTION read_section; /* section to protect the following fields */
283 DWORD dwContentLength; /* total number of bytes to be read */
284 DWORD dwContentRead; /* bytes of the content read so far */
285 BOOL read_chunked; /* are we reading in chunked mode? */
286 DWORD read_pos; /* current read position in read_buf */
287 DWORD read_size; /* valid data size in read_buf */
288 BYTE read_buf[4096]; /* buffer for already read but not returned data */
290 BOOL decoding;
291 gzip_stream_t *gzip_stream;
292 } http_request_t;
296 struct WORKREQ_FTPPUTFILEW
298 LPWSTR lpszLocalFile;
299 LPWSTR lpszNewRemoteFile;
300 DWORD dwFlags;
301 DWORD_PTR dwContext;
304 struct WORKREQ_FTPSETCURRENTDIRECTORYW
306 LPWSTR lpszDirectory;
309 struct WORKREQ_FTPCREATEDIRECTORYW
311 LPWSTR lpszDirectory;
314 struct WORKREQ_FTPFINDFIRSTFILEW
316 LPWSTR lpszSearchFile;
317 LPWIN32_FIND_DATAW lpFindFileData;
318 DWORD dwFlags;
319 DWORD_PTR dwContext;
322 struct WORKREQ_FTPGETCURRENTDIRECTORYW
324 LPWSTR lpszDirectory;
325 DWORD *lpdwDirectory;
328 struct WORKREQ_FTPOPENFILEW
330 LPWSTR lpszFilename;
331 DWORD dwAccess;
332 DWORD dwFlags;
333 DWORD_PTR dwContext;
336 struct WORKREQ_FTPGETFILEW
338 LPWSTR lpszRemoteFile;
339 LPWSTR lpszNewFile;
340 BOOL fFailIfExists;
341 DWORD dwLocalFlagsAttribute;
342 DWORD dwFlags;
343 DWORD_PTR dwContext;
346 struct WORKREQ_FTPDELETEFILEW
348 LPWSTR lpszFilename;
351 struct WORKREQ_FTPREMOVEDIRECTORYW
353 LPWSTR lpszDirectory;
356 struct WORKREQ_FTPRENAMEFILEW
358 LPWSTR lpszSrcFile;
359 LPWSTR lpszDestFile;
362 struct WORKREQ_FTPFINDNEXTW
364 LPWIN32_FIND_DATAW lpFindFileData;
367 struct WORKREQ_HTTPSENDREQUESTW
369 LPWSTR lpszHeader;
370 DWORD dwHeaderLength;
371 LPVOID lpOptional;
372 DWORD dwOptionalLength;
373 DWORD dwContentLength;
374 BOOL bEndRequest;
377 struct WORKREQ_HTTPENDREQUESTW
379 DWORD dwFlags;
380 DWORD_PTR dwContext;
383 struct WORKREQ_SENDCALLBACK
385 DWORD_PTR dwContext;
386 DWORD dwInternetStatus;
387 LPVOID lpvStatusInfo;
388 DWORD dwStatusInfoLength;
391 struct WORKREQ_INTERNETOPENURLW
393 HINTERNET hInternet;
394 LPWSTR lpszUrl;
395 LPWSTR lpszHeaders;
396 DWORD dwHeadersLength;
397 DWORD dwFlags;
398 DWORD_PTR dwContext;
401 struct WORKREQ_INTERNETREADFILEEXA
403 LPINTERNET_BUFFERSA lpBuffersOut;
406 struct WORKREQ_INTERNETREADFILEEXW
408 LPINTERNET_BUFFERSW lpBuffersOut;
411 typedef struct WORKREQ
413 void (*asyncproc)(struct WORKREQ*);
414 object_header_t *hdr;
416 union {
417 struct WORKREQ_FTPPUTFILEW FtpPutFileW;
418 struct WORKREQ_FTPSETCURRENTDIRECTORYW FtpSetCurrentDirectoryW;
419 struct WORKREQ_FTPCREATEDIRECTORYW FtpCreateDirectoryW;
420 struct WORKREQ_FTPFINDFIRSTFILEW FtpFindFirstFileW;
421 struct WORKREQ_FTPGETCURRENTDIRECTORYW FtpGetCurrentDirectoryW;
422 struct WORKREQ_FTPOPENFILEW FtpOpenFileW;
423 struct WORKREQ_FTPGETFILEW FtpGetFileW;
424 struct WORKREQ_FTPDELETEFILEW FtpDeleteFileW;
425 struct WORKREQ_FTPREMOVEDIRECTORYW FtpRemoveDirectoryW;
426 struct WORKREQ_FTPRENAMEFILEW FtpRenameFileW;
427 struct WORKREQ_FTPFINDNEXTW FtpFindNextW;
428 struct WORKREQ_HTTPSENDREQUESTW HttpSendRequestW;
429 struct WORKREQ_HTTPENDREQUESTW HttpEndRequestW;
430 struct WORKREQ_SENDCALLBACK SendCallback;
431 struct WORKREQ_INTERNETOPENURLW InternetOpenUrlW;
432 struct WORKREQ_INTERNETREADFILEEXA InternetReadFileExA;
433 struct WORKREQ_INTERNETREADFILEEXW InternetReadFileExW;
434 } u;
436 } WORKREQUEST, *LPWORKREQUEST;
438 void *alloc_object(object_header_t*,const object_vtbl_t*,size_t);
439 object_header_t *get_handle_object( HINTERNET hinternet );
440 object_header_t *WININET_AddRef( object_header_t *info );
441 BOOL WININET_Release( object_header_t *info );
443 DWORD INET_QueryOption( object_header_t *, DWORD, void *, DWORD *, BOOL );
445 time_t ConvertTimeString(LPCWSTR asctime);
447 HINTERNET FTP_Connect(appinfo_t *hIC, LPCWSTR lpszServerName,
448 INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
449 LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
450 DWORD dwInternalFlags);
452 DWORD HTTP_Connect(appinfo_t*,LPCWSTR,
453 INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
454 LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
455 DWORD dwInternalFlags, HINTERNET*);
457 BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
458 struct sockaddr *psa, socklen_t *sa_len);
460 void INTERNET_SetLastError(DWORD dwError);
461 DWORD INTERNET_GetLastError(void);
462 DWORD INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest);
463 LPSTR INTERNET_GetResponseBuffer(void);
464 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen);
466 VOID SendAsyncCallback(object_header_t *hdr, DWORD_PTR dwContext,
467 DWORD dwInternetStatus, LPVOID lpvStatusInfo,
468 DWORD dwStatusInfoLength);
470 VOID INTERNET_SendCallback(object_header_t *hdr, DWORD_PTR dwContext,
471 DWORD dwInternetStatus, LPVOID lpvStatusInfo,
472 DWORD dwStatusInfoLength);
473 BOOL INTERNET_FindProxyForProtocol(LPCWSTR szProxy, LPCWSTR proto, WCHAR *foundProxy, DWORD *foundProxyLen);
475 BOOL NETCON_connected(WININET_NETCONNECTION *connection);
476 DWORD NETCON_init(WININET_NETCONNECTION *connnection, BOOL useSSL);
477 void NETCON_unload(void);
478 DWORD NETCON_create(WININET_NETCONNECTION *connection, int domain,
479 int type, int protocol);
480 DWORD NETCON_close(WININET_NETCONNECTION *connection);
481 DWORD NETCON_connect(WININET_NETCONNECTION *connection, const struct sockaddr *serv_addr,
482 unsigned int addrlen);
483 DWORD NETCON_secure_connect(WININET_NETCONNECTION *connection, LPWSTR hostname);
484 DWORD NETCON_send(WININET_NETCONNECTION *connection, const void *msg, size_t len, int flags,
485 int *sent /* out */);
486 DWORD NETCON_recv(WININET_NETCONNECTION *connection, void *buf, size_t len, int flags,
487 int *recvd /* out */);
488 BOOL NETCON_query_data_available(WININET_NETCONNECTION *connection, DWORD *available);
489 LPCVOID NETCON_GetCert(WININET_NETCONNECTION *connection);
490 int NETCON_GetCipherStrength(WININET_NETCONNECTION *connection);
491 DWORD NETCON_set_timeout(WININET_NETCONNECTION *connection, BOOL send, int value);
492 int sock_get_error(int);
494 extern void URLCacheContainers_CreateDefaults(void);
495 extern void URLCacheContainers_DeleteAll(void);
497 #define MAX_REPLY_LEN 0x5B4
499 /* Used for debugging - maybe need to be shared in the Wine debugging code ? */
500 typedef struct
502 DWORD val;
503 const char* name;
504 } wininet_flag_info;
506 #endif /* _WINE_INTERNET_H_ */