Skip to content

Commit

Permalink
hotplace rev.489 grooming
Browse files Browse the repository at this point in the history
  • Loading branch information
princeb612 committed Apr 6, 2024
1 parent cb0fde8 commit 70284d4
Show file tree
Hide file tree
Showing 10 changed files with 724 additions and 274 deletions.
7 changes: 0 additions & 7 deletions sdk/crypto/jose/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@
namespace hotplace {
namespace crypto {

enum jose_serialization_t {
jose_compact = 0,
jose_json = 1,
jose_flatjson = 2,
};
#define JOSE_JSON_FORMAT jose_serialization_t::jose_flatjson

enum jose_compose_t {
jose_enc_only = 1,
jose_alg_only = 2,
Expand Down
7 changes: 7 additions & 0 deletions sdk/crypto/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,13 @@ typedef struct _hash_context_t hash_context_t;
struct _otp_context_t {};
typedef struct _otp_context_t otp_context_t;

enum jose_serialization_t {
jose_compact = 0,
jose_json = 1,
jose_flatjson = 2,
};
#define JOSE_JSON_FORMAT jose_serialization_t::jose_flatjson

} // namespace crypto
} // namespace hotplace

Expand Down
2 changes: 1 addition & 1 deletion sdk/io/string/url.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ return_t split_url(const char* src, url_info_t* info) {
info->uripath = *tokens.begin();
}

regex_token(url, "[?][a-zA-Z0-9&%+./:=_]*", pos, tokens);
regex_token(url, "[?][a-zA-Z0-9&%+-./:=_]*", pos, tokens);
if (tokens.size()) {
info->query = *tokens.begin();
info->query.erase(info->query.begin()); // "?" query
Expand Down
61 changes: 38 additions & 23 deletions sdk/net/http/http_router.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,41 +37,54 @@ void http_router::clear() {
}

http_router& http_router::add(const char* uri, http_request_handler_t handler, http_authenticate_provider* auth_provider, bool upref) {
critical_section_guard guard(_lock);
if (uri) {
add(std::string(uri), handler, auth_provider, upref);
}
return *this;
}

http_router& http_router::add(const char* uri, http_request_function_t handler, http_authenticate_provider* auth_provider, bool upref) {
if (uri) {
http_router_t route;
route.handler = handler;
_handler_map.insert(std::make_pair(uri, route));

if (auth_provider) {
authenticate_map_pib_t pib = _authenticate_map.insert(std::make_pair(uri, auth_provider));
if (upref) {
if (pib.second) {
auth_provider->addref();
}
add(std::string(uri), handler, auth_provider, upref);
}
return *this;
}

http_router& http_router::add(std::string const& uri, http_request_handler_t handler, http_authenticate_provider* auth_provider, bool upref) {
critical_section_guard guard(_lock);

http_router_t route;
route.handler = handler;
_handler_map.insert(std::make_pair(uri, route));

if (auth_provider) {
authenticate_map_pib_t pib = _authenticate_map.insert(std::make_pair(uri, auth_provider));
if (upref) {
if (pib.second) {
auth_provider->addref();
}
}
}

return *this;
}

http_router& http_router::add(const char* uri, http_request_function_t handler, http_authenticate_provider* auth_provider, bool upref) {
http_router& http_router::add(std::string const& uri, http_request_function_t handler, http_authenticate_provider* auth_provider, bool upref) {
critical_section_guard guard(_lock);
if (uri) {
http_router_t route;
route.stdfunc = handler;
_handler_map.insert(std::make_pair(uri, route));

if (auth_provider) {
authenticate_map_pib_t pib = _authenticate_map.insert(std::make_pair(uri, auth_provider));
if (upref) {
if (pib.second) {
auth_provider->addref();
}

http_router_t route;
route.stdfunc = handler;
_handler_map.insert(std::make_pair(uri, route));

if (auth_provider) {
authenticate_map_pib_t pib = _authenticate_map.insert(std::make_pair(uri, auth_provider));
if (upref) {
if (pib.second) {
auth_provider->addref();
}
}
}

return *this;
}

Expand Down Expand Up @@ -165,6 +178,8 @@ http_authentication_resolver& http_router::get_authenticate_resolver() { return

html_documents& http_router::get_html_documents() { return _http_documents; }

oauth2_provider& http_router::get_oauth2_provider() { return _oauth2; }

bool http_router::get_auth_provider(http_request* request, http_response* response, http_authenticate_provider** provider) {
bool ret_value = false;
return_t ret = errorcode_t::success;
Expand Down
6 changes: 6 additions & 0 deletions sdk/net/http/http_router.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <sdk/net/http/html_documents.hpp>
#include <sdk/net/http/http_authentication_provider.hpp>
#include <sdk/net/http/http_authentication_resolver.hpp>
#include <sdk/net/http/oauth2.hpp>
#include <sdk/net/server/network_protocol.hpp>

namespace hotplace {
Expand All @@ -46,6 +47,8 @@ class http_router {
*/
http_router& add(const char* uri, http_request_handler_t handler, http_authenticate_provider* auth_provider = nullptr, bool upref = false);
http_router& add(const char* uri, http_request_function_t handler, http_authenticate_provider* auth_provider = nullptr, bool upref = false);
http_router& add(std::string const& uri, http_request_handler_t handler, http_authenticate_provider* auth_provider = nullptr, bool upref = false);
http_router& add(std::string const& uri, http_request_function_t handler, http_authenticate_provider* auth_provider = nullptr, bool upref = false);
/**
* @brief register a handler
* @sample
Expand Down Expand Up @@ -74,6 +77,8 @@ class http_router {

html_documents& get_html_documents();

oauth2_provider& get_oauth2_provider();

protected:
/**
* @brief http_authenticate_provider
Expand Down Expand Up @@ -103,6 +108,7 @@ class http_router {
status_handler_map_t _status_handler_map;
authenticate_map_t _authenticate_map;
http_authentication_resolver _resolver;
oauth2_provider _oauth2;
html_documents _http_documents;
};

Expand Down
Loading

0 comments on commit 70284d4

Please sign in to comment.