51Testing软件测试论坛

标题: im-message-part2 [打印本页]

作者: sun.sun    时间: 2012-6-28 12:11
标题: im-message-part2
para:
/*定义各类全局变量*/
char *xmpp_node1_addr = "192.168.0.75:5222";//XMPP第一个节点的地址
char *xmpp_node2_addr = "192.168.0.40:5222";//XMPP第二个节点的地址
char *xmpp_node3_addr = "192.168.0.138:5222";//XMPP第三个节点的地址
           
char *xmpp_testtoken  = "This'sjusttfortest";//测试用Token
char *xmpp_domain     = "rcs.com";//XMPP Server的域名
//util
#include "para.h"
char base64encode_lut[] = {
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q',
'R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h',
'i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y',
'z','0','1','2','3','4','5','6','7','8','9','+','/','='};
char base64decode_lut[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0,62, 0, 0, 0,63,52,53,54,55,56,57,58,59,60,61, 0, 0,
0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0,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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, };

void base64encode(char *src, char *dest, int len)
{
   int i=0, slen=strlen(src);
   for(i=0;i<slen && i<len;i+=3,src+=3)
   { // Enc next 4 characters
   *(dest++)=base64encode_lut[(*src&0xFC)>>0x2];
   *(dest++)=base64encode_lut[(*src&0x3)<<0x4|(*(src+1)&0xF0)>>0x4];
   *(dest++)=((i+1)<slen)?base64encode_lut[(*(src+1)&0xF)<<0x2|(*(src+2)&0xC0)>>0x6]:'=';
   *(dest++)=((i+2)<slen)?base64encode_lut[*(src+2)&0x3F]:'=';
   }
   *dest='\0'; // Append terminator
}
/*BASE64加密函数,将传入的参数进行BASE64加密,作为函数的返回值*/
char* b64_encode_string( char *source)
{
   int dest_size;
   int res;
   char *dest;
   // Allocate dest recbfer
   dest_size = 1 + ((strlen(source)+2)/3*4);
   dest = (char *)malloc(dest_size);
   memset(dest,0,dest_size);
   // Encode & Save
   base64encode(source, dest, dest_size);
   return dest;
}
/*随机获取XMPP Server的地址*/
char* getXMPPAddr()
{
int temp = rand();
if(temp%3 == 0)
{
  return xmpp_node2_addr;
}
else if(temp%3 == 1)
{
  return xmpp_node2_addr;
}
else
{
  return xmpp_node2_addr;
}
}




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2