[svn] pinentry - r220 - in trunk: . qt4
svn author wk
cvs at cvs.gnupg.org
Tue Mar 2 13:27:44 CET 2010
Author: wk
Date: 2010-03-02 13:27:43 +0100 (Tue, 02 Mar 2010)
New Revision: 220
Modified:
trunk/ChangeLog
trunk/qt4/main.cpp
Log:
invalid utf8 workaround
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2010-02-19 15:07:24 UTC (rev 219)
+++ trunk/ChangeLog 2010-03-02 12:27:43 UTC (rev 220)
@@ -1,3 +1,25 @@
+2010-03-02 Werner Koch <wk at g10code.com>
+
+ * qt4/main.cpp (from_utf8): Add extra braces for clarity.
+ (main): Copy the fixed --display string.
+
+2010-02-25 Marc Mutz <marc at kdab.com> (wk)
+
+ * qt4/main.cpp (from_utf8): don't throw InvalidUtf8(); for now,
+ fall back to QString::fromLocal8Bit()
+
+2010-02-22 Marc Mutz <marc at kdab.com> (wk)
+
+ * qt4/main.cpp (InvalidUtf8): New exception class.
+ (from_utf8): wrapper around QString::fromUtf8 throwing
+ InvalidUtf8.
+ (qt_cmd_handler): Use from_utf8 instead of QString::fromUtf8.
+ (qt_cmd_handler_ex): New wrapper around qt_cmd_handler.
+ (pinentry_cmd_handler): Use qt_cmd_handler_ex.
+
+ * qt4/main.cpp (qt_cmd_handler): Also handle accels in
+ SET{OK,NOTOK,CANCEL} string.
+
2010-02-19 Marc Mutz <marc at kdab.com> (wk)
* qt4/main.cpp (qt_cmd_handler), qt4/pinentrydialog.cpp
Modified: trunk/qt4/main.cpp
===================================================================
--- trunk/qt4/main.cpp 2010-02-19 15:07:24 UTC (rev 219)
+++ trunk/qt4/main.cpp 2010-03-02 12:27:43 UTC (rev 220)
@@ -43,6 +43,7 @@
#include <errno.h>
#include <memory>
+#include <stdexcept>
#ifdef FALLBACK_CURSES
#include <pinentry-curses.h>
@@ -102,6 +103,29 @@
}
};
+namespace {
+ class InvalidUtf8 : public std::invalid_argument {
+ public:
+ InvalidUtf8() : std::invalid_argument( "invalid utf8" ) {}
+ ~InvalidUtf8() throw() {}
+ };
+}
+
+static const bool GPG_AGENT_IS_PORTED_TO_ONLY_SEND_UTF8 = false;
+
+static QString from_utf8( const char * s ) {
+ const QString result = QString::fromUtf8( s );
+ if ( result.contains( QChar::ReplacementCharacter ) )
+ {
+ if ( GPG_AGENT_IS_PORTED_TO_ONLY_SEND_UTF8 )
+ throw InvalidUtf8();
+ else
+ return QString::fromLocal8Bit( s );
+ }
+
+ return result;
+}
+
static int
qt_cmd_handler (pinentry_t pe)
{
@@ -114,15 +138,15 @@
int want_pass = !!pe->pin;
const QString ok =
- pe->ok ? QString::fromUtf8( pe->ok ) :
- pe->default_ok ? escape_accel( QString::fromUtf8( pe->default_ok ) ) :
+ pe->ok ? escape_accel( from_utf8( pe->ok ) ) :
+ pe->default_ok ? escape_accel( from_utf8( pe->default_ok ) ) :
/* else */ QLatin1String( "&OK" ) ;
const QString cancel =
- pe->cancel ? QString::fromUtf8( pe->cancel ) :
- pe->default_cancel ? escape_accel( QString::fromUtf8( pe->default_cancel ) ) :
+ pe->cancel ? escape_accel( from_utf8( pe->cancel ) ) :
+ pe->default_cancel ? escape_accel( from_utf8( pe->default_cancel ) ) :
/* else */ QLatin1String( "&Cancel" ) ;
const QString title =
- pe->title ? QString::fromUtf8( pe->title ) :
+ pe->title ? from_utf8( pe->title ) :
/* else */ QLatin1String( "pinentry-qt4" ) ;
@@ -131,10 +155,10 @@
PinEntryDialog pinentry (parent, 0, true, !!pe->quality_bar);
pinentry.setPinentryInfo (pe);
- pinentry.setPrompt (escape_accel (QString::fromUtf8 (pe->prompt)) );
- pinentry.setDescription (QString::fromUtf8 (pe->description));
+ pinentry.setPrompt (escape_accel (from_utf8 (pe->prompt)) );
+ pinentry.setDescription (from_utf8 (pe->description));
if ( pe->title )
- pinentry.setWindowTitle( QString::fromUtf8( pe->title ) );
+ pinentry.setWindowTitle( from_utf8( pe->title ) );
/* If we reuse the same dialog window. */
pinentry.setPin (secqstring());
@@ -142,11 +166,11 @@
pinentry.setOkText (ok);
pinentry.setCancelText (cancel);
if (pe->error)
- pinentry.setError (QString::fromUtf8 (pe->error));
+ pinentry.setError (from_utf8 (pe->error));
if (pe->quality_bar)
- pinentry.setQualityBar (QString::fromUtf8 (pe->quality_bar));
+ pinentry.setQualityBar (from_utf8 (pe->quality_bar));
if (pe->quality_bar_tt)
- pinentry.setQualityBarTT (QString::fromUtf8 (pe->quality_bar_tt));
+ pinentry.setQualityBarTT (from_utf8 (pe->quality_bar_tt));
bool ret = pinentry.exec ();
if (!ret)
@@ -169,8 +193,8 @@
}
else
{
- const QString desc = pe->description ? QString::fromUtf8 ( pe->description ) : QString();
- const QString notok = pe->notok ? QString::fromUtf8 ( pe->notok ) : QString();
+ const QString desc = pe->description ? from_utf8 ( pe->description ) : QString();
+ const QString notok = pe->notok ? escape_accel (from_utf8 ( pe->notok )) : QString();
const QMessageBox::StandardButtons buttons =
pe->one_button ? QMessageBox::Ok :
@@ -211,8 +235,22 @@
}
}
-pinentry_cmd_handler_t pinentry_cmd_handler = qt_cmd_handler;
+static int
+qt_cmd_handler_ex (pinentry_t pe)
+{
+ try {
+ return qt_cmd_handler (pe);
+ } catch ( const InvalidUtf8 & ) {
+ pe->locale_err = true;
+ return pe->pin ? -1 : false ;
+ } catch ( ... ) {
+ pe->canceled = true;
+ return pe->pin ? -1 : false ;
+ }
+}
+pinentry_cmd_handler_t pinentry_cmd_handler = qt_cmd_handler_ex;
+
int
main (int argc, char *argv[])
{
@@ -249,7 +287,8 @@
for (done=0,p=*new_argv,i=0; i < argc; i++)
if (!done && !strcmp (argv[i], "--display"))
{
- new_argv[i] = "-display";
+ new_argv[i] = strcpy (p, argv[i]+1);
+ p += strlen (argv[i]+1) + 1;
done = 1;
}
else
More information about the Gnupg-commits
mailing list