lwip-users
[Top][All Lists]
Advanced

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

RE : RE : RE : RE : TR : RE : RE: [lwip-users] webserver with method=POS


From: Frédéric BERNON
Subject: RE : RE : RE : RE : TR : RE : RE: [lwip-users] webserver with method=POST
Date: Wed, 25 Jul 2007 09:36:10 +0200

I see in your trace file that you use a CS8900. There is a problem identified 
in https://savannah.nongnu.org/bugs/?20531 .

A Ethereal/Wireshark capture file (with the matching TCPOutput.txt) would be 
good.

In your TCPOutput.txt, I can see some :

"memp_malloc: out of memory in pool 7" => should be MEMP_NETCONN in memp_t (see 
memp.h) in 1.2.0
"memp_malloc: out of memory in pool 8" => should be MEMP_API_MSG in memp_t (see 
memp.h) in 1.2.0

I'm not sure of the matching pool in your lwIP release, so check these last two 
points. Since you don't have define all "MEMP_NUM_" in your lwipopts.h, your 
target use the ones from  opt.h. In current CVS HEAD, it's :

MEMP_NUM_NETCONN=4
MEMP_NUM_API_MSG=8 (note this one is no longer used in CVS HEAD and will be 
removed).

Just for information, do you have also increase your MEM_SIZE? 

Last, I see in your lwipopts.h that LWIP_SO_RCVTIMEO=1. I thought you used lwIP 
1.2.0. In this release, this option isn't defined. Can you confirm the lwIP 
release you use?


====================================
Frédéric BERNON 
HYMATOM SA 
Chef de projet informatique 
Microsoft Certified Professional 
Tél. : +33 (0)4-67-87-61-10 
Fax. : +33 (0)4-67-70-85-44 
Email : address@hidden 
Web Site : http://www.hymatom.fr 
====================================
P Avant d'imprimer, penser à l'environnement
 


