<commit_before>
#include <hobbes/events/events.H>
#include <hobbes/events/httpd.H>
#include <hobbes/ipc/net.H>
#include <hobbes/util/str.H>

#include <sstream>

#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <netdb.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

namespace hobbes {

// evaluate HTTP request data until completed
class PartialHTTPRequestState {
public:
  PartialHTTPRequestState(int s, HTTPRequestHandler f, void* ud) : s(s), f(f), ud(ud), state(Method) {
  }

  bool transition(const char* b, const char* e) {
    while (b != e) {
      if (!transition(*b)) {
        this->f(this->req, this->s, this->ud);
        return false;
      }
      ++b;
    }
    return true;
  }
private:
  int                s;
  HTTPRequestHandler f;
  void*              ud;

  enum State {
    Method = 0,
    Document,
    FindHeaderBegin,
    HeaderNameOrEnd,
    HeaderName,
    HeaderValue,
    AccData
  };
  State state;

  std::ostringstream r0;
  std::ostringstream r1;
  size_t             len;

  HTTPRequest req;

  bool transition(char c) {
    switch (this->state) {
    case Method:
      if (c != ' ') {
        this->r0.put(c);
      } else {
        this->req.method = this->r0.str();
        this->r0.str("");

        this->state = Document;
        break;
      }
      break;
    case Document:
      if (c != ' ') {
        this->r0.put(c);
      } else {
        this->req.document = this->r0.str();
        this->r0.str("");

        this->state = FindHeaderBegin;
        break;
      }
    case FindHeaderBegin:
      if (c == '\n') {
        this->state = HeaderNameOrEnd;
      }
      break;
    case HeaderNameOrEnd:
      if (c == '\r' || c == '\n') {
        auto cl = this->req.headers.find("Content-Length");
        if (cl == this->req.headers.end()) {
          return false;
        } else {
          std::istringstream slen(cl->second);
          slen >> this->len;
          if (!slen || this->len == 0) { return false; }

          this->state = AccData;
        }<commit_msg>fix compile error in gcc8<commit_after>
#include <hobbes/events/events.H>
#include <hobbes/events/httpd.H>
#include <hobbes/ipc/net.H>
#include <hobbes/util/str.H>

#include <sstream>

#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <netdb.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

namespace hobbes {

// evaluate HTTP request data until completed
class PartialHTTPRequestState {
public:
  PartialHTTPRequestState(int s, HTTPRequestHandler f, void* ud) : s(s), f(f), ud(ud), state(Method) {
  }

  bool transition(const char* b, const char* e) {
    while (b != e) {
      if (!transition(*b)) {
        this->f(this->req, this->s, this->ud);
        return false;
      }
      ++b;
    }
    return true;
  }
private:
  int                s;
  HTTPRequestHandler f;
  void*              ud;

  enum State {
    Method = 0,
    Document,
    FindHeaderBegin,
    HeaderNameOrEnd,
    HeaderName,
    HeaderValue,
    AccData
  };
  State state;

  std::ostringstream r0;
  std::ostringstream r1;
  size_t             len;

  HTTPRequest req;

  bool transition(char c) {
    switch (this->state) {
    case Method:
      if (c != ' ') {
        this->r0.put(c);
      } else {
        this->req.method = this->r0.str();
        this->r0.str("");

        this->state = Document;
        break;
      }
      break;
    case Document:
      if (c != ' ') {
        this->r0.put(c);
      } else {
        this->req.document = this->r0.str();
        this->r0.str("");

        this->state = FindHeaderBegin;
      }
      break;
    case FindHeaderBegin:
      if (c == '\n') {
        this->state = HeaderNameOrEnd;
      }
      break;
    case HeaderNameOrEnd:
      if (c == '\r' || c == '\n') {
        auto cl = this->req.headers.find("Content-Length");
        if (cl == this->req.headers.end()) {
          return false;
        } else {
          std::istringstream slen(cl->second);
          slen >> this->len;
          if (!slen || this->len == 0) { return false; }

          this->state = AccData;
        }
{'fraction_non_alphanumeric': 0.15623506927854755, 'fraction_numerical': 0.005016722408026756, 'mean_word_length': 2.0187454938716654, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 77, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2100658', 'n_tokens_mistral': 1465, 'n_tokens_neox': 1444, 'n_words': 326}