/
netrc.hpp
65 lines (53 loc) · 1.29 KB
/
netrc.hpp
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
#ifndef NETRC_HPP
#define NETRC_HPP
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <map>
// https://en.cppreference.com/w/cpp/feature_test
#ifdef __has_include
# if __has_include(<filesystem>)
# include <filesystem> // gcc8 (Fedora29+)
# elif __has_include(<experimental/filesystem>)
# include <experimental/filesystem> // gcc7 (Ubuntu 18.04)
# endif
#else
#error no __has_include
#endif
// key: machine's value
// value: tuple of login,password,account
// (account is optional)
using netrc_map = std::map<std::string, std::tuple<std::string, std::string, std::string>>;
class parse_error : public std::exception
{
public:
parse_error (std::string& failure) noexcept
{
this->line_failed = failure;
}
virtual const char* what() const throw()
{
return this->line_failed.c_str();
}
private:
std::string line_failed;
};
class file_error : public std::exception
{
public:
file_error (const std::string& netrc_filename) noexcept
{
this->filename = netrc_filename;
}
virtual const char *what() const throw()
{
return this->filename.c_str();
}
private:
std::string filename;
};
netrc_map netrc_parse(std::istream& infile);
netrc_map netrc_parse_file(const std::string& infilename);
netrc_map netrc_parse_default_file(void);
#endif