lwip-users
[Top][All Lists]
Advanced

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

Re: [lwip-users] LWIP_HTTPD_SSI_MULTIPART and concurrent HTTP requests


From: Noam Weissman
Subject: Re: [lwip-users] LWIP_HTTPD_SSI_MULTIPART and concurrent HTTP requests
Date: Fri, 24 Nov 2017 14:57:21 +0000

Hi,


For every connection the HTTP server allocates a session data structure ( http_state ).

This data structure is passed to the call back functions as arg. You need to use it to

differentiate between session.


See inside httpd_accept:


/* Allocate memory for the structure that holds the state of the
     connection - initialized by that function. */
  hs = http_state_alloc();
  if (hs == NULL) {
    LWIP_DEBUGF(HTTPD_DEBUG, ("http_accept: Out of memory, RST\n"));
    return ERR_MEM;
  }
  hs->pcb = pcb;

  /* Tell TCP that this is the structure we wish to be passed for our
     callbacks. */
  tcp_arg(pcb, hs);

--------------------------------------------------------------------------------

The above hs is your session structure that passes to the call backs.


Now in function http_init_file:


static err_t
http_init_file(struct http_state *hs, struct fs_file *file, int is_09, const char *uri,
               u8_t tag_check, char* params)
{
  if (file != NULL) {
    /* file opened, initialise struct http_state */
#if LWIP_HTTPD_SSI
    if (tag_check) {
      struct http_ssi_state *ssi = http_ssi_state_alloc();
      if (ssi != NULL) {
        ssi->tag_index = 0;
        ssi->tag_state = TAG_NONE;
        ssi->parsed = file->data;
        ssi->parse_left = file->len;
        ssi->tag_end = file->data;
        hs->ssi = ssi;
      }

--------------------------------------------------------------------------------


In function http_init_file you see an allocation to struct http_ssi_state ssi !!


This ssi is assigned to your connection hs->ssi ... inside the ssi you have the

ssi->tag_part


every time the web server call's your SSI call back it assigns the tag_part to HTTPD_LAST_TAG_PART


If you do not change the tag_part the web server assumes that this is the last part of your SSI

and will not call your function any more. If you change the tag_part it will call your function again

current_tag_part value is either 0 when it first calls your SSI function or it will be what ever value

you assign to tag_part but not HTTPD_LAST_TAG_PART.


Example code:

Lets assume your SSI function looks like this:


u16_t SSIHandler(tag, ssi->tag_insert, current_tag_part, *ssi->tag_part)
{
  u16_t RespLen = 0;

 
  if(current_tag_part == 0)
  {
    // add some code here...
    
    *ssi->tag_part = (current_tag_part + 1);
  }
  else if(current_tag_part == 1)
  {
    // add some code here...
 
    *ssi->tag_part = (current_tag_part + 1);
  }
  else if(current_tag_part == 2)
  {
    // add some code here...
    
    // last part we do not touch tag_part !
  }
 
  return RespLen;
}


Hope that helped :-)


BR,

Noam.


From: lwip-users <lwip-users-bounces+address@hidden> on behalf of R. Diez <address@hidden>
Sent: Friday, November 24, 2017 12:40 PM
To: address@hidden
Subject: [lwip-users] LWIP_HTTPD_SSI_MULTIPART and concurrent HTTP requests
 
Hi all:

I am using the httpd server that comes with lwIP version 2.0.2 on a small embedded device.

As I am generating dynamic HTML content that can reach 1 or 2 KiB per CGI SSI tag, I enabled LWIP_HTTPD_SSI_MULTIPART, so that I can send the tag contents in chunks. Whenever I get an SSI tag callback, I fill a small buffer with the generated contents for that tag, and I give the data back piece by piece on the next callbacks. That is all working fine.

However, I have recently realised that the httpd server can accept and serve multiple connections at the same time. I was not aware of this as the SSI callbacks do not seem to pass any context pointers. I noticed this because some asserts are triggering in my SSI handling logic. For example, say the same web page is requested simultaneously from 2 different browsers. Then my SSI multipart callbacks do not know which page is meant on the current callback. The SSI tag contents can be different per page, think for example about some text that has the current clock time embedded.

Is there any way to make lwIP's httpd server provide some "request context" when processing an SSI tag? Would I know when the context has been destroyed, in order to release the associated SSI multipart buffer?

Or is it possible to make the httpd server accept just 1 connection at a time?

Thanks in advance,
  rdiez


reply via email to

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