예제 #1
0
void message_status(struct stream_s *stream,const char *from, const char *to,
				const char *args, xmlnode msg){
Session *session;
User *user;
char *m;

	session=session_get_by_jid(from,stream,0);
	if (session!=NULL)
		user=session->user;
	else
		user=user_get_by_jid(from);

	g_free(user->status);
	if (args) {
		if (!g_strcasecmp(args,"off")) user->status=NULL;
		else user->status=g_strndup(string_to_gg(args),GG_STATUS_DESCR_MAXSIZE);
	}
	else user->status=NULL;

	m=g_strdup_printf(_("status: %s%s%s"),
			(user->status?"`":""),
			(user->status?string_from_gg(user->status):_("not set")),
			(user->status?"'":""));
	message_send(stream,to,from,1,m,0);
	g_free(m);

	if (session!=NULL) session_send_status(session);
	user_save(user);
}
예제 #2
0
파일: sessions.c 프로젝트: Doap/transports
static int session_try_login(Session *s){
struct gg_login_params login_params;
GgServer *serv;

	g_message(N_("Trying to log in on server %u for %s"),
			g_list_position(gg_servers, s->current_server), s->jid);

	if (s->ping_timeout_func) g_source_remove(s->ping_timeout_func);
	s->ping_timeout_func=NULL;
	if (s->timeout_func) g_source_remove(s->timeout_func);
	s->timeout_func=NULL;
	if (s->ping_timer) g_timer_destroy(s->ping_timer);
	s->ping_timer=NULL;
	if (s->ggs) {
		gg_free_session(s->ggs);
		s->ggs=NULL;
	}
	session_remove_g_source(s);

	memset(&login_params,0,sizeof(login_params));
	login_params.uin=s->user->uin;
	login_params.password=string_to_gg(s->user->password);
	login_params.async=1;
	login_params.last_sysmsg=s->user->last_sys_msg;
	login_params.protocol_version=GG_DEFAULT_PROTOCOL_VERSION;
	login_params.protocol_features=GG_FEATURE_ALL;
	login_params.client_version=GG_DEFAULT_CLIENT_VERSION;
	login_params.encoding = GG_ENCODING_UTF8;
	login_params.status=GG_STATUS_INVISIBLE;
	if(s->user->status)
		login_params.status_descr=s->user->status;

	serv=(GgServer*)s->current_server->data;
	if(serv->port!=1){
		login_params.server_addr=serv->addr.s_addr;
		login_params.server_port=serv->port;
	}
#ifdef __GG_LIBGADU_HAVE_OPENSSL
	debug(N_("Turning TLS %s"), serv->tls?"on":"off");
	login_params.tls=serv->tls;
#endif

	s->ggs=gg_login(&login_params);
	if (!s->ggs){
		g_free(s);
		return 1;
	}
	session_setup_g_source(s);

	s->timeout_func=g_timeout_add(conn_timeout*1000,session_timeout,s);
	return FALSE;
}
예제 #3
0
파일: presence.c 프로젝트: Jajcus/jggtrans
int presence(struct stream_s *stream,const char *from,const char *to,
		int available,const char *show,const char *status,int priority){
Session *s;
const char *resource;
User *u;

	s=session_get_by_jid(from,available?stream:NULL,1);
	if (!s){
		debug(L_("presence: No such session: %s"),from);
		presence_send_error(stream,NULL,from,407,_("Not logged in"));
		u=user_get_by_jid(from);
		if (u==NULL) presence_send_unsubscribed(stream,to,from);
		return -1;
	}
	resource=jid_get_resource(from);
	session_set_status(s,resource,available,show,string_to_gg(status),priority);
	return 0;
}
예제 #4
0
int jabber_message(struct stream_s *stream,xmlnode tag){
char *type;
char *from;
char *to;
char *subject;
char *body;
int chat;
xmlnode subject_n;
xmlnode body_n;
Session *s;
User *u;

	body_n=xmlnode_get_tag(tag,"body");
	if (body_n!=NULL) body=xmlnode_get_data(body_n);
	else body=NULL;

	subject_n=xmlnode_get_tag(tag,"subject");
	if (subject_n!=NULL) subject=xmlnode_get_data(subject_n);
	else subject=NULL;

	from=xmlnode_get_attrib(tag,"from");
	to=xmlnode_get_attrib(tag,"to");
	type=xmlnode_get_attrib(tag,"type");

	if (!acl_is_allowed(from,tag)){
		if (type && !strcmp(type,"error")){
			debug("Ignoring forbidden message error");
			return -1;
		}
		if (!from) return -1;
		message_send_error(stream,to,from,NULL,405,_("Not allowed"));
		return -1;
	}

	if (from) u=user_get_by_jid(from);
	else u=NULL;
	user_load_locale(u);

	if (!type || !strcmp(type,"normal")) chat=0;
	else if (!strcmp(type,"chat")) chat=1;
	else if (!strcmp(type,"error")){
		g_warning(N_("Error message received: %s"),xmlnode2str(tag));
		return 0;
	}
	else{
		g_warning(N_("Unsupported message type"));
		message_send_error(stream,to,from,body,500,_("Internal Server Error"));
		return -1;
	}

	if (!to || !jid_is_my(to)){
		g_warning(N_("Bad 'to' in: %s"),xmlnode2str(tag));
		message_send_error(stream,to,from,body,400,_("Bad Request"));
		return -1;
	}

	if (!jid_has_uin(to)){
		return message_to_me(stream,from,to,body,tag);
	}

	if (!from){
		g_warning(N_("Anonymous message? %s"),xmlnode2str(tag));
		message_send_error(stream,to,from,body,400,_("Bad Request"));
		return -1;
	}

	s=session_get_by_jid(from,NULL,0);
	if (!s || !s->connected){
		g_warning(N_("%s not logged in. While processing %s"),from,xmlnode2str(tag));
		message_send_error(stream,to,from,body,407,_("Not logged in"));
		return -1;
	}

	if (subject)
		body=g_strdup_printf("Subject: %s\n%s",subject,body);
	session_send_message(s,jid_get_uin(to),chat,string_to_gg(body));
	if (subject)
		g_free(body);

	return 0;
}