⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 roster.c

📁 Simple Jabber Client for Symbian Platform
💻 C
字号:
/*
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 *  Jabber
 *  Copyright (C) 2004 Xie Tian Lu  http://sabber.jabberstudio.org/
 */

#include "roster.h"

void jabr_request( jconn j )
{
    xmlnode x;

    x = jutil_iqnew(JPACKET__GET, NS_ROSTER);
    jab_send(j,x);
    xmlnode_free(x);
}

char* jabr_probe( jconn j, char* user )
{
	char* id;
	xmlnode x;

	id = jab_getid(j);

	// example "<presence to="zhixm@ims.uptech.com" type="probe""
	x = jutil_presnew(JPACKET__PROBE, user, 0, NULL );

	jab_send(j, x);
    xmlnode_free(x);

	return id;
}

void jabr_add_item( jconn j, char *group, char *user, char *name )
{
    xmlnode xml,tmp;
        
	xml = jutil_iqnew(JPACKET__SET, NS_ROSTER);
    tmp = xmlnode_get_tag(xml,"query");

    tmp = xmlnode_insert_tag(tmp,"item");
    xmlnode_put_attrib(tmp,"jid",user);
    if(name) xmlnode_put_attrib(tmp,"name",name);

    if(group) {
        tmp = xmlnode_insert_tag(tmp,"group");
        xmlnode_insert_cdata(tmp,group,-1);
    }

    jab_send(j,xml);
    xmlnode_free(xml);
}


void jabr_rmv_item( jconn j, char *user )
{
    xmlnode xml,itm,tmp;

	xml = jutil_iqnew(JPACKET__SET, NS_ROSTER);
    tmp = xmlnode_get_tag(xml,"query");

    itm = xmlnode_insert_tag(tmp,"item");
    xmlnode_put_attrib(itm,"jid",user);
    xmlnode_put_attrib(itm,"subscription","remove");

    jab_send(j,xml);
    xmlnode_free(xml);
}

void jabr_set_item( jconn j, char* jid, char* name, char* group )
{
	xmlnode x, c, g;
	char*	id;

	id = jab_getid(j);

	x = jutil_iqnew( JPACKET__SET, NS_ROSTER );
	
	c = xmlnode_get_tag( x, "query" );

	g = xmlnode_insert_tag( c, "item" );
	xmlnode_put_attrib( g, "jid", jid );
	xmlnode_put_attrib( g, "name", name );

	g = xmlnode_insert_tag( g, "group" );
	xmlnode_insert_cdata( g, group, strlen( group ) );

	jab_send( j, x );
	xmlnode_free( x );
}

void jabr_show( jconn j, int show, char* status )
{
	xmlnode x;

	if ( show )
		x = jutil_presnew( JPACKET__AVAILABLE, NULL, 0, status );
	else 
		x = jutil_presnew( JPACKET__INVISIBLE, NULL, 0, NULL );

	jab_send(j, x);
    xmlnode_free(x);
}

void jabr_change_status( jconn j, char* show, char* status )
{
	xmlnode x;

	x = jutil_presnew( JPACKET__AVAILABLE, NULL, show, status );

	jab_send(j, x);
    xmlnode_free(x);
}


char* jabr_subscribe_friend( jconn j, char* user, int subscribe )
{
	char* id;
	xmlnode x;

	id = jab_getid(j);

	if( subscribe )
		x = jutil_presnew(JPACKET__SUBSCRIBE, user, 0, "I would like to add you to my roster.");
	else
		x = jutil_presnew(JPACKET__UNSUBSCRIBE, user, 0, "I would like to drop you form my roster.");

	jab_send(j, x);
    xmlnode_free(x);

	return id;
}

char* jabr_response_subscribe( jconn j, char* user, int subscribed )
{
	char* id;
	xmlnode x;

	id = jab_getid(j);

	if( subscribed )
		x = jutil_presnew(JPACKET__SUBSCRIBED, user, 0, "" );
	else
		x = jutil_presnew(JPACKET__UNSUBSCRIBED, user, 0, "" );

	jab_send(j, x);
    xmlnode_free(x);

	return id;
}

void jabr_request_msn( jconn j )
{
	xmlnode x;
	char*	id;

	id = jab_getid( j );

	x = jutil_iqnew( JPACKET__GET, NS_REGISTER );	
	xmlnode_put_attrib( x, "to", "msn.upvim.com" );

	jab_send( j, x );
	xmlnode_free( x );
}

void jabr_regist_msn( jconn j, char* user, char* nick, char* pass, char* key ) 
{
	xmlnode x, c, g;
	char*	id, *result;

	id = jab_getid( j );

	x = jutil_iqnew( JPACKET__SET, NS_REGISTER );	
	xmlnode_put_attrib( x, "to", "msn.upvim.com" );

	c = xmlnode_get_tag( x, "query" );

	g = xmlnode_insert_tag( c, "username" );
	xmlnode_insert_cdata( g, user, strlen( user ) );

	g = xmlnode_insert_tag( c, "password" );
	xmlnode_insert_cdata( g, pass, strlen( pass ) );

	g = xmlnode_insert_tag( c, "nick" );
	xmlnode_insert_cdata( g, nick, strlen( nick ) );

	g = xmlnode_insert_tag( c, "key" );
	xmlnode_insert_cdata( g, key, strlen( key ) );

	result = xmlnode2str( x );

	jab_send( j, x );
	xmlnode_free( x );

}

void jabr_remove_msn( jconn j )
{
	xmlnode x, c;
	char*	id;
	char* xml;

	id = jab_getid( j );

	x = jutil_iqnew( JPACKET__SET, NS_REGISTER );
	xmlnode_put_attrib( x, "to", "msn.upvim.com" );
	
	c = xmlnode_get_tag( x, "query" );

	xmlnode_insert_tag( c, "remove" );

	xml = xmlnode2str( x );

	jab_send( j, x );
	xmlnode_free( x );
}

void jabr_logon_msn( jconn j ) 
{
	xmlnode x, c;

	x = jutil_presnew( JPACKET__AVAILABLE, "msn.upvim.com", 0, 0 );

	jab_send( j, x );
	xmlnode_free( x );
}

void jabr_logoff_msn( jconn j ) 
{
	xmlnode x;

	x = jutil_presnew( JPACKET__UNAVAILABLE, "msn.upvim.com", 0, 0 );

	jab_send( j, x );
	xmlnode_free( x );
}

void jabr_subscrib_msn( jconn j )
{
	xmlnode x, c;

	x = jutil_presnew( JPACKET__SUBSCRIBED, "msn.upvim.com", 0, NULL );
	c = xmlnode_insert_tag( x, "priority" );
	xmlnode_insert_cdata( c, "0", 1 );

	jab_send( j, x );
	xmlnode_free( x );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -