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