/*
 * Copyright (c) 1996-2007, OpenFWTK Development Group
 * All rights reserved. See LICENSE.
 */

#include <sys/param.h>
#include "firewall.h"
#include "fwstats.h"

#define SO_LNONE 0
#define SO_LCRLF 1
#define SO_LCR   2
#define SO_LLF   3

#define OP_DENY 001
#define OP_LOG  002
#define OP_AUTH 004             
#define OP_XTND 010

/*
 *	netperm-table parsing and parameters defninitions
 */

#define	FWPARM_NONE	0000	 
#define	FWPARM_INT	0001	 
#define	FWPARM_BOOL	0002
#define	FWPARM_STRING	0003
#define	FWPARM_LIST	0004
#define	FWPARM_CHAR	0005
#define	FWPARM_PORT	0006
#define	FWPARM_DSCP	0007
#define	FWPARM_OPPERMIT 0100 
#define	FWPARM_OPLOG	0100 | OP_LOG
#define	FWPARM_OPDENY	0100 | OP_DENY
#define	FWPARM_OPAUTH	0100 | OP_AUTH
#define	FWPARM_OPXTND	0100 | OP_XTND	

typedef struct {
	int	type;
	char	*name;
	char	*value;
} fwparm;

#ifndef  LIBEMFW_INCLUDED
struct hash_entry
{
  const char *name;
  int len;
  const struct hash_entry *next;
  int (*handler)();
  unsigned flags;
};

struct hash_descr
{
  const struct hash_entry *data;
  const struct hash_entry * const *hash;
  const struct hash_entry * const *by_code;
  unsigned hash_size;
};

#define HASH_IDX(name,ptr) HASH_IDX1 (name##_data, ptr)
#define HASH_IDX1(data,ptr) ((ptr) - &(data)[0])
#define HASH_IDX2(descr,ptr) HASH_IDX1 ((descr).data, ptr)

#endif /*  LIBEMFW_INCLUDED */

extern  struct fwstats proxy_stats;
extern  Cfg* proxy_confp;
extern  char proxy_name[MAX_STR];
extern  char proxy_chroot[MAXPATHLEN];
extern  int  proxy_uid;
extern  int  proxy_gid;
extern  int  proxy_timeout;
extern	int  proxy_linestyle;
extern	int  proxy_nodns;

void    proxy_exit() ATTR_NORETURN;
void    proxy_update_status();
void    proxy_update_operation(char*);
Cfg*    proxy_init();
void	addlist(char*,char***);
int     searchlist(char*,char**);
int     searchlistnc(char*,char**);
int     searchlisth(char*,char**);
void	freelist(char***);
void    proxy_get_transparent_dst(char*,unsigned int*);
int     proxy_check_dest(char**,int);
void    proxy_chroot_setugid();
void    proxy_setugid();
Cfg*	proxy_conf_hosts (Cfg*,char*,char*);
void	proxy_conf_arg_count(Cfg*,int);
int	proxy_conf_int(Cfg*,const char*,int,int,int);
char*	proxy_conf_string(Cfg*,const char*);
int	proxy_conf_userid(Cfg*);
int	proxy_conf_groupid(Cfg*);
char*   proxy_conf_chroot(Cfg*);
int	proxy_conf_timeout(Cfg*);
int	proxy_conf_diffserv_codepoint(Cfg*,char*);
void	proxy_parse_options(Cfg*,fwparm*);
void	proxy_set_dscp(int,int);
void	proxy_tunnel(int,int);
void 	sosetline(int);
time_t	sotimeout(int);
int	soread(int,char*,int);
int	sowrite(int,char*,int);
int	sogets(int,char*,int);
int	sosayn(int,char*,int);
int	sosay(int,char*);

void* xmalloc(size_t);
void* xrealloc(void*,size_t);
char* xstrndup(const char*,size_t);
char* xstrdup(const char*);
size_t strlcpy(char*,const char*,size_t);
size_t strlcat(char*,const char*,size_t);

unsigned hash2 (const char *, size_t, unsigned);
const struct hash_entry *find_he(const struct hash_entry * const *,
					  unsigned, const char *, size_t);
const struct hash_entry *find_he2 (const struct hash_descr *,
					   const char *, size_t);
struct hash_entry *find_vhe(struct hash_entry **,
					  unsigned, const char *, size_t);
struct hash_entry *find_vhe2 (struct hash_descr *,
					   const char *, size_t);

