lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] httpd: how to implement AJAX


From: Giuseppe Modugno
Subject: Re: [lwip-users] httpd: how to implement AJAX
Date: Wed, 22 Nov 2017 17:07:13 +0100
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0

Il 13/11/2017 21:25, address@hidden ha scritto:
Giuseppe Modugno wrote:
The prototype for SSI callbacks is:
[..]
I don't see any reference to query string parameters. So how to select the right action?

Sorry for the confusion. This is a mix of resource optimization, missing documentation and maybe missing framework functions.

The idea is that we don't want to keep the http request pbuf(s) around until the end of the SSI file is transmitted (which might be long).
Instead, this is done in three steps:
- fs_open() calls fs_state_init(file, name) to create an object big enough to hold everything you'd need for 'file'
  (for custom files, you'll have to call this yourself)
- httpd_cgi_handler() can parse everything needed and store it in this object
- the SSI handler gets this object, too, and can access the content required
(- or alternatively, in a custom read function, you might direclty access file->state)
I'm trying to implement what you wrote, using "custom files" instead of SSI. I think something doesn't work.

Suppose I have a CGI script that the client requests with a GET /login.cgi?auth=pippo:pluto
fs_open_custom() returns 1 if "login.cgi" is passed as filename. However here I'm not able to create the answer, because I need to evaluate the query string parameters (that I will do in CGI handler). So I can't do much in fs_open_custom() and I don't know how to set file->data, file->line and file->index.

In CGI handler I'm ready to create the full answer because I have the query string, maybe in a buffer allocated with malloc and saved in file->state pointer.

The problem here is fs_read_custom() is never called, because LWIP_HTTPD_DYNAMIC_FILE_READ isn't defined. Is really needed to define LWIP_HTTPD_DYNAMIC_FILE_READ in this scenario? This macro will allocate a dynamic output buffer in http_state and call fs_read_custom() that will limit to copy all or part of data created in CGI to the buffer of http_state. It seems too complex for this scenario.

In CGI handler I could set all the "file info" in http_state (length and pointer), however http_state isn't accessible from this point.


One thing I can't understand. It's index member of struct fs_file. It is initialized as the length of file content if fs_open(), for non custom files. And it is used in:

  int fs_bytes_left(struct fs_file *file) {

    return file->len - file->index;
  }

So after fs_bytes_left() is zero immediately after fs_open(). This sounds strange to me. Maybe index isn't the pointer to unsent data (it should be zero after open), but to the pointer of the next byte to read from file (and for "static" files, there's no other data to read after open, because all data is ready immediately).



reply via email to

[Prev in Thread] Current Thread [Next in Thread]