Network Component  Version 7.19.0
MDK Middleware for IPv4 and IPv6 Networking
File System Interface

HTTP server functions that work with a File System. More...

Functions

void * netHTTPs_fopen (const char *fname)
 Open a file for reading on HTTP server. [interface]. More...
 
void netHTTPs_fclose (void *file)
 Close a file previously open on HTTP server. [interface]. More...
 
uint32_t netHTTPs_fread (void *file, uint8_t *buf, uint32_t len)
 Read block of data from a file on HTTP server. [interface]. More...
 
char * netHTTPs_fgets (void *file, char *buf, uint32_t size)
 Read a string from a file on HTTP server. [interface]. More...
 
void netHTTPs_fstat (const char *fname, uint32_t *fsize, uint32_t *ftime)
 Retrieve file size and last modification time. [interface]. More...
 

Description

HTTP server functions that work with a File System.

All File System Interface functions are located in HTTP_Server_FS.c, which will be automatically added to your project's Network folder. The file is preconfigured for the , so no modifications are required. If you wish to use another type of file system, you need to override these weak procedures with your required functionality.

The following functions are implemented in this module:

Web on SD Card

The Web Server supports storing of web pages on a SD Card, which is attached to the embedded system. This is useful if you want to update or change the web content remotely. In this case, the File System Component is used, which must be configured for a target device Memory Card Drive.

You can use any of the update methods to change the content of web pages:

Web Update

When the Web Server tries to open a web page, it searches the external file system first. This is usually an externally attached SD Card. As the Compact Web Server is not configured to use an external file system, it searches only the internal ROM file system.

If the requested file is found on the SD Card, the content is sent to the web client. If the requested file does not exist on the SD Card, it is opened from the internal ROM file system and transferred to the web client. This concept allows you to replace easily the web content from the internal ROM file system with a new one stored on the external SD Card.

You should carefully update the cgi and cgx script files, as changes in the script files usually need to be reflected in the application code, which is in the module HTTP_Server_CGI.c. If you have made a mistake in the uploaded script files, the web pages might not be accessible any more.

To enable the SD-Card File System, you need the select the Web Server in the Manage Run-Time Environment window under Network:Service:

Function Documentation

◆ netHTTPs_fclose()

void netHTTPs_fclose ( void *  file)

Close a file previously open on HTTP server. [interface].

Parameters
[in]filepointer to the file to close.
Returns
none.

The function netHTTPs_fclose closes the file identified by the file stream pointer in the function argument.

The function interfaces to the File System Component and will be called by the Network Component automatically. If another file system will be used, refer to the reference implementation in the HTTP_Server_FS.c module.

◆ netHTTPs_fgets()

char * netHTTPs_fgets ( void *  file,
char *  buf,
uint32_t  size 
)

Read a string from a file on HTTP server. [interface].

Parameters
[in]filepointer to the file to read from.
[out]bufoutput buffer to write data to.
[in]sizesize of output buffer.
Returns
status information:
  • Pointer to string on success.
  • NULL in case of an error.

The function netHTTPs_fgets reads up to size bytes from the file identified by the file stream pointer in the function argument.

The argument buf is a pointer to the buffer which stores the data.

The function interfaces to the File System Component and will be called by the Network Component automatically. If another file system will be used, refer to the reference implementation in the HTTP_Server_FS.c module.

Note
The function is used by the script interpreter.

◆ netHTTPs_fopen()

void * netHTTPs_fopen ( const char *  fname)

Open a file for reading on HTTP server. [interface].

Parameters
[in]fnamename of the file to open.
Returns
status information:
  • Pointer to an open file.
  • NULL in case of an error.

The function netHTTPs_fopen opens a file for reading.

The argument fname specifies the name of the file to open. If the file does not exist, the function fails and returns NULL. fname is percent-encoded. This means that all reserved characters in a file name are escaped.

The function interfaces to the File System Component and will be called by the Network Component automatically. If another file system will be used, refer to the reference implementation in the HTTP_Server_FS.c module.

◆ netHTTPs_fread()

uint32_t netHTTPs_fread ( void *  file,
uint8_t *  buf,
uint32_t  len 
)

Read block of data from a file on HTTP server. [interface].

Parameters
[in]filepointer to the file to read from.
[out]bufblock of memory to write data to.
[in]lenlength of data to read in bytes.
Returns
number of bytes successfully read.

The function netHTTPs_fread reads len bytes from the file identified by the file stream pointer in the function argument.

The argument buf is a pointer to the buffer where the function stores the read data.

The function interfaces to the File System Component and will be called by the Network Component automatically. If another file system will be used, refer to the reference implementation in the HTTP_Server_FS.c module.

Note
The function must read len bytes. The Web Server stops reading and closes the file if the return value is less than len bytes.

◆ netHTTPs_fstat()

void netHTTPs_fstat ( const char *  fname,
uint32_t *  fsize,
uint32_t *  ftime 
)

Retrieve file size and last modification time. [interface].

Parameters
[in]fnamename of the file.
[out]fsizefile size in bytes.
[out]ftimecreated or last modified time.
Returns
none.

The function netHTTPs_fstat reads the size of a file and the time when the file was last modified.

The argument fname identifies the file for which the information is to be retrieved.

The function interfaces to the File System Component and will be called by the Network Component automatically. If another file system will be used, refer to the reference implementation in the HTTP_Server_FS.c module.