AuthenticationStatusDocumentApiImpl.cpp 6.3 KB
Newer Older
yangjian's avatar
add udr  
yangjian committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* Nudr_DataRepository API OpenAPI file
* Unified Data Repository Service. © 2020, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved.
*
* The version of the OpenAPI document: 2.1.2
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/

#include "AuthenticationStatusDocumentApiImpl.h"
#include "logger.hpp"

namespace org {
namespace openapitools {
namespace server {
namespace api {

using namespace org::openapitools::server::model;

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;
    nlohmann::json j;

    if (mysql_real_query(mysql_WitcommUDRDB,select_AuthenticationStatus.c_str(), (unsigned long)select_AuthenticationStatus.size()))
    {
        Logger::udr_server().error("mysql_real_query failure!SQL(%s)",select_AuthenticationStatus);
        return;
    }

    res = mysql_store_result(mysql_WitcommUDRDB);
    if(res == NULL)
    {
        Logger::udr_server().error("mysql_store_result failure!SQL(%s)",select_AuthenticationStatus);
        return;
    }
    if (mysql_num_rows(res))
    {
        query="update AuthenticationStatus set nfInstanceId='"+authEvent.getNfInstanceId()+"'"+ \
            ",success="+(authEvent.isSuccess()?"1":"0")+ \
            ",timeStamp='"+authEvent.getTimeStamp()+"'"+ \
            ",servingNetworkName='"+authEvent.getServingNetworkName()+"'"+ \
            (authEvent.authRemovalIndIsSet()?(authEvent.isAuthRemovalInd()?",authRemovalInd=1":",authRemovalInd=0"):"");
        to_json(j,authEvent.getAuthType());
        query += ",authType='"+j.dump()+"'";
        query += " where ueid='"+ueId+"'";
    }
    else
    {
        query="insert into AuthenticationStatus set ueid='"+ueId+"'"+ \
            ",nfInstanceId='"+authEvent.getNfInstanceId()+"'"+ \
            ",success="+(authEvent.isSuccess()?"1":"0")+ \
            ",timeStamp='"+authEvent.getTimeStamp()+"'"+ \
            ",servingNetworkName='"+authEvent.getServingNetworkName()+"'"+ \
            (authEvent.authRemovalIndIsSet()?(authEvent.isAuthRemovalInd()?",authRemovalInd=1":",authRemovalInd=0"):"");
        to_json(j,authEvent.getAuthType());
        query += ",authType='"+j.dump()+"'";
    }

    mysql_free_result(res);
    if (mysql_real_query(mysql_WitcommUDRDB,query.c_str(), (unsigned long)query.size()))
    {
yangjian's avatar
yangjian committed
75
        Logger::udr_server().error("mysql create failure!");
yangjian's avatar
add udr  
yangjian committed
76
77
78
        return;
    }

yangjian's avatar
yangjian committed
79
80
81
82
    to_json(j,authEvent);
    std::string out = j.dump();
    Logger::udr_server().debug("AuthenticationSubscription PATCH - json:\n\"%s\"",out.c_str());

yangjian's avatar
add udr  
yangjian committed
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
    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) {
    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))
            {
                AuthType authtype;
                nlohmann::json::parse(row[i]).get_to(authtype);
                authenticationstatus.setAuthType(authtype);
            }
            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());

        std::string out = j.dump();
        Logger::udr_server().debug("AuthenticationStatus GET - json:\n\"%s\"",out.c_str());
    }
    else
    {
        std::cout << "AuthenticationStatus no data!" << std::endl;
    }

    mysql_free_result(res);
}


}
}
}
}