diff --git a/libkcups/KCupsConnection.cpp b/libkcups/KCupsConnection.cpp index 2646bbb..57976b6 100644 --- a/libkcups/KCupsConnection.cpp +++ b/libkcups/KCupsConnection.cpp @@ -1,899 +1,899 @@ /*************************************************************************** * Copyright (C) 2010-2018 by Daniel Nicoletti * * dantti12@gmail.com * * Copyright (C) 2012 Harald Sitter * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; see the file COPYING. If not, write to * * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301, USA. * ***************************************************************************/ #include "KCupsConnection.h" #include "Debug.h" #include "KCupsPasswordDialog.h" #include "KIppRequest.h" #include #include #include #include #include #include #include #define RENEW_INTERVAL 3500 #define SUBSCRIPTION_DURATION 3600 #define DBUS_SERVER_RESTARTED "server-restarted" // ServerRestarted #define DBUS_SERVER_STARTED "server-started" // ServerStarted #define DBUS_SERVER_STOPPED "server-stopped" // ServerStopped #define DBUS_SERVER_AUDIT "server-audit" // ServerAudit #define DBUS_PRINTER_RESTARTED "printer-restarted" // PrinterRestarted #define DBUS_PRINTER_SHUTDOWN "printer-shutdown" // PrinterShutdown #define DBUS_PRINTER_STOPPED "printer-stopped" // PrinterStopped #define DBUS_PRINTER_STATE_CHANGED "printer-state-changed" // PrinterStateChanged #define DBUS_PRINTER_FINISHINGS_CHANGED "printer-finishings-changed" // PrinterFinishingsChanged #define DBUS_PRINTER_MEDIA_CHANGED "printer-media-changed" // PrinterMediaChanged #define DBUS_PRINTER_ADDED "printer-added" // PrinterAdded #define DBUS_PRINTER_DELETED "printer-deleted" // PrinterDeleted #define DBUS_PRINTER_MODIFIED "printer-modified" // PrinterModified #define DBUS_JOB_STATE_CHANGED "job-state-changed" // JobState #define DBUS_JOB_CREATED "job-created" // JobCreated #define DBUS_JOB_COMPLETED "job-completed" // JobCompleted #define DBUS_JOB_STOPPED "job-stopped" // JobStopped #define DBUS_JOB_CONFIG_CHANGED "job-config-changed" // JobConfigChanged #define DBUS_JOB_PROGRESS "job-progress" // JobProgress Q_DECLARE_METATYPE(QList) Q_DECLARE_METATYPE(QList) KCupsConnection* KCupsConnection::m_instance = nullptr; static int password_retries = 0; static int total_retries = 0; static int internalErrorCount = 0; const char * password_cb(const char *prompt, http_t *http, const char *method, const char *resource, void *user_data); KCupsConnection* KCupsConnection::global() { if (!m_instance) { m_instance = new KCupsConnection(qApp); } return m_instance; } KCupsConnection::KCupsConnection(QObject *parent) : QThread(parent) { init(); } KCupsConnection::KCupsConnection(const QUrl &server, QObject *parent) : QThread(parent), m_serverUrl(server) { qRegisterMetaType("KIppRequest"); init(); } KCupsConnection::~KCupsConnection() { if (m_instance == this) { m_instance = nullptr; } m_passwordDialog->deleteLater(); quit(); wait(); delete m_renewTimer; delete m_subscriptionTimer; } void KCupsConnection::setPasswordMainWindow(WId mainwindow) { m_passwordDialog->setMainWindow(mainwindow); } void KCupsConnection::init() { // Creating the dialog before start() will make it run on the gui thread m_passwordDialog = new KCupsPasswordDialog; // setup the DBus subscriptions // Server related signals // ServerStarted notifierConnect(QLatin1String("ServerStarted"), this, SIGNAL(serverStarted(QString))); // ServerStopped notifierConnect(QLatin1String("ServerStopped"), this, SIGNAL(serverStopped(QString))); // ServerRestarted notifierConnect(QLatin1String("ServerRestarted"), this, SIGNAL(serverRestarted(QString))); // ServerAudit notifierConnect(QLatin1String("ServerAudit"), this, SIGNAL(serverAudit(QString))); // Printer related signals // PrinterAdded notifierConnect(QLatin1String("PrinterAdded"), this, SIGNAL(printerAdded(QString,QString,QString,uint,QString,bool))); // PrinterModified notifierConnect(QLatin1String("PrinterModified"), this, SIGNAL(printerModified(QString,QString,QString,uint,QString,bool))); // PrinterDeleted notifierConnect(QLatin1String("PrinterDeleted"), this, SIGNAL(printerDeleted(QString,QString,QString,uint,QString,bool))); // PrinterStateChanged notifierConnect(QLatin1String("PrinterStateChanged"), this, SIGNAL(printerStateChanged(QString,QString,QString,uint,QString,bool))); // PrinterStopped notifierConnect(QLatin1String("PrinterStopped"), this, SIGNAL(printerStopped(QString,QString,QString,uint,QString,bool))); // PrinterShutdown notifierConnect(QLatin1String("PrinterShutdown"), this, SIGNAL(printerShutdown(QString,QString,QString,uint,QString,bool))); // PrinterRestarted notifierConnect(QLatin1String("PrinterRestarted"), this, SIGNAL(printerRestarted(QString,QString,QString,uint,QString,bool))); // PrinterMediaChanged notifierConnect(QLatin1String("PrinterMediaChanged"), this, SIGNAL(printerMediaChanged(QString,QString,QString,uint,QString,bool))); // PrinterFinishingsChanged notifierConnect(QLatin1String("PrinterFinishingsChanged"), this, SIGNAL(PrinterFinishingsChanged(QString,QString,QString,uint,QString,bool))); // Job related signals // JobState notifierConnect(QLatin1String("JobState"), this, SIGNAL(jobState(QString,QString,QString,uint,QString,bool,uint,uint,QString,QString,uint))); // JobCreated notifierConnect(QLatin1String("JobCreated"), this, SIGNAL(jobCreated(QString,QString,QString,uint,QString,bool,uint,uint,QString,QString,uint))); // JobStopped notifierConnect(QLatin1String("JobStopped"), this, SIGNAL(jobStopped(QString,QString,QString,uint,QString,bool,uint,uint,QString,QString,uint))); // JobConfigChanged notifierConnect(QLatin1String("JobConfigChanged"), this, SIGNAL(jobConfigChanged(QString,QString,QString,uint,QString,bool,uint,uint,QString,QString,uint))); // JobProgress notifierConnect(QLatin1String("JobProgress"), this, SIGNAL(jobProgress(QString,QString,QString,uint,QString,bool,uint,uint,QString,QString,uint))); // JobCompleted notifierConnect(QLatin1String("JobCompleted"), this, SIGNAL(jobCompleted(QString,QString,QString,uint,QString,bool,uint,uint,QString,QString,uint))); // This signal is needed since the cups registration thing // doesn't emit printerAdded when we add a printer class // This is emitted when a printer/queue is changed QDBusConnection::systemBus().connect(QLatin1String(""), QLatin1String("/com/redhat/PrinterSpooler"), QLatin1String("com.redhat.PrinterSpooler"), QLatin1String("PrinterAdded"), this, SIGNAL(rhPrinterAdded(QString))); // This signal is needed since the cups registration thing // sometimes simple stops working... don't ask me why // This is emitted when a printer/queue is changed QDBusConnection::systemBus().connect(QLatin1String(""), QLatin1String("/com/redhat/PrinterSpooler"), QLatin1String("com.redhat.PrinterSpooler"), QLatin1String("QueueChanged"), this, SIGNAL(rhQueueChanged(QString))); // This signal is needed since the cups registration thing // doesn't emit printerRemoved when we add a printer class // This is emitted when a printer/queue is changed QDBusConnection::systemBus().connect(QLatin1String(""), QLatin1String("/com/redhat/PrinterSpooler"), QLatin1String("com.redhat.PrinterSpooler"), QLatin1String("PrinterRemoved"), this, SIGNAL(rhPrinterRemoved(QString))); QDBusConnection::systemBus().connect(QLatin1String(""), QLatin1String("/com/redhat/PrinterSpooler"), QLatin1String("com.redhat.PrinterSpooler"), QLatin1String("JobQueuedLocal"), this, SIGNAL(rhJobQueuedLocal(QString,uint,QString))); QDBusConnection::systemBus().connect(QLatin1String(""), QLatin1String("/com/redhat/PrinterSpooler"), QLatin1String("com.redhat.PrinterSpooler"), QLatin1String("JobStartedLocal"), this, SIGNAL(rhJobStartedLocal(QString,uint,QString))); // Creates the timer that will renew the DBus subscription m_renewTimer = new QTimer; m_renewTimer->setInterval(RENEW_INTERVAL*1000); m_renewTimer->moveToThread(this); connect(m_renewTimer, &QTimer::timeout, this, static_cast(&KCupsConnection::renewDBusSubscription), Qt::DirectConnection); // Creates the timer to merge updates on the DBus subscription m_subscriptionTimer = new QTimer; m_subscriptionTimer->setInterval(0); m_subscriptionTimer->setSingleShot(true); m_subscriptionTimer->moveToThread(this); connect(m_subscriptionTimer, &QTimer::timeout, this, &KCupsConnection::updateSubscription, Qt::DirectConnection); // Starts this thread start(); } void KCupsConnection::run() { // Check if we need an special connection if (!m_serverUrl.isEmpty()) { if (m_serverUrl.port() < 0) { // TODO find out if there's a better way of hardcoding // the CUPS port m_serverUrl.setPort(631); } cupsSetServer(qUtf8Printable(m_serverUrl.authority())); } // This is dead cool, cups will call the thread_password_cb() // function when a password set is needed, as we passed the // password dialog pointer the functions just need to call // it on a blocking mode. cupsSetPasswordCB2(password_cb, m_passwordDialog); m_inited = true; exec(); // Event loop quit so cancelDBusSubscription() if (m_subscriptionId != -1) { cancelDBusSubscription(); } } bool KCupsConnection::readyToStart() { if (QThread::currentThread() == this) { password_retries = 0; total_retries = 0; internalErrorCount = 0; return true; } return false; } ReturnArguments KCupsConnection::request(const KIppRequest &request, ipp_tag_t groupTag) const { ReturnArguments ret; ipp_t *response = nullptr; do { ippDelete(response); response = nullptr; response = request.sendIppRequest(); } while (retry(qUtf8Printable(request.resource()), request.operation())); if (response && groupTag != IPP_TAG_ZERO) { ret = parseIPPVars(response, groupTag); } ippDelete(response); return ret; } int KCupsConnection::renewDBusSubscription(int subscriptionId, int leaseDuration, const QStringList &events) { int ret = -1; ipp_op_t operation; // check if we have a valid subscription ID if (subscriptionId >= 0) { // Add the "notify-events" values to the request operation = IPP_RENEW_SUBSCRIPTION; } else { operation = IPP_CREATE_PRINTER_SUBSCRIPTION; } KIppRequest request(operation, QLatin1String("/")); request.addString(IPP_TAG_OPERATION, IPP_TAG_URI, KCUPS_PRINTER_URI, QLatin1String("/")); request.addInteger(IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER, KCUPS_NOTIFY_LEASE_DURATION, leaseDuration); if (operation == IPP_CREATE_PRINTER_SUBSCRIPTION) { // Add the "notify-events" values to the request request.addStringList(IPP_TAG_SUBSCRIPTION, IPP_TAG_KEYWORD, KCUPS_NOTIFY_EVENTS, events); request.addString(IPP_TAG_SUBSCRIPTION, IPP_TAG_KEYWORD, KCUPS_NOTIFY_PULL_METHOD, QLatin1String("ippget")); request.addString(IPP_TAG_SUBSCRIPTION, IPP_TAG_URI, KCUPS_NOTIFY_RECIPIENT_URI, QLatin1String("dbus://")); } else { request.addInteger(IPP_TAG_OPERATION, IPP_TAG_INTEGER, KCUPS_NOTIFY_SUBSCRIPTION_ID, subscriptionId); } ipp_t *response = nullptr; do { // Do the request response = request.sendIppRequest(); } while (retry("/", operation)); #if !(CUPS_VERSION_MAJOR == 1 && CUPS_VERSION_MINOR < 6) if (response && ippGetStatusCode(response) == IPP_OK) { #else if (response && response->request.status.status_code == IPP_OK) { #endif // !(CUPS_VERSION_MAJOR == 1 && CUPS_VERSION_MINOR < 6) ipp_attribute_t *attr; if (subscriptionId >= 0) { // Request was ok, just return the current subscription ret = subscriptionId; } else if ((attr = ippFindAttribute(response, "notify-subscription-id", IPP_TAG_INTEGER)) == nullptr) { qCWarning(LIBKCUPS) << "No notify-subscription-id in response!"; ret = -1; } else { #if !(CUPS_VERSION_MAJOR == 1 && CUPS_VERSION_MINOR < 6) ret = ippGetInteger(attr, 0); } } else if (subscriptionId >= 0 && response && ippGetStatusCode(response) == IPP_NOT_FOUND) { qCDebug(LIBKCUPS) << "Subscription not found"; // When the subscription is not found try to get a new one return renewDBusSubscription(-1, leaseDuration, events); #else ret = attr->values[0].integer; } } else if (subscriptionId >= 0 && response && response->request.status.status_code == IPP_NOT_FOUND) { qCDebug(LIBKCUPS) << "Subscription not found"; // When the subscription is not found try to get a new one return renewDBusSubscription(-1, leaseDuration, events); #endif // !(CUPS_VERSION_MAJOR == 1 && CUPS_VERSION_MINOR < 6) } else { qCDebug(LIBKCUPS) << "Request failed" << cupsLastError() << httpGetStatus(CUPS_HTTP_DEFAULT); // When the server stops/restarts we will have some error so ignore it ret = subscriptionId; } ippDelete(response); return ret; } void KCupsConnection::notifierConnect(const QString &signal, QObject *receiver, const char *slot) { QDBusConnection systemBus = QDBusConnection::systemBus(); systemBus.connect(QString(), QStringLiteral("/org/cups/cupsd/Notifier"), QStringLiteral("org.cups.cupsd.Notifier"), signal, receiver, slot); } void KCupsConnection::connectNotify(const QMetaMethod & signal) { QMutexLocker locker(&m_mutex); QString event = eventForSignal(signal); if (!event.isNull()) { m_connectedEvents << event; QMetaObject::invokeMethod(m_subscriptionTimer, "start", Qt::QueuedConnection); } } void KCupsConnection::disconnectNotify(const QMetaMethod & signal) { QMutexLocker locker(&m_mutex); QString event = eventForSignal(signal); if (!event.isNull()) { m_connectedEvents.removeOne(event); QMetaObject::invokeMethod(m_subscriptionTimer, "start", Qt::QueuedConnection); } } QString KCupsConnection::eventForSignal(const QMetaMethod & signal) const { // Server signals if (signal == QMetaMethod::fromSignal(&KCupsConnection::serverAudit)) { return QStringLiteral(DBUS_SERVER_AUDIT); } if (signal == QMetaMethod::fromSignal(&KCupsConnection::serverStarted)) { return QStringLiteral(DBUS_SERVER_STARTED); } if (signal == QMetaMethod::fromSignal(&KCupsConnection::serverStopped)) { return QStringLiteral(DBUS_SERVER_STOPPED); } if (signal == QMetaMethod::fromSignal(&KCupsConnection::serverRestarted)) { return QStringLiteral(DBUS_SERVER_RESTARTED); } // Printer signals if (signal == QMetaMethod::fromSignal(&KCupsConnection::printerAdded)) { return QStringLiteral(DBUS_PRINTER_ADDED); } if (signal == QMetaMethod::fromSignal(&KCupsConnection::printerDeleted)) { return QStringLiteral(DBUS_PRINTER_DELETED); } if (signal == QMetaMethod::fromSignal(&KCupsConnection::printerFinishingsChanged)) { return QStringLiteral(DBUS_PRINTER_FINISHINGS_CHANGED); } if (signal == QMetaMethod::fromSignal(&KCupsConnection::printerMediaChanged)) { return QStringLiteral(DBUS_PRINTER_MEDIA_CHANGED); } if (signal == QMetaMethod::fromSignal(&KCupsConnection::printerModified)) { return QStringLiteral(DBUS_PRINTER_MODIFIED); } if (signal == QMetaMethod::fromSignal(&KCupsConnection::printerRestarted)) { return QStringLiteral(DBUS_PRINTER_RESTARTED); } if (signal == QMetaMethod::fromSignal(&KCupsConnection::printerShutdown)) { return QStringLiteral(DBUS_PRINTER_SHUTDOWN); } if (signal == QMetaMethod::fromSignal(&KCupsConnection::printerStateChanged)) { return QStringLiteral(DBUS_PRINTER_STATE_CHANGED); } if (signal == QMetaMethod::fromSignal(&KCupsConnection::printerStopped)) { return QStringLiteral(DBUS_PRINTER_STOPPED); } // job signals if (signal == QMetaMethod::fromSignal(&KCupsConnection::jobCompleted)) { return QStringLiteral(DBUS_JOB_COMPLETED); } if (signal == QMetaMethod::fromSignal(&KCupsConnection::jobConfigChanged)) { return QStringLiteral(DBUS_JOB_CONFIG_CHANGED); } if (signal == QMetaMethod::fromSignal(&KCupsConnection::jobCreated)) { return QStringLiteral(DBUS_JOB_CREATED); } if (signal == QMetaMethod::fromSignal(&KCupsConnection::jobProgress)) { return QStringLiteral(DBUS_JOB_PROGRESS); } if (signal == QMetaMethod::fromSignal(&KCupsConnection::jobState)) { return QStringLiteral(DBUS_JOB_STATE_CHANGED); } if (signal == QMetaMethod::fromSignal(&KCupsConnection::jobStopped)) { return QStringLiteral(DBUS_JOB_STOPPED); } // No registered event signal matched return QString(); } void KCupsConnection::updateSubscription() { QMutexLocker locker(&m_mutex); // Build the current list QStringList currentEvents = m_connectedEvents; currentEvents.sort(); currentEvents.removeDuplicates(); // Check if the requested events are already being asked if (m_requestedDBusEvents != currentEvents) { m_requestedDBusEvents = currentEvents; // If we already have a subscription lets cancel // and create a new one if (m_subscriptionId >= 0) { cancelDBusSubscription(); } // Calculates the new events renewDBusSubscription(); } } void KCupsConnection::renewDBusSubscription() { // check if we have a valid subscription ID if (m_subscriptionId >= 0) { m_subscriptionId = renewDBusSubscription(m_subscriptionId, SUBSCRIPTION_DURATION); } // The above request might fail if the subscription was cancelled if (m_subscriptionId < 0) { if (m_requestedDBusEvents.isEmpty()) { m_renewTimer->stop(); } else { m_subscriptionId = renewDBusSubscription(m_subscriptionId, SUBSCRIPTION_DURATION, m_requestedDBusEvents); m_renewTimer->start(); } } } void KCupsConnection::cancelDBusSubscription() { KIppRequest request(IPP_CANCEL_SUBSCRIPTION, QLatin1String("/")); request.addString(IPP_TAG_OPERATION, IPP_TAG_URI, KCUPS_PRINTER_URI, QLatin1String("/")); request.addInteger(IPP_TAG_OPERATION, IPP_TAG_INTEGER, KCUPS_NOTIFY_SUBSCRIPTION_ID, m_subscriptionId); do { // Do the request ippDelete(request.sendIppRequest()); } while (retry(qUtf8Printable(request.resource()), request.operation())); // Reset the subscription id m_subscriptionId = -1; } ReturnArguments KCupsConnection::parseIPPVars(ipp_t *response, ipp_tag_t group_tag) { ipp_attribute_t *attr; ReturnArguments ret; #if !(CUPS_VERSION_MAJOR == 1 && CUPS_VERSION_MINOR < 6) QVariantHash destAttributes; for (attr = ippFirstAttribute(response); attr != nullptr; attr = ippNextAttribute(response)) { // We hit an attribute separator if (ippGetName(attr) == nullptr) { ret << destAttributes; destAttributes.clear(); continue; } // Skip leading attributes until we hit a group which can be a printer, job... if (ippGetGroupTag(attr) != group_tag || (ippGetValueTag(attr) != IPP_TAG_INTEGER && ippGetValueTag(attr) != IPP_TAG_ENUM && ippGetValueTag(attr) != IPP_TAG_BOOLEAN && ippGetValueTag(attr) != IPP_TAG_TEXT && ippGetValueTag(attr) != IPP_TAG_TEXTLANG && ippGetValueTag(attr) != IPP_TAG_LANGUAGE && ippGetValueTag(attr) != IPP_TAG_NAME && ippGetValueTag(attr) != IPP_TAG_NAMELANG && ippGetValueTag(attr) != IPP_TAG_KEYWORD && ippGetValueTag(attr) != IPP_TAG_RANGE && ippGetValueTag(attr) != IPP_TAG_URI)) { continue; } // Add a printer description attribute... destAttributes[QString::fromUtf8(ippGetName(attr))] = ippAttrToVariant(attr); } if (!destAttributes.isEmpty()) { ret << destAttributes; } #else for (attr = response->attrs; attr != nullptr; attr = attr->next) { /* * Skip leading attributes until we hit a group which can be a printer, job... */ while (attr && attr->group_tag != group_tag) { attr = attr->next; } if (attr == nullptr) { break; } /* * Pull the needed attributes from this printer... */ QVariantHash destAttributes; for (; attr && attr->group_tag == group_tag; attr = attr->next) { if (attr->value_tag != IPP_TAG_INTEGER && attr->value_tag != IPP_TAG_ENUM && attr->value_tag != IPP_TAG_BOOLEAN && attr->value_tag != IPP_TAG_TEXT && attr->value_tag != IPP_TAG_TEXTLANG && attr->value_tag != IPP_TAG_LANGUAGE && attr->value_tag != IPP_TAG_NAME && attr->value_tag != IPP_TAG_NAMELANG && attr->value_tag != IPP_TAG_KEYWORD && attr->value_tag != IPP_TAG_RANGE && attr->value_tag != IPP_TAG_URI) { continue; } /* * Add a printer description attribute... */ destAttributes[QString::fromUtf8(attr->name)] = ippAttrToVariant(attr); } ret << destAttributes; if (attr == nullptr) { break; } } #endif // !(CUPS_VERSION_MAJOR == 1 && CUPS_VERSION_MINOR < 6) return ret; } QVariant KCupsConnection::ippAttrToVariant(ipp_attribute_t *attr) { QVariant ret; #if !(CUPS_VERSION_MAJOR == 1 && CUPS_VERSION_MINOR < 6) switch (ippGetValueTag(attr)) { case IPP_TAG_INTEGER: case IPP_TAG_ENUM: if (ippGetCount(attr) == 1) { ret = ippGetInteger(attr, 0); } else { QList values; for (int i = 0; i < ippGetCount(attr); ++i) { values << ippGetInteger(attr, i); } - ret = qVariantFromValue(values); + ret = QVariant::fromValue(values); } break; case IPP_TAG_BOOLEAN: if (ippGetCount(attr)== 1) { ret = ippGetBoolean(attr, 0); } else { QList values; for (int i = 0; i < ippGetCount(attr); ++i) { values << ippGetBoolean(attr, i); } - ret = qVariantFromValue(values); + ret = QVariant::fromValue(values); } break; case IPP_TAG_RANGE: { QVariantList values; for (int i = 0; i < ippGetCount(attr); ++i) { int rangeUpper; values << ippGetRange(attr, i, &rangeUpper); values << rangeUpper; } ret = values; } break; default: if (ippGetCount(attr)== 1) { ret = QString::fromUtf8(ippGetString(attr, 0, nullptr)); } else { QStringList values; for (int i = 0; i < ippGetCount(attr); ++i) { values << QString::fromUtf8(ippGetString(attr, i, nullptr)); } ret = values; } } #else switch (attr->value_tag) { case IPP_TAG_INTEGER: case IPP_TAG_ENUM: if (attr->num_values == 1) { ret = attr->values[0].integer; } else { QList values; for (int i = 0; i < attr->num_values; ++i) { values << attr->values[i].integer; } - ret = qVariantFromValue(values); + ret = QVariant::fromValue(values); } break; case IPP_TAG_BOOLEAN: if (attr->num_values == 1) { ret = static_cast(attr->values[0].integer); } else { QList values; for (int i = 0; i < attr->num_values; ++i) { values << static_cast(attr->values[i].integer); } - ret = qVariantFromValue(values); + ret = QVariant::fromValue(values); } break; case IPP_TAG_RANGE: { QVariantList values; for (int i = 0; i < attr->num_values; ++i) { values << attr->values[i].range.lower; values << attr->values[i].range.upper; } ret = values; } break; default: if (attr->num_values == 1) { ret = QString::fromUtf8(attr->values[0].string.text); } else { QStringList values; for (int i = 0; i < attr->num_values; ++i) { values << QString::fromUtf8(attr->values[i].string.text); } ret = values; } } #endif // !(CUPS_VERSION_MAJOR == 1 && CUPS_VERSION_MINOR < 6) return ret; } bool KCupsConnection::retry(const char *resource, int operation) const { ipp_status_t status = cupsLastError(); if (operation != -1) { qCDebug(LIBKCUPS) << ippOpString(static_cast(operation)) << "last error:" << status << cupsLastErrorString(); } else { qCDebug(LIBKCUPS) << operation << "last error:" << status << cupsLastErrorString(); } // When CUPS process stops our connection // with it fails and has to be re-established if (status == IPP_INTERNAL_ERROR) { // Deleting this connection thread forces it // to create a new CUPS connection qCWarning(LIBKCUPS) << "IPP_INTERNAL_ERROR: clearing cookies and reconnecting"; // TODO maybe reconnect is enough // httpClearCookie(CUPS_HTTP_DEFAULT); // Reconnect to CUPS if (httpReconnect(CUPS_HTTP_DEFAULT)) { qCWarning(LIBKCUPS) << "Failed to reconnect" << cupsLastErrorString(); // Server might be restarting sleep for a few ms msleep(500); } // Try the request again return ++internalErrorCount < 3; } total_retries++; if (total_retries > (password_retries + 3)) { // Something is wrong. // This will happen if the password_cb function is not called, // which will for example be the case if the server has // an IP blacklist and thus always return 403. // In this case, there is nothing we can do. return false; } bool forceAuth = false; // If our user is forbidden to perform the // task we try again using the root user // ONLY if it was the first time if (status == IPP_FORBIDDEN && password_retries == 0) { // Pretend to be the root user // Sometimes setting this just works cupsSetUser("root"); // force authentication forceAuth = true; } if (status == IPP_NOT_AUTHORIZED || status == IPP_NOT_AUTHENTICATED) { if (password_retries > 3 || password_retries == -1) { // the authentication failed 3 times // OR the dialog was canceled (-1) // reset to 0 and quit the do-while loop password_retries = 0; total_retries = 0; return false; } // force authentication forceAuth = true; } if (forceAuth) { // force authentication qCDebug(LIBKCUPS) << "Calling cupsDoAuthentication() password_retries:" << password_retries; int ret = cupsDoAuthentication(CUPS_HTTP_DEFAULT, "POST", resource); qCDebug(LIBKCUPS) << "Called cupsDoAuthentication(), success:" << (ret == -1 ? true : false); // If the authentication was successful // sometimes just trying to be root works return ret == -1 ? true : false; } // the action was not forbidden return false; } const char * password_cb(const char *prompt, http_t *http, const char *method, const char *resource, void *user_data) { Q_UNUSED(http) Q_UNUSED(method) Q_UNUSED(resource) if (++password_retries > 3) { // cancel the authentication cupsSetUser(nullptr); return nullptr; } auto passwordDialog = static_cast(user_data); bool wrongPassword = password_retries > 1; // use prompt text from CUPS callback for dialog passwordDialog->setPromptText(i18n("A CUPS connection requires authentication: \"%1\"", QString::fromUtf8(prompt))); // This will block this thread until exec is not finished qCDebug(LIBKCUPS) << password_retries; QMetaObject::invokeMethod(passwordDialog, "exec", Qt::BlockingQueuedConnection, Q_ARG(QString, QString::fromUtf8(cupsUser())), Q_ARG(bool, wrongPassword)); qCDebug(LIBKCUPS) << passwordDialog->accepted(); // The password dialog has just returned check the result // method that returns QDialog enums if (passwordDialog->accepted()) { cupsSetUser(qUtf8Printable(passwordDialog->username())); return qUtf8Printable(passwordDialog->password()); } else { // the dialog was canceled password_retries = -1; cupsSetUser(nullptr); return nullptr; } } #include "moc_KCupsConnection.cpp" diff --git a/libkcups/KCupsRequest.cpp b/libkcups/KCupsRequest.cpp index 7617b54..542e48f 100644 --- a/libkcups/KCupsRequest.cpp +++ b/libkcups/KCupsRequest.cpp @@ -1,669 +1,669 @@ /*************************************************************************** * Copyright (C) 2010-2018 by Daniel Nicoletti * * dantti12@gmail.com * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; see the file COPYING. If not, write to * * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301, USA. * ***************************************************************************/ #include "KCupsRequest.h" #include "Debug.h" #include "KIppRequest.h" #include "KCupsJob.h" #include "KCupsPrinter.h" #include #include #include #define CUPS_DATADIR QLatin1String("/usr/share/cups") KCupsRequest::KCupsRequest(KCupsConnection *connection) : m_connection(connection) { // If no connection was specified use default one if (m_connection == nullptr) { m_connection = KCupsConnection::global(); } connect(this, &KCupsRequest::finished, &m_loop, &QEventLoop::quit); } QString KCupsRequest::serverError() const { switch (error()) { case IPP_SERVICE_UNAVAILABLE: return i18n("Print service is unavailable"); case IPP_NOT_FOUND : return i18n("Not found"); default : // In this case we don't want to map all enums qCWarning(LIBKCUPS) << "status unrecognised: " << error(); return QString::fromUtf8(ippErrorString(error())); } } void KCupsRequest::getPPDS(const QString &make) { if (m_connection->readyToStart()) { KIppRequest request(CUPS_GET_PPDS, QLatin1String("/")); if (!make.isEmpty()) { request.addString(IPP_TAG_PRINTER, IPP_TAG_TEXT, KCUPS_PPD_MAKE_AND_MODEL, make); } m_ppds = m_connection->request(request, IPP_TAG_PRINTER); setError(httpGetStatus(CUPS_HTTP_DEFAULT), cupsLastError(), QString::fromUtf8(cupsLastErrorString())); setFinished(); } else { invokeMethod("getPPDS", make); } } static void choose_device_cb(const char *device_class, /* I - Class */ const char *device_id, /* I - 1284 device ID */ const char *device_info, /* I - Description */ const char *device_make_and_model, /* I - Make and model */ const char *device_uri, /* I - Device URI */ const char *device_location, /* I - Location */ void *user_data) /* I - Result object */ { /* * Add the device to the array... */ auto request = static_cast(user_data); QMetaObject::invokeMethod(request, "device", Qt::QueuedConnection, Q_ARG(QString, QString::fromUtf8(device_class)), Q_ARG(QString, QString::fromUtf8(device_id)), Q_ARG(QString, QString::fromUtf8(device_info)), Q_ARG(QString, QString::fromUtf8(device_make_and_model)), Q_ARG(QString, QString::fromUtf8(device_uri)), Q_ARG(QString, QString::fromUtf8(device_location))); } void KCupsRequest::getDevices(int timeout) { getDevices(timeout, QStringList(), QStringList()); } void KCupsRequest::getDevices(int timeout, QStringList includeSchemes, QStringList excludeSchemes) { if (m_connection->readyToStart()) { do { const char *include; if (includeSchemes.isEmpty()) { include = CUPS_INCLUDE_ALL; } else { include = qUtf8Printable(includeSchemes.join(QLatin1String(","))); } const char *exclude; if (excludeSchemes.isEmpty()) { exclude = CUPS_EXCLUDE_NONE; } else { exclude = qUtf8Printable(excludeSchemes.join(QLatin1String(","))); } // Scan for devices for "timeout" seconds cupsGetDevices(CUPS_HTTP_DEFAULT, timeout, include, exclude, (cups_device_cb_t) choose_device_cb, this); } while (m_connection->retry("/admin/", CUPS_GET_DEVICES)); setError(httpGetStatus(CUPS_HTTP_DEFAULT), cupsLastError(), QString::fromUtf8(cupsLastErrorString())); setFinished(true); } else { invokeMethod("getDevices", timeout, includeSchemes, excludeSchemes); } } // THIS function can get the default server dest through the // "printer-is-default" attribute BUT it does not get user // defined default printer, see cupsGetDefault() on www.cups.org for details void KCupsRequest::getPrinters(QStringList attributes, int mask) { if (m_connection->readyToStart()) { KIppRequest request(CUPS_GET_PRINTERS, QLatin1String("/")); request.addInteger(IPP_TAG_OPERATION, IPP_TAG_ENUM, KCUPS_PRINTER_TYPE, CUPS_PRINTER_LOCAL); if (!attributes.isEmpty()) { request.addStringList(IPP_TAG_OPERATION, IPP_TAG_KEYWORD, KCUPS_REQUESTED_ATTRIBUTES, attributes); } if (mask != -1) { request.addInteger(IPP_TAG_OPERATION, IPP_TAG_ENUM, KCUPS_PRINTER_TYPE_MASK, mask); } const ReturnArguments ret = m_connection->request(request, IPP_TAG_PRINTER); for (const QVariantHash &arguments : ret) { m_printers << KCupsPrinter(arguments); } setError(httpGetStatus(CUPS_HTTP_DEFAULT), cupsLastError(), QString::fromUtf8(cupsLastErrorString())); setFinished(); } else { - invokeMethod("getPrinters", qVariantFromValue(attributes), mask); + invokeMethod("getPrinters", QVariant::fromValue(attributes), mask); } } void KCupsRequest::getPrinterAttributes(const QString &printerName, bool isClass, QStringList attributes) { if (m_connection->readyToStart()) { KIppRequest request(IPP_GET_PRINTER_ATTRIBUTES, QLatin1String("/")); request.addPrinterUri(printerName, isClass); request.addInteger(IPP_TAG_OPERATION, IPP_TAG_ENUM, QLatin1String(KCUPS_PRINTER_TYPE), CUPS_PRINTER_LOCAL); request.addStringList(IPP_TAG_OPERATION, IPP_TAG_KEYWORD, QLatin1String(KCUPS_REQUESTED_ATTRIBUTES), attributes); const ReturnArguments ret = m_connection->request(request, IPP_TAG_PRINTER); for (const QVariantHash &arguments : ret) { // Inject the printer name back to the arguments hash QVariantHash args = arguments; args[KCUPS_PRINTER_NAME] = printerName; m_printers << KCupsPrinter(args); } setError(httpGetStatus(CUPS_HTTP_DEFAULT), cupsLastError(), QString::fromUtf8(cupsLastErrorString())); setFinished(); } else { - invokeMethod("getPrinterAttributes", printerName, isClass, qVariantFromValue(attributes)); + invokeMethod("getPrinterAttributes", printerName, isClass, QVariant::fromValue(attributes)); } } void KCupsRequest::getJobs(const QString &printerName, bool myJobs, int whichJobs, QStringList attributes) { if (m_connection->readyToStart()) { KIppRequest request(IPP_GET_JOBS, QLatin1String("/")); // printer-uri makes the Name of the Job and owner came blank lol request.addPrinterUri(printerName, false); request.addInteger(IPP_TAG_OPERATION, IPP_TAG_ENUM, KCUPS_PRINTER_TYPE, CUPS_PRINTER_LOCAL); request.addStringList(IPP_TAG_OPERATION, IPP_TAG_KEYWORD, KCUPS_REQUESTED_ATTRIBUTES, attributes); request.addInteger(IPP_TAG_OPERATION, IPP_TAG_ENUM, KCUPS_MY_JOBS, myJobs); if (whichJobs == CUPS_WHICHJOBS_COMPLETED) { request.addString(IPP_TAG_OPERATION, IPP_TAG_KEYWORD, KCUPS_WHICH_JOBS, QLatin1String("completed")); } else if (whichJobs == CUPS_WHICHJOBS_ALL) { request.addString(IPP_TAG_OPERATION, IPP_TAG_KEYWORD, KCUPS_WHICH_JOBS, QLatin1String("all")); } const ReturnArguments ret = m_connection->request(request, IPP_TAG_JOB); for (const QVariantHash &arguments : ret) { m_jobs << KCupsJob(arguments); } setError(httpGetStatus(CUPS_HTTP_DEFAULT), cupsLastError(), QString::fromUtf8(cupsLastErrorString())); setFinished(); } else { - invokeMethod("getJobs", printerName, myJobs, whichJobs, qVariantFromValue(attributes)); + invokeMethod("getJobs", printerName, myJobs, whichJobs, QVariant::fromValue(attributes)); } } void KCupsRequest::getJobAttributes(int jobId, const QString &printerUri, QStringList attributes) { if (m_connection->readyToStart()) { KIppRequest request(IPP_GET_JOB_ATTRIBUTES, QLatin1String("/")); request.addString(IPP_TAG_OPERATION, IPP_TAG_URI, KCUPS_PRINTER_URI, printerUri); request.addInteger(IPP_TAG_OPERATION, IPP_TAG_ENUM, KCUPS_PRINTER_TYPE, CUPS_PRINTER_LOCAL); request.addStringList(IPP_TAG_OPERATION, IPP_TAG_KEYWORD, KCUPS_REQUESTED_ATTRIBUTES, attributes); request.addInteger(IPP_TAG_OPERATION, IPP_TAG_INTEGER, KCUPS_JOB_ID, jobId); const ReturnArguments ret = m_connection->request(request, IPP_TAG_PRINTER); for (const QVariantHash &arguments : ret) { m_jobs << KCupsJob(arguments); } setError(httpGetStatus(CUPS_HTTP_DEFAULT), cupsLastError(), QString::fromUtf8(cupsLastErrorString())); setFinished(); } else { - invokeMethod("getJobAttributes", jobId, printerUri, qVariantFromValue(attributes)); + invokeMethod("getJobAttributes", jobId, printerUri, QVariant::fromValue(attributes)); } } void KCupsRequest::getServerSettings() { if (m_connection->readyToStart()) { do { int num_settings; cups_option_t *settings; QVariantHash arguments; 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/", -1)); setFinished(); } else { invokeMethod("getServerSettings"); } } void KCupsRequest::getPrinterPPD(const QString &printerName) { if (m_connection->readyToStart()) { do { const char *filename; filename = cupsGetPPD2(CUPS_HTTP_DEFAULT, qUtf8Printable(printerName)); qCDebug(LIBKCUPS) << filename; m_ppdFile = QString::fromUtf8(filename); qCDebug(LIBKCUPS) << m_ppdFile; } while (m_connection->retry("/", CUPS_GET_PPD)); setError(httpGetStatus(CUPS_HTTP_DEFAULT), cupsLastError(), QString::fromUtf8(cupsLastErrorString())); setFinished(); } else { invokeMethod("getPrinterPPD", printerName); } } void KCupsRequest::setServerSettings(const KCupsServer &server) { if (m_connection->readyToStart()) { do { QVariantHash args = server.arguments(); int num_settings = 0; cups_option_t *settings; QVariantHash::const_iterator i = args.constBegin(); while (i != args.constEnd()) { num_settings = cupsAddOption(qUtf8Printable(i.key()), qUtf8Printable(i.value().toString()), num_settings, &settings); ++i; } cupsAdminSetServerSettings(CUPS_HTTP_DEFAULT, num_settings, settings); cupsFreeOptions(num_settings, settings); } while (m_connection->retry("/admin/", -1)); setError(httpGetStatus(CUPS_HTTP_DEFAULT), cupsLastError(), QString::fromUtf8(cupsLastErrorString())); setFinished(); } else { - invokeMethod("setServerSettings", qVariantFromValue(server)); + invokeMethod("setServerSettings", QVariant::fromValue(server)); } } void KCupsRequest::addOrModifyPrinter(const QString &printerName, const QVariantHash &attributes, const QString &filename) { KIppRequest request(CUPS_ADD_MODIFY_PRINTER, QLatin1String("/admin/"), filename); request.addPrinterUri(printerName); request.addVariantValues(attributes); process(request); } void KCupsRequest::addOrModifyClass(const QString &printerName, const QVariantHash &attributes) { KIppRequest request(CUPS_ADD_MODIFY_CLASS, QLatin1String("/admin/")); request.addPrinterUri(printerName, true); request.addVariantValues(attributes); process(request); } void KCupsRequest::setShared(const QString &printerName, bool isClass, bool shared) { KIppRequest request(isClass ? CUPS_ADD_MODIFY_CLASS : CUPS_ADD_MODIFY_PRINTER, QLatin1String("/admin/")); request.addPrinterUri(printerName, isClass); request.addBoolean(IPP_TAG_OPERATION, KCUPS_PRINTER_IS_SHARED, shared); process(request); } void KCupsRequest::pausePrinter(const QString &printerName) { KIppRequest request(IPP_PAUSE_PRINTER, QLatin1String("/admin/")); request.addPrinterUri(printerName); process(request); } void KCupsRequest::resumePrinter(const QString &printerName) { KIppRequest request(IPP_RESUME_PRINTER, QLatin1String("/admin/")); request.addPrinterUri(printerName); process(request); } void KCupsRequest::rejectJobs(const QString &printerName) { KIppRequest request(CUPS_REJECT_JOBS, QLatin1String("/admin/")); request.addPrinterUri(printerName); process(request); } void KCupsRequest::acceptJobs(const QString &printerName) { KIppRequest request(CUPS_ACCEPT_JOBS, QLatin1String("/admin/")); request.addPrinterUri(printerName); process(request); } void KCupsRequest::setDefaultPrinter(const QString &printerName) { KIppRequest request(CUPS_SET_DEFAULT, QLatin1String("/admin/")); request.addPrinterUri(printerName); process(request); } void KCupsRequest::deletePrinter(const QString &printerName) { KIppRequest request(CUPS_DELETE_PRINTER, QLatin1String("/admin/")); request.addPrinterUri(printerName); process(request); } void KCupsRequest::printTestPage(const QString &printerName, bool isClass) { QString resource; /* POST resource path */ QString filename; /* Test page filename */ QString datadir; /* CUPS_DATADIR env var */ /* * Locate the test page file... */ datadir = QString::fromUtf8(qgetenv("CUPS_DATADIR")); if (datadir.isEmpty()) { datadir = CUPS_DATADIR; } filename = datadir % QLatin1String("/data/testprint"); /* * Point to the printer/class... */ if (isClass) { resource = QLatin1String("/classes/") + printerName; } else { resource = QLatin1String("/printers/") + printerName; } KIppRequest request(IPP_PRINT_JOB, resource, filename); request.addPrinterUri(printerName); request.addString(IPP_TAG_OPERATION, IPP_TAG_NAME, KCUPS_JOB_NAME, i18n("Test Page")); process(request); } void KCupsRequest::printCommand(const QString &printerName, const QString &command, const QString &title) { if (m_connection->readyToStart()) { do { int job_id; /* Command file job */ char command_file[1024]; /* Command "file" */ http_status_t status; /* Document status */ cups_option_t hold_option; /* job-hold-until option */ /* * Create the CUPS command file... */ snprintf(command_file, sizeof(command_file), "#CUPS-COMMAND\n%s\n", command.toUtf8().constData()); /* * Send the command file job... */ hold_option.name = const_cast("job-hold-until"); hold_option.value = const_cast("no-hold"); if ((job_id = cupsCreateJob(CUPS_HTTP_DEFAULT, qUtf8Printable(printerName), qUtf8Printable(title), 1, &hold_option)) < 1) { qWarning() << "Unable to send command to printer driver!"; setError(HTTP_OK, IPP_NOT_POSSIBLE, i18n("Unable to send command to printer driver!")); setFinished(); return; } status = cupsStartDocument(CUPS_HTTP_DEFAULT, qUtf8Printable(printerName), job_id, nullptr, CUPS_FORMAT_COMMAND, 1); if (status == HTTP_CONTINUE) { status = cupsWriteRequestData(CUPS_HTTP_DEFAULT, command_file, strlen(command_file)); } if (status == HTTP_CONTINUE) { cupsFinishDocument(CUPS_HTTP_DEFAULT, qUtf8Printable(printerName)); } 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(qUtf8Printable(printerName), job_id); setFinished(); return; // Return to avoid a new try } } while (m_connection->retry("/", IPP_CREATE_JOB)); setError(httpGetStatus(CUPS_HTTP_DEFAULT), cupsLastError(), QString::fromUtf8(cupsLastErrorString())); setFinished(); } else { invokeMethod("printCommand", printerName, command, title); } } void KCupsRequest::cancelJob(const QString &printerName, int jobId) { KIppRequest request(IPP_CANCEL_JOB, QLatin1String("/jobs/")); request.addPrinterUri(printerName); request.addInteger(IPP_TAG_OPERATION, IPP_TAG_INTEGER, KCUPS_JOB_ID, jobId); process(request); } void KCupsRequest::holdJob(const QString &printerName, int jobId) { KIppRequest request(IPP_HOLD_JOB, QLatin1String("/jobs/")); request.addPrinterUri(printerName); request.addInteger(IPP_TAG_OPERATION, IPP_TAG_INTEGER, KCUPS_JOB_ID, jobId); process(request); } void KCupsRequest::releaseJob(const QString &printerName, int jobId) { KIppRequest request(IPP_RELEASE_JOB, QLatin1String("/jobs/")); request.addPrinterUri(printerName); request.addInteger(IPP_TAG_OPERATION, IPP_TAG_INTEGER, KCUPS_JOB_ID, jobId); process(request); } void KCupsRequest::restartJob(const QString &printerName, int jobId) { KIppRequest request(IPP_RESTART_JOB, QLatin1String("/jobs/")); request.addPrinterUri(printerName); request.addInteger(IPP_TAG_OPERATION, IPP_TAG_INTEGER, KCUPS_JOB_ID, jobId); process(request); } void KCupsRequest::moveJob(const QString &fromPrinterName, int jobId, const QString &toPrinterName) { if (jobId < -1 || fromPrinterName.isEmpty() || toPrinterName.isEmpty() || jobId == 0) { qWarning() << "Internal error, invalid input data" << jobId << fromPrinterName << toPrinterName; setFinished(); return; } KIppRequest request(CUPS_MOVE_JOB, QLatin1String("/jobs/")); request.addPrinterUri(fromPrinterName); request.addInteger(IPP_TAG_OPERATION, IPP_TAG_INTEGER, KCUPS_JOB_ID, jobId); QString toPrinterUri = KIppRequest::assembleUrif(toPrinterName, false); request.addString(IPP_TAG_OPERATION, IPP_TAG_URI, KCUPS_JOB_PRINTER_URI, toPrinterUri); process(request); } void KCupsRequest::invokeMethod(const char *method, const QVariant &arg1, const QVariant &arg2, const QVariant &arg3, const QVariant &arg4, const QVariant &arg5, const QVariant &arg6, const QVariant &arg7, const QVariant &arg8) { m_error = IPP_OK; m_errorMsg.clear(); m_printers.clear(); m_jobs.clear(); m_ppds.clear(); m_ppdFile.clear(); // If this fails we get into a infinite loop // Do not use global()->thread() which point // to the KCupsConnection parent thread moveToThread(m_connection); m_finished = !QMetaObject::invokeMethod(this, method, Qt::QueuedConnection, QGenericArgument(arg1.typeName(), arg1.data()), QGenericArgument(arg2.typeName(), arg2.data()), QGenericArgument(arg3.typeName(), arg3.data()), QGenericArgument(arg4.typeName(), arg4.data()), QGenericArgument(arg5.typeName(), arg5.data()), QGenericArgument(arg6.typeName(), arg6.data()), QGenericArgument(arg7.typeName(), arg7.data()), QGenericArgument(arg8.typeName(), arg8.data())); if (m_finished) { setError(HTTP_ERROR, IPP_BAD_REQUEST, i18n("Failed to invoke method: %1", QLatin1String(method))); setFinished(); } } void KCupsRequest::process(const KIppRequest &request) { if (m_connection->readyToStart()) { m_connection->request(request); setError(httpGetStatus(CUPS_HTTP_DEFAULT), cupsLastError(), QString::fromUtf8(cupsLastErrorString())); setFinished(); } else { - invokeMethod("process", qVariantFromValue(request)); + invokeMethod("process", QVariant::fromValue(request)); } } ReturnArguments KCupsRequest::ppds() const { return m_ppds; } KCupsServer KCupsRequest::serverSettings() const { return m_server; } QString KCupsRequest::printerPPD() const { return m_ppdFile; } KCupsPrinters KCupsRequest::printers() const { return m_printers; } KCupsJobs KCupsRequest::jobs() const { return m_jobs; } void KCupsRequest::waitTillFinished() { if (m_finished) { return; } m_loop.exec(); } bool KCupsRequest::hasError() const { return m_error; } 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; } KCupsConnection *KCupsRequest::connection() const { return m_connection; } void KCupsRequest::setError(http_status_t httpStatus, ipp_status_t error, const QString &errorMsg) { m_httpStatus = httpStatus; m_error = error; m_errorMsg = errorMsg; } void KCupsRequest::setFinished(bool delayed) { m_finished = true; if (delayed) { QTimer::singleShot(0, this, [this] () { emit finished(this); }); } else { emit finished(this); } } #include "moc_KCupsRequest.cpp"