Honestly, I can't really follow all
your mails here. I lost trace of what's good and what's bad.
I'm in the process of adding httpd examples to the contrib
repository. Your CGI/generated file combination is one of the
next.
I'd suggest that I push my example (hopefully next week) and
then let's discuss your thoughts again by sharing diffs. Looking
at diffs is *much* easier than following 5 emails of textual
descriptions...
Simon
Giuseppe Modugno:
I need to answer to GET
/login.cgi?user=admin&pwd=admin request with
JSON data. The answer depends on parameters user and pwd
passed as query string.
I can't create the answer in fs_open_custom(), because
parameters aren't available. Even the answer buffer can't be
allocated in fs_open_custom(), because the answer length isn't
known yet. In CGI handler I can allocate and create the
answer, however I can't set the file content, because I can't
access file structure.
One solution is to use LWIP_HTTPD_DYNAMIC_FILE_READ
and implement a trivial fs_read_custom(). I think a better
solution could be to use LWIP_HTTPD_FILE_STATE, set
file->state as file in fs_open_custom() and set file
content in CGI handler.
int fs_open_custom(struct fs_file *file, const char
*name) {
if (!strcmp(name, "/login.cgi")) {
file->state = file;
}
}
void httpd_cgi_handler(const char *filename, int
iNumParams, char **pcParam, char **pcValue, void
*file_state) {
if (!strcmp(filename, "/login.cgi")) {
struct fs_file *file = (struct fs_file
*)file_state;
void *reply_buf =
malloc(answer_length);
file->data = "">
file->len = file->index =
strlen(reply_buf);
}
This doesn't work, because in http_init_file() hs->handle,
hs->file and hs->left are assigned before
calling CGI httpd_cgi_handler().
However this could work if httpd_cgi_handler() is moved before
assigning hs->handle, hs->file and hs->left. I tried
and it seems it works.
IMHO another good modification could be to pass file to
httpd_cgi_handler(), instead of only file->state. In the
handler, you will have the access to file and file->state.
With this change, you could avoid assigning
file->state=file in fs_open_custom() that could be empty.
_______________________________________________
lwip-devel mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/lwip-devel