[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdeutils/ark
From: Raphael Kubo da Costa <kubito () gmail ! com>
Date: 2011-01-24 0:29:30
Message-ID: 20110124002930.98FCFAC8BF () svn ! kde ! org
[Download RAW message or body]
SVN commit 1216559 by rkcosta:
cliinterface: Add the PasswordPromptPattern parameter.
Plugins can now specify a regular expression that matches password
prompts, which are now detected by CliInterface.
Header-protected rar and 7z files should be working now.
M +39 -0 kerfuffle/cliinterface.cpp
M +23 -0 kerfuffle/cliinterface.h
M +2 -0 plugins/cli7zplugin/cliplugin.cpp
M +2 -0 plugins/clirarplugin/cliplugin.cpp
--- trunk/KDE/kdeutils/ark/kerfuffle/cliinterface.cpp #1216558:1216559
@@ -443,6 +443,7 @@
bool foundErrorMessage =
(checkForErrorMessage(QLatin1String( lines.last() ), WrongPasswordPatterns) \
||
checkForErrorMessage(QLatin1String( lines.last() ), \
ExtractionFailedPatterns) || + \
checkForPasswordPromptMessage(QLatin1String(lines.last())) || \
checkForFileExistsMessage(QLatin1String( lines.last() )));
if (foundErrorMessage) {
@@ -508,6 +509,26 @@
}
if (m_operationMode == List) {
+ if (checkForPasswordPromptMessage(line)) {
+ kDebug() << "Found a password prompt";
+
+ Kerfuffle::PasswordNeededQuery query(filename());
+ userQuery(&query);
+ query.waitForResponse();
+
+ if (query.responseCancelled()) {
+ failOperation();
+ return;
+ }
+
+ setPassword(query.password());
+
+ const QString response(password() + QLatin1Char('\n'));
+ writeToProcess(response.toLocal8Bit());
+
+ return;
+ }
+
if (checkForErrorMessage(line, WrongPasswordPatterns)) {
kDebug() << "Wrong password!";
error(i18n("Incorrect password."));
@@ -532,6 +553,24 @@
}
}
+bool CliInterface::checkForPasswordPromptMessage(const QString& line)
+{
+ const QString passwordPromptPattern(m_param.value(PasswordPromptPattern).toString());
+
+ if (passwordPromptPattern.isEmpty())
+ return false;
+
+ if (m_passwordPromptPattern.isEmpty()) {
+ m_passwordPromptPattern.setPattern(m_param.value(PasswordPromptPattern).toString());
+ }
+
+ if (m_passwordPromptPattern.indexIn(line) != -1) {
+ return true;
+ }
+
+ return false;
+}
+
bool CliInterface::checkForFileExistsMessage(const QString& line)
{
if (m_existsPattern.isEmpty()) {
--- trunk/KDE/kdeutils/ark/kerfuffle/cliinterface.h #1216558:1216559
@@ -49,6 +49,13 @@
*/
CaptureProgress = 0,
+ /**
+ * QString
+ * Default: empty
+ * A regexp pattern that matches the program's password prompt.
+ */
+ PasswordPromptPattern,
+
///////////////[ LIST ]/////////////
/**
@@ -259,6 +266,21 @@
void substituteListVariables(QStringList& params);
void cacheParameterList();
+
+ /**
+ * Checks whether a line of the program's output is a password prompt.
+ *
+ * It uses the regular expression in the @c PasswordPromptPattern parameter
+ * for the check.
+ *
+ * @param line A line of the program's output.
+ *
+ * @return @c true if the given @p line is a password prompt, @c false
+ * otherwise.
+ */
+
+ bool checkForPasswordPromptMessage(const QString& line);
+
bool checkForFileExistsMessage(const QString& line);
bool handleFileExistsMessage(const QString& filename);
bool checkForErrorMessage(const QString& line, int parameterIndex);
@@ -295,6 +317,7 @@
QByteArray m_stdOutData;
bool m_userCancelled;
QRegExp m_existsPattern;
+ QRegExp m_passwordPromptPattern;
#ifdef Q_OS_WIN
KProcess *m_process;
--- trunk/KDE/kdeutils/ark/plugins/cli7zplugin/cliplugin.cpp #1216558:1216559
@@ -69,6 +69,8 @@
<< QLatin1String( "S" ) //autoskip
<< QLatin1String( "Q" ) //cancel
;
+
+ p[PasswordPromptPattern] = QLatin1String("Enter password \\(will not be \
echoed\\) :"); }
return p;
--- trunk/KDE/kdeutils/ark/plugins/clirarplugin/cliplugin.cpp #1216558:1216559
@@ -79,6 +79,8 @@
p[AddArgs] = QStringList() << QLatin1String( "a" ) << QLatin1String( \
"$Archive" ) << QLatin1String( "$Files" );
+ p[PasswordPromptPattern] = QLatin1String("Enter password \\(will not be \
echoed\\) for"); +
p[WrongPasswordPatterns] = QStringList() << QLatin1String("password \
incorrect") << QLatin1String("wrong password");
p[ExtractionFailedPatterns] = QStringList() << QLatin1String( "CRC failed" ) \
<< QLatin1String( "Cannot find volume" ); }
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic