/* destroys Session object */ static int session_destroy(Session *s){ GList *it; g_message(L_("Deleting session for '%s'"),s->jid); if (s->ping_timeout_func) g_source_remove(s->ping_timeout_func); if (s->timeout_func) g_source_remove(s->timeout_func); if (s->ping_timer) g_timer_destroy(s->ping_timer); session_remove_g_source(s); while(s->resources) resource_remove((Resource *)s->resources->data,0); if (s->ggs){ if (s->connected){ debug("gg_logoff(%p)",s->ggs); gg_logoff(s->ggs); } gg_free_session(s->ggs); s->ggs=NULL; } if (s->connected && s->s && s->jid){ for(it=g_list_first(s->user->contacts);it;it=g_list_next(it)){ Contact *c=(Contact *)it->data; if (!GG_S_NA(c->status) && c->status!=-1){ char *ujid; ujid=jid_build_full(c->uin); presence_send(s->s,ujid,s->user->jid,0,NULL,NULL,0); g_free(ujid); } } } if (s->query) xmlnode_free(s->query); if (s->user) user_unref(s->user); g_free(s->gg_status_descr); g_free(s); return 0; }
int presence_unsubscribe(struct stream_s *stream,const char *from,const char *to){ User *u; Session *s; Contact *c; uin_t uin; u=user_get_by_jid(from); if (!u){ g_warning(N_("Presence subscription from unknown user (%s)"),from); presence_send_unsubscribed(stream,to,from); return -1; } if (jid_is_me(to)){ debug(L_("Presence unsubscribe request sent to me")); if (u->subscribe==SUB_TO || u->subscribe==SUB_UNDEFINED) u->subscribe=SUB_NONE; else if (u->subscribe==SUB_BOTH) u->subscribe=SUB_FROM; user_save(u); return 0; } if (!jid_has_uin(to) || !jid_is_my(to)){ g_warning(N_("Bad 'to': %s"),to); return -1; } s=session_get_by_jid(from,stream,0); debug(L_("Unsubscribing %s from %s..."),from,to); uin=jid_get_uin(to); c=user_get_contact(u,uin,FALSE); if (!c) { presence_send_unsubscribed(stream,to,from); return -1; } if (c->subscribe==SUB_TO) c->subscribe=SUB_NONE; else if (c->subscribe==SUB_BOTH) c->subscribe=SUB_FROM; user_save(u); if (s) session_update_contact(s,c); debug(L_("Unsubscribed.")); presence_send_unsubscribed(stream,to,from); if (!GG_S_NA(c->status) && c->status!=-1){ char *ujid; ujid=jid_build_full(uin); presence_send(stream,ujid,u->jid,0,NULL,"Unsubscribed",0); g_free(ujid); } return 0; }
void session_broken(Session *s){ if (s->req_id){ jabber_iq_send_error(s->s,s->jid,NULL,s->req_id,502,_("Remote Server Error")); } else{ GList *it; presence_send(s->s,NULL,s->user->jid,0,NULL,"Connection broken",0); for(it=g_list_first(s->user->contacts);it;it=g_list_next(it)){ Contact *c=(Contact *)it->data; if (!GG_S_NA(c->status) && c->status!=-1){ char *ujid; ujid=jid_build_full(c->uin); presence_send(s->s,ujid,s->user->jid,0,NULL,"Transport disconnected",0); g_free(ujid); } } } s->connected=0; session_schedule_reconnect(s); session_remove(s); }