Merge branch 'dev'
This commit is contained in:
commit
e0c630f34f
62 changed files with 20038 additions and 3979 deletions
10
CHANGELOG.md
10
CHANGELOG.md
|
@ -1,3 +1,13 @@
|
||||||
|
# v6.10.0
|
||||||
|
- [#2122](https://github.com/xmrig/xmrig/pull/2122) Fixed pause logic when both pause on battery and user activity are enabled.
|
||||||
|
- [#2123](https://github.com/xmrig/xmrig/issues/2123) Fixed compatibility with gcc 4.8.
|
||||||
|
- [#2147](https://github.com/xmrig/xmrig/pull/2147) Fixed many `new job` messages when solo mining.
|
||||||
|
- [#2150](https://github.com/xmrig/xmrig/pull/2150) Updated `sse2neon.h` to the latest master, fixes build on ARMv7.
|
||||||
|
- [#2157](https://github.com/xmrig/xmrig/pull/2157) Fixed crash in `cn-heavy` on Zen3 with manual thread count.
|
||||||
|
- Fixed possible out of order write to log file.
|
||||||
|
- [http-parser](https://github.com/nodejs/http-parser) replaced to [llhttp](https://github.com/nodejs/llhttp).
|
||||||
|
- For official builds: libuv, hwloc and OpenSSL updated to latest versions.
|
||||||
|
|
||||||
# v6.9.0
|
# v6.9.0
|
||||||
- [#2104](https://github.com/xmrig/xmrig/pull/2104) Added [pause-on-active](https://xmrig.com/docs/miner/config/misc#pause-on-active) config option and `--pause-on-active=N` command line option.
|
- [#2104](https://github.com/xmrig/xmrig/pull/2104) Added [pause-on-active](https://xmrig.com/docs/miner/config/misc#pause-on-active) config option and `--pause-on-active=N` command line option.
|
||||||
- [#2112](https://github.com/xmrig/xmrig/pull/2112) Added support for [Tari merge mining](https://github.com/tari-project/tari/blob/development/README.md#tari-merge-mining).
|
- [#2112](https://github.com/xmrig/xmrig/pull/2112) Added support for [Tari merge mining](https://github.com/tari-project/tari/blob/development/README.md#tari-merge-mining).
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/bash -e
|
#!/bin/bash -e
|
||||||
|
|
||||||
HWLOC_VERSION="2.4.0"
|
HWLOC_VERSION="2.4.1"
|
||||||
|
|
||||||
mkdir -p deps
|
mkdir -p deps
|
||||||
mkdir -p deps/include
|
mkdir -p deps/include
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/bash -e
|
#!/bin/bash -e
|
||||||
|
|
||||||
OPENSSL_VERSION="1.1.1i"
|
OPENSSL_VERSION="1.1.1j"
|
||||||
|
|
||||||
mkdir -p deps
|
mkdir -p deps
|
||||||
mkdir -p deps/include
|
mkdir -p deps/include
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/bash -e
|
#!/bin/bash -e
|
||||||
|
|
||||||
UV_VERSION="1.40.0"
|
UV_VERSION="1.41.0"
|
||||||
|
|
||||||
mkdir -p deps
|
mkdir -p deps
|
||||||
mkdir -p deps/include
|
mkdir -p deps/include
|
||||||
|
|
68
src/3rdparty/http-parser/AUTHORS
vendored
68
src/3rdparty/http-parser/AUTHORS
vendored
|
@ -1,68 +0,0 @@
|
||||||
# Authors ordered by first contribution.
|
|
||||||
Ryan Dahl <ry@tinyclouds.org>
|
|
||||||
Jeremy Hinegardner <jeremy@hinegardner.org>
|
|
||||||
Sergey Shepelev <temotor@gmail.com>
|
|
||||||
Joe Damato <ice799@gmail.com>
|
|
||||||
tomika <tomika_nospam@freemail.hu>
|
|
||||||
Phoenix Sol <phoenix@burninglabs.com>
|
|
||||||
Cliff Frey <cliff@meraki.com>
|
|
||||||
Ewen Cheslack-Postava <ewencp@cs.stanford.edu>
|
|
||||||
Santiago Gala <sgala@apache.org>
|
|
||||||
Tim Becker <tim.becker@syngenio.de>
|
|
||||||
Jeff Terrace <jterrace@gmail.com>
|
|
||||||
Ben Noordhuis <info@bnoordhuis.nl>
|
|
||||||
Nathan Rajlich <nathan@tootallnate.net>
|
|
||||||
Mark Nottingham <mnot@mnot.net>
|
|
||||||
Aman Gupta <aman@tmm1.net>
|
|
||||||
Tim Becker <tim.becker@kuriositaet.de>
|
|
||||||
Sean Cunningham <sean.cunningham@mandiant.com>
|
|
||||||
Peter Griess <pg@std.in>
|
|
||||||
Salman Haq <salman.haq@asti-usa.com>
|
|
||||||
Cliff Frey <clifffrey@gmail.com>
|
|
||||||
Jon Kolb <jon@b0g.us>
|
|
||||||
Fouad Mardini <f.mardini@gmail.com>
|
|
||||||
Paul Querna <pquerna@apache.org>
|
|
||||||
Felix Geisendörfer <felix@debuggable.com>
|
|
||||||
koichik <koichik@improvement.jp>
|
|
||||||
Andre Caron <andre.l.caron@gmail.com>
|
|
||||||
Ivo Raisr <ivosh@ivosh.net>
|
|
||||||
James McLaughlin <jamie@lacewing-project.org>
|
|
||||||
David Gwynne <loki@animata.net>
|
|
||||||
Thomas LE ROUX <thomas@november-eleven.fr>
|
|
||||||
Randy Rizun <rrizun@ortivawireless.com>
|
|
||||||
Andre Louis Caron <andre.louis.caron@usherbrooke.ca>
|
|
||||||
Simon Zimmermann <simonz05@gmail.com>
|
|
||||||
Erik Dubbelboer <erik@dubbelboer.com>
|
|
||||||
Martell Malone <martellmalone@gmail.com>
|
|
||||||
Bertrand Paquet <bpaquet@octo.com>
|
|
||||||
BogDan Vatra <bogdan@kde.org>
|
|
||||||
Peter Faiman <peter@thepicard.org>
|
|
||||||
Corey Richardson <corey@octayn.net>
|
|
||||||
Tóth Tamás <tomika_nospam@freemail.hu>
|
|
||||||
Cam Swords <cam.swords@gmail.com>
|
|
||||||
Chris Dickinson <christopher.s.dickinson@gmail.com>
|
|
||||||
Uli Köhler <ukoehler@btronik.de>
|
|
||||||
Charlie Somerville <charlie@charliesomerville.com>
|
|
||||||
Patrik Stutz <patrik.stutz@gmail.com>
|
|
||||||
Fedor Indutny <fedor.indutny@gmail.com>
|
|
||||||
runner <runner.mei@gmail.com>
|
|
||||||
Alexis Campailla <alexis@janeasystems.com>
|
|
||||||
David Wragg <david@wragg.org>
|
|
||||||
Vinnie Falco <vinnie.falco@gmail.com>
|
|
||||||
Alex Butum <alexbutum@linux.com>
|
|
||||||
Rex Feng <rexfeng@gmail.com>
|
|
||||||
Alex Kocharin <alex@kocharin.ru>
|
|
||||||
Mark Koopman <markmontymark@yahoo.com>
|
|
||||||
Helge Heß <me@helgehess.eu>
|
|
||||||
Alexis La Goutte <alexis.lagoutte@gmail.com>
|
|
||||||
George Miroshnykov <george.miroshnykov@gmail.com>
|
|
||||||
Maciej Małecki <me@mmalecki.com>
|
|
||||||
Marc O'Morain <github.com@marcomorain.com>
|
|
||||||
Jeff Pinner <jpinner@twitter.com>
|
|
||||||
Timothy J Fontaine <tjfontaine@gmail.com>
|
|
||||||
Akagi201 <akagi201@gmail.com>
|
|
||||||
Romain Giraud <giraud.romain@gmail.com>
|
|
||||||
Jay Satiro <raysatiro@yahoo.com>
|
|
||||||
Arne Steen <Arne.Steen@gmx.de>
|
|
||||||
Kjell Schubert <kjell.schubert@gmail.com>
|
|
||||||
Olivier Mengué <dolmen@cpan.org>
|
|
19
src/3rdparty/http-parser/LICENSE-MIT
vendored
19
src/3rdparty/http-parser/LICENSE-MIT
vendored
|
@ -1,19 +0,0 @@
|
||||||
Copyright Joyent, Inc. and other Node contributors.
|
|
||||||
|
|
||||||
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.
|
|
246
src/3rdparty/http-parser/README.md
vendored
246
src/3rdparty/http-parser/README.md
vendored
|
@ -1,246 +0,0 @@
|
||||||
HTTP Parser
|
|
||||||
===========
|
|
||||||
|
|
||||||
[](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
|
|
||||||
applications. It does not make any syscalls nor allocations, it does not
|
|
||||||
buffer data, it can be interrupted at anytime. Depending on your
|
|
||||||
architecture, it only requires about 40 bytes of data per message
|
|
||||||
stream (in a web server that is per connection).
|
|
||||||
|
|
||||||
Features:
|
|
||||||
|
|
||||||
* No dependencies
|
|
||||||
* Handles persistent streams (keep-alive).
|
|
||||||
* Decodes chunked encoding.
|
|
||||||
* Upgrade support
|
|
||||||
* Defends against buffer overflow attacks.
|
|
||||||
|
|
||||||
The parser extracts the following information from HTTP messages:
|
|
||||||
|
|
||||||
* Header fields and values
|
|
||||||
* Content-Length
|
|
||||||
* Request method
|
|
||||||
* Response status code
|
|
||||||
* Transfer-Encoding
|
|
||||||
* HTTP version
|
|
||||||
* Request URL
|
|
||||||
* Message body
|
|
||||||
|
|
||||||
|
|
||||||
Usage
|
|
||||||
-----
|
|
||||||
|
|
||||||
One `http_parser` object is used per TCP connection. Initialize the struct
|
|
||||||
using `http_parser_init()` and set the callbacks. That might look something
|
|
||||||
like this for a request parser:
|
|
||||||
```c
|
|
||||||
http_parser_settings settings;
|
|
||||||
settings.on_url = my_url_callback;
|
|
||||||
settings.on_header_field = my_header_field_callback;
|
|
||||||
/* ... */
|
|
||||||
|
|
||||||
http_parser *parser = malloc(sizeof(http_parser));
|
|
||||||
http_parser_init(parser, HTTP_REQUEST);
|
|
||||||
parser->data = my_socket;
|
|
||||||
```
|
|
||||||
|
|
||||||
When data is received on the socket execute the parser and check for errors.
|
|
||||||
|
|
||||||
```c
|
|
||||||
size_t len = 80*1024, nparsed;
|
|
||||||
char buf[len];
|
|
||||||
ssize_t recved;
|
|
||||||
|
|
||||||
recved = recv(fd, buf, len, 0);
|
|
||||||
|
|
||||||
if (recved < 0) {
|
|
||||||
/* Handle error. */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Start up / continue the parser.
|
|
||||||
* Note we pass recved==0 to signal that EOF has been received.
|
|
||||||
*/
|
|
||||||
nparsed = http_parser_execute(parser, &settings, buf, recved);
|
|
||||||
|
|
||||||
if (parser->upgrade) {
|
|
||||||
/* handle new protocol */
|
|
||||||
} else if (nparsed != recved) {
|
|
||||||
/* Handle error. Usually just close the connection. */
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
`http_parser` needs to know where the end of the stream is. For example, sometimes
|
|
||||||
servers send responses without Content-Length and expect the client to
|
|
||||||
consume input (for the body) until EOF. To tell `http_parser` about EOF, give
|
|
||||||
`0` as the fourth parameter to `http_parser_execute()`. Callbacks and errors
|
|
||||||
can still be encountered during an EOF, so one must still be prepared
|
|
||||||
to receive them.
|
|
||||||
|
|
||||||
Scalar valued message information such as `status_code`, `method`, and the
|
|
||||||
HTTP version are stored in the parser structure. This data is only
|
|
||||||
temporally stored in `http_parser` and gets reset on each new message. If
|
|
||||||
this information is needed later, copy it out of the structure during the
|
|
||||||
`headers_complete` callback.
|
|
||||||
|
|
||||||
The parser decodes the transfer-encoding for both requests and responses
|
|
||||||
transparently. That is, a chunked encoding is decoded before being sent to
|
|
||||||
the on_body callback.
|
|
||||||
|
|
||||||
|
|
||||||
The Special Problem of Upgrade
|
|
||||||
------------------------------
|
|
||||||
|
|
||||||
`http_parser` supports upgrading the connection to a different protocol. An
|
|
||||||
increasingly common example of this is the WebSocket protocol which sends
|
|
||||||
a request like
|
|
||||||
|
|
||||||
GET /demo HTTP/1.1
|
|
||||||
Upgrade: WebSocket
|
|
||||||
Connection: Upgrade
|
|
||||||
Host: example.com
|
|
||||||
Origin: http://example.com
|
|
||||||
WebSocket-Protocol: sample
|
|
||||||
|
|
||||||
followed by non-HTTP data.
|
|
||||||
|
|
||||||
(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
|
|
||||||
http_parser_execute() will stop parsing at the end of the headers and return.
|
|
||||||
|
|
||||||
The user is expected to check if `parser->upgrade` has been set to 1 after
|
|
||||||
`http_parser_execute()` returns. Non-HTTP data begins at the buffer supplied
|
|
||||||
offset by the return value of `http_parser_execute()`.
|
|
||||||
|
|
||||||
|
|
||||||
Callbacks
|
|
||||||
---------
|
|
||||||
|
|
||||||
During the `http_parser_execute()` call, the callbacks set in
|
|
||||||
`http_parser_settings` will be executed. The parser maintains state and
|
|
||||||
never looks behind, so buffering the data is not necessary. If you need to
|
|
||||||
save certain data for later usage, you can do that from the callbacks.
|
|
||||||
|
|
||||||
There are two types of callbacks:
|
|
||||||
|
|
||||||
* notification `typedef int (*http_cb) (http_parser*);`
|
|
||||||
Callbacks: on_message_begin, on_headers_complete, on_message_complete.
|
|
||||||
* data `typedef int (*http_data_cb) (http_parser*, const char *at, size_t length);`
|
|
||||||
Callbacks: (requests only) on_url,
|
|
||||||
(common) on_header_field, on_header_value, on_body;
|
|
||||||
|
|
||||||
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:
|
|
||||||
```c
|
|
||||||
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
|
|
||||||
valid for the lifetime of callback. You can also `read()` into a heap allocated
|
|
||||||
buffer to avoid copying memory around if this fits your application.
|
|
||||||
|
|
||||||
Reading headers may be a tricky task if you read/parse headers partially.
|
|
||||||
Basically, you need to remember whether last header callback was field or value
|
|
||||||
and apply the following logic:
|
|
||||||
|
|
||||||
(on_header_field and on_header_value shortened to on_h_*)
|
|
||||||
------------------------ ------------ --------------------------------------------
|
|
||||||
| State (prev. callback) | Callback | Description/action |
|
|
||||||
------------------------ ------------ --------------------------------------------
|
|
||||||
| nothing (first call) | on_h_field | Allocate new buffer and copy callback data |
|
|
||||||
| | | into it |
|
|
||||||
------------------------ ------------ --------------------------------------------
|
|
||||||
| value | on_h_field | New header started. |
|
|
||||||
| | | Copy current name,value buffers to headers |
|
|
||||||
| | | list and allocate new buffer for new name |
|
|
||||||
------------------------ ------------ --------------------------------------------
|
|
||||||
| field | on_h_field | Previous name continues. Reallocate name |
|
|
||||||
| | | buffer and append callback data to it |
|
|
||||||
------------------------ ------------ --------------------------------------------
|
|
||||||
| field | on_h_value | Value for current header started. Allocate |
|
|
||||||
| | | new buffer and copy callback data to it |
|
|
||||||
------------------------ ------------ --------------------------------------------
|
|
||||||
| value | on_h_value | Value continues. Reallocate value buffer |
|
|
||||||
| | | and append callback data to it |
|
|
||||||
------------------------ ------------ --------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
Parsing URLs
|
|
||||||
------------
|
|
||||||
|
|
||||||
A simplistic zero-copy URL parser is provided as `http_parser_parse_url()`.
|
|
||||||
Users of this library may wish to use it to parse URLs constructed from
|
|
||||||
consecutive `on_url` callbacks.
|
|
||||||
|
|
||||||
See examples of reading in headers:
|
|
||||||
|
|
||||||
* [partial example](http://gist.github.com/155877) in C
|
|
||||||
* [from http-parser tests](http://github.com/joyent/http-parser/blob/37a0ff8/test.c#L403) in C
|
|
||||||
* [from Node library](http://github.com/joyent/node/blob/842eaf4/src/http.js#L284) in Javascript
|
|
2565
src/3rdparty/http-parser/http_parser.c
vendored
2565
src/3rdparty/http-parser/http_parser.c
vendored
File diff suppressed because it is too large
Load diff
442
src/3rdparty/http-parser/http_parser.h
vendored
442
src/3rdparty/http-parser/http_parser.h
vendored
|
@ -1,442 +0,0 @@
|
||||||
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
#ifndef http_parser_h
|
|
||||||
#define http_parser_h
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Also update SONAME in the Makefile whenever you change these. */
|
|
||||||
#define HTTP_PARSER_VERSION_MAJOR 2
|
|
||||||
#define HTTP_PARSER_VERSION_MINOR 9
|
|
||||||
#define HTTP_PARSER_VERSION_PATCH 3
|
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
#if defined(_WIN32) && !defined(__MINGW32__) && \
|
|
||||||
(!defined(_MSC_VER) || _MSC_VER<1600) && !defined(__WINE__)
|
|
||||||
#include <BaseTsd.h>
|
|
||||||
typedef __int8 int8_t;
|
|
||||||
typedef unsigned __int8 uint8_t;
|
|
||||||
typedef __int16 int16_t;
|
|
||||||
typedef unsigned __int16 uint16_t;
|
|
||||||
typedef __int32 int32_t;
|
|
||||||
typedef unsigned __int32 uint32_t;
|
|
||||||
typedef __int64 int64_t;
|
|
||||||
typedef unsigned __int64 uint64_t;
|
|
||||||
#else
|
|
||||||
#include <stdint.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Compile with -DHTTP_PARSER_STRICT=0 to make less checks, but run
|
|
||||||
* faster
|
|
||||||
*/
|
|
||||||
#ifndef HTTP_PARSER_STRICT
|
|
||||||
# define HTTP_PARSER_STRICT 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Maximium header size allowed. If the macro is not defined
|
|
||||||
* before including this header then the default is used. To
|
|
||||||
* change the maximum header size, define the macro in the build
|
|
||||||
* environment (e.g. -DHTTP_MAX_HEADER_SIZE=<value>). To remove
|
|
||||||
* the effective limit on the size of the header, define the macro
|
|
||||||
* to a very large number (e.g. -DHTTP_MAX_HEADER_SIZE=0x7fffffff)
|
|
||||||
*/
|
|
||||||
#ifndef HTTP_MAX_HEADER_SIZE
|
|
||||||
# define HTTP_MAX_HEADER_SIZE (80*1024)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct http_parser http_parser;
|
|
||||||
typedef struct http_parser_settings http_parser_settings;
|
|
||||||
|
|
||||||
|
|
||||||
/* Callbacks should return non-zero to indicate an error. The parser will
|
|
||||||
* then halt execution.
|
|
||||||
*
|
|
||||||
* The one exception is on_headers_complete. In a HTTP_RESPONSE parser
|
|
||||||
* returning '1' from on_headers_complete will tell the parser that it
|
|
||||||
* should not expect a body. This is used when receiving a response to a
|
|
||||||
* HEAD request which may contain 'Content-Length' or 'Transfer-Encoding:
|
|
||||||
* chunked' headers that indicate the presence of a body.
|
|
||||||
*
|
|
||||||
* Returning `2` from on_headers_complete will tell parser that it should not
|
|
||||||
* expect neither a body nor any futher responses on this connection. This is
|
|
||||||
* useful for handling responses to a CONNECT request which may not contain
|
|
||||||
* `Upgrade` or `Connection: upgrade` headers.
|
|
||||||
*
|
|
||||||
* http_data_cb does not return data chunks. It will be called arbitrarily
|
|
||||||
* many times for each string. E.G. you might get 10 callbacks for "on_url"
|
|
||||||
* each providing just a few characters more data.
|
|
||||||
*/
|
|
||||||
typedef int (*http_data_cb) (http_parser*, const char *at, size_t length);
|
|
||||||
typedef int (*http_cb) (http_parser*);
|
|
||||||
|
|
||||||
|
|
||||||
/* Status Codes */
|
|
||||||
#define HTTP_STATUS_MAP(XX) \
|
|
||||||
XX(100, CONTINUE, Continue) \
|
|
||||||
XX(101, SWITCHING_PROTOCOLS, Switching Protocols) \
|
|
||||||
XX(102, PROCESSING, Processing) \
|
|
||||||
XX(200, OK, OK) \
|
|
||||||
XX(201, CREATED, Created) \
|
|
||||||
XX(202, ACCEPTED, Accepted) \
|
|
||||||
XX(203, NON_AUTHORITATIVE_INFORMATION, Non-Authoritative Information) \
|
|
||||||
XX(204, NO_CONTENT, No Content) \
|
|
||||||
XX(205, RESET_CONTENT, Reset Content) \
|
|
||||||
XX(206, PARTIAL_CONTENT, Partial Content) \
|
|
||||||
XX(207, MULTI_STATUS, Multi-Status) \
|
|
||||||
XX(208, ALREADY_REPORTED, Already Reported) \
|
|
||||||
XX(226, IM_USED, IM Used) \
|
|
||||||
XX(300, MULTIPLE_CHOICES, Multiple Choices) \
|
|
||||||
XX(301, MOVED_PERMANENTLY, Moved Permanently) \
|
|
||||||
XX(302, FOUND, Found) \
|
|
||||||
XX(303, SEE_OTHER, See Other) \
|
|
||||||
XX(304, NOT_MODIFIED, Not Modified) \
|
|
||||||
XX(305, USE_PROXY, Use Proxy) \
|
|
||||||
XX(307, TEMPORARY_REDIRECT, Temporary Redirect) \
|
|
||||||
XX(308, PERMANENT_REDIRECT, Permanent Redirect) \
|
|
||||||
XX(400, BAD_REQUEST, Bad Request) \
|
|
||||||
XX(401, UNAUTHORIZED, Unauthorized) \
|
|
||||||
XX(402, PAYMENT_REQUIRED, Payment Required) \
|
|
||||||
XX(403, FORBIDDEN, Forbidden) \
|
|
||||||
XX(404, NOT_FOUND, Not Found) \
|
|
||||||
XX(405, METHOD_NOT_ALLOWED, Method Not Allowed) \
|
|
||||||
XX(406, NOT_ACCEPTABLE, Not Acceptable) \
|
|
||||||
XX(407, PROXY_AUTHENTICATION_REQUIRED, Proxy Authentication Required) \
|
|
||||||
XX(408, REQUEST_TIMEOUT, Request Timeout) \
|
|
||||||
XX(409, CONFLICT, Conflict) \
|
|
||||||
XX(410, GONE, Gone) \
|
|
||||||
XX(411, LENGTH_REQUIRED, Length Required) \
|
|
||||||
XX(412, PRECONDITION_FAILED, Precondition Failed) \
|
|
||||||
XX(413, PAYLOAD_TOO_LARGE, Payload Too Large) \
|
|
||||||
XX(414, URI_TOO_LONG, URI Too Long) \
|
|
||||||
XX(415, UNSUPPORTED_MEDIA_TYPE, Unsupported Media Type) \
|
|
||||||
XX(416, RANGE_NOT_SATISFIABLE, Range Not Satisfiable) \
|
|
||||||
XX(417, EXPECTATION_FAILED, Expectation Failed) \
|
|
||||||
XX(421, MISDIRECTED_REQUEST, Misdirected Request) \
|
|
||||||
XX(422, UNPROCESSABLE_ENTITY, Unprocessable Entity) \
|
|
||||||
XX(423, LOCKED, Locked) \
|
|
||||||
XX(424, FAILED_DEPENDENCY, Failed Dependency) \
|
|
||||||
XX(426, UPGRADE_REQUIRED, Upgrade Required) \
|
|
||||||
XX(428, PRECONDITION_REQUIRED, Precondition Required) \
|
|
||||||
XX(429, TOO_MANY_REQUESTS, Too Many Requests) \
|
|
||||||
XX(431, REQUEST_HEADER_FIELDS_TOO_LARGE, Request Header Fields Too Large) \
|
|
||||||
XX(451, UNAVAILABLE_FOR_LEGAL_REASONS, Unavailable For Legal Reasons) \
|
|
||||||
XX(500, INTERNAL_SERVER_ERROR, Internal Server Error) \
|
|
||||||
XX(501, NOT_IMPLEMENTED, Not Implemented) \
|
|
||||||
XX(502, BAD_GATEWAY, Bad Gateway) \
|
|
||||||
XX(503, SERVICE_UNAVAILABLE, Service Unavailable) \
|
|
||||||
XX(504, GATEWAY_TIMEOUT, Gateway Timeout) \
|
|
||||||
XX(505, HTTP_VERSION_NOT_SUPPORTED, HTTP Version Not Supported) \
|
|
||||||
XX(506, VARIANT_ALSO_NEGOTIATES, Variant Also Negotiates) \
|
|
||||||
XX(507, INSUFFICIENT_STORAGE, Insufficient Storage) \
|
|
||||||
XX(508, LOOP_DETECTED, Loop Detected) \
|
|
||||||
XX(510, NOT_EXTENDED, Not Extended) \
|
|
||||||
XX(511, NETWORK_AUTHENTICATION_REQUIRED, Network Authentication Required) \
|
|
||||||
|
|
||||||
enum http_status
|
|
||||||
{
|
|
||||||
#define XX(num, name, string) HTTP_STATUS_##name = num,
|
|
||||||
HTTP_STATUS_MAP(XX)
|
|
||||||
#undef XX
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/* Request Methods */
|
|
||||||
#define HTTP_METHOD_MAP(XX) \
|
|
||||||
XX(0, DELETE, DELETE) \
|
|
||||||
XX(1, GET, GET) \
|
|
||||||
XX(2, HEAD, HEAD) \
|
|
||||||
XX(3, POST, POST) \
|
|
||||||
XX(4, PUT, PUT) \
|
|
||||||
/* pathological */ \
|
|
||||||
XX(5, CONNECT, CONNECT) \
|
|
||||||
XX(6, OPTIONS, OPTIONS) \
|
|
||||||
XX(7, TRACE, TRACE) \
|
|
||||||
/* WebDAV */ \
|
|
||||||
XX(8, COPY, COPY) \
|
|
||||||
XX(9, LOCK, LOCK) \
|
|
||||||
XX(10, MKCOL, MKCOL) \
|
|
||||||
XX(11, MOVE, MOVE) \
|
|
||||||
XX(12, PROPFIND, PROPFIND) \
|
|
||||||
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(20, REPORT, REPORT) \
|
|
||||||
XX(21, MKACTIVITY, MKACTIVITY) \
|
|
||||||
XX(22, CHECKOUT, CHECKOUT) \
|
|
||||||
XX(23, MERGE, MERGE) \
|
|
||||||
/* upnp */ \
|
|
||||||
XX(24, MSEARCH, M-SEARCH) \
|
|
||||||
XX(25, NOTIFY, NOTIFY) \
|
|
||||||
XX(26, SUBSCRIBE, SUBSCRIBE) \
|
|
||||||
XX(27, UNSUBSCRIBE, UNSUBSCRIBE) \
|
|
||||||
/* RFC-5789 */ \
|
|
||||||
XX(28, PATCH, PATCH) \
|
|
||||||
XX(29, PURGE, PURGE) \
|
|
||||||
/* CalDAV */ \
|
|
||||||
XX(30, MKCALENDAR, MKCALENDAR) \
|
|
||||||
/* RFC-2068, section 19.6.1.2 */ \
|
|
||||||
XX(31, LINK, LINK) \
|
|
||||||
XX(32, UNLINK, UNLINK) \
|
|
||||||
/* icecast */ \
|
|
||||||
XX(33, SOURCE, SOURCE) \
|
|
||||||
|
|
||||||
enum http_method
|
|
||||||
{
|
|
||||||
#define XX(num, name, string) HTTP_##name = num,
|
|
||||||
HTTP_METHOD_MAP(XX)
|
|
||||||
#undef XX
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
enum http_parser_type { HTTP_REQUEST, HTTP_RESPONSE, HTTP_BOTH };
|
|
||||||
|
|
||||||
|
|
||||||
/* Flag values for http_parser.flags field */
|
|
||||||
enum flags
|
|
||||||
{ F_CHUNKED = 1 << 0
|
|
||||||
, F_CONNECTION_KEEP_ALIVE = 1 << 1
|
|
||||||
, F_CONNECTION_CLOSE = 1 << 2
|
|
||||||
, F_CONNECTION_UPGRADE = 1 << 3
|
|
||||||
, F_TRAILING = 1 << 4
|
|
||||||
, F_UPGRADE = 1 << 5
|
|
||||||
, F_SKIPBODY = 1 << 6
|
|
||||||
, F_CONTENTLENGTH = 1 << 7
|
|
||||||
, F_TRANSFER_ENCODING = 1 << 8
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/* Map for errno-related constants
|
|
||||||
*
|
|
||||||
* The provided argument should be a macro that takes 2 arguments.
|
|
||||||
*/
|
|
||||||
#define HTTP_ERRNO_MAP(XX) \
|
|
||||||
/* No error */ \
|
|
||||||
XX(OK, "success") \
|
|
||||||
\
|
|
||||||
/* Callback-related errors */ \
|
|
||||||
XX(CB_message_begin, "the on_message_begin callback failed") \
|
|
||||||
XX(CB_url, "the on_url callback failed") \
|
|
||||||
XX(CB_header_field, "the on_header_field callback failed") \
|
|
||||||
XX(CB_header_value, "the on_header_value callback failed") \
|
|
||||||
XX(CB_headers_complete, "the on_headers_complete callback failed") \
|
|
||||||
XX(CB_body, "the on_body callback failed") \
|
|
||||||
XX(CB_message_complete, "the on_message_complete callback failed") \
|
|
||||||
XX(CB_status, "the on_status callback failed") \
|
|
||||||
XX(CB_chunk_header, "the on_chunk_header callback failed") \
|
|
||||||
XX(CB_chunk_complete, "the on_chunk_complete callback failed") \
|
|
||||||
\
|
|
||||||
/* Parsing-related errors */ \
|
|
||||||
XX(INVALID_EOF_STATE, "stream ended at an unexpected time") \
|
|
||||||
XX(HEADER_OVERFLOW, \
|
|
||||||
"too many header bytes seen; overflow detected") \
|
|
||||||
XX(CLOSED_CONNECTION, \
|
|
||||||
"data received after completed connection: close message") \
|
|
||||||
XX(INVALID_VERSION, "invalid HTTP version") \
|
|
||||||
XX(INVALID_STATUS, "invalid HTTP status code") \
|
|
||||||
XX(INVALID_METHOD, "invalid HTTP method") \
|
|
||||||
XX(INVALID_URL, "invalid URL") \
|
|
||||||
XX(INVALID_HOST, "invalid host") \
|
|
||||||
XX(INVALID_PORT, "invalid port") \
|
|
||||||
XX(INVALID_PATH, "invalid path") \
|
|
||||||
XX(INVALID_QUERY_STRING, "invalid query string") \
|
|
||||||
XX(INVALID_FRAGMENT, "invalid fragment") \
|
|
||||||
XX(LF_EXPECTED, "LF character expected") \
|
|
||||||
XX(INVALID_HEADER_TOKEN, "invalid character in header") \
|
|
||||||
XX(INVALID_CONTENT_LENGTH, \
|
|
||||||
"invalid character in content-length header") \
|
|
||||||
XX(UNEXPECTED_CONTENT_LENGTH, \
|
|
||||||
"unexpected content-length header") \
|
|
||||||
XX(INVALID_CHUNK_SIZE, \
|
|
||||||
"invalid character in chunk size header") \
|
|
||||||
XX(INVALID_TRANSFER_ENCODING, \
|
|
||||||
"request has invalid transfer-encoding") \
|
|
||||||
XX(INVALID_CONSTANT, "invalid constant string") \
|
|
||||||
XX(INVALID_INTERNAL_STATE, "encountered unexpected internal state")\
|
|
||||||
XX(STRICT, "strict mode assertion failed") \
|
|
||||||
XX(PAUSED, "parser is paused") \
|
|
||||||
XX(UNKNOWN, "an unknown error occurred")
|
|
||||||
|
|
||||||
|
|
||||||
/* Define HPE_* values for each errno value above */
|
|
||||||
#define HTTP_ERRNO_GEN(n, s) HPE_##n,
|
|
||||||
enum http_errno {
|
|
||||||
HTTP_ERRNO_MAP(HTTP_ERRNO_GEN)
|
|
||||||
};
|
|
||||||
#undef HTTP_ERRNO_GEN
|
|
||||||
|
|
||||||
|
|
||||||
/* Get an http_errno value from an http_parser */
|
|
||||||
#define HTTP_PARSER_ERRNO(p) ((enum http_errno) (p)->http_errno)
|
|
||||||
|
|
||||||
|
|
||||||
struct http_parser {
|
|
||||||
/** PRIVATE **/
|
|
||||||
unsigned int type : 2; /* enum http_parser_type */
|
|
||||||
unsigned int state : 7; /* enum state from http_parser.c */
|
|
||||||
unsigned int header_state : 7; /* enum header_state from http_parser.c */
|
|
||||||
unsigned int index : 7; /* index into current matcher */
|
|
||||||
unsigned int lenient_http_headers : 1;
|
|
||||||
unsigned int flags : 16; /* F_* values from 'flags' enum; semi-public */
|
|
||||||
|
|
||||||
uint32_t nread; /* # bytes read in various scenarios */
|
|
||||||
uint64_t content_length; /* # bytes in body (0 if no Content-Length header) */
|
|
||||||
|
|
||||||
/** READ-ONLY **/
|
|
||||||
unsigned short http_major;
|
|
||||||
unsigned short http_minor;
|
|
||||||
unsigned int status_code : 16; /* responses only */
|
|
||||||
unsigned int method : 8; /* requests only */
|
|
||||||
unsigned int http_errno : 7;
|
|
||||||
|
|
||||||
/* 1 = Upgrade header was present and the parser has exited because of that.
|
|
||||||
* 0 = No upgrade header present.
|
|
||||||
* Should be checked when http_parser_execute() returns in addition to
|
|
||||||
* error checking.
|
|
||||||
*/
|
|
||||||
unsigned int upgrade : 1;
|
|
||||||
|
|
||||||
/** PUBLIC **/
|
|
||||||
void *data; /* A pointer to get hook to the "connection" or "socket" object */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct http_parser_settings {
|
|
||||||
http_cb on_message_begin;
|
|
||||||
http_data_cb on_url;
|
|
||||||
http_data_cb on_status;
|
|
||||||
http_data_cb on_header_field;
|
|
||||||
http_data_cb on_header_value;
|
|
||||||
http_cb on_headers_complete;
|
|
||||||
http_data_cb on_body;
|
|
||||||
http_cb on_message_complete;
|
|
||||||
/* When on_chunk_header is called, the current chunk length is stored
|
|
||||||
* in parser->content_length.
|
|
||||||
*/
|
|
||||||
http_cb on_chunk_header;
|
|
||||||
http_cb on_chunk_complete;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
enum http_parser_url_fields
|
|
||||||
{ UF_SCHEMA = 0
|
|
||||||
, UF_HOST = 1
|
|
||||||
, UF_PORT = 2
|
|
||||||
, UF_PATH = 3
|
|
||||||
, UF_QUERY = 4
|
|
||||||
, UF_FRAGMENT = 5
|
|
||||||
, UF_USERINFO = 6
|
|
||||||
, UF_MAX = 7
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/* Result structure for http_parser_parse_url().
|
|
||||||
*
|
|
||||||
* Callers should index into field_data[] with UF_* values iff field_set
|
|
||||||
* has the relevant (1 << UF_*) bit set. As a courtesy to clients (and
|
|
||||||
* because we probably have padding left over), we convert any port to
|
|
||||||
* a uint16_t.
|
|
||||||
*/
|
|
||||||
struct http_parser_url {
|
|
||||||
uint16_t field_set; /* Bitmask of (1 << UF_*) values */
|
|
||||||
uint16_t port; /* Converted UF_PORT string */
|
|
||||||
|
|
||||||
struct {
|
|
||||||
uint16_t off; /* Offset into buffer in which field starts */
|
|
||||||
uint16_t len; /* Length of run in buffer */
|
|
||||||
} field_data[UF_MAX];
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/* Returns the library version. Bits 16-23 contain the major version number,
|
|
||||||
* bits 8-15 the minor version number and bits 0-7 the patch level.
|
|
||||||
* Usage example:
|
|
||||||
*
|
|
||||||
* unsigned long version = http_parser_version();
|
|
||||||
* unsigned major = (version >> 16) & 255;
|
|
||||||
* unsigned minor = (version >> 8) & 255;
|
|
||||||
* unsigned patch = version & 255;
|
|
||||||
* printf("http_parser v%u.%u.%u\n", major, minor, patch);
|
|
||||||
*/
|
|
||||||
unsigned long http_parser_version(void);
|
|
||||||
|
|
||||||
void http_parser_init(http_parser *parser, enum http_parser_type type);
|
|
||||||
|
|
||||||
|
|
||||||
/* Initialize http_parser_settings members to 0
|
|
||||||
*/
|
|
||||||
void http_parser_settings_init(http_parser_settings *settings);
|
|
||||||
|
|
||||||
|
|
||||||
/* Executes the parser. Returns number of parsed bytes. Sets
|
|
||||||
* `parser->http_errno` on error. */
|
|
||||||
size_t http_parser_execute(http_parser *parser,
|
|
||||||
const http_parser_settings *settings,
|
|
||||||
const char *data,
|
|
||||||
size_t len);
|
|
||||||
|
|
||||||
|
|
||||||
/* If http_should_keep_alive() in the on_headers_complete or
|
|
||||||
* on_message_complete callback returns 0, then this should be
|
|
||||||
* the last message on the connection.
|
|
||||||
* If you are the server, respond with the "Connection: close" header.
|
|
||||||
* If you are the client, close the connection.
|
|
||||||
*/
|
|
||||||
int http_should_keep_alive(const http_parser *parser);
|
|
||||||
|
|
||||||
/* Returns a string version of the HTTP method. */
|
|
||||||
const char *http_method_str(enum http_method m);
|
|
||||||
|
|
||||||
/* Returns a string version of the HTTP status code. */
|
|
||||||
const char *http_status_str(enum http_status s);
|
|
||||||
|
|
||||||
/* Return a string name of the given error */
|
|
||||||
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,
|
|
||||||
struct http_parser_url *u);
|
|
||||||
|
|
||||||
/* Pause or un-pause the parser; a nonzero value pauses */
|
|
||||||
void http_parser_pause(http_parser *parser, int paused);
|
|
||||||
|
|
||||||
/* Checks if this is the final chunk of the body. */
|
|
||||||
int http_body_is_final(const http_parser *parser);
|
|
||||||
|
|
||||||
/* Change the maximum header size provided at compile time. */
|
|
||||||
void http_parser_set_max_header_size(uint32_t size);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif
|
|
53
src/3rdparty/hwloc/include/hwloc.h
vendored
53
src/3rdparty/hwloc/include/hwloc.h
vendored
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright © 2009 CNRS
|
* Copyright © 2009 CNRS
|
||||||
* Copyright © 2009-2020 Inria. All rights reserved.
|
* Copyright © 2009-2021 Inria. All rights reserved.
|
||||||
* Copyright © 2009-2012 Université Bordeaux
|
* Copyright © 2009-2012 Université Bordeaux
|
||||||
* Copyright © 2009-2020 Cisco Systems, Inc. All rights reserved.
|
* Copyright © 2009-2020 Cisco Systems, Inc. All rights reserved.
|
||||||
* See COPYING in top-level directory.
|
* See COPYING in top-level directory.
|
||||||
|
@ -2362,22 +2362,9 @@ HWLOC_DECLSPEC hwloc_obj_t hwloc_topology_insert_misc_object(hwloc_topology_t to
|
||||||
/** \brief Allocate a Group object to insert later with hwloc_topology_insert_group_object().
|
/** \brief Allocate a Group object to insert later with hwloc_topology_insert_group_object().
|
||||||
*
|
*
|
||||||
* This function returns a new Group object.
|
* This function returns a new Group object.
|
||||||
* The caller should (at least) initialize its sets before inserting the object.
|
|
||||||
* See hwloc_topology_insert_group_object().
|
|
||||||
*
|
*
|
||||||
* The \p subtype object attribute may be set to display something else
|
* The caller should (at least) initialize its sets before inserting
|
||||||
* than "Group" as the type name for this object in lstopo.
|
* the object in the topology. See hwloc_topology_insert_group_object().
|
||||||
* Custom name/value info pairs may be added with hwloc_obj_add_info() after
|
|
||||||
* insertion.
|
|
||||||
*
|
|
||||||
* The \p kind group attribute should be 0. The \p subkind group attribute may
|
|
||||||
* be set to identify multiple Groups of the same level.
|
|
||||||
*
|
|
||||||
* It is recommended not to set any other object attribute before insertion,
|
|
||||||
* since the Group may get discarded during insertion.
|
|
||||||
*
|
|
||||||
* The object will be destroyed if passed to hwloc_topology_insert_group_object()
|
|
||||||
* without any set defined.
|
|
||||||
*/
|
*/
|
||||||
HWLOC_DECLSPEC hwloc_obj_t hwloc_topology_alloc_group_object(hwloc_topology_t topology);
|
HWLOC_DECLSPEC hwloc_obj_t hwloc_topology_alloc_group_object(hwloc_topology_t topology);
|
||||||
|
|
||||||
|
@ -2388,34 +2375,44 @@ HWLOC_DECLSPEC hwloc_obj_t hwloc_topology_alloc_group_object(hwloc_topology_t to
|
||||||
* the final location of the Group in the topology.
|
* the final location of the Group in the topology.
|
||||||
* Then the object can be passed to this function for actual insertion in the topology.
|
* Then the object can be passed to this function for actual insertion in the topology.
|
||||||
*
|
*
|
||||||
* The group \p dont_merge attribute may be set to prevent the core from
|
|
||||||
* ever merging this object with another object hierarchically-identical.
|
|
||||||
*
|
|
||||||
* Either the cpuset or nodeset field (or both, if compatible) must be set
|
* Either the cpuset or nodeset field (or both, if compatible) must be set
|
||||||
* to a non-empty bitmap. The complete_cpuset or complete_nodeset may be set
|
* to a non-empty bitmap. The complete_cpuset or complete_nodeset may be set
|
||||||
* instead if inserting with respect to the complete topology
|
* instead if inserting with respect to the complete topology
|
||||||
* (including disallowed, offline or unknown objects).
|
* (including disallowed, offline or unknown objects).
|
||||||
*
|
* If grouping several objects, hwloc_obj_add_other_obj_sets() is an easy way
|
||||||
* It grouping several objects, hwloc_obj_add_other_obj_sets() is an easy way
|
|
||||||
* to build the Group sets iteratively.
|
* to build the Group sets iteratively.
|
||||||
*
|
|
||||||
* These sets cannot be larger than the current topology, or they would get
|
* These sets cannot be larger than the current topology, or they would get
|
||||||
* restricted silently.
|
* restricted silently.
|
||||||
*
|
|
||||||
* The core will setup the other sets after actual insertion.
|
* The core will setup the other sets after actual insertion.
|
||||||
*
|
*
|
||||||
|
* The \p subtype object attribute may be defined (to a dynamically
|
||||||
|
* allocated string) to display something else than "Group" as the
|
||||||
|
* type name for this object in lstopo.
|
||||||
|
* Custom name/value info pairs may be added with hwloc_obj_add_info() after
|
||||||
|
* insertion.
|
||||||
|
*
|
||||||
|
* The group \p dont_merge attribute may be set to \c 1 to prevent
|
||||||
|
* the hwloc core from ever merging this object with another
|
||||||
|
* hierarchically-identical object.
|
||||||
|
* This is useful when the Group itself describes an important feature
|
||||||
|
* that cannot be exposed anywhere else in the hierarchy.
|
||||||
|
*
|
||||||
|
* The group \p kind attribute may be set to a high value such
|
||||||
|
* as \c 0xffffffff to tell hwloc that this new Group should always
|
||||||
|
* be discarded in favor of any existing Group with the same locality.
|
||||||
|
*
|
||||||
* \return The inserted object if it was properly inserted.
|
* \return The inserted object if it was properly inserted.
|
||||||
*
|
*
|
||||||
* \return An existing object if the Group was discarded because the topology already
|
* \return An existing object if the Group was merged or discarded
|
||||||
* contained an object at the same location (the Group did not add any locality information).
|
* because the topology already contained an object at the same
|
||||||
* Any name/info key pair set before inserting is appended to the existing object.
|
* location (the Group did not add any hierarchy information).
|
||||||
*
|
*
|
||||||
* \return \c NULL if the insertion failed because of conflicting sets in topology tree.
|
* \return \c NULL if the insertion failed because of conflicting sets in topology tree.
|
||||||
*
|
*
|
||||||
* \return \c NULL if Group objects are filtered-out of the topology (::HWLOC_TYPE_FILTER_KEEP_NONE).
|
* \return \c NULL if Group objects are filtered-out of the topology (::HWLOC_TYPE_FILTER_KEEP_NONE).
|
||||||
*
|
*
|
||||||
* \return \c NULL if the object was discarded because no set was initialized in the Group
|
* \return \c NULL if the object was discarded because no set was
|
||||||
* before insert, or all of them were empty.
|
* initialized in the Group before insert, or all of them were empty.
|
||||||
*/
|
*/
|
||||||
HWLOC_DECLSPEC hwloc_obj_t hwloc_topology_insert_group_object(hwloc_topology_t topology, hwloc_obj_t group);
|
HWLOC_DECLSPEC hwloc_obj_t hwloc_topology_insert_group_object(hwloc_topology_t topology, hwloc_obj_t group);
|
||||||
|
|
||||||
|
|
|
@ -11,10 +11,10 @@
|
||||||
#ifndef HWLOC_CONFIG_H
|
#ifndef HWLOC_CONFIG_H
|
||||||
#define HWLOC_CONFIG_H
|
#define HWLOC_CONFIG_H
|
||||||
|
|
||||||
#define HWLOC_VERSION "2.4.0"
|
#define HWLOC_VERSION "2.4.1"
|
||||||
#define HWLOC_VERSION_MAJOR 2
|
#define HWLOC_VERSION_MAJOR 2
|
||||||
#define HWLOC_VERSION_MINOR 4
|
#define HWLOC_VERSION_MINOR 4
|
||||||
#define HWLOC_VERSION_RELEASE 0
|
#define HWLOC_VERSION_RELEASE 1
|
||||||
#define HWLOC_VERSION_GREEK ""
|
#define HWLOC_VERSION_GREEK ""
|
||||||
|
|
||||||
#define __hwloc_restrict
|
#define __hwloc_restrict
|
||||||
|
|
9
src/3rdparty/hwloc/include/hwloc/opencl.h
vendored
9
src/3rdparty/hwloc/include/hwloc/opencl.h
vendored
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright © 2012-2020 Inria. All rights reserved.
|
* Copyright © 2012-2021 Inria. All rights reserved.
|
||||||
* Copyright © 2013, 2018 Université Bordeaux. All right reserved.
|
* Copyright © 2013, 2018 Université Bordeaux. All right reserved.
|
||||||
* See COPYING in top-level directory.
|
* See COPYING in top-level directory.
|
||||||
*/
|
*/
|
||||||
|
@ -82,9 +82,10 @@ hwloc_opencl_get_device_pci_busid(cl_device_id device,
|
||||||
if (CL_SUCCESS == clret
|
if (CL_SUCCESS == clret
|
||||||
&& HWLOC_CL_DEVICE_TOPOLOGY_TYPE_PCIE_AMD == amdtopo.raw.type) {
|
&& HWLOC_CL_DEVICE_TOPOLOGY_TYPE_PCIE_AMD == amdtopo.raw.type) {
|
||||||
*domain = 0; /* can't do anything better */
|
*domain = 0; /* can't do anything better */
|
||||||
*bus = (unsigned) amdtopo.pcie.bus;
|
/* cl_device_topology_amd stores bus ID in cl_char, dont convert those signed char directly to unsigned int */
|
||||||
*dev = (unsigned) amdtopo.pcie.device;
|
*bus = (unsigned) (unsigned char) amdtopo.pcie.bus;
|
||||||
*func = (unsigned) amdtopo.pcie.function;
|
*dev = (unsigned) (unsigned char) amdtopo.pcie.device;
|
||||||
|
*func = (unsigned) (unsigned char) amdtopo.pcie.function;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
201
src/3rdparty/hwloc/include/hwloc/rsmi.h
vendored
Normal file
201
src/3rdparty/hwloc/include/hwloc/rsmi.h
vendored
Normal file
|
@ -0,0 +1,201 @@
|
||||||
|
/*
|
||||||
|
* Copyright © 2012-2020 Inria. All rights reserved.
|
||||||
|
* Copyright (c) 2020, Advanced Micro Devices, Inc. All rights reserved.
|
||||||
|
* Written by Advanced Micro Devices,
|
||||||
|
* See COPYING in top-level directory.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** \file
|
||||||
|
* \brief Macros to help interaction between hwloc and the ROCm SMI Management Library.
|
||||||
|
*
|
||||||
|
* Applications that use both hwloc and the ROCm SMI Management Library may want to
|
||||||
|
* include this file so as to get topology information for AMD GPU devices.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef HWLOC_RSMI_H
|
||||||
|
#define HWLOC_RSMI_H
|
||||||
|
|
||||||
|
#include "hwloc.h"
|
||||||
|
#include "hwloc/autogen/config.h"
|
||||||
|
#include "hwloc/helper.h"
|
||||||
|
#ifdef HWLOC_LINUX_SYS
|
||||||
|
#include "hwloc/linux.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <rocm_smi/rocm_smi.h>
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/** \defgroup hwlocality_rsmi Interoperability with the ROCm SMI Management Library
|
||||||
|
*
|
||||||
|
* This interface offers ways to retrieve topology information about
|
||||||
|
* devices managed by the ROCm SMI Management Library.
|
||||||
|
*
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** \brief Get the CPU set of logical processors that are physically
|
||||||
|
* close to AMD GPU device whose index is \p dv_ind.
|
||||||
|
*
|
||||||
|
* Return the CPU set describing the locality of the AMD GPU device
|
||||||
|
* whose index is \p dv_ind.
|
||||||
|
*
|
||||||
|
* Topology \p topology and device \p dv_ind must match the local machine.
|
||||||
|
* I/O devices detection and the ROCm SMI component are not needed in the
|
||||||
|
* topology.
|
||||||
|
*
|
||||||
|
* The function only returns the locality of the device.
|
||||||
|
* If more information about the device is needed, OS objects should
|
||||||
|
* be used instead, see hwloc_rsmi_get_device_osdev()
|
||||||
|
* and hwloc_rsmi_get_device_osdev_by_index().
|
||||||
|
*
|
||||||
|
* This function is currently only implemented in a meaningful way for
|
||||||
|
* Linux; other systems will simply get a full cpuset.
|
||||||
|
*/
|
||||||
|
static __hwloc_inline int
|
||||||
|
hwloc_rsmi_get_device_cpuset(hwloc_topology_t topology __hwloc_attribute_unused,
|
||||||
|
uint32_t dv_ind, hwloc_cpuset_t set)
|
||||||
|
{
|
||||||
|
#ifdef HWLOC_LINUX_SYS
|
||||||
|
/* If we're on Linux, use the sysfs mechanism to get the local cpus */
|
||||||
|
#define HWLOC_RSMI_DEVICE_SYSFS_PATH_MAX 128
|
||||||
|
char path[HWLOC_RSMI_DEVICE_SYSFS_PATH_MAX];
|
||||||
|
rsmi_status_t ret;
|
||||||
|
uint64_t bdfid = 0;
|
||||||
|
unsigned domain, device, bus;
|
||||||
|
|
||||||
|
if (!hwloc_topology_is_thissystem(topology)) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = rsmi_dev_pci_id_get(dv_ind, &bdfid);
|
||||||
|
if (RSMI_STATUS_SUCCESS != ret) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
domain = (bdfid>>32) & 0xffffffff;
|
||||||
|
bus = ((bdfid & 0xffff)>>8) & 0xff;
|
||||||
|
device = ((bdfid & 0xff)>>3) & 0x1f;
|
||||||
|
|
||||||
|
sprintf(path, "/sys/bus/pci/devices/%04x:%02x:%02x.0/local_cpus", domain, bus, device);
|
||||||
|
if (hwloc_linux_read_path_as_cpumask(path, set) < 0
|
||||||
|
|| hwloc_bitmap_iszero(set))
|
||||||
|
hwloc_bitmap_copy(set, hwloc_topology_get_complete_cpuset(topology));
|
||||||
|
#else
|
||||||
|
/* Non-Linux systems simply get a full cpuset */
|
||||||
|
hwloc_bitmap_copy(set, hwloc_topology_get_complete_cpuset(topology));
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** \brief Get the hwloc OS device object corresponding to the
|
||||||
|
* AMD GPU device whose index is \p dv_ind.
|
||||||
|
*
|
||||||
|
* Return the OS device object describing the AMD GPU device whose
|
||||||
|
* index is \p dv_ind. Returns NULL if there is none.
|
||||||
|
*
|
||||||
|
* The topology \p topology does not necessarily have to match the current
|
||||||
|
* machine. For instance the topology may be an XML import of a remote host.
|
||||||
|
* I/O devices detection and the ROCm SMI component must be enabled in the
|
||||||
|
* topology.
|
||||||
|
*
|
||||||
|
* \note The corresponding PCI device object can be obtained by looking
|
||||||
|
* at the OS device parent object (unless PCI devices are filtered out).
|
||||||
|
*/
|
||||||
|
static __hwloc_inline hwloc_obj_t
|
||||||
|
hwloc_rsmi_get_device_osdev_by_index(hwloc_topology_t topology, uint32_t dv_ind)
|
||||||
|
{
|
||||||
|
hwloc_obj_t osdev = NULL;
|
||||||
|
while ((osdev = hwloc_get_next_osdev(topology, osdev)) != NULL) {
|
||||||
|
if (HWLOC_OBJ_OSDEV_GPU == osdev->attr->osdev.type
|
||||||
|
&& osdev->name
|
||||||
|
&& !strncmp("rsmi", osdev->name, 4)
|
||||||
|
&& atoi(osdev->name + 4) == (int) dv_ind)
|
||||||
|
return osdev;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** \brief Get the hwloc OS device object corresponding to AMD GPU device,
|
||||||
|
* whose index is \p dv_ind.
|
||||||
|
*
|
||||||
|
* Return the hwloc OS device object that describes the given
|
||||||
|
* AMD GPU, whose index is \p dv_ind Return NULL if there is none.
|
||||||
|
*
|
||||||
|
* Topology \p topology and device \p dv_ind must match the local machine.
|
||||||
|
* I/O devices detection and the ROCm SMI component must be enabled in the
|
||||||
|
* topology. If not, the locality of the object may still be found using
|
||||||
|
* hwloc_rsmi_get_device_cpuset().
|
||||||
|
*
|
||||||
|
* \note The corresponding hwloc PCI device may be found by looking
|
||||||
|
* at the result parent pointer (unless PCI devices are filtered out).
|
||||||
|
*/
|
||||||
|
static __hwloc_inline hwloc_obj_t
|
||||||
|
hwloc_rsmi_get_device_osdev(hwloc_topology_t topology, uint32_t dv_ind)
|
||||||
|
{
|
||||||
|
hwloc_obj_t osdev;
|
||||||
|
rsmi_status_t ret;
|
||||||
|
uint64_t bdfid = 0;
|
||||||
|
unsigned domain, device, bus, func;
|
||||||
|
uint64_t id;
|
||||||
|
char uuid[64];
|
||||||
|
|
||||||
|
if (!hwloc_topology_is_thissystem(topology)) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = rsmi_dev_pci_id_get(dv_ind, &bdfid);
|
||||||
|
if (RSMI_STATUS_SUCCESS != ret) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
domain = (bdfid>>32) & 0xffffffff;
|
||||||
|
bus = ((bdfid & 0xffff)>>8) & 0xff;
|
||||||
|
device = ((bdfid & 0xff)>>3) & 0x1f;
|
||||||
|
func = bdfid & 0x7;
|
||||||
|
|
||||||
|
ret = rsmi_dev_unique_id_get(dv_ind, &id);
|
||||||
|
if (RSMI_STATUS_SUCCESS != ret)
|
||||||
|
uuid[0] = '\0';
|
||||||
|
else
|
||||||
|
sprintf(uuid, "%lx", id);
|
||||||
|
|
||||||
|
osdev = NULL;
|
||||||
|
while ((osdev = hwloc_get_next_osdev(topology, osdev)) != NULL) {
|
||||||
|
hwloc_obj_t pcidev = osdev->parent;
|
||||||
|
const char *info;
|
||||||
|
|
||||||
|
if (strncmp(osdev->name, "rsmi", 4))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (pcidev
|
||||||
|
&& pcidev->type == HWLOC_OBJ_PCI_DEVICE
|
||||||
|
&& pcidev->attr->pcidev.domain == domain
|
||||||
|
&& pcidev->attr->pcidev.bus == bus
|
||||||
|
&& pcidev->attr->pcidev.dev == device
|
||||||
|
&& pcidev->attr->pcidev.func == func)
|
||||||
|
return osdev;
|
||||||
|
|
||||||
|
info = hwloc_obj_get_info_by_name(osdev, "AMDUUID");
|
||||||
|
if (info && !strcmp(info, uuid))
|
||||||
|
return osdev;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @} */
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* HWLOC_RSMI_H */
|
4
src/3rdparty/hwloc/src/cpukinds.c
vendored
4
src/3rdparty/hwloc/src/cpukinds.c
vendored
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright © 2020 Inria. All rights reserved.
|
* Copyright © 2020-2021 Inria. All rights reserved.
|
||||||
* See COPYING in top-level directory.
|
* See COPYING in top-level directory.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -270,7 +270,7 @@ hwloc__cpukinds_check_duplicate_rankings(struct hwloc_topology *topology)
|
||||||
unsigned i,j;
|
unsigned i,j;
|
||||||
for(i=0; i<topology->nr_cpukinds; i++)
|
for(i=0; i<topology->nr_cpukinds; i++)
|
||||||
for(j=i+1; j<topology->nr_cpukinds; j++)
|
for(j=i+1; j<topology->nr_cpukinds; j++)
|
||||||
if (topology->cpukinds[i].forced_efficiency == topology->cpukinds[j].forced_efficiency)
|
if (topology->cpukinds[i].ranking_value == topology->cpukinds[j].ranking_value)
|
||||||
/* if any duplicate, fail */
|
/* if any duplicate, fail */
|
||||||
return -1;
|
return -1;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
7
src/3rdparty/hwloc/src/static-components.h
vendored
7
src/3rdparty/hwloc/src/static-components.h
vendored
|
@ -1,4 +1,9 @@
|
||||||
#include <private/internal-components.h>
|
HWLOC_DECLSPEC extern const struct hwloc_component hwloc_noos_component;
|
||||||
|
HWLOC_DECLSPEC extern const struct hwloc_component hwloc_xml_component;
|
||||||
|
HWLOC_DECLSPEC extern const struct hwloc_component hwloc_synthetic_component;
|
||||||
|
HWLOC_DECLSPEC extern const struct hwloc_component hwloc_xml_nolibxml_component;
|
||||||
|
HWLOC_DECLSPEC extern const struct hwloc_component hwloc_windows_component;
|
||||||
|
HWLOC_DECLSPEC extern const struct hwloc_component hwloc_x86_component;
|
||||||
static const struct hwloc_component * hwloc_static_components[] = {
|
static const struct hwloc_component * hwloc_static_components[] = {
|
||||||
&hwloc_noos_component,
|
&hwloc_noos_component,
|
||||||
&hwloc_xml_component,
|
&hwloc_xml_component,
|
||||||
|
|
16
src/3rdparty/hwloc/src/topology-x86.c
vendored
16
src/3rdparty/hwloc/src/topology-x86.c
vendored
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright © 2010-2020 Inria. All rights reserved.
|
* Copyright © 2010-2021 Inria. All rights reserved.
|
||||||
* Copyright © 2010-2013 Université Bordeaux
|
* Copyright © 2010-2013 Université Bordeaux
|
||||||
* Copyright © 2010-2011 Cisco Systems, Inc. All rights reserved.
|
* Copyright © 2010-2011 Cisco Systems, Inc. All rights reserved.
|
||||||
* See COPYING in top-level directory.
|
* See COPYING in top-level directory.
|
||||||
|
@ -908,6 +908,16 @@ static void summarize(struct hwloc_backend *backend, struct procinfo *infos, uns
|
||||||
int gotnuma = 0;
|
int gotnuma = 0;
|
||||||
int fulldiscovery = (flags & HWLOC_X86_DISC_FLAG_FULL);
|
int fulldiscovery = (flags & HWLOC_X86_DISC_FLAG_FULL);
|
||||||
|
|
||||||
|
#ifdef HWLOC_DEBUG
|
||||||
|
hwloc_debug("\nSummary of x86 CPUID topology:\n");
|
||||||
|
for(i=0; i<nbprocs; i++) {
|
||||||
|
hwloc_debug("PU %u present=%u apicid=%u on PKG %d CORE %d DIE %d NODE %d\n",
|
||||||
|
i, infos[i].present, infos[i].apicid,
|
||||||
|
infos[i].ids[PKG], infos[i].ids[CORE], infos[i].ids[DIE], infos[i].ids[NODE]);
|
||||||
|
}
|
||||||
|
hwloc_debug("\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
for (i = 0; i < nbprocs; i++)
|
for (i = 0; i < nbprocs; i++)
|
||||||
if (infos[i].present) {
|
if (infos[i].present) {
|
||||||
hwloc_bitmap_set(complete_cpuset, i);
|
hwloc_bitmap_set(complete_cpuset, i);
|
||||||
|
@ -1587,7 +1597,8 @@ hwloc_x86_discover(struct hwloc_backend *backend, struct hwloc_disc_status *dsta
|
||||||
}
|
}
|
||||||
|
|
||||||
if (topology->levels[0][0]->cpuset) {
|
if (topology->levels[0][0]->cpuset) {
|
||||||
/* somebody else discovered things */
|
/* somebody else discovered things, reconnect levels so that we can look at them */
|
||||||
|
hwloc_topology_reconnect(topology, 0);
|
||||||
if (topology->nb_levels == 2 && topology->level_nbobjects[1] == data->nbprocs) {
|
if (topology->nb_levels == 2 && topology->level_nbobjects[1] == data->nbprocs) {
|
||||||
/* only PUs were discovered, as much as we would, complete the topology with everything else */
|
/* only PUs were discovered, as much as we would, complete the topology with everything else */
|
||||||
alreadypus = 1;
|
alreadypus = 1;
|
||||||
|
@ -1595,7 +1606,6 @@ hwloc_x86_discover(struct hwloc_backend *backend, struct hwloc_disc_status *dsta
|
||||||
}
|
}
|
||||||
|
|
||||||
/* several object types were added, we can't easily complete, just do partial discovery */
|
/* several object types were added, we can't easily complete, just do partial discovery */
|
||||||
hwloc_topology_reconnect(topology, 0);
|
|
||||||
ret = hwloc_look_x86(backend, flags);
|
ret = hwloc_look_x86(backend, flags);
|
||||||
if (ret)
|
if (ret)
|
||||||
hwloc_obj_add_info(topology->levels[0][0], "Backend", "x86");
|
hwloc_obj_add_info(topology->levels[0][0], "Backend", "x86");
|
||||||
|
|
3
src/3rdparty/hwloc/src/topology-xml.c
vendored
3
src/3rdparty/hwloc/src/topology-xml.c
vendored
|
@ -1462,6 +1462,9 @@ hwloc__xml_v2import_distances(hwloc_topology_t topology,
|
||||||
unsigned long long u;
|
unsigned long long u;
|
||||||
if (heterotypes) {
|
if (heterotypes) {
|
||||||
hwloc_obj_type_t t = HWLOC_OBJ_TYPE_NONE;
|
hwloc_obj_type_t t = HWLOC_OBJ_TYPE_NONE;
|
||||||
|
if (!*tmp)
|
||||||
|
/* reached the end of this indexes attribute */
|
||||||
|
break;
|
||||||
if (hwloc_type_sscanf(tmp, &t, NULL, 0) < 0) {
|
if (hwloc_type_sscanf(tmp, &t, NULL, 0) < 0) {
|
||||||
if (hwloc__xml_verbose())
|
if (hwloc__xml_verbose())
|
||||||
fprintf(stderr, "%s: %s with unrecognized heterogeneous type %s\n",
|
fprintf(stderr, "%s: %s with unrecognized heterogeneous type %s\n",
|
||||||
|
|
55
src/3rdparty/hwloc/src/topology.c
vendored
55
src/3rdparty/hwloc/src/topology.c
vendored
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright © 2009 CNRS
|
* Copyright © 2009 CNRS
|
||||||
* Copyright © 2009-2020 Inria. All rights reserved.
|
* Copyright © 2009-2021 Inria. All rights reserved.
|
||||||
* Copyright © 2009-2012, 2020 Université Bordeaux
|
* Copyright © 2009-2012, 2020 Université Bordeaux
|
||||||
* Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved.
|
* Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved.
|
||||||
* See COPYING in top-level directory.
|
* See COPYING in top-level directory.
|
||||||
|
@ -567,8 +567,9 @@ hwloc_free_unlinked_object(hwloc_obj_t obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Replace old with contents of new object, and make new freeable by the caller.
|
/* Replace old with contents of new object, and make new freeable by the caller.
|
||||||
* Only updates next_sibling/first_child pointers,
|
* Requires reconnect (for siblings pointers and group depth),
|
||||||
* so may only be used during early discovery.
|
* fixup of sets (only the main cpuset was likely compared before merging),
|
||||||
|
* and update of total_memory and group depth.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
hwloc_replace_linked_object(hwloc_obj_t old, hwloc_obj_t new)
|
hwloc_replace_linked_object(hwloc_obj_t old, hwloc_obj_t new)
|
||||||
|
@ -1348,7 +1349,7 @@ merge_insert_equal(hwloc_obj_t new, hwloc_obj_t old)
|
||||||
|
|
||||||
/* returns the result of merge, or NULL if not merged */
|
/* returns the result of merge, or NULL if not merged */
|
||||||
static __hwloc_inline hwloc_obj_t
|
static __hwloc_inline hwloc_obj_t
|
||||||
hwloc__insert_try_merge_group(hwloc_obj_t old, hwloc_obj_t new)
|
hwloc__insert_try_merge_group(hwloc_topology_t topology, hwloc_obj_t old, hwloc_obj_t new)
|
||||||
{
|
{
|
||||||
if (new->type == HWLOC_OBJ_GROUP && old->type == HWLOC_OBJ_GROUP) {
|
if (new->type == HWLOC_OBJ_GROUP && old->type == HWLOC_OBJ_GROUP) {
|
||||||
/* which group do we keep? */
|
/* which group do we keep? */
|
||||||
|
@ -1359,6 +1360,7 @@ hwloc__insert_try_merge_group(hwloc_obj_t old, hwloc_obj_t new)
|
||||||
|
|
||||||
/* keep the new one, it doesn't want to be merged */
|
/* keep the new one, it doesn't want to be merged */
|
||||||
hwloc_replace_linked_object(old, new);
|
hwloc_replace_linked_object(old, new);
|
||||||
|
topology->modified = 1;
|
||||||
return new;
|
return new;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -1366,9 +1368,12 @@ hwloc__insert_try_merge_group(hwloc_obj_t old, hwloc_obj_t new)
|
||||||
/* keep the old one, it doesn't want to be merged */
|
/* keep the old one, it doesn't want to be merged */
|
||||||
return old;
|
return old;
|
||||||
|
|
||||||
/* compare subkinds to decice who to keep */
|
/* compare subkinds to decide which group to keep */
|
||||||
if (new->attr->group.kind < old->attr->group.kind)
|
if (new->attr->group.kind < old->attr->group.kind) {
|
||||||
|
/* keep smaller kind */
|
||||||
hwloc_replace_linked_object(old, new);
|
hwloc_replace_linked_object(old, new);
|
||||||
|
topology->modified = 1;
|
||||||
|
}
|
||||||
return old;
|
return old;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1394,6 +1399,7 @@ hwloc__insert_try_merge_group(hwloc_obj_t old, hwloc_obj_t new)
|
||||||
* and let the caller free the new object
|
* and let the caller free the new object
|
||||||
*/
|
*/
|
||||||
hwloc_replace_linked_object(old, new);
|
hwloc_replace_linked_object(old, new);
|
||||||
|
topology->modified = 1;
|
||||||
return old;
|
return old;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -1435,7 +1441,7 @@ hwloc___insert_object_by_cpuset(struct hwloc_topology *topology, hwloc_obj_t cur
|
||||||
int setres = res;
|
int setres = res;
|
||||||
|
|
||||||
if (res == HWLOC_OBJ_EQUAL) {
|
if (res == HWLOC_OBJ_EQUAL) {
|
||||||
hwloc_obj_t merged = hwloc__insert_try_merge_group(child, obj);
|
hwloc_obj_t merged = hwloc__insert_try_merge_group(topology, child, obj);
|
||||||
if (merged)
|
if (merged)
|
||||||
return merged;
|
return merged;
|
||||||
/* otherwise compare actual types to decide of the inclusion */
|
/* otherwise compare actual types to decide of the inclusion */
|
||||||
|
@ -1931,12 +1937,24 @@ hwloc_topology_insert_group_object(struct hwloc_topology *topology, hwloc_obj_t
|
||||||
|
|
||||||
if (!res)
|
if (!res)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (res != obj)
|
|
||||||
/* merged */
|
if (res != obj && res->type != HWLOC_OBJ_GROUP)
|
||||||
|
/* merged, not into a Group, nothing to update */
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
|
/* res == obj means that the object was inserted.
|
||||||
|
* We need to reconnect levels, fill all its cpu/node sets,
|
||||||
|
* compute its total memory, group depth, etc.
|
||||||
|
*
|
||||||
|
* res != obj usually means that our new group was merged into an
|
||||||
|
* existing object, no need to recompute anything.
|
||||||
|
* However, if merging with an existing group, depending on their kinds,
|
||||||
|
* the contents of obj may overwrite the contents of the old group.
|
||||||
|
* This requires reconnecting levels, filling sets, recomputing total memory, etc.
|
||||||
|
*/
|
||||||
|
|
||||||
/* properly inserted */
|
/* properly inserted */
|
||||||
hwloc_obj_add_children_sets(obj);
|
hwloc_obj_add_children_sets(res);
|
||||||
if (hwloc_topology_reconnect(topology, 0) < 0)
|
if (hwloc_topology_reconnect(topology, 0) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -1948,7 +1966,7 @@ hwloc_topology_insert_group_object(struct hwloc_topology *topology, hwloc_obj_t
|
||||||
#endif
|
#endif
|
||||||
hwloc_topology_check(topology);
|
hwloc_topology_check(topology);
|
||||||
|
|
||||||
return obj;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
hwloc_obj_t
|
hwloc_obj_t
|
||||||
|
@ -4658,6 +4676,9 @@ hwloc__check_misc_children(hwloc_topology_t topology, hwloc_bitmap_t gp_indexes,
|
||||||
static void
|
static void
|
||||||
hwloc__check_object(hwloc_topology_t topology, hwloc_bitmap_t gp_indexes, hwloc_obj_t obj)
|
hwloc__check_object(hwloc_topology_t topology, hwloc_bitmap_t gp_indexes, hwloc_obj_t obj)
|
||||||
{
|
{
|
||||||
|
hwloc_uint64_t total_memory;
|
||||||
|
hwloc_obj_t child;
|
||||||
|
|
||||||
assert(!hwloc_bitmap_isset(gp_indexes, obj->gp_index));
|
assert(!hwloc_bitmap_isset(gp_indexes, obj->gp_index));
|
||||||
hwloc_bitmap_set(gp_indexes, obj->gp_index);
|
hwloc_bitmap_set(gp_indexes, obj->gp_index);
|
||||||
|
|
||||||
|
@ -4715,6 +4736,18 @@ hwloc__check_object(hwloc_topology_t topology, hwloc_bitmap_t gp_indexes, hwloc_
|
||||||
assert(hwloc_cache_type_by_depth_type(obj->attr->cache.depth, obj->attr->cache.type) == obj->type);
|
assert(hwloc_cache_type_by_depth_type(obj->attr->cache.depth, obj->attr->cache.type) == obj->type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* check total memory */
|
||||||
|
total_memory = 0;
|
||||||
|
if (obj->type == HWLOC_OBJ_NUMANODE)
|
||||||
|
total_memory += obj->attr->numanode.local_memory;
|
||||||
|
for_each_child(child, obj) {
|
||||||
|
total_memory += child->total_memory;
|
||||||
|
}
|
||||||
|
for_each_memory_child(child, obj) {
|
||||||
|
total_memory += child->total_memory;
|
||||||
|
}
|
||||||
|
assert(total_memory == obj->total_memory);
|
||||||
|
|
||||||
/* check children */
|
/* check children */
|
||||||
hwloc__check_normal_children(topology, gp_indexes, obj);
|
hwloc__check_normal_children(topology, gp_indexes, obj);
|
||||||
hwloc__check_memory_children(topology, gp_indexes, obj);
|
hwloc__check_memory_children(topology, gp_indexes, obj);
|
||||||
|
|
22
src/3rdparty/llhttp/LICENSE-MIT
vendored
Normal file
22
src/3rdparty/llhttp/LICENSE-MIT
vendored
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
This software is licensed under the MIT License.
|
||||||
|
|
||||||
|
Copyright Fedor Indutny, 2018.
|
||||||
|
|
||||||
|
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.
|
135
src/3rdparty/llhttp/README.md
vendored
Normal file
135
src/3rdparty/llhttp/README.md
vendored
Normal file
|
@ -0,0 +1,135 @@
|
||||||
|
# llhttp
|
||||||
|
[](https://github.com/nodejs/llhttp/actions?query=workflow%3ACI)
|
||||||
|
|
||||||
|
Port of [http_parser][0] to [llparse][1].
|
||||||
|
|
||||||
|
## Why?
|
||||||
|
|
||||||
|
Let's face it, [http_parser][0] is practically unmaintainable. Even
|
||||||
|
introduction of a single new method results in a significant code churn.
|
||||||
|
|
||||||
|
This project aims to:
|
||||||
|
|
||||||
|
* Make it maintainable
|
||||||
|
* Verifiable
|
||||||
|
* Improving benchmarks where possible
|
||||||
|
|
||||||
|
More details in [Fedor Indutny's talk at JSConf EU 2019](https://youtu.be/x3k_5Mi66sY)
|
||||||
|
|
||||||
|
## How?
|
||||||
|
|
||||||
|
Over time, different approaches for improving [http_parser][0]'s code base
|
||||||
|
were tried. However, all of them failed due to resulting significant performance
|
||||||
|
degradation.
|
||||||
|
|
||||||
|
This project is a port of [http_parser][0] to TypeScript. [llparse][1] is used
|
||||||
|
to generate the output C source file, which could be compiled and
|
||||||
|
linked with the embedder's program (like [Node.js][7]).
|
||||||
|
|
||||||
|
## Performance
|
||||||
|
|
||||||
|
So far llhttp outperforms http_parser:
|
||||||
|
|
||||||
|
| | input size | bandwidth | reqs/sec | time |
|
||||||
|
|:----------------|-----------:|-------------:|-----------:|--------:|
|
||||||
|
| **llhttp** | 8192.00 mb | 1777.24 mb/s | 3583799.39 req/sec | 4.61 s |
|
||||||
|
| **http_parser** | 8192.00 mb | 694.66 mb/s | 1406180.33 req/sec | 11.79 s |
|
||||||
|
|
||||||
|
llhttp is faster by approximately **156%**.
|
||||||
|
|
||||||
|
## Maintenance
|
||||||
|
|
||||||
|
llhttp project has about 1400 lines of TypeScript code describing the parser
|
||||||
|
itself and around 450 lines of C code and headers providing the helper methods.
|
||||||
|
The whole [http_parser][0] is implemented in approximately 2500 lines of C, and
|
||||||
|
436 lines of headers.
|
||||||
|
|
||||||
|
All optimizations and multi-character matching in llhttp are generated
|
||||||
|
automatically, and thus doesn't add any extra maintenance cost. On the contrary,
|
||||||
|
most of http_parser's code is hand-optimized and unrolled. Instead describing
|
||||||
|
"how" it should parse the HTTP requests/responses, a maintainer should
|
||||||
|
implement the new features in [http_parser][0] cautiously, considering
|
||||||
|
possible performance degradation and manually optimizing the new code.
|
||||||
|
|
||||||
|
## Verification
|
||||||
|
|
||||||
|
The state machine graph is encoded explicitly in llhttp. The [llparse][1]
|
||||||
|
automatically checks the graph for absence of loops and correct reporting of the
|
||||||
|
input ranges (spans) like header names and values. In the future, additional
|
||||||
|
checks could be performed to get even stricter verification of the llhttp.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```C
|
||||||
|
#include "llhttp.h"
|
||||||
|
|
||||||
|
llhttp_t parser;
|
||||||
|
llhttp_settings_t settings;
|
||||||
|
|
||||||
|
/* Initialize user callbacks and settings */
|
||||||
|
llhttp_settings_init(&settings);
|
||||||
|
|
||||||
|
/* Set user callback */
|
||||||
|
settings.on_message_complete = handle_on_message_complete;
|
||||||
|
|
||||||
|
/* Initialize the parser in HTTP_BOTH mode, meaning that it will select between
|
||||||
|
* HTTP_REQUEST and HTTP_RESPONSE parsing automatically while reading the first
|
||||||
|
* input.
|
||||||
|
*/
|
||||||
|
llhttp_init(&parser, HTTP_BOTH, &settings);
|
||||||
|
|
||||||
|
/* Parse request! */
|
||||||
|
const char* request = "GET / HTTP/1.1\r\n\r\n";
|
||||||
|
int request_len = strlen(request);
|
||||||
|
|
||||||
|
enum llhttp_errno err = llhttp_execute(&parser, request, request_len);
|
||||||
|
if (err == HPE_OK) {
|
||||||
|
/* Successfully parsed! */
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "Parse error: %s %s\n", llhttp_errno_name(err),
|
||||||
|
parser.reason);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Bindings to other languages
|
||||||
|
|
||||||
|
* Python: [pallas/pyllhttp][8]
|
||||||
|
* Ruby: [metabahn/llhttp][9]
|
||||||
|
|
||||||
|
#### LICENSE
|
||||||
|
|
||||||
|
This software is licensed under the MIT License.
|
||||||
|
|
||||||
|
Copyright Fedor Indutny, 2018.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
[0]: https://github.com/nodejs/http-parser
|
||||||
|
[1]: https://github.com/nodejs/llparse
|
||||||
|
[2]: https://en.wikipedia.org/wiki/Register_allocation#Spilling
|
||||||
|
[3]: https://en.wikipedia.org/wiki/Tail_call
|
||||||
|
[4]: https://llvm.org/docs/LangRef.html
|
||||||
|
[5]: https://llvm.org/docs/LangRef.html#call-instruction
|
||||||
|
[6]: https://clang.llvm.org/
|
||||||
|
[7]: https://github.com/nodejs/node
|
||||||
|
[8]: https://github.com/pallas/pyllhttp
|
||||||
|
[9]: https://github.com/metabahn/llhttp
|
275
src/3rdparty/llhttp/api.c
vendored
Normal file
275
src/3rdparty/llhttp/api.c
vendored
Normal file
|
@ -0,0 +1,275 @@
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "llhttp.h"
|
||||||
|
|
||||||
|
#define CALLBACK_MAYBE(PARSER, NAME, ...) \
|
||||||
|
do { \
|
||||||
|
const llhttp_settings_t* settings; \
|
||||||
|
settings = (const llhttp_settings_t*) (PARSER)->settings; \
|
||||||
|
if (settings == NULL || settings->NAME == NULL) { \
|
||||||
|
err = 0; \
|
||||||
|
break; \
|
||||||
|
} \
|
||||||
|
err = settings->NAME(__VA_ARGS__); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
void llhttp_init(llhttp_t* parser, llhttp_type_t type,
|
||||||
|
const llhttp_settings_t* settings) {
|
||||||
|
llhttp__internal_init(parser);
|
||||||
|
|
||||||
|
parser->type = type;
|
||||||
|
parser->settings = (void*) settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void llhttp_reset(llhttp_t* parser) {
|
||||||
|
llhttp_type_t type = parser->type;
|
||||||
|
const llhttp_settings_t* settings = parser->settings;
|
||||||
|
void* data = parser->data;
|
||||||
|
uint8_t lenient_flags = parser->lenient_flags;
|
||||||
|
|
||||||
|
llhttp__internal_init(parser);
|
||||||
|
|
||||||
|
parser->type = type;
|
||||||
|
parser->settings = (void*) settings;
|
||||||
|
parser->data = data;
|
||||||
|
parser->lenient_flags = lenient_flags;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
llhttp_errno_t llhttp_execute(llhttp_t* parser, const char* data, size_t len) {
|
||||||
|
return llhttp__internal_execute(parser, data, data + len);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void llhttp_settings_init(llhttp_settings_t* settings) {
|
||||||
|
memset(settings, 0, sizeof(*settings));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
llhttp_errno_t llhttp_finish(llhttp_t* parser) {
|
||||||
|
int err;
|
||||||
|
|
||||||
|
/* We're in an error state. Don't bother doing anything. */
|
||||||
|
if (parser->error != 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (parser->finish) {
|
||||||
|
case HTTP_FINISH_SAFE_WITH_CB:
|
||||||
|
CALLBACK_MAYBE(parser, on_message_complete, parser);
|
||||||
|
if (err != HPE_OK) return err;
|
||||||
|
|
||||||
|
/* FALLTHROUGH */
|
||||||
|
case HTTP_FINISH_SAFE:
|
||||||
|
return HPE_OK;
|
||||||
|
case HTTP_FINISH_UNSAFE:
|
||||||
|
parser->reason = "Invalid EOF state";
|
||||||
|
return HPE_INVALID_EOF_STATE;
|
||||||
|
default:
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void llhttp_pause(llhttp_t* parser) {
|
||||||
|
if (parser->error != HPE_OK) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
parser->error = HPE_PAUSED;
|
||||||
|
parser->reason = "Paused";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void llhttp_resume(llhttp_t* parser) {
|
||||||
|
if (parser->error != HPE_PAUSED) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
parser->error = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void llhttp_resume_after_upgrade(llhttp_t* parser) {
|
||||||
|
if (parser->error != HPE_PAUSED_UPGRADE) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
parser->error = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
llhttp_errno_t llhttp_get_errno(const llhttp_t* parser) {
|
||||||
|
return parser->error;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const char* llhttp_get_error_reason(const llhttp_t* parser) {
|
||||||
|
return parser->reason;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void llhttp_set_error_reason(llhttp_t* parser, const char* reason) {
|
||||||
|
parser->reason = reason;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const char* llhttp_get_error_pos(const llhttp_t* parser) {
|
||||||
|
return parser->error_pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const char* llhttp_errno_name(llhttp_errno_t err) {
|
||||||
|
#define HTTP_ERRNO_GEN(CODE, NAME, _) case HPE_##NAME: return "HPE_" #NAME;
|
||||||
|
switch (err) {
|
||||||
|
HTTP_ERRNO_MAP(HTTP_ERRNO_GEN)
|
||||||
|
default: abort();
|
||||||
|
}
|
||||||
|
#undef HTTP_ERRNO_GEN
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const char* llhttp_method_name(llhttp_method_t method) {
|
||||||
|
#define HTTP_METHOD_GEN(NUM, NAME, STRING) case HTTP_##NAME: return #STRING;
|
||||||
|
switch (method) {
|
||||||
|
HTTP_METHOD_MAP(HTTP_METHOD_GEN)
|
||||||
|
default: abort();
|
||||||
|
}
|
||||||
|
#undef HTTP_METHOD_GEN
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void llhttp_set_lenient_headers(llhttp_t* parser, int enabled) {
|
||||||
|
if (enabled) {
|
||||||
|
parser->lenient_flags |= LENIENT_HEADERS;
|
||||||
|
} else {
|
||||||
|
parser->lenient_flags &= ~LENIENT_HEADERS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void llhttp_set_lenient_chunked_length(llhttp_t* parser, int enabled) {
|
||||||
|
if (enabled) {
|
||||||
|
parser->lenient_flags |= LENIENT_CHUNKED_LENGTH;
|
||||||
|
} else {
|
||||||
|
parser->lenient_flags &= ~LENIENT_CHUNKED_LENGTH;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Callbacks */
|
||||||
|
|
||||||
|
|
||||||
|
int llhttp__on_message_begin(llhttp_t* s, const char* p, const char* endp) {
|
||||||
|
int err;
|
||||||
|
CALLBACK_MAYBE(s, on_message_begin, s);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int llhttp__on_url(llhttp_t* s, const char* p, const char* endp) {
|
||||||
|
int err;
|
||||||
|
CALLBACK_MAYBE(s, on_url, s, p, endp - p);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int llhttp__on_url_complete(llhttp_t* s, const char* p, const char* endp) {
|
||||||
|
int err;
|
||||||
|
CALLBACK_MAYBE(s, on_url_complete, s);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int llhttp__on_status(llhttp_t* s, const char* p, const char* endp) {
|
||||||
|
int err;
|
||||||
|
CALLBACK_MAYBE(s, on_status, s, p, endp - p);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int llhttp__on_status_complete(llhttp_t* s, const char* p, const char* endp) {
|
||||||
|
int err;
|
||||||
|
CALLBACK_MAYBE(s, on_status_complete, s);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int llhttp__on_header_field(llhttp_t* s, const char* p, const char* endp) {
|
||||||
|
int err;
|
||||||
|
CALLBACK_MAYBE(s, on_header_field, s, p, endp - p);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int llhttp__on_header_field_complete(llhttp_t* s, const char* p, const char* endp) {
|
||||||
|
int err;
|
||||||
|
CALLBACK_MAYBE(s, on_header_field_complete, s);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int llhttp__on_header_value(llhttp_t* s, const char* p, const char* endp) {
|
||||||
|
int err;
|
||||||
|
CALLBACK_MAYBE(s, on_header_value, s, p, endp - p);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int llhttp__on_header_value_complete(llhttp_t* s, const char* p, const char* endp) {
|
||||||
|
int err;
|
||||||
|
CALLBACK_MAYBE(s, on_header_value_complete, s);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int llhttp__on_headers_complete(llhttp_t* s, const char* p, const char* endp) {
|
||||||
|
int err;
|
||||||
|
CALLBACK_MAYBE(s, on_headers_complete, s);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int llhttp__on_message_complete(llhttp_t* s, const char* p, const char* endp) {
|
||||||
|
int err;
|
||||||
|
CALLBACK_MAYBE(s, on_message_complete, s);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int llhttp__on_body(llhttp_t* s, const char* p, const char* endp) {
|
||||||
|
int err;
|
||||||
|
CALLBACK_MAYBE(s, on_body, s, p, endp - p);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int llhttp__on_chunk_header(llhttp_t* s, const char* p, const char* endp) {
|
||||||
|
int err;
|
||||||
|
CALLBACK_MAYBE(s, on_chunk_header, s);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int llhttp__on_chunk_complete(llhttp_t* s, const char* p, const char* endp) {
|
||||||
|
int err;
|
||||||
|
CALLBACK_MAYBE(s, on_chunk_complete, s);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Private */
|
||||||
|
|
||||||
|
|
||||||
|
void llhttp__debug(llhttp_t* s, const char* p, const char* endp,
|
||||||
|
const char* msg) {
|
||||||
|
if (p == endp) {
|
||||||
|
fprintf(stderr, "p=%p type=%d flags=%02x next=null debug=%s\n", s, s->type,
|
||||||
|
s->flags, msg);
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "p=%p type=%d flags=%02x next=%02x debug=%s\n", s,
|
||||||
|
s->type, s->flags, *p, msg);
|
||||||
|
}
|
||||||
|
}
|
187
src/3rdparty/llhttp/api.h
vendored
Normal file
187
src/3rdparty/llhttp/api.h
vendored
Normal file
|
@ -0,0 +1,187 @@
|
||||||
|
#ifndef INCLUDE_LLHTTP_API_H_
|
||||||
|
#define INCLUDE_LLHTTP_API_H_
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
typedef llhttp__internal_t llhttp_t;
|
||||||
|
typedef struct llhttp_settings_s llhttp_settings_t;
|
||||||
|
|
||||||
|
typedef int (*llhttp_data_cb)(llhttp_t*, const char *at, size_t length);
|
||||||
|
typedef int (*llhttp_cb)(llhttp_t*);
|
||||||
|
|
||||||
|
struct llhttp_settings_s {
|
||||||
|
/* Possible return values 0, -1, `HPE_PAUSED` */
|
||||||
|
llhttp_cb on_message_begin;
|
||||||
|
|
||||||
|
llhttp_data_cb on_url;
|
||||||
|
llhttp_data_cb on_status;
|
||||||
|
llhttp_data_cb on_header_field;
|
||||||
|
llhttp_data_cb on_header_value;
|
||||||
|
|
||||||
|
/* Possible return values:
|
||||||
|
* 0 - Proceed normally
|
||||||
|
* 1 - Assume that request/response has no body, and proceed to parsing the
|
||||||
|
* next message
|
||||||
|
* 2 - Assume absence of body (as above) and make `llhttp_execute()` return
|
||||||
|
* `HPE_PAUSED_UPGRADE`
|
||||||
|
* -1 - Error
|
||||||
|
* `HPE_PAUSED`
|
||||||
|
*/
|
||||||
|
llhttp_cb on_headers_complete;
|
||||||
|
|
||||||
|
llhttp_data_cb on_body;
|
||||||
|
|
||||||
|
/* Possible return values 0, -1, `HPE_PAUSED` */
|
||||||
|
llhttp_cb on_message_complete;
|
||||||
|
|
||||||
|
/* When on_chunk_header is called, the current chunk length is stored
|
||||||
|
* in parser->content_length.
|
||||||
|
* Possible return values 0, -1, `HPE_PAUSED`
|
||||||
|
*/
|
||||||
|
llhttp_cb on_chunk_header;
|
||||||
|
llhttp_cb on_chunk_complete;
|
||||||
|
|
||||||
|
llhttp_cb on_url_complete;
|
||||||
|
llhttp_cb on_status_complete;
|
||||||
|
llhttp_cb on_header_field_complete;
|
||||||
|
llhttp_cb on_header_value_complete;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Initialize the parser with specific type and user settings.
|
||||||
|
*
|
||||||
|
* NOTE: lifetime of `settings` has to be at least the same as the lifetime of
|
||||||
|
* the `parser` here. In practice, `settings` has to be either a static
|
||||||
|
* variable or be allocated with `malloc`, `new`, etc.
|
||||||
|
*/
|
||||||
|
void llhttp_init(llhttp_t* parser, llhttp_type_t type,
|
||||||
|
const llhttp_settings_t* settings);
|
||||||
|
|
||||||
|
/* Reset an already initialized parser back to the start state, preserving the
|
||||||
|
* existing parser type, callback settings, user data, and lenient flags.
|
||||||
|
*/
|
||||||
|
void llhttp_reset(llhttp_t* parser);
|
||||||
|
|
||||||
|
/* Initialize the settings object */
|
||||||
|
void llhttp_settings_init(llhttp_settings_t* settings);
|
||||||
|
|
||||||
|
/* Parse full or partial request/response, invoking user callbacks along the
|
||||||
|
* way.
|
||||||
|
*
|
||||||
|
* If any of `llhttp_data_cb` returns errno not equal to `HPE_OK` - the parsing
|
||||||
|
* interrupts, and such errno is returned from `llhttp_execute()`. If
|
||||||
|
* `HPE_PAUSED` was used as a errno, the execution can be resumed with
|
||||||
|
* `llhttp_resume()` call.
|
||||||
|
*
|
||||||
|
* In a special case of CONNECT/Upgrade request/response `HPE_PAUSED_UPGRADE`
|
||||||
|
* is returned after fully parsing the request/response. If the user wishes to
|
||||||
|
* continue parsing, they need to invoke `llhttp_resume_after_upgrade()`.
|
||||||
|
*
|
||||||
|
* NOTE: if this function ever returns a non-pause type error, it will continue
|
||||||
|
* to return the same error upon each successive call up until `llhttp_init()`
|
||||||
|
* is called.
|
||||||
|
*/
|
||||||
|
llhttp_errno_t llhttp_execute(llhttp_t* parser, const char* data, size_t len);
|
||||||
|
|
||||||
|
/* This method should be called when the other side has no further bytes to
|
||||||
|
* send (e.g. shutdown of readable side of the TCP connection.)
|
||||||
|
*
|
||||||
|
* Requests without `Content-Length` and other messages might require treating
|
||||||
|
* all incoming bytes as the part of the body, up to the last byte of the
|
||||||
|
* connection. This method will invoke `on_message_complete()` callback if the
|
||||||
|
* request was terminated safely. Otherwise a error code would be returned.
|
||||||
|
*/
|
||||||
|
llhttp_errno_t llhttp_finish(llhttp_t* parser);
|
||||||
|
|
||||||
|
/* Returns `1` if the incoming message is parsed until the last byte, and has
|
||||||
|
* to be completed by calling `llhttp_finish()` on EOF
|
||||||
|
*/
|
||||||
|
int llhttp_message_needs_eof(const llhttp_t* parser);
|
||||||
|
|
||||||
|
/* Returns `1` if there might be any other messages following the last that was
|
||||||
|
* successfully parsed.
|
||||||
|
*/
|
||||||
|
int llhttp_should_keep_alive(const llhttp_t* parser);
|
||||||
|
|
||||||
|
/* Make further calls of `llhttp_execute()` return `HPE_PAUSED` and set
|
||||||
|
* appropriate error reason.
|
||||||
|
*
|
||||||
|
* Important: do not call this from user callbacks! User callbacks must return
|
||||||
|
* `HPE_PAUSED` if pausing is required.
|
||||||
|
*/
|
||||||
|
void llhttp_pause(llhttp_t* parser);
|
||||||
|
|
||||||
|
/* Might be called to resume the execution after the pause in user's callback.
|
||||||
|
* See `llhttp_execute()` above for details.
|
||||||
|
*
|
||||||
|
* Call this only if `llhttp_execute()` returns `HPE_PAUSED`.
|
||||||
|
*/
|
||||||
|
void llhttp_resume(llhttp_t* parser);
|
||||||
|
|
||||||
|
/* Might be called to resume the execution after the pause in user's callback.
|
||||||
|
* See `llhttp_execute()` above for details.
|
||||||
|
*
|
||||||
|
* Call this only if `llhttp_execute()` returns `HPE_PAUSED_UPGRADE`
|
||||||
|
*/
|
||||||
|
void llhttp_resume_after_upgrade(llhttp_t* parser);
|
||||||
|
|
||||||
|
/* Returns the latest return error */
|
||||||
|
llhttp_errno_t llhttp_get_errno(const llhttp_t* parser);
|
||||||
|
|
||||||
|
/* Returns the verbal explanation of the latest returned error.
|
||||||
|
*
|
||||||
|
* Note: User callback should set error reason when returning the error. See
|
||||||
|
* `llhttp_set_error_reason()` for details.
|
||||||
|
*/
|
||||||
|
const char* llhttp_get_error_reason(const llhttp_t* parser);
|
||||||
|
|
||||||
|
/* Assign verbal description to the returned error. Must be called in user
|
||||||
|
* callbacks right before returning the errno.
|
||||||
|
*
|
||||||
|
* Note: `HPE_USER` error code might be useful in user callbacks.
|
||||||
|
*/
|
||||||
|
void llhttp_set_error_reason(llhttp_t* parser, const char* reason);
|
||||||
|
|
||||||
|
/* Returns the pointer to the last parsed byte before the returned error. The
|
||||||
|
* pointer is relative to the `data` argument of `llhttp_execute()`.
|
||||||
|
*
|
||||||
|
* Note: this method might be useful for counting the number of parsed bytes.
|
||||||
|
*/
|
||||||
|
const char* llhttp_get_error_pos(const llhttp_t* parser);
|
||||||
|
|
||||||
|
/* Returns textual name of error code */
|
||||||
|
const char* llhttp_errno_name(llhttp_errno_t err);
|
||||||
|
|
||||||
|
/* Returns textual name of HTTP method */
|
||||||
|
const char* llhttp_method_name(llhttp_method_t method);
|
||||||
|
|
||||||
|
|
||||||
|
/* Enables/disables lenient header value parsing (disabled by default).
|
||||||
|
*
|
||||||
|
* Lenient parsing disables header value token checks, extending llhttp's
|
||||||
|
* protocol support to highly non-compliant clients/server. No
|
||||||
|
* `HPE_INVALID_HEADER_TOKEN` will be raised for incorrect header values when
|
||||||
|
* lenient parsing is "on".
|
||||||
|
*
|
||||||
|
* **(USE AT YOUR OWN RISK)**
|
||||||
|
*/
|
||||||
|
void llhttp_set_lenient_headers(llhttp_t* parser, int enabled);
|
||||||
|
|
||||||
|
|
||||||
|
/* Enables/disables lenient handling of conflicting `Transfer-Encoding` and
|
||||||
|
* `Content-Length` headers (disabled by default).
|
||||||
|
*
|
||||||
|
* Normally `llhttp` would error when `Transfer-Encoding` is present in
|
||||||
|
* conjunction with `Content-Length`. This error is important to prevent HTTP
|
||||||
|
* request smuggling, but may be less desirable for small number of cases
|
||||||
|
* involving legacy servers.
|
||||||
|
*
|
||||||
|
* **(USE AT YOUR OWN RISK)**
|
||||||
|
*/
|
||||||
|
void llhttp_set_lenient_chunked_length(llhttp_t* parser, int enabled);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
#endif /* INCLUDE_LLHTTP_API_H_ */
|
149
src/3rdparty/llhttp/http.c
vendored
Normal file
149
src/3rdparty/llhttp/http.c
vendored
Normal file
|
@ -0,0 +1,149 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#ifndef LLHTTP__TEST
|
||||||
|
# include "llhttp.h"
|
||||||
|
#else
|
||||||
|
# define llhttp_t llparse_t
|
||||||
|
#endif /* */
|
||||||
|
|
||||||
|
int llhttp_message_needs_eof(const llhttp_t* parser);
|
||||||
|
int llhttp_should_keep_alive(const llhttp_t* parser);
|
||||||
|
|
||||||
|
int llhttp__before_headers_complete(llhttp_t* parser, const char* p,
|
||||||
|
const char* endp) {
|
||||||
|
/* Set this here so that on_headers_complete() callbacks can see it */
|
||||||
|
if ((parser->flags & F_UPGRADE) &&
|
||||||
|
(parser->flags & F_CONNECTION_UPGRADE)) {
|
||||||
|
/* For responses, "Upgrade: foo" and "Connection: upgrade" are
|
||||||
|
* mandatory only when it is a 101 Switching Protocols response,
|
||||||
|
* otherwise it is purely informational, to announce support.
|
||||||
|
*/
|
||||||
|
parser->upgrade =
|
||||||
|
(parser->type == HTTP_REQUEST || parser->status_code == 101);
|
||||||
|
} else {
|
||||||
|
parser->upgrade = (parser->method == HTTP_CONNECT);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Return values:
|
||||||
|
* 0 - No body, `restart`, message_complete
|
||||||
|
* 1 - CONNECT request, `restart`, message_complete, and pause
|
||||||
|
* 2 - chunk_size_start
|
||||||
|
* 3 - body_identity
|
||||||
|
* 4 - body_identity_eof
|
||||||
|
* 5 - invalid transfer-encoding for request
|
||||||
|
*/
|
||||||
|
int llhttp__after_headers_complete(llhttp_t* parser, const char* p,
|
||||||
|
const char* endp) {
|
||||||
|
int hasBody;
|
||||||
|
|
||||||
|
hasBody = parser->flags & F_CHUNKED || parser->content_length > 0;
|
||||||
|
if (parser->upgrade && (parser->method == HTTP_CONNECT ||
|
||||||
|
(parser->flags & F_SKIPBODY) || !hasBody)) {
|
||||||
|
/* Exit, the rest of the message is in a different protocol. */
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parser->flags & F_SKIPBODY) {
|
||||||
|
return 0;
|
||||||
|
} else if (parser->flags & F_CHUNKED) {
|
||||||
|
/* chunked encoding - ignore Content-Length header, prepare for a chunk */
|
||||||
|
return 2;
|
||||||
|
} else if (parser->flags & F_TRANSFER_ENCODING) {
|
||||||
|
if (parser->type == HTTP_REQUEST &&
|
||||||
|
(parser->lenient_flags & LENIENT_CHUNKED_LENGTH) == 0) {
|
||||||
|
/* RFC 7230 3.3.3 */
|
||||||
|
|
||||||
|
/* If a Transfer-Encoding header field
|
||||||
|
* is present in a request and the chunked transfer coding is not
|
||||||
|
* the final encoding, the message body length cannot be determined
|
||||||
|
* reliably; the server MUST respond with the 400 (Bad Request)
|
||||||
|
* status code and then close the connection.
|
||||||
|
*/
|
||||||
|
return 5;
|
||||||
|
} else {
|
||||||
|
/* RFC 7230 3.3.3 */
|
||||||
|
|
||||||
|
/* If a Transfer-Encoding header field is present in a response and
|
||||||
|
* the chunked transfer coding is not the final encoding, the
|
||||||
|
* message body length is determined by reading the connection until
|
||||||
|
* it is closed by the server.
|
||||||
|
*/
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!(parser->flags & F_CONTENT_LENGTH)) {
|
||||||
|
if (!llhttp_message_needs_eof(parser)) {
|
||||||
|
/* Assume content-length 0 - read the next */
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
/* Read body until EOF */
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
} else if (parser->content_length == 0) {
|
||||||
|
/* Content-Length header given but zero: Content-Length: 0\r\n */
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
/* Content-Length header given and non-zero */
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int llhttp__after_message_complete(llhttp_t* parser, const char* p,
|
||||||
|
const char* endp) {
|
||||||
|
int should_keep_alive;
|
||||||
|
|
||||||
|
should_keep_alive = llhttp_should_keep_alive(parser);
|
||||||
|
parser->finish = HTTP_FINISH_SAFE;
|
||||||
|
parser->flags = 0;
|
||||||
|
|
||||||
|
/* NOTE: this is ignored in loose parsing mode */
|
||||||
|
return should_keep_alive;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int llhttp_message_needs_eof(const llhttp_t* parser) {
|
||||||
|
if (parser->type == HTTP_REQUEST) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* See RFC 2616 section 4.4 */
|
||||||
|
if (parser->status_code / 100 == 1 || /* 1xx e.g. Continue */
|
||||||
|
parser->status_code == 204 || /* No Content */
|
||||||
|
parser->status_code == 304 || /* Not Modified */
|
||||||
|
(parser->flags & F_SKIPBODY)) { /* response to a HEAD request */
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* RFC 7230 3.3.3, see `llhttp__after_headers_complete` */
|
||||||
|
if ((parser->flags & F_TRANSFER_ENCODING) &&
|
||||||
|
(parser->flags & F_CHUNKED) == 0) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parser->flags & (F_CHUNKED | F_CONTENT_LENGTH)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int llhttp_should_keep_alive(const llhttp_t* parser) {
|
||||||
|
if (parser->http_major > 0 && parser->http_minor > 0) {
|
||||||
|
/* HTTP/1.1 */
|
||||||
|
if (parser->flags & F_CONNECTION_CLOSE) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* HTTP/1.0 or earlier */
|
||||||
|
if (!(parser->flags & F_CONNECTION_KEEP_ALIVE)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return !llhttp_message_needs_eof(parser);
|
||||||
|
}
|
14871
src/3rdparty/llhttp/llhttp.c
vendored
Normal file
14871
src/3rdparty/llhttp/llhttp.c
vendored
Normal file
File diff suppressed because it is too large
Load diff
439
src/3rdparty/llhttp/llhttp.h
vendored
Normal file
439
src/3rdparty/llhttp/llhttp.h
vendored
Normal file
|
@ -0,0 +1,439 @@
|
||||||
|
#ifndef INCLUDE_LLHTTP_H_
|
||||||
|
#define INCLUDE_LLHTTP_H_
|
||||||
|
|
||||||
|
#define LLHTTP_VERSION_MAJOR 4
|
||||||
|
#define LLHTTP_VERSION_MINOR 0
|
||||||
|
#define LLHTTP_VERSION_PATCH 0
|
||||||
|
|
||||||
|
#ifndef LLHTTP_STRICT_MODE
|
||||||
|
# define LLHTTP_STRICT_MODE 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef INCLUDE_LLHTTP_ITSELF_H_
|
||||||
|
#define INCLUDE_LLHTTP_ITSELF_H_
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
typedef struct llhttp__internal_s llhttp__internal_t;
|
||||||
|
struct llhttp__internal_s {
|
||||||
|
int32_t _index;
|
||||||
|
void* _span_pos0;
|
||||||
|
void* _span_cb0;
|
||||||
|
int32_t error;
|
||||||
|
const char* reason;
|
||||||
|
const char* error_pos;
|
||||||
|
void* data;
|
||||||
|
void* _current;
|
||||||
|
uint64_t content_length;
|
||||||
|
uint8_t type;
|
||||||
|
uint8_t method;
|
||||||
|
uint8_t http_major;
|
||||||
|
uint8_t http_minor;
|
||||||
|
uint8_t header_state;
|
||||||
|
uint8_t lenient_flags;
|
||||||
|
uint8_t upgrade;
|
||||||
|
uint8_t finish;
|
||||||
|
uint16_t flags;
|
||||||
|
uint16_t status_code;
|
||||||
|
void* settings;
|
||||||
|
};
|
||||||
|
|
||||||
|
int llhttp__internal_init(llhttp__internal_t* s);
|
||||||
|
int llhttp__internal_execute(llhttp__internal_t* s, const char* p, const char* endp);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
#endif /* INCLUDE_LLHTTP_ITSELF_H_ */
|
||||||
|
|
||||||
|
#ifndef LLLLHTTP_C_HEADERS_
|
||||||
|
#define LLLLHTTP_C_HEADERS_
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
enum llhttp_errno {
|
||||||
|
HPE_OK = 0,
|
||||||
|
HPE_INTERNAL = 1,
|
||||||
|
HPE_STRICT = 2,
|
||||||
|
HPE_LF_EXPECTED = 3,
|
||||||
|
HPE_UNEXPECTED_CONTENT_LENGTH = 4,
|
||||||
|
HPE_CLOSED_CONNECTION = 5,
|
||||||
|
HPE_INVALID_METHOD = 6,
|
||||||
|
HPE_INVALID_URL = 7,
|
||||||
|
HPE_INVALID_CONSTANT = 8,
|
||||||
|
HPE_INVALID_VERSION = 9,
|
||||||
|
HPE_INVALID_HEADER_TOKEN = 10,
|
||||||
|
HPE_INVALID_CONTENT_LENGTH = 11,
|
||||||
|
HPE_INVALID_CHUNK_SIZE = 12,
|
||||||
|
HPE_INVALID_STATUS = 13,
|
||||||
|
HPE_INVALID_EOF_STATE = 14,
|
||||||
|
HPE_INVALID_TRANSFER_ENCODING = 15,
|
||||||
|
HPE_CB_MESSAGE_BEGIN = 16,
|
||||||
|
HPE_CB_HEADERS_COMPLETE = 17,
|
||||||
|
HPE_CB_MESSAGE_COMPLETE = 18,
|
||||||
|
HPE_CB_CHUNK_HEADER = 19,
|
||||||
|
HPE_CB_CHUNK_COMPLETE = 20,
|
||||||
|
HPE_PAUSED = 21,
|
||||||
|
HPE_PAUSED_UPGRADE = 22,
|
||||||
|
HPE_USER = 23
|
||||||
|
};
|
||||||
|
typedef enum llhttp_errno llhttp_errno_t;
|
||||||
|
|
||||||
|
enum llhttp_flags {
|
||||||
|
F_CONNECTION_KEEP_ALIVE = 0x1,
|
||||||
|
F_CONNECTION_CLOSE = 0x2,
|
||||||
|
F_CONNECTION_UPGRADE = 0x4,
|
||||||
|
F_CHUNKED = 0x8,
|
||||||
|
F_UPGRADE = 0x10,
|
||||||
|
F_CONTENT_LENGTH = 0x20,
|
||||||
|
F_SKIPBODY = 0x40,
|
||||||
|
F_TRAILING = 0x80,
|
||||||
|
F_TRANSFER_ENCODING = 0x200
|
||||||
|
};
|
||||||
|
typedef enum llhttp_flags llhttp_flags_t;
|
||||||
|
|
||||||
|
enum llhttp_lenient_flags {
|
||||||
|
LENIENT_HEADERS = 0x1,
|
||||||
|
LENIENT_CHUNKED_LENGTH = 0x2
|
||||||
|
};
|
||||||
|
typedef enum llhttp_lenient_flags llhttp_lenient_flags_t;
|
||||||
|
|
||||||
|
enum llhttp_type {
|
||||||
|
HTTP_BOTH = 0,
|
||||||
|
HTTP_REQUEST = 1,
|
||||||
|
HTTP_RESPONSE = 2
|
||||||
|
};
|
||||||
|
typedef enum llhttp_type llhttp_type_t;
|
||||||
|
|
||||||
|
enum llhttp_finish {
|
||||||
|
HTTP_FINISH_SAFE = 0,
|
||||||
|
HTTP_FINISH_SAFE_WITH_CB = 1,
|
||||||
|
HTTP_FINISH_UNSAFE = 2
|
||||||
|
};
|
||||||
|
typedef enum llhttp_finish llhttp_finish_t;
|
||||||
|
|
||||||
|
enum llhttp_method {
|
||||||
|
HTTP_DELETE = 0,
|
||||||
|
HTTP_GET = 1,
|
||||||
|
HTTP_HEAD = 2,
|
||||||
|
HTTP_POST = 3,
|
||||||
|
HTTP_PUT = 4,
|
||||||
|
HTTP_CONNECT = 5,
|
||||||
|
HTTP_OPTIONS = 6,
|
||||||
|
HTTP_TRACE = 7,
|
||||||
|
HTTP_COPY = 8,
|
||||||
|
HTTP_LOCK = 9,
|
||||||
|
HTTP_MKCOL = 10,
|
||||||
|
HTTP_MOVE = 11,
|
||||||
|
HTTP_PROPFIND = 12,
|
||||||
|
HTTP_PROPPATCH = 13,
|
||||||
|
HTTP_SEARCH = 14,
|
||||||
|
HTTP_UNLOCK = 15,
|
||||||
|
HTTP_BIND = 16,
|
||||||
|
HTTP_REBIND = 17,
|
||||||
|
HTTP_UNBIND = 18,
|
||||||
|
HTTP_ACL = 19,
|
||||||
|
HTTP_REPORT = 20,
|
||||||
|
HTTP_MKACTIVITY = 21,
|
||||||
|
HTTP_CHECKOUT = 22,
|
||||||
|
HTTP_MERGE = 23,
|
||||||
|
HTTP_MSEARCH = 24,
|
||||||
|
HTTP_NOTIFY = 25,
|
||||||
|
HTTP_SUBSCRIBE = 26,
|
||||||
|
HTTP_UNSUBSCRIBE = 27,
|
||||||
|
HTTP_PATCH = 28,
|
||||||
|
HTTP_PURGE = 29,
|
||||||
|
HTTP_MKCALENDAR = 30,
|
||||||
|
HTTP_LINK = 31,
|
||||||
|
HTTP_UNLINK = 32,
|
||||||
|
HTTP_SOURCE = 33,
|
||||||
|
HTTP_PRI = 34,
|
||||||
|
HTTP_DESCRIBE = 35,
|
||||||
|
HTTP_ANNOUNCE = 36,
|
||||||
|
HTTP_SETUP = 37,
|
||||||
|
HTTP_PLAY = 38,
|
||||||
|
HTTP_PAUSE = 39,
|
||||||
|
HTTP_TEARDOWN = 40,
|
||||||
|
HTTP_GET_PARAMETER = 41,
|
||||||
|
HTTP_SET_PARAMETER = 42,
|
||||||
|
HTTP_REDIRECT = 43,
|
||||||
|
HTTP_RECORD = 44,
|
||||||
|
HTTP_FLUSH = 45
|
||||||
|
};
|
||||||
|
typedef enum llhttp_method llhttp_method_t;
|
||||||
|
|
||||||
|
#define HTTP_ERRNO_MAP(XX) \
|
||||||
|
XX(0, OK, OK) \
|
||||||
|
XX(1, INTERNAL, INTERNAL) \
|
||||||
|
XX(2, STRICT, STRICT) \
|
||||||
|
XX(3, LF_EXPECTED, LF_EXPECTED) \
|
||||||
|
XX(4, UNEXPECTED_CONTENT_LENGTH, UNEXPECTED_CONTENT_LENGTH) \
|
||||||
|
XX(5, CLOSED_CONNECTION, CLOSED_CONNECTION) \
|
||||||
|
XX(6, INVALID_METHOD, INVALID_METHOD) \
|
||||||
|
XX(7, INVALID_URL, INVALID_URL) \
|
||||||
|
XX(8, INVALID_CONSTANT, INVALID_CONSTANT) \
|
||||||
|
XX(9, INVALID_VERSION, INVALID_VERSION) \
|
||||||
|
XX(10, INVALID_HEADER_TOKEN, INVALID_HEADER_TOKEN) \
|
||||||
|
XX(11, INVALID_CONTENT_LENGTH, INVALID_CONTENT_LENGTH) \
|
||||||
|
XX(12, INVALID_CHUNK_SIZE, INVALID_CHUNK_SIZE) \
|
||||||
|
XX(13, INVALID_STATUS, INVALID_STATUS) \
|
||||||
|
XX(14, INVALID_EOF_STATE, INVALID_EOF_STATE) \
|
||||||
|
XX(15, INVALID_TRANSFER_ENCODING, INVALID_TRANSFER_ENCODING) \
|
||||||
|
XX(16, CB_MESSAGE_BEGIN, CB_MESSAGE_BEGIN) \
|
||||||
|
XX(17, CB_HEADERS_COMPLETE, CB_HEADERS_COMPLETE) \
|
||||||
|
XX(18, CB_MESSAGE_COMPLETE, CB_MESSAGE_COMPLETE) \
|
||||||
|
XX(19, CB_CHUNK_HEADER, CB_CHUNK_HEADER) \
|
||||||
|
XX(20, CB_CHUNK_COMPLETE, CB_CHUNK_COMPLETE) \
|
||||||
|
XX(21, PAUSED, PAUSED) \
|
||||||
|
XX(22, PAUSED_UPGRADE, PAUSED_UPGRADE) \
|
||||||
|
XX(23, USER, USER) \
|
||||||
|
|
||||||
|
|
||||||
|
#define HTTP_METHOD_MAP(XX) \
|
||||||
|
XX(0, DELETE, DELETE) \
|
||||||
|
XX(1, GET, GET) \
|
||||||
|
XX(2, HEAD, HEAD) \
|
||||||
|
XX(3, POST, POST) \
|
||||||
|
XX(4, PUT, PUT) \
|
||||||
|
XX(5, CONNECT, CONNECT) \
|
||||||
|
XX(6, OPTIONS, OPTIONS) \
|
||||||
|
XX(7, TRACE, TRACE) \
|
||||||
|
XX(8, COPY, COPY) \
|
||||||
|
XX(9, LOCK, LOCK) \
|
||||||
|
XX(10, MKCOL, MKCOL) \
|
||||||
|
XX(11, MOVE, MOVE) \
|
||||||
|
XX(12, PROPFIND, PROPFIND) \
|
||||||
|
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) \
|
||||||
|
XX(20, REPORT, REPORT) \
|
||||||
|
XX(21, MKACTIVITY, MKACTIVITY) \
|
||||||
|
XX(22, CHECKOUT, CHECKOUT) \
|
||||||
|
XX(23, MERGE, MERGE) \
|
||||||
|
XX(24, MSEARCH, M-SEARCH) \
|
||||||
|
XX(25, NOTIFY, NOTIFY) \
|
||||||
|
XX(26, SUBSCRIBE, SUBSCRIBE) \
|
||||||
|
XX(27, UNSUBSCRIBE, UNSUBSCRIBE) \
|
||||||
|
XX(28, PATCH, PATCH) \
|
||||||
|
XX(29, PURGE, PURGE) \
|
||||||
|
XX(30, MKCALENDAR, MKCALENDAR) \
|
||||||
|
XX(31, LINK, LINK) \
|
||||||
|
XX(32, UNLINK, UNLINK) \
|
||||||
|
XX(33, SOURCE, SOURCE) \
|
||||||
|
XX(34, PRI, PRI) \
|
||||||
|
XX(35, DESCRIBE, DESCRIBE) \
|
||||||
|
XX(36, ANNOUNCE, ANNOUNCE) \
|
||||||
|
XX(37, SETUP, SETUP) \
|
||||||
|
XX(38, PLAY, PLAY) \
|
||||||
|
XX(39, PAUSE, PAUSE) \
|
||||||
|
XX(40, TEARDOWN, TEARDOWN) \
|
||||||
|
XX(41, GET_PARAMETER, GET_PARAMETER) \
|
||||||
|
XX(42, SET_PARAMETER, SET_PARAMETER) \
|
||||||
|
XX(43, REDIRECT, REDIRECT) \
|
||||||
|
XX(44, RECORD, RECORD) \
|
||||||
|
XX(45, FLUSH, FLUSH) \
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
#endif /* LLLLHTTP_C_HEADERS_ */
|
||||||
|
|
||||||
|
#ifndef INCLUDE_LLHTTP_API_H_
|
||||||
|
#define INCLUDE_LLHTTP_API_H_
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
typedef llhttp__internal_t llhttp_t;
|
||||||
|
typedef struct llhttp_settings_s llhttp_settings_t;
|
||||||
|
|
||||||
|
typedef int (*llhttp_data_cb)(llhttp_t*, const char *at, size_t length);
|
||||||
|
typedef int (*llhttp_cb)(llhttp_t*);
|
||||||
|
|
||||||
|
struct llhttp_settings_s {
|
||||||
|
/* Possible return values 0, -1, `HPE_PAUSED` */
|
||||||
|
llhttp_cb on_message_begin;
|
||||||
|
|
||||||
|
llhttp_data_cb on_url;
|
||||||
|
llhttp_data_cb on_status;
|
||||||
|
llhttp_data_cb on_header_field;
|
||||||
|
llhttp_data_cb on_header_value;
|
||||||
|
|
||||||
|
/* Possible return values:
|
||||||
|
* 0 - Proceed normally
|
||||||
|
* 1 - Assume that request/response has no body, and proceed to parsing the
|
||||||
|
* next message
|
||||||
|
* 2 - Assume absence of body (as above) and make `llhttp_execute()` return
|
||||||
|
* `HPE_PAUSED_UPGRADE`
|
||||||
|
* -1 - Error
|
||||||
|
* `HPE_PAUSED`
|
||||||
|
*/
|
||||||
|
llhttp_cb on_headers_complete;
|
||||||
|
|
||||||
|
llhttp_data_cb on_body;
|
||||||
|
|
||||||
|
/* Possible return values 0, -1, `HPE_PAUSED` */
|
||||||
|
llhttp_cb on_message_complete;
|
||||||
|
|
||||||
|
/* When on_chunk_header is called, the current chunk length is stored
|
||||||
|
* in parser->content_length.
|
||||||
|
* Possible return values 0, -1, `HPE_PAUSED`
|
||||||
|
*/
|
||||||
|
llhttp_cb on_chunk_header;
|
||||||
|
llhttp_cb on_chunk_complete;
|
||||||
|
|
||||||
|
llhttp_cb on_url_complete;
|
||||||
|
llhttp_cb on_status_complete;
|
||||||
|
llhttp_cb on_header_field_complete;
|
||||||
|
llhttp_cb on_header_value_complete;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Initialize the parser with specific type and user settings.
|
||||||
|
*
|
||||||
|
* NOTE: lifetime of `settings` has to be at least the same as the lifetime of
|
||||||
|
* the `parser` here. In practice, `settings` has to be either a static
|
||||||
|
* variable or be allocated with `malloc`, `new`, etc.
|
||||||
|
*/
|
||||||
|
void llhttp_init(llhttp_t* parser, llhttp_type_t type,
|
||||||
|
const llhttp_settings_t* settings);
|
||||||
|
|
||||||
|
/* Reset an already initialized parser back to the start state, preserving the
|
||||||
|
* existing parser type, callback settings, user data, and lenient flags.
|
||||||
|
*/
|
||||||
|
void llhttp_reset(llhttp_t* parser);
|
||||||
|
|
||||||
|
/* Initialize the settings object */
|
||||||
|
void llhttp_settings_init(llhttp_settings_t* settings);
|
||||||
|
|
||||||
|
/* Parse full or partial request/response, invoking user callbacks along the
|
||||||
|
* way.
|
||||||
|
*
|
||||||
|
* If any of `llhttp_data_cb` returns errno not equal to `HPE_OK` - the parsing
|
||||||
|
* interrupts, and such errno is returned from `llhttp_execute()`. If
|
||||||
|
* `HPE_PAUSED` was used as a errno, the execution can be resumed with
|
||||||
|
* `llhttp_resume()` call.
|
||||||
|
*
|
||||||
|
* In a special case of CONNECT/Upgrade request/response `HPE_PAUSED_UPGRADE`
|
||||||
|
* is returned after fully parsing the request/response. If the user wishes to
|
||||||
|
* continue parsing, they need to invoke `llhttp_resume_after_upgrade()`.
|
||||||
|
*
|
||||||
|
* NOTE: if this function ever returns a non-pause type error, it will continue
|
||||||
|
* to return the same error upon each successive call up until `llhttp_init()`
|
||||||
|
* is called.
|
||||||
|
*/
|
||||||
|
llhttp_errno_t llhttp_execute(llhttp_t* parser, const char* data, size_t len);
|
||||||
|
|
||||||
|
/* This method should be called when the other side has no further bytes to
|
||||||
|
* send (e.g. shutdown of readable side of the TCP connection.)
|
||||||
|
*
|
||||||
|
* Requests without `Content-Length` and other messages might require treating
|
||||||
|
* all incoming bytes as the part of the body, up to the last byte of the
|
||||||
|
* connection. This method will invoke `on_message_complete()` callback if the
|
||||||
|
* request was terminated safely. Otherwise a error code would be returned.
|
||||||
|
*/
|
||||||
|
llhttp_errno_t llhttp_finish(llhttp_t* parser);
|
||||||
|
|
||||||
|
/* Returns `1` if the incoming message is parsed until the last byte, and has
|
||||||
|
* to be completed by calling `llhttp_finish()` on EOF
|
||||||
|
*/
|
||||||
|
int llhttp_message_needs_eof(const llhttp_t* parser);
|
||||||
|
|
||||||
|
/* Returns `1` if there might be any other messages following the last that was
|
||||||
|
* successfully parsed.
|
||||||
|
*/
|
||||||
|
int llhttp_should_keep_alive(const llhttp_t* parser);
|
||||||
|
|
||||||
|
/* Make further calls of `llhttp_execute()` return `HPE_PAUSED` and set
|
||||||
|
* appropriate error reason.
|
||||||
|
*
|
||||||
|
* Important: do not call this from user callbacks! User callbacks must return
|
||||||
|
* `HPE_PAUSED` if pausing is required.
|
||||||
|
*/
|
||||||
|
void llhttp_pause(llhttp_t* parser);
|
||||||
|
|
||||||
|
/* Might be called to resume the execution after the pause in user's callback.
|
||||||
|
* See `llhttp_execute()` above for details.
|
||||||
|
*
|
||||||
|
* Call this only if `llhttp_execute()` returns `HPE_PAUSED`.
|
||||||
|
*/
|
||||||
|
void llhttp_resume(llhttp_t* parser);
|
||||||
|
|
||||||
|
/* Might be called to resume the execution after the pause in user's callback.
|
||||||
|
* See `llhttp_execute()` above for details.
|
||||||
|
*
|
||||||
|
* Call this only if `llhttp_execute()` returns `HPE_PAUSED_UPGRADE`
|
||||||
|
*/
|
||||||
|
void llhttp_resume_after_upgrade(llhttp_t* parser);
|
||||||
|
|
||||||
|
/* Returns the latest return error */
|
||||||
|
llhttp_errno_t llhttp_get_errno(const llhttp_t* parser);
|
||||||
|
|
||||||
|
/* Returns the verbal explanation of the latest returned error.
|
||||||
|
*
|
||||||
|
* Note: User callback should set error reason when returning the error. See
|
||||||
|
* `llhttp_set_error_reason()` for details.
|
||||||
|
*/
|
||||||
|
const char* llhttp_get_error_reason(const llhttp_t* parser);
|
||||||
|
|
||||||
|
/* Assign verbal description to the returned error. Must be called in user
|
||||||
|
* callbacks right before returning the errno.
|
||||||
|
*
|
||||||
|
* Note: `HPE_USER` error code might be useful in user callbacks.
|
||||||
|
*/
|
||||||
|
void llhttp_set_error_reason(llhttp_t* parser, const char* reason);
|
||||||
|
|
||||||
|
/* Returns the pointer to the last parsed byte before the returned error. The
|
||||||
|
* pointer is relative to the `data` argument of `llhttp_execute()`.
|
||||||
|
*
|
||||||
|
* Note: this method might be useful for counting the number of parsed bytes.
|
||||||
|
*/
|
||||||
|
const char* llhttp_get_error_pos(const llhttp_t* parser);
|
||||||
|
|
||||||
|
/* Returns textual name of error code */
|
||||||
|
const char* llhttp_errno_name(llhttp_errno_t err);
|
||||||
|
|
||||||
|
/* Returns textual name of HTTP method */
|
||||||
|
const char* llhttp_method_name(llhttp_method_t method);
|
||||||
|
|
||||||
|
|
||||||
|
/* Enables/disables lenient header value parsing (disabled by default).
|
||||||
|
*
|
||||||
|
* Lenient parsing disables header value token checks, extending llhttp's
|
||||||
|
* protocol support to highly non-compliant clients/server. No
|
||||||
|
* `HPE_INVALID_HEADER_TOKEN` will be raised for incorrect header values when
|
||||||
|
* lenient parsing is "on".
|
||||||
|
*
|
||||||
|
* **(USE AT YOUR OWN RISK)**
|
||||||
|
*/
|
||||||
|
void llhttp_set_lenient_headers(llhttp_t* parser, int enabled);
|
||||||
|
|
||||||
|
|
||||||
|
/* Enables/disables lenient handling of conflicting `Transfer-Encoding` and
|
||||||
|
* `Content-Length` headers (disabled by default).
|
||||||
|
*
|
||||||
|
* Normally `llhttp` would error when `Transfer-Encoding` is present in
|
||||||
|
* conjunction with `Content-Length`. This error is important to prevent HTTP
|
||||||
|
* request smuggling, but may be less desirable for small number of cases
|
||||||
|
* involving legacy servers.
|
||||||
|
*
|
||||||
|
* **(USE AT YOUR OWN RISK)**
|
||||||
|
*/
|
||||||
|
void llhttp_set_lenient_chunked_length(llhttp_t* parser, int enabled);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
#endif /* INCLUDE_LLHTTP_API_H_ */
|
||||||
|
|
||||||
|
#endif /* INCLUDE_LLHTTP_H_ */
|
|
@ -86,7 +86,9 @@ xmrig::CpuWorker<N>::CpuWorker(size_t id, const CpuLaunchData &data) :
|
||||||
if ((N == 1) && (m_av == CnHash::AV_SINGLE) && (m_algorithm.family() == Algorithm::CN_HEAVY) && (m_assembly != Assembly::NONE) && (Cpu::info()->arch() == ICpuInfo::ARCH_ZEN3)) {
|
if ((N == 1) && (m_av == CnHash::AV_SINGLE) && (m_algorithm.family() == Algorithm::CN_HEAVY) && (m_assembly != Assembly::NONE) && (Cpu::info()->arch() == ICpuInfo::ARCH_ZEN3)) {
|
||||||
std::lock_guard<std::mutex> lock(cn_heavyZen3MemoryMutex);
|
std::lock_guard<std::mutex> lock(cn_heavyZen3MemoryMutex);
|
||||||
if (!cn_heavyZen3Memory) {
|
if (!cn_heavyZen3Memory) {
|
||||||
cn_heavyZen3Memory = new VirtualMemory(m_algorithm.l3() * m_threads, data.hugePages, false, false, node());
|
// Round up number of threads to the multiple of 8
|
||||||
|
const size_t num_threads = ((m_threads + 7) / 8) * 8;
|
||||||
|
cn_heavyZen3Memory = new VirtualMemory(m_algorithm.l3() * num_threads, data.hugePages, false, false, node());
|
||||||
}
|
}
|
||||||
m_memory = cn_heavyZen3Memory;
|
m_memory = cn_heavyZen3Memory;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* XMRig
|
/* XMRig
|
||||||
* Copyright 2018-2021 SChernykh <https://github.com/SChernykh>
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -21,7 +21,6 @@
|
||||||
|
|
||||||
|
|
||||||
#include "base/api/Api.h"
|
#include "base/api/Api.h"
|
||||||
#include "3rdparty/http-parser/http_parser.h"
|
|
||||||
#include "base/api/interfaces/IApiListener.h"
|
#include "base/api/interfaces/IApiListener.h"
|
||||||
#include "base/api/requests/HttpApiRequest.h"
|
#include "base/api/requests/HttpApiRequest.h"
|
||||||
#include "base/crypto/keccak.h"
|
#include "base/crypto/keccak.h"
|
||||||
|
@ -186,7 +185,7 @@ void xmrig::Api::exec(IApiRequest &request)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
request.done(request.isNew() ? HTTP_STATUS_NOT_FOUND : HTTP_STATUS_OK);
|
request.done(request.isNew() ? 404 : 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* XMRig
|
/* XMRig
|
||||||
* Copyright 2018-2021 SChernykh <https://github.com/SChernykh>
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
|
|
@ -1,12 +1,6 @@
|
||||||
/* XMRig
|
/* XMRig
|
||||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
|
||||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
|
||||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
|
||||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -22,9 +16,8 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "base/api/Httpd.h"
|
#include "base/api/Httpd.h"
|
||||||
#include "3rdparty/http-parser/http_parser.h"
|
#include "3rdparty/llhttp/llhttp.h"
|
||||||
#include "base/api/Api.h"
|
#include "base/api/Api.h"
|
||||||
#include "base/io/log/Log.h"
|
#include "base/io/log/Log.h"
|
||||||
#include "base/net/http/HttpApiResponse.h"
|
#include "base/net/http/HttpApiResponse.h"
|
||||||
|
@ -155,25 +148,25 @@ void xmrig::Httpd::onHttpData(const HttpData &data)
|
||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
return HttpResponse(data.id(), HTTP_STATUS_NOT_FOUND).end();
|
return HttpResponse(data.id(), 404 /* NOT_FOUND */).end();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.method > 4) {
|
if (data.method > 4) {
|
||||||
return HttpApiResponse(data.id(), HTTP_STATUS_METHOD_NOT_ALLOWED).end();
|
return HttpApiResponse(data.id(), 405 /* METHOD_NOT_ALLOWED */).end();
|
||||||
}
|
}
|
||||||
|
|
||||||
const int status = auth(data);
|
const int status = auth(data);
|
||||||
if (status != HTTP_STATUS_OK) {
|
if (status != 200) {
|
||||||
return HttpApiResponse(data.id(), status).end();
|
return HttpApiResponse(data.id(), status).end();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.method != HTTP_GET) {
|
if (data.method != HTTP_GET) {
|
||||||
if (m_base->config()->http().isRestricted()) {
|
if (m_base->config()->http().isRestricted()) {
|
||||||
return HttpApiResponse(data.id(), HTTP_STATUS_FORBIDDEN).end();
|
return HttpApiResponse(data.id(), 403 /* FORBIDDEN */).end();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data.headers.count(HttpData::kContentTypeL) || data.headers.at(HttpData::kContentTypeL) != HttpData::kApplicationJson) {
|
if (!data.headers.count(HttpData::kContentTypeL) || data.headers.at(HttpData::kContentTypeL) != HttpData::kApplicationJson) {
|
||||||
return HttpApiResponse(data.id(), HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE).end();
|
return HttpApiResponse(data.id(), 415 /* UNSUPPORTED_MEDIA_TYPE */).end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,19 +179,19 @@ int xmrig::Httpd::auth(const HttpData &req) const
|
||||||
const Http &config = m_base->config()->http();
|
const Http &config = m_base->config()->http();
|
||||||
|
|
||||||
if (!req.headers.count(kAuthorization)) {
|
if (!req.headers.count(kAuthorization)) {
|
||||||
return config.isAuthRequired() ? HTTP_STATUS_UNAUTHORIZED : HTTP_STATUS_OK;
|
return config.isAuthRequired() ? 401 /* UNAUTHORIZED */ : 200;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.token().isNull()) {
|
if (config.token().isNull()) {
|
||||||
return HTTP_STATUS_UNAUTHORIZED;
|
return 401 /* UNAUTHORIZED */;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string &token = req.headers.at(kAuthorization);
|
const std::string &token = req.headers.at(kAuthorization);
|
||||||
const size_t size = token.size();
|
const size_t size = token.size();
|
||||||
|
|
||||||
if (token.size() < 8 || config.token().size() != size - 7 || memcmp("Bearer ", token.c_str(), 7) != 0) {
|
if (token.size() < 8 || config.token().size() != size - 7 || memcmp("Bearer ", token.c_str(), 7) != 0) {
|
||||||
return HTTP_STATUS_FORBIDDEN;
|
return 403 /* FORBIDDEN */;
|
||||||
}
|
}
|
||||||
|
|
||||||
return strncmp(config.token().data(), token.c_str() + 7, config.token().size()) == 0 ? HTTP_STATUS_OK : HTTP_STATUS_FORBIDDEN;
|
return strncmp(config.token().data(), token.c_str() + 7, config.token().size()) == 0 ? 200 : 403 /* FORBIDDEN */;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,6 @@
|
||||||
/* XMRig
|
/* XMRig
|
||||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
|
||||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
|
||||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
|
||||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
|
|
@ -1,12 +1,6 @@
|
||||||
/* XMRig
|
/* XMRig
|
||||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
|
||||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
|
||||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
|
||||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -24,7 +18,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include "base/api/requests/HttpApiRequest.h"
|
#include "base/api/requests/HttpApiRequest.h"
|
||||||
#include "3rdparty/http-parser/http_parser.h"
|
#include "3rdparty/llhttp/llhttp.h"
|
||||||
#include "3rdparty/rapidjson/error/en.h"
|
#include "3rdparty/rapidjson/error/en.h"
|
||||||
#include "base/io/json/Json.h"
|
#include "base/io/json/Json.h"
|
||||||
#include "base/net/http/HttpData.h"
|
#include "base/net/http/HttpData.h"
|
||||||
|
@ -53,8 +47,8 @@ static inline const char *rpcError(int code) {
|
||||||
return "Invalid params";
|
return "Invalid params";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (code >= HTTP_STATUS_BAD_REQUEST && code <= HTTP_STATUS_NETWORK_AUTHENTICATION_REQUIRED) {
|
if (code >= 400 && code < 600) {
|
||||||
return http_status_str(static_cast<http_status>(code));
|
return HttpData::statusName(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
return "Internal error";
|
return "Internal error";
|
||||||
|
@ -155,10 +149,10 @@ void xmrig::HttpApiRequest::done(int status)
|
||||||
using namespace rapidjson;
|
using namespace rapidjson;
|
||||||
auto &allocator = doc().GetAllocator();
|
auto &allocator = doc().GetAllocator();
|
||||||
|
|
||||||
m_res.setStatus(HTTP_STATUS_OK);
|
m_res.setStatus(200);
|
||||||
|
|
||||||
if (status != HTTP_STATUS_OK) {
|
if (status != 200) {
|
||||||
setRpcError(status == HTTP_STATUS_NOT_FOUND ? RPC_METHOD_NOT_FOUND : status);
|
setRpcError(status == 404 /* NOT_FOUND */ ? RPC_METHOD_NOT_FOUND : status);
|
||||||
}
|
}
|
||||||
else if (!reply().HasMember(kResult)) {
|
else if (!reply().HasMember(kResult)) {
|
||||||
Value result(kObjectType);
|
Value result(kObjectType);
|
||||||
|
@ -205,6 +199,6 @@ void xmrig::HttpApiRequest::rpcDone(const char *key, rapidjson::Value &value)
|
||||||
reply().AddMember("jsonrpc", "2.0", allocator);
|
reply().AddMember("jsonrpc", "2.0", allocator);
|
||||||
reply().AddMember(StringRef(kId), Value().CopyFrom(Json::getValue(m_body, kId), allocator), allocator);
|
reply().AddMember(StringRef(kId), Value().CopyFrom(Json::getValue(m_body, kId), allocator), allocator);
|
||||||
|
|
||||||
m_res.setStatus(HTTP_STATUS_OK);
|
m_res.setStatus(200);
|
||||||
m_res.end();
|
m_res.end();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,6 @@
|
||||||
/* XMRig
|
/* XMRig
|
||||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
|
||||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
|
||||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
|
||||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
|
|
@ -160,7 +160,7 @@ endif()
|
||||||
|
|
||||||
if (WITH_HTTP)
|
if (WITH_HTTP)
|
||||||
set(HEADERS_BASE_HTTP
|
set(HEADERS_BASE_HTTP
|
||||||
src/3rdparty/http-parser/http_parser.h
|
src/3rdparty/llhttp/llhttp.h
|
||||||
src/base/api/Api.h
|
src/base/api/Api.h
|
||||||
src/base/api/Httpd.h
|
src/base/api/Httpd.h
|
||||||
src/base/api/interfaces/IApiRequest.h
|
src/base/api/interfaces/IApiRequest.h
|
||||||
|
@ -181,7 +181,9 @@ if (WITH_HTTP)
|
||||||
)
|
)
|
||||||
|
|
||||||
set(SOURCES_BASE_HTTP
|
set(SOURCES_BASE_HTTP
|
||||||
src/3rdparty/http-parser/http_parser.c
|
src/3rdparty/llhttp/llhttp.c
|
||||||
|
src/3rdparty/llhttp/api.c
|
||||||
|
src/3rdparty/llhttp/http.c
|
||||||
src/base/api/Api.cpp
|
src/base/api/Api.cpp
|
||||||
src/base/api/Httpd.cpp
|
src/base/api/Httpd.cpp
|
||||||
src/base/api/requests/ApiRequest.cpp
|
src/base/api/requests/ApiRequest.cpp
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* XMRig
|
/* XMRig
|
||||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -37,9 +37,6 @@ static void fsWriteCallback(uv_fs_t *req)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static const char *kNewLine = "\n";
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace xmrig
|
} // namespace xmrig
|
||||||
|
|
||||||
|
|
||||||
|
@ -50,11 +47,24 @@ bool xmrig::FileLogWriter::open(const char *fileName)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uv_fs_t req;
|
uv_fs_t req{};
|
||||||
m_file = uv_fs_open(uv_default_loop(), &req, Env::expand(fileName), O_CREAT | O_APPEND | O_WRONLY, 0644, nullptr);
|
const auto path = Env::expand(fileName);
|
||||||
|
m_file = uv_fs_open(uv_default_loop(), &req, path, O_CREAT | O_WRONLY, 0644, nullptr);
|
||||||
|
|
||||||
|
if (req.result < 0 || !isOpen()) {
|
||||||
|
uv_fs_req_cleanup(&req);
|
||||||
|
m_file = -1;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
uv_fs_req_cleanup(&req);
|
uv_fs_req_cleanup(&req);
|
||||||
|
|
||||||
return isOpen();
|
uv_fs_stat(uv_default_loop(), &req, path, nullptr);
|
||||||
|
m_pos = req.statbuf.st_size;
|
||||||
|
uv_fs_req_cleanup(&req);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -70,7 +80,8 @@ bool xmrig::FileLogWriter::write(const char *data, size_t size)
|
||||||
auto req = new uv_fs_t;
|
auto req = new uv_fs_t;
|
||||||
req->data = buf.base;
|
req->data = buf.base;
|
||||||
|
|
||||||
uv_fs_write(uv_default_loop(), req, m_file, &buf, 1, -1, fsWriteCallback);
|
uv_fs_write(uv_default_loop(), req, m_file, &buf, 1, m_pos, fsWriteCallback);
|
||||||
|
m_pos += size;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -78,9 +89,9 @@ bool xmrig::FileLogWriter::write(const char *data, size_t size)
|
||||||
|
|
||||||
bool xmrig::FileLogWriter::writeLine(const char *data, size_t size)
|
bool xmrig::FileLogWriter::writeLine(const char *data, size_t size)
|
||||||
{
|
{
|
||||||
uv_buf_t buf[2] = {
|
const uv_buf_t buf[2] = {
|
||||||
uv_buf_init(new char[size], size),
|
uv_buf_init(new char[size], size),
|
||||||
uv_buf_init(const_cast<char *>(kNewLine), 1)
|
uv_buf_init(m_endl, sizeof(m_endl) - 1)
|
||||||
};
|
};
|
||||||
|
|
||||||
memcpy(buf[0].base, data, size);
|
memcpy(buf[0].base, data, size);
|
||||||
|
@ -88,7 +99,8 @@ bool xmrig::FileLogWriter::writeLine(const char *data, size_t size)
|
||||||
auto req = new uv_fs_t;
|
auto req = new uv_fs_t;
|
||||||
req->data = buf[0].base;
|
req->data = buf[0].base;
|
||||||
|
|
||||||
uv_fs_write(uv_default_loop(), req, m_file, buf, 2, -1, fsWriteCallback);
|
uv_fs_write(uv_default_loop(), req, m_file, buf, 2, m_pos, fsWriteCallback);
|
||||||
|
m_pos += (buf[0].len + buf[1].len);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* XMRig
|
/* XMRig
|
||||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
|
||||||
namespace xmrig {
|
namespace xmrig {
|
||||||
|
@ -33,13 +34,21 @@ public:
|
||||||
FileLogWriter(const char *fileName) { open(fileName); }
|
FileLogWriter(const char *fileName) { open(fileName); }
|
||||||
|
|
||||||
inline bool isOpen() const { return m_file >= 0; }
|
inline bool isOpen() const { return m_file >= 0; }
|
||||||
|
inline int64_t pos() const { return m_pos; }
|
||||||
|
|
||||||
bool open(const char *fileName);
|
bool open(const char *fileName);
|
||||||
bool write(const char *data, size_t size);
|
bool write(const char *data, size_t size);
|
||||||
bool writeLine(const char *data, size_t size);
|
bool writeLine(const char *data, size_t size);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
# ifdef XMRIG_OS_WIN
|
||||||
|
char m_endl[3] = "\r\n";
|
||||||
|
# else
|
||||||
|
char m_endl[2] = "\n";
|
||||||
|
# endif
|
||||||
|
|
||||||
int m_file = -1;
|
int m_file = -1;
|
||||||
|
int64_t m_pos = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* XMRig
|
/* XMRig
|
||||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -30,7 +30,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
xmrig::FetchRequest::FetchRequest(http_method method, const String &host, uint16_t port, const String &path, bool tls, bool quiet, const char *data, size_t size, const char *contentType) :
|
xmrig::FetchRequest::FetchRequest(llhttp_method method, const String &host, uint16_t port, const String &path, bool tls, bool quiet, const char *data, size_t size, const char *contentType) :
|
||||||
quiet(quiet),
|
quiet(quiet),
|
||||||
tls(tls),
|
tls(tls),
|
||||||
method(method),
|
method(method),
|
||||||
|
@ -44,7 +44,7 @@ xmrig::FetchRequest::FetchRequest(http_method method, const String &host, uint16
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
xmrig::FetchRequest::FetchRequest(http_method method, const String &host, uint16_t port, const String &path, const rapidjson::Value &value, bool tls, bool quiet) :
|
xmrig::FetchRequest::FetchRequest(llhttp_method method, const String &host, uint16_t port, const String &path, const rapidjson::Value &value, bool tls, bool quiet) :
|
||||||
quiet(quiet),
|
quiet(quiet),
|
||||||
tls(tls),
|
tls(tls),
|
||||||
method(method),
|
method(method),
|
||||||
|
@ -99,7 +99,7 @@ void xmrig::fetch(const char *tag, FetchRequest &&req, const std::weak_ptr<IHttp
|
||||||
{
|
{
|
||||||
# ifdef APP_DEBUG
|
# ifdef APP_DEBUG
|
||||||
LOG_DEBUG(CYAN("http%s://%s:%u ") MAGENTA_BOLD("\"%s %s\"") BLACK_BOLD(" body: ") CYAN_BOLD("%zu") BLACK_BOLD(" bytes"),
|
LOG_DEBUG(CYAN("http%s://%s:%u ") MAGENTA_BOLD("\"%s %s\"") BLACK_BOLD(" body: ") CYAN_BOLD("%zu") BLACK_BOLD(" bytes"),
|
||||||
req.tls ? "s" : "", req.host.data(), req.port, http_method_str(req.method), req.path.data(), req.body.size());
|
req.tls ? "s" : "", req.host.data(), req.port, llhttp_method_name(req.method), req.path.data(), req.body.size());
|
||||||
|
|
||||||
if (req.hasBody() && req.body.size() < (Log::kMaxBufferSize - 1024) && req.headers.count(HttpData::kContentType) && req.headers.at(HttpData::kContentType) == HttpData::kApplicationJson) {
|
if (req.hasBody() && req.body.size() < (Log::kMaxBufferSize - 1024) && req.headers.count(HttpData::kContentType) && req.headers.at(HttpData::kContentType) == HttpData::kApplicationJson) {
|
||||||
Log::print(BLUE_BG_BOLD("%s:") BLACK_BOLD_S " %.*s", req.headers.at(HttpData::kContentType).c_str(), static_cast<int>(req.body.size()), req.body.c_str());
|
Log::print(BLUE_BG_BOLD("%s:") BLACK_BOLD_S " %.*s", req.headers.at(HttpData::kContentType).c_str(), static_cast<int>(req.body.size()), req.body.c_str());
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* XMRig
|
/* XMRig
|
||||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -21,7 +21,7 @@
|
||||||
#define XMRIG_FETCH_H
|
#define XMRIG_FETCH_H
|
||||||
|
|
||||||
|
|
||||||
#include "3rdparty/http-parser/http_parser.h"
|
#include "3rdparty/llhttp/llhttp.h"
|
||||||
#include "3rdparty/rapidjson/fwd.h"
|
#include "3rdparty/rapidjson/fwd.h"
|
||||||
#include "base/tools/String.h"
|
#include "base/tools/String.h"
|
||||||
|
|
||||||
|
@ -41,8 +41,8 @@ class FetchRequest
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FetchRequest() = default;
|
FetchRequest() = default;
|
||||||
FetchRequest(http_method method, const String &host, uint16_t port, const String &path, bool tls = false, bool quiet = false, const char *data = nullptr, size_t size = 0, const char *contentType = nullptr);
|
FetchRequest(llhttp_method method, const String &host, uint16_t port, const String &path, bool tls = false, bool quiet = false, const char *data = nullptr, size_t size = 0, const char *contentType = nullptr);
|
||||||
FetchRequest(http_method method, const String &host, uint16_t port, const String &path, const rapidjson::Value &value, bool tls = false, bool quiet = false);
|
FetchRequest(llhttp_method method, const String &host, uint16_t port, const String &path, const rapidjson::Value &value, bool tls = false, bool quiet = false);
|
||||||
|
|
||||||
void setBody(const char *data, size_t size, const char *contentType = nullptr);
|
void setBody(const char *data, size_t size, const char *contentType = nullptr);
|
||||||
void setBody(const rapidjson::Value &value);
|
void setBody(const rapidjson::Value &value);
|
||||||
|
@ -51,7 +51,7 @@ public:
|
||||||
|
|
||||||
bool quiet = false;
|
bool quiet = false;
|
||||||
bool tls = false;
|
bool tls = false;
|
||||||
http_method method = HTTP_GET;
|
llhttp_method method = HTTP_GET;
|
||||||
std::map<const std::string, const std::string> headers;
|
std::map<const std::string, const std::string> headers;
|
||||||
std::string body;
|
std::string body;
|
||||||
String fingerprint;
|
String fingerprint;
|
||||||
|
|
|
@ -1,13 +1,7 @@
|
||||||
/* XMRig
|
/* XMRig
|
||||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
|
||||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
|
||||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
|
||||||
* Copyright 2014-2019 heapwolf <https://github.com/heapwolf>
|
|
||||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
|
||||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -25,7 +19,6 @@
|
||||||
|
|
||||||
|
|
||||||
#include "base/net/http/HttpApiResponse.h"
|
#include "base/net/http/HttpApiResponse.h"
|
||||||
#include "3rdparty/http-parser/http_parser.h"
|
|
||||||
#include "3rdparty/rapidjson/prettywriter.h"
|
#include "3rdparty/rapidjson/prettywriter.h"
|
||||||
#include "3rdparty/rapidjson/stringbuffer.h"
|
#include "3rdparty/rapidjson/stringbuffer.h"
|
||||||
#include "base/net/http/HttpData.h"
|
#include "base/net/http/HttpData.h"
|
||||||
|
@ -68,7 +61,7 @@ void xmrig::HttpApiResponse::end()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_doc.HasMember(kError)) {
|
if (!m_doc.HasMember(kError)) {
|
||||||
m_doc.AddMember(StringRef(kError), StringRef(http_status_str(static_cast<http_status>(statusCode()))), m_doc.GetAllocator());
|
m_doc.AddMember(StringRef(kError), StringRef(HttpData::statusName(statusCode())), m_doc.GetAllocator());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,7 @@
|
||||||
/* XMRig
|
/* XMRig
|
||||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
|
||||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
|
||||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
|
||||||
* Copyright 2014-2019 heapwolf <https://github.com/heapwolf>
|
|
||||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
|
||||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -23,7 +17,6 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef XMRIG_HTTPAPIRESPONSE_H
|
#ifndef XMRIG_HTTPAPIRESPONSE_H
|
||||||
#define XMRIG_HTTPAPIRESPONSE_H
|
#define XMRIG_HTTPAPIRESPONSE_H
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/* XMRig
|
/* XMRig
|
||||||
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
|
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
|
||||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include "base/net/http/HttpClient.h"
|
#include "base/net/http/HttpClient.h"
|
||||||
#include "3rdparty/http-parser/http_parser.h"
|
#include "3rdparty/llhttp/llhttp.h"
|
||||||
#include "base/io/log/Log.h"
|
#include "base/io/log/Log.h"
|
||||||
#include "base/kernel/Platform.h"
|
#include "base/kernel/Platform.h"
|
||||||
#include "base/net/dns/Dns.h"
|
#include "base/net/dns/Dns.h"
|
||||||
|
@ -102,7 +102,7 @@ void xmrig::HttpClient::handshake()
|
||||||
}
|
}
|
||||||
|
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << http_method_str(static_cast<http_method>(method)) << " " << url << " HTTP/1.1" << kCRLF;
|
ss << llhttp_method_name(static_cast<llhttp_method>(method)) << " " << url << " HTTP/1.1" << kCRLF;
|
||||||
|
|
||||||
for (auto &header : headers) {
|
for (auto &header : headers) {
|
||||||
ss << header.first << ": " << header.second << kCRLF;
|
ss << header.first << ": " << header.second << kCRLF;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/* XMRig
|
/* XMRig
|
||||||
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
|
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
|
||||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/* XMRig
|
/* XMRig
|
||||||
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
|
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
|
||||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include "base/net/http/HttpContext.h"
|
#include "base/net/http/HttpContext.h"
|
||||||
#include "3rdparty/http-parser/http_parser.h"
|
#include "3rdparty/llhttp/llhttp.h"
|
||||||
#include "base/kernel/interfaces/IHttpListener.h"
|
#include "base/kernel/interfaces/IHttpListener.h"
|
||||||
#include "base/tools/Baton.h"
|
#include "base/tools/Baton.h"
|
||||||
#include "base/tools/Chrono.h"
|
#include "base/tools/Chrono.h"
|
||||||
|
@ -32,7 +32,7 @@
|
||||||
namespace xmrig {
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
static http_parser_settings http_settings;
|
static llhttp_settings_t http_settings;
|
||||||
static std::map<uint64_t, HttpContext *> storage;
|
static std::map<uint64_t, HttpContext *> storage;
|
||||||
static uint64_t SEQUENCE = 0;
|
static uint64_t SEQUENCE = 0;
|
||||||
|
|
||||||
|
@ -78,13 +78,13 @@ xmrig::HttpContext::HttpContext(int parser_type, const std::weak_ptr<IHttpListen
|
||||||
{
|
{
|
||||||
storage[id()] = this;
|
storage[id()] = this;
|
||||||
|
|
||||||
m_parser = new http_parser;
|
m_parser = new llhttp_t;
|
||||||
m_tcp = new uv_tcp_t;
|
m_tcp = new uv_tcp_t;
|
||||||
|
|
||||||
uv_tcp_init(uv_default_loop(), m_tcp);
|
uv_tcp_init(uv_default_loop(), m_tcp);
|
||||||
uv_tcp_nodelay(m_tcp, 1);
|
uv_tcp_nodelay(m_tcp, 1);
|
||||||
|
|
||||||
http_parser_init(m_parser, static_cast<http_parser_type>(parser_type));
|
llhttp_init(m_parser, static_cast<llhttp_type_t>(parser_type), &http_settings);
|
||||||
|
|
||||||
m_parser->data = m_tcp->data = this;
|
m_parser->data = m_tcp->data = this;
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ size_t xmrig::HttpContext::parse(const char *data, size_t size)
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
return http_parser_execute(m_parser, &http_settings, data, size);
|
return llhttp_execute(m_parser, data, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -175,11 +175,9 @@ void xmrig::HttpContext::close(int status)
|
||||||
|
|
||||||
xmrig::HttpContext *xmrig::HttpContext::get(uint64_t id)
|
xmrig::HttpContext *xmrig::HttpContext::get(uint64_t id)
|
||||||
{
|
{
|
||||||
if (storage.count(id) == 0) {
|
const auto it = storage.find(id);
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return storage[id];
|
return it == storage.end() ? nullptr : it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -193,7 +191,7 @@ void xmrig::HttpContext::closeAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int xmrig::HttpContext::onHeaderField(http_parser *parser, const char *at, size_t length)
|
int xmrig::HttpContext::onHeaderField(llhttp_t *parser, const char *at, size_t length)
|
||||||
{
|
{
|
||||||
auto ctx = static_cast<HttpContext*>(parser->data);
|
auto ctx = static_cast<HttpContext*>(parser->data);
|
||||||
|
|
||||||
|
@ -212,7 +210,7 @@ int xmrig::HttpContext::onHeaderField(http_parser *parser, const char *at, size_
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int xmrig::HttpContext::onHeaderValue(http_parser *parser, const char *at, size_t length)
|
int xmrig::HttpContext::onHeaderValue(llhttp_t *parser, const char *at, size_t length)
|
||||||
{
|
{
|
||||||
auto ctx = static_cast<HttpContext*>(parser->data);
|
auto ctx = static_cast<HttpContext*>(parser->data);
|
||||||
|
|
||||||
|
@ -227,14 +225,14 @@ int xmrig::HttpContext::onHeaderValue(http_parser *parser, const char *at, size_
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void xmrig::HttpContext::attach(http_parser_settings *settings)
|
void xmrig::HttpContext::attach(llhttp_settings_t *settings)
|
||||||
{
|
{
|
||||||
settings->on_message_begin = nullptr;
|
settings->on_message_begin = nullptr;
|
||||||
settings->on_status = nullptr;
|
settings->on_status = nullptr;
|
||||||
settings->on_chunk_header = nullptr;
|
settings->on_chunk_header = nullptr;
|
||||||
settings->on_chunk_complete = nullptr;
|
settings->on_chunk_complete = nullptr;
|
||||||
|
|
||||||
settings->on_url = [](http_parser *parser, const char *at, size_t length) -> int
|
settings->on_url = [](llhttp_t *parser, const char *at, size_t length) -> int
|
||||||
{
|
{
|
||||||
static_cast<HttpContext*>(parser->data)->url = std::string(at, length);
|
static_cast<HttpContext*>(parser->data)->url = std::string(at, length);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -243,7 +241,7 @@ void xmrig::HttpContext::attach(http_parser_settings *settings)
|
||||||
settings->on_header_field = onHeaderField;
|
settings->on_header_field = onHeaderField;
|
||||||
settings->on_header_value = onHeaderValue;
|
settings->on_header_value = onHeaderValue;
|
||||||
|
|
||||||
settings->on_headers_complete = [](http_parser* parser) -> int {
|
settings->on_headers_complete = [](llhttp_t *parser) -> int {
|
||||||
auto ctx = static_cast<HttpContext*>(parser->data);
|
auto ctx = static_cast<HttpContext*>(parser->data);
|
||||||
ctx->status = parser->status_code;
|
ctx->status = parser->status_code;
|
||||||
|
|
||||||
|
@ -258,14 +256,14 @@ void xmrig::HttpContext::attach(http_parser_settings *settings)
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
settings->on_body = [](http_parser *parser, const char *at, size_t len) -> int
|
settings->on_body = [](llhttp_t *parser, const char *at, size_t len) -> int
|
||||||
{
|
{
|
||||||
static_cast<HttpContext*>(parser->data)->body.append(at, len);
|
static_cast<HttpContext*>(parser->data)->body.append(at, len);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
settings->on_message_complete = [](http_parser *parser) -> int
|
settings->on_message_complete = [](llhttp_t *parser) -> int
|
||||||
{
|
{
|
||||||
auto ctx = static_cast<HttpContext*>(parser->data);
|
auto ctx = static_cast<HttpContext*>(parser->data);
|
||||||
auto listener = ctx->httpListener();
|
auto listener = ctx->httpListener();
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/* XMRig
|
/* XMRig
|
||||||
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
|
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
|
||||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -22,8 +22,8 @@
|
||||||
#define XMRIG_HTTPCONTEXT_H
|
#define XMRIG_HTTPCONTEXT_H
|
||||||
|
|
||||||
|
|
||||||
using http_parser = struct http_parser;
|
using llhttp_settings_t = struct llhttp_settings_s;
|
||||||
using http_parser_settings = struct http_parser_settings;
|
using llhttp_t = struct llhttp__internal_s;
|
||||||
using uv_connect_t = struct uv_connect_s;
|
using uv_connect_t = struct uv_connect_s;
|
||||||
using uv_handle_t = struct uv_handle_s;
|
using uv_handle_t = struct uv_handle_s;
|
||||||
using uv_stream_t = struct uv_stream_s;
|
using uv_stream_t = struct uv_stream_s;
|
||||||
|
@ -76,15 +76,15 @@ protected:
|
||||||
private:
|
private:
|
||||||
inline IHttpListener *httpListener() const { return m_listener.expired() ? nullptr : m_listener.lock().get(); }
|
inline IHttpListener *httpListener() const { return m_listener.expired() ? nullptr : m_listener.lock().get(); }
|
||||||
|
|
||||||
static int onHeaderField(http_parser *parser, const char *at, size_t length);
|
static int onHeaderField(llhttp_t *parser, const char *at, size_t length);
|
||||||
static int onHeaderValue(http_parser *parser, const char *at, size_t length);
|
static int onHeaderValue(llhttp_t *parser, const char *at, size_t length);
|
||||||
static void attach(http_parser_settings *settings);
|
static void attach(llhttp_settings_t *settings);
|
||||||
|
|
||||||
void setHeader();
|
void setHeader();
|
||||||
|
|
||||||
bool m_wasHeaderValue = false;
|
bool m_wasHeaderValue = false;
|
||||||
const uint64_t m_timestamp;
|
const uint64_t m_timestamp;
|
||||||
http_parser *m_parser;
|
llhttp_t *m_parser;
|
||||||
std::string m_lastHeaderField;
|
std::string m_lastHeaderField;
|
||||||
std::string m_lastHeaderValue;
|
std::string m_lastHeaderValue;
|
||||||
std::weak_ptr<IHttpListener> m_listener;
|
std::weak_ptr<IHttpListener> m_listener;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/* XMRig
|
/* XMRig
|
||||||
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
|
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
|
||||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include "base/net/http/HttpData.h"
|
#include "base/net/http/HttpData.h"
|
||||||
#include "3rdparty/http-parser/http_parser.h"
|
#include "3rdparty/llhttp/llhttp.h"
|
||||||
#include "3rdparty/rapidjson/document.h"
|
#include "3rdparty/rapidjson/document.h"
|
||||||
#include "3rdparty/rapidjson/error/en.h"
|
#include "3rdparty/rapidjson/error/en.h"
|
||||||
#include "base/io/json/Json.h"
|
#include "base/io/json/Json.h"
|
||||||
|
@ -29,6 +29,76 @@
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
|
|
||||||
|
/* Status Codes */
|
||||||
|
#define HTTP_STATUS_MAP(XX) \
|
||||||
|
XX(100, CONTINUE, Continue) \
|
||||||
|
XX(101, SWITCHING_PROTOCOLS, Switching Protocols) \
|
||||||
|
XX(102, PROCESSING, Processing) \
|
||||||
|
XX(200, OK, OK) \
|
||||||
|
XX(201, CREATED, Created) \
|
||||||
|
XX(202, ACCEPTED, Accepted) \
|
||||||
|
XX(203, NON_AUTHORITATIVE_INFORMATION, Non-Authoritative Information) \
|
||||||
|
XX(204, NO_CONTENT, No Content) \
|
||||||
|
XX(205, RESET_CONTENT, Reset Content) \
|
||||||
|
XX(206, PARTIAL_CONTENT, Partial Content) \
|
||||||
|
XX(207, MULTI_STATUS, Multi-Status) \
|
||||||
|
XX(208, ALREADY_REPORTED, Already Reported) \
|
||||||
|
XX(226, IM_USED, IM Used) \
|
||||||
|
XX(300, MULTIPLE_CHOICES, Multiple Choices) \
|
||||||
|
XX(301, MOVED_PERMANENTLY, Moved Permanently) \
|
||||||
|
XX(302, FOUND, Found) \
|
||||||
|
XX(303, SEE_OTHER, See Other) \
|
||||||
|
XX(304, NOT_MODIFIED, Not Modified) \
|
||||||
|
XX(305, USE_PROXY, Use Proxy) \
|
||||||
|
XX(307, TEMPORARY_REDIRECT, Temporary Redirect) \
|
||||||
|
XX(308, PERMANENT_REDIRECT, Permanent Redirect) \
|
||||||
|
XX(400, BAD_REQUEST, Bad Request) \
|
||||||
|
XX(401, UNAUTHORIZED, Unauthorized) \
|
||||||
|
XX(402, PAYMENT_REQUIRED, Payment Required) \
|
||||||
|
XX(403, FORBIDDEN, Forbidden) \
|
||||||
|
XX(404, NOT_FOUND, Not Found) \
|
||||||
|
XX(405, METHOD_NOT_ALLOWED, Method Not Allowed) \
|
||||||
|
XX(406, NOT_ACCEPTABLE, Not Acceptable) \
|
||||||
|
XX(407, PROXY_AUTHENTICATION_REQUIRED, Proxy Authentication Required) \
|
||||||
|
XX(408, REQUEST_TIMEOUT, Request Timeout) \
|
||||||
|
XX(409, CONFLICT, Conflict) \
|
||||||
|
XX(410, GONE, Gone) \
|
||||||
|
XX(411, LENGTH_REQUIRED, Length Required) \
|
||||||
|
XX(412, PRECONDITION_FAILED, Precondition Failed) \
|
||||||
|
XX(413, PAYLOAD_TOO_LARGE, Payload Too Large) \
|
||||||
|
XX(414, URI_TOO_LONG, URI Too Long) \
|
||||||
|
XX(415, UNSUPPORTED_MEDIA_TYPE, Unsupported Media Type) \
|
||||||
|
XX(416, RANGE_NOT_SATISFIABLE, Range Not Satisfiable) \
|
||||||
|
XX(417, EXPECTATION_FAILED, Expectation Failed) \
|
||||||
|
XX(421, MISDIRECTED_REQUEST, Misdirected Request) \
|
||||||
|
XX(422, UNPROCESSABLE_ENTITY, Unprocessable Entity) \
|
||||||
|
XX(423, LOCKED, Locked) \
|
||||||
|
XX(424, FAILED_DEPENDENCY, Failed Dependency) \
|
||||||
|
XX(426, UPGRADE_REQUIRED, Upgrade Required) \
|
||||||
|
XX(428, PRECONDITION_REQUIRED, Precondition Required) \
|
||||||
|
XX(429, TOO_MANY_REQUESTS, Too Many Requests) \
|
||||||
|
XX(431, REQUEST_HEADER_FIELDS_TOO_LARGE, Request Header Fields Too Large) \
|
||||||
|
XX(451, UNAVAILABLE_FOR_LEGAL_REASONS, Unavailable For Legal Reasons) \
|
||||||
|
XX(500, INTERNAL_SERVER_ERROR, Internal Server Error) \
|
||||||
|
XX(501, NOT_IMPLEMENTED, Not Implemented) \
|
||||||
|
XX(502, BAD_GATEWAY, Bad Gateway) \
|
||||||
|
XX(503, SERVICE_UNAVAILABLE, Service Unavailable) \
|
||||||
|
XX(504, GATEWAY_TIMEOUT, Gateway Timeout) \
|
||||||
|
XX(505, HTTP_VERSION_NOT_SUPPORTED, HTTP Version Not Supported) \
|
||||||
|
XX(506, VARIANT_ALSO_NEGOTIATES, Variant Also Negotiates) \
|
||||||
|
XX(507, INSUFFICIENT_STORAGE, Insufficient Storage) \
|
||||||
|
XX(508, LOOP_DETECTED, Loop Detected) \
|
||||||
|
XX(510, NOT_EXTENDED, Not Extended) \
|
||||||
|
XX(511, NETWORK_AUTHENTICATION_REQUIRED, Network Authentication Required) \
|
||||||
|
|
||||||
|
enum http_status
|
||||||
|
{
|
||||||
|
# define XX(num, name, string) HTTP_STATUS_##name = num,
|
||||||
|
HTTP_STATUS_MAP(XX)
|
||||||
|
# undef XX
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
namespace xmrig {
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
|
@ -38,6 +108,17 @@ const std::string HttpData::kContentTypeL = "content-type";
|
||||||
const std::string HttpData::kTextPlain = "text/plain";
|
const std::string HttpData::kTextPlain = "text/plain";
|
||||||
|
|
||||||
|
|
||||||
|
static const char *http_status_str(enum http_status s)
|
||||||
|
{
|
||||||
|
switch (s) {
|
||||||
|
# define XX(num, name, string) case HTTP_STATUS_##name: return #string;
|
||||||
|
HTTP_STATUS_MAP(XX)
|
||||||
|
# undef XX
|
||||||
|
default: return "<unknown>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace xmrig
|
} // namespace xmrig
|
||||||
|
|
||||||
|
|
||||||
|
@ -55,17 +136,7 @@ bool xmrig::HttpData::isJSON() const
|
||||||
|
|
||||||
const char *xmrig::HttpData::methodName() const
|
const char *xmrig::HttpData::methodName() const
|
||||||
{
|
{
|
||||||
return http_method_str(static_cast<http_method>(method));
|
return llhttp_method_name(static_cast<llhttp_method>(method));
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const char *xmrig::HttpData::statusName() const
|
|
||||||
{
|
|
||||||
if (status < 0) {
|
|
||||||
return uv_strerror(status);
|
|
||||||
}
|
|
||||||
|
|
||||||
return http_status_str(static_cast<http_status>(status));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -94,3 +165,13 @@ rapidjson::Document xmrig::HttpData::json() const
|
||||||
|
|
||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const char *xmrig::HttpData::statusName(int status)
|
||||||
|
{
|
||||||
|
if (status < 0) {
|
||||||
|
return uv_strerror(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
return http_status_str(static_cast<http_status>(status));
|
||||||
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/* XMRig
|
/* XMRig
|
||||||
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
|
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
|
||||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -47,6 +47,7 @@ public:
|
||||||
inline HttpData(uint64_t id) : m_id(id) {}
|
inline HttpData(uint64_t id) : m_id(id) {}
|
||||||
virtual ~HttpData() = default;
|
virtual ~HttpData() = default;
|
||||||
|
|
||||||
|
inline const char *statusName() const { return statusName(status); }
|
||||||
inline uint64_t id() const { return m_id; }
|
inline uint64_t id() const { return m_id; }
|
||||||
|
|
||||||
virtual bool isRequest() const = 0;
|
virtual bool isRequest() const = 0;
|
||||||
|
@ -59,9 +60,10 @@ public:
|
||||||
|
|
||||||
bool isJSON() const;
|
bool isJSON() const;
|
||||||
const char *methodName() const;
|
const char *methodName() const;
|
||||||
const char *statusName() const;
|
|
||||||
rapidjson::Document json() const;
|
rapidjson::Document json() const;
|
||||||
|
|
||||||
|
static const char *statusName(int status);
|
||||||
|
|
||||||
int method = 0;
|
int method = 0;
|
||||||
int status = 0;
|
int status = 0;
|
||||||
int userType = 0;
|
int userType = 0;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* XMRig
|
/* XMRig
|
||||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include "base/net/http/HttpListener.h"
|
#include "base/net/http/HttpListener.h"
|
||||||
#include "3rdparty/http-parser/http_parser.h"
|
#include "3rdparty/llhttp/llhttp.h"
|
||||||
#include "base/io/log/Log.h"
|
#include "base/io/log/Log.h"
|
||||||
#include "base/net/http/HttpData.h"
|
#include "base/net/http/HttpData.h"
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ void xmrig::HttpListener::onHttpData(const HttpData &data)
|
||||||
# ifdef APP_DEBUG
|
# ifdef APP_DEBUG
|
||||||
if (!data.isRequest()) {
|
if (!data.isRequest()) {
|
||||||
LOG_DEBUG("%s " CYAN_BOLD("http%s://%s:%u ") MAGENTA_BOLD("\"%s %s\" ") CSI "1;%dm%d" CLEAR BLACK_BOLD(" received: ") CYAN_BOLD("%zu") BLACK_BOLD(" bytes"),
|
LOG_DEBUG("%s " CYAN_BOLD("http%s://%s:%u ") MAGENTA_BOLD("\"%s %s\" ") CSI "1;%dm%d" CLEAR BLACK_BOLD(" received: ") CYAN_BOLD("%zu") BLACK_BOLD(" bytes"),
|
||||||
m_tag, data.tlsVersion() ? "s" : "", data.host(), data.port(), http_method_str(static_cast<http_method>(data.method)), data.url.data(),
|
m_tag, data.tlsVersion() ? "s" : "", data.host(), data.port(), llhttp_method_name(static_cast<llhttp_method>(data.method)), data.url.data(),
|
||||||
(data.status >= 400 || data.status < 0) ? 31 : 32, data.status, data.body.size());
|
(data.status >= 400 || data.status < 0) ? 31 : 32, data.status, data.body.size());
|
||||||
|
|
||||||
if (data.body.size() < (Log::kMaxBufferSize - 1024) && data.isJSON()) {
|
if (data.body.size() < (Log::kMaxBufferSize - 1024) && data.isJSON()) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* XMRig
|
/* XMRig
|
||||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
|
|
@ -1,13 +1,7 @@
|
||||||
/* XMRig
|
/* XMRig
|
||||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
|
||||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
|
||||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
|
||||||
* Copyright 2014-2019 heapwolf <https://github.com/heapwolf>
|
|
||||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
|
||||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -25,7 +19,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include "base/net/http/HttpResponse.h"
|
#include "base/net/http/HttpResponse.h"
|
||||||
#include "3rdparty/http-parser/http_parser.h"
|
#include "3rdparty/llhttp/llhttp.h"
|
||||||
#include "base/io/log/Log.h"
|
#include "base/io/log/Log.h"
|
||||||
#include "base/net/http/HttpContext.h"
|
#include "base/net/http/HttpContext.h"
|
||||||
|
|
||||||
|
@ -78,7 +72,7 @@ void xmrig::HttpResponse::end(const char *data, size_t size)
|
||||||
setHeader("Connection", "close");
|
setHeader("Connection", "close");
|
||||||
|
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "HTTP/1.1 " << statusCode() << " " << http_status_str(static_cast<http_status>(statusCode())) << kCRLF;
|
ss << "HTTP/1.1 " << statusCode() << " " << HttpData::statusName(statusCode()) << kCRLF;
|
||||||
|
|
||||||
for (auto &header : m_headers) {
|
for (auto &header : m_headers) {
|
||||||
ss << header.first << ": " << header.second << kCRLF;
|
ss << header.first << ": " << header.second << kCRLF;
|
||||||
|
@ -97,7 +91,7 @@ void xmrig::HttpResponse::end(const char *data, size_t size)
|
||||||
|
|
||||||
Log::print(err ? Log::ERR : Log::INFO, CYAN("%s ") CLEAR MAGENTA_BOLD("%s") WHITE_BOLD(" %s ") CSI "1;%dm%d " CLEAR WHITE_BOLD("%zu ") CYAN_BOLD("%" PRIu64 "ms ") BLACK_BOLD("\"%s\""),
|
Log::print(err ? Log::ERR : Log::INFO, CYAN("%s ") CLEAR MAGENTA_BOLD("%s") WHITE_BOLD(" %s ") CSI "1;%dm%d " CLEAR WHITE_BOLD("%zu ") CYAN_BOLD("%" PRIu64 "ms ") BLACK_BOLD("\"%s\""),
|
||||||
ctx->ip().c_str(),
|
ctx->ip().c_str(),
|
||||||
http_method_str(static_cast<http_method>(ctx->method)),
|
llhttp_method_name(static_cast<llhttp_method>(ctx->method)),
|
||||||
ctx->url.c_str(),
|
ctx->url.c_str(),
|
||||||
err ? 31 : 32,
|
err ? 31 : 32,
|
||||||
statusCode(),
|
statusCode(),
|
||||||
|
|
|
@ -1,13 +1,7 @@
|
||||||
/* XMRig
|
/* XMRig
|
||||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
|
||||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
|
||||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
|
||||||
* Copyright 2014-2019 heapwolf <https://github.com/heapwolf>
|
|
||||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
|
||||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -23,7 +17,6 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef XMRIG_HTTPRESPONSE_H
|
#ifndef XMRIG_HTTPRESPONSE_H
|
||||||
#define XMRIG_HTTPRESPONSE_H
|
#define XMRIG_HTTPRESPONSE_H
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,7 @@
|
||||||
/* XMRig
|
/* XMRig
|
||||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
|
||||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
|
||||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
|
||||||
* Copyright 2014-2019 heapwolf <https://github.com/heapwolf>
|
|
||||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
|
||||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -29,7 +23,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include "base/net/http/HttpServer.h"
|
#include "base/net/http/HttpServer.h"
|
||||||
#include "3rdparty/http-parser/http_parser.h"
|
#include "3rdparty/llhttp/llhttp.h"
|
||||||
#include "base/net/http/HttpContext.h"
|
#include "base/net/http/HttpContext.h"
|
||||||
#include "base/net/tools/NetBuffer.h"
|
#include "base/net/tools/NetBuffer.h"
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,7 @@
|
||||||
/* XMRig
|
/* XMRig
|
||||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
|
||||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
|
||||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
|
||||||
* Copyright 2014-2019 heapwolf <https://github.com/heapwolf>
|
|
||||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
|
||||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -23,15 +17,10 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef XMRIG_HTTPSERVER_H
|
#ifndef XMRIG_HTTPSERVER_H
|
||||||
#define XMRIG_HTTPSERVER_H
|
#define XMRIG_HTTPSERVER_H
|
||||||
|
|
||||||
|
|
||||||
using http_parser = struct http_parser;
|
|
||||||
using http_parser_settings = struct http_parser_settings;
|
|
||||||
|
|
||||||
|
|
||||||
#include "base/kernel/interfaces/ITcpServerListener.h"
|
#include "base/kernel/interfaces/ITcpServerListener.h"
|
||||||
#include "base/tools/Object.h"
|
#include "base/tools/Object.h"
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* XMRig
|
/* XMRig
|
||||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include "base/net/https/HttpsContext.h"
|
#include "base/net/https/HttpsContext.h"
|
||||||
#include "3rdparty/http-parser/http_parser.h"
|
#include "3rdparty/llhttp/llhttp.h"
|
||||||
#include "base/net/tls/TlsContext.h"
|
#include "base/net/tls/TlsContext.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* XMRig
|
/* XMRig
|
||||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
|
|
@ -25,7 +25,6 @@
|
||||||
|
|
||||||
|
|
||||||
#include "base/net/stratum/DaemonClient.h"
|
#include "base/net/stratum/DaemonClient.h"
|
||||||
#include "3rdparty/http-parser/http_parser.h"
|
|
||||||
#include "3rdparty/rapidjson/document.h"
|
#include "3rdparty/rapidjson/document.h"
|
||||||
#include "3rdparty/rapidjson/error/en.h"
|
#include "3rdparty/rapidjson/error/en.h"
|
||||||
#include "base/io/json/Json.h"
|
#include "base/io/json/Json.h"
|
||||||
|
@ -151,7 +150,7 @@ void xmrig::DaemonClient::connect(const Pool &pool)
|
||||||
|
|
||||||
void xmrig::DaemonClient::onHttpData(const HttpData &data)
|
void xmrig::DaemonClient::onHttpData(const HttpData &data)
|
||||||
{
|
{
|
||||||
if (data.status != HTTP_STATUS_OK) {
|
if (data.status != 200) {
|
||||||
return retry();
|
return retry();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,13 +178,31 @@ void xmrig::DaemonClient::onHttpData(const HttpData &data)
|
||||||
return send(kGetInfo);
|
return send(kGetInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isOutdated(Json::getUint64(doc, kHeight), Json::getString(doc, kHash))) {
|
const uint64_t height = Json::getUint64(doc, kHeight);
|
||||||
|
const String hash = Json::getString(doc, kHash);
|
||||||
|
|
||||||
|
if (isOutdated(height, hash)) {
|
||||||
|
// Multiple /getheight responses can come at once resulting in multiple getBlockTemplate() calls
|
||||||
|
if ((height != m_blocktemplateRequestHeight) || (hash != m_blocktemplateRequestHash)) {
|
||||||
|
m_blocktemplateRequestHeight = height;
|
||||||
|
m_blocktemplateRequestHash = hash;
|
||||||
getBlockTemplate();
|
getBlockTemplate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (data.url == kGetInfo && isOutdated(Json::getUint64(doc, kHeight), Json::getString(doc, "top_block_hash"))) {
|
}
|
||||||
|
else if (data.url == kGetInfo) {
|
||||||
|
const uint64_t height = Json::getUint64(doc, kHeight);
|
||||||
|
const String hash = Json::getString(doc, "top_block_hash");
|
||||||
|
|
||||||
|
if (isOutdated(height, hash)) {
|
||||||
|
// Multiple /getinfo responses can come at once resulting in multiple getBlockTemplate() calls
|
||||||
|
if ((height != m_blocktemplateRequestHeight) || (hash != m_blocktemplateRequestHash)) {
|
||||||
|
m_blocktemplateRequestHeight = height;
|
||||||
|
m_blocktemplateRequestHash = hash;
|
||||||
getBlockTemplate();
|
getBlockTemplate();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,6 +89,8 @@ private:
|
||||||
String m_tlsFingerprint;
|
String m_tlsFingerprint;
|
||||||
String m_tlsVersion;
|
String m_tlsVersion;
|
||||||
Timer *m_timer;
|
Timer *m_timer;
|
||||||
|
uint64_t m_blocktemplateRequestHeight = 0;
|
||||||
|
String m_blocktemplateRequestHash;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -119,8 +119,10 @@ bool xmrig::Job::setTarget(const char *target)
|
||||||
}
|
}
|
||||||
|
|
||||||
# ifdef XMRIG_PROXY_PROJECT
|
# ifdef XMRIG_PROXY_PROJECT
|
||||||
|
assert(sizeof(m_rawTarget) > (size * 2));
|
||||||
|
|
||||||
memset(m_rawTarget, 0, sizeof(m_rawTarget));
|
memset(m_rawTarget, 0, sizeof(m_rawTarget));
|
||||||
memcpy(m_rawTarget, target, len);
|
memcpy(m_rawTarget, target, std::min(size * 2, sizeof(m_rawTarget)));
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
m_diff = toDiff(m_target);
|
m_diff = toDiff(m_target);
|
||||||
|
@ -134,8 +136,7 @@ void xmrig::Job::setDiff(uint64_t diff)
|
||||||
m_target = toDiff(diff);
|
m_target = toDiff(diff);
|
||||||
|
|
||||||
# ifdef XMRIG_PROXY_PROJECT
|
# ifdef XMRIG_PROXY_PROJECT
|
||||||
Buffer::toHex(reinterpret_cast<uint8_t *>(&m_target), 8, m_rawTarget);
|
Cvt::toHex(m_rawTarget, sizeof(m_rawTarget), reinterpret_cast<uint8_t *>(&m_target), sizeof(m_target));
|
||||||
m_rawTarget[16] = '\0';
|
|
||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
|
|
||||||
|
|
||||||
#include "base/net/stratum/SelfSelectClient.h"
|
#include "base/net/stratum/SelfSelectClient.h"
|
||||||
#include "3rdparty/http-parser/http_parser.h"
|
|
||||||
#include "3rdparty/rapidjson/document.h"
|
#include "3rdparty/rapidjson/document.h"
|
||||||
#include "3rdparty/rapidjson/error/en.h"
|
#include "3rdparty/rapidjson/error/en.h"
|
||||||
#include "base/io/json/Json.h"
|
#include "base/io/json/Json.h"
|
||||||
|
@ -288,7 +287,7 @@ void xmrig::SelfSelectClient::submitOriginDaemon(const JobResult& result)
|
||||||
|
|
||||||
void xmrig::SelfSelectClient::onHttpData(const HttpData &data)
|
void xmrig::SelfSelectClient::onHttpData(const HttpData &data)
|
||||||
{
|
{
|
||||||
if (data.status != HTTP_STATUS_OK) {
|
if (data.status != 200) {
|
||||||
return retry();
|
return retry();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -354,6 +354,7 @@ public:
|
||||||
bool battery_power = false;
|
bool battery_power = false;
|
||||||
bool user_active = false;
|
bool user_active = false;
|
||||||
bool enabled = true;
|
bool enabled = true;
|
||||||
|
int32_t auto_pause = 0;
|
||||||
bool reset = true;
|
bool reset = true;
|
||||||
Controller *controller;
|
Controller *controller;
|
||||||
Job job;
|
Job job;
|
||||||
|
@ -635,7 +636,8 @@ void xmrig::Miner::onTimer(const Timer *)
|
||||||
LOG_INFO("%s %s", Tags::miner(), pause ? pauseMessage : activeMessage);
|
LOG_INFO("%s %s", Tags::miner(), pause ? pauseMessage : activeMessage);
|
||||||
|
|
||||||
state = pause;
|
state = pause;
|
||||||
setEnabled(!pause);
|
d_ptr->auto_pause += pause ? 1 : -1;
|
||||||
|
setEnabled(d_ptr->auto_pause == 0);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -75,9 +75,9 @@ static inline const std::string &usage()
|
||||||
u += "\nCPU backend:\n";
|
u += "\nCPU backend:\n";
|
||||||
|
|
||||||
u += " --no-cpu disable CPU mining backend\n";
|
u += " --no-cpu disable CPU mining backend\n";
|
||||||
u += " -t, --threads=N number of CPU threads\n";
|
u += " -t, --threads=N number of CPU threads, proper CPU affinity required for some optimizations.\n";
|
||||||
u += " -v, --av=N algorithm variation, 0 auto select\n";
|
|
||||||
u += " --cpu-affinity set process affinity to CPU core(s), mask 0x3 for cores 0 and 1\n";
|
u += " --cpu-affinity set process affinity to CPU core(s), mask 0x3 for cores 0 and 1\n";
|
||||||
|
u += " -v, --av=N algorithm variation, 0 auto select\n";
|
||||||
u += " --cpu-priority set process priority (0 idle, 2 normal to 5 highest)\n";
|
u += " --cpu-priority set process priority (0 idle, 2 normal to 5 highest)\n";
|
||||||
u += " --cpu-max-threads-hint=N maximum CPU threads count (in percentage) hint for autoconfig\n";
|
u += " --cpu-max-threads-hint=N maximum CPU threads count (in percentage) hint for autoconfig\n";
|
||||||
u += " --cpu-memory-pool=N number of 2 MB pages for persistent memory pool, -1 (auto), 0 (disable)\n";
|
u += " --cpu-memory-pool=N number of 2 MB pages for persistent memory pool, -1 (auto), 0 (disable)\n";
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -230,6 +230,7 @@ void xmrig::DmiMemory::setId(const char *slot, const char *bank)
|
||||||
m_slot = slot;
|
m_slot = slot;
|
||||||
m_bank = bank;
|
m_bank = bank;
|
||||||
|
|
||||||
|
try {
|
||||||
std::cmatch cm;
|
std::cmatch cm;
|
||||||
if (std::regex_match(slot, cm, std::regex("^Channel([A-Z])[-_]DIMM(\\d+)$", std::regex_constants::icase))) {
|
if (std::regex_match(slot, cm, std::regex("^Channel([A-Z])[-_]DIMM(\\d+)$", std::regex_constants::icase))) {
|
||||||
m_id = fmt::format(kIdFormat, cm.str(1), cm.str(2)).c_str();
|
m_id = fmt::format(kIdFormat, cm.str(1), cm.str(2)).c_str();
|
||||||
|
@ -240,4 +241,5 @@ void xmrig::DmiMemory::setId(const char *slot, const char *bank)
|
||||||
m_id = fmt::format(kIdFormat, cm.str(1), cm2.str(1)).c_str();
|
m_id = fmt::format(kIdFormat, cm.str(1), cm2.str(1)).c_str();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (...) {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,14 +28,14 @@
|
||||||
#define APP_ID "xmrig"
|
#define APP_ID "xmrig"
|
||||||
#define APP_NAME "XMRig"
|
#define APP_NAME "XMRig"
|
||||||
#define APP_DESC "XMRig miner"
|
#define APP_DESC "XMRig miner"
|
||||||
#define APP_VERSION "6.9.0"
|
#define APP_VERSION "6.10.0-dev"
|
||||||
#define APP_DOMAIN "xmrig.com"
|
#define APP_DOMAIN "xmrig.com"
|
||||||
#define APP_SITE "www.xmrig.com"
|
#define APP_SITE "www.xmrig.com"
|
||||||
#define APP_COPYRIGHT "Copyright (C) 2016-2021 xmrig.com"
|
#define APP_COPYRIGHT "Copyright (C) 2016-2021 xmrig.com"
|
||||||
#define APP_KIND "miner"
|
#define APP_KIND "miner"
|
||||||
|
|
||||||
#define APP_VER_MAJOR 6
|
#define APP_VER_MAJOR 6
|
||||||
#define APP_VER_MINOR 9
|
#define APP_VER_MINOR 10
|
||||||
#define APP_VER_PATCH 0
|
#define APP_VER_PATCH 0
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue