Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
WS4D
jCoAP
Commits
7e8d9e00
Commit
7e8d9e00
authored
Jun 25, 2015
by
Bjoern Konieczek
Browse files
Fixing Path Length Bug & Alllowing very long Option Values
parent
6d52561b
Changes
2
Hide whitespace changes
Inline
Side-by-side
ws4d-jcoap/src/org/ws4d/coap/messages/AbstractCoapMessage.java
View file @
7e8d9e00
...
...
@@ -538,7 +538,8 @@ public abstract class AbstractCoapMessage implements CoapMessage {
int
shortLength
;
int
longLength
;
int
deserializedLength
;
static
final
int
MAX_LENGTH
=
255
;
static
final
int
MAX_SEGMENT_LENGTH
=
255
;
static
final
int
MAX_PROXI_URI_LENGTH
=
1034
;
public
int
getDeserializedLength
()
{
return
deserializedLength
;
...
...
@@ -652,9 +653,15 @@ public abstract class AbstractCoapMessage implements CoapMessage {
public
int
getSerializeLength
(){
int
serializedLength
=
optionData
.
length
;
if
(
hasLongLength
()){
serializedLength
+=
2
;
if
(
hasLongLength
()
){
// If shortLength is 14, two extra length bytes follow the initial byte
if
(
shortLength
==
14
)
serializedLength
+=
3
;
// If shortLength is 13, only one extra length byte follows the initial byte
else
serializedLength
+=
2
;
}
else
{
// If shortLength < 13, only the initial byte, containing 4 bit optionDelta and 4 bit option value length is added
serializedLength
++;
}
...
...
ws4d-jcoap/src/org/ws4d/coap/messages/BasicCoapRequest.java
View file @
7e8d9e00
...
...
@@ -65,7 +65,7 @@ public class BasicCoapRequest extends AbstractCoapMessage implements CoapRequest
if
(
options
.
optionExists
(
CoapHeaderOptionType
.
Uri_Host
)){
throw
new
IllegalArgumentException
(
"Uri-Host option already exists"
);
}
if
(
host
.
length
()
<
1
||
host
.
length
()
>
CoapHeaderOption
.
MAX_LENGTH
){
if
(
host
.
length
()
<
1
||
host
.
length
()
>
CoapHeaderOption
.
MAX_
SEGMENT_
LENGTH
){
throw
new
IllegalArgumentException
(
"Invalid Uri-Host option length"
);
}
/*TODO: check if host is a valid address */
...
...
@@ -97,7 +97,7 @@ public class BasicCoapRequest extends AbstractCoapMessage implements CoapRequest
/* add a Uri Path option for each part */
for
(
String
element
:
pathElements
)
{
/* check length */
if
(
element
.
length
()
<
0
||
element
.
length
()
>
CoapHeaderOption
.
MAX_LENGTH
){
if
(
element
.
length
()
<
0
||
element
.
length
()
>
CoapHeaderOption
.
MAX_
SEGMENT_
LENGTH
){
throw
new
IllegalArgumentException
(
"Invalid Uri-Path length!"
);
}
else
if
(
element
.
length
()
>
0
){
/* ignore empty substrings */
...
...
@@ -109,11 +109,7 @@ public class BasicCoapRequest extends AbstractCoapMessage implements CoapRequest
@Override
public
void
setUriQuery
(
String
query
)
{
if
(
query
==
null
)
return
;
if
(
query
.
length
()
>
CoapHeaderOption
.
MAX_LENGTH
){
throw
new
IllegalArgumentException
(
"Uri-Query option too long"
);
}
/* delete old options if present */
options
.
removeOption
(
CoapHeaderOptionType
.
Uri_Query
);
...
...
@@ -122,8 +118,8 @@ public class BasicCoapRequest extends AbstractCoapMessage implements CoapRequest
/* add a Uri Path option for each part */
for
(
String
element
:
pathElements
)
{
/* check length */
if
(
element
.
length
()
<
0
||
element
.
length
()
>
CoapHeaderOption
.
MAX_LENGTH
){
throw
new
IllegalArgumentException
(
"Invalid Uri-
Path
"
);
if
(
element
.
length
()
<
0
||
element
.
length
()
>
CoapHeaderOption
.
MAX_
SEGMENT_
LENGTH
){
throw
new
IllegalArgumentException
(
"Invalid Uri-
Query
"
);
}
else
if
(
element
.
length
()
>
0
){
/* ignore empty substrings */
options
.
addOption
(
CoapHeaderOptionType
.
Uri_Query
,
element
.
getBytes
());
...
...
@@ -144,8 +140,8 @@ public class BasicCoapRequest extends AbstractCoapMessage implements CoapRequest
throw
new
IllegalArgumentException
(
"Proxy Uri must be at least one byte long"
);
}
if
(
proxyUri
.
length
()
>
CoapHeaderOption
.
MAX_LENGTH
){
throw
new
IllegalArgumentException
(
"Proxy Uri longer then
270
bytes are not supported
yet (to be implemented)
"
);
if
(
proxyUri
.
length
()
>
CoapHeaderOption
.
MAX_
PROXI_URI_
LENGTH
){
throw
new
IllegalArgumentException
(
"Proxy Uri longer then
1034
bytes are not supported
!
"
);
}
options
.
addOption
(
CoapHeaderOptionType
.
Proxy_Uri
,
proxyUri
.
getBytes
());
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment