📄 common.h
字号:
/*
* Copyright (c) 2002, 南京联创系统集成股份有限公司综合结算产品部
* All rights reserved.
*
* 文件名称:common.h
* 摘 要:定义传输程序中的一些数据结构和宏及函数申明
*
* 当前版本:
* 作 者:冯亮(fengl@lianchuang.com)
* 完成日期:
*/
#ifndef _COMMON_H_
#define _COMMON_H_
#include "config.h"
#include "logalert.h"
#include "monapi.h"
#undef STRING_LEN
const int STRING_LEN = 1024;
const int SOCK_TIME_OUT = 600;
struct S_GobalMutex
{
/*写日志互斥*/
pthread_mutex_t LogMutex;
/*写告警互斥*/
pthread_mutex_t AlertMutex;
/*配置文件操作互斥*/
pthread_mutex_t ConfigFileMutex;
/*搜索文件互斥*/
pthread_mutex_t SearchFileMutex;
};
const int MAX_PATH = 255;
const int DATA_LENGTH = 10240;
const int FILE_NAME_LEN = 255;
const int INFO_LEN = 255;
/*数据的传输结构*/
struct S_DataInfo
{
/*传输类型: 0:PUTFILE -- 上传文件 1:GETFILE -- 下载文件*/
int iTransferType;
/*远端路径*/
char chRemotePath[MAX_PATH];
/*远端最终路径*/
char chRemoteTargetPath[MAX_PATH];
/*远端备份路径*/
char chRemoteBackupPath[MAX_PATH];
/*文件的过滤条件*/
char chFileFilter[MAX_PATH];
/*当前文件位置*/
long lFilePos;
/*1--压缩;0--不压缩*/
int iCompress;
/*返回状态:0--无文件,1--存在文件,2--文件发送完成 -1 ---失败*/
int iStatus;
/*错误信息*/
char chErrorMsg[INFO_LEN];
/*文件名*/
char chFileName[FILE_NAME_LEN];
/*原始文件长度*/
long lFileLen;
/*压缩后文件长度*/
long lZipSize;
/*数据块长度*/
long lDataLen;
/*控制信息校验值*/
long lCheckValue;
/*预留字段1*/
int iReserved1;
/*预留字段2*/
int iReserved2;
/*数据块*/
char chData[DATA_LENGTH];
};
extern C_Monitor gv_TranMonitor;
extern S_GobalMutex gv_GobalMutex;
/*下载文件*/
#define CMD_GET 1
/*上传文件*/
#define CMD_PUT 0
/*状态 错误*/
#define STATUS_ERROR 0
/*无文件*/
#define STATUS_NOFILE 1
/*存在文件*/
#define STATUS_FILEEXIST 2
/*现在正在发送文件*/
#define STATUS_SENDFILE 3
/*这是最后的文件块*/
#define STATUS_LASTDATA 4
/*文件发送完成*/
#define STATUS_FINISH 5
/*结束本次会话*/
#define STATUS_BYBY 6
/*请求发送信息*/
#define STATUS_FILEINFO 7
#define COMPRESS 1
#define NOT_COMPRESS 0
#define MODE_READ 0
#define MODE_WRITE 1
//严重错误,导致系统停止,且需人工立即干预
#define ALERT_LEVEL_1 "1"
//导致系统停止,需人工做维护工作后,重新启动
#define ALERT_LEVEL_3 "3"
//导致系统停止,不需人工做维护工作,直接重新启动即可解决
#define ALERT_LEVEL_5 "5"
//一般错误,但是有错误数据产生
#define ALERT_LEVEL_7 "7"
//一般错误,但是没有错误数据产生,只是产生错误告警
#define ALERT_LEVEL_9 "9"
#define CREATETHREAD_ERROR "100"
#define SOCKETINIT_ERROR "101"
#define CONNECT_ERROR "102"
#define WRITESOCKDATA_ERROR "103"
#define GETSOCKDATA_ERROR "104"
#define FILETOTEMP_ERROR "105"
#define PUTFILE_ERROR "106"
#define SENDFILE_ERROR "107"
#define GETFILESIZE_ERROR "108"
#define TIMEWAIT_ERROR "109"
#define READ_ERROR "110"
#define WRITE_ERROR "111"
#define CHECKDATA_ERROR "112"
#define POPEN_ERROR "113"
#define FOPEN_ERROR "114"
#define FSEEK_ERROR "115"
#define ZIPFILE_ERROR "116"
#define UNZIPFILE_ERROR "117"
#define DELETEFILE_ERROR "118"
#define FWRITE_ERROR "119"
#define RENAME_ERROR "120"
#define FILENOTEXIST_ERROR "121"
#define SAVEFILE_ERROR "122"
#define READBACKUPFILE_ERROR "123"
#define LOADCONFIG_ERROR "124"
#define GETENV_ERROR "125"
#define GETPARAM_ERROR "126"
#define SEARCHONEFILE_ERROR "127"
#define FILETOTARGETPATH_ERROR "128"
#define UNKNOWNSTATUS_ERROR "129"
#define REMOVE_ERROR "130"
#define TEMPTOFILE_ERROR "131"
#define BACKUP_ERROR "132"
/*函数原型*/
void GetFullName(struct S_DataInfo *data, char *chFullName);
void print_data(struct S_DataInfo *data);
long GetFileSize(char *chFileName);
int GetSockData(int iSockfd, struct S_DataInfo *data);
int WriteSockData(int iSockfd, struct S_DataInfo *data);
int TimeWait(int fd, int Mode);
int SendFile(int iSockfd, struct S_DataInfo *data, char *chFullName);
int ZipFile(char *chFileName);
int UnZipFile(char *chFileName);
int IsZipFile(char *chFileName);
int SaveFile(struct S_DataInfo *data, char *chLocalDir);
int CheckData(struct S_DataInfo *data);
int SetCheckValue(struct S_DataInfo *data);
int FileToTemp(char *chSrcPath, char *chSrcFile, char * chDescPath, char *chDestFile);
int TempToFile(char *chSrcPath, char *chSrcFile, char * chDescPath, char *chDestFile);
int FullPath(char *chPath);
int GetCurrentDate(char *pchDate);
int GetCurrentTime(char *pchTime);
void WriteAlert(const char *pchAlertCode, const char *pchAlertObject, const char *pchAlertLevel);
#endif/*_COMMON_H_*/
/*---------------------------------The End-------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -