/***************************************************************************
 *
 * Copyright (c) 2000, 2001 BalaBit IT Ltd, Budapest, Hungary
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * $Id: policy.h,v 1.11.2.1.2.3 2001/09/19 19:22:17 bazsi Exp $
 *
 ***************************************************************************/

#ifndef ZORP_POLICY_H_INCLUDED
#define ZORP_POLICY_H_INCLUDED

#include <zorp/zpython.h>

gboolean z_python_policy_init(void);
void z_policy_destroy(void);
gboolean z_policy_read(char *file);
gboolean z_policy_init();
void z_policy_lock(ZPolicyThread *thread);
void z_policy_unlock(ZPolicyThread *thread);

#define Z_UNSPEC     0 /* policy doesn't specify it, do something sensible */
#define Z_OK         1 /* continue & allow */
#define Z_ACCEPT     1
#define Z_DENY       2 /* continue and don't do it */
#define Z_REJECT     3 /* continue and tell the client that we didn't do it */
#define Z_ABORT      4 /* abort the connection */
#define Z_DROP       5

#define z_policy_none Py_None

#define z_policy_var_build(format, args...) Py_BuildValue(format, ##args)
#define z_policy_var_parse(v, format, args...) PyArg_Parse(v, format, ##args)
#define z_policy_var_parse_tuple(v, format, args...) PyArg_ParseTuple(v, format, ##args)
#define z_policy_var_str(v) PyObject_Str(v)
#define z_policy_var_ref(v)   Py_XINCREF(v)
#define z_policy_var_unref(v) Py_XDECREF(v)

#define z_policy_seq_check(v) PySequence_Check(v)
#define z_policy_seq_new(s) PyTuple_New(s)
#define z_policy_seq_getitem(v, i) PySequence_GetItem(v, i)
#define z_policy_seq_setitem(v, i, x) PySequence_SetItem(v, i, x)
#define z_policy_seq_length(v) PyObject_Length(v)

#define z_policy_str_check(v) PyString_Check(v)
#define z_policy_str_as_string(v) PyString_AsString(v)

ZPolicyObj *z_policy_call(ZPolicyObj *handler, char *name, ZPolicyObj *args, gboolean *called);
int z_policy_event(ZPolicyObj *handler, char *name, ZPolicyObj *args);
PyObject *z_policy_call_object(PyObject *func, PyObject *args);
gint z_policy_setattr(ZPolicyObj *handler, char *name, ZPolicyObj *value);
ZPolicyObj *z_policy_getattr(ZPolicyObj *handler, char *name);
PyObject *z_session_getattr(PyObject *handler, char *name);

#define z_zorp_sockaddr_new z_py_zorp_sockaddr_new

#endif
