Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
CPPHTTPLIB_NAMESPACE::detail::FormDataParser Class Reference
Collaboration diagram for CPPHTTPLIB_NAMESPACE::detail::FormDataParser:

Public Member Functions

void set_boundary (std::string &&boundary)
bool is_valid () const
bool parse (const char *buf, size_t n, const FormDataHeader &header_callback, const ContentReceiver &content_callback)

Private Member Functions

void clear_file_info ()
bool start_with_case_ignore (const std::string &a, const char *b) const
bool start_with (const std::string &a, size_t spos, size_t epos, const std::string &b) const
size_t buf_size () const
const char * buf_data () const
std::string buf_head (size_t l) const
bool buf_start_with (const std::string &s) const
size_t buf_find (const std::string &s) const
void buf_append (const char *data, size_t n)
void buf_erase (size_t size)

Private Attributes

const std::string dash_ = "--"
const std::string crlf_ = "\r\n"
std::string boundary_
std::string dash_boundary_crlf_
std::string crlf_dash_boundary_
size_t state_ = 0
bool is_valid_ = false
FormData file_
std::string buf_
size_t buf_spos_ = 0
size_t buf_epos_ = 0

Member Function Documentation

◆ set_boundary()

void CPPHTTPLIB_NAMESPACE::detail::FormDataParser::set_boundary ( std::string && boundary)
inline
287135 {
287136 boundary_ = boundary;
287137 dash_boundary_crlf_ = dash_ + boundary_ + crlf_;
287138 crlf_dash_boundary_ = crlf_ + dash_ + boundary_;
287139 }

◆ is_valid()

bool CPPHTTPLIB_NAMESPACE::detail::FormDataParser::is_valid ( ) const
inline
287141{ return is_valid_; }

◆ parse()

bool CPPHTTPLIB_NAMESPACE::detail::FormDataParser::parse ( const char * buf,
size_t n,
const FormDataHeader & header_callback,
const ContentReceiver & content_callback )
inline
287144 {
287145
287146 buf_append(buf, n);
287147
287148 while (buf_size() > 0) {
287149 switch (state_) {
287150 case 0: { // Initial boundary
287151 auto pos = buf_find(dash_boundary_crlf_);
287152 if (pos == buf_size()) { return true; }
287153 buf_erase(pos + dash_boundary_crlf_.size());
287154 state_ = 1;
287155 break;
287156 }
287157 case 1: { // New entry
287158 clear_file_info();
287159 state_ = 2;
287160 break;
287161 }
287162 case 2: { // Headers
287163 auto pos = buf_find(crlf_);
287164 if (pos > CPPHTTPLIB_HEADER_MAX_LENGTH) { return false; }
287165 while (pos < buf_size()) {
287166 // Empty line
287167 if (pos == 0) {
287168 if (!header_callback(file_)) {
287169 is_valid_ = false;
287170 return false;
287171 }
287172 buf_erase(crlf_.size());
287173 state_ = 3;
287174 break;
287175 }
287176
287177 const auto header = buf_head(pos);
287178
287179 if (!parse_header(header.data(), header.data() + header.size(),
287180 [&](const std::string &, const std::string &) {})) {
287181 is_valid_ = false;
287182 return false;
287183 }
287184
287185 // Parse and emplace space trimmed headers into a map
287186 if (!parse_header(
287187 header.data(), header.data() + header.size(),
287188 [&](const std::string &key, const std::string &val) {
287189 file_.headers.emplace(key, val);
287190 })) {
287191 is_valid_ = false;
287192 return false;
287193 }
287194
287195 constexpr const char header_content_type[] = "Content-Type:";
287196
287197 if (start_with_case_ignore(header, header_content_type)) {
287198 file_.content_type =
287199 trim_copy(header.substr(str_len(header_content_type)));
287200 } else {
287201 REGEX_SCOPE const Regex re_content_disposition(
287202 R"~(^Content-Disposition:\s*form-data;\s*(.*)$)~",
287203 duckdb_re2::RegexOptions::CASE_INSENSITIVE);
287204
287205 Match m;
287206 if (RegexMatch(header, m, re_content_disposition)) {
287207 Params params;
287208 parse_disposition_params(m[1], params);
287209
287210 auto it = params.find("name");
287211 if (it != params.end()) {
287212 file_.name = it->second;
287213 } else {
287214 is_valid_ = false;
287215 return false;
287216 }
287217
287218 it = params.find("filename");
287219 if (it != params.end()) { file_.filename = it->second; }
287220
287221 it = params.find("filename*");
287222 if (it != params.end()) {
287223 // Only allow UTF-8 encoding...
287224 REGEX_SCOPE const Regex re_rfc5987_encoding(
287225 R"~(^UTF-8''(.+?)$)~", duckdb_re2::RegexOptions::CASE_INSENSITIVE);
287226
287227 Match m2;
287228 if (RegexMatch(it->second, m2, re_rfc5987_encoding)) {
287229 file_.filename = decode_path_component(m2[1]); // override...
287230 } else {
287231 is_valid_ = false;
287232 return false;
287233 }
287234 }
287235 }
287236 }
287237 buf_erase(pos + crlf_.size());
287238 pos = buf_find(crlf_);
287239 }
287240 if (state_ != 3) { return true; }
287241 break;
287242 }
287243 case 3: { // Body
287244 if (crlf_dash_boundary_.size() > buf_size()) { return true; }
287245 auto pos = buf_find(crlf_dash_boundary_);
287246 if (pos < buf_size()) {
287247 if (!content_callback(buf_data(), pos)) {
287248 is_valid_ = false;
287249 return false;
287250 }
287251 buf_erase(pos + crlf_dash_boundary_.size());
287252 state_ = 4;
287253 } else {
287254 auto len = buf_size() - crlf_dash_boundary_.size();
287255 if (len > 0) {
287256 if (!content_callback(buf_data(), len)) {
287257 is_valid_ = false;
287258 return false;
287259 }
287260 buf_erase(len);
287261 }
287262 return true;
287263 }
287264 break;
287265 }
287266 case 4: { // Boundary
287267 if (crlf_.size() > buf_size()) { return true; }
287268 if (buf_start_with(crlf_)) {
287269 buf_erase(crlf_.size());
287270 state_ = 1;
287271 } else {
287272 if (dash_.size() > buf_size()) { return true; }
287273 if (buf_start_with(dash_)) {
287274 buf_erase(dash_.size());
287275 is_valid_ = true;
287276 buf_erase(buf_size()); // Remove epilogue
287277 } else {
287278 return true;
287279 }
287280 }
287281 break;
287282 }
287283 }
287284 }
287285
287286 return true;
287287 }
Match(int x, int y, float similarity, const String &class_id, int template_id)
kinfu::Params Params
PyParams params(const std::string &tag, const std::string &model, const std::string &weights, const std::string &device)

