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

Side by Side Diff: src/DefaultWebRequestWinInet.cpp

Issue 10459038: Clean up and fix Utils::ToUTF8String() and Utils::ToUTF16String() (Closed)
Patch Set: Created May 14, 2013, 1:54 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 | « src/DefaultFileSystem.cpp ('k') | src/Utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2013 Eyeo GmbH 3 * Copyright (C) 2006-2013 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 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 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 nextHeaderNameStart++; 150 nextHeaderNameStart++;
151 prevHeaderStart = nextHeaderNameStart; 151 prevHeaderStart = nextHeaderNameStart;
152 continue; 152 continue;
153 } 153 }
154 std::wstring headerNameW = responseHeaders.substr(prevHeaderStart, headerN ameEnd - prevHeaderStart); 154 std::wstring headerNameW = responseHeaders.substr(prevHeaderStart, headerN ameEnd - prevHeaderStart);
155 std::wstring headerValueW = responseHeaders.substr(headerValueStart, nextH eaderNameStart - headerValueStart); 155 std::wstring headerValueW = responseHeaders.substr(headerValueStart, nextH eaderNameStart - headerValueStart);
156 156
157 headerNameW = AdblockPlus::Utils::TrimString(headerNameW); 157 headerNameW = AdblockPlus::Utils::TrimString(headerNameW);
158 headerValueW = AdblockPlus::Utils::TrimString(headerValueW); 158 headerValueW = AdblockPlus::Utils::TrimString(headerValueW);
159 159
160 std::string headerName = AdblockPlus::Utils::ToUTF8String(headerNameW.c_st r(), headerNameW.length()); 160 std::string headerName = AdblockPlus::Utils::ToUTF8String(headerNameW.c_st r());
161 std::string headerValue = AdblockPlus::Utils::ToUTF8String(headerValueW.c_ str(), headerValueW.length()); 161 std::string headerValue = AdblockPlus::Utils::ToUTF8String(headerValueW.c_ str());
162 162
163 std::transform(headerName.begin(), headerName.end(), headerName.begin(), : :tolower); 163 std::transform(headerName.begin(), headerName.end(), headerName.begin(), : :tolower);
164 std::transform(headerValue.begin(), headerValue.end(), headerValue.begin() , ::tolower); 164 std::transform(headerValue.begin(), headerValue.end(), headerValue.begin() , ::tolower);
165 165
166 result->responseHeaders.push_back( 166 result->responseHeaders.push_back(
167 std::pair<std::string, std::string>(headerName, headerValue)); 167 std::pair<std::string, std::string>(headerName, headerValue));
168 168
169 nextHeaderNameStart++; 169 nextHeaderNameStart++;
170 prevHeaderStart = nextHeaderNameStart; 170 prevHeaderStart = nextHeaderNameStart;
171 } 171 }
(...skipping 17 matching lines...) Expand all
189 AdblockPlus::ServerResponse AdblockPlus::DefaultWebRequest::GET( 189 AdblockPlus::ServerResponse AdblockPlus::DefaultWebRequest::GET(
190 const std::string& url, const HeaderList& requestHeaders) const 190 const std::string& url, const HeaderList& requestHeaders) const
191 { 191 {
192 AdblockPlus::ServerResponse result; 192 AdblockPlus::ServerResponse result;
193 result.status = NS_ERROR_FAILURE; 193 result.status = NS_ERROR_FAILURE;
194 result.responseStatus = 0; 194 result.responseStatus = 0;
195 195
196 HRESULT hr; 196 HRESULT hr;
197 BOOL res; 197 BOOL res;
198 198
199 std::wstring canonizedUrl = Utils::CanonizeUrl(Utils::ToUTF16String(url, url.l ength())); 199 std::wstring canonizedUrl = Utils::CanonizeUrl(Utils::ToUTF16String(url));
200 200
201 std::string headersString = ""; 201 std::string headersString = "";
202 for (int i = 0; i < requestHeaders.size(); i++) 202 for (int i = 0; i < requestHeaders.size(); i++)
203 { 203 {
204 headersString += requestHeaders[i].first + ": "; 204 headersString += requestHeaders[i].first + ": ";
205 headersString += requestHeaders[i].second + ";"; 205 headersString += requestHeaders[i].second + ";";
206 } 206 }
207 std::wstring headers = Utils::ToUTF16String(headersString, headersString.lengt h()); 207 std::wstring headers = Utils::ToUTF16String(headersString);
208 208
209 LPSTR outBuffer; 209 LPSTR outBuffer;
210 DWORD downloadSize, downloaded; 210 DWORD downloadSize, downloaded;
211 WinHttpHandle hSession(0), hConnect(0), hRequest(0); 211 WinHttpHandle hSession(0), hConnect(0), hRequest(0);
212 212
213 // Use WinHttpOpen to obtain a session handle. 213 // Use WinHttpOpen to obtain a session handle.
214 std::wstring proxyName, proxyBypass; 214 std::wstring proxyName, proxyBypass;
215 215
216 GetProxySettings(proxyName, proxyBypass); 216 GetProxySettings(proxyName, proxyBypass);
217 if (proxyName.empty()) 217 if (proxyName.empty())
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 if( WinHttpReadData(hRequest, (LPVOID)outBuffer, downloadSize, &downloaded )) 329 if( WinHttpReadData(hRequest, (LPVOID)outBuffer, downloadSize, &downloaded ))
330 { 330 {
331 result.responseText.append(outBuffer, downloaded); 331 result.responseText.append(outBuffer, downloaded);
332 } 332 }
333 // Free the memory allocated to the buffer. 333 // Free the memory allocated to the buffer.
334 delete[] outBuffer; 334 delete[] outBuffer;
335 } 335 }
336 } while (downloadSize > 0); 336 } while (downloadSize > 0);
337 return result; 337 return result;
338 } 338 }
OLDNEW
« no previous file with comments | « src/DefaultFileSystem.cpp ('k') | src/Utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld