ReactOS  0.4.15-dev-3295-gaa8fc87
http.c File Reference
#include <stdlib.h>
#include "winsock2.h"
#include "ws2ipdef.h"
#include <stdarg.h>
#include <stdio.h>
#include <time.h>
#include <assert.h>
#include <errno.h>
#include <limits.h>
#include "windef.h"
#include "winbase.h"
#include "wininet.h"
#include "winerror.h"
#include "winternl.h"
#include "shlwapi.h"
#include "sspi.h"
#include "wincrypt.h"
#include "winuser.h"
#include "internet.h"
#include "zlib.h"
#include "resource.h"
#include "wine/debug.h"
#include "wine/exception.h"
Include dependency graph for http.c:

Go to the source code of this file.

Classes

struct  HttpAuthInfo
 
struct  _basicAuthorizationData
 
struct  _authorizationData
 
struct  data_stream_vtbl_t
 
struct  chunked_stream_t
 
struct  gzip_stream_t
 
struct  read_file_task_t
 
struct  send_request_task_t
 
struct  end_request_task_t
 

Macros

#define NO_SHLWAPI_STREAM
 
#define NO_SHLWAPI_REG
 
#define NO_SHLWAPI_GDI
 
#define HTTP_ADDHDR_FLAG_ADD   0x20000000
 
#define HTTP_ADDHDR_FLAG_ADD_IF_NEW   0x10000000
 
#define HTTP_ADDHDR_FLAG_COALESCE_WITH_COMMA   0x40000000
 
#define HTTP_ADDHDR_FLAG_COALESCE_WITH_SEMICOLON   0x01000000
 
#define HTTP_ADDHDR_FLAG_REPLACE   0x80000000
 
#define HTTP_ADDHDR_FLAG_REQ   0x02000000
 
#define COLLECT_TIME   60000
 
#define FE(x)   { x, #x }
 
#define COALESCEFLAGS   (HTTP_ADDHDR_FLAG_COALESCE_WITH_COMMA|HTTP_ADDHDR_FLAG_COALESCE_WITH_SEMICOLON)
 

Typedefs

typedef struct _basicAuthorizationData basicAuthorizationData
 
typedef struct _authorizationData authorizationData
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (wininet)
 
static DWORD HTTP_GetResponseHeaders (http_request_t *req, INT *len)
 
static DWORD HTTP_ProcessHeader (http_request_t *req, LPCWSTR field, LPCWSTR value, DWORD dwModifier)
 
static LPWSTRHTTP_InterpretHttpHeader (LPCWSTR buffer)
 
static DWORD HTTP_InsertCustomHeader (http_request_t *req, LPHTTPHEADERW lpHdr)
 
static INT HTTP_GetCustomHeaderIndex (http_request_t *req, LPCWSTR lpszField, INT index, BOOL Request)
 
static BOOL HTTP_DeleteCustomHeader (http_request_t *req, DWORD index)
 
static LPWSTR HTTP_build_req (LPCWSTR *list, int len)
 
static DWORD HTTP_HttpQueryInfoW (http_request_t *, DWORD, LPVOID, LPDWORD, LPDWORD)
 
static UINT HTTP_DecodeBase64 (LPCWSTR base64, LPSTR bin)
 
static DWORD drain_content (http_request_t *, BOOL)
 
void server_addref (server_t *server)
 
void server_release (server_t *server)
 
static BOOL process_host_port (server_t *server)
 
server_tget_server (substr_t name, INTERNET_PORT port, BOOL is_https, BOOL do_create)
 
BOOL collect_connections (collect_type_t collect_type)
 
static DWORD WINAPI collect_connections_proc (void *arg)
 
static LPHTTPHEADERW HTTP_GetHeader (http_request_t *req, LPCWSTR head)
 
static WCHARget_host_header (http_request_t *req)
 
static void destroy_data_stream (data_stream_t *stream)
 
static void reset_data_stream (http_request_t *req)
 
static void remove_header (http_request_t *request, const WCHAR *str, BOOL from_request)
 
static BOOL gzip_end_of_data (data_stream_t *stream, http_request_t *req)
 
static DWORD gzip_read (data_stream_t *stream, http_request_t *req, BYTE *buf, DWORD size, DWORD *read, BOOL allow_blocking)
 
static DWORD gzip_drain_content (data_stream_t *stream, http_request_t *req, BOOL allow_blocking)
 
static void gzip_destroy (data_stream_t *stream)
 
static voidpf wininet_zalloc (voidpf opaque, uInt items, uInt size)
 
static void wininet_zfree (voidpf opaque, voidpf address)
 
static DWORD init_gzip_stream (http_request_t *req, BOOL is_gzip)
 
static void HTTP_FreeTokens (LPWSTR *token_array)
 
static void HTTP_FixURL (http_request_t *request)
 
static WCHARbuild_request_header (http_request_t *request, const WCHAR *verb, const WCHAR *path, const WCHAR *version, BOOL use_cr)
 
static WCHARbuild_response_header (http_request_t *request, BOOL use_cr)
 
static void HTTP_ProcessCookies (http_request_t *request)
 
static void strip_spaces (LPWSTR start)
 
static BOOL is_basic_auth_value (LPCWSTR pszAuthValue, LPWSTR *pszRealm)
 
static void destroy_authinfo (struct HttpAuthInfo *authinfo)
 
static UINT retrieve_cached_basic_authorization (http_request_t *req, const WCHAR *host, const WCHAR *realm, char **auth_data)
 
static void cache_basic_authorization (LPWSTR host, LPWSTR realm, LPSTR auth_data, UINT auth_data_len)
 
static BOOL retrieve_cached_authorization (LPWSTR host, LPWSTR scheme, SEC_WINNT_AUTH_IDENTITY_W *nt_auth_identity)
 
static void cache_authorization (LPWSTR host, LPWSTR scheme, SEC_WINNT_AUTH_IDENTITY_W *nt_auth_identity)
 
void free_authorization_cache (void)
 
static BOOL HTTP_DoAuthorization (http_request_t *request, LPCWSTR pszAuthValue, struct HttpAuthInfo **ppAuthInfo, LPWSTR domain_and_username, LPWSTR password, LPWSTR host)
 
static DWORD HTTP_HttpAddRequestHeadersW (http_request_t *request, LPCWSTR lpszHeader, DWORD dwHeaderLength, DWORD dwModifier)
 
BOOL WINAPI HttpAddRequestHeadersW (HINTERNET hHttpRequest, LPCWSTR lpszHeader, DWORD dwHeaderLength, DWORD dwModifier)
 
BOOL WINAPI HttpAddRequestHeadersA (HINTERNET hHttpRequest, LPCSTR lpszHeader, DWORD dwHeaderLength, DWORD dwModifier)
 
static void free_accept_types (WCHAR **accept_types)
 
static WCHAR ** convert_accept_types (const char **accept_types)
 
HINTERNET WINAPI HttpOpenRequestA (HINTERNET hHttpSession, LPCSTR lpszVerb, LPCSTR lpszObjectName, LPCSTR lpszVersion, LPCSTR lpszReferrer, LPCSTR *lpszAcceptTypes, DWORD dwFlags, DWORD_PTR dwContext)
 
static UINT HTTP_EncodeBase64 (LPCSTR bin, unsigned int len, LPWSTR base64)
 
static WCHARencode_auth_data (const WCHAR *scheme, const char *data, UINT data_len)
 
static BOOL HTTP_InsertAuthorization (http_request_t *request, struct HttpAuthInfo *pAuthInfo, LPCWSTR header)
 
static WCHARbuild_proxy_path_url (http_request_t *req)
 
static BOOL HTTP_DomainMatches (LPCWSTR server, substr_t domain)
 
static BOOL HTTP_ShouldBypassProxy (appinfo_t *lpwai, LPCWSTR server)
 
static BOOL HTTP_DealWithProxy (appinfo_t *hIC, http_session_t *session, http_request_t *request)
 
static DWORD HTTP_ResolveName (http_request_t *request)
 
static WCHARcompose_request_url (http_request_t *req)
 
static void HTTPREQ_Destroy (object_header_t *hdr)
 
static void http_release_netconn (http_request_t *req, BOOL reuse)
 
static BOOL HTTP_KeepAlive (http_request_t *request)
 
static void HTTPREQ_CloseConnection (object_header_t *hdr)
 
static DWORD str_to_buffer (const WCHAR *str, void *buffer, DWORD *size, BOOL unicode)
 
static DWORD get_security_cert_struct (http_request_t *req, INTERNET_CERTIFICATE_INFOA *info)
 
