/** * @return bool|wfWAFLexerToken * @throws wfWAFParserSyntaxError */ public function nextToken() { if (!$this->scanner->eos()) { /** @var wfWAFLexerTokenMatcher $tokenMatcher */ foreach ($this->tokenMatchers as $tokenMatcher) { $this->scanner->skip('/^\\s+/s'); if ($this->scanner->eos()) { return false; } if (($this->flags & self::FLAG_TOKENIZE_MYSQL_PORTABLE_COMMENTS) === 0 && ($tokenMatcher->getTokenID() === self::MYSQL_PORTABLE_COMMENT_START || $tokenMatcher->getTokenID() === self::MYSQL_PORTABLE_COMMENT_END)) { continue; } if (!$this->hasPortableCommentStart && $tokenMatcher->getTokenID() === self::MYSQL_PORTABLE_COMMENT_END) { continue; } if ($tokenMatcher->useMaximalMunch() && ($match = $this->scanner->check($tokenMatcher->getMatch())) !== null) { $biggestToken = $this->createToken($tokenMatcher->getTokenID(), $match); /** @var wfWAFLexerTokenMatcher $tokenMatcher2 */ foreach ($this->tokenMatchers as $tokenMatcher2) { if ($tokenMatcher === $tokenMatcher2) { continue; } if (($match2 = $this->scanner->check($tokenMatcher2->getMatch())) !== null) { $biggestToken2 = $this->createToken($tokenMatcher2->getTokenID(), $match2); if (wfWAFUtils::strlen($biggestToken2->getValue()) > wfWAFUtils::strlen($biggestToken->getValue())) { $biggestToken = $biggestToken2; } } } $this->scanner->advancePointer(wfWAFUtils::strlen($biggestToken->getValue())); return $biggestToken; } else { if (($match = $this->scanner->scan($tokenMatcher->getMatch())) !== null) { $token = $this->createToken($tokenMatcher->getTokenID(), $match); if ($tokenMatcher->getTokenID() === self::MYSQL_PORTABLE_COMMENT_START) { $this->hasPortableCommentStart = true; } else { if ($tokenMatcher->getTokenID() === self::MYSQL_PORTABLE_COMMENT_END) { $this->hasPortableCommentStart = false; } } return $token; } } } $char = $this->scanner->scanChar(); $e = new wfWAFParserSyntaxError(sprintf('Invalid character "%s" (\\x%02x) found on line %d, column %d', $char, ord($char), $this->scanner->getLine(), $this->scanner->getColumn())); $e->setParseLine($this->scanner->getLine()); $e->setParseColumn($this->scanner->getColumn()); throw $e; } return false; }
/** * @return bool|wfWAFLexerToken * @throws wfWAFParserSyntaxError */ public function nextToken() { if (!$this->scanner->eos()) { $this->scanner->skip('/\\s+/s'); if ($this->scanner->eos()) { return false; } if (($match = $this->scanner->scan(self::MATCH_IDENTIFIER)) !== null) { switch (wfWAFUtils::strtolower($match)) { case 'if': return $this->createToken(self::T_RULE_START, $match); case 'and': case 'or': case 'xor': return $this->createToken(self::T_COMPARISON_OPERATOR, $match); default: return $this->createToken(self::T_IDENTIFIER, $match); } } else { if (($match = $this->scanner->scan(self::MATCH_SINGLE_STRING_LITERAL)) !== null) { return $this->createToken(self::T_SINGLE_STRING_LITERAL, $match); } else { if (($match = $this->scanner->scan(self::MATCH_DOUBLE_STRING_LITERAL)) !== null) { return $this->createToken(self::T_DOUBLE_STRING_LITERAL, $match); } else { if (($match = $this->scanner->scan(self::MATCH_NUMBER_LITERAL)) !== null) { return $this->createToken(self::T_NUMBER_LITERAL, $match); } else { if (($match = $this->scanner->scan(self::MATCH_DOT)) !== null) { return $this->createToken(self::T_DOT, $match); } else { if (($match = $this->scanner->scan(self::MATCH_COMPARISON_OPERATOR)) !== null) { return $this->createToken(self::T_COMPARISON_OPERATOR, $match); } else { if (($match = $this->scanner->scan(self::MATCH_OPEN_PARENTHESIS)) !== null) { return $this->createToken(self::T_OPEN_PARENTHESIS, $match); } else { if (($match = $this->scanner->scan(self::MATCH_CLOSE_PARENTHESIS)) !== null) { return $this->createToken(self::T_CLOSE_PARENTHESIS, $match); } else { if (($match = $this->scanner->scan(self::MATCH_COMMA)) !== null) { return $this->createToken(self::T_COMMA, $match); } else { if (($match = $this->scanner->scan(self::MATCH_RULE_COMPARISON_END)) !== null) { return $this->createToken(self::T_RULE_COMPARISON_END, $match); } else { if (($match = $this->scanner->scan(self::MATCH_ASSIGNMENT)) !== null) { return $this->createToken(self::T_ASSIGNMENT, $match); } else { if (($match = $this->scanner->scan(self::MATCH_OPEN_BRACKET)) !== null) { return $this->createToken(self::T_OPEN_BRACKET, $match); } else { if (($match = $this->scanner->scan(self::MATCH_CLOSE_BRACKET)) !== null) { return $this->createToken(self::T_CLOSE_BRACKET, $match); } else { if (($match = $this->scanner->scan(self::MATCH_SINGLE_LINE_COMMENT)) !== null) { return $this->createToken(self::T_SINGLE_LINE_COMMENT, $match); } else { if (($match = $this->scanner->scan(self::MATCH_MULTIPLE_LINE_COMMENT)) !== null) { return $this->createToken(self::T_MULTIPLE_LINE_COMMENT, $match); } else { $e = new wfWAFParserSyntaxError(sprintf('Invalid character "%s" found on line %d, column %d', $this->scanner->scanChar(), $this->scanner->getLine(), $this->scanner->getColumn())); $e->setParseLine($this->scanner->getLine()); $e->setParseColumn($this->scanner->getColumn()); throw $e; } } } } } } } } } } } } } } } } return false; }