ReactOS 0.4.15-dev-7897-g78dc504
handle.c File Reference
#include "config.h"
#include "ws2tcpip.h"
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "winhttp.h"
#include "wine/debug.h"
#include "winhttp_private.h"
Include dependency graph for handle.c:

Go to the source code of this file.

Macros

#define HANDLE_CHUNK_SIZE   0x10
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (winhttp)
 
struct object_headeraddref_object (struct object_header *hdr)
 
struct object_headergrab_object (HINTERNET hinternet)
 
void release_object (struct object_header *hdr)
 
HINTERNET alloc_handle (struct object_header *hdr)
 
BOOL free_handle (HINTERNET hinternet)
 

Variables

static CRITICAL_SECTION handle_cs = { &handle_cs_debug, -1, 0, 0, 0, 0 }
 
static CRITICAL_SECTION_DEBUG handle_cs_debug
 
static struct object_header ** handles
 
static ULONG_PTR next_handle
 
static ULONG_PTR max_handles
 

Macro Definition Documentation

◆ HANDLE_CHUNK_SIZE

#define HANDLE_CHUNK_SIZE   0x10

Definition at line 34 of file handle.c.

Function Documentation

◆ addref_object()

struct object_header * addref_object ( struct object_header hdr)

Definition at line 49 of file handle.c.

50{
51 ULONG refs = InterlockedIncrement( &hdr->refs );
52 TRACE("%p -> refcount = %d\n", hdr, refs);
53 return hdr;
54}
#define InterlockedIncrement
Definition: armddk.h:53
char hdr[14]
Definition: iptest.cpp:33
#define TRACE(s)
Definition: solgame.cpp:4
uint32_t ULONG
Definition: typedefs.h:59

Referenced by alloc_handle(), grab_object(), WinHttpConnect(), WinHttpOpenRequest(), WinHttpQueryDataAvailable(), WinHttpReadData(), WinHttpReceiveResponse(), WinHttpSendRequest(), and WinHttpWriteData().

◆ alloc_handle()

HINTERNET alloc_handle ( struct object_header hdr)

Definition at line 88 of file handle.c.

89{
90 struct object_header **p;
92
93 list_init( &hdr->children );
94 hdr->handle = NULL;
95
97 if (!max_handles)
98 {
100 if (!(p = heap_alloc_zero( sizeof(ULONG_PTR) * num ))) goto end;
101 handles = p;
103 }
105 {
106 num = max_handles * 2;
107 if (!(p = heap_realloc_zero( handles, sizeof(ULONG_PTR) * num ))) goto end;
108 handles = p;
110 }
112 if (handles[handle]) ERR("handle isn't free but should be\n");
113
115 hdr->handle = (HINTERNET)(handle + 1);
117
118end:
120 return hdr->handle;
121}
static void list_init(struct list_entry *head)
Definition: list.h:51
#define ERR(fmt,...)
Definition: debug.h:110
#define NULL
Definition: types.h:112
static CRITICAL_SECTION handle_cs
Definition: handle.c:36
#define HANDLE_CHUNK_SIZE
Definition: handle.c:34
static struct object_header ** handles
Definition: handle.c:45
static ULONG_PTR max_handles
Definition: handle.c:47
struct object_header * addref_object(struct object_header *hdr)
Definition: handle.c:49
static ULONG_PTR next_handle
Definition: handle.c:46
GLuint GLuint end
Definition: gl.h:1545
GLfloat GLfloat p
Definition: glext.h:8902
GLuint GLuint num
Definition: glext.h:9618
HINTERNET handle
uint32_t ULONG_PTR
Definition: typedefs.h:65
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
LPVOID HINTERNET
Definition: winhttp.h:32

◆ free_handle()

BOOL free_handle ( HINTERNET  hinternet)

Definition at line 123 of file handle.c.

