From e011b5182d50142bfc74aac2930f5ff6dad7334a Mon Sep 17 00:00:00 2001 From: princeb612 Date: Sun, 21 Apr 2024 08:06:49 +0900 Subject: [PATCH] hotplace rev.500 grooming --- sdk/base/basic/cmdline.hpp | 2 +- sdk/base/basic/variant.cpp | 2 + sdk/base/error.cpp | 2 +- sdk/base/error.hpp | 2 +- sdk/io/basic/payload.cpp | 183 ++++++++--- sdk/io/basic/payload.hpp | 21 +- sdk/io/cbor/cbor_pair.cpp | 20 +- sdk/io/cbor/cbor_visitor.cpp | 4 +- sdk/net.hpp | 7 + sdk/net/http/http2_frame.cpp | 555 ++++++++++++++++---------------- sdk/net/http/http2_frame.hpp | 30 +- sdk/net/http/http2_protocol.cpp | 1 + sdk/net/http/http_resource.cpp | 5 +- sdk/net/http/http_resource.hpp | 4 +- sdk/net/tls/tls.cpp | 2 +- sdk/net/tls/tls_client.cpp | 2 +- sdk/net/tls/tls_server.cpp | 2 +- sdk/odbc/basic/odbc_sinker.cpp | 2 +- test/httpauth/sample.cpp | 2 +- test/httpserver/sample.cpp | 2 +- test/httpserver2/sample.cpp | 2 +- test/io/sample.cpp | 26 +- 22 files changed, 498 insertions(+), 380 deletions(-) diff --git a/sdk/base/basic/cmdline.hpp b/sdk/base/basic/cmdline.hpp index eb1f541c..830e368c 100644 --- a/sdk/base/basic/cmdline.hpp +++ b/sdk/base/basic/cmdline.hpp @@ -248,7 +248,7 @@ return_t cmdline_t::parse(int argc, char** argv) { } if (_mandatory.size()) { - ret = errorcode_t::insufficiency; + ret = errorcode_t::insufficient; } return ret; diff --git a/sdk/base/basic/variant.cpp b/sdk/base/basic/variant.cpp index 600bde20..19729ac8 100644 --- a/sdk/base/basic/variant.cpp +++ b/sdk/base/basic/variant.cpp @@ -12,6 +12,7 @@ #include #include +#include #include namespace hotplace { @@ -339,6 +340,7 @@ return_t variant::to_binary(binary_t& target) const { } return ret; } + return_t variant::to_string(std::string& target) const { return_t ret = errorcode_t::success; diff --git a/sdk/base/error.cpp b/sdk/base/error.cpp index 6f7fc561..9947559d 100644 --- a/sdk/base/error.cpp +++ b/sdk/base/error.cpp @@ -58,7 +58,7 @@ const error_description error_descriptions[] = { errordef(busy, "busy"), errordef(query, "query"), errordef(fetch, "fetch"), - errordef(insufficiency, "insufficiency"), + errordef(insufficient, "insufficient"), errordef(reserved, "reserved"), errordef(suspicious, "suspicious"), errordef(unknown, "unknown"), diff --git a/sdk/base/error.hpp b/sdk/base/error.hpp index 0e809676..3367f4ba 100644 --- a/sdk/base/error.hpp +++ b/sdk/base/error.hpp @@ -235,7 +235,7 @@ enum errorcode_t { /* 0xef010025 4009820197 */ busy, /* 0xef010026 4009820198 */ query, /* 0xef010027 4009820199 */ fetch, - /* 0xef010028 4009820200 */ insufficiency, + /* 0xef010028 4009820200 */ insufficient, /* 0xef010029 4009820201 */ reserved, /* 0xef01002a 4009820202 */ suspicious, /* 0xef01002b 4009820203 */ unknown, diff --git a/sdk/io/basic/payload.cpp b/sdk/io/basic/payload.cpp index 6ebef5ea..3236c23d 100644 --- a/sdk/io/basic/payload.cpp +++ b/sdk/io/basic/payload.cpp @@ -18,6 +18,17 @@ payload_member::payload_member(uint8 value, const char* name, const char* group) get_variant().set_uint8(value); } +payload_member::payload_member(uint8 value, uint16 repeat, const char* name, const char* group) + : _change_endian(false), _member_value_of(nullptr), _reserve(repeat) { + set_name(name).set_group(group); + binary_t bin; + uint16 temp = repeat; + while (temp--) { + bin.insert(bin.end(), value); + } + get_variant().set_binary_new(bin); +} + payload_member::payload_member(uint16 value, bool change_endian, const char* name, const char* group) : _change_endian(change_endian), _member_value_of(nullptr), _reserve(0) { set_name(name).set_group(group); @@ -82,12 +93,25 @@ variant& payload_member::get_variant() { return _vt; } size_t payload_member::get_space() { size_t space = 0; payload_member* ref = get_value_of(); - if (variant_flag_t::flag_int == get_variant().flag()) { + if (_reserve) { + space = _reserve; + } else if (variant_flag_t::flag_int == get_variant().flag()) { space = get_variant().size(); } else if (ref) { space = t_variant_to_int(ref->get_variant().content()); - } else if (_reserve) { + } + return space; +} + +size_t payload_member::get_capacity() { + size_t space = 0; + payload_member* ref = get_value_of(); + if (_reserve) { space = _reserve; + } else if (ref) { + space = t_variant_to_int(ref->get_variant().content()); + } else { + space = get_variant().size(); } return space; } @@ -168,10 +192,10 @@ payload_member& payload_member::read(byte_t* ptr, size_t size_ptr, size_t* size_ } else { size_t size = 0; payload_member* ref = get_value_of(); - if (ref) { - size = t_variant_to_int(ref->get_variant().content()); - } else if (_reserve) { + if (_reserve) { size = _reserve; + } else if (ref) { + size = t_variant_to_int(ref->get_variant().content()); } if (size_ptr >= size) { @@ -246,72 +270,105 @@ payload& payload::set_reference_value(std::string const& name, std::string const return *this; } -payload& payload::dump(binary_t& bin) { +return_t payload::dump(binary_t& bin) { + return_t ret = errorcode_t::success; for (auto item : _members) { bool condition = get_group_condition(item->get_group()); if (condition) { item->dump(bin); } } - return *this; + return ret; } -payload& payload::read(binary_t const& bin) { return read((byte_t*)&bin[0], bin.size()); } +return_t payload::read(binary_t const& bin) { return read((byte_t*)&bin[0], bin.size()); } -payload& payload::read(byte_t* base, size_t size) { - size_t size_sum = 0; - std::list _size_unknown; +return_t payload::read(byte_t* base, size_t size) { + return_t ret = errorcode_t::success; - { - byte_t* p = base; - size_t len = size; - size_t pos = 0; - size_t size_read = 0; - bool check = true; - for (auto item : _members) { - uint16 space = item->get_space(); - size_sum += space; - if (0 == space) { - if (nullptr == item->get_value_of()) { - _size_unknown.push_back(item); + __try2 { + if (nullptr == base) { + ret = errorcode_t::invalid_parameter; + __leave2; + } + + size_t size_sum = 0; + std::list _size_unknown; + + { + byte_t* p = base; + size_t len = size; + size_t pos = 0; + size_t size_read = 0; + bool check = true; + for (auto item : _members) { + bool condition = get_group_condition(item->get_group()); + if (false == condition) { + continue; } - check = false; - } else { - if (check) { - item->read(p + pos, len, &size_read); - p += size_read; - len -= size_read; + + uint16 space = item->get_space(); + size_sum += space; + if (0 == space) { + if (nullptr == item->get_value_of()) { + _size_unknown.push_back(item); + } + check = false; + } else { + if (check) { + item->read(p + pos, len, &size_read); + p += size_read; + len -= size_read; + } } } } - } - if (size > size_sum) { - if (1 == _size_unknown.size()) { - size_t remain = size - size_sum; - payload_member* item = *(_size_unknown.begin()); - item->reserve(remain); - _size_unknown.clear(); + if (_size_unknown.size() > 1) { + ret = errorcode_t::unknown; + __leave2; } - } - if (_size_unknown.empty()) { - byte_t* p = base; - size_t len = size; - size_t pos = 0; - size_t size_read = 0; - bool check = true; - for (auto item : _members) { - uint16 space = item->get_space(); - size_sum += space; + if (size > size_sum) { + if (1 == _size_unknown.size()) { + size_t remain = size - size_sum; + payload_member* item = *(_size_unknown.begin()); + item->reserve(remain); + _size_unknown.clear(); + } + } + + if (_size_unknown.empty()) { + byte_t* p = base; + size_t len = size; + size_t pos = 0; + size_t size_read = 0; + bool check = true; + for (auto item : _members) { + bool condition = get_group_condition(item->get_group()); + if (false == condition) { + continue; + } + + uint16 space = item->get_space(); + size_sum += space; + + if (len < space) { + ret = errorcode_t::insufficient; + break; + } - item->read(p + pos, len, &size_read); - p += size_read; - len -= size_read; + item->read(p + pos, len, &size_read); + p += size_read; + len -= size_read; + } } } + __finally2 { + // do nothing + } - return *this; + return ret; } payload& payload::for_each(std::function func) { @@ -330,6 +387,32 @@ payload_member* payload::select(std::string const& name) { return item; } +size_t payload::size_estimated() { + size_t ret_value = 0; + for (auto item : _members) { + bool condition = get_group_condition(item->get_group()); + if (false == condition) { + continue; + } + + ret_value += item->get_space(); + } + return ret_value; +} + +size_t payload::size_occupied() { + size_t ret_value = 0; + for (auto item : _members) { + bool condition = get_group_condition(item->get_group()); + if (false == condition) { + continue; + } + + ret_value += item->get_capacity(); + } + return ret_value; +} + payload& payload::clear() { for (auto item : _members) { delete item; diff --git a/sdk/io/basic/payload.hpp b/sdk/io/basic/payload.hpp index 18c9e7b6..4867bf30 100644 --- a/sdk/io/basic/payload.hpp +++ b/sdk/io/basic/payload.hpp @@ -59,11 +59,13 @@ namespace io { * << new payload_member((uint32)0, true, "value") * << new payload_member(pad, "pad", "pad"); * binary_t decoded = base16_decode("036461746100001000706164"); - * pl.set_reference_value("pad", "padlen").read(decoded); // sizeof "pad" refers "padlen" value + * pl.set_reference_value("pad", "padlen"); + * pl.read(decoded); // sizeof "pad" refers "padlen" value */ class payload_member { public: payload_member(uint8 value, const char* name = nullptr, const char* group = nullptr); + payload_member(uint8 value, uint16 repeat, const char* name = nullptr, const char* group = nullptr); payload_member(uint16 value, bool change_endian, const char* name = nullptr, const char* group = nullptr); payload_member(uint32_24_t value, const char* name = nullptr, const char* group = nullptr); payload_member(uint32 value, bool change_endian, const char* name = nullptr, const char* group = nullptr); @@ -81,6 +83,7 @@ class payload_member { variant& get_variant(); size_t get_space(); + size_t get_capacity(); payload_member* get_value_of(); payload_member& set_value_of(payload_member* member); @@ -110,13 +113,23 @@ class payload { bool get_group_condition(std::string const& name); payload& set_reference_value(std::string const& name, std::string const& ref); - payload& dump(binary_t& bin); - payload& read(binary_t const& bin); - payload& read(byte_t* p, size_t size); + return_t dump(binary_t& bin); + return_t read(binary_t const& bin); + return_t read(byte_t* p, size_t size); payload& for_each(std::function func); payload_member* select(std::string const& name); + /** + * @brief size + * @return size estimated + * @remarks + * if (stream_size >= pl.size_estimated()) { + * pl.read(stream, stream_size); + * } + */ + size_t size_estimated(); + size_t size_occupied(); payload& clear(); private: diff --git a/sdk/io/cbor/cbor_pair.cpp b/sdk/io/cbor/cbor_pair.cpp index 1bf09f78..8630eaf7 100644 --- a/sdk/io/cbor/cbor_pair.cpp +++ b/sdk/io/cbor/cbor_pair.cpp @@ -36,7 +36,7 @@ cbor_pair::cbor_pair(int64 value, cbor_data* object) __try2 { if (nullptr == object) { - throw errorcode_t::insufficiency; + throw errorcode_t::insufficient; } __try_new_catch(_lhs, new cbor_data(value), ret, __leave2); } @@ -61,7 +61,7 @@ cbor_pair::cbor_pair(int64 value, cbor_map* object) __try2 { if (nullptr == object) { - throw errorcode_t::insufficiency; + throw errorcode_t::insufficient; } __try_new_catch(_lhs, new cbor_data(value), ret, __leave2); } @@ -86,7 +86,7 @@ cbor_pair::cbor_pair(int64 value, cbor_array* object) __try2 { if (nullptr == object) { - throw errorcode_t::insufficiency; + throw errorcode_t::insufficient; } __try_new_catch(_lhs, new cbor_data(value), ret, __leave2); } @@ -100,7 +100,7 @@ cbor_pair::cbor_pair(const char* key, cbor_data* object) : cbor_object(cbor_type __try2 { if (nullptr == object) { - throw errorcode_t::insufficiency; + throw errorcode_t::insufficient; } __try_new_catch(_lhs, new cbor_data(key), ret, __leave2); } @@ -114,7 +114,7 @@ cbor_pair::cbor_pair(const char* key, cbor_map* object) : cbor_object(cbor_type_ __try2 { if (nullptr == object) { - throw errorcode_t::insufficiency; + throw errorcode_t::insufficient; } __try_new_catch(_lhs, new cbor_data(key), ret, __leave2); } @@ -128,7 +128,7 @@ cbor_pair::cbor_pair(const char* key, cbor_array* object) : cbor_object(cbor_typ __try2 { if (nullptr == object) { - throw errorcode_t::insufficiency; + throw errorcode_t::insufficient; } __try_new_catch(_lhs, new cbor_data(key), ret, __leave2); } @@ -139,25 +139,25 @@ cbor_pair::cbor_pair(const char* key, cbor_array* object) : cbor_object(cbor_typ cbor_pair::cbor_pair(cbor_data* key, cbor_data* object) : cbor_object(cbor_type_t::cbor_type_pair), _lhs(key), _rhs(object) { if (nullptr == key || nullptr == object) { - throw errorcode_t::insufficiency; + throw errorcode_t::insufficient; } } cbor_pair::cbor_pair(cbor_data* key, cbor_map* object) : cbor_object(cbor_type_t::cbor_type_pair), _lhs(key), _rhs(object) { if (nullptr == key || nullptr == object) { - throw errorcode_t::insufficiency; + throw errorcode_t::insufficient; } } cbor_pair::cbor_pair(cbor_data* key, cbor_array* object) : cbor_object(cbor_type_t::cbor_type_pair), _lhs(key), _rhs(object) { if (nullptr == key || nullptr == object) { - throw errorcode_t::insufficiency; + throw errorcode_t::insufficient; } } cbor_pair::cbor_pair(cbor_data* key, cbor_object* object) : cbor_object(cbor_type_t::cbor_type_pair), _lhs(key), _rhs(object) { if (nullptr == key || nullptr == object) { - throw errorcode_t::insufficiency; + throw errorcode_t::insufficient; } } diff --git a/sdk/io/cbor/cbor_visitor.cpp b/sdk/io/cbor/cbor_visitor.cpp index b6cfbff6..2e64e6a6 100644 --- a/sdk/io/cbor/cbor_visitor.cpp +++ b/sdk/io/cbor/cbor_visitor.cpp @@ -18,7 +18,7 @@ namespace io { cbor_concise_visitor::cbor_concise_visitor(binary_t* concise) : _concise(concise) { if (nullptr == concise) { - throw errorcode_t::insufficiency; + throw errorcode_t::insufficient; } } @@ -37,7 +37,7 @@ binary_t* cbor_concise_visitor::get_binary() { return _concise; } cbor_diagnostic_visitor::cbor_diagnostic_visitor(stream_t* stream) : _diagnostic(stream) { if (nullptr == stream) { - throw errorcode_t::insufficiency; + throw errorcode_t::insufficient; } } diff --git a/sdk/net.hpp b/sdk/net.hpp index 5c3fa986..a893e593 100644 --- a/sdk/net.hpp +++ b/sdk/net.hpp @@ -19,9 +19,14 @@ #include #include #include +#include #include +#include +#include #include +#include #include +#include #include #include #include @@ -35,6 +40,8 @@ #include #include #include +#include +#include #include #include #include diff --git a/sdk/net/http/http2_frame.cpp b/sdk/net/http/http2_frame.cpp index 43fac3b8..b4ce3379 100644 --- a/sdk/net/http/http2_frame.cpp +++ b/sdk/net/http/http2_frame.cpp @@ -14,6 +14,8 @@ #include #include #include +#include +#include #include namespace hotplace { @@ -24,6 +26,23 @@ constexpr char constexpr_frame_length[] = "length"; constexpr char constexpr_frame_type[] = "type"; constexpr char constexpr_frame_flags[] = "flags"; constexpr char constexpr_frame_stream_identifier[] = "stream identifier"; +constexpr char constexpr_frame_pad_length[] = "pad length"; +constexpr char constexpr_frame_data[] = "data"; +constexpr char constexpr_frame_padding[] = "padding"; +constexpr char constexpr_frame_stream_dependency[] = "stream dependency"; +constexpr char constexpr_frame_weight[] = "weight"; +constexpr char constexpr_frame_fragment[] = "fragment"; +constexpr char constexpr_frame_priority[] = "priority"; +constexpr char constexpr_frame_error_code[] = "error code"; +constexpr char constexpr_frame_promised_stream_id[] = "promised stream id"; +constexpr char constexpr_frame_opaque[] = "opaque"; +constexpr char constexpr_frame_last_stream_id[] = "last stream id"; +constexpr char constexpr_frame_debug_data[] = "debug data"; +constexpr char constexpr_frame_window_size_increment[] = "window size increment"; + +constexpr char constexpr_frame_exclusive[] = "exclusive"; +constexpr char constexpr_frame_identifier[] = "identifier"; +constexpr char constexpr_frame_value[] = "value"; http2_frame_header::http2_frame_header() : _payload_size(0), _type(0), _flags(0), _stream_id(0) {} @@ -137,19 +156,22 @@ void http2_frame_header::dump(stream_t* s) { std::string frame_name = resource->get_frame_name(get_type()); s->printf("- http/2 frame type %d %s\n", get_type(), frame_name.c_str()); - s->printf("> len %u type %u flags 0x%02x stream identifier %u\n", get_payload_size(), get_type(), get_flags(), get_stream_id()); - s->printf("> flags [ "); + s->printf("> "); + s->printf("%s %u", constexpr_frame_length, get_payload_size()); + s->printf("%s %u", constexpr_frame_type, get_type()); + s->printf("%s %02x", constexpr_frame_flags, get_flags()); + s->printf("%s %u", constexpr_frame_stream_identifier, get_stream_id()); + s->printf("\n"); + s->printf("> %s [ ", constexpr_frame_flags); - resource->for_each_flags(get_flags(), s, - [](uint8 flag, stream_t* s) -> void { s->printf("%s ", http_resource::get_instance()->get_frame_flag(flag).c_str()); }); + resource->for_each_frame_flags(get_flags(), s, + [](uint8 flag, stream_t* s) -> void { s->printf("%s ", http_resource::get_instance()->get_frame_flag(flag).c_str()); }); s->printf("]\n"); - // dump_memory(bin, s, 16, 2, 0x0, dump_memory_flag_t::dump_notrunc); - // s->printf("\n"); } } -http2_data_frame::http2_data_frame() : http2_frame_header(h2_frame_t::h2_frame_data) {} +http2_data_frame::http2_data_frame() : http2_frame_header(h2_frame_t::h2_frame_data), _padlen(0) {} return_t http2_data_frame::read(http2_frame_header_t const* header, size_t size) { return_t ret = errorcode_t::success; @@ -166,26 +188,25 @@ return_t http2_data_frame::read(http2_frame_header_t const* header, size_t size) __leave2; } - byte_t* payload = nullptr; - ret = get_payload(header, size, &payload); + byte_t* ptr_payload = nullptr; + ret = get_payload(header, size, &ptr_payload); if (errorcode_t::success != ret) { __leave2; } // Pad Length? // conditional (as signified by a "?" in the diagram) and is only present if the PADDED flag is set - if (get_flags() & h2_flag_t::h2_flag_padded) { - // padlen(1) + data(len-1-padlen) + pad(padlen) - uint8 padlen = payload[0]; - uint32 datalen = get_payload_size() - (1 + padlen); - byte_t* data = payload + 1; - byte_t* pad = payload + (1 + datalen); + payload pl; + pl << new payload_member((uint8)0, constexpr_frame_pad_length, constexpr_frame_padding) << new payload_member(binary_t(), constexpr_frame_data) + << new payload_member(binary_t(), constexpr_frame_padding, constexpr_frame_padding); - set_binary(_data, data, datalen); - set_binary(_pad, pad, padlen); - } else { - set_binary(_data, payload, get_payload_size()); - } + pl.set_group(constexpr_frame_padding, (get_flags() & h2_flag_t::h2_flag_padded) ? true : false) + .set_reference_value(constexpr_frame_padding, constexpr_frame_pad_length); + + pl.read(ptr_payload, get_payload_size()); + + _padlen = t_variant_to_int(pl.select(constexpr_frame_pad_length)->get_variant().content()); + pl.select(constexpr_frame_length)->get_variant().dump(_data, true); } __finally2 { // do nothing @@ -196,45 +217,38 @@ return_t http2_data_frame::read(http2_frame_header_t const* header, size_t size) return_t http2_data_frame::write(binary_t& frame) { return_t ret = errorcode_t::success; + payload pl; + pl << new payload_member(_padlen, constexpr_frame_pad_length, constexpr_frame_padding) << new payload_member(_data, constexpr_frame_data) + << new payload_member((uint8)0, _padlen, constexpr_frame_padding, constexpr_frame_padding); + + pl.set_group(constexpr_frame_padding, _padlen ? true : false); + + binary_t bin_payload; + pl.dump(bin_payload); + uint8 flags = 0; - uint8 padsize = 0; - if (_pad.size()) { + if (_padlen) { flags |= h2_flag_t::h2_flag_padded; - padsize = 1; } - + set_payload_size(bin_payload.size()); set_flags(flags); - ret = set_payload_size(padsize + _data.size() + _pad.size()); - if (errorcode_t::success == ret) { - http2_frame_header::write(frame); + http2_frame_header::write(frame); + frame.insert(frame.end(), bin_payload.begin(), bin_payload.end()); - if (flags & h2_flag_t::h2_flag_padded) { - frame.insert(frame.end(), (uint8)_pad.size()); - } - frame.insert(frame.end(), _data.begin(), _data.end()); - if (flags & h2_flag_t::h2_flag_padded) { - frame.insert(frame.end(), _pad.begin(), _pad.end()); - } - } return ret; } void http2_data_frame::dump(stream_t* s) { if (s) { http2_frame_header::dump(s); - s->printf("> data\n"); + s->printf("> %s\n", constexpr_frame_data); dump_memory(_data, s, 16, 2, 0x0, dump_memory_flag_t::dump_notrunc); s->printf("\n"); - if (_pad.size()) { - s->printf("> pad\n"); - dump_memory(_pad, s, 16, 2, 0x0, dump_memory_flag_t::dump_notrunc); - s->printf("\n"); - } } } -http2_headers_frame::http2_headers_frame() : http2_frame_header(h2_frame_t::h2_frame_headers), _use_priority(false), _dependency(0), _weight(0) {} +http2_headers_frame::http2_headers_frame() : http2_frame_header(h2_frame_t::h2_frame_headers), _padlen(0), _exclusive(false), _dependency(0), _weight(0) {} return_t http2_headers_frame::read(http2_frame_header_t const* header, size_t size) { return_t ret = errorcode_t::success; @@ -250,114 +264,88 @@ return_t http2_headers_frame::read(http2_frame_header_t const* header, size_t si __leave2; } - byte_t* payload = nullptr; - ret = get_payload(header, size, &payload); + byte_t* ptr_payload = nullptr; + ret = get_payload(header, size, &ptr_payload); if (errorcode_t::success != ret) { __leave2; } - uint32 pos = 0; - uint8 padlen = 0; - http2_priority_t* priority = nullptr; + payload pl; + pl << new payload_member((uint8)0, constexpr_frame_pad_length, constexpr_frame_padding) + << new payload_member((uint32)0, true, constexpr_frame_stream_dependency, constexpr_frame_priority) + << new payload_member((uint8)0, constexpr_frame_weight, constexpr_frame_priority) << new payload_member(binary_t(), constexpr_frame_fragment) + << new payload_member(binary_t(), constexpr_frame_padding, constexpr_frame_padding); + + pl.set_group(constexpr_frame_padding, (get_flags() & h2_flag_t::h2_flag_padded) ? true : false) + .set_group(constexpr_frame_priority, (get_flags() & h2_flag_t::h2_flag_priority) ? true : false) + .set_reference_value(constexpr_frame_padding, constexpr_frame_pad_length); + + pl.read(ptr_payload, get_payload_size()); + if (get_flags() & h2_flag_t::h2_flag_padded) { - pos++; - padlen = payload[0]; + _padlen = t_variant_to_int(pl.select(constexpr_frame_pad_length)->get_variant().content()); } - uint32 prilen = 0; if (get_flags() & h2_flag_t::h2_flag_priority) { - priority = (http2_priority_t*)(payload + pos); - prilen = sizeof(http2_priority_t); - - _use_priority = true; - _dependency = ntohl(priority->dependency); - _weight = priority->weight; - } else { - _use_priority = false; + uint32 temp = t_variant_to_int(pl.select(constexpr_frame_stream_dependency)->get_variant().content()); + _exclusive = (temp & 0x80000000) ? true : false; + _dependency = (temp & 0x7fffffff); + _weight = t_variant_to_int(pl.select(constexpr_frame_weight)->get_variant().content()); } - - byte_t* fragment = payload + pos + prilen; - uint32 fraglen = get_payload_size() - (pos + prilen + padlen); - - byte_t* pad = payload + pos + prilen + fraglen; - - set_binary(_fragment, fragment, fraglen); - set_binary(_pad, pad, padlen); + pl.select(constexpr_frame_fragment)->get_variant().dump(_fragment, true); } __finally2 { // do nothing } return ret; } + return_t http2_headers_frame::write(binary_t& frame) { return_t ret = errorcode_t::success; + + uint32 dependency = _dependency; + if (_exclusive) { + dependency |= 0x80000000; + } + + payload pl; + pl << new payload_member(_padlen, constexpr_frame_pad_length, constexpr_frame_padding) + << new payload_member(dependency, true, constexpr_frame_stream_dependency, constexpr_frame_priority) + << new payload_member(_weight, constexpr_frame_weight, constexpr_frame_priority) << new payload_member(_fragment, constexpr_frame_fragment) + << new payload_member(uint8(0), _padlen, constexpr_frame_padding, constexpr_frame_padding); + + pl.set_group(constexpr_frame_padding, (get_flags() & h2_flag_t::h2_flag_padded) ? true : false) + .set_group(constexpr_frame_priority, (get_flags() & h2_flag_t::h2_flag_priority) ? true : false); + + binary_t bin_payload; + pl.dump(bin_payload); + uint8 flags = 0; - uint32 padsize = 0; - uint32 depsize = 0; - if (_pad.size()) { + if (_padlen) { flags |= h2_flag_t::h2_flag_padded; - padsize = 1; } - if (_use_priority) { + if (dependency) { flags |= h2_flag_t::h2_flag_priority; - depsize = sizeof(http2_priority_t); } - + set_payload_size(bin_payload.size()); set_flags(flags); - ret = set_payload_size(padsize + depsize + _fragment.size() + _pad.size()); - if (errorcode_t::success == ret) { - http2_frame_header::write(frame); + http2_frame_header::write(frame); + frame.insert(frame.end(), bin_payload.begin(), bin_payload.end()); - if (flags & h2_flag_t::h2_flag_padded) { - frame.insert(frame.end(), (uint8)_pad.size()); // Pad Length? - } - if (flags & h2_flag_t::h2_flag_priority) { - binsert(frame, _dependency, htonl); // Stream Dependency? - frame.insert(frame.end(), _weight); // Weight? - } - frame.insert(frame.end(), _fragment.begin(), _fragment.end()); - if (flags & h2_flag_t::h2_flag_padded) { - frame.insert(frame.end(), _pad.begin(), _pad.end()); - } - } return ret; } void http2_headers_frame::dump(stream_t* s) { if (s) { - basic_stream bs; - uint8 flags = 0; - uint32 padsize = 0; - uint32 depsize = 0; - if (_pad.size()) { - flags |= h2_flag_t::h2_flag_padded; - padsize = 1; - } - if (_use_priority) { - flags |= h2_flag_t::h2_flag_priority; - depsize = sizeof(http2_priority_t); - } - http2_frame_header::dump(s); - s->printf("> fragment\n"); + s->printf("> %s\n", constexpr_frame_fragment); dump_memory(_fragment, s, 16, 2, 0x0, dump_memory_flag_t::dump_notrunc); s->printf("\n"); - if (_pad.size()) { - s->printf("> pad\n"); - dump_memory(_pad, s, 16, 2, 0x0, dump_memory_flag_t::dump_notrunc); - s->printf("\n"); - } } } http2_priority_frame::http2_priority_frame() : http2_frame_header(h2_frame_t::h2_frame_priority), _exclusive(false), _dependency(0), _weight(0) {} -uint8 http2_priority_frame::get_exclusive() { return _exclusive ? 1 : 0; } - -uint32 http2_priority_frame::get_dependency() { return _dependency; } - -uint8 http2_priority_frame::get_weight() { return _weight; } - return_t http2_priority_frame::read(http2_frame_header_t const* header, size_t size) { return_t ret = errorcode_t::success; @@ -373,26 +361,23 @@ return_t http2_priority_frame::read(http2_frame_header_t const* header, size_t s __leave2; } - byte_t* payload = nullptr; - ret = get_payload(header, size, &payload); + byte_t* ptr_payload = nullptr; + ret = get_payload(header, size, &ptr_payload); if (errorcode_t::success != ret) { __leave2; } - // A PRIORITY frame with a length other than 5 octets MUST be treated as a stream error (Section 5.4.2) of type FRAME_SIZE_ERROR. - if (get_payload_size() != sizeof(http2_priority_t)) { - ret = errorcode_t::bad_data; - __leave2; - } + payload pl; + pl << new payload_member((uint32)0, true, constexpr_frame_stream_dependency) << new payload_member((uint8)0, constexpr_frame_weight); + + pl.set_reference_value(constexpr_frame_padding, constexpr_frame_pad_length); - http2_priority_t priority; - http2_priority_t* temp = (http2_priority_t*)payload; - priority.dependency = ntohl(temp->dependency); - priority.weight = temp->weight; + pl.read(ptr_payload, get_payload_size()); - _exclusive = (priority.dependency & 0x80000000) ? true : false; - _dependency = (priority.dependency & 0x7fffffff); - _weight = priority.weight; + uint32 temp = t_variant_to_int(pl.select(constexpr_frame_stream_dependency)->get_variant().content()); + _exclusive = (temp & 0x80000000) ? true : false; + _dependency = (temp & 0x7fffffff); + _weight = t_variant_to_int(pl.select(constexpr_frame_weight)->get_variant().content()); } __finally2 { // do nothing @@ -403,21 +388,23 @@ return_t http2_priority_frame::read(http2_frame_header_t const* header, size_t s return_t http2_priority_frame::write(binary_t& frame) { return_t ret = errorcode_t::success; - ret = set_payload_size(sizeof(http2_priority_t)); + uint32 dependency = _dependency; + if (_exclusive) { + dependency |= 0x80000000; + } - if (errorcode_t::success == ret) { - http2_frame_header::write(frame); + payload pl; + pl << new payload_member(dependency, true, constexpr_frame_stream_dependency) << new payload_member(_weight, constexpr_frame_weight); - http2_priority_t priority; - priority.dependency = _dependency; - if (_exclusive) { - priority.dependency |= 0x80000000; - } - priority.weight = _weight; + binary_t bin_payload; + pl.dump(bin_payload); - binsert(frame, priority.dependency, htonl); - frame.insert(frame.end(), priority.weight); - } + uint8 flags = 0; + set_payload_size(bin_payload.size()); + set_flags(flags); + + http2_frame_header::write(frame); + frame.insert(frame.end(), bin_payload.begin(), bin_payload.end()); return ret; } @@ -426,19 +413,14 @@ void http2_priority_frame::dump(stream_t* s) { if (s) { http2_frame_header::dump(s); - s->printf("> exclusive %u dependency %u weight %u\n", get_exclusive(), get_dependency(), get_weight()); + s->printf("> %s %u\n", constexpr_frame_exclusive, _exclusive ? 1 : 0); + s->printf("> %s %u\n", constexpr_frame_stream_dependency, _dependency); + s->printf("> %s %u\n", constexpr_frame_weight, _weight); } } http2_rst_stream_frame::http2_rst_stream_frame() : http2_frame_header(h2_frame_t::h2_frame_rst_stream), _errorcode(0) {} -uint32 http2_rst_stream_frame::get_errorcode() { return _errorcode; } - -http2_rst_stream_frame& http2_rst_stream_frame::set_errorcode(uint32 errorcode) { - _errorcode = errorcode; - return *this; -} - return_t http2_rst_stream_frame::read(http2_frame_header_t const* header, size_t size) { return_t ret = errorcode_t::success; @@ -454,20 +436,18 @@ return_t http2_rst_stream_frame::read(http2_frame_header_t const* header, size_t __leave2; } - byte_t* payload = nullptr; - ret = get_payload(header, size, &payload); + byte_t* ptr_payload = nullptr; + ret = get_payload(header, size, &ptr_payload); if (errorcode_t::success != ret) { __leave2; } - // The RST_STREAM frame contains a single unsigned, 32-bit integer identifying the error code - if (get_payload_size() != sizeof(uint32)) { - ret = errorcode_t::bad_data; - __leave2; - } + payload pl; + pl << new payload_member((uint32)0, true, constexpr_frame_error_code); + + pl.read(ptr_payload, get_payload_size()); - uint32 temp = *(uint32*)payload; - _errorcode = ntohl(temp); + _errorcode = t_variant_to_int(pl.select(constexpr_frame_error_code)->get_variant().content()); } __finally2 { // do nothing @@ -478,12 +458,18 @@ return_t http2_rst_stream_frame::read(http2_frame_header_t const* header, size_t return_t http2_rst_stream_frame::write(binary_t& frame) { return_t ret = errorcode_t::success; - ret = set_payload_size(sizeof(uint32)); - if (errorcode_t::success == ret) { - http2_frame_header::write(frame); + payload pl; + pl << new payload_member(_errorcode, true, constexpr_frame_error_code); - binsert(frame, _errorcode, htonl); - } + binary_t bin_payload; + pl.dump(bin_payload); + + uint8 flags = 0; + set_payload_size(bin_payload.size()); + set_flags(flags); + + http2_frame_header::write(frame); + frame.insert(frame.end(), bin_payload.begin(), bin_payload.end()); return ret; } @@ -492,7 +478,7 @@ void http2_rst_stream_frame::dump(stream_t* s) { if (s) { http2_frame_header::dump(s); - s->printf("> errorcode %u\n", get_errorcode()); + s->printf("> %s %u\n", constexpr_frame_error_code, _errorcode); } } @@ -560,8 +546,8 @@ return_t http2_settings_frame::write(binary_t& frame) { // RFC 7540 Figure 10: Setting Format h2_setting_map_t::iterator iter; for (iter = _settings.begin(); iter != _settings.end(); iter++) { - binsert(frame, iter->first, htons); - binsert(frame, iter->second, htonl); + binsert(frame, iter->first, hton16); + binsert(frame, iter->second, hton32); } } @@ -574,12 +560,13 @@ void http2_settings_frame::dump(stream_t* s) { h2_setting_map_t::iterator iter; for (iter = _settings.begin(); iter != _settings.end(); iter++) { - s->printf("> id %u value %u (0x%08x)\n", iter->first, iter->second, iter->second); + s->printf("> %s %u\n", constexpr_frame_identifier, iter->first); + s->printf("> %s %u (0x%08x)\n", constexpr_frame_value, iter->second, iter->second); } } } -http2_push_promise_frame::http2_push_promise_frame() : http2_frame_header(h2_frame_t::h2_frame_push_promise), _promised_id(0) {} +http2_push_promise_frame::http2_push_promise_frame() : http2_frame_header(h2_frame_t::h2_frame_push_promise), _padlen(0), _promised_id(0) {} return_t http2_push_promise_frame::read(http2_frame_header_t const* header, size_t size) { return_t ret = errorcode_t::success; @@ -595,27 +582,28 @@ return_t http2_push_promise_frame::read(http2_frame_header_t const* header, size __leave2; } - byte_t* payload = nullptr; - ret = get_payload(header, size, &payload); + byte_t* ptr_payload = nullptr; + ret = get_payload(header, size, &ptr_payload); if (errorcode_t::success != ret) { __leave2; } - uint32 pos = 0; - uint8 padlen = 0; - http2_priority_t* priority = nullptr; + payload pl; + pl << new payload_member((uint8)0, constexpr_frame_pad_length, constexpr_frame_padding) + << new payload_member((uint32)0, true, constexpr_frame_promised_stream_id) << new payload_member(binary_t(), constexpr_frame_fragment) + << new payload_member(binary_t(), constexpr_frame_padding, constexpr_frame_padding); + + pl.set_group(constexpr_frame_padding, (get_flags() & h2_flag_t::h2_flag_padded) ? true : false) + .set_reference_value(constexpr_frame_padding, constexpr_frame_pad_length); + + pl.read(ptr_payload, get_payload_size()); + if (get_flags() & h2_flag_t::h2_flag_padded) { - pos++; - padlen = payload[0]; + _padlen = t_variant_to_int(pl.select(constexpr_frame_pad_length)->get_variant().content()); } - uint32 temp = *(uint32*)(payload + pos); - byte_t* frag = payload + pos + sizeof(uint32); - uint32 fraglen = get_payload_size() - (pos + sizeof(uint32) + padlen); - byte_t* pad = payload + pos + sizeof(uint32) + fraglen; - _promised_id = ntohl(temp); - set_binary(_fragment, frag, fraglen); - set_binary(_pad, pad, padlen); + _promised_id = t_variant_to_int(pl.select(constexpr_frame_promised_stream_id)->get_variant().content()); + pl.select(constexpr_frame_fragment)->get_variant().dump(_fragment, true); } __finally2 { // do nothing @@ -625,27 +613,42 @@ return_t http2_push_promise_frame::read(http2_frame_header_t const* header, size return_t http2_push_promise_frame::write(binary_t& frame) { return_t ret = errorcode_t::success; - // TODO + + payload pl; + pl << new payload_member(_padlen, constexpr_frame_pad_length, constexpr_frame_padding) + << new payload_member(_promised_id, true, constexpr_frame_promised_stream_id) << new payload_member(_fragment, constexpr_frame_fragment) + << new payload_member(uint8(0), _padlen, constexpr_frame_padding, constexpr_frame_padding); + + pl.set_group(constexpr_frame_padding, (get_flags() & h2_flag_t::h2_flag_padded) ? true : false); + + binary_t bin_payload; + pl.dump(bin_payload); + + uint8 flags = 0; + if (_padlen) { + flags |= h2_flag_t::h2_flag_padded; + } + set_payload_size(bin_payload.size()); + set_flags(flags); + + http2_frame_header::write(frame); + frame.insert(frame.end(), bin_payload.begin(), bin_payload.end()); + return ret; } void http2_push_promise_frame::dump(stream_t* s) { if (s) { http2_frame_header::dump(s); - - // TODO + s->printf("> %s %u\n", constexpr_frame_promised_stream_id, _promised_id); + s->printf("> %s\n", constexpr_frame_fragment); + dump_memory(_fragment, s, 16, 2, 0x0, dump_memory_flag_t::dump_notrunc); + s->printf("\n"); } } http2_ping_frame::http2_ping_frame() : http2_frame_header(h2_frame_t::h2_frame_ping), _opaque(0) {} -uint64 http2_ping_frame::get_opaque() { return _opaque; } - -http2_ping_frame& http2_ping_frame::set_opaque(uint64 opaque) { - _opaque = opaque; - return *this; -} - return_t http2_ping_frame::read(http2_frame_header_t const* header, size_t size) { return_t ret = errorcode_t::success; __try2 { @@ -660,20 +663,19 @@ return_t http2_ping_frame::read(http2_frame_header_t const* header, size_t size) __leave2; } - byte_t* payload = nullptr; - ret = get_payload(header, size, &payload); + // PING frames MUST contain 8 octets of opaque data in the payload. + byte_t* ptr_payload = nullptr; + ret = get_payload(header, size, &ptr_payload); if (errorcode_t::success != ret) { __leave2; } - // PING frames MUST contain 8 octets of opaque data in the payload. - if (get_payload_size() != sizeof(uint64)) { - ret = errorcode_t::bad_data; - __leave2; - } + payload pl; + pl << new payload_member((uint32)0, true, constexpr_frame_opaque); + + pl.read(ptr_payload, get_payload_size()); - uint64 temp = *(uint64*)payload; - _opaque = ntoh64(temp); + _opaque = t_variant_to_int(pl.select(constexpr_frame_opaque)->get_variant().content()); } __finally2 { // do nothing @@ -684,13 +686,18 @@ return_t http2_ping_frame::read(http2_frame_header_t const* header, size_t size) return_t http2_ping_frame::write(binary_t& frame) { return_t ret = errorcode_t::success; - ret = set_payload_size(sizeof(uint64)); + payload pl; + pl << new payload_member(_opaque, true, constexpr_frame_opaque); - if (errorcode_t::success == ret) { - http2_frame_header::write(frame); + binary_t bin_payload; + pl.dump(bin_payload); - binsert(frame, _opaque, hton64); - } + uint8 flags = 0; + set_payload_size(bin_payload.size()); + set_flags(flags); + + http2_frame_header::write(frame); + frame.insert(frame.end(), bin_payload.begin(), bin_payload.end()); return ret; } @@ -699,34 +706,12 @@ void http2_ping_frame::dump(stream_t* s) { if (s) { http2_frame_header::dump(s); - s->printf("> opaque %I64u\n", get_opaque()); + s->printf("> %s %I64u\n", constexpr_frame_opaque, _opaque); } } http2_goaway_frame::http2_goaway_frame() : http2_frame_header(h2_frame_t::h2_frame_goaway), _last_id(0), _errorcode(0) {} -uint32 http2_goaway_frame::get_last_id() { return _last_id; } - -uint32 http2_goaway_frame::get_errorcode() { return _errorcode; } - -http2_goaway_frame& http2_goaway_frame::set_last_id(uint32 last_id) { - _last_id = last_id; - return *this; -} - -http2_goaway_frame& http2_goaway_frame::set_errorcode(uint32 errorcode) { - _errorcode = errorcode; - return *this; -} - -http2_goaway_frame& http2_goaway_frame::set_debug(byte_t* debug, size_t size) { - if (debug) { - _debug.clear(); - _debug.insert(_debug.end(), debug, debug + size); - } - return *this; -} - return_t http2_goaway_frame::read(http2_frame_header_t const* header, size_t size) { return_t ret = errorcode_t::success; __try2 { @@ -741,22 +726,21 @@ return_t http2_goaway_frame::read(http2_frame_header_t const* header, size_t siz __leave2; } - byte_t* payload = nullptr; - ret = get_payload(header, size, &payload); + byte_t* ptr_payload = nullptr; + ret = get_payload(header, size, &ptr_payload); if (errorcode_t::success != ret) { __leave2; } - if (get_payload_size() < sizeof(uint64)) { - ret = errorcode_t::bad_data; - __leave2; - } + payload pl; + pl << new payload_member((uint32)0, true, constexpr_frame_last_stream_id) << new payload_member((uint32)0, true, constexpr_frame_error_code) + << new payload_member(binary_t(), constexpr_frame_debug_data); + + pl.read(ptr_payload, get_payload_size()); - http2_goaway_t* goaway = (http2_goaway_t*)payload; - _last_id = ntohl(goaway->last_id); - _errorcode = ntohl(goaway->errorcode); - uint32 debuglen = get_payload_size() - (sizeof(uint32) + sizeof(uint32)); - set_debug(goaway->debug, debuglen); + _last_id = t_variant_to_int(pl.select(constexpr_frame_last_stream_id)->get_variant().content()); + _errorcode = t_variant_to_int(pl.select(constexpr_frame_error_code)->get_variant().content()); + pl.select(constexpr_frame_fragment)->get_variant().dump(_debug, true); } __finally2 { // do nothing @@ -766,15 +750,20 @@ return_t http2_goaway_frame::read(http2_frame_header_t const* header, size_t siz return_t http2_goaway_frame::write(binary_t& frame) { return_t ret = errorcode_t::success; - set_payload_size(sizeof(uint32) + sizeof(uint32) + _debug.size()); - if (errorcode_t::success == ret) { - http2_frame_header::write(frame); + payload pl; + pl << new payload_member(_last_id, true, constexpr_frame_last_stream_id) << new payload_member(_errorcode, true, constexpr_frame_error_code) + << new payload_member(_debug, constexpr_frame_debug_data); - binsert(frame, _last_id, htonl); - binsert(frame, _errorcode, htonl); - frame.insert(frame.end(), _debug.begin(), _debug.end()); - } + binary_t bin_payload; + pl.dump(bin_payload); + + uint8 flags = 0; + set_payload_size(bin_payload.size()); + set_flags(flags); + + http2_frame_header::write(frame); + frame.insert(frame.end(), bin_payload.begin(), bin_payload.end()); return ret; } @@ -783,22 +772,16 @@ void http2_goaway_frame::dump(stream_t* s) { if (s) { http2_frame_header::dump(s); - s->printf("> last_id %u errorcode %u\n", get_last_id(), get_errorcode()); - basic_stream bs; - dump_memory(_debug, &bs, 16, 2); - s->printf("> debug\n%s\n", bs.c_str()); + s->printf("> %s %u\n", constexpr_frame_last_stream_id, _last_id); + s->printf("> %s %u\n", constexpr_frame_error_code, _errorcode); + s->printf("> %s\n", constexpr_frame_debug_data); + dump_memory(_debug, s, 16, 2, 0x0, dump_memory_flag_t::dump_notrunc); + s->printf("\n"); } } http2_window_update_frame::http2_window_update_frame() : http2_frame_header(h2_frame_t::h2_frame_window_update), _increment(0) {} -uint32 http2_window_update_frame::get_increment() { return _increment; } - -http2_window_update_frame& http2_window_update_frame::set_increment(uint32 increment) { - _increment; - return *this; -} - return_t http2_window_update_frame::read(http2_frame_header_t const* header, size_t size) { return_t ret = errorcode_t::success; @@ -814,19 +797,18 @@ return_t http2_window_update_frame::read(http2_frame_header_t const* header, siz __leave2; } - byte_t* payload = nullptr; - ret = get_payload(header, size, &payload); + byte_t* ptr_payload = nullptr; + ret = get_payload(header, size, &ptr_payload); if (errorcode_t::success != ret) { __leave2; } - if (get_payload_size() != sizeof(uint32)) { - ret = errorcode_t::bad_data; - __leave2; - } + payload pl; + pl << new payload_member((uint32)0, true, constexpr_frame_window_size_increment); + + pl.read(ptr_payload, get_payload_size()); - uint32 temp = *(uint32*)payload; - _increment = ntohl(temp); + _increment = t_variant_to_int(pl.select(constexpr_frame_window_size_increment)->get_variant().content()); } __finally2 { // do nothing @@ -837,11 +819,18 @@ return_t http2_window_update_frame::read(http2_frame_header_t const* header, siz return_t http2_window_update_frame::write(binary_t& frame) { return_t ret = errorcode_t::success; - set_payload_size(sizeof(uint32)); + payload pl; + pl << new payload_member(_increment, true, constexpr_frame_window_size_increment); + + binary_t bin_payload; + pl.dump(bin_payload); - http2_frame_header::write(frame); + uint8 flags = 0; + set_payload_size(bin_payload.size()); + set_flags(flags); - binsert(frame, _increment, htonl); + http2_frame_header::write(frame); + frame.insert(frame.end(), bin_payload.begin(), bin_payload.end()); return ret; } @@ -850,7 +839,7 @@ void http2_window_update_frame::dump(stream_t* s) { if (s) { http2_frame_header::dump(s); - s->printf("> increment %u\n", get_increment()); + s->printf("> %s %u\n", constexpr_frame_window_size_increment, _increment); } } @@ -870,13 +859,18 @@ return_t http2_continuation_frame::read(http2_frame_header_t const* header, size __leave2; } - byte_t* payload = nullptr; - ret = get_payload(header, size, &payload); + byte_t* ptr_payload = nullptr; + ret = get_payload(header, size, &ptr_payload); if (errorcode_t::success != ret) { __leave2; } - // TODO + payload pl; + pl << new payload_member(binary_t(), constexpr_frame_fragment); + + pl.read(ptr_payload, get_payload_size()); + + pl.select(constexpr_frame_fragment)->get_variant().dump(_fragment, true); } __finally2 { // do nothing @@ -886,7 +880,20 @@ return_t http2_continuation_frame::read(http2_frame_header_t const* header, size return_t http2_continuation_frame::write(binary_t& frame) { return_t ret = errorcode_t::success; - // TODO + + payload pl; + pl << new payload_member(_fragment, constexpr_frame_fragment); + + binary_t bin_payload; + pl.dump(bin_payload); + + uint8 flags = 0; + set_payload_size(bin_payload.size()); + set_flags(flags); + + http2_frame_header::write(frame); + frame.insert(frame.end(), bin_payload.begin(), bin_payload.end()); + return ret; } @@ -894,7 +901,9 @@ void http2_continuation_frame::dump(stream_t* s) { if (s) { http2_frame_header::dump(s); - // TODO + s->printf("> %s\n", constexpr_frame_fragment); + dump_memory(_fragment, s, 16, 2, 0x0, dump_memory_flag_t::dump_notrunc); + s->printf("\n"); } } diff --git a/sdk/net/http/http2_frame.hpp b/sdk/net/http/http2_frame.hpp index d4e9116e..d9182d0a 100644 --- a/sdk/net/http/http2_frame.hpp +++ b/sdk/net/http/http2_frame.hpp @@ -126,7 +126,6 @@ class http2_frame_header { virtual return_t write(binary_t& frame); virtual void dump(stream_t* s); - void set_uint8(uint8& target, uint8 data) { target = data; } void set_binary(binary_t& target, byte_t* data, size_t size) { if (data) { target.clear(); @@ -155,8 +154,8 @@ class http2_data_frame : public http2_frame_header { virtual void dump(stream_t* s); private: + uint8 _padlen; binary_t _data; - binary_t _pad; }; // RFC 7540 6.2 HEADERS @@ -169,11 +168,11 @@ class http2_headers_frame : public http2_frame_header { virtual void dump(stream_t* s); private: - bool _use_priority; + uint8 _padlen; + bool _exclusive; uint32 _dependency; uint8 _weight; binary_t _fragment; - binary_t _pad; }; // RFC 7540 6.3. PRIORITY @@ -182,10 +181,6 @@ class http2_priority_frame : public http2_frame_header { public: http2_priority_frame(); - uint8 get_exclusive(); - uint32 get_dependency(); - uint8 get_weight(); - virtual return_t read(http2_frame_header_t const* header, size_t size); virtual return_t write(binary_t& frame); virtual void dump(stream_t* s); @@ -202,9 +197,6 @@ class http2_rst_stream_frame : public http2_frame_header { public: http2_rst_stream_frame(); - uint32 get_errorcode(); - http2_rst_stream_frame& set_errorcode(uint32 errorcode); - virtual return_t read(http2_frame_header_t const* header, size_t size); virtual return_t write(binary_t& frame); virtual void dump(stream_t* s); @@ -240,9 +232,9 @@ class http2_push_promise_frame : public http2_frame_header { virtual void dump(stream_t* s); private: + uint8 _padlen; uint32 _promised_id; binary_t _fragment; - binary_t _pad; }; // RFC 7540 6.7. PING @@ -250,9 +242,6 @@ class http2_ping_frame : public http2_frame_header { public: http2_ping_frame(); - uint64 get_opaque(); - http2_ping_frame& set_opaque(uint64 opaque); - virtual return_t read(http2_frame_header_t const* header, size_t size); virtual return_t write(binary_t& frame); virtual void dump(stream_t* s); @@ -266,12 +255,6 @@ class http2_goaway_frame : public http2_frame_header { public: http2_goaway_frame(); - uint32 get_last_id(); - uint32 get_errorcode(); - http2_goaway_frame& set_last_id(uint32 last_id); - http2_goaway_frame& set_errorcode(uint32 errorcode); - http2_goaway_frame& set_debug(byte_t* debug, size_t size); - virtual return_t read(http2_frame_header_t const* header, size_t size); virtual return_t write(binary_t& frame); virtual void dump(stream_t* s); @@ -287,9 +270,6 @@ class http2_window_update_frame : public http2_frame_header { public: http2_window_update_frame(); - uint32 get_increment(); - http2_window_update_frame& set_increment(uint32 increment); - virtual return_t read(http2_frame_header_t const* header, size_t size); virtual return_t write(binary_t& frame); virtual void dump(stream_t* s); @@ -308,7 +288,7 @@ class http2_continuation_frame : public http2_frame_header { virtual void dump(stream_t* s); private: - binary_t fragment; + binary_t _fragment; }; } // namespace net diff --git a/sdk/net/http/http2_protocol.cpp b/sdk/net/http/http2_protocol.cpp index 8a97401c..4c7ea759 100644 --- a/sdk/net/http/http2_protocol.cpp +++ b/sdk/net/http/http2_protocol.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include namespace hotplace { diff --git a/sdk/net/http/http_resource.cpp b/sdk/net/http/http_resource.cpp index a730b8df..cc2ae1c9 100644 --- a/sdk/net/http/http_resource.cpp +++ b/sdk/net/http/http_resource.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -140,7 +141,7 @@ std::string http_resource::get_frame_flag(uint8 flag) { return flag_name; } -void http_resource::for_each_flags(uint8 flags, std::string& flag_string, std::function func) { +void http_resource::for_each_frame_flags(uint8 flags, std::string& flag_string, std::function func) { if (func) { for (auto item : _frame_flags) { uint8 flag = item.first; @@ -151,7 +152,7 @@ void http_resource::for_each_flags(uint8 flags, std::string& flag_string, std::f } } -void http_resource::for_each_flags(uint8 flags, stream_t* flag_string, std::function func) { +void http_resource::for_each_frame_flags(uint8 flags, stream_t* flag_string, std::function func) { if (flag_string && func) { for (auto item : _frame_flags) { uint8 flag = item.first; diff --git a/sdk/net/http/http_resource.hpp b/sdk/net/http/http_resource.hpp index 35bc1a9b..f1e6993a 100644 --- a/sdk/net/http/http_resource.hpp +++ b/sdk/net/http/http_resource.hpp @@ -57,8 +57,8 @@ class http_resource { * @brief frame flag */ std::string get_frame_flag(uint8 flag); - void for_each_flags(uint8 flags, std::string& flag_string, std::function func); - void for_each_flags(uint8 flags, stream_t* flag_string, std::function func); + void for_each_frame_flags(uint8 flags, std::string& flag_string, std::function func); + void for_each_frame_flags(uint8 flags, stream_t* flag_string, std::function func); protected: http_resource(); diff --git a/sdk/net/tls/tls.cpp b/sdk/net/tls/tls.cpp index e45ab1ed..f92d3baa 100644 --- a/sdk/net/tls/tls.cpp +++ b/sdk/net/tls/tls.cpp @@ -33,7 +33,7 @@ typedef struct _tls_context_t { transport_layer_security::transport_layer_security(SSL_CTX* x509) : _x509(x509) { if (nullptr == x509) { - throw errorcode_t::insufficiency; + throw errorcode_t::insufficient; } SSL_CTX_up_ref(x509); _shared.make_share(this); diff --git a/sdk/net/tls/tls_client.cpp b/sdk/net/tls/tls_client.cpp index d29e6a83..c9cd7cbf 100644 --- a/sdk/net/tls/tls_client.cpp +++ b/sdk/net/tls/tls_client.cpp @@ -16,7 +16,7 @@ namespace net { tls_client_socket::tls_client_socket(transport_layer_security* tls) : tcp_client_socket(), _tls(tls) { if (nullptr == tls) { - throw errorcode_t::insufficiency; + throw errorcode_t::insufficient; } tls->addref(); _shared.make_share(this); diff --git a/sdk/net/tls/tls_server.cpp b/sdk/net/tls/tls_server.cpp index b012bc12..ead5fa77 100644 --- a/sdk/net/tls/tls_server.cpp +++ b/sdk/net/tls/tls_server.cpp @@ -17,7 +17,7 @@ namespace net { tls_server_socket::tls_server_socket(transport_layer_security* tls) : _tls(tls) { if (nullptr == tls) { - throw errorcode_t::insufficiency; + throw errorcode_t::insufficient; } tls->addref(); _shared.make_share(this); diff --git a/sdk/odbc/basic/odbc_sinker.cpp b/sdk/odbc/basic/odbc_sinker.cpp index 395d3a3a..02adbd32 100644 --- a/sdk/odbc/basic/odbc_sinker.cpp +++ b/sdk/odbc/basic/odbc_sinker.cpp @@ -17,7 +17,7 @@ namespace odbc { odbc_sinker::odbc_sinker(odbc_query* dbquery, uint32 tmo_seconds) : _dbquery(dbquery), _tmo_seconds(tmo_seconds) { if (nullptr == dbquery) { - throw errorcode_t::insufficiency; + throw errorcode_t::insufficient; } time_monotonic(_timestamp); diff --git a/test/httpauth/sample.cpp b/test/httpauth/sample.cpp index 16b16a90..860da328 100644 --- a/test/httpauth/sample.cpp +++ b/test/httpauth/sample.cpp @@ -323,7 +323,7 @@ int main(int argc, char** argv) { #endif cmdline.make_share(new cmdline_t