◆ clear_file_info()

void CPPHTTPLIB_NAMESPACE::detail::FormDataParser::clear_file_info ( )
inlineprivate
287290 {
287291 file_.name.clear();
287292 file_.filename.clear();
287293 file_.content_type.clear();
287294 file_.headers.clear();
287295 }

◆ start_with_case_ignore()

bool CPPHTTPLIB_NAMESPACE::detail::FormDataParser::start_with_case_ignore ( const std::string & a,
const char * b ) const
inlineprivate
287297 {
287298 const auto b_len = strlen(b);
287299 if (a.size() < b_len) { return false; }
287300 for (size_t i = 0; i < b_len; i++) {
287301 if (case_ignore::to_lower(a[i]) != case_ignore::to_lower(b[i])) {
287302 return false;
287303 }
287304 }
287305 return true;
287306 }

◆ start_with()

bool CPPHTTPLIB_NAMESPACE::detail::FormDataParser::start_with ( const std::string & a,
size_t spos,
size_t epos,
const std::string & b ) const
inlineprivate
287320 {
287321 if (epos - spos < b.size()) { return false; }
287322 for (size_t i = 0; i < b.size(); i++) {
287323 if (a[i + spos] != b[i]) { return false; }
287324 }
287325 return true;
287326 }

◆ buf_size()

size_t CPPHTTPLIB_NAMESPACE::detail::FormDataParser::buf_size ( ) const
inlineprivate
287328{ return buf_epos_ - buf_spos_; }

◆ buf_data()

const char * CPPHTTPLIB_NAMESPACE::detail::FormDataParser::buf_data ( ) const
inlineprivate
287330{ return &buf_[buf_spos_]; }

◆ buf_head()

std::string CPPHTTPLIB_NAMESPACE::detail::FormDataParser::buf_head ( size_t l) const
inlineprivate
287332{ return buf_.substr(buf_spos_, l); }

◆ buf_start_with()

bool CPPHTTPLIB_NAMESPACE::detail::FormDataParser::buf_start_with ( const std::string & s) const
inlineprivate
287334 {
287335 return start_with(buf_, buf_spos_, buf_epos_, s);
287336 }

◆ buf_find()

size_t CPPHTTPLIB_NAMESPACE::detail::FormDataParser::buf_find ( const std::string & s) const
inlineprivate
287338 {
287339 auto c = s.front();
287340
287341 size_t off = buf_spos_;
287342 while (off < buf_epos_) {
287343 auto pos = off;
287344 while (true) {
287345 if (pos == buf_epos_) { return buf_size(); }
287346 if (buf_[pos] == c) { break; }
287347 pos++;
287348 }
287349
287350 auto remaining_size = buf_epos_ - pos;
287351 if (s.size() > remaining_size) { return buf_size(); }
287352
287353 if (start_with(buf_, pos, buf_epos_, s)) { return pos - buf_spos_; }
287354
287355 off = pos + 1;
287356 }
287357
287358 return buf_size();
287359 }

◆ buf_append()

void CPPHTTPLIB_NAMESPACE::detail::FormDataParser::buf_append ( const char * data,
size_t n )
inlineprivate
287361 {
287362 auto remaining_size = buf_size();
287363 if (remaining_size > 0 && buf_spos_ > 0) {
287364 for (size_t i = 0; i < remaining_size; i++) {
287365 buf_[i] = buf_[buf_spos_ + i];
287366 }
287367 }
287368 buf_spos_ = 0;
287369 buf_epos_ = remaining_size;
287370
287371 if (remaining_size + n > buf_.size()) { buf_.resize(remaining_size + n); }
287372
287373 for (size_t i = 0; i < n; i++) {
287374 buf_[buf_epos_ + i] = data[i];
287375 }
287376 buf_epos_ += n;
287377 }

◆ buf_erase()

void CPPHTTPLIB_NAMESPACE::detail::FormDataParser::buf_erase ( size_t size)
inlineprivate
287379{ buf_spos_ += size; }
GOpaque< Size > size(const GMat &src)

The documentation for this class was generated from the following file: