diff options
Diffstat (limited to 'segget')
-rw-r--r-- | segget/config.cpp | 27 | ||||
-rw-r--r-- | segget/config.h | 1 | ||||
-rw-r--r-- | segget/connection.cpp | 4 | ||||
-rw-r--r-- | segget/log.cpp | 38 | ||||
-rw-r--r-- | segget/segget.conf | 81 | ||||
-rw-r--r-- | segget/settings.cpp | 4 | ||||
-rw-r--r-- | segget/settings.h | 8 |
7 files changed, 141 insertions, 22 deletions
diff --git a/segget/config.cpp b/segget/config.cpp index fbbbab0..2dc7421 100644 --- a/segget/config.cpp +++ b/segget/config.cpp @@ -49,15 +49,14 @@ void Tconfig::load_settings_from_config_file(){ if (! line.length()) continue; if (line[0] == '#') continue; if (line[0] == ';') continue; - line=noupper(line); if (line[0] == '[') { - inSection=trim(line.substr(1,line.find(']')-1)); + inSection=noupper(trim(line.substr(1,line.find(']')-1))); continue; } posEqual=line.find('='); - name = trim(line.substr(0,posEqual)); + name = noupper(trim(line.substr(0,posEqual))); value = trim(line.substr(posEqual+1)); - content_[inSection+'/'+name]=noupper(value); + content_[inSection+'/'+name]=value; } }catch(ifstream::failure e){ if (!file.eof()){ @@ -81,6 +80,25 @@ int Tconfig::set(string const& section, string const& entry, string &dst) const return 1; } else{ + dst=noupper(ci->second); + log("Settings in file:"+config_file_name+" ["+section+"]."+entry+"="+dst); + return 0; + } + }catch(...){ + error_log("Error in config.cpp: set(string &dst, string const& section, string const& entry)"); + return 1; + } +} + +int Tconfig::set_keep_case(string const& section, string const& entry, string &dst) const { + try{ + map<string,string>::const_iterator ci = content_.find(section + '/' + entry); + if (ci == content_.end()){ + log("! Settings in file:"+config_file_name+" ["+section+"]."+entry+" has not been set."); + log("! Settings in file:"+config_file_name+" ["+section+"]."+entry+"="+dst+". Default value forced."); + return 1; + } + else{ dst=ci->second; log("Settings in file:"+config_file_name+" ["+section+"]."+entry+"="+dst); return 0; @@ -90,6 +108,7 @@ int Tconfig::set(string const& section, string const& entry, string &dst) const return 1; } } + int Tconfig::set(string const& section, string const& entry, ulong &dst, uint const& min_limit, uint const& max_limit) const { try{ uint return_value; diff --git a/segget/config.h b/segget/config.h index 60ae673..79e9ba4 100644 --- a/segget/config.h +++ b/segget/config.h @@ -45,6 +45,7 @@ class Tconfig { {config_file_name=file_name;load_settings_from_config_file();}; void load_settings_from_config_file(); int set(string const& section, string const& entry, string &dst) const; + int set_keep_case(string const& section, string const& entry, string &dst) const; int set(string const& section, string const& entry, ulong &dst, uint const& min_limit, uint const& max_limit) const; int set(string const& section, string const& entry, bool &dst) const; void clear(); diff --git a/segget/connection.cpp b/segget/connection.cpp index 02993b6..9380cf4 100644 --- a/segget/connection.cpp +++ b/segget/connection.cpp @@ -207,10 +207,10 @@ void Tconnection::show_connection_progress(ulong time_diff){ ulong speed=(bytes_per_last_interval*1000)/time_diff; ulong avg_speed=(total_dld_bytes*1000)/time_left_from(start_time); string eta_string; - if (speed==0){ + if (avg_speed==0){ eta_string=" ETA: inf"; }else{ - eta_string=" ETA: "+secsToString((segment->segment_size-segment->downloaded_bytes)/speed); + eta_string=" ETA: "+secsToString((segment->segment_size-segment->downloaded_bytes)/avg_speed); } string speed_str; string avg_speed_str; diff --git a/segget/log.cpp b/segget/log.cpp index 6af0ffa..4d1edfe 100644 --- a/segget/log.cpp +++ b/segget/log.cpp @@ -26,6 +26,22 @@ #include "log.h" +string get_time(string time_format){ + try{ + time_format=time_format+" "; + time_t rawtime; + struct tm * timeinfo; + char buffer [80]; + time ( &rawtime ); + timeinfo = localtime ( &rawtime ); + strftime(buffer,80,time_format.c_str(),timeinfo); + return buffer; + }catch(...){ + error_log("Error in log.cpp: get_time()"); + return ""; + } +} + void log_no_msg(string log_msg_text){ try{ if (settings.general_log_file!="none"){ @@ -38,7 +54,7 @@ void log_no_msg(string log_msg_text){ return; } try{ - file << log_msg_text << endl; + file << get_time(settings.general_log_time_format) << log_msg_text << endl; file.close(); } catch(...){ @@ -47,16 +63,16 @@ void log_no_msg(string log_msg_text){ } } }catch(...){ - error_log("Error in tui.cpp: log()"); + error_log("Error in log.cpp: log()"); } } void log(string log_msg_text){ log_no_msg(log_msg_text); try{ - msg_log(log_msg_text); + msg_log(get_time(settings.general_log_time_format)+log_msg_text); }catch(...){ - error_log("Error in tui.cpp: log()"); + error_log("Error in log.cpp: log()"); } } @@ -73,7 +89,7 @@ void debug_no_msg(string debug_msg_text){ return; } try{ - file << debug_msg_text << endl; + file << get_time(settings.debug_log_time_format) << debug_msg_text << endl; file.close(); } catch(...){ @@ -82,16 +98,16 @@ void debug_no_msg(string debug_msg_text){ } } }catch(...){ - error_log("Error in tui.cpp: debug()"); + error_log("Error in log.cpp: debug()"); } } void debug(string debug_msg_text){ debug_no_msg(debug_msg_text); try{ -// msg(DEBUG_LINE_NUM,0, "DEBUG:"+debug_msg_text); +// msg(DEBUG_LINE_NUM,0, "DEBUG:"+get_time(settings.debug_time_format)+debug_msg_text); }catch(...){ - error_log("Error in tui.cpp: debug()"); + error_log("Error in log.cpp: debug()"); } } @@ -99,7 +115,7 @@ void error_log_no_msg(string error_msg_text){ try{ if (settings.error_log_file!="none"){ ofstream file ((settings.logs_dir+"/"+settings.error_log_file).c_str(), ios::app); - file << error_msg_text << endl; + file << get_time(settings.error_log_time_format) << error_msg_text << endl; file.close(); } }catch(...){ @@ -111,8 +127,8 @@ void error_log_no_msg(string error_msg_text){ void error_log(string error_msg_text){ error_log_no_msg(error_msg_text); try{ - msg_error_log(error_msg_text); + msg_error_log(get_time(settings.error_log_time_format)+error_msg_text); }catch(...){ - error_log_no_msg("Error in tui.cpp: error_log()"); + error_log_no_msg("Error in log.cpp: error_log()"); } }
\ No newline at end of file diff --git a/segget/segget.conf b/segget/segget.conf index 8e41fec..4cac4a3 100644 --- a/segget/segget.conf +++ b/segget/segget.conf @@ -214,11 +214,11 @@ provide_proxy_fetcher_port=3130 # network7_priority=0 # network8_priority=0 # network9_priority=0 -network0_priority=0 +network0_priority=10 network1_priority=0 network2_priority=0 network3_priority=0 -network4_priority=7 +network4_priority=0 network5_priority=0 network6_priority=0 network7_priority=0 @@ -259,12 +259,32 @@ ui_ip=127.0.0.1 # ui_port=9999 ui_port=9999 +[request_server] +# request application adds distfiles to segget daemon queue by establishing tcp connection +# with segget daemon (request_server part of it). + +# REQUEST_IP +# Define an ip address segget will use to provide access for tuiclients. +# The parameter should be a string holding your host dotted IP address. +# Default: +# request_ip=127.0.0.1 +request_ip=127.0.0.1 + +# REQUEST_PORT +# Define a port segget will use to provide access for tuiclients. +# The parameter should be an integer. +# Minimum value: 1 +# Maximum value: 65535 +# Default: +# request_port=10000 +request_port=10000 + [logs] # LOGS_DIR # Define a dir to store log files. # Default: # logs_dir=./logs -logs_dir=./logs +logs_dir=/home/mona/idfetcha/logs # GENERAL_LOG_FILE # Define a file name to store general log. @@ -273,6 +293,43 @@ logs_dir=./logs # general_log_file=segget.log general_log_file=segget.log +# GENERAL_LOG_TIME_FORMAT +# Set time format for general log as a string containing any combination of +# regular characters and special format specifiers. These format specifiers are +# replaced by the function to the corresponding values to represent the time +# specified in timeptr. They all begin with a percentage (%) sign, and are: +# %a Abbreviated weekday name [For example: Thu] +# %A Full weekday name [For example: Thursday] +# %b Abbreviated month name [For example: Aug] +# %B Full month name [For example: August] +# %c Date and time representation [For example: Thu Aug 23 14:55:02 2001] +# %d Day of the month (01-31) [For example: 23] +# %H Hour in 24h format (00-23) [For example: 14] +# %I Hour in 12h format (01-12) [For example: 02] +# %j Day of the year (001-366) [For example: 235] +# %m Month as a decimal number (01-12) [For example: 08] +# %M Minute (00-59) [For example: 55] +# %p AM or PM designation [For example: PM] +# %S Second (00-61) [For example: 02] +# %U Week number with the first Sunday +# as the first day of week one (00-53) [For example: 33] +# %w Weekday as a decimal number with +# Sunday as 0 (0-6) [For example: 4] +# %W Week number with the first Monday as +# the first day of week one (00-53) [For example: 34] +# %x Date representation [For example: 08/23/01] +# %X Time representation [For example: 14:55:02] +# %y Year, last two digits (00-99) [For example: 01] +# %Y Year [For example: 2001] +# %Z Timezone name or abbreviation [For example: CDT] +# %% A % sign [For example: %] +# +# For instace general_log_time_format=Time: %m/%d %X +# +# Default: +# general_log_time_format=%m/%d %X +general_log_time_format=%m/%d %X + # ERROR_LOG_FILE # Define a file name to store error log. # Set to none to disable loggin. @@ -280,9 +337,25 @@ general_log_file=segget.log # error_log_file=segget.log error_log_file=error.log +# ERROR_LOG_TIME_FORMAT +# Set time format for error log as a string containing any combination of +# regular characters and special format specifiers. See GENERAL_LOG_TIME_FORMAT +# for details on format specifiers. +# Default: +# error_log_time_format=%m/%d %X +error_log_time_format=%m/%d %X + # DEBUG_LOG_FILE # Define a file name to store debug log. # Set to none to disable loggin. # Default: # debug_log_file=segget.log -debug_log_file=debug.log
\ No newline at end of file +debug_log_file=debug.log + +# DEBUG_LOG_TIME_FORMAT +# Set time format for debug log as a string containing any combination of +# regular characters and special format specifiers. See GENERAL_LOG_TIME_FORMAT +# for details on format specifiers. +# Default: +# debug_log_time_format=%m/%d %X +debug_log_time_format=%m/%d %X
\ No newline at end of file diff --git a/segget/settings.cpp b/segget/settings.cpp index d16507c..e4415c8 100644 --- a/segget/settings.cpp +++ b/segget/settings.cpp @@ -72,6 +72,10 @@ void Tsettings::init(){ 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_keep_case("logs","general_log_time_format",general_log_time_format); + conf.set_keep_case("logs","error_log_time_format",error_log_time_format); + conf.set_keep_case("logs","debug_log_time_format",debug_log_time_format); + conf.set("connections","max_connections",max_connections,1,MAX_CONNECTS); conf.set("folders","distfiles_dir",distfiles_dir); diff --git a/segget/settings.h b/segget/settings.h index 93f381a..f7c2e95 100644 --- a/segget/settings.h +++ b/segget/settings.h @@ -84,6 +84,9 @@ class Tsettings{ string general_log_file; string error_log_file; string debug_log_file; + string general_log_time_format; + string error_log_time_format; + string debug_log_time_format; Tsettings(): conf_dir("/etc/seggetd"), @@ -130,7 +133,10 @@ class Tsettings{ logs_dir("./logs"), general_log_file("segget.log"), error_log_file("error.log"), - debug_log_file("debug.log") + debug_log_file("debug.log"), + general_log_time_format("%m/%d %X"), + error_log_time_format("%m/%d %X"), + debug_log_time_format("%m/%d %X") {}; void set_resume(bool resume_setting){resume_on=resume_setting;}; bool get_resume(){return resume_on;}; |