libsrrophe 是xmpp协议在C下封装好的库,通过strophe库可以在C下完成XMPP通讯。
libstrophe同意好友申请是presence类型。
首先确定收到了好友的申请信息,增加presence类型响应函数
1 |
xmpp_handler_add(conn, get_presence, NULL, "presence", NULL, ctx); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
//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函数发送以下信息:
1 2 3 4 5 6 7 |
pres = xmpp_presence_new(ctx); xmpp_stanza_set_type(pres, "subscribed"); //同意好友申请类型 xmpp_stanza_set_to(pres, node_strophe.to); //指定向向你申请好友的账号 xmpp_send(conn, pres); |
我能请教关于C调用libstrophe 连接到openfire服务器吗
可以的