#ifndef __PROTOCOL_H__
#define __PROTOCOL_H__

#define RESERVED              5
#define MaxSizeOfCode         3

#define MaxSizeOfTID          52
#define MaxSizeOfIssuer       128
#define MaxSizeOfSID          128
#define MaxSizeOfRCID         32

#define MaxSizeOfRCURL        128
#define MaxSizeOfServiceName  128
#define MaxSizeOfURIPath      1024

#define NumOfServerType             11
#define MaxSizeOfServerName         32
#define MaxSizeOfServerAddr         16
#define MaxSizeOfServerPort         8
#define MaxSizeOfServerType         24

#define MaxSizeOfRCAcctName         32
#define MaxSizeOfRCAcctUser         32
#define MaxSizeOfRCAcctPassword     32
#define MaxSizeOfRCAcctCert         128
#define MaxSizeOfRCAcctAuthkey      128

#define MAX_SRV_NAME				128
#define MAX_DOMAIN_NAME				256

#define MAX_MNG_RCID				128
#define	MAX_MNG_SERVNAME			128
#define CONFIG_SERV                 "SERV"
#define CONFIG_RCACCT               "RCACCT"
#define MAX_ALLOWED_DEAD_COUNT		3
#define ALLOWED_MAX_ERROR_COUNT		5
#define	SENDSMSTERM					5
#define MAXSENDSMSCOUNT				5
#define SERV_ALIVE		1
#define SERV_DEAD		2
#define NO_MONITOR		3
#define	END_OF_SHM		"end of shm!"

//#define MYQUERY			"SELECT NAME, IP, PORT, TYPE, MONITOR_YN FROM t_rms_rc_server_index WHERE DELETED_YN = 'N' ORDER BY cast(ETC2 as signed) ASC, ETC1 ASC ,NAME ASC"
#define MYQUERY		"SELECT NAME, IP, PORT, TYPE, MONITOR_YN from (SELECT NAME, IP, PORT, TYPE, MONITOR_YN FROM t_rms_rc_server_index WHERE DELETED_YN = 'N' AND rcid != 'TIME' ORDER BY cast(ETC2 as signed) ASC, ETC1 ASC ,NAME ASC) a UNION ALL SELECT NAME, IP, PORT, TYPE, MONITOR_YN FROM t_rms_rc_server_index WHERE DELETED_YN = 'N' AND rcid = 'TIME'"
enum eServType
{
	SERV_WWW         = 0,
	SERV_FHS         = 1,
	SERV_RC          = 2,
	SERV_DB          = 3
};

extern const char	 a_ServType[NumOfServerType][MaxSizeOfServerType];

#define MAX_IP_STRING   17

struct common_message_header {
	char szTransactionID[MaxSizeOfTID];
	unsigned long ulMode;
	char szIssuer[MaxSizeOfIssuer];
	char szServiceID[MaxSizeOfSID];
	unsigned long ulResult;
	unsigned long ulBodyLength;
};
#define MaxSizeOfCMH          (sizeof(struct common_message_header))

struct local_message_header {
	char szTransactionID[MaxSizeOfTID];
	unsigned long ulMode;
	char szIssuer[MaxSizeOfIssuer];
	char szServiceID[MaxSizeOfSID];
	char szRCID[MaxSizeOfRCID];
	unsigned long ulResult;
	unsigned long ulBodyLength;
};

#define MaxSizeOfLMH          (sizeof(struct local_message_header))

#define CODE_ESC              0x1b

#define DOMAIN_SIZE         512
#define HOSTNAME_SIZE       64

struct disk_usage {
	/* Original Message */
	char domain[DOMAIN_SIZE];
	unsigned long long total;
	unsigned long long free;

	/* Additional : 2006.11.08 by Elenoa */
	/* if manually upload enable/disable */
	int manual_disable;
	int upload_level;
	/* disk stat: backlog and use percentage */
	int disk_backlog;
	int disk_percent;
	/* connection stat: established connection and others all */
	int connection_established;
	int connection_total;
	/* traffic stat: in and out traffic info (packet, byte) */
	unsigned long traffic_ip;
	unsigned long traffic_ib;
	unsigned long traffic_op;
	unsigned long traffic_ob;
	char hostname[HOSTNAME_SIZE];
};

struct svr_status {
	    time_t stamp;
		struct disk_usage du;
};

#define AuthPrime 137897
typedef struct _s_time_sync_t {
	    long sync_info;
} time_sync_t;

typedef struct _ServInfo_e
{;
	char			m_pszServName[MAX_SRV_NAME];
	char			m_szIpString[MAX_IP_STRING];
	short			m_sPort;
	time_t          m_StatChgTime;
	unsigned int    m_Status;
	unsigned int    m_ServType;
	unsigned int    m_DeadCount;
	char			m_pszDomainName[MAX_DOMAIN_NAME];
	char			m_monitorYN[2];
	struct svr_status ss;

	struct _ServInfo_e *next;
} servinfo_t;

