#include "srfile.h"
//=========================================================================================
//函数名称:makeFileList(char *rfbuf)
//功能描述:生成发送文件链表
//函数参数:arg1[],发送文件名的指针数组
//返回值:
//=========================================================================================
int makeFileList(char *arg1[]) { //char *arg[10];
char filename[50]; char filesize[50]; char mtime[50]; char filetype[5]; int i=2; struct stat filetypebuf; initFileList(); while(arg1[i]) { memset(filename,0,sizeof(filename)); memset(filesize,0,sizeof(filesize)); memset(mtime,0,sizeof(mtime)); memset(filetype,0,sizeof(filetype)); printf("arg1[%i]=%s\n",i,arg1[i]); if(lstat(arg1[i],&filetypebuf)<0) { printf("file:'%s' is err!\n",arg1[i]); i++; continue; } if(S_ISREG(filetypebuf.st_mode)) { sprintf(filetype,"%d",1); } else if(S_ISDIR(filetypebuf.st_mode)) { sprintf(filetype,"%d",2); } else { //filetype=;
continue; } strcpy(filename,arg1[i]); sprintf(filesize,"%u",filetypebuf.st_size); sprintf(mtime,"%u",filetypebuf.st_mtime); printf("file[%d]=%s\n",i,filename); addFile(filename,filesize,mtime,filetype); i++; } return i; } //============================================================================================
//函数名称:sendFileLIst(int sockfd,FILENODE *filelist)
//功能描述:发送文件链表
//函数参数:发送的sockfd对象,filelist发送的文件链表
//返 回 值:
//============================================================================================
int sendFileList(int sockfd,USERINFO *destusr,FILENODE *filelist) { char sendbuf[600]; FILENODE *tmpNode; int i=0; tmpNode=filelist; MSG sfMsg; while(tmpNode) { memset(sendbuf,0,sizeof(sendbuf)); sprintf(sendbuf+1,"%d:%s:%x:%x:%x:\\a",tmpNode->fileno ,tmpNode->filename ,tmpNode->filesize ,tmpNode->mtime ,tmpNode->filetype); // len=len+strlen(tmpNode->fileno)+1;
// strcpy(sendbuf+len,tmpNode->filename);
// len=len+strlen(tmpNode->filename)+1;
// strcpy(sendbuf+len,tmpNode->filesize);
// len=len+strlen(tmpNode->mtime)+1;
// strcpy(sendbuf+len,tmpNode->mtime);
// len=len+strlen(tmpNode->filetype)+1;
// strcpy(sendbuf+len,tmpNode->filetype);
makeSendMsg(&sfMsg,sendbuf,destusr->ipaddr,IPMSG_SENDMSG|IPMSG_FILEATTACHOPT);//
sendToMsg(sockfd,&sfMsg); tmpNode=tmpNode->next; i++; printf("i=%d in sendfilelist\n",i); } return i; }
|