-
Notifications
You must be signed in to change notification settings - Fork 29
/
profiles.cpp
45 lines (37 loc) · 1.5 KB
/
profiles.cpp
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
#include "dpitunnel-cli.h"
#include "profiles.h"
#include "utils.h"
#include <iostream>
#include <algorithm>
// Map contains net interface name to that apply profile and profile settings
std::map<std::string, struct Profile_s> Profiles;
extern struct Profile_s Profile;
void add_profile(std::string name, Profile_s profile) {
Profiles[name] = profile;
}
int change_profile(const std::string &iface, const std::string &wifi_ap,
std::string *choosen_profile_name /*= NULL*/) {
if (Profiles.empty())
return 0;
auto search = std::find_if(Profiles.begin(), Profiles.end(),
[iface, wifi_ap](const auto &element) -> bool {
return wildcard_match(element.first.c_str(), (iface +
(wifi_ap.empty()
? "" : (':' +
wifi_ap))).c_str());
});
if (search != Profiles.end())
Profile = search->second;
else {
search = Profiles.find("default");
if (search != Profiles.end())
Profile = search->second;
else {
std::cerr << "Failed to find profile" << std::endl;
return -1;
}
}
if (choosen_profile_name != NULL)
*choosen_profile_name = search->first;
return 0;
}