Commit 5a1f12b8e426d5efaa9c7e33493c60945ba2779f
1 parent
4c19358f
removed post format
Showing
1 changed file
with
0 additions
and
106 deletions
openbr/plugins/format/post.cpp deleted
| 1 | -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | |
| 2 | - * Copyright 2012 The MITRE Corporation * | |
| 3 | - * * | |
| 4 | - * Licensed under the Apache License, Version 2.0 (the "License"); * | |
| 5 | - * you may not use this file except in compliance with the License. * | |
| 6 | - * You may obtain a copy of the License at * | |
| 7 | - * * | |
| 8 | - * http://www.apache.org/licenses/LICENSE-2.0 * | |
| 9 | - * * | |
| 10 | - * Unless required by applicable law or agreed to in writing, software * | |
| 11 | - * distributed under the License is distributed on an "AS IS" BASIS, * | |
| 12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * | |
| 13 | - * See the License for the specific language governing permissions and * | |
| 14 | - * limitations under the License. * | |
| 15 | - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | |
| 16 | - | |
| 17 | -#include <QTcpSocket> | |
| 18 | -#include <opencv2/highgui/highgui.hpp> | |
| 19 | - | |
| 20 | -#include <openbr/plugins/openbr_internal.h> | |
| 21 | -#include <http_parser.h> | |
| 22 | - | |
| 23 | -using namespace cv; | |
| 24 | - | |
| 25 | -namespace br | |
| 26 | -{ | |
| 27 | - | |
| 28 | -/*! | |
| 29 | - * \ingroup formats | |
| 30 | - * \brief Handle POST requests | |
| 31 | - * \author Josh Klontz \cite jklontz | |
| 32 | - */ | |
| 33 | -class postFormat : public Format | |
| 34 | -{ | |
| 35 | - Q_OBJECT | |
| 36 | - | |
| 37 | - Template read() const | |
| 38 | - { | |
| 39 | - Template t(file); | |
| 40 | - | |
| 41 | - // Read from socket | |
| 42 | - QTcpSocket *socket = new QTcpSocket(); | |
| 43 | - socket->setSocketDescriptor(file.get<qintptr>("socketDescriptor")); | |
| 44 | - socket->write("HTTP/1.1 200 OK\r\n" | |
| 45 | - "Content-Type: text/html; charset=UTF-8\r\n\r\n" | |
| 46 | - "Hello World!\r\n"); | |
| 47 | - socket->waitForBytesWritten(); | |
| 48 | - socket->waitForReadyRead(); | |
| 49 | - QByteArray data = socket->readAll(); | |
| 50 | - socket->close(); | |
| 51 | - delete socket; | |
| 52 | - | |
| 53 | - qDebug() << data; | |
| 54 | - | |
| 55 | - // Parse data | |
| 56 | - http_parser_settings settings; | |
| 57 | - settings.on_body = bodyCallback; | |
| 58 | - settings.on_headers_complete = NULL; | |
| 59 | - settings.on_header_field = NULL; | |
| 60 | - settings.on_header_value = NULL; | |
| 61 | - settings.on_message_begin = NULL; | |
| 62 | - settings.on_message_complete = NULL; | |
| 63 | - settings.on_status_complete = NULL; | |
| 64 | - settings.on_url = NULL; | |
| 65 | - | |
| 66 | - { | |
| 67 | - QByteArray body; | |
| 68 | - http_parser parser; | |
| 69 | - http_parser_init(&parser, HTTP_REQUEST); | |
| 70 | - parser.data = &body; | |
| 71 | - http_parser_execute(&parser, &settings, data.data(), data.size()); | |
| 72 | - data = body; | |
| 73 | - } | |
| 74 | - | |
| 75 | - data.prepend("HTTP/1.1 200 OK"); | |
| 76 | - QByteArray body; | |
| 77 | - { // Image data is two layers deep | |
| 78 | - http_parser parser; | |
| 79 | - http_parser_init(&parser, HTTP_BOTH); | |
| 80 | - parser.data = &body; | |
| 81 | - http_parser_execute(&parser, &settings, data.data(), data.size()); | |
| 82 | - } | |
| 83 | - | |
| 84 | - t.append(imdecode(Mat(1, body.size(), CV_8UC1, body.data()), 1)); | |
| 85 | - return t; | |
| 86 | - } | |
| 87 | - | |
| 88 | - void write(const Template &t) const | |
| 89 | - { | |
| 90 | - (void) t; | |
| 91 | - qFatal("Not supported!"); | |
| 92 | - } | |
| 93 | - | |
| 94 | - static int bodyCallback(http_parser *parser, const char *at, size_t length) | |
| 95 | - { | |
| 96 | - QByteArray *byteArray = (QByteArray*)parser->data; | |
| 97 | - *byteArray = QByteArray(at, length); | |
| 98 | - return 0; | |
| 99 | - } | |
| 100 | -}; | |
| 101 | - | |
| 102 | -BR_REGISTER(Format, postFormat) | |
| 103 | - | |
| 104 | -} // namespace br | |
| 105 | - | |
| 106 | -#include "format/post.moc" |