Skip to content

Commit

Permalink
Bug fix in POST parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsonm236 committed Feb 21, 2021
1 parent 7499875 commit 299ca49
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 23 deletions.
Binary file removed 20200806_retired_release.zip
Binary file not shown.
Binary file removed 20201230_0411_retired.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion NetworkModule/.Idea_Groups/Vector_File.grp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Group File Created by IDEA
# Project: <NetworkModule>
# Sat Feb 20 16:53:40 2021
# Sun Feb 21 11:31:10 2021
#
"networkmodule_vector.o"
83 changes: 83 additions & 0 deletions NetworkModule/.Idea_Temp/IDEA.ERR
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
- NetworkModule_vector.o
- crts0.sm8
- ds18b20.o
- enc28j60.o
- gpio.o
- httpd.o
- main.o
- mqtt.o
- mqtt_pal.o
- spi.o
- timer.o
- uart.o
- uip.o
- uip_arp.o
- uip_tcpapphub.o
- libisl0.sm8
- libm0.sm8
- NetworkModule_vector.o
- crts0.sm8
- ds18b20.o
- enc28j60.o
- gpio.o
- httpd.o
- main.o
- mqtt.o
- mqtt_pal.o
- spi.o
- timer.o
- uart.o
- uip.o
- uip_arp.o
- uip_tcpapphub.o
- libisl0.sm8
- libm0.sm8
NetworkModule_vector.o:
C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\crts0.sm8:
ds18b20.o:
enc28j60.o:
gpio.o:
httpd.o:
main.o:
mqtt.o:
mqtt_pal.o:
spi.o:
timer.o:
uart.o:
uip.o:
uip_arp.o:
uip_tcpapphub.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libisl0.sm8)isxdig0.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libisl0.sm8)memmov.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libisl0.sm8)strcat0.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libisl0.sm8)strlen0.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)bmulx.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)eeprom.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)fmul.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)ftol.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)imul.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)itolx.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)itoly.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)ladc.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)ladd.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lcmp.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lgadc.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lgadd.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lglsh.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lgor.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lgsbc.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lgursh.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lreg.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)ltor.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)ludiv.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)ldiv.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lgneg.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lneg.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lumod.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lzmp.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)rtol.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)sdivx.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)uitof.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)utolx.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)xreg.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)yreg.o:
2 changes: 1 addition & 1 deletion NetworkModule/.Idea_Temp/IDEABLD.BAT
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
REM COMMAND FILE BUILT BY IDEA
REM Sat Feb 20 16:53:36 2021
REM Sun Feb 21 11:31:06 2021
REM
cxstm8 -v -l +strict +debug +modsl0 +split +warn "networkmodule_vector.c"
cxstm8 -v -l +strict +debug +modsl0 +split +warn "ds18b20.c" "enc28j60.c" "gpio.c" "httpd.c" "main.c" "mqtt.c" "mqtt_pal.c" "spi.c" "timer.c" "uart.c" "uip.c" "uip_arp.c" "uip_tcpapphub.c"
Expand Down
2 changes: 1 addition & 1 deletion NetworkModule/Main.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
//---------------------------------------------------------------------------//
//---------------------------------------------------------------------------//
//---------------------------------------------------------------------------//
const char code_revision[] = "20210220 2350";
const char code_revision[] = "20210221 1826";
//---------------------------------------------------------------------------//
//---------------------------------------------------------------------------//
//---------------------------------------------------------------------------//
Expand Down
92 changes: 72 additions & 20 deletions NetworkModule/httpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1611,14 +1611,6 @@ static uint16_t CopyHttpData(uint8_t* pBuffer, const char** ppData, uint16_t* pD
// If the loop terminates and there is still data left to transmit (as
// indicated by pDataLeft > 0) the calling routine will call the function
// again.
//
// Normally one pass of this loop copies one character from the webpage
// template to the transmission buffer. However, up to ~75 bytes can be
// copied to the transmission buffer (for instance when one of the
// "replacement strings" (like %y00) is processed. For this reason nBytes
// might exceed nMaxBytes by up to 75 bytes if the code does not pre
// compensate for it. This is why nMaxBytes is set well below MAXFRAME.
//

if (*pDataLeft > 0) {
// If pDataLeft > 0 then we are (or are still) processing a page
Expand Down Expand Up @@ -2453,12 +2445,13 @@ void HttpDCall(uint8_t* pBuffer, uint16_t nBytes, struct tHttpD* pSocket)
// "\r\n\r\n" sequence, and we need to be able to handle TCP fragmentation
// during that search.
//
// If we are parsing a fragment then pSocket->nState may have been restored
// to a state further down in the process.
// If we are parsing a TCP fragment then pSocket->nState may have been
// restored to STATE_PARSEPOST or STATE_PARSEGET. If so the parse code will
// run but won't do anything.

{
// use the structure defined on the top of this function to process
// the GET ans the POST
uint8_t found = 0;
// the GET and the POST
// loop trough the table and identify the current state (pSocket->nState)
for (i=0; i<=AUTO_PARSE_ELEMENTS ; i++) {
// current table element is our current state?
Expand All @@ -2472,18 +2465,77 @@ void HttpDCall(uint8_t* pBuffer, uint16_t nBytes, struct tHttpD* pSocket)
nBytes--;
pBuffer++;
// signals a match found
found = 1;
}
}
}
// if we tested all possibilities without find a match
// move to next character in buffer
if (!found) {
nBytes--;
pBuffer++;
}
}

