BBS2chProxyFormData.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #pragma once
  2. #include <vector>
  3. #include <string>
  4. #include <map>
  5. std::string decodeURIComponent(const char *input, size_t inputLength, bool decodePlus);
  6. std::string encodeURIComponent(const char *input, size_t inputLength, bool spaceAsPlus);
  7. class BBS2chProxyURLEncodedValue {
  8. private:
  9. std::string _value;
  10. std::string _encodedValue;
  11. bool _hasValue;
  12. bool _hasEncodedValue;
  13. public:
  14. BBS2chProxyURLEncodedValue();
  15. BBS2chProxyURLEncodedValue(const std::string &value, bool encoded=false);
  16. BBS2chProxyURLEncodedValue(const char *value, size_t length, bool encoded=false);
  17. const std::string& get();
  18. const std::string& getEncoded();
  19. void set(const std::string &value, bool encoded=false);
  20. bool empty();
  21. BBS2chProxyURLEncodedValue& operator=(const std::string &value);
  22. };
  23. class BBS2chProxyFormData {
  24. private:
  25. std::map<std::string, BBS2chProxyURLEncodedValue> _fields;
  26. std::vector<std::string> _order;
  27. std::string _body;
  28. bool _dirty;
  29. public:
  30. typedef std::map<std::string, BBS2chProxyURLEncodedValue>::iterator iterator;
  31. BBS2chProxyFormData() {};
  32. BBS2chProxyFormData(const char *data, size_t length);
  33. std::string get(const std::string &key);
  34. std::string getEncoded(const std::string &key);
  35. void append(const std::string &key, const std::string &value, bool encoded=false);
  36. void set(const std::string &key, const std::string &value, bool encoded=false);
  37. bool has(const std::string &key);
  38. void remove(const std::string &key);
  39. void reorder(const std::vector<std::string> &order);
  40. const std::string& toString();
  41. size_t size();
  42. iterator begin();
  43. iterator end();
  44. std::string operator[](const std::string &key);
  45. };