Skip to content

Commit

Permalink
hotplace rev.458 http
Browse files Browse the repository at this point in the history
  • Loading branch information
princeb612 committed Jan 13, 2024
1 parent 0e179f8 commit ca41128
Show file tree
Hide file tree
Showing 28 changed files with 551 additions and 315 deletions.
19 changes: 9 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,6 @@

## implemented

* RFC 4648 The Base16, Base32, and Base64 Data Encodings
* sdk/io/basic/
* test/encode/

* RFC 4226 HOTP: An HMAC-Based One-Time Password Algorithm
* RFC 6238 TOTP: Time-Based One-Time Password Algorithm
* sdk/crypto/basic/
* test/crypto/

* RFC 7049 Concise Binary Object Representation (CBOR)
* RFC 8949 Concise Binary Object Representation (CBOR)
* sdk/io/cbor/
Expand All @@ -52,6 +43,15 @@

## applied

* RFC 4648 The Base16, Base32, and Base64 Data Encodings
* sdk/io/basic/
* test/encode/

* RFC 4226 HOTP: An HMAC-Based One-Time Password Algorithm
* RFC 6238 TOTP: Time-Based One-Time Password Algorithm
* sdk/crypto/basic/
* test/crypto/

* RFC 2144 The CAST-128 Encryption Algorithm (May 1997)
* RFC 2612 The CAST-256 Encryption Algorithm (June 1999)
* RFC 3394 Advanced Encryption Standard (AES) Key Wrap Algorithm (September 2002)
Expand Down Expand Up @@ -91,7 +91,6 @@
* RFC 8996 Deprecating TLS 1.0 and TLS 1.1
* sdk/net/tls/

* RFC 2617 HTTP Authentication: Basic and Digest Access Authentication
* RFC 2069 An Extension to HTTP : Digest Access Authentication
* RFC 2617 HTTP Authentication: Basic and Digest Access Authentication
* RFC 7616 HTTP Digest Access Authentication
Expand Down
2 changes: 1 addition & 1 deletion sdk/base/stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class stream_t {

virtual byte_t* data() const = 0;
virtual uint64 size() const = 0;
virtual return_t write(void* data, size_t size) = 0;
virtual return_t write(const void* data, size_t size) = 0;
virtual return_t fill(size_t l, char c) = 0;
virtual return_t clear() = 0;

Expand Down
18 changes: 15 additions & 3 deletions sdk/base/stream/basic_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ namespace hotplace {

basic_stream::basic_stream(size_t allocsize, uint32 flags) : _handle(nullptr) { _bio.open(&_handle, allocsize, 1, flags); }

basic_stream::basic_stream(const char* data) : _handle(nullptr) {
basic_stream::basic_stream(const char* data, ...) : _handle(nullptr) {
va_list ap;
va_start(ap, data);
_bio.open(&_handle, 1 << 10, 1);
_bio.write(_handle, data, strlen(data));
_bio.vprintf(_handle, data, ap);
va_end(ap);
}

basic_stream::basic_stream(const basic_stream& stream) : _handle(nullptr) {
Expand Down Expand Up @@ -56,7 +59,11 @@ uint64 basic_stream::size() const {
return size;
}

return_t basic_stream::write(void* data, size_t size) { return _bio.write(_handle, data, size); }
return_t basic_stream::write(const void* data, size_t size) { return _bio.write(_handle, data, size); }

return_t basic_stream::cut(uint32 begin_pos, uint32 length) { return _bio.cut(_handle, begin_pos, length); }

return_t basic_stream::insert(size_t begin, const void* data, size_t data_size) { return _bio.insert(_handle, begin, data, data_size); }

return_t basic_stream::fill(size_t l, char c) {
return_t ret = errorcode_t::success;
Expand Down Expand Up @@ -162,6 +169,11 @@ basic_stream& basic_stream::operator<<(unsigned long value) {
return *this;
}

basic_stream& basic_stream::operator<<(size_t value) {
printf("%zi", value);
return *this;
}

basic_stream& basic_stream::operator<<(basic_stream const& value) {
write(value.data(), value.size());
return *this;
Expand Down
7 changes: 5 additions & 2 deletions sdk/base/stream/basic_stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class basic_stream : public stream_t {
* @brief constructor
* @param const char* data [in]
*/
basic_stream(const char* data);
basic_stream(const char* data, ...);
/**
* @brief constructor
* @param const basic_stream& stream [in]
Expand Down Expand Up @@ -63,7 +63,9 @@ class basic_stream : public stream_t {
* @param void* data [in]
* @param size_t size [in]
*/
return_t write(void* data, size_t size);
return_t write(const void* data, size_t size);
return_t cut(uint32 begin_pos, uint32 length);
return_t insert(size_t begin, const void* data, size_t data_size);
/**
* @brief fill
* @param size_t l [in]
Expand Down Expand Up @@ -95,6 +97,7 @@ class basic_stream : public stream_t {
basic_stream& operator<<(unsigned int value);
basic_stream& operator<<(long value);
basic_stream& operator<<(unsigned long value);
basic_stream& operator<<(size_t value);
basic_stream& operator<<(basic_stream const& value);
basic_stream& operator<<(std::string const& value);

Expand Down
15 changes: 10 additions & 5 deletions sdk/base/syntax.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@
#define __leave2 break

#if defined DEBUG
#define __footprints(x) ::printf("[\e[31m%08x\e[0m][%s @ %d]\n", x, __FILE__, __LINE__)
#define __footprintf(...) \
::printf("[\e[35m debug \e[0m][%s @ %d] ", __FILE__, __LINE__); \
::printf(__VA_ARGS__); \
printf("\n");
#define __footprints(x) \
if (hotplace::get_trace_option()) { \
::printf("[\e[31m%08x\e[0m][%s @ %d]\n", x, __FILE__, __LINE__); \
}
#define __footprintf(...) \
if (hotplace::get_trace_option()) { \
::printf("[\e[35m debug \e[0m][%s @ %d] ", __FILE__, __LINE__); \
::printf(__VA_ARGS__); \
printf("\n"); \
}
#else
#define __footprints(x)
#define __footprintf(...)
Expand Down
2 changes: 1 addition & 1 deletion sdk/crypto/authenticode/authenticode_verifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ int verify_callback(int ok, X509_STORE_CTX* ctx) {
std::string find = format("CN=%s", cn.c_str());
size_t pos = subject.find(find);

if ((size_t)-1 != pos) {
if (std::string::npos != pos) {
if (0 == strcmp(subject.substr(pos).c_str(), find.c_str())) {
match = true;
break;
Expand Down
2 changes: 1 addition & 1 deletion sdk/io/stream/ansi_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ uint64 ansi_string::size() const {
return size;
}

return_t ansi_string::write(void* data, size_t size) { return _bio.write(_handle, data, size); }
return_t ansi_string::write(const void* data, size_t size) { return _bio.write(_handle, data, size); }

return_t ansi_string::fill(size_t l, char c) {
return_t ret = errorcode_t::success;
Expand Down
16 changes: 14 additions & 2 deletions sdk/io/stream/dump_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,26 @@
namespace hotplace {
namespace io {

return_t dump_memory(const std::string& data, stream_t* stream_object, unsigned hex_part, unsigned indent, size_t rebase, int flags) {
return_t dump_memory(const char* data, stream_t* stream_object, unsigned hex_part, unsigned indent, size_t rebase, int flags) {
size_t size = 0;
if (data) {
size = strlen(data);
}
return dump_memory((byte_t*)data, size, stream_object, hex_part, indent, rebase, flags);
}

return_t dump_memory(std::string const& data, stream_t* stream_object, unsigned hex_part, unsigned indent, size_t rebase, int flags) {
return dump_memory((byte_t*)data.c_str(), data.size(), stream_object, hex_part, indent, rebase, flags);
}

return_t dump_memory(const binary_t& data, stream_t* stream_object, unsigned hex_part, unsigned indent, size_t rebase, int flags) {
return_t dump_memory(binary_t const& data, stream_t* stream_object, unsigned hex_part, unsigned indent, size_t rebase, int flags) {
return dump_memory(&data[0], data.size(), stream_object, hex_part, indent, rebase, flags);
}

return_t dump_memory(basic_stream const& data, stream_t* stream_object, unsigned hex_part, unsigned indent, size_t rebase, int flags) {
return dump_memory(data.data(), data.size(), stream_object, hex_part, indent, rebase, flags);
}

return_t dump_memory(bufferio_context_t* handle, stream_t* stream_object, unsigned hex_part, unsigned indent, size_t rebase, int flags) {
return_t ret = errorcode_t::success;

Expand Down
2 changes: 1 addition & 1 deletion sdk/io/stream/file_stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class file_stream : public stream_t {
* in case of mmaped status, all write operation work up to (4G - 1) bytes
* @sa
*/
virtual return_t write(void* data, size_t size_data);
virtual return_t write(const void* data, size_t size_data);
virtual return_t fill(size_t l, char c);
/**
* @brief read
Expand Down
41 changes: 10 additions & 31 deletions sdk/io/stream/linux/file_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,40 +262,19 @@ void file_stream::seek(int64 file_pos, int64* ptr_file_pos, uint32 method) {
}
}

return_t file_stream::write(void* data, size_t size_data) {
return_t file_stream::write(const void* data, size_t size_data) {
return_t ret = errorcode_t::success;

__try2 {
if (true == is_open()) {
if (true == is_mmapped()) {
if ((_filepos_high > 0) || (((uint32)-1 - _filepos_low) < size_data)) {
ret = errorcode_t::not_supported;
} else {
memcpy(reinterpret_cast<byte_t*>(data) + _filepos_low, data, size_data);
uint32 size_mask = ~_filepos_low;
if (size_mask < size_data) {
_filepos_high++;
}
_filepos_low += size_data;
}
} else {
uint32 dwIndex = 0;
int len = 0;
while (size_data) {
len = ::write(_file_handle, (byte_t*)data + dwIndex, size_data);
if (-1 == len) {
ret = errno;
break;
}
size_data -= len;
dwIndex += len;
}
}
} else {
uint32 dwIndex = 0;
int len = 0;
while (size_data) {
len = ::write(_file_handle, (byte_t*)data + dwIndex, size_data);
if (-1 == len) {
ret = errno;
break;
}
}
__finally2 {
// do nothing
size_data -= len;
dwIndex += len;
}
return ret;
}
Expand Down
7 changes: 5 additions & 2 deletions sdk/io/stream/stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <sdk/base/basic/valist.hpp>
#include <sdk/base/stream.hpp>
#include <sdk/base/stream/basic_stream.hpp>
#include <sdk/base/stream/bufferio.hpp>

namespace hotplace {
Expand Down Expand Up @@ -146,8 +147,10 @@ return_t vtprintf(stream_t* stream, variant_t const& vt, vtprintf_style_t style
// part - dump
//

return_t dump_memory(const std::string& data, stream_t* stream_object, unsigned hex_part = 16, unsigned indent = 0, size_t rebase = 0x0, int flags = 0);
return_t dump_memory(const binary_t& data, stream_t* stream_object, unsigned hex_part = 16, unsigned indent = 0, size_t rebase = 0x0, int flags = 0);
return_t dump_memory(const char* data, stream_t* stream_object, unsigned hex_part = 16, unsigned indent = 0, size_t rebase = 0x0, int flags = 0);
return_t dump_memory(std::string const& data, stream_t* stream_object, unsigned hex_part = 16, unsigned indent = 0, size_t rebase = 0x0, int flags = 0);
return_t dump_memory(binary_t const& data, stream_t* stream_object, unsigned hex_part = 16, unsigned indent = 0, size_t rebase = 0x0, int flags = 0);
return_t dump_memory(basic_stream const& data, stream_t* stream_object, unsigned hex_part = 16, unsigned indent = 0, size_t rebase = 0x0, int flags = 0);
return_t dump_memory(bufferio_context_t* context, stream_t* stream_object, unsigned hex_part = 16, unsigned indent = 0, size_t rebase = 0x0, int flags = 0);
return_t dump_memory(variant_t vt, stream_t* stream_object, unsigned hex_part = 16, unsigned indent = 0, size_t rebase = 0x0, int flags = 0);

Expand Down
4 changes: 2 additions & 2 deletions sdk/io/stream/string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ansi_string : public stream_t {

byte_t* data() const;
uint64 size() const;
return_t write(void* data, size_t size);
return_t write(const void* data, size_t size);
return_t fill(size_t l, char c);
return_t clear();

Expand Down Expand Up @@ -150,7 +150,7 @@ class wide_string : public stream_t {

byte_t* data() const;
uint64 size() const;
return_t write(void* data, size_t size);
return_t write(const void* data, size_t size);
return_t fill(size_t l, char c);
return_t clear();

Expand Down
2 changes: 1 addition & 1 deletion sdk/io/stream/unicode/wide_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ uint64 wide_string::size() const {
return size;
}

return_t wide_string::write(void* data, size_t size) { return _bio.write(_handle, data, size); }
return_t wide_string::write(const void* data, size_t size) { return _bio.write(_handle, data, size); }

return_t wide_string::fill(size_t l, char c) {
return_t ret = errorcode_t::success;
Expand Down
50 changes: 18 additions & 32 deletions sdk/io/stream/windows/file_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,41 +311,27 @@ void file_stream::seek(int64 lfilepos, int64* ptrfilepos, uint32 method) {
}
}

return_t file_stream::write(void* data, size_t size_data) {
return_t file_stream::write(const void* data, size_t size_data) {
return_t ret = errorcode_t::success;

__try2 {
if (true == is_open()) {
if (true == is_mmapped()) {
if ((_filepos_high > 0) || (-1 - _filepos_low < size_data)) {
ret = errorcode_t::not_supported;
} else {
memcpy(reinterpret_cast<byte_t*>(data) + _filepos_low, data, size_data);
uint32 size_mask = ~_filepos_low;
if (size_mask < size_data) {
_filepos_high++;
}
_filepos_low += size_data;
}
} else {
byte_t* mem = (byte_t*)data;
uint32 idx = 0;
while (size_data) {
DWORD written = 0;
BOOL test = WriteFile(_file_handle, mem + idx, size_data, &written, nullptr);
if (FALSE == test) {
ret = GetLastError();
break;
}
size_data -= written;
idx += written;
}
}
} else {
// windows
// handle = CreateFileMapping ( ..., filesize + tobewritten, ...);
// fileptr = MapViewOfFile(handle)
// memcpy (fileptr + filesize, data, tobewritten);

// linux .. not work

byte_t* mem = (byte_t*)data;
uint32 idx = 0;
while (size_data) {
DWORD written = 0;
BOOL test = WriteFile(_file_handle, mem + idx, size_data, &written, nullptr);
if (FALSE == test) {
ret = GetLastError();
break;
}
}
__finally2 {
// do nothing
size_data -= written;
idx += written;
}
return ret;
}
Expand Down
Loading

0 comments on commit ca41128

Please sign in to comment.