Fixes found in smtp testing
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@356 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
f43ffa05aa
commit
00093c0a08
@ -45,6 +45,7 @@
|
|||||||
|
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
@ -70,11 +71,29 @@
|
|||||||
# include <net/uip/resolv.h>
|
# include <net/uip/resolv.h>
|
||||||
#elif defined(CONFIG_EXAMPLE_UIP_WEBCLIENT)
|
#elif defined(CONFIG_EXAMPLE_UIP_WEBCLIENT)
|
||||||
# include <net/uip/webclient.h>
|
# include <net/uip/webclient.h>
|
||||||
|
#else
|
||||||
|
# error "No network application specified"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/************************************************************
|
/****************************************************************************
|
||||||
|
* Private Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#if defined(CONFIG_EXAMPLE_UIP_SMTP)
|
||||||
|
static const char g_host_name[] = "localhost";
|
||||||
|
static const char g_recipient[] = "spudmonkey@racsa.co.cr";
|
||||||
|
static const char g_sender[] = "nuttx-testing@example.com";
|
||||||
|
static const char g_subject[] = "Testing SMTP from NuttX";
|
||||||
|
static const char g_msg_body[] = "Test message sent by NuttX\r\n";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
* user_initialize
|
* user_initialize
|
||||||
************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifndef CONFIG_HAVE_WEAKFUNCTIONS
|
#ifndef CONFIG_HAVE_WEAKFUNCTIONS
|
||||||
void user_initialize(void)
|
void user_initialize(void)
|
||||||
@ -85,11 +104,11 @@ void user_initialize(void)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/************************************************************
|
/****************************************************************************
|
||||||
* user_start
|
* user_start
|
||||||
************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int user_start(int argc, char *argv[])
|
int user_start(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct in_addr addr;
|
struct in_addr addr;
|
||||||
#if defined(CONFIG_EXAMPLE_UIP_DHCPC) || defined(CONFIG_ARCH_SIM)
|
#if defined(CONFIG_EXAMPLE_UIP_DHCPC) || defined(CONFIG_ARCH_SIM)
|
||||||
@ -154,9 +173,9 @@ void user_initialize(void)
|
|||||||
handle = smtp_open();
|
handle = smtp_open();
|
||||||
if (handle)
|
if (handle)
|
||||||
{
|
{
|
||||||
smtp_configure("localhost", addr.s_addr);
|
smtp_configure(handle, g_host_name, &addr.s_addr);
|
||||||
smtp_send("adam@sics.se", NULL, "uip-testing@example.com",
|
smtp_send(handle, g_recipient, NULL, g_sender, g_subject,
|
||||||
"Testing SMTP from uIP", "Test message sent by uIP\r\n");
|
g_msg_body, strlen(g_msg_body));
|
||||||
smtp_close(handle);
|
smtp_close(handle);
|
||||||
}
|
}
|
||||||
#elif defined(CONFIG_EXAMPLE_UIP_WEBCLIENT)
|
#elif defined(CONFIG_EXAMPLE_UIP_WEBCLIENT)
|
||||||
@ -180,6 +199,7 @@ void uip_log(char *m)
|
|||||||
printf("uIP log message: %s\n", m);
|
printf("uIP log message: %s\n", m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(CONFIG_EXAMPLE_UIP_WEBCLIENT)
|
||||||
void webclient_closed(void)
|
void webclient_closed(void)
|
||||||
{
|
{
|
||||||
printf("Webclient: connection closed\n");
|
printf("Webclient: connection closed\n");
|
||||||
@ -204,3 +224,4 @@ void webclient_datahandler(char *data, uint16 len)
|
|||||||
{
|
{
|
||||||
printf("Webclient: got %d bytes of data.\n", len);
|
printf("Webclient: got %d bytes of data.\n", len);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
@ -57,8 +57,11 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
extern void *smtp_open(void);
|
extern void *smtp_open(void);
|
||||||
extern void smtp_configure(void *handle, char *localhostname, void *smtpserver);
|
extern void smtp_configure(void *handle, const char *localhostname,
|
||||||
extern int smtp_send(void *handle, char *to, char *cc, char *from, char *subject, char *msg, int msglen);
|
const uip_ipaddr_t *paddr);
|
||||||
|
extern int smtp_send(void *handle, const char *to, const char *cc,
|
||||||
|
const char *from, const char *subject,
|
||||||
|
const char *msg, int msglen);
|
||||||
extern void smtp_close(void *handle);
|
extern void smtp_close(void *handle);
|
||||||
|
|
||||||
#endif /* __SMTP_H__ */
|
#endif /* __SMTP_H__ */
|
||||||
|
@ -258,8 +258,7 @@ int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
|
|||||||
goto errout;
|
goto errout;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ENOSYS;
|
return OK;
|
||||||
/*return OK;*/
|
|
||||||
|
|
||||||
errout:
|
errout:
|
||||||
*get_errno_ptr() = err;
|
*get_errno_ptr() = err;
|
||||||
|
@ -406,7 +406,7 @@ static ssize_t recvfrom_result(int result, struct recvfrom_s *pstate)
|
|||||||
* psock Pointer to the socket structure for the SOCK_DRAM socket
|
* psock Pointer to the socket structure for the SOCK_DRAM socket
|
||||||
* buf Buffer to receive data
|
* buf Buffer to receive data
|
||||||
* len Length of buffer
|
* len Length of buffer
|
||||||
* infrom INET ddress of source
|
* infrom INET ddress of source (may be NULL)
|
||||||
*
|
*
|
||||||
* Returned Value:
|
* Returned Value:
|
||||||
* On success, returns the number of characters sent. On error,
|
* On success, returns the number of characters sent. On error,
|
||||||
@ -489,7 +489,7 @@ static ssize_t udp_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
|
|||||||
* psock Pointer to the socket structure for the SOCK_DRAM socket
|
* psock Pointer to the socket structure for the SOCK_DRAM socket
|
||||||
* buf Buffer to receive data
|
* buf Buffer to receive data
|
||||||
* len Length of buffer
|
* len Length of buffer
|
||||||
* infrom INET ddress of source
|
* infrom INET ddress of source (may be NULL)
|
||||||
*
|
*
|
||||||
* Returned Value:
|
* Returned Value:
|
||||||
* On success, returns the number of characters sent. On error,
|
* On success, returns the number of characters sent. On error,
|
||||||
@ -575,7 +575,7 @@ static ssize_t tcp_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
|
|||||||
* buf Buffer to receive data
|
* buf Buffer to receive data
|
||||||
* len Length of buffer
|
* len Length of buffer
|
||||||
* flags Receive flags
|
* flags Receive flags
|
||||||
* from Address of source
|
* from Address of source (may be NULL)
|
||||||
* fromlen The length of the address structure
|
* fromlen The length of the address structure
|
||||||
*
|
*
|
||||||
* Returned Value:
|
* Returned Value:
|
||||||
@ -624,7 +624,7 @@ ssize_t recvfrom(int sockfd, FAR void *buf, size_t len, int flags, FAR struct so
|
|||||||
|
|
||||||
/* Verify that non-NULL pointers were passed */
|
/* Verify that non-NULL pointers were passed */
|
||||||
|
|
||||||
if (!buf || !from || !fromlen)
|
if (!buf)
|
||||||
{
|
{
|
||||||
err = EINVAL;
|
err = EINVAL;
|
||||||
goto errout;
|
goto errout;
|
||||||
@ -640,8 +640,10 @@ ssize_t recvfrom(int sockfd, FAR void *buf, size_t len, int flags, FAR struct so
|
|||||||
goto errout;
|
goto errout;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Verify that a valid address has been provided */
|
/* If a 'from' address has been provided, verify that it is valid */
|
||||||
|
|
||||||
|
if (from)
|
||||||
|
{
|
||||||
#ifdef CONFIG_NET_IPv6
|
#ifdef CONFIG_NET_IPv6
|
||||||
if (from->sa_family != AF_INET6 || *fromlen < sizeof(struct sockaddr_in6))
|
if (from->sa_family != AF_INET6 || *fromlen < sizeof(struct sockaddr_in6))
|
||||||
#else
|
#else
|
||||||
@ -651,6 +653,7 @@ ssize_t recvfrom(int sockfd, FAR void *buf, size_t len, int flags, FAR struct so
|
|||||||
err = EBADF;
|
err = EBADF;
|
||||||
goto errout;
|
goto errout;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Set the socket state to receiving */
|
/* Set the socket state to receiving */
|
||||||
|
|
||||||
|
@ -79,12 +79,12 @@ struct smtp_state
|
|||||||
boolean connected;
|
boolean connected;
|
||||||
sem_t sem;
|
sem_t sem;
|
||||||
uip_ipaddr_t smtpserver;
|
uip_ipaddr_t smtpserver;
|
||||||
char *localhostname;
|
const char *localhostname;
|
||||||
char *to;
|
const char *to;
|
||||||
char *cc;
|
const char *cc;
|
||||||
char *from;
|
const char *from;
|
||||||
char *subject;
|
const char *subject;
|
||||||
char *msg;
|
const char *msg;
|
||||||
int msglen;
|
int msglen;
|
||||||
int sentlen;
|
int sentlen;
|
||||||
int textlen;
|
int textlen;
|
||||||
@ -242,33 +242,35 @@ static inline int smtp_send_message(int sockfd, struct smtp_state *psmtp)
|
|||||||
|
|
||||||
/* Specificy an SMTP server and hostname.
|
/* Specificy an SMTP server and hostname.
|
||||||
*
|
*
|
||||||
* This function is used to configure the SMTP module with an SMTP
|
* This function is used to configure the SMTP module with an SMTP server and
|
||||||
* server and the hostname of the host.
|
* the hostname of the host.
|
||||||
*
|
*
|
||||||
* lhostname The hostname of the uIP host.
|
* lhostname - The hostname of the local, uIP host.
|
||||||
*
|
*
|
||||||
* server A pointer to a 4-byte array representing the IP
|
* paddr - A pointer to the IP address of the SMTP server to be
|
||||||
* address of the SMTP server to be configured.
|
* configured.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void smtp_configure(void *handle, char *lhostname, void *server)
|
void smtp_configure(void *handle, const char *lhostname,
|
||||||
|
const uip_ipaddr_t *paddr)
|
||||||
{
|
{
|
||||||
struct smtp_state *psmtp = (struct smtp_state *)handle;
|
struct smtp_state *psmtp = (struct smtp_state *)handle;
|
||||||
psmtp->localhostname = lhostname;
|
psmtp->localhostname = lhostname;
|
||||||
uip_ipaddr_copy(psmtp->smtpserver, server);
|
uip_ipaddr_copy(psmtp->smtpserver, paddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Send an e-mail.
|
/* Send an e-mail.
|
||||||
*
|
*
|
||||||
* to The e-mail address of the receiver of the e-mail.
|
* to - The e-mail address of the receiver of the e-mail.
|
||||||
* cc The e-mail address of the CC: receivers of the e-mail.
|
* cc - The e-mail address of the CC: receivers of the e-mail.
|
||||||
* from The e-mail address of the sender of the e-mail.
|
* from - The e-mail address of the sender of the e-mail.
|
||||||
* subject The subject of the e-mail.
|
* subject - The subject of the e-mail.
|
||||||
* msg The actual e-mail message.
|
* msg - The actual e-mail message.
|
||||||
* msglen The length of the e-mail message.
|
* msglen - The length of the e-mail message.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int smtp_send(void *handle, char *to, char *cc, char *from, char *subject, char *msg, int msglen)
|
int smtp_send(void *handle, const char *to, const char *cc, const char *from,
|
||||||
|
const char *subject, const char *msg, int msglen)
|
||||||
{
|
{
|
||||||
struct smtp_state *psmtp = (struct smtp_state *)handle;
|
struct smtp_state *psmtp = (struct smtp_state *)handle;
|
||||||
struct sockaddr_in server;
|
struct sockaddr_in server;
|
||||||
|
@ -289,6 +289,7 @@ static void handle_connection(struct httpd_state *pstate)
|
|||||||
int httpd_listen(void)
|
int httpd_listen(void)
|
||||||
{
|
{
|
||||||
#warning "this is all very broken at the moment"
|
#warning "this is all very broken at the moment"
|
||||||
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
Loading…
Reference in New Issue
Block a user