summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr/src/cmd/hal/addons/network-devices/network-discovery.xml3
-rw-r--r--usr/src/cmd/lp/lib/papi/job.c8
-rw-r--r--usr/src/cmd/lp/lib/papi/lpsched-jobs.c52
-rw-r--r--usr/src/cmd/print/bsd-sysv-commands/in.lpd.c24
-rw-r--r--usr/src/cmd/print/bsd-sysv-commands/lp.c22
-rw-r--r--usr/src/lib/print/libpapi-common/common/attribute.c517
-rw-r--r--usr/src/lib/print/libpapi-lpd/common/lpd-job.c36
7 files changed, 292 insertions, 370 deletions
diff --git a/usr/src/cmd/hal/addons/network-devices/network-discovery.xml b/usr/src/cmd/hal/addons/network-devices/network-discovery.xml
index 8844dee0fa..d17d2cf5cc 100644
--- a/usr/src/cmd/hal/addons/network-devices/network-discovery.xml
+++ b/usr/src/cmd/hal/addons/network-devices/network-discovery.xml
@@ -93,6 +93,9 @@
</property_group>
<property_group name='config' type='framework'>
+ <!-- authorization to add/delete config properties -->
+ <propval name='modify_authorization' type='astring'
+ value='solaris.smf.value.discovery.printers.snmp' />
<!-- authorization to modify config properties -->
<propval name='value_authorization' type='astring'
value='solaris.smf.value.discovery.printers.snmp' />
diff --git a/usr/src/cmd/lp/lib/papi/job.c b/usr/src/cmd/lp/lib/papi/job.c
index b139224464..4ee09858ce 100644
--- a/usr/src/cmd/lp/lib/papi/job.c
+++ b/usr/src/cmd/lp/lib/papi/job.c
@@ -19,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -623,7 +623,7 @@ papiJobValidate(papi_service_t handle, char *printer,
int i;
papiAttributeListAddString(&attributes, PAPI_ATTR_REPLACE,
- "job-hold-until", "hold");
+ "job-hold-until", "indefinite");
for (i = 0; job_attributes[i]; i++)
list_append(&attributes, job_attributes[i]);
@@ -1032,6 +1032,10 @@ papiJobModify(papi_service_t handle, char *printer, int32_t job_id,
status = lpsched_end_change(svc, dest, job_id);
lpsched_request_to_job_attributes(r, j);
+
+ papiAttributeListAddInteger(&j->attributes, PAPI_ATTR_REPLACE,
+ "job-id", job_id);
+
freerequest(r);
return (status);
diff --git a/usr/src/cmd/lp/lib/papi/lpsched-jobs.c b/usr/src/cmd/lp/lib/papi/lpsched-jobs.c
index 08d7f68524..933e2fc3af 100644
--- a/usr/src/cmd/lp/lib/papi/lpsched-jobs.c
+++ b/usr/src/cmd/lp/lib/papi/lpsched-jobs.c
@@ -19,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -47,6 +47,7 @@ job_attributes_to_lpsched_request(papi_service_t svc, REQUEST *r,
papi_status_t status = PAPI_OK;
papi_attribute_t *attr;
papi_attribute_t **unmapped = NULL;
+ papi_attribute_t *tmp[2];
int i;
char *s;
@@ -68,7 +69,7 @@ job_attributes_to_lpsched_request(papi_service_t svc, REQUEST *r,
"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",
+ "pr-indent", "pr-title", "pr-width", "job-priority",
"requesting-user-name", "job-originating-host-name",
NULL };
@@ -90,11 +91,11 @@ job_attributes_to_lpsched_request(papi_service_t svc, REQUEST *r,
* set the priority. PAPI/IPP uses 1-100, lpsched use 0-39, so we
* have to convert it.
*/
- if (papiAttributeListGetInteger(attributes, NULL, "priority", &i)
+ if (papiAttributeListGetInteger(attributes, NULL, "job-priority", &i)
== PAPI_OK) {
if ((i < 1) || (i > 100))
i = 50;
- i = (i + 1) / 2.5;
+ i = 40 - (i / 2.5);
r->priority = i;
}
if ((r->priority < 0) || (r->priority > 39))
@@ -104,23 +105,15 @@ job_attributes_to_lpsched_request(papi_service_t svc, REQUEST *r,
papiAttributeListGetLPString(attributes, "form", &r->form);
/* set the page range */
-#ifndef LP_USE_PAPI_ATTR
- papiAttributeListGetLPString(attributes, "page-ranges", &r->pages);
-#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, lower, upper);
- free(r->pages);
- } else
- snprintf(buf, sizeof (buf), "%d-%d", lower, upper);
- r->pages = (char *)strdup(buf);
- }
-#endif
+ memset(tmp, NULL, sizeof (tmp));
+ tmp[0] = papiAttributeListFind(attributes, "page-ranges");
+ if (tmp[0] != NULL) {
+ char buf[BUFSIZ];
+
+ papiAttributeListToString(tmp, " ", buf, sizeof (buf));
+ if ((s = strchr(buf, '=')) != NULL)
+ r->pages = (char *)strdup(++s);
+ }
/*
* set the document format, converting to old format names as
@@ -167,13 +160,14 @@ job_attributes_to_lpsched_request(papi_service_t svc, REQUEST *r,
s = NULL;
papiAttributeListGetString(attributes, NULL, "job-hold-until", &s);
if (s != NULL) {
- if (strcmp(s, "immediate") == 0)
- r->actions |= ACT_IMMEDIATE;
- else if ((strcmp(s, "resume") == 0) ||
- (strcmp(s, "no-hold") == 0))
+ r->actions &= ~(ACT_SPECIAL); /* strip immediate/hold/resume */
+ if (strcmp(s, "resume") == 0)
r->actions |= ACT_RESUME;
- else if ((strcmp(s, "hold") == 0) ||
- (strcmp(s, "indefinite") == 0))
+ else if ((strcmp(s, "immediate") == 0) ||
+ (strcmp(s, "no-hold") == 0))
+ r->actions |= ACT_IMMEDIATE;
+ else if ((strcmp(s, "indefinite") == 0) ||
+ (strcmp(s, "hold") == 0))
r->actions |= ACT_HOLD;
}
@@ -281,7 +275,7 @@ job_attributes_to_lpsched_request(papi_service_t svc, REQUEST *r,
char *buf = malloc(1024);
ssize_t size = 1024;
- while (papiAttributeListToString(unmapped, ", ", buf, size)
+ while (papiAttributeListToString(unmapped, " ", buf, size)
!= PAPI_OK) {
size += 1024;
buf = realloc(buf, size);
@@ -417,7 +411,7 @@ lpsched_request_to_job_attributes(REQUEST *r, job_t *j)
/* priority (map 0-39 to 1-100) */
papiAttributeListAddInteger(&j->attributes, PAPI_ATTR_REPLACE,
- "job-priority", (int)((r->priority + 1) * 2.5));
+ "job-priority", (int)(100 - (r->priority * 2.5)));
/* pages */
papiAttributeListAddLPString(&j->attributes, PAPI_ATTR_REPLACE,
diff --git a/usr/src/cmd/print/bsd-sysv-commands/in.lpd.c b/usr/src/cmd/print/bsd-sysv-commands/in.lpd.c
index 7782ee9a36..6a012adcb1 100644
--- a/usr/src/cmd/print/bsd-sysv-commands/in.lpd.c
+++ b/usr/src/cmd/print/bsd-sysv-commands/in.lpd.c
@@ -20,7 +20,7 @@
*/
/*
- * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
*/
@@ -308,14 +308,10 @@ parse_cf(papi_service_t svc, char *cf, char **files)
papiAttributeListAddString(&list,
PAPI_ATTR_EXCL,
"job-hold-until", "indefinite");
- else if (strcasecmp(entry, "release") == 0)
+ else if (strcasecmp(entry, "immediate") == 0)
papiAttributeListAddString(&list,
PAPI_ATTR_EXCL,
"job-hold-until", "no-hold");
- else if (strcasecmp(entry, "immediate") == 0)
- papiAttributeListAddInteger(&list,
- PAPI_ATTR_EXCL,
- "job-priority", 100);
else
papiAttributeListAddString(&list,
PAPI_ATTR_EXCL,
@@ -325,19 +321,23 @@ parse_cf(papi_service_t svc, char *cf, char **files)
papiAttributeListAddBoolean(&list,
PAPI_ATTR_EXCL, "rfc-1179-mail", 1);
break;
- case 'P': /* Solaris page list */
- papiAttributeListAddString(&list,
- PAPI_ATTR_EXCL,
- "page-ranges", ++entry);
+ case 'P': { /* Solaris page list */
+ char buf[BUFSIZ];
+
+ snprintf(buf, sizeof (buf), "page-ranges=%s",
+ ++entry);
+ papiAttributeListFromString(&list,
+ PAPI_ATTR_EXCL, buf);
+ }
break;
case 'q': { /* Solaris priority */
int i = atoi(optarg);
- i = 99 * (39 - i) / 39 + 1;
+ i = 100 - (i * 2.5);
if ((i < 1) || (i > 100))
i = 50;
papiAttributeListAddInteger(&list,
- PAPI_ATTR_EXCL, "priority", i);
+ PAPI_ATTR_EXCL, "job-priority", i);
}
break;
case 'S': /* Solaris character set */
diff --git a/usr/src/cmd/print/bsd-sysv-commands/lp.c b/usr/src/cmd/print/bsd-sysv-commands/lp.c
index 5abe7ae7e8..aeec532e54 100644
--- a/usr/src/cmd/print/bsd-sysv-commands/lp.c
+++ b/usr/src/cmd/print/bsd-sysv-commands/lp.c
@@ -20,7 +20,7 @@
*/
/*
- * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
*/
@@ -89,22 +89,22 @@ main(int ac, char *av[])
papiAttributeListAddString(&list,
PAPI_ATTR_EXCL,
"job-hold-until", "indefinite");
- else if (strcasecmp(optarg, "release") == 0)
+ else if (strcasecmp(optarg, "immediate") == 0)
papiAttributeListAddString(&list,
PAPI_ATTR_EXCL,
"job-hold-until", "no-hold");
- else if (strcasecmp(optarg, "immediate") == 0)
- papiAttributeListAddInteger(&list,
- PAPI_ATTR_EXCL,
- "job-priority", 100);
else
papiAttributeListAddString(&list,
PAPI_ATTR_EXCL,
"job-hold-until", optarg);
break;
- case 'P': /* page list */
- papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
- "page-ranges", optarg);
+ case 'P': { /* page list */
+ char buf[BUFSIZ];
+
+ snprintf(buf, sizeof (buf), "page-ranges=%s", optarg);
+ papiAttributeListFromString(&list,
+ PAPI_ATTR_EXCL, buf);
+ }
break;
case 'S': /* charset */
papiAttributeListAddString(&list, PAPI_ATTR_EXCL,
@@ -156,14 +156,14 @@ main(int ac, char *av[])
case 'q': { /* priority */
int i = atoi(optarg);
- i = 99 * (39 - i) / 39 + 1;
+ i = 100 - (i * 2.5);
if ((i < 1) || (i > 100)) {
fprintf(stderr, gettext(
"priority must be between 0 and 39.\n"));
exit(1);
}
papiAttributeListAddInteger(&list, PAPI_ATTR_EXCL,
- "priority", i);
+ "job-priority", i);
}
break;
case 'r': /* "raw" mode */
diff --git a/usr/src/lib/print/libpapi-common/common/attribute.c b/usr/src/lib/print/libpapi-common/common/attribute.c
index 4fd9f01a19..d2f039ec69 100644
--- a/usr/src/lib/print/libpapi-common/common/attribute.c
+++ b/usr/src/lib/print/libpapi-common/common/attribute.c
@@ -20,7 +20,7 @@
*/
/*
- * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
*/
@@ -35,8 +35,10 @@
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
+#include <ctype.h>
#include <alloca.h>
#include <papi.h>
+#include <regex.h>
static void papiAttributeFree(papi_attribute_t *attribute);
@@ -617,335 +619,242 @@ papiAttributeListGetMetadata(papi_attribute_t **list, void **iter,
return (status);
}
-/*
- * Description: The given string contains one or more attributes, in the
- * following form:
- * "aaaa=true bbbbb=1 ccccc=abcd"
- * extract the next attribute from that string; the 'next'
- * parameter should be set to zero to extract the first attribute
- * in the string.
- *
- */
+/* The string is modified by this call */
static char *
-_getNextAttr(char *string, int *next)
-
+regvalue(regmatch_t match, char *string)
{
char *result = NULL;
- char *start = (char *)string + *next;
- char *nl = NULL;
- char *sp = NULL;
- char *tab = NULL;
- char *val = NULL;
- int len = 0;
-
- if ((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 (match.rm_so != match.rm_eo) {
+ result = string + match.rm_so;
+ *(result + (match.rm_eo - match.rm_so)) = '\0';
+ }
+ return (result);
+}
- if (len == 0) {
- len = strlen(start);
+static papi_attribute_value_type_t
+_process_value(char *string, char ***parts)
+{
+ int i;
+ static struct {
+ papi_attribute_value_type_t type;
+ size_t vals;
+ char *expression;
+ int compiled;
+ regex_t re;
+ } types[] = {
+ { PAPI_BOOLEAN, 1, "^(true|false|yes|no)$", 0 },
+ { PAPI_COLLECTION, 1, "^\\{(.+)\\}$", 0 },
+ /* PAPI_DATETIME is unsupported, too much like an integer */
+ { PAPI_INTEGER, 1, "^([+-]{0,1}[[:digit:]]+)$", 0 },
+ { PAPI_RANGE, 3, "^([[:digit:]]+)-([[:digit:]]+)$", 0 },
+ { PAPI_RESOLUTION, 4, "^([[:digit:]]+)x([[:digit:]]+)dp(i|c)$",
+ 0 },
+ NULL
+ };
+ regmatch_t matches[4];
+
+ for (i = 0; i < 5; i++) {
+ int j;
+
+ if (types[i].compiled == 0) {
+ (void) regcomp(&(types[i].re), types[i].expression,
+ REG_EXTENDED|REG_ICASE);
+ types[i].compiled = 1;
}
+ if (regexec(&(types[i].re), string, (size_t)types[i].vals,
+ matches, 0) == REG_NOMATCH)
+ continue;
- if (len > 0) {
- result = (char *)malloc(len+1);
- if (result != NULL) {
- strncpy(result, start, len);
- result[len] = '\0';
- *next = (start-string)+len;
- }
- }
+ for (j = 0 ; j < types[i].vals; j++)
+ list_append(parts, regvalue(matches[j], string));
+ return (types[i].type);
}
- return (result);
-} /* _getNextAttr() */
-
+ list_append(parts, string);
+ return (PAPI_STRING);
+}
-/*
- * Description: Parse the given attribute string value and transform it into
- * the papi_attribute_value_t in the papi_attribute_t structure.
- *
- */
+static void
+_add_attribute_value(papi_attribute_value_t ***list,
+ papi_attribute_value_type_t type,
+ papi_attribute_value_type_t dtype, char **parts)
+{
+ papi_attribute_value_t *value = calloc(1, sizeof (*value));
+
+ switch(type) {
+ case PAPI_STRING:
+ value->string = strdup(parts[0]);
+ list_append(list, value);
+ break;
+ case PAPI_BOOLEAN:
+ value->boolean = PAPI_TRUE;
+ if ((strcasecmp(parts[0], "false") == 0) ||
+ (strcasecmp(parts[0], "no") == 0))
+ value->boolean = PAPI_FALSE;
+ list_append(list, value);
+ break;
+ case PAPI_INTEGER:
+ value->integer = atoi(parts[0]);
+ list_append(list, value);
+ break;
+ case PAPI_RANGE:
+ if (dtype == PAPI_INTEGER)
+ value->range.lower = value->range.upper
+ = atoi(parts[0]);
+ else if (dtype == PAPI_RANGE) {
+ value->range.lower = atoi(parts[1]);
+ value->range.upper = atoi(parts[2]);
+ }
+ list_append(list, value);
+ break;
+ case PAPI_RESOLUTION:
+ value->resolution.xres = atoi(parts[1]);
+ value->resolution.yres = atoi(parts[2]);
+ if (parts[3][0] == 'i')
+ value->resolution.units = PAPI_RES_PER_INCH;
+ else
+ value->resolution.units = PAPI_RES_PER_CM;
+ list_append(list, value);
+ break;
+ case PAPI_COLLECTION:
+ papiAttributeListFromString(&(value->collection), 0, parts[0]);
+ list_append(list, value);
+ break;
+ }
+}
static papi_status_t
-_parseAttrValue(char *value, papi_attribute_t *attr)
-
+_papiAttributeFromStrings(papi_attribute_t ***list, int flags,
+ char *key, char **values)
{
+ int i;
papi_status_t result = PAPI_OK;
- int len = 0;
- int i = 0;
- char *papiString = NULL;
- char *tmp1 = NULL;
- char *tmp2 = NULL;
- char *tmp3 = NULL;
- papi_attribute_value_t **avalues = NULL;
-
- 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);
- }
+ papi_attribute_t *attr = calloc(1, sizeof (*attr));
+ /* these are specified in the papi spec as ranges */
+ char *ranges[] = { "copies-supported", "job-impressions-supported",
+ "job-k-octets-supported",
+ "job-media-sheets-supported", "page-ranges",
+ NULL };
-/*
- * 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;
- }
+ if ((attr == NULL) || ((attr->name = strdup(key)) == NULL))
+ return (PAPI_TEMPORARY_ERROR);
- i++;
- }
+ attr->type = PAPI_METADATA;
+ /* these are known ranges */
+ for (i = 0; ranges[i] != NULL; i++)
+ if (strcasecmp(attr->name, ranges[i]) == 0) {
+ attr->type = PAPI_RANGE;
+ break;
+ }
- 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 (values != NULL) {
+ papi_attribute_value_t **vals = NULL;
- 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;
- }
- }
- }
+ for (i = 0; values[i] != NULL; i++) {
+ papi_attribute_value_type_t dtype;
+ char **parts = NULL;
- if (attr->type != PAPI_RESOLUTION) {
- attr->type = PAPI_STRING;
- avalues[0]->string = strdup(value);
- if (avalues[0]->string == NULL) {
- result = PAPI_TEMPORARY_ERROR;
- }
- }
- }
- free(tmp1);
+ dtype = _process_value(values[i], &parts);
+ if (attr->type == PAPI_METADATA)
+ attr->type = dtype;
+ _add_attribute_value(&vals, attr->type, dtype, parts);
+ free(parts);
}
-
- } else {
- result = PAPI_BAD_ARGUMENT;
+ attr->values = vals;
}
- if (result != PAPI_OK) {
- i = 0;
- while (avalues[i] != NULL) {
- free(avalues[i]);
- i++;
- }
- free(avalues);
- } else {
- attr->values = avalues;
- }
+ list_append(list, attr);
return (result);
-} /* _parseAttrValue() */
-
-
-/*
- * Description: Parse the given attribute string and transform it into the
- * papi_attribute_t structure.
- *
- */
+}
static papi_status_t
-_parseAttributeString(char *attrString, papi_attribute_t *attr)
-
+_parse_attribute_list(papi_attribute_t ***list, int flags, char *string)
{
papi_status_t result = PAPI_OK;
- char *string = NULL;
- char *p = NULL;
- papi_attribute_value_t **avalues = NULL;
-
- 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 {
- char value;
- /* boolean - no value so assume 'true' */
- if (strncasecmp(string, "no", 2) == 0) {
- string += 2;
- value = PAPI_FALSE;
- } else
- value = PAPI_TRUE;
-
- attr->name = string;
- attr->type = PAPI_BOOLEAN;
-
- avalues = malloc(
- sizeof (papi_attribute_value_t *) * 2);
- if (avalues == NULL) {
- result = PAPI_TEMPORARY_ERROR;
+ char *ptr;
+
+ if ((list == NULL) || (string == NULL))
+ return (PAPI_BAD_ARGUMENT);
+
+ if ((ptr = strdup(string)) == NULL)
+ return (PAPI_TEMPORARY_ERROR);
+
+ while ((*ptr != '\0') && (result == PAPI_OK)) {
+ char *key, **values = NULL;
+
+ /* strip any leading whitespace */
+ while (isspace(*ptr) != 0)
+ ptr++;
+
+ /* Get the name: name[=value] */
+ key = ptr;
+ while ((*ptr != '\0') && (*ptr != '=') && (isspace(*ptr) == 0))
+ ptr++;
+
+ if (*ptr == '=') {
+ *ptr++ = '\0';
+
+ while ((*ptr != '\0') && (isspace(*ptr) == 0)) {
+ char *value = ptr;
+
+ if ((*ptr == '\'') || (*ptr == '"')) {
+ char q = *ptr++;
+
+ /* quoted string value */
+ while ((*ptr != '\0') && (*ptr != q))
+ ptr++;
+ if (*ptr == q)
+ ptr++;
+ } else if (*ptr == '{') {
+ /* collection */
+ while ((*ptr != '\0') && (*ptr != '}'))
+ ptr++;
+ if (*ptr == '}')
+ ptr++;
} else {
- avalues[0] = malloc(
- sizeof (papi_attribute_value_t));
- avalues[1] = NULL;
- if (avalues[0] == NULL) {
- free(avalues);
- result = PAPI_TEMPORARY_ERROR;
- } else {
- avalues[0]->boolean = value;
- attr->values = avalues;
- }
+ /* value */
+ while ((*ptr != '\0') &&
+ (*ptr != ',') &&
+ (isspace(*ptr) == 0))
+ ptr++;
}
+ if (*ptr == ',')
+ *ptr++ = '\0';
+ list_append(&values, value);
+ }
+ } else { /* boolean "[no]key" */
+ char *value = "true";
+
+ if (strncasecmp(key, "no", 2) == 0) {
+ key += 2;
+ value = "false";
}
+ list_append(&values, value);
}
- } else {
- result = PAPI_BAD_ARGUMENT;
+ if (*ptr != '\0')
+ *ptr++ = '\0';
+
+ result = _papiAttributeFromStrings(list, flags, key, values);
+ free(values);
}
return (result);
-} /* _parseAttributeString() */
-
+}
papi_status_t
papiAttributeListFromString(papi_attribute_t ***attrs,
int flags, char *string)
{
papi_status_t result = PAPI_OK;
- int next = 0;
- char *attrString = NULL;
- papi_attribute_t attr;
if ((attrs != NULL) && (string != NULL) &&
((flags & ~(PAPI_ATTR_APPEND+PAPI_ATTR_REPLACE+PAPI_ATTR_EXCL))
== 0)) {
- attrString = _getNextAttr(string, &next);
- while ((result == PAPI_OK) && (attrString != NULL)) {
- result = _parseAttributeString(attrString, &attr);
- if ((result == PAPI_OK) && (attr.name != NULL)) {
- /* add this attribute to the list */
- if ((attr.values != NULL) &&
- (attr.values[0] != NULL)) {
- result = papiAttributeListAddValue(
- attrs, PAPI_ATTR_APPEND,
- attr.name, attr.type,
- attr.values[0]);
- free(attr.values[0]);
- free(attr.values);
- } else {
- result = PAPI_TEMPORARY_ERROR;
- }
- }
- free(attrString);
-
- attrString = _getNextAttr(string, &next);
- }
- }
- else
- {
+ result = _parse_attribute_list(attrs, flags, string);
+ } else {
result = PAPI_BAD_ARGUMENT;
}
@@ -959,8 +868,18 @@ papiAttributeToString(papi_attribute_t *attribute, char *delim,
papi_attribute_value_t **values = attribute->values;
int rc, i;
- strlcat(buffer, attribute->name, buflen);
- strlcat(buffer, "=", buflen);
+ if ((attribute->type == PAPI_BOOLEAN) && (values[1] == NULL)) {
+ if (values[0]->boolean == PAPI_FALSE) {
+ if (isupper(attribute->name[0]) == 0)
+ strlcat(buffer, "no", buflen);
+ else
+ strlcat(buffer, "No", buflen);
+ }
+ rc = strlcat(buffer, attribute->name, buflen);
+ } else {
+ strlcat(buffer, attribute->name, buflen);
+ rc = strlcat(buffer, "=", buflen);
+ }
if (values == NULL)
return (PAPI_OK);
@@ -979,14 +898,20 @@ papiAttributeToString(papi_attribute_t *attribute, char *delim,
}
break;
case PAPI_BOOLEAN:
- rc = strlcat(buffer, (values[i]->boolean ? "true" :
- "false"), buflen);
+ if (values[1] != NULL)
+ rc = strlcat(buffer, (values[i]->boolean ?
+ "true" : "false"), buflen);
break;
case PAPI_RANGE: {
char string[24];
- snprintf(string, sizeof (string), "%d-%d",
- values[i]->range.lower, values[i]->range.upper);
+ if (values[i]->range.lower == values[i]->range.upper)
+ snprintf(string, sizeof (string), "%d",
+ values[i]->range.lower);
+ else
+ snprintf(string, sizeof (string), "%d-%d",
+ values[i]->range.lower,
+ values[i]->range.upper);
rc = strlcat(buffer, string, buflen);
}
break;
@@ -1013,18 +938,9 @@ papiAttributeToString(papi_attribute_t *attribute, char *delim,
break;
case PAPI_COLLECTION: {
char *string = alloca(buflen);
-#ifdef DEBUG
- char prefix[256];
- snprintf(prefix, sizeof (prefix), "%s %s(%d) ", delim,
- attribute->name, i);
-
- papiAttributeListToString(values[i]->collection,
- prefix, string, buflen);
-#else
papiAttributeListToString(values[i]->collection,
delim, string, buflen);
-#endif
rc = strlcat(buffer, string, buflen);
}
break;
@@ -1061,9 +977,6 @@ papiAttributeListToString(papi_attribute_t **attrs,
if (!delim)
delim = " ";
-#ifdef DEBUG
- strlcat(buffer, delim, buflen);
-#endif
for (i = 0; ((attrs[i] != NULL) && (status == PAPI_OK)); i++) {
status = papiAttributeToString(attrs[i], delim, buffer, buflen);
if (attrs[i+1] != NULL)
diff --git a/usr/src/lib/print/libpapi-lpd/common/lpd-job.c b/usr/src/lib/print/libpapi-lpd/common/lpd-job.c
index 359e4230d2..5a2cb26fa6 100644
--- a/usr/src/lib/print/libpapi-lpd/common/lpd-job.c
+++ b/usr/src/lib/print/libpapi-lpd/common/lpd-job.c
@@ -331,6 +331,7 @@ static papi_status_t
lpd_add_svr4_attributes(service_t *svc, papi_attribute_t **attributes,
char **metadata, papi_attribute_t ***used)
{
+ papi_attribute_t *tmp[2];
char *s;
int integer;
@@ -348,37 +349,44 @@ lpd_add_svr4_attributes(service_t *svc, papi_attribute_t **attributes,
/* Handling */
s = NULL;
- papiAttributeListGetString(attributes, NULL, "job_hold_until", &s);
+ papiAttributeListGetString(attributes, NULL, "job-hold-until", &s);
if ((s != NULL) && (strcmp(s, "indefinite"))) {
add_svr4_control_line(metadata, 'H', "hold");
papiAttributeListAddString(used, PAPI_ATTR_EXCL,
- "media", "hold");
+ "job-hold-until", "indefinite");
} else if ((s != NULL) && (strcmp(s, "no-hold"))) {
- add_svr4_control_line(metadata, 'H', "release");
+ add_svr4_control_line(metadata, 'H', "immediate");
papiAttributeListAddString(used, PAPI_ATTR_EXCL,
- "media", "release");
- } else if ((s != NULL) && (strcmp(s, "immediate"))) {
- add_int_control_line(metadata, 'q', 0, LPD_SVR4);
+ "job-hold-until", "no-hold");
+ } else if (s != NULL) {
+ add_svr4_control_line(metadata, 'H', s);
papiAttributeListAddString(used, PAPI_ATTR_EXCL,
- "media", "immediate");
+ "job-hold-until", s);
}
/* Pages */
s = NULL;
- papiAttributeListGetString(attributes, NULL, "page-ranges", &s);
- if (s != NULL) {
- add_svr4_control_line(metadata, 'P', s);
- papiAttributeListAddString(used, PAPI_ATTR_EXCL,
- "page-ranges", s);
+ memset(tmp, NULL, sizeof (tmp));
+ tmp[0] = papiAttributeListFind(attributes, "page-ranges");
+ if (tmp[0] != NULL) {
+ char buf[BUFSIZ];
+
+ papiAttributeListToString(tmp, " ", buf, sizeof (buf));
+ if ((s = strchr(buf, '=')) != NULL) {
+ add_svr4_control_line(metadata, 'P', ++s);
+ papiAttributeListAddString(used, PAPI_ATTR_EXCL,
+ "page-ranges", s);
+ }
}
/* Priority : lp -q */
integer = -1;
- papiAttributeListGetInteger(attributes, NULL, "priority", &integer);
+ papiAttributeListGetInteger(attributes, NULL, "job-priority", &integer);
if (integer != -1) {
+ integer = 40 - (integer / 2.5);
add_int_control_line(metadata, 'q', integer, LPD_SVR4);
papiAttributeListAddInteger(used, PAPI_ATTR_EXCL,
- "priority", integer);
+ "job-priority", integer);
}
/* Charset : lp -S */