Commit 717b2796 authored by yangjian's avatar yangjian

update AuthenticationStatus: add database

parent 7427dad0
......@@ -50,7 +50,10 @@ void AuthenticationStatusDocumentApi::create_authentication_status_handler(const
// Getting the body param
AuthEvent authEvent;
//std::cout << request.body() << std::endl;
try {
nlohmann::json::parse(request.body()).get_to(authEvent);
this->create_authentication_status(ueId, authEvent, response);
......
......@@ -19,21 +19,135 @@ namespace api {
using namespace org::openapitools::server::model;
AuthenticationStatusDocumentApiImpl::AuthenticationStatusDocumentApiImpl(std::shared_ptr<Pistache::Rest::Router> rtr)
AuthenticationStatusDocumentApiImpl::AuthenticationStatusDocumentApiImpl(std::shared_ptr<Pistache::Rest::Router> rtr,MYSQL *mysql)
: AuthenticationStatusDocumentApi(rtr)
{ }
{
mysql_WitcommUDRDB = mysql;
}
void AuthenticationStatusDocumentApiImpl::create_authentication_status(const std::string &ueId, const AuthEvent &authEvent, Pistache::Http::ResponseWriter &response) {
//response.send(Pistache::Http::Code::Ok, "create_authentication_status\n");
MYSQL_RES *res = NULL;
MYSQL_ROW row;
const std::string select_AuthenticationStatus = "select * from AuthenticationStatus WHERE ueid="+ueId;
std::string query;
if (mysql_real_query(mysql_WitcommUDRDB,select_AuthenticationStatus.c_str(), (unsigned long)select_AuthenticationStatus.size()))
{
std::cout << "mysql_real_query failure!" << std::endl;
return;
}
res = mysql_store_result(mysql_WitcommUDRDB);
if(res == NULL)
{
std::cout << "mysql_store_result failure!" << std::endl;
return;
}
if (mysql_num_rows(res))
{
query="update AuthenticationStatus set nfInstanceId="+authEvent.getNfInstanceId()+",success="+(authEvent.isSuccess()?"1":"0")+",timeStamp="+authEvent.getTimeStamp()+",servingNetworkName="+authEvent.getServingNetworkName()+",authRemovalInd="+ \
(authEvent.authRemovalIndIsSet()?authEvent.isAuthRemovalInd()?"1":"0":"")+" where ueid="+ueId;
}
else
{
query="insert into AuthenticationStatus(ueid,nfInstanceId,success,timeStamp,servingNetworkName,authRemovalInd) values("+ueId+","+ \
authEvent.getNfInstanceId()+","+(authEvent.isSuccess()?"1":"0")+","+authEvent.getTimeStamp()+","+authEvent.getServingNetworkName()+","+(authEvent.authRemovalIndIsSet()?(authEvent.isAuthRemovalInd()?"1":"0"):"")+")";
}
mysql_free_result(res);
//std::cout << query << std::endl;
if (mysql_real_query(mysql_WitcommUDRDB,query.c_str(), (unsigned long)query.size()))
{
std::cout << "mysql_real_query failure!" << std::endl;
return;
}
response.send(Pistache::Http::Code::No_Content, "");
}
void AuthenticationStatusDocumentApiImpl::delete_authentication_status(const std::string &ueId, Pistache::Http::ResponseWriter &response) {
//response.send(Pistache::Http::Code::Ok, "delete_authentication_status\n");
const std::string query = "DELETE from AuthenticationStatus WHERE ueid="+ueId;
if (mysql_real_query(mysql_WitcommUDRDB,query.c_str(), (unsigned long)query.size()))
{
std::cout << "mysql_real_query failure!" << std::endl;
return;
}
response.send(Pistache::Http::Code::No_Content, "");
}
void AuthenticationStatusDocumentApiImpl::query_authentication_status(const std::string &ueId, const Pistache::Optional<std::vector<std::string>> &fields, const Pistache::Optional<std::string> &supportedFeatures, Pistache::Http::ResponseWriter &response) {
response.send(Pistache::Http::Code::Ok, "query_authentication_status\n");
MYSQL_RES *res = NULL;
MYSQL_ROW row;
MYSQL_FIELD* field = nullptr;
nlohmann::json j;
AuthEvent authenticationstatus;
const std::string query = "select * from AuthenticationStatus WHERE ueid="+ueId;
if (mysql_real_query(mysql_WitcommUDRDB,query.c_str(), (unsigned long)query.size()))
{
std::cout << "mysql_real_query failure!" << std::endl;
return;
}
res = mysql_store_result(mysql_WitcommUDRDB);
if(res == NULL)
{
std::cout << "mysql_store_result failure!" << std::endl;
return;
}
row = mysql_fetch_row(res);
if(row != NULL)
{
for (int i = 0; field = mysql_fetch_field(res); i++)
{
if(!strcmp("nfInstanceId", field->name))
{
authenticationstatus.setNfInstanceId(row[i]);
}
else if(!strcmp("success", field->name))
{
if(strcmp(row[i], "0"))
authenticationstatus.setSuccess(true);
else
authenticationstatus.setSuccess(false);
}
else if(!strcmp("timeStamp", field->name))
{
authenticationstatus.setTimeStamp(row[i]);
}
else if(!strcmp("authType", field->name))
{
//authenticationstatus.setAuthType(row[i]);
}
else if(!strcmp("servingNetworkName", field->name))
{
authenticationstatus.setServingNetworkName(row[i]);
}
else if(!strcmp("authRemovalInd", field->name) && row[i] != NULL)
{
if(strcmp(row[i], "0"))
authenticationstatus.setAuthRemovalInd(true);
else
authenticationstatus.setAuthRemovalInd(false);
}
}
to_json(j,authenticationstatus);
response.send(Pistache::Http::Code::Ok, j.dump());
}
else
{
std::cout << "AuthenticationStatus no data!" << std::endl;
}
mysql_free_result(res);
}
......
......@@ -32,6 +32,8 @@
#include "AuthEvent.h"
#include <string>
#include <mysql/mysql.h>
namespace org {
namespace openapitools {
namespace server {
......@@ -41,7 +43,7 @@ using namespace org::openapitools::server::model;
class AuthenticationStatusDocumentApiImpl : public org::openapitools::server::api::AuthenticationStatusDocumentApi {
public:
AuthenticationStatusDocumentApiImpl(std::shared_ptr<Pistache::Rest::Router>);
AuthenticationStatusDocumentApiImpl(std::shared_ptr<Pistache::Rest::Router>,MYSQL *mysql);
~AuthenticationStatusDocumentApiImpl() {}
void create_authentication_status(const std::string &ueId, const AuthEvent &authEvent, Pistache::Http::ResponseWriter &response);
......@@ -49,6 +51,8 @@ public:
void delete_authentication_status(const std::string &ueId, Pistache::Http::ResponseWriter &response);
void query_authentication_status(const std::string &ueId, const Pistache::Optional<std::vector<std::string>> &fields, const Pistache::Optional<std::string> &supportedFeatures, Pistache::Http::ResponseWriter &response);
private:
MYSQL *mysql_WitcommUDRDB;
};
}
......
......@@ -67,6 +67,7 @@ void AuthenticationSubscriptionDocumentApiImpl::read_authentication_subscription
std::cout << "mysql_real_query failure!" << std::endl;
return;
}
std::cout << "mysql_real_query successful!" << std::endl;
res = mysql_store_result(mysql_WitcommUDRDB);
if(res == NULL)
......@@ -77,68 +78,75 @@ void AuthenticationSubscriptionDocumentApiImpl::read_authentication_subscription
row = mysql_fetch_row(res);
for (int i = 0; field = mysql_fetch_field(res); i++)
{
if(!strcmp("authenticationMethod", field->name))
{
//authenticationsubscription.setAuthenticationMethod((AuthMethod) row[i]);
}
else if(!strcmp("encPermanentKey", field->name))
{
authenticationsubscription.setEncPermanentKey(row[i]);
}
else if(!strcmp("protectionParameterId", field->name))
{
authenticationsubscription.setProtectionParameterId(row[i]);
}
else if(!strcmp("sequenceNumber", field->name))
{
//authenticationsubscription.setSequenceNumber((SequenceNumber) row[i]);
}
else if(!strcmp("authenticationManagementField", field->name))
{
authenticationsubscription.setAuthenticationManagementField(row[i]);
}
else if(!strcmp("algorithmId", field->name))
{
authenticationsubscription.setAlgorithmId(row[i]);
}
else if(!strcmp("encOpcKey", field->name))
{
authenticationsubscription.setEncOpcKey(row[i]);
}
else if(!strcmp("encTopcKey", field->name))
{
authenticationsubscription.setEncTopcKey(row[i]);
}
else if(!strcmp("vectorGenerationInHss", field->name))
{
std::cout<<row[i]<<std::endl;
if(strcmp(row[i], "0"))
authenticationsubscription.setVectorGenerationInHss(true);
else
authenticationsubscription.setVectorGenerationInHss(false);
}
else if(!strcmp("n5gcAuthMethod", field->name))
{
//authenticationsubscription.setN5gcAuthMethod(AuthMethod const & value);
}
else if(!strcmp("rgAuthenticationInd", field->name))
{
std::cout<<row[i]<<std::endl;
if(strcmp(row[i], "0"))
authenticationsubscription.setRgAuthenticationInd(true);
else
authenticationsubscription.setRgAuthenticationInd(false);
}
else if(!strcmp("supi", field->name))
{
authenticationsubscription.setSupi(row[i]);
}
}
to_json(j,authenticationsubscription);
response.send(Pistache::Http::Code::Ok, j.dump());
if(row != NULL)
{
for (int i = 0; field = mysql_fetch_field(res); i++)
{
if(!strcmp("authenticationMethod", field->name))
{
//authenticationsubscription.setAuthenticationMethod((AuthMethod) row[i]);
}
else if(!strcmp("encPermanentKey", field->name))
{
authenticationsubscription.setEncPermanentKey(row[i]);
}
else if(!strcmp("protectionParameterId", field->name))
{
authenticationsubscription.setProtectionParameterId(row[i]);
}
else if(!strcmp("sequenceNumber", field->name))
{
//authenticationsubscription.setSequenceNumber((SequenceNumber) row[i]);
}
else if(!strcmp("authenticationManagementField", field->name))
{
authenticationsubscription.setAuthenticationManagementField(row[i]);
}
else if(!strcmp("algorithmId", field->name))
{
authenticationsubscription.setAlgorithmId(row[i]);
}
else if(!strcmp("encOpcKey", field->name))
{
authenticationsubscription.setEncOpcKey(row[i]);
}
else if(!strcmp("encTopcKey", field->name))
{
authenticationsubscription.setEncTopcKey(row[i]);
}
else if(!strcmp("vectorGenerationInHss", field->name))
{
std::cout<<row[i]<<std::endl;
if(strcmp(row[i], "0"))
authenticationsubscription.setVectorGenerationInHss(true);
else
authenticationsubscription.setVectorGenerationInHss(false);
}
else if(!strcmp("n5gcAuthMethod", field->name))
{
//authenticationsubscription.setN5gcAuthMethod(AuthMethod const & value);
}
else if(!strcmp("rgAuthenticationInd", field->name))
{
std::cout<<row[i]<<std::endl;
if(strcmp(row[i], "0"))
authenticationsubscription.setRgAuthenticationInd(true);
else
authenticationsubscription.setRgAuthenticationInd(false);
}
else if(!strcmp("supi", field->name))
{
authenticationsubscription.setSupi(row[i]);
}
}
to_json(j,authenticationsubscription);
response.send(Pistache::Http::Code::Ok, j.dump());
}
else
{
std::cout << "AuthenticationSubscription no data!" << std::endl;
}
mysql_free_result(res);
}
......
......@@ -187,7 +187,7 @@ int main() {
ApplicationDataSubscriptionsCollectionApiserver.init();
AuthenticationSoRDocumentApiImpl AuthenticationSoRDocumentApiserver(router);
AuthenticationSoRDocumentApiserver.init();
AuthenticationStatusDocumentApiImpl AuthenticationStatusDocumentApiserver(router);
AuthenticationStatusDocumentApiImpl AuthenticationStatusDocumentApiserver(router,&mysql);
AuthenticationStatusDocumentApiserver.init();
AuthenticationSubscriptionDocumentApiImpl AuthenticationSubscriptionDocumentApiserver(router,&mysql);
AuthenticationSubscriptionDocumentApiserver.init();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment