mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-14 11:49:59 +01:00
Added history of recent SRT hosts
Saving known hosts in settings and validating ip and port in SRT connector for source
This commit is contained in:
99
Settings.cpp
99
Settings.cpp
@@ -52,6 +52,22 @@ XMLElement *save_history(Settings::History &h, const char *nodename, XMLDocument
|
||||
}
|
||||
|
||||
|
||||
XMLElement *save_knownhost(Settings::KnownHosts &h, const char *nodename, XMLDocument &xmlDoc)
|
||||
{
|
||||
XMLElement *pElement = xmlDoc.NewElement( nodename );
|
||||
pElement->SetAttribute("protocol", h.protocol.c_str());
|
||||
for(auto it = h.hosts.cbegin(); it != h.hosts.cend(); ++it) {
|
||||
XMLElement *hostNode = xmlDoc.NewElement("host");
|
||||
XMLText *text = xmlDoc.NewText( it->first.c_str() );
|
||||
hostNode->InsertEndChild( text );
|
||||
hostNode->SetAttribute("port", it->second.c_str());
|
||||
pElement->InsertFirstChild(hostNode);
|
||||
}
|
||||
return pElement;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Settings::Save(uint64_t runtime)
|
||||
{
|
||||
// impose C locale for all app
|
||||
@@ -111,8 +127,6 @@ void Settings::Save(uint64_t runtime)
|
||||
applicationNode->SetAttribute("pannel_history_mode", application.pannel_current_session_mode);
|
||||
applicationNode->SetAttribute("stream_protocol", application.stream_protocol);
|
||||
applicationNode->SetAttribute("broadcast_port", application.broadcast_port);
|
||||
applicationNode->SetAttribute("custom_connect_ip", application.custom_connect_ip.c_str());
|
||||
applicationNode->SetAttribute("custom_connect_port", application.custom_connect_port.c_str());
|
||||
pRoot->InsertEndChild(applicationNode);
|
||||
|
||||
// Widgets
|
||||
@@ -245,6 +259,17 @@ void Settings::Save(uint64_t runtime)
|
||||
pRoot->InsertEndChild(recent);
|
||||
}
|
||||
|
||||
// hosts known hosts
|
||||
{
|
||||
XMLElement *knownhosts = xmlDoc.NewElement( "Hosts" );
|
||||
|
||||
// recent SRT hosts
|
||||
knownhosts->InsertEndChild( save_knownhost(application.recentSRT, "SRT", xmlDoc));
|
||||
|
||||
|
||||
pRoot->InsertEndChild(knownhosts);
|
||||
}
|
||||
|
||||
// Timer Metronome
|
||||
XMLElement *timerConfNode = xmlDoc.NewElement( "Timer" );
|
||||
timerConfNode->SetAttribute("mode", application.timer.mode);
|
||||
@@ -304,6 +329,33 @@ void load_history(Settings::History &h, const char *nodename, XMLElement *root)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void load_knownhost(Settings::KnownHosts &h, const char *nodename, XMLElement *root)
|
||||
{
|
||||
XMLElement * pElement = root->FirstChildElement(nodename);
|
||||
if (pElement)
|
||||
{
|
||||
// list of hosts
|
||||
h.hosts.clear();
|
||||
XMLElement* host_ = pElement->FirstChildElement("host");
|
||||
for( ; host_ ; host_ = host_->NextSiblingElement())
|
||||
{
|
||||
const char *ip_ = host_->GetText();
|
||||
if (ip_) {
|
||||
const char *port_ = host_->Attribute("port");
|
||||
if (port_)
|
||||
h.push( std::string(ip_), std::string(port_) );
|
||||
else
|
||||
h.push( std::string(ip_) );
|
||||
}
|
||||
}
|
||||
// protocol attribute
|
||||
const char *protocol_ = pElement->Attribute("protocol");
|
||||
if (protocol_)
|
||||
h.protocol = std::string(protocol_);
|
||||
}
|
||||
}
|
||||
|
||||
void Settings::Load()
|
||||
{
|
||||
// impose C locale for all app
|
||||
@@ -346,16 +398,6 @@ void Settings::Load()
|
||||
applicationNode->QueryIntAttribute("pannel_history_mode", &application.pannel_current_session_mode);
|
||||
applicationNode->QueryIntAttribute("stream_protocol", &application.stream_protocol);
|
||||
applicationNode->QueryIntAttribute("broadcast_port", &application.broadcast_port);
|
||||
const char *ip = applicationNode->Attribute("custom_connect_ip");
|
||||
if (ip)
|
||||
application.custom_connect_ip = std::string(ip);
|
||||
else
|
||||
application.custom_connect_ip = "127.0.0.1";
|
||||
const char *p = applicationNode->Attribute("custom_connect_port");
|
||||
if (p)
|
||||
application.custom_connect_port = std::string(p);
|
||||
else
|
||||
application.custom_connect_port = "8888";
|
||||
}
|
||||
|
||||
// Widgets
|
||||
@@ -533,6 +575,16 @@ void Settings::Load()
|
||||
}
|
||||
}
|
||||
|
||||
// bloc of known hosts
|
||||
{
|
||||
XMLElement * pElement = pRoot->FirstChildElement("Hosts");
|
||||
if (pElement)
|
||||
{
|
||||
// recent SRT hosts
|
||||
load_knownhost(application.recentSRT, "SRT", pElement);
|
||||
}
|
||||
}
|
||||
|
||||
// Timer Metronome
|
||||
XMLElement * timerconfnode = pRoot->FirstChildElement("Timer");
|
||||
if (timerconfnode != nullptr) {
|
||||
@@ -595,6 +647,29 @@ void Settings::History::validate()
|
||||
}
|
||||
}
|
||||
|
||||
void Settings::KnownHosts::push(const string &ip, const string &port)
|
||||
{
|
||||
if (!ip.empty()) {
|
||||
|
||||
std::pair<std::string, std::string> h = { ip, port };
|
||||
hosts.remove(h);
|
||||
hosts.push_front(h);
|
||||
if (hosts.size() > MAX_RECENT_HISTORY)
|
||||
hosts.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
void Settings::KnownHosts::remove(const string &ip)
|
||||
{
|
||||
for (auto hit = hosts.begin(); hit != hosts.end();) {
|
||||
if ( ip.compare( hit->first ) > 0 )
|
||||
++hit;
|
||||
else
|
||||
hit = hosts.erase(hit);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Settings::Lock()
|
||||
{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user