internet.h 12.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * Wininet
 *
 * Copyright 1999 Corel Corporation
 *
 * Ulrich Czekalla
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * 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
21 22
 */

23 24 25
#ifndef _WINE_INTERNET_H_
#define _WINE_INTERNET_H_

26 27 28 29
#ifndef __WINE_CONFIG_H
# error You must include config.h to use this header
#endif

30
#include "wine/unicode.h"
31
#include "wine/list.h"
32

33
#include <time.h>
34 35 36 37
#ifdef HAVE_NETDB_H
# include <netdb.h>
#endif
#ifdef HAVE_NETINET_IN_H
38
# include <sys/types.h>
39 40
# include <netinet/in.h>
#endif
41 42 43
#ifdef HAVE_SYS_SOCKET_H
# include <sys/socket.h>
#endif
44

Steven Edwards's avatar
Steven Edwards committed
45
#if defined(__MINGW32__) || defined (_MSC_VER)
46
#include "ws2tcpip.h"
Steven Edwards's avatar
Steven Edwards committed
47 48 49
#ifndef MSG_WAITALL
#define MSG_WAITALL 0
#endif
50 51
#else
#define closesocket close
52
#define ioctlsocket ioctl
53 54
#endif /* __MINGW32__ */

55 56 57 58 59
/* used for netconnection.c stuff */
typedef struct
{
    BOOL useSSL;
    int socketFD;
60
    void *ssl_s;
61 62
    char *peek_msg;
    char *peek_msg_mem;
63
    size_t peek_len;
64
} WININET_NETCONNECTION;
65

66
static inline LPWSTR WININET_strdupW( LPCWSTR str )
67 68 69 70 71 72
{
    LPWSTR ret = HeapAlloc( GetProcessHeap(), 0, (strlenW(str) + 1)*sizeof(WCHAR) );
    if (ret) strcpyW( ret, str );
    return ret;
}

73
static inline LPWSTR WININET_strdup_AtoW( LPCSTR str )
74 75 76 77 78 79 80 81
{
    int len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0);
    LPWSTR ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
    if (ret)
        MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len);
    return ret;
}

82
static inline LPSTR WININET_strdup_WtoA( LPCWSTR str )
83 84 85 86 87 88 89 90
{
    int len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
    LPSTR ret = HeapAlloc( GetProcessHeap(), 0, len );
    if (ret)
        WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL);
    return ret;
}

91
static inline void WININET_find_data_WtoA(LPWIN32_FIND_DATAW dataW, LPWIN32_FIND_DATAA dataA)
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
{
    dataA->dwFileAttributes = dataW->dwFileAttributes;
    dataA->ftCreationTime   = dataW->ftCreationTime;
    dataA->ftLastAccessTime = dataW->ftLastAccessTime;
    dataA->ftLastWriteTime  = dataW->ftLastWriteTime;
    dataA->nFileSizeHigh    = dataW->nFileSizeHigh;
    dataA->nFileSizeLow     = dataW->nFileSizeLow;
    dataA->dwReserved0      = dataW->dwReserved0;
    dataA->dwReserved1      = dataW->dwReserved1;
    WideCharToMultiByte(CP_ACP, 0, dataW->cFileName, -1, 
        dataA->cFileName, sizeof(dataA->cFileName),
        NULL, NULL);
    WideCharToMultiByte(CP_ACP, 0, dataW->cAlternateFileName, -1, 
        dataA->cAlternateFileName, sizeof(dataA->cAlternateFileName),
        NULL, NULL);
}

109 110
typedef enum
{
111 112 113 114 115
    WH_HINIT = INTERNET_HANDLE_TYPE_INTERNET,
    WH_HFTPSESSION = INTERNET_HANDLE_TYPE_CONNECT_FTP,
    WH_HGOPHERSESSION = INTERNET_HANDLE_TYPE_CONNECT_GOPHER,
    WH_HHTTPSESSION = INTERNET_HANDLE_TYPE_CONNECT_HTTP,
    WH_HFILE = INTERNET_HANDLE_TYPE_FTP_FILE,
116
    WH_HFTPFINDNEXT = INTERNET_HANDLE_TYPE_FTP_FIND,
117
    WH_HHTTPREQ = INTERNET_HANDLE_TYPE_HTTP_REQUEST,
118 119
} WH_TYPE;

120
#define INET_OPENURL 0x0001
121
#define INET_CALLBACKW 0x0002
122

123 124
typedef struct _WININETHANDLEHEADER WININETHANDLEHEADER, *LPWININETHANDLEHEADER;

