BasicSMTP.c File Reference


Detailed Description

Basic SMTP Client for AVR32 UC3.

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/

Definition in file BasicSMTP.c.

#include <string.h>
#include "gpio.h"
#include "FreeRTOS.h"
#include "task.h"
#include "BasicSMTP.h"
#include "semphr.h"
#include "portmacro.h"
#include "intc.h"
#include "fsaccess.h"
#include "conf_explorer.h"
#include "config_file.h"
#include "supervisor.h"
#include "ethernet.h"
#include "lwip/api.h"
#include "lwip/tcpip.h"
#include "lwip/memp.h"
#include "lwip/stats.h"
#include "lwip/opt.h"
#include "lwip/arch.h"
#include "lwip/sys.h"
#include "lwip/sockets.h"
#include "netif/loopif.h"

Go to the source code of this file.

Data Structures

struct  xMailDef
 mail structure posted through mail box More...

Defines

#define SMTP_CONFIG_FILE   "A:/CFG/smtp.txt"
 The config file location.
#define SMTP_DATA_STRING   "DATA\r\n"
 SMTP DATA string.
#define SMTP_END_OF_TRANSMISSION_STRING   "221"
 SMTP end of transmission code answer.
#define SMTP_ERRMSG_CONFIGURESMTP   "SMTP has not been compiled, please set SMTP_USED to 1 at preprocessor level\r\n"
 define the error string to use SMTP through configuration
#define SMTP_HELO_STRING   "220"
 SMTP HELO code answer.
#define SMTP_MAIL_END_STRING   "\r\n.\r\n"
 SMTP EOM string.
#define SMTP_MAILS_QUEUE_SIZE   2
 the mailbox queue size
#define SMTP_OK_STRING   "250"
 SMTP OK code answer.
#define SMTP_PACKET_SIZE   512
 the size of a packet
#define SMTP_PORT   25
 SMTP default port.
#define SMTP_QUIT_STRING   "QUIT\r\n"
 SMTP QUIT string.
#define SMTP_START_OF_TRANSMISSION_STRING   "354"
 SMTP start of transmission code answer.

Enumerations

enum  eSMTPCurrentStateType {
  eSMTPIdle = 0, eSMTPHeloSent, eSMTPMailFromSent, eSMTPMailToSent,
  eSMTPDataSent, eSMTPContentSent, eSMTPQuitSent, eSMTPMailSent,
  eSMTPNbState
}
 states for SMTP state machine More...

Functions

eExecStatus e_smtpclient_cmd_get_config (eModId xModId, signed short FsNavId, int ac, signed portCHAR *av[], signed portCHAR **ppcStringReply)
 The get smtp client config command: get the SMTP variables. Takes no parameter.
eExecStatus e_smtpclient_cmd_set_config (eModId xModId, signed short FsNavId, int ac, signed portCHAR *av[], signed portCHAR **ppcStringReply)
 The set smtp client config command: set the SMTP variables.
 portTASK_FUNCTION (vBasicSMTPClient, pvParameters)
 Task for SMTP management.
void v_SMTP_Post (portCHAR *MailSubject, portCHAR *Filename)
 Post a message to send.
void v_SMTP_PostFromISR (portCHAR *MailSubject, portCHAR *Filename)
 Post a message to send from ISR.

Variables

portCHAR cMailFrom [40]
 mail sender
portCHAR cMailTo [40]
 mail recipient
portCHAR cServerName [16]
 Server Name.
portCHAR cTempBuffer [200]
 temporary buffer for SMTP response
eSMTPCurrentStateType eSMTPCurrentState = eSMTPIdle
 SMTP sending state mchine current state.
static unsigned int uiSMTPPort
 SMTP port.
xSemaphoreHandle xCFGMutex
 The CFG system mutex.
xMailDef xMailFromISR
 var for mail params under IT
static xQueueHandle xMailsQueue = 0
 The handle of the queue of mails.


Define Documentation

#define SMTP_CONFIG_FILE   "A:/CFG/smtp.txt"

The config file location.

Definition at line 121 of file BasicSMTP.c.

Referenced by e_smtpclient_cmd_set_config(), and portTASK_FUNCTION().

#define SMTP_DATA_STRING   "DATA\r\n"

SMTP DATA string.

Definition at line 109 of file BasicSMTP.c.

Referenced by portTASK_FUNCTION().

#define SMTP_END_OF_TRANSMISSION_STRING   "221"

SMTP end of transmission code answer.

Definition at line 103 of file BasicSMTP.c.

#define SMTP_ERRMSG_CONFIGURESMTP   "SMTP has not been compiled, please set SMTP_USED to 1 at preprocessor level\r\n"

define the error string to use SMTP through configuration

Definition at line 82 of file BasicSMTP.c.

Referenced by e_smtpclient_cmd_set_config().

#define SMTP_HELO_STRING   "220"

SMTP HELO code answer.

Definition at line 101 of file BasicSMTP.c.

#define SMTP_MAIL_END_STRING   "\r\n.\r\n"

SMTP EOM string.

Definition at line 111 of file BasicSMTP.c.

Referenced by portTASK_FUNCTION().

#define SMTP_MAILS_QUEUE_SIZE   2

the mailbox queue size

Definition at line 118 of file BasicSMTP.c.

Referenced by portTASK_FUNCTION().

#define SMTP_OK_STRING   "250"

SMTP OK code answer.

Definition at line 105 of file BasicSMTP.c.

#define SMTP_PACKET_SIZE   512

the size of a packet

Definition at line 116 of file BasicSMTP.c.

Referenced by portTASK_FUNCTION().

#define SMTP_PORT   25

SMTP default port.

Definition at line 99 of file BasicSMTP.c.

Referenced by portTASK_FUNCTION().

#define SMTP_QUIT_STRING   "QUIT\r\n"

SMTP QUIT string.

Definition at line 113 of file BasicSMTP.c.

Referenced by portTASK_FUNCTION().

#define SMTP_START_OF_TRANSMISSION_STRING   "354"

SMTP start of transmission code answer.

Definition at line 107 of file BasicSMTP.c.


Enumeration Type Documentation

states for SMTP state machine

Enumerator:
eSMTPIdle 
eSMTPHeloSent 
eSMTPMailFromSent 
eSMTPMailToSent 
eSMTPDataSent 
eSMTPContentSent 
eSMTPQuitSent 
eSMTPMailSent 
eSMTPNbState 

Definition at line 127 of file BasicSMTP.c.

00127             {
00128   eSMTPIdle = 0,      // IDLE mode
00129   eSMTPHeloSent,      // HELO has been sent
00130   eSMTPMailFromSent,  // MAIL FROM has been set
00131   eSMTPMailToSent,    // RECPT TO has been sent
00132   eSMTPDataSent,      // DATA has been sent
00133   eSMTPContentSent,   // EOM has been sent
00134   eSMTPQuitSent,      // QUIT has been sent
00135   eSMTPMailSent,      // End of state machine, will return to IDLE
00136   eSMTPNbState        // should be used to know the states number
00137 }eSMTPCurrentStateType;


Function Documentation

eExecStatus e_smtpclient_cmd_get_config ( eModId  xModId,
signed short  FsNavId,
int  ac,
signed portCHAR *  av[],
signed portCHAR **  ppcStringReply 
)

The get smtp client config command: get the SMTP variables. Takes no parameter.

Note:
This function must be of the type eExecStatus defined by the shell module.
Parameters:
xModId Input. The module that is calling this function.
FsNavId Ignored.
ac Input. The argument counter. For this command, should be 1.
av Input. The argument vector.
ppcStringReply Input/Output. The response string. If Input is NULL, no response string will be output. Else a malloc for the response string is performed here; the caller must free this string.
Returns:
the status of the command execution.

Definition at line 613 of file BasicSMTP.c.

References cMailFrom, cMailTo, cServerName, MAX_CONFIG_FILE_SIZE, SHELL_ERRMSG_MEMALLOC, SHELL_EXECSTATUS_KO, SHELL_EXECSTATUS_OK, sprintf(), and uiSMTPPort.

Referenced by e_syscmds_cmd_get_config().

