summaryrefslogtreecommitdiff
blob: 5a44ad480ceb9a2e695a4779ad05b9bca26fb175 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
* Copyright (C) 2010 Robin H.Johnson, Ovechko Kostyantyn <fastinetserver@gmail.com>.
*
* Project: IDFetch.
* Developer: Ovechko Kostyantyn Olexandrovich (Kharkiv State Technical University of Construction and Architecture, Ukraine).
* Mentor: Robin H. Johnson (Gentoo Linux: Developer, Trustee & Infrastructure Lead).
* Mentoring organization: Gentoo Linux.
* Sponsored by GSOC 2010.
*
* This file is part of Segget.
*
* Segget is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* Segget is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Segget; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include "settings.h"

Tsettings settings;

void Tsettings::load_provide_mirror_files_restricted_patterns_vector(){
	try{
		ifstream file;
		file.exceptions (ifstream::failbit | ifstream::badbit);
		try{
			file.open("restrict.conf");
		}
		catch(...){
			error_log("Can NOT open pattern list file restrict.conf. Setting provide_mirror_files_restrict_list_on=0 will be forced.");
			provide_mirror_files_restrict_list_on=0;
			return;
		}
		try{
			//processing file
			string restricted_pattern_line;
			while (not(file.eof())) {
				getline(file,restricted_pattern_line);
				if (! restricted_pattern_line.length()) continue;
				if (restricted_pattern_line[0] == '#') continue;
				if (restricted_pattern_line[0] == ';') continue;
				provide_mirror_files_restricted_patterns_vector.push_back(restricted_pattern_line);
				debug("restricted_pattern_line added:"+restricted_pattern_line);
			}
			log(toString(provide_mirror_files_restricted_patterns_vector.size())+" pattern(s) was(were) read from restrict.conf");
			if (! provide_mirror_files_restricted_patterns_vector.size()){
				error_log("No patterns were read from restrict.conf file. Setting provide_mirror_files_restrict_list_on=0 will be forced.");
				provide_mirror_files_restrict_list_on=0;
			}
		}
		catch(...){
			error_log("Restricted pattern list file restrict.conf was opened, but an error occured while reading it.");
		}
	}catch(...){
		error_log("Error in settings.cpp: load_provide_mirror_files_restricted_patterns_vector()");
	}
}

void Tsettings::init(){
	try{
		Tconfig conf("segget.conf");
		conf.set("logs","general_log_file",general_log_file);
		conf.set("logs","logs_dir",logs_dir);
		conf.set("logs","error_log_file",error_log_file);
		conf.set("logs","debug_log_file",debug_log_file);
		conf.set("connections","max_connections",max_connections,1,MAX_CONNECTS);

		conf.set("folders","distfiles_dir",distfiles_dir);
		conf.set("folders","segments_dir",segments_dir);

		conf.set("pkg_list","pkg_list_dir",pkg_list_dir);
		conf.set("pkg_list","del_pkg_list_when_dld_finished",del_pkg_list_when_dld_finished);

		conf.set("distfiles","max_connection_num_per_distfile",max_connection_num_per_distfile,1,MAX_CONNECTS);

		conf.set("segments","resume_on",resume_on);
		conf.set("segments","max_segment_size",max_segment_size,10000,10000000);
		conf.set("segments","max_tries",max_tries,1,-1);

		conf.set("connections","current_speed_time_interval_msecs",current_speed_time_interval_msecs,100,60000);

		conf.set("mirrors","max_connections_num_per_mirror",max_connections_num_per_mirror,1,10);
		conf.set("mirrors","benchmark_oblivion",benchmark_oblivion,0,1000);

		conf.set("provide_mirror_to_others","provide_mirror_dir",provide_mirror_dir);
		if (provide_mirror_dir!="none"){
			conf.set("provide_mirror_to_others","provide_mirror_files_restrict_list_on",provide_mirror_files_restrict_list_on);
			if (provide_mirror_files_restrict_list_on)
				load_provide_mirror_files_restricted_patterns_vector();
		}

		conf.set("provide_proxy_fetcher_to_others","provide_proxy_fetcher_ip",provide_proxy_fetcher_ip);
		conf.set("provide_proxy_fetcher_to_others","provide_proxy_fetcher_port",provide_proxy_fetcher_port,1,65535);

		ulong cur_network_priority;
		for (uint network_num=0; network_num<MAX_NETWORKS; network_num++){
			//set default values, in case segget.conf doesn't have these settings
			network_array[network_num].network_num=network_num;
			if (network_num==0){
				cur_network_priority=10;
			}else{
				cur_network_priority=0;
			}

			conf.set("networks","network"+toString(network_num)+"_priority",cur_network_priority,0,10);
			if (cur_network_priority>0){
				network_array[network_num].init(cur_network_priority);
			}
		}

		conf.set("ui_server","ui_ip",ui_ip);
		conf.set("ui_server","ui_port",ui_port,1,65535);

		conf.clear();
	}catch(...){
		error_log_no_msg("Error in settings.cpp: init()");
	}
}