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;
  }
  /**
   * 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");
    }
  }
Exemple #3
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");
    }
  }
Exemple #4
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;
  }
  /**
   * 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;
  }