diff options
author | Kostyantyn Ovechko <fastinetserver@gmail.com> | 2010-07-05 00:52:06 +0300 |
---|---|---|
committer | Kostyantyn Ovechko <fastinetserver@gmail.com> | 2010-07-05 00:52:06 +0300 |
commit | 854561b9520bc59a1bd233bd210a5fdd43b8bf9a (patch) | |
tree | 523c50ffb5462a30533459ffbcc54f57845275ff | |
parent | Failprove networkbroker.cpp and log errors to error.log (diff) | |
download | idfetch-854561b9520bc59a1bd233bd210a5fdd43b8bf9a.tar.gz idfetch-854561b9520bc59a1bd233bd210a5fdd43b8bf9a.tar.bz2 idfetch-854561b9520bc59a1bd233bd210a5fdd43b8bf9a.zip |
Failprove .cpp files and log errors to error.log
-rw-r--r-- | segget/checksum.cpp | 18 | ||||
-rw-r--r-- | segget/checksum.h | 49 | ||||
-rw-r--r-- | segget/config.cpp | 221 | ||||
-rw-r--r-- | segget/connection.cpp | 1 | ||||
-rw-r--r-- | segget/connection.h | 1 | ||||
-rw-r--r-- | segget/distfile.cpp | 136 | ||||
-rw-r--r-- | segget/distfile.h | 2 | ||||
-rw-r--r-- | segget/network.cpp | 84 | ||||
-rw-r--r-- | segget/network.h | 2 | ||||
-rw-r--r-- | segget/network1.conf | 2 | ||||
-rw-r--r-- | segget/pkg.cpp | 28 | ||||
-rw-r--r-- | segget/pkg.h | 52 | ||||
-rw-r--r-- | segget/segget.cpp | 28 | ||||
-rw-r--r-- | segget/segget.h | 63 | ||||
-rw-r--r-- | segget/segment.cpp | 11 | ||||
-rw-r--r-- | segget/segment.h | 2 | ||||
-rw-r--r-- | segget/settings.cpp | 60 | ||||
-rw-r--r-- | segget/stats.cpp | 70 | ||||
-rw-r--r-- | segget/stats.h | 68 | ||||
-rw-r--r-- | segget/str.cpp | 73 | ||||
-rw-r--r-- | segget/tui.cpp | 137 | ||||
-rw-r--r-- | segget/utils.cpp | 2 | ||||
-rw-r--r-- | segget/utils.h | 1 |
23 files changed, 661 insertions, 450 deletions
diff --git a/segget/checksum.cpp b/segget/checksum.cpp index 60a42f2..cb36561 100644 --- a/segget/checksum.cpp +++ b/segget/checksum.cpp @@ -24,20 +24,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef __CHECKSUM_H__ -#define __CHECKSUM_H__ - -#include <string> -#include "cryptopp/crc.h" -#include "cryptopp/sha.h" -#include "cryptopp/whrlpool.h" -#include "cryptopp/ripemd.h" -#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1 -#include "cryptopp/md5.h" -#include "cryptopp/files.h" -#include "cryptopp/hex.h" -#include "tui.h" -#include "str.h" +#include "checksum.h" bool rmd160_ok(string distfile_filename, string portage_hash){ try{ @@ -163,5 +150,4 @@ bool crc32_ok(string distfile_filename, string portage_hash){ error_log("Error in checksum.cpp : crc32_ok()"); return false; } -} -#endif
\ No newline at end of file +}
\ No newline at end of file diff --git a/segget/checksum.h b/segget/checksum.h new file mode 100644 index 0000000..9a0cccb --- /dev/null +++ b/segget/checksum.h @@ -0,0 +1,49 @@ +/* +* 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 +*/ + +#ifndef __CHECKSUM_H__ +#define __CHECKSUM_H__ + +#include <string> +#include "cryptopp/crc.h" +#include "cryptopp/sha.h" +#include "cryptopp/whrlpool.h" +#include "cryptopp/ripemd.h" +#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1 +#include "cryptopp/md5.h" +#include "cryptopp/files.h" +#include "cryptopp/hex.h" +#include "tui.h" +#include "str.h" + +bool rmd160_ok(string distfile_filename, string portage_hash); +bool sha1_ok(string distfile_filename, string portage_hash); +bool sha256_ok(string distfile_filename, string portage_hash); +bool sha512_ok(string distfile_filename, string portage_hash); +bool whirlpool_ok(string distfile_filename, string portage_hash); +bool md5_ok(string distfile_filename, string portage_hash); +bool crc32_ok(string distfile_filename, string portage_hash); +#endif
\ No newline at end of file diff --git a/segget/config.cpp b/segget/config.cpp index 540c641..7029691 100644 --- a/segget/config.cpp +++ b/segget/config.cpp @@ -26,135 +26,152 @@ #include "config.h" -void Tconfig::load_settings_from_config_file() { - - ifstream file; - file.exceptions (ifstream::failbit | ifstream::badbit); - try{ - file.open(config_file_name.c_str()); - } - catch(...){ - error_log("Error opening settings file: "+config_file_name+". Default settings will be used. Check if config file: "+config_file_name+" exists and segget has rights to access it."); - return; - } +void Tconfig::load_settings_from_config_file(){ try{ - //processing file - string line; - string name; - string value; - string inSection; - int posEqual; - while (not(file.eof())) { - getline(file,line); - 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)); - continue; - } - - posEqual=line.find('='); - name = trim(line.substr(0,posEqual)); - value = trim(line.substr(posEqual+1)); - - content_[inSection+'/'+name]=noupper(value); + ifstream file; + file.exceptions (ifstream::failbit | ifstream::badbit); + try{ + file.open(config_file_name.c_str()); } - }catch(ifstream::failure e){ - if (!file.eof()){ - error_log("Settings file: "+config_file_name+" was opened, but an error occured while reading it."); + catch(...){ + error_log("Error opening settings file: "+config_file_name+". Default settings will be used. Check if config file: "+config_file_name+" exists and segget has rights to access it."); return; } + try{ + //processing file + string line; + string name; + string value; + string inSection; + int posEqual; + while (not(file.eof())) { + getline(file,line); + 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)); + continue; + } + posEqual=line.find('='); + name = trim(line.substr(0,posEqual)); + value = trim(line.substr(posEqual+1)); + content_[inSection+'/'+name]=noupper(value); + } + }catch(ifstream::failure e){ + if (!file.eof()){ + error_log("Settings file: "+config_file_name+" was opened, but an error occured while reading it."); + return; + } + }catch(...){ + error_log("Settings file: "+config_file_name+" was opened, but an error occured while reading settings from it."); + } }catch(...){ - error_log("Settings file: "+config_file_name+" was opened, but an error occured while reading settings from it."); + error_log("Error in config.cpp: load_settings_from_config_file()"); } } int Tconfig::set(string &dst, string const& section, string const& entry) const { - 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."); + 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; + } + }catch(...){ + error_log("Error in config.cpp: set(string &dst, string const& section, string const& entry)"); return 1; } - else{ - dst=ci->second; - log("Settings in file:"+config_file_name+" ["+section+"]."+entry+"="+dst); - return 0; - } } int Tconfig::set(ulong &dst, string const& section, string const& entry, uint const& min_limit, uint const& max_limit) const { - uint return_value; - 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+"="+toString(dst)+". Default value forced."); - return 1; - } - else{ - return_value=atoi(ci->second.c_str()); - if (return_value==0) - if (toString(return_value)!=ci->second){ + try{ + uint return_value; + 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+"="+toString(dst)+". Default value forced."); + return 1; + } + else{ + return_value=atoi(ci->second.c_str()); + if (return_value==0) + if (toString(return_value)!=ci->second){ + log("! Settings in file:"+config_file_name+" ["+section+"]."+entry + +" must have an integer value in range from "+toString(min_limit) + +" to "+toString(max_limit) + +". Can't convert "+ci->second + +" to integer. "); + log("! Settings in file:"+config_file_name+" ["+section+"]."+entry+"="+toString(dst)+". Default value forced."); + return 1; + } + if ((return_value>=min_limit) and (return_value<=max_limit)){ + //everything is ok + log("Settings in file:"+config_file_name+" ["+section+"]."+entry+"="+toString(return_value)); + dst=return_value; + return 0; + }else{ log("! Settings in file:"+config_file_name+" ["+section+"]."+entry - +" must have an integer value in range from "+toString(min_limit) - +" to "+toString(max_limit) - +". Can't convert "+ci->second - +" to integer. "); - log("! Settings in file:"+config_file_name+" ["+section+"]."+entry+"="+toString(dst)+". Default value forced."); + +" must have an integer value in range from "+toString(min_limit) + +" to "+toString(max_limit)+"."); + log("! Settings in file:"+config_file_name+" ["+section+"]."+entry+"="+toString(dst)+". Default value forced."); return 1; } - if ((return_value>=min_limit) and (return_value<=max_limit)){ - //everything is ok - log("Settings in file:"+config_file_name+" ["+section+"]."+entry+"="+toString(return_value)); - dst=return_value; - return 0; - }else{ - log("! Settings in file:"+config_file_name+" ["+section+"]."+entry - +" must have an integer value in range from "+toString(min_limit) - +" to "+toString(max_limit)+"."); - log("! Settings in file:"+config_file_name+" ["+section+"]."+entry+"="+toString(dst)+". Default value forced."); - return 1; } + }catch(...){ + error_log("Error in config.cpp: set(ulong &dst, string const& section, string const& entry, uint const& min_limit, uint const& max_limit)"); + return 1; } } -int Tconfig::set(bool &dst, string const& section, string const& entry) const { - uint return_value; - map<std::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+"="+toString(dst)+". Default value forced."); - return 1; - } - else{ - return_value=atoi(ci->second.c_str()); - if (return_value==0) - if (toString(return_value)!=ci->second){ +int Tconfig::set(bool &dst, string const& section, string const& entry) const { + try{ + uint return_value; + map<std::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+"="+toString(dst)+". Default value forced."); + return 1; + } + else{ + return_value=atoi(ci->second.c_str()); + if (return_value==0) + if (toString(return_value)!=ci->second){ + log("! Settings in file:"+config_file_name+" ["+section+"]."+entry + +" must have a boolean value: 0 or 1" + +". Can't convert "+ci->second + +" to 0 or 1. "); + log("! Settings in file:"+config_file_name+" ["+section+"]."+entry+"="+toString(dst)+". Default value forced."); + return 1; + } + if ((return_value==0) or (return_value==1)){ + //everything is ok + log("Settings in file:"+config_file_name+" ["+section+"]."+entry+"="+toString(return_value)); + dst=return_value; + return 0; + }else{ log("! Settings in file:"+config_file_name+" ["+section+"]."+entry - +" must have a boolean value: 0 or 1" - +". Can't convert "+ci->second - +" to 0 or 1. "); + +" must have a boolean value: 0 or 1"); log("! Settings in file:"+config_file_name+" ["+section+"]."+entry+"="+toString(dst)+". Default value forced."); return 1; } - if ((return_value==0) or (return_value==1)){ - //everything is ok - log("Settings in file:"+config_file_name+" ["+section+"]."+entry+"="+toString(return_value)); - dst=return_value; - return 0; - }else{ - log("! Settings in file:"+config_file_name+" ["+section+"]."+entry - +" must have a boolean value: 0 or 1"); - log("! Settings in file:"+config_file_name+" ["+section+"]."+entry+"="+toString(dst)+". Default value forced."); - return 1; } + }catch(...){ + error_log("Error in config.cpp: set(bool &dst, string const& section, string const& entry)"); + return 1; } } void Tconfig::clear(){ - content_.clear(); + try{ + content_.clear(); + }catch(...){ + error_log("Error in config.cpp: clear()"); + } }
\ No newline at end of file diff --git a/segget/connection.cpp b/segget/connection.cpp index 48809ea..dc1cc98 100644 --- a/segget/connection.cpp +++ b/segget/connection.cpp @@ -81,7 +81,6 @@ void Tconnection::stop(uint connection_result){ segment->status=DOWNLOADED; prnt_distfile->inc_dld_segments_count(segment); }; - }catch(...){ error_log("Error in connection.cpp: stop()"); } diff --git a/segget/connection.h b/segget/connection.h index f189b98..fccf324 100644 --- a/segget/connection.h +++ b/segget/connection.h @@ -28,6 +28,7 @@ #define __CONNECTION_H__ #include <time.h> +#include <curl/curl.h> class Tsegment; #include "segment.h" #include "utils.h" diff --git a/segget/distfile.cpp b/segget/distfile.cpp index ba832db..023d0e7 100644 --- a/segget/distfile.cpp +++ b/segget/distfile.cpp @@ -27,8 +27,12 @@ #include "distfile.h" void Tdistfile::init(){ - for (uint network_num=0; network_num<MAX_NETWORKS; network_num++){ - network_distfile_brokers_array[network_num].init(network_num); + try{ + for (uint network_num=0; network_num<MAX_NETWORKS; network_num++){ + network_distfile_brokers_array[network_num].init(network_num); + } + }catch(...){ + error_log("Error: distfile.cpp: init()"); } } void Tdistfile::load_url_list(json_object* json_array_distfile_urllist){ @@ -132,6 +136,7 @@ Tdistfile::~Tdistfile(){ } } bool Tdistfile::choose_best_mirror(CURLM* cm, uint connection_num, uint network_num, uint seg_num){ + try{ Tmirror *Pcurr_mirror; Tmirror *Pbest_mirror=0; // the best isn't set let's find it uint best_mirror_num=-1; // the best isn't set let's find it @@ -163,13 +168,16 @@ bool Tdistfile::choose_best_mirror(CURLM* cm, uint connection_num, uint network_ error_log("Can't choose mirror for segment:"+dn_segments[seg_num].file_name); return 1; } + }catch(...){ + error_log("Error: distfile.cpp: choose_best_mirror()"); + return 1; + } } bool Tdistfile::choose_best_local_mirror(CURLM* cm, uint connection_num, uint network_num, uint seg_num){ + try{ long best_mirror_num=-1; // the best isn't set let's find it - ulong best_mirror_self_rating=-1; ulong curr_mirror_self_rating; - for (ulong mirror_num=0; mirror_num<network_array[network_num].benchmarked_mirror_list.size(); mirror_num++){ if (network_array[network_num].benchmarked_mirror_list[mirror_num].get_active_num()<settings.max_connections_num_per_mirror){ curr_mirror_self_rating=network_array[network_num].benchmarked_mirror_list[mirror_num].mirror_on_the_wall(); @@ -192,6 +200,10 @@ bool Tdistfile::choose_best_local_mirror(CURLM* cm, uint connection_num, uint ne error_log("Can't choose LOCAL mirror for segment:"+dn_segments[seg_num].file_name); return 1; } + }catch(...){ + error_log("Error: distfile.cpp: choose_best_local_mirror()"); + return 1; + } } int Tdistfile::provide_segment(CURLM* cm, uint connection_num, uint seg_num){ @@ -268,11 +280,11 @@ int Tdistfile::provide_segment(CURLM* cm, uint connection_num, uint seg_num){ } } } + return 0; }catch(...){ error_log("Error: distfile.cpp: provide_segment()"); return 1; } - return 0; } void Tdistfile::inc_dld_segments_count(Tsegment* current_segment){ try{ @@ -284,68 +296,72 @@ void Tdistfile::inc_dld_segments_count(Tsegment* current_segment){ } } void Tdistfile::symlink_distfile_to_provide_mirror_dir(){ - for(ulong pattern_num=0; pattern_num<settings.provide_mirror_files_restricted_patterns_vector.size(); pattern_num++){ - if (name.find(settings.provide_mirror_files_restricted_patterns_vector[pattern_num],0)!=name.npos){ - log("Symlink to distfile:"+name+" was restricted by pattern <" - +settings.provide_mirror_files_restricted_patterns_vector[pattern_num] - +"> from line "+toString(pattern_num+1)+" of restrict.conf file"); - return; - } - } - string new_mirror_name; - string old_distfile_name; try{ - string old_distfile_path; - char current_path[FILENAME_MAX]; - if (!GetCurrentDir(current_path, sizeof(current_path))) - { - return; - } - if (settings.distfiles_dir.find("./",0)==0){ - old_distfile_path=current_path+settings.distfiles_dir.substr(1,settings.distfiles_dir.npos); - }else{ - old_distfile_path=settings.distfiles_dir; + for(ulong pattern_num=0; pattern_num<settings.provide_mirror_files_restricted_patterns_vector.size(); pattern_num++){ + if (name.find(settings.provide_mirror_files_restricted_patterns_vector[pattern_num],0)!=name.npos){ + log("Symlink to distfile:"+name+" was restricted by pattern <" + +settings.provide_mirror_files_restricted_patterns_vector[pattern_num] + +"> from line "+toString(pattern_num+1)+" of restrict.conf file"); + return; + } } - new_mirror_name=settings.provide_mirror_dir+"/"+name; - old_distfile_name=old_distfile_path+"/"+name; + string new_mirror_name; + string old_distfile_name; try{ - if (!symlink(old_distfile_name.c_str(), new_mirror_name.c_str())){ - log("Distfile:"+old_distfile_path+" was symlinked to the mirror dir:"); - }; - }catch(uint errno){ - switch (errno){ - case EACCES : error_log("Write access to the directory containing "+settings.provide_mirror_dir+" is denied, or one of the directories in the path prefix of "+settings.provide_mirror_dir+" did not allow search permission. (See also path_resolution(7)."); - break; - case EEXIST : error_log("There is already an existing file named "+new_mirror_name+"."); - break; - case EFAULT : error_log(old_distfile_path+" or "+settings.provide_mirror_dir+" points outside your accessible address space."); - break; - case EIO : error_log("A hardware error occurred while reading or writing data on the disk."); - break; - case ELOOP : error_log("Too many symbolic links were encountered in resolving "+settings.provide_mirror_dir+"."); - break; - case ENAMETOOLONG : error_log(old_distfile_path+" or "+settings.provide_mirror_dir+" was too long."); - break; - case ENOENT : error_log("A directory component in "+settings.provide_mirror_dir+" does not exist or is a dangling symbolic link, or "+old_distfile_path+" is the empty string."); - break; - case ENOMEM : error_log("Insufficient kernel memory was available."); - break; - case ENOSPC : error_log("The device containing the file has no room for the new directory entry."); - break; - case ENOTDIR : error_log("A component used as a directory in "+settings.provide_mirror_dir+" is not, in fact, a directory."); - break; - case EPERM : error_log("The file system containing "+settings.provide_mirror_dir+" does not support the creation of symbolic links."); - break; - case EROFS : error_log("The file "+new_mirror_name+" would exist on a read-only file system."); - break; - default: - error_log("Undocumented error while trying to symlink "+old_distfile_name+" to "+new_mirror_name); + string old_distfile_path; + char current_path[FILENAME_MAX]; + if (!GetCurrentDir(current_path, sizeof(current_path))) + { + return; + } + if (settings.distfiles_dir.find("./",0)==0){ + old_distfile_path=current_path+settings.distfiles_dir.substr(1,settings.distfiles_dir.npos); + }else{ + old_distfile_path=settings.distfiles_dir; + } + new_mirror_name=settings.provide_mirror_dir+"/"+name; + old_distfile_name=old_distfile_path+"/"+name; + try{ + if (!symlink(old_distfile_name.c_str(), new_mirror_name.c_str())){ + log("Distfile:"+old_distfile_path+" was symlinked to the mirror dir:"); + }; + }catch(uint errno){ + switch (errno){ + case EACCES : error_log("Write access to the directory containing "+settings.provide_mirror_dir+" is denied, or one of the directories in the path prefix of "+settings.provide_mirror_dir+" did not allow search permission. (See also path_resolution(7)."); + break; + case EEXIST : error_log("There is already an existing file named "+new_mirror_name+"."); + break; + case EFAULT : error_log(old_distfile_path+" or "+settings.provide_mirror_dir+" points outside your accessible address space."); + break; + case EIO : error_log("A hardware error occurred while reading or writing data on the disk."); + break; + case ELOOP : error_log("Too many symbolic links were encountered in resolving "+settings.provide_mirror_dir+"."); + break; + case ENAMETOOLONG : error_log(old_distfile_path+" or "+settings.provide_mirror_dir+" was too long."); + break; + case ENOENT : error_log("A directory component in "+settings.provide_mirror_dir+" does not exist or is a dangling symbolic link, or "+old_distfile_path+" is the empty string."); + break; + case ENOMEM : error_log("Insufficient kernel memory was available."); + break; + case ENOSPC : error_log("The device containing the file has no room for the new directory entry."); + break; + case ENOTDIR : error_log("A component used as a directory in "+settings.provide_mirror_dir+" is not, in fact, a directory."); + break; + case EPERM : error_log("The file system containing "+settings.provide_mirror_dir+" does not support the creation of symbolic links."); + break; + case EROFS : error_log("The file "+new_mirror_name+" would exist on a read-only file system."); + break; + default: + error_log("Undocumented error while trying to symlink "+old_distfile_name+" to "+new_mirror_name); + } + }catch(...){ + error_log("Undocumented error (error description is not an integer) while trying to symlink "+old_distfile_name+" to "+new_mirror_name); } }catch(...){ - error_log("Undocumented error (error description is not an integer) while trying to symlink "+old_distfile_name+" to "+new_mirror_name); + error_log("Error in distfile.cpp :: symlink_distfile_to_provide_mirror_dir() while trying to symlink "+old_distfile_name+" to "+new_mirror_name); } }catch(...){ - error_log("Error in distfile.cpp :: symlink_distfile_to_provide_mirror_dir() while trying to symlink "+old_distfile_name+" to "+new_mirror_name); + error_log("Error: distfile.cpp: symlink_distfile_to_provide_mirror_dir()"); } } int Tdistfile::combine_segments(){ diff --git a/segget/distfile.h b/segget/distfile.h index 0768b32..2f9c3fa 100644 --- a/segget/distfile.h +++ b/segget/distfile.h @@ -48,7 +48,7 @@ #endif #include "segment.h" #include "mirror.h" -#include "checksum.cpp" +#include "checksum.h" #include "network.h" #include "networkbroker.h" diff --git a/segget/network.cpp b/segget/network.cpp index bb58a2b..f0ea3b6 100644 --- a/segget/network.cpp +++ b/segget/network.cpp @@ -25,33 +25,37 @@ */ #include "network.h" void Tnetwork::load_mirror_list(){ - ifstream file; - string mirror_list_file_name="network"+toString(network_num)+"_mirrors.conf"; - file.exceptions (ifstream::failbit | ifstream::badbit); try{ - file.open(mirror_list_file_name.c_str()); - } - catch(...){ - error_log("Can NOT open mirror list file: "+mirror_list_file_name+". Network will be disabled"); - priority=0; - return; - } - try{ - //processing file - string mirror_line; - while (not(file.eof())) { - getline(file,mirror_line); - if (! mirror_line.length()) continue; - if (mirror_line[0] == '#') continue; - if (mirror_line[0] == ';') continue; - Tmirror cur_mirror; - cur_mirror.url=mirror_line; - benchmarked_mirror_list.push_back(cur_mirror); - debug("LOCAL_MIRROR_ADDED:"+mirror_line); + ifstream file; + string mirror_list_file_name="network"+toString(network_num)+"_mirrors.conf"; + file.exceptions (ifstream::failbit | ifstream::badbit); + try{ + file.open(mirror_list_file_name.c_str()); } - } - catch(...){ - error_log("Mirror list file: "+mirror_list_file_name+" was opened, but an error occured while reading from it."); + catch(...){ + error_log("Can NOT open mirror list file: "+mirror_list_file_name+". Network will be disabled"); + priority=0; + return; + } + try{ + //processing file + string mirror_line; + while (not(file.eof())) { + getline(file,mirror_line); + if (! mirror_line.length()) continue; + if (mirror_line[0] == '#') continue; + if (mirror_line[0] == ';') continue; + Tmirror cur_mirror; + cur_mirror.url=mirror_line; + benchmarked_mirror_list.push_back(cur_mirror); + debug("LOCAL_MIRROR_ADDED:"+mirror_line); + } + } + catch(...){ + error_log("Mirror list file: "+mirror_list_file_name+" was opened, but an error occured while reading from it."); + } + }catch(...){ + error_log_no_msg("Error in network.cpp: load_mirror_list()"); } } @@ -84,26 +88,34 @@ void Tnetwork::init(uint priority_value){ log("Settings: Network"+toString(network_num)+" local mirror_list size:"+toString(mirror_list.size())); } conf.clear(); - } - catch(...) - { - error_log_no_msg("Error calling msg() in settings.cpp: load_from_conf_file()"); + }catch(...){ + error_log("Error in network.cpp: init()"); } } bool Tnetwork::has_free_connections(){ - if (active_connections_num<max_connections){ - return true; - }else{ + try{ + if (active_connections_num<max_connections){ + return true; + }else{ + return false; + } + }catch(...){ + error_log_no_msg("Error in network.cpp: has_free_connections()"); return false; } } bool Tnetwork::connect(){ - if (active_connections_num<max_connections){ - active_connections_num++; - return true; - }else{ + try{ + if (active_connections_num<max_connections){ + active_connections_num++; + return true; + }else{ + return false; + } + }catch(...){ + error_log_no_msg("Error in network.cpp: connect()"); return false; } }
\ No newline at end of file diff --git a/segget/network.h b/segget/network.h index 4a065b6..c164bb7 100644 --- a/segget/network.h +++ b/segget/network.h @@ -28,8 +28,8 @@ //#include <string> //#include <map> -#include "str.h" #include <vector> +#include "str.h" #include "mirror.h" #include "config.h" //#include "tui.h" diff --git a/segget/network1.conf b/segget/network1.conf index 21ac1e1..7e0a72b 100644 --- a/segget/network1.conf +++ b/segget/network1.conf @@ -189,4 +189,4 @@ use_own_mirror_list_only_on=1 # NETWORK_MAX_CONNECTIONS in [network_connections] section of this file). # Default: # only_local_when_possible=1 -only_local_when_possible=0
\ No newline at end of file +only_local_when_possible=1
\ No newline at end of file diff --git a/segget/pkg.cpp b/segget/pkg.cpp index 40ddef3..84dc9f6 100644 --- a/segget/pkg.cpp +++ b/segget/pkg.cpp @@ -23,32 +23,9 @@ * License along with Segget; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef __PKG_H__ -#define __PKG_H__ -#include <stdio.h> -#include <stdlib.h> -#include <fstream> -#include <iostream> -#include <json/json.h> -#include "distfile.h" +#include "pkg.h" -using namespace std; -typedef unsigned int uint; - -class Tpkg{ - public: - Tdistfile **Pdistfile_list; - string name; - string category; - uint distfile_count; - void load_distfile_list(json_object* json_array_distfile_list); - Tpkg(): Pdistfile_list(0),name(""),category(""), distfile_count(0){}; - Tpkg(const Tpkg &L); // copy constructor - Tpkg & operator=(const Tpkg &L); - ~Tpkg(); - void load_pkg_from_json(json_object* json_obj_pkg); -}; void Tpkg::load_distfile_list(json_object* json_array_distfile_list){ try{ distfile_count=json_object_array_length(json_array_distfile_list); @@ -81,5 +58,4 @@ Tpkg::~Tpkg(){ }catch(...){ error_log("Error in pkg.cpp: ~Tpkg"); } -} -#endif
\ No newline at end of file +}
\ No newline at end of file diff --git a/segget/pkg.h b/segget/pkg.h new file mode 100644 index 0000000..660dde2 --- /dev/null +++ b/segget/pkg.h @@ -0,0 +1,52 @@ +/* +* 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 +*/ +#ifndef __PKG_H__ +#define __PKG_H__ + +#include <stdio.h> +#include <stdlib.h> +#include <fstream> +#include <iostream> +#include <json/json.h> +#include "distfile.h" + +using namespace std; +typedef unsigned int uint; + +class Tpkg{ + public: + Tdistfile **Pdistfile_list; + string name; + string category; + uint distfile_count; + void load_distfile_list(json_object* json_array_distfile_list); + Tpkg(): Pdistfile_list(0),name(""),category(""), distfile_count(0){}; + Tpkg(const Tpkg &L); // copy constructor + Tpkg & operator=(const Tpkg &L); + ~Tpkg(); + void load_pkg_from_json(json_object* json_obj_pkg); +}; +#endif
\ No newline at end of file diff --git a/segget/segget.cpp b/segget/segget.cpp index 2f6981c..edb6b0f 100644 --- a/segget/segget.cpp +++ b/segget/segget.cpp @@ -24,31 +24,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include <stdio.h> -#include <stdlib.h> -#include <fstream> -#include <iostream> -#include <json/json.h> -#include <ncurses.h> -#include "config.cpp" -#include "connection.cpp" -#include "distfile.cpp" -#include "mirror.cpp" -#include "network.cpp" -#include "networkbroker.cpp" -#include "pkg.cpp" -#include "segment.cpp" -#include "settings.cpp" -#include "str.cpp" -#include "tui.cpp" -#include "utils.cpp" -//#include "settings.cpp" - -using namespace std; - -Tpkg **Ppkg_array; - -CURLM *cm; +#include "segget.h" int load_pkgs(){ try{ @@ -306,4 +282,4 @@ int main() //error while ending curses } return 0; -} +}
\ No newline at end of file diff --git a/segget/segget.h b/segget/segget.h new file mode 100644 index 0000000..fc65f31 --- /dev/null +++ b/segget/segget.h @@ -0,0 +1,63 @@ +/* +* 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 +*/ + +#ifndef __SEGGET_H__ +#define __SEGGET_H__ + +#include <stdio.h> +#include <stdlib.h> +#include <fstream> +#include <iostream> +#include <json/json.h> +#include <ncurses.h> +#include "checksum.cpp" +#include "config.cpp" +#include "connection.cpp" +#include "distfile.cpp" +#include "mirror.cpp" +#include "network.cpp" +#include "networkbroker.cpp" +#include "pkg.cpp" +#include "segment.cpp" +#include "settings.cpp" +#include "stats.cpp" +#include "str.cpp" +#include "tui.cpp" +#include "utils.cpp" + +using namespace std; + +Tpkg **Ppkg_array; + +CURLM *cm; + +int load_pkgs(); +void show_pkgs(); +int choose_segment(uint connection_num); +int download_pkgs(); +int main(); + +#endif
\ No newline at end of file diff --git a/segget/segment.cpp b/segget/segment.cpp index 4bda02c..8e29b9c 100644 --- a/segget/segment.cpp +++ b/segget/segment.cpp @@ -79,13 +79,16 @@ void Tsegment::prepare_for_connection(CURLM *cm, uint con_num, uint network_num, } Tsegment::~Tsegment(){ - //try + try{ segment_file.close(); + }catch(...){ + error_log("Error in segment.cpp: ~Tsegment()"); + } } int Tsegment::add_easy_handle_to_multi(CURLM *cm, uint network_num){ - segment_file.exceptions (ofstream::badbit); try{ + segment_file.exceptions (ofstream::badbit); segment_file.open((settings.segments_dir+"/"+file_name).c_str(), ios::trunc|ios::binary ); }catch(std::ifstream::failure e){ if (!segment_file.eof()){ @@ -179,9 +182,9 @@ size_t write_data(void *buffer, size_t size, size_t nmemb, void *cur_segment){ show_progress(time_diff_msecs); stats.reset_previous_time(); }; - } - catch(...){ + }catch(...){ error_log("Error in segment.cpp: write_data()"); + return 0; } return bytes_written; }
\ No newline at end of file diff --git a/segget/segment.h b/segget/segment.h index 81e9a82..deb55b5 100644 --- a/segget/segment.h +++ b/segget/segment.h @@ -41,7 +41,7 @@ using namespace std; #include "distfile.h" class Tdistfile; -#include "stats.cpp" +#include "stats.h" extern Tsettings settings; diff --git a/segget/settings.cpp b/segget/settings.cpp index 352f19b..b60e2d0 100644 --- a/segget/settings.cpp +++ b/segget/settings.cpp @@ -26,35 +26,39 @@ #include "settings.h" void Tsettings::load_provide_mirror_files_restricted_patterns_vector(){ - 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); + ifstream file; + file.exceptions (ifstream::failbit | ifstream::badbit); + try{ + file.open("restrict.conf"); } - 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."); + 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; } - } - catch(...){ - error_log("Restricted pattern list file restrict.conf was opened, but an error occured while reading it."); + 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()"); } } @@ -106,9 +110,7 @@ void Tsettings::init(){ } } conf.clear(); - }catch(...) - { - error_log_no_msg("Error calling msg() in settings.cpp: load_from_conf_file()"); + }catch(...){ + error_log_no_msg("Error in settings.cpp: init()"); } - }
\ No newline at end of file diff --git a/segget/stats.cpp b/segget/stats.cpp index 5df2b7a..3683c5c 100644 --- a/segget/stats.cpp +++ b/segget/stats.cpp @@ -24,54 +24,20 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef __STATS_H__ -#define __STATS_H__ - -#include <sys/time.h> -#include "connection.h" -#include "tui.h" -#include "settings.h" -using namespace std; - -class Tstats{ - private: - ulong dld_size; - ulong dld_distfiles_count; - uint total_size; - public: - ulong total_bytes_per_last_interval; - struct timeval previous_time; - double last_time_interval; - uint pkg_count; - uint distfiles_count; - Tstats(): - dld_size(0), - dld_distfiles_count(0), - total_size(0), - total_bytes_per_last_interval(0), - previous_time(), - last_time_interval(1), - pkg_count(0), - distfiles_count(0) - {}; - void inc_dld_size(ulong more_bytes){ dld_size+=more_bytes;}; - ulong get_dld_size(){return dld_size;}; - void inc_dld_distfiles_count(); - ulong get_dld_distfiles_count(){return dld_distfiles_count;}; - void inc_total_size(ulong more_bytes){ total_size+=more_bytes;}; - ulong get_total_size(){return total_size;}; - void show_totals(); - void reset_previous_time(); -}; +#include "stats.h" void Tstats::inc_dld_distfiles_count(){ - dld_distfiles_count++; - if ((settings.del_pkg_list_when_dld_finished) and (dld_distfiles_count>distfiles_count)){ - //delete pkg.list file; - if(remove((settings.pkg_list_dir+"/pkg.list").c_str()) != 0 ) - error_log("Error in stats.cpp: inc_dld_distfiles_count(): Can't delete:"+settings.pkg_list_dir+"/pkg.list"); - else - debug(settings.pkg_list_dir+"/pkg.list"+" deleted" ); + try{ + dld_distfiles_count++; + if ((settings.del_pkg_list_when_dld_finished) and (dld_distfiles_count>distfiles_count)){ + //delete pkg.list file; + if(remove((settings.pkg_list_dir+"/pkg.list").c_str()) != 0 ) + error_log("Error in stats.cpp: inc_dld_distfiles_count(): Can't delete:"+settings.pkg_list_dir+"/pkg.list"); + else + debug(settings.pkg_list_dir+"/pkg.list"+" deleted" ); + } + }catch(...){ + error_log("Error in stats.cpp: show_totals()"); } } @@ -97,10 +63,8 @@ void Tstats::show_totals(){ // +" Secs:"+toString(now_timee.tv_sec) // +" usecs:"+toString(now_timee.tv_usec) ); - } - catch(...) - { - error_log_no_msg("Error in stats.cpp: show_totals()"); + }catch(...){ + error_log("Error in stats.cpp: show_totals()"); } } @@ -108,8 +72,6 @@ void Tstats::reset_previous_time(){ try{ gettimeofday(&previous_time,NULL); }catch(...){ - error_log_no_msg("Error in stats.cpp: reset_previous_time()"); + error_log("Error in stats.cpp: reset_previous_time()"); } -} -Tstats stats; -#endif
\ No newline at end of file +}
\ No newline at end of file diff --git a/segget/stats.h b/segget/stats.h new file mode 100644 index 0000000..dd14160 --- /dev/null +++ b/segget/stats.h @@ -0,0 +1,68 @@ +/* +* 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 +*/ + +#ifndef __STATS_H__ +#define __STATS_H__ + +#include <sys/time.h> +#include "connection.h" +#include "tui.h" +#include "settings.h" +using namespace std; + +class Tstats{ + private: + ulong dld_size; + ulong dld_distfiles_count; + uint total_size; + public: + ulong total_bytes_per_last_interval; + struct timeval previous_time; + double last_time_interval; + uint pkg_count; + uint distfiles_count; + Tstats(): + dld_size(0), + dld_distfiles_count(0), + total_size(0), + total_bytes_per_last_interval(0), + previous_time(), + last_time_interval(1), + pkg_count(0), + distfiles_count(0) + {}; + void inc_dld_size(ulong more_bytes){ dld_size+=more_bytes;}; + ulong get_dld_size(){return dld_size;}; + void inc_dld_distfiles_count(); + ulong get_dld_distfiles_count(){return dld_distfiles_count;}; + void inc_total_size(ulong more_bytes){ total_size+=more_bytes;}; + ulong get_total_size(){return total_size;}; + void show_totals(); + void reset_previous_time(); +}; + +Tstats stats; +#endif
\ No newline at end of file diff --git a/segget/str.cpp b/segget/str.cpp index 094d0e0..a9f652f 100644 --- a/segget/str.cpp +++ b/segget/str.cpp @@ -27,43 +27,60 @@ #include "str.h" using namespace std; -template<typename T> string toString(T t) -{ +template<typename T> string toString(T t){ stringstream s; s << t; return s.str(); } -template<typename T> string field(string prefix,T t, int width) -{ - stringstream s1,s2; - s1 << t; - width=width+prefix.length(); - s2.width(width); - s2 << prefix+s1.str(); - return s2.str(); +template<typename T> string field(string prefix,T t, int width){ + try{ + stringstream s1,s2; + s1 << t; + width=width+prefix.length(); + s2.width(width); + s2 << prefix+s1.str(); + return s2.str(); + }catch(...){ + error_log("Error in str.cpp: field()"); + return ""; + } } -int lower_char(int c) -{ - return tolower((unsigned char)c); +int lower_char(int c){ + try{ + return tolower((unsigned char)c); + }catch(...){ + error_log("Error in str.cpp: lower_char()"); + return 0; + } } -string noupper(string s){ - transform(s.begin(), s.end(), s.begin(), lower_char); - return s; +string noupper(string s){ + try{ + transform(s.begin(), s.end(), s.begin(), lower_char); + return s; + }catch(...){ + error_log("Error in str.cpp: noupper()"); + return ""; + } } string trim(std::string const& source, char const* delims) { - string result(source); - string::size_type index = result.find_last_not_of(delims); - if(index != string::npos) - result.erase(++index); - - index = result.find_first_not_of(delims); - if(index != string::npos) - result.erase(0, index); - else - result.erase(); - return result; -} + try{ + string result(source); + string::size_type index = result.find_last_not_of(delims); + if(index != string::npos) + result.erase(++index); + + index = result.find_first_not_of(delims); + if(index != string::npos) + result.erase(0, index); + else + result.erase(); + return result; + }catch(...){ + error_log("Error in str.cpp: trim()"); + return ""; + } +}
\ No newline at end of file diff --git a/segget/tui.cpp b/segget/tui.cpp index 355fc98..3b880ae 100644 --- a/segget/tui.cpp +++ b/segget/tui.cpp @@ -30,18 +30,20 @@ extern Tsettings settings; const uint CONNECTION_LINES=5; void msg(uint y, uint x, string msg_text){ + try{ move(y,x); string ready_msg_text=msg_text+" "; printw(ready_msg_text.c_str()); refresh(); + }catch(...){ + error_log_no_msg("Error in tui.cpp: msg()"); + } } void msg_connecting(uint connection_num, uint distfile_num, uint segment_num, string msg_text){ try{ msg(connection_num*CONNECTION_LINES+1,0,"DF#"+toString(distfile_num)+" Seg#"+toString(segment_num)+" "+msg_text); - } - catch(...) - { + }catch(...){ error_log_no_msg("Error in tui.cpp: msg_connecting()"); } } @@ -69,9 +71,7 @@ void msg_segment_progress(uint connection_num, uint network_num, uint segment_nu +field(" = ",percent,3)+"%%" +speed_str +avg_speed_str); - } - catch(...) - { + }catch(...){ error_log_no_msg("Error in tui.cpp: msg_segment_progress()"); } } @@ -79,101 +79,112 @@ void msg_segment_progress(uint connection_num, uint network_num, uint segment_nu void msg_status1(uint connection_num, uint segment_num, string msg_text){ try{ msg(connection_num*CONNECTION_LINES+2,0,"Seg#"+toString(segment_num)+" "+msg_text); - } - catch(...) - { + }catch(...){ error_log_no_msg("Error in tui.cpp: msg_status1()"); } } void msg_status2(uint connection_num, string msg_text){ try{ msg(connection_num*CONNECTION_LINES+3,0,msg_text); - } - catch(...) - { + }catch(...){ error_log_no_msg("Error in tui.cpp: msg_status2()"); } } void msg_clean_connection(uint connection_num){ - msg(connection_num*CONNECTION_LINES,0," "); - msg(connection_num*CONNECTION_LINES+1,0," "); - msg(connection_num*CONNECTION_LINES+2,0," "); - msg(connection_num*CONNECTION_LINES+3,0," "); + try{ + msg(connection_num*CONNECTION_LINES,0," "); + msg(connection_num*CONNECTION_LINES+1,0," "); + msg(connection_num*CONNECTION_LINES+2,0," "); + msg(connection_num*CONNECTION_LINES+3,0," "); + }catch(...){ + error_log_no_msg("Error in tui.cpp: msg_clean_connection()"); + } } void msg_error(string error_text){ try{ msg(20,0, error_text); - } - catch(...) - { + }catch(...){ error_log_no_msg("Error in tui.cpp: msg_error()"); } } void msg_total(string msg_text){ try{ msg(settings.max_connections*CONNECTION_LINES,0,msg_text); - } - catch(...) - { + }catch(...){ error_log_no_msg("Error in tui.cpp: msg_total()"); } } void log(string log_msg_text){ - msg(settings.max_connections*CONNECTION_LINES+1,0, "LOG:"+log_msg_text); - ofstream file; - file.exceptions (ofstream::failbit | ofstream::badbit); try{ - file.open((settings.logs_dir+"/"+settings.general_log_file).c_str(), ios::app); + msg(settings.max_connections*CONNECTION_LINES+1,0, "LOG:"+log_msg_text); + ofstream file; + file.exceptions (ofstream::failbit | ofstream::badbit); + try{ + file.open((settings.logs_dir+"/"+settings.general_log_file).c_str(), ios::app); + }catch(...){ + error_log("Error opening "+settings.logs_dir+"/"+settings.general_log_file+"."); + return; + } + try{ + file << log_msg_text << endl; + file.close(); + } + catch(...){ + error_log("Error while writing "+settings.logs_dir+"/"+settings.general_log_file+"."); + return; + } }catch(...){ - error_log("Error opening "+settings.logs_dir+"/"+settings.general_log_file+"."); - return; - } - try{ - file << log_msg_text << endl; - file.close(); - } - catch(...){ - error_log("Error while writing "+settings.logs_dir+"/"+settings.general_log_file+"."); - return; + error_log("Error in tui.cpp: log()"); } } void debug(string debug_msg_text){ - msg(settings.max_connections*CONNECTION_LINES+2,0, "DEBUG:"+debug_msg_text); - ofstream file; - file.exceptions (ofstream::failbit | ofstream::badbit); - try{ - file.open((settings.logs_dir+"/"+settings.debug_log_file).c_str(), ios::app); - } - catch(...){ - error_log("Error opening "+settings.logs_dir+"/"+settings.debug_log_file+"."); - return; - } try{ - file << debug_msg_text << endl; - file.close(); - } - catch(...){ - error_log("Error while writing "+settings.logs_dir+"/"+settings.debug_log_file+"."); - return; + msg(settings.max_connections*CONNECTION_LINES+2,0, "DEBUG:"+debug_msg_text); + ofstream file; + file.exceptions (ofstream::failbit | ofstream::badbit); + try{ + file.open((settings.logs_dir+"/"+settings.debug_log_file).c_str(), ios::app); + } + catch(...){ + error_log("Error opening "+settings.logs_dir+"/"+settings.debug_log_file+"."); + return; + } + try{ + file << debug_msg_text << endl; + file.close(); + } + catch(...){ + error_log("Error while writing "+settings.logs_dir+"/"+settings.debug_log_file+"."); + return; + } + }catch(...){ + error_log("Error in tui.cpp: debug()"); } } void error_log_no_msg(string error_msg_text){ - ofstream file ((settings.logs_dir+"/"+settings.error_log_file).c_str(), ios::app); - file << error_msg_text << endl; - file.close(); + try{ + ofstream file ((settings.logs_dir+"/"+settings.error_log_file).c_str(), ios::app); + file << error_msg_text << endl; + file.close(); + }catch(...){ + fprintf(stderr, "Error opening error log file."); + fprintf(stderr, "Error log file: %s/%s",settings.logs_dir.c_str(),settings.error_log_file.c_str()); + } } void error_log(string error_msg_text){ - ofstream file ((settings.logs_dir+"/"+settings.error_log_file).c_str(), ios::app); - file << error_msg_text << endl; - file.close(); + try{ + ofstream file ((settings.logs_dir+"/"+settings.error_log_file).c_str(), ios::app); + file << error_msg_text << endl; + file.close(); + }catch(...){ + fprintf(stderr, "Error opening error log file."); + fprintf(stderr, "Error log file: %s/%s",settings.logs_dir.c_str(),settings.error_log_file.c_str()); + } try{ msg(settings.max_connections*CONNECTION_LINES+3,0, "ERROR:"+error_msg_text); - } - catch(...) - { - error_log_no_msg("Error calling msg() in tui.cpp: error_log()"); + }catch(...){ + error_log_no_msg("Error in tui.cpp: error_log()"); } - }
\ No newline at end of file diff --git a/segget/utils.cpp b/segget/utils.cpp index fdbbf5a..1179363 100644 --- a/segget/utils.cpp +++ b/segget/utils.cpp @@ -24,6 +24,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "utils.h" + ulong time_left_from(timeval from_time){ try{ timeval now_time; diff --git a/segget/utils.h b/segget/utils.h index b286a79..d32208f 100644 --- a/segget/utils.h +++ b/segget/utils.h @@ -27,7 +27,6 @@ #ifndef __UTILS_H__ #define __UTILS_H__ -#include "utils.h" #include "sys/time.h" ulong time_left_from(timeval from_time); |