001: /*
002: * Portions Copyright 2000-2007 Sun Microsystems, Inc. All Rights
003: * Reserved. Use is subject to license terms.
004: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License version
008: * 2 only, as published by the Free Software Foundation.
009: *
010: * This program is distributed in the hope that it will be useful, but
011: * WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * General Public License version 2 for more details (a copy is
014: * included at /legal/license.txt).
015: *
016: * You should have received a copy of the GNU General Public License
017: * version 2 along with this work; if not, write to the Free Software
018: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
019: * 02110-1301 USA
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
022: * Clara, CA 95054 or visit www.sun.com if you need additional
023: * information or have any questions.
024: */
025: package gov.nist.siplite.parser;
026:
027: import gov.nist.siplite.header.*;
028: import gov.nist.core.*;
029:
030: /**
031: * Parser for the challenge portion of the authentication header.
032: *
033: * @version JAIN-SIP-1.1
034: *
035: *
036: * <a href="{@docRoot}/uncopyright.html">This code is in the public domain.</a>
037: *
038: * @version 1.0
039: */
040: public abstract class ChallengeParser extends HeaderParser {
041: /** Default constructor. */
042: protected ChallengeParser() {
043: }
044:
045: /**
046: * Constructor with initial challenge string.
047: * @param challenge message to parse to set
048: */
049: protected ChallengeParser(String challenge) {
050: super (challenge);
051: }
052:
053: /**
054: * Constructor with initial lexer engine.
055: * @param lexer initial lexer engine
056: */
057: protected ChallengeParser(Lexer lexer) {
058: super (lexer);
059: }
060:
061: /**
062: * Gets the parameter of the challenge string.
063: * @param header header field to process
064: */
065: protected void parseParameter(AuthenticationHeader header)
066: throws ParseException {
067:
068: if (debug)
069: dbg_enter("parseParameter");
070: try {
071: NameValue nv = nameValue('=');
072: if (header.hasParameter(nv.getName())) {
073: throw new ParseException("Duplicated parameter: "
074: + nv.getName(), 0);
075: }
076: header.setParameter(nv);
077: } finally {
078: if (debug)
079: dbg_leave("parseParameter");
080: }
081: }
082:
083: /**
084: * Parses the String message.
085: * @param header Challenge object for parsed data
086: * @throws ParseException if the message does not respect the spec.
087: */
088: public void parse(AuthenticationHeader header)
089: throws ParseException {
090: // the Scheme:
091: this .lexer.SPorHT();
092: lexer.match(TokenTypes.ID);
093: Token type = lexer.getNextToken();
094: this .lexer.SPorHT();
095: header.setScheme(type.getTokenValue());
096:
097: // The parameters:
098: try {
099: while (lexer.lookAhead(0) != '\n') {
100: this .parseParameter(header);
101: this .lexer.SPorHT();
102: if (lexer.lookAhead(0) == '\n'
103: || lexer.lookAhead(0) == '\0')
104: break;
105: this .lexer.match(',');
106: this .lexer.SPorHT();
107: }
108: } catch (ParseException ex) {
109: throw ex;
110: }
111: }
112: }
|