openprinting-papi-svn Mailing List for OpenPrinting
Brought to you by:
njacobs,
shawn_pratt
You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
(2) |
May
(18) |
Jun
(2) |
Jul
(2) |
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
|
Feb
(2) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2008 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
(4) |
Jul
(2) |
Aug
(5) |
Sep
|
Oct
|
Nov
|
Dec
|
From: <al...@us...> - 2008-08-27 15:08:23
|
Revision: 196 http://openprinting.svn.sourceforge.net/openprinting/?rev=196&view=rev Author: allad Date: 2008-08-27 15:08:32 +0000 (Wed, 27 Aug 2008) Log Message: ----------- Ironing out some bugs in ipp-support.c +Code cleaning Modified Paths: -------------- branches/GSOC-2008/papi/source/libpapi-cups/cups-ipp.c branches/GSOC-2008/papi/source/libpapi-cups/ipp-support.c Modified: branches/GSOC-2008/papi/source/libpapi-cups/cups-ipp.c =================================================================== --- branches/GSOC-2008/papi/source/libpapi-cups/cups-ipp.c 2008-08-21 14:50:04 UTC (rev 195) +++ branches/GSOC-2008/papi/source/libpapi-cups/cups-ipp.c 2008-08-27 15:08:32 UTC (rev 196) @@ -347,8 +347,12 @@ PAPI_ATTR_APPEND, attr->name, attr->values[i].integer); break; case IPP_TAG_BOOLEAN: + for(i = 0; i<attr->num_values;i++) + papiAttributeListAddBoolean(&attributes, + PAPI_ATTR_APPEND, attr->name, attr->values[i].boolean); break; case IPP_TAG_DATE: + break; } Modified: branches/GSOC-2008/papi/source/libpapi-cups/ipp-support.c =================================================================== --- branches/GSOC-2008/papi/source/libpapi-cups/ipp-support.c 2008-08-21 14:50:04 UTC (rev 195) +++ branches/GSOC-2008/papi/source/libpapi-cups/ipp-support.c 2008-08-27 15:08:32 UTC (rev 196) @@ -283,33 +283,6 @@ } } - -/* - * don't actually write anything, just add to the total size and return the - * size of what would be written, so we can figure out how big the request - * is going to be. - */ -static ssize_t -size_calculate(void *fd, void *buffer, size_t length) -{ - ssize_t *size = (ssize_t *)fd; - - *size += length; - return (length); -} - - -static ssize_t -build_chunk(void *fd, void *buffer, size_t length) -{ - char **s1 = fd; - - memcpy(*s1, buffer, length); - *s1 = *s1 + length; - - return (length); -} - ssize_t ipp_request_write(void *fd, void *buffer, size_t length) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2008-08-21 14:49:56
|
Revision: 195 http://openprinting.svn.sourceforge.net/openprinting/?rev=195&view=rev Author: allad Date: 2008-08-21 14:50:04 +0000 (Thu, 21 Aug 2008) Log Message: ----------- CUPS layer implemented. Still some ironing out to be done though. Printer API using ipp-support layer : OK Job API : using ipp-support. Need to adapt ipp_send_initial_request() method to support Job Streaming Semantics. Modified Paths: -------------- branches/GSOC-2008/papi/source/libpapi-cups/Makefile.am branches/GSOC-2008/papi/source/libpapi-cups/ipp-support.c branches/GSOC-2008/papi/source/libpapi-cups/papi_impl.h branches/GSOC-2008/papi/source/libpapi-cups/printer.c Added Paths: ----------- branches/GSOC-2008/papi/source/libpapi-cups/job.c Modified: branches/GSOC-2008/papi/source/libpapi-cups/Makefile.am =================================================================== --- branches/GSOC-2008/papi/source/libpapi-cups/Makefile.am 2008-08-13 15:18:11 UTC (rev 194) +++ branches/GSOC-2008/papi/source/libpapi-cups/Makefile.am 2008-08-21 14:50:04 UTC (rev 195) @@ -48,6 +48,6 @@ papi_cupsincludedir = $(includedir) # PAPI support layered on CUPS -papi_cups_la_SOURCES = service.c cups-ipp.c strings.c +papi_cups_la_SOURCES = service.c cups-ipp.c strings.c ipp-support.c printer.c job.c EXTRA_DIST = papi_impl.h mapfile.in Modified: branches/GSOC-2008/papi/source/libpapi-cups/ipp-support.c =================================================================== --- branches/GSOC-2008/papi/source/libpapi-cups/ipp-support.c 2008-08-13 15:18:11 UTC (rev 194) +++ branches/GSOC-2008/papi/source/libpapi-cups/ipp-support.c 2008-08-21 14:50:04 UTC (rev 195) @@ -34,7 +34,6 @@ #include <errno.h> #include <fcntl.h> #include <sys/stat.h> -#include <md5.h> #include <config-site.h> @@ -72,78 +71,78 @@ switch (status) { case IPP_OK: return (PAPI_OK); - case IPP_OK_IGNORED_ATTRIBUTES: + case IPP_OK_SUBST: return (PAPI_OK); - case IPP_OK_CONFLICTING_ATTRIBUTES: + case IPP_OK_CONFLICT: return (PAPI_OK); case IPP_OK_IGNORED_SUBSCRIPTIONS: return (PAPI_OK_IGNORED_SUBSCRIPTIONS); case IPP_OK_IGNORED_NOTIFICATIONS: return (PAPI_OK_IGNORED_NOTIFICATIONS); - case IPP_CERR_BAD_REQUEST: + case IPP_BAD_REQUEST: return (PAPI_BAD_REQUEST); - case IPP_CERR_FORBIDDEN: + case IPP_FORBIDDEN: return (PAPI_FORBIDDEN); - case IPP_CERR_NOT_AUTHENTICATED: + case IPP_NOT_AUTHENTICATED: return (PAPI_NOT_AUTHENTICATED); - case IPP_CERR_NOT_AUTHORIZED: + case IPP_NOT_AUTHORIZED: return (PAPI_NOT_AUTHORIZED); - case IPP_CERR_NOT_POSSIBLE: + case IPP_NOT_POSSIBLE: return (PAPI_NOT_POSSIBLE); - case IPP_CERR_TIMEOUT: + case IPP_TIMEOUT: return (PAPI_TIMEOUT); - case IPP_CERR_NOT_FOUND: + case IPP_NOT_FOUND: return (PAPI_NOT_FOUND); - case IPP_CERR_GONE: + case IPP_GONE: return (PAPI_GONE); - case IPP_CERR_REQUEST_ENTITY: + case IPP_REQUEST_ENTITY: return (PAPI_REQUEST_ENTITY); - case IPP_CERR_REQUEST_VALUE: + case IPP_REQUEST_VALUE: return (PAPI_REQUEST_VALUE); - case IPP_CERR_DOCUMENT_FORMAT: + case IPP_DOCUMENT_FORMAT: return (PAPI_DOCUMENT_FORMAT); - case IPP_CERR_ATTRIBUTES: + case IPP_ATTRIBUTES: return (PAPI_ATTRIBUTES); - case IPP_CERR_URI_SCHEME: + case IPP_URI_SCHEME: return (PAPI_URI_SCHEME); - case IPP_CERR_CHARSET: + case IPP_CHARSET: return (PAPI_CHARSET); - case IPP_CERR_CONFLICT: + case IPP_CONFLICT: return (PAPI_CONFLICT); - case IPP_CERR_COMPRESSION_NOT_SUPPORTED: + case IPP_COMPRESSION_NOT_SUPPORTED: return (PAPI_COMPRESSION_NOT_SUPPORTED); - case IPP_CERR_COMPRESSION_ERROR: + case IPP_COMPRESSION_ERROR: return (PAPI_COMPRESSION_ERROR); - case IPP_CERR_DOCUMENT_FORMAT_ERROR: + case IPP_DOCUMENT_FORMAT_ERROR: return (PAPI_DOCUMENT_FORMAT_ERROR); - case IPP_CERR_DOCUMENT_ACCESS_ERROR: + case IPP_DOCUMENT_ACCESS_ERROR: return (PAPI_DOCUMENT_ACCESS_ERROR); - case IPP_CERR_ATTRIBUTES_NOT_SETTABLE: + case IPP_ATTRIBUTES_NOT_SETTABLE: return (PAPI_ATTRIBUTES_NOT_SETTABLE); - case IPP_CERR_IGNORED_ALL_SUBSCRIPTIONS: + case IPP_IGNORED_ALL_SUBSCRIPTIONS: return (PAPI_IGNORED_ALL_SUBSCRIPTIONS); - case IPP_CERR_TOO_MANY_SUBSCRIPTIONS: + case IPP_TOO_MANY_SUBSCRIPTIONS: return (PAPI_TOO_MANY_SUBSCRIPTIONS); - case IPP_CERR_IGNORED_ALL_NOTIFICATIONS: + case IPP_IGNORED_ALL_NOTIFICATIONS: return (PAPI_IGNORED_ALL_NOTIFICATIONS); - case IPP_CERR_PRINT_SUPPORT_FILE_NOT_FOUND: + case IPP_PRINT_SUPPORT_FILE_NOT_FOUND: return (PAPI_PRINT_SUPPORT_FILE_NOT_FOUND); - case IPP_SERR_INTERNAL: + case IPP_INTERNAL_ERROR: return (PAPI_INTERNAL_ERROR); - case IPP_SERR_OPERATION_NOT_SUPPORTED: + case IPP_OPERATION_NOT_SUPPORTED: return (PAPI_OPERATION_NOT_SUPPORTED); - case IPP_SERR_SERVICE_UNAVAILABLE: + case IPP_SERVICE_UNAVAILABLE: return (PAPI_SERVICE_UNAVAILABLE); - case IPP_SERR_VERSION_NOT_SUPPORTED: + case IPP_VERSION_NOT_SUPPORTED: return (PAPI_VERSION_NOT_SUPPORTED); - case IPP_SERR_DEVICE_ERROR: + case IPP_DEVICE_ERROR: return (PAPI_DEVICE_ERROR); - case IPP_SERR_TEMPORARY_ERROR: + case IPP_TEMPORARY_ERROR: return (PAPI_TEMPORARY_ERROR); - case IPP_SERR_NOT_ACCEPTING: + case IPP_NOT_ACCEPTING: return (PAPI_NOT_ACCEPTING); - case IPP_SERR_BUSY: - case IPP_SERR_CANCELLED: + case IPP_PRINTER_BUSY: + case IPP_ERROR_JOB_CANCELED: default: return (PAPI_TEMPORARY_ERROR); } @@ -348,14 +347,12 @@ } papi_status_t -ipp_send_initial_request_block(service_t *svc, papi_attribute_t **request, ipp_t **ippreq) +ipp_send_initial_request_block(papi_attribute_t **request, ipp_t **ippreq) { papi_status_t result = PAPI_OK; http_status_t status; - - /* build the request chunk */ result = ipp_write_message(ippreq,request); @@ -366,81 +363,7 @@ return (result); } -static int -setAuthString(service_t *svc) -{ - http_t *http; - char *user, *passphrase; - char encoded[BUFSIZ]; - if ((svc == NULL) || (svc->connection == NULL) || (svc->name == NULL)) - return (-1); - - http = svc->connection; - - if (svc->user == NULL) { - struct passwd *p; - - if ((p = getpwuid(getuid())) != NULL) { - user = p->pw_name; - } else if ((user = getenv("LOGNAME")) == NULL) - user = getenv("USER"); - if (user == NULL) - user = "nobody"; - } else - user = svc->user; - - /* if the passphrase is not set, use the Authentication Callback */ - if (((svc->password == NULL) || (svc->password[0] == '\0')) && - (svc->authCB != NULL)) - (svc->authCB)(svc, svc->app_data); - passphrase = svc->password; - - /* if there is still no passphrase, we have to fail */ - if ((passphrase == NULL) || (passphrase[0] == '\0')) - return (-1); - - if (strncmp(http->fields[HTTP_FIELD_WWW_AUTHENTICATE], - "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); - } else if (strncmp(http->fields[HTTP_FIELD_WWW_AUTHENTICATE], - "Digest", 6) == 0) { - char realm[HTTP_MAX_VALUE]; - char nonce[HTTP_MAX_VALUE]; - char line [BUFSIZ]; - char urp[128]; - char mr[128]; - char *uri = svc->post; - - httpGetSubField(http, HTTP_FIELD_WWW_AUTHENTICATE, - "realm", realm); - httpGetSubField(http, HTTP_FIELD_WWW_AUTHENTICATE, - "nonce", nonce); - - snprintf(line, sizeof (line), "%s:%s:%s", user, realm, - passphrase); - md5_calc(urp, line, strlen(line)); - - snprintf(line, sizeof (line), "POST:%s", uri); - md5_calc(mr, line, strlen(line)); - - snprintf(line, sizeof (line), "%s:%s:%s", urp, mr, nonce); - 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); - } - - return (0); -} - papi_status_t ipp_status_info(service_t *svc, papi_attribute_t **response) { @@ -480,12 +403,12 @@ fflush(stderr); #endif - result = ipp_send_initial_request_block (svc,request, &ippreq); + result = ipp_send_initial_request_block (request, &ippreq); if(result != PAPI_OK) return (result); - ippres = cupsDoFileRequest(svc->connection,ippreq,NULL,file); + ippresp = cupsDoFileRequest(svc->connection,ippreq,NULL,file); if(ippresp == NULL) return (PAPI_DEVICE_ERROR); Added: branches/GSOC-2008/papi/source/libpapi-cups/job.c =================================================================== --- branches/GSOC-2008/papi/source/libpapi-cups/job.c (rev 0) +++ branches/GSOC-2008/papi/source/libpapi-cups/job.c 2008-08-21 14:50:04 UTC (rev 195) @@ -0,0 +1,612 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + */ + +#pragma ident "$Id$" + +/*LINTLIBRARY*/ + +#include <stdlib.h> +#include <errno.h> +#include <string.h> +#include <papi_impl.h> + +#ifndef OPID_CUPS_MOVE_JOB +#define OPID_CUPS_MOVE_JOB 0x400D +#endif + +void +papiJobFree(papi_job_t job) +{ + job_t *tmp = (job_t *)job; + + if (tmp != NULL) { + if (tmp->attributes != NULL) + papiAttributeListFree(tmp->attributes); + free(tmp); + } +} + +void +papiJobListFree(papi_job_t *jobs) +{ + if (jobs != NULL) { + int i; + + for (i = 0; jobs[i] != NULL; i++) + papiJobFree(jobs[i]); + free(jobs); + } +} + +papi_attribute_t ** +papiJobGetAttributeList(papi_job_t job) +{ + papi_attribute_t **result = NULL; + job_t *j = job; + + if (j != NULL) + result = j->attributes; + + return (result); +} + +char * +papiJobGetPrinterName(papi_job_t job) +{ + char *result = NULL; + job_t *j = job; + + if (j != NULL) + (void) papiAttributeListGetString(j->attributes, NULL, + "printer-name", &result); + + return (result); +} + +int32_t +papiJobGetId(papi_job_t job) +{ + int32_t result = -1; + job_t *j = job; + + if (j != NULL) + (void) papiAttributeListGetInteger(j->attributes, NULL, + "job-id", &result); + + return (result); +} + +papi_job_ticket_t * +papiJobGetJobTicket(papi_job_t job) +{ + papi_job_ticket_t *result = NULL; + + return (result); +} + +static void +populate_job_request(service_t *svc, papi_attribute_t ***request, + papi_attribute_t **attributes, char *printer, uint16_t type) +{ + papi_attribute_t **operational = NULL, **job = NULL; + static char *operational_names[] = { + "job-name", "ipp-attribute-fidelity", "document-name", + "compression", "document-format", "document-natural-language", + "job-k-octets", "job-impressions", "job-media-sheets", NULL + }; + + /* create the base IPP request */ + ipp_initialize_request(svc, request, type); + + /* create an operational attributes group */ + ipp_initialize_operational_attributes(svc, &operational, printer, -1); + + /* split up the attributes into operational and job attributes */ + split_and_copy_attributes(operational_names, attributes, + &operational, &job); + + /* add the operational attributes group to the request */ + papiAttributeListAddCollection(request, PAPI_ATTR_REPLACE, + "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); + papiAttributeListFree(job); + } +} + +static papi_status_t +send_document_uri(service_t *svc, char *file, papi_attribute_t **attributes, + char *printer, int32_t id, char last, uint16_t type) +{ + papi_status_t result = PAPI_INTERNAL_ERROR; + papi_attribute_t **request = NULL, **op = NULL, **response = NULL; + + /* create the base IPP request */ + ipp_initialize_request(svc, &request, type); + + /* create an operational attributes group */ + ipp_initialize_operational_attributes(svc, &op, printer, id); + + papiAttributeListAddString(&op, PAPI_ATTR_REPLACE, "document-name", + file); + papiAttributeListAddBoolean(&op, PAPI_ATTR_REPLACE, "last-document", + (last ? PAPI_TRUE : PAPI_FALSE)); + papiAttributeListAddCollection(&request, PAPI_ATTR_REPLACE, + "operational-attributes-group", op); + papiAttributeListFree(op); + + /* send the IPP request to the server */ + result = ipp_send_request_with_file(svc, request, &response, file); + papiAttributeListFree(request); + papiAttributeListFree(response); + + return (result); +} + +typedef enum {_WITH_DATA, _BY_REFERENCE, _VALIDATE} call_type_t; + +papi_status_t +internal_job_submit(papi_service_t handle, char *printer, + papi_attribute_t **job_attributes, + papi_job_ticket_t *job_ticket, + char **files, papi_job_t *job, + call_type_t call_type) +{ + papi_status_t result = PAPI_INTERNAL_ERROR; + service_t *svc = handle; + job_t *j = NULL; + int i; + uint16_t req_type = IPP_PRINT_JOB; + uint16_t data_type = IPP_SEND_DOCUMENT; + papi_attribute_t **request = NULL, **response = NULL; + + if ((svc == NULL) || (printer == NULL) || (job == NULL)) + return (PAPI_BAD_ARGUMENT); + + switch (call_type) { + case _BY_REFERENCE: +#ifdef SOME_DAY_WE_WILL_BE_ABLE_TO_USE_URIS_FOR_JOB_DATA + /* + * For the time being, this is disabled. There are a number + * of issues to be dealt with before we can send a URI + * across the network to the server. For example, the file + * name(s) passed in are most likely relative to the current + * hosts filesystem. They also most likely will require some + * form of authentication information to be passed with the + * URI. + */ + req_type = OPID_PRINT_URI; + req_type = OPID_SEND_URI; +#endif + /* fall-through */ + case _WITH_DATA: + if ((files == NULL) || (files[0] == NULL)) + return (PAPI_BAD_ARGUMENT); + + if (files[1] != NULL) /* more than 1 file */ + req_type = IPP_CREATE_JOB; + + break; + case _VALIDATE: + req_type = IPP_VALIDATE_JOB; + /* if we have files, validate access to them */ + if (files != NULL) { + for (i = 0; files[i] != NULL; i++) + if (access(files[i], R_OK) < 0) { + detailed_error(svc, "%s: %s", files[i], + strerror(errno)); + return (PAPI_DOCUMENT_ACCESS_ERROR); + } + files = NULL; + } + break; + } + + /* if we are already connected, use that connection. */ + if (svc->connection == NULL) + if ((result = service_connect(svc, printer)) != PAPI_OK) + return (result); + + if ((*job = j = calloc(1, sizeof (*j))) == NULL) + return (PAPI_TEMPORARY_ERROR); + + /* create IPP request */ + populate_job_request(svc, &request, job_attributes, printer, req_type); + + switch (req_type) { + case IPP_PRINT_JOB: + result = ipp_send_request_with_file(svc, request, &response, + files[0]); + break; + case IPP_CREATE_JOB: + case IPP_VALIDATE_JOB: + case IPP_PRINT_URI: + result = ipp_send_request(svc, request, &response); + break; + } + papiAttributeListFree(request); + + if (result == PAPI_OK) { + papi_attribute_t **op = NULL; + + /* retrieve the job attributes */ + papiAttributeListGetCollection(response, NULL, + "job-attributes-group", &op); + copy_attributes(&j->attributes, op); + + if (req_type == IPP_CREATE_JOB) { + int32_t id = 0; + + papiAttributeListGetInteger(j->attributes, NULL, + "job-id", &id); + /* send each document */ + for (i = 0; ((result == PAPI_OK) && (files[i] != NULL)); + i++) + result = send_document_uri(svc, files[i], + job_attributes, + printer, id, (files[i+1]?0:1), + data_type); + } + } + papiAttributeListFree(response); + + return (result); +} + +papi_status_t +papiJobSubmit(papi_service_t handle, char *printer, + papi_attribute_t **job_attributes, + 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)); +} + +papi_status_t +papiJobSubmitByReference(papi_service_t handle, char *printer, + papi_attribute_t **job_attributes, + 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)); +} + +papi_status_t +papiJobValidate(papi_service_t handle, char *printer, + papi_attribute_t **job_attributes, + 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)); +} + +papi_status_t +papiJobStreamOpen(papi_service_t handle, char *printer, + papi_attribute_t **job_attributes, + papi_job_ticket_t *job_ticket, papi_stream_t *stream) +{ + papi_status_t result = PAPI_INTERNAL_ERROR; + papi_attribute_t **request = NULL; + service_t *svc = handle; + + if ((svc == NULL) || (printer == NULL) || (stream == NULL)) + return (PAPI_BAD_ARGUMENT); + + /* if we are already connected, use that connection. */ + if (svc->connection == NULL) + if ((result = service_connect(svc, printer)) != PAPI_OK) + return (result); + + /* create job request */ + populate_job_request(svc, &request, job_attributes, printer, + IPP_PRINT_JOB); + + *stream = svc->connection; + /*TODO adapt ipp_send_initial_request_block ()*/ + result = ipp_send_initial_request_block(request, 0); + papiAttributeListFree(request); + + return (result); +} + +papi_status_t +papiJobStreamWrite(papi_service_t handle, + papi_stream_t stream, void *buffer, size_t buflen) +{ + papi_status_t result = PAPI_OK; + service_t *svc = handle; + size_t rc; + +#ifdef DEBUG + printf("papiJobStreamWrite(0x%8.8x, 0x%8.8x, 0x%8.8x, %d)\n", + handle, stream, buffer, buflen); + httpDumpData(stdout, "papiJobStreamWrite:", buffer, buflen); +#endif + + if ((svc == NULL) || (stream == NULL) || (buffer == NULL) || + (buflen == 0)) + return (PAPI_BAD_ARGUMENT); + + while ((result == PAPI_OK) && (buflen > 0)) { + rc = ipp_request_write(svc, buffer, buflen); + if (rc < 0) + result = PAPI_TEMPORARY_ERROR; + else { + buffer = (char *)buffer + rc; + buflen -= rc; + } + } + +#ifdef DEBUG + printf("papiJobStreamWrite(): %s\n", papiStatusString(result)); +#endif + + return (result); +} + +papi_status_t +papiJobStreamClose(papi_service_t handle, + papi_stream_t stream, papi_job_t *job) +{ + papi_status_t result = PAPI_INTERNAL_ERROR; + http_status_t status = HTTP_CONTINUE; + service_t *svc = handle; + papi_attribute_t **response = NULL; + job_t *j = NULL; + + if ((svc == NULL) || (stream == NULL) || (job == NULL)) + return (PAPI_BAD_ARGUMENT); + + if ((*job = j = calloc(1, sizeof (*j))) == NULL) + return (PAPI_TEMPORARY_ERROR); + + (void) ipp_request_write(svc, "", 0); + + /* update our connection info */ + while (status == HTTP_CONTINUE) + status = httpUpdate(svc->connection); + + if (status != HTTP_OK) + return (http_to_papi_status(status)); + httpWait(svc->connection, 1000); + + /* TODO adapt read the IPP response */ + //result = ipp_read_message(&ipp_request_read, svc, &response); + if (result == PAPI_OK) + result = ipp_status_info(svc, response); + + if (result == PAPI_OK) { + papi_attribute_t **op = NULL; + + papiAttributeListGetCollection(response, NULL, + "job-attributes-group", &op); + copy_attributes(&j->attributes, op); + } + papiAttributeListFree(response); + + return (result); +} + +papi_status_t +papiJobQuery(papi_service_t handle, char *printer, int32_t job_id, + char **requested_attrs, + papi_job_t *job) +{ + papi_status_t result = PAPI_INTERNAL_ERROR; + service_t *svc = handle; + job_t *j = NULL; + papi_attribute_t **request = NULL, **op = NULL, **response = NULL; + + if ((svc == NULL) || (printer == NULL)) + return (PAPI_BAD_ARGUMENT); + + /* if we are already connected, use that connection. */ + if (svc->connection == NULL) + if ((result = service_connect(svc, printer)) != PAPI_OK) + return (result); + + if ((*job = j = calloc(1, sizeof (*j))) == NULL) + return (PAPI_TEMPORARY_ERROR); + + ipp_initialize_request(svc, &request, IPP_GET_JOB_ATTRIBUTES); + + ipp_initialize_operational_attributes(svc, &op, printer, job_id); + + if (requested_attrs != NULL) { + int i; + + for (i = 0; requested_attrs[i] != NULL; i++) + papiAttributeListAddString(&op, PAPI_ATTR_APPEND, + "requested-attributes", requested_attrs[i]); + } + + papiAttributeListAddCollection(&request, PAPI_ATTR_REPLACE, + "operational-attributes-group", op); + papiAttributeListFree(op); + result = ipp_send_request(svc, request, &response); + papiAttributeListFree(request); + + op = NULL; + papiAttributeListGetCollection(response, NULL, + "job-attributes-group", &op); + copy_attributes(&j->attributes, op); + papiAttributeListFree(response); + + return (result); +} + +/* papiJob{Cancel|Hold|Release|Restart|Promote} are all the same */ +static papi_status_t +_job_cancel_hold_release_restart_promote(papi_service_t handle, + char *printer, int32_t job_id, uint16_t type) +{ + papi_status_t result = PAPI_INTERNAL_ERROR; + service_t *svc = handle; + papi_attribute_t **request = NULL, **op = NULL, **response = NULL; + + if ((svc == NULL) || (printer == NULL) || (job_id < 0)) + return (PAPI_BAD_ARGUMENT); + + /* if we are already connected, use that connection. */ + if (svc->connection == NULL) + if ((result = service_connect(svc, printer)) != PAPI_OK) + return (result); + + ipp_initialize_request(svc, &request, type); + + ipp_initialize_operational_attributes(svc, &op, printer, job_id); + + papiAttributeListAddCollection(&request, PAPI_ATTR_REPLACE, + "operational-attributes-group", op); + papiAttributeListFree(op); + result = ipp_send_request(svc, request, &response); + papiAttributeListFree(request); + papiAttributeListFree(response); + + return (result); +} + +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, IPP_CANCEL_JOB)); +} + + +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, IPP_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, IPP_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, IPP_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, IPP_PROMOTE_JOB)); +} + +papi_status_t +papiJobMove(papi_service_t handle, char *printer, int32_t job_id, + char *destination) +{ + papi_status_t result = PAPI_INTERNAL_ERROR; + service_t *svc = handle; + papi_attribute_t **request = NULL, **op = NULL, **response = NULL; + + if ((svc == NULL) || (printer == NULL) || (job_id < 0) || + (destination == NULL)) + return (PAPI_BAD_ARGUMENT); + + /* if we are already connected, use that connection. */ + if (svc->connection == NULL) + if ((result = service_connect(svc, printer)) != PAPI_OK) + return (result); + + ipp_initialize_request(svc, &request, CUPS_MOVE_JOB); + + ipp_initialize_operational_attributes(svc, &op, printer, job_id); + + papiAttributeListAddCollection(&request, PAPI_ATTR_REPLACE, + "operational-attributes-group", op); + papiAttributeListFree(op); + + op = NULL; + papiAttributeListAddString(&op, PAPI_ATTR_EXCL, + "job-printer-uri", destination); + papiAttributeListAddCollection(&request, PAPI_ATTR_REPLACE, + "job-attributes-group", op); + papiAttributeListFree(op); + + result = ipp_send_request(svc, request, &response); + papiAttributeListFree(request); + papiAttributeListFree(response); + + return (result); +} + +papi_status_t +papiJobModify(papi_service_t handle, char *printer, int32_t job_id, + papi_attribute_t **attributes, papi_job_t *job) +{ + papi_status_t result = PAPI_INTERNAL_ERROR; + service_t *svc = handle; + papi_attribute_t **request = NULL, **op = NULL, **response = NULL; + job_t *j = NULL; + + if ((svc == NULL) || (printer == NULL) || (job_id < 0) || + (attributes == NULL)) + return (PAPI_BAD_ARGUMENT); + + if ((*job = j = calloc(1, sizeof (*j))) == NULL) + return (PAPI_TEMPORARY_ERROR); + + /* if we are already connected, use that connection. */ + if (svc->connection == NULL) + if ((result = service_connect(svc, printer)) != PAPI_OK) + return (result); + + ipp_initialize_request(svc, &request, IPP_SET_JOB_ATTRIBUTES); + + ipp_initialize_operational_attributes(svc, &op, printer, job_id); + + papiAttributeListAddCollection(&request, PAPI_ATTR_REPLACE, + "operational-attributes-group", op); + papiAttributeListFree(op); + papiAttributeListAddCollection(&request, PAPI_ATTR_REPLACE, + "job-attributes-group", attributes); + result = ipp_send_request(svc, request, &response); + papiAttributeListFree(request); + + op = NULL; + papiAttributeListGetCollection(response, NULL, + "job-attributes-group", &op); + copy_attributes(&j->attributes, op); + papiAttributeListFree(response); + + return (result); +} Property changes on: branches/GSOC-2008/papi/source/libpapi-cups/job.c ___________________________________________________________________ Added: svn:keywords + Id Modified: branches/GSOC-2008/papi/source/libpapi-cups/papi_impl.h =================================================================== --- branches/GSOC-2008/papi/source/libpapi-cups/papi_impl.h 2008-08-13 15:18:11 UTC (rev 194) +++ branches/GSOC-2008/papi/source/libpapi-cups/papi_impl.h 2008-08-21 14:50:04 UTC (rev 195) @@ -86,8 +86,7 @@ extern papi_status_t ipp_send_request_with_file(service_t *svc, papi_attribute_t **request, papi_attribute_t ***response, char *file); -extern papi_status_t ipp_send_initial_request_block(service_t *svc, - papi_attribute_t **request, ssize_t file_size); +extern papi_status_t ipp_send_initial_request_block(papi_attribute_t **request, ipp_t **ippreq); extern papi_status_t ipp_status_info(service_t *svc, papi_attribute_t **response); extern void ipp_initialize_request(service_t *svc, Modified: branches/GSOC-2008/papi/source/libpapi-cups/printer.c =================================================================== --- branches/GSOC-2008/papi/source/libpapi-cups/printer.c 2008-08-13 15:18:11 UTC (rev 194) +++ branches/GSOC-2008/papi/source/libpapi-cups/printer.c 2008-08-21 14:50:04 UTC (rev 195) @@ -152,7 +152,7 @@ if ((*printer = p = calloc(1, sizeof (*p))) == NULL) return (PAPI_TEMPORARY_ERROR); - ipp_initialize_request(svc, &request, OPID_GET_PRINTER_ATTRIBUTES); + ipp_initialize_request(svc, &request, IPP_GET_PRINTER_ATTRIBUTES ); ipp_initialize_operational_attributes(svc, &op, name, -1); @@ -200,11 +200,11 @@ ipp_initialize_operational_attributes(svc, &op, name, -1); switch (type) { - case OPID_DISABLE_PRINTER: + case IPP_DISABLE_PRINTER: papiAttributeListAddString(&op, PAPI_ATTR_REPLACE, "printer-message-from-operator", message); break; - case OPID_PAUSE_PRINTER: + case IPP_PAUSE_PRINTER: papiAttributeListAddString(&op, PAPI_ATTR_REPLACE, "printer-state-message", message); break; @@ -226,28 +226,28 @@ papiPrinterEnable(papi_service_t handle, char *name) { return (_printer_enable_disable_pause_resume_delete(handle, name, - NULL, OPID_ENABLE_PRINTER)); + NULL, IPP_ENABLE_PRINTER)); } papi_status_t papiPrinterResume(papi_service_t handle, char *name) { return (_printer_enable_disable_pause_resume_delete(handle, name, - NULL, OPID_RESUME_PRINTER)); + NULL, IPP_RESUME_PRINTER)); } papi_status_t papiPrinterPause(papi_service_t handle, char *name, char *message) { return (_printer_enable_disable_pause_resume_delete(handle, name, - message, OPID_PAUSE_PRINTER)); + message, IPP_PAUSE_PRINTER)); } papi_status_t papiPrinterDisable(papi_service_t handle, char *name, char *message) { return (_printer_enable_disable_pause_resume_delete(handle, name, - message, OPID_PAUSE_PRINTER)); + message, IPP_PAUSE_PRINTER)); } /* @@ -282,7 +282,7 @@ if ((*printer = p = calloc(1, sizeof (*p))) == NULL) return (PAPI_TEMPORARY_ERROR); - ipp_initialize_request(svc, &request, OPID_SET_PRINTER_ATTRIBUTES); + ipp_initialize_request(svc, &request, IPP_SET_PRINTER_ATTRIBUTES); ipp_initialize_operational_attributes(svc, &op, name, -1); @@ -329,7 +329,7 @@ if ((result = service_connect(svc, name)) != PAPI_OK) return (result); - ipp_initialize_request(svc, &request, OPID_PURGE_JOBS); + ipp_initialize_request(svc, &request, IPP_PURGE_JOBS); ipp_initialize_operational_attributes(svc, &op, name, -1); @@ -377,7 +377,7 @@ if ((result = service_connect(svc, name)) != PAPI_OK) return (result); - ipp_initialize_request(svc, &request, OPID_GET_JOBS); + ipp_initialize_request(svc, &request, IPP_GET_JOBS); ipp_initialize_operational_attributes(svc, &op, name, -1); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2008-08-13 16:24:27
|
Revision: 194 http://openprinting.svn.sourceforge.net/openprinting/?rev=194&view=rev Author: allad Date: 2008-08-13 15:18:11 +0000 (Wed, 13 Aug 2008) Log Message: ----------- Started Implementation of ipp_read_message() function. Modified Paths: -------------- branches/GSOC-2008/papi/source/libpapi-cups/Makefile.am branches/GSOC-2008/papi/source/libpapi-cups/cups-ipp.c branches/GSOC-2008/papi/source/libpapi-cups/ipp-support.c Added Paths: ----------- branches/GSOC-2008/papi/source/libpapi-cups/strings.c Modified: branches/GSOC-2008/papi/source/libpapi-cups/Makefile.am =================================================================== --- branches/GSOC-2008/papi/source/libpapi-cups/Makefile.am 2008-08-12 15:56:12 UTC (rev 193) +++ branches/GSOC-2008/papi/source/libpapi-cups/Makefile.am 2008-08-13 15:18:11 UTC (rev 194) @@ -47,7 +47,7 @@ papi_cupsincludedir = $(includedir) -# PAPI support layered on IPP -papi_cups_la_SOURCES = service.c cups-ipp.c +# PAPI support layered on CUPS +papi_cups_la_SOURCES = service.c cups-ipp.c strings.c EXTRA_DIST = papi_impl.h mapfile.in Modified: branches/GSOC-2008/papi/source/libpapi-cups/cups-ipp.c =================================================================== --- branches/GSOC-2008/papi/source/libpapi-cups/cups-ipp.c 2008-08-12 15:56:12 UTC (rev 193) +++ branches/GSOC-2008/papi/source/libpapi-cups/cups-ipp.c 2008-08-13 15:18:11 UTC (rev 194) @@ -310,3 +310,57 @@ return (result); } + + +papi_status_t +ipp_read_message (ipp_t *ippresp,papi_attribute_t ***message) +{ + papi_attribute_t **attributes = NULL; + ipp_tag_t group; + int i; + ipp_attribute_t *attr; + + for(attr = ippresp->attrs;attr;attr = attr->next){ + if(!group){ + /*first attribute */ + group = attr->group_tag; + } + else if(attr->group_tag != group){ + /* new group starting + save last built group */ + if (attributes != NULL) { + char name[32]; + + (void) ipp_tag_string(group, name, sizeof (name)); + papiAttributeListAddCollection(message, PAPI_ATTR_APPEND, name, + attributes); + } + /*reset attributes list for next group */ + attributes = NULL; + group = attr->group_tag; + } + + switch(attr->value_tag){ + case IPP_TAG_INTEGER: + for(i = 0; i<attr->num_values;i++) + papiAttributeListAddInteger(&attributes, + PAPI_ATTR_APPEND, attr->name, attr->values[i].integer); + break; + case IPP_TAG_BOOLEAN: + break; + case IPP_TAG_DATE: + break; + + } + } + + /*last attributes */ + if (attributes != NULL) { + char name[32]; + + (void) ipp_tag_string(group, name, sizeof (name)); + papiAttributeListAddCollection(message, PAPI_ATTR_APPEND, name, + attributes); + } +} + Modified: branches/GSOC-2008/papi/source/libpapi-cups/ipp-support.c =================================================================== --- branches/GSOC-2008/papi/source/libpapi-cups/ipp-support.c 2008-08-12 15:56:12 UTC (rev 193) +++ branches/GSOC-2008/papi/source/libpapi-cups/ipp-support.c 2008-08-13 15:18:11 UTC (rev 194) @@ -38,7 +38,9 @@ #include <config-site.h> +#include <cups/cups.h> + static void ipp_add_printer_uri(service_t *svc, char *name, papi_attribute_t ***op); @@ -346,70 +348,21 @@ } papi_status_t -ipp_send_initial_request_block(service_t *svc, papi_attribute_t **request, - ssize_t file_size) +ipp_send_initial_request_block(service_t *svc, papi_attribute_t **request, ipp_t **ippreq) { papi_status_t result = PAPI_OK; - ssize_t chunk_size = 0; - char length[32]; - void *chunk, *ptr; + http_status_t status; + - /* calculate the request size */ - (void) ipp_write_message(&size_calculate, &chunk_size, request); - /* Fill in the HTTP Header information */ - httpClearFields(svc->connection); - if (svc->transfer_encoding == TRANSFER_ENCODING_CHUNKED) - httpSetField(svc->connection, HTTP_FIELD_TRANSFER_ENCODING, - "chunked"); - else { - sprintf(length, "%lu", (unsigned long)(file_size + chunk_size)); - httpSetField(svc->connection, HTTP_FIELD_CONTENT_LENGTH, - length); - } - httpSetField(svc->connection, HTTP_FIELD_CONTENT_TYPE, - "application/ipp"); - httpSetField(svc->connection, HTTP_FIELD_AUTHORIZATION, - svc->connection->authstring); - - /* flush any state information about this connection */ - httpFlush(svc->connection); - - /* if we have don't have a POST path, use the service uri path */ - if (svc->post == NULL) - svc->post = strdup(svc->uri->path); - /* send the HTTP POST message for the IPP request */ - /* if the POST fails, return the error */ - status = httpPost(svc->connection, svc->post); - if (status != 0) - return (http_to_papi_status(status)); - - if (httpCheck(svc->connection) != 0) { - status = httpUpdate(svc->connection); - if (status != HTTP_OK) - return (http_to_papi_status(status)); - } - /* build the request chunk */ - chunk = ptr = calloc(1, chunk_size); - result = ipp_write_message(&build_chunk, &ptr, request); + + result = ipp_write_message(ippreq,request); #ifdef DEBUG - printf("request: %d (0x%x) bytes\n", chunk_size, chunk_size); - httpDumpData(stdout, "request:", chunk, chunk_size); + /*TODO DEBUG OUTPUT*/ #endif - /* send the actual IPP request */ - if (ipp_request_write(svc, chunk, chunk_size) != chunk_size) - result = PAPI_TEMPORARY_ERROR; - free(chunk); - - if (httpCheck(svc->connection) != 0) { - status = httpUpdate(svc->connection); - if (status != HTTP_OK) - return (http_to_papi_status(status)); - } - return (result); } @@ -516,6 +469,9 @@ papi_status_t result = PAPI_OK; ssize_t size = 0; int fd; + ipp_t *ippreq; + ipp_t *ippresp; + #ifdef DEBUG fprintf(stderr, "\nIPP-REQUEST: (%s)", (file ? file : "")); @@ -524,78 +480,21 @@ fflush(stderr); #endif - /* - * if we are sending a file, open it and include it's size in the - * message size. - */ - if (file != NULL) { - if ((fd = open(file, O_RDONLY)) < 0) { - detailed_error(svc, "%s: %s", file, strerror(errno)); - return (PAPI_DOCUMENT_ACCESS_ERROR); - } else if (svc->transfer_encoding != - TRANSFER_ENCODING_CHUNKED) { - struct stat st; + result = ipp_send_initial_request_block (svc,request, &ippreq); + if(result != PAPI_OK) + return (result); + + + ippres = cupsDoFileRequest(svc->connection,ippreq,NULL,file); + + if(ippresp == NULL) + return (PAPI_DEVICE_ERROR); + + /* read the IPP response */ + result = ipp_read_message(&ippresp, response); - if (fstat(fd, &st) >= 0) - size = st.st_size; - } - } - - *response = NULL; - while (*response == NULL) { - http_status_t status = HTTP_CONTINUE; - - result = ipp_send_initial_request_block(svc, request, size); - - if (result == PAPI_OK) { - if (file != NULL) { - /* send the file contents if we have it */ - int rc; - char buf[BUFSIZ]; - - lseek(fd, 0L, SEEK_SET); - while ((rc = read(fd, buf, sizeof (buf))) > 0) { - if (ipp_request_write(svc, buf, rc) - < rc) { - break; - } - } - } - - (void) ipp_request_write(svc, "", 0); - } - - /* update our connection info */ - while (status == HTTP_CONTINUE) - status = httpUpdate(svc->connection); - - if (status == HTTP_UNAUTHORIZED) { - httpFlush(svc->connection); - if ((svc->connection->authstring[0] == '\0') && - (setAuthString(svc) == 0)) { - httpReconnect(svc->connection); - continue; - } - } else if (status == HTTP_UPGRADE_REQUIRED) { - /* - * If the transport was built with TLS support, we can - * try to use it. - */ - httpFlush(svc->connection); - httpReconnect(svc->connection); - httpEncryption(svc->connection, HTTP_ENCRYPT_REQUIRED); - continue; - } - - if (status != HTTP_OK) - return (http_to_papi_status(status)); - - /* read the IPP response */ - result = ipp_read_message(&ipp_request_read, svc, response, - IPP_TYPE_RESPONSE); - - if (result == PAPI_OK) - result = ipp_status_info(svc, *response); + if (result == PAPI_OK) + result = ipp_status_info(svc, *response); #ifdef DEBUG fprintf(stderr, "\nIPP-RESPONSE: (%s) (%s)", (file ? file : ""), papiStatusString(result)); @@ -603,8 +502,8 @@ putc('\n', stderr); fflush(stderr); #endif - } + return (result); } Added: branches/GSOC-2008/papi/source/libpapi-cups/strings.c =================================================================== --- branches/GSOC-2008/papi/source/libpapi-cups/strings.c (rev 0) +++ branches/GSOC-2008/papi/source/libpapi-cups/strings.c 2008-08-13 15:18:11 UTC (rev 194) @@ -0,0 +1,360 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + */ + +#pragma ident "$Id$" + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <papi.h> +#include <cups/cups.h> + +#define VTAG_MAX 0x5f +#define VTAG_EXTEND 0x7f + +static char *tag_strings[] = { + /* delimiter tags */ + "reserved-delimiter-00", + "operational-attributes-group", + "job-attributes-group", + "end-of-attributes-group", + "printer-attributes-group", + "unsupported-attributes-group", + "subscription-attributes-group", + "event-notification-attributes-group", + "reserved-delimiter-08", + "reserved-delimiter-09", + "reserved-delimiter-0a", + "reserved-delimiter-0b", + "reserved-delimiter-0c", + "reserved-delimiter-0d", + "reserved-delimiter-0e", + "reserved-delimiter-0f", + /* value tags */ + "unsupported", + "reserved-default", + "unknown", + "no-value", + "reserved-out-of-band-14", + "not-settable", + "delete-attribute", + "admin-define", + "reserved-out-of-band-18", + "reserved-out-of-band-19", + "reserved-out-of-band-1a", + "reserved-out-of-band-1b", + "reserved-out-of-band-1c", + "reserved-out-of-band-1d", + "reserved-out-of-band-1e", + "reserved-out-of-band-1f", + "reserved", + "integer", + "boolean", + "enum", + "reserved-integer-type-24", + "reserved-integer-type-25", + "reserved-integer-type-26", + "reserved-integer-type-27", + "reserved-integer-type-28", + "reserved-integer-type-29", + "reserved-integer-type-2a", + "reserved-integer-type-2b", + "reserved-integer-type-2c", + "reserved-integer-type-2d", + "reserved-integer-type-2e", + "reserved-integer-type-2f", + "octetString", + "dateTime", + "resolution", + "rangeOfInteger", + "begCollection", + "textWithLanguage", + "nameWithLanguage", + "endCollection", + "reserved-octetString-38", + "reserved-octetString-39", + "reserved-octetString-3a", + "reserved-octetString-3b", + "reserved-octetString-3c", + "reserved-octetString-3d", + "reserved-octetString-3e", + "reserved-octetString-3f", + "reserved", + "textWithoutLanguage", + "nameWithoutLanguage", + "reserved", + "keyword", + "uri", + "uriScheme", + "charset", + "naturalLanguage", + "mimeMediaType", + "memberAttrName", + "reserved-charString-4b", + "reserved-charString-4c", + "reserved-charString-4d", + "reserved-charString-4e", + "reserved-charString-4f", + "reserved-charString-50", + "reserved-charString-51", + "reserved-charString-52", + "reserved-charString-53", + "reserved-charString-54", + "reserved-charString-55", + "reserved-charString-56", + "reserved-charString-57", + "reserved-charString-58", + "reserved-charString-59", + "reserved-charString-5a", + "reserved-charString-5b", + "reserved-charString-5c", + "reserved-charString-5d", + "reserved-charString-5e", + "reserved-charString-5f", +}; + +static char *opid_strings[] = { + "reserved-0x0000", + "reserved-0x0001", + "Print-Job", + "Print-URI", + "Validate-Job", + "Create-Job", + "Send-Document", + "Send-URI", + "Cancel-Job", + "Get-Job-Attributes", + "Get-Jobs", + "Get-Printer-Attributes", + "Hold-Job", + "Release-Job", + "Restart-Job", + "reserved-0x000f", + "Pause-Printer", + "Resume-Printer", + "Purge-Jobs", + "Set-Printer-Attributes", + "Set-Job-Attributes", + "Get-Printer-Supported-Values", + "Create-Printer-Subscription", + "Create-Job-Subscription", + "Get-Subscription-Attributes", + "Get-Subscriptions", + "Renew-Subscription", + "Cancel-Subscription", + "Get-Notifications", + "Send-Notifications", + "Get-Resource-Attributes-deleted", + "Get-Resource-Data-deleted", + "Get-Resources-deleted", + "Get-Print-Support-Files", + "Disable-Printer", + "Pause-Printer-After-Current-Job", + "Hold-New-Jobs", + "Release-Held-New-Jobs", + "Deactivate-Printer", + "Activate-Printer", + "Restart-Printer", + "Shutdown-Printer", + "Startup-Printer", + "Reprocess-Job", + "Cancel-Current-Job", + "Suspend-Current-Job", + "Resume-Job", + "Promote-Job", + "Schedule-Job-After", + NULL +}; + +static char *res_opid_strings[] = { + "Microsoft-0x4000", + "CUPS-Get-Default", + "CUPS-Get-Printers", + "CUPS-Add-Printer", + "CUPS-Delete-Printer", + "CUPS-Get-Classes", + "CUPS-Add-Class", + "CUPS-Delete-Class", + "CUPS-Accept-Jobs", + "CUPS-Reject-Jobs", + "CUPS-Set-Default", + "CUPS-Get-Devices", + "CUPS-Get-PPDs", + "CUPS-Move-Job", + "CUPS-0x400e", + "CUPS-0x400f", + "Peerless-0x4010", + NULL +}; +#define KNOWN_RESERVED_MIN 0x4000 +#define KNOWN_RESERVED_MAX 0x4010 + +static char *ok_status_strings[] = { + "successful-ok", + "successful-ok-ignored-or-substituted-attributes", + "successful-ok-conflicting-attributes", + "successful-ok-ignored-subscriptions", + "successful-ok-ignored-notifications", + "successful-ok-too-many-events", + "successful-ok-but-cancel-subscription" +}; + +static char *redir_status_strings[] = { + "redirection-other-site" +}; + +static char *client_error_status_strings[] = { + "client-error-bad-request", + "client-error-forbidden", + "client-error-not-authenticated", + "client-error-not-authorized", + "client-error-not-possible", + "client-error-timeout", + "client-error-not-found", + "client-error-gone", + "client-error-request-entity-too-large", + "client-error-request-value-too-long", + "client-error-document-format-not-supported", + "client-error-attributes-or-values-not-supported", + "client-error-uri-scheme-not-supported", + "client-error-charset-not-supported", + "client-error-conflicting-attributes", + "client-error-compression-not-supported", + "client-error-compression-error", + "client-error-document-format-error", + "client-error-document-access-error", + "client-error-attributes-not-settable", + "client-error-ignored-all-subscriptions", + "client-error-too-many-subscriptions", + "client-error-ignored-all-notifications", + "client-error-print-support-file-not-found" +}; + +static char *server_error_status_strings[] = { + "server-error-internal-error", + "server-error-operation-not-supported", + "server-error-service-unavailable", + "server-error-version-not-supported", + "server-error-device-error", + "server-error-temporary-error", + "server-error-not-accepting-jobs", + "server-error-busy", + "server-error-job-canceled", + "server-error-multiple-document-jobs-not-supported", + "server-error-printer-is-deactivated" +}; + +char * +ipp_tag_string(int8_t id, char *ret, size_t len) +{ + if (id < VTAG_MAX) + (void) strlcpy(ret, tag_strings[id], len); + else if (id == VTAG_EXTEND) + (void) strlcpy(ret, "extension", len); + else + (void) snprintf(ret, len, "bogus-0x%.2x", id); + + return (ret); +} + + +/* + * attribute template handling routines + */ +char *job_template[] = { + "copies", + "finishing", + "job-hold-until", + "job-priority", + "job-sheets", + "media", + "multiple-document-handling", + "number-up", + "page-ranges-supported", + "print-quality", + "printer-resoultion", + "sides", + NULL +}; + +char *job_description[] = { + "copies-default", "copies-supported", + "finishing-default", "finishing-supported", + "job-hold-until-default", "job-hold-until-supported", + "job-priority-default", "job-priority-supported", + "job-sheets-default", "job-sheets-supported", + "media-default", "media-supported", + "multiple-document-handling-default", + "multiple-document-handling-supported", + "number-up-default", "number-up-supported", + "page-ranges-supported", + "print-quality-default", "print-quality-supported", + "printer-resoultion-default", "printer-resoultion-supported", + "sides-default", "sides-supported", + NULL +}; + +char *printer_description[] = { + "printer-uri-supported", + "uri-security-supported", + "uri-authentication-supported", + "printer-name", + "printer-location", + "printer-info", + "printer-more-info", + "printer-driver-installer", + "printer-make-and-model", + "printer-more-info-manufacturer", + "printer-state", + "printer-state-reasons", + "printer-state-message", + "ipp-versions-supported", + "multiple-document-jobs-supported", + "charset-configured", + "charset-supported", + "natural-language-configured", + "generated-natural-language-supported", + "document-format-default", + "document-format-supported", + "printer-is-accepting-jobs", + "queued-job-count", + "printer-message-from-operator", + "color-supported", + "reference-uri-schemes-supported", + "pdl-override-supported", + "printer-up-time", + "printer-current-time", + "multiple-operation-time-out", + "compression-supported", + "job-k-octets-supported", + "job-impressions-supported", + "job-media-sheets-supported", + "pages-per-minute", + "pages-per-minute-color", + NULL +}; Property changes on: branches/GSOC-2008/papi/source/libpapi-cups/strings.c ___________________________________________________________________ Added: svn:keywords + Id This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2008-08-12 15:56:03
|
Revision: 193 http://openprinting.svn.sourceforge.net/openprinting/?rev=193&view=rev Author: allad Date: 2008-08-12 15:56:12 +0000 (Tue, 12 Aug 2008) Log Message: ----------- CUPS IPP layer implementation ippWriteMessage() substitute implemented in cups-ipp.c Modified Paths: -------------- branches/GSOC-2008/papi/source/libpapi-cups/Makefile.am branches/GSOC-2008/papi/source/libpapi-cups/cups-ipp.c Modified: branches/GSOC-2008/papi/source/libpapi-cups/Makefile.am =================================================================== --- branches/GSOC-2008/papi/source/libpapi-cups/Makefile.am 2008-08-06 13:22:07 UTC (rev 192) +++ branches/GSOC-2008/papi/source/libpapi-cups/Makefile.am 2008-08-12 15:56:12 UTC (rev 193) @@ -31,7 +31,7 @@ # this gets installed in libexecdir libdir = $(libexecdir) -AM_CPPFLAGS = -I../libpapi-common -I../libhttp-core -I../libipp-core -I. +AM_CPPFLAGS = -I../libpapi-common -I. lib_LTLIBRARIES = papi-cups.la @@ -48,6 +48,6 @@ papi_cupsincludedir = $(includedir) # PAPI support layered on IPP -papi_cups_la_SOURCES = service.c +papi_cups_la_SOURCES = service.c cups-ipp.c EXTRA_DIST = papi_impl.h mapfile.in Modified: branches/GSOC-2008/papi/source/libpapi-cups/cups-ipp.c =================================================================== --- branches/GSOC-2008/papi/source/libpapi-cups/cups-ipp.c 2008-08-06 13:22:07 UTC (rev 192) +++ branches/GSOC-2008/papi/source/libpapi-cups/cups-ipp.c 2008-08-12 15:56:12 UTC (rev 193) @@ -37,42 +37,227 @@ #include <papi.h> #include <cups/cups.h> -papi_status_t -ipp_write_message(ipp_t **ipp, papi_attribute_t **message) + +#define DTAG_MIN 0x00 +#define DTAG_MAX 0x0f + +static int8_t +papi_attribute_to_ipp_type(papi_attribute_value_type_t type) { - papi_status_t result; - ipp_t * request = *ipp; - int tmp; + switch (type) { + case PAPI_INTEGER: + return (IPP_TAG_INTEGER); + case PAPI_BOOLEAN: + return (IPP_TAG_BOOLEAN); + case PAPI_RANGE: + return (IPP_TAG_RANGE); + case PAPI_RESOLUTION: + return (IPP_TAG_RESOLUTION); + case PAPI_DATETIME: + return (IPP_TAG_DATE); + case PAPI_STRING: + return (IPP_TAG_TEXT); + } - if (message == NULL)) - return (PAPI_BAD_ARGUMENT); + return (0); +} + +static papi_status_t +papi_ipp_type_match(papi_attribute_value_type_t papi, int8_t ipp) +{ + switch (papi) { + case PAPI_STRING: + switch (ipp) { + case IPP_TAG_URI: + case IPP_TAG_STRING: + case IPP_TAG_TEXT: + case IPP_TAG_URISCHEME: + case IPP_TAG_CHARSET: + case IPP_TAG_LANGUAGE: + case IPP_TAG_MIMETYPE: + case IPP_TAG_NAME: + case IPP_TAG_KEYWORD: + break; + default: + return (PAPI_CONFLICT); + } + break; + case PAPI_INTEGER: + switch (ipp) { + case IPP_TAG_ENUM: + case IPP_TAG_INTEGER: + break; + default: + return (PAPI_CONFLICT); + } + break; + case PAPI_BOOLEAN: + if (ipp != IPP_TAG_BOOLEAN) + return (PAPI_CONFLICT); + break; + case PAPI_RANGE: + if (ipp != IPP_TAG_RANGE) + return (PAPI_CONFLICT); + break; + case PAPI_RESOLUTION: + if (ipp != IPP_TAG_RESOLUTION) + return (PAPI_CONFLICT); + break; + case PAPI_DATETIME: + if (ipp != IPP_TAG_DATE) + return (PAPI_CONFLICT); + break; + case PAPI_COLLECTION: + /* don't need to match */ + break; + } + + return (PAPI_OK); +} + +static ipp_res_t +papi_res_to_ipp_res(papi_resolution_unit_t unit) +{ + switch(unit){ + case PAPI_RES_PER_CM: + return IPP_RES_PER_CM; + case PAPI_RES_PER_INCH: + return IPP_RES_PER_INCH; + } +} + +static papi_status_t +ipp_write_attribute(ipp_t *ipp, int8_t group, papi_attribute_t *attribute) +{ + papi_status_t status; + papi_attribute_value_t **values; + int8_t type; + int i; + char *name; + + name = attribute->name; + values = attribute->values; + + if ((type = name_to_ipp_type(name)) == 0) + type = papi_attribute_to_ipp_type(attribute->type); + + /* The types don't match, so don't send the attribute */ + if ((status = papi_ipp_type_match(attribute->type, type)) != PAPI_OK) + return (status); + + if (values == NULL) { + uint16_t length; + + type = IPP_TAG_UNSUPPORTED_VALUE; + + /*TODO deal with unsupported values*/ + + return (PAPI_OK); + } + + + int nb_values = 0; + for(i = 0; values[i] != NULL; i++) + nb_values++; - /* get the request/status code */ - papiAttributeListGetInteger(message, NULL, "status-code", &tmp); - papiAttributeListGetInteger(message, NULL, "operation-id", &tmp); - - request = ippNewRequest((ipp_op_t)tmp); - - if (request != NULL) - result = ipp_write_attribute_groups(request, message); + switch (attribute->type) { + case PAPI_STRING: { + char **strs = (char**)malloc(nb_values*sizeof(char *)); + + for (i = 0; values[i] != NULL; i++) { + papi_attribute_value_t *value = values[i]; + + char *v = (char *)value->string; + strs[i] = strdup(v); + } + + ippAddStrings(ipp,group,type,name,nb_values,NULL,(char *const *)strs);/*TODO check type*/ + } + break; + case PAPI_BOOLEAN: { + char *bools = (char*) malloc(nb_values*sizeof(char)); - return (result); + for (i = 0; values[i] != NULL; i++) { + papi_attribute_value_t *value = values[i]; + + char b = (char)value->boolean; + bools[i] = b; + } + + ippAddBooleans(ipp,group,name,nb_values,bools); + } + break; + case PAPI_INTEGER: { + int *ints = (int*) malloc(nb_values*sizeof(int)); + + for (i = 0; values[i] != NULL; i++) { + papi_attribute_value_t *value = values[i]; + + int i = (int)value->integer; + ints[i] = i; + } + + ippAddIntegers(ipp,group,type,name,nb_values,ints);/*TODO check type*/ + } + break; + case PAPI_RANGE: { + int *min = (int *)malloc(nb_values*sizeof(int)); + int *max = (int *)malloc(nb_values*sizeof(int)); + + for (i = 0; values[i] != NULL; i++) { + papi_attribute_value_t *value = values[i]; + + int min1 = (int)value->range.lower; + min[i] = min1; + int max1 = (int)value->range.upper; + max[i] = max1; + + } + + ippAddRanges(ipp,group,name,nb_values,min,max); + } + break; + case PAPI_RESOLUTION: { + for (i = 0; values[i] != NULL; i++) { + papi_attribute_value_t *value = values[i]; + + int x = (int)value->resolution.xres; + int y = (int)value->resolution.yres; + ipp_res_t units = papi_res_to_ipp_res(value->resolution.units); + + ippAddResolution(ipp,group,name,units,x,y); + } + } + break; + case PAPI_DATETIME: { + + for (i = 0; values[i] != NULL; i++) { + papi_attribute_value_t *value = values[i]; + + /*get a string representation from the datetime int value */ + char *date = strdup(asctime(gmtime(&value->datetime))); + + ippAddDate(ipp,group,name,date); + } + } + break; + default: + return (PAPI_DEVICE_ERROR); + } + + return (PAPI_OK); } static papi_status_t -ipp_write_attribute_group(ipp_writer_t iwrite, void *fd, int8_t type, +ipp_write_attribute_group(ipp_t *ipp, int8_t type, papi_attribute_t **attributes) { papi_status_t result = PAPI_OK; int i; - /* write group tag */ - if (iwrite(fd, &type, 1) != 1) - return (PAPI_DEVICE_ERROR); - /* write values */ for (i = 0; ((attributes[i] != NULL) && (result == PAPI_OK)); i++) - result = ipp_write_attribute(iwrite, fd, attributes[i]); + result = ipp_write_attribute(ipp,type, attributes[i]); return (result); } @@ -96,13 +281,32 @@ ((status == PAPI_OK) && (result == PAPI_OK)); status = papiAttributeListGetCollection(groups, &iter, NULL, &group)) - result = ipp_write_attribute_group(iwrite, fd, + result = ipp_write_attribute_group(ipp, c, group); } - c = DTAG_END_OF_ATTRIBUTES; - if (iwrite(fd, &c, 1) != 1) - result = PAPI_DEVICE_ERROR; + return (result); +} +papi_status_t +ipp_write_message(ipp_t **ipp, papi_attribute_t **message) +{ + papi_status_t result; + ipp_t * request = *ipp; + int tmp; + + if (message == NULL) + return (PAPI_BAD_ARGUMENT); + + /* get the request/status code */ + papiAttributeListGetInteger(message, NULL, "status-code", &tmp); + papiAttributeListGetInteger(message, NULL, "operation-id", &tmp); + + request = ippNewRequest((ipp_op_t)tmp); + + if (request != NULL) + result = ipp_write_attribute_groups(request, message); + return (result); } + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2008-08-06 13:21:59
|
Revision: 192 http://openprinting.svn.sourceforge.net/openprinting/?rev=192&view=rev Author: allad Date: 2008-08-06 13:22:07 +0000 (Wed, 06 Aug 2008) Log Message: ----------- Started CUPS implementation of IPP calls. Added Paths: ----------- branches/GSOC-2008/papi/source/libpapi-cups/cups-ipp.c Added: branches/GSOC-2008/papi/source/libpapi-cups/cups-ipp.c =================================================================== --- branches/GSOC-2008/papi/source/libpapi-cups/cups-ipp.c (rev 0) +++ branches/GSOC-2008/papi/source/libpapi-cups/cups-ipp.c 2008-08-06 13:22:07 UTC (rev 192) @@ -0,0 +1,108 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + */ + +#pragma ident "$Id$" + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/types.h> +#include <netinet/in.h> +#include <inttypes.h> + +#include <papi.h> +#include <cups/cups.h> + +papi_status_t +ipp_write_message(ipp_t **ipp, papi_attribute_t **message) +{ + papi_status_t result; + ipp_t * request = *ipp; + int tmp; + + if (message == NULL)) + return (PAPI_BAD_ARGUMENT); + + /* get the request/status code */ + papiAttributeListGetInteger(message, NULL, "status-code", &tmp); + papiAttributeListGetInteger(message, NULL, "operation-id", &tmp); + + request = ippNewRequest((ipp_op_t)tmp); + + if (request != NULL) + result = ipp_write_attribute_groups(request, message); + + return (result); +} + +static papi_status_t +ipp_write_attribute_group(ipp_writer_t iwrite, void *fd, int8_t type, + papi_attribute_t **attributes) +{ + papi_status_t result = PAPI_OK; + int i; + + /* write group tag */ + if (iwrite(fd, &type, 1) != 1) + return (PAPI_DEVICE_ERROR); + + /* write values */ + for (i = 0; ((attributes[i] != NULL) && (result == PAPI_OK)); i++) + result = ipp_write_attribute(iwrite, fd, attributes[i]); + + return (result); +} + +static papi_status_t +ipp_write_attribute_groups(ipp_t *ipp, + papi_attribute_t **groups) +{ + papi_status_t result = PAPI_OK; + int8_t c; + + for (c = DTAG_MIN; c <= DTAG_MAX; c++) { + papi_status_t status; + papi_attribute_t **group = NULL; + void *iter = NULL; + char name[32]; + + (void) ipp_tag_string(c, name, sizeof (name)); + for (status = papiAttributeListGetCollection(groups, &iter, + name, &group); + ((status == PAPI_OK) && (result == PAPI_OK)); + status = papiAttributeListGetCollection(groups, &iter, + NULL, &group)) + result = ipp_write_attribute_group(iwrite, fd, + c, group); + } + + c = DTAG_END_OF_ATTRIBUTES; + if (iwrite(fd, &c, 1) != 1) + result = PAPI_DEVICE_ERROR; + + return (result); +} Property changes on: branches/GSOC-2008/papi/source/libpapi-cups/cups-ipp.c ___________________________________________________________________ Added: svn:keywords + Id This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2008-07-19 20:04:52
|
Revision: 191 http://openprinting.svn.sourceforge.net/openprinting/?rev=191&view=rev Author: allad Date: 2008-07-19 20:00:37 +0000 (Sat, 19 Jul 2008) Log Message: ----------- Updated service.c implementation to use cups/cups.h instead of libhttp and libipp Modified Paths: -------------- branches/GSOC-2008/papi/source/libpapi-cups/Makefile.am branches/GSOC-2008/papi/source/libpapi-cups/ipp-support.c branches/GSOC-2008/papi/source/libpapi-cups/papi_impl.h branches/GSOC-2008/papi/source/libpapi-cups/service.c Modified: branches/GSOC-2008/papi/source/libpapi-cups/Makefile.am =================================================================== --- branches/GSOC-2008/papi/source/libpapi-cups/Makefile.am 2008-07-08 23:25:53 UTC (rev 190) +++ branches/GSOC-2008/papi/source/libpapi-cups/Makefile.am 2008-07-19 20:00:37 UTC (rev 191) @@ -48,6 +48,6 @@ papi_cupsincludedir = $(includedir) # PAPI support layered on IPP -papi_cups_la_SOURCES = service.c printer.c ipp-support.c +papi_cups_la_SOURCES = service.c EXTRA_DIST = papi_impl.h mapfile.in Modified: branches/GSOC-2008/papi/source/libpapi-cups/ipp-support.c =================================================================== --- branches/GSOC-2008/papi/source/libpapi-cups/ipp-support.c 2008-07-08 23:25:53 UTC (rev 190) +++ branches/GSOC-2008/papi/source/libpapi-cups/ipp-support.c 2008-07-19 20:00:37 UTC (rev 191) @@ -38,7 +38,6 @@ #include <config-site.h> -#include <ipp.h> static void ipp_add_printer_uri(service_t *svc, char *name, papi_attribute_t ***op); Modified: branches/GSOC-2008/papi/source/libpapi-cups/papi_impl.h =================================================================== --- branches/GSOC-2008/papi/source/libpapi-cups/papi_impl.h 2008-07-08 23:25:53 UTC (rev 190) +++ branches/GSOC-2008/papi/source/libpapi-cups/papi_impl.h 2008-07-19 20:00:37 UTC (rev 191) @@ -41,9 +41,9 @@ #include <stdarg.h> #include <uri.h> -#include <http.h> -#include <ipp.h> +#include <cups/cups.h> + /* * Implementation specific types/prototypes/definitions follow * Modified: branches/GSOC-2008/papi/source/libpapi-cups/service.c =================================================================== --- branches/GSOC-2008/papi/source/libpapi-cups/service.c 2008-07-08 23:25:53 UTC (rev 190) +++ branches/GSOC-2008/papi/source/libpapi-cups/service.c 2008-07-19 20:00:37 UTC (rev 191) @@ -98,14 +98,20 @@ uri_from_string(service_name, &svc->uri); } - if (svc->uri == NULL) - return (PAPI_NOT_POSSIBLE); + if (svc->uri != NULL){ - if (svc->uri->port != NULL) - port = strtol(svc->uri->port, NULL, 10); - - svc->connection = httpConnectEncrypt(svc->uri->host, port, + if (svc->uri->port != NULL) + port = strtol(svc->uri->port, NULL, 10); + else port = ippPort(); + + svc->connection = httpConnectEncrypt(svc->uri->host, port, http_encryption_type(svc->encryption)); + } + else{ + /*Use CUPS default methods to get server and ports*/ + svc->connection = httpConnectEncrypt(cupsServer(), ippPort(), + http_encryption_type(svc->encryption)); + } if (svc->connection == NULL) { if (svc->uri != NULL) { uri_free(svc->uri); @@ -152,12 +158,10 @@ svc->transfer_encoding = TRANSFER_ENCODING_LENGTH; else svc->transfer_encoding = TRANSFER_ENCODING_CHUNKED; + + result = service_connect(svc, service_name); + - if (service_name != NULL) { - result = service_connect(svc, service_name); - } else - result = PAPI_OK; - return (result); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2008-07-08 23:25:48
|
Revision: 190 http://openprinting.svn.sourceforge.net/openprinting/?rev=190&view=rev Author: allad Date: 2008-07-08 16:25:53 -0700 (Tue, 08 Jul 2008) Log Message: ----------- Imported implementation code from libpapi-ipp. Switching to CUPS low level IPP/HTTP layers Modified Paths: -------------- branches/GSOC-2008/papi/source/libpapi-cups/Makefile.am branches/GSOC-2008/papi/source/libpapi-cups/papi_impl.h branches/GSOC-2008/papi/source/libpapi-cups/printer.c branches/GSOC-2008/papi/source/libpapi-cups/service.c Added Paths: ----------- branches/GSOC-2008/papi/source/libpapi-cups/ipp-support.c Modified: branches/GSOC-2008/papi/source/libpapi-cups/Makefile.am =================================================================== --- branches/GSOC-2008/papi/source/libpapi-cups/Makefile.am 2008-06-30 20:27:00 UTC (rev 189) +++ branches/GSOC-2008/papi/source/libpapi-cups/Makefile.am 2008-07-08 23:25:53 UTC (rev 190) @@ -31,7 +31,7 @@ # this gets installed in libexecdir libdir = $(libexecdir) -AM_CPPFLAGS = -I../libpapi-common -I. +AM_CPPFLAGS = -I../libpapi-common -I../libhttp-core -I../libipp-core -I. lib_LTLIBRARIES = papi-cups.la @@ -48,6 +48,6 @@ papi_cupsincludedir = $(includedir) # PAPI support layered on IPP -papi_cups_la_SOURCES = service.c printer.c +papi_cups_la_SOURCES = service.c printer.c ipp-support.c EXTRA_DIST = papi_impl.h mapfile.in Added: branches/GSOC-2008/papi/source/libpapi-cups/ipp-support.c =================================================================== --- branches/GSOC-2008/papi/source/libpapi-cups/ipp-support.c (rev 0) +++ branches/GSOC-2008/papi/source/libpapi-cups/ipp-support.c 2008-07-08 23:25:53 UTC (rev 190) @@ -0,0 +1,617 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + */ + +#pragma ident "$Id$" + +#include <papi_impl.h> +#include <stdlib.h> +#include <pwd.h> +#include <locale.h> +#include <errno.h> +#include <fcntl.h> +#include <sys/stat.h> +#include <md5.h> + +#include <config-site.h> + +#include <ipp.h> + +static void ipp_add_printer_uri(service_t *svc, char *name, + papi_attribute_t ***op); + +papi_status_t +http_to_papi_status(http_status_t status) +{ + switch (status) { + case HTTP_OK: + return (PAPI_OK); + case HTTP_BAD_REQUEST: + return (PAPI_BAD_REQUEST); + case HTTP_UNAUTHORIZED: + case HTTP_FORBIDDEN: + return (PAPI_NOT_AUTHORIZED); + case HTTP_NOT_FOUND: + return (PAPI_NOT_FOUND); + case HTTP_GONE: + return (PAPI_GONE); + case HTTP_SERVICE_UNAVAILABLE: + return (PAPI_SERVICE_UNAVAILABLE); + default: + return ((papi_status_t)status); + } +} + +papi_status_t +ipp_to_papi_status(uint16_t status) +{ + switch (status) { + case IPP_OK: + return (PAPI_OK); + case IPP_OK_IGNORED_ATTRIBUTES: + return (PAPI_OK); + case IPP_OK_CONFLICTING_ATTRIBUTES: + return (PAPI_OK); + case IPP_OK_IGNORED_SUBSCRIPTIONS: + return (PAPI_OK_IGNORED_SUBSCRIPTIONS); + case IPP_OK_IGNORED_NOTIFICATIONS: + return (PAPI_OK_IGNORED_NOTIFICATIONS); + case IPP_CERR_BAD_REQUEST: + return (PAPI_BAD_REQUEST); + case IPP_CERR_FORBIDDEN: + return (PAPI_FORBIDDEN); + case IPP_CERR_NOT_AUTHENTICATED: + return (PAPI_NOT_AUTHENTICATED); + case IPP_CERR_NOT_AUTHORIZED: + return (PAPI_NOT_AUTHORIZED); + case IPP_CERR_NOT_POSSIBLE: + return (PAPI_NOT_POSSIBLE); + case IPP_CERR_TIMEOUT: + return (PAPI_TIMEOUT); + case IPP_CERR_NOT_FOUND: + return (PAPI_NOT_FOUND); + case IPP_CERR_GONE: + return (PAPI_GONE); + case IPP_CERR_REQUEST_ENTITY: + return (PAPI_REQUEST_ENTITY); + case IPP_CERR_REQUEST_VALUE: + return (PAPI_REQUEST_VALUE); + case IPP_CERR_DOCUMENT_FORMAT: + return (PAPI_DOCUMENT_FORMAT); + case IPP_CERR_ATTRIBUTES: + return (PAPI_ATTRIBUTES); + case IPP_CERR_URI_SCHEME: + return (PAPI_URI_SCHEME); + case IPP_CERR_CHARSET: + return (PAPI_CHARSET); + case IPP_CERR_CONFLICT: + return (PAPI_CONFLICT); + case IPP_CERR_COMPRESSION_NOT_SUPPORTED: + return (PAPI_COMPRESSION_NOT_SUPPORTED); + case IPP_CERR_COMPRESSION_ERROR: + return (PAPI_COMPRESSION_ERROR); + case IPP_CERR_DOCUMENT_FORMAT_ERROR: + return (PAPI_DOCUMENT_FORMAT_ERROR); + case IPP_CERR_DOCUMENT_ACCESS_ERROR: + return (PAPI_DOCUMENT_ACCESS_ERROR); + case IPP_CERR_ATTRIBUTES_NOT_SETTABLE: + return (PAPI_ATTRIBUTES_NOT_SETTABLE); + case IPP_CERR_IGNORED_ALL_SUBSCRIPTIONS: + return (PAPI_IGNORED_ALL_SUBSCRIPTIONS); + case IPP_CERR_TOO_MANY_SUBSCRIPTIONS: + return (PAPI_TOO_MANY_SUBSCRIPTIONS); + case IPP_CERR_IGNORED_ALL_NOTIFICATIONS: + return (PAPI_IGNORED_ALL_NOTIFICATIONS); + case IPP_CERR_PRINT_SUPPORT_FILE_NOT_FOUND: + return (PAPI_PRINT_SUPPORT_FILE_NOT_FOUND); + case IPP_SERR_INTERNAL: + return (PAPI_INTERNAL_ERROR); + case IPP_SERR_OPERATION_NOT_SUPPORTED: + return (PAPI_OPERATION_NOT_SUPPORTED); + case IPP_SERR_SERVICE_UNAVAILABLE: + return (PAPI_SERVICE_UNAVAILABLE); + case IPP_SERR_VERSION_NOT_SUPPORTED: + return (PAPI_VERSION_NOT_SUPPORTED); + case IPP_SERR_DEVICE_ERROR: + return (PAPI_DEVICE_ERROR); + case IPP_SERR_TEMPORARY_ERROR: + return (PAPI_TEMPORARY_ERROR); + case IPP_SERR_NOT_ACCEPTING: + return (PAPI_NOT_ACCEPTING); + case IPP_SERR_BUSY: + case IPP_SERR_CANCELLED: + default: + return (PAPI_TEMPORARY_ERROR); + } +} + +void +ipp_initialize_request(service_t *svc, papi_attribute_t ***request, + uint16_t operation) +{ + papiAttributeListAddInteger(request, PAPI_ATTR_EXCL, + "version-major", 1); + papiAttributeListAddInteger(request, PAPI_ATTR_EXCL, + "version-minor", 1); + papiAttributeListAddInteger(request, PAPI_ATTR_EXCL, + "request-id", (short)lrand48()); + papiAttributeListAddInteger(request, PAPI_ATTR_EXCL, + "operation-id", operation); +} + +void +ipp_initialize_operational_attributes(service_t *svc, papi_attribute_t ***op, + char *printer, int job_id) +{ + char *charset = "utf-8"; /* default to UTF-8 encoding */ + char *language = setlocale(LC_ALL, ""); + char *user = "nobody"; + struct passwd *pw = NULL; + + /* + * All IPP requests must contain the following: + * attributes-charset (UTF-8) + * attributes-natural-language (our current locale) + * (object identifier) printer-uri/job-id or job-uri + * requesting-user-name (process user or none) + */ + papiAttributeListAddString(op, PAPI_ATTR_EXCL, + "attributes-charset", charset); + + papiAttributeListAddString(op, PAPI_ATTR_EXCL, + "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); + + if ((pw = getpwuid(getuid())) != NULL) + user = pw->pw_name; + /* + * if our euid is 0 "super user", we will allow the system supplied + * user name to be overridden, if the requestor wants to. + */ + if (geteuid() == 0) { + if (svc->user != NULL) + user = svc->user; + } + papiAttributeListAddString(op, PAPI_ATTR_REPLACE, + "requesting-user-name", user); +} + +#ifndef OPID_CUPS_GET_DEFAULT /* for servers that will enumerate */ +#define OPID_CUPS_GET_DEFAULT 0x4001 +#endif /* OPID_CUPS_GET_DEFAULT */ + +static papi_status_t +_default_destination(service_t *svc, char **uri) +{ + papi_status_t result = PAPI_INTERNAL_ERROR; + printer_t *p = NULL; + papi_attribute_t **request = NULL, **op = NULL, **response = NULL; + char *tmp = NULL; + + if ((svc == NULL) || (uri == NULL)) + return (PAPI_BAD_ARGUMENT); + + /* we must be connected to find the default destination */ + if (svc->connection == NULL) + return (PAPI_NOT_POSSIBLE); + + if ((p = calloc(1, sizeof (*p))) == NULL) + return (PAPI_TEMPORARY_ERROR); + + 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"); + papiAttributeListAddCollection(&request, PAPI_ATTR_REPLACE, + "operational-attributes-group", op); + papiAttributeListFree(op); + result = ipp_send_request(svc, request, &response); + papiAttributeListFree(request); + + op = NULL; + papiAttributeListGetCollection(response, NULL, + "printer-attributes-group", &op); + + if (uri != NULL) { + char *tmp = NULL; + + papiAttributeListGetString(op, NULL, "printer-uri", &tmp); + papiAttributeListGetString(op, NULL, + "printer-uri-supported", &tmp); + if (tmp != NULL) + *uri = strdup(tmp); + } + + papiAttributeListFree(response); + + return (result); +} + +static void +ipp_add_printer_uri(service_t *svc, char *name, papi_attribute_t ***op) +{ + char *uri = name; + char buf[BUFSIZ]; + uri_t *tmp = NULL; + + if (strstr(name, "://") == NULL) { /* not in URI form */ + if (strcmp(name, DEFAULT_DEST) != 0) { + /* not the "default" */ + snprintf(buf, sizeof (buf), "%s/%s", svc->name, name); + uri = buf; + } else + _default_destination(svc, &uri); + } + + papiAttributeListAddString(op, PAPI_ATTR_EXCL, "printer-uri", uri); + + /* save the printer-uri's path to be used by http POST request */ + if ((uri_from_string(uri, &tmp) == 0) && (tmp != NULL)) { + if (svc->post != NULL) + free(svc->post); + svc->post = strdup(tmp->path); + uri_free(tmp); + } +} + + +/* + * don't actually write anything, just add to the total size and return the + * size of what would be written, so we can figure out how big the request + * is going to be. + */ +static ssize_t +size_calculate(void *fd, void *buffer, size_t length) +{ + ssize_t *size = (ssize_t *)fd; + + *size += length; + return (length); +} + + +static ssize_t +build_chunk(void *fd, void *buffer, size_t length) +{ + char **s1 = fd; + + memcpy(*s1, buffer, length); + *s1 = *s1 + length; + + return (length); +} + +ssize_t +ipp_request_write(void *fd, void *buffer, size_t length) +{ + service_t *svc = (service_t *)fd; + +#ifdef DEBUG + printf("ipp_request_write(0x%8.8x, 0x%8.8x, %d)\n", fd, buffer, length); + httpDumpData(stdout, "ipp_request_write:", buffer, length); +#endif + return (httpWrite(svc->connection, buffer, length)); +} + +ssize_t +ipp_request_read(void *fd, void *buffer, size_t length) +{ + service_t *svc = (service_t *)fd; + ssize_t rc, i = length; + char *p = buffer; + + while ((rc = httpRead(svc->connection, p, i)) != i) { + if (rc == 0) + return (rc); + if (rc < 0) + return (rc); + i -= rc; + p += rc; + } +#ifdef DEBUG + printf("ipp_request_read(0x%8.8x, 0x%8.8x, %d) = %d\n", + fd, buffer, length, rc); + httpDumpData(stdout, "ipp_request_read:", buffer, length); +#endif + + return (length); +} + +papi_status_t +ipp_send_initial_request_block(service_t *svc, papi_attribute_t **request, + ssize_t file_size) +{ + papi_status_t result = PAPI_OK; + ssize_t chunk_size = 0; + char length[32]; + void *chunk, *ptr; + http_status_t status; + + /* calculate the request size */ + (void) ipp_write_message(&size_calculate, &chunk_size, request); + + /* Fill in the HTTP Header information */ + httpClearFields(svc->connection); + if (svc->transfer_encoding == TRANSFER_ENCODING_CHUNKED) + httpSetField(svc->connection, HTTP_FIELD_TRANSFER_ENCODING, + "chunked"); + else { + sprintf(length, "%lu", (unsigned long)(file_size + chunk_size)); + httpSetField(svc->connection, HTTP_FIELD_CONTENT_LENGTH, + length); + } + httpSetField(svc->connection, HTTP_FIELD_CONTENT_TYPE, + "application/ipp"); + httpSetField(svc->connection, HTTP_FIELD_AUTHORIZATION, + svc->connection->authstring); + + /* flush any state information about this connection */ + httpFlush(svc->connection); + + /* if we have don't have a POST path, use the service uri path */ + if (svc->post == NULL) + svc->post = strdup(svc->uri->path); + /* send the HTTP POST message for the IPP request */ + /* if the POST fails, return the error */ + status = httpPost(svc->connection, svc->post); + if (status != 0) + return (http_to_papi_status(status)); + + if (httpCheck(svc->connection) != 0) { + status = httpUpdate(svc->connection); + if (status != HTTP_OK) + return (http_to_papi_status(status)); + } + + /* build the request chunk */ + chunk = ptr = calloc(1, chunk_size); + result = ipp_write_message(&build_chunk, &ptr, request); +#ifdef DEBUG + printf("request: %d (0x%x) bytes\n", chunk_size, chunk_size); + httpDumpData(stdout, "request:", chunk, chunk_size); +#endif + + /* send the actual IPP request */ + if (ipp_request_write(svc, chunk, chunk_size) != chunk_size) + result = PAPI_TEMPORARY_ERROR; + free(chunk); + + if (httpCheck(svc->connection) != 0) { + status = httpUpdate(svc->connection); + if (status != HTTP_OK) + return (http_to_papi_status(status)); + } + + return (result); +} + +static int +setAuthString(service_t *svc) +{ + http_t *http; + char *user, *passphrase; + char encoded[BUFSIZ]; + + if ((svc == NULL) || (svc->connection == NULL) || (svc->name == NULL)) + return (-1); + + http = svc->connection; + + if (svc->user == NULL) { + struct passwd *p; + + if ((p = getpwuid(getuid())) != NULL) { + user = p->pw_name; + } else if ((user = getenv("LOGNAME")) == NULL) + user = getenv("USER"); + if (user == NULL) + user = "nobody"; + } else + user = svc->user; + + /* if the passphrase is not set, use the Authentication Callback */ + if (((svc->password == NULL) || (svc->password[0] == '\0')) && + (svc->authCB != NULL)) + (svc->authCB)(svc, svc->app_data); + passphrase = svc->password; + + /* if there is still no passphrase, we have to fail */ + if ((passphrase == NULL) || (passphrase[0] == '\0')) + return (-1); + + if (strncmp(http->fields[HTTP_FIELD_WWW_AUTHENTICATE], + "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); + } else if (strncmp(http->fields[HTTP_FIELD_WWW_AUTHENTICATE], + "Digest", 6) == 0) { + char realm[HTTP_MAX_VALUE]; + char nonce[HTTP_MAX_VALUE]; + char line [BUFSIZ]; + char urp[128]; + char mr[128]; + char *uri = svc->post; + + httpGetSubField(http, HTTP_FIELD_WWW_AUTHENTICATE, + "realm", realm); + httpGetSubField(http, HTTP_FIELD_WWW_AUTHENTICATE, + "nonce", nonce); + + snprintf(line, sizeof (line), "%s:%s:%s", user, realm, + passphrase); + md5_calc(urp, line, strlen(line)); + + snprintf(line, sizeof (line), "POST:%s", uri); + md5_calc(mr, line, strlen(line)); + + snprintf(line, sizeof (line), "%s:%s:%s", urp, mr, nonce); + 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); + } + + return (0); +} + +papi_status_t +ipp_status_info(service_t *svc, papi_attribute_t **response) +{ + papi_attribute_t **operational = NULL; + int32_t status = 0; + + papiAttributeListGetCollection(response, NULL, + "operational-attributes-group", &operational); + if (operational != NULL) { + char *message = NULL; + + papiAttributeListGetString(response, NULL, + "status-message", &message); + papiAttributeListAddString(&svc->attributes, PAPI_ATTR_REPLACE, + "detailed-status-message", message); + } + papiAttributeListGetInteger(response, NULL, "status-code", &status); + + return (ipp_to_papi_status(status)); +} + +papi_status_t +ipp_send_request_with_file(service_t *svc, papi_attribute_t **request, + papi_attribute_t ***response, char *file) +{ + papi_status_t result = PAPI_OK; + ssize_t size = 0; + int fd; + +#ifdef DEBUG + fprintf(stderr, "\nIPP-REQUEST: (%s)", (file ? file : "")); + papiAttributeListPrint(stderr, request, " "); + putc('\n', stderr); + fflush(stderr); +#endif + + /* + * if we are sending a file, open it and include it's size in the + * message size. + */ + if (file != NULL) { + if ((fd = open(file, O_RDONLY)) < 0) { + detailed_error(svc, "%s: %s", file, strerror(errno)); + return (PAPI_DOCUMENT_ACCESS_ERROR); + } else if (svc->transfer_encoding != + TRANSFER_ENCODING_CHUNKED) { + struct stat st; + + if (fstat(fd, &st) >= 0) + size = st.st_size; + } + } + + *response = NULL; + while (*response == NULL) { + http_status_t status = HTTP_CONTINUE; + + result = ipp_send_initial_request_block(svc, request, size); + + if (result == PAPI_OK) { + if (file != NULL) { + /* send the file contents if we have it */ + int rc; + char buf[BUFSIZ]; + + lseek(fd, 0L, SEEK_SET); + while ((rc = read(fd, buf, sizeof (buf))) > 0) { + if (ipp_request_write(svc, buf, rc) + < rc) { + break; + } + } + } + + (void) ipp_request_write(svc, "", 0); + } + + /* update our connection info */ + while (status == HTTP_CONTINUE) + status = httpUpdate(svc->connection); + + if (status == HTTP_UNAUTHORIZED) { + httpFlush(svc->connection); + if ((svc->connection->authstring[0] == '\0') && + (setAuthString(svc) == 0)) { + httpReconnect(svc->connection); + continue; + } + } else if (status == HTTP_UPGRADE_REQUIRED) { + /* + * If the transport was built with TLS support, we can + * try to use it. + */ + httpFlush(svc->connection); + httpReconnect(svc->connection); + httpEncryption(svc->connection, HTTP_ENCRYPT_REQUIRED); + continue; + } + + if (status != HTTP_OK) + return (http_to_papi_status(status)); + + /* read the IPP response */ + result = ipp_read_message(&ipp_request_read, svc, 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)); + papiAttributeListPrint(stderr, *response, " "); + putc('\n', stderr); + fflush(stderr); +#endif + } + + return (result); +} + +papi_status_t +ipp_send_request(service_t *svc, papi_attribute_t **request, + papi_attribute_t ***response) +{ + return (ipp_send_request_with_file(svc, request, response, NULL)); +} Property changes on: branches/GSOC-2008/papi/source/libpapi-cups/ipp-support.c ___________________________________________________________________ Name: svn:keywords + Id Modified: branches/GSOC-2008/papi/source/libpapi-cups/papi_impl.h =================================================================== --- branches/GSOC-2008/papi/source/libpapi-cups/papi_impl.h 2008-06-30 20:27:00 UTC (rev 189) +++ branches/GSOC-2008/papi/source/libpapi-cups/papi_impl.h 2008-07-08 23:25:53 UTC (rev 190) @@ -39,8 +39,10 @@ #include <time.h> #include <sys/types.h> #include <stdarg.h> -#include <cups/cups.h> +#include <uri.h> +#include <http.h> +#include <ipp.h> /* * Implementation specific types/prototypes/definitions follow @@ -58,9 +60,13 @@ char *name; char *user; char *password; + int (*authCB)(papi_service_t svc, void *app_data); + papi_encryption_t encryption; void *app_data; - int num_dests; - cups_dest_t *dests; + uri_t *uri; + char *post; + http_t *connection; + http_transfer_encoding_t transfer_encoding; } service_t; typedef struct job { @@ -68,14 +74,33 @@ } job_t; typedef struct { - cups_dest_t *dest; papi_attribute_t **attributes; } printer_t; +/* IPP glue interfaces */ +extern ssize_t ipp_request_read(void *fd, void *buffer, size_t length); +extern ssize_t ipp_request_write(void *fd, void *buffer, size_t length); +extern papi_status_t ipp_send_request(service_t *svc, + papi_attribute_t **request, + papi_attribute_t ***response); +extern papi_status_t ipp_send_request_with_file(service_t *svc, + papi_attribute_t **request, + papi_attribute_t ***response, char *file); +extern papi_status_t ipp_send_initial_request_block(service_t *svc, + papi_attribute_t **request, ssize_t file_size); +extern papi_status_t ipp_status_info(service_t *svc, + papi_attribute_t **response); +extern void ipp_initialize_request(service_t *svc, + papi_attribute_t ***request, uint16_t type); +extern void ipp_initialize_operational_attributes(service_t *svc, + papi_attribute_t ***op, + char *printer, int job_id); +extern papi_status_t ipp_to_papi_status(uint16_t status); +extern papi_status_t http_to_papi_status(http_status_t status); - /* service related interfaces */ extern void detailed_error(service_t *svc, char *fmt, ...); +extern papi_status_t service_connect(service_t *svc, char *service_name); #ifdef __cplusplus Modified: branches/GSOC-2008/papi/source/libpapi-cups/printer.c =================================================================== --- branches/GSOC-2008/papi/source/libpapi-cups/printer.c 2008-06-30 20:27:00 UTC (rev 189) +++ branches/GSOC-2008/papi/source/libpapi-cups/printer.c 2008-07-08 23:25:53 UTC (rev 190) @@ -27,11 +27,12 @@ #pragma ident "$Id$" +/*LINTLIBRARY*/ #include <stdlib.h> #include <papi_impl.h> -#include <cups/cups.h> +#include <config-site.h> void papiPrinterFree(papi_printer_t printer) @@ -57,38 +58,23 @@ } } -static int -filter_cups_printer(cups_dest_t *printer,papi_filter_t *filter) -{ - if(filter == NULL) - return 1; - - if(printer == NULL) - return 0; - - /*TODO implement filters */ - if(filter->filter.bitmask.mask & PAPI_PRINTER_LOCAL) - { - } - - if(filter->filter.bitmask.mask & PAPI_PRINTER_CLASS) - { - } - - if(filter->filter.bitmask.mask & PAPI_PRINTER_REMOTE) - { - } - - if(filter->filter.bitmask.mask & PAPI_PRINTER_BW) - { - } - - if(filter->filter.bitmask.mask & PAPI_PRINTER_COLOR) - { - } - - return 1; -} +/* + * Enumeration of printers is not part of the IPP specification, so many + * servers will probably not respond back with a list of printers, but + * CUPS has implemented an extension to IPP to enumerate printers and + * classes. the Apache/mod_ipp IPP listener module available in Solaris + * implements this IPP extension, so CUPS and Solaris can provide this + * to IPP clients. + */ +#ifndef OPID_CUPS_GET_PRINTERS /* for servers that will enumerate */ +#define OPID_CUPS_GET_PRINTERS 0x4002 +#endif /* OPID_CUPS_GET_PRINTERS */ +#ifndef OPID_CUPS_DELETE_PRINTER /* for servers that can delete */ +#define OPID_CUPS_DELETE_PRINTER 0x4004 +#endif /* OPID_CUPS_DELETE_PRINTER */ +#ifndef OPID_CUPS_GET_CLASSES /* for servers that will enumerate */ +#define OPID_CUPS_GET_CLASSES 0x4005 +#endif /* OPID_CUPS_GET_CLASSES */ papi_status_t papiPrintersList(papi_service_t handle, char **requested_attrs, @@ -96,68 +82,54 @@ { papi_status_t status, result = PAPI_INTERNAL_ERROR; service_t *svc = handle; - int i; + papi_attribute_t **request = NULL, **op = NULL, **response = NULL; + void *iter = NULL; if ((svc == NULL) || (printers == NULL)) return (PAPI_BAD_ARGUMENT); - - /* only bitmask filters are supported */ - if(filter && filter->type != PAPI_FILTER_BITMASK){ - return PAPI_OPERATION_NOT_SUPPORTED; + + /* if we are already connected, use that connection. */ + if (svc->connection == NULL) + if ((result = service_connect(svc, DEFAULT_DEST)) != PAPI_OK) + return (result); + ipp_initialize_request(svc, &request, OPID_CUPS_GET_PRINTERS); + + ipp_initialize_operational_attributes(svc, &op, NULL, -1); + + if (requested_attrs != NULL) { + int i; + + for (i = 0; requested_attrs[i] != NULL; i++) + papiAttributeListAddString(&op, PAPI_ATTR_APPEND, + "requested-attributes", requested_attrs[i]); } - - for(i=0;i< svc->num_dests;i++){ - /*filter if needed*/ - - if(filter_cups_printer(svc->dests+i,filter) == 0){ - //printer didn't pass filter - continue; - } - - /* ok. printer passed filtering*/ + + papiAttributeListAddCollection(&request, PAPI_ATTR_REPLACE, + "operational-attributes-group", op); + papiAttributeListFree(op); + result = ipp_send_request(svc, request, &response); + papiAttributeListFree(request); + + op = NULL; + for (status = papiAttributeListGetCollection(response, &iter, + "printer-attributes-group", &op); + status == PAPI_OK; + status = papiAttributeListGetCollection(response, &iter, + NULL, &op)) { printer_t *p = NULL; - int j = 0; if ((p = calloc(1, sizeof (*p))) == NULL) return (PAPI_TEMPORARY_ERROR); - - p->dest = svc->dests+i; - for(j=0;j<svc->dests[i].num_options;j++){ - if(requested_attrs != NULL){ - //filter attribute - char *attr = (char *)list_locate (&requested_attrs,strcasecmp,svc->dests[i].options[j].name); - if(attr == NULL) - continue; /* attribute not requested*/ - } - - papiAttributeListAddString (&p->attributes,PAPI_ATTR_APPEND, - svc->dests[i].options[j].name,svc->dests[i].options[j].value); - } - /* if printer-name attribute is requested, add it - Printer name is treated differently because it is not included in CUPS options. - */ - char *pname = (char *)list_locate (&requested_attrs,strcasecmp,"printer-name"); - if(pname != NULL){ - papiAttributeListAddString (&p->attributes,PAPI_ATTR_APPEND, - "printer-name",svc->dests[i].name); - } - - list_append (printers,p); + copy_attributes(&p->attributes, op); + op = NULL; + list_append(printers, p); } + papiAttributeListFree(response); - result = PAPI_OK; - return (result); } - -/* - * Returns PAPI_NOT_FOUND if there's no printer - * named "name" - * PAPI_OK otherwise - * - */ papi_status_t papiPrinterQuery(papi_service_t handle, char *name, char **requested_attrs, @@ -167,51 +139,130 @@ papi_status_t result = PAPI_INTERNAL_ERROR; service_t *svc = handle; printer_t *p = NULL; - cups_dest_t *dest = NULL; + papi_attribute_t **request = NULL, **op = NULL, **response = NULL; if ((svc == NULL) || (name == NULL) || (printer == NULL)) return (PAPI_BAD_ARGUMENT); - - dest = cupsGetDest(name,NULL,svc->num_dests,svc->dests); - if(dest == NULL){ - return PAPI_NOT_FOUND; //named dest not found - } - + /* if we are already connected, use that connection. */ + if (svc->connection == NULL) + if ((result = service_connect(svc, name)) != PAPI_OK) + return (result); + if ((*printer = p = calloc(1, sizeof (*p))) == NULL) return (PAPI_TEMPORARY_ERROR); - - p->dest = dest; - int j = 0; - - for(j=0;j<dest->num_options;j++){ - if(requested_attrs != NULL){ - //filter attribute - char *attr = (char *)list_locate (&requested_attrs,strcasecmp,dest->options[j].name); - if(attr == NULL) - continue; /* attribute not requested*/ - } - - papiAttributeListAddString (&p->attributes,PAPI_ATTR_APPEND, - dest->options[j].name,dest->options[j].value); + ipp_initialize_request(svc, &request, OPID_GET_PRINTER_ATTRIBUTES); + + ipp_initialize_operational_attributes(svc, &op, name, -1); + + if (requested_attrs != NULL) { + int i; + + for (i = 0; requested_attrs[i] != NULL; i++) + papiAttributeListAddString(&op, PAPI_ATTR_APPEND, + "requested-attributes", requested_attrs[i]); } - /* if printer-name attribute is requested, add it - Printer name is treated differently because it is not included in CUPS options. - */ - char *pname = (char *)list_locate (&requested_attrs,strcasecmp,"printer-name"); - if(pname != NULL){ - papiAttributeListAddString (&p->attributes,PAPI_ATTR_APPEND, - "printer-name",dest->name); + + papiAttributeListAddCollection(&request, PAPI_ATTR_REPLACE, + "operational-attributes-group", op); + papiAttributeListFree(op); + result = ipp_send_request(svc, request, &response); + papiAttributeListFree(request); + + op = NULL; + papiAttributeListGetCollection(response, NULL, + "printer-attributes-group", &op); + copy_attributes(&p->attributes, op); + papiAttributeListFree(response); + + return (result); +} + +static papi_status_t +_printer_enable_disable_pause_resume_delete(papi_service_t handle, char *name, + char *message, uint16_t type) +{ + papi_status_t result = PAPI_INTERNAL_ERROR; + service_t *svc = handle; + papi_attribute_t **request = NULL, **op = NULL, **response = NULL; + + if ((svc == NULL) || (name == NULL)) + return (PAPI_BAD_ARGUMENT); + + /* if we are already connected, use that connection. */ + if (svc->connection == NULL) + if ((result = service_connect(svc, name)) != PAPI_OK) + return (result); + + ipp_initialize_request(svc, &request, type); + + ipp_initialize_operational_attributes(svc, &op, name, -1); + + switch (type) { + case OPID_DISABLE_PRINTER: + papiAttributeListAddString(&op, PAPI_ATTR_REPLACE, + "printer-message-from-operator", message); + break; + case OPID_PAUSE_PRINTER: + papiAttributeListAddString(&op, PAPI_ATTR_REPLACE, + "printer-state-message", message); + break; + default: /* a message value is of no use */ + break; } - - result = PAPI_OK; + papiAttributeListAddCollection(&request, PAPI_ATTR_REPLACE, + "operational-attributes-group", op); + papiAttributeListFree(op); + result = ipp_send_request(svc, request, &response); + papiAttributeListFree(request); + papiAttributeListFree(response); + return (result); } +papi_status_t +papiPrinterEnable(papi_service_t handle, char *name) +{ + return (_printer_enable_disable_pause_resume_delete(handle, name, + NULL, OPID_ENABLE_PRINTER)); +} papi_status_t +papiPrinterResume(papi_service_t handle, char *name) +{ + return (_printer_enable_disable_pause_resume_delete(handle, name, + NULL, OPID_RESUME_PRINTER)); +} + +papi_status_t +papiPrinterPause(papi_service_t handle, char *name, char *message) +{ + return (_printer_enable_disable_pause_resume_delete(handle, name, + message, OPID_PAUSE_PRINTER)); +} + +papi_status_t +papiPrinterDisable(papi_service_t handle, char *name, char *message) +{ + return (_printer_enable_disable_pause_resume_delete(handle, name, + message, OPID_PAUSE_PRINTER)); +} + +/* + * there is no IPP create operation, the set-printer-attibutes operation + * is the closest we have, so we will assume that the server will create + * a printer and set attributes if there is none. + */ +papi_status_t +papiPrinterAdd(papi_service_t handle, char *name, + papi_attribute_t **attributes, papi_printer_t *printer) +{ + return (papiPrinterModify(handle, name, attributes, printer)); +} + +papi_status_t papiPrinterModify(papi_service_t handle, char *name, papi_attribute_t **attributes, papi_printer_t *printer) { @@ -219,111 +270,159 @@ service_t *svc = handle; printer_t *p = NULL; papi_attribute_t **request = NULL, **op = NULL, **response = NULL; - cups_dest_t *dest = NULL; - int i = 0; if ((svc == NULL) || (name == NULL) || (printer == NULL)) return (PAPI_BAD_ARGUMENT); - dest = cupsGetDest(name,NULL,svc->num_dests,svc->dests); + /* if we are already connected, use that connection. */ + if (svc->connection == NULL) + if ((result = service_connect(svc, name)) != PAPI_OK) + return (result); - if(dest == NULL){ - return PAPI_NOT_FOUND; //named dest not found - } - - for(i = 0; attributes[i] != NULL; i++){ - char *value = (char *)cupsGetOption(attributes[i]->name, - dest->num_options,dest->options); - if(value != NULL) { - //the attribute already existe. remove it first - //(so that we can add it later on with the new value) - dest->num_options = cupsRemoveOption(attributes[i]->name, - dest->num_options,&dest->options); - } - - //if it is not a DELETE attribute, then add it now with the new - //value - if(attributes[i]->type == PAPI_METADATA - && attributes[i]->values[0]->metadata != PAPI_DELETE){ - char buffer[256]; - papiAttributeToString (attributes[i]," ", - buffer,256); - dest->num_options = cupsAddOption(attributes[i]->name,buffer, - dest->num_options,&dest->options); - } - - } - - //now commit changes - cupsSetDests(svc->num_dests,svc->dests); - if ((*printer = p = calloc(1, sizeof (*p))) == NULL) return (PAPI_TEMPORARY_ERROR); - - p->dest = dest; - result = PAPI_OK; + ipp_initialize_request(svc, &request, OPID_SET_PRINTER_ATTRIBUTES); + ipp_initialize_operational_attributes(svc, &op, name, -1); + + papiAttributeListAddCollection(&request, PAPI_ATTR_REPLACE, + "operational-attributes-group", op); + papiAttributeListFree(op); + + papiAttributeListAddCollection(&request, PAPI_ATTR_REPLACE, + "printer-attributes-group", attributes); + result = ipp_send_request(svc, request, &response); + papiAttributeListFree(request); + + op = NULL; + papiAttributeListGetCollection(response, NULL, + "printer-attributes-group", &op); + copy_attributes(&p->attributes, op); + papiAttributeListFree(response); + return (result); } +papi_status_t +papiPrinterRemove(papi_service_t handle, char *name) +{ + return (_printer_enable_disable_pause_resume_delete(handle, name, + NULL, OPID_CUPS_DELETE_PRINTER)); +} -/*Add a new Printer with the given attributes. - *If a printer with the same name already exists, - *simply update its attributes - */ papi_status_t -papiPrinterAdd(papi_service_t handle, char *name, - papi_attribute_t **attributes, papi_printer_t *printer) +papiPrinterPurgeJobs(papi_service_t handle, char *name, + papi_job_t **jobs) { - papi_status_t result = PAPI_INTERNAL_ERROR; + papi_status_t status, result = PAPI_INTERNAL_ERROR; service_t *svc = handle; - printer_t *p = NULL; papi_attribute_t **request = NULL, **op = NULL, **response = NULL; - cups_dest_t *dest = NULL; + void *iter = NULL; - if ((svc == NULL) || (name == NULL) || (printer == NULL)) + + if ((svc == NULL) || (name == NULL)) return (PAPI_BAD_ARGUMENT); - dest = cupsGetDest(name,NULL,svc->num_dests,svc->dests); + /* if we are already connected, use that connection. */ + if (svc->connection == NULL) + if ((result = service_connect(svc, name)) != PAPI_OK) + return (result); - if(dest != NULL){ - //first add new destination to destinations list - svc->num_dests = cupsAddDests(name,NULL,svc->num_dests,&svc->dests); + ipp_initialize_request(svc, &request, OPID_PURGE_JOBS); + + ipp_initialize_operational_attributes(svc, &op, name, -1); + + papiAttributeListAddCollection(&request, PAPI_ATTR_REPLACE, + "operational-attributes-group", op); + papiAttributeListFree(op); + result = ipp_send_request(svc, request, &response); + papiAttributeListFree(request); + + op = NULL; + for (status = papiAttributeListGetCollection(response, &iter, + "job-attributes-group", &op); + status == PAPI_OK; + status = papiAttributeListGetCollection(response, &iter, + NULL, &op)) { + job_t *j = NULL; + + if ((j = calloc(1, sizeof (*j))) == NULL) + return (PAPI_TEMPORARY_ERROR); + + copy_attributes(&j->attributes, op); + op = NULL; + list_append(jobs, j); } + papiAttributeListFree(response); - result = papiPrinterModify(handle,name,attributes,printer); - return (result); } - papi_status_t -papiPrinterRemove(papi_service_t handle, char *name) +papiPrinterListJobs(papi_service_t handle, char *name, + char **requested_attrs, int type_mask, + int max_num_jobs, papi_job_t **jobs) { - papi_status_t result = PAPI_INTERNAL_ERROR; + papi_status_t status, result = PAPI_INTERNAL_ERROR; service_t *svc = handle; - printer_t *p = NULL; - cups_dest_t *dest = NULL; - - if ((svc == NULL) || (name == NULL) ) + papi_attribute_t **request = NULL, **op = NULL, **response = NULL; + void *iter = NULL; + + if ((svc == NULL) || (name == NULL)) return (PAPI_BAD_ARGUMENT); - dest = cupsGetDest(name,NULL,svc->num_dests,svc->dests); - - if(dest == NULL) - return (PAPI_NOT_FOUND); - - svc->num_dests = papiRemoveDest(name,NULL,svc->num_dests,&svc->dests); - - //commit changes - cupsSetDests(svc->num_dests,svc->dests); - - result = PAPI_OK; - + /* if we are already connected, use that connection. */ + if (svc->connection == NULL) + if ((result = service_connect(svc, name)) != PAPI_OK) + return (result); + + ipp_initialize_request(svc, &request, OPID_GET_JOBS); + + ipp_initialize_operational_attributes(svc, &op, name, -1); + + if (requested_attrs != NULL) { + int i; + + for (i = 0; requested_attrs[i] != NULL; i++) + papiAttributeListAddString(&op, PAPI_ATTR_APPEND, + "requested-attributes", requested_attrs[i]); + } + + papiAttributeListAddCollection(&request, PAPI_ATTR_REPLACE, + "operational-attributes-group", op); + papiAttributeListFree(op); + result = ipp_send_request(svc, request, &response); + papiAttributeListFree(request); + + op = NULL; + for (status = papiAttributeListGetCollection(response, &iter, + "job-attributes-group", &op); + status == PAPI_OK; + status = papiAttributeListGetCollection(response, &iter, + NULL, &op)) { + job_t *j = NULL; + + if ((j = calloc(1, sizeof (*j))) == NULL) + return (PAPI_TEMPORARY_ERROR); + + copy_attributes(&j->attributes, op); + op = NULL; + list_append(jobs, j); + } + papiAttributeListFree(response); + return (result); } +papi_attribute_t ** +papiPrinterGetAttributeList(papi_printer_t printer) +{ + papi_attribute_t **result = NULL; + printer_t *p = printer; + if (p != NULL) + result = p->attributes; - + return (result); +} Modified: branches/GSOC-2008/papi/source/libpapi-cups/service.c =================================================================== --- branches/GSOC-2008/papi/source/libpapi-cups/service.c 2008-06-30 20:27:00 UTC (rev 189) +++ branches/GSOC-2008/papi/source/libpapi-cups/service.c 2008-07-08 23:25:53 UTC (rev 190) @@ -34,18 +34,91 @@ #include <stdarg.h> #include <string.h> #include <alloca.h> -#include <cups/cups.h> +#include <libintl.h> #include <papi_impl.h> #include <config-site.h> -const char *cupsPasswordCB(const char *buf) +http_encryption_t +http_encryption_type(papi_encryption_t encryption) { - /*TODO Return password set by user*/ - return NULL; + switch (encryption) { + case PAPI_ENCRYPT_IF_REQUESTED: + return (HTTP_ENCRYPT_IF_REQUESTED); + case PAPI_ENCRYPT_REQUIRED: + return (HTTP_ENCRYPT_REQUIRED); + case PAPI_ENCRYPT_ALWAYS: + return (HTTP_ENCRYPT_ALWAYS); + case PAPI_ENCRYPT_NEVER: + return (HTTP_ENCRYPT_NEVER); + default: + ; /* this should log an error */ + } + + return (HTTP_ENCRYPT_NEVER); /* should never get here */ } papi_status_t +service_connect(service_t *svc, char *service_name) +{ + papi_status_t result = PAPI_OK; + int port = 631; + + if (svc == NULL) + return (PAPI_BAD_ARGUMENT); + + if (svc->connection != NULL) /* alread connected ? */ + return (PAPI_OK); + + if (svc->uri == NULL) + uri_from_string(service_name, &svc->uri); + + if ((service_name != NULL) && (svc->uri == NULL)) { + /* + * a name was supplied and it's not in URI form, we will + * try to use a "default" IPP service under the assumption + * that this is most likely a short-form printer name from + * from a papiPrinter*() or papiJob*() call and not from a + * papiServiceCreate() call. + */ + if ((service_name = getenv("PAPI_SERVICE_URI")) == NULL) { + char *cups; + + if ((cups = getenv("CUPS_SERVER")) != NULL) { + char buf[BUFSIZ]; + + snprintf(buf, sizeof (buf), + "ipp://%s/printers/", cups); + service_name = strdup(buf); + } + } + if (service_name == NULL) + service_name = DEFAULT_IPP_SERVICE_URI; + + uri_from_string(service_name, &svc->uri); + } + + if (svc->uri == NULL) + return (PAPI_NOT_POSSIBLE); + + if (svc->uri->port != NULL) + port = strtol(svc->uri->port, NULL, 10); + + svc->connection = httpConnectEncrypt(svc->uri->host, port, + http_encryption_type(svc->encryption)); + if (svc->connection == NULL) { + if (svc->uri != NULL) { + uri_free(svc->uri); + svc->uri = NULL; + } + result = PAPI_SERVICE_UNAVAILABLE; + } else if (service_name != NULL) + svc->name = strdup(service_name); + + return (result); +} + +papi_status_t papiServiceCreate(papi_service_t *handle, char *service_name, char *user_name, char *password, int (*authCB)(papi_service_t svc, void *app_data), @@ -53,6 +126,7 @@ { papi_status_t result = PAPI_NOT_POSSIBLE; service_t *svc = NULL; + char *encoding = getenv("HTTP_TRANSFER_ENCODING"); if (handle == NULL) return (PAPI_BAD_ARGUMENT); @@ -60,22 +134,29 @@ if ((*handle = svc = calloc(1, sizeof (*svc))) == NULL) return (PAPI_TEMPORARY_ERROR); - if (user_name != NULL){ + if (user_name != NULL) svc->user = strdup(user_name); - cupsSetUser(svc->user); - } if (password != NULL) svc->password = strdup(password); + svc->encryption = encryption; + if (authCB != NULL) + svc->authCB = authCB; + if (app_data != NULL) svc->app_data = app_data; - /* preload CUPS dests */ - svc->num_dests = cupsGetDests(&svc->dests); + if ((encoding != NULL) && (strcasecmp(encoding, "content-length") == 0)) + svc->transfer_encoding = TRANSFER_ENCODING_LENGTH; + else + svc->transfer_encoding = TRANSFER_ENCODING_CHUNKED; - result = PAPI_OK; + if (service_name != NULL) { + result = service_connect(svc, service_name); + } else + result = PAPI_OK; return (result); } @@ -94,8 +175,12 @@ free(svc->user); if (svc->password != NULL) free(svc->password); - if(svc->dests != NULL) - cupsFreeDests(svc->num_dests,svc->dests); + if (svc->uri != NULL) + uri_free(svc->uri); + if (svc->post != NULL) + free(svc->post); + if (svc->connection != NULL) + httpClose(svc->connection); free(handle); } @@ -112,10 +197,8 @@ if (svc->user != NULL) free(svc->user); svc->user = NULL; - if (user_name != NULL) { + if (user_name != NULL) svc->user = strdup(user_name); - cupsSetUser(svc->user); - } } else result = PAPI_BAD_ARGUMENT; @@ -145,8 +228,17 @@ papiServiceSetEncryption(papi_service_t handle, papi_encryption_t encryption) { - papi_status_t result = PAPI_OPERATION_NOT_SUPPORTED; - + papi_status_t result = PAPI_OK; + + if (handle != NULL) { + service_t *svc = handle; + + svc->encryption = encryption; + httpEncryption(svc->connection, + (http_encryption_t)svc->encryption); + } else + result = PAPI_BAD_ARGUMENT; + return (result); } @@ -154,8 +246,15 @@ papiServiceSetAuthCB(papi_service_t handle, int (*authCB)(papi_service_t svc, void *app_data)) { - papi_status_t result = PAPI_OPERATION_NOT_SUPPORTED; + papi_status_t result = PAPI_OK; + if (handle != NULL) { + service_t *svc = handle; + + svc->authCB = authCB; + } else + result = PAPI_BAD_ARGUMENT; + return (result); } @@ -222,6 +321,12 @@ { papi_encryption_t result = PAPI_ENCRYPT_NEVER; + if (handle != NULL) { + service_t *svc = handle; + + result = svc->encryption; + } + return (result); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2008-06-30 20:26:55
|
Revision: 189 http://openprinting.svn.sourceforge.net/openprinting/?rev=189&view=rev Author: allad Date: 2008-06-30 13:27:00 -0700 (Mon, 30 Jun 2008) Log Message: ----------- Printer API implemenation : -papiPrinterAdd() -papiPrinterRemove() -papiPrinterList() -papiPrinterModify() Modified Paths: -------------- branches/GSOC-2008/papi/ChangeLog branches/GSOC-2008/papi/source/bsd-sysv-commands/cancel.c branches/GSOC-2008/papi/source/bsd-sysv-commands/common.c branches/GSOC-2008/papi/source/bsd-sysv-commands/in.lpd.c branches/GSOC-2008/papi/source/bsd-sysv-commands/lp.c branches/GSOC-2008/papi/source/bsd-sysv-commands/lpstat.c branches/GSOC-2008/papi/source/libpapi-common/attribute.c branches/GSOC-2008/papi/source/libpapi-common/list.c branches/GSOC-2008/papi/source/libpapi-cups/papi_impl.h branches/GSOC-2008/papi/source/libpapi-cups/printer.c branches/GSOC-2008/papi/source/libpapi-cups/service.c branches/GSOC-2008/papi/source/libpapi-dynamic/nss.c branches/GSOC-2008/papi/source/libpapi-lpd/lpd-job.c Modified: branches/GSOC-2008/papi/ChangeLog =================================================================== --- branches/GSOC-2008/papi/ChangeLog 2008-06-30 17:24:54 UTC (rev 188) +++ branches/GSOC-2008/papi/ChangeLog 2008-06-30 20:27:00 UTC (rev 189) @@ -1,3 +1,25 @@ +2008-06-30 Norm Jacobs <Norm.Jacobs@Sun.COM> + resync with Solaris Nevada + * source/libpapi-dynamic/nss.c + fix some cycle detection + * source/libpapi-common/attribute.c + fix papiAttribute[To|From]String to be more + closely aligned with spec + * source/libpapi-common/list.c + fix memory issues with list_remove() + * source/bsd-sysv-commands/lpstat.c + make more like Solaris 10 lpstat + * source/bsd-sysv-commands/lp.c + fix several issues with handling options + * source/bsd-sysv-commands/in.lpd.c + cycle detection + * source/bsd-sysv-commands/cancel.c + make work like Solaris 10 + * source/bsd-sysv-commands/common.c + misc fixes for commands + * source/libpapi-lpd/lpd-job.c + deal with attribute list to rfc1179 translation better + 2007-07-31 Norm Jacobs <Norm.Jacobs@Sun.COM> resync with Solaris Nevada, use gethostname() for linux * source/libipp-listener/ipp-listener.c Modified: branches/GSOC-2008/papi/source/bsd-sysv-commands/cancel.c =================================================================== --- branches/GSOC-2008/papi/source/bsd-sysv-commands/cancel.c 2008-06-30 17:24:54 UTC (rev 188) +++ branches/GSOC-2008/papi/source/bsd-sysv-commands/cancel.c 2008-06-30 20:27:00 UTC (rev 189) @@ -20,12 +20,13 @@ */ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * */ #pragma ident "$Id$" +/* #pragma ident "@(#)cancel.c 1.2 08/06/06 SMI" */ #include <stdio.h> #include <stdlib.h> @@ -51,6 +52,49 @@ } int +cancel_jobs_for_user(char *user, papi_encryption_t encryption, char *pname) { + + papi_status_t status; + papi_service_t svc = NULL; + char **printers = NULL; + int i, exit_code; + + if (pname == NULL) { + status = papiServiceCreate(&svc, NULL, user, NULL, + cli_auth_callback, encryption, NULL); + printers = interest_list(svc); + papiServiceDestroy(svc); + } else { + list_append(&printers, strdup(pname)); + } + + if (printers == NULL) + exit(0); + + for (i = 0; printers[i] != NULL; i++) { + char *printer = printers[i]; + + status = papiServiceCreate(&svc, printer, user, NULL, + cli_auth_callback, encryption, NULL); + + if (status != PAPI_OK) { + fprintf(stderr, gettext( + "Failed to contact service for %s: %s\n"), + printer, verbose_papi_message(svc, status)); + exit(1); + } + exit_code = berkeley_cancel_request(svc, stdout, printer, 1, + &user); + + papiServiceDestroy(svc); + if (exit_code != 0) + break; + } + free(printers); + return (exit_code); +} + +int main(int ac, char *av[]) { int exit_code = 0; @@ -61,6 +105,9 @@ (void) setlocale(LC_ALL, ""); (void) textdomain("SUNW_OST_OSCMD"); + if (ac == 1) + usage(av[0]); + while ((c = getopt(ac, av, "Eu:")) != EOF) switch (c) { case 'E': @@ -83,11 +130,11 @@ (void) get_printer_id(av[c], &printer, &id); status = papiServiceCreate(&svc, printer, user, NULL, - cli_auth_callback, encryption, NULL); + cli_auth_callback, encryption, NULL); if (status != PAPI_OK) { - fprintf(stderr, gettext( - "Failed to contact service for %s: %s\n"), - printer, verbose_papi_message(svc, status)); + fprintf(stderr, + gettext("Failed to contact service for %s: %s\n"), + printer, verbose_papi_message(svc, status)); exit(1); } @@ -97,29 +144,55 @@ char *mesg = "cancelled"; status = papiJobCancel(svc, printer, id); - if (status != PAPI_OK) { + if (status == PAPI_NOT_AUTHORIZED) { + mesg = papiStatusString(status); + exit_code = 1; + } else if (status != PAPI_OK) { mesg = verbose_papi_message(svc, status); exit_code = 1; } fprintf(OUT, "%s-%d: %s\n", printer, id, mesg); + } else { /* it's a printer */ - status = papiPrinterPurgeJobs(svc, printer, &jobs); - if (status != PAPI_OK) { - fprintf(stderr, gettext("PurgeJobs %s: %s\n"), - printer, - verbose_papi_message(svc, status)); - exit_code = 1; - } + if (user == NULL) { - while ((jobs != NULL) && (*jobs != NULL)) - fprintf(OUT, "%s-%d: %s\n", printer, - papiJobGetId(*jobs++), "cancelled"); + /* Remove first job from printer */ - papiJobListFree(jobs); + status = papiPrinterListJobs(svc, printer, + NULL, NULL, 0, &jobs); + + if (status != PAPI_OK) { + fprintf(stderr, gettext( + "ListJobs %s: %s\n"), printer, + verbose_papi_message(svc, status)); + exit_code = 1; + } + + if (jobs != NULL && *jobs != NULL) { + char jobid[32]; + char *jid; + + snprintf(jobid, sizeof (jobid), "%u", + papiJobGetId(*jobs)); + + jid = jobid; + exit_code = berkeley_cancel_request(svc, + stdout, printer, 1, &jid); + + } + papiJobListFree(jobs); + + } else { + /* Purging user's print jobs */ + exit_code = cancel_jobs_for_user(user, + encryption, printer); + } } - papiServiceDestroy(svc); } + if (optind == ac) + exit_code = cancel_jobs_for_user(user, encryption, NULL); + return (exit_code); } Modified: branches/GSOC-2008/papi/source/bsd-sysv-commands/common.c =================================================================== --- branches/GSOC-2008/papi/source/bsd-sysv-commands/common.c 2008-06-30 17:24:54 UTC (rev 188) +++ branches/GSOC-2008/papi/source/bsd-sysv-commands/common.c 2008-06-30 20:27:00 UTC (rev 189) @@ -20,12 +20,13 @@ */ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * */ #pragma ident "$Id$" +/* #pragma ident "@(#)common.c 1.3 08/05/28 SMI" */ #include <stdio.h> #include <stdlib.h> @@ -191,6 +192,8 @@ (void) papiAttributeListGetInteger(list, NULL, "job-id", &id); + (void) papiAttributeListGetInteger(list, NULL, + "job-id-requested", &id); (void) papiAttributeListGetString(list, NULL, "job-originating-user-name", &user); (void) papiAttributeListGetString(list, NULL, @@ -236,16 +239,20 @@ papi_status_t status; papi_attribute_t **list = papiJobGetAttributeList(job); int id = 0; + int rid = 0; char *user = ""; char *mesg = gettext("cancelled"); papiAttributeListGetInteger(list, NULL, "job-id", &id); + papiAttributeListGetInteger(list, NULL, + "job-id-requested", &rid); papiAttributeListGetString(list, NULL, "job-originating-user-name", &user); /* if we are looking and it doesn't match, return early */ - if ((ac > 0) && (match_job(id, user, ac, av) < 0)) + if ((ac > 0) && (match_job(id, user, ac, av) < 0) && + (match_job(rid, user, ac, av) < 0)) return; status = papiJobCancel(svc, printer, id); @@ -265,7 +272,7 @@ char *pattrs[] = { "printer-name", "printer-state", "printer-state-reasons", NULL }; char *jattrs[] = { "job-name", "job-octets", "job-k-octets", "job-id", - "job-originating-user-name", + "job-originating-user-name", "job-id-requested", "job-originating-host-name", "number-of-intervening-jobs", NULL }; int num_jobs = 0; @@ -313,7 +320,8 @@ { papi_status_t status; papi_job_t *jobs = NULL; - char *jattrs[] = { "job-originating-user-name", "job-id", NULL }; + char *jattrs[] = { "job-originating-user-name", "job-id", + "job-id-requested", NULL }; status = papiPrinterListJobs(svc, dest, jattrs, PAPI_LIST_JOBS_ALL, 0, &jobs); Modified: branches/GSOC-2008/papi/source/bsd-sysv-commands/in.lpd.c =================================================================== --- branches/GSOC-2008/papi/source/bsd-sysv-commands/in.lpd.c 2008-06-30 17:24:54 UTC (rev 188) +++ branches/GSOC-2008/papi/source/bsd-sysv-commands/in.lpd.c 2008-06-30 20:27:00 UTC (rev 189) @@ -20,12 +20,13 @@ */ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * */ #pragma ident "$Id$" +/* #pragma ident "@(#)in.lpd.c 1.6 08/06/05 SMI" */ #include <stdio.h> #include <stdlib.h> @@ -33,12 +34,12 @@ #include <fcntl.h> #include <stdarg.h> #include <string.h> +#include <ctype.h> #include <errno.h> #include <syslog.h> #include <libintl.h> #include <pwd.h> #include <grp.h> -#include <sys/param.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/socket.h> @@ -66,7 +67,7 @@ socklen_t peer_len = sizeof (peer); int fd = fileno(fp); int error_num; - char myname[MAXHOSTNAMELEN], tmp_buf[INET6_ADDRSTRLEN]; + char *myname, tmp_buf[INET6_ADDRSTRLEN]; char *hostname; /* who is our peer ? */ @@ -78,12 +79,14 @@ } /* get their name or return a string containing their address */ +#if defined(HAVE_GETIPNODEBYNAME) if ((hp = getipnodebyaddr((const char *)&peer.sin6_addr, sizeof (struct in6_addr), AF_INET6, &error_num)) == NULL) { return (strdup(inet_ntop(peer.sin6_family, &peer.sin6_addr, tmp_buf, sizeof (tmp_buf)))); } +#endif /* is it "localhost" ? */ if (strcasecmp(hp->h_name, "localhost") == 0) @@ -91,9 +94,10 @@ /* duplicate the name because gethostbyXXXX() is not reentrant */ hostname = strdup(hp->h_name); - gethostname(myname, sizeof (myname)); + myname = localhostname(); /* is it from one of my addresses ? */ +#if defined(HAVE_GETIPNODEBYNAME) if ((hp = getipnodebyname(myname, AF_INET6, AI_ALL|AI_V4MAPPED, &error_num)) != NULL) { struct in6_addr **tmp = (struct in6_addr **)hp->h_addr_list; @@ -107,6 +111,7 @@ } } } +#endif /* It must be someone else */ return (hostname); @@ -306,14 +311,10 @@ papiAttributeListAddString(&list, PAPI_ATTR_EXCL, "job-hold-until", "indefinite"); - else if (strcasecmp(entry, "release") == 0) + else if (strcasecmp(entry, "immediate") == 0) papiAttributeListAddString(&list, PAPI_ATTR_EXCL, "job-hold-until", "no-hold"); - else if (strcasecmp(entry, "immediate") == 0) - papiAttributeListAddInteger(&list, - PAPI_ATTR_EXCL, - "job-priority", 100); else papiAttributeListAddString(&list, PAPI_ATTR_EXCL, @@ -323,19 +324,23 @@ papiAttributeListAddBoolean(&list, PAPI_ATTR_EXCL, "rfc-1179-mail", 1); break; - case 'P': /* Solaris page list */ - papiAttributeListAddString(&list, - PAPI_ATTR_EXCL, - "page-ranges", ++entry); + case 'P': { /* Solaris page list */ + char buf[BUFSIZ]; + + snprintf(buf, sizeof (buf), "page-ranges=%s", + ++entry); + papiAttributeListFromString(&list, + PAPI_ATTR_EXCL, buf); + } break; case 'q': { /* Solaris priority */ int i = atoi(optarg); - i = 99 * (39 - i) / 39 + 1; + i = 100 - (i * 2.5); if ((i < 1) || (i > 100)) i = 50; papiAttributeListAddInteger(&list, - PAPI_ATTR_EXCL, "priority", i); + PAPI_ATTR_EXCL, "job-priority", i); } break; case 'S': /* Solaris character set */ @@ -379,7 +384,8 @@ } static papi_status_t -submit_job(papi_service_t svc, FILE *ifp, char *printer, char *cf, char **files) +submit_job(papi_service_t svc, FILE *ifp, char *printer, int rid, char *cf, + char **files) { papi_attribute_t **list = NULL; papi_status_t status; @@ -395,6 +401,10 @@ "job-originating-host-name", host); free(host); } + if (rid > 0) { + papiAttributeListAddInteger(&list, PAPI_ATTR_EXCL, + "job-id-requested", rid); + } } status = papiJobSubmit(svc, printer, list, NULL, files, &job); @@ -498,6 +508,7 @@ papi_status_t status = PAPI_OK; char *file, **files = NULL; /* the job data files */ char *cf = NULL; + int rid = 0; char buf[BUFSIZ]; while (fgets(buf, sizeof (buf), ifp) != NULL) { @@ -513,12 +524,18 @@ cleanup(&files, &cf); break; case 0x02: { /* Receive control file */ + if (((cf = strchr(buf, ' ')) != NULL) && + (strlen(cf) > 4)) { + while ((*cf != NULL) && (isdigit(*cf) == 0)) + cf++; + rid = atoi(cf); + } cf = receive_control_file(svc, ifp, ofp, atoi(&buf[1])); if (cf == NULL) { cleanup(&files, &cf); return (PAPI_BAD_REQUEST); } else if (files != NULL) { - status = submit_job(svc, ifp, printer, cf, + status = submit_job(svc, ifp, printer, rid, cf, files); cleanup(&files, &cf); } @@ -541,7 +558,7 @@ } if ((cf != NULL) && (files != NULL)) - status = submit_job(svc, ifp, printer, cf, files); + status = submit_job(svc, ifp, printer, rid, cf, files); cleanup(&files, &cf); @@ -581,7 +598,7 @@ cyclical_service_check(char *svc_name) { papi_attribute_t **list; - char buf[BUFSIZ]; + char *myname = localhostname(); uri_t *uri = NULL; char *s = NULL; @@ -612,9 +629,8 @@ } /* is it the local host? */ - gethostname(buf, sizeof (buf)); if ((strcasecmp(uri->host, "localhost") != 0) && - (strcasecmp(uri->host, buf) != 0)) { + (strcasecmp(uri->host, myname) != 0)) { uri_free(uri); return (0); } Modified: branches/GSOC-2008/papi/source/bsd-sysv-commands/lp.c =================================================================== --- branches/GSOC-2008/papi/source/bsd-sysv-commands/lp.c 2008-06-30 17:24:54 UTC (rev 188) +++ branches/GSOC-2008/papi/source/bsd-sysv-commands/lp.c 2008-06-30 20:27:00 UTC (rev 189) @@ -20,12 +20,13 @@ */ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * */ #pragma ident "$Id$" +/* #pragma ident "@(#)lp.c 1.5 08/05/26 SMI" */ #include <stdio.h> #include <stdlib.h> @@ -87,22 +88,22 @@ papiAttributeListAddString(&list, PAPI_ATTR_EXCL, "job-hold-until", "indefinite"); - else if (strcasecmp(optarg, "release") == 0) + else if (strcasecmp(optarg, "immediate") == 0) papiAttributeListAddString(&list, PAPI_ATTR_EXCL, "job-hold-until", "no-hold"); - else if (strcasecmp(optarg, "immediate") == 0) - papiAttributeListAddInteger(&list, - PAPI_ATTR_EXCL, - "job-priority", 100); else papiAttributeListAddString(&list, PAPI_ATTR_EXCL, "job-hold-until", optarg); break; - case 'P': /* page list */ - papiAttributeListAddString(&list, PAPI_ATTR_EXCL, - "page-ranges", optarg); + case 'P': { /* page list */ + char buf[BUFSIZ]; + + snprintf(buf, sizeof (buf), "page-ranges=%s", optarg); + papiAttributeListFromString(&list, + PAPI_ATTR_EXCL, buf); + } break; case 'S': /* charset */ papiAttributeListAddString(&list, PAPI_ATTR_EXCL, @@ -154,14 +155,14 @@ case 'q': { /* priority */ int i = atoi(optarg); - i = 99 * (39 - i) / 39 + 1; + i = 100 - (i * 2.5); if ((i < 1) || (i > 100)) { fprintf(stderr, gettext( "priority must be between 0 and 39.\n")); exit(1); } papiAttributeListAddInteger(&list, PAPI_ATTR_EXCL, - "priority", i); + "job-priority", i); } break; case 'r': /* "raw" mode */ Modified: branches/GSOC-2008/papi/source/bsd-sysv-commands/lpstat.c =================================================================== --- branches/GSOC-2008/papi/source/bsd-sysv-commands/lpstat.c 2008-06-30 17:24:54 UTC (rev 188) +++ branches/GSOC-2008/papi/source/bsd-sysv-commands/lpstat.c 2008-06-30 20:27:00 UTC (rev 189) @@ -20,12 +20,13 @@ */ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * */ #pragma ident "$Id$" +/* #pragma ident "@(#)lpstat.c 1.7 08/05/21 SMI" */ #include <stdio.h> #include <stdlib.h> @@ -396,6 +397,16 @@ printf(gettext("\tDescription: %s\n"), str); str = ""; + iter = NULL; + (void) papiAttributeListGetString(attrs, &iter, + "lpsched-printer-type", &str); + printf(gettext("\tPrinter types: %s"), str); + while (papiAttributeListGetString(attrs, &iter, NULL, &str) + == PAPI_OK) + printf(", %s", str); + printf("\n"); + + str = ""; (void) papiAttributeListGetString(attrs, NULL, "lpsched-dial-info", &str); printf(gettext("\tConnection: %s\n"), @@ -475,10 +486,16 @@ str = ""; (void) papiAttributeListGetString(attrs, NULL, "job-sheets-supported", &str); - printf(gettext("\tBanner %s\n"), - (strcasecmp(str, "none") == 0 ? - gettext("not required") : gettext("required"))); + if ((strcasecmp(str, "none")) == 0) + str = gettext("page never printed"); + else if (strcasecmp(str, "optional") == 0) + str = gettext("not required"); + else + str = gettext("required"); + printf(gettext("\tBanner %s\n"), str); + + str = ""; iter = NULL; (void) papiAttributeListGetString(attrs, &iter, Modified: branches/GSOC-2008/papi/source/libpapi-common/attribute.c =================================================================== --- branches/GSOC-2008/papi/source/libpapi-common/attribute.c 2008-06-30 17:24:54 UTC (rev 188) +++ branches/GSOC-2008/papi/source/libpapi-common/attribute.c 2008-06-30 20:27:00 UTC (rev 189) @@ -20,21 +20,25 @@ */ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * */ #pragma ident "$Id$" +/* #pragma ident "@(#)attribute.c 1.3 08/05/26 SMI" */ + /*LINTLIBRARY*/ #include <stdio.h> #include <stdlib.h> #include <stdarg.h> #include <string.h> +#include <ctype.h> #include <alloca.h> #include <papi.h> +#include <regex.h> static void papiAttributeFree(papi_attribute_t *attribute); @@ -615,335 +619,241 @@ return (status); } -/* - * Description: The given string contains one or more attributes, in the - * following form: - * "aaaa=true bbbbb=1 ccccc=abcd" - * extract the next attribute from that string; the 'next' - * parameter should be set to zero to extract the first attribute - * in the string. - * - */ +/* The string is modified by this call */ static char * -_getNextAttr(char *string, int *next) - +regvalue(regmatch_t match, char *string) { char *result = NULL; - char *start = (char *)string + *next; - char *nl = NULL; - char *sp = NULL; - char *tab = NULL; - char *val = NULL; - int len = 0; + if (match.rm_so != match.rm_eo) { + result = string + match.rm_so; + *(result + (match.rm_eo - match.rm_so)) = '\0'; + } + return (result); +} - if ((string != NULL) && (*start != '\0')) { - while ((*start == ' ') || (*start == '\t') || (*start == '\n')) - { - start++; - } - nl = strchr(start, '\n'); - sp = strchr(start, ' '); - tab = strchr(start, '\t'); +static papi_attribute_value_type_t +_process_value(char *string, char ***parts) +{ + int i; + static struct { + papi_attribute_value_type_t type; + size_t vals; + char *expression; + int compiled; + regex_t re; + } types[] = { + { PAPI_BOOLEAN, 1, "^(true|false|yes|no)$", 0 }, + { PAPI_COLLECTION, 1, "^\\{(.+)\\}$", 0 }, + /* PAPI_DATETIME is unsupported, too much like an integer */ + { PAPI_INTEGER, 1, "^([+-]{0,1}[[:digit:]]+)$", 0 }, + { PAPI_RANGE, 3, "^([[:digit:]]+)-([[:digit:]]+)$", 0 }, + { PAPI_RESOLUTION, 4, "^([[:digit:]]+)x([[:digit:]]+)dp(i|c)$", + 0 }, + }; + regmatch_t matches[4]; - val = strchr(start, '='); + for (i = 0; i < 5; i++) { + int j; - if ((val != NULL) && ((val[1] == '"') || (val[1] == '\''))) { - val = strchr(&val[2], val[1]); - if (val != NULL) { - nl = strchr(&val[1], '\n'); - sp = strchr(&val[1], ' '); - tab = strchr(&val[1], '\t'); - } + if (types[i].compiled == 0) { + (void) regcomp(&(types[i].re), types[i].expression, + REG_EXTENDED|REG_ICASE); + types[i].compiled = 1; } + if (regexec(&(types[i].re), string, (size_t)types[i].vals, + matches, 0) == REG_NOMATCH) + continue; - if ((nl != NULL) && - ((sp == NULL) || ((sp != NULL) && (nl < sp))) && - ((tab == NULL) || ((tab != NULL) && (nl < tab)))) { - len = nl-start; - } else if ((sp != NULL) && (tab != NULL) && (sp > tab)) { - len = tab-start; - } else if ((sp != NULL) && (sp != NULL)) { - len = sp-start; - } else if ((tab != NULL) && (tab != NULL)) { - len = tab-start; - } + for (j = 0 ; j < types[i].vals; j++) + list_append(parts, regvalue(matches[j], string)); + return (types[i].type); + } - if (len == 0) { - len = strlen(start); - } + list_append(parts, string); + return (PAPI_STRING); +} - if (len > 0) { - result = (char *)malloc(len+1); - if (result != NULL) { - strncpy(result, start, len); - result[len] = '\0'; - *next = (start-string)+len; - } +static void +_add_attribute_value(papi_attribute_value_t ***list, + papi_attribute_value_type_t type, + papi_attribute_value_type_t dtype, char **parts) +{ + papi_attribute_value_t *value = calloc(1, sizeof (*value)); + + switch(type) { + case PAPI_STRING: + value->string = strdup(parts[0]); + list_append(list, value); + break; + case PAPI_BOOLEAN: + value->boolean = PAPI_TRUE; + if ((strcasecmp(parts[0], "false") == 0) || + (strcasecmp(parts[0], "no") == 0)) + value->boolean = PAPI_FALSE; + list_append(list, value); + break; + case PAPI_INTEGER: + value->integer = atoi(parts[0]); + list_append(list, value); + break; + case PAPI_RANGE: + if (dtype == PAPI_INTEGER) + value->range.lower = value->range.upper + = atoi(parts[0]); + else if (dtype == PAPI_RANGE) { + value->range.lower = atoi(parts[1]); + value->range.upper = atoi(parts[2]); } + list_append(list, value); + break; + case PAPI_RESOLUTION: + value->resolution.xres = atoi(parts[1]); + value->resolution.yres = atoi(parts[2]); + if (parts[3][0] == 'i') + value->resolution.units = PAPI_RES_PER_INCH; + else + value->resolution.units = PAPI_RES_PER_CM; + list_append(list, value); + break; + case PAPI_COLLECTION: + papiAttributeListFromString(&(value->collection), 0, parts[0]); + list_append(list, value); + break; } +} - return (result); -} /* _getNextAttr() */ - - -/* - * Description: Parse the given attribute string value and transform it into - * the papi_attribute_value_t in the papi_attribute_t structure. - * - */ - static papi_status_t -_parseAttrValue(char *value, papi_attribute_t *attr) - +_papiAttributeFromStrings(papi_attribute_t ***list, int flags, + char *key, char **values) { + int i; papi_status_t result = PAPI_OK; - int len = 0; - int i = 0; - char *papiString = NULL; - char *tmp1 = NULL; - char *tmp2 = NULL; - char *tmp3 = NULL; - papi_attribute_value_t **avalues = NULL; + papi_attribute_t *attr = calloc(1, sizeof (*attr)); - avalues = malloc(sizeof (papi_attribute_value_t *) * 2); - if (avalues == NULL) { - result = PAPI_TEMPORARY_ERROR; - return (result); - } - avalues[0] = malloc(sizeof (papi_attribute_value_t)); - avalues[1] = NULL; - if (avalues[0] == NULL) { - free(avalues); - result = PAPI_TEMPORARY_ERROR; - return (result); - } + /* these are specified in the papi spec as ranges */ + char *ranges[] = { "copies-supported", "job-impressions-supported", + "job-k-octets-supported", + "job-media-sheets-supported", "page-ranges", + NULL }; + if ((attr == NULL) || ((attr->name = strdup(key)) == NULL)) + return (PAPI_TEMPORARY_ERROR); -/* - * TODO - need to sort out 'resolution', 'dateandtime' & 'collection' values - */ - if ((value != NULL) && (strlen(value) > 0) && (attr != NULL)) { + attr->type = PAPI_METADATA; + /* these are known ranges */ + for (i = 0; ranges[i] != NULL; i++) + if (strcasecmp(attr->name, ranges[i]) == 0) { + attr->type = PAPI_RANGE; + break; + } - len = strlen(value); - if ((len >= 2) && (((value[0] == '"') && - (value[len-1] == '"')) || ((value[0] == '\'') && - (value[len-1] == '\'')))) { - /* string value */ - attr->type = PAPI_STRING; + if (values != NULL) { + papi_attribute_value_t **vals = NULL; - papiString = strdup(value+1); - if (papiString != NULL) { - papiString[strlen(papiString)-1] = '\0'; - avalues[0]->string = papiString; - } else { - result = PAPI_TEMPORARY_ERROR; - } - } else if ((strcasecmp(value, "true") == 0) || - (strcasecmp(value, "YES") == 0)) { - /* boolean = true */ - attr->type = PAPI_BOOLEAN; - avalues[0]->boolean = PAPI_TRUE; - } else if ((strcasecmp(value, "false") == 0) || - (strcasecmp(value, "NO") == 0)) { - /* boolean = false */ - attr->type = PAPI_BOOLEAN; - avalues[0]->boolean = PAPI_FALSE; - } else { - /* is value an integer or a range ? */ + for (i = 0; values[i] != NULL; i++) { + papi_attribute_value_type_t dtype; + char **parts = NULL; - i = 0; - attr->type = PAPI_INTEGER; - tmp1 = strdup(value); - while (((value[i] >= '0') && (value[i] <= '9')) || - (value[i] == '-')) { - if (value[i] == '-') { - tmp1[i] = '\0'; - tmp2 = &tmp1[i+1]; - attr->type = PAPI_RANGE; - } - - i++; - } - - if (strlen(value) == i) { - if (attr->type == PAPI_RANGE) { - avalues[0]->range.lower = atoi(tmp1); - avalues[0]->range.upper = atoi(tmp2); - } else { - avalues[0]->integer = atoi(value); - } - } else { - /* is value a resolution ? */ - i = 0; - attr->type = PAPI_INTEGER; - tmp1 = strdup(value); - while (((value[i] >= '0') && - (value[i] <= '9')) || - (value[i] == 'x')) { - if (value[i] == 'x') { - tmp1[i] = '\0'; - if (attr->type == PAPI_INTEGER) - { - tmp2 = &tmp1[i+1]; - attr->type = - PAPI_RESOLUTION; - } else { - tmp3 = &tmp1[i+1]; - } - } - - i++; - } - - if (strlen(value) == i) { - if (attr->type == PAPI_RESOLUTION) { - avalues[0]->resolution.xres = - atoi(tmp1); - avalues[0]->resolution.yres = - atoi(tmp2); - if (tmp3 != NULL) { - avalues[0]-> - resolution.units = - atoi(tmp3); - } else { - avalues[0]-> - resolution.units = 0; - } - } - } - - if (attr->type != PAPI_RESOLUTION) { - attr->type = PAPI_STRING; - avalues[0]->string = strdup(value); - if (avalues[0]->string == NULL) { - result = PAPI_TEMPORARY_ERROR; - } - } - } - free(tmp1); + dtype = _process_value(values[i], &parts); + if (attr->type == PAPI_METADATA) + attr->type = dtype; + _add_attribute_value(&vals, attr->type, dtype, parts); + free(parts); } - - } else { - result = PAPI_BAD_ARGUMENT; + attr->values = vals; } - if (result != PAPI_OK) { - i = 0; - while (avalues[i] != NULL) { - free(avalues[i]); - i++; - } - free(avalues); - } else { - attr->values = avalues; - } + list_append(list, attr); return (result); -} /* _parseAttrValue() */ +} - -/* - * Description: Parse the given attribute string and transform it into the - * papi_attribute_t structure. - * - */ - static papi_status_t -_parseAttributeString(char *attrString, papi_attribute_t *attr) - +_parse_attribute_list(papi_attribute_t ***list, int flags, char *string) { papi_status_t result = PAPI_OK; - char *string = NULL; - char *p = NULL; - papi_attribute_value_t **avalues = NULL; + char *ptr; - if ((attrString != NULL) && (strlen(attrString) >= 3) && - (attr != NULL)) { - attr->name = NULL; - string = strdup(attrString); - if (string != NULL) { - p = strchr(string, '='); - if (p != NULL) { - *p = '\0'; - attr->name = string; - p++; /* pointer to value */ + if ((list == NULL) || (string == NULL)) + return (PAPI_BAD_ARGUMENT); - result = _parseAttrValue(p, attr); - } else { - char value; - /* boolean - no value so assume 'true' */ - if (strncasecmp(string, "no", 2) == 0) { - string += 2; - value = PAPI_FALSE; - } else - value = PAPI_TRUE; + if ((ptr = strdup(string)) == NULL) + return (PAPI_TEMPORARY_ERROR); - attr->name = string; - attr->type = PAPI_BOOLEAN; + while ((*ptr != '\0') && (result == PAPI_OK)) { + char *key, **values = NULL; - avalues = malloc( - sizeof (papi_attribute_value_t *) * 2); - if (avalues == NULL) { - result = PAPI_TEMPORARY_ERROR; + /* strip any leading whitespace */ + while (isspace(*ptr) != 0) + ptr++; + + /* Get the name: name[=value] */ + key = ptr; + while ((*ptr != '\0') && (*ptr != '=') && (isspace(*ptr) == 0)) + ptr++; + + if (*ptr == '=') { + *ptr++ = '\0'; + + while ((*ptr != '\0') && (isspace(*ptr) == 0)) { + char *value = ptr; + + if ((*ptr == '\'') || (*ptr == '"')) { + char q = *ptr++; + + /* quoted string value */ + while ((*ptr != '\0') && (*ptr != q)) + ptr++; + if (*ptr == q) + ptr++; + } else if (*ptr == '{') { + /* collection */ + while ((*ptr != '\0') && (*ptr != '}')) + ptr++; + if (*ptr == '}') + ptr++; } else { - avalues[0] = malloc( - sizeof (papi_attribute_value_t)); - avalues[1] = NULL; - if (avalues[0] == NULL) { - free(avalues); - result = PAPI_TEMPORARY_ERROR; - } else { - avalues[0]->boolean = value; - attr->values = avalues; - } + /* value */ + while ((*ptr != '\0') && + (*ptr != ',') && + (isspace(*ptr) == 0)) + ptr++; } + if (*ptr == ',') + *ptr++ = '\0'; + list_append(&values, value); } + } else { /* boolean "[no]key" */ + char *value = "true"; + + if (strncasecmp(key, "no", 2) == 0) { + key += 2; + value = "false"; + } + list_append(&values, value); } - } else { - result = PAPI_BAD_ARGUMENT; + if (*ptr != '\0') + *ptr++ = '\0'; + + result = _papiAttributeFromStrings(list, flags, key, values); + free(values); } return (result); -} /* _parseAttributeString() */ +} - papi_status_t papiAttributeListFromString(papi_attribute_t ***attrs, int flags, char *string) { papi_status_t result = PAPI_OK; - int next = 0; - char *attrString = NULL; - papi_attribute_t attr; if ((attrs != NULL) && (string != NULL) && ((flags & ~(PAPI_ATTR_APPEND+PAPI_ATTR_REPLACE+PAPI_ATTR_EXCL)) == 0)) { - attrString = _getNextAttr(string, &next); - while ((result == PAPI_OK) && (attrString != NULL)) { - result = _parseAttributeString(attrString, &attr); - if ((result == PAPI_OK) && (attr.name != NULL)) { - /* add this attribute to the list */ - if ((attr.values != NULL) && - (attr.values[0] != NULL)) { - result = papiAttributeListAddValue( - attrs, PAPI_ATTR_APPEND, - attr.name, attr.type, - attr.values[0]); - free(attr.values[0]); - free(attr.values); - } else { - result = PAPI_TEMPORARY_ERROR; - } - } - free(attrString); - - attrString = _getNextAttr(string, &next); - } - } - else - { + result = _parse_attribute_list(attrs, flags, string); + } else { result = PAPI_BAD_ARGUMENT; } @@ -957,8 +867,18 @@ papi_attribute_value_t **values = attribute->values; int rc, i; - strlcat(buffer, attribute->name, buflen); - strlcat(buffer, "=", buflen); + if ((attribute->type == PAPI_BOOLEAN) && (values[1] == NULL)) { + if (values[0]->boolean == PAPI_FALSE) { + if (isupper(attribute->name[0]) == 0) + strlcat(buffer, "no", buflen); + else + strlcat(buffer, "No", buflen); + } + rc = strlcat(buffer, attribute->name, buflen); + } else { + strlcat(buffer, attribute->name, buflen); + rc = strlcat(buffer, "=", buflen); + } if (values == NULL) return (PAPI_OK); @@ -977,14 +897,20 @@ } break; case PAPI_BOOLEAN: - rc = strlcat(buffer, (values[i]->boolean ? "true" : - "false"), buflen); + if (values[1] != NULL) + rc = strlcat(buffer, (values[i]->boolean ? + "true" : "false"), buflen); break; case PAPI_RANGE: { char string[24]; - snprintf(string, sizeof (string), "%d-%d", - values[i]->range.lower, values[i]->range.upper); + if (values[i]->range.lower == values[i]->range.upper) + snprintf(string, sizeof (string), "%d", + values[i]->range.lower); + else + snprintf(string, sizeof (string), "%d-%d", + values[i]->range.lower, + values[i]->range.upper); rc = strlcat(buffer, string, buflen); } break; @@ -1011,18 +937,9 @@ break; case PAPI_COLLECTION: { char *string = alloca(buflen); -#ifdef DEBUG - char prefix[256]; - snprintf(prefix, sizeof (prefix), "%s %s(%d) ", delim, - attribute->name, i); - papiAttributeListToString(values[i]->collection, - prefix, string, buflen); -#else - papiAttributeListToString(values[i]->collection, delim, string, buflen); -#endif rc = strlcat(buffer, string, buflen); } break; @@ -1059,9 +976,6 @@ if (!delim) delim = " "; -#ifdef DEBUG - strlcat(buffer, delim, buflen); -#endif for (i = 0; ((attrs[i] != NULL) && (status == PAPI_OK)); i++) { status = papiAttributeToString(attrs[i], delim, buffer, buflen); if (attrs[i+1] != NULL) Modified: branches/GSOC-2008/papi/source/libpapi-common/list.c =================================================================== --- branches/GSOC-2008/papi/source/libpapi-common/list.c 2008-06-30 17:24:54 UTC (rev 188) +++ branches/GSOC-2008/papi/source/libpapi-common/list.c 2008-06-30 20:27:00 UTC (rev 189) @@ -20,13 +20,15 @@ */ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * */ #pragma ident "$Id$" +/* #pragma ident "@(#)list.c 1.4 08/05/08 SMI" */ + /*LINTLIBRARY*/ #include <stdlib.h> @@ -35,6 +37,8 @@ static int __list_increment = 16; +#define LIST_SIZE(x) ((((x) / __list_increment) + 1) * __list_increment) + int list_append(void ***list, void *item) { @@ -48,14 +52,14 @@ if (item != NULL) { if (*list == NULL) *list = (void **)calloc(__list_increment, - sizeof (void *)); + sizeof (void *)); - for (count = 0; (*list)[count] != NULL; count++); + for (count = 0; (*list)[count] != NULL; count++) + ; if ((count + 1) % __list_increment == 0) { /* expand the list */ void **new_list = NULL; - int new_size = (((count + 1) / __list_increment) + 1) * - __list_increment; + int new_size = LIST_SIZE(count + 1); new_list = (void **)calloc(new_size, sizeof (void *)); if (new_list == NULL) @@ -83,9 +87,9 @@ list_concatenate(void ***result, void **list2) { void **list1; - int size1 = 0, - size2 = 0, - new_size = 0; + int size1 = 0; + int size2 = 0; + int new_size = 0; if ((result == NULL) || ((*result == NULL) && (list2 == NULL))) { errno = EINVAL; @@ -95,15 +99,16 @@ list1 = *result; if (list1 != NULL) - for (size1 = 0; list1[size1] != NULL; size1++); + for (size1 = 0; list1[size1] != NULL; size1++) + ; if (list2 != NULL) - for (size2 = 0; list2[size2] != NULL; size2++); + for (size2 = 0; list2[size2] != NULL; size2++) + ; /* list1 + list2 padded to a multiple of _list_increment */ - new_size = ((size1 + size2)/__list_increment + 2) * __list_increment; + new_size = LIST_SIZE(size1 + size2); - if ((*result = (void **)calloc((new_size), sizeof (void *))) - != NULL) { + if ((*result = (void **)calloc((new_size), sizeof (void *))) != NULL) { int count = 0; if (list1 != NULL) @@ -138,33 +143,35 @@ void list_remove(void ***list, void *item) { - int i, count; - void **tmp = NULL; + int i = 0, count; if ((list == NULL) || (*list == NULL) || (item == NULL)) return; - for (count = 0; (*list)[count] != NULL; count++); + /* size the original list */ + for (count = 0; (*list)[count] != NULL; count++) + if ((*list)[count] == item) { /* mark the location of item */ + i = count; + item = NULL; + } - if (count > 0) { - int new_size = (((count + 1) / __list_increment) + 1) * - __list_increment; + /* if found, remove it */ + if (item == NULL) { + /* shift the list over the item */ + for (++i; ((*list)[i] != NULL); i++) + (*list)[i-1] = (*list)[i]; + (*list)[i-1] = NULL; + } - if ((tmp = (void **)calloc(new_size, sizeof (void *))) != NULL) - tmp = *list; + /* if found, removed, and list should shrink, shrink it */ + if ((item == NULL) && (LIST_SIZE(i) < LIST_SIZE(count))) { + void **tmp = (void **)calloc(LIST_SIZE(i), sizeof (void *)); - /* copy up to item */ - for (i = 0; (((*list)[i] != NULL) && ((*list)[i] != item)); i++) - tmp[i] = (*list)[i]; - /* copy after item */ - if ((*list)[i] == item) - for (++i; ((*list)[i] != NULL); i++) - tmp[i-1] = (*list)[i]; + if (tmp != NULL) { + for (i = 0; (*list)[i] != NULL; i++) + tmp[i] = (*list)[i]; + free(*list); + *list = tmp; + } } - - /* replace the list */ - if (tmp != *list) { - free(*list); - *list = tmp; - } } Modified: branches/GSOC-2008/papi/source/libpapi-cups/papi_impl.h =================================================================== --- branches/GSOC-2008/papi/source/libpapi-cups/papi_impl.h 2008-06-30 17:24:54 UTC (rev 188) +++ branches/GSOC-2008/papi/source/libpapi-cups/papi_impl.h 2008-06-30 20:27:00 UTC (rev 189) @@ -59,7 +59,7 @@ char *user; char *password; void *app_data; - int numDests; + int num_dests; cups_dest_t *dests; } service_t; Modified: branches/GSOC-2008/papi/source/libpapi-cups/printer.c =================================================================== --- branches/GSOC-2008/papi/source/libpapi-cups/printer.c 2008-06-30 17:24:54 UTC (rev 188) +++ branches/GSOC-2008/papi/source/libpapi-cups/printer.c 2008-06-30 20:27:00 UTC (rev 189) @@ -106,7 +106,7 @@ return PAPI_OPERATION_NOT_SUPPORTED; } - for(i=0;i< svc->numDests;i++){ + for(i=0;i< svc->num_dests;i++){ /*filter if needed*/ if(filter_cups_printer(svc->dests+i,filter) == 0){ @@ -172,7 +172,7 @@ if ((svc == NULL) || (name == NULL) || (printer == NULL)) return (PAPI_BAD_ARGUMENT); - dest = cupsGetDest(name,NULL,svc->numDests,svc->dests); + dest = cupsGetDest(name,NULL,svc->num_dests,svc->dests); if(dest == NULL){ return PAPI_NOT_FOUND; //named dest not found @@ -210,3 +210,120 @@ return (result); } + +papi_status_t +papiPrinterModify(papi_service_t handle, char *name, + papi_attribute_t **attributes, papi_printer_t *printer) +{ + papi_status_t result = PAPI_INTERNAL_ERROR; + service_t *svc = handle; + printer_t *p = NULL; + papi_attribute_t **request = NULL, **op = NULL, **response = NULL; + cups_dest_t *dest = NULL; + int i = 0; + + if ((svc == NULL) || (name == NULL) || (printer == NULL)) + return (PAPI_BAD_ARGUMENT); + + dest = cupsGetDest(name,NULL,svc->num_dests,svc->dests); + + if(dest == NULL){ + return PAPI_NOT_FOUND; //named dest not found + } + + for(i = 0; attributes[i] != NULL; i++){ + char *value = (char *)cupsGetOption(attributes[i]->name, + dest->num_options,dest->options); + if(value != NULL) { + //the attribute already existe. remove it first + //(so that we can add it later on with the new value) + dest->num_options = cupsRemoveOption(attributes[i]->name, + dest->num_options,&dest->options); + } + + //if it is not a DELETE attribute, then add it now with the new + //value + if(attributes[i]->type == PAPI_METADATA + && attributes[i]->values[0]->metadata != PAPI_DELETE){ + char buffer[256]; + papiAttributeToString (attributes[i]," ", + buffer,256); + dest->num_options = cupsAddOption(attributes[i]->name,buffer, + dest->num_options,&dest->options); + } + + } + + //now commit changes + cupsSetDests(svc->num_dests,svc->dests); + + if ((*printer = p = calloc(1, sizeof (*p))) == NULL) + return (PAPI_TEMPORARY_ERROR); + + p->dest = dest; + + result = PAPI_OK; + + return (result); +} + + +/*Add a new Printer with the given attributes. + *If a printer with the same name already exists, + *simply update its attributes + */ +papi_status_t +papiPrinterAdd(papi_service_t handle, char *name, + papi_attribute_t **attributes, papi_printer_t *printer) +{ + papi_status_t result = PAPI_INTERNAL_ERROR; + service_t *svc = handle; + printer_t *p = NULL; + papi_attribute_t **request = NULL, **op = NULL, **response = NULL; + cups_dest_t *dest = NULL; + + if ((svc == NULL) || (name == NULL) || (printer == NULL)) + return (PAPI_BAD_ARGUMENT); + + dest = cupsGetDest(name,NULL,svc->num_dests,svc->dests); + + if(dest != NULL){ + //first add new destination to destinations list + svc->num_dests = cupsAddDests(name,NULL,svc->num_dests,&svc->dests); + } + + result = papiPrinterModify(handle,name,attributes,printer); + + return (result); +} + + +papi_status_t +papiPrinterRemove(papi_service_t handle, char *name) +{ + papi_status_t result = PAPI_INTERNAL_ERROR; + service_t *svc = handle; + printer_t *p = NULL; + cups_dest_t *dest = NULL; + + if ((svc == NULL) || (name == NULL) ) + return (PAPI_BAD_ARGUMENT); + + dest = cupsGetDest(name,NULL,svc->num_dests,svc->dests); + + if(dest == NULL) + return (PAPI_NOT_FOUND); + + svc->num_dests = papiRemoveDest(name,NULL,svc->num_dests,&svc->dests); + + //commit changes + cupsSetDests(svc->num_dests,svc->dests); + + result = PAPI_OK; + + return (result); +} + + + + Modified: branches/GSOC-2008/papi/source/libpapi-cups/service.c =================================================================== --- branches/GSOC-2008/papi/source/libpapi-cups/service.c 2008-06-30 17:24:54 UTC (rev 188) +++ branches/GSOC-2008/papi/source/libpapi-cups/service.c 2008-06-30 20:27:00 UTC (rev 189) @@ -73,7 +73,7 @@ svc->app_data = app_data; /* preload CUPS dests */ - svc->numDests = cupsGetDests(&svc->dests); + svc->num_dests = cupsGetDests(&svc->dests); result = PAPI_OK; @@ -95,7 +95,7 @@ if (svc->password != NULL) free(svc->password); if(svc->dests != NULL) - cupsFreeDests(svc->numDests,svc->dests); + cupsFreeDests(svc->num_dests,svc->dests); free(handle); } Modified: branches/GSOC-2008/papi/source/libpapi-dynamic/nss.c =================================================================== --- branches/GSOC-2008/papi/source/libpapi-dynamic/nss.c 2008-06-30 17:24:54 UTC (rev 188) +++ branches/GSOC-2008/papi/source/libpapi-dynamic/nss.c 2008-06-30 20:27:00 UTC (rev 189) @@ -20,14 +20,14 @@ */ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * */ -/* Id: nss.c 180 2006-07-20 17:33:02Z njacobs $ */ +#pragma ident "Id: nss.c 180 2006-07-20 17:33:02Z njacobs $" +/* #pragma ident "@(#)nss.c 1.6 08/05/28 SMI" */ - #include <stdio.h> #include <stdlib.h> #include <unistd.h> @@ -44,6 +44,9 @@ #include <nss_dbdefs.h> #endif #include <config-site.h> +#if defined(__sun) && defined(__SVR4) +#include <sys/systeminfo.h> +#endif static char * @@ -194,7 +197,7 @@ return (1); /* is it the {nodename} */ - gethostname(hostname, sizeof (hostname)); + sysinfo(SI_HOSTNAME, hostname, sizeof (hostname)); if (strncasecmp(host, hostname, strlen(hostname)) == 0) return (1); @@ -264,9 +267,14 @@ if (attribute != NULL) /* we have what we need, return */ return; - /* do we have a printer-uri to rename */ + /* do we have a printer-uri (in URI form) to rename */ attribute = papiAttributeListFind(*list, "printer-uri"); - if (attribute != NULL) { /* rename it in place and return */ + if ((attribute != NULL) && + (attribute->type == PAPI_STRING) && + (attribute->values != NULL) && + (attribute->values[0]->string != NULL) && + (strstr(attribute->values[0]->string, "://") != NULL)) { + /* rename it in place and return */ free(attribute->name); attribute->name = strdup("printer-uri-supported"); return; Modified: branches/GSOC-2008/papi/source/libpapi-lpd/lpd-job.c =================================================================== --- branches/GSOC-2008/papi/source/libpapi-lpd/lpd-job.c 2008-06-30 17:24:54 UTC (rev 188) +++ branches/GSOC-2008/papi/source/libpapi-lpd/lpd-job.c 2008-06-30 20:27:00 UTC (rev 189) @@ -20,12 +20,13 @@ */ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * */ #pragma ident "$Id$" +/* #pragma ident "@(#)lpd-job.c 1.5 08/05/26 SMI" */ #define __EXTENSIONS__ /* for strtok_r() */ #include <stdio.h> @@ -282,6 +283,45 @@ return (status); } +static char * +unused_attributes(papi_attribute_t **list, papi_attribute_t **used) +{ + char *result = NULL; + char **names = NULL; + int i; + + if ((list == NULL) || (used == NULL)) + return (NULL); + + for (i = 0; used[i] != NULL; i++) + list_append(&names, used[i]->name); + + if (names != NULL) { + papi_attribute_t **unused = NULL; + + /* add these to the list of things to ignore */ + list_append(&names, "document-format"); + list_append(&names, "copies"); + + split_and_copy_attributes(names, list, NULL, &unused); + if (unused != NULL) { + size_t size = 0; + + do { + size += 1024; + if (result != NULL) + free(result); + result = calloc(1, size); + } while (papiAttributeListToString(unused, " ", + result, size) != PAPI_OK); + papiAttributeListFree(unused); + } + free(names); + } + + return (result); +} + /* * lpd_add_svr4_attributes * Solaris 2.x LP - BSD protocol extensions @@ -290,6 +330,7 @@ lpd_add_svr4_attributes(service_t *svc, papi_attribute_t **attributes, char **metadata, papi_attribute_t ***used) { + papi_attribute_t *tmp[2]; char *s; int integer; @@ -307,37 +348,44 @@ /* Handling */ s = NULL; - papiAttributeListGetString(attributes, NULL, "job_hold_until", &s); + papiAttributeListGetString(attributes, NULL, "job-hold-until", &s); if ((s != NULL) && (strcmp(s, "indefinite"))) { add_svr4_control_line(metadata, 'H', "hold"); papiAttributeListAddString(used, PAPI_ATTR_EXCL, - "media", "hold"); + "job-hold-until", "indefinite"); } else if ((s != NULL) && (strcmp(s, "no-hold"))) { - add_svr4_control_line(metadata, 'H', "release"); + add_svr4_control_line(metadata, 'H', "immediate"); papiAttributeListAddString(used, PAPI_ATTR_EXCL, - "media", "release"); - } else if ((s != NULL) && (strcmp(s, "immediate"))) { - add_int_control_line(metadata, 'q', 0, LPD_SVR4); + "job-hold-until", "no-hold"); + } else if (s != NULL) { + add_svr4_control_line(metadata, 'H', s); papiAttributeListAddString(used, PAPI_ATTR_EXCL, - "media", "immediate"); + "job-hold-until", s); } /* Pages */ s = NULL; - papiAttributeListGetString(attributes, NULL, "page-ranges", &s); - if (s != NULL) { - add_svr4_control_line(metadata, 'P', s); - papiAttributeListAddString(used, PAPI_ATTR_EXCL, - "page-ranges", s); + memset(tmp, NULL, sizeof (tmp)); + tmp[0] = papiAttributeListFind(attributes, "page-ranges"); + if (tmp[0] != NULL) { + char buf[BUFSIZ]; + + papiAttributeListToString(tmp, " ", buf, sizeof (buf)); + if ((s = strchr(buf, '=')) != NULL) { + add_svr4_control_line(metadata, 'P', ++s); + papiAttributeListAddString(used, PAPI_ATTR_EXCL, + "page-ranges", s); + } } /* Priority : lp -q */ integer = -1; - papiAttributeListGetInteger(attributes, NULL, "priority", &integer); + papiAttributeListGetInteger(attributes, NULL, "job-priority", &integer); if (integer != -1) { + integer = 40 - (integer / 2.5); add_int_control_line(metadata, 'q', integer, LPD_SVR4); papiAttributeListAddInteger(used, PAPI_ATTR_EXCL, - "priority", integer); + "job-priority", integer); } /* Charset : lp -S */ @@ -360,13 +408,10 @@ "lp-modes", s); } - /* Options lp -o */ - s = NULL; - papiAttributeListGetString(attributes, NULL, "lp-options", &s); - if (s != NULL) { - add_svr4_control_line(metadata, 'o', s); - papiAttributeListAddString(used, PAPI_ATTR_EXCL, - "lp-options", s); + /* Options lp -o are handled elsewhere */ + if ((s = unused_attributes(attributes, *used)) != NULL) { + add_lpd_control_line(metadata, 'O', s); + free(s); } return (PAPI_OK); @@ -379,12 +424,9 @@ char *s = NULL; /* Options lp -o */ - s = NULL; - papiAttributeListGetString(attributes, NULL, "lp-options", &s); - if (s != NULL) { + if ((s = unused_attributes(attributes, *used)) != NULL) { add_hpux_control_line(metadata, s); - papiAttributeListAddString(used, PAPI_ATTR_EXCL, - "lp-options", s); + free(s); } return (PAPI_OK); @@ -399,6 +441,7 @@ lpd_add_rfc1179_attributes(svc, attributes, metadata, used); + /* add protocol extensions if applicable */ if (svc->uri->fragment != NULL) { if ((strcasecmp(svc->uri->fragment, "solaris") == 0) || (strcasecmp(svc->uri->fragment, "svr4") == 0)) @@ -547,3 +590,4 @@ return (status); } + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nj...@us...> - 2008-06-30 17:25:17
|
Revision: 188 http://openprinting.svn.sourceforge.net/openprinting/?rev=188&view=rev Author: njacobs Date: 2008-06-30 10:24:54 -0700 (Mon, 30 Jun 2008) Log Message: ----------- 2008-06-30 Norm Jacobs <Norm.Jacobs@Sun.COM> resync with Solaris Nevada * source/libpapi-dynamic/nss.c fix some cycle detection * source/libpapi-common/attribute.c fix papiAttribute[To|From]String to be more closely aligned with spec * source/libpapi-common/list.c fix memory issues with list_remove() * source/bsd-sysv-commands/lpstat.c make more like Solaris 10 lpstat * source/bsd-sysv-commands/lp.c fix several issues with handling options * source/bsd-sysv-commands/in.lpd.c cycle detection * source/bsd-sysv-commands/cancel.c make work like Solaris 10 * source/bsd-sysv-commands/common.c misc fixes for commands * source/libpapi-lpd/lpd-job.c deal with attribute list to rfc1179 translation better Modified Paths: -------------- trunk/papi/ChangeLog trunk/papi/source/bsd-sysv-commands/cancel.c trunk/papi/source/bsd-sysv-commands/common.c trunk/papi/source/bsd-sysv-commands/in.lpd.c trunk/papi/source/bsd-sysv-commands/lp.c trunk/papi/source/bsd-sysv-commands/lpstat.c trunk/papi/source/libpapi-common/attribute.c trunk/papi/source/libpapi-common/list.c trunk/papi/source/libpapi-dynamic/nss.c trunk/papi/source/libpapi-lpd/lpd-job.c Modified: trunk/papi/ChangeLog =================================================================== --- trunk/papi/ChangeLog 2008-06-27 23:24:35 UTC (rev 187) +++ trunk/papi/ChangeLog 2008-06-30 17:24:54 UTC (rev 188) @@ -1,3 +1,25 @@ +2008-06-30 Norm Jacobs <Norm.Jacobs@Sun.COM> + resync with Solaris Nevada + * source/libpapi-dynamic/nss.c + fix some cycle detection + * source/libpapi-common/attribute.c + fix papiAttribute[To|From]String to be more + closely aligned with spec + * source/libpapi-common/list.c + fix memory issues with list_remove() + * source/bsd-sysv-commands/lpstat.c + make more like Solaris 10 lpstat + * source/bsd-sysv-commands/lp.c + fix several issues with handling options + * source/bsd-sysv-commands/in.lpd.c + cycle detection + * source/bsd-sysv-commands/cancel.c + make work like Solaris 10 + * source/bsd-sysv-commands/common.c + misc fixes for commands + * source/libpapi-lpd/lpd-job.c + deal with attribute list to rfc1179 translation better + 2007-07-31 Norm Jacobs <Norm.Jacobs@Sun.COM> resync with Solaris Nevada, use gethostname() for linux * source/libipp-listener/ipp-listener.c Modified: trunk/papi/source/bsd-sysv-commands/cancel.c =================================================================== --- trunk/papi/source/bsd-sysv-commands/cancel.c 2008-06-27 23:24:35 UTC (rev 187) +++ trunk/papi/source/bsd-sysv-commands/cancel.c 2008-06-30 17:24:54 UTC (rev 188) @@ -20,12 +20,13 @@ */ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * */ #pragma ident "$Id$" +/* #pragma ident "@(#)cancel.c 1.2 08/06/06 SMI" */ #include <stdio.h> #include <stdlib.h> @@ -51,6 +52,49 @@ } int +cancel_jobs_for_user(char *user, papi_encryption_t encryption, char *pname) { + + papi_status_t status; + papi_service_t svc = NULL; + char **printers = NULL; + int i, exit_code; + + if (pname == NULL) { + status = papiServiceCreate(&svc, NULL, user, NULL, + cli_auth_callback, encryption, NULL); + printers = interest_list(svc); + papiServiceDestroy(svc); + } else { + list_append(&printers, strdup(pname)); + } + + if (printers == NULL) + exit(0); + + for (i = 0; printers[i] != NULL; i++) { + char *printer = printers[i]; + + status = papiServiceCreate(&svc, printer, user, NULL, + cli_auth_callback, encryption, NULL); + + if (status != PAPI_OK) { + fprintf(stderr, gettext( + "Failed to contact service for %s: %s\n"), + printer, verbose_papi_message(svc, status)); + exit(1); + } + exit_code = berkeley_cancel_request(svc, stdout, printer, 1, + &user); + + papiServiceDestroy(svc); + if (exit_code != 0) + break; + } + free(printers); + return (exit_code); +} + +int main(int ac, char *av[]) { int exit_code = 0; @@ -61,6 +105,9 @@ (void) setlocale(LC_ALL, ""); (void) textdomain("SUNW_OST_OSCMD"); + if (ac == 1) + usage(av[0]); + while ((c = getopt(ac, av, "Eu:")) != EOF) switch (c) { case 'E': @@ -83,11 +130,11 @@ (void) get_printer_id(av[c], &printer, &id); status = papiServiceCreate(&svc, printer, user, NULL, - cli_auth_callback, encryption, NULL); + cli_auth_callback, encryption, NULL); if (status != PAPI_OK) { - fprintf(stderr, gettext( - "Failed to contact service for %s: %s\n"), - printer, verbose_papi_message(svc, status)); + fprintf(stderr, + gettext("Failed to contact service for %s: %s\n"), + printer, verbose_papi_message(svc, status)); exit(1); } @@ -97,29 +144,55 @@ char *mesg = "cancelled"; status = papiJobCancel(svc, printer, id); - if (status != PAPI_OK) { + if (status == PAPI_NOT_AUTHORIZED) { + mesg = papiStatusString(status); + exit_code = 1; + } else if (status != PAPI_OK) { mesg = verbose_papi_message(svc, status); exit_code = 1; } fprintf(OUT, "%s-%d: %s\n", printer, id, mesg); + } else { /* it's a printer */ - status = papiPrinterPurgeJobs(svc, printer, &jobs); - if (status != PAPI_OK) { - fprintf(stderr, gettext("PurgeJobs %s: %s\n"), - printer, - verbose_papi_message(svc, status)); - exit_code = 1; - } + if (user == NULL) { - while ((jobs != NULL) && (*jobs != NULL)) - fprintf(OUT, "%s-%d: %s\n", printer, - papiJobGetId(*jobs++), "cancelled"); + /* Remove first job from printer */ - papiJobListFree(jobs); + status = papiPrinterListJobs(svc, printer, + NULL, NULL, 0, &jobs); + + if (status != PAPI_OK) { + fprintf(stderr, gettext( + "ListJobs %s: %s\n"), printer, + verbose_papi_message(svc, status)); + exit_code = 1; + } + + if (jobs != NULL && *jobs != NULL) { + char jobid[32]; + char *jid; + + snprintf(jobid, sizeof (jobid), "%u", + papiJobGetId(*jobs)); + + jid = jobid; + exit_code = berkeley_cancel_request(svc, + stdout, printer, 1, &jid); + + } + papiJobListFree(jobs); + + } else { + /* Purging user's print jobs */ + exit_code = cancel_jobs_for_user(user, + encryption, printer); + } } - papiServiceDestroy(svc); } + if (optind == ac) + exit_code = cancel_jobs_for_user(user, encryption, NULL); + return (exit_code); } Modified: trunk/papi/source/bsd-sysv-commands/common.c =================================================================== --- trunk/papi/source/bsd-sysv-commands/common.c 2008-06-27 23:24:35 UTC (rev 187) +++ trunk/papi/source/bsd-sysv-commands/common.c 2008-06-30 17:24:54 UTC (rev 188) @@ -20,12 +20,13 @@ */ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * */ #pragma ident "$Id$" +/* #pragma ident "@(#)common.c 1.3 08/05/28 SMI" */ #include <stdio.h> #include <stdlib.h> @@ -191,6 +192,8 @@ (void) papiAttributeListGetInteger(list, NULL, "job-id", &id); + (void) papiAttributeListGetInteger(list, NULL, + "job-id-requested", &id); (void) papiAttributeListGetString(list, NULL, "job-originating-user-name", &user); (void) papiAttributeListGetString(list, NULL, @@ -236,16 +239,20 @@ papi_status_t status; papi_attribute_t **list = papiJobGetAttributeList(job); int id = 0; + int rid = 0; char *user = ""; char *mesg = gettext("cancelled"); papiAttributeListGetInteger(list, NULL, "job-id", &id); + papiAttributeListGetInteger(list, NULL, + "job-id-requested", &rid); papiAttributeListGetString(list, NULL, "job-originating-user-name", &user); /* if we are looking and it doesn't match, return early */ - if ((ac > 0) && (match_job(id, user, ac, av) < 0)) + if ((ac > 0) && (match_job(id, user, ac, av) < 0) && + (match_job(rid, user, ac, av) < 0)) return; status = papiJobCancel(svc, printer, id); @@ -265,7 +272,7 @@ char *pattrs[] = { "printer-name", "printer-state", "printer-state-reasons", NULL }; char *jattrs[] = { "job-name", "job-octets", "job-k-octets", "job-id", - "job-originating-user-name", + "job-originating-user-name", "job-id-requested", "job-originating-host-name", "number-of-intervening-jobs", NULL }; int num_jobs = 0; @@ -313,7 +320,8 @@ { papi_status_t status; papi_job_t *jobs = NULL; - char *jattrs[] = { "job-originating-user-name", "job-id", NULL }; + char *jattrs[] = { "job-originating-user-name", "job-id", + "job-id-requested", NULL }; status = papiPrinterListJobs(svc, dest, jattrs, PAPI_LIST_JOBS_ALL, 0, &jobs); Modified: trunk/papi/source/bsd-sysv-commands/in.lpd.c =================================================================== --- trunk/papi/source/bsd-sysv-commands/in.lpd.c 2008-06-27 23:24:35 UTC (rev 187) +++ trunk/papi/source/bsd-sysv-commands/in.lpd.c 2008-06-30 17:24:54 UTC (rev 188) @@ -20,12 +20,13 @@ */ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * */ #pragma ident "$Id$" +/* #pragma ident "@(#)in.lpd.c 1.6 08/06/05 SMI" */ #include <stdio.h> #include <stdlib.h> @@ -33,12 +34,12 @@ #include <fcntl.h> #include <stdarg.h> #include <string.h> +#include <ctype.h> #include <errno.h> #include <syslog.h> #include <libintl.h> #include <pwd.h> #include <grp.h> -#include <sys/param.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/socket.h> @@ -66,7 +67,7 @@ socklen_t peer_len = sizeof (peer); int fd = fileno(fp); int error_num; - char myname[MAXHOSTNAMELEN], tmp_buf[INET6_ADDRSTRLEN]; + char *myname, tmp_buf[INET6_ADDRSTRLEN]; char *hostname; /* who is our peer ? */ @@ -78,12 +79,14 @@ } /* get their name or return a string containing their address */ +#if defined(HAVE_GETIPNODEBYNAME) if ((hp = getipnodebyaddr((const char *)&peer.sin6_addr, sizeof (struct in6_addr), AF_INET6, &error_num)) == NULL) { return (strdup(inet_ntop(peer.sin6_family, &peer.sin6_addr, tmp_buf, sizeof (tmp_buf)))); } +#endif /* is it "localhost" ? */ if (strcasecmp(hp->h_name, "localhost") == 0) @@ -91,9 +94,10 @@ /* duplicate the name because gethostbyXXXX() is not reentrant */ hostname = strdup(hp->h_name); - gethostname(myname, sizeof (myname)); + myname = localhostname(); /* is it from one of my addresses ? */ +#if defined(HAVE_GETIPNODEBYNAME) if ((hp = getipnodebyname(myname, AF_INET6, AI_ALL|AI_V4MAPPED, &error_num)) != NULL) { struct in6_addr **tmp = (struct in6_addr **)hp->h_addr_list; @@ -107,6 +111,7 @@ } } } +#endif /* It must be someone else */ return (hostname); @@ -306,14 +311,10 @@ papiAttributeListAddString(&list, PAPI_ATTR_EXCL, "job-hold-until", "indefinite"); - else if (strcasecmp(entry, "release") == 0) + else if (strcasecmp(entry, "immediate") == 0) papiAttributeListAddString(&list, PAPI_ATTR_EXCL, "job-hold-until", "no-hold"); - else if (strcasecmp(entry, "immediate") == 0) - papiAttributeListAddInteger(&list, - PAPI_ATTR_EXCL, - "job-priority", 100); else papiAttributeListAddString(&list, PAPI_ATTR_EXCL, @@ -323,19 +324,23 @@ papiAttributeListAddBoolean(&list, PAPI_ATTR_EXCL, "rfc-1179-mail", 1); break; - case 'P': /* Solaris page list */ - papiAttributeListAddString(&list, - PAPI_ATTR_EXCL, - "page-ranges", ++entry); + case 'P': { /* Solaris page list */ + char buf[BUFSIZ]; + + snprintf(buf, sizeof (buf), "page-ranges=%s", + ++entry); + papiAttributeListFromString(&list, + PAPI_ATTR_EXCL, buf); + } break; case 'q': { /* Solaris priority */ int i = atoi(optarg); - i = 99 * (39 - i) / 39 + 1; + i = 100 - (i * 2.5); if ((i < 1) || (i > 100)) i = 50; papiAttributeListAddInteger(&list, - PAPI_ATTR_EXCL, "priority", i); + PAPI_ATTR_EXCL, "job-priority", i); } break; case 'S': /* Solaris character set */ @@ -379,7 +384,8 @@ } static papi_status_t -submit_job(papi_service_t svc, FILE *ifp, char *printer, char *cf, char **files) +submit_job(papi_service_t svc, FILE *ifp, char *printer, int rid, char *cf, + char **files) { papi_attribute_t **list = NULL; papi_status_t status; @@ -395,6 +401,10 @@ "job-originating-host-name", host); free(host); } + if (rid > 0) { + papiAttributeListAddInteger(&list, PAPI_ATTR_EXCL, + "job-id-requested", rid); + } } status = papiJobSubmit(svc, printer, list, NULL, files, &job); @@ -498,6 +508,7 @@ papi_status_t status = PAPI_OK; char *file, **files = NULL; /* the job data files */ char *cf = NULL; + int rid = 0; char buf[BUFSIZ]; while (fgets(buf, sizeof (buf), ifp) != NULL) { @@ -513,12 +524,18 @@ cleanup(&files, &cf); break; case 0x02: { /* Receive control file */ + if (((cf = strchr(buf, ' ')) != NULL) && + (strlen(cf) > 4)) { + while ((*cf != NULL) && (isdigit(*cf) == 0)) + cf++; + rid = atoi(cf); + } cf = receive_control_file(svc, ifp, ofp, atoi(&buf[1])); if (cf == NULL) { cleanup(&files, &cf); return (PAPI_BAD_REQUEST); } else if (files != NULL) { - status = submit_job(svc, ifp, printer, cf, + status = submit_job(svc, ifp, printer, rid, cf, files); cleanup(&files, &cf); } @@ -541,7 +558,7 @@ } if ((cf != NULL) && (files != NULL)) - status = submit_job(svc, ifp, printer, cf, files); + status = submit_job(svc, ifp, printer, rid, cf, files); cleanup(&files, &cf); @@ -581,7 +598,7 @@ cyclical_service_check(char *svc_name) { papi_attribute_t **list; - char buf[BUFSIZ]; + char *myname = localhostname(); uri_t *uri = NULL; char *s = NULL; @@ -612,9 +629,8 @@ } /* is it the local host? */ - gethostname(buf, sizeof (buf)); if ((strcasecmp(uri->host, "localhost") != 0) && - (strcasecmp(uri->host, buf) != 0)) { + (strcasecmp(uri->host, myname) != 0)) { uri_free(uri); return (0); } Modified: trunk/papi/source/bsd-sysv-commands/lp.c =================================================================== --- trunk/papi/source/bsd-sysv-commands/lp.c 2008-06-27 23:24:35 UTC (rev 187) +++ trunk/papi/source/bsd-sysv-commands/lp.c 2008-06-30 17:24:54 UTC (rev 188) @@ -20,12 +20,13 @@ */ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * */ #pragma ident "$Id$" +/* #pragma ident "@(#)lp.c 1.5 08/05/26 SMI" */ #include <stdio.h> #include <stdlib.h> @@ -87,22 +88,22 @@ papiAttributeListAddString(&list, PAPI_ATTR_EXCL, "job-hold-until", "indefinite"); - else if (strcasecmp(optarg, "release") == 0) + else if (strcasecmp(optarg, "immediate") == 0) papiAttributeListAddString(&list, PAPI_ATTR_EXCL, "job-hold-until", "no-hold"); - else if (strcasecmp(optarg, "immediate") == 0) - papiAttributeListAddInteger(&list, - PAPI_ATTR_EXCL, - "job-priority", 100); else papiAttributeListAddString(&list, PAPI_ATTR_EXCL, "job-hold-until", optarg); break; - case 'P': /* page list */ - papiAttributeListAddString(&list, PAPI_ATTR_EXCL, - "page-ranges", optarg); + case 'P': { /* page list */ + char buf[BUFSIZ]; + + snprintf(buf, sizeof (buf), "page-ranges=%s", optarg); + papiAttributeListFromString(&list, + PAPI_ATTR_EXCL, buf); + } break; case 'S': /* charset */ papiAttributeListAddString(&list, PAPI_ATTR_EXCL, @@ -154,14 +155,14 @@ case 'q': { /* priority */ int i = atoi(optarg); - i = 99 * (39 - i) / 39 + 1; + i = 100 - (i * 2.5); if ((i < 1) || (i > 100)) { fprintf(stderr, gettext( "priority must be between 0 and 39.\n")); exit(1); } papiAttributeListAddInteger(&list, PAPI_ATTR_EXCL, - "priority", i); + "job-priority", i); } break; case 'r': /* "raw" mode */ Modified: trunk/papi/source/bsd-sysv-commands/lpstat.c =================================================================== --- trunk/papi/source/bsd-sysv-commands/lpstat.c 2008-06-27 23:24:35 UTC (rev 187) +++ trunk/papi/source/bsd-sysv-commands/lpstat.c 2008-06-30 17:24:54 UTC (rev 188) @@ -20,12 +20,13 @@ */ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * */ #pragma ident "$Id$" +/* #pragma ident "@(#)lpstat.c 1.7 08/05/21 SMI" */ #include <stdio.h> #include <stdlib.h> @@ -396,6 +397,16 @@ printf(gettext("\tDescription: %s\n"), str); str = ""; + iter = NULL; + (void) papiAttributeListGetString(attrs, &iter, + "lpsched-printer-type", &str); + printf(gettext("\tPrinter types: %s"), str); + while (papiAttributeListGetString(attrs, &iter, NULL, &str) + == PAPI_OK) + printf(", %s", str); + printf("\n"); + + str = ""; (void) papiAttributeListGetString(attrs, NULL, "lpsched-dial-info", &str); printf(gettext("\tConnection: %s\n"), @@ -475,10 +486,16 @@ str = ""; (void) papiAttributeListGetString(attrs, NULL, "job-sheets-supported", &str); - printf(gettext("\tBanner %s\n"), - (strcasecmp(str, "none") == 0 ? - gettext("not required") : gettext("required"))); + if ((strcasecmp(str, "none")) == 0) + str = gettext("page never printed"); + else if (strcasecmp(str, "optional") == 0) + str = gettext("not required"); + else + str = gettext("required"); + printf(gettext("\tBanner %s\n"), str); + + str = ""; iter = NULL; (void) papiAttributeListGetString(attrs, &iter, Modified: trunk/papi/source/libpapi-common/attribute.c =================================================================== --- trunk/papi/source/libpapi-common/attribute.c 2008-06-27 23:24:35 UTC (rev 187) +++ trunk/papi/source/libpapi-common/attribute.c 2008-06-30 17:24:54 UTC (rev 188) @@ -20,21 +20,25 @@ */ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * */ #pragma ident "$Id$" +/* #pragma ident "@(#)attribute.c 1.3 08/05/26 SMI" */ + /*LINTLIBRARY*/ #include <stdio.h> #include <stdlib.h> #include <stdarg.h> #include <string.h> +#include <ctype.h> #include <alloca.h> #include <papi.h> +#include <regex.h> static void papiAttributeFree(papi_attribute_t *attribute); @@ -615,335 +619,241 @@ return (status); } -/* - * Description: The given string contains one or more attributes, in the - * following form: - * "aaaa=true bbbbb=1 ccccc=abcd" - * extract the next attribute from that string; the 'next' - * parameter should be set to zero to extract the first attribute - * in the string. - * - */ +/* The string is modified by this call */ static char * -_getNextAttr(char *string, int *next) - +regvalue(regmatch_t match, char *string) { char *result = NULL; - char *start = (char *)string + *next; - char *nl = NULL; - char *sp = NULL; - char *tab = NULL; - char *val = NULL; - int len = 0; + if (match.rm_so != match.rm_eo) { + result = string + match.rm_so; + *(result + (match.rm_eo - match.rm_so)) = '\0'; + } + return (result); +} - if ((string != NULL) && (*start != '\0')) { - while ((*start == ' ') || (*start == '\t') || (*start == '\n')) - { - start++; - } - nl = strchr(start, '\n'); - sp = strchr(start, ' '); - tab = strchr(start, '\t'); +static papi_attribute_value_type_t +_process_value(char *string, char ***parts) +{ + int i; + static struct { + papi_attribute_value_type_t type; + size_t vals; + char *expression; + int compiled; + regex_t re; + } types[] = { + { PAPI_BOOLEAN, 1, "^(true|false|yes|no)$", 0 }, + { PAPI_COLLECTION, 1, "^\\{(.+)\\}$", 0 }, + /* PAPI_DATETIME is unsupported, too much like an integer */ + { PAPI_INTEGER, 1, "^([+-]{0,1}[[:digit:]]+)$", 0 }, + { PAPI_RANGE, 3, "^([[:digit:]]+)-([[:digit:]]+)$", 0 }, + { PAPI_RESOLUTION, 4, "^([[:digit:]]+)x([[:digit:]]+)dp(i|c)$", + 0 }, + }; + regmatch_t matches[4]; - val = strchr(start, '='); + for (i = 0; i < 5; i++) { + int j; - if ((val != NULL) && ((val[1] == '"') || (val[1] == '\''))) { - val = strchr(&val[2], val[1]); - if (val != NULL) { - nl = strchr(&val[1], '\n'); - sp = strchr(&val[1], ' '); - tab = strchr(&val[1], '\t'); - } + if (types[i].compiled == 0) { + (void) regcomp(&(types[i].re), types[i].expression, + REG_EXTENDED|REG_ICASE); + types[i].compiled = 1; } + if (regexec(&(types[i].re), string, (size_t)types[i].vals, + matches, 0) == REG_NOMATCH) + continue; - if ((nl != NULL) && - ((sp == NULL) || ((sp != NULL) && (nl < sp))) && - ((tab == NULL) || ((tab != NULL) && (nl < tab)))) { - len = nl-start; - } else if ((sp != NULL) && (tab != NULL) && (sp > tab)) { - len = tab-start; - } else if ((sp != NULL) && (sp != NULL)) { - len = sp-start; - } else if ((tab != NULL) && (tab != NULL)) { - len = tab-start; - } + for (j = 0 ; j < types[i].vals; j++) + list_append(parts, regvalue(matches[j], string)); + return (types[i].type); + } - if (len == 0) { - len = strlen(start); - } + list_append(parts, string); + return (PAPI_STRING); +} - if (len > 0) { - result = (char *)malloc(len+1); - if (result != NULL) { - strncpy(result, start, len); - result[len] = '\0'; - *next = (start-string)+len; - } +static void +_add_attribute_value(papi_attribute_value_t ***list, + papi_attribute_value_type_t type, + papi_attribute_value_type_t dtype, char **parts) +{ + papi_attribute_value_t *value = calloc(1, sizeof (*value)); + + switch(type) { + case PAPI_STRING: + value->string = strdup(parts[0]); + list_append(list, value); + break; + case PAPI_BOOLEAN: + value->boolean = PAPI_TRUE; + if ((strcasecmp(parts[0], "false") == 0) || + (strcasecmp(parts[0], "no") == 0)) + value->boolean = PAPI_FALSE; + list_append(list, value); + break; + case PAPI_INTEGER: + value->integer = atoi(parts[0]); + list_append(list, value); + break; + case PAPI_RANGE: + if (dtype == PAPI_INTEGER) + value->range.lower = value->range.upper + = atoi(parts[0]); + else if (dtype == PAPI_RANGE) { + value->range.lower = atoi(parts[1]); + value->range.upper = atoi(parts[2]); } + list_append(list, value); + break; + case PAPI_RESOLUTION: + value->resolution.xres = atoi(parts[1]); + value->resolution.yres = atoi(parts[2]); + if (parts[3][0] == 'i') + value->resolution.units = PAPI_RES_PER_INCH; + else + value->resolution.units = PAPI_RES_PER_CM; + list_append(list, value); + break; + case PAPI_COLLECTION: + papiAttributeListFromString(&(value->collection), 0, parts[0]); + list_append(list, value); + break; } +} - return (result); -} /* _getNextAttr() */ - - -/* - * Description: Parse the given attribute string value and transform it into - * the papi_attribute_value_t in the papi_attribute_t structure. - * - */ - static papi_status_t -_parseAttrValue(char *value, papi_attribute_t *attr) - +_papiAttributeFromStrings(papi_attribute_t ***list, int flags, + char *key, char **values) { + int i; papi_status_t result = PAPI_OK; - int len = 0; - int i = 0; - char *papiString = NULL; - char *tmp1 = NULL; - char *tmp2 = NULL; - char *tmp3 = NULL; - papi_attribute_value_t **avalues = NULL; + papi_attribute_t *attr = calloc(1, sizeof (*attr)); - avalues = malloc(sizeof (papi_attribute_value_t *) * 2); - if (avalues == NULL) { - result = PAPI_TEMPORARY_ERROR; - return (result); - } - avalues[0] = malloc(sizeof (papi_attribute_value_t)); - avalues[1] = NULL; - if (avalues[0] == NULL) { - free(avalues); - result = PAPI_TEMPORARY_ERROR; - return (result); - } + /* these are specified in the papi spec as ranges */ + char *ranges[] = { "copies-supported", "job-impressions-supported", + "job-k-octets-supported", + "job-media-sheets-supported", "page-ranges", + NULL }; + if ((attr == NULL) || ((attr->name = strdup(key)) == NULL)) + return (PAPI_TEMPORARY_ERROR); -/* - * TODO - need to sort out 'resolution', 'dateandtime' & 'collection' values - */ - if ((value != NULL) && (strlen(value) > 0) && (attr != NULL)) { + attr->type = PAPI_METADATA; + /* these are known ranges */ + for (i = 0; ranges[i] != NULL; i++) + if (strcasecmp(attr->name, ranges[i]) == 0) { + attr->type = PAPI_RANGE; + break; + } - len = strlen(value); - if ((len >= 2) && (((value[0] == '"') && - (value[len-1] == '"')) || ((value[0] == '\'') && - (value[len-1] == '\'')))) { - /* string value */ - attr->type = PAPI_STRING; + if (values != NULL) { + papi_attribute_value_t **vals = NULL; - papiString = strdup(value+1); - if (papiString != NULL) { - papiString[strlen(papiString)-1] = '\0'; - avalues[0]->string = papiString; - } else { - result = PAPI_TEMPORARY_ERROR; - } - } else if ((strcasecmp(value, "true") == 0) || - (strcasecmp(value, "YES") == 0)) { - /* boolean = true */ - attr->type = PAPI_BOOLEAN; - avalues[0]->boolean = PAPI_TRUE; - } else if ((strcasecmp(value, "false") == 0) || - (strcasecmp(value, "NO") == 0)) { - /* boolean = false */ - attr->type = PAPI_BOOLEAN; - avalues[0]->boolean = PAPI_FALSE; - } else { - /* is value an integer or a range ? */ + for (i = 0; values[i] != NULL; i++) { + papi_attribute_value_type_t dtype; + char **parts = NULL; - i = 0; - attr->type = PAPI_INTEGER; - tmp1 = strdup(value); - while (((value[i] >= '0') && (value[i] <= '9')) || - (value[i] == '-')) { - if (value[i] == '-') { - tmp1[i] = '\0'; - tmp2 = &tmp1[i+1]; - attr->type = PAPI_RANGE; - } - - i++; - } - - if (strlen(value) == i) { - if (attr->type == PAPI_RANGE) { - avalues[0]->range.lower = atoi(tmp1); - avalues[0]->range.upper = atoi(tmp2); - } else { - avalues[0]->integer = atoi(value); - } - } else { - /* is value a resolution ? */ - i = 0; - attr->type = PAPI_INTEGER; - tmp1 = strdup(value); - while (((value[i] >= '0') && - (value[i] <= '9')) || - (value[i] == 'x')) { - if (value[i] == 'x') { - tmp1[i] = '\0'; - if (attr->type == PAPI_INTEGER) - { - tmp2 = &tmp1[i+1]; - attr->type = - PAPI_RESOLUTION; - } else { - tmp3 = &tmp1[i+1]; - } - } - - i++; - } - - if (strlen(value) == i) { - if (attr->type == PAPI_RESOLUTION) { - avalues[0]->resolution.xres = - atoi(tmp1); - avalues[0]->resolution.yres = - atoi(tmp2); - if (tmp3 != NULL) { - avalues[0]-> - resolution.units = - atoi(tmp3); - } else { - avalues[0]-> - resolution.units = 0; - } - } - } - - if (attr->type != PAPI_RESOLUTION) { - attr->type = PAPI_STRING; - avalues[0]->string = strdup(value); - if (avalues[0]->string == NULL) { - result = PAPI_TEMPORARY_ERROR; - } - } - } - free(tmp1); + dtype = _process_value(values[i], &parts); + if (attr->type == PAPI_METADATA) + attr->type = dtype; + _add_attribute_value(&vals, attr->type, dtype, parts); + free(parts); } - - } else { - result = PAPI_BAD_ARGUMENT; + attr->values = vals; } - if (result != PAPI_OK) { - i = 0; - while (avalues[i] != NULL) { - free(avalues[i]); - i++; - } - free(avalues); - } else { - attr->values = avalues; - } + list_append(list, attr); return (result); -} /* _parseAttrValue() */ +} - -/* - * Description: Parse the given attribute string and transform it into the - * papi_attribute_t structure. - * - */ - static papi_status_t -_parseAttributeString(char *attrString, papi_attribute_t *attr) - +_parse_attribute_list(papi_attribute_t ***list, int flags, char *string) { papi_status_t result = PAPI_OK; - char *string = NULL; - char *p = NULL; - papi_attribute_value_t **avalues = NULL; + char *ptr; - if ((attrString != NULL) && (strlen(attrString) >= 3) && - (attr != NULL)) { - attr->name = NULL; - string = strdup(attrString); - if (string != NULL) { - p = strchr(string, '='); - if (p != NULL) { - *p = '\0'; - attr->name = string; - p++; /* pointer to value */ + if ((list == NULL) || (string == NULL)) + return (PAPI_BAD_ARGUMENT); - result = _parseAttrValue(p, attr); - } else { - char value; - /* boolean - no value so assume 'true' */ - if (strncasecmp(string, "no", 2) == 0) { - string += 2; - value = PAPI_FALSE; - } else - value = PAPI_TRUE; + if ((ptr = strdup(string)) == NULL) + return (PAPI_TEMPORARY_ERROR); - attr->name = string; - attr->type = PAPI_BOOLEAN; + while ((*ptr != '\0') && (result == PAPI_OK)) { + char *key, **values = NULL; - avalues = malloc( - sizeof (papi_attribute_value_t *) * 2); - if (avalues == NULL) { - result = PAPI_TEMPORARY_ERROR; + /* strip any leading whitespace */ + while (isspace(*ptr) != 0) + ptr++; + + /* Get the name: name[=value] */ + key = ptr; + while ((*ptr != '\0') && (*ptr != '=') && (isspace(*ptr) == 0)) + ptr++; + + if (*ptr == '=') { + *ptr++ = '\0'; + + while ((*ptr != '\0') && (isspace(*ptr) == 0)) { + char *value = ptr; + + if ((*ptr == '\'') || (*ptr == '"')) { + char q = *ptr++; + + /* quoted string value */ + while ((*ptr != '\0') && (*ptr != q)) + ptr++; + if (*ptr == q) + ptr++; + } else if (*ptr == '{') { + /* collection */ + while ((*ptr != '\0') && (*ptr != '}')) + ptr++; + if (*ptr == '}') + ptr++; } else { - avalues[0] = malloc( - sizeof (papi_attribute_value_t)); - avalues[1] = NULL; - if (avalues[0] == NULL) { - free(avalues); - result = PAPI_TEMPORARY_ERROR; - } else { - avalues[0]->boolean = value; - attr->values = avalues; - } + /* value */ + while ((*ptr != '\0') && + (*ptr != ',') && + (isspace(*ptr) == 0)) + ptr++; } + if (*ptr == ',') + *ptr++ = '\0'; + list_append(&values, value); } + } else { /* boolean "[no]key" */ + char *value = "true"; + + if (strncasecmp(key, "no", 2) == 0) { + key += 2; + value = "false"; + } + list_append(&values, value); } - } else { - result = PAPI_BAD_ARGUMENT; + if (*ptr != '\0') + *ptr++ = '\0'; + + result = _papiAttributeFromStrings(list, flags, key, values); + free(values); } return (result); -} /* _parseAttributeString() */ +} - papi_status_t papiAttributeListFromString(papi_attribute_t ***attrs, int flags, char *string) { papi_status_t result = PAPI_OK; - int next = 0; - char *attrString = NULL; - papi_attribute_t attr; if ((attrs != NULL) && (string != NULL) && ((flags & ~(PAPI_ATTR_APPEND+PAPI_ATTR_REPLACE+PAPI_ATTR_EXCL)) == 0)) { - attrString = _getNextAttr(string, &next); - while ((result == PAPI_OK) && (attrString != NULL)) { - result = _parseAttributeString(attrString, &attr); - if ((result == PAPI_OK) && (attr.name != NULL)) { - /* add this attribute to the list */ - if ((attr.values != NULL) && - (attr.values[0] != NULL)) { - result = papiAttributeListAddValue( - attrs, PAPI_ATTR_APPEND, - attr.name, attr.type, - attr.values[0]); - free(attr.values[0]); - free(attr.values); - } else { - result = PAPI_TEMPORARY_ERROR; - } - } - free(attrString); - - attrString = _getNextAttr(string, &next); - } - } - else - { + result = _parse_attribute_list(attrs, flags, string); + } else { result = PAPI_BAD_ARGUMENT; } @@ -957,8 +867,18 @@ papi_attribute_value_t **values = attribute->values; int rc, i; - strlcat(buffer, attribute->name, buflen); - strlcat(buffer, "=", buflen); + if ((attribute->type == PAPI_BOOLEAN) && (values[1] == NULL)) { + if (values[0]->boolean == PAPI_FALSE) { + if (isupper(attribute->name[0]) == 0) + strlcat(buffer, "no", buflen); + else + strlcat(buffer, "No", buflen); + } + rc = strlcat(buffer, attribute->name, buflen); + } else { + strlcat(buffer, attribute->name, buflen); + rc = strlcat(buffer, "=", buflen); + } if (values == NULL) return (PAPI_OK); @@ -977,14 +897,20 @@ } break; case PAPI_BOOLEAN: - rc = strlcat(buffer, (values[i]->boolean ? "true" : - "false"), buflen); + if (values[1] != NULL) + rc = strlcat(buffer, (values[i]->boolean ? + "true" : "false"), buflen); break; case PAPI_RANGE: { char string[24]; - snprintf(string, sizeof (string), "%d-%d", - values[i]->range.lower, values[i]->range.upper); + if (values[i]->range.lower == values[i]->range.upper) + snprintf(string, sizeof (string), "%d", + values[i]->range.lower); + else + snprintf(string, sizeof (string), "%d-%d", + values[i]->range.lower, + values[i]->range.upper); rc = strlcat(buffer, string, buflen); } break; @@ -1011,18 +937,9 @@ break; case PAPI_COLLECTION: { char *string = alloca(buflen); -#ifdef DEBUG - char prefix[256]; - snprintf(prefix, sizeof (prefix), "%s %s(%d) ", delim, - attribute->name, i); - papiAttributeListToString(values[i]->collection, - prefix, string, buflen); -#else - papiAttributeListToString(values[i]->collection, delim, string, buflen); -#endif rc = strlcat(buffer, string, buflen); } break; @@ -1059,9 +976,6 @@ if (!delim) delim = " "; -#ifdef DEBUG - strlcat(buffer, delim, buflen); -#endif for (i = 0; ((attrs[i] != NULL) && (status == PAPI_OK)); i++) { status = papiAttributeToString(attrs[i], delim, buffer, buflen); if (attrs[i+1] != NULL) Modified: trunk/papi/source/libpapi-common/list.c =================================================================== --- trunk/papi/source/libpapi-common/list.c 2008-06-27 23:24:35 UTC (rev 187) +++ trunk/papi/source/libpapi-common/list.c 2008-06-30 17:24:54 UTC (rev 188) @@ -20,13 +20,15 @@ */ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * */ #pragma ident "$Id$" +/* #pragma ident "@(#)list.c 1.4 08/05/08 SMI" */ + /*LINTLIBRARY*/ #include <stdlib.h> @@ -35,6 +37,8 @@ static int __list_increment = 16; +#define LIST_SIZE(x) ((((x) / __list_increment) + 1) * __list_increment) + int list_append(void ***list, void *item) { @@ -48,14 +52,14 @@ if (item != NULL) { if (*list == NULL) *list = (void **)calloc(__list_increment, - sizeof (void *)); + sizeof (void *)); - for (count = 0; (*list)[count] != NULL; count++); + for (count = 0; (*list)[count] != NULL; count++) + ; if ((count + 1) % __list_increment == 0) { /* expand the list */ void **new_list = NULL; - int new_size = (((count + 1) / __list_increment) + 1) * - __list_increment; + int new_size = LIST_SIZE(count + 1); new_list = (void **)calloc(new_size, sizeof (void *)); if (new_list == NULL) @@ -83,9 +87,9 @@ list_concatenate(void ***result, void **list2) { void **list1; - int size1 = 0, - size2 = 0, - new_size = 0; + int size1 = 0; + int size2 = 0; + int new_size = 0; if ((result == NULL) || ((*result == NULL) && (list2 == NULL))) { errno = EINVAL; @@ -95,15 +99,16 @@ list1 = *result; if (list1 != NULL) - for (size1 = 0; list1[size1] != NULL; size1++); + for (size1 = 0; list1[size1] != NULL; size1++) + ; if (list2 != NULL) - for (size2 = 0; list2[size2] != NULL; size2++); + for (size2 = 0; list2[size2] != NULL; size2++) + ; /* list1 + list2 padded to a multiple of _list_increment */ - new_size = ((size1 + size2)/__list_increment + 2) * __list_increment; + new_size = LIST_SIZE(size1 + size2); - if ((*result = (void **)calloc((new_size), sizeof (void *))) - != NULL) { + if ((*result = (void **)calloc((new_size), sizeof (void *))) != NULL) { int count = 0; if (list1 != NULL) @@ -138,33 +143,35 @@ void list_remove(void ***list, void *item) { - int i, count; - void **tmp = NULL; + int i = 0, count; if ((list == NULL) || (*list == NULL) || (item == NULL)) return; - for (count = 0; (*list)[count] != NULL; count++); + /* size the original list */ + for (count = 0; (*list)[count] != NULL; count++) + if ((*list)[count] == item) { /* mark the location of item */ + i = count; + item = NULL; + } - if (count > 0) { - int new_size = (((count + 1) / __list_increment) + 1) * - __list_increment; + /* if found, remove it */ + if (item == NULL) { + /* shift the list over the item */ + for (++i; ((*list)[i] != NULL); i++) + (*list)[i-1] = (*list)[i]; + (*list)[i-1] = NULL; + } - if ((tmp = (void **)calloc(new_size, sizeof (void *))) != NULL) - tmp = *list; + /* if found, removed, and list should shrink, shrink it */ + if ((item == NULL) && (LIST_SIZE(i) < LIST_SIZE(count))) { + void **tmp = (void **)calloc(LIST_SIZE(i), sizeof (void *)); - /* copy up to item */ - for (i = 0; (((*list)[i] != NULL) && ((*list)[i] != item)); i++) - tmp[i] = (*list)[i]; - /* copy after item */ - if ((*list)[i] == item) - for (++i; ((*list)[i] != NULL); i++) - tmp[i-1] = (*list)[i]; + if (tmp != NULL) { + for (i = 0; (*list)[i] != NULL; i++) + tmp[i] = (*list)[i]; + free(*list); + *list = tmp; + } } - - /* replace the list */ - if (tmp != *list) { - free(*list); - *list = tmp; - } } Modified: trunk/papi/source/libpapi-dynamic/nss.c =================================================================== --- trunk/papi/source/libpapi-dynamic/nss.c 2008-06-27 23:24:35 UTC (rev 187) +++ trunk/papi/source/libpapi-dynamic/nss.c 2008-06-30 17:24:54 UTC (rev 188) @@ -20,14 +20,14 @@ */ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * */ -/* Id: nss.c 180 2006-07-20 17:33:02Z njacobs $ */ +#pragma ident "Id: nss.c 180 2006-07-20 17:33:02Z njacobs $" +/* #pragma ident "@(#)nss.c 1.6 08/05/28 SMI" */ - #include <stdio.h> #include <stdlib.h> #include <unistd.h> @@ -44,6 +44,9 @@ #include <nss_dbdefs.h> #endif #include <config-site.h> +#if defined(__sun) && defined(__SVR4) +#include <sys/systeminfo.h> +#endif static char * @@ -194,7 +197,7 @@ return (1); /* is it the {nodename} */ - gethostname(hostname, sizeof (hostname)); + sysinfo(SI_HOSTNAME, hostname, sizeof (hostname)); if (strncasecmp(host, hostname, strlen(hostname)) == 0) return (1); @@ -264,9 +267,14 @@ if (attribute != NULL) /* we have what we need, return */ return; - /* do we have a printer-uri to rename */ + /* do we have a printer-uri (in URI form) to rename */ attribute = papiAttributeListFind(*list, "printer-uri"); - if (attribute != NULL) { /* rename it in place and return */ + if ((attribute != NULL) && + (attribute->type == PAPI_STRING) && + (attribute->values != NULL) && + (attribute->values[0]->string != NULL) && + (strstr(attribute->values[0]->string, "://") != NULL)) { + /* rename it in place and return */ free(attribute->name); attribute->name = strdup("printer-uri-supported"); return; Modified: trunk/papi/source/libpapi-lpd/lpd-job.c =================================================================== --- trunk/papi/source/libpapi-lpd/lpd-job.c 2008-06-27 23:24:35 UTC (rev 187) +++ trunk/papi/source/libpapi-lpd/lpd-job.c 2008-06-30 17:24:54 UTC (rev 188) @@ -20,12 +20,13 @@ */ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * */ #pragma ident "$Id$" +/* #pragma ident "@(#)lpd-job.c 1.5 08/05/26 SMI" */ #define __EXTENSIONS__ /* for strtok_r() */ #include <stdio.h> @@ -282,6 +283,45 @@ return (status); } +static char * +unused_attributes(papi_attribute_t **list, papi_attribute_t **used) +{ + char *result = NULL; + char **names = NULL; + int i; + + if ((list == NULL) || (used == NULL)) + return (NULL); + + for (i = 0; used[i] != NULL; i++) + list_append(&names, used[i]->name); + + if (names != NULL) { + papi_attribute_t **unused = NULL; + + /* add these to the list of things to ignore */ + list_append(&names, "document-format"); + list_append(&names, "copies"); + + split_and_copy_attributes(names, list, NULL, &unused); + if (unused != NULL) { + size_t size = 0; + + do { + size += 1024; + if (result != NULL) + free(result); + result = calloc(1, size); + } while (papiAttributeListToString(unused, " ", + result, size) != PAPI_OK); + papiAttributeListFree(unused); + } + free(names); + } + + return (result); +} + /* * lpd_add_svr4_attributes * Solaris 2.x LP - BSD protocol extensions @@ -290,6 +330,7 @@ lpd_add_svr4_attributes(service_t *svc, papi_attribute_t **attributes, char **metadata, papi_attribute_t ***used) { + papi_attribute_t *tmp[2]; char *s; int integer; @@ -307,37 +348,44 @@ /* Handling */ s = NULL; - papiAttributeListGetString(attributes, NULL, "job_hold_until", &s); + papiAttributeListGetString(attributes, NULL, "job-hold-until", &s); if ((s != NULL) && (strcmp(s, "indefinite"))) { add_svr4_control_line(metadata, 'H', "hold"); papiAttributeListAddString(used, PAPI_ATTR_EXCL, - "media", "hold"); + "job-hold-until", "indefinite"); } else if ((s != NULL) && (strcmp(s, "no-hold"))) { - add_svr4_control_line(metadata, 'H', "release"); + add_svr4_control_line(metadata, 'H', "immediate"); papiAttributeListAddString(used, PAPI_ATTR_EXCL, - "media", "release"); - } else if ((s != NULL) && (strcmp(s, "immediate"))) { - add_int_control_line(metadata, 'q', 0, LPD_SVR4); + "job-hold-until", "no-hold"); + } else if (s != NULL) { + add_svr4_control_line(metadata, 'H', s); papiAttributeListAddString(used, PAPI_ATTR_EXCL, - "media", "immediate"); + "job-hold-until", s); } /* Pages */ s = NULL; - papiAttributeListGetString(attributes, NULL, "page-ranges", &s); - if (s != NULL) { - add_svr4_control_line(metadata, 'P', s); - papiAttributeListAddString(used, PAPI_ATTR_EXCL, - "page-ranges", s); + memset(tmp, NULL, sizeof (tmp)); + tmp[0] = papiAttributeListFind(attributes, "page-ranges"); + if (tmp[0] != NULL) { + char buf[BUFSIZ]; + + papiAttributeListToString(tmp, " ", buf, sizeof (buf)); + if ((s = strchr(buf, '=')) != NULL) { + add_svr4_control_line(metadata, 'P', ++s); + papiAttributeListAddString(used, PAPI_ATTR_EXCL, + "page-ranges", s); + } } /* Priority : lp -q */ integer = -1; - papiAttributeListGetInteger(attributes, NULL, "priority", &integer); + papiAttributeListGetInteger(attributes, NULL, "job-priority", &integer); if (integer != -1) { + integer = 40 - (integer / 2.5); add_int_control_line(metadata, 'q', integer, LPD_SVR4); papiAttributeListAddInteger(used, PAPI_ATTR_EXCL, - "priority", integer); + "job-priority", integer); } /* Charset : lp -S */ @@ -360,13 +408,10 @@ "lp-modes", s); } - /* Options lp -o */ - s = NULL; - papiAttributeListGetString(attributes, NULL, "lp-options", &s); - if (s != NULL) { - add_svr4_control_line(metadata, 'o', s); - papiAttributeListAddString(used, PAPI_ATTR_EXCL, - "lp-options", s); + /* Options lp -o are handled elsewhere */ + if ((s = unused_attributes(attributes, *used)) != NULL) { + add_lpd_control_line(metadata, 'O', s); + free(s); } return (PAPI_OK); @@ -379,12 +424,9 @@ char *s = NULL; /* Options lp -o */ - s = NULL; - papiAttributeListGetString(attributes, NULL, "lp-options", &s); - if (s != NULL) { + if ((s = unused_attributes(attributes, *used)) != NULL) { add_hpux_control_line(metadata, s); - papiAttributeListAddString(used, PAPI_ATTR_EXCL, - "lp-options", s); + free(s); } return (PAPI_OK); @@ -399,6 +441,7 @@ lpd_add_rfc1179_attributes(svc, attributes, metadata, used); + /* add protocol extensions if applicable */ if (svc->uri->fragment != NULL) { if ((strcasecmp(svc->uri->fragment, "solaris") == 0) || (strcasecmp(svc->uri->fragment, "svr4") == 0)) @@ -547,3 +590,4 @@ return (status); } + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2008-06-27 23:24:27
|
Revision: 187 http://openprinting.svn.sourceforge.net/openprinting/?rev=187&view=rev Author: allad Date: 2008-06-27 16:24:35 -0700 (Fri, 27 Jun 2008) Log Message: ----------- Fixes to the service API Started Implemenatation of the printer API Fixes to the build scripts : configure now checks for libcups and cups.h Modified Paths: -------------- branches/GSOC-2008/papi/configure.in branches/GSOC-2008/papi/source/Makefile.am branches/GSOC-2008/papi/source/libpapi-cups/Makefile.am branches/GSOC-2008/papi/source/libpapi-cups/mapfile.in branches/GSOC-2008/papi/source/libpapi-cups/papi_impl.h branches/GSOC-2008/papi/source/libpapi-cups/service.c Added Paths: ----------- branches/GSOC-2008/papi/source/libpapi-cups/printer.c Property Changed: ---------------- branches/GSOC-2008/papi/source/libpapi-cups/Makefile.am branches/GSOC-2008/papi/source/libpapi-cups/mapfile.in branches/GSOC-2008/papi/source/libpapi-cups/papi_impl.h branches/GSOC-2008/papi/source/libpapi-cups/service.c Modified: branches/GSOC-2008/papi/configure.in =================================================================== --- branches/GSOC-2008/papi/configure.in 2008-06-26 14:34:29 UTC (rev 186) +++ branches/GSOC-2008/papi/configure.in 2008-06-27 23:24:35 UTC (rev 187) @@ -91,6 +91,12 @@ AC_CHECK_LIB(md5, md5_calc, [libmd5=true], [libmd5=false]) AM_CONDITIONAL(HAVE_LIBMD5, [ test x$libmd5 = xtrue ] ) + +dnl check for the cups headers and library +AC_CHECK_HEADERS(cups/cups.h) +AC_CHECK_LIB(cups,[libcups=true], [libcups=false]) +AM_CONDITIONAL(HAVE_LIBCUPS, [ test x$libcups = xtrue ] ) + dnl do we want the broken papiPrintersList printer-uri semantics AC_ARG_ENABLE(broken-printer-uri-semantic, [ --enable-broken-printer-uri-semantic build nss support to add a printer-uri to printer enumeration results for applications that use this instead of printer-uri-supported (only libgnomeprint-2.12.0 and earlier libgnomeprintpapi modules should need this enabled)], Modified: branches/GSOC-2008/papi/source/Makefile.am =================================================================== --- branches/GSOC-2008/papi/source/Makefile.am 2008-06-26 14:34:29 UTC (rev 186) +++ branches/GSOC-2008/papi/source/Makefile.am 2008-06-27 23:24:35 UTC (rev 187) @@ -36,24 +36,21 @@ RUBY_BINDINGS = ruby endif +if HAVE_LIBCUPS +PAPI_CUPS= libpapi-cups +endif + AUTOMAKE_OPTIONS=foreign -SUBDIRS= libpapi-common \ - libpapi-dynamic \ - libhttp-core \ - libipp-core \ - libpapi-lpd \ - libpapi-ipp \ - libipp-listener \ - bsd-sysv-commands \ - $(APACHE_MODULE) \ - $(RUBY_BINDINGS) \ - examples +SUBDIRS = libpapi-common $(APACHE_MODULE) $(PAPI_CUPS) $(RUBY_BINDINGS) \ + bsd-sysv-commands examples libhttp-core libipp-core libipp-listener libpapi-common \ + libpapi-dynamic libpapi-ipp libpapi-lpd libpapi-dynamic: libpapi-common libpapi-lpd: libpapi-common libpapi-ipp: libpapi-common libipp-core libhttp-core libipp-listener: libpapi-dynamic libipp-core mod_ipp: libipp-listener libpapi-dynamic +libpapi-cups: libpapi-common bsd-sysv-commands: libpapi-dynamic examples: libpapi-dynamic ruby: libpapi-dynamic Modified: branches/GSOC-2008/papi/source/libpapi-cups/Makefile.am =================================================================== --- branches/GSOC-2008/papi/source/libpapi-cups/Makefile.am 2008-06-26 14:34:29 UTC (rev 186) +++ branches/GSOC-2008/papi/source/libpapi-cups/Makefile.am 2008-06-27 23:24:35 UTC (rev 187) @@ -25,7 +25,7 @@ # # -# $Id: Makefile.am 181 2006-10-16 05:22:57Z njacobs $ +# $Id$ # # this gets installed in libexecdir @@ -33,9 +33,11 @@ AM_CPPFLAGS = -I../libpapi-common -I. + lib_LTLIBRARIES = papi-cups.la papi_cups_la_LIBADD = ../libpapi-common/libpapi-common.la +papi_cups_la_LIBADD += -lcups papi_cups_la_LDFLAGS = @MAPFLAGS@ papi_cups_la_LDFLAGS += -module -avoid-version if LINUX @@ -46,6 +48,6 @@ papi_cupsincludedir = $(includedir) # PAPI support layered on IPP -papi_cups_la_SOURCES = service.c +papi_cups_la_SOURCES = service.c printer.c EXTRA_DIST = papi_impl.h mapfile.in Property changes on: branches/GSOC-2008/papi/source/libpapi-cups/Makefile.am ___________________________________________________________________ Name: svn:keywords + Id Modified: branches/GSOC-2008/papi/source/libpapi-cups/mapfile.in =================================================================== --- branches/GSOC-2008/papi/source/libpapi-cups/mapfile.in 2008-06-26 14:34:29 UTC (rev 186) +++ branches/GSOC-2008/papi/source/libpapi-cups/mapfile.in 2008-06-27 23:24:35 UTC (rev 187) @@ -25,7 +25,7 @@ # # -# $Id: mapfile.in 183 2007-02-03 02:35:26Z njacobs $ +# $Id$ # # Property changes on: branches/GSOC-2008/papi/source/libpapi-cups/mapfile.in ___________________________________________________________________ Name: svn:keywords + Id Modified: branches/GSOC-2008/papi/source/libpapi-cups/papi_impl.h =================================================================== --- branches/GSOC-2008/papi/source/libpapi-cups/papi_impl.h 2008-06-26 14:34:29 UTC (rev 186) +++ branches/GSOC-2008/papi/source/libpapi-cups/papi_impl.h 2008-06-27 23:24:35 UTC (rev 187) @@ -28,7 +28,7 @@ #ifndef _PAPI_IMPL_H #define _PAPI_IMPL_H -#pragma ident "$Id: papi_impl.h 184 2007-07-31 17:04:09Z njacobs $" +#pragma ident "$Id$" #include <papi.h> @@ -39,6 +39,7 @@ #include <time.h> #include <sys/types.h> #include <stdarg.h> +#include <cups/cups.h> /* @@ -58,6 +59,8 @@ char *user; char *password; void *app_data; + int numDests; + cups_dest_t *dests; } service_t; typedef struct job { @@ -65,6 +68,7 @@ } job_t; typedef struct { + cups_dest_t *dest; papi_attribute_t **attributes; } printer_t; Property changes on: branches/GSOC-2008/papi/source/libpapi-cups/papi_impl.h ___________________________________________________________________ Name: svn:keywords + Id Added: branches/GSOC-2008/papi/source/libpapi-cups/printer.c =================================================================== --- branches/GSOC-2008/papi/source/libpapi-cups/printer.c (rev 0) +++ branches/GSOC-2008/papi/source/libpapi-cups/printer.c 2008-06-27 23:24:35 UTC (rev 187) @@ -0,0 +1,212 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + */ + +#pragma ident "$Id$" + + +#include <stdlib.h> +#include <papi_impl.h> +#include <cups/cups.h> + + +void +papiPrinterFree(papi_printer_t printer) +{ + printer_t *tmp = printer; + + if (tmp != NULL) { + if (tmp->attributes != NULL) + papiAttributeListFree(tmp->attributes); + free(tmp); + } +} + +void +papiPrinterListFree(papi_printer_t *printers) +{ + if (printers != NULL) { + int i; + + for (i = 0; printers[i] != NULL; i++) + papiPrinterFree(printers[i]); + free(printers); + } +} + +static int +filter_cups_printer(cups_dest_t *printer,papi_filter_t *filter) +{ + if(filter == NULL) + return 1; + + if(printer == NULL) + return 0; + + /*TODO implement filters */ + if(filter->filter.bitmask.mask & PAPI_PRINTER_LOCAL) + { + } + + if(filter->filter.bitmask.mask & PAPI_PRINTER_CLASS) + { + } + + if(filter->filter.bitmask.mask & PAPI_PRINTER_REMOTE) + { + } + + if(filter->filter.bitmask.mask & PAPI_PRINTER_BW) + { + } + + if(filter->filter.bitmask.mask & PAPI_PRINTER_COLOR) + { + } + + return 1; +} + +papi_status_t +papiPrintersList(papi_service_t handle, char **requested_attrs, + papi_filter_t *filter, papi_printer_t **printers) +{ + papi_status_t status, result = PAPI_INTERNAL_ERROR; + service_t *svc = handle; + int i; + + if ((svc == NULL) || (printers == NULL)) + return (PAPI_BAD_ARGUMENT); + + /* only bitmask filters are supported */ + if(filter && filter->type != PAPI_FILTER_BITMASK){ + return PAPI_OPERATION_NOT_SUPPORTED; + } + + for(i=0;i< svc->numDests;i++){ + /*filter if needed*/ + + if(filter_cups_printer(svc->dests+i,filter) == 0){ + //printer didn't pass filter + continue; + } + + /* ok. printer passed filtering*/ + printer_t *p = NULL; + int j = 0; + + if ((p = calloc(1, sizeof (*p))) == NULL) + return (PAPI_TEMPORARY_ERROR); + + p->dest = svc->dests+i; + + for(j=0;j<svc->dests[i].num_options;j++){ + if(requested_attrs != NULL){ + //filter attribute + char *attr = (char *)list_locate (&requested_attrs,strcasecmp,svc->dests[i].options[j].name); + if(attr == NULL) + continue; /* attribute not requested*/ + } + + papiAttributeListAddString (&p->attributes,PAPI_ATTR_APPEND, + svc->dests[i].options[j].name,svc->dests[i].options[j].value); + } + /* if printer-name attribute is requested, add it + Printer name is treated differently because it is not included in CUPS options. + */ + char *pname = (char *)list_locate (&requested_attrs,strcasecmp,"printer-name"); + if(pname != NULL){ + papiAttributeListAddString (&p->attributes,PAPI_ATTR_APPEND, + "printer-name",svc->dests[i].name); + } + + list_append (printers,p); + } + + result = PAPI_OK; + + return (result); +} + + +/* + * Returns PAPI_NOT_FOUND if there's no printer + * named "name" + * PAPI_OK otherwise + * + */ +papi_status_t +papiPrinterQuery(papi_service_t handle, char *name, + char **requested_attrs, + papi_attribute_t **job_attributes, + papi_printer_t *printer) +{ + papi_status_t result = PAPI_INTERNAL_ERROR; + service_t *svc = handle; + printer_t *p = NULL; + cups_dest_t *dest = NULL; + + if ((svc == NULL) || (name == NULL) || (printer == NULL)) + return (PAPI_BAD_ARGUMENT); + + dest = cupsGetDest(name,NULL,svc->numDests,svc->dests); + + if(dest == NULL){ + return PAPI_NOT_FOUND; //named dest not found + } + + if ((*printer = p = calloc(1, sizeof (*p))) == NULL) + return (PAPI_TEMPORARY_ERROR); + + + p->dest = dest; + int j = 0; + + for(j=0;j<dest->num_options;j++){ + if(requested_attrs != NULL){ + //filter attribute + char *attr = (char *)list_locate (&requested_attrs,strcasecmp,dest->options[j].name); + if(attr == NULL) + continue; /* attribute not requested*/ + } + + papiAttributeListAddString (&p->attributes,PAPI_ATTR_APPEND, + dest->options[j].name,dest->options[j].value); + } + /* if printer-name attribute is requested, add it + Printer name is treated differently because it is not included in CUPS options. + */ + char *pname = (char *)list_locate (&requested_attrs,strcasecmp,"printer-name"); + if(pname != NULL){ + papiAttributeListAddString (&p->attributes,PAPI_ATTR_APPEND, + "printer-name",dest->name); + } + + result = PAPI_OK; + + return (result); +} + Property changes on: branches/GSOC-2008/papi/source/libpapi-cups/printer.c ___________________________________________________________________ Name: svn:keywords + Id Modified: branches/GSOC-2008/papi/source/libpapi-cups/service.c =================================================================== --- branches/GSOC-2008/papi/source/libpapi-cups/service.c 2008-06-26 14:34:29 UTC (rev 186) +++ branches/GSOC-2008/papi/source/libpapi-cups/service.c 2008-06-27 23:24:35 UTC (rev 187) @@ -34,10 +34,17 @@ #include <stdarg.h> #include <string.h> #include <alloca.h> +#include <cups/cups.h> #include <papi_impl.h> #include <config-site.h> +const char *cupsPasswordCB(const char *buf) +{ + /*TODO Return password set by user*/ + return NULL; +} + papi_status_t papiServiceCreate(papi_service_t *handle, char *service_name, char *user_name, char *password, @@ -53,8 +60,10 @@ if ((*handle = svc = calloc(1, sizeof (*svc))) == NULL) return (PAPI_TEMPORARY_ERROR); - if (user_name != NULL) + if (user_name != NULL){ svc->user = strdup(user_name); + cupsSetUser(svc->user); + } if (password != NULL) svc->password = strdup(password); @@ -63,6 +72,8 @@ if (app_data != NULL) svc->app_data = app_data; + /* preload CUPS dests */ + svc->numDests = cupsGetDests(&svc->dests); result = PAPI_OK; @@ -83,6 +94,8 @@ free(svc->user); if (svc->password != NULL) free(svc->password); + if(svc->dests != NULL) + cupsFreeDests(svc->numDests,svc->dests); free(handle); } @@ -99,8 +112,10 @@ if (svc->user != NULL) free(svc->user); svc->user = NULL; - if (user_name != NULL) + if (user_name != NULL) { svc->user = strdup(user_name); + cupsSetUser(svc->user); + } } else result = PAPI_BAD_ARGUMENT; Property changes on: branches/GSOC-2008/papi/source/libpapi-cups/service.c ___________________________________________________________________ Name: svn:keywords + Id This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2008-06-26 14:35:21
|
Revision: 186 http://openprinting.svn.sourceforge.net/openprinting/?rev=186&view=rev Author: allad Date: 2008-06-26 07:34:29 -0700 (Thu, 26 Jun 2008) Log Message: ----------- -Added libpapi-cups for CUPS PAPI implementation -Service API implemented Modified Paths: -------------- branches/GSOC-2008/papi/configure.in Added Paths: ----------- branches/GSOC-2008/papi/source/libpapi-cups/ branches/GSOC-2008/papi/source/libpapi-cups/Makefile.am branches/GSOC-2008/papi/source/libpapi-cups/mapfile.in branches/GSOC-2008/papi/source/libpapi-cups/papi_impl.h branches/GSOC-2008/papi/source/libpapi-cups/service.c Modified: branches/GSOC-2008/papi/configure.in =================================================================== --- branches/GSOC-2008/papi/configure.in 2008-05-29 07:07:57 UTC (rev 185) +++ branches/GSOC-2008/papi/configure.in 2008-06-26 14:34:29 UTC (rev 186) @@ -270,6 +270,8 @@ source/libhttp-core/mapfile source/libpapi-lpd/Makefile source/libpapi-lpd/mapfile + source/libpapi-cups/Makefile + source/libpapi-cups/mapfile source/mod_ipp/Makefile source/ruby/Makefile packaging/Solaris/pkginfo Added: branches/GSOC-2008/papi/source/libpapi-cups/Makefile.am =================================================================== --- branches/GSOC-2008/papi/source/libpapi-cups/Makefile.am (rev 0) +++ branches/GSOC-2008/papi/source/libpapi-cups/Makefile.am 2008-06-26 14:34:29 UTC (rev 186) @@ -0,0 +1,51 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. +# +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing permissions +# and limitations under the License. +# +# When distributing Covered Code, include this CDDL HEADER in each +# file and include the License file at usr/src/OPENSOLARIS.LICENSE. +# If applicable, add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your own identifying +# information: Portions Copyright [yyyy] [name of copyright owner] +# +# CDDL HEADER END +# + +# +# Copyright 2006 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +# +# $Id: Makefile.am 181 2006-10-16 05:22:57Z njacobs $ +# + +# this gets installed in libexecdir +libdir = $(libexecdir) + +AM_CPPFLAGS = -I../libpapi-common -I. + +lib_LTLIBRARIES = papi-cups.la + +papi_cups_la_LIBADD = ../libpapi-common/libpapi-common.la +papi_cups_la_LDFLAGS = @MAPFLAGS@ +papi_cups_la_LDFLAGS += -module -avoid-version +if LINUX +papi_cups_la_LDFLAGS += -Wl,-Bsymbolic +endif + + +papi_cupsincludedir = $(includedir) + +# PAPI support layered on IPP +papi_cups_la_SOURCES = service.c + +EXTRA_DIST = papi_impl.h mapfile.in Added: branches/GSOC-2008/papi/source/libpapi-cups/mapfile.in =================================================================== --- branches/GSOC-2008/papi/source/libpapi-cups/mapfile.in (rev 0) +++ branches/GSOC-2008/papi/source/libpapi-cups/mapfile.in 2008-06-26 14:34:29 UTC (rev 186) @@ -0,0 +1,123 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. +# +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing permissions +# and limitations under the License. +# +# When distributing Covered Code, include this CDDL HEADER in each +# file and include the License file at usr/src/OPENSOLARIS.LICENSE. +# If applicable, add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your own identifying +# information: Portions Copyright [yyyy] [name of copyright owner] +# +# CDDL HEADER END +# + +# +# Copyright 2006 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +# +# $Id: mapfile.in 183 2007-02-03 02:35:26Z njacobs $ +# + +# +# Common interfaces that are most likely to be shared amongst the various +# PAPI implementations. +# + +SUNW_1.0 { + global: + # PAPI Attribute Calls + papiAttributeListAddValue @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; + papiAttributeListAddBoolean @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; + papiAttributeListAddCollection @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; + papiAttributeListAddDatetime @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; + papiAttributeListAddInteger @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; + papiAttributeListAddMetadata @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; + papiAttributeListAddRange @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; + papiAttributeListAddResolution @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; + papiAttributeListAddString @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; + papiAttributeListDelete @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; + papiAttributeListGetValue @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; + papiAttributeListGetNext @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; + papiAttributeListFind @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; + papiAttributeListGetBoolean @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; + papiAttributeListGetCollection @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; + papiAttributeListGetDatetime @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; + papiAttributeListGetInteger @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; + papiAttributeListGetMetadata @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; + papiAttributeListGetRange @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; + papiAttributeListGetResolution @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; + papiAttributeListGetString @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; + papiAttributeListFromString @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; + papiAttributeListToString @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; + papiAttributeListFree @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; + + # PAPI Service Calls + papiServiceCreate ; + papiServiceDestroy ; + papiServiceSetUserName ; + papiServiceSetPassword ; + papiServiceSetEncryption ; + papiServiceSetAuthCB ; + papiServiceSetAppData ; + papiServiceGetUserName ; + papiServiceGetPassword ; + papiServiceGetEncryption ; + papiServiceGetAppData ; + papiServiceGetServiceName ; + papiServiceGetAttributeList ; + papiServiceGetStatusMessage ; + + # PAPI Printer Calls + papiPrintersList ; + papiPrinterQuery ; + papiPrinterAdd ; + papiPrinterModify ; + papiPrinterRemove ; + papiPrinterDisable ; + papiPrinterEnable ; + papiPrinterPause ; + papiPrinterResume ; + papiPrinterPurgeJobs ; + papiPrinterListJobs ; + papiPrinterGetAttributeList ; + papiPrinterFree ; + papiPrinterListFree ; + + # PAPI Job Calls + papiJobSubmit ; + papiJobSubmitByReference ; + papiJobValidate ; + papiJobStreamOpen ; + papiJobStreamWrite ; + papiJobStreamClose ; + papiJobQuery ; + papiJobModify ; + papiJobMove ; + papiJobCancel ; + papiJobHold ; + papiJobRelease ; + papiJobRestart ; + papiJobPromote ; + papiJobGetAttributeList ; + papiJobGetPrinterName ; + papiJobGetId ; + papiJobGetJobTicket ; + papiJobFree ; + papiJobListFree ; + + # Misc. PAPI Calls + papiStatusString @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; + papiLibrarySupportedCall @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; + papiLibrarySupportedCalls @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; +}; + Added: branches/GSOC-2008/papi/source/libpapi-cups/papi_impl.h =================================================================== --- branches/GSOC-2008/papi/source/libpapi-cups/papi_impl.h (rev 0) +++ branches/GSOC-2008/papi/source/libpapi-cups/papi_impl.h 2008-06-26 14:34:29 UTC (rev 186) @@ -0,0 +1,81 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + */ + +#ifndef _PAPI_IMPL_H +#define _PAPI_IMPL_H + +#pragma ident "$Id: papi_impl.h 184 2007-07-31 17:04:09Z njacobs $" + +#include <papi.h> + +#ifdef __cplusplus +extern "C" { +#endif + +#include <time.h> +#include <sys/types.h> +#include <stdarg.h> + + +/* + * Implementation specific types/prototypes/definitions follow + * + * + * Ex: + */ +typedef enum { + TRANSFER_ENCODING_CHUNKED, + TRANSFER_ENCODING_LENGTH +} http_transfer_encoding_t; + +typedef struct { + papi_attribute_t **attributes; + char *name; + char *user; + char *password; + void *app_data; +} service_t; + +typedef struct job { + papi_attribute_t **attributes; +} job_t; + +typedef struct { + papi_attribute_t **attributes; +} printer_t; + + + +/* service related interfaces */ +extern void detailed_error(service_t *svc, char *fmt, ...); + + +#ifdef __cplusplus +} +#endif + +#endif /* _PAPI_IMPL_H */ Added: branches/GSOC-2008/papi/source/libpapi-cups/service.c =================================================================== --- branches/GSOC-2008/papi/source/libpapi-cups/service.c (rev 0) +++ branches/GSOC-2008/papi/source/libpapi-cups/service.c 2008-06-26 14:34:29 UTC (rev 186) @@ -0,0 +1,272 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + */ + +#pragma ident "$Id$" + +/*LINTLIBRARY*/ + +#include <stdlib.h> +#include <stdio.h> +#include <stdarg.h> +#include <string.h> +#include <alloca.h> +#include <papi_impl.h> + +#include <config-site.h> + +papi_status_t +papiServiceCreate(papi_service_t *handle, char *service_name, + char *user_name, char *password, + int (*authCB)(papi_service_t svc, void *app_data), + papi_encryption_t encryption, void *app_data) +{ + papi_status_t result = PAPI_NOT_POSSIBLE; + service_t *svc = NULL; + + if (handle == NULL) + return (PAPI_BAD_ARGUMENT); + + if ((*handle = svc = calloc(1, sizeof (*svc))) == NULL) + return (PAPI_TEMPORARY_ERROR); + + if (user_name != NULL) + svc->user = strdup(user_name); + + if (password != NULL) + svc->password = strdup(password); + + + if (app_data != NULL) + svc->app_data = app_data; + + + result = PAPI_OK; + + return (result); +} + +void +papiServiceDestroy(papi_service_t handle) +{ + if (handle != NULL) { + service_t *svc = handle; + + if (svc->attributes != NULL) + papiAttributeListFree(svc->attributes); + if (svc->name != NULL) + free(svc->name); + if (svc->user != NULL) + free(svc->user); + if (svc->password != NULL) + free(svc->password); + + free(handle); + } +} + +papi_status_t +papiServiceSetUserName(papi_service_t handle, char *user_name) +{ + papi_status_t result = PAPI_OK; + + if (handle != NULL) { + service_t *svc = handle; + + if (svc->user != NULL) + free(svc->user); + svc->user = NULL; + if (user_name != NULL) + svc->user = strdup(user_name); + } else + result = PAPI_BAD_ARGUMENT; + + return (result); +} + +papi_status_t +papiServiceSetPassword(papi_service_t handle, char *password) +{ + papi_status_t result = PAPI_OK; + + if (handle != NULL) { + service_t *svc = handle; + + if (svc->password != NULL) + free(svc->password); + svc->password = NULL; + if (password != NULL) + svc->password = strdup(password); + } else + result = PAPI_BAD_ARGUMENT; + + return (result); +} + +papi_status_t +papiServiceSetEncryption(papi_service_t handle, + papi_encryption_t encryption) +{ + papi_status_t result = PAPI_OPERATION_NOT_SUPPORTED; + + return (result); +} + +papi_status_t +papiServiceSetAuthCB(papi_service_t handle, + int (*authCB)(papi_service_t svc, void *app_data)) +{ + papi_status_t result = PAPI_OPERATION_NOT_SUPPORTED; + + return (result); +} + + +papi_status_t +papiServiceSetAppData(papi_service_t handle, void *app_data) +{ + papi_status_t result = PAPI_OK; + + if (handle != NULL) { + service_t *svc = handle; + + svc->app_data = (void *)app_data; + } else + result = PAPI_BAD_ARGUMENT; + + return (result); +} + +char * +papiServiceGetServiceName(papi_service_t handle) +{ + char *result = NULL; + + if (handle != NULL) { + service_t *svc = handle; + + result = svc->name; + } + + return (result); +} + +char * +papiServiceGetUserName(papi_service_t handle) +{ + char *result = NULL; + + if (handle != NULL) { + service_t *svc = handle; + + result = svc->user; + } + + return (result); +} + +char * +papiServiceGetPassword(papi_service_t handle) +{ + char *result = NULL; + + if (handle != NULL) { + service_t *svc = handle; + + result = svc->password; + } + + return (result); +} + +papi_encryption_t +papiServiceGetEncryption(papi_service_t handle) +{ + papi_encryption_t result = PAPI_ENCRYPT_NEVER; + + return (result); +} + +void * +papiServiceGetAppData(papi_service_t handle) +{ + void *result = NULL; + + if (handle != NULL) { + service_t *svc = handle; + + result = svc->app_data; + } + + return (result); +} + +papi_attribute_t ** +papiServiceGetAttributeList(papi_service_t handle) +{ + papi_attribute_t **result = NULL; + service_t *svc = handle; + + if (handle != NULL) + result = svc->attributes; + + return (result); +} + +char * +papiServiceGetStatusMessage(papi_service_t handle) +{ + char *result = NULL; + service_t *svc = handle; + + papiAttributeListGetString(svc->attributes, NULL, + "detailed-status-message", &result); + + return (result); +} + +void +detailed_error(service_t *svc, char *fmt, ...) +{ + if ((svc != NULL) && (fmt != NULL)) { + va_list ap; + size_t size; + char *message = alloca(BUFSIZ); + + va_start(ap, fmt); + /* + * fill in the message. If the buffer is too small, allocate + * one that is large enough and fill it in. + */ + if ((size = vsnprintf(message, BUFSIZ, fmt, ap)) >= BUFSIZ) + if ((message = alloca(size)) != NULL) + vsnprintf(message, size, fmt, ap); + va_end(ap); + + papiAttributeListAddString(&svc->attributes, PAPI_ATTR_APPEND, + "detailed-status-message", message); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nj...@us...> - 2008-05-29 07:07:50
|
Revision: 185 http://openprinting.svn.sourceforge.net/openprinting/?rev=185&view=rev Author: njacobs Date: 2008-05-29 00:07:57 -0700 (Thu, 29 May 2008) Log Message: ----------- A Branch for GSOC work Added Paths: ----------- branches/GSOC-2008/ Copied: branches/GSOC-2008 (from rev 184, trunk) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nj...@us...> - 2007-07-31 17:04:09
|
Revision: 184 http://openprinting.svn.sourceforge.net/openprinting/?rev=184&view=rev Author: njacobs Date: 2007-07-31 10:04:09 -0700 (Tue, 31 Jul 2007) Log Message: ----------- use gethostname() for linux, resync with Solaris Nevada Modified Paths: -------------- trunk/papi/ChangeLog trunk/papi/source/bsd-sysv-commands/in.lpd.c trunk/papi/source/bsd-sysv-commands/lpstat.c trunk/papi/source/libipp-core/read.c trunk/papi/source/libipp-listener/ipp-listener.c trunk/papi/source/libpapi-dynamic/nss.c trunk/papi/source/libpapi-ipp/ipp-support.c trunk/papi/source/libpapi-ipp/job.c trunk/papi/source/libpapi-ipp/papi_impl.h trunk/papi/source/libpapi-ipp/printer.c trunk/papi/source/libpapi-lpd/job.c trunk/papi/source/libpapi-lpd/lpd-cancel.c trunk/papi/source/libpapi-lpd/lpd-job.c trunk/papi/source/libpapi-lpd/lpd-misc.c trunk/papi/source/libpapi-lpd/lpd-port.c trunk/papi/source/libpapi-lpd/lpd-query.c trunk/papi/source/libpapi-lpd/printer.c Modified: trunk/papi/ChangeLog =================================================================== --- trunk/papi/ChangeLog 2007-02-03 02:35:26 UTC (rev 183) +++ trunk/papi/ChangeLog 2007-07-31 17:04:09 UTC (rev 184) @@ -1,3 +1,27 @@ +2007-07-31 Norm Jacobs <Norm.Jacobs@Sun.COM> + resync with Solaris Nevada, use gethostname() for linux + * source/libipp-listener/ipp-listener.c + * source/libpapi-dynamic/nss.c + gethostname() + * source/libipp-core/read.c + improper read of ipp request id + * source/libpapi-ipp/papi_impl.h + * source/libpapi-ipp/ipp-support.c + * source/libpapi-ipp/printer.c + * source/libpapi-ipp/job.c + IPP/1.1 compliance work + * source/bsd-sysv-commands/lpstat.c + fix regressions in '-lp' and output + * source/libpapi-lpd/lpd-port.c + * source/libpapi-lpd/lpd-cancel.c + * source/libpapi-lpd/printer.c + * source/libpapi-lpd/lpd-job.c + * source/libpapi-lpd/lpd-misc.c + * source/libpapi-lpd/job.c + lpd-port should use less risky interfaces + * source/libpapi-lpd/lpd-query.c + lpd-port should use less risky interfaces, better parsing + 2007-02-02 Norm Jacobs <Norm.Jacobs@Sun.COM> * source/libipp-listener/ipp-listener.c * source/libpapi-common/papi.h Modified: trunk/papi/source/bsd-sysv-commands/in.lpd.c =================================================================== --- trunk/papi/source/bsd-sysv-commands/in.lpd.c 2007-02-03 02:35:26 UTC (rev 183) +++ trunk/papi/source/bsd-sysv-commands/in.lpd.c 2007-07-31 17:04:09 UTC (rev 184) @@ -38,13 +38,13 @@ #include <libintl.h> #include <pwd.h> #include <grp.h> +#include <sys/param.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <netdb.h> -#include <sys/systeminfo.h> #include <papi.h> #include <uri.h> @@ -91,7 +91,7 @@ /* duplicate the name because gethostbyXXXX() is not reentrant */ hostname = strdup(hp->h_name); - (void) sysinfo(SI_HOSTNAME, myname, sizeof (myname)); + gethostname(myname, sizeof (myname)); /* is it from one of my addresses ? */ if ((hp = getipnodebyname(myname, AF_INET6, AI_ALL|AI_V4MAPPED, @@ -612,7 +612,7 @@ } /* is it the local host? */ - sysinfo(SI_HOSTNAME, buf, sizeof (buf)); + gethostname(buf, sizeof (buf)); if ((strcasecmp(uri->host, "localhost") != 0) && (strcasecmp(uri->host, buf) != 0)) { uri_free(uri); Modified: trunk/papi/source/bsd-sysv-commands/lpstat.c =================================================================== --- trunk/papi/source/bsd-sysv-commands/lpstat.c 2007-02-03 02:35:26 UTC (rev 183) +++ trunk/papi/source/bsd-sysv-commands/lpstat.c 2007-07-31 17:04:09 UTC (rev 184) @@ -33,6 +33,7 @@ #include <string.h> #include <locale.h> #include <libintl.h> +#include <ctype.h> #include <pwd.h> #include <papi.h> #include <uri.h> @@ -531,10 +532,14 @@ status = papiServiceCreate(&svc, name, NULL, NULL, cli_auth_callback, encryption, NULL); if (status != PAPI_OK) { - fprintf(stderr, gettext( - "Failed to contact service for %s: %s\n"), - name ? name : "(NULL)", - verbose_papi_message(svc, status)); + if (status == PAPI_NOT_FOUND) + fprintf(stderr, gettext("%s: unknown printer\n"), + name ? name : "(NULL)"); + else + fprintf(stderr, gettext( + "Failed to contact service for %s: %s\n"), + name ? name : "(NULL)", + verbose_papi_message(svc, status)); papiServiceDestroy(svc); return (-1); } @@ -857,8 +862,18 @@ (void) textdomain("SUNW_OST_OSCMD"); argv = (char **)calloc((ac + 1), sizeof (char *)); - for (c = 0; c < ac; c++) - argv[c] = av[c]; + for (c = 0; c < ac; c++) { + if ((av[c][0] == '-') && (av[c][1] == 'l') && + (isalpha(av[c][2]) != 0)) { + /* preserve old "-l[po...]" behavior */ + argv[c] = &av[c][1]; + argv[c][0] = '-'; + verbose = 1; + + } else + argv[c] = av[c]; + } + argv[c++] = "--"; ac = c; Modified: trunk/papi/source/libipp-core/read.c =================================================================== --- trunk/papi/source/libipp-core/read.c 2007-02-03 02:35:26 UTC (rev 183) +++ trunk/papi/source/libipp-core/read.c 2007-07-31 17:04:09 UTC (rev 184) @@ -621,7 +621,7 @@ (void) papiAttributeListAddInteger(message, PAPI_ATTR_REPLACE, attr_name, s); - memcpy(&s, &buf[4], 4); + memcpy(&i, &buf[4], 4); i = (uint32_t)ntohl(i); (void) papiAttributeListAddInteger(message, PAPI_ATTR_REPLACE, "request-id", i); Modified: trunk/papi/source/libipp-listener/ipp-listener.c =================================================================== --- trunk/papi/source/libipp-listener/ipp-listener.c 2007-02-03 02:35:26 UTC (rev 183) +++ trunk/papi/source/libipp-listener/ipp-listener.c 2007-07-31 17:04:09 UTC (rev 184) @@ -38,7 +38,6 @@ #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> -#include <sys/systeminfo.h> #include <papi.h> #include <ipp-listener.h> @@ -397,7 +396,7 @@ } /* does the host match up */ - sysinfo(SI_HOSTNAME, buf, sizeof (buf)); + gethostname(buf, sizeof (buf)); if ((strcasecmp(uri->host, "localhost") != 0) && (strcasecmp(uri->host, buf) != 0)) { uri_free(uri); Modified: trunk/papi/source/libpapi-dynamic/nss.c =================================================================== --- trunk/papi/source/libpapi-dynamic/nss.c 2007-02-03 02:35:26 UTC (rev 183) +++ trunk/papi/source/libpapi-dynamic/nss.c 2007-07-31 17:04:09 UTC (rev 184) @@ -44,9 +44,6 @@ #include <nss_dbdefs.h> #endif #include <config-site.h> -#if defined(__sun) && defined(__SVR4) -#include <sys/systeminfo.h> -#endif static char * @@ -197,7 +194,7 @@ return (1); /* is it the {nodename} */ - sysinfo(SI_HOSTNAME, hostname, sizeof (hostname)); + gethostname(hostname, sizeof (hostname)); if (strncasecmp(host, hostname, strlen(hostname)) == 0) return (1); Modified: trunk/papi/source/libpapi-ipp/ipp-support.c =================================================================== --- trunk/papi/source/libpapi-ipp/ipp-support.c 2007-02-03 02:35:26 UTC (rev 183) +++ trunk/papi/source/libpapi-ipp/ipp-support.c 2007-07-31 17:04:09 UTC (rev 184) @@ -40,6 +40,9 @@ #include <ipp.h> +static void ipp_add_printer_uri(service_t *svc, char *name, + papi_attribute_t ***op); + papi_status_t http_to_papi_status(http_status_t status) { @@ -161,7 +164,7 @@ void ipp_initialize_operational_attributes(service_t *svc, papi_attribute_t ***op, - papi_attribute_t **attributes) + char *printer, int job_id) { char *charset = "utf-8"; /* default to UTF-8 encoding */ char *language = setlocale(LC_ALL, ""); @@ -172,18 +175,22 @@ * All IPP requests must contain the following: * attributes-charset (UTF-8) * attributes-natural-language (our current locale) - * requesting-user-name (process user) + * (object identifier) printer-uri/job-id or job-uri + * requesting-user-name (process user or none) */ - papiAttributeListGetString(attributes, NULL, - "attributes-charset", &charset); papiAttributeListAddString(op, PAPI_ATTR_EXCL, "attributes-charset", charset); - papiAttributeListGetString(attributes, NULL, - "attributes-natural-language", &language); papiAttributeListAddString(op, PAPI_ATTR_EXCL, "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); + if ((pw = getpwuid(getuid())) != NULL) user = pw->pw_name; /* @@ -193,8 +200,6 @@ if (geteuid() == 0) { if (svc->user != NULL) user = svc->user; - papiAttributeListGetString(attributes, NULL, - "requesting-user-name", &user); } papiAttributeListAddString(op, PAPI_ATTR_REPLACE, "requesting-user-name", user); @@ -223,7 +228,7 @@ return (PAPI_TEMPORARY_ERROR); ipp_initialize_request(svc, &request, OPID_CUPS_GET_DEFAULT); - ipp_initialize_operational_attributes(svc, &op, NULL); + ipp_initialize_operational_attributes(svc, &op, NULL, -1); papiAttributeListAddString(&op, PAPI_ATTR_APPEND, "requested-attributes", "printer-uri-supported"); papiAttributeListAddCollection(&request, PAPI_ATTR_REPLACE, @@ -251,7 +256,7 @@ return (result); } -void +static void ipp_add_printer_uri(service_t *svc, char *name, papi_attribute_t ***op) { char *uri = name; Modified: trunk/papi/source/libpapi-ipp/job.c =================================================================== --- trunk/papi/source/libpapi-ipp/job.c 2007-02-03 02:35:26 UTC (rev 183) +++ trunk/papi/source/libpapi-ipp/job.c 2007-07-31 17:04:09 UTC (rev 184) @@ -123,8 +123,7 @@ ipp_initialize_request(svc, request, type); /* create an operational attributes group */ - ipp_initialize_operational_attributes(svc, &operational, NULL); - ipp_add_printer_uri(svc, printer, &operational); + ipp_initialize_operational_attributes(svc, &operational, printer, -1); /* split up the attributes into operational and job attributes */ split_and_copy_attributes(operational_names, attributes, @@ -154,11 +153,8 @@ ipp_initialize_request(svc, &request, type); /* create an operational attributes group */ - ipp_initialize_operational_attributes(svc, &op, NULL); - ipp_add_printer_uri(svc, printer, &op); + ipp_initialize_operational_attributes(svc, &op, printer, id); - papiAttributeListAddInteger(&op, PAPI_ATTR_REPLACE, "job-id", - id); papiAttributeListAddString(&op, PAPI_ATTR_REPLACE, "document-name", file); papiAttributeListAddBoolean(&op, PAPI_ATTR_REPLACE, "last-document", @@ -443,10 +439,8 @@ ipp_initialize_request(svc, &request, OPID_GET_JOB_ATTRIBUTES); - ipp_initialize_operational_attributes(svc, &op, NULL); - ipp_add_printer_uri(svc, printer, &op); + ipp_initialize_operational_attributes(svc, &op, printer, job_id); - papiAttributeListAddInteger(&op, PAPI_ATTR_REPLACE, "job-id", job_id); if (requested_attrs != NULL) { int i; @@ -489,10 +483,8 @@ ipp_initialize_request(svc, &request, type); - ipp_initialize_operational_attributes(svc, &op, NULL); - ipp_add_printer_uri(svc, printer, &op); + ipp_initialize_operational_attributes(svc, &op, printer, job_id); - papiAttributeListAddInteger(&op, PAPI_ATTR_REPLACE, "job-id", job_id); papiAttributeListAddCollection(&request, PAPI_ATTR_REPLACE, "operational-attributes-group", op); papiAttributeListFree(op); @@ -558,10 +550,8 @@ ipp_initialize_request(svc, &request, OPID_CUPS_MOVE_JOB); - ipp_initialize_operational_attributes(svc, &op, NULL); - ipp_add_printer_uri(svc, printer, &op); + ipp_initialize_operational_attributes(svc, &op, printer, job_id); - papiAttributeListAddInteger(&op, PAPI_ATTR_REPLACE, "job-id", job_id); papiAttributeListAddCollection(&request, PAPI_ATTR_REPLACE, "operational-attributes-group", op); papiAttributeListFree(op); @@ -603,10 +593,8 @@ ipp_initialize_request(svc, &request, OPID_SET_JOB_ATTRIBUTES); - ipp_initialize_operational_attributes(svc, &op, NULL); - ipp_add_printer_uri(svc, printer, &op); + ipp_initialize_operational_attributes(svc, &op, printer, job_id); - papiAttributeListAddInteger(&op, PAPI_ATTR_REPLACE, "job-id", job_id); papiAttributeListAddCollection(&request, PAPI_ATTR_REPLACE, "operational-attributes-group", op); papiAttributeListFree(op); Modified: trunk/papi/source/libpapi-ipp/papi_impl.h =================================================================== --- trunk/papi/source/libpapi-ipp/papi_impl.h 2007-02-03 02:35:26 UTC (rev 183) +++ trunk/papi/source/libpapi-ipp/papi_impl.h 2007-07-31 17:04:09 UTC (rev 184) @@ -94,13 +94,10 @@ papi_attribute_t ***request, uint16_t type); extern void ipp_initialize_operational_attributes(service_t *svc, papi_attribute_t ***op, - papi_attribute_t **attributes); + char *printer, int job_id); extern papi_status_t ipp_to_papi_status(uint16_t status); extern papi_status_t http_to_papi_status(http_status_t status); -extern void ipp_add_printer_uri(service_t *svc, char *name, - papi_attribute_t ***op); - /* service related interfaces */ extern void detailed_error(service_t *svc, char *fmt, ...); extern papi_status_t service_connect(service_t *svc, char *service_name); Modified: trunk/papi/source/libpapi-ipp/printer.c =================================================================== --- trunk/papi/source/libpapi-ipp/printer.c 2007-02-03 02:35:26 UTC (rev 183) +++ trunk/papi/source/libpapi-ipp/printer.c 2007-07-31 17:04:09 UTC (rev 184) @@ -94,7 +94,7 @@ return (result); ipp_initialize_request(svc, &request, OPID_CUPS_GET_PRINTERS); - ipp_initialize_operational_attributes(svc, &op, NULL); + ipp_initialize_operational_attributes(svc, &op, NULL, -1); if (requested_attrs != NULL) { int i; @@ -154,8 +154,7 @@ ipp_initialize_request(svc, &request, OPID_GET_PRINTER_ATTRIBUTES); - ipp_initialize_operational_attributes(svc, &op, NULL); - ipp_add_printer_uri(svc, name, &op); + ipp_initialize_operational_attributes(svc, &op, name, -1); if (requested_attrs != NULL) { int i; @@ -198,8 +197,7 @@ ipp_initialize_request(svc, &request, type); - ipp_initialize_operational_attributes(svc, &op, NULL); - ipp_add_printer_uri(svc, name, &op); + ipp_initialize_operational_attributes(svc, &op, name, -1); switch (type) { case OPID_DISABLE_PRINTER: @@ -286,8 +284,7 @@ ipp_initialize_request(svc, &request, OPID_SET_PRINTER_ATTRIBUTES); - ipp_initialize_operational_attributes(svc, &op, NULL); - ipp_add_printer_uri(svc, name, &op); + ipp_initialize_operational_attributes(svc, &op, name, -1); papiAttributeListAddCollection(&request, PAPI_ATTR_REPLACE, "operational-attributes-group", op); @@ -334,8 +331,7 @@ ipp_initialize_request(svc, &request, OPID_PURGE_JOBS); - ipp_initialize_operational_attributes(svc, &op, NULL); - ipp_add_printer_uri(svc, name, &op); + ipp_initialize_operational_attributes(svc, &op, name, -1); papiAttributeListAddCollection(&request, PAPI_ATTR_REPLACE, "operational-attributes-group", op); @@ -383,8 +379,7 @@ ipp_initialize_request(svc, &request, OPID_GET_JOBS); - ipp_initialize_operational_attributes(svc, &op, NULL); - ipp_add_printer_uri(svc, name, &op); + ipp_initialize_operational_attributes(svc, &op, name, -1); if (requested_attrs != NULL) { int i; Modified: trunk/papi/source/libpapi-lpd/job.c =================================================================== --- trunk/papi/source/libpapi-lpd/job.c 2007-02-03 02:35:26 UTC (rev 183) +++ trunk/papi/source/libpapi-lpd/job.c 2007-07-31 17:04:09 UTC (rev 184) @@ -58,7 +58,7 @@ if (job_ticket != NULL) { detailed_error(svc, - gettext("papiJobSubmit: job ticket not supported")); + gettext("papiJobSubmit: job ticket not supported")); return (PAPI_OPERATION_NOT_SUPPORTED); } @@ -67,16 +67,19 @@ if ((*job = j = (job_t *)calloc(1, sizeof (*j))) == NULL) { detailed_error(svc, - gettext("calloc() failed")); + gettext("calloc() failed")); return (PAPI_TEMPORARY_ERROR); } /* create a control file */ - status = lpd_job_add_attributes(svc, attributes, &metadata, - &j->attributes); - status = lpd_job_add_files(svc, attributes, files, &metadata, - &j->attributes); + (void) lpd_job_add_attributes(svc, attributes, &metadata, + &j->attributes); + if ((status = lpd_job_add_files(svc, attributes, files, &metadata, + &j->attributes)) != PAPI_OK) { + return (status); + } + /* send the job to the server */ status = lpd_submit_job(svc, metadata, &j->attributes, NULL); free(metadata); @@ -92,7 +95,7 @@ papi_job_ticket_t *job_ticket, char **files, papi_job_t *job) { return (papiJobSubmit(handle, name, job_attributes, - job_ticket, files, job)); + job_ticket, files, job)); } papi_status_t @@ -131,9 +134,9 @@ char *files[] = { "standard input", NULL }; lpd_job_add_files(svc, attributes, files, &metadata, - &(s->job->attributes)); + &(s->job->attributes)); status = lpd_submit_job(svc, metadata, &(s->job->attributes), - &s->fd); + &s->fd); } else { char dfname[18]; @@ -186,9 +189,9 @@ files[1] = NULL; lpd_job_add_files(svc, s->job->attributes, files, &s->metadata, - &(s->job->attributes)); + &(s->job->attributes)); status = lpd_submit_job(svc, s->metadata, - &(s->job->attributes), NULL); + &(s->job->attributes), NULL); unlink(s->dfname); free(s->dfname); } else @@ -252,7 +255,7 @@ if (j != NULL) papiAttributeListGetString(j->attributes, NULL, - "printer-name", &result); + "printer-name", &result); return (result); } @@ -265,7 +268,7 @@ if (j != NULL) papiAttributeListGetInteger(j->attributes, NULL, - "job-id", &result); + "job-id", &result); return (result); } Modified: trunk/papi/source/libpapi-lpd/lpd-cancel.c =================================================================== --- trunk/papi/source/libpapi-lpd/lpd-cancel.c 2007-02-03 02:35:26 UTC (rev 183) +++ trunk/papi/source/libpapi-lpd/lpd-cancel.c 2007-07-31 17:04:09 UTC (rev 184) @@ -49,7 +49,7 @@ list[0] = buf; list[1] = NULL; - if ((fd = lpd_open(svc, 'c', list, 3)) < 0) + if ((fd = lpd_open(svc, 'c', list, 15)) < 0) return (PAPI_INTERNAL_ERROR); memset(buf, 0, sizeof (buf)); @@ -80,7 +80,7 @@ if (svc == NULL) return (PAPI_BAD_ARGUMENT); - if ((fd = lpd_open(svc, 'c', NULL, 3)) < 0) + if ((fd = lpd_open(svc, 'c', NULL, 15)) < 0) return (PAPI_INTERNAL_ERROR); queue = queue_name_from_uri(svc->uri); Modified: trunk/papi/source/libpapi-lpd/lpd-job.c =================================================================== --- trunk/papi/source/libpapi-lpd/lpd-job.c 2007-02-03 02:35:26 UTC (rev 183) +++ trunk/papi/source/libpapi-lpd/lpd-job.c 2007-07-31 17:04:09 UTC (rev 184) @@ -504,7 +504,7 @@ list[0] = path; list[1] = NULL; - if (((fd = lpd_open(svc, 's', list, 3)) < 0) && (errno != EBADMSG)) { + if (((fd = lpd_open(svc, 's', list, 15)) < 0) && (errno != EBADMSG)) { switch (errno) { case ENOSPC: status = PAPI_TEMPORARY_ERROR; Modified: trunk/papi/source/libpapi-lpd/lpd-misc.c =================================================================== --- trunk/papi/source/libpapi-lpd/lpd-misc.c 2007-02-03 02:35:26 UTC (rev 183) +++ trunk/papi/source/libpapi-lpd/lpd-misc.c 2007-07-31 17:04:09 UTC (rev 184) @@ -127,7 +127,7 @@ { int ac, rc = -1, fds[2]; pid_t pid; - char *av[64], buf[BUFSIZ]; + char *av[64], *tmp, buf[BUFSIZ]; if ((svc == NULL) || (svc->uri == NULL)) return (-1); @@ -137,18 +137,30 @@ #endif av[0] = SUID_LPD_PORT; ac = 1; - uri_to_string(svc->uri, buf, sizeof (buf)); - av[ac++] = "-u"; - av[ac++] = strdup(buf); + /* server */ + av[ac++] = "-H"; + av[ac++] = svc->uri->host; + + /* timeout */ if (timeout > 0) { snprintf(buf, sizeof (buf), "%d", timeout); av[ac++] = "-t"; av[ac++] = strdup(buf); } + + /* operation */ snprintf(buf, sizeof (buf), "-%c", type); av[ac++] = buf; + /* queue */ + if ((tmp = strrchr(svc->uri->path, '/')) == NULL) + tmp = svc->uri->path; + else + tmp++; + av[ac++] = tmp; + + /* args */ if (args != NULL) while ((*args != NULL) && (ac < 62)) av[ac++] = *args++; Modified: trunk/papi/source/libpapi-lpd/lpd-port.c =================================================================== --- trunk/papi/source/libpapi-lpd/lpd-port.c 2007-02-03 02:35:26 UTC (rev 183) +++ trunk/papi/source/libpapi-lpd/lpd-port.c 2007-07-31 17:04:09 UTC (rev 184) @@ -50,11 +50,9 @@ #include <pwd.h> #include <sys/sendfile.h> #include <ctype.h> -#include <alloca.h> #ifdef HAVE_PRIV_H #include <priv.h> #endif -#include <papi_impl.h> #ifndef JOB_ID_FILE #define JOB_ID_FILE "/var/run/rfc-1179.seq" @@ -107,7 +105,7 @@ } static int -sock_connect(int sock, uri_t *uri, int timeout) +sock_connect(int sock, char *host, int timeout) { struct hostent *hp; struct servent *sp; @@ -120,13 +118,11 @@ int err, error_num; unsigned timo = 1; - int port = -1; - /* * Get the host address and port number to connect to. */ - if ((uri == NULL) || (uri->host == NULL)) { + if (host == NULL) { return (-1); } @@ -134,7 +130,7 @@ (void) memset((char *)&sin, (int)NULL, sizeof (sin)); #if defined(HAVE_GETIPNODEBYNAME) && defined(HAVE_RRESVPORT_AF) - if ((hp = getipnodebyname(uri->host, AF_INET6, AI_DEFAULT, + if ((hp = getipnodebyname(host, AF_INET6, AI_DEFAULT, &error_num)) == NULL) { errno = ENOENT; return (-1); @@ -142,7 +138,7 @@ (void) memcpy((caddr_t)&sin.sin6_addr, hp->h_addr, hp->h_length); sin.sin6_family = hp->h_addrtype; #else - if ((hp = gethostbyname(uri->host)) == NULL) { + if ((hp = gethostbyname(host)) == NULL) { errno = ENOENT; return (-1); } @@ -156,15 +152,10 @@ return (-1); } - if (uri->port != NULL) - port = atoi(uri->port); - if (port < 0) - port = sp->s_port; - #if defined(HAVE_GETIPNODEBYNAME) && defined(HAVE_RRESVPORT_AF) - sin.sin6_port = port; + sin.sin6_port = sp->s_port; #else - sin.sin_port = port; + sin.sin_port = sp->s_port; #endif retry: @@ -444,8 +435,9 @@ static int -submit_job(int sock, uri_t *uri, int job_id, char *path) +submit_job(int sock, char *printer, int job_id, char *path) { + struct stat st; int current = 0; off_t off = 0; char *metadata = NULL; @@ -454,30 +446,36 @@ int sent_files = 0; char buf[BUFSIZ]; size_t len; - char *printer = queue_name_from_uri(uri); - /* read in the control file */ - if ((fd = open(path, O_RDONLY)) >= 0) { - struct stat st; + /* open the control file */ + if ((fd = open(path, O_RDONLY)) < 0) { + syslog(LOG_ERR, "submit_job(%d, %s, %d, %s): open(): %m", + sock, printer, job_id, path); + return (-1); + } - if (fstat(fd, &st) < 0) { - close(fd); - return (-1); - } + /* get the size of the control file */ + if (fstat(fd, &st) < 0) { + syslog(LOG_ERR, "submit_job(%d, %s, %d, %s): fstat(): %m", + sock, printer, job_id, path); + close(fd); + return (-1); + } - metadata = alloca(st.st_size + 1); - memset(metadata, 0, st.st_size + 1); + /* allocate memory for the control file */ + if ((metadata = calloc(1, st.st_size + 1)) == NULL) { + syslog(LOG_ERR, "submit_job(%d, %s, %d, %s): calloc(): %m", + sock, printer, job_id, path); + close(fd); + return (-1); + } - if (read(fd, metadata, st.st_size) != st.st_size) { - close(fd); - free(metadata); - metadata = NULL; - return (-1); - } - - } else { - syslog(LOG_ERR, - "lpd-port:submit_job:open failed : %m path %s", path); + /* read in the control file */ + if (read(fd, metadata, st.st_size) != st.st_size) { + syslog(LOG_ERR, "submit_job(%d, %s, %d, %s): read(): %m", + sock, printer, job_id, path); + free(metadata); + close(fd); return (-1); } @@ -486,6 +484,9 @@ /* bad control data, dump the job */ syslog(LOG_ALERT, "bad control file, possible subversion attempt"); + free(metadata); + close(fd); + return (-1); } /* request to transfer the job */ @@ -545,13 +546,11 @@ return (0); } - static int -query(int fd, uri_t *uri, int ac, char **av) +query(int fd, char *printer, int ac, char **av) { char buf[BUFSIZ]; int rc, len; - char *printer = queue_name_from_uri(uri); /* build the request */ snprintf(buf, sizeof (buf), "\04%s", printer); @@ -569,11 +568,10 @@ } static int -cancel(int fd, uri_t *uri, int ac, char **av) +cancel(int fd, char *printer, int ac, char **av) { char buf[BUFSIZ]; int rc, len; - char *printer = queue_name_from_uri(uri); /* build the request */ snprintf(buf, sizeof (buf), "\05%s %s", printer, get_user_name()); @@ -602,12 +600,12 @@ else name++; - fprintf(stderr, "usage:\t%s -u uri [-t timeout] " - "[-s control ]\n", name); - fprintf(stderr, "\t%s -u uri [-t timeout] " - "[-c user|job ...]\n", name); - fprintf(stderr, "\t%s -u uri [-t timeout] " - "[-q user|job ...]\n", name); + fprintf(stderr, "usage:\t%s -H host [-t timeout] -s queue control ]\n", + name); + fprintf(stderr, "\t%s -H host [-t timeout] -c queue [user|job ...]\n", + name); + fprintf(stderr, "\t%s -H host [-t timeout] -q queue [user|job ...]\n", + name); exit(EINVAL); } @@ -626,7 +624,7 @@ { enum { OP_NONE, OP_SUBMIT, OP_QUERY, OP_CANCEL } operation = OP_NONE; int fd, c, timeout = 0, exit_code = 0; - uri_t *uri = NULL; + char *host = NULL, *queue = NULL; uid_t uid = getuid(); #ifdef PRIV_ALLSETS priv_set_t *saveset = NULL; @@ -670,44 +668,42 @@ seteuid(uid); #endif - - while ((c = getopt(ac, av, "cqst:u:")) != EOF) { + while ((c = getopt(ac, av, "H:t:c:q:s:")) != EOF) { switch (c) { + case 'H': + host = optarg; + break; + case 't': + timeout = atoi(optarg); + break; case 'c': if (operation != OP_NONE) usage(av[0]); operation = OP_CANCEL; + queue = optarg; break; case 'q': if (operation != OP_NONE) usage(av[0]); operation = OP_QUERY; + queue = optarg; break; case 's': if (operation != OP_NONE) usage(av[0]); operation = OP_SUBMIT; + queue = optarg; break; - case 't': - timeout = atoi(optarg); - break; - case 'u': - if (uri_from_string(optarg, &uri) < 0) - usage(av[0]); - break; default: usage(av[0]); /* does not return */ } } - if ((uri == NULL) || (timeout < 0) || (operation == OP_NONE)) + if ((host == NULL) || (queue == NULL) || (timeout < 0) || + (operation == OP_NONE)) usage(av[0]); - if ((strcasecmp(uri->scheme, "lpd") != 0) && - (strcasecmp(uri->scheme, "rfc-1179") != 0)) - usage(av[0]); - if (operation == OP_SUBMIT) /* get a job-id if we need it */ if ((c = next_job_id()) < 0) { syslog(LOG_ERR, "lpd_port:main:next_job_id fails"); @@ -726,23 +722,22 @@ setreuid(uid, uid); - /* connect to the print service */ - if ((fd = sock_connect(fd, uri, timeout)) < 0) + if ((fd = sock_connect(fd, host, timeout)) < 0) return (errno); /* perform the requested operation */ switch (operation) { case OP_SUBMIT: /* transfer the job, close the fd */ - if (submit_job(fd, uri, c, av[optind]) < 0) + if (submit_job(fd, queue, c, av[optind]) < 0) exit_code = errno; break; case OP_QUERY: /* send the query string, return the fd */ - if (query(fd, uri, ac - optind, &av[optind]) < 0) + if (query(fd, queue, ac - optind, &av[optind]) < 0) exit_code = errno; break; case OP_CANCEL: /* send the cancel string, return the fd */ - if (cancel(fd, uri, ac - optind, &av[optind]) < 0) + if (cancel(fd, queue, ac - optind, &av[optind]) < 0) exit_code = errno; break; default: /* This should never happen */ Modified: trunk/papi/source/libpapi-lpd/lpd-query.c =================================================================== --- trunk/papi/source/libpapi-lpd/lpd-query.c 2007-02-03 02:35:26 UTC (rev 183) +++ trunk/papi/source/libpapi-lpd/lpd-query.c 2007-07-31 17:04:09 UTC (rev 184) @@ -27,7 +27,6 @@ #pragma ident "$Id$" -#define __EXTENSIONS__ /* for strtok_r() */ #include <stdio.h> #include <stdlib.h> #include <unistd.h> @@ -38,86 +37,130 @@ #include <ctype.h> #include <string.h> #include <stdarg.h> +#include <regex.h> #include <papi_impl.h> +/* The string is modified by this call */ +static char * +regvalue(regmatch_t match, char *string) +{ + char *result = NULL; + + if (match.rm_so != match.rm_eo) { + result = string + match.rm_so; + *(result + (match.rm_eo - match.rm_so)) = '\0'; + } + + return (result); +} + +/* + * Print job entries start with: + * (user): (rank) [job (number) (...)] + * (user) is the job-owner's user name + * (rank) is the rank in queue. (active, 1st, 2nd, ...) + * (number) is the job number + * (...) is an optional hostname + * some servers will use whitespace a little differently than is displayed + * above. The regular expression below makes whitespace optional in some + * places. + */ +static char *job_expr = "^(.*[[:alnum:]]):[[:space:]]+([[:alnum:]]+)[[:space:]]+[[][[:space:]]*job[[:space:]]*([[:digit:]]+)[[:space:]]*(.*)]"; +static regex_t job_re; + +/* + * status line(s) for "processing" printers will contain one of the following: + * ready and printing + * Printing + */ +static char *proc_expr = "(ready and printing|printing)"; +static regex_t proc_re; + +/* + * status line(s) for "idle" printers will contain one of the following: + * no entries + * (printer) is ready + * idle + */ +static char *idle_expr = "(no entries|is ready| idle)"; +static regex_t idle_re; + +/* + * document line(s) + * (copies) copies of (name) (size) bytes + * (name) (size) bytes + * document lines can be in either format above. + * (copies) is the number of copies of the document to print + * (name) is the name of the document: /etc/motd, ... + * (size) is the number of bytes in the document data + */ +static char *doc1_expr = "[[:space:]]+(([[:digit:]]+) copies of )([^[:space:]]+)[[:space:]]*([[:digit:]]+) bytes"; +static char *doc2_expr = "[[:space:]]+()([^[:space:]]+)[[:space:]]*([[:digit:]]+) bytes"; +static regex_t doc1_re; +static regex_t doc2_re; + static void -parse_lpd_job_entry(service_t *svc, int fd, job_t **job) +parse_lpd_job(service_t *svc, job_t **job, int fd, char *line, int len) { - char *iter = NULL; - char line[128]; papi_attribute_t **attributes = NULL; - char *p; + regmatch_t matches[5]; + char *s; int octets = 0; - *job = NULL; + /* job_re was compiled in the calling function */ + if (regexec(&job_re, line, (size_t)5, matches, 0) == REG_NOMATCH) + return; - if (fdgets(line, sizeof (line), fd) == NULL) - return; - /* - * 1st line... - * user: rank [job (ID)(host)]\n - */ - if ((p = strtok_r(line, ": ", &iter)) == NULL) /* user: ... */ - return; /* invalid format */ + if ((s = regvalue(matches[1], line)) == NULL) + s = "nobody"; papiAttributeListAddString(&attributes, PAPI_ATTR_REPLACE, - "job-originating-user-name", p); + "job-originating-user-name", s); - p = strtok_r(NULL, "\t ", &iter); /* ...rank... */ + if ((s = regvalue(matches[2], line)) == NULL) + s = "0"; papiAttributeListAddInteger(&attributes, PAPI_ATTR_REPLACE, - "number-of-intervening-jobs", atoi(p) - 1); - p = strtok_r(NULL, " ", &iter); /* ...[job ... */ - if ((p = strtok_r(NULL, "]\n", &iter)) == NULL) /* ...(id)(hostname)] */ - return; - while (isspace(*p)) p++; + "number-of-intervening-jobs", atoi(s) - 1); + + if ((s = regvalue(matches[3], line)) == NULL) + s = "0"; papiAttributeListAddInteger(&attributes, PAPI_ATTR_REPLACE, - "job-id", atoi(p)); - while (isdigit(*(++p))); - while (isspace(*p)) p++; + "job-id", atoi(s)); + + if ((s = regvalue(matches[4], line)) == NULL) + s = svc->uri->host; papiAttributeListAddString(&attributes, PAPI_ATTR_REPLACE, - "job-originating-host-name", p); + "job-originating-host-name", s); - /* - * rest-o-lines - * [(num) copies of ]file size bytes\n - */ - while ((fdgets(line, sizeof (line), fd) != NULL) && (line[0] != '\n')) { - int copies, size; - char *q; + while ((fdgets(line, len, fd) != NULL) && + (regexec(&job_re, line, (size_t)0, NULL, 0) == REG_NOMATCH)) { + int size = 0, copies = 1; + /* process copies/documents */ - /* find the number of copies */ - if ((p = strstr(line, "copies of")) != NULL) { - copies = atoi(line); - p += 9; - } else { + /* doc1_re and doc2_re were compiled in the calling function */ + if ((regexec(&doc1_re, line, (size_t)4, matches, 0) != 0) && + (regexec(&doc2_re, line, (size_t)4, matches, 0) != 0)) + continue; + + if ((s = regvalue(matches[1], line)) == NULL) + s = "1"; + if ((copies = atoi(s)) < 1) copies = 1; - p = line; - } - papiAttributeListAddInteger(&attributes, PAPI_ATTR_EXCL, - "copies", copies); - /* eat the leading whitespace */ - while (isspace(*p) != 0) - p++; - if ((q = strstr(p, " bytes\n")) != NULL) { - /* back up to the beginning of the size */ - do { q--; } while (isdigit(*q) != 0); + if ((s = regvalue(matches[2], line)) == NULL) + s = "unknown"; + papiAttributeListAddString(&attributes, + PAPI_ATTR_APPEND, "job-name", s); + papiAttributeListAddString(&attributes, + PAPI_ATTR_APPEND, "job-file-names", s); - /* seperate the name and size */ - *q = '\0'; - q++; - - size = atoi(q); - - papiAttributeListAddString(&attributes, - PAPI_ATTR_APPEND, "job-name", p); - papiAttributeListAddString(&attributes, - PAPI_ATTR_APPEND, "job-file-names", p); - papiAttributeListAddInteger(&attributes, + if ((s = regvalue(matches[3], line)) == NULL) + s = "0"; + size = atoi(s); + papiAttributeListAddInteger(&attributes, PAPI_ATTR_APPEND, "job-file-sizes", size); - octets += (size * copies); - } + octets += (size * copies); } papiAttributeListAddInteger(&attributes, PAPI_ATTR_APPEND, @@ -131,19 +174,6 @@ (*job)->attributes = attributes; } -static void -parse_lpd_job_entries(service_t *svc, int fd) -{ - job_t *job = NULL; - - do { - parse_lpd_job_entry(svc, fd, &job); - list_append(&svc->cache->jobs, job); - } while (job != NULL); - -} - - void parse_lpd_query(service_t *svc, int fd) { @@ -151,26 +181,45 @@ cache_t *cache = NULL; int state = 0x03; /* idle */ char line[128]; - char buf[1024]; + char status[1024]; + char *s; - /* get the status line */ - if (fdgets(line, sizeof (line), fd) == NULL) - return; /* this should not happen. */ - papiAttributeListAddString(&attributes, PAPI_ATTR_APPEND, "printer-name", queue_name_from_uri(svc->uri)); - if (uri_to_string(svc->uri, buf, sizeof (buf)) == 0) + if (uri_to_string(svc->uri, status, sizeof (status)) == 0) papiAttributeListAddString(&attributes, PAPI_ATTR_APPEND, - "printer-uri-supported", buf); + "printer-uri-supported", status); + /* + * on most systems, status is a single line, but some appear to + * return multi-line status messages. To get the "best" possible + * printer-state-reason, we accumulate the text until we hit the + * first print job entry. + * + * Print job entries start with: + * user: rank [job number ...] + */ + (void) regcomp(&job_re, job_expr, REG_EXTENDED|REG_ICASE); + + status[0] = '\0'; + while ((fdgets(line, sizeof (line), fd) != NULL) && + (regexec(&job_re, line, (size_t)0, NULL, 0) == REG_NOMATCH)) { + strlcat(status, line, sizeof (status)); + } + /* chop off trailing whitespace */ + s = status + strlen(status) - 1; + while ((s > status) && (isspace(*s) != 0)) + *s-- = '\0'; + papiAttributeListAddString(&attributes, PAPI_ATTR_REPLACE, - "printer-state-reasons", line); + "printer-state-reasons", status); - if (strstr(line, "ready and printing") != NULL) + (void) regcomp(&proc_re, proc_expr, REG_EXTENDED|REG_ICASE); + (void) regcomp(&idle_re, idle_expr, REG_EXTENDED|REG_ICASE); + if (regexec(&proc_re, status, (size_t)0, NULL, 0) == 0) state = 0x04; /* processing */ - else if ((strstr(line, "no entries") != NULL) || - (strstr(line, "is ready") != NULL)) + else if (regexec(&idle_re, status, (size_t)0, NULL, 0) == 0) state = 0x03; /* idle */ else state = 0x05; /* stopped */ @@ -188,9 +237,16 @@ cache->printer->attributes = attributes; svc->cache = cache; - if (fdgets(line, sizeof (line), fd) != NULL) { - /* get the jobs */ - parse_lpd_job_entries(svc, fd); + (void) regcomp(&doc1_re, doc1_expr, REG_EXTENDED|REG_ICASE); + (void) regcomp(&doc2_re, doc2_expr, REG_EXTENDED|REG_ICASE); + /* process job related entries */ + while (line[0] != '\0') { + job_t *job = NULL; + + parse_lpd_job(svc, &job, fd, line, sizeof (line)); + if (job == NULL) + break; + list_append(&cache->jobs, job); } time(&cache->timestamp); @@ -207,7 +263,7 @@ if (svc == NULL) return; - if ((fd = lpd_open(svc, 'q', NULL, 3)) < 0) + if ((fd = lpd_open(svc, 'q', NULL, 15)) < 0) return; parse_lpd_query(svc, fd); Modified: trunk/papi/source/libpapi-lpd/printer.c =================================================================== --- trunk/papi/source/libpapi-lpd/printer.c 2007-02-03 02:35:26 UTC (rev 183) +++ trunk/papi/source/libpapi-lpd/printer.c 2007-07-31 17:04:09 UTC (rev 184) @@ -81,6 +81,12 @@ PAPI_ATTR_APPEND, "printer-uri-supported", buf); } + /* Set printer accepting: mimic prepapi behavior */ + if ((p = *printer) != NULL) + papiAttributeListAddBoolean(&(p->attributes), + PAPI_ATTR_REPLACE, + "printer-is-accepting-jobs", PAPI_TRUE); + } return (status); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nj...@us...> - 2007-02-03 02:35:28
|
Revision: 183 http://svn.sourceforge.net/openprinting/?rev=183&view=rev Author: njacobs Date: 2007-02-02 18:35:26 -0800 (Fri, 02 Feb 2007) Log Message: ----------- Resync with Solaris fixes... check for cycles in IPP requests. list_remove should give back space. use built-in md5 support when available lpstat should report form info lp/lpr use incorrect mime-types SF1152246 in.lpd does not create print jobs Modified Paths: -------------- trunk/papi/ChangeLog trunk/papi/source/bsd-sysv-commands/common.c trunk/papi/source/bsd-sysv-commands/common.h trunk/papi/source/bsd-sysv-commands/in.lpd.c trunk/papi/source/bsd-sysv-commands/lp.c trunk/papi/source/bsd-sysv-commands/lpr.c trunk/papi/source/bsd-sysv-commands/lpstat.c trunk/papi/source/libipp-listener/ipp-listener.c trunk/papi/source/libpapi-common/attribute.c trunk/papi/source/libpapi-common/common.c trunk/papi/source/libpapi-common/list.c trunk/papi/source/libpapi-common/mapfile.in trunk/papi/source/libpapi-common/papi.h trunk/papi/source/libpapi-dynamic/mapfile.in trunk/papi/source/libpapi-ipp/ipp-support.c trunk/papi/source/libpapi-ipp/mapfile.in trunk/papi/source/libpapi-lpd/lpd-job.c trunk/papi/source/libpapi-lpd/mapfile.in Modified: trunk/papi/ChangeLog =================================================================== --- trunk/papi/ChangeLog 2007-02-03 01:40:22 UTC (rev 182) +++ trunk/papi/ChangeLog 2007-02-03 02:35:26 UTC (rev 183) @@ -1,4 +1,28 @@ 2007-02-02 Norm Jacobs <Norm.Jacobs@Sun.COM> + * source/libipp-listener/ipp-listener.c + * source/libpapi-common/papi.h + * source/libpapi-common/common.c + * source/libpapi-common/mapfile.in + * source/libpapi-dynamic/mapfile.in + * source/libpapi-ipp/mapfile.in + * source/libpapi-lpd/mapfile.in + check for cycles in IPP requests. + * source/libpapi-common/attribute.c + * source/libpapi-common/list.c + list_remove should give back space. + * source/libpapi-ipp/ipp-support.c + use built-in md5 support when available + * source/bsd-sysv-commands/lpstat.c + lpstat should report form info + * source/bsd-sysv-commands/lp.c + * source/bsd-sysv-commands/lpr.c + * source/bsd-sysv-commands/common.h + * source/libpapi-lpd/lpd-job.c + lp/lpr use incorrect mime-types + * source/bsd-sysv-commands/in.lpd.c + SF1152246 in.lpd does not create print jobs + +2007-02-02 Norm Jacobs <Norm.Jacobs@Sun.COM> * docs/man/Makefile.am * docs/man/README * docs/man/libpapi.3lib.in Modified: trunk/papi/source/bsd-sysv-commands/common.c =================================================================== --- trunk/papi/source/bsd-sysv-commands/common.c 2007-02-03 01:40:22 UTC (rev 182) +++ trunk/papi/source/bsd-sysv-commands/common.c 2007-02-03 02:35:26 UTC (rev 183) @@ -30,6 +30,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> @@ -72,6 +75,41 @@ 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 */ @@ -155,6 +193,8 @@ "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)) @@ -224,9 +264,9 @@ 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; @@ -369,6 +409,35 @@ 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) { Modified: trunk/papi/source/bsd-sysv-commands/common.h =================================================================== --- trunk/papi/source/bsd-sysv-commands/common.h 2007-02-03 01:40:22 UTC (rev 182) +++ trunk/papi/source/bsd-sysv-commands/common.h 2007-02-03 02:35:26 UTC (rev 183) @@ -54,6 +54,8 @@ extern char **interest_list(papi_service_t svc); extern char *localhostname(); +extern char *lp_type_to_mime_type(char *lp_type); +extern int is_postscript(const char *file); extern int cli_auth_callback(papi_service_t svc, void *app_data); Modified: trunk/papi/source/bsd-sysv-commands/in.lpd.c =================================================================== --- trunk/papi/source/bsd-sysv-commands/in.lpd.c 2007-02-03 01:40:22 UTC (rev 182) +++ trunk/papi/source/bsd-sysv-commands/in.lpd.c 2007-02-03 02:35:26 UTC (rev 183) @@ -29,13 +29,25 @@ #include <stdio.h> #include <stdlib.h> +#include <unistd.h> +#include <fcntl.h> #include <stdarg.h> #include <string.h> #include <errno.h> #include <syslog.h> #include <libintl.h> +#include <pwd.h> +#include <grp.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <netdb.h> +#include <sys/systeminfo.h> #include <papi.h> +#include <uri.h> #include "common.h" #define ACK(fp) { (void) fputc('\0', fp); (void) fflush(fp); } @@ -46,7 +58,61 @@ * code assumes a BSD Socket interface to the networking side. */ -void +static char * +remote_host_name(FILE *fp) +{ + struct hostent *hp; + struct sockaddr_in6 peer; + socklen_t peer_len = sizeof (peer); + int fd = fileno(fp); + int error_num; + char myname[MAXHOSTNAMELEN], tmp_buf[INET6_ADDRSTRLEN]; + char *hostname; + + /* who is our peer ? */ + if (getpeername(fd, (struct sockaddr *)&peer, &peer_len) < 0) { + if ((errno != ENOTSOCK) && (errno != EINVAL)) + return (NULL); + else + return (strdup("localhost")); + } + + /* get their name or return a string containing their address */ + if ((hp = getipnodebyaddr((const char *)&peer.sin6_addr, + sizeof (struct in6_addr), AF_INET6, + &error_num)) == NULL) { + return (strdup(inet_ntop(peer.sin6_family, + &peer.sin6_addr, tmp_buf, sizeof (tmp_buf)))); + } + + /* is it "localhost" ? */ + if (strcasecmp(hp->h_name, "localhost") == 0) + return (strdup("localhost")); + + /* duplicate the name because gethostbyXXXX() is not reentrant */ + hostname = strdup(hp->h_name); + (void) sysinfo(SI_HOSTNAME, myname, sizeof (myname)); + + /* is it from one of my addresses ? */ + if ((hp = getipnodebyname(myname, AF_INET6, AI_ALL|AI_V4MAPPED, + &error_num)) != NULL) { + struct in6_addr **tmp = (struct in6_addr **)hp->h_addr_list; + int i = 0; + + while (tmp[i] != NULL) { + if (memcmp(tmp[i++], &peer.sin6_addr, hp->h_length) + == 0) { + free(hostname); + return (strdup("localhost")); + } + } + } + + /* It must be someone else */ + return (hostname); +} + +static void fatal(FILE *fp, char *fmt, ...) { va_list ap; @@ -55,62 +121,440 @@ vsyslog(LOG_DEBUG, fmt, ap); vfprintf(fp, fmt, ap); va_end(ap); + exit(1); } static void -cleanup(char **files) +cleanup(char ***files, char **cf) { - if (files != NULL) { + if (*files != NULL) { int i; - for (i = 0; files[i] != NULL; i++) - unlink(files[i]); + for (i = 0; (*files)[i] != NULL; i++) { + (void) unlink((*files)[i]); + free((*files)[i]); + } + free(*files); + *files = NULL; } + + if (*cf != NULL) { + free(*cf); + *cf = NULL; + } } -static void -berkeley_receive_files(papi_service_t svc, FILE *ifp, FILE *ofp) +static papi_attribute_t ** +parse_cf(papi_service_t svc, char *cf, char **files) { - char line[BUFSIZ]; - char **files = NULL; /* the job data files */ + papi_attribute_t **list = NULL; + char previous = NULL, + *entry, + *s, + text[BUFSIZ]; + int count = 0, + copies_set = 0, + copies = 0; - /* This should actually implement transfer job from RFC-1179 */ - ACK(ofp); + for (entry = strtok(cf, "\n"); entry != NULL; + entry = strtok(NULL, "\n")) { + char *format = NULL; - while (fgets(line, sizeof (line), ifp) != NULL) { - switch (line[0]) { - case 0x01: /* Abort */ - cleanup(files); + /* count the copies */ + if ((entry[0] >= 'a') && (entry[0] <= 'z') && + (copies_set == 0) && (previous == entry[0])) + copies++; + else if ((previous >= 'a') && (previous <= 'z')) + copies_set = 1; + previous = entry[0]; + + /* process the control message */ + switch (entry[0]) { + /* RFC-1179 options */ + case 'J': /* RFC-1179 Banner Job Name */ + papiAttributeListAddString(&list, PAPI_ATTR_EXCL, + "job-name", ++entry); break; - case 0x02: /* Receive control file */ + case 'C': /* RFC-1179 Banner Class Name */ + papiAttributeListAddString(&list, PAPI_ATTR_EXCL, + "rfc-1179-class", ++entry); + break; + case 'L': /* RFC-1179 Banner toggle */ + papiAttributeListAddString(&list, PAPI_ATTR_EXCL, + "job-sheets", "standard"); + break; + case 'T': /* RFC-1179 Title (pr) */ + papiAttributeListAddString(&list, PAPI_ATTR_EXCL, + "pr-title", ++entry); + break; + case 'H': /* RFC-1179 Host */ + /* + * use the host as known by us, not by them + * + * papiAttributeListAddString(&list, PAPI_ATTR_EXCL, + * "job-originating-host-name", ++entry); + */ + break; + case 'P': /* RFC-1179 User */ + ++entry; + papiAttributeListAddString(&list, PAPI_ATTR_EXCL, + "requesting-user-name", entry); + papiServiceSetUserName(svc, entry); + break; + case 'M': /* RFC-1179 Mail to User */ + papiAttributeListAddBoolean(&list, PAPI_ATTR_EXCL, + "rfc-1179-mail", 1); + break; + case 'W': /* RFC-1179 Width (pr) */ + papiAttributeListAddInteger(&list, PAPI_ATTR_EXCL, + "pr-width", atoi(++entry)); + break; + case 'I': /* RFC-1179 Indent (pr) */ + papiAttributeListAddInteger(&list, PAPI_ATTR_EXCL, + "pr-indent", atoi(++entry)); + break; + case 'N': /* RFC-1179 Filename */ + /* could have HPUX extension embedded */ + if (entry[1] != ' ') { /* real pathname */ +#ifdef DEBUG + papiAttributeListAddString(&list, + PAPI_ATTR_EXCL, + "flist", ++entry); +#endif + } else if (entry[2] == 'O') /* HPUX lp -o options */ + papiAttributeListFromString(&list, + PAPI_ATTR_APPEND, ++entry); + break; + case 'U': /* RFC-1179 Unlink */ + break; /* ignored */ + case '1': /* RFC-1179 TROFF Font R */ + papiAttributeListAddString(&list, PAPI_ATTR_EXCL, + "rfc-1179-font-r", ++entry); + break; + case '2': /* RFC-1179 TROFF Font I */ + papiAttributeListAddString(&list, PAPI_ATTR_EXCL, + "rfc-1179-font-i", ++entry); + break; + case '3': /* RFC-1179 TROFF Font B */ + papiAttributeListAddString(&list, PAPI_ATTR_EXCL, + "rfc-1179-font-b", ++entry); + break; + case '4': /* RFC-1179 TROFF Font S */ + papiAttributeListAddString(&list, PAPI_ATTR_EXCL, + "rfc-1179-font-s", ++entry); + break; + case 'f': /* RFC-1179 ASCII file (print) */ + format = "text/plain"; + if (is_postscript(files[0]) == 1) + format = "application/postscript"; + break; + case 'l': /* RFC-1179 CATV file (print) */ + format = "application/octet-stream"; + if (is_postscript(files[0]) == 1) + format = "application/postscript"; + break; + case 'o': /* RFC-1179 Postscript file (print) */ + format = "application/postscript"; + break; + case 'p': /* RFC-1179 PR file (print) */ + format = "application/x-pr"; + papiAttributeListAddBoolean(&list, PAPI_ATTR_EXCL, + "pr-filter", 1); + break; + case 't': /* RFC-1179 TROFF file (print) */ + format = "application/x-troff"; + break; + case 'n': /* RFC-1179 DITROFF file (print) */ + format = "application/x-ditroff"; + break; + case 'd': /* RFC-1179 DVI file (print) */ + format = "application/x-dvi"; + break; + case 'g': /* RFC-1179 GRAPH file (print) */ + format = "application/x-plot"; + break; + case 'c': /* RFC-1179 CIF file (print) */ + format = "application/x-cif"; + break; + case 'v': /* RFC-1179 RASTER file (print) */ + format = "application/x-raster"; + break; + case 'r': /* RFC-1179 FORTRAN file (print) */ + format = "application/x-fortran"; + break; + /* Sun Solaris Extensions */ + case 'O': + ++entry; + do { + if (*entry != '"') + text[count++] = *entry; + } while (*entry++); + papiAttributeListFromString(&list, PAPI_ATTR_APPEND, + text); + break; + case '5': + ++entry; + switch (entry[0]) { + case 'f': /* Solaris form */ + papiAttributeListAddString(&list, + PAPI_ATTR_EXCL, + "form", ++entry); + break; + case 'H': /* Solaris handling */ + ++entry; + if (strcasecmp(entry, "hold") == 0) + papiAttributeListAddString(&list, + PAPI_ATTR_EXCL, + "job-hold-until", "indefinite"); + else if (strcasecmp(entry, "release") == 0) + papiAttributeListAddString(&list, + PAPI_ATTR_EXCL, + "job-hold-until", "no-hold"); + else if (strcasecmp(entry, "immediate") == 0) + papiAttributeListAddInteger(&list, + PAPI_ATTR_EXCL, + "job-priority", 100); + else + papiAttributeListAddString(&list, + PAPI_ATTR_EXCL, + "job-hold-until", entry); + break; + case 'p': /* Solaris notification */ + papiAttributeListAddBoolean(&list, + PAPI_ATTR_EXCL, "rfc-1179-mail", 1); + break; + case 'P': /* Solaris page list */ + papiAttributeListAddString(&list, + PAPI_ATTR_EXCL, + "page-ranges", ++entry); + break; + case 'q': { /* Solaris priority */ + int i = atoi(optarg); + i = 99 * (39 - i) / 39 + 1; + if ((i < 1) || (i > 100)) + i = 50; + papiAttributeListAddInteger(&list, + PAPI_ATTR_EXCL, "priority", i); + } + break; + case 'S': /* Solaris character set */ + papiAttributeListAddString(&list, + PAPI_ATTR_EXCL, "lp-charset", + ++entry); + break; + case 'T': /* Solaris type */ + format = lp_type_to_mime_type(++entry); + break; + case 'y': /* Solaris mode */ + papiAttributeListAddString(&list, + PAPI_ATTR_APPEND, "lp-modes", ++entry); + break; + default: + syslog(LOG_INFO|LOG_DEBUG, + "Warning: cf message (%s) ignored", + entry); + break; + } break; - case 0x03: { /* Receive data file */ - char file[] = "lpdXXXXXX"; - int fd; + /* Undefined Extensions: SCO, Ultrix, AIX, ... */ - fd = mkstemp(file); + default: + syslog(LOG_INFO|LOG_DEBUG, + "Warning: cf message (%s) ignored", entry); + break; + } - list_append(&files, strdup(file)); + if (format != NULL) + papiAttributeListAddString(&list, PAPI_ATTR_EXCL, + "document-format", format); + } + + papiAttributeListAddInteger(&list, PAPI_ATTR_EXCL, + "copies", ++copies); + papiAttributeListAddString(&list, PAPI_ATTR_EXCL, + "job-sheets", "none"); + + return (list); +} + +static papi_status_t +submit_job(papi_service_t svc, FILE *ifp, char *printer, char *cf, char **files) +{ + papi_attribute_t **list = NULL; + papi_status_t status; + papi_job_t job = NULL; + char *format = ""; + + if ((list = parse_cf(svc, cf, files)) != NULL) { + /* use the host as known by us, not by them */ + char *host = remote_host_name(ifp); + + if (host != NULL) { + papiAttributeListAddString(&list, PAPI_ATTR_REPLACE, + "job-originating-host-name", host); + free(host); + } + } + + status = papiJobSubmit(svc, printer, list, NULL, files, &job); + syslog(LOG_DEBUG, "submit: %s", papiStatusString(status)); + if (status != PAPI_OK) { + char *tmp = papiServiceGetStatusMessage(svc); + + syslog(LOG_DEBUG, "submit-detail: %s", tmp ? tmp : "none"); + } + papiJobFree(job); + + return (status); +} + +static char * +receive_control_file(papi_service_t svc, FILE *ifp, FILE *ofp, int size) +{ + char *ptr, *cf_data; + + if ((ptr = cf_data = calloc(1, size + 1)) == NULL) { + NACK(ofp); + return (NULL); + } else + ACK(ofp); + + while (size > 0) { + int rc; + + if (((rc = fread(ptr, 1, size, ifp)) == 0) && + (feof(ifp) != 0)) { + free(cf_data); + return (NULL); + } else { + ptr += rc; + size -= rc; + } + } + syslog(LOG_DEBUG, "cf_data(%s)", cf_data); + + if (fgetc(ifp) != 0) { + free(cf_data); + return (NULL); + } + ACK(ofp); + + return (cf_data); +} + +static char * +receive_data_file(FILE *ifp, FILE *ofp, int size) +{ + char file[] = "lpdXXXXXX"; + char buf[BUFSIZ]; + int fd; + + if ((fd = mkstemp(file)) < 0) { + NACK(ofp); + return (NULL); + } else + ACK(ofp); + + while (size > 0) { + int rc = ((size > BUFSIZ) ? BUFSIZ : size); + + if (((rc = fread(buf, 1, rc, ifp)) == 0) && + (feof(ifp) != 0)) { + close(fd); + unlink(file); + return (NULL); + } else { + char *ptr = buf; + + while (rc > 0) { + int wrc = write(fd, ptr, rc); + + if (wrc < 0) { + close(fd); + unlink(file); + return (NULL); + } + + ptr += wrc; + size -= wrc; + rc -= wrc; } + } + } + close(fd); + if (fgetc(ifp) != 0) { + unlink(file); + return (NULL); + } + ACK(ofp); + + return (strdup(file)); +} + +static papi_status_t +berkeley_receive_files(papi_service_t svc, FILE *ifp, FILE *ofp, char *printer) +{ + papi_status_t status = PAPI_OK; + char *file, **files = NULL; /* the job data files */ + char *cf = NULL; + char buf[BUFSIZ]; + + while (fgets(buf, sizeof (buf), ifp) != NULL) { + int size; + + syslog(LOG_DEBUG, "XFER CMD: (%d)%s\n", buf[0], &buf[1]); +#ifdef DEBUG /* translate [1-3]... messages to \[1-3] to run by hand */ + if ((buf[0] > '0') && (buf[0] < '4')) + buf[0] -= '0'; +#endif + switch (buf[0]) { + case 0x01: /* Abort */ + cleanup(&files, &cf); break; + case 0x02: { /* Receive control file */ + cf = receive_control_file(svc, ifp, ofp, atoi(&buf[1])); + if (cf == NULL) { + cleanup(&files, &cf); + return (PAPI_BAD_REQUEST); + } else if (files != NULL) { + status = submit_job(svc, ifp, printer, cf, + files); + cleanup(&files, &cf); + } + } + break; + case 0x03: { /* Receive data file */ + file = receive_data_file(ifp, ofp, atoi(&buf[1])); + if (file == NULL) { + cleanup(&files, &cf); + return (PAPI_TEMPORARY_ERROR); + } + list_append(&files, file); + } + break; default: + cleanup(&files, &cf); fatal(ofp, "protocol screwup"); - cleanup(files); break; } } - cleanup(files); + if ((cf != NULL) && (files != NULL)) + status = submit_job(svc, ifp, printer, cf, files); + + cleanup(&files, &cf); + + return (status); } -static void +static papi_status_t berkeley_transfer_files(papi_service_t svc, FILE *ifp, FILE *ofp, char *printer) { papi_status_t status; papi_printer_t p = NULL; - char *keys[] = { "printer-is-accepting", NULL }; + char *keys[] = { "printer-is-accepting-jobs", NULL }; status = papiPrinterQuery(svc, printer, keys, NULL, &p); if ((status == PAPI_OK) && (p != NULL)) { @@ -118,18 +562,68 @@ char accepting = PAPI_FALSE; papiAttributeListGetBoolean(attrs, NULL, - "printer-is-accepting", &accepting); + "printer-is-accepting-jobs", &accepting); - if (accepting == PAPI_TRUE) - berkeley_receive_files(svc, ifp, ofp); - else + if (accepting == PAPI_TRUE) { + ACK(ofp); + status = berkeley_receive_files(svc, ifp, ofp, printer); + } else NACK(ofp); papiPrinterFree(p); } else NACK(ofp); + + return (status); } +static int +cyclical_service_check(char *svc_name) +{ + papi_attribute_t **list; + char buf[BUFSIZ]; + uri_t *uri = NULL; + char *s = NULL; + + /* was there a printer? */ + if (svc_name == NULL) + return (0); + + if ((list = getprinterbyname(svc_name, NULL)) == NULL) + return (0); /* if it doesnt' resolve, we will fail later */ + + papiAttributeListGetString(list, NULL, "printer-uri-supported", &s); + if ((s == NULL) || (strcasecmp(svc_name, s) != 0)) + return (0); /* they don't match */ + + /* is it in uri form? */ + if (uri_from_string(s, &uri) < 0) + return (0); + + if ((uri == NULL) || (uri->scheme == NULL) || (uri->host == NULL)) { + uri_free(uri); + return (0); + } + + /* is it in lpd form? */ + if (strcasecmp(uri->scheme, "lpd") != 0) { + uri_free(uri); + return (0); + } + + /* is it the local host? */ + sysinfo(SI_HOSTNAME, buf, sizeof (buf)); + if ((strcasecmp(uri->host, "localhost") != 0) && + (strcasecmp(uri->host, buf) != 0)) { + uri_free(uri); + return (0); + } + + uri_free(uri); + return (1); +} + + /* * This is the entry point for this program. The program takes the * following options: @@ -146,20 +640,54 @@ int c; char buf[BUFSIZ], **args, - *printer; + *printer, + *run_dir = "/var/run/in.lpd", + *run_user = NULL; + struct passwd *pw = NULL; + (void) chdir("/tmp"); /* run in /tmp by default */ openlog("bsd-gw", LOG_PID, LOG_LPR); - while ((c = getopt(ac, av, "d")) != EOF) + while ((c = getopt(ac, av, "Ed:u:")) != EOF) switch (c) { case 'E': encryption = PAPI_ENCRYPT_ALWAYS; break; - case 'd': + case 'd': /* run where they tell you */ + run_dir = optarg; + break; + case 'u': /* run as */ + run_user = optarg; + break; default: ; } + if (run_user != NULL) /* get the requested user info */ + pw = getpwnam(run_user); + + if (run_dir != NULL) { /* setup the run_dir */ + (void) mkdir(run_dir, 0700); + if (pw != NULL) + (void) chown(run_dir, pw->pw_uid, pw->pw_gid); + } + + if (pw != NULL) { /* run as the requested user */ + syslog(LOG_DEBUG, "name: %s, uid: %d, gid: %d", + pw->pw_name, pw->pw_uid, pw->pw_gid); + initgroups(pw->pw_name, pw->pw_gid); + setgid(pw->pw_gid); + setuid(pw->pw_uid); + } + + if (run_dir != NULL) /* move to the run_dir */ + if (chdir(run_dir) < 0) { + syslog(LOG_DEBUG, "failed to chdir(%s)", run_dir); + exit(1); + } + + syslog(LOG_DEBUG, "$CWD = %s", getwd(NULL)); + if (fgets(buf, sizeof (buf), ifp) == NULL) { if (feof(ifp) == 0) syslog(LOG_ERR, "Error reading from connection: %s", @@ -167,6 +695,13 @@ exit(1); } + syslog(LOG_DEBUG, "CMD: (%d)%s\n", buf[0], &buf[1]); + +#ifdef DEBUG /* translate [1-5]... messages to \[1-5] to run by hand */ + if ((buf[0] > '0') && (buf[0] < '6')) + buf[0] -= '0'; +#endif + if ((buf[0] < 1) || (buf[0] > 5)) { fatal(ofp, "Invalid protocol request (%d): %c%s\n", buf[0], buf[0], buf); @@ -181,6 +716,11 @@ exit(1); } + if (cyclical_service_check(printer) != 0) { + fatal(ofp, "%s is cyclical\n", printer); + exit(1); + } + status = papiServiceCreate(&svc, printer, NULL, NULL, NULL, encryption, NULL); if (status != PAPI_OK) { @@ -189,20 +729,19 @@ exit(1); } -#ifdef HAVE_IS_SYSTEM_LABELED - if (is_system_labeled()) { - int fd = fileno(ifp); + /* + * Trusted Solaris can't be trusting of intermediaries. Pass + * the socket connection to the print service to retrieve the + * sensativity label off of a multi-level port. + */ + (void) papiServiceSetPeer(svc, fileno(ifp)); - (void) papiServiceSetPeer(svc, fd); - } -#endif - switch (buf[0]) { case '\1': /* restart printer */ ACK(ofp); /* there is no equivalent */ break; case '\2': /* transfer job(s) */ - berkeley_transfer_files(svc, ifp, ofp, printer); + status = berkeley_transfer_files(svc, ifp, ofp, printer); break; case '\3': /* show queue (short) */ case '\4': { /* show queue (long) */ @@ -214,10 +753,18 @@ } break; case '\5': { /* cancel job(s) */ - char *requestor = *args++; + char *user = *args++; + char *host = remote_host_name(ifp); int count; - status = papiServiceSetUserName(svc, requestor); + if (host != NULL) { + char buf[BUFSIZ]; + + snprintf(buf, sizeof (buf), "%s@%s", user, host); + status = papiServiceSetUserName(svc, buf); + } else + status = papiServiceSetUserName(svc, user); + for (count = 0; args[count] != 0; count++); berkeley_cancel_request(svc, ofp, printer, count, args); @@ -232,7 +779,9 @@ syslog(LOG_DEBUG, "protocol request(%d) for %s completed: %s", buf[0], printer, papiStatusString(status)); - syslog(LOG_DEBUG, "detail: %s", verbose_papi_message(svc, status)); + if (status != PAPI_OK) + syslog(LOG_DEBUG, "detail: %s", + verbose_papi_message(svc, status)); papiServiceDestroy(svc); Modified: trunk/papi/source/bsd-sysv-commands/lp.c =================================================================== --- trunk/papi/source/bsd-sysv-commands/lp.c 2007-02-03 01:40:22 UTC (rev 182) +++ trunk/papi/source/bsd-sysv-commands/lp.c 2007-02-03 02:35:26 UTC (rev 183) @@ -60,41 +60,6 @@ exit(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} -}; - -static 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); -} - int main(int ac, char *av[]) { @@ -159,7 +124,7 @@ break; case 'f': /* form */ papiAttributeListAddString(&list, PAPI_ATTR_EXCL, - "media", optarg); + "form", optarg); break; case 'i': /* modify job */ if ((get_printer_id(optarg, &printer, &modify) < 0) || @@ -248,19 +213,22 @@ optind = ac; if (modify == -1) { - char *document_format = "application/octet-stream"; + char *document_format = "text/plain"; -#ifdef MAGIC_MIME if (optind != ac) { /* get the mime type of the file data */ +#ifdef MAGIC_MIME magic_t ms = NULL; if ((ms = magic_open(MAGIC_MIME)) != NULL) { document_format = magic_file(ms, av[optind]); magic_close(ms); } - } +#else + if (is_postscript(av[optind]) == 1) + document_format = "application/postscript"; #endif + } papiAttributeListAddInteger(&list, PAPI_ATTR_EXCL, "copies", 1); papiAttributeListAddString(&list, PAPI_ATTR_EXCL, @@ -278,6 +246,12 @@ exit(1); } + if (dump != 0) { + printf("requesting attributes:\n"); + papiAttributeListPrint(stdout, list, "\t"); + printf("\n"); + } + if (modify != -1) status = papiJobModify(svc, printer, modify, list, &job); else if (optind == ac) /* no file list, use stdin */ Modified: trunk/papi/source/bsd-sysv-commands/lpr.c =================================================================== --- trunk/papi/source/bsd-sysv-commands/lpr.c 2007-02-03 01:40:22 UTC (rev 182) +++ trunk/papi/source/bsd-sysv-commands/lpr.c 2007-02-03 02:35:26 UTC (rev 183) @@ -73,7 +73,7 @@ int validate = 0; int remove = 0; int copy = 1; /* default is to copy the data */ - char *document_format = "application/octet-stream"; + char *document_format = "text/plain"; int c; (void) setlocale(LC_ALL, ""); @@ -208,17 +208,20 @@ if (((optind + 1) == ac) && (strcmp(av[optind], "-") == 0)) optind = ac; -#ifdef MAGIC_MIME if (optind != ac) { /* get the mime type of the file data */ +#ifdef MAGIC_MIME magic_t ms; if ((ms = magic_open(MAGIC_MIME)) != NULL) { document_format = magic_file(ms, av[optind]); magic_close(ms); } +#else + if (is_postscript(av[optind]) == 1) + document_format = "application/postscript"; +#endif } -#endif papiAttributeListAddInteger(&list, PAPI_ATTR_EXCL, "copies", 1); papiAttributeListAddString(&list, PAPI_ATTR_EXCL, Modified: trunk/papi/source/bsd-sysv-commands/lpstat.c =================================================================== --- trunk/papi/source/bsd-sysv-commands/lpstat.c 2007-02-03 01:40:22 UTC (rev 182) +++ trunk/papi/source/bsd-sysv-commands/lpstat.c 2007-02-03 02:35:26 UTC (rev 183) @@ -662,9 +662,15 @@ printf(gettext(", complete")); if (verbose == 1) { + char *form = NULL; + (void) papiAttributeListGetString(attrs, NULL, "output-device-assigned", &destination); printf("\n\t assigned %s", destination); + + (void) papiAttributeListGetString(attrs, NULL, "form", &form); + if (form != NULL) + printf(", form %s", form); } else if (verbose > 1) { printf("\n"); papiAttributeListPrint(stdout, attrs, "\t"); Modified: trunk/papi/source/libipp-listener/ipp-listener.c =================================================================== --- trunk/papi/source/libipp-listener/ipp-listener.c 2007-02-03 01:40:22 UTC (rev 182) +++ trunk/papi/source/libipp-listener/ipp-listener.c 2007-02-03 02:35:26 UTC (rev 183) @@ -37,9 +37,12 @@ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> +#include <unistd.h> +#include <sys/systeminfo.h> #include <papi.h> #include <ipp-listener.h> +#include <uri.h> typedef papi_status_t (ipp_handler_t)(papi_service_t svc, papi_attribute_t **request, @@ -358,6 +361,61 @@ return (PAPI_OK); } +/* simplistic check for cyclical service references */ +static int +cyclical_service_check(char *svc_name, int port) +{ + papi_attribute_t **list; + char buf[BUFSIZ]; + uri_t *uri = NULL; + char *s = NULL; + + /* was there a service_uri? */ + if (svc_name == NULL) + return (0); + + if ((list = getprinterbyname(svc_name, NULL)) == NULL) + return (0); /* if it doesnt' resolve, we will fail later */ + + papiAttributeListGetString(list, NULL, "printer-uri-supported", &s); + if ((s == NULL) || (strcasecmp(svc_name, s) != 0)) + return (0); /* they don't match */ + + /* is it in uri form? */ + if (uri_from_string(s, &uri) < 0) + return (0); + + if ((uri == NULL) || (uri->scheme == NULL) || (uri->host == NULL)) { + uri_free(uri); + return (0); + } + + /* is it ipp form */ + if (strcasecmp(uri->scheme, "ipp") != 0) { + uri_free(uri); + return (0); + } + + /* does the host match up */ + sysinfo(SI_HOSTNAME, buf, sizeof (buf)); + if ((strcasecmp(uri->host, "localhost") != 0) && + (strcasecmp(uri->host, buf) != 0)) { + uri_free(uri); + return (0); + } + + /* does the port match our own */ + if (((uri->port == NULL) && (port != 631)) || + ((uri->port != NULL) && (atoi(uri->port) != port))) { + uri_free(uri); + return (0); + } + + uri_free(uri); + + return (1); +} + static papi_status_t print_service_connect(papi_service_t *svc, papi_attribute_t **request, papi_attribute_t ***response) @@ -367,6 +425,7 @@ char *printer_uri = NULL; char *svc_name = NULL; char *user = NULL; + int port = 631; /* Get the operational attributes group from the request */ (void) papiAttributeListGetCollection(request, NULL, @@ -382,6 +441,15 @@ "default-service", &svc_name); get_printer_id(operational, &svc_name, NULL); + /* get the port that we are listening on */ + (void) papiAttributeListGetInteger(request, NULL, "uri-port", &port); + + if (cyclical_service_check(svc_name, port) != 0) { + status = PAPI_NOT_POSSIBLE; + ipp_set_status(response, status, "printer-uri is cyclical"); + return (status); + } + status = papiServiceCreate(svc, svc_name, user, NULL, NULL, PAPI_ENCRYPT_NEVER, NULL); if (status != PAPI_OK) { Modified: trunk/papi/source/libpapi-common/attribute.c =================================================================== --- trunk/papi/source/libpapi-common/attribute.c 2007-02-03 01:40:22 UTC (rev 182) +++ trunk/papi/source/libpapi-common/attribute.c 2007-02-03 02:35:26 UTC (rev 183) @@ -385,7 +385,7 @@ if ((attribute = papiAttributeListFind(*list, name)) == NULL) return (PAPI_NOT_FOUND); - list_remove(*list, attribute); + list_remove(list, attribute); papiAttributeFree(attribute); return (PAPI_OK); Modified: trunk/papi/source/libpapi-common/common.c =================================================================== --- trunk/papi/source/libpapi-common/common.c 2007-02-03 01:40:22 UTC (rev 182) +++ trunk/papi/source/libpapi-common/common.c 2007-02-03 02:35:26 UTC (rev 183) @@ -246,3 +246,6 @@ "job-id", &id); return (id); } +/* private functions */ +#pragma weak getprinterbyname = _unsupported_null_return + Modified: trunk/papi/source/libpapi-common/list.c =================================================================== --- trunk/papi/source/libpapi-common/list.c 2007-02-03 01:40:22 UTC (rev 182) +++ trunk/papi/source/libpapi-common/list.c 2007-02-03 02:35:26 UTC (rev 183) @@ -58,6 +58,8 @@ __list_increment; new_list = (void **)calloc(new_size, sizeof (void *)); + if (new_list == NULL) + return (-1); for (count = 0; (*list)[count] != NULL; count++) new_list[count] = (*list)[count]; @@ -134,26 +136,35 @@ } void -list_remove(void **list, void *item) +list_remove(void ***list, void *item) { - int i, last; + int i, count; + void **tmp = NULL; if ((list == NULL) || (*list == NULL) || (item == NULL)) return; - for (last = 0; list[last] != NULL; last++) - ; - --last; + for (count = 0; (*list)[count] != NULL; count++); - /* - * This doesn't preserve order, and doesn't shrink the allocation if we - * go below % __list_increment == 0. <shrug> - */ - for (i = 0; list[i] != NULL; i++) { - if (list[i] == item) { - list[i] = list[last]; - list[last] = NULL; - break; - } + if (count > 0) { + int new_size = (((count + 1) / __list_increment) + 1) * + __list_increment; + + if ((tmp = (void **)calloc(new_size, sizeof (void *))) != NULL) + tmp = *list; + + /* copy up to item */ + for (i = 0; (((*list)[i] != NULL) && ((*list)[i] != item)); i++) + tmp[i] = (*list)[i]; + /* copy after item */ + if ((*list)[i] == item) + for (++i; ((*list)[i] != NULL); i++) + tmp[i-1] = (*list)[i]; } + + /* replace the list */ + if (tmp != *list) { + free(*list); + *list = tmp; + } } Modified: trunk/papi/source/libpapi-common/mapfile.in =================================================================== --- trunk/papi/source/libpapi-common/mapfile.in 2007-02-03 01:40:22 UTC (rev 182) +++ trunk/papi/source/libpapi-common/mapfile.in 2007-02-03 02:35:26 UTC (rev 183) @@ -157,6 +157,8 @@ split_and_copy_attributes; papiAttributeListPrint; + getprinterbyname; + # missing from libc on some platforms strlcpy @MAP_FILTER@ = FUNCTION AUXILIARY libc.so ; strlcat @MAP_FILTER@ = FUNCTION AUXILIARY libc.so ; Modified: trunk/papi/source/libpapi-common/papi.h =================================================================== --- trunk/papi/source/libpapi-common/papi.h 2007-02-03 01:40:22 UTC (rev 182) +++ trunk/papi/source/libpapi-common/papi.h 2007-02-03 02:35:26 UTC (rev 183) @@ -465,6 +465,7 @@ papi_attribute_t **attributes, papi_attribute_t ***in, papi_attribute_t ***out); +extern papi_attribute_t **getprinterbyname(char *name, char *ns); #ifdef __cplusplus } Modified: trunk/papi/source/libpapi-dynamic/mapfile.in =================================================================== --- trunk/papi/source/libpapi-dynamic/mapfile.in 2007-02-03 01:40:22 UTC (rev 182) +++ trunk/papi/source/libpapi-dynamic/mapfile.in 2007-02-03 02:35:26 UTC (rev 183) @@ -157,6 +157,8 @@ split_and_copy_attributes @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; papiAttributeListPrint @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; + getprinterbyname; + # missing from libc on some platforms strlcpy @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; strlcat @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; Modified: trunk/papi/source/libpapi-ipp/ipp-support.c =================================================================== --- trunk/papi/source/libpapi-ipp/ipp-support.c 2007-02-03 01:40:22 UTC (rev 182) +++ trunk/papi/source/libpapi-ipp/ipp-support.c 2007-02-03 02:35:26 UTC (rev 183) @@ -34,12 +34,11 @@ #include <errno.h> #include <fcntl.h> #include <sys/stat.h> +#include <md5.h> #include <config-site.h> -#ifdef HAVE_MD5_H -#include <md5.h> -#endif +#include <ipp.h> papi_status_t http_to_papi_status(http_status_t status) @@ -466,7 +465,6 @@ httpGetSubField(http, HTTP_FIELD_WWW_AUTHENTICATE, "nonce", nonce); -#ifdef HAVE_MD5_H snprintf(line, sizeof (line), "%s:%s:%s", user, realm, passphrase); md5_calc(urp, line, strlen(line)); @@ -476,10 +474,6 @@ snprintf(line, sizeof (line), "%s:%s:%s", urp, mr, nonce); md5_calc(encoded, line, strlen(line)); -#else - httpMD5(user, realm, passphrase, line); - httpMD5(nonce, "POST", uri, encoded); -#endif snprintf(http->authstring, sizeof (http->authstring), "Digest username=\"%s\", realm=\"%s\", nonce=\"%s\", " Modified: trunk/papi/source/libpapi-ipp/mapfile.in =================================================================== --- trunk/papi/source/libpapi-ipp/mapfile.in 2007-02-03 01:40:22 UTC (rev 182) +++ trunk/papi/source/libpapi-ipp/mapfile.in 2007-02-03 02:35:26 UTC (rev 183) @@ -156,6 +156,8 @@ split_and_copy_attributes @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; papiAttributeListPrint @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; + getprinterbyname @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; + # missing from libc on some platforms strlcpy @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; strlcat @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; Modified: trunk/papi/source/libpapi-lpd/lpd-job.c =================================================================== --- trunk/papi/source/libpapi-lpd/lpd-job.c 2007-02-03 01:40:22 UTC (rev 182) +++ trunk/papi/source/libpapi-lpd/lpd-job.c 2007-02-03 02:35:26 UTC (rev 183) @@ -47,7 +47,7 @@ mime_type_to_rfc1179_type(char *mime) { static struct { char *mime; char rfc; } cvt[] = { - { "plain/text", 'f' }, + { "text/plain", 'f' }, { "application/octet-stream", 'l' }, { "application/postscript", 'f' }, /* rfc incorrectly has 'o' */ { "application/x-pr", 'p' }, @@ -420,7 +420,7 @@ lpd_job_add_files(service_t *svc, papi_attribute_t **attributes, char **files, char **metadata, papi_attribute_t ***used) { - char *format = "plain/text"; + char *format = "text/plain"; char rfc_fmt = 'l'; int copies = 1; char host[BUFSIZ]; Modified: trunk/papi/source/libpapi-lpd/mapfile.in =================================================================== --- trunk/papi/source/libpapi-lpd/mapfile.in 2007-02-03 01:40:22 UTC (rev 182) +++ trunk/papi/source/libpapi-lpd/mapfile.in 2007-02-03 02:35:26 UTC (rev 183) @@ -156,6 +156,8 @@ split_and_copy_attributes @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; papiAttributeListPrint @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; + getprinterbyname @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; + # missing from libc on some platforms strlcpy @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; strlcat @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nj...@us...> - 2007-02-03 01:40:25
|
Revision: 182 http://svn.sourceforge.net/openprinting/?rev=182&view=rev Author: njacobs Date: 2007-02-02 17:40:22 -0800 (Fri, 02 Feb 2007) Log Message: ----------- added library man pages donated by Sun Microsystems Modified Paths: -------------- trunk/papi/ChangeLog trunk/papi/docs/man/Makefile.am Added Paths: ----------- trunk/papi/docs/man/libpapi.3lib.in trunk/papi/docs/man/papiAttributeListAddValue.3papi.in trunk/papi/docs/man/papiJobSubmit.3papi.in trunk/papi/docs/man/papiLibrarySupportedCall.3papi.in trunk/papi/docs/man/papiPrintersList.3papi.in trunk/papi/docs/man/papiServiceCreate.3papi.in trunk/papi/docs/man/papiStatusString.3papi.in Modified: trunk/papi/ChangeLog =================================================================== --- trunk/papi/ChangeLog 2006-10-16 05:22:57 UTC (rev 181) +++ trunk/papi/ChangeLog 2007-02-03 01:40:22 UTC (rev 182) @@ -1,3 +1,15 @@ +2007-02-02 Norm Jacobs <Norm.Jacobs@Sun.COM> + * docs/man/Makefile.am + * docs/man/README + * docs/man/libpapi.3lib.in + * docs/man/papiAttributeListAddValue.3papi.in + * docs/man/papiJobSubmit.3papi.in + * docs/man/papiLibrarySupportedCall.3papi.in + * docs/man/papiPrintersList.3papi.in + * docs/man/papiServiceCreate.3papi.in + * docs/man/papiStatusString.3papi.in + added library man pages donated by Sun Microsystems + 2006-10-15 Norm Jacobs <Norm.Jacobs@Sun.COM> * source/libpapi-lpd/lpd-cancel.c: fix core dump during papiJobCancel() to rfc1179 server Modified: trunk/papi/docs/man/Makefile.am =================================================================== --- trunk/papi/docs/man/Makefile.am 2006-10-16 05:22:57 UTC (rev 181) +++ trunk/papi/docs/man/Makefile.am 2007-02-03 01:40:22 UTC (rev 182) @@ -8,6 +8,10 @@ man_MANS_in = lpq.1b.in lpr.1b.in lprm.1b.in lpc.1b.in man_MANS_in += lpstat.1.in lp.1.in cancel.1.in enable.1.in disable.1.in man_MANS_in += lpmove.1m.in accept.1m.in reject.1m.in +man_MANS_in += libpapi.3lib.in +man_MANS_in += papiAttributeListAddValue.3papi.in papiJobSubmit.3papi.in +man_MANS_in += papiLibrarySupportedCall.3papi.in papiPrintersList.3papi.in +man_MANS_in += papiServiceCreate.3papi.in papiStatusString.3papi.in man_MANS_in += printers.conf.4.in man_MANS_in += psm-ipp.5.in @@ -16,6 +20,10 @@ man_MANS += lpq.1b lpr.1b lprm.1b lpc.1b man_MANS += lpstat.1 lp.1 cancel.1 enable.1 disable.1 man_MANS += lpmove.1m accept.1m reject.1m +man_MANS += libpapi.3lib +man_MANS += papiAttributeListAddValue.3papi papiJobSubmit.3papi +man_MANS += papiLibrarySupportedCall.3papi papiPrintersList.3papi +man_MANS += papiServiceCreate.3papi papiStatusString.3papi man_MANS += printers.conf.4 man_MANS += psm-ipp.5 Added: trunk/papi/docs/man/libpapi.3lib.in =================================================================== --- trunk/papi/docs/man/libpapi.3lib.in (rev 0) +++ trunk/papi/docs/man/libpapi.3lib.in 2007-02-03 01:40:22 UTC (rev 182) @@ -0,0 +1,289 @@ +'\" te +.\" CDDL HEADER START +.\" +.\" The contents of this file are subject to the terms of the +.\" Common Development and Distribution License (the "License"). +.\" You may not use this file except in compliance with the License. +.\" +.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +.\" or http://www.opensolaris.org/os/licensing. +.\" See the License for the specific language governing permissions +.\" and limitations under the License. +.\" +.\" When distributing Covered Code, include this CDDL HEADER in each +.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE. +.\" If applicable, add the following below this CDDL HEADER, with the +.\" fields enclosed by brackets "[]" replaced with your own identifying +.\" information: Portions Copyright [yyyy] [name of copyright owner] +.\" +.\" CDDL HEADER END +.\" Copyright (c) 2006, Sun Microsystems, Inc. All Rights Reserved. +.TH libpapi 3LIB "18 Dec 2006" "SunOS 5.11" "" +.SH NAME +libpapi \- Free Standards Group Open Printing API (PAPI) library functions +.SH SYNOPSIS +.LP +.nf +cc [ \fIflag\fR\&.\|.\|. ] \fIfile\fR\&.\|.\|. \fB-lpapi\fR [ \fIlibrary\fR\&.\|.\|. ] +#include <papi.h> +.fi + +.SH DESCRIPTION + +.LP +Functions in this library provide an interface for interaction with print services as described in v1.0 of the Free Standards Group (FSG) Open Printing API (PAPI). +.sp + +.LP +This particular implementation of the PAPI includes naming support as described in the +\fBprinters.conf\fR(4) and +\fBprinters\fR(4) manual pages. It also supplies support for interaction with local LP services, remote LPD services, and remote IPP services through the use of loadable modules that export +the same interface. These modules should not be linked with directly, but can be used directly at runtime through the use of \fBLD_PRELOAD\fR for debugging purposes. +.sp + +.SH INTERFACES + +.LP +The shared object \fBlibpapi.so.0\fR provides the public interfaces defined below. See +\fBIntro\fR(3) for additional information on shared object +interfaces. +.sp + +.SS Attribute + +.LP + +.sp +.TS +tab(); +lw(2.75i) lw(2.75i) +lw(2.75i) lw(2.75i) +. +\fBpapiAttributeListAddBoolean\fR\fBpapiAttributeListAddCollection\fR +\fBpapiAttributeListAddDatetime\fR\fBpapiAttributeListAddInteger\fR +\fBpapiAttributeListAddMetadata\fR\fBpapiAttributeListAddRange\fR +\fBpapiAttributeListAddResolution\fR\fBpapiAttributeListAddString\fR +\fBpapiAttributeListAddValue\fR\fBpapiAttributeListDelete\fR +\fBpapiAttributeListFind\fR\fBpapiAttributeListFree\fR +\fBpapiAttributeListFromString\fR\fBpapiAttributeListGetBoolean\fR +\fBpapiAttributeListGetCollection\fR\fBpapiAttributeListGetDatetime\fR +\fBpapiAttributeListGetInteger\fR\fBpapiAttributeListGetMetadata\fR +\fBpapiAttributeListGetNext\fR\fBpapiAttributeListGetRange\fR +\fBpapiAttributeListGetResolution\fR\fBpapiAttributeListGetString\fR +\fBpapiAttributeListGetValue\fR\fBpapiAttributeListToString\fR +.TE + +.SS Service + +.LP + +.sp +.TS +tab(); +lw(2.75i) lw(2.75i) +lw(2.75i) lw(2.75i) +. +\fBpapiServiceCreate\fR\fBpapiServiceDestroy\fR +\fBpapiServiceGetAppData\fR\fBpapiServiceGetAttributeList\fR +\fBpapiServiceGetEncryption\fR\fBpapiServiceGetPassword\fR +\fBpapiServiceGetServiceName\fR\fBpapiServiceGetStatusMessage\fR +\fBpapiServiceGetUserName\fR\fBpapiServiceSetAppData\fR +\fBpapiServiceSetAuthCB\fR\fBpapiServiceSetEncryption\fR +\fBpapiServiceSetPassword\fR\fBpapiServiceSetUserName\fR +.TE + +.SS Printer + +.LP + +.sp +.TS +tab(); +lw(2.75i) lw(2.75i) +lw(2.75i) lw(2.75i) +. +\fBpapiPrinterAdd\fR\fBpapiPrinterDisable\fR +\fBpapiPrinterEnable\fR\fBpapiPrinterFree\fR +\fBpapiPrinterGetAttributeList\fR\fBpapiPrinterListFree\fR +\fBpapiPrinterListJobs\fR\fBpapiPrinterModify\fR +\fBpapiPrinterPause\fR\fBpapiPrinterPurgeJobs\fR +\fBpapiPrinterQuery\fR\fBpapiPrinterRemove\fR +\fBpapiPrinterResume\fR\fBpapiPrintersList\fR +.TE + +.SS Job + +.LP + +.sp +.TS +tab(); +lw(2.75i) lw(2.75i) +lw(2.75i) lw(2.75i) +. +\fBpapiJobCancel\fR\fBpapiJobFree\fR +\fBpapiJobGetAttributeList\fR\fBpapiJobGetId\fR +\fBpapiJobGetJobTicket\fR\fBpapiJobGetPrinterName\fR +\fBpapiJobHold\fR\fBpapiJobListFree\fR +\fBpapiJobModify\fR\fBpapiJobMove\fR +\fBpapiJobPromote\fR\fBpapiJobQuery\fR +\fBpapiJobRelease\fR\fBpapiJobRestart\fR +\fBpapiJobStreamClose\fR\fBpapiJobStreamOpen\fR +\fBpapiJobStreamWrite\fR\fBpapiJobSubmit\fR +\fBpapiJobSubmitByReference\fR\fBpapiJobValidate\fR +.TE + +.SS Miscellaneous + +.LP + +.sp +.TS +tab(); +lw(2.75i) lw(2.75i) +lw(2.75i) lw(2.75i) +. +\fBpapiLibrarySupportedCall\fR\fBpapiLibrarySupportedCalls\fR +\fBpapiStatusString\fR +.TE + +.SH FILES + +.sp +.ne 2 +.mk +.na +\fB\fB%libdir%/libpapi.so.0\fR\fR +.ad +.RS 31n +.rt +shared object +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fB%libdir%/libpapi-common.so.0\fR\fR +.ad +.RS 31n +.rt +private shared code +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fB%libexecdir%/psm-lpd.so\fR\fR +.ad +.RS 31n +.rt +private rfc1179 support +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fB%libexecdir%/psm-lpsched.so\fR\fR +.ad +.RS 31n +.rt +private LP support +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fB%libexecdir%/psm-ipp.so\fR\fR +.ad +.RS 31n +.rt +private IPP support +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fB%libdir%/libipp-core.so\fR\fR +.ad +.RS 31n +.rt +private IPP marshalling support +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fB/%libdir%/-listener.so\fR\fR +.ad +.RS 31n +.rt +private IPP operations support +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fB/usr/lip/libhttp-core.so\fR\fR +.ad +.RS 31n +.rt +private HTTP support +.sp + +.RE + +.SH ATTRIBUTES + +.LP +See +\fBattributes\fR(5) for descriptions of the following attributes: +.sp + +.LP + +.sp +.TS +tab() box; +cw(2.75i) |cw(2.75i) +lw(2.75i) |lw(2.75i) +. +ATTRIBUTE TYPEATTRIBUTE VALUE +_ +AvailabilitySUNWpapi +_ +Interface StabilityVolatile +_ +MT-LevelSafe +.TE + +.SH SEE ALSO + +.LP + +\fBIntro\fR(3), +\fBprinters\fR(4), +\fBprinters.conf\fR(4), +\fBattributes\fR(5) +.sp + Added: trunk/papi/docs/man/papiAttributeListAddValue.3papi.in =================================================================== --- trunk/papi/docs/man/papiAttributeListAddValue.3papi.in (rev 0) +++ trunk/papi/docs/man/papiAttributeListAddValue.3papi.in 2007-02-03 01:40:22 UTC (rev 182) @@ -0,0 +1,778 @@ +'\" te +.\" CDDL HEADER START +.\" +.\" The contents of this file are subject to the terms of the +.\" Common Development and Distribution License (the "License"). +.\" You may not use this file except in compliance with the License. +.\" +.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +.\" or http://www.opensolaris.org/os/licensing. +.\" See the License for the specific language governing permissions +.\" and limitations under the License. +.\" +.\" When distributing Covered Code, include this CDDL HEADER in each +.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE. +.\" If applicable, add the following below this CDDL HEADER, with the +.\" fields enclosed by brackets "[]" replaced with your own identifying +.\" information: Portions Copyright [yyyy] [name of copyright owner] +.\" +.\" CDDL HEADER END +.\" Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved. +.TH papiAttributeListAddValue 3PAPI "17 Jan 2007" "SunOS 5.11" "PAPI Library Functions" +.SH NAME +papiAttributeListAddValue, papiAttributeListAddBoolean, papiAttributeListAddCollection, papiAttributeListAddDatetime, papiAttributeListAddInteger, papiAttributeListAddMetadata, papiAttributeListAddRange, papiAttributeListAddResolution, papiAttributeListAddString, papiAttributeListDelete, papiAttributeListGetValue, papiAttributeListGetNext, papiAttributeListFind, papiAttributeListGetBoolean, papiAttributeListGetCollection, papiAttributeListGetDatetime, papiAttributeListGetInteger, papiAttributeListGetMetadata, papiAttributeListGetRange, papiAttributeListGetResolution, papiAttributeListGetString, papiAttributeListFromString, papiAttributeListToString, papiAttributeListFree \- manage PAPI attribute lists +.SH SYNOPSIS +.LP +.nf +cc [ \fIflag\fR\&.\|.\|. ] \fIfile\fR\&.\|.\|. \fB-lpapi\fR [ \fIlibrary\fR\&.\|.\|. ] +#include <papi.h> + +\fBpapi_status_t\fR \fBpapiAttributeListAddValue\fR(\fBpapi_attribute_t ***\fR\fIattrs\fR, + \fBint\fR \fIflags\fR, \fBchar *\fR\fIname\fR, \fBpapi_attribute_value_type_t\fR \fItype\fR, + \fBpapi_attribute_value_t *\fR\fIvalue\fR); +.fi +.LP +.nf +\fBpapi_status_t\fR \fBpapiAttributeListAddString\fR(\fBpapi_attribute_t ***\fR\fIattrs\fR, + \fBint\fR \fIflags\fR, \fBchar *\fR\fIname\fR, \fBchar *\fR\fIstring\fR); +.fi +.LP +.nf +\fBpapi_status_t\fR \fBpapiAttributeListAddInteger\fR(\fBpapi_attribute_t ***\fR\fIattrs\fR, + \fBint\fR \fIflags\fR, \fBchar *\fR\fIname\fR, \fBint\fR \fIinteger\fR); +.fi +.LP +.nf +\fBpapi_status_t\fR \fBpapiAttributeListAddBoolean\fR(\fBpapi_attribute_t ***\fR\fIattrs\fR, + \fBint\fR \fIflags\fR, \fBchar *\fR\fIname\fR, \fBchar\fR \fIboolean\fR); +.fi +.LP +.nf +\fBpapi_status_t\fR \fBpapiAttributeListAddRange\fR(\fBpapi_attribute_t ***\fR\fIattrs\fR, + \fBint\fR \fIflags\fR, \fBchar *\fR\fIname\fR, \fBint\fR \fIlower\fR, \fBint\fR \fIupper\fR); +.fi +.LP +.nf +\fBpapi_status_t\fR \fBpapiAttributeListAddResolution\fR(\fBpapi_attribute_t ***\fR\fIattrs\fR, + \fBint\fR \fIflags\fR, \fBchar *\fR\fIname\fR, \fBint\fR \fIxres\fR, \fBint\fR \fIyres\fR, + \fBpapi_resolution_unit_t\fR \fIunits\fR); +.fi +.LP +.nf +\fBpapi_status_t\fR \fBpapiAttributeListAddDatetime\fR(\fBpapi_attribute_t ***\fR\fIattrs\fR, + \fBint\fR \fIflags\fR, \fBchar *\fR\fIname\fR, \fBtime_t\fR \fIdatetime\fR); +.fi +.LP +.nf +\fBpapi_status_t\fR \fBpapiAttributeListAddCollection\fR(\fBpapi_attribute_t ***\fR\fIattrs\fR, + \fBint\fR \fIflags\fR, \fBchar *\fR\fIname\fR, \fBpapi_attribute_t **\fR\fIcollection\fR); +.fi +.LP +.nf +\fBpapi_status_t\fR \fBpapiAttributeListAddMetadata\fR(\fBpapi_attribute_t ***\fR\fIattrs\fR, + \fBint\fR \fIflags\fR, \fBchar *\fR\fIname\fR, \fBpapi_metadata_t\fR \fImetadata\fR); +.fi +.LP +.nf +\fBpapi_status_t\fR \fBpapiAttributeListDelete\fR(\fBpapi_attribute_t ***\fR\fIattributes\fR, + \fBchar *\fR\fIname\fR); +.fi +.LP +.nf +\fBpapi_status_t\fR \fBpapiAttributeListGetValue\fR(\fBpapi_attribute_t **\fR\fIlist\fR, + \fBvoid **\fR\fIiterator\fR, \fBchar *\fR\fIname\fR, \fBpapi_attribute_value_type_t\fR \fItype\fR, + \fBpapi_attribute_value_t **\fR\fIvalue\fR); +.fi +.LP +.nf +\fBpapi_status_t\fR \fBpapiAttributeListGetString\fR(\fBpapi_attribute_t **\fR\fIlist\fR, + \fBvoid **\fR\fIiterator\fR, \fBchar *\fR\fIname\fR, \fBchar **\fR\fIvptr\fR); +.fi +.LP +.nf +\fBpapi_status_t\fR \fBpapiAttributeListGetInteger\fR(\fBpapi_attribute_t **\fR\fIlist\fR, + \fBvoid **\fR\fIiterator\fR, \fBchar *\fR\fIname\fR, \fBint *\fR\fIvptr\fR); +.fi +.LP +.nf +\fBpapi_status_t\fR \fBpapiAttributeListGetBoolean\fR(\fBpapi_attribute_t **\fR\fIlist\fR, + \fBvoid **\fR\fIiterator\fR, \fBchar *\fR\fIname\fR, \fBchar *\fR\fIvptr\fR); +.fi +.LP +.nf +\fBpapi_status_t\fR \fBpapiAttributeListGetRange\fR(\fBpapi_attribute_t **\fR\fIlist\fR, + \fBvoid **\fR\fIiterator\fR, \fBchar *\fR\fIname\fR, \fBint *\fR\fImin\fR, \fBint *\fR\fImax\fR); +.fi +.LP +.nf +\fBpapi_status_t\fR \fBpapiAttributeListGetResolution\fR(\fBpapi_attribute_t **\fR\fIlist\fR, + \fBvoid **\fR\fIiterator\fR, \fBchar *\fR\fIname\fR, \fBint *\fR\fIx\fR, \fBint *\fR\fIy\fR, + \fBpapi_resolution_unit_t *\fR\fIunits\fR); +.fi +.LP +.nf +\fBpapi_status_t\fR \fBpapiAttributeListGetDatetime\fR(\fBpapi_attribute_t **\fR\fIlist\fR, + \fBvoid **\fR\fIiterator\fR, \fBchar *\fR\fIname\fR, \fBtime_t *\fR\fIdt\fR); +.fi +.LP +.nf +\fBpapi_status_t\fR \fBpapiAttributeListGetCollection\fR(\fBpapi_attribute_t **\fR\fIlist\fR, + \fBvoid **\fR\fIiterator\fR, \fBchar *\fR\fIname\fR, \fBpapi_attribute_t ***\fR\fIcollection\fR); +.fi +.LP +.nf +\fBpapi_status_t\fR \fBpapiAttributeListGetMetadata\fR(\fBpapi_attribute_t **\fR\fIlist\fR, + \fBvoid **\fR\fIiterator\fR, \fBchar *\fR\fIname\fR, \fBpapi_metadata_t *\fR\fIvptr\fR); +.fi +.LP +.nf +\fBpapi_attribute_t *\fR\fBpapiAttributeListFind\fR(\fBpapi_attribute_t **\fR\fIlist\fR, + \fBchar *\fR\fIname\fR); +.fi +.LP +.nf +\fBpapi_attribute_t *\fR\fBpapiAttributeListGetNext\fR(\fBpapi_attribute_t **\fR\fIlist\fR, + \fBvoid **\fR\fIiterator\fR); +.fi +.LP +.nf +\fBvoid\fR \fBpapiAttributeListFree\fR(\fBpapi_attribute_t **\fR\fIattributes\fR); +.fi +.LP +.nf +\fBpapi_status_t\fR \fBpapiAttributeListFromString\fR(\fBpapi_attribute_t ***\fR\fIattrs\fR, + \fBint\fR \fIflags\fR, \fBchar *\fR\fIstring\fR); +.fi +.LP +.nf +\fBpapi_status_t\fR \fBpapiAttributeListToString\fR(\fBpapi_attribute_t **\fR\fIattrs\fR, + \fBchar *\fR\fIdelim\fR, \fBchar *\fR\fIbuffer\fR, \fBsize_t\fR \fIbuflen\fR); +.fi + +.SH PARAMETERS + +.sp +.ne 2 +.mk +.na +\fB\fIattrs\fR\fR +.ad +.RS 12n +.rt +address of array of pointers to attributes +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fIattributes\fR\fR +.ad +.RS 12n +.rt +a list of attributes (of type \fBpapi_attribute_t **\fR) contained in a collection. Lists can be hierarchical. +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fIboolean\fR\fR +.ad +.RS 12n +.rt +boolean value (\fBPAPI_TRUE\fR or \fBPAPI_FALSE)\fR +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fIbuffer\fR\fR +.ad +.RS 12n +.rt +buffer to fill +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fIbuflen\fR\fR +.ad +.RS 12n +.rt +length of supplied buffer +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fIcollection\fR\fR +.ad +.RS 12n +.rt +list of attributes +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fIdatetime\fR\fR +.ad +.RS 12n +.rt +attribute time value specified in \fBtime_t\fR representation +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fIdelim\fR\fR +.ad +.RS 12n +.rt +delimiter used in construction of a string representation of an attribute list +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fIdt\fR\fR +.ad +.RS 12n +.rt +date and time represented as a \fBtime_t\fR +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fIflags\fR\fR +.ad +.RS 12n +.rt +Specify bit fields defining how actions will be performed: +.sp + +.sp +.ne 2 +.mk +.na +\fB\fBPAPI_ATTR_REPLACE\fR\fR +.ad +.sp .6 +.RS 4n + +Free any existing value(s) and replace it with the supplied value(s). +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBPAPI_ATTR_APPEND\fR\fR +.ad +.sp .6 +.RS 4n + +Add the supplied value to the attribute. +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBPAPI_ATTR_EXCL\fR\fR +.ad +.sp .6 +.RS 4n + +Add the supplied value to the attribute, if the attribute was not previously defined. +.sp + +.RE + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fIinteger\fR\fR +.ad +.RS 12n +.rt +integer value +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fIiterator\fR\fR +.ad +.RS 12n +.rt +iterator for enumerating multiple values of multi-value attributes +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fIlist\fR\fR +.ad +.RS 12n +.rt +array of pointers to attributes (attribute list) +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fIlower\fR\fR +.ad +.RS 12n +.rt +lower bound for a range of integer +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fImax\fR\fR +.ad +.RS 12n +.rt +maximum value in a range +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fImetadata\fR\fR +.ad +.RS 12n +.rt +pseudo-values for specialized attributes \fBPAPI_UNSUPPORTED\fR, \fBPAPI_DEFAULT\fR, \fBPAPI_UNKNOWN\fR, \fBPAPI_NO_VALUE\fR, \fBPAPI_NOT_SETTABLE\fR, \fBPAPI_DELETE\fR +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fImin\fR\fR +.ad +.RS 12n +.rt +minimum value in a range +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fIname\fR\fR +.ad +.RS 12n +.rt +attribute name +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fIstring\fR\fR +.ad +.RS 12n +.rt +string value +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fItype\fR\fR +.ad +.RS 12n +.rt +attribute type (\fBPAPI_STRING\fR, \fBPAPI_INTEGER\fR, \fBPAPI_BOOLEAN\fR, \fBPAPI_RANGE\fR, \fBPAPI_RESOLUTION\fR, \fBPAPI_DATETIME\fR, \fBPAPI_COLLECTION\fR, \fBPAPI_METADATA\fR) +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fIunits\fR\fR +.ad +.RS 12n +.rt +resolution unit of measure (\fBPAPI_RES_PER_INCH\fR or \fBPAPI_RES_PER_CM\fR) +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fIupper\fR\fR +.ad +.RS 12n +.rt +upper bound for a range of integer +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fIvalue\fR\fR +.ad +.RS 12n +.rt +attribute value +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fIvptr\fR\fR +.ad +.RS 12n +.rt +pointer to arbitrary data +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fIx\fR\fR +.ad +.RS 12n +.rt +horizontal (x) resolution +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fIxres\fR\fR +.ad +.RS 12n +.rt +horizontal (x) component of a resolution +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fIy\fR\fR +.ad +.RS 12n +.rt +vertical (y) resolution +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fIyres\fR\fR +.ad +.RS 12n +.rt +vertical (y) component of a resolution +.sp + +.RE + +.SH DESCRIPTION + +.LP +The \fBpapiAttributeListAdd*()\fR functions add new attributes and/or values to the attribute list passed in. If necessary, the attribute list passed in is expanded to contain a new attribute pointer for any new attributes added to the list. The list is null-terminated. Space +for the new attributes and values is allocated and the name and value are copied into this allocated space. +.sp + +.LP +If \fBPAPI_ATTR_REPLACE\fR is specified in flags, any existing attribute values are freed and replaced with the supplied value. +.sp + +.LP +If \fBPAPI_ATTR_APPEND\fR is specified, the supplied value is appended to the attribute's list of values. +.sp + +.LP +If \fBPAPI_ATTR_EXCL\fR is specified, the operation succeeds only if the attribute was not previously defined. +.sp + +.LP +The \fBpapiAttributeListGet*()\fR functions retrieve an attribute value from an attribute list. If the attribute is a multi-valued attribute, the first call to retrieve a value should pass in an iterator and attribute name. Subsequent calls to retrieve additional values should +pass in the iterator and a null value for the attribute name. If a single-valued attribute is to be retrieved, \fINULL\fR can be used in place of the iterator. +.sp + +.LP +Upon successful completion of a get operation, the value passed in (string, integer, boolean, ...) is changed to the value from the attribute list. If the operation fails for any reason (type mismatch, not found, ...), the value passed in remains untouched. +.sp + +.LP +The resulting value returned from a get operation is returned from the attribute list's allocated memory. It is not guaranteed to be available after the attribute list has been freed. +.sp + +.LP +The \fBpapiAttributeListDelete()\fR function removes an attribute from a supplied list. +.sp + +.LP +The \fBpapiAttributeListFind()\fR function allows an application to retrieve an entire attribute structure from the passed-in attribute list. +.sp + +.LP +The \fBpapiAttributeListGetNext()\fR function allows an application to walk through an attribute list returning subsequent attributes from the list. With the first call, the iterator should be initialized to \fINULL\fR and subsequent calls should use \fINULL\fR for the list argument. +.sp + +.LP +The \fBpapiAttributeListFree()\fR function deallocates all memory associated with an attribute list, including values that might have been retrieved previously using \fBpapiAttributeListGet*()\fR calls. +.sp + +.LP +The \fBpapiAttributeListFromString()\fR function takes in a string representation of a set of attributes, parses the string and adds the attributes to the passed in attribute list using the flags to determine how to add them. String values are specified with "key=value". +Integer values are specified with "key=number". Boolean values are specified with either "key=(true|false)" or "[no]key". Multiple attributes can be specified in the string by separating them with a whitespace character. +.sp + +.LP +The \fBpapiAttributeListToString()\fR function converts an attribute list to a string representation that can be displayed to a user. The delimiter value is placed between attributes in the string. +.sp + +.SH RETURN VALUES + +.LP +These functions return \fBPAPI_OK\fR upon successful completion and one of the following on failure: +.sp + +.sp +.ne 2 +.mk +.na +\fB\fBPAPI_BAD_ARGUMENT\fR\fR +.ad +.RS 22n +.rt +The supplied arguments were not valid. +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBPAPI_CONFLICT\fR\fR +.ad +.RS 22n +.rt +There was an attribute type mismatch. +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBPAPI_NOT_FOUND\fR\fR +.ad +.RS 22n +.rt +The requested attribute could not be found. +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBPAPI_NOT_POSSIBLE\fR\fR +.ad +.RS 22n +.rt +The requested operation could not be performed due to buffer overflow. +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBPAPI_TEMPORARY_ERROR\fR\fR +.ad +.RS 22n +.rt +Memory could not be allocated to add to the attribute list. +.sp + +.RE + +.SH EXAMPLES +.LP +\fBExample 1 \fRThe following example manipulates a PAPI attribute list. + +.LP +.in +2 +.nf +/* +* program to manipulate a PAPI attribute list +*/ +#include <stdio.h> +#include <papi.h> + +/*ARGSUSED*/ +int +main(int ac, char *av[]) +{ + char buf[BUFSIZ]; + papi_status_t status; + papi_attribute_t **list = NULL; + void *iter = NULL; + char *string = NULL; + int32_t integer = 0; + + /* build an attribute list */ + (void) papiAttributeListAddString(&list, PAPI_ATTR_EXCL, + "job-title", "example"); + (void) papiAttributeListAddInteger(&list, PAPI_ATTR_EXCL, + "copies", 1); + (void) papiAttributeListFromString(&list, PAPI_ATTR_REPLACE, av[1]); + status = papiAttributeListAddString(&list, PAPI_ATTR_EXCL, + "document-format", "text/plain"); + if (status != PAPI_OK) + printf("failed to set document-format to text/plain: %s\en", + papiStatusString(status)); + + /* dump the list */ + status = papiAttributeListToString(list, "\en\et", buf, sizeof (buf)); + if (status == PAPI_OK) + printf("Attributes: %s\en", buf); + else + printf("Attribute list to big to dump\en"); + + + /* retreive various elements */ + integer = 12; + (void) papiAttributeListGetInteger(list, NULL, "copies", &integer); + printf("copies: %d\en", integer); + + string = NULL; + for (status = papiAttributeListGetString(list, &oter, + "job-files", &string); + status == PAPI_OK; + status = papiAttributeListGetString(list, &iter, NULL, &string)) + printf("file: %s\en", string); + + papiAttributeListFree(list); +} +.fi +.in -2 + +.SH ATTRIBUTES + +.LP +See +\fBattributes\fR(5) for descriptions of the following attributes: +.sp + +.LP + +.sp +.TS +tab() box; +cw(2.75i) |cw(2.75i) +lw(2.75i) |lw(2.75i) +. +ATTRIBUTE TYPEATTRIBUTE VALUE +_ +Interface StabilityVolatile +_ +MT-LevelSafe +.TE + +.SH SEE ALSO + +.LP + +\fBlibpapi\fR(3LIB), +\fBattributes\fR(5) +.sp + Added: trunk/papi/docs/man/papiJobSubmit.3papi.in =================================================================== --- trunk/papi/docs/man/papiJobSubmit.3papi.in (rev 0) +++ trunk/papi/docs/man/papiJobSubmit.3papi.in 2007-02-03 01:40:22 UTC (rev 182) @@ -0,0 +1,791 @@ +'\" te +.\" CDDL HEADER START +.\" +.\" The contents of this file are subject to the terms of the +.\" Common Development and Distribution License (the "License"). +.\" You may not use this file except in compliance with the License. +.\" +.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +.\" or http://www.opensolaris.org/os/licensing. +.\" See the License for the specific language governing permissions +.\" and limitations under the License. +.\" +.\" When distributing Covered Code, include this CDDL HEADER in each +.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE. +.\" If applicable, add the following below this CDDL HEADER, with the +.\" fields enclosed by brackets "[]" replaced with your own identifying +.\" information: Portions Copyright [yyyy] [name of copyright owner] +.\" +.\" CDDL HEADER END +.\" Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved. +.TH papiJobSubmit 3PAPI "17 Jan 2007" "SunOS 5.11" "PAPI Library Functions" +.SH NAME +papiJobSubmit, papiJobSubmitByReference, papiJobValidate, papiJobStreamOpen, papiJobStreamWrite, papiJobStreamClose, papiJobQuery, papiJobModify, papiJobMove, papiJobCancel, papiJobHold, papiJobRelease, papiJobRestart, papiJobPromote, papiJobGetAttributeList, papiJobGetPrinterName, papiJobGetId, papiJobGetJobTicket, papiJobFree, papiJobListFree \- job object manipulation +.SH SYNOPSIS +.LP +.nf +cc [ \fIflag\fR\&.\|.\|. ] \fIfile\fR\&.\|.\|. \fB-lpapi\fR [ \fIlibrary\fR\&.\|.\|. ] +#include <papi.h> + +\fBpapi_status_t\fR \fBpapiJobSubmit\fR(\fBpapi_service_t\fR \fIhandle\fR, + \fBchar *\fR\fIprinter\fR, \fBpapi_attribute_t **\fR\fIjob_attributes\fR, + \fBpapi_job_ticket_t *\fR\fIjob_ticket\fR, \fBchar **\fR\fIfiles\fR, + \fBpapi_job_t *\fR\fIjob\fR); +.fi +.LP +.nf +\fBpapi_status_t\fR \fBpapiJobSubmitByReference\fR(\fBpapi_service_t\fR \fIhandle\fR, + \fBchar *\fR\fIprinter\fR, \fBpapi_attribute_t **\fR\fIjob_attributes\fR, + \fBpapi_job_ticket_t *\fR\fIjob_ticket\fR, \fBchar **\fR\fIfiles\fR, + \fBpapi_job_t *\fR\fIjob\fR); +.fi +.LP +.nf +\fBpapi_status_t\fR \fBpapiJobValidate\fR(\fBpapi_service_t\fR \fIhandle\fR, + \fBchar *\fR\fIprinter\fR, \fBpapi_attribute_t **\fR\fIjob_attributes\fR, + \fBpapi_job_ticket_t *\fR\fIjob_ticket\fR, \fBchar **\fR\fIfiles\fR, + \fBpapi_job_t *\fR\fIjob\fR); +.fi +.LP +.nf +\fBpapi_status_t\fR \fBpapiJobStreamOpen\fR(\fBpapi_service_t\fR \fIhandle\fR, + \fBchar *\fR\fIprinter\fR, \fBpapi_attribute_t **\fR\fIjob_attributes\fR, + \fBpapi_job_ticket_t *\fR\fIjob_ticket\fR, \fBpapi_stream_t *\fR\fIstream\fR); +.fi +.LP +.nf +\fBpapi_status_t\fR \fBpapiJobStreamWrite\fR(\fBpapi_service_t\fR \fIhandle\fR, + \fBpapi_stream_t\fR \fIstream\fR, \fBvoid *\fR\fIbuffer\fR, \fBsize_t\fR \fIbuflen\fR); +.fi +.LP +.nf +\fBpapi_status_t\fR \fBpapiJobStreamClose\fR(\fBpapi_service_t\fR \fIhandle\fR, + \fBpapi_stream_t\fR \fIstream\fR, \fBpapi_job_t *\fR\fIjob\fR); +.fi +.LP +.nf +\fBpapi_status_t\fR \fBpapiJobQuery\fR(\fBpapi_service_t\fR \fIhandle\fR, + \fBchar *\fR\fIprinter\fR, \fBint32_t\fR \fIjob_id\fR, \fBchar **\fR\fIrequested_attrs\fR, + \fBpapi_job_t *\fR\fIjob\fR); +.fi +.LP +.nf +\fBpapi_status_t\fR \fBpapiJobModify\fR(\fBpapi_service_t\fR \fIhandle\fR, + \fBchar *\fR\fIprinter\fR, \fBint32_t\fR \fIjob_id\fR, + \fBpapi_attribute_t **\fR\fIattributes\fR, \fBpapi_job_t *\fR\fIjob\fR); +.fi +.LP +.nf +\fBpapi_status_t\fR \fBpapiJobMove\fR(\fBpapi_service_t\fR \fIhandle\fR, + \fBchar *\fR\fIprinter\fR, \fBint32_t\fR \fIjob_id\fR, \fBchar *\fR\fIdestination\fR); +.fi +.LP +.nf +\fBpapi_status_t\fR \fBpapiJobCancel\fR(\fBpapi_service_t\fR \fIhandle\fR, + \fBchar *\fR\fIprinter\fR, \fBint32_t\fR \fIjob_id\fR); +.fi +.LP +.nf +\fBpapi_status_t\fR \fBpapiJobHold\fR(\fBpapi_service_t\fR \fIhandle\fR, + \fBchar *\fR\fIprinter\fR, \fBint32_t\fR \fIjob_id\fR); +.fi +.LP +.nf +\fBpapi_status_t\fR \fBpapiJobRelease\fR(\fBpapi_service_t\fR \fIhandle\fR, + \fBchar *\fR\fIprinter\fR, \fBint32_t\fR \fIjob_id\fR); +.fi +.LP +.nf +\fBpapi_status_t\fR \fBpapiJobRestart\fR(\fBpapi_service_t\fR \fIhandle\fR, + \fBchar *\fR\fIprinter\fR, \fBint32_t\fR \fIjob_id\fR); +.fi +.LP +.nf +\fBpapi_status_t\fR \fBpapiJobPromote\fR(\fBpapi_service_t\fR \fIhandle\fR, + \fBchar *\fR\fIprinter\fR, \fBint32_t\fR \fIjob_id\fR); +.fi +.LP +.nf +\fBpapi_attribute_t **\fR\fBpapiJobGetAttributeList\fR(\fBpapi_job_t\fR \fIjob\fR); +.fi +.LP +.nf +\fBchar *\fR\fBpapiJobGetPrinterName\fR(\fBpapi_job_t\fR \fIjob\fR); +.fi +.LP +.nf +\fBint32_t\fR \fBpapiJobGetId\fR(\fBpapi_job_t\fR \fIjob\fR); +.fi +.LP +.nf +\fBpapi_job_ticket_t *\fR\fBpapiJobGetJobTicket\fR(\fBpapi_job_t\fR \fIjob\fR); +.fi +.LP +.nf +\fBvoid\fR \fBpapiJobFree\fR(\fBpapi_job_t\fR \fIjob\fR); +.fi +.LP +.nf +\fBvoid\fR \fBpapiJobListFree\fR(\fBpapi_job_t *\fR\fIjobs\fR); +.fi + +.SH PARAMETERS + +.sp +.ne 2 +.mk +.na +\fB\fIattributes\fR\fR +.ad +.RS 17n +.rt +a set of attributes to be applied to a printer object +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fIbuffer\fR\fR +.ad +.RS 17n +.rt +a buffer of data to be written to the job stream +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fIbufflen\fR\fR +.ad +.RS 17n +.rt +the size of the supplied buffer +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fIdestination\fR\fR +.ad +.RS 17n +.rt +the name of the printer where a print job should be relocated, which must reside within the same print services as the job is currently queued +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fIfiles\fR\fR +.ad +.RS 17n +.rt +files to use during job submission +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fIhandle\fR\fR +.ad +.RS 17n +.rt +a pointer to a handle to be used for all PAPI operations that is created by calling \fBpapiServiceCreate()\fR +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fIjob\fR\fR +.ad +.RS 17n +.rt +a pointer to a printer object (initialized to NULL) to be filled in by \fBpapiJobQuery()\fR, \fBpapiJobSubmit()\fR, \fBpapiJobSubmitByReference()\fR, \fBpapiJobValidate()\fR, \fBpapiJobStreamClose()\fR, and \fBpapiJobModify()\fR +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fIjob_attributes\fR\fR +.ad +.RS 17n +.rt +attributes to apply during job creation or modification +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fIjob_id\fR\fR +.ad +.RS 17n +.rt +ID number of the job reported on or manipulated +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fIjob_ticket\fR\fR +.ad +.RS 17n +.rt +unused +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fIjobs\fR\fR +.ad +.RS 17n +.rt +a list of job objects returned by \fBpapiPrinterListJobs()\fR or \fBpapiPrinterPurgeJobs()\fR +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fIprinter\fR\fR +.ad +.RS 17n +.rt +name of the printer where the job is or should reside +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fIrequested_attrs\fR\fR +.ad +.RS 17n +.rt +a null-terminated array of pointers to attribute names requested during job enumeration (\fBpapiPrinterListJobs()\fR) or job query (\fBpapiJobQuery()\fR) +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fIstream\fR\fR +.ad +.RS 17n +.rt +a communication endpoint for sending print job data +.sp + +.RE + +.SH DESCRIPTION + +.LP +The \fBpapiJobSubmit()\fR function creates a print job containing the passed in files with the supplied attributes. When the function returns, the data in the passed files will have been copied by the print service. A job object is returned that reflects the state of the job. +.sp + +.LP +The \fBpapiJobSubmitByReference()\fR function creates a print job containing the passed in files with the supplied attributes. When the function returns, the data in the passed files might have been copied by the print service. A job object is returned that reflects the state +of the job. +.sp + +.LP +The \fBpapiJobStreamOpen()\fR, \fBpapiJobStreamWrite()\fR, \fBpapiJobStreamClose()\fR functions create a print job by opening a stream, writing to the stream, and closing it. +.sp + +.LP +The \fBpapiJobValidate()\fR function validates that the supplied attributes and files will result in a valid print job. +.sp + +.LP +The \fBpapiJobQuery()\fR function retrieves job information from the print service. +.sp + +.LP +The \fBpapiJobModify()\fR function modifies a queued job according to the attribute list passed into the call. A job object is returned that reflects the state of the job after the modification has been applied. +.sp + +.LP +The \fBpapiJobMove()\fR function moves a job from its current queue to the named destination within the same print service. +.sp + +.LP +The \fBpapiJobCancel()\fR function removes a job from the queue. +.sp + +.LP +The \fBpapiJobHold()\fR and \fBpapiJobRelease()\fR functions set the job state to "held" or "idle" to indicate whether the job is eligible for processing. +.sp + +.LP +The \fBpapiJobRestart()\fR function restarts processing of a currently queued print job. +.sp + +.LP +The \fBpapiJobGetAttributeList()\fR function returns a list of attributes describing the job. This list can be searched and/or enumerated using \fBpapiAttributeList*()\fR calls. See +\fBpapiAttributeListAddValue\fR(3PAPI). +.sp + +.LP +The \fBpapiJobGetPrinterName()\fR function returns the name of the queue where the job is currently queued. +.sp + +.LP +The \fBpapiJobGetId()\fR function returns a job identifier number from the job object passed in. +.sp + +.LP +The \fBpapiJobPromote()\fR function moves a job to the head of the print queue. +.sp + +.LP +The \fBpapiJobGetJobTicket()\fR function retrieves a pointer to a job ticket associated with the job object. +.sp + +.LP +The \fBpapiJobFree()\fR and \fBpapiJobListFree()\fR functions deallocate memory allocated for the return of printer object(s) from functions that return printer objects. +.sp + +.SH RETURN VALUES + +.LP +Upon successful completion, all \fBpapiJob*()\fR functions that return a value return \fBPAPI_OK\fR. Otherwise, they return an appropriate \fBpapi_status_t\fR indicating the type of failure. +.sp + +.LP +Upon successful completion, \fBpapiJobGetAttributeList()\fR returns a pointer to the requested data. Otherwise, it returns \fINULL\fR. +.sp + +.SH EXAMPLES +.LP +\fBExample 1 \fREnumerate all jobs in a queue + +.LP +.in +2 +.nf +/* +* program to enumerate queued jobs using PAPI interfaces. +*/ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <libintl.h> +#include <pwd.h> +#include <papi.h> + +static int +authCB(papi_service_t svc, void *app_data) +{ + char prompt[BUFSIZ]; + char *user, *svc_name, *passphrase; + + /* get the name of the service we are contacting */ + if ((svc_name = papiServiceGetServiceName(svc)) == NULL) + return (-1); + + /* find out who we are supposed to be */ + if ((user = papiServiceGetUserName(svc)) == NULL) { + struct passwd *pw; + + if ((pw = getpwuid(getuid())) != NULL) + user = pw->pw_name; + else + user = "nobody"; + } + + /* build the prompt string */ + snprintf(prompt, sizeof (prompt), + gettext("passphrase for %s to access %s: "), user, + svc_name); + + /* ask for the passphrase */ + if ((passphrase = getpassphrase(prompt)) != NULL) + papiServiceSetPassword(svc, passphrase); + + return (0); +} + +/*ARGSUSED*/ +int +main(int ac, char *av[]) +{ + papi_status_t status; + papi_service_t svc = NULL; + papi_job_t *jobs = NULL; + char *svc_name = NULL; + char *pname = "unknown"; + int c; + + while ((c = getopt(ac, av, "s:p:")) != EOF) + switch (c) { + case 's': + svc_name = optarg; + break; + case 'p': + pname = optarg; + break; + } + + status = papiServiceCreate(&svc, svc_name, NULL, NULL, authCB, + PAPI_ENCRYPT_NEVER, NULL); + + if (status != PAPI_OK) { + printf("papiServiceCreate(%s): %s\n", svc_name ? svc_name : + "NULL", papiStatusString(status)); + papiServiceDestroy(svc); + exit(1); + } + + status = papiPrinterListJobs(svc, pname, NULL, 0, 0, &jobs); + if (status != PAPI_OK) { + printf("papiPrinterListJobs(%s): %s\n", pname, + papiStatusString(status)); + papiServiceDestroy(svc); + exit(1); + } + + if (jobs != NULL) { + int i; + + for (i = 0; jobs[i] != NULL; i++) { + papi_attribute_t **list = papiJobGetAttributeList(jobs[i]); + + if (list != NULL) { + char *name = "unknown"; + int32_t id = 0; + char *buffer = NULL; + size_t size = 0; + + (void) papiAttributeListGetString(list, NULL, + "printer-name", &name); + (void) papiAttributeListGetInteger(list, NULL, + "job-id", &id); + while (papiAttributeListToString(list, "\n\t", buffer, + size) != PAPI_OK) + buffer = realloc(buffer, size += BUFSIZ); + + printf("%s-%d:\n\t%s\n", name, id, buffer); + free(buffer); + } + } + papiJobListFree(jobs); + } + + papiServiceDestroy(svc); + + exit(0); +} +.fi +.in -2 +.LP +\fBExample 2 \fRDump all job attributes. + +.LP +.in +2 +.nf +/* +* program to dump a queued job's attributes using PAPI interfaces. +*/ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <libintl.h> +#include <pwd.h> +#include <papi.h> + +static int +authCB(papi_service_t svc, void *app_data) +{ + char prompt[BUFSIZ]; + char *user, *svc_name, *passphrase; + + /* get the name of the service we are contacting */ + if ((svc_name = papiServiceGetServiceName(svc)) == NULL) + return (-1); + + /* find out who we are supposed to be */ + if ((user = papiServiceGetUserName(svc)) == NULL) { + struct passwd *pw; + + if ((pw = getpwuid(getuid())) != NULL) + user = pw->pw_name; + else + user = "nobody"; + } + + /* build the prompt string */ + snprintf(prompt, sizeof (prompt), + gettext("passphrase for %s to access %s: "), user, + svc_name); + + /* ask for the passphrase */ + if ((passphrase = getpassphrase(prompt)) != NULL) + papiServiceSetPassword(svc, passphrase); + + return (0); +} + +/*ARGSUSED*/ +int +main(int ac, char *av[]) +{ + papi_status_t status; + papi_service_t svc = NULL; + papi_job_t job = NULL; + char *svc_name = NULL; + char *pname = "unknown"; + int id = 0; + int c; + + while ((c = getopt(ac, av, "s:p:j:")) != EOF) + switch (c) { + case 's': + svc_name = optarg; + break; + case 'p': + pname = optarg; + break; + case 'j': + id = atoi(optarg); + break; + } + + status = papiServiceCreate(&svc, svc_name, NULL, NULL, authCB, + PAPI_ENCRYPT_NEVER, NULL); + + if (status != PAPI_OK) { + printf("papiServiceCreate(%s): %s\n", svc_name ? svc_name : + "NULL", papiStatusString(status)); + papiServiceDestroy(svc); + exit(1); + } + + status = papiJobQuery(svc, pname, id, NULL, &job); + if ((status == PAPI_OK) && (job != NULL)) { + papi_attribute_t **list = papiJobGetAttributeList(job); + + if (list != NULL) { + char *name = "unknown"; + int32_t id = 0; + char *buffer = NULL; + size_t size = 0; + + (void) papiAttributeListGetString(list, NULL, + "printer-name", &name); + (void) papiAttributeListGetInteger(list, NULL, + "job-id", &id); + while (papiAttributeListToString(list, "\n\t", buffer, size) + != PAPI_OK) + buffer = realloc(buffer, size += BUFSIZ); + + printf("%s-%d:\n\t%s\n", name, id, buffer); + free(buffer); + } + } else + printf("papiJobQuery(%s-%d): %s\n", pname, id, + papiStatusString(status)); + + papiJobFree(job); + papiServiceDestroy(svc); + + exit(0); +} +.fi +.in -2 +.LP +\fBExample 3 \fRSubmit a job (stream). + +.LP +.in +2 +.nf +/* +* program to submit a job from standard input. +*/ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <libintl.h> +#include <pwd.h> +#include <papi.h> + +static int +authCB(papi_service_t svc, void *app_data) +{ + char prompt[BUFSIZ]; + char *user, *svc_name, *passphrase; + + /* get the name of the service we are contacting */ + if ((svc_name = papiServiceGetServiceName(svc)) == NULL) + return (-1); + + /* find out who we are supposed to be */ + if ((user = papiServiceGetUserName(svc)) == NULL) { + struct passwd *pw; + + if ((pw = getpwuid(getuid())) != NULL) + user = pw->pw_name; + else + user = "nobody"; + } + + /* build the prompt string */ + snprintf(prompt, sizeof (prompt), + gettext("passphrase for %s to access %s: "), user, + svc_name); + + /* ask for the passphrase */ + if ((passphrase = getpassphrase(prompt)) != NULL) + papiServiceSetPassword(svc, passphrase); + + return (0); +} + +/*ARGSUSED*/ +int +main(int ac, char *av[]) +{ + papi_status_t status; + papi_service_t svc = NULL; + papi_stream_t stream = NULL; + papi_job_t job = NULL; + papi_attribute_t **attrs = NULL; + char *svc_name = NULL; + char *pname = "unknown"; + int id = 0; + int c; + int rc; + char buf[BUFSIZ]; + + while ((c = getopt(ac, av, "s:p:")) != EOF) + switch (c) { + case 's': + svc_name = optarg; + break; + case 'p': + pname = optarg; + break; + } + + status = papiServiceCreate(&svc, svc_name, NULL, NULL, authCB, + PAPI_ENCRYPT_NEVER, NULL); + + if (status != PAPI_OK) { + printf("papiServiceCreate(%s): %s\n", svc_name ? svc_name : + "NULL", papiStatusString(status)); + papiServiceDestroy(svc); + exit(1); + } + + papiAttributeListAddInteger(&attrs, PAPI_ATTR_EXCL, "copies", 1); + papiAttributeListAddString(&attrs, PAPI_ATTR_EXCL, + "document-format", "application/octet-stream"); + papiAttributeListAddString(&attrs, PAPI_ATTR_EXCL, + "job-title", "Standard Input"); + + status = papiJobStreamOpen(svc, pname, attrs, NULL, &stream); + while ((status == PAPI_OK) && ((rc = read(0, buf, + sizeof (buf))) > 0)) + status = papiJobStreamWrite(svc, stream, buf, rc); + + if (status == PAPI_OK) + status = papiJobStreamClose(svc, stream, &job); + + + if ((status == PAPI_OK) && (job != NULL)) { + papi_attribute_t **list = papiJobGetAttributeList(job); + + if (list != NULL) { + char *name = "unknown"; + int32_t id = 0; + char *buffer = NULL; + size_t size = 0; + + (void) papiAttributeListGetString(list, NULL, + "printer-name", &name); + (void) papiAttributeListGetInteger(list, NULL, + "job-id", &id); + while (papiAttributeListToString(list, "\n\t", buffer, size) + != PAPI_OK) + buffer = realloc(buffer, size += BUFSIZ); + + printf("%s-%d:\n\t%s\n", name, id, buffer); + free(buffer); + } + } else + printf("papiJobStream*(%s-%d): %s\n", pname, id, + papiStatusString(status)); + + papiJobFree(job); + papiServiceDestroy(svc); + + exit(0); +} +.fi +.in -2 + +.SH ATTRIBUTES + +.LP +See +\fBattributes\fR(5) for descriptions of the following attributes: +.sp + +.LP + +.sp +.TS +tab() box; +cw(2.75i) |cw(2.75i) +lw(2.75i) |lw(2.75i) +. +ATTRIBUTE TYPEATTRIBUTE VALUE +_ +Interface StabilityVolatile +_ +MT-LevelSafe +.TE + +.SH SEE ALSO + +.LP + +\fBlibpapi\fR(3LIB), +\fBpapiAttributeListAddValue\fR(3PAPI), +\fBattributes\fR(5) +.sp + Added: trunk/papi/docs/man/papiLibrarySupportedCall.3papi.in =================================================================== --- trunk/papi/docs/man/papiLibrarySupportedCall.3papi.in (rev 0) +++ trunk/papi/docs/man/papiLibrarySupportedCall.3papi.in 2007-02-03 01:40:22 UTC (rev 182) @@ -0,0 +1,101 @@ +'\" te +.\" CDDL HEADER START +.\" +.\" The contents of this file are subject to the terms of the +.\" Common Development and Distribution License (the "License"). +.\" You may not use this file except in compliance with the License. +.\" +.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +.\" or http://www.opensolaris.org/os/licensing. +.\" See the License for the specific language governing permissions +.\" and limitations under the License. +.\" +.\" When distributing Covered Code, include this CDDL HEADER in each +.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE. +.\" If applicable, add the following below this CDDL HEADER, with the +.\" fields enclosed by brackets "[]" replaced with your own identifying +.\" information: Portions Copyright [yyyy] [name of copyright owner] +.\" +.\" CDDL HEADER END +.\" Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved. +.TH papiLibrarySupportedCall 3PAPI "17 Jan 2007" "SunOS 5.11" "PAPI Library Functions" +.SH NAME +papiLibrarySupportedCall, papiLibrarySupportedCalls \- determine if a PAPI function returns valid data +.SH SYNOPSIS +.LP +.nf +cc [ \fIflag\fR\&.\|.\|. ] \fIfile\fR\&.\|.\|. \fB-lpapi\fR [ \fIlibrary\fR\&.\|.\|. ] +#include <papi.h> + +\fBchar\fR \fBpapiLibrarySupportedCall\fR(\fBconst char *\fR\fIname\fR); +.fi +.LP +.nf +\fBchar **\fR\fBpapiLibrarySupportedCalls\fR(\fBvoid\fR); +.fi + +.SH PARAMETERS + +.sp +.ne 2 +.mk +.na +\fB\fIname\fR\fR +.ad +.RS 6n +.rt +the name of a PAPI function +.sp + +.RE + +.SH DESCRIPTION + +.LP +The \fBpapiLibrarySupportedCall()\fR function queries to determine if a particular PAPI function returns valid data other than \fBPAPI_OPERATION_NOT_SUPPORTED\fR. +.sp + +.LP +The \fBpapiLibrarySupportedCalls()\fR function enumerates all PAPI functions that return valid data other than \fBPAPI_OPERATION_NOT_SUPPORTED\fR. +.sp + +.SH RETURN VALUES + +.LP +The \fBpapiLibrarySupportedCall()\fR function returns \fBPAPI_TRUE\fR if the specified PAPI function returns valid data other than \fBPAPI_OPERATION_NOT_SUPPORTED\fR. Otherwise, \fBPAPI_FALSE\fR is returned. +.sp + +.LP +The \fBpapiLibrarySupportedCalls()\fR function returns a null-terminated array of strings listing all of the PAPI functions that return valid data other than \fBPAPI_OPERATION_NOT_SUPPORTED\fR. Otherwise, \fINULL\fR is returned. +.sp + +.SH ATTRIBUTES + +.LP +See +\fBattributes\fR(5) for descriptions of the following attributes: +.sp + +.LP + +.sp +.TS +tab() box; +cw(2.75i) |cw(2.75i) +lw(2.75i) |lw(2.75i) +. +ATTRIBUTE TYPEATTRIBUTE VALUE +_ +Interface StabilityVolatile +_ +MT-LevelSafe +.TE + +.SH SEE ALSO + +.LP + +\fBlibpapi\fR(3LIB), +\fBattributes\fR(5) +.sp + Added: trunk/papi/docs/man/papiPrintersList.3papi.in =================================================================== --- trunk/papi/docs/man/papiPrintersList.3papi.in (rev 0) +++ trunk/papi/docs/man/papiPrintersList.3papi.in 2007-02-03 01:40:22 UTC (rev 182) @@ -0,0 +1,588 @@ +'\" te +.\" CDDL HEADER START +.\" +.\" The contents of this file are subject to the terms of the +.\" Common Development and Distribution License (the "License"). +.\" You may not use this file except in compliance with the License. +.\" +.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +.\" or http://www.opensolaris.org/os/licensing. +.\" See the License for the specific language governing permissions +.\" and limitations under the License. +.\" +.\" When distributing Covered Code, include this CDDL HEADER in each +.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE. +.\" If applicable, add the following below this CDDL HEADER, with the +.\" fields enclosed by brackets "[]" replaced with your own identifying +.\" information: Portions Copyright [yyyy] [name of copyright owner] +.\" +.\" CDDL HEADER END +.\" Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved. +.TH papiPrintersList 3PAPI "17 Jan 2007" "SunOS 5.11" "PAPI Library Functions" +.SH NAME +papiPrintersList, papiPrinterQuery, papiPrinterAdd, papiPrinterModify, papiPrinterRemove, papiPrinterDisable, papiPrinterEnable, papiPrinterPause, papiPrinterResume, papiPrinterPurgeJobs, papiPrinterListJobs, papiPrinterGetAttributeList, papiPrinterFree, papiPrinterListFree \- print object manipulation +.SH SYNOPSIS +.LP +.nf +cc [ \fIflag\fR\&.\|.\|. ] \fIfile\fR\&.\|.\|. \fB-lpapi\fR [ \fIlibrary\fR\&.\|.\|. ] +#include <papi.h> + +\fBpapi_status_t\fR \fBpapiPrintersList\fR(\fBpapi_service_t\fR \fIhandle\fR, + \fBchar **\fR\fIrequested_attrs\fR, \fBpapi_filter_t *\fR\fIfilter\fR, + \fBpapi_printer_t **\fR\fIprinters\fR); +.fi +.LP +.nf +\fBpapi_status_t\fR \fBpapiPrinterQuery\fR(\fBpapi_service_t\fR \fIhandle\fR, \fBchar *\fR\fIname\fR, + \fBchar **\fR\fIrequested_attrs\fR, \fBpapi_attribute_t **\fR\fIjob_attributes\fR, + \fBpapi_printer_t *\fR\fIprinter\fR); +.fi +.LP +.nf +\fBpapi_status_t\fR \fBpapiPrinterAdd\fR(\fBpapi_service_t\fR \fIhandle\fR, \fBchar *\fR\fIname\fR, + \fBpapi_attribute_t **\fR\fIattributes\fR, \fBpapi_printer_t *\fR\fIprinter\fR); +.fi +.LP +.nf +\fBpapi_status_t\fR \fBpapiPrinterModify\fR(\fBpapi_service_t\fR \fIhandle\fR, \fBchar *\fR\fIname\fR, + \fBpapi_attribute_t **\fR\fIattributes\fR, \fBpapi_printer_t *\fR\fIprinter\fR); +.fi +.LP +.nf +\fBpapi_status_t\fR \fBpapiPrinterRemove\fR(\fBpapi_service_t\fR \fIhandle\fR, \fBchar *\fR\fIname\fR); +.fi +.LP +.nf +\fBpapi_status_t\fR \fBpapiPrinterDisable\fR(\fBpapi_service_t\fR \fIhandle\fR, \fBchar *\fR\fIname\fR, + \fBchar *\fR\fImessage\fR); +.fi +.LP +.nf +\fBpapi_status_t\fR \fBpapiPrinterEnable\fR(\fBpapi_service_t\fR \fIhandle\fR, \fBchar *\fR\fIname\fR); +.fi +.LP +.nf +\fBpapi_status_t\fR \fBpapiPrinterPause\fR(\fBpapi_service_t\fR \fIhandle\fR, \fBchar *\fR\fIname\fR, + \fBchar *\fR\fImessage\fR); +.fi +.LP +.nf +\fBpapi_status_t\fR \fBpapiPrinterResume\fR(\fBpapi_service_t\fR \fIhandle\fR, \fBchar *\fR\fIname\fR); +.fi +.LP +.nf +\fBpapi_status_t\fR \fBpapiPrinterPurgeJobs\fR(\fBpapi_service_t\fR \fIhandle\fR, \fBchar *\fR\fIname\fR, + \fBpapi_job_t **\fR\fIjobs\fR); +.fi +.LP +.nf +\fBpapi_status_t\fR \fBpapiPrinterListJobs\fR(\fBpapi_service_t\fR \fIhandle\fR, \fBchar *\fR\fIname\fR, + \fBchar **\fR\fIrequested_attrs\fR, \fBint\fR \fItype_mask\fR, \fBint\fR \fImax_num_jobs\fR, + \fBpapi_job_t **\fR\fIjobs\fR); +.fi +.LP +.nf +\fBpapi_attribute_t **\fR\fBpapiPrinterGetAttributeList\fR(\fBpapi_printer_t\fR \fIprinter\fR); +.fi +.LP +.nf +\fBvoid\fR \fBpapiPrinterFree\fR(\fBpapi_printer_t\fR \fIprinter\fR); +.fi +.LP +.nf +\fBvoid\fR \fBpapiPrinterListFree\fR(\fBpapi_printer_t *\fR\fIprinters\fR); +.fi + +.SH PARAMETERS + +.sp +.ne 2 +.mk +.na +\fB\fIattributes\fR\fR +.ad +.RS 17n +.rt +a set of attributes to be applied to a printer object +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fIfilter\fR\fR +.ad +.RS 17n +.rt +a filter to be applied during printer enumeration +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fIhandle\fR\fR +.ad +.RS 17n +.rt +a pointer to a handle to be used for all PAPI operations, created by calling \fBpapiServiceCreate()\fR +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fIjob_attributes\fR\fR +.ad +.RS 17n +.rt +unused +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fIjobs\fR\fR +.ad +.RS 17n +.rt +a pointer to a list to return job objects (initialized to \fINULL\fR) enumerated by \fBpapiPrinterGetJobs()\fR +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fImax_num_jobs\fR\fR +.ad +.RS 17n +.rt +the maximum number of jobs to return from a \fBpapiPrinterGetJobs()\fR request +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fImessage\fR\fR +.ad +.RS 17n +.rt +a message to be associated with a printer while disabled or paused +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fIname\fR\fR +.ad +.RS 17n +.rt +the name of the printer object being operated on +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fIprinter\fR\fR +.ad +.RS 17n +.rt +a pointer to a printer object (initialized to \fINULL\fR) to be filled in by \fBpapiPrinterQuery()\fR, \fBpapiPrinterAdd()\fR, and \fBpapiPrinterModify()\fR +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fIprinters\fR\fR +.ad +.RS 17n +.rt +a pointer to a list to return printer objects (initialized to \fINULL\fR) enumerated by \fBpapiPrintersList()\fR +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fIrequested_attrs\fR\fR +.ad +.RS 17n +.rt +a null-terminated array of pointers to attribute names requested during printer enumeration (\fBpapiPrintersList()\fR), printer query (\fBpapiPrinterQuery()\fR), or job enumeration (\fBpapiPrinterListJobs()\fR) +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fItype_mask\fR\fR +.ad +.RS 17n +.rt +a bit field indicating which type of jobs to return \fBPAPI_LIST_JOBS_OTHERS\fR include jobs submitted by others. The default is to report only on your own jobs +.sp + +.sp +.ne 2 +.mk +.na +\fB\fBPAPI_LIST_JOBS_COMPLETED\fR\fR +.ad +.sp .6 +.RS 4n + +include completed jobs +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBPAPI_LIST_JOBS_NOT_COMPLETED\fR\fR +.ad +.sp .6 +.RS 4n + +include jobs not complete +.sp + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBPAPI_LIST_JOBS_ALL\fR\fR +.ad +.sp .6 +.RS 4n + +report on all jobs +.sp + +.RE + +.RE + +.SH DESCRIPTION + +.LP +The \fBpapiPrintersList()\fR function retrieves the requested attributes from the print service(s) for all available printers. Because the Solaris implementation is name service-enabled, applications should retrieve only the \fBprinter-name\fR and \fBprinter-uri-supported\fR attributes using this function, thereby reducing the overhead involved in generating a printer list. Further integration of printer state and capabilities can be performed with \fBpapiPrinterQuery()\fR. +.sp + +.LP +The \fBpapiPrinterAdd()\fR, \fBpapiPrinterModify()\fR, and \fBpapiPrinterRemove()\fR functions allow for creation, modification, and removal of print queues. Print queues are added or modified according to the attribute list passed into the call. A +printer object is returned that reflects the configuration of the printer after the addition or modification has been applied. At this time, they provide only minimal functionality and only for the LP print service. +.sp + +.LP +The \fBpapiPrinterDisable()\fR and \fBpapiPrinterEnable()\fR functions allow applications to turn off and on queueing (accepting print requests) for a print queue. The \fBpapiPrinterEnable()\fR and \fBpapiPrinterDisable()\fR functions allow +applications to turn on and off print job processing for a print queue. +.sp + +.LP +The \fBpapiPrinterPause()\fR function stops queueing of print jobs on the named print queue. +.sp + +.LP +The \fBpapiPrinterResume()\fR function resumes queueing of print jobs on the named print queue. +.sp + +.LP +The \fBpapiPrinterPurgeJobs()\fR function allows applications to delete all print jobs that it has privilege to remove. A list of cancelled jobs is returned in the jobs argument. +.sp + +.LP +The \fBpapiPrinterListJobs()\fR function enumerates print jobs on a particular queue. \fBpapiPrinterGetAttributeList()\fR retrieves an attribute list from a printer object. +.sp + +.LP +The \fBpapiPrinterGetAttributeList()\fR function retrieves an attribute list from a printer object returned from \fBpapiPrinterQuery()\fR, \fBpapiPrintersList()\fR, \fBpapiPrinterModify()\fR, and \fBpapiPrinterAdd()\fR. This +attribute list can be searched for various information about the printer object. +.sp + +.LP +The \fBpapiPrinterFree()\fR and \fBpapiPrinterListFree()\fR functions deallocate memory allocated for the return of printer object(s) from functions that return printer objects. +.sp + +.SH RETURN VALUES + +.LP +Upon successful completion, all functions that return a value return \fBPAPI_OK\fR. Otherwise, they return an appropriate \fBpapi_status_t()\fR indicating the type of failure. +.sp + +.LP +Upon successful completion, \fBpapiPrinterGetAttributeList()\fR returns a pointer to the requested data. Otherwise, it returns \fINULL\fR. +.sp + +.SH EXAMPLES +.LP +\fBExample 1 \fREnumerate all available printers. + +.LP +.in +2 +.nf +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <libintl.h> +#include <pwd.h> +#include <papi.h> + +static int +authCB(papi_service_t svc, void *app_data) +{ + char prompt[BUFSIZ]; + char *user, *svc_name, *passphrase; + + /* get the name of the service we are contacting */ + if ((svc_name = papiServiceGetServiceName(svc)) == NULL) + return (-1); + + /* find out who we are supposed to be */ + if ((user = papiServiceGetUserName(svc)) == NULL) { + struct passwd *pw; + + if ((pw = getpwuid(getuid())) != NULL) + user = pw->pw_name; + else + user = "nobody"; + } + + /* build the prompt string */ + snprintf(prompt, sizeof (prompt), + gettext("passphrase for %s to access %s: "), user, + svc_name); + + /* ask for the passphrase */ + if ((passphrase = getpassphrase(prompt)) != NULL) + papiServiceSetPassword(svc, passphrase); + + return (0); +} + +/*ARGSUSED*/ +int +main(int ac, char *av[]) +{ + papi_status_t status; + papi_service_t svc = NULL; + papi_printer_t *printers = NULL; + char *attrs[] = { "printer-name", "printer-uri-supported", NULL }; + char *svc_name = NULL; + int c; + + while ((c = getopt(ac, av, "s:")) != EOF) + switch (c) { + case 's': + svc_name = optarg; + break; + } + + status = papiServiceCreate(&svc, svc_name, NULL, NULL, authCB, + PAPI_ENCRYPT_NEVER, NULL); + + if (status != PAPI_OK) { + printf("papiServiceCreate(%s): %s\en", svc_name ? svc_name : + "NULL", papi... [truncated message content] |
From: <nj...@us...> - 2006-10-16 05:23:13
|
Revision: 181 http://svn.sourceforge.net/openprinting/?rev=181&view=rev Author: njacobs Date: 2006-10-15 22:22:57 -0700 (Sun, 15 Oct 2006) Log Message: ----------- fix core dump during papiJobCancel() to rfc1179 server lp(1) process '-' as a standard input for standards compliance lpc fix core dump when run non-interactively. libpapi leaks fds cleanup nss support on Solaris papiPrintersList() wouldn't return proper results after the first call. use libmd5 if it's already on the system. Modified Paths: -------------- trunk/papi/ChangeLog trunk/papi/configure.in trunk/papi/source/bsd-sysv-commands/lp.c trunk/papi/source/bsd-sysv-commands/lpc.c trunk/papi/source/bsd-sysv-commands/lpr.c trunk/papi/source/libhttp-core/Makefile.am trunk/papi/source/libhttp-core/http.h trunk/papi/source/libpapi-dynamic/nss.c trunk/papi/source/libpapi-dynamic/printer.c trunk/papi/source/libpapi-dynamic/service.c trunk/papi/source/libpapi-ipp/Makefile.am trunk/papi/source/libpapi-ipp/ipp-support.c trunk/papi/source/libpapi-lpd/lpd-cancel.c Modified: trunk/papi/ChangeLog =================================================================== --- trunk/papi/ChangeLog 2006-07-20 17:33:02 UTC (rev 180) +++ trunk/papi/ChangeLog 2006-10-16 05:22:57 UTC (rev 181) @@ -1,3 +1,26 @@ +2006-10-15 Norm Jacobs <Norm.Jacobs@Sun.COM> + * source/libpapi-lpd/lpd-cancel.c: + fix core dump during papiJobCancel() to rfc1179 server + * source/bsd-sysv-commands/lp.c: + process '-' as a standard input for standards compliance + * source/bsd-sysv-commands/lpr.c: + process '-' as a standard input to match lp(1) + * source/bsd-sysv-commands/lpc.c: + fix core dump when run non-interactively. + * source/libpapi-dynamic/service.c + libpapi leaks fds + * source/libpapi-dynamic/nss.c + cleanup nss support on Solaris + * source/libpapi-dynamic/printer.c + papiPrintersList() wouldn't return proper results after the + first call. + * configure.in: + * source/libhttp-core/Makefile.in: + * source/libhttp-core/http.h: + * source/libpapi-ipp/Makefile.am: + * source/libpapi-ipp/ipp-support.c: + use libmd5 if it's already on the system. + 2006-07-20 Norm Jacobs <Norm.Jacobs@Sun.COM> * source/libpapi-dynamic/nss.c: fix core dump from invalid printers.conf entry where Modified: trunk/papi/configure.in =================================================================== --- trunk/papi/configure.in 2006-07-20 17:33:02 UTC (rev 180) +++ trunk/papi/configure.in 2006-10-16 05:22:57 UTC (rev 181) @@ -87,6 +87,10 @@ AC_MSG_CHECKING([NSS Support]) AC_MSG_RESULT([$nss_support]) +AC_CHECK_HEADERS(md5.h) +AC_CHECK_LIB(md5, md5_calc, [libmd5=true], [libmd5=false]) +AM_CONDITIONAL(HAVE_LIBMD5, [ test x$libmd5 = xtrue ] ) + dnl do we want the broken papiPrintersList printer-uri semantics AC_ARG_ENABLE(broken-printer-uri-semantic, [ --enable-broken-printer-uri-semantic build nss support to add a printer-uri to printer enumeration results for applications that use this instead of printer-uri-supported (only libgnomeprint-2.12.0 and earlier libgnomeprintpapi modules should need this enabled)], Modified: trunk/papi/source/bsd-sysv-commands/lp.c =================================================================== --- trunk/papi/source/bsd-sysv-commands/lp.c 2006-07-20 17:33:02 UTC (rev 180) +++ trunk/papi/source/bsd-sysv-commands/lp.c 2006-10-16 05:22:57 UTC (rev 181) @@ -244,6 +244,9 @@ ((printer = getenv("LPDEST")) == NULL)) printer = DEFAULT_DEST; + if (((optind + 1) == ac) && (strcmp(av[optind], "-") == 0)) + optind = ac; + if (modify == -1) { char *document_format = "application/octet-stream"; Modified: trunk/papi/source/bsd-sysv-commands/lpc.c =================================================================== --- trunk/papi/source/bsd-sysv-commands/lpc.c 2006-07-20 17:33:02 UTC (rev 180) +++ trunk/papi/source/bsd-sysv-commands/lpc.c 2006-10-16 05:22:57 UTC (rev 181) @@ -463,12 +463,30 @@ return (-1); } - if (((printer != NULL) && (strcmp(printer, "all") != 0)) || - (num_args <= ac)) - rc = process_one(handler, av, num_args); - else + if (((ac == 0) && (num_args != 0)) || + ((printer != NULL) && strcmp(printer, "all") == 0)) rc = process_all(handler, av, num_args); + else if (num_args < ac) { + int i; + char *argv[4]; + memset(argv, 0, sizeof (argv)); + argv[0] = av[0]; + + if (strcmp(av[0], "topq") == 0) { + argv[1] = av[1]; + for (i = 2; i <= ac; i++) { + argv[2] = av[i]; + process_one(handler, argv, num_args); + } + } else + for (i = 1; i <= ac; i++) { + argv[1] = av[i]; + process_one(handler, argv, num_args); + } + } else + rc = process_one(handler, av, num_args); + return (rc); } @@ -506,7 +524,7 @@ if ((av = strsplit(line, " \t\n")) != NULL) for (ac = 0; av[ac] != NULL; ac++); - (void) process(ac, av); + (void) process(ac - 1, av); free(av); } } @@ -532,7 +550,7 @@ if (optind == ac) lpc_shell(); else - result = process(optind - 2, &av[optind]); + result = process(ac - optind - 1, &av[optind]); return (result); } Modified: trunk/papi/source/bsd-sysv-commands/lpr.c =================================================================== --- trunk/papi/source/bsd-sysv-commands/lpr.c 2006-07-20 17:33:02 UTC (rev 180) +++ trunk/papi/source/bsd-sysv-commands/lpr.c 2006-10-16 05:22:57 UTC (rev 181) @@ -205,6 +205,9 @@ ((printer = getenv("LPDEST")) == NULL)) printer = DEFAULT_DEST; + if (((optind + 1) == ac) && (strcmp(av[optind], "-") == 0)) + optind = ac; + #ifdef MAGIC_MIME if (optind != ac) { /* get the mime type of the file data */ Modified: trunk/papi/source/libhttp-core/Makefile.am =================================================================== --- trunk/papi/source/libhttp-core/Makefile.am 2006-07-20 17:33:02 UTC (rev 180) +++ trunk/papi/source/libhttp-core/Makefile.am 2006-10-16 05:22:57 UTC (rev 181) @@ -41,6 +41,10 @@ libhttp_core_includedir = $(includedir)/papi # HTTP code lifted from CUPS libhttp_core_include_HEADERS = debug.h http.h http-private.h -libhttp_core_la_SOURCES = http-addr.c http-support.c http.c md5.c md5passwd.c +libhttp_core_la_SOURCES = http-addr.c http-support.c http.c +if !HAVE_LIBMD5 +libhttp_core_la_SOURCES += md5.c md5passwd.c +endif + EXTRA_DIST = mapfile.in Modified: trunk/papi/source/libhttp-core/http.h =================================================================== --- trunk/papi/source/libhttp-core/http.h 2006-07-20 17:33:02 UTC (rev 180) +++ trunk/papi/source/libhttp-core/http.h 2006-10-16 05:22:57 UTC (rev 181) @@ -54,7 +54,9 @@ # endif /* AF_LOCAL */ # endif /* WIN32 */ +#ifndef HAVE_MD5_H # include "md5.h" +#endif /* @@ -318,7 +320,9 @@ char buffer[HTTP_MAX_BUFFER]; /* Buffer for messages */ int auth_type; /* Authentication in use */ +#ifndef HAVE_MD5_H _cups_md5_state_t md5_state; /* MD5 state */ +#endif char nonce[HTTP_MAX_VALUE]; /* Nonce value */ int nonce_count; /* Nonce count */ Modified: trunk/papi/source/libpapi-dynamic/nss.c =================================================================== --- trunk/papi/source/libpapi-dynamic/nss.c 2006-07-20 17:33:02 UTC (rev 180) +++ trunk/papi/source/libpapi-dynamic/nss.c 2006-10-16 05:22:57 UTC (rev 181) @@ -25,8 +25,9 @@ * */ -#pragma ident "$Id$" +/* Id: nss.c 180 2006-07-20 17:33:02Z njacobs $ */ + #include <stdio.h> #include <stdlib.h> #include <unistd.h> @@ -441,7 +442,6 @@ static DEFINE_NSS_GETENT(context); static char *private_ns = NULL; -static char initialized = 0; static void _nss_initf_printers(p) @@ -457,14 +457,12 @@ */ p->name = NSS_DBNAM__PRINTERS; /* "_printers" */ p->default_config = private_ns; - private_ns = NULL; - } else if (initialized == 0) { + } else { /* regular behaviour */ p->name = NSS_DBNAM_PRINTERS; /* "printers" */ p->default_config = NSS_DEFCONF_PRINTERS; - initialized = 1; } - syslog(LOG_DEBUG, "database: %s, services: %s", + syslog(LOG_DEBUG, "database: %s, default: %s", (p->name ? p->name : "NULL"), (p->default_config ? p->default_config : "NULL")); } @@ -481,6 +479,11 @@ { if (lenstr + 1 > buflen) return (NSS_STR_PARSE_ERANGE); + + /* skip entries that begin with '#' */ + if (instr[0] == '#') + return (NSS_STR_PARSE_PARSE); + /* * We copy the input string into the output buffer */ @@ -497,9 +500,9 @@ #ifdef NSS_EMULATION emul_setprinterentry(stayopen); #elif NSS_SOLARIS - initialized = 0; private_ns = ns; nss_setent(&db_root, _nss_initf_printers, &context); + private_ns = NULL; #endif return (0); } @@ -511,9 +514,9 @@ #ifdef NSS_EMULATION emul_endprinterentry(); #elif NSS_SOLARIS - initialized = 0; nss_endent(&db_root, _nss_initf_printers, &context); nss_delete(&db_root); + private_ns = NULL; #endif return (0); } @@ -533,9 +536,11 @@ #elif NSS_SOLARIS nss_XbyY_args_t arg; + private_ns = ns; NSS_XbyY_INIT(&arg, buf, buf, sizeof (buf), str2printer); res = nss_getent(&db_root, _nss_initf_printers, &context, &arg); (void) NSS_XbyY_FINI(&arg); + private_ns = NULL; #endif if (res != NSS_SUCCESS) @@ -600,6 +605,7 @@ res = nss_search(&db_root, _nss_initf_printers, NSS_DBOP_PRINTERS_BYNAME, &arg); (void) NSS_XbyY_FINI(&arg); + private_ns = NULL; if (res != NSS_SUCCESS) buf[0] = '\0'; Modified: trunk/papi/source/libpapi-dynamic/printer.c =================================================================== --- trunk/papi/source/libpapi-dynamic/printer.c 2006-07-20 17:33:02 UTC (rev 180) +++ trunk/papi/source/libpapi-dynamic/printer.c 2006-10-16 05:22:57 UTC (rev 181) @@ -177,6 +177,7 @@ return (PAPI_BAD_ARGUMENT); /* retrieve printers from the nameservice */ + setprinterentry(0, NULL); while ((attrs = getprinterentry(NULL)) != NULL) { printer_t *p = NULL; Modified: trunk/papi/source/libpapi-dynamic/service.c =================================================================== --- trunk/papi/source/libpapi-dynamic/service.c 2006-07-20 17:33:02 UTC (rev 180) +++ trunk/papi/source/libpapi-dynamic/service.c 2006-10-16 05:22:57 UTC (rev 181) @@ -180,6 +180,9 @@ if (svc->so_handle != NULL) { papi_status_t (*f)(); + if (svc->svc_handle != NULL) /* already connected? */ + return (PAPI_OK); + f = (papi_status_t (*)())psm_sym(svc, "papiServiceCreate"); if (f != NULL) { Modified: trunk/papi/source/libpapi-ipp/Makefile.am =================================================================== --- trunk/papi/source/libpapi-ipp/Makefile.am 2006-07-20 17:33:02 UTC (rev 180) +++ trunk/papi/source/libpapi-ipp/Makefile.am 2006-10-16 05:22:57 UTC (rev 181) @@ -44,6 +44,10 @@ psm_ipp_la_LDFLAGS += -Wl,-Bsymbolic endif +if HAVE_LIBMD5 +psm_ipp_la_LIBADD += -lmd5 +endif + psm_ippincludedir = $(includedir) # PAPI support layered on IPP Modified: trunk/papi/source/libpapi-ipp/ipp-support.c =================================================================== --- trunk/papi/source/libpapi-ipp/ipp-support.c 2006-07-20 17:33:02 UTC (rev 180) +++ trunk/papi/source/libpapi-ipp/ipp-support.c 2006-10-16 05:22:57 UTC (rev 181) @@ -37,6 +37,10 @@ #include <config-site.h> +#ifdef HAVE_MD5_H +#include <md5.h> +#endif + papi_status_t http_to_papi_status(http_status_t status) { @@ -452,15 +456,31 @@ "Digest", 6) == 0) { char realm[HTTP_MAX_VALUE]; char nonce[HTTP_MAX_VALUE]; + char line [BUFSIZ]; + char urp[128]; + char mr[128]; char *uri = svc->post; httpGetSubField(http, HTTP_FIELD_WWW_AUTHENTICATE, "realm", realm); httpGetSubField(http, HTTP_FIELD_WWW_AUTHENTICATE, "nonce", nonce); - httpMD5(user, realm, passphrase, encoded); - httpMD5Final(nonce, "POST", uri, encoded); +#ifdef HAVE_MD5_H + snprintf(line, sizeof (line), "%s:%s:%s", user, realm, + passphrase); + md5_calc(urp, line, strlen(line)); + + snprintf(line, sizeof (line), "POST:%s", uri); + md5_calc(mr, line, strlen(line)); + + snprintf(line, sizeof (line), "%s:%s:%s", urp, mr, nonce); + md5_calc(encoded, line, strlen(line)); +#else + httpMD5(user, realm, passphrase, line); + httpMD5(nonce, "POST", uri, encoded); +#endif + snprintf(http->authstring, sizeof (http->authstring), "Digest username=\"%s\", realm=\"%s\", nonce=\"%s\", " "uri=\"%s\", response=\"%s\"", user, realm, nonce, uri, Modified: trunk/papi/source/libpapi-lpd/lpd-cancel.c =================================================================== --- trunk/papi/source/libpapi-lpd/lpd-cancel.c 2006-07-20 17:33:02 UTC (rev 180) +++ trunk/papi/source/libpapi-lpd/lpd-cancel.c 2006-10-16 05:22:57 UTC (rev 181) @@ -39,7 +39,7 @@ { papi_status_t status = PAPI_INTERNAL_ERROR; int fd; - char **list; + char *list[2]; char buf[128]; /* this should be overkill */ if (svc == NULL) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nj...@us...> - 2006-07-20 17:33:44
|
Revision: 180 Author: njacobs Date: 2006-07-20 10:33:02 -0700 (Thu, 20 Jul 2006) ViewCVS: http://svn.sourceforge.net/openprinting/?rev=180&view=rev Log Message: ----------- fix core dump from invalid printers.conf entry where bsdaddr=server, not server,queue. Modified Paths: -------------- trunk/papi/ChangeLog trunk/papi/source/libpapi-dynamic/nss.c Modified: trunk/papi/ChangeLog =================================================================== --- trunk/papi/ChangeLog 2006-07-17 18:24:07 UTC (rev 179) +++ trunk/papi/ChangeLog 2006-07-20 17:33:02 UTC (rev 180) @@ -1,3 +1,8 @@ +2006-07-20 Norm Jacobs <Norm.Jacobs@Sun.COM> + * source/libpapi-dynamic/nss.c: + fix core dump from invalid printers.conf entry where + bsdaddr=server, not server,queue. + 2006-07-17 Norm Jacobs <Norm.Jacobs@Sun.COM> * source/libipp-listener/ipp-listener.c: Modified: trunk/papi/source/libpapi-dynamic/nss.c =================================================================== --- trunk/papi/source/libpapi-dynamic/nss.c 2006-07-17 18:24:07 UTC (rev 179) +++ trunk/papi/source/libpapi-dynamic/nss.c 2006-07-20 17:33:02 UTC (rev 180) @@ -49,7 +49,7 @@ static char * -bsdaddr_to_uri(char *bsdaddr) +bsdaddr_to_uri(papi_attribute_t **list, char *bsdaddr) { char *result = NULL; @@ -60,10 +60,13 @@ tmp = strdup(bsdaddr); bsd[0] = strtok_r(tmp, ":,", &iter); - bsd[1] = strtok_r(NULL, ":,", &iter); + if ((bsd[1] = strtok_r(NULL, ":,", &iter)) == NULL) + papiAttributeListGetString(list, NULL, + "printer-name", &bsd[1]); bsd[2] = strtok_r(NULL, ":,", &iter); - snprintf(buf, sizeof (buf), "lpd://%s/%s%s%s", bsd[0], bsd[1], + snprintf(buf, sizeof (buf), "lpd://%s/printers/%s%s%s", bsd[0], + (bsd[1] != NULL) ? bsd[1] : "", (bsd[2] != NULL) ? "#" : "", (bsd[2] != NULL) ? bsd[2] : ""); @@ -274,7 +277,7 @@ /* do we have a printers.conf(4) "bsdaddr" to convert */ papiAttributeListGetString(*list, NULL, "bsdaddr", &string); if (string != NULL) { /* parse it, convert it, add it */ - char *uri = bsdaddr_to_uri(string); + char *uri = bsdaddr_to_uri(*list, string); if (uri != NULL) { papiAttributeListAddString(list, PAPI_ATTR_APPEND, @@ -572,7 +575,7 @@ papiAttributeListAddString(&result, PAPI_ATTR_APPEND, "printer-uri-supported", name); } else if (strchr(name, ':') != NULL) { /* shortcut for POSIX form */ - char *uri = bsdaddr_to_uri(name); + char *uri = bsdaddr_to_uri(result, name); papiAttributeListAddString(&result, PAPI_ATTR_APPEND, "printer-name", name); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nj...@us...> - 2006-07-17 18:24:22
|
Revision: 179 Author: njacobs Date: 2006-07-17 11:24:07 -0700 (Mon, 17 Jul 2006) ViewCVS: http://svn.sourceforge.net/openprinting/?rev=179&view=rev Log Message: ----------- incorporate several fixes from Solaris Modified Paths: -------------- trunk/papi/ChangeLog trunk/papi/source/bsd-sysv-commands/in.lpd.c trunk/papi/source/bsd-sysv-commands/lp.c trunk/papi/source/bsd-sysv-commands/lpstat.c trunk/papi/source/libipp-listener/common.c trunk/papi/source/libipp-listener/ipp-listener.c trunk/papi/source/libpapi-dynamic/nss.c trunk/papi/source/libpapi-dynamic/service.c trunk/papi/source/libpapi-lpd/job.c trunk/papi/source/libpapi-lpd/lpd-job.c Modified: trunk/papi/ChangeLog =================================================================== --- trunk/papi/ChangeLog 2006-06-23 01:37:20 UTC (rev 178) +++ trunk/papi/ChangeLog 2006-07-17 18:24:07 UTC (rev 179) @@ -1,3 +1,27 @@ +2006-07-17 Norm Jacobs <Norm.Jacobs@Sun.COM> + + * source/libipp-listener/ipp-listener.c: + * source/libipp-listener/common.c: + use the client supplied printer uri to contact the + print service and fallback to the "default-service" + * source/libpapi-dynamic/service.c: + remove hidden whitespace + * source/libpapi-dynamic/nss.c: + more complete determination if the host is actually the + local host using "localhost", nodename, and configured + interfaces. + * source/bsd-sysv-commands/lpstat.c: + don't report the uri if it's not configured + * source/bsd-sysv-commands/lp.c: + report the supplied destination as the default + * source/bsd-sysv-commands/in.lpd.c: + add space after keyword + * source/libpapi-lpd/lpd-job.c: + remove hidden whitespace + * source/libpapi-lpd/job.c: + copying of attributes pointer in papJobStreamOpen is causing + double free on cleanup + 2006-06-22 Norm Jacobs <Norm.Jacobs@Sun.COM> * source/libpapi-dynamic/printer.c: Modified: trunk/papi/source/bsd-sysv-commands/in.lpd.c =================================================================== --- trunk/papi/source/bsd-sysv-commands/in.lpd.c 2006-06-23 01:37:20 UTC (rev 178) +++ trunk/papi/source/bsd-sysv-commands/in.lpd.c 2006-07-17 18:24:07 UTC (rev 179) @@ -77,7 +77,7 @@ /* This should actually implement transfer job from RFC-1179 */ ACK(ofp); - while (fgets(line, sizeof(line), ifp) != NULL) { + while (fgets(line, sizeof (line), ifp) != NULL) { switch (line[0]) { case 0x01: /* Abort */ cleanup(files); Modified: trunk/papi/source/bsd-sysv-commands/lp.c =================================================================== --- trunk/papi/source/bsd-sysv-commands/lp.c 2006-06-23 01:37:20 UTC (rev 178) +++ trunk/papi/source/bsd-sysv-commands/lp.c 2006-07-17 18:24:07 UTC (rev 179) @@ -301,13 +301,13 @@ if (((silent == 0) || (dump != 0)) && ((list = papiJobGetAttributeList(job)) != NULL)) { - char *dest = "unknown"; int32_t id = 0; - papiAttributeListGetString(list, NULL, "printer-name", &dest); + papiAttributeListGetString(list, NULL, + "printer-name", &printer); papiAttributeListGetInteger(list, NULL, "job-id", &id); - printf(gettext("request id is %s-%d "), dest, id); - if (ac != optind) + printf(gettext("request id is %s-%d "), printer, id); + if (ac != optind) printf("(%d file(s))\n", ac - optind); else printf("(standard input)\n"); Modified: trunk/papi/source/bsd-sysv-commands/lpstat.c =================================================================== --- trunk/papi/source/bsd-sysv-commands/lpstat.c 2006-06-23 01:37:20 UTC (rev 178) +++ trunk/papi/source/bsd-sysv-commands/lpstat.c 2006-07-17 18:24:07 UTC (rev 179) @@ -405,7 +405,7 @@ "lpsched-interface-script", &str); printf(gettext("\tInterface: %s\n"), str); - str = ""; + str = NULL; (void) papiAttributeListGetString(attrs, NULL, "ppd-file-uri", &str); (void) papiAttributeListGetString(attrs, NULL, Modified: trunk/papi/source/libipp-listener/common.c =================================================================== --- trunk/papi/source/libipp-listener/common.c 2006-06-23 01:37:20 UTC (rev 178) +++ trunk/papi/source/libipp-listener/common.c 2006-07-17 18:24:07 UTC (rev 179) @@ -100,10 +100,6 @@ *id = atoi(++job); } } - - /* move to the last component of the name */ - if (*printer != NULL) - *printer = strrchr(*printer, '/') + 1; } void Modified: trunk/papi/source/libipp-listener/ipp-listener.c =================================================================== --- trunk/papi/source/libipp-listener/ipp-listener.c 2006-06-23 01:37:20 UTC (rev 178) +++ trunk/papi/source/libipp-listener/ipp-listener.c 2006-07-17 18:24:07 UTC (rev 179) @@ -378,10 +378,9 @@ "requesting-user-name", &user); /* get the printer or service name */ - get_printer_id(operational, &printer_uri, NULL); - svc_name = destination_from_printer_uri(printer_uri); (void) papiAttributeListGetString(request, NULL, "default-service", &svc_name); + get_printer_id(operational, &svc_name, NULL); status = papiServiceCreate(svc, svc_name, user, NULL, NULL, PAPI_ENCRYPT_NEVER, NULL); Modified: trunk/papi/source/libpapi-dynamic/nss.c =================================================================== --- trunk/papi/source/libpapi-dynamic/nss.c 2006-06-23 01:37:20 UTC (rev 178) +++ trunk/papi/source/libpapi-dynamic/nss.c 2006-07-17 18:24:07 UTC (rev 179) @@ -76,6 +76,134 @@ } #if defined(__sun) && defined(__SVR4) +#include <sys/socket.h> +#include <sys/ioctl.h> +#include <sys/sockio.h> +#include <net/if.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <netdb.h> + +static struct in6_addr ** +local_interfaces() +{ + struct in6_addr **result = NULL; + int s; + struct lifnum n; + struct lifconf c; + struct lifreq *r; + int count; + + /* we need a socket to get the interfaces */ + if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) + return (0); + + /* get the number of interfaces */ + memset(&n, 0, sizeof (n)); + n.lifn_family = AF_UNSPEC; + if (ioctl(s, SIOCGLIFNUM, (char *)&n) < 0) { + close(s); + return (0); /* no interfaces */ + } + + /* get the interface(s) configuration */ + memset(&c, 0, sizeof (c)); + c.lifc_family = AF_UNSPEC; + c.lifc_buf = calloc(n.lifn_count, sizeof (struct lifreq)); + c.lifc_len = (n.lifn_count * sizeof (struct lifreq)); + if (ioctl(s, SIOCGLIFCONF, (char *)&c) < 0) { + free(c.lifc_buf); + close(s); + return (0); /* can't get interface(s) configuration */ + } + close(s); + + r = c.lifc_req; + for (count = c.lifc_len / sizeof (struct lifreq); + count > 0; count--, r++) { + struct in6_addr v6[1], *addr = NULL; + + switch (r->lifr_addr.ss_family) { + case AF_INET: { + struct sockaddr_in *s = + (struct sockaddr_in *)&r->lifr_addr; + IN6_INADDR_TO_V4MAPPED(&s->sin_addr, v6); + addr = v6; + } + break; + case AF_INET6: { + struct sockaddr_in6 *s = + (struct sockaddr_in6 *)&r->lifr_addr; + addr = &s->sin6_addr; + } + break; + } + + if (addr != NULL) { + struct in6_addr *a = malloc(sizeof (*a)); + + memcpy(a, addr, sizeof (*a)); + list_append(&result, a); + } + } + free(c.lifc_buf); + + return (result); +} + +static int +match_interfaces(char *host) +{ + struct in6_addr **lif = local_interfaces(); + struct hostent *hp; + int rc = 0; + int errnum; + + /* are there any local interfaces */ + if (lif == NULL) + return (0); + + /* cycle through the host db addresses */ + hp = getipnodebyname(host, AF_INET6, AI_ALL|AI_V4MAPPED, &errnum); + if (hp != NULL) { + struct in6_addr **tmp = (struct in6_addr **)hp->h_addr_list; + int i; + + for (i = 0; ((rc == 0) && (tmp[i] != NULL)); i++) { + int j; + + for (j = 0; ((rc == 0) && (lif[j] != NULL)); j++) + if (memcmp(tmp[i], lif[j], + sizeof (struct in6_addr)) == 0) + rc = 1; + } + } + free(lif); + + return (rc); +} + +static int +is_localhost(char *host) +{ + char hostname[BUFSIZ]; + + /* is it "localhost" */ + if (strncasecmp(host, "localhost", 10) == 0) + return (1); + + /* is it the {nodename} */ + sysinfo(SI_HOSTNAME, hostname, sizeof (hostname)); + if (strncasecmp(host, hostname, strlen(hostname)) == 0) + return (1); + + /* does it match one of the host's configured interfaces */ + if (match_interfaces(host) != 0) + return (1); + + return (0); +} + /* * This is an awful HACK to force the dynamic PAPI library to use the * lpsched support when the destination apears to be a local lpsched @@ -87,7 +215,6 @@ papi_attribute_t *attribute; uri_t *uri = NULL; char *printer = NULL; - char hostname[BUFSIZ]; char buf[128], buf2[128]; /* setting this in the calling env can be useful for debugging */ @@ -103,12 +230,6 @@ if (strcasecmp(uri->scheme, "lpsched") == 0) return; - sysinfo(SI_HOSTNAME, hostname, sizeof (hostname)); - if ((uri->host != NULL) && - (strncasecmp(uri->host, hostname, strlen(hostname)) != 0) && - (strncasecmp(uri->host, "localhost", 10) != 0)) - return; - if ((printer = strrchr(uri->path, '/')) == NULL) printer = uri->path; else @@ -120,7 +241,12 @@ if ((access(buf, F_OK) < 0) && (access(buf2, F_OK) < 0)) return; - snprintf(buf, sizeof (buf), "lpsched://localhost/printers/%s", printer); + /* is this the "local" host */ + if ((uri->host != NULL) && (is_localhost(uri->host) == 0)) + return; + + snprintf(buf, sizeof (buf), "lpsched://%s/printers/%s", + (uri->host ? uri->host : "localhost"), printer); papiAttributeListAddString(list, PAPI_ATTR_REPLACE, "printer-uri-supported", buf); } @@ -192,7 +318,7 @@ if ((list == NULL) || (*list == NULL)) return; - /* do we have a printer-uri-supported */ + /* do we have a printer-uri */ attribute = papiAttributeListFind(*list, "printer-uri"); if (attribute != NULL) /* we have what we need, return */ return; @@ -297,9 +423,6 @@ } fill_printer_uri_supported(&list); -#if defined(__sun) && defined(__SVR4) - solaris_lpsched_shortcircuit_hack(&list); -#endif cvt_all_to_member_names(&list); /* convert "all" to "member-names" */ return (list); @@ -416,6 +539,9 @@ buf[0] = '\0'; result = _cvt_nss_entry_to_printer(buf); +#if defined(__sun) && defined(__SVR4) + solaris_lpsched_shortcircuit_hack(&result); +#endif #ifdef NEED_BROKEN_PRINTER_URI_SEMANTIC fill_printer_uri(&result); #endif /* NEED_BROKEN_PRINTER_URI_SEMANTIC */ @@ -479,7 +605,9 @@ result = _cvt_nss_entry_to_printer(buf); #endif } - +#if defined(__sun) && defined(__SVR4) + solaris_lpsched_shortcircuit_hack(&result); +#endif #ifdef DEBUG printf("getprinterbyname(%s): %s = 0x%8.8x\n", (ns ? ns : "NULL"), name, result); Modified: trunk/papi/source/libpapi-dynamic/service.c =================================================================== --- trunk/papi/source/libpapi-dynamic/service.c 2006-06-23 01:37:20 UTC (rev 178) +++ trunk/papi/source/libpapi-dynamic/service.c 2006-07-17 18:24:07 UTC (rev 179) @@ -71,9 +71,7 @@ return (result); } - - static char * default_print_service() { Modified: trunk/papi/source/libpapi-lpd/job.c =================================================================== --- trunk/papi/source/libpapi-lpd/job.c 2006-06-23 01:37:20 UTC (rev 178) +++ trunk/papi/source/libpapi-lpd/job.c 2006-07-17 18:24:07 UTC (rev 179) @@ -141,7 +141,6 @@ if ((s->fd = mkstemp(dfname)) >= 0) s->dfname = strdup(dfname); - s->job->attributes = attributes; } s->metadata = metadata; Modified: trunk/papi/source/libpapi-lpd/lpd-job.c =================================================================== --- trunk/papi/source/libpapi-lpd/lpd-job.c 2006-06-23 01:37:20 UTC (rev 178) +++ trunk/papi/source/libpapi-lpd/lpd-job.c 2006-07-17 18:24:07 UTC (rev 179) @@ -97,7 +97,7 @@ *metadata = (char *)tmp; else return (PAPI_TEMPORARY_ERROR); - } + } snprintf(line, sizeof (line), "%c%s\n", code, value); strlcat(*metadata, line, size); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nj...@us...> - 2006-06-23 01:37:29
|
Revision: 178 Author: njacobs Date: 2006-06-22 18:37:20 -0700 (Thu, 22 Jun 2006) ViewCVS: http://svn.sourceforge.net/openprinting/?rev=178&view=rev Log Message: ----------- fixed papiPrinterQuery() to only use the binding if there is more complete information. Modified Paths: -------------- trunk/papi/ChangeLog trunk/papi/source/libpapi-dynamic/printer.c Modified: trunk/papi/ChangeLog =================================================================== --- trunk/papi/ChangeLog 2006-06-14 21:17:55 UTC (rev 177) +++ trunk/papi/ChangeLog 2006-06-23 01:37:20 UTC (rev 178) @@ -1,3 +1,9 @@ +2006-06-22 Norm Jacobs <Norm.Jacobs@Sun.COM> + + * source/libpapi-dynamic/printer.c: + fixed papiPrinterQuery() to only use the binding if + there is more complete information. + 2006-06-14 Till Kamppeter <Til...@gm...> * packaging/RPM/papi.spec: new and complete RPM support Modified: trunk/papi/source/libpapi-dynamic/printer.c =================================================================== --- trunk/papi/source/libpapi-dynamic/printer.c 2006-06-14 21:17:55 UTC (rev 177) +++ trunk/papi/source/libpapi-dynamic/printer.c 2006-06-23 01:37:20 UTC (rev 178) @@ -244,7 +244,8 @@ if ((*printer = p = calloc(1, sizeof (*p))) == NULL) return (PAPI_TEMPORARY_ERROR); - if (svc->name != NULL) { + if ((svc->name != NULL) && (svc->svc_handle != NULL) && + (svc->uri != NULL)) { p->svc = svc; f = (papi_status_t (*)())psm_sym(p->svc, "papiPrinterQuery"); if (f != NULL) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nj...@us...> - 2006-06-14 21:18:07
|
Revision: 177 Author: njacobs Date: 2006-06-14 14:17:55 -0700 (Wed, 14 Jun 2006) ViewCVS: http://svn.sourceforge.net/openprinting/?rev=177&view=rev Log Message: ----------- new and more complete RPM support from Till Kamppeter Modified Paths: -------------- trunk/papi/ChangeLog Added Paths: ----------- trunk/papi/packaging/RPM/papi.spec Modified: trunk/papi/ChangeLog =================================================================== --- trunk/papi/ChangeLog 2006-05-25 07:56:17 UTC (rev 176) +++ trunk/papi/ChangeLog 2006-06-14 21:17:55 UTC (rev 177) @@ -1,3 +1,7 @@ +2006-06-14 Till Kamppeter <Til...@gm...> + + * packaging/RPM/papi.spec: new and complete RPM support + 2006-05-25 Kouhei Sutou <ko...@co...> * source/ruby/rb-papi-printer.c: implemented non-standard Added: trunk/papi/packaging/RPM/papi.spec =================================================================== --- trunk/papi/packaging/RPM/papi.spec (rev 0) +++ trunk/papi/packaging/RPM/papi.spec 2006-06-14 21:17:55 UTC (rev 177) @@ -0,0 +1,504 @@ +##### VERSION NUMBERS + +%define papiversion 1.0 +%define papiextraversion svn-r +%define papisvnrevision 171 +%define papireleaseno 0.%{papisvnrevision}.2 +%define papirelease %mkrel %papireleaseno +%define papimajor 0 +%define libpapi %mklibname papi %{papimajor} + +##### BUILD OPTIONS + +%define debug 0 +%define withapache 0 +%define withruby 1 + +##### RPM PROBLEM WORKAROUNDS + +# Suppress automatically generated Requires for devel packages and +# for libpapi.so.0 (this one will be generated by update-alternatives +# in the postinstall script of libpapi) +%define _requires_exceptions devel\(.*\)\\|libpapi\.so\.%{papimajor} + +# Suppress automatically generated Requires for Perl libraries. +#define _requires_exceptions perl\(.*\) + +#define _unpackaged_files_terminate_build 0 +#define _missing_doc_files_terminate_build 0 + +##### GENERAL DEFINITIONS + +Summary: FSG OpenPrinting PAPI Implementation(s) and Applications +Name: papi +Version: %{papiversion} +Release: %{papirelease} +License: GPL/LPGL/MIT/CDDL +Group: System/Servers +Requires: /usr/sbin/update-alternatives +URL: http://openprinting.sourceforge.net/ + + +##### BUILDREQUIRES + +%if %{withapache} +BuildRequires: apache-devel +%endif +%if %{withruby} +BuildRequires: ruby-devel +%endif + + + +##### PAPI SOURCES + +Source0: http://sourceforge.net/projects/openprinting/papi-%{papiversion}%{papiextraversion}%{papisvnrevision}.tar.bz2 + +##### PAPI PATCHES + +# Fixed acinclude.m4 so that it is also checked for the apr.h file of +# libapr-1 which is needed by the Apache headers +#Patch1: papi-1.0-acinclude-m4-apache-apr1.patch.bz2 + + + +##### BUILD ROOT + +BuildRoot: %_tmppath/%name-%papiversion-%papirelease-root + + + +##### PACKAGE DESCRIPTIONS + +%package common +Summary: FSG OpenPrinting PAPI Common files and Documentation +Group: System/Servers +Obsoletes: papi-doc +Provides: papi-doc + +%package commands +Summary: FSG OpenPrinting PAPI BSD and System V printing commands +Group: System/Servers +Requires: /usr/sbin/update-alternatives +Conflicts: cups-common <= 1.2.0-2mdk + +%package utils +Summary: FSG OpenPrinting PAPI sample tools +Group: System/Servers +Obsoletes: papi-tools +Provides: papi-tools + +%if %{withruby} +%package -n ruby-papi +Summary: FSG OpenPrinting PAPI Ruby bindings +Group: System/Servers +Requires: ruby +Obsoletes: papi-ruby +Provides: papi-ruby + +%package -n ruby-papi-devel +Summary: FSG OpenPrinting PAPI Ruby bindings, development libraries +Group: Development/Other +Requires: ruby-papi +%endif + +%if %{withapache} +%package apache +Summary: FSG OpenPrinting PAPI IPP server Apache module +Group: System/Servers +Requires: apache-base +%endif + +%package -n %libpapi +Summary: FSG OpenPrinting PAPI libraries +Group: System/Servers +Requires: papi-common +Provides: libpapi.so.%{papimajor} +Obsoletes: papi-psm +Provides: papi-psm + +%package -n %libpapi-devel +Summary: Headers and links to compile against the "%{libpapi}" library +Group: Development/C +Requires: %{libpapi} = %{version} +Provides: libpapi-devel +Provides: papi-devel + + + +##### DESCRIPTION TEXTS + +%description +This package contains implentations of the Free Standards Group (FSG) +Open Printing API (PAPI) (v1.0) and client software that uses it. The +implemenations of the API are designed so that they can be used +individually to support client application interaction with a +particular type of print service or together to interact with a +variety of different print service types. + +%description common +This package contains common files like man pages, documentation, the +LPD privileged port access helper, etc. The documentation includesthe +FSG OpenPrinting PAPI specification and also information on how to use +and how to develop with this implementation of PAPI. It also contains +the source code of the papi-utils package as coding example. + +%description commands +Implementations of the BSD and SYSV printing commands layered on top +of the PAPI. The command implementation are intended to be reasonably +faithful to their counterparts on a Solaris system. They should be +reasonably faithful to pretty much any implementation of these +commands. This should allow them to be dropped on a system and used +in place of any prior version of the commands without causing layered +scripts and software to break. The commands covered are: + + BSD: lpr(1), lpq(1), lprm(1), lpc(8) + SYSV: lp(1), lpstat(1), cancel(1), accept(8), reject(8), + enable(8), disable(8) + +%description utils +Sample tools that makes use of the API to do marginally interesting +things. + +%if %{withruby} +%description -n ruby-papi +Ruby bindings for the PAPI libraries + +%description -n ruby-papi-devel +This package contains the .la files for the ruby bindings for +PAPI. It's likely nobody will ever need these. +%endif + +%if %{withapache} +%description apache +Apache module to make Apache working as IPP server +%endif + +%description -n %libpapi +This package contains libraries which provide PAPI implementation + +%description -n %libpapi-devel +This package contains the static library and the header files needed +to compile applications using the PAPI shared libraries. + + + +%prep + +# remove old directory +rm -rf $RPM_BUILD_DIR/papi + +##### PAPI + +%setup -q -n papi +#patch1 -p0 -b .apache-apr1 + +# Let other names be used for the libraries, to express that they work all +# directly as a libpapi and not only as plug-ins for libpapi-dynamic. +perl -p -i -e 's:psm([_\-])lpd:libpapi${1}lpd:' source/libpapi-lpd/Makefile.am +perl -p -i -e 's:psm([_\-])ipp:libpapi${1}ipp:' source/libpapi-ipp/Makefile.am +perl -p -i -e 's:\"/psm(-%s.so)\":\"/libpapi$1\":' source/libpapi-dynamic/psm.c +# Add lines to the source/libpapi-dynamic/Makefile.am so that libpapi.so is +# built twice, once with the name libpapi.so and second as +# libpapi-dynamic.so. We will include only libpapi-dynamic.so (and make a +# symbolic link named libpapi.so to the library we actually want to use). +# The libpapi.so which we build here only serves to satisfy the compilation +# process of the other parts of this package. After having run "make +# install" we delete it. +# There are three calls of Perl to modify the Makefile.am: The first joins +# continuation lines ('\' in the end of a line to continue the line in the +# next line), so that it is easier to manipilate and copy lines. The second +# copies all lines beginning with "libpapi_la" and replaces the "libpapi_la" +# in the copy by "libpapi_dynamic_la". The third Perl call adds +# "libpapi-dynamic.la" to the "lib_LTLIBRARIES" line. +cat source/libpapi-dynamic/Makefile.am | perl -e 'my $f = join("", <>); $f =~ s:\s*\\\n\s*: :sm; print $f' | perl -p -e 's:(^libpapi_la(.*)$):$1\nlibpapi_dynamic_la$2:' | perl -p -e 's:(libpapi\.la):$1 libpapi-dynamic.la:' > source/libpapi-dynamic/Makefile.am.new +mv -f source/libpapi-dynamic/Makefile.am.new source/libpapi-dynamic/Makefile.am +# Let library files have a version number +perl -p -i -e 's:\s*-avoid-version::' source/libpapi-lpd/Makefile.am source/libpapi-ipp/Makefile.am +# Move all libraries into libdir (no libraries in libexecdir any more) +perl -p -i -e 's:(libdir\s*=\s*\$\(libexecdir\)):\#$1:' source/libpapi-lpd/Makefile.am source/libpapi-ipp/Makefile.am +perl -p -i -e 's:libexecdir:libdir:g' source/libpapi-dynamic/Makefile.am +# Move lpd-port into /usr/bin +perl -p -i -e 's:libexecdir:bindir:' source/libpapi-lpd/Makefile.am +perl -p -i -e 's:libexec_(PROGRAMS):bin_$1:' source/libpapi-lpd/Makefile.am +perl -p -i -e 's:(SUID_LPD_PORT=\"\$\{)libexecdir(\}/lpd-port\"):$1bindir$2:' configure.in + +# Fix broken source/libpapi-*/mapfile.in +perl -e 'my $f = join("", <>); $f =~ s:(libpapi-common.so)\s*\n;:$1 ;:sm; print $f' source/libpapi-lpd/mapfile.in > source/libpapi-lpd/mapfile.in.new +mv -f source/libpapi-lpd/mapfile.in.new source/libpapi-lpd/mapfile.in +perl -e 'my $f = join("", <>); $f =~ s:(libpapi-common.so)\s*\n;:$1 ;:sm; print $f' source/libpapi-ipp/mapfile.in > source/libpapi-ipp/mapfile.in.new +mv -f source/libpapi-ipp/mapfile.in.new source/libpapi-ipp/mapfile.in + + + +%build + +# Change compiler flags for debugging when in debug mode +%if %debug +export DONT_STRIP=1 +export CFLAGS="`echo %optflags |sed -e 's/-O3/-g/' |sed -e 's/-O2/-g/'`" +export CXXFLAGS="`echo %optflags |sed -e 's/-O3/-g/' |sed -e 's/-O2/-g/'`" +export RPM_OPT_FLAGS="`echo %optflags |sed -e 's/-O3/-g/' |sed -e 's/-O2/-g/'`" +%endif + +##### PAPI + +# We have a Subversion version and also have heavily manipulated the +# Makefile.am files, so we must re-generate "configure" +./autogen.sh + +%if %{withapache} +WITH_APACHE=" --with-apache=%{_prefix}" +%else +WITH_APACHE=" --without-apache" +%endif +%if %{withruby} +WITH_RUBY="" +%else +WITH_RUBY=" --without-ruby" +%endif + +export LDFLAGS="$LDFLAGS -L$RPM_BUILD_DIR/papi/source/libpapi-dynamic/.libs" +export CFLAGS="$CFLAGS -DDEFAULT_PRINT_SERVICE=\\\"ipp\\\"" +%configure$WITH_APACHE$WITH_RUBY +make + + + +%install + +rm -rf %{buildroot} + +# Change compiler flapapi for debugging when in debug mode +%if %debug +export DONT_STRIP=1 +export CFLAGS="`echo %optflags |sed -e 's/-O3/-g/' |sed -e 's/-O2/-g/'`" +export CXXFLAGS="`echo %optflags |sed -e 's/-O3/-g/' |sed -e 's/-O2/-g/'`" +export RPM_OPT_FLAGS="`echo %optflags |sed -e 's/-O3/-g/' |sed -e 's/-O2/-g/'`" +%endif + +##### PAPI + +%makeinstall \ + ruby_sitearchdir=%{buildroot}`ls -d %{_prefix}/lib*/ruby/site_ruby/*/*-linux-gnu*` \ + ruby_sitelibdir=%{buildroot}`ls -d %{_prefix}/lib*/ruby/site_ruby/*` + +# entry for xinetd (disabled by default) +install -d %{buildroot}%{_sysconfdir}/xinetd.d +cat <<EOF >%{buildroot}%{_sysconfdir}/xinetd.d/papi-lpd +# default: off +# description: The cups-lpd mini daemon enable cups accepting jobs from a \ +# remote LPD client (for example a machine with an older distribution \ +# than Linux Mandrake 7.2 or with a commercial Unix). +service papi-lpd +{ + socket_type = stream + protocol = tcp + wait = no + user = lp + group = sys + server = %{_sbindir}/in.lpd + passenv = + env = + disable = yes +} +EOF + +# Prepare the commands conflicting with actual print spooling systems +# for the update-alternatives treatment +# Move also the admin man pages into chapter 8 +install -d %{buildroot}%{_mandir}/man8 +( cd %{buildroot}%{_bindir} + mv lpr lpr-papi + mv lpq lpq-papi + mv lprm lprm-papi + mv lp lp-papi + mv cancel cancel-papi + mv lpstat lpstat-papi +) +( cd %{buildroot}%{_sbindir} + mv accept accept-papi + mv disable disable-papi + mv enable enable-papi + mv lpc lpc-papi + mv lpmove lpmove-papi + mv reject reject-papi +) +( cd %{buildroot}%{_mandir}/man1 + mv ../man*/lpr.* lpr-papi.1 + mv ../man*/lpq.* lpq-papi.1 + mv ../man*/lprm.* lprm-papi.1 + mv ../man*/lp.* lp-papi.1 + mv ../man*/cancel.* cancel-papi.1 + mv ../man*/lpstat.* lpstat-papi.1 +) +( cd %{buildroot}%{_mandir}/man8 + mv ../man*/accept.* accept-papi.8 + mv ../man*/disable.* disable-papi.8 + mv ../man*/enable.* enable-papi.8 + mv ../man*/lpc.* lpc-papi.8 + mv ../man*/lpmove.* lpmove-papi.8 + mv ../man*/reject.* reject-papi.8 +) + +# Remove the /usr/lib/libpapi.* files, as at their place we use symlinks +# generated by update-alternatives. These symlinks point to the libpapi +# library we want to use for our actual printing system. +( cd %{buildroot}%{_libdir} + rm -f libpapi.* +) + +# Install documentation +install -d %{buildroot}%{_docdir}/%{name}-%{version} +mv %{buildroot}%{_datadir}/examples %{buildroot}/%{_docdir}/%{name}-%{version} +cp docs/*.pdf docs/README* %{buildroot}/%{_docdir}/%{name}-%{version} +cp README %{buildroot}/%{_docdir}/%{name}-%{version}/README.devel +cp *.txt ChangeLog INSTALL LICENSE TODO %{buildroot}/%{_docdir}/%{name}-%{version} + + + +##### PRE/POSTINSTALL SCRIPTS + +%post -n %{libpapi} +# Set up update-alternatives entries +libversion=`\ls %{_libdir}/libpapi-dynamic.so.* | egrep 'so\.%{papimajor}\.[0-9]+\.[0-9]+$' | perl -p -e 's:^.*\.so\.::'` +%{_sbindir}/update-alternatives --install %{_libdir}/libpapi.so libpapi.so %{_libdir}/libpapi-dynamic.so 10 --slave %{_libdir}/libpapi.so.%{papimajor} libpapi.so.%{papimajor} %{_libdir}/libpapi-dynamic.so.%{papimajor} --slave %{_libdir}/libpapi.so.$libversion libpapi.so.$libversion %{_libdir}/libpapi-dynamic.so.$libversion +%{_sbindir}/update-alternatives --install %{_libdir}/libpapi.so libpapi.so %{_libdir}/libpapi-ipp.so 30 --slave %{_libdir}/libpapi.so.%{papimajor} libpapi.so.%{papimajor} %{_libdir}/libpapi-ipp.so.%{papimajor} --slave %{_libdir}/libpapi.so.$libversion libpapi.so.$libversion %{_libdir}/libpapi-ipp.so.$libversion +%{_sbindir}/update-alternatives --install %{_libdir}/libpapi.so libpapi.so %{_libdir}/libpapi-lpd.so 20 --slave %{_libdir}/libpapi.so.%{papimajor} libpapi.so.%{papimajor} %{_libdir}/libpapi-lpd.so.%{papimajor} --slave %{_libdir}/libpapi.so.$libversion libpapi.so.$libversion %{_libdir}/libpapi-lpd.so.$libversion + +/sbin/ldconfig + + + +%post commands +# Set up update-alternatives entries +%{_sbindir}/update-alternatives --install %{_bindir}/lpr lpr %{_bindir}/lpr-papi 100 --slave %{_mandir}/man1/lpr.1.bz2 lpr.1.bz2 %{_mandir}/man1/lpr-papi.1.bz2 +%{_sbindir}/update-alternatives --install %{_bindir}/lpq lpq %{_bindir}/lpq-papi 100 --slave %{_mandir}/man1/lpq.1.bz2 lpq.1.bz2 %{_mandir}/man1/lpq-papi.1.bz2 +%{_sbindir}/update-alternatives --install %{_bindir}/lprm lprm %{_bindir}/lprm-papi 100 --slave %{_mandir}/man1/lprm.1.bz2 lprm.1.bz2 %{_mandir}/man1/lprm-papi.1.bz2 +%{_sbindir}/update-alternatives --install %{_bindir}/lp lp %{_bindir}/lp-papi 100 --slave %{_mandir}/man1/lp.1.bz2 lp.1.bz2 %{_mandir}/man1/lp-papi.1.bz2 +%{_sbindir}/update-alternatives --install %{_bindir}/cancel cancel %{_bindir}/cancel-papi 100 --slave %{_mandir}/man1/cancel.1.bz2 cancel.1.bz2 %{_mandir}/man1/cancel-papi.1.bz2 +%{_sbindir}/update-alternatives --install %{_bindir}/lpstat lpstat %{_bindir}/lpstat-papi 100 --slave %{_mandir}/man1/lpstat.1.bz2 lpstat.1.bz2 %{_mandir}/man1/lpstat-papi.1.bz2 +%{_sbindir}/update-alternatives --install %{_sbindir}/accept accept %{_sbindir}/accept-papi 100 --slave %{_mandir}/man8/accept.8.bz2 accept.8.bz2 %{_mandir}/man8/accept-papi.8.bz2 +%{_sbindir}/update-alternatives --install %{_sbindir}/disable disable %{_sbindir}/disable-papi 100 --slave %{_mandir}/man8/disable.8.bz2 disable.8.bz2 %{_mandir}/man8/disable-papi.8.bz2 +%{_sbindir}/update-alternatives --install %{_sbindir}/enable enable %{_sbindir}/enable-papi 100 --slave %{_mandir}/man8/enable.8.bz2 enable.8.bz2 %{_mandir}/man8/enable-papi.8.bz2 +%{_sbindir}/update-alternatives --install %{_sbindir}/lpc lpc %{_sbindir}/lpc-papi 100 --slave %{_mandir}/man8/lpc.8.bz2 lpc.8.bz2 %{_mandir}/man8/lpc-papi.8.bz2 +%{_sbindir}/update-alternatives --install %{_sbindir}/lpmove lpmove %{_sbindir}/lpmove-papi 100 --slave %{_mandir}/man8/lpmove.8.bz2 lpmove.8.bz2 %{_mandir}/man8/lpmove-papi.8.bz2 +%{_sbindir}/update-alternatives --install %{_sbindir}/reject reject %{_sbindir}/reject-papi 100 --slave %{_mandir}/man8/reject.8.bz2 reject.8.bz2 %{_mandir}/man8/reject-papi.8.bz2 + + + +%preun -n %{libpapi} +if [ "$1" = 0 ]; then + # Remove update-alternatives entries + %{_sbindir}/update-alternatives --remove libpapi.so %{_libdir}/libpapi-dynamic.so + %{_sbindir}/update-alternatives --remove libpapi.so %{_libdir}/libpapi-ipp.so + %{_sbindir}/update-alternatives --remove libpapi.so %{_libdir}/libpapi-lpd.so +fi + + + +%preun commands +if [ "$1" = 0 ]; then + # Remove update-alternatives entries + %{_sbindir}/update-alternatives --remove lpr %{_bindir}/lpr-papi + %{_sbindir}/update-alternatives --remove lpq %{_bindir}/lpq-papi + %{_sbindir}/update-alternatives --remove lprm %{_bindir}/lprm-papi + %{_sbindir}/update-alternatives --remove lp %{_bindir}/lp-papi + %{_sbindir}/update-alternatives --remove cancel %{_bindir}/cancel-papi + %{_sbindir}/update-alternatives --remove lpstat %{_bindir}/lpstat-papi + %{_sbindir}/update-alternatives --remove accept %{_sbindir}/accept-papi + %{_sbindir}/update-alternatives --remove disable %{_sbindir}/disable-papi + %{_sbindir}/update-alternatives --remove enable %{_sbindir}/enable-papi + %{_sbindir}/update-alternatives --remove lpc %{_sbindir}/lpc-papi + %{_sbindir}/update-alternatives --remove lpmove %{_sbindir}/lpmove-papi + %{_sbindir}/update-alternatives --remove reject %{_sbindir}/reject-papi +fi + + + +%postun -n %{libpapi} -p /sbin/ldconfig + + + +%clean +rm -rf %{buildroot} + + + +##### FILES + +%files common +%defattr(-,root,root) +# This must be SUID root to access LPD port 515 +%attr(4755,root,root) %{_bindir}/lpd-port +%{_mandir}/man*/psm-* +%{_mandir}/man4/* +%{_docdir}/%{name}-%{version} + +%files commands +%defattr(-,root,root) +%{_bindir}/*papi +%{_sbindir}/*papi +%{_sbindir}/in.lpd +%{_mandir}/man*/*-papi.[0-9n]* +%attr(644,root,root) %config(noreplace) %{_sysconfdir}/xinetd.d/papi-lpd + +%files utils +%defattr(-,root,root) +%{_bindir}/add-modify-printer +%{_bindir}/ipp +%{_bindir}/print-test +%{_bindir}/printer-query +%{_bindir}/printers-list +%{_bindir}/remove-printer + +%if %{withruby} +%files -n ruby-papi +%defattr(-,root,root) +%{_prefix}/lib*/ruby/site_ruby/*/*.rb +%{_prefix}/lib*/ruby/site_ruby/*/*/*.so.* + +%files -n ruby-papi-devel +%defattr(-,root,root) +%{_prefix}/lib*/ruby/site_ruby/*/*/*.so +%{_prefix}/lib*/ruby/site_ruby/*/*/*.*a +%endif + +%if %{withapache} +%files apache +%defattr(-,root,root) + +%endif + +%files -n %{libpapi} +%defattr(-,root,root) +%{_libdir}/lib*.so.* +%{_libdir}/lib*.so + +%files -n %{libpapi}-devel +%defattr(-,root,root) +%{_libdir}/lib*.la +%{_libdir}/pkgconfig/* +%{_includedir}/papi + + + +%changelog +* Mon Jun 12 2006 Till Kamppeter <ti...@ma...> 1.0-0.171.2mdv2007.0 +- Added "Obsoletes: papi-ruby" to the ruby-papi package. + +* Sat May 20 2006 Till Kamppeter <ti...@ma...> 1.0-0.171.1mdk +- Updated to state of subversion revision 171. +- Renamed print service modules to comply with library policy + and to express there stand-alone usability without libpapi-dynamic, + moved the libraries into the libpapi package. +- Replaced papi-psm and papi-doc packages by papi-common, and papi-tools + by papi-utils. +- Made PAPI library selection possible with update-alternatives. +- Removed patch 1 (merged upstream). + +* Thu May 18 2006 Till Kamppeter <ti...@ma...> 1.0-0.164.2mdk +- Fixed Ruby bindings package. + +* Tue May 16 2006 Till Kamppeter <ti...@ma...> 1.0-0.164.1mdk +- Initial Mandriva release. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kt...@us...> - 2006-05-25 07:56:24
|
Revision: 176 Author: ktou Date: 2006-05-25 00:56:17 -0700 (Thu, 25 May 2006) ViewCVS: http://svn.sourceforge.net/openprinting/?rev=176&view=rev Log Message: ----------- * source/ruby/rb-papi-printer.c: implemented non-standard API. (papiPrinterGet* and papiPrinterIs*). * source/ruby/rb-papi-job.c: implemented non-standard API. (papiJobGet* and papiJobIs*). * source/ruby/test-papi.rb: added tests for PAPI::PrinterState. Modified Paths: -------------- trunk/papi/ChangeLog trunk/papi/source/ruby/rb-papi-job.c trunk/papi/source/ruby/rb-papi-printer.c trunk/papi/source/ruby/test-papi.rb Modified: trunk/papi/ChangeLog =================================================================== --- trunk/papi/ChangeLog 2006-05-25 07:51:09 UTC (rev 175) +++ trunk/papi/ChangeLog 2006-05-25 07:56:17 UTC (rev 176) @@ -1,3 +1,17 @@ +2006-05-25 Kouhei Sutou <ko...@co...> + + * source/ruby/rb-papi-printer.c: implemented non-standard + API. (papiPrinterGet* and papiPrinterIs*). + + * source/ruby/rb-papi-job.c: implemented non-standard + API. (papiJobGet* and papiJobIs*). + + * source/ruby/test-papi.rb: added tests for PAPI::PrinterState. + + * source/libpapi-ipp/mapfile.in: fixed typo. + + * source/libpapi-lpd/mapfile.in: fixed typo. + 2006-05-24 Norm Jacobs <Norm.Jacobs@Sun.COM> * source/libpapi-dynamic/service.c: Modified: trunk/papi/source/ruby/rb-papi-job.c =================================================================== --- trunk/papi/source/ruby/rb-papi-job.c 2006-05-25 07:51:09 UTC (rev 175) +++ trunk/papi/source/ruby/rb-papi-job.c 2006-05-25 07:56:17 UTC (rev 176) @@ -330,6 +330,56 @@ } +/* non-standard API */ +static VALUE +rb_papi_job_get_name(VALUE self) +{ + char *name; + rb_papi_status_check(papiJobGetName(RVAL2JOB(self), &name)); + return rb_str_new2(name); +} + +static VALUE +rb_papi_job_get_owner(VALUE self) +{ + char *owner; + rb_papi_status_check(papiJobGetOwner(RVAL2JOB(self), &owner)); + return rb_str_new2(owner); +} + +static VALUE +rb_papi_job_get_size_in_kilobytes(VALUE self) +{ + int size; + rb_papi_status_check(papiJobGetSizeInKilobytes(RVAL2JOB(self), &size)); + return INT2NUM(size); +} + +static VALUE +rb_papi_job_get_state(VALUE self) +{ + int state; + rb_papi_status_check(papiJobGetState(RVAL2JOB(self), &state)); + return INT2NUM(state); +} + +static VALUE +rb_papi_job_get_state_reasons(VALUE self) +{ + char *reasons; + rb_papi_status_check(papiJobGetStateReasons(RVAL2JOB(self), &reasons)); + return rb_str_new2(reasons); +} + +static VALUE +rb_papi_job_get_state_message(VALUE self) +{ + char *message; + rb_papi_status_check(papiJobGetStateMessage(RVAL2JOB(self), &message)); + return rb_str_new2(message); +} + + /* JobStream related */ static VALUE rb_papi_job_stream_callback(VALUE info) @@ -454,6 +504,15 @@ rb_define_method(cJob, "restart", rb_papi_job_restart, 0); rb_define_method(cJob, "promote", rb_papi_job_promote, 0); + /* non-standard API */ + rb_define_method(cJob, "name", rb_papi_job_get_name, 0); + rb_define_method(cJob, "owner", rb_papi_job_get_owner, 0); + rb_define_method(cJob, "size_in_kilobytes", + rb_papi_job_get_size_in_kilobytes, 0); + rb_define_method(cJob, "state", rb_papi_job_get_state, 0); + rb_define_method(cJob, "state_reasons", rb_papi_job_get_state_reasons, 0); + rb_define_method(cJob, "state_message", rb_papi_job_get_state_message, 0); + /* Job accessors */ rb_define_method(cJob, "attributes", rb_papi_job_get_attribute_list, 0); rb_define_method(cJob, "printer_name", rb_papi_job_get_printer_name, 0); Modified: trunk/papi/source/ruby/rb-papi-printer.c =================================================================== --- trunk/papi/source/ruby/rb-papi-printer.c 2006-05-25 07:51:09 UTC (rev 175) +++ trunk/papi/source/ruby/rb-papi-printer.c 2006-05-25 07:56:17 UTC (rev 176) @@ -208,10 +208,73 @@ } + +/* no-standard API */ +static VALUE +rb_papi_printer_get_name(VALUE self) +{ + char *name; + rb_papi_status_check(papiPrinterGetName(RVAL2PRINTER(self), &name)); + return rb_str_new2(name); +} + +static VALUE +rb_papi_printer_get_uri(VALUE self) +{ + char *uri; + rb_papi_status_check(papiPrinterGetURI(RVAL2PRINTER(self), &uri)); + return rb_str_new2(uri); +} + +static VALUE +rb_papi_printer_get_state(VALUE self) +{ + int state; + rb_papi_status_check(papiPrinterGetState(RVAL2PRINTER(self), &state)); + return INT2NUM(state); +} + +static VALUE +rb_papi_printer_get_state_reasons(VALUE self) +{ + char *reasons; + rb_papi_status_check(papiPrinterGetStateReasons(RVAL2PRINTER(self), + &reasons)); + return rb_str_new2(reasons); +} + +static VALUE +rb_papi_printer_get_state_message(VALUE self) +{ + char *message; + rb_papi_status_check(papiPrinterGetStateMessage(RVAL2PRINTER(self), + &message)); + return rb_str_new2(message); +} + +static VALUE +rb_papi_printer_is_accepting_jobs(VALUE self) +{ + char boolean; + rb_papi_status_check(papiPrinterIsAcceptingJobs(RVAL2PRINTER(self), + &boolean)); + return boolean ? Qtrue : Qfalse; +} + +static VALUE +rb_papi_printer_is_enabled(VALUE self) +{ + char boolean; + rb_papi_status_check(papiPrinterIsEnabled(RVAL2PRINTER(self), &boolean)); + return boolean ? Qtrue : Qfalse; +} + + + void Init_rb_papi_printer(VALUE mPAPI) { - VALUE cService; + VALUE cService, mPrinterState; cService = rb_const_get(mPAPI, rb_intern("Service")); cPrinter = rb_define_class_under(mPAPI, "Printer", rb_cData); @@ -230,4 +293,22 @@ rb_define_method(cService, "printer_jobs", rb_papi_printer_list_jobs, -1); rb_define_method(cPrinter, "attributes", rb_papi_printer_attribute_list, 0); + + /* non-standard API */ + mPrinterState = rb_define_module_under(mPAPI, "PrinterState"); + rb_define_const(mPrinterState, "IDLE", INT2NUM(PAPI_PRINTER_IDLE)); + rb_define_const(mPrinterState, "PROCESSING", + INT2NUM(PAPI_PRINTER_PROCESSING)); + rb_define_const(mPrinterState, "STOPPED", INT2NUM(PAPI_PRINTER_STOPPED)); + + rb_define_method(cPrinter, "name", rb_papi_printer_get_name, 0); + rb_define_method(cPrinter, "uri", rb_papi_printer_get_uri, 0); + rb_define_method(cPrinter, "state", rb_papi_printer_get_state, 0); + rb_define_method(cPrinter, "state_reasons", + rb_papi_printer_get_state_reasons, 0); + rb_define_method(cPrinter, "state_message", + rb_papi_printer_get_state_message, 0); + rb_define_method(cPrinter, "accepting_jobs?", + rb_papi_printer_is_accepting_jobs, 0); + rb_define_method(cPrinter, "enabled?", rb_papi_printer_is_enabled, 0); } Modified: trunk/papi/source/ruby/test-papi.rb =================================================================== --- trunk/papi/source/ruby/test-papi.rb 2006-05-25 07:51:09 UTC (rev 175) +++ trunk/papi/source/ruby/test-papi.rb 2006-05-25 07:56:17 UTC (rev 176) @@ -117,6 +117,12 @@ assert_equal(0xfffc, PAPI::FilterBitmask::OPTIONS) end + def test_printer_status + assert_equal(0x03, PAPI::PrinterState::IDLE) + assert_equal(0x04, PAPI::PrinterState::PROCESSING) + assert_equal(0x05, PAPI::PrinterState::STOPPED) + end + def test_service service = PAPI::Service.new("ipp://localhost/") service.attributes.each do |attr| This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kt...@us...> - 2006-05-25 07:51:12
|
Revision: 175 Author: ktou Date: 2006-05-25 00:51:09 -0700 (Thu, 25 May 2006) ViewCVS: http://svn.sourceforge.net/openprinting/?rev=175&view=rev Log Message: ----------- * source/libpapi-ipp/mapfile.in: fixed typo. Modified Paths: -------------- trunk/papi/source/libpapi-ipp/mapfile.in Modified: trunk/papi/source/libpapi-ipp/mapfile.in =================================================================== --- trunk/papi/source/libpapi-ipp/mapfile.in 2006-05-25 07:45:29 UTC (rev 174) +++ trunk/papi/source/libpapi-ipp/mapfile.in 2006-05-25 07:51:09 UTC (rev 175) @@ -134,8 +134,7 @@ papiPrinterGetStateReasons @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; papiPrinterGetStateMessage @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; papiPrinterIsEnabled @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; - papiPrinterIsAccepting @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so -; + papiPrinterIsAccepting @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; papiJobGetName @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; papiJobGetOwner @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; papiJobGetSizeInKilobytes @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kt...@us...> - 2006-05-25 07:45:36
|
Revision: 174 Author: ktou Date: 2006-05-25 00:45:29 -0700 (Thu, 25 May 2006) ViewCVS: http://svn.sourceforge.net/openprinting/?rev=174&view=rev Log Message: ----------- * source/libpapi-lpd/mapfile.in: fixed typo. Modified Paths: -------------- trunk/papi/source/libpapi-lpd/mapfile.in Modified: trunk/papi/source/libpapi-lpd/mapfile.in =================================================================== --- trunk/papi/source/libpapi-lpd/mapfile.in 2006-05-25 04:52:06 UTC (rev 173) +++ trunk/papi/source/libpapi-lpd/mapfile.in 2006-05-25 07:45:29 UTC (rev 174) @@ -134,8 +134,7 @@ papiPrinterGetStateReasons @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; papiPrinterGetStateMessage @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; papiPrinterIsEnabled @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; - papiPrinterIsAccepting @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so -; + papiPrinterIsAccepting @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; papiJobGetName @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; papiJobGetOwner @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; papiJobGetSizeInKilobytes @MAP_FILTER@ = FUNCTION FILTER libpapi-common.so ; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nj...@us...> - 2006-05-25 04:52:12
|
Revision: 173 Author: njacobs Date: 2006-05-24 21:52:06 -0700 (Wed, 24 May 2006) ViewCVS: http://svn.sourceforge.net/openprinting/?rev=173&view=rev Log Message: ----------- more closely align with Solaris lpstat -p output Modified Paths: -------------- trunk/papi/ChangeLog trunk/papi/source/bsd-sysv-commands/lpstat.c Modified: trunk/papi/ChangeLog =================================================================== --- trunk/papi/ChangeLog 2006-05-24 20:54:00 UTC (rev 172) +++ trunk/papi/ChangeLog 2006-05-25 04:52:06 UTC (rev 173) @@ -4,6 +4,9 @@ fixed papiServiceGetAttributeList() to query the "default" service if it's not bound to one already. + * source/bsd-sysv-commands/lpstat.c: + more closely align with Solaris lpstat -p output + 2006-05-19 Norm Jacobs <Norm.Jacobs@Sun.COM> * source/libpapi-dynamic/nss.c: Modified: trunk/papi/source/bsd-sysv-commands/lpstat.c =================================================================== --- trunk/papi/source/bsd-sysv-commands/lpstat.c 2006-05-24 20:54:00 UTC (rev 172) +++ trunk/papi/source/bsd-sysv-commands/lpstat.c 2006-05-25 04:52:06 UTC (rev 173) @@ -405,6 +405,14 @@ "lpsched-interface-script", &str); printf(gettext("\tInterface: %s\n"), str); + str = ""; + (void) papiAttributeListGetString(attrs, NULL, + "ppd-file-uri", &str); + (void) papiAttributeListGetString(attrs, NULL, + "lpsched-ppd-source-path", &str); + if (str != NULL) + printf(gettext("\tPPD: %s\n"), str); + str = NULL; (void) papiAttributeListGetString(attrs, NULL, "lpsched-fault-alert-command", &str); @@ -417,27 +425,31 @@ printf(gettext("\tAfter fault: %s\n"), ((str[0] == '\0') ? gettext("continue") : str)); - str = ""; + str = "(all)"; iter = NULL; - printf(gettext("\tUsers allowed:\n")); - for (status = papiAttributeListGetString(attrs, &iter, + (void) papiAttributeListGetString(attrs, &iter, "requesting-user-name-allowed", &str); - status == PAPI_OK; - status = papiAttributeListGetString(attrs, &iter, NULL, - &str)) + printf(gettext("\tUsers allowed:\n\t\t%s\n"), + ((str[0] == '\0') ? gettext("(none)") : str)); + if ((str != NULL) && (str[0] != '\0')) + while (papiAttributeListGetString(attrs, &iter, NULL, + &str) == PAPI_OK) printf("\t\t%s\n", str); - str = ""; + str = NULL; iter = NULL; - printf(gettext("\tUsers denied:\n")); - for (status = papiAttributeListGetString(attrs, &iter, + (void) papiAttributeListGetString(attrs, &iter, "requesting-user-name-denied", &str); - status == PAPI_OK; - status = papiAttributeListGetString(attrs, &iter, NULL, - &str)) - printf("\t\t%s\n", str); + if (str != NULL) { + printf(gettext("\tUsers denied:\n\t\t%s\n"), + ((str[0] == '\0') ? gettext("(none)") : str)); + if ((str != NULL) && (str[0] != '\0')) + while (papiAttributeListGetString(attrs, &iter, + NULL, &str) == PAPI_OK) + printf("\t\t%s\n", str); + } - str = ""; + str = "(none)"; iter = NULL; (void) papiAttributeListGetString(attrs, &iter, "form-supported", &str); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nj...@us...> - 2006-05-24 20:54:17
|
Revision: 172 Author: njacobs Date: 2006-05-24 13:54:00 -0700 (Wed, 24 May 2006) ViewCVS: http://svn.sourceforge.net/openprinting/?rev=172&view=rev Log Message: ----------- fixed papiServiceGetAttributeList() to query the "default" service if it's not bound to one already. Modified Paths: -------------- trunk/papi/ChangeLog trunk/papi/source/libpapi-dynamic/service.c Modified: trunk/papi/ChangeLog =================================================================== --- trunk/papi/ChangeLog 2006-05-20 06:00:32 UTC (rev 171) +++ trunk/papi/ChangeLog 2006-05-24 20:54:00 UTC (rev 172) @@ -1,3 +1,9 @@ +2006-05-24 Norm Jacobs <Norm.Jacobs@Sun.COM> + + * source/libpapi-dynamic/service.c: + fixed papiServiceGetAttributeList() to query the "default" + service if it's not bound to one already. + 2006-05-19 Norm Jacobs <Norm.Jacobs@Sun.COM> * source/libpapi-dynamic/nss.c: Modified: trunk/papi/source/libpapi-dynamic/service.c =================================================================== --- trunk/papi/source/libpapi-dynamic/service.c 2006-05-20 06:00:32 UTC (rev 171) +++ trunk/papi/source/libpapi-dynamic/service.c 2006-05-24 20:54:00 UTC (rev 172) @@ -51,20 +51,40 @@ } static char * +default_service_uri(char *fallback) +{ + char *result = NULL; + + if ((result = getenv("PAPI_SERVICE_URI")) == NULL) { + char *cups; + + if ((cups = getenv("CUPS_SERVER")) != NULL) { + char buf[BUFSIZ]; + + snprintf(buf, sizeof (buf), "ipp://%s/printers/", cups); + result = strdup(buf); + } + } + + if (result == NULL) + result = fallback; + + return (result); +} + + + +static char * default_print_service() { static char *result = NULL; if (result == NULL) { - char *service_uri = getenv("PAPI_SERVICE_URI"); + char *service_uri = default_service_uri(DEFAULT_SERVICE_URI); uri_t *uri = NULL; if (uri_from_string(service_uri, &uri) != -1) result = strdup(uri->scheme); - else if (getenv("CUPS_SERVER") != NULL) - result = "ipp"; - else if (uri_from_string(DEFAULT_SERVICE_URI, &uri) != -1) - result = strdup(uri->scheme); if (uri != NULL) uri_free(uri); @@ -219,18 +239,9 @@ svc->app_data = app_data; /* If not specified, get a "default" service from the environment */ - if ((service_name == NULL) && - ((service_name = getenv("PAPI_SERVICE_URI")) == NULL)) { - char *cups; + if (service_name == NULL) + service_name = default_service_uri(NULL); - if ((cups = getenv("CUPS_SERVER")) != NULL) { - char buf[BUFSIZ]; - - snprintf(buf, sizeof (buf), "ipp://%s/printers/", cups); - service_name = strdup(buf); - } - } - if (service_name != NULL) { result = service_load(svc, service_name); /* if the psm loaded and the svc contains a URI, connect */ @@ -488,6 +499,13 @@ if (handle != NULL) { papi_attribute_t **(*f)(); + if (svc->so_handle == NULL) { + char *uri = default_service_uri(DEFAULT_SERVICE_URI); + + if (service_connect(svc, uri) != PAPI_OK) + return (NULL); + } + f = (papi_attribute_t **(*)())psm_sym(svc, "papiServiceGetAttributeList"); if (f != NULL) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |