Changeset 961:d95cd3ca9e8d in freeDiameter
- Timestamp:
- Mar 7, 2013, 4:09:54 AM (11 years ago)
- Branch:
- default
- Parents:
- 960:f39fa6cd86e0 (diff), 933:04f590da5821 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Phase:
- public
- Files:
-
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
.hgtags
r932 r961 30 30 226f5957186ae4369467b070aeb61b1c631c9a5c 1.1.5-rc2 31 31 ae96ae28f3ddc48b9e2676e9538008eab2b9d60a 1.1.5 32 8500947421cb412b5f4f2dfffdf1a35b6fb369e0 FORK 32 33 155d45d0653025f45b58ab96b6ba0d5e6fb7fcf8 1.1.6 -
.hgtags
r942 r961 31 31 ae96ae28f3ddc48b9e2676e9538008eab2b9d60a 1.1.5 32 32 8500947421cb412b5f4f2dfffdf1a35b6fb369e0 FORK 33 155d45d0653025f45b58ab96b6ba0d5e6fb7fcf8 1.1.6 -
extensions/acl_wl/aw_conf.y
r928 r961 35 35 36 36 /* Yacc extension's configuration parser. 37 * See doc/a pp_test.conf.sample for configuration file format37 * See doc/acl_wl.conf.sample for configuration file format 38 38 */ 39 39 -
extensions/acl_wl/aw_conf.y
r957 r961 3 3 * Author: Sebastien Decugis <sdecugis@freediameter.net> * 4 4 * * 5 * Copyright (c) 201 1, WIDE Project and NICT *5 * Copyright (c) 2013, WIDE Project and NICT * 6 6 * All rights reserved. * 7 7 * * … … 127 127 fqdn_added++; 128 128 } 129 | conffile LEX_ERROR 130 { 131 yyerror(&yylloc, conffile, "An error occurred while parsing the configuration file"); 132 return EINVAL; 133 } 129 134 ; 130 135 -
include/freeDiameter/libfdproto.h
r928 r961 110 110 111 111 /* 112 * FUNCTION: fd_log _debug_fstr112 * FUNCTION: fd_log 113 113 * MACRO: fd_log_debug 114 114 * 115 115 * PARAMETERS: 116 * fstr : Stream where the text will be sent (default: stdout)116 * loglevel : Integer, how important the message is 117 117 * format : Same format string as in the printf function 118 118 * ... : Same list as printf 119 119 * 120 120 * DESCRIPTION: 121 * Log internal information for use of developpers only.121 * Write information to log. 122 122 * The format and arguments may contain UTF-8 encoded data. The 123 * output medium (file or console)is expected to support this encoding.123 * output medium is expected to support this encoding. 124 124 * 125 125 * RETURN VALUE: 126 126 * None. 127 127 */ 128 void fd_log_debug_fstr ( FILE * fstr, const char * format, ... ); 129 #define fd_log_debug(format,args...) fd_log_debug_fstr(NULL, format, ## args) 128 void fd_log ( int, const char *, ... ); 129 #define fd_log_debug(format,args...) fd_log(FD_LOG_DEBUG, format, ## args) 130 void fd_log_debug_fstr( FILE *, const char *, ... ); 130 131 131 132 /* these are internal objects of the debug facility, … … 174 175 * 175 176 * PARAMETERS: 176 * fstr : Stream where the text will be sent to (default: stdout)177 * loglevel : priority of the message 177 178 * format : Same format string as in the printf function 178 179 * va_list : Argument list … … 184 185 * int : Success or failure 185 186 */ 186 int fd_log_handler_register ( void (*logger)( const char * format, va_list *args) );187 int fd_log_handler_register ( void (*logger)(int loglevel, const char * format, va_list args) ); 187 188 188 189 /* … … 209 210 #endif /* ASSERT */ 210 211 211 /* levels definitions */ 212 /* log levels definitions */ 213 #define FD_LOG_DEBUG 0 214 #define FD_LOG_ERROR 5 215 216 /* print level definitions */ 212 217 #define NONE 0 /* Display no debug message */ 213 218 #define INFO 1 /* Display errors only */ … … 216 221 #define FCTS 6 /* Display entry parameters of most functions */ 217 222 #define CALL 9 /* Display calls to most functions (with CHECK macros) */ 218 219 /* Increment the debug level for a file at compilation time by defining -DTRACE_LEVEL=FULL for example. */220 #ifndef TRACE_LEVEL221 #define TRACE_LEVEL NONE222 #endif /* TRACE_LEVEL */223 224 /* The level of the file being compiled. */225 static int local_debug_level = TRACE_LEVEL;226 223 227 224 /* A global level, changed by configuration or cmd line for example. Default is INFO (in libfdproto/log.c). */ … … 247 244 /* Boolean for tracing at a certain level */ 248 245 #ifdef DEBUG 249 #define TRACE_BOOL(_level_) ( ((_level_) <= local_debug_level +fd_g_debug_lvl) \246 #define TRACE_BOOL(_level_) ( ((_level_) <= fd_g_debug_lvl) \ 250 247 || (fd_debug_one_function && !strcmp(fd_debug_one_function, __PRETTY_FUNCTION__)) \ 251 248 || (fd_debug_one_file && !strcmp(fd_debug_one_file, __STRIPPED_FILE__) ) ) 252 249 #else /* DEBUG */ 253 #define TRACE_BOOL(_level_) ((_level_) <= local_debug_level +fd_g_debug_lvl)250 #define TRACE_BOOL(_level_) ((_level_) <= fd_g_debug_lvl) 254 251 #endif /* DEBUG */ 255 252 256 253 254 #define STD_TRACE_FMT_STRING "thread %s in %s@%s:%d: " 257 255 /************* 258 256 The general debug macro, each call results in two lines of debug messages (change the macro for more compact output) … … 262 260 #define TRACE_DEBUG(level,format,args... ) { \ 263 261 if ( TRACE_BOOL(level) ) { \ 264 char __buf[25]; \265 262 const char * __thn = ((char *)pthread_getspecific(fd_log_thname) ?: "unnamed"); \ 266 fd_log_debug("\t | tid:%-20s\t%s\tin %s@%s:%d\n" \ 267 "\t%s|%*s" format "\n", \ 268 __thn, fd_log_time(NULL, __buf, sizeof(__buf)), __PRETTY_FUNCTION__, __FILE__, __LINE__,\ 269 (level < FULL)?"@":" ",level, "", ## args); \ 263 fd_log(level, STD_TRACE_FMT_STRING format, \ 264 __thn, __PRETTY_FUNCTION__, __FILE__, __LINE__, ## args); \ 270 265 } \ 271 266 } … … 275 270 if ( TRACE_BOOL(level) ) { \ 276 271 if (fd_g_debug_lvl > FULL) { \ 277 char __buf[25]; \278 272 const char * __thn = ((char *)pthread_getspecific(fd_log_thname) ?: "unnamed"); \ 279 fd_log_debug("\t | tid:%-20s\t%s\tin %s@%s:%d\n" \ 280 "\t%s|%*s" format "\n", \ 281 __thn, fd_log_time(NULL, __buf, sizeof(__buf)), __PRETTY_FUNCTION__, __FILE__, __LINE__,\ 282 (level < FULL)?"@":" ",level, "", ## args); \ 273 fd_log(level, STD_TRACE_FMT_STRING format, \ 274 __thn, __PRETTY_FUNCTION__, __FILE__, __LINE__, ## args); \ 283 275 } else { \ 284 fd_log _debug(format "\n", ## args);\276 fd_log(level, format, ## args); \ 285 277 } \ 286 278 } \ … … 316 308 #define TRACE_DEBUG_BUFFER(level, prefix, buf, bufsz, suffix ) { \ 317 309 if ( TRACE_BOOL(level) ) { \ 318 char __ts[25]; \319 310 int __i; \ 320 311 size_t __sz = (size_t)(bufsz); \ 321 312 uint8_t * __buf = (uint8_t *)(buf); \ 322 313 char * __thn = ((char *)pthread_getspecific(fd_log_thname) ?: "unnamed"); \ 323 fd_log_debug("\t | tid:%-20s\t%s\tin %s@%s:%d\n" \ 324 "\t%s|%*s" prefix , \ 325 __thn, fd_log_time(NULL, __ts, sizeof(__ts)), __PRETTY_FUNCTION__, __FILE__, __LINE__, \ 326 (level < FULL)?"@":" ",level, ""); \ 314 fd_log(level, STD_TRACE_FMT_STRING prefix, \ 315 __thn, __PRETTY_FUNCTION__, __FILE__, __LINE__); \ 327 316 for (__i = 0; __i < __sz; __i++) { \ 328 fd_log _debug("%02.2hhx", __buf[__i]);\317 fd_log(level, "%02.2hhx", __buf[__i]); \ 329 318 } \ 330 fd_log _debug(suffix "\n");\319 fd_log(level, suffix); \ 331 320 } \ 332 321 } … … 345 334 346 335 /* Dump one sockaddr Node information */ 347 #define sSA_DUMP_NODE( sa, flag ) {\336 #define sSA_DUMP_NODE( buf, bufsize, sa, flag ) { \ 348 337 sSA * __sa = (sSA *)(sa); \ 349 338 char __addrbuf[INET6_ADDRSTRLEN]; \ … … 357 346 flag); \ 358 347 if (__rc) \ 359 fd_log_debug("%s", (char *)gai_strerror(__rc)); \348 snprintf(buf, bufsize, "%s", gai_strerror(__rc)); \ 360 349 else \ 361 fd_log_debug("%s", &__addrbuf[0]);\350 snprintf(buf, bufsize, "%s", &__addrbuf[0]); \ 362 351 } else { \ 363 fd_log_debug("(NULL / ANY)");\352 snprintf(buf, bufsize, "(NULL / ANY)"); \ 364 353 } \ 365 354 } 366 355 /* Same but with the port (service) also */ 367 #define sSA_DUMP_NODE_SERV( sa, flag ) {\356 #define sSA_DUMP_NODE_SERV( buf, bufsize, sa, flag ) { \ 368 357 sSA * __sa = (sSA *)(sa); \ 369 358 char __addrbuf[INET6_ADDRSTRLEN]; \ … … 378 367 flag); \ 379 368 if (__rc) \ 380 fd_log_debug("%s", (char *)gai_strerror(__rc));\369 snprintf(buf, bufsize, "%s", gai_strerror(__rc)); \ 381 370 else \ 382 fd_log_debug("[%s]:%s", &__addrbuf[0],&__servbuf[0]);\371 snprintf(buf, bufsize, "[%s]:%s", &__addrbuf[0],&__servbuf[0]); \ 383 372 } else { \ 384 fd_log_debug("(NULL / ANY)");\373 snprintf(buf, bufsize,"(NULL / ANY)"); \ 385 374 } \ 386 375 } … … 389 378 #define TRACE_DEBUG_sSA(level, prefix, sa, flags, suffix ) { \ 390 379 if ( TRACE_BOOL(level) ) { \ 391 char __buf[25];\380 char buf[1024]; \ 392 381 char * __thn = ((char *)pthread_getspecific(fd_log_thname) ?: "unnamed"); \ 393 fd_log_debug("\t | tid:%-20s\t%s\tin %s@%s:%d\n" \ 394 "\t%s|%*s" prefix , \ 395 __thn, fd_log_time(NULL, __buf, sizeof(__buf)), __PRETTY_FUNCTION__, __FILE__, __LINE__,\ 396 (level < FULL)?"@":" ",level, ""); \ 397 sSA_DUMP_NODE_SERV( sa, flags ); \ 398 fd_log_debug(suffix "\n"); \ 382 sSA_DUMP_NODE_SERV(buf, sizeof(buf), sa, flags ); \ 383 fd_log(level, STD_TRACE_FMT_STRING "%s%s%s", \ 384 __thn, __PRETTY_FUNCTION__, __FILE__, __LINE__, prefix, buf, suffix); \ 399 385 } \ 400 386 } … … 418 404 #define TRACE_DEBUG_sSA(level, prefix, sa, flags, suffix ) 419 405 #define TRACE_DEBUG_ERROR(format,args... ) { \ 420 fd_log _debug(format "\n", ## args); \406 fd_log(FD_LOG_ERROR, format, ## args); \ 421 407 } 422 408 #endif /* STRIP_DEBUG_CODE */ … … 1445 1431 1446 1432 ret = fd_dict_search ( dict, DICT_AVP, AVP_BY_NAME_AND_VENDOR, &avpvendorboolean, &avp_sampleboolean, ENOENT); 1433 1434 -- this would also work, but be slower, because it has to search all vendor dictionaries -- 1435 ret = fd_dict_search ( dict, DICT_AVP, AVP_BY_NAME_ALL_VENDORS, "Sample-Boolean", &avp_sampleboolean, ENOENT); 1447 1436 1448 1437 } -
include/freeDiameter/libfdproto.h
r958 r961 3 3 * Author: Sebastien Decugis <sdecugis@freediameter.net> * 4 4 * * 5 * Copyright (c) 201 2, WIDE Project and NICT *5 * Copyright (c) 2013, WIDE Project and NICT * 6 6 * All rights reserved. * 7 7 * * -
libfdcore/cnxctx.c
r928 r961 229 229 230 230 if (TRACE_BOOL(INFO)) { 231 fd_log_debug("%s : accepted new client [", fd_cnx_getid(serv));232 sSA_DUMP_NODE( &ss, NI_NUMERICHOST );233 fd_log_debug(" ].\n");231 char buf[1024]; 232 sSA_DUMP_NODE( buf, sizeof(buf), &ss, NI_NUMERICHOST ); 233 fd_log_debug("%s : accepted new client [%s].\n", fd_cnx_getid(serv), buf); 234 234 } 235 235 … … 312 312 313 313 if (TRACE_BOOL(INFO)) { 314 fd_log_debug("Connection established to server '");315 sSA_DUMP_NODE_SERV( sa, NI_NUMERICSERV);316 fd_log_debug(" ' (TCP:%d).\n", sock);314 char buf[1024]; 315 sSA_DUMP_NODE_SERV( buf, sizeof(buf), sa, NI_NUMERICSERV); 316 fd_log_debug("Connection established to server '%s' (TCP:%d).\n", buf, sock); 317 317 } 318 318 … … 404 404 405 405 if (TRACE_BOOL(INFO)) { 406 fd_log_debug("Connection established to server '");407 sSA_DUMP_NODE_SERV( &primary, NI_NUMERICSERV);408 fd_log_debug(" ' (SCTP:%d, %d/%d streams).\n", sock, cnx->cc_sctp_para.str_in, cnx->cc_sctp_para.str_out);406 char buf[1024]; 407 sSA_DUMP_NODE_SERV( buf, sizeof(buf), &primary, NI_NUMERICSERV); 408 fd_log_debug("Connection established to server '%s' (SCTP:%d, %d/%d streams).\n", buf, sock, cnx->cc_sctp_para.str_in, cnx->cc_sctp_para.str_out); 409 409 } 410 410 -
libfdcore/cnxctx.c
r946 r961 3 3 * Author: Sebastien Decugis <sdecugis@freediameter.net> * 4 4 * * 5 * Copyright (c) 201 2, WIDE Project and NICT *5 * Copyright (c) 2013, WIDE Project and NICT * 6 6 * All rights reserved. * 7 7 * * … … 561 561 continue; 562 562 563 if (cur->ifa_addr == NULL) /* may happen with ppp interfaces */ 564 continue; 565 563 566 if (fd_g_config->cnf_flags.no_ip4 && (cur->ifa_addr->sa_family == AF_INET)) 564 567 continue; -
libfdcore/core.c
r928 r961 226 226 227 227 /* Parse the freeDiameter.conf configuration file, load the extensions */ 228 int fd_core_parseconf(c har * conffile)228 int fd_core_parseconf(const char * conffile) 229 229 { 230 230 TRACE_ENTRY("%p", conffile); -
libfdcore/core.c
r947 r961 3 3 * Author: Sebastien Decugis <sdecugis@freediameter.net> * 4 4 * * 5 * Copyright (c) 201 2, WIDE Project and NICT *5 * Copyright (c) 2013, WIDE Project and NICT * 6 6 * All rights reserved. * 7 7 * * -
libfdcore/fdd.l
r950 r961 3 3 * Author: Sebastien Decugis <sdecugis@freediameter.net> * 4 4 * * 5 * Copyright (c) 201 1, WIDE Project and NICT *5 * Copyright (c) 2013, WIDE Project and NICT * 6 6 * All rights reserved. * 7 7 * * … … 67 67 /* %option noinput ? */ 68 68 #define YY_NO_INPUT 69 70 /* Additional for files inclusion */ 71 #include <glob.h> 72 #include <string.h> 73 74 #define MAX_NESTED_CONF_FILES 5 75 76 struct nested_conffiles_t { 77 YY_BUFFER_STATE parent_level_state; 78 glob_t filelist; 79 int current_file; 80 } nested_conffiles[MAX_NESTED_CONF_FILES]; 81 82 int current_nested_level = 0; 83 84 int globerrfct(const char *epath, int eerrno) 85 { 86 TRACE_DEBUG_ERROR("Failed to scan %s: %s\n", epath, strerror(eerrno)); 87 return 1; 88 } 89 69 90 %} 70 91 … … 73 94 %option nounput 74 95 96 %x in_include 97 75 98 /* Quoted string. Multilines do not match. */ 76 99 qstring \"[^\"\n]*\" 77 100 78 101 %% 79 80 102 <*>\n { 81 103 /* Update the line count */ … … 87 109 <*>([[:space:]]{-}[\n])+ ; /* Eat all spaces, not new lines */ 88 110 <*>#.*$ ; /* Eat all comments */ 111 112 113 include BEGIN(in_include); 114 /* Following an "include" keyword */ 115 <in_include>{ 116 {qstring} { /* Name of the file to include. This is directly sent to glob. */ 117 int globerror=0; 118 char * buf = strdup(yytext+1); 119 if (buf[yyleng-2] != '"') 120 { 121 TRACE_DEBUG_ERROR("Unterminated string: %s\n", yytext); 122 return LEX_ERROR; 123 } 124 buf[yyleng-2] = '\0'; 125 126 if (current_nested_level >= MAX_NESTED_CONF_FILES) 127 { 128 TRACE_DEBUG_ERROR("Too many recursion levels in configuration files includes\n"); 129 return LEX_ERROR; 130 } 131 132 /* glob the include */ 133 globerror = glob(buf, GLOB_ERR, globerrfct, &nested_conffiles[current_nested_level].filelist); 134 135 if (globerror == GLOB_NOSPACE) 136 { 137 TRACE_DEBUG_ERROR("Not enough memory to parse include directive.\n"); 138 return LEX_ERROR; 139 } 140 if (globerror == GLOB_ABORTED) 141 { 142 TRACE_DEBUG_ERROR("An error was encountered in include directive.\n"); 143 return LEX_ERROR; 144 } 145 if (globerror == GLOB_NOMATCH) 146 { 147 globfree(&nested_conffiles[current_nested_level].filelist); 148 goto nomatch; 149 } 150 if (globerror) 151 { 152 TRACE_DEBUG_ERROR("Unexpected error in glob (%d).\n", globerror); 153 return LEX_ERROR; 154 } 155 156 /* We have a list of files to include. */ 157 158 /* save the current buffer for returning when this include has been parsed */ 159 nested_conffiles[current_nested_level].parent_level_state = YY_CURRENT_BUFFER; 160 161 /* Start with the first match */ 162 nested_conffiles[current_nested_level].current_file = 0; 163 164 yyin = fopen( nested_conffiles[current_nested_level].filelist.gl_pathv[0], "r" ); 165 166 if ( ! yyin ) 167 { 168 TRACE_DEBUG_ERROR("Error in %s: %s", nested_conffiles[current_nested_level].filelist.gl_pathv[0], strerror(errno)); 169 return LEX_ERROR; 170 } 171 172 yy_switch_to_buffer(yy_create_buffer( yyin, YY_BUF_SIZE )); 173 174 /* In case of recursive includes */ 175 current_nested_level++; 176 177 nomatch: 178 BEGIN(INITIAL); 179 } 180 } 181 182 <<EOF>> { 183 if (current_nested_level == 0) 184 { 185 /* We are at the end of parsing */ 186 yyterminate(); 187 } 188 189 /* Otherwise we are doing an include statement */ 190 --current_nested_level; 191 yy_delete_buffer(YY_CURRENT_BUFFER); 192 193 /* Go to next file, if any */ 194 nested_conffiles[current_nested_level].current_file++; 195 if ( nested_conffiles[current_nested_level].filelist.gl_pathv[nested_conffiles[current_nested_level].current_file] == NULL ) 196 { 197 /* We have finished with this list of includes */ 198 globfree(&nested_conffiles[current_nested_level].filelist); 199 yy_switch_to_buffer(nested_conffiles[current_nested_level].parent_level_state); 200 } 201 else 202 { 203 /* Proceed to next included file */ 204 yyin = fopen( nested_conffiles[current_nested_level].filelist.gl_pathv[nested_conffiles[current_nested_level].current_file], "r" ); 205 206 if ( ! yyin ) 207 { 208 TRACE_DEBUG_ERROR("Error in %s: %s", nested_conffiles[current_nested_level].filelist.gl_pathv[nested_conffiles[current_nested_level].current_file], strerror(errno)); 209 return LEX_ERROR; 210 } 211 212 yy_switch_to_buffer(yy_create_buffer( yyin, YY_BUF_SIZE )); 213 214 /* In case of recursive includes */ 215 current_nested_level++; 216 } 217 218 } 89 219 90 220 {qstring} { -
libfdcore/fdd.y
r950 r961 3 3 * Author: Sebastien Decugis <sdecugis@freediameter.net> * 4 4 * * 5 * Copyright (c) 201 2, WIDE Project and NICT *5 * Copyright (c) 2013, WIDE Project and NICT * 6 6 * All rights reserved. * 7 7 * * -
libfdcore/peers.c
r933 r961 91 91 92 92 /* Add a new peer entry */ 93 int fd_peer_add ( struct peer_info * info, c har * orig_dbg, void (*cb)(struct peer_info *, void *), void * cb_data )93 int fd_peer_add ( struct peer_info * info, const char * orig_dbg, void (*cb)(struct peer_info *, void *), void * cb_data ) 94 94 { 95 95 struct fd_peer *p = NULL; -
libfdcore/peers.c
r950 r961 3 3 * Author: Sebastien Decugis <sdecugis@freediameter.net> * 4 4 * * 5 * Copyright (c) 201 2, WIDE Project and NICT *5 * Copyright (c) 2013, WIDE Project and NICT * 6 6 * All rights reserved. * 7 7 * * … … 515 515 peer->p_flags.pf_delete = 1; 516 516 517 #ifndef DISABLE_PEER_EXPIRY 517 518 /* Set this peer to expire on inactivity */ 518 519 peer->p_hdr.info.config.pic_flags.exp = PI_EXP_INACTIVE; 519 520 peer->p_hdr.info.config.pic_lft = 3600; /* 1 hour without any message 520 521 -- RFC3539 states that this must not be inferior to BRINGDOWN_INTERVAL = 5 minutes */ 522 521 523 CHECK_FCT_DO( ret = fd_p_expi_update( peer ), goto out ); 522 524 #endif /* DISABLE_PEER_EXPIRY */ 523 525 524 526 /* Insert the new peer in the list (the PSM will take care of setting the expiry after validation) */ -
libfdcore/sctp.c
r928 r961 909 909 } 910 910 if (TRACE_BOOL(SCTP_LEVEL)) { 911 char buf[1024]; 912 sSA_DUMP_NODE_SERV(buf, sizeof(buf), &status.sstat_primary.spinfo_address, NI_NUMERICHOST | NI_NUMERICSERV ); 911 913 fd_log_debug( "SCTP_STATUS : sstat_state : %i\n" , status.sstat_state); 912 914 fd_log_debug( " sstat_rwnd : %u\n" , status.sstat_rwnd); … … 916 918 fd_log_debug( " sstat_outstrms : %hu\n", status.sstat_outstrms); 917 919 fd_log_debug( " sstat_fragmentation_point : %u\n" , status.sstat_fragmentation_point); 918 fd_log_debug( " sstat_primary.spinfo_address : "); 919 sSA_DUMP_NODE_SERV(&status.sstat_primary.spinfo_address, NI_NUMERICHOST | NI_NUMERICSERV ); 920 fd_log_debug( "\n" ); 920 fd_log_debug( " sstat_primary.spinfo_address : %s\n" , buf); 921 921 fd_log_debug( " sstat_primary.spinfo_state : %d\n" , status.sstat_primary.spinfo_state); 922 922 fd_log_debug( " sstat_primary.spinfo_cwnd : %u\n" , status.sstat_primary.spinfo_cwnd); -
libfdcore/sctp.c
r950 r961 3 3 * Author: Sebastien Decugis <sdecugis@freediameter.net> * 4 4 * * 5 * Copyright (c) 201 2, WIDE Project and NICT *5 * Copyright (c) 2013, WIDE Project and NICT * 6 6 * All rights reserved. * 7 7 * * -
libfdproto/dictionary.c
r928 r961 1278 1278 _OBINFO(obj).dump_data(&obj->data); 1279 1279 1280 fd_log_debug("\n");1281 1282 1280 if (depth) { 1283 1281 int i; … … 1470 1468 1471 1469 /* Done! */ 1472 CHECK_FCT( dump_add_str(outstr, offset, outlen, "\n") );1473 1470 return 0; 1474 1471 } … … 1725 1722 switch (type) { 1726 1723 case DICT_VENDOR: 1724 TRACE_DEBUG(FULL, "Vendor %s already in dictionary", new->data.vendor.vendor_name); 1727 1725 /* if we are here, it means the two vendors id are identical */ 1728 1726 if (fd_os_cmp(locref->data.vendor.vendor_name, locref->datastr_len, … … 1736 1734 1737 1735 case DICT_APPLICATION: 1736 TRACE_DEBUG(FULL, "Application %s already in dictionary", new->data.application.application_name); 1738 1737 /* got same id */ 1739 1738 if (fd_os_cmp(locref->data.application.application_name, locref->datastr_len, … … 1746 1745 1747 1746 case DICT_TYPE: 1747 TRACE_DEBUG(FULL, "Type %s already in dictionary", new->data.type.type_name); 1748 1748 /* got same name */ 1749 1749 if (locref->data.type.type_base != new->data.type.type_base) { … … 1768 1768 1769 1769 case DICT_ENUMVAL: 1770 TRACE_DEBUG(FULL, "Enum %s already in dictionary", new->data.enumval.enum_name); 1770 1771 /* got either same name or same value. We check that both are true */ 1771 1772 if (order_enum_by_name(locref, new)) { … … 1781 1782 1782 1783 case DICT_AVP: 1784 TRACE_DEBUG(FULL, "AVP %s already in dictionary", new->data.avp.avp_name); 1783 1785 /* got either same name or code */ 1784 1786 if (order_avp_by_code(locref, new)) { … … 1810 1812 1811 1813 case DICT_COMMAND: 1814 TRACE_DEBUG(FULL, "Command %s already in dictionary", new->data.cmd.cmd_name); 1812 1815 /* We got either same name, or same code + R flag */ 1813 1816 if (order_cmd_by_name(locref, new)) { -
libfdproto/dictionary.c
r952 r961 3 3 * Author: Sebastien Decugis <sdecugis@freediameter.net> * 4 4 * * 5 * Copyright (c) 201 2, WIDE Project and NICT *5 * Copyright (c) 2013, WIDE Project and NICT * 6 6 * All rights reserved. * 7 7 * * -
libfdproto/log.c
r928 r961 44 44 int fd_g_debug_lvl = INFO; 45 45 46 static void fd_internal_logger( int, const char *, va_list ); 47 46 48 /* These may be used to pass specific debug requests via the command-line parameters */ 47 49 char * fd_debug_one_function = NULL; … … 53 55 54 56 /* Allow passing of the log and debug information from base stack to extensions */ 55 void (*fd_ external_logger)( const char * format, va_list *args ) = NULL;57 void (*fd_logger)( int loglevel, const char * format, va_list args ) = fd_internal_logger; 56 58 57 /* Register an dexternal call back for tracing and debug */58 int fd_log_handler_register( void (*logger)( const char * format, va_list *args))59 /* Register an external call back for tracing and debug */ 60 int fd_log_handler_register( void (*logger)(int loglevel, const char * format, va_list args) ) 59 61 { 60 62 CHECK_PARAMS( logger ); 61 63 62 if ( fd_ external_logger != NULL)64 if ( fd_logger != fd_internal_logger ) 63 65 { 64 66 return EALREADY; /* only one registration allowed */ … … 66 68 else 67 69 { 68 fd_ external_logger = logger;70 fd_logger = logger; 69 71 } 72 70 73 return 0; 71 74 } … … 74 77 int fd_log_handler_unregister ( void ) 75 78 { 76 fd_ external_logger = NULL;79 fd_logger = fd_internal_logger; 77 80 return 0; /* Successfull in all cases. */ 78 81 } … … 83 86 } 84 87 88 89 static void fd_internal_logger( int loglevel, const char *format, va_list ap ) 90 { 91 char buf[25]; 92 FILE *fstr = fd_g_debug_fstr ?: stdout; 93 94 /* logging has been decided by macros outside already */ 95 96 /* add timestamp */ 97 fprintf(fd_g_debug_fstr, "%s\t", fd_log_time(NULL, buf, sizeof(buf))); 98 vfprintf(fd_g_debug_fstr, format, ap); 99 if (format && (format[strlen(format)-1] != '\n')) { 100 fprintf(fd_g_debug_fstr, "\n"); 101 } 102 fflush(fd_g_debug_fstr); 103 } 104 85 105 /* Log a debug message */ 86 void fd_log _debug_fstr ( FILE * fstr, const char * format, ... )106 void fd_log ( int loglevel, const char * format, ... ) 87 107 { 88 108 va_list ap; … … 93 113 94 114 va_start(ap, format); 95 if ( fd_external_logger != NULL ) 96 { 97 fd_external_logger( format, &ap ); 98 } 99 else 100 { 101 vfprintf( fstr ?: stdout, format, ap); 102 fflush(fstr ?: stdout); 103 } 115 fd_logger(loglevel, format, ap); 104 116 va_end(ap); 105 117 … … 107 119 108 120 (void)pthread_mutex_unlock(&fd_log_lock); 121 } 122 123 /* Log debug message to file. */ 124 void fd_log_debug_fstr( FILE * fstr, const char * format, ... ) 125 { 126 va_list ap; 127 128 va_start(ap, format); 129 vfprintf(fstr, format, ap); 130 va_end(ap); 109 131 } 110 132 -
libfdproto/log.c
r945 r961 3 3 * Author: Sebastien Decugis <sdecugis@freediameter.net> * 4 4 * * 5 * Copyright (c) 201 2, WIDE Project and NICT *5 * Copyright (c) 2013, WIDE Project and NICT * 6 6 * All rights reserved. * 7 7 * * -
libfdproto/messages.c
r928 r961 683 683 struct tm tm; 684 684 685 CHECK_FCT( dump_add_str(outstr, offset, outlen, "%*sMSG: %p \n", INOBJHDRVAL, msg) );685 CHECK_FCT( dump_add_str(outstr, offset, outlen, "%*sMSG: %p|", INOBJHDRVAL, msg) ); 686 686 687 687 if (!CHECK_MSG(msg)) { 688 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "INVALID! \n", INOBJHDRVAL) );688 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "INVALID!", INOBJHDRVAL) ); 689 689 return 0; 690 690 } … … 693 693 tsoffset += strftime(buftime + tsoffset, sizeof(buftime) - tsoffset, "%D,%T", localtime_r( &msg->msg_ts_rcv.tv_sec , &tm )); 694 694 tsoffset += snprintf(buftime + tsoffset, sizeof(buftime) - tsoffset, ".%6.6ld", msg->msg_ts_rcv.tv_nsec / 1000); 695 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "Received: %s \n", INOBJHDRVAL, buftime) );695 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "Received: %s|", INOBJHDRVAL, buftime) ); 696 696 } 697 697 if ((msg->msg_ts_sent.tv_sec != 0) || (msg->msg_ts_sent.tv_nsec != 0)) { 698 698 tsoffset += strftime(buftime + tsoffset, sizeof(buftime) - tsoffset, "%D,%T", localtime_r( &msg->msg_ts_sent.tv_sec , &tm )); 699 699 tsoffset += snprintf(buftime + tsoffset, sizeof(buftime) - tsoffset, ".%6.6ld", msg->msg_ts_sent.tv_nsec / 1000); 700 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "Sent : %s \n", INOBJHDRVAL, buftime) );700 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "Sent : %s|", INOBJHDRVAL, buftime) ); 701 701 } 702 702 703 703 if (!msg->msg_model) { 704 704 705 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "(no model) \n", INOBJHDRVAL) );705 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "(no model)|", INOBJHDRVAL) ); 706 706 707 707 } else { … … 711 711 ret = fd_dict_gettype(msg->msg_model, &dicttype); 712 712 if (ret || (dicttype != DICT_COMMAND)) { 713 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "(invalid model: %d %d) \n", INOBJHDRVAL, ret, dicttype) );713 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "(invalid model: %d %d)|", INOBJHDRVAL, ret, dicttype) ); 714 714 goto public; 715 715 } 716 716 ret = fd_dict_getval(msg->msg_model, &dictdata); 717 717 if (ret != 0) { 718 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "(error getting model data: %s) \n", INOBJHDRVAL, strerror(ret)) );718 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "(error getting model data: %s)|", INOBJHDRVAL, strerror(ret)) ); 719 719 goto public; 720 720 } 721 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "model : v/m:" DUMP_CMDFL_str "/" DUMP_CMDFL_str ", %u \"%s\" \n", INOBJHDRVAL,721 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "model : v/m:" DUMP_CMDFL_str "/" DUMP_CMDFL_str ", %u \"%s\"|", INOBJHDRVAL, 722 722 DUMP_CMDFL_val(dictdata.cmd_flag_val), DUMP_CMDFL_val(dictdata.cmd_flag_mask), dictdata.cmd_code, dictdata.cmd_name) ); 723 723 } 724 724 public: 725 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "public: V:%d L:%d fl:" DUMP_CMDFL_str " CC:%u A:%d hi:%x ei:%x \n", INOBJHDRVAL,725 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "public: V:%d L:%d fl:" DUMP_CMDFL_str " CC:%u A:%d hi:%x ei:%x|", INOBJHDRVAL, 726 726 msg->msg_public.msg_version, 727 727 msg->msg_public.msg_length, … … 732 732 msg->msg_public.msg_eteid 733 733 ) ); 734 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "intern: rwb:%p rt:%d cb:%p(%p) qry:%p asso:%d sess:%p src:%s(%zd) \n",734 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "intern: rwb:%p rt:%d cb:%p(%p) qry:%p asso:%d sess:%p src:%s(%zd)|", 735 735 INOBJHDRVAL, msg->msg_rawbuffer, msg->msg_routable, msg->msg_cb.fct, msg->msg_cb.data, msg->msg_query, msg->msg_associated, msg->msg_sess, msg->msg_src_id?:"(nil)", msg->msg_src_id_len) ); 736 736 return 0; … … 743 743 744 744 if (!CHECK_AVP(avp)) { 745 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "INVALID! \n", INOBJHDRVAL) );745 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "INVALID!", INOBJHDRVAL) ); 746 746 return 0; 747 747 } … … 749 749 if (!avp->avp_model) { 750 750 751 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "(no model resolved) \n", INOBJHDRVAL) );751 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "(no model resolved)|", INOBJHDRVAL) ); 752 752 753 753 } else { … … 757 757 ret = fd_dict_gettype(avp->avp_model, &dicttype); 758 758 if (ret || (dicttype != DICT_AVP)) { 759 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "(invalid model: %d %d) \n", INOBJHDRVAL, ret, dicttype) );759 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "(invalid model: %d %d)|", INOBJHDRVAL, ret, dicttype) ); 760 760 goto public; 761 761 } 762 762 ret = fd_dict_getval(avp->avp_model, &dictdata); 763 763 if (ret != 0) { 764 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "(error getting model data: %s) \n", INOBJHDRVAL, strerror(ret)) );764 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "(error getting model data: %s)|", INOBJHDRVAL, strerror(ret)) ); 765 765 goto public; 766 766 } 767 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "model : v/m:" DUMP_AVPFL_str "/" DUMP_AVPFL_str ", %12s, %u \"%s\" \n", INOBJHDRVAL,767 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "model : v/m:" DUMP_AVPFL_str "/" DUMP_AVPFL_str ", %12s, %u \"%s\"|", INOBJHDRVAL, 768 768 DUMP_AVPFL_val(dictdata.avp_flag_val), 769 769 DUMP_AVPFL_val(dictdata.avp_flag_mask), … … 773 773 } 774 774 public: 775 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "public: C:%u fl:" DUMP_AVPFL_str " L:%d V:%u data:@%p \n", INOBJHDRVAL,775 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "public: C:%u fl:" DUMP_AVPFL_str " L:%d V:%u data:@%p|", INOBJHDRVAL, 776 776 avp->avp_public.avp_code, 777 777 DUMP_AVPFL_val(avp->avp_public.avp_flags), … … 783 783 if (avp->avp_public.avp_value) { 784 784 if (!avp->avp_model) { 785 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "(data set but no model: ERROR) \n", INOBJHDRVAL) );785 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "(data set but no model: ERROR)|", INOBJHDRVAL) ); 786 786 } else { 787 787 CHECK_FCT( fd_dict_dump_avp_value(avp->avp_public.avp_value, avp->avp_model, indent, outstr, offset, outlen) ); … … 789 789 } 790 790 791 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "intern: src:%p mf:%d raw:%p(%d) \n", INOBJHDRVAL, avp->avp_source, avp->avp_mustfreeos, avp->avp_rawdata, avp->avp_rawlen) );791 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "intern: src:%p mf:%d raw:%p(%d)|", INOBJHDRVAL, avp->avp_source, avp->avp_mustfreeos, avp->avp_rawdata, avp->avp_rawlen) ); 792 792 return 0; 793 793 } … … 880 880 /* now really output this in one shot, so it is not interrupted */ 881 881 TRACE_DEBUG(level, "------ Dumping object %p (w)-------", obj); 882 fd_log_debug_fstr(fd_g_debug_fstr, "%s", outstr);882 TRACE_DEBUG(level, "%s", outstr); 883 883 TRACE_DEBUG(level, "------ /end of object %p -------", obj); 884 884 … … 896 896 fd_log_debug_fstr(fd_g_debug_fstr, "Error while dumping %p\n", obj) ); 897 897 TRACE_DEBUG(level, "------ Dumping object %p (s)-------", obj); 898 fd_log_debug_fstr(fd_g_debug_fstr, "%s", outstr);898 TRACE_DEBUG(level, "%s", outstr); 899 899 TRACE_DEBUG(level, "------ /end of object %p -------", obj); 900 900 free(outstr); -
libfdproto/messages.c
r951 r961 3 3 * Author: Sebastien Decugis <sdecugis@freediameter.net> * 4 4 * * 5 * Copyright (c) 201 2, WIDE Project and NICT *5 * Copyright (c) 2013, WIDE Project and NICT * 6 6 * All rights reserved. * 7 7 * *
Note: See TracChangeset
for help on using the changeset viewer.