Example #1
0
 private TelephoneNumber local_phone_number() throws ParseException {
   if (debug) dbg_enter("local_phone_number");
   TelephoneNumber tn = new TelephoneNumber();
   tn.setGlobal(false);
   NameValueList nv = null;
   String b = null;
   try {
     b = local_number();
     tn.setPhoneNumber(b);
     if (lexer.hasMoreChars()) {
       Token tok = this.lexer.peekNextToken();
       switch (tok.getTokenType()) {
         case SEMICOLON:
           {
             this.lexer.consume(1);
             nv = tel_parameters();
             tn.setParameters(nv);
             break;
           }
         default:
           {
             break;
           }
       }
     }
   } finally {
     if (debug) dbg_leave("local_phone_number");
   }
   return tn;
 }
  public SIPHeader parse() throws ParseException {

    ContentType contentType = new ContentType();
    if (debug) dbg_enter("ContentTypeParser.parse");

    try {
      this.headerName(TokenTypes.CONTENT_TYPE);

      // The type:
      lexer.match(TokenTypes.ID);
      Token type = lexer.getNextToken();
      this.lexer.SPorHT();
      contentType.setContentType(type.getTokenValue());

      // The sub-type:
      lexer.match('/');
      lexer.match(TokenTypes.ID);
      Token subType = lexer.getNextToken();
      this.lexer.SPorHT();
      contentType.setContentSubType(subType.getTokenValue());
      super.parse(contentType);
      this.lexer.match('\n');
    } finally {
      if (debug) dbg_leave("ContentTypeParser.parse");
    }
    return contentType;
  }
Example #3
0
  /**
   * parse the String message
   *
   * @return SIPHeader (AcceptEncoding object)
   * @throws ParseException if the message does not respect the spec.
   */
  public SIPHeader parse() throws ParseException {
    AcceptEncodingList acceptEncodingList = new AcceptEncodingList();
    if (debug) dbg_enter("AcceptEncodingParser.parse");

    try {
      headerName(TokenTypes.ACCEPT_ENCODING);
      // empty body is fine for this header.
      if (lexer.lookAhead(0) == '\n') {
        AcceptEncoding acceptEncoding = new AcceptEncoding();
        acceptEncodingList.add(acceptEncoding);
      } else {
        while (lexer.lookAhead(0) != '\n') {
          AcceptEncoding acceptEncoding = new AcceptEncoding();
          if (lexer.lookAhead(0) != ';') {
            // Content-Coding:
            lexer.match(TokenTypes.ID);
            Token value = lexer.getNextToken();
            acceptEncoding.setEncoding(value.getTokenValue());
          }

          while (lexer.lookAhead(0) == ';') {
            this.lexer.match(';');
            this.lexer.SPorHT();
            this.lexer.match('q');
            this.lexer.SPorHT();
            this.lexer.match('=');
            this.lexer.SPorHT();
            lexer.match(TokenTypes.ID);
            Token value = lexer.getNextToken();
            try {
              float qv = Float.parseFloat(value.getTokenValue());
              acceptEncoding.setQValue(qv);
            } catch (NumberFormatException ex) {
              throw createParseException(ex.getMessage());
            } catch (InvalidArgumentException ex) {
              throw createParseException(ex.getMessage());
            }
            this.lexer.SPorHT();
          }

          acceptEncodingList.add(acceptEncoding);
          if (lexer.lookAhead(0) == ',') {
            this.lexer.match(',');
            this.lexer.SPorHT();
          }
        }
      }
      return acceptEncodingList;
    } finally {
      if (debug) dbg_leave("AcceptEncodingParser.parse");
    }
  }
Example #4
0
  /**
   * parse the Accept String header
   *
   * @return SIPHeader (AcceptList object)
   * @throws SIPParseException if the message does not respect the spec.
   */
  public SIPHeader parse() throws ParseException {

    if (debug) dbg_enter("AcceptParser.parse");
    AcceptList list = new AcceptList();

    try {
      headerName(TokenTypes.ACCEPT);

      Accept accept = new Accept();
      accept.setHeaderName(SIPHeaderNames.ACCEPT);

      this.lexer.SPorHT();
      this.lexer.match(TokenTypes.ID);
      Token token = lexer.getNextToken();
      accept.setContentType(token.getTokenValue());
      this.lexer.match('/');
      this.lexer.match(TokenTypes.ID);
      token = lexer.getNextToken();
      accept.setContentSubType(token.getTokenValue());
      this.lexer.SPorHT();

      super.parse(accept);
      list.add(accept);

      while (lexer.lookAhead(0) == ',') {
        this.lexer.match(',');
        this.lexer.SPorHT();

        accept = new Accept();

        this.lexer.match(TokenTypes.ID);
        token = lexer.getNextToken();
        accept.setContentType(token.getTokenValue());
        this.lexer.match('/');
        this.lexer.match(TokenTypes.ID);
        token = lexer.getNextToken();
        accept.setContentSubType(token.getTokenValue());
        this.lexer.SPorHT();
        super.parse(accept);
        list.add(accept);
      }
      return list;
    } finally {
      if (debug) dbg_leave("AcceptParser.parse");
    }
  }
