コード例 #1
0
ファイル: sessions.c プロジェクト: Doap/transports
int session_event_status(Session *s,int status,uin_t uin,char *desc,
				int more,uint32_t ip,uint16_t port,uint32_t version){
int oldstat;
int available;
char *ujid;
char *show;
Contact *c;

	c=user_get_contact(s->user,uin,FALSE);
	if (c==NULL) {
/*		debug(L_("%s got notification from unknown contact %i. Converting to subscription request."),s->user->jid,uin);
		ujid=jid_build(uin);
		presence_send_subscribe(s->s,ujid,s->user->jid);
		g_free(ujid);
*/		debug(L_("%s got notification from unknown contact %i."),s->user->jid,uin);
	       	return 0;
	}
	if (!c->got_probe && c->subscribe!=SUB_TO && c->subscribe!=SUB_BOTH) {
		debug(L_("%s got notification from contact %i, whose presence was not requested. Ignoring."),s->user->jid,uin);
	       	return 0;
	}

	available=status_gg_to_jabber(status,&show,&desc);
	oldstat=user_get_contact_status(s->user,uin);
	user_set_contact_status(s->user,status,uin,desc,more,ip,port,version);

	if (!available && oldstat==-1)
		ujid=jid_build(uin);
	else
		ujid=jid_build_full(uin);

	presence_send(s->s,ujid,s->user->jid,available,show,desc,0);
	g_free(ujid);
	return 0;
}
コード例 #2
0
ファイル: presence.c プロジェクト: AdamPrzybyla/jggtrans
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;
}