/***********************************************************************
*
* mimedefang.h
*
* External declarations and defines.
*
* Copyright (C) 2002-2005 by Roaring Penguin Software Inc.
*
***********************************************************************/

/* $Id: mimedefang.h,v 1.29 2005/02/08 16:04:39 dfs Exp $ */

#ifndef MIMEDEFANG_H
#define MIMEDEFANG_H 1

#define SMALLBUF 8192
#define BIGBUF 65536
#include <stddef.h>

extern void chomp(char *str);
extern void write_percent_encoded(unsigned char const *str, int fd);
extern int percent_encode(unsigned char *in, unsigned char *out, int outlen);
extern void percent_decode(unsigned char *buf);

extern int MXCheckFreeSlaves(char const *sockname);
extern int MXScanDir(char const *sockname, char const *dir);
extern int MXCommand(char const *sockname, char const *cmd, char *buf, int len);
extern int MXRelayOK(char const *sockname, char *msg,
		     char const *ip, char const *name);
extern int MXSenderOK(char const *sockname, char *msg,
		      char const **sender_argv, char const *ip, char const *name,
		      char const *helo, char const *dir, char const *qid);
extern int MXRecipientOK(char const *sockname, char *msg,
			 char const **recip_argv,
			 char const *sender, char const *ip, char const *name,
			 char const *firstRecip, char const *helo,
			 char const *dir, char const *qid,
			 char const *rcpt_mailer, char const *rcpt_host,
			 char const *rcpt_addr);

extern int safeWriteHeader(int fd, unsigned char *str);
extern void split_on_space(char *buf, char **first, char **rest);
extern void split_on_space3(char *buf,
			    char **first, char **second, char **rest);
extern void split_on_space4(char *buf,
			    char **first, char **second, char **third,
			    char **rest);
extern void *malloc_with_log(size_t s);
extern char *strdup_with_log(char const *s);
extern void write_mx_command(int fd, char cmd, unsigned char const *buf);
extern int rm_r(char const *dir);
extern int writen(int fd, unsigned char const *buf, size_t len);
extern int readn(int fd, void *buf, size_t count);
extern int writestr(int fd, unsigned char const *buf);
extern int closefd(int fd);
extern int validate_smtp_code(char const *code, char const *first);
extern int validate_smtp_dsn(char const *dsn, char const *first);
extern int make_listening_socket(char const *str, int backlog, int must_be_unix);
extern int connect_to_socket(char const *str);
extern void do_delay(char const *sleepstr);

#ifdef EMBED_PERL
extern int make_embedded_interpreter(char const *progPath,
				     char const *subFilter,
				     int wantStatusReports);
extern void run_embedded_filter(void);
#endif

#endif

