Search in sources :

Example 6 with Token

use of gov.nist.core.Token in project XobotOS by xamarin.

the class URLParser method uriReference.

/**
     * Parse and return a structure for a generic URL.
     * Note that non SIP URLs are just stored as a string (not parsed).
     * @return URI is a URL structure for a SIP url.
     * @throws ParseException if there was a problem parsing.
     */
public GenericURI uriReference(boolean inBrackets) throws ParseException {
    if (debug)
        dbg_enter("uriReference");
    GenericURI retval = null;
    Token[] tokens = lexer.peekNextToken(2);
    Token t1 = (Token) tokens[0];
    Token t2 = (Token) tokens[1];
    try {
        if (t1.getTokenType() == TokenTypes.SIP || t1.getTokenType() == TokenTypes.SIPS) {
            if (t2.getTokenType() == ':')
                retval = sipURL(inBrackets);
            else
                throw createParseException("Expecting \':\'");
        } else if (t1.getTokenType() == TokenTypes.TEL) {
            if (t2.getTokenType() == ':') {
                retval = telURL(inBrackets);
            } else
                throw createParseException("Expecting \':\'");
        } else {
            String urlString = uricString();
            try {
                retval = new GenericURI(urlString);
            } catch (ParseException ex) {
                throw createParseException(ex.getMessage());
            }
        }
    } finally {
        if (debug)
            dbg_leave("uriReference");
    }
    return retval;
}
Also used : GenericURI(gov.nist.javax.sip.address.GenericURI) Token(gov.nist.core.Token) ParseException(java.text.ParseException)

Example 7 with Token

use of gov.nist.core.Token in project XobotOS by xamarin.

the class URLParser method sipURL.

/**
     * Parse and return a structure for a SIP URL.
     * @return a URL structure for a SIP url.
     * @throws ParseException if there was a problem parsing.
     */
public SipUri sipURL(boolean inBrackets) throws ParseException {
    if (debug)
        dbg_enter("sipURL");
    SipUri retval = new SipUri();
    // pmusgrave - handle sips case
    Token nextToken = lexer.peekNextToken();
    int sipOrSips = TokenTypes.SIP;
    String scheme = TokenNames.SIP;
    if (nextToken.getTokenType() == TokenTypes.SIPS) {
        sipOrSips = TokenTypes.SIPS;
        scheme = TokenNames.SIPS;
    }
    try {
        lexer.match(sipOrSips);
        lexer.match(':');
        retval.setScheme(scheme);
        int startOfUser = lexer.markInputPosition();
        // Note: user may contain ';', host may not...
        String userOrHost = user();
        String passOrPort = null;
        // name:password or host:port
        if (lexer.lookAhead() == ':') {
            lexer.consume(1);
            passOrPort = password();
        }
        // name@hostPort
        if (lexer.lookAhead() == '@') {
            lexer.consume(1);
            retval.setUser(userOrHost);
            if (passOrPort != null)
                retval.setUserPassword(passOrPort);
        } else {
            // then userOrHost was a host, backtrack just in case a ';' was eaten...
            lexer.rewindInputPosition(startOfUser);
        }
        HostNameParser hnp = new HostNameParser(this.getLexer());
        HostPort hp = hnp.hostPort(false);
        retval.setHostPort(hp);
        lexer.selectLexer("charLexer");
        while (lexer.hasMoreChars()) {
            // If the URI is not enclosed in brackets, parameters belong to header
            if (lexer.lookAhead(0) != ';' || !inBrackets)
                break;
            lexer.consume(1);
            NameValue parms = uriParam();
            if (parms != null)
                retval.setUriParameter(parms);
        }
        if (lexer.hasMoreChars() && lexer.lookAhead(0) == '?') {
            lexer.consume(1);
            while (lexer.hasMoreChars()) {
                NameValue parms = qheader();
                retval.setQHeader(parms);
                if (lexer.hasMoreChars() && lexer.lookAhead(0) != '&')
                    break;
                else
                    lexer.consume(1);
            }
        }
        return retval;
    } finally {
        if (debug)
            dbg_leave("sipURL");
    }
}
Also used : HostNameParser(gov.nist.core.HostNameParser) NameValue(gov.nist.core.NameValue) HostPort(gov.nist.core.HostPort) Token(gov.nist.core.Token) SipUri(gov.nist.javax.sip.address.SipUri)

