Navigation


Changeset 658:f198d16fa7f4 in freeDiameter for libfdcore


Ignore:
Timestamp:
Jan 14, 2011, 3:15:23 PM (13 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Initial commit for 1.1.0:

  • Restructuring:
    • libfreeDiameter:
      • renamed folder & binary into libfdproto
      • renamed libfD.h into fdproto-internal.h
      • removed signals management (replaced by triggers in libfdcore)
  • freeDiameter split into:
    • libfdcore (most contents)
      • renamed fD.h into fdcore-internal.h
      • added core.c for framework init/shutdown.
      • new triggers mechanism in events.c.
  • freeDiameterd (main, command line parsing, signals management)
  • tests:
    • now in top-level directory tests.
  • other changes:
    • fd_dict_new now returns 0 on duplicate identical entries.
    • fixes in dict_legacy_xml
    • fixes in some dictionaries
    • moved FD_DEFAULT_CONF_FILENAME definition to freeDiameter-host.h
Location:
libfdcore
Files:
1 added
1 copied
27 moved

Legend:

Unmodified
Added
Removed
  • libfdcore/CMakeLists.txt

    r592 r658  
    11# The subproject name
    2 Project("freeDiameterd" C)
     2Project("freeDiameter core library" C)
    33
    44# Configuration parser
     
    88
    99# List of source files
    10 SET(FD_COMMON_SRC
    11         fD.h
     10SET(FDCORE_SRC
     11        fdcore-internal.h
    1212        apps.c
    1313        cnxctx.h
    1414        config.c
     15        core.c
    1516        cnxctx.c
    1617        endpoints.c
     
    3536
    3637IF(NOT DISABLE_SCTP)
    37         SET(FD_COMMON_SRC ${FD_COMMON_SRC} sctp.c sctps.c)
     38        SET(FDCORE_SRC ${FDCORE_SRC} sctp.c sctps.c)
    3839ENDIF(NOT DISABLE_SCTP)
    3940
    40 SET(FD_COMMON_GEN_SRC
     41SET(FDCORE_GEN_SRC
    4142                lex.fdd.c
    4243                fdd.tab.c
     
    4546       
    4647# Save the list of files for the tests
    47 SET(FD_COMMON_SRC ${FD_COMMON_SRC} PARENT_SCOPE)
    48 SET(FD_COMMON_GEN_SRC ${FD_COMMON_GEN_SRC} PARENT_SCOPE)
    49 
    50 
    51 # Require GNU TLS for building the daemon
    52 FIND_PACKAGE(GnuTLS REQUIRED)
    53 INCLUDE_DIRECTORIES(${GNUTLS_INCLUDE_DIR})
    54 SET(FD_LIBS ${FD_LIBS} ${GNUTLS_LIBRARIES})
    55 find_path(GCRYPT_INCLUDE_DIR NAMES gcrypt.h)
    56 If ( NOT GCRYPT_INCLUDE_DIR )
    57         MESSAGE(SEND_ERROR "Unable to find gcrypt.h, please install libgcrypt-dev or equivalent")
    58 Endif ( NOT GCRYPT_INCLUDE_DIR )
    59 MARK_AS_ADVANCED(GCRYPT_INCLUDE_DIR)
    60 INCLUDE_DIRECTORIES(${GCRYPT_INCLUDE_DIR})
    61 
    62 # Also we need libgcrypt to... display its version :(
    63 find_library(GCRYPT_LIBRARY
    64   NAMES gcrypt
    65 )
    66 If ( NOT GCRYPT_LIBRARY )
    67         MESSAGE(SEND_ERROR "Unable to find libgcrypt, please install libgcrypt or equivalent")
    68 Endif ( NOT GCRYPT_LIBRARY )
    69 SET(FD_LIBS ${FD_LIBS} ${GCRYPT_LIBRARY})
    70 
     48SET(FDCORE_SRC ${FDCORE_SRC} PARENT_SCOPE)
     49SET(FDCORE_GEN_SRC ${FDCORE_GEN_SRC} PARENT_SCOPE)
    7150
    7251
    7352# Build the executable
    74 ADD_EXECUTABLE(freeDiameterd ${FD_COMMON_SRC} ${FD_COMMON_GEN_SRC} main.c)
     53ADD_LIBRARY(libfdcore SHARED ${FDCORE_SRC} ${FDCORE_GEN_SRC})
    7554
    76 # The version
    77 SET_TARGET_PROPERTIES(freeDiameterd PROPERTIES
     55# Avoid the liblib name, and set the version
     56SET_TARGET_PROPERTIES(libfdcore PROPERTIES
     57        OUTPUT_NAME "fdcore"
     58        SOVERSION ${FD_PROJECT_VERSION_API}
    7859        VERSION ${FD_PROJECT_VERSION_MAJOR}.${FD_PROJECT_VERSION_MINOR}.${FD_PROJECT_VERSION_REV})
    7960
    80 # The link command
    81 LINK_DIRECTORIES(${CURRENT_BINARY_DIR}/../libfreeDiameter)
    82 TARGET_LINK_LIBRARIES(freeDiameterd libfreeDiameter ${FD_LIBS})
     61# The library itself needs other libraries
     62LINK_DIRECTORIES(${CURRENT_BINARY_DIR}/../libfdproto)
     63TARGET_LINK_LIBRARIES(libfdcore libfdproto ${LFDCORE_LIBS})
    8364
    84 # The unary tests directory
    85 IF ( BUILD_TESTING )
    86         SUBDIRS(tests)
    87 ENDIF ( BUILD_TESTING )
    8865
    8966####
    9067## INSTALL section ##
    9168
    92 INSTALL(TARGETS freeDiameterd
    93         RUNTIME DESTINATION ${INSTALL_DAEMON_SUFFIX}
    94         COMPONENT freeDiameter-daemon)
     69INSTALL(TARGETS libfdcore
     70        LIBRARY DESTINATION ${INSTALL_LIBRARY_SUFFIX}
     71        COMPONENT freeDiameter-common)
  • libfdcore/apps.c

    r648 r658  
    3434*********************************************************************************************************/
    3535
    36 #include "fD.h"
     36#include "fdcore-internal.h"
    3737
    3838/* Merge information into a list of apps */
  • libfdcore/cnxctx.c

    r591 r658  
    3434*********************************************************************************************************/
    3535
    36 #include "fD.h"
     36#include "fdcore-internal.h"
    3737#include "cnxctx.h"
    3838
  • libfdcore/config.c

    r578 r658  
    3434*********************************************************************************************************/
    3535
    36 #include "fD.h"
     36#include "fdcore-internal.h"
    3737#include <sys/stat.h>
    3838
     
    4646#endif /* GNUTLS_DEFAULT_DHBITS */
    4747
    48 /* Initialize the fd_g_config structure to default values */
     48/* Initialize the fd_g_config structure to default values -- it should already have been initialized to all-0 */
    4949int fd_conf_init()
    5050{
  • libfdcore/dict_base_proto.c

    r336 r658  
    3737 */
    3838
    39 #include "fD.h"
     39#include "fdcore-internal.h"
    4040
    4141#include <netinet/in.h>
  • libfdcore/endpoints.c

    r640 r658  
    3434*********************************************************************************************************/
    3535
    36 #include "fD.h"
     36#include "fdcore-internal.h"
    3737
    3838
  • libfdcore/events.c

    r82 r658  
    3434*********************************************************************************************************/
    3535
    36 #include "fD.h"
     36#include "fdcore-internal.h"
     37
     38/* Events are a subset of fifo queues, with a known type */
    3739
    3840int fd_event_send(struct fifo *queue, int code, size_t datasz, void * data)
     
    110112                case_str(FDEV_DUMP_CONFIG);
    111113                case_str(FDEV_DUMP_PEERS);
     114                case_str(FDEV_TRIGGER);
    112115               
    113116                default:
     
    117120}
    118121
     122/**********************************************************************/
     123/* Trigged events */
     124/* This allows extensions to register for / send triggers to other extensions */
     125/* It is used for example for users interactions (through signals or ...) */
     126
     127/* Because the number of triggers is not expected to grow, we use a simple ordered chained list */
     128static pthread_rwlock_t trig_rwl = PTHREAD_RWLOCK_INITIALIZER;
     129static struct fd_list   trig_list = FD_LIST_INITIALIZER(trig_list); /* The list of triggers ordered by trigger value */
     130struct trig_item {
     131        struct fd_list  chain;
     132        int             trig_value;
     133        const char *    trig_module;
     134        void            (*cb)(void);
     135};     
     136
     137/* Add a new entry in the trigger list */
     138int fd_event_trig_regcb(int trigger_val, const char * module, void (*cb)(void))
     139{
     140        struct trig_item * ti;
     141        struct fd_list * li;
     142       
     143        TRACE_ENTRY("%d %p %p", trigger_val, module, cb);
     144        CHECK_PARAMS( trigger_val && cb );
     145       
     146        /* Create a new trig_item */
     147        CHECK_MALLOC( ti = malloc(sizeof(struct trig_item)) );
     148        memset(ti, 0, sizeof(struct trig_item));
     149        fd_list_init(&ti->chain, ti);
     150        ti->trig_value = trigger_val;
     151        ti->trig_module = module;
     152        ti->cb = cb;
     153       
     154        /* Now insert in the list */
     155        CHECK_POSIX( pthread_rwlock_wrlock(&trig_rwl) );
     156       
     157        for (li = trig_list.next; li != &trig_list; li = li->next) {
     158                struct trig_item *t = li->o;
     159                if (t->trig_value >= trigger_val)
     160                        break;
     161        }
     162       
     163        fd_list_insert_before(li, &ti->chain);
     164       
     165        CHECK_POSIX( pthread_rwlock_unlock(&trig_rwl) );
     166
     167        return 0;
     168}
     169
     170void fd_event_trig_dump()
     171{
     172        struct fd_list * li;
     173        if (!TRACE_BOOL(FULL))
     174                return;
     175       
     176        CHECK_POSIX_DO( pthread_rwlock_rdlock(&trig_rwl),  );
     177       
     178        for (li = trig_list.next; li != &trig_list; li = li->next) {
     179                struct trig_item *t = li->o;
     180                fd_log_debug("  Trigger %d, module '%s': %p\n", t->trig_value, t->trig_module, t->cb);
     181        }
     182       
     183        CHECK_POSIX_DO( pthread_rwlock_unlock(&trig_rwl),  );
     184}
     185
     186static void *call_cb_detached(void * arg)
     187{
     188        void (*cb)(void) = arg;
     189        fd_log_threadname("Trig'd callback thread");
     190        TRACE_ENTRY("%p", arg);
     191        (*cb)();
     192        TRACE_DEBUG(ANNOYING, "Callback %p completed", cb);
     193}
     194
     195int fd_event_trig_call_cb(int trigger_val)
     196{
     197        struct fd_list * li;
     198        pthread_attr_t detached;
     199        pthread_t th;
     200       
     201        CHECK_POSIX( pthread_attr_init(&detached) );
     202        CHECK_POSIX( pthread_attr_setdetachstate(&detached, PTHREAD_CREATE_DETACHED) );
     203       
     204        CHECK_POSIX( pthread_rwlock_rdlock(&trig_rwl)  );
     205       
     206        for (li = trig_list.next; li != &trig_list; li = li->next) {
     207                struct trig_item *t = li->o;
     208                if (t->trig_value == trigger_val) {
     209                        TRACE_DEBUG(FULL, "Trigger %d: Calling %p in %s", t->trig_value, t->cb, t->trig_module);
     210                        CHECK_POSIX_DO( pthread_create( &th, &detached, call_cb_detached, t->cb ), break );
     211                }
     212                if (t->trig_value > trigger_val)
     213                        break;
     214        }
     215       
     216        CHECK_POSIX( pthread_rwlock_unlock(&trig_rwl)  );
     217       
     218        return 0;
     219}
     220
     221int fd_event_trig_fini(void) {
     222       
     223        TRACE_ENTRY("");
     224       
     225        CHECK_POSIX( pthread_rwlock_wrlock(&trig_rwl) );
     226       
     227        while (!FD_IS_LIST_EMPTY(&trig_list)) {
     228                struct fd_list * li = trig_list.next;
     229                fd_list_unlink(li);
     230                free(li);
     231        }
     232       
     233        CHECK_POSIX( pthread_rwlock_unlock(&trig_rwl) );
     234       
     235        return 0;
     236}
  • libfdcore/extensions.c

    r287 r658  
    3434*********************************************************************************************************/
    3535
    36 #include "fD.h"
     36#include "fdcore-internal.h"
    3737
    3838#include <dlfcn.h>      /* We may use libtool's <ltdl.h> later for better portability.... */
  • libfdcore/fdcore-internal.h

    r649 r658  
    3434*********************************************************************************************************/
    3535
    36 /* This file contains the definitions for internal use in the freeDiameter daemon */
    37 
    38 #ifndef _FD_H
    39 #define _FD_H
     36/* This file contains the definitions for internal use in the freeDiameter core library */
     37
     38#ifndef _FDCORE_INTERNAL_H
     39#define _FDCORE_INTERNAL_H
    4040
    4141#include <freeDiameter/freeDiameter-host.h>
    42 #include <freeDiameter/freeDiameter.h>
    43 
    44 #ifndef FD_DEFAULT_CONF_FILENAME
    45 #define FD_DEFAULT_CONF_FILENAME "freeDiameter.conf"
    46 #endif /* FD_DEFAULT_CONF_FILENAME */
     42#include <freeDiameter/libfdcore.h>
    4743
    4844#ifdef DISABLE_SCTP
     
    106102int fd_queues_init(void);
    107103int fd_queues_fini(struct fifo ** queue);
     104
     105/* Trigged events */
     106int fd_event_trig_call_cb(int trigger_val);
     107int fd_event_trig_fini(void);
    108108
    109109/* Create all the dictionary objects defined in the Diameter base RFC. */
     
    345345#define FD_CNX_BROADCAST        (1 << 1)        /* The message is sent over all stream pairs, in case of SCTP. No effect on TCP */
    346346
    347 #endif /* _FD_H */
     347#endif /* _FDCORE_INTERNAL_H */
  • libfdcore/fdd.l

    r578 r658  
    4343%{
    4444/* Include the daemon's header files */
    45 #include "fD.h"
     45#include "fdcore-internal.h"
    4646/* Include yacc tokens definitions */
    4747#include "fdd.tab.h"
  • libfdcore/fdd.y

    r578 r658  
    5353
    5454%{
    55 #include "fD.h"
     55#include "fdcore-internal.h"
    5656#include "fdd.tab.h"    /* bug : bison does not define the YYLTYPE before including this bloc, so... */
    5757
  • libfdcore/messages.c

    r648 r658  
    3434*********************************************************************************************************/
    3535
    36 #include "fD.h"
     36#include "fdcore-internal.h"
    3737
    3838static struct dict_object * dict_avp_OH  = NULL; /* Origin-Host */
  • libfdcore/p_ce.c

    r454 r658  
    3434*********************************************************************************************************/
    3535
    36 #include "fD.h"
     36#include "fdcore-internal.h"
    3737
    3838/* This file contains code to handle Capabilities Exchange messages (CER and CEA) and election process */
  • libfdcore/p_cnx.c

    r379 r658  
    3434*********************************************************************************************************/
    3535
    36 #include "fD.h"
     36#include "fdcore-internal.h"
    3737
    3838/* This file contains code used by a peer state machine to initiate a connection to remote peer */
  • libfdcore/p_dp.c

    r454 r658  
    3434*********************************************************************************************************/
    3535
    36 #include "fD.h"
     36#include "fdcore-internal.h"
    3737
    3838/* This file contains code to handle Disconnect Peer messages (DPR and DPA) */
  • libfdcore/p_dw.c

    r454 r658  
    3434*********************************************************************************************************/
    3535
    36 #include "fD.h"
     36#include "fdcore-internal.h"
    3737
    3838/* This file contains code to handle Device Watchdog messages (DWR and DWA) */
  • libfdcore/p_expiry.c

    r648 r658  
    3434*********************************************************************************************************/
    3535
    36 #include "fD.h"
     36#include "fdcore-internal.h"
    3737
    3838/* Delay for garbage collection of expired peers, in seconds */
  • libfdcore/p_out.c

    r455 r658  
    3434*********************************************************************************************************/
    3535
    36 #include "fD.h"
     36#include "fdcore-internal.h"
    3737
    3838/* Alloc a new hbh for requests, bufferize the message and send on the connection, save in sentreq if provided */
  • libfdcore/p_psm.c

    r454 r658  
    3434*********************************************************************************************************/
    3535
    36 #include "fD.h"
     36#include "fdcore-internal.h"
    3737
    3838/* The actual declaration of peer_state_str */
  • libfdcore/p_sr.c

    r650 r658  
    3434*********************************************************************************************************/
    3535
    36 #include "fD.h"
     36#include "fdcore-internal.h"
    3737
    3838#ifndef SR_DEBUG_LVL
  • libfdcore/peers.c

    r649 r658  
    3434*********************************************************************************************************/
    3535
    36 #include "fD.h"
     36#include "fdcore-internal.h"
    3737
    3838/* Global list of peers */
  • libfdcore/queues.c

    r124 r658  
    3434*********************************************************************************************************/
    3535
    36 #include "fD.h"
     36#include "fdcore-internal.h"
    3737
    3838/* The global message queues */
  • libfdcore/routing_dispatch.c

    r649 r658  
    3434*********************************************************************************************************/
    3535
    36 #include "fD.h"
     36#include "fdcore-internal.h"
    3737
    3838/********************************************************************************/
  • libfdcore/sctp.c

    r590 r658  
    3434*********************************************************************************************************/
    3535
    36 #include "fD.h"
     36#include "fdcore-internal.h"
    3737#include "cnxctx.h"
    3838
  • libfdcore/sctps.c

    r543 r658  
    3737/* See http://aaa.koganei.wide.ad.jp/blogs/index.php/waaad/2008/08/18/tls-over-sctp for history */
    3838
    39 #include "fD.h"
     39#include "fdcore-internal.h"
    4040#include "cnxctx.h"
    4141
  • libfdcore/server.c

    r590 r658  
    3434*********************************************************************************************************/
    3535
    36 #include "fD.h"
     36#include "fdcore-internal.h"
    3737
    3838/* Server (listening) part of the daemon */
  • libfdcore/tcp.c

    r378 r658  
    3434*********************************************************************************************************/
    3535
    36 #include "fD.h"
     36#include "fdcore-internal.h"
    3737#include "cnxctx.h"
    3838
Note: See TracChangeset for help on using the changeset viewer.