Safeheron-SGX-Native-Development-Framework v1.2.0
Loading...
Searching...
No Matches
ssgx_http_u.h
Go to the documentation of this file.
1#ifndef SSGX_HTTP_U_CALLBACK_MANAGER_H
2#define SSGX_HTTP_U_CALLBACK_MANAGER_H
3
4#include <cstddef>
5#include <mutex>
6#include <sgx_error.h>
7#include <sgx_urts.h>
8#include <unordered_map>
9
10namespace ssgx {
11
16namespace http_u {
17
19using HttpOnMessageCallback = sgx_status_t (*)(sgx_enclave_id_t eid, int* retval, const char* server_id,
20 const char* req_method, const char* req_path,
21 const char* req_params_json, const char* req_headers_json,
22 const uint8_t* req_body, size_t req_body_size,
23 char** resp_status_headers_json, uint8_t** resp_body,
24 size_t* resp_body_size);
25
27using RegisterEidCallback = sgx_status_t (*)(sgx_enclave_id_t eid, sgx_enclave_id_t enclave_eid);
28
29
34 public:
40 static HttpCallbackManager instance;
41 return instance;
42 }
50 bool RegisterCallbacks(sgx_enclave_id_t eid, RegisterEidCallback register_cb, HttpOnMessageCallback http_cb) {
51 std::lock_guard<std::mutex> lock(mutex_);
52 http_callback_map_[eid] = http_cb;
53 sgx_status_t status = register_cb(eid, eid);
54 return status == SGX_SUCCESS;
55 }
56
62 bool HasHttpCallback(sgx_enclave_id_t eid) const {
63 std::lock_guard<std::mutex> lock(mutex_);
64 return http_callback_map_.count(eid) > 0;
65 }
66
72 HttpOnMessageCallback GetHttpCallback(sgx_enclave_id_t eid) const {
73 std::lock_guard<std::mutex> lock(mutex_);
74 auto it = http_callback_map_.find(eid);
75 if (it != http_callback_map_.end()) {
76 return it->second;
77 }
78 return nullptr;
79 }
80
81 public:
84
87
88 private:
89 HttpCallbackManager() = default;
90 ~HttpCallbackManager() = default;
91
92 mutable std::mutex mutex_;
93 std::unordered_map<sgx_enclave_id_t, HttpOnMessageCallback> http_callback_map_;
94};
95
96} // namespace http_u
97} // namespace ssgx
98
99#endif // SSGX_HTTP_U_CALLBACK_MANAGER_H
Http module callback function registration and management.
Definition ssgx_http_u.h:33
bool RegisterCallbacks(sgx_enclave_id_t eid, RegisterEidCallback register_cb, HttpOnMessageCallback http_cb)
Http module callback function registration.
Definition ssgx_http_u.h:50
static HttpCallbackManager & GetInstance()
Singleton Pattern.
Definition ssgx_http_u.h:39
HttpCallbackManager(const HttpCallbackManager &)=delete
HttpCallbackManager & operator=(HttpCallbackManager &&)=delete
bool HasHttpCallback(sgx_enclave_id_t eid) const
Check if the enclave has registered a callback function.
Definition ssgx_http_u.h:62
HttpOnMessageCallback GetHttpCallback(sgx_enclave_id_t eid) const
Get the http message callback function of the corresponding enclave.
Definition ssgx_http_u.h:72
HttpCallbackManager(HttpCallbackManager &&)=delete
HttpCallbackManager & operator=(const HttpCallbackManager &)=delete
sgx_status_t(*)(sgx_enclave_id_t eid, sgx_enclave_id_t enclave_eid) RegisterEidCallback
Typedef for Enclave ID registration callback.
Definition ssgx_http_u.h:27
sgx_status_t(*)(sgx_enclave_id_t eid, int *retval, const char *server_id, const char *req_method, const char *req_path, const char *req_params_json, const char *req_headers_json, const uint8_t *req_body, size_t req_body_size, char **resp_status_headers_json, uint8_t **resp_body, size_t *resp_body_size) HttpOnMessageCallback
Typedef for HTTP message callback.
Definition ssgx_http_u.h:19
Definition ssgx_attestation_t.h:6