Permalink
Browse files

Merge pull request #21 from vladimirralev/ims-header-issue-20

Fixes and tests for #20
2 parents 80ff040 + fe55ea9 commit 9575b7346795d650473ae601063f0bab2f8b13a4 @ranganathanm ranganathanm committed on GitHub Dec 22, 2016
@@ -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;
@@ -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)
@@ -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
*/
@@ -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();
@@ -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"
};

0 comments on commit 9575b73

Please sign in to comment.