summaryrefslogtreecommitdiff
path: root/usr/src/lib
diff options
context:
space:
mode:
authorsonam gupta - Sun Microsystems - Bangalore India <Sonam.Gupta@Sun.COM>2009-03-23 23:26:09 -0700
committersonam gupta - Sun Microsystems - Bangalore India <Sonam.Gupta@Sun.COM>2009-03-23 23:26:09 -0700
commit3d09a4fec6be19a6f09e277d5d5d17942bb4abf4 (patch)
treee494bd339b4d362c20d064d041407385b34066e0 /usr/src/lib
parent546a399722fe82dc300c308a8fb86a11d2ca3ba3 (diff)
downloadillumos-joyent-3d09a4fec6be19a6f09e277d5d5d17942bb4abf4.tar.gz
6789790 'lpstat -o' doesnot display the host-info along with the owner of the request with ipp service
Diffstat (limited to 'usr/src/lib')
-rw-r--r--usr/src/lib/print/libipp-listener/Makefile.com5
-rw-r--r--usr/src/lib/print/libipp-listener/common/print-job.c66
-rw-r--r--usr/src/lib/print/libpapi-ipp/common/job.c17
3 files changed, 76 insertions, 12 deletions
diff --git a/usr/src/lib/print/libipp-listener/Makefile.com b/usr/src/lib/print/libipp-listener/Makefile.com
index 74db2efd60..6e06c1a360 100644
--- a/usr/src/lib/print/libipp-listener/Makefile.com
+++ b/usr/src/lib/print/libipp-listener/Makefile.com
@@ -19,10 +19,9 @@
# CDDL HEADER END
#
#
-# Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
-# ident "%Z%%M% %I% %E% SMI"
#
LIBRARY = libipp-listener.a
@@ -55,7 +54,7 @@ CPPFLAGS += -I../../libipp-core/common
MAPFILES = $(SRCDIR)/mapfile
-LDLIBS += -lipp-core -lpapi -lc
+LDLIBS += -lipp-core -lpapi -lc -lsocket -lnsl
.KEEP_STATE:
diff --git a/usr/src/lib/print/libipp-listener/common/print-job.c b/usr/src/lib/print/libipp-listener/common/print-job.c
index 3b24d53339..4b95f32819 100644
--- a/usr/src/lib/print/libipp-listener/common/print-job.c
+++ b/usr/src/lib/print/libipp-listener/common/print-job.c
@@ -20,17 +20,20 @@
*/
/*
- * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
*/
/* $Id: print-job.c 146 2006-03-24 00:26:54Z njacobs $ */
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#include <stdio.h>
#include <stdlib.h>
+#include <netdb.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
#include <papi.h>
#include <ipp.h>
#include <ipp-listener.h>
@@ -47,12 +50,13 @@ ipp_print_job(papi_service_t svc, papi_attribute_t **request,
char *queue = NULL;
ssize_t rc;
char buf[BUFSIZ];
+ char *host = NULL;
char *keys[] = { "attributes-natural-language", "attributes-charset",
"printer-uri", NULL };
/* Get operational attributes from the request */
(void) papiAttributeListGetCollection(request, NULL,
- "operational-attributes-group", &operational);
+ "operational-attributes-group", &operational);
/*
* The operational-attributes-group must contain:
@@ -61,7 +65,7 @@ ipp_print_job(papi_service_t svc, papi_attribute_t **request,
get_printer_id(operational, &queue, NULL);
if (queue == NULL) {
ipp_set_status(response, status, "printer-uri: %s",
- papiStatusString(status));
+ papiStatusString(status));
return (PAPI_BAD_REQUEST);
}
@@ -83,15 +87,59 @@ ipp_print_job(papi_service_t svc, papi_attribute_t **request,
/* copy any job-attributes-group attributes for the PAPI call */
if (papiAttributeListGetCollection(request, NULL,
- "job-attributes-group", &operational) == PAPI_OK)
+ "job-attributes-group", &operational) == PAPI_OK)
copy_attributes(&job_attributes, operational);
+ /* Set "job-originating-host-name" attribute if not set */
+ papiAttributeListGetString(job_attributes, NULL,
+ "job-originating-host-name", &host);
+
+ if (host == NULL) {
+ int fd = -1;
+ (void) papiAttributeListGetInteger(request, NULL,
+ "peer-socket", &fd);
+
+ if (fd != -1) {
+ struct sockaddr_in peer;
+ int peer_len;
+
+ peer_len = sizeof (peer);
+ if (getpeername(fd, (struct sockaddr *)&peer,
+ &peer_len) == 0) {
+ struct hostent *he;
+ int error_num;
+
+ he = getipnodebyaddr(&peer.sin_addr,
+ sizeof (peer.sin_addr),
+ peer.sin_family, &error_num);
+
+ if ((he != NULL) && (he->h_name != NULL)) {
+ papiAttributeListAddString(
+ &job_attributes,
+ PAPI_ATTR_REPLACE,
+ "job-originating-host-name",
+ he->h_name);
+ } else {
+ /*
+ * Node-name could not be read
+ * so set the ip-address
+ */
+ papiAttributeListAddString(
+ &job_attributes,
+ PAPI_ATTR_REPLACE,
+ "job-originating-host-name",
+ inet_ntoa(peer.sin_addr));
+ }
+ }
+ }
+ }
+
/* request job creation with a resulting stream that we can write to */
status = papiJobStreamOpen(svc, queue, job_attributes, NULL, &s);
papiAttributeListFree(job_attributes);
if (status != PAPI_OK) {
ipp_set_status(response, status, "job submission: %s",
- ipp_svc_status_mesg(svc, status));
+ ipp_svc_status_mesg(svc, status));
return (status);
}
@@ -100,7 +148,7 @@ ipp_print_job(papi_service_t svc, papi_attribute_t **request,
status = papiJobStreamWrite(svc, s, buf, rc);
if (status != PAPI_OK) {
ipp_set_status(response, status, "write job data: %s",
- ipp_svc_status_mesg(svc, status));
+ ipp_svc_status_mesg(svc, status));
return (status);
}
@@ -108,7 +156,7 @@ ipp_print_job(papi_service_t svc, papi_attribute_t **request,
status = papiJobStreamClose(svc, s, &j);
if (status != PAPI_OK) {
ipp_set_status(response, status, "close job stream: %s",
- ipp_svc_status_mesg(svc, status));
+ ipp_svc_status_mesg(svc, status));
papiJobFree(j); /* we shouldn't have a job, but just in case */
return (status);
}
diff --git a/usr/src/lib/print/libpapi-ipp/common/job.c b/usr/src/lib/print/libpapi-ipp/common/job.c
index 0c4aac1af2..c2938850dc 100644
--- a/usr/src/lib/print/libpapi-ipp/common/job.c
+++ b/usr/src/lib/print/libpapi-ipp/common/job.c
@@ -140,6 +140,23 @@ populate_job_request(service_t *svc, papi_attribute_t ***request,
/* add the job attributes group to the request */
if (job != NULL) {
+ /*
+ * Add job-originating-host-name to attributes
+ * if not already set.
+ */
+ char *hostname = NULL;
+
+ papiAttributeListGetString(job, NULL,
+ "job-originating-host-name", &hostname);
+
+ if (hostname == NULL) {
+ char host[BUFSIZ];
+
+ if (gethostname(host, sizeof (host)) == 0)
+ papiAttributeListAddString(&job, PAPI_ATTR_EXCL,
+ "job-originating-host-name", host);
+ }
+
papiAttributeListAddCollection(request, PAPI_ATTR_REPLACE,
"job-attributes-group", job);
papiAttributeListFree(job);