Example #5
0
  /**
   * parse the String message
   *
   * @return SIPHeader (RequireList object)
   * @throws SIPParseException if the message does not respect the spec.
   */
  public SIPHeader parse() throws ParseException {
    RequireList requireList = new RequireList();
    if (debug) dbg_enter("RequireParser.parse");

    try {
      headerName(TokenTypes.REQUIRE);

      while (lexer.lookAhead(0) != '\n') {
        Require r = new Require();
        r.setHeaderName(SIPHeaderNames.REQUIRE);

        // Parsing the option tag
        this.lexer.match(TokenTypes.ID);
        Token token = lexer.getNextToken();
        r.setOptionTag(token.getTokenValue());
        this.lexer.SPorHT();

        requireList.add(r);

        while (lexer.lookAhead(0) == ',') {
          this.lexer.match(',');
          this.lexer.SPorHT();

          r = new Require();

          // Parsing the option tag
          this.lexer.match(TokenTypes.ID);
          token = lexer.getNextToken();
          r.setOptionTag(token.getTokenValue());
          this.lexer.SPorHT();

          requireList.add(r);
        }
      }
    } finally {
      if (debug) dbg_leave("RequireParser.parse");
    }

    return requireList;
  }
Example #6
0
  /**
   * 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 ParsException if there was a problem parsing.
   */
  public GenericURI uriReference() throws ParseException {
    if (debug) dbg_enter("uriReference");
    GenericURI retval = null;
    Vector<?> vect = lexer.peekNextToken(2);
    Token t1 = (Token) vect.elementAt(0);
    Token t2 = (Token) vect.elementAt(1);
    try {

      // System.out.println("token = "  + t1.getTokenValue());
      // System.out.println("tokenval = " + t1.getTokenType());

      if (t1.getTokenType() == TokenTypes.SIP) {
        if (t2.getTokenType() == ':') retval = sipURL();
        else throw createParseException("Expecting \':\'");
      } else if (t1.getTokenType() == TokenTypes.TEL) {
        if (t2.getTokenType() == ':') {
          retval = telURL();
        } 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;
  }
  /**
   * parse the String message
   *
   * @return SIPHeader (RetryAfter object)
   * @throws SIPParseException if the message does not respect the spec.
   */
  public SIPHeader parse() throws ParseException {

    if (debug) dbg_enter("RetryAfterParser.parse");

    RetryAfter retryAfter = new RetryAfter();
    try {
      headerName(TokenTypes.RETRY_AFTER);

      // mandatory delatseconds:
      String value = lexer.number();
      try {
        int ds = Integer.parseInt(value);
        retryAfter.setRetryAfter(ds);
      } catch (NumberFormatException ex) {
        throw createParseException(ex.getMessage());
      } catch (InvalidArgumentException ex) {
        throw createParseException(ex.getMessage());
      }

      this.lexer.SPorHT();
      if (lexer.lookAhead(0) == '(') {
        String comment = this.lexer.comment();
        retryAfter.setComment(comment);
      }
      this.lexer.SPorHT();

      while (lexer.lookAhead(0) == ';') {
        this.lexer.match(';');
        this.lexer.SPorHT();
        lexer.match(TokenTypes.ID);
        Token token = lexer.getNextToken();
        value = token.getTokenValue();
        if (value.equalsIgnoreCase("duration")) {
          this.lexer.match('=');
          this.lexer.SPorHT();
          value = lexer.number();
          try {
            int duration = Integer.parseInt(value);
            retryAfter.setDuration(duration);
          } catch (NumberFormatException ex) {
            throw createParseException(ex.getMessage());
          } catch (InvalidArgumentException ex) {
            throw createParseException(ex.getMessage());
          }
        } else {
          this.lexer.SPorHT();
          this.lexer.match('=');
          this.lexer.SPorHT();
          lexer.match(TokenTypes.ID);
          Token secondToken = lexer.getNextToken();
          String secondValue = secondToken.getTokenValue();
          retryAfter.setParameter(value, secondValue);
        }
        this.lexer.SPorHT();
      }
    } finally {
      if (debug) dbg_leave("RetryAfterParser.parse");
    }

    return retryAfter;
  }