/*H***************************************************************************
**
**  Copyright  (c)  2002,  Video Surveillance, Inc.
**		  All Rights Reserved.
**
**  Subsystem:	
**  File:	 	auth_msg.h
**  Created By:   	cham.li
**  Created On:	 04/24/2007
**  
**  Purpose: 
**   authentication and user management message definition 
**  
**  History:
**  Programmer	  Date	  Rev Number Description
** 
**
***************************************************************************H*/
#ifndef _AUTH_MESSAGE_H_
#define _AUTH_MESSAGE_H_

#include <string>
#include "ss_global.h"
#include "table_structs.h"
#include "vs_conf.h"
#include "messages.h"
#include "err_code.h"

#define VMS_HB_TIMER_LENGTH 10

using namespace std;

enum VMS_CLIENT_TYPE
{
	VS_CLIENT = 1,
	VS_MNG_CLIENT = 2,
	VSS_SERVER,
};


//message type please refer to message.h


//message sub type in usr/group set operation
#define AUTH_ADD  101
#define AUTH_MOD  102
#define AUTH_DEL  103

#define AUTH_LOGIN 201
#define AUTH_AUTHEN 202
#define AUTH_GET_LOGIN_INFO 203	//仅仅用于获得登录信息


//user or group enable status
#define AUTH_ENABLE 1
#define AUTH_DISABLE 0

//get usr or group list flag
#define AUTH_PROF_LIST_MORE 0
#define AUTH_PROF_LIST_END  1
#define AUTH_PROF_LIST_EMPTY 2


//error code
#define AUTH_NO_ERROR			  ERR_OK 
 
//array length
#define AUTH_MAX_NAME_LEN 32
#define AUTH_CRYPTO_BYTE_LEN 8
//#define AUTH_MAX_GRP_LEN 8
#define AUTH_HASH_PSWD_LEN 20
#define AUTH_MAX_DOMAIN_LEN 64
#define AUTH_MAX_USER_ID_LEN 32
#define AUTH_CRYPTO_KEY_LEN 128
#define AUTH_MAX_PRIORITY 10
#define AUTH_MAX_ACC_DOMAIN_LEN 1024
#define AUTH_DOMAIN_ID_LEN  5
#define AUTH_MAX_TVWALL_DOMAIN_LEN 256
#define AUTH_MAX_GRP_ID_LEN 32

#define AUTH_WWW_DOMAINNAME_LEN 64
#define AUTH_MAX_MOBILEPHONE_LEN 32
#define AUTH_MAX_EMAILADDR_LEN 64
#define AUTH_MAX_RIGHTBIT_LEN 64
#define AUTH_MAX_IPCCFG_FILTER_LEN	64
#define AUTH_MAX_SDNAME_LEN 32
#define AUTH_MAX_FTPPWD_LEN 32

//rigth bit
#define AUTH_PTZ_CONTROL	1
#define AUTH_DEVICE_MNG	 2
#define AUTH_CONTENT_MNG	3
#define AUTH_SURVEIL		4
#define AUTH_USR_MNG		5
#define AUTH_VIEDO_REPLAY   6
#define AUTH_AUDIO_CONTROL  7
#define AUTH_BROADCAST_CONTROL 8
#define AUTH_TV_WALL_MNG	9
#define AUTH_ALARM_MNG	  10
#define AUTH_CONTENT_DELETE 11
#define AUTH_SET_LINUX_PASSWD 12

inline void ClearMask(U32 bit, S8 **pstrRight)
{
	if( bit >= AUTH_MAX_RIGHTBIT_LEN-1 )
		return;

	*(*pstrRight+bit) = '0';
}

inline void SetMask(U32 bit, S8 **pstrRight)
{
	if( bit >= AUTH_MAX_RIGHTBIT_LEN-1 )
		return;

	*(*pstrRight+bit) = '1';
}

inline U32 GetMask(U32 bit, S8 **pstrRight)
{
	if( bit >= AUTH_MAX_RIGHTBIT_LEN-1 )
		return 0;

	if( *(*pstrRight+bit) == '1' )
		return 1;
	else
		return 0;
}


