Mercurial > hg > waaad
view extensions/radius_gw/rg_utils.c @ 406:3a8e91184d4d
Added code to handle RADIUS client deconnection
author | Sebastien Decugis <sdecugis@nict.go.jp> |
---|---|
date | Wed, 10 Jun 2009 15:33:26 +0900 |
parents | 03b512313cc1 |
children |
line wrap: on
line source
/********************************************************************************************************* * Software License Agreement (BSD License) * * Author: Sebastien Decugis <sdecugis@nict.go.jp> * * * * Copyright (c) 2009, WIDE Project and NICT * * All rights reserved. * * * * Redistribution and use of this software in source and binary forms, with or without modification, are * * permitted provided that the following conditions are met: * * * * * Redistributions of source code must retain the above * * copyright notice, this list of conditions and the * * following disclaimer. * * * * * Redistributions in binary form must reproduce the above * * copyright notice, this list of conditions and the * * following disclaimer in the documentation and/or other * * materials provided with the distribution. * * * * * Neither the name of the WIDE Project or NICT nor the * * names of its contributors may be used to endorse or * * promote products derived from this software without * * specific prior written permission of WIDE Project and * * NICT. * * * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * *********************************************************************************************************/ #include "rg_common.h" /************ Lists ***********/ void rg_list_init(struct rg_list * plist) { ASSERT(plist != NULL); plist->next = plist; plist->prev = plist; plist->head = plist; } int rg_list_is_empty(struct rg_list * plist) { ASSERT(plist != NULL); return plist == plist->next; } void rg_list_insert_after(struct rg_list * ref, struct rg_list * item) { ASSERT(ref != NULL); ASSERT(item != NULL); ASSERT(rg_list_is_empty(item)); item->next = ref->next; item->prev = ref; item->head = ref->head; ref->next->prev = item; ref->next = item; } void rg_list_insert_before(struct rg_list * ref, struct rg_list * item) { ASSERT(ref != NULL); ASSERT(item != NULL); ASSERT(rg_list_is_empty(item)); item->prev = ref->prev; item->next = ref; item->head = ref->head; ref->prev->next = item; ref->prev = item; } void rg_list_unlink(struct rg_list * plist) { ASSERT(plist != NULL); if (plist->head == plist) return; plist->next->prev = plist->prev; plist->prev->next = plist->next; plist->next = plist; plist->prev = plist; plist->head = plist; } /************ Other helpers ***********/ /* Terminate a thread */ int rg_thread_term(pthread_t * th) { int ret = 0; void * th_ret = NULL; CHECK_PARAMS(th); /* Test if it was already terminated */ if (*th == (pthread_t)NULL) return 0; /* Cancel the thread if it is still running - ignore error if it was already terminated */ (void) pthread_cancel(*th); /* Then join the thread */ CHECK_POSIX_DO( ret = pthread_join(*th, &th_ret), /* continue */ ); if (th_ret != NULL) { TRACE_DEBUG(FULL, "The thread returned the following value: %p (ignored)", th_ret); } /* Clean the location */ *th = (pthread_t)NULL; return ret; } /* Cancellation cleanups */ void rg_cleanup_mutex(void * mtx) { CHECK_POSIX_DO( pthread_mutex_unlock((pthread_mutex_t *)mtx), ); } /* Global functions not exported through the API (bad practice since no ABI control...) */ int rg_pointers_init(void ** hdl) { CHECK_PARAMS(hdl); *hdl = dlopen(0, RTLD_LAZY | RTLD_GLOBAL); if (!*hdl) { TRACE_DEBUG(INFO, "Error in dlopen(0): %s", dlerror()); return ENOTSUP; } return 0; } void rg_pointers_fini(void **hdl) { CHECK_PARAMS_DO(hdl, return); dlclose(*hdl); *hdl = NULL; return; }