Vous êtes sur la page 1sur 45

Rfrence / Reference : SMO/SFO-0039 Titre /Title :

Rvision / Revision :

Package IP Reference Manual

Programme / Subject : TELIUM

Approbation de la rvision / Revision Approval : H Nom


Name
Etabli par : Written by:

Fonction
Function

Vincent Gomes

Software Engineer

Vrifi ou Approuv par :

Checked or approved by:

Jean-Luc Menez

SDK Project Manager

Autoris par : Authorized by:

Christophe Barthelemy

SDK Product leader

Rvision Issue

Date de validit / dapplication Validity/application date

Nb de pages Nb of pages

Nb de pages annexes Nb of appendices

Objet et description de la modification Object and description of modification

A B C D E F G H

September 2005 November 2005 August 2006 January 2007 April 2007 February 2008 April 2008 October 2008

Initial version (PackIP 1.2). Add sample "ExternalGPRS" (PackIP 2.1) Add PING facility and default route settings (PackIP 2.2) Add SMTP and POP3 interfaces (PackIP 3.0) Add HTTP server and attached files for SMTP (PackIP 3.1) Add details on HTTP server functions. Add HTTPS server facility. Add details on Ethernet options.

TRES IMPORTANT : la validit du prsent document, soumis signature lectronique doit tre vrifie, avant usage, dans le rpertoire Docs Applicables de PRISMA Programmes.

Page : M1

TABLE OF CONTENT

1. 2. 3.

INTRODUCTION ..............................................................................................................................................................1 OVERVIEW........................................................................................................................................................................2 PPP INTERFACE ..............................................................................................................................................................3 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 3.10
CONNECTION ................................................................................................................................................................3 OPEN A CONNECTION ....................................................................................................................................................3 CLOSE A CONNECTION .................................................................................................................................................4 START A CONNECTION..................................................................................................................................................4 STOP A CONNECTION ....................................................................................................................................................4 GET THE CONNECTION STATE .......................................................................................................................................5 WAIT FOR A CONNECTION STATE .................................................................................................................................5 CONFIGURE A CONNECTION .........................................................................................................................................6 SET AN OPTION OF THE CONNECTION ...........................................................................................................................7 GET AN OPTION OF THE CONNECTION ...........................................................................................................................7

4.

IP CONFIGURATION MANAGEMENT........................................................................................................................8 4.1 4.2 4.3 4.4 4.5 LOAD THE DEFAULT CONFIGURATION ..........................................................................................................................8 UNLOAD A CONFIGURATION .........................................................................................................................................9 READ AN OPTION OF THE DEFAULT CONFIGURATION ....................................................................................................9 SET AN OPTION OF THE DEFAULT CONFIGURATION .....................................................................................................10 SAVE THE DEFAULT CONFIGURATION .........................................................................................................................11

5.

ETHERNET MANAGEMENT .......................................................................................................................................12 5.1 5.2 GET AN OPTION OF THE ETHERNET LINK .....................................................................................................................12 SET AN OPTION OF THE ETHERNET LINK .....................................................................................................................12

6.

DNS RESOLVER SETTINGS ........................................................................................................................................14 6.1 6.2 GET AN OPTION OF THE DNS RESOLVER ....................................................................................................................14 SET AN OPTION OF THE DNS RESOLVER .....................................................................................................................14

7.

DEFAULT ROUTE SETTINGS .....................................................................................................................................15 7.1 7.2 GET THE DEFAULT GATEWAY ADDRESS .....................................................................................................................15 SET THE DEFAULT GATEWAY ADDRESS ......................................................................................................................15

8.

UTILITIES FUNCTIONS ...............................................................................................................................................16 8.1 8.2 8.3 ACCESS THE INTERNAL ERROR (ERRNO)....................................................................................................................16 FORMAT A TCP/IP ADDRESS .................................................................................................................................16 PING ...........................................................................................................................................................................18

9.

SMTP .................................................................................................................................................................................19 9.1 9.2 9.3 9.4 CONNECTION TO THE SERVER ....................................................................................................................................19 DISCONNECTION FROM THE SERVER...........................................................................................................................19 SEND A MESSAGE .......................................................................................................................................................20 SEND A SINGLE MESSAGE ...........................................................................................................................................21 POP3 .............................................................................................................................................................................23 CONNECTION TO THE SERVER ....................................................................................................................................23 DISCONNECTION FROM THE SERVER...........................................................................................................................23 REQUESTING THE NUMBER OF MESSAGES...................................................................................................................24 REQUESTING A GIVEN MESSAGE ...............................................................................................................................24 DELETING A GIVEN MESSAGE ...................................................................................................................................25

10. 10.1 10.2 10.3 10.4 10.5

SMO/SFO-0039

Rv. : H

Page : S1

10.6 11. 11.1 11.2 11.3 11.4 11.5 12. 13. 13.1 13.2 13.3 13.4 13.5

RESET THE SESSION ...................................................................................................................................................26 HTTP/HTTPS SERVER .............................................................................................................................................27 LAUNCH THE SERVER .................................................................................................................................................27 WAIT FOR A REQUEST ................................................................................................................................................28 SEND A RESPONSE ......................................................................................................................................................32 STOP THE SERVER ......................................................................................................................................................33 GET INFORMATION ABOUT SSL SESSION (HTTPS ONLY) ..........................................................................................33 COMPATIBILITY ......................................................................................................................................................35 SAMPLE PROGRAMS...............................................................................................................................................36 PPP SAMPLE ..............................................................................................................................................................36 ETHERNET SAMPLE ....................................................................................................................................................37 ENABLE/DISABLE THE ICMP REPLY FACILITY ...........................................................................................................38 MAIL SAMPLE ............................................................................................................................................................38 HTTP SAMPLE ...........................................................................................................................................................41

SMO/SFO-0039

Rv. : H

Page : S2

1.

INTRODUCTION

The package IP is a static library (named IP_.lib) which makes easier the development of Internet programs for EFT POS terminals. This library is static (it must be linked with the application). It is compiled with the three compilers (GCC, RVD and SDT) supported by the Telium SDK. Its interface is composed of several API header files : <IP_.h >, <SMTP_.h>, <PPP_.h>, <POP3_.h>.and <HTTP_.h>. The package provides all the services to perform Internet communications. Its main facilities are : IP communications. BSD interface. Client and server. TCP/IP. UDP. PPP Management. Ethernet Management. DNS Resolver. SMTP and POP3 email services. HTTP server facility ...

Developers shall read the [SMO-SFO-0075_PackIP_SecurityGuidance.pdf] which describes best practises for implementing IP enabled applications, according to the requirements of the POS Terminal Security Program.(PTS)

SMO/SFO-0039

Rv. : H

Page : 1

2.