#define VERIFY_MSG_HEAD(head)  \
((MSMSGMAGIC != head.magic || MSG_CLS_REQ != head.MsgClass) ? AUTH_MSG_HEAD_ERROR : AUTH_NO_ERROR)

#define VERIFY_MSG_VERSION(version) \
( ((VS_AUTH_VER == version) || (VS_AUTH_VER_2 == version) )? AUTH_NO_ERROR : AUTH_VERSION_ERROR )
   
#define GET_ENCRYPT_LENGTH(len)  (((len+AUTH_CRYPTO_BYTE_LEN-1)/AUTH_CRYPTO_BYTE_LEN)*AUTH_CRYPTO_BYTE_LEN) 

#define AUTH_DEF_HB_PORT 20002
#define AUTH_CLIENT_HB_LISN_PORT_BASE 10000

//usr profile
struct auth_usr_prof
{
	S8 strName[AUTH_MAX_NAME_LEN];
	S8 strUsrId[AUTH_MAX_USER_ID_LEN];
	S8 digestPW[AUTH_HASH_PSWD_LEN];
	S8 strGrpId[AUTH_MAX_GRP_ID_LEN];
	S8 strMobilePhone[AUTH_MAX_MOBILEPHONE_LEN];
	S8 strEmailAddr[AUTH_MAX_EMAILADDR_LEN];
	U8 enabled;
};

//group profile
struct auth_grp_prof
{
	S8 strGrpId[AUTH_MAX_GRP_ID_LEN];
	S8 strName[AUTH_MAX_NAME_LEN];
	S8 strBlgDomainId[AUTH_DOMAIN_ID_LEN+1];
	S8 strAccDomainId[AUTH_MAX_ACC_DOMAIN_LEN];
	S8 strTvWallDomainId[AUTH_MAX_TVWALL_DOMAIN_LEN];
	S8 grpRightBit[AUTH_MAX_RIGHTBIT_LEN];
	U16 grpPriority; 
	U8 enabled;
};



/*************user management message interface****************/

//request part
//get user list request
struct auth_list_usr_prof_req
{
	S8 strOperatorId[AUTH_MAX_USER_ID_LEN];
};

//get group list request
struct auth_list_grp_prof_req
{
	S8 strOperatorId[AUTH_MAX_USER_ID_LEN];	
};

//set user profile request
struct auth_set_usr_prof_req
{
	S8 strOperatorId[AUTH_MAX_USER_ID_LEN];
	auth_usr_prof usr;
};

//set group profile request
struct auth_set_grp_prof_req
{
	S8 strOperatorId[AUTH_MAX_USER_ID_LEN];
	auth_grp_prof grp;
};

//get user profile request
struct auth_get_usr_prof_req
{
	S8 strOperatorId[AUTH_MAX_USER_ID_LEN];
	S8 strUsrId[AUTH_MAX_USER_ID_LEN];
};

//get group profile request
struct auth_get_grp_prof_req
{
	S8 strOperatorId[AUTH_MAX_USER_ID_LEN];
	S8 strGrpId[AUTH_MAX_GRP_ID_LEN];
};

//set password request
struct auth_set_pswd_req
{
	S8 strOperatorId[AUTH_MAX_USER_ID_LEN];
	S8 strUsrId[AUTH_MAX_USER_ID_LEN];
	U16 dcDataLen;
};
//encrypt password attached

struct auth_list_domain_req
{
	S8 strOperatorId[AUTH_MAX_USER_ID_LEN];
};

//用于MFS列出与子域的关系，以及与子域之间的带宽限制
struct auth_list_domainrelation_req
{
	S8 strDomainId[AUTH_DOMAIN_ID_LEN+1];
};


//response part
//set usr profile response
struct auth_set_usr_prof_rsp
{

};

//set group profile response
struct auth_set_grp_prof_rsp
{

};

//get user profile response
struct auth_get_usr_prof_rsp
{
	U8 endFlag;		 //1: end 0:more
	auth_usr_prof usr;
};

