common.c revision 40e7ce05bde825a43b0db32ded62db8cc5b6ec9c
/*
* 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.
*
*/
/* $Id: common.c 162 2006-05-08 14:17:44Z njacobs $ */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <alloca.h>
#include <string.h>
#include <libintl.h>
#include <ctype.h>
#include <pwd.h>
#include <papi.h>
#include "common.h"
#ifndef HAVE_GETPASSPHRASE /* some systems don't have getpassphrase() */
#define getpassphrase getpass
#endif
/* give the most verbose error message to the caller */
char *
{
char *mesg;
return (mesg);
}
static int
{
int i;
for (i = 0; i < ac; i++)
return (0); /* "current" user match */
return (0); /* job-id match */
return (0); /* user match */
return (-1);
}
static struct {
char *mime_type;
char *lp_type;
} type_map[] = {
{ "application/octet-stream", "raw" },
{ "application/octet-stream", "any" },
{ "application/postscript", "postscript" },
{ "application/postscript", "ps" },
{ "application/x-cif", "cif" },
{ "application/x-dvi", "dvi" },
{ "application/x-plot", "plot" },
{ "application/x-ditroff", "troff" },
{ "application/x-troff", "otroff" },
{ "application/x-pr", "pr" },
{ "application/x-fortran", "fortran" },
{ "application/x-raster", "raster" },
};
char *
lp_type_to_mime_type(char *lp_type)
{
int i;
return ("application/octet-stream");
return (lp_type);
}
/*
*/
static char *
state_string(int state)
{
switch (state) {
case 3:
return (gettext("idle"));
case 4:
return (gettext("processing"));
case 5:
return (gettext("stopped"));
default:
return (gettext("unknown"));
}
}
static char *_rank_suffixes[] = {
"th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th"
};
static char *
rank_string(const int rank)
{
static char buf[12];
if (rank < 0)
else if (rank == 0)
else
return (buf);
}
static void
{
int state = 0;
char *reason = "";
"printer-state", &state);
"printer-state-reasons", &reason);
"printer-name", &name);
else
} else
}
static void
{
}
static void
{
char *name = "print job";
char *user = "nobody";
char *host = "localhost";
char *suffix = "k";
"job-id", &id);
"job-id-requested", &id);
"job-originating-user-name", &user);
"job-originating-host-name", &host);
/* if we are looking and it doesn't match, return early */
return;
"copies", &copies);
"number-of-intervening-jobs", &rank);
== PAPI_OK)
suffix = "bytes";
else
"job-k-octets", &size);
"job-name", &name);
if (fmt == 3) {
} else
"\n%s: %s\t\t\t\t[job %d %s]\n\t%-32.32s\t%d %s\n"),
suffix);
}
/*
* to support job cancelation
*/
static void
{
int id = 0;
int rid = 0;
char *user = "";
"job-id", &id);
"job-id-requested", &rid);
"job-originating-user-name", &user);
/* if we are looking and it doesn't match, return early */
return;
if (rid != 0)
else
}
int
{
papi_printer_t p = NULL;
"printer-state-reasons", NULL };
"job-originating-user-name", "job-id-requested",
"job-originating-host-name",
"number-of-intervening-jobs", NULL };
int num_jobs = 0;
"Failed to query service for state of %s: %s\n"),
return (-1);
}
0, &jobs);
"Failed to query service for jobs on %s: %s\n"),
return (-1);
}
num_jobs++;
}
if (num_jobs > 0) {
int i;
if (fmt == 3)
}
papiPrinterFree(p);
return (num_jobs);
}
int
{
"job-id-requested", NULL };
0, &jobs);
return (-1);
}
/* cancel the job(s) */
int i;
}
return (0);
}
int
{
int result = -1;
if (p != NULL) {
char *s = NULL;
if (s[0] != '\0')
*id = -1;
else
*p = '\0';
result = 0;
} else
*id = -1;
}
return (result);
}
/*
* strsplit() splits a string into a NULL terminated array of substrings
* determined by a seperator. The original string is modified, and newly
* allocated space is only returned for the array itself. If more than
* 1024 substrings exist, they will be ignored.
*/
char **
{
**result;
int length = 0;
return (NULL);
length++;
return (result);
}
{
int rc;
if (len > 0)
return (status);
}
/*
* is_postscript() will detect if the file passed in contains postscript
* data. A one is returned if the file contains postscript, zero is returned
* if the file is not postscript, and -1 is returned if an error occurs
*/
#define PS_MAGIC "%!"
#define PC_PS_MAGIC "^D%!"
int
{
return (-1);
}
return (1);
else
return (0);
}
int
is_postscript(const char *file)
{
int rc = -1;
int fd;
char buf[3];
}
return (rc);
}
static char **
{
if (attributes != NULL) {
}
}
return (result);
}
static char **
{
int i;
"printer-name", &name);
}
}
return (result);
}
char **
{
static char been_here;
static char **result;
if (been_here == 0) { /* only do this once */
been_here = 1;
}
return (result);
}
char *
{
static char *result;
static char buf[256];
}
return (result);
}
int
{
/* get the name of the service we are contacting */
return (-1);
/* find our who we are supposed to be */
else
user = "nobody";
}
/* build the prompt string */
/* ask for the passphrase */
return (0);
}