OVERVIEW

Folder
SDK/inc

Content
IP_.h PPP_.h SMTP_.h POP3_.h HTTP_.h IP_.lib IP_.lib IP_.lib

Description
The library header files for respectively IP, PPP, SMTP, POP3 and HTTP.

SDK/lib_gnu SDK/lib_rvd SDK/lib_sdt SDK/Samples/ExternalGPRS

SDK/Samples/TCPIP

SDK/Sample/FTP SDK/Sample/SSL

Static IP library for GNU Static IP library for RVD Static IP library for SDT Source of a sample application which manages an external GPRS modem. It shows how to perform a PPP connection. Source of a sample application which shows: 1. how to implement a TCP client 2. how to implement a TCP server 3. how to retrieve the Ethernet parameters 4. how to send and receive emails Source of a FTP sample (please refer the FTP documentation) Source of an SSL sample (please refer the SSL documentation)

The header file <IP_.h> regroups mainly the standard BSD definitions. This document does not explain these functions. It describes the specific functions, particularly the ones of the interface of the integrated protocols PPP, HTTP, POP3 and SMTP.

SMO/SFO-0039

Rv. : H

Page : 2

3.
3.1

PPP INTERFACE
CONNECTION Syntax : PPP_HANDLE PPP_Connect ( const char *szComPort, const char *szLogin, const char *szPassword, int nProfile, unsigned int nDelay, unsigned int nTimeout ); < PPP_.h >

Include : Parameters :

szComPort: szLogin : szPassword : nProfile : nDelay: nTimeout Return : Description :

Communication port name (for example : "COM1", "COM6" ...). PPP user name PPP password. Connection profile. Polling delay (in 10 ms) Maximum waiting delay (in 10 ms)

Returns the connection handle (>=0) or a negative error code. This function establishes a PPP connection through a communication port. It performs all the process of the connection. Several common connection modes are possible. Please refer to the function "PPP_Setup" to know the different profiles. The polling delay must be lower than the timeout delay. It indicates the delay to verify periodically the state of the connection.

Nota :

3.2

OPEN A CONNECTION Syntax : Include : Return : PPP_HANDLE PPP_Open ( const char *szComPort ); < PPP_.h > Returns the connection handle (>=0) or a negative error code.

SMO/SFO-0039

Rv. : H

Page : 3

Parameters : szComPort: Communication port name (for example : "COM1", "COM6" ...). Description : This function opens a connection through a communication port (physical link). The communication port must be previously opened. The function returns only an handle on the connection.

3.3

CLOSE A CONNECTION Syntax : Include : Return : Parameters : nHandle : Description : PPP connection handle. This function closes a connection. It releases all its allocated resources. int PPP_Close ( PPP_HANDLE handle ); < PPP_.h > Returns 0 or a negative error code.

3.4

START A CONNECTION Syntax : Include : Return : Parameters : nHandle : Description : PPP connection handle. This function starts the connection (e.g. : . the PPP negotiation). int PPP_Start ( PPP_HANDLE handle ); < PPP_.h > Returns 0 or a negative error code.

3.5

STOP A CONNECTION Syntax : int PPP_Stop ( PPP_HANDLE handle );

SMO/SFO-0039

Rv. : H

Page : 4

Include : Return : Parameters : nHandle : Description :

< PPP_.h > Returns 0 or a negative error code.

PPP connection handle. This function stops the connection (e.g. : it disconnect it), but it do not close the connection.

3.6

GET THE CONNECTION STATE Syntax : Include : Return : Parameters : nHandle : Description : PPP connection handle. This function returns the state of the connection. int PPP_GetState ( PPP_HANDLE handle ); < PPP_.h > PPP connection state.

State PPP_STATE_DEAD PPP_STATE_ESTABLISH PPP_STATE_NETWORK PPP_STATE_AUTH PPP_STATE_TERMINATE PPP_STATE_IFUP

Comment The physical link is not ready. Physical connection in progress Network connection in progress Authentication in progress Disconnected Connection successful.

3.7

WAIT FOR A CONNECTION STATE Syntax : int PPP_WaitState( PPP_HANDLE nHandle, int nWaitState, int nStateExit, unsigned long nTimeout ); < PPP_.h > Returns 0 or a negative error code.

Include : Return :

SMO/SFO-0039

Rv. : H

Page : 5

Parameters : nHandle : PPP connection handle.

nWaitState : Waited state nStateExit : Exit State nTimeout : Description : Maximum timeout for waiting. This function waits until the connection has reached the given state. It exits also, with an error, when the 'nStateExit' has been reached or when the waiting timeout expires.

3.8

CONFIGURE A CONNECTION Syntax : int PPP_Setup ( PPP_HANDLE handle, const char *szLogin, const char *szPassword, int nProfile ); < PPP_.h >

Include : Parameters : nHandle : szLogin :

PPP connection handle. PPP user name PPP password. Connection profile. Returns 0 or a negative error code. This function configures the parameters of a connection.. Several common connection modes are possible. They are defined by a specific profile

szPassword : nProfile : Return : Description : Nota :

Profile PPP_PERSONAL_PROFILE

PPP_PSTN_PROFILE

Description Minimal configuration (login and password). The user must complete this configuration himself by calling the function "PPP_Set" (described below). Configuration dedicated to the PSTN communications.

SMO/SFO-0039

Rv. : H

Page : 6

PPP_GPRS _PROFILE

Configuration dedicated to the GPRS communications.

3.9

SET AN OPTION OF THE CONNECTION Syntax : Include : Parameters : nHandle : nOption: pArg: Return : Description : PPP connection handle. Option to set. Value. Returns 0 or a negative error code. This function sets an option parameter of a connection.. int PPP_SetOption ( PPP_HANDLE handle, int nOption, void *pArg ); < PPP_.h >

3.10 GET AN OPTION OF THE CONNECTION Syntax : Include : Parameters : nHandle : nOption: pArg: Return : Description : PPP connection handle. Option to get. Value. Returns 0 or a negative error code. This function gets the current value of an option parameter of a connection. int PPP_GetOption ( PPP_HANDLE handle, int nOption, void *pArg ); < PPP_.h >

SMO/SFO-0039

Rv. : H

Page : 7

4.

IP CONFIGURATION MANAGEMENT

The IP package provides functions to monitor the configuration of the IP facility. The different options are listed in the table below. They can be read, written and saved persistently (to become the default configuration). A sample is given in the section : 13.3 Enable/disable the ICMP reply facility (page 38)

Option __DFL_MAC_ADDRESS __DFL_ETH_LINK_SPEED

