mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2025-01-26 09:35:23 +00:00
Create smtp_opts.h and add SMTP client to doxygen docs
This commit is contained in:
parent
f7ac739022
commit
9b6192bd65
@ -4,48 +4,58 @@
|
|||||||
*
|
*
|
||||||
* Author: Simon Goldschmidt
|
* Author: Simon Goldschmidt
|
||||||
*
|
*
|
||||||
|
* @defgroup smtp SMTP client
|
||||||
|
* @ingroup apps
|
||||||
|
*
|
||||||
|
* This is simple SMTP client for raw API.
|
||||||
|
* It is a minimal implementation of SMTP as specified in RFC 5321.
|
||||||
|
*
|
||||||
* Example usage:
|
* Example usage:
|
||||||
*
|
@code{.c}
|
||||||
* void my_smtp_result_fn(void *arg, u8_t smtp_result, u16_t srv_err, err_t err)
|
void my_smtp_result_fn(void *arg, u8_t smtp_result, u16_t srv_err, err_t err)
|
||||||
* {
|
{
|
||||||
* printf("mail (%p) sent with results: 0x%02x, 0x%04x, 0x%08x\n", arg,
|
printf("mail (%p) sent with results: 0x%02x, 0x%04x, 0x%08x\n", arg,
|
||||||
* smtp_result, srv_err, err);
|
smtp_result, srv_err, err);
|
||||||
* }
|
}
|
||||||
* static void my_smtp_test(void)
|
static void my_smtp_test(void)
|
||||||
* {
|
{
|
||||||
* smtp_set_server_addr("mymailserver.org");
|
smtp_set_server_addr("mymailserver.org");
|
||||||
* -> set both username and password as NULL if no auth needed
|
-> set both username and password as NULL if no auth needed
|
||||||
* smtp_set_auth("username", "password");
|
smtp_set_auth("username", "password");
|
||||||
* smtp_send_mail("sender", "recipient", "subject", "body", my_smtp_result_fn,
|
smtp_send_mail("sender", "recipient", "subject", "body", my_smtp_result_fn,
|
||||||
* some_argument);
|
some_argument);
|
||||||
* }
|
}
|
||||||
*
|
@endcode
|
||||||
|
|
||||||
* When using from any other thread than the tcpip_thread (for NO_SYS==0), use
|
* When using from any other thread than the tcpip_thread (for NO_SYS==0), use
|
||||||
* smtp_send_mail_int()!
|
* smtp_send_mail_int()!
|
||||||
*
|
*
|
||||||
*
|
|
||||||
* SMTP_BODYDH usage:
|
* SMTP_BODYDH usage:
|
||||||
|
@code{.c}
|
||||||
|
int my_smtp_bodydh_fn(void *arg, struct smtp_bodydh *bdh)
|
||||||
|
{
|
||||||
|
if(bdh->state >= 10) {
|
||||||
|
return BDH_DONE;
|
||||||
|
}
|
||||||
|
sprintf(bdh->buffer,"Line #%2d\r\n",bdh->state);
|
||||||
|
bdh->length = strlen(bdh->buffer);
|
||||||
|
++bdh->state;
|
||||||
|
return BDH_WORKING;
|
||||||
|
}
|
||||||
|
|
||||||
|
smtp_send_mail_bodycback("sender", "recipient", "subject",
|
||||||
|
my_smtp_bodydh_fn, my_smtp_result_fn, some_argument);
|
||||||
|
@endcode
|
||||||
*
|
*
|
||||||
* int my_smtp_bodydh_fn(void *arg, struct smtp_bodydh *bdh)
|
* @todo:
|
||||||
* {
|
* - attachments (the main difficulty here is streaming base64-encoding to
|
||||||
* if(bdh->state >= 10) {
|
* prevent having to allocate a buffer for the whole encoded file at once)
|
||||||
* return BDH_DONE;
|
* - test with more mail servers...
|
||||||
* }
|
*
|
||||||
* sprintf(bdh->buffer,"Line #%2d\r\n",bdh->state);
|
|
||||||
* bdh->length = strlen(bdh->buffer);
|
|
||||||
* ++bdh->state;
|
|
||||||
* return BDH_WORKING;
|
|
||||||
* }
|
|
||||||
*
|
|
||||||
* smtp_send_mail_bodycback("sender", "recipient", "subject",
|
|
||||||
* my_smtp_bodydh_fn, my_smtp_result_fn, some_argument);
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "lwip/apps/smtp.h"
|
#include "lwip/apps/smtp.h"
|
||||||
|
|
||||||
#include "lwip/opt.h"
|
|
||||||
|
|
||||||
#if LWIP_TCP && LWIP_CALLBACK_API
|
#if LWIP_TCP && LWIP_CALLBACK_API
|
||||||
#include "lwip/sys.h"
|
#include "lwip/sys.h"
|
||||||
#include "lwip/sockets.h"
|
#include "lwip/sockets.h"
|
||||||
@ -58,61 +68,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
/** This is simple SMTP client for raw API.
|
|
||||||
* It is a minimal implementation of SMTP as specified in RFC 5321.
|
|
||||||
*
|
|
||||||
* @todo:
|
|
||||||
* - attachments (the main difficulty here is streaming base64-encoding to
|
|
||||||
* prevent having to allocate a buffer for the whole encoded file at once)
|
|
||||||
* - test with more mail servers...
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SMTP_DEBUG: Enable debugging for SNTP.
|
|
||||||
*/
|
|
||||||
#ifndef SMTP_DEBUG
|
|
||||||
#define SMTP_DEBUG LWIP_DBG_OFF
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** Maximum length reserved for server name */
|
|
||||||
#ifndef SMTP_MAX_SERVERNAME_LEN
|
|
||||||
#define SMTP_MAX_SERVERNAME_LEN 256
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** Maximum length reserved for username */
|
|
||||||
#ifndef SMTP_MAX_USERNAME_LEN
|
|
||||||
#define SMTP_MAX_USERNAME_LEN 32
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** Maximum length reserved for password */
|
|
||||||
#ifndef SMTP_MAX_PASS_LEN
|
|
||||||
#define SMTP_MAX_PASS_LEN 32
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** Set this to 0 if you know the authentication data will not change
|
|
||||||
* during the smtp session, which saves some heap space. */
|
|
||||||
#ifndef SMTP_COPY_AUTHDATA
|
|
||||||
#define SMTP_COPY_AUTHDATA 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** Set this to 0 to save some code space if you know for sure that all data
|
|
||||||
* passed to this module conforms to the requirements in the SMTP RFC.
|
|
||||||
* WARNING: use this with care!
|
|
||||||
*/
|
|
||||||
#ifndef SMTP_CHECK_DATA
|
|
||||||
#define SMTP_CHECK_DATA 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** Set this to 1 to enable AUTH PLAIN support */
|
|
||||||
#ifndef SMTP_SUPPORT_AUTH_PLAIN
|
|
||||||
#define SMTP_SUPPORT_AUTH_PLAIN 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** Set this to 1 to enable AUTH LOGIN support */
|
|
||||||
#ifndef SMTP_SUPPORT_AUTH_LOGIN
|
|
||||||
#define SMTP_SUPPORT_AUTH_LOGIN 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** TCP poll interval. Unit is 0.5 sec. */
|
/** TCP poll interval. Unit is 0.5 sec. */
|
||||||
#define SMTP_POLL_INTERVAL 4
|
#define SMTP_POLL_INTERVAL 4
|
||||||
/** TCP poll timeout while sending message body, reset after every
|
/** TCP poll timeout while sending message body, reset after every
|
||||||
@ -205,12 +160,6 @@
|
|||||||
#define SMTP_AUTH_PLAIN_LEN(session) smtp_auth_plain_len
|
#define SMTP_AUTH_PLAIN_LEN(session) smtp_auth_plain_len
|
||||||
#endif /* SMTP_COPY_AUTHDATA */
|
#endif /* SMTP_COPY_AUTHDATA */
|
||||||
|
|
||||||
/* Memory allocation/deallocation can be overridden... */
|
|
||||||
#ifndef SMTP_STATE_MALLOC
|
|
||||||
#define SMTP_STATE_MALLOC(size) mem_malloc(size)
|
|
||||||
#define SMTP_STATE_FREE(ptr) mem_free(ptr)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if SMTP_BODYDH
|
#if SMTP_BODYDH
|
||||||
#ifndef SMTP_BODYDH_MALLOC
|
#ifndef SMTP_BODYDH_MALLOC
|
||||||
#define SMTP_BODYDH_MALLOC(size) mem_malloc(size)
|
#define SMTP_BODYDH_MALLOC(size) mem_malloc(size)
|
||||||
@ -387,7 +336,8 @@ smtp_pbuf_str(struct pbuf* p)
|
|||||||
}
|
}
|
||||||
#endif /* LWIP_DEBUG */
|
#endif /* LWIP_DEBUG */
|
||||||
|
|
||||||
/** Set IP address or DNS name for next SMTP connection
|
/** @ingroup smtp
|
||||||
|
* Set IP address or DNS name for next SMTP connection
|
||||||
*
|
*
|
||||||
* @param server IP address (in ASCII representation) or DNS name of the server
|
* @param server IP address (in ASCII representation) or DNS name of the server
|
||||||
*/
|
*/
|
||||||
@ -405,7 +355,8 @@ smtp_set_server_addr(const char* server)
|
|||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Set TCP port for next SMTP connection
|
/** @ingroup smtp
|
||||||
|
* Set TCP port for next SMTP connection
|
||||||
*
|
*
|
||||||
* @param port TCP port
|
* @param port TCP port
|
||||||
*/
|
*/
|
||||||
@ -423,7 +374,8 @@ smtp_set_tls_config(struct altcp_tls_config *tls_config)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** Set authentication parameters for next SMTP connection
|
/** @ingroup smtp
|
||||||
|
* Set authentication parameters for next SMTP connection
|
||||||
*
|
*
|
||||||
* @param username login name as passed to the server
|
* @param username login name as passed to the server
|
||||||
* @param pass password passed to the server together with username
|
* @param pass password passed to the server together with username
|
||||||
@ -595,7 +547,8 @@ leave:
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Send an email via the currently selected server, username and password.
|
/** @ingroup smtp
|
||||||
|
* Send an email via the currently selected server, username and password.
|
||||||
*
|
*
|
||||||
* @param from source email address (must be NULL-terminated)
|
* @param from source email address (must be NULL-terminated)
|
||||||
* @param to target email address (must be NULL-terminated)
|
* @param to target email address (must be NULL-terminated)
|
||||||
@ -654,7 +607,8 @@ smtp_send_mail(const char* from, const char* to, const char* subject, const char
|
|||||||
return smtp_send_mail_alloced(s);
|
return smtp_send_mail_alloced(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Same as smtp_send_mail, but doesn't copy from, to, subject and body into
|
/** @ingroup smtp
|
||||||
|
* Same as smtp_send_mail, but doesn't copy from, to, subject and body into
|
||||||
* an internal buffer to save memory.
|
* an internal buffer to save memory.
|
||||||
* WARNING: the above data must stay untouched until the callback function is
|
* WARNING: the above data must stay untouched until the callback function is
|
||||||
* called (unless the function returns != ERR_OK)
|
* called (unless the function returns != ERR_OK)
|
||||||
@ -695,7 +649,8 @@ smtp_send_mail_static(const char *from, const char* to, const char* subject,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Same as smpt_send_mail but takes a struct smtp_send_request as single
|
/** @ingroup smtp
|
||||||
|
* Same as smpt_send_mail but takes a struct smtp_send_request as single
|
||||||
* parameter which contains all the other parameters.
|
* parameter which contains all the other parameters.
|
||||||
* To be used with tcpip_callback to send mail from interrupt context or from
|
* To be used with tcpip_callback to send mail from interrupt context or from
|
||||||
* another thread.
|
* another thread.
|
||||||
|
@ -1,11 +1,7 @@
|
|||||||
#ifndef LWIP_HDR_APPS_SMTP_H
|
#ifndef LWIP_HDR_APPS_SMTP_H
|
||||||
#define LWIP_HDR_APPS_SMTP_H
|
#define LWIP_HDR_APPS_SMTP_H
|
||||||
|
|
||||||
/** Set this to 1 to enable data handler callback on BODY */
|
#include "lwip/apps/smtp_opts.h"
|
||||||
#ifndef SMTP_BODYDH
|
|
||||||
#define SMTP_BODYDH 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "lwip/err.h"
|
#include "lwip/err.h"
|
||||||
|
|
||||||
/** The default TCP port used for SMTP */
|
/** The default TCP port used for SMTP */
|
||||||
|
81
src/include/lwip/apps/smtp_opts.h
Normal file
81
src/include/lwip/apps/smtp_opts.h
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
#ifndef LWIP_HDR_APPS_SMTP_OPTS_H
|
||||||
|
#define LWIP_HDR_APPS_SMTP_OPTS_H
|
||||||
|
|
||||||
|
#include "lwip/opt.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @defgroup smtp_opts Options
|
||||||
|
* @ingroup smtp
|
||||||
|
*
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** Set this to 1 to enable data handler callback on BODY */
|
||||||
|
#ifndef SMTP_BODYDH
|
||||||
|
#define SMTP_BODYDH 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/** SMTP_DEBUG: Enable debugging for SNTP. */
|
||||||
|
#ifndef SMTP_DEBUG
|
||||||
|
#define SMTP_DEBUG LWIP_DBG_OFF
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/** Maximum length reserved for server name */
|
||||||
|
#ifndef SMTP_MAX_SERVERNAME_LEN
|
||||||
|
#define SMTP_MAX_SERVERNAME_LEN 256
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/** Maximum length reserved for username */
|
||||||
|
#ifndef SMTP_MAX_USERNAME_LEN
|
||||||
|
#define SMTP_MAX_USERNAME_LEN 32
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/** Maximum length reserved for password */
|
||||||
|
#ifndef SMTP_MAX_PASS_LEN
|
||||||
|
#define SMTP_MAX_PASS_LEN 32
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/** Set this to 0 if you know the authentication data will not change
|
||||||
|
* during the smtp session, which saves some heap space. */
|
||||||
|
#ifndef SMTP_COPY_AUTHDATA
|
||||||
|
#define SMTP_COPY_AUTHDATA 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/** Set this to 0 to save some code space if you know for sure that all data
|
||||||
|
* passed to this module conforms to the requirements in the SMTP RFC.
|
||||||
|
* WARNING: use this with care!
|
||||||
|
*/
|
||||||
|
#ifndef SMTP_CHECK_DATA
|
||||||
|
#define SMTP_CHECK_DATA 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/** Set this to 1 to enable AUTH PLAIN support */
|
||||||
|
#ifndef SMTP_SUPPORT_AUTH_PLAIN
|
||||||
|
#define SMTP_SUPPORT_AUTH_PLAIN 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/** Set this to 1 to enable AUTH LOGIN support */
|
||||||
|
#ifndef SMTP_SUPPORT_AUTH_LOGIN
|
||||||
|
#define SMTP_SUPPORT_AUTH_LOGIN 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Memory allocation/deallocation can be overridden... */
|
||||||
|
#ifndef SMTP_STATE_MALLOC
|
||||||
|
#define SMTP_STATE_MALLOC(size) mem_malloc(size)
|
||||||
|
#define SMTP_STATE_FREE(ptr) mem_free(ptr)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* SMTP_OPTS_H */
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user