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

   mod_dav_pgsql (DASL) for apache 2.X
   CopyRight(C) 2005 SolutionBox Inc. All Rights reserved.
   Author : sean kim (sean@solutionbox.co.kr)

   $Id: dav_repos.h,v 1.2 2006/09/20 09:22:59 sean Exp $

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

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

#ifndef __DAV_REPOS_H__
#define __DAV_REPOS_H__

#include <mod_dav.h>
//#include <libpq-fe.h>
#include <http_protocol.h>
#include <apr_reslist.h>
#include <apr_thread_rwlock.h>

#include <math.h>	// added by sangkeun.ha 20091111

extern apr_thread_rwlock_t *db_lock;
//extern apr_global_mutex_t *db_global_lock;
// 2012.07.04 dadamin
// FreeBSD 경우 getmntent 함수 쓰레드 지원하지 않기 때문에
// 관련 함수 사용 로직에 lock을 사용하여 이를 대처함
#ifdef __FreeBSD__
extern apr_global_mutex_t *local_disk_lock;
#endif // __FreeBSD__

#ifndef __OPENDAV_DEBUG__
#undef DBG0
#undef DBG1
#undef DBG2
#undef DBG3
#define DBG0(f)
#define DBG1(f,a1)
#define DBG2(f,a1,a2)
#define DBG3(f,a1,a2,a3)
#endif

//#define TRACE() DBG3("**** TRACE FUNC: %s, LINE: %d , FILE: %s",  __FUNCTION__ , __LINE__, __FILE__);
#define TRACE() {}
#define MD5Private "sl;dif;weoghniodsvklhn[4gjv0w v9erjg0[2jf[	poejf' pqoefgjb[24tjgo2vbnmgjvoiwgnbl;erykn['3khi	-q0wefvoidskvnmbl;en3j1q049fvowfidbnmlenmklcn	jwbs	uq2hneu	24thngo31ignoifndvbnb456nhg-qrkebpow4mbnoiwmdfvbinj4hvgacvm;kldsgnboerignbowignb0q935tgj0	31fdpodsmv;lfnb[o4i3wjh09rjgvpqrjvbwfopbmeryojk= 42-whb'afbm;fhknmb2	9irj0`	oJAF[POjSFOIQJGVOWIJHP[OGJ1Q3YGJ"

#define DEFAULT_NAMESPACE_URI "http://dav.solbox.com/dav/props/"

typedef struct
{ 
	const char *storage_dir;
	const char *base_uri;
	apr_table_t *d_params;       /* per-directory DAV config parameters */
} dav_repos_dir_conf;

struct __dav_repos_server_conf;

#define MaxSizeOfFilePath       4096
#define MaxSizeOfFileName       1024

typedef struct _mirror_header {
	unsigned int ulMode;
	char szFilePath[MaxSizeOfFilePath];
	char szFileName[MaxSizeOfFileName];
	apr_int64_t fileSize;
	apr_int64_t fileOffSet;
} sync_msg_header_t;


typedef struct __dav_repos_server_conf
{
	const char *storage_dir;
	const char *base_uri;
	const char *host_name;
	const char *max_fhs;
	int	max_progress;


	// CHG 2019-09-24 huibong Bigbox FHS 장비 사용에 따른 mount 별 운영여유공간 계산방식 개선 (#32807)
	// - 기존 conf 상의 DavProviderStorageLimit 설정은 제거 처리
	//int storage_limit;
	
	const char *max_anony_realm;

	// CHG 2012-06-27 dadamin
	// sibling 및 sync_host 기능은 2011 년 BD-06 사내망 제거 이후 더 이상 사용하지 않는 기능임.
	// 따라서 아래 관련 코드를 주석 처리함.
	//const char *sibling;
	//const char *sync_host;

	const char * db_charset;

	int user_cache;
	int close_insertoff;

	apr_table_t *d_params;	
} dav_repos_server_conf;


/* our hooks structures; these are gathered into a dav_provider */
extern const dav_hooks_repository dav_repos_hooks_repos;
extern const dav_hooks_propdb dav_repos_hooks_propdb;
extern const dav_hooks_search dav_repos_hooks_search;

// CHG 2011-12-01 huibong
// repos.c 에 정의된 static const dav_hooks_liveprop dav_repos_hooks_liveprop; 구문으로 인해
// gcc 4.4.5 버전에서 컴파일 오류 발생. 이를 해결하기 위해 중복 선언 부분을 제거처리함.
//extern const dav_hooks_liveprop dav_repos_hooks_liveprop;

extern const dav_hooks_locks dav_repos_hooks_locks;
extern const dav_liveprop_group dav_repos_liveprop_group;

/* handle the SEARCH method */
int dav_repos_method_search(request_rec * r);

void dav_repos_insert_all_liveprops(request_rec * r, const dav_resource * resource, dav_prop_insert what, apr_text_header * phdr);
int dav_repos_find_liveprop(const dav_resource * resource, const char *ns_uri, const char *name, const dav_hooks_liveprop ** hooks);

/* some prototype */
const char *dav_repos_getetag(const dav_resource * resource);

#ifdef __USE_MULTIPLE_STORAGE__
	int get_writable_path(apr_pool_t *p, const char *homepath, char *subpath);
#endif

	
int dav_auth_authorization(request_rec * r);
int dav_auth_authenticate(request_rec * r);

int dav_auth_user_start(dav_resource_private *info);
void dav_auth_user_end(dav_resource_private *info);


#ifdef __USE_AUTH_SOFTLINE_ONLY__
	void dav_auth_upload_end( dav_resource_private *info );
#endif // __USE_AUTH_SOFTLINE_ONLY__
#endif
