| 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 java.text.ParseException; |
| 30 |
|
| 31 |
/** |
| 32 |
* Parser for Server header. |
| 33 |
* |
| 34 |
* @version 1.2 $Revision: 1.9 $ $Date: 2009/07/17 18:58:05 $ |
| 35 |
* |
| 36 |
* @author Olivier Deruelle <br/> |
| 37 |
* @author M. Ranganathan <br/> |
| 38 |
* |
| 39 |
* |
| 40 |
*/ |
| 41 |
public class ServerParser extends HeaderParser { |
| 42 |
|
| 43 |
/** |
| 44 |
* Creates a new instance of ServerParser |
| 45 |
* @param server the header to parse |
| 46 |
*/ |
| 47 |
public ServerParser(String server) { |
| 48 |
super(server); |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Constructor |
| 53 |
* @param lexer the lexer to use to parse the header |
| 54 |
*/ |
| 55 |
protected ServerParser(Lexer lexer) { |
| 56 |
super(lexer); |
| 57 |
} |
| 58 |
|
| 59 |
/** |
| 60 |
* parse the String server |
| 61 |
* @return SIPHeader (Server object) |
| 62 |
* @throws SIPParseException if the message does not respect the spec. |
| 63 |
*/ |
| 64 |
public SIPHeader parse() throws ParseException { |
| 65 |
|
| 66 |
if (debug) |
| 67 |
dbg_enter("ServerParser.parse"); |
| 68 |
Server server = new Server(); |
| 69 |
try { |
| 70 |
headerName(TokenTypes.SERVER); |
| 71 |
if (this.lexer.lookAhead(0) == '\n') |
| 72 |
throw createParseException("empty header"); |
| 73 |
|
| 74 |
// mandatory token: product[/product-version] | (comment) |
| 75 |
while (this.lexer.lookAhead(0) != '\n' |
| 76 |
&& this.lexer.lookAhead(0) != '\0') { |
| 77 |
if (this.lexer.lookAhead(0) == '(') { |
| 78 |
String comment = this.lexer.comment(); |
| 79 |
server.addProductToken('(' + comment + ')'); |
| 80 |
} else { |
| 81 |
String tok; |
| 82 |
int marker = 0; |
| 83 |
try { |
| 84 |
marker = this.lexer.markInputPosition(); |
| 85 |
tok = this.lexer.getString('/'); |
| 86 |
|
| 87 |
if (tok.charAt(tok.length() - 1) == '\n') |
| 88 |
tok = tok.trim(); |
| 89 |
server.addProductToken(tok); |
| 90 |
} catch (ParseException ex) { |
| 91 |
this.lexer.rewindInputPosition(marker); |
| 92 |
tok = this.lexer.getRest().trim(); |
| 93 |
server.addProductToken(tok); |
| 94 |
break; |
| 95 |
} |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
} finally { |
| 100 |
if (debug) |
| 101 |
dbg_leave("ServerParser.parse"); |
| 102 |
} |
| 103 |
|
| 104 |
return server; |
| 105 |
} |
| 106 |
|
| 107 |
/* |
| 108 |
public static void main(String args[]) throws ParseException { |
| 109 |
String server[] = { |
| 110 |
"Server: Softphone/Beta1.5 \n", |
| 111 |
"Server: HomeServer v2\n", |
| 112 |
"Server: Nist/Beta1 (beta version) \n", |
| 113 |
"Server: Nist proxy (beta version)\n", |
| 114 |
"Server: Nist1.0/Beta2 UbiServer/vers.1.0 (new stuff) (Cool) \n", |
| 115 |
"Server: Sip EXpress router (0.8.11 (sparc64/solaris))\n" |
| 116 |
}; |
| 117 |
|
| 118 |
for (int i = 0; i < server.length; i++ ) { |
| 119 |
ServerParser parser = |
| 120 |
new ServerParser(server[i]); |
| 121 |
Server s= (Server) parser.parse(); |
| 122 |
System.out.println("encoded = " + s.encode()); |
| 123 |
} |
| 124 |
|
| 125 |
} |
| 126 |
*/ |
| 127 |
|
| 128 |
} |
| 129 |
/* |
| 130 |
* $Log: ServerParser.java,v $ |
| 131 |
* Revision 1.9 2009/07/17 18:58:05 emcho |
| 132 |
* Converts indentation tabs to spaces so that we have a uniform indentation policy in the whole project. |
| 133 |
* |
| 134 |
* Revision 1.8 2006/07/13 09:02:16 mranga |
| 135 |
* Issue number: |
| 136 |
* Obtained from: |
| 137 |
* Submitted by: jeroen van bemmel |
| 138 |
* Reviewed by: mranga |
| 139 |
* Moved some changes from jain-sip-1.2 to java.net |
| 140 |
* |
| 141 |
* CVS: ---------------------------------------------------------------------- |
| 142 |
* CVS: Issue number: |
| 143 |
* CVS: If this change addresses one or more issues, |
| 144 |
* CVS: then enter the issue number(s) here. |
| 145 |
* CVS: Obtained from: |
| 146 |
* CVS: If this change has been taken from another system, |
| 147 |
* CVS: then name the system in this line, otherwise delete it. |
| 148 |
* CVS: Submitted by: |
| 149 |
* CVS: If this code has been contributed to the project by someone else; i.e., |
| 150 |
* CVS: they sent us a patch or a set of diffs, then include their name/email |
| 151 |
* CVS: address here. If this is your work then delete this line. |
| 152 |
* CVS: Reviewed by: |
| 153 |
* CVS: If we are doing pre-commit code reviews and someone else has |
| 154 |
* CVS: reviewed your changes, include their name(s) here. |
| 155 |
* CVS: If you have not had it reviewed then delete this line. |
| 156 |
* |
| 157 |
* Revision 1.4 2006/06/19 06:47:27 mranga |
| 158 |
* javadoc fixups |
| 159 |
* |
| 160 |
* Revision 1.3 2006/06/17 10:18:14 mranga |
| 161 |
* Added some synchronization to the sequence number checking. |
| 162 |
* Small javadoc fixups |
| 163 |
* |
| 164 |
* Revision 1.2 2006/06/16 15:26:28 mranga |
| 165 |
* Added NIST disclaimer to all public domain files. Clean up some javadoc. Fixed a leak |
| 166 |
* |
| 167 |
* Revision 1.1.1.1 2005/10/04 17:12:36 mranga |
| 168 |
* |
| 169 |
* Import |
| 170 |
* |
| 171 |
* |
| 172 |
* Revision 1.6 2004/01/30 17:10:47 mranga |
| 173 |
* Reviewed by: mranga |
| 174 |
* Server and user agent parser leave an extra Linefeed at the end of token. |
| 175 |
* |
| 176 |
* Revision 1.5 2004/01/27 13:52:11 mranga |
| 177 |
* Reviewed by: mranga |
| 178 |
* Fixed server/user-agent parser. |
| 179 |
* suppress sending ack to TU when retransFilter is enabled and ack is retransmitted. |
| 180 |
* |
| 181 |
* Revision 1.4 2004/01/22 13:26:32 sverker |
| 182 |
* Issue number: |
| 183 |
* Obtained from: |
| 184 |
* Submitted by: sverker |
| 185 |
* Reviewed by: mranga |
| 186 |
* |
| 187 |
* Major reformat of code to conform with style guide. Resolved compiler and javadoc warnings. Added CVS tags. |
| 188 |
* |
| 189 |
* CVS: ---------------------------------------------------------------------- |
| 190 |
* CVS: Issue number: |
| 191 |
* CVS: If this change addresses one or more issues, |
| 192 |
* CVS: then enter the issue number(s) here. |
| 193 |
* CVS: Obtained from: |
| 194 |
* CVS: If this change has been taken from another system, |
| 195 |
* CVS: then name the system in this line, otherwise delete it. |
| 196 |
* CVS: Submitted by: |
| 197 |
* CVS: If this code has been contributed to the project by someone else; i.e., |
| 198 |
* CVS: they sent us a patch or a set of diffs, then include their name/email |
| 199 |
* CVS: address here. If this is your work then delete this line. |
| 200 |
* CVS: Reviewed by: |
| 201 |
* CVS: If we are doing pre-commit code reviews and someone else has |
| 202 |
* CVS: reviewed your changes, include their name(s) here. |
| 203 |
* CVS: If you have not had it reviewed then delete this line. |
| 204 |
* |
| 205 |
*/ |