Feature/cherrypick ws (#52)
* int to hex * Websocket frame size * Hash methods refactor * Uri components fix
This commit is contained in:
1 parent
0e2be8d5bb
commit
0d79c4975e
4 files changed
+56
-14
No files matched your search
@@ -36,13 +36,11 @@ namespace Web
|
|||||||
|
|
||||||
secondByte = m.ReadByte()
|
secondByte = m.ReadByte()
|
||||||
m.is_masked = (secondByte and &h80) <> 0
|
m.is_masked = (secondByte and &h80) <> 0
|
||||||
m.payload_size = secondByte and &h7F
|
|
||||||
|
|
||||||
if not m.is_masked
|
if not m.is_masked
|
||||||
return false
|
return false
|
||||||
end if
|
end if
|
||||||
|
|
||||||
if m.payload_size >= 126
|
if not m.ReadPayloadSize(secondByte)
|
||||||
return false
|
return false
|
||||||
end if
|
end if
|
||||||
|
|
||||||
@@ -56,13 +54,41 @@ namespace Web
|
|||||||
return true
|
return true
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
function ReadPayloadSize(secondByte as integer) as integer
|
||||||
|
payloadSize = secondByte and &h7F
|
||||||
|
if payloadSize < 126
|
||||||
|
m.payload_size = payloadSize
|
||||||
|
return true
|
||||||
|
else if payloadSize = 126
|
||||||
|
payloadSize = (m.ReadByte() << 8) or m.ReadByte()
|
||||||
|
m.payload_size = payloadSize
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
'TODO: Read size in 8 bytes
|
||||||
|
return false
|
||||||
|
end if
|
||||||
|
end function
|
||||||
|
|
||||||
|
function WritePayloadSize(payloadSize as integer)
|
||||||
|
if payloadSize < 126
|
||||||
|
m.WriteByte(payloadSize)
|
||||||
|
else if payloadSize < 65536
|
||||||
|
m.WriteByte(126)
|
||||||
|
m.WriteByte(payloadSize >> 8)
|
||||||
|
m.WriteByte(payloadSize and &hFF)
|
||||||
|
else
|
||||||
|
m.WriteByte(127)
|
||||||
|
'TODO: Write size in 8 bytes
|
||||||
|
end if
|
||||||
|
end function
|
||||||
|
|
||||||
function WriteToBuffer(buffer as object, index as integer, length as integer) as integer
|
function WriteToBuffer(buffer as object, index as integer, length as integer) as integer
|
||||||
m.buffer = buffer
|
m.buffer = buffer
|
||||||
m.index = index
|
m.index = index
|
||||||
m.length = length
|
m.length = length
|
||||||
|
|
||||||
m.WriteByte(m.fin or m.opcode)
|
m.WriteByte(m.fin or m.opcode)
|
||||||
m.WriteByte(m.payload_size)
|
m.WritePayloadSize(m.payload_size)
|
||||||
|
|
||||||
for i = 0 to m.payload_size - 1
|
for i = 0 to m.payload_size - 1
|
||||||
m.buffer[m.index] = m.payload[i]
|
m.buffer[m.index] = m.payload[i]
|
||||||
|
|||||||
@@ -16,4 +16,15 @@ namespace ColorUtils
|
|||||||
|
|
||||||
return value
|
return value
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
function IntToHex(color as integer) as string
|
||||||
|
hexDigits = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"]
|
||||||
|
hexString = "#"
|
||||||
|
|
||||||
|
for i = 7 to 0 step -1
|
||||||
|
hexString = hexString + hexDigits[(color >> (i * 4)) and &hF]
|
||||||
|
end for
|
||||||
|
|
||||||
|
return hexString
|
||||||
|
end function
|
||||||
end namespace
|
end namespace
|
||||||
@@ -1,17 +1,20 @@
|
|||||||
function GetSha256(input as string) as string
|
function GetSha256(input as string) as string
|
||||||
buffer = CreateObject("roByteArray")
|
return GetEvpDigest(input, "sha256")
|
||||||
buffer.FromAsciiString(input)
|
|
||||||
|
|
||||||
digest = CreateObject("roEVPDigest")
|
|
||||||
digest.Setup("sha256")
|
|
||||||
return digest.Process(buffer)
|
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function GetSha1(input as string) as string
|
function GetSha1(input as string) as string
|
||||||
|
return GetEvpDigest(input, "sha1")
|
||||||
|
end function
|
||||||
|
|
||||||
|
function GetMd5(input as string) as string
|
||||||
|
return GetEvpDigest(input, "md5")
|
||||||
|
end function
|
||||||
|
|
||||||
|
function GetEvpDigest(input as string, method as string) as string
|
||||||
buffer = CreateObject("roByteArray")
|
buffer = CreateObject("roByteArray")
|
||||||
buffer.FromAsciiString(input)
|
buffer.FromAsciiString(input)
|
||||||
|
|
||||||
digest = CreateObject("roEVPDigest")
|
digest = CreateObject("roEVPDigest")
|
||||||
digest.Setup("sha1")
|
digest.Setup(method)
|
||||||
return digest.Process(buffer)
|
return digest.Process(buffer)
|
||||||
end function
|
end function
|
||||||
@@ -13,7 +13,7 @@ namespace WebUtils
|
|||||||
if Instr(0, component, "=")
|
if Instr(0, component, "=")
|
||||||
keyValue = component.split("=")
|
keyValue = component.split("=")
|
||||||
key = keyValue[0]
|
key = keyValue[0]
|
||||||
value = keyValue[1]
|
value = keyValue[1].DecodeUriComponent()
|
||||||
hasValue = true
|
hasValue = true
|
||||||
end if
|
end if
|
||||||
|
|
||||||
@@ -22,11 +22,13 @@ namespace WebUtils
|
|||||||
if GetInterface(oldValue, "ifArray") = invalid
|
if GetInterface(oldValue, "ifArray") = invalid
|
||||||
oldValue = [oldValue]
|
oldValue = [oldValue]
|
||||||
end if
|
end if
|
||||||
oldValue.push(value)
|
oldValue.push(value.DecodeUriComponent())
|
||||||
value = oldValue
|
value = oldValue
|
||||||
end if
|
end if
|
||||||
|
|
||||||
query[key] = value
|
if key <> ""
|
||||||
|
query[key] = value
|
||||||
|
end if
|
||||||
end for
|
end for
|
||||||
return query
|
return query
|
||||||
end function
|
end function
|
||||||
|
|||||||
Reference in new issue
Block a user