Added new return codes to RsInit::InitRetroShare to know, what failed.

Show error box when gpg initialization failed.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3744 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2010-11-03 22:54:34 +00:00
parent 89f448d282
commit 0e41211f3c
6 changed files with 208 additions and 112 deletions

View File

@ -135,6 +135,8 @@ AuthGPGimpl::AuthGPGimpl()
{ {
RsStackMutex stack(gpgMtxEngine); /******* LOCKED ******/ RsStackMutex stack(gpgMtxEngine); /******* LOCKED ******/
CTX = NULL;
setlocale(LC_ALL, ""); setlocale(LC_ALL, "");
gpgme_check_version(NULL); gpgme_check_version(NULL);
gpgme_set_locale(NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL)); gpgme_set_locale(NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL));
@ -197,6 +199,11 @@ bool AuthGPGimpl::InitAuth ()
{ {
std::string HomeDir; std::string HomeDir;
if (!CTX) {
std::cerr << "Error with gpg initialization. Is gpg missing ?" << std::endl;
return false;
}
#ifdef WINDOWS_SYS #ifdef WINDOWS_SYS
if (RsInit::isPortable ()) { if (RsInit::isPortable ()) {
// set home dir of gpg to configdir\gnupg // set home dir of gpg to configdir\gnupg

View File

@ -26,7 +26,11 @@
* *
*/ */
// Initialize ok, result >= 0
#define RS_INIT_OK 0 // Initialize ok
#define RS_INIT_HAVE_ACCOUNT 1 // Initialize ok, have account
// Initialize failed, result < 0
#define RS_INIT_AUTH_FAILED -1 // AuthGPG::InitAuth failed
/**** /****
@ -55,10 +59,9 @@ class RsInit
* @param argc passed from executable * @param argc passed from executable
* @param argv commandline arguments passed to executable * @param argv commandline arguments passed to executable
* @param strictCheck set to true if you want rs to continue executing if invalid argument passed and vice versa * @param strictCheck set to true if you want rs to continue executing if invalid argument passed and vice versa
* @return one is initialisation has been successful * @return RS_INIT_...
*/ */
static int InitRetroShare(int argc, char **argv, static int InitRetroShare(int argc, char **argv, bool strictCheck=true);
bool strictCheck=true);
/*! /*!
* This return directory seperator for different platforms, not an issue anymore as C library can distinguish * This return directory seperator for different platforms, not an issue anymore as C library can distinguish
@ -107,7 +110,7 @@ class RsInit
/*! /*!
* Final Certificate load. This can be called if: * Final Certificate load. This can be called if:
* a) InitRetroshare() returns true -> autoLoad/password Set. * a) InitRetroshare() returns RS_INIT_HAVE_ACCOUNT -> autoLoad/password Set.
* b) SelectGPGAccount() && LoadPassword() * b) SelectGPGAccount() && LoadPassword()
* *
* This wrapper is used to lock the profile first before * This wrapper is used to lock the profile first before

View File

@ -586,7 +586,10 @@ int RsInit::InitRetroShare(int argcIgnored, char **argvIgnored, bool strictCheck
get_configinit(RsInitConfig::basedir, RsInitConfig::preferedId); get_configinit(RsInitConfig::basedir, RsInitConfig::preferedId);
/* Initialize AuthGPG */ /* Initialize AuthGPG */
AuthGPG::getAuthGPG()->InitAuth(); if (AuthGPG::getAuthGPG()->InitAuth() == false) {
std::cerr << "AuthGPG::InitAuth failed" << std::endl;
return RS_INIT_AUTH_FAILED;
}
//std::list<accountId> ids; //std::list<accountId> ids;
std::list<accountId>::iterator it; std::list<accountId>::iterator it;
@ -648,7 +651,7 @@ int RsInit::InitRetroShare(int argcIgnored, char **argvIgnored, bool strictCheck
if (RsInitConfig::havePasswd) if (RsInitConfig::havePasswd)
{ {
return 1; return RS_INIT_HAVE_ACCOUNT;
} }
RsInit::LoadPassword(RsInitConfig::preferedId, ""); RsInit::LoadPassword(RsInitConfig::preferedId, "");
@ -656,10 +659,10 @@ int RsInit::InitRetroShare(int argcIgnored, char **argvIgnored, bool strictCheck
if (RsTryAutoLogin()) if (RsTryAutoLogin())
{ {
RsInit::setAutoLogin(true); RsInit::setAutoLogin(true);
return 1; return RS_INIT_HAVE_ACCOUNT;
} }
} }
return 0; return RS_INIT_OK;
} }
/**************************** Access Functions for Init Data **************************/ /**************************** Access Functions for Init Data **************************/

View File

@ -1193,7 +1193,7 @@ Verfügbar: %3</translation>
<message> <message>
<location filename="../gui/settings/ChatPage.ui" line="+522"/> <location filename="../gui/settings/ChatPage.ui" line="+522"/>
<source>Chat Settings</source> <source>Chat Settings</source>
<translation>Chat EInstellungen</translation> <translation>Chat Einstellungen</translation>
</message> </message>
<message> <message>
<location line="+6"/> <location line="+6"/>
@ -4225,7 +4225,7 @@ Fill in your GPG password when asked, to sign your new key.</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location line="+208"/> <location line="+222"/>
<source>Click and drag the nodes around, and zoom with the mouse wheel or the &apos;+&apos; and &apos;-&apos; keys</source> <source>Click and drag the nodes around, and zoom with the mouse wheel or the &apos;+&apos; and &apos;-&apos; keys</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
@ -6493,29 +6493,29 @@ Rechtsklick und als Freund hinzufügen um zu verbinden.</translation>
<message> <message>
<location filename="../gui/NetworkDialog.ui" line="+111"/> <location filename="../gui/NetworkDialog.ui" line="+111"/>
<location line="+168"/> <location line="+168"/>
<location line="+235"/> <location line="+238"/>
<source>Name</source> <source>Name</source>
<translation>Name</translation> <translation>Name</translation>
</message> </message>
<message> <message>
<location line="-398"/> <location line="-401"/>
<location line="+403"/> <location line="+406"/>
<source>Did I authenticated peer</source> <source>Did I authenticated peer</source>
<translation>Habe ich den Peer authentifiziert</translation> <translation>Habe ich den Peer authentifiziert</translation>
</message> </message>
<message> <message>
<location line="-400"/> <location line="-403"/>
<source>Did I sign his gpg key</source> <source>Did I sign his gpg key</source>
<translation>Habe ich seinen GPG Schlüssel unterzeichnet</translation> <translation>Habe ich seinen GPG Schlüssel unterzeichnet</translation>
</message> </message>
<message> <message>
<location line="+10"/> <location line="+10"/>
<location line="+400"/> <location line="+403"/>
<source>Cert Id</source> <source>Cert Id</source>
<translation>ID des Zertifikates</translation> <translation>ID des Zertifikates</translation>
</message> </message>
<message> <message>
<location line="-316"/> <location line="-319"/>
<source>Search Network</source> <source>Search Network</source>
<translation>Netzwerksuche</translation> <translation>Netzwerksuche</translation>
</message> </message>
@ -6553,7 +6553,7 @@ p, li { white-space: pre-wrap; }
<translation>Externer IP Adressen Finder</translation> <translation>Externer IP Adressen Finder</translation>
</message> </message>
<message> <message>
<location line="+121"/> <location line="+124"/>
<source>Add Friend</source> <source>Add Friend</source>
<translation>Freund hinzufügen</translation> <translation>Freund hinzufügen</translation>
</message> </message>
@ -6583,18 +6583,18 @@ p, li { white-space: pre-wrap; }
<translation>Willkommen bei RetroShare.</translation> <translation>Willkommen bei RetroShare.</translation>
</message> </message>
<message> <message>
<location filename="../gui/NetworkDialog.ui" line="-566"/> <location filename="../gui/NetworkDialog.ui" line="-569"/>
<source>Network</source> <source>Network</source>
<translation>Netzwerk</translation> <translation>Netzwerk</translation>
</message> </message>
<message> <message>
<location line="+88"/> <location line="+88"/>
<location line="+400"/> <location line="+403"/>
<source>Did peer authenticated me</source> <source>Did peer authenticated me</source>
<translation>Hat mich der Peer authentifiziert</translation> <translation>Hat mich der Peer authentifiziert</translation>
</message> </message>
<message> <message>
<location line="-232"/> <location line="-235"/>
<source>Show keys that are not validated by the GPG web of trust</source> <source>Show keys that are not validated by the GPG web of trust</source>
<translation>Zeige Schlüssel, die nicht vom web of trust bestätigt sind</translation> <translation>Zeige Schlüssel, die nicht vom web of trust bestätigt sind</translation>
</message> </message>
@ -6604,7 +6604,7 @@ p, li { white-space: pre-wrap; }
<translation>Log</translation> <translation>Log</translation>
</message> </message>
<message> <message>
<location line="+194"/> <location line="+197"/>
<source>Clear</source> <source>Clear</source>
<translation>Leeren</translation> <translation>Leeren</translation>
</message> </message>
@ -6704,16 +6704,29 @@ p, li { white-space: pre-wrap; }
</message> </message>
<message> <message>
<location line="+4"/> <location line="+4"/>
<source>UPNP NOT FOUND.</source> <source>UPNP not found or not enabled.</source>
<translation>UPNP wurde nicht gefunden.</translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location line="+5"/> <location line="+5"/>
<source>DHT OK.</source> <source>DHT is running.</source>
<translation>DHT OK.</translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location line="+9"/> <location line="+4"/>
<source>DHT is off.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>UPNP NOT FOUND.</source>
<translation type="obsolete">UPNP wurde nicht gefunden.</translation>
</message>
<message>
<source>DHT OK.</source>
<translation type="obsolete">DHT OK.</translation>
</message>
<message>
<location line="+5"/>
<source>Stun external address detection is working.</source> <source>Stun external address detection is working.</source>
<translation>Stun externe Adresserkennung arbeitet.</translation> <translation>Stun externe Adresserkennung arbeitet.</translation>
</message> </message>
@ -6743,17 +6756,16 @@ p, li { white-space: pre-wrap; }
<translation>Externer IP Adress-Finder hat nichts gefunden</translation> <translation>Externer IP Adress-Finder hat nichts gefunden</translation>
</message> </message>
<message> <message>
<location line="-27"/>
<source>DHT is not working (down).</source> <source>DHT is not working (down).</source>
<translation>DHT läuft nicht.</translation> <translation type="obsolete">DHT läuft nicht.</translation>
</message> </message>
<message> <message>
<location filename="../gui/NetworkDialog.ui" line="-162"/> <location filename="../gui/NetworkDialog.ui" line="-165"/>
<source>Network Status</source> <source>Network Status</source>
<translation>Netzwerk-Status</translation> <translation>Netzwerk-Status</translation>
</message> </message>
<message> <message>
<location line="+167"/> <location line="+170"/>
<source>Set Tabs Right</source> <source>Set Tabs Right</source>
<translation>Setze Tabs nach Rechts</translation> <translation>Setze Tabs nach Rechts</translation>
</message> </message>
@ -6783,7 +6795,7 @@ p, li { white-space: pre-wrap; }
<translation>Setze Tabs Form Dreieck</translation> <translation>Setze Tabs Form Dreieck</translation>
</message> </message>
<message> <message>
<location line="-384"/> <location line="-387"/>
<source>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt; <source>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt; &lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; } p, li { white-space: pre-wrap; }
@ -6801,7 +6813,7 @@ p, li { white-space: pre-wrap; }
<translation>Peer ID</translation> <translation>Peer ID</translation>
</message> </message>
<message> <message>
<location filename="../gui/NetworkDialog.cpp" line="-90"/> <location filename="../gui/NetworkDialog.cpp" line="-117"/>
<source>Sorry, create certificate failed</source> <source>Sorry, create certificate failed</source>
<translation>Zertifikat-Datei konnte nicht erstellt werden</translation> <translation>Zertifikat-Datei konnte nicht erstellt werden</translation>
</message> </message>
@ -6819,54 +6831,69 @@ p, li { white-space: pre-wrap; }
<context> <context>
<name>NetworkView</name> <name>NetworkView</name>
<message> <message>
<location filename="../gui/NetworkView.cpp" line="+306"/>
<source>Hide Settings</source> <source>Hide Settings</source>
<translation>Einstellungen verbergen</translation> <translation type="obsolete">Einstellungen verbergen</translation>
</message> </message>
<message> <message>
<location line="+4"/>
<source>Show Settings</source> <source>Show Settings</source>
<translation>Einstellungen anzeigen</translation> <translation type="obsolete">Einstellungen anzeigen</translation>
</message> </message>
<message> <message>
<location filename="../gui/NetworkView.ui" line="+13"/> <location filename="../gui/NetworkView.ui" line="+14"/>
<source>Form</source> <source>Form</source>
<translation>Formular</translation> <translation>Formular</translation>
</message> </message>
<message> <message>
<location line="+38"/> <location line="+15"/>
<source>background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,stop:0 lightgray, stop:1 darkgray);</source>
<translation type="unfinished"></translation>
</message>
<message>
<location line="+9"/>
<source>Refresh</source> <source>Refresh</source>
<translation>Erneuern</translation> <translation>Erneuern</translation>
</message> </message>
<message>
<location line="+21"/>
<source>Basic</source>
<translation type="unfinished"></translation>
</message>
<message>
<location line="+5"/>
<source>Friends</source>
<translation type="unfinished">Freunde</translation>
</message>
<message>
<location line="+5"/>
<source>Extended</source>
<translation type="unfinished"></translation>
</message>
<message>
<location line="+8"/>
<source>Display mode:</source>
<translation type="unfinished"></translation>
</message>
<message>
<location line="+17"/>
<source>Friends level:</source>
<translation type="unfinished"></translation>
</message>
<message> <message>
<location line="+20"/> <location line="+20"/>
<source>Edge length:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Settings</source> <source>Settings</source>
<translation>Einstellungen</translation> <translation type="obsolete">Einstellungen</translation>
</message> </message>
<message> <message>
<location line="+35"/>
<source>Show Friends of Friends</source> <source>Show Friends of Friends</source>
<translation>Zeige Freunde von Freunden</translation> <translation type="obsolete">Zeige Freunde von Freunden</translation>
</message> </message>
<message> <message>
<location line="+18"/>
<source>Draw Friend Connections</source> <source>Draw Friend Connections</source>
<translation>Zeichne Verbindungen zwischen Freunden</translation> <translation type="obsolete">Zeichne Verbindungen zwischen Freunden</translation>
</message>
<message>
<location line="-87"/>
<source>background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,
stop:0 lightgray, stop:1 darkgray);
</source>
<translation></translation>
</message>
<message>
<location line="+76"/>
<source>Connect Signature</source>
<translation></translation>
</message> </message>
</context> </context>
<context> <context>
@ -8541,7 +8568,24 @@ p, li { white-space: pre-wrap; }
<context> <context>
<name>QObject</name> <name>QObject</name>
<message> <message>
<location filename="../main.cpp" line="+151"/> <location filename="../main.cpp" line="+75"/>
<location line="+119"/>
<source>RetroShare</source>
<translation>RetroShare</translation>
</message>
<message>
<location line="-113"/>
<source>Inititialize failed. Wrong or missing installation of gpg.</source>
<translation>Initialisierung fehlgeschlagen. GPG fehlt oder es ist eine falsche Version installiert.</translation>
</message>
<message>
<location line="+5"/>
<location line="+108"/>
<source>An unexpected error occured. Please report &apos;RsInit::InitRetroShare unexpected return code %1&apos;.</source>
<translation>Ein unerwarteter Fehler ist aufgetreten. Bitte melde &apos;RsInit::InitRetroShare unexpected return code %1&apos;.</translation>
</message>
<message>
<location line="-21"/>
<location line="+6"/> <location line="+6"/>
<source>Multiple instances</source> <source>Multiple instances</source>
<translation>Mehrere Instanzen</translation> <translation>Mehrere Instanzen</translation>
@ -10127,12 +10171,12 @@ p, li { white-space: pre-wrap; }
<context> <context>
<name>SplashScreen</name> <name>SplashScreen</name>
<message> <message>
<location filename="../main.cpp" line="-29"/> <location filename="../main.cpp" line="-28"/>
<source>Load profile</source> <source>Load profile</source>
<translation>Lade Profil</translation> <translation>Lade Profil</translation>
</message> </message>
<message> <message>
<location line="+35"/> <location line="+41"/>
<source>Load configuration</source> <source>Load configuration</source>
<translation>Lade Konfiguration</translation> <translation>Lade Konfiguration</translation>
</message> </message>

