Changeset 126

Show
Ignore:
Timestamp:
24/10/08 11:33:05 (3 months ago)
Author:
smoku
Message:

Revamped session disconnection handling

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • jggtrans/src/sessions.c

    r125 r126  
    295295} 
    296296 
    297 gboolean session_timeout(gpointer data){ 
    298 Session *s; 
     297gboolean session_error(Session *s){ 
    299298GgServer *serv; 
    300299 
    301         g_assert(data!=NULL); 
    302         s=(Session *)data; 
    303300        serv=(GgServer*)s->current_server->data; 
    304         user_load_locale(s->user); 
    305301 
    306302        if(serv->port!=1){ 
    307                 g_warning(N_("Timeout for server %u - failure count: %d"), 
    308                         g_list_position(gg_servers, s->current_server), 
    309                         serv->error_count); 
    310  
    311303                /* failure accounting for non-hubs */ 
    312304                serv->error_count+=1; 
    313305                serv->error_time=time(NULL); 
    314         } else { 
    315                 g_warning(N_("Timeout for hub %u"), 
    316                         g_list_position(gg_servers, s->current_server)); 
    317306        } 
    318307 
     
    341330        g_warning(N_("Session timeout for %s"),s->jid); 
    342331 
     332        session_broken(s); 
     333        return FALSE; 
     334} 
     335 
     336gboolean session_timeout(gpointer data){ 
     337Session *s; 
     338GgServer *serv; 
     339 
     340        g_assert(data!=NULL); 
     341        s=(Session *)data; 
     342        serv=(GgServer*)s->current_server->data; 
     343        user_load_locale(s->user); 
     344 
     345        if(serv->port!=1){ 
     346                g_warning(N_("Timeout for server %u - failure count: %d"), 
     347                        g_list_position(gg_servers, s->current_server), 
     348                        serv->error_count); 
     349        } else { 
     350                g_warning(N_("Timeout for hub %u"), 
     351                        g_list_position(gg_servers, s->current_server)); 
     352        } 
     353 
     354        return session_error(s); 
     355} 
     356 
     357void session_broken(Session *s){ 
     358 
    343359        if (s->req_id){ 
    344                 jabber_iq_send_error(s->s,s->jid,NULL,s->req_id,504,_("Remote Server Timeout")); 
     360                jabber_iq_send_error(s->s,s->jid,NULL,s->req_id,502,_("Remote Server Error")); 
    345361        } 
    346362        else{ 
    347                 presence_send(s->s,NULL,s->user->jid,0,NULL,"Connection Timeout",0); 
    348         } 
    349  
     363                GList *it; 
     364                presence_send(s->s,NULL,s->user->jid,0,NULL,"Connection broken",0); 
     365                for(it=s->user->contacts;it;it=it->next){ 
     366                        Contact *c=(Contact *)it->data; 
     367 
     368                        if (!GG_S_NA(c->status) && c->status!=-1){ 
     369                                char *ujid; 
     370                                ujid=jid_build_full(c->uin); 
     371                                presence_send(s->s,ujid,s->user->jid,0,NULL,"Transport disconnected",0); 
     372                                g_free(ujid); 
     373                        } 
     374                } 
     375        } 
     376        s->connected=0; 
    350377        session_schedule_reconnect(s); 
    351378        session_remove(s); 
    352         return FALSE; 
    353 } 
     379} 
     380 
    354381 
    355382gboolean session_ping(gpointer data){ 
     
    453480} 
    454481 
    455 void session_broken(Session *s){ 
    456  
    457         if (s->req_id){ 
    458                 jabber_iq_send_error(s->s,s->jid,NULL,s->req_id,502,_("Remote Server Error")); 
    459         } 
    460         else{ 
    461                 GList *it; 
    462                 presence_send(s->s,NULL,s->user->jid,0,NULL,"Connection broken",0); 
    463                 for(it=s->user->contacts;it;it=it->next){ 
    464                         Contact *c=(Contact *)it->data; 
    465  
    466                         if (!GG_S_NA(c->status) && c->status!=-1){ 
    467                                 char *ujid; 
    468                                 ujid=jid_build_full(c->uin); 
    469                                 presence_send(s->s,ujid,s->user->jid,0,NULL,"Transport disconnected",0); 
    470                                 g_free(ujid); 
    471                         } 
    472                 } 
    473         } 
    474         s->connected=0; 
    475         session_schedule_reconnect(s); 
    476         session_remove(s); 
    477 } 
    478  
    479  
    480482int session_io_handler(Session *s){ 
    481483struct gg_event *event; 
     
    491493                if (condition&G_IO_HUP){ 
    492494                        g_warning(N_("Hangup on connection for %s, GGid: %i"),s->jid,s->ggs->uin); 
    493                         s->current_server=g_list_next(s->current_server); 
    494                         if(!s->connected && s->current_server!=NULL){ 
    495                                 session_try_login(s); 
    496                                 return FALSE; 
    497                         } 
     495                        return session_error(s); 
    498496                } 
    499497                if (condition&G_IO_NVAL) g_warning(N_("Invalid channel on connection for %s"),s->jid); 
     
    507505        if (!event){ 
    508506                g_warning(N_("Connection broken. Session of %s, GGid: %i"),s->jid,s->ggs->uin); 
    509                 session_broken(s); 
    510                 return FALSE; 
     507                return session_error(s); 
    511508        } 
    512509 
     
    514511                case GG_EVENT_DISCONNECT: 
    515512                        g_warning(N_("Server closed connection of %s, GGid: %i"),s->jid,s->ggs->uin); 
    516                         session_timeout((gpointer) s); 
     513                        session_error(s); 
    517514                        gg_event_free(event); 
    518515                        return FALSE; 
     
    534531                                        case GG_FAILURE_WRITING: 
    535532                                        case GG_FAILURE_TLS: 
    536                                                 session_timeout((gpointer) s); 
     533                                                session_error(s); 
    537534                                        default: 
    538535                                                break;