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:
csoler 2010-02-07 18:10:12 +00:00
parent 13bfd5617d
commit 3621ef4a95
7 changed files with 49 additions and 5 deletions

View File

@ -23,6 +23,7 @@
* *
*/ */
#include <sstream>
#include "util/rsdebug.h" #include "util/rsdebug.h"
#include "util/rsdir.h" #include "util/rsdir.h"
#include "rsiface/rstypes.h" #include "rsiface/rstypes.h"
@ -243,8 +244,42 @@ void ftServer::run()
/********************** Controller Access **********************/ /********************** 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) 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 ; std::cerr << "Requesting " << fname << std::endl ;
if(mFtController->alreadyHaveFile(hash)) if(mFtController->alreadyHaveFile(hash))

View File

@ -102,6 +102,10 @@ void StartupThreads();
/* own thread */ /* own thread */
virtual void run(); 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 *****************************/ /*************** Control Interface *****************************/
/************** (Implements RsFiles) ***************************/ /************** (Implements RsFiles) ***************************/

View File

@ -503,6 +503,11 @@ void MainWindow::doQuit()
rApp->quit(); 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) void MainWindow::closeEvent(QCloseEvent *e)
{ {
static bool firstTime = true; static bool firstTime = true;

View File

@ -102,6 +102,7 @@ public slots:
void showWindow(Page page); void showWindow(Page page);
void updateHashingInfo(const QString&) ; void updateHashingInfo(const QString&) ;
void displayErrorMessage(int,int,const QString&) ;
protected: protected:
void closeEvent(QCloseEvent *); void closeEvent(QCloseEvent *);

View File

@ -31,11 +31,7 @@
void NotifyQt::notifyErrorMsg(int list, int type, std::string msg) void NotifyQt::notifyErrorMsg(int list, int type, std::string msg)
{ {
(void) list; emit errorOccurred(list,type,QString::fromStdString(msg)) ;
(void) type;
(void) msg;
return;
} }
void NotifyQt::notifyOwnAvatarChanged() void NotifyQt::notifyOwnAvatarChanged()

View File

@ -40,6 +40,7 @@ class NotifyQt: public QObject, public NotifyBase
virtual void notifyPeerHasNewAvatar(std::string peer_id) ; virtual void notifyPeerHasNewAvatar(std::string peer_id) ;
virtual void notifyOwnAvatarChanged() ; virtual void notifyOwnAvatarChanged() ;
virtual void notifyOwnStatusMessageChanged() ; virtual void notifyOwnStatusMessageChanged() ;
virtual std::string askForPassword(const std::string& window_title,const std::string& text) ; virtual std::string askForPassword(const std::string& window_title,const std::string& text) ;
signals: signals:
@ -61,6 +62,7 @@ class NotifyQt: public QObject, public NotifyBase
void peerHasNewAvatar(const QString& peer_id) const ; void peerHasNewAvatar(const QString& peer_id) const ;
void ownAvatarChanged() const ; void ownAvatarChanged() const ;
void ownStatusMessageChanged() const ; void ownStatusMessageChanged() const ;
void errorOccurred(int,int,const QString&) const ;
public slots: public slots:

View File

@ -149,6 +149,7 @@ int main(int argc, char *argv[])
QObject::connect(notify,SIGNAL(ownStatusMessageChanged()),w->peersDialog,SLOT(loadmypersonalstatus())); 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(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(ConfCertDialog::instance(),SIGNAL(configChanged()),w->networkDialog,SLOT(insertConnect())) ;
QObject::connect(w->peersDialog,SIGNAL(friendsUpdated()),w->networkDialog,SLOT(insertConnect())) ; QObject::connect(w->peersDialog,SIGNAL(friendsUpdated()),w->networkDialog,SLOT(insertConnect())) ;