//get group profile response
struct auth_get_grp_prof_rsp
{
	U8 endFlag;		 //1: end 0:more
	auth_grp_prof grp;
};

//set password response
struct auth_set_pswd_rsp
{

};

//list domain response
struct auth_list_domain_rsp
{
	U16 domainNum;
};
//domain list attached


//用于MFS列出与子域的关系，以及与子域之间的带宽限制
struct auth_list_domainrelation_rsp
{
	U16 domainNum;
};
//domain relation list attached

//通知客户端重启(修改用户的某些参数后)
struct auth_notify_reboot
{
};


/*************authentication message interface****************/

//request part
//log in authentication request
struct auth_as_req 
{
	S8 strUsrName[AUTH_MAX_NAME_LEN];
	U16 clientType;
	U16 dcDataLen;				  //request data is encrypted
};
// encrypt ip and port attached


//response part
//log in authentication response
struct auth_as_rsp
{
	U16 dcDataLen;				  //response data is encrypted
	U16 bDownloadDbsConfig;
	S8 szFilePath[VS_FILE_PATH_LEN];//指示客户端使用的FTP路径
	S8 szFtpUsrName[VS_FTP_USER_NAME_LEN];	//县文件所用的临时分配的用户名
	S8 szFtpUsrPwd[VS_FTP_USER_NAME_LEN];	
};
// encrypt package attached


//log out request
struct auth_logout_req
{
	S8 strUsrId[AUTH_MAX_USER_ID_LEN];
	U16 clientType;
};

//log out response
struct auth_logout_rsp
{
	
};


struct auth_applyfor_ftp_req
{
	S8 strOperatorId[AUTH_MAX_USER_ID_LEN];
};

struct auth_applyfor_ftp_rsp
{
	S8 szFilePath[VS_FILE_PATH_LEN];//指示客户端使用的FTP路径
	S8 szFtpUsrName[VS_FTP_USER_NAME_LEN];	//县文件所用的临时分配的用户名
	S8 szFtpUsrPwd[VS_FTP_USER_NAME_LEN];
};


//对前端设备的配置和控制begin
//上载文件到IPC，包括升级/配置等
#define VS_UPLOADFILE_IPC_TYPE_FIRMWARE	0 //升级firmware
#define VS_UPLOADFILE_IPC_TYPE_CONFIG	1 //配置文件
#define VS_UPLOADFILE_IPC_TYPE_FIRMWARE_ALL 2 //针对所以设备的固件升级
#define VS_UPLOADFILE_IPC_TYPE_CONFIG_ALL 3 //针对所以设备的配置升级

struct auth_ipc_uploadfile_req
{
	S8 strOperatorId[AUTH_MAX_USER_ID_LEN];
	S8 strDevId[VS_DEV_ID_LEN];
	S8 strFilePath[VS_MAX_FILEPATH_LEN];
	U32 nFileType;	//VS_UPLOADFILE_IPC_TYPE_FIRMWARE，VS_UPLOADFILE_IPC_TYPE_CONFIG
};

struct auth_ipc_uploadfile_rsp
{
};


//控制/配置IPC,通过XML文本来传递，放到结构的后面
//包括重启/格式化/插拔SD/默认配置/获取配置/设置配置等等，统一用一对消息
struct auth_ipc_control_req
{
	S8 strOperatorId[AUTH_MAX_USER_ID_LEN];
	S8 strDevId[VS_DEV_ID_LEN];
	U32	nXmlLength;//XML文本长度，放到结构体的后面，由接收方收到后取出
};

struct auth_ipc_control_rsp
{
	S8 strDevId[VS_DEV_ID_LEN];
	U32	nXmlLength;//XML文本长度，放到结构体的后面，由接收方收到后取出
};

typedef enum
{
	IPC_FILE_TYPE_LOG = 0,
	IPC_FILE_TYPE_CONFIG,
	IPC_FILE_TYPE_OTHER,
}VsIpcFileType;

