Commit c438f8e9 authored by yangjian's avatar yangjian

modify mysql connect

parent 682df33c
...@@ -107,6 +107,8 @@ function main() ...@@ -107,6 +107,8 @@ function main()
if [[ $install_deps -ne 0 ]]; then if [[ $install_deps -ne 0 ]]; then
apt-get install cmake make libconfig++-dev libspdlog-dev mysql-server mysql-client libmysqlclient-dev phpmyadmin -y apt-get install cmake make libconfig++-dev libspdlog-dev mysql-server mysql-client libmysqlclient-dev phpmyadmin -y
read -p "Do you want to install Nlohmann Json ? <y/N> " prompt
if [[ $prompt =~ [yY](es)* ]]; then
if [ ! -d "$OPENXGUDR_DIR/build/ext/json/build" ]; then if [ ! -d "$OPENXGUDR_DIR/build/ext/json/build" ]; then
mkdir $OPENXGUDR_DIR/build/ext/json/build mkdir $OPENXGUDR_DIR/build/ext/json/build
fi fi
...@@ -114,6 +116,7 @@ function main() ...@@ -114,6 +116,7 @@ function main()
cmake .. cmake ..
make make
make install make install
fi
echo "install successful!" echo "install successful!"
return 0 return 0
fi fi
......
...@@ -14,6 +14,11 @@ ...@@ -14,6 +14,11 @@
#include "AuthenticationStatusDocumentApiImpl.h" #include "AuthenticationStatusDocumentApiImpl.h"
#include "logger.hpp" #include "logger.hpp"
#include "udr_config.hpp"
using namespace config;
extern udr_config udr_cfg;
namespace org { namespace org {
namespace openapitools { namespace openapitools {
namespace server { namespace server {
...@@ -31,6 +36,18 @@ void AuthenticationStatusDocumentApiImpl::create_authentication_status( ...@@ -31,6 +36,18 @@ void AuthenticationStatusDocumentApiImpl::create_authentication_status(
const std::string &ueId, const AuthEvent &authEvent, const std::string &ueId, const AuthEvent &authEvent,
Pistache::Http::ResponseWriter &response) { Pistache::Http::ResponseWriter &response) {
// response.send(Pistache::Http::Code::Ok, "create_authentication_status\n"); // response.send(Pistache::Http::Code::Ok, "create_authentication_status\n");
Logger::udr_server().info("AuthenticationStatus PUT - response->UDM");
response.send(Pistache::Http::Code::No_Content, "");
MYSQL mysqldb;
mysql_init(&mysqldb);
if (!mysql_real_connect(&mysqldb, udr_cfg.mysql.mysql_server.c_str(),udr_cfg.mysql.mysql_user.c_str(),udr_cfg.mysql.mysql_pass.c_str(),udr_cfg.mysql.mysql_db.c_str(), udr_cfg.mysql.mysql_port, 0, 0))
{
Logger::udr_server().error("An error occurred while connecting to db: %s", mysql_error(&mysqldb));
return ;
}
MYSQL_RES *res = NULL; MYSQL_RES *res = NULL;
MYSQL_ROW row; MYSQL_ROW row;
...@@ -39,17 +56,19 @@ void AuthenticationStatusDocumentApiImpl::create_authentication_status( ...@@ -39,17 +56,19 @@ void AuthenticationStatusDocumentApiImpl::create_authentication_status(
std::string query; std::string query;
nlohmann::json j; nlohmann::json j;
if (mysql_real_query(mysql_WitcommUDRDB, select_AuthenticationStatus.c_str(), if (mysql_real_query(&mysqldb, select_AuthenticationStatus.c_str(),
(unsigned long)select_AuthenticationStatus.size())) { (unsigned long)select_AuthenticationStatus.size())) {
Logger::udr_server().error("mysql_real_query failure!SQL(%s)", Logger::udr_server().error("mysql_real_query failure!SQL(%s)",
select_AuthenticationStatus.c_str()); select_AuthenticationStatus.c_str());
mysql_close(&mysqldb);
return; return;
} }
res = mysql_store_result(mysql_WitcommUDRDB); res = mysql_store_result(&mysqldb);
if (res == NULL) { if (res == NULL) {
Logger::udr_server().error("mysql_store_result failure!SQL(%s)", Logger::udr_server().error("mysql_store_result failure!SQL(%s)",
select_AuthenticationStatus.c_str()); select_AuthenticationStatus.c_str());
mysql_close(&mysqldb);
return; return;
} }
if (mysql_num_rows(res)) { if (mysql_num_rows(res)) {
...@@ -82,13 +101,14 @@ void AuthenticationStatusDocumentApiImpl::create_authentication_status( ...@@ -82,13 +101,14 @@ void AuthenticationStatusDocumentApiImpl::create_authentication_status(
} }
mysql_free_result(res); mysql_free_result(res);
if (mysql_real_query(mysql_WitcommUDRDB, query.c_str(), if (mysql_real_query(&mysqldb, query.c_str(),
(unsigned long)query.size())) { (unsigned long)query.size())) {
Logger::udr_server().error("mysql create failure!SQL(%s)", query.c_str()); Logger::udr_server().error("mysql create failure!SQL(%s)", query.c_str());
mysql_close(&mysqldb);
return; return;
} }
response.send(Pistache::Http::Code::No_Content, ""); mysql_close(&mysqldb);
to_json(j, authEvent); to_json(j, authEvent);
Logger::udr_server().debug("AuthenticationStatus PUT - json:\n\"%s\"", Logger::udr_server().debug("AuthenticationStatus PUT - json:\n\"%s\"",
...@@ -98,16 +118,27 @@ void AuthenticationStatusDocumentApiImpl::create_authentication_status( ...@@ -98,16 +118,27 @@ void AuthenticationStatusDocumentApiImpl::create_authentication_status(
void AuthenticationStatusDocumentApiImpl::delete_authentication_status( void AuthenticationStatusDocumentApiImpl::delete_authentication_status(
const std::string &ueId, Pistache::Http::ResponseWriter &response) { const std::string &ueId, Pistache::Http::ResponseWriter &response) {
MYSQL mysqldb;
mysql_init(&mysqldb);
if (!mysql_real_connect(&mysqldb, udr_cfg.mysql.mysql_server.c_str(),udr_cfg.mysql.mysql_user.c_str(),udr_cfg.mysql.mysql_pass.c_str(),udr_cfg.mysql.mysql_db.c_str(), udr_cfg.mysql.mysql_port, 0, 0))
{
Logger::udr_server().error("An error occurred while connecting to db: %s", mysql_error(&mysqldb));
return ;
}
const std::string query = const std::string query =
"DELETE from AuthenticationStatus WHERE ueid='" + ueId + "'"; "DELETE from AuthenticationStatus WHERE ueid='" + ueId + "'";
if (mysql_real_query(mysql_WitcommUDRDB, query.c_str(), if (mysql_real_query(&mysqldb, query.c_str(),
(unsigned long)query.size())) { (unsigned long)query.size())) {
Logger::udr_server().error("mysql_real_query failure!SQL(%s)", Logger::udr_server().error("mysql_real_query failure!SQL(%s)",
query.c_str()); query.c_str());
mysql_close(&mysqldb);
return; return;
} }
mysql_close(&mysqldb);
response.send(Pistache::Http::Code::No_Content, ""); response.send(Pistache::Http::Code::No_Content, "");
Logger::udr_server().debug("AuthenticationStatus DELETE - successful"); Logger::udr_server().debug("AuthenticationStatus DELETE - successful");
} }
...@@ -126,16 +157,28 @@ void AuthenticationStatusDocumentApiImpl::query_authentication_status( ...@@ -126,16 +157,28 @@ void AuthenticationStatusDocumentApiImpl::query_authentication_status(
const std::string query = const std::string query =
"select * from AuthenticationStatus WHERE ueid='" + ueId + "'"; "select * from AuthenticationStatus WHERE ueid='" + ueId + "'";
if (mysql_real_query(mysql_WitcommUDRDB, query.c_str(), MYSQL mysqldb;
mysql_init(&mysqldb);
if (!mysql_real_connect(&mysqldb, udr_cfg.mysql.mysql_server.c_str(),udr_cfg.mysql.mysql_user.c_str(),udr_cfg.mysql.mysql_pass.c_str(),udr_cfg.mysql.mysql_db.c_str(), udr_cfg.mysql.mysql_port, 0, 0))
{
Logger::udr_server().error("An error occurred while connecting to db: %s", mysql_error(&mysqldb));
mysql_close(&mysqldb);
return ;
}
if (mysql_real_query(&mysqldb, query.c_str(),
(unsigned long)query.size())) { (unsigned long)query.size())) {
Logger::udr_server().error("mysql_real_query failure!SQL(%s)", Logger::udr_server().error("mysql_real_query failure!SQL(%s)",
query.c_str()); query.c_str());
mysql_close(&mysqldb);
return; return;
} }
res = mysql_store_result(mysql_WitcommUDRDB); res = mysql_store_result(&mysqldb);
if (res == NULL) { if (res == NULL) {
Logger::udr_server().error("mysql_store_result failure!"); Logger::udr_server().error("mysql_store_result failure!");
mysql_close(&mysqldb);
return; return;
} }
...@@ -176,6 +219,7 @@ void AuthenticationStatusDocumentApiImpl::query_authentication_status( ...@@ -176,6 +219,7 @@ void AuthenticationStatusDocumentApiImpl::query_authentication_status(
} }
mysql_free_result(res); mysql_free_result(res);
mysql_close(&mysqldb);
} }
} // namespace api } // namespace api
......
...@@ -43,6 +43,9 @@ void AuthenticationSubscriptionDocumentApiImpl:: ...@@ -43,6 +43,9 @@ void AuthenticationSubscriptionDocumentApiImpl::
const Pistache::Optional<std::string> &supportedFeatures, const Pistache::Optional<std::string> &supportedFeatures,
Pistache::Http::ResponseWriter &response) { Pistache::Http::ResponseWriter &response) {
Logger::udr_server().info("AuthenticationSubscription PATCH - response->UDM");
response.send(Pistache::Http::Code::No_Content, "");
MYSQL mysqldb; MYSQL mysqldb;
mysql_init(&mysqldb); mysql_init(&mysqldb);
if (!mysql_real_connect(&mysqldb, udr_cfg.mysql.mysql_server.c_str(),udr_cfg.mysql.mysql_user.c_str(),udr_cfg.mysql.mysql_pass.c_str(),udr_cfg.mysql.mysql_db.c_str(), udr_cfg.mysql.mysql_port, 0, 0)) if (!mysql_real_connect(&mysqldb, udr_cfg.mysql.mysql_server.c_str(),udr_cfg.mysql.mysql_user.c_str(),udr_cfg.mysql.mysql_pass.c_str(),udr_cfg.mysql.mysql_db.c_str(), udr_cfg.mysql.mysql_port, 0, 0))
...@@ -108,13 +111,13 @@ void AuthenticationSubscriptionDocumentApiImpl:: ...@@ -108,13 +111,13 @@ void AuthenticationSubscriptionDocumentApiImpl::
return; return;
} }
} }
mysql_close(&mysqldb);
to_json(tmp_j, patchItem[i]); to_json(tmp_j, patchItem[i]);
j += tmp_j; j += tmp_j;
} }
response.send(Pistache::Http::Code::No_Content, ""); mysql_close(&mysqldb);
// response.send(Pistache::Http::Code::No_Content, "");
std::string out = j.dump(); std::string out = j.dump();
Logger::udr_server().debug("AuthenticationSubscription PATCH - json:\n\"%s\"", Logger::udr_server().debug("AuthenticationSubscription PATCH - json:\n\"%s\"",
......
...@@ -53,15 +53,15 @@ int main(int argc, char **argv) { ...@@ -53,15 +53,15 @@ int main(int argc, char **argv) {
Pistache::Address addr(udr_cfg.sbi.addr4, Pistache::Port(udr_cfg.sbi.port)); Pistache::Address addr(udr_cfg.sbi.addr4, Pistache::Port(udr_cfg.sbi.port));
MYSQL mysql; MYSQL mysql;
mysql_init(&mysql); // mysql_init(&mysql);
if (!mysql_real_connect(&mysql, udr_cfg.mysql.mysql_server.c_str(), // if (!mysql_real_connect(&mysql, udr_cfg.mysql.mysql_server.c_str(),
udr_cfg.mysql.mysql_user.c_str(), // udr_cfg.mysql.mysql_user.c_str(),
udr_cfg.mysql.mysql_pass.c_str(), // udr_cfg.mysql.mysql_pass.c_str(),
udr_cfg.mysql.mysql_db.c_str(), udr_cfg.mysql.mysql_port, 0, 0)) { // udr_cfg.mysql.mysql_db.c_str(), udr_cfg.mysql.mysql_port, 0, 0)) {
Logger::udr_app().error("An error occurred while connecting to db: %s", // Logger::udr_app().error("An error occurred while connecting to db: %s",
mysql_error(&mysql)); // mysql_error(&mysql));
return 0; // return 0;
} // }
UDRApiServer udrApiServer(addr, &mysql); UDRApiServer udrApiServer(addr, &mysql);
udrApiServer.init(PISTACHE_SERVER_THREADS); udrApiServer.init(PISTACHE_SERVER_THREADS);
...@@ -69,6 +69,6 @@ int main(int argc, char **argv) { ...@@ -69,6 +69,6 @@ int main(int argc, char **argv) {
Logger::udr_app().debug("Initiating Done!"); Logger::udr_app().debug("Initiating Done!");
pause(); pause();
mysql_close(&mysql); // mysql_close(&mysql);
return 0; return 0;
} }
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