From 45243dd2f2be49cd91be1dc28932e6c9040db6a1 Mon Sep 17 00:00:00 2001 From: Kozlov Dmitry Date: Mon, 6 Sep 2010 18:27:02 +0400 Subject: working on radius module --- accel-pptpd/triton/CMakeLists.txt | 1 + accel-pptpd/triton/event.c | 103 ++++++++++++++++++++++++++++++++++++++ accel-pptpd/triton/triton.h | 4 ++ accel-pptpd/triton/triton_p.h | 9 +++- 4 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 accel-pptpd/triton/event.c (limited to 'accel-pptpd/triton') diff --git a/accel-pptpd/triton/CMakeLists.txt b/accel-pptpd/triton/CMakeLists.txt index fd6b5182..41339d97 100644 --- a/accel-pptpd/triton/CMakeLists.txt +++ b/accel-pptpd/triton/CMakeLists.txt @@ -7,6 +7,7 @@ SET(sources_c loader.c log.c mempool.c + event.c ) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) ADD_DEFINITIONS("-DUSE_SPINLOCK") diff --git a/accel-pptpd/triton/event.c b/accel-pptpd/triton/event.c new file mode 100644 index 00000000..17483ec7 --- /dev/null +++ b/accel-pptpd/triton/event.c @@ -0,0 +1,103 @@ +#include +#include +#include + +#include "triton_p.h" + +static int max_events = 1024; +static struct _triton_event_t **events; + +struct event_handler_t +{ + struct list_head entry; + triton_event_func func; +}; + +int event_init(void) +{ + events = malloc(max_events * sizeof(void *)); + if (!events) { + fprintf(stderr,"event:cann't allocate memory\n"); + return -1; + } + + memset(events, 0, max_events * sizeof(void *)); + + return 0; +} + +int triton_event_register_handler(int ev_id, triton_event_func func) +{ + struct _triton_event_t *ev; + struct event_handler_t *h; + + if (ev_id >= max_events) + return -1; + + ev = events[ev_id]; + if (!ev) { + ev = malloc(sizeof(*ev)); + if (!ev) { + triton_log_error("event: out of memory\n"); + return -1; + } + INIT_LIST_HEAD(&ev->handlers); + events[ev_id] = ev; + } + + h = malloc(sizeof(*h)); + if (!h) { + triton_log_error("event: out of memory\n"); + return -1; + } + + h->func = func; + list_add_tail(&h->entry, &ev->handlers); + + return 0; +} + +/*int triton_event_unregister_handler(int ev_id, triton_event_func func) +{ + struct _triton_event_t *ev; + struct event_handler_t *h; + + if (ev_id >= max_events) + return -1; + + ev = events[ev_id]; + if (!ev) { + return -1; + } + + list_for_each_entry(h, &ev->handlers, entry) { + if (h->func == func) { + if (ev->in_progress) + h->func = NULL; + else { + list_del(&h->entry); + free(h); + } + return 0; + } + } + + return -1; +}*/ + +void triton_event_fire(int ev_id, void *arg) +{ + struct _triton_event_t *ev; + struct event_handler_t *h; + + if (ev_id >= max_events) + return; + + ev = events[ev_id]; + if (!ev) + return; + + list_for_each_entry(h, &ev->handlers, entry) + h->func(arg); +} + diff --git a/accel-pptpd/triton/triton.h b/accel-pptpd/triton/triton.h index 1009d67a..d130d86e 100644 --- a/accel-pptpd/triton/triton.h +++ b/accel-pptpd/triton/triton.h @@ -55,6 +55,10 @@ int triton_timer_add(struct triton_ctx_t *ctx, struct triton_timer_t*,int abs_ti int triton_timer_mod(struct triton_timer_t *,int abs_time); void triton_timer_del(struct triton_timer_t *); +typedef void (*triton_event_func)(void *); +int triton_event_register_handler(int ev_id, triton_event_func func); +void triton_event_fire(int ev_id, void *arg); + struct conf_sect_t *conf_get_section(const char *name); char *conf_get_opt(const char *sect, const char *name); diff --git a/accel-pptpd/triton/triton_p.h b/accel-pptpd/triton/triton_p.h index 0f7e7160..c31efd6e 100644 --- a/accel-pptpd/triton/triton_p.h +++ b/accel-pptpd/triton/triton_p.h @@ -57,6 +57,11 @@ struct _triton_timer_t struct triton_timer_t *ud; }; +struct _triton_event_t +{ + struct list_head handlers; +}; + typedef void * mempool_t; mempool_t *mempool_create(int size); void *mempool_alloc(mempool_t*); @@ -64,9 +69,11 @@ void mempool_free(void*); int log_init(void); int md_init(); +int timer_init(); +int event_init(); + void md_run(); void md_terminate(); -int timer_init(); void timer_run(); void timer_terminate(); struct triton_ctx_t *default_ctx; -- cgit v1.2.3