| 1 | // Copyright (c) 2006-2013, Andrey N. Sabelnikov, www.sabelnikov.net |
| 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 met: |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above copyright |
| 9 | // notice, this list of conditions and the following disclaimer in the |
| 10 | // documentation and/or other materials provided with the distribution. |
| 11 | // * Neither the name of the Andrey N. Sabelnikov nor the |
| 12 | // names of its contributors may be used to endorse or promote products |
| 13 | // derived from this software without specific prior written permission. |
| 14 | // |
| 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 16 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 17 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 18 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER BE LIABLE FOR ANY |
| 19 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 20 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 21 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 22 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 24 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 | // |
| 26 | |
| 27 | #include "net/http_base.h" |
| 28 | #include "memwipe.h" |
| 29 | #include "string_tools.h" |
| 30 | |
| 31 | #include <boost/regex.hpp> |
| 32 | #include <string> |
| 33 | #include <utility> |
| 34 | |
| 35 | #undef MONERO_DEFAULT_LOG_CATEGORY |
| 36 | #define MONERO_DEFAULT_LOG_CATEGORY "net.http" |
| 37 | |
| 38 | namespace epee |
| 39 | { |
| 40 | namespace net_utils |
| 41 | { |
| 42 | namespace http |
| 43 | { |
| 44 | std::string get_value_from_fields_list(const std::string& param_name, const net_utils::http::fields_list& fields) |
| 45 | { |
| 46 | fields_list::const_iterator it = fields.begin(); |
| 47 | for(; it != fields.end(); ++it) |
| 48 | if(!string_tools::compare_no_case(param_name, it->first)) |
| 49 | break; |
| 50 | |
| 51 | if(it==fields.end()) |
| 52 | return std::string(); |
| 53 | |
| 54 | return it->second; |
| 55 | } |
| 56 | |
| 57 | std::string get_value_from_uri_line(const std::string& param_name, const std::string& uri) |
| 58 | { |
| 59 | std::string buff = "([\\?|&])"; |
| 60 | buff += param_name + "=([^&]*)"; |
| 61 | boost::regex match_param(buff.c_str(), boost::regex::icase | boost::regex::normal); |
| 62 | boost::smatch result; |
| 63 | if(boost::regex_search(uri, result, match_param, boost::match_default) && result[0].matched) |
| 64 | { |
| 65 | return result[2]; |
| 66 | } |
| 67 | return std::string(); |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | } |