#pragma once

typedef struct {
	char			path[2048];
	__int64			size;
	char			lastModified[32];
	unsigned int	attr;
	char			source[128];
	int				hit_today;
	int				hit_yesterday;
	int				hit_avr;
	int				per_success;
	__int64			total_size;
	__int64			used_size;
	__int64			traffic;
	__int64			today_traffic;
	char			service_status[2];
	char			ip[16];
	char			backup_path[2048];
} CLFILE_STRUCTEX, *PCLFILE_STRUCTEX;

typedef struct {
	char			sp_user_id[255];
	char			vol_name[255];
	char			s_file[255];
	char			t_file[255];
	char			action;
	char			file_flag;
} TF_LOG_STURCT, *PTF_LOG_STURCT;

#define KP_ERROR_SUCCESS				0
#define KP_ERROR_ERROR					-1
#define UNDEFINED_ERROR					1000

#define NOADMIT_SET_FAIL				1001 
#define NOADMIT_SET_SUCCESS				1010 

#define ADMIT_SET_FAIL					1101 
#define ADMIT_SET_SUCCESS				1110 

#define LOGIN_FAIL_NOID					2001 
#define LOGIN_FAIL_NOPASSWD				2002 
#define LOGIN_FAIL_NETDRV				2003 // 2006.12.19 추가
#define LOGIN_SUCCESS_NOCPD				2009 
#define LOGIN_SUCCESS_EXCPD				2010 
#define LOGIN_SUCCESS_NOCPD_ADMIN		2011 
#define LOGIN_SUCCESS_EXCPD_ADMIN		2012 
#define LOGIN_SUCCESS_NOCPD_SVC_ADMIN	2013  // 2006.11.30 추가
#define LOGIN_SUCCESS_EXCPD_SVC_ADMIN	2014  // 2006.11.30 추가
#define LOGIN_SUCCESS_NETDRV			2015  // 2006.12.19 추가

#define CANNOT_WRITE					4001 
#define NO_QUOTA						4002
#define UPLOAD_WORKING					4003
#define CAN_WRITE						4010 
#define CAN_OVER_WRITE					4009

#define WRITE_WORKING					5001 
#define WRITE_BEGIN						5010 
#define WRITE_END						6010 

#define MODIFY_WORKING					7001 
#define MODIFY_BEGIN					7010 
#define TARGET_FILE_EXIST				7002
#define MODIFY_END						8010 

#define SET_BACKUP						1110 

#define NOTICE_SHOW						1210
#define NOTICE_HIDE						1209 

#define SYNC_SUCCESS					1510 // 2006.12.19 추가

#define DELIM							"!"
#define FILE_TYPE_D						"D"
#define FILE_TYPE_F						"F"

#define KPOST_WEBIP				_T("www.ktsystemhosting.com")
#define KPOST_WEBREF			_T("/sp/getlogs/modules/")
#define _HTTP_PORT				8080

//#define KPOST_WEBREF			"modules/test.php"

static TCHAR *modify_types[] = {_T("R"), //Rename
_T("D"), //Delete
_T("M"), //Move
_T("C"), //Copy
_T("A")	 //Append
};

class CWebUtil  
{
public:
	static enum MODIFY_TYPE {
		MOD_RENAME,
		MOD_DELETE,
		MOD_MOVE,
		MOD_COPY,
		MOD_APPEND,
		MOD_UNKNOWN
	};

public:
	CWebUtil();
	virtual ~CWebUtil();

	PCLFILE_STRUCTEX kp_get_file_list(
		const char   *path,		// Path
		unsigned int depth,		// 0 : itself
		// 1 : 1 depth children
		// 2 : all children
		unsigned int *count);	// File count

	void kp_free_file_list(
		PCLFILE_STRUCTEX pclf); // File list pointer

	int	kp_init(CString cp_id,CString cp_user_id, CString pass);
	int kp_set_annoy(CString sPath,BOOL bSet);
	int kp_chk_login(BOOL bisNetdrive = FALSE);
	int kp_chk_upload(CString sPath,CString sFileName,LARGE_INTEGER nSize,BOOL bDir);
	int kp_set_start_upload(CString sPath, CString sFileName, LARGE_INTEGER nSize,BOOL bIsDir, BOOL bOverWrite);
	int kp_set_end_upload(CString sPath, CString sFileName, LARGE_INTEGER nSize,BOOL bSuccess);
	int kp_set_start_modify(CString sSPath, CString sSFileName, LARGE_INTEGER nSSize, 
		CString sDPath, CString sDFileName, LARGE_INTEGER nDSize, MODIFY_TYPE Type);
	int kp_set_end_modify(CString sSPath, CString sSFileName, LARGE_INTEGER nSSize, 
		CString sDPath, CString sDFileName, LARGE_INTEGER nDSize, MODIFY_TYPE Type);
	int kp_set_backup(CString sSrcPath,CString sFlag);
	int kp_set_backup_path(CString sBackupPath);
	CString kp_get_backup_path();
	int kp_chk_notice();
	int kp_sync_data();
	int kp_get_sync_time();
private:
	CString m_cpid;
	CString m_loginid;
	CString m_pass;
	CString kp_get_encoded_data(CString strData);
	CString kp_get_decoded_data(CString strData);
	CString kp_get_base64_data(CString strData);
	CString kp_get_unbase64_data(CString strData);
	CString kp_get_crypted_data(CString strData);
	CString kp_recv_data_http(CString strParam,BOOL bssl);

	PCLFILE_STRUCTEX kp_parse_file_list_struct(CString sData,unsigned int *count);
	int kp_process_errors(int nError,MODIFY_TYPE Type = MOD_UNKNOWN);
public:
	int kp_file_opt_log(PTF_LOG_STURCT);
	int kp_send_mail(CString  , CString , CString , CString );

};