static DWORD HTTPREQ_QueryOption (object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
 
static DWORD HTTPREQ_SetOption (object_header_t *hdr, DWORD option, void *buffer, DWORD size)
 
static void commit_cache_entry (http_request_t *req)
 
static void create_cache_entry (http_request_t *req)
 
static DWORD read_more_data (http_request_t *req, int maxlen)
 
static void remove_data (http_request_t *req, int count)
 
static DWORD read_line (http_request_t *req, LPSTR buffer, DWORD *len)
 
static BOOL end_of_read_data (http_request_t *req)
 
static DWORD read_http_stream (http_request_t *req, BYTE *buf, DWORD size, DWORD *read, BOOL allow_blocking)
 
static DWORD refill_read_buffer (http_request_t *req, BOOL allow_blocking, DWORD *read_bytes)
 
static BOOL netconn_end_of_data (data_stream_t *stream, http_request_t *req)
 
static DWORD netconn_read (data_stream_t *stream, http_request_t *req, BYTE *buf, DWORD size, DWORD *read, BOOL allow_blocking)
 
static DWORD netconn_drain_content (data_stream_t *stream, http_request_t *req, BOOL allow_blocking)
 
static void netconn_destroy (data_stream_t *stream)
 
static char next_chunked_data_char (chunked_stream_t *stream)
 
static BOOL chunked_end_of_data (data_stream_t *stream, http_request_t *req)
 
static DWORD chunked_read (data_stream_t *stream, http_request_t *req, BYTE *buf, DWORD size, DWORD *read, BOOL allow_blocking)
 
static DWORD chunked_drain_content (data_stream_t *stream, http_request_t *req, BOOL allow_blocking)
 
static void chunked_destroy (data_stream_t *stream)
 
static DWORD set_content_length (http_request_t *request)
 
static void send_request_complete (http_request_t *req, DWORD_PTR result, DWORD error)
 
static void HTTP_ReceiveRequestData (http_request_t *req)
 
static DWORD HTTPREQ_Read (http_request_t *req, void *buffer, DWORD size, DWORD *read, BOOL allow_blocking)
 
static void async_read_file_proc (task_header_t *hdr)
 
static DWORD async_read (http_request_t *req, void *buf, DWORD size, DWORD read_pos, DWORD *ret_read)
 
static DWORD HTTPREQ_ReadFile (object_header_t *hdr, void *buf, DWORD size, DWORD *ret_read, DWORD flags, DWORD_PTR context)
 
static DWORD HTTPREQ_WriteFile (object_header_t *hdr, const void *buffer, DWORD size, DWORD *written)
 
static DWORD HTTPREQ_QueryDataAvailable (object_header_t *hdr, DWORD *available, DWORD flags, DWORD_PTR ctx)
 
static DWORD HTTPREQ_LockRequestFile (object_header_t *hdr, req_file_t **ret)
 
static DWORD HTTP_HttpOpenRequestW (http_session_t *session, LPCWSTR lpszVerb, LPCWSTR lpszObjectName, LPCWSTR lpszVersion, LPCWSTR lpszReferrer, LPCWSTR *lpszAcceptTypes, DWORD dwFlags, DWORD_PTR dwContext, HINTERNET *ret)
 
HINTERNET WINAPI HttpOpenRequestW (HINTERNET hHttpSession, LPCWSTR lpszVerb, LPCWSTR lpszObjectName, LPCWSTR lpszVersion, LPCWSTR lpszReferrer, LPCWSTR *lpszAcceptTypes, DWORD dwFlags, DWORD_PTR dwContext)
 
BOOL WINAPI HttpQueryInfoW (HINTERNET hHttpRequest, DWORD dwInfoLevel, LPVOID lpBuffer, LPDWORD lpdwBufferLength, LPDWORD lpdwIndex)
 
BOOL WINAPI HttpQueryInfoA (HINTERNET hHttpRequest, DWORD dwInfoLevel, LPVOID lpBuffer, LPDWORD lpdwBufferLength, LPDWORD lpdwIndex)
 
static WCHARget_redirect_url (http_request_t *request)
 
static DWORD HTTP_HandleRedirect (http_request_t *request, WCHAR *url)
 
static void HTTP_InsertCookies (http_request_t *request)
 
static WORD HTTP_ParseWkday (LPCWSTR day)
 
static WORD HTTP_ParseMonth (LPCWSTR month)
 
static BOOL HTTP_ParseTime (SYSTEMTIME *st, LPCWSTR *str)
 
static BOOL HTTP_ParseDateAsAsctime (LPCWSTR value, FILETIME *ft)
 
static BOOL HTTP_ParseRfc1123Date (LPCWSTR value, FILETIME *ft)
 
static WORD HTTP_ParseWeekday (LPCWSTR day)
 
static BOOL HTTP_ParseRfc850Date (LPCWSTR value, FILETIME *ft)
 
static BOOL HTTP_ParseDate (LPCWSTR value, FILETIME *ft)
 
static void HTTP_ProcessExpires (http_request_t *request)
 
static void HTTP_ProcessLastModified (http_request_t *request)
 
static void http_process_keep_alive (http_request_t *req)
 
static DWORD open_http_connection (http_request_t *request, BOOL *reusing)
 
static charbuild_ascii_request (const WCHAR *str, void *data, DWORD data_len, DWORD *out_len)
 
static void set_content_length_header (http_request_t *request, DWORD len, DWORD flags)
 
static DWORD HTTP_HttpSendRequestW (http_request_t *request, LPCWSTR lpszHeaders, DWORD dwHeaderLength, LPVOID lpOptional, DWORD dwOptionalLength, DWORD dwContentLength, BOOL bEndRequest)
 
static void AsyncHttpSendRequestProc (task_header_t *hdr)
 
static DWORD HTTP_HttpEndRequestW (http_request_t *request, DWORD dwFlags, DWORD_PTR dwContext)
 
BOOL WINAPI HttpEndRequestA (HINTERNET hRequest, LPINTERNET_BUFFERSA lpBuffersOut, DWORD dwFlags, DWORD_PTR dwContext)
 
static void AsyncHttpEndRequestProc (task_header_t *hdr)
 
BOOL WINAPI HttpEndRequestW (HINTERNET hRequest, LPINTERNET_BUFFERSW lpBuffersOut, DWORD dwFlags, DWORD_PTR dwContext)
 
BOOL WINAPI HttpSendRequestExA (HINTERNET hRequest, LPINTERNET_BUFFERSA lpBuffersIn, LPINTERNET_BUFFERSA lpBuffersOut, DWORD dwFlags, DWORD_PTR dwContext)
 
BOOL WINAPI HttpSendRequestExW (HINTERNET hRequest, LPINTERNET_BUFFERSW lpBuffersIn, LPINTERNET_BUFFERSW lpBuffersOut, DWORD dwFlags, DWORD_PTR dwContext)
 
BOOL WINAPI HttpSendRequestW (HINTERNET hHttpRequest, LPCWSTR lpszHeaders, DWORD dwHeaderLength, LPVOID lpOptional, DWORD dwOptionalLength)
 
BOOL WINAPI HttpSendRequestA (HINTERNET hHttpRequest, LPCSTR lpszHeaders, DWORD dwHeaderLength, LPVOID lpOptional, DWORD dwOptionalLength)
 
static void HTTPSESSION_Destroy (object_header_t *hdr)
 
static DWORD HTTPSESSION_QueryOption (object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
 
static DWORD HTTPSESSION_SetOption (object_header_t *hdr, DWORD option, void *buffer, DWORD size)
 
DWORD HTTP_Connect (appinfo_t *hIC, LPCWSTR lpszServerName, INTERNET_PORT serverPort, LPCWSTR lpszUserName, LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext, DWORD dwInternalFlags, HINTERNET *ret)
 
static void HTTP_clear_response_headers (http_request_t *request)
 
static INT HTTP_GetCustomHeaderIndex (http_request_t *request, LPCWSTR lpszField, int requested_index, BOOL request_only)
 
BOOL WINAPI IsHostInProxyBypassList (DWORD flags, LPCSTR szHost, DWORD length)
 

Variables

static struct list basicAuthorizationCache = LIST_INIT(basicAuthorizationCache)
 
static struct list authorizationCache = LIST_INIT(authorizationCache)
 
static CRITICAL_SECTION authcache_cs = { &critsect_debug, -1, 0, 0, 0, 0 }
 
static CRITICAL_SECTION_DEBUG critsect_debug
 
static CRITICAL_SECTION connection_pool_cs = { &connection_pool_debug, -1, 0, 0, 0, 0 }
 
static CRITICAL_SECTION_DEBUG connection_pool_debug
 
static struct list connection_pool = LIST_INIT(connection_pool)
 
static BOOL collector_running
 
static const data_stream_vtbl_t gzip_stream_vtbl
 
static const signed char HTTP_Base64Dec []
 
static const data_stream_vtbl_t netconn_stream_vtbl
 
static const data_stream_vtbl_t chunked_stream_vtbl
 
static const object_vtbl_t HTTPREQVtbl
 
static const LPCWSTR header_lookup []
 
static const object_vtbl_t HTTPSESSIONVtbl
 

Macro Definition Documentation

◆ COALESCEFLAGS

◆ COLLECT_TIME

#define COLLECT_TIME   60000

Definition at line 74 of file http.c.

◆ FE

#define FE (   x)    { x, #x }

◆ HTTP_ADDHDR_FLAG_ADD

#define HTTP_ADDHDR_FLAG_ADD   0x20000000

Definition at line 67 of file http.c.

◆ HTTP_ADDHDR_FLAG_ADD_IF_NEW

#define HTTP_ADDHDR_FLAG_ADD_IF_NEW   0x10000000

Definition at line 68 of file http.c.

◆ HTTP_ADDHDR_FLAG_COALESCE_WITH_COMMA

#define HTTP_ADDHDR_FLAG_COALESCE_WITH_COMMA   0x40000000

Definition at line 69 of file http.c.

◆ HTTP_ADDHDR_FLAG_COALESCE_WITH_SEMICOLON

#define HTTP_ADDHDR_FLAG_COALESCE_WITH_SEMICOLON   0x01000000

Definition at line 70 of file http.c.

◆ HTTP_ADDHDR_FLAG_REPLACE

#define HTTP_ADDHDR_FLAG_REPLACE   0x80000000

Definition at line 71 of file http.c.

◆ HTTP_ADDHDR_FLAG_REQ

#define HTTP_ADDHDR_FLAG_REQ   0x02000000

Definition at line 72 of file http.c.

◆ NO_SHLWAPI_GDI

#define NO_SHLWAPI_GDI

Definition at line 52 of file http.c.

◆ NO_SHLWAPI_REG

#define NO_SHLWAPI_REG

Definition at line 51 of file http.c.

◆ NO_SHLWAPI_STREAM

#define NO_SHLWAPI_STREAM

Definition at line 50 of file http.c.

Typedef Documentation

◆ authorizationData

◆ basicAuthorizationData

Function Documentation

◆ async_read()

static DWORD async_read ( http_request_t req,
void buf,
DWORD  size,
DWORD  read_pos,
DWORD ret_read 
)
static

Definition at line 3157 of file http.c.

3158 {
3159  read_file_task_t *task;
3160 
3161  task = alloc_async_task(&req->hdr, async_read_file_proc, sizeof(*task));
3162  if(!task)
3163  return ERROR_OUTOFMEMORY;
3164 
3165  task->buf = buf;
3166  task->size = size;
3167  task->read_pos = read_pos;
3168  task->ret_read = ret_read;
3169 
3170  INTERNET_AsyncCall(&task->hdr);
3171  return ERROR_IO_PENDING;
3172 }
#define ERROR_IO_PENDING
Definition: dderror.h:15
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
task_header_t hdr
Definition: http.c:3110
object_header_t hdr
Definition: internet.h:345
DWORD * ret_read
Definition: http.c:3114
DWORD read_pos
Definition: http.c:3113
GLsizeiptr size
Definition: glext.h:5919
void * buf
Definition: http.c:3111
void * alloc_async_task(object_header_t *hdr, async_task_proc_t proc, size_t size)
Definition: internet.c:3894
DWORD INTERNET_AsyncCall(task_header_t *task)
Definition: internet.c:3915
DWORD size
Definition: http.c:3112
static void async_read_file_proc(task_header_t *hdr)
Definition: http.c:3117
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13

Referenced by HTTPREQ_QueryDataAvailable(), and HTTPREQ_ReadFile().

◆ async_read_file_proc()

static void async_read_file_proc ( task_header_t hdr)
static

Definition at line 3117 of file http.c.

3118 {
3120  http_request_t *req = (http_request_t*)task->hdr.hdr;
3121  DWORD res = ERROR_SUCCESS, read = task->read_pos, complete_arg = 0;
3122 
3123  TRACE("req %p buf %p size %u read_pos %u ret_read %p\n", req, task->buf, task->size, task->read_pos, task->ret_read);
3124 
3125  if(task->buf) {
3126  DWORD read_bytes;
3127  while (read < task->size) {
3128  res = HTTPREQ_Read(req, (char*)task->buf + read, task->size - read, &read_bytes, TRUE);
3129  if (res != ERROR_SUCCESS || !read_bytes)
3130  break;
3131  read += read_bytes;
3132  }
3133  }else {
3135  res = refill_read_buffer(req, TRUE, &read);
3137 
3138  if(task->ret_read)
3139  complete_arg = read; /* QueryDataAvailable reports read bytes in request complete notification */
3140  if(res != ERROR_SUCCESS || !read)
3142  }
3143 
3144  TRACE("res %u read %u\n", res, read);
3145 
3146  if(task->ret_read)
3147  *task->ret_read = read;
3148 
3149  /* FIXME: We should report bytes transferred before decoding content. */
3151 
3152  if(res != ERROR_SUCCESS)
3153  complete_arg = res;
3154  send_request_complete(req, res == ERROR_SUCCESS, complete_arg);
3155 }
char hdr[14]
Definition: iptest.cpp:33
#define ERROR_SUCCESS
Definition: deptool.c:10
#define TRUE
Definition: types.h:120
static BOOL read_bytes(parse_buffer *buf, LPVOID data, DWORD size)
Definition: parsing.c:168
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
static DWORD HTTPREQ_Read(http_request_t *req, void *buffer, DWORD size, DWORD *read, BOOL allow_blocking)
Definition: http.c:3053
VOID INTERNET_SendCallback(object_header_t *hdr, DWORD_PTR dwContext, DWORD dwInternetStatus, LPVOID lpvStatusInfo, DWORD dwStatusInfoLength) DECLSPEC_HIDDEN
DWORD_PTR dwContext
Definition: internet.h:278
#define FALSE
Definition: types.h:117
task_header_t hdr
Definition: http.c:3110
object_header_t hdr
Definition: internet.h:345
DWORD * ret_read
Definition: http.c:3114
DWORD read_pos
Definition: http.c:3113
static void send_request_complete(http_request_t *req, DWORD_PTR result, DWORD error)
Definition: http.c:3014
#define TRACE(s)
Definition: solgame.cpp:4
GLsizeiptr size
Definition: glext.h:5919
static void http_release_netconn(http_request_t *req, BOOL reuse)
Definition: http.c:1895
unsigned long DWORD
Definition: ntddk_ex.h:95
static DWORD drain_content(http_request_t *, BOOL)
Definition: http.c:3091
void * buf
Definition: http.c:3111
object_header_t * hdr
Definition: internet.h:390
static DWORD refill_read_buffer(http_request_t *req, BOOL allow_blocking, DWORD *read_bytes)
Definition: http.c:2657
CRITICAL_SECTION read_section
Definition: internet.h:373
GLuint res
Definition: glext.h:9613
DWORD size
Definition: http.c:3112
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
#define INTERNET_STATUS_RESPONSE_RECEIVED
Definition: wininet.h:890
_CRTIMP int __cdecl read(_In_ int _FileHandle, _Out_writes_bytes_(_MaxCharCount) void *_DstBuf, _In_ unsigned int _MaxCharCount)

Referenced by async_read().

◆ AsyncHttpEndRequestProc()

static void AsyncHttpEndRequestProc ( task_header_t hdr)
static

Definition at line 5369 of file http.c.

5370 {
5372  http_request_t *req = (http_request_t*)task->hdr.hdr;
5373 
5374  TRACE("%p\n", req);
5375 
5376  HTTP_HttpEndRequestW(req, task->flags, task->context);
5377 }
char hdr[14]
Definition: iptest.cpp:33
task_header_t hdr
Definition: http.c:5364
#define TRACE(s)
Definition: solgame.cpp:4
object_header_t * hdr
Definition: internet.h:390
static DWORD HTTP_HttpEndRequestW(http_request_t *request, DWORD dwFlags, DWORD_PTR dwContext)
Definition: http.c:5269

Referenced by HttpEndRequestW().

◆ AsyncHttpSendRequestProc()

static void AsyncHttpSendRequestProc ( task_header_t hdr)
static

Definition at line 5255 of file http.c.

5256 {
5259 
5260  TRACE("%p\n", request);
5261 
5263  task->optional_len, task->content_len, task->end_request);
5264 
5265  heap_free(task->headers);
5266 }
char hdr[14]
Definition: iptest.cpp:33
DWORD headers_len
Definition: http.c:5243
void * optional
Definition: http.c:5244
DWORD optional_len
Definition: http.c:5245
WCHAR * headers
Definition: http.c:5242
#define TRACE(s)
Definition: solgame.cpp:4
object_header_t * hdr
Definition: internet.h:390
task_header_t hdr
Definition: http.c:5241
Definition: tftpd.h:85
DWORD content_len
Definition: http.c:5246
static DWORD HTTP_HttpSendRequestW(http_request_t *request, LPCWSTR lpszHeaders, DWORD dwHeaderLength, LPVOID lpOptional, DWORD dwOptionalLength, DWORD dwContentLength, BOOL bEndRequest)
Definition: http.c:4910
static BOOL heap_free(void *mem)
Definition: appwiz.h:75

Referenced by HttpSendRequestExW(), and HttpSendRequestW().

◆ build_ascii_request()

static char* build_ascii_request ( const WCHAR str,
void data,
DWORD  data_len,
DWORD out_len 
)
static

Definition at line 4879 of file http.c.

4880 {
4881  int len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL );
4882  char *ret;
4883 
4884  if (!(ret = heap_alloc( len + data_len ))) return NULL;
4885  WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
4886  if (data_len) memcpy( ret + len - 1, data, data_len );
4887  *out_len = len + data_len - 1;
4888  ret[*out_len] = 0;
4889  return ret;
4890 }
#define WideCharToMultiByte
Definition: compat.h:111
#define CP_ACP
Definition: compat.h:109
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
const WCHAR * str
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
int ret
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLsizei len
Definition: glext.h:6722
#define NULL
Definition: types.h:112

Referenced by HTTP_HttpSendRequestW().

◆ build_proxy_path_url()

static WCHAR* build_proxy_path_url ( http_request_t req)
static

Definition at line 1657 of file http.c.

1658 {
1659  DWORD size, len;
1660  WCHAR *url;
1661 
1663  size = len + lstrlenW(req->path) + 1;
1664  if(*req->path != '/')
1665  size++;
1666  url = heap_alloc(size * sizeof(WCHAR));
1667  if(!url)
1668  return NULL;
1669 
1670  memcpy(url, req->server->scheme_host_port, len*sizeof(WCHAR));
1671  if(*req->path != '/')
1672  url[len++] = '/';
1673 
1674  lstrcpyW(url+len, req->path);
1675 
1676  TRACE("url=%s\n", debugstr_w(url));
1677  return url;
1678 }
#define lstrlenW
Definition: compat.h:609
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
#define debugstr_w
Definition: kernel32.h:32
#define TRACE(s)
Definition: solgame.cpp:4
GLsizeiptr size
Definition: glext.h:5919
__wchar_t WCHAR
Definition: xmlstorage.h:180
static const WCHAR url[]
Definition: encode.c:1432
unsigned long DWORD
Definition: ntddk_ex.h:95
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLsizei len
Definition: glext.h:6722
server_t * server
Definition: internet.h:347
#define lstrcpyW
Definition: compat.h:608
#define NULL
Definition: types.h:112
WCHAR * scheme_host_port
Definition: internet.h:43
LPWSTR path
Definition: internet.h:349

Referenced by HTTP_HttpSendRequestW().

◆ build_request_header()

static WCHAR* build_request_header ( http_request_t request,
const WCHAR verb,
const WCHAR path,
const WCHAR version,
BOOL  use_cr 
)
static

Definition at line 556 of file http.c.

558 {
559  LPWSTR requestString;
560  DWORD len, n;
561  LPCWSTR *req;
562  UINT i;
563 
564  EnterCriticalSection( &request->headers_section );
565 
566  /* allocate space for an array of all the string pointers to be added */
567  len = request->nCustHeaders * 5 + 10;
568  if (!(req = heap_alloc( len * sizeof(const WCHAR *) )))
569  {
570  LeaveCriticalSection( &request->headers_section );
571  return NULL;
572  }
573 
574  /* add the verb, path and HTTP version string */
575  n = 0;
576  req[n++] = verb;
577  req[n++] = L" ";
578  req[n++] = path;
579  req[n++] = L" ";
580  req[n++] = version;
581  if (use_cr)
582  req[n++] = L"\r";
583  req[n++] = L"\n";
584 
585  /* Append custom request headers */
586  for (i = 0; i < request->nCustHeaders; i++)
587  {
588  if (request->custHeaders[i].wFlags & HDR_ISREQUEST)
589  {
590  req[n++] = request->custHeaders[i].lpszField;
591  req[n++] = L": ";
592  req[n++] = request->custHeaders[i].lpszValue;
593  if (use_cr)
594  req[n++] = L"\r";
595  req[n++] = L"\n";
596 
597  TRACE("Adding custom header %s (%s)\n",
598  debugstr_w(request->custHeaders[i].lpszField),
599  debugstr_w(request->custHeaders[i].lpszValue));
600  }
601  }
602  if (use_cr)
603  req[n++] = L"\r";
604  req[n++] = L"\n";
605  req[n] = NULL;
606 
607  requestString = HTTP_build_req( req, 4 );
608  heap_free( req );
609  LeaveCriticalSection( &request->headers_section );
610  return requestString;
611 }
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
GLsizei const GLchar ** path
Definition: glext.h:7234
GLdouble n
Definition: glext.h:7729
static LPWSTR HTTP_build_req(LPCWSTR *list, int len)
Definition: http.c:4259
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
#define HDR_ISREQUEST
Definition: internet.h:314
#define debugstr_w
Definition: kernel32.h:32
static const WCHAR version[]
Definition: asmname.c:66
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
GLenum GLsizei len
Definition: glext.h:6722
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
Definition: tftpd.h:85
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
WCHAR * LPWSTR
Definition: xmlstorage.h:184
static BOOL heap_free(void *mem)
Definition: appwiz.h:75

Referenced by HTTP_HttpQueryInfoW(), and HTTP_HttpSendRequestW().

◆ build_response_header()

static WCHAR* build_response_header ( http_request_t request,
BOOL  use_cr 
)
static

Definition at line 613 of file http.c.

614 {
615  const WCHAR **req;
616  WCHAR *ret, buf[14];
617  DWORD i, n = 0;
618 
619  EnterCriticalSection( &request->headers_section );
620 
621  if (!(req = heap_alloc( (request->nCustHeaders * 5 + 8) * sizeof(WCHAR *) )))
622  {
623  LeaveCriticalSection( &request->headers_section );
624  return NULL;
625  }
626 
627  if (request->status_code)
628  {
629  req[n++] = request->version;
630  swprintf(buf, ARRAY_SIZE(buf), L" %u ", request->status_code);
631  req[n++] = buf;
632  req[n++] = request->statusText;
633  if (use_cr)
634  req[n++] = L"\r";
635  req[n++] = L"\n";
636  }
637 
638  for(i = 0; i < request->nCustHeaders; i++)
639  {
640  if(!(request->custHeaders[i].wFlags & HDR_ISREQUEST)
641  && wcscmp(request->custHeaders[i].lpszField, L"Status"))
642  {
643  req[n++] = request->custHeaders[i].lpszField;
644  req[n++] = L": ";
645  req[n++] = request->custHeaders[i].lpszValue;
646  if(use_cr)
647  req[n++] = L"\r";
648  req[n++] = L"\n";
649 
650  TRACE("Adding custom header %s (%s)\n",
651  debugstr_w(request->custHeaders[i].lpszField),
652  debugstr_w(request->custHeaders[i].lpszValue));
653  }
654  }
655  if(use_cr)
656  req[n++] = L"\r";
657  req[n++] = L"\n";
658  req[n] = NULL;
659 
660  ret = HTTP_build_req(req, 0);
661  heap_free(req);
662  LeaveCriticalSection( &request->headers_section );
663  return ret;
664 }
WCHAR * version
GLdouble n
Definition: glext.h:7729
static LPWSTR HTTP_build_req(LPCWSTR *list, int len)
Definition: http.c:4259
#define swprintf
Definition: precomp.h:40
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define HDR_ISREQUEST
Definition: internet.h:314
#define debugstr_w
Definition: kernel32.h:32
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
int ret
static const WCHAR L[]
Definition: oid.c:1250
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define ARRAY_SIZE(a)
Definition: main.h:24
#define NULL
Definition: types.h:112
Definition: tftpd.h:85
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
static BOOL heap_free(void *mem)
Definition: appwiz.h:75

Referenced by commit_cache_entry(), and HTTP_HttpQueryInfoW().

◆ cache_authorization()

static void cache_authorization ( LPWSTR  host,
LPWSTR  scheme,
SEC_WINNT_AUTH_IDENTITY_W nt_auth_identity 
)
static

Definition at line 891 of file http.c.

