| OLD | NEW |
| 1 #include <iostream> | 1 #include <iostream> |
| 2 #include <sstream> | 2 #include <sstream> |
| 3 | 3 |
| 4 #include "MatchesCommand.h" | 4 #include "MatchesCommand.h" |
| 5 | 5 |
| 6 MatchesCommand::MatchesCommand(AdblockPlus::FilterEngine& filterEngine) | 6 MatchesCommand::MatchesCommand(AdblockPlus::FilterEngine& filterEngine) |
| 7 : Command("matches"), filterEngine(filterEngine) | 7 : Command("matches"), filterEngine(filterEngine) |
| 8 { | 8 { |
| 9 } | 9 } |
| 10 | 10 |
| 11 void MatchesCommand::operator()(const std::string& arguments) | 11 void MatchesCommand::operator()(const std::string& arguments) |
| 12 { | 12 { |
| 13 std::istringstream argumentStream(arguments); | 13 std::istringstream argumentStream(arguments); |
| 14 std::string url; | 14 std::string url; |
| 15 argumentStream >> url; | 15 argumentStream >> url; |
| 16 std::string contentType; | 16 std::string contentType; |
| 17 argumentStream >> contentType; | 17 argumentStream >> contentType; |
| 18 std::string documentUrl; | 18 std::string documentUrl; |
| 19 argumentStream >> documentUrl; | 19 argumentStream >> documentUrl; |
| 20 if (!url.size() || !contentType.size() || !documentUrl.size()) | 20 if (!url.size() || !contentType.size() || !documentUrl.size()) |
| 21 { | 21 { |
| 22 ShowUsage(); | 22 ShowUsage(); |
| 23 return; | 23 return; |
| 24 } | 24 } |
| 25 | 25 |
| 26 AdblockPlus::FilterPtr match = filterEngine.Matches(url, contentType, document
Url); | 26 AdblockPlus::FilterPtr match = filterEngine.Matches(url, contentType, document
Url); |
| 27 if (!match) | 27 if (!match) |
| 28 std::cout << "No match" << std::endl; | 28 std::cout << "No match" << std::endl; |
| 29 else if (match->GetProperty("type", "") == "exception") | 29 else if (match->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION) |
| 30 std::cout << "Whitelisted" << std::endl; | 30 std::cout << "Whitelisted by " << match->GetProperty("text")->AsString() <<
std::endl; |
| 31 else | 31 else |
| 32 std::cout << "Blocked" << std::endl; | 32 std::cout << "Blocked by " << match->GetProperty("text")->AsString() << std:
:endl; |
| 33 } | 33 } |
| 34 | 34 |
| 35 std::string MatchesCommand::GetDescription() const | 35 std::string MatchesCommand::GetDescription() const |
| 36 { | 36 { |
| 37 return "Returns the first filter that matches the supplied URL"; | 37 return "Returns the first filter that matches the supplied URL"; |
| 38 } | 38 } |
| 39 | 39 |
| 40 std::string MatchesCommand::GetUsage() const | 40 std::string MatchesCommand::GetUsage() const |
| 41 { | 41 { |
| 42 return name + " URL CONTENT_TYPE DOCUMENT_URL"; | 42 return name + " URL CONTENT_TYPE DOCUMENT_URL"; |
| 43 } | 43 } |
| OLD | NEW |