Navigation


Changeset 658:f198d16fa7f4 in freeDiameter


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

Initial commit for 1.1.0:

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

Legend:

Unmodified
Added
Removed
  • CMakeLists.txt

    r647 r658  
    1111# Version of the source code
    1212SET(FD_PROJECT_VERSION_MAJOR 1)
    13 SET(FD_PROJECT_VERSION_MINOR 0)
    14 SET(FD_PROJECT_VERSION_REV 4)
     13SET(FD_PROJECT_VERSION_MINOR 1)
     14SET(FD_PROJECT_VERSION_REV 0)
    1515
    1616# Version of the API with the library
    17 SET(FD_PROJECT_VERSION_API 3)
     17SET(FD_PROJECT_VERSION_API 4)
    1818
    1919# The test framework, using CTest and CDash.
     
    3131SET(INSTALL_HEADERS_SUFFIX              include/freeDiameter    CACHE PATH "Directory where the headers are installed (relative to CMAKE_INSTALL_PREFIX).")
    3232SET(INSTALL_DAEMON_SUFFIX               bin                     CACHE PATH "Directory where the daemon binary is installed (relative to CMAKE_INSTALL_PREFIX).")
    33 SET(INSTALL_LIBRARY_SUFFIX              lib                     CACHE PATH "Directory where the libfreeDiameter library is installed (relative to CMAKE_INSTALL_PREFIX).")
     33SET(INSTALL_LIBRARY_SUFFIX              lib                     CACHE PATH "Directory where the freeDiameter libraries are installed (relative to CMAKE_INSTALL_PREFIX).")
    3434SET(INSTALL_EXTENSIONS_SUFFIX   ${INSTALL_LIBRARY_SUFFIX}/freeDiameter  CACHE PATH "Directory where the extensions are installed / searched (relative to CMAKE_INSTALL_PREFIX).")
    3535
     
    7777
    7878# Location for the source code
    79 SUBDIRS(libfreeDiameter)
    80 SUBDIRS(freeDiameter)
     79SUBDIRS(libfdproto)
     80SUBDIRS(libfdcore)
     81SUBDIRS(freeDiameterd)
    8182
    8283# Extensions (there is no use of freeDiameter without any extension)
    8384SUBDIRS(extensions)
     85
     86# The unary tests directory
     87IF ( BUILD_TESTING )
     88        SUBDIRS(tests)
     89ENDIF ( BUILD_TESTING )
     90
  • contrib/debian/control

    r631 r658  
    1313Architecture: any
    1414Depends: ${shlibs:Depends}, ${misc:Depends}
    15 Description: The libfreeDiameter library.
    16  This library is required by all freeDiameter components.
     15Description: The freeDiameter libraries.
     16 This package contains the libraries required by all freeDiameter components.
    1717 It may also be useful for other projects which need to
    1818 perform operations on Diameter messages.
  • contrib/debian/freediameter-common.install

    r328 r658  
    1 usr/lib/libfreeDiameter.so*
     1usr/lib/libfdproto.so*
     2usr/lib/libfdcore.so*
  • extensions/dbg_interactive/CMakeLists.txt

    r641 r658  
    1616SET(SWIG_MODULE_fDpy_EXTRA_DEPS
    1717        ${CMAKE_BINARY_DIR}/include/freeDiameter/freeDiameter-host.h
    18         ${CMAKE_SOURCE_DIR}/include/freeDiameter/libfreeDiameter.h
    19         ${CMAKE_SOURCE_DIR}/include/freeDiameter/freeDiameter.h
     18        ${CMAKE_SOURCE_DIR}/include/freeDiameter/libfdcore.h
     19        ${CMAKE_SOURCE_DIR}/include/freeDiameter/libfdproto.h
    2020        lists.i
    2121        dictionary.i
  • extensions/dbg_interactive/dbg_interactive.c

    r639 r658  
    5959        fd_log_threadname ( "fDpy" );
    6060       
    61         CHECK_FCT_DO(fd_wait_initialization_complete(), goto end);
     61        CHECK_FCT_DO(fd_core_waitstartcomplete(), goto end);
    6262       
    6363        fd_log_debug("\nStarting interactive python interpreter [experimental].\n");
  • extensions/dbg_interactive/dbg_interactive.i

    r641 r658  
    159159 *********************************************************/
    160160%include "freeDiameter/freeDiameter-host.h"
    161 %include "freeDiameter/libfreeDiameter.h"
    162 %include "freeDiameter/freeDiameter.h"
     161%include "freeDiameter/libfdproto.h"
     162%include "freeDiameter/libfdcore.h"
    163163
    164164/* Most of the functions from the API are not directly usable "as is".
  • extensions/dbg_monitor/dbg_monitor.c

    r258 r658  
    7878
    7979/* Function called on receipt of MONITOR_SIGNAL */
    80 static void got_sig(int signal)
     80static void got_sig()
    8181{
    8282        fd_log_debug("[dbg_monitor] Dumping extra information\n");
     
    9292       
    9393        /* Catch signal SIGUSR1 */
    94         CHECK_FCT( fd_sig_register(MONITOR_SIGNAL, "dbg_monitor", got_sig));
     94        CHECK_FCT( fd_event_trig_regcb(MONITOR_SIGNAL, "dbg_monitor", got_sig));
    9595       
    9696        CHECK_POSIX( pthread_create( &thr, NULL, mn_thr, NULL ) );
  • extensions/dict_eap/dict_eap.c

    r10 r658  
    296296                                        268,                                    /* Code */
    297297                                        "Diameter-EAP-Request",                 /* Name */
    298                                         CMD_FLAG_REQUEST | CMD_FLAG_PROXIABLE | CMD_FLAG_RETRANSMIT | CMD_FLAG_ERROR,   /* Fixed flags */
     298                                        CMD_FLAG_REQUEST | CMD_FLAG_PROXIABLE | CMD_FLAG_ERROR, /* Fixed flags */
    299299                                        CMD_FLAG_REQUEST | CMD_FLAG_PROXIABLE                   /* Fixed flag values */
    300300                                        };
  • extensions/dict_legacy_xml/dict_lxml_xml.c

    r616 r658  
    933933                                        { TRACE_DEBUG(INFO, "Invalid 'type' tag found without 'name' attribute."); goto xml_tree_error; } );
    934934                               
     935                                /* Check there is only 1 type */
     936                                if (!FD_IS_LIST_EMPTY(&data->cur_avp->type)) {
     937                                        TRACE_DEBUG(INFO, "Multiple 'type' tags found for AVP.");
     938                                        goto xml_tree_error;
     939                                }
     940                               
     941                                /* Add the new type */
    935942                                CHECK_FCT_DO( new_avptype(&data->cur_avp->type, xname),
    936943                                        { TRACE_DEBUG(INFO, "An error occurred while parsing a type tag. Entry ignored."); goto xml_tree_error; } )
     
    10111018        }
    10121019        data->error_depth += 1;
     1020        if (data->cur_app || data->cur_cmd || data->cur_avp) {
     1021                TRACE_DEBUG(INFO, "Error encountered while parsing tag of:");
     1022                if (data->cur_app)
     1023                        fd_log_debug("  Application: '%s'\n", data->cur_app->name);
     1024                if (data->cur_cmd)
     1025                        fd_log_debug("  Command    : '%s'\n", data->cur_cmd->name);
     1026                if (data->cur_avp)
     1027                        fd_log_debug("  AVP        : '%s'\n", data->cur_avp->name);
     1028        }
    10131029        return;
    10141030}
     
    13871403               
    13881404                /* Now create the new rule */
    1389                 CHECK_FCT( fd_dict_new ( fD_dict, DICT_RULE, &rd, parent, NULL ) );
     1405                CHECK_FCT_DO( ret = fd_dict_new ( fD_dict, DICT_RULE, &rd, parent, NULL ),
     1406                        { TRACE_DEBUG(INFO, "Error creating rule for sub-AVP '%s'", r->avpname); return ret; } );
    13901407                if (nb_added)
    13911408                        *nb_added += 1;
     
    13981415static int rules_to_fD(struct dictionary * fD_dict, struct dict_object * parent, struct fd_list * fixed, struct fd_list * required, struct fd_list * optional, int * nb_added)
    13991416{
     1417        int ret;
     1418       
    14001419        TRACE_ENTRY("%p %p %p %p %p %p", fD_dict, parent, fixed, required, optional, nb_added);
    14011420       
    14021421        /* Process the rules */
    1403         CHECK_FCT( rules_to_fD_onelist(fD_dict, parent, RULE_FIXED_HEAD, fixed, nb_added) );
    1404         CHECK_FCT( rules_to_fD_onelist(fD_dict, parent, RULE_REQUIRED, required, nb_added) );
    1405         CHECK_FCT( rules_to_fD_onelist(fD_dict, parent, RULE_OPTIONAL, optional, nb_added) );
     1422        CHECK_FCT_DO( ret = rules_to_fD_onelist(fD_dict, parent, RULE_FIXED_HEAD, fixed, nb_added),
     1423                { TRACE_DEBUG(INFO, "Error processing FIXED rules"); return ret; } );
     1424        CHECK_FCT_DO( ret = rules_to_fD_onelist(fD_dict, parent, RULE_REQUIRED, required, nb_added),
     1425                { TRACE_DEBUG(INFO, "Error processing REQUIRED rules"); return ret; } );
     1426        CHECK_FCT_DO( ret = rules_to_fD_onelist(fD_dict, parent, RULE_OPTIONAL, optional, nb_added),
     1427                { TRACE_DEBUG(INFO, "Error processing OPTIONAL rules"); return ret; } );
    14061428       
    14071429        return 0;
     
    14251447        ad.avp_vendor = a->vendor;
    14261448        ad.avp_name   = (char *)a->name;
    1427         ad.avp_flag_mask = a->fmask;
     1449        ad.avp_flag_mask = a->fmask | AVP_FLAG_VENDOR;
    14281450        ad.avp_flag_val  = a->flags;
    14291451       
    14301452        if (!FD_IS_LIST_EMPTY(&a->type)) {
    14311453                /* special exception: we use per-AVP enumerated types in fD */
    1432                 if (strcasecmp("Enumerated", (char *)((struct t_avptype *)a->type.next)->type_name))
     1454                if (!strcasecmp("Enumerated", (char *)((struct t_avptype *)a->type.next)->type_name))
     1455                        goto enumerated;
     1456                /* Let's allow "Unsigned32" instead of "Enumerated" also... */
     1457                if ((!FD_IS_LIST_EMPTY(&a->enums)) && (!strcasecmp("Unsigned32", (char *)((struct t_avptype *)a->type.next)->type_name)))
    14331458                        goto enumerated;
    14341459               
     
    14411466                        || !FD_IS_LIST_EMPTY(&a->grouped_fixed) ) {
    14421467                        /* The AVP has rules, it is a grouped AVP */
    1443                         CHECK_PARAMS( FD_IS_LIST_EMPTY(&a->enums) );
     1468                        CHECK_PARAMS_DO( FD_IS_LIST_EMPTY(&a->enums),
     1469                                { TRACE_DEBUG(INFO, "Conflict: The AVP '%s' has both enum values and rules.", ad.avp_name); return EINVAL; } );
    14441470                        ad.avp_basetype = AVP_TYPE_GROUPED;
    14451471                } else {
    14461472                        /* It should be an enumerated AVP... */
    14471473                        if (FD_IS_LIST_EMPTY(&a->enums)) {
    1448                                 TRACE_DEBUG(INFO, "[dict_legacy_xml] Error: Missing type information for AVP '%s'", ad.avp_name);
     1474                                TRACE_DEBUG(INFO, "Error: Missing type information for AVP '%s'", ad.avp_name);
    14491475                                return EINVAL;
    14501476                        } else {
     
    14921518        /* Now, the inner elements, if any */
    14931519       
     1520        if ( (!FD_IS_LIST_EMPTY(&a->enums)) && (ad.avp_basetype != AVP_TYPE_UNSIGNED32)) {
     1521                TRACE_DEBUG(INFO, "AVP '%s' type is not an Unsigned32 but it has enum values (invalid in this extension).", ad.avp_name);
     1522                return EINVAL;
     1523        }
     1524
    14941525        /* In case of enumeration, define the enum values */
    1495         ASSERT( FD_IS_LIST_EMPTY(&a->enums) || (type && (ad.avp_basetype == AVP_TYPE_UNSIGNED32)) ); /* u32 type must be defined for enumerators */
    14961526        for (li = a->enums.next; li != &a->enums; li = li->next) {
    14971527                struct t_enum * e = (struct t_enum *)li;
     
    15021532                ed.enum_value.u32 = e->code;
    15031533               
    1504                 CHECK_FCT( fd_dict_new ( fD_dict, DICT_ENUMVAL, &ed, type, NULL ) );
     1534                CHECK_FCT_DO( ret = fd_dict_new ( fD_dict, DICT_ENUMVAL, &ed, type, NULL ),
     1535                        {
     1536                                TRACE_DEBUG(INFO, "Error defining constant value '%s' for AVP '%s': %s", ed.enum_name, ad.avp_name, strerror(ret));
     1537                                return ret;
     1538                        } );
    15051539                if (nb_added)
    15061540                        *nb_added += 1;
     
    15111545          || !FD_IS_LIST_EMPTY(&a->grouped_required)
    15121546          || !FD_IS_LIST_EMPTY(&a->grouped_fixed) ) {
    1513                 CHECK_PARAMS( ad.avp_basetype == AVP_TYPE_GROUPED );
    1514                 CHECK_FCT( rules_to_fD(fD_dict, prev, &a->grouped_fixed, &a->grouped_required, &a->grouped_optional, nb_added) );
     1547                CHECK_PARAMS_DO( ad.avp_basetype == AVP_TYPE_GROUPED,
     1548                        { TRACE_DEBUG(INFO, "Got rules for non-grouped AVP '%s'", ad.avp_name); return EINVAL;} );
     1549                CHECK_FCT_DO( ret = rules_to_fD(fD_dict, prev, &a->grouped_fixed, &a->grouped_required, &a->grouped_optional, nb_added),
     1550                        { TRACE_DEBUG(INFO, "Error processing rules for AVP '%s': %s", ad.avp_name, strerror(ret)); return ret; } );
    15151551        }
    15161552       
     
    15361572        snprintf(cmdname, sizeof(cmdname), "%s-Request", (char *)c->name);
    15371573        cd.cmd_name = &cmdname[0];
    1538         cd.cmd_flag_mask = c->fmask | CMD_FLAG_REQUEST;
     1574        cd.cmd_flag_mask = c->fmask | CMD_FLAG_REQUEST | CMD_FLAG_ERROR;
    15391575        cd.cmd_flag_val  = c->flags | CMD_FLAG_REQUEST;
    15401576       
     
    15641600        snprintf(cmdname, sizeof(cmdname), "%s-Answer", (char *)c->name);
    15651601        cd.cmd_flag_val &= ~CMD_FLAG_REQUEST;
     1602        cd.cmd_flag_mask &= ~CMD_FLAG_ERROR;
    15661603       
    15671604        ret = fd_dict_new ( fD_dict, DICT_COMMAND, &cd, fd_appl, &ans );
     
    15851622rules:
    15861623        /* Now process the rules inside the command */
    1587         CHECK_FCT( rules_to_fD(fD_dict, req, &c->reqrules_fixed, &c->reqrules_required, &c->reqrules_optional, nb_added) );
    1588         CHECK_FCT( rules_to_fD(fD_dict, ans, &c->ansrules_fixed, &c->ansrules_required, &c->ansrules_optional, nb_added) );
     1624        CHECK_FCT_DO( ret = rules_to_fD(fD_dict, req, &c->reqrules_fixed, &c->reqrules_required, &c->reqrules_optional, nb_added),
     1625                        {
     1626                                TRACE_DEBUG(INFO, "Error converting data from request rules: %s", strerror(ret));
     1627                                return ret;
     1628                        }   );
     1629        CHECK_FCT_DO( ret = rules_to_fD(fD_dict, ans, &c->ansrules_fixed, &c->ansrules_required, &c->ansrules_optional, nb_added),
     1630                        {
     1631                                TRACE_DEBUG(INFO, "Error converting data from answer rules: %s", strerror(ret));
     1632                                return ret;
     1633                        }   );
    15891634       
    15901635        /* Done */
     
    16411686        /* First, define all the types */
    16421687        for (li = a->types.next; li != &a->types; li = li->next) {
    1643                 CHECK_FCT( typdefn_to_fD((struct t_typedefn *)li, fD_dict, prev, NULL, nb_added) );
     1688                CHECK_FCT_DO( ret = typdefn_to_fD((struct t_typedefn *)li, fD_dict, prev, NULL, nb_added),
     1689                        {
     1690                                TRACE_DEBUG(INFO, "Error converting data from typedefn '%s': %s", ((struct t_typedefn *)li)->name, strerror(ret));
     1691                                return ret;
     1692                        }  );
    16441693        }
    16451694       
    16461695        /* Then, AVPs, enums, and grouped AVP rules */
    16471696        for (li = a->avps.next; li != &a->avps; li = li->next) {
    1648                 CHECK_FCT( avp_to_fD((struct t_avp *)li, fD_dict, prev, NULL, nb_added) );
     1697                CHECK_FCT_DO( ret = avp_to_fD((struct t_avp *)li, fD_dict, prev, NULL, nb_added),
     1698                        {
     1699                                TRACE_DEBUG(INFO, "Error converting data from AVP '%s': %s", ((struct t_avp *)li)->name, strerror(ret));
     1700                                return ret;
     1701                        }  );
    16491702        }
    16501703       
    16511704        /* Finally, the commands and rules */
    16521705        for (li = a->commands.next; li != &a->commands; li = li->next) {
    1653                 CHECK_FCT( cmd_to_fD((struct t_cmd *)li, fD_dict, prev, NULL, nb_added) );
     1706                CHECK_FCT_DO( ret = cmd_to_fD((struct t_cmd *)li, fD_dict, prev, NULL, nb_added),
     1707                        {
     1708                                TRACE_DEBUG(INFO, "Error converting data from command '%s': %s", ((struct t_cmd *)li)->name, strerror(ret));
     1709                                return ret;
     1710                        }  );
    16541711        }
    16551712       
     
    16621719{
    16631720        struct fd_list * li;
     1721        int ret;
    16641722       
    16651723        TRACE_ENTRY("%p %p %p", fD_dict, xmldict, nb_added);
     
    16711729        /* Create all the vendors */
    16721730        for (li = xmldict->vendors.next; li != &xmldict->vendors; li = li->next) {
    1673                 CHECK_FCT( vend_to_fD((struct t_vend *)li, fD_dict, NULL, nb_added) );
     1731                CHECK_FCT_DO( ret = vend_to_fD((struct t_vend *)li, fD_dict, NULL, nb_added),
     1732                        {
     1733                                TRACE_DEBUG(INFO, "Error converting data from vendor '%s': %s", ((struct t_vend *)li)->name, strerror(ret));
     1734                                return ret;
     1735                        } );
    16741736        }
    16751737       
    16761738        /* Now, process each application */
    1677         CHECK_FCT( appl_to_fD(&xmldict->base_and_applications, fD_dict, NULL, nb_added) );
     1739        CHECK_FCT_DO( ret = appl_to_fD(&xmldict->base_and_applications, fD_dict, NULL, nb_added),
     1740                        {
     1741                                TRACE_DEBUG(INFO, "Error converting data from Base application: %s", strerror(ret));
     1742                                return ret;
     1743                        } );
    16781744        for (li = xmldict->base_and_applications.chain.next; li != &xmldict->base_and_applications.chain; li = li->next) {
    1679                 CHECK_FCT( appl_to_fD((struct t_appl *) li, fD_dict, NULL, nb_added) );
     1745                CHECK_FCT_DO( ret = appl_to_fD((struct t_appl *) li, fD_dict, NULL, nb_added),
     1746                        {
     1747                                TRACE_DEBUG(INFO, "Error converting data from application '%s': %s", ((struct t_appl *)li)->name, strerror(ret));
     1748                                return ret;
     1749                        }  );
    16801750        }
    16811751       
     
    17251795        }
    17261796       
    1727         TRACE_DEBUG(FULL, "XML file parsing complete.");
     1797        TRACE_DEBUG(FULL, "XML file parsing, 1st pass completed.");
    17281798        if (TRACE_BOOL(ANNOYING)) {
    17291799                dump_dict(&data.dict);
     
    17311801       
    17321802        /* Now, convert all the objects from the temporary tree into the freeDiameter dictionary */
    1733         CHECK_FCT_DO( dict_to_fD(fd_g_config->cnf_dict, &data.dict, &ret), { del_dict_contents(&data.dict); return -1; } );
    1734        
    1735         TRACE_DEBUG(FULL, "Conversion to freeDiameter internal format complete.");
     1803        CHECK_FCT_DO( dict_to_fD(fd_g_config->cnf_dict, &data.dict, &ret),
     1804                {
     1805                        TRACE_DEBUG(INFO, "Error while converting data read from file '%s'", xmlfilename);
     1806                        del_dict_contents(&data.dict);
     1807                        return -1;
     1808                } );
     1809       
     1810        TRACE_DEBUG(FULL, "Conversion from '%s' to freeDiameter internal format complete.", xmlfilename);
    17361811        if (TRACE_BOOL(ANNOYING)) {
    17371812                fd_dict_dump(fd_g_config->cnf_dict);
  • extensions/dict_nasreq/dict_nasreq.c

    r523 r658  
    30053005                                        265,                                    /* Code */
    30063006                                        "AA-Request",                           /* Name */
    3007                                         CMD_FLAG_REQUEST | CMD_FLAG_PROXIABLE | CMD_FLAG_RETRANSMIT | CMD_FLAG_ERROR,   /* Fixed flags */
     3007                                        CMD_FLAG_REQUEST | CMD_FLAG_PROXIABLE | CMD_FLAG_ERROR, /* Fixed flags */
    30083008                                        CMD_FLAG_REQUEST | CMD_FLAG_PROXIABLE                   /* Fixed flag values */
    30093009                                        };
  • extensions/test_app/ta_bench.c

    r575 r658  
    208208
    209209/* The function called when the signal is received */
    210 static void ta_bench_start(int sig) {
     210static void ta_bench_start() {
    211211        struct timespec end_time, now;
    212212        struct ta_stats start, end;
     
    274274        CHECK_SYS( sem_init( &ta_sem, 0, ta_conf->bench_concur) );
    275275
    276         CHECK_FCT( fd_sig_register(ta_conf->signal, "test_app.bench", ta_bench_start ) );
     276        CHECK_FCT( fd_event_trig_regcb(ta_conf->signal, "test_app.bench", ta_bench_start ) );
    277277       
    278278        return 0;
     
    281281void ta_bench_fini(void)
    282282{
    283         CHECK_FCT_DO( fd_sig_unregister(ta_conf->signal), /* continue */ );
     283        // CHECK_FCT_DO( fd_sig_unregister(ta_conf->signal), /* continue */ );
    284284       
    285285        CHECK_SYS_DO( sem_destroy(&ta_sem), );
  • extensions/test_app/ta_cli.c

    r639 r658  
    136136
    137137/* Create a test message */
    138 static void ta_cli_test_message(int sig)
     138static void ta_cli_test_message()
    139139{
    140140        struct msg * req = NULL;
     
    236236        CHECK_FCT( fd_sess_handler_create(&ta_cli_reg, free, NULL) );
    237237       
    238         CHECK_FCT( fd_sig_register(ta_conf->signal, "test_app.cli", ta_cli_test_message ) );
     238        CHECK_FCT( fd_event_trig_regcb(ta_conf->signal, "test_app.cli", ta_cli_test_message ) );
    239239       
    240240        return 0;
     
    243243void ta_cli_fini(void)
    244244{
    245         CHECK_FCT_DO( fd_sig_unregister(ta_conf->signal), /* continue */ );
     245        // CHECK_FCT_DO( fd_sig_unregister(ta_conf->signal), /* continue */ );
    246246       
    247247        CHECK_FCT_DO( fd_sess_handler_destroy(&ta_cli_reg, NULL), /* continue */ );
  • extensions/test_sip/test_sip.c

    r639 r658  
    215215       
    216216        CHECK_FCT(fd_sess_handler_create(&ts_sess_hdl, free, NULL));
    217         //CHECK_FCT( fd_sig_register(30, "test_sip", (void *)test_sipSL_LIR_cb ) );
    218         CHECK_FCT( fd_sig_register(30, "test_sip", (void *)test_sip_SAR_cb ) );
    219         CHECK_FCT( fd_sig_register(31, "test_sip", (void *)test_sip_LIR_cb ) );
     217        //CHECK_FCT( fd_event_trig_regcb(30, "test_sip", (void *)test_sipSL_LIR_cb ) );
     218        CHECK_FCT( fd_event_trig_regcb(30, "test_sip", (void *)test_sip_SAR_cb ) );
     219        CHECK_FCT( fd_event_trig_regcb(31, "test_sip", (void *)test_sip_LIR_cb ) );
    220220       
    221221        return 0;
  • freeDiameterd/CMakeLists.txt

    r592 r658  
    11# The subproject name
    2 Project("freeDiameterd" C)
    3 
    4 # Configuration parser
    5 BISON_FILE(fdd.y)
    6 FLEX_FILE(fdd.l)
    7 SET_SOURCE_FILES_PROPERTIES(lex.fdd.c fdd.tab.c PROPERTIES COMPILE_FLAGS "-I ${CMAKE_CURRENT_SOURCE_DIR}")
    8 
    9 # List of source files
    10 SET(FD_COMMON_SRC
    11         fD.h
    12         apps.c
    13         cnxctx.h
    14         config.c
    15         cnxctx.c
    16         endpoints.c
    17         events.c
    18         extensions.c
    19         dict_base_proto.c
    20         messages.c
    21         queues.c
    22         peers.c
    23         p_ce.c
    24         p_cnx.c
    25         p_dw.c
    26         p_dp.c
    27         p_expiry.c
    28         p_out.c
    29         p_psm.c
    30         p_sr.c
    31         routing_dispatch.c
    32         server.c
    33         tcp.c
    34         )
    35 
    36 IF(NOT DISABLE_SCTP)
    37         SET(FD_COMMON_SRC ${FD_COMMON_SRC} sctp.c sctps.c)
    38 ENDIF(NOT DISABLE_SCTP)
    39 
    40 SET(FD_COMMON_GEN_SRC
    41                 lex.fdd.c
    42                 fdd.tab.c
    43                 fdd.tab.h
    44         )
    45        
    46 # Save the list of files for the tests
    47 SET(FD_COMMON_SRC ${FD_COMMON_SRC} PARENT_SCOPE)
    48 SET(FD_COMMON_GEN_SRC ${FD_COMMON_GEN_SRC} PARENT_SCOPE)
    49 
    50 
    51 # Require GNU TLS for building the daemon
    52 FIND_PACKAGE(GnuTLS REQUIRED)
    53 INCLUDE_DIRECTORIES(${GNUTLS_INCLUDE_DIR})
    54 SET(FD_LIBS ${FD_LIBS} ${GNUTLS_LIBRARIES})
    55 find_path(GCRYPT_INCLUDE_DIR NAMES gcrypt.h)
    56 If ( NOT GCRYPT_INCLUDE_DIR )
    57         MESSAGE(SEND_ERROR "Unable to find gcrypt.h, please install libgcrypt-dev or equivalent")
    58 Endif ( NOT GCRYPT_INCLUDE_DIR )
    59 MARK_AS_ADVANCED(GCRYPT_INCLUDE_DIR)
    60 INCLUDE_DIRECTORIES(${GCRYPT_INCLUDE_DIR})
    61 
    62 # Also we need libgcrypt to... display its version :(
    63 find_library(GCRYPT_LIBRARY
    64   NAMES gcrypt
    65 )
    66 If ( NOT GCRYPT_LIBRARY )
    67         MESSAGE(SEND_ERROR "Unable to find libgcrypt, please install libgcrypt or equivalent")
    68 Endif ( NOT GCRYPT_LIBRARY )
    69 SET(FD_LIBS ${FD_LIBS} ${GCRYPT_LIBRARY})
    70 
    71 
     2Project("freeDiameter simple daemon" C)
    723
    734# Build the executable
    74 ADD_EXECUTABLE(freeDiameterd ${FD_COMMON_SRC} ${FD_COMMON_GEN_SRC} main.c)
     5ADD_EXECUTABLE(freeDiameterd main.c)
    756
    767# The version
     
    7910
    8011# The link command
    81 LINK_DIRECTORIES(${CURRENT_BINARY_DIR}/../libfreeDiameter)
    82 TARGET_LINK_LIBRARIES(freeDiameterd libfreeDiameter ${FD_LIBS})
    83 
    84 # The unary tests directory
    85 IF ( BUILD_TESTING )
    86         SUBDIRS(tests)
    87 ENDIF ( BUILD_TESTING )
     12TARGET_LINK_LIBRARIES(freeDiameterd libfdproto libfdcore)
    8813
    8914####
  • freeDiameterd/main.c

    r628 r658  
    3434*********************************************************************************************************/
    3535
    36 #include "fD.h"
     36#include <freeDiameter/freeDiameter-host.h>
     37#include <freeDiameter/libfdcore.h>
    3738
    3839#include <signal.h>
    3940#include <getopt.h>
    4041#include <locale.h>
    41 #include <gcrypt.h>
     42
    4243
    4344/* forward declarations */
    44 static void fd_shutdown(int signal);
    4545static int main_cmdline(int argc, char *argv[]);
    46 static void main_version(void);
    47 static void main_help( void );
    48 static int signal_framework_ready(void);
    49 
    50 /* The static configuration structure */
    51 static struct fd_config conf;
    52 struct fd_config * fd_g_config = &conf;
    53 
    54 /* gcrypt functions to support posix threads */
    55 GCRY_THREAD_OPTION_PTHREAD_IMPL;
    56 
    57 /* freeDiameter starting point */
    58 int main(int argc, char * argv[])
    59 {
    60         int ret;
    61        
    62         memset(fd_g_config, 0, sizeof(struct fd_config));
    63        
    64         /* Initialize the library -- must come first since it initializes the debug facility */
    65         CHECK_FCT( fd_lib_init(1) );
    66         TRACE_DEBUG(INFO, "libfreeDiameter initialized.");
    67        
    68         /* Name this thread */
    69         fd_log_threadname("Main");
    70        
    71         /* Initialize gcrypt and gnutls */
    72         GNUTLS_TRACE( (void) gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread) );
    73         GNUTLS_TRACE( (void) gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0) );
    74         CHECK_GNUTLS_DO( gnutls_global_init(), return EINVAL );
    75         if ( ! gnutls_check_version(GNUTLS_VERSION) ) {
    76                 fprintf(stderr, "The GNUTLS library is too old; found '%s', need '" GNUTLS_VERSION "'\n", gnutls_check_version(NULL));
    77                 return EINVAL;
    78         } else {
    79                 TRACE_DEBUG(INFO, "libgnutls '%s', libgcrypt '%s', initialized.", gnutls_check_version(NULL), gcry_check_version(NULL) );
    80         }
    81        
    82         /* Initialize the config */
    83         CHECK_FCT( fd_conf_init() );
    84 
    85         /* Parse the command-line */
    86         CHECK_FCT(  main_cmdline(argc, argv)  );
    87        
    88         /* Allow SIGINT and SIGTERM from this point to terminate the application */
    89         CHECK_FCT( fd_sig_register(SIGINT,  "freeDiameter.main", fd_shutdown) );
    90         CHECK_FCT( fd_sig_register(SIGTERM, "freeDiameter.main", fd_shutdown) );
    91        
    92         /* Add definitions of the base protocol */
    93         CHECK_FCT( fd_dict_base_protocol(fd_g_config->cnf_dict) );
    94        
    95         /* Initialize other modules */
    96         CHECK_FCT(  fd_queues_init()  );
    97         CHECK_FCT(  fd_msg_init()  );
    98         CHECK_FCT(  fd_sess_start()  );
    99         CHECK_FCT(  fd_p_expi_init()  );
    100        
    101         /* Parse the configuration file */
    102         CHECK_FCT( fd_conf_parse() );
    103        
    104         /* Create the daemon's threads */
    105         CHECK_FCT(  fd_rtdisp_init()  );
    106        
    107         /* Load the dynamic extensions */
    108         CHECK_FCT(  fd_ext_load()  );
    109        
    110         fd_conf_dump();
    111         fd_sig_dump(FULL, 1);
    112        
    113         /* Start the servers */
    114         CHECK_FCT( fd_servers_start() );
    115        
    116         /* Start the peer state machines */
    117         CHECK_FCT( fd_psm_start() );
    118        
    119         /* Now, just wait for events */
    120         TRACE_DEBUG(INFO, FD_PROJECT_BINARY " daemon initialized.");
    121         CHECK_FCT( signal_framework_ready() );
    122         while (1) {
    123                 int code; size_t sz; void * data;
    124                 CHECK_FCT_DO(  fd_event_get(fd_g_config->cnf_main_ev, &code, &sz, &data),  break  );
    125                 switch (code) {
    126                         case FDEV_DUMP_DICT:
    127                                 fd_dict_dump(fd_g_config->cnf_dict);
    128                                 break;
    129                        
    130                         case FDEV_DUMP_EXT:
    131                                 fd_ext_dump();
    132                                 break;
    133                        
    134                         case FDEV_DUMP_SERV:
    135                                 fd_servers_dump();
    136                                 break;
    137                        
    138                         case FDEV_DUMP_QUEUES:
    139                                 fd_fifo_dump(0, "Incoming messages", fd_g_incoming, fd_msg_dump_walk);
    140                                 fd_fifo_dump(0, "Outgoing messages", fd_g_outgoing, fd_msg_dump_walk);
    141                                 fd_fifo_dump(0, "Local messages",    fd_g_local,    fd_msg_dump_walk);
    142                                 break;
    143                        
    144                         case FDEV_DUMP_CONFIG:
    145                                 fd_conf_dump();
    146                                 break;
    147                        
    148                         case FDEV_DUMP_PEERS:
    149                                 fd_peer_dump_list(FULL);
    150                                 break;
    151                        
    152                         case FDEV_TERMINATE:
    153                                 ret = 0;
    154                                 goto end;
    155                        
    156                         default:
    157                                 TRACE_DEBUG(INFO, "Unexpected event in the daemon (%d), ignored.\n", code);
    158                 }
    159         }
    160        
    161 end:
    162         TRACE_DEBUG(INFO, FD_PROJECT_BINARY " daemon is stopping...");
    163        
    164         /* cleanups */
    165         CHECK_FCT_DO( fd_servers_stop(), /* Stop accepting new connections */ );
    166         CHECK_FCT_DO( fd_rtdisp_cleanstop(), /* Stop dispatch thread(s) after a clean loop if possible */ );
    167         CHECK_FCT_DO( fd_peer_fini(), /* Stop all connections */ );
    168         CHECK_FCT_DO( fd_rtdisp_fini(), /* Stop routing threads and destroy routing queues */ );
    169        
    170         CHECK_FCT_DO( fd_ext_term(), /* Cleanup all extensions */ );
    171         CHECK_FCT_DO( fd_rtdisp_cleanup(), /* destroy remaining handlers */ );
    172        
    173         GNUTLS_TRACE( gnutls_global_deinit() );
    174        
    175         CHECK_FCT_DO( fd_conf_deinit(), );
    176        
    177         fd_log_debug(FD_PROJECT_BINARY " daemon is terminated.\n");
    178        
    179         fd_lib_fini();
    180        
    181         return ret;
    182 }
     46static void * catch_signals(void * arg);
     47static pthread_t signals_thr;
     48
     49static char *conffile = NULL;
     50static int gnutls_debug = 0;
    18351
    18452/* gnutls debug */
     
    18755}
    18856
    189 /* Parse the command-line */
    190 static int main_cmdline(int argc, char *argv[])
    191 {
    192         int c;
    193         int option_index = 0;
    194         char * locale;
    195        
    196         struct option long_options[] = {
    197                 { "help",       no_argument,            NULL, 'h' },
    198                 { "version",    no_argument,            NULL, 'V' },
    199                 { "config",     required_argument,      NULL, 'c' },
    200                 { "debug",      no_argument,            NULL, 'd' },
    201                 { "quiet",      no_argument,            NULL, 'q' },
    202                 { "dbglocale",  optional_argument,      NULL, 'l' },
    203                 { "dbg_func",   required_argument,      NULL, 'f' },
    204                 { "dbg_file",   required_argument,      NULL, 'F' },
    205                 { "dbg_gnutls", required_argument,      NULL, 'g' },
    206                 { NULL,         0,                      NULL, 0 }
    207         };
    208        
    209         TRACE_ENTRY("%d %p", argc, argv);
    210        
    211         /* Loop on arguments */
    212         while (1) {
    213                 c = getopt_long (argc, argv, "hVc:dql:", long_options, &option_index);
    214                 if (c == -1)
    215                         break;  /* Exit from the loop.  */
    216                
    217                 switch (c) {
    218                         case 'h':       /* Print help and exit.  */
    219                                 main_help();
    220                                 exit(0);
    221 
    222                         case 'V':       /* Print version and exit.  */
    223                                 main_version();
    224                                 exit(0);
    225 
    226                         case 'c':       /* Read configuration from this file instead of the default location..  */
    227                                 CHECK_PARAMS( optarg );
    228                                 fd_g_config->cnf_file = optarg;
    229                                 break;
    230 
    231                         case 'l':       /* Change the locale.  */
    232                                 locale = setlocale(LC_ALL, optarg?:"");
    233                                 if (locale) {
    234                                         TRACE_DEBUG(INFO, "Locale set to: %s", optarg ?: locale);
    235                                 } else {
    236                                         TRACE_DEBUG(INFO, "Unable to set locale (%s)", optarg);
    237                                         return EINVAL;
    238                                 }
    239                                 break;
    240 
    241                         case 'd':       /* Increase verbosity of debug messages.  */
    242                                 fd_g_debug_lvl++;
    243                                 break;
    244                                
    245                         case 'f':       /* Full debug for the function with this name.  */
    246                                 #ifdef DEBUG
    247                                 fd_debug_one_function = optarg;
    248                                 #else /* DEBUG */
    249                                 TRACE_DEBUG(INFO, "Error: must compile with DEBUG support to use this feature");
    250                                 return EINVAL;
    251                                 #endif /* DEBUG */
    252                                 break;
    253                                
    254                         case 'F':       /* Full debug for the file with this name.  */
    255                                 #ifdef DEBUG
    256                                 fd_debug_one_file = basename(optarg);
    257                                 #else /* DEBUG */
    258                                 TRACE_DEBUG(INFO, "Error: must compile with DEBUG support to use this feature");
    259                                 return EINVAL;
    260                                 #endif /* DEBUG */
    261                                 break;
    262                                
    263                         case 'g':       /* Full debug for the function with this name.  */
    264                                 {
    265                                         int l = (int)atoi(optarg);
    266                                         if (l) {
    267                                                 gnutls_global_set_log_function((gnutls_log_func)fd_gnutls_debug);
    268                                                 gnutls_global_set_log_level (l);
    269                                                 TRACE_DEBUG(INFO, "Enabled GNUTLS debug at level %d", l);
    270                                         }
    271                                 }
    272                                 break;
    273                                
    274                         case 'q':       /* Decrease verbosity then remove debug messages.  */
    275                                 fd_g_debug_lvl--;
    276                                 break;
    277 
    278                         case '?':       /* Invalid option.  */
    279                                 /* `getopt_long' already printed an error message.  */
    280                                 TRACE_DEBUG(INFO, "getopt_long found an invalid character");
    281                                 return EINVAL;
    282 
    283                         default:        /* bug: option not considered.  */
    284                                 TRACE_DEBUG(INFO, "A command-line option is missing in parser: %c", c);
    285                                 ASSERT(0);
    286                                 return EINVAL;
    287                 }
    288         }
    289                
     57
     58/* freeDiameter starting point */
     59int main(int argc, char * argv[])
     60{
     61        int ret;
     62        sigset_t sig_all;
     63       
     64        /* Block all signals from the current thread and all its future children */
     65        sigfillset(&sig_all);
     66        ret = pthread_sigmask(SIG_BLOCK, &sig_all, NULL);
     67        ASSERT(ret == 0);
     68       
     69        /* Parse the command-line */
     70        ret = main_cmdline(argc, argv);
     71        if (ret != 0) {
     72                return ret;
     73        }
     74       
     75        /* Initialize the core library */
     76        ret = fd_core_initialize();
     77        if (ret != 0) {
     78                fprintf(stderr, "An error occurred during freeDiameter core library initialization.\n");
     79                return ret;
     80        }
     81       
     82        /* Set gnutls debug level ? */
     83        if (gnutls_debug) {
     84                gnutls_global_set_log_function((gnutls_log_func)fd_gnutls_debug);
     85                gnutls_global_set_log_level (gnutls_debug);
     86                TRACE_DEBUG(INFO, "Enabled GNUTLS debug at level %d", gnutls_debug);
     87        }
     88               
     89        /* Allow SIGINT and SIGTERM from this point to terminate the application */
     90        CHECK_POSIX( pthread_create(&signals_thr, NULL, catch_signals, NULL) );
     91       
     92        /* Parse the configuration file */
     93        CHECK_FCT( fd_core_parseconf(conffile) );
     94       
     95        /* Start the servers */
     96        CHECK_FCT( fd_core_start() );
     97       
     98        TRACE_DEBUG(INFO, FD_PROJECT_BINARY " daemon initialized.");
     99       
     100        /* Now, just wait for termination */
     101        CHECK_FCT( fd_core_wait_shutdown_complete() );
     102       
     103        /* Just in case it was not the result of a signal, we cancel signals_thr */
     104        fd_thr_term(&signals_thr);
     105       
    290106        return 0;
    291107}
     108
    292109
    293110/* Display package version */
     
    302119                ")"
    303120#endif /* HG_VERSION */
    304                 "\n",
     121                " (libfdcore: %s)\n",
    305122                FD_PROJECT_NAME, FD_PROJECT_VERSION_MAJOR, FD_PROJECT_VERSION_MINOR, FD_PROJECT_VERSION_REV
    306123#ifdef HG_VERSION
     
    310127# endif /* PACKAGE_HG_VERSION */
    311128#endif /* HG_VERSION */
    312                 );
     129                , fd_core_version());
    313130}
    314131
     
    341158}
    342159
    343 /* Terminate the application */
    344 static void fd_shutdown(int signal)
    345 {
    346         TRACE_ENTRY("%d", signal);
    347        
    348         TRACE_DEBUG(INFO, "Received signal %s (%d), exiting", fd_sig_abbrev(signal), signal);
    349 
    350         CHECK_FCT_DO( fd_event_send(fd_g_config->cnf_main_ev, FDEV_TERMINATE, 0, NULL), exit(2) );
    351        
    352         return;
    353 }
    354 
    355 
    356 /* Signal extensions when the framework is completly initialized */
    357 static int             is_ready = 0;
    358 static pthread_mutex_t is_ready_mtx = PTHREAD_MUTEX_INITIALIZER;
    359 static pthread_cond_t  is_ready_cnd = PTHREAD_COND_INITIALIZER;
    360 static int signal_framework_ready(void)
    361 {
    362         TRACE_ENTRY("");
    363         CHECK_POSIX( pthread_mutex_lock( &is_ready_mtx ) );
    364         is_ready = 1;
    365         CHECK_POSIX( pthread_cond_broadcast( &is_ready_cnd ) );
    366         CHECK_POSIX( pthread_mutex_unlock( &is_ready_mtx ) );
     160/* Parse the command-line */
     161static int main_cmdline(int argc, char *argv[])
     162{
     163        int c;
     164        int option_index = 0;
     165        char * locale;
     166       
     167        struct option long_options[] = {
     168                { "help",       no_argument,            NULL, 'h' },
     169                { "version",    no_argument,            NULL, 'V' },
     170                { "config",     required_argument,      NULL, 'c' },
     171                { "debug",      no_argument,            NULL, 'd' },
     172                { "quiet",      no_argument,            NULL, 'q' },
     173                { "dbglocale",  optional_argument,      NULL, 'l' },
     174                { "dbg_func",   required_argument,      NULL, 'f' },
     175                { "dbg_file",   required_argument,      NULL, 'F' },
     176                { "dbg_gnutls", required_argument,      NULL, 'g' },
     177                { NULL,         0,                      NULL, 0 }
     178        };
     179       
     180        /* Loop on arguments */
     181        while (1) {
     182                c = getopt_long (argc, argv, "hVc:dql:", long_options, &option_index);
     183                if (c == -1)
     184                        break;  /* Exit from the loop.  */
     185               
     186                switch (c) {
     187                        case 'h':       /* Print help and exit.  */
     188                                main_help();
     189                                exit(0);
     190
     191                        case 'V':       /* Print version and exit.  */
     192                                main_version();
     193                                exit(0);
     194
     195                        case 'c':       /* Read configuration from this file instead of the default location..  */
     196                                if (optarg == NULL ) {
     197                                        fprintf(stderr, "Missing argument with --config directive\n");
     198                                        return EINVAL;
     199                                }
     200                                conffile = optarg;
     201                                break;
     202
     203                        case 'l':       /* Change the locale.  */
     204                                locale = setlocale(LC_ALL, optarg?:"");
     205                                if (!locale) {
     206                                        fprintf(stderr, "Unable to set locale (%s)\n", optarg);
     207                                        return EINVAL;
     208                                }
     209                                break;
     210
     211                        case 'd':       /* Increase verbosity of debug messages.  */
     212                                fd_g_debug_lvl++;
     213                                break;
     214                               
     215                        case 'f':       /* Full debug for the function with this name.  */
     216                                #ifdef DEBUG
     217                                fd_debug_one_function = optarg;
     218                                #else /* DEBUG */
     219                                fprintf(stderr, "Error: must compile with DEBUG support to use --dbg_func feature!\n");
     220                                return EINVAL;
     221                                #endif /* DEBUG */
     222                                break;
     223                               
     224                        case 'F':       /* Full debug for the file with this name.  */
     225                                #ifdef DEBUG
     226                                fd_debug_one_file = basename(optarg);
     227                                #else /* DEBUG */
     228                                fprintf(stderr, "Error: must compile with DEBUG support to use --dbg_file feature!\n");
     229                                return EINVAL;
     230                                #endif /* DEBUG */
     231                                break;
     232                               
     233                        case 'g':       /* Set a debug level and function for GNU TLS calls.  */
     234                                gnutls_debug = (int)atoi(optarg);
     235                                break;
     236                               
     237                        case 'q':       /* Decrease verbosity then remove debug messages.  */
     238                                fd_g_debug_lvl--;
     239                                break;
     240
     241                        case '?':       /* Invalid option.  */
     242                                /* `getopt_long' already printed an error message.  */
     243                                fprintf(stderr, "getopt_long found an invalid character\n");
     244                                return EINVAL;
     245
     246                        default:        /* bug: option not considered.  */
     247                                fprintf(stderr, "A command-line option is missing in parser: %c\n", c);
     248                                ASSERT(0);
     249                                return EINVAL;
     250                }
     251        }
     252               
    367253        return 0;
    368254}
    369 int fd_wait_initialization_complete(void)
    370 {
    371         TRACE_ENTRY("");
    372         CHECK_POSIX( pthread_mutex_lock( &is_ready_mtx ) );
    373         pthread_cleanup_push( fd_cleanup_mutex, &is_ready_mtx );
    374         while (!is_ready) {
    375                 CHECK_POSIX( pthread_cond_wait( &is_ready_cnd, &is_ready_mtx ) );
    376         }
    377         pthread_cleanup_pop( 0 );
    378         CHECK_POSIX( pthread_mutex_unlock( &is_ready_mtx ) );
    379         return 0;
    380 }
     255
     256/* Handle some signals */
     257static void * catch_signals(void * arg)
     258{
     259        sigset_t ss;
     260        fd_log_threadname ( "signals catcher" );
     261       
     262        sigemptyset(&ss);
     263       
     264        /* Signals that terminate the daemon */
     265        sigaddset(&ss, SIGTERM);
     266        sigaddset(&ss, SIGINT);
     267       
     268        /* Signals that send an event */
     269        sigaddset(&ss, SIGUSR1);
     270        sigaddset(&ss, SIGUSR2);
     271       
     272        /* Now loop on the reception of the signal */
     273        while (1) {
     274                int sig, *ps;
     275               
     276                /* Wait to receive the next signal */
     277                CHECK_POSIX_DO( sigwait(&ss, &sig), break );
     278               
     279                TRACE_DEBUG(FULL, "Signal %d caught", sig);
     280               
     281                switch (sig) {
     282                        case SIGUSR1:
     283                        case SIGUSR2:
     284                                CHECK_MALLOC_DO( ps = malloc(sizeof(int)), goto out);
     285                                *ps = sig;
     286                                CHECK_FCT_DO( fd_event_send(fd_g_config->cnf_main_ev, FDEV_TRIGGER, sizeof(int), ps), goto out );
     287                                break;
     288                               
     289                        case SIGINT:
     290                        case SIGTERM:
     291                                CHECK_FCT_DO( fd_core_shutdown(), goto out );
     292
     293                }
     294        }
     295out:   
     296        /* Better way to handle this ? */
     297        ASSERT(0);
     298        return NULL;
     299}
  • include/freeDiameter/CMakeLists.txt

    r561 r658  
    11#CMake configuration for freeDiameter include directory
    22
    3 Project("freeDiameter include directory" C)
     3Project("freeDiameter includes directory" C)
    44
    55########################
     
    6868ENDIF (HAVE_CLOCK_GETTIME)
    6969
    70 # LFD_LIBS = libraries required by the libfreeDiameter.
    71 SET(LFD_LIBS ${CLOCK_GETTIME_LIBS} ${CMAKE_THREAD_LIBS_INIT})
     70# LFDPROTO_LIBS = libraries required by the libfdproto.
     71SET(LFDPROTO_LIBS ${CLOCK_GETTIME_LIBS} ${CMAKE_THREAD_LIBS_INIT})
    7272
    7373
     
    9898
    9999
    100 # FD_LIBS = libraries required by the daemon
    101 SET(FD_LIBS ${CMAKE_DL_LIBS} ${SCTP_LIBRARIES})
     100# Require GNU TLS for building the library
     101FIND_PACKAGE(GnuTLS REQUIRED)
     102INCLUDE_DIRECTORIES(${GNUTLS_INCLUDE_DIR})
     103
     104find_path(GCRYPT_INCLUDE_DIR NAMES gcrypt.h)
     105If ( NOT GCRYPT_INCLUDE_DIR )
     106        MESSAGE(SEND_ERROR "Unable to find gcrypt.h, please install libgcrypt-dev or equivalent")
     107Endif ( NOT GCRYPT_INCLUDE_DIR )
     108MARK_AS_ADVANCED(GCRYPT_INCLUDE_DIR)
     109INCLUDE_DIRECTORIES(${GCRYPT_INCLUDE_DIR})
     110
     111# Also we need libgcrypt to... display its version :(
     112find_library(GCRYPT_LIBRARY
     113  NAMES gcrypt
     114)
     115If ( NOT GCRYPT_LIBRARY )
     116        MESSAGE(SEND_ERROR "Unable to find libgcrypt, please install libgcrypt or equivalent")
     117Endif ( NOT GCRYPT_LIBRARY )
     118
     119
     120# LFDCORE_LIBS = libraries required by the libfdcore
     121SET(LFDCORE_LIBS ${CMAKE_DL_LIBS} ${SCTP_LIBRARIES} ${GCRYPT_LIBRARY} ${GNUTLS_LIBRARIES})
    102122
    103123##########################
     
    111131
    112132# Save some variables for the other directories
    113 SET(FD_LIBS  ${FD_LIBS} PARENT_SCOPE)
    114 SET(LFD_LIBS ${LFD_LIBS} PARENT_SCOPE)
     133SET(LFDPROTO_LIBS ${LFDPROTO_LIBS} PARENT_SCOPE)
     134SET(LFDCORE_LIBS  ${LFDCORE_LIBS} PARENT_SCOPE)
    115135SET(CMAKE_THREAD_LIBS_INIT ${CMAKE_THREAD_LIBS_INIT} PARENT_SCOPE)
    116136
     
    119139
    120140# The headers from this directory are required to develop new extensions for freeDiameter.
    121 INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/freeDiameter-host.h libfreeDiameter.h freeDiameter.h extension.h
     141INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/freeDiameter-host.h libfdproto.h libfdcore.h extension.h
    122142        DESTINATION ${INSTALL_HEADERS_SUFFIX}
    123143        COMPONENT freeDiameter-dev)
  • include/freeDiameter/extension.h

    r8 r658  
    33* Author: Sebastien Decugis <sdecugis@nict.go.jp>                                                        *
    44*                                                                                                        *
    5 * Copyright (c) 2009, WIDE Project and NICT                                                              *
     5* Copyright (c) 2011, WIDE Project and NICT                                                              *
    66* All rights reserved.                                                                                   *
    77*                                                                                                        *
     
    3939/* Include definition of freeDiameter API */
    4040#include <freeDiameter/freeDiameter-host.h>
    41 #include <freeDiameter/freeDiameter.h>
     41#include <freeDiameter/libfdcore.h>
    4242
    4343/* Macro that define the entry point of the extension */
  • include/freeDiameter/freeDiameter-host.h.in

    r648 r658  
    7575#cmakedefine DEFAULT_EXTENSIONS_PATH "@DEFAULT_EXTENSIONS_PATH@"
    7676
     77#ifndef FD_DEFAULT_CONF_FILENAME
     78#define FD_DEFAULT_CONF_FILENAME "freeDiameter.conf"
     79#endif /* FD_DEFAULT_CONF_FILENAME */
     80
    7781#endif /* FD_IS_CONFIG */
  • include/freeDiameter/libfdcore.h

    r648 r658  
    3434*********************************************************************************************************/
    3535
    36 #ifndef _FREEDIAMETER_H
    37 #define _FREEDIAMETER_H
    38 
    39 
    40 #include <freeDiameter/libfreeDiameter.h>
     36#ifndef _LIBFDCORE_H
     37#define _LIBFDCORE_H
     38
     39
     40#include <freeDiameter/libfdproto.h>
    4141#include <gnutls/gnutls.h>
    4242#include <gnutls/x509.h>
     
    6868        (__call__);                                                     \
    6969}
     70
     71
     72/*============================================================*/
     73/*                      INITIALIZATION                        */
     74/*============================================================*/
     75
     76
     77/* Initialize the libfdcore internals. This also initializes libfdproto */
     78int fd_core_initialize(void);
     79
     80/* Return a string describing the version of the library */
     81const char *fd_core_version(void);
     82
     83/* Parse the freeDiameter.conf configuration file, load the extensions */
     84int fd_core_parseconf(char * conffile);
     85
     86/* Start the server & client threads */
     87int fd_core_start(void);
     88
     89/* Block until the framework has completed its initialization -- useful for extensions */
     90int fd_core_waitstartcomplete(void);
     91
     92/* Initialize shutdown of the framework */
     93int fd_core_shutdown(void);
     94
     95/* Wait for the shutdown to be complete -- this should always be called after fd_core_shutdown */
     96int fd_core_wait_shutdown_complete(void);
     97
     98
     99/*============================================================*/
     100/*                          CONFIG                            */
     101/*============================================================*/
    70102
    71103/* Structure to hold the configuration of the freeDiameter daemon */
     
    129161
    130162
    131 /***************************************/
    132 /*   Peers information                 */
    133 /***************************************/
     163
     164/*============================================================*/
     165/*                         PEERS                              */
     166/*============================================================*/
    134167
    135168/* States of a peer */
     
    366399 */
    367400
    368 /***************************************/
    369 /*   Sending a message on the network  */
    370 /***************************************/
     401
     402
     403/*============================================================*/
     404/*                         MESSAGES                           */
     405/*============================================================*/
    371406
    372407/*
     
    444479
    445480
    446 /***************************************/
    447 /*   Dispatch module, daemon's part    */
    448 /***************************************/
     481
     482
     483/*============================================================*/
     484/*                         DISPATCH                           */
     485/*============================================================*/
    449486
    450487/*
     
    471508
    472509
    473 /***************************************/
    474 /*          Routing module             */
    475 /***************************************/
     510/*============================================================*/
     511/*                         ROUTING                            */
     512/*============================================================*/
    476513
    477514/* This file contains the definitions of types and functions involved in the routing decisions in freeDiameter,
     
    661698
    662699
    663 /***************************************/
    664 /*   Events helpers                    */
    665 /***************************************/
     700/*============================================================*/
     701/*                         EVENTS                             */
     702/*============================================================*/
    666703
    667704struct fd_event {
     
    671708};
    672709
    673 /* Daemon's codespace: 1000->1999 (1500->1999 defined in fD.h) */
     710/* Daemon's codespace: 1000->1999 (1500->1999 defined in fdcore-internal.h) */
    674711enum {
    675712         FDEV_TERMINATE = 1000  /* request to terminate */
     
    680717        ,FDEV_DUMP_CONFIG       /* Dump the configuration */
    681718        ,FDEV_DUMP_PEERS        /* Dump the list of peers */
     719        ,FDEV_TRIGGER           /* Trigger available for extensions. size is sizeof(int), data is int * */
    682720};
    683721
     
    688726const char * fd_ev_str(int event);
    689727
    690 
    691 /* The following function does not really use events, but it may be used
    692 by extensions that need to start an action when the framework is fully initialized.
    693 This function will block until all initializations are performed in the daemon.
    694 It is meant to be used as follow by extensions:
    695  - in initialization callback, create a new thread.
    696  - this new thread calls this function.
    697  - when the function returns, the thread can start working and using all framework features.
    698 */
    699 int fd_wait_initialization_complete(void);
    700 
    701 
    702 /***************************************/
    703 /*   Endpoints lists helpers           */
    704 /***************************************/
     728/* for extensions */
     729int fd_event_trig_regcb(int trigger_val, const char * module, void (*cb)(void));
     730void fd_event_trig_dump();
     731
     732
     733/*============================================================*/
     734/*                         ENDPOINTS                          */
     735/*============================================================*/
    705736
    706737struct fd_endpoint {
     
    737768void fd_ep_dump( int indent, struct fd_list * eps );
    738769
    739 /***************************************/
    740 /*   Applications lists helpers        */
    741 /***************************************/
     770
     771/*============================================================*/
     772/*                         APPLICATIONS IDs                   */
     773/*============================================================*/
    742774
    743775struct fd_app {
     
    756788int fd_app_empty(struct fd_list * list);
    757789
    758 #endif /* _FREEDIAMETER_H */
     790#endif /* _LIBFDCORE_H */
  • include/freeDiameter/libfdproto.h

    r653 r658  
    5454 */
    5555
    56 #ifndef _LIBFREEDIAMETER_H
    57 #define _LIBFREEDIAMETER_H
     56#ifndef _LIBFDPROTO_H
     57#define _LIBFDPROTO_H
    5858
    5959#ifndef FD_IS_CONFIG
     
    8383
    8484/* This function must be called first, before any call to another library function */
    85 /* If the parameter is not 0, the support for signals (fd_sig_register) is enabled, otherwise it is disabled */
    86 /* The function must be called while the application is single-threaded to enable support for signals */
    87 int fd_lib_init(int support_signals);
     85int fd_libproto_init(void); /* note if you are using libfdcore, it handles this already */
    8886
    8987/* Call this one when the application terminates, to destroy internal threads */
    90 void fd_lib_fini(void);
     88void fd_libproto_fini(void);
    9189
    9290
     
    633631}
    634632
    635 /*============================================================*/
    636 /*                          SIGNALS                           */
    637 /*============================================================*/
    638 
    639 /* Register a new callback to be called on reception of a given signal (it receives the signal as parameter) */
    640 /* EALREADY will be returned if there is already a callback registered on this signal */
    641 /* NOTE: the signal handler will be called from a new detached thread */
    642 int fd_sig_register(int signal, char * modname, void (*callback)(int signal));
    643 
    644 /* Remove the handler for a given signal */
    645 int fd_sig_unregister(int signal);
    646 
    647 /* Dump list of handlers */
    648 void fd_sig_dump(int level, int indent);
    649 
    650 /* Name of signals */
    651 const char * fd_sig_abbrev(int signal);
    652 
    653633
    654634/*============================================================*/
     
    28122792void fd_fifo_dump(int level, char * name, struct fifo * queue, void (*dump_item)(int level, void * item));
    28132793
    2814 #endif /* _LIBFREEDIAMETER_H */
     2794#endif /* _LIBFDPROTO_H */
  • libfdcore/CMakeLists.txt

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    r378 r658  
    3434*********************************************************************************************************/
    3535
    36 #include "fD.h"
     36#include "fdcore-internal.h"
    3737#include "cnxctx.h"
    3838
  • libfdproto/CMakeLists.txt

    r320 r658  
    11# Name of the subproject
    2 Project("libfreeDiameter" C)
     2Project("libfdproto" C)
    33
    44# List of source files for the library
    5 SET(LFD_SRC
    6         libfD.h
     5SET(LFDPROTO_SRC
     6        fdproto-internal.h
    77        dictionary.c
    88        dispatch.c
     
    1414        rt_data.c
    1515        sessions.c
    16         signal.c
    1716        )
    1817
    19 # Save the list of files for testcases in the daemon's directory
    20 SET(LFD_SRC ${LFD_SRC} PARENT_SCOPE)
     18# Save the list of files for testcases in the core's directory
     19SET(LFDPROTO_SRC ${LFDPROTO_SRC} PARENT_SCOPE)
    2120
    2221# Build as a shared library
    23 ADD_LIBRARY(libfreeDiameter SHARED ${LFD_SRC})
     22ADD_LIBRARY(libfdproto SHARED ${LFDPROTO_SRC})
    2423
    2524# Avoid the liblib name, and set the version
    26 SET_TARGET_PROPERTIES(libfreeDiameter PROPERTIES
    27         OUTPUT_NAME "freeDiameter"
     25SET_TARGET_PROPERTIES(libfdproto PROPERTIES
     26        OUTPUT_NAME "fdproto"
    2827        SOVERSION ${FD_PROJECT_VERSION_API}
    2928        VERSION ${FD_PROJECT_VERSION_MAJOR}.${FD_PROJECT_VERSION_MINOR}.${FD_PROJECT_VERSION_REV})
    3029
    3130# The library itself needs other libraries
    32 TARGET_LINK_LIBRARIES(libfreeDiameter ${LFD_LIBS})
     31TARGET_LINK_LIBRARIES(libfdproto ${LFDPROTO_LIBS})
    3332
    3433
     
    3635## INSTALL section ##
    3736
    38 INSTALL(TARGETS libfreeDiameter
     37INSTALL(TARGETS libfdproto
    3938        LIBRARY DESTINATION ${INSTALL_LIBRARY_SUFFIX}
    4039        COMPONENT freeDiameter-common)
  • libfdproto/dictionary.c

    r602 r658  
    3434*********************************************************************************************************/
    3535
    36 #include "libfD.h"
     36#include "fdproto-internal.h"
    3737
    3838/* Names of the base types */
     
    323323                                                obj->objeyec, OBJECT_EYECATCHER,
    324324                                                obj->typeyec, _OBINFO(obj).eyecatcher);
     325                        } else {
     326                                TRACE_DEBUG(FULL, "Invalid object : NULL pointer");
    325327                        }
    326328                        return 0;
     
    552554}
    553555
    554 /* Compare two rule object by the AVP name that they refer (checks already performed) */
     556/* Compare two rule object by the AVP vendor & code that they refer (checks already performed) */
    555557static int order_rule_by_avpn ( struct dict_object *o1, struct dict_object *o2 )
    556558{
    557559        TRACE_ENTRY("%p %p", o1, o2);
    558560       
    559         return strcmp( o1->data.rule.rule_avp->data.avp.avp_name, o2->data.rule.rule_avp->data.avp.avp_name );
     561        return ORDER_scalar(o1->data.rule.rule_avp->data.avp.avp_vendor, o2->data.rule.rule_avp->data.avp.avp_vendor)
     562                ?: ORDER_scalar(o1->data.rule.rule_avp->data.avp.avp_code, o2->data.rule.rule_avp->data.avp.avp_code) ;
    560563}
    561564
     
    14961499        struct dict_object * new = NULL;
    14971500        struct dict_object * vendor = NULL;
     1501        struct dict_object * locref = NULL;
    14981502       
    14991503        TRACE_ENTRY("%p %d(%s) %p %p %p", dict, type, dict_obj_info[CHECK_TYPE(type) ? type : 0].name, data, parent, ref);
     
    15251529        if (type == DICT_AVP) {
    15261530                CHECK_FCT_DO(  fd_dict_search( dict, DICT_VENDOR, VENDOR_BY_ID, &(((struct dict_avp_data *)data)->avp_vendor), (void*)&vendor, ENOENT ),
    1527                                 CHECK_PARAMS( vendor = NULL )  );
     1531                        { TRACE_DEBUG(INFO, "Unable to find vendor '%d' referenced in the AVP data", ((struct dict_avp_data *)data)->avp_vendor); return EINVAL; }  );
    15281532               
    15291533                /* Also check if a parent is provided, that the type are the same */
     
    15681572                case DICT_VENDOR:
    15691573                        /* A vendor object is linked in the g_dict_vendors.list[0], by their id */
    1570                         CHECK_FCT_DO(  ret = fd_list_insert_ordered ( &dict->dict_vendors.list[0], &new->list[0], (int (*)(void*, void *))order_vendor_by_id, (void **)ref ),
    1571                                         goto error_unlock  );
     1574                        ret = fd_list_insert_ordered ( &dict->dict_vendors.list[0], &new->list[0], (int (*)(void*, void *))order_vendor_by_id, (void **)&locref );
     1575                        if (ret)
     1576                                goto error_unlock;
    15721577                        break;
    15731578               
    15741579                case DICT_APPLICATION:
    15751580                        /* An application object is linked in the g_dict_applciations.list[0], by their id */
    1576                         CHECK_FCT_DO(  ret = fd_list_insert_ordered ( &dict->dict_applications.list[0], &new->list[0], (int (*)(void*, void *))order_appli_by_id, (void **)ref ),
    1577                                         goto error_unlock  );
     1581                        ret = fd_list_insert_ordered ( &dict->dict_applications.list[0], &new->list[0], (int (*)(void*, void *))order_appli_by_id, (void **)&locref );
     1582                        if (ret)
     1583                                goto error_unlock;
    15781584                        break;
    15791585               
    15801586                case DICT_TYPE:
    15811587                        /* A type object is linked in g_list_types by its name */
    1582                         CHECK_FCT_DO(  ret = fd_list_insert_ordered ( &dict->dict_types, &new->list[0], (int (*)(void*, void *))order_type_by_name, (void **)ref ),
    1583                                         goto error_unlock  );
     1588                        ret = fd_list_insert_ordered ( &dict->dict_types, &new->list[0], (int (*)(void*, void *))order_type_by_name, (void **)&locref );
     1589                        if (ret)
     1590                                goto error_unlock;
    15841591                        break;
    15851592               
    15861593                case DICT_ENUMVAL:
    15871594                        /* A type_enum object is linked in it's parent 'type' object lists 1 and 2 by its name and values */
    1588                         CHECK_FCT_DO(  ret = fd_list_insert_ordered ( &parent->list[1], &new->list[0], (int (*)(void*, void *))order_enum_by_name, (void **)ref ),
    1589                                         goto error_unlock  );
    1590                         CHECK_FCT_DO(  ret = fd_list_insert_ordered ( &parent->list[2], &new->list[1], (int (*)(void*, void *))order_enum_by_val, (void **)ref ),
    1591                                         { fd_list_unlink(&new->list[0]); goto error_unlock; }  );
     1595                        ret = fd_list_insert_ordered ( &parent->list[1], &new->list[0], (int (*)(void*, void *))order_enum_by_name, (void **)&locref );
     1596                        if (ret)
     1597                                goto error_unlock;
     1598                       
     1599                        ret = fd_list_insert_ordered ( &parent->list[2], &new->list[1], (int (*)(void*, void *))order_enum_by_val, (void **)&locref );
     1600                        if (ret) {
     1601                                fd_list_unlink(&new->list[0]);
     1602                                goto error_unlock;
     1603                        }
    15921604                        break;
    15931605               
    15941606                case DICT_AVP:
    15951607                        /* An avp object is linked in lists 1 and 2 of its vendor, by code and name */
    1596                         CHECK_FCT_DO(  ret = fd_list_insert_ordered ( &vendor->list[1], &new->list[0], (int (*)(void*, void *))order_avp_by_code, (void **)ref ),
    1597                                         goto error_unlock  );
    1598                         CHECK_FCT_DO(  ret = fd_list_insert_ordered ( &vendor->list[2], &new->list[1], (int (*)(void*, void *))order_avp_by_name, (void **)ref ),
    1599                                         { fd_list_unlink(&new->list[0]); goto error_unlock; }  );
     1608                        ret = fd_list_insert_ordered ( &vendor->list[1], &new->list[0], (int (*)(void*, void *))order_avp_by_code, (void **)&locref );
     1609                        if (ret)
     1610                                goto error_unlock;
     1611                       
     1612                        ret = fd_list_insert_ordered ( &vendor->list[2], &new->list[1], (int (*)(void*, void *))order_avp_by_name, (void **)&locref );
     1613                        if (ret) {
     1614                                fd_list_unlink(&new->list[0]);
     1615                                goto error_unlock;
     1616                        }
    16001617                        break;
    16011618                       
    16021619                case DICT_COMMAND:
    16031620                        /* A command object is linked in g_list_cmd_name and g_list_cmd_code by its name and code */
    1604                         CHECK_FCT_DO(  ret = fd_list_insert_ordered ( &dict->dict_cmd_code, &new->list[1], (int (*)(void*, void *))order_cmd_by_codefl, (void **)ref ),
    1605                                         goto error_unlock  );
    1606                         CHECK_FCT_DO(  ret = fd_list_insert_ordered ( &dict->dict_cmd_name, &new->list[0], (int (*)(void*, void *))order_cmd_by_name, (void **)ref ),
    1607                                         { fd_list_unlink(&new->list[1]); goto error_unlock; }  );
     1621                        ret = fd_list_insert_ordered ( &dict->dict_cmd_code, &new->list[1], (int (*)(void*, void *))order_cmd_by_codefl, (void **)&locref );
     1622                        if (ret)
     1623                                goto error_unlock;
     1624                       
     1625                        ret = fd_list_insert_ordered ( &dict->dict_cmd_name, &new->list[0], (int (*)(void*, void *))order_cmd_by_name, (void **)&locref );
     1626                        if (ret) {
     1627                                fd_list_unlink(&new->list[1]);
     1628                                goto error_unlock;
     1629                        }
    16081630                        break;
    16091631               
    16101632                case DICT_RULE:
    16111633                        /* A rule object is linked in list[2] of its parent command or AVP by the name of the AVP it refers */
    1612                         CHECK_FCT_DO(  ret = fd_list_insert_ordered ( &parent->list[2], &new->list[0], (int (*)(void*, void *))order_rule_by_avpn, (void **)ref ),
    1613                                         goto error_unlock  );
     1634                        ret = fd_list_insert_ordered ( &parent->list[2], &new->list[0], (int (*)(void*, void *))order_rule_by_avpn, (void **)&locref );
     1635                        if (ret)
     1636                                goto error_unlock;
    16141637                        break;
    16151638                       
     
    16321655error_unlock:
    16331656        CHECK_POSIX_DO(  pthread_rwlock_unlock(&dict->dict_lock),  /* continue */  );
     1657        if (ret == EEXIST) {
     1658                /* We have a duplicate key in locref. Check if the pointed object is the same or not */
     1659                switch (type) {
     1660                        case DICT_VENDOR:
     1661                                /* if we are here, it meas the two vendor id are identical */
     1662                                if (strcmp(locref->data.vendor.vendor_name, new->data.vendor.vendor_name)) {
     1663                                        TRACE_DEBUG(FULL, "Conflicting vendor name");
     1664                                        break;
     1665                                }
     1666                                /* Otherwise (same name), we consider the function succeeded, since the (same) object is in the dictionary */
     1667                                ret = 0;
     1668                                break;
     1669
     1670                        case DICT_APPLICATION:
     1671                                /* got same id */
     1672                                if (strcmp(locref->data.application.application_name, new->data.application.application_name)) {
     1673                                        TRACE_DEBUG(FULL, "Conflicting application name");
     1674                                        break;
     1675                                }
     1676                                ret = 0;
     1677                                break;
     1678
     1679                        case DICT_TYPE:
     1680                                /* got same name */
     1681                                if (locref->data.type.type_base != new->data.type.type_base) {
     1682                                        TRACE_DEBUG(FULL, "Conflicting base type");
     1683                                        break;
     1684                                }
     1685                                /* discard new definition only it a callback is provided and different from the previous one */
     1686                                if ((new->data.type.type_interpret) && (locref->data.type.type_interpret != new->data.type.type_interpret)) {
     1687                                        TRACE_DEBUG(FULL, "Conflicting interpret cb");
     1688                                        break;
     1689                                }
     1690                                if ((new->data.type.type_encode) && (locref->data.type.type_encode != new->data.type.type_encode)) {
     1691                                        TRACE_DEBUG(FULL, "Conflicting encode cb");
     1692                                        break;
     1693                                }
     1694                                if ((new->data.type.type_dump) && (locref->data.type.type_dump != new->data.type.type_dump)) {
     1695                                        TRACE_DEBUG(FULL, "Conflicting dump cb");
     1696                                        break;
     1697                                }
     1698                                ret = 0;
     1699                                break;
     1700
     1701                        case DICT_ENUMVAL:
     1702                                /* got either same name or same value. We check that both are true */
     1703                                if (order_enum_by_name(locref, new)) {
     1704                                        TRACE_DEBUG(FULL, "Conflicting enum name");
     1705                                        break;
     1706                                }
     1707                                if (order_enum_by_val(locref, new)) {
     1708                                        TRACE_DEBUG(FULL, "Conflicting enum value");
     1709                                        break;
     1710                                }
     1711                                ret = 0;
     1712                                break;
     1713
     1714                        case DICT_AVP:
     1715                                /* got either same name or code */
     1716                                if (order_avp_by_code(locref, new)) {
     1717                                        TRACE_DEBUG(FULL, "Conflicting AVP code");
     1718                                        break;
     1719                                }
     1720                                if (order_avp_by_name(locref, new)) {
     1721                                        TRACE_DEBUG(FULL, "Conflicting AVP name");
     1722                                        break;
     1723                                }
     1724                                if  (locref->data.avp.avp_vendor != new->data.avp.avp_vendor) {
     1725                                        TRACE_DEBUG(FULL, "Conflicting AVP vendor");
     1726                                        break;
     1727                                }
     1728                                if  (locref->data.avp.avp_flag_mask != new->data.avp.avp_flag_mask) {
     1729                                        TRACE_DEBUG(FULL, "Conflicting AVP flags mask");
     1730                                        break;
     1731                                }
     1732                                if  ((locref->data.avp.avp_flag_val & locref->data.avp.avp_flag_mask) != (new->data.avp.avp_flag_val & new->data.avp.avp_flag_mask)) {
     1733                                        TRACE_DEBUG(FULL, "Conflicting AVP flags value");
     1734                                        break;
     1735                                }
     1736                                if  (locref->data.avp.avp_basetype != new->data.avp.avp_basetype) {
     1737                                        TRACE_DEBUG(FULL, "Conflicting AVP base type");
     1738                                        break;
     1739                                }
     1740                                ret = 0;
     1741                                break;
     1742
     1743                        case DICT_COMMAND:
     1744                                /* We got either same name, or same code + R flag */
     1745                                if (order_cmd_by_name(locref, new)) {
     1746                                        TRACE_DEBUG(FULL, "Conflicting command name");
     1747                                        break;
     1748                                }
     1749                                if (locref->data.cmd.cmd_code != new->data.cmd.cmd_code) {
     1750                                        TRACE_DEBUG(FULL, "Conflicting command code");
     1751                                        break;
     1752                                }
     1753                                if (locref->data.cmd.cmd_flag_mask != new->data.cmd.cmd_flag_mask) {
     1754                                        TRACE_DEBUG(FULL, "Conflicting command flags mask %hhx:%hhx", locref->data.cmd.cmd_flag_mask, new->data.cmd.cmd_flag_mask);
     1755                                        break;
     1756                                }
     1757                                if ((locref->data.cmd.cmd_flag_val & locref->data.cmd.cmd_flag_mask) != (new->data.cmd.cmd_flag_val & new->data.cmd.cmd_flag_mask)) {
     1758                                        TRACE_DEBUG(FULL, "Conflicting command flags value");
     1759                                        break;
     1760                                }
     1761                                ret = 0;
     1762                                break;
     1763
     1764                        case DICT_RULE:
     1765                                /* Both rules point to the same AVPs */
     1766                                if (locref->data.rule.rule_position != new->data.rule.rule_position) {
     1767                                        TRACE_DEBUG(FULL, "Conflicting rule position");
     1768                                        break;
     1769                                }
     1770                                if ( ((locref->data.rule.rule_position == RULE_FIXED_HEAD) ||
     1771                                        (locref->data.rule.rule_position == RULE_FIXED_TAIL))
     1772                                    && (locref->data.rule.rule_order != new->data.rule.rule_order)) {
     1773                                        TRACE_DEBUG(FULL, "Conflicting rule order");
     1774                                        break;
     1775                                }
     1776                                if (locref->data.rule.rule_min != new->data.rule.rule_min) {
     1777                                        int r1 = locref->data.rule.rule_min;
     1778                                        int r2 = new->data.rule.rule_min;
     1779                                        int p  = locref->data.rule.rule_position;
     1780                                        if (  ((r1 != -1) && (r2 != -1)) /* none of the definitions contains the "default" value */
     1781                                           || ((p == RULE_OPTIONAL) && (r1 != 0) && (r2 != 0)) /* the other value is not 0 for an optional rule */
     1782                                           || ((r1 != 1) && (r2 != 1)) /* the other value is not 1 for another rule */
     1783                                        ) {
     1784                                                TRACE_DEBUG(FULL, "Conflicting rule min");
     1785                                                break;
     1786                                        }
     1787                                }
     1788                                if (locref->data.rule.rule_max != new->data.rule.rule_max) {
     1789                                        TRACE_DEBUG(FULL, "Conflicting rule max");
     1790                                        break;
     1791                                }
     1792                                ret = 0;
     1793                                break;
     1794                }
     1795                if (ret) {
     1796                        TRACE_DEBUG(INFO, "An existing object with different non-key data was found: EEXIST");
     1797                } else {
     1798                        TRACE_DEBUG(FULL, "An existing object with the same data was found, ignoring the error...");
     1799                }
     1800                if (ref)
     1801                        *ref = locref;
     1802        } else {
     1803                CHECK_FCT_DO( ret, ); /* log the error */
     1804        }
     1805
    16341806error_free:
    16351807        free(new);
  • libfdproto/dispatch.c

    r648 r658  
    3434*********************************************************************************************************/
    3535
    36 #include "libfD.h"
     36#include "fdproto-internal.h"
    3737
    3838/* The dispatch module in the library is quite simple: callbacks are saved in a global list
  • libfdproto/fdproto-internal.h

    r291 r658  
    3434*********************************************************************************************************/
    3535
    36 /* This file contains the definitions for internal use in the libfreeDiameter library */
     36/* This file contains the definitions for internal use in the freeDiameter protocol library */
    3737
    38 #ifndef _LIBFD_H
    39 #define _LIBFD_H
     38#ifndef _LIBFDPROTO_INTERNAL_H
     39#define _LIBFDPROTO_INTERNAL_H
    4040
    4141#include <freeDiameter/freeDiameter-host.h>
    42 #include <freeDiameter/libfreeDiameter.h>
     42#include <freeDiameter/libfdproto.h>
    4343
    4444/* Internal to the library */
     
    4747int fd_sess_init(void);
    4848void fd_sess_fini(void);
    49 int fd_sig_init(void);
    50 void fd_sig_fini(void);
    5149
    5250/* Iterator on the rules of a parent object */
     
    6563int fd_sess_reclaim_msg ( struct session ** session );
    6664
    67 #endif /* _LIBFD_H */
     65#endif /* _LIBFDPROTO_INTERNAL_H */
  • libfdproto/fifo.c

    r451 r658  
    4646 */
    4747
    48 #include "libfD.h"
     48#include "fdproto-internal.h"
    4949
    5050/* Definition of a FIFO queue object */
  • libfdproto/init.c

    r454 r658  
    3434*********************************************************************************************************/
    3535
    36 #include "libfD.h"
     36#include "fdproto-internal.h"
    3737
    3838/* Only for CPU cache flush */
     
    4040
    4141/* Initialize library variables and threads */
    42 int fd_lib_init(int support_signals)
     42int fd_libproto_init()
    4343{
    4444        int ret = 0;
     
    5151        }
    5252       
    53         /* Initialize signals if requested */
    54         if (support_signals) {
    55                 CHECK_FCT( fd_sig_init() );
    56         }
    57        
    5853        /* Initialize the modules that need it */
    5954        fd_msg_eteid_init();
     
    6459
    6560/* Stop all threads created in the library */
    66 void fd_lib_fini(void)
     61void fd_libproto_fini(void)
    6762{
    6863        fd_sess_fini();
    69         fd_sig_fini();
    7064}
  • libfdproto/lists.c

    r83 r658  
    3434*********************************************************************************************************/
    3535
    36 #include "libfD.h"
     36#include "fdproto-internal.h"
    3737
    3838/* Initialize a list element */
  • libfdproto/log.c

    r653 r658  
    3434*********************************************************************************************************/
    3535
    36 #include "libfD.h"
     36#include "fdproto-internal.h"
    3737
    3838#include <stdarg.h>
  • libfdproto/messages.c

    r656 r658  
    3939 */
    4040
    41 #include "libfD.h"
     41#include "fdproto-internal.h"
    4242
    4343#include <sys/param.h>
  • libfdproto/rt_data.c

    r563 r658  
    3939 */
    4040
    41 #include "libfD.h"
     41#include "fdproto-internal.h"
    4242
    4343/* Structure that contains the routing data for a message */
  • libfdproto/sessions.c

    r639 r658  
    3939 */
    4040
    41 #include "libfD.h"
     41#include "fdproto-internal.h"
    4242
    4343/*********************** Parameters **********************/
  • tests/CMakeLists.txt

    r585 r658  
    11# Test directory
    2 PROJECT("libfreeDiameter tests" C)
     2PROJECT("freeDiameter tests" C)
    33
    44# give the possibility to configure the timeout duration for the tests
     
    2828ADD_DEFINITIONS(-DTRACE_LEVEL=NONE)
    2929
    30 INCLUDE_DIRECTORIES( ".." )
    31 INCLUDE_DIRECTORIES( "../../libfreeDiameter" )
    32 
    33 BISON_FILE(../fdd.y)
    34 FLEX_FILE(../fdd.l)
    35 
    36 SET(TEST_COMMON_SRC "")
    37 
    38 FOREACH( SRC_FILE ${FD_COMMON_SRC})
    39    SET(TEST_COMMON_SRC ${TEST_COMMON_SRC} "../${SRC_FILE}")
    40 ENDFOREACH(SRC_FILE)
    41 
    42 FOREACH( SRC_FILE ${FD_COMMON_GEN_SRC})
    43    SET(TEST_COMMON_SRC ${TEST_COMMON_SRC} "${CMAKE_CURRENT_BINARY_DIR}/../${SRC_FILE}")
    44 ENDFOREACH(SRC_FILE)
    45 
    46 FOREACH( SRC_FILE ${LFD_SRC})
    47    SET(TEST_COMMON_SRC ${TEST_COMMON_SRC} "../../libfreeDiameter/${SRC_FILE}")
    48 ENDFOREACH(SRC_FILE)
    49 
    50 # Create an archive with the daemon common files (all but main)
    51 ADD_LIBRARY(fDcore STATIC ${TEST_COMMON_SRC})
     30INCLUDE_DIRECTORIES( "../libfdproto" )
     31INCLUDE_DIRECTORIES( "../libfdcore" )
    5232
    5333
     
    7252
    7353                # List of source files, copied from the extension CMakeLists.
    74                 BISON_FILE(../../extensions/app_acct/acct_conf.y)
    75                 FLEX_FILE(../../extensions/app_acct/acct_conf.l)
     54                BISON_FILE(../extensions/app_acct/acct_conf.y)
     55                FLEX_FILE(../extensions/app_acct/acct_conf.l)
    7656                #SET_SOURCE_FILES_PROPERTIES(lex.acct_conf.c acct_conf.tab.c PROPERTIES COMPILE_FLAGS "-I ${CMAKE_CURRENT_SOURCE_DIR}")
    7757               
     
    8969
    9070                # The extension headers
    91                 INCLUDE_DIRECTORIES( "../../extensions/app_acct" )
     71                INCLUDE_DIRECTORIES( "../extensions/app_acct" )
    9272
    9373                SET(testappacct_ADDITIONAL "")
    9474
    9575                FOREACH( SRC_FILE ${APP_ACCT_SRC})
    96                    SET(testappacct_ADDITIONAL ${testappacct_ADDITIONAL} "../../extensions/app_acct/${SRC_FILE}")
     76                   SET(testappacct_ADDITIONAL ${testappacct_ADDITIONAL} "../extensions/app_acct/${SRC_FILE}")
    9777                ENDFOREACH(SRC_FILE)
    9878
    9979                FOREACH( SRC_FILE ${APP_ACCT_SRC_GEN})
    100                    SET(testappacct_ADDITIONAL ${testappacct_ADDITIONAL} "${CMAKE_CURRENT_BINARY_DIR}/../../extensions/app_acct/${SRC_FILE}")
     80                   SET(testappacct_ADDITIONAL ${testappacct_ADDITIONAL} "${CMAKE_CURRENT_BINARY_DIR}/../extensions/app_acct/${SRC_FILE}")
    10181                ENDFOREACH(SRC_FILE)
    10282
     
    10989FOREACH( TEST ${TEST_LIST} )
    11090   ADD_EXECUTABLE(${TEST} ${TEST}.c tests.h ${${TEST}_ADDITIONAL})
    111    TARGET_LINK_LIBRARIES(${TEST} fDcore ${FD_LIBS} ${LFD_LIBS} ${${TEST}_ADDITIONAL_LIB})
     91   TARGET_LINK_LIBRARIES(${TEST} libfdproto libfdcore ${${TEST}_ADDITIONAL_LIB})
    11292   ADD_TEST(${TEST} ${EXECUTABLE_OUTPUT_PATH}/${TEST})
    11393ENDFOREACH( TEST )
  • tests/tests.h

    r481 r658  
    4242#define _TESTS_H
    4343
    44 #include "libfD.h"
    45 #include "fD.h"
     44#include "fdproto-internal.h"
     45#include "fdcore-internal.h"
    4646
    4747#include <pthread.h>
     
    8282struct fd_config * fd_g_config = &conf;
    8383
    84 /* gcrypt functions to support posix threads */
    85 GCRY_THREAD_OPTION_PTHREAD_IMPL;
    86 
    8784/* Define the standard check routines */
    8885#define CHECK( _val, _assert ){                         \
     
    105102}
    106103
    107 /* Minimum inits */
    108 #define INIT_FD() {                                                             \
    109         memset(fd_g_config, 0, sizeof(struct fd_config));                       \
    110         CHECK( 0, fd_lib_init(1) );                                             \
    111         fd_log_threadname(basename(__FILE__));                                  \
    112         (void) gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);    \
    113         (void) gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);                   \
    114         CHECK( 0, gnutls_global_init());                                        \
    115         CHECK( 0, fd_conf_init() );                                             \
    116         CHECK( 0, fd_dict_base_protocol(fd_g_config->cnf_dict) );               \
    117         CHECK( 0, fd_sess_start() );                                            \
    118         parse_cmdline(argc, argv);                                              \
     104static pthread_t timeout_thr;
     105static void * timeout_catch(void * arg)
     106{
     107        int sig;
     108        sigset_t ss;
     109        fd_log_threadname ( "timeout catcher" );
     110       
     111        sigemptyset(&ss);
     112        sigaddset(&ss, SIGALRM);
     113       
     114        CHECK_POSIX_DO( sigwait(&ss, &sig),  );
     115       
     116        FAILTEST("The timeout (" _stringize(TEST_TIMEOUT) " sec) was reached. Use -n or change TEST_TIMEOUT if the test needs more time to execute.");
     117       
     118        return NULL;
    119119}
     120       
    120121
    121 static void test_timeout(int signal)
    122 {
    123         FAILTEST("The timeout (" _stringize(TEST_TIMEOUT) " sec) was reached. Use -n or change TEST_TIMEOUT if the test needs more time to execute.");
    124 }
     122GCRY_THREAD_OPTION_PTHREAD_IMPL;
    125123
    126124static inline void parse_cmdline(int argc, char * argv[]) {
     
    164162        if (!no_timeout) {
    165163                alarm(TEST_TIMEOUT);
    166                 fd_sig_register(SIGALRM, "Test.harness", test_timeout);
     164                CHECK( 0, pthread_create(&timeout_thr, NULL, timeout_catch, NULL) );
    167165        }
    168166}
    169167 
     168static inline void test_init(int argc, char * argv[])
     169{
     170        memset(fd_g_config, 0, sizeof(struct fd_config));
     171       
     172        CHECK( 0, fd_libproto_init() );
     173       
     174        fd_log_threadname(basename(__FILE__));
     175       
     176        /* Initialize gcrypt and gnutls */
     177        (void) gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
     178        (void) gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
     179        CHECK( 0, gnutls_global_init());
     180       
     181        /* Initialize the config */
     182        CHECK( 0, fd_conf_init() );
     183
     184        /* Add definitions of the base protocol */
     185        CHECK( 0, fd_dict_base_protocol(fd_g_config->cnf_dict) );
     186       
     187        /* Initialize only the sessions */
     188        CHECK( 0, fd_sess_start()  );
     189       
     190        /* Parse the command line */
     191        parse_cmdline(argc, argv);
     192       
     193        return;
     194}
     195#define INIT_FD()  test_init(argc, argv);
     196
    170197#endif /* _TESTS_H */
Note: See TracChangeset for help on using the changeset viewer.