Skip to content

Commit

Permalink
hotplace rev.462 http
Browse files Browse the repository at this point in the history
  • Loading branch information
princeb612 committed Jan 14, 2024
1 parent bc3b6ad commit def0bf9
Show file tree
Hide file tree
Showing 17 changed files with 376 additions and 143 deletions.
8 changes: 7 additions & 1 deletion sdk/base/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ enum errorcode_t {
/* 0xef010017 4009820183 */ expired,
/* 0xef010018 4009820184 */ canceled,
/* 0xef010019 4009820185 */ request,
/* */ invalid_request = request,
/* 0xef01001a 4009820186 */ response,
/* 0xef01001b 4009820187 */ unexpected,
/* 0xef01001c 4009820188 */ max_reached,
Expand All @@ -239,7 +240,12 @@ enum errorcode_t {
/* 0xef01002a 4009820202 */ suspicious,
/* 0xef01002b 4009820203 */ unknown,
/* 0xef01002c 4009820204 */ inaccurate,
/* 0xef01002d 4009820205 */ authenticate,
/* 0xef01002d 4009820205 */ unauthorized_client,
/* 0xef01002e 4009820206 */ access_denied,
/* 0xef01002f 4009820207 */ unsupported_response_type,
/* 0xef010030 4009820208 */ invalid_scope,
/* 0xef010031 4009820209 */ server_error,
/* 0xef010032 4009820210 */ temporarily_unavailable,

/* 0xef010080 4009820288 */ internal_error_0 = 0xef010080,
/* 0xef010081 4009820289 */ internal_error_1,
Expand Down
11 changes: 11 additions & 0 deletions sdk/crypto/basic/openssl_prng.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,16 @@ std::string openssl_prng::nonce(size_t size) {
return ret_value;
}

std::string openssl_prng::token(size_t size) {
std::string ret_value;

binary_t buffer;
buffer.resize(size);
RAND_bytes(&buffer[0], buffer.size());
ret_value = base64_encode(buffer, base64_encoding_t::base64url_encoding);

return ret_value;
}

} // namespace crypto
} // namespace hotplace
1 change: 1 addition & 0 deletions sdk/crypto/basic/openssl_prng.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class openssl_prng {
return_t random(binary_t& buffer, size_t size);
return_t random(uint32& i, uint32 mask = (uint32)~1);
std::string nonce(size_t size);
std::string token(size_t size);
};

} // namespace crypto
Expand Down
22 changes: 22 additions & 0 deletions sdk/io/basic/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@
namespace hotplace {
namespace io {

/**
* @brief json
* @param json_t** object [out]
* @param const char* buffer [in]
* @param bool suppress [inopt] default false
* @sample
* json_t* json_root = nullptr;
* json_open_stream(&json_root, json_stream);
* if (json_root) {
* const char* unp_access_token = nullptr;
* const char* unp_token_type = nullptr;
* json_unpack(json_root, "{s:s}", "access_token", &unp_access_token);
* json_unpack(json_root, "{s:s}", "token_type", &unp_token_type);
* json_decref(json_root);
* }
*/
static inline return_t json_open_stream(json_t** object, const char* buffer, bool suppress = false) {
return_t ret = errorcode_t::success;

Expand Down Expand Up @@ -49,6 +65,12 @@ static inline return_t json_open_stream(json_t** object, const char* buffer, boo
return ret;
}

/**
* @brief json
* @param json_t** object [out]
* @param const char* file [in]
* @param bool suppress [inopt] default false
*/
static inline return_t json_open_file(json_t** object, const char* file, bool suppress = false) {
return_t ret = errorcode_t::success;

Expand Down
21 changes: 19 additions & 2 deletions sdk/io/basic/keyvalue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,22 @@ class key_value {
* @param uint32 flags [inopt]
*/
key_value(uint32 flags = key_value_flag_t::key_value_case_sensitive);
/**
* @brief destructor
*/
~key_value();

/**
* @brief set
* @param uint32 flags [in]
*/
key_value& set(uint32 flags);

/**
* @brief add, update
* @param const char* name [IN]
* @param const char* value [IN]
* @param uint32 flags [INOPT] 1 overwrite, 0 keep old
* @param uint32 mode [INOPT] 1 overwrite, 0 keep old
* @return error code (see error.hpp)
* @remarks
* set (key1, value1, key_value_mode_t::keep); // return errorcode_t::success
Expand Down Expand Up @@ -124,9 +131,19 @@ class key_value {
*/
return_t copy(key_value& rhs, int mode = key_value_mode_t::update);

/**
* @brief copy
* @return error code (see error.hpp)
* @sa copy
*/
return_t copyfrom(std::map<std::string, std::string>& source, int mode);
return_t copyto(std::map<std::string, std::string>& target);

/**
* @brief foreach
* @param std::function<void(std::string const&, std::string const&, void*)> func [in]
* @param void* param [inopt]
*/
void foreach (std::function<void(std::string const&, std::string const&, void*)> func, void* param = nullptr);

/**
Expand All @@ -144,14 +161,14 @@ class key_value {
*/
key_value& operator<<(key_value& rhs);

protected:
/* key, value */
typedef std::map<std::string, std::string> keyvalue_map_t;
typedef std::pair<keyvalue_map_t::iterator, bool> keyvalue_map_pib_t;

typedef std::map<int, std::string> key_order_map_t;
typedef std::map<std::string, int> key_reverse_order_map_t;

protected:
critical_section _lock;
keyvalue_map_t _keyvalues;
key_order_map_t _order_map;
Expand Down
8 changes: 4 additions & 4 deletions sdk/io/basic/zlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ return_t zlib_deflate(zlib_windowbits_t windowbits, byte_t const* input, size_t
case zlib_windowbits_t::windowbits_deflate:
wbit = -MAX_WBITS;
break;
case zlib_windowbits_t::windowbits_zlib:
case zlib_windowbits_t::windowbits_gzip:
wbit = MAX_WBITS + 16;
break;
}
Expand Down Expand Up @@ -124,7 +124,7 @@ return_t zlib_inflate(zlib_windowbits_t windowbits, byte_t const* input, size_t
case zlib_windowbits_t::windowbits_deflate:
wbit = -MAX_WBITS;
break;
case zlib_windowbits_t::windowbits_zlib:
case zlib_windowbits_t::windowbits_gzip:
wbit = MAX_WBITS + 16;
break;
}
Expand Down Expand Up @@ -192,7 +192,7 @@ return_t zlib_deflate(zlib_windowbits_t windowbits, byte_t const* input, size_t
case zlib_windowbits_t::windowbits_deflate:
wbit = -MAX_WBITS;
break;
case zlib_windowbits_t::windowbits_zlib:
case zlib_windowbits_t::windowbits_gzip:
wbit = MAX_WBITS + 16;
break;
}
Expand Down Expand Up @@ -252,7 +252,7 @@ return_t zlib_inflate(zlib_windowbits_t windowbits, byte_t const* input, size_t
case zlib_windowbits_t::windowbits_deflate:
wbit = -MAX_WBITS;
break;
case zlib_windowbits_t::windowbits_zlib:
case zlib_windowbits_t::windowbits_gzip:
wbit = MAX_WBITS + 16;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/io/basic/zlib.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace io {
enum zlib_windowbits_t {
windowbits_compress = 0, /* using windowBits MAX_WBITS(15) */
windowbits_deflate = 1, /* RFC1951 : DEFLATE Compressed Data Format Specification version 1.3, using windowBits -MAX_WBITS(-15) */
windowbits_zlib = 2, /* RFC1952 : GZIP file format specification version 4.3, using windowBits MAX_WBITS + 16(31) */
windowbits_gzip = 2, /* RFC1952 : GZIP file format specification version 4.3, using windowBits MAX_WBITS + 16(31) */
};

return_t zlib_deflate(zlib_windowbits_t windowbits, binary_t const& input, binary_t& output);
Expand Down
Loading

0 comments on commit def0bf9

Please sign in to comment.