1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 08:47:17 +01:00
SqMod/vendor/CPR/include/cpr/proxyauth.h

52 lines
1.6 KiB
C
Raw Normal View History

2021-07-02 16:44:48 +02:00
#ifndef CPR_PROXYAUTH_H
#define CPR_PROXYAUTH_H
#include <initializer_list>
#include <map>
#include <string>
2021-07-02 16:44:48 +02:00
#include "cpr/auth.h"
#include "cpr/util.h"
namespace cpr {
class ProxyAuthentication;
2021-07-02 16:44:48 +02:00
class EncodedAuthentication {
friend ProxyAuthentication;
2021-07-02 16:44:48 +02:00
public:
EncodedAuthentication() = default;
EncodedAuthentication(const std::string& p_username, const std::string& p_password) : username(util::urlEncode(p_username)), password(util::urlEncode(p_password)) {}
2021-07-02 16:44:48 +02:00
EncodedAuthentication(const EncodedAuthentication& other) = default;
EncodedAuthentication(EncodedAuthentication&& old) noexcept = default;
virtual ~EncodedAuthentication() noexcept;
2021-07-02 16:44:48 +02:00
EncodedAuthentication& operator=(EncodedAuthentication&& old) noexcept = default;
EncodedAuthentication& operator=(const EncodedAuthentication& other) = default;
[[nodiscard]] const std::string& GetUsername() const;
[[nodiscard]] const std::string& GetPassword() const;
2021-07-02 16:44:48 +02:00
private:
std::string username;
std::string password;
2021-07-02 16:44:48 +02:00
};
class ProxyAuthentication {
public:
ProxyAuthentication() = default;
ProxyAuthentication(const std::initializer_list<std::pair<const std::string, EncodedAuthentication>>& auths) : proxyAuth_{auths} {}
explicit ProxyAuthentication(const std::map<std::string, EncodedAuthentication>& auths) : proxyAuth_{auths} {}
2021-07-02 16:44:48 +02:00
[[nodiscard]] bool has(const std::string& protocol) const;
const char* GetUsername(const std::string& protocol);
const char* GetPassword(const std::string& protocol);
2021-07-02 16:44:48 +02:00
private:
std::map<std::string, EncodedAuthentication> proxyAuth_;
};
} // namespace cpr
#endif