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

#include "ci_milter.h"
#include "firewall2.h"

#include <syslog.h>

int inspect_with_milters (char* file2inspect, char* ctype, char** filters, char** err_msg)
{
	char** flt;
	
	char **rcpt = xmalloc(sizeof(char*) * 2);
	rcpt[0] = xstrdup("unauth@gateway");
	rcpt[1] = NULL;
      	
	for (flt = filters; *flt; flt++) {
		int rc;	
	
		rc = milter_inspect_binary("ftp-gw", proxy_stats.rladdr,
				proxy_stats.riaddr,  *flt, file2inspect, "unauth@gateway",
				&rcpt, "attachment.dat", ctype ? ctype : "application/octet-stream");
		
		if (rc & MS_ER) {
			syslog(LLEV,"fwtksyserr: milter %s failed on %s", *flt, file2inspect);
	  
			if(err_msg)
				*err_msg = "Content inspection failed";

			return -1;
		}
		if (rc & MS_QU) {
			syslog(LLEV,"milter %s requested quarantine of %s", *flt, file2inspect);
	  
			if(err_msg)
				*err_msg = "Content quarantined by filter request";
	
			return -1; 
		}
		if (rc & MS_RJ) {
			if(err_msg)
				*err_msg = "Content rejected";
			
			return -1;
		}
	}
	
	return 0;
}
