piler/src/defs.h

426 lines
8.0 KiB
C
Raw Normal View History

2011-11-14 15:57:52 +01:00
/*
* defs.h, SJ
*/
#ifndef _DEFS_H
#define _DEFS_H
#ifdef NEED_MYSQL
#include <mysql.h>
2014-07-10 11:54:37 +02:00
#include <mysqld_error.h>
2011-11-14 15:57:52 +01:00
#endif
#ifdef HAVE_TRE
#include <tre/tre.h>
#include <tre/regex.h>
#endif
#include <openssl/sha.h>
2012-10-27 14:40:25 +02:00
#include <openssl/ssl.h>
#include <netinet/in.h>
#include "tai.h"
2011-11-14 15:57:52 +01:00
#include "config.h"
#define MSG_UNDEF -1
#define MSG_BODY 0
#define MSG_RECEIVED 1
#define MSG_FROM 2
#define MSG_SENDER 3
#define MSG_TO 4
#define MSG_CC 5
#define MSG_SUBJECT 6
#define MSG_CONTENT_TYPE 7
#define MSG_CONTENT_TRANSFER_ENCODING 8
#define MSG_CONTENT_DISPOSITION 9
#define MSG_MESSAGE_ID 10
#define MSG_REFERENCES 11
#define MSG_RECIPIENT 12
#define MSG_ENVELOPE_TO 13
2011-11-14 15:57:52 +01:00
#define MAXHASH 277
2011-11-14 15:57:52 +01:00
#define BASE64_RATIO 1.33333333
#define DIGEST_LENGTH SHA256_DIGEST_LENGTH
#define UNDEF 0
#define READY 1
#define BUSY 2
#define MAX_SQL_VARS 20
#define TYPE_UNDEF 0
2013-05-15 11:52:41 +02:00
#define TYPE_SHORT 1
#define TYPE_LONG 2
#define TYPE_LONGLONG 3
#define TYPE_STRING 4
#define MAXCHILDREN 64
2014-05-12 01:05:44 +02:00
#define RULE_UNDEF 0
#define RULE_MATCH 1
#define RULE_NO_MATCH -100
struct child {
pid_t pid;
int serial;
int messages;
int status;
};
2011-11-14 15:57:52 +01:00
struct attachment {
int size;
2011-11-16 14:47:47 +01:00
char type[TINYBUFSIZE];
char shorttype[TINYBUFSIZE];
2012-09-07 15:08:50 +02:00
char aname[TINYBUFSIZE];
char filename[SMALLBUFSIZE];
2011-11-19 21:25:44 +01:00
char internalname[TINYBUFSIZE];
char digest[2*DIGEST_LENGTH+1];
2012-09-07 15:08:50 +02:00
char dumped;
2011-11-14 15:57:52 +01:00
};
2011-11-19 21:25:44 +01:00
struct ptr_array {
uint64 ptr;
char piler_id[RND_STR_LEN+2];
int attachment_id;
};
struct node {
void *str;
unsigned int key;
struct node *r;
2011-11-14 15:57:52 +01:00
};
struct smtp_acl {
char network_str[BUFLEN];
in_addr_t low, high;
int prefix;
int rejected;
struct smtp_acl *r;
};
struct net {
int socket;
int use_ssl;
int starttls;
int timeout;
SSL_CTX *ctx;
SSL *ssl;
};
2011-11-19 21:25:44 +01:00
struct rule {
#ifdef HAVE_TRE
regex_t from;
regex_t to;
regex_t subject;
2015-03-11 12:54:31 +01:00
regex_t body;
regex_t attachment_name;
2011-11-23 12:24:21 +01:00
regex_t attachment_type;
2011-11-19 21:25:44 +01:00
#endif
2012-02-19 22:59:47 +01:00
int spam;
2011-11-19 21:25:44 +01:00
int size;
char _size[4];
2011-11-23 12:24:21 +01:00
int attachment_size;
char _attachment_size[4];
2013-07-31 09:10:26 +02:00
char *domain;
int domainlen;
2012-02-19 22:59:47 +01:00
int days;
int folder_id;
2012-02-19 22:59:47 +01:00
2015-03-11 12:54:31 +01:00
char emptyfrom, emptyto, emptysubject, emptybody, emptyaname, emptyatype;
2014-06-30 14:44:33 +02:00
2011-11-19 21:25:44 +01:00
char *rulestr;
char compiled;
2012-02-19 22:59:47 +01:00
2011-11-19 21:25:44 +01:00
struct rule *r;
};
struct rule_cond {
char domain[SMALLBUFSIZE];
char from[SMALLBUFSIZE];
char to[SMALLBUFSIZE];
char subject[SMALLBUFSIZE];
char body[SMALLBUFSIZE];
char _size[SMALLBUFSIZE];
char attachment_name[SMALLBUFSIZE];
char attachment_type[SMALLBUFSIZE];
char _attachment_size[SMALLBUFSIZE];
int size, attachment_size, spam, days, folder_id;
};
2015-11-21 23:06:47 +01:00
struct parser_state {
2011-11-16 14:47:47 +01:00
int line_num;
2011-11-14 15:57:52 +01:00
int message_state;
int is_header;
2011-11-22 12:31:54 +01:00
int is_1st_header;
2011-11-14 15:57:52 +01:00
int textplain;
int texthtml;
int message_rfc822;
int base64;
int utf8;
int qp;
int htmltag;
int style;
int skip_html;
int has_to_dump;
int has_to_dump_whole_body;
2011-11-14 15:57:52 +01:00
int fd;
2012-09-07 15:08:50 +02:00
int b64fd;
2011-11-19 21:25:44 +01:00
int mfd;
2011-11-16 14:47:47 +01:00
int octetstream;
2011-11-14 15:57:52 +01:00
int realbinary;
int content_type_is_set;
2011-11-19 21:25:44 +01:00
int pushed_pointer;
int saved_size;
unsigned int writebufpos;
unsigned int abufpos;
unsigned int received_header;
2011-11-14 15:57:52 +01:00
char attachedfile[RND_STR_LEN+SMALLBUFSIZE];
char message_id[SMALLBUFSIZE];
2014-04-25 21:17:01 +02:00
char message_id_hash[2*DIGEST_LENGTH+1];
2011-11-16 14:47:47 +01:00
char miscbuf[MAX_TOKEN_LEN];
2011-12-07 15:24:52 +01:00
char qpbuf[MAX_TOKEN_LEN];
char receivedbuf[SMALLBUFSIZE];
2011-11-14 15:57:52 +01:00
unsigned long n_token;
unsigned long n_subject_token;
unsigned long n_body_token;
unsigned long n_chain_token;
2011-11-22 12:31:54 +01:00
char type[TINYBUFSIZE];
2014-08-30 21:10:29 +02:00
char charset[TINYBUFSIZE];
2011-11-22 12:31:54 +01:00
char attachment_name_buf[SMALLBUFSIZE];
int anamepos;
struct node *boundaries[MAXHASH];
struct node *rcpt[MAXHASH];
struct node *rcpt_domain[MAXHASH];
struct node *journal_recipient[MAXHASH];
2011-11-14 15:57:52 +01:00
int n_attachments;
struct attachment attachments[MAX_ATTACHMENTS];
2012-02-08 23:14:28 +01:00
char reference[SMALLBUFSIZE];
char b_from[SMALLBUFSIZE], b_from_domain[SMALLBUFSIZE], b_sender[SMALLBUFSIZE], b_sender_domain[SMALLBUFSIZE], b_to[MAXBUFSIZE], b_to_domain[SMALLBUFSIZE], b_subject[MAXBUFSIZE], b_body[BIGBUFSIZE];
char b_journal_to[MAXBUFSIZE];
2012-08-21 21:57:39 +02:00
unsigned int bodylen;
unsigned int tolen;
unsigned int todomainlen;
unsigned int found_security_header;
int journaltolen;
2013-07-31 10:06:05 +02:00
int retention;
2011-11-14 15:57:52 +01:00
};
struct session_data {
char filename[SMALLBUFSIZE];
2011-12-13 17:05:22 +01:00
char ttmpfile[SMALLBUFSIZE], tmpframe[SMALLBUFSIZE], tre, restored_copy;
2011-11-14 15:57:52 +01:00
char mailfrom[SMALLBUFSIZE], rcptto[MAX_RCPT_TO][SMALLBUFSIZE], client_addr[SMALLBUFSIZE];
char fromemail[SMALLBUFSIZE];
2011-11-14 15:57:52 +01:00
char acceptbuf[SMALLBUFSIZE];
2011-12-30 15:52:59 +01:00
char attachments[SMALLBUFSIZE];
char internal_sender, internal_recipient, external_recipient;
uint64 duplicate_id;
2013-05-15 11:46:08 +02:00
short int customer_id;
int direction;
2012-10-28 20:36:46 +01:00
int tls;
2012-01-26 14:35:51 +01:00
int spam_message;
2014-05-05 16:00:33 +02:00
int fd, hdr_len, tot_len, stored_len, num_of_rcpt_to, rav;
2011-11-14 15:57:52 +01:00
int need_scan;
float __acquire, __parsed, __av, __store, __compress, __encrypt;
char bodydigest[2*DIGEST_LENGTH+1];
2011-11-22 12:31:54 +01:00
char digest[2*DIGEST_LENGTH+1];
2015-11-02 15:14:52 +01:00
time_t now, sent, delivered, retained;
2013-01-27 21:43:42 +01:00
char ms_journal;
2014-01-13 13:06:10 +01:00
char import;
2012-09-28 21:48:20 +02:00
int journal_envelope_length, journal_bottom_length;
2014-07-10 11:54:37 +02:00
unsigned int sql_errno;
2011-11-14 15:57:52 +01:00
#ifdef NEED_MYSQL
MYSQL mysql;
#endif
};
#ifdef HAVE_MEMCACHED
#include <stdbool.h>
#include <netinet/in.h>
struct flags {
bool no_block:1;
bool no_reply:1;
bool tcp_nodelay:1;
bool tcp_keepalive:1;
};
struct memcached_server {
struct flags flags;
int fd;
unsigned int snd_timeout;
unsigned int rcv_timeout;
int send_size;
int recv_size;
unsigned int tcp_keepidle;
int last_read_bytes;
char *result;
char buf[MAXBUFSIZE];
struct sockaddr_in addr;
char server_ip[IPLEN];
2011-11-14 15:57:52 +01:00
int server_port;
char initialised;
};
#endif
2013-08-23 13:02:51 +02:00
struct import {
2014-06-04 22:20:10 +02:00
char *extra_recipient;
char *move_folder;
char *failed_folder;
2013-08-23 13:02:51 +02:00
int status;
int total_messages;
int processed_messages;
int batch_processing_limit;
int start_position;
2013-08-23 13:02:51 +02:00
int import_job_id;
int remove_after_import;
2014-10-15 23:22:36 +02:00
int download_only;
int keep_eml;
int timeout;
int cap_uidplus;
int fd;
2014-07-16 12:39:54 +02:00
long total_size;
int dryrun;
int tot_msgs;
int port;
int seq;
int table_id;
int delay;
char *server;
char *username;
char *password;
char *database;
char *skiplist;
char *folder_imap;
char *folder_name;
char *mboxdir;
char *folder;
char filename[SMALLBUFSIZE];
2013-08-23 13:02:51 +02:00
time_t started, updated, finished;
};
2015-12-09 21:19:14 +01:00
struct licence {
char customer[TINYBUFSIZE];
char hostname[TINYBUFSIZE];
char ip[TINYBUFSIZE];
time_t expiry;
int licenced_users;
};
struct data {
2013-09-27 14:33:15 +02:00
int folder, quiet;
2012-09-03 10:06:34 +02:00
char recursive_folder_names;
2012-10-28 20:36:46 +01:00
char starttls[TINYBUFSIZE];
struct node *mydomains[MAXHASH];
2013-09-04 22:42:06 +02:00
struct node *imapfolders[MAXHASH];
2013-08-23 13:02:51 +02:00
struct import *import;
2015-12-09 21:19:14 +01:00
struct licence licence;
char *dedup;
int child_serial;
int pos;
2011-11-14 15:57:52 +01:00
#ifdef HAVE_TRE
struct node *archiving_rules[1];
struct node *retention_rules[1];
struct node *folder_rules[1];
2011-11-14 15:57:52 +01:00
#endif
#ifdef HAVE_MEMCACHED
struct memcached_server memc;
#endif
struct net *net;
2011-11-14 15:57:52 +01:00
};
#if !defined(MARIADB_BASE_VERSION) && !defined(MARIADB_VERSION_ID) && \
MYSQL_VERSION_ID >= 80001 && MYSQL_VERSION_ID != 80002
typedef bool my_bool;
#endif
struct sql {
#ifdef NEED_MYSQL
MYSQL_STMT *stmt;
#endif
char *sql[MAX_SQL_VARS];
int type[MAX_SQL_VARS];
int len[MAX_SQL_VARS];
unsigned long length[MAX_SQL_VARS];
my_bool is_null[MAX_SQL_VARS];
my_bool error[MAX_SQL_VARS];
int pos;
};
struct counters {
2011-11-14 15:57:52 +01:00
unsigned long long c_rcvd;
unsigned long long c_virus;
unsigned long long c_duplicate;
2011-12-27 20:51:56 +01:00
unsigned long long c_ignore;
2012-02-10 13:57:04 +01:00
unsigned long long c_size;
2014-05-05 15:26:42 +02:00
unsigned long long c_stored_size;
2011-11-14 15:57:52 +01:00
};
struct smtp_session {
char ttmpfile[SMALLBUFSIZE];
char mailfrom[SMALLBUFSIZE];
char rcptto[MAX_RCPT_TO][SMALLBUFSIZE];
char buf[MAXBUFSIZE];
char remote_host[INET6_ADDRSTRLEN+1];
char nullbyte;
time_t lasttime;
int protocol_state;
int slot;
int fd;
int bad;
int buflen;
int last_data_char;
int tot_len;
int bdat_bytes_to_read;
int num_of_rcpt_to;
struct config *cfg;
struct net net;
};
struct tls_protocol {
char *proto;
int version;
};
2011-11-14 15:57:52 +01:00
#endif /* _DEFS_H */