Commit 03250ca3 authored by Daniel Nicoletti's avatar Daniel Nicoletti
Browse files

Rely on cupsAdminGetServerSettings() return value to know if the request went...

Rely on cupsAdminGetServerSettings() return value to know if the request went fine since it might just read the local file
BUG: 308314
parent 40f788d1
......@@ -477,7 +477,7 @@ int KCupsConnection::renewDBusSubscription(int subscriptionId, int leaseDuration
return renewDBusSubscription(-1, leaseDuration, events);
#endif // CUPS_VERSION_MAJOR == 1 && CUPS_VERSION_MINOR >= 6
} else {
kDebug() << "Request failed" << lastError();
kDebug() << "Request failed" << cupsLastError() << httpGetStatus(CUPS_HTTP_DEFAULT);
// When the server stops/restarts we will have some error so ignore it
ret = subscriptionId;
}
......@@ -1045,13 +1045,6 @@ bool KCupsConnection::retry(const char *resource)
return false;
}
ipp_status_t KCupsConnection::lastError()
{
ipp_status_t status = cupsLastError();
return status;
}
const char * password_cb(const char *prompt, http_t *http, const char *method, const char *resource, void *user_data)
{
Q_UNUSED(prompt)
......
......@@ -345,15 +345,6 @@ protected:
virtual void run();
bool readyToStart();
bool retry(const char *resource);
/**
* Always use this method to get the last error
* because if the cups connection fails, the last
* error will be an internal error and we need
* to destroy this thread in order to recover
* from this error.
*/
ipp_status_t lastError();
ReturnArguments request(ipp_op_e operation,
const char *resource,
const QVariantHash &reqValues,
......
......@@ -69,7 +69,7 @@ void KCupsRequest::getPPDS(const QString &make)
"/",
request,
true);
setError(m_connection->lastError(), QString::fromUtf8(cupsLastErrorString()));
setError(httpGetStatus(CUPS_HTTP_DEFAULT), cupsLastError(), QString::fromUtf8(cupsLastErrorString()));
setFinished();
} else {
invokeMethod("getPPDS", make);
......@@ -130,7 +130,7 @@ void KCupsRequest::getDevices(int timeout, QStringList includeSchemes, QStringLi
(cups_device_cb_t) choose_device_cb,
this);
} while (m_connection->retry("/admin/"));
setError(m_connection->lastError(), QString::fromUtf8(cupsLastErrorString()));
setError(httpGetStatus(CUPS_HTTP_DEFAULT), cupsLastError(), QString::fromUtf8(cupsLastErrorString()));
setFinished(true);
} else {
invokeMethod("getDevices", timeout, includeSchemes, excludeSchemes);
......@@ -166,7 +166,7 @@ void KCupsRequest::getPrinters(QStringList attributes, const QVariantHash &argum
m_printers << KCupsPrinter(arguments);
}
setError(m_connection->lastError(), QString::fromUtf8(cupsLastErrorString()));
setError(httpGetStatus(CUPS_HTTP_DEFAULT), cupsLastError(), QString::fromUtf8(cupsLastErrorString()));
setFinished();
} else {
invokeMethod("getPrinters", qVariantFromValue(attributes), arguments);
......@@ -195,7 +195,7 @@ void KCupsRequest::getPrinterAttributes(const QString &printerName, bool isClass
m_printers << KCupsPrinter(args);
}
setError(m_connection->lastError(), QString::fromUtf8(cupsLastErrorString()));
setError(httpGetStatus(CUPS_HTTP_DEFAULT), cupsLastError(), QString::fromUtf8(cupsLastErrorString()));
setFinished();
} else {
invokeMethod("getPrinterAttributes", printerName, isClass, qVariantFromValue(attributes));
......@@ -233,7 +233,7 @@ void KCupsRequest::getJobs(const QString &printerName, bool myJobs, int whichJob
m_jobs << KCupsJob(arguments);
}
setError(m_connection->lastError(), QString::fromUtf8(cupsLastErrorString()));
setError(httpGetStatus(CUPS_HTTP_DEFAULT), cupsLastError(), QString::fromUtf8(cupsLastErrorString()));
setFinished();
} else {
invokeMethod("getJobs", printerName, myJobs, whichJobs, qVariantFromValue(attributes));
......@@ -259,7 +259,7 @@ void KCupsRequest::getJobAttributes(int jobId, const QString &printerUri, QStrin
m_jobs << KCupsJob(arguments);
}
setError(m_connection->lastError(), QString::fromUtf8(cupsLastErrorString()));
setError(httpGetStatus(CUPS_HTTP_DEFAULT), cupsLastError(), QString::fromUtf8(cupsLastErrorString()));
setFinished();
} else {
invokeMethod("getJobAttributes", jobId, printerUri, qVariantFromValue(attributes));
......@@ -273,17 +273,21 @@ void KCupsRequest::getServerSettings()
int num_settings;
cups_option_t *settings;
QVariantHash arguments;
cupsAdminGetServerSettings(CUPS_HTTP_DEFAULT, &num_settings, &settings);
int ret = cupsAdminGetServerSettings(CUPS_HTTP_DEFAULT, &num_settings, &settings);
for (int i = 0; i < num_settings; ++i) {
QString name = QString::fromUtf8(settings[i].name);
QString value = QString::fromUtf8(settings[i].value);
arguments[name] = value;
}
cupsFreeOptions(num_settings, settings);
if (ret) {
setError(HTTP_OK, IPP_OK, QString());
} else {
setError(httpGetStatus(CUPS_HTTP_DEFAULT), cupsLastError(), QString::fromUtf8(cupsLastErrorString()));
}
m_server = KCupsServer(arguments);
} while (m_connection->retry("/admin/"));
setError(m_connection->lastError(), QString::fromUtf8(cupsLastErrorString()));
setFinished();
} else {
invokeMethod("getServerSettings");
......@@ -300,7 +304,7 @@ void KCupsRequest::getPrinterPPD(const QString &printerName)
m_ppdFile = filename;
kDebug() << m_ppdFile;
} while (m_connection->retry("/"));
setError(m_connection->lastError(), QString::fromUtf8(cupsLastErrorString()));
setError(httpGetStatus(CUPS_HTTP_DEFAULT), cupsLastError(), QString::fromUtf8(cupsLastErrorString()));
setFinished();
} else {
invokeMethod("getPrinterPPD", printerName);
......@@ -327,7 +331,7 @@ void KCupsRequest::setServerSettings(const KCupsServer &server)
cupsAdminSetServerSettings(CUPS_HTTP_DEFAULT, num_settings, settings);
cupsFreeOptions(num_settings, settings);
} while (m_connection->retry("/admin/"));
setError(m_connection->lastError(), QString::fromUtf8(cupsLastErrorString()));
setError(httpGetStatus(CUPS_HTTP_DEFAULT), cupsLastError(), QString::fromUtf8(cupsLastErrorString()));
setFinished();
} else {
invokeMethod("setServerSettings", qVariantFromValue(server));
......@@ -470,7 +474,7 @@ void KCupsRequest::printCommand(const QString &printerName, const QString &comma
&hold_option)) < 1) {
qWarning() << "Unable to send command to printer driver!";
setError(IPP_NOT_POSSIBLE, i18n("Unable to send command to printer driver!"));
setError(HTTP_OK, IPP_NOT_POSSIBLE, i18n("Unable to send command to printer driver!"));
setFinished();
return;
}
......@@ -490,8 +494,8 @@ void KCupsRequest::printCommand(const QString &printerName, const QString &comma
cupsFinishDocument(CUPS_HTTP_DEFAULT, printerName.toUtf8());
}
setError(m_connection->lastError(), QString::fromUtf8(cupsLastErrorString()));
if (m_connection->lastError() >= IPP_REDIRECTION_OTHER_SITE) {
setError(httpGetStatus(CUPS_HTTP_DEFAULT), cupsLastError(), QString::fromUtf8(cupsLastErrorString()));
if (httpGetStatus(CUPS_HTTP_DEFAULT), cupsLastError() >= IPP_REDIRECTION_OTHER_SITE) {
qWarning() << "Unable to send command to printer driver!";
cupsCancelJob(printerName.toUtf8(), job_id);
......@@ -499,7 +503,7 @@ void KCupsRequest::printCommand(const QString &printerName, const QString &comma
return; // Return to avoid a new try
}
} while (m_connection->retry("/"));
setError(m_connection->lastError(), QString::fromUtf8(cupsLastErrorString()));
setError(httpGetStatus(CUPS_HTTP_DEFAULT), cupsLastError(), QString::fromUtf8(cupsLastErrorString()));
setFinished();
} else {
invokeMethod("printCommand", printerName, command, title);
......@@ -592,7 +596,7 @@ void KCupsRequest::invokeMethod(const char *method,
QGenericArgument(arg7.typeName(), arg7.data()),
QGenericArgument(arg8.typeName(), arg8.data()));
if (m_finished) {
setError(IPP_BAD_REQUEST, i18n("Failed to invoke method: %1", method));
setError(HTTP_ERROR, IPP_BAD_REQUEST, i18n("Failed to invoke method: %1", method));
setFinished();
}
}
......@@ -605,7 +609,7 @@ void KCupsRequest::doOperation(int operation, const QString &resource, const QVa
request,
false);
setError(m_connection->lastError(), QString::fromUtf8(cupsLastErrorString()));
setError(httpGetStatus(CUPS_HTTP_DEFAULT), cupsLastError(), QString::fromUtf8(cupsLastErrorString()));
setFinished();
} else {
invokeMethod("doOperation", operation, resource, request);
......@@ -656,6 +660,11 @@ ipp_status_t KCupsRequest::error() const
return m_error;
}
http_status_t KCupsRequest::httpStatus() const
{
return m_httpStatus;
}
QString KCupsRequest::errorMsg() const
{
return m_errorMsg;
......@@ -666,8 +675,9 @@ KCupsConnection *KCupsRequest::connection() const
return m_connection;
}
void KCupsRequest::setError(ipp_status_t error, const QString &errorMsg)
void KCupsRequest::setError(http_status_t httpStatus, ipp_status_t error, const QString &errorMsg)
{
m_httpStatus = httpStatus;
m_error = error;
m_errorMsg = errorMsg;
}
......
......@@ -55,6 +55,7 @@ public:
*/
bool hasError() const;
ipp_status_t error() const;
http_status_t httpStatus() const;
QString serverError() const;
QString errorMsg() const;
......@@ -314,13 +315,14 @@ private:
const QVariant &arg7 = QVariant(),
const QVariant &arg8 = QVariant());
Q_INVOKABLE void doOperation(int operation, const QString &resource, const QVariantHash &request);
void setError(ipp_status_t error, const QString &errorMsg);
void setError(http_status_t httpStatus, ipp_status_t error, const QString &errorMsg);
void setFinished(bool delayed = false);
KCupsConnection *m_connection;
QEventLoop m_loop;
bool m_finished;
ipp_status_t m_error;
http_status_t m_httpStatus;
QString m_errorMsg;
ReturnArguments m_ppds;
KCupsServer m_server;
......
......@@ -49,7 +49,6 @@ PrintKCM::PrintKCM(QWidget *parent, const QVariantList &args) :
KCModule(PrintKCMFactory::componentData(), parent, args),
ui(new Ui::PrintKCM),
m_lastError(-1), // Force the error to run on the first time
m_gotServerSettings(false),
m_serverRequest(0)
{
KAboutData *aboutData;
......@@ -319,15 +318,6 @@ void PrintKCM::getServerSettingsFinished()
{
KCupsRequest *request = qobject_cast<KCupsRequest *>(sender());
// This is odd, when the server settings didn't change
// we get IPP_SERVICE_UNAVAILABLE and a message of "Not Modified"
// but we can't rely on the message since it's localized
kDebug() << request->errorMsg();
if (m_gotServerSettings == true && request->error() == IPP_SERVICE_UNAVAILABLE) {
request->deleteLater();
return;
}
// When we don't have any destinations error is set to IPP_NOT_FOUND
// we can safely ignore the error since it DOES bring the server settings
bool error = request->hasError() && request->error() != IPP_NOT_FOUND;
......@@ -344,7 +334,6 @@ void PrintKCM::getServerSettingsFinished()
i18nc("@title:window", "Failed"));
} else {
KCupsServer server = request->serverSettings();
m_gotServerSettings = true;
m_showSharedPrinters->setChecked(server.showSharedPrinters());
m_shareConnectedPrinters->setChecked(server.sharePrinters());
......
......@@ -58,7 +58,6 @@ private:
Ui::PrintKCM *ui;
PrinterModel *m_model;
int m_lastError;
bool m_gotServerSettings;
KCupsRequest *m_serverRequest;
QAction *m_showSharedPrinters;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment