Navigation


Changeset 2:d8ce06172629 in freeDiameter


Ignore:
Timestamp:
Aug 31, 2009, 5:32:22 PM (12 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Added a global debug level var

Files:
8 edited

Legend:

Unmodified
Added
Removed
  • freeDiameter/CMakeLists.txt

    r1 r2  
    1818TARGET_LINK_LIBRARIES(freeDiameterd libfreeDiameter ${FD_LIBS})
    1919
     20# Save the list of files, if needed
     21SET(FD_COMMON_SRC ${FD_COMMON_SRC} PARENT_SCOPE)
     22
    2023# The unary tests directory
    2124OPTION(SKIP_TESTS "Skip compilation of the tests?" OFF)
  • freeDiameter/tests/CMakeLists.txt

    r1 r2  
    2020# Some parameters for the tests
    2121
    22 # Add this flag to add some debug information in the tests themselves
    2322ADD_DEFINITIONS(-DTEST_DEBUG)
     23ADD_DEFINITIONS(-DTRACE_LEVEL=NONE)
    2424
    2525INCLUDE_DIRECTORIES( ".." )
     26INCLUDE_DIRECTORIES( "../../libfreeDiameter" )
    2627
    2728SET(TEST_COMMON_SRC "")
     
    3536# ENDFOREACH(SRC_FILE)
    3637
     38FOREACH( SRC_FILE ${LFD_SRC})
     39   SET(TEST_COMMON_SRC ${TEST_COMMON_SRC} "../../libfreeDiameter/${SRC_FILE}")
     40ENDFOREACH(SRC_FILE)
     41
    3742# Create an archive with the daemon common files (all but main)
    3843ADD_LIBRARY(fDcore STATIC ${TEST_COMMON_SRC})
     
    4348FOREACH( TEST ${TEST_LIST} )
    4449   ADD_EXECUTABLE(${TEST} ${TEST}.c tests.h)
    45    TARGET_LINK_LIBRARIES(${TEST} libfreeDiameter fDcore ${FD_LIBS})
     50   TARGET_LINK_LIBRARIES(${TEST} fDcore ${FD_LIBS})
    4651   ADD_TEST(${TEST} ${EXECUTABLE_OUTPUT_PATH}/${TEST})
    4752ENDFOREACH( TEST )
  • freeDiameter/tests/testmesg.c

    r1 r2  
    436436                                memset(&buf, 0, sizeof(buf)); /* Test that the OS value is really copied */
    437437                                CHECK( 0, fd_msg_update_length ( avpi ) );
    438                                 #if 1
     438                                #if 0
    439439                                fd_log_debug("AVP octet string, 'This\\0 is a b...'\n");
    440440                                fd_msg_dump_one(0, avpi);
  • freeDiameter/tests/tests.h

    r1 r2  
    5252#endif /* TEST_TIMEOUT */
    5353
    54 static int test_verbosity = 0;
    55 
    5654/* Standard includes */
    5755#include <getopt.h>
     
    7674}
    7775
     76static int test_verbo = 0;
     77
    7878/* Define the standard check routines */
    7979#define CHECK( _val, _assert ){                         \
    80         if (test_verbosity > 0) {                       \
     80        if (test_verbo > 0) {                           \
    8181                fprintf(stderr,                         \
    8282                        "%s:%-4d: CHECK( " #_assert " == "\
     
    111111                switch (c) {
    112112                        case 'd':       /* Increase verbosity of debug messages.  */
    113                                 test_verbosity++;
     113                                test_verbo++;
    114114                                break;
    115115                               
    116                         case 'q':       /* Decrease verbosity then remove debug messages.  */
    117                                 test_verbosity--;
     116                        case 'q':       /* Decrease verbosity.  */
     117                                test_verbo--;
    118118                                break;
    119119                       
     
    126126                }
    127127        }
     128        fd_g_debug_lvl = (test_verbo > 0) ? (test_verbo - 1) : 0;
    128129        if (!no_timeout)
    129130                alarm(TEST_TIMEOUT);
  • include/freeDiameter/libfreeDiameter.h

    r1 r2  
    122122char * fd_log_time ( char * buf, size_t len );
    123123
    124 /************************** DEBUG MACROS ************************************/
    125124
    126125/* levels definitions */
     
    137136#endif /* TRACE_LEVEL */
    138137
    139 /* The level of the file being compiled */
     138/* The level of the file being compiled. */
    140139static int local_debug_level = TRACE_LEVEL;
    141140
    142 /* helper macros (pre-processor hacks) */
     141/* A global level, changed by configuration or cmd line for example. default is 0. */
     142extern int fd_g_debug_lvl;
     143
     144/* helper macros (pre-processor hacks to allow macro arguments) */
    143145#define __str( arg )  #arg
    144146#define _stringize( arg ) __str( arg )
     
    146148#define _aggregate( arg1, arg2 ) __agr( arg1, arg2 )
    147149
    148 /* Some portability tricks to get nice function name in __PRETTY_FUNCTION__ */
     150/* Some portability code to get nice function name in __PRETTY_FUNCTION__ */
    149151#if __STDC_VERSION__ < 199901L
    150152# if __GNUC__ >= 2
     
    159161
    160162/* Boolean for tracing at a certain level */
    161 #define TRACE_BOOL(_level_) ( (_level_) <= local_debug_level )
    162 
    163 /* The general debug macro, each call results in two lines of debug messages */
     163#define TRACE_BOOL(_level_) ( (_level_) <= local_debug_level + fd_g_debug_lvl )
     164
     165/* The general debug macro, each call results in two lines of debug messages (change the macro for more compact output) */
    164166#define TRACE_DEBUG(level,format,args... ) {                                                                                    \
    165167        if ( TRACE_BOOL(level) ) {                                                                                              \
     
    173175}
    174176
    175 /* Helper for function entry */
     177/* Helper for function entry -- for very detailed trace of the execution */
    176178#define TRACE_ENTRY(_format,_args... ) \
    177179        TRACE_DEBUG(FCTS, "->%s (" #_args ") = (" _format ") >", __PRETTY_FUNCTION__, ##_args );
    178180
    179 /* Helper for debugging by adding traces */
     181/* Helper for debugging by adding traces -- for debuging a specific location of the code */
    180182#define TRACE_HERE()    \
    181         TRACE_DEBUG(INFO, " -- debug checkpoint -- ");
    182 
    183 /* Helper for tracing the CHECK_* macros bellow */
     183        TRACE_DEBUG(NONE, " -- debug checkpoint -- ");
     184
     185/* Helper for tracing the CHECK_* macros bellow -- very very verbose code execution! */
    184186#define TRACE_DEBUG_ALL( str )  \
    185187        TRACE_DEBUG(CALL, str );
     
    403405}
    404406
    405 /* Cleanups for cancellation (all threads should be safely cancelable!) */
     407/* Cleanups for cancellation (all threads should be safely cancelable...) */
    406408static __inline__ void fd_cleanup_mutex( void * mutex )
    407409{
     
    12741276#define ER_DIAMETER_REDIRECT_INDICATION         3006
    12751277
    1276 /* Iterator on the rules of a parent object */
    1277 int fd_dict_iterate_rules ( struct dict_object *parent, void * data, int (*cb)(void *, struct dict_rule_data *) );
     1278
     1279/*============================================================*/
     1280/*                         SESSIONS                           */
     1281/*============================================================*/
     1282
     1283
     1284
     1285/*
     1286 * The libfreeDiameter does not provide a full support of the sessions state machines as described in the RFC3588.
     1287 * It only provides a basic support allowing an extension to associate some state with a session identifier, and retrieve
     1288 * this data later.
     1289 *
     1290 * A session is an opaque object, associated with a value of a Session-Id AVP.
     1291 * An extension that wants to associate data with the session must first register as session module client
     1292 * with the sess_regext function to get an identifier object (sess_reg_t).
     1293 *
     1294 * The module manages tuplets ( sess_id_t *, sess_reg_t *, void *). The following functions are used to manage these tuplets:
     1295 * sess_data_reg  : associate a pointer with a given session for a given module client.
     1296 * sess_data_dereg: removes an association.
     1297 * sess_data_get  : get the pointer associated with an association without changing it.
     1298 *
     1299 * Note that creating an association calls sess_link as a side effect, and removing the association calls sess_unlink.
     1300 *
     1301 * QUICK TUTORIAL:
     1302 *  For an extension that wants to implement a session state machine, here is a quick guide.
     1303 *
     1304 * First, the extension must define a structure to save the session state, for example appstate_t.
     1305 *
     1306 * Since the extension will use the session module, it creates a sess_reg_t by calling sess_regext.
     1307 *
     1308 * If the extension behaves as a client, it receives external events that trig the start of a new sessions.
     1309 * When such event occurs, the extension calls sess_new with the appropriate parameters to create a new session.
     1310 * It initializes an appstate_t structure with the data of this session and creates an association with sess_data_reg (%).
     1311 * Then it creates a message (application-specific) to request authentication and/or authorization for the service
     1312 * and the message is sent.
     1313 *
     1314 * Later, assuming that the extension has registered appropriate callbacks in the dispatcher module, when a message
     1315 * is received, the extension can retrieve the state of the session with the sess_data_get function.
     1316 *
     1317 * Finaly, when the extension decides to terminate the session (timer, or as result of a message exchange), it
     1318 * calls sess_data_dereg in order to destroy the binding in the daemon. When last message refering this session is freed,
     1319 * the session data is freed.
     1320 *
     1321 * (%) A this time, the extension must call sess_unlink in order to counter the effects of the sess_new function.
     1322 * This allows to have the session destroyed when no more data is associated to it.
     1323
     1324
     1325
     1326/*============================================================*/
     1327/*                         DISPATCH                           */
     1328/*============================================================*/
     1329
     1330/* The dispatch process consists in passing a message to some handlers
     1331 (typically provided by extensions) based on its content (app id, cmd code...) */
     1332
     1333/* The dispatch module has two main roles:
     1334 *  - help determine if a message can be handled locally (during the routing step)
     1335 *  - pass the message to the callback(s) that will handle it (during the dispatch step)
     1336 *
     1337 * These are the possibilities for registering a callback:
     1338 *
     1339 * -> For All messages.
     1340 *  This callback is called for all messages that are handled locally. This should be used only
     1341 *  internally by the daemon, or for debug purpose.
     1342 *
     1343 * -> by AVP value (constants).
     1344 *  This callback will be called when a message is received and contains a certain AVP with a specified value.
     1345 *
     1346 * -> by AVP.
     1347 *  This callback will be called when the received message contains a certain AVP.
     1348 *
     1349 * -> by command-code.
     1350 *  This callback will be called when the message is a specific command.
     1351 *
     1352 * -> by application.
     1353 *  This callback will be called when the message has a specific application-id.
     1354 *
     1355 * ( by vendor: would this be useful? it may be added later)
     1356 *
     1357 * Note that several criteria may be selected at the same time, for example command-code AND application id.
     1358 *
     1359 * When a callback is called, it receives the message as parameter, and eventually a pointer to
     1360 * the AVP in the message when this is appropriate.
     1361 *
     1362 * The callback must process the message, and eventually create an answer to it. See the definition
     1363 * bellow for more information.
     1364 *
     1365 * If no callback has handled the message, a default handler will be called with the effect of
     1366 * requeuing the message for forwarding on the network to another peer (for requests, if possible), or
     1367 * discarding the message (for answers).
     1368 */
     1369
     1370
    12781371
    12791372
  • libfreeDiameter/CMakeLists.txt

    r1 r2  
    2424TARGET_LINK_LIBRARIES(libfreeDiameter ${FD_LIBS})
    2525
     26# Save the list of files for testcases in the daemon's directory
     27SET(LFD_SRC ${LFD_SRC} PARENT_SCOPE)
     28
  • libfreeDiameter/libfD.h

    r1 r2  
    4646void fd_msg_eteid_init(void);
    4747
     48/* Iterator on the rules of a parent object */
     49int fd_dict_iterate_rules ( struct dict_object *parent, void * data, int (*cb)(void *, struct dict_rule_data *) );
     50
     51
    4852
    4953#endif /* _LIBFD_H */
  • libfreeDiameter/log.c

    r1 r2  
    4040pthread_mutex_t fd_log_lock = PTHREAD_MUTEX_INITIALIZER;
    4141pthread_key_t   fd_log_thname;
     42int fd_g_debug_lvl = 0;
    4243
    4344/* Log a debug message */
Note: See TracChangeset for help on using the changeset viewer.