-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmmcomm.h
131 lines (101 loc) · 4.43 KB
/
mmcomm.h
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#ifndef MMCOMM_H
#define MMCOMM_H
#include <sys/types.h>
#include <sys/socket.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#include <openssl/conf.h>
#include <openssl/bio.h>
#include <readini.h>
#include "socktalk.h"
// Prototype to make available for function pointer typedefs
typedef struct bundle Bundle;
/* Typedefs of callback function pointers: */
typedef void(*StrVal)(const char *val);
typedef void(*CB_SSL)(SSL *ssl, Bundle *p_bundle);
typedef void(*CB_Socket)(int handle_socket, Bundle *p_bundle);
typedef void(*CB_Talker)(STalker *talker, Bundle *p_bundle);
typedef struct _mc_mail
{
const char *To;
const char *From;
const char *Subject;
const char *Reply_To;
const char *CC;
const char *BCC;
const char *message;
} MC_Mail;
typedef int(*Email_Tap)(MC_Mail *mail, void *data);
typedef struct bundle
{
const ri_Section *section;
const char *acct;
const Status_Line *host_status_chain;
const char* raw_login;
const char* encoded_login;
const char* raw_password;
const char* encoded_password;
CB_Socket socket_user;
CB_Talker talker_user;
Email_Tap email_tap;
void *email_data;
} Bundle;
/** Shortcut functions to extract configuration data from the bundle. */
const char *bundle_value(const Bundle *b, const char *section, const char *tag);
const char *acct_value(const Bundle *b, const char *tag);
/**
* Returns the reply status value ONLY if the first three
* characters are numerals followed by a space or a hypen.
**/
int get_reply_int(const char *buffer);
/** Boolean function to confirm successful reply. */
int reply_is_good(char *buffer);
/** Also returns 1 or 0 for success or failure, but also prints a message to stderr. */
int reply_is_good_stderr(char *buffer, int message_length, const char *description);
/** Specifically processes authorization reply messages. */
int reply_auth_is_good_stderr(char *buffer, int message_length, const char *description);
/** Locate the configuration file, searching several places. */
const char *find_config(void);
/** Debugging function to convert an integer SSL error to a string. */
void present_ssl_error(int connect_error);
/**
* Beginning of functions that establish the SMTP connection:
*/
/** Construct and submit an email envelope (MAIL FROM and RCPT TO fields). */
int prepare_email_envelope(STalker *talker, const char *to, const char *from);
/** Send base46-encoded login and password to server and return success. */
int check_authentication(STalker *talker, Bundle *p_bundle);
/** Work-in-progress function to end up while testing SMTP connection. */
void use_talker_for_email(STalker *talker, Bundle *p_bundle);
/** Initialize SSL session with an already-open socket. */
void start_ssl(int socket_handle, Bundle *p_bundle);
/** First action after opening a socket. Begins negotiation for connection type. */
void use_socket_for_email(int socket_handle, Bundle *p_bundle);
/** Create a socket that is the passed to the socket_user function in bundle. */
void get_socket(const char *url, const char *service, Bundle *p_bundle);
/** Callback function that consumes settings in a configuration file to call get_socket(). */
void use_config_file(const ri_Section *section, void *data);
/**
* The order of function invocation is the reverse of the above functions:
* 1. Call config reader (library function), which calls ...
* 2. use_config_file() to determine socket address, which calls ...
* 3. get_socket(), which opens a socket at an address and port,
* and upon success, builds a STalker object to communicate
* with the server, continues by invoking a function pointer
* in Bundle, `socket_user`, which currently is ...
* 4. use_socket_for_email(), calls the SMTP server with EHLO to
* determine requirements and capabilities. After this,
* processing ultimately continues by calling the `talker_user`
* function pointer in Bundle, either with a pass through
* start_ssl(), or directly calling the function pointer
* with the already-established STalker that uses the socket
* directly.
* 5. start_ssl(), if necessary, starts a TLS session and builds
* a new STalker object to communicate with the server,
* continuing to ...
* 6. use_talker_for_email() for now, but this may change with
* continued development. It calls check_authentication()
* to login and send_email_header() to begin a canned email
* transaction.
*/
#endif