124{
125 BOOL ret = FALSE;
126 ULONG_PTR handle = (ULONG_PTR)hinternet;
127 struct object_header *hdr = NULL, *child, *next;
128
130
131 if ((handle > 0) && (handle <= max_handles))
132 {
133 handle--;
134 if (handles[handle])
135 {
136 hdr = handles[handle];
137 TRACE("destroying handle 0x%lx for object %p\n", handle + 1, hdr);
139 ret = TRUE;
140 }
141 }
142
144
145 if (hdr)
146 {
148 {
149 TRACE("freeing child handle %p for parent handle 0x%lx\n", child->handle, handle + 1);
150 free_handle( child->handle );
151 }
153 }
154
158
159 return ret;
160}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
BOOL free_handle(HINTERNET hinternet)
Definition: handle.c:123
void release_object(struct object_header *hdr)
Definition: handle.c:72
#define ULONG_PTR
Definition: config.h:101
unsigned int BOOL
Definition: ntddk_ex.h:94
uint32_t entry
Definition: isohybrid.c:63
static HWND child
Definition: cursoricon.c:298
static unsigned __int64 next
Definition: rand_nt.c:6
#define LIST_FOR_EACH_ENTRY_SAFE(cursor, cursor2, list, type, field)
Definition: list.h:204
int ret

Referenced by free_handle(), pqInsert(), and WinHttpCloseHandle().

◆ grab_object()

◆ release_object()

void release_object ( struct object_header hdr)

Definition at line 72 of file handle.c.

73{
74 ULONG refs = InterlockedDecrement( &hdr->refs );
75 TRACE("object %p refcount = %d\n", hdr, refs);
76 if (!refs)
77 {
79
81
82 TRACE("destroying object %p\n", hdr);
83 if (hdr->type != WINHTTP_HANDLE_TYPE_SESSION) list_remove( &hdr->entry );
84 hdr->vtbl->destroy( hdr );
85 }
86}
#define InterlockedDecrement
Definition: armddk.h:52
static void list_remove(struct list_entry *entry)
Definition: list.h:90
void send_callback(struct object_header *hdr, DWORD status, void *info, DWORD buflen)
Definition: session.c:55
static void close_connection(void)
Definition: http.c:5576
Definition: tftpd.h:86
#define WINHTTP_HANDLE_TYPE_REQUEST
Definition: winhttp.h:432
#define WINHTTP_HANDLE_TYPE_SESSION
Definition: winhttp.h:430
#define WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING
Definition: winhttp.h:391

Referenced by connect_destroy(), free_handle(), request_destroy(), task_proc(), WinHttpAddRequestHeaders(), WinHttpCloseHandle(), WinHttpConnect(), WinHttpGetProxyForUrl(), WinHttpOpen(), WinHttpOpenRequest(), WinHttpQueryAuthSchemes(), WinHttpQueryDataAvailable(), WinHttpQueryHeaders(), WinHttpQueryOption(), WinHttpReadData(), WinHttpReceiveResponse(), WinHttpSendRequest(), WinHttpSetCredentials(), WinHttpSetOption(), WinHttpSetStatusCallback(), WinHttpSetTimeouts(), and WinHttpWriteData().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( winhttp  )

Variable Documentation

◆ handle_cs

static CRITICAL_SECTION handle_cs = { &handle_cs_debug, -1, 0, 0, 0, 0 }
static

Definition at line 36 of file handle.c.

Referenced by alloc_handle(), free_handle(), and grab_object().

◆ handle_cs_debug

CRITICAL_SECTION_DEBUG handle_cs_debug
static
Initial value:
=
{
0, 0, &handle_cs,
0, 0, { (ULONG_PTR)(__FILE__ ": handle_cs") }
}
static CRITICAL_SECTION_DEBUG handle_cs_debug
Definition: handle.c:37
LIST_ENTRY ProcessLocksList
Definition: winbase.h:883

Definition at line 37 of file handle.c.

◆ handles

struct object_header** handles
static

Definition at line 45 of file handle.c.

Referenced by alloc_handle(), free_handle(), and grab_object().

◆ max_handles

ULONG_PTR max_handles
static

Definition at line 47 of file handle.c.

Referenced by alloc_handle(), free_handle(), and grab_object().

◆ next_handle

ULONG_PTR next_handle
static

Definition at line 46 of file handle.c.

Referenced by alloc_handle(), and free_handle().