25 RCSID(
"$Id: b55850d4b1ea96d0bbdab66dc874024e0aafd78e $")
27 #include <freeradius-devel/util/debug.h>
28 #include <freeradius-devel/server/request_data.h>
131 DEBUG4(
"%s - freed with opaque data", desc);
139 DEBUG4(
"%s - freed, but leaving opaque data", desc);
184 bool free_on_replace,
bool free_on_parent,
bool persist,
198 fr_assert(!persist || request->session_state_ctx);
200 (talloc_parent(opaque) == request->session_state_ctx) ||
202 fr_assert(!free_on_parent || (talloc_parent(opaque) != request));
204 #ifndef TALLOC_GET_TYPE_ABORT_NOOP
205 if (
type) opaque = _talloc_get_type_abort(opaque,
type, __location__);
218 RDEBUG4(
"%s: Freeing %s%s%p at %p:%i via replacement",
269 RDEBUG4(
"%s: %s%s%p at %p:%i, free_on_replace: %s, free_on_parent: %s, persist: %s",
273 free_on_replace ?
"yes" :
"no",
274 free_on_parent ?
"yes" :
"no",
275 persist ?
"yes" :
"no");
296 if (!request)
return NULL;
308 #ifndef TALLOC_GET_TYPE_ABORT_NOOP
309 if (rd->
type) ptr = _talloc_get_type_abort(ptr, rd->
type, __location__);
312 RDEBUG4(
"%s: %s%s%p at %p:%i retrieved and unlinked",
322 RDEBUG4(
"%s: No request data found at %p:%i", __FUNCTION__, unique_ptr, unique_int);
343 if (!request)
return NULL;
348 #ifndef TALLOC_GET_TYPE_ABORT_NOOP
352 RDEBUG4(
"%s: %s%s%p at %p:%i retrieved",
360 RDEBUG4(
"%s: No request data found at %p:%i", __FUNCTION__, unique_ptr, unique_int);
378 if (rd->
persist != persist)
continue;
406 if (rd->
persist != persist)
continue;
411 memcpy(
new, rd,
sizeof(*
new));
416 memset(&new->list, 0,
sizeof(new->list));
445 if (rd->
persist != persist)
continue;
502 #ifdef WITH_VERIFY_PTR
static void * fr_dlist_next(fr_dlist_head_t const *list_head, void const *ptr)
Get the next item in a list.
static void fr_dlist_talloc_free(fr_dlist_head_t *head)
Free all items in a doubly linked list (with talloc)
static void fr_dlist_entry_unlink(fr_dlist_t *entry)
Remove an item from the dlist when we don't have access to the head.
static bool fr_dlist_empty(fr_dlist_head_t const *list_head)
Check whether a list has any items.
static int fr_dlist_insert_tail(fr_dlist_head_t *list_head, void *ptr)
Insert an item into the tail of a list.
static int fr_dlist_move(fr_dlist_head_t *list_dst, fr_dlist_head_t *list_src)
Merge two lists, inserting the source at the tail of the destination.
static void * fr_dlist_remove(fr_dlist_head_t *list_head, void *ptr)
Remove an item from the list.
#define fr_dlist_talloc_init(_head, _type, _field)
Initialise the head structure of a doubly linked list.
static int fr_dlist_insert_head(fr_dlist_head_t *list_head, void *ptr)
Insert an item into the head of a list.
Head of a doubly linked list.
Entry in a doubly linked list.
#define ROPTIONAL(_l_request, _l_global, _fmt,...)
Use different logging functions depending on whether request is NULL or not.
#define DEBUG_ENABLED4
True if global debug level 1-3 messages are enabled.
bool free_on_replace
Whether to talloc_free(opaque) when the request data is removed.
char const * file
File where this request data was added.
int request_data_by_persistance_count(request_t *request, bool persist)
Return how many request data entries exist of a given persistence.
int request_data_by_persistance(fr_dlist_head_t *out, request_t *request, bool persist)
Loop over all the request data, pulling out ones matching persist state.
fr_dlist_t list
Next opaque request data struct linked to this request.
void * request_data_get(request_t *request, void const *unique_ptr, int unique_int)
Get opaque data from a request.
int _request_data_add(request_t *request, void const *unique_ptr, int unique_int, char const *type, void *opaque, bool free_on_replace, bool free_on_parent, bool persist, char const *file, int line)
Add opaque data to a request_t.
static char * request_data_description(TALLOC_CTX *ctx, request_data_t *rd)
void * opaque
Opaque data.
void * request_data_reference(request_t *request, void const *unique_ptr, int unique_int)
Get opaque data from a request without removing it.
static int _request_data_free(request_data_t *rd)
Ensure opaque data is freed by binding its lifetime to the request_data_t.
void request_data_list_init(fr_dlist_head_t *data)
void const * unique_ptr
Key to lookup request data.
bool persist
Whether this data should be transferred to a session_entry_t after we're done processing this request...
void request_data_restore(request_t *request, fr_dlist_head_t *in)
Add request data back to a request.
static request_data_t * request_data_alloc(TALLOC_CTX *ctx)
Allocate request data.
char const * type
Opaque type e.g. fr_pair_t, fr_dict_attr_t etc...
void request_data_dump(request_t *request)
int line
Line where this request data was added.
bool free_on_parent
Whether to talloc_free(opaque) when the request is freed.
void request_data_persistable_free(request_t *request)
Used for removing data from subrequests that are about to be freed.
int request_data_by_persistance_reparent(TALLOC_CTX *ctx, fr_dlist_head_t *out, request_t *request, bool persist)
Loop over all the request data, copying, then freeing ones matching persist state.
void request_data_list_dump(request_t *request, fr_dlist_head_t *head)
int unique_int
Alternative key to lookup request data.
Per-request opaque data, added by modules.
MEM(pair_append_request(&vp, attr_eap_aka_sim_identity) >=0)
fr_aka_sim_id_type_t type
void * talloc_null_ctx(void)
Retrieve the current talloc NULL ctx.
char * talloc_typed_asprintf(TALLOC_CTX *ctx, char const *fmt,...)
Call talloc vasprintf, setting the type on the new chunk correctly.
static size_t char ** out