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 if (!url.size() || !contentType.size()) | 18 std::string documentUrl; |
| 19 argumentStream >> documentUrl; |
| 20 if (!url.size() || !contentType.size() || !documentUrl.size()) |
19 { | 21 { |
20 ShowUsage(); | 22 ShowUsage(); |
21 return; | 23 return; |
22 } | 24 } |
23 | 25 |
24 if (filterEngine.Matches(url, contentType)) | 26 AdblockPlus::Filter* match = filterEngine.Matches(url, contentType, documentUr
l); |
25 std::cout << "Match" << std::endl; | 27 if (!match) |
| 28 std::cout << "No match" << std::endl; |
| 29 else if (match->GetProperty("type", "") == "exception") |
| 30 std::cout << "Whitelisted" << std::endl; |
26 else | 31 else |
27 std::cout << "No match" << std::endl; | 32 std::cout << "Blocked" << std::endl; |
28 } | 33 } |
29 | 34 |
30 std::string MatchesCommand::GetDescription() const | 35 std::string MatchesCommand::GetDescription() const |
31 { | 36 { |
32 return "Returns the first filter that matches the supplied URL"; | 37 return "Returns the first filter that matches the supplied URL"; |
33 } | 38 } |
34 | 39 |
35 std::string MatchesCommand::GetUsage() const | 40 std::string MatchesCommand::GetUsage() const |
36 { | 41 { |
37 return name + " URL CONTENT_TYPE"; | 42 return name + " URL CONTENT_TYPE DOCUMENT_URL"; |
38 } | 43 } |
OLD | NEW |