View previous topic :: View next topic |
Author |
Message |
Paulvk
Joined: 28 Jul 2006 Posts: 1257 Location: SYDNEY
|
Posted: Sun May 04, 2014 10:38 am Post subject: Problem with Instr |
|
|
I am having a problem with Instr it was working but now after updates it is not it seems.
The result is wrong it gives me 30 but it should be much more below is the code and the buffer print you can see its wrong.
Note using big strings Buffer is 1001 long
Code: |
'*******************************************************************************
'Check all sockets status
'*******************************************************************************
Sub Ethernet()
Local Get_it As String * 4
Local User_p As String * 10 'only 10 characters long
Local Pass_p As String * 10 'only 10 characters long
Local Pass_word As String * 22
Local Bufbytes As Word
Local Bb As Byte
Local Bc As Word
Local P1 As Byte
Local Fs As Byte
Local Buffend As String * 3
' Local Lend As String * 2
Local Tempy As Word
Local Tempz As Word
Local Tt As Byte
Local Lt As Byte
Local Ls As Word
Local Sss As String * 2
Local Gpl As String * 40
' Lend = Lineend
Filetype = 0
Buffend = Chr(04) + Chr(13) + Chr(10) 'this is so we can place a known set of characters at the end of the buffer
For I = 0 To 3 ' for all sockets
Bufbytes = Socketstat(i , 0) ' get status
Select Case Bufbytes
Case Sock_established
Bptr = 1
If Getdstip(i) <> Ipcon Then ' the current client is different then the number stored
Bauth(i) = 0 ' reset authentication bit
Print "RESET of IP"
End If
'#endif
Bufbytes = Socketstat(i , Sel_recv) ' get the number of received bytes
If Bufbytes > 0 Then ' if there is something received
Bcmd = 0
Print "receive buffer size : " ; Bufbytes
Buffer = " " 'clear buffer
For Bc = 1 To Bufbytes
Bb = Tcpread(i , Buf(bc) , 1)
Next Bc
Buffer = Buffer + Buffend
Buffpoint(1) = 1
Print "Read buffer>>>>>>>>>>>>>>>>>>>"
Print Buffer ; "<<<<read><buffer<<<<<<<"
Print
If Bauth(i) = 0 Then
Tempy = Instr(buffer , "Authorization: Basic ") 'looking for Authorization: Basic Note space after Basic
' |---------21------------|
Print "Authorization: Basic at " ; Tempy ; " Characters"
If Tempy > 0 Then
Cls
Lcd "CheckingPassword" '16 character LCD no room for space!
Tempy = Tempy + 21
Tempz = Instr(tempy , Buffer , Lineend)
Print "Tempz1>" ; Tempz
Tempz = Tempz - Tempy
Print "Tempz2>" ; Tempz
Genpurpose(25) = ""
' Genpurpose(25) = Mid(buffer , Tempy , Tempz)
Genpurpose(25) = Mid(buffer , Tempy , 12)
Print
Print ">>>>>>>" ; Genpurpose(25) ; "<<<<<<<<" 'print password sent for debug
Print
User_p = User
Pass_p = Pass
Pass_word = User_p + ":" + Pass_p
Print Pass_word
Print "======"
Print Genpurpose(25)
Gpl = Base64dec(genpurpose(25))
Print "======"
Print Gpl
Print "======"
Wait 10
If Base64dec(genpurpose(25)) = Pass_word Then 'if user name & password matches stored password then
Bauth(i) = 1 ' verified
Ipcon = Getdstip(i) ' store current ip number
Cls
Locate 2 , 1
Lcd "Pass Word OK"
' Print "Pass Word OK Bauth = 1"
End If
Wait 5
End If
End If
If Bauth(i) = 1 Then
Get_it = Left(buffer , 4)
'Print "Get It>>" ; Get_it
Select Case Get_it
Case "GET " 'sent GET
Bcmd = 1 ' For example GET /index.htm HTTP/1.1
Call Find_page()
Case "HEAD" 'sent HEAD
Bcmd = 2
Call Find_page()
Case "POST" 'sent POST
Bcmd = 3
Tempy = Instr(buffer , "Referer: ")
Tempy = Tempy + 9 'looking for Referer: Note space after Referer:
' |--9------|
Tempz = Instr(tempy , Buffer , Lineend)
Tempz = Tempz - Tempy
Genpurpose(25) = ""
Genpurpose(25) = Mid(buffer , Tempy , Tempz)
' Print
' Print "REFERER>>>" ; Genpurpose(25)
'Print
'Tt = Split(genpurpose(25) , Genpurpose(1) , "/")
' Lt = 0
' Genpurpose(tt) = Genpurpose(tt) + "{013}{010}"
' Lt = Instr(1 , Genpurpose(tt) , "{013}{010}") 'Lineend = "{013}{010}" CrLf
' Lt = Lt - 1
'Print
' Print "LT>" ; Lt
' Print
'Print
' Print "REFERER PAGE 1 >>>" ; Genpurpose(tt)
' Print
' Genpurpose(tt) = Left(genpurpose(tt) , Lt)
Print
Print "REFERER PAGE 2 >-->" ; Genpurpose(25) 'now we have what page sent this post
Print
Tempy = Instr(buffer , "Content-Length: ")
Tempy = Tempy + 16 'looking for Content-Length: Note space after Content-Length:
' |--------16--------|
Tempz = Instr(tempy , Buffer , Lineend)
Tempz = Tempz - Tempy
Genpurpose(24) = ""
Genpurpose(24) = Mid(buffer , Tempy , Tempz)
Print "Content Length is>" ; Genpurpose(24)
Lt = Val(genpurpose(24)) 'turn it into a number
Tt = Lt + 3 'add 3 for the 3 characters at the end of the string
Genpurpose(23) = Right(buffer , Tt)
Genpurpose(23) = Left(genpurpose(23) , Lt) 'get rid of the 3 characters
Print "This is the content sent>" ; Genpurpose(23)
'---------now we have the page that sent this Genpurpose(25) and the information it sent Genpurpose(23)
End Select
End If
If Bauth(i) = 0 Then
Bc = Tcpwrite(i , "HTTP/1.0 401 OK{013}{010}") ' ask for user password
Bc = Tcpwrite(i , "WWW-Authenticate: Basic realm={034}ServerID{034}{013}{010}")
Buffer = ""
Print "filetype>" ; Filetype
' Else
'Bc = Tcpwrite(i , "HTTP/1.0 200 OK{013}{010}")
End If
If Bauth(i) = 1 Then
If Filetype > 0 Then 'valid file type
Fs = File_security(filetype) 'look up settings
' Print "Select Case Fs" ; Fs
Select Case Fs ' determin what setings are
Case 145
Case Else 'default eeprom value
'#if Authenticate = 1
End Select
If Valid = 1 Then
' Call Parse_data
End If
End If
End If
'------------------------------------------------------------------------------- LED on/off
If Bcmd = 3 Then 'post data
'#if Cdebug
Print "Posted > data"
Print "Buffer>" ; Buffer
Print "Bconten>" ; Bcontent
'#endif
Bc = Tcpread(i , Buf(1) , Bcontent) ' read data
Bcontent = Bcontent + 1
Buf(bcontent) = 0 ' put string terminator at end of data so we can handle it as a string
Print Buffer
If Buffer = "LED=1" Then
Toggle Led1
End If
Shtml = "index.htm" 'send Page
Valid = 1
End If
'-------------------------------------------------------------------------------
Print "Valid = " ; Valid
Print "HTML page:" ; Shtml
If Valid > 0 Then 'if its 0 its not a valid file
'send Data
If Ext = "js" Then
Call Wiz_send_js() 'send javascript
Else
Call Sd_html() 'send hml-jpg-gif-css
End If
End If
'-------------------------------------------------------------------------------
#if Cdebug
Print "closing socket"
#endif
Socketdisconnect I ' close the connection
End If
Case Sock_close_wait
#if Cdebug
Print "CLOSE_WAIT"
#endif
Socketdisconnect I ' we need to close
Case Sock_closed
#if Cdebug
Print "CLOSED"
#endif
'Here you set the port to listen on
I = Getsocket(i , Sock_stream , 80 , 0) ' get a new socket on Port 80
Socketlisten I ' listen
#if Cdebug
Print "Listening on socket : " ; I
#endif
End Select
Next
End Sub
|
This is the buffer printed to the terminal and the value of Instr at 30>>>>>>>>
RESET of IP
receive buffer size : 287
Read buffer>>>>>>>>>>>>>>>>>>>
GET / HTTP/1.1
Host: 192.168.0.192
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
<<<<read><buffer<<<<<<<
Authorization: Basic at 0 Characters
filetype>0
Valid = 0
HTML page:
RESET of IP
receive buffer size : 322
Read buffer>>>>>>>>>>>>>>>>>>>
GET / HTTP/1.1
Host: 192.168.0.192
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Authorization: Basic ZnJlZDpkb2c=
<<<<read><buffer<<<<<<<
Authorization: Basic at 30 Characters
Tempz1>122
Tempz2>71
>>>>>>>ozilla/5.0 (<<<<<<<<
fred:dog
======
ozilla/5.0 (
======
£8¥•¯ùËI,
======
Regards Paul
(BASCOM-AVR version : 2.0.7.7 ) |
|
Back to top |
|
|
Paulvk
Joined: 28 Jul 2006 Posts: 1257 Location: SYDNEY
|
Posted: Tue May 06, 2014 10:43 am Post subject: |
|
|
It appears bigstrings is not working for me the code below shows a length of 254 for the string when its over 300 so when you search for a match in less than 254 characters you get the correct answer so is it just me or do others have the same problem.
Note: I set the LCD to 20 x 4 in the compiler
Regards Paul
Code: |
$regfile = "m1284pdef.dat"
$crystal = 20000000
$hwstack = 100
$swstack = 100
$framesize = 100
$bigstrings
Const Lineend = "{013}{010}"
Dim Httpa As String * 1001
Dim A As Word
Dim C As Word
Httpa = "GET / HTTP/1.1" + Lineend + "Host: 192.168.0.192" + Lineend + "User -agent : Mozilla / 5.0(windows Nt 6.2 ; Wow64 ; Rv : 28.0) Gecko / 20100101 Firefox / 28.0" + Lineend + "Accept : Text / Html , Application / Xhtml + Xml , Application / Xml ; Q = 0.9 , * / * ; Q = 0.8" + Lineend + "Accept-Language: en-US,en;q=0.5" + Lineend + "Accept -encoding : Gzip , Deflate" + Lineend + "Connection : Keep -alive" + Lineend + "Authorization: Basic ZnJlZDpkb2c=" + Lineend
A = Instr(httpa , "Authorization: Basic")
C = Len(httpa)
Cls
Lcd "position=" ; A
Locate 2 , 1
Lcd "Len=" ; C
A = Instr(httpa , "User -agent : Mozilla")
Locate 3 , 1
Lcd "position2=" ; A
End
|
|
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Tue May 06, 2014 1:15 pm Post subject: |
|
|
i will have a look at it, _________________ Mark |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Tue May 06, 2014 3:13 pm Post subject: |
|
|
Paul
while the strings can be > 255, the string constants are limited to 255.
so your code never worked in any version.
i understand that you try to make a sample and this is not the original problem.
anyway to make it work :
s="some long const"
s=s + "add more to it"
i will increase the internal constant storage.
i got this after i did :
GET / HTTP/1.1
Host: 192.168.0.192
User -agent : Mozilla / 5.0(windows Nt 6.2 ; Wow64 ; Rv : 28.0) Gecko / 20100101 Firefox / 28.0
Accept : Text / Html , Application / Xhtml + Xml , Application / Xml ; Q = 0.9 , * / * ; Q = 0.8
Accept-Language: en-US,en;q=0.5
Accept -encoding : Gzip , Deflate
Connection : Keep -alive
Authorization: Basic ZnJlZDpkb2c=
position=327
Len=361
position2=38
when you write to support i can provide an update that does not need a rewrite of your code. _________________ Mark |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Tue May 06, 2014 9:55 pm Post subject: |
|
|
what you can try : compile the bigstrings lib with lib manager.
i tried to duplicate your problem using this code :
Code: | $regfile = "m1284pdef.dat"
$crystal = 20000000
$hwstack = 100
$swstack = 100
$framesize = 100
$baud = 19200
$BigStrings
Const Lineend = "{013}{010}"
Dim Httpa As String * 1001
'Dim A As Word
Dim C As Word
declare sub test()
test
end
sub test()
local a as word
Httpa = "GET / HTTP/1.1" + Lineend + "Host: 192.168.0.192" + Lineend + "User -agent : Mozilla / 5.0(windows Nt 6.2 ; Wow64 ; Rv : 28.0) Gecko / 20100101 Firefox / 28.0" + Lineend + "Accept : Text / Html , Application / Xhtml + Xml , Application / Xml ; Q = 0.9 , * / * ; Q = 0.8" + Lineend + "Accept-Language: en-US,en;q=0.5" + Lineend + "Accept -encoding : Gzip , Deflate" + Lineend + "Connection : Keep -alive" + Lineend + "Authorization: Basic ZnJlZDpkb2c=" + Lineend
print Httpa
A = Instr(httpa , "Authorization: Basic")
C = Len(httpa)
print "position=" ; A
print "Len=" ; C
A = Instr(httpa , "User -agent : Mozilla")
print "position2=" ; A
End sub |
but it prints the correct values. as you can see i also tested with a local.
make sure you have the correct bigstrings.lib/lbx _________________ Mark |
|
Back to top |
|
|
Paulvk
Joined: 28 Jul 2006 Posts: 1257 Location: SYDNEY
|
Posted: Sun May 11, 2014 12:52 pm Post subject: |
|
|
Hello Mark
Done more testing using IE 6.0 on my XP computer gives different results with the same firmware loaded into the AVR as firefox different string length returned for Len(buffer) less than the Print Buffer shows on terminal which prints the whole of the data from the wiznet buffer I have loaded into the AVR buffer. I also compiled on my XP computer same version of bascom update from your server no copy between computers so as not to copy faulty lib, same results.
It works ok if I build the string as you said keeping each chunk less than 254 as constants as a test, but not when I get it from the wiznet chip.
Regards Paul |
|
Back to top |
|
|
Paulvk
Joined: 28 Jul 2006 Posts: 1257 Location: SYDNEY
|
Posted: Tue May 13, 2014 12:10 pm Post subject: |
|
|
I have tried many ways now , still same result I can not search the string.
Here is very simple code that still reports the length of Buffer wrong
Code: |
'Const Lineend = "{013}{010}"
'Dim Buffer as string * 1001
'Dim I As Byte
'Local Tempx As Word
'Local Bufbytes as word
'Local Gpl as string * 100
'Local Bb as byte
Do
Gpl = ""
Bb = Tcpread(i , Gpl )
Buffer = Buffer + Gpl + Lineend
Bufbytes = Socketstat(i , Sel_recv)
Loop Until Bufbytes = 0
Tempx = Len(buffer)
Print "buffer length is>" ; Tempx
Print Buffer
wait 10 'here I have time to end terminal capture and close firefox
|
Now if I build the buffer from constants it works!
Note the constants are arranged to match the print in the terminal exactly so both print the same thing!
Code: |
$regfile = "m1284pdef.dat"
$crystal = 8000000
$hwstack = 100
$swstack = 100
$framesize = 100
$baud = 57600
$bigstrings
Dim Httpa As String * 1001
Dim Result As String * 50
Dim A As Word
Dim C As Word
Dim Tempz As Word
Const One = "GET / HTTP/1.1"
Const Two = "Host: 192.168.0.192"
Const Three = "User -agent : Mozilla / 5.0(windows Nt 6.2 ; Wow64 ; Rv : 29.0) Gecko / 20100101 Firefox / 29.0"
Const Four = "Accept : Text / Html , Application / Xhtml + Xml , Application / Xml ; Q = 0.9 , * / * ; Q = 0.8"
Const Five = "Accept-Language: en-US,en;q=0.5"
Const Six = "Accept -encoding : Gzip , Deflate"
Const Seven = "Connection : Keep -alive"
Const Eight = "Authorization: Basic ZnJlZDpkb2c="
Const Lineend = "{013}{010}"
Httpa = One + Lineend + Two + Lineend
Httpa = Httpa + Three + Lineend
Httpa = Httpa + Four + Lineend + Five
Httpa = Httpa + Lineend + Six + Lineend
Httpa = Httpa + Seven + Lineend + Eight + Lineend + Lineend
Print Httpa
Print "----------------------------"
A = Instr(httpa , "Authorization: Basic")
C = Len(httpa)
Print "Len=" ; C
Print "position=" ; A
A = A + 21
Tempz = Instr(a , Httpa , Lineend)
Result = Mid(httpa , A , Tempz)
Print
Print Result
End
|
Here is what is printed to the terminal for Buffer Note >>>>>>>>>>>>> Buffer is in here these show start and end <<<<<<<<<<<<<<<
Read buffer>>>>>>>>>>>>>>>>>>>
GET / HTTP/1.1
Host: 192.168.0.192
User-Agent: Mozilla/5.0 (Windows NT 6.2; Wow64; rv:29.0) Gecko/20100101 Firefox/29.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Authorization: Basic ZnJlZDpkb2c=
<<<<<<<<<<<
Regards Paul |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Tue May 13, 2014 11:12 pm Post subject: |
|
|
Paul
when the same info is printed, it probably only appears to be the same.
So you can do one more test : make a string from constants that should be equal to what you receive.
Then build a second string from the data you receive.
Finally, compare the 2 strings. you can do that with IF THEN, but also character for character, using mid() and asc() and then see where it fails.
also, try to log the data you receive to a file. that way embedded 0 or other data can be found.
When that does not help, make a small as possible test program and send it here or to support. _________________ Mark |
|
Back to top |
|
|
Paulvk
Joined: 28 Jul 2006 Posts: 1257 Location: SYDNEY
|
Posted: Wed May 14, 2014 12:07 am Post subject: |
|
|
Hello Mark
I am logging to file but as text so I will log it as hex bytes this will show any diffrences. I will also put both bits of code into the one program and run them to see if they both fail or one works. I will also go back to the original code posted on the forum and change it to read the wiznet buffer into a ram buffer as I am doing and see if that fails or not.
Working with this it would be handy if you could have Bascom save the code into a zip type file with date & time so that each time you get to a stage it is backed up at that point so when something stops working you can go back to a previous working copy, maybe one of the people on the forum could write this utility then you need only add a link/button as I know you have far to much to do as it is.
Regards Paul |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Wed May 14, 2014 9:17 am Post subject: |
|
|
Paul
the zip thing is already on my todo list.
i thought i had a history backup already but i was confused. i work at too many things at the same time. will add it to todo as well. it simply saves your code with a unique name each time you compile. _________________ Mark |
|
Back to top |
|
|
Paulvk
Joined: 28 Jul 2006 Posts: 1257 Location: SYDNEY
|
Posted: Sun May 25, 2014 1:19 pm Post subject: |
|
|
Ok have been busy so I have just now put the code that works in line before the code I am having problems with. I built the string from constants then printed the string, then the length etc as in the working test code (I copied it from the working test) and it failed it did exactly as the next lot of code which is what is not working , but they were consistent both did exactly the same. So when I get time I will start from the beginning and put together just enough code to get it to the point of building the string from the W5100 buffer , printing the length of the string and searching for the password to see if that fails.
Regards Paul |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|