patchlwIP - A Lightweight TCP/IP stack - Patches: patch #9501, httpd: move httpd_cgi_handler()...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

patch #9501: httpd: move httpd_cgi_handler() call

Submitter:  Giuseppe Modugno <giusloq>
Submitted:  Mon 27 Nov 2017 09:18:41 AM UTC
   
 
Category:  apps Priority:  5 - Normal
Status:  Done Privacy:  Public
Assigned to:  goldsimon Open/Closed:  Closed
Planned Release:  2.1.0

Fri 02 Feb 2018 08:32:01 AM UTC, comment #2: 

Applied, thanks for the patch.

Simon Goldschmidt <goldsimon>
Group administrator
Thu 01 Feb 2018 06:58:27 PM UTC, comment #1: 


> IMHO another good modification could be to pass file to httpd_cgi_handler()


That would be good, too, indeed.

Simon Goldschmidt <goldsimon>
Group administrator
Mon 27 Nov 2017 09:18:41 AM UTC, original submission:  

This patch moves in advance httpd_cgi_handler() call, before assigning variables like hs->file and hs->left.

In this way, CGI handler could prepare the reply data and set the "file properties", like file->data and file->len. At the exit, hs->file and hs->left is correctly assigned.
The handler prototype says it can't access file pointer, however it is simple to obtain it after setting LWIP_HTTPD_FILE_STATE that enables a "file state" pointer. It is sufficient to assign file->state to file itself in fs_open_custom().


For example, I have the request GET /login.cgi?user=admin&pwd=admin and I have to reply with some JSON data. The answer depends on parameters user and pwd passed in the 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 in advance. In CGI handler I can allocate and create the answer.


int fs_open_custom(struct fs_file *file, const char *name) {
  if (!strcmp(name, "/login.cgi")) {
    file->state = file;
    return 1;
  }
}

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 = reply_buf;
    file->len = file->index = strlen(reply_buf);
  }
}


This could work only if my patch is applied.


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().

Giuseppe Modugno <giusloq>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attached Files
file #42496:  patch.diff added by giusloq (2KiB - application/octet-stream)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by goldsimon (Updated the item)
  • -email is unavailable- added by giusloq (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-02-02 goldsimon StatusNone Done
        Assigned toNone goldsimon
        Open/ClosedOpen Closed
    2018-01-02 goldsimon Planned ReleaseNone 2.1.0
    2017-11-27 giusloq Attached File- Added patch.diff, #42496

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code