资源简介
在utf8和gbk的环境中,支持中文聊天及中文文件名
代码片段和文件信息
/**********************************************************
*Filename: coms.c
*Author: 星云鹏
*Date: 2008-05-15
*
*主要的数据结构、全局变量和包的解析与生成
*********************************************************/
#include “ipmsg.h“
#include “coms.h“
#include
#include
#include
#include
#include
#include
const char allHosts[] = “255.255.255.255“; //广播用地址
int msgSock; //消息
int tcpSock; //文件
struct passwd* pwd;
struct utsname sysName;
char workDir[FILENAME];
int utf8;
gsNode sendFHead getFHead; //发送和接收文件列表
msgList mList; //接受到的消息列表
pthread_mutex_t sendFMutex=PTHREAD_MUTEX_INITIALIZER; //发送文件
pthread_mutex_t getFMutex=PTHREAD_MUTEX_INITIALIZER; //接收文件
pthread_mutex_t msgMutex=PTHREAD_MUTEX_INITIALIZER; //消息队列
pthread_mutex_t usrMutex=PTHREAD_MUTEX_INITIALIZER; //消息队列
sem_t waitNonEmpty waitNonFull; //消息列表信号量
/*解析接受到的字符串*/
int msgParser(char *msg int size command* com)// struct sockaddr_in *peer)
{
char *start;
char *pos;
char outStr[COMLEN];
int min;
int index=0colonCount tmp;
if ((msg==NULL)||(com==NULL))
return -1;
if (utf8)
{
g2u(msg size outStr sizeof(outStr));
start = outStr;
}
else start = msg;
bzero(com sizeof(command));
while (index<5)
{
pos = strchr(start ‘:‘);
if (pos==NULL)
break;
colonCount=1;
while(*(pos+1) == ‘:‘)
{
pos++;
colonCount++;
}
if (colonCount % 2 == 0) //偶数个:表示不是分割符
{
start = pos+1;
continue;
}
switch (index)
{
case 0:
com->version = atoi(start);
break;
case 1:
com->packetNo = atoi(start);
break;
case 2:
min = sizeof(com->senderName)<(pos-start)?sizeof(com->senderName):(pos-start);
memcpy(com->senderName start min);
com->senderName[min]=‘\0‘;
break;
case 3:
min = sizeof(com->senderHost)<(pos-start)?sizeof(com->senderHost):(pos-start);
memcpy(com->senderHost start min);
com->senderHost[min]=‘\0‘;
break;
case 4:
com->commandNo = atoi(start);
break;
default:
break;
}
start = pos+1;
index++;
}
strncpy(com->additional start MSGLEN);
if (com->commandNo & IPMSG_FILEATTACHOPT)
{
tmp = strlen(com->additional);
com->fileList = getFilelist(start+tmp+1);
}
index++;
return index;
}
/*生成要发送的message*/
int msgCreater(char* msg command* com size_t msgLen)
{
int len curLen tmp fileNo;
char fileName[FILENAME] dest[COMLEN];
filenode *curFile;
if ((dest==NULL)||(com==NULL))
return -1;
len = snprintf(dest sizeof(dest) “%d:%d:%s:%s:%d:%s“
com->version
com->packetNo
com->senderName
com->senderHost
com->commandNo
com->additional);
tmp = sizeof(dest) - len - 1;
if (com->commandNo & IPMSG_FILEATTACHOPT)
{
fileNo = 0;
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 7451 2008-05-17 09:39 ipmsg\coms.c
文件 2827 2008-05-18 18:48 ipmsg\coms.h
文件 812 2008-05-17 15:04 ipmsg\encode.c
文件 289 2008-05-14 21:34 ipmsg\encode.h
文件 3623 2008-05-14 21:19 ipmsg\ipmsg.h
文件 10231 2008-05-18 18:47 ipmsg\main.c
文件 571 2008-05-18 15:20 ipmsg\Makefile
文件 23865 2008-05-19 09:32 ipmsg\send_receive.c
文件 1114 2008-05-15 16:26 ipmsg\send_receive.h
文件 3156 2008-05-15 16:25 ipmsg\users.c
文件 733 2008-05-15 16:25 ipmsg\users.h
文件 5117 2008-05-19 09:40 ipmsg\utils.c
文件 834 2008-05-18 18:35 ipmsg\utils.h
目录 0 2013-04-02 09:19 ipmsg
----------- --------- ---------- ----- ----
60623 14
- 上一篇:金蝶K3WISE维护工具
- 下一篇:PoorSakura4改钱存档相关
评论
共有 条评论