/***************************************************************************
                Database Class
                -----------------------------------------
    begin      : 2015/05/11
    copyright  : (C) 2010 SolutionBox Inc.
	author     : Service 1 Team
	email      : svc1@solbox.com
    version    : 1.0

    CopyRight(C) 2010 SolutionBox Inc. All Rights reserved.
    Redistribution and use in source and binary forms, with or with out
    modification, are not permitted in outside of SolutionBox Inc.
***************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>

#ifndef __FIMNGD_DATA_H__
#define __FIMNGD_DATA_H__

#define MaxSizeOfPermittedReferer	4096
#define MaxSizeOfSvcID			33
#define MaxSizeOfUserID			256
#define MaxSizeOfUserPassword	256
#define MaxSizeOfUserSeq		40
#define MaxSizeOfUserTranID		40
#define KEY_LENGTH				24
#define MaxSizeOfUserIV			(KEY_LENGTH + 2)
#define MaxSizeOfUserPK			(KEY_LENGTH + 2)
#define MaxSizeOfUserAuthUri	256
#define MaxSizeOfUserAuthAddr	256
#define MaxSizeOfUserAuthMode	10

#define URI_SIZE_MAX           2048
#define DOMAIN_SIZE				512

#define FILENAME_HASH_SIZE		128
#define HOST_NAME_SIZE		64

////////////////////// shared memory를 위한 구조체들 /////////////////////
//  /tmp/opendav.shared.account.shm 
struct account {
	//flag
	// DB조회 결과에서 해당 서비스가 없다면 nFlag를 '1'로 설정
	// 값이 1이면 RCDB 조회결과 해당 서비스가 없다는 의미이다.
	int nFlag; // 0 : 서비스 존재, 1: 서비스 없음
	
	// authorized related
	char id[MaxSizeOfUserID];
	char svc_id[MaxSizeOfSvcID];
	char pass[MaxSizeOfUserPassword];
	char seq[MaxSizeOfUserSeq];
	char tran_id[MaxSizeOfUserTranID];
	char iv[MaxSizeOfUserIV];
	char pk[MaxSizeOfUserPK];

	//uri ignore case  : 1 - ignore case, 0 - Not ignore case
	int is_ignorecase;
	
	// authenticate related - user identify
	char auth_uri[MaxSizeOfUserAuthUri];
	char auth_addr[MaxSizeOfUserAuthAddr];
	short auth_port;
	int auth_timeout;

	/* billing related - for SP */
	char bill_uri[MaxSizeOfUserAuthUri];
	char bill_addr[MaxSizeOfUserAuthAddr];
	short bill_port;
	int bill_timeout;

	// auth and bill mode
	char mode[MaxSizeOfUserAuthMode];

	//traffic control value
	int tc_percent;
	int tc_session;

	/* Elenoa: 2007. 5. 9: add referer check */
	char permitted_referer[MaxSizeOfPermittedReferer];
	char permitted_extend[MaxSizeOfPermittedReferer];
};

// /tmp/opendav.shared.anony.shm 
struct anonymous {
	char uri[URI_SIZE_MAX];
	char domain[DOMAIN_SIZE];
	int nFlag;
};

// /tmp/opendav.shared.fhsstat.shm
struct fhs_stat
{  
	char    szHostname[64];
	int     nActionCode;
};


// /tmp/opendav.shared.networkstat.shm
// rc_statd와 통신을 할 때도 사용 된다.
struct service_network_stat {
	int nServiceSeq;
	int nUserSeq;
    uint32_t timestamp; // 5분 단위 1씩 증가.

    uint64_t down_content_size;	// 누적시 down content size 누적
	uint64_t up_content_size;   // 누적시 up contents size 누적
    uint64_t down_traffic;		// 누적시 (down_content_size * 1.1)를 누적
	uint64_t up_traffic;		// 누적시 (up_traffic * 1.1)를 누적
};

////////////////////// IPC Message 큐를 위한 구조체 /////////////////////
// IPC Msg Queue 용 전달 구조체.
struct Transfer_stat {
    long mtype;	// 고정으로 1 :>> Message Queue를 활용 할 때 항상 mtype은 있어야 한다.
    uint32_t timestamp; // opendav에서 정보를 생성한 시간
    short int nInOut; // Outboud : 0  Inboud: non zero
    int nUserSeq;
    int nServiceSeq;
    uint64_t sizeTransfer;
    char filename_hash[FILENAME_HASH_SIZE];
};

#endif // __FIMNGD_DATA_H__