//IPC文件查询
struct auth_ipc_file_query_req
{
	S8  szDevId[VS_DEV_ID_LEN];
	VsIpcFileType nFileType;
	U32 nPageNum;	//从0开始
	content_timeinfo_t time_info;
};

//IPC文件查询回应
struct auth_ipc_file_query_rsp
{
	S8  szDevId[VS_DEV_ID_LEN];
	VsIpcFileType nFileType;
	U16	nTotalNum;		//总记录数
	U16 nRecordNum;	//本次记录个数
	//具体记录内容放到结构体的后面，由接收方收到后取出
};
//content_fileinfo_t file_info[VS_CONTENT_PAGE_SIZE];

//取消升级
struct auth_ipc_cancel_uploadfile_req
{
	S8 strOperatorId[AUTH_MAX_USER_ID_LEN];
	S8 strDevId[VS_DEV_ID_LEN];
	S8 strFilePath[VS_MAX_FILEPATH_LEN];	
};

struct auth_ipc_cancel_uploadfile_rsp
{
	S8 strDevId[VS_DEV_ID_LEN];
	S8 strFilePath[VS_MAX_FILEPATH_LEN];	
};

//将前端升级时下载文件进度通知到客户端
struct auth_notify_uploadfile_down_progress
{
	S8 szDevId[VS_DEV_ID_LEN];
	S8 szFilePath[VS_FILE_PATH_LEN];	// 升级文件名
	U32 nProgress;	//上载进度，0-100
};

//通知客户端前端下载客户端上传文件的结果(客户端请求上传文件到IPC前端后，等待前端处理过程中)
struct auth_notify_uploadfile_result
{
	S8 szDevId[VS_DEV_ID_LEN];
	S8 szFilePath[VS_FILE_PATH_LEN];	// 升级文件名
};

//文件下载,一次只允许一个文件
struct auth_ipc_file_down_req
{
	S8 szDevId[VS_DEV_ID_LEN];
	S8 szFilePath[VS_FILE_PATH_LEN];	// 查询时返回的文件路径
};

struct auth_ipc_file_down_rsp
{
	S8 strDevId[VS_DEV_ID_LEN];
	S8 szFilePath[VS_FILE_PATH_LEN];	// 查询时返回的文件路径
} ;

//客户端主动取消前端文件下载
struct auth_ipc_cancel_file_down_req
{
	S8 szDevId[VS_DEV_ID_LEN];
	S8 szFilePath[VS_FILE_PATH_LEN];	// IPC前端录像文件名
};

//回应消息:客户端主动取消前端文件下载
struct auth_ipc_cancel_file_down_rsp
{
	S8 szDevId[VS_DEV_ID_LEN];
	S8 szFilePath[VS_FILE_PATH_LEN];	// IPC前端日志文件名
};

//将前端文件上载进度通知到客户端
struct auth_notify_ipcfile_upload_progress
{
	S8 szDevId[VS_DEV_ID_LEN];
	S8 szFilePath[VS_FILE_PATH_LEN];	// IPC前端日志文件名
	U32 nProgress;	//上载进度，0-100
};


//通知客户端前端日志文件上载失败(客户端请求下载前端日志文件后，等待下载过程中)
struct auth_notify_ipcfile_upload_failed
{
	S8 szDevId[VS_DEV_ID_LEN];
	S8 szFilePath[VS_FILE_PATH_LEN];	// IPC前端录像文件上载后的路径
};

//通知客户端下载日志文件
struct auth_notify_ipcfile_download
{
	S8 szDevId[VS_DEV_ID_LEN];
	S8 szFilePath[VS_FILE_PATH_LEN];	// IPC前端日志文件上载后的路径
	S8 szFtpUsrName[VS_USER_NAME_LEN];	//下载文件所用的临时分配的用户名
	S8 szFtpUsrPwd[AUTH_MAX_FTPPWD_LEN];
};

//对前端设备的配置和控制end


//通知客户端IPC状态改变
struct auth_notify_ipc_status
{
	S8 szDevId[VS_DEV_ID_LEN];
//#define STATUS_OFFLINE		0
//#define STATUS_HBLOST		1
//#define STATUS_ACTIVE		2
	U32	nState;	//状态0:  STATUS_OFFLINE	1: STATUS_HBLOST	2: STATUS_ACTIVE
};


