summaryrefslogtreecommitdiff
path: root/usr/src/lib/print/libpapi-ipp
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src/lib/print/libpapi-ipp')
-rw-r--r--usr/src/lib/print/libpapi-ipp/common/ipp-support.c77
-rw-r--r--usr/src/lib/print/libpapi-ipp/common/job.c97
2 files changed, 98 insertions, 76 deletions
diff --git a/usr/src/lib/print/libpapi-ipp/common/ipp-support.c b/usr/src/lib/print/libpapi-ipp/common/ipp-support.c
index 3196afccd9..ab3d1a337c 100644
--- a/usr/src/lib/print/libpapi-ipp/common/ipp-support.c
+++ b/usr/src/lib/print/libpapi-ipp/common/ipp-support.c
@@ -20,14 +20,13 @@
*/
/*
- * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
*/
/* $Id: ipp-support.c 148 2006-04-25 16:54:17Z njacobs $ */
-#pragma ident "%Z%%M% %I% %E% SMI"
#include <papi_impl.h>
#include <stdlib.h>
@@ -155,13 +154,13 @@ ipp_initialize_request(service_t *svc, papi_attribute_t ***request,
uint16_t operation)
{
papiAttributeListAddInteger(request, PAPI_ATTR_EXCL,
- "version-major", 1);
+ "version-major", 1);
papiAttributeListAddInteger(request, PAPI_ATTR_EXCL,
- "version-minor", 1);
+ "version-minor", 1);
papiAttributeListAddInteger(request, PAPI_ATTR_EXCL,
- "request-id", (short)lrand48());
+ "request-id", (short)lrand48());
papiAttributeListAddInteger(request, PAPI_ATTR_EXCL,
- "operation-id", operation);
+ "operation-id", operation);
}
void
@@ -181,17 +180,17 @@ ipp_initialize_operational_attributes(service_t *svc, papi_attribute_t ***op,
* requesting-user-name (process user or none)
*/
papiAttributeListAddString(op, PAPI_ATTR_EXCL,
- "attributes-charset", charset);
+ "attributes-charset", charset);
papiAttributeListAddString(op, PAPI_ATTR_EXCL,
- "attributes-natural-language", language);
+ "attributes-natural-language", language);
if (printer != NULL)
ipp_add_printer_uri(svc, printer, op);
if ((printer != NULL) && (job_id >= 0))
papiAttributeListAddInteger(op, PAPI_ATTR_EXCL,
- "job-id", job_id);
+ "job-id", job_id);
if ((pw = getpwuid(getuid())) != NULL)
user = pw->pw_name;
@@ -204,7 +203,7 @@ ipp_initialize_operational_attributes(service_t *svc, papi_attribute_t ***op,
user = svc->user;
}
papiAttributeListAddString(op, PAPI_ATTR_REPLACE,
- "requesting-user-name", user);
+ "requesting-user-name", user);
}
#ifndef OPID_CUPS_GET_DEFAULT /* for servers that will enumerate */
@@ -232,23 +231,23 @@ _default_destination(service_t *svc, char **uri)
ipp_initialize_request(svc, &request, OPID_CUPS_GET_DEFAULT);
ipp_initialize_operational_attributes(svc, &op, NULL, -1);
papiAttributeListAddString(&op, PAPI_ATTR_APPEND,
- "requested-attributes", "printer-uri-supported");
+ "requested-attributes", "printer-uri-supported");
papiAttributeListAddCollection(&request, PAPI_ATTR_REPLACE,
- "operational-attributes-group", op);
+ "operational-attributes-group", op);
papiAttributeListFree(op);
result = ipp_send_request(svc, request, &response);
papiAttributeListFree(request);
op = NULL;
papiAttributeListGetCollection(response, NULL,
- "printer-attributes-group", &op);
+ "printer-attributes-group", &op);
if (uri != NULL) {
char *tmp = NULL;
papiAttributeListGetString(op, NULL, "printer-uri", &tmp);
papiAttributeListGetString(op, NULL,
- "printer-uri-supported", &tmp);
+ "printer-uri-supported", &tmp);
if (tmp != NULL)
*uri = strdup(tmp);
}
@@ -341,7 +340,7 @@ ipp_request_read(void *fd, void *buffer, size_t length)
}
#ifdef DEBUG
printf("ipp_request_read(0x%8.8x, 0x%8.8x, %d) = %d\n",
- fd, buffer, length, rc);
+ fd, buffer, length, rc);
httpDumpData(stdout, "ipp_request_read:", buffer, length);
#endif
@@ -365,16 +364,16 @@ ipp_send_initial_request_block(service_t *svc, papi_attribute_t **request,
httpClearFields(svc->connection);
if (svc->transfer_encoding == TRANSFER_ENCODING_CHUNKED)
httpSetField(svc->connection, HTTP_FIELD_TRANSFER_ENCODING,
- "chunked");
+ "chunked");
else {
sprintf(length, "%lu", (unsigned long)(file_size + chunk_size));
httpSetField(svc->connection, HTTP_FIELD_CONTENT_LENGTH,
- length);
+ length);
}
httpSetField(svc->connection, HTTP_FIELD_CONTENT_TYPE,
- "application/ipp");
+ "application/ipp");
httpSetField(svc->connection, HTTP_FIELD_AUTHORIZATION,
- svc->connection->authstring);
+ svc->connection->authstring);
/* flush any state information about this connection */
httpFlush(svc->connection);
@@ -451,15 +450,15 @@ setAuthString(service_t *svc)
return (-1);
if (strncmp(http->fields[HTTP_FIELD_WWW_AUTHENTICATE],
- "Basic", 5) == 0) {
+ "Basic", 5) == 0) {
char plain[BUFSIZ];
snprintf(plain, sizeof (plain), "%s:%s", user, passphrase);
httpEncode64(encoded, plain);
snprintf(http->authstring, sizeof (http->authstring),
- "Basic %s", encoded);
+ "Basic %s", encoded);
} else if (strncmp(http->fields[HTTP_FIELD_WWW_AUTHENTICATE],
- "Digest", 6) == 0) {
+ "Digest", 6) == 0) {
char realm[HTTP_MAX_VALUE];
char nonce[HTTP_MAX_VALUE];
char line [BUFSIZ];
@@ -468,12 +467,12 @@ setAuthString(service_t *svc)
char *uri = svc->post;
httpGetSubField(http, HTTP_FIELD_WWW_AUTHENTICATE,
- "realm", realm);
+ "realm", realm);
httpGetSubField(http, HTTP_FIELD_WWW_AUTHENTICATE,
- "nonce", nonce);
+ "nonce", nonce);
snprintf(line, sizeof (line), "%s:%s:%s", user, realm,
- passphrase);
+ passphrase);
md5_calc(urp, line, strlen(line));
snprintf(line, sizeof (line), "POST:%s", uri);
@@ -483,9 +482,9 @@ setAuthString(service_t *svc)
md5_calc(encoded, line, strlen(line));
snprintf(http->authstring, sizeof (http->authstring),
- "Digest username=\"%s\", realm=\"%s\", nonce=\"%s\", "
- "uri=\"%s\", response=\"%s\"", user, realm, nonce, uri,
- encoded);
+ "Digest username=\"%s\", realm=\"%s\", nonce=\"%s\", "
+ "uri=\"%s\", response=\"%s\"", user, realm, nonce, uri,
+ encoded);
}
return (0);
@@ -498,14 +497,14 @@ ipp_status_info(service_t *svc, papi_attribute_t **response)
int32_t status = 0;
papiAttributeListGetCollection(response, NULL,
- "operational-attributes-group", &operational);
+ "operational-attributes-group", &operational);
if (operational != NULL) {
char *message = NULL;
papiAttributeListGetString(response, NULL,
- "status-message", &message);
+ "status-message", &message);
papiAttributeListAddString(&svc->attributes, PAPI_ATTR_REPLACE,
- "detailed-status-message", message);
+ "detailed-status-message", message);
}
papiAttributeListGetInteger(response, NULL, "status-code", &status);
@@ -518,6 +517,7 @@ ipp_send_request_with_file(service_t *svc, papi_attribute_t **request,
{
papi_status_t result = PAPI_OK;
ssize_t size = 0;
+ struct stat statbuf;
int fd;
#ifdef DEBUG
@@ -535,8 +535,15 @@ ipp_send_request_with_file(service_t *svc, papi_attribute_t **request,
if ((fd = open(file, O_RDONLY)) < 0) {
detailed_error(svc, "%s: %s", file, strerror(errno));
return (PAPI_DOCUMENT_ACCESS_ERROR);
+ } else if (strcmp("standard input", file) != 0) {
+ stat(file, &statbuf);
+ if (statbuf.st_size == 0) {
+ detailed_error(svc,
+ "Zero byte (empty) file: %s", file);
+ return (PAPI_BAD_ARGUMENT);
+ }
} else if (svc->transfer_encoding !=
- TRANSFER_ENCODING_CHUNKED) {
+ TRANSFER_ENCODING_CHUNKED) {
struct stat st;
if (fstat(fd, &st) >= 0)
@@ -559,7 +566,7 @@ ipp_send_request_with_file(service_t *svc, papi_attribute_t **request,
lseek(fd, 0L, SEEK_SET);
while ((rc = read(fd, buf, sizeof (buf))) > 0) {
if (ipp_request_write(svc, buf, rc)
- < rc) {
+ < rc) {
break;
}
}
@@ -595,13 +602,13 @@ ipp_send_request_with_file(service_t *svc, papi_attribute_t **request,
/* read the IPP response */
result = ipp_read_message(&ipp_request_read, svc, response,
- IPP_TYPE_RESPONSE);
+ IPP_TYPE_RESPONSE);
if (result == PAPI_OK)
result = ipp_status_info(svc, *response);
#ifdef DEBUG
fprintf(stderr, "\nIPP-RESPONSE: (%s) (%s)", (file ? file : ""),
- papiStatusString(result));
+ papiStatusString(result));
papiAttributeListPrint(stderr, *response, " ");
putc('\n', stderr);
fflush(stderr);
diff --git a/usr/src/lib/print/libpapi-ipp/common/job.c b/usr/src/lib/print/libpapi-ipp/common/job.c
index 0ed762cece..0c4aac1af2 100644
--- a/usr/src/lib/print/libpapi-ipp/common/job.c
+++ b/usr/src/lib/print/libpapi-ipp/common/job.c
@@ -20,14 +20,13 @@
*/
/*
- * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
*/
/* $Id: job.c 148 2006-04-25 16:54:17Z njacobs $ */
-#pragma ident "%Z%%M% %I% %E% SMI"
/*LINTLIBRARY*/
@@ -35,6 +34,9 @@
#include <errno.h>
#include <string.h>
#include <papi_impl.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
#ifndef OPID_CUPS_MOVE_JOB
#define OPID_CUPS_MOVE_JOB 0x400D
@@ -84,7 +86,7 @@ papiJobGetPrinterName(papi_job_t job)
if (j != NULL)
(void) papiAttributeListGetString(j->attributes, NULL,
- "printer-name", &result);
+ "printer-name", &result);
return (result);
}
@@ -97,7 +99,7 @@ papiJobGetId(papi_job_t job)
if (j != NULL)
(void) papiAttributeListGetInteger(j->attributes, NULL,
- "job-id", &result);
+ "job-id", &result);
return (result);
}
@@ -129,17 +131,17 @@ populate_job_request(service_t *svc, papi_attribute_t ***request,
/* split up the attributes into operational and job attributes */
split_and_copy_attributes(operational_names, attributes,
- &operational, &job);
+ &operational, &job);
/* add the operational attributes group to the request */
papiAttributeListAddCollection(request, PAPI_ATTR_REPLACE,
- "operational-attributes-group", operational);
+ "operational-attributes-group", operational);
papiAttributeListFree(operational);
/* add the job attributes group to the request */
if (job != NULL) {
papiAttributeListAddCollection(request, PAPI_ATTR_REPLACE,
- "job-attributes-group", job);
+ "job-attributes-group", job);
papiAttributeListFree(job);
}
}
@@ -158,11 +160,11 @@ send_document_uri(service_t *svc, char *file, papi_attribute_t **attributes,
ipp_initialize_operational_attributes(svc, &op, printer, id);
papiAttributeListAddString(&op, PAPI_ATTR_REPLACE, "document-name",
- file);
+ file);
papiAttributeListAddBoolean(&op, PAPI_ATTR_REPLACE, "last-document",
- (last ? PAPI_TRUE : PAPI_FALSE));
+ (last ? PAPI_TRUE : PAPI_FALSE));
papiAttributeListAddCollection(&request, PAPI_ATTR_REPLACE,
- "operational-attributes-group", op);
+ "operational-attributes-group", op);
papiAttributeListFree(op);
/* send the IPP request to the server */
@@ -184,6 +186,7 @@ internal_job_submit(papi_service_t handle, char *printer,
{
papi_status_t result = PAPI_INTERNAL_ERROR;
service_t *svc = handle;
+ struct stat statbuf;
job_t *j = NULL;
int i;
uint16_t req_type = OPID_PRINT_JOB;
@@ -221,12 +224,24 @@ internal_job_submit(papi_service_t handle, char *printer,
req_type = OPID_VALIDATE_JOB;
/* if we have files, validate access to them */
if (files != NULL) {
- for (i = 0; files[i] != NULL; i++)
+ for (i = 0; files[i] != NULL; i++) {
if (access(files[i], R_OK) < 0) {
detailed_error(svc, "%s: %s", files[i],
- strerror(errno));
+ strerror(errno));
return (PAPI_DOCUMENT_ACCESS_ERROR);
}
+
+ if (strcmp("standard input", files[i]) != 0) {
+ stat(files[i], &statbuf);
+ if (statbuf.st_size == 0) {
+ detailed_error(svc,
+ "Zero byte (empty) file: "
+ "%s",
+ files[i]);
+ return (PAPI_BAD_ARGUMENT);
+ }
+ }
+ }
files = NULL;
}
break;
@@ -246,7 +261,7 @@ internal_job_submit(papi_service_t handle, char *printer,
switch (req_type) {
case OPID_PRINT_JOB:
result = ipp_send_request_with_file(svc, request, &response,
- files[0]);
+ files[0]);
break;
case OPID_CREATE_JOB:
case OPID_VALIDATE_JOB:
@@ -261,21 +276,21 @@ internal_job_submit(papi_service_t handle, char *printer,
/* retrieve the job attributes */
papiAttributeListGetCollection(response, NULL,
- "job-attributes-group", &op);
+ "job-attributes-group", &op);
copy_attributes(&j->attributes, op);
if (req_type == OPID_CREATE_JOB) {
int32_t id = 0;
papiAttributeListGetInteger(j->attributes, NULL,
- "job-id", &id);
+ "job-id", &id);
/* send each document */
for (i = 0; ((result == PAPI_OK) && (files[i] != NULL));
- i++)
+ i++)
result = send_document_uri(svc, files[i],
- job_attributes,
- printer, id, (files[i+1]?0:1),
- data_type);
+ job_attributes,
+ printer, id, (files[i+1]?0:1),
+ data_type);
}
}
papiAttributeListFree(response);
@@ -289,7 +304,7 @@ papiJobSubmit(papi_service_t handle, char *printer,
papi_job_ticket_t *job_ticket, char **files, papi_job_t *job)
{
return (internal_job_submit(handle, printer, job_attributes,
- job_ticket, files, job, _WITH_DATA));
+ job_ticket, files, job, _WITH_DATA));
}
papi_status_t
@@ -298,7 +313,7 @@ papiJobSubmitByReference(papi_service_t handle, char *printer,
papi_job_ticket_t *job_ticket, char **files, papi_job_t *job)
{
return (internal_job_submit(handle, printer, job_attributes,
- job_ticket, files, job, _BY_REFERENCE));
+ job_ticket, files, job, _BY_REFERENCE));
}
papi_status_t
@@ -307,7 +322,7 @@ papiJobValidate(papi_service_t handle, char *printer,
papi_job_ticket_t *job_ticket, char **files, papi_job_t *job)
{
return (internal_job_submit(handle, printer, job_attributes,
- job_ticket, files, job, _VALIDATE));
+ job_ticket, files, job, _VALIDATE));
}
papi_status_t
@@ -329,7 +344,7 @@ papiJobStreamOpen(papi_service_t handle, char *printer,
/* create job request */
populate_job_request(svc, &request, job_attributes, printer,
- OPID_PRINT_JOB);
+ OPID_PRINT_JOB);
*stream = svc->connection;
@@ -349,7 +364,7 @@ papiJobStreamWrite(papi_service_t handle,
#ifdef DEBUG
printf("papiJobStreamWrite(0x%8.8x, 0x%8.8x, 0x%8.8x, %d)\n",
- handle, stream, buffer, buflen);
+ handle, stream, buffer, buflen);
httpDumpData(stdout, "papiJobStreamWrite:", buffer, buflen);
#endif
@@ -402,7 +417,7 @@ papiJobStreamClose(papi_service_t handle,
/* read the IPP response */
result = ipp_read_message(&ipp_request_read, svc, &response,
- IPP_TYPE_RESPONSE);
+ IPP_TYPE_RESPONSE);
if (result == PAPI_OK)
result = ipp_status_info(svc, response);
@@ -410,7 +425,7 @@ papiJobStreamClose(papi_service_t handle,
papi_attribute_t **op = NULL;
papiAttributeListGetCollection(response, NULL,
- "job-attributes-group", &op);
+ "job-attributes-group", &op);
copy_attributes(&j->attributes, op);
}
papiAttributeListFree(response);
@@ -448,18 +463,18 @@ papiJobQuery(papi_service_t handle, char *printer, int32_t job_id,
for (i = 0; requested_attrs[i] != NULL; i++)
papiAttributeListAddString(&op, PAPI_ATTR_APPEND,
- "requested-attributes", requested_attrs[i]);
+ "requested-attributes", requested_attrs[i]);
}
papiAttributeListAddCollection(&request, PAPI_ATTR_REPLACE,
- "operational-attributes-group", op);
+ "operational-attributes-group", op);
papiAttributeListFree(op);
result = ipp_send_request(svc, request, &response);
papiAttributeListFree(request);
op = NULL;
papiAttributeListGetCollection(response, NULL,
- "job-attributes-group", &op);
+ "job-attributes-group", &op);
copy_attributes(&j->attributes, op);
papiAttributeListFree(response);
@@ -488,7 +503,7 @@ _job_cancel_hold_release_restart_promote(papi_service_t handle,
ipp_initialize_operational_attributes(svc, &op, printer, job_id);
papiAttributeListAddCollection(&request, PAPI_ATTR_REPLACE,
- "operational-attributes-group", op);
+ "operational-attributes-group", op);
papiAttributeListFree(op);
result = ipp_send_request(svc, request, &response);
papiAttributeListFree(request);
@@ -501,7 +516,7 @@ papi_status_t
papiJobCancel(papi_service_t handle, char *printer, int32_t job_id)
{
return (_job_cancel_hold_release_restart_promote(handle, printer,
- job_id, OPID_CANCEL_JOB));
+ job_id, OPID_CANCEL_JOB));
}
@@ -509,28 +524,28 @@ papi_status_t
papiJobHold(papi_service_t handle, char *printer, int32_t job_id)
{
return (_job_cancel_hold_release_restart_promote(handle, printer,
- job_id, OPID_HOLD_JOB));
+ job_id, OPID_HOLD_JOB));
}
papi_status_t
papiJobRelease(papi_service_t handle, char *printer, int32_t job_id)
{
return (_job_cancel_hold_release_restart_promote(handle, printer,
- job_id, OPID_RELEASE_JOB));
+ job_id, OPID_RELEASE_JOB));
}
papi_status_t
papiJobRestart(papi_service_t handle, char *printer, int32_t job_id)
{
return (_job_cancel_hold_release_restart_promote(handle, printer,
- job_id, OPID_RESTART_JOB));
+ job_id, OPID_RESTART_JOB));
}
papi_status_t
papiJobPromote(papi_service_t handle, char *printer, int32_t job_id)
{
return (_job_cancel_hold_release_restart_promote(handle, printer,
- job_id, OPID_PROMOTE_JOB));
+ job_id, OPID_PROMOTE_JOB));
}
papi_status_t
@@ -555,14 +570,14 @@ papiJobMove(papi_service_t handle, char *printer, int32_t job_id,
ipp_initialize_operational_attributes(svc, &op, printer, job_id);
papiAttributeListAddCollection(&request, PAPI_ATTR_REPLACE,
- "operational-attributes-group", op);
+ "operational-attributes-group", op);
papiAttributeListFree(op);
op = NULL;
papiAttributeListAddString(&op, PAPI_ATTR_EXCL,
- "job-printer-uri", destination);
+ "job-printer-uri", destination);
papiAttributeListAddCollection(&request, PAPI_ATTR_REPLACE,
- "job-attributes-group", op);
+ "job-attributes-group", op);
papiAttributeListFree(op);
result = ipp_send_request(svc, request, &response);
@@ -598,16 +613,16 @@ papiJobModify(papi_service_t handle, char *printer, int32_t job_id,
ipp_initialize_operational_attributes(svc, &op, printer, job_id);
papiAttributeListAddCollection(&request, PAPI_ATTR_REPLACE,
- "operational-attributes-group", op);
+ "operational-attributes-group", op);
papiAttributeListFree(op);
papiAttributeListAddCollection(&request, PAPI_ATTR_REPLACE,
- "job-attributes-group", attributes);
+ "job-attributes-group", attributes);
result = ipp_send_request(svc, request, &response);
papiAttributeListFree(request);
op = NULL;
papiAttributeListGetCollection(response, NULL,
- "job-attributes-group", &op);
+ "job-attributes-group", &op);
copy_attributes(&j->attributes, op);
papiAttributeListFree(response);