Index: src/engine/main.cpp |
=================================================================== |
--- a/src/engine/main.cpp |
+++ b/src/engine/main.cpp |
@@ -35,35 +35,53 @@ namespace |
if (utf8StringLength == 0) |
throw std::runtime_error("Failed to determine the required buffer size"); |
std::string utf8String(utf8StringLength, '\0'); |
WideCharToMultiByte(CP_UTF8, 0, str.c_str(), length, &utf8String[0], utf8StringLength, 0, 0); |
return utf8String; |
} |
- std::string HandleRequest(const std::vector<std::string>& strings) |
+ Communication::OutputBuffer HandleRequest(Communication::InputBuffer& request) |
{ |
- std::string procedureName = strings[0]; |
+ Communication::OutputBuffer response; |
+ |
+ std::string procedureName; |
+ request >> procedureName; |
if (procedureName == "Matches") |
- return filterEngine->Matches(strings[1], strings[2], strings[3]) ? "1" : "0"; |
+ { |
+ std::string url; |
+ std::string type; |
+ std::string documentUrl; |
+ request >> url >> type >> documentUrl; |
+ response << filterEngine->Matches(url, type, documentUrl); |
+ } |
if (procedureName == "GetElementHidingSelectors") |
- return Communication::MarshalStrings(filterEngine->GetElementHidingSelectors(strings[1])); |
- return ""; |
+ { |
+ std::string domain; |
+ request >> domain; |
+ |
+ std::vector<std::string> selectors = filterEngine->GetElementHidingSelectors(domain); |
+ |
+ int32_t length = selectors.size(); |
+ response << length; |
+ for (int32_t i = 0; i < length; i++) |
+ response << selectors[i]; |
+ } |
+ return response; |
} |
DWORD WINAPI ClientThread(LPVOID param) |
{ |
HANDLE pipe = static_cast<HANDLE>(param); |
try |
{ |
- std::string message = Communication::ReadMessage(pipe); |
- std::vector<std::string> strings = Communication::UnmarshalStrings(message); |
- std::string response = HandleRequest(strings); |
+ Communication::InputBuffer message = Communication::ReadMessage(pipe); |
+ Communication::OutputBuffer response = HandleRequest(message); |
Communication::WriteMessage(pipe, response); |
} |
catch (const std::exception& e) |
{ |
LogException(e); |
} |
// TODO: Keep the pipe open until the client disconnects |