summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2014-05-06 19:05:20 +0200
committerSimon Rettberg2014-05-06 19:05:20 +0200
commit206fe0a050de1e5b2919affdec617000426434fb (patch)
tree5832a7b059f9ef5f51205806db9f1a43bc0af27f
parentFix: run_backend returned wrong status code (diff)
downloadprintergui-206fe0a050de1e5b2919affdec617000426434fb.tar.gz
printergui-206fe0a050de1e5b2919affdec617000426434fb.tar.xz
printergui-206fe0a050de1e5b2919affdec617000426434fb.zip
[printpwgui] rename helper_error to helper_messageBox, show messageBox if print job was submitted to remote print server, handle "Printer does not exist" message from backend
-rw-r--r--src/pwgui/main.cpp55
1 files changed, 38 insertions, 17 deletions
diff --git a/src/pwgui/main.cpp b/src/pwgui/main.cpp
index 8cccccd..3d6059c 100644
--- a/src/pwgui/main.cpp
+++ b/src/pwgui/main.cpp
@@ -21,6 +21,8 @@
#define BUFLEN 1000
#define ENVLEN 10000
+#define CUSTOM_CUPS_NO_SUCH_PRINTER 50
+
static int pid = -1;
// UID and GUI of user we should drop privileges to
static int ruid = 65534, rgid = 65534;
@@ -37,7 +39,7 @@ static void helper_dropprivs();
static void helper_copyenv();
static char *helper_urlencode(char *s, char *enc);
static int helper_cupsError(const int code);
-static void helper_error(const char *caption, const char *text);
+static void helper_messageBox(const char *caption, const char *text, const bool error = false);
int main(int argc, char *argv[])
{
@@ -77,7 +79,7 @@ int main(int argc, char *argv[])
// Is valid?
if (access(backend, X_OK | R_OK) != 0) {
helper_getpiduid(argv[2], argv[3]);
- helper_error("PrinterGUI", "Kein Backend für den gewählten Drucker vorhanden.");
+ helper_messageBox("PrinterGUI", "Kein Backend für den gewählten Drucker vorhanden.");
fprintf(stderr, "ERROR: Backend %s is not executable.\n", backend);
return CUPS_BACKEND_FAILED;
}
@@ -102,7 +104,7 @@ int main(int argc, char *argv[])
snprintf(tmpfile, NAMELEN, "/tmp/print-%s-%d-%s-%d", argv[1], (int)time(NULL), argv[2], (int)getpid());
int fh = open(tmpfile, O_CREAT | O_WRONLY | O_TRUNC, 0600);
if (fh < 0) {
- helper_error("PrinterGUI", "Konnte temporäre Datei für den Druckjob nicht anlegen.");
+ helper_messageBox("PrinterGUI", "Konnte temporäre Datei für den Druckjob nicht anlegen.");
fprintf(stderr, "ERROR: Could not open %s for writing..\n", tmpfile);
return CUPS_BACKEND_FAILED;
}
@@ -113,13 +115,13 @@ int main(int argc, char *argv[])
bytes = read(STDIN_FILENO, buffer, BUFLEN);
if (bytes == 0) break;
if (bytes < 0) {
- helper_error("PrinterGUI", "Konnte den Druckjob nicht auf STDIN empfangen.");
+ helper_messageBox("PrinterGUI", "Konnte den Druckjob nicht auf STDIN empfangen.");
fprintf(stderr, "ERROR: Could not read print job from STDIN.\n");
remove(tmpfile);
return CUPS_BACKEND_FAILED;
}
if ((ret = write(fh, buffer, bytes)) != bytes) {
- helper_error("PrinterGUI", "Konnte Druckjob nicht in temporäre Datei schreiben.");
+ helper_messageBox("PrinterGUI", "Konnte Druckjob nicht in temporäre Datei schreiben.");
fprintf(stderr, "ERROR: Could not write %d bytes to %s (wrote %d)\n", (int)bytes, tmpfile, (int)ret);
remove(tmpfile);
return CUPS_BACKEND_FAILED;
@@ -134,7 +136,7 @@ int main(int argc, char *argv[])
snprintf(tmpfile, NAMELEN, "%s", argv[6]);
int fh = open(tmpfile, O_RDONLY);
if (fh < 0) {
- helper_error("PrinterGUI", "Konnte den Druckjob nicht vom Dateisystem lesen.");
+ helper_messageBox("PrinterGUI", "Konnte den Druckjob nicht vom Dateisystem lesen.");
fprintf(stderr, "ERROR: Could not open %s for reading..\n", tmpfile);
return CUPS_BACKEND_FAILED;
}
@@ -155,7 +157,7 @@ int main(int argc, char *argv[])
fputs("ERROR: Opening PW dialog....\n", stderr);
int pfd[2];
if (pipe(pfd) != 0) {
- helper_error("PrinterGUI", "Konnte pipe für die GUI nicht anlegen.");
+ helper_messageBox("PrinterGUI", "Konnte pipe für die GUI nicht anlegen.");
fputs("ERROR: Could not create pipe for GUI.\n", stderr);
return CUPS_BACKEND_FAILED;
}
@@ -179,7 +181,7 @@ int main(int argc, char *argv[])
// Wait for child to die
waitpid(pid, NULL, 0); // Don't check status, just look at pipe data
if (bytes <= 0) { // Probably means user pressed cancel
- helper_error("PrinterGUI", "Druckauftrag abgebrochen.");
+ helper_messageBox("PrinterGUI", "Druckauftrag abgebrochen.");
fputs("ERROR: Could not read anything from pipe after showing GUI.\n", stderr);
remove(tmpfile);
return CUPS_BACKEND_CANCEL;
@@ -245,15 +247,21 @@ static int run_backend(char *backend, char *uri, char *jobid, char *user, char *
close(pipefd[1]); // close writing end
char buffer[BUFLEN];
bool needAuth = false;
+ bool nonexistent = false;
int readlen = 0;
while ((readlen = read(pipefd[0], buffer, BUFLEN-1)) > 0) {
buffer[readlen] = '\0';
+ fprintf(stderr, "ERROR: BACKEND: %s\n", buffer);
if (strstr(buffer, "Unable to get printer status (Unauthorized)") != NULL) {
needAuth = true;
if (kill(pid, SIGTERM) < 0) {
fprintf(stderr, "ERROR: Sending kill1 to backend %d failed: %d\n", (int)pid, errno);
}
break;
+ } else if (strstr(buffer, "Destination printer does not exist") != NULL) {
+ nonexistent = true;
+ kill(pid, SIGTERM);
+ break;
}
}
close(pipefd[0]);
@@ -269,6 +277,10 @@ static int run_backend(char *backend, char *uri, char *jobid, char *user, char *
fprintf(stderr, "ERROR: Killed backend because of 'unauthorized' message (iprint crap?), trying with auth\n");
return CUPS_BACKEND_AUTH_REQUIRED;
}
+ if (nonexistent) {
+ fprintf(stderr, "ERROR: Destination printer does not exist!\n");
+ return CUSTOM_CUPS_NO_SUCH_PRINTER;
+ }
if (!WIFEXITED(status)) {
fprintf(stderr, "ERROR: Running backend %s failed!\n", backend);
return CUPS_BACKEND_FAILED;
@@ -412,47 +424,52 @@ static int helper_cupsError(const int code)
{
switch (code) {
case CUPS_BACKEND_OK:
+ helper_messageBox("CUPS", "Der Druckauftrag wurde erfolgreich an den print server übermittelt", false);
return CUPS_BACKEND_OK;
case CUPS_BACKEND_FAILED:
// The print file was not successfully transmitted to the device or remote server. The scheduler will respond to this by canceling the job, retrying the job, or stopping the queue depending on the state of the error-policy attribute.
- helper_error("CUPS Fehler", "Fehler beim lokalen Verarbeiten des Druckauftrags");
+ helper_messageBox("CUPS Fehler", "Fehler beim lokalen Verarbeiten des Druckauftrags");
return CUPS_BACKEND_HOLD;
case CUPS_BACKEND_AUTH_REQUIRED:
// The print file was not successfully transmitted because valid authentication information is required. The scheduler will respond to this by holding the job and adding the "cups-held-for-authentication" keyword to the "job-reasons" attribute.
- helper_error("CUPS Fehler", "Authentifizierung am Druckserver/Drucker fehlgeschlagen");
+ helper_messageBox("CUPS Fehler", "Authentifizierung am Druckserver/Drucker fehlgeschlagen");
break;
case CUPS_BACKEND_HOLD:
// The print file was not successfully transmitted because it cannot be printed at this time. The scheduler will respond to this by holding the job.
- helper_error("CUPS Fehler", "Der Drucker hat die Annahme des Druckauftrags verweigert (3)");
+ helper_messageBox("CUPS Fehler", "Der Drucker hat die Annahme des Druckauftrags verweigert (3)");
break;
case CUPS_BACKEND_STOP:
// The print file was not successfully transmitted because it cannot be printed at this time. The scheduler will respond to this by stopping the queue.
- helper_error("CUPS Fehler", "Der Drucker hat die Annahme des Druckauftrags verweigert (4)");
+ helper_messageBox("CUPS Fehler", "Der Drucker hat die Annahme des Druckauftrags verweigert (4)");
return CUPS_BACKEND_HOLD;
case CUPS_BACKEND_CANCEL:
// The print file was not successfully transmitted because one or more attributes are not supported or the job was canceled at the printer. The scheduler will respond to this by canceling the job.
- helper_error("CUPS Fehler", "Fehler 5 beim lokalen Verarbeiten des Druckauftrags");
+ helper_messageBox("CUPS Fehler", "Fehler 5 beim lokalen Verarbeiten des Druckauftrags");
return CUPS_BACKEND_HOLD;
case CUPS_BACKEND_RETRY:
// The print file was not successfully transmitted because of a temporary issue. The scheduler will retry the job at a future time - other jobs may print before this one.
- helper_error("CUPS Fehler", "Fehler 6 beim lokalen Verarbeiten des Druckauftrags");
+ helper_messageBox("CUPS Fehler", "Fehler 6 beim lokalen Verarbeiten des Druckauftrags");
return CUPS_BACKEND_HOLD;
case CUPS_BACKEND_RETRY_CURRENT:
// The print file was not successfully transmitted because of a temporary issue. The scheduler will retry the job immediately without allowing intervening jobs.
- helper_error("CUPS Fehler", "Fehler 7 beim lokalen Verarbeiten des Druckauftrags");
+ helper_messageBox("CUPS Fehler", "Fehler 7 beim lokalen Verarbeiten des Druckauftrags");
return CUPS_BACKEND_HOLD;
+
+ case CUSTOM_CUPS_NO_SUCH_PRINTER:
+ helper_messageBox("CUPS Fehler", "Die Druckerwarteschlange existiert nicht auf dem print server. Fehlerhafte lokale printers.conf?");
+ return CUPS_BACKEND_CANCEL;
}
return code;
}
-static void helper_error(const char *caption, const char *text)
+static void helper_messageBox(const char *caption, const char *text, const bool error)
{
const pid_t pid = fork();
if (pid == 0) {
@@ -463,7 +480,11 @@ static void helper_error(const char *caption, const char *text)
helper_dropprivs();
helper_copyenv();
QApplication a(argc, argv);
- QMessageBox::critical(NULL, QString::fromUtf8(caption), QString::fromUtf8(text));
+ if (error) {
+ QMessageBox::critical(NULL, QString::fromUtf8(caption), QString::fromUtf8(text));
+ } else {
+ QMessageBox::information(NULL, QString::fromUtf8(caption), QString::fromUtf8(text));
+ }
exit(a.exec());
return;
}