-----Message d'origine-----
De : Urs Gerber [mailto:address@hidden 
Envoyé : mercredi 25 juillet 2007 08:02
À : Frédéric BERNON
Objet : AW: RE : RE : RE : TR : RE : RE: [lwip-users] webserver with method=POST


Hi Frederic

Here are my option-file and a outputfile.
I have tryed with all MEMP mulitipl by 2 and now it work on a maschine. But if 
I try with my workstation (also the emulator is running over ethernet) it 
dosen't work. The outputfile is from this configuration.

Mit freundlichen Grüssen
Urs Gerber

 


-----Ursprüngliche Nachricht-----
Von: Frédéric BERNON [mailto:address@hidden
Gesendet: Dienstag, 24. Juli 2007 21:13
An: address@hidden; Mailing list for lwIP users
Betreff: RE : RE : RE : TR : RE : RE: [lwip-users] webserver with method=POST


What are you lwipopts.h main options ?

MEMP_NUM_TCP_PCB
MEMP_NUM_TCP_PCB_LISTEN
MEMP_NUM_PBUF

Etc... ?

Do you have active some traces to see if all the connections sent by the 
browser are "accepted"? You can also send a network capture file ???
  
====================================
Frédéric BERNON 
HYMATOM SA 
Chef de projet informatique 
Microsoft Certified Professional 
Tél. : +33 (0)4-67-87-61-10 
Fax. : +33 (0)4-67-70-85-44 
Email : address@hidden 
Web Site : http://www.hymatom.fr 
====================================
P Avant d'imprimer, penser à l'environnement
 


-----Message d'origine-----
De : address@hidden [mailto:address@hidden De la part de Urs Gerber Envoyé : 
mardi 24 juillet 2007 17:54 À : 'Mailing list for lwIP users' Cc : Frédéric 
BERNON Objet : AW: RE : RE : TR : RE : RE: [lwip-users] webserver with 
method=POST


If I try only one frame (x.x.x.x/001.htm) - it works.
If I try the whole page (x.x.x.x) it dosen't work.
I believe, that there lost any message inside the lwip!


My frames:
const char WEB_PAGE000[] = "\
<frameset rows='8%,*,5%' border='0' frameborder='0' framespacing='0'>\r\n\ 
<frame src='001.htm' name='oben' marginwidth='0' marginheight='0' 
scrolling='auto' noresize>\r\n\ <frameset cols='10%,*' border='0' 
frameborder='0' framespacing='0'>\r\n\ <frame src='002.htm' name='links' 
marginwidth='0' marginheight='0' scrolling='auto' noresize>\r\n\ <frame 
src='004.htm' name='main' marginwidth='10' marginheight='10' scrolling='auto' 
noresize>\r\n\ </frameset>\r\n\ <frame src='003.htm' name='unten' 
marginwidth='0' marginheight='0' scrolling='auto' noresize>\r\n\ 
</frameset>\r\n\ </HTML>\r\n";

const char WEB_PAGE001[] = "\
<body><CENTER>\r\n\
<font size=6 color=black face='arial'>Gerätetyp: DBKGN23</font>\r\n\ 
</body></html>\r\n"; const char WEB_PAGE002[] = "\ <body><CENTER>\r\n\ <font 
size=6 color=black face='arial'>Gerätetyp: DBKGN23</font>\r\n\ 
</body></html>\r\n"; const char WEB_PAGE003[] = "\ <body><CENTER>\r\n\ <font 
size=6 color=black face='arial'>Gerätetyp: DBKGN23</font>\r\n\ 
</body></html>\r\n"; const char WEB_PAGE004[] = "\ <body><CENTER>\r\n\ <font 
size=6 color=black face='arial'>Gerätetyp: DBKGN23</font>\r\n\ 
</body></html>\r\n";


Mit freundlichen Grüssen
Urs Gerber

-----Ursprüngliche Nachricht-----
Von: address@hidden
[mailto:address@hidden Auftrag von Frédéric BERNON
Gesendet: Dienstag, 24. Juli 2007 17:25
An: Mailing list for lwIP users
Betreff: RE : RE : TR : RE : RE: [lwip-users] webserver with method=POST


>I try a webserver with four frames on screen. Each frame works solo but
>if all frames wil be handelt, there are somthimes lost of a frame.

Uhm, finally, not sure it's the problem. Can you tell me more about "all frames 
wil be handelt" ?

>I d'ont understand, why I have close the connection handle with each
>message?
 
You can use a HTTP "keepalive" connection, in this case, you only have to 
"netconn_delete" it once you got a tcp error (when the peer reset the 
connection).

====================================
Frédéric BERNON 
HYMATOM SA 
Chef de projet informatique 
Microsoft Certified Professional 
Tél. : +33 (0)4-67-87-61-10 
Fax. : +33 (0)4-67-70-85-44 
Email : address@hidden 
Web Site : http://www.hymatom.fr 
====================================
P Avant d'imprimer, penser à l'environnement
 


-----Message d'origine-----
De : address@hidden [mailto:address@hidden De la part de Frédéric BERNON Envoyé 
: mardi 24 juillet 2007 17:16 À : Mailing list for lwIP users Objet : RE : TR : 
RE : RE: [lwip-users] webserver with method=POST


Urs,

There could be a problem (fixed in current CVS HEAD) with the netconn_delete. 
Could you try to do a "pause" (something like a sleep, wait...) before the 
netconn_delete?  Or better, could you try the CVS HEAD to test it ?
  
====================================
Frédéric BERNON 
HYMATOM SA 
Chef de projet informatique 
Microsoft Certified Professional 
Tél. : +33 (0)4-67-87-61-10 
Fax. : +33 (0)4-67-70-85-44 
Email : address@hidden 
Web Site : http://www.hymatom.fr 
====================================
P Avant d'imprimer, penser à l'environnement
 


-----Message d'origine-----
De : address@hidden [mailto:address@hidden De la part de Frédéric BERNON Envoyé 
: mardi 24 juillet 2007 17:13 À : Mailing list for lwIP users Objet : TR : RE : 
RE: [lwip-users] webserver with method=POST



-----Message d'origine-----
De : Urs Gerber [mailto:address@hidden 
Envoyé : mardi 24 juillet 2007 16:38
À : Frédéric BERNON
Objet : AW: RE : RE: [lwip-users] webserver with method=POST


hi Frederic

Thanks for your help - it works fin.
Now, I have a new problem:
I try a webserver with four frames on screen. Each frame works solo but if all 
frames wil be handelt, there are somthimes lost of a frame. I d'ont understand, 
why I have close the connection handle with each message?

i give you also my code:
/******************************************************************************
* Beschreibung : Ausgabe der WEB-Page
*
* Argumente    :  -
* Rueckgabewert:  -
* Hinweise     : 
*                
******************************************************************************/
static void SendeHTML_Page1 (struct netconn *conn, unsigned short usFileNr) {
  char *pSave;
  char *pWork;
  int  i;
  char *pPage;
  
  
  switch (usFileNr) {
    case 0: pPage = (char *)WEB_PAGE000; i = sizeof(WEB_PAGE000); break;
    case 1: pPage = (char *)WEB_PAGE001; i = sizeof(WEB_PAGE001); break;
    case 2: pPage = (char *)WEB_PAGE002; i = sizeof(WEB_PAGE002); break;
    case 3: pPage = (char *)WEB_PAGE003; i = sizeof(WEB_PAGE003); break;
    case 4: pPage = (char *)WEB_PAGE004; i = sizeof(WEB_PAGE004); break;
    default:
      SendeHTML_Page(conn);
      i = 0;
  }

  if (i > 0) {
    pSave = pWork = (char*)MALLOC(6000);              /* Antwortbuffer 
allozieren */
    if (pSave != NULL) {
//      i += sizeof(HTTP_TITEL);
//      pWork += sprintf(pWork,HTTP_OK,i);
//      i = pWork - pSave;
  
      /* Send the actual web page. */
//      if(netconn_write(conn, (void *)pSave, i, NETCONN_NOCOPY) != ERR_OK)
//        printf("***Write1Err***\n\r");

                        strcpy( pWork, HTTP_TITEL );
                        strcat( pWork, pPage );
//      pWork += sprintf(pWork,HTTP_TITEL);
//      pWork += sprintf(pWork,pPage);
//      i = pWork - pSave;
//        printf("*** %d ***\n\r",i);
  
      /* Send the actual web page. */
      if(netconn_write(conn, (void *)pSave, (u16_t)strlen( pSave ), 
NETCONN_NOCOPY) != ERR_OK)
        printf("***Write1Err***\n\r");
      
      free(pSave);  
    }
  }

}


/******************************************************************************
* Beschreibung : Verarbeitung einer Empfangsverbindung
*
* Argumente    :  -
* Rueckgabewert:  -
* Hinweise     : 
*                
******************************************************************************/
static void Webserver_connection(struct netconn *conn)
{
  struct netbuf *inbuf;
  char *rq;
  u16_t len, i;
  unsigned char  ucMethod;   // 0: GET / 1: POST
  unsigned short usFile;     // Filenummer: 0 = Grundscreen

  /* Read data from the connection into the netbuf inbuf.
  We assume that the full request is in the netbuf. */
  if((inbuf = netconn_recv(conn)) == NULL) {
    return;
  }

  netbuf_data(inbuf, (void **)&rq, &len);
  ucMethod = Webserver_GetMethod(rq);
  usFile = Webserver_GetFile(rq);
//  printf(rq);
  printf("Hello: %d -%d\n",usFile, ucMethod);
  
  if (ucMethod <= 1) {
    /* ev. Parameter auch noch verarbeiten! */
    
    /* Write out the HTTP OK header. */ 
    netconn_write(conn, HTTP_OK1, (u16_t)strlen( HTTP_OK1 ), NETCONN_COPY ); 
    
    /* Antwort zurücksenden */
    SendeHTML_Page1(conn,usFile);
//    SendeHTML_Page1(conn,4);
    
  } else {
    printf("***bad data***\n\r");
  }

  netbuf_delete(inbuf);    /* delete data buffer */
  
}




/******************************************************************************
*                   WEB - Server
******************************************************************************/

/******************************************************************************
* Beschreibung : Task WebServers
*
* Argumente    :  -
* Rueckgabewert:  - (niemals ein Rücksprung)
* Hinweise     : 
*                
******************************************************************************/
static void WebServerThred(void *arg)
{
  struct netconn *conn, *newconn;

  /* Create a new TCP connection handle. */
  conn = netconn_new(NETCONN_TCP);

  /* Bind the connection to port 80 on any local IP address. */
  netconn_bind(conn, NULL, 80);

  /* Put the connection into LISTEN state. */
  netconn_listen(conn);

  /* Loop forever. */

  while(1) {
                /* Wait for a first connection. Accept a new connection. */
    newconn = netconn_accept(conn);

    if(newconn != NULL) {
      /* Process the incomming connection. */
      Webserver_connection(newconn);

      /* Deallocate connection handle. */
//          netconn_close(newconn);
      netconn_delete(newconn);
//      newconn = NULL;
    }
  }
}



Mit freundlichen Grüssen
Urs Gerber



-----Ursprüngliche Nachricht-----
Von: Frédéric BERNON [mailto:address@hidden
Gesendet: Dienstag, 17. Juli 2007 21:12
An: Mailing list for lwIP users; address@hidden
Betreff: [?? Probable Spam] RE : RE: [lwip-users] webserver with method=POST


Hi Urs,

I can give you a generic guideline to process "simply" GET & POST on your 
embedded web server. What you have to do:

1/ On the accepted socket, read datas in a buffer until "\r\n\r\n" (included). 
This part is the "http_headers". It can be useful to add a 0x00 at the end of 
the block to use "string" functions from C runtime, or simply do a "printf".

2/ Extract from the first line (of the "http_headers" got in 1/) the method 
(should be "POST" or "GET"), and the document (could be "/" for the root). The 
method is the first word, the document the next.

3/ If the method (got in 2/) is "GET", copy (or use a pointer) all the datas 
from the first line which are after a possible "?". Note it's possible to not 
have any "?" in a request. At this point, note you can have between 0 to n 
bytes for these datas. I will call this memory block "http_params_datas" in 
next points. 
   
4/ If the method (got in 2/) is "POST", you have first to find in 
"http_headers" a line started by "Content-Length: ". The line have a form like 
"Content-Length: 32\r\n". When you found this line, convert the value of the 
line (32 is this sample) in a integer. This is the "post_data_size". One you 
got that, read on the socket the next "post_data_size" bytes, and copy them (or 
use a pointer) in the memory block named "http_params_datas".

5/ At this point, you should have a memory block named "http_params_datas" 
(with its size). It can contain datas from GET parameters, or from POST datas. 
Note than GET have a maximum size of 1024 bytes. That's why, most of time, POST 
is used to get "big" datas. POST is also useful if you don't want to "show" on 
the address bar your parameters. The aim is to have a memory block to process 
on next point. It can be useful to add a 0x00 at the end of the block to use 
"string" functions from C runtime, or simply do a "printf".

6/ You can now read param by param your "http_params_datas", you will got each 
parameters from your "form". They are in the same form in GET or POST 
(something like "param1=value1&param2=value2").

That's all. This "framework" will work, but need some checkings. First is to 
not read more bytes than your buffer can contains. Other tips: if you try to do 
a UPLOAD, the processing is a little bit different from 6/, since you can to 
process a "multipart" document, with "boundary" tags to limit the datas (which 
can be binary datas). Look for "RFC1341 - 7.2.1 Multipart: The common syntax" 
for this case.

I can propose you two simple functions to "parse" (a big word in this case) 
http datas. They are basic tools to help to start, bug mainly used the C 
runtime (note they were used on win32, I just change them with lwIP types, so, 
it SHOULD work).

err_t http_getheadervalue( char* lpszHeaderName, char* lpszHeaders, char* 
lpszBuffer, u32_t dwBufferSize)
{ err_t bResult    = ERR_ARG;
  char* lpszHeader = NULL;
  
  memset( lpszBuffer, 0, dwBufferSize);
  lpszHeader = strstr( lpszHeaders, lpszHeaderName);
  if (lpszHeader!=NULL)
   { if (sscanf( lpszHeader+strlen(lpszHeaderName)+1/*:*/+1/*SPACE*/, 
"%[^\r\n]", lpszBuffer)>=0)
      { bResult = ERR_OK;
      }
   }
  return bResult;
}

err_t http_getlinevalue( char* lpszValueName, char* lpszLine, char* lpszBuffer, 
u32_t dwBufferSize)
{ err_t  bResult      = ERR_ARG;
  char* lpszValue     = NULL;
  char  szValue[256]  = "";
  
  memset( lpszBuffer, 0, dwBufferSize);
  memset( szValue,    0, sizeof(szValue));
     
  lpszValue = strstr( lpszLine, lpszValueName);
  if (lpszValue!=NULL)
   { if (sscanf( lpszValue+strlen(lpszValueName)+1/*=*/, "%[^ ;&\r\n]", 
szValue)>=0)
      { /* Note you have to process special escape sequence, or special chars: 
by example, any "+" have to be replace by a " " */
        /* Can you find in your datas some sequence like "%20". You have to 
replace them by the a matching ASCII value. For "%20", its 0x20, so, a "space"
        /* etc...*/
        bResult = ERR_OK
      }
   }
  return bResult;
}

Good luke...


====================================
Frédéric BERNON 
HYMATOM SA 
Chef de projet informatique 
Microsoft Certified Professional 
Tél. : +33 (0)4-67-87-61-10 
Fax. : +33 (0)4-67-70-85-44 
Email : address@hidden 
Web Site : http://www.hymatom.fr 
====================================
P Avant d'imprimer, penser à l'environnement

-----Message d'origine-----
De : address@hidden [mailto:address@hidden De la part de Grubb, Jared Envoyé : 
mardi 17 juillet 2007 18:01 À : address@hidden; Mailing list for lwIP users 
Objet : RE: RE: [lwip-users] webserver with method=POST


The version in lwIP is *incredibly* simple. It serves up the same web page to 
every incoming HTTP GET command - and doesn't even fully parse the input. A 
quick Google search pulled up this website, which can explain more about the 
HTTP protocol and how you can parse the things sent to the server: 
http://www.jmarshall.com/easy/http/#postmethod
 
But as for using lwIP to do the network transfers, the online example can get 
you started.

Jared
 
From: address@hidden [mailto:address@hidden On Behalf Of Urs Gerber
Sent: Tuesday, July 17, 2007 8:51 AM
To: Grubb, Jared; 'Mailing list for lwIP users'
Subject: AW: RE: [lwip-users] webserver with method=POST
 
Hi Jared
 
Thanks for short answer.
But all examples work with method "GET" and these is also no problem. I try 
with method "POST" and do not find the entered datas!?
 
Mit freundlichen Grüssen 
Urs Gerber 
-----Ursprüngliche Nachricht-----
Von: Grubb, Jared [mailto:address@hidden
Gesendet: Dienstag, 17. Juli 2007 17:29
An: address@hidden; Mailing list for lwIP users
Betreff: [?? Probable Spam] RE: [lwip-users] webserver with method=POST There 
is a real basic web server example in the CVS right now, under 
/contrib/apps/httpserver (this is in the "contrib" module). You can browse the 
online CVS if you need to.
 
Second, I would read the original document that Adam Dunkels wrote about lwIP. 
It's a few years old now, and we're working on updated documentation, but with 
the example above (which is current) and the old PDF, you should be able to get 
yourself started! The PDF is here: http://www.sics.se/~adam/lwip/doc/lwip.pdf

Jared
 
From: address@hidden [mailto:address@hidden On Behalf Of Urs Gerber
Sent: Tuesday, July 17, 2007 7:25 AM
To: address@hidden
Subject: [lwip-users] webserver with method=POST
 
I'm using lwip 1.2 and would like to make a small webserver application with a 
password inquiry (method POST).
Question: 
How can I read the entered data?
Does someone have an example?
 
Mit freundlichen Grüssen 
Urs Gerber 
 


Attachment: Frédéric BERNON.vcf
Description: Frédéric BERNON.vcf


reply via email to

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