Navigation


Changeset 5:c2d2729e3603 in freeDiameter for libfreeDiameter/sessions.c


Ignore:
Timestamp:
Sep 3, 2009, 2:33:45 PM (15 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Completed new session module tests; some bugs fixed

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libfreeDiameter/sessions.c

    r4 r5  
    296296                                if (st->hdl->id < del->id)
    297297                                        continue;
    298                                 if (st->hdl->id > del->id)
    299                                         break;
    300                                 /* This state belongs to the handler we are deleting, move the item to the deleted_states list */
    301                                 fd_list_unlink(&st->chain);
    302                                 CHECK_MALLOC( st->sid = strdup(sess->sid) );
    303                                 fd_list_insert_before(&deleted_states, &st->chain);
     298                                if (st->hdl->id == del->id) {
     299                                        /* This state belongs to the handler we are deleting, move the item to the deleted_states list */
     300                                        fd_list_unlink(&st->chain);
     301                                        CHECK_MALLOC( st->sid = strdup(sess->sid) );
     302                                        fd_list_insert_before(&deleted_states, &st->chain);
     303                                }
     304                                break;
    304305                        }
    305306                        CHECK_POSIX(  pthread_mutex_unlock(&sess->stlock)  );
     
    400401        }
    401402       
    402         /* If the session did not exist, we can add it into the hash table */
     403        /* If the session did not exist, we can link it in global tables */
    403404        if (!found) {
    404                 fd_list_insert_before(li, &sess->chain_h);
     405                fd_list_insert_before(li, &sess->chain_h); /* hash table */
    405406               
    406407                /* We must also insert in the expiry list */
     
    410411                for (li = exp_sentinel.prev; li != &exp_sentinel; li = li->prev) {
    411412                        struct session * s = (struct session *)(li->o);
    412                        
    413413                        if (TS_IS_INFERIOR( &s->timeout, &sess->timeout ) )
    414414                                break;
    415                        
    416                         continue;
    417415                }
    418416                fd_list_insert_after( li, &sess->expire );
     417
     418                #if 0
     419                if (TRACE_BOOL(ANNOYING)) {     
     420                        TRACE_DEBUG(FULL, "-- Updated session expiry list --");
     421                        for (li = exp_sentinel.next; li != &exp_sentinel; li = li->next) {
     422                                struct session * s = (struct session *)(li->o);
     423                                fd_sess_dump(FULL, s);
     424                        }
     425                        TRACE_DEBUG(FULL, "-- end of expiry list --");
     426                }
     427                #endif
    419428               
    420429                /* We added a new expiring element, we must signal */
     
    502511        /* We added a new expiring element, we must signal */
    503512        CHECK_POSIX( pthread_cond_signal(&exp_cond) );
     513
     514        #if 0
     515        if (TRACE_BOOL(ANNOYING)) {     
     516                TRACE_DEBUG(FULL, "-- Updated session expiry list --");
     517                for (li = exp_sentinel.next; li != &exp_sentinel; li = li->next) {
     518                        struct session * s = (struct session *)(li->o);
     519                        fd_sess_dump(FULL, s);
     520                }
     521                TRACE_DEBUG(FULL, "-- end of expiry list --");
     522        }
     523        #endif
    504524
    505525        /* We're done */
     
    548568
    549569/* Save a state information with a session */
    550 int fd_sess_state_store ( struct session_handler * handler, struct session * session, session_state ** state )
     570int fd_sess_state_store_int ( struct session_handler * handler, struct session * session, session_state ** state )
    551571{
    552572        struct state *new;
     
    597617
    598618/* Get the data back */
    599 int fd_sess_state_retrieve ( struct session_handler * handler, struct session * session, session_state ** state )
     619int fd_sess_state_retrieve_int ( struct session_handler * handler, struct session * session, session_state ** state )
    600620{
    601621        struct fd_list * li;
     
    632652
    633653
    634 
    635654/* Dump functions */
    636655void fd_sess_dump(int level, struct session * session)
    637656{
    638657        struct fd_list * li;
     658        char buf[30];
     659        struct tm tm;
     660       
    639661        if (!TRACE_BOOL(level))
    640662                return;
    641663       
    642         fd_log_debug("Session @%p:\n", session);
     664        fd_log_debug("\t  %*s -- Session @%p --\n", level, "", session);
    643665        if (!VALIDATE_SI(session)) {
    644                 fd_log_debug("  Invalid session object\n");
    645                 return;
    646         }
    647                
    648         fd_log_debug("  sid '%s', hash %x\n", session->sid, session->hash);
    649         fd_log_debug("  timeout %d.%09d\n", session->timeout.tv_sec, session->timeout.tv_nsec);
    650        
    651         CHECK_POSIX_DO( pthread_mutex_lock(&session->stlock), /* ignore */ );
    652         for (li = session->states.next; li != &session->states; li = li->next) {
    653                 struct state * st = (struct state *)(li->o);
    654                 fd_log_debug("    handler %d registered data %p\n", st->hdl->id, st->state);
    655         }
    656         CHECK_POSIX_DO( pthread_mutex_unlock(&session->stlock), /* ignore */ );
     666                fd_log_debug("\t  %*s  Invalid session object\n", level, "");
     667        } else {
     668               
     669                fd_log_debug("\t  %*s  sid '%s', hash %x\n", level, "", session->sid, session->hash);
     670
     671                strftime(buf, sizeof(buf), "%D,%T", localtime_r( &session->timeout.tv_sec , &tm ));
     672                fd_log_debug("\t  %*s  timeout %s.%09ld\n", level, "", buf, session->timeout.tv_nsec);
     673
     674                CHECK_POSIX_DO( pthread_mutex_lock(&session->stlock), /* ignore */ );
     675                for (li = session->states.next; li != &session->states; li = li->next) {
     676                        struct state * st = (struct state *)(li->o);
     677                        fd_log_debug("\t  %*s    handler %d registered data %p\n", level, "", st->hdl->id, st->state);
     678                }
     679                CHECK_POSIX_DO( pthread_mutex_unlock(&session->stlock), /* ignore */ );
     680        }
     681        fd_log_debug("\t  %*s -- end of session @%p --\n", level, "", session);
    657682}
    658683
     
    662687                return;
    663688       
    664         fd_log_debug("Handler @%p:\n", handler);
     689        fd_log_debug("\t  %*s -- Handler @%p --\n", level, "", handler);
    665690        if (!VALIDATE_SH(handler)) {
    666                 fd_log_debug("  Invalid session handler object\n");
    667                 return;
    668         }
    669                
    670         fd_log_debug("  id %d, cleanup %p\n", handler->id, handler->cleanup);
     691                fd_log_debug("\t  %*s  Invalid session handler object\n", level, "");
     692        } else {
     693                fd_log_debug("\t  %*s  id %d, cleanup %p\n", level, "", handler->id, handler->cleanup);
     694        }
     695        fd_log_debug("\t  %*s -- end of handler @%p --\n", level, "", handler);
    671696}       
Note: See TracChangeset for help on using the changeset viewer.