Changeset 1085:7d7266115a34 in freeDiameter for libfdproto/sessions.c
- Timestamp:
- May 3, 2013, 8:20:56 PM (11 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libfdproto/sessions.c
r1027 r1085 70 70 int id; /* A unique integer to identify this handler */ 71 71 void (*cleanup)(session_state *, os0_t, void *); /* The cleanup function to be called for cleaning a state */ 72 session_state_dump *state_dump; /* dumper function */ 72 73 void *opaque; /* a value that is passed as is to the cleanup callback */ 73 74 }; … … 273 274 274 275 /* Create a new handler */ 275 int fd_sess_handler_create_internal ( struct session_handler ** handler, void (*cleanup)(session_state *, os0_t, void *), void * opaque )276 int fd_sess_handler_create_internal ( struct session_handler ** handler, void (*cleanup)(session_state *, os0_t, void *), session_state_dump dumper, void * opaque ) 276 277 { 277 278 struct session_handler *new; … … 290 291 new->eyec = SH_EYEC; 291 292 new->cleanup = cleanup; 293 new->state_dump = dumper; 292 294 new->opaque = opaque; 293 295 … … 873 875 874 876 /* Dump functions */ 875 void fd_sess_dump(int level, struct session * session) 876 { 877 struct fd_list * li; 878 char buf[30]; 879 struct tm tm; 880 881 if (!TRACE_BOOL(level)) 882 return; 883 884 fd_log_debug("\t %*s -- Session @%p --", level, "", session); 877 DECLARE_FD_DUMP_PROTOTYPE(fd_sess_dump, struct session * session, int with_states) 878 { 879 size_t o = 0; 880 if (!offset) 881 offset = &o; 882 883 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "{session}(@%p): ", session), return NULL); 884 885 885 if (!VALIDATE_SI(session)) { 886 fd_log_debug("\t %*s Invalid session object", level, "");886 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "INVALID/NULL\n"), return NULL); 887 887 } else { 888 889 fd_log_debug("\t %*s sid '%s'(%zd), hash %x, msg %d, destroyed %d", level, "", session->sid, session->sidlen, session->hash, session->msg_cnt, session->is_destroyed); 890 891 strftime(buf, sizeof(buf), "%D,%T", localtime_r( &session->timeout.tv_sec , &tm )); 892 fd_log_debug("\t %*s timeout %s.%09ld", level, "", buf, session->timeout.tv_nsec); 893 894 CHECK_POSIX_DO( pthread_mutex_lock(&session->stlock), /* ignore */ ); 895 pthread_cleanup_push( fd_cleanup_mutex, &session->stlock ); 896 for (li = session->states.next; li != &session->states; li = li->next) { 897 struct state * st = (struct state *)(li->o); 898 fd_log_debug("\t %*s handler %d registered data %p", level, "", st->hdl->id, st->state); 888 char timebuf[30]; 889 struct tm tm; 890 891 strftime(timebuf, sizeof(timebuf), "%D,%T", localtime_r( &session->timeout.tv_sec , &tm )); 892 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "'%s'(%zd) h:%x m:%d d:%d to:%s.%06ld\n", 893 session->sid, session->sidlen, session->hash, session->msg_cnt, session->is_destroyed, 894 timebuf, session->timeout.tv_nsec/1000), 895 return NULL); 896 897 if (with_states) { 898 struct fd_list * li; 899 CHECK_POSIX_DO( pthread_mutex_lock(&session->stlock), /* ignore */ ); 900 pthread_cleanup_push( fd_cleanup_mutex, &session->stlock ); 901 902 for (li = session->states.next; li != &session->states; li = li->next) { 903 struct state * st = (struct state *)(li->o); 904 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " {state i:%d}(@%p): \n", st->hdl->id, st), return NULL); 905 if (st->hdl->state_dump) { 906 CHECK_MALLOC_DO( (*st->hdl->state_dump)( FD_DUMP_STD_PARAMS, st->state), 907 fd_dump_extend( FD_DUMP_STD_PARAMS, "[dumper error]\n")); 908 } else { 909 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "<%p>\n", st->state), return NULL); 910 } 911 } 912 913 pthread_cleanup_pop(0); 914 CHECK_POSIX_DO( pthread_mutex_unlock(&session->stlock), /* ignore */ ); 899 915 } 900 pthread_cleanup_pop(0);901 CHECK_POSIX_DO( pthread_mutex_unlock(&session->stlock), /* ignore */ );902 903 fd_log_debug("\t %*s -- end of session @%p --", level, "", session); 904 } 905 906 void fd_sess_dump_hdl(int level, struct session_handler * handler) 907 { 908 if (!TRACE_BOOL(level))909 return;910 911 fd_log_debug("\t %*s -- Handler @%p --", level, "", handler);916 } 917 return *buf; 918 } 919 920 DECLARE_FD_DUMP_PROTOTYPE(fd_sess_dump_hdl, struct session_handler * handler) 921 { 922 size_t o = 0; 923 if (!offset) 924 offset = &o; 925 926 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "{sesshdl}(@%p): ", handler), return NULL); 927 912 928 if (!VALIDATE_SH(handler)) { 913 fd_log_debug("\t %*s Invalid session handler object", level, "");929 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "INVALID/NULL\n"), return NULL); 914 930 } else { 915 fd_log_debug("\t %*s id %d, cleanup %p, opaque %p", level, "", handler->id, handler->cleanup, handler->opaque);916 } 917 fd_log_debug("\t %*s -- end of handler @%p --", level, "", handler);931 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "i:%d cl:%p d:%p o:%p\n", handler->id, handler->cleanup, handler->state_dump, handler->opaque), return NULL); 932 } 933 return *buf; 918 934 } 919 935
Note: See TracChangeset
for help on using the changeset viewer.