aboutsummaryrefslogtreecommitdiff
path: root/utilities.h
blob: 23044cae0f643c14f89a5ce21c08a350590f8428 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#ifndef UTILITIES_H
#define UTILITIES_H

#include <stdbool.h>
#include <stdio.h>

#ifdef __cplusplus
#include "vmime/vmime.hpp"

vmime::shared_ptr<vmime::security::cert::defaultCertificateVerifier>
windows_root_certs_verifier(void);

extern "C" {
#endif

enum bool_param {
	PARAM_NO,
	PARAM_YES,
	PARAM_NOT_GIVEN
};

struct config {
	const char *host;
	const char *login;
	const char *password;
	const char *subject;
	const char *reply_to;
	const char *from;
	const char *dest_dir;
	const char **files;
	size_t nfiles;
	const char *msg_body;
	size_t msg_size;
	const char **to;
	size_t nto;
	int port_POP3;
	int port_SMTP;
	enum bool_param use_SSL;
	enum bool_param use_AUTH;
	int timeout;
	enum bool_param del_msgs;
	enum bool_param save_body;
	enum bool_param save_subj;
};

void _finish(bool ok);
#define PRINT_ERROR(message...) \
  ((fprintf(stderr, message) && false) || fprintf(stderr, "\r\n"))
#define FAIL(message...) _finish(PRINT_ERROR(message) && false)
#define FAIL_NOMSG() _finish(false)
#define SUCCEED() _finish(true)

void *dirtyalloc(size_t size);

void read_config(const char *filename, struct config *config);

void get_config(int argc, const char **argv, struct config *config);

int dummy_errback(const char *fmt, ...);

int provisional_wide_char_fgetc(FILE *stream);

bool is_valid_port_number(int port);

void free_config(struct config *config);

void validate_config(struct config *config);

void perform_work(const struct config *config);

inline static bool is_empty_string(const char *string)
{
	return string == NULL || *string == '\0';
}

#define MESSAGES_EXTERN
#include "messages.c"

#ifdef __cplusplus
}
#endif

#endif /* UTILITIES_H */