Changeset 689:933d098fc75d in freeDiameter
- Timestamp:
- Jan 20, 2011, 2:24:13 PM (13 years ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
include/freeDiameter/libfdproto.h
r688 r689 2068 2068 }; 2069 2069 int fd_msg_log_config(enum fd_msg_log_cause cause, enum fd_msg_log_method method, const char * arg); 2070 void ml_conf_init(struct dictionary *dict);2070 void fd_msg_log_init(struct dictionary *dict); 2071 2071 2072 2072 /*********************************************/ -
libfdcore/core.c
r688 r689 197 197 198 198 /* Initialize the message logging facility */ 199 ml_conf_init(fd_g_config->cnf_dict);199 fd_msg_log_init(fd_g_config->cnf_dict); 200 200 201 201 /* Add definitions of the base protocol */ -
libfdproto/CMakeLists.txt
r668 r689 12 12 log.c 13 13 messages.c 14 msg_log.c 14 15 rt_data.c 15 16 sessions.c -
libfdproto/fdproto-internal.h
r687 r689 51 51 FILE * fd_g_debug_fstr; 52 52 53 /* Special message dump function */ 54 void fd_msg_dump_fstr ( struct msg * msg, FILE * fstr ); 55 53 56 /* Iterator on the rules of a parent object */ 54 57 int fd_dict_iterate_rules ( struct dict_object *parent, void * data, int (*cb)(void *, struct dict_rule_data *) ); -
libfdproto/messages.c
r688 r689 2325 2325 2326 2326 2327 /***************************************************************************************************************/2328 /* messages logging facility */2329 #include <stdarg.h>2330 2331 static struct {2332 struct {2333 enum fd_msg_log_method meth;2334 const char * metharg;2335 } causes[FD_MSG_LOG_MAX + 1];2336 pthread_mutex_t lock;2337 int init;2338 struct dictionary *dict;2339 } ml_conf = { .lock = PTHREAD_MUTEX_INITIALIZER, .init = 0 };2340 2341 void ml_conf_init(struct dictionary *dict)2342 {2343 memset(&ml_conf.causes, 0, sizeof(ml_conf.causes));2344 ml_conf.init = 1;2345 ml_conf.dict = dict;2346 }2347 2348 /* Set a configuration property */2349 int fd_msg_log_config(enum fd_msg_log_cause cause, enum fd_msg_log_method method, const char * arg)2350 {2351 /* Check the parameters are valid */2352 TRACE_ENTRY("%d %d %p", cause, method, arg);2353 CHECK_PARAMS( (cause >= 0) && (cause <= FD_MSG_LOG_MAX) );2354 CHECK_PARAMS( (method >= FD_MSG_LOGTO_DEBUGONLY) && (method <= FD_MSG_LOGTO_DIR) );2355 CHECK_PARAMS( (method == FD_MSG_LOGTO_DEBUGONLY) || (arg != NULL) );2356 2357 /* Lock the configuration */2358 CHECK_POSIX( pthread_mutex_lock(&ml_conf.lock) );2359 if (!ml_conf.init) {2360 ASSERT(0);2361 }2362 2363 /* Now set the parameter */2364 ml_conf.causes[cause].meth = method;2365 ml_conf.causes[cause].metharg = arg;2366 2367 if (method) {2368 TRACE_DEBUG(INFO, "Logging %s messages set to %s '%s'",2369 (cause == FD_MSG_LOG_DROPPED) ? "DROPPED" :2370 (cause == FD_MSG_LOG_RECEIVED) ? "RECEIVED" :2371 (cause == FD_MSG_LOG_SENT) ? "SENT" :2372 "???",2373 (method == FD_MSG_LOGTO_FILE) ? "file" :2374 (method == FD_MSG_LOGTO_DIR) ? "directory" :2375 "???",2376 arg);2377 }2378 2379 CHECK_POSIX( pthread_mutex_unlock(&ml_conf.lock) );2380 2381 /* Done */2382 return 0;2383 }2384 2385 /* Do not log anything within this one, since log lock is held */2386 static void fd_cleanup_mutex_silent( void * mutex )2387 {2388 (void)pthread_mutex_unlock((pthread_mutex_t *)mutex);2389 }2390 2391 /* Really log the message */2392 void fd_msg_log( enum fd_msg_log_cause cause, struct msg * msg, const char * prefix_format, ... )2393 {2394 va_list ap;2395 enum fd_msg_log_method meth;2396 const char * metharg;2397 FILE * fstr;2398 2399 TRACE_ENTRY("%d %p %p", cause, msg, prefix_format);2400 CHECK_PARAMS_DO( (cause >= 0) && (cause <= FD_MSG_LOG_MAX),2401 {2402 TRACE_DEBUG(INFO, "Invalid cause received (%d)! Message was:", cause);2403 fd_msg_dump_walk(INFO, msg);2404 } );2405 2406 /* First retrieve the config for this message */2407 CHECK_POSIX_DO( pthread_mutex_lock(&ml_conf.lock), );2408 if (!ml_conf.init) {2409 ASSERT(0);2410 }2411 meth = ml_conf.causes[cause].meth;2412 metharg = ml_conf.causes[cause].metharg;2413 CHECK_POSIX_DO( pthread_mutex_unlock(&ml_conf.lock), );2414 2415 /* Okay, now we will create the file descriptor */2416 switch (meth) {2417 case FD_MSG_LOGTO_DEBUGONLY:2418 fstr = fd_g_debug_fstr;2419 break;2420 2421 case FD_MSG_LOGTO_FILE:2422 TODO("Log to arg file");2423 TODO("Log a note to debug stream");2424 break;2425 case FD_MSG_LOGTO_DIR:2426 TODO("Log to arg directory in a new file");2427 TODO("Log a note to debug stream");2428 break;2429 }2430 2431 /* For file methods, let's parse the message so it looks better */2432 if ((meth != FD_MSG_LOGTO_DEBUGONLY) && ml_conf.dict) {2433 CHECK_FCT_DO( fd_msg_parse_dict( msg, ml_conf.dict, NULL ), );2434 }2435 2436 /* Then dump the prefix message to this stream, & to debug stream */2437 (void)pthread_mutex_lock(&fd_log_lock);2438 pthread_cleanup_push(fd_cleanup_mutex_silent, &fd_log_lock);2439 va_start(ap, prefix_format);2440 vfprintf( fstr, prefix_format, ap);2441 va_end(ap);2442 fflush(fstr);2443 pthread_cleanup_pop(0);2444 (void)pthread_mutex_unlock(&fd_log_lock);2445 fd_log_debug_fstr(fstr, "\n\n");2446 2447 /* And now the message itself */2448 fd_msg_dump_fstr(msg, fstr);2449 2450 /* And finally close the stream if needed */2451 TODO("close?");2452 }2453 -
tests/tests.h
r676 r689 68 68 fprintf(stderr, ## message); \ 69 69 TRACE_DEBUG(INFO, "Test failed"); \ 70 (void)fd_core_shutdown(); \71 (void)fd_core_wait_shutdown_complete(); \72 70 exit(FAIL); \ 73 71 } … … 79 77 (void)fd_core_shutdown(); \ 80 78 (void)fd_core_wait_shutdown_complete(); \ 79 (void)fd_thr_term(&timeout_thr); \ 81 80 exit(PASS); \ 82 81 } … … 186 185 CHECK( 0, fd_conf_init() ); 187 186 187 /* Initialize the message logging facility */ 188 fd_msg_log_init(fd_g_config->cnf_dict); 189 188 190 /* Add definitions of the base protocol */ 189 191 CHECK( 0, fd_dict_base_protocol(fd_g_config->cnf_dict) );
Note: See TracChangeset
for help on using the changeset viewer.