00616 {
00617 
00618   if(ppcStringReply != NULL)
00619   {
00620     // allocate a buffer for answer
00621     *ppcStringReply = (signed portCHAR *)pvPortMalloc(MAX_CONFIG_FILE_SIZE);
00622     if( NULL == *ppcStringReply )
00623     {
00624        *ppcStringReply = (signed portCHAR *)SHELL_ERRMSG_MEMALLOC;
00625        return( SHELL_EXECSTATUS_KO );
00626     }
00627 #if (SMTP_USED == 1)
00628     // get SMTP variables and add them to the buffer
00629     sprintf((char *)*ppcStringReply,"port=%u\r\nserver=%s\r\nmailto=%s\r\nmailfrom=%s\r\n",
00630                                      uiSMTPPort,
00631                                      cServerName,
00632                                      cMailTo,
00633                                      cMailFrom);
00634 #else
00635     // get SMTP variables and add them to the buffer
00636     sprintf((char *)*ppcStringReply,"port=NotCompiled\r\nserver=NotCompiled\r\nmailto=NotCompiled\r\nmailfrom=NotCompiled\r\n");
00637 #endif
00638     /* no error, return */
00639     return( SHELL_EXECSTATUS_OK );
00640   }
00641   return( SHELL_EXECSTATUS_KO );
00642 }

eExecStatus e_smtpclient_cmd_set_config ( eModId  xModId,
signed short  FsNavId,
int  ac,
signed portCHAR *  av[],
signed portCHAR **  ppcStringReply 
)

The set smtp client config command: set the SMTP variables.

 *         Takes 4 parameters :
 *                        port=ppppp
 *                        server=smtp.domain.com
 *                        mailto=recipient@domain.com
 *                        mailfrom=sender@domain.com
 * 

Note:
This function must be of the type eExecStatus defined by the shell module.
Parameters:
xModId Input. The module that is calling this function.
FsNavId Ignored.
ac Input. The argument counter. For this command, should be 1.
av Input. The argument vector.
ppcStringReply Input/Output. The response string. If Input is NULL, no response string will be output. Else a malloc for the response string is performed here; the caller must free this string.
Returns:
the status of the command execution.

Definition at line 546 of file BasicSMTP.c.

References cMailFrom, cMailTo, config_file_set_value(), cServerName, SHELL_ERRMSG_CONFIGERROR, SHELL_EXECSTATUS_KO, SHELL_EXECSTATUS_OK_NO_FREE, SHELL_MSG_CONFIG_SET, SMTP_CONFIG_FILE, SMTP_ERRMSG_CONFIGURESMTP, and uiSMTPPort.

Referenced by e_syscmds_cmd_set_config().

00549 {
00550 #if (SMTP_USED == 1)
00551   if (config_file_set_value(SMTP_CONFIG_FILE, ac, av) != 0)
00552   {
00553     *ppcStringReply = (signed portCHAR *)SHELL_ERRMSG_CONFIGERROR;
00554     // return error
00555     return( SHELL_EXECSTATUS_KO );
00556   }
00557 
00558   if (!strcmp((char *)av[0] , "port"))
00559   {
00560     uiSMTPPort = atoi((char *)av[1]);
00561     *ppcStringReply = (signed portCHAR *)SHELL_MSG_CONFIG_SET;
00562     return( SHELL_EXECSTATUS_OK_NO_FREE );
00563   }
00564   else if (!strcmp((char *)av[0] , "mailto"))
00565   {
00566     cMailTo[0]='\0';
00567     strncat(cMailTo, (char *)av[1], Min(sizeof(cMailTo),strlen((char *)av[1])));
00568     *ppcStringReply = (signed portCHAR *)SHELL_MSG_CONFIG_SET;
00569     return( SHELL_EXECSTATUS_OK_NO_FREE );
00570   }
00571   else if (!strcmp((char *)av[0] , "mailfrom"))
00572   {
00573     cMailFrom[0]='\0';
00574     strncat(cMailFrom, (char *)av[1], Min(sizeof(cMailFrom),strlen((char *)av[1])));
00575     *ppcStringReply = (signed portCHAR *)SHELL_MSG_CONFIG_SET;
00576     return( SHELL_EXECSTATUS_OK_NO_FREE );
00577   }
00578   else if (!strcmp((char *)av[0] , "server"))
00579   {
00580     cServerName[0]='\0';
00581     strncat(cServerName, (char *)av[1], Min(sizeof(cServerName),strlen((char *)av[1])));
00582     *ppcStringReply = (signed portCHAR *)SHELL_MSG_CONFIG_SET;
00583     return( SHELL_EXECSTATUS_OK_NO_FREE );
00584   }
00585   else
00586   {
00587     *ppcStringReply = (signed portCHAR *)SHELL_ERRMSG_CONFIGERROR;
00588     return( SHELL_EXECSTATUS_KO );
00589   }
00590 #else
00591     *ppcStringReply = (signed portCHAR *)SMTP_ERRMSG_CONFIGURESMTP;
00592     return( SHELL_EXECSTATUS_KO );
00593 #endif
00594 }