893 {
894  authorizationData *ad;
895  BOOL found = FALSE;
896 
897  TRACE("Caching authorization for %s:%s\n", debugstr_w(host), debugstr_w(scheme));
898 
901  if(!wcsicmp(host, ad->host) && !wcsicmp(scheme, ad->scheme)) {
902  found = TRUE;
903  break;
904  }
905 
906  if(found) {
907  heap_free(ad->user);
908  heap_free(ad->password);
909  heap_free(ad->domain);
910  } else {
911  ad = heap_alloc(sizeof(authorizationData));
912  if(!ad) {
914  return;
915  }
916 
917  ad->host = heap_strdupW(host);
918  ad->scheme = heap_strdupW(scheme);
920  }
921 
922  ad->user = heap_strndupW(nt_auth_identity->User, nt_auth_identity->UserLength);
923  ad->password = heap_strndupW(nt_auth_identity->Password, nt_auth_identity->PasswordLength);
924  ad->domain = heap_strndupW(nt_auth_identity->Domain, nt_auth_identity->DomainLength);
925  ad->user_len = nt_auth_identity->UserLength;
926  ad->password_len = nt_auth_identity->PasswordLength;
927  ad->domain_len = nt_auth_identity->DomainLength;
928 
929  if(!ad->host || !ad->scheme || !ad->user || !ad->password
930  || (nt_auth_identity->Domain && !ad->domain)) {
931  heap_free(ad->host);
932  heap_free(ad->scheme);
933  heap_free(ad->user);
934  heap_free(ad->password);
935  heap_free(ad->domain);
936  list_remove(&ad->entry);
937  heap_free(ad);
938  }
939 
941 }
struct list entry
Definition: http.c:102
unsigned short * Domain
Definition: rpcdce.h:225
unsigned short * User
Definition: rpcdce.h:223
LPWSTR password
Definition: http.c:110
static LPWSTR heap_strndupW(LPCWSTR str, unsigned len)
UINT password_len
Definition: http.c:111
LPWSTR domain
Definition: http.c:106
#define TRUE
Definition: types.h:120
unsigned short * Password
Definition: rpcdce.h:227
char * host
Definition: whois.c:55
__WINE_SERVER_LIST_INLINE void list_add_head(struct list *list, struct list *elem)
Definition: list.h:96
DWORD scheme
UINT domain_len
Definition: http.c:107
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:198
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
static WCHAR * heap_strdupW(const WCHAR *str)
Definition: propsheet.c:178
#define debugstr_w
Definition: kernel32.h:32
__WINE_SERVER_LIST_INLINE void list_remove(struct list *elem)
Definition: list.h:108
#define TRACE(s)
Definition: solgame.cpp:4
#define wcsicmp
Definition: compat.h:15
uint32_t entry
Definition: isohybrid.c:63
LPWSTR scheme
Definition: http.c:105
LPWSTR host
Definition: http.c:104
LPWSTR user
Definition: http.c:108
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
static BOOL heap_free(void *mem)
Definition: appwiz.h:75
static struct list authorizationCache
Definition: http.c:115
static CRITICAL_SECTION authcache_cs
Definition: http.c:117

Referenced by HTTP_DoAuthorization().

◆ cache_basic_authorization()

static void cache_basic_authorization ( LPWSTR  host,
LPWSTR  realm,
LPSTR  auth_data,
UINT  auth_data_len 
)
static

Definition at line 814 of file http.c.

815 {
816  struct list *cursor;
818 
819  TRACE("caching authorization for %s:%s = %s\n",debugstr_w(host),debugstr_w(realm),debugstr_an(auth_data,auth_data_len));
820 
823  {
825  if (!wcsicmp(host,check->host) && !wcscmp(realm,check->realm))
826  {
827  ad = check;
828  break;
829  }
830  }
831 
832  if (ad)
833  {
834  TRACE("Found match in cache, replacing\n");
836  ad->authorization = heap_alloc(auth_data_len);
837  memcpy(ad->authorization, auth_data, auth_data_len);
838  ad->authorizationLen = auth_data_len;
839  }
840  else
841  {
842  ad = heap_alloc(sizeof(basicAuthorizationData));
843  ad->host = heap_strdupW(host);
844  ad->realm = heap_strdupW(realm);
845  ad->authorization = heap_alloc(auth_data_len);
846  memcpy(ad->authorization, auth_data, auth_data_len);
847  ad->authorizationLen = auth_data_len;
849  TRACE("authorization cached\n");
850  }
852 }
static struct list basicAuthorizationCache
Definition: http.c:114
char * host
Definition: whois.c:55
__WINE_SERVER_LIST_INLINE void list_add_head(struct list *list, struct list *elem)
Definition: list.h:96
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
static WCHAR * heap_strdupW(const WCHAR *str)
Definition: propsheet.c:178
#define debugstr_w
Definition: kernel32.h:32
#define LIST_FOR_EACH(cursor, list)
Definition: list.h:188
#define TRACE(s)
Definition: solgame.cpp:4
void check(CONTEXT *pContext)
Definition: NtContinue.c:68
#define wcsicmp
Definition: compat.h:15
static __inline const char * debugstr_an(const char *s, int n)
Definition: compat.h:55
uint32_t entry
Definition: isohybrid.c:63
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
Definition: _list.h:228
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
const char cursor[]
Definition: icontest.c:13
struct list entry
Definition: http.c:92
#define NULL
Definition: types.h:112
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
#define LIST_ENTRY(type)
Definition: queue.h:175
static BOOL heap_free(void *mem)
Definition: appwiz.h:75
static CRITICAL_SECTION authcache_cs
Definition: http.c:117

Referenced by HTTP_DoAuthorization().

◆ chunked_destroy()

static void chunked_destroy ( data_stream_t stream)
static

Definition at line 2929 of file http.c.

2930 {
2931  chunked_stream_t *chunked_stream = (chunked_stream_t*)stream;
2932  heap_free(chunked_stream);
2933 }
Definition: parse.h:22
static BOOL heap_free(void *mem)
Definition: appwiz.h:75

◆ chunked_drain_content()

static DWORD chunked_drain_content ( data_stream_t stream,
http_request_t req,
BOOL  allow_blocking 
)
static

Definition at line 2911 of file http.c.

2912 {
2913  chunked_stream_t *chunked_stream = (chunked_stream_t*)stream;
2914  BYTE buf[1024];
2915  DWORD size, res;
2916 
2917  while(chunked_stream->state != CHUNKED_STREAM_STATE_END_OF_STREAM
2918  && chunked_stream->state != CHUNKED_STREAM_STATE_ERROR) {
2919  res = chunked_read(stream, req, buf, sizeof(buf), &size, allow_blocking);
2920  if(res != ERROR_SUCCESS)
2921  return res;
2922  }
2923 
2924  if(chunked_stream->state != CHUNKED_STREAM_STATE_END_OF_STREAM)
2925  return ERROR_NO_DATA;
2926  return ERROR_SUCCESS;
2927 }
#define ERROR_SUCCESS
Definition: deptool.c:10
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLsizeiptr size
Definition: glext.h:5919
#define ERROR_NO_DATA
Definition: winerror.h:284
unsigned long DWORD
Definition: ntddk_ex.h:95
Definition: parse.h:22
unsigned char BYTE
Definition: xxhash.c:193
static DWORD chunked_read(data_stream_t *stream, http_request_t *req, BYTE *buf, DWORD size, DWORD *read, BOOL allow_blocking)
Definition: http.c:2768
enum chunked_stream_t::@577 state
GLuint res
Definition: glext.h:9613

◆ chunked_end_of_data()

static BOOL chunked_end_of_data ( data_stream_t stream,
http_request_t req 
)
static

Definition at line 2755 of file http.c.

2756 {
2757  chunked_stream_t *chunked_stream = (chunked_stream_t*)stream;
2758  switch(chunked_stream->state) {
2759  case CHUNKED_STREAM_STATE_DISCARD_EOL_AT_END:
2760  case CHUNKED_STREAM_STATE_END_OF_STREAM:
2761  case CHUNKED_STREAM_STATE_ERROR:
2762  return TRUE;
2763  default:
2764  return FALSE;
2765  }
2766 }
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
Definition: parse.h:22
enum chunked_stream_t::@577 state

◆ chunked_read()

static DWORD chunked_read ( data_stream_t stream,
http_request_t req,
BYTE buf,
DWORD  size,
DWORD read,
BOOL  allow_blocking 
)
static

Definition at line 2768 of file http.c.

2770 {
2771  chunked_stream_t *chunked_stream = (chunked_stream_t*)stream;
2772  DWORD ret_read = 0, res = ERROR_SUCCESS;
2773  BOOL continue_read = TRUE;
2774  int read_bytes;
2775  char ch;
2776 
2777  do {
2778  TRACE("state %d\n", chunked_stream->state);
2779 
2780  /* Ensure that we have data in the buffer for states that need it. */
2781  if(!chunked_stream->buf_size) {
2782  BOOL blocking_read = allow_blocking;
2783 
2784  switch(chunked_stream->state) {
2785  case CHUNKED_STREAM_STATE_DISCARD_EOL_AT_END:
2786  case CHUNKED_STREAM_STATE_DISCARD_EOL_AFTER_SIZE:
2787  /* never allow blocking after 0 chunk size */
2788  if(!chunked_stream->chunk_size)
2789  blocking_read = FALSE;
2790  /* fall through */
2791  case CHUNKED_STREAM_STATE_READING_CHUNK_SIZE:
2792  case CHUNKED_STREAM_STATE_DISCARD_EOL_AFTER_DATA:
2793  chunked_stream->buf_pos = 0;
2794  res = NETCON_recv(req->netconn, chunked_stream->buf, sizeof(chunked_stream->buf), blocking_read, &read_bytes);
2795  if(res == ERROR_SUCCESS && read_bytes) {
2796  chunked_stream->buf_size += read_bytes;
2797  }else if(res == WSAEWOULDBLOCK) {
2798  if(ret_read || allow_blocking)
2799  res = ERROR_SUCCESS;
2800  continue_read = FALSE;
2801  continue;
2802  }else {
2803  chunked_stream->state = CHUNKED_STREAM_STATE_ERROR;
2804  }
2805  break;
2806  default:
2807  break;
2808  }
2809  }
2810 
2811  switch(chunked_stream->state) {
2812  case CHUNKED_STREAM_STATE_READING_CHUNK_SIZE:
2813  ch = next_chunked_data_char(chunked_stream);
2814 
2815  if(ch >= '0' && ch <= '9') {
2816  chunked_stream->chunk_size = chunked_stream->chunk_size * 16 + ch - '0';
2817  }else if(ch >= 'a' && ch <= 'f') {
2818  chunked_stream->chunk_size = chunked_stream->chunk_size * 16 + ch - 'a' + 10;
2819  }else if (ch >= 'A' && ch <= 'F') {
2820  chunked_stream->chunk_size = chunked_stream->chunk_size * 16 + ch - 'A' + 10;
2821  }else if (ch == ';' || ch == '\r' || ch == '\n') {
2822  TRACE("reading %u byte chunk\n", chunked_stream->chunk_size);
2823  chunked_stream->buf_size++;
2824  chunked_stream->buf_pos--;
2825  if(req->contentLength == ~0) req->contentLength = chunked_stream->chunk_size;
2826  else req->contentLength += chunked_stream->chunk_size;
2827  chunked_stream->state = CHUNKED_STREAM_STATE_DISCARD_EOL_AFTER_SIZE;
2828  }
2829  break;
2830 
2831  case CHUNKED_STREAM_STATE_DISCARD_EOL_AFTER_SIZE:
2832  ch = next_chunked_data_char(chunked_stream);
2833  if(ch == '\n')
2834  chunked_stream->state = chunked_stream->chunk_size
2835  ? CHUNKED_STREAM_STATE_READING_CHUNK
2836  : CHUNKED_STREAM_STATE_DISCARD_EOL_AT_END;
2837  else if(ch != '\r')
2838  WARN("unexpected char '%c'\n", ch);
2839  break;
2840 
2841  case CHUNKED_STREAM_STATE_READING_CHUNK:
2842  assert(chunked_stream->chunk_size);
2843  if(!size) {
2844  continue_read = FALSE;
2845  break;
2846  }
2847  read_bytes = min(size, chunked_stream->chunk_size);
2848 
2849  if(chunked_stream->buf_size) {
2850  if(read_bytes > chunked_stream->buf_size)
2851  read_bytes = chunked_stream->buf_size;
2852 
2853  memcpy(buf+ret_read, chunked_stream->buf+chunked_stream->buf_pos, read_bytes);
2854  chunked_stream->buf_pos += read_bytes;
2855  chunked_stream->buf_size -= read_bytes;
2856  }else {
2857  res = NETCON_recv(req->netconn, (char*)buf+ret_read, read_bytes,
2858  allow_blocking, (int*)&read_bytes);
2859  if(res != ERROR_SUCCESS) {
2860  continue_read = FALSE;
2861  break;
2862  }
2863 
2864  if(!read_bytes) {
2865  chunked_stream->state = CHUNKED_STREAM_STATE_ERROR;
2866  continue;
2867  }
2868  }
2869 
2870  chunked_stream->chunk_size -= read_bytes;
2871  size -= read_bytes;
2872  ret_read += read_bytes;
2873  if(!chunked_stream->chunk_size)
2874  chunked_stream->state = CHUNKED_STREAM_STATE_DISCARD_EOL_AFTER_DATA;
2875  allow_blocking = FALSE;
2876  break;
2877 
2878  case CHUNKED_STREAM_STATE_DISCARD_EOL_AFTER_DATA:
2879  ch = next_chunked_data_char(chunked_stream);
2880  if(ch == '\n')
2881  chunked_stream->state = CHUNKED_STREAM_STATE_READING_CHUNK_SIZE;
2882  else if(ch != '\r')
2883  WARN("unexpected char '%c'\n", ch);
2884  break;
2885 
2886  case CHUNKED_STREAM_STATE_DISCARD_EOL_AT_END:
2887  ch = next_chunked_data_char(chunked_stream);
2888  if(ch == '\n')
2889  chunked_stream->state = CHUNKED_STREAM_STATE_END_OF_STREAM;
2890  else if(ch != '\r')
2891  WARN("unexpected char '%c'\n", ch);
2892  break;
2893 
2894  case CHUNKED_STREAM_STATE_END_OF_STREAM:
2895  case CHUNKED_STREAM_STATE_ERROR:
2896  continue_read = FALSE;
2897  break;
2898  }
2899  } while(continue_read);
2900 
2901  if(ret_read)
2902  res = ERROR_SUCCESS;
2903  if(res != ERROR_SUCCESS)
2904  return res;
2905 
2906  TRACE("read %d bytes\n", ret_read);
2907  *read = ret_read;
2908  return ERROR_SUCCESS;
2909 }
DWORD chunk_size
Definition: http.c:329
#define ERROR_SUCCESS
Definition: deptool.c:10
#define TRUE
Definition: types.h:120
DWORD buf_pos
Definition: http.c:328
BYTE buf[READ_BUFFER_SIZE]
Definition: http.c:326
#define WARN(fmt,...)
Definition: debug.h:112
#define WSAEWOULDBLOCK
Definition: winerror.h:1948
ULONGLONG contentLength
Definition: internet.h:374
#define assert(x)
Definition: debug.h:53
static BOOL read_bytes(parse_buffer *buf, LPVOID data, DWORD size)
Definition: parsing.c:168
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
DWORD NETCON_recv(netconn_t *, void *, size_t, BOOL, int *) DECLSPEC_HIDDEN
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
netconn_t * netconn
Definition: internet.h:351
#define TRACE(s)
Definition: solgame.cpp:4
GLsizeiptr size
Definition: glext.h:5919
unsigned long DWORD
Definition: ntddk_ex.h:95
Definition: parse.h:22
static char next_chunked_data_char(chunked_stream_t *stream)
Definition: http.c:2747
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define min(a, b)
Definition: monoChain.cc:55
DWORD buf_size
Definition: http.c:327
enum chunked_stream_t::@577 state
GLuint res
Definition: glext.h:9613
_CRTIMP int __cdecl read(_In_ int _FileHandle, _Out_writes_bytes_(_MaxCharCount) void *_DstBuf, _In_ unsigned int _MaxCharCount)

Referenced by chunked_drain_content().

◆ collect_connections()

BOOL collect_connections ( collect_type_t  collect_type)

Definition at line 235 of file http.c.

236 {
237  netconn_t *netconn, *netconn_safe;
238  server_t *server, *server_safe;
239  BOOL remaining = FALSE;
240  DWORD64 now;
241 
242 #ifdef __REACTOS__
243  now = GetTickCount();
244 #else
245  now = GetTickCount64();
246 #endif
247 
249  LIST_FOR_EACH_ENTRY_SAFE(netconn, netconn_safe, &server->conn_pool, netconn_t, pool_entry) {
250  if(collect_type > COLLECT_TIMEOUT || netconn->keep_until < now) {
251  TRACE("freeing %p\n", netconn);
252  list_remove(&netconn->pool_entry);
254  }else {
255  remaining = TRUE;
256  }
257  }
258 
259  if(collect_type == COLLECT_CLEANUP) {
260  list_remove(&server->entry);
261  list_init(&server->entry);
263  }
264  }
265 
266  return remaining;
267 }
ULONGLONG keep_until
static rfbScreenInfoPtr server
Definition: vnc.c:74
#define TRUE
Definition: types.h:120
DWORD WINAPI GetTickCount(VOID)
Definition: time.c:455
void server_release(server_t *server)
Definition: http.c:154
ULONGLONG WINAPI GetTickCount64(VOID)
Definition: GetTickCount64.c:9
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
time_t now
Definition: finger.c:65
void free_netconn(netconn_t *) DECLSPEC_HIDDEN
__WINE_SERVER_LIST_INLINE void list_remove(struct list *elem)
Definition: list.h:108
#define TRACE(s)
Definition: solgame.cpp:4
uint32_t entry
Definition: isohybrid.c:63
#define LIST_FOR_EACH_ENTRY_SAFE(cursor, cursor2, list, type, field)
Definition: list.h:204
uint64_t DWORD64
Definition: typedefs.h:67
__WINE_SERVER_LIST_INLINE void list_init(struct list *list)
Definition: list.h:149
static struct list connection_pool
Definition: http.c:146

