TA的每日心情 | 开心 2015-5-3 23:41 |
---|
签到天数: 2 天 连续签到: 1 天 [LV.1]测试小兵
|
action:
Action()
{
//根据参数定义,获取一个xmpp_userid
char *s_jid = lr_eval_string("{xmpp_jid}");
char *r_jid = lr_eval_string("[url=mailto:test%7Bxmpp_3rd_jid%7D@gmail.com]test{xmpp_3rd_jid}@gmail.com[/url]");
lr_output_message("send jid:%s",s_jid);
lr_output_message("recv jid:%s",r_jid);
char tempSocket[20]={'\0'};
//执行登陆操作
if(TransfromIM(s_jid,r_jid) == 0)
{
return 0;
}
else
{
return -1;
}
}
login:
#include "util.h"
#define LOGIN_SUCCESS 0
#define LOGIN_FAIL -1
int Login(char *pszJID, char *pszSocketName)
{
char tmpString[2000];
char errorMsg[200];
//设置变量
lr_save_string(pszJID,"xmpp_userid_v");
lr_save_string(getXMPPAddr(),"xmpp_addr_v");
lr_save_string(xmpp_testtoken,"xmpp_testtoken_v");
lr_save_string(xmpp_domain,"xmpp_domain_v");
sprintf(tmpString,lr_eval_string("pc:{xmpp_userid_v}@{xmpp_domain_v}:{xmpp_testtoken_v}"));
lr_save_string(b64_encode_string(tmpString),"base64str");
//启动事务
lr_start_transaction("LOGIN_TRANS");
//创建与XMPP Server之间的TCP长连接
lrs_create_socket(pszSocketName,"TCP", "RemoteHost={xmpp_addr_v}", LrsLastArg);
//发送初始化码流建立XMPP连接,并接收XMPP Server返回的结果
lrs_send(pszSocketName,"initStream",LrsLastArg);
lrs_set_recv_timeout(5,0);
lrs_receive(pszSocketName,"initStreamResp",LrsLastArg);
//发送用户鉴权信息,并接收XMPP Server返回的鉴权结果
lrs_send(pszSocketName,"authStream",LrsLastArg);
lrs_set_recv_timeout(5,0);
lrs_receive(pszSocketName,"authStreamResp",LrsLastArg);
//检测XMPP Server鉴权结果,如果包含success关键词,登陆事务成功;否则失败,打印错误信息
lrs_save_param(pszSocketName, NULL, "auth_res", 1, 7);
if(strcmp(lr_eval_string("{auth_res}"),"success")==0)
{
lr_end_transaction("LOGIN_TRANS",LR_PASS);
return LOGIN_SUCCESS;
}
else
{
errorMsg[0]='\0';
lrs_save_param(pszSocketName, NULL, "auth_fail", 0, 6);
strcat(errorMsg,pszJID);
strcat(errorMsg,lr_eval_string("{auth_fail}"));
lr_error_message(errorMsg);
lr_end_transaction("LOGIN_TRANS", LR_FAIL);
return LOGIN_FAIL;
}
}
void logout(char *pszSocketName)
{
//发送结束码流,退出登陆
lrs_send(pszSocketName,"endStream",LrsLastArg);
lrs_receive(pszSocketName,"endStreamResp",LrsLastArg);
} |
|