Commit 7427dad0 authored by yangjian's avatar yangjian

Update AuthenticationSubscription: add database

parent 4cf68dd5
...@@ -34,4 +34,4 @@ file(GLOB SRCS ...@@ -34,4 +34,4 @@ file(GLOB SRCS
add_executable(${PROJECT_NAME} ${SRCS} ) add_executable(${PROJECT_NAME} ${SRCS} )
add_dependencies(${PROJECT_NAME} PISTACHE NLOHMANN) add_dependencies(${PROJECT_NAME} PISTACHE NLOHMANN)
target_link_libraries(${PROJECT_NAME} pistache pthread) target_link_libraries(${PROJECT_NAME} pistache pthread mysqlclient)
...@@ -81,9 +81,9 @@ void AuthenticationSubscriptionDocumentApi::read_authentication_subscription_han ...@@ -81,9 +81,9 @@ void AuthenticationSubscriptionDocumentApi::read_authentication_subscription_han
{ {
// Getting the path params // Getting the path params
auto ueId = request.param(":ueId").as<std::string>(); auto ueId = request.param(":ueId").as<std::string>();
std::cout<<"***** ueId ("<<ueId<<")******"<<std::endl; // std::cout<<"***** ueId ("<<ueId<<")******"<<std::endl;
//
std::cout<<"***** request.body() ("<<request.body()<<")******"<<std::endl; // std::cout<<"***** request.body() ("<<request.body()<<")******"<<std::endl;
// Getting the query params // Getting the query params
auto supportedFeaturesQuery = request.query().get("supported-features"); auto supportedFeaturesQuery = request.query().get("supported-features");
......
...@@ -13,6 +13,10 @@ ...@@ -13,6 +13,10 @@
#include "AuthenticationSubscriptionDocumentApiImpl.h" #include "AuthenticationSubscriptionDocumentApiImpl.h"
#include "PatchResult.h" #include "PatchResult.h"
#include <AuthenticationSubscription.h>
namespace org { namespace org {
namespace openapitools { namespace openapitools {
namespace server { namespace server {
...@@ -20,9 +24,12 @@ namespace api { ...@@ -20,9 +24,12 @@ namespace api {
using namespace org::openapitools::server::model; using namespace org::openapitools::server::model;
AuthenticationSubscriptionDocumentApiImpl::AuthenticationSubscriptionDocumentApiImpl(std::shared_ptr<Pistache::Rest::Router> rtr) AuthenticationSubscriptionDocumentApiImpl::AuthenticationSubscriptionDocumentApiImpl(std::shared_ptr<Pistache::Rest::Router> rtr,MYSQL *mysql)
: AuthenticationSubscriptionDocumentApi(rtr) : AuthenticationSubscriptionDocumentApi(rtr)
{ } {
mysql_WitcommUDRDB = mysql;
}
void AuthenticationSubscriptionDocumentApiImpl::modify_authentication_subscription(const std::string &ueId, const std::vector<PatchItem> &patchItem, const Pistache::Optional<std::string> &supportedFeatures, Pistache::Http::ResponseWriter &response) { void AuthenticationSubscriptionDocumentApiImpl::modify_authentication_subscription(const std::string &ueId, const std::vector<PatchItem> &patchItem, const Pistache::Optional<std::string> &supportedFeatures, Pistache::Http::ResponseWriter &response) {
...@@ -46,16 +53,94 @@ void AuthenticationSubscriptionDocumentApiImpl::modify_authentication_subscripti ...@@ -46,16 +53,94 @@ void AuthenticationSubscriptionDocumentApiImpl::modify_authentication_subscripti
void AuthenticationSubscriptionDocumentApiImpl::read_authentication_subscription(const std::string &ueId, const Pistache::Optional<std::string> &supportedFeatures, Pistache::Http::ResponseWriter &response) void AuthenticationSubscriptionDocumentApiImpl::read_authentication_subscription(const std::string &ueId, const Pistache::Optional<std::string> &supportedFeatures, Pistache::Http::ResponseWriter &response)
{ {
MYSQL_RES *res = NULL;
MYSQL_ROW row;
MYSQL_FIELD* field = nullptr;
/************************ test ************************/ nlohmann::json j;
response.send(Pistache::Http::Code::Ok, "read_authentication_subscription");
//response.send(Pistache::Http::Code::Ok, "Do some magic hello\n");
/******************************************************/
//1.read handler database AuthenticationSubscription authenticationsubscription;
//2.send data const std::string query = "select * from AuthenticationSubscription WHERE ueid="+ueId;
//response.send(Pistache::Http::Code::Ok, j.dump());
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);
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());
mysql_free_result(res);
} }
......
...@@ -35,6 +35,8 @@ ...@@ -35,6 +35,8 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <mysql/mysql.h>
namespace org { namespace org {
namespace openapitools { namespace openapitools {
namespace server { namespace server {
...@@ -44,12 +46,15 @@ using namespace org::openapitools::server::model; ...@@ -44,12 +46,15 @@ using namespace org::openapitools::server::model;
class AuthenticationSubscriptionDocumentApiImpl : public org::openapitools::server::api::AuthenticationSubscriptionDocumentApi { class AuthenticationSubscriptionDocumentApiImpl : public org::openapitools::server::api::AuthenticationSubscriptionDocumentApi {
public: public:
AuthenticationSubscriptionDocumentApiImpl(std::shared_ptr<Pistache::Rest::Router>); AuthenticationSubscriptionDocumentApiImpl(std::shared_ptr<Pistache::Rest::Router>,MYSQL *mysql);
~AuthenticationSubscriptionDocumentApiImpl() {} ~AuthenticationSubscriptionDocumentApiImpl() {}
void modify_authentication_subscription(const std::string &ueId, const std::vector<PatchItem> &patchItem, const Pistache::Optional<std::string> &supportedFeatures, Pistache::Http::ResponseWriter &response); void modify_authentication_subscription(const std::string &ueId, const std::vector<PatchItem> &patchItem, const Pistache::Optional<std::string> &supportedFeatures, Pistache::Http::ResponseWriter &response);
void read_authentication_subscription(const std::string &ueId, const Pistache::Optional<std::string> &supportedFeatures, Pistache::Http::ResponseWriter &response); void read_authentication_subscription(const std::string &ueId, const Pistache::Optional<std::string> &supportedFeatures, Pistache::Http::ResponseWriter &response);
private:
MYSQL *mysql_WitcommUDRDB;
}; };
} }
......
...@@ -106,6 +106,8 @@ ...@@ -106,6 +106,8 @@
#include "UsageMonitoringInformationDocumentApiImpl.h" #include "UsageMonitoringInformationDocumentApiImpl.h"
#include "V2XSubscriptionDataApiImpl.h" #include "V2XSubscriptionDataApiImpl.h"
#include <mysql/mysql.h>
#define PISTACHE_SERVER_THREADS 2 #define PISTACHE_SERVER_THREADS 2
#define PISTACHE_SERVER_MAX_REQUEST_SIZE 32768 #define PISTACHE_SERVER_MAX_REQUEST_SIZE 32768
#define PISTACHE_SERVER_MAX_RESPONSE_SIZE 32768 #define PISTACHE_SERVER_MAX_RESPONSE_SIZE 32768
...@@ -160,6 +162,14 @@ int main() { ...@@ -160,6 +162,14 @@ int main() {
opts.maxResponseSize(PISTACHE_SERVER_MAX_RESPONSE_SIZE); opts.maxResponseSize(PISTACHE_SERVER_MAX_RESPONSE_SIZE);
httpEndpoint->init(opts); httpEndpoint->init(opts);
MYSQL mysql;
mysql_init(&mysql);
if (!mysql_real_connect(&mysql, "127.0.0.1","yunshou", "123456", "Witcomm-UDR-DB", 0, 0, 0))
{
std::cout << "mysql_real_connect failure!"<< std::endl;
return 0;
}
AMF3GPPAccessRegistrationDocumentApiImpl AMF3GPPAccessRegistrationDocumentApiserver(router); AMF3GPPAccessRegistrationDocumentApiImpl AMF3GPPAccessRegistrationDocumentApiserver(router);
AMF3GPPAccessRegistrationDocumentApiserver.init(); AMF3GPPAccessRegistrationDocumentApiserver.init();
...@@ -179,7 +189,7 @@ int main() { ...@@ -179,7 +189,7 @@ int main() {
AuthenticationSoRDocumentApiserver.init(); AuthenticationSoRDocumentApiserver.init();
AuthenticationStatusDocumentApiImpl AuthenticationStatusDocumentApiserver(router); AuthenticationStatusDocumentApiImpl AuthenticationStatusDocumentApiserver(router);
AuthenticationStatusDocumentApiserver.init(); AuthenticationStatusDocumentApiserver.init();
AuthenticationSubscriptionDocumentApiImpl AuthenticationSubscriptionDocumentApiserver(router); AuthenticationSubscriptionDocumentApiImpl AuthenticationSubscriptionDocumentApiserver(router,&mysql);
AuthenticationSubscriptionDocumentApiserver.init(); AuthenticationSubscriptionDocumentApiserver.init();
AuthenticationUPUDocumentApiImpl AuthenticationUPUDocumentApiserver(router); AuthenticationUPUDocumentApiImpl AuthenticationUPUDocumentApiserver(router);
AuthenticationUPUDocumentApiserver.init(); AuthenticationUPUDocumentApiserver.init();
...@@ -336,6 +346,7 @@ int main() { ...@@ -336,6 +346,7 @@ int main() {
httpEndpoint->serve(); httpEndpoint->serve();
httpEndpoint->shutdown(); httpEndpoint->shutdown();
mysql_close(&mysql);
} }
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