/***************************************************************************
 *
 * 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: ctrack.h,v 1.9.2.3 2001/09/19 19:22:17 bazsi Exp $
 *
 ***************************************************************************/

#ifndef ZORP_CTRACK_H_INCLUDED
#define ZORP_CTRACK_H_INCLUDED

#include <zorp/sockaddr.h>
#include <zorp/stream.h>
#include <zorp/ctrouter.h>
#include <zorp/zpython.h>
#include <zorp/packsock.h>

struct _ZProxy;

struct _ZCProxy;

#define MAX_SESSION_ID          64

#define MAX_POOL_KEYSIZE        128

typedef void (*ZConntrackKeygen)(struct _ZCProxy *self, ZPacket *packet,
                                                gchar *key, guint maxsize);
typedef struct _ZCProxy
{
  gchar session_id[MAX_SESSION_ID];
  int flags;
  ZPolicyObj *handler;
  ZPolicyThread *thread;
  GHashTable *vars;
        
  ZPolicyObj *(*getattr)(struct _ZProxy *self, char *name);
  gint (*setattr)(struct _ZProxy *self, char *name, ZPolicyObj *value);
  void (*free)(struct _ZProxy *);

  void (*callback)(gpointer, ZPacket *);
  gpointer user_data;
  void (*config)(struct _ZCProxy *);

  GHashTable *proxypool;
  GHashTable *trackpool;
  GList *timer;
  gint timeout;
  gint max_packet;
  
  guint way;
  
  gint sender_fd;

  ZCTRouter *router;
  struct _ZCProxy *other;
  
  gboolean srcip;
  gboolean srcport;
  gboolean dstip;
  gboolean dstport;
  gboolean sess;
  
  void (*keygen)(struct _ZCProxy *self, ZPacket *packet,
                                           gchar *key, guint maxsize);
} ZCProxy;

typedef ZCProxy *(*ZDTrackerCreateFunc)(ZPolicyObj *handler, ZCTRouter *router);

typedef void (*ZCKeygen)(ZCProxy *self, ZPacket *packet,
                         gchar *key, guint keylength);

void z_tracker_init(ZCProxy *self, ZPolicyObj *handler, ZCTRouter *router);

gboolean z_tracker_config_event(ZCProxy *self);

void z_tracker_tune(ZCProxy *self, ZCProxy *other, ZCKeygen keygen);

void z_tracker_sender_init(ZCProxy *self, ZCProxy *old);

void z_tracker_read(ZCProxy *self, ZPacket *packet, int fd);

gchar *z_tracker_write(ZCProxy *self, ZPacket *packet,
                                  struct _ZProxy *proxy, gchar *key, gpointer session);

void z_tracker_drop(ZCProxy *self, ZPacket *packet);

gboolean z_tracker_connect_server(ZCProxy *self, ZorpCHeader *header);

void z_tracker_stop_session(ZCProxy *self, gchar *key);

#endif