125 126
typedef struct {
    void (*Destroy)(WININETHANDLEHEADER*);
127
    void (*CloseConnection)(WININETHANDLEHEADER*);
128
    DWORD (*QueryOption)(WININETHANDLEHEADER*,DWORD,void*,DWORD*,BOOL);
129
    DWORD (*SetOption)(WININETHANDLEHEADER*,DWORD,void*,DWORD);
130
    DWORD (*ReadFile)(WININETHANDLEHEADER*,void*,DWORD,DWORD*);
131
    DWORD (*ReadFileExA)(WININETHANDLEHEADER*,INTERNET_BUFFERSA*,DWORD,DWORD_PTR);
132
    BOOL (*WriteFile)(WININETHANDLEHEADER*,const void*,DWORD,DWORD*);
133
    DWORD (*QueryDataAvailable)(WININETHANDLEHEADER*,DWORD*,DWORD,DWORD_PTR);
134
    DWORD (*FindNextFileW)(WININETHANDLEHEADER*,void*);
135 136
} HANDLEHEADERVtbl;

137
struct _WININETHANDLEHEADER
138 139
{
    WH_TYPE htype;
140
    const HANDLEHEADERVtbl *vtbl;
141
    HINTERNET hInternet;
142
    DWORD  dwFlags;
143
    DWORD_PTR dwContext;
144
    DWORD  dwError;
145
    DWORD  dwInternalFlags;
146
    LONG   refs;
147
    INTERNET_STATUS_CALLBACK lpfnStatusCB;
148 149
    struct list entry;
    struct list children;
150
};
151 152 153 154 155


typedef struct
{
    WININETHANDLEHEADER hdr;
156 157 158 159 160
    LPWSTR  lpszAgent;
    LPWSTR  lpszProxy;
    LPWSTR  lpszProxyBypass;
    LPWSTR  lpszProxyUsername;
    LPWSTR  lpszProxyPassword;
161
    DWORD   dwAccessType;
162
} WININETAPPINFOW, *LPWININETAPPINFOW;
163 164 165 166 167


typedef struct
{
    WININETHANDLEHEADER hdr;
168
    WININETAPPINFOW *lpAppInfo;
169 170
    LPWSTR  lpszHostName; /* the final destination of the request */
    LPWSTR  lpszServerName; /* the name of the server we directly connect to */
171
    LPWSTR  lpszUserName;
172
    LPWSTR  lpszPassword;
173 174
    INTERNET_PORT nHostPort; /* the final destination port of the request */
    INTERNET_PORT nServerPort; /* the port of the server we directly connect to */
175
    struct sockaddr_in socketAddress;
176
} WININETHTTPSESSIONW, *LPWININETHTTPSESSIONW;
177

178 179 180 181 182 183
#define HDR_ISREQUEST		0x0001
#define HDR_COMMADELIMITED	0x0002
#define HDR_SEMIDELIMITED	0x0004

typedef struct
{
184 185
    LPWSTR lpszField;
    LPWSTR lpszValue;
186 187
    WORD wFlags;
    WORD wCount;
188
} HTTPHEADERW, *LPHTTPHEADERW;
189

190

191 192
struct HttpAuthInfo;

193 194 195
typedef struct
{
    WININETHANDLEHEADER hdr;
196
    WININETHTTPSESSIONW *lpHttpSession;
197 198
    LPWSTR lpszPath;
    LPWSTR lpszVerb;
199
    LPWSTR lpszRawHeaders;
200
    WININET_NETCONNECTION netConnection;
201 202
    LPWSTR lpszVersion;
    LPWSTR lpszStatusText;
203 204
    DWORD dwContentLength; /* total number of bytes to be read */
    DWORD dwContentRead; /* bytes of the content read so far */
205
    HTTPHEADERW *pCustHeaders;
206
    DWORD nCustHeaders;
207 208
    HANDLE hCacheFile;
    LPWSTR lpszCacheFile;
209
    struct HttpAuthInfo *pAuthInfo;
210
    struct HttpAuthInfo *pProxyAuthInfo;
211
} WININETHTTPREQW, *LPWININETHTTPREQW;
212 213 214



215
struct WORKREQ_FTPPUTFILEW
216
{
217 218
    LPWSTR lpszLocalFile;
    LPWSTR lpszNewRemoteFile;
219
    DWORD  dwFlags;
220
    DWORD_PTR dwContext;
221 222
};

223
struct WORKREQ_FTPSETCURRENTDIRECTORYW
224
{
225
    LPWSTR lpszDirectory;
226 227
};

