欢迎光临
我们一直在努力

libstrophe同意好友申请presence |subscribed

libsrrophe 是xmpp协议在C下封装好的库,通过strophe库可以在C下完成XMPP通讯。
libstrophe同意好友申请是presence类型。

首先确定收到了好友的申请信息,增加presence类型响应函数

xmpp_handler_add(conn, get_presence, NULL, "presence", NULL, ctx);

//presence响应函数

int get_presence(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata)

{

xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata;

char *intext ;

if( xmpp_stanza_get_type(stanza) != NULL && !strcmp(xmpp_stanza_get_type(stanza), "error"))

{

intext = xmpp_stanza_get_text(xmpp_stanza_get_child_by_name(stanza, "body"));

xmessage("recv xmpp server error [%s]", intext);

xmpp_free( ctx, intext );

}

else

{

char getname[256];

sscanf(xmpp_stanza_get_from(stanza), "%s",getname);

char *pchar;

pchar =  strstr(getname, "jgsweep");

*(pchar + strlen("jgsweep")) = '\0';

printf("\n!!!!!!!:get name is %s\n",getname);

sprintf(node_strophe.to, "%s",getname);

node_strophe.strophe_server_connet = 1;

 

if(node_strophe.strophe_server_state == 1)

{

xmpp_stanza_t* pres;

pres = xmpp_presence_new(ctx);

xmpp_stanza_set_type(pres, "subscribed");

xmpp_stanza_set_to(pres, node_strophe.to);

xmpp_send(conn, pres);

}

}
}

以上,主要是利用xmpp_send函数发送以下信息:

pres = xmpp_presence_new(ctx);

xmpp_stanza_set_type(pres, "subscribed");  //同意好友申请类型

xmpp_stanza_set_to(pres, node_strophe.to);     //指定向向你申请好友的账号

xmpp_send(conn, pres);

赞(3) 打赏
未经允许不得转载:huangea的博客 » libstrophe同意好友申请presence |subscribed

评论 2

  1. #1

    我能请教关于C调用libstrophe 连接到openfire服务器吗

    boy6年前 (2018-06-06)回复

有趣的网站

支持快讯、专题、百度收录推送、人机验证、多级分类筛选器,适用于垂直站点、科技博客、个人站,扁平化设计、简洁白色、超多功能配置、会员中心、直达链接、文章图片弹窗、自动缩略图等...

联系我们联系我们

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续给力更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫打赏

微信扫一扫打赏

登录

找回密码

注册