diff options
author | Kostyantyn Ovechko <fastinetserver@gmail.com> | 2010-07-26 15:49:44 +0300 |
---|---|---|
committer | Kostyantyn Ovechko <fastinetserver@gmail.com> | 2010-07-26 15:49:44 +0300 |
commit | 5150d35df6e1a56c2e66b33aac9e86a3503b1bb7 (patch) | |
tree | 2d2b7764a5590decdca045dcbab89e06599f476f | |
parent | Implement checks for both (proxy_fetcher and request_server) queues. (diff) | |
download | idfetch-5150d35df6e1a56c2e66b33aac9e86a3503b1bb7.tar.gz idfetch-5150d35df6e1a56c2e66b33aac9e86a3503b1bb7.tar.bz2 idfetch-5150d35df6e1a56c2e66b33aac9e86a3503b1bb7.zip |
Check all set checksums, checksums are optional
-rw-r--r-- | segget/checksum.cpp | 63 | ||||
-rw-r--r-- | segget/distfile.cpp | 93 | ||||
-rw-r--r-- | segget/distfile.h | 10 | ||||
-rw-r--r-- | segget/pkg.cpp | 13 |
4 files changed, 135 insertions, 44 deletions
diff --git a/segget/checksum.cpp b/segget/checksum.cpp index cb36561..396c196 100644 --- a/segget/checksum.cpp +++ b/segget/checksum.cpp @@ -28,16 +28,21 @@ bool rmd160_ok(string distfile_filename, string portage_hash){ try{ + if (portage_hash=="") return true; std::string digest; CryptoPP::RIPEMD160 hash; CryptoPP::FileSource distfile_to_hash(distfile_filename.c_str(), true, new CryptoPP::HashFilter(hash, new CryptoPP::HexEncoder( new CryptoPP::StringSink(digest)))); - if (portage_hash==noupper(digest)) + if (portage_hash==noupper(digest)){ + log("RMD160 checksum for distfile:"+distfile_filename+" is [OK]"); return true; - else + }else{ + log("Error: RMD160 checksum for distfile:"+distfile_filename+" [FAILED]"); + error_log("Error: RMD160 checksum for distfile:"+distfile_filename+" [FAILED]"); return false; + } }catch(...){ error_log("Error in checksum.cpp : rmd160_ok()"); return false; @@ -45,6 +50,7 @@ bool rmd160_ok(string distfile_filename, string portage_hash){ } bool sha1_ok(string distfile_filename, string portage_hash){ try{ + if (portage_hash=="") return true; std::string digest; CryptoPP::SHA1 hash; CryptoPP::FileSource distfile_to_hash(distfile_filename.c_str(), true, @@ -52,10 +58,14 @@ bool sha1_ok(string distfile_filename, string portage_hash){ new CryptoPP::HexEncoder( new CryptoPP::StringSink(digest)))); // debug("SHA1:"+noupper(digest)); - if (portage_hash==noupper(digest)) + if (portage_hash==noupper(digest)){ + log("SHA1 checksum for distfile:"+distfile_filename+" is [OK]"); return true; - else + }else{ + log("Error: SHA1 checksum for distfile:"+distfile_filename+" [FAILED]"); + error_log("Error: SHA1 checksum for distfile:"+distfile_filename+" [FAILED]"); return false; + } }catch(...){ error_log("Error in checksum.cpp : sha1_ok()"); return false; @@ -63,6 +73,7 @@ bool sha1_ok(string distfile_filename, string portage_hash){ } bool sha256_ok(string distfile_filename, string portage_hash){ try{ + if (portage_hash=="") return true; std::string digest; CryptoPP::SHA256 hash; CryptoPP::FileSource distfile_to_hash(distfile_filename.c_str(), true, @@ -70,10 +81,14 @@ bool sha256_ok(string distfile_filename, string portage_hash){ new CryptoPP::HexEncoder( new CryptoPP::StringSink(digest)))); // debug("SHA256:"+noupper(digest)); - if (portage_hash==noupper(digest)) + if (portage_hash==noupper(digest)){ + log("SHA256 checksum for distfile:"+distfile_filename+" is [OK]"); return true; - else + }else{ + log("Error: SHA256 checksum for distfile:"+distfile_filename+" [FAILED]"); + error_log("Error: SHA256 checksum for distfile:"+distfile_filename+" [FAILED]"); return false; + } }catch(...){ error_log("Error in checksum.cpp : sha256_ok()"); return false; @@ -81,6 +96,7 @@ bool sha256_ok(string distfile_filename, string portage_hash){ } bool sha512_ok(string distfile_filename, string portage_hash){ try{ + if (portage_hash=="") return true; std::string digest; CryptoPP::SHA512 hash; CryptoPP::FileSource distfile_to_hash(distfile_filename.c_str(), true, @@ -88,10 +104,14 @@ bool sha512_ok(string distfile_filename, string portage_hash){ new CryptoPP::HexEncoder( new CryptoPP::StringSink(digest)))); // debug("SHA256:"+noupper(digest)); - if (portage_hash==noupper(digest)) + if (portage_hash==noupper(digest)){ + log("SHA512 checksum for distfile:"+distfile_filename+" is [OK]"); return true; - else + }else{ + log("Error: SHA512 checksum for distfile:"+distfile_filename+" [FAILED]"); + error_log("Error: SHA512 checksum for distfile:"+distfile_filename+" [FAILED]"); return false; + } }catch(...){ error_log("Error in checksum.cpp : sha512_ok()"); return false; @@ -99,6 +119,7 @@ bool sha512_ok(string distfile_filename, string portage_hash){ } bool whirlpool_ok(string distfile_filename, string portage_hash){ try{ + if (portage_hash=="") return true; std::string digest; CryptoPP::Whirlpool hash; CryptoPP::FileSource distfile_to_hash(distfile_filename.c_str(), true, @@ -106,10 +127,14 @@ bool whirlpool_ok(string distfile_filename, string portage_hash){ new CryptoPP::HexEncoder( new CryptoPP::StringSink(digest)))); // debug("SHA256:"+noupper(digest)); - if (portage_hash==noupper(digest)) + if (portage_hash==noupper(digest)){ + log("WHIRLPOOL checksum for distfile:"+distfile_filename+" is [OK]"); return true; - else + }else{ + log("Error: WHIRLPOOL checksum for distfile:"+distfile_filename+" [FAILED]"); + error_log("Error: WHIRLPOOL checksum for distfile:"+distfile_filename+" [FAILED]"); return false; + } }catch(...){ error_log("Error in checksum.cpp : whirlpool_ok()"); return false; @@ -117,6 +142,7 @@ bool whirlpool_ok(string distfile_filename, string portage_hash){ } bool md5_ok(string distfile_filename, string portage_hash){ try{ + if (portage_hash=="") return true; std::string digest; CryptoPP::Weak::MD5 hash; CryptoPP::FileSource distfile_to_hash(distfile_filename.c_str(), true, @@ -124,10 +150,14 @@ bool md5_ok(string distfile_filename, string portage_hash){ new CryptoPP::HexEncoder( new CryptoPP::StringSink(digest)))); // debug("SHA256:"+noupper(digest)); - if (portage_hash==noupper(digest)) + if (portage_hash==noupper(digest)){ + log("MD5 checksum for distfile:"+distfile_filename+" is [OK]"); return true; - else + }else{ + log("Error: MD5 checksum for distfile:"+distfile_filename+" [FAILED]"); + error_log("Error: MD5 checksum for distfile:"+distfile_filename+" [FAILED]"); return false; + } }catch(...){ error_log("Error in checksum.cpp : md5_ok()"); return false; @@ -135,6 +165,7 @@ bool md5_ok(string distfile_filename, string portage_hash){ } bool crc32_ok(string distfile_filename, string portage_hash){ try{ + if (portage_hash=="") return true; std::string digest; CryptoPP::CRC32 hash; CryptoPP::FileSource distfile_to_hash(distfile_filename.c_str(), true, @@ -142,10 +173,14 @@ bool crc32_ok(string distfile_filename, string portage_hash){ new CryptoPP::HexEncoder( new CryptoPP::StringSink(digest)))); // debug("SHA256:"+noupper(digest)); - if (portage_hash==noupper(digest)) + if (portage_hash==noupper(digest)){ + log("CRC32 checksum for distfile:"+distfile_filename+" is [OK]"); return true; - else + }else{ + log("Error: CRC32 checksum for distfile:"+distfile_filename+" [FAILED]"); + error_log("Error: CRC32 checksum for distfile:"+distfile_filename+" [FAILED]"); return false; + } }catch(...){ error_log("Error in checksum.cpp : crc32_ok()"); return false; diff --git a/segget/distfile.cpp b/segget/distfile.cpp index 8e85d7a..f3825a1 100644 --- a/segget/distfile.cpp +++ b/segget/distfile.cpp @@ -149,7 +149,7 @@ bool Tdistfile::allows_new_actions(){ // DPROXY_FAILED, // DPROXY_DOWNLOADED, // DWAITING, -// DDOWNLOADING, +// DDOWNLOADING,json_object_object_get(json_obj_distfile,"SHA512") } void Tdistfile::init(){ @@ -207,21 +207,59 @@ bool Tdistfile::check_if_dld(){ } } -void Tdistfile::load_distfile_from_json(json_object* json_obj_distfile){ +bool Tdistfile::load_distfile_from_json(json_object* json_obj_distfile){ try{ - name=json_object_get_string(json_object_object_get(json_obj_distfile,"name")); - size=atoi(json_object_to_json_string(json_object_object_get(json_obj_distfile,"size"))); - RMD160=json_object_get_string(json_object_object_get(json_obj_distfile,"RMD160")); - SHA1=json_object_get_string(json_object_object_get(json_obj_distfile,"SHA1")); - SHA256=json_object_get_string(json_object_object_get(json_obj_distfile,"SHA256")); + json_object* json_obj_buffer; + json_obj_buffer=json_object_object_get(json_obj_distfile,"name"); + if (json_obj_buffer){ + name=json_object_get_string(json_obj_buffer); + }else{ + return true; + } + json_obj_buffer=json_object_object_get(json_obj_distfile,"size"); + if (json_obj_buffer){ + size=atoi(json_object_get_string(json_obj_buffer)); + }else{ + return true; + } + json_obj_buffer=json_object_object_get(json_obj_distfile,"RMD160"); + if (json_obj_buffer){ + RMD160=json_object_get_string(json_obj_buffer); + } + json_obj_buffer=json_object_object_get(json_obj_distfile,"SHA1"); + if (json_obj_buffer){ + SHA1=json_object_get_string(json_obj_buffer); + } + json_obj_buffer=json_object_object_get(json_obj_distfile,"SHA256"); + if (json_obj_buffer){ + SHA256=json_object_get_string(json_obj_buffer); + } + json_obj_buffer=json_object_object_get(json_obj_distfile,"SHA512"); + if (json_obj_buffer){ + SHA512=json_object_get_string(json_obj_buffer); + } + json_obj_buffer=json_object_object_get(json_obj_distfile,"WHIRLPOOL"); + if (json_obj_buffer){ + WHIRLPOOL=json_object_get_string(json_obj_buffer); + } + json_obj_buffer=json_object_object_get(json_obj_distfile,"MD5"); + if (json_obj_buffer){ + MD5=json_object_get_string(json_obj_buffer); + } + json_obj_buffer=json_object_object_get(json_obj_distfile,"CRC32"); + if (json_obj_buffer){ + CRC32=json_object_get_string(json_obj_buffer); + } if (not(check_if_dld())){ json_data=json_object_to_json_string(json_obj_distfile); split_into_segments(); load_url_list(json_object_object_get(json_obj_distfile,"url_list")); } + debug("Added distfile: "+name+" to download queue"); }catch(...){ error_log("Error: distfile.cpp: load_distfile_from_json()"); } + return false; } void Tdistfile::split_into_segments(){ @@ -762,32 +800,41 @@ int Tdistfile::combine_segments(){ return 5; } try{ - if (rmd160_ok(settings.distfiles_dir+"/"+name,RMD160)) - log("RMD160 checksum for distfile:"+name+" is [OK]"); - else{ - log("Error: RMD160 checksum for distfile:"+name+" [FAILED]"); - error_log("Error: RMD160 checksum for distfile:"+name+" [FAILED]"); + if (! rmd160_ok(settings.distfiles_dir+"/"+name,RMD160)){ status=DFAILED; return 10; - } + }; - if (sha1_ok(settings.distfiles_dir+"/"+name,SHA1)) - log("SHA1 checksum for distfile:"+name+" is [OK]"); - else{ - log("Error: SHA1 checksum for distfile:"+name+" [FAILED]"); - error_log("Error: SHA1 checksum for distfile:"+name+" [FAILED]"); + if (! sha1_ok(settings.distfiles_dir+"/"+name,SHA1)){ status=DFAILED; return 11; } - if (sha256_ok(settings.distfiles_dir+"/"+name,SHA256)) - log("SHA256 checksum for distfile:"+name+" is [OK]"); - else{ - log("Error: SHA256 checksum for distfile:"+name+" [FAILED]"); - error_log("Error: SHA256 checksum for distfile:"+name+" [FAILED]"); + if (! sha256_ok(settings.distfiles_dir+"/"+name,SHA256)){ status=DFAILED; return 12; } +/* + if (! sha512_ok(settings.distfiles_dir+"/"+name,SHA512)){ + status=DFAILED; + return 13; + } + + if (! whirlpool_ok(settings.distfiles_dir+"/"+name,WHIRLPOOL)){ + status=DFAILED; + return 14; + } + + if (! md5_ok(settings.distfiles_dir+"/"+name,MD5)){ + status=DFAILED; + return 15; + } + + if (! crc32_ok(settings.distfiles_dir+"/"+name,CRC32)){ + status=DFAILED; + return 16; + } + */ status=DDOWNLOADED; if (settings.provide_mirror_dir!="none"){ symlink_distfile_to_provide_mirror_dir(); diff --git a/segget/distfile.h b/segget/distfile.h index 8d42894..973bf67 100644 --- a/segget/distfile.h +++ b/segget/distfile.h @@ -111,6 +111,10 @@ class Tdistfile{ string RMD160; string SHA1; string SHA256; + string SHA512; + string WHIRLPOOL; + string MD5; + string CRC32; uint url_count; uint segment_size; Tdistfile(): @@ -130,6 +134,10 @@ class Tdistfile{ RMD160(""), SHA1(""), SHA256(""), + SHA512(""), + WHIRLPOOL(""), + MD5(""), + CRC32(""), url_count(0), segment_size(settings.max_segment_size) {init();}; @@ -139,7 +147,7 @@ class Tdistfile{ int request(ulong network_num, string msg); void init(); bool allows_new_actions(); - void load_distfile_from_json(json_object* json_obj_distfile); + bool load_distfile_from_json(json_object* json_obj_distfile); void load_url_list(json_object* json_array_distfile_urllist); void split_into_segments(); uint provide_local_network(CURLM* cm, uint connection_num, uint seg_num, uint network_priority); diff --git a/segget/pkg.cpp b/segget/pkg.cpp index a6c9887..e3a0a41 100644 --- a/segget/pkg.cpp +++ b/segget/pkg.cpp @@ -40,12 +40,13 @@ int Tpkg::push_back_distfile(json_object* json_obj_distfile){ try{ distfile_count++; Tdistfile * Pcur_distfile=new Tdistfile(); - Pdistfile_list.push_back(Pcur_distfile); - Pcur_distfile->load_distfile_from_json(json_obj_distfile); - - string distfile_name=json_object_get_string(json_object_object_get(json_obj_distfile,"name")); - debug("Added distfile: "+distfile_name+" to download queue"); - return R_PF_ADDED_TO_PROXY_QUEUE; + if (Pcur_distfile->load_distfile_from_json(json_obj_distfile)){ + error_log("Error in pkg.cpp: push_back_distfile(): while loading distfile"); + return R_PF_ERROR_ADDING_TO_PROXY_QUEUE; + }else{ + Pdistfile_list.push_back(Pcur_distfile); + return R_PF_ADDED_TO_PROXY_QUEUE; + } }catch(...){ error_log("Error in pkg.cpp: pushback_distfile()"); return R_PF_ERROR_ADDING_TO_PROXY_QUEUE; |