Network Component
Version 7.19.0
MDK Middleware for IPv4 and IPv6 Networking
|
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... | |
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:
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:
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:
void netHTTPs_fclose | ( | void * | file | ) |
Close a file previously open on HTTP server. [interface].
[in] | file | pointer to the file to close. |
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.
char * netHTTPs_fgets | ( | void * | file, |
char * | buf, | ||
uint32_t | size | ||
) |
Read a string from a file on HTTP server. [interface].
[in] | file | pointer to the file to read from. |
[out] | buf | output buffer to write data to. |
[in] | size | size of output buffer. |
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.
void * netHTTPs_fopen | ( | const char * | fname | ) |
Open a file for reading on HTTP server. [interface].
[in] | fname | name of the file to open. |
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.
uint32_t netHTTPs_fread | ( | void * | file, |
uint8_t * | buf, | ||
uint32_t | len | ||
) |
Read block of data from a file on HTTP server. [interface].
[in] | file | pointer to the file to read from. |
[out] | buf | block of memory to write data to. |
[in] | len | length of data to read in bytes. |
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.
void netHTTPs_fstat | ( | const char * | fname, |
uint32_t * | fsize, | ||
uint32_t * | ftime | ||
) |
Retrieve file size and last modification time. [interface].
[in] | fname | name of the file. |
[out] | fsize | file size in bytes. |
[out] | ftime | created or last modified time. |
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.