ReactOS  0.4.14-dev-115-g4576127
handle.c File Reference
#include "config.h"
#include "wine/port.h"
#include "wine/debug.h"
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "winhttp.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)
 
object_header_taddref_object (object_header_t *hdr)
 
object_header_tgrab_object (HINTERNET hinternet)
 
void release_object (object_header_t *hdr)
 
HINTERNET alloc_handle (object_header_t *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 object_header_t ** 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 35 of file handle.c.

Function Documentation

◆ addref_object()

object_header_t* addref_object ( object_header_t hdr)

Definition at line 50 of file handle.c.

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

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

◆ alloc_handle()

HINTERNET alloc_handle ( object_header_t hdr)

Definition at line 89 of file handle.c.

90 {
93 
94  list_init( &hdr->children );
95  hdr->handle = NULL;
96 
98  if (!max_handles)
99  {
101  if (!(p = heap_alloc_zero( sizeof(ULONG_PTR) * num ))) goto end;
102  handles = p;
103  max_handles = num;
104  }
105  if (max_handles == next_handle)
106  {
107  num = max_handles * 2;
108  if (!(p = heap_realloc_zero( handles, sizeof(ULONG_PTR) * num ))) goto end;
109  handles = p;
110  max_handles = num;
111  }
113  if (handles[handle]) ERR("handle isn't free but should be\n");
114 
116  hdr->handle = (HINTERNET)(handle + 1);
118 
119 end:
121  return hdr->handle;
122 }
LPVOID HINTERNET
Definition: winhttp.h:32
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:82
char hdr[14]
Definition: iptest.cpp:33
GLuint GLuint end
Definition: gl.h:1545
#define HANDLE_CHUNK_SIZE
Definition: handle.c:35
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
uint32_t ULONG_PTR
Definition: typedefs.h:63
smooth NULL
Definition: ftsmooth.c:416
static ULONG_PTR next_handle
Definition: handle.c:47
static object_header_t ** handles
Definition: handle.c:46
GLuint GLuint num
Definition: glext.h:9618
#define ERR(fmt,...)
Definition: debug.h:109
static ULONG_PTR max_handles
Definition: handle.c:48
object_header_t * addref_object(object_header_t *hdr)
Definition: handle.c:50
__WINE_SERVER_LIST_INLINE void list_init(struct list *list)
Definition: list.h:149
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
GLfloat GLfloat p
Definition: glext.h:8902
static CRITICAL_SECTION handle_cs
Definition: handle.c:37

◆ free_handle()

BOOL free_handle ( HINTERNET  hinternet)

Definition at line 124 of file handle.c.

125 {
126  BOOL ret = FALSE;
127  ULONG_PTR handle = (ULONG_PTR)hinternet;
129 
131 
132  if ((handle > 0) && (handle <= max_handles))
133  {
134  handle--;
135  if (handles[handle])
136  {
137  hdr = handles[handle];
138  TRACE("destroying handle 0x%lx for object %p\n", handle + 1, hdr);
139  handles[handle] = NULL;
140  ret = TRUE;
141  }
142  }
143 
145 
146  if (hdr)
147  {
149  {
150  TRACE("freeing child handle %p for parent handle 0x%lx\n", child->handle, handle + 1);
151  free_handle( child->handle );
152  }
153  release_object( hdr );
154  }
155 
159 
160  return ret;
161 }
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:82
#define TRUE
Definition: types.h:120
char hdr[14]
Definition: iptest.cpp:33
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
static HWND child
Definition: cursoricon.c:298
uint32_t ULONG_PTR
Definition: typedefs.h:63
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
static ULONG_PTR next_handle
Definition: handle.c:47
static object_header_t ** handles
Definition: handle.c:46
int ret
uint32_t entry
Definition: isohybrid.c:63
BOOL free_handle(HINTERNET hinternet)
Definition: handle.c:124
void release_object(object_header_t *hdr)
Definition: handle.c:73
static unsigned __int64 next
Definition: rand_nt.c:6
#define LIST_FOR_EACH_ENTRY_SAFE(cursor, cursor2, list, type, field)
Definition: list.h:204
static ULONG_PTR max_handles
Definition: handle.c:48
#define ULONG_PTR
Definition: config.h:101
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
static CRITICAL_SECTION handle_cs
Definition: handle.c:37

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

◆ grab_object()

object_header_t* grab_object ( HINTERNET  hinternet)

Definition at line 57 of file handle.c.

58 {
60  ULONG_PTR handle = (ULONG_PTR)hinternet;
61 
63 
64  if ((handle > 0) && (handle <= max_handles) && handles[handle - 1])
65  hdr = addref_object( handles[handle - 1] );
66 
68 
69  TRACE("handle 0x%lx -> %p\n", handle, hdr);
70  return hdr;
71 }
char hdr[14]
Definition: iptest.cpp:33
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
uint32_t ULONG_PTR
Definition: typedefs.h:63
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
static object_header_t ** handles
Definition: handle.c:46
static ULONG_PTR max_handles
Definition: handle.c:48
object_header_t * addref_object(object_header_t *hdr)
Definition: handle.c:50
#define ULONG_PTR
Definition: config.h:101
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
static CRITICAL_SECTION handle_cs
Definition: handle.c:37

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

◆ release_object()

void release_object ( object_header_t hdr)

Definition at line 73 of file handle.c.

74 {
75  ULONG refs = InterlockedDecrement( &hdr->refs );
76  TRACE("object %p refcount = %d\n", hdr, refs);
77  if (!refs)
78  {
80 
82 
83  TRACE("destroying object %p\n", hdr);
84  if (hdr->type != WINHTTP_HANDLE_TYPE_SESSION) list_remove( &hdr->entry );
85  hdr->vtbl->destroy( hdr );
86  }
87 }
#define WINHTTP_HANDLE_TYPE_REQUEST
Definition: winhttp.h:432
char hdr[14]
Definition: iptest.cpp:33
void send_callback(object_header_t *hdr, DWORD status, LPVOID info, DWORD buflen)
Definition: session.c:71
#define WINHTTP_HANDLE_TYPE_SESSION
Definition: winhttp.h:430
__WINE_SERVER_LIST_INLINE void list_remove(struct list *elem)
Definition: list.h:108
#define TRACE(s)
Definition: solgame.cpp:4
#define WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING
Definition: winhttp.h:391
#define InterlockedDecrement
Definition: armddk.h:52
void close_connection(request_t *request)
Definition: request.c:1803
unsigned int ULONG
Definition: retypes.h:1

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 37 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") }
}
LIST_ENTRY ProcessLocksList
Definition: winbase.h:855
static CRITICAL_SECTION_DEBUG handle_cs_debug
Definition: handle.c:38
#define ULONG_PTR
Definition: config.h:101
static CRITICAL_SECTION handle_cs
Definition: handle.c:37

Definition at line 38 of file handle.c.

◆ handles

◆ max_handles

ULONG_PTR max_handles
static

Definition at line 48 of file handle.c.

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

◆ next_handle

ULONG_PTR next_handle
static

Definition at line 47 of file handle.c.

Referenced by alloc_handle(), and free_handle().