summaryrefslogtreecommitdiff
path: root/tntconfig.cpp
blob: 1b0aadf1b395e91d8ff8f2e06ab6aef29362fbd3 (plain)
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
65
#include <cerrno>
#include <cstring>
#include <fstream>
#include <sstream>
#include <stdexcept>
#include <vdr/plugin.h>
#include "setup.h"
#include "tntconfig.h"

namespace vdrlive {

using namespace std;

TntConfig::TntConfig()
{
	WriteConfig();
}

void TntConfig::WriteConfig()
{
	WriteProperties();

	ostringstream builder;
	builder << cPlugin::ConfigDirectory( PLUGIN_NAME_I18N ) << "/httpd.config";
	m_configPath = builder.str();
	
	ofstream file( m_configPath.c_str(), ios::out | ios::trunc );
	if ( !file ) {
		ostringstream builder;
		builder << "Can't open " << m_configPath << " for writing: " << strerror( errno );
		throw runtime_error( builder.str() );
	}

	// XXX modularize
	file << "MapUrl /([^.]+)(\\..+)? $1@libtnt-live" << std::endl;
	file << "Listen 0.0.0.0 8003" << std::endl;
	file << "PropertyFile " << m_propertiesPath << std::endl;
	file << "CompPath " << Setup::Get().GetLibraryPath() << "/" << std::endl;
}

void TntConfig::WriteProperties()
{
	ostringstream builder;
	builder << cPlugin::ConfigDirectory( PLUGIN_NAME_I18N ) << "/httpd.properties";
	m_propertiesPath = builder.str();
	
	ofstream file( m_propertiesPath.c_str(), ios::out | ios::trunc );
	if ( !file ) {
		ostringstream builder;
		builder << "Can't open " << m_propertiesPath << " for writing: " << strerror( errno );
		throw runtime_error( builder.str() );
	}

	// XXX modularize
	file << "rootLogger=INFO" << std::endl;
	file << "logger.tntnet=INFO" << std::endl;
}

TntConfig const& TntConfig::Get()
{
	static TntConfig instance;
	return instance;
}

} // namespace vdrlive