/*
// This is the old, less efficient parse code that was used to find the POST
// or GET phrases. The "parse_table" code above replaced this.
if (pSocket->nState == STATE_CONNECTED) {
if (nBytes == 0) return;
if (*pBuffer == 'G') {
pSocket->nState = STATE_GET_G;
}
else if (*pBuffer == 'P') {
pSocket->nState = STATE_POST_P;
}
nBytes--;
pBuffer++;
}
if (pSocket->nState == STATE_GET_G) {
if (nBytes == 0) return;
if (*pBuffer == 'E') pSocket->nState = STATE_GET_GE;
nBytes--;
pBuffer++;
}
if (pSocket->nState == STATE_GET_GE) {
if (nBytes == 0) return;
if (*pBuffer == 'T') pSocket->nState = STATE_GET_GET;
nBytes--;
pBuffer++;
}
if (pSocket->nState == STATE_GET_GET) {
if (nBytes == 0) return;
if (*pBuffer == ' ') pSocket->nState = STATE_GOTGET;
nBytes--;
pBuffer++;
}
if (pSocket->nState == STATE_POST_P) {
if (nBytes == 0) return;
if (*pBuffer == 'O') pSocket->nState = STATE_POST_PO;
nBytes--;
pBuffer++;
}
if (pSocket->nState == STATE_POST_PO) {
if (nBytes == 0) return;
if (*pBuffer == 'S') pSocket->nState = STATE_POST_POS;
nBytes--;
pBuffer++;
}
if (pSocket->nState == STATE_POST_POS) {
if (nBytes == 0) return;
if (*pBuffer == 'T') pSocket->nState = STATE_POST_POST;
nBytes--;
pBuffer++;
}
if (pSocket->nState == STATE_POST_POST) {
if (nBytes == 0) return;
if (*pBuffer == ' ') pSocket->nState = STATE_GOTPOST;
nBytes--;
pBuffer++;
}
*/

if (pSocket->nState == STATE_GOTPOST) {
//Search for \r\n\r\n
saved_nstate = STATE_GOTPOST;
Expand Down Expand Up @@ -3075,7 +3127,7 @@ void HttpDCall(uint8_t* pBuffer, uint16_t nBytes, struct tHttpD* pSocket)
break; // Exit parsing
}
}
} // end of "while(nBytes != 0)" loop
} // end of "while(1)" loop

// If nParseLeft == 0 we should enter STATE_SENDHEADER204, but we
// clean up the fragment tracking pointers first.
Expand Down

0 comments on commit 299ca49

Please sign in to comment.