#define VS_CFGCHANGE_TBL_SCOPE_ALL	0
#define VS_CFGCHANGE_TBL_SCOPE_ONE	1
typedef struct{
	U32 nTblScope;		//0: 所有 1: 指定表名
	S8 	tblName[VS_STRING_LENG_64];	//配置更改的表名
} cli_notify_cfgchange_struct;


typedef struct{
}cli_notify_cfgchange_rsp;

typedef struct{
	U32 nAliveDevNum;		//在线设备个数
}vs_alldev_status_notify;
//具体设备状态数据放到结构体后面，每个设备状态的数据结构为auth_notify_ipc_status

typedef struct{
	U32 nAliveCamNum;		//在线Camera个数
}vs_allcam_reginfo_notify;
//具体设备状态数据放到结构体后面，每个设备状态的数据结构为auth_camera_reginfo

typedef struct{
	S8 szDevId[VS_DEV_ID_LEN];
	U8 bDoubleStream;
	U8 bWithPTZ;
	U8 bWithAudioIn;
	U8 bWithAudioOut;
}auth_camera_reginfo;


#define VS_CTL_SYSTEM_SHUTDOWN_SERVER	1
#define VS_CTL_SYSTEM_REBOOT_SERVER	2
#define VS_CTL_SYSTEM_REBOOT_NE	3

//操作服务器系统
struct vms_ctlsystem_req
{
	U32 nControlSystemType;	//refer to upper define
};


//获取/修改服务器IP地址
#define VS_MAX_NETCARD_COUNT	10	//最大网卡数量

//单个网卡配置
struct vs_netcard_systemip_cfg
{
	S8 szNetcard[VS_STRING_LENG_16];	//网卡名称,如eth0
	S8 szIpAddr[VS_IPADDR_LEN];	 //IP地址
	S8 szMask[VS_IPADDR_LEN];		//子网掩码
	S8 szGatewayIp[VS_IPADDR_LEN];	//网关
};

typedef struct
{
	U32 nNetCardCount;	//网卡个数
	S8 szWWWAddr[AUTH_WWW_DOMAINNAME_LEN];	//外网访问地址
	vs_netcard_systemip_cfg netcard[VS_MAX_NETCARD_COUNT];
}vs_get_systemip_cfg;

typedef struct
{
	U32 nSetVMConfig;
	S8 szWWWAddr[AUTH_WWW_DOMAINNAME_LEN];	//外网访问地址
	vs_netcard_systemip_cfg netcardcfg;
}vs_set_systemip_cfg;

struct vms_get_systemip_cfg
{
	vs_get_systemip_cfg data;
};

struct vms_set_systemip_cfg
{
	vs_set_systemip_cfg data;
};




//获取/设置VMS通用配置，包括自动添加设备等配置
struct vms_general_option_cfg
{
	U32 nAutoAddDeviceFlag;
	U32 nAutoSetRecordFlag;
	U32 nAutoSetTcpTransPro;
	U32 nAutoForbitMainStream;
};


struct vms_setsystem_password
{
	S8 szPassword[VS_STRING_LENG_32];
};



/************* decoder message begin *************************/
//播放开始
typedef struct 
{
	S8  szDevId[VS_DEV_ID_LEN];
//	U32	nConfigLen;	//配置长度
//	S8	nConfig[VS_DEV_DECODER_CONFIG_LEN];
} cli_decoder_play_start_req;

typedef struct 
{
} cli_decoder_play_start_rsp;

//播放停止
typedef struct 
{
	S8  szDevId[VS_DEV_ID_LEN];
} cli_decoder_play_stop_req;

typedef struct 
{
} cli_decoder_play_stop_rsp;

//暂停轮询
typedef struct 
{
	S8  szDevId[VS_DEV_ID_LEN];
} cli_decoder_play_cur_scheme_req;

typedef struct 
{
} cli_decoder_play_cur_scheme_rsp;