Value 6 bytes Integer. 10 or 100 __DFL_ETH_BOOT_PROTOCOL DHCP or Static __DFL_ETH_ADDR 4 bytes __DFL_ETH_GATEWAY 4 bytes __DFL_ETH_NETMASK 4 bytes __DFL_ETH_DNS1 4 bytes __DFL_ETH_DNS2 4 bytes __DFL_ICMP_REDIRECT Bool ON or OFF __DFL_ICMP_ECHO_REPLY Bool ON or OFF

Access Comments Read MAC Address Read/Write Ethernet link speed __DFL_ETH_LINK_SPEED_10MB __DFL_ETH_LINK_SPEED_100MB Read/Write Ethernet boot protocol (Static or DHCP) __DFL_ETH_BOOT_PROTOCOL_NONE __DFL_ETH_BOOT_PROTOCOL_DHCP Read/Write Ethernet local Address Read/Write Ethernet gateway address Read/Write Ethernet network mask Read/Write Ethernet DNS1 address Read/Write Ethernet DNS2 address Read/Write Activate ICMP redirection __DFL_ON __DFL_OFF Read/Write Activate ICMP reply __DFL_ON __DFL_OFF

4.1

LOAD THE DEFAULT CONFIGURATION Syntax : Include : Parameters : pnError : Output parameter which returns the error code of the loading operation.
Error Code __DLF_OK __DFL_ERROR_HW_ADDR_FOUND __DFL_ERROR_OPEN_FAILED __DFL_ERROR_LOADING Comment The IP configuration parameters have been successfully loaded. The hardware address (MAC) is missing. It is a mandatory parameter. The default parameter file can not be opened. Error when reading the default parameter file.

ETHCONF_HANDLE __LoadDefaultOptions ( int *pnError ); < IP_.h >

SMO/SFO-0039

Rv. : H

Page : 8

Return :

Returns an handle on the IP configuration (>=0) or a negative error code. This function loads the default parameters of the IP Ethernet link.

Description :

4.2

UNLOAD A CONFIGURATION

Syntax : Include :

int __UnloadDefaultOptions ( ETHCONF_HANDLE hConf ); < IP_.h >

Parameters : hConf : Return : Handle on the configuration to unload. Returns 0 or a negative error code.

Error Code __DLF_OK

__DFL_ERROR_INVALID_HANDLE

Comment The configuration has been successfully unloaed. Invalid handle parameter

Description :

This function unloads a configuration previously loaded using the function __LoadDefaultOptions. The configuration is lost (e.g it is not saved). The configuration handle is released. It must not be used anymore.

4.3

READ AN OPTION OF THE DEFAULT CONFIGURATION

Syntax :

int __GetDefaultOption ( ETHCONF_HANDLE handle, int nOption, void *pArg ); < IP_.h >

Include : Parameters : handle : nOption:

Handle on the configuration . Option to get. The list of options is given in table above.

SMO/SFO-0039

Rv. : H

Page : 9

pArg: Return :

Value. Returns 0 or a negative error code.

Error Code __DLF_OK

__DFL_ERROR_INVALID_HANDLE __DFL_ERROR_INVALID_OPTION

Comment The option has been successfully retrieved. Invalid handle parameter Invalid option parameter

Description :

This function gets an option parameter of IP configuration.

4.4

SET AN OPTION OF THE DEFAULT CONFIGURATION

Syntax :

int __SetDefaultOption ( ETHCONF_HANDLE handle, int nOption, void *pArg ); < IP_.h >

Include : Parameters : handle : nOption: pArg: Return :

Handle on the configuration Option to set. The list of options is given in table above. Value. Returns 0 or a negative error code.

Error Code __DLF_OK __DFL_ERROR_FIXED_OPTION __DFL_ERROR_INVALID_VALUE

__DFL_ERROR_INVALID_HANDLE __DFL_ERROR_INVALID_OPTION

Comment The option has been successfully set. The option is fixed. It can not be changed The option value is invalid. Invalid handle parameter Invalid option parameter

Description :

This function sets an option parameter in the IP configuration. To make this change persistent, the configuration must be saved using the function __SaveDefaultOptions (described below).

SMO/SFO-0039

Rv. : H

Page : 10

4.5

SAVE THE DEFAULT CONFIGURATION Syntax : Include : Parameters : handle : Return : Handle on the configuration to save. Returns the negative error code __DFL_ERROR_INVALID_HANDLE (the handle parameter is invalid ) or never returns. This function saves the configuration as the default one. The terminal is automatically rebooted and the new saved configuration is used. int __SaveDefaultOptions ( ETHCONF_HANDLE handle ); < IP_.h >

Description :

SMO/SFO-0039

Rv. : H

Page : 11

5.

ETHERNET MANAGEMENT

The IP package provides two functions to monitor the Ethernet configuration. They allow to read and to write the parameters of the Ethernet interface. The parameters are listed in the following table below. Some of them can not be written, they can be read-only.
Option ETH_IFO_ADDR ETH_IFO_NETMASK ETH_IFO_BRDADDR ETH_IFO_GATEWAY Comment Local address. Network mask. Broadcast address. Gateway address (read-only). DNS address 1 (read-only). DNS address 2 (read-only).

ETH_IFO_DNS1 ETH_IFO_DNS2

5.1

GET AN OPTION OF THE ETHERNET LINK Syntax : Include : Parameters : nOption: pArg: Return : Description : Option to set. Value. Returns 0 or a negative error code. This function gets an option parameter of the Ethernet link.. int EthernetGetOption ( < IP_.h > int nOption, void *pArg );

5.2

SET AN OPTION OF THE ETHERNET LINK Syntax : Include : Parameters : nOption: pArg: Return : Description : Option to set. Value. Returns 0 or a negative error code. This function sets an option parameter of the Ethernet link. int EthernetSetOption ( < IP_.h > int nOption, void *pArg );

SMO/SFO-0039

Rv. : H

Page : 12

SMO/SFO-0039

Rv. : H

Page : 13

6.

DNS RESOLVER SETTINGS

The Domain Name Server (DNS) resolver settings can be monitored using the the two following functions. 6.1 GET AN OPTION OF THE DNS RESOLVER Syntax : Include : Parameters : nOption: pArg: Return : Description : 6.2 Option to set. Value. Returns 0 or a negative error code. This function gets an option parameter of the DNS resolver. int ResolverGetOption ( < IP_.h > int nOption, void *pArg );

SET AN OPTION OF THE DNS RESOLVER Syntax : Include : Parameters : nOption: pArg: Return : Description : Option to set. Value. Returns 0 or a negative error code. This function sets an option parameter of the DNS resolver. int ResolverSetOption ( < IP_.h > int nOption, void *pArg );

SMO/SFO-0039

Rv. : H

Page : 14

7.

DEFAULT ROUTE SETTINGS

The gateway address of the embedded TCP/IP stack is managed by the two following functions.

