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);

huangea的博客


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