mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -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
@ -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) ***************************/
|
||||
|
@ -503,6 +503,11 @@ void MainWindow::doQuit()
|
||||
rApp->quit();
|
||||
}
|
||||
|
||||
void MainWindow::displayErrorMessage(int a,int b,const QString& error_msg)
|
||||
{
|
||||
QMessageBox::critical(NULL, tr("Internal Error"),error_msg) ;
|
||||
}
|
||||
|
||||
void MainWindow::closeEvent(QCloseEvent *e)
|
||||
{
|
||||
static bool firstTime = true;
|
||||
|
@ -102,6 +102,7 @@ public slots:
|
||||
void showWindow(Page page);
|
||||
|
||||
void updateHashingInfo(const QString&) ;
|
||||
void displayErrorMessage(int,int,const QString&) ;
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *);
|
||||
|
@ -31,11 +31,7 @@
|
||||
|
||||
void NotifyQt::notifyErrorMsg(int list, int type, std::string msg)
|
||||
{
|
||||
(void) list;
|
||||
(void) type;
|
||||
(void) msg;
|
||||
|
||||
return;
|
||||
emit errorOccurred(list,type,QString::fromStdString(msg)) ;
|
||||
}
|
||||
|
||||
void NotifyQt::notifyOwnAvatarChanged()
|
||||
|
@ -40,6 +40,7 @@ class NotifyQt: public QObject, public NotifyBase
|
||||
virtual void notifyPeerHasNewAvatar(std::string peer_id) ;
|
||||
virtual void notifyOwnAvatarChanged() ;
|
||||
virtual void notifyOwnStatusMessageChanged() ;
|
||||
|
||||
virtual std::string askForPassword(const std::string& window_title,const std::string& text) ;
|
||||
|
||||
signals:
|
||||
@ -61,6 +62,7 @@ class NotifyQt: public QObject, public NotifyBase
|
||||
void peerHasNewAvatar(const QString& peer_id) const ;
|
||||
void ownAvatarChanged() const ;
|
||||
void ownStatusMessageChanged() const ;
|
||||
void errorOccurred(int,int,const QString&) const ;
|
||||
|
||||
public slots:
|
||||
|
||||
|
@ -149,6 +149,7 @@ int main(int argc, char *argv[])
|
||||
QObject::connect(notify,SIGNAL(ownStatusMessageChanged()),w->peersDialog,SLOT(loadmypersonalstatus()));
|
||||
|
||||
QObject::connect(notify,SIGNAL(logInfoChanged(const QString&)),w->networkDialog,SLOT(setLogInfo(QString))) ;
|
||||
QObject::connect(notify,SIGNAL(errorOccurred(int,int,const QString&)),w,SLOT(displayErrorMessage(int,int,const QString&))) ;
|
||||
|
||||
QObject::connect(ConfCertDialog::instance(),SIGNAL(configChanged()),w->networkDialog,SLOT(insertConnect())) ;
|
||||
QObject::connect(w->peersDialog,SIGNAL(friendsUpdated()),w->networkDialog,SLOT(insertConnect())) ;
|
||||
|
Loading…
Reference in New Issue
Block a user