228
struct WORKREQ_FTPCREATEDIRECTORYW
229
{
230
    LPWSTR lpszDirectory;
231 232
};

233
struct WORKREQ_FTPFINDFIRSTFILEW
234
{
235 236
    LPWSTR lpszSearchFile;
    LPWIN32_FIND_DATAW lpFindFileData;
237
    DWORD  dwFlags;
238
    DWORD_PTR dwContext;
239 240
};

241
struct WORKREQ_FTPGETCURRENTDIRECTORYW
242
{
243
    LPWSTR lpszDirectory;
244 245 246
    DWORD *lpdwDirectory;
};

247
struct WORKREQ_FTPOPENFILEW
248
{
249
    LPWSTR lpszFilename;
250 251
    DWORD  dwAccess;
    DWORD  dwFlags;
252
    DWORD_PTR dwContext;
253 254
};

255
struct WORKREQ_FTPGETFILEW
256
{
257 258
    LPWSTR lpszRemoteFile;
    LPWSTR lpszNewFile;
259 260 261
    BOOL   fFailIfExists;
    DWORD  dwLocalFlagsAttribute;
    DWORD  dwFlags;
262
    DWORD_PTR dwContext;
263 264
};

265
struct WORKREQ_FTPDELETEFILEW
266
{
267
    LPWSTR lpszFilename;
268 269
};

270
struct WORKREQ_FTPREMOVEDIRECTORYW
271
{
272
    LPWSTR lpszDirectory;
273 274
};

275
struct WORKREQ_FTPRENAMEFILEW
276
{
277 278
    LPWSTR lpszSrcFile;
    LPWSTR lpszDestFile;
279 280
};

281
struct WORKREQ_FTPFINDNEXTW
282
{
283
    LPWIN32_FIND_DATAW lpFindFileData;
284 285
};

286
struct WORKREQ_HTTPSENDREQUESTW
287
{
288
    LPWSTR lpszHeader;
289 290 291
    DWORD  dwHeaderLength;
    LPVOID lpOptional;
    DWORD  dwOptionalLength;
292 293
    DWORD  dwContentLength;
    BOOL   bEndRequest;
294 295 296 297
};

struct WORKREQ_SENDCALLBACK
{
298
    DWORD_PTR dwContext;
299 300 301 302 303
    DWORD     dwInternetStatus;
    LPVOID    lpvStatusInfo;
    DWORD     dwStatusInfoLength;
};

304
struct WORKREQ_INTERNETOPENURLW
305 306
{
    HINTERNET hInternet;
307 308
    LPWSTR     lpszUrl;
    LPWSTR     lpszHeaders;
309 310
    DWORD     dwHeadersLength;
    DWORD     dwFlags;
311
    DWORD_PTR dwContext;
312 313
};

314 315 316 317 318
struct WORKREQ_INTERNETREADFILEEXA
{
    LPINTERNET_BUFFERSA lpBuffersOut;
};

319 320
typedef struct WORKREQ
{
321
    void (*asyncproc)(struct WORKREQ*);
322
    WININETHANDLEHEADER *hdr;
323 324

    union {
325 326 327 328 329 330 331 332 333 334
        struct WORKREQ_FTPPUTFILEW              FtpPutFileW;
        struct WORKREQ_FTPSETCURRENTDIRECTORYW  FtpSetCurrentDirectoryW;
        struct WORKREQ_FTPCREATEDIRECTORYW      FtpCreateDirectoryW;
        struct WORKREQ_FTPFINDFIRSTFILEW        FtpFindFirstFileW;
        struct WORKREQ_FTPGETCURRENTDIRECTORYW  FtpGetCurrentDirectoryW;
        struct WORKREQ_FTPOPENFILEW             FtpOpenFileW;
        struct WORKREQ_FTPGETFILEW              FtpGetFileW;
        struct WORKREQ_FTPDELETEFILEW           FtpDeleteFileW;
        struct WORKREQ_FTPREMOVEDIRECTORYW      FtpRemoveDirectoryW;
        struct WORKREQ_FTPRENAMEFILEW           FtpRenameFileW;
335
        struct WORKREQ_FTPFINDNEXTW             FtpFindNextW;
336
        struct WORKREQ_HTTPSENDREQUESTW         HttpSendRequestW;
337
        struct WORKREQ_SENDCALLBACK             SendCallback;
338
	struct WORKREQ_INTERNETOPENURLW         InternetOpenUrlW;
339
        struct WORKREQ_INTERNETREADFILEEXA      InternetReadFileExA;
340
    } u;
341 342 343

} WORKREQUEST, *LPWORKREQUEST;