7.1

GET THE DEFAULT GATEWAY ADDRESS Syntax : Include : Parameters : nGatewayAddress: Return : Description : None. This function gets the current gateway address of the embedded TCP/IP stack. Default gateway address. void __GetDefaultRoute ( unsigned int *nGatewayAddress ); < IP_.h >

7.2

SET THE DEFAULT GATEWAY ADDRESS Syntax : Include : Parameters : nGatewayAddress: Return : Description : None. This function sets the current gateway address of the embedded TCP/IP stack. Gateway address to set. void __SetDefaultRoute ( < IP_.h > unsigned int nGatewayAddress );

SMO/SFO-0039

Rv. : H

Page : 15

8.

UTILITIES FUNCTIONS

The package TCP/IP provides other utility functions described in this section. 8.1 ACCESS THE INTERNAL ERROR (ERRNO)

The two following functions allow to access the internal error code (ERRNO). Syntax : Include : int GetErrno (void ); < IP_.h >

Parameters : None. Return : Description : The internal error code value (ERRNO). This function returns the current value of the internal error code (ERRNO).

Syntax : Include :

void SetErrno (int nError ); < IP_.h >

Parameters : nError : Return : Description : Error code. None. This function sets the value of the internal error code (ERRNO).

8.2

FORMAT A TCP/IP ADDRESS

The following functions are provided to convert and format a TCP/IP address.

Syntax : Include :

unsigned long __inet_addr( const char *szAddress ); < IP_.h >

Parameters : szAddress: .TCP/IP address - ASCII format ("www.xxx.yyy.zzz").


Rv. : H Page : 16

SMO/SFO-0039

Return :

Returns the converted address (4 bytes format) or 0 when the ASCII address is not rightly formatted. This function converts an ASCII TCP/IP address to its 4 bytes format (struct in_addr).

Description :

Syntax : Include :

char *__inet_ntoa( struct in_addr nAddress ); < IP_.h >

Parameters : nAddress: Return : Description : . TCP/IP address - 4 bytes format. Converted address - ASCII format ("www.xxx.yyy.zzz"). Inverse of the function "__inet_addr". This function converts a 4 bytes address in its ASCII format.

Nota :

The returned character string is NULL terminated. It is allocated by the function "__inet_ntoa" and belongs to this one. It must copied by the calling function and must not be freed.

Syntax : Include :

int __inet_aton( const char *szAddress, struct in_addr *pnAddress ); < IP_.h >

Parameters : szAddress: pnAddress: Return : Description : .TCP/IP address - ASCII format ("www.xxx.yyy.zzz"). Converted address - 4 bytes format.

Returns 1 if the address has been rightly converted, and 0 otherwise. This function converts an ASCII TCP/IP address to its 4 bytes format (struct in_addr).

SMO/SFO-0039

Rv. : H

Page : 17

8.3

PING Syntax : Include : Parameters : nAddress: nTimeout: Return : Description : Remote address to reach Waiting delay (in 10 ms) for the answer. Returns 0 or a negative error code. This function tests if a remote address is reachable., by sending an ICMP request (Ping). int __Ping ( < IP_.h > unsigned int nAddress, int nTimeout );

SMO/SFO-0039

Rv. : H

Page : 18

9.
9.1

SMTP
CONNECTION TO THE SERVER Syntax : SMTP_HANDLE SMTP_Connect(const char *szSMTPServer, int nPort, const char *szLogin, const char *szPassword, const char *szSMTPClient ); < SMTP_.h >

Include : Parameters :

szSMTPServer: nPort: szLogin

TCP/IP address of the SMTP server. SMTP port (usually 25). User name. May be set to NULL (or ""), if no authentication required by the remote SMTP server. Password associated to the user name. Is NULL when the user name is NULL. Network name of the terminal.

szPassword

szSMTPClient Return : Description :

Returns the connection handle (>=0), or a negative error code. This function connects the terminal to the SMTP server. This connection can request an identification, or be anonymous (no user, nor password).

9.2

DISCONNECTION FROM THE SERVER Syntax : Include : Parameters : handle: Return : Description : Handle on the connection to close. None. This function disconnects the terminal from the SMTP server.
SMO/SFO-0039 Rv. : H Page : 19

void SMTP_Disconnect ( SMTP_HANDLE handle ); < SMTP_.h >

9.3

SEND A MESSAGE Syntax : int SMTP_Send ( SMTP_HANDLE handle, const char *szMessage, int nMessageSize, const char *szSubject, const char *szFrom, const char *szTo, const char *szCC, const char *szBCC, const char *pAttachedFilesList[] );

Include : Parameters : handle:

< SMTP_.h >

Handle on an existing connection. Message to send. Please note that the global raw message's size (header and content) is limited to 8 kilobytes. Size, in bytes, of the message to send. Subject of the message. May be NULL. E-mail address of the sender. This address cannot be NULL. Use a valid address to be able to be informed about distribution failures. List of recipients. This list can be NULL. In case of multiple recipients, put a comma (,) between each address. List of recipients put in copy. This list can be NULL. In case of multiple recipients, put a comma (,) between each address. List of recipients put in blind copy. This list can be NULL. In case of multiple recipients, put a comma (,) between each address.

szMessage:

nMessageSize: szSubject: szFrom:

szTo:

szCC:

szBCC:

pAttachedFilesList: Array of attachement files' names. These files must be stored in the FFMS before being sent. The complete path to these files (directory and file name) must be put in this array. This list can be NULL (no attached files). In any case, the last item of this list must be NULL.

SMO/SFO-0039

Rv. : H

Page : 20

Note:

At least of one list of recipients (To, CC, or BCC) must not be NULL.

Return : Description :

Number of attachement files sent (0 if none), or a negative error code. Send an US-ASCII text message to the lists of specified recipients. This message has an header formatted according to the standard RFC 822, as long as this header is not greater than 1024 bytes. Otherwise no header is added.

9.4

SEND A SINGLE MESSAGE Syntax : int SMTP_SendUniqueMessage (const char *szSMTPServer, int nPort, const char *szLogin, const char *szPassword, const char *szSMTPClient, const char *szMessage, int nMessageSize, const char *szSubject, const char *szFrom, const char *szTo, const char *szCC, const char *szBCC, const char *pAttachedFilesList[] );

Include : Parameters :

< SMTP_.h >

szSMTPServer: nPort: szLogin:

TCP/IP address of the SMTP server. SMTP server port (usually 25). User name. May be set to NULL (or ""), if no authentication required by the remote SMTP server. Password associated to the user name. Is NULL when the user name is NULL. Network name of the terminal.

szPassword

szSMTPClient

SMO/SFO-0039

Rv. : H

Page : 21

szMessage:

