diff --git a/CMakeLists.txt b/CMakeLists.txt index 2db8863..83fee1d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,7 +26,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules/") set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME Core) -add_definitions(-DQS_LOG_LINE_NUMBERS -DQHTTPSERVER_EXPORT) +add_definitions(-DQS_LOG_LINE_NUMBERS) include(DependencyConfiguration) include(QtConfiguration) diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index 15d94f5..072305b 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -1,7 +1,7 @@ -add_subdirectory(qhttpserver) add_subdirectory(qslog) +add_subdirectory(qhttp) if(APPLE) add_subdirectory(plistparser) add_subdirectory(SPMediaKeyTap) -endif(APPLE) \ No newline at end of file +endif(APPLE) diff --git a/external/qhttpserver/http-parser/.mailmap b/external/qhttp/3rdparty/http-parser/.mailmap similarity index 100% rename from external/qhttpserver/http-parser/.mailmap rename to external/qhttp/3rdparty/http-parser/.mailmap diff --git a/external/qhttpserver/http-parser/.travis.yml b/external/qhttp/3rdparty/http-parser/.travis.yml similarity index 100% rename from external/qhttpserver/http-parser/.travis.yml rename to external/qhttp/3rdparty/http-parser/.travis.yml diff --git a/external/qhttpserver/http-parser/AUTHORS b/external/qhttp/3rdparty/http-parser/AUTHORS old mode 100755 new mode 100644 similarity index 98% rename from external/qhttpserver/http-parser/AUTHORS rename to external/qhttp/3rdparty/http-parser/AUTHORS index 8e2df1d..5323b68 --- a/external/qhttpserver/http-parser/AUTHORS +++ b/external/qhttp/3rdparty/http-parser/AUTHORS @@ -65,3 +65,4 @@ Romain Giraud Jay Satiro Arne Steen Kjell Schubert +Olivier Mengué diff --git a/external/qhttpserver/http-parser/LICENSE-MIT b/external/qhttp/3rdparty/http-parser/LICENSE-MIT old mode 100755 new mode 100644 similarity index 100% rename from external/qhttpserver/http-parser/LICENSE-MIT rename to external/qhttp/3rdparty/http-parser/LICENSE-MIT diff --git a/external/qhttpserver/http-parser/README.md b/external/qhttp/3rdparty/http-parser/README.md old mode 100755 new mode 100644 similarity index 75% rename from external/qhttpserver/http-parser/README.md rename to external/qhttp/3rdparty/http-parser/README.md index 7c54dd4..eedd7f8 --- a/external/qhttpserver/http-parser/README.md +++ b/external/qhttp/3rdparty/http-parser/README.md @@ -1,7 +1,7 @@ HTTP Parser =========== -[![Build Status](https://travis-ci.org/joyent/http-parser.png?branch=master)](https://travis-ci.org/joyent/http-parser) +[![Build Status](https://api.travis-ci.org/nodejs/http-parser.svg?branch=master)](https://travis-ci.org/nodejs/http-parser) This is a parser for HTTP messages written in C. It parses both requests and responses. The parser is designed to be used in performance HTTP @@ -94,7 +94,7 @@ The Special Problem of Upgrade ------------------------------ HTTP supports upgrading the connection to a different protocol. An -increasingly common example of this is the Web Socket protocol which sends +increasingly common example of this is the WebSocket protocol which sends a request like GET /demo HTTP/1.1 @@ -106,8 +106,8 @@ a request like followed by non-HTTP data. -(See http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-75 for more -information the Web Socket protocol.) +(See [RFC6455](https://tools.ietf.org/html/rfc6455) for more information the +WebSocket protocol.) To support this, the parser will treat this as a normal HTTP message without a body, issuing both on_headers_complete and on_message_complete callbacks. However @@ -137,6 +137,69 @@ There are two types of callbacks: Callbacks must return 0 on success. Returning a non-zero value indicates error to the parser, making it exit immediately. +For cases where it is necessary to pass local information to/from a callback, +the `http_parser` object's `data` field can be used. +An example of such a case is when using threads to handle a socket connection, +parse a request, and then give a response over that socket. By instantiation +of a thread-local struct containing relevant data (e.g. accepted socket, +allocated memory for callbacks to write into, etc), a parser's callbacks are +able to communicate data between the scope of the thread and the scope of the +callback in a threadsafe manner. This allows http-parser to be used in +multi-threaded contexts. + +Example: +``` + typedef struct { + socket_t sock; + void* buffer; + int buf_len; + } custom_data_t; + + +int my_url_callback(http_parser* parser, const char *at, size_t length) { + /* access to thread local custom_data_t struct. + Use this access save parsed data for later use into thread local + buffer, or communicate over socket + */ + parser->data; + ... + return 0; +} + +... + +void http_parser_thread(socket_t sock) { + int nparsed = 0; + /* allocate memory for user data */ + custom_data_t *my_data = malloc(sizeof(custom_data_t)); + + /* some information for use by callbacks. + * achieves thread -> callback information flow */ + my_data->sock = sock; + + /* instantiate a thread-local parser */ + http_parser *parser = malloc(sizeof(http_parser)); + http_parser_init(parser, HTTP_REQUEST); /* initialise parser */ + /* this custom data reference is accessible through the reference to the + parser supplied to callback functions */ + parser->data = my_data; + + http_parser_settings settings; / * set up callbacks */ + settings.on_url = my_url_callback; + + /* execute parser */ + nparsed = http_parser_execute(parser, &settings, buf, recved); + + ... + /* parsed information copied from callback. + can now perform action on data copied into thread-local memory from callbacks. + achieves callback -> thread information flow */ + my_data->buffer; + ... +} + +``` + In case you parse HTTP message in chunks (i.e. `read()` request line from socket, parse, read half headers, parse, etc) your data callbacks may be called more than once. Http-parser guarantees that data pointer is only diff --git a/external/qhttpserver/http-parser/bench.c b/external/qhttp/3rdparty/http-parser/bench.c similarity index 100% rename from external/qhttpserver/http-parser/bench.c rename to external/qhttp/3rdparty/http-parser/bench.c diff --git a/external/qhttpserver/http-parser/contrib/parsertrace.c b/external/qhttp/3rdparty/http-parser/contrib/parsertrace.c similarity index 100% rename from external/qhttpserver/http-parser/contrib/parsertrace.c rename to external/qhttp/3rdparty/http-parser/contrib/parsertrace.c diff --git a/external/qhttpserver/http-parser/contrib/url_parser.c b/external/qhttp/3rdparty/http-parser/contrib/url_parser.c similarity index 97% rename from external/qhttpserver/http-parser/contrib/url_parser.c rename to external/qhttp/3rdparty/http-parser/contrib/url_parser.c index 6650b41..f235bed 100644 --- a/external/qhttpserver/http-parser/contrib/url_parser.c +++ b/external/qhttp/3rdparty/http-parser/contrib/url_parser.c @@ -35,6 +35,7 @@ int main(int argc, char ** argv) { connect = strcmp("connect", argv[1]) == 0 ? 1 : 0; printf("Parsing %s, connect %d\n", argv[2], connect); + http_parser_url_init(&u); result = http_parser_parse_url(argv[2], len, connect, &u); if (result != 0) { printf("Parse error : %d\n", result); @@ -43,4 +44,4 @@ int main(int argc, char ** argv) { printf("Parse ok, result : \n"); dump_url(argv[2], &u); return 0; -} \ No newline at end of file +} diff --git a/external/qhttpserver/http-parser/http_parser.c b/external/qhttp/3rdparty/http-parser/http_parser.c old mode 100755 new mode 100644 similarity index 96% rename from external/qhttpserver/http-parser/http_parser.c rename to external/qhttp/3rdparty/http-parser/http_parser.c index 0fa1c36..b3037d7 --- a/external/qhttpserver/http-parser/http_parser.c +++ b/external/qhttp/3rdparty/http-parser/http_parser.c @@ -400,6 +400,8 @@ enum http_host_state , s_http_host , s_http_host_v6 , s_http_host_v6_end + , s_http_host_v6_zone_start + , s_http_host_v6_zone , s_http_host_port_start , s_http_host_port }; @@ -957,21 +959,23 @@ reexecute: parser->method = (enum http_method) 0; parser->index = 1; switch (ch) { + case 'A': parser->method = HTTP_ACL; break; + case 'B': parser->method = HTTP_BIND; break; case 'C': parser->method = HTTP_CONNECT; /* or COPY, CHECKOUT */ break; case 'D': parser->method = HTTP_DELETE; break; case 'G': parser->method = HTTP_GET; break; case 'H': parser->method = HTTP_HEAD; break; - case 'L': parser->method = HTTP_LOCK; break; + case 'L': parser->method = HTTP_LOCK; /* or LINK */ break; case 'M': parser->method = HTTP_MKCOL; /* or MOVE, MKACTIVITY, MERGE, M-SEARCH, MKCALENDAR */ break; case 'N': parser->method = HTTP_NOTIFY; break; case 'O': parser->method = HTTP_OPTIONS; break; case 'P': parser->method = HTTP_POST; /* or PROPFIND|PROPPATCH|PUT|PATCH|PURGE */ break; - case 'R': parser->method = HTTP_REPORT; break; + case 'R': parser->method = HTTP_REPORT; /* or REBIND */ break; case 'S': parser->method = HTTP_SUBSCRIBE; /* or SEARCH */ break; case 'T': parser->method = HTTP_TRACE; break; - case 'U': parser->method = HTTP_UNLOCK; /* or UNSUBSCRIBE */ break; + case 'U': parser->method = HTTP_UNLOCK; /* or UNSUBSCRIBE, UNBIND, UNLINK */ break; default: SET_ERRNO(HPE_INVALID_METHOD); goto error; @@ -1027,16 +1031,32 @@ reexecute: SET_ERRNO(HPE_INVALID_METHOD); goto error; } - } else if (parser->index == 1 && parser->method == HTTP_POST) { - if (ch == 'R') { - parser->method = HTTP_PROPFIND; /* or HTTP_PROPPATCH */ - } else if (ch == 'U') { - parser->method = HTTP_PUT; /* or HTTP_PURGE */ - } else if (ch == 'A') { - parser->method = HTTP_PATCH; - } else { - SET_ERRNO(HPE_INVALID_METHOD); - goto error; + } else if (parser->method == HTTP_REPORT) { + if (parser->index == 2 && ch == 'B') { + parser->method = HTTP_REBIND; + } else { + SET_ERRNO(HPE_INVALID_METHOD); + goto error; + } + } else if (parser->index == 1) { + if (parser->method == HTTP_POST) { + if (ch == 'R') { + parser->method = HTTP_PROPFIND; /* or HTTP_PROPPATCH */ + } else if (ch == 'U') { + parser->method = HTTP_PUT; /* or HTTP_PURGE */ + } else if (ch == 'A') { + parser->method = HTTP_PATCH; + } else { + SET_ERRNO(HPE_INVALID_METHOD); + goto error; + } + } else if (parser->method == HTTP_LOCK) { + if (ch == 'I') { + parser->method = HTTP_LINK; + } else { + SET_ERRNO(HPE_INVALID_METHOD); + goto error; + } } } else if (parser->index == 2) { if (parser->method == HTTP_PUT) { @@ -1049,6 +1069,8 @@ reexecute: } else if (parser->method == HTTP_UNLOCK) { if (ch == 'S') { parser->method = HTTP_UNSUBSCRIBE; + } else if(ch == 'B') { + parser->method = HTTP_UNBIND; } else { SET_ERRNO(HPE_INVALID_METHOD); goto error; @@ -1059,6 +1081,8 @@ reexecute: } } else if (parser->index == 4 && parser->method == HTTP_PROPFIND && ch == 'P') { parser->method = HTTP_PROPPATCH; + } else if (parser->index == 3 && parser->method == HTTP_UNLOCK && ch == 'I') { + parser->method = HTTP_UNLINK; } else { SET_ERRNO(HPE_INVALID_METHOD); goto error; @@ -1828,11 +1852,12 @@ reexecute: case s_headers_done: { + int hasBody; STRICT_CHECK(ch != LF); parser->nread = 0; - int hasBody = parser->flags & F_CHUNKED || + hasBody = parser->flags & F_CHUNKED || (parser->content_length > 0 && parser->content_length != ULLONG_MAX); if (parser->upgrade && (parser->method == HTTP_CONNECT || (parser->flags & F_SKIPBODY) || !hasBody)) { @@ -1857,8 +1882,7 @@ reexecute: /* Content-Length header given and non-zero */ UPDATE_STATE(s_body_identity); } else { - if (parser->type == HTTP_REQUEST || - !http_message_needs_eof(parser)) { + if (!http_message_needs_eof(parser)) { /* Assume content-length 0 - read the next */ UPDATE_STATE(NEW_MESSAGE()); CALLBACK_NOTIFY(message_complete); @@ -2153,15 +2177,13 @@ http_parser_settings_init(http_parser_settings *settings) const char * http_errno_name(enum http_errno err) { - assert(((size_t) err) < - (sizeof(http_strerror_tab) / sizeof(http_strerror_tab[0]))); + assert(((size_t) err) < ARRAY_SIZE(http_strerror_tab)); return http_strerror_tab[err].name; } const char * http_errno_description(enum http_errno err) { - assert(((size_t) err) < - (sizeof(http_strerror_tab) / sizeof(http_strerror_tab[0]))); + assert(((size_t) err) < ARRAY_SIZE(http_strerror_tab)); return http_strerror_tab[err].description; } @@ -2214,6 +2236,23 @@ http_parse_host_char(enum http_host_state s, const char ch) { return s_http_host_v6; } + if (s == s_http_host_v6 && ch == '%') { + return s_http_host_v6_zone_start; + } + break; + + case s_http_host_v6_zone: + if (ch == ']') { + return s_http_host_v6_end; + } + + /* FALLTHROUGH */ + case s_http_host_v6_zone_start: + /* RFC 6874 Zone ID consists of 1*( unreserved / pct-encoded) */ + if (IS_ALPHANUM(ch) || ch == '%' || ch == '.' || ch == '-' || ch == '_' || + ch == '~') { + return s_http_host_v6_zone; + } break; case s_http_host_port: @@ -2232,6 +2271,7 @@ http_parse_host_char(enum http_host_state s, const char ch) { static int http_parse_host(const char * buf, struct http_parser_url *u, int found_at) { + assert(u->field_set & (1 << UF_HOST)); enum http_host_state s; const char *p; @@ -2263,6 +2303,11 @@ http_parse_host(const char * buf, struct http_parser_url *u, int found_at) { u->field_data[UF_HOST].len++; break; + case s_http_host_v6_zone_start: + case s_http_host_v6_zone: + u->field_data[UF_HOST].len++; + break; + case s_http_host_port: if (s != s_http_host_port) { u->field_data[UF_PORT].off = p - buf; @@ -2292,6 +2337,8 @@ http_parse_host(const char * buf, struct http_parser_url *u, int found_at) { case s_http_host_start: case s_http_host_v6_start: case s_http_host_v6: + case s_http_host_v6_zone_start: + case s_http_host_v6_zone: case s_http_host_port_start: case s_http_userinfo: case s_http_userinfo_start: @@ -2303,6 +2350,11 @@ http_parse_host(const char * buf, struct http_parser_url *u, int found_at) { return 0; } +void +http_parser_url_init(struct http_parser_url *u) { + memset(u, 0, sizeof(*u)); +} + int http_parser_parse_url(const char *buf, size_t buflen, int is_connect, struct http_parser_url *u) @@ -2376,7 +2428,12 @@ http_parser_parse_url(const char *buf, size_t buflen, int is_connect, /* host must be present if there is a schema */ /* parsing http:///toto will fail */ - if ((u->field_set & ((1 << UF_SCHEMA) | (1 << UF_HOST))) != 0) { + if ((u->field_set & (1 << UF_SCHEMA)) && + (u->field_set & (1 << UF_HOST)) == 0) { + return 1; + } + + if (u->field_set & (1 << UF_HOST)) { if (http_parse_host(buf, u, found_at) != 0) { return 1; } diff --git a/external/qhttpserver/http-parser/http_parser.gyp b/external/qhttp/3rdparty/http-parser/http_parser.gyp old mode 100755 new mode 100644 similarity index 100% rename from external/qhttpserver/http-parser/http_parser.gyp rename to external/qhttp/3rdparty/http-parser/http_parser.gyp diff --git a/external/qhttpserver/http-parser/http_parser.h b/external/qhttp/3rdparty/http-parser/http_parser.h old mode 100755 new mode 100644 similarity index 92% rename from external/qhttpserver/http-parser/http_parser.h rename to external/qhttp/3rdparty/http-parser/http_parser.h index eb71bf9..34bebf3 --- a/external/qhttpserver/http-parser/http_parser.h +++ b/external/qhttp/3rdparty/http-parser/http_parser.h @@ -26,11 +26,12 @@ extern "C" { /* Also update SONAME in the Makefile whenever you change these. */ #define HTTP_PARSER_VERSION_MAJOR 2 -#define HTTP_PARSER_VERSION_MINOR 5 +#define HTTP_PARSER_VERSION_MINOR 6 #define HTTP_PARSER_VERSION_PATCH 0 #include -#if defined(_WIN32) && !defined(__MINGW32__) && (!defined(_MSC_VER) || _MSC_VER<1600) +#if defined(_WIN32) && !defined(__MINGW32__) && \ + (!defined(_MSC_VER) || _MSC_VER<1600) && !defined(__WINE__) #include #include typedef __int8 int8_t; @@ -95,7 +96,7 @@ typedef int (*http_cb) (http_parser*); XX(5, CONNECT, CONNECT) \ XX(6, OPTIONS, OPTIONS) \ XX(7, TRACE, TRACE) \ - /* webdav */ \ + /* WebDAV */ \ XX(8, COPY, COPY) \ XX(9, LOCK, LOCK) \ XX(10, MKCOL, MKCOL) \ @@ -104,21 +105,28 @@ typedef int (*http_cb) (http_parser*); XX(13, PROPPATCH, PROPPATCH) \ XX(14, SEARCH, SEARCH) \ XX(15, UNLOCK, UNLOCK) \ + XX(16, BIND, BIND) \ + XX(17, REBIND, REBIND) \ + XX(18, UNBIND, UNBIND) \ + XX(19, ACL, ACL) \ /* subversion */ \ - XX(16, REPORT, REPORT) \ - XX(17, MKACTIVITY, MKACTIVITY) \ - XX(18, CHECKOUT, CHECKOUT) \ - XX(19, MERGE, MERGE) \ + XX(20, REPORT, REPORT) \ + XX(21, MKACTIVITY, MKACTIVITY) \ + XX(22, CHECKOUT, CHECKOUT) \ + XX(23, MERGE, MERGE) \ /* upnp */ \ - XX(20, MSEARCH, M-SEARCH) \ - XX(21, NOTIFY, NOTIFY) \ - XX(22, SUBSCRIBE, SUBSCRIBE) \ - XX(23, UNSUBSCRIBE, UNSUBSCRIBE) \ + XX(24, MSEARCH, M-SEARCH) \ + XX(25, NOTIFY, NOTIFY) \ + XX(26, SUBSCRIBE, SUBSCRIBE) \ + XX(27, UNSUBSCRIBE, UNSUBSCRIBE) \ /* RFC-5789 */ \ - XX(24, PATCH, PATCH) \ - XX(25, PURGE, PURGE) \ + XX(28, PATCH, PATCH) \ + XX(29, PURGE, PURGE) \ /* CalDAV */ \ - XX(26, MKCALENDAR, MKCALENDAR) \ + XX(30, MKCALENDAR, MKCALENDAR) \ + /* RFC-2068, section 19.6.1.2 */ \ + XX(31, LINK, LINK) \ + XX(32, UNLINK, UNLINK) \ enum http_method { @@ -144,7 +152,7 @@ enum flags /* Map for errno-related constants - * + * * The provided argument should be a macro that takes 2 arguments. */ #define HTTP_ERRNO_MAP(XX) \ @@ -325,6 +333,9 @@ const char *http_errno_name(enum http_errno err); /* Return a string description of the given error */ const char *http_errno_description(enum http_errno err); +/* Initialize all http_parser_url members to 0 */ +void http_parser_url_init(struct http_parser_url *u); + /* Parse a URL; return nonzero on failure */ int http_parser_parse_url(const char *buf, size_t buflen, int is_connect, diff --git a/external/qhttpserver/http-parser/test.c b/external/qhttp/3rdparty/http-parser/test.c old mode 100755 new mode 100644 similarity index 97% rename from external/qhttpserver/http-parser/test.c rename to external/qhttp/3rdparty/http-parser/test.c index 4c00571..c63b8f0 --- a/external/qhttpserver/http-parser/test.c +++ b/external/qhttp/3rdparty/http-parser/test.c @@ -1101,6 +1101,58 @@ const struct message requests[] = ,.body= "" } +/* Examples from the Internet draft for LINK/UNLINK methods: + * https://tools.ietf.org/id/draft-snell-link-method-01.html#rfc.section.5 + */ + +#define LINK_REQUEST 40 +, {.name = "link request" + ,.type= HTTP_REQUEST + ,.raw= "LINK /images/my_dog.jpg HTTP/1.1\r\n" + "Host: example.com\r\n" + "Link: ; rel=\"tag\"\r\n" + "Link: ; rel=\"tag\"\r\n" + "\r\n" + ,.should_keep_alive= TRUE + ,.message_complete_on_eof= FALSE + ,.http_major= 1 + ,.http_minor= 1 + ,.method= HTTP_LINK + ,.request_path= "/images/my_dog.jpg" + ,.request_url= "/images/my_dog.jpg" + ,.query_string= "" + ,.fragment= "" + ,.num_headers= 3 + ,.headers= { { "Host", "example.com" } + , { "Link", "; rel=\"tag\"" } + , { "Link", "; rel=\"tag\"" } + } + ,.body= "" + } + +#define UNLINK_REQUEST 41 +, {.name = "link request" + ,.type= HTTP_REQUEST + ,.raw= "UNLINK /images/my_dog.jpg HTTP/1.1\r\n" + "Host: example.com\r\n" + "Link: ; rel=\"tag\"\r\n" + "\r\n" + ,.should_keep_alive= TRUE + ,.message_complete_on_eof= FALSE + ,.http_major= 1 + ,.http_minor= 1 + ,.method= HTTP_UNLINK + ,.request_path= "/images/my_dog.jpg" + ,.request_url= "/images/my_dog.jpg" + ,.query_string= "" + ,.fragment= "" + ,.num_headers= 2 + ,.headers= { { "Host", "example.com" } + , { "Link", "; rel=\"tag\"" } + } + ,.body= "" + } + , {.name= NULL } /* sentinel */ }; @@ -2918,6 +2970,59 @@ const struct url_test url_tests[] = ,.rv=1 /* s_dead */ } +, {.name="ipv6 address with Zone ID" + ,.url="http://[fe80::a%25eth0]/" + ,.is_connect=0 + ,.u= + {.field_set= (1<setStatusCode(qhttp::ESTATUS_OK); // status 200 + res->addHeader("connection", "close"); // it's the default header, this line can be omitted. + res->end("Hello World!\n"); // response body data + + // when "connection: close", the req and res will be deleted automatically. + }); + + + if ( !server.isListening() ) { + fprintf(stderr, "failed. can not listen at port 8080!\n"); + return -1; + } + + // application's main event loop + return app.exec(); +} +``` + +to request weather information by **HTTP client**: +```cpp +int main(int argc, char** argv) { + QCoreApplication app(argc, argv); + using namespace qhttp::client; + + QHttpClient client(&app); + QByteArray httpBody; + + QUrl weatherUrl("http://api.openweathermap.org/data/2.5/weather?q=tehran,ir&units=metric&mode=xml"); + + client.request(qhttp::EHTTP_GET, weatherUrl, [&httpBody](QHttpResponse* res) { + // response handler, called when the HTTP headers of the response are ready + + // gather HTTP response data + res->onData([&httpBody](const QByteArray& chunk) { + httpBody.append(chunk); + }); + + // called when all data in HTTP response have been read. + res->onEnd([&httpBody]() { + // print the XML body of the response + puts("\n[incoming response:]"); + puts(httpBody.constData()); + puts("\n\n"); + + QCoreApplication::instance()->quit(); + }); + + // just for fun! print headers: + puts("\n[Headers:]"); + const qhttp::THeaderHash& hs = res->headers(); + for ( auto cit = hs.constBegin(); cit != hs.constEnd(); cit++) { + printf("%s : %s\n", cit.key().constData(), cit.value().constData()); + } + }); + + + return app.exec(); +} +``` + +## Setup +[TOC](#table-of-contents) + +instructions: +```bash +# first clone this repository: +$> git clone --depth=1 https://github.com/azadkuh/qhttp.git -b master +$> cd qhttp + +# prepare dependencies: +$> ./update-dependencies.sh + +# now build the library and the examples +$> qmake qhttp.pro +$> make -j 8 +``` + +## Multi-threading +[TOC](#table-of-contents) + +As `QHttp` is **asynchrounous** and **non-bloking**, your app can handle thousands of concurrent HTTP connections by a single thread. + +in some rare scenarios you may want to use multiple handler threads (although it's not the best solution): + +* there are some blocking APIs (QSql, system calls, ...) in your connection handler (adopting asynchronous layer over the blocking API is a better approach). + +* the hardware has lots of free cores and the measurement shows that the load on the main `QHttp` thread is close to highest limit. There you can spawn some other handler threads. + + +[benchmark example](./example/benchmark/README.md) shows how to implement a single or multi threaded HTTP app (both server and client). This example uses worker `QThread` and `QObject::moveToThread()` for worker objects. see aslo: [Subclassing no longer recommended way of using QThread](http://qt-project.org/doc/note_revisions/5/8/view). + +**Note**: +> moving objects between threads is an expensive job, more ever the locking/unlocking mechanism, creating or stopping threads, ... cost even more! so using multiple threads in an application is not guaranteed to get better performance, but it's guaranteed to add more complexity, nasty bugs and headache! + +see why other top performer networking libraries as ZeroMQ are concurrent but not multi-threaded by default: + +* [ZeroMQ : Multithreading Magic](http://zeromq.org/blog:multithreading-magic) +* [Node.js : about](http://nodejs.org/about/) + + +## Source tree +[TOC](#table-of-contents) + + +* **`3rdparty/`**: +will contain `http-parser` source tree as the only dependency. +this directory is created by setup. see also: [setup](#setup). + +* **`example/`**: +contains some sample applications representing the `QHttp` usage: + * **`helloworld/`**: + the HelloWorld example of `QHttp`, both server + client are represented. + see: [README@helloworld](./example/helloworld/README.md) + + * **`basic-server/`**: + a basic HTTP server shows how to collect the request body, and respond to the clients. + see: [README@basic-server](./example/basic-server/README.md) + + + * **`benchmark/`**: + a simple utility to measure the throughput (requests per second) of `QHttp` as a REST/Json server. this app provides both the server and attacking clinets. + see: [README@benchmark](./example/benchmark/README.md) + + * **`nodejs/`**: + Node.js implementation of `benchmark/` in server mode. Provided for benchmarking `QHttp` with `Node.js` as a RESTFul service app. + see: [README@nodejs](./example/nodejs/README.md) + + +* **`src/`**: +holds the source code of `QHttp`. server classes are prefixed by `qhttpserver*` and client classes by `qhttpclient*`. + * **`private/`**: + Private classes of the library. see: [d-pointers](https://qt-project.org/wiki/Dpointer). + +* **`tmp/`**: +a temporary directory which is created while `make`ing the library and holds all the `.o`, `moc files`, etc. + +* **`xbin/`**: +all the executable and binaries will be placed on this folder by `make`. + + + + +## Disclaimer +[TOC](#table-of-contents) + +* Implementing a lightweight and simple HTTP server/client in Qt with Node.js like API, is the main purpose of `QHttp`. + +* There are lots of features in a full blown HTTP server which are out of scope of this small library, although those can be added on top of `QHttp`. + +* The client classes are by no mean designed as a `QNetworkAccessManager` replacement. `QHttpClient` is simpler and lighter, for serious scenarios just use `QNetworkAccessManager`. + +* I'm a busy person. + + +> If you have any ideas, critiques, suggestions or whatever you want to call it, please open an issue. I'll be happy to hear from you what you'd see in this lib. I think about all suggestions, and I try to add those that make sense. + + +## License +[TOC](#table-of-contents) + +Distributed under the MIT license. Copyright (c) 2014, Amir Zamani. + diff --git a/external/qhttp/src/private/qhttpbase.hpp b/external/qhttp/src/private/qhttpbase.hpp new file mode 100644 index 0000000..b8e6f02 --- /dev/null +++ b/external/qhttp/src/private/qhttpbase.hpp @@ -0,0 +1,470 @@ +/** base classes for private implementations. + * https://github.com/azadkuh/qhttp + * + * @author amir zamani + * @version 2.0.0 + * @date 2014-07-11 + */ + +#ifndef QHTTPBASE_HPP +#define QHTTPBASE_HPP + +#include "qhttpfwd.hpp" + +#include +#include +#include +#include +#include + +#include "http-parser/http_parser.h" + +/////////////////////////////////////////////////////////////////////////////// +namespace qhttp { +/////////////////////////////////////////////////////////////////////////////// + +class QSocket +{ +public: + void close() { + if ( itcpSocket ) + itcpSocket->close(); + if ( ilocalSocket ) + ilocalSocket->close(); + } + + void release() { + close(); + if ( itcpSocket ) + itcpSocket->deleteLater(); + if ( ilocalSocket ) + ilocalSocket->deleteLater(); + + itcpSocket = nullptr; + ilocalSocket = nullptr; + } + + void flush() { + if ( itcpSocket ) + itcpSocket->flush(); + else if ( ilocalSocket ) + ilocalSocket->flush(); + } + + bool isOpen() const { + if ( ibackendType == ETcpSocket && itcpSocket ) + return itcpSocket->isOpen() && itcpSocket->state() == QTcpSocket::ConnectedState; + + else if ( ibackendType == ELocalSocket && ilocalSocket ) + return ilocalSocket->isOpen() && ilocalSocket->state() == QLocalSocket::ConnectedState; + + return false; + } + + void connectTo(const QUrl& url) { + if ( ilocalSocket ) + ilocalSocket->connectToServer(url.path()); + } + + void connectTo(const QString& host, quint16 port) { + if ( itcpSocket ) + itcpSocket->connectToHost(host, port); + } + + qint64 readRaw(char* buffer, int maxlen) { + if ( itcpSocket ) + return itcpSocket->read(buffer, maxlen); + else if ( ilocalSocket ) + return ilocalSocket->read(buffer, maxlen); + + return 0; + } + + void writeRaw(const QByteArray& data) { + if ( itcpSocket ) + itcpSocket->write(data); + else if ( ilocalSocket ) + ilocalSocket->write(data); + } + + qint64 bytesAvailable() { + if ( itcpSocket ) + return itcpSocket->bytesAvailable(); + else if ( ilocalSocket ) + return ilocalSocket->bytesAvailable(); + + return 0; + } + + void disconnectAllQtConnections() { + if ( itcpSocket ) + QObject::disconnect(itcpSocket, 0, 0, 0); + if ( ilocalSocket ) + QObject::disconnect(ilocalSocket, 0, 0, 0); + } + +public: + TBackend ibackendType = ETcpSocket; + QTcpSocket* itcpSocket = nullptr; + QLocalSocket* ilocalSocket = nullptr; +}; + +/////////////////////////////////////////////////////////////////////////////// + +class HttpBase +{ +public: + THeaderHash iheaders; + QString iversion; +}; + +/////////////////////////////////////////////////////////////////////////////// + +class HttpRequestBase : public HttpBase +{ +public: + QUrl iurl; + THttpMethod imethod; +}; + +/////////////////////////////////////////////////////////////////////////////// + +class HttpResponseBase : public HttpBase +{ +public: + HttpResponseBase() { + iversion = "1.1"; + } + +public: + TStatusCode istatus = ESTATUS_BAD_REQUEST; +}; + +/////////////////////////////////////////////////////////////////////////////// + +// usage in client::QHttpResponse, server::QHttpRequest +template +class HttpReader : public TBase +{ +public: + enum TReadState { + EEmpty, + EPartial, + EComplete, + ESent + }; + +public: + void collectData(int atMost) { + icollectCapacity = atMost; + icollectedData.clear(); + icollectedData.reserve(atMost); + } + + bool shouldCollect() const { + return icollectCapacity > 0; + } + + bool append(const char* data, size_t length) { + int currentLength = icollectedData.length(); + + if ( (currentLength + (int)length) >= icollectCapacity ) + return false; // capacity if full + + icollectedData.append(data, length); + return true; + } + +public: + TReadState ireadState = EEmpty; + bool isuccessful = false; + + int icollectCapacity = 0; + QByteArray icollectedData; +}; + +/////////////////////////////////////////////////////////////////////////////// + +// usage in client::QHttpRequest, server::QHttpResponse +template +class HttpWriter : public TBase +{ +public: + bool addHeader(const QByteArray &field, const QByteArray &value) { + if ( ifinished ) + return false; + + TBase::iheaders.insert(field.toLower(), value); + return true; + } + + bool writeHeader(const QByteArray& field, const QByteArray& value) { + if ( ifinished ) + return false; + + QByteArray buffer = QByteArray(field) + .append(": ") + .append(value) + .append("\r\n"); + + isocket.writeRaw(buffer); + return true; + } + + bool writeData(const QByteArray& data) { + if ( ifinished ) + return false; + + ensureWritingHeaders(); + isocket.writeRaw(data); + return true; + } + + bool endPacket(const QByteArray& data) { + if ( !writeData(data) ) + return false; + + isocket.flush(); + ifinished = true; + return true; + } + + void ensureWritingHeaders() { + if ( ifinished || iheaderWritten ) + return; + + TImpl* me = static_cast(this); + isocket.writeRaw(me->makeTitle()); + writeHeaders(); + + iheaderWritten = true; + } + + void writeHeaders(bool doFlush = false) { + if ( ifinished || iheaderWritten ) + return; + + if ( TBase::iheaders.keyHasValue("connection", "keep-alive") ) + ikeepAlive = true; + else + TBase::iheaders.insert("connection", "close"); + + TImpl* me = static_cast(this); + me->prepareHeadersToWrite(); + + + for ( auto cit = TBase::iheaders.constBegin(); cit != TBase::iheaders.constEnd(); cit++ ) { + const QByteArray& field = cit.key(); + const QByteArray& value = cit.value(); + + writeHeader(field, value); + } + + isocket.writeRaw("\r\n"); + if ( doFlush ) + isocket.flush(); + } + +public: + QSocket isocket; + + bool ifinished = false; + bool iheaderWritten = false; + bool ikeepAlive = false; +}; + +/////////////////////////////////////////////////////////////////////////////// + +// usage in client::QHttpClient, server::QHttpConnection +template +class HttpParser +{ +public: + explicit HttpParser(http_parser_type type) { + // create http_parser object + iparser.data = static_cast(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* parser) { + TImpl *me = static_cast(parser->data); + return me->messageBegin(parser); + } + + static int onUrl(http_parser* parser, const char* at, size_t length) { + TImpl *me = static_cast(parser->data); + return me->url(parser, at, length); + } + + static int onStatus(http_parser* parser, const char* at, size_t length) { + TImpl *me = static_cast(parser->data); + return me->status(parser, at, length); + } + + static int onHeaderField(http_parser* parser, const char* at, size_t length) { + TImpl *me = static_cast(parser->data); + return me->headerField(parser, at, length); + } + + static int onHeaderValue(http_parser* parser, const char* at, size_t length) { + TImpl *me = static_cast(parser->data); + return me->headerValue(parser, at, length); + } + + static int onHeadersComplete(http_parser* parser) { + TImpl *me = static_cast(parser->data); + return me->headersComplete(parser); + } + + static int onBody(http_parser* parser, const char* at, size_t length) { + TImpl *me = static_cast(parser->data); + return me->body(parser, at, length); + } + + static int onMessageComplete(http_parser* parser) { + TImpl *me = static_cast(parser->data); + return me->messageComplete(parser); + } + + +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; + + + +protected: + http_parser iparser; + http_parser_settings iparserSettings; +}; + +/////////////////////////////////////////////////////////////////////////////// +#if 0 +template +class HttpWriterBase +{ +public: + explicit HttpWriterBase() { + } + + virtual ~HttpWriterBase() { + } + + void initialize() { + reset(); + + if ( itcpSocket ) { + // first disconnects previous dangling lambdas + QObject::disconnect(itcpSocket, &QTcpSocket::bytesWritten, 0, 0); + + QObject::connect(itcpSocket, &QTcpSocket::bytesWritten, [this](qint64 ){ + if ( itcpSocket->bytesToWrite() == 0 ) + static_cast(this)->allBytesWritten(); + + }); + + } else if ( ilocalSocket ) { + // first disconnects previous dangling lambdas + QObject::disconnect(ilocalSocket, &QLocalSocket::bytesWritten, 0, 0); + + QObject::connect(ilocalSocket, &QLocalSocket::bytesWritten, [this](qint64 ){ + if ( ilocalSocket->bytesToWrite() == 0 ) + static_cast(this)->allBytesWritten(); + }); + } + } + + void reset() { + iheaderWritten = false; + ifinished = false; + } + +public: + bool addHeader(const QByteArray &field, const QByteArray &value) { + if ( ifinished ) + return false; + + static_cast(this)->iheaders.insert(field.toLower(), value); + return true; + } + + bool writeHeader(const QByteArray& field, const QByteArray& value) { + if ( ifinished ) + return false; + + QByteArray buffer = QByteArray(field) + .append(": ") + .append(value) + .append("\r\n"); + writeRaw(buffer); + return true; + } + + bool writeData(const QByteArray& data) { + if ( ifinished ) + return false; + + static_cast(this)->ensureWritingHeaders(); + writeRaw(data); + return true; + } + + bool endPacket(const QByteArray& data) { + if ( !writeData(data) ) + return false; + + if ( itcpSocket ) + itcpSocket->flush(); + else if ( ilocalSocket ) + ilocalSocket->flush(); + + ifinished = true; + return true; + } + +protected: + void writeRaw(const QByteArray &data) { + if ( itcpSocket ) + itcpSocket->write(data); + else if ( ilocalSocket ) + ilocalSocket->write(data); + } + +public: + QTcpSocket* itcpSocket = nullptr; + QLocalSocket* ilocalSocket = nullptr; + + bool iheaderWritten; + bool ifinished; +}; +#endif +/////////////////////////////////////////////////////////////////////////////// +} // namespace qhttp +/////////////////////////////////////////////////////////////////////////////// +#endif // QHTTPBASE_HPP diff --git a/external/qhttp/src/private/qhttpclient_private.hpp b/external/qhttp/src/private/qhttpclient_private.hpp new file mode 100644 index 0000000..68d8932 --- /dev/null +++ b/external/qhttp/src/private/qhttpclient_private.hpp @@ -0,0 +1,167 @@ +/** private imeplementation. + * https://github.com/azadkuh/qhttp + * + * @author amir zamani + * @version 2.0.0 + * @date 2014-07-11 + */ + +#ifndef QHTTPCLIENT_PRIVATE_HPP +#define QHTTPCLIENT_PRIVATE_HPP +/////////////////////////////////////////////////////////////////////////////// + +#include "qhttpclient.hpp" +#include "qhttpclientrequest_private.hpp" +#include "qhttpclientresponse_private.hpp" + +/////////////////////////////////////////////////////////////////////////////// +namespace qhttp { +namespace client { +/////////////////////////////////////////////////////////////////////////////// + +class QHttpClientPrivate : public HttpParser +{ + Q_DECLARE_PUBLIC(QHttpClient) + +public: + explicit QHttpClientPrivate(QHttpClient* q) : HttpParser(HTTP_RESPONSE), q_ptr(q) { + QObject::connect(q_func(), &QHttpClient::disconnected, [this](){ + release(); + }); + + QHTTP_LINE_DEEPLOG + } + + virtual ~QHttpClientPrivate() { + QHTTP_LINE_DEEPLOG + } + + void release() { + // if socket drops and http_parser can not call messageComplete, dispatch the ilastResponse + onDispatchResponse(); + + isocket.disconnectAllQtConnections(); + isocket.close(); + isocket.release(); + + if ( ilastRequest ) { + ilastRequest->deleteLater(); + ilastRequest = nullptr; + } + if ( ilastResponse ) { + ilastResponse->deleteLater(); + ilastResponse = nullptr; + } + + // must be called! or the later http_parser_execute() may fail + http_parser_init(&iparser, HTTP_RESPONSE); + } + + void initializeSocket() { + if ( isocket.isOpen() ) { + if ( ikeepAlive ) // no need to reconnect. do nothing and simply return + return; + + // close previous connection + release(); // release now! instead being called by emitted disconnected signal + } + + ikeepAlive = false; + + // create a tcp connection + if ( isocket.ibackendType == ETcpSocket ) { + + QTcpSocket* sok = new QTcpSocket(q_func()); + isocket.itcpSocket = sok; + + QObject::connect(sok, &QTcpSocket::connected, [this](){ + onConnected(); + }); + QObject::connect(sok, &QTcpSocket::readyRead, [this](){ + onReadyRead(); + }); + QObject::connect(sok, &QTcpSocket::bytesWritten, [this](qint64){ + if ( isocket.itcpSocket->bytesToWrite() == 0 && ilastRequest ) + emit ilastRequest->allBytesWritten(); + }); + QObject::connect(sok, &QTcpSocket::disconnected, + q_func(), &QHttpClient::disconnected); + + } else if ( isocket.ibackendType == ELocalSocket ) { + + QLocalSocket* sok = new QLocalSocket(q_func()); + isocket.ilocalSocket = sok; + + QObject::connect(sok, &QLocalSocket::connected, [this](){ + onConnected(); + }); + QObject::connect(sok, &QLocalSocket::readyRead, [this](){ + onReadyRead(); + }); + QObject::connect(sok, &QLocalSocket::bytesWritten, [this](qint64){ + if ( isocket.ilocalSocket->bytesToWrite() == 0 && ilastRequest ) + emit ilastRequest->allBytesWritten(); + }); + QObject::connect(sok, &QLocalSocket::disconnected, + q_func(), &QHttpClient::disconnected); + } + } + +public: + int messageBegin(http_parser* parser); + int url(http_parser*, const char*, size_t) { + return 0; // not used in parsing incoming respone. + } + int status(http_parser* parser, const char* at, size_t length) ; + int headerField(http_parser* parser, const char* at, size_t length); + int headerValue(http_parser* parser, const char* at, size_t length); + int headersComplete(http_parser* parser); + int body(http_parser* parser, const char* at, size_t length); + int messageComplete(http_parser* parser); + +protected: + void onConnected() { + if ( itimeOut > 0 ) + itimer.start(itimeOut, Qt::CoarseTimer, q_func()); + + if ( ireqHandler ) + ireqHandler(ilastRequest); + else + q_func()->onRequestReady(ilastRequest); + } + + void onReadyRead() { + while ( isocket.bytesAvailable() > 0 ) { + char buffer[4097] = {0}; + size_t readLength = (size_t) isocket.readRaw(buffer, 4096); + + parse(buffer, readLength); + } + + onDispatchResponse(); + } + + void onDispatchResponse() { + // if ilastResponse has been sent previously, just return + if ( ilastResponse->d_func()->ireadState == QHttpResponsePrivate::ESent ) + return; + + ilastResponse->d_func()->ireadState = QHttpResponsePrivate::ESent; + emit ilastResponse->end(); + } + +protected: + QHttpClient* const q_ptr; + + QHttpRequest* ilastRequest = nullptr; + QHttpResponse* ilastResponse = nullptr; + TRequstHandler ireqHandler; + TResponseHandler irespHandler; +}; + +/////////////////////////////////////////////////////////////////////////////// +} // namespace client +} // namespace qhttp +/////////////////////////////////////////////////////////////////////////////// + +#endif // QHTTPCLIENT_PRIVATE_HPP diff --git a/external/qhttp/src/private/qhttpclientrequest_private.hpp b/external/qhttp/src/private/qhttpclientrequest_private.hpp new file mode 100644 index 0000000..b552f48 --- /dev/null +++ b/external/qhttp/src/private/qhttpclientrequest_private.hpp @@ -0,0 +1,56 @@ +/** private imeplementation. + * https://github.com/azadkuh/qhttp + * + * @author amir zamani + * @version 2.0.0 + * @date 2014-07-11 + */ + +#ifndef QHTTPCLIENT_REQUEST_PRIVATE_HPP +#define QHTTPCLIENT_REQUEST_PRIVATE_HPP +/////////////////////////////////////////////////////////////////////////////// +#include "qhttpbase.hpp" +#include "qhttpclient.hpp" +#include "qhttpclientrequest.hpp" + +#include + +/////////////////////////////////////////////////////////////////////////////// +namespace qhttp { +namespace client { +/////////////////////////////////////////////////////////////////////////////// +class QHttpRequestPrivate : public HttpWriter +{ + Q_DECLARE_PUBLIC(QHttpRequest) + +public: + explicit QHttpRequestPrivate(QHttpClient* cli, QHttpRequest* q) : q_ptr(q), iclient(cli) { + QHTTP_LINE_DEEPLOG + } + + virtual ~QHttpRequestPrivate() { + QHTTP_LINE_DEEPLOG + } + + void initialize() { + iversion = "1.1"; + + isocket.ibackendType = iclient->backendType(); + isocket.itcpSocket = iclient->tcpSocket(); + isocket.ilocalSocket = iclient->localSocket(); + } + + QByteArray makeTitle(); + + void prepareHeadersToWrite(); + +protected: + QHttpRequest* const q_ptr; + QHttpClient* const iclient; +}; + +/////////////////////////////////////////////////////////////////////////////// +} // namespace client +} // namespace qhttp +/////////////////////////////////////////////////////////////////////////////// +#endif // QHTTPCLIENT_REQUEST_PRIVATE_HPP diff --git a/external/qhttp/src/private/qhttpclientresponse_private.hpp b/external/qhttp/src/private/qhttpclientresponse_private.hpp new file mode 100644 index 0000000..19c0b19 --- /dev/null +++ b/external/qhttp/src/private/qhttpclientresponse_private.hpp @@ -0,0 +1,50 @@ +/** private imeplementation. + * https://github.com/azadkuh/qhttp + * + * @author amir zamani + * @version 2.0.0 + * @date 2014-07-11 + */ + +#ifndef QHTTPCLIENT_RESPONSE_PRIVATE_HPP +#define QHTTPCLIENT_RESPONSE_PRIVATE_HPP +/////////////////////////////////////////////////////////////////////////////// + +#include "qhttpbase.hpp" +#include "qhttpclient.hpp" +#include "qhttpclientresponse.hpp" + +/////////////////////////////////////////////////////////////////////////////// +namespace qhttp { +namespace client { +/////////////////////////////////////////////////////////////////////////////// +class QHttpResponsePrivate : public HttpReader +{ + Q_DECLARE_PUBLIC(QHttpResponse) + QHttpResponse* const q_ptr; + +public: + explicit QHttpResponsePrivate(QHttpClient* cli, QHttpResponse* q) + : q_ptr(q), iclient(cli) { + QHTTP_LINE_DEEPLOG + } + + virtual ~QHttpResponsePrivate() { + QHTTP_LINE_DEEPLOG + } + + void initialize() { + } + +public: + QString icustomStatusMessage; + +protected: + QHttpClient* const iclient; +}; + +/////////////////////////////////////////////////////////////////////////////// +} // namespace client +} // namespace qhttp +/////////////////////////////////////////////////////////////////////////////// +#endif // QHTTPCLIENT_RESPONSE_PRIVATE_HPP diff --git a/external/qhttp/src/private/qhttpserver_private.hpp b/external/qhttp/src/private/qhttpserver_private.hpp new file mode 100644 index 0000000..324acc3 --- /dev/null +++ b/external/qhttp/src/private/qhttpserver_private.hpp @@ -0,0 +1,90 @@ +/** private imeplementation. + * https://github.com/azadkuh/qhttp + * + * @author amir zamani + * @version 2.0.0 + * @date 2014-07-11 + */ + +#ifndef QHTTPSERVER_PRIVATE_HPP +#define QHTTPSERVER_PRIVATE_HPP +/////////////////////////////////////////////////////////////////////////////// + +#include "qhttpserver.hpp" +#include "qhttpserverconnection.hpp" +#include "qhttpserverrequest.hpp" +#include "qhttpserverresponse.hpp" + +#include +#include +/////////////////////////////////////////////////////////////////////////////// +namespace qhttp { +namespace server { +/////////////////////////////////////////////////////////////////////////////// + +class QHttpServerPrivate +{ +public: + template + class BackendServer : public TServer + { + public: + QHttpServer* iserver; + + explicit BackendServer(QHttpServer* s) : TServer(s), iserver(s) { + } + + protected: + // if it's a QTcpServer + virtual void incomingConnection(qintptr socketDescriptor) { + iserver->incomingConnection(socketDescriptor); + } + + // if it's a QLocalServer + virtual void incomingConnection(quintptr socketDescriptor) { + iserver->incomingConnection((qintptr) socketDescriptor); + } + }; + + typedef QScopedPointer> TTcpServer; + typedef QScopedPointer> TLocalServer; + +public: + quint32 itimeOut = 0; + TServerHandler ihandler = nullptr; + + TBackend ibackend = ETcpSocket; + + TTcpServer itcpServer; + TLocalServer ilocalServer; + +public: + explicit QHttpServerPrivate() { + QHTTP_LINE_DEEPLOG + } + + virtual ~QHttpServerPrivate() { + QHTTP_LINE_DEEPLOG + } + + void initialize(TBackend backend, QHttpServer* parent) { + ibackend = backend; + + if ( ibackend == ETcpSocket ) { + itcpServer.reset( new BackendServer(parent) ); + ilocalServer.reset( nullptr ); + + } else if ( ibackend == ELocalSocket ) { + itcpServer.reset( nullptr ); + ilocalServer.reset( new BackendServer(parent) ); + } + } + +}; + +/////////////////////////////////////////////////////////////////////////////// +} // namespace server +} // namespace qhttp +/////////////////////////////////////////////////////////////////////////////// + +#endif // QHTTPSERVER_PRIVATE_HPP diff --git a/external/qhttp/src/private/qhttpserverconnection_private.hpp b/external/qhttp/src/private/qhttpserverconnection_private.hpp new file mode 100644 index 0000000..a2af5d7 --- /dev/null +++ b/external/qhttp/src/private/qhttpserverconnection_private.hpp @@ -0,0 +1,148 @@ +/** private imeplementation. + * https://github.com/azadkuh/qhttp + * + * @author amir zamani + * @version 2.0.0 + * @date 2014-07-11 + */ + +#ifndef QHTTPSERVER_CONNECTION_PRIVATE_HPP +#define QHTTPSERVER_CONNECTION_PRIVATE_HPP +/////////////////////////////////////////////////////////////////////////////// + +#include "qhttpserverconnection.hpp" + +#include "qhttpserverrequest.hpp" +#include "qhttpserverresponse.hpp" + +#include "private/qhttpserverrequest_private.hpp" +#include "private/qhttpserverresponse_private.hpp" + +#include +#include +/////////////////////////////////////////////////////////////////////////////// +namespace qhttp { +namespace server { +/////////////////////////////////////////////////////////////////////////////// +class QHttpConnectionPrivate : public HttpParser +{ +protected: + Q_DECLARE_PUBLIC(QHttpConnection) + QHttpConnection* const q_ptr; + +public: + QByteArray itempUrl; + + // Since there can only be one request/response pair per connection at any time even with pipelining. + QHttpRequest* ilastRequest = nullptr; + QHttpResponse* ilastResponse = nullptr; + + + TServerHandler ihandler = nullptr; + +public: + explicit QHttpConnectionPrivate(QHttpConnection* q) : HttpParser(HTTP_REQUEST), q_ptr(q) { + + QObject::connect(q_func(), &QHttpConnection::disconnected, [this](){ + // if socket drops and http_parser can not call messageComplete, dispatch the ilastRequest + onDispatchRequest(); + isocket.release(); + + if ( ilastRequest ) + ilastRequest->deleteLater(); + if ( ilastResponse ) + ilastResponse->deleteLater(); + + q_func()->deleteLater(); + }); + + QHTTP_LINE_DEEPLOG + } + + virtual ~QHttpConnectionPrivate() { + QHTTP_LINE_DEEPLOG + } + + void createSocket(qintptr sokDesc, TBackend bend) { + isocket.ibackendType = bend; + + if ( bend == ETcpSocket ) { + QTcpSocket* sok = new QTcpSocket( q_func() ); + isocket.itcpSocket = sok; + sok->setSocketDescriptor(sokDesc); + + QObject::connect(sok, &QTcpSocket::readyRead, [this](){ + onReadyRead(); + }); + QObject::connect(sok, &QTcpSocket::bytesWritten, [this](){ + if ( isocket.itcpSocket->bytesToWrite() == 0 && ilastResponse ) + emit ilastResponse->allBytesWritten(); + }); + QObject::connect(sok, &QTcpSocket::disconnected, + q_func(), &QHttpConnection::disconnected, + Qt::QueuedConnection); + + } else if ( bend == ELocalSocket ) { + QLocalSocket* sok = new QLocalSocket( q_func() ); + isocket.ilocalSocket = sok; + sok->setSocketDescriptor(sokDesc); + + QObject::connect(sok, &QLocalSocket::readyRead, [this](){ + onReadyRead(); + }); + QObject::connect(sok, &QLocalSocket::bytesWritten, [this](){ + if ( isocket.ilocalSocket->bytesToWrite() == 0 && ilastResponse ) + emit ilastResponse->allBytesWritten(); + }); + QObject::connect(sok, &QLocalSocket::disconnected, + q_func(), &QHttpConnection::disconnected, + Qt::QueuedConnection); + } + + } + +public: + void onReadyRead() { + while ( isocket.bytesAvailable() > 0 ) { + char buffer[4097] = {0}; + size_t readLength = (size_t) isocket.readRaw(buffer, 4096); + + parse(buffer, readLength); + } + + onDispatchRequest(); + } + + void onDispatchRequest() { + // if ilastRequest has been sent previously, just return + if ( ilastRequest->d_func()->ireadState == QHttpRequestPrivate::ESent ) + return; + + ilastRequest->d_func()->ireadState = QHttpRequestPrivate::ESent; + emit ilastRequest->end(); + } + +public: + int messageBegin(http_parser* parser); + int url(http_parser* parser, const char* at, size_t length); + int status(http_parser*, const char*, size_t) { + return 0; // not used in parsing incoming request. + } + int headerField(http_parser* parser, const char* at, size_t length); + int headerValue(http_parser* parser, const char* at, size_t length); + int headersComplete(http_parser* parser); + int body(http_parser* parser, const char* at, size_t length); + int messageComplete(http_parser* parser); + +#ifdef USE_CUSTOM_URL_CREATOR +public: + static QUrl createUrl(const char *urlData, const http_parser_url &urlInfo); +#endif // USE_CUSTOM_URL_CREATOR + +}; + +/////////////////////////////////////////////////////////////////////////////// +} // namespace server +} // namespace qhttp +/////////////////////////////////////////////////////////////////////////////// +#endif // QHTTPSERVER_CONNECTION_PRIVATE_HPP diff --git a/external/qhttp/src/private/qhttpserverrequest_private.hpp b/external/qhttp/src/private/qhttpserverrequest_private.hpp new file mode 100644 index 0000000..1a395a3 --- /dev/null +++ b/external/qhttp/src/private/qhttpserverrequest_private.hpp @@ -0,0 +1,50 @@ +/** private imeplementation. + * https://github.com/azadkuh/qhttp + * + * @author amir zamani + * @version 2.0.0 + * @date 2014-07-11 + */ + +#ifndef QHTTPSERVER_REQUEST_PRIVATE_HPP +#define QHTTPSERVER_REQUEST_PRIVATE_HPP +/////////////////////////////////////////////////////////////////////////////// + +#include "qhttpbase.hpp" +#include "qhttpserverrequest.hpp" +#include "qhttpserverconnection.hpp" + +/////////////////////////////////////////////////////////////////////////////// +namespace qhttp { +namespace server { +/////////////////////////////////////////////////////////////////////////////// +class QHttpRequestPrivate : public HttpReader +{ +protected: + Q_DECLARE_PUBLIC(QHttpRequest) + QHttpRequest* const q_ptr; + +public: + explicit QHttpRequestPrivate(QHttpConnection* conn, QHttpRequest* q) : q_ptr(q), iconnection(conn) { + QHTTP_LINE_DEEPLOG + } + + virtual ~QHttpRequestPrivate() { + QHTTP_LINE_DEEPLOG + } + + void initialize() { + } + +public: + QString iremoteAddress; + quint16 iremotePort = 0; + + QHttpConnection* const iconnection = nullptr; +}; + +/////////////////////////////////////////////////////////////////////////////// +} // namespace server +} // namespace qhttp +/////////////////////////////////////////////////////////////////////////////// +#endif // QHTTPSERVER_REQUEST_PRIVATE_HPP diff --git a/external/qhttp/src/private/qhttpserverresponse_private.hpp b/external/qhttp/src/private/qhttpserverresponse_private.hpp new file mode 100644 index 0000000..d9c865d --- /dev/null +++ b/external/qhttp/src/private/qhttpserverresponse_private.hpp @@ -0,0 +1,61 @@ +/** private imeplementation. + * https://github.com/azadkuh/qhttp + * + * @author amir zamani + * @version 2.0.0 + * @date 2014-07-11 + */ + +#ifndef QHTTPSERVER_RESPONSE_PRIVATE_HPP +#define QHTTPSERVER_RESPONSE_PRIVATE_HPP +/////////////////////////////////////////////////////////////////////////////// +#include "qhttpbase.hpp" +#include "qhttpserverresponse.hpp" +#include "qhttpserver.hpp" +#include "qhttpserverconnection.hpp" + +#include +#include +#include + +/////////////////////////////////////////////////////////////////////////////// +namespace qhttp { +namespace server { +/////////////////////////////////////////////////////////////////////////////// +class QHttpResponsePrivate : public HttpWriter +{ + Q_DECLARE_PUBLIC(QHttpResponse) + +public: + explicit QHttpResponsePrivate(QHttpConnection* conn, QHttpResponse* q) + : q_ptr(q), iconnection(conn) { + QHTTP_LINE_DEEPLOG + } + + virtual ~QHttpResponsePrivate() { + QHTTP_LINE_DEEPLOG + } + + void initialize() { + isocket.ibackendType = iconnection->backendType(); + isocket.ilocalSocket = iconnection->localSocket(); + isocket.itcpSocket = iconnection->tcpSocket(); + + QObject::connect(iconnection, &QHttpConnection::disconnected, + q_func(), &QHttpResponse::deleteLater); + } + + QByteArray makeTitle(); + + void prepareHeadersToWrite(); + +protected: + QHttpResponse* const q_ptr; + QHttpConnection* const iconnection; +}; + +/////////////////////////////////////////////////////////////////////////////// +} // namespace server +} // namespace qhttp +/////////////////////////////////////////////////////////////////////////////// +#endif // QHTTPSERVER_RESPONSE_PRIVATE_HPP diff --git a/external/qhttp/src/qhttpabstracts.cpp b/external/qhttp/src/qhttpabstracts.cpp new file mode 100644 index 0000000..1b106e5 --- /dev/null +++ b/external/qhttp/src/qhttpabstracts.cpp @@ -0,0 +1,114 @@ +#include "qhttpabstracts.hpp" +#include "http-parser/http_parser.h" + +/////////////////////////////////////////////////////////////////////////////// +namespace qhttp { +/////////////////////////////////////////////////////////////////////////////// +#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) +# error "to compile QHttp classes, Qt 5.0 or later is needed." +#endif + +#define HTTP_STATUS_MAP(XX) \ + XX(100, "Continue") \ + XX(101, "Switching Protocols") \ + /* RFC 2518) obsoleted by RFC 4918 */ \ + XX(102, "Processing") \ + XX(200, "OK") \ + XX(201, "Created") \ + XX(202, "Accepted") \ + XX(203, "Non-Authoritative Information") \ + XX(204, "No Content") \ + XX(205, "Reset Content") \ + XX(206, "Partial Content") \ + /* RFC 4918 */ \ + XX(207, "Multi-Status") \ + XX(300, "Multiple Choices") \ + XX(301, "Moved Permanently") \ + XX(302, "Moved Temporarily") \ + XX(303, "See Other") \ + XX(304, "Not Modified") \ + XX(305, "Use Proxy") \ + XX(307, "Temporary Redirect") \ + XX(400, "Bad Request") \ + XX(401, "Unauthorized") \ + XX(402, "Payment Required") \ + XX(403, "Forbidden") \ + XX(404, "Not Found") \ + XX(405, "Method Not Allowed") \ + XX(406, "Not Acceptable") \ + XX(407, "Proxy Authentication Required") \ + XX(408, "Request Time-out") \ + XX(409, "Conflict") \ + XX(410, "Gone") \ + XX(411, "Length Required") \ + XX(412, "Precondition Failed") \ + XX(413, "Request Entity Too Large") \ + XX(414, "Request-URI Too Large") \ + XX(415, "Unsupported Media Type") \ + XX(416, "Requested Range Not Satisfiable") \ + XX(417, "Expectation Failed") \ + /* RFC 2324 */ \ + XX(418, "I\"m a teapot") \ + /* RFC 4918 */ \ + XX(422, "Unprocessable Entity") \ + /* RFC 4918 */ \ + XX(423, "Locked") \ + /* RFC 4918 */ \ + XX(424, "Failed Dependency") \ + /* RFC 4918 */ \ + XX(425, "Unordered Collection") \ + /* RFC 2817 */ \ + XX(426, "Upgrade Required") \ + XX(500, "Internal Server Error") \ + XX(501, "Not Implemented") \ + XX(502, "Bad Gateway") \ + XX(503, "Service Unavailable") \ + XX(504, "Gateway Time-out") \ + XX(505, "HTTP Version not supported") \ + /* RFC 2295 */ \ + XX(506, "Variant Also Negotiates") \ + /* RFC 4918 */ \ + XX(507, "Insufficient Storage") \ + XX(509, "Bandwidth Limit Exceeded") \ + /* RFC 2774 */ \ + XX(510, "Not Extended") + +#define PATCH_STATUS_CODES(n,s) {n, s}, +static struct { + int code; + const char* message; +} g_status_codes[] { + HTTP_STATUS_MAP(PATCH_STATUS_CODES) +}; +#undef PATCH_STATUS_CODES + +/////////////////////////////////////////////////////////////////////////////// + +const char* +Stringify::toString(TStatusCode code) { + size_t count = sizeof(g_status_codes) / sizeof(g_status_codes[0]); + for ( size_t i = 0; i < count; i++ ) { + if ( g_status_codes[i].code == code ) + return g_status_codes[i].message; + } + + return nullptr; +} + +const char* +Stringify::toString(THttpMethod method) { + return http_method_str(static_cast(method)); +} + +/////////////////////////////////////////////////////////////////////////////// + +QHttpAbstractInput::QHttpAbstractInput(QObject* parent) : QObject(parent) { +} + +QHttpAbstractOutput::QHttpAbstractOutput(QObject *parent) : QObject(parent) { +} + + +/////////////////////////////////////////////////////////////////////////////// +} // namespace qhttp +/////////////////////////////////////////////////////////////////////////////// diff --git a/external/qhttp/src/qhttpabstracts.hpp b/external/qhttp/src/qhttpabstracts.hpp new file mode 100644 index 0000000..a5b161d --- /dev/null +++ b/external/qhttp/src/qhttpabstracts.hpp @@ -0,0 +1,193 @@ +/** interfaces of QHttp' incomming and outgoing classes. + * https://github.com/azadkuh/qhttp + * + * @author amir zamani + * @version 2.0.0 + * @date 2014-07-11 + */ + +#ifndef QHTTPABSTRACTS_HPP +#define QHTTPABSTRACTS_HPP + +/////////////////////////////////////////////////////////////////////////////// +#include "qhttpfwd.hpp" + +#include +#include +/////////////////////////////////////////////////////////////////////////////// +namespace qhttp { +/////////////////////////////////////////////////////////////////////////////// + +/** a utility class to give the string representation of qhttp types. */ +class QHTTP_API Stringify +{ +public: + /** returns the standard message for an HTTP status code. */ + static const char* toString(TStatusCode); + + /** returns the standars name of an HTTP method. */ + static const char* toString(THttpMethod); +}; + +/////////////////////////////////////////////////////////////////////////////// + +typedef std::function TDataHandler; +typedef std::function TEndHandler; + +/////////////////////////////////////////////////////////////////////////////// +/** an interface for input (incoming) HTTP packets. + * server::QHttpRequest or client::QHttpResponse inherit from this class. */ +class QHTTP_API QHttpAbstractInput : public QObject +{ + Q_OBJECT + +public: + /** Return all the headers in the incomming packet. + * This returns a reference. If you want to store headers + * somewhere else, where the request may be deleted, + * make sure you store them as a copy. + * @note All header names are lowercase . */ + virtual const THeaderHash& headers() const=0; + + /** The HTTP version of the packet. + * @return A string in the form of "x.x" */ + virtual const QString& httpVersion() const=0; + + /** If this packet was successfully received. + * Set before end() has been emitted, stating whether + * the message was properly received. This is false + * until the receiving the full request has completed. */ + virtual bool isSuccessful() const=0; + +signals: + /** Emitted when new body data has been received. + * @param data Received data. + * @note This may be emitted zero or more times depending on the transfer type. + * @see onData(); + */ + void data(QByteArray data); + + /** Emitted when the incomming packet has been fully received. + * @note The no more data() signals will be emitted after this. + * @see onEnd(); + */ + void end(); + +public: + /** optionally set a handler for data() signal. + * @param dataHandler a std::function or lambda handler to receive incoming data. + * @note if you set this handler, the data() signal won't be emitted anymore. + */ + void onData(const TDataHandler& dataHandler) { + QObject::connect(this, &QHttpAbstractInput::data, [dataHandler](QByteArray data){ + dataHandler(data); + }); + } + + /** optionally set a handler for end() signal. + * @param endHandler a std::function or lambda handler to receive end notification. + * @note if you set this handler, the end() signal won't be emitted anymore. + */ + void onEnd(const TEndHandler& endHandler) { + QObject::connect(this, &QHttpAbstractInput::end, [endHandler](){ + endHandler(); + }); + } + +public: + /** tries to collect all the incoming data internally. + * @note if you call this method, data() signal won't be emitted and + * onData() will have no effect. + * + * @param atMost maximum acceptable incoming data. if the incoming data + * exceeds this value, the connection won't read any more data and + * end() signal will be emitted. -1 means unlimited. + */ + virtual void collectData(int atMost = -1) =0; + + /** returns the collected data requested by collectData(). */ + virtual const QByteArray& collectedData()const =0; + + +public: + virtual ~QHttpAbstractInput() = default; + + explicit QHttpAbstractInput(QObject* parent); + + Q_DISABLE_COPY(QHttpAbstractInput) +}; + +/////////////////////////////////////////////////////////////////////////////// + +/** an interface for output (outgoing) HTTP packets. + * server::QHttpResponse or client::QHttpRequest inherit from this class. */ +class QHTTP_API QHttpAbstractOutput : public QObject +{ + Q_OBJECT + +public: + /** changes the HTTP version string ex: "1.1" or "1.0". + * version is "1.1" set by default. */ + virtual void setVersion(const QString& versionString)=0; + + /** helper function. @sa addHeader */ + template + void addHeaderValue(const QByteArray &field, T value); + + /** adds an HTTP header to the packet. + * @note this method does not actually write anything to socket, just prepares the headers(). */ + virtual void addHeader(const QByteArray& field, const QByteArray& value)=0; + + /** returns all the headers that already been set. */ + virtual THeaderHash& headers()=0; + + /** writes a block of data into the HTTP packet. + * @note headers are written (flushed) before any data. + * @warning after calling this method add a new header, set staus code, set Url have no effect! */ + virtual void write(const QByteArray &data)=0; + + /** ends (finishes) the outgoing packet by calling write(). + * headers and data will be flushed to the underlying socket. + * + * @sa write() */ + virtual void end(const QByteArray &data = QByteArray())=0; + +signals: + /** Emitted when all the data has been sent. + * this signal indicates that the underlaying socket has transmitted all + * of it's buffered data. */ + void allBytesWritten(); + + /** Emitted when the packet is finished and reports if it was the last packet. + * if it was the last packet (google for "Connection: keep-alive / close") + * the http connection (socket) will be closed automatically. */ + void done(bool wasTheLastPacket); + +public: + virtual ~QHttpAbstractOutput() = default; + +protected: + explicit QHttpAbstractOutput(QObject* parent); + + Q_DISABLE_COPY(QHttpAbstractOutput) +}; + +template<> inline void +QHttpAbstractOutput::addHeaderValue(const QByteArray &field, int value) { + addHeader(field, QString::number(value).toLatin1()); +} + +template<> inline void +QHttpAbstractOutput::addHeaderValue(const QByteArray &field, size_t value) { + addHeader(field, QString::number(value).toLatin1()); +} + +template<> inline void +QHttpAbstractOutput::addHeaderValue(const QByteArray &field, QString value) { + addHeader(field, value.toUtf8()); +} + +/////////////////////////////////////////////////////////////////////////////// +} // namespace qhttp +/////////////////////////////////////////////////////////////////////////////// +#endif // QHTTPABSTRACTS_HPP diff --git a/external/qhttp/src/qhttpclient.cpp b/external/qhttp/src/qhttpclient.cpp new file mode 100644 index 0000000..0c97d37 --- /dev/null +++ b/external/qhttp/src/qhttpclient.cpp @@ -0,0 +1,256 @@ +#include "private/qhttpclient_private.hpp" + +#include +/////////////////////////////////////////////////////////////////////////////// +namespace qhttp { +namespace client { +/////////////////////////////////////////////////////////////////////////////// +QHttpClient::QHttpClient(QObject *parent) + : QObject(parent), d_ptr(new QHttpClientPrivate(this)) { + QHTTP_LINE_LOG +} + +QHttpClient::QHttpClient(QHttpClientPrivate &dd, QObject *parent) + : QObject(parent), d_ptr(&dd) { + QHTTP_LINE_LOG +} + +QHttpClient::~QHttpClient() { + QHTTP_LINE_LOG +} + +quint32 +QHttpClient::timeOut() const { + return d_func()->itimeOut; +} + +void +QHttpClient::setTimeOut(quint32 t) { + d_func()->itimeOut = t; +} + +bool +QHttpClient::isOpen() const { + return d_func()->isocket.isOpen(); +} + +void +QHttpClient::killConnection() { + d_func()->isocket.close(); +} + +TBackend +QHttpClient::backendType() const { + return d_func()->isocket.ibackendType; +} + +QTcpSocket* +QHttpClient::tcpSocket() const { + return d_func()->isocket.itcpSocket; +} + +QLocalSocket* +QHttpClient::localSocket() const { + return d_func()->isocket.ilocalSocket; +} + +bool +QHttpClient::request(THttpMethod method, QUrl url, + const TRequstHandler &reqHandler, + const TResponseHandler &resHandler) { + Q_D(QHttpClient); + + d->ireqHandler = nullptr; + d->irespHandler = nullptr; + + // if url is a local file (UNIX socket) the host could be empty! + if ( !url.isValid() || url.isEmpty() /*|| url.host().isEmpty()*/ ) + return false; + + // process handlers + if ( resHandler ) { + d->irespHandler = resHandler; + + if ( reqHandler ) + d->ireqHandler = reqHandler; + else + d->ireqHandler = [](QHttpRequest* req) ->void { + req->addHeader("connection", "close"); + req->end(); + }; + } + + auto requestCreator = [this, method, url]() { + // create request object + if ( d_ptr->ilastRequest ) + d_ptr->ilastRequest->deleteLater(); + + d_ptr->ilastRequest = new QHttpRequest(this); + QObject::connect(d_ptr->ilastRequest, &QHttpRequest::done, [this](bool wasTheLastPacket){ + d_ptr->ikeepAlive = !wasTheLastPacket; + }); + + d_ptr->ilastRequest->d_ptr->imethod = method; + d_ptr->ilastRequest->d_ptr->iurl = url; + }; + + // connecting to host/server must be the last thing. (after all function handlers and ...) + // check for type + if ( url.scheme().toLower() == QLatin1String("file") ) { + d->isocket.ibackendType = ELocalSocket; + d->initializeSocket(); + + requestCreator(); + + if ( d->isocket.isOpen() ) + d->onConnected(); + else + d->isocket.connectTo(url); + + } else { + d->isocket.ibackendType = ETcpSocket; + d->initializeSocket(); + + requestCreator(); + + if ( d->isocket.isOpen() ) + d->onConnected(); + else + d->isocket.connectTo(url.host(), url.port(80)); + } + + + return true; +} + +void +QHttpClient::timerEvent(QTimerEvent *e) { + Q_D(QHttpClient); + + if ( e->timerId() == d->itimer.timerId() ) { + killConnection(); + } +} + +void +QHttpClient::onRequestReady(QHttpRequest *req) { + emit httpConnected(req); +} + +void +QHttpClient::onResponseReady(QHttpResponse *res) { + emit newResponse(res); +} + +/////////////////////////////////////////////////////////////////////////////// + +// if user closes the connection, ends the response or by any other reason +// the socket be disconnected, then the iresponse instance may has been deleted. +// In these situations reading more http body or emitting end() for incoming response +// is not possible. +#define CHECK_FOR_DISCONNECTED if ( ilastResponse == nullptr ) \ + return 0; + + +int +QHttpClientPrivate::messageBegin(http_parser*) { + itempHeaderField.clear(); + itempHeaderValue.clear(); + + return 0; +} + +int +QHttpClientPrivate::status(http_parser* parser, const char* at, size_t length) { + if ( ilastResponse ) + ilastResponse->deleteLater(); + + ilastResponse = new QHttpResponse(q_func()); + ilastResponse->d_func()->istatus = static_cast(parser->status_code); + ilastResponse->d_func()->iversion = QString("%1.%2") + .arg(parser->http_major) + .arg(parser->http_minor); + ilastResponse->d_func()->icustomStatusMessage = QString::fromUtf8(at, length); + + return 0; +} + +int +QHttpClientPrivate::headerField(http_parser*, const char* at, size_t length) { + CHECK_FOR_DISCONNECTED + + // insert the header we parsed previously + // into the header map + if ( !itempHeaderField.isEmpty() && !itempHeaderValue.isEmpty() ) { + // header names are always lower-cased + ilastResponse->d_func()->iheaders.insert( + itempHeaderField.toLower(), + itempHeaderValue.toLower() + ); + // clear header value. this sets up a nice + // feedback loop where the next time + // HeaderValue is called, it can simply append + itempHeaderField.clear(); + itempHeaderValue.clear(); + } + + itempHeaderField.append(at, length); + return 0; +} + +int +QHttpClientPrivate::headerValue(http_parser*, const char* at, size_t length) { + + itempHeaderValue.append(at, length); + return 0; +} + +int +QHttpClientPrivate::headersComplete(http_parser*) { + CHECK_FOR_DISCONNECTED + + // Insert last remaining header + ilastResponse->d_func()->iheaders.insert( + itempHeaderField.toLower(), + itempHeaderValue.toLower() + ); + + if ( irespHandler ) + irespHandler(ilastResponse); + else + q_func()->onResponseReady(ilastResponse); + + return 0; +} + +int +QHttpClientPrivate::body(http_parser*, const char* at, size_t length) { + CHECK_FOR_DISCONNECTED + + ilastResponse->d_func()->ireadState = QHttpResponsePrivate::EPartial; + + if ( ilastResponse->d_func()->shouldCollect() ) { + if ( !ilastResponse->d_func()->append(at, length) ) + onDispatchResponse(); // forcefully dispatch the ilastResponse + + return 0; + } + + emit ilastResponse->data(QByteArray(at, length)); + return 0; +} + +int +QHttpClientPrivate::messageComplete(http_parser*) { + CHECK_FOR_DISCONNECTED + + // response is ready to be dispatched + ilastResponse->d_func()->isuccessful = true; + ilastResponse->d_func()->ireadState = QHttpResponsePrivate::EComplete; + return 0; +} + +/////////////////////////////////////////////////////////////////////////////// +} // namespace client +} // namespace qhttp +/////////////////////////////////////////////////////////////////////////////// diff --git a/external/qhttp/src/qhttpclient.hpp b/external/qhttp/src/qhttpclient.hpp new file mode 100644 index 0000000..cd7642b --- /dev/null +++ b/external/qhttp/src/qhttpclient.hpp @@ -0,0 +1,160 @@ +/** HTTP client class. + * https://github.com/azadkuh/qhttp + * + * @author amir zamani + * @version 2.0.0 + * @date 2014-07-11 + */ + +#ifndef QHTTPCLIENT_HPP +#define QHTTPCLIENT_HPP + +/////////////////////////////////////////////////////////////////////////////// +#include "qhttpfwd.hpp" + +#include +#include + +/////////////////////////////////////////////////////////////////////////////// +namespace qhttp { +namespace client { +/////////////////////////////////////////////////////////////////////////////// +typedef std::function TRequstHandler; +typedef std::function TResponseHandler; + +/** a simple and async HTTP client class which sends a request to an HTTP server and parses the + * corresponding response. + * This class internally handles the memory management and life cycle of QHttpRequest and + * QHttpResponse instances. you do not have to manually delete or keep their pointers. + * in fact the QHttpRequest and QHttpResponse object will be deleted when the internal socket + * disconnects. + */ +class QHTTP_API QHttpClient : public QObject +{ + Q_OBJECT + + Q_PROPERTY(quint32 timeOut READ timeOut WRITE setTimeOut) + +public: + explicit QHttpClient(QObject *parent = nullptr); + + virtual ~QHttpClient(); + + /** tries to connect to a HTTP server. + * when the connection is made, the reqHandler will be called + * and when the response is ready, resHandler will be called. + * @note httpConnected() and newResponse() won't be emitted. + * + * @param method an HTTP method, ex: GET, POST, ... + * @param url specifies server's address, port and optional path and query strings. + * if url starts with socket:// the request will be made on QLocalSocket, otherwise + * normal QTcpSocket will be used. + * @param resHandler response handler (a lambda, std::function object, ...) + * @return true if the url is valid or false (no connection will be made). + */ + bool request(THttpMethod method, QUrl url, + const TRequstHandler& reqHandler, + const TResponseHandler& resHandler); + + /** tries to connect to a HTTP server. + * when the connection is made, a default request handler is called automatically ( + * simply calls req->end()) and when the response is ready, resHandler will be called. + * @note httpConnected() and newResponse() won't be emitted. + * + * @param method an HTTP method, ex: GET, POST, ... + * @param url specifies server's address, port and optional path and query strings. + * @param resHandler response handler (a lambda, std::function object, ...) + * @return true if the url is valid or false (no connection will be made). + */ + inline bool request(THttpMethod method, QUrl url, const TResponseHandler& resHandler) { + return request(method, url, nullptr, resHandler); + } + + /** tries to connect to a HTTP server. + * when the connection is made, creates and emits a QHttpRequest instance + * by @sa httpConnected(QHttpRequest*). + * @note both httpConnected() and newResponse() may be emitted. + * + * @param method an HTTP method, ex: GET, POST, ... + * @param url specifies server's address, port and optional path and query strings. + * @return true if the url is valid or false (no connection will be made). + */ + inline bool request(THttpMethod method, QUrl url) { + return request(method, url, nullptr, nullptr); + } + + /** checks if the connetion to the server is open. */ + bool isOpen() const; + + /** forcefully close the connection. */ + void killConnection(); + + + /** returns time-out value [mSec] for open connections (sockets). + * @sa setTimeOut(). */ + quint32 timeOut()const; + + /** set time-out for new open connections in miliseconds [mSec]. + * each connection will be forcefully closed after this timeout. + * a zero (0) value disables timer for new connections. */ + void setTimeOut(quint32); + + /** returns the backend type of this client. */ + TBackend backendType() const; + + /** returns tcp socket of the connection if backend() == ETcpSocket. */ + QTcpSocket* tcpSocket() const; + + /** returns local socket of the connection if backend() == ELocalSocket. */ + QLocalSocket* localSocket() const; + +signals: + /** emitted when a new HTTP connection to the server is established. + * if you overload onRequestReady this signal won't be emitted. + * @sa onRequestReady + * @sa QHttpRequest + */ + void httpConnected(QHttpRequest* req); + + /** emitted when a new response is received from the server. + * if you overload onResponseReady this signal won't be emitted. + * @sa onResponseReady + * @sa QHttpResponse + */ + void newResponse(QHttpResponse* res); + + /** emitted when the HTTP connection drops or being disconnected. */ + void disconnected(); + + +protected: + /** called when a new HTTP connection is established. + * you can overload this method, the default implementaion only emits connected(). + * @param req use this request instance for assinging the + * request headers and sending optional body. + * @see httpConnected(QHttpRequest*) + */ + virtual void onRequestReady(QHttpRequest* req); + + /** called when a new response is received from the server. + * you can overload this method, the default implementaion only emits newResponse(). + * @param res use this instance for reading incoming response. + * @see newResponse(QHttpResponse*) + */ + virtual void onResponseReady(QHttpResponse* res); + +protected: + explicit QHttpClient(QHttpClientPrivate&, QObject*); + + void timerEvent(QTimerEvent*) override; + + Q_DECLARE_PRIVATE(QHttpClient) + Q_DISABLE_COPY(QHttpClient) + QScopedPointer d_ptr; +}; + +/////////////////////////////////////////////////////////////////////////////// +} // namespace client +} // namespace qhttp +/////////////////////////////////////////////////////////////////////////////// +#endif // define QHTTPCLIENT_HPP diff --git a/external/qhttp/src/qhttpclientrequest.cpp b/external/qhttp/src/qhttpclientrequest.cpp new file mode 100644 index 0000000..50e1d99 --- /dev/null +++ b/external/qhttp/src/qhttpclientrequest.cpp @@ -0,0 +1,98 @@ +#include "private/qhttpclientrequest_private.hpp" +#include "qhttpclient.hpp" +/////////////////////////////////////////////////////////////////////////////// +namespace qhttp { +namespace client { +/////////////////////////////////////////////////////////////////////////////// +QHttpRequest::QHttpRequest(QHttpClient* cli) + : QHttpAbstractOutput(cli) , d_ptr(new QHttpRequestPrivate(cli, this)) { + d_ptr->initialize(); + QHTTP_LINE_LOG +} + +QHttpRequest::QHttpRequest(QHttpRequestPrivate& dd, QHttpClient* cli) + : QHttpAbstractOutput(cli) , d_ptr(&dd) { + d_ptr->initialize(); + QHTTP_LINE_LOG +} + +QHttpRequest::~QHttpRequest() { + QHTTP_LINE_LOG +} + +void +QHttpRequest::setVersion(const QString &versionString) { + d_func()->iversion = versionString; +} + +void +QHttpRequest::addHeader(const QByteArray &field, const QByteArray &value) { + d_func()->addHeader(field, value); +} + +THeaderHash& +QHttpRequest::headers() { + return d_func()->iheaders; +} + +void +QHttpRequest::write(const QByteArray &data) { + d_func()->writeData(data); +} + +void +QHttpRequest::end(const QByteArray &data) { + Q_D(QHttpRequest); + + if ( d->endPacket(data) ) + emit done(!d->ikeepAlive); +} + +QHttpClient* +QHttpRequest::connection() const { + return d_func()->iclient; +} + +/////////////////////////////////////////////////////////////////////////////// +QByteArray +QHttpRequestPrivate::makeTitle() { + + QByteArray title; + title.reserve(512); + title.append(qhttp::Stringify::toString(imethod)) + .append(" "); + + QByteArray path = iurl.path(QUrl::FullyEncoded).toLatin1(); + if ( path.size() == 0 ) + path = "/"; + title.append(path); + + if ( iurl.hasQuery() ) + title.append("?").append(iurl.query(QUrl::FullyEncoded).toLatin1()); + + + title.append(" HTTP/") + .append(iversion.toLatin1()) + .append("\r\n"); + + return title; +} + +void +QHttpRequestPrivate::prepareHeadersToWrite() { + + if ( !iheaders.contains("host") ) { + quint16 port = iurl.port(); + if ( port == 0 ) + port = 80; + + iheaders.insert("host", + QString("%1:%2").arg(iurl.host()).arg(port).toLatin1() + ); + } +} + +/////////////////////////////////////////////////////////////////////////////// +} // namespace client +} // namespace qhttp +/////////////////////////////////////////////////////////////////////////////// diff --git a/external/qhttp/src/qhttpclientrequest.hpp b/external/qhttp/src/qhttpclientrequest.hpp new file mode 100644 index 0000000..6a87506 --- /dev/null +++ b/external/qhttp/src/qhttpclientrequest.hpp @@ -0,0 +1,63 @@ +/** HTTP request from a client. + * https://github.com/azadkuh/qhttp + * + * @author amir zamani + * @version 2.0.0 + * @date 2014-07-11 + */ + +#ifndef QHTTPCLIENT_REQUEST_HPP +#define QHTTPCLIENT_REQUEST_HPP + +/////////////////////////////////////////////////////////////////////////////// +#include "qhttpabstracts.hpp" +#include +/////////////////////////////////////////////////////////////////////////////// +namespace qhttp { +namespace client { +/////////////////////////////////////////////////////////////////////////////// +/** a class for building a new HTTP request. + * the life cycle of this class and the memory management is handled by QHttpClient. + * @sa QHttpClient + */ +class QHTTP_API QHttpRequest : public QHttpAbstractOutput +{ + Q_OBJECT + +public: + virtual ~QHttpRequest(); + +public: // QHttpAbstractOutput methods: + /** @see QHttpAbstractOutput::setVersion(). */ + void setVersion(const QString& versionString) override; + + /** @see QHttpAbstractOutput::addHeader(). */ + void addHeader(const QByteArray& field, const QByteArray& value) override; + + /** @see QHttpAbstractOutput::headers(). */ + THeaderHash& headers() override; + + /** @see QHttpAbstractOutput::write(). */ + void write(const QByteArray &data) override; + + /** @see QHttpAbstractOutput::end(). */ + void end(const QByteArray &data = QByteArray()) override; + +public: + /** returns parent QHttpClient object. */ + QHttpClient* connection() const; + +protected: + explicit QHttpRequest(QHttpClient*); + explicit QHttpRequest(QHttpRequestPrivate&, QHttpClient*); + friend class QHttpClient; + + Q_DECLARE_PRIVATE(QHttpRequest) + QScopedPointer d_ptr; +}; + +/////////////////////////////////////////////////////////////////////////////// +} // namespace client +} // namespace qhttp +/////////////////////////////////////////////////////////////////////////////// +#endif // define QHTTPCLIENT_REQUEST_HPP diff --git a/external/qhttp/src/qhttpclientresponse.cpp b/external/qhttp/src/qhttpclientresponse.cpp new file mode 100644 index 0000000..182d2b0 --- /dev/null +++ b/external/qhttp/src/qhttpclientresponse.cpp @@ -0,0 +1,66 @@ +#include "private/qhttpclientresponse_private.hpp" +#include "qhttpclient.hpp" +/////////////////////////////////////////////////////////////////////////////// +namespace qhttp { +namespace client { +/////////////////////////////////////////////////////////////////////////////// +QHttpResponse::QHttpResponse(QHttpClient *cli) + : QHttpAbstractInput(cli), d_ptr(new QHttpResponsePrivate(cli, this)) { + d_ptr->initialize(); + QHTTP_LINE_LOG +} + +QHttpResponse::QHttpResponse(QHttpResponsePrivate &dd, QHttpClient *cli) + : QHttpAbstractInput(cli), d_ptr(&dd) { + d_ptr->initialize(); + QHTTP_LINE_LOG +} + +QHttpResponse::~QHttpResponse() { + QHTTP_LINE_LOG +} + +TStatusCode +QHttpResponse::status() const { + return d_func()->istatus; +} + +const QString& +QHttpResponse::statusString() const { + return d_func()->icustomStatusMessage; +} + +const QString& +QHttpResponse::httpVersion() const { + return d_func()->iversion; +} + +const THeaderHash& +QHttpResponse::headers() const { + return d_func()->iheaders; +} + +bool +QHttpResponse::isSuccessful() const { + return d_func()->isuccessful; +} + +void +QHttpResponse::collectData(int atMost) { + d_func()->collectData(atMost); +} + +const QByteArray& +QHttpResponse::collectedData() const { + return d_func()->icollectedData; +} + +QHttpClient* +QHttpResponse::connection() const { + return d_func()->iclient; +} + +/////////////////////////////////////////////////////////////////////////////// +} // namespace client +} // namespace qhttp +/////////////////////////////////////////////////////////////////////////////// diff --git a/external/qhttp/src/qhttpclientresponse.hpp b/external/qhttp/src/qhttpclientresponse.hpp new file mode 100644 index 0000000..37024f0 --- /dev/null +++ b/external/qhttp/src/qhttpclientresponse.hpp @@ -0,0 +1,73 @@ +/** HTTP response received by client. + * https://github.com/azadkuh/qhttp + * + * @author amir zamani + * @version 2.0.0 + * @date 2014-07-11 + */ + +#ifndef QHTTPCLIENT_RESPONSE_HPP +#define QHTTPCLIENT_RESPONSE_HPP +/////////////////////////////////////////////////////////////////////////////// + +#include "qhttpabstracts.hpp" + +#include +/////////////////////////////////////////////////////////////////////////////// +namespace qhttp { +namespace client { +/////////////////////////////////////////////////////////////////////////////// +/** a class for reading incoming HTTP response from a server. + * the life cycle of this class and the memory management is handled by QHttpClient. + * @sa QHttpClient + */ +class QHTTP_API QHttpResponse : public QHttpAbstractInput +{ + Q_OBJECT + +public: + virtual ~QHttpResponse(); + +public: // QHttpAbstractInput methods: + /** @see QHttpAbstractInput::headers(). */ + const THeaderHash& headers() const override; + + /** @see QHttpAbstractInput::httpVersion(). */ + const QString& httpVersion() const override; + + /** @see QHttpAbstractInput::isSuccessful(). */ + bool isSuccessful() const override; + + /** @see QHttpAbstractInput::collectData(). */ + void collectData(int atMost = -1) override; + + /** @see QHttpAbstractInput::collectedData(). */ + const QByteArray& collectedData()const override; + + +public: + /** The status code of this response. */ + TStatusCode status() const ; + + /** The server status message as string. + * may be slightly different than: @code qhttp::Stringify::toString(status()); @endcode + * depending on implementation of HTTP server. */ + const QString& statusString() const; + + /** returns parent QHttpClient object. */ + QHttpClient* connection() const; + +protected: + explicit QHttpResponse(QHttpClient*); + explicit QHttpResponse(QHttpResponsePrivate&, QHttpClient*); + friend class QHttpClientPrivate; + + Q_DECLARE_PRIVATE(QHttpResponse) + QScopedPointer d_ptr; +}; + +/////////////////////////////////////////////////////////////////////////////// +} // namespace client +} // namespace qhttp +/////////////////////////////////////////////////////////////////////////////// +#endif // define QHTTPCLIENT_RESPONSE_HPP diff --git a/external/qhttp/src/qhttpfwd.hpp b/external/qhttp/src/qhttpfwd.hpp new file mode 100644 index 0000000..188c942 --- /dev/null +++ b/external/qhttp/src/qhttpfwd.hpp @@ -0,0 +1,197 @@ +/** forward declarations and general definitions of the QHttp. + * https://github.com/azadkuh/qhttp + * + * @author amir zamani + * @version 2.0.0 + * @date 2014-07-11 + */ + +#ifndef QHTTPFWD_HPP +#define QHTTPFWD_HPP +/////////////////////////////////////////////////////////////////////////////// +#include +#include +#include + +#include +/////////////////////////////////////////////////////////////////////////////// +// Qt +class QTcpServer; +class QTcpSocket; +class QLocalServer; +class QLocalSocket; + +// http_parser +struct http_parser_settings; +struct http_parser; + +/////////////////////////////////////////////////////////////////////////////// +namespace qhttp { +/////////////////////////////////////////////////////////////////////////////// + +/** A map of request or response headers. */ +class THeaderHash : public QHash +{ +public: + /** checks for a header item, regardless of the case of the characters. */ + inline bool has(const QByteArray& key) const { + return contains(key.toLower()); + } + + /** checks if a header has the specified value ignoring the case of the characters. */ + inline bool keyHasValue(const QByteArray& key, const QByteArray& value) const { + if ( !contains(key) ) + return false; + + const QByteArray& v = QHash::value(key); + return qstrnicmp(value.constData(), v.constData(), v.size()) == 0; + } +}; + +/** Request method enumeration. + * @note Taken from http_parser.h */ +enum THttpMethod { + EHTTP_DELETE = 0, ///< DELETE + EHTTP_GET = 1, ///< GET + EHTTP_HEAD = 2, ///< HEAD + EHTTP_POST = 3, ///< POST + EHTTP_PUT = 4, ///< PUT + /* pathological */ + EHTTP_CONNECT = 5, ///< CONNECT + EHTTP_OPTIONS = 6, ///< OPTIONS + EHTTP_TRACE = 7, ///< TRACE + /* webdav */ + EHTTP_COPY = 8, ///< COPY + EHTTP_LOCK = 9, ///< LOCK + EHTTP_MKCOL = 10, ///< MKCOL + EHTTP_MOVE = 11, ///< MOVE + EHTTP_PROPFIND = 12, ///< PROPFIND + EHTTP_PROPPATCH = 13, ///< PROPPATCH + EHTTP_SEARCH = 14, ///< SEARCH + EHTTP_UNLOCK = 15, ///< UNLOCK + /* subversion */ + EHTTP_REPORT = 16, ///< REPORT + EHTTP_MKACTIVITY = 17, ///< MKACTIVITY + EHTTP_CHECKOUT = 18, ///< CHECKOUT + EHTTP_MERGE = 19, ///< MERGE + /* upnp */ + EHTTP_MSEARCH = 20, ///< M-SEARCH + EHTTP_NOTIFY = 21, ///< NOTIFY + EHTTP_SUBSCRIBE = 22, ///< SUBSCRIBE + EHTTP_UNSUBSCRIBE = 23, ///< UNSUBSCRIBE + /* RFC-5789 */ + EHTTP_PATCH = 24, ///< PATCH + EHTTP_PURGE = 25, ///< PURGE +}; + +/** HTTP status codes. */ +enum TStatusCode { + ESTATUS_CONTINUE = 100, + ESTATUS_SWITCH_PROTOCOLS = 101, + ESTATUS_OK = 200, + ESTATUS_CREATED = 201, + ESTATUS_ACCEPTED = 202, + ESTATUS_NON_AUTHORITATIVE_INFORMATION = 203, + ESTATUS_NO_CONTENT = 204, + ESTATUS_RESET_CONTENT = 205, + ESTATUS_PARTIAL_CONTENT = 206, + ESTATUS_MULTI_STATUS = 207, + ESTATUS_MULTIPLE_CHOICES = 300, + ESTATUS_MOVED_PERMANENTLY = 301, + ESTATUS_FOUND = 302, + ESTATUS_SEE_OTHER = 303, + ESTATUS_NOT_MODIFIED = 304, + ESTATUS_USE_PROXY = 305, + ESTATUS_TEMPORARY_REDIRECT = 307, + ESTATUS_BAD_REQUEST = 400, + ESTATUS_UNAUTHORIZED = 401, + ESTATUS_PAYMENT_REQUIRED = 402, + ESTATUS_FORBIDDEN = 403, + ESTATUS_NOT_FOUND = 404, + ESTATUS_METHOD_NOT_ALLOWED = 405, + ESTATUS_NOT_ACCEPTABLE = 406, + ESTATUS_PROXY_AUTHENTICATION_REQUIRED = 407, + ESTATUS_REQUEST_TIMEOUT = 408, + ESTATUS_CONFLICT = 409, + ESTATUS_GONE = 410, + ESTATUS_LENGTH_REQUIRED = 411, + ESTATUS_PRECONDITION_FAILED = 412, + ESTATUS_REQUEST_ENTITY_TOO_LARGE = 413, + ESTATUS_REQUEST_URI_TOO_LONG = 414, + ESTATUS_REQUEST_UNSUPPORTED_MEDIA_TYPE = 415, + ESTATUS_REQUESTED_RANGE_NOT_SATISFIABLE = 416, + ESTATUS_EXPECTATION_FAILED = 417, + ESTATUS_INTERNAL_SERVER_ERROR = 500, + ESTATUS_NOT_IMPLEMENTED = 501, + ESTATUS_BAD_GATEWAY = 502, + ESTATUS_SERVICE_UNAVAILABLE = 503, + ESTATUS_GATEWAY_TIMEOUT = 504, + ESTATUS_HTTP_VERSION_NOT_SUPPORTED = 505 +}; + +/** The backend of QHttp library. */ +enum TBackend { + ETcpSocket = 0, ///< client / server work on top of TCP/IP stack. (default) + ESslSocket = 1, ///< client / server work on SSL/TLS tcp stack. (not implemented yet) + ELocalSocket = 2 ///< client / server work on local socket (unix socket). +}; + +/////////////////////////////////////////////////////////////////////////////// +namespace server { +/////////////////////////////////////////////////////////////////////////////// +class QHttpServer; +class QHttpConnection; +class QHttpRequest; +class QHttpResponse; + +// Privte classes +class QHttpServerPrivate; +class QHttpConnectionPrivate; +class QHttpRequestPrivate; +class QHttpResponsePrivate; + +typedef std::function TServerHandler; + +/////////////////////////////////////////////////////////////////////////////// +} // namespace server +/////////////////////////////////////////////////////////////////////////////// +namespace client { +/////////////////////////////////////////////////////////////////////////////// +class QHttpClient; +class QHttpRequest; +class QHttpResponse; + +// Private classes +class QHttpClientPrivate; +class QHttpRequestPrivate; +class QHttpResponsePrivate; +/////////////////////////////////////////////////////////////////////////////// +} // namespace client +/////////////////////////////////////////////////////////////////////////////// +#ifdef Q_OS_WIN +# if defined(QHTTP_EXPORT) +# define QHTTP_API __declspec(dllexport) +# else +# define QHTTP_API __declspec(dllimport) +# endif +#else +# define QHTTP_API +#endif + + +#if QHTTP_MEMORY_LOG > 0 +# define QHTTP_LINE_LOG fprintf(stderr, "%s(): obj = %p @ %s[%d]\n",\ + __FUNCTION__, this, __FILE__, __LINE__); +#else +# define QHTTP_LINE_LOG +#endif + +#if QHTTP_MEMORY_LOG > 1 +# define QHTTP_LINE_DEEPLOG QHTTP_LINE_LOG +#else +# define QHTTP_LINE_DEEPLOG +#endif +/////////////////////////////////////////////////////////////////////////////// +} // namespace qhttp +/////////////////////////////////////////////////////////////////////////////// +#endif // define QHTTPFWD_HPP diff --git a/external/qhttp/src/qhttpserver.cpp b/external/qhttp/src/qhttpserver.cpp new file mode 100644 index 0000000..fb126ec --- /dev/null +++ b/external/qhttp/src/qhttpserver.cpp @@ -0,0 +1,118 @@ +#include "private/qhttpserver_private.hpp" + +/////////////////////////////////////////////////////////////////////////////// +namespace qhttp { +namespace server { +/////////////////////////////////////////////////////////////////////////////// + +QHttpServer::QHttpServer(QObject *parent) + : QObject(parent), d_ptr(new QHttpServerPrivate) { +} + +QHttpServer::QHttpServer(QHttpServerPrivate &dd, QObject *parent) + : QObject(parent), d_ptr(&dd) { +} + +QHttpServer::~QHttpServer() { + stopListening(); +} + +bool +QHttpServer::listen(const QString &socketOrPort, const TServerHandler &handler) { + Q_D(QHttpServer); + + bool isNumber = false; + quint16 tcpPort = socketOrPort.toUShort(&isNumber); + if ( isNumber && tcpPort > 0 ) + return listen(QHostAddress::Any, tcpPort, handler); + + d->initialize(ELocalSocket, this); + d->ihandler = handler; + return d->ilocalServer->listen(socketOrPort); +} + +bool +QHttpServer::listen(const QHostAddress& address, quint16 port, const qhttp::server::TServerHandler& handler) { + Q_D(QHttpServer); + + d->initialize(ETcpSocket, this); + d->ihandler = handler; + return d->itcpServer->listen(address, port); +} + +bool +QHttpServer::isListening() const { + const Q_D(QHttpServer); + + if ( d->ibackend == ETcpSocket && d->itcpServer ) + return d->itcpServer->isListening(); + + else if ( d->ibackend == ELocalSocket && d->ilocalServer ) + return d->ilocalServer->isListening(); + + return false; +} + +void +QHttpServer::stopListening() { + Q_D(QHttpServer); + + if ( d->itcpServer ) + d->itcpServer->close(); + + if ( d->ilocalServer ) { + d->ilocalServer->close(); + QLocalServer::removeServer( d->ilocalServer->fullServerName() ); + } +} + +quint32 +QHttpServer::timeOut() const { + return d_func()->itimeOut; +} + +void +QHttpServer::setTimeOut(quint32 newValue) { + d_func()->itimeOut = newValue; +} + +TBackend +QHttpServer::backendType() const { + return d_func()->ibackend; +} + +QTcpServer* +QHttpServer::tcpServer() const { + return d_func()->itcpServer.data(); +} + +QLocalServer* +QHttpServer::localServer() const { + return d_func()->ilocalServer.data(); +} + +void +QHttpServer::incomingConnection(qintptr handle) { + QHttpConnection* conn = new QHttpConnection(this); + conn->setSocketDescriptor(handle, backendType()); + conn->setTimeOut(d_func()->itimeOut); + + emit newConnection(conn); + + Q_D(QHttpServer); + if ( d->ihandler ) + QObject::connect(conn, &QHttpConnection::newRequest, d->ihandler); + else + incomingConnection(conn); +} + +void +QHttpServer::incomingConnection(QHttpConnection *connection) { + QObject::connect(connection, &QHttpConnection::newRequest, + this, &QHttpServer::newRequest); +} + +/////////////////////////////////////////////////////////////////////////////// +} // namespace server +} // namespace qhttp +/////////////////////////////////////////////////////////////////////////////// diff --git a/external/qhttp/src/qhttpserver.hpp b/external/qhttp/src/qhttpserver.hpp new file mode 100644 index 0000000..4e492e3 --- /dev/null +++ b/external/qhttp/src/qhttpserver.hpp @@ -0,0 +1,131 @@ +/** HTTP server class. + * https://github.com/azadkuh/qhttp + * + * @author amir zamani + * @version 2.0.0 + * @date 2014-07-11 + */ + +#ifndef QHTTPSERVER_HPP +#define QHTTPSERVER_HPP + +/////////////////////////////////////////////////////////////////////////////// +#include "qhttpfwd.hpp" + +#include +#include +/////////////////////////////////////////////////////////////////////////////// +namespace qhttp { +namespace server { +/////////////////////////////////////////////////////////////////////////////// + +/** The QHttpServer class is a fast, async (non-blocking) HTTP server. */ +class QHTTP_API QHttpServer : public QObject +{ + Q_OBJECT + + Q_PROPERTY(quint32 timeOut READ timeOut WRITE setTimeOut) + +public: + /** construct a new HTTP Server. */ + explicit QHttpServer(QObject *parent = nullptr); + + virtual ~QHttpServer(); + + /** starts a TCP or Local (unix domain socket) server. + * if you provide a server handler, the newRequest() signal won't be emitted. + * + * @param socketOrPort could be a tcp port number as "8080" or a unix socket name as + * "/tmp/sample.socket" or "sample.socket". + * @param handler optional server handler (a lambda, std::function, ...) + * @return false if listening fails. + */ + bool listen(const QString& socketOrPort, + const TServerHandler& handler = nullptr); + + /** starts a TCP server on specified address and port. + * if you provide a server handler, the newRequest() signal won't be emitted. + * + * @param address listening address as QHostAddress::Any. + * @param port listening port. + * @param handler optional server handler (a lambda, std::function, ...) + * @return false if listening fails. + */ + bool listen(const QHostAddress& address, quint16 port, + const TServerHandler& handler = nullptr); + + /** @overload listen() */ + bool listen(quint16 port) { + return listen(QHostAddress::Any, port); + } + + /** returns true if server successfully listens. @sa listen() */ + bool isListening() const; + + /** closes the server and stops from listening. */ + void stopListening(); + + /** returns timeout value [mSec] for open connections (sockets). + * @sa setTimeOut(). */ + quint32 timeOut()const; + + /** set time-out for new open connections in miliseconds [mSec]. + * new incoming connections will be forcefully closed after this time out. + * a zero (0) value disables timer for new connections. */ + void setTimeOut(quint32); + + /** returns the QHttpServer's backend type. */ + TBackend backendType() const; + +signals: + /** emitted when a client makes a new request to the server if you do not override + * incomingConnection(QHttpConnection *connection); + * @sa incommingConnection(). */ + void newRequest(QHttpRequest *request, QHttpResponse *response); + + /** emitted when a new connection comes to the server if you do not override + * incomingConnection(QHttpConnection *connection); + * @sa incomingConnection(); */ + void newConnection(QHttpConnection* connection); + +protected: + /** returns the tcp server instance if the backend() == ETcpSocket. */ + QTcpServer* tcpServer() const; + + /** returns the local server instance if the backend() == ELocalSocket. */ + QLocalServer* localServer() const; + + + /** is called when server accepts a new connection. + * you can override this function for using a thread-pool or ... some other reasons. + * + * the default implementation just connects QHttpConnection::newRequest signal. + * @note if you override this method, the signal won't be emitted by QHttpServer. + * (perhaps, you do not need it anymore). + * + * @param connection New incoming connection. */ + virtual void incomingConnection(QHttpConnection* connection); + + /** overrides QTcpServer::incomingConnection() to make a new QHttpConnection. + * override this function if you like to create your derived QHttpConnection instances. + * + * @note if you override this method, incomingConnection(QHttpConnection*) or + * newRequest(QHttpRequest *, QHttpResponse *) signal won't be called. + * + * @see example/benchmark/server.cpp to see how to override. + */ + virtual void incomingConnection(qintptr handle); + +private: + explicit QHttpServer(QHttpServerPrivate&, QObject *parent); + + Q_DECLARE_PRIVATE(QHttpServer) + Q_DISABLE_COPY(QHttpServer) + QScopedPointer d_ptr; +}; + +/////////////////////////////////////////////////////////////////////////////// +} // namespace server +} // namespace qhttp +/////////////////////////////////////////////////////////////////////////////// +#endif // define QHTTPSERVER_HPP diff --git a/external/qhttp/src/qhttpserverconnection.cpp b/external/qhttp/src/qhttpserverconnection.cpp new file mode 100644 index 0000000..8cea69f --- /dev/null +++ b/external/qhttp/src/qhttpserverconnection.cpp @@ -0,0 +1,271 @@ +#include "private/qhttpserverconnection_private.hpp" + +/////////////////////////////////////////////////////////////////////////////// +namespace qhttp { +namespace server { +/////////////////////////////////////////////////////////////////////////////// +QHttpConnection::QHttpConnection(QObject *parent) + : QObject(parent), d_ptr(new QHttpConnectionPrivate(this)) { + QHTTP_LINE_LOG +} + +QHttpConnection::QHttpConnection(QHttpConnectionPrivate& dd, QObject* parent) + : QObject(parent), d_ptr(&dd) { + QHTTP_LINE_LOG +} + +void +QHttpConnection::setSocketDescriptor(qintptr sokDescriptor, TBackend backendType) { + d_ptr->createSocket(sokDescriptor, backendType); +} + +QHttpConnection::~QHttpConnection() { + QHTTP_LINE_LOG +} + +void +QHttpConnection::setTimeOut(quint32 miliSeconds) { + if ( miliSeconds != 0 ) { + d_func()->itimeOut = miliSeconds; + d_func()->itimer.start(miliSeconds, Qt::CoarseTimer, this); + } +} + +void +QHttpConnection::killConnection() { + d_func()->isocket.close(); +} + +TBackend +QHttpConnection::backendType() const { + return d_func()->isocket.ibackendType; +} + +QTcpSocket* +QHttpConnection::tcpSocket() const { + return d_func()->isocket.itcpSocket; +} + +QLocalSocket* +QHttpConnection::localSocket() const { + return d_func()->isocket.ilocalSocket; +} + +void +QHttpConnection::onHandler(const TServerHandler &handler) { + d_func()->ihandler = handler; +} + +void +QHttpConnection::timerEvent(QTimerEvent *) { + killConnection(); +} + +/////////////////////////////////////////////////////////////////////////////// + +// if user closes the connection, ends the response or by any other reason +// the socket be disconnected, then the irequest and iresponse instances may bhave been deleted. +// In these situations reading more http body or emitting end() for incoming request +// are not possible. +#define CHECK_FOR_DISCONNECTED if ( ilastRequest == nullptr ) \ + return 0; + + +int +QHttpConnectionPrivate::messageBegin(http_parser*) { + itempUrl.clear(); + itempUrl.reserve(128); + + if ( ilastRequest ) + ilastRequest->deleteLater(); + + ilastRequest = new QHttpRequest(q_func()); + return 0; +} + +int +QHttpConnectionPrivate::url(http_parser*, const char* at, size_t length) { + Q_ASSERT(ilastRequest); + + itempUrl.append(at, length); + return 0; +} + +int +QHttpConnectionPrivate::headerField(http_parser*, const char* at, size_t length) { + CHECK_FOR_DISCONNECTED + + // insert the header we parsed previously + // into the header map + if ( !itempHeaderField.isEmpty() && !itempHeaderValue.isEmpty() ) { + // header names are always lower-cased + ilastRequest->d_func()->iheaders.insert( + itempHeaderField.toLower(), + itempHeaderValue.toLower() + ); + // clear header value. this sets up a nice + // feedback loop where the next time + // HeaderValue is called, it can simply append + itempHeaderField.clear(); + itempHeaderValue.clear(); + } + + itempHeaderField.append(at, length); + return 0; +} + +int +QHttpConnectionPrivate::headerValue(http_parser*, const char* at, size_t length) { + CHECK_FOR_DISCONNECTED + + itempHeaderValue.append(at, length); + return 0; +} + +int +QHttpConnectionPrivate::headersComplete(http_parser* parser) { + CHECK_FOR_DISCONNECTED + +#if defined(USE_CUSTOM_URL_CREATOR) + // get parsed url + struct http_parser_url urlInfo; + int r = http_parser_parse_url(itempUrl.constData(), + itempUrl.size(), + parser->method == HTTP_CONNECT, + &urlInfo); + Q_ASSERT(r == 0); + Q_UNUSED(r); + + ilastRequest->d_func()->iurl = createUrl( + itempUrl.constData(), + urlInfo + ); +#else + ilastRequest->d_func()->iurl = QUrl(itempUrl); +#endif // defined(USE_CUSTOM_URL_CREATOR) + + // set method + ilastRequest->d_func()->imethod = + static_cast(parser->method); + + // set version + ilastRequest->d_func()->iversion = QString("%1.%2") + .arg(parser->http_major) + .arg(parser->http_minor); + + // Insert last remaining header + ilastRequest->d_func()->iheaders.insert( + itempHeaderField.toLower(), + itempHeaderValue.toLower() + ); + + // set client information + if ( isocket.ibackendType == ETcpSocket ) { + ilastRequest->d_func()->iremoteAddress = isocket.itcpSocket->peerAddress().toString(); + ilastRequest->d_func()->iremotePort = isocket.itcpSocket->peerPort(); + + } else if ( isocket.ibackendType == ELocalSocket ) { + ilastRequest->d_func()->iremoteAddress = isocket.ilocalSocket->fullServerName(); + ilastRequest->d_func()->iremotePort = 0; // not used in local sockets + } + + if ( ilastResponse ) + ilastResponse->deleteLater(); + ilastResponse = new QHttpResponse(q_func()); + + if ( parser->http_major < 1 || parser->http_minor < 1 ) + ilastResponse->d_func()->ikeepAlive = false; + + // close the connection if response was the last packet + QObject::connect(ilastResponse, &QHttpResponse::done, [this](bool wasTheLastPacket){ + ikeepAlive = !wasTheLastPacket; + if ( wasTheLastPacket ) { + isocket.flush(); + isocket.close(); + } + }); + + // we are good to go! + if ( ihandler ) + ihandler(ilastRequest, ilastResponse); + else + emit q_ptr->newRequest(ilastRequest, ilastResponse); + + return 0; +} + +int +QHttpConnectionPrivate::body(http_parser*, const char* at, size_t length) { + CHECK_FOR_DISCONNECTED + + ilastRequest->d_func()->ireadState = QHttpRequestPrivate::EPartial; + + if ( ilastRequest->d_func()->shouldCollect() ) { + if ( !ilastRequest->d_func()->append(at, length) ) + onDispatchRequest(); // forcefully dispatch the ilastRequest + + return 0; + } + + emit ilastRequest->data(QByteArray(at, length)); + return 0; +} + +int +QHttpConnectionPrivate::messageComplete(http_parser*) { + CHECK_FOR_DISCONNECTED + + // request is ready to be dispatched + ilastRequest->d_func()->isuccessful = true; + ilastRequest->d_func()->ireadState = QHttpRequestPrivate::EComplete; + return 0; +} + + + +/////////////////////////////////////////////////////////////////////////////// +#if defined(USE_CUSTOM_URL_CREATOR) +/////////////////////////////////////////////////////////////////////////////// +/* URL Utilities */ +#define HAS_URL_FIELD(info, field) (info.field_set &(1 << (field))) + +#define GET_FIELD(data, info, field) \ + QString::fromLatin1(data + info.field_data[field].off, info.field_data[field].len) + +#define CHECK_AND_GET_FIELD(data, info, field) \ + (HAS_URL_FIELD(info, field) ? GET_FIELD(data, info, field) : QString()) + +QUrl +QHttpConnectionPrivate::createUrl(const char *urlData, const http_parser_url &urlInfo) { + QUrl url; + url.setScheme(CHECK_AND_GET_FIELD(urlData, urlInfo, UF_SCHEMA)); + url.setHost(CHECK_AND_GET_FIELD(urlData, urlInfo, UF_HOST)); + // Port is dealt with separately since it is available as an integer. + url.setPath(CHECK_AND_GET_FIELD(urlData, urlInfo, UF_PATH)); +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) + url.setQuery(CHECK_AND_GET_FIELD(urlData, urlInfo, UF_QUERY)); +#else + if (HAS_URL_FIELD(urlInfo, UF_QUERY)) { + url.setEncodedQuery(QByteArray(urlData + urlInfo.field_data[UF_QUERY].off, + urlInfo.field_data[UF_QUERY].len)); + } +#endif + url.setFragment(CHECK_AND_GET_FIELD(urlData, urlInfo, UF_FRAGMENT)); + url.setUserInfo(CHECK_AND_GET_FIELD(urlData, urlInfo, UF_USERINFO)); + + if (HAS_URL_FIELD(urlInfo, UF_PORT)) + url.setPort(urlInfo.port); + + return url; +} + +#undef CHECK_AND_SET_FIELD +#undef GET_FIELD +#undef HAS_URL_FIELD +/////////////////////////////////////////////////////////////////////////////// +#endif // defined(USE_CUSTOM_URL_CREATOR) + +/////////////////////////////////////////////////////////////////////////////// +} // namespace server +} // namespace qhttp +/////////////////////////////////////////////////////////////////////////////// diff --git a/external/qhttp/src/qhttpserverconnection.hpp b/external/qhttp/src/qhttpserverconnection.hpp new file mode 100644 index 0000000..b908665 --- /dev/null +++ b/external/qhttp/src/qhttpserverconnection.hpp @@ -0,0 +1,87 @@ +/** HTTP connection class. + * https://github.com/azadkuh/qhttp + * + * @author amir zamani + * @version 2.0.0 + * @date 2014-07-11 + */ + +#ifndef QHTTPSERVER_CONNECTION_HPP +#define QHTTPSERVER_CONNECTION_HPP +/////////////////////////////////////////////////////////////////////////////// +#include "qhttpfwd.hpp" + +#include + +/////////////////////////////////////////////////////////////////////////////// +namespace qhttp { +namespace server { +/////////////////////////////////////////////////////////////////////////////// +/** a HTTP connection in the server. + * this class controls the HTTP connetion and handles life cycle and the memory management + * of QHttpRequest and QHttpResponse instances autoamtically. + */ +class QHTTP_API QHttpConnection : public QObject +{ + Q_OBJECT + +public: + virtual ~QHttpConnection(); + + /** set an optional timer event to close the connection. */ + void setTimeOut(quint32 miliSeconds); + + /** forcefully kills (closes) a connection. */ + void killConnection(); + + /** optionally set a handler for connection class. + * @note if you set this handler, the newRequest() signal won't be emitted. + */ + void onHandler(const TServerHandler& handler); + + /** returns the backend type of the connection. */ + TBackend backendType() const; + + /** returns connected socket if the backend() == ETcpSocket. */ + QTcpSocket* tcpSocket() const; + + /** returns connected socket if the backend() == ELocalSocket. */ + QLocalSocket* localSocket() const; + + /** creates a new QHttpConnection based on arguments. */ + static + QHttpConnection* create(qintptr sokDescriptor, TBackend backendType, QObject* parent) { + QHttpConnection* conn = new QHttpConnection(parent); + conn->setSocketDescriptor(sokDescriptor, backendType); + return conn; + } + +signals: + /** emitted when a pair of HTTP request and response are ready to interact. + * @param req incoming request by the client. + * @param res outgoing response to the client. + */ + void newRequest(QHttpRequest* req, QHttpResponse* res); + + /** emitted when the tcp/local socket, disconnects. */ + void disconnected(); + +protected: + explicit QHttpConnection(QObject *parent); + explicit QHttpConnection(QHttpConnectionPrivate&, QObject *); + + void setSocketDescriptor(qintptr sokDescriptor, TBackend backendType); + void timerEvent(QTimerEvent*) override; + + Q_DISABLE_COPY(QHttpConnection) + Q_DECLARE_PRIVATE(QHttpConnection) + QScopedPointer d_ptr; + + friend class QHttpServer; +}; + +/////////////////////////////////////////////////////////////////////////////// +} // namespace server +} // namespace qhttp +/////////////////////////////////////////////////////////////////////////////// +#endif // #define QHTTPSERVER_CONNECTION_HPP diff --git a/external/qhttp/src/qhttpserverrequest.cpp b/external/qhttp/src/qhttpserverrequest.cpp new file mode 100644 index 0000000..87787fa --- /dev/null +++ b/external/qhttp/src/qhttpserverrequest.cpp @@ -0,0 +1,81 @@ +#include "private/qhttpserverrequest_private.hpp" + +/////////////////////////////////////////////////////////////////////////////// +namespace qhttp { +namespace server { +/////////////////////////////////////////////////////////////////////////////// +QHttpRequest::QHttpRequest(QHttpConnection *conn) + : QHttpAbstractInput(conn), d_ptr(new QHttpRequestPrivate(conn, this)) { + d_ptr->initialize(); + QHTTP_LINE_LOG +} + +QHttpRequest::QHttpRequest(QHttpRequestPrivate &dd, QHttpConnection *conn) + : QHttpAbstractInput(conn), d_ptr(&dd) { + d_ptr->initialize(); + QHTTP_LINE_LOG +} + +QHttpRequest::~QHttpRequest() { + QHTTP_LINE_LOG +} + +THttpMethod +QHttpRequest::method() const { + return d_func()->imethod; +} + +const QString +QHttpRequest::methodString() const { + return http_method_str(static_cast(d_func()->imethod)); +} + +const QUrl& +QHttpRequest::url() const { + return d_func()->iurl; +} + +const QString& +QHttpRequest::httpVersion() const { + return d_func()->iversion; +} + +const THeaderHash& +QHttpRequest::headers() const { + return d_func()->iheaders; +} + +const QString& +QHttpRequest::remoteAddress() const { + return d_func()->iremoteAddress; +} + +quint16 +QHttpRequest::remotePort() const { + return d_func()->iremotePort; +} + +bool +QHttpRequest::isSuccessful() const { + return d_func()->isuccessful; +} + +void +QHttpRequest::collectData(int atMost) { + d_func()->collectData(atMost); +} + +const QByteArray& +QHttpRequest::collectedData() const { + return d_func()->icollectedData; +} + +QHttpConnection* +QHttpRequest::connection() const { + return d_ptr->iconnection; +} + +/////////////////////////////////////////////////////////////////////////////// +} // namespace server +} // namespace qhttp +/////////////////////////////////////////////////////////////////////////////// diff --git a/external/qhttp/src/qhttpserverrequest.hpp b/external/qhttp/src/qhttpserverrequest.hpp new file mode 100644 index 0000000..4001c71 --- /dev/null +++ b/external/qhttp/src/qhttpserverrequest.hpp @@ -0,0 +1,82 @@ +/** HTTP request which is received by the server. + * https://github.com/azadkuh/qhttp + * + * @author amir zamani + * @version 2.0.0 + * @date 2014-07-11 + */ + +#ifndef QHTTPSERVER_REQUEST_HPP +#define QHTTPSERVER_REQUEST_HPP +/////////////////////////////////////////////////////////////////////////////// + +#include "qhttpabstracts.hpp" + +#include +/////////////////////////////////////////////////////////////////////////////// +namespace qhttp { +namespace server { +/////////////////////////////////////////////////////////////////////////////// +/** The QHttpRequest class represents the header and body data sent by the client. + * The class is read-only. + * @sa QHttpConnection + */ +class QHTTP_API QHttpRequest : public QHttpAbstractInput +{ + Q_OBJECT + +public: + virtual ~QHttpRequest(); + +public: // QHttpAbstractInput methods: + /** @see QHttpAbstractInput::headers(). */ + const THeaderHash& headers() const override; + + /** @see QHttpAbstractInput::httpVersion(). */ + const QString& httpVersion() const override; + + /** @see QHttpAbstractInput::isSuccessful(). */ + bool isSuccessful() const override; + + /** @see QHttpAbstractInput::collectData(). */ + void collectData(int atMost = -1) override; + + /** @see QHttpAbstractInput::collectedData(). */ + const QByteArray& collectedData()const override; + + +public: + /** The method used for the request. */ + THttpMethod method() const ; + + /** Returns the method string for the request. + * @note This will plainly transform the enum into a string HTTP_GET -> "HTTP_GET". */ + const QString methodString() const; + + /** The complete URL for the request. + * This includes the path and query string. @sa path(). */ + const QUrl& url() const; + + /** IP Address of the client in dotted decimal format. */ + const QString& remoteAddress() const; + + /** Outbound connection port for the client. */ + quint16 remotePort() const; + + /** returns the parent QHttpConnection object. */ + QHttpConnection* connection() const; + +protected: + explicit QHttpRequest(QHttpConnection*); + explicit QHttpRequest(QHttpRequestPrivate&, QHttpConnection*); + friend class QHttpConnectionPrivate; + + Q_DECLARE_PRIVATE(QHttpRequest) + QScopedPointer d_ptr; +}; + +/////////////////////////////////////////////////////////////////////////////// +} // namespace server +} // namespace qhttp +/////////////////////////////////////////////////////////////////////////////// +#endif // define QHTTPSERVER_REQUEST_HPP diff --git a/external/qhttp/src/qhttpserverresponse.cpp b/external/qhttp/src/qhttpserverresponse.cpp new file mode 100644 index 0000000..5e60746 --- /dev/null +++ b/external/qhttp/src/qhttpserverresponse.cpp @@ -0,0 +1,90 @@ +#include "private/qhttpserverresponse_private.hpp" + +/////////////////////////////////////////////////////////////////////////////// +namespace qhttp { +namespace server { +/////////////////////////////////////////////////////////////////////////////// +QHttpResponse::QHttpResponse(QHttpConnection* conn) + : QHttpAbstractOutput(conn) , d_ptr(new QHttpResponsePrivate(conn, this)) { + d_ptr->initialize(); + QHTTP_LINE_LOG +} + +QHttpResponse::QHttpResponse(QHttpResponsePrivate& dd, QHttpConnection* conn) + : QHttpAbstractOutput(conn) , d_ptr(&dd) { + d_ptr->initialize(); + QHTTP_LINE_LOG +} + +QHttpResponse::~QHttpResponse() { + QHTTP_LINE_LOG +} + +void +QHttpResponse::setStatusCode(TStatusCode code) { + d_func()->istatus = code; +} + +void +QHttpResponse::setVersion(const QString &versionString) { + d_func()->iversion = versionString; +} + +void +QHttpResponse::addHeader(const QByteArray &field, const QByteArray &value) { + d_func()->addHeader(field, value); +} + +THeaderHash& +QHttpResponse::headers() { + return d_func()->iheaders; +} + +void +QHttpResponse::write(const QByteArray &data) { + d_func()->writeData(data); +} + +void +QHttpResponse::end(const QByteArray &data) { + Q_D(QHttpResponse); + + if ( d->endPacket(data) ) + emit done(!d->ikeepAlive); +} + +QHttpConnection* +QHttpResponse::connection() const { + return d_func()->iconnection; +} + +/////////////////////////////////////////////////////////////////////////////// +QByteArray +QHttpResponsePrivate::makeTitle() { + + QString title = QString("HTTP/%1 %2 %3\r\n") + .arg(iversion) + .arg(istatus) + .arg(Stringify::toString(istatus)); + + return title.toLatin1(); +} + +void +QHttpResponsePrivate::prepareHeadersToWrite() { + + if ( !iheaders.contains("date") ) { + // Sun, 06 Nov 1994 08:49:37 GMT - RFC 822. Use QLocale::c() so english is used for month and + // day. + QString dateString = QLocale::c(). + toString(QDateTime::currentDateTimeUtc(), + "ddd, dd MMM yyyy hh:mm:ss") + .append(" GMT"); + addHeader("date", dateString.toLatin1()); + } +} + +/////////////////////////////////////////////////////////////////////////////// +} // namespace server +} // namespace qhttp +/////////////////////////////////////////////////////////////////////////////// diff --git a/external/qhttp/src/qhttpserverresponse.hpp b/external/qhttp/src/qhttpserverresponse.hpp new file mode 100644 index 0000000..d066712 --- /dev/null +++ b/external/qhttp/src/qhttpserverresponse.hpp @@ -0,0 +1,70 @@ +/** HTTP response from a server. + * https://github.com/azadkuh/qhttp + * + * @author amir zamani + * @version 2.0.0 + * @date 2014-07-11 + */ + +#ifndef QHTTPSERVER_RESPONSE_HPP +#define QHTTPSERVER_RESPONSE_HPP + +/////////////////////////////////////////////////////////////////////////////// + +#include "qhttpabstracts.hpp" + +/////////////////////////////////////////////////////////////////////////////// +namespace qhttp { +namespace server { +/////////////////////////////////////////////////////////////////////////////// +/** The QHttpResponse class handles sending data back to the client as a response to a request. + * @sa QHttpConnection + */ +class QHTTP_API QHttpResponse : public QHttpAbstractOutput +{ + Q_OBJECT + +public: + virtual ~QHttpResponse(); + +public: + /** set the response HTTP status code. @sa TStatusCode. + * default value is ESTATUS_BAD_REQUEST. + * @sa write() + */ + void setStatusCode(TStatusCode code); + +public: // QHttpAbstractOutput methods: + /** @see QHttpAbstractOutput::setVersion(). */ + void setVersion(const QString& versionString) override; + + /** @see QHttpAbstractOutput::addHeader(). */ + void addHeader(const QByteArray& field, const QByteArray& value) override; + + /** @see QHttpAbstractOutput::headers(). */ + THeaderHash& headers() override; + + /** @see QHttpAbstractOutput::write(). */ + void write(const QByteArray &data) override; + + /** @see QHttpAbstractOutput::end(). */ + void end(const QByteArray &data = QByteArray()) override; + +public: + /** returns the parent QHttpConnection object. */ + QHttpConnection* connection() const; + +protected: + explicit QHttpResponse(QHttpConnection*); + explicit QHttpResponse(QHttpResponsePrivate&, QHttpConnection*); + friend class QHttpConnectionPrivate; + + Q_DECLARE_PRIVATE(QHttpResponse) + QScopedPointer d_ptr; +}; + +/////////////////////////////////////////////////////////////////////////////// +} // namespace server +} // namespace qhttp +/////////////////////////////////////////////////////////////////////////////// +#endif // define QHTTPSERVER_RESPONSE_HPP diff --git a/external/qhttpserver/.gitignore b/external/qhttpserver/.gitignore deleted file mode 100755 index e7540b8..0000000 --- a/external/qhttpserver/.gitignore +++ /dev/null @@ -1,30 +0,0 @@ -# Folders -build -lib - -# Generated -Makefile -*.o -moc_* - -# Docs -docs/html - -# Build folders -*/debug -*/release -*/*/debug -*/*/release - -# Visual studio -*.suo -*.ncb -*.user -*.pdb -*.idb -*.vcproj -*.vcxproj -*.vcxproj.filters -*.lib -*.sln -*.rc diff --git a/external/qhttpserver/CMakeLists.txt b/external/qhttpserver/CMakeLists.txt deleted file mode 100644 index 8663bfb..0000000 --- a/external/qhttpserver/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -aux_source_directory(src HTTP_SRC) - -include_directories(http-parser) -add_library(http-parser STATIC http-parser/http_parser.c) - -set(CMAKE_AUTOMOC ON) -add_library(qhttpserver STATIC ${HTTP_SRC} ${PARSER_SRC}) -target_link_libraries(qhttpserver http-parser) \ No newline at end of file diff --git a/external/qhttpserver/LICENSE b/external/qhttpserver/LICENSE deleted file mode 100755 index 4cac42a..0000000 --- a/external/qhttpserver/LICENSE +++ /dev/null @@ -1,19 +0,0 @@ -Copyright (C) 2011-2014 Nikhil Marathe - -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. diff --git a/external/qhttpserver/README.md b/external/qhttpserver/README.md deleted file mode 100755 index 97e253c..0000000 --- a/external/qhttpserver/README.md +++ /dev/null @@ -1,72 +0,0 @@ -QHttpServer -=========== - -A Qt HTTP Server - because hard-core programmers write web-apps in C++ :) - -It uses Joyent's [HTTP Parser](http://github.com/joyent/http-parser) and is asynchronous and does not require any inheritance. - -QHttpServer is available under the MIT License. - -**NOTE: QHttpServer is NOT fully HTTP compliant right now! DO NOT use it for -anything complex** - -Installation ------------- - -Requires Qt 4 or Qt 5. - - qmake && make && su -c 'make install' - -To link to your projects put this in your project's qmake project file - - LIBS += -lqhttpserver - -By default, the installation prefix is /usr/local. To change that to /usr, -for example, run: - - qmake -r PREFIX=/usr - -Usage ------ - -Include the headers - - #include - #include - #include - -Create a server, and connect to the signal for new requests - - QHttpServer *server = new QHttpServer; - connect(server, SIGNAL(newRequest(QHttpRequest*, QHttpResponse*)), - handler, SLOT(handle(QHttpRequest*, QHttpResponse*))); - - // let's go - server->listen(8080); - -In the handler, you may dispatch on routes or do whatever other things -you want. See the API documentation for what information -is provided about the request via the QHttpRequest object. - -To send data back to the browser and end the request: - - void Handler::handle(QHttpRequest *req, QHttpResponse *resp) - { - resp->setHeader("Content-Length", 11); - resp->writeHead(200); // everything is OK - resp->write("Hello World"); - resp->end(); - } - -The server and request/response objects emit various signals -and have guarantees about memory management. See the API documentation for -these. - -Contribute ----------- - -Feel free to file issues, branch and send pull requests. If you plan to work on a major feature (say WebSocket support), please run it by me first by filing an issue! qhttpserver has a narrow scope and API and I'd like to keep it that way, so a thousand line patch that implements the kitchen sink is unlikely to be accepted. - -- Nikhil Marathe (maintainer) - -Everybody who has ever contributed shows up in [Contributors](https://github.com/nikhilm/qhttpserver/graphs/contributors). diff --git a/external/qhttpserver/TODO b/external/qhttpserver/TODO deleted file mode 100755 index d376a28..0000000 --- a/external/qhttpserver/TODO +++ /dev/null @@ -1,7 +0,0 @@ -* Expect & Continue stuff -* Chunked encoding support -* Only copy over public headers etc. -* connection object should connect to QHttpResponse::destroyed() -and stop pushing data into it or whatever if the object is destroyed. -* response object should keep track of emitting done() and not accept writes after that -* handle encoding in response write and end diff --git a/external/qhttpserver/docs/Doxyfile b/external/qhttpserver/docs/Doxyfile deleted file mode 100755 index ebc46e7..0000000 --- a/external/qhttpserver/docs/Doxyfile +++ /dev/null @@ -1,2314 +0,0 @@ -# Doxyfile 1.8.5 - -# This file describes the settings to be used by the documentation system -# doxygen (www.doxygen.org) for a project. -# -# All text after a double hash (##) is considered a comment and is placed in -# front of the TAG it is preceding. -# -# All text after a single hash (#) is considered a comment and will be ignored. -# The format is: -# TAG = value [value, ...] -# For lists, items can also be appended using: -# TAG += value [value, ...] -# Values that contain spaces should be placed between quotes (\" \"). - -#--------------------------------------------------------------------------- -# Project related configuration options -#--------------------------------------------------------------------------- - -# This tag specifies the encoding used for all characters in the config file -# that follow. The default is UTF-8 which is also the encoding used for all text -# before the first occurrence of this tag. Doxygen uses libiconv (or the iconv -# built into libc) for the transcoding. See http://www.gnu.org/software/libiconv -# for the list of possible encodings. -# The default value is: UTF-8. - -DOXYFILE_ENCODING = UTF-8 - -# The PROJECT_NAME tag is a single word (or a sequence of words surrounded by -# double-quotes, unless you are using Doxywizard) that should identify the -# project for which the documentation is generated. This name is used in the -# title of most generated pages and in a few other places. -# The default value is: My Project. - -PROJECT_NAME = QHttpServer - -# The PROJECT_NUMBER tag can be used to enter a project or revision number. This -# could be handy for archiving the generated documentation or if some version -# control system is used. - -PROJECT_NUMBER = 0.1 - -# Using the PROJECT_BRIEF tag one can provide an optional one line description -# for a project that appears at the top of each page and should give viewer a -# quick idea about the purpose of the project. Keep the description short. - -PROJECT_BRIEF = "A Qt based asynchronous Http Server" - -# With the PROJECT_LOGO tag one can specify an logo or icon that is included in -# the documentation. The maximum height of the logo should not exceed 55 pixels -# and the maximum width should not exceed 200 pixels. Doxygen will copy the logo -# to the output directory. - -PROJECT_LOGO = - -# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path -# into which the generated documentation will be written. If a relative path is -# entered, it will be relative to the location where doxygen was started. If -# left blank the current directory will be used. - -OUTPUT_DIRECTORY = ./ - -# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create 4096 sub- -# directories (in 2 levels) under the output directory of each output format and -# will distribute the generated files over these directories. Enabling this -# option can be useful when feeding doxygen a huge amount of source files, where -# putting all generated files in the same directory would otherwise causes -# performance problems for the file system. -# The default value is: NO. - -CREATE_SUBDIRS = NO - -# The OUTPUT_LANGUAGE tag is used to specify the language in which all -# documentation generated by doxygen is written. Doxygen will use this -# information to generate all constant output in the proper language. -# Possible values are: Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese- -# Traditional, Croatian, Czech, Danish, Dutch, English, Esperanto, Farsi, -# Finnish, French, German, Greek, Hungarian, Italian, Japanese, Japanese-en, -# Korean, Korean-en, Latvian, Norwegian, Macedonian, Persian, Polish, -# Portuguese, Romanian, Russian, Serbian, Slovak, Slovene, Spanish, Swedish, -# Turkish, Ukrainian and Vietnamese. -# The default value is: English. - -OUTPUT_LANGUAGE = English - -# If the BRIEF_MEMBER_DESC tag is set to YES doxygen will include brief member -# descriptions after the members that are listed in the file and class -# documentation (similar to Javadoc). Set to NO to disable this. -# The default value is: YES. - -BRIEF_MEMBER_DESC = YES - -# If the REPEAT_BRIEF tag is set to YES doxygen will prepend the brief -# description of a member or function before the detailed description -# -# Note: If both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the -# brief descriptions will be completely suppressed. -# The default value is: YES. - -REPEAT_BRIEF = YES - -# This tag implements a quasi-intelligent brief description abbreviator that is -# used to form the text in various listings. Each string in this list, if found -# as the leading text of the brief description, will be stripped from the text -# and the result, after processing the whole list, is used as the annotated -# text. Otherwise, the brief description is used as-is. If left blank, the -# following values are used ($name is automatically replaced with the name of -# the entity):The $name class, The $name widget, The $name file, is, provides, -# specifies, contains, represents, a, an and the. - -ABBREVIATE_BRIEF = "The $name class" \ - "The $name widget" \ - "The $name file" \ - is \ - provides \ - specifies \ - contains \ - represents \ - a \ - an \ - the - -# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then -# doxygen will generate a detailed section even if there is only a brief -# description. -# The default value is: NO. - -ALWAYS_DETAILED_SEC = NO - -# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all -# inherited members of a class in the documentation of that class as if those -# members were ordinary class members. Constructors, destructors and assignment -# operators of the base classes will not be shown. -# The default value is: NO. - -INLINE_INHERITED_MEMB = NO - -# If the FULL_PATH_NAMES tag is set to YES doxygen will prepend the full path -# before files name in the file list and in the header files. If set to NO the -# shortest path that makes the file name unique will be used -# The default value is: YES. - -FULL_PATH_NAMES = YES - -# The STRIP_FROM_PATH tag can be used to strip a user-defined part of the path. -# Stripping is only done if one of the specified strings matches the left-hand -# part of the path. The tag can be used to show relative paths in the file list. -# If left blank the directory from which doxygen is run is used as the path to -# strip. -# -# Note that you can specify absolute paths here, but also relative paths, which -# will be relative from the directory where doxygen is started. -# This tag requires that the tag FULL_PATH_NAMES is set to YES. - -STRIP_FROM_PATH = - -# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the -# path mentioned in the documentation of a class, which tells the reader which -# header file to include in order to use a class. If left blank only the name of -# the header file containing the class definition is used. Otherwise one should -# specify the list of include paths that are normally passed to the compiler -# using the -I flag. - -STRIP_FROM_INC_PATH = - -# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but -# less readable) file names. This can be useful is your file systems doesn't -# support long names like on DOS, Mac, or CD-ROM. -# The default value is: NO. - -SHORT_NAMES = NO - -# If the JAVADOC_AUTOBRIEF tag is set to YES then doxygen will interpret the -# first line (until the first dot) of a Javadoc-style comment as the brief -# description. If set to NO, the Javadoc-style will behave just like regular Qt- -# style comments (thus requiring an explicit @brief command for a brief -# description.) -# The default value is: NO. - -JAVADOC_AUTOBRIEF = NO - -# If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first -# line (until the first dot) of a Qt-style comment as the brief description. If -# set to NO, the Qt-style will behave just like regular Qt-style comments (thus -# requiring an explicit \brief command for a brief description.) -# The default value is: NO. - -QT_AUTOBRIEF = YES - -# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make doxygen treat a -# multi-line C++ special comment block (i.e. a block of //! or /// comments) as -# a brief description. This used to be the default behavior. The new default is -# to treat a multi-line C++ comment block as a detailed description. Set this -# tag to YES if you prefer the old behavior instead. -# -# Note that setting this tag to YES also means that rational rose comments are -# not recognized any more. -# The default value is: NO. - -MULTILINE_CPP_IS_BRIEF = YES - -# If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the -# documentation from any documented member that it re-implements. -# The default value is: YES. - -INHERIT_DOCS = YES - -# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce a -# new page for each member. If set to NO, the documentation of a member will be -# part of the file/class/namespace that contains it. -# The default value is: NO. - -SEPARATE_MEMBER_PAGES = NO - -# The TAB_SIZE tag can be used to set the number of spaces in a tab. Doxygen -# uses this value to replace tabs by spaces in code fragments. -# Minimum value: 1, maximum value: 16, default value: 4. - -TAB_SIZE = 4 - -# This tag can be used to specify a number of aliases that act as commands in -# the documentation. An alias has the form: -# name=value -# For example adding -# "sideeffect=@par Side Effects:\n" -# will allow you to put the command \sideeffect (or @sideeffect) in the -# documentation, which will result in a user-defined paragraph with heading -# "Side Effects:". You can put \n's in the value part of an alias to insert -# newlines. - -ALIASES = - -# This tag can be used to specify a number of word-keyword mappings (TCL only). -# A mapping has the form "name=value". For example adding "class=itcl::class" -# will allow you to use the command class in the itcl::class meaning. - -TCL_SUBST = - -# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources -# only. Doxygen will then generate output that is more tailored for C. For -# instance, some of the names that are used will be different. The list of all -# members will be omitted, etc. -# The default value is: NO. - -OPTIMIZE_OUTPUT_FOR_C = NO - -# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java or -# Python sources only. Doxygen will then generate output that is more tailored -# for that language. For instance, namespaces will be presented as packages, -# qualified scopes will look different, etc. -# The default value is: NO. - -OPTIMIZE_OUTPUT_JAVA = NO - -# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran -# sources. Doxygen will then generate output that is tailored for Fortran. -# The default value is: NO. - -OPTIMIZE_FOR_FORTRAN = NO - -# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL -# sources. Doxygen will then generate output that is tailored for VHDL. -# The default value is: NO. - -OPTIMIZE_OUTPUT_VHDL = NO - -# Doxygen selects the parser to use depending on the extension of the files it -# parses. With this tag you can assign which parser to use for a given -# extension. Doxygen has a built-in mapping, but you can override or extend it -# using this tag. The format is ext=language, where ext is a file extension, and -# language is one of the parsers supported by doxygen: IDL, Java, Javascript, -# C#, C, C++, D, PHP, Objective-C, Python, Fortran, VHDL. For instance to make -# doxygen treat .inc files as Fortran files (default is PHP), and .f files as C -# (default is Fortran), use: inc=Fortran f=C. -# -# Note For files without extension you can use no_extension as a placeholder. -# -# Note that for custom extensions you also need to set FILE_PATTERNS otherwise -# the files are not read by doxygen. - -EXTENSION_MAPPING = - -# If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments -# according to the Markdown format, which allows for more readable -# documentation. See http://daringfireball.net/projects/markdown/ for details. -# The output of markdown processing is further processed by doxygen, so you can -# mix doxygen, HTML, and XML commands with Markdown formatting. Disable only in -# case of backward compatibilities issues. -# The default value is: YES. - -MARKDOWN_SUPPORT = YES - -# When enabled doxygen tries to link words that correspond to documented -# classes, or namespaces to their corresponding documentation. Such a link can -# be prevented in individual cases by by putting a % sign in front of the word -# or globally by setting AUTOLINK_SUPPORT to NO. -# The default value is: YES. - -AUTOLINK_SUPPORT = YES - -# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want -# to include (a tag file for) the STL sources as input, then you should set this -# tag to YES in order to let doxygen match functions declarations and -# definitions whose arguments contain STL classes (e.g. func(std::string); -# versus func(std::string) {}). This also make the inheritance and collaboration -# diagrams that involve STL classes more complete and accurate. -# The default value is: NO. - -BUILTIN_STL_SUPPORT = NO - -# If you use Microsoft's C++/CLI language, you should set this option to YES to -# enable parsing support. -# The default value is: NO. - -CPP_CLI_SUPPORT = NO - -# Set the SIP_SUPPORT tag to YES if your project consists of sip (see: -# http://www.riverbankcomputing.co.uk/software/sip/intro) sources only. Doxygen -# will parse them like normal C++ but will assume all classes use public instead -# of private inheritance when no explicit protection keyword is present. -# The default value is: NO. - -SIP_SUPPORT = NO - -# For Microsoft's IDL there are propget and propput attributes to indicate -# getter and setter methods for a property. Setting this option to YES will make -# doxygen to replace the get and set methods by a property in the documentation. -# This will only work if the methods are indeed getting or setting a simple -# type. If this is not the case, or you want to show the methods anyway, you -# should set this option to NO. -# The default value is: YES. - -IDL_PROPERTY_SUPPORT = YES - -# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC -# tag is set to YES, then doxygen will reuse the documentation of the first -# member in the group (if any) for the other members of the group. By default -# all members of a group must be documented explicitly. -# The default value is: NO. - -DISTRIBUTE_GROUP_DOC = NO - -# Set the SUBGROUPING tag to YES to allow class member groups of the same type -# (for instance a group of public functions) to be put as a subgroup of that -# type (e.g. under the Public Functions section). Set it to NO to prevent -# subgrouping. Alternatively, this can be done per class using the -# \nosubgrouping command. -# The default value is: YES. - -SUBGROUPING = YES - -# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and unions -# are shown inside the group in which they are included (e.g. using \ingroup) -# instead of on a separate page (for HTML and Man pages) or section (for LaTeX -# and RTF). -# -# Note that this feature does not work in combination with -# SEPARATE_MEMBER_PAGES. -# The default value is: NO. - -INLINE_GROUPED_CLASSES = NO - -# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and unions -# with only public data fields or simple typedef fields will be shown inline in -# the documentation of the scope in which they are defined (i.e. file, -# namespace, or group documentation), provided this scope is documented. If set -# to NO, structs, classes, and unions are shown on a separate page (for HTML and -# Man pages) or section (for LaTeX and RTF). -# The default value is: NO. - -INLINE_SIMPLE_STRUCTS = NO - -# When TYPEDEF_HIDES_STRUCT tag is enabled, a typedef of a struct, union, or -# enum is documented as struct, union, or enum with the name of the typedef. So -# typedef struct TypeS {} TypeT, will appear in the documentation as a struct -# with name TypeT. When disabled the typedef will appear as a member of a file, -# namespace, or class. And the struct will be named TypeS. This can typically be -# useful for C code in case the coding convention dictates that all compound -# types are typedef'ed and only the typedef is referenced, never the tag name. -# The default value is: NO. - -TYPEDEF_HIDES_STRUCT = NO - -# The size of the symbol lookup cache can be set using LOOKUP_CACHE_SIZE. This -# cache is used to resolve symbols given their name and scope. Since this can be -# an expensive process and often the same symbol appears multiple times in the -# code, doxygen keeps a cache of pre-resolved symbols. If the cache is too small -# doxygen will become slower. If the cache is too large, memory is wasted. The -# cache size is given by this formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range -# is 0..9, the default is 0, corresponding to a cache size of 2^16=65536 -# symbols. At the end of a run doxygen will report the cache usage and suggest -# the optimal cache size from a speed point of view. -# Minimum value: 0, maximum value: 9, default value: 0. - -LOOKUP_CACHE_SIZE = 0 - -#--------------------------------------------------------------------------- -# Build related configuration options -#--------------------------------------------------------------------------- - -# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in -# documentation are documented, even if no documentation was available. Private -# class members and static file members will be hidden unless the -# EXTRACT_PRIVATE respectively EXTRACT_STATIC tags are set to YES. -# Note: This will also disable the warnings about undocumented members that are -# normally produced when WARNINGS is set to YES. -# The default value is: NO. - -EXTRACT_ALL = NO - -# If the EXTRACT_PRIVATE tag is set to YES all private members of a class will -# be included in the documentation. -# The default value is: NO. - -EXTRACT_PRIVATE = NO - -# If the EXTRACT_PACKAGE tag is set to YES all members with package or internal -# scope will be included in the documentation. -# The default value is: NO. - -EXTRACT_PACKAGE = NO - -# If the EXTRACT_STATIC tag is set to YES all static members of a file will be -# included in the documentation. -# The default value is: NO. - -EXTRACT_STATIC = NO - -# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) defined -# locally in source files will be included in the documentation. If set to NO -# only classes defined in header files are included. Does not have any effect -# for Java sources. -# The default value is: YES. - -EXTRACT_LOCAL_CLASSES = YES - -# This flag is only useful for Objective-C code. When set to YES local methods, -# which are defined in the implementation section but not in the interface are -# included in the documentation. If set to NO only methods in the interface are -# included. -# The default value is: NO. - -EXTRACT_LOCAL_METHODS = NO - -# If this flag is set to YES, the members of anonymous namespaces will be -# extracted and appear in the documentation as a namespace called -# 'anonymous_namespace{file}', where file will be replaced with the base name of -# the file that contains the anonymous namespace. By default anonymous namespace -# are hidden. -# The default value is: NO. - -EXTRACT_ANON_NSPACES = NO - -# If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all -# undocumented members inside documented classes or files. If set to NO these -# members will be included in the various overviews, but no documentation -# section is generated. This option has no effect if EXTRACT_ALL is enabled. -# The default value is: NO. - -HIDE_UNDOC_MEMBERS = NO - -# If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all -# undocumented classes that are normally visible in the class hierarchy. If set -# to NO these classes will be included in the various overviews. This option has -# no effect if EXTRACT_ALL is enabled. -# The default value is: NO. - -HIDE_UNDOC_CLASSES = NO - -# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend -# (class|struct|union) declarations. If set to NO these declarations will be -# included in the documentation. -# The default value is: NO. - -HIDE_FRIEND_COMPOUNDS = NO - -# If the HIDE_IN_BODY_DOCS tag is set to YES, doxygen will hide any -# documentation blocks found inside the body of a function. If set to NO these -# blocks will be appended to the function's detailed documentation block. -# The default value is: NO. - -HIDE_IN_BODY_DOCS = NO - -# The INTERNAL_DOCS tag determines if documentation that is typed after a -# \internal command is included. If the tag is set to NO then the documentation -# will be excluded. Set it to YES to include the internal documentation. -# The default value is: NO. - -INTERNAL_DOCS = NO - -# If the CASE_SENSE_NAMES tag is set to NO then doxygen will only generate file -# names in lower-case letters. If set to YES upper-case letters are also -# allowed. This is useful if you have classes or files whose names only differ -# in case and if your file system supports case sensitive file names. Windows -# and Mac users are advised to set this option to NO. -# The default value is: system dependent. - -CASE_SENSE_NAMES = NO - -# If the HIDE_SCOPE_NAMES tag is set to NO then doxygen will show members with -# their full class and namespace scopes in the documentation. If set to YES the -# scope will be hidden. -# The default value is: NO. - -HIDE_SCOPE_NAMES = NO - -# If the SHOW_INCLUDE_FILES tag is set to YES then doxygen will put a list of -# the files that are included by a file in the documentation of that file. -# The default value is: YES. - -SHOW_INCLUDE_FILES = YES - -# If the FORCE_LOCAL_INCLUDES tag is set to YES then doxygen will list include -# files with double quotes in the documentation rather than with sharp brackets. -# The default value is: NO. - -FORCE_LOCAL_INCLUDES = NO - -# If the INLINE_INFO tag is set to YES then a tag [inline] is inserted in the -# documentation for inline members. -# The default value is: YES. - -INLINE_INFO = YES - -# If the SORT_MEMBER_DOCS tag is set to YES then doxygen will sort the -# (detailed) documentation of file and class members alphabetically by member -# name. If set to NO the members will appear in declaration order. -# The default value is: YES. - -SORT_MEMBER_DOCS = YES - -# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the brief -# descriptions of file, namespace and class members alphabetically by member -# name. If set to NO the members will appear in declaration order. -# The default value is: NO. - -SORT_BRIEF_DOCS = NO - -# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen will sort the -# (brief and detailed) documentation of class members so that constructors and -# destructors are listed first. If set to NO the constructors will appear in the -# respective orders defined by SORT_BRIEF_DOCS and SORT_MEMBER_DOCS. -# Note: If SORT_BRIEF_DOCS is set to NO this option is ignored for sorting brief -# member documentation. -# Note: If SORT_MEMBER_DOCS is set to NO this option is ignored for sorting -# detailed member documentation. -# The default value is: NO. - -SORT_MEMBERS_CTORS_1ST = NO - -# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the hierarchy -# of group names into alphabetical order. If set to NO the group names will -# appear in their defined order. -# The default value is: NO. - -SORT_GROUP_NAMES = NO - -# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be sorted by -# fully-qualified names, including namespaces. If set to NO, the class list will -# be sorted only by class name, not including the namespace part. -# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. -# Note: This option applies only to the class list, not to the alphabetical -# list. -# The default value is: NO. - -SORT_BY_SCOPE_NAME = NO - -# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to do proper -# type resolution of all parameters of a function it will reject a match between -# the prototype and the implementation of a member function even if there is -# only one candidate or it is obvious which candidate to choose by doing a -# simple string match. By disabling STRICT_PROTO_MATCHING doxygen will still -# accept a match between prototype and implementation in such cases. -# The default value is: NO. - -STRICT_PROTO_MATCHING = NO - -# The GENERATE_TODOLIST tag can be used to enable ( YES) or disable ( NO) the -# todo list. This list is created by putting \todo commands in the -# documentation. -# The default value is: YES. - -GENERATE_TODOLIST = NO - -# The GENERATE_TESTLIST tag can be used to enable ( YES) or disable ( NO) the -# test list. This list is created by putting \test commands in the -# documentation. -# The default value is: YES. - -GENERATE_TESTLIST = YES - -# The GENERATE_BUGLIST tag can be used to enable ( YES) or disable ( NO) the bug -# list. This list is created by putting \bug commands in the documentation. -# The default value is: YES. - -GENERATE_BUGLIST = YES - -# The GENERATE_DEPRECATEDLIST tag can be used to enable ( YES) or disable ( NO) -# the deprecated list. This list is created by putting \deprecated commands in -# the documentation. -# The default value is: YES. - -GENERATE_DEPRECATEDLIST= YES - -# The ENABLED_SECTIONS tag can be used to enable conditional documentation -# sections, marked by \if ... \endif and \cond -# ... \endcond blocks. - -ENABLED_SECTIONS = - -# The MAX_INITIALIZER_LINES tag determines the maximum number of lines that the -# initial value of a variable or macro / define can have for it to appear in the -# documentation. If the initializer consists of more lines than specified here -# it will be hidden. Use a value of 0 to hide initializers completely. The -# appearance of the value of individual variables and macros / defines can be -# controlled using \showinitializer or \hideinitializer command in the -# documentation regardless of this setting. -# Minimum value: 0, maximum value: 10000, default value: 30. - -MAX_INITIALIZER_LINES = 30 - -# Set the SHOW_USED_FILES tag to NO to disable the list of files generated at -# the bottom of the documentation of classes and structs. If set to YES the list -# will mention the files that were used to generate the documentation. -# The default value is: YES. - -SHOW_USED_FILES = NO - -# Set the SHOW_FILES tag to NO to disable the generation of the Files page. This -# will remove the Files entry from the Quick Index and from the Folder Tree View -# (if specified). -# The default value is: YES. - -SHOW_FILES = NO - -# Set the SHOW_NAMESPACES tag to NO to disable the generation of the Namespaces -# page. This will remove the Namespaces entry from the Quick Index and from the -# Folder Tree View (if specified). -# The default value is: YES. - -SHOW_NAMESPACES = YES - -# The FILE_VERSION_FILTER tag can be used to specify a program or script that -# doxygen should invoke to get the current version for each file (typically from -# the version control system). Doxygen will invoke the program by executing (via -# popen()) the command command input-file, where command is the value of the -# FILE_VERSION_FILTER tag, and input-file is the name of an input file provided -# by doxygen. Whatever the program writes to standard output is used as the file -# version. For an example see the documentation. - -FILE_VERSION_FILTER = - -# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed -# by doxygen. The layout file controls the global structure of the generated -# output files in an output format independent way. To create the layout file -# that represents doxygen's defaults, run doxygen with the -l option. You can -# optionally specify a file name after the option, if omitted DoxygenLayout.xml -# will be used as the name of the layout file. -# -# Note that if you run doxygen from a directory containing a file called -# DoxygenLayout.xml, doxygen will parse it automatically even if the LAYOUT_FILE -# tag is left empty. - -LAYOUT_FILE = - -# The CITE_BIB_FILES tag can be used to specify one or more bib files containing -# the reference definitions. This must be a list of .bib files. The .bib -# extension is automatically appended if omitted. This requires the bibtex tool -# to be installed. See also http://en.wikipedia.org/wiki/BibTeX for more info. -# For LaTeX the style of the bibliography can be controlled using -# LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the -# search path. Do not use file names with spaces, bibtex cannot handle them. See -# also \cite for info how to create references. - -CITE_BIB_FILES = - -#--------------------------------------------------------------------------- -# Configuration options related to warning and progress messages -#--------------------------------------------------------------------------- - -# The QUIET tag can be used to turn on/off the messages that are generated to -# standard output by doxygen. If QUIET is set to YES this implies that the -# messages are off. -# The default value is: NO. - -QUIET = NO - -# The WARNINGS tag can be used to turn on/off the warning messages that are -# generated to standard error ( stderr) by doxygen. If WARNINGS is set to YES -# this implies that the warnings are on. -# -# Tip: Turn warnings on while writing the documentation. -# The default value is: YES. - -WARNINGS = YES - -# If the WARN_IF_UNDOCUMENTED tag is set to YES, then doxygen will generate -# warnings for undocumented members. If EXTRACT_ALL is set to YES then this flag -# will automatically be disabled. -# The default value is: YES. - -WARN_IF_UNDOCUMENTED = YES - -# If the WARN_IF_DOC_ERROR tag is set to YES, doxygen will generate warnings for -# potential errors in the documentation, such as not documenting some parameters -# in a documented function, or documenting parameters that don't exist or using -# markup commands wrongly. -# The default value is: YES. - -WARN_IF_DOC_ERROR = YES - -# This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that -# are documented, but have no documentation for their parameters or return -# value. If set to NO doxygen will only warn about wrong or incomplete parameter -# documentation, but not about the absence of documentation. -# The default value is: NO. - -WARN_NO_PARAMDOC = NO - -# The WARN_FORMAT tag determines the format of the warning messages that doxygen -# can produce. The string should contain the $file, $line, and $text tags, which -# will be replaced by the file and line number from which the warning originated -# and the warning text. Optionally the format may contain $version, which will -# be replaced by the version of the file (if it could be obtained via -# FILE_VERSION_FILTER) -# The default value is: $file:$line: $text. - -WARN_FORMAT = "$file:$line: $text" - -# The WARN_LOGFILE tag can be used to specify a file to which warning and error -# messages should be written. If left blank the output is written to standard -# error (stderr). - -WARN_LOGFILE = - -#--------------------------------------------------------------------------- -# Configuration options related to the input files -#--------------------------------------------------------------------------- - -# The INPUT tag is used to specify the files and/or directories that contain -# documented source files. You may enter file names like myfile.cpp or -# directories like /usr/src/myproject. Separate the files or directories with -# spaces. -# Note: If this tag is empty the current directory is searched. - -INPUT = pages \ - ../src - -# This tag can be used to specify the character encoding of the source files -# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses -# libiconv (or the iconv built into libc) for the transcoding. See the libiconv -# documentation (see: http://www.gnu.org/software/libiconv) for the list of -# possible encodings. -# The default value is: UTF-8. - -INPUT_ENCODING = UTF-8 - -# If the value of the INPUT tag contains directories, you can use the -# FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and -# *.h) to filter out the source-files in the directories. If left blank the -# following patterns are tested:*.c, *.cc, *.cxx, *.cpp, *.c++, *.java, *.ii, -# *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h, *.hh, *.hxx, *.hpp, -# *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc, *.m, *.markdown, -# *.md, *.mm, *.dox, *.py, *.f90, *.f, *.for, *.tcl, *.vhd, *.vhdl, *.ucf, -# *.qsf, *.as and *.js. - -FILE_PATTERNS = *.cpp \ - *.inl \ - *.h \ - *.dox - -# The RECURSIVE tag can be used to specify whether or not subdirectories should -# be searched for input files as well. -# The default value is: NO. - -RECURSIVE = YES - -# The EXCLUDE tag can be used to specify files and/or directories that should be -# excluded from the INPUT source files. This way you can easily exclude a -# subdirectory from a directory tree whose root is specified with the INPUT tag. -# -# Note that relative paths are relative to the directory from which doxygen is -# run. - -EXCLUDE = - -# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or -# directories that are symbolic links (a Unix file system feature) are excluded -# from the input. -# The default value is: NO. - -EXCLUDE_SYMLINKS = NO - -# If the value of the INPUT tag contains directories, you can use the -# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude -# certain files from those directories. -# -# Note that the wildcards are matched against the file with absolute path, so to -# exclude all test directories for example use the pattern */test/* - -EXCLUDE_PATTERNS = ui_*.h \ - moc_* - -# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names -# (namespaces, classes, functions, etc.) that should be excluded from the -# output. The symbol name can be a fully qualified name, a word, or if the -# wildcard * is used, a substring. Examples: ANamespace, AClass, -# AClass::ANamespace, ANamespace::*Test -# -# Note that the wildcards are matched against the file with absolute path, so to -# exclude all test directories use the pattern */test/* - -EXCLUDE_SYMBOLS = - -# The EXAMPLE_PATH tag can be used to specify one or more files or directories -# that contain example code fragments that are included (see the \include -# command). - -EXAMPLE_PATH = ../examples - -# If the value of the EXAMPLE_PATH tag contains directories, you can use the -# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and -# *.h) to filter out the source-files in the directories. If left blank all -# files are included. - -EXAMPLE_PATTERNS = * - -# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be -# searched for input files to be used with the \include or \dontinclude commands -# irrespective of the value of the RECURSIVE tag. -# The default value is: NO. - -EXAMPLE_RECURSIVE = NO - -# The IMAGE_PATH tag can be used to specify one or more files or directories -# that contain images that are to be included in the documentation (see the -# \image command). - -IMAGE_PATH = - -# The INPUT_FILTER tag can be used to specify a program that doxygen should -# invoke to filter for each input file. Doxygen will invoke the filter program -# by executing (via popen()) the command: -# -# -# -# where is the value of the INPUT_FILTER tag, and is the -# name of an input file. Doxygen will then use the output that the filter -# program writes to standard output. If FILTER_PATTERNS is specified, this tag -# will be ignored. -# -# Note that the filter must not add or remove lines; it is applied before the -# code is scanned, but not when the output code is generated. If lines are added -# or removed, the anchors will not be placed correctly. - -INPUT_FILTER = - -# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern -# basis. Doxygen will compare the file name with each pattern and apply the -# filter if there is a match. The filters are a list of the form: pattern=filter -# (like *.cpp=my_cpp_filter). See INPUT_FILTER for further information on how -# filters are used. If the FILTER_PATTERNS tag is empty or if none of the -# patterns match the file name, INPUT_FILTER is applied. - -FILTER_PATTERNS = - -# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using -# INPUT_FILTER ) will also be used to filter the input files that are used for -# producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES). -# The default value is: NO. - -FILTER_SOURCE_FILES = NO - -# The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file -# pattern. A pattern will override the setting for FILTER_PATTERN (if any) and -# it is also possible to disable source filtering for a specific pattern using -# *.ext= (so without naming a filter). -# This tag requires that the tag FILTER_SOURCE_FILES is set to YES. - -FILTER_SOURCE_PATTERNS = - -# If the USE_MDFILE_AS_MAINPAGE tag refers to the name of a markdown file that -# is part of the input, its contents will be placed on the main page -# (index.html). This can be useful if you have a project on for instance GitHub -# and want to reuse the introduction page also for the doxygen output. - -USE_MDFILE_AS_MAINPAGE = - -#--------------------------------------------------------------------------- -# Configuration options related to source browsing -#--------------------------------------------------------------------------- - -# If the SOURCE_BROWSER tag is set to YES then a list of source files will be -# generated. Documented entities will be cross-referenced with these sources. -# -# Note: To get rid of all source code in the generated output, make sure that -# also VERBATIM_HEADERS is set to NO. -# The default value is: NO. - -SOURCE_BROWSER = NO - -# Setting the INLINE_SOURCES tag to YES will include the body of functions, -# classes and enums directly into the documentation. -# The default value is: NO. - -INLINE_SOURCES = NO - -# Setting the STRIP_CODE_COMMENTS tag to YES will instruct doxygen to hide any -# special comment blocks from generated source code fragments. Normal C, C++ and -# Fortran comments will always remain visible. -# The default value is: YES. - -STRIP_CODE_COMMENTS = YES - -# If the REFERENCED_BY_RELATION tag is set to YES then for each documented -# function all documented functions referencing it will be listed. -# The default value is: NO. - -REFERENCED_BY_RELATION = NO - -# If the REFERENCES_RELATION tag is set to YES then for each documented function -# all documented entities called/used by that function will be listed. -# The default value is: NO. - -REFERENCES_RELATION = NO - -# If the REFERENCES_LINK_SOURCE tag is set to YES and SOURCE_BROWSER tag is set -# to YES, then the hyperlinks from functions in REFERENCES_RELATION and -# REFERENCED_BY_RELATION lists will link to the source code. Otherwise they will -# link to the documentation. -# The default value is: YES. - -REFERENCES_LINK_SOURCE = YES - -# If SOURCE_TOOLTIPS is enabled (the default) then hovering a hyperlink in the -# source code will show a tooltip with additional information such as prototype, -# brief description and links to the definition and documentation. Since this -# will make the HTML file larger and loading of large files a bit slower, you -# can opt to disable this feature. -# The default value is: YES. -# This tag requires that the tag SOURCE_BROWSER is set to YES. - -SOURCE_TOOLTIPS = YES - -# If the USE_HTAGS tag is set to YES then the references to source code will -# point to the HTML generated by the htags(1) tool instead of doxygen built-in -# source browser. The htags tool is part of GNU's global source tagging system -# (see http://www.gnu.org/software/global/global.html). You will need version -# 4.8.6 or higher. -# -# To use it do the following: -# - Install the latest version of global -# - Enable SOURCE_BROWSER and USE_HTAGS in the config file -# - Make sure the INPUT points to the root of the source tree -# - Run doxygen as normal -# -# Doxygen will invoke htags (and that will in turn invoke gtags), so these -# tools must be available from the command line (i.e. in the search path). -# -# The result: instead of the source browser generated by doxygen, the links to -# source code will now point to the output of htags. -# The default value is: NO. -# This tag requires that the tag SOURCE_BROWSER is set to YES. - -USE_HTAGS = NO - -# If the VERBATIM_HEADERS tag is set the YES then doxygen will generate a -# verbatim copy of the header file for each class for which an include is -# specified. Set to NO to disable this. -# See also: Section \class. -# The default value is: YES. - -VERBATIM_HEADERS = YES - -# If the CLANG_ASSISTED_PARSING tag is set to YES, then doxygen will use the -# clang parser (see: http://clang.llvm.org/) for more acurate parsing at the -# cost of reduced performance. This can be particularly helpful with template -# rich C++ code for which doxygen's built-in parser lacks the necessary type -# information. -# Note: The availability of this option depends on whether or not doxygen was -# compiled with the --with-libclang option. -# The default value is: NO. - -CLANG_ASSISTED_PARSING = NO - -# If clang assisted parsing is enabled you can provide the compiler with command -# line options that you would normally use when invoking the compiler. Note that -# the include paths will already be set by doxygen for the files and directories -# specified with INPUT and INCLUDE_PATH. -# This tag requires that the tag CLANG_ASSISTED_PARSING is set to YES. - -CLANG_OPTIONS = - -#--------------------------------------------------------------------------- -# Configuration options related to the alphabetical class index -#--------------------------------------------------------------------------- - -# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index of all -# compounds will be generated. Enable this if the project contains a lot of -# classes, structs, unions or interfaces. -# The default value is: YES. - -ALPHABETICAL_INDEX = YES - -# The COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns in -# which the alphabetical index list will be split. -# Minimum value: 1, maximum value: 20, default value: 5. -# This tag requires that the tag ALPHABETICAL_INDEX is set to YES. - -COLS_IN_ALPHA_INDEX = 5 - -# In case all classes in a project start with a common prefix, all classes will -# be put under the same header in the alphabetical index. The IGNORE_PREFIX tag -# can be used to specify a prefix (or a list of prefixes) that should be ignored -# while generating the index headers. -# This tag requires that the tag ALPHABETICAL_INDEX is set to YES. - -IGNORE_PREFIX = - -#--------------------------------------------------------------------------- -# Configuration options related to the HTML output -#--------------------------------------------------------------------------- - -# If the GENERATE_HTML tag is set to YES doxygen will generate HTML output -# The default value is: YES. - -GENERATE_HTML = YES - -# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. If a -# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of -# it. -# The default directory is: html. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_OUTPUT = html - -# The HTML_FILE_EXTENSION tag can be used to specify the file extension for each -# generated HTML page (for example: .htm, .php, .asp). -# The default value is: .html. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_FILE_EXTENSION = .html - -# The HTML_HEADER tag can be used to specify a user-defined HTML header file for -# each generated HTML page. If the tag is left blank doxygen will generate a -# standard header. -# -# To get valid HTML the header file that includes any scripts and style sheets -# that doxygen needs, which is dependent on the configuration options used (e.g. -# the setting GENERATE_TREEVIEW). It is highly recommended to start with a -# default header using -# doxygen -w html new_header.html new_footer.html new_stylesheet.css -# YourConfigFile -# and then modify the file new_header.html. See also section "Doxygen usage" -# for information on how to generate the default header that doxygen normally -# uses. -# Note: The header is subject to change so you typically have to regenerate the -# default header when upgrading to a newer version of doxygen. For a description -# of the possible markers and block names see the documentation. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_HEADER = - -# The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each -# generated HTML page. If the tag is left blank doxygen will generate a standard -# footer. See HTML_HEADER for more information on how to generate a default -# footer and what special commands can be used inside the footer. See also -# section "Doxygen usage" for information on how to generate the default footer -# that doxygen normally uses. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_FOOTER = - -# The HTML_STYLESHEET tag can be used to specify a user-defined cascading style -# sheet that is used by each HTML page. It can be used to fine-tune the look of -# the HTML output. If left blank doxygen will generate a default style sheet. -# See also section "Doxygen usage" for information on how to generate the style -# sheet that doxygen normally uses. -# Note: It is recommended to use HTML_EXTRA_STYLESHEET instead of this tag, as -# it is more robust and this tag (HTML_STYLESHEET) will in the future become -# obsolete. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_STYLESHEET = - -# The HTML_EXTRA_STYLESHEET tag can be used to specify an additional user- -# defined cascading style sheet that is included after the standard style sheets -# created by doxygen. Using this option one can overrule certain style aspects. -# This is preferred over using HTML_STYLESHEET since it does not replace the -# standard style sheet and is therefor more robust against future updates. -# Doxygen will copy the style sheet file to the output directory. For an example -# see the documentation. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_EXTRA_STYLESHEET = - -# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or -# other source files which should be copied to the HTML output directory. Note -# that these files will be copied to the base HTML output directory. Use the -# $relpath^ marker in the HTML_HEADER and/or HTML_FOOTER files to load these -# files. In the HTML_STYLESHEET file, use the file name only. Also note that the -# files will be copied as-is; there are no commands or markers available. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_EXTRA_FILES = - -# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen -# will adjust the colors in the stylesheet and background images according to -# this color. Hue is specified as an angle on a colorwheel, see -# http://en.wikipedia.org/wiki/Hue for more information. For instance the value -# 0 represents red, 60 is yellow, 120 is green, 180 is cyan, 240 is blue, 300 -# purple, and 360 is red again. -# Minimum value: 0, maximum value: 359, default value: 220. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_COLORSTYLE_HUE = 220 - -# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of the colors -# in the HTML output. For a value of 0 the output will use grayscales only. A -# value of 255 will produce the most vivid colors. -# Minimum value: 0, maximum value: 255, default value: 100. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_COLORSTYLE_SAT = 100 - -# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to the -# luminance component of the colors in the HTML output. Values below 100 -# gradually make the output lighter, whereas values above 100 make the output -# darker. The value divided by 100 is the actual gamma applied, so 80 represents -# a gamma of 0.8, The value 220 represents a gamma of 2.2, and 100 does not -# change the gamma. -# Minimum value: 40, maximum value: 240, default value: 80. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_COLORSTYLE_GAMMA = 80 - -# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML -# page will contain the date and time when the page was generated. Setting this -# to NO can help when comparing the output of multiple runs. -# The default value is: YES. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_TIMESTAMP = YES - -# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML -# documentation will contain sections that can be hidden and shown after the -# page has loaded. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_DYNAMIC_SECTIONS = NO - -# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of entries -# shown in the various tree structured indices initially; the user can expand -# and collapse entries dynamically later on. Doxygen will expand the tree to -# such a level that at most the specified number of entries are visible (unless -# a fully collapsed tree already exceeds this amount). So setting the number of -# entries 1 will produce a full collapsed tree by default. 0 is a special value -# representing an infinite number of entries and will result in a full expanded -# tree by default. -# Minimum value: 0, maximum value: 9999, default value: 100. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_INDEX_NUM_ENTRIES = 100 - -# If the GENERATE_DOCSET tag is set to YES, additional index files will be -# generated that can be used as input for Apple's Xcode 3 integrated development -# environment (see: http://developer.apple.com/tools/xcode/), introduced with -# OSX 10.5 (Leopard). To create a documentation set, doxygen will generate a -# Makefile in the HTML output directory. Running make will produce the docset in -# that directory and running make install will install the docset in -# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at -# startup. See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html -# for more information. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -GENERATE_DOCSET = NO - -# This tag determines the name of the docset feed. A documentation feed provides -# an umbrella under which multiple documentation sets from a single provider -# (such as a company or product suite) can be grouped. -# The default value is: Doxygen generated docs. -# This tag requires that the tag GENERATE_DOCSET is set to YES. - -DOCSET_FEEDNAME = "Doxygen generated docs" - -# This tag specifies a string that should uniquely identify the documentation -# set bundle. This should be a reverse domain-name style string, e.g. -# com.mycompany.MyDocSet. Doxygen will append .docset to the name. -# The default value is: org.doxygen.Project. -# This tag requires that the tag GENERATE_DOCSET is set to YES. - -DOCSET_BUNDLE_ID = org.doxygen.Project - -# The DOCSET_PUBLISHER_ID tag specifies a string that should uniquely identify -# the documentation publisher. This should be a reverse domain-name style -# string, e.g. com.mycompany.MyDocSet.documentation. -# The default value is: org.doxygen.Publisher. -# This tag requires that the tag GENERATE_DOCSET is set to YES. - -DOCSET_PUBLISHER_ID = org.doxygen.Publisher - -# The DOCSET_PUBLISHER_NAME tag identifies the documentation publisher. -# The default value is: Publisher. -# This tag requires that the tag GENERATE_DOCSET is set to YES. - -DOCSET_PUBLISHER_NAME = Publisher - -# If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three -# additional HTML index files: index.hhp, index.hhc, and index.hhk. The -# index.hhp is a project file that can be read by Microsoft's HTML Help Workshop -# (see: http://www.microsoft.com/en-us/download/details.aspx?id=21138) on -# Windows. -# -# The HTML Help Workshop contains a compiler that can convert all HTML output -# generated by doxygen into a single compiled HTML file (.chm). Compiled HTML -# files are now used as the Windows 98 help format, and will replace the old -# Windows help format (.hlp) on all Windows platforms in the future. Compressed -# HTML files also contain an index, a table of contents, and you can search for -# words in the documentation. The HTML workshop also contains a viewer for -# compressed HTML files. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -GENERATE_HTMLHELP = NO - -# The CHM_FILE tag can be used to specify the file name of the resulting .chm -# file. You can add a path in front of the file if the result should not be -# written to the html output directory. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -CHM_FILE = - -# The HHC_LOCATION tag can be used to specify the location (absolute path -# including file name) of the HTML help compiler ( hhc.exe). If non-empty -# doxygen will try to run the HTML help compiler on the generated index.hhp. -# The file has to be specified with full path. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -HHC_LOCATION = - -# The GENERATE_CHI flag controls if a separate .chi index file is generated ( -# YES) or that it should be included in the master .chm file ( NO). -# The default value is: NO. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -GENERATE_CHI = NO - -# The CHM_INDEX_ENCODING is used to encode HtmlHelp index ( hhk), content ( hhc) -# and project file content. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -CHM_INDEX_ENCODING = - -# The BINARY_TOC flag controls whether a binary table of contents is generated ( -# YES) or a normal table of contents ( NO) in the .chm file. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -BINARY_TOC = NO - -# The TOC_EXPAND flag can be set to YES to add extra items for group members to -# the table of contents of the HTML help documentation and to the tree view. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -TOC_EXPAND = NO - -# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and -# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated that -# can be used as input for Qt's qhelpgenerator to generate a Qt Compressed Help -# (.qch) of the generated HTML documentation. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -GENERATE_QHP = NO - -# If the QHG_LOCATION tag is specified, the QCH_FILE tag can be used to specify -# the file name of the resulting .qch file. The path specified is relative to -# the HTML output folder. -# This tag requires that the tag GENERATE_QHP is set to YES. - -QCH_FILE = - -# The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help -# Project output. For more information please see Qt Help Project / Namespace -# (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#namespace). -# The default value is: org.doxygen.Project. -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHP_NAMESPACE = org.doxygen.Project - -# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt -# Help Project output. For more information please see Qt Help Project / Virtual -# Folders (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#virtual- -# folders). -# The default value is: doc. -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHP_VIRTUAL_FOLDER = doc - -# If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom -# filter to add. For more information please see Qt Help Project / Custom -# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom- -# filters). -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHP_CUST_FILTER_NAME = - -# The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the -# custom filter to add. For more information please see Qt Help Project / Custom -# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom- -# filters). -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHP_CUST_FILTER_ATTRS = - -# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this -# project's filter section matches. Qt Help Project / Filter Attributes (see: -# http://qt-project.org/doc/qt-4.8/qthelpproject.html#filter-attributes). -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHP_SECT_FILTER_ATTRS = - -# The QHG_LOCATION tag can be used to specify the location of Qt's -# qhelpgenerator. If non-empty doxygen will try to run qhelpgenerator on the -# generated .qhp file. -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHG_LOCATION = - -# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files will be -# generated, together with the HTML files, they form an Eclipse help plugin. To -# install this plugin and make it available under the help contents menu in -# Eclipse, the contents of the directory containing the HTML and XML files needs -# to be copied into the plugins directory of eclipse. The name of the directory -# within the plugins directory should be the same as the ECLIPSE_DOC_ID value. -# After copying Eclipse needs to be restarted before the help appears. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -GENERATE_ECLIPSEHELP = NO - -# A unique identifier for the Eclipse help plugin. When installing the plugin -# the directory name containing the HTML and XML files should also have this -# name. Each documentation set should have its own identifier. -# The default value is: org.doxygen.Project. -# This tag requires that the tag GENERATE_ECLIPSEHELP is set to YES. - -ECLIPSE_DOC_ID = org.doxygen.Project - -# If you want full control over the layout of the generated HTML pages it might -# be necessary to disable the index and replace it with your own. The -# DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) at top -# of each HTML page. A value of NO enables the index and the value YES disables -# it. Since the tabs in the index contain the same information as the navigation -# tree, you can set this option to YES if you also set GENERATE_TREEVIEW to YES. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -DISABLE_INDEX = NO - -# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index -# structure should be generated to display hierarchical information. If the tag -# value is set to YES, a side panel will be generated containing a tree-like -# index structure (just like the one that is generated for HTML Help). For this -# to work a browser that supports JavaScript, DHTML, CSS and frames is required -# (i.e. any modern browser). Windows users are probably better off using the -# HTML help feature. Via custom stylesheets (see HTML_EXTRA_STYLESHEET) one can -# further fine-tune the look of the index. As an example, the default style -# sheet generated by doxygen has an example that shows how to put an image at -# the root of the tree instead of the PROJECT_NAME. Since the tree basically has -# the same information as the tab index, you could consider setting -# DISABLE_INDEX to YES when enabling this option. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -GENERATE_TREEVIEW = NO - -# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that -# doxygen will group on one line in the generated HTML documentation. -# -# Note that a value of 0 will completely suppress the enum values from appearing -# in the overview section. -# Minimum value: 0, maximum value: 20, default value: 4. -# This tag requires that the tag GENERATE_HTML is set to YES. - -ENUM_VALUES_PER_LINE = 4 - -# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be used -# to set the initial width (in pixels) of the frame in which the tree is shown. -# Minimum value: 0, maximum value: 1500, default value: 250. -# This tag requires that the tag GENERATE_HTML is set to YES. - -TREEVIEW_WIDTH = 250 - -# When the EXT_LINKS_IN_WINDOW option is set to YES doxygen will open links to -# external symbols imported via tag files in a separate window. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -EXT_LINKS_IN_WINDOW = NO - -# Use this tag to change the font size of LaTeX formulas included as images in -# the HTML documentation. When you change the font size after a successful -# doxygen run you need to manually remove any form_*.png images from the HTML -# output directory to force them to be regenerated. -# Minimum value: 8, maximum value: 50, default value: 10. -# This tag requires that the tag GENERATE_HTML is set to YES. - -FORMULA_FONTSIZE = 10 - -# Use the FORMULA_TRANPARENT tag to determine whether or not the images -# generated for formulas are transparent PNGs. Transparent PNGs are not -# supported properly for IE 6.0, but are supported on all modern browsers. -# -# Note that when changing this option you need to delete any form_*.png files in -# the HTML output directory before the changes have effect. -# The default value is: YES. -# This tag requires that the tag GENERATE_HTML is set to YES. - -FORMULA_TRANSPARENT = YES - -# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see -# http://www.mathjax.org) which uses client side Javascript for the rendering -# instead of using prerendered bitmaps. Use this if you do not have LaTeX -# installed or if you want to formulas look prettier in the HTML output. When -# enabled you may also need to install MathJax separately and configure the path -# to it using the MATHJAX_RELPATH option. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -USE_MATHJAX = NO - -# When MathJax is enabled you can set the default output format to be used for -# the MathJax output. See the MathJax site (see: -# http://docs.mathjax.org/en/latest/output.html) for more details. -# Possible values are: HTML-CSS (which is slower, but has the best -# compatibility), NativeMML (i.e. MathML) and SVG. -# The default value is: HTML-CSS. -# This tag requires that the tag USE_MATHJAX is set to YES. - -MATHJAX_FORMAT = HTML-CSS - -# When MathJax is enabled you need to specify the location relative to the HTML -# output directory using the MATHJAX_RELPATH option. The destination directory -# should contain the MathJax.js script. For instance, if the mathjax directory -# is located at the same level as the HTML output directory, then -# MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax -# Content Delivery Network so you can quickly see the result without installing -# MathJax. However, it is strongly recommended to install a local copy of -# MathJax from http://www.mathjax.org before deployment. -# The default value is: http://cdn.mathjax.org/mathjax/latest. -# This tag requires that the tag USE_MATHJAX is set to YES. - -MATHJAX_RELPATH = http://www.mathjax.org/mathjax - -# The MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax -# extension names that should be enabled during MathJax rendering. For example -# MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols -# This tag requires that the tag USE_MATHJAX is set to YES. - -MATHJAX_EXTENSIONS = - -# The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces -# of code that will be used on startup of the MathJax code. See the MathJax site -# (see: http://docs.mathjax.org/en/latest/output.html) for more details. For an -# example see the documentation. -# This tag requires that the tag USE_MATHJAX is set to YES. - -MATHJAX_CODEFILE = - -# When the SEARCHENGINE tag is enabled doxygen will generate a search box for -# the HTML output. The underlying search engine uses javascript and DHTML and -# should work on any modern browser. Note that when using HTML help -# (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets (GENERATE_DOCSET) -# there is already a search function so this one should typically be disabled. -# For large projects the javascript based search engine can be slow, then -# enabling SERVER_BASED_SEARCH may provide a better solution. It is possible to -# search using the keyboard; to jump to the search box use + S -# (what the is depends on the OS and browser, but it is typically -# , /