summaryrefslogtreecommitdiff
path: root/usr/src/cmd/lp/lib/papi
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src/cmd/lp/lib/papi')
-rw-r--r--usr/src/cmd/lp/lib/papi/Makefile13
-rw-r--r--usr/src/cmd/lp/lib/papi/attribute.c1113
-rw-r--r--usr/src/cmd/lp/lib/papi/job.c256
-rw-r--r--usr/src/cmd/lp/lib/papi/library.c98
-rw-r--r--usr/src/cmd/lp/lib/papi/list.c158
-rw-r--r--usr/src/cmd/lp/lib/papi/lpsched-jobs.c254
-rw-r--r--usr/src/cmd/lp/lib/papi/lpsched-misc.c51
-rw-r--r--usr/src/cmd/lp/lib/papi/lpsched-msgs.c288
-rw-r--r--usr/src/cmd/lp/lib/papi/lpsched-printers.c237
-rw-r--r--usr/src/cmd/lp/lib/papi/lpsched-service.c13
-rw-r--r--usr/src/cmd/lp/lib/papi/mapfile151
-rw-r--r--usr/src/cmd/lp/lib/papi/mapfile-vers125
-rw-r--r--usr/src/cmd/lp/lib/papi/papi.h411
-rw-r--r--usr/src/cmd/lp/lib/papi/papi_impl.h40
-rw-r--r--usr/src/cmd/lp/lib/papi/ppd.c164
-rw-r--r--usr/src/cmd/lp/lib/papi/printer.c171
-rw-r--r--usr/src/cmd/lp/lib/papi/service.c34
-rw-r--r--usr/src/cmd/lp/lib/papi/status.c133
18 files changed, 1330 insertions, 2380 deletions
diff --git a/usr/src/cmd/lp/lib/papi/Makefile b/usr/src/cmd/lp/lib/papi/Makefile
index 72c7ff60a5..2f3d18a668 100644
--- a/usr/src/cmd/lp/lib/papi/Makefile
+++ b/usr/src/cmd/lp/lib/papi/Makefile
@@ -17,8 +17,6 @@
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
-
-
#
#
# Copyright 2006 Sun Microsystems, Inc. All rights reserved.
@@ -34,8 +32,8 @@ VERS=.1
LPSCHED_OBJS = lpsched-msgs.o lpsched-service.o lpsched-printers.o \
lpsched-jobs.o lpsched-misc.o
-OBJECTS = $(LPSCHED_OBJS) \
- list.o attribute.o status.o service.o printer.o job.o
+OBJECTS = $(LPSCHED_OBJS) service.o printer.o job.o ppd.o library.o
+
include ../../../../lib/Makefile.lib
include ../../Makefile.lp
@@ -44,7 +42,7 @@ ROOTLIBDIR= $(ROOT)/usr/lib/print
CPPFLAGS = -I.
CPPFLAGS += -I$(LPINC)
-CPPFLAGS += -I$(SRC)/lib
+CPPFLAGS += -I$(SRC)/lib/print/libpapi-common/common
CPPFLAGS += -D_REENTRANT
CPPFLAGS += $(ENVCPPFLAGS1)
CPPFLAGS += $(ENVCPPFLAGS2)
@@ -55,11 +53,12 @@ LDLIBS += -L$(SRC)/cmd/lp/lib/class -llpcls
LDLIBS += -L$(SRC)/cmd/lp/lib/requests -llpreq
LDLIBS += -L$(SRC)/cmd/lp/lib/secure -llpsec
LDLIBS += -L$(SRC)/cmd/lp/lib/forms -llpfrm
+LDLIBS += -L$(SRC)/cmd/lp/lib/access -llpacc
LDLIBS += -L$(SRC)/cmd/lp/lib/lp -llp
-MAPFILES= mapfile-vers
+MAPFILES= mapfile
MAPOPTS= $(MAPFILES:%=-M%)
-DYNFLAGS += $(MAPOPTS)
+DYNFLAGS += $(BDIRECT) $(MAPOPTS)
LIBS = $(DYNLIB)
diff --git a/usr/src/cmd/lp/lib/papi/attribute.c b/usr/src/cmd/lp/lib/papi/attribute.c
deleted file mode 100644
index 02f5db2fc4..0000000000
--- a/usr/src/cmd/lp/lib/papi/attribute.c
+++ /dev/null
@@ -1,1113 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (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 2004 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-
-#pragma ident "%Z%%M% %I% %E% SMI"
-
-/*LINTLIBRARY*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <papi_impl.h>
-
-static void papiAttributeFree(papi_attribute_t *attribute);
-
-static void
-papiAttributeValueFree(papi_attribute_value_type_t type,
- papi_attribute_value_t *value)
-{
- if (value != NULL) {
- switch (type) {
- case PAPI_STRING:
- if (value->string != NULL)
- free(value->string);
- break;
- case PAPI_COLLECTION:
- if (value->collection != NULL) {
- int i;
-
- for (i = 0; value->collection[i] != NULL; i++)
- papiAttributeFree(value->collection[i]);
-
- free(value->collection);
- }
- break;
- default: /* don't need to free anything extra */
- break;
- }
-
- free(value);
- }
-}
-
-static void
-papiAttributeValuesFree(papi_attribute_value_type_t type,
- papi_attribute_value_t **values)
-{
- if (values != NULL) {
- int i;
-
- for (i = 0; values[i] != NULL; i++)
- papiAttributeValueFree(type, values[i]);
-
- free(values);
- }
-}
-
-static void
-papiAttributeFree(papi_attribute_t *attribute)
-{
- if (attribute != NULL) {
- if (attribute->name != NULL)
- free(attribute->name);
- if (attribute->values != NULL)
- papiAttributeValuesFree(attribute->type,
- attribute->values);
- free(attribute);
- }
-}
-
-void
-papiAttributeListFree(papi_attribute_t **list)
-{
- if (list != NULL) {
- int i;
-
- for (i = 0; list[i] != NULL; i++)
- papiAttributeFree(list[i]);
-
- free(list);
- }
-}
-
-static papi_attribute_t **
-collection_dup(papi_attribute_t **collection)
-{
- papi_attribute_t **result = NULL;
-
- /* allows a NULL collection that is "empty" or "no value" */
- if (collection != NULL) {
- int i;
-
- for (i = 0; collection[i] != NULL; i++) {
- papi_attribute_t *a = collection[i];
-
- papiAttributeListAdd(&result, PAPI_ATTR_APPEND, a->name,
- a->type, NULL);
- if (a->values != NULL) {
- int j;
-
- for (j = 0; a->values[j] != NULL; j++)
- papiAttributeListAdd(&result,
- PAPI_ATTR_APPEND,
- a->name, a->type,
- a->values[j]);
- }
- }
- }
-
- return (result);
-}
-
-static papi_attribute_value_t *
-papiAttributeValueDup(const papi_attribute_value_type_t type,
- const papi_attribute_value_t *v)
-{
- papi_attribute_value_t *result = NULL;
-
- if ((v != NULL) && ((result = calloc(1, sizeof (*result))) != NULL)) {
- switch (type) {
- case PAPI_STRING:
- if (v->string == NULL) {
- free(result);
- result = NULL;
- } else
- result->string = strdup(v->string);
- break;
- case PAPI_INTEGER:
- result->integer = v->integer;
- break;
- case PAPI_BOOLEAN:
- result->boolean = v->boolean;
- break;
- case PAPI_RANGE:
- result->range.lower = v->range.lower;
- result->range.upper = v->range.upper;
- break;
- case PAPI_RESOLUTION:
- result->resolution.xres = v->resolution.xres;
- result->resolution.yres = v->resolution.yres;
- result->resolution.units = v->resolution.units;
- break;
- case PAPI_DATETIME:
- result->datetime = v->datetime;
- break;
- case PAPI_COLLECTION:
- result->collection = collection_dup(v->collection);
- break;
- default: /* unknown type, fail to duplicate */
- free(result);
- result = NULL;
- }
- }
-
- return (result);
-}
-
-static papi_attribute_t *
-papiAttributeAlloc(const char *name, papi_attribute_value_type_t type)
-{
- papi_attribute_t *result = NULL;
-
- if ((result = calloc(1, sizeof (*result))) != NULL) {
- result->name = strdup(name);
- result->type = type;
- }
-
- return (result);
-}
-
-static papi_status_t
-papiAttributeListAddValue(papi_attribute_value_t ***values,
- const papi_attribute_value_type_t type,
- const papi_attribute_value_t *value)
-{
-
- if (values == NULL)
- return (PAPI_BAD_ARGUMENT);
-
- if (value != NULL) { /* this allows "empty" attributes */
- papi_attribute_value_t *tmp = NULL;
-
- if ((tmp = papiAttributeValueDup(type, value)) == NULL)
- return (PAPI_TEMPORARY_ERROR);
-
- list_append(values, tmp);
- }
-
- return (PAPI_OK);
-}
-
-papi_status_t
-papiAttributeListAdd(papi_attribute_t ***list, const int flgs,
- const char *name, const papi_attribute_value_type_t type,
- const papi_attribute_value_t *value)
-{
- papi_status_t result;
- int flags = flgs;
- papi_attribute_t *attribute = NULL;
- papi_attribute_value_t **values = NULL;
-
- if ((list == NULL) || (name == NULL))
- return (PAPI_BAD_ARGUMENT);
-
- if ((type == PAPI_RANGE) && (value != NULL) &&
- (value->range.lower > value->range.upper))
- return (PAPI_BAD_ARGUMENT); /* RANGE must have min <= max */
-
- if (flags == 0) /* if it wasn't set, set a default behaviour */
- flags = PAPI_ATTR_APPEND;
-
- /* look for an existing one */
- attribute = papiAttributeListFind(*list, name);
-
- if (((flags & PAPI_ATTR_EXCL) != 0) && (attribute != NULL))
- return (PAPI_CONFLICT); /* EXISTS */
-
- if (((flags & PAPI_ATTR_REPLACE) == 0) && (attribute != NULL) &&
- (attribute->type != type))
- return (PAPI_CONFLICT); /* TYPE CONFLICT */
-
- /* if we don't have one, create it and add it to the list */
- if ((attribute == NULL) &&
- ((attribute = papiAttributeAlloc(name, type)) != NULL))
- list_append(list, attribute);
-
- /* if we don't have one by now, it's most likely an alloc fail */
- if (attribute == NULL)
- return (PAPI_TEMPORARY_ERROR);
-
- /*
- * if we are replacing, clear any existing values, but don't free
- * until after we have replaced the values, in case we are replacing
- * a collection with a relocated version of the original collection.
- */
- if (((flags & PAPI_ATTR_REPLACE) != 0) && (attribute->values != NULL)) {
- values = attribute->values;
- attribute->values = NULL;
- }
-
- attribute->type = type;
-
- result = papiAttributeListAddValue(&attribute->values, type, value);
-
- /* free old values if we replaced them */
- if (values != NULL)
- papiAttributeValuesFree(type, values);
-
- return (result);
-}
-
-papi_status_t
-papiAttributeListAddString(papi_attribute_t ***list, const int flags,
- const char *name, const char *string)
-{
- papi_attribute_value_t v;
-
- v.string = (char *)string;
- return (papiAttributeListAdd(list, flags, name, PAPI_STRING, &v));
-}
-
-papi_status_t
-papiAttributeListAddInteger(papi_attribute_t ***list, const int flags,
- const char *name, const int integer)
-{
- papi_attribute_value_t v;
-
- v.integer = integer;
- return (papiAttributeListAdd(list, flags, name, PAPI_INTEGER, &v));
-}
-
-papi_status_t
-papiAttributeListAddBoolean(papi_attribute_t ***list, const int flags,
- const char *name, const char boolean)
-{
- papi_attribute_value_t v;
-
- v.boolean = boolean;
- return (papiAttributeListAdd(list, flags, name, PAPI_BOOLEAN, &v));
-}
-
-papi_status_t
-papiAttributeListAddRange(papi_attribute_t ***list, const int flags,
- const char *name, const int lower, const int upper)
-{
- papi_attribute_value_t v;
-
- v.range.lower = lower;
- v.range.upper = upper;
- return (papiAttributeListAdd(list, flags, name, PAPI_RANGE, &v));
-}
-
-papi_status_t
-papiAttributeListAddResolution(papi_attribute_t ***list, const int flags,
- const char *name, const int xres, const int yres,
- const papi_resolution_unit_t units)
-{
- papi_attribute_value_t v;
-
- v.resolution.xres = xres;
- v.resolution.yres = yres;
- v.resolution.units = units;
- return (papiAttributeListAdd(list, flags, name, PAPI_RESOLUTION, &v));
-}
-
-papi_status_t
-papiAttributeListAddDatetime(papi_attribute_t ***list, const int flags,
- const char *name, const time_t datetime)
-{
- papi_attribute_value_t v;
-
- v.datetime = datetime;
- return (papiAttributeListAdd(list, flags, name, PAPI_DATETIME, &v));
-}
-
-papi_status_t
-papiAttributeListAddCollection(papi_attribute_t ***list, const int flags,
- const char *name, const papi_attribute_t **collection)
-{
- papi_attribute_value_t v;
-
- v.collection = (papi_attribute_t **)collection;
- return (papiAttributeListAdd(list, flags, name, PAPI_COLLECTION, &v));
-}
-
-papi_status_t
-papiAttributeListDelete(papi_attribute_t ***list, const char *name)
-{
- papi_attribute_t *attribute;
-
- if ((list == NULL) || (name == NULL))
- return (PAPI_BAD_ARGUMENT);
-
- if ((attribute = papiAttributeListFind(*list, name)) == NULL)
- return (PAPI_NOT_FOUND);
-
- list_remove(*list, attribute);
- papiAttributeFree(attribute);
-
- return (PAPI_OK);
-}
-
-papi_attribute_t *
-papiAttributeListFind(papi_attribute_t **list, const char *name)
-{
- if (list != NULL) {
- int i;
-
- for (i = 0; list[i] != NULL; i++)
- if (strcasecmp(list[i]->name, name) == 0)
- return ((papi_attribute_t *)list[i]);
- }
-
- return (NULL);
-}
-
-papi_attribute_t *
-papiAttributeListGetNext(papi_attribute_t **list, void **iter)
-{
- papi_attribute_t **tmp, *result;
-
- if ((list == NULL) && (iter == NULL))
- return (NULL);
-
- if (*iter == NULL)
- *iter = list;
-
- tmp = *iter;
- result = *tmp;
- *iter = ++tmp;
-
- return (result);
-}
-
-papi_status_t
-papiAttributeListGetValue(papi_attribute_t **list, void **iter,
- const char *name, papi_attribute_value_type_t type,
- papi_attribute_value_t **value)
-{
- papi_attribute_value_t **tmp;
- void *fodder = NULL;
-
- if ((list == NULL) || ((name == NULL) && (iter == NULL)) ||
- (value == NULL))
- return (PAPI_BAD_ARGUMENT);
-
- if (iter == NULL)
- iter = &fodder;
-
- if ((iter == NULL) || (*iter == NULL)) {
- papi_attribute_t *attr = papiAttributeListFind(list, name);
-
- if (attr == NULL)
- return (PAPI_NOT_FOUND);
-
- if (attr->type != type)
- return (PAPI_NOT_POSSIBLE);
-
- tmp = attr->values;
- } else
- tmp = *iter;
-
- if (tmp == NULL)
- return (PAPI_NOT_FOUND);
-
- *value = *tmp;
- *iter = ++tmp;
-
- if (*value == NULL)
- return (PAPI_GONE);
-
- return (PAPI_OK);
-}
-
-papi_status_t
-papiAttributeListGetString(papi_attribute_t **list, void **iter,
- const char *name, char **vptr)
-{
- papi_status_t status;
- papi_attribute_value_t *value = NULL;
-
- if (vptr == NULL)
- return (PAPI_BAD_ARGUMENT);
-
- status = papiAttributeListGetValue(list, iter, name,
- PAPI_STRING, &value);
- if (status == PAPI_OK)
- *vptr = value->string;
-
- return (status);
-}
-
-papi_status_t
-papiAttributeListGetInteger(papi_attribute_t **list, void **iter,
- const char *name, int *vptr)
-{
- papi_status_t status;
- papi_attribute_value_t *value = NULL;
-
- if (vptr == NULL)
- return (PAPI_BAD_ARGUMENT);
-
- status = papiAttributeListGetValue(list, iter, name,
- PAPI_INTEGER, &value);
- if (status == PAPI_OK)
- *vptr = value->integer;
-
- return (status);
-}
-
-papi_status_t
-papiAttributeListGetBoolean(papi_attribute_t **list, void **iter,
- const char *name, char *vptr)
-{
- papi_status_t status;
- papi_attribute_value_t *value = NULL;
-
- if (vptr == NULL)
- return (PAPI_BAD_ARGUMENT);
-
- status = papiAttributeListGetValue(list, iter, name,
- PAPI_BOOLEAN, &value);
- if (status == PAPI_OK)
- *vptr = value->boolean;
-
- return (status);
-}
-
-papi_status_t
-papiAttributeListGetRange(papi_attribute_t **list, void **iter,
- const char *name, int *min, int *max)
-{
- papi_status_t status;
- papi_attribute_value_t *value = NULL;
-
- if ((min == NULL) || (max == NULL))
- return (PAPI_BAD_ARGUMENT);
-
- status = papiAttributeListGetValue(list, iter, name,
- PAPI_RANGE, &value);
- if (status == PAPI_OK) {
- *min = value->range.lower;
- *max = value->range.upper;
- }
-
- return (status);
-}
-
-papi_status_t
-papiAttributeListGetResolution(papi_attribute_t **list, void **iter,
- const char *name, int *x, int *y,
- papi_resolution_unit_t *units)
-{
- papi_status_t status;
- papi_attribute_value_t *value = NULL;
-
- if ((x == NULL) || (y == NULL) || (units == NULL))
- return (PAPI_BAD_ARGUMENT);
-
- status = papiAttributeListGetValue(list, iter, name,
- PAPI_RESOLUTION, &value);
- if (status == PAPI_OK) {
- *x = value->resolution.xres;
- *y = value->resolution.yres;
- *units = value->resolution.units;
- }
-
- return (status);
-}
-
-papi_status_t
-papiAttributeListGetDatetime(papi_attribute_t **list, void **iter,
- const char *name, time_t *dt)
-{
- papi_status_t status;
- papi_attribute_value_t *value = NULL;
-
- if (dt == NULL)
- return (PAPI_BAD_ARGUMENT);
-
- status = papiAttributeListGetValue(list, iter, name,
- PAPI_DATETIME, &value);
- if (status == PAPI_OK) {
- *dt = value->datetime;
- }
-
- return (status);
-}
-
-papi_status_t
-papiAttributeListGetCollection(papi_attribute_t **list, void **iter,
- const char *name, papi_attribute_t ***collection)
-{
- papi_status_t status;
- papi_attribute_value_t *value = NULL;
-
- if (collection == NULL)
- return (PAPI_BAD_ARGUMENT);
-
- status = papiAttributeListGetValue(list, iter, name,
- PAPI_COLLECTION, &value);
- if (status == PAPI_OK) {
- *collection = value->collection;
- }
-
- 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.
- *
- * *****************************************************************************
- */
-
-static char *
-_getNextAttr(const char *string, int *next)
-
-{
- char *result = NULL;
- char *start = (char *)string + *next;
- char *nl = NULL;
- char *sp = NULL;
- char *tab = NULL;
- char *val = NULL;
- int len = 0;
-
- if ((string != NULL) && (*start != '\0'))
- {
- while ((*start == ' ') || (*start == '\t') || (*start == '\n'))
- {
- start++;
- }
- nl = strchr(start, '\n');
- sp = strchr(start, ' ');
- tab = strchr(start, '\t');
-
- val = strchr(start, '=');
-
- 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 ((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;
- }
-
- if (len == 0)
- {
- len = strlen(start);
- }
-
- if (len > 0)
- {
- result = (char *)malloc(len+1);
- if (result != NULL)
- {
- strncpy(result, start, len);
- result[len] = '\0';
- *next = (start-string)+len;
- }
- }
- }
-
- 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)
-
-{
- 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;
-
- 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);
- }
-
-
-/*
- * TODO - need to sort out 'resolution', 'dateandtime' & 'collection' values
- */
- if ((value != NULL) && (strlen(value) > 0) && (attr != NULL))
- {
-
- len = strlen(value);
- if ((len >= 2) &&
- (((value[0] == '"') && (value[len-1] == '"')) ||
- ((value[0] == '\'') && (value[len-1] == '\''))))
- {
- /* string value */
- attr->type = PAPI_STRING;
-
- 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? */
-
- 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);
- }
-
- }
- else
- {
- result = PAPI_BAD_ARGUMENT;
- }
-
- if (result != PAPI_OK)
- {
- i = 0;
- while (avalues[i] != NULL)
- {
- free(avalues[i]);
- i++;
- }
- free(avalues);
- }
- else
- {
- attr->values = avalues;
- }
-
- 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)
-
-{
- papi_status_t result = PAPI_OK;
- char *string = NULL;
- char *p = NULL;
- papi_attribute_value_t **avalues = NULL;
-
- 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 */
-
- result = _parseAttrValue(p, attr);
- }
- else
- {
- /* boolean - no value so assume 'true' */
- attr->name = string;
- attr->type = PAPI_BOOLEAN;
-
- avalues =
- malloc(
- sizeof (papi_attribute_value_t *) * 2);
- if (avalues == NULL)
- {
- result = PAPI_TEMPORARY_ERROR;
- }
- 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 =
- PAPI_TRUE;
- attr->values = avalues;
- }
- }
- }
- }
- }
- else
- {
- result = PAPI_BAD_ARGUMENT;
- }
-
- return (result);
-} /* _parseAttributeString() */
-
-
-papi_status_t
-papiAttributeListFromString(papi_attribute_t ***attrs,
- const int flags, const 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)) {
-printf("papiAttributeListFromString() attr='%s'\n", attrString);
- 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 = papiAttributeListAdd(
- 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 = PAPI_BAD_ARGUMENT;
- }
-
- return (result);
-}
-
-papi_status_t
-papiAttributeListToString(const papi_attribute_t **attrs,
- const char *delim, char *buffer, const size_t buflen)
-{
- return (PAPI_OPERATION_NOT_SUPPORTED);
-}
-
-/* for debugging, not part of the public API */
-static char *
-typeString(papi_attribute_value_type_t type)
-{
- switch (type) {
- case PAPI_STRING:
- return ("string");
- case PAPI_INTEGER:
- return ("integer");
- case PAPI_BOOLEAN:
- return ("boolean");
- case PAPI_RANGE:
- return ("range");
- case PAPI_RESOLUTION:
- return ("resolution");
- case PAPI_DATETIME:
- return ("datetime");
- case PAPI_COLLECTION:
- return ("collection");
- }
-
- return ("unknown");
-}
-
-void papiAttributeListPrint(FILE *fp, char *prefix, papi_attribute_t **list);
-
-void
-papiAttributePrint(FILE *fp, char *prefix, papi_attribute_t *attribute)
-{
- if (attribute != NULL) {
- char *name = attribute->name;
-
- if (prefix == NULL)
- prefix = "";
-
-/*
- * fprintf(fp, "%s'%s' (%s) =\n", prefix, (name ? name : "(NULL)"),
- * typeString(attribute->type));
- */
- if (attribute->values != NULL) {
- papi_attribute_value_t **values = attribute->values;
- int i;
-
- for (i = 0; values[i] != NULL; i++) {
- fprintf(fp, "%s=", (name ? name : "(NULL)"));
-/*
- * if (attribute->type != PAPI_COLLECTION)
- * fprintf(fp, "%s\t", prefix);
- */
- switch (attribute->type) {
- case PAPI_STRING:
- if ((strchr(values[i]->string, ' ')
- != NULL) ||
- (strchr(values[i]->string, '\t')
- != NULL)) {
- /* quote the string */
- fprintf(fp, "\"%s\"",
- values[i]->string);
- } else {
- fprintf(fp, "%s",
- values[i]->string);
- }
- break;
- case PAPI_INTEGER:
- fprintf(fp, "%d", values[i]->integer);
- break;
- case PAPI_BOOLEAN:
- fprintf(fp, "%s", (values[i]->boolean ?
- "true" : "false"));
- break;
- case PAPI_RANGE:
- fprintf(fp, "%d-%d",
- values[i]->range.lower,
- values[i]->range.upper);
- break;
- case PAPI_RESOLUTION:
- fprintf(fp, "%dx%d",
- values[i]->resolution.xres,
- values[i]->resolution.yres);
- break;
- case PAPI_DATETIME: {
- struct tm *tm;
-
- tm = localtime(&values[i]->datetime);
- if (tm != NULL) {
- char buf[64];
-
- strftime(buf, sizeof (buf),
- "%C", tm);
- fprintf(fp, "%s", buf);
- }}
- break;
- case PAPI_COLLECTION: {
- char s[64];
-
- snprintf(s, sizeof (s), "%s\t", prefix);
- papiAttributeListPrint(fp, s,
- values[i]->collection);
- }
- break;
- default:
- fprintf(fp, "unknown");
- }
- if (attribute->type != PAPI_COLLECTION)
- fprintf(fp, "\n");
- }
- }
- }
-}
-
-
-void
-papiAttributeListPrint(FILE *fp, char *prefix, papi_attribute_t **list)
-{
- if (list != NULL) {
- int i;
-
- for (i = 0; list[i] != NULL; i++)
- papiAttributePrint(fp, prefix, list[i]);
- }
-}
diff --git a/usr/src/cmd/lp/lib/papi/job.c b/usr/src/cmd/lp/lib/papi/job.c
index ff8aea70b7..776e6dee1c 100644
--- a/usr/src/cmd/lp/lib/papi/job.c
+++ b/usr/src/cmd/lp/lib/papi/job.c
@@ -35,11 +35,22 @@
#include <sys/stat.h>
#include <papi_impl.h>
+
+/*
+ * for an older application that may have been linked with a pre-v1.0
+ * PAPI implementation.
+ */
+papi_status_t
+papiAttributeListAdd(papi_attribute_t ***attrs, int flags, char *name,
+ papi_attribute_value_type_t type, papi_attribute_value_t *value)
+{
+ return (papiAttributeListAddValue(attrs, flags, name, type, value));
+}
+
#ifdef LP_USE_PAPI_ATTR
-static papi_status_t psm_modifyAttrsFile(const papi_attribute_t **attrs,
- char *file);
-static papi_status_t psm_modifyAttrsList(char *file,
- const papi_attribute_t **attrs, papi_attribute_t ***newAttrs);
+static papi_status_t psm_modifyAttrsFile(papi_attribute_t **attrs, char *file);
+static papi_status_t psm_modifyAttrsList(char *file, papi_attribute_t **attrs,
+ papi_attribute_t ***newAttrs);
#endif
@@ -104,12 +115,6 @@ papiJobGetId(papi_job_t job)
return (result);
}
-papi_job_ticket_t *
-papiJobGetJobTicket(papi_job_t job)
-{
- return (NULL); /* NOT SUPPORTED */
-}
-
static REQUEST *
create_request(papi_service_t svc, char *printer, papi_attribute_t **attributes)
{
@@ -158,7 +163,7 @@ authorized(service_t *svc, int32_t id)
}
static papi_status_t
-copy_file(const char *from, char *to)
+copy_file(char *from, char *to)
{
int ifd, ofd;
char buf[BUFSIZ];
@@ -199,23 +204,18 @@ copy_file(const char *from, char *to)
*/
static papi_status_t
-psm_copy_attrsToFile(const papi_attribute_t **attrs, char *file)
+psm_copy_attrsToFile(papi_attribute_t **attrs, char *file)
{
papi_status_t result = PAPI_OK;
- FILE *out = NULL;
-
- if ((attrs != NULL) && (*attrs != NULL))
- {
- out = fopen(file, "w");
- if (out != NULL)
- {
- papiAttributeListPrint(
- out, "", (papi_attribute_t **)attrs);
+
+ if ((attrs != NULL) && (*attrs != NULL)) {
+ FILE *out = NULL;
+
+ if ((out = fopen(file, "w")) != NULL) {
+ papiAttributeListPrint(out, attrs, "");
fclose(out);
- }
- else
- {
+ } else {
result = PAPI_NOT_POSSIBLE;
}
}
@@ -238,7 +238,7 @@ psm_copy_attrsToFile(const papi_attribute_t **attrs, char *file)
*/
static papi_status_t
-psm_modifyAttrsFile(const papi_attribute_t **attrs, char *file)
+psm_modifyAttrsFile(papi_attribute_t **attrs, char *file)
{
papi_status_t result = PAPI_OK;
@@ -246,61 +246,46 @@ psm_modifyAttrsFile(const papi_attribute_t **attrs, char *file)
struct stat tmpBuf;
FILE *fd = NULL;
- if ((attrs != NULL) && (*attrs != NULL) && (file != NULL))
- {
+ if ((attrs != NULL) && (*attrs != NULL) && (file != NULL)) {
/*
* check file exist before try to modify it, if it doesn't
* exist assume there is an error
*/
- if (stat(file, &tmpBuf) == 0)
- {
+ if (stat(file, &tmpBuf) == 0) {
/*
* if file is currently empty just write the given
* attributes to the file otherwise exact the attributes
* from the file and modify them accordingly before
* writing them back to the file
*/
- if (tmpBuf.st_size == 0)
- {
-printf("psm_modifyAttrsFile() @1 - empty attribute file\n");
+ if (tmpBuf.st_size == 0) {
newAttrs = (papi_attribute_t **)attrs;
fd = fopen(file, "w");
- if (fd != NULL)
- {
+ if (fd != NULL) {
papiAttributeListPrint(fd,
- "", newAttrs);
+ newAttrs, "");
fclose(fd);
- }
- else
- {
+ } else {
result = PAPI_NOT_POSSIBLE;
}
- }
- else
- {
-printf("psm_modifyAttrsFile() @2 - modify file\n");
+ } else {
result =
psm_modifyAttrsList(file, attrs, &newAttrs);
fd = fopen(file, "w");
- if (fd != NULL)
- {
+ if (fd != NULL) {
papiAttributeListPrint(fd,
- "", newAttrs);
+ newAttrs, "");
fclose(fd);
- }
- else
- {
+ } else {
result = PAPI_NOT_POSSIBLE;
}
papiAttributeListFree(newAttrs);
}
- }
- else
- {
+ } else {
result = PAPI_NOT_POSSIBLE;
}
}
@@ -324,7 +309,7 @@ printf("psm_modifyAttrsFile() @2 - modify file\n");
*/
static papi_status_t
-psm_modifyAttrsList(char *file, const papi_attribute_t **attrs,
+psm_modifyAttrsList(char *file, papi_attribute_t **attrs,
papi_attribute_t ***newAttrs)
{
@@ -341,39 +326,30 @@ psm_modifyAttrsList(char *file, const papi_attribute_t **attrs,
int n = 0;
fd = fopen(file, "r");
- if (fd != NULL)
- {
+ if (fd != NULL) {
fD = fileno(fd);
a = &aBuff[0];
p = &aBuff[0];
count = read(fD, &aBuff[0], sizeof (aBuff) - 1);
- while ((result == PAPI_OK) && (count > 0))
- {
+ while ((result == PAPI_OK) && (count > 0)) {
aBuff[count+n] = '\0';
- if (count == sizeof (aBuff) - n - 1)
- {
+ if (count == sizeof (aBuff) - n - 1) {
p = strrchr(aBuff, '\n');
- if (p != NULL)
- {
+ if (p != NULL) {
/* terminate at last complete line */
*p = '\0';
}
}
-printf("psm_modifyAttrsList() @3 - aBuff=\n");
-printf("%s\n", aBuff);
result = papiAttributeListFromString(
newAttrs, PAPI_ATTR_EXCL, aBuff);
-printf("psm_modifyAttrsList() @4 - result=%d\n", result);
- if (result == PAPI_OK)
- {
+ if (result == PAPI_OK) {
/*
* handle any part lines and then read the next
* buffer from the file
*/
n = 0;
- if (p != a)
- {
+ if (p != a) {
p++; /* skip NL */
n = sizeof (aBuff) - 1 - (p - a);
strncpy(aBuff, p, n);
@@ -389,13 +365,11 @@ printf("psm_modifyAttrsList() @4 - result=%d\n", result);
/* now modify the attribute list with the new attributes in 'attrs' */
nextAttr = papiAttributeListGetNext((papi_attribute_t **)attrs, &iter);
- while ((result == PAPI_OK) && (nextAttr != NULL))
- {
+ while ((result == PAPI_OK) && (nextAttr != NULL)) {
values = nextAttr->values;
- if ((values != NULL) && (*values != NULL))
- {
- result = papiAttributeListAdd(newAttrs,
+ if ((values != NULL) && (*values != NULL)) {
+ result = papiAttributeListAddValue(newAttrs,
PAPI_ATTR_REPLACE,
nextAttr->name,
nextAttr->type, *values);
@@ -403,9 +377,8 @@ printf("psm_modifyAttrsList() @4 - result=%d\n", result);
}
while ((result == PAPI_OK) &&
- (values != NULL) && (*values != NULL))
- {
- result = papiAttributeListAdd(newAttrs,
+ (values != NULL) && (*values != NULL)) {
+ result = papiAttributeListAddValue(newAttrs,
PAPI_ATTR_APPEND,
nextAttr->name,
nextAttr->type, *values);
@@ -421,10 +394,10 @@ printf("psm_modifyAttrsList() @4 - result=%d\n", result);
papi_status_t
-papiJobSubmit(papi_service_t handle, const char *printer,
- const papi_attribute_t **job_attributes,
- const papi_job_ticket_t *job_ticket,
- const char **files, papi_job_t *job)
+papiJobSubmit(papi_service_t handle, char *printer,
+ papi_attribute_t **job_attributes,
+ papi_job_ticket_t *job_ticket,
+ char **files, papi_job_t *job)
{
papi_status_t status;
service_t *svc = handle;
@@ -526,10 +499,10 @@ papiJobSubmit(papi_service_t handle, const char *printer,
}
papi_status_t
-papiJobSubmitByReference(papi_service_t handle, const char *printer,
- const papi_attribute_t **job_attributes,
- const papi_job_ticket_t *job_ticket,
- const char **files, papi_job_t *job)
+papiJobSubmitByReference(papi_service_t handle, char *printer,
+ papi_attribute_t **job_attributes,
+ papi_job_ticket_t *job_ticket,
+ char **files, papi_job_t *job)
{
service_t *svc = handle;
job_t *j;
@@ -620,10 +593,10 @@ papiJobSubmitByReference(papi_service_t handle, const char *printer,
}
papi_status_t
-papiJobValidate(papi_service_t handle, const char *printer,
- const papi_attribute_t **job_attributes,
- const papi_job_ticket_t *job_ticket,
- const char **files, papi_job_t *job)
+papiJobValidate(papi_service_t handle, char *printer,
+ papi_attribute_t **job_attributes,
+ papi_job_ticket_t *job_ticket,
+ char **files, papi_job_t *job)
{
papi_status_t status;
papi_attribute_t **attributes = NULL;
@@ -635,7 +608,7 @@ papiJobValidate(papi_service_t handle, const char *printer,
list_append(&attributes, job_attributes[i]);
status = papiJobSubmitByReference(handle, printer,
- (const papi_attribute_t **)attributes,
+ (papi_attribute_t **)attributes,
job_ticket, files, job);
if (status == PAPI_OK) {
int id = papiJobGetId(*job);
@@ -651,9 +624,9 @@ papiJobValidate(papi_service_t handle, const char *printer,
}
papi_status_t
-papiJobStreamOpen(papi_service_t handle, const char *printer,
- const papi_attribute_t **job_attributes,
- const papi_job_ticket_t *job_ticket, papi_stream_t *stream)
+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 status;
service_t *svc = handle;
@@ -716,7 +689,7 @@ papiJobStreamOpen(papi_service_t handle, const char *printer,
papi_status_t
papiJobStreamWrite(papi_service_t handle,
- papi_stream_t stream, const void *buffer, const size_t buflen)
+ papi_stream_t stream, void *buffer, size_t buflen)
{
service_t *svc = handle;
job_stream_t *s = stream;
@@ -769,8 +742,8 @@ papiJobStreamClose(papi_service_t handle,
}
papi_status_t
-papiJobQuery(papi_service_t handle, const char *printer, const int32_t job_id,
- const char **requested_attrs,
+papiJobQuery(papi_service_t handle, char *printer, int32_t job_id,
+ char **requested_attrs,
papi_job_t *job)
{
service_t *svc = handle;
@@ -824,7 +797,51 @@ papiJobQuery(papi_service_t handle, const char *printer, const int32_t job_id,
}
papi_status_t
-papiJobCancel(papi_service_t handle, const char *printer, const int32_t job_id)
+papiJobMove(papi_service_t handle, char *printer, int32_t job_id,
+ char *destination)
+{
+ papi_status_t result = PAPI_OK;
+ service_t *svc = handle;
+ char req_id[64];
+ char *queue;
+ char *user = NULL;
+
+ if ((svc == NULL) || (printer == NULL) || (job_id < 0) ||
+ (destination == NULL))
+ return (PAPI_BAD_ARGUMENT);
+
+ queue = printer_name_from_uri_id(printer, job_id);
+ snprintf(req_id, sizeof (req_id), "%s-%d", queue, job_id);
+ free(queue);
+
+ if (papiAttributeListGetString(svc->attributes, NULL, "user-name",
+ &user) == PAPI_OK) {
+ REQUEST *r = getrequest(req_id);
+
+ if ((r != NULL) && (r->user != NULL) &&
+ (strcmp(r->user, user) != 0))
+ result = PAPI_NOT_AUTHORIZED;
+ freerequest(r);
+ }
+
+ if (result == PAPI_OK) {
+ short status = MOK;
+ char *dest = printer_name_from_uri_id(destination, -1);
+
+ if ((snd_msg(svc, S_MOVE_REQUEST, req_id, dest) < 0) ||
+ (rcv_msg(svc, R_MOVE_REQUEST, &status) < 0))
+ status = MTRANSMITERR;
+
+ free(dest);
+
+ result = lpsched_status_to_papi_status(status);
+ }
+
+ return (result);
+}
+
+papi_status_t
+papiJobCancel(papi_service_t handle, char *printer, int32_t job_id)
{
papi_status_t result = PAPI_OK;
service_t *svc = handle;
@@ -843,7 +860,8 @@ papiJobCancel(papi_service_t handle, const char *printer, const int32_t job_id)
&user) == PAPI_OK) {
REQUEST *r = getrequest(req_id);
- if ((r != NULL) && (strcmp(r->user, user) != 0))
+ if ((r != NULL) && (r->user != NULL) &&
+ (strcmp(r->user, user) != 0))
result = PAPI_NOT_AUTHORIZED;
freerequest(r);
}
@@ -862,8 +880,8 @@ papiJobCancel(papi_service_t handle, const char *printer, const int32_t job_id)
}
papi_status_t
-hold_release_job(papi_service_t handle, const char *printer,
- const int32_t job_id, int flag)
+hold_release_job(papi_service_t handle, char *printer,
+ int32_t job_id, int flag)
{
papi_status_t status;
service_t *svc = handle;
@@ -884,16 +902,25 @@ hold_release_job(papi_service_t handle, const char *printer,
if ((r = getrequest(file)) != NULL) {
r->actions &= ~ACT_RESUME;
- if (flag == 0)
+ switch (flag) {
+ case 0:
r->actions |= ACT_HOLD;
- else
+ break;
+ case 1:
r->actions |= ACT_RESUME;
+ break;
+ case 2:
+ r->actions |= ACT_IMMEDIATE;
+ break;
+ }
if (putrequest(file, r) < 0) {
detailed_error(svc,
gettext("failed to write job: %s: %s"),
file, strerror(errno));
+ freerequest(r);
return (PAPI_DEVICE_ERROR);
}
+ freerequest(r);
} else {
detailed_error(svc, gettext("failed to read job: %s: %s"),
file, strerror(errno));
@@ -901,34 +928,31 @@ hold_release_job(papi_service_t handle, const char *printer,
}
status = lpsched_end_change(svc, dest, job_id);
- freerequest(r);
- free(dest);
return (status);
}
papi_status_t
-papiJobHold(papi_service_t handle, const char *printer, const int32_t job_id,
- const char *hold_until, const time_t *hold_until_time)
+papiJobHold(papi_service_t handle, char *printer, int32_t job_id)
{
return (hold_release_job(handle, printer, job_id, 0));
}
papi_status_t
-papiJobRelease(papi_service_t handle, const char *printer, const int32_t job_id)
+papiJobRelease(papi_service_t handle, char *printer, int32_t job_id)
{
return (hold_release_job(handle, printer, job_id, 1));
}
papi_status_t
-papiJobRestart(papi_service_t handle, const char *printer, const int32_t job_id)
+papiJobPromote(papi_service_t handle, char *printer, int32_t job_id)
{
- return (PAPI_OPERATION_NOT_SUPPORTED);
+ return (hold_release_job(handle, printer, job_id, 2));
}
papi_status_t
-papiJobModify(papi_service_t handle, const char *printer, const int32_t job_id,
- const papi_attribute_t **attributes, papi_job_t *job)
+papiJobModify(papi_service_t handle, char *printer, int32_t job_id,
+ papi_attribute_t **attributes, papi_job_t *job)
{
papi_status_t status;
job_t *j = NULL;
@@ -989,7 +1013,6 @@ papiJobModify(papi_service_t handle, const char *printer, const int32_t job_id,
status = lpsched_end_change(svc, dest, job_id);
lpsched_request_to_job_attributes(r, j);
freerequest(r);
- free(dest);
return (status);
}
@@ -1000,9 +1023,9 @@ papiJobModify(papi_service_t handle, const char *printer, const int32_t job_id,
#define DUMMY_FILE "/var/spool/lp/fifos/FIFO"
papi_status_t
-papiJobCreate(papi_service_t handle, const char *printer,
- const papi_attribute_t **job_attributes,
- const papi_job_ticket_t *job_ticket, papi_job_t *job)
+papiJobCreate(papi_service_t handle, char *printer,
+ papi_attribute_t **job_attributes,
+ papi_job_ticket_t *job_ticket, papi_job_t *job)
{
papi_status_t status;
service_t *svc = handle;
@@ -1030,6 +1053,8 @@ papiJobCreate(papi_service_t handle, const char *printer,
/* convert the attributes to an lpsched REQUEST structure */
request = create_request(svc, (char *)printer,
(papi_attribute_t **)job_attributes);
+ if (request == NULL)
+ return (PAPI_TEMPORARY_ERROR);
addlist(&request->file_list, DUMMY_FILE); /* add a dummy file */
request->actions |= ACT_HOLD; /* hold the job */
@@ -1046,12 +1071,14 @@ papiJobCreate(papi_service_t handle, const char *printer,
if (status != PAPI_OK) {
detailed_error(svc, "unable to copy attributes to file: %s: %s",
metadata_file, strerror(errno));
+ free(request_id);
return (PAPI_DEVICE_ERROR);
}
#endif
/* store the REQUEST on disk */
snprintf(metadata_file, sizeof (metadata_file), "%s-0", request_id);
+ free(request_id);
if (putrequest(metadata_file, request) < 0) {
detailed_error(svc, gettext("unable to save request: %s: %s"),
metadata_file, strerror(errno));
@@ -1103,6 +1130,7 @@ papiJobCommit(papi_service_t handle, char *printer, int32_t id)
detailed_error(svc,
gettext("failed to write job: %s: %s"),
metadata_file, strerror(errno));
+ freerequest(r);
return (PAPI_DEVICE_ERROR);
}
} else {
@@ -1113,7 +1141,6 @@ papiJobCommit(papi_service_t handle, char *printer, int32_t id)
status = lpsched_end_change(svc, dest, id);
freerequest(r);
- free(dest);
return (status);
}
@@ -1173,7 +1200,6 @@ papiJobStreamAdd(papi_service_t handle, char *printer, int32_t id,
}
status = lpsched_end_change(svc, dest, id);
- free(dest);
if (status != PAPI_OK)
return (status);
diff --git a/usr/src/cmd/lp/lib/papi/library.c b/usr/src/cmd/lp/lib/papi/library.c
new file mode 100644
index 0000000000..53c3a956a6
--- /dev/null
+++ b/usr/src/cmd/lp/lib/papi/library.c
@@ -0,0 +1,98 @@
+/*
+ * 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 "%Z%%M% %I% %E% SMI"
+
+/*LINTLIBRARY*/
+
+#include <stdio.h>
+#include <string.h>
+#include <papi.h>
+
+static char *calls[] = {
+ /* Attribute Calls */
+ "papiAttributeListAddValue",
+ "papiAttributeListAddBoolean", "papiAttributeListAddCollection",
+ "papiAttributeListAddDatetime", "papiAttributeListAddInteger",
+ "papiAttributeListAddMetadata", "papiAttributeListAddRange",
+ "papiAttributeListAddResolution", "papiAttributeListAddString",
+ "papiAttributeListDelete",
+ "papiAttributeListGetValue", "papiAttributeListGetNext",
+ "papiAttributeListFind",
+ "papiAttributeListGetBoolean", "papiAttributeListGetCollection",
+ "papiAttributeListGetDatetime", "papiAttributeListGetInteger",
+ "papiAttributeListGetMetadata", "papiAttributeListGetRange",
+ "papiAttributeListGetResolution", "papiAttributeListGetString",
+ "papiAttributeListFromString", "papiAttributeListToString",
+ "papiAttributeListFree",
+ /* Job Calls */
+ "papiJobSubmit", "papiJobSubmitByReference", "papiJobValidate",
+ "papiJobStreamOpen", "papiJobStreamWrite", "papiJobStreamClose",
+ "papiJobQuery", "papiJobModify", "papiJobCancel", "papiJobPromote",
+ "papiJobGetAttributeList", "papiJobGetId", "papiJobGetPrinterName",
+ "papiJobFree", "papiJobListFree",
+ "papiJobHold", "papiJobRelease",
+ /* Printer Calls */
+ "papiPrintersList", "papiPrinterQuery", "papiPrinterModify",
+ "papiPrinterAdd", "papiPrinterRemove",
+ "papiPrinterPause", "papiPrinterResume",
+ "papiPrinterDisable", "papiPrinterEnable",
+ "papiPrinterPurgeJobs", "papiPrinterListJobs",
+ "papiPrinterGetAttributeList",
+ "papiPrinterFree", "papiPrinterListFree",
+ /* Service Calls */
+ "papiServiceCreate", "papiServiceDestroy",
+ "papiServiceGetAppData",
+ "papiServiceGetEncryption", "papiServiceGetPassword",
+ "papiServiceGetServiceName", "papiServiceGetUserName",
+ "papiServiceSetAppData", "papiServiceSetAuthCB",
+ "papiServiceSetEncryption", "papiServiceSetPassword",
+ "papiServiceSetUserName",
+ "papiServiceGetAttributeList", "papiServiceGetStatusMessage",
+ /* Misc Calls */
+ "papiStatusString",
+ "papiLibrarySupportedCall", "papiLibrarySupportedCalls",
+ NULL
+};
+
+char **
+papiLibrarySupportedCalls()
+{
+ return (calls);
+}
+
+char
+papiLibrarySupportedCall(const char *name)
+{
+ int i;
+
+ for (i = 0; calls[i] != NULL; i++)
+ if (strcmp(name, calls[i]) == 0)
+ return (PAPI_TRUE);
+
+ return (PAPI_FALSE);
+}
diff --git a/usr/src/cmd/lp/lib/papi/list.c b/usr/src/cmd/lp/lib/papi/list.c
deleted file mode 100644
index fb5451232f..0000000000
--- a/usr/src/cmd/lp/lib/papi/list.c
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (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 2003 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-
-#pragma ident "%Z%%M% %I% %E% SMI"
-
-/*LINTLIBRARY*/
-
-#include <stdlib.h>
-#include <stdarg.h>
-#include <errno.h>
-
-static int __list_increment = 16;
-
-int
-list_append(void ***list, void *item)
-{
- int count;
-
- if ((list == NULL) || (item == NULL)) {
- errno = EINVAL;
- return (-1);
- }
-
- if (item != NULL) {
- if (*list == NULL)
- *list = (void **)calloc(__list_increment,
- sizeof (void *));
-
- 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;
-
- new_list = (void **)calloc(new_size, sizeof (void *));
-
- for (count = 0; (*list)[count] != NULL; count++)
- new_list[count] = (*list)[count];
- free(*list);
- *list = new_list;
- }
-
- (*list)[count] = item;
- }
-
- return (0);
-}
-
-/*
- * list_concatenate() takes in two NULL terminated lists of items (type **)
- * and creates a new list with items from list2 appended on the end of
- * the list of items from list1. The result is a list (type **). If
- * there is a failure, -1 is returned.
- */
-int
-list_concatenate(void ***result, void **list2)
-{
- void **list1;
- int size1 = 0,
- size2 = 0,
- new_size = 0;
-
- if ((result == NULL) || ((*result == NULL) && (list2 == NULL))) {
- errno = EINVAL;
- return (-1);
- }
-
- list1 = *result;
-
- if (list1 != NULL)
- for (size1 = 0; list1[size1] != NULL; size1++);
- if (list2 != NULL)
- 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;
-
- if ((*result = (void **)calloc((new_size), sizeof (void *)))
- != NULL) {
- int count = 0;
-
- if (list1 != NULL)
- for (size1 = 0; list1[size1] != NULL; size1++)
- (*result)[count++] = list1[size1];
- if (list2 != NULL)
- for (size2 = 0; list2[size2] != NULL; size2++)
- (*result)[count++] = list2[size2];
- free(list1);
- }
-
- return (0);
-}
-
-/*
- * list_locate() iterates through the list passed in and uses the comparison
- * routine and element passed in to find an element in the list. It
- * returns the first element matched, or NULL if none exists
- */
-void *
-list_locate(void **list, int (*compare)(void *, void *), void *element)
-{
- int current = 0;
-
- if ((list != NULL) && (element != NULL))
- for (current = 0; list[current] != NULL; current++)
- if ((compare)(list[current], element) == 0)
- return (list[current]);
- return (NULL);
-}
-
-void
-list_remove(void **list, void *item)
-{
- int i, last;
-
- if ((list == NULL) || (*list == NULL) || (item == NULL))
- return;
-
- for (last = 0; list[last] != NULL; last++)
- ;
- --last;
-
- /*
- * 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;
- }
- }
-}
diff --git a/usr/src/cmd/lp/lib/papi/lpsched-jobs.c b/usr/src/cmd/lp/lib/papi/lpsched-jobs.c
index 225cc08dcf..a4fea773a5 100644
--- a/usr/src/cmd/lp/lib/papi/lpsched-jobs.c
+++ b/usr/src/cmd/lp/lib/papi/lpsched-jobs.c
@@ -44,14 +44,14 @@ papi_status_t
job_attributes_to_lpsched_request(papi_service_t svc, REQUEST *r,
papi_attribute_t **attributes)
{
+ papi_status_t status = PAPI_OK;
papi_attribute_t *attr;
+ papi_attribute_t **unmapped = NULL;
int i;
char *s;
char **options = NULL;
char **modes = NULL;
- char *class = NULL;
- char *job_name = NULL;
char pr_filter = 0;
char *pr_title = NULL;
@@ -59,26 +59,36 @@ job_attributes_to_lpsched_request(papi_service_t svc, REQUEST *r,
int pr_indent = -1;
int numberUp = 0;
int orientation = 0;
- int lowerPage = 0;
- int upperPage = 0;
- papi_status_t getResult = 0;
+ int lower = 0;
+ int upper = 0;
char buf[256];
void *iterator = NULL;
-
- char banner = 0;
+ char *mapped_keys[] = { "copies", "document-format", "form",
+ "job-class", "job-hold-until", "job-host", "job-name",
+ "job-originating-user-name", "job-printer",
+ "job-sheets", "lp-charset", "lp-modes", "number-up",
+ "orienttation-requested", "page-ranges", "pr-filter",
+ "pr-indent", "pr-title", "pr-width", "priority",
+ "requesting-user-name", NULL };
if (attributes == NULL)
return (PAPI_BAD_ARGUMENT);
- papiAttributeListGetString(attributes, NULL, "job-printer",
- &r->destination);
+ /* replace the current destination */
+ papiAttributeListGetLPString(attributes,
+ "job-printer", &r->destination);
+ /* set the copies. We need at least 1 */
i = r->copies;
papiAttributeListGetInteger(attributes, NULL, "copies", &i);
if (i <= 0)
i = 1;
r->copies = i;
+ /*
+ * set the priority. PAPI/IPP uses 1-100, lpsched use 0-39, so we
+ * have to convert it.
+ */
if (papiAttributeListGetInteger(attributes, NULL, "priority", &i)
== PAPI_OK) {
if ((i < 1) || (i > 100))
@@ -86,56 +96,41 @@ job_attributes_to_lpsched_request(papi_service_t svc, REQUEST *r,
i = (i + 1) / 2.5;
r->priority = i;
}
-
if ((r->priority < 0) || (r->priority > 39))
r->priority = 20;
- /*
- * 'media' size should be processed both in the lpsched filter and
- * the foomatic filter (if present) so that we ensure the result of
- * other options like 'page-ranges' are consistent.
- */
-/*
- * TODO - I thing we should really have this but I can't get it to filter
- * so its commented out for now (paulcun)
- * papiAttributeListGetString(attributes, NULL, "media", &r->form);
- */
+ /* set the requested form to print on */
+ papiAttributeListGetLPString(attributes, "form", &r->form);
+ /* set the page range */
#ifndef LP_USE_PAPI_ATTR
- papiAttributeListGetString(attributes, NULL, "page-ranges", &r->pages);
+ papiAttributeListGetLPString(attributes, "page-ranges", &r->pages);
#else
- getResult =
- papiAttributeListGetRange(attributes, &iterator,
- "page-ranges", &lowerPage, &upperPage);
- while (getResult == PAPI_OK) {
- if (r->pages == NULL) {
- snprintf(buf, sizeof (buf),
- "%d-%d", lowerPage, upperPage);
- r->pages = (char *)strdup(buf);
- }
- else
- {
+ for (status = papiAttributeListGetRange(attributes, &iterator,
+ "page-ranges", &lower, &upper);
+ status == PAPI_OK;
+ status = papiAttributeListGetRange(attributes, &iterator,
+ "page-ranges", &lower, &upper)) {
+ if (r->pages != NULL) {
snprintf(buf, sizeof (buf), "%s,%d-%d",
- r->pages, lowerPage, upperPage);
+ r->pages, lower, upper);
free(r->pages);
- r->pages = (char *)strdup(buf);
- }
- /*
- * get the next value; note the attribute 'name' is set to
- * NULL to do this.
- */
- getResult =
- papiAttributeListGetRange(attributes, &iterator,
- "page-ranges", &lowerPage, &upperPage);
+ } else
+ snprintf(buf, sizeof (buf), "%d-%d", lower, upper);
+ r->pages = (char *)strdup(buf);
}
#endif
-
+ /*
+ * set the document format, converting to old format names as
+ * as needed.
+ */
s = NULL;
papiAttributeListGetString(attributes, NULL, "document-format", &s);
if (s != NULL)
r->input_type = strdup(mime_type_to_lp_type(s));
+
/*
* If we don't have an owner, set one.
*/
@@ -165,6 +160,7 @@ job_attributes_to_lpsched_request(papi_service_t svc, REQUEST *r,
r->user = strdup(user);
}
+ /* set any held state */
s = NULL;
papiAttributeListGetString(attributes, NULL, "job-hold-until", &s);
if (s != NULL) {
@@ -178,7 +174,8 @@ job_attributes_to_lpsched_request(papi_service_t svc, REQUEST *r,
r->actions |= ACT_HOLD;
}
- papiAttributeListGetString(attributes, NULL, "lp-charset", &r->charset);
+ /* set lp charset/printwheel */
+ papiAttributeListGetLPString(attributes, "lp-charset", &r->charset);
/* legacy pr(1) filter related garbage "lpr -p" */
papiAttributeListGetBoolean(attributes, NULL, "pr-filter", &pr_filter);
@@ -208,12 +205,16 @@ job_attributes_to_lpsched_request(papi_service_t svc, REQUEST *r,
"pr(1) filter options specified without enabling pr(1) filter"));
/* add burst page information */
- papiAttributeListGetBoolean(attributes, NULL, "job-sheets", &banner);
- papiAttributeListGetString(attributes, NULL, "job-class", &class);
- papiAttributeListGetString(attributes, NULL, "job-name", &job_name);
-
- {
+ s = NULL;
+ papiAttributeListGetString(attributes, NULL, "job-sheets", &s);
+ if ((s != NULL) && (strcasecmp(s, "none") == 0)) {
char buf[128];
+ char *class = NULL;
+ char *job_name = NULL;
+
+ papiAttributeListGetLPString(attributes, "job-class", &class);
+ papiAttributeListGetLPString(attributes, "job-name", &job_name);
+
/* burst page is enabled by default, add the title */
snprintf(buf, sizeof (buf), "%s%s%s",
(job_name ? job_name : ""),
@@ -224,27 +225,9 @@ job_attributes_to_lpsched_request(papi_service_t svc, REQUEST *r,
free(r->title);
r->title = strdup(buf);
}
- }
- if (banner == 0) /* burst page is disabled via lp "option" */
+ } else /* burst page is disabled via lp "option" */
appendlist(&options, "nobanner");
- /* add "lp -o" options */
- attr = papiAttributeListFind(attributes, "lp-options");
- if ((attr != NULL) && (attr->type == PAPI_STRING) &&
- (attr->values != NULL)) {
- int i;
-
- for (i = 0; attr->values[i] != NULL; i++)
- appendlist(&options, attr->values[i]->string);
- }
-
- if (options != NULL) {
- if (r->options != NULL)
- free(r->options);
- r->options = sprintlist(options);
- freelist(options);
- }
-
/* Convert attribute "number-up" to mode group=n */
papiAttributeListGetInteger(attributes, NULL, "number-up", &numberUp);
if ((numberUp >= 2) && ((numberUp % 2) == 0)) {
@@ -260,45 +243,15 @@ job_attributes_to_lpsched_request(papi_service_t svc, REQUEST *r,
"orientation-requested", &orientation);
if ((orientation >= 3) && (orientation <= 6)) {
switch (orientation) {
- case 3:
- {
- /* 3 = portrait */
- appendlist(&modes, "portrait");
- break;
- }
-
- case 4:
- {
- /* 4 = landscape */
- appendlist(&modes, "landscape");
- break;
- }
-
- case 5:
- {
- /*
- * 5 = reverse-landscape - not supported in
- * lpsched so just use 'landscape' for now
- */
- appendlist(&modes, "landscape");
- break;
- }
-
- case 6:
- {
- /*
- * 6 = reverse-portrait not supported in
- * lpsched so just use 'portrait' for now
- */
- appendlist(&modes, "portrait");
- break;
- }
-
- default:
- {
- appendlist(&modes, "portrait");
- break;
- }
+ case 4: /* landscape */
+ case 5: /* reverse-landscape, use landscape instead */
+ appendlist(&modes, "landscape");
+ break;
+ case 3: /* portrait */
+ case 6: /* reverse-portrait, use portrait instead */
+ default:
+ appendlist(&modes, "portrait");
+ break;
}
}
@@ -319,6 +272,29 @@ job_attributes_to_lpsched_request(papi_service_t svc, REQUEST *r,
freelist(modes);
}
+ /* add any unconsumed attributes to the "options" list */
+ split_and_copy_attributes(mapped_keys, attributes, NULL, &unmapped);
+ if (unmapped != NULL) { /* convert them to lp options */
+ char *buf = malloc(1024);
+ ssize_t size = 1024;
+
+ while (papiAttributeListToString(unmapped, ", ", buf, size)
+ != PAPI_OK) {
+ size += 1024;
+ buf = realloc(buf, size);
+ }
+ appendlist(&options, buf);
+ free(buf);
+ papiAttributeListFree(unmapped);
+ }
+
+ if (options != NULL) {
+ if (r->options != NULL)
+ free(r->options);
+ r->options = sprintlist(options);
+ freelist(options);
+ }
+
return (PAPI_OK);
}
@@ -388,26 +364,16 @@ lpsched_request_to_job_attributes(REQUEST *r, job_t *j)
"copies", r->copies);
/* destination */
- addLPString(&j->attributes, PAPI_ATTR_REPLACE, "printer-name",
- r->destination);
-
- /* file_list */
- addLPStrings(&j->attributes, PAPI_ATTR_REPLACE,
- "lpsched-files", r->file_list);
+ papiAttributeListAddLPString(&j->attributes, PAPI_ATTR_REPLACE,
+ "printer-name", r->destination);
/* form */
- addLPString(&j->attributes, PAPI_ATTR_REPLACE, "media", r->form);
-
- /* actions */
- papiAttributeListAddInteger(&j->attributes, PAPI_ATTR_REPLACE,
- "lpsched-actions", r->actions);
-
- /* alert */
- addLPString(&j->attributes, PAPI_ATTR_REPLACE, "lp-alert", r->alert);
+ papiAttributeListAddLPString(&j->attributes, PAPI_ATTR_REPLACE,
+ "form", r->form);
/* options */
- addLPString(&j->attributes, PAPI_ATTR_REPLACE,
- "lp-options", r->options);
+ papiAttributeListFromString(&j->attributes, PAPI_ATTR_APPEND,
+ r->options);
tmp = (((r->options != NULL) && (strstr(r->options, "nobanner")
!= NULL)) ? "none" : "standard");
@@ -429,33 +395,30 @@ lpsched_request_to_job_attributes(REQUEST *r, job_t *j)
"job-priority", (int)((r->priority + 1) * 2.5));
/* pages */
- addLPString(&j->attributes, PAPI_ATTR_REPLACE, "page-ranges", r->pages);
+ papiAttributeListAddLPString(&j->attributes, PAPI_ATTR_REPLACE,
+ "page-ranges", r->pages);
/* charset */
- addLPString(&j->attributes, PAPI_ATTR_REPLACE, "lp-charset",
- r->charset);
+ papiAttributeListAddLPString(&j->attributes, PAPI_ATTR_REPLACE,
+ "lp-charset", r->charset);
/* modes */
- addLPString(&j->attributes, PAPI_ATTR_REPLACE, "lp-modes", r->modes);
+ papiAttributeListAddLPString(&j->attributes, PAPI_ATTR_REPLACE,
+ "lp-modes", r->modes);
/* title */
- addLPString(&j->attributes, PAPI_ATTR_REPLACE, "job-name", r->title);
+ papiAttributeListAddLPString(&j->attributes, PAPI_ATTR_REPLACE,
+ "job-name", r->title);
/* input_type */
/* user */
- addLPString(&j->attributes, PAPI_ATTR_REPLACE,
+ papiAttributeListAddLPString(&j->attributes, PAPI_ATTR_REPLACE,
"job-originating-user-name", r->user);
/* outcome */
- papiAttributeListAddInteger(&j->attributes, PAPI_ATTR_REPLACE,
- "lpsched-outcome", r->outcome);
lpsched_request_outcome_to_attributes(&j->attributes, r->outcome);
- /* version */
- papiAttributeListAddInteger(&j->attributes, PAPI_ATTR_REPLACE,
- "lpsched-version", r->version);
-
/* constants, (should be derived from options) */
papiAttributeListAddInteger(&j->attributes, PAPI_ATTR_REPLACE,
"number-up", 1);
@@ -476,7 +439,7 @@ job_status_to_attributes(job_t *job, char *req_id, char *user, char *slabel,
char buf[BUFSIZ];
char *p;
- addLPString(&job->attributes, PAPI_ATTR_REPLACE,
+ papiAttributeListAddLPString(&job->attributes, PAPI_ATTR_REPLACE,
"job-originating-user-name", user);
papiAttributeListAddInteger(&job->attributes, PAPI_ATTR_REPLACE,
"job-k-octets", size/1024);
@@ -486,10 +449,12 @@ job_status_to_attributes(job_t *job, char *req_id, char *user, char *slabel,
papiAttributeListAddInteger(&job->attributes, PAPI_ATTR_REPLACE,
"job-id", atoi(++p));
}
- snprintf(buf, sizeof (buf), "lpsched://%s/%d", destination, atoi(p));
+ snprintf(buf, sizeof (buf), "lpsched://localhost/printers/%s/%d",
+ destination, atoi(p));
papiAttributeListAddString(&job->attributes, PAPI_ATTR_REPLACE,
"job-uri", buf);
- snprintf(buf, sizeof (buf), "lpsched://%s", destination);
+ snprintf(buf, sizeof (buf), "lpsched://localhost/printers/%s",
+ destination);
papiAttributeListAddString(&job->attributes, PAPI_ATTR_REPLACE,
"job-printer-uri", buf);
papiAttributeListAddInteger(&job->attributes, PAPI_ATTR_REPLACE,
@@ -498,25 +463,26 @@ job_status_to_attributes(job_t *job, char *req_id, char *user, char *slabel,
"output-device-assigned", destination);
papiAttributeListAddString(&job->attributes, PAPI_ATTR_REPLACE,
"printer-name", destination);
- addLPString(&job->attributes, PAPI_ATTR_REPLACE, "media", form);
+ papiAttributeListAddLPString(&job->attributes, PAPI_ATTR_REPLACE,
+ "form", form);
lpsched_request_outcome_to_attributes(&job->attributes, state);
papiAttributeListAddInteger(&job->attributes, PAPI_ATTR_REPLACE,
"time-at-creation", date);
- addLPString(&job->attributes, PAPI_ATTR_REPLACE,
+ papiAttributeListAddLPString(&job->attributes, PAPI_ATTR_REPLACE,
"lpsched-request-id", req_id);
- addLPString(&job->attributes, PAPI_ATTR_REPLACE,
+ papiAttributeListAddLPString(&job->attributes, PAPI_ATTR_REPLACE,
"lp-charset", charset);
papiAttributeListAddInteger(&job->attributes, PAPI_ATTR_REPLACE,
"lpsched-job-state", state);
papiAttributeListAddInteger(&job->attributes, PAPI_ATTR_REPLACE,
"number-of-intervening-jobs", rank - 1);
- addLPString(&job->attributes, PAPI_ATTR_REPLACE,
+ papiAttributeListAddLPString(&job->attributes, PAPI_ATTR_REPLACE,
"lpsched-file", file);
- addLPString(&job->attributes, PAPI_ATTR_EXCL,
+ papiAttributeListAddLPString(&job->attributes, PAPI_ATTR_EXCL,
"job-name", file);
- addLPString(&job->attributes, PAPI_ATTR_EXCL,
+ papiAttributeListAddLPString(&job->attributes, PAPI_ATTR_EXCL,
"tsol-sensitivity-label", slabel);
}
diff --git a/usr/src/cmd/lp/lib/papi/lpsched-misc.c b/usr/src/cmd/lp/lib/papi/lpsched-misc.c
index 0ed7895fbb..97047a8357 100644
--- a/usr/src/cmd/lp/lib/papi/lpsched-misc.c
+++ b/usr/src/cmd/lp/lib/papi/lpsched-misc.c
@@ -2,9 +2,8 @@
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
+ * 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.
@@ -20,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -36,7 +35,8 @@
papi_status_t
-addLPString(papi_attribute_t ***list, int flags, char *name, char *value)
+papiAttributeListAddLPString(papi_attribute_t ***list, int flags, char *name,
+ char *value)
{
papi_status_t result = PAPI_BAD_ARGUMENT;
@@ -47,7 +47,7 @@ addLPString(papi_attribute_t ***list, int flags, char *name, char *value)
}
papi_status_t
-addLPStrings(papi_attribute_t ***list, int flags, char *name,
+papiAttributeListAddLPStrings(papi_attribute_t ***list, int flags, char *name,
char **values)
{
papi_status_t result = PAPI_OK;
@@ -64,8 +64,45 @@ addLPStrings(papi_attribute_t ***list, int flags, char *name,
return (result);
}
+void
+papiAttributeListGetLPString(papi_attribute_t **attributes, char *key,
+ char **string)
+{
+ char *value = NULL;
+
+ papiAttributeListGetString(attributes, NULL, key, &value);
+ if (value != NULL) {
+ if (*string != NULL)
+ free(*string);
+ *string = strdup(value);
+ }
+}
+
+void
+papiAttributeListGetLPStrings(papi_attribute_t **attributes, char *key,
+ char ***strings)
+{
+ papi_status_t status;
+ char **values = NULL;
+ char *value = NULL;
+ void *iter = NULL;
+
+ for (status = papiAttributeListGetString(attributes, &iter,
+ key, &value);
+ status == PAPI_OK;
+ status = papiAttributeListGetString(attributes, &iter,
+ NULL, &value))
+ addlist(&values, value);
+
+ if (values != NULL) {
+ if (*strings != NULL)
+ freelist(*strings);
+ *strings = values;
+ }
+}
+
char *
-printer_name_from_uri_id(const char *uri, int32_t id)
+printer_name_from_uri_id(char *uri, int32_t id)
{
REQUEST *request = NULL;
char *result = "";
diff --git a/usr/src/cmd/lp/lib/papi/lpsched-msgs.c b/usr/src/cmd/lp/lib/papi/lpsched-msgs.c
index 7da01787da..5f5806276b 100644
--- a/usr/src/cmd/lp/lib/papi/lpsched-msgs.c
+++ b/usr/src/cmd/lp/lib/papi/lpsched-msgs.c
@@ -2,9 +2,8 @@
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
+ * 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.
@@ -20,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -33,12 +32,14 @@
#include <libintl.h>
#include <string.h>
#include <stdlib.h>
+#include <errno.h>
/* lpsched include files */
#include "lp.h"
#include "msgs.h"
#include "printers.h"
+#include "class.h"
#include <papi_impl.h>
@@ -139,6 +140,8 @@ lpsched_status_to_papi_status(int status)
return (PAPI_SERVICE_UNAVAILABLE);
case M2LATE:
return (PAPI_GONE);
+ case MBUSY:
+ return (PAPI_PRINTER_BUSY);
case MOK:
case MOKMORE:
return (PAPI_OK);
@@ -233,7 +236,7 @@ lpsched_commit_job(papi_service_t svc, char *job, char **tmp)
}
papi_status_t
-lpsched_start_change(papi_service_t svc, const char *printer, int32_t job_id,
+lpsched_start_change(papi_service_t svc, char *printer, int32_t job_id,
char **tmp)
{
papi_status_t result = PAPI_OK;
@@ -264,7 +267,7 @@ lpsched_start_change(papi_service_t svc, const char *printer, int32_t job_id,
}
papi_status_t
-lpsched_end_change(papi_service_t svc, const char *printer, int32_t job_id)
+lpsched_end_change(papi_service_t svc, char *printer, int32_t job_id)
{
papi_status_t result = PAPI_OK;
short status = MOK;
@@ -294,7 +297,62 @@ lpsched_end_change(papi_service_t svc, const char *printer, int32_t job_id)
}
papi_status_t
-lpsched_enable_printer(papi_service_t svc, const char *printer)
+lpsched_accept_printer(papi_service_t svc, char *printer)
+{
+ papi_status_t result = PAPI_OK;
+ short status;
+ char *req_id;
+ char *dest;
+
+ if ((svc == NULL) || (printer == NULL))
+ return (PAPI_BAD_ARGUMENT);
+
+ dest = printer_name_from_uri_id(printer, -1);
+ if ((snd_msg(svc, S_ACCEPT_DEST, dest) < 0) ||
+ (rcv_msg(svc, R_ACCEPT_DEST, &status, &req_id) < 0))
+ status = MTRANSMITERR;
+ free(dest);
+
+ if ((status != MOK) && (status != MERRDEST)) {
+ detailed_error(svc, "%s: %s", printer,
+ lpsched_status_string(status));
+ result = lpsched_status_to_papi_status(status);
+ }
+
+ return (result);
+}
+
+papi_status_t
+lpsched_reject_printer(papi_service_t svc, char *printer, char *message)
+{
+ papi_status_t result = PAPI_OK;
+ short status;
+ char *req_id;
+ char *dest;
+
+ if ((svc == NULL) || (printer == NULL))
+ return (PAPI_BAD_ARGUMENT);
+
+ if (message == NULL)
+ message = "stopped by user";
+
+ dest = printer_name_from_uri_id(printer, -1);
+ if ((snd_msg(svc, S_REJECT_DEST, dest, message, 0) < 0) ||
+ (rcv_msg(svc, R_REJECT_DEST, &status, &req_id) < 0))
+ status = MTRANSMITERR;
+ free(dest);
+
+ if ((status != MOK) && (status != MERRDEST)) {
+ detailed_error(svc, "%s: %s", printer,
+ lpsched_status_string(status));
+ result = lpsched_status_to_papi_status(status);
+ }
+
+ return (result);
+}
+
+papi_status_t
+lpsched_enable_printer(papi_service_t svc, char *printer)
{
papi_status_t result = PAPI_OK;
short status;
@@ -320,8 +378,7 @@ lpsched_enable_printer(papi_service_t svc, const char *printer)
}
papi_status_t
-lpsched_disable_printer(papi_service_t svc, const char *printer,
- const char *message)
+lpsched_disable_printer(papi_service_t svc, char *printer, char *message)
{
papi_status_t result = PAPI_OK;
short status;
@@ -348,3 +405,216 @@ lpsched_disable_printer(papi_service_t svc, const char *printer,
return (result);
}
+
+papi_status_t
+lpsched_load_unload_dest(papi_service_t handle, char *dest, int type)
+{
+ service_t *svc = handle;
+ papi_status_t result;
+ short status = MOK;
+
+ /* tell the scheduler it's going */
+ if (snd_msg(svc, type, dest, "", "") < 0)
+ return (PAPI_SERVICE_UNAVAILABLE);
+
+ switch (type) {
+ case S_LOAD_PRINTER:
+ type = R_LOAD_PRINTER;
+ break;
+ case S_UNLOAD_PRINTER:
+ type = R_UNLOAD_PRINTER;
+ break;
+ case S_LOAD_CLASS:
+ type = R_LOAD_CLASS;
+ break;
+ case S_UNLOAD_CLASS:
+ type = R_UNLOAD_CLASS;
+ }
+
+ if (rcv_msg(svc, type, &status) < 0)
+ return (PAPI_SERVICE_UNAVAILABLE);
+
+ result = lpsched_status_to_papi_status(status);
+
+ return (result);
+}
+
+papi_status_t
+lpsched_remove_class(papi_service_t handle, char *dest)
+{
+ papi_status_t result;
+
+ /* tell the scheduler it's going */
+ result = lpsched_load_unload_dest(handle, dest, S_UNLOAD_CLASS);
+
+ if (result == PAPI_OK) {
+ /* remove the scheduler config files */
+ if (delclass(dest) == -1)
+ result = PAPI_SERVICE_UNAVAILABLE;
+ }
+
+ return (result);
+}
+
+static void
+remove_from_class(papi_service_t handle, char *dest, CLASS *cls)
+{
+ if (dellist(&cls->members, dest) == 0) {
+ if (cls->members != NULL) {
+ if (putclass(cls->name, cls) == 0)
+ (void) lpsched_load_unload_dest(handle,
+ cls->name, S_LOAD_CLASS);
+ } else
+ (void) lpsched_remove_class(handle, cls->name);
+ }
+}
+
+papi_status_t
+lpsched_remove_printer(papi_service_t handle, char *dest)
+{
+
+ papi_status_t result;
+
+ /* tell the scheduler it's going */
+ result = lpsched_load_unload_dest(handle, dest, S_UNLOAD_PRINTER);
+
+ if (result == PAPI_OK) {
+ CLASS *cls;
+ char *dflt;
+
+ /* remove the scheduler config files */
+ if (delprinter(dest) == -1)
+ return (PAPI_SERVICE_UNAVAILABLE);
+
+ /* remove from any classes */
+ while ((cls = getclass(NAME_ALL)) != NULL)
+ if (searchlist(dest, cls->members) != 0)
+ remove_from_class(handle, dest, cls);
+
+ /* reset the default if it needs to be done */
+ if (((dflt = getdefault()) != NULL) &&
+ (strcmp(dflt, dest) == 0))
+ putdefault(NAME_NONE);
+ }
+
+ return (result);
+}
+
+papi_status_t
+lpsched_add_modify_class(papi_service_t handle, char *dest,
+ papi_attribute_t **attributes)
+{
+ papi_status_t result;
+ void *iter = NULL;
+ char **members = NULL;
+ char *member;
+
+ /*
+ * The only attribute that we can modify for a class is the set of
+ * members. Anything else will be ignored.
+ */
+ for (result = papiAttributeListGetString(attributes, &iter,
+ "member-names", &member);
+ result == PAPI_OK;
+ result = papiAttributeListGetString(attributes, &iter,
+ NULL, &member))
+ addlist(&members, member);
+
+ if (members != NULL) {
+ /* modify the configuration file */
+ CLASS class;
+
+ memset(&class, 0, sizeof (class));
+ class.name = dest;
+ class.members = members;
+
+ if (putclass(dest, &class) == -1) {
+ if ((errno == EPERM) || (errno == EACCES))
+ result = PAPI_NOT_AUTHORIZED;
+ else
+ result = PAPI_NOT_POSSIBLE;
+ } else
+ result = PAPI_OK;
+
+ freelist(members);
+ } else
+ result = PAPI_ATTRIBUTES;
+
+ /* tell the scheduler about the changes */
+ if (result == PAPI_OK)
+ result = lpsched_load_unload_dest(handle, dest, S_LOAD_CLASS);
+
+ return (result);
+}
+
+papi_status_t
+lpsched_add_printer(papi_service_t handle, char *dest,
+ papi_attribute_t **attributes)
+{
+ PRINTER *p;
+ papi_status_t result = PAPI_TEMPORARY_ERROR;
+
+ if ((p = calloc(1, sizeof (*p))) != NULL) {
+ p->name = strdup(dest);
+ p->banner = BAN_ALWAYS;
+ p->interface = strdup("/usr/lib/lp/model/uri");
+ p->fault_alert.shcmd = strdup("mail");
+
+ attributes_to_printer(attributes, p);
+
+ if (putprinter(dest, p) == -1) {
+ if ((errno == EPERM) || (errno == EACCES))
+ result = PAPI_NOT_AUTHORIZED;
+ else
+ result = PAPI_NOT_POSSIBLE;
+ } else
+ result = PAPI_OK;
+
+ freeprinter(p);
+ }
+
+ /* tell the scheduler about the changes */
+ if (result == PAPI_OK)
+ result = lpsched_load_unload_dest(handle, dest, S_LOAD_PRINTER);
+
+ return (result);
+}
+
+papi_status_t
+lpsched_add_modify_printer(papi_service_t handle, char *dest,
+ papi_attribute_t **attributes, int type)
+{
+ PRINTER *p;
+ papi_status_t result;
+
+ if (type == 0) {
+ if ((p = calloc(1, sizeof (*p))) != NULL) {
+ p->name = strdup(dest);
+ p->banner = BAN_ALWAYS;
+ p->interface = strdup("/usr/lib/lp/model/uri");
+ p->fault_alert.shcmd = strdup("mail");
+ }
+ } else
+ p = getprinter(dest);
+
+ if (p != NULL) {
+ attributes_to_printer(attributes, p);
+
+ if (putprinter(dest, p) == -1) {
+ if ((errno == EPERM) || (errno == EACCES))
+ result = PAPI_NOT_AUTHORIZED;
+ else
+ result = PAPI_NOT_POSSIBLE;
+ } else
+ result = PAPI_OK;
+
+ freeprinter(p);
+ } else
+ result = PAPI_NOT_POSSIBLE;
+
+ /* tell the scheduler about the changes */
+ if (result == PAPI_OK)
+ result = lpsched_load_unload_dest(handle, dest, S_LOAD_PRINTER);
+
+ return (result);
+}
diff --git a/usr/src/cmd/lp/lib/papi/lpsched-printers.c b/usr/src/cmd/lp/lib/papi/lpsched-printers.c
index d425c1bef7..408af31962 100644
--- a/usr/src/cmd/lp/lib/papi/lpsched-printers.c
+++ b/usr/src/cmd/lp/lib/papi/lpsched-printers.c
@@ -2,9 +2,8 @@
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
+ * 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.
@@ -20,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -31,12 +30,12 @@
#include <stdlib.h>
#include <libintl.h>
#include <unistd.h>
+#include <string.h>
#include <sys/utsname.h>
#include <papi_impl.h>
#include "class.h"
-
void
lpsched_printer_status_to_attributes(papi_attribute_t ***attrs,
unsigned short status)
@@ -73,25 +72,9 @@ lpsched_printer_status_to_attributes(papi_attribute_t ***attrs,
papiAttributeListAddBoolean(attrs, PAPI_ATTR_REPLACE,
"printer-is-accepting-jobs",
((status & PS_REJECTED) != PS_REJECTED));
- papiAttributeListAddInteger(attrs, PAPI_ATTR_REPLACE,
- "lpsched-status", status);
papiAttributeListAddBoolean(attrs, PAPI_ATTR_REPLACE,
"printer-is-processing-jobs",
((status & PS_DISABLED) != PS_DISABLED));
- papiAttributeListAddBoolean(attrs, PAPI_ATTR_REPLACE,
- "lpsched-faulted", (status & PS_FAULTED));
- papiAttributeListAddBoolean(attrs, PAPI_ATTR_REPLACE,
- "lpsched-busy", (status & PS_BUSY));
- papiAttributeListAddBoolean(attrs, PAPI_ATTR_REPLACE,
- "lpsched-later", (status & PS_LATER));
- papiAttributeListAddBoolean(attrs, PAPI_ATTR_REPLACE,
- "lpsched-remote", (status & PS_REMOTE));
- papiAttributeListAddBoolean(attrs, PAPI_ATTR_REPLACE,
- "lpsched-show-fault", (status & PS_SHOW_FAULT));
- papiAttributeListAddBoolean(attrs, PAPI_ATTR_REPLACE,
- "lpsched-use-as-key", (status & PS_USE_AS_KEY));
- papiAttributeListAddBoolean(attrs, PAPI_ATTR_REPLACE,
- "lpsched-form-fault", (status & PS_FORM_FAULT));
}
void
@@ -113,12 +96,23 @@ lpsched_printer_defaults(papi_attribute_t ***attributes)
"job-priority-default", 20);
papiAttributeListAddRange(attributes, PAPI_ATTR_REPLACE,
"copies-supported", 1, 65535);
+ papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE,
+ "copies-default", 1);
papiAttributeListAddBoolean(attributes, PAPI_ATTR_REPLACE,
"page-ranges-supported", PAPI_TRUE);
papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE,
"number-up-supported", 1);
papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE,
"number-up-default", 1);
+ papiAttributeListAddString(attributes, PAPI_ATTR_REPLACE,
+ "job-hold-until-supported", "no-hold");
+ papiAttributeListAddString(attributes, PAPI_ATTR_APPEND,
+ "job-hold-until-supported", "indefinite");
+ papiAttributeListAddString(attributes, PAPI_ATTR_REPLACE,
+ "job-hold-until-default", "no-hold");
+ papiAttributeListAddString(attributes, PAPI_ATTR_REPLACE,
+ "document-format-default", "application/octet-stream");
+
}
papi_status_t
@@ -128,6 +122,7 @@ lpsched_printer_configuration_to_attributes(service_t *svc, printer_t *p,
PRINTER *tmp;
char buf[BUFSIZ+1];
struct utsname sysname;
+ char **allowed = NULL, **denied = NULL;
if ((svc == NULL) || (p == NULL) || (dest == NULL))
return (PAPI_BAD_ARGUMENT);
@@ -140,12 +135,13 @@ lpsched_printer_configuration_to_attributes(service_t *svc, printer_t *p,
}
/* name */
- addLPString(&p->attributes, PAPI_ATTR_REPLACE,
+ papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
"printer-name", tmp->name);
if (tmp->name != NULL) {
char uri[BUFSIZ];
- snprintf(uri, sizeof (uri), "lpsched://%s", tmp->name);
+ snprintf(uri, sizeof (uri), "lpsched://localhost/printers/%s",
+ tmp->name);
papiAttributeListAddString(&p->attributes, PAPI_ATTR_REPLACE,
"printer-uri-supported", uri);
}
@@ -166,53 +162,53 @@ lpsched_printer_configuration_to_attributes(service_t *svc, printer_t *p,
int i;
for (i = 0; tmp->input_types[i] != NULL; i++)
- addLPString(&p->attributes,
+ papiAttributeListAddLPString(&p->attributes,
PAPI_ATTR_APPEND, "document-format-supported",
lp_type_to_mime_type(tmp->input_types[i]));
}
/* description */
- addLPString(&p->attributes, PAPI_ATTR_REPLACE,
+ papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
"printer-info", tmp->description);
/* add lpsched specific attributes */
- addLPString(&p->attributes, PAPI_ATTR_REPLACE,
+ papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
"device-uri", tmp->device);
- addLPString(&p->attributes, PAPI_ATTR_REPLACE,
+ papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
"lpsched-dial-info", tmp->dial_info);
- addLPString(&p->attributes, PAPI_ATTR_REPLACE,
+ papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
"lpsched-fault-recovery", tmp->fault_rec);
- addLPString(&p->attributes, PAPI_ATTR_REPLACE,
+ papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
"lpsched-interface-script", tmp->interface);
- addLPString(&p->attributes, PAPI_ATTR_REPLACE,
+ papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
"lpsched-data-rate", tmp->speed);
- addLPString(&p->attributes, PAPI_ATTR_REPLACE,
+ papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
"lpsched-stty", tmp->stty);
- addLPString(&p->attributes, PAPI_ATTR_REPLACE,
- "lpsched-remote", tmp->remote);
papiAttributeListAddBoolean(&p->attributes, PAPI_ATTR_REPLACE,
"lpsched-login-term", tmp->login);
papiAttributeListAddBoolean(&p->attributes, PAPI_ATTR_REPLACE,
"lpsched-daisy", tmp->daisy);
- addLPStrings(&p->attributes, PAPI_ATTR_REPLACE,
+ papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE,
"lpsched-charsets", tmp->char_sets);
#ifdef CAN_DO_MODULES
- addLPStrings(&p->attributes, PAPI_ATTR_REPLACE,
+ papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE,
"lpsched-modules", tmp->modules);
#endif /* CAN_DO_MODULES */
- addLPStrings(&p->attributes, PAPI_ATTR_REPLACE,
+ papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE,
"lpsched-options", tmp->options);
- addLPStrings(&p->attributes, PAPI_ATTR_REPLACE,
+ papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE,
"lpsched-printer-type", tmp->printer_types);
- addLPString(&p->attributes, PAPI_ATTR_REPLACE,
+ if (tmp->fault_alert.shcmd != NULL) {
+ papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
"lpsched-fault-alert-command",
tmp->fault_alert.shcmd);
- papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
+ papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
"lpsched-fault-alert-threshold",
tmp->fault_alert.Q);
- papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
+ papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
"lpsched-fault-alert-interval",
tmp->fault_alert.W);
+ }
papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
"lpsched-cpi-value", tmp->cpi.val);
papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
@@ -229,6 +225,14 @@ lpsched_printer_configuration_to_attributes(service_t *svc, printer_t *p,
"lpsched-pwid-value", tmp->pwid.val);
papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
"lpsched-pwid-unit", tmp->pwid.sc);
+
+ /* allow/deny list */
+ load_userprinter_access(dest, &allowed, &denied);
+ papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE,
+ "requesting-user-name-allowed", allowed);
+ papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE,
+ "requesting-user-name-denied", denied);
+
#ifdef LP_USE_PAPI_ATTR
if (tmp->ppd != NULL) {
int fd;
@@ -242,12 +246,14 @@ lpsched_printer_configuration_to_attributes(service_t *svc, printer_t *p,
snprintf(buf, sizeof (buf), "file://%s%s/ppd/%s.ppd",
sysname.nodename, ETCDIR, tmp->name);
papiAttributeListAddString(&p->attributes, PAPI_ATTR_REPLACE,
- "lpsched-printer-ppd-uri", buf);
+ "ppd-file-uri", buf);
snprintf(buf, sizeof (buf), "file://%s%s",
sysname.nodename, tmp->ppd);
papiAttributeListAddString(&p->attributes, PAPI_ATTR_REPLACE,
"lpsched-printer-configure-ppd-uri", buf);
+ papiAttributeListAddString(&p->attributes, PAPI_ATTR_REPLACE,
+ "lpsched-ppd-source-path", tmp->ppd);
snprintf(buf, sizeof (buf), "%s/ppd/%s.ppd", ETCDIR, tmp->name);
@@ -255,56 +261,7 @@ lpsched_printer_configuration_to_attributes(service_t *svc, printer_t *p,
* We don't return error on any of the error conditions, we just
* silently return without adding the attribute.
*/
- if (((fd = open(buf, O_RDONLY)) >= 0) &&
- (fstat(fd, &sbuf) == 0)) {
- char *contents;
-
- if ((contents = malloc(sbuf.st_size + 1)) != NULL) {
- int pos = 0, rd, rdsize;
-
- rdsize = sbuf.st_blksize;
-
- while (rd = read(fd, contents + pos, rdsize)) {
- if (rd < 0) {
- if (errno == EINTR) {
- continue;
- } else {
- break;
- }
- }
- pos += rd;
-
- /*
- * Don't write past the end of our
- * buffer. This is paranoid, in case
- * the file increased size while we were
- * reading it.
- */
- if (pos + rdsize > sbuf.st_size) {
- rdsize = sbuf.st_size - pos;
- }
- }
-
- /* File didn't change size while reading. */
- if (pos + rd == sbuf.st_size) {
- /*
- * Terminate the buffer and set
- * attribute. This assume that there
- * are no null bytes in the ppd file.
- */
- contents[pos + rd] = '\0';
-
- papiAttributeListAddString(
- &p->attributes,
- PAPI_ATTR_REPLACE,
- "lpsched-printer-ppd-contents",
- contents);
- }
-
- free(contents);
- }
- }
- close(fd);
+ PPDFileToAttributesList(&p->attributes, buf);
}
#endif
@@ -315,25 +272,25 @@ lpsched_printer_configuration_to_attributes(service_t *svc, printer_t *p,
papi_status_t
printer_status_to_attributes(printer_t *p, char *printer, char *form,
- char *character_set, char *reject_reason, char *disable_reason,
+ char *character_set, char *disable_reason, char *reject_reason,
short status, char *request_id,
- long enable_date, long reject_date)
+ long disable_date, long reject_date)
{
if (p == NULL)
return (PAPI_BAD_ARGUMENT);
- addLPString(&p->attributes, PAPI_ATTR_REPLACE,
- "media-ready", form);
- addLPString(&p->attributes, PAPI_ATTR_REPLACE,
+ papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
+ "form-ready", form);
+ papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
"lpsched-active-job", request_id);
- addLPString(&p->attributes, PAPI_ATTR_REPLACE,
+ papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
"lpsched-mounted-char-set", character_set);
- addLPString(&p->attributes, PAPI_ATTR_REPLACE,
- "printer-reject-reason", reject_reason);
- addLPString(&p->attributes, PAPI_ATTR_REPLACE,
- "printer-disable-reason", disable_reason);
+ papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
+ "lpsched-disable-reason", disable_reason);
papiAttributeListAddDatetime(&p->attributes, PAPI_ATTR_REPLACE,
- "lpsched-enable-date", enable_date);
+ "lpsched-disable-date", disable_date);
+ papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
+ "lpsched-reject-reason", reject_reason);
papiAttributeListAddDatetime(&p->attributes, PAPI_ATTR_REPLACE,
"lpsched-reject-date", reject_date);
@@ -378,12 +335,13 @@ lpsched_class_configuration_to_attributes(service_t *svc, printer_t *p,
}
/* name */
- addLPString(&p->attributes, PAPI_ATTR_REPLACE,
+ papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
"printer-name", tmp->name);
if (tmp->name != NULL) {
char uri[BUFSIZ];
- snprintf(uri, sizeof (uri), "lpsched://%s", tmp->name);
+ snprintf(uri, sizeof (uri), "lpsched://localhost/printers/%s",
+ tmp->name);
papiAttributeListAddString(&p->attributes, PAPI_ATTR_REPLACE,
"printer-uri-supported", uri);
}
@@ -410,8 +368,8 @@ class_status_to_attributes(printer_t *p, char *printer, short status,
if (p == NULL)
return (PAPI_BAD_ARGUMENT);
- addLPString(&p->attributes, PAPI_ATTR_REPLACE,
- "printer-reject-reason", reject_reason);
+ papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
+ "lpsched-reject-reason", reject_reason);
papiAttributeListAddDatetime(&p->attributes, PAPI_ATTR_REPLACE,
"lpsched-reject-date", reject_date);
@@ -432,3 +390,70 @@ class_status_to_attributes(printer_t *p, char *printer, short status,
return (PAPI_OK);
}
+
+papi_status_t
+attributes_to_printer(papi_attribute_t **attributes, PRINTER *tmp)
+{
+ papi_status_t status;
+ void *iter = NULL;
+ char *string = NULL;
+ int flags;
+ char **list = NULL;
+
+ /* banner needs some conversion to the bitfield */
+ iter = NULL, string = NULL; flags = 0;
+ for (status = papiAttributeListGetString(attributes, &iter,
+ "job-sheets-supported", &string);
+ status == PAPI_OK;
+ status = papiAttributeListGetString(attributes, &iter,
+ NULL, &string))
+ if (strcasecmp(string, "none") == 0)
+ flags |= BAN_NEVER;
+ else if (strcasecmp(string, "standard") == 0)
+ flags |= BAN_ALWAYS;
+ if (flags != 0)
+ tmp->banner = flags;
+
+ /* input_types needs mime-type conversion */
+ iter = NULL, string = NULL; list = NULL;
+ for (status = papiAttributeListGetString(attributes, &iter,
+ "document-format-supported", &string);
+ status == PAPI_OK;
+ status = papiAttributeListGetString(attributes, &iter,
+ NULL, &string))
+ addlist(&list, mime_type_to_lp_type(string));
+ if (list != NULL) {
+ if (tmp->input_types != NULL)
+ freelist(tmp->input_types);
+ tmp->input_types = list;
+ }
+
+ papiAttributeListGetLPString(attributes,
+ "device-uri", &tmp->device);
+ papiAttributeListGetLPString(attributes,
+ "printer-info", &tmp->description);
+ papiAttributeListGetLPString(attributes,
+ "lpsched-dial-info", &tmp->dial_info);
+ papiAttributeListGetLPString(attributes,
+ "lpsched-fault-recovery", &tmp->fault_rec);
+ papiAttributeListGetLPString(attributes,
+ "lpsched-interface-script", &tmp->interface);
+ papiAttributeListGetLPString(attributes,
+ "lpsched-data-rate", &tmp->speed);
+ papiAttributeListGetLPString(attributes,
+ "lpsched-stty", &tmp->stty);
+ papiAttributeListGetLPStrings(attributes,
+ "lpsched-charsets", &tmp->char_sets);
+ papiAttributeListGetLPStrings(attributes,
+ "lpsched-printer-types", &tmp->printer_types);
+ papiAttributeListGetLPStrings(attributes,
+ "lpsched-options", &tmp->options);
+ papiAttributeListGetLPStrings(attributes,
+ "lpsched-modules", &tmp->modules);
+#ifdef LP_USE_PAPI_ATTR
+ papiAttributeListGetLPString(attributes,
+ "lpsched-printer-ppd-uri", &tmp->ppd);
+#endif
+
+ return (PAPI_OK);
+}
diff --git a/usr/src/cmd/lp/lib/papi/lpsched-service.c b/usr/src/cmd/lp/lib/papi/lpsched-service.c
index 8b6d6b944b..33f0082944 100644
--- a/usr/src/cmd/lp/lib/papi/lpsched-service.c
+++ b/usr/src/cmd/lp/lib/papi/lpsched-service.c
@@ -2,9 +2,8 @@
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
+ * 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.
@@ -20,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -36,13 +35,13 @@
void
-lpsched_service_information(printer_t *p)
+lpsched_service_information(papi_attribute_t ***attrs)
{
FORM form;
while (getform(NAME_ALL, &form, (FALERT *)0, (FILE **)0) != -1) {
- papiAttributeListAddString(&p->attributes, PAPI_ATTR_APPEND,
- "media-supported", form.name);
+ papiAttributeListAddString(attrs, PAPI_ATTR_APPEND,
+ "form-supported", form.name);
freeform(&form);
}
}
diff --git a/usr/src/cmd/lp/lib/papi/mapfile b/usr/src/cmd/lp/lib/papi/mapfile
new file mode 100644
index 0000000000..a10fae2acf
--- /dev/null
+++ b/usr/src/cmd/lp/lib/papi/mapfile
@@ -0,0 +1,151 @@
+#
+# 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.
+#
+# ident "%Z%%M% %I% %E% SMI"
+#
+# Generic interface definition for usr/src/cmd/lp/lib/papi
+#
+# For information regarding the establishment of versioned definitions see:
+# The Linker and Libraries Manual (version 2.5 or greater)
+# This is part of the Developers Guide in the Answerbook. Specifically refer
+# to Chapter 2 under section "Defining Additional Symbols" through section
+# "Reducing Symbol Scope", and Chapter 5 "Versioning".
+#
+# For specific OSNET rules for the modification (evolution) of these version
+# definitions see:
+# Policy for Shared Library Version Names and Interface Definitions
+
+SUNW_1.0 {
+ global:
+ # PAPI Attribute Calls
+ papiAttributeListAdd;
+ papiAttributeListAddValue = FUNCTION FILTER libpapi-common.so ;
+ papiAttributeListAddBoolean = FUNCTION FILTER libpapi-common.so ;
+ papiAttributeListAddCollection = FUNCTION FILTER libpapi-common.so ;
+ papiAttributeListAddDatetime = FUNCTION FILTER libpapi-common.so ;
+ papiAttributeListAddInteger = FUNCTION FILTER libpapi-common.so ;
+ papiAttributeListAddMetadata = FUNCTION FILTER libpapi-common.so ;
+ papiAttributeListAddRange = FUNCTION FILTER libpapi-common.so ;
+ papiAttributeListAddResolution = FUNCTION FILTER libpapi-common.so ;
+ papiAttributeListAddString = FUNCTION FILTER libpapi-common.so ;
+ papiAttributeListDelete = FUNCTION FILTER libpapi-common.so ;
+ papiAttributeListGetValue = FUNCTION FILTER libpapi-common.so ;
+ papiAttributeListGetNext = FUNCTION FILTER libpapi-common.so ;
+ papiAttributeListFind = FUNCTION FILTER libpapi-common.so ;
+ papiAttributeListGetBoolean = FUNCTION FILTER libpapi-common.so ;
+ papiAttributeListGetCollection = FUNCTION FILTER libpapi-common.so ;
+ papiAttributeListGetDatetime = FUNCTION FILTER libpapi-common.so ;
+ papiAttributeListGetInteger = FUNCTION FILTER libpapi-common.so ;
+ papiAttributeListGetMetadata = FUNCTION FILTER libpapi-common.so ;
+ papiAttributeListGetRange = FUNCTION FILTER libpapi-common.so ;
+ papiAttributeListGetResolution = FUNCTION FILTER libpapi-common.so ;
+ papiAttributeListGetString = FUNCTION FILTER libpapi-common.so ;
+ papiAttributeListFromString = FUNCTION FILTER libpapi-common.so ;
+ papiAttributeListToString = FUNCTION FILTER libpapi-common.so ;
+ papiAttributeListFree = 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 = FUNCTION FILTER libpapi-common.so ;
+ papiJobPromote;
+ papiJobGetAttributeList;
+ papiJobGetPrinterName;
+ papiJobGetId;
+ papiJobGetJobTicket = FUNCTION FILTER libpapi-common.so ;
+ papiJobFree;
+ papiJobListFree;
+
+ # Misc. PAPI Calls
+ papiStatusString = FUNCTION FILTER libpapi-common.so ;
+ papiLibrarySupportedCall;
+ papiLibrarySupportedCalls;
+};
+
+SUNWprivate_1.0 {
+ global:
+ papiServiceSetPeer; # used by to pass peer connection
+ papiJobCreate;
+ papiJobStreamAdd;
+ papiJobCommit;
+
+ # Misc. supporting calls
+ # URI
+ uri_from_string = FUNCTION FILTER libpapi-common.so ;
+ uri_to_string = FUNCTION FILTER libpapi-common.so ;
+ uri_free = FUNCTION FILTER libpapi-common.so ;
+ # list
+ list_remove = FUNCTION FILTER libpapi-common.so ;
+ list_append = FUNCTION FILTER libpapi-common.so ;
+ list_concatenate = FUNCTION FILTER libpapi-common.so ;
+
+ # extra Attribute Calls
+ copy_attributes = FUNCTION FILTER libpapi-common.so ;
+ split_and_copy_attributes = FUNCTION FILTER libpapi-common.so ;
+ papiAttributeListPrint = FUNCTION FILTER libpapi-common.so ;
+
+ local:
+ *;
+};
diff --git a/usr/src/cmd/lp/lib/papi/mapfile-vers b/usr/src/cmd/lp/lib/papi/mapfile-vers
deleted file mode 100644
index 2bddef28d0..0000000000
--- a/usr/src/cmd/lp/lib/papi/mapfile-vers
+++ /dev/null
@@ -1,125 +0,0 @@
-#
-# Copyright 2006 Sun Microsystems, Inc. All rights reserved.
-# Use is subject to license terms.
-#
-# ident "%Z%%M% %I% %E% SMI"
-#
-# 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
-#
-#
-# Generic interface definition for usr/src/cmd/lp/lib/papi
-#
-# For information regarding the establishment of versioned definitions see:
-# The Linker and Libraries Manual (version 2.5 or greater)
-# This is part of the Developers Guide in the Answerbook. Specifically refer
-# to Chapter 2 under section "Defining Additional Symbols" through section
-# "Reducing Symbol Scope", and Chapter 5 "Versioning".
-#
-# For specific OSNET rules for the modification (evolution) of these version
-# definitions see:
-# Policy for Shared Library Version Names and Interface Definitions
-
-
-SUNWprivate_1.1 {
- global:
-
- papiAttributeListAdd;
- papiAttributeListAddString;
- papiAttributeListAddInteger;
- papiAttributeListAddBoolean;
- papiAttributeListAddRange;
- papiAttributeListAddResolution;
- papiAttributeListAddDatetime;
- papiAttributeListAddCollection;
- papiAttributeListDelete;
- papiAttributeListGetValue;
- papiAttributeListGetString;
- papiAttributeListGetInteger;
- papiAttributeListGetBoolean;
- papiAttributeListGetRange;
- papiAttributeListGetResolution;
- papiAttributeListGetDatetime;
- papiAttributeListGetCollection;
- papiAttributeListFree;
- papiAttributeListFind;
- papiAttributeListGetNext;
- papiAttributeListFromString;
- papiAttributeListToString;
-
- papiServiceCreate;
- papiServiceDestroy;
- papiServiceSetPeer; # used by to pass peer connection
- papiServiceSetUserName;
- papiServiceSetPassword;
- papiServiceSetEncryption;
- papiServiceSetAuthCB;
- papiServiceSetAppData;
- papiServiceGetUserName;
- papiServiceGetPassword;
- papiServiceGetEncryption;
- papiServiceGetAppData;
- papiServiceGetServiceName;
- papiServiceGetStatusMessage;
-
- papiPrintersList;
- papiPrinterQuery;
- papiPrinterModify;
- papiPrinterPause;
- papiPrinterResume;
- papiPrinterPurgeJobs;
- papiPrinterListJobs;
- papiPrinterGetAttributeList;
- papiPrinterFree;
- papiPrinterListFree;
-
- papiJobSubmit;
- papiJobSubmitByReference;
- papiJobValidate;
- papiJobStreamOpen;
- papiJobStreamWrite;
- papiJobStreamClose;
- papiJobQuery;
- papiJobModify;
- papiJobCancel;
- papiJobHold;
- papiJobRelease;
- papiJobRestart;
- papiJobGetAttributeList;
- papiJobGetPrinterName;
- papiJobGetId;
- papiJobGetJobTicket;
- papiJobFree;
- papiJobListFree;
-
- papiStatusString;
- #papiLibrarySupportedCalls;
- #papiLibrarySupportedCall;
-
- papiAttributeListPrint;
- list_append;
-
- papiJobCreate;
- papiJobStreamAdd;
- papiJobCommit;
-
- local:
- *;
-};
-
diff --git a/usr/src/cmd/lp/lib/papi/papi.h b/usr/src/cmd/lp/lib/papi/papi.h
deleted file mode 100644
index 1ba622aa2a..0000000000
--- a/usr/src/cmd/lp/lib/papi/papi.h
+++ /dev/null
@@ -1,411 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (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 2003 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-
-#ifndef _PAPI_H
-#define _PAPI_H
-
-#pragma ident "%Z%%M% %I% %E% SMI"
-
-#include <sys/types.h>
-#include <time.h>
-#include <stdio.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
- * Types
- */
-
-/* service related types */
-typedef void *papi_service_t;
-typedef void *papi_printer_t;
-typedef void *papi_job_t;
-typedef void *papi_stream_t;
-
-typedef enum {
- PAPI_ENCRYPT_IF_REQUESTED, /* Encrypt if requested (TLS upgrade) */
- PAPI_ENCRYPT_NEVER, /* Never encrypt */
- PAPI_ENCRYPT_REQUIRED, /* Encryption required (TLS upgrade) */
- PAPI_ENCRYPT_ALWAYS /* Always encrypt (SSL) */
-} papi_encryption_t;
-
-/* attribute related types */
-typedef enum {
- PAPI_STRING,
- PAPI_INTEGER,
- PAPI_BOOLEAN,
- PAPI_RANGE,
- PAPI_RESOLUTION,
- PAPI_DATETIME,
- PAPI_COLLECTION
-} papi_attribute_value_type_t;
-
-typedef enum {
- PAPI_RES_PER_INCH = 3,
- PAPI_RES_PER_CM
-} papi_resolution_unit_t;
-
-enum { /* for boolean values */
- PAPI_FALSE = 0,
- PAPI_TRUE = 1
-};
-
-#define PAPI_LIST_JOBS_OTHERS 0x0001
-#define PAPI_LIST_JOBS_COMPLETED 0x0002
-#define PAPI_LIST_JOBS_NOT_COMPLETED 0x0004
-#define PAPI_LIST_JOBS_ALL 0xFFFF
-
-typedef struct papi_attribute_s papi_attribute_t;
-
-typedef union {
- char *string; /* PAPI_STRING value */
- int integer; /* PAPI_INTEGER value */
- char boolean; /* PAPI_BOOLEAN value */
- struct { /* PAPI_RANGE value */
- int lower;
- int upper;
- } range;
- struct { /* PAPI_RESOLUTION value */
- int xres;
- int yres;
- papi_resolution_unit_t units;
- } resolution;
- time_t datetime; /* PAPI_DATETIME value */
- papi_attribute_t **collection; /* PAPI_COLLECTION value */
-} papi_attribute_value_t;
-
-struct papi_attribute_s {
- char *name; /* attribute name */
- papi_attribute_value_type_t type; /* type of values */
- papi_attribute_value_t **values; /* list of values */
-};
-
-#define PAPI_ATTR_APPEND 0x0001 /* Add values to attr */
-#define PAPI_ATTR_REPLACE 0x0002 /* Delete existing values, then add */
-#define PAPI_ATTR_EXCL 0x0004 /* Fail if attr exists */
-
-/* job related types */
-typedef enum {
- PAPI_JT_FORMAT_JDF = 0,
- PAPI_JT_FORMAT_PWG = 1
-} papi_jt_format_t;
-
-typedef struct {
- papi_jt_format_t format;
- char *ticket_data;
- char *file_name;
-} papi_job_ticket_t;
-
-/* status related types */
-typedef enum {
- PAPI_OK = 0x0000,
- PAPI_OK_SUBST,
- PAPI_OK_CONFLICT,
- PAPI_OK_IGNORED_SUBSCRIPTIONS,
- PAPI_OK_IGNORED_NOTIFICATIONS,
- PAPI_OK_TOO_MANY_EVENTS,
- PAPI_OK_BUT_CANCEL_SUBSCRIPTION,
- PAPI_REDIRECTION_OTHER_SITE = 0x0300,
- PAPI_BAD_REQUEST = 0x0400,
- PAPI_FORBIDDEN,
- PAPI_NOT_AUTHENTICATED,
- PAPI_NOT_AUTHORIZED,
- PAPI_NOT_POSSIBLE,
- PAPI_TIMEOUT,
- PAPI_NOT_FOUND,
- PAPI_GONE,
- PAPI_REQUEST_ENTITY,
- PAPI_REQUEST_VALUE,
- PAPI_DOCUMENT_FORMAT,
- PAPI_ATTRIBUTES,
- PAPI_URI_SCHEME,
- PAPI_CHARSET,
- PAPI_CONFLICT,
- PAPI_COMPRESSION_NOT_SUPPORTED,
- PAPI_COMPRESSION_ERROR,
- PAPI_DOCUMENT_FORMAT_ERROR,
- PAPI_DOCUMENT_ACCESS_ERROR,
- PAPI_ATTRIBUTES_NOT_SETTABLE,
- PAPI_IGNORED_ALL_SUBSCRIPTIONS,
- PAPI_TOO_MANY_SUBSCRIPTIONS,
- PAPI_IGNORED_ALL_NOTIFICATIONS,
- PAPI_PRINT_SUPPORT_FILE_NOT_FOUND,
- PAPI_INTERNAL_ERROR = 0x0500,
- PAPI_OPERATION_NOT_SUPPORTED,
- PAPI_SERVICE_UNAVAILABLE,
- PAPI_VERSION_NOT_SUPPORTED,
- PAPI_DEVICE_ERROR,
- PAPI_TEMPORARY_ERROR,
- PAPI_NOT_ACCEPTING,
- PAPI_PRINTER_BUSY,
- PAPI_ERROR_JOB_CANCELLED,
- PAPI_MULTIPLE_JOBS_NOT_SUPPORTED,
- PAPI_PRINTER_IS_DEACTIVATED,
- PAPI_BAD_ARGUMENT,
- PAPI_JOB_TICKET_NOT_SUPPORTED
-} papi_status_t;
-
-/* list filter related */
-typedef enum {
- PAPI_FILTER_BITMASK = 0
-} papi_filter_type_t;
-
-typedef struct {
- papi_filter_type_t type;
- union {
- struct { /* PAPI_FILTER_BITMASK */
- unsigned int mask;
- unsigned int value;
- } bitmask;
- } filter;
-} papi_filter_t;
-
-enum {
- PAPI_PRINTER_LOCAL = 0x0000, /* Local destination */
- PAPI_PRINTER_CLASS = 0x0001, /* Printer class */
- PAPI_PRINTER_REMOTE = 0x0002, /* Remote destination */
- PAPI_PRINTER_BW = 0x0004, /* Can do B&W printing */
- PAPI_PRINTER_COLOR = 0x0008, /* Can do color printing */
- PAPI_PRINTER_DUPLEX = 0x0010, /* Can do duplex printing */
- PAPI_PRINTER_STAPLE = 0x0020, /* Can do stapling */
- PAPI_PRINTER_COPIES = 0x0040, /* Can do copies */
- PAPI_PRINTER_COLLATE = 0x0080, /* Can collate copies */
- PAPI_PRINTER_PUNCH = 0x0100, /* Can punch output */
- PAPI_PRINTER_COVER = 0x0200, /* Can cover output */
- PAPI_PRINTER_BIND = 0x0400, /* Can bind output */
- PAPI_PRINTER_SORT = 0x0800, /* Can sort output */
- PAPI_PRINTER_SMALL = 0x1000, /* Can do letter/legal/a4 */
- PAPI_PRINTER_MEDIUM = 0x2000, /* Can do tabloid/B/C/A3/A2 */
- PAPI_PRINTER_LARGE = 0x4000, /* Can do D/E/A1/A0 */
- PAPI_PRINTER_VARIABLE = 0x8000, /* Can do variable sizes */
- PAPI_PRINTER_IMPLICIT = 0x10000, /* implicit class */
- PAPI_PRINTER_DEFAULT = 0x20000, /* Default printer on network */
- PAPI_PRINTER_OPTIONS = 0xfffc /* ~ (CLASS | REMOTE | IMPLICIT) */
-};
-
-/*
- * Functions
- */
-
-/* Service related */
-extern papi_status_t papiServiceCreate(papi_service_t *handle,
- const char *service_name,
- const char *user_name,
- const char *password,
- const int (*authCB)(papi_service_t svc),
- const papi_encryption_t encryption,
- void *app_data);
-extern void papiServiceDestroy(papi_service_t handle);
-extern papi_status_t papiServiceSetUserName(papi_service_t handle,
- const char *user_name);
-extern papi_status_t papiServiceSetPassword(papi_service_t handle,
- const char *password);
-extern papi_status_t papiServiceSetEncryption(papi_service_t handle,
- const papi_encryption_t encryption);
-extern papi_status_t papiServiceSetAuthCB(papi_service_t handle,
- const int (*authCB)(papi_service_t s));
-extern papi_status_t papiServiceSetAppData(papi_service_t handle,
- const void *app_data);
-extern char *papiServiceGetServiceName(papi_service_t handle);
-extern char *papiServiceGetUserName(papi_service_t handle);
-extern char *papiServiceGetPassword(papi_service_t handle);
-extern papi_encryption_t papiServiceGetEncryption(papi_service_t handle);
-extern void *papiServiceGetAppData(papi_service_t handle);
-extern char *papiServiceGetStatusMessage(papi_service_t handle);
-
-/* Attribute related */
-extern papi_status_t papiAttributeListAdd(papi_attribute_t ***attrs,
- const int flags,
- const char *name,
- const papi_attribute_value_type_t type,
- const papi_attribute_value_t *value);
-extern papi_status_t papiAttributeListAddString(papi_attribute_t ***attrs,
- const int flags, const char *name,
- const char *string);
-extern papi_status_t papiAttributeListAddInteger(papi_attribute_t ***attrs,
- const int flags, const char *name,
- const int integer);
-extern papi_status_t papiAttributeListAddBoolean(papi_attribute_t ***attrs,
- const int flags, const char *name,
- const char boolean);
-extern papi_status_t papiAttributeListAddRange(papi_attribute_t ***attrs,
- const int flags, const char *name,
- const int lower, const int upper);
-extern papi_status_t papiAttributeListAddResolution(papi_attribute_t ***attrs,
- const int flags, const char *name,
- const int xres, const int yres,
- papi_resolution_unit_t units);
-extern papi_status_t papiAttributeListAddDatetime(papi_attribute_t ***attrs,
- const int flags, const char *name,
- const time_t datetime);
-extern papi_status_t papiAttributeListAddCollection(papi_attribute_t ***attrs,
- const int flags, const char *name,
- const papi_attribute_t **collection);
-extern papi_status_t papiAttributeListDelete(papi_attribute_t ***attributes,
- const char *name);
-extern papi_status_t papiAttributeListGetValue(papi_attribute_t **list,
- void **iterator, const char *name,
- papi_attribute_value_type_t type,
- papi_attribute_value_t **value);
-extern papi_status_t papiAttributeListGetString(papi_attribute_t **list,
- void **iterator, const char *name,
- char **vptr);
-extern papi_status_t papiAttributeListGetInteger(papi_attribute_t **list,
- void **iterator, const char *name,
- int *vptr);
-extern papi_status_t papiAttributeListGetBoolean(papi_attribute_t **list,
- void **iterator, const char *name,
- char *vptr);
-extern papi_status_t papiAttributeListGetRange(papi_attribute_t **list,
- void **iterator, const char *name,
- int *min, int *max);
-extern papi_status_t papiAttributeListGetResolution(papi_attribute_t **list,
- void **iterator, const char *name,
- int *x, int *y,
- papi_resolution_unit_t *units);
-extern papi_status_t papiAttributeListGetDatetime(papi_attribute_t **list,
- void **iterator, const char *name,
- time_t *dt);
-extern papi_status_t papiAttributeListGetCollection(papi_attribute_t **list,
- void **iterator, const char *name,
- papi_attribute_t ***collection);
-extern papi_attribute_t *papiAttributeListFind(papi_attribute_t **list,
- const char *name);
-extern papi_attribute_t *papiAttributeListGetNext(papi_attribute_t **list,
- void **iterator);
-extern void papiAttributeListFree(papi_attribute_t **attributes);
-
-extern papi_status_t papiAttributeListFromString(papi_attribute_t ***attrs,
- const int flags, const char *string);
-extern papi_status_t papiAttributeListToString(const papi_attribute_t **attrs,
- const char *delim,
- char *buffer, const size_t buflen);
-extern void papiAttributeListPrint
- (FILE *fp, char *prefix, papi_attribute_t **list);
-
-/* Printer related */
-extern papi_status_t papiPrintersList(papi_service_t handle,
- const char **requested_attrs,
- const papi_filter_t *filter,
- papi_printer_t **printers);
-extern papi_status_t papiPrinterQuery(papi_service_t handle, const char *name,
- const char **requested_attrs,
- const papi_attribute_t **job_attributes,
- papi_printer_t *printer);
-extern papi_status_t papiPrinterModify(papi_service_t handle, const char *name,
- const papi_attribute_t **attributes,
- papi_printer_t *printer);
-extern papi_status_t papiPrinterPause(papi_service_t handle, const char *name,
- const char *message);
-extern papi_status_t papiPrinterResume(papi_service_t handle, const char *name);
-extern papi_status_t papiPrinterPurgeJobs(papi_service_t handle,
- const char *name, papi_job_t **jobs);
-extern papi_status_t papiPrinterListJobs(papi_service_t handle,
- const char *name,
- const char **requested_attrs,
- const int type_mask,
- const int max_num_jobs,
- papi_job_t **jobs);
-extern papi_attribute_t **papiPrinterGetAttributeList(papi_printer_t printer);
-extern void papiPrinterFree(papi_printer_t printer);
-extern void papiPrinterListFree(papi_printer_t *printers);
-
-/* Job related */
-extern papi_status_t papiJobSubmit(papi_service_t handle, const char *printer,
- const papi_attribute_t **job_attributes,
- const papi_job_ticket_t *job_ticket,
- const char **files, papi_job_t *job);
-extern papi_status_t papiJobSubmitByReference(papi_service_t handle,
- const char *printer,
- const papi_attribute_t **job_attributes,
- const papi_job_ticket_t *job_ticket,
- const char **files, papi_job_t *job);
-extern papi_status_t papiJobValidate(papi_service_t handle, const char *printer,
- const papi_attribute_t **job_attributes,
- const papi_job_ticket_t *job_ticket,
- const char **files, papi_job_t *job);
-extern papi_status_t papiJobStreamOpen(papi_service_t handle,
- const char *printer,
- const papi_attribute_t **job_attributes,
- const papi_job_ticket_t *job_ticket,
- papi_stream_t *stream);
-extern papi_status_t papiJobStreamWrite(papi_service_t handle,
- papi_stream_t stream,
- const void *buffer,
- const size_t buflen);
-extern papi_status_t papiJobStreamClose(papi_service_t handle,
- papi_stream_t stream,
- papi_job_t *job);
-extern papi_status_t papiJobQuery(papi_service_t handle, const char *printer,
- const int32_t job_id,
- const char **requested_attrs,
- papi_job_t *job);
-extern papi_status_t papiJobModify(papi_service_t handle, const char *printer,
- const int32_t job_id,
- const papi_attribute_t **attributes,
- papi_job_t *job);
-extern papi_status_t papiJobCancel(papi_service_t handle, const char *printer,
- const int32_t job_id);
-extern papi_status_t papiJobHold(papi_service_t handle, const char *printer,
- const int32_t job_id,
- const char *hold_until,
- const time_t *hold_until_time);
-extern papi_status_t papiJobRelease(papi_service_t handle, const char *printer,
- const int32_t job_id);
-extern papi_status_t papiJobRestart(papi_service_t handle, const char *printer,
- const int32_t job_id);
-extern papi_attribute_t **papiJobGetAttributeList(papi_printer_t printer);
-extern char *papiJobGetPrinterName(papi_printer_t printer);
-extern int32_t papiJobGetId(papi_printer_t printer);
-extern papi_job_ticket_t *papiJobGetJobTicket(papi_printer_t printer);
-extern void papiJobFree(papi_job_t job);
-extern void papiJobListFree(papi_job_t *jobs);
-
-#ifdef SOLARIS_PRIVATE_POST_1_0
-/*
- * These have been added to support IPP create-job/send-document with PAPI v1.0
- * in an IPP listener using PAPI as it's spooler interface. A future version
- * of the API is expected to support this type of functionality
- */
-extern papi_status_t papiJobCreate(papi_service_t handle, const char *printer,
- const papi_attribute_t **job_attributes,
- const papi_job_ticket_t *job_ticket,
- papi_job_t *job);
-extern papi_status_t papiJobStreamAdd(papi_service_t handle, papi_job_t job,
- papi_attribute_t **document_attributes,
- papi_stream_t *stream);
-extern papi_status_t papiJobCommit(papi_service_t handle, papi_job_t job);
-#endif /* SOLARIS_PRIVATE_POST_1_0 */
-
-extern char *papiStatusString(const papi_status_t status);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _PAPI_H */
diff --git a/usr/src/cmd/lp/lib/papi/papi_impl.h b/usr/src/cmd/lp/lib/papi/papi_impl.h
index d2359f4e73..5d13df73ee 100644
--- a/usr/src/cmd/lp/lib/papi/papi_impl.h
+++ b/usr/src/cmd/lp/lib/papi/papi_impl.h
@@ -54,7 +54,7 @@ extern "C" {
typedef struct {
papi_attribute_t **attributes;
- int (*authCB)(papi_service_t svc);
+ int (*authCB)(papi_service_t svc, void *app_data);
void *app_data;
MESG *md;
char *msgbuf;
@@ -86,18 +86,27 @@ extern void job_status_to_attributes(job_t *job, char *req_id, char *user,
char *charset, short rank, char *file);
extern papi_status_t addLPString(papi_attribute_t ***list,
int flags, char *name, char *value);
-extern papi_status_t addLPStrings(papi_attribute_t ***list,
+extern papi_status_t papiAttributeListAddLPStrings(papi_attribute_t ***list,
int flags, char *name, char **values);
+extern void papiAttributeListGetLPString(papi_attribute_t **attributes,
+ char *key, char **string);
+extern void papiAttributeListGetLPStrings(papi_attribute_t **attributes,
+ char *key, char ***string);
+
extern papi_status_t lpsched_printer_configuration_to_attributes(
service_t *svc, printer_t *p, char *dest);
extern papi_status_t lpsched_class_configuration_to_attributes(service_t *svc,
printer_t *p, char *dest);
extern papi_status_t class_status_to_attributes(printer_t *p, char *printer,
short status, char *reject_reason, long reject_date);
+extern papi_status_t lpsched_reject_printer(papi_service_t svc,
+ char *printer, char *message);
+extern papi_status_t lpsched_accept_printer(papi_service_t svc,
+ char *printer);
extern papi_status_t lpsched_disable_printer(papi_service_t svc,
- const char *printer, const char *message);
+ char *printer, char *message);
extern papi_status_t lpsched_enable_printer(papi_service_t svc,
- const char *printer);
+ char *printer);
extern papi_status_t lpsched_status_to_papi_status(int status);
extern papi_status_t job_attributes_to_lpsched_request(papi_service_t svc,
REQUEST *r, papi_attribute_t **attributes);
@@ -106,31 +115,32 @@ extern papi_status_t lpsched_alloc_files(papi_service_t svc, int number,
extern papi_status_t lpsched_commit_job(papi_service_t svc, char *job,
char **tmp);
extern papi_status_t lpsched_start_change(papi_service_t svc,
- const char *printer, int32_t job_id, char **tmp);
+ char *printer, int32_t job_id, char **tmp);
extern papi_status_t lpsched_end_change(papi_service_t svc,
- const char *printer, int32_t job_id);
+ char *printer, int32_t job_id);
extern papi_status_t printer_status_to_attributes(printer_t *p, char *printer,
char *form, char *character_set, char *reject_reason,
char *disable_reason, short status, char *request_id, long enable_date,
long reject_date);
-
-extern void lpsched_service_information(printer_t *p);
+extern papi_status_t lpsched_remove_printer(papi_service_t svc, char *dest);
+extern papi_status_t lpsched_remove_class(papi_service_t svc, char *dest);
+extern papi_status_t lpsched_add_modify_printer(papi_service_t svc, char *dest,
+ papi_attribute_t **attributes, int type);
+extern papi_status_t lpsched_add_modify_class(papi_service_t svc, char *dest,
+ papi_attribute_t **attributes);
+
+extern void lpsched_service_information(papi_attribute_t ***attrs);
extern void lpsched_request_to_job_attributes(REQUEST *r, job_t *j);
extern void detailed_error(service_t *svc, char *fmt, ...);
extern char *banner_type(unsigned short banner);
extern char *mime_type_to_lp_type(char *mime_type);
extern char *lp_type_to_mime_type(char *lp_type);
-extern char *fifo_name_from_uri(const char *uri);
-extern char *printer_name_from_uri_id(const char *uri, int32_t id);
+extern char *fifo_name_from_uri(char *uri);
+extern char *printer_name_from_uri_id(char *uri, int32_t id);
extern int snd_msg(service_t *svc, int type, ...);
extern int rcv_msg(service_t *svc, int type, ...);
-extern int list_append();
-extern void list_remove();
-
-
-
#ifdef __cplusplus
}
#endif
diff --git a/usr/src/cmd/lp/lib/papi/ppd.c b/usr/src/cmd/lp/lib/papi/ppd.c
new file mode 100644
index 0000000000..5facf902be
--- /dev/null
+++ b/usr/src/cmd/lp/lib/papi/ppd.c
@@ -0,0 +1,164 @@
+/*
+ * 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 "%Z%%M% %I% %E% SMI"
+
+/*
+ * This file contains an extremely rudimentary implementation of PPD file
+ * parsing support. The parsing done here converts the contents of a PPD
+ * file into a set of PAPI attributes that applications can use to build
+ * print panels.
+ */
+
+#include <stdio.h>
+#include <ctype.h>
+#include <string.h>
+#include <papi.h>
+
+static void
+process_line(char *line, char **key, char **value, char **comment)
+{
+ char *ptr, *ptr2;
+
+ *key = &line[1];
+ *value = NULL;
+ *comment = NULL;
+
+ if ((ptr = strchr(line, ':')) == NULL)
+ return;
+
+ /*
+ * line is in the form:
+ * *key: value/comment
+ * or
+ * *key value/comment: data
+ */
+ *ptr++ = NULL;
+ while (isspace(*ptr) != 0)
+ ptr++;
+
+ if ((ptr2 = strchr(line, ' ')) != NULL) {
+ ptr = ptr2;
+ /*
+ * line is in the form:
+ * *key value/comment: data
+ */
+ *ptr++ = NULL;
+ while (*ptr == ' ')
+ ptr++;
+ }
+
+ if (*ptr == '*')
+ ptr++;
+
+ *value = ptr;
+
+ if ((ptr = strchr(ptr, '/')) != NULL) {
+ *ptr++ = NULL;
+ *comment = ptr;
+ }
+}
+
+papi_status_t
+PPDFileToAttributesList(papi_attribute_t ***attributes, char *filename)
+{
+ papi_status_t status = PAPI_OK;
+ FILE *fp;
+ char line[256];
+ char capability[256];
+ char def[256];
+ char supported[256];
+ char *current_group_name = NULL;
+
+ int ui = 0;
+
+ if ((fp = fopen(filename, "r")) == NULL)
+ return (PAPI_NOT_POSSIBLE);
+
+ while ((status == PAPI_OK) &&
+ (fgets(line, sizeof (line), fp) != NULL)) {
+ char *key = NULL, *value = NULL, *text = NULL;
+
+ /* we want *key...: "value" */
+ if (line[0] != '*')
+ continue;
+
+ if (strchr(line, ':') == NULL)
+ continue;
+
+ if ((text = strrchr(line, '\n')) != NULL)
+ *text = NULL;
+
+ process_line(line, &key, &value, &text);
+
+ if ((strcasecmp(key, "PageSize") == 0) ||
+ (strcasecmp(key, "InputSlot") == 0))
+ key = "media";
+
+ if (strcasecmp(key, "OpenGroup") == 0) {
+ if (value == NULL)
+ value = "unknown";
+ current_group_name = strdup(value);
+ } else if (strcasecmp(key, "OpenUI") == 0) {
+ if ((strcasecmp(value, "PageSize") == 0) ||
+ (strcasecmp(value, "InputSlot") == 0))
+ value = "media";
+ snprintf(capability, sizeof (capability), "%s", value);
+ snprintf(def, sizeof (def),
+ "%s-default", value);
+ snprintf(supported, sizeof (supported),
+ "%s-supported", value);
+ ui = 1;
+ } else if (strcasecmp(key, "CloseGroup") == 0) {
+ /* do nothing */
+ } else if (strcasecmp(key, "CloseUI") == 0) {
+ ui = 0;
+ /* do nothing */
+ } else if (strcasecmp(key, "Manufacturer") == 0) {
+ status = papiAttributeListAddString(attributes,
+ PAPI_ATTR_EXCL,
+ "printer-make", value);
+ } else if (strcasecmp(key, "ModelName") == 0) {
+ status = papiAttributeListAddString(attributes,
+ PAPI_ATTR_EXCL,
+ "printer-model", value);
+ } else if (strcasecmp(key, "ShortNickName") == 0) {
+ status = papiAttributeListAddString(attributes,
+ PAPI_ATTR_EXCL,
+ "printer-make-and-model", value);
+ } else if ((strncasecmp(key, "Default", 7) == 0) && ui) {
+ status = papiAttributeListAddString(attributes,
+ PAPI_ATTR_EXCL,
+ def, value);
+ } else if ((strcasecmp(key, capability) == 0) && ui) {
+ status = papiAttributeListAddString(attributes,
+ PAPI_ATTR_APPEND,
+ supported, value);
+ }
+ }
+ fclose(fp);
+
+ return (status);
+}
diff --git a/usr/src/cmd/lp/lib/papi/printer.c b/usr/src/cmd/lp/lib/papi/printer.c
index 2bfc1eabc8..8d1c6f6459 100644
--- a/usr/src/cmd/lp/lib/papi/printer.c
+++ b/usr/src/cmd/lp/lib/papi/printer.c
@@ -59,8 +59,8 @@ papiPrinterListFree(papi_printer_t *printers)
}
papi_status_t
-papiPrintersList(papi_service_t handle, const char **requested_attrs,
- const papi_filter_t *filter, papi_printer_t **printers)
+papiPrintersList(papi_service_t handle, char **requested_attrs,
+ papi_filter_t *filter, papi_printer_t **printers)
{
service_t *svc = handle;
printer_t *p = NULL;
@@ -139,9 +139,9 @@ papiPrintersList(papi_service_t handle, const char **requested_attrs,
}
papi_status_t
-papiPrinterQuery(papi_service_t handle, const char *name,
- const char **requested_attrs,
- const papi_attribute_t **job_attrs,
+papiPrinterQuery(papi_service_t handle, char *name,
+ char **requested_attrs,
+ papi_attribute_t **job_attrs,
papi_printer_t *printer)
{
papi_status_t pst;
@@ -166,6 +166,22 @@ papiPrinterQuery(papi_service_t handle, const char *name,
dest = printer_name_from_uri_id(name, -1);
+ if (strcmp(dest, "_default") == 0) {
+ static char *_default;
+
+ if (_default == NULL) {
+ int fd;
+ static char buf[128];
+
+ if ((fd = open("/etc/lp/default", O_RDONLY)) >= 0) {
+ read(fd, buf, sizeof (buf));
+ close(fd);
+ _default = strtok(buf, " \t\n");
+ }
+ }
+ dest = _default;
+ }
+
if (isprinter(dest) != 0) {
pst = lpsched_printer_configuration_to_attributes(svc, p, dest);
if (pst != PAPI_OK)
@@ -202,7 +218,7 @@ papiPrinterQuery(papi_service_t handle, const char *name,
reject_reason, reject_date);
} else if (strcmp(dest, "PrintService") == 0) {
/* fill the printer object with service information */
- lpsched_service_information(p);
+ lpsched_service_information(&p->attributes);
} else
return (PAPI_NOT_FOUND);
@@ -212,19 +228,108 @@ papiPrinterQuery(papi_service_t handle, const char *name,
}
papi_status_t
-papiPrinterModify(papi_service_t handle, const char *name,
- const papi_attribute_t **attributes, papi_printer_t *result)
+papiPrinterAdd(papi_service_t handle, char *name,
+ papi_attribute_t **attributes, papi_printer_t *result)
{
- service_t *svc = handle;
+ papi_status_t status;
+ printer_t *p = NULL;
+ char *dest;
+
+ if ((handle == NULL) || (name == NULL) || (attributes == NULL))
+ return (PAPI_BAD_ARGUMENT);
+
+ dest = printer_name_from_uri_id(name, -1);
+
+ if (isprinter(dest) != 0) {
+ status = lpsched_add_modify_printer(handle, dest,
+ attributes, 0);
+
+ if ((*result = p = calloc(1, sizeof (*p))) != NULL)
+ lpsched_printer_configuration_to_attributes(handle, p,
+ dest);
+ else
+ status = PAPI_TEMPORARY_ERROR;
+
+ } else if (isclass(dest) != 0) {
+ status = lpsched_add_modify_class(handle, dest, attributes);
+
+ if ((*result = p = calloc(1, sizeof (*p))) != NULL)
+ lpsched_class_configuration_to_attributes(handle, p,
+ dest);
+ else
+ status = PAPI_TEMPORARY_ERROR;
+
+ } else
+ status = PAPI_NOT_FOUND;
+
+ free(dest);
+
+ return (status);
+}
+
+papi_status_t
+papiPrinterModify(papi_service_t handle, char *name,
+ papi_attribute_t **attributes, papi_printer_t *result)
+{
+ papi_status_t status;
+ printer_t *p = NULL;
+ char *dest;
+
+ if ((handle == NULL) || (name == NULL) || (attributes == NULL))
+ return (PAPI_BAD_ARGUMENT);
+
+ dest = printer_name_from_uri_id(name, -1);
+
+ if (isprinter(dest) != 0) {
+ status = lpsched_add_modify_printer(handle, dest,
+ attributes, 1);
+
+ if ((*result = p = calloc(1, sizeof (*p))) != NULL)
+ lpsched_printer_configuration_to_attributes(handle, p,
+ dest);
+ else
+ status = PAPI_TEMPORARY_ERROR;
+ } else if (isclass(dest) != 0) {
+ status = lpsched_add_modify_class(handle, dest, attributes);
+
+ if ((*result = p = calloc(1, sizeof (*p))) != NULL)
+ lpsched_class_configuration_to_attributes(handle, p,
+ dest);
+ else
+ status = PAPI_TEMPORARY_ERROR;
+ } else
+ status = PAPI_NOT_FOUND;
+
+ free(dest);
+
+ return (status);
+}
+
+papi_status_t
+papiPrinterRemove(papi_service_t handle, char *name)
+{
+ papi_status_t result;
+ char *dest;
- if ((svc == NULL) || (name == NULL) || (attributes == NULL))
+ if ((handle == NULL) || (name == NULL))
return (PAPI_BAD_ARGUMENT);
- return (PAPI_OPERATION_NOT_SUPPORTED);
+ dest = printer_name_from_uri_id(name, -1);
+
+ if (isprinter(dest) != 0) {
+ result = lpsched_remove_printer(handle, dest);
+ } else if (isclass(dest) != 0) {
+ result = lpsched_remove_class(handle, dest);
+ } else
+ result = PAPI_NOT_FOUND;
+
+ free(dest);
+
+ return (result);
}
papi_status_t
-papiPrinterPause(papi_service_t handle, const char *name, const char *message)
+papiPrinterDisable(papi_service_t handle, char *name, char *message)
{
papi_status_t result;
@@ -237,7 +342,7 @@ papiPrinterPause(papi_service_t handle, const char *name, const char *message)
}
papi_status_t
-papiPrinterResume(papi_service_t handle, const char *name)
+papiPrinterEnable(papi_service_t handle, char *name)
{
papi_status_t result;
@@ -250,7 +355,33 @@ papiPrinterResume(papi_service_t handle, const char *name)
}
papi_status_t
-papiPrinterPurgeJobs(papi_service_t handle, const char *name, papi_job_t **jobs)
+papiPrinterPause(papi_service_t handle, char *name, char *message)
+{
+ papi_status_t result;
+
+ if ((handle == NULL) || (name == NULL))
+ return (PAPI_BAD_ARGUMENT);
+
+ result = lpsched_reject_printer(handle, name, message);
+
+ return (result);
+}
+
+papi_status_t
+papiPrinterResume(papi_service_t handle, char *name)
+{
+ papi_status_t result;
+
+ if ((handle == NULL) || (name == NULL))
+ return (PAPI_BAD_ARGUMENT);
+
+ result = lpsched_accept_printer(handle, name);
+
+ return (result);
+}
+
+papi_status_t
+papiPrinterPurgeJobs(papi_service_t handle, char *name, papi_job_t **jobs)
{
service_t *svc = handle;
papi_status_t result = PAPI_OK_SUBST;
@@ -263,10 +394,10 @@ papiPrinterPurgeJobs(papi_service_t handle, const char *name, papi_job_t **jobs)
return (PAPI_BAD_ARGUMENT);
dest = printer_name_from_uri_id(name, -1);
- if (snd_msg(svc, S_CANCEL, dest, "", "") < 0)
- return (PAPI_SERVICE_UNAVAILABLE);
-
+ more = snd_msg(svc, S_CANCEL, dest, "", "");
free(dest);
+ if (more < 0)
+ return (PAPI_SERVICE_UNAVAILABLE);
do {
if (rcv_msg(svc, R_CANCEL, &more, &status, &req_id) < 0)
@@ -300,9 +431,9 @@ papiPrinterPurgeJobs(papi_service_t handle, const char *name, papi_job_t **jobs)
}
papi_status_t
-papiPrinterListJobs(papi_service_t handle, const char *name,
- const char **requested_attrs, const int type_mask,
- const int max_num_jobs, papi_job_t **jobs)
+papiPrinterListJobs(papi_service_t handle, char *name,
+ char **requested_attrs, int type_mask,
+ int max_num_jobs, papi_job_t **jobs)
{
service_t *svc = handle;
char *dest;
diff --git a/usr/src/cmd/lp/lib/papi/service.c b/usr/src/cmd/lp/lib/papi/service.c
index f9c9162406..a15434fcfb 100644
--- a/usr/src/cmd/lp/lib/papi/service.c
+++ b/usr/src/cmd/lp/lib/papi/service.c
@@ -38,10 +38,10 @@
#include <tsol/label.h>
papi_status_t
-papiServiceCreate(papi_service_t *handle, const char *service_name,
- const char *user_name, const char *password,
- const int (*authCB)(papi_service_t svc),
- const papi_encryption_t encryption, void *app_data)
+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)
{
service_t *svc = NULL;
char *path = Lp_FIFO;
@@ -125,7 +125,7 @@ papiServiceSetPeer(papi_service_t handle, int peerfd)
}
papi_status_t
-papiServiceSetUserName(papi_service_t handle, const char *user_name)
+papiServiceSetUserName(papi_service_t handle, char *user_name)
{
service_t *svc = handle;
@@ -137,7 +137,7 @@ papiServiceSetUserName(papi_service_t handle, const char *user_name)
}
papi_status_t
-papiServiceSetPassword(papi_service_t handle, const char *password)
+papiServiceSetPassword(papi_service_t handle, char *password)
{
service_t *svc = handle;
@@ -150,7 +150,7 @@ papiServiceSetPassword(papi_service_t handle, const char *password)
papi_status_t
papiServiceSetEncryption(papi_service_t handle,
- const papi_encryption_t encryption)
+ papi_encryption_t encryption)
{
service_t *svc = handle;
@@ -163,20 +163,20 @@ papiServiceSetEncryption(papi_service_t handle,
papi_status_t
papiServiceSetAuthCB(papi_service_t handle,
- const int (*authCB)(papi_service_t svc))
+ int (*authCB)(papi_service_t svc, void *app_data))
{
service_t *svc = handle;
if (svc == NULL)
return (PAPI_BAD_ARGUMENT);
- svc->authCB = (int (*)(papi_service_t svc))authCB;
+ svc->authCB = (int (*)(papi_service_t svc, void *app_data))authCB;
return (PAPI_OK);
}
papi_status_t
-papiServiceSetAppData(papi_service_t handle, const void *app_data)
+papiServiceSetAppData(papi_service_t handle, void *app_data)
{
service_t *svc = handle;
@@ -252,6 +252,20 @@ papiServiceGetAppData(papi_service_t handle)
return (result);
}
+papi_attribute_t **
+papiServiceGetAttributeList(papi_service_t handle)
+{
+ service_t *svc = handle;
+ papi_attribute_t **result = NULL;
+
+ if (svc != NULL) {
+ lpsched_service_information(&svc->attributes);
+ result = svc->attributes;
+ }
+
+ return (result);
+}
+
char *
papiServiceGetStatusMessage(papi_service_t handle)
{
diff --git a/usr/src/cmd/lp/lib/papi/status.c b/usr/src/cmd/lp/lib/papi/status.c
deleted file mode 100644
index 61f6d20739..0000000000
--- a/usr/src/cmd/lp/lib/papi/status.c
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (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 2003 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-
-#pragma ident "%Z%%M% %I% %E% SMI"
-
-/*LINTLIBRARY*/
-
-
-#include <stdlib.h>
-#include <papi_impl.h>
-#include <libintl.h>
-
-char *
-papiStatusString(const papi_status_t status)
-{
- switch (status) {
- case PAPI_OK:
- return (gettext("ok"));
- case PAPI_OK_SUBST:
- return (gettext("ok-substitution"));
- case PAPI_OK_CONFLICT:
- return (gettext("ok-conflict"));
- case PAPI_OK_IGNORED_SUBSCRIPTIONS:
- return (gettext("ok-ignored-subscriptions"));
- case PAPI_OK_IGNORED_NOTIFICATIONS:
- return (gettext("ok-ignored-notifications"));
- case PAPI_OK_TOO_MANY_EVENTS:
- return (gettext("ok-too-many-events"));
- case PAPI_OK_BUT_CANCEL_SUBSCRIPTION:
- return (gettext("ok-but-cancel-subscription"));
- case PAPI_REDIRECTION_OTHER_SITE:
- return (gettext("redirection-to-other-site"));
- case PAPI_BAD_REQUEST:
- return (gettext("bad-request"));
- case PAPI_FORBIDDEN:
- return (gettext("forbidden"));
- case PAPI_NOT_AUTHENTICATED:
- return (gettext("not-authenticated"));
- case PAPI_NOT_AUTHORIZED:
- return (gettext("not-authorized"));
- case PAPI_NOT_POSSIBLE:
- return (gettext("not-possible"));
- case PAPI_TIMEOUT:
- return (gettext("timeout"));
- case PAPI_NOT_FOUND:
- return (gettext("not-found"));
- case PAPI_GONE:
- return (gettext("gone"));
- case PAPI_REQUEST_ENTITY:
- return (gettext("request-entity"));
- case PAPI_REQUEST_VALUE:
- return (gettext("request-value"));
- case PAPI_DOCUMENT_FORMAT:
- return (gettext("document-format"));
- case PAPI_ATTRIBUTES:
- return (gettext("attributes"));
- case PAPI_URI_SCHEME:
- return (gettext("uri-scheme"));
- case PAPI_CHARSET:
- return (gettext("charset"));
- case PAPI_CONFLICT:
- return (gettext("conflict"));
- case PAPI_COMPRESSION_NOT_SUPPORTED:
- return (gettext("compression-not-supported"));
- case PAPI_COMPRESSION_ERROR:
- return (gettext("compression-error"));
- case PAPI_DOCUMENT_FORMAT_ERROR:
- return (gettext("document-format-error"));
- case PAPI_DOCUMENT_ACCESS_ERROR:
- return (gettext("document-access-error"));
- case PAPI_ATTRIBUTES_NOT_SETTABLE:
- return (gettext("attributes-not-settable"));
- case PAPI_IGNORED_ALL_SUBSCRIPTIONS:
- return (gettext("ignored-all-subscriptions"));
- case PAPI_TOO_MANY_SUBSCRIPTIONS:
- return (gettext("too-many-subscriptions"));
- case PAPI_IGNORED_ALL_NOTIFICATIONS:
- return (gettext("ignored-all-notifications"));
- case PAPI_PRINT_SUPPORT_FILE_NOT_FOUND:
- return (gettext("print-support-file-not-found"));
- case PAPI_INTERNAL_ERROR:
- return (gettext("internal-error"));
- case PAPI_OPERATION_NOT_SUPPORTED:
- return (gettext("operation-not-supported"));
- case PAPI_SERVICE_UNAVAILABLE:
- return (gettext("service-unavailable"));
- case PAPI_VERSION_NOT_SUPPORTED:
- return (gettext("version-not-supported"));
- case PAPI_DEVICE_ERROR:
- return (gettext("device-error"));
- case PAPI_TEMPORARY_ERROR:
- return (gettext("temporary-error"));
- case PAPI_NOT_ACCEPTING:
- return (gettext("not-accepting"));
- case PAPI_PRINTER_BUSY:
- return (gettext("printer-busy"));
- case PAPI_ERROR_JOB_CANCELLED:
- return (gettext("error-job-cancelled"));
- case PAPI_MULTIPLE_JOBS_NOT_SUPPORTED:
- return (gettext("multiple-jobs-not-supported"));
- case PAPI_PRINTER_IS_DEACTIVATED:
- return (gettext("printer-is-deactivated"));
- case PAPI_BAD_ARGUMENT:
- return (gettext("bad-argument"));
- case PAPI_JOB_TICKET_NOT_SUPPORTED:
- return (gettext("job-ticket-not-supported"));
- default:
- return (gettext("unknown-error"));
- }
-}