Referenced by collect_connections_proc(), DllMain(), and INET_SetOption().

◆ collect_connections_proc()

static DWORD WINAPI collect_connections_proc ( void arg)
static

Definition at line 269 of file http.c.

270 {
271  BOOL remaining_conns;
272 
273  do {
274  /* FIXME: Use more sophisticated method */
275  Sleep(5000);
276 
278 
279  remaining_conns = collect_connections(COLLECT_TIMEOUT);
280  if(!remaining_conns)
282 
284  }while(remaining_conns);
285 
287 }
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
VOID WINAPI FreeLibraryAndExitThread(HMODULE hLibModule, DWORD dwExitCode)
Definition: loader.c:507
#define FALSE
Definition: types.h:117
HMODULE WININET_hModule
Definition: internet.c:73
unsigned int BOOL
Definition: ntddk_ex.h:94
static BOOL collector_running
Definition: http.c:147
static CRITICAL_SECTION connection_pool_cs
Definition: http.c:137
BOOL collect_connections(collect_type_t collect_type)
Definition: http.c:235
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)

Referenced by http_release_netconn().

◆ commit_cache_entry()

static void commit_cache_entry ( http_request_t req)
static

Definition at line 2426 of file http.c.

2427 {
2428  WCHAR *header;
2429  DWORD header_len;
2430  BOOL res;
2431 
2432  TRACE("%p\n", req);
2433 
2434  CloseHandle(req->hCacheFile);
2435  req->hCacheFile = NULL;
2436 
2438  header_len = (header ? lstrlenW(header) : 0);
2441  header, header_len, NULL, 0);
2442  if(res)
2443  req->req_file->is_committed = TRUE;
2444  else
2445  WARN("CommitUrlCacheEntry failed: %u\n", GetLastError());
2446  heap_free(header);
2447 }
#define CloseHandle
Definition: compat.h:598
FILETIME last_modified
Definition: internet.h:366
#define TRUE
Definition: types.h:120
#define WARN(fmt,...)
Definition: debug.h:112
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
FILETIME expires
Definition: internet.h:369
#define lstrlenW
Definition: compat.h:609
unsigned int BOOL
Definition: ntddk_ex.h:94
req_file_t * req_file
Definition: internet.h:368
#define NORMAL_CACHE_ENTRY
Definition: wininet.h:2087
#define TRACE(s)
Definition: solgame.cpp:4
BOOL WINAPI CommitUrlCacheEntryW(LPCWSTR lpszUrlName, LPCWSTR lpszLocalFileName, FILETIME ExpireTime, FILETIME LastModifiedTime, DWORD CacheEntryType, LPWSTR lpHeaderInfo, DWORD dwHeaderSize, LPCWSTR lpszFileExtension, LPCWSTR lpszOriginalUrl)
Definition: urlcache.c:3085
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL is_committed
Definition: internet.h:252
HANDLE hCacheFile
Definition: internet.h:367
#define NULL
Definition: types.h:112
static WCHAR * build_response_header(http_request_t *request, BOOL use_cr)
Definition: http.c:613
GLuint res
Definition: glext.h:9613
WCHAR * file_name
Definition: internet.h:250
WCHAR * url
Definition: internet.h:251
struct CFHEADER header
Definition: fdi.c:101
static BOOL heap_free(void *mem)
Definition: appwiz.h:75

Referenced by create_cache_entry(), and read_http_stream().

◆ compose_request_url()

static WCHAR* compose_request_url ( http_request_t req)
static

Definition at line 1815 of file http.c.

1816 {
1817  const WCHAR *host, *scheme;
1818  WCHAR *buf, *ptr;
1819  size_t len;
1820 
1821  host = req->server->canon_host_port;
1822 
1823  if (req->server->is_https)
1824  scheme = L"https://";
1825  else
1826  scheme = L"http://";
1827 
1828  len = lstrlenW(scheme) + lstrlenW(host) + (req->path[0] != '/' ? 1 : 0) + lstrlenW(req->path);
1829  ptr = buf = heap_alloc((len+1) * sizeof(WCHAR));
1830  if(buf) {
1831  lstrcpyW(ptr, scheme);
1832  ptr += lstrlenW(ptr);
1833 
1834  lstrcpyW(ptr, host);
1835  ptr += lstrlenW(ptr);
1836 
1837  if(req->path[0] != '/')
1838  *ptr++ = '/';
1839 
1840  lstrcpyW(ptr, req->path);
1841  ptr += lstrlenW(ptr);
1842  *ptr = 0;
1843  }
1844 
1845  return buf;
1846 }
BOOL is_https
Definition: internet.h:38
char * host
Definition: whois.c:55
DWORD scheme
#define lstrlenW
Definition: compat.h:609
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
const WCHAR * canon_host_port
Definition: internet.h:45
static PVOID ptr
Definition: dispmode.c:27
__wchar_t WCHAR
Definition: xmlstorage.h:180
static const WCHAR L[]
Definition: oid.c:1250
GLenum GLsizei len
Definition: glext.h:6722
server_t * server
Definition: internet.h:347
#define lstrcpyW
Definition: compat.h:608
LPWSTR path
Definition: internet.h:349

Referenced by create_cache_entry(), and HTTPREQ_QueryOption().

◆ convert_accept_types()

static WCHAR** convert_accept_types ( const char **  accept_types)
static

Definition at line 1359 of file http.c.

1360 {
1361  unsigned int count;
1362  const char **types = accept_types;
1363  WCHAR **typesW;
1364  BOOL invalid_pointer = FALSE;
1365 
1366  if (!types) return NULL;
1367  count = 0;
1368  while (*types)
1369  {
1370  __TRY
1371  {
1372  /* find out how many there are */
1373  if (*types && **types)
1374  {
1375  TRACE("accept type: %s\n", debugstr_a(*types));
1376  count++;
1377  }
1378  }
1380  {
1381  WARN("invalid accept type pointer\n");
1382  invalid_pointer = TRUE;
1383  }
1384  __ENDTRY;
1385  types++;
1386  }
1387  if (invalid_pointer) return NULL;
1388  if (!(typesW = heap_alloc( sizeof(WCHAR *) * (count + 1) ))) return NULL;
1389  count = 0;
1390  types = accept_types;
1391  while (*types)
1392  {
1393  if (*types && **types) typesW[count++] = heap_strdupAtoW( *types );
1394  types++;
1395  }
1396  typesW[count] = NULL;
1397  return typesW;
1398 }
#define TRUE
Definition: types.h:120
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define WARN(fmt,...)
Definition: debug.h:112
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
#define __TRY
Definition: compat.h:80
static WCHAR * heap_strdupAtoW(const char *str)
Definition: appwiz.h:80
#define TRACE(s)
Definition: solgame.cpp:4
Definition: cmds.c:130
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define debugstr_a
Definition: kernel32.h:31
#define __ENDTRY
Definition: compat.h:82
#define NULL
Definition: types.h:112
#define __EXCEPT_PAGE_FAULT
Definition: compat.h:81

Referenced by HttpOpenRequestA().

◆ create_cache_entry()

static void create_cache_entry ( http_request_t req)
static

Definition at line 2449 of file http.c.

2450 {
2452  WCHAR *url;
2453  BOOL b = TRUE;
2454 
2455  /* FIXME: We should free previous cache file earlier */
2456  if(req->req_file) {
2457  req_file_release(req->req_file);
2458  req->req_file = NULL;
2459  }
2460  if(req->hCacheFile) {
2461  CloseHandle(req->hCacheFile);
2462  req->hCacheFile = NULL;
2463  }
2464 
2466  b = FALSE;
2467 
2468  if(b) {
2469  int header_idx;
2470 
2472 
2473  header_idx = HTTP_GetCustomHeaderIndex(req, L"Cache-Control", 0, FALSE);
2474  if(header_idx != -1) {
2475  WCHAR *ptr;
2476 
2477  for(ptr=req->custHeaders[header_idx].lpszValue; *ptr; ) {
2478  WCHAR *end;
2479 
2480  while(*ptr==' ' || *ptr=='\t')
2481  ptr++;
2482 
2483  end = wcschr(ptr, ',');
2484  if(!end)
2485  end = ptr + lstrlenW(ptr);
2486 
2487  if(!wcsnicmp(ptr, L"no-cache", ARRAY_SIZE(L"no-cache")-1)
2488  || !wcsnicmp(ptr, L"no-store", ARRAY_SIZE(L"no-store")-1)) {
2489  b = FALSE;
2490  break;
2491  }
2492 
2493  ptr = end;
2494  if(*ptr == ',')
2495  ptr++;
2496  }
2497  }
2498 
2500  }
2501 
2502  if(!b) {
2503  if(!(req->hdr.dwFlags & INTERNET_FLAG_NEED_FILE))
2504  return;
2505 
2506  FIXME("INTERNET_FLAG_NEED_FILE is not supported correctly\n");
2507  }
2508 
2509  url = compose_request_url(req);
2510  if(!url) {
2511  WARN("Could not get URL\n");
2512  return;
2513  }
2514 
2515  b = CreateUrlCacheEntryW(url, req->contentLength == ~0 ? 0 : req->contentLength, NULL, file_name, 0);
2516  if(!b) {
2517  WARN("Could not create cache entry: %08x\n", GetLastError());
2518  return;
2519  }
2520 
2522  req->req_file->url = url;
2523 
2526  if(req->hCacheFile == INVALID_HANDLE_VALUE) {
2527  WARN("Could not create file: %u\n", GetLastError());
2528  req->hCacheFile = NULL;
2529  return;
2530  }
2531 
2532  if(req->read_size) {
2533  DWORD written;
2534 
2535  b = WriteFile(req->hCacheFile, req->read_buf+req->read_pos, req->read_size, &written, NULL);
2536  if(!b)
2537  FIXME("WriteFile failed: %u\n", GetLastError());
2538 
2539  if(req->data_stream->vtbl->end_of_data(req->data_stream, req))
2540  commit_cache_entry(req);
2541  }
2542 }
BOOL WINAPI CreateUrlCacheEntryW(LPCWSTR lpszUrlName, DWORD dwExpectedFileSize, LPCWSTR lpszFileExtension, LPWSTR lpszFileName, DWORD dwReserved)
Definition: urlcache.c:2815
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
#define INTERNET_FLAG_NO_CACHE_WRITE
Definition: wininet.h:66
void req_file_release(req_file_t *req_file)
Definition: internet.c:4015
#define CloseHandle
Definition: compat.h:598
#define INTERNET_FLAG_NEED_FILE
Definition: wininet.h:88
#define TRUE
Definition: types.h:120
#define WARN(fmt,...)
Definition: debug.h:112
ULONGLONG contentLength
Definition: internet.h:374
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
#define lstrlenW
Definition: compat.h:609
BOOL(* end_of_data)(data_stream_t *, http_request_t *)
Definition: http.c:317
#define FILE_SHARE_READ
Definition: compat.h:136
HTTPHEADERW * custHeaders
Definition: internet.h:363
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GENERIC_WRITE
Definition: nt_native.h:90
#define FIXME(fmt,...)
Definition: debug.h:111
req_file_t * req_file
Definition: internet.h:368
static PVOID ptr
Definition: dispmode.c:27
object_header_t hdr
Definition: internet.h:345
DWORD create_req_file(const WCHAR *file_name, req_file_t **ret)
Definition: internet.c:3988
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
data_stream_t * data_stream
Definition: internet.h:380
_CONST_RETURN wchar_t *__cdecl wcschr(_In_z_ const wchar_t *_Str, wchar_t _Ch)
__wchar_t WCHAR
Definition: xmlstorage.h:180
static const WCHAR url[]
Definition: encode.c:1432
#define MAX_PATH
Definition: compat.h:34
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD read_size
Definition: internet.h:377
GLuint GLuint end
Definition: gl.h:1545
#define wcsnicmp
Definition: compat.h:14
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
static const WCHAR L[]
Definition: oid.c:1250
const data_stream_vtbl_t * vtbl
Definition: internet.h:332
static INT HTTP_GetCustomHeaderIndex(http_request_t *req, LPCWSTR lpszField, INT index, BOOL Request)
HANDLE hCacheFile
Definition: internet.h:367
#define CREATE_ALWAYS
Definition: disk.h:72
DWORD read_pos
Definition: internet.h:376
#define ARRAY_SIZE(a)
Definition: main.h:24
#define NULL
Definition: types.h:112
BYTE read_buf[READ_BUFFER_SIZE]
Definition: internet.h:378
static LPCWSTR file_name
Definition: protocol.c:147
#define CreateFileW
Definition: compat.h:600
static void commit_cache_entry(http_request_t *req)
Definition: http.c:2426
LPWSTR lpszValue
Definition: internet.h:321
WCHAR * url
Definition: internet.h:251
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
static WCHAR * compose_request_url(http_request_t *req)
Definition: http.c:1815
CRITICAL_SECTION headers_section
Definition: internet.h:362

Referenced by HTTP_HttpEndRequestW(), and HTTP_HttpSendRequestW().

◆ destroy_authinfo()

static void destroy_authinfo ( struct HttpAuthInfo authinfo)
static

Definition at line 763 of file http.c.

764 {
765  if (!authinfo) return;
766 
771 
772  heap_free(authinfo->auth_data);
775 }
#define SecIsValidHandle(x)
Definition: sspi.h:63
SECURITY_STATUS WINAPI FreeCredentialsHandle(PCredHandle phCredential)
Definition: wrapper.c:151
CredHandle cred
DWORD scheme
SECURITY_STATUS WINAPI DeleteSecurityContext(PCtxtHandle phContext)
Definition: wrapper.c:450
static BOOL heap_free(void *mem)
Definition: appwiz.h:75
CtxtHandle ctx

Referenced by HTTP_DoAuthorization(), HTTP_HttpSendRequestW(), and HTTPREQ_Destroy().

◆ destroy_data_stream()

static void destroy_data_stream ( data_stream_t stream)
inlinestatic

Definition at line 342 of file http.c.

343 {
344  stream->vtbl->destroy(stream);
345 }
Definition: parse.h:22

Referenced by gzip_destroy(), HTTPREQ_Destroy(), and reset_data_stream().

◆ drain_content()

static DWORD drain_content ( http_request_t req,
BOOL  blocking 
)
static

Definition at line 3091 of file http.c.

3092 {
3093  DWORD res;
3094 
3095  TRACE("%p\n", req->netconn);
3096 
3097  if(!is_valid_netconn(req->netconn))
3098  return ERROR_NO_DATA;
3099 
3100  if(!wcscmp(req->verb, L"HEAD"))
3101  return ERROR_SUCCESS;
3102 
3104  res = req->data_stream->vtbl->drain_content(req->data_stream, req, blocking);
3106  return res;
3107 }
#define ERROR_SUCCESS
Definition: deptool.c:10
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
netconn_t * netconn
Definition: internet.h:351
data_stream_t * data_stream
Definition: internet.h:380
#define TRACE(s)
Definition: solgame.cpp:4
LPWSTR verb
Definition: internet.h:350
#define ERROR_NO_DATA
Definition: winerror.h:284
DWORD(* drain_content)(data_stream_t *, http_request_t *, BOOL)
Definition: http.c:319
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
const data_stream_vtbl_t * vtbl
Definition: internet.h:332
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
BOOL is_valid_netconn(netconn_t *) DECLSPEC_HIDDEN
CRITICAL_SECTION read_section
Definition: internet.h:373
GLuint res
Definition: glext.h:9613
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)

Referenced by async_read_file_proc(), HTTP_HttpEndRequestW(), HTTP_HttpSendRequestW(), HTTPREQ_CloseConnection(), HTTPREQ_Read(), and open_http_connection().

◆ encode_auth_data()

static WCHAR* encode_auth_data ( const WCHAR scheme,
const char data,
UINT  data_len 
)
static

Definition at line 1574 of file http.c.

1575 {
1576  WCHAR *ret;
1577  UINT len, scheme_len = lstrlenW( scheme );
1578 
1579  /* scheme + space + base64 encoded data (3/2/1 bytes data -> 4 bytes of characters) */
1580  len = scheme_len + 1 + ((data_len + 2) * 4) / 3;
1581  if (!(ret = heap_alloc( (len + 1) * sizeof(WCHAR) ))) return NULL;
1582  memcpy( ret, scheme, scheme_len * sizeof(WCHAR) );
1583  ret[scheme_len] = ' ';
1584  HTTP_EncodeBase64( data, data_len, ret + scheme_len + 1 );
1585  return ret;
1586 }
DWORD scheme
static UINT HTTP_EncodeBase64(LPCSTR bin, unsigned int len, LPWSTR base64)
Definition: http.c:1468
#define lstrlenW
Definition: compat.h:609
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
__wchar_t WCHAR
Definition: xmlstorage.h:180
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
int ret
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLsizei len
Definition: glext.h:6722
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112

Referenced by HTTP_InsertAuthorization().

◆ end_of_read_data()

static BOOL end_of_read_data ( http_request_t req)
static

Definition at line 2625 of file http.c.

