void message_invisible(struct stream_s *stream,const char *from, const char *to, const char *args, xmlnode msg){ Session *session; User *user; Resource *r; gboolean on; session=session_get_by_jid(from,stream,0); if (session!=NULL) user=session->user; else user=user_get_by_jid(from); if (args && g_strcasecmp(args,"on")==0) on=TRUE; else if (args && g_strcasecmp(args,"off")==0) on=FALSE; else on=!user->invisible; if (user->invisible==on){ message_send(stream,to,from,1,_("No change."),0); return; } user->invisible=on; if (on) message_send(stream,to,from,1,_("invisible: on"),0); else message_send(stream,to,from,1,_("invisible: off"),0); if (session!=NULL) session_send_status(session); r=session_get_cur_resource(session); if ( r ) presence_send(stream,NULL,user->jid,user->invisible?-1:r->available,r->show,session->gg_status_descr,0); user_save(user); }
void session_print(Session *s,int indent){ char *space,*space1; GList *it; Resource *r,*cr; char *njid; space=g_strnfill(indent*2,' '); space1=g_strnfill((indent+1)*2,' '); njid=jid_normalized(s->jid,0); g_message(L_("%sSession: %p"),space,s); g_message("%sJID: %s",space,s->jid); g_message(L_("%sUser:"******"%sResources:"),space); cr=session_get_cur_resource(s); for(it=g_list_first(s->resources);it;it=g_list_next(it)){ r=(Resource *)it->data; g_message(L_("%sResource: %p%s"),space1,r,(r==cr)?N_(" (current)"):""); if (njid && r->name) g_message("%sJID: %s/%s",space1,njid,r->name); else g_message("%sJID: %s",space1,s->jid); g_message(L_("%sPriority: %i"),space1,r->priority); g_message(L_("%sAvailable: %i"),space1,r->available); if (r->show) g_message(L_("%sShow: %s"),space1,r->show); if (r->status) g_message(L_("%sStatus: %s"),space1,r->status); } g_message(L_("%sGG session: %p"),space,s->ggs); g_message(L_("%sGSource: %p"),space,s->g_source); g_message(L_("%sStream: %p"),space,s->s); g_message(L_("%sConnected: %i"),space,s->connected); g_message(L_("%sRequest id: %s"),space,s->req_id?s->req_id:"(null)"); g_message(L_("%sRequest query: %s"),space,s->query?xmlnode2str(s->query):"(null)"); g_message(L_("%sWaiting for ping: %i"),space,(int)s->waiting_for_pong); g_free(njid); g_free(space1); g_free(space); }
int presence_probe(struct stream_s *stream,const char *from,const char *to){ Session *s; User *u; Contact *c; uin_t uin; int status; int available; char *show,*stat,*jid; GList *it; GTime timestamp; s=session_get_by_jid(from,NULL,0); if (jid_is_me(to)){ if (s){ if (!s->connected){ presence_send(stream,to,from,0,NULL,"Disconnected",0); } else{ Resource *r=session_get_cur_resource(s); if (r) presence_send(stream,NULL,s->user->jid,s->user->invisible?-1:r->available, r->show,r->status,0); } return 0; } else if (user_get_by_jid(from)) { presence_send(stream, to, from, 0, NULL, "Not logged in", 0); } else { presence_send_unsubscribed(stream, NULL, from); } return 0; } if (!jid_is_my(to)){ presence_send_unsubscribed(stream,to,from); return -1; } if (s) u=s->user; else u=user_get_by_jid(from); if (!u){ presence_send_unsubscribed(stream,to,from); return -1; } uin=jid_get_uin(to); /* create the contact: if we got 'prope' the user has it on his * contact list, do not change that */ c = user_get_contact(u, uin, TRUE); if (!c) { return -1; } c->got_probe=TRUE; if (s) session_update_contact(s,c); status=0; stat=NULL; timestamp=0; for(it=u->contacts;it;it=it->next){ Contact *c=(Contact *)it->data; if (c && c->uin==uin){ status=c->status; timestamp=c->last_update; stat=c->status_desc; } } if (!status){ // user not found on userlist? presence_send_unsubscribed(stream,to,from); return -1; } if (status==-1) return 0; /* Not known yet */ available=status_gg_to_jabber(status,&show,&stat); if (available) jid=jid_build_full(uin); else jid=jid_build(uin); presence_send(stream,jid,u->jid,available,show,stat,timestamp); g_free(jid); return 0; }
/* returns: -1 on error, 1 on status change, 0 on no change */ int session_make_status(Session *s, gboolean send_presence){ Resource *r; r=session_get_cur_resource(s); return session_do_make_status(s,r,send_presence); }