> On Wed, Jan 12, 2011 at 12:26 AM, David Hite <[email protected]>
> wrote:
> > Hello,
> > I am trying to parse the incoming query in a request to the
> synchronous
> > server. I see that there is a "query" method on the HTTP Normal
> Client
> > Request but not the Pod Server Request. I can't find any example of
> the
> > server request query parameters.
> >
> > Is there a simple way to pull out the "?" query portion of the uri?
> >
> > I am able to get the destination(request) method to work and could
do
> some
> > string parsing but I figured there is a better way...
> >
We use something like this in a header
********************************************
#include "boost/spirit/include/qi.hpp"
#include <string>
#include <utility>
template <typename Iterator, typename map_type>
struct key_value_sequence : boost::spirit::qi::grammar<Iterator,
map_type()>
{
key_value_sequence() : key_value_sequence::base_type(query)
{
query = pair >> *((boost::spirit::qi::lit(';') | '&') >> pair);
pair = key >> -('=' >> value);
key = boost::spirit::qi::char_("a-zA-Z_0-9%+") >>
*boost::spirit::qi::char_("a-zA-Z_0-9%+");
value = +boost::spirit::qi::char_("a-zA-Z_0-9%+");
}
boost::spirit::qi::rule<Iterator, map_type()> query;
boost::spirit::qi::rule<Iterator, std::pair<std::string,
std::string>()> pair;
boost::spirit::qi::rule<Iterator, std::string()> key, value;
};
template<typename map_type>
inline map_type& parse_http_query(const std::string& uri, map_type&
output)
{
std::string new_uri(uri); // this should go away when qi can parse
const iterators
key_value_sequence<std::string::iterator, map_type> p;
const size_t query_pos = new_uri.find('?');
std::string::iterator begin = std::string::npos == query_pos ?
new_uri.end() : new_uri.begin() + query_pos + 1;
std::string::iterator end = new_uri.end();
if (!boost::spirit::qi::parse(begin, end, p, output))
{
// throw an error here if non-parsing is considered erroneous
}
return output;
}
**********************************************
Used like this
**********************************************************
string object;
const size_t query_pos = request.uri.find('?');
if(not request.uri.empty()) // if we have a uri
{
object.assign(*request.uri.begin() == '/' ? ++request.uri.begin() :
request.uri.begin(), std::string::npos == query_pos ? request.uri.end()
: request.uri.begin() + query_pos);
}
std::map<std::string, std::string> args;
parse_http_query(request.uri, args);
**************************************************
I think it's mostly derived from some Spirit examples somebody found
somewhere.
Erik
----------------------------------------------------------------------
This message w/attachments (message) is intended solely for the use of the
intended recipient(s) and may contain information that is privileged,
confidential or proprietary. If you are not an intended recipient, please
notify the sender, and then please delete and destroy all copies and
attachments, and be advised that any review or dissemination of, or the taking
of any action in reliance on, the information contained in or attached to this
message is prohibited.
Unless specifically indicated, this message is not an offer to sell or a
solicitation of any investment products or other financial product or service,
an official confirmation of any transaction, or an official statement of
Sender. Subject to applicable law, Sender may intercept, monitor, review and
retain e-communications (EC) traveling through its networks/systems and may
produce any such EC to regulators, law enforcement, in litigation and as
required by law.
The laws of the country of each sender/recipient may impact the handling of EC,
and EC may be archived, supervised and produced in countries other than the
country in which you are located. This message cannot be guaranteed to be
secure or free of errors or viruses.
References to "Sender" are references to any subsidiary of Bank of America
Corporation. Securities and Insurance Products: * Are Not FDIC Insured * Are
Not Bank Guaranteed * May Lose Value * Are Not a Bank Deposit * Are Not a
Condition to Any Banking Service or Activity * Are Not Insured by Any Federal
Government Agency. Attachments that are part of this EC may have additional
important disclosures and disclaimers, which you should read. This message is
subject to terms available at the following link:
http://www.bankofamerica.com/emaildisclaimer. By messaging with Sender you
consent to the foregoing.
------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand
malware threats, the impact they can have on your business, and how you
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Cpp-netlib-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/cpp-netlib-devel