/****************************************************************************

   mod_dav_pgsql (DASL) for apache 2.X
   CopyRight(C) 2005 SolutionBox Inc. All Rights reserved.
   CopyRight(C) 2006 Netomi Inc. All Rights reserved.
   Author : elenoa lazyfake (elenoa@solutionbox.co.kr)

   $Id: share.h,v 1.6 2007/03/19 08:43:12 elenoa Exp $

   Redistribution and use in source and binary forms, with or with out
   modification, are not permitted in outside of SolutionBox Inc.

 ****************************************************************************/

#ifndef __SHARE_ACCOUNT_H__
#define __SHARE_ACCOUNT_H__

#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 MaxSizeOfPermittedReferer	4096


#ifdef __CLASSIFIED_TRAFFIC_MANAGE__
#define MAX_CLASS	4
#endif // __CLASSIFIED_TRAFFIC_MANAGE__

struct account_cache {
	//flag
	// DB조회 결과에서 해당 서비스가 없다면 nFlag를 '1'로 설정
	int nFlag; // 0 or 1 '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];
};

/* account cache */
int dav_initialize_shared_account_cache(dav_repos_server_conf *dsc, server_rec *s, apr_pool_t *p);
void dav_cleanup_shared_account_cache();


struct account_cache * dav_shared_ac_get_by_vol(const char * volume_name);
struct account_cache * dav_shared_ac_get_by_vol_not_timeout(const char * volume_name);
struct account_cache * dav_shared_ac_get_by_tranid(char *tranid);

// NEW 2012-03-20 노경민
// 각 서비스별 uri 에 대한 대소문자 구분, 무시 여부를 반환한다.
// 해당 반환값은 RCDB t_sms_sp_svc_product 테이블 uri_ignore_case 필드의 설정값을 확인하여 다음과 같이 반환처리한다.
//  0 : 대소문자 구분 ( 양방향 Default )
//  1 : 대소문자 무시
// -1 : 오류 발생.
int dav_shared_is_uri_ignore_case(const dav_resource * resource);
int dav_shared_is_uri_ignore_case_by_tranid(char *tranid);
int dav_shared_is_uri_ignore_case_by_svcname(const char * svcname);

int dav_shared_ac_check_referer(struct account_cache *ac, request_rec *r);

#endif // __SHARE_ACCOUNT_H__