2626 {
2627  return !req->read_size && req->data_stream->vtbl->end_of_data(req->data_stream, req);
2628 }
BOOL(* end_of_data)(data_stream_t *, http_request_t *)
Definition: http.c:317
data_stream_t * data_stream
Definition: internet.h:380
DWORD read_size
Definition: internet.h:377
const data_stream_vtbl_t * vtbl
Definition: internet.h:332

Referenced by HTTPREQ_QueryDataAvailable(), and HTTPREQ_ReadFile().

◆ free_accept_types()

static void free_accept_types ( WCHAR **  accept_types)
static

Definition at line 1346 of file http.c.

1347 {
1348  WCHAR *ptr, **types = accept_types;
1349 
1350  if (!types) return;
1351  while ((ptr = *types))
1352  {
1353  heap_free( ptr );
1354  types++;
1355  }
1356  heap_free( accept_types );
1357 }
static PVOID ptr
Definition: dispmode.c:27
Definition: cmds.c:130
__wchar_t WCHAR
Definition: xmlstorage.h:180
static BOOL heap_free(void *mem)
Definition: appwiz.h:75

Referenced by HttpOpenRequestA().

◆ free_authorization_cache()

void free_authorization_cache ( void  )

Definition at line 943 of file http.c.

944 {
945  authorizationData *ad, *sa_safe;
946  basicAuthorizationData *basic, *basic_safe;
947 
949 
951  {
952  heap_free(basic->host);
953  heap_free(basic->realm);
954  heap_free(basic->authorization);
955 
956  list_remove(&basic->entry);
957  heap_free(basic);
958  }
959 
961  {
962  heap_free(ad->host);
963  heap_free(ad->scheme);
964  heap_free(ad->user);
965  heap_free(ad->password);
966  heap_free(ad->domain);
967  list_remove(&ad->entry);
968  heap_free(ad);
969  }
970 
972 }
static struct list basicAuthorizationCache
Definition: http.c:114
struct list entry
Definition: http.c:102
LPWSTR password
Definition: http.c:110
LPWSTR domain
Definition: http.c:106
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
__WINE_SERVER_LIST_INLINE void list_remove(struct list *elem)
Definition: list.h:108
uint32_t entry
Definition: isohybrid.c:63
#define LIST_FOR_EACH_ENTRY_SAFE(cursor, cursor2, list, type, field)
Definition: list.h:204
LPWSTR scheme
Definition: http.c:105
struct list entry
Definition: http.c:92
LPWSTR host
Definition: http.c:104
LPWSTR user
Definition: http.c:108
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
static BOOL heap_free(void *mem)
Definition: appwiz.h:75
static struct list authorizationCache
Definition: http.c:115
static CRITICAL_SECTION authcache_cs
Definition: http.c:117

Referenced by InternetSetOptionW().

◆ get_host_header()

static WCHAR* get_host_header ( http_request_t req)
static

Definition at line 304 of file http.c.

305 {
307  WCHAR *ret = NULL;
308 
310  if ((header = HTTP_GetHeader( req, L"Host" ))) ret = heap_strdupW( header->lpszValue );
311  else ret = heap_strdupW( req->server->canon_host_port );
313  return ret;
314 }
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
const WCHAR * canon_host_port
Definition: internet.h:45
static WCHAR * heap_strdupW(const WCHAR *str)
Definition: propsheet.c:178
__wchar_t WCHAR
Definition: xmlstorage.h:180
int ret
static const WCHAR L[]
Definition: oid.c:1250
static LPHTTPHEADERW HTTP_GetHeader(http_request_t *req, LPCWSTR head)
Definition: http.c:294
server_t * server
Definition: internet.h:347
#define NULL
Definition: types.h:112
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
CRITICAL_SECTION headers_section
Definition: internet.h:362
struct CFHEADER header
Definition: fdi.c:101

Referenced by HTTP_InsertAuthorization().

◆ get_redirect_url()

static WCHAR* get_redirect_url ( http_request_t request)
static

Definition at line 4076 of file http.c.

4077 {
4078  static WCHAR szHttp[] = L"http";
4079  static WCHAR szHttps[] = L"https";
4080  http_session_t *session = request->session;
4081  URL_COMPONENTSW urlComponents = { sizeof(urlComponents) };
4082  WCHAR *orig_url = NULL, *redirect_url = NULL, *combined_url = NULL;
4083  DWORD url_length = 0, res;
4084  BOOL b;
4085 
4086  url_length = 0;
4087  res = HTTP_HttpQueryInfoW(request, HTTP_QUERY_LOCATION, redirect_url, &url_length, NULL);
4089  redirect_url = heap_alloc(url_length);
4090  res = HTTP_HttpQueryInfoW(request, HTTP_QUERY_LOCATION, redirect_url, &url_length, NULL);
4091  }
4092  if(res != ERROR_SUCCESS) {
4093  heap_free(redirect_url);
4094  return NULL;
4095  }
4096 
4097  urlComponents.dwSchemeLength = 1;
4098  b = InternetCrackUrlW(redirect_url, url_length / sizeof(WCHAR), 0, &urlComponents);
4099  if(b && urlComponents.dwSchemeLength &&
4100  urlComponents.nScheme != INTERNET_SCHEME_HTTP && urlComponents.nScheme != INTERNET_SCHEME_HTTPS) {
4101  TRACE("redirect to non-http URL\n");
4102  return NULL;
4103  }
4104 
4105  urlComponents.lpszScheme = (request->hdr.dwFlags & INTERNET_FLAG_SECURE) ? szHttps : szHttp;
4106  urlComponents.dwSchemeLength = 0;
4107  urlComponents.lpszHostName = request->server->name;
4108  urlComponents.nPort = request->server->port;
4109  urlComponents.lpszUserName = session->userName;
4110  urlComponents.lpszUrlPath = request->path;
4111 
4112  b = InternetCreateUrlW(&urlComponents, 0, NULL, &url_length);
4114  orig_url = heap_alloc(url_length);
4115 
4116  /* convert from bytes to characters */
4117  url_length = url_length / sizeof(WCHAR) - 1;
4118  b = InternetCreateUrlW(&urlComponents, 0, orig_url, &url_length);
4119  }
4120 
4121  if(b) {
4122  url_length = 0;
4123  b = InternetCombineUrlW(orig_url, redirect_url, NULL, &url_length, ICU_ENCODE_SPACES_ONLY);
4125  combined_url = heap_alloc(url_length * sizeof(WCHAR));
4126  b = InternetCombineUrlW(orig_url, redirect_url, combined_url, &url_length, ICU_ENCODE_SPACES_ONLY);
4127  if(!b) {
4129  combined_url = NULL;
4130  }
4131  }
4132  }
4133 
4134  heap_free(orig_url);
4135  heap_free(redirect_url);
4136  return combined_url;
4137 }
#define ERROR_SUCCESS
Definition: deptool.c:10
#define INTERNET_FLAG_SECURE
Definition: wininet.h:71
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
LPWSTR lpszHostName
Definition: wininet.h:215
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
DWORD dwSchemeLength
Definition: wininet.h:213
INTERNET_PORT nPort
Definition: wininet.h:217
unsigned int BOOL
Definition: ntddk_ex.h:94
char path[256]
Definition: tftpd.h:94
static DWORD HTTP_HttpQueryInfoW(http_request_t *, DWORD, LPVOID, LPDWORD, LPDWORD)
Definition: http.c:3592
#define b
Definition: ke_i.h:79
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
#define TRACE(s)
Definition: solgame.cpp:4
#define ICU_ENCODE_SPACES_ONLY
Definition: winhttp.h:293
LPWSTR lpszScheme
Definition: wininet.h:212
__wchar_t WCHAR
Definition: xmlstorage.h:180
INTERNET_SCHEME nScheme
Definition: wininet.h:214
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL WINAPI InternetCombineUrlW(LPCWSTR lpszBaseUrl, LPCWSTR lpszRelativeUrl, LPWSTR lpszBuffer, LPDWORD lpdwBufferLength, DWORD dwFlags)
Definition: internet.c:4147
LPWSTR lpszUserName
Definition: wininet.h:218
static const WCHAR L[]
Definition: oid.c:1250
LPWSTR lpszUrlPath
Definition: wininet.h:222
BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags, LPWSTR lpszUrl, LPDWORD lpdwUrlLength)
Definition: internet.c:4425
struct object_header hdr
#define NULL
Definition: types.h:112
const char * combined_url
Definition: protocol.c:466
Definition: tftpd.h:85
BOOL WINAPI InternetCrackUrlW(const WCHAR *lpszUrl, DWORD dwUrlLength, DWORD dwFlags, URL_COMPONENTSW *lpUC)
Definition: internet.c:1625
GLuint res
Definition: glext.h:9613
#define HTTP_QUERY_LOCATION
Definition: wininet.h:1556
static BOOL heap_free(void *mem)
Definition: appwiz.h:75
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10

Referenced by HTTP_HttpEndRequestW(), and HTTP_HttpSendRequestW().

◆ get_security_cert_struct()

static DWORD get_security_cert_struct ( http_request_t req,
INTERNET_CERTIFICATE_INFOA info 
)
static

Definition at line 2022 of file http.c.

2023 {
2025  DWORD len;
2026 
2028  if(!context)
2029  return ERROR_NOT_SUPPORTED;
2030 
2031  memset(info, 0, sizeof(*info));
2032  info->ftExpiry = context->pCertInfo->NotAfter;
2033  info->ftStart = context->pCertInfo->NotBefore;
2034  len = CertNameToStrA(context->dwCertEncodingType,
2035  &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR|CERT_NAME_STR_CRLF_FLAG, NULL, 0);
2036  info->lpszSubjectInfo = LocalAlloc(0, len);
2037  if(info->lpszSubjectInfo)
2038  CertNameToStrA(context->dwCertEncodingType,
2040  info->lpszSubjectInfo, len);
2041  len = CertNameToStrA(context->dwCertEncodingType,
2042  &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR|CERT_NAME_STR_CRLF_FLAG, NULL, 0);
2043  info->lpszIssuerInfo = LocalAlloc(0, len);
2044  if(info->lpszIssuerInfo)
2045  CertNameToStrA(context->dwCertEncodingType,
2047  info->lpszIssuerInfo, len);
2048  info->dwKeySize = NETCON_GetCipherStrength(req->netconn);
2049 
2051  return ERROR_SUCCESS;
2052 }
#define ERROR_SUCCESS
Definition: deptool.c:10
Definition: http.c:7251
BOOL WINAPI CertFreeCertificateContext(PCCERT_CONTEXT pCertContext)
Definition: cert.c:371
DWORD WINAPI CertNameToStrA(DWORD dwCertEncodingType, PCERT_NAME_BLOB pName, DWORD dwStrType, LPSTR psz, DWORD csz)
Definition: str.c:414
int NETCON_GetCipherStrength(netconn_t *) DECLSPEC_HIDDEN
#define CERT_NAME_STR_CRLF_FLAG
Definition: wincrypt.h:3490
netconn_t * netconn
Definition: internet.h:351
LPCVOID NETCON_GetCert(netconn_t *connection) DECLSPEC_HIDDEN
const CERT_CONTEXT * PCCERT_CONTEXT
Definition: wincrypt.h:485
unsigned long DWORD
Definition: ntddk_ex.h:95
_In_opt_ PVOID _In_ ULONG _In_ PVOID context
Definition: wdfdriver.h:113
GLenum GLsizei len
Definition: glext.h:6722
#define NULL
Definition: types.h:112
#define ERROR_NOT_SUPPORTED
Definition: compat.h:100
#define CERT_SIMPLE_NAME_STR
Definition: wincrypt.h:3484
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1373
#define memset(x, y, z)
Definition: compat.h:39

Referenced by HTTPREQ_QueryOption().

◆ get_server()

server_t* get_server ( substr_t  name,
INTERNET_PORT  port,
BOOL  is_https,
BOOL  do_create 
)

Definition at line 198 of file http.c.

199 {
200  server_t *iter, *server = NULL;
201 
203 
205  if(iter->port == port && name.len == lstrlenW(iter->name) && !wcsnicmp(iter->name, name.str, name.len)
206  && iter->is_https == is_https) {
207  server = iter;
209  break;
210  }
211  }
212 
213  if(!server && do_create) {
214  server = heap_alloc_zero(sizeof(*server));
215  if(server) {
216  server->ref = 2; /* list reference and return */
217  server->port = port;
218  server->is_https = is_https;
219  list_init(&server->conn_pool);
220  server->name = heap_strndupW(name.str, name.len);
221  if(server->name && process_host_port(server)) {
223  }else {
224  heap_free(server);
225  server = NULL;
226  }
227  }
228  }
229 
231 
232  return server;
233 }
static BOOL process_host_port(server_t *server)
Definition: http.c:174
BOOL is_https
Definition: internet.h:38
static LPWSTR heap_strndupW(LPCWSTR str, unsigned len)
static rfbScreenInfoPtr server
Definition: vnc.c:74
__WINE_SERVER_LIST_INLINE void list_add_head(struct list *list, struct list *elem)
Definition: list.h:96
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
#define lstrlenW
Definition: compat.h:609
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:198
INTERNET_PORT port
Definition: internet.h:37
static CRITICAL_SECTION connection_pool_cs
Definition: http.c:137
#define wcsnicmp
Definition: compat.h:14
uint32_t entry
Definition: isohybrid.c:63
void server_addref(server_t *server)
Definition: http.c:149
WCHAR * name
Definition: internet.h:36
#define NULL
Definition: types.h:112
Definition: name.c:38
__WINE_SERVER_LIST_INLINE void list_init(struct list *list)
Definition: list.h:149
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
USHORT port
Definition: uri.c:228
static struct list connection_pool
Definition: http.c:146
static BOOL heap_free(void *mem)
Definition: appwiz.h:75

Referenced by HTTP_DealWithProxy(), HTTP_HandleRedirect(), and HTTP_HttpOpenRequestW().

◆ gzip_destroy()

static void gzip_destroy ( data_stream_t stream)
static

Definition at line 450 of file http.c.

451 {
452  gzip_stream_t *gzip_stream = (gzip_stream_t*)stream;
453 
454  destroy_data_stream(gzip_stream->parent_stream);
455 
456  if(!gzip_stream->end_of_data)
457  inflateEnd(&gzip_stream->zstream);
458  heap_free(gzip_stream);
459 }
data_stream_t * parent_stream
Definition: http.c:366
BOOL end_of_data
Definition: http.c:371
static void destroy_data_stream(data_stream_t *stream)
Definition: http.c:342
int inflateEnd(z_streamp strm)
Definition: inflate.c:1910
Definition: parse.h:22
z_stream zstream
Definition: http.c:367
static BOOL heap_free(void *mem)
Definition: appwiz.h:75

◆ gzip_drain_content()

static DWORD gzip_drain_content ( data_stream_t stream,
http_request_t req,
BOOL  allow_blocking 
)
static

Definition at line 444 of file http.c.

445 {
446  gzip_stream_t *gzip_stream = (gzip_stream_t*)stream;
447  return gzip_stream->parent_stream->vtbl->drain_content(gzip_stream->parent_stream, req, allow_blocking);
448 }
data_stream_t * parent_stream
Definition: http.c:366
DWORD(* drain_content)(data_stream_t *, http_request_t *, BOOL)
Definition: http.c:319
Definition: parse.h:22
const data_stream_vtbl_t * vtbl
Definition: internet.h:332

◆ gzip_end_of_data()

static BOOL gzip_end_of_data ( data_stream_t stream,
http_request_t req 
)
static

Definition at line 374 of file http.c.

375 {
376  gzip_stream_t *gzip_stream = (gzip_stream_t*)stream;
377  return gzip_stream->end_of_data
378  || (!gzip_stream->buf_size && gzip_stream->parent_stream->vtbl->end_of_data(gzip_stream->parent_stream, req));
379 }
DWORD buf_size
Definition: http.c:369
data_stream_t * parent_stream
Definition: http.c:366
BOOL(* end_of_data)(data_stream_t *, http_request_t *)
Definition: http.c:317
BOOL end_of_data
Definition: http.c:371
Definition: parse.h:22
const data_stream_vtbl_t * vtbl
Definition: internet.h:332

◆ gzip_read()

static DWORD gzip_read ( data_stream_t stream,
http_request_t req,
BYTE buf,
DWORD  size,
DWORD read,
BOOL  allow_blocking 
)
static

Definition at line 381 of file http.c.

