piler/src/defs.h

392 lines
7.7 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
2013-05-21 11:03:03 +02:00
#ifdef NEED_PSQL
#include <libpq-fe.h>
2011-11-14 15:57:52 +01:00
#endif
#ifdef HAVE_TRE
#include <tre/tre.h>
#include <tre/regex.h>
#endif
#ifdef HAVE_LIBWRAP
#include <tcpd.h>
#endif
2011-11-14 15:57:52 +01:00
#include <openssl/sha.h>
2012-10-27 14:40:25 +02:00
#include <openssl/ssl.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_TO 3
#define MSG_CC 4
#define MSG_SUBJECT 5
#define MSG_CONTENT_TYPE 6
#define MSG_CONTENT_TRANSFER_ENCODING 7
#define MSG_CONTENT_DISPOSITION 8
#define MSG_MESSAGE_ID 9
2012-02-08 23:14:28 +01:00
#define MSG_REFERENCES 10
2012-09-03 10:06:34 +02:00
#define MSG_RECIPIENT 11
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
typedef void signal_func (int);
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];
2011-11-16 14:47:47 +01:00
char filename[TINYBUFSIZE];
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
};
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 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;
2012-08-21 21:57:39 +02:00
int writebufpos;
int abufpos;
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];
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 filename[TINYBUFSIZE];
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_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
int bodylen;
int tolen;
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
2013-05-21 11:03:03 +02:00
#ifdef NEED_PSQL
PGconn *psql;
char conninfo[SMALLBUFSIZE];
2011-11-14 15:57:52 +01:00
#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;
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;
2016-04-05 21:10:09 +02:00
int reimport;
int cap_uidplus;
2014-07-16 12:39:54 +02:00
long total_size;
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;
};
2011-11-14 15:57:52 +01:00
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;
2012-10-28 20:36:46 +01:00
#ifdef NEED_MYSQL
MYSQL_STMT *stmt_generic;
MYSQL_STMT *stmt_get_meta_id_by_message_id;
MYSQL_STMT *stmt_insert_into_rcpt_table;
MYSQL_STMT *stmt_insert_into_sphinx_table;
MYSQL_STMT *stmt_insert_into_meta_table;
MYSQL_STMT *stmt_insert_into_attachment_table;
2015-09-09 12:52:15 +02:00
MYSQL_STMT *stmt_insert_into_folder_message_table;
MYSQL_STMT *stmt_get_attachment_id_by_signature;
MYSQL_STMT *stmt_get_attachment_pointer;
MYSQL_STMT *stmt_query_attachment;
2013-01-28 13:40:44 +01:00
MYSQL_STMT *stmt_get_folder_id;
MYSQL_STMT *stmt_insert_into_folder_table;
MYSQL_STMT *stmt_update_metadata_reference;
MYSQL_STMT *stmt_update_metadata;
MYSQL_STMT *stmt_select_from_meta_table;
MYSQL_STMT *stmt_select_non_referenced_attachments;
#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;
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
2012-10-27 14:40:25 +02:00
SSL_CTX *ctx;
SSL *ssl;
2011-11-14 15:57:52 +01:00
};
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 session_ctx {
char *status;
int new_sd;
int db_conn;
int inj;
int bdat_rounds;
int bdat_last_round;
struct __config *cfg;
struct __data *data;
struct parser_state *parser_state;
struct counters *counters;
};
2011-11-14 15:57:52 +01:00
#endif /* _DEFS_H */