portTASK_FUNCTION ( vBasicSMTPClient  ,
pvParameters   
)

Task for SMTP management.

Definition at line 251 of file BasicSMTP.c.

References cMailFrom, cMailTo, config_file_get_value(), cServerName, cTempBuffer, eSMTPContentSent, eSMTPCurrentState, eSMTPDataSent, eSMTPHeloSent, eSMTPIdle, eSMTPMailFromSent, eSMTPMailSent, eSMTPMailToSent, eSMTPQuitSent, xMailDef::File, NAKED_TRACE_COM2, xMailDef::NeedFree, SMTP_CONFIG_FILE, SMTP_DATA_STRING, SMTP_MAIL_END_STRING, SMTP_MAILS_QUEUE_SIZE, SMTP_PACKET_SIZE, SMTP_PORT, SMTP_QUIT_STRING, xMailDef::Subject, uiSMTPPort, x_supervisor_SemaphoreGive(), x_supervisor_SemaphoreTake(), xCFGMutex, and xMailsQueue.

00252 {
00253 
00254    struct sockaddr_in stServeurSockAddr;
00255    portLONG lRetval;
00256    portLONG lSocket = -1;
00257    portLONG ulResponseCode = 0;
00258    xMailDef * pxMail;
00259    int Size, SizeRead;
00260    portCHAR * pcRespData;
00261    int fd;
00262    portCHAR cToken[6];
00263 
00264    // Just to stop compiler warnings.
00265    ( void ) pvParameters;
00266 
00267    // Create the xMailsQueue capable of containing DATALOG_LOGSQUEUE_SIZE ptrs
00268    // to xLogDef structures.
00269    xMailsQueue = xQueueCreate( SMTP_MAILS_QUEUE_SIZE, sizeof( xMailDef * ) );
00270 
00271    // SMTP configuration.
00272    // Get the xCFGMutex.
00273    if( pdFALSE == x_supervisor_SemaphoreTake( xCFGMutex, 500 ) )
00274    {
00275       // Failed to get the CFG mutex, use the default HTTP config.
00276       uiSMTPPort = SMTP_PORT;
00277       cMailTo[0] = '\0';
00278       cMailFrom[0] = '\0';
00279       cServerName[0] = '\0';
00280    }
00281    // Mutex has been taken
00282    else
00283    {
00284       // get the field value for port number
00285       if (config_file_get_value(SMTP_CONFIG_FILE, "port" , cToken) >= 0)
00286       {
00287          sscanf(cToken, "%u", &uiSMTPPort);
00288       }
00289       // if it does not exist, use the default value
00290       else
00291       {
00292          uiSMTPPort = SMTP_PORT;
00293       }
00294       // try to get the mailto field
00295       if (config_file_get_value(SMTP_CONFIG_FILE, "mailto", cMailTo) < 0)
00296       {
00297          cMailTo[0] = '\0';
00298          // can't find field in config file, warn user
00299          NAKED_TRACE_COM2("Warning : No mailto configured !!Please fill mailto= field in %s\r\n", SMTP_CONFIG_FILE);
00300       }
00301       // try to get the mailfrom field
00302       if (config_file_get_value(SMTP_CONFIG_FILE, "mailfrom", cMailFrom) < 0)
00303       {
00304          cMailFrom[0] = '\0';
00305          // can't find field in config file, warn user
00306          NAKED_TRACE_COM2("Warning : No mailfrom configured !!Please fill mailfrom= field in %s\r\n", SMTP_CONFIG_FILE);
00307       }
00308       // try to get the server field
00309       if (config_file_get_value(SMTP_CONFIG_FILE, "server", cServerName) < 0)
00310       {
00311          cServerName[0] = '\0';
00312          // can't find field in config file, warn user
00313          NAKED_TRACE_COM2("Warning : No server name configured !! Please fill server= field in %s\r\n", SMTP_CONFIG_FILE);
00314       }
00315       // Release the xCFGMutex.
00316       x_supervisor_SemaphoreGive( xCFGMutex );
00317    }
00318 
00319    for(;;)
00320    {
00321       // NOTE: the task should be resumed when it is necessary to send a mail
00322       // Get the oldest mail from the queue.
00323       // NOTE: we are sure there is an item to get => no block time.
00324       if( pdTRUE == xQueueReceive( xMailsQueue, &pxMail, ( portTickType )1000 ) )
00325       {
00326          if (cServerName[0] == '\0')
00327          {
00328             // can't find field in config file, warn user
00329             NAKED_TRACE_COM2("Warning : No server name configured !! Please fill server= field in %s\r\n", SMTP_CONFIG_FILE);
00330          }
00331          else if (cMailTo[0] == '\0')
00332          {
00333             // can't find field in config file, warn user
00334             NAKED_TRACE_COM2("Warning : No mailto configured !!Please fill mailto= field in %s\r\n", SMTP_CONFIG_FILE);
00335          }
00336          else if (cMailFrom[0] == '\0')
00337          {
00338             // can't find field in config file, warn user
00339             NAKED_TRACE_COM2("Warning : No mailfrom configured !!Please fill mailfrom= field in %s\r\n", SMTP_CONFIG_FILE);
00340          }
00341          else
00342          {
00343             // Set up port
00344             memset(&stServeurSockAddr, 0, sizeof(stServeurSockAddr));
00345             stServeurSockAddr.sin_len = sizeof(stServeurSockAddr);
00346             stServeurSockAddr.sin_addr.s_addr = inet_addr(cServerName);
00347             stServeurSockAddr.sin_port = htons(uiSMTPPort);
00348             stServeurSockAddr.sin_family = AF_INET;
00349 
00350             // socket as a stream
00351             if ( (lSocket = socket(AF_INET, SOCK_STREAM, 0)) < 0)
00352             {
00353                // socket failed
00354                NAKED_TRACE_COM2("Socket Failed\r\n");
00355             }
00356             // connect to the server
00357             if(connect(lSocket,(struct sockaddr *)&stServeurSockAddr,sizeof(stServeurSockAddr)) < 0)
00358             {
00359                // connect failed
00360                NAKED_TRACE_COM2("Connect Failed\r\n");
00361             }
00362             else
00363             {
00364                eSMTPCurrentState = eSMTPIdle;
00365                while ( eSMTPCurrentState != eSMTPMailSent )
00366                {
00367                   // wait for SMTP Server answer
00368                   do
00369                   {
00370                      lRetval = recv(lSocket, cTempBuffer, sizeof(cTempBuffer), 0);
00371                   }while (lRetval <= 0);
00372 
00373                   cTempBuffer[3] = '\0';
00374                   // Get the response code from server
00375                   ulResponseCode = atoi(cTempBuffer);
00376 
00377                   switch (ulResponseCode)
00378                   {
00379                      case 220:
00380                      {
00381                         // send helo
00382                         send(lSocket, "HELO ", 5, 0);
00383                         send(lSocket, cServerName, strlen(cServerName), 0);
00384                         send(lSocket, "\r\n", 2, 0);
00385                         eSMTPCurrentState = eSMTPHeloSent;
00386                         break;
00387                      }
00388                      case 221:
00389                      {
00390                         // QUIT sequence has been acknowledged by server
00391                         if (eSMTPCurrentState == eSMTPQuitSent)
00392                         {
00393                            eSMTPCurrentState = eSMTPMailSent;
00394                         }
00395                         break;
00396                      }
00397                      case 250:
00398                      {
00399                         if (eSMTPCurrentState == eSMTPHeloSent)
00400                         {
00401                            // send MAIL FROM
00402                            send(lSocket, "MAIL FROM: <", 12, 0); ;
00403                            send(lSocket, cMailFrom, strlen(cMailFrom), 0);
00404                            send(lSocket, ">\r\n", 3, 0);
00405                            eSMTPCurrentState = eSMTPMailFromSent;
00406                         }
00407                         else if (eSMTPCurrentState == eSMTPMailFromSent)
00408                         {
00409                            // send MAIL TO
00410                            send(lSocket, "RCPT TO: <", 10, 0); ;
00411                            send(lSocket, cMailTo, strlen(cMailTo), 0);
00412                            send(lSocket, ">\r\n", 3, 0);
00413                            eSMTPCurrentState = eSMTPMailToSent;
00414                         }
00415                         else if (eSMTPCurrentState == eSMTPMailToSent)
00416                         {
00417                            // send DATA
00418                            send(lSocket, SMTP_DATA_STRING, 6, 0);
00419                            eSMTPCurrentState = eSMTPDataSent;
00420                         }
00421                         else if (eSMTPCurrentState == eSMTPContentSent)
00422                         {
00423                            // send QUIT
00424                            send(lSocket, SMTP_QUIT_STRING, 6, 0);
00425                            eSMTPCurrentState = eSMTPQuitSent;
00426                         }
00427                         break;
00428                      }
00429                      case 354:
00430                      {
00431                         if (eSMTPCurrentState == eSMTPDataSent)
00432                         {
00433                            // set Subject field
00434                            send(lSocket, "Subject:", 8, 0);
00435                            // add subject
00436                            send(lSocket, pxMail->Subject, strlen(pxMail->Subject), 0);
00437                            send(lSocket, "\r\nFROM:", 7, 0);
00438                            send(lSocket, cMailFrom, strlen(cMailFrom), 0);
00439                            send(lSocket, "\r\nTO:", 5, 0);
00440                            send(lSocket, cMailTo, strlen(cMailTo), 0);
00441                            send(lSocket, "\r\n\r\n", 4, 0);
00442                            // if a file has been specified, copy the content in the mail body
00443                            if (pxMail->File != NULL)
00444                            {
00445                               // allocate response
00446                               pcRespData = (portCHAR *)pvPortMalloc(SMTP_PACKET_SIZE);
00447                               if (pcRespData != NULL)
00448                               {
00449                                  if ((fd = open((const char *)pxMail->File, O_RDONLY)) >= 0)
00450                                  {
00451                                     Size = fsaccess_file_get_size(fd);
00452                                     // get sectors of maximum size
00453                                     while(Size > 0)
00454                                     {
00455                                        // get the data from filesystem
00456                                        SizeRead = read(fd, pcRespData, SMTP_PACKET_SIZE);
00457                                        // if error occurs during the read
00458                                        if (SizeRead <= 0)
00459                                        {
00460                                           // end the loop and send what has already been added
00461                                           break;
00462                                        }
00463                                        // sned data to the socket
00464                                        send(lSocket, pcRespData, SizeRead, 0);
00465                                        // decrease remaing size
00466                                        Size -= SizeRead;
00467                                     }
00468                                     // close the file
00469                                     close(fd);
00470                                     // free the buffer
00471                                     vPortFree(pcRespData);
00472                                  }
00473                                  else
00474                                  {
00475                                     // warn user : can't open the file
00476                                     NAKED_TRACE_COM2("Open file fails\r\n");
00477                                  }
00478                               }
00479                               else
00480                               {
00481                                  // warn user : can't malloc the file buffer
00482                                  NAKED_TRACE_COM2("SMTP : Malloc fails\r\n");
00483                               }
00484                            }
00485                            // add "<CRLF>.<CRLF>"
00486                            send(lSocket, SMTP_MAIL_END_STRING, 5, 0);
00487                            eSMTPCurrentState = eSMTPContentSent;
00488                         }
00489                         break;
00490                      }
00491                      default:
00492                      {
00493                         // unknown SMTP code
00494                         NAKED_TRACE_COM2("Unimplented %l SMTP response from server\r\n",ulResponseCode);
00495                         // break loop and reset state machine
00496                         eSMTPCurrentState = eSMTPMailSent;
00497                         break;
00498                      }
00499                   }
00500                }
00501                // close the socket
00502                close(lSocket);
00503             }
00504             // if the item was not posted from ISR
00505             if (pxMail->NeedFree == pdTRUE)
00506             {
00507                // if a file has been specified
00508                if ( pxMail->File != NULL )
00509                {
00510                   // free the item
00511                   vPortFree(pxMail->File);
00512                }
00513                // free the items
00514                vPortFree(pxMail->Subject);
00515                vPortFree(pxMail);
00516             }
00517          }
00518       }
00519    }
00520 }