Example 8 with Token

use of gov.nist.core.Token in project XobotOS by xamarin.

the class PAccessNetworkInfoParser method parse.

public SIPHeader parse() throws ParseException {
    if (debug)
        dbg_enter("AccessNetworkInfoParser.parse");
    try {
        headerName(TokenTypes.P_ACCESS_NETWORK_INFO);
        PAccessNetworkInfo accessNetworkInfo = new PAccessNetworkInfo();
        accessNetworkInfo.setHeaderName(SIPHeaderNamesIms.P_ACCESS_NETWORK_INFO);
        this.lexer.SPorHT();
        lexer.match(TokenTypes.ID);
        Token token = lexer.getNextToken();
        accessNetworkInfo.setAccessType(token.getTokenValue());
        this.lexer.SPorHT();
        while (lexer.lookAhead(0) == ';') {
            this.lexer.match(';');
            this.lexer.SPorHT();
            NameValue nv = super.nameValue('=');
            accessNetworkInfo.setParameter(nv);
            this.lexer.SPorHT();
        }
        this.lexer.SPorHT();
        this.lexer.match('\n');
        return accessNetworkInfo;
    } finally {
        if (debug)
            dbg_leave("AccessNetworkInfoParser.parse");
    }
}
Also used : NameValue(gov.nist.core.NameValue) PAccessNetworkInfo(gov.nist.javax.sip.header.ims.PAccessNetworkInfo) Token(gov.nist.core.Token)

Example 9 with Token

use of gov.nist.core.Token in project XobotOS by xamarin.

the class Parser method method.

/**
     * parses a method. Consumes if a valid method has been found.
     */
protected String method() throws ParseException {
    try {
        if (debug)
            dbg_enter("method");
        Token[] tokens = this.lexer.peekNextToken(1);
        Token token = (Token) tokens[0];
        if (token.getTokenType() == INVITE || token.getTokenType() == ACK || token.getTokenType() == OPTIONS || token.getTokenType() == BYE || token.getTokenType() == REGISTER || token.getTokenType() == CANCEL || token.getTokenType() == SUBSCRIBE || token.getTokenType() == NOTIFY || token.getTokenType() == PUBLISH || token.getTokenType() == MESSAGE || token.getTokenType() == ID) {
            lexer.consume();
            return token.getTokenValue();
        } else {
            throw createParseException("Invalid Method");
        }
    } finally {
        if (Debug.debug)
            dbg_leave("method");
    }
}
Also used : Token(gov.nist.core.Token)

Example 10 with Token

use of gov.nist.core.Token in project XobotOS by xamarin.

the class PVisitedNetworkIDParser method parseToken.

protected void parseToken(PVisitedNetworkID visitedNetworkID) throws ParseException {
    // issued by Miguel Freitas
    lexer.match(TokenTypes.ID);
    Token token = lexer.getNextToken();
    //String value = token.getTokenValue();
    visitedNetworkID.setVisitedNetworkID(token);
    super.parse(visitedNetworkID);
}
Also used : Token(gov.nist.core.Token)

Aggregations

Token (gov.nist.core.Token)10 NameValue (gov.nist.core.NameValue)3 ParseException (java.text.ParseException)3 HostNameParser (gov.nist.core.HostNameParser)1 HostPort (gov.nist.core.HostPort)1 NameValueList (gov.nist.core.NameValueList)1 GenericURI (gov.nist.javax.sip.address.GenericURI)1 SipUri (gov.nist.javax.sip.address.SipUri)1 TelephoneNumber (gov.nist.javax.sip.address.TelephoneNumber)1 SIPHeaderList (gov.nist.javax.sip.header.SIPHeaderList)1 PAccessNetworkInfo (gov.nist.javax.sip.header.ims.PAccessNetworkInfo)1 PMediaAuthorization (gov.nist.javax.sip.header.ims.PMediaAuthorization)1 PMediaAuthorizationList (gov.nist.javax.sip.header.ims.PMediaAuthorizationList)1 InvalidArgumentException (javax.sip.InvalidArgumentException)1