2008-08-08 00:01:22 +00:00
|
|
|
#include "request.h"
|
|
|
|
|
2008-08-08 03:23:34 +00:00
|
|
|
namespace afp {
|
|
|
|
|
2008-08-08 00:01:22 +00:00
|
|
|
// Protocol:
|
|
|
|
// code NULL <key> NULL <value> NULL ... <value> NULL NULL
|
|
|
|
|
|
|
|
bool
|
|
|
|
request::load(std::istream &inp) {
|
2008-08-08 03:23:34 +00:00
|
|
|
inp.unsetf(std::ios_base::skipws);
|
2008-08-08 00:01:22 +00:00
|
|
|
|
|
|
|
std::istream_iterator<char> it(inp), p, end;
|
|
|
|
|
|
|
|
std::pair<std::istream_iterator<char>, std::istream_iterator<char> >
|
|
|
|
iters;
|
|
|
|
|
|
|
|
filter.erase();
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
if (*it == '\0')
|
|
|
|
break;
|
|
|
|
filter.push_back(*it);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (it == end)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
it++;
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
std::string key, value;
|
|
|
|
|
|
|
|
/* read the key */
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
if (*it == '\0')
|
|
|
|
break;
|
|
|
|
key.push_back(*it);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (it == end)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (key.empty())
|
|
|
|
/* empty string means end of input */
|
|
|
|
return true;
|
|
|
|
|
|
|
|
it++;
|
|
|
|
|
|
|
|
/* read the value */
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
if (*it == '\0')
|
|
|
|
break;
|
|
|
|
value.push_back(*it);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (it == end)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
it++;
|
|
|
|
|
2008-08-08 03:23:34 +00:00
|
|
|
f.add_variable(key, datum(value));
|
2008-08-08 00:01:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
request::evaluate()
|
|
|
|
{
|
|
|
|
return f.evaluate(filter);
|
|
|
|
}
|
|
|
|
|
2008-08-08 03:23:34 +00:00
|
|
|
} // namespace afp
|