OLD | NEW |
1 #include "stdafx.h" | 1 #include "stdafx.h" |
2 | 2 |
3 #include "../shared/AutoHandle.h" | 3 #include "../shared/AutoHandle.h" |
4 #include "../shared/Communication.h" | 4 #include "../shared/Communication.h" |
5 | 5 |
6 namespace | 6 namespace |
7 { | 7 { |
8 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine; | 8 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine; |
9 | 9 |
10 void Log(const std::string& message) | 10 void Log(const std::string& message) |
(...skipping 22 matching lines...) Expand all Loading... |
33 | 33 |
34 DWORD utf8StringLength = WideCharToMultiByte(CP_UTF8, 0, str.c_str(), length
, 0, 0, 0, 0); | 34 DWORD utf8StringLength = WideCharToMultiByte(CP_UTF8, 0, str.c_str(), length
, 0, 0, 0, 0); |
35 if (utf8StringLength == 0) | 35 if (utf8StringLength == 0) |
36 throw std::runtime_error("Failed to determine the required buffer size"); | 36 throw std::runtime_error("Failed to determine the required buffer size"); |
37 | 37 |
38 std::string utf8String(utf8StringLength, '\0'); | 38 std::string utf8String(utf8StringLength, '\0'); |
39 WideCharToMultiByte(CP_UTF8, 0, str.c_str(), length, &utf8String[0], utf8Str
ingLength, 0, 0); | 39 WideCharToMultiByte(CP_UTF8, 0, str.c_str(), length, &utf8String[0], utf8Str
ingLength, 0, 0); |
40 return utf8String; | 40 return utf8String; |
41 } | 41 } |
42 | 42 |
43 std::string HandleRequest(const std::vector<std::string>& strings) | 43 Communication::OutputBuffer HandleRequest(Communication::InputBuffer& request) |
44 { | 44 { |
45 std::string procedureName = strings[0]; | 45 Communication::OutputBuffer response; |
| 46 |
| 47 std::string procedureName; |
| 48 request >> procedureName; |
46 if (procedureName == "Matches") | 49 if (procedureName == "Matches") |
47 return filterEngine->Matches(strings[1], strings[2], strings[3]) ? "1" : "
0"; | 50 { |
| 51 std::string url; |
| 52 std::string type; |
| 53 std::string documentUrl; |
| 54 request >> url >> type >> documentUrl; |
| 55 response << filterEngine->Matches(url, type, documentUrl); |
| 56 } |
48 if (procedureName == "GetElementHidingSelectors") | 57 if (procedureName == "GetElementHidingSelectors") |
49 return Communication::MarshalStrings(filterEngine->GetElementHidingSelecto
rs(strings[1])); | 58 { |
50 return ""; | 59 std::string domain; |
| 60 request >> domain; |
| 61 |
| 62 std::vector<std::string> selectors = filterEngine->GetElementHidingSelecto
rs(domain); |
| 63 |
| 64 int32_t length = selectors.size(); |
| 65 response << length; |
| 66 for (int32_t i = 0; i < length; i++) |
| 67 response << selectors[i]; |
| 68 } |
| 69 return response; |
51 } | 70 } |
52 | 71 |
53 DWORD WINAPI ClientThread(LPVOID param) | 72 DWORD WINAPI ClientThread(LPVOID param) |
54 { | 73 { |
55 HANDLE pipe = static_cast<HANDLE>(param); | 74 HANDLE pipe = static_cast<HANDLE>(param); |
56 | 75 |
57 try | 76 try |
58 { | 77 { |
59 std::string message = Communication::ReadMessage(pipe); | 78 Communication::InputBuffer message = Communication::ReadMessage(pipe); |
60 std::vector<std::string> strings = Communication::UnmarshalStrings(message
); | 79 Communication::OutputBuffer response = HandleRequest(message); |
61 std::string response = HandleRequest(strings); | |
62 Communication::WriteMessage(pipe, response); | 80 Communication::WriteMessage(pipe, response); |
63 } | 81 } |
64 catch (const std::exception& e) | 82 catch (const std::exception& e) |
65 { | 83 { |
66 LogException(e); | 84 LogException(e); |
67 } | 85 } |
68 | 86 |
69 // TODO: Keep the pipe open until the client disconnects | 87 // TODO: Keep the pipe open until the client disconnects |
70 FlushFileBuffers(pipe); | 88 FlushFileBuffers(pipe); |
71 DisconnectNamedPipe(pipe); | 89 DisconnectNamedPipe(pipe); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 AutoHandle thread(CreateThread(0, 0, ClientThread, static_cast<LPVOID>(pipe)
, 0, 0)); | 184 AutoHandle thread(CreateThread(0, 0, ClientThread, static_cast<LPVOID>(pipe)
, 0, 0)); |
167 if (!thread.get()) | 185 if (!thread.get()) |
168 { | 186 { |
169 LogLastError("CreateThread failed"); | 187 LogLastError("CreateThread failed"); |
170 return 1; | 188 return 1; |
171 } | 189 } |
172 } | 190 } |
173 | 191 |
174 return 0; | 192 return 0; |
175 } | 193 } |
OLD | NEW |