Changeset View
Changeset View
Standalone View
Standalone View
libkcups/KCupsConnection.cpp
Show First 20 Lines • Show All 61 Lines • ▼ Show 20 Line(s) | |||||
62 | #define DBUS_JOB_CONFIG_CHANGED "job-config-changed" // JobConfigChanged | 62 | #define DBUS_JOB_CONFIG_CHANGED "job-config-changed" // JobConfigChanged | ||
63 | #define DBUS_JOB_PROGRESS "job-progress" // JobProgress | 63 | #define DBUS_JOB_PROGRESS "job-progress" // JobProgress | ||
64 | 64 | | |||
65 | Q_DECLARE_METATYPE(QList<int>) | 65 | Q_DECLARE_METATYPE(QList<int>) | ||
66 | Q_DECLARE_METATYPE(QList<bool>) | 66 | Q_DECLARE_METATYPE(QList<bool>) | ||
67 | 67 | | |||
68 | KCupsConnection* KCupsConnection::m_instance = 0; | 68 | KCupsConnection* KCupsConnection::m_instance = 0; | ||
69 | static int password_retries = 0; | 69 | static int password_retries = 0; | ||
70 | static int total_retries = 0; | ||||
70 | static int internalErrorCount = 0; | 71 | static int internalErrorCount = 0; | ||
71 | const char * password_cb(const char *prompt, http_t *http, const char *method, const char *resource, void *user_data); | 72 | const char * password_cb(const char *prompt, http_t *http, const char *method, const char *resource, void *user_data); | ||
72 | 73 | | |||
73 | KCupsConnection* KCupsConnection::global() | 74 | KCupsConnection* KCupsConnection::global() | ||
74 | { | 75 | { | ||
75 | if (!m_instance) { | 76 | if (!m_instance) { | ||
76 | m_instance = new KCupsConnection(qApp); | 77 | m_instance = new KCupsConnection(qApp); | ||
77 | } | 78 | } | ||
▲ Show 20 Lines • Show All 230 Lines • ▼ Show 20 Line(s) | 308 | if (m_subscriptionId != -1) { | |||
308 | cancelDBusSubscription(); | 309 | cancelDBusSubscription(); | ||
309 | } | 310 | } | ||
310 | } | 311 | } | ||
311 | 312 | | |||
312 | bool KCupsConnection::readyToStart() | 313 | bool KCupsConnection::readyToStart() | ||
313 | { | 314 | { | ||
314 | if (QThread::currentThread() == this) { | 315 | if (QThread::currentThread() == this) { | ||
315 | password_retries = 0; | 316 | password_retries = 0; | ||
317 | total_retries = 0; | ||||
316 | internalErrorCount = 0; | 318 | internalErrorCount = 0; | ||
317 | return true; | 319 | return true; | ||
318 | } | 320 | } | ||
319 | return false; | 321 | return false; | ||
320 | } | 322 | } | ||
321 | 323 | | |||
322 | 324 | | |||
323 | ReturnArguments KCupsConnection::request(const KIppRequest &request, ipp_tag_t groupTag) const | 325 | ReturnArguments KCupsConnection::request(const KIppRequest &request, ipp_tag_t groupTag) const | ||
▲ Show 20 Lines • Show All 471 Lines • ▼ Show 20 Line(s) | 794 | if (httpReconnect(CUPS_HTTP_DEFAULT)) { | |||
795 | // Server might be restarting sleep for a few ms | 797 | // Server might be restarting sleep for a few ms | ||
796 | msleep(500); | 798 | msleep(500); | ||
797 | } | 799 | } | ||
798 | 800 | | |||
799 | // Try the request again | 801 | // Try the request again | ||
800 | return ++internalErrorCount < 3; | 802 | return ++internalErrorCount < 3; | ||
801 | } | 803 | } | ||
802 | 804 | | |||
805 | total_retries++; | ||||
806 | | ||||
807 | if (total_retries > (password_retries + 3)) { | ||||
cfeck: Add spaces around + | |||||
808 | // Something is wrong. | ||||
809 | // This will happen if the password_cb function is not called, | ||||
810 | // which will for example be the case if the server has | ||||
811 | // an IP blacklist and thus always return 403. | ||||
812 | // In this case, there is nothing we can do. | ||||
813 | return false; | ||||
814 | } | ||||
815 | | ||||
803 | bool forceAuth = false; | 816 | bool forceAuth = false; | ||
804 | // If our user is forbidden to perform the | 817 | // If our user is forbidden to perform the | ||
805 | // task we try again using the root user | 818 | // task we try again using the root user | ||
806 | // ONLY if it was the first time | 819 | // ONLY if it was the first time | ||
807 | if (status == IPP_FORBIDDEN && | 820 | if (status == IPP_FORBIDDEN && | ||
808 | password_retries == 0) { | 821 | password_retries == 0) { | ||
809 | // Pretend to be the root user | 822 | // Pretend to be the root user | ||
810 | // Sometimes setting this just works | 823 | // Sometimes setting this just works | ||
811 | cupsSetUser("root"); | 824 | cupsSetUser("root"); | ||
812 | 825 | | |||
813 | // force authentication | 826 | // force authentication | ||
814 | forceAuth = true; | 827 | forceAuth = true; | ||
815 | } | 828 | } | ||
816 | 829 | | |||
817 | if (status == IPP_NOT_AUTHORIZED || | 830 | if (status == IPP_NOT_AUTHORIZED || | ||
818 | status == IPP_NOT_AUTHENTICATED) { | 831 | status == IPP_NOT_AUTHENTICATED) { | ||
819 | if (password_retries > 3 || password_retries == -1) { | 832 | if (password_retries > 3 || password_retries == -1) { | ||
820 | // the authentication failed 3 times | 833 | // the authentication failed 3 times | ||
821 | // OR the dialog was canceld (-1) | 834 | // OR the dialog was canceld (-1) | ||
822 | // reset to 0 and quit the do-while loop | 835 | // reset to 0 and quit the do-while loop | ||
823 | password_retries = 0; | 836 | password_retries = 0; | ||
837 | total_retries = 0; | ||||
824 | return false; | 838 | return false; | ||
825 | } | 839 | } | ||
826 | 840 | | |||
827 | // force authentication | 841 | // force authentication | ||
828 | forceAuth = true; | 842 | forceAuth = true; | ||
829 | } | 843 | } | ||
830 | 844 | | |||
831 | if (forceAuth) { | 845 | if (forceAuth) { | ||
▲ Show 20 Lines • Show All 51 Lines • Show Last 20 Lines |
Add spaces around +