diff options
author | Kostyantyn Ovechko <fastinetserver@gmail.com> | 2010-06-24 12:22:29 +0300 |
---|---|---|
committer | Kostyantyn Ovechko <fastinetserver@gmail.com> | 2010-06-24 12:22:29 +0300 |
commit | 3fa425d93b61f350796870d9552b41da0340c3fe (patch) | |
tree | 4a92881691642025e3620dc4504432de0cccc557 | |
parent | Add [user-data].user_agent option to segget.conf (diff) | |
download | idfetch-3fa425d93b61f350796870d9552b41da0340c3fe.tar.gz idfetch-3fa425d93b61f350796870d9552b41da0340c3fe.tar.bz2 idfetch-3fa425d93b61f350796870d9552b41da0340c3fe.zip |
Add [logs] section to segget.conf
LOGS_DIR
Define a dir to store log files.
Default:
logs_dir=./logs
GENERAL_LOG_FILE
Define a file name to store general log.
Default:
general_log_file=segget.log
ERROR_LOG_FILE
Define a file name to store error log.
Default:
error_log_file=segget.log
DEBUG_LOG_FILE
Define a file name to store debug log.
Default:
debug_log_file=debug.log
-rw-r--r-- | segget/config.cpp | 2 | ||||
-rw-r--r-- | segget/mirror.cpp | 4 | ||||
-rw-r--r-- | segget/segget.conf | 20 | ||||
-rw-r--r-- | segget/segment.cpp | 3 | ||||
-rw-r--r-- | segget/settings.cpp | 88 | ||||
-rw-r--r-- | segget/settings.h | 89 | ||||
-rw-r--r-- | segget/stats.cpp | 1 | ||||
-rw-r--r-- | segget/tui.cpp | 22 | ||||
-rw-r--r-- | segget/tui.h | 22 |
9 files changed, 155 insertions, 96 deletions
diff --git a/segget/config.cpp b/segget/config.cpp index 6d4130d..8dac6a4 100644 --- a/segget/config.cpp +++ b/segget/config.cpp @@ -4,7 +4,7 @@ #include <string> #include <map> #include "str.cpp" -#include "tui.cpp" +#include "tui.h" using namespace std; map<string,string> content_; diff --git a/segget/mirror.cpp b/segget/mirror.cpp index 2b8c14e..631ef92 100644 --- a/segget/mirror.cpp +++ b/segget/mirror.cpp @@ -4,11 +4,11 @@ #include <string> #include <map> #include "str.cpp" -#include "tui.cpp" +#include "tui.h" #include "settings.cpp" -#include "tui.cpp" using namespace std; +extern Tsettings settings; class Tmirror{ private: uint active_num; diff --git a/segget/segget.conf b/segget/segget.conf index 21c17a9..d9b3a42 100644 --- a/segget/segget.conf +++ b/segget/segget.conf @@ -262,6 +262,26 @@ proxy_off=1 # NOT IMPLEMENTED YET: mirror_dir=./mirror [logs] +# LOGS_DIR +# Define a dir to store log files. +# Default: +# logs_dir=./logs +logs_dir=./logs + +# GENERAL_LOG_FILE +# Define a file name to store general log. +# Default: +# general_log_file=segget.log general_log_file=segget.log + +# ERROR_LOG_FILE +# Define a file name to store error log. +# Default: +# error_log_file=segget.log error_log_file=error.log + +# DEBUG_LOG_FILE +# Define a file name to store debug log. +# Default: +# debug_log_file=segget.log debug_log_file=debug.log
\ No newline at end of file diff --git a/segget/segment.cpp b/segget/segment.cpp index f8bf50a..afa4bac 100644 --- a/segget/segment.cpp +++ b/segget/segment.cpp @@ -9,11 +9,12 @@ #include <cstdio> #include <ncurses.h> #include <curl/curl.h> -#include "settings.cpp" +#include "settings.h" #include "stats.cpp" using namespace std; +extern Tsettings settings; unsigned long downloaded_bytes=0; size_t write_data(void *buffer, size_t size, size_t nmemb, void *cur_segment); diff --git a/segget/settings.cpp b/segget/settings.cpp index f574fd3..5b246ca 100644 --- a/segget/settings.cpp +++ b/segget/settings.cpp @@ -1,83 +1,14 @@ -#ifndef __SETTINGS_H__ -#define __SETTINGS_H__ +#include "settings.h" -#include <string> -#include "config.cpp" -//#include "tui.cpp" - -using namespace std; - -class Tsettings{ - private: - public: - //folders - string distfiles_dir; - string segments_dir; - //distfiles - uint max_connection_num_per_distfile; - //segments - uint max_segment_size; - bool resume_on; - uint max_tries; - //connections - uint max_connections; - uint connection_timeout; - uint ftp_response_timeout; - uint time_out; - uint low_connection_speed_limit; - uint low_connection_speed_time; - uint max_connection_speed; - string bind_interface; - //mirrors - uint max_connections_num_per_mirror; - uint benchmark_oblivion; - //user-data - string user_agent; - //proxy - string proxy_ip_or_name; - uint proxy_port; - uint proxy_off; - string proxy_user; - string proxy_password; - Tsettings(): - //folders - distfiles_dir("./distfiles"), - segments_dir("./tmp"), - //distfiles - max_connection_num_per_distfile(3), - //segments - max_segment_size(500000), - resume_on(1), - max_tries(30), - //connections - max_connections(6), - connection_timeout(15), - ftp_response_timeout(5000), - time_out(6000), - low_connection_speed_limit(1000), - low_connection_speed_time(10), - max_connection_speed(0), - bind_interface("none"), - //mirrors - max_connections_num_per_mirror(2), - benchmark_oblivion(5), - //user-data - user_agent("segget"), - //proxy - proxy_ip_or_name("none"), - proxy_port(0), - proxy_off(1), - proxy_user("none"), - proxy_password("none") - //logs - {}; - void set_resume(bool resume_setting){resume_on=resume_setting;}; - bool get_resume(){return resume_on;}; - void load_from_conf_file(); -}; +Tsettings settings; void Tsettings::load_from_conf_file(){ ConfigFile conf("segget.conf"); + conf.set(general_log_file, "logs", "general_log_file"); + conf.set(logs_dir, "logs", "logs_dir"); + conf.set(error_log_file, "logs", "error_log_file"); + conf.set(debug_log_file, "logs", "debug_log_file"); + conf.set(distfiles_dir, "folders", "distfiles_dir"); conf.set(segments_dir, "folders", "segments_dir"); // log("segments_dir set to:"+segments_dir); @@ -107,7 +38,4 @@ void Tsettings::load_from_conf_file(){ conf.set(proxy_off, "proxy", "proxy_off"); conf.set(proxy_user, "proxy", "proxy_user"); conf.set(proxy_password, "proxy", "proxy_password"); -} - -Tsettings settings; -#endif
\ No newline at end of file +}
\ No newline at end of file diff --git a/segget/settings.h b/segget/settings.h new file mode 100644 index 0000000..5a32bb2 --- /dev/null +++ b/segget/settings.h @@ -0,0 +1,89 @@ +#ifndef __SETTINGS_H__ +#define __SETTINGS_H__ + +#include <string> +#include "config.cpp" +//#include "tui.cpp" + +using namespace std; + +class Tsettings{ + private: + public: + //folders + string distfiles_dir; + string segments_dir; + //distfiles + uint max_connection_num_per_distfile; + //segments + uint max_segment_size; + bool resume_on; + uint max_tries; + //connections + uint max_connections; + uint connection_timeout; + uint ftp_response_timeout; + uint time_out; + uint low_connection_speed_limit; + uint low_connection_speed_time; + uint max_connection_speed; + string bind_interface; + //mirrors + uint max_connections_num_per_mirror; + uint benchmark_oblivion; + //user-data + string user_agent; + //proxy + string proxy_ip_or_name; + uint proxy_port; + uint proxy_off; + string proxy_user; + string proxy_password; + //logs + string logs_dir; + string general_log_file; + string error_log_file; + string debug_log_file; + + Tsettings(): + //folders + distfiles_dir("./distfiles"), + segments_dir("./tmp"), + //distfiles + max_connection_num_per_distfile(3), + //segments + max_segment_size(500000), + resume_on(1), + max_tries(30), + //connections + max_connections(6), + connection_timeout(15), + ftp_response_timeout(5000), + time_out(6000), + low_connection_speed_limit(1000), + low_connection_speed_time(10), + max_connection_speed(0), + bind_interface("none"), + //mirrors + max_connections_num_per_mirror(2), + benchmark_oblivion(5), + //user-data + user_agent("segget"), + //proxy + proxy_ip_or_name("none"), + proxy_port(0), + proxy_off(1), + proxy_user("none"), + proxy_password("none"), + //logs + logs_dir("./logs"), + general_log_file("segget.log"), + error_log_file("error.log"), + debug_log_file("debug.log") + {}; + void set_resume(bool resume_setting){resume_on=resume_setting;}; + bool get_resume(){return resume_on;}; + void load_from_conf_file(); +}; + +#endif diff --git a/segget/stats.cpp b/segget/stats.cpp index 73bbda2..8374eb8 100644 --- a/segget/stats.cpp +++ b/segget/stats.cpp @@ -2,6 +2,7 @@ #define __STATS_H__ #include "connection.cpp" +#include "tui.h" class Tstats{ private: diff --git a/segget/tui.cpp b/segget/tui.cpp index 5a5013e..12c7afb 100644 --- a/segget/tui.cpp +++ b/segget/tui.cpp @@ -1,17 +1,16 @@ -#ifndef __TUI_H__ -#define __TUI_H__ +#include "tui.h" +extern Tsettings settings; -using namespace std; -template<typename T> std::string toString(T t) +template<typename T> string toString(T t) { - std::stringstream s; + stringstream s; s << t; return s.str(); } -template<typename T> std::string field(string prefix,T t, int width) +template<typename T> string field(string prefix,T t, int width) { - std::stringstream s1,s2; + stringstream s1,s2; s1 << t; width=width+prefix.length(); s2.width(width); @@ -75,21 +74,20 @@ void msg_total(string msg_text){ msg(30,0,msg_text); } void log(string log_msg_text){ - ofstream file ("segget.log", ios::app); + ofstream file ((settings.logs_dir+"/"+settings.general_log_file).c_str(), ios::app); file << log_msg_text << endl; file.close(); msg(31,0, "LOG:"+log_msg_text); } void debug(string debug_msg_text){ - ofstream file ("debug.log", ios::app); + ofstream file ((settings.logs_dir+"/"+settings.debug_log_file).c_str(), ios::app); file << debug_msg_text << endl; file.close(); msg(32,0, "DEBUG:"+debug_msg_text); } void error_log(string error_msg_text){ - ofstream file ("error.log", ios::app); + ofstream file ((settings.logs_dir+"/"+settings.error_log_file).c_str(), ios::app); file << error_msg_text << endl; file.close(); msg(33,0, "ERROR:"+error_msg_text); -} -#endif
\ No newline at end of file +}
\ No newline at end of file diff --git a/segget/tui.h b/segget/tui.h new file mode 100644 index 0000000..24a550b --- /dev/null +++ b/segget/tui.h @@ -0,0 +1,22 @@ +#ifndef __TUI_H__ +#define __TUI_H__ +#include "settings.h" + +using namespace std; +template<typename T> string toString(T t); +template<typename T> string field(string prefix,T t, int width); + +void msg_total(string msg_text); + +void msg(uint y, uint x, string msg_text); +void msg_connecting(uint connection_num, uint distfile_num, uint segment_num, string msg_text); +void msg_segment_progress(uint connection_num, uint segment_num, uint try_num, ulong dld_bytes, ulong total_bytes, ulong speed); +void msg_status1(uint connection_num, uint segment_num, string msg_text); +void msg_status2(uint connection_num, string msg_text); +void msg_error(string error_text); +void msg_total(string msg_text); + +void log(string log_msg_text); +void debug(string debug_msg_text); +void error_log(string error_msg_text); +#endif
\ No newline at end of file |