Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

closes RestComm/jain-slee#111 #149

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ThE-MaRaC
Copy link
Contributor

No description provided.

@@ -34,8 +34,8 @@
*/
public class Debug {

public static boolean debug = false;
public static boolean parserDebug = false;
public static boolean debug = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need these flags set to true? would it be possible you used them for debugging and forget to set them to false again?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are back to false

@@ -736,7 +736,8 @@ public String number() throws ParseException {

int startIdx = ptr;
try {
if (!isDigit(lookAhead(0))) {
char c = lookAhead(0);
if (c != '-' && !isDigit(c)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this logic will affect several parsing scenarios. What is the reasoning to include the condition on "-" char? is it based on any RFC3261 statement? can you include a link to the grammar that supports this rule?

Copy link
Contributor Author

@ThE-MaRaC ThE-MaRaC May 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it is based on the following RFC: https://tools.ietf.org/html/rfc4475#section-3.3.9
RFC states:
From a framing perspective, this situation is equivalent to an invalid Content-Length value (or no value at all).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you include this link,and brief explanation as comment

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my concern is that this requirement seems to be specific for Content-Length header, but this piece of code we are modifying is applied to all sort of numberic header conversions.., hence im afraid we can break contract for other headers...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
this a brief of main usages for "number" method including different types of headers

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apparently, if I rewrite the test as in (i prefer my version,not based on asserting exception message, but whether exception hs been raised or not)9:
// https://github.com/RestComm/jain-slee/issues/111 public void testNegativeContentLength(){ try { final String header = "Content-Length: -123 \n"; System.out.print(header); createParser(ContentLengthParser.class, header).parse(); fail("previous command should have raise an expection"); } catch (java.text.ParseException ex) { //expected exception thrown } }

Even the original code passes, throwing the parseexception (at different part of the logic).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All JUnit parser tests (jain-sip/src/test/unit/gov/nist/javax/sip/parser) are OK.

From the headers above the following are covered:

  • HostNameParserTest
  • TimeStampParserTest
  • ContentLengthParserTest
  • CSeqParserTest
  • MaxForwardsParserTest
  • MimeVersionParserTest
  • MinExpiresParserTest
  • RetryAfterParserTest

TCK regression is also OK.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you think about my claim? "Even the original code passes, throwing the parseexception (at different part of the logic)."

@@ -43,7 +43,7 @@

protected ParseException createParseException(String exceptionString) {
return new ParseException(
lexer.getBuffer() + ":" + exceptionString,
lexer.getBuffer().trim() + ":" + exceptionString,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need to "trim" here? messages should be already well formatted..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if parsing fails, like for example negative number value, buffer will contain new line (\n) at the end, so that's the reason for the trim

logger.logDebug("Sending automatic 400 Bad Request:");
logger.logDebug(badReqRes.toString());
}
sendResponse(badReqRes);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we add a Reason-Phrase header with the exception message?

Copy link
Contributor Author

@ThE-MaRaC ThE-MaRaC May 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementation is based on MessageChannel.createBadReqRes, so if we plan to add it, it should be added everywhere
For Reason header, we can use the same exception message that is used in response:
SIPResponse badReqRes = sipRequest.createResponse(Response.BAD_REQUEST, "Bad Request (" + pe.getLocalizedMessage() + ')');

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementation for reason header is also ready, it is based on RFC3326.
Should I add it here or in a separate bug report?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we may introduce that later in a separate PR

throw new TransactionUnavailableException(ex.getMessage(), ex);
} catch (ParseException pe) {
try {
SIPResponse badReqRes = sipRequest.createResponse(Response.BAD_REQUEST,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have you tested this somehow? could you add ad test case for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the bug report (RestComm/jain-slee#111) there is a SIPP TC which was used to test this correction, but I will additionally create junit TC

@jaimecasero
Copy link
Contributor

RestComm/jain-slee#111

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants