lpd-query.c revision 4bd2082ff2d009263265d7de938de336894b6009
/*
* 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 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
*/
/* $Id: lpd-query.c 155 2006-04-26 02:34:54Z ktou $ */
#pragma ident "%Z%%M% %I% %E% SMI"
#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.
*/
static char *job_expr = "^(.*[[:alnum:]]):[[:space:]]+([[:alnum:]]+)[[:space:]]+[[][[:space:]]*job[[:space:]]*([[:digit:]]+)[[:space:]]*(.*)]";
/*
* status line(s) for "processing" printers will contain one of the following:
* ready and printing
* Printing
*/
static char *proc_expr = "(ready and printing|printing)";
/*
* status line(s) for "idle" printers will contain one of the following:
* no entries
* (printer) is ready
* idle
*/
static char *idle_expr = "(no entries|is ready| idle)";
/*
* 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
*/
static char *doc1_expr = "[[:space:]]+(([[:digit:]]+) copies of )([^[:space:]]+)[[:space:]]*([[:digit:]]+) bytes";
static char *doc2_expr = "[[:space:]]+()([^[:space:]]+)[[:space:]]*([[:digit:]]+) bytes";
static void
{
char *s;
int octets = 0;
/* job_re was compiled in the calling function */
return;
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 line[128];
char status[1024];
char *s;
"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 ...]
*/
status[0] = '\0';
}
/* chop off trailing whitespace */
*s-- = '\0';
"printer-state-reasons", status);
else
"printer-state", state);
return;
== NULL)
return;
/* process job related entries */
while (line[0] != '\0') {
break;
}
}
void
{
int fd;
return;
return;
return;
}
{
return (PAPI_BAD_ARGUMENT);
} else
return (result);
}
{
}
}
return (result);
}
{
int i;
int id = -1;
"job-id", &id);
}
}
return (result);
}
void
{
}
}