Changeset 658:f198d16fa7f4 in freeDiameter
- Timestamp:
- Jan 14, 2011, 3:15:23 PM (13 years ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 1 added
- 1 deleted
- 16 edited
- 1 copied
- 53 moved
Legend:
- Unmodified
- Added
- Removed
-
CMakeLists.txt
r647 r658 11 11 # Version of the source code 12 12 SET(FD_PROJECT_VERSION_MAJOR 1) 13 SET(FD_PROJECT_VERSION_MINOR 0)14 SET(FD_PROJECT_VERSION_REV 4)13 SET(FD_PROJECT_VERSION_MINOR 1) 14 SET(FD_PROJECT_VERSION_REV 0) 15 15 16 16 # Version of the API with the library 17 SET(FD_PROJECT_VERSION_API 3)17 SET(FD_PROJECT_VERSION_API 4) 18 18 19 19 # The test framework, using CTest and CDash. … … 31 31 SET(INSTALL_HEADERS_SUFFIX include/freeDiameter CACHE PATH "Directory where the headers are installed (relative to CMAKE_INSTALL_PREFIX).") 32 32 SET(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 isinstalled (relative to CMAKE_INSTALL_PREFIX).")33 SET(INSTALL_LIBRARY_SUFFIX lib CACHE PATH "Directory where the freeDiameter libraries are installed (relative to CMAKE_INSTALL_PREFIX).") 34 34 SET(INSTALL_EXTENSIONS_SUFFIX ${INSTALL_LIBRARY_SUFFIX}/freeDiameter CACHE PATH "Directory where the extensions are installed / searched (relative to CMAKE_INSTALL_PREFIX).") 35 35 … … 77 77 78 78 # Location for the source code 79 SUBDIRS(libfreeDiameter) 80 SUBDIRS(freeDiameter) 79 SUBDIRS(libfdproto) 80 SUBDIRS(libfdcore) 81 SUBDIRS(freeDiameterd) 81 82 82 83 # Extensions (there is no use of freeDiameter without any extension) 83 84 SUBDIRS(extensions) 85 86 # The unary tests directory 87 IF ( BUILD_TESTING ) 88 SUBDIRS(tests) 89 ENDIF ( BUILD_TESTING ) 90 -
contrib/debian/control
r631 r658 13 13 Architecture: any 14 14 Depends: ${shlibs:Depends}, ${misc:Depends} 15 Description: The libfreeDiameter library.16 This library is required by all freeDiameter components.15 Description: The freeDiameter libraries. 16 This package contains the libraries required by all freeDiameter components. 17 17 It may also be useful for other projects which need to 18 18 perform operations on Diameter messages. -
contrib/debian/freediameter-common.install
r328 r658 1 usr/lib/libfreeDiameter.so* 1 usr/lib/libfdproto.so* 2 usr/lib/libfdcore.so* -
extensions/dbg_interactive/CMakeLists.txt
r641 r658 16 16 SET(SWIG_MODULE_fDpy_EXTRA_DEPS 17 17 ${CMAKE_BINARY_DIR}/include/freeDiameter/freeDiameter-host.h 18 ${CMAKE_SOURCE_DIR}/include/freeDiameter/libf reeDiameter.h19 ${CMAKE_SOURCE_DIR}/include/freeDiameter/ freeDiameter.h18 ${CMAKE_SOURCE_DIR}/include/freeDiameter/libfdcore.h 19 ${CMAKE_SOURCE_DIR}/include/freeDiameter/libfdproto.h 20 20 lists.i 21 21 dictionary.i -
extensions/dbg_interactive/dbg_interactive.c
r639 r658 59 59 fd_log_threadname ( "fDpy" ); 60 60 61 CHECK_FCT_DO(fd_ wait_initialization_complete(), goto end);61 CHECK_FCT_DO(fd_core_waitstartcomplete(), goto end); 62 62 63 63 fd_log_debug("\nStarting interactive python interpreter [experimental].\n"); -
extensions/dbg_interactive/dbg_interactive.i
r641 r658 159 159 *********************************************************/ 160 160 %include "freeDiameter/freeDiameter-host.h" 161 %include "freeDiameter/libf reeDiameter.h"162 %include "freeDiameter/ freeDiameter.h"161 %include "freeDiameter/libfdproto.h" 162 %include "freeDiameter/libfdcore.h" 163 163 164 164 /* Most of the functions from the API are not directly usable "as is". -
extensions/dbg_monitor/dbg_monitor.c
r258 r658 78 78 79 79 /* Function called on receipt of MONITOR_SIGNAL */ 80 static void got_sig( int signal)80 static void got_sig() 81 81 { 82 82 fd_log_debug("[dbg_monitor] Dumping extra information\n"); … … 92 92 93 93 /* 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)); 95 95 96 96 CHECK_POSIX( pthread_create( &thr, NULL, mn_thr, NULL ) ); -
extensions/dict_eap/dict_eap.c
r10 r658 296 296 268, /* Code */ 297 297 "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 */ 299 299 CMD_FLAG_REQUEST | CMD_FLAG_PROXIABLE /* Fixed flag values */ 300 300 }; -
extensions/dict_legacy_xml/dict_lxml_xml.c
r616 r658 933 933 { TRACE_DEBUG(INFO, "Invalid 'type' tag found without 'name' attribute."); goto xml_tree_error; } ); 934 934 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 */ 935 942 CHECK_FCT_DO( new_avptype(&data->cur_avp->type, xname), 936 943 { TRACE_DEBUG(INFO, "An error occurred while parsing a type tag. Entry ignored."); goto xml_tree_error; } ) … … 1011 1018 } 1012 1019 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 } 1013 1029 return; 1014 1030 } … … 1387 1403 1388 1404 /* 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; } ); 1390 1407 if (nb_added) 1391 1408 *nb_added += 1; … … 1398 1415 static 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) 1399 1416 { 1417 int ret; 1418 1400 1419 TRACE_ENTRY("%p %p %p %p %p %p", fD_dict, parent, fixed, required, optional, nb_added); 1401 1420 1402 1421 /* 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; } ); 1406 1428 1407 1429 return 0; … … 1425 1447 ad.avp_vendor = a->vendor; 1426 1448 ad.avp_name = (char *)a->name; 1427 ad.avp_flag_mask = a->fmask ;1449 ad.avp_flag_mask = a->fmask | AVP_FLAG_VENDOR; 1428 1450 ad.avp_flag_val = a->flags; 1429 1451 1430 1452 if (!FD_IS_LIST_EMPTY(&a->type)) { 1431 1453 /* 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))) 1433 1458 goto enumerated; 1434 1459 … … 1441 1466 || !FD_IS_LIST_EMPTY(&a->grouped_fixed) ) { 1442 1467 /* 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; } ); 1444 1470 ad.avp_basetype = AVP_TYPE_GROUPED; 1445 1471 } else { 1446 1472 /* It should be an enumerated AVP... */ 1447 1473 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); 1449 1475 return EINVAL; 1450 1476 } else { … … 1492 1518 /* Now, the inner elements, if any */ 1493 1519 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 1494 1525 /* 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 */1496 1526 for (li = a->enums.next; li != &a->enums; li = li->next) { 1497 1527 struct t_enum * e = (struct t_enum *)li; … … 1502 1532 ed.enum_value.u32 = e->code; 1503 1533 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 } ); 1505 1539 if (nb_added) 1506 1540 *nb_added += 1; … … 1511 1545 || !FD_IS_LIST_EMPTY(&a->grouped_required) 1512 1546 || !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; } ); 1515 1551 } 1516 1552 … … 1536 1572 snprintf(cmdname, sizeof(cmdname), "%s-Request", (char *)c->name); 1537 1573 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; 1539 1575 cd.cmd_flag_val = c->flags | CMD_FLAG_REQUEST; 1540 1576 … … 1564 1600 snprintf(cmdname, sizeof(cmdname), "%s-Answer", (char *)c->name); 1565 1601 cd.cmd_flag_val &= ~CMD_FLAG_REQUEST; 1602 cd.cmd_flag_mask &= ~CMD_FLAG_ERROR; 1566 1603 1567 1604 ret = fd_dict_new ( fD_dict, DICT_COMMAND, &cd, fd_appl, &ans ); … … 1585 1622 rules: 1586 1623 /* 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 } ); 1589 1634 1590 1635 /* Done */ … … 1641 1686 /* First, define all the types */ 1642 1687 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 } ); 1644 1693 } 1645 1694 1646 1695 /* Then, AVPs, enums, and grouped AVP rules */ 1647 1696 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 } ); 1649 1702 } 1650 1703 1651 1704 /* Finally, the commands and rules */ 1652 1705 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 } ); 1654 1711 } 1655 1712 … … 1662 1719 { 1663 1720 struct fd_list * li; 1721 int ret; 1664 1722 1665 1723 TRACE_ENTRY("%p %p %p", fD_dict, xmldict, nb_added); … … 1671 1729 /* Create all the vendors */ 1672 1730 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 } ); 1674 1736 } 1675 1737 1676 1738 /* 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 } ); 1678 1744 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 } ); 1680 1750 } 1681 1751 … … 1725 1795 } 1726 1796 1727 TRACE_DEBUG(FULL, "XML file parsing complete.");1797 TRACE_DEBUG(FULL, "XML file parsing, 1st pass completed."); 1728 1798 if (TRACE_BOOL(ANNOYING)) { 1729 1799 dump_dict(&data.dict); … … 1731 1801 1732 1802 /* 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); 1736 1811 if (TRACE_BOOL(ANNOYING)) { 1737 1812 fd_dict_dump(fd_g_config->cnf_dict); -
extensions/dict_nasreq/dict_nasreq.c
r523 r658 3005 3005 265, /* Code */ 3006 3006 "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 */ 3008 3008 CMD_FLAG_REQUEST | CMD_FLAG_PROXIABLE /* Fixed flag values */ 3009 3009 }; -
extensions/test_app/ta_bench.c
r575 r658 208 208 209 209 /* The function called when the signal is received */ 210 static void ta_bench_start( int sig) {210 static void ta_bench_start() { 211 211 struct timespec end_time, now; 212 212 struct ta_stats start, end; … … 274 274 CHECK_SYS( sem_init( &ta_sem, 0, ta_conf->bench_concur) ); 275 275 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 ) ); 277 277 278 278 return 0; … … 281 281 void ta_bench_fini(void) 282 282 { 283 CHECK_FCT_DO( fd_sig_unregister(ta_conf->signal), /* continue */ );283 // CHECK_FCT_DO( fd_sig_unregister(ta_conf->signal), /* continue */ ); 284 284 285 285 CHECK_SYS_DO( sem_destroy(&ta_sem), ); -
extensions/test_app/ta_cli.c
r639 r658 136 136 137 137 /* Create a test message */ 138 static void ta_cli_test_message( int sig)138 static void ta_cli_test_message() 139 139 { 140 140 struct msg * req = NULL; … … 236 236 CHECK_FCT( fd_sess_handler_create(&ta_cli_reg, free, NULL) ); 237 237 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 ) ); 239 239 240 240 return 0; … … 243 243 void ta_cli_fini(void) 244 244 { 245 CHECK_FCT_DO( fd_sig_unregister(ta_conf->signal), /* continue */ );245 // CHECK_FCT_DO( fd_sig_unregister(ta_conf->signal), /* continue */ ); 246 246 247 247 CHECK_FCT_DO( fd_sess_handler_destroy(&ta_cli_reg, NULL), /* continue */ ); -
extensions/test_sip/test_sip.c
r639 r658 215 215 216 216 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 ) ); 220 220 221 221 return 0; -
freeDiameterd/CMakeLists.txt
r592 r658 1 1 # 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 2 Project("freeDiameter simple daemon" C) 72 3 73 4 # Build the executable 74 ADD_EXECUTABLE(freeDiameterd ${FD_COMMON_SRC} ${FD_COMMON_GEN_SRC}main.c)5 ADD_EXECUTABLE(freeDiameterd main.c) 75 6 76 7 # The version … … 79 10 80 11 # 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 ) 12 TARGET_LINK_LIBRARIES(freeDiameterd libfdproto libfdcore) 88 13 89 14 #### -
freeDiameterd/main.c
r628 r658 34 34 *********************************************************************************************************/ 35 35 36 #include "fD.h" 36 #include <freeDiameter/freeDiameter-host.h> 37 #include <freeDiameter/libfdcore.h> 37 38 38 39 #include <signal.h> 39 40 #include <getopt.h> 40 41 #include <locale.h> 41 #include <gcrypt.h> 42 42 43 43 44 /* forward declarations */ 44 static void fd_shutdown(int signal);45 45 static 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 } 46 static void * catch_signals(void * arg); 47 static pthread_t signals_thr; 48 49 static char *conffile = NULL; 50 static int gnutls_debug = 0; 183 51 184 52 /* gnutls debug */ … … 187 55 } 188 56 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 */ 59 int 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 290 106 return 0; 291 107 } 108 292 109 293 110 /* Display package version */ … … 302 119 ")" 303 120 #endif /* HG_VERSION */ 304 " \n",121 " (libfdcore: %s)\n", 305 122 FD_PROJECT_NAME, FD_PROJECT_VERSION_MAJOR, FD_PROJECT_VERSION_MINOR, FD_PROJECT_VERSION_REV 306 123 #ifdef HG_VERSION … … 310 127 # endif /* PACKAGE_HG_VERSION */ 311 128 #endif /* HG_VERSION */ 312 );129 , fd_core_version()); 313 130 } 314 131 … … 341 158 } 342 159 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 */ 161 static 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 367 253 return 0; 368 254 } 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 */ 257 static 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 } 295 out: 296 /* Better way to handle this ? */ 297 ASSERT(0); 298 return NULL; 299 } -
include/freeDiameter/CMakeLists.txt
r561 r658 1 1 #CMake configuration for freeDiameter include directory 2 2 3 Project("freeDiameter include directory" C)3 Project("freeDiameter includes directory" C) 4 4 5 5 ######################## … … 68 68 ENDIF (HAVE_CLOCK_GETTIME) 69 69 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. 71 SET(LFDPROTO_LIBS ${CLOCK_GETTIME_LIBS} ${CMAKE_THREAD_LIBS_INIT}) 72 72 73 73 … … 98 98 99 99 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 101 FIND_PACKAGE(GnuTLS REQUIRED) 102 INCLUDE_DIRECTORIES(${GNUTLS_INCLUDE_DIR}) 103 104 find_path(GCRYPT_INCLUDE_DIR NAMES gcrypt.h) 105 If ( NOT GCRYPT_INCLUDE_DIR ) 106 MESSAGE(SEND_ERROR "Unable to find gcrypt.h, please install libgcrypt-dev or equivalent") 107 Endif ( NOT GCRYPT_INCLUDE_DIR ) 108 MARK_AS_ADVANCED(GCRYPT_INCLUDE_DIR) 109 INCLUDE_DIRECTORIES(${GCRYPT_INCLUDE_DIR}) 110 111 # Also we need libgcrypt to... display its version :( 112 find_library(GCRYPT_LIBRARY 113 NAMES gcrypt 114 ) 115 If ( NOT GCRYPT_LIBRARY ) 116 MESSAGE(SEND_ERROR "Unable to find libgcrypt, please install libgcrypt or equivalent") 117 Endif ( NOT GCRYPT_LIBRARY ) 118 119 120 # LFDCORE_LIBS = libraries required by the libfdcore 121 SET(LFDCORE_LIBS ${CMAKE_DL_LIBS} ${SCTP_LIBRARIES} ${GCRYPT_LIBRARY} ${GNUTLS_LIBRARIES}) 102 122 103 123 ########################## … … 111 131 112 132 # Save some variables for the other directories 113 SET( FD_LIBS ${FD_LIBS}PARENT_SCOPE)114 SET(LFD _LIBS ${LFD_LIBS}PARENT_SCOPE)133 SET(LFDPROTO_LIBS ${LFDPROTO_LIBS} PARENT_SCOPE) 134 SET(LFDCORE_LIBS ${LFDCORE_LIBS} PARENT_SCOPE) 115 135 SET(CMAKE_THREAD_LIBS_INIT ${CMAKE_THREAD_LIBS_INIT} PARENT_SCOPE) 116 136 … … 119 139 120 140 # The headers from this directory are required to develop new extensions for freeDiameter. 121 INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/freeDiameter-host.h libf reeDiameter.h freeDiameter.h extension.h141 INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/freeDiameter-host.h libfdproto.h libfdcore.h extension.h 122 142 DESTINATION ${INSTALL_HEADERS_SUFFIX} 123 143 COMPONENT freeDiameter-dev) -
include/freeDiameter/extension.h
r8 r658 3 3 * Author: Sebastien Decugis <sdecugis@nict.go.jp> * 4 4 * * 5 * Copyright (c) 20 09, WIDE Project and NICT *5 * Copyright (c) 2011, WIDE Project and NICT * 6 6 * All rights reserved. * 7 7 * * … … 39 39 /* Include definition of freeDiameter API */ 40 40 #include <freeDiameter/freeDiameter-host.h> 41 #include <freeDiameter/ freeDiameter.h>41 #include <freeDiameter/libfdcore.h> 42 42 43 43 /* Macro that define the entry point of the extension */ -
include/freeDiameter/freeDiameter-host.h.in
r648 r658 75 75 #cmakedefine DEFAULT_EXTENSIONS_PATH "@DEFAULT_EXTENSIONS_PATH@" 76 76 77 #ifndef FD_DEFAULT_CONF_FILENAME 78 #define FD_DEFAULT_CONF_FILENAME "freeDiameter.conf" 79 #endif /* FD_DEFAULT_CONF_FILENAME */ 80 77 81 #endif /* FD_IS_CONFIG */ -
include/freeDiameter/libfdcore.h
r648 r658 34 34 *********************************************************************************************************/ 35 35 36 #ifndef _ FREEDIAMETER_H37 #define _ FREEDIAMETER_H38 39 40 #include <freeDiameter/libf reeDiameter.h>36 #ifndef _LIBFDCORE_H 37 #define _LIBFDCORE_H 38 39 40 #include <freeDiameter/libfdproto.h> 41 41 #include <gnutls/gnutls.h> 42 42 #include <gnutls/x509.h> … … 68 68 (__call__); \ 69 69 } 70 71 72 /*============================================================*/ 73 /* INITIALIZATION */ 74 /*============================================================*/ 75 76 77 /* Initialize the libfdcore internals. This also initializes libfdproto */ 78 int fd_core_initialize(void); 79 80 /* Return a string describing the version of the library */ 81 const char *fd_core_version(void); 82 83 /* Parse the freeDiameter.conf configuration file, load the extensions */ 84 int fd_core_parseconf(char * conffile); 85 86 /* Start the server & client threads */ 87 int fd_core_start(void); 88 89 /* Block until the framework has completed its initialization -- useful for extensions */ 90 int fd_core_waitstartcomplete(void); 91 92 /* Initialize shutdown of the framework */ 93 int fd_core_shutdown(void); 94 95 /* Wait for the shutdown to be complete -- this should always be called after fd_core_shutdown */ 96 int fd_core_wait_shutdown_complete(void); 97 98 99 /*============================================================*/ 100 /* CONFIG */ 101 /*============================================================*/ 70 102 71 103 /* Structure to hold the configuration of the freeDiameter daemon */ … … 129 161 130 162 131 /***************************************/ 132 /* Peers information */ 133 /***************************************/ 163 164 /*============================================================*/ 165 /* PEERS */ 166 /*============================================================*/ 134 167 135 168 /* States of a peer */ … … 366 399 */ 367 400 368 /***************************************/ 369 /* Sending a message on the network */ 370 /***************************************/ 401 402 403 /*============================================================*/ 404 /* MESSAGES */ 405 /*============================================================*/ 371 406 372 407 /* … … 444 479 445 480 446 /***************************************/ 447 /* Dispatch module, daemon's part */ 448 /***************************************/ 481 482 483 /*============================================================*/ 484 /* DISPATCH */ 485 /*============================================================*/ 449 486 450 487 /* … … 471 508 472 509 473 /* **************************************/474 /* Routing module*/475 /* **************************************/510 /*============================================================*/ 511 /* ROUTING */ 512 /*============================================================*/ 476 513 477 514 /* This file contains the definitions of types and functions involved in the routing decisions in freeDiameter, … … 661 698 662 699 663 /* **************************************/664 /* Events helpers*/665 /* **************************************/700 /*============================================================*/ 701 /* EVENTS */ 702 /*============================================================*/ 666 703 667 704 struct fd_event { … … 671 708 }; 672 709 673 /* Daemon's codespace: 1000->1999 (1500->1999 defined in f D.h) */710 /* Daemon's codespace: 1000->1999 (1500->1999 defined in fdcore-internal.h) */ 674 711 enum { 675 712 FDEV_TERMINATE = 1000 /* request to terminate */ … … 680 717 ,FDEV_DUMP_CONFIG /* Dump the configuration */ 681 718 ,FDEV_DUMP_PEERS /* Dump the list of peers */ 719 ,FDEV_TRIGGER /* Trigger available for extensions. size is sizeof(int), data is int * */ 682 720 }; 683 721 … … 688 726 const char * fd_ev_str(int event); 689 727 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 */ 729 int fd_event_trig_regcb(int trigger_val, const char * module, void (*cb)(void)); 730 void fd_event_trig_dump(); 731 732 733 /*============================================================*/ 734 /* ENDPOINTS */ 735 /*============================================================*/ 705 736 706 737 struct fd_endpoint { … … 737 768 void fd_ep_dump( int indent, struct fd_list * eps ); 738 769 739 /***************************************/ 740 /* Applications lists helpers */ 741 /***************************************/ 770 771 /*============================================================*/ 772 /* APPLICATIONS IDs */ 773 /*============================================================*/ 742 774 743 775 struct fd_app { … … 756 788 int fd_app_empty(struct fd_list * list); 757 789 758 #endif /* _ FREEDIAMETER_H */790 #endif /* _LIBFDCORE_H */ -
include/freeDiameter/libfdproto.h
r653 r658 54 54 */ 55 55 56 #ifndef _LIBF REEDIAMETER_H57 #define _LIBF REEDIAMETER_H56 #ifndef _LIBFDPROTO_H 57 #define _LIBFDPROTO_H 58 58 59 59 #ifndef FD_IS_CONFIG … … 83 83 84 84 /* 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); 85 int fd_libproto_init(void); /* note if you are using libfdcore, it handles this already */ 88 86 89 87 /* Call this one when the application terminates, to destroy internal threads */ 90 void fd_lib _fini(void);88 void fd_libproto_fini(void); 91 89 92 90 … … 633 631 } 634 632 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 653 633 654 634 /*============================================================*/ … … 2812 2792 void fd_fifo_dump(int level, char * name, struct fifo * queue, void (*dump_item)(int level, void * item)); 2813 2793 2814 #endif /* _LIBF REEDIAMETER_H */2794 #endif /* _LIBFDPROTO_H */ -
libfdcore/CMakeLists.txt
r592 r658 1 1 # The subproject name 2 Project("freeDiameter d" C)2 Project("freeDiameter core library" C) 3 3 4 4 # Configuration parser … … 8 8 9 9 # List of source files 10 SET(FD _COMMON_SRC11 f D.h10 SET(FDCORE_SRC 11 fdcore-internal.h 12 12 apps.c 13 13 cnxctx.h 14 14 config.c 15 core.c 15 16 cnxctx.c 16 17 endpoints.c … … 35 36 36 37 IF(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) 38 39 ENDIF(NOT DISABLE_SCTP) 39 40 40 SET(FD _COMMON_GEN_SRC41 SET(FDCORE_GEN_SRC 41 42 lex.fdd.c 42 43 fdd.tab.c … … 45 46 46 47 # 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 48 SET(FDCORE_SRC ${FDCORE_SRC} PARENT_SCOPE) 49 SET(FDCORE_GEN_SRC ${FDCORE_GEN_SRC} PARENT_SCOPE) 71 50 72 51 73 52 # Build the executable 74 ADD_ EXECUTABLE(freeDiameterd ${FD_COMMON_SRC} ${FD_COMMON_GEN_SRC} main.c)53 ADD_LIBRARY(libfdcore SHARED ${FDCORE_SRC} ${FDCORE_GEN_SRC}) 75 54 76 # The version 77 SET_TARGET_PROPERTIES(freeDiameterd PROPERTIES 55 # Avoid the liblib name, and set the version 56 SET_TARGET_PROPERTIES(libfdcore PROPERTIES 57 OUTPUT_NAME "fdcore" 58 SOVERSION ${FD_PROJECT_VERSION_API} 78 59 VERSION ${FD_PROJECT_VERSION_MAJOR}.${FD_PROJECT_VERSION_MINOR}.${FD_PROJECT_VERSION_REV}) 79 60 80 # The li nk command81 LINK_DIRECTORIES(${CURRENT_BINARY_DIR}/../libf reeDiameter)82 TARGET_LINK_LIBRARIES( freeDiameterd libfreeDiameter ${FD_LIBS})61 # The library itself needs other libraries 62 LINK_DIRECTORIES(${CURRENT_BINARY_DIR}/../libfdproto) 63 TARGET_LINK_LIBRARIES(libfdcore libfdproto ${LFDCORE_LIBS}) 83 64 84 # The unary tests directory85 IF ( BUILD_TESTING )86 SUBDIRS(tests)87 ENDIF ( BUILD_TESTING )88 65 89 66 #### 90 67 ## INSTALL section ## 91 68 92 INSTALL(TARGETS freeDiameterd93 RUNTIME DESTINATION ${INSTALL_DAEMON_SUFFIX}94 COMPONENT freeDiameter- daemon)69 INSTALL(TARGETS libfdcore 70 LIBRARY DESTINATION ${INSTALL_LIBRARY_SUFFIX} 71 COMPONENT freeDiameter-common) -
libfdcore/apps.c
r648 r658 34 34 *********************************************************************************************************/ 35 35 36 #include "f D.h"36 #include "fdcore-internal.h" 37 37 38 38 /* Merge information into a list of apps */ -
libfdcore/cnxctx.c
r591 r658 34 34 *********************************************************************************************************/ 35 35 36 #include "f D.h"36 #include "fdcore-internal.h" 37 37 #include "cnxctx.h" 38 38 -
libfdcore/config.c
r578 r658 34 34 *********************************************************************************************************/ 35 35 36 #include "f D.h"36 #include "fdcore-internal.h" 37 37 #include <sys/stat.h> 38 38 … … 46 46 #endif /* GNUTLS_DEFAULT_DHBITS */ 47 47 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 */ 49 49 int fd_conf_init() 50 50 { -
libfdcore/dict_base_proto.c
r336 r658 37 37 */ 38 38 39 #include "f D.h"39 #include "fdcore-internal.h" 40 40 41 41 #include <netinet/in.h> -
libfdcore/endpoints.c
r640 r658 34 34 *********************************************************************************************************/ 35 35 36 #include "f D.h"36 #include "fdcore-internal.h" 37 37 38 38 -
libfdcore/events.c
r82 r658 34 34 *********************************************************************************************************/ 35 35 36 #include "fD.h" 36 #include "fdcore-internal.h" 37 38 /* Events are a subset of fifo queues, with a known type */ 37 39 38 40 int fd_event_send(struct fifo *queue, int code, size_t datasz, void * data) … … 110 112 case_str(FDEV_DUMP_CONFIG); 111 113 case_str(FDEV_DUMP_PEERS); 114 case_str(FDEV_TRIGGER); 112 115 113 116 default: … … 117 120 } 118 121 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 */ 128 static pthread_rwlock_t trig_rwl = PTHREAD_RWLOCK_INITIALIZER; 129 static struct fd_list trig_list = FD_LIST_INITIALIZER(trig_list); /* The list of triggers ordered by trigger value */ 130 struct 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 */ 138 int 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 170 void 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 186 static 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 195 int 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 221 int 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 34 34 *********************************************************************************************************/ 35 35 36 #include "f D.h"36 #include "fdcore-internal.h" 37 37 38 38 #include <dlfcn.h> /* We may use libtool's <ltdl.h> later for better portability.... */ -
libfdcore/fdcore-internal.h
r649 r658 34 34 *********************************************************************************************************/ 35 35 36 /* This file contains the definitions for internal use in the freeDiameter daemon*/37 38 #ifndef _FD _H39 #define _FD _H36 /* This file contains the definitions for internal use in the freeDiameter core library */ 37 38 #ifndef _FDCORE_INTERNAL_H 39 #define _FDCORE_INTERNAL_H 40 40 41 41 #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> 47 43 48 44 #ifdef DISABLE_SCTP … … 106 102 int fd_queues_init(void); 107 103 int fd_queues_fini(struct fifo ** queue); 104 105 /* Trigged events */ 106 int fd_event_trig_call_cb(int trigger_val); 107 int fd_event_trig_fini(void); 108 108 109 109 /* Create all the dictionary objects defined in the Diameter base RFC. */ … … 345 345 #define FD_CNX_BROADCAST (1 << 1) /* The message is sent over all stream pairs, in case of SCTP. No effect on TCP */ 346 346 347 #endif /* _FD _H */347 #endif /* _FDCORE_INTERNAL_H */ -
libfdcore/fdd.l
r578 r658 43 43 %{ 44 44 /* Include the daemon's header files */ 45 #include "f D.h"45 #include "fdcore-internal.h" 46 46 /* Include yacc tokens definitions */ 47 47 #include "fdd.tab.h" -
libfdcore/fdd.y
r578 r658 53 53 54 54 %{ 55 #include "f D.h"55 #include "fdcore-internal.h" 56 56 #include "fdd.tab.h" /* bug : bison does not define the YYLTYPE before including this bloc, so... */ 57 57 -
libfdcore/messages.c
r648 r658 34 34 *********************************************************************************************************/ 35 35 36 #include "f D.h"36 #include "fdcore-internal.h" 37 37 38 38 static struct dict_object * dict_avp_OH = NULL; /* Origin-Host */ -
libfdcore/p_ce.c
r454 r658 34 34 *********************************************************************************************************/ 35 35 36 #include "f D.h"36 #include "fdcore-internal.h" 37 37 38 38 /* This file contains code to handle Capabilities Exchange messages (CER and CEA) and election process */ -
libfdcore/p_cnx.c
r379 r658 34 34 *********************************************************************************************************/ 35 35 36 #include "f D.h"36 #include "fdcore-internal.h" 37 37 38 38 /* This file contains code used by a peer state machine to initiate a connection to remote peer */ -
libfdcore/p_dp.c
r454 r658 34 34 *********************************************************************************************************/ 35 35 36 #include "f D.h"36 #include "fdcore-internal.h" 37 37 38 38 /* This file contains code to handle Disconnect Peer messages (DPR and DPA) */ -
libfdcore/p_dw.c
r454 r658 34 34 *********************************************************************************************************/ 35 35 36 #include "f D.h"36 #include "fdcore-internal.h" 37 37 38 38 /* This file contains code to handle Device Watchdog messages (DWR and DWA) */ -
libfdcore/p_expiry.c
r648 r658 34 34 *********************************************************************************************************/ 35 35 36 #include "f D.h"36 #include "fdcore-internal.h" 37 37 38 38 /* Delay for garbage collection of expired peers, in seconds */ -
libfdcore/p_out.c
r455 r658 34 34 *********************************************************************************************************/ 35 35 36 #include "f D.h"36 #include "fdcore-internal.h" 37 37 38 38 /* 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 34 34 *********************************************************************************************************/ 35 35 36 #include "f D.h"36 #include "fdcore-internal.h" 37 37 38 38 /* The actual declaration of peer_state_str */ -
libfdcore/p_sr.c
r650 r658 34 34 *********************************************************************************************************/ 35 35 36 #include "f D.h"36 #include "fdcore-internal.h" 37 37 38 38 #ifndef SR_DEBUG_LVL -
libfdcore/peers.c
r649 r658 34 34 *********************************************************************************************************/ 35 35 36 #include "f D.h"36 #include "fdcore-internal.h" 37 37 38 38 /* Global list of peers */ -
libfdcore/queues.c
r124 r658 34 34 *********************************************************************************************************/ 35 35 36 #include "f D.h"36 #include "fdcore-internal.h" 37 37 38 38 /* The global message queues */ -
libfdcore/routing_dispatch.c
r649 r658 34 34 *********************************************************************************************************/ 35 35 36 #include "f D.h"36 #include "fdcore-internal.h" 37 37 38 38 /********************************************************************************/ -
libfdcore/sctp.c
r590 r658 34 34 *********************************************************************************************************/ 35 35 36 #include "f D.h"36 #include "fdcore-internal.h" 37 37 #include "cnxctx.h" 38 38 -
libfdcore/sctps.c
r543 r658 37 37 /* See http://aaa.koganei.wide.ad.jp/blogs/index.php/waaad/2008/08/18/tls-over-sctp for history */ 38 38 39 #include "f D.h"39 #include "fdcore-internal.h" 40 40 #include "cnxctx.h" 41 41 -
libfdcore/server.c
r590 r658 34 34 *********************************************************************************************************/ 35 35 36 #include "f D.h"36 #include "fdcore-internal.h" 37 37 38 38 /* Server (listening) part of the daemon */ -
libfdcore/tcp.c
r378 r658 34 34 *********************************************************************************************************/ 35 35 36 #include "f D.h"36 #include "fdcore-internal.h" 37 37 #include "cnxctx.h" 38 38 -
libfdproto/CMakeLists.txt
r320 r658 1 1 # Name of the subproject 2 Project("libf reeDiameter" C)2 Project("libfdproto" C) 3 3 4 4 # List of source files for the library 5 SET(LFD _SRC6 libfD.h5 SET(LFDPROTO_SRC 6 fdproto-internal.h 7 7 dictionary.c 8 8 dispatch.c … … 14 14 rt_data.c 15 15 sessions.c 16 signal.c17 16 ) 18 17 19 # Save the list of files for testcases in the daemon's directory20 SET(LFD _SRC ${LFD_SRC} PARENT_SCOPE)18 # Save the list of files for testcases in the core's directory 19 SET(LFDPROTO_SRC ${LFDPROTO_SRC} PARENT_SCOPE) 21 20 22 21 # Build as a shared library 23 ADD_LIBRARY(libf reeDiameter SHARED ${LFD_SRC})22 ADD_LIBRARY(libfdproto SHARED ${LFDPROTO_SRC}) 24 23 25 24 # Avoid the liblib name, and set the version 26 SET_TARGET_PROPERTIES(libf reeDiameterPROPERTIES27 OUTPUT_NAME "f reeDiameter"25 SET_TARGET_PROPERTIES(libfdproto PROPERTIES 26 OUTPUT_NAME "fdproto" 28 27 SOVERSION ${FD_PROJECT_VERSION_API} 29 28 VERSION ${FD_PROJECT_VERSION_MAJOR}.${FD_PROJECT_VERSION_MINOR}.${FD_PROJECT_VERSION_REV}) 30 29 31 30 # The library itself needs other libraries 32 TARGET_LINK_LIBRARIES(libf reeDiameter ${LFD_LIBS})31 TARGET_LINK_LIBRARIES(libfdproto ${LFDPROTO_LIBS}) 33 32 34 33 … … 36 35 ## INSTALL section ## 37 36 38 INSTALL(TARGETS libf reeDiameter37 INSTALL(TARGETS libfdproto 39 38 LIBRARY DESTINATION ${INSTALL_LIBRARY_SUFFIX} 40 39 COMPONENT freeDiameter-common) -
libfdproto/dictionary.c
r602 r658 34 34 *********************************************************************************************************/ 35 35 36 #include " libfD.h"36 #include "fdproto-internal.h" 37 37 38 38 /* Names of the base types */ … … 323 323 obj->objeyec, OBJECT_EYECATCHER, 324 324 obj->typeyec, _OBINFO(obj).eyecatcher); 325 } else { 326 TRACE_DEBUG(FULL, "Invalid object : NULL pointer"); 325 327 } 326 328 return 0; … … 552 554 } 553 555 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) */ 555 557 static int order_rule_by_avpn ( struct dict_object *o1, struct dict_object *o2 ) 556 558 { 557 559 TRACE_ENTRY("%p %p", o1, o2); 558 560 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) ; 560 563 } 561 564 … … 1496 1499 struct dict_object * new = NULL; 1497 1500 struct dict_object * vendor = NULL; 1501 struct dict_object * locref = NULL; 1498 1502 1499 1503 TRACE_ENTRY("%p %d(%s) %p %p %p", dict, type, dict_obj_info[CHECK_TYPE(type) ? type : 0].name, data, parent, ref); … … 1525 1529 if (type == DICT_AVP) { 1526 1530 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; } ); 1528 1532 1529 1533 /* Also check if a parent is provided, that the type are the same */ … … 1568 1572 case DICT_VENDOR: 1569 1573 /* 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; 1572 1577 break; 1573 1578 1574 1579 case DICT_APPLICATION: 1575 1580 /* 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; 1578 1584 break; 1579 1585 1580 1586 case DICT_TYPE: 1581 1587 /* 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; 1584 1591 break; 1585 1592 1586 1593 case DICT_ENUMVAL: 1587 1594 /* 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 } 1592 1604 break; 1593 1605 1594 1606 case DICT_AVP: 1595 1607 /* 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 } 1600 1617 break; 1601 1618 1602 1619 case DICT_COMMAND: 1603 1620 /* 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 } 1608 1630 break; 1609 1631 1610 1632 case DICT_RULE: 1611 1633 /* 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; 1614 1637 break; 1615 1638 … … 1632 1655 error_unlock: 1633 1656 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 1634 1806 error_free: 1635 1807 free(new); -
libfdproto/dispatch.c
r648 r658 34 34 *********************************************************************************************************/ 35 35 36 #include " libfD.h"36 #include "fdproto-internal.h" 37 37 38 38 /* The dispatch module in the library is quite simple: callbacks are saved in a global list -
libfdproto/fdproto-internal.h
r291 r658 34 34 *********************************************************************************************************/ 35 35 36 /* This file contains the definitions for internal use in the libfreeDiameterlibrary */36 /* This file contains the definitions for internal use in the freeDiameter protocol library */ 37 37 38 #ifndef _LIBFD _H39 #define _LIBFD _H38 #ifndef _LIBFDPROTO_INTERNAL_H 39 #define _LIBFDPROTO_INTERNAL_H 40 40 41 41 #include <freeDiameter/freeDiameter-host.h> 42 #include <freeDiameter/libf reeDiameter.h>42 #include <freeDiameter/libfdproto.h> 43 43 44 44 /* Internal to the library */ … … 47 47 int fd_sess_init(void); 48 48 void fd_sess_fini(void); 49 int fd_sig_init(void);50 void fd_sig_fini(void);51 49 52 50 /* Iterator on the rules of a parent object */ … … 65 63 int fd_sess_reclaim_msg ( struct session ** session ); 66 64 67 #endif /* _LIBFD _H */65 #endif /* _LIBFDPROTO_INTERNAL_H */ -
libfdproto/fifo.c
r451 r658 46 46 */ 47 47 48 #include " libfD.h"48 #include "fdproto-internal.h" 49 49 50 50 /* Definition of a FIFO queue object */ -
libfdproto/init.c
r454 r658 34 34 *********************************************************************************************************/ 35 35 36 #include " libfD.h"36 #include "fdproto-internal.h" 37 37 38 38 /* Only for CPU cache flush */ … … 40 40 41 41 /* Initialize library variables and threads */ 42 int fd_lib _init(int support_signals)42 int fd_libproto_init() 43 43 { 44 44 int ret = 0; … … 51 51 } 52 52 53 /* Initialize signals if requested */54 if (support_signals) {55 CHECK_FCT( fd_sig_init() );56 }57 58 53 /* Initialize the modules that need it */ 59 54 fd_msg_eteid_init(); … … 64 59 65 60 /* Stop all threads created in the library */ 66 void fd_lib _fini(void)61 void fd_libproto_fini(void) 67 62 { 68 63 fd_sess_fini(); 69 fd_sig_fini();70 64 } -
libfdproto/lists.c
r83 r658 34 34 *********************************************************************************************************/ 35 35 36 #include " libfD.h"36 #include "fdproto-internal.h" 37 37 38 38 /* Initialize a list element */ -
libfdproto/log.c
r653 r658 34 34 *********************************************************************************************************/ 35 35 36 #include " libfD.h"36 #include "fdproto-internal.h" 37 37 38 38 #include <stdarg.h> -
libfdproto/messages.c
r656 r658 39 39 */ 40 40 41 #include " libfD.h"41 #include "fdproto-internal.h" 42 42 43 43 #include <sys/param.h> -
libfdproto/rt_data.c
r563 r658 39 39 */ 40 40 41 #include " libfD.h"41 #include "fdproto-internal.h" 42 42 43 43 /* Structure that contains the routing data for a message */ -
libfdproto/sessions.c
r639 r658 39 39 */ 40 40 41 #include " libfD.h"41 #include "fdproto-internal.h" 42 42 43 43 /*********************** Parameters **********************/ -
tests/CMakeLists.txt
r585 r658 1 1 # Test directory 2 PROJECT(" libfreeDiameter tests" C)2 PROJECT("freeDiameter tests" C) 3 3 4 4 # give the possibility to configure the timeout duration for the tests … … 28 28 ADD_DEFINITIONS(-DTRACE_LEVEL=NONE) 29 29 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}) 30 INCLUDE_DIRECTORIES( "../libfdproto" ) 31 INCLUDE_DIRECTORIES( "../libfdcore" ) 52 32 53 33 … … 72 52 73 53 # 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) 76 56 #SET_SOURCE_FILES_PROPERTIES(lex.acct_conf.c acct_conf.tab.c PROPERTIES COMPILE_FLAGS "-I ${CMAKE_CURRENT_SOURCE_DIR}") 77 57 … … 89 69 90 70 # The extension headers 91 INCLUDE_DIRECTORIES( "../ ../extensions/app_acct" )71 INCLUDE_DIRECTORIES( "../extensions/app_acct" ) 92 72 93 73 SET(testappacct_ADDITIONAL "") 94 74 95 75 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}") 97 77 ENDFOREACH(SRC_FILE) 98 78 99 79 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}") 101 81 ENDFOREACH(SRC_FILE) 102 82 … … 109 89 FOREACH( TEST ${TEST_LIST} ) 110 90 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}) 112 92 ADD_TEST(${TEST} ${EXECUTABLE_OUTPUT_PATH}/${TEST}) 113 93 ENDFOREACH( TEST ) -
tests/tests.h
r481 r658 42 42 #define _TESTS_H 43 43 44 #include " libfD.h"45 #include "f D.h"44 #include "fdproto-internal.h" 45 #include "fdcore-internal.h" 46 46 47 47 #include <pthread.h> … … 82 82 struct fd_config * fd_g_config = &conf; 83 83 84 /* gcrypt functions to support posix threads */85 GCRY_THREAD_OPTION_PTHREAD_IMPL;86 87 84 /* Define the standard check routines */ 88 85 #define CHECK( _val, _assert ){ \ … … 105 102 } 106 103 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); \ 104 static pthread_t timeout_thr; 105 static 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; 119 119 } 120 120 121 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 } 122 GCRY_THREAD_OPTION_PTHREAD_IMPL; 125 123 126 124 static inline void parse_cmdline(int argc, char * argv[]) { … … 164 162 if (!no_timeout) { 165 163 alarm(TEST_TIMEOUT); 166 fd_sig_register(SIGALRM, "Test.harness", test_timeout);164 CHECK( 0, pthread_create(&timeout_thr, NULL, timeout_catch, NULL) ); 167 165 } 168 166 } 169 167 168 static 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 170 197 #endif /* _TESTS_H */
Note: See TracChangeset
for help on using the changeset viewer.