| 1 |
// Copyright (c) 2009, Whispersoft s.r.l. |
|---|
| 2 |
// All rights reserved. |
|---|
| 3 |
// |
|---|
| 4 |
// Redistribution and use in source and binary forms, with or without |
|---|
| 5 |
// modification, are permitted provided that the following conditions are |
|---|
| 6 |
// met: |
|---|
| 7 |
// |
|---|
| 8 |
// * Redistributions of source code must retain the above copyright |
|---|
| 9 |
// notice, this list of conditions and the following disclaimer. |
|---|
| 10 |
// * Redistributions in binary form must reproduce the above |
|---|
| 11 |
// copyright notice, this list of conditions and the following disclaimer |
|---|
| 12 |
// in the documentation and/or other materials provided with the |
|---|
| 13 |
// distribution. |
|---|
| 14 |
// * Neither the name of Whispersoft s.r.l. nor the names of its |
|---|
| 15 |
// contributors may be used to endorse or promote products derived from |
|---|
| 16 |
// this software without specific prior written permission. |
|---|
| 17 |
// |
|---|
| 18 |
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|---|
| 19 |
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|---|
| 20 |
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|---|
| 21 |
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|---|
| 22 |
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|---|
| 23 |
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|---|
| 24 |
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|---|
| 25 |
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|---|
| 26 |
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|---|
| 27 |
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|---|
| 28 |
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|---|
| 29 |
// |
|---|
| 30 |
|
|---|
| 31 |
#include "net/url/url.h" |
|---|
| 32 |
|
|---|
| 33 |
#include "common/base/types.h" |
|---|
| 34 |
#include "common/base/log.h" |
|---|
| 35 |
#include "common/base/system.h" |
|---|
| 36 |
|
|---|
| 37 |
void LogUrl(const char* surl) { |
|---|
| 38 |
URL url(surl); |
|---|
| 39 |
vector< pair<string, string> > qp; |
|---|
| 40 |
int num = url.GetQueryParameters(&qp, true); |
|---|
| 41 |
LOG_INFO << "\n===================================================" |
|---|
| 42 |
<< "\nSTRING: " << surl |
|---|
| 43 |
<< "\nURL: " << url.is_valid() |
|---|
| 44 |
<< "\n scheme: [" << url.scheme() << "]" |
|---|
| 45 |
<< "\n spec: [" << url.spec() << "]" |
|---|
| 46 |
<< "\n host: [" << url.host() << "]" |
|---|
| 47 |
<< "\n port: [" << url.port() << "] / [" |
|---|
| 48 |
<< url.IntPort() << "]" |
|---|
| 49 |
<< "\n path: [" << url.path() << "] / [" |
|---|
| 50 |
<< (url.path().size() > 0 |
|---|
| 51 |
? url.PathForRequest().c_str() : "--?--") << "]" |
|---|
| 52 |
<< "\n query: [" << url.query() << "]" |
|---|
| 53 |
<< "\n ref: [" << url.ref() << "]"; |
|---|
| 54 |
for ( int i = 0; i < num; i++ ) { |
|---|
| 55 |
LOG_INFO << " Param " << i << " [" << qp[i].first << "] = [" |
|---|
| 56 |
<< qp[i].second << "]"; |
|---|
| 57 |
} |
|---|
| 58 |
} |
|---|
| 59 |
|
|---|
| 60 |
int main(int argc, char* argv[]) { |
|---|
| 61 |
common::Init(argc, argv); |
|---|
| 62 |
LogUrl("http://www.google.com/"); |
|---|
| 63 |
LogUrl("http://www.google.com/gigi/marga?xyz=abc%5c&zuzu=aba+mucu"); |
|---|
| 64 |
LogUrl("http://www.google.com/gigi/marga?x yz=ab[c%5c&zuzu=aba mucu"); |
|---|
| 65 |
LogUrl("http://www.google.com/gigi/marga?lulu=~!@#$%^&*()_+"); |
|---|
| 66 |
LogUrl("http://www.google.com/gigi/marga?lulu=`1234567890-="); |
|---|
| 67 |
LogUrl("http://www.google.com/gigi/%7E%21%40%23%24%25%5E%26" |
|---|
| 68 |
"%2A%28%29%5F%2B?%601234567890%2D%3D=%5B%5D%5C%3B%27" |
|---|
| 69 |
"%2C%2E%2F&%7B%7D%7C%3A%22%3C%3E%3F="); |
|---|
| 70 |
LogUrl("@#$http://www.*&google.com/gigi/%7E%21%40%23%24%25%5E" |
|---|
| 71 |
"%26%2A%28%29%5F%2B?%601234567890%2D%3D=%5B%5D%5C%3B%27" |
|---|
| 72 |
"%2C%2E%2F&%7B%7D%7C%3A%22%3C%3E%3F="); |
|---|
| 73 |
LogUrl("http://www.google.com/gigi/marga?xyz=abc%A7%BC"); |
|---|
| 74 |
LogUrl("http://h/a/b/c/d?x=10&y=20"); |
|---|
| 75 |
|
|---|
| 76 |
LOG_INFO << URL::UrlEscape("abc$%-="); |
|---|
| 77 |
CHECK_EQ(URL::UrlUnescape(URL::UrlEscape("abc$%-=")), "abc$%-="); |
|---|
| 78 |
} |
|---|