/*
* 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
*/
/*
*/
/* $Id: lpd-query.c 155 2006-04-26 02:34:54Z ktou $ */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <ctype.h>
#include <string.h>
#include <stdarg.h>
#include <regex.h>
#include <papi_impl.h>
/* The string is modified by this call */
static char *
{
}
return (result);
}
/*
* Print job entries start with:
* (user): (rank) [job (number) (...)]
* (user) is the job-owner's user name
* (rank) is the rank in queue. (active, 1st, 2nd, ...)
* (number) is the job number
* (...) is an optional hostname
* some servers will use whitespace a little differently than is displayed
* above. The regular expression below makes whitespace optional in some
* places.
*/
"[[:space:]]+[[][[:space:]]*job[[:space:]]*([[:digit:]]+)"\
"[[:space:]]*(.*)]";
/*
* Print job entries for remote windows printer start with:
* Owner Status Jobname Job-Id Size Pages Priority
* e.g:
* Owner Status Jobname Job-Id Size Pages Priority
* ------------------------------------------------------------
*
* Owner is the job-owner's user name
* Status is the job-status (printing, waiting, error)
* Jobname is the name of the job to be printed
* Job-Id is the id of the job queued to be printed
* Size is the size of the job in bytes
* Pages is the number of pages of the job
* Priority is the job-priority
*/
"+([[:alnum:]]+)[[:space:]]+(.*)([[:alnum:]]+)(.*)[[:space:]]+"\
"([[:digit:]]+)[[:space:]]+([[:digit:]]+)[[:space:]]+([[:digit:]]+)"\
"[[:space:]]+([[:digit:]]+)";
/*
* Windows job header is in the following format
* Owner Status Jobname Job-Id Size Pages Priority
* --------------------------------------------------------------
*/
" Size Pages Priority";
/*
* status line(s) for "processing" printers will contain one of the following:
* ready and printing
* Printing
* processing
*/
/*
* status line(s) for "idle" printers will contain one of the following:
* no entries
* (printer) is ready
* idle
*/
/*
* Printer state reason (For Windows remote printers)
* Paused
*/
/*
* document line(s)
* (copies) copies of (name) (size) bytes
* (name) (size) bytes
* document lines can be in either format above.
* (copies) is the number of copies of the document to print
* (size) is the number of bytes in the document data
*/
"([^[:space:]]+)[[:space:]]*([[:digit:]]+) bytes";
"([[:digit:]]+) bytes";
/* Printer-state for Windows */
static void
{
char *s;
int octets = 0;
int flag = 0;
/*
* job_re and wjob_re were compiled in the calling function
* first check for solaris jobs
* if there is no-match check for windows jobs
*/
== REG_NOMATCH)
return;
else
flag = 1;
}
if (flag == 1) {
/* Windows job */
/* first match is job-id */
s = "nobody";
"job-originating-user-name", s);
s = "unknown";
"job-name", s);
"job-file-names", s);
s = "0";
"job-id", atoi(s));
s = "0";
/*
* Since a job has been found so the printer state is either
* 'stopped' or 'processing'
* By default it is "processing"
*/
win_state = 0x04;
} else {
/* Solaris job */
s = "nobody";
"job-originating-user-name", s);
s = "0";
s = "0";
"job-id", atoi(s));
"job-originating-host-name", s);
}
/* doc1_re and doc2_re were compiled in the calling function */
continue;
s = "1";
copies = 1;
s = "unknown";
PAPI_ATTR_APPEND, "job-name", s);
PAPI_ATTR_APPEND, "job-file-names", s);
s = "0";
}
"job-octets", octets);
}
void
{
char *s;
int win_flag = 0;
"printer-uri-supported", status);
/*
* on most systems, status is a single line, but some appear to
* return multi-line status messages. To get the "best" possible
* printer-state-reason, we accumulate the text until we hit the
* first print job entry.
*
* Print job entries start with:
* user: rank [job number ...]
*/
/*
* For remote windows printers
* Print job entries start with:
* Owner Status Jobname Job-Id Size Pages Priority
*/
status[0] = '\0';
/*
* When windows job queue gets queried following header
* should not get printed
* Owner Status Jobname Job-Id Size Pages Priority
* -----------------------------------------------
*/
== REG_NOMATCH) &&
== REG_NOMATCH))
}
/* chop off trailing whitespace */
*s-- = '\0';
"printer-state-reasons", status);
/* Check if this is for Windows remote printers */
/*
* It is a remote windows printer
* By default set the status as idle
* Set the printer-state after call to "parse_lpd_job"
*/
win_flag = 1;
} else {
else
"printer-state", state);
}
return;
== NULL)
return;
/* process job related entries */
while (line[0] != '\0') {
break;
}
/*
* For remote windows printer set the printer-state
* after parse_lpd_job
*/
if (win_flag) {
if (state == 0x05)
"printer-state", win_state);
}
}
void
{
int fd;
return;
} else
return;
}
return;
}
{
return (PAPI_BAD_ARGUMENT);
} else
return (result);
}
{
}
}
/*
* cache jobs is free()-ed in
* papiPrinterListJobs() cache printer is
* free()-ed by the caller of
* lpd_find_printer_info Invalidate the
* cache by freeing the cache.
*/
return (result);
}
{
int i;
"job-id", &id);
}
}
return (result);
}
void
{
}
}