Sorry if i resend this message but i do not find it in list archive.
Some time ago (29.04.2004) reported to work on the TCPIP example. (strange behaviour of the tcpip example) Here are my Results (to late?): 1. The HTTP Server works more correct. Waits until Request is complete. Some Browser have Problems with this. 2. The HTTP Server can accept Get requests with variables and values. e. g. : HTTP://192.168.0.166?temperatur=250&var2=val2&var3=val3 easyweb_diff: May by someone can review the diff that i attached and commit it to cvs? example.tar.gz: I also add a little example --- a heating control with web interface (only german comments :-( ) !Please do not commit this ugly pease of code until reviewing (and translating)
--- easyweb_orig.c 2004-11-15 16:30:27.000000000 +0100 +++ easyweb.c 2004-11-15 16:30:01.000000000 +0100 @@ -21,6 +21,20 @@ #include "webside.c" #include "easyweb.h" +#define PARAMCOUNTMAX 10 +typedef struct +{ + unsigned char RequestString[512]; // Holds the HTTP Request + char* url; // Points to the URL in RequestString + char* parameter[PARAMCOUNTMAX+1]; // Points to the parameter in RequestString + char* VarName[PARAMCOUNTMAX+1]; // Points to the name of a variable in RequestString + char* VarValue[PARAMCOUNTMAX+1]; // Points to the value of a variable in RequestString + int parametercount;// count of parameter in RequestString +} requeststruct; +requeststruct RequestStruct; +unsigned char RequestComplete=0; + + int main(void) { InitOsc(); @@ -44,6 +58,9 @@ DoNetworkStuff(); } */ + RequestStruct.RequestString[0]='\0';// 0 terminate the first + RequestStruct.RequestString[1]='\0';// 2 RequestString Chars + RequestStruct.parametercount=0; HTTPStatus = 0; // clear HTTP-server's flag register @@ -61,6 +78,22 @@ } +// This Function splits the char-string of the argument +// Form: ArgumentCharString ="Var=Val" +// into Var and Val + +void ArgumentCharStringSplit(void) +{ + int i; + for (i=0;i<RequestStruct.parametercount;i++) + { + RequestStruct.VarName[i] =RequestStruct.parameter[i]; + RequestStruct.VarValue[i] = strstr(RequestStruct.VarName[i],"="); + RequestStruct.VarValue[i][0] = '\0'; + RequestStruct.VarValue[i]++; + } +} + // This function implements a very simple dynamic HTTP-server. // It waits until connected, then sends a HTTP-header and the // HTML-code stored in memory. Before sending, it replaces @@ -71,10 +104,67 @@ void HTTPServer(void) { + char* pointer; + int i,length,timeout=0; + char separator; if (SocketStatus & SOCK_CONNECTED) // check if somebody has connected to our TCP { + if(!RequestComplete)/*request complete?*/ + { + length=strlen(RequestStruct.RequestString); + pointer=RequestStruct.RequestString+length;/*nullterm bla??*/ + pointer[0]='\0'; + if((length+strlen(RxTCPBuffer))<512) + { + strcpy(pointer,RxTCPBuffer); + if(length>4) + length-=4; + pointer=RequestStruct.RequestString+length; + } + else + RequestComplete=1;/*abbruch für kaputte requests*/ + + if((strstr(pointer,"\n"))||(strstr(pointer,"\r\n"))) + RequestComplete=1; + + if(timeout++>4) + RequestComplete=1; + TCPReleaseRxBuffer();/*auf jeden Fall den RXPuffer frei machen!!*/ + } + if(RequestComplete) + { if (SocketStatus & SOCK_DATA_AVAILABLE) // check if remote TCP sent data - TCPReleaseRxBuffer(); // and throw it away + { + TCPReleaseRxBuffer();/*auf jeden Fall den RXPuffer frei machen!!*/ + } + if(pointer=strstr(RequestStruct.RequestString,"GET ")) + /*liefert einen pointer auf die addresse von get zurück*/ + { + pointer+=4;/*skip "GET "*/ + RequestStruct.url=pointer; + length=strcspn(pointer," ?\r\n"); + + separator=pointer[length]; + pointer[length]='\0';/*Nullterminierung für die URL*/ + if (separator=='?') + { + pointer+=length+1; + // jeden einzelnen Parameter holen + while ((length=strcspn(pointer," &\r\n"))>0) + { + // einen Parameter senden + separator=pointer[length]; + pointer[length]='\0'; + RequestStruct.parameter[RequestStruct.parametercount++]=pointer; + // Wenn keine weiteren Parameter vorhanden sind oder maximalzahl erreicht, abbrechen + if ((separator!='&') || (RequestStruct.parametercount>=PARAMCOUNTMAX)) + break; + pointer+=length+1; + } + ArgumentCharStringSplit();/*splits the ArgumentCharString into VarName and Value*/ + PortSwitchSync();/*Switch the ports in argumentlist*/ + } + } if (SocketStatus & SOCK_TX_BUF_RELEASED) // check if buffer is free for TX { @@ -112,14 +202,19 @@ TCPTransmitTxBuffer(); // send last segment TCPClose(); // and close connection HTTPBytesToSend = 0; // all data sent + RequestComplete=0;/*zurücksetzen*/ + RequestStruct.RequestString[0]='\0'; + RequestStruct.RequestString[1]='\0'; + RequestStruct.parametercount=0; + timeout=0; } HTTPStatus |= HTTP_SEND_PAGE; // ok, 1st loop executed } } + } else HTTPStatus &= ~HTTP_SEND_PAGE; // reset help-flag if not connected - } // samples and returns the AD-converter value of channel 7
example.tar.gz
Description: application/tgz