/***************************************************************************
				protocol define (cc_tsd)
                -----------------------------------------

	begin      : 2013/09/16
	copyright  : (C) 2005 Solbox Inc.
	author     : Development 1 Team
					- 2013/09/16
	email      : dev1@solbox.com
	version    : 3.2.0

	CopyRight(C) 2005 Solbox Inc. All Rights reserved.
	Redistribution and use in source and binary forms, with or with out
	modification, are not permitted in outside of Solbox Inc.
***************************************************************************/


#ifndef __PROTOCOL_H__
#define __PROTOCOL_H__

#include <iostream>


using namespace std;

#define MaxSizeOfTID				  52 
#define MaxSizeOfIssuer				  128
#define MaxSizeOfServiceID			  128

#define MaxSizeOfSvcID				  32
#define MaxSizeOfRCURL				  128

#define CODE_ESC					  0x1b

#define MODE_DEFAULT				  0x0000
#define MODE_SYNC_NOTICE			  0x0001
#define MODE_SP_DATA				  0x0002
#define MODE_SYNC_RESPONSE			  0x0009
#define MODE_SRV_LST_REQUEST		  0x0010
#define MODE_SRV_LST_RESPONSE		  0x0011
#define MODE_SRV_LST_2ND_REQUEST	  0x0080
#define MODE_SRV_LST_2ND_RESPONSE	  0x0081
#define MODE_SRV_TRAFFIC_REQUEST      0x0082
#define MODE_SRV_TRAFFIC_RESPONSE     0x0083

#define PROTO_SUCCESS				  0x1000
#define PROTO_FAILURE				  0x3000 
#define PROTO_FAILURE_AUTH			  0x3001 
#define PROTO_INTERNAL_ERROR		  0x9000 

#define MODE_USER_DATA_MODIFIER_REQ   0x0301
#define MODE_USER_DATE_MODIFIER_RESP  0x0302

#define MODE_APACHE_ERROR_LOG_REQ     0x0401
#define MODE_APACHE_ERROR_LOG_RESP    0x0402
#define MODE_APACHE_ACCESS_LOG_REQ    0x0403
#define MODE_APACHE_ACCESS_LOG_RESP   0x0404

#define ISSUER_SP_CONSOLE "SP-Console"
#define ISSUER_SP_CONSOLE3 "SP-Console3"
#define ISSUER_SERVER "cc_tsd"


typedef struct _s_time_sync_t
{
	int32_t sync_info;
} time_sync_t;

typedef struct _s_msg_header {
	char		m_szTID[MaxSizeOfTID];
	uint32_t	m_ulMode;
	char		m_szIssuer[MaxSizeOfIssuer];
	char		m_szServiceID[MaxSizeOfServiceID];
	uint32_t	m_ulResult;
	uint32_t	m_ulBodyLength;
} MsgHeader;

typedef struct _s_t_service_info {
	char sp_svc_id[MaxSizeOfSvcID];
	char svc_rcts_url[MaxSizeOfRCURL];
	char vol_url[MaxSizeOfRCURL];
} sp_service_info;

typedef struct _s_user_auth {
	char szUserID[32];
	char szHashed[33];
	time_t reqTime;    // 32/64 bit not equeal data size... !!!
} user_auth_t;

#define SizeOfMsgHeader      sizeof(MsgHeader)
extern int fillMsgHeader(MsgHeader *pMsgHeader, const char *pszTID, 
                         const unsigned long m_ulMode, const char *pszIssuer,
                         const char *pszServiceID, const unsigned long m_ulResult,
                         const long m_ulBodyLength);

#endif