void v_SMTP_Post ( portCHAR *  MailSubject,
portCHAR *  Filename 
)

Post a message to send.

Parameters:
MailSubject : the subject for the mail to send
Filename : the filename for data to send as mail content

Definition at line 182 of file BasicSMTP.c.

References xMailDef::File, xMailDef::NeedFree, xMailDef::Subject, and xMailsQueue.

Referenced by b_light_get_value(), b_potentiometer_get_value(), b_temperature_get_value(), and prv_xopen_current_logfile().

00183 {
00184 xMailDef * pxMail;
00185 
00186    // try to allocate a descriptor for this mail
00187    pxMail = (xMailDef *) pvPortMalloc(sizeof(xMailDef));
00188    // if allocation succeeds
00189    if (pxMail != NULL)
00190    {
00191       // try to allocate a buffer for the subject
00192       pxMail->Subject = (portCHAR *) pvPortMalloc(strlen(MailSubject));
00193       // if allocation succeeds
00194       if (pxMail->Subject != NULL)
00195       {
00196          // copy the subject to mailbox item
00197          strcpy(pxMail->Subject, MailSubject );
00198          // if a filename as been provided
00199          if (Filename != NULL)
00200          {
00201             // try to allocate a buffer for the filename
00202             pxMail->File = (portCHAR *) pvPortMalloc(strlen(Filename));
00203             // if allocation succeeds
00204             if (pxMail->File != NULL)
00205             {
00206                // copy the filename to mailbox item
00207                strcpy(pxMail->File, Filename );
00208             }
00209          }
00210          else
00211          {
00212             // mark field as unused
00213             pxMail->File = NULL;
00214          }
00215          // item must be free, so mark it so.
00216          pxMail->NeedFree = pdTRUE;
00217          // post item to the mailbox
00218          xQueueSend( xMailsQueue, (void *)&pxMail, 0 );
00219       }
00220    }
00221 }

