cancel
Showing results for 
Search instead for 
Did you mean: 

lwip cgi help

######
Senior

Can anyone help me please?

I'm using LWIP and CGI SSI and http webserver. I've written an html form on my webserver that when submitted sends 16 parameters (each of 32 byte length) as a get. This crashes my webpage and the code never reaches the cgi handler.

The same code currently works however if I only send 12 parameters of the same format.

Thanks in advance.

Parameters I have tried increasing:

MEM_SIZE 10*1024 Byte(s)

LWIP_HTTPD_MAX_CGI_PARAMETERS 48

LWIP_HTTPD_MAX_TAG_LEN 48

LWIP_HTTPD_MAX_TAG_INSERT_LEN 1024

LWIP_HTTPD_MAX_REQUEST_URI_LEN 2048

LWIP_HTTPD_POST_MAX_RESPONSE_URI_LEN 2048

1 ACCEPTED SOLUTION

Accepted Solutions
######
Senior

Thanks everyone. I've fixed it (after wiresharking) by increasing the LWIP_HTTPD_REQ_BUFSIZE and LWIP_HTTPD_MAX_REQ_LENGTH parameters.

View solution in original post

5 REPLIES 5
LCE
Principal

 This crashes my webpage and the code never reaches the cgi handler.

More details please, and what does debugging show?

I have an html page with CGI & SSI running, I started from the lwip example, but can't remember if I changed anything.

Here's my http init with setting the CGI and SSI handlers.

/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
  * @brief  Http webserver Init
  */
void HttpServerInit(void)
{
	/* Httpd Init */
	httpd_init();

	/* configure SSI handlers (ADC page SSI) */
	http_set_ssi_handler(Global_SSI_Handler, (char const **)szSSI_tags, SSI_NUMBER_OF_TAGS);

	/* configure CGI handlers (LEDs control CGI) */
	CGI_table[0] = Led_CGI;
	CGI_table[1] = Spdif_CGI;
	http_set_cgi_handlers(CGI_table, 2);
}

The same code currently works however if I only send 12 parameters of the same format. 

Maybe it's some simple (tag) numbering problem?

Thanks.

I'll try and setup some debug tomorrow, and will change the length of the tag to see if that makes a difference. I've just double checked the tag numbering it's fine. 

I kept the CGI handler code the same and just commented the form boxes on my html to see when it "broke". That's when I got to the number of 12 parameters as working, but 16 parameters doesn't. I'm sure I just need to increase an LWIP option.

TIA.

######
Senior

Update: I have the following debug options defined:

#define LWIP_DEBUG 1
#define NETIF_DEBUG LWIP_DBG_ON
#define UDP_DEBUG LWIP_DBG_ON
#define HTTPD_DEBUG LWIP_DBG_ON
#define MEMP_DEBUG LWIP_DBG_ON
#define MEM_DEBUG LWIP_DBG_ON

I have also looked at lwip_stats

The page has SSI tags that load correctly. When I submit my form the main debug error message I see is: 

Received GET request"
bad request

Update:

I've tried changing the html to send 16 parameters of 4 bytes each (rather than 16 parameters of 32 bytes each) and this works.

Not sure what else I can change to allow a large get such as this?

I'm not sure right now, but isn't the GET SSI / CGI stuff in the URI, so you simply might have a URI / size problem with that many parameters in lwip?

So you might check that, including any string size limits from lwip.

Edit: okay, I just see that you already changed the defines for URI size and LWIP_HTTPD_MAX_CGI_PARAMETERS ...

Edit 2: Can't you find out exactly what triggers this "bad request" reply, where in the (probably) httpd.c file?

######
Senior

Thanks everyone. I've fixed it (after wiresharking) by increasing the LWIP_HTTPD_REQ_BUFSIZE and LWIP_HTTPD_MAX_REQ_LENGTH parameters.