ConOpSys V2970  P004.07
ANVILEX control operating system
smtp.h
Go to the documentation of this file.
1 #ifndef LWIP_HDR_APPS_SMTP_H
2 #define LWIP_HDR_APPS_SMTP_H
3 
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7 
8 #include "lwip/apps/smtp_opts.h"
9 #include "lwip/err.h"
10 #include "lwip/prot/iana.h"
11 
12 /** The default TCP port used for SMTP */
13 #define SMTP_DEFAULT_PORT LWIP_IANA_PORT_SMTP
14 /** The default TCP port used for SMTPS */
15 #define SMTPS_DEFAULT_PORT LWIP_IANA_PORT_SMTPS
16 
17 /** Email successfully sent */
18 #define SMTP_RESULT_OK 0
19 /** Unknown error */
20 #define SMTP_RESULT_ERR_UNKNOWN 1
21 /** Connection to server failed */
22 #define SMTP_RESULT_ERR_CONNECT 2
23 /** Failed to resolve server hostname */
24 #define SMTP_RESULT_ERR_HOSTNAME 3
25 /** Connection unexpectedly closed by remote server */
26 #define SMTP_RESULT_ERR_CLOSED 4
27 /** Connection timed out (server didn't respond in time) */
28 #define SMTP_RESULT_ERR_TIMEOUT 5
29 /** Server responded with an unknown response code */
30 #define SMTP_RESULT_ERR_SVR_RESP 6
31 /** Out of resources locally */
32 #define SMTP_RESULT_ERR_MEM 7
33 
34 /** Prototype of an smtp callback function
35  *
36  * @param arg argument specified when initiating the email
37  * @param smtp_result result of the mail transfer (see defines SMTP_RESULT_*)
38  * @param srv_err if aborted by the server, this contains the error code received
39  * @param err an error returned by internal lwip functions, can help to specify
40  * the source of the error but must not necessarily be != ERR_OK
41  */
42 typedef void (*smtp_result_fn)(void *arg, u8_t smtp_result, u16_t srv_err, err_t err);
43 
44 /** This structure is used as argument for smtp_send_mail_int(),
45  * which in turn can be used with tcpip_callback() to send mail
46  * from interrupt context, e.g. like this:
47  * struct smtp_send_request *req; (to be filled)
48  * tcpip_try_callback(smtp_send_mail_int, (void*)req);
49  *
50  * For member description, see parameter description of smtp_send_mail().
51  * When using with tcpip_callback, this structure has to stay allocated
52  * (e.g. using mem_malloc/mem_free) until its 'callback_fn' is called.
53  */
55  const char *from;
56  const char* to;
57  const char* subject;
58  const char* body;
60  void* callback_arg;
61  /** If this is != 0, data is *not* copied into an extra buffer
62  * but used from the pointers supplied in this struct.
63  * This means less memory usage, but data must stay untouched until
64  * the callback function is called. */
66 };
67 
68 
69 #if SMTP_BODYDH
70 
71 #ifndef SMTP_BODYDH_BUFFER_SIZE
72 #define SMTP_BODYDH_BUFFER_SIZE 256
73 #endif /* SMTP_BODYDH_BUFFER_SIZE */
74 
75 struct smtp_bodydh {
76  u16_t state;
77  u16_t length; /* Length of content in buffer */
78  char buffer[SMTP_BODYDH_BUFFER_SIZE]; /* buffer for generated content */
79 #ifdef SMTP_BODYDH_USER_SIZE
80  u8_t user[SMTP_BODYDH_USER_SIZE];
81 #endif /* SMTP_BODYDH_USER_SIZE */
82 };
83 
84 enum bdh_retvals_e {
85  BDH_DONE = 0,
86  BDH_WORKING
87 };
88 
89 /** Prototype of an smtp body callback function
90  * It receives a struct smtp_bodydh, and a buffer to write data,
91  * must return BDH_WORKING to be called again and BDH_DONE when
92  * it has finished processing. This one tries to fill one TCP buffer with
93  * data, your function will be repeatedly called until that happens; so if you
94  * know you'll be taking too long to serve your request, pause once in a while
95  * by writing length=0 to avoid hogging system resources
96  *
97  * @param arg argument specified when initiating the email
98  * @param smtp_bodydh state handling + buffer structure
99  */
100 typedef int (*smtp_bodycback_fn)(void *arg, struct smtp_bodydh *bodydh);
101 
102 err_t smtp_send_mail_bodycback(const char *from, const char* to, const char* subject,
103  smtp_bodycback_fn bodycback_fn, smtp_result_fn callback_fn, void* callback_arg);
104 
105 #endif /* SMTP_BODYDH */
106 
107 
108 err_t smtp_set_server_addr(const char* server);
110 #if LWIP_ALTCP && LWIP_ALTCP_TLS
111 struct altcp_tls_config;
112 void smtp_set_tls_config(struct altcp_tls_config *tls_config);
113 #endif
114 err_t smtp_set_auth(const char* username, const char* pass);
115 err_t smtp_send_mail(const char *from, const char* to, const char* subject, const char* body,
116  smtp_result_fn callback_fn, void* callback_arg);
117 err_t smtp_send_mail_static(const char *from, const char* to, const char* subject, const char* body,
118  smtp_result_fn callback_fn, void* callback_arg);
119 void smtp_send_mail_int(void *arg);
120 #ifdef LWIP_DEBUG
121 const char* smtp_result_str(u8_t smtp_result);
122 #endif
123 
124 #ifdef __cplusplus
125 }
126 #endif
127 
128 #endif /* LWIP_HDR_APPS_SMTP_H */
uint8_t u8_t
Definition: arch.h:125
uint16_t u16_t
Definition: arch.h:127
s8_t err_t
Definition: err.h:96
err_t smtp_send_mail_static(const char *from, const char *to, const char *subject, const char *body, smtp_result_fn callback_fn, void *callback_arg)
err_t smtp_set_server_addr(const char *server)
void smtp_set_server_port(u16_t port)
err_t smtp_set_auth(const char *username, const char *pass)
void(* smtp_result_fn)(void *arg, u8_t smtp_result, u16_t srv_err, err_t err)
Definition: smtp.h:42
void smtp_send_mail_int(void *arg)
err_t smtp_send_mail(const char *from, const char *to, const char *subject, const char *body, smtp_result_fn callback_fn, void *callback_arg)
Definition: smtp.h:54
smtp_result_fn callback_fn
Definition: smtp.h:59
const char * body
Definition: smtp.h:58
const char * to
Definition: smtp.h:56
const char * from
Definition: smtp.h:55
u8_t static_data
Definition: smtp.h:65
void * callback_arg
Definition: smtp.h:60
const char * subject
Definition: smtp.h:57