summaryrefslogtreecommitdiff
path: root/usr/src/cmd/print/bsd-sysv-commands/common.c
diff options
context:
space:
mode:
authorjacobs <none@none>2006-11-15 19:19:07 -0800
committerjacobs <none@none>2006-11-15 19:19:07 -0800
commit0a44ef6d9afbfe052a7e975f55ea0d2954b62a82 (patch)
treeafca18ba6ad0fb467b29e368f05399e53a19ec4a /usr/src/cmd/print/bsd-sysv-commands/common.c
parent3383b6dda001791704e0e66f7b78dd0dfe74f547 (diff)
downloadillumos-joyent-0a44ef6d9afbfe052a7e975f55ea0d2954b62a82.tar.gz
4634017 Lpadmin's new printer limit needs to be increased.
4941143 lpsched leaks memory in freeprinter() 6480891 lpsched fixes unused files 6486772 in.lpd should use libpapi 6486967 print-svc refers to /usr/sbin/cut 6487898 lpadmin doesn't add remote access 6488443 printmr/lpadmin should prefer IPP support when it's available 6490445 psm-lpd has incorrect mime type in it's translation table 6490453 lpr uses the wrong default mime type 6491971 in.lpd and the ipp listener should detect cycles 6491978 libhttp-core should build when -DDEBUG is specified 6492414 lpstat -o -l should report on requested form when available --HG-- rename : usr/src/cmd/lp/cmd/adaptor/Makefile => deleted_files/usr/src/cmd/lp/cmd/adaptor/Makefile rename : usr/src/cmd/lp/cmd/adaptor/cancel_job.c => deleted_files/usr/src/cmd/lp/cmd/adaptor/cancel_job.c rename : usr/src/cmd/lp/cmd/adaptor/misc.c => deleted_files/usr/src/cmd/lp/cmd/adaptor/misc.c rename : usr/src/cmd/lp/cmd/adaptor/misc.h => deleted_files/usr/src/cmd/lp/cmd/adaptor/misc.h rename : usr/src/cmd/lp/cmd/adaptor/show_queue.c => deleted_files/usr/src/cmd/lp/cmd/adaptor/show_queue.c rename : usr/src/cmd/lp/cmd/adaptor/submit_job.c => deleted_files/usr/src/cmd/lp/cmd/adaptor/submit_job.c rename : usr/src/cmd/print/gateway/Makefile => deleted_files/usr/src/cmd/print/gateway/Makefile rename : usr/src/cmd/print/gateway/adaptor.c => deleted_files/usr/src/cmd/print/gateway/adaptor.c rename : usr/src/cmd/print/gateway/adaptor.h => deleted_files/usr/src/cmd/print/gateway/adaptor.h rename : usr/src/cmd/print/gateway/cleanup.xml => deleted_files/usr/src/cmd/print/gateway/cleanup.xml rename : usr/src/cmd/print/gateway/main.c => deleted_files/usr/src/cmd/print/gateway/main.c rename : usr/src/cmd/print/gateway/print-cleanup => deleted_files/usr/src/cmd/print/gateway/print-cleanup rename : usr/src/cmd/print/gateway/printd.c => deleted_files/usr/src/cmd/print/gateway/printd.c rename : usr/src/cmd/print/gateway/translators/Makefile => deleted_files/usr/src/cmd/print/gateway/translators/Makefile rename : usr/src/cmd/print/gateway/translators/cascade/Makefile => deleted_files/usr/src/cmd/print/gateway/translators/cascade/Makefile rename : usr/src/cmd/print/gateway/translators/cascade/cascade.c => deleted_files/usr/src/cmd/print/gateway/translators/cascade/cascade.c rename : usr/src/cmd/print/gateway/translators/test/Makefile => deleted_files/usr/src/cmd/print/gateway/translators/test/Makefile rename : usr/src/cmd/print/gateway/translators/test/README => deleted_files/usr/src/cmd/print/gateway/translators/test/README rename : usr/src/cmd/print/gateway/translators/test/test.c => deleted_files/usr/src/cmd/print/gateway/translators/test/test.c rename : usr/src/cmd/print/gateway/rfc1179.xml => usr/src/cmd/print/bsd-sysv-commands/rfc1179.xml
Diffstat (limited to 'usr/src/cmd/print/bsd-sysv-commands/common.c')
-rw-r--r--usr/src/cmd/print/bsd-sysv-commands/common.c75
1 files changed, 72 insertions, 3 deletions
diff --git a/usr/src/cmd/print/bsd-sysv-commands/common.c b/usr/src/cmd/print/bsd-sysv-commands/common.c
index 5d70752563..73483957ff 100644
--- a/usr/src/cmd/print/bsd-sysv-commands/common.c
+++ b/usr/src/cmd/print/bsd-sysv-commands/common.c
@@ -32,6 +32,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
#include <alloca.h>
#include <string.h>
#include <libintl.h>
@@ -74,6 +77,41 @@ match_job(int id, char *user, int ac, char *av[])
return (-1);
}
+static struct {
+ char *mime_type;
+ char *lp_type;
+} type_map[] = {
+ { "text/plain", "simple" },
+ { "application/octet-stream", "raw" },
+ { "application/octet-stream", "any" },
+ { "application/postscript", "postscript" },
+ { "application/postscript", "ps" },
+ { "application/x-cif", "cif" },
+ { "application/x-dvi", "dvi" },
+ { "application/x-plot", "plot" },
+ { "application/x-ditroff", "troff" },
+ { "application/x-troff", "otroff" },
+ { "application/x-pr", "pr" },
+ { "application/x-fortran", "fortran" },
+ { "application/x-raster", "raster" },
+ { NULL, NULL}
+};
+
+char *
+lp_type_to_mime_type(char *lp_type)
+{
+ int i;
+
+ if (lp_type == NULL)
+ return ("application/octet-stream");
+
+ for (i = 0; type_map[i].lp_type != NULL; i++)
+ if (strcasecmp(type_map[i].lp_type, lp_type) == 0)
+ return (type_map[i].mime_type);
+
+ return (lp_type);
+}
+
/*
* to support job/printer status
*/
@@ -157,6 +195,8 @@ print_job_line(FILE *fp, int count, papi_job_t job, int fmt, int ac, char *av[])
"job-id", &id);
(void) papiAttributeListGetString(list, NULL,
"job-originating-user-name", &user);
+ (void) papiAttributeListGetString(list, NULL,
+ "job-originating-host-name", &host);
/* if we are looking and it doesn't match, return early */
if ((ac > 0) && (match_job(id, user, ac, av) < 0))
@@ -226,9 +266,9 @@ berkeley_queue_report(papi_service_t svc, FILE *fp, char *dest, int fmt,
papi_job_t *jobs = NULL;
char *pattrs[] = { "printer-name", "printer-state",
"printer-state-reasons", NULL };
- char *jattrs[] = {
- "job-name", "job-octets", "job-k-octets",
- "job-originating-user-name", "job-id",
+ char *jattrs[] = { "job-name", "job-octets", "job-k-octets", "job-id",
+ "job-originating-user-name",
+ "job-originating-host-name",
"number-of-intervening-jobs", NULL };
int num_jobs = 0;
@@ -371,6 +411,35 @@ jobSubmitSTDIN(papi_service_t svc, char *printer, papi_attribute_t **list,
return (status);
}
+/*
+ * is_postscript() will detect if the file passed in contains postscript
+ * data. A one is returned if the file contains postscript, zero is returned
+ * if the file is not postscript, and -1 is returned if an error occurs
+ */
+#define PS_MAGIC "%!"
+#define PC_PS_MAGIC "^D%!"
+int
+is_postscript(const char *file)
+{
+ char buf[3];
+ int fd;
+
+ if ((fd = open(file, O_RDONLY)) < 0)
+ return (-1);
+
+ if (read(fd, buf, sizeof (buf)) < 0) {
+ close(fd);
+ return (-1);
+ }
+ close(fd);
+
+ if ((strncmp(buf, PS_MAGIC, sizeof (PS_MAGIC) - 1) == 0) ||
+ (strncmp(buf, PC_PS_MAGIC, sizeof (PC_PS_MAGIC) - 1) == 0))
+ return (1);
+ else
+ return (0);
+}
+
static char **
all_list(papi_service_t svc)
{