//恢复轮询
typedef struct 
{
	S8  szDevId[VS_DEV_ID_LEN];
} cli_decoder_play_resume_req;

typedef struct 
{
} cli_decoder_play_resume_rsp;

//播放上一个方案
typedef struct 
{
	S8  szDevId[VS_DEV_ID_LEN];
} cli_decoder_play_pre_req;

typedef struct 
{
} cli_decoder_play_pre_rsp;

//播放下一个方案
typedef struct 
{
	S8  szDevId[VS_DEV_ID_LEN];
} cli_decoder_play_next_req;

typedef struct 
{
} cli_decoder_play_next_rsp;

typedef	enum
{
	DECODER_STATUS_OK,
	DECODER_STATUS_NO_DATA,
	DECODER_STATUS_DECODE_FAILD
}DecoderStatusEn;

//解码器状态报告
typedef struct 
{
	S8  			szDevId[VS_DEV_ID_LEN];
	DecoderStatusEn	nStatusCode;
	U32				nFpsDecode;
	U32				nFpsDisplay;
	U32				nSchemeLen;	//当前方案长度
//	S8				szScheme[VS_DEV_DECODER_SCHEME_LEN];
} cli_decoder_status_report_req;

typedef struct 
{
} cli_decoder_status_report_rsp;

/************* decoder message end *************************/

















/*************main message struct***********************/

typedef union 
{
	auth_list_usr_prof_req listUsrReq;
	auth_list_grp_prof_req listGrpReq;
	auth_set_usr_prof_req setUsrReq;
	auth_set_grp_prof_req setGrpReq;
	auth_get_usr_prof_req getUsrReq;
	auth_get_grp_prof_req getGrpReq;
	auth_set_pswd_req setPsWdReq;
	auth_as_req asReq;
	auth_list_domain_req listDomainReq;
	auth_list_domainrelation_req listDomainRelationReq;//MFS获取域间关系和带宽限制的请求
	auth_logout_req logOutReq;

	auth_ipc_uploadfile_req	ipcUploadFileReq;
	
	auth_ipc_control_req	ipcControlReq;

	auth_ipc_file_query_req	ipcFileQueryReq;
	auth_ipc_file_down_req	ipcFileDownReq;
	auth_ipc_cancel_file_down_req	ipcCancelFileDownReq;

	auth_ipc_cancel_uploadfile_req	ipcCancelUploadFileReq;

	auth_applyfor_ftp_req	applyforFtpReq;		//上载文件到服务器前，先申请FTP

	cli_notify_cfgchange_struct cfgchange_notify_t;

//	cli_set_decoder_scheme_req setDecoderSchemeReq;
	cli_decoder_play_start_req		decoderCtlStartReq;
	cli_decoder_play_stop_req		decoderCtlStopReq;
	cli_decoder_play_cur_scheme_req	decoderCtlPlayCurSchemeReq;
	cli_decoder_play_resume_req		decoderCtlPlayResumeReq;
	cli_decoder_play_pre_req		decoderCtlPlayPreReq;
	cli_decoder_play_next_req		decoderCtlPlayNextReq;
	cli_decoder_status_report_rsp	decoderStatusReportRsp;

	vms_set_systemip_cfg		setsystemipReq;
	vms_ctlsystem_req		ctlsystemReq;
	vms_setsystem_password	setsystempwdReq;
	vms_general_option_cfg	generalcfgReq;
}cli_vms_msg_body;