383 {
384  gzip_stream_t *gzip_stream = (gzip_stream_t*)stream;
385  z_stream *zstream = &gzip_stream->zstream;
386  DWORD current_read, ret_read = 0;
387  int zres;
389 
390  TRACE("(%d %x)\n", size, allow_blocking);
391 
392  while(size && !gzip_stream->end_of_data) {
393  if(!gzip_stream->buf_size) {
394  if(gzip_stream->buf_pos) {
395  if(gzip_stream->buf_size)
396  memmove(gzip_stream->buf, gzip_stream->buf+gzip_stream->buf_pos, gzip_stream->buf_size);
397  gzip_stream->buf_pos = 0;
398  }
399  res = gzip_stream->parent_stream->vtbl->read(gzip_stream->parent_stream, req, gzip_stream->buf+gzip_stream->buf_size,
400  sizeof(gzip_stream->buf)-gzip_stream->buf_size, &current_read, allow_blocking);
401  if(res != ERROR_SUCCESS)
402  break;
403 
404  gzip_stream->buf_size += current_read;
405  if(!current_read) {
406  WARN("unexpected end of data\n");
407  gzip_stream->end_of_data = TRUE;
408  break;
409  }
410  }
411 
412  zstream->next_in = gzip_stream->buf+gzip_stream->buf_pos;
413  zstream->avail_in = gzip_stream->buf_size;
414  zstream->next_out = buf+ret_read;
415  zstream->avail_out = size;
416  zres = inflate(&gzip_stream->zstream, 0);
417  current_read = size - zstream->avail_out;
418  size -= current_read;
419  ret_read += current_read;
420  gzip_stream->buf_size -= zstream->next_in - (gzip_stream->buf+gzip_stream->buf_pos);
421  gzip_stream->buf_pos = zstream->next_in-gzip_stream->buf;
422  if(zres == Z_STREAM_END) {
423  TRACE("end of data\n");
424  gzip_stream->end_of_data = TRUE;
425  inflateEnd(zstream);
426  }else if(zres != Z_OK) {
427  WARN("inflate failed %d: %s\n", zres, debugstr_a(zstream->msg));
428  if(!ret_read)
430  break;
431  }
432 
433  if(ret_read)
434  allow_blocking = FALSE;
435  }
436 
437  TRACE("read %u bytes\n", ret_read);
438  if(ret_read)
439  res = ERROR_SUCCESS;
440  *read = ret_read;
441  return res;
442 }
DWORD buf_size
Definition: http.c:369
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
#define ERROR_SUCCESS
Definition: deptool.c:10
#define TRUE
Definition: types.h:120
#define Z_OK
Definition: zlib.h:114
#define WARN(fmt,...)
Definition: debug.h:112
uInt avail_in
Definition: zlib.h:60
data_stream_t * parent_stream
Definition: http.c:366
z_const char * msg
Definition: zlib.h:67
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define Z_STREAM_END
Definition: zlib.h:115
#define FALSE
Definition: types.h:117
DWORD buf_pos
Definition: http.c:370
BYTE buf[READ_BUFFER_SIZE]
Definition: http.c:368
BOOL end_of_data
Definition: http.c:371
z_const Bytef * next_in
Definition: zlib.h:59
#define ERROR_INTERNET_DECODING_FAILED
Definition: wininet.h:2083
#define TRACE(s)
Definition: solgame.cpp:4
GLsizeiptr size
Definition: glext.h:5919
#define debugstr_a
Definition: kernel32.h:31
unsigned long DWORD
Definition: ntddk_ex.h:95
int inflateEnd(z_streamp strm)
Definition: inflate.c:1910
Definition: parse.h:22
z_stream zstream
Definition: http.c:367
const data_stream_vtbl_t * vtbl
Definition: internet.h:332
uInt avail_out
Definition: zlib.h:64
DWORD(* read)(data_stream_t *, http_request_t *, BYTE *, DWORD, DWORD *, BOOL)
Definition: http.c:318
GLuint res
Definition: glext.h:9613
int inflate(z_streamp strm, int flush)
Definition: inflate.c:1257
Bytef * next_out
Definition: zlib.h:63
_CRTIMP int __cdecl read(_In_ int _FileHandle, _Out_writes_bytes_(_MaxCharCount) void *_DstBuf, _In_ unsigned int _MaxCharCount)

◆ HTTP_build_req()

static LPWSTR HTTP_build_req ( LPCWSTR list,
int  len 
)
static

Definition at line 4259 of file http.c.

4260 {
4261  LPCWSTR *t;
4262  LPWSTR str;
4263 
4264  for( t = list; *t ; t++ )
4265  len += lstrlenW( *t );
4266  len++;
4267 
4268  str = heap_alloc(len*sizeof(WCHAR));
4269  *str = 0;
4270 
4271  for( t = list; *t ; t++ )
4272  lstrcatW( str, *t );
4273 
4274  return str;
4275 }
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
GLdouble GLdouble t
Definition: gl.h:2047
#define lstrlenW
Definition: compat.h:609
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
const WCHAR * str
__wchar_t WCHAR
Definition: xmlstorage.h:180
GLenum GLsizei len
Definition: glext.h:6722
Definition: _list.h:228
LPWSTR WINAPI lstrcatW(LPWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:274
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by build_request_header(), and build_response_header().

◆ HTTP_clear_response_headers()

static void HTTP_clear_response_headers ( http_request_t request)
static

Definition at line 5901 of file http.c.

5902 {
5903  DWORD i;
5904 
5905  EnterCriticalSection( &request->headers_section );
5906 
5907  for( i=0; i<request->nCustHeaders; i++)
5908  {
5909  if( !request->custHeaders[i].lpszField )
5910  continue;
5911  if( !request->custHeaders[i].lpszValue )
5912  continue;
5913  if ( request->custHeaders[i].wFlags & HDR_ISREQUEST )
5914  continue;
5916  i--;
5917  }
5918 
5919  LeaveCriticalSection( &request->headers_section );
5920 }
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
#define HDR_ISREQUEST
Definition: internet.h:314
static BOOL HTTP_DeleteCustomHeader(http_request_t *req, DWORD index)
Definition: http.c:6322
unsigned long DWORD
Definition: ntddk_ex.h:95
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
Definition: tftpd.h:85
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)

Referenced by HTTP_GetResponseHeaders().

◆ HTTP_Connect()

DWORD HTTP_Connect ( appinfo_t hIC,
LPCWSTR  lpszServerName,
INTERNET_PORT  serverPort,
LPCWSTR  lpszUserName,
LPCWSTR  lpszPassword,
DWORD  dwFlags,
DWORD_PTR  dwContext,
DWORD  dwInternalFlags,
HINTERNET ret 
)

Definition at line 5836 of file http.c.

