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.core.*; 29 30 import gov.nist.javax.sip.header.extensions.*; 31 32 import gov.nist.javax.sip.header.ims.*; 33 34 import javax.sip.header.*; 35 import java.util.Hashtable; 36 37 /** 38 * Lexer class for the parser. 39 * 40 * @version 1.2 41 * 42 * @author M. Ranganathan <br/> 43 * 44 * 45 */ 46 public class Lexer extends LexerCore { 47 /** 48 * get the header name of the line 49 * 50 * @return the header name (stuff before the :) bug fix submitted by 51 * zvali@dev.java.net 52 */ getHeaderName(String line)53 public static String getHeaderName(String line) { 54 if (line == null) 55 return null; 56 String headerName = null; 57 try { 58 int begin = line.indexOf(":"); 59 headerName = null; 60 if (begin >= 1) 61 headerName = line.substring(0, begin).trim(); 62 } catch (IndexOutOfBoundsException e) { 63 return null; 64 } 65 return headerName; 66 } 67 Lexer(String lexerName, String buffer)68 public Lexer(String lexerName, String buffer) { 69 super(lexerName, buffer); 70 this.selectLexer(lexerName); 71 } 72 73 /** 74 * get the header value of the line 75 * 76 * @return String 77 */ getHeaderValue(String line)78 public static String getHeaderValue(String line) { 79 if (line == null) 80 return null; 81 String headerValue = null; 82 try { 83 int begin = line.indexOf(":"); 84 headerValue = line.substring(begin + 1); 85 } catch (IndexOutOfBoundsException e) { 86 return null; 87 } 88 return headerValue; 89 } 90 selectLexer(String lexerName)91 public void selectLexer(String lexerName) { 92 synchronized (lexerTables) { 93 // Synchronization Bug fix by Robert Rosen. 94 currentLexer = (Hashtable) lexerTables.get(lexerName); 95 this.currentLexerName = lexerName; 96 if (currentLexer == null) { 97 addLexer(lexerName); 98 if (lexerName.equals("method_keywordLexer")) { 99 addKeyword(TokenNames.REGISTER, TokenTypes.REGISTER); 100 addKeyword(TokenNames.ACK, TokenTypes.ACK); 101 addKeyword(TokenNames.OPTIONS, TokenTypes.OPTIONS); 102 addKeyword(TokenNames.BYE, TokenTypes.BYE); 103 addKeyword(TokenNames.INVITE, TokenTypes.INVITE); 104 addKeyword(TokenNames.SIP.toUpperCase(), TokenTypes.SIP); 105 addKeyword(TokenNames.SIPS.toUpperCase(), TokenTypes.SIPS); 106 addKeyword(TokenNames.SUBSCRIBE, TokenTypes.SUBSCRIBE); 107 addKeyword(TokenNames.NOTIFY, TokenTypes.NOTIFY); 108 addKeyword(TokenNames.MESSAGE, TokenTypes.MESSAGE); 109 110 // JvB: added to support RFC3903 111 addKeyword(TokenNames.PUBLISH, TokenTypes.PUBLISH); 112 113 } else if (lexerName.equals("command_keywordLexer")) { 114 addKeyword(ErrorInfoHeader.NAME.toUpperCase(), 115 TokenTypes.ERROR_INFO); 116 addKeyword(AllowEventsHeader.NAME.toUpperCase(), 117 TokenTypes.ALLOW_EVENTS); 118 addKeyword(AuthenticationInfoHeader.NAME.toUpperCase(), 119 TokenTypes.AUTHENTICATION_INFO); 120 addKeyword(EventHeader.NAME.toUpperCase(), TokenTypes.EVENT); 121 addKeyword(MinExpiresHeader.NAME.toUpperCase(), 122 TokenTypes.MIN_EXPIRES); 123 addKeyword(RSeqHeader.NAME.toUpperCase(), TokenTypes.RSEQ); 124 addKeyword(RAckHeader.NAME.toUpperCase(), TokenTypes.RACK); 125 addKeyword(ReasonHeader.NAME.toUpperCase(), 126 TokenTypes.REASON); 127 addKeyword(ReplyToHeader.NAME.toUpperCase(), 128 TokenTypes.REPLY_TO); 129 addKeyword(SubscriptionStateHeader.NAME.toUpperCase(), 130 TokenTypes.SUBSCRIPTION_STATE); 131 addKeyword(TimeStampHeader.NAME.toUpperCase(), 132 TokenTypes.TIMESTAMP); 133 addKeyword(InReplyToHeader.NAME.toUpperCase(), 134 TokenTypes.IN_REPLY_TO); 135 addKeyword(MimeVersionHeader.NAME.toUpperCase(), 136 TokenTypes.MIME_VERSION); 137 addKeyword(AlertInfoHeader.NAME.toUpperCase(), 138 TokenTypes.ALERT_INFO); 139 addKeyword(FromHeader.NAME.toUpperCase(), TokenTypes.FROM); 140 addKeyword(ToHeader.NAME.toUpperCase(), TokenTypes.TO); 141 addKeyword(ReferToHeader.NAME.toUpperCase(), 142 TokenTypes.REFER_TO); 143 addKeyword(ViaHeader.NAME.toUpperCase(), TokenTypes.VIA); 144 addKeyword(UserAgentHeader.NAME.toUpperCase(), 145 TokenTypes.USER_AGENT); 146 addKeyword(ServerHeader.NAME.toUpperCase(), 147 TokenTypes.SERVER); 148 addKeyword(AcceptEncodingHeader.NAME.toUpperCase(), 149 TokenTypes.ACCEPT_ENCODING); 150 addKeyword(AcceptHeader.NAME.toUpperCase(), 151 TokenTypes.ACCEPT); 152 addKeyword(AllowHeader.NAME.toUpperCase(), TokenTypes.ALLOW); 153 addKeyword(RouteHeader.NAME.toUpperCase(), TokenTypes.ROUTE); 154 addKeyword(AuthorizationHeader.NAME.toUpperCase(), 155 TokenTypes.AUTHORIZATION); 156 addKeyword(ProxyAuthorizationHeader.NAME.toUpperCase(), 157 TokenTypes.PROXY_AUTHORIZATION); 158 addKeyword(RetryAfterHeader.NAME.toUpperCase(), 159 TokenTypes.RETRY_AFTER); 160 addKeyword(ProxyRequireHeader.NAME.toUpperCase(), 161 TokenTypes.PROXY_REQUIRE); 162 addKeyword(ContentLanguageHeader.NAME.toUpperCase(), 163 TokenTypes.CONTENT_LANGUAGE); 164 addKeyword(UnsupportedHeader.NAME.toUpperCase(), 165 TokenTypes.UNSUPPORTED); 166 addKeyword(SupportedHeader.NAME.toUpperCase(), 167 TokenTypes.SUPPORTED); 168 addKeyword(WarningHeader.NAME.toUpperCase(), 169 TokenTypes.WARNING); 170 addKeyword(MaxForwardsHeader.NAME.toUpperCase(), 171 TokenTypes.MAX_FORWARDS); 172 addKeyword(DateHeader.NAME.toUpperCase(), TokenTypes.DATE); 173 addKeyword(PriorityHeader.NAME.toUpperCase(), 174 TokenTypes.PRIORITY); 175 addKeyword(ProxyAuthenticateHeader.NAME.toUpperCase(), 176 TokenTypes.PROXY_AUTHENTICATE); 177 addKeyword(ContentEncodingHeader.NAME.toUpperCase(), 178 TokenTypes.CONTENT_ENCODING); 179 addKeyword(ContentLengthHeader.NAME.toUpperCase(), 180 TokenTypes.CONTENT_LENGTH); 181 addKeyword(SubjectHeader.NAME.toUpperCase(), 182 TokenTypes.SUBJECT); 183 addKeyword(ContentTypeHeader.NAME.toUpperCase(), 184 TokenTypes.CONTENT_TYPE); 185 addKeyword(ContactHeader.NAME.toUpperCase(), 186 TokenTypes.CONTACT); 187 addKeyword(CallIdHeader.NAME.toUpperCase(), 188 TokenTypes.CALL_ID); 189 addKeyword(RequireHeader.NAME.toUpperCase(), 190 TokenTypes.REQUIRE); 191 addKeyword(ExpiresHeader.NAME.toUpperCase(), 192 TokenTypes.EXPIRES); 193 addKeyword(RecordRouteHeader.NAME.toUpperCase(), 194 TokenTypes.RECORD_ROUTE); 195 addKeyword(OrganizationHeader.NAME.toUpperCase(), 196 TokenTypes.ORGANIZATION); 197 addKeyword(CSeqHeader.NAME.toUpperCase(), TokenTypes.CSEQ); 198 addKeyword(AcceptLanguageHeader.NAME.toUpperCase(), 199 TokenTypes.ACCEPT_LANGUAGE); 200 addKeyword(WWWAuthenticateHeader.NAME.toUpperCase(), 201 TokenTypes.WWW_AUTHENTICATE); 202 addKeyword(CallInfoHeader.NAME.toUpperCase(), 203 TokenTypes.CALL_INFO); 204 addKeyword(ContentDispositionHeader.NAME.toUpperCase(), 205 TokenTypes.CONTENT_DISPOSITION); 206 // And now the dreaded short forms.... 207 addKeyword(TokenNames.K.toUpperCase(), TokenTypes.SUPPORTED); 208 addKeyword(TokenNames.C.toUpperCase(), 209 TokenTypes.CONTENT_TYPE); 210 addKeyword(TokenNames.E.toUpperCase(), 211 TokenTypes.CONTENT_ENCODING); 212 addKeyword(TokenNames.F.toUpperCase(), TokenTypes.FROM); 213 addKeyword(TokenNames.I.toUpperCase(), TokenTypes.CALL_ID); 214 addKeyword(TokenNames.M.toUpperCase(), TokenTypes.CONTACT); 215 addKeyword(TokenNames.L.toUpperCase(), 216 TokenTypes.CONTENT_LENGTH); 217 addKeyword(TokenNames.S.toUpperCase(), TokenTypes.SUBJECT); 218 addKeyword(TokenNames.T.toUpperCase(), TokenTypes.TO); 219 addKeyword(TokenNames.U.toUpperCase(), 220 TokenTypes.ALLOW_EVENTS); // JvB: added 221 addKeyword(TokenNames.V.toUpperCase(), TokenTypes.VIA); 222 addKeyword(TokenNames.R.toUpperCase(), TokenTypes.REFER_TO); 223 addKeyword(TokenNames.O.toUpperCase(), TokenTypes.EVENT); // Bug 224 // fix 225 // by 226 // Mario 227 // Mantak 228 addKeyword(TokenNames.X.toUpperCase(), TokenTypes.SESSIONEXPIRES_TO); // Bug fix by Jozef Saniga 229 230 // JvB: added to support RFC3903 231 addKeyword(SIPETagHeader.NAME.toUpperCase(), 232 TokenTypes.SIP_ETAG); 233 addKeyword(SIPIfMatchHeader.NAME.toUpperCase(), 234 TokenTypes.SIP_IF_MATCH); 235 236 // pmusgrave: Add RFC4028 and ReferredBy 237 addKeyword(SessionExpiresHeader.NAME.toUpperCase(), 238 TokenTypes.SESSIONEXPIRES_TO); 239 addKeyword(MinSEHeader.NAME.toUpperCase(), 240 TokenTypes.MINSE_TO); 241 addKeyword(ReferredByHeader.NAME.toUpperCase(), 242 TokenTypes.REFERREDBY_TO); 243 244 // pmusgrave RFC3891 245 addKeyword(ReplacesHeader.NAME.toUpperCase(), 246 TokenTypes.REPLACES_TO); 247 //jean deruelle RFC3911 248 addKeyword(JoinHeader.NAME.toUpperCase(), 249 TokenTypes.JOIN_TO); 250 251 // IMS Headers 252 addKeyword(PathHeader.NAME.toUpperCase(), TokenTypes.PATH); 253 addKeyword(ServiceRouteHeader.NAME.toUpperCase(), 254 TokenTypes.SERVICE_ROUTE); 255 addKeyword(PAssertedIdentityHeader.NAME.toUpperCase(), 256 TokenTypes.P_ASSERTED_IDENTITY); 257 addKeyword(PPreferredIdentityHeader.NAME.toUpperCase(), 258 TokenTypes.P_PREFERRED_IDENTITY); 259 addKeyword(PrivacyHeader.NAME.toUpperCase(), 260 TokenTypes.PRIVACY); 261 262 // issued by Miguel Freitas 263 addKeyword(PCalledPartyIDHeader.NAME.toUpperCase(), 264 TokenTypes.P_CALLED_PARTY_ID); 265 addKeyword(PAssociatedURIHeader.NAME.toUpperCase(), 266 TokenTypes.P_ASSOCIATED_URI); 267 addKeyword(PVisitedNetworkIDHeader.NAME.toUpperCase(), 268 TokenTypes.P_VISITED_NETWORK_ID); 269 addKeyword(PChargingFunctionAddressesHeader.NAME 270 .toUpperCase(), 271 TokenTypes.P_CHARGING_FUNCTION_ADDRESSES); 272 addKeyword(PChargingVectorHeader.NAME.toUpperCase(), 273 TokenTypes.P_VECTOR_CHARGING); 274 addKeyword(PAccessNetworkInfoHeader.NAME.toUpperCase(), 275 TokenTypes.P_ACCESS_NETWORK_INFO); 276 addKeyword(PMediaAuthorizationHeader.NAME.toUpperCase(), 277 TokenTypes.P_MEDIA_AUTHORIZATION); 278 279 addKeyword(SecurityServerHeader.NAME.toUpperCase(), 280 TokenTypes.SECURITY_SERVER); 281 addKeyword(SecurityVerifyHeader.NAME.toUpperCase(), 282 TokenTypes.SECURITY_VERIFY); 283 addKeyword(SecurityClientHeader.NAME.toUpperCase(), 284 TokenTypes.SECURITY_CLIENT); 285 286 // added by aayush@rancore 287 addKeyword(PUserDatabaseHeader.NAME.toUpperCase(), 288 TokenTypes.P_USER_DATABASE); 289 290 // added by aayush@rancore 291 addKeyword(PProfileKeyHeader.NAME.toUpperCase(), 292 TokenTypes.P_PROFILE_KEY); 293 294 // added by aayush@rancore 295 addKeyword(PServedUserHeader.NAME.toUpperCase(), 296 TokenTypes.P_SERVED_USER); 297 298 // added by aayush@rancore 299 addKeyword(PPreferredServiceHeader.NAME.toUpperCase(), 300 TokenTypes.P_PREFERRED_SERVICE); 301 302 // added by aayush@rancore 303 addKeyword(PAssertedServiceHeader.NAME.toUpperCase(), 304 TokenTypes.P_ASSERTED_SERVICE); 305 306 // added References header 307 addKeyword(ReferencesHeader.NAME.toUpperCase(),TokenTypes.REFERENCES); 308 309 // end // 310 311 312 } else if (lexerName.equals("status_lineLexer")) { 313 addKeyword(TokenNames.SIP.toUpperCase(), TokenTypes.SIP); 314 } else if (lexerName.equals("request_lineLexer")) { 315 addKeyword(TokenNames.SIP.toUpperCase(), TokenTypes.SIP); 316 } else if (lexerName.equals("sip_urlLexer")) { 317 addKeyword(TokenNames.TEL.toUpperCase(), TokenTypes.TEL); 318 addKeyword(TokenNames.SIP.toUpperCase(), TokenTypes.SIP); 319 addKeyword(TokenNames.SIPS.toUpperCase(), TokenTypes.SIPS); 320 } 321 } 322 } 323 } 324 } 325