#ifndef _COMMLIB_H
#define _COMMLIB_H

#if defined(COMMLIB_EXPORTS)
# define WIN32DLL __declspec(dllexport)
#else
# define WIN32DLL __declspec(dllimport)
#endif


typedef void *HCOMMLIB;


#pragma pack(1)
typedef struct {
	char id[32];
	char domain[128];
#ifdef _OLD
#else
	char domain2[128];
#endif
} CLSERVICE_STRUCT, *PCLSERVICE_STRUCT;
#pragma pack()

#pragma pack(1)
typedef struct {
	char value;
	char path[2048];
} CLPATHINFO_STRUCT, *PCLPATHINFO_STRUCT;
#pragma pack()

typedef struct {
	char         path[2048];
	__int64      size;
	char         lastModified[32];
	unsigned int attr;
//	char*        mimeType;
	char         source[128];
} CLFILE_STRUCT, *PCLFILE_STRUCT;


// For SHFILE_STRUCT.attr
enum CL_FILEATTR {
	CLFILEATTR_FOLDER = 0x00000001,
};

// For write policy
enum CL_WRITEPOLICY {
	CLWRITEPOLICY_NONE      = 0,
	CLWRITEPOLICY_OVERWRITE,
	CLWRITEPOLICY_APPEND
};

// For error number : SHCSDK_ERRNO 와 동일해야한다.
enum CL_ERRNO {
	CLERRNO_UNDEFINED         	= 30000,
	CLERRNO_INVALID_HANDLE    	= 30001,
	CLERRNO_INVALID_FILE_HANDLE	= 30002,
	CLERRNO_SERVICE           	= 30003,
	CLERRNO_AUTHORIZATION     	= 30004,	
	CLERRNO_BUSY              	= 30005,	
	CLERRNO_EXISTSFILE        	= 30006,
	CLERRNO_NOEXISTSFILE      	= 30007,	
	CLERRNO_NOAVAILQUOTA		= 30008,
	CLERRNO_ALREADYEXIST		= 30009,
	CLERRNO_RESP_TIMEOUT		= 30010,
	CLERRNO_NE_LOOKUP			= 30011,
	CLERRNO_NE_CONNECT			= 30012,
	CLERRNO_TRAGETBIGGER		= 30013,
	CLERRNO_DNS_TIMEOUT			= 30014,
	// SHCSDK_ERRNO 선언되지 않는 에러들
	CLERRNO_PARSE_FILE_LIST   	= 30041,
	CLERRNO_ABNORMAL_RESPONSE 	= 30042,
	CLERRNO_FORBIDDEN         	= 30043,
	CLERRNO_NOSERVICE_LIST		= 30044,
	CLERRNO_NOAVAILPATH_LIST	= 30045,
	CLERRNO_INVALID_CMD_RESULT	= 30046,
	// SSDK_ERRORNO 	
	CLERRNO_SSDK_AUTHORIZATION		= 31000,
	CLERRNO_SSDK_INTERNAL			= 31001,
	CLERRNO_SSDK_NOSERVICE			= 32000,
	CLERRNO_SSDK_NOCACHEFILE		= 33000,
	CLERRNO_SSDK_INVALIDCACHEFILE	= 33001,
	CLERRNO_MAX					= CLERRNO_SSDK_INVALIDCACHEFILE + 1,
};

// Callback function format
typedef void (*cl_callback)(
	void    *param, // Callback function's param
	__int64 result  // 0  : Complete,
                    // -1 : Error,
                    // .. : Processing
);


