mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 06:06:10 -04:00
resurected error msg window. Added a check for file hashes in FileRequest() to detect issues with badly formed file links
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2230 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
13bfd5617d
commit
3621ef4a95
7 changed files with 49 additions and 5 deletions
|
@ -23,6 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <sstream>
|
||||
#include "util/rsdebug.h"
|
||||
#include "util/rsdir.h"
|
||||
#include "rsiface/rstypes.h"
|
||||
|
@ -243,8 +244,42 @@ void ftServer::run()
|
|||
/********************** Controller Access **********************/
|
||||
/***************************************************************/
|
||||
|
||||
bool ftServer::checkHash(const std::string& hash,std::string& error_string)
|
||||
{
|
||||
static const uint32_t HASH_LENGTH = 40 ;
|
||||
|
||||
if(hash.length() != HASH_LENGTH)
|
||||
{
|
||||
std::ostringstream is ;
|
||||
is << "Line too long : " << hash.length() << " chars, " << HASH_LENGTH << " expected." ;
|
||||
is.flush() ;
|
||||
error_string = is.str() ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
for(uint i=0;i<hash.length();++i)
|
||||
if(!((hash[i] > 47 && hash[i] < 58) || (hash[i] > 96 && hash[i] < 103)))
|
||||
{
|
||||
std::ostringstream is;
|
||||
is << "unexpected char code=" << (int)hash[i] << " '" << hash[i] << "'" ;
|
||||
is.flush() ;
|
||||
error_string = is.str() ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool ftServer::FileRequest(std::string fname, std::string hash, uint64_t size, std::string dest, uint32_t flags, std::list<std::string> srcIds)
|
||||
{
|
||||
std::string error_string ;
|
||||
|
||||
if(!checkHash(hash,error_string))
|
||||
{
|
||||
rsicontrol->getNotify().notifyErrorMsg(0,0,"Error handling hash \""+hash+"\". This hash appears to be invalid(Error string=\""+error_string+"\"). This is probably due an bad handling of strings.") ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
std::cerr << "Requesting " << fname << std::endl ;
|
||||
|
||||
if(mFtController->alreadyHaveFile(hash))
|
||||
|
|
|
@ -102,6 +102,10 @@ void StartupThreads();
|
|||
/* own thread */
|
||||
virtual void run();
|
||||
|
||||
// Checks that the given hash is well formed. Used to chase
|
||||
// string bugs.
|
||||
static bool checkHash(const std::string& hash,std::string& error_string) ;
|
||||
|
||||
/***************************************************************/
|
||||
/*************** Control Interface *****************************/
|
||||
/************** (Implements RsFiles) ***************************/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue