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 ******/
CTX = NULL;
setlocale(LC_ALL, "");
gpgme_check_version(NULL);
gpgme_set_locale(NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL));
@ -197,6 +199,11 @@ bool AuthGPGimpl::InitAuth ()
{
std::string HomeDir;
if (!CTX) {
std::cerr << "Error with gpg initialization. Is gpg missing ?" << std::endl;
return false;
}
#ifdef WINDOWS_SYS
if (RsInit::isPortable ()) {
// 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 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
* @return one is initialisation has been successful
* @return RS_INIT_...
*/
static int InitRetroShare(int argc, char **argv,
bool strictCheck=true);
static int InitRetroShare(int argc, char **argv, bool strictCheck=true);
/*!
* 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:
* a) InitRetroshare() returns true -> autoLoad/password Set.
* a) InitRetroshare() returns RS_INIT_HAVE_ACCOUNT -> autoLoad/password Set.
* b) SelectGPGAccount() && LoadPassword()
*
* This wrapper is used to lock the profile first before

View File

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

View File

@ -1193,7 +1193,7 @@ Verfügbar: %3</translation>
<message>
<location filename="../gui/settings/ChatPage.ui" line="+522"/>
<source>Chat Settings</source>
<translation>Chat EInstellungen</translation>
<translation>Chat Einstellungen</translation>
</message>
<message>
<location line="+6"/>
@ -4225,7 +4225,7 @@ Fill in your GPG password when asked, to sign your new key.</source>
<translation></translation>
</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>
<translation type="unfinished"></translation>
</message>
@ -6493,29 +6493,29 @@ Rechtsklick und als Freund hinzufügen um zu verbinden.</translation>
<message>
<location filename="../gui/NetworkDialog.ui" line="+111"/>
<location line="+168"/>
<location line="+235"/>
<location line="+238"/>
<source>Name</source>
<translation>Name</translation>
</message>
<message>
<location line="-398"/>
<location line="+403"/>
<location line="-401"/>
<location line="+406"/>
<source>Did I authenticated peer</source>
<translation>Habe ich den Peer authentifiziert</translation>
</message>
<message>
<location line="-400"/>
<location line="-403"/>
<source>Did I sign his gpg key</source>
<translation>Habe ich seinen GPG Schlüssel unterzeichnet</translation>
</message>
<message>
<location line="+10"/>
<location line="+400"/>
<location line="+403"/>
<source>Cert Id</source>
<translation>ID des Zertifikates</translation>
</message>
<message>
<location line="-316"/>
<location line="-319"/>
<source>Search Network</source>
<translation>Netzwerksuche</translation>
</message>
@ -6553,7 +6553,7 @@ p, li { white-space: pre-wrap; }
<translation>Externer IP Adressen Finder</translation>
</message>
<message>
<location line="+121"/>
<location line="+124"/>
<source>Add Friend</source>
<translation>Freund hinzufügen</translation>
</message>
@ -6583,18 +6583,18 @@ p, li { white-space: pre-wrap; }
<translation>Willkommen bei RetroShare.</translation>
</message>
<message>
<location filename="../gui/NetworkDialog.ui" line="-566"/>
<location filename="../gui/NetworkDialog.ui" line="-569"/>
<source>Network</source>
<translation>Netzwerk</translation>
</message>
<message>
<location line="+88"/>
<location line="+400"/>
<location line="+403"/>
<source>Did peer authenticated me</source>
<translation>Hat mich der Peer authentifiziert</translation>
</message>
<message>
<location line="-232"/>
<location line="-235"/>
<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>
</message>
@ -6604,7 +6604,7 @@ p, li { white-space: pre-wrap; }
<translation>Log</translation>
</message>
<message>
<location line="+194"/>
<location line="+197"/>
<source>Clear</source>
<translation>Leeren</translation>
</message>
@ -6704,16 +6704,29 @@ p, li { white-space: pre-wrap; }
</message>
<message>
<location line="+4"/>
<source>UPNP NOT FOUND.</source>
<translation>UPNP wurde nicht gefunden.</translation>
<source>UPNP not found or not enabled.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location line="+5"/>
<source>DHT OK.</source>
<translation>DHT OK.</translation>
<source>DHT is running.</source>
<translation type="unfinished"></translation>
</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>
<translation>Stun externe Adresserkennung arbeitet.</translation>
</message>
@ -6743,17 +6756,16 @@ p, li { white-space: pre-wrap; }
<translation>Externer IP Adress-Finder hat nichts gefunden</translation>
</message>
<message>
<location line="-27"/>
<source>DHT is not working (down).</source>
<translation>DHT läuft nicht.</translation>
<translation type="obsolete">DHT läuft nicht.</translation>
</message>
<message>
<location filename="../gui/NetworkDialog.ui" line="-162"/>
<location filename="../gui/NetworkDialog.ui" line="-165"/>
<source>Network Status</source>
<translation>Netzwerk-Status</translation>
</message>
<message>
<location line="+167"/>
<location line="+170"/>
<source>Set Tabs Right</source>
<translation>Setze Tabs nach Rechts</translation>
</message>
@ -6783,7 +6795,7 @@ p, li { white-space: pre-wrap; }
<translation>Setze Tabs Form Dreieck</translation>
</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;
&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; }
@ -6801,7 +6813,7 @@ p, li { white-space: pre-wrap; }
<translation>Peer ID</translation>
</message>
<message>
<location filename="../gui/NetworkDialog.cpp" line="-90"/>
<location filename="../gui/NetworkDialog.cpp" line="-117"/>
<source>Sorry, create certificate failed</source>
<translation>Zertifikat-Datei konnte nicht erstellt werden</translation>
</message>
@ -6819,54 +6831,69 @@ p, li { white-space: pre-wrap; }
<context>
<name>NetworkView</name>
<message>
<location filename="../gui/NetworkView.cpp" line="+306"/>
<source>Hide Settings</source>
<translation>Einstellungen verbergen</translation>
<translation type="obsolete">Einstellungen verbergen</translation>
</message>
<message>
<location line="+4"/>
<source>Show Settings</source>
<translation>Einstellungen anzeigen</translation>
<translation type="obsolete">Einstellungen anzeigen</translation>
</message>
<message>
<location filename="../gui/NetworkView.ui" line="+13"/>
<location filename="../gui/NetworkView.ui" line="+14"/>
<source>Form</source>
<translation>Formular</translation>
</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>
<translation>Erneuern</translation>
</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>
<location line="+20"/>
<source>Edge length:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Settings</source>
<translation>Einstellungen</translation>
<translation type="obsolete">Einstellungen</translation>
</message>
<message>
<location line="+35"/>
<source>Show Friends of Friends</source>
<translation>Zeige Freunde von Freunden</translation>
<translation type="obsolete">Zeige Freunde von Freunden</translation>
</message>
<message>
<location line="+18"/>
<source>Draw Friend Connections</source>
<translation>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>
<translation type="obsolete">Zeichne Verbindungen zwischen Freunden</translation>
</message>
</context>
<context>
@ -8541,7 +8568,24 @@ p, li { white-space: pre-wrap; }
<context>
<name>QObject</name>
<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"/>
<source>Multiple instances</source>
<translation>Mehrere Instanzen</translation>
@ -10127,12 +10171,12 @@ p, li { white-space: pre-wrap; }
<context>
<name>SplashScreen</name>
<message>
<location filename="../main.cpp" line="-29"/>
<location filename="../main.cpp" line="-28"/>
<source>Load profile</source>
<translation>Lade Profil</translation>
</message>
<message>
<location line="+35"/>
<location line="+41"/>
<source>Load configuration</source>
<translation>Lade Konfiguration</translation>
</message>

View File

@ -67,7 +67,28 @@ int main(int argc, char *argv[])
/* RetroShare Core Objects */
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
path maybe wrong, when no profile exist
@ -87,62 +108,63 @@ int main(int argc, char *argv[])
QSplashScreen splashScreen(QPixmap(":/images/splash.png")/* , Qt::WindowStaysOnTopHint*/);
/* Login Dialog */
if (!okStart)
{
/* check for existing Certificate */
std::string userName;
StartDialog *sd = NULL;
bool genCert = false;
std::list<std::string> accountIds;
if (RsInit::getAccountIds(accountIds) && (accountIds.size() > 0))
switch (initResult) {
case RS_INIT_OK:
{
sd = new StartDialog();
sd->show();
/* Login Dialog */
/* check for existing Certificate */
std::string userName;
while(sd -> isVisible())
StartDialog *sd = NULL;
bool genCert = false;
std::list<std::string> accountIds;
if (RsInit::getAccountIds(accountIds) && (accountIds.size() > 0))
{
rshare.processEvents();
sd = new StartDialog();
sd->show();
while(sd -> isVisible())
{
rshare.processEvents();
#ifdef WIN32
Sleep(10);
Sleep(10);
#else // __LINUX__
usleep(10000);
usleep(10000);
#endif
}
/* if we're logged in */
genCert = sd->requestedNewCert();
delete (sd);
}
else
{
genCert = true;
}
/* if we're logged in */
genCert = sd->requestedNewCert();
delete (sd);
if (genCert)
{
GenCertDialog gd;
gd.exec ();
}
splashScreen.show();
}
else
break;
case RS_INIT_HAVE_ACCOUNT:
{
genCert = true;
}
splashScreen.show();
splashScreen.showMessage(rshare.translate("SplashScreen", "Load profile"), Qt::AlignHCenter | Qt::AlignBottom);
if (genCert)
{
GenCertDialog gd;
gd.exec ();
}
std::string preferredId, gpgId, gpgName, gpgEmail, sslName;
RsInit::getPreferedAccountId(preferredId);
splashScreen.show();
}
else
{
splashScreen.show();
splashScreen.showMessage(rshare.translate("SplashScreen", "Load profile"), Qt::AlignHCenter | Qt::AlignBottom);
if (RsInit::getAccountDetails(preferredId, gpgId, gpgName, gpgEmail, sslName))
{
RsInit::SelectGPGAccount(gpgId);
}
std::string preferredId, gpgId, gpgName, gpgEmail, sslName;
RsInit::getPreferedAccountId(preferredId);
if (RsInit::getAccountDetails(preferredId,
gpgId, gpgName, gpgEmail, sslName))
{
RsInit::SelectGPGAccount(gpgId);
}
// true: note auto-login is active
// true: note auto-login is active
int retVal = RsInit::LockAndLoadCertificates(true);
switch(retVal)
{
@ -164,6 +186,13 @@ int main(int argc, char *argv[])
return 1;
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);

View File

@ -71,7 +71,21 @@ int main(int argc, char **argv)
**/
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()
* otherwise loaded from commandline.
@ -128,7 +142,3 @@ int main(int argc, char **argv)
}
return 1;
}