#ifdef __cplusplus
extern "C" {
#endif

#ifdef _OLD
// Initialization
WIN32DLL HCOMMLIB cl_init(
	const char   *url,       // Url, CENTER == NULL
	const char   *userId,    // User id
	const char   *password,  // Password
	const char   *proxyHost, // Proxy server addr
	unsigned int proxyPort); // Proxy server port
#else
WIN32DLL HCOMMLIB cl_init(
	const char   *url,       // Url, CENTER == NULL
	const char	 *d2,		 // second domain
	const char   *userId,    // User id
	const char   *password,  // Password
	const char   *proxyHost, // Proxy server addr
	unsigned int proxyPort); // Proxy server port
#endif

// Termination
WIN32DLL void cl_free(
	HCOMMLIB hcl);


WIN32DLL int cl_get_error_number(
	HCOMMLIB hcl);
WIN32DLL const char* cl_get_error_message(
	HCOMMLIB hcl);


WIN32DLL PCLSERVICE_STRUCT cl_get_service_list(
	HCOMMLIB     hcl,
	unsigned int *count); // Island count

WIN32DLL void cl_free_service_list(
	HCOMMLIB          hcl,
	PCLSERVICE_STRUCT pclsl); // Volume list pointer

WIN32DLL BOOL cl_get_service_info(
	HCOMMLIB   hcl,
	const char *serviceId,
	__int64    *totalBytes,
	__int64    *usedBytes);


WIN32DLL PCLFILE_STRUCT cl_get_file_list(
	HCOMMLIB     hcl,
	const char   *path,   // Path
	unsigned int depth,   // 0 : itself
                          // 1 : 1 depth children
                          // 2 : all children
	unsigned int *count); // File count

WIN32DLL void cl_free_file_list(
	HCOMMLIB       hcl,
	PCLFILE_STRUCT pclfl); // File list pointer


WIN32DLL PCLPATHINFO_STRUCT cl_get_path_auth(
	HCOMMLIB     hcl,
	const char   *serviceId,
	unsigned int *count);

WIN32DLL void cl_free_path_auth(
	HCOMMLIB           hcl,
	PCLPATHINFO_STRUCT pclpi);

WIN32DLL BOOL cl_set_anonyauth(
	HCOMMLIB   hcl,
	const char *serviceId,
	BOOL       set,
	const char *path);

WIN32DLL BOOL cl_set_bandwidth(
	HCOMMLIB   hcl,
	const char *serviceId,
	const char *levelnpath);


WIN32DLL BOOL cl_make_directory(
	HCOMMLIB   hcl,
	const char *drectory); // Directory Path

WIN32DLL BOOL cl_copy(
	HCOMMLIB   hcl,
	const char *srcPath,   // Source directory | file Path
	const char *dstPath,   // Destination directory | file Path
	BOOL       overwrite); // Overwrite

WIN32DLL BOOL cl_move(
	HCOMMLIB   hcl,
	const char *srcPath,   // Source directory | file Path
	const char *dstPath,   // Destination directory | file Path
	BOOL       overwrite); // Overwrite

WIN32DLL BOOL cl_delete(
	HCOMMLIB   hcl,
	const char *path);  // Directory | file Path


WIN32DLL BOOL cl_upload(
	HCOMMLIB    hcl,
	const char  *srcPath,     // Source file
	const char  *dstPath,     // Destination file
	int         writePolicy,  // Write policy flag
	__int64     availQuota,
	cl_callback callbackProc,
	void        *pParam);

WIN32DLL BOOL cl_download(
	HCOMMLIB    hcl,
	const char  *srcPath,     // Source file
	const char  *dstPath,     // Destination file
	int         writePolicy,  // Write policy flag
	__int64     availQuota,
	cl_callback callbackProc,
	void        *pParam);

WIN32DLL void cl_stop_transfer(
	HCOMMLIB hcl);

WIN32DLL void cl_set_write_log_dir(bool bLog);
WIN32DLL void cl_set_write_log_upload(bool bLog);
WIN32DLL bool cl_create_log_file();
WIN32DLL void cl_destroy_log_file();
WIN32DLL void cl_write_log(char* pszLog, DWORD dwSize, bool bWriteTime);

#ifdef __cplusplus
}
#endif

#endif
