xref: /titanic_54/usr/src/cmd/print/bsd-sysv-commands/accept.c (revision 98f04078d5fc5800e80b21e0b18abe0024af1cbe)
1355b4669Sjacobs /*
2355b4669Sjacobs  * CDDL HEADER START
3355b4669Sjacobs  *
4355b4669Sjacobs  * The contents of this file are subject to the terms of the
5355b4669Sjacobs  * Common Development and Distribution License (the "License").
6355b4669Sjacobs  * You may not use this file except in compliance with the License.
7355b4669Sjacobs  *
8355b4669Sjacobs  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9355b4669Sjacobs  * or http://www.opensolaris.org/os/licensing.
10355b4669Sjacobs  * See the License for the specific language governing permissions
11355b4669Sjacobs  * and limitations under the License.
12355b4669Sjacobs  *
13355b4669Sjacobs  * When distributing Covered Code, include this CDDL HEADER in each
14355b4669Sjacobs  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15355b4669Sjacobs  * If applicable, add the following below this CDDL HEADER, with the
16355b4669Sjacobs  * fields enclosed by brackets "[]" replaced with your own identifying
17355b4669Sjacobs  * information: Portions Copyright [yyyy] [name of copyright owner]
18355b4669Sjacobs  *
19355b4669Sjacobs  * CDDL HEADER END
20355b4669Sjacobs  */
21355b4669Sjacobs 
22355b4669Sjacobs /*
23*98f04078SGowtham Thommandra  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24355b4669Sjacobs  * Use is subject to license terms.
25355b4669Sjacobs  *
26355b4669Sjacobs  */
27355b4669Sjacobs 
28355b4669Sjacobs /* $Id: accept.c 146 2006-03-24 00:26:54Z njacobs $ */
29355b4669Sjacobs 
30355b4669Sjacobs #include <stdio.h>
31355b4669Sjacobs #include <stdlib.h>
32355b4669Sjacobs #include <unistd.h>
33355b4669Sjacobs #include <string.h>
34355b4669Sjacobs #include <locale.h>
35355b4669Sjacobs #include <libintl.h>
36355b4669Sjacobs #include <papi.h>
37355b4669Sjacobs #include "common.h"
38355b4669Sjacobs 
39355b4669Sjacobs static void
40355b4669Sjacobs usage(char *program)
41355b4669Sjacobs {
42355b4669Sjacobs 	char *name;
43355b4669Sjacobs 
44355b4669Sjacobs 	if ((name = strrchr(program, '/')) == NULL)
45355b4669Sjacobs 		name = program;
46355b4669Sjacobs 	else
47355b4669Sjacobs 		name++;
48355b4669Sjacobs 
49355b4669Sjacobs 	fprintf(stdout,
50355b4669Sjacobs 	    gettext("Usage: %s destination ...\n"),
51355b4669Sjacobs 	    name);
52355b4669Sjacobs 	exit(1);
53355b4669Sjacobs }
54355b4669Sjacobs 
55355b4669Sjacobs int
56355b4669Sjacobs main(int ac, char *av[])
57355b4669Sjacobs {
58355b4669Sjacobs 	papi_status_t status;
59355b4669Sjacobs 	papi_service_t svc = NULL;
60355b4669Sjacobs 	papi_encryption_t encryption = PAPI_ENCRYPT_NEVER;
61355b4669Sjacobs 	int exit_status = 0;
62355b4669Sjacobs 	int c;
63355b4669Sjacobs 
64355b4669Sjacobs 	(void) setlocale(LC_ALL, "");
65355b4669Sjacobs 	(void) textdomain("SUNW_OST_OSCMD");
66355b4669Sjacobs 
67355b4669Sjacobs 	while ((c = getopt(ac, av, "E")) != EOF)
68355b4669Sjacobs 		switch (c) {
69355b4669Sjacobs 		case 'E':
70355b4669Sjacobs 			encryption = PAPI_ENCRYPT_ALWAYS;
71355b4669Sjacobs 			break;
72355b4669Sjacobs 		default:
73355b4669Sjacobs 			usage(av[0]);
74355b4669Sjacobs 		}
75355b4669Sjacobs 
76355b4669Sjacobs 	if (ac == optind)
77355b4669Sjacobs 		usage(av[0]);
78355b4669Sjacobs 
79355b4669Sjacobs 	for (c = optind; c < ac; c++) {
80355b4669Sjacobs 		char *printer = av[c];
81355b4669Sjacobs 
82355b4669Sjacobs 		status = papiServiceCreate(&svc, printer, NULL, NULL,
83355b4669Sjacobs 		    cli_auth_callback, encryption, NULL);
84355b4669Sjacobs 		if (status != PAPI_OK) {
85355b4669Sjacobs 			fprintf(stderr, gettext(
86355b4669Sjacobs 			    "Failed to contact service for %s: %s\n"),
87355b4669Sjacobs 			    printer, verbose_papi_message(svc, status));
88355b4669Sjacobs 			exit_status = 1;
89355b4669Sjacobs 		}
90355b4669Sjacobs 
91355b4669Sjacobs 		status = papiPrinterResume(svc, printer);
92*98f04078SGowtham Thommandra 		if (status == PAPI_OK) {
93*98f04078SGowtham Thommandra 			printf(gettext(
94*98f04078SGowtham Thommandra 			    "Destination \"%s\" now accepting requests\n"),
95*98f04078SGowtham Thommandra 			    printer);
96*98f04078SGowtham Thommandra 		} else if (status == PAPI_NOT_ACCEPTING) {
97*98f04078SGowtham Thommandra 			fprintf(stderr, gettext(
98*98f04078SGowtham Thommandra 			    "Destination \"%s\" was already "
99*98f04078SGowtham Thommandra 			    "accepting requests.\n"), printer);
100*98f04078SGowtham Thommandra 			exit_status = 1;
101*98f04078SGowtham Thommandra 		} else {
102355b4669Sjacobs 			fprintf(stderr, gettext("accept: %s: %s\n"), printer,
103355b4669Sjacobs 			    verbose_papi_message(svc, status));
104355b4669Sjacobs 			exit_status = 1;
105355b4669Sjacobs 		}
106355b4669Sjacobs 
107355b4669Sjacobs 		papiServiceDestroy(svc);
108355b4669Sjacobs 	}
109355b4669Sjacobs 
110355b4669Sjacobs 	return (exit_status);
111355b4669Sjacobs }
112