/usr/include/bobcat/cgi is in libbobcat-dev 4.04.00-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | #ifndef INCLUDED_BOBCAT_CGI_
#define INCLUDED_BOBCAT_CGI_
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <vector>
#include <unordered_map>
#include <bobcat/pattern>
namespace FBB
{
class CGI
{
friend std::ostream &operator<<(std::ostream &out, CGI const &cgi);
public:
typedef std::unordered_map<std::string, std::vector<std::string> >
MapStringVector;
enum Method
{
UNDETERMINED,
GET,
POST
};
enum Create
{
DONT_CREATE_PATH,
CREATE_PATH
};
private:
enum Boundary // see multipartFormData()
{
NO_BOUNDARY,
BOUNDARY,
END_BOUNDARY
};
Method d_method;
bool d_escapeValue;
bool d_escape[256]; // initially all d_defaultEscape
MapStringVector d_param;
std::string d_query;
std::string d_boundary; // boundary of the multipart/form-data forms
// empty if POST produces GET-like info on
// stdin.
unsigned long long d_contentLength;
std::string d_filePath; // uploaded files are named
std::string d_filePrefix; // d_filePath / d_filePrefix d_fileNr++
size_t d_fileNr;
Pattern d_contentDisposition;
Pattern d_contentFile;
std::string d_status;
bool d_activated;
unsigned long long d_maxUploadSize;
static std::vector<std::string> s_empty;
enum: size_t
{
s_uploadBlock = 8000, // upload.cc
s_nTries = 100
};
public:
explicit CGI(bool defaultEscape = true,
char const *header = "Content-type: text/html",
std::ostream &out = std::cout);
CGI(CGI &&tmp);
CGI &operator=(CGI const &rhs) = default;
CGI &operator=(CGI &&tmp);
CGI &operator<<(std::string const &set);
CGI &operator<<(std::pair<char, char> range);
CGI &operator<<(int ch);
void setFileDestination(std::string const &path,
std::string const &prefix = "",
Create create = CREATE_PATH);
void setMaxUploadSize(size_t maxUploadSize, int unit = 'M');
void report() const; // also called by param()
// accessors:
char const *operator[](std::string const &key) const; // opindex.f
unsigned long long maxUploadSize() const; // .f
Method method() const; // .f
std::string const &query() const; // .f
// empty with multipart/form-data
std::vector<std::string> const ¶m(std::string const &variable);
MapStringVector::const_iterator begin(); // .f
MapStringVector::const_iterator end(); // .f
std::string param1(std::string const &variable);
// static members:
// unpercent also does the '+' to ' '
// conversion
static std::string unPercent(std::string const &text);
static std::string dos2unix(std::string const &text);
CGI(CGI const &&tmp); // Deprecated
CGI &operator=(CGI const &&tmp); // Deprecated
private:
void setQuery();
void get();
void post();
void addParam(std::string const ¶m);
void init(bool &target);
std::string escape(std::string const &text);
void next(std::string *line);
void multipartFormData();
Boundary typeOf(std::string const &line) const;
bool isFile(std::string const &line);
void readPart(std::string *line);
void setMethod();
void setParam();
void upload(std::string *line);
};
inline char const *CGI::operator[](std::string const &key) const
{
return getenv(key.c_str());
}
inline std::string const &CGI::query() const
{
return d_query;
}
inline CGI::Method CGI::method() const
{
return d_method;
}
inline CGI::MapStringVector::const_iterator CGI::begin()
{
setParam();
return d_param.begin();
}
inline CGI::MapStringVector::const_iterator CGI::end()
{
setParam();
return d_param.end();
}
} // namespace
#endif
|