lwip-devel
[Top][All Lists]
Advanced

[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

URL:
  <http://savannah.nongnu.org/patch/?9501>

                 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

    _______________________________________________________

Details:

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



    _______________________________________________________

File Attachments:


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

<http://savannah.nongnu.org/patch/download.php?file_id=42496>

    _______________________________________________________

Reply to this item at:

  <http://savannah.nongnu.org/patch/?9501>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.nongnu.org/




reply via email to

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