|
@@ -11,9 +11,9 @@ namespace gsd{
|
|
}
|
|
}
|
|
|
|
|
|
int32_t Hepu::Init(std::string username, std::string url, int port){
|
|
int32_t Hepu::Init(std::string username, std::string url, int port){
|
|
- cout<<"Hepu username: "<<username<<endl;
|
|
|
|
- cout<<"Hepu api url: "<<url<<endl;
|
|
|
|
- cout<<"Hepu port: "<<port<<endl;
|
|
|
|
|
|
+ //cout<<"Hepu username: "<<username<<endl;
|
|
|
|
+ //cout<<"Hepu api url: "<<url<<endl;
|
|
|
|
+ //cout<<"Hepu port: "<<port<<endl;
|
|
this->username_ = username;
|
|
this->username_ = username;
|
|
m_hepu = std::make_shared<httplib::Client>(url, port);
|
|
m_hepu = std::make_shared<httplib::Client>(url, port);
|
|
if(m_hepu == NULL){
|
|
if(m_hepu == NULL){
|
|
@@ -21,7 +21,10 @@ namespace gsd{
|
|
return ERR;
|
|
return ERR;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
|
|
+ if(this->getSalt() != OK){
|
|
|
|
+ ErrorL << "Failed to get salt from Hepu IPC.";
|
|
|
|
+ return ERR;
|
|
|
|
+ }
|
|
|
|
|
|
if(this->LoginHepu() != OK){
|
|
if(this->LoginHepu() != OK){
|
|
ErrorL << "Failed to login to Hepu IPC.";
|
|
ErrorL << "Failed to login to Hepu IPC.";
|
|
@@ -54,24 +57,24 @@ namespace gsd{
|
|
hepuloginMsg.objectToJson(msg);
|
|
hepuloginMsg.objectToJson(msg);
|
|
msg += "\r\n";
|
|
msg += "\r\n";
|
|
|
|
|
|
- cout<<"login json msg: "<<endl;
|
|
|
|
- cout<<msg<<endl;
|
|
|
|
|
|
+ //cout<<"login json msg: "<<endl;
|
|
|
|
+ //cout<<msg<<endl;
|
|
|
|
|
|
if(auto res = m_hepu->Post("/cgi-bin/proc.cgi", msg,"application/json")){
|
|
if(auto res = m_hepu->Post("/cgi-bin/proc.cgi", msg,"application/json")){
|
|
- cout<<res->body<<endl;
|
|
|
|
|
|
+ //cout<<res->body<<endl;
|
|
if(res->status != 100){
|
|
if(res->status != 100){
|
|
HepuLoginRe hepuloginReMsg;
|
|
HepuLoginRe hepuloginReMsg;
|
|
if(!hepuloginReMsg.jsonToObject(res->body)){
|
|
if(!hepuloginReMsg.jsonToObject(res->body)){
|
|
- cout<<"login res json2object fail."<<endl;
|
|
|
|
|
|
+ //cout<<"login res json2object fail."<<endl;
|
|
return ERR;
|
|
return ERR;
|
|
}
|
|
}
|
|
if(hepuloginReMsg.ackvalue != 100){
|
|
if(hepuloginReMsg.ackvalue != 100){
|
|
- cout<<"login res ack err: "<<hepuloginReMsg.ackvalue<<endl;
|
|
|
|
|
|
+ //cout<<"login res ack err: "<<hepuloginReMsg.ackvalue<<endl;
|
|
return ERR;
|
|
return ERR;
|
|
}
|
|
}
|
|
if(hepuloginReMsg.token.size()){
|
|
if(hepuloginReMsg.token.size()){
|
|
this->token_ = hepuloginReMsg.token;
|
|
this->token_ = hepuloginReMsg.token;
|
|
- cout<<"login res token: "<<hepuloginReMsg.token<<endl;
|
|
|
|
|
|
+ //cout<<"login res token: "<<hepuloginReMsg.token<<endl;
|
|
return OK;
|
|
return OK;
|
|
}
|
|
}
|
|
return ERR;
|
|
return ERR;
|
|
@@ -79,7 +82,7 @@ namespace gsd{
|
|
return ERR;
|
|
return ERR;
|
|
}else{
|
|
}else{
|
|
auto err = res.error();
|
|
auto err = res.error();
|
|
- cout<<"The Hepu is not avaliable, "<<err<<endl;
|
|
|
|
|
|
+ //cout<<"The Hepu is not avaliable, "<<err<<endl;
|
|
ErrorL << "The service is not available,"<<err<<endl;
|
|
ErrorL << "The service is not available,"<<err<<endl;
|
|
return ERR;
|
|
return ERR;
|
|
}
|
|
}
|
|
@@ -98,15 +101,15 @@ namespace gsd{
|
|
hepuGetSaltMsg.objectToJson(msg);
|
|
hepuGetSaltMsg.objectToJson(msg);
|
|
msg+="\r\n";
|
|
msg+="\r\n";
|
|
|
|
|
|
- cout<<"get salt json msg: "<<endl;
|
|
|
|
- cout<<msg<<endl;
|
|
|
|
|
|
+ //cout<<"get salt json msg: "<<endl;
|
|
|
|
+ //cout<<msg<<endl;
|
|
|
|
|
|
if(auto res = m_hepu->Post("/cgi-bin/proc.cgi", msg,"application/json")){
|
|
if(auto res = m_hepu->Post("/cgi-bin/proc.cgi", msg,"application/json")){
|
|
- cout<<res->body<<endl;
|
|
|
|
|
|
+ //cout<<res->body<<endl;
|
|
if(res->status != 100){
|
|
if(res->status != 100){
|
|
HepuGetSaltRe hepuGetSaltReMsg;
|
|
HepuGetSaltRe hepuGetSaltReMsg;
|
|
if(!hepuGetSaltReMsg.jsonToObject(res->body)){
|
|
if(!hepuGetSaltReMsg.jsonToObject(res->body)){
|
|
- cout<<"get salt res json2object fail."<<endl;
|
|
|
|
|
|
+ //cout<<"get salt res json2object fail."<<endl;
|
|
return ERR;
|
|
return ERR;
|
|
}
|
|
}
|
|
this->salt_ = hepuGetSaltReMsg.salt;
|
|
this->salt_ = hepuGetSaltReMsg.salt;
|
|
@@ -115,7 +118,7 @@ namespace gsd{
|
|
return ERR;
|
|
return ERR;
|
|
}else{
|
|
}else{
|
|
auto err = res.error();
|
|
auto err = res.error();
|
|
- cout<<"hepu getsalt failed,"<<err<<endl;
|
|
|
|
|
|
+ //cout<<"hepu getsalt failed,"<<err<<endl;
|
|
ErrorL <<"Hepu getsalt failed,"<<err<<endl;
|
|
ErrorL <<"Hepu getsalt failed,"<<err<<endl;
|
|
return ERR;
|
|
return ERR;
|
|
}
|
|
}
|
|
@@ -131,15 +134,15 @@ namespace gsd{
|
|
hepuGetSaltMsg.objectToJson(msg);
|
|
hepuGetSaltMsg.objectToJson(msg);
|
|
msg+="\r\n";
|
|
msg+="\r\n";
|
|
|
|
|
|
- cout<<"get salt json msg: "<<endl;
|
|
|
|
- cout<<msg<<endl;
|
|
|
|
|
|
+ //cout<<"get salt json msg: "<<endl;
|
|
|
|
+ //cout<<msg<<endl;
|
|
|
|
|
|
if(auto res = m_hepu->Post("/cgi-bin/proc.cgi", msg,"application/json")){
|
|
if(auto res = m_hepu->Post("/cgi-bin/proc.cgi", msg,"application/json")){
|
|
- cout<<res->body<<endl;
|
|
|
|
|
|
+ //cout<<res->body<<endl;
|
|
if(res->status != 100){
|
|
if(res->status != 100){
|
|
HepuGetSaltRe hepuGetSaltReMsg;
|
|
HepuGetSaltRe hepuGetSaltReMsg;
|
|
if(!hepuGetSaltReMsg.jsonToObject(res->body)){
|
|
if(!hepuGetSaltReMsg.jsonToObject(res->body)){
|
|
- cout<<"get salt res json2object fail."<<endl;
|
|
|
|
|
|
+ //cout<<"get salt res json2object fail."<<endl;
|
|
return ERR;
|
|
return ERR;
|
|
}
|
|
}
|
|
this->salt_ = hepuGetSaltReMsg.salt;
|
|
this->salt_ = hepuGetSaltReMsg.salt;
|
|
@@ -148,7 +151,7 @@ namespace gsd{
|
|
return ERR;
|
|
return ERR;
|
|
}else{
|
|
}else{
|
|
auto err = res.error();
|
|
auto err = res.error();
|
|
- cout<<"hepu getsalt failed,"<<err<<endl;
|
|
|
|
|
|
+ //cout<<"hepu getsalt failed,"<<err<<endl;
|
|
ErrorL <<"Hepu getsalt failed,"<<err<<endl;
|
|
ErrorL <<"Hepu getsalt failed,"<<err<<endl;
|
|
return ERR;
|
|
return ERR;
|
|
}
|
|
}
|
|
@@ -163,19 +166,19 @@ namespace gsd{
|
|
hepuHBMsg.objectToJson(msg);
|
|
hepuHBMsg.objectToJson(msg);
|
|
msg+="\r\n";
|
|
msg+="\r\n";
|
|
|
|
|
|
- cout<<"hb json msg: "<<endl;
|
|
|
|
- cout<<msg<<endl;
|
|
|
|
|
|
+ //cout<<"hb json msg: "<<endl;
|
|
|
|
+ //cout<<msg<<endl;
|
|
|
|
|
|
if(auto res = m_hepu->Post("/cgi-bin/proc.cgi", msg,"application/json")){
|
|
if(auto res = m_hepu->Post("/cgi-bin/proc.cgi", msg,"application/json")){
|
|
- cout<<res->body<<endl;
|
|
|
|
|
|
+ //cout<<res->body<<endl;
|
|
if(res->status != 100){
|
|
if(res->status != 100){
|
|
HepuHBRe hepuHBReMsg;
|
|
HepuHBRe hepuHBReMsg;
|
|
if(!hepuHBReMsg.jsonToObject(res->body)){
|
|
if(!hepuHBReMsg.jsonToObject(res->body)){
|
|
- cout<<"hb res json2object fail."<<endl;
|
|
|
|
|
|
+ //cout<<"hb res json2object fail."<<endl;
|
|
return ERR;
|
|
return ERR;
|
|
}
|
|
}
|
|
if(hepuHBReMsg.ackvalue != 100){
|
|
if(hepuHBReMsg.ackvalue != 100){
|
|
- cout<<"hb res ack err: "<<hepuHBReMsg.ackvalue<<endl;
|
|
|
|
|
|
+ //cout<<"hb res ack err: "<<hepuHBReMsg.ackvalue<<endl;
|
|
return ERR;
|
|
return ERR;
|
|
}
|
|
}
|
|
return OK;
|
|
return OK;
|
|
@@ -183,7 +186,7 @@ namespace gsd{
|
|
return ERR;
|
|
return ERR;
|
|
}else{
|
|
}else{
|
|
auto err = res.error();
|
|
auto err = res.error();
|
|
- cout<<"Hepu heartbeat failed,"<<err<<endl;
|
|
|
|
|
|
+ //cout<<"Hepu heartbeat failed,"<<err<<endl;
|
|
ErrorL << "Hepu Heartbeat failed,"<<err<<endl;
|
|
ErrorL << "Hepu Heartbeat failed,"<<err<<endl;
|
|
return ERR;
|
|
return ERR;
|
|
}
|
|
}
|
|
@@ -199,19 +202,19 @@ namespace gsd{
|
|
hepuHBMsg.objectToJson(msg);
|
|
hepuHBMsg.objectToJson(msg);
|
|
msg+="\r\n";
|
|
msg+="\r\n";
|
|
|
|
|
|
- cout<<"hb json msg: "<<endl;
|
|
|
|
- cout<<msg<<endl;
|
|
|
|
|
|
+ //cout<<"hb json msg: "<<endl;
|
|
|
|
+ //cout<<msg<<endl;
|
|
|
|
|
|
if(auto res = m_hepu->Post("/cgi-bin/proc.cgi", msg,"application/json")){
|
|
if(auto res = m_hepu->Post("/cgi-bin/proc.cgi", msg,"application/json")){
|
|
- cout<<res->body<<endl;
|
|
|
|
|
|
+ //cout<<res->body<<endl;
|
|
if(res->status != 100){
|
|
if(res->status != 100){
|
|
HepuHBRe hepuHBReMsg;
|
|
HepuHBRe hepuHBReMsg;
|
|
if(!hepuHBReMsg.jsonToObject(res->body)){
|
|
if(!hepuHBReMsg.jsonToObject(res->body)){
|
|
- cout<<"hb res json2object fail."<<endl;
|
|
|
|
|
|
+ //cout<<"hb res json2object fail."<<endl;
|
|
return ERR;
|
|
return ERR;
|
|
}
|
|
}
|
|
if(hepuHBReMsg.ackvalue != 100){
|
|
if(hepuHBReMsg.ackvalue != 100){
|
|
- cout<<"hb res ack err: "<<hepuHBReMsg.ackvalue<<endl;
|
|
|
|
|
|
+ //cout<<"hb res ack err: "<<hepuHBReMsg.ackvalue<<endl;
|
|
return ERR;
|
|
return ERR;
|
|
}
|
|
}
|
|
return OK;
|
|
return OK;
|
|
@@ -219,7 +222,7 @@ namespace gsd{
|
|
return ERR;
|
|
return ERR;
|
|
}else{
|
|
}else{
|
|
auto err = res.error();
|
|
auto err = res.error();
|
|
- cout<<"Hepu heartbeat failed,"<<err<<endl;
|
|
|
|
|
|
+ //cout<<"Hepu heartbeat failed,"<<err<<endl;
|
|
ErrorL << "Hepu Heartbeat failed,"<<err<<endl;
|
|
ErrorL << "Hepu Heartbeat failed,"<<err<<endl;
|
|
return ERR;
|
|
return ERR;
|
|
}
|
|
}
|
|
@@ -284,4 +287,4 @@ namespace gsd{
|
|
this->port_ = port;
|
|
this->port_ = port;
|
|
}
|
|
}
|
|
|
|
|
|
-}
|
|
|
|
|
|
+}
|