52 lines
1.8 KiB
C++
52 lines
1.8 KiB
C++
#include "tfe_rpc.h"
|
|
#include "tfe_utils.h"
|
|
#include "MESA/MESA_prof_load.h"
|
|
#include "MESA/MESA_handle_logger.h"
|
|
#include "string.h"
|
|
|
|
static void
|
|
tfe_rpc_on_succ(void* result, void* user)
|
|
{
|
|
struct tfe_rpc_response_result* response = tfe_rpc_release(result);
|
|
int status_code = response->status_code;
|
|
const char* status_msg = response->status_msg;
|
|
char* data = (char*)response->data;
|
|
int len = response->len;
|
|
*(data+len) = '\0';
|
|
printf("status_code is %d\n", status_code);
|
|
printf("status_msg is %s\n", status_msg);
|
|
printf("data is %s\n", data);
|
|
printf("len is %d\n", len);
|
|
}
|
|
|
|
|
|
static void
|
|
tfe_rpc_on_fail(enum e_future_error err, const char * what, void * user){
|
|
printf("err is %d\n", err);
|
|
printf("what is %s\n", what);
|
|
printf("user is %s\n", user);
|
|
}
|
|
|
|
int main()
|
|
{
|
|
char cert_store_host[TFE_STRING_MAX];
|
|
unsigned int cert_store_port;
|
|
const char* file_path = "./log/test_tfe_rpc.log",*host="localhost";
|
|
void * logger = MESA_create_runtime_log_handle(file_path, RLOG_LV_INFO);
|
|
const char* profile = "./conf/tfe.conf";
|
|
const char* section = "key_keeper";
|
|
int keyring_id = 0;
|
|
MESA_load_profile_string_def(profile, section, "cert_store_host", cert_store_host, sizeof(cert_store_host), "xxxxx");
|
|
MESA_load_profile_uint_def(profile, section, "cert_store_port", &cert_store_port, 80);
|
|
struct event_base* evbase = event_base_new();
|
|
struct future* f_tfe_rpc = future_create("tfe_rpc", tfe_rpc_on_succ, tfe_rpc_on_fail, NULL);
|
|
struct tfe_rpc* rpc = tfe_rpc_init(NULL, NULL, logger);
|
|
char url[TFE_STRING_MAX];
|
|
strncpy(cert_store_host, "www.baidu.com", TFE_STRING_MAX);
|
|
snprintf(url, TFE_STRING_MAX, "http://%s:%d/ca?host=%s&flag=1&valid=1&kering_id=%d", cert_store_host, cert_store_port, host, keyring_id);
|
|
printf("url is %s\n", url);
|
|
tfe_rpc_async_ask(f_tfe_rpc, rpc, url, GET, DONE_CB, NULL, 0, evbase);
|
|
event_base_dispatch(evbase);
|
|
}
|
|
|