View File

@ -67,7 +67,28 @@ int main(int argc, char *argv[])
/* RetroShare Core Objects */ /* RetroShare Core Objects */
RsInit::InitRsConfig(); RsInit::InitRsConfig();
bool okStart = RsInit::InitRetroShare(argc, argv); int initResult = RsInit::InitRetroShare(argc, argv);
if (initResult < 0) {
/* Error occured */
QApplication dummyApp (argc, argv); // needed for QMessageBox
QMessageBox mb(QMessageBox::Critical, QObject::tr("RetroShare"), "", QMessageBox::Ok);
mb.setWindowIcon(QIcon(":/images/rstray3.png"));
switch (initResult) {
case RS_INIT_AUTH_FAILED:
std::cerr << "RsInit::InitRetroShare AuthGPG::InitAuth failed" << std::endl;
mb.setText(QObject::tr("Inititialize failed. Wrong or missing installation of gpg."));
break;
default:
/* Unexpected return code */
std::cerr << "RsInit::InitRetroShare unexpected return code " << initResult << std::endl;
mb.setText(QObject::tr("An unexpected error occured. Please report 'RsInit::InitRetroShare unexpected return code %1'.").arg(initResult));
break;
}
mb.exec();
return 1;
}
/* create global settings object /* create global settings object
path maybe wrong, when no profile exist path maybe wrong, when no profile exist
@ -87,9 +108,10 @@ int main(int argc, char *argv[])
QSplashScreen splashScreen(QPixmap(":/images/splash.png")/* , Qt::WindowStaysOnTopHint*/); QSplashScreen splashScreen(QPixmap(":/images/splash.png")/* , Qt::WindowStaysOnTopHint*/);
/* Login Dialog */ switch (initResult) {
if (!okStart) case RS_INIT_OK:
{ {
/* Login Dialog */
/* check for existing Certificate */ /* check for existing Certificate */
std::string userName; std::string userName;
@ -128,7 +150,8 @@ int main(int argc, char *argv[])
splashScreen.show(); splashScreen.show();
} }
else break;
case RS_INIT_HAVE_ACCOUNT:
{ {
splashScreen.show(); splashScreen.show();
splashScreen.showMessage(rshare.translate("SplashScreen", "Load profile"), Qt::AlignHCenter | Qt::AlignBottom); splashScreen.showMessage(rshare.translate("SplashScreen", "Load profile"), Qt::AlignHCenter | Qt::AlignBottom);
@ -136,8 +159,7 @@ int main(int argc, char *argv[])
std::string preferredId, gpgId, gpgName, gpgEmail, sslName; std::string preferredId, gpgId, gpgName, gpgEmail, sslName;
RsInit::getPreferedAccountId(preferredId); RsInit::getPreferedAccountId(preferredId);
if (RsInit::getAccountDetails(preferredId, if (RsInit::getAccountDetails(preferredId, gpgId, gpgName, gpgEmail, sslName))
gpgId, gpgName, gpgEmail, sslName))
{ {
RsInit::SelectGPGAccount(gpgId); RsInit::SelectGPGAccount(gpgId);
} }
@ -165,6 +187,13 @@ int main(int argc, char *argv[])
default: std::cerr << "StartDialog::loadCertificates() unexpected switch value " << retVal << std::endl; default: std::cerr << "StartDialog::loadCertificates() unexpected switch value " << retVal << std::endl;
} }
} }
break;
default:
/* Unexpected return code */
std::cerr << "RsInit::InitRetroShare unexpected return code " << initResult << std::endl;
QMessageBox::warning(0, QObject::tr("RetroShare"), QObject::tr("An unexpected error occured. Please report 'RsInit::InitRetroShare unexpected return code %1'.").arg(initResult));
return 1;
}
splashScreen.showMessage(rshare.translate("SplashScreen", "Load configuration"), Qt::AlignHCenter | Qt::AlignBottom); splashScreen.showMessage(rshare.translate("SplashScreen", "Load configuration"), Qt::AlignHCenter | Qt::AlignBottom);

View File

@ -71,7 +71,21 @@ int main(int argc, char **argv)
**/ **/
RsInit::InitRsConfig(); RsInit::InitRsConfig();
RsInit::InitRetroShare(argc, argv); int initResult = RsInit::InitRetroShare(argc, argv);
if (initResult < 0) {
/* Error occured */
switch (initResult) {
case RS_INIT_AUTH_FAILED:
std::cerr << "RsInit::InitRetroShare AuthGPG::InitAuth failed" << std::endl;
break;
default:
/* Unexpected return code */
std::cerr << "RsInit::InitRetroShare unexpected return code " << initResult << std::endl;
break;
}
return 1;
}
/* load password should be called at this point: LoadPassword() /* load password should be called at this point: LoadPassword()
* otherwise loaded from commandline. * otherwise loaded from commandline.
@ -128,7 +142,3 @@ int main(int argc, char **argv)
} }
return 1; return 1;
} }