Message to send. Please note that the global raw message's size (header and content) is limited to 8 kilobytes. Size, in bytes, of the message to send. Subject of the message. May be NULL. E-mail address of the sender. This address cannot be NULL. Use a valid address to be able to be informed about distribution failures, List of recipients. This list can be NULL. In case of multiple recipients, put a comma (,) between each address. List of recipients put in copy. This list can be NULL. In case of multiple recipients, put a comma (,) between each address. List of recipients put in blind copy. This list can be NULL. In case of multiple recipients, put a comma (,) between each address.

nMessageSize: szSubject: szFrom:

szTo:

szCC:

szBCC:

pAttachedFilesList: Array of attachement files' names. These files must be stored in the FFMS before being sent. The complete path to these files (directory and file name) must be put in this array. This list can be NULL (no attached files). In any case, the last item of this list must be NULL. Note: At least of one list of recipients (To, CC, or BCC) must not be NULL.

Return : Description :

Number of attachement files sent (0 if none), or an negative error code. This function can be used to send an unique message. It automatically performs the sequence:
SMTP_Connect(), SMTP_Send() SMTP_Disconnect()

SMO/SFO-0039

Rv. : H

Page : 22

10.

POP3

10.1 CONNECTION TO THE SERVER Syntax : POP3_HANDLE POP3_Connect (const char *szPop3Server, int nPort, const char *szLogin, const char *szPassword, char bSecuredConnection ); < POP3_.h >

Include : Parameters :

szSMTPServer: nPort: szLogin: szPassword: bSecuredConnection: Return : Description :

TCP/IP address of the POP3 server. POP3 server port (usually 110). User name. Password associated to the user name. Reserved for future use.

Returns the connection handle (>=0), or a negative error code. This function connects the terminal to the POP3 server. This connection requires an authentication.

10.2 DISCONNECTION FROM THE SERVER Syntax : Include : Parameters : handle: Return : Handle on the connection to close. None. void POP3_Disconnect( < POP3_.h > POP3_HANDLE handle );

Description :

This function disconnects the terminal from the SMTP server.

SMO/SFO-0039

Rv. : H

Page : 23

10.3 REQUESTING THE NUMBER OF MESSAGES Syntax : int POP3_GetNbMessages( POP3_HANDLE int *nTotalSize ); handle,

Include : Parameters : handle:

< POP3_.h >

Handle on the connection,

nTotalSize: Pointer to an integer to fill with the global size of the messages currently into the open mail account. This pointer may be NULL if this value is not needed. Return : The number of messages currently into the mail account. This number includes all the messages (new messages and those already read). This function returns the number of message present on the mail account, and, if required, the total size occupied by the messages.

Description :

10.4 REQUESTING A GIVEN MESSAGE Syntax : int POP3_GetMessage( POP3_HANDLE handle, int nMessageIndex, POP3_INFO *pPop3Info, char *szBufferBody, int nBufferSize );

Include : Parameters : handle:

< POP3_.h >

Handle on the connection, Number of the message to retrieve from the POP3 server. The index of the first message (oldest one) is 1. A pointer to the structure that will be filled with data extracted from the header, and important message characteristics. Please note that the buffers (see POP3_INFO description below) containing these data are 128 bytes long. If the content

nMessageIndex:

pPop3Info:

SMO/SFO-0039

Rv. : H

Page : 24

in the message's header is longer than 128 bytes, the data will be truncated to fit with buffer size. szBufferBody: Buffer to fill with the body of the message. This parameter can be NULL, whether only the info structure is requested.

Note: The content of the body is US-ASCII text only. Thus, any mail containing other elements, like MIME encoding parts, has to be processed by the user. nBufferSize: Maximum size of the buffer allocated to receive the body of the message.

Return : Description :

0, or a negative error code. This function returns the given message, with, the header on the info structure, and the body in a separate buffer.

typedef struct { char szSubject char szFrom char szDate char szTo char szCC char szUIDL int } POP3_INFO;

[_POP3_HEADER_LINE_SIZE]; [_POP3_HEADER_LINE_SIZE]; [_POP3_HEADER_LINE_SIZE]; [_POP3_HEADER_LINE_SIZE]; [_POP3_HEADER_LINE_SIZE]; [_POP3_HEADER_LINE_SIZE]; nSize;

// // // // // // //

Subject of the message Sender of the message Date Recipicient(s) Recipicient(s) in copy Unique identifier for the message Size of the message (in bytes)

Note: this function does not delete the message on the POP3 server. Hence, a new request to this same message is valid.

10.5 DELETING A GIVEN MESSAGE Syntax : int POP3_DeleteMessage( POP3_HANDLE handle, int nMessageIndex ); < POP3_.h >

Include : Parameters : handle:

Handle on the connection. Index of the message to delete from the POP3 server. The index of the first message (oldest one) is 1.

nMessageIndex:

SMO/SFO-0039

Rv. : H

Page : 25

Return :

0, or a negative error code.

Description : This function deletes a given message.

10.6 RESET THE SESSION Syntax : Include : Parameters : handle: Return : Handle on the connection. 0, or a negative error code. int POP3_Reset( POP3_HANDLE handle ); < POP3_.h >

Description : This function reset the session. It cancels the deletion of the messages performed during the current session.

SMO/SFO-0039

Rv. : H

Page : 26

11.

HTTP/HTTPS SERVER

The package TCP/IP provides functions to easily manage the HTTP/HTTPS server facility. It enables to launch a simple HTTP/HTTPS server and to process the incoming requests (GET, POST and PUT). An HTTP sample is given in the section : 13.5. HTTP sample (page 41). Note: to use the HTTPS facility, the SSL DLL must be loaded in the terminal and the application must be linked with SSL_.lib library.

11.1 LAUNCH THE SERVER Syntax : int HTTP_Server_Open ( HTTP_SERVER_HANDLE *hHandle, unsigned int nPort, const char *szDestDisk ); int HTTPS_Server_Open ( HTTP_SERVER_HANDLE *hHandle, unsigned int nPort, const char *szDestDisk, const char* szSslProfile, int bUseCache, int bCheckPeer ); Include : Parameters : hHandle: nPort: szDestDisk: Handle on the HTTP(S) server. Listening port (usually 80 for HTTP and 443 for HTTPS). Disk name where the server stores the downloaded files. This parameter can be set to NULL: in that case, the server won't store any files. Name of the SSL profile - HTTPS server only. Set to TRUE to use SSL session cache, FALSE otherwise HTTPS server only. Set to TRUE to check peer certificate (mutual authentication), FALSE otherwise (simple authentication) HTTPS server only. With simple authentication, the server does not authenticate the client (but the client does authenticate the server). < HTTP_.h >

szSslProfile: bUseCache:

bCheckPeer:

Return :

