Navigation


Changeset 8:3e143f047f78 in freeDiameter


Ignore:
Timestamp:
Sep 18, 2009, 6:54:07 PM (15 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Backup for the week-end

Files:
10 added
2 deleted
15 edited
2 moved

Legend:

Unmodified
Added
Removed
  • CMakeLists.txt

    r1 r8  
    33# Name of the project, and language
    44PROJECT("freeDiameter" C)
     5
     6# Informations to display in daemon's help
     7SET(FD_PROJECT_NAME freeDiameter)
     8SET(FD_PROJECT_BINARY freeDiameterd)
     9SET(FD_PROJECT_VERSION_MAJOR 0)
     10SET(FD_PROJECT_VERSION_MINOR 1)
     11SET(FD_PROJECT_VERSION_REV 0)
     12SET(FD_PROJECT_COPYRIGHT "Copyright (c) 2008-2009, WIDE Project (www.wide.ad.jp) and NICT (www.nict.go.jp)")
    513
    614# Some subfolders may have tests
     
    1624ADD_DEFINITIONS(-D_GNU_SOURCE)
    1725
    18 # Location for the include files
    19 INCLUDE_DIRECTORIES(include)
    20 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/include)
    21 SUBDIRS(include/freeDiameter)
    22 
    2326# some subfolders use yacc and lex parsers
    2427SET(BISON_GENERATE_DEFINES TRUE)
     
    3336# how to do the check with cmake???
    3437
     38# Location for the include files
     39INCLUDE_DIRECTORIES(include)
     40INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/include)
     41SUBDIRS(include/freeDiameter)
     42
    3543# Location for the source code
    3644SUBDIRS(libfreeDiameter)
  • cmake/Modules/FindSCTP.cmake

    r0 r8  
    66#  SCTP_LIBRARIES - link these to use SCTP
    77
    8 include(LibFindMacros)
    9 
    10 # Use pkg-config to get hints about paths (Note: not yet supported?)
    11 # libfind_pkg_check_modules(SCTP_PKGCONF sctp)
     8if (SCTP_INCLUDE_DIRS)
     9  set(SCTP_FIND_QUIETLY TRUE)
     10endif (SCTP_INCLUDE_DIRS)
    1211
    1312# Include dir
    1413find_path(SCTP_INCLUDE_DIR
    1514  NAMES netinet/sctp.h
    16   PATHS ${SCTP_PKGCONF_INCLUDE_DIRS}
    1715)
    1816
    19 # Finally the library itself
     17# Library
    2018find_library(SCTP_LIBRARY
    2119  NAMES sctp
    22   PATHS ${SCTP_PKGCONF_LIBRARY_DIRS}
    2320)
    2421
    2522# Set the include dir variables and the libraries and let libfind_process do the rest.
    2623# NOTE: Singular variables for this library, plural for libraries this this lib depends on.
    27 set(SCTP_PROCESS_INCLUDES SCTP_INCLUDE_DIR)
    28 set(SCTP_PROCESS_LIBS SCTP_LIBRARY)
    29 libfind_process(SCTP)
     24#set(SCTP_PROCESS_INCLUDES SCTP_INCLUDE_DIR)
     25#set(SCTP_PROCESS_LIBS SCTP_LIBRARY)
     26#libfind_process(SCTP)
     27
     28
     29# handle the QUIETLY and REQUIRED arguments and set SCTP_FOUND to TRUE if
     30# all listed variables are TRUE
     31INCLUDE(FindPackageHandleStandardArgs)
     32FIND_PACKAGE_HANDLE_STANDARD_ARGS(SCTP DEFAULT_MSG SCTP_LIBRARY SCTP_INCLUDE_DIR)
     33
     34# If we successfully found the sctp library then add the library to the
     35# SCTP_LIBRARIES cmake variable otherwise set SCTP_LIBRARIES to nothing.
     36IF(SCTP_FOUND)
     37   SET( SCTP_LIBRARIES ${SCTP_LIBRARY} )
     38ELSE(SCTP_FOUND)
     39   SET( SCTP_LIBRARIES )
     40ENDIF(SCTP_FOUND)
     41
     42
     43# Lastly make it so that the SCTP_LIBRARY and SCTP_INCLUDE_DIR variables
     44# only show up under the advanced options in the gui cmake applications.
     45MARK_AS_ADVANCED( SCTP_LIBRARY SCTP_INCLUDE_DIR )
     46
  • freeDiameter/CMakeLists.txt

    r2 r8  
    22Project("freeDiameterd" C)
    33
    4 SET(PROJECT_VERSION 0.1)
    5 SET(PROJECT_COPYRIGHT "Copyright (c) 2008-2009, WIDE Project (www.wide.ad.jp) and NICT (www.nict.go.jp)")
     4# Configuration parser
     5BISON_FILE(fdd.y)
     6FLEX_FILE(fdd.l)
     7SET_SOURCE_FILES_PROPERTIES(lex.fdd.c fdd.tab.c PROPERTIES COMPILE_FLAGS "-I ${CMAKE_CURRENT_SOURCE_DIR}")
    68
    79# List of source files
    810SET(FD_COMMON_SRC
    911        fD.h
     12        config.c
     13        extensions.c
    1014        dict_base_proto.c
    1115        )
    1216
     17SET(FD_COMMON_GEN_SRC
     18                lex.fdd.c
     19                fdd.tab.c
     20                fdd.tab.h
     21        )
     22
     23
    1324# Building the executable
    14 ADD_EXECUTABLE(freeDiameterd ${FD_COMMON_SRC} main.c)
     25ADD_EXECUTABLE(freeDiameterd ${FD_COMMON_SRC} ${FD_COMMON_GEN_SRC} main.c)
    1526
    1627# The link command
     
    2031# Save the list of files, if needed
    2132SET(FD_COMMON_SRC ${FD_COMMON_SRC} PARENT_SCOPE)
     33SET(FD_COMMON_GEN_SRC ${FD_COMMON_GEN_SRC} PARENT_SCOPE)
    2234
    2335# The unary tests directory
  • freeDiameter/fD.h

    r1 r8  
    4242#include <freeDiameter/freeDiameter.h>
    4343
     44/* Events codespace for fd_g_config->g_fifo_main */
     45enum {
     46        FM_TERMINATE = 1000     /* request to terminate */
     47};
     48
     49/* Configuration */
     50int fd_conf_init();
     51void fd_conf_dump();
     52int fd_conf_parse();
     53int fddparse(struct fd_config * conf); /* yacc generated */
     54
     55/* Extensions */
     56int fd_ext_init();
     57int fd_ext_add( char * filename, char * conffile );
     58int fd_ext_load();
     59int fd_ext_fini(void);
     60
    4461/* Create all the dictionary objects defined in the Diameter base RFC. */
    4562int fd_dict_base_protocol(struct dictionary * dict);
    4663
    47 
    4864#endif /* _FD_H */
  • freeDiameter/main.c

    r3 r8  
    3636#include "fD.h"
    3737
     38#include <signal.h>
     39#include <getopt.h>
     40
     41
     42/* Display package version */
     43static void main_version_core(void)
     44{
     45        printf("%s, version %d.%d.%d"
     46#ifdef HG_VERSION
     47                " (r%s"
     48# ifdef PACKAGE_HG_REVISION
     49                "/%s"
     50# endif /* PACKAGE_HG_VERSION */
     51                ")"
     52#endif /* HG_VERSION */
     53                "\n",
     54                FD_PROJECT_NAME, FD_PROJECT_VERSION_MAJOR, FD_PROJECT_VERSION_MINOR, FD_PROJECT_VERSION_REV
     55#ifdef HG_VERSION
     56                , HG_VERSION
     57# ifdef PACKAGE_HG_REVISION
     58                , PACKAGE_HG_REVISION
     59# endif /* PACKAGE_HG_VERSION */
     60#endif /* HG_VERSION */
     61                );
     62}
     63
     64/* Display package version and general info */
     65static void main_version(void)
     66{
     67        main_version_core();
     68        printf( "%s\n", FD_PROJECT_COPYRIGHT);
     69        printf( "\nSee " FD_PROJECT_NAME " homepage at http://aaa.koganei.wide.ad.jp/\n"
     70                " for information, updates and bug reports on this software.\n");
     71}
     72
     73/* Print command-line options */
     74static void main_help( void )
     75{
     76        main_version_core();
     77        printf( "  This daemon is an implementation of the Diameter protocol\n"
     78                "  used for Authentication, Authorization, and Accounting (AAA).\n");
     79        printf("\nUsage:  " FD_PROJECT_BINARY " [OPTIONS]...\n");
     80        printf( "  -h, --help             Print help and exit\n"
     81                "  -V, --version          Print version and exit\n"
     82                "  -c, --config=filename  Read configuration from this file instead of the \n"
     83                "                           default location (%s).\n", DEFAULT_CONF_FILE);
     84        printf( "\nDebug:\n"
     85                "  These options are mostly useful for developers\n"
     86                "  -d, --debug            Increase verbosity of debug messages\n"
     87                "  -q, --quiet            Decrease verbosity then remove debug messages\n");
     88}
     89
     90/* Parse the command-line */
     91static int main_cmdline(int argc, char *argv[])
     92{
     93        int c;
     94        int option_index = 0;
     95       
     96        struct option long_options[] = {
     97                { "help",       0, NULL, 'h' },
     98                { "version",    0, NULL, 'V' },
     99                { "config",     1, NULL, 'c' },
     100                { "debug",      0, NULL, 'd' },
     101                { "quiet",      0, NULL, 'q' },
     102                { NULL, 0, NULL, 0 }
     103        };
     104       
     105        TRACE_ENTRY("%d %p", argc, argv);
     106       
     107        /* Loop on arguments */
     108        while (1) {
     109                c = getopt_long (argc, argv, "hVc:dq", long_options, &option_index);
     110                if (c == -1)
     111                        break;  /* Exit from the loop.  */
     112               
     113                switch (c) {
     114                        case 'h':       /* Print help and exit.  */
     115                                main_help();
     116                                exit(0);
     117
     118                        case 'V':       /* Print version and exit.  */
     119                                main_version();
     120                                exit(0);
     121
     122                        case 'c':       /* Read configuration from this file instead of the default location..  */
     123                                CHECK_PARAMS( optarg );
     124                                fd_g_config->conf_file = optarg;
     125                                break;
     126
     127                        case 'd':       /* Increase verbosity of debug messages.  */
     128                                fd_g_debug_lvl++;
     129                                break;
     130                               
     131                        case 'q':       /* Decrease verbosity then remove debug messages.  */
     132                                fd_g_debug_lvl--;
     133                                break;
     134
     135                        case '?':       /* Invalid option.  */
     136                                /* `getopt_long' already printed an error message.  */
     137                                TRACE_DEBUG(INFO, "getopt_long found an invalid character\n");
     138                                return EINVAL;
     139
     140                        default:        /* bug: option not considered.  */
     141                                TRACE_DEBUG(INFO, "A command-line option is missing in parser: %c\n", c);
     142                                ASSERT(0);
     143                                return EINVAL;
     144                }
     145        }
     146               
     147        return 0;
     148       
     149}
     150
     151#ifdef HAVE_SIGNALENT_H
     152const char *const signalstr[] = {
     153# include "signalent.h"
     154};
     155const int nsignalstr = sizeof signalstr / sizeof signalstr[0];
     156# define SIGNALSTR(sig) (((sig) < nsignalstr) ? signalstr[(sig)] : "unknown")
     157#else /* HAVE_SIGNALENT_H */
     158# define SIGNALSTR(sig) ("")
     159#endif /* HAVE_SIGNALENT_H */
     160
     161
     162/* signal handler */
     163static void * sig_hdl(void * arg)
     164{
     165        sigset_t sig_main;
     166        int sig = 0;
     167       
     168        TRACE_ENTRY();
     169        fd_log_threadname("Main signal handler");
     170       
     171        sigemptyset(&sig_main);
     172        sigaddset(&sig_main, SIGINT);
     173        sigaddset(&sig_main, SIGTERM);
     174       
     175        CHECK_SYS_DO(  sigwait(&sig_main, &sig), TRACE_DEBUG(INFO, "Error in sigwait function") );
     176       
     177        TRACE_DEBUG(INFO, "Received signal %s (%d), exiting", SIGNALSTR(sig), sig);
     178        CHECK_FCT_DO( fd_event_send(fd_g_config->g_fifo_main, FM_TERMINATE, NULL), exit(2) );
     179        return NULL;
     180}
     181       
     182/* The static configuration structure */
     183static struct fd_config conf;
     184struct fd_config * fd_g_config = &conf;
     185
    38186/* Entry point */
    39187int main(int argc, char * argv[])
    40188{
     189        int ret;
     190        pthread_t sig_th;
     191        sigset_t sig_all;
     192       
     193        memset(fd_g_config, 0, sizeof(struct fd_config));
     194        sigfillset(&sig_all);
     195        CHECK_POSIX(  pthread_sigmask(SIG_BLOCK, &sig_all, NULL)  );
     196       
    41197        /* Initialize the library */
    42198        CHECK_FCT( fd_lib_init() );
     
    44200        /* Name this thread */
    45201        fd_log_threadname("Main");
    46 
    47         /* Initialize the dictionary */
    48         CHECK_FCT( fd_dict_init(&fd_g_dict) );
     202       
     203        /* Initialize the config */
     204        CHECK_FCT( fd_conf_init() );
     205
     206        /* Parse the command-line */
     207        CHECK_FCT(  main_cmdline(argc, argv)  );
     208       
     209        /* Allow SIGINT and SIGTERM from this point */
     210        CHECK_POSIX(  pthread_create(&sig_th, NULL, sig_hdl, NULL)  );
    49211       
    50212        /* Add definitions of the base protocol */
    51         CHECK_FCT( fd_dict_base_protocol(fd_g_dict) );
    52        
    53         TRACE_DEBUG(INFO, "freeDiameter daemon initialized.");
    54        
    55         return 0;
    56 }
     213        CHECK_FCT( fd_dict_base_protocol(fd_g_config->g_dict) );
     214       
     215        /* Initialize other modules */
     216        CHECK_FCT(  fd_ext_init()  );
     217       
     218        /* Parse the configuration file */
     219        CHECK_FCT( fd_conf_parse() );
     220       
     221        /* Load the dynamic extensions */
     222        CHECK_FCT(  fd_ext_load()  );
     223       
     224        /* Start the peer state machines */
     225       
     226       
     227        /* Now, just wait for events */
     228        TRACE_DEBUG(INFO, FD_PROJECT_BINARY " daemon initialized.");
     229        fd_conf_dump();
     230        while (1) {
     231                int code;
     232                CHECK_FCT_DO(  fd_event_get(fd_g_config->g_fifo_main, &code, NULL),  break  );
     233                switch (code) {
     234                        case FM_TERMINATE:
     235                                ret = 0;
     236                                goto end;
     237                       
     238                        default:
     239                                TRACE_DEBUG(INFO, "Unexpected event in the daemon (%d), terminating.\n", code);
     240                                ret = -1;
     241                                goto end;
     242                }
     243        }
     244       
     245end:
     246        TRACE_DEBUG(INFO, FD_PROJECT_BINARY " daemon is stopping...");
     247       
     248        /* cleanups */
     249        CHECK_FCT( fd_thr_term(&sig_th) );
     250       
     251        return ret;
     252}
  • freeDiameter/tests/CMakeLists.txt

    r7 r8  
    1515        testdict
    1616        testmesg
    17         testmq
     17        testqueues
    1818        testsess
    1919        testdisp
     
    2929INCLUDE_DIRECTORIES( "../../libfreeDiameter" )
    3030
     31BISON_FILE(../fdd.y)
     32FLEX_FILE(../fdd.l)
     33
    3134SET(TEST_COMMON_SRC "")
    3235
     
    3538ENDFOREACH(SRC_FILE)
    3639
    37 # FOREACH( SRC_FILE ${FD_COMMON_GEN_SRC})
    38 #    SET(TEST_COMMON_SRC ${TEST_COMMON_SRC} "${CMAKE_CURRENT_BINARY_DIR}/../${SRC_FILE}")
    39 # ENDFOREACH(SRC_FILE)
     40FOREACH( SRC_FILE ${FD_COMMON_GEN_SRC})
     41   SET(TEST_COMMON_SRC ${TEST_COMMON_SRC} "${CMAKE_CURRENT_BINARY_DIR}/../${SRC_FILE}")
     42ENDFOREACH(SRC_FILE)
    4043
    4144FOREACH( SRC_FILE ${LFD_SRC})
  • freeDiameter/tests/testdict.c

    r1 r8  
    6767               
    6868                /* Create two vendors */
    69                 CHECK( 0, fd_dict_new ( fd_g_dict, DICT_VENDOR, &vendor1_data , NULL, &obj1 ) );
    70                 CHECK( 0, fd_dict_new ( fd_g_dict, DICT_VENDOR, &vendor2_data , NULL, NULL ) );
     69                CHECK( 0, fd_dict_new ( fd_g_config->g_dict, DICT_VENDOR, &vendor1_data , NULL, &obj1 ) );
     70                CHECK( 0, fd_dict_new ( fd_g_config->g_dict, DICT_VENDOR, &vendor2_data , NULL, NULL ) );
    7171               
    7272                /* Check we always retrieve the correct vendor object */
    73                 CHECK( 0, fd_dict_search ( fd_g_dict, DICT_VENDOR, VENDOR_BY_ID, &vendor_id, &obj2, ENOENT ) );
     73                CHECK( 0, fd_dict_search ( fd_g_config->g_dict, DICT_VENDOR, VENDOR_BY_ID, &vendor_id, &obj2, ENOENT ) );
    7474                CHECK( obj1, obj2);
    75                 CHECK( 0, fd_dict_search ( fd_g_dict, DICT_VENDOR, VENDOR_BY_NAME, "Vendor test 1", &obj2, ENOENT ) );
     75                CHECK( 0, fd_dict_search ( fd_g_config->g_dict, DICT_VENDOR, VENDOR_BY_NAME, "Vendor test 1", &obj2, ENOENT ) );
    7676                CHECK( obj1, obj2);
    7777               
    7878                /* Check the error conditions */
    79                 CHECK( 0, fd_dict_search ( fd_g_dict, DICT_VENDOR, VENDOR_BY_ID, &vendor_id, NULL, ENOENT ) );
     79                CHECK( 0, fd_dict_search ( fd_g_config->g_dict, DICT_VENDOR, VENDOR_BY_ID, &vendor_id, NULL, ENOENT ) );
    8080               
    8181                vendor_id = 735673; /* Not defined */
    82                 CHECK( ENOENT, fd_dict_search ( fd_g_dict, DICT_VENDOR, VENDOR_BY_ID, &vendor_id, NULL, ENOENT ) );
    83                 CHECK( ENOENT, fd_dict_search ( fd_g_dict, DICT_VENDOR, VENDOR_BY_NAME, "Vendor test 3", NULL, ENOENT ) );
    84                 CHECK( ENOENT, fd_dict_search ( fd_g_dict, DICT_VENDOR, VENDOR_BY_ID, &vendor_id, &obj2, ENOENT ) );
    85                 CHECK( ENOENT, fd_dict_search ( fd_g_dict, DICT_VENDOR, VENDOR_BY_NAME, "Vendor test 3", &obj2, ENOENT ) );
    86                 CHECK( ENOTSUP, fd_dict_search ( fd_g_dict, DICT_VENDOR, VENDOR_BY_NAME, "Vendor test 3", &obj2, ENOTSUP ) );
     82                CHECK( ENOENT, fd_dict_search ( fd_g_config->g_dict, DICT_VENDOR, VENDOR_BY_ID, &vendor_id, NULL, ENOENT ) );
     83                CHECK( ENOENT, fd_dict_search ( fd_g_config->g_dict, DICT_VENDOR, VENDOR_BY_NAME, "Vendor test 3", NULL, ENOENT ) );
     84                CHECK( ENOENT, fd_dict_search ( fd_g_config->g_dict, DICT_VENDOR, VENDOR_BY_ID, &vendor_id, &obj2, ENOENT ) );
     85                CHECK( ENOENT, fd_dict_search ( fd_g_config->g_dict, DICT_VENDOR, VENDOR_BY_NAME, "Vendor test 3", &obj2, ENOENT ) );
     86                CHECK( ENOTSUP, fd_dict_search ( fd_g_config->g_dict, DICT_VENDOR, VENDOR_BY_NAME, "Vendor test 3", &obj2, ENOTSUP ) );
    8787               
    8888                /* Check the get_* functions */
     
    9494               
    9595                /* Create the application with vendor1 as parent */
    96                 CHECK( EINVAL, fd_dict_new ( fd_g_dict, DICT_APPLICATION, &app1_data , (struct dict_object *)"bad object", &obj2 ) );
    97                 CHECK( 0, fd_dict_new ( fd_g_dict, DICT_APPLICATION, &app1_data , obj1, &obj2 ) );
     96                CHECK( EINVAL, fd_dict_new ( fd_g_config->g_dict, DICT_APPLICATION, &app1_data , (struct dict_object *)"bad object", &obj2 ) );
     97                CHECK( 0, fd_dict_new ( fd_g_config->g_dict, DICT_APPLICATION, &app1_data , obj1, &obj2 ) );
    9898               
    99                 CHECK( 0, fd_dict_search ( fd_g_dict, DICT_VENDOR, VENDOR_OF_APPLICATION, obj2, &obj3, ENOENT ) );
     99                CHECK( 0, fd_dict_search ( fd_g_config->g_dict, DICT_VENDOR, VENDOR_OF_APPLICATION, obj2, &obj3, ENOENT ) );
    100100                CHECK( obj1, obj3);
    101101               
     
    112112                struct dict_avp_data example_avp_data = { 999999, 0, "Example-AVP", AVP_FLAG_VENDOR , 0, AVP_TYPE_GROUPED };
    113113
    114                 CHECK( 0, fd_dict_search ( fd_g_dict, DICT_AVP, AVP_BY_NAME, "Origin-Host", &origin_host_avp, ENOENT ) );
    115                 CHECK( 0, fd_dict_search ( fd_g_dict, DICT_AVP, AVP_BY_NAME, "Session-Id", &session_id_avp, ENOENT ) );
     114                CHECK( 0, fd_dict_search ( fd_g_config->g_dict, DICT_AVP, AVP_BY_NAME, "Origin-Host", &origin_host_avp, ENOENT ) );
     115                CHECK( 0, fd_dict_search ( fd_g_config->g_dict, DICT_AVP, AVP_BY_NAME, "Session-Id", &session_id_avp, ENOENT ) );
    116116               
    117                 CHECK( 0, fd_dict_new ( fd_g_dict, DICT_AVP, &example_avp_data , NULL, &example_avp_avp ) );
     117                CHECK( 0, fd_dict_new ( fd_g_config->g_dict, DICT_AVP, &example_avp_data , NULL, &example_avp_avp ) );
    118118               
    119119                rule_data.rule_avp = origin_host_avp;
    120120                rule_data.rule_min = 1;
    121121                rule_data.rule_max = 1;
    122                 CHECK( 0, fd_dict_new ( fd_g_dict, DICT_RULE, &rule_data, example_avp_avp, NULL ) );
     122                CHECK( 0, fd_dict_new ( fd_g_config->g_dict, DICT_RULE, &rule_data, example_avp_avp, NULL ) );
    123123               
    124124                rule_data.rule_avp = session_id_avp;
    125125                rule_data.rule_min = 1;
    126126                rule_data.rule_max = -1;
    127                 CHECK( 0, fd_dict_new ( fd_g_dict, DICT_RULE, &rule_data, example_avp_avp, NULL ) );
     127                CHECK( 0, fd_dict_new ( fd_g_config->g_dict, DICT_RULE, &rule_data, example_avp_avp, NULL ) );
    128128               
    129129                CHECK( 0, fd_dict_iterate_rules ( example_avp_avp, &nbr, iter_test) );
  • freeDiameter/tests/testdisp.c

    r7 r8  
    128128                struct dict_enumval_data enu2_data = { "ENU test 2", { .u32 = 2 }};
    129129               
    130                 CHECK( 0, fd_dict_new ( fd_g_dict, DICT_APPLICATION, &app1_data, NULL, &app1 ) );
    131                 CHECK( 0, fd_dict_new ( fd_g_dict, DICT_APPLICATION, &app2_data, NULL, &app2 ) );
    132                 CHECK( 0, fd_dict_new ( fd_g_dict, DICT_COMMAND, &cmd1_data, NULL, &cmd1 ) );
    133                 CHECK( 0, fd_dict_new ( fd_g_dict, DICT_COMMAND, &cmd2_data, NULL, &cmd2 ) );
    134                 CHECK( 0, fd_dict_new ( fd_g_dict, DICT_TYPE, &type_data, NULL, &enutype ) );
    135                 CHECK( 0, fd_dict_new ( fd_g_dict, DICT_AVP, &avp1_data, NULL,    &avp1 ) );
    136                 CHECK( 0, fd_dict_new ( fd_g_dict, DICT_AVP, &avp2_data, enutype, &avp2 ) );
    137                 CHECK( 0, fd_dict_new ( fd_g_dict, DICT_ENUMVAL, &enu1_data, enutype, &enu1 ) );
    138                 CHECK( 0, fd_dict_new ( fd_g_dict, DICT_ENUMVAL, &enu2_data, enutype, &enu2 ) );
     130                CHECK( 0, fd_dict_new ( fd_g_config->g_dict, DICT_APPLICATION, &app1_data, NULL, &app1 ) );
     131                CHECK( 0, fd_dict_new ( fd_g_config->g_dict, DICT_APPLICATION, &app2_data, NULL, &app2 ) );
     132                CHECK( 0, fd_dict_new ( fd_g_config->g_dict, DICT_COMMAND, &cmd1_data, NULL, &cmd1 ) );
     133                CHECK( 0, fd_dict_new ( fd_g_config->g_dict, DICT_COMMAND, &cmd2_data, NULL, &cmd2 ) );
     134                CHECK( 0, fd_dict_new ( fd_g_config->g_dict, DICT_TYPE, &type_data, NULL, &enutype ) );
     135                CHECK( 0, fd_dict_new ( fd_g_config->g_dict, DICT_AVP, &avp1_data, NULL,    &avp1 ) );
     136                CHECK( 0, fd_dict_new ( fd_g_config->g_dict, DICT_AVP, &avp2_data, enutype, &avp2 ) );
     137                CHECK( 0, fd_dict_new ( fd_g_config->g_dict, DICT_ENUMVAL, &enu1_data, enutype, &enu1 ) );
     138                CHECK( 0, fd_dict_new ( fd_g_config->g_dict, DICT_ENUMVAL, &enu2_data, enutype, &enu2 ) );
    139139        }
    140140       
  • freeDiameter/tests/testmesg.c

    r2 r8  
    5151
    5252                /* Now find the ACR dictionary object */
    53                 CHECK( 0, fd_dict_search ( fd_g_dict, DICT_COMMAND, CMD_BY_NAME, "Accounting-Request", &acr_model, ENOENT ) );
     53                CHECK( 0, fd_dict_search ( fd_g_config->g_dict, DICT_COMMAND, CMD_BY_NAME, "Accounting-Request", &acr_model, ENOENT ) );
    5454
    5555                /* Create the instance, using the templates */
     
    7171
    7272                /* Now find the ACR dictionary object */
    73                 CHECK( 0, fd_dict_search ( fd_g_dict, DICT_AVP, AVP_BY_NAME, "Proxy-Info", &pi_model, ENOENT ) );
     73                CHECK( 0, fd_dict_search ( fd_g_config->g_dict, DICT_AVP, AVP_BY_NAME, "Proxy-Info", &pi_model, ENOENT ) );
    7474
    7575                /* Create the instance, using the templates */
     
    133133
    134134                /* Now find the dictionary object */
    135                 CHECK( 0, fd_dict_search ( fd_g_dict, DICT_AVP, AVP_BY_NAME, "Route-Record", &rr_model, ENOENT ) );
     135                CHECK( 0, fd_dict_search ( fd_g_config->g_dict, DICT_AVP, AVP_BY_NAME, "Route-Record", &rr_model, ENOENT ) );
    136136
    137137                /* Create the instance, using the templates */
     
    161161
    162162                /* Now find the ACR dictionary object */
    163                 CHECK( 0, fd_dict_search ( fd_g_dict, DICT_COMMAND, CMD_BY_NAME, "Accounting-Request", &acr_model, ENOENT ) );
     163                CHECK( 0, fd_dict_search ( fd_g_config->g_dict, DICT_COMMAND, CMD_BY_NAME, "Accounting-Request", &acr_model, ENOENT ) );
    164164
    165165                /* Create the instance, using the templates */
     
    173173                {
    174174                        struct dict_vendor_data vendor_data = { 73565, "Vendor test" };
    175                         CHECK( 0, fd_dict_new ( fd_g_dict, DICT_VENDOR, &vendor_data , NULL, &vendor ) );
     175                        CHECK( 0, fd_dict_new ( fd_g_config->g_dict, DICT_VENDOR, &vendor_data , NULL, &vendor ) );
    176176                }
    177177               
    178178                {
    179179                        struct dict_application_data app_data = { 73566, "Application test" };
    180                         CHECK( 0, fd_dict_new ( fd_g_dict, DICT_APPLICATION, &app_data , vendor, NULL ) );
     180                        CHECK( 0, fd_dict_new ( fd_g_config->g_dict, DICT_APPLICATION, &app_data , vendor, NULL ) );
    181181                }
    182182               
    183183                {
    184184                        struct dict_avp_data avp_data = { 73567, 0, "AVP Test - no vendor - f32", 0, 0, AVP_TYPE_FLOAT32 };
    185                         CHECK( 0, fd_dict_new ( fd_g_dict, DICT_AVP, &avp_data , NULL, NULL ) );
     185                        CHECK( 0, fd_dict_new ( fd_g_config->g_dict, DICT_AVP, &avp_data , NULL, NULL ) );
    186186                }
    187187               
     
    190190                        struct dict_type_data type_data = { AVP_TYPE_INTEGER64, "Int64 test" };
    191191                        struct dict_avp_data  avp_data = { 73568, 73565, "AVP Test - i64", AVP_FLAG_VENDOR, AVP_FLAG_VENDOR, AVP_TYPE_INTEGER64 };
    192                         CHECK( 0, fd_dict_new ( fd_g_dict, DICT_TYPE, &type_data , NULL, &type ) );
    193                         CHECK( 0, fd_dict_new ( fd_g_dict, DICT_AVP, &avp_data , type, NULL ) );
     192                        CHECK( 0, fd_dict_new ( fd_g_config->g_dict, DICT_TYPE, &type_data , NULL, &type ) );
     193                        CHECK( 0, fd_dict_new ( fd_g_config->g_dict, DICT_AVP, &avp_data , type, NULL ) );
    194194                }
    195195               
     
    202202                        struct dict_avp_data     avp_data = { 73569, 73565, "AVP Test - enumi32", AVP_FLAG_VENDOR, AVP_FLAG_VENDOR, AVP_TYPE_INTEGER32 };
    203203                       
    204                         CHECK( 0, fd_dict_new ( fd_g_dict, DICT_TYPE, &type_data , NULL, &type ) );
    205                         CHECK( 0, fd_dict_new ( fd_g_dict, DICT_AVP, &avp_data , type, NULL ) );
    206                         CHECK( 0, fd_dict_new ( fd_g_dict, DICT_ENUMVAL, &val1 , type, NULL ) );
    207                         CHECK( 0, fd_dict_new ( fd_g_dict, DICT_ENUMVAL, &val2 , type, NULL ) );
    208                         CHECK( 0, fd_dict_new ( fd_g_dict, DICT_ENUMVAL, &val3 , type, NULL ) );
     204                        CHECK( 0, fd_dict_new ( fd_g_config->g_dict, DICT_TYPE, &type_data , NULL, &type ) );
     205                        CHECK( 0, fd_dict_new ( fd_g_config->g_dict, DICT_AVP, &avp_data , type, NULL ) );
     206                        CHECK( 0, fd_dict_new ( fd_g_config->g_dict, DICT_ENUMVAL, &val1 , type, NULL ) );
     207                        CHECK( 0, fd_dict_new ( fd_g_config->g_dict, DICT_ENUMVAL, &val2 , type, NULL ) );
     208                        CHECK( 0, fd_dict_new ( fd_g_config->g_dict, DICT_ENUMVAL, &val3 , type, NULL ) );
    209209                }
    210210                       
     
    213213                        struct dict_type_data type_data = { AVP_TYPE_OCTETSTRING, "OS test" };
    214214                        struct dict_avp_data  avp_data = { 73570, 73565, "AVP Test - os", AVP_FLAG_VENDOR, AVP_FLAG_VENDOR, AVP_TYPE_OCTETSTRING };
    215                         CHECK( 0, fd_dict_new ( fd_g_dict, DICT_TYPE, &type_data , NULL, &type ) );
    216                         CHECK( 0, fd_dict_new ( fd_g_dict, DICT_AVP, &avp_data , type, NULL ) );
     215                        CHECK( 0, fd_dict_new ( fd_g_config->g_dict, DICT_TYPE, &type_data , NULL, &type ) );
     216                        CHECK( 0, fd_dict_new ( fd_g_config->g_dict, DICT_AVP, &avp_data , type, NULL ) );
    217217                }
    218218               
     
    225225                        struct dict_avp_data     avp_data = { 73571, 73565, "AVP Test - enumos", AVP_FLAG_VENDOR, AVP_FLAG_VENDOR, AVP_TYPE_OCTETSTRING };
    226226                       
    227                         CHECK( 0, fd_dict_new ( fd_g_dict, DICT_TYPE, &type_data , NULL, &type ) );
    228                         CHECK( 0, fd_dict_new ( fd_g_dict, DICT_AVP, &avp_data , type, NULL ) );
    229                         CHECK( 0, fd_dict_new ( fd_g_dict, DICT_ENUMVAL, &val1 , type, NULL ) );
    230                         CHECK( 0, fd_dict_new ( fd_g_dict, DICT_ENUMVAL, &val2 , type, NULL ) );
    231                         CHECK( 0, fd_dict_new ( fd_g_dict, DICT_ENUMVAL, &val3 , type, NULL ) );
     227                        CHECK( 0, fd_dict_new ( fd_g_config->g_dict, DICT_TYPE, &type_data , NULL, &type ) );
     228                        CHECK( 0, fd_dict_new ( fd_g_config->g_dict, DICT_AVP, &avp_data , type, NULL ) );
     229                        CHECK( 0, fd_dict_new ( fd_g_config->g_dict, DICT_ENUMVAL, &val1 , type, NULL ) );
     230                        CHECK( 0, fd_dict_new ( fd_g_config->g_dict, DICT_ENUMVAL, &val2 , type, NULL ) );
     231                        CHECK( 0, fd_dict_new ( fd_g_config->g_dict, DICT_ENUMVAL, &val3 , type, NULL ) );
    232232                }
    233233               
     
    236236                        struct dict_avp_data avp_data = { 73572, 73565, "AVP Test - grouped", AVP_FLAG_VENDOR, AVP_FLAG_VENDOR, AVP_TYPE_GROUPED };
    237237                       
    238                         CHECK( 0, fd_dict_new ( fd_g_dict, DICT_AVP, &avp_data , NULL, &gavp ) );
     238                        CHECK( 0, fd_dict_new ( fd_g_config->g_dict, DICT_AVP, &avp_data , NULL, &gavp ) );
    239239                       
    240240                        /* Macro to search AVP and create a rule */             
     
    243243                                struct dict_avp_request _req = { (_vendor), 0, (_avpname) };                    \
    244244                                struct dict_rule_data _data;                                                    \
    245                                 CHECK( 0, fd_dict_search( fd_g_dict, DICT_AVP, AVP_BY_NAME_AND_VENDOR, &_req, &_avp, ENOENT));\
     245                                CHECK( 0, fd_dict_search( fd_g_config->g_dict, DICT_AVP, AVP_BY_NAME_AND_VENDOR, &_req, &_avp, ENOENT));\
    246246                                _data.rule_avp = _avp;                                                          \
    247247                                _data.rule_position = (_pos);                                                   \
     
    249249                                _data.rule_min = (_min);                                                        \
    250250                                _data.rule_max = (_max);                                                        \
    251                                 CHECK( 0, fd_dict_new ( fd_g_dict, DICT_RULE, &_data , (_parent), NULL ) );     \
     251                                CHECK( 0, fd_dict_new ( fd_g_config->g_dict, DICT_RULE, &_data , (_parent), NULL ) );   \
    252252                        }
    253253                       
     
    261261                        struct dict_cmd_data  cmd_data = { 73573, "Test-Command-Request", CMD_FLAG_REQUEST, CMD_FLAG_REQUEST };
    262262                       
    263                         CHECK( 0, fd_dict_search ( fd_g_dict, DICT_APPLICATION, APPLICATION_BY_NAME, "Application test", &application, ENOENT ) );
    264                         CHECK( 0, fd_dict_new ( fd_g_dict, DICT_COMMAND, &cmd_data , application, &command ) );
     263                        CHECK( 0, fd_dict_search ( fd_g_config->g_dict, DICT_APPLICATION, APPLICATION_BY_NAME, "Application test", &application, ENOENT ) );
     264                        CHECK( 0, fd_dict_new ( fd_g_config->g_dict, DICT_COMMAND, &cmd_data , application, &command ) );
    265265                        ADD_RULE(command, 0,     "AVP Test - no vendor - f32",  RULE_FIXED_HEAD, -1,  1,  1);
    266266                        ADD_RULE(command, 73565, "AVP Test - i64",              RULE_REQUIRED,   -1, -1,  0);
     
    275275                        struct dict_avp_data  avp_data = { 73574, 73565, "AVP Test - rules", AVP_FLAG_VENDOR, AVP_FLAG_VENDOR, AVP_TYPE_GROUPED };
    276276                       
    277                         CHECK( 0, fd_dict_new ( fd_g_dict, DICT_AVP, &avp_data , NULL, &gavp ) );
     277                        CHECK( 0, fd_dict_new ( fd_g_config->g_dict, DICT_AVP, &avp_data , NULL, &gavp ) );
    278278                       
    279279                        ADD_RULE(gavp,     0, "AVP Test - no vendor - f32", RULE_FIXED_HEAD,   0, 1, 1);
     
    303303                union avp_value      value;
    304304               
    305                 CHECK( 0, fd_dict_search ( fd_g_dict, DICT_COMMAND, CMD_BY_NAME, "Test-Command-Request", &cmd_model, ENOENT ) );
     305                CHECK( 0, fd_dict_search ( fd_g_config->g_dict, DICT_COMMAND, CMD_BY_NAME, "Test-Command-Request", &cmd_model, ENOENT ) );
    306306               
    307307                /* Check an error is trigged if the AVP has no value set */
    308308                {
    309                         CHECK( 0, fd_dict_search ( fd_g_dict, DICT_AVP,     AVP_BY_NAME,     "AVP Test - no vendor - f32", &avp_model, ENOENT ) );
     309                        CHECK( 0, fd_dict_search ( fd_g_config->g_dict, DICT_AVP,     AVP_BY_NAME,     "AVP Test - no vendor - f32", &avp_model, ENOENT ) );
    310310                       
    311311                        CHECK( 0, fd_msg_new ( cmd_model, 0, &msg ) );
     
    329329                                struct dict_object * _avp = NULL;                                               \
    330330                                struct dict_avp_request _req = { (_avpvendor), 0, (_avpname) };                 \
    331                                 CHECK( 0, fd_dict_search( fd_g_dict, DICT_AVP, AVP_BY_NAME_AND_VENDOR, &_req, &_avp, ENOENT));\
     331                                CHECK( 0, fd_dict_search( fd_g_config->g_dict, DICT_AVP, AVP_BY_NAME_AND_VENDOR, &_req, &_avp, ENOENT));\
    332332                                CHECK( 0, fd_msg_avp_new ( _avp, 0, &_avpi ) );                                 \
    333333                                CHECK( 0, fd_msg_avp_add ( (_parent), (_position), _avpi ) );                   \
     
    378378                               
    379379                                CHECK( 0, fd_msg_model ( avpi, &avp_model ) );
    380                                 CHECK( 0, fd_dict_search ( fd_g_dict, DICT_TYPE, TYPE_OF_AVP, avp_model, &type_model, ENOENT ) );
     380                                CHECK( 0, fd_dict_search ( fd_g_config->g_dict, DICT_TYPE, TYPE_OF_AVP, avp_model, &type_model, ENOENT ) );
    381381                                memset(&request, 0, sizeof(request));
    382382                                request.type_obj = type_model;
    383383                                request.search.enum_name = "i32 const test (val 2)";
    384                                 CHECK( 0, fd_dict_search ( fd_g_dict, DICT_ENUMVAL, ENUMVAL_BY_STRUCT, &request, &value_model, ENOENT ) );
     384                                CHECK( 0, fd_dict_search ( fd_g_config->g_dict, DICT_ENUMVAL, ENUMVAL_BY_STRUCT, &request, &value_model, ENOENT ) );
    385385                                CHECK( 0, fd_dict_getval ( value_model, &request.search ) );
    386386                                CHECK( 0, fd_msg_avp_setvalue ( avpi, &request.search.enum_value ) );
     
    399399                               
    400400                                CHECK( 0, fd_msg_model ( avpi, &avp_model ) );
    401                                 CHECK( 0, fd_dict_search ( fd_g_dict, DICT_TYPE, TYPE_OF_AVP, avp_model, &type_model, ENOENT ) );
     401                                CHECK( 0, fd_dict_search ( fd_g_config->g_dict, DICT_TYPE, TYPE_OF_AVP, avp_model, &type_model, ENOENT ) );
    402402                                memset(&request, 0, sizeof(request));
    403403                                request.type_obj = type_model;
    404404                                request.search.enum_name = "i32 const test (val -5)";
    405                                 CHECK( 0, fd_dict_search ( fd_g_dict, DICT_ENUMVAL, ENUMVAL_BY_STRUCT, &request, &value_model, ENOENT ) );
     405                                CHECK( 0, fd_dict_search ( fd_g_config->g_dict, DICT_ENUMVAL, ENUMVAL_BY_STRUCT, &request, &value_model, ENOENT ) );
    406406                                CHECK( 0, fd_dict_getval ( value_model, &request.search ) );
    407407                                CHECK( 0, fd_msg_avp_setvalue ( avpi, &request.search.enum_value ) );
     
    458458                               
    459459                                CHECK( 0, fd_msg_model ( avpi, &avp_model ) );
    460                                 CHECK( 0, fd_dict_search ( fd_g_dict, DICT_TYPE, TYPE_OF_AVP, avp_model, &type_model, ENOENT ) );
     460                                CHECK( 0, fd_dict_search ( fd_g_config->g_dict, DICT_TYPE, TYPE_OF_AVP, avp_model, &type_model, ENOENT ) );
    461461                                memset(&request, 0, sizeof(request));
    462462                                request.type_obj = type_model;
    463463                                request.search.enum_name = "os const test (waaad)";
    464                                 CHECK( 0, fd_dict_search ( fd_g_dict, DICT_ENUMVAL, ENUMVAL_BY_STRUCT, &request, &value_model, ENOENT ) );
     464                                CHECK( 0, fd_dict_search ( fd_g_config->g_dict, DICT_ENUMVAL, ENUMVAL_BY_STRUCT, &request, &value_model, ENOENT ) );
    465465                                CHECK( 0, fd_dict_getval ( value_model, &request.search ) );
    466466                                CHECK( 0, fd_msg_avp_setvalue ( avpi, &request.search.enum_value ) );
     
    483483                               
    484484                                CHECK( 0, fd_msg_model ( avpi, &avp_model ) );
    485                                 CHECK( 0, fd_dict_search ( fd_g_dict, DICT_TYPE, TYPE_OF_AVP, avp_model, &type_model, ENOENT ) );
     485                                CHECK( 0, fd_dict_search ( fd_g_config->g_dict, DICT_TYPE, TYPE_OF_AVP, avp_model, &type_model, ENOENT ) );
    486486                                memset(&request, 0, sizeof(request));
    487487                                request.type_obj = type_model;
    488488                                request.search.enum_name = "os const test (waa)";
    489                                 CHECK( 0, fd_dict_search ( fd_g_dict, DICT_ENUMVAL, ENUMVAL_BY_STRUCT, &request, &value_model, ENOENT ) );
     489                                CHECK( 0, fd_dict_search ( fd_g_config->g_dict, DICT_ENUMVAL, ENUMVAL_BY_STRUCT, &request, &value_model, ENOENT ) );
    490490                                CHECK( 0, fd_dict_getval ( value_model, &request.search ) );
    491491                                CHECK( 0, fd_msg_avp_setvalue ( avpi, &request.search.enum_value ) );
     
    654654                       
    655655                        /* Now find the ACR dictionary object */
    656                         CHECK( 0, fd_dict_search ( fd_g_dict, DICT_AVP, AVP_BY_NAME, "AVP Test - no vendor - f32", &avp_model, ENOENT ) );
     656                        CHECK( 0, fd_dict_search ( fd_g_config->g_dict, DICT_AVP, AVP_BY_NAME, "AVP Test - no vendor - f32", &avp_model, ENOENT ) );
    657657                       
    658658                        CPYBUF();
     
    680680                                buf_cpy[5] = 0x11;
    681681                                CHECK( 0, fd_msg_parse_buffer( &buf_cpy, 344, &msg) );
    682                                 CHECK( ENOTSUP, fd_msg_parse_dict( msg, fd_g_dict ) );
     682                                CHECK( ENOTSUP, fd_msg_parse_dict( msg, fd_g_config->g_dict ) );
    683683                               
    684684                                /* reset */
     
    695695                                /* Check that we cannot support this message now */
    696696                                CHECK( 0, fd_msg_parse_buffer( &buf_cpy, 344, &msg) );
    697                                 CHECK( ENOTSUP, fd_msg_parse_dict( msg, fd_g_dict ) );
     697                                CHECK( ENOTSUP, fd_msg_parse_dict( msg, fd_g_config->g_dict ) );
    698698                               
    699699                                /* reset */
     
    709709                                /* Check that we can support this message now */
    710710                                CHECK( 0, fd_msg_parse_buffer( &buf_cpy, 344, &msg) );
    711                                 CHECK( 0, fd_msg_parse_dict( msg, fd_g_dict ) );
     711                                CHECK( 0, fd_msg_parse_dict( msg, fd_g_config->g_dict ) );
    712712                               
    713713                                #if 0
     
    720720                       
    721721                        CHECK( 0, fd_msg_parse_buffer( &buf, 344, &msg) );
    722                         CHECK( 0, fd_msg_parse_dict( msg, fd_g_dict ) );
     722                        CHECK( 0, fd_msg_parse_dict( msg, fd_g_config->g_dict ) );
    723723                        #if 0
    724724                        fd_msg_dump_walk(0, msg);
     
    730730                        struct dict_object * rule;
    731731                       
    732                         CHECK( 0, fd_msg_parse_rules( msg, fd_g_dict, &rule ) );
     732                        CHECK( 0, fd_msg_parse_rules( msg, fd_g_config->g_dict, &rule ) );
    733733                       
    734734                        /* Use the "AVP Test - rules" AVP to test the rules */
     
    749749                               
    750750                                /* Check the message is still conform */
    751                                 CHECK( 0, fd_msg_parse_rules( msg, fd_g_dict, &rule ) );
     751                                CHECK( 0, fd_msg_parse_rules( msg, fd_g_config->g_dict, &rule ) );
    752752                               
    753753                                /* The first avp is optional in fixed position, so remove it and check the message is still OK */
    754754                                CHECK( 0, fd_msg_browse ( tavp, MSG_BRW_FIRST_CHILD, &childavp, NULL) );
    755755                                CHECK( 0, fd_msg_free ( childavp ) );
    756                                 CHECK( 0, fd_msg_parse_rules( msg, fd_g_dict, &rule ) );
     756                                CHECK( 0, fd_msg_parse_rules( msg, fd_g_config->g_dict, &rule ) );
    757757                                ADD_AVP( tavp, MSG_BRW_FIRST_CHILD, childavp,     0, "AVP Test - no vendor - f32" );
    758758                               
     
    761761                                #define CHECK_CONFLICT( _msg, _ruleavp, _avpvendor )            {                               \
    762762                                        struct dict_object * _rule;                                                             \
    763                                         CHECK( EBADMSG,  fd_msg_parse_rules( _msg, fd_g_dict, &_rule ) );                       \
     763                                        CHECK( EBADMSG,  fd_msg_parse_rules( _msg, fd_g_config->g_dict, &_rule ) );                     \
    764764                                        if ((_ruleavp) == NULL) {                                                               \
    765765                                                CHECK( NULL, _rule);                                                            \
     
    768768                                                struct dict_object *    _avp;                                                   \
    769769                                                struct dict_avp_request _req = { (_avpvendor), 0, (_ruleavp) };                 \
    770                                                 CHECK( 0, fd_dict_search( fd_g_dict, DICT_AVP, AVP_BY_NAME_AND_VENDOR, &_req, &_avp, ENOENT));  \
     770                                                CHECK( 0, fd_dict_search( fd_g_config->g_dict, DICT_AVP, AVP_BY_NAME_AND_VENDOR, &_req, &_avp, ENOENT));        \
    771771                                                CHECK( 0, fd_dict_getval( _rule, &_ruledata ) );                                \
    772772                                                CHECK( _avp, _ruledata.rule_avp );                                              \
     
    824824                                       
    825825                                        /* The message is still conform */
    826                                         CHECK( 0, fd_msg_parse_rules( msg, fd_g_dict, &rule ) );
     826                                        CHECK( 0, fd_msg_parse_rules( msg, fd_g_config->g_dict, &rule ) );
    827827                                       
    828828                                        /* Now break the rule */
     
    865865               
    866866                /* Find the CER dictionary object */
    867                 CHECK( 0, fd_dict_search ( fd_g_dict, DICT_COMMAND, CMD_BY_NAME, "Capabilities-Exchange-Request", &cer_model, ENOENT ) );
     867                CHECK( 0, fd_dict_search ( fd_g_config->g_dict, DICT_COMMAND, CMD_BY_NAME, "Capabilities-Exchange-Request", &cer_model, ENOENT ) );
    868868
    869869                /* Now find the Host-IP-Address dictionary object */
    870                 CHECK( 0, fd_dict_search ( fd_g_dict, DICT_AVP, AVP_BY_NAME, "Host-IP-Address", &hia_model, ENOENT ) );
     870                CHECK( 0, fd_dict_search ( fd_g_config->g_dict, DICT_AVP, AVP_BY_NAME, "Host-IP-Address", &hia_model, ENOENT ) );
    871871
    872872                /* Create the msg instance */
     
    945945                /* Ok, now let's recreate the message */
    946946                CHECK( 0, fd_msg_parse_buffer( &buf, 64, &cer) );
    947                 CHECK( 0, fd_msg_parse_dict( cer, fd_g_dict ) );
     947                CHECK( 0, fd_msg_parse_dict( cer, fd_g_config->g_dict ) );
    948948               
    949949                /* Get the pointers to the first and last AVP */
     
    972972                {
    973973                        struct dict_avp_data avp_data = { 91001, 0, "AVP Test 2 - os", 0, 0, AVP_TYPE_OCTETSTRING };
    974                         CHECK( 0, fd_dict_new ( fd_g_dict, DICT_AVP, &avp_data , NULL, NULL ) );
     974                        CHECK( 0, fd_dict_new ( fd_g_config->g_dict, DICT_AVP, &avp_data , NULL, NULL ) );
    975975                }
    976976                {
    977977                        struct dict_avp_data avp_data = { 91002, 0, "AVP Test 2 - i32", 0, 0, AVP_TYPE_INTEGER32 };
    978                         CHECK( 0, fd_dict_new ( fd_g_dict, DICT_AVP, &avp_data , NULL, NULL ) );
     978                        CHECK( 0, fd_dict_new ( fd_g_config->g_dict, DICT_AVP, &avp_data , NULL, NULL ) );
    979979                }
    980980                {
    981981                        struct dict_avp_data avp_data = { 91003, 0, "AVP Test 2 - i64", 0, 0, AVP_TYPE_INTEGER64 };
    982                         CHECK( 0, fd_dict_new ( fd_g_dict, DICT_AVP, &avp_data , NULL, NULL ) );
     982                        CHECK( 0, fd_dict_new ( fd_g_config->g_dict, DICT_AVP, &avp_data , NULL, NULL ) );
    983983                }
    984984                {
    985985                        struct dict_avp_data avp_data = { 91004, 0, "AVP Test 2 - u32", 0, 0, AVP_TYPE_UNSIGNED32 };
    986                         CHECK( 0, fd_dict_new ( fd_g_dict, DICT_AVP, &avp_data , NULL, NULL ) );
     986                        CHECK( 0, fd_dict_new ( fd_g_config->g_dict, DICT_AVP, &avp_data , NULL, NULL ) );
    987987                }
    988988                {
    989989                        struct dict_avp_data avp_data = { 91005, 0, "AVP Test 2 - u64", 0, 0, AVP_TYPE_UNSIGNED64 };
    990                         CHECK( 0, fd_dict_new ( fd_g_dict, DICT_AVP, &avp_data , NULL, NULL ) );
     990                        CHECK( 0, fd_dict_new ( fd_g_config->g_dict, DICT_AVP, &avp_data , NULL, NULL ) );
    991991                }
    992992                {
    993993                        struct dict_avp_data avp_data = { 91006, 0, "AVP Test 2 - f32", 0, 0, AVP_TYPE_FLOAT32 };
    994                         CHECK( 0, fd_dict_new ( fd_g_dict, DICT_AVP, &avp_data , NULL, NULL ) );
     994                        CHECK( 0, fd_dict_new ( fd_g_config->g_dict, DICT_AVP, &avp_data , NULL, NULL ) );
    995995                }
    996996                {
    997997                        struct dict_avp_data avp_data = { 91007, 0, "AVP Test 2 - f64", 0, 0, AVP_TYPE_FLOAT64 };
    998                         CHECK( 0, fd_dict_new ( fd_g_dict, DICT_AVP, &avp_data , NULL, NULL ) );
     998                        CHECK( 0, fd_dict_new ( fd_g_config->g_dict, DICT_AVP, &avp_data , NULL, NULL ) );
    999999                }
    10001000               
     
    10101010                        struct msg_hdr     * msgdata = NULL;
    10111011
    1012                         CHECK( 0, fd_dict_search ( fd_g_dict, DICT_COMMAND, CMD_BY_NAME, "Test-Command-Request", &cmd_model, ENOENT ) );
     1012                        CHECK( 0, fd_dict_search ( fd_g_config->g_dict, DICT_COMMAND, CMD_BY_NAME, "Test-Command-Request", &cmd_model, ENOENT ) );
    10131013
    10141014                        /* Create a message */
     
    11751175                       
    11761176                        CHECK( 0, fd_msg_parse_buffer( &buf, 148, &msg) );
    1177                         CHECK( 0, fd_msg_parse_dict( msg, fd_g_dict ) );
     1177                        CHECK( 0, fd_msg_parse_dict( msg, fd_g_config->g_dict ) );
    11781178                        #if 0
    11791179                        fd_msg_dump_walk(0, msg);
  • freeDiameter/tests/testqueues.c

    r1 r8  
    3838/* Structure for testing threshold function */
    3939static struct thrh_test {
    40         struct mqueue * queue; /* pointer to the queue */
     40        struct fifo *  queue; /* pointer to the queue */
    4141        int             h_calls; /* number of calls of h_cb */
    4242        int             l_calls; /* number of calls of l_cb */
     
    4444
    4545/* Callbacks for threasholds test */
    46 void thrh_cb_h(struct mqueue *queue, void **data)
     46void thrh_cb_h(struct fifo *queue, void **data)
    4747{
    4848        if (thrh_td.h_calls == thrh_td.l_calls) {
     
    5757        thrh_td.h_calls ++;
    5858}
    59 void thrh_cb_l(struct mqueue *queue, void **data)
     59void thrh_cb_l(struct fifo *queue, void **data)
    6060{
    6161        CHECK( 1, data ? 1 : 0 );
     
    7676/* Structure that is passed to the test function */
    7777struct test_data {
    78         struct mqueue     * queue; /* pointer to the queue */
     78        struct fifo     * queue; /* pointer to the queue */
    7979        pthread_barrier_t * bar;   /* if not NULL, barrier to synchronize before getting messages */
    8080        struct timespec   * ts;    /* if not NULL, use a timedget instead of a get */
     
    100100        for (i=0; i< td->nbr; i++) {
    101101                if (td->ts != NULL) {
    102                         CHECK( 0, fd_mq_timedget(td->queue, &msg, td->ts) );
     102                        CHECK( 0, fd_fifo_timedget(td->queue, &msg, td->ts) );
    103103                } else {
    104                         CHECK( 0, fd_mq_get(td->queue, &msg) );
     104                        CHECK( 0, fd_fifo_get(td->queue, &msg) );
    105105                }
    106106        }
     
    128128                struct dict_object * dwr_model = NULL;
    129129
    130                 CHECK( 0, fd_dict_search ( fd_g_dict, DICT_COMMAND, CMD_BY_NAME, "Accounting-Request",                  &acr_model, ENOENT ) );
    131                 CHECK( 0, fd_dict_search ( fd_g_dict, DICT_COMMAND, CMD_BY_NAME, "Capabilities-Exchange-Request",       &cer_model, ENOENT ) );
    132                 CHECK( 0, fd_dict_search ( fd_g_dict, DICT_COMMAND, CMD_BY_NAME, "Device-Watchdog-Request",             &dwr_model, ENOENT ) );
     130                CHECK( 0, fd_dict_search ( fd_g_config->g_dict, DICT_COMMAND, CMD_BY_NAME, "Accounting-Request",                        &acr_model, ENOENT ) );
     131                CHECK( 0, fd_dict_search ( fd_g_config->g_dict, DICT_COMMAND, CMD_BY_NAME, "Capabilities-Exchange-Request",     &cer_model, ENOENT ) );
     132                CHECK( 0, fd_dict_search ( fd_g_config->g_dict, DICT_COMMAND, CMD_BY_NAME, "Device-Watchdog-Request",           &dwr_model, ENOENT ) );
    133133                CHECK( 0, fd_msg_new ( acr_model, 0, &msg1 ) );
    134134                CHECK( 0, fd_msg_new ( cer_model, 0, &msg2 ) );
     
    138138        /* Basic operation */
    139139        {
    140                 struct mqueue * queue = NULL;
     140                struct fifo * queue = NULL;
    141141                int count;
    142142                struct msg * msg  = NULL;
    143143               
    144144                /* Create the queue */
    145                 CHECK( 0, fd_mq_new(&queue) );
     145                CHECK( 0, fd_fifo_new(&queue) );
    146146               
    147147                /* Check the count is 0 */
    148                 CHECK( 0, fd_mq_length(queue, &count) );
     148                CHECK( 0, fd_fifo_length(queue, &count) );
    149149                CHECK( 0, count);
    150150               
    151151                /* Now enqueue */
    152152                msg = msg1;
    153                 CHECK( 0, fd_mq_post(queue, &msg) );
     153                CHECK( 0, fd_fifo_post(queue, &msg) );
    154154                msg = msg2;
    155                 CHECK( 0, fd_mq_post(queue, &msg) );
     155                CHECK( 0, fd_fifo_post(queue, &msg) );
    156156                msg = msg3;
    157                 CHECK( 0, fd_mq_post(queue, &msg) );
     157                CHECK( 0, fd_fifo_post(queue, &msg) );
    158158               
    159159                /* Check the count is 3 */
    160                 CHECK( 0, fd_mq_length(queue, &count) );
     160                CHECK( 0, fd_fifo_length(queue, &count) );
    161161                CHECK( 3, count);
    162162               
    163                 /* Retrieve the first message using fd_mq_get */
    164                 CHECK( 0, fd_mq_get(queue, &msg) );
     163                /* Retrieve the first message using fd_fifo_get */
     164                CHECK( 0, fd_fifo_get(queue, &msg) );
    165165                CHECK( msg1, msg);
    166                 CHECK( 0, fd_mq_length(queue, &count) );
     166                CHECK( 0, fd_fifo_length(queue, &count) );
    167167                CHECK( 2, count);
    168168               
    169                 /* Retrieve the second message using fd_mq_timedget */
     169                /* Retrieve the second message using fd_fifo_timedget */
    170170                CHECK(0, clock_gettime(CLOCK_REALTIME, &ts));
    171171                ts.tv_sec += 1; /* Set the timeout to 1 second */
    172                 CHECK( 0, fd_mq_timedget(queue, &msg, &ts) );
     172                CHECK( 0, fd_fifo_timedget(queue, &msg, &ts) );
    173173                CHECK( msg2, msg);
    174                 CHECK( 0, fd_mq_length(queue, &count) );
     174                CHECK( 0, fd_fifo_length(queue, &count) );
    175175                CHECK( 1, count);
    176176               
    177177                /* Retrieve the third message using meq_tryget */
    178                 CHECK( 0, fd_mq_tryget(queue, &msg) );
     178                CHECK( 0, fd_fifo_tryget(queue, &msg) );
    179179                CHECK( msg3, msg);
    180                 CHECK( 0, fd_mq_length(queue, &count) );
     180                CHECK( 0, fd_fifo_length(queue, &count) );
    181181                CHECK( 0, count);
    182182               
    183183                /* Check that another meq_tryget does not block */
    184                 CHECK( EWOULDBLOCK, fd_mq_tryget(queue, &msg) );
    185                 CHECK( 0, fd_mq_length(queue, &count) );
     184                CHECK( EWOULDBLOCK, fd_fifo_tryget(queue, &msg) );
     185                CHECK( 0, fd_fifo_length(queue, &count) );
    186186                CHECK( 0, count);
    187187               
    188188                /* We're done for basic tests */
    189                 CHECK( 0, fd_mq_del(&queue) );
     189                CHECK( 0, fd_fifo_del(&queue) );
    190190        }
    191191       
     
    194194#define NBR_MSG         200
    195195#define NBR_THREADS     60
    196                 struct mqueue           *queue = NULL;
     196                struct fifo             *queue = NULL;
    197197                pthread_barrier_t        bar;
    198198                struct test_data         td_1;
     
    205205               
    206206                /* Create the queue */
    207                 CHECK( 0, fd_mq_new(&queue) );
     207                CHECK( 0, fd_fifo_new(&queue) );
    208208               
    209209                /* Create the barrier */
     
    215215               
    216216                /* Create the messages */
    217                 CHECK( 0, fd_dict_search ( fd_g_dict, DICT_COMMAND, CMD_BY_NAME, "Device-Watchdog-Request",             &dwr_model, ENOENT ) );
     217                CHECK( 0, fd_dict_search ( fd_g_config->g_dict, DICT_COMMAND, CMD_BY_NAME, "Device-Watchdog-Request",           &dwr_model, ENOENT ) );
    218218                for (i = 0; i < NBR_MSG * NBR_THREADS * 2; i++) {
    219219                        CHECK( 0, fd_msg_new ( dwr_model, 0, &msgs[i] ) );
     
    248248                for (i=0; i < NBR_MSG * NBR_THREADS * 2; i++) {
    249249                        msg = msgs[i];
    250                         CHECK( 0, fd_mq_post(queue, &msg) );
     250                        CHECK( 0, fd_fifo_post(queue, &msg) );
    251251                }
    252252               
     
    257257               
    258258                /* Check the count of the queue is back to 0 */
    259                 CHECK( 0, fd_mq_length(queue, &count) );
     259                CHECK( 0, fd_fifo_length(queue, &count) );
    260260                CHECK( 0, count);
    261261               
    262262                /* Destroy this queue and the messages */
    263                 CHECK( 0, fd_mq_del(&queue) );
     263                CHECK( 0, fd_fifo_del(&queue) );
    264264                for (i=0; i < NBR_MSG * NBR_THREADS * 2; i++) {
    265265                        CHECK( 0, fd_msg_free(  msgs[i] ) );
     
    269269        /* Test thread cancelation */
    270270        {
    271                 struct mqueue           *queue = NULL;
     271                struct fifo             *queue = NULL;
    272272                pthread_barrier_t        bar;
    273273                struct test_data         td;
     
    275275               
    276276                /* Create the queue */
    277                 CHECK( 0, fd_mq_new(&queue) );
     277                CHECK( 0, fd_fifo_new(&queue) );
    278278               
    279279                /* Create the barrier */
     
    332332               
    333333                /* Destroy the queue */
    334                 CHECK( 0, fd_mq_del(&queue) );
     334                CHECK( 0, fd_fifo_del(&queue) );
    335335        }
    336336       
    337337        /* Test the threashold function */
    338338        {
    339                 struct mqueue * queue = NULL;
     339                struct fifo * queue = NULL;
    340340                int i;
    341341                struct msg * msg  = NULL;
    342342               
    343343                /* Create the queue */
    344                 CHECK( 0, fd_mq_new(&queue) );
     344                CHECK( 0, fd_fifo_new(&queue) );
    345345               
    346346                /* Prepare the test data */
     
    349349               
    350350                /* Set the thresholds for the queue */
    351                 CHECK( 0, fd_mq_setthrhd ( queue, NULL, 6, thrh_cb_h, 4, thrh_cb_l ) );
     351                CHECK( 0, fd_fifo_setthrhd ( queue, NULL, 6, thrh_cb_h, 4, thrh_cb_l ) );
    352352               
    353353                /* Post 5 messages, no cb must be called. */
    354354                for (i=0; i<5; i++) {
    355355                        msg = msg1;
    356                         CHECK( 0, fd_mq_post(queue, &msg) );
     356                        CHECK( 0, fd_fifo_post(queue, &msg) );
    357357                } /* 5 msg in queue */
    358358                CHECK( 0, thrh_td.h_calls );
     
    361361                /* Get all these messages, and check again */
    362362                for (i=0; i<5; i++) {
    363                         CHECK( 0, fd_mq_get(queue, &msg) );
     363                        CHECK( 0, fd_fifo_get(queue, &msg) );
    364364                } /* 0 msg in queue */
    365365                CHECK( 0, thrh_td.h_calls );
     
    369369                for (i=0; i<6; i++) {
    370370                        msg = msg1;
    371                         CHECK( 0, fd_mq_post(queue, &msg) );
     371                        CHECK( 0, fd_fifo_post(queue, &msg) );
    372372                } /* 6 msg in queue */
    373373                CHECK( 1, thrh_td.h_calls );
     
    376376                /* Remove 2 messages, to reach the low threshold */
    377377                for (i=0; i<2; i++) {
    378                         CHECK( 0, fd_mq_get(queue, &msg) );
     378                        CHECK( 0, fd_fifo_get(queue, &msg) );
    379379                } /* 4 msg in queue */
    380380                CHECK( 1, thrh_td.h_calls );
     
    384384                for (i=0; i<2; i++) {
    385385                        msg = msg1;
    386                         CHECK( 0, fd_mq_post(queue, &msg) );
     386                        CHECK( 0, fd_fifo_post(queue, &msg) );
    387387                } /* 6 msg in queue */
    388388                CHECK( 2, thrh_td.h_calls );
     
    392392                for (i=0; i<6; i++) {
    393393                        msg = msg1;
    394                         CHECK( 0, fd_mq_post(queue, &msg) );
     394                        CHECK( 0, fd_fifo_post(queue, &msg) );
    395395                } /* 12 msg in queue */
    396396                CHECK( 3, thrh_td.h_calls );
     
    398398                for (i=0; i<5; i++) {
    399399                        msg = msg1;
    400                         CHECK( 0, fd_mq_post(queue, &msg) );
     400                        CHECK( 0, fd_fifo_post(queue, &msg) );
    401401                } /* 17 msg in queue */
    402402                CHECK( 3, thrh_td.h_calls );
     
    405405                /* Now the queue goes back to 0 messages */
    406406                for (i=0; i<17; i++) {
    407                         CHECK( 0, fd_mq_get(queue, &msg) );
     407                        CHECK( 0, fd_fifo_get(queue, &msg) );
    408408                } /* 0 msg in queue */
    409409                CHECK( 3, thrh_td.h_calls );
     
    411411               
    412412                /* We're done for this test */
    413                 CHECK( 0, fd_mq_del(&queue) );
     413                CHECK( 0, fd_fifo_del(&queue) );
    414414        }
    415415       
  • freeDiameter/tests/tests.h

    r3 r8  
    7575
    7676static int test_verbo = 0;
     77static struct fd_config conf;
     78struct fd_config * fd_g_config = &conf;
    7779
    7880/* Define the standard check routines */
     
    9799
    98100/* Minimum inits */
    99 #define INIT_FD() {                                     \
    100         CHECK( 0, fd_lib_init() );                      \
    101         fd_log_threadname(basename(__FILE__));          \
    102         CHECK( 0, fd_dict_init(&fd_g_dict) );           \
    103         CHECK( 0, fd_dict_base_protocol(fd_g_dict) );   \
    104         parse_cmdline(argc, argv);                      \
     101#define INIT_FD() {                                             \
     102        memset(fd_g_config, 0, sizeof(struct fd_config));       \
     103        CHECK( 0, fd_lib_init() );                              \
     104        fd_log_threadname(basename(__FILE__));                  \
     105        CHECK( 0, fd_conf_init() );                             \
     106        CHECK( 0, fd_dict_base_protocol(fd_g_config->g_dict) ); \
     107        parse_cmdline(argc, argv);                              \
    105108}
    106109
  • include/freeDiameter/CMakeLists.txt

    r1 r8  
    7272CHECK_INCLUDE_FILES (malloc.h HAVE_MALLOC_H)
    7373
     74# signalent.h ? -- found in strace distrib; just for nice signal names...
     75CHECK_INCLUDE_FILES (signalent.h HAVE_SIGNALENT_H)
     76
    7477# The default configuration file name
    7578IF (NOT DEFAULT_CONF_FILE)
  • include/freeDiameter/freeDiameter-host.h.in

    r1 r8  
    4040#cmakedefine HAVE_NTOHLL
    4141#cmakedefine HAVE_MALLOC_H
     42#cmakedefine HAVE_SIGNALENT_H
    4243
    4344#cmakedefine HOST_BIG_ENDIAN @HOST_BIG_ENDIAN@
     
    4546#cmakedefine DISABLE_SCTP
    4647
    47 #cmakedefine PROJECT_NAME "@PROJECT_NAME@"
    48 #cmakedefine CMAKE_PROJECT_NAME "@CMAKE_PROJECT_NAME@"
    49 #cmakedefine PROJECT_VERSION "@PROJECT_VERSION@"
    50 #cmakedefine PROJECT_COPYRIGHT "@PROJECT_COPYRIGHT@"
     48#cmakedefine FD_PROJECT_BINARY "@FD_PROJECT_BINARY@"
     49#cmakedefine FD_PROJECT_NAME "@FD_PROJECT_NAME@"
     50#cmakedefine FD_PROJECT_VERSION_MAJOR @FD_PROJECT_VERSION_MAJOR@
     51#ifndef FD_PROJECT_VERSION_MAJOR
     52# define FD_PROJECT_VERSION_MAJOR 0
     53#endif /*FD_PROJECT_VERSION_MAJOR*/
     54#cmakedefine FD_PROJECT_VERSION_MINOR @FD_PROJECT_VERSION_MINOR@
     55#ifndef FD_PROJECT_VERSION_MINOR
     56# define FD_PROJECT_VERSION_MINOR 0
     57#endif /*FD_PROJECT_VERSION_MINOR*/
     58#cmakedefine FD_PROJECT_VERSION_REV   @FD_PROJECT_VERSION_REV@
     59#ifndef FD_PROJECT_VERSION_REV
     60# define FD_PROJECT_VERSION_REV 0
     61#endif /*FD_PROJECT_VERSION_REV*/
     62/* HG_VERSION */
     63/* PACKAGE_HG_REVISION */
     64#cmakedefine FD_PROJECT_COPYRIGHT "@FD_PROJECT_COPYRIGHT@"
    5165
    5266#cmakedefine DEFAULT_CONF_FILE "@DEFAULT_CONF_FILE@"
    5367
     68
    5469#endif /* FD_IS_CONFIG */
  • include/freeDiameter/freeDiameter.h

    r7 r8  
    4141
    4242
    43 /* The global dictionary */
    44 extern struct dictionary * fd_g_dict;
    45 
     43/* Structure to hold the configuration of the freeDiameter daemon */
     44struct fd_config {
     45        int              eyec;          /* Eye catcher: EYEC_CONFIG */
     46        char            *conf_file;     /* Configuration file to parse, default is DEFAULT_CONF_FILE */
     47       
     48        char            *diam_id;       /* Diameter Identity of the local peer (FQDN -- UTF-8) */
     49        size_t           diam_id_len;   /* length of the previous string */
     50        char            *diam_realm;    /* Diameter realm of the local peer, default to realm part of diam_id */
     51        size_t           diam_realm_len;/* length of the previous string */
     52       
     53        uint16_t         loc_port;      /* the local port for legacy Diameter (default: 3868) in host byte order */
     54        uint16_t         loc_port_tls;  /* the local port for Diameter/TLS (default: 3869) in host byte order */
     55        uint16_t         loc_sctp_str;  /* default max number of streams for SCTP associations (def: 30) */
     56        struct fd_list   loc_endpoints; /* the local endpoints to bind the server to. list of struct fd_endpoint. default is empty (bind all) */
     57        struct {
     58                unsigned no_ip4 : 1;    /* disable IP */
     59                unsigned no_ip6 : 1;    /* disable IPv6 */
     60                unsigned no_tcp : 1;    /* disable use of TCP */
     61                unsigned no_sctp: 1;    /* disable the use of SCTP */
     62                unsigned pr_tcp : 1;    /* prefer TCP over SCTP */
     63                unsigned tls_alg: 1;    /* TLS algorithm for initiated cnx. 0: separate port. 1: inband-security (old) */
     64                unsigned no_fwd : 1;    /* the peer does not relay messages (0xffffff app id) */
     65        }                flags;
     66       
     67        unsigned int     timer_tc;      /* The value in seconds of the default Tc timer */
     68        unsigned int     timer_tw;      /* The value in seconds of the default Tw timer */
     69       
     70        uint32_t         or_state_id;   /* The value to use in Origin-State-Id, default to random value */
     71        struct dictionary *g_dict;      /* pointer to the global dictionary */
     72        struct fifo       *g_fifo_main; /* FIFO queue of events in the daemon main (struct fd_event items) */
     73};
     74
     75#define EYEC_CONFIG     0xC011F16
     76
     77/* The pointer to access the global configuration, initalized in main */
     78extern struct fd_config *fd_g_config;
     79
     80/* Endpoints */
     81struct fd_endpoint {
     82        struct fd_list  chain;  /* link in loc_endpoints list */
     83        sSS             ss;     /* the socket information. */
     84};
     85
     86/* Events */
     87struct fd_event {
     88        int      code; /* codespace depends on the queue */
     89        void    *data;
     90};
     91
     92/* send an event */
     93static __inline__ int fd_event_send(struct fifo *queue, int code, void * data)
     94{
     95        struct fd_event * ev;
     96        CHECK_MALLOC( ev = malloc(sizeof(struct fd_event)) );
     97        ev->code = code;
     98        ev->data = data;
     99        CHECK_FCT( fd_fifo_post(queue, &ev) );
     100        return 0;
     101}
     102/* receive an event */
     103static __inline__ int fd_event_get(struct fifo *queue, int *code, void ** data)
     104{
     105        struct fd_event * ev;
     106        CHECK_FCT( fd_fifo_get(queue, &ev) );
     107        if (code)
     108                *code = ev->code;
     109        if (data)
     110                *data = ev->data;
     111        free(ev);
     112        return 0;
     113}
    46114
    47115/***************************************/
  • include/freeDiameter/libfreeDiameter.h

    r7 r8  
    3737 *
    3838 * This library is meant to be used by both the freeDiameter daemon and its extensions.
    39  *
    4039 * It provides the tools to manipulate Diameter messages and related data.
    41  *
    4240 * This file should always be included as #include <freeDiameter/libfreeDiameter.h>
     41 *
     42 * The file contains the following parts:
     43 *      DEBUG
     44 *      MACROS
     45 *      THREADS
     46 *      LISTS
     47 *      DICTIONARY
     48 *      SESSIONS
     49 *      MESSAGES
     50 *      DISPATCH
     51 *      QUEUES
    4352 */
    4453
     
    297306#define sSA6    struct sockaddr_in6
    298307
    299 /* Dump one sockaddr */
    300 #define sSA_DUMP( level, text, sa ) {                           \
     308/* Dump one sockaddr Node information */
     309#define sSA_DUMP_NODE( sa, flag ) {                             \
    301310        sSA * __sa = (sSA *)(sa);                               \
    302         char *__str, __addrbuf[INET6_ADDRSTRLEN];               \
     311        char __addrbuf[INET6_ADDRSTRLEN];                       \
    303312        if (__sa) {                                             \
    304313          int __rc = getnameinfo(__sa,                          \
     
    308317                        NULL,                                   \
    309318                        0,                                      \
    310                         0);                                     \
     319                        flag);                                  \
    311320          if (__rc)                                             \
    312                 __str = (char *)gai_strerror(__rc);             \
     321                fd_log_debug((char *)gai_strerror(__rc));       \
    313322          else                                                  \
    314                 __str = &__addrbuf[0];                          \
     323                fd_log_debug(&__addrbuf[0]);                    \
    315324        } else {                                                \
    316                 __str = "(NULL / ANY)";                         \
     325                fd_log_debug("(NULL / ANY)");                   \
    317326        }                                                       \
    318         TRACE_DEBUG(level, text "%s", __str);                   \
    319327}
     328/* if needed, add sSA_DUMP_SERVICE */
    320329
    321330/* The sockaddr length of a sSS structure */
     
    22752284
    22762285/*============================================================*/
    2277 /*                    MESSAGE QUEUES                          */
     2286/*                     QUEUES                                 */
    22782287/*============================================================*/
    22792288
    2280 /* Management of queues of messages */
    2281 
    2282 /* A message queue is an opaque object */
    2283 struct mqueue;
    2284 
    2285 /*
    2286  * FUNCTION:    fd_mq_new
    2287  *
    2288  * PARAMETERS:
    2289  *  queue       : Upon success, a pointer to the new message queue is saved here.
    2290  *
    2291  * DESCRIPTION:
    2292  *  Create a new empty message queue.
     2289/* Management of FIFO queues of elements */
     2290
     2291/* A queue is an opaque object */
     2292struct fifo;
     2293
     2294/*
     2295 * FUNCTION:    fd_fifo_new
     2296 *
     2297 * PARAMETERS:
     2298 *  queue       : Upon success, a pointer to the new queue is saved here.
     2299 *
     2300 * DESCRIPTION:
     2301 *  Create a new empty queue.
    22932302 *
    22942303 * RETURN VALUE :
    2295  *  0           : The message queue has been initialized successfully.
     2304 *  0           : The queue has been initialized successfully.
    22962305 *  EINVAL      : The parameter is invalid.
    22972306 *  ENOMEM      : Not enough memory to complete the creation. 
    22982307 */
    2299 int fd_mq_new ( struct mqueue ** queue );
    2300 
    2301 /*
    2302  * FUNCTION:    fd_mq_del
    2303  *
    2304  * PARAMETERS:
    2305  *  queue       : Pointer to an empty message queue to delete.
    2306  *
    2307  * DESCRIPTION:
    2308  *  Destroys a message queue. This is only possible if no thread is waiting for a message,
     2308int fd_fifo_new ( struct fifo ** queue );
     2309
     2310/*
     2311 * FUNCTION:    fd_fifo_del
     2312 *
     2313 * PARAMETERS:
     2314 *  queue       : Pointer to an empty queue to delete.
     2315 *
     2316 * DESCRIPTION:
     2317 *  Destroys a queue. This is only possible if no thread is waiting for an element,
    23092318 * and the queue is empty.
    23102319 *
    23112320 * RETURN VALUE:
    2312  *  0           : The message queue has been destroyed successfully.
     2321 *  0           : The queue has been destroyed successfully.
    23132322 *  EINVAL      : The parameter is invalid.
    23142323 */
    2315 int fd_mq_del ( struct mqueue  ** queue );
    2316 
    2317 /*
    2318  * FUNCTION:    fd_mq_length
    2319  *
    2320  * PARAMETERS:
    2321  *  queue       : The queue from which to retrieve the length.
    2322  *  length      : Upon success, the current number of messages in the queue is stored here.
    2323  *
    2324  * DESCRIPTION:
    2325  *  Retrieve the number of messages pending in a queue.
     2324int fd_fifo_del ( struct fifo  ** queue );
     2325
     2326/*
     2327 * FUNCTION:    fd_fifo_length
     2328 *
     2329 * PARAMETERS:
     2330 *  queue       : The queue from which to retrieve the number of elements.
     2331 *  length      : Upon success, the current number of elements in the queue is stored here.
     2332 *
     2333 * DESCRIPTION:
     2334 *  Retrieve the number of elements in a queue.
    23262335 *
    23272336 * RETURN VALUE:
     
    23292338 *  EINVAL      : A parameter is invalid.
    23302339 */
    2331 int fd_mq_length ( struct mqueue * queue, int * length );
    2332 int fd_mq_length_noerr ( struct mqueue * queue ); /* alternate with no error checking */
    2333 
    2334 /*
    2335  * FUNCTION:    fd_mq_setthrhd
     2340int fd_fifo_length ( struct fifo * queue, int * length );
     2341int fd_fifo_length_noerr ( struct fifo * queue ); /* no error checking version */
     2342
     2343/*
     2344 * FUNCTION:    fd_fifo_setthrhd
    23362345 *
    23372346 * PARAMETERS:
     
    23452354 * DESCRIPTION:
    23462355 *  This function allows to adjust the number of producer / consumer threads of a queue.
    2347  * If the consumer are slower than the producers, the number of messages in the queue increase.
     2356 * If the consumer are slower than the producers, the number of elements in the queue increase.
    23482357 * By setting a "high" value, we allow a callback to be called when this number is too high.
    23492358 * The typical use would be to create an additional consumer thread in this callback.
    23502359 * If the queue continues to grow, the callback will be called again when the length is 2 * high, then 3*high, ... N * high
    2351  * (the callback itself may implement a limit on the number of consumers that can be created)
     2360 * (the callback itself should implement a limit on the number of consumers that can be created)
    23522361 * When the queue starts to decrease, and the number of elements go under ((N - 1) * high + low, the l_cb callback is called
    2353  * and would typially stop one of the consumer threads. If the queue continue to reduce, l_cb is again called at (N-2)*high + low,
     2362 * and would typially stop one of the consumer threads. If the queue continues to reduce, l_cb is again called at (N-2)*high + low,
    23542363 * and so on.
    23552364 *
     
    23572366 * l_cb when the length of the queue is becoming < low.
    23582367 *
    2359  * Note that the callbacks are called synchronously, during fd_mq_post or fd_mq_get. Their operation should be quick.
     2368 * Note that the callbacks are called synchronously, during fd_fifo_post or fd_fifo_get. Their operation should be quick.
    23602369 *
    23612370 * RETURN VALUE:
     
    23632372 *  EINVAL      : A parameter is invalid.
    23642373 */
    2365 int fd_mq_setthrhd ( struct mqueue * queue, void * data, uint16_t high, void (*h_cb)(struct mqueue *, void **), uint16_t low, void (*l_cb)(struct mqueue *, void **) );
    2366 
    2367 /*
    2368  * FUNCTION:    fd_mq_post
    2369  *
    2370  * PARAMETERS:
    2371  *  queue       : The queue in which the message must be posted.
    2372  *  msg         : The message that is put in the queue.
    2373  *
    2374  * DESCRIPTION:
    2375  *  A message is added in a queue. Messages are retrieved from the queue (in FIFO order)
    2376  *  with the fd_mq_get, fd_mq_tryget, or fd_mq_timedget functions.
    2377  *
    2378  * RETURN VALUE:
    2379  *  0           : The message is queued.
     2374int fd_fifo_setthrhd ( struct fifo * queue, void * data, uint16_t high, void (*h_cb)(struct fifo *, void **), uint16_t low, void (*l_cb)(struct fifo *, void **) );
     2375
     2376/*
     2377 * FUNCTION:    fd_fifo_post
     2378 *
     2379 * PARAMETERS:
     2380 *  queue       : The queue in which the element must be posted.
     2381 *  item        : The element that is put in the queue.
     2382 *
     2383 * DESCRIPTION:
     2384 *  An element is added in a queue. Elements are retrieved from the queue in FIFO order
     2385 *  with the fd_fifo_get, fd_fifo_tryget, or fd_fifo_timedget functions.
     2386 *
     2387 * RETURN VALUE:
     2388 *  0           : The element is queued.
    23802389 *  EINVAL      : A parameter is invalid.
    23812390 *  ENOMEM      : Not enough memory to complete the operation.
    23822391 */
    2383 int fd_mq_post ( struct mqueue * queue, struct msg ** msg );
    2384 
    2385 /*
    2386  * FUNCTION:    fd_mq_get
    2387  *
    2388  * PARAMETERS:
    2389  *  queue       : The queue from which the message must be retrieved.
    2390  *  msg         : On return, the first message of the queue is stored here.
    2391  *
    2392  * DESCRIPTION:
    2393  *  This function retrieves a message from a queue. If the queue is empty, the function will block the
    2394  * thread until a new message is posted to the queue, or until the thread is canceled (in which case the
     2392int fd_fifo_post_int ( struct fifo * queue, void ** item );
     2393#define fd_fifo_post(queue, item) \
     2394        fd_fifo_post_int((queue), (void *)(item))
     2395
     2396/*
     2397 * FUNCTION:    fd_fifo_get
     2398 *
     2399 * PARAMETERS:
     2400 *  queue       : The queue from which the first element must be retrieved.
     2401 *  item        : On return, the first element of the queue is stored here.
     2402 *
     2403 * DESCRIPTION:
     2404 *  This function retrieves the first element from a queue. If the queue is empty, the function will block the
     2405 * thread until a new element is posted to the queue, or until the thread is canceled (in which case the
    23952406 * function does not return).
    23962407 *
    23972408 * RETURN VALUE:
    2398  *  0           : A new message has been retrieved.
    2399  *  EINVAL      : A parameter is invalid.
    2400  */
    2401 int fd_mq_get ( struct mqueue * queue, struct msg ** msg );
    2402 
    2403 /*
    2404  * FUNCTION:    fd_mq_tryget
    2405  *
    2406  * PARAMETERS:
    2407  *  queue       : The queue from which the message must be retrieved.
     2409 *  0           : A new element has been retrieved.
     2410 *  EINVAL      : A parameter is invalid.
     2411 */
     2412int fd_fifo_get_int ( struct fifo * queue, void ** item );
     2413#define fd_fifo_get(queue, item) \
     2414        fd_fifo_get_int((queue), (void *)(item))
     2415
     2416/*
     2417 * FUNCTION:    fd_fifo_tryget
     2418 *
     2419 * PARAMETERS:
     2420 *  queue       : The queue from which the element must be retrieved.
    24082421 *  msg         : On return, the message is stored here.
    24092422 *
    24102423 * DESCRIPTION:
    2411  *  This function is similar to fd_mq_get, except that it will not block if
     2424 *  This function is similar to fd_fifo_get, except that it will not block if
    24122425 * the queue is empty, but return EWOULDBLOCK instead.
    24132426 *
    24142427 * RETURN VALUE:
    2415  *  0           : A new message has been retrieved.
     2428 *  0           : A new element has been retrieved.
    24162429 *  EINVAL      : A parameter is invalid.
    24172430 *  EWOULDBLOCK : The queue was empty.
    24182431 */
    2419 int fd_mq_tryget ( struct mqueue * queue, struct msg ** msg );
    2420 
    2421 /*
    2422  * FUNCTION:    fd_mq_timedget
    2423  *
    2424  * PARAMETERS:
    2425  *  queue       : The queue from which the message must be retrieved.
    2426  *  msg         : On return, the message is stored here.
    2427  *  abstime     : the absolute time until which we allow waiting for a message.
    2428  *
    2429  * DESCRIPTION:
    2430  *  This function is similar to fd_mq_get, except that it will block if the queue is empty
     2432int fd_fifo_tryget_int ( struct fifo * queue, void ** item );
     2433#define fd_fifo_tryget(queue, item) \
     2434        fd_fifo_tryget_int((queue), (void *)(item))
     2435
     2436/*
     2437 * FUNCTION:    fd_fifo_timedget
     2438 *
     2439 * PARAMETERS:
     2440 *  queue       : The queue from which the element must be retrieved.
     2441 *  item        : On return, the element is stored here.
     2442 *  abstime     : the absolute time until which we allow waiting for an item.
     2443 *
     2444 * DESCRIPTION:
     2445 *  This function is similar to fd_fifo_get, except that it will block if the queue is empty
    24312446 * only until the absolute time abstime (see pthread_cond_timedwait for + info).
    24322447 * If the queue is still empty when the time expires, the function returns ETIMEDOUT
    24332448 *
    24342449 * RETURN VALUE:
    2435  *  0           : A new message has been retrieved.
    2436  *  EINVAL      : A parameter is invalid.
    2437  *  ETIMEDOUT   : The time out has passed and no message has been received.
    2438  */
    2439 int fd_mq_timedget ( struct mqueue * queue, struct msg ** msg, const struct timespec *abstime );
     2450 *  0           : A new item has been retrieved.
     2451 *  EINVAL      : A parameter is invalid.
     2452 *  ETIMEDOUT   : The time out has passed and no item has been received.
     2453 */
     2454int fd_fifo_timedget_int ( struct fifo * queue, void ** item, const struct timespec *abstime );
     2455#define fd_fifo_timedget(queue, item, abstime) \
     2456        fd_fifo_timedget_int((queue), (void *)(item), (abstime))
    24402457
    24412458#endif /* _LIBFREEDIAMETER_H */
  • libfreeDiameter/CMakeLists.txt

    r7 r8  
    11# Name of the subproject
    22Project("libfreeDiameter" C)
    3 
    4 SET(PROJECT_COPYRIGHT "Copyright (c) 2008-2009, WIDE Project (www.wide.ad.jp) and NICT (www.nict.go.jp)")
    53
    64# List of source files for the library
     
    1311        log.c
    1412        messages.c
    15         mqueues.c
     13        queues.c
    1614        sessions.c
    1715        )
  • libfreeDiameter/queues.c

    r1 r8  
    3434*********************************************************************************************************/
    3535
    36 /* Messages queues module.
     36/* FIFO queues module.
    3737 *
    3838 * The threads that call these functions must be in the cancellation state PTHREAD_CANCEL_ENABLE and type PTHREAD_CANCEL_DEFERRED.
     
    4242 *  -> shutdown any process that can add into the queue first.
    4343 *  -> pthread_cancel any thread that could be waiting on the queue.
    44  *  -> consume any message that is in the queue, using meq_tryget.
    45  *  -> then destroy the queue using meq_del.
     44 *  -> consume any element that is in the queue, using fd_qu_tryget_int.
     45 *  -> then destroy the queue using fd_mq_del.
    4646 */
    4747
    4848#include "libfD.h"
    4949
    50 /* Definition of a message queue object */
    51 struct mqueue {
    52         int             eyec;   /* An eye catcher, also used to check a queue is valid. MQ_EYEC */
     50/* Definition of a FIFO queue object */
     51struct fifo {
     52        int             eyec;   /* An eye catcher, also used to check a queue is valid. FIFO_EYEC */
    5353       
    5454        pthread_mutex_t mtx;    /* Mutex protecting this queue */
    5555        pthread_cond_t  cond;   /* condition variable of the list */
    5656       
    57         struct fd_list  list;   /* sentinel for the list of messages */
     57        struct fd_list  list;   /* sentinel for the list of elements */
    5858        int             count;  /* number of objects in the list */
    59         int             thrs;   /* number of threads waiting for a new message (when count is 0) */
     59        int             thrs;   /* number of threads waiting for a new element (when count is 0) */
    6060       
    6161        uint16_t        high;   /* High level threshold (see libfreeDiameter.h for details) */
    6262        uint16_t        low;    /* Low level threshhold */
    6363        void            *data;  /* Opaque pointer for threshold callbacks */
    64         void            (*h_cb)(struct mqueue *, void **); /* The callbacks */
    65         void            (*l_cb)(struct mqueue *, void **);
     64        void            (*h_cb)(struct fifo *, void **); /* The callbacks */
     65        void            (*l_cb)(struct fifo *, void **);
    6666        int             highest;/* The highest count value for which h_cb has been called */
    6767};
    6868
    6969/* The eye catcher value */
    70 #define MQ_EYEC 0xe7ec1130
     70#define FIFO_EYEC       0xe7ec1130
    7171
    7272/* Macro to check a pointer */
    73 #define CHECK_QUEUE( _queue ) (( (_queue) != NULL) && ( (_queue)->eyec == MQ_EYEC) )
    74 
    75 
    76 /* Create a new message queue */
    77 int fd_mq_new ( struct mqueue ** queue )
    78 {
    79         struct mqueue * new;
     73#define CHECK_FIFO( _queue ) (( (_queue) != NULL) && ( (_queue)->eyec == FIFO_EYEC) )
     74
     75
     76/* Create a new queue */
     77int fd_fifo_new ( struct fifo ** queue )
     78{
     79        struct fifo * new;
    8080       
    8181        TRACE_ENTRY( "%p", queue );
     
    8484       
    8585        /* Create a new object */
    86         CHECK_MALLOC( new = malloc (sizeof (struct mqueue) )  );
     86        CHECK_MALLOC( new = malloc (sizeof (struct fifo) )  );
    8787       
    8888        /* Initialize the content */
    89         memset(new, 0, sizeof(struct mqueue));
    90        
    91         new->eyec = MQ_EYEC;
     89        memset(new, 0, sizeof(struct fifo));
     90       
     91        new->eyec = FIFO_EYEC;
    9292        CHECK_POSIX( pthread_mutex_init(&new->mtx, NULL) );
    9393        CHECK_POSIX( pthread_cond_init(&new->cond, NULL) );
     
    100100}
    101101
    102 /* Delete a message queue. It must be unused. */
    103 int fd_mq_del ( struct mqueue  ** queue )
    104 {
    105         struct mqueue * q;
     102/* Delete a queue. It must be unused. */
     103int fd_fifo_del ( struct fifo  ** queue )
     104{
     105        struct fifo * q;
    106106       
    107107        TRACE_ENTRY( "%p", queue );
    108108
    109         CHECK_PARAMS( queue && CHECK_QUEUE( *queue ) );
     109        CHECK_PARAMS( queue && CHECK_FIFO( *queue ) );
    110110       
    111111        q = *queue;
     
    139139
    140140/* Get the length of the queue */
    141 int fd_mq_length ( struct mqueue * queue, int * length )
     141int fd_fifo_length ( struct fifo * queue, int * length )
    142142{
    143143        TRACE_ENTRY( "%p %p", queue, length );
    144144       
    145145        /* Check the parameters */
    146         CHECK_PARAMS( CHECK_QUEUE( queue ) && length );
     146        CHECK_PARAMS( CHECK_FIFO( queue ) && length );
    147147       
    148148        /* lock the queue */
     
    160160
    161161/* alternate version with no error checking */
    162 int fd_mq_length_noerr ( struct mqueue * queue )
    163 {
    164         if ( !CHECK_QUEUE( queue ) )
     162int fd_fifo_length_noerr ( struct fifo * queue )
     163{
     164        if ( !CHECK_FIFO( queue ) )
    165165                return 0;
    166166       
     
    169169
    170170/* Set the thresholds of the queue */
    171 int fd_mq_setthrhd ( struct mqueue * queue, void * data, uint16_t high, void (*h_cb)(struct mqueue *, void **), uint16_t low, void (*l_cb)(struct mqueue *, void **) )
     171int fd_fifo_setthrhd ( struct fifo * queue, void * data, uint16_t high, void (*h_cb)(struct fifo *, void **), uint16_t low, void (*l_cb)(struct fifo *, void **) )
    172172{
    173173        TRACE_ENTRY( "%p %p %hu %p %hu %p", queue, data, high, h_cb, low, l_cb );
    174174       
    175175        /* Check the parameters */
    176         CHECK_PARAMS( CHECK_QUEUE( queue ) && (high > low) && (queue->data == NULL) );
     176        CHECK_PARAMS( CHECK_FIFO( queue ) && (high > low) && (queue->data == NULL) );
    177177       
    178178        /* lock the queue */
     
    193193}
    194194
    195 /* Post a new message in the queue */
    196 int fd_mq_post ( struct mqueue * queue, struct msg ** msg )
     195/* Post a new item in the queue */
     196int fd_fifo_post_int ( struct fifo * queue, void ** item )
    197197{
    198198        struct fd_list * new;
    199199        int call_cb = 0;
    200200       
    201         TRACE_ENTRY( "%p %p", queue, msg );
    202        
    203         /* Check the parameters */
    204         CHECK_PARAMS( CHECK_QUEUE( queue ) && msg && *msg );
     201        TRACE_ENTRY( "%p %p", queue, item );
     202       
     203        /* Check the parameters */
     204        CHECK_PARAMS( CHECK_FIFO( queue ) && item && *item );
    205205       
    206206        /* Create a new list item */
    207207        CHECK_MALLOC(  new = malloc (sizeof (struct fd_list))  );
    208208       
    209         fd_list_init(new, *msg);
    210         *msg = NULL;
    211        
    212         /* lock the queue */
    213         CHECK_POSIX(  pthread_mutex_lock( &queue->mtx )  );
    214        
    215         /* Add the new message at the end */
     209        fd_list_init(new, *item);
     210        *item = NULL;
     211       
     212        /* lock the queue */
     213        CHECK_POSIX(  pthread_mutex_lock( &queue->mtx )  );
     214       
     215        /* Add the new item at the end */
    216216        fd_list_insert_before( &queue->list, new);
    217217        queue->count++;
     
    237237}
    238238
    239 /* Pop the first message from the queue */
    240 static struct msg * mq_pop(struct mqueue * queue)
    241 {
    242         struct msg * ret = NULL;
     239/* Pop the first item from the queue */
     240static void * mq_pop(struct fifo * queue)
     241{
     242        void * ret = NULL;
    243243        struct fd_list * li;
    244244       
     
    247247        fd_list_unlink(li = queue->list.next);
    248248        queue->count--;
    249         ret = (struct msg *)(li->o);
     249        ret = li->o;
    250250        free(li);
    251251       
     
    254254
    255255/* Check if the low watermark callback must be called. */
    256 static int test_l_cb(struct mqueue * queue)
     256static __inline__ int test_l_cb(struct fifo * queue)
    257257{
    258258        if ((queue->high == 0) || (queue->low == 0) || (queue->l_cb == 0))
     
    267267}
    268268
    269 /* Try poping a message */
    270 int fd_mq_tryget ( struct mqueue * queue, struct msg ** msg )
     269/* Try poping an item */
     270int fd_fifo_tryget_int ( struct fifo * queue, void ** item )
    271271{
    272272        int wouldblock = 0;
    273273        int call_cb = 0;
    274274       
    275         TRACE_ENTRY( "%p %p", queue, msg );
    276        
    277         /* Check the parameters */
    278         CHECK_PARAMS( CHECK_QUEUE( queue ) && msg );
     275        TRACE_ENTRY( "%p %p", queue, item );
     276       
     277        /* Check the parameters */
     278        CHECK_PARAMS( CHECK_FIFO( queue ) && item );
    279279       
    280280        /* lock the queue */
     
    283283        /* Check queue status */
    284284        if (queue->count > 0) {
    285                 /* There are messages in the queue, so pick the first one */
    286                 *msg = mq_pop(queue);
     285                /* There are elements in the queue, so pick the first one */
     286                *item = mq_pop(queue);
    287287                call_cb = test_l_cb(queue);
    288288        } else {
    289289                wouldblock = 1;
    290                 *msg = NULL;
     290                *item = NULL;
    291291        }
    292292               
     
    303303
    304304/* This handler is called when a thread is blocked on a queue, and cancelled */
    305 static void mq_cleanup(void * queue)
    306 {
    307         struct mqueue * q = (struct mqueue *)queue;
     305static void fifo_cleanup(void * queue)
     306{
     307        struct fifo * q = (struct fifo *)queue;
    308308        TRACE_ENTRY( "%p", queue );
    309309       
    310310        /* Check the parameter */
    311         if ( ! CHECK_QUEUE( q )) {
     311        if ( ! CHECK_FIFO( q )) {
    312312                TRACE_DEBUG(INFO, "Invalid queue, skipping handler");
    313313                return;
     
    324324}
    325325
    326 /* The internal function for meq_timedget and meq_get */
    327 static int mq_tget ( struct mqueue * queue, struct msg ** msg, int istimed, const struct timespec *abstime)
     326/* The internal function for fd_fifo_timedget and fd_fifo_get */
     327static int fifo_tget ( struct fifo * queue, void ** item, int istimed, const struct timespec *abstime)
    328328{
    329329        int timedout = 0;
     
    331331       
    332332        /* Check the parameters */
    333         CHECK_PARAMS( CHECK_QUEUE( queue ) && msg && (abstime || !istimed) );
    334        
    335         /* Initialize the msg value */
    336         *msg = NULL;
     333        CHECK_PARAMS( CHECK_FIFO( queue ) && item && (abstime || !istimed) );
     334       
     335        /* Initialize the return value */
     336        *item = NULL;
    337337       
    338338        /* lock the queue */
     
    342342        /* Check queue status */
    343343        if (queue->count > 0) {
    344                 /* There are messages in the queue, so pick the first one */
    345                 *msg = mq_pop(queue);
     344                /* There are items in the queue, so pick the first one */
     345                *item = mq_pop(queue);
    346346                call_cb = test_l_cb(queue);
    347347        } else {
    348348                int ret = 0;
    349                 /* We have to wait for a new message */
     349                /* We have to wait for a new item */
    350350                queue->thrs++ ;
    351                 pthread_cleanup_push( mq_cleanup, queue);
     351                pthread_cleanup_push( fifo_cleanup, queue);
    352352                if (istimed) {
    353353                        ret = pthread_cond_timedwait( &queue->cond, &queue->mtx, abstime );
     
    379379}
    380380
    381 /* Get the next available message, block until there is one */
    382 int fd_mq_get ( struct mqueue * queue, struct msg ** msg )
    383 {
    384         TRACE_ENTRY( "%p %p", queue, msg );
    385         return mq_tget(queue, msg, 0, NULL);
    386 }
    387 
    388 /* Get the next available message, block until there is one, or the timeout expires */
    389 int fd_mq_timedget ( struct mqueue * queue, struct msg ** msg, const struct timespec *abstime )
    390 {
    391         TRACE_ENTRY( "%p %p %p", queue, msg, abstime );
    392         return mq_tget(queue, msg, 1, abstime);
    393 }
    394 
     381/* Get the next available item, block until there is one */
     382int fd_fifo_get_int ( struct fifo * queue, void ** item )
     383{
     384        TRACE_ENTRY( "%p %p", queue, item );
     385        return fifo_tget(queue, item, 0, NULL);
     386}
     387
     388/* Get the next available item, block until there is one, or the timeout expires */
     389int fd_fifo_timedget_int ( struct fifo * queue, void ** item, const struct timespec *abstime )
     390{
     391        TRACE_ENTRY( "%p %p %p", queue, item, abstime );
     392        return fifo_tget(queue, item, 1, abstime);
     393}
     394
Note: See TracChangeset for help on using the changeset viewer.