typedef struct _RCAcct_e
{
	char *           m_pszServiceName;
	char *           m_pszUserName;
	char *           m_pszPassword;
	char *           m_pszAuthkey;
	char *           m_pszCertLocation;
	struct _RCAcct_e *next;
} rcacct_t;

/* Global Shared Memory Address */
typedef struct _g_shm_addr
{
	unsigned int is_dirty;
	unsigned int serv_num;
	unsigned int thread_number[1024];
} g_shm_t;

typedef struct _rcmng_common_header
{
	char			rcmng_rcid[MAX_MNG_RCID];
	char			rcmng_servName[MAX_SRV_NAME];
	unsigned int	rcmng_serviceType;
	unsigned long	bodylength;
} rcmng_cheader_t;

typedef struct _CellInfo
{
	char           m_strCellPhone[24];
} cellinfo_t;

/* Definition of Message Mode */

#define MSG_MODE_VRCD_STATUSD_RTS_STATUS               0x0a01

/* Open Service and Subroot Create */

#define MSG_MODE_SMS_CCSYNC_OPEN_SERVICE               0x0001
#define MSG_MODE_CCSYNC_RCSYNC_DATA_INPUT              0x0002
#define MSG_MODE_RCSYNC_CCSYNC_DATA_INPUT_RESP         0x0003
#define MSG_MODE_RCSYNC_RCTRAN_SUBROOT_CREATE          0x0004
#define MSG_MODE_RCTRAN_VMA_SUBROOT_CREATE             0x0005
#define MSG_MODE_RCTRAN_RCSYNC_SUBROOT_CREATE_RESP     0x0006
#define MSG_MODE_RCSYNC_CCSYNC_DATA_INPUT_FAIL         0x0007
#define MSG_MODE_VMA_RCTRAN_SUBROOT_CREATE_RESP        0x0008

/* SP-Console Process : Receive Server List */

#define MSG_MODE_SPCONS_CCTRAN_SERVER_LIST             0x0010
#define MSG_MODE_CCTRAN_SPCONS_SERVER_LIST_RESP        0x0011

/* SP-Console Process : Receive Volume Size */

#define MSG_MODE_SPCONS_RCTRAN_VOLUME_SIZE             0x0012
#define MSG_MODE_RCTRAN_SPCONS_VOLUME_SIZE_RESP        0x0013

/* SP-Console Process : Set/Unset Anonymous Directory */

#define MSG_MODE_SPCONS_RCTRAN_SET_ANONY               0x0014
#define MSG_MODE_RCTRAN_APACHE_SET_ANONY               0x0015
#define MSG_MODE_RCTRAN_SPCONS_SET_ANONY_RESP          0x0016
#define MSG_MODE_APACHE_RCTRAN_SET_ANONY_RESP          0x0017

#define MSG_MODE_SPCONS_RCTRAN_UNSET_ANONY             0x0018
#define MSG_MODE_RCTRAN_APACHE_UNSET_ANONY             0x0019
#define MSG_MODE_RCTRAN_SPCONS_UNSET_ANONY_RESP        0x001a
#define MSG_MODE_APACHE_RCTRAN_UNSET_ANONY_RESP        0x001b

/* SP-Console Process : Bandwidth Level */

#define MSG_MODE_SPCONS_RCTRAN_SET_BCLEVEL             0x001c
#define MSG_MODE_RCTRAN_APACHE_SET_BCLEVEL             0x001d
#define MSG_MODE_RCTRAN_SPCONS_SET_BCLEVEL_RESP        0x001e
#define MSG_MODE_APACHE_RCTRAN_SET_BCLEVEL_RESP        0x001f

/* Volume Manager Agent Process : Statistcs and Disksize broadcast */

#define MSG_MODE_VMA_APACHE_DISKSIZE                   0x0100
#define MSG_MODE_APACHE_VMA_DISKSIZE_RESP              0x0101
#define MSG_MODE_GVA_VMA_STG_STAT_REQ                  0x0102
#define MSG_MODE_VMA_GVA_STG_STAT_RESP                 0x0103

/* Network Statistics */

#define MSG_MODE_STATCOL_APACHE_NETSTAT_REQ            0x0104
#define MSG_MODE_APACHE_STATCOL_NETSTAT_RESP           0x0105
#define MSG_MODE_STATCOL_STATDEM_NETSTAT               0x0106
#define MSG_MODE_STATDEM_STATCOL_NETSTAT_RESP          0x0107

/* Statistics Service */

#define MSG_MODE_OPENDAV_RCSTAT_NETSTAT                0x0110
#define MSG_MODE_RCSTAT_OPENDAV_NETSTAT_RESP           0x0111
#define MSG_MODE_RCSTAT_CCSTAT_NETSTAT                 0x0112
#define MSG_MODE_CCSTAT_RCSTAT_NETSTAT_RESP            0x0113
#define MSG_MODE_RCSTAT_CCSTAT_STGSTAT                 0x0114
#define MSG_MODE_CCSTAT_RCSTAT_STGSTAT_RESP            0x0115

#endif