typedef union 
{
	auth_set_usr_prof_rsp setUsrRsp;
	auth_set_grp_prof_rsp setGrpRsp;
	auth_get_usr_prof_rsp getUsrRsp;
	auth_get_grp_prof_rsp getGrpRsp;
	auth_set_pswd_rsp setPsWdRsp;
	auth_as_rsp asRsp;
	auth_list_domain_rsp listDomainRsp;
	auth_list_domainrelation_rsp listDomainRelationRsp;
	auth_logout_rsp logOutRsp;

	auth_notify_reboot	rebootClientNotify;//通知客户端重启

	auth_ipc_uploadfile_rsp	ipcUploadFileRsp;
	auth_ipc_control_rsp		ipcControlRsp;

	auth_ipc_file_query_rsp	ipcFileQueryRsp;
	auth_ipc_file_down_rsp	ipcFileDownRsp;
	auth_ipc_cancel_file_down_rsp	ipcCancelFileDownRsp;
	auth_ipc_cancel_uploadfile_rsp	ipcCancelUploadFileRsp;

	auth_notify_uploadfile_down_progress	ipcUploadFileProgressNotify;
	auth_notify_uploadfile_result		ipcUploadFileResult;
	
	auth_notify_ipcfile_upload_progress	ipcFileUpProgressNotify;
	auth_notify_ipcfile_upload_failed	ipcFileUpFailedNotify;
	auth_notify_ipcfile_download	ipcFileDownNotify;		


	auth_notify_ipc_status	ipcStatusNotify;
	vs_alldev_status_notify	allDevStatusNotify;
	vs_allcam_reginfo_notify	allCamReginfiNotify;
	cli_notify_cfgchange_struct cfgchange_notify_t;	//VMS通知监控客户端配置更新

	auth_applyfor_ftp_rsp	applyforFtpRsp;		//上载文件到服务器前，先申请FTP	,返回FTP路径/用户/密码

	cli_notify_cfgchange_rsp cfgchange_rsp_t;

//	cli_set_decoder_scheme_rsp setDecoderSchemeRsp;	
	cli_decoder_play_start_rsp		decoderCtlStartRsp;
	cli_decoder_play_stop_rsp		decoderCtlStopRsp;
	cli_decoder_play_cur_scheme_rsp	decoderCtlPlayCurSchemeRsp;
	cli_decoder_play_resume_rsp		decoderCtlPlayResumeRsp;
	cli_decoder_play_pre_rsp		decoderCtlPlayPreRsp;
	cli_decoder_play_next_rsp		decoderCtlPlayNextRsp;
	cli_decoder_status_report_req	decoderStatusReportReq;

	vms_get_systemip_cfg		getsystemipRsp;
	vms_general_option_cfg		generalcfgRsp;
	vms_ctlsystem_req		ctlsystemRsp;

}vms_cli_msg_body;

struct auth_req
{
	MSMsgHead_t head;
	U32 reqId;
	U16 subType;

	cli_vms_msg_body msg;

	U16 payloadLen;
};

struct auth_rsp
{
	MSMsgHead_t head;
	U32 reqId;
	U16 subType;
	U32 errCode;

	vms_cli_msg_body msg;

	U16 payloadLen;
};




/*************encrypt message ***********************/

struct auth_as_req_enc 
{
	S8 strUsrName[AUTH_MAX_NAME_LEN];
};

struct auth_set_pswd_enc
{
	S8 strUsrId[AUTH_MAX_USER_ID_LEN];
	S8 digestPW[AUTH_HASH_PSWD_LEN];
};


struct auth_domain
{
	S8 strDomainName[AUTH_MAX_DOMAIN_LEN]; 
	S8 strDomainId[AUTH_DOMAIN_ID_LEN+1];
};


#define VISIT_DBS_BY_IP				CONNECT_BY_IP		// 0
#define VISIT_DBS_BY_WWWDOMAINNAME	CONNECT_BY_NAME		// 1

#define VISIT_MFS_BY_IP				CONNECT_BY_IP		// 0
#define VISIT_MFS_BY_WWWDOMAINNAME	CONNECT_BY_NAME		// 1
#define NO_MFS_VISIT					CONNECT_INVALID		// 2

struct auth_domain_svr
{
	auth_domain domain;
	U8 nDbsVisitOption;	//VISIT_DBS_BY_IP, VISIT_DBS_BY_WWWDOMAINNAME
	U8 nMfsVisitOption;	//NO_MFS_VISIT, VISIT_MFS_BY_IP, VISIT_MFS_BY_WWWDOMAINNAME
	U32 nDbsIP; 	//dbs server ip address
	U16 nDbsPort;	//dbs server port
	U16 nDbsWWWPort;
	S8 strDbsWWWDomainName[AUTH_WWW_DOMAINNAME_LEN];

