[Top][All Lists]

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

[lwip-devel] [patch #9501] httpd: move httpd_cgi_handler() call

From: Giuseppe Modugno
Subject: [lwip-devel] [patch #9501] httpd: move httpd_cgi_handler() call
Date: Mon, 27 Nov 2017 04:18:42 -0500 (EST)
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36


                 Summary: httpd: move httpd_cgi_handler() call
                 Project: lwIP - A Lightweight TCP/IP stack
            Submitted by: giusloq
            Submitted on: Mon 27 Nov 2017 09:18:41 AM UTC
                Category: apps
                Priority: 5 - Normal
                  Status: None
                 Privacy: Public
             Assigned to: None
        Originator Email: 
             Open/Closed: Open
         Discussion Lock: Any
         Planned Release: None



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

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


File Attachments:

Date: Mon 27 Nov 2017 09:18:41 AM UTC  Name: patch.diff  Size: 2KiB   By:



Reply to this item at:


  Message sent via/by Savannah

reply via email to

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