lwip-users
[Top][All Lists]
Advanced

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

Re: [lwip-users] httpd server app lwip 2.0.2 cgi


From: Noam Weissman
Subject: Re: [lwip-users] httpd server app lwip 2.0.2 cgi
Date: Fri, 10 Nov 2017 19:27:57 +0000

Hi,


I am working with my own HTTP server that is different from the one in the contribution

but uses a very similar mechanism.


It took me some time to find it but you need to check:

   \src\include\lwip\apps  httpd.h


In the above file your will find more information.


For every connection the server has a buffer with limited size (LWIP_HTTPD_MAX_REQ_LENGTH).

You can add data to this buffer but MUST consider the size limit. If the data that you need to add is

larger then the send buffer you need to send it in parts !.


Check define HTTPD_LAST_TAG_PART


Your call back function prototype looks like this (taken from httpd.h):


typedef u16_t (*tSSIHandler)(
#if LWIP_HTTPD_SSI_RAW
                             const char* ssi_tag_name,
#else /* LWIP_HTTPD_SSI_RAW */
                             int iIndex,
#endif /* LWIP_HTTPD_SSI_RAW */
                             char *pcInsert, int iInsertLen
#if LWIP_HTTPD_SSI_MULTIPART
                             , u16_t current_tag_part, u16_t *next_tag_part
#endif /* LWIP_HTTPD_SSI_MULTIPART */
#if defined(LWIP_HTTPD_FILE_STATE) && LWIP_HTTPD_FILE_STATE
                             , void *connection_state
#endif /* LWIP_HTTPD_FILE_STATE */
                             );


Inside your call back function you need to create something like this:


u16_t TestSSI(char *pcInsert, int iInsertLen, u16_t current_tag_part, u16_t *next_tag_part)

{

u16_t RespLen;


if(current_tag_part == 0) // first part

{

  RespLen = snprintf(pcInsert, iInsertLen, "this is some dynamic data");


  // this will notify the serevr to send your data and call your call back again.

  *next_tag_part = (current_tag_part + 1);

}

else if(current_tag_part == 1) // second and last part

{

  RespLen = snprintf(pcInsert, iInsertLen, "this is some more dynamic data");

}


return RespLen;

}


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


When you do not change *next_tag_part the HTTP server and leave it as is the server

knows that this is your last part and never calls your function anymore.


The above is just a minimal example.


You can add HTML code or _javascript_ in these call backs.


I am using JS so I am adding variables and after page loads I use this variables to update

the page.


I hope that helped :-)



BR,

Noam.



From: lwip-users <lwip-users-bounces+address@hidden> on behalf of billium <address@hidden>
Sent: Friday, November 10, 2017 5:50 PM
To: address@hidden
Subject: Re: [lwip-users] httpd server app lwip 2.0.2 cgi
 
On 10/11/17 13:05, Markus Pischinger wrote:
Hi guys,
I've been trying out the new httpd server app that comes with lwip 2.0.2.
It works great so far for static websites but i'm looking into CGI to make GET requests.
Has anyone maybe got an example on how to do this? And what should I use? There is a "old style" with LWIP_HTTPD_CGI and "new style" with LWIP_HTTPD_CGI_SSI.
I tried the CGI_SSI, which works so far - i wrote a httpd_cgi_handler and it gets called on GET requests. But i don't really get how i should return any kind of data here?

That's the only comment in the header file to the cgi_handler:
/** Define this generic CGI handler in your application.
 * It is called once for every URI with parameters.
 * The parameters can be stored to
 */
Thanks in advance for any help!


_______________________________________________
lwip-users mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/lwip-users

The esp-open-rtos on github examples section has one, also does web sockets, I got it working on a TIVA TM4C1294 ok.

Billy

reply via email to

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