private final static String basePhoneNumber(String number) throws ParseException { StringBuffer s = new StringBuffer(); Lexer lexer = new Lexer("sip_urlLexer", number); int lc = 0; while (lexer.hasMoreChars()) { char w = lexer.lookAhead(0); if (Lexer.isDigit(w) || w == '-' || w == '.' || w == '(' || w == ')') { lexer.consume(1); s.append(w); lc++; } // else if (lc > 0) // break; else throw new IllegalArgumentException("unexpected " + w + " in the phone number"); } return s.toString(); }
/** * Creates new HeaderParser * @param String to parse. */ protected HeaderParser(String header) { this.lexer = new Lexer("command_keywordLexer", header); }
String headerName = Lexer.getHeaderName(line); String headerValue = Lexer.getHeaderValue(line); if (headerName == null || headerValue == null) throw new ParseException("The header name or value is null", 0);
@Override protected void processHeader(String header, SIPMessage message, ParseExceptionListener parseExceptionListener, byte[] msgBuffer) throws ParseException { String headerName = Lexer.getHeaderName(header); if (headerName == null) throw new ParseException("The header name or value is null", 0); // logic to process headers only if they are present in the list of headers to parse from a given stack property if(headersToParse.contains(headerName.toLowerCase())) { super.processHeader(header, message, parseExceptionListener, msgBuffer); } else { ((SelectiveMessage) message).addHeaderNotParsed(headerName, header); } }
/** * Parser for the base phone number. */ private String base_phone_number() throws ParseException { StringBuilder s = new StringBuilder(); if (debug) dbg_enter("base_phone_number"); try { int lc = 0; while (lexer.hasMoreChars()) { char w = lexer.lookAhead(0); if (Lexer.isDigit(w) || w == '-' || w == '.' || w == '(' || w == ')') { lexer.consume(1); s.append(w); lc++; } else if (lc > 0) break; else throw createParseException("unexpected " + w); } return s.toString(); } finally { if (debug) dbg_leave("base_phone_number"); } }
protected static boolean isUnreserved(char next) { return Lexer.isAlphaDigit(next) || isMark(next); }
protected String uric() { if (debug) dbg_enter("uric"); try { try { char la = lexer.lookAhead(0); if (isUnreserved(la)) { lexer.consume(1); return Lexer.charAsString(la); } else if (isReserved(la)) { lexer.consume(1); return Lexer.charAsString(la); } else if (isEscaped()) { String retval = lexer.charAsString(3); lexer.consume(3); return retval; } else return null; } catch (Exception ex) { return null; } } finally { if (debug) dbg_leave("uric"); } }
addKeyword(TokenNames.REGISTER, TokenTypes.REGISTER); addKeyword(TokenNames.ACK, TokenTypes.ACK); addKeyword(TokenNames.OPTIONS, TokenTypes.OPTIONS); addKeyword(TokenNames.BYE, TokenTypes.BYE); addKeyword(TokenNames.INVITE, TokenTypes.INVITE); addKeyword(TokenNames.SIP, TokenTypes.SIP); addKeyword(TokenNames.SIPS, TokenTypes.SIPS); addKeyword(TokenNames.SUBSCRIBE, TokenTypes.SUBSCRIBE); addKeyword(TokenNames.NOTIFY, TokenTypes.NOTIFY); addKeyword(TokenNames.MESSAGE, TokenTypes.MESSAGE); addKeyword(TokenNames.PUBLISH, TokenTypes.PUBLISH); addKeyword(ErrorInfoHeader.NAME, TokenTypes.ERROR_INFO); addKeyword(AllowEventsHeader.NAME, TokenTypes.ALLOW_EVENTS); addKeyword(AuthenticationInfoHeader.NAME, TokenTypes.AUTHENTICATION_INFO); addKeyword(EventHeader.NAME, TokenTypes.EVENT); addKeyword(MinExpiresHeader.NAME, TokenTypes.MIN_EXPIRES); addKeyword(RSeqHeader.NAME, TokenTypes.RSEQ); addKeyword(RAckHeader.NAME, TokenTypes.RACK); addKeyword(ReasonHeader.NAME, TokenTypes.REASON); addKeyword(ReplyToHeader.NAME, TokenTypes.REPLY_TO); addKeyword(SubscriptionStateHeader.NAME,
public RequestLineParser(String requestLine) { this.lexer = new Lexer("method_keywordLexer", requestLine); } public RequestLineParser(Lexer lexer) {
} catch (ParseException ex) { if (parseExceptionListener != null) { String headerName = Lexer.getHeaderName(header); Class headerClass = NameMap.getClassFromName(headerName); if (headerClass == null) {
isValidChar = true; if (isValidChar || Lexer.isAlphaDigit(la)) { lexer.consume(1); retval.append(la);
protected String uricNoSlash() { if (debug) dbg_enter("uricNoSlash"); try { try { char la = lexer.lookAhead(0); if (isEscaped()) { String retval = lexer.charAsString(3); lexer.consume(3); return retval; } else if (isUnreserved(la)) { lexer.consume(1); return Lexer.charAsString(la); } else if (isReservedNoSlash(la)) { lexer.consume(1); return Lexer.charAsString(la); } else return null; } catch (ParseException ex) { return null; } } finally { if (debug) dbg_leave("uricNoSlash"); } }
public URLParser(String url) { this.lexer = new Lexer("sip_urlLexer", url); }
/** * Parses the 'phone-context' parameter in tel: URLs * @throws ParseException */ private NameValue phone_context() throws ParseException { lexer.match('='); char la = lexer.lookAhead(0); Object value; if (la=='+') {// global-number-digits lexer.consume(1);// skip '+' value = "+" + base_phone_number(); } else if ( Lexer.isAlphaDigit(la) ) { Token t = lexer.match( Lexer.ID );// more broad than allowed value = t.getTokenValue(); } else { throw new ParseException( "Invalid phone-context:" + la , -1 ); } return new NameValue( "phone-context", value, false ); }
public StatusLineParser(String statusLine) { this.lexer = new Lexer("status_lineLexer", statusLine); }
public AddressParser(String address) { this.lexer = new Lexer("charLexer", address); }
/** * Parse a host name and return a parsed structure. * * @param host * is a String containing the host name to be parsed * @return a parsed address structure. * @since v1.0 * @exception ParseException * a ParseException when the hostname is badly formatted. */ public Host parseHost(String host) throws ParseException { Lexer lexer = new Lexer("charLexer", host); return new HostNameParser(lexer).host(); }