| Description | | The cgi_process_data function processes the data returned from the CGI form POST method. The HTTP server calls this function when a user presses the SUBMIT button on the input form, using a web browser. | Code | Data Type | Meaning of dat pointer | Meaning of len |
|---|
| 0 | Form data | Pointer to data string returned from the POST method. | Length of data string. | | 1 | Filename | Pointer to a Filename for the http file upload. Filename is a 0-terminated string. | Length of a filename. | | 2 | File data | Pointer to data packet received from the host. | Length of data packet. | | 3 | End of file | NULL | Don't care. |
The cgi_process_data function is part of RL-TCPnet. The prototype is defined in net_config.h. You can customize the function in http_cgi.c. note |
| Example | |
void cgi_process_data (U8 code, U8 *dat, U16 len) {
U8 passw[12], retyped[12];
U8 var[40], stpassw;
switch (code) {
case 0:
/* Url encoded form data received. */
break;
case 1:
/* Filename for file upload received as encoded by the browser. */
/* It might contain an absolute path to a file from the sending */
/* host. Open a file for writing. */
return;
case 2:
/* File content data received. Write data to a file. */
/* This function will be called several times with */
/* code 2 when a big file is being uploaded. */
return;
case 3:
/* File upload finished. Close a file. */
return;
default:
return;
}
if (len == 0) {
/* No data, or all items (radio, checkbox) are off. */
return;
}
stpassw = 0;
do {
/* Parse all returned parameters. */
dat = http_get_var (dat, var, 40);
if (var[0] != 0) {
/* Parameter found, returned string is non 0-length. */
if (str_scomp (var, "pw=") == __TRUE) {
/* Change password. */
str_copy (passw, var+3);
stpassw |= 1;
}
else if (str_scomp (var, "pw2=") == __TRUE) {
/* Retyped password. */
str_copy (retyped, var+4);
stpassw |= 2;
}
}
}while (dat);
if (stpassw == 0x03) {
len = strlen (passw);
if (mem_comp (passw, retyped, len) == __TRUE) {
/* OK, both entered passwords the same, change it. */
str_copy (http_auth_passw, passw);
}
}
}
|