Esempio n. 1
0
 Request(FCGX_Request &request) : //request(request),
     _type(RequestType::Unknown),
     isbuf(request.in), osbuf(request.out), esbuf(request.err),
     fcin(&isbuf), fcout(&osbuf), fcerr(&esbuf), _postset(false)
 {
     // Parse environment variables
     char **e = request.envp;
     while (*(++e))
     {
         char *eq = strchr(*e, '=');
         if (eq == NULL) throw std::logic_error(
             std::string("Malformed environment variable: ")+*e);
         _env[std::string(*e, eq-(*e))] = std::string(eq+1);
     }
     // Parse cookies
     std::stringstream cookiestream(env("HTTP_COOKIE"));
     parse_pairs(cookiestream, ';', _cookies);
     // Determine request type
     std::string method = env("REQUEST_METHOD");
     if (method == "GET")
         _type = RequestType::Get;
     if (method == "POST")
         _type = RequestType::Post;
     // Parse get arguments
     std::stringstream querystream(env("QUERY_STRING"));
     parse_pairs(querystream, '&', _get);
     auto it = _get.find("q");
     if (it != _get.end()) _query = it->second;
 }
Esempio n. 2
0
    void edituser_page(Database &database, Request &request,
            std::ostream &fcout, std::istream &fcin)
    {
        if (request.type() == RequestType::Post)
        {
            std::map<std::string, std::string> data;
            parse_pairs(fcin, '&', data);
            auto pass = data.find("pass");
            auto pass_again = data.find("again");
            std::string userid_str = request.post("userid");
            uint64_t userid;
            if (userid_str.empty() || !parse_unsigned(userid_str, userid))
                throw std::logic_error("Invalid or missing userid!");

            if (pass != data.end())
            {
                if (pass_again == data.end() || pass_again->second == pass->second)
                {
                    User user = User::find(database, userid);
                    if (!user.valid())
                    {
                        LOG_MESSAGE_DEBUG("No such user");
                        throw std::logic_error("No such user!");
                    }
                    //user.name(name->second);
                    user.reset_password(pass->second);
                    user.save();
                    fcout << "Location: ?q=user\r\n";
                    fcout << "\r\n\r\n";
                } else
                {
                    LOG_MESSAGE_DEBUG("Password different");
                    throw std::logic_error("Password different");
                }
            } else
            {
                LOG_MESSAGE_DEBUG("Missing password");
                throw std::logic_error("Missing password");
            }
        } else
        {
            fcout << "<form name=\"edituser_form\" method=\"post\">";
            fcout << "<input type=\"hidden\" name=\"userid\" value=\"" << request.get("userid") << "\">";
            //fcout << "Username: <input name=\"name\">";
            fcout << "Password: <input name=\"pass\">";
            fcout << "Password again: <input name=\"pass_again\">";
            fcout << "<input type=\"submit\" value=\"Edit\">";
            fcout << "</form>";
        }
    }
Esempio n. 3
0
 void need_post()
 {
     if (_postset) return;
     _postset = true;
     if (env("CONTENT_TYPE") == "application/x-www-form-urlencoded")
     {
         if (_type == RequestType::Post)
         {
             try {
                 parse_pairs(fcin, '&', _post);
             } catch (...)
             {
                 // TODO
             }
         }
     }
 }
Esempio n. 4
0
static int
parse_sections (int ctr, RcFile * data, FILE * conf_file, char *temp,
                int buf_size)
{
  int result;
  char *start;
  data->sections = utlCalloc (sizeof (Section), ctr);
  if (NULL == data->sections)
    return 1;

  data->section_count = ctr;
  result = skip_to_first_section (conf_file, temp, &start, buf_size);
  ctr = 0;
  while (result != -1)
  {
    int kctr;
    Section *sec = &(data->sections[ctr]);
    kctr = 0;

    sec->name = strdup (start);
    if (!sec->name)
    {
      errMsg ("strdup: %s", strerror (errno));
      return 1;
    }
    kctr = count_pairs (conf_file, temp, &start, buf_size);
    if (kctr < 0)
      return 1;

    sec->pairs = utlCalloc (sizeof (KvPair), kctr);
    if ((!sec->pairs) && (kctr != 0))
    {
      errMsg ("calloc");
      return 1;
    }
    sec->kv_count = kctr;
    result = parse_pairs (sec, conf_file, temp, &start, buf_size);
    if (result == 20)
      return 1;
    ctr++;
  }
  return 0;
}
Esempio n. 5
0
 void newuser_page(Database &database, Request &request,
         std::ostream &fcout, std::istream &fcin)
 {
     if (request.type() == RequestType::Post)
     {
         std::map<std::string, std::string> data;
         parse_pairs(fcin, '&', data);
         auto name = data.find("name");
         auto pass = data.find("pass");
         auto pass_again = data.find("again");
         if (name != data.end() && pass != data.end())
         {
             if (pass_again == data.end() || pass_again->second == pass->second)
             {
                 User user(database, name->second, pass->second);
                 user.save();
                 fcout << "Location: ?q=main\r\n";
                 fcout << "\r\n\r\n";
             } else
             {
                 throw std::logic_error("Password different");
             }
         } else
         {
             throw std::logic_error("Missing username of password");
         }
     } else
     {
         fcout << "<form name=\"newuser_form\" method=\"post\">";
         fcout << "Username: <input name=\"name\">";
         fcout << "Password: <input name=\"pass\">";
         fcout << "Password again: <input name=\"pass_again\">";
         fcout << "<input type=\"submit\" value=\"Create\">";
         fcout << "</form>";
     }
 }
Esempio n. 6
0
bool MemcachedSessionManager::load_session(std::string const &sessionid, Session &session)
{
    memcached_return_t rc;
    size_t value_length;
    char *value = memcached_get(memcached_conn,
            sessionid.data(), sessionid.length(),
            &value_length, 0, &rc);
    if (memcached_success(rc))
    {
        std::stringstream valuestream(std::string(value, value_length));
        parse_pairs(valuestream, '\n', session.data());
        uint64_t userid = 0;
        try {
            userid = std::stoi(session.get("userid"));
        } catch (std::exception const &ex)
        {
            LOG_MESSAGE_WARN("Invalid userid in session data");
            return false;
        }
        session.set(User::find(database(), userid), sessionid);
    }
    if (value != NULL) free(value);
    return memcached_success(rc);
}
Esempio n. 7
0
static int
parse_vxlan(struct vxlan_peer *peer, char *param)
{
	return parse_pairs(peer, param, parse_vxlan_pair);
}
Esempio n. 8
0
static int
parse_port(struct net *net, char *param)
{
	return parse_pairs(net, param, parse_port_pair);
}