void v_SMTP_PostFromISR ( portCHAR *  MailSubject,
portCHAR *  Filename 
)

Post a message to send from ISR.

Parameters:
MailSubject : MUST be a const, no dynamic allocation in ISR
Filename : MUST be a const, no dynamic allocation in ISR

Definition at line 229 of file BasicSMTP.c.

References xMailDef::File, xMailDef::NeedFree, xMailDef::Subject, and xMailsQueue.

Referenced by prvjoystick_ISR_NonNakedBehaviour(), and prvpushb_ISR_NonNakedBehaviour().

00230 {
00231 xMailDef * pxMail = &xMailFromISR;
00232 portBASE_TYPE xYieldRequired = pdFALSE;
00233 
00234    // reference mail subject
00235    pxMail->Subject = MailSubject;
00236    // reference file name
00237    pxMail->File = Filename;
00238    // reference IT field
00239    pxMail->NeedFree = pdFALSE;
00240 
00241    // post message to queue, disable IT prior to do it
00242    portENTER_CRITICAL();
00243    xQueueSendFromISR( xMailsQueue, (void *)&pxMail, &xYieldRequired );
00244    portEXIT_CRITICAL();
00245 }


Variable Documentation

portCHAR cMailFrom[40]

mail sender

Definition at line 150 of file BasicSMTP.c.

