Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Host on device via webserver instead of using file://
- Loading branch information
1 parent
5d8dbff
commit 3b9e50c
Showing
37 changed files
with
3,513 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| [submodule "libs/http-parser"] | ||
| path = libs/http-parser | ||
| url = https://github.com/nodejs/http-parser.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| add_subdirectory(qhttp) |
Submodule http-parser
added at
ec8b5e
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| project(qhttp C CXX) | ||
| cmake_minimum_required(VERSION 3.0.0) | ||
|
|
||
|
|
||
| find_package(Qt5Core REQUIRED) | ||
| find_package(Qt5Network REQUIRED) | ||
|
|
||
| set(CMAKE_AUTOMOC ON) | ||
| set(CMAKE_AUTORCC ON) | ||
|
|
||
| set(QHTTP "QHttp") | ||
|
|
||
| set(SRC | ||
| ../http-parser/http_parser.c | ||
| ../http-parser/http_parser.h | ||
| qhttpabstracts.cpp | ||
| qhttpabstracts.hpp | ||
| qhttpfwd.hpp | ||
| qhttpserver.cpp | ||
| qhttpserver.hpp | ||
| qhttpserverconnection.cpp | ||
| qhttpserverconnection.hpp | ||
| qhttpserverrequest.cpp | ||
| qhttpserverrequest.hpp | ||
| qhttpserverresponse.cpp | ||
| qhttpserverresponse.hpp | ||
| ) | ||
|
|
||
| set(CMAKE_INCLUDE_CURRENT_DIR ON) | ||
| set(CMAKE_AUTOMOC ON) | ||
|
|
||
| add_library(${QHTTP} SHARED ${SRC}) | ||
|
|
||
|
|
||
|
|
||
| set(CMAKE_AUTOMOC ON) | ||
| set(CMAKE_AUTORCC ON) | ||
|
|
||
| target_link_libraries(${QHTTP} PUBLIC | ||
| Qt5::Core | ||
| Qt5::Network | ||
| ) | ||
|
|
||
| target_include_directories(${QHTTP} PUBLIC | ||
| . | ||
| ../ | ||
| ) | ||
|
|
||
| target_compile_definitions(${QHTTP} PUBLIC | ||
| QHTTP_DYNAMIC_LIB | ||
| QHTTP_HAS_CLIENT | ||
| QHTTP_MEMORY_LOG=0 | ||
| ) | ||
|
|
||
| install(TARGETS ${QHTTP} LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" | ||
| ) | ||
|
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| The MIT License (MIT) | ||
|
|
||
| Copyright (c) 2014 Amir Zamani | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
| this software and associated documentation files (the "Software"), to deal in | ||
| the Software without restriction, including without limitation the rights to | ||
| use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
| the Software, and to permit persons to whom the Software is furnished to do so, | ||
| subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
| FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
| COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
| IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
|
||
|
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| /** @file httpparser.hxx | ||
| * | ||
| * @copyright (C) 2016 | ||
| * @date 2016.05.26 | ||
| * @version 1.0.0 | ||
| * @author amir zamani <azadkuh@live.com> | ||
| * | ||
| */ | ||
|
|
||
| #ifndef __QHTTP_HTTPPARSER_HXX__ | ||
| #define __QHTTP_HTTPPARSER_HXX__ | ||
|
|
||
| #include "qhttpbase.hpp" | ||
| /////////////////////////////////////////////////////////////////////////////// | ||
| namespace qhttp { | ||
| namespace details { | ||
| /////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
|
|
||
| /// base HttpParser based on joyent http_parser | ||
| template<class TImpl> | ||
| class HttpParser | ||
| { | ||
| public: | ||
| explicit HttpParser(http_parser_type type) { | ||
| // create http_parser object | ||
| iparser.data = static_cast<TImpl*>(this); | ||
| http_parser_init(&iparser, type); | ||
|
|
||
| memset(&iparserSettings, 0, sizeof(http_parser_settings)); | ||
| iparserSettings.on_message_begin = onMessageBegin; | ||
| iparserSettings.on_url = onUrl; | ||
| iparserSettings.on_status = onStatus; | ||
| iparserSettings.on_header_field = onHeaderField; | ||
| iparserSettings.on_header_value = onHeaderValue; | ||
| iparserSettings.on_headers_complete = onHeadersComplete; | ||
| iparserSettings.on_body = onBody; | ||
| iparserSettings.on_message_complete = onMessageComplete; | ||
| } | ||
|
|
||
| size_t parse(const char* data, size_t length) { | ||
| return http_parser_execute(&iparser, | ||
| &iparserSettings, | ||
| data, | ||
| length); | ||
| } | ||
|
|
||
| public: // callback functions for http_parser_settings | ||
| static int onMessageBegin(http_parser* p) { | ||
| return me(p)->messageBegin(p); | ||
| } | ||
|
|
||
| static int onUrl(http_parser* p, const char* at, size_t length) { | ||
| return me(p)->url(p, at, length); | ||
| } | ||
|
|
||
| static int onStatus(http_parser* p, const char* at, size_t length) { | ||
| return me(p)->status(p, at, length); | ||
| } | ||
|
|
||
| static int onHeaderField(http_parser* p, const char* at, size_t length) { | ||
| return me(p)->headerField(p, at, length); | ||
| } | ||
|
|
||
| static int onHeaderValue(http_parser* p, const char* at, size_t length) { | ||
| return me(p)->headerValue(p, at, length); | ||
| } | ||
|
|
||
| static int onHeadersComplete(http_parser* p) { | ||
| return me(p)->headersComplete(p); | ||
| } | ||
|
|
||
| static int onBody(http_parser* p, const char* at, size_t length) { | ||
| return me(p)->body(p, at, length); | ||
| } | ||
|
|
||
| static int onMessageComplete(http_parser* p) { | ||
| return me(p)->messageComplete(p); | ||
| } | ||
|
|
||
|
|
||
| protected: | ||
| // The ones we are reading in from the parser | ||
| QByteArray itempHeaderField; | ||
| QByteArray itempHeaderValue; | ||
| // if connection has a timeout, these fields will be used | ||
| quint32 itimeOut = 0; | ||
| QBasicTimer itimer; | ||
| // uniform socket object | ||
| QSocket isocket; | ||
| // if connection should persist | ||
| bool ikeepAlive = false; | ||
|
|
||
| // joyent http_parser | ||
| http_parser iparser; | ||
| http_parser_settings iparserSettings; | ||
|
|
||
| static auto me(http_parser* p) { | ||
| return static_cast<TImpl*>(p->data); | ||
| } | ||
| }; // | ||
|
|
||
| /// basic request parser (server) | ||
| template<class TImpl> | ||
| struct HttpRequestParser : public HttpParser<TImpl> { | ||
| HttpRequestParser() : HttpParser<TImpl>(HTTP_REQUEST) {} | ||
| }; | ||
|
|
||
| /// basic response parser (clinet) | ||
| template<class TImpl> | ||
| struct HttpResponseParser : public HttpParser<TImpl> { | ||
| HttpResponseParser() : HttpParser<TImpl>(HTTP_RESPONSE) {} | ||
| }; | ||
|
|
||
| /////////////////////////////////////////////////////////////////////////////// | ||
| } // namespace details | ||
| } // namespace qhttp | ||
| /////////////////////////////////////////////////////////////////////////////// | ||
| #endif // __QHTTP_HTTPPARSER_HXX__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| /** @file httpreader.hxx | ||
| * | ||
| * @copyright (C) 2016 | ||
| * @date 2016.05.26 | ||
| * @version 1.0.0 | ||
| * @author amir zamani <azadkuh@live.com> | ||
| * | ||
| */ | ||
|
|
||
| #ifndef __QHTTP_HTTPREADER_HXX__ | ||
| #define __QHTTP_HTTPREADER_HXX__ | ||
|
|
||
| #include "qhttpbase.hpp" | ||
| /////////////////////////////////////////////////////////////////////////////// | ||
| namespace qhttp { | ||
| namespace details { | ||
| /////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| // usage in client::QHttpResponse, server::QHttpRequest | ||
| template<class TBase> | ||
| class HttpReader : public TBase | ||
| { | ||
| public: | ||
| enum TReadState { | ||
| EEmpty, | ||
| EPartial, | ||
| EComplete, | ||
| ESent | ||
| }; | ||
|
|
||
| public: | ||
| void collectData(int atMost) { | ||
| icollectRequired = true; | ||
| icollectCapacity = atMost; | ||
| icollectedData.clear(); | ||
| if ( atMost > 0 ) | ||
| icollectedData.reserve(atMost); | ||
| } | ||
|
|
||
| bool append(const char* data, size_t length) { | ||
| if ( !icollectRequired ) // not allowed to collect data | ||
| return false; | ||
|
|
||
| int newLength = icollectedData.length() + (int) length; | ||
|
|
||
| if ( icollectCapacity > 0 && newLength > icollectCapacity ) | ||
| return false; // the capacity is full | ||
|
|
||
| icollectedData.append(data, length); | ||
| return true; | ||
| } | ||
|
|
||
| // call cb if the message is not finalized yet | ||
| template<class Func> | ||
| void finalizeSending(Func cb) { | ||
| if ( ireadState != EComplete ) { | ||
| ireadState = EComplete; | ||
| isuccessful = true; | ||
|
|
||
| cb(); | ||
| } | ||
| } | ||
|
|
||
| public: | ||
| bool isuccessful = false; | ||
| TReadState ireadState = EEmpty; | ||
|
|
||
| /// shall I collect incoming body data by myself? | ||
| bool icollectRequired = false; | ||
| int icollectCapacity = 0; | ||
| QByteArray icollectedData; | ||
| }; | ||
|
|
||
| /////////////////////////////////////////////////////////////////////////////// | ||
| } // namespace details | ||
| } // namespace qhttp | ||
| /////////////////////////////////////////////////////////////////////////////// | ||
| #endif // __QHTTP_HTTPREADER_HXX__ |
Oops, something went wrong.