Commit c438f8e9 authored by yangjian's avatar yangjian

modify mysql connect

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