Returns HTTP_SERVER_OK or a negative error code.

SMO/SFO-0039

Rv. : H

Page : 27

Error Code

Comment

HTTP_SERVER_OK HTTP_SERVER_ERROR_MEMORY HTTP_SERVER_ERROR_SOCKET HTTP_SERVER_ERROR_DISK HTTP_SERVER_ERROR_INVALID_PROFILE

The function succeeds. The server is launched. Memory error for the handle allocation. Cannot create or activate the listening socket. Cannot mount the destination disk.

Cannot load the SSL profile. Cannot open the SSL DLL : is it HTTP_SERVER_ERROR_SSL_DLL_NOT_FOUND loaded in the terminal ?

Description :

This function starts the HTTP server on the given port. A handle is allocated and returned. The function mounts the destination disk. This disk is unmounted when the server is stopped (see function HTTP_Server_Close() described below).

Note:

11.2 WAIT FOR A REQUEST Syntax : int HTTP_Server_WaitRequest ( HTTP_SERVER_HANDLE hHandle, unsigned int nTimeout HTTP_SERVER_DATA **pRequest ); int HTTPS_Server_WaitRequest ( HTTP_SERVER_HANDLE hHandle, unsigned int nTimeout HTTP_SERVER_DATA **pRequest ); Include : Parameters : hHandle: nTimeout: pRequest : Return : Handle on the HTTP/HTTPS server. Duration to wait for a request. A pointer on the decoded HTTP request. < HTTP_.h >

Returns HTTP_SERVER_OK or a negative error code.

SMO/SFO-0039

Rv. : H

Page : 28

Error Code

Comment

The function succeeds. A request has been received, HTTP_SERVER_OK decoded and returned. Timeout expired. No request HTTP_SERVER_ERROR_TIMEOUT received. HTTP_SERVER_ERROR_HANDLE Invalid handle parameter. Request refused. The HTTP_SERVER_ERROR_SOCKET dedicated socket can not be created. Nothing received from the HTTP_SERVER_ERROR_CLIENT_TIMEOUT client in the last 10 seconds. HTTP_SERVER_ERROR_CLIENT_SOCKET Error on client socket. Unable to parse the request HTTP_SERVER_ERROR_MALFORMED_REQUEST properly.

Description :

This function waits for the reception of an HTTP request. The request is decoded and returned in the parameter of type HTTP_SERVER_DATA (described below). The function creates a connection dedicated to the treatment of the request. The pointer on the request is internally allocated, it must not be released by the application. If the call to HTTP_Server-WaitRequest() function is successful (return code equal to HTTP_SERVER_OK), a call to HTTP_SendResponse() is mandatory to terminate the dedicated connection properly. For any other return codes, the connection with the client, if established, is automatically closed.

Note:

The requests sent to the server are automatically decoded and stored in a structure of type HTTP_SERVER_DATA described below.
typedef struct { // Request char m_nCommand; // HTTP Command char m_szHttpVersion[4]; // HTTP Version (0.9, 1.0 or 1.1) char m_szURI[HTTP_SERVER_MAX_URI]; // Address of the requested page // Header parameters short m_nHeaderParamNb; char m_szHeaderParamName [][]; char m_szHeaderParamValue[][]; short m_nBoundaryPos; // Data short m_nDataNumber;

// // // //

Number of elements in the header Name of the parameter Value of the parameter Internal use only

// Number of data

SMO/SFO-0039

Rv. : H

Page : 29

char m_szDataName [][]; short m_nFileIndex []; char m_szDataValue[][]; // Files short m_nFileNumber; char m_szFilename [][]; char m_szFileType [][]; char m_szFsFileName[][]; int m_nFileLength [];

// Name of the current data // Internal use // Value of the current data

// // // // //

Number of files in the data Name of the received file Type of the received file Name of the file saved in the file system Length of the file (in bytes)

// Added int m_nContentLength; // Value of the Content-Length parameter (if any) char m_szBoundary[]; // HTTP Boundary (if any) // Client information char m_szClientAddress[]; int m_nClientPort; } HTTP_SERVER_DATA;

// Address of the client // Client port

Common parameters m_nCommand: type of the HTTP command received in the request. Can be : o o o o HTTP_SERVER_GET. HTTP_SERVER_POST. HTTP_SERVER_PUT. HTTP_SERVER_UNKNOWN_COMMAND.

m_szHttpVersion: a string representing the HTTP version of the request. m_szURI: a string representing the address of the requested page ("/" or "/INDEX.HTML" for example). This string is always internally set to upper case, to be compliant with Telium File System syntax.

Header parameters m_nHeaderParamNb: the number of elements in the header. A maximum of 32 elements are stored. m_szHeaderParamName[nIndex]: a string storing the name of the nIndexth parameter (for example: "Content Length"). The maximum length of this string is 32 bytes. m_szHeaderParamValue[nIndex]: a string storing the value of the nIndexth parameter. The maximum length for this value is 64 bytes. m_nBoundaryPos: internal use only.

Data parameters (for POST and PUT only) m_nDataNumber: the number of data elements in the request. A maximum of 32 elements are stored. m_szDataName[nIndex]: a string storing the name of the nIndexth data element. The maximum length of this string is 32 bytes. m_nFileIndex: internal use only.

SMO/SFO-0039

Rv. : H

Page : 30

m_szDataValue[nIndex]: a string storing the value of the nIndexth data element. The maximum length for this value is 64 bytes.

File parameters (for POST and PUT only): m_nFileNumber: number of files retrieved. A maximum of 6 files can be loaded using one request. m_szFilename[nIndex]: the name of the nIndexth downloaded file directly taken from the request. The real name of the file saved in flash is put m_szFlashFileName[nIndex] (see below). The maximum length of this string is 32 bytes. If the request is sent with a name that includes '/' or '\' (full path to a file), only the string after the separator is read and stored in the buffer. m_szFileType[nIndex]: a string describing the type of the nIndexth downloaded file. The maximum length of this string is 32 bytes. m_szFsFileName[nIndex]: the name of the file stored in the server disk. The name is adapted from m_szFileName[nIndex] to be compliant with Telium File System requirements (length of the name and characters supported). m_szFileLength[nIndex]: length of the file (in bytes).

Note: the files received through POST and PUT methods are automatically stored in the disk specified when calling HTTP_Server_Open() function. If the file name already exists in the disk, the new file is not downloaded to the disk, and is not added to the data structure. In a request containing raw data after the header (not separated by boundaries), the data received by the server is stored in a file named "HTTP_R<n>.BIN" when <n> is the file index coded in 4 hexadecimal digits format Other parameters Example The client sends a post request through the HTML form below.
<H1> File selection </H1> <FORM ENCTYPE="multipart/form-data" ACTION="ProcessRequest" METHOD=POST> <INPUT TYPE=HIDDEN NAME="DATA_ONE" VALUE="Value of data one"> <INPUT TYPE=FILE SIZE=80 NAME="filename"> <INPUT TYPE=HIDDEN NAME="DATA_TWO" VALUE="2222222"> <INPUT TYPE=SUBMIT VALUE= "Send"> </FORM>

m_nContentLength: value of the parameter "Content-Length" of the request. m_szBoundary: HTTP boundary found in the request. m_szClientAddress: address of the client (aaa.bbb.ccc.ddd). m_nClientPort: port of the client.

The data structure is filled with the content of the request: the selected file is "test.txt", the request is sent using a web browser. The file "test.txt" is automatically stored in the disk specified in the HTTP_Server_Open() function. Page : 31

SMO/SFO-0039

Rv. : H

m_nCommand: m_szHttpVersion: m_szURI: m_nHeaderParamNb: m_szHeaderParamName[0]: m_szHeaderParamValue[0]: m_szHeaderParamName[1]: m_szHeaderParamValue[1]: m_nDataNumber: m_szDataName[0]: m_szDataValue[0]: m_szDataName[1]: m_szDataValue[1]: m_szDataName[2]: m_szDataValue[2]: m_nFileNumber: m_szFileName[0]: m_szFsFileName[0]: m_nFileLength[0]: m_nContentLength: m_szBoundary: m_szClientAddress: m_nClientPort:

HTTP_SERVER_POST "1.1" "/PROCESSREQUEST" 12 "Host" "192.168.45.2" "User Agent" "Mozilla/5.0" 3 "DATA_ONE" "Value of data one" "filename" "" "DATA_TWO" "2222222" 1 "test.txt" "TEST.TXT" 146 314 "---------------------------AZY845S" "192.168.45.61" 32718

11.3 SEND A RESPONSE Syntax : int HTTP_Server_SendResponse ( HTTP_SERVER_HANDLE hHandle, const char *pcBuffer, unsigned int nDataSize); int HTTPS_Server_SendResponse ( HTTP_SERVER_HANDLE hHandle, const char *pcBuffer, unsigned int nDataSize); Include : Parameters : hHandle: pcBuffer : nDataSize : Return :
Error Code

< HTTP_.h >

Handle on the HTTP server. Buffer containing the response to send Size of the buffer response

Returns HTTP_SERVER_OK or a negative error code.


Comment

HTTP_SERVER_OK HTTP_SERVER_ERROR_HANDLE

The function succeeds. The server has sent the request. Invalid handle parameter

SMO/SFO-0039

Rv. : H

Page : 32

HTTP_SERVER_ERROR_NO_REQUEST No request is currently in progress. HTTP_SERVER_ERROR_SERVER_CLOSED The server is not running. HTTP_SERVER_ERROR_SOCKET Error on server listening socket. Description : This function sends an HTTP response and then close the dedicated connection. It must be called after the success of the call to the function HTTP_Server_WaitRequest().

11.4 STOP THE SERVER Syntax : int HTTP_Server_Close ( HTTP_SERVER_HANDLE hHandle ); int HTTPS_Server_Close ( HTTP_SERVER_HANDLE hHandle ); Include : Parameters : hHandle: Return :
Error Code

< HTTP_.h >

Handle on the HTTP server. Returns HTTP_SERVER_OK or a negative error code.


Comment

HTTP_SERVER_OK HTTP_SERVER_ERROR_HANDLE Description :

The function succeeds. The server has been stopped. Invalid handle parameter

This function stops the HTTP server and releases the handle and all the resources used by the server. The destination folder is unmounted.

Note :

11.5 GET INFORMATION ABOUT SSL SESSION (HTTPS ONLY) Syntax : int HTTPS_Server_GetHandles ( HTTP_SERVER_HANDLE hHandle, SSL_HANDLE* phSession, SSL_PROFILE_HANDLE* phProfile )

Include : Parameters : hHandle:

< HTTP_.h >

Handle on the HTTP server.

SMO/SFO-0039

Rv. : H

Page : 33

phSession: phProfile: Return :


Error Code

Handle on the current SSL connection. Handle on the server SSL profile.

Returns HTTP_SERVER_OK or a negative error code.


Comment

HTTP_SERVER_OK HTTP_SERVER_ERROR_HANDLE Description :

The function succeeds. Invalid handle parameter

This function retrieves the handles on the SSL connection and on the server SSL profile. phSession will only return a non NULL value while a connection with a client is established (between a successful call to HTTPS_Server_ WaitRequest() and HTTPS_Server_SendResponse()). phProfile will return a non-NULL value ever since the HTTPS server is successfully launched.

Note :

SMO/SFO-0039

Rv. : H

Page : 34

12.

COMPATIBILITY

The package TCP/IP is compatible with BSD interface. However, it exists some differences, listed below. The "shutdown" function is renamed "shutdownsocket". The "select" function is renamed "selectsocket". The functions "gethostbyname" and "gethostbyaddr" are deprecated and replaced respectively by the functions : "gethostbyname_r" and "gethostbyaddr_r". The functions "inet_addr", "inet_aton" and "inet_ntoa" are deprecatated and replaced respectively by the functions :"__inet_addr", "__inet_aton" and "__inet_ntoa".

SMO/SFO-0039

Rv. : H

Page : 35

13.

SAMPLE PROGRAMS

13.1 PPP SAMPLE This section provides a simply sample to show how to perform a PPP connection through the GSM link. After connecting the PSTN provider in GSM, just call the following function.
int PPP_Connect( char *szLogin, char *szPassword ) { int nState = 0; PPP_HANDLE nHandle = 0; int i = 0; nHandle = PPP_Open( "DGPRS" ); if( nHandle != 0 ) { PPP_Setup( nHandle, szLogin, szPassword, PPP_PSTN_PROFILE ); PPP_Start( nHandle ); do { nState = PPP_GetState( nHandle ); ttestall( 0, 100 ); } while(( i < 60 ) && ( nState != PPP_STATE_IFUP) && ( nState != PPP_STATE_DEAD));

if( nState == PPP_STATE_IFUP) { // Connection success. return 0; } } return -1; }

The PPP configuration can be made accurately by the user.


... void *arg = 0; // The minimal configuration : // Just the login and the password are set. PPP_Setup( nHandle, szLogin, szPassword, PPP_PERSONAL_PROFILE );

SMO/SFO-0039

Rv. : H

Page : 36

// Set several options. //-----------------------------// Ask for peer authentication. arg = PPP_TRUE; PPP_SetOption( nHandle, PPP_INFO_LCP_AUTH, &arg );

// Negociate DNS1 address, but not DNS2 arg = PPP_TRUE; PPP_SetOption ( nHandle, PPP_INFO_IPCP_DNS1, &arg ); arg = PPP_INT(0); PPP_SetOption( nHandle, PPP_INFO_IPCP_DNS1_ADDR, &arg); arg = PPP_FALSE; PPP_SetOption( nHandle,PPP_INFO_IPCP_DNS2, &arg ); ...

13.2 ETHERNET SAMPLE The following code shows how to get the information of the Ethernet link (local IP address and the network mask).
void PrintNetworkInfos() { char szTemp[BUFFER_SIZE]; unsigned char *p; unsigned int local_addr = 0; unsigned int netmask_addr = 0; EthernetGetOption( ETH_IFO_ADDR, &local_addr ); EthernetGetOption( ETH_IFO_NETMASK, &netmask_addr ); p = (char *) &local_addr; sprintf( szTemp, "Local Addr: %d.%d.%d.%d\n", p[0], p[1], p[2], p[3] ); ... p = (char *) &netmask_addr; sprintf( szTemp, "Netmask: %d.%d.%d.%d\n", p[0], p[1], p[2], p[3] ); ... }

SMO/SFO-0039

Rv. : H

Page : 37

13.3 ENABLE/DISABLE THE ICMP REPLY FACILITY This sample code below shows how to enable or disable the ICMP reply facility. It demonstrates how to modify the default parameters.

void ActivateReplyICMP( int bOn ) { ETHCONF_HANDLE hConf = __LoadDefaultOptions( NULL ); if( hConf != NULL ) { int bEchoReply; if( __GetDefaultOption( hConf, __DFL_ICMP_ECHO_REPLY, &bEchoReply ) == __DLF_OK ) { if( bEchoReply != bOn ) { // Modify the option. __SetDefaultOption( hConf, __DFL_ICMP_ECHO_REPLY, &bOn ); // Save the configuration. The terminal reboots automatically. __SaveDefaultOptions( hConf ); } } __UnloadDefaultOptions( hConf ); } }

13.4 MAIL SAMPLE


The sample code below shows how to send and receive an email using the dedicated interface.

void SendMail( const char* szSubject, const char* szMessage ) { int nReturn; int nPort = 25; char szSmtpAddress[] = "123.123.123.123"; char szLogin[] = "myaccount"; char szPassword[] = "mypassword"; char szSmtpClient[] = "TELIUM_CLIENT"; char szFrom[] = "myaccount@myprovider.com"; char szTo[] = "recipient1@server.com,recipient2@server.com"; char szCC[] = "recipientcc@server.com"; const char *pList[] = { "/HOST/FILE1.TXT", "/TEMP/FILE2.BIN", NULL // Last item must be NULL !!! };

SMO/SFO-0039

Rv. : H

Page : 38

nReturn = SMTP_SendUniqueMessage( szSmtpAddress, nPort, szLogin, szPassword, szSmtpClient, szMessage, strlen( szMessage ), szSubject, szFrom, szTo, szCC, NULL, // No recipient in blind copy pList ); if( nReturn == 2 ) { // Both attached files where successfully sent } else { if( nReturn >= 0) { // At least one attached file was not sent // The message is sent without this (these) file(s) } else { // The mail was not sent } } }

void ReceiveMail( void ) { POP3_HANDLE hPop; POP3_INFO Info; int nMessages; int nTotalSize; int bDeleteFromServer = FALSE; int nPort = 110; int nIndex; int nReturn; char szPopAddress[] = "123.123.123.123"; char szLogin[] = "mylogin"; char szPassword[] = "mypassword"; char* pcBuffer; ... hPop = POP3_Connect( szPopAddress, nPort, szLogin, szPassword, FALSE ); if( hPop >= 0 ) { // Retrieve the number of message on the account nMessages = POP3_GetNbMessages( hPop, &nTotalSize );

SMO/SFO-0039

Rv. : H

Page : 39

if( ( nMessages > 0 ) && ( nTotalSize > 0 ) ) { // Allocate buffer for the total size of the messages // to avoid any overflow pcBuffer = umalloc( nTotalSize ); if( pcBuffer != NULL ) { for( nIndex = 1; nIndex <= nMessages; nIndex++ ) { // Retrieve the message nReturn = POP3_GetMessage( hPop, nIndex, &Info, pcBuffer, nTotalSize ); if( nReturn == 0 ) { // A message is received ... // Erase the message from the server if( bDeleteFromServer == TRUE ) { POP3_DeleteMessage( hPop, nIndex ); } } else { // Error on receiving the message } } ufree( pcBuffer ); } else { // Can't allocate memory } } else { // No message } POP3_Disconnect( hPop ); } else { // Can't connect to server } }

SMO/SFO-0039

Rv. : H

Page : 40

13.5 HTTP SAMPLE The following code shows how to launch an HTTP server and how to process the GET requests.

static void ServerHTTP() { int nError; HTTP_SERVER_HANDLE hServerHTTP; HTTP_SERVER_DATA *pRequest; unsigned int char char unsigned int S_FS_FILE nMode; szFullURI[200]; szDataToSend[4096]; nDataSize; *hFile;

// Launch the HTTP server. // The folder which the folder HOST for destination directory. if( HTTP_Server_Open( &hServerHTTP, 80, "/HOST" ) != HTTP_SERVER_OK ) { // Error. return; } // Mount the disk with the HTTP Files. FS_mount( "/HOST", &nMode ); while(1) { // Wait for a request. nError = HTTP_Server_WaitRequest ( hServerHTTP, 80, &pRequest ); if ( nError == HTTP_SERVER_OK ) { strcpy( szFullURI, "/HOST" ); if ( pRequest->m_nCommand == HTTP_SERVER_GET ) { // GET Command if ( strcmp( pRequest->m_szURI, "/" ) == 0 ) { // Request the default web page. strcat( szFullURI, "/INDEX.HTML" ); } else { // Request a given page. strcat(szFullURI, pRequest->m_szURI); } // Open the page file. hFile = FS_open(szFullURI, "r"); if (hFile == NULL) {

SMO/SFO-0039

Rv. : H

Page : 41

// Problem to open the file. // Return the default error page. strcpy(szDataToSend, HTTP_SERVER_PAGE_404); nDataSize = strlen(HTTP_SERVER_PAGE_404); } else { // Read the page file. strcpy(szDataToSend, HTTP_SERVER_HTTP_200); nDataSize = strlen(HTTP_SERVER_HTTP_200); nDataSize += FS_read( szDataToSend + nDataSize, 1, 4096, hFile); FS_close(hFile); } // Send the page response HTTP_Server_SendResponse( hServerHTTP, szDataToSend, nDataSize ); } } }

SMO/SFO-0039

Rv. : H

Page : 42