1 /* 2 * Conditions Of Use 3 * 4 * This software was developed by employees of the National Institute of 5 * Standards and Technology (NIST), an agency of the Federal Government. 6 * Pursuant to title 15 Untied States Code Section 105, works of NIST 7 * employees are not subject to copyright protection in the United States 8 * and are considered to be in the public domain. As a result, a formal 9 * license is not needed to use the software. 10 * 11 * This software is provided by NIST as a service and is expressly 12 * provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED 13 * OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF 14 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT 15 * AND DATA ACCURACY. NIST does not warrant or make any representations 16 * regarding the use of the software or the results thereof, including but 17 * not limited to the correctness, accuracy, reliability or usefulness of 18 * the software. 19 * 20 * Permission to use this software is contingent upon your acceptance 21 * of the terms of this agreement 22 * 23 * . 24 * 25 */ 26 package gov.nist.javax.sip.parser; 27 28 import gov.nist.javax.sip.header.*; 29 import gov.nist.core.*; 30 import java.text.ParseException; 31 32 /** 33 * Parser for the challenge portion of the authentication header. 34 * 35 * @version 1.2 $Revision: 1.8 $ $Date: 2009/07/17 18:57:58 $ 36 * @since 1.1 37 * 38 * @author Olivier Deruelle <br/> 39 * 40 * 41 */ 42 43 public abstract class ChallengeParser extends HeaderParser { 44 45 /** 46 * Constructor 47 * @param String challenge message to parse to set 48 */ 49 protected ChallengeParser(String challenge) { 50 super(challenge); 51 } 52 53 /** 54 * Constructor 55 * @param String challenge message to parse to set 56 */ 57 protected ChallengeParser(Lexer lexer) { 58 super(lexer); 59 } 60 61 /** 62 * Get the parameter of the challenge string 63 * @return NameValue containing the parameter 64 */ 65 protected void parseParameter(AuthenticationHeader header) 66 throws ParseException { 67 68 if (debug) 69 dbg_enter("parseParameter"); 70 try { 71 NameValue nv = this.nameValue('='); 72 header.setParameter(nv); 73 } finally { 74 if (debug) 75 dbg_leave("parseParameter"); 76 } 77 78 } 79 80 /** 81 * parser the String message. 82 * @param header - header structure to fill in. 83 * @throws ParseException if the message does not respect the spec. 84 */ 85 public void parse(AuthenticationHeader header) throws ParseException { 86 87 // the Scheme: 88 this.lexer.SPorHT(); 89 lexer.match(TokenTypes.ID); 90 Token type = lexer.getNextToken(); 91 this.lexer.SPorHT(); 92 header.setScheme(type.getTokenValue()); 93 94 // The parameters: 95 try { 96 while (lexer.lookAhead(0) != '\n') { 97 this.parseParameter(header); 98 this.lexer.SPorHT(); 99 char la = lexer.lookAhead(0); 100 if (la == '\n' || la == '\0') 101 break; 102 this.lexer.match(','); 103 this.lexer.SPorHT(); 104 } 105 } catch (ParseException ex) { 106 throw ex; 107 } 108 } 109 } 110