5840 {
5842 
5843  TRACE("-->\n");
5844 
5845  if (!lpszServerName || !lpszServerName[0])
5846  return ERROR_INVALID_PARAMETER;
5847 
5848  assert( hIC->hdr.htype == WH_HINIT );
5849 
5851  if (!session)
5852  return ERROR_OUTOFMEMORY;
5853 
5854  /*
5855  * According to my tests. The name is not resolved until a request is sent
5856  */
5857 
5858  session->hdr.htype = WH_HHTTPSESSION;
5859  session->hdr.dwFlags = dwFlags;
5860  session->hdr.dwContext = dwContext;
5861  session->hdr.dwInternalFlags |= dwInternalFlags;
5862  session->hdr.decoding = hIC->hdr.decoding;
5863 
5864  WININET_AddRef( &hIC->hdr );
5865  session->appInfo = hIC;
5866  list_add_head( &hIC->hdr.children, &session->hdr.entry );
5867 
5868  session->hostName = heap_strdupW(lpszServerName);
5869  if (lpszUserName && lpszUserName[0])
5870  session->userName = heap_strdupW(lpszUserName);
5871  session->password = heap_strdupW(lpszPassword);
5872  session->hostPort = serverPort;
5874  session->send_timeout = 0;
5875  session->receive_timeout = 0;
5876 
5877  /* Don't send a handle created callback if this handle was created with InternetOpenUrl */
5878  if (!(session->hdr.dwInternalFlags & INET_OPENURL))
5879  {
5880  INTERNET_SendCallback(&hIC->hdr, dwContext,
5882  sizeof(HINTERNET));
5883  }
5884 
5885 /*
5886  * an INTERNET_STATUS_REQUEST_COMPLETE is NOT sent here as per my tests on
5887  * windows
5888  */
5889 
5890  TRACE("%p --> %p\n", hIC, session);
5891 
5892  *ret = session->hdr.hInternet;
5893  return ERROR_SUCCESS;
5894 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define ERROR_SUCCESS
Definition: deptool.c:10
__WINE_SERVER_LIST_INLINE void list_add_head(struct list *list, struct list *elem)
Definition: list.h:96
struct list children
Definition: internet.h:286
#define assert(x)
Definition: debug.h:53
_In_opt_ LPSTR _In_opt_ LPSTR lpszPassword
Definition: winbase.h:2690
int receive_timeout
VOID INTERNET_SendCallback(object_header_t *hdr, DWORD_PTR dwContext, DWORD dwInternetStatus, LPVOID lpvStatusInfo, DWORD dwStatusInfoLength) DECLSPEC_HIDDEN
static WCHAR * heap_strdupW(const WCHAR *str)
Definition: propsheet.c:178
object_header_t * WININET_AddRef(object_header_t *info)
Definition: internet.c:169
#define TRACE(s)
Definition: solgame.cpp:4
struct object_header hdr
int ret
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
void * alloc_object(object_header_t *parent, const object_vtbl_t *vtbl, size_t size)
Definition: internet.c:103
DWORD connect_timeout
Definition: internet.h:298
static const object_vtbl_t HTTPSESSIONVtbl
Definition: http.c:5814
object_header_t hdr
Definition: internet.h:291
#define INET_OPENURL
Definition: internet.h:243
#define NULL
Definition: types.h:112
int connect_timeout
int send_timeout
#define INTERNET_STATUS_HANDLE_CREATED
Definition: wininet.h:895
WH_TYPE htype
Definition: internet.h:273
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13

Referenced by INTERNET_InternetOpenUrlW(), and InternetConnectW().

◆ HTTP_DealWithProxy()

static BOOL HTTP_DealWithProxy ( appinfo_t hIC,
http_session_t session,
http_request_t request 
)
static

Definition at line 1748 of file http.c.

1749 {
1750  static WCHAR szNul[] = L"";
1751  URL_COMPONENTSW UrlComponents = { sizeof(UrlComponents) };
1752  server_t *new_server = NULL;
1753  WCHAR *proxy;
1754 
1755  proxy = INTERNET_FindProxyForProtocol(hIC->proxy, L"http");
1756  if(!proxy)
1757  return FALSE;
1759  proxy, lstrlenW(L"http://"), L"http://", lstrlenW(L"http://"))) {
1760  WCHAR *proxy_url = heap_alloc(lstrlenW(proxy)*sizeof(WCHAR) + sizeof(L"http://"));
1761  if(!proxy_url) {
1762  heap_free(proxy);
1763  return FALSE;
1764  }
1765  lstrcpyW(proxy_url, L"http://");
1766  lstrcatW(proxy_url, proxy);
1767  heap_free(proxy);
1768  proxy = proxy_url;
1769  }
1770 
1771  UrlComponents.dwHostNameLength = 1;
1772  if(InternetCrackUrlW(proxy, 0, 0, &UrlComponents) && UrlComponents.dwHostNameLength) {
1773  if( !request->path )
1774  request->path = szNul;
1775 
1776  new_server = get_server(substr(UrlComponents.lpszHostName, UrlComponents.dwHostNameLength),
1777  UrlComponents.nPort, UrlComponents.nScheme == INTERNET_SCHEME_HTTPS, TRUE);
1778  }
1779  heap_free(proxy);
1780  if(!new_server)
1781  return FALSE;
1782 
1783  request->proxy = new_server;
1784 
1785  TRACE("proxy server=%s port=%d\n", debugstr_w(new_server->name), new_server->port);
1786  return TRUE;
1787 }
int proxy
Definition: main.c:67
#define TRUE
Definition: types.h:120
#define NORM_IGNORECASE
Definition: winnls.h:176
#define lstrlenW
Definition: compat.h:609
LPWSTR lpszHostName
Definition: wininet.h:215
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
INTERNET_PORT port
Definition: internet.h:37
#define FALSE
Definition: types.h:117
INTERNET_PORT nPort
Definition: wininet.h:217
#define debugstr_w
Definition: kernel32.h:32
char path[256]
Definition: tftpd.h:94
INT WINAPI CompareStringW(LCID lcid, DWORD flags, LPCWSTR str1, INT len1, LPCWSTR str2, INT len2)
Definition: lang.c:2275
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
INTERNET_SCHEME nScheme
Definition: wininet.h:214
#define LOCALE_SYSTEM_DEFAULT
DWORD dwHostNameLength
Definition: wininet.h:216
LPWSTR proxy
Definition: internet.h:293
static const WCHAR L[]
Definition: oid.c:1250
WCHAR * name
Definition: internet.h:36
#define CSTR_EQUAL
Definition: winnls.h:456
server_t * get_server(substr_t name, INTERNET_PORT port, BOOL is_https, BOOL do_create)
Definition: http.c:198
#define lstrcpyW
Definition: compat.h:608
#define NULL
Definition: types.h:112
Definition: tftpd.h:85
BOOL WINAPI InternetCrackUrlW(const WCHAR *lpszUrl, DWORD dwUrlLength, DWORD dwFlags, URL_COMPONENTSW *lpUC)
Definition: internet.c:1625
static substr_t substr(const WCHAR *str, size_t len)
Definition: internet.h:203
LPWSTR WINAPI lstrcatW(LPWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:274
WCHAR * INTERNET_FindProxyForProtocol(LPCWSTR szProxy, LPCWSTR proto)
Definition: internet.c:384
static BOOL heap_free(void *mem)
Definition: appwiz.h:75

Referenced by HTTP_HttpOpenRequestW().

◆ HTTP_DecodeBase64()

static UINT HTTP_DecodeBase64 ( LPCWSTR  base64,
LPSTR  bin 
)
static

Definition at line 1524 of file http.c.

1525 {
1526  unsigned int n = 0;
1527 
1528  while(*base64)
1529  {
1530  signed char in[4];
1531 
1532  if (base64[0] >= ARRAY_SIZE(HTTP_Base64Dec) ||
1533  ((in[0] = HTTP_Base64Dec[base64[0]]) == -1) ||
1534  base64[1] >= ARRAY_SIZE(HTTP_Base64Dec) ||
1535  ((in[1] = HTTP_Base64Dec[base64[1]]) == -1))
1536  {
1537  WARN("invalid base64: %s\n", debugstr_w(base64));
1538  return 0;
1539  }
1540  if (bin)
1541  bin[n] = (unsigned char) (in[0] << 2 | in[1] >> 4);
1542  n++;
1543 
1544  if ((base64[2] == '=') && (base64[3] == '='))
1545  break;
1546  if (base64[2] > ARRAY_SIZE(HTTP_Base64Dec) ||
1547  ((in[2] = HTTP_Base64Dec[base64[2]]) == -1))
1548  {
1549  WARN("invalid base64: %s\n", debugstr_w(&base64[2]));
1550  return 0;
1551  }
1552  if (bin)
1553  bin[n] = (unsigned char) (in[1] << 4 | in[2] >> 2);
1554  n++;
1555 
1556  if (base64[3] == '=')
1557  break;
1558  if (base64[3] > ARRAY_SIZE(HTTP_Base64Dec) ||
1559  ((in[3] = HTTP_Base64Dec[base64[3]]) == -1))
1560  {
1561  WARN("invalid base64: %s\n", debugstr_w(&base64[3]));
1562  return 0;
1563  }
1564  if (bin)
1565  bin[n] = (unsigned char) (((in[2] << 6) & 0xc0) | in[3]);
1566  n++;
1567 
1568  base64 += 4;
1569  }
1570 
1571  return n;
1572 }
#define WARN(fmt,...)
Definition: debug.h:112
GLdouble n
Definition: glext.h:7729
#define debugstr_w
Definition: kernel32.h:32
unsigned char
Definition: typeof.h:29
GLuint in
Definition: glext.h:9616
#define ARRAY_SIZE(a)
Definition: main.h:24
static struct _PeImage bin
static const signed char HTTP_Base64Dec[]
Definition: http.c:1509

Referenced by HTTP_DoAuthorization().

◆ HTTP_DeleteCustomHeader()

static BOOL HTTP_DeleteCustomHeader ( http_request_t req,
DWORD  index 
)
static

Definition at line 6322 of file http.c.

6323 {
6324  if( request->nCustHeaders <= 0 )
6325  return FALSE;
6326  if( index >= request->nCustHeaders )
6327  return FALSE;
6328  request->nCustHeaders--;
6329 
6330  heap_free(request->custHeaders[index].lpszField);
6331  heap_free(request->custHeaders[index].lpszValue);
6332 
6333  memmove( &request->custHeaders[index], &request->custHeaders[index+1],
6334  (request->nCustHeaders - index)* sizeof(HTTPHEADERW) );
6335  memset( &request->custHeaders[request->nCustHeaders], 0, sizeof(HTTPHEADERW) );
6336 
6337  return TRUE;
6338 }
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
GLuint index
Definition: glext.h:6031
Definition: tftpd.h:85
#define memset(x, y, z)
Definition: compat.h:39
static BOOL heap_free(void *mem)
Definition: appwiz.h:75

Referenced by HTTP_clear_response_headers(), HTTP_ProcessHeader(), remove_header(), and set_content_length().

◆ HTTP_DoAuthorization()

static BOOL HTTP_DoAuthorization ( http_request_t request,
LPCWSTR  pszAuthValue,
struct HttpAuthInfo **  ppAuthInfo,
LPWSTR  domain_and_username,
LPWSTR  password,
LPWSTR  host 
)
static

Definition at line 974 of file http.c.

978 {
979  SECURITY_STATUS sec_status;
980  struct HttpAuthInfo *pAuthInfo = *ppAuthInfo;
981  BOOL first = FALSE;
982  LPWSTR szRealm = NULL;
983 
984  TRACE("%s\n", debugstr_w(pszAuthValue));
985 
986  if (!pAuthInfo)
987  {
988  TimeStamp exp;
989 
990  first = TRUE;
991  pAuthInfo = heap_alloc(sizeof(*pAuthInfo));
992  if (!pAuthInfo)
993  return FALSE;
994 
995  SecInvalidateHandle(&pAuthInfo->cred);
996  SecInvalidateHandle(&pAuthInfo->ctx);
997  memset(&pAuthInfo->exp, 0, sizeof(pAuthInfo->exp));
998  pAuthInfo->attr = 0;
999  pAuthInfo->auth_data = NULL;
1000  pAuthInfo->auth_data_len = 0;
1001  pAuthInfo->finished = FALSE;
1002 
1003  if (is_basic_auth_value(pszAuthValue,NULL))
1004  {
1005  pAuthInfo->scheme = heap_strdupW(L"Basic");
1006  if (!pAuthInfo->scheme)
1007  {
1008  heap_free(pAuthInfo);
1009  return FALSE;
1010  }
1011  }
1012  else
1013  {
1014  PVOID pAuthData;
1015  SEC_WINNT_AUTH_IDENTITY_W nt_auth_identity;
1016 
1017  pAuthInfo->scheme = heap_strdupW(pszAuthValue);
1018  if (!pAuthInfo->scheme)
1019  {
1020  heap_free(pAuthInfo);
1021  return FALSE;
1022  }
1023 
1024  if (domain_and_username)
1025  {
1026  WCHAR *user = wcschr(domain_and_username, '\\');
1027  WCHAR *domain = domain_and_username;
1028 
1029  /* FIXME: make sure scheme accepts SEC_WINNT_AUTH_IDENTITY before calling AcquireCredentialsHandle */
1030 
1031  pAuthData = &nt_auth_identity;
1032 
1033  if (user) user++;
1034  else
1035  {
1036  user = domain_and_username;
1037  domain = NULL;
1038  }
1039 
1040  nt_auth_identity.Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE;
1041  nt_auth_identity.User = user;
1042  nt_auth_identity.UserLength = lstrlenW(nt_auth_identity.User);
1043  nt_auth_identity.Domain = domain;
1044  nt_auth_identity.DomainLength = domain ? user - domain - 1 : 0;
1045  nt_auth_identity.Password = password;
1046  nt_auth_identity.PasswordLength = lstrlenW(nt_auth_identity.Password);
1047 
1048  cache_authorization(host, pAuthInfo->scheme, &nt_auth_identity);
1049  }
1050  else if(retrieve_cached_authorization(host, pAuthInfo->scheme, &nt_auth_identity))
1051  pAuthData = &nt_auth_identity;
1052  else
1053  /* use default credentials */
1054  pAuthData = NULL;
1055 
1056  sec_status = AcquireCredentialsHandleW(NULL, pAuthInfo->scheme,
1058  pAuthData, NULL,
1059  NULL, &pAuthInfo->cred,
1060  &exp);
1061 
1062  if(pAuthData && !domain_and_username) {
1063  heap_free(nt_auth_identity.User);
1064  heap_free(nt_auth_identity.Domain);
1065  heap_free(nt_auth_identity.Password);
1066  }
1067 
1068  if (sec_status == SEC_E_OK)
1069  {
1070  PSecPkgInfoW sec_pkg_info;
1071  sec_status = QuerySecurityPackageInfoW(pAuthInfo->scheme, &sec_pkg_info);
1072  if (sec_status == SEC_E_OK)
1073  {
1074  pAuthInfo->max_token = sec_pkg_info->cbMaxToken;
1075  FreeContextBuffer(sec_pkg_info);
1076  }
1077  }
1078  if (sec_status != SEC_E_OK)
1079  {
1080  WARN("AcquireCredentialsHandleW for scheme %s failed with error 0x%08x\n",
1081  debugstr_w(pAuthInfo->scheme), sec_status);
1082  heap_free(pAuthInfo->scheme);
1083  heap_free(pAuthInfo);
1084  return FALSE;
1085  }
1086  }
1087  *ppAuthInfo = pAuthInfo;
1088  }
1089  else if (pAuthInfo->finished)
1090  return FALSE;
1091 
1092  if ((lstrlenW(pszAuthValue) < lstrlenW(pAuthInfo->scheme)) ||
1093  wcsnicmp(pszAuthValue, pAuthInfo->scheme, lstrlenW(pAuthInfo->scheme)))
1094  {
1095  ERR("authentication scheme changed from %s to %s\n",
1096  debugstr_w(pAuthInfo->scheme), debugstr_w(pszAuthValue));
1097  return FALSE;
1098  }
1099 
1100  if (is_basic_auth_value(pszAuthValue,&szRealm))
1101  {
1102  int userlen;
1103  int passlen;
1104  char *auth_data = NULL;
1105  UINT auth_data_len = 0;
1106 
1107  TRACE("basic authentication realm %s\n",debugstr_w(szRealm));
1108 
1109  if (!domain_and_username)
1110  {
1111  if (host && szRealm)
1113  if (auth_data_len == 0)
1114  {
1115  heap_free(szRealm);
1116  return FALSE;
1117  }
1118  }
1119  else
1120  {
1121  userlen = WideCharToMultiByte(CP_UTF8, 0, domain_and_username, lstrlenW(domain_and_username), NULL, 0, NULL, NULL);
1123 
1124  /* length includes a nul terminator, which will be re-used for the ':' */
1125  auth_data = heap_alloc(userlen + 1 + passlen);
1126  if (!auth_data)
1127  {
1128  heap_free(szRealm);
1129  return FALSE;
1130  }
1131 
1132  WideCharToMultiByte(CP_UTF8, 0, domain_and_username, -1, auth_data, userlen, NULL, NULL);
1133  auth_data[userlen] = ':';
1134  WideCharToMultiByte(CP_UTF8, 0, password, -1, &auth_data[userlen+1], passlen, NULL, NULL);
1135  auth_data_len = userlen + 1 + passlen;
1136  if (host && szRealm)
1138  }
1139 
1140  pAuthInfo->auth_data = auth_data;
1141  pAuthInfo->auth_data_len = auth_data_len;
1142  pAuthInfo->finished = TRUE;
1143  heap_free(szRealm);
1144  return TRUE;
1145  }
1146  else
1147  {
1148  LPCWSTR pszAuthData;
1149  SecBufferDesc out_desc, in_desc;
1150  SecBuffer out, in;
1151  unsigned char *buffer;
1154 
1155  in.BufferType = SECBUFFER_TOKEN;
1156  in.cbBuffer = 0;
1157  in.pvBuffer = NULL;
1158 
1159  in_desc.ulVersion = 0;
1160  in_desc.cBuffers = 1;
1161  in_desc.pBuffers = &in;
1162 
1163  pszAuthData = pszAuthValue + lstrlenW(pAuthInfo->scheme);
1164  if (*pszAuthData == ' ')
1165  {
1166  pszAuthData++;
1167  in.cbBuffer = HTTP_DecodeBase64(pszAuthData, NULL);
1168  in.pvBuffer = heap_alloc(in.cbBuffer);
1169  HTTP_DecodeBase64(pszAuthData, in.pvBuffer);
1170  }
1171 
1172  buffer = heap_alloc(pAuthInfo->max_token);
1173 
1174  out.BufferType = SECBUFFER_TOKEN;
1175  out.cbBuffer = pAuthInfo->max_token;
1176  out.pvBuffer = buffer;
1177 
1178  out_desc.ulVersion = 0;
1179  out_desc.cBuffers = 1;
1180  out_desc.pBuffers = &out;
1181 
1182  sec_status = InitializeSecurityContextW(first ? &pAuthInfo->cred : NULL,
1183  first ? NULL : &pAuthInfo->ctx,
1184  first ? request->server->name : NULL,
1185  context_req, 0, SECURITY_NETWORK_DREP,
1186  in.pvBuffer ? &in_desc : NULL,
1187  0, &pAuthInfo->ctx, &out_desc,
1188  &pAuthInfo->attr, &pAuthInfo->exp);
1189  if (sec_status == SEC_E_OK)
1190  {
1191  pAuthInfo->finished = TRUE;
1192  pAuthInfo->auth_data = out.pvBuffer;
1193  pAuthInfo->auth_data_len = out.cbBuffer;
1194  TRACE("sending last auth packet\n");
1195  }
1196  else if (sec_status == SEC_I_CONTINUE_NEEDED)
1197  {
1198  pAuthInfo->auth_data = out.pvBuffer;
1199  pAuthInfo->auth_data_len = out.cbBuffer;
1200  TRACE("sending next auth packet\n");
1201  }
1202  else
1203  {
1204  ERR("InitializeSecurityContextW returned error 0x%08x\n", sec_status);
1205  heap_free(out.pvBuffer);
1206  destroy_authinfo(pAuthInfo);
1207  *ppAuthInfo = NULL;
1208  return FALSE;
1209  }
1210  }
1211 
1212  return TRUE;
1213 }
static BOOL is_basic_auth_value(LPCWSTR pszAuthValue, LPWSTR *pszRealm)
Definition: http.c:727
unsigned int auth_data_len
Definition: http.c:85
CtxtHandle ctx
Definition: http.c:80
unsigned short * Domain
Definition: rpcdce.h:225
unsigned short * User
Definition: rpcdce.h:223
#define SECPKG_CRED_OUTBOUND
Definition: sspi.h:291
#define WideCharToMultiByte
Definition: compat.h:111
SECURITY_STATUS WINAPI AcquireCredentialsHandleW(SEC_WCHAR *pszPrincipal, SEC_WCHAR *pszPackage, ULONG fCredentialsUse, PLUID pvLogonID, PVOID pAuthData, SEC_GET_KEY_FN pGetKeyFn, PVOID pvGetKeyArgument, PCredHandle phCredential, PTimeStamp ptsExpiry)
Definition: wrapper.c:105
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
SECURITY_STATUS WINAPI FreeContextBuffer(PVOID pv)
Definition: sspi.c:699
#define TRUE
Definition: types.h:120
unsigned short * Password
Definition: rpcdce.h:227
ULONG ulVersion
Definition: sspi.h:181
const GLint * first
Definition: glext.h:5794
#define WARN(fmt,...)
Definition: debug.h:112
static UINT HTTP_DecodeBase64(LPCWSTR base64, LPSTR bin)
Definition: http.c:1524
char * host
Definition: whois.c:55
GLuint buffer
Definition: glext.h:5915
#define ISC_REQ_DELEGATE
Definition: sspi.h:362
#define lstrlenW
Definition: compat.h:609
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
Definition: cookie.c:41
static void cache_basic_authorization(LPWSTR host, LPWSTR realm, LPSTR auth_data, UINT auth_data_len)
Definition: http.c:814
#define SecInvalidateHandle(x)
Definition: sspi.h:58
static BOOL retrieve_cached_authorization(LPWSTR host, LPWSTR scheme, SEC_WINNT_AUTH_IDENTITY_W *nt_auth_identity)
Definition: http.c:854
#define CP_UTF8
Definition: nls.h:20
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
ULONG cbMaxToken
Definition: sspi.h:117
TimeStamp exp
Definition: http.c:81
static WCHAR * heap_strdupW(const WCHAR *str)
Definition: propsheet.c:178
#define debugstr_w
Definition: kernel32.h:32
LPWSTR scheme
Definition: http.c:78
static void cache_authorization(LPWSTR host, LPWSTR scheme, SEC_WINNT_AUTH_IDENTITY_W *nt_auth_identity)
Definition: http.c:891
#define SEC_I_CONTINUE_NEEDED
Definition: winerror.h:2927
LONG SECURITY_STATUS
Definition: sspi.h:34
static void destroy_authinfo(struct HttpAuthInfo *authinfo)
Definition: http.c:763
#define TRACE(s)
Definition: solgame.cpp:4
BOOL finished
Definition: http.c:86
SECURITY_STATUS WINAPI InitializeSecurityContextW(PCredHandle phCredential, PCtxtHandle phContext, SEC_WCHAR *pszTargetName, ULONG fContextReq, ULONG Reserved1, ULONG TargetDataRep, PSecBufferDesc pInput, ULONG Reserved2, PCtxtHandle phNewContext, PSecBufferDesc pOutput, ULONG *pfContextAttr, PTimeStamp ptsExpiry)
Definition: wrapper.c:301
_CONST_RETURN wchar_t *__cdecl wcschr(_In_z_ const wchar_t *_Str, wchar_t _Ch)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define SEC_WINNT_AUTH_IDENTITY_UNICODE
Definition: rpcdce.h:310
static FILE * out
Definition: regtests2xml.c:44
ULONG max_token
Definition: http.c:83
static UINT retrieve_cached_basic_authorization(http_request_t *req, const WCHAR *host, const WCHAR *realm, char **auth_data)
Definition: http.c:777
#define wcsnicmp
Definition: compat.h:14
static const WCHAR L[]
Definition: oid.c:1250
T1_FIELD_DICT_PRIVATE password
Definition: t1tokens.h:64
ULONG attr
Definition: http.c:82
#define SECBUFFER_TOKEN
Definition: sspi.h:161
#define ISC_REQ_USE_DCE_STYLE
Definition: sspi.h:371
#define SECURITY_NETWORK_DREP
Definition: sspi.h:474
void * auth_data
Definition: http.c:84
#define SEC_E_OK
Definition: winerror.h:2356
#define ISC_REQ_CONNECTION
Definition: sspi.h:373
#define ERR(fmt,...)
Definition: debug.h:110
GLuint in
Definition: glext.h:9616
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
DWORD exp
Definition: msg.c:16033
#define ISC_REQ_MUTUAL_AUTH
Definition: sspi.h:363
Definition: tftpd.h:85
CredHandle cred
Definition: http.c:79
unsigned int ULONG
Definition: retypes.h:1
WCHAR * LPWSTR
Definition: xmlstorage.h:184
ULONG cBuffers
Definition: sspi.h:182
#define memset(x, y, z)
Definition: compat.h:39
void user(int argc, const char *argv[])
Definition: cmds.c:1350
SECURITY_STATUS WINAPI QuerySecurityPackageInfoW(SEC_WCHAR *pszPackageName, PSecPkgInfoW *ppPackageInfo)
Definition: wrapper.c:750
static BOOL heap_free(void *mem)
Definition: appwiz.h:75

Referenced by HTTP_HttpSendRequestW().

◆ HTTP_DomainMatches()

static BOOL HTTP_DomainMatches ( LPCWSTR  server,
substr_t  domain 
)
static

Definition at line 1680 of file http.c.

1681 {
1682  const WCHAR *dot, *ptr;
1683  int len;
1684 
1685  if(domain.len == ARRAY_SIZE(L"<local>")-1 && !wcsnicmp(domain.str, L"<local>", domain.len) && !wcschr(server, '.' ))
1686  return TRUE;
1687 
1688  if(domain.len && *domain.str != '*')
1689  return domain.len == lstrlenW(server) && !wcsnicmp(server, domain.str, domain.len);
1690 
1691  if(domain.len < 2 || domain.str[1] != '.')
1692  return FALSE;
1693 
1694  /* For a hostname to match a wildcard, the last domain must match
1695  * the wildcard exactly. E.g. if the wildcard is *.a.b, and the
1696  * hostname is www.foo.a.b, it matches, but a.b does not.
1697  */
1698  dot = wcschr(server, '.');
1699  if(!dot)
1700  return FALSE;
1701 
1702  len = lstrlenW(dot + 1);
1703  if(len < domain.len - 2)
1704  return FALSE;
1705 
1706  /* The server's domain is longer than the wildcard, so it
1707  * could be a subdomain. Compare the last portion of the
1708  * server's domain.
1709  */
1710  ptr = dot + 1 + len - domain.len + 2;
1711  if(!wcsnicmp(ptr, domain.str+2, domain.len-2))
1712  /* This is only a match if the preceding character is
1713  * a '.', i.e. that it is a matching domain. E.g.
1714  * if domain is '*.b.c' and server is 'www.ab.c' they
1715  * do not match.
1716  */
1717  return *(ptr - 1) == '.';
1718 
1719  return len == domain.len-2 && !wcsnicmp(dot + 1, domain.str + 2, len);
1720 }
static rfbScreenInfoPtr server
Definition: vnc.c:74
#define TRUE
Definition: types.h:120
#define lstrlenW
Definition: compat.h:609
Definition: cookie.c:41
#define FALSE
Definition: types.h:117
static PVOID ptr
Definition: dispmode.c:27
_CONST_RETURN wchar_t *__cdecl wcschr(_In_z_ const wchar_t *_Str, wchar_t _Ch)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define wcsnicmp
Definition: compat.h:14
static const WCHAR L[]
Definition: oid.c:1250
GLenum GLsizei len
Definition: glext.h:6722
#define ARRAY_SIZE(a)
Definition: main.h:24

Referenced by HTTP_ShouldBypassProxy().

◆ HTTP_EncodeBase64()

static UINT HTTP_EncodeBase64 ( LPCSTR  bin,
unsigned int  len,
LPWSTR  base64 
)
static

Definition at line 1468 of file http.c.

1469 {
1470  UINT n = 0, x;
1471  static const CHAR HTTP_Base64Enc[] =
1472  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
1473 
1474  while( len > 0 )
1475  {
1476  /* first 6 bits, all from bin[0] */
1477  base64[n++] = HTTP_Base64Enc[(bin[0] & 0xfc) >> 2];
1478  x = (bin[0] & 3) << 4;
1479 
1480  /* next 6 bits, 2 from bin[0] and 4 from bin[1] */
1481  if( len == 1 )
1482  {
1483  base64[n++] = HTTP_Base64Enc[x];
1484  base64[n++] = '=';
1485  base64[n++] = '=';
1486  break;
1487  }
1488  base64[n++] = HTTP_Base64Enc[ x | ( (bin[1]&0xf0) >> 4 ) ];
1489  x = ( bin[1] & 0x0f ) << 2;
1490 
1491  /* next 6 bits 4 from bin[1] and 2 from bin[2] */
1492  if( len == 2 )
1493  {
1494  base64[n++] = HTTP_Base64Enc[x];
1495  base64[n++] = '=';
1496  break;
1497  }
1498  base64[n++] = HTTP_Base64Enc[ x | ( (bin[2]&0xc0 ) >> 6 ) ];
1499 
1500  /* last 6 bits, all from bin [2] */
1501  base64[n++] = HTTP_Base64Enc[ bin[2] & 0x3f ];
1502  bin += 3;
1503  len -= 3;
1504  }
1505  base64[n] = 0;
1506  return n;
1507 }
char CHAR
Definition: xmlstorage.h:175
GLdouble n
Definition: glext.h:7729
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLenum GLsizei len
Definition: glext.h:6722
unsigned int UINT
Definition: ndis.h:50
static struct _PeImage bin

Referenced by encode_auth_data().

◆ HTTP_FixURL()

static void HTTP_FixURL ( http_request_t request)
static

Definition at line 524 of file http.c.

525 {
526  /* If we don't have a path we set it to root */
527  if (NULL == request->path)
528  request->path = heap_strdupW(L"/");
529  else /* remove \r and \n*/
530  {
531  int nLen = lstrlenW(request->path);
532  while ((nLen >0 ) && ((request->path[nLen-1] == '\r')||(request->path[nLen-1] == '\n')))
533  {
534  nLen--;
535  request->path[nLen]='\0';
536  }
537  /* Replace '\' with '/' */
538  while (nLen>0) {
539  nLen--;
540  if (request->path[nLen] == '\\') request->path[nLen]='/';
541  }
542  }
543 
545  request->path, lstrlenW(request->path), L"http://", lstrlenW(L"http://") )
546  && request->path[0] != '/') /* not an absolute path ?? --> fix it !! */
547  {
548  WCHAR *fixurl = heap_alloc((lstrlenW(request->path) + 2)*sizeof(WCHAR));
549  *fixurl = '/';
550  lstrcpyW(fixurl + 1, request->path);
551  heap_free( request->path );
552  request->path = fixurl;
553  }
554 }
#define NORM_IGNORECASE
Definition: winnls.h:176
#define lstrlenW
Definition: compat.h:609
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
static WCHAR * heap_strdupW(const WCHAR *str)
Definition: propsheet.c:178
char path[256]
Definition: tftpd.h:94
INT WINAPI CompareStringW(LCID lcid, DWORD flags, LPCWSTR str1, INT len1, LPCWSTR str2, INT len2)
Definition: lang.c:2275
__wchar_t WCHAR
Definition: xmlstorage.h:180
static const WCHAR L[]
Definition: oid.c:1250
#define CSTR_EQUAL
Definition: winnls.h:456
#define LOCALE_INVARIANT
#define lstrcpyW
Definition: compat.h:608
#define NULL
Definition: types.h:112
Definition: tftpd.h:85
static BOOL heap_free(void *mem)
Definition: appwiz.h:75

