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

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

   $Id: lock.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_LOCK_H__
#define __DAV_REPOS_LOCK_H__

#include <apr_uuid.h>
//#include <libpq-fe.h>

#include "dav_repos.h"

/* #################################################################
** ### keep these structures (internal) or move fully to dav_lock?
*/

/*
** Use the opaquelock scheme for locktokens
*/
struct dav_locktoken
{
    const char *char_uuid;
};

int dav_repos_lock_expired(time_t expires);

/*
** We need to reliably size the fixed-length portion of
** dav_lock_discovery; best to separate it into another 
** struct for a convenient sizeof, unless we pack lock_discovery.
*/
typedef struct dav_lock_discovery_fixed
{
    char scope;
    char type;
    int depth;
    time_t timeout;
}
dav_lock_discovery_fixed;

typedef struct dav_lock_discovery
{
    struct dav_lock_discovery_fixed f;
    dav_locktoken *locktoken;
    const char *owner;		/* owner field from activelock */
    const char *auth_user;	/* authenticated user who created the lock */
    struct dav_lock_discovery *next;
}
dav_lock_discovery;

/* Indirect locks represent locks inherited from containing collections.
 * They reference the lock token for the collection the lock is
 * inherited from. A lock provider may also define a key to the
 * inherited lock, for fast datbase lookup. The key is opaque outside
 * the lock provider.
 */
typedef struct dav_lock_indirect
{
    dav_locktoken *locktoken;
    const char *key;
    struct dav_lock_indirect *next;
    time_t timeout;
}
dav_lock_indirect;

/* ################################################################# */


#define DAV_TRUE		1
#define DAV_FALSE		0

#define DAV_CREATE_LIST		23
#define DAV_APPEND_LIST		24

/* Stored lock_discovery prefix */
#define DAV_LOCK_DIRECT		1
#define DAV_LOCK_INDIRECT	2


#endif
