Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Examples  

smtp.c File Reference

Go to the source code of this file.

Functions

int smtp_yylex_memory (char *src)
 This function is the flex parser itself. Please look at the file 'smtp.lex' for details.

int response_parser (char *response, struct smtp_response *data)
 Parse the response from the SMTP server.

int client_smtp_connect (struct smtp_connexion_config *conf, struct smtp_res *result)
 Open a connexion to the SMTP server.

void smtp_disconnect ()
 Close the connexion between the SMTP client ant the server.

int smtp_send_email (struct smtp_connexion_config *conf, struct smtp_mail *email, struct smtp_res *result)
 Send an email to the SMTP server.


Variables

sockaddr_in tcp_add
 Internet address of the SMTP server.

int tcp_sock = -1
 Socket descriptor associated with the TCP connexion.


Detailed Description

This file implements the SMTP client API.

Definition in file smtp.c.


Function Documentation

int client_smtp_connect struct smtp_connexion_config   conf,
struct smtp_res   result
 

Open a connexion to the SMTP server.

Parameters:
conf Pointer to a configuration structure.
result Pointer to smtp_res structure.
Returns:
Upon successful completion, the function returns a positive number that represents the socket descriptor associated with the connexion. In this case, the field ellapsed contains the ellapsed time of the connexion in milli-seconds.
Otherwise the function returns the value -1. In this case the field error_code of result contains a value that identifies the failure. This value may be:

  • An error code from the function open_tcp_connexion() (of the Common C Library). See the detailed description of open_tcp_connexion() for full details.
  • An error code from the function read_from_socket()(of the Common C Library). See the detailed description of read_from_socket() for full details.
  • The value SMTP_WRITE_ERROR. This means that the system call write failed.
  • The value SMTP_BAD_ANSWER. This means that the response from the SMTP server was not valid.

Definition at line 93 of file smtp.c.

References smtp_connexion_config::connect_timeout_micro, smtp_connexion_config::connect_timeout_sec, smtp_res::ellapsed, smtp_res::error_code, smtp_connexion_config::host, smtp_connexion_config::id, open_tcp_connexion(), smtp_connexion_config::port, read_from_socket(), smtp_connexion_config::read_timeout_micro, smtp_connexion_config::read_timeout_sec, response_parser(), SCK_READ_OK, SMTP_BAD_ANSWER, SMTP_BUFFER_SIZE, SMTP_CLIENT_IDENTIFICATION_OK, smtp_disconnect(), SMTP_SERVER_IDENTIFICATION_OK, SMTP_WRITE_ERROR, tcp_add, and tcp_sock.

int response_parser char *    response,
struct smtp_response   data
[static]
 

Parse the response from the SMTP server.

Parameters:
response Pointer to a zero terminated string of characters the response from the SMTP server.
data Pointer to a smtp_response data structure that will be used to store information about the repsonse.
Returns:
The function returns one of the following value:
  • SMTP_SERVER_IDENTIFICATION_OK = 220 ("220 newsletter.tiscali.fr Simple Mail Transfer Service Ready" - follow the connexion)
  • SMTP_CLIENT_IDENTIFICATION_OK = 250 ("250 newsletter.tiscali.fr" - Follow the command HELO or EHLO)
  • SMTP_FROM_OK = 250 ("250 OK" - Follow the command MAIL FROM)
  • SMTP_RCPT_OK = 250 ("250 OK" - Follow the command RCPT TO)
  • SMTP_DATA_OK = 354 ("354 Start mail input; end with...", Follow the command DATA)
  • SMTP_END_OF_DATA_OK = 250 ("250 OK" - Follow the <CRLF>.CRLF> that marks the end of the data part.
  • SMTP_INVALID_ANSWER = -1 This means that the response is not well formated.

Definition at line 46 of file smtp.c.

References SMTP_INVALID_ANSWER, and smtp_yylex_memory().

Referenced by client_smtp_connect(), and smtp_send_email().

int smtp_send_email struct smtp_connexion_config   conf,
struct smtp_mail   email,
struct smtp_res   result
 

Send an email to the SMTP server.

Parameters:
conf Pointer to a configuration structure.
email Pointer to a smtp_mail structure that contains the mail's data.
result Pointer to smtp_res structure.
Returns:
Upon successfull completion the function returns 0, therwise it returns -1 and the connexion is closed.
If the returned value is 0 (success), then the field ellapsed of the structure pointed by result contains the ellapsed time of the action in milli-seconds.

If the returned value is -1 (error), then the field error_code of the structure pointed by result contains an error code that describes the failure. This value may be:

  • An error code from the function read_from_socket()(of the Common C Library). See the detailed description of read_from_socket() for full details.
  • The value SMTP_WRITE_ERROR. This means that the system call write failed.
  • The value SMTP_BAD_ANSWER. This means that the response from the SMTP server was not valid.
  • The value SMTP_BUFFER_OVERFLOW. This means that one of the input arguments "from" or "rcpt" is too long.

Definition at line 257 of file smtp.c.

References smtp_mail::data, smtp_res::ellapsed, smtp_res::error_code, smtp_mail::from, smtp_mail::rcpt, smtp_mail::rcpt_number, read_from_socket(), smtp_connexion_config::read_timeout_micro, smtp_connexion_config::read_timeout_sec, response_parser(), SCK_READ_OK, SMTP_BAD_ANSWER, SMTP_BUFFER_OVERFLOW, SMTP_BUFFER_SIZE, SMTP_DATA_OK, smtp_disconnect(), SMTP_END_OF_DATA_OK, SMTP_FROM_OK, SMTP_RCPT_OK, SMTP_WRITE_ERROR, and tcp_sock.


Generated on Thu Apr 3 16:23:47 2003 for Common_C_libraries by doxygen1.3-rc1