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

Side by Side Diff: src/engine/main.cpp

Issue 10874009: Use a proper enum type for procedures that can be called (Closed)
Patch Set: Created June 3, 2013, 1:53 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/plugin/AdblockPlusClient.cpp » ('j') | src/shared/Communication.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "Debug.h" 5 #include "Debug.h"
6 #include "Utils.h" 6 #include "Utils.h"
7 7
8 namespace 8 namespace
9 { 9 {
10 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine; 10 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 << subscription->GetProperty("title")->AsString() 45 << subscription->GetProperty("title")->AsString()
46 << subscription->GetProperty("specialization")->AsString() 46 << subscription->GetProperty("specialization")->AsString()
47 << subscription->IsListed(); 47 << subscription->IsListed();
48 } 48 }
49 } 49 }
50 50
51 Communication::OutputBuffer HandleRequest(Communication::InputBuffer& request) 51 Communication::OutputBuffer HandleRequest(Communication::InputBuffer& request)
52 { 52 {
53 Communication::OutputBuffer response; 53 Communication::OutputBuffer response;
54 54
55 std::string procedureName; 55 Communication::ProcType procedure;
56 request >> procedureName; 56 request >> procedure;
57 if (procedureName == "Matches") 57 switch (procedure)
58 { 58 {
59 std::string url; 59 case Communication::PROC_MATCHES:
60 std::string type; 60 {
61 std::string documentUrl; 61 std::string url;
62 request >> url >> type >> documentUrl; 62 std::string type;
63 response << filterEngine->Matches(url, type, documentUrl); 63 std::string documentUrl;
64 } 64 request >> url >> type >> documentUrl;
65 else if (procedureName == "GetElementHidingSelectors") 65 response << filterEngine->Matches(url, type, documentUrl);
66 { 66 break;
67 std::string domain; 67 }
68 request >> domain; 68 case Communication::PROC_GET_ELEMHIDE_SELECTORS:
69 WriteStrings(response, filterEngine->GetElementHidingSelectors(domain)); 69 {
70 } 70 std::string domain;
71 else if (procedureName == "FetchAvailableSubscriptions") 71 request >> domain;
72 { 72 WriteStrings(response, filterEngine->GetElementHidingSelectors(domain));
73 WriteSubscriptions(response, filterEngine->FetchAvailableSubscriptions()); 73 break;
74 } 74 }
75 else if (procedureName == "GetListedSubscriptions") 75 case Communication::PROC_AVAILABLE_SUBSCRIPTIONS:
76 { 76 {
77 WriteSubscriptions(response, filterEngine->GetListedSubscriptions()); 77 WriteSubscriptions(response, filterEngine->FetchAvailableSubscriptions() );
78 } 78 break;
79 else if (procedureName == "SetSubscription") 79 }
80 { 80 case Communication::PROC_LISTED_SUBSCRIPTIONS:
81 std::string url; 81 {
82 request >> url; 82 WriteSubscriptions(response, filterEngine->GetListedSubscriptions());
83 break;
84 }
85 case Communication::PROC_SET_SUBSCRIPTION:
86 {
87 std::string url;
88 request >> url;
83 89
84 std::vector<AdblockPlus::SubscriptionPtr> subscriptions = filterEngine->Ge tListedSubscriptions(); 90 std::vector<AdblockPlus::SubscriptionPtr> subscriptions = filterEngine-> GetListedSubscriptions();
85 for (size_t i = 0, count = subscriptions.size(); i < count; i++) 91 for (size_t i = 0, count = subscriptions.size(); i < count; i++)
86 subscriptions[i]->RemoveFromList(); 92 subscriptions[i]->RemoveFromList();
87 93
88 filterEngine->GetSubscription(url)->AddToList(); 94 filterEngine->GetSubscription(url)->AddToList();
89 } 95 break;
90 else if (procedureName == "UpdateAllSubscriptions") 96 }
91 { 97 case Communication::PROC_UPDATE_ALL_SUBSCRIPTIONS:
92 std::vector<AdblockPlus::SubscriptionPtr> subscriptions = filterEngine->Ge tListedSubscriptions();
93 for (size_t i = 0, count = subscriptions.size(); i < count; i++)
94 subscriptions[i]->UpdateFilters();
95 }
96 else if (procedureName == "GetExceptionDomains")
97 {
98 std::vector<AdblockPlus::FilterPtr> filters = filterEngine->GetListedFilte rs();
99 std::vector<std::string> domains;
100 for (size_t i = 0, count = filters.size(); i < count; i++)
101 { 98 {
102 AdblockPlus::FilterPtr filter = filters[i]; 99 std::vector<AdblockPlus::SubscriptionPtr> subscriptions = filterEngine-> GetListedSubscriptions();
103 if (filter->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION) 100 for (size_t i = 0, count = subscriptions.size(); i < count; i++)
101 subscriptions[i]->UpdateFilters();
102 break;
103 }
104 case Communication::PROC_GET_EXCEPTION_DOMAINS:
105 {
106 std::vector<AdblockPlus::FilterPtr> filters = filterEngine->GetListedFil ters();
107 std::vector<std::string> domains;
108 for (size_t i = 0, count = filters.size(); i < count; i++)
104 { 109 {
105 std::string text = filter->GetProperty("text")->AsString(); 110 AdblockPlus::FilterPtr filter = filters[i];
111 if (filter->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION)
112 {
113 std::string text = filter->GetProperty("text")->AsString();
106 114
107 //@@||example.com^$document 115 //@@||example.com^$document
108 const char prefix[] = "@@||"; 116 const char prefix[] = "@@||";
109 const char suffix[] = "^$document"; 117 const char suffix[] = "^$document";
110 const int prefixLen = strlen(prefix); 118 const int prefixLen = strlen(prefix);
111 const int suffixLen = strlen(suffix); 119 const int suffixLen = strlen(suffix);
112 if (!text.compare(0, prefixLen, prefix) && 120 if (!text.compare(0, prefixLen, prefix) &&
113 !text.compare(text.size() - suffixLen, suffixLen, suffix)) 121 !text.compare(text.size() - suffixLen, suffixLen, suffix))
114 { 122 {
115 domains.push_back(text.substr(prefixLen, text.size() - prefixLen - s uffixLen)); 123 domains.push_back(text.substr(prefixLen, text.size() - prefixLen - suffixLen));
124 }
116 } 125 }
117 } 126 }
127
128 WriteStrings(response, domains);
129 break;
118 } 130 }
131 case Communication::PROC_ADD_FILTER:
132 {
133 std::string text;
134 request >> text;
119 135
120 WriteStrings(response, domains); 136 filterEngine->GetFilter(text)->AddToList();
121 } 137 break;
122 else if (procedureName == "AddFilter") 138 }
123 {
124 std::string text;
125 request >> text;
126
127 filterEngine->GetFilter(text)->AddToList();
128 } 139 }
129 return response; 140 return response;
130 } 141 }
131 142
132 DWORD WINAPI ClientThread(LPVOID param) 143 DWORD WINAPI ClientThread(LPVOID param)
133 { 144 {
134 std::auto_ptr<Communication::Pipe> pipe(static_cast<Communication::Pipe*>(pa ram)); 145 std::auto_ptr<Communication::Pipe> pipe(static_cast<Communication::Pipe*>(pa ram));
135 146
136 try 147 try
137 { 148 {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 } 200 }
190 catch (std::runtime_error e) 201 catch (std::runtime_error e)
191 { 202 {
192 DebugException(e); 203 DebugException(e);
193 return 1; 204 return 1;
194 } 205 }
195 } 206 }
196 207
197 return 0; 208 return 0;
198 } 209 }
OLDNEW
« no previous file with comments | « no previous file | src/plugin/AdblockPlusClient.cpp » ('j') | src/shared/Communication.h » ('J')

Powered by Google App Engine
This is Rietveld