job.c revision e061a5d7a75180eab31acb1289368162e020bc71
/*
* 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
* 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 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*LINTLIBRARY*/
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <libintl.h>
#include <pwd.h>
#include <papi_impl.h>
/*
* for an older application that may have been linked with a pre-v1.0
* PAPI implementation.
*/
{
}
#ifdef LP_USE_PAPI_ATTR
papi_attribute_t ***newAttrs);
#endif
void
{
}
}
void
{
int i;
papiJobFree(jobs[i]);
}
}
}
{
return (tmp->attributes);
return (NULL);
}
char *
{
"printer-name", &result);
return (result);
}
{
int result = -1;
&result);
return (result);
}
static REQUEST *
{
REQUEST *r;
r->priority = -1;
"job-originating-host-name", &hostname);
"job-originating-host-name",
host);
}
}
return (r);
}
static papi_status_t
{
char file[32];
REQUEST *r;
"user-name", &user);
}
else {
/*
* user and r->user might contain the
* host info also
*/
/*
* token1 and token3 contain usernames
* token2 and token4 contain hostnames
*/
/*
* cancel any requset
*/
/*
* usernames are same
* compare the hostnames
*/
0)) {
/*
* Its server machine
*/
static char host[256];
if (gethostname(host,
sizeof (host)) == 0) {
token2) == 0))
result =
}
/*
* When the request is sent from
* client to server using ipp
* token4 is NULL
*/
}
}
}
}
freerequest(r);
} else
return (result);
}
static papi_status_t
{
int rc;
return (PAPI_DOCUMENT_ACCESS_ERROR);
return (PAPI_NOT_POSSIBLE);
}
return (PAPI_OK);
}
#ifdef LP_USE_PAPI_ATTR
/*
* *****************************************************************************
*
* Description: Create a file containing all the attributes in the attribute
* list passed to this function.
* This file is then passed through lpsched and given to either
* a slow-filter or to the printer's interface script to process
* the attributes.
*
* Parameters: attrs - list of attributes and their values
* file - file pathname to create and put the attributes into.
*
* *****************************************************************************
*/
static papi_status_t
{
} else {
}
}
return (result);
} /* psm_copy_attrsToFile */
/*
* *****************************************************************************
*
* Description: Modify the given attribute 'file' with the attributes from the
* 'attrs' list. Attributes already in the file will be replaced
* with the new value. New attributes will be added into the file.
*
* Parameters: attrs - list of attributes and their values
* file - file pathname to create and put the attributes into.
*
* *****************************************************************************
*/
static papi_status_t
{
/*
* check file exist before try to modify it, if it doesn't
* exist assume there is an error
*/
/*
* 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
*/
newAttrs, "");
} else {
}
} else {
result =
newAttrs, "");
} else {
}
}
} else {
}
}
return (result);
} /* psm_modifyAttrsFile */
/*
* *****************************************************************************
*
* Description: Extracts the attributes in the given attribute 'file' and
* creates a new list 'newAttrs' containing the modified list of
* attributes.
*
* Parameters: file - pathname of file containing attributes to be modified
* attrs - list of attributes and their values to modify
* newAttrs - returns the modified list of attributes
*
* *****************************************************************************
*/
static papi_status_t
{
register int fD = 0;
char aBuff[200];
char *a = NULL;
char *p = NULL;
int count = 0;
int n = 0;
a = &aBuff[0];
p = &aBuff[0];
if (p != NULL) {
/* terminate at last complete line */
*p = '\0';
}
}
/*
* handle any part lines and then read the next
* buffer from the file
*/
n = 0;
if (p != a) {
p++; /* skip NL */
n = sizeof (aBuff) - 1 - (p - a);
}
sizeof (aBuff) - n - 1);
p = &aBuff[0];
}
}
}
/* now modify the attribute list with the new attributes in 'attrs' */
values++;
}
values++;
}
nextAttr =
}
return (result);
} /* papi_modifyAttrsList() */
#endif
{
job_t *j;
int file_no;
char *request_id = NULL;
int i;
char *c;
return (PAPI_BAD_ARGUMENT);
if (job_ticket != NULL)
return (PAPI_OPERATION_NOT_SUPPORTED);
gettext("Cannot access file: %s: %s"),
return (PAPI_BAD_ARGUMENT);
}
gettext("Cannot access file: %s: %s"),
return (PAPI_DOCUMENT_ACCESS_ERROR);
}
gettext("Zero byte (empty) file: %s"),
return (PAPI_BAD_ARGUMENT);
}
}
return (PAPI_TEMPORARY_ERROR);
/* file_no + 1 for the control file (-0) */
return (status);
gettext("unable to copy: %s -> %s: %s"),
return (PAPI_DEVICE_ERROR);
}
}
#ifdef LP_USE_PAPI_ATTR
/*
* store the job attributes in the PAPI job attribute file that was
* created by lpsched_alloc_files(), the attributes will then pass
* through lpsched and be given to the slow-filters and the printer's
* interface script to process them
*/
return (PAPI_DEVICE_ERROR);
}
#endif
/* store the meta-data file */
return (PAPI_DEVICE_ERROR);
}
return (status);
}
c++;
"job-id", atoi(c));
"job-uri", tmp);
return (PAPI_OK);
}
{
job_t *j;
int file_no;
short status;
char *request_id = NULL;
char *c;
return (PAPI_BAD_ARGUMENT);
if (job_ticket != NULL)
return (PAPI_OPERATION_NOT_SUPPORTED);
gettext("Cannot access file: %s: %s"),
return (PAPI_DOCUMENT_ACCESS_ERROR);
}
gettext("Cannot access file: %s: %s"),
return (PAPI_DOCUMENT_ACCESS_ERROR);
}
gettext("Zero byte (empty) file: %s"),
return (PAPI_BAD_ARGUMENT);
}
char path[MAXPATHLEN];
"getcwd for file: %s: %s"),
return (PAPI_DOCUMENT_ACCESS_ERROR);
}
>= sizeof (path)) {
"pathname too long: %s"),
return (PAPI_DOCUMENT_ACCESS_ERROR);
}
} else
}
return (PAPI_TEMPORARY_ERROR);
/* 1 for the control file (-0) */
return (status);
#ifdef LP_USE_PAPI_ATTR
/*
* store the job attributes in the PAPI job attribute file that was
* created by lpsched_alloc_files(), the attributes will then pass
* through lpsched and be given to the slow-filters and the printer's
* interface script to process them
*/
return (PAPI_DEVICE_ERROR);
}
#endif
/* store the meta-data file */
return (PAPI_DEVICE_ERROR);
}
return (status);
}
c++;
"job-id", atoi(c));
"job-uri", tmp);
return (PAPI_OK);
}
{
int i;
"job-hold-until", "indefinite");
for (i = 0; job_attributes[i]; i++)
if (id != -1)
}
return (status);
}
{
job_stream_t *s = NULL;
char *request_id = NULL;
return (PAPI_BAD_ARGUMENT);
if (job_ticket != NULL)
return (PAPI_OPERATION_NOT_SUPPORTED);
return (PAPI_TEMPORARY_ERROR);
/* 1 for data, 1 for the meta-data (-0) */
return (status);
#ifdef LP_USE_PAPI_ATTR
/*
* store the job attributes in the PAPI job attribute file that was
* created by lpsched_alloc_files(), the attributes will then pass
* through lpsched and be given to the slow-filters and the printer's
* interface script to process them
*/
free(s);
return (PAPI_DEVICE_ERROR);
}
#endif
/* store the meta-data file */
return (PAPI_DEVICE_ERROR);
}
return (PAPI_OK);
}
{
job_stream_t *s = stream;
return (PAPI_BAD_ARGUMENT);
return (PAPI_DEVICE_ERROR);
return (PAPI_OK);
}
{
job_stream_t *s = stream;
return (PAPI_BAD_ARGUMENT);
return (PAPI_TEMPORARY_ERROR);
if (s->meta_data_file != NULL) {
unlink(s->meta_data_file);
return (status);
}
c++;
"job-id", atoi(c));
"job-uri", tmp);
free(s->meta_data_file);
}
freerequest(s->request);
free(s);
return (PAPI_OK);
}
char **requested_attrs,
{
job_t *j;
char *dest;
char req_id[32];
short rc;
*request_id = NULL,
short rank = 0,
state = 0;
return (PAPI_BAD_ARGUMENT);
if (rc < 0)
return (PAPI_SERVICE_UNAVAILABLE);
gettext("failed to read response from scheduler"));
return (PAPI_DEVICE_ERROR);
}
return (PAPI_NOT_FOUND);
return (PAPI_TEMPORARY_ERROR);
return (PAPI_OK);
}
char *destination)
{
long bits;
char req_id[64];
char *queue;
(destination == NULL))
return (PAPI_BAD_ARGUMENT);
freerequest(r);
}
}
return (result);
}
{
char req_id[64];
char *dest;
return (PAPI_BAD_ARGUMENT);
freerequest(r);
}
}
return (result);
}
{
char *file;
char *dest;
return (PAPI_BAD_ARGUMENT);
return (status);
return (status);
r->actions &= ~ACT_RESUME;
switch (flag) {
case 0:
break;
case 1:
r->actions |= ACT_RESUME;
break;
case 2:
r->actions |= ACT_IMMEDIATE;
break;
}
if (putrequest(file, r) < 0) {
gettext("failed to write job: %s: %s"),
freerequest(r);
return (PAPI_DEVICE_ERROR);
}
freerequest(r);
} else {
return (PAPI_DEVICE_ERROR);
}
return (status);
}
{
}
{
}
{
}
{
char *dest;
(attributes == NULL))
return (PAPI_BAD_ARGUMENT);
return (PAPI_TEMPORARY_ERROR);
return (status);
(papi_attribute_t **)attributes);
#ifdef LP_USE_PAPI_ATTR
/*
* store the job attributes in the PAPI job attribute file
* that was created by the origonal job request. We need to
* modify the attributes in the file as per the new attributes
*/
"unable to modify the attributes file: %s: %s",
return (PAPI_DEVICE_ERROR);
}
#endif
if (putrequest(file, r) < 0) {
gettext("failed to write job: %s: %s"),
freerequest(r);
return (PAPI_DEVICE_ERROR);
}
} else {
return (PAPI_DEVICE_ERROR);
}
"job-id", job_id);
freerequest(r);
return (status);
}
/*
* Extension to PAPI, a variation of this is slated for post-1.0
*/
{
char *request_id = NULL;
char *c;
char metadata_file[MAXPATHLEN];
return (PAPI_BAD_ARGUMENT);
if (job_ticket != NULL)
return (PAPI_JOB_TICKET_NOT_SUPPORTED);
return (PAPI_TEMPORARY_ERROR);
/* 1 for the control file (-0) */
return (status);
/* convert the attributes to an lpsched REQUEST structure */
return (PAPI_TEMPORARY_ERROR);
#ifdef LP_USE_PAPI_ATTR
/*
* store the job attributes in the PAPI job attribute file that was
* created by lpsched_alloc_files(), the attributes will then pass
* through lpsched and be given to the slow-filters and the printer's
* interface script to process them
*/
return (PAPI_DEVICE_ERROR);
}
#endif
/* store the REQUEST on disk */
return (PAPI_DEVICE_ERROR);
}
return (status);
}
c++;
"job-id", atoi(c));
"job-uri", tmp);
return (PAPI_OK);
}
{
char *metadata_file;
char *dest;
return (PAPI_BAD_ARGUMENT);
/* tell the scheduler that we want to change the job */
return (status);
r->actions &= ~ACT_RESUME;
r->actions |= ACT_RESUME;
if (putrequest(metadata_file, r) < 0) {
gettext("failed to write job: %s: %s"),
freerequest(r);
return (PAPI_DEVICE_ERROR);
}
} else {
return (PAPI_DEVICE_ERROR);
}
freerequest(r);
return (status);
}
{
job_stream_t *s = NULL;
char *metadata_file = NULL;
char *dest;
char path[MAXPATHLEN];
/* allocate space for the stream */
return (PAPI_TEMPORARY_ERROR);
free(s);
return (PAPI_NOT_AUTHORIZED);
}
/* add data file to job */
free(s);
return (status);
}
free(s);
return (PAPI_NOT_POSSIBLE);
}
free(s);
return (PAPI_NOT_POSSIBLE);
}
return (status);
return (PAPI_OK);
}