	U32 nMfsIP;   //mfs server ip address
	U16 nMfsPort; //mfs server port
	U16 nMfsWWWPort;
	S8	strMfsWWWDomainName[AUTH_WWW_DOMAINNAME_LEN];
	U32 nMfsBandLimit;	//本域MFS接入子域监控流的带宽限制
};

struct auth_domain_relation
{
	S8 strDomainId[AUTH_DOMAIN_ID_LEN+1]; 
	S8 strParentDomainId[AUTH_DOMAIN_ID_LEN+1];
	U32 nMfsBandLimit;	//子域与父域之间监控流的带宽限制
};

//ip and port is network byte order
struct auth_as_rsp_enc
{
	auth_domain belongDomain; // belong domain 
	S8 strUsrId[AUTH_MAX_USER_ID_LEN];
	S8 strGrpId[AUTH_MAX_GRP_ID_LEN]; // group id list,separated with ','
	S8 strTvWallDomainId[AUTH_MAX_TVWALL_DOMAIN_LEN]; // TV Wall Domain ID list,separated with ','
	S8 realRightBit[AUTH_MAX_RIGHTBIT_LEN];		 //client right bit & with group right bit
	U16 realPriority;		 //max priority in belong group 
	//server address
	U32 ntpIPAddr;			//ntp server ip address 

	U8 nDbsVisitOption;	//VISIT_DBS_BY_IP, VISIT_DBS_BY_WWWDOMAINNAME
	U8 nMfsVisitOption;	//NO_MFS_VISIT, VISIT_MFS_BY_IP, VISIT_MFS_BY_WWWDOMAINNAME
	U8 nVssVisitOption;	//根据登录客户的IP是否公网IP，指示Client访问VSS用WWW域名或者IP地址:CONNECT_BY_IP/CONNECT_BY_NAME
	U32 nDbsIP; 	//dbs server ip address
	U16 nDbsPort;	//dbs server port
	S8 strDbsWWWDomainName[AUTH_WWW_DOMAINNAME_LEN];
	U16 nDbsWWWPort;
	
	U32 nMfsIP;   //mfs server ip address
	U16 nMfsPort; //mfs server port
	S8	strMfsWWWDomainName[AUTH_WWW_DOMAINNAME_LEN];
	U16 nMfsWWWPort;	

	U16 accDomainNum;		 // access domain number
};
// domain list(unit as auth_domain_svr struct) attached, accDomainNum defined the number of the list

typedef struct
{
	U16 bDownloadDbsConfig;
	S8 szFilePath[VS_FILE_PATH_LEN];//指示客户端使用的FTP路径
	S8 szFtpUsrName[VS_FTP_USER_NAME_LEN];	//县文件所用的临时分配的用户名
	S8 szFtpUsrPwd[VS_FTP_USER_NAME_LEN];	
}DbsConfigFtpInfo;

/******************heart beat************************/
struct auth_new_hb_req
{
	MSMsgHead_t head;
	U32 reqId;//
	U16 subType;//本2字段无用，只为VMS用统一的结构来接收心跳请求
	S8 strUsrId[AUTH_MAX_USER_ID_LEN];
	U16 clientType;
};

/*
 *	decrypt password by sha1 to create a digest(20 bytes)
 *  input:
 *  @buf: password
 *  @len: password length
 *  output:
 *  @digest: encrypt data
 */
void SHA1(const S8* buf, U32 len, S8* digest);

/*
 *	encrypt data
 */
int encrypt(const S8* pInBuf, U32 nInLen, void* key, S8** pOutBuf, U32* nOutLen);

/*
 *	decrypt data(output length is the same with the input length)
 */
int decrypt(const S8* pInBuf, U32 nInLen, void* key, S8** pOutBuf);

/*
 *	create crypto key(input: 8 bytes, output:128 bytes) 
 */
void createKey(void *kval, void *key);


#endif