Referenced by e_smtpclient_cmd_get_config(), e_smtpclient_cmd_set_config(), and portTASK_FUNCTION().

portCHAR cMailTo[40]

mail recipient

Definition at line 147 of file BasicSMTP.c.

Referenced by e_smtpclient_cmd_get_config(), e_smtpclient_cmd_set_config(), and portTASK_FUNCTION().

portCHAR cServerName[16]

Server Name.

Definition at line 153 of file BasicSMTP.c.

Referenced by e_smtpclient_cmd_get_config(), e_smtpclient_cmd_set_config(), and portTASK_FUNCTION().

portCHAR cTempBuffer[200]

temporary buffer for SMTP response

Definition at line 144 of file BasicSMTP.c.

Referenced by portTASK_FUNCTION().

SMTP sending state mchine current state.

Definition at line 141 of file BasicSMTP.c.

Referenced by portTASK_FUNCTION().

unsigned int uiSMTPPort [static]

SMTP port.

Definition at line 156 of file BasicSMTP.c.

Referenced by e_smtpclient_cmd_get_config(), e_smtpclient_cmd_set_config(), and portTASK_FUNCTION().

xSemaphoreHandle xCFGMutex

The CFG system mutex.

The CFG system mutex.

Definition at line 203 of file supervisor.c.

var for mail params under IT

Definition at line 173 of file BasicSMTP.c.

xQueueHandle xMailsQueue = 0 [static]

The handle of the queue of mails.

Definition at line 159 of file BasicSMTP.c.

Referenced by portTASK_FUNCTION(), v_SMTP_Post(), and v_SMTP_PostFromISR().


Generated on Fri Feb 19 02:22:42 2010 for AVR32 - Control Panel demonstration. by  doxygen 1.5.5