Referenced by HTTP_HttpSendRequestW().

◆ HTTP_FreeTokens()

static void HTTP_FreeTokens ( LPWSTR token_array)
static

Definition at line 517 of file http.c.

518 {
519  int i;
520  for (i = 0; token_array[i]; i++) heap_free(token_array[i]);
521  heap_free(token_array);
522 }
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static BOOL heap_free(void *mem)
Definition: appwiz.h:75

Referenced by HTTP_GetResponseHeaders(), HTTP_HttpAddRequestHeadersW(), and HTTP_InterpretHttpHeader().

◆ HTTP_GetCustomHeaderIndex() [1/2]

◆ HTTP_GetCustomHeaderIndex() [2/2]

static INT HTTP_GetCustomHeaderIndex ( http_request_t request,
LPCWSTR  lpszField,
int  requested_index,
BOOL  request_only 
)
static

Definition at line 6252 of file http.c.

6254 {
6255  DWORD index;
6256 
6257  TRACE("%s, %d, %d\n", debugstr_w(lpszField), requested_index, request_only);
6258 
6259  for (index = 0; index < request->nCustHeaders; index++)
6260  {
6261  if (wcsicmp(request->custHeaders[index].lpszField, lpszField))
6262  continue;
6263 
6264  if (request_only && !(request->custHeaders[index].wFlags & HDR_ISREQUEST))
6265  continue;
6266 
6267  if (!request_only && (request->custHeaders[index].wFlags & HDR_ISREQUEST))
6268  continue;
6269 
6270  if (requested_index == 0)
6271  break;
6272  requested_index --;
6273  }
6274 
6275  if (index >= request->nCustHeaders)
6276  index = -1;
6277 
6278  TRACE("Return: %d\n", index);
6279  return index;
6280 }
#define HDR_ISREQUEST
Definition: internet.h:314
#define debugstr_w
Definition: kernel32.h:32
GLuint index
Definition: glext.h:6031
#define TRACE(s)
Definition: solgame.cpp:4
unsigned long DWORD
Definition: ntddk_ex.h:95
#define wcsicmp
Definition: compat.h:15
#define index(s, c)
Definition: various.h:29
Definition: tftpd.h:85

◆ HTTP_GetHeader()

static LPHTTPHEADERW HTTP_GetHeader ( http_request_t req,
LPCWSTR  head 
)
static

Definition at line 294 of file http.c.

295 {
296  int HeaderIndex = 0;
297  HeaderIndex = HTTP_GetCustomHeaderIndex(req, head, 0, TRUE);
298  if (HeaderIndex == -1)
299  return NULL;
300  else
301  return &req->custHeaders[HeaderIndex];
302 }
struct outqueuenode * head
Definition: adnsresfilter.c:66
#define TRUE
Definition: types.h:120
HTTPHEADERW * custHeaders
Definition: internet.h:363
static INT HTTP_GetCustomHeaderIndex(http_request_t *req, LPCWSTR lpszField, INT index, BOOL Request)
#define NULL
Definition: types.h:112

Referenced by get_host_header(), and HTTP_HttpSendRequestW().

◆ HTTP_GetResponseHeaders()

static DWORD HTTP_GetResponseHeaders ( http_request_t req,
INT len 
)
static

Definition at line 5932 of file http.c.

5933 {
5934  INT cbreaks = 0;
5936  DWORD buflen = MAX_REPLY_LEN;
5937  INT rc = 0;
5938  char bufferA[MAX_REPLY_LEN];
5939  LPWSTR status_code = NULL, status_text = NULL;
5941  BOOL codeHundred = FALSE;
5942 
5943  TRACE("-->\n");
5944 
5946  goto lend;
5947 
5948  /* clear old response headers (eg. from a redirect response) */
5950 
5952  do {
5953  /*
5954  * We should first receive 'HTTP/1.x nnn OK' where nnn is the status code.
5955  */
5956  buflen = MAX_REPLY_LEN;
5957  if ((res = read_line(request, bufferA, &buflen)))
5958  goto lend;
5959 
5960  if (!buflen) goto lend;
5961 
5962  rc += buflen;
5963  MultiByteToWideChar( CP_ACP, 0, bufferA, buflen, buffer, MAX_REPLY_LEN );
5964  /* check is this a status code line? */
5965  if (!wcsncmp(buffer, L"HTTP/1.0", 4))
5966  {
5967  /* split the version from the status code */
5968  status_code = wcschr( buffer, ' ' );
5969  if( !status_code )
5970  goto lend;
5971  *status_code++=0;
5972 
5973  /* split the status code from the status text */
5974  status_text = wcschr( status_code, ' ' );
5975  if( status_text )
5976  *status_text++=0;
5977 
5978  request->status_code = wcstol(status_code, NULL, 10);
5979 
5980  TRACE("version [%s] status code [%s] status text [%s]\n",
5981  debugstr_w(buffer), debugstr_w(status_code), debugstr_w(status_text) );
5982 
5983  codeHundred = request->status_code == HTTP_STATUS_CONTINUE;
5984  }
5985  else if (!codeHundred)
5986  {
5987  WARN("No status line at head of response (%s)\n", debugstr_w(buffer));
5988 
5990  heap_free(request->statusText);
5991 
5992  request->status_code = HTTP_STATUS_OK;
5993  request->version = heap_strdupW(L"HTTP/1.0");
5994  request->statusText = heap_strdupW(L"OK");
5995 
5996  goto lend;
5997  }
5998  } while (codeHundred);
5999 
6000  /* Add status code */
6003 
6005  heap_free(request->statusText);
6006 
6008  request->statusText = heap_strdupW(status_text ? status_text : L"");
6009 
6010  /* Restore the spaces */
6011  *(status_code-1) = ' ';
6012  if (status_text)
6013  *(status_text-1) = ' ';
6014 
6015  /* Parse each response line */
6016  do
6017  {
6018  buflen = MAX_REPLY_LEN;
6019  if (!read_line(request, bufferA, &buflen) && buflen)
6020  {
6021  LPWSTR * pFieldAndValue;
6022 
6023  TRACE("got line %s, now interpreting\n", debugstr_a(bufferA));
6024 
6025  if (!bufferA[0]) break;
6026  MultiByteToWideChar( CP_ACP, 0, bufferA, buflen, buffer, MAX_REPLY_LEN );
6027 
6028  pFieldAndValue = HTTP_InterpretHttpHeader(buffer);
6029  if (pFieldAndValue)
6030  {
6031  HTTP_ProcessHeader(request, pFieldAndValue[0], pFieldAndValue[1],
6033  HTTP_FreeTokens(pFieldAndValue);
6034  }
6035  }
6036  else
6037  {
6038  cbreaks++;
6039  if (cbreaks >= 2)
6040  break;
6041  }
6042  }while(1);
6043 
6044  res = ERROR_SUCCESS;
6045 
6046 lend:
6047 
6048  *len = rc;
6049  TRACE("<--\n");
6050  return res;
6051 }
int receive_timeout
#define HTTP_ADDHDR_FLAG_REPLACE
Definition: http.c:71
#define ERROR_SUCCESS
Definition: deptool.c:10
#define CP_ACP
Definition: compat.h:109
#define WARN(fmt,...)
Definition: debug.h:112
static void HTTP_clear_response_headers(http_request_t *request)
Definition: http.c:5901
WCHAR * version
GLuint buffer
Definition: glext.h:5915
_Check_return_ long __cdecl wcstol(_In_z_ const wchar_t *_Str, _Out_opt_ _Deref_post_z_ wchar_t **_EndPtr, _In_ int _Radix)
int32_t INT
Definition: typedefs.h:58
#define ERROR_HTTP_INVALID_SERVER_RESPONSE
Definition: wininet.h:2060
#define MAX_REPLY_LEN
Definition: request.c:2568
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
static WCHAR * heap_strdupW(const WCHAR *str)
Definition: propsheet.c:178
#define debugstr_w
Definition: kernel32.h:32
#define HTTP_ADDREQ_FLAG_ADD
Definition: wininet.h:1707
static DWORD HTTP_ProcessHeader(http_request_t *req, LPCWSTR field, LPCWSTR value, DWORD dwModifier)
Definition: http.c:6117
static DWORD read_line(http_request_t *req, LPSTR buffer, DWORD *len)
Definition: http.c:2575
DWORD NETCON_set_timeout(netconn_t *connection, BOOL send, DWORD value) DECLSPEC_HIDDEN
#define TRACE(s)
Definition: solgame.cpp:4
_CONST_RETURN wchar_t *__cdecl wcschr(_In_z_ const wchar_t *_Str, wchar_t _Ch)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define debugstr_a
Definition: kernel32.h:31
unsigned long DWORD
Definition: ntddk_ex.h:95
#define HTTP_STATUS_OK
Definition: winhttp.h:240
static LPWSTR * HTTP_InterpretHttpHeader(LPCWSTR buffer)
Definition: http.c:6063
_Check_return_ _CRTIMP int __cdecl wcsncmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
static const WCHAR L[]
Definition: oid.c:1250
GLenum GLsizei len
Definition: glext.h:6722
BOOL is_valid_netconn(netconn_t *) DECLSPEC_HIDDEN
struct netconn * netconn
#define NULL
Definition: types.h:112
#define MultiByteToWideChar
Definition: compat.h:110
Definition: tftpd.h:85
static void HTTP_FreeTokens(LPWSTR *token_array)
Definition: http.c:517
#define HTTP_STATUS_CONTINUE
Definition: winhttp.h:238
#define HTTP_ADDHDR_FLAG_ADD
Definition: http.c:67
GLuint res
Definition: glext.h:9613
WCHAR * LPWSTR
Definition: xmlstorage.h:184
static BOOL heap_free(void *mem)
Definition: appwiz.h:75

Referenced by HTTP_HttpEndRequestW(), and HTTP_HttpSendRequestW().

◆ HTTP_HandleRedirect()

static DWORD HTTP_HandleRedirect ( http_request_t request,
WCHAR url 
)
static

Definition at line 4143 of file http.c.

4144 {
4145  URL_COMPONENTSW urlComponents = { sizeof(urlComponents) };
4146  http_session_t *session = request->session;
4147  size_t url_len = lstrlenW(url);
4148 
4149  if(url[0] == '/')
4150  {
4151  /* if it's an absolute path, keep the same session info */
4152  urlComponents.lpszUrlPath = url;
4153  urlComponents.dwUrlPathLength = url_len;
4154  }
4155  else
4156  {
4157  urlComponents.dwHostNameLength = 1;
4158  urlComponents.dwUserNameLength = 1;
4159  urlComponents.dwUrlPathLength = 1;
4160  if(!InternetCrackUrlW(url, url_len, 0, &urlComponents))
4161  return INTERNET_GetLastError();
4162 
4163  if(!urlComponents.dwHostNameLength)
4165  }
4166 
4168  url, (url_len + 1) * sizeof(WCHAR));
4169 
4170  if(urlComponents.dwHostNameLength) {
4171  BOOL custom_port = FALSE;
4172  substr_t host;
4173 
4174  if(urlComponents.nScheme == INTERNET_SCHEME_HTTP) {
4175  if(request->hdr.dwFlags & INTERNET_FLAG_SECURE) {
4176  TRACE("redirect from secure page to non-secure page\n");
4177  /* FIXME: warn about from secure redirect to non-secure page */
4178  request->hdr.dwFlags &= ~INTERNET_FLAG_SECURE;
4179  }
4180 
4181  custom_port = urlComponents.nPort != INTERNET_DEFAULT_HTTP_PORT;
4182  }else if(urlComponents.nScheme == INTERNET_SCHEME_HTTPS) {
4183  if(!(request->hdr.dwFlags & INTERNET_FLAG_SECURE)) {
4184  TRACE("redirect from non-secure page to secure page\n");
4185  /* FIXME: notify about redirect to secure page */
4186  request->hdr.dwFlags |= INTERNET_FLAG_SECURE;
4187  }
4188 
4189  custom_port = urlComponents.nPort != INTERNET_DEFAULT_HTTPS_PORT;
4190  }
4191 
4192  heap_free(session->hostName);
4193 
4194  session->hostName = heap_strndupW(urlComponents.lpszHostName, urlComponents.dwHostNameLength);
4195  session->hostPort = urlComponents.nPort;
4196 
4197  heap_free(session->userName);
4198  session->userName = NULL;
4199  if (urlComponents.dwUserNameLength)
4200  session->userName = heap_strndupW(urlComponents.lpszUserName, urlComponents.dwUserNameLength);
4201 
4203 
4204  host = substr(urlComponents.lpszHostName, urlComponents.dwHostNameLength);
4205 
4206  if(host.len != lstrlenW(request->server->name) || wcsnicmp(request->server->name, host.str, host.len)
4207  || request->server->port != urlComponents.nPort) {
4208  server_t *new_server;
4209 
4210  new_server = get_server(host, urlComponents.nPort, urlComponents.nScheme == INTERNET_SCHEME_HTTPS, TRUE);
4211  server_release(request->server);
4212  request->server = new_server;
4213  }
4214 
4215  if (custom_port)
4216  HTTP_ProcessHeader(request, L"Host", request->server->host_port,
4218  else
4219  HTTP_ProcessHeader(request, L"Host", request->server->name,
4221  }
4222 
4224  request->path = NULL;
4225  if(urlComponents.dwUrlPathLength)
4226  {
4227  DWORD needed = 1;
4228  HRESULT rc;
4229  WCHAR dummy[] = L"";
4230  WCHAR *path;
4231 
4232  path = heap_strndupW(urlComponents.lpszUrlPath, urlComponents.dwUrlPathLength);
4233  rc = UrlEscapeW(path, dummy, &needed, URL_ESCAPE_SPACES_ONLY);
4234  if (rc != E_POINTER)
4235  ERR("Unable to escape string!(%s) (%d)\n",debugstr_w(path),rc);
4236  request->path = heap_alloc(needed*sizeof(WCHAR));
4237  rc = UrlEscapeW(path, request->path, &needed,
4239  if (rc != S_OK)
4240  {
4241  ERR("Unable to escape string!(%s) (%d)\n",debugstr_w(path),rc);
4243  }
4244  heap_free(path);
4245  }
4246 
4247  /* Remove custom content-type/length headers on redirects. */
4248  remove_header(request, L"Content-Type", TRUE);
4249  remove_header(request, L"Content-Length", TRUE);