344 345
HINTERNET WININET_AllocHandle( LPWININETHANDLEHEADER info );
LPWININETHANDLEHEADER WININET_GetObject( HINTERNET hinternet );
346 347
LPWININETHANDLEHEADER WININET_AddRef( LPWININETHANDLEHEADER info );
BOOL WININET_Release( LPWININETHANDLEHEADER info );
348
BOOL WININET_FreeHandle( HINTERNET hinternet );
349

350
time_t ConvertTimeString(LPCWSTR asctime);
351

352
HINTERNET FTP_Connect(LPWININETAPPINFOW hIC, LPCWSTR lpszServerName,
353
	INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
354
	LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
355
	DWORD dwInternalFlags);
356

357
HINTERNET HTTP_Connect(LPWININETAPPINFOW hIC, LPCWSTR lpszServerName,
358
	INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
359
	LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
360
	DWORD dwInternalFlags);
361

362
BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
363
	struct sockaddr_in *psa);
364 365

void INTERNET_SetLastError(DWORD dwError);
366
DWORD INTERNET_GetLastError(void);
367
BOOL INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest);
368
LPSTR INTERNET_GetResponseBuffer(void);
369
LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen);
370

371
BOOLAPI HTTP_HttpSendRequestW(LPWININETHTTPREQW lpwhr, LPCWSTR lpszHeaders,
372 373
	DWORD dwHeaderLength, LPVOID lpOptional, DWORD dwOptionalLength,
	DWORD dwContentLength, BOOL bEndRequest);
374
INTERNETAPI HINTERNET WINAPI HTTP_HttpOpenRequestW(LPWININETHTTPSESSIONW lpwhs,
375 376
	LPCWSTR lpszVerb, LPCWSTR lpszObjectName, LPCWSTR lpszVersion,
	LPCWSTR lpszReferrer , LPCWSTR *lpszAcceptTypes,
377
	DWORD dwFlags, DWORD_PTR dwContext);
378
BOOL HTTP_FinishedReading(LPWININETHTTPREQW lpwhr);
379

380
VOID SendAsyncCallback(LPWININETHANDLEHEADER hdr, DWORD_PTR dwContext,
381 382
                       DWORD dwInternetStatus, LPVOID lpvStatusInfo,
                       DWORD dwStatusInfoLength);
383

384
VOID INTERNET_SendCallback(LPWININETHANDLEHEADER hdr, DWORD_PTR dwContext,
385 386
                           DWORD dwInternetStatus, LPVOID lpvStatusInfo,
                           DWORD dwStatusInfoLength);
387

388 389
LPHTTPHEADERW HTTP_GetHeader(LPWININETHTTPREQW lpwhr, LPCWSTR header);

390
BOOL NETCON_connected(WININET_NETCONNECTION *connection);
391
BOOL NETCON_init(WININET_NETCONNECTION *connnection, BOOL useSSL);
392 393 394 395
BOOL NETCON_create(WININET_NETCONNECTION *connection, int domain,
	      int type, int protocol);
BOOL NETCON_close(WININET_NETCONNECTION *connection);
BOOL NETCON_connect(WININET_NETCONNECTION *connection, const struct sockaddr *serv_addr,
396
		    unsigned int addrlen);
397
BOOL NETCON_secure_connect(WININET_NETCONNECTION *connection, LPCWSTR hostname);
398 399 400 401
BOOL NETCON_send(WININET_NETCONNECTION *connection, const void *msg, size_t len, int flags,
		int *sent /* out */);
BOOL NETCON_recv(WININET_NETCONNECTION *connection, void *buf, size_t len, int flags,
		int *recvd /* out */);
402
BOOL NETCON_query_data_available(WININET_NETCONNECTION *connection, DWORD *available);
403
BOOL NETCON_getNextLine(WININET_NETCONNECTION *connection, LPSTR lpszBuffer, LPDWORD dwBuffer);
404
LPCVOID NETCON_GetCert(WININET_NETCONNECTION *connection);
405
DWORD NETCON_set_timeout(WININET_NETCONNECTION *connection, BOOL send, int value);
406

Mike McCormack's avatar
Mike McCormack committed
407 408 409
extern void URLCacheContainers_CreateDefaults(void);
extern void URLCacheContainers_DeleteAll(void);

410 411
#define MAX_REPLY_LEN	 	0x5B4

412 413 414 415 416 417
/* Used for debugging - maybe need to be shared in the Wine debugging code ? */
typedef struct
{
    DWORD val;
    const char* name;
} wininet_flag_info;
418 419

#endif /* _WINE_INTERNET_H_ */