+ int OnUrl(const char* buf, size_t len)
+ {
+ if (!AcceptData(len))
+ {
+ status_code = HTTP_STATUS_URI_TOO_LONG;
+ return -1;
+ }
+ uri.append(buf, len);
+ return 0;
+ }
+
+ enum { HEADER_NONE, HEADER_FIELD, HEADER_VALUE } header_state;
+ std::string header_field;
+ std::string header_value;
+
+ void OnHeaderComplete()
+ {
+ headers.SetHeader(header_field, header_value);
+ header_field.clear();
+ header_value.clear();
+ }
+
+ int OnHeaderField(const char* buf, size_t len)
+ {
+ if (header_state == HEADER_VALUE)
+ OnHeaderComplete();
+ header_state = HEADER_FIELD;
+ if (!AcceptData(len))
+ {
+ status_code = HTTP_STATUS_REQUEST_HEADER_FIELDS_TOO_LARGE;
+ return -1;
+ }
+ header_field.append(buf, len);
+ return 0;
+ }
+
+ int OnHeaderValue(const char* buf, size_t len)
+ {
+ header_state = HEADER_VALUE;
+ if (!AcceptData(len))
+ {
+ status_code = HTTP_STATUS_REQUEST_HEADER_FIELDS_TOO_LARGE;
+ return -1;
+ }
+ header_value.append(buf, len);
+ return 0;
+ }
+
+ int OnHeadersComplete()
+ {
+ if (header_state != HEADER_NONE)
+ OnHeaderComplete();
+ return 0;
+ }
+
+ int OnBody(const char* buf, size_t len)
+ {
+ if (!AcceptData(len))
+ {
+ status_code = HTTP_STATUS_PAYLOAD_TOO_LARGE;
+ return -1;
+ }
+ body.append(buf, len);
+ return 0;
+ }
+
+ int OnMessageComplete()
+ {
+ ServeData();
+ return 0;
+ }
+
+ public:
+ HttpServerSocket(int newfd, const std::string& IP, ListenSocket* via, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server, unsigned int timeoutsec)
+ : BufferedSocket(newfd)
+ , Timer(timeoutsec)
+ , ip(IP)
+ , status_code(0)
+ , waitingcull(false)
+ {
+ if ((!via->iohookprovs.empty()) && (via->iohookprovs.back()))
+ {
+ via->iohookprovs.back()->OnAccept(this, client, server);
+ // IOHook may have errored
+ if (!getError().empty())
+ {
+ AddToCull();
+ return;
+ }
+ }
+
+ parser.data = this;
+ http_parser_init(&parser, HTTP_REQUEST);
+ ServerInstance->Timers.AddTimer(this);