wininet: Convert WININETSESSIONW's socketAddress to a struct sockaddr_storage.
[wine/testsucceed.git] / dlls / wininet / internet.h
blob4cd22d67ecbe4f0f77334de9855934ba0f2cb123
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 /* used for netconnection.c stuff */
51 typedef struct
53 BOOL useSSL;
54 int socketFD;
55 void *ssl_s;
56 } WININET_NETCONNECTION;
58 static inline LPWSTR WININET_strdupW( LPCWSTR str )
60 LPWSTR ret = HeapAlloc( GetProcessHeap(), 0, (strlenW(str) + 1)*sizeof(WCHAR) );
61 if (ret) strcpyW( ret, str );
62 return ret;
65 static inline LPWSTR WININET_strdup_AtoW( LPCSTR str )
67 int len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0);
68 LPWSTR ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
69 if (ret)
70 MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len);
71 return ret;
74 static inline LPSTR WININET_strdup_WtoA( LPCWSTR str )
76 int len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
77 LPSTR ret = HeapAlloc( GetProcessHeap(), 0, len );
78 if (ret)
79 WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL);
80 return ret;
83 static inline void WININET_find_data_WtoA(LPWIN32_FIND_DATAW dataW, LPWIN32_FIND_DATAA dataA)
85 dataA->dwFileAttributes = dataW->dwFileAttributes;
86 dataA->ftCreationTime = dataW->ftCreationTime;
87 dataA->ftLastAccessTime = dataW->ftLastAccessTime;
88 dataA->ftLastWriteTime = dataW->ftLastWriteTime;
89 dataA->nFileSizeHigh = dataW->nFileSizeHigh;
90 dataA->nFileSizeLow = dataW->nFileSizeLow;
91 dataA->dwReserved0 = dataW->dwReserved0;
92 dataA->dwReserved1 = dataW->dwReserved1;
93 WideCharToMultiByte(CP_ACP, 0, dataW->cFileName, -1,
94 dataA->cFileName, sizeof(dataA->cFileName),
95 NULL, NULL);
96 WideCharToMultiByte(CP_ACP, 0, dataW->cAlternateFileName, -1,
97 dataA->cAlternateFileName, sizeof(dataA->cAlternateFileName),
98 NULL, NULL);
101 typedef enum
103 WH_HINIT = INTERNET_HANDLE_TYPE_INTERNET,
104 WH_HFTPSESSION = INTERNET_HANDLE_TYPE_CONNECT_FTP,
105 WH_HGOPHERSESSION = INTERNET_HANDLE_TYPE_CONNECT_GOPHER,
106 WH_HHTTPSESSION = INTERNET_HANDLE_TYPE_CONNECT_HTTP,
107 WH_HFILE = INTERNET_HANDLE_TYPE_FTP_FILE,
108 WH_HFTPFINDNEXT = INTERNET_HANDLE_TYPE_FTP_FIND,
109 WH_HHTTPREQ = INTERNET_HANDLE_TYPE_HTTP_REQUEST,
110 } WH_TYPE;
112 #define INET_OPENURL 0x0001
113 #define INET_CALLBACKW 0x0002
115 typedef struct _object_header_t object_header_t;
117 typedef struct {
118 void (*Destroy)(object_header_t*);
119 void (*CloseConnection)(object_header_t*);
120 DWORD (*QueryOption)(object_header_t*,DWORD,void*,DWORD*,BOOL);
121 DWORD (*SetOption)(object_header_t*,DWORD,void*,DWORD);
122 DWORD (*ReadFile)(object_header_t*,void*,DWORD,DWORD*);
123 DWORD (*ReadFileExA)(object_header_t*,INTERNET_BUFFERSA*,DWORD,DWORD_PTR);
124 DWORD (*ReadFileExW)(object_header_t*,INTERNET_BUFFERSW*,DWORD,DWORD_PTR);
125 BOOL (*WriteFile)(object_header_t*,const void*,DWORD,DWORD*);
126 DWORD (*QueryDataAvailable)(object_header_t*,DWORD*,DWORD,DWORD_PTR);
127 DWORD (*FindNextFileW)(object_header_t*,void*);
128 } object_vtbl_t;
130 struct _object_header_t
132 WH_TYPE htype;
133 const object_vtbl_t *vtbl;
134 HINTERNET hInternet;
135 DWORD dwFlags;
136 DWORD_PTR dwContext;
137 DWORD dwError;
138 DWORD dwInternalFlags;
139 LONG refs;
140 INTERNET_STATUS_CALLBACK lpfnStatusCB;
141 struct list entry;
142 struct list children;
146 typedef struct
148 object_header_t hdr;
149 LPWSTR lpszAgent;
150 LPWSTR lpszProxy;
151 LPWSTR lpszProxyBypass;
152 LPWSTR lpszProxyUsername;
153 LPWSTR lpszProxyPassword;
154 DWORD dwAccessType;
155 } WININETAPPINFOW, *LPWININETAPPINFOW;
158 typedef struct
160 object_header_t hdr;
161 WININETAPPINFOW *lpAppInfo;
162 LPWSTR lpszHostName; /* the final destination of the request */
163 LPWSTR lpszServerName; /* the name of the server we directly connect to */
164 LPWSTR lpszUserName;
165 LPWSTR lpszPassword;
166 INTERNET_PORT nHostPort; /* the final destination port of the request */
167 INTERNET_PORT nServerPort; /* the port of the server we directly connect to */
168 struct sockaddr_storage socketAddress;
169 socklen_t sa_len;
170 } WININETHTTPSESSIONW, *LPWININETHTTPSESSIONW;
172 #define HDR_ISREQUEST 0x0001
173 #define HDR_COMMADELIMITED 0x0002
174 #define HDR_SEMIDELIMITED 0x0004
176 typedef struct
178 LPWSTR lpszField;
179 LPWSTR lpszValue;
180 WORD wFlags;
181 WORD wCount;
182 } HTTPHEADERW, *LPHTTPHEADERW;
185 struct HttpAuthInfo;
187 typedef struct gzip_stream_t gzip_stream_t;
189 typedef struct
191 object_header_t hdr;
192 WININETHTTPSESSIONW *lpHttpSession;
193 LPWSTR lpszPath;
194 LPWSTR lpszVerb;
195 LPWSTR lpszRawHeaders;
196 WININET_NETCONNECTION netConnection;
197 LPWSTR lpszVersion;
198 LPWSTR lpszStatusText;
199 DWORD dwBytesToWrite;
200 DWORD dwBytesWritten;
201 HTTPHEADERW *pCustHeaders;
202 DWORD nCustHeaders;
203 HANDLE hCacheFile;
204 LPWSTR lpszCacheFile;
205 struct HttpAuthInfo *pAuthInfo;
206 struct HttpAuthInfo *pProxyAuthInfo;
208 CRITICAL_SECTION read_section; /* section to protect the following fields */
209 DWORD dwContentLength; /* total number of bytes to be read */
210 DWORD dwContentRead; /* bytes of the content read so far */
211 BOOL read_chunked; /* are we reading in chunked mode? */
212 DWORD read_pos; /* current read position in read_buf */
213 DWORD read_size; /* valid data size in read_buf */
214 BYTE read_buf[4096]; /* buffer for already read but not returned data */
216 BOOL decoding;
217 gzip_stream_t *gzip_stream;
218 } WININETHTTPREQW, *LPWININETHTTPREQW;
222 struct WORKREQ_FTPPUTFILEW
224 LPWSTR lpszLocalFile;
225 LPWSTR lpszNewRemoteFile;
226 DWORD dwFlags;
227 DWORD_PTR dwContext;
230 struct WORKREQ_FTPSETCURRENTDIRECTORYW
232 LPWSTR lpszDirectory;
235 struct WORKREQ_FTPCREATEDIRECTORYW
237 LPWSTR lpszDirectory;
240 struct WORKREQ_FTPFINDFIRSTFILEW
242 LPWSTR lpszSearchFile;
243 LPWIN32_FIND_DATAW lpFindFileData;
244 DWORD dwFlags;
245 DWORD_PTR dwContext;
248 struct WORKREQ_FTPGETCURRENTDIRECTORYW
250 LPWSTR lpszDirectory;
251 DWORD *lpdwDirectory;
254 struct WORKREQ_FTPOPENFILEW
256 LPWSTR lpszFilename;
257 DWORD dwAccess;
258 DWORD dwFlags;
259 DWORD_PTR dwContext;
262 struct WORKREQ_FTPGETFILEW
264 LPWSTR lpszRemoteFile;
265 LPWSTR lpszNewFile;
266 BOOL fFailIfExists;
267 DWORD dwLocalFlagsAttribute;
268 DWORD dwFlags;
269 DWORD_PTR dwContext;
272 struct WORKREQ_FTPDELETEFILEW
274 LPWSTR lpszFilename;
277 struct WORKREQ_FTPREMOVEDIRECTORYW
279 LPWSTR lpszDirectory;
282 struct WORKREQ_FTPRENAMEFILEW
284 LPWSTR lpszSrcFile;
285 LPWSTR lpszDestFile;
288 struct WORKREQ_FTPFINDNEXTW
290 LPWIN32_FIND_DATAW lpFindFileData;
293 struct WORKREQ_HTTPSENDREQUESTW
295 LPWSTR lpszHeader;
296 DWORD dwHeaderLength;
297 LPVOID lpOptional;
298 DWORD dwOptionalLength;
299 DWORD dwContentLength;
300 BOOL bEndRequest;
303 struct WORKREQ_HTTPENDREQUESTW
305 DWORD dwFlags;
306 DWORD_PTR dwContext;
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 struct WORKREQ_INTERNETREADFILEEXW
334 LPINTERNET_BUFFERSW lpBuffersOut;
337 typedef struct WORKREQ
339 void (*asyncproc)(struct WORKREQ*);
340 object_header_t *hdr;
342 union {
343 struct WORKREQ_FTPPUTFILEW FtpPutFileW;
344 struct WORKREQ_FTPSETCURRENTDIRECTORYW FtpSetCurrentDirectoryW;
345 struct WORKREQ_FTPCREATEDIRECTORYW FtpCreateDirectoryW;
346 struct WORKREQ_FTPFINDFIRSTFILEW FtpFindFirstFileW;
347 struct WORKREQ_FTPGETCURRENTDIRECTORYW FtpGetCurrentDirectoryW;
348 struct WORKREQ_FTPOPENFILEW FtpOpenFileW;
349 struct WORKREQ_FTPGETFILEW FtpGetFileW;
350 struct WORKREQ_FTPDELETEFILEW FtpDeleteFileW;
351 struct WORKREQ_FTPREMOVEDIRECTORYW FtpRemoveDirectoryW;
352 struct WORKREQ_FTPRENAMEFILEW FtpRenameFileW;
353 struct WORKREQ_FTPFINDNEXTW FtpFindNextW;
354 struct WORKREQ_HTTPSENDREQUESTW HttpSendRequestW;
355 struct WORKREQ_HTTPENDREQUESTW HttpEndRequestW;
356 struct WORKREQ_SENDCALLBACK SendCallback;
357 struct WORKREQ_INTERNETOPENURLW InternetOpenUrlW;
358 struct WORKREQ_INTERNETREADFILEEXA InternetReadFileExA;
359 struct WORKREQ_INTERNETREADFILEEXW InternetReadFileExW;
360 } u;
362 } WORKREQUEST, *LPWORKREQUEST;
364 HINTERNET WININET_AllocHandle( object_header_t *info );
365 object_header_t *WININET_GetObject( HINTERNET hinternet );
366 object_header_t *WININET_AddRef( object_header_t *info );
367 BOOL WININET_Release( object_header_t *info );
368 BOOL WININET_FreeHandle( HINTERNET hinternet );
370 DWORD INET_QueryOption(DWORD,void*,DWORD*,BOOL);
372 time_t ConvertTimeString(LPCWSTR asctime);
374 HINTERNET FTP_Connect(LPWININETAPPINFOW hIC, LPCWSTR lpszServerName,
375 INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
376 LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
377 DWORD dwInternalFlags);
379 HINTERNET HTTP_Connect(LPWININETAPPINFOW hIC, LPCWSTR lpszServerName,
380 INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
381 LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
382 DWORD dwInternalFlags);
384 BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
385 struct sockaddr *psa, socklen_t *sa_len);
387 void INTERNET_SetLastError(DWORD dwError);
388 DWORD INTERNET_GetLastError(void);
389 BOOL INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest);
390 LPSTR INTERNET_GetResponseBuffer(void);
391 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen);
393 BOOLAPI HTTP_HttpSendRequestW(LPWININETHTTPREQW lpwhr, LPCWSTR lpszHeaders,
394 DWORD dwHeaderLength, LPVOID lpOptional, DWORD dwOptionalLength,
395 DWORD dwContentLength, BOOL bEndRequest);
396 INTERNETAPI HINTERNET WINAPI HTTP_HttpOpenRequestW(LPWININETHTTPSESSIONW lpwhs,
397 LPCWSTR lpszVerb, LPCWSTR lpszObjectName, LPCWSTR lpszVersion,
398 LPCWSTR lpszReferrer , LPCWSTR *lpszAcceptTypes,
399 DWORD dwFlags, DWORD_PTR dwContext);
401 VOID SendAsyncCallback(object_header_t *hdr, DWORD_PTR dwContext,
402 DWORD dwInternetStatus, LPVOID lpvStatusInfo,
403 DWORD dwStatusInfoLength);
405 VOID INTERNET_SendCallback(object_header_t *hdr, DWORD_PTR dwContext,
406 DWORD dwInternetStatus, LPVOID lpvStatusInfo,
407 DWORD dwStatusInfoLength);
409 BOOL NETCON_connected(WININET_NETCONNECTION *connection);
410 BOOL NETCON_init(WININET_NETCONNECTION *connnection, BOOL useSSL);
411 BOOL NETCON_create(WININET_NETCONNECTION *connection, int domain,
412 int type, int protocol);
413 BOOL NETCON_close(WININET_NETCONNECTION *connection);
414 BOOL NETCON_connect(WININET_NETCONNECTION *connection, const struct sockaddr *serv_addr,
415 unsigned int addrlen);
416 BOOL NETCON_secure_connect(WININET_NETCONNECTION *connection, LPCWSTR hostname);
417 BOOL NETCON_send(WININET_NETCONNECTION *connection, const void *msg, size_t len, int flags,
418 int *sent /* out */);
419 BOOL NETCON_recv(WININET_NETCONNECTION *connection, void *buf, size_t len, int flags,
420 int *recvd /* out */);
421 BOOL NETCON_query_data_available(WININET_NETCONNECTION *connection, DWORD *available);
422 LPCVOID NETCON_GetCert(WININET_NETCONNECTION *connection);
423 DWORD NETCON_set_timeout(WININET_NETCONNECTION *connection, BOOL send, int value);
425 extern void URLCacheContainers_CreateDefaults(void);
426 extern void URLCacheContainers_DeleteAll(void);
428 #define MAX_REPLY_LEN 0x5B4
430 /* Used for debugging - maybe need to be shared in the Wine debugging code ? */
431 typedef struct
433 DWORD val;
434 const char* name;
435 } wininet_flag_info;
437 #endif /* _WINE_INTERNET_H_ */