public function wait_for_body($event, $args) { switch ($event) { case 'body': $content_length = $this->headers['Content-Length']; $rcvd = $args[0]; $rcvd_len = strlen($rcvd); $this->recvd_body_len += $rcvd_len; if ($this->body === null) { $this->body = $rcvd; } else { $this->body .= $rcvd; } if ($this->multipart) { // boundary start, content_disposition, form data, boundary start, ....., boundary end // these define various states of a multipart/form-data $form_data = explode(HTTPServer::HTTP_CRLF, $rcvd); foreach ($form_data as $data) { //JAXLLogger::debug("passing $data to multipart fsm"); if (!$this->multipart->process($data)) { JAXLLogger::debug("multipart fsm returned false"); $this->close(); return array('closed', false); } } } if ($this->recvd_body_len < $content_length && $this->multipart->state() != 'done') { JAXLLogger::debug("rcvd body len: {$this->recvd_body_len}/{$content_length}"); return 'wait_for_body'; } else { JAXLLogger::debug("all data received, switching state for dispatch"); return 'headers_received'; } break; case 'set_header': $content_length = $this->headers['Content-Length']; $body = implode(":", $args); $rcvd_len = strlen($body); $this->recvd_body_len += $rcvd_len; if (!$this->multipart->process($body)) { JAXLLogger::debug("multipart fsm returned false"); $this->close(); return array('closed', false); } if ($this->recvd_body_len < $content_length) { JAXLLogger::debug("rcvd body len: {$this->recvd_body_len}/{$content_length}"); return 'wait_for_body'; } else { JAXLLogger::debug("all data received, switching state for dispatch"); return 'headers_received'; } break; case 'empty_line': $content_length = $this->headers['Content-Length']; if (!$this->multipart->process('')) { JAXLLogger::debug("multipart fsm returned false"); $this->close(); return array('closed', false); } if ($this->recvd_body_len < $content_length) { JAXLLogger::debug("rcvd body len: {$this->recvd_body_len}/{$content_length}"); return 'wait_for_body'; } else { JAXLLogger::debug("all data received, switching state for dispatch"); return 'headers_received'; } break; default: JAXLLogger::warning("uncatched {$event}"); return 'wait_for_body'; } }