Skip to content

Commit

Permalink
Merge pull request #21 from vladimirralev/ims-header-issue-20
Browse files Browse the repository at this point in the history
Fixes and tests for #20
  • Loading branch information
ranganathanm committed Dec 22, 2016
2 parents 80ff040 + fe55ea9 commit 9575b73
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 4 deletions.
50 changes: 50 additions & 0 deletions src/gov/nist/core/LexerCore.java
Expand Up @@ -479,6 +479,56 @@ public String ttokenSafe() {
return null;
}
}

public String ttokenGenValue() {
int startIdx = ptr;
try {
while (hasMoreChars()) {
char nextChar = lookAhead(0);
if (isAlphaDigit(nextChar)) {
consume(1);
}
else {
boolean isValidChar = false;
switch (nextChar) {
case '_':
case '+':
case '-':
case '!':
case '`':
case '\'':
case '.':
case '/':
case '}':
case '{':
case ']':
case '[':
case '^':
case '|':
case '~':
case '%': // bug fix by Bruno Konik, JvB copied here
case '#':
case '@':
case '$':
case ':':
case '?':
case '\"':
case '*':
isValidChar = true;
}
if (isValidChar) {
consume(1);
}
else {
break;
}
}
}
return String.valueOf(buffer, startIdx, ptr - startIdx);
} catch (ParseException ex) {
return null;
}
}

static final char ALPHA_VALID_CHARS = Character.MAX_VALUE;
static final char DIGIT_VALID_CHARS = Character.MAX_VALUE - 1;
Expand Down
35 changes: 32 additions & 3 deletions src/gov/nist/javax/sip/parser/ims/PAccessNetworkInfoParser.java
Expand Up @@ -49,7 +49,7 @@
* <p>RFC 3455 - Private Header (P-Header) Extensions to the Session Initiation
* Protocol (SIP) for the 3rd-Generation Partnership Project (3GPP) </p>
*
* <p>Sintax (RFC 3455):</p>
* <p>Syntax (RFC 3455):</p>
* <pre>
* P-Access-Network-Info = "P-Access-Network-Info" HCOLON access-net-spec
* access-net-spec = access-type *(SEMI access-info)
Expand All @@ -60,7 +60,23 @@
* extension-access-info = gen-value
* cgi-3gpp = "cgi-3gpp" EQUAL (token / quoted-string)
* utran-cell-id-3gpp = "utran-cell-id-3gpp" EQUAL (token / quoted-string)
* gen-value = token / host / quoted-string
* </pre>
*
* <p>RFC 7913 - P-Access-Network-Info ABNF Update </p>
* <p>Newer RFC https://tools.ietf.org/html/rfc7913</p>
* <pre>
* access-info = cgi-3gpp / utran-cell-id-3gpp /
* dsl-location / i-wlan-node-id /
* ci-3gpp2 / eth-location /
* ci-3gpp2-femto / fiber-location /
* np / gstn-location /local-time-zone /
* dvb-rcs2-node-id / operator-specific-GI /
* utran-sai-3gpp / extension-access-info
* np = "network-provided"
* extension-access-info = generic-param
* </pre>
*
*
* @author Miguel Freitas (IT) PT-Inovacao
*/
Expand Down Expand Up @@ -104,8 +120,21 @@ public SIPHeader parse() throws ParseException
this.lexer.match(';');
this.lexer.SPorHT();

NameValue nv = super.nameValue('=');
accessNetworkInfo.setParameter(nv);
try {
NameValue nv = super.nameValue('=');
accessNetworkInfo.setParameter(nv);
} catch (ParseException e) {
this.lexer.SPorHT();
String ext = this.lexer.quotedString();
if(ext == null) {
ext = this.lexer.ttokenGenValue();
} else {
// avoids tokens such as "a=b" to be stripped of quotes and misinterpretend as
// RFC 7913 generic-param when re-encoded
ext = "\"" + ext + "\"";
}
accessNetworkInfo.setExtensionAccessInfo(ext);
}
this.lexer.SPorHT();
}
this.lexer.SPorHT();
Expand Down
Expand Up @@ -34,8 +34,15 @@ public void testParser() {

String[] accessNetworkInfo = {

"P-Access-Network-Info: 3GPP-UTRAN-TDD; utran-cell-id-3gpp=23456789ABCDE; [123:4::abcd]; rand=l\n",
"P-Access-Network-Info: 3GPP-UTRAN-TDD; utran-cell-id-3gpp=23456789ABCDE; a-b.c1; rand=l\n",
"P-Access-Network-Info: 3GPP-UTRAN-TDD; utran-cell-id-3gpp=23456789ABCDE; 127.0.0.1; rand=l\n",
"P-Access-Network-Info: 3GPP-UTRAN-TDD; utran-cell-id-3gpp=23456789ABCDE;\"\"\n",
"P-Access-Network-Info: 3GPP-UTRAN-TDD; utran-cell-id-3gpp=23456789ABCDE;\";\"\n",
"P-Access-Network-Info: 3GPP-UTRAN-TDD; utran-cell-id-3gpp=23456789ABCDE;\"ip=123.123.123.123\"\n",
"P-Access-Network-Info: 3GPP-UTRAN-TDD; utran-cell-id-3gpp=23456789ABCDE; [123:4::abcd];rand=l\n",
"P-Access-Network-Info: 3GPP-UTRAN-TDD; utran-cell-id-3gpp=23456789ABCDE; [123:4::abcd]\n",
"P-Access-Network-Info: IEEE-802.11\n",

"P-Access-Network-Info: 3GPP-UTRAN-TDD; utran-cell-id-3gpp=23456789ABCDE\n"

};
Expand Down

0 comments on commit 9575b73

Please sign in to comment.