file.cpp
#include "iostream"
#include "CAuthorization.h"
#include "CAuthorizationXMLVisitor.h"
using namespace std;
using namespace tinyxml2;
using namespace Authorization;
vector <auth_handle> clients;
CAuthorization userInformation;
int auth_init(auth_handle** handle)
{
if (*handle == nullptr)
{
CAuthorizationData* data = new CAuthorizationData;
userInformation.Load("auth.xml");
*data = userInformation.Data();
auth_handle *data_ = new auth_handle{};
data_->mem = (void *)data;
clients.push_back(*data_);
char login [20];
char password [20];
int result=auth_checkpasswd(data_,login,password);
printf("login: %s\n",login);
printf("password:%s\n",password);
*handle = data_;
}
return 0;
}
auth_checkpasswd(auth_handle* handle, char* login, char* passwd)
{
for (const auto &User: userInformation.Data().users)
{
cout << "Login" << User.login << endl;
cout << "Password" << User.password << endl;
}
}
CAuthorizationData.h
#ifndef CAUTHORIZATIONDATA_H
#define CAUTHORIZATIONDATA_H
#include <string>
#include <vector>
namespace Authorization
{
struct CAuthorizationData
{
struct CUserData
{
std::string _name;
std::string _login;
std::string _password;
enum class RolesType
{
_none,
_viewer,
_operator,
_engineer,
_installer
};
std::vector<RolesType> _roles;
};
std::vector<CUserData> _users;
};
}
#endif // CSETTINGSDATA_H
Знаю С++ на 2. Помогите в функции auth_checkpasswd(auth_handle* handle, char* login, char* passwd) вывести только логины и пароли, полученные из xml файла в функции int auth_init(auth_handle** handle) и записанные в data_.
auth.xml
<?xml version="1.0" encoding="UTF-8"?>
<authorization>
<user name="user1" login="login1" password="password1">
<role type="viewer"/>
<role type="engineer"/>
<role type="operator"/>
</user>
<user name="user2" login="login2" password="password2">
<role type="operator"/>
</user>
<user name="user3" login="login3" password="password3">
<role type="engineer"/>
</user>
<user name="user4" login="login4" password="password4">
<role type="installer"/>
<role type="unknown"/>
</user>
</authorization>