Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: src/shared/Communication.h

Issue 4882650246414336: Issue 2005 - Refactor working with strings in InputBuffer and OutputBuffer
Left Patch Set: fix forgotten sizeof and add check for string length Created Feb. 18, 2015, 2:37 p.m.
Right Patch Set: rebase Created April 2, 2015, 11:09 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH
4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */
17
1 #ifndef COMMUNICATION_H 18 #ifndef COMMUNICATION_H
2 #define COMMUNICATION_H 19 #define COMMUNICATION_H
3 20
4 #include <memory> 21 #include <memory>
5 #include <sstream> 22 #include <sstream>
6 #include <stdexcept> 23 #include <stdexcept>
7 #include <stdint.h> 24 #include <stdint.h>
8 #include <string> 25 #include <string>
9 #include <vector> 26 #include <vector>
10 #include <Windows.h> 27 #include <Windows.h>
11 #include "Utils.h" 28 #include "Utils.h"
12 29
13 namespace Communication 30 namespace Communication
14 { 31 {
15 extern const std::wstring pipeName; 32 extern const std::wstring pipeName;
16 extern std::wstring browserSID; 33 extern std::wstring browserSID;
17 34
18 enum ProcType : uint32_t { 35 enum ProcType : uint32_t {
19 PROC_MATCHES, 36 PROC_MATCHES,
20 PROC_GET_ELEMHIDE_SELECTORS, 37 PROC_GET_ELEMHIDE_SELECTORS,
21 PROC_AVAILABLE_SUBSCRIPTIONS, 38 PROC_AVAILABLE_SUBSCRIPTIONS,
22 PROC_LISTED_SUBSCRIPTIONS, 39 PROC_LISTED_SUBSCRIPTIONS,
23 PROC_SET_SUBSCRIPTION, 40 PROC_SET_SUBSCRIPTION,
24 PROC_ADD_SUBSCRIPTION, 41 PROC_ADD_SUBSCRIPTION,
25 PROC_REMOVE_SUBSCRIPTION, 42 PROC_REMOVE_SUBSCRIPTION,
26 PROC_UPDATE_ALL_SUBSCRIPTIONS, 43 PROC_UPDATE_ALL_SUBSCRIPTIONS,
27 PROC_GET_EXCEPTION_DOMAINS, 44 PROC_GET_EXCEPTION_DOMAINS,
28 PROC_IS_WHITELISTED_URL, 45 PROC_GET_WHITELISTING_FITER,
29 PROC_IS_ELEMHIDE_WHITELISTED_ON_URL, 46 PROC_IS_ELEMHIDE_WHITELISTED_ON_URL,
30 PROC_ADD_FILTER, 47 PROC_ADD_FILTER,
31 PROC_REMOVE_FILTER, 48 PROC_REMOVE_FILTER,
32 PROC_SET_PREF, 49 PROC_SET_PREF,
33 PROC_GET_PREF, 50 PROC_GET_PREF,
34 PROC_IS_FIRST_RUN_ACTION_NEEDED, 51 PROC_IS_FIRST_RUN_ACTION_NEEDED,
35 PROC_CHECK_FOR_UPDATES, 52 PROC_CHECK_FOR_UPDATES,
36 PROC_GET_DOCUMENTATION_LINK, 53 PROC_GET_DOCUMENTATION_LINK,
37 PROC_TOGGLE_PLUGIN_ENABLED, 54 PROC_TOGGLE_PLUGIN_ENABLED,
38 PROC_GET_HOST, 55 PROC_GET_HOST,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 InputBuffer& ReadString(std::string& value) 109 InputBuffer& ReadString(std::string& value)
93 { 110 {
94 CheckType(TYPE_STRING); 111 CheckType(TYPE_STRING);
95 112
96 SizeType length; 113 SizeType length;
97 ReadBinary(length); 114 ReadBinary(length);
98 value.resize(length); 115 value.resize(length);
99 if (length > 0) 116 if (length > 0)
100 { 117 {
101 buffer.read(&value[0], length); 118 buffer.read(&value[0], length);
119 if (buffer.fail())
120 throw new std::runtime_error("Unexpected end of input buffer");
102 } 121 }
103 if (buffer.fail())
104 throw new std::runtime_error("Unexpected end of input buffer");
Eric 2015/02/18 18:12:47 This test for failure should be guarded by the con
sergei 2015/02/19 17:26:57 moved
105 return *this; 122 return *this;
106 } 123 }
107 124
108 InputBuffer& ReadStrings(std::vector<std::string>& value) 125 InputBuffer& ReadStrings(std::vector<std::string>& value)
109 { 126 {
110 value.clear(); 127 value.clear();
111 CheckType(ValueType::TYPE_STRINGS); 128 CheckType(ValueType::TYPE_STRINGS);
112 129
113 SizeType length; 130 SizeType length;
114 ReadBinary(length); 131 ReadBinary(length);
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 252
236 InputBuffer ReadMessage(); 253 InputBuffer ReadMessage();
237 void WriteMessage(OutputBuffer& message); 254 void WriteMessage(OutputBuffer& message);
238 255
239 protected: 256 protected:
240 HANDLE pipe; 257 HANDLE pipe;
241 }; 258 };
242 } 259 }
243 260
244 #endif 261 #endif
LEFTRIGHT

Powered by Google App Engine
This is Rietveld