1*9855SNagaraj.Yedathore@Sun.COM 22264Sjacobs /* 32264Sjacobs * CDDL HEADER START 42264Sjacobs * 52264Sjacobs * The contents of this file are subject to the terms of the 62264Sjacobs * Common Development and Distribution License (the "License"). 72264Sjacobs * You may not use this file except in compliance with the License. 82264Sjacobs * 92264Sjacobs * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 102264Sjacobs * or http://www.opensolaris.org/os/licensing. 112264Sjacobs * See the License for the specific language governing permissions 122264Sjacobs * and limitations under the License. 132264Sjacobs * 142264Sjacobs * When distributing Covered Code, include this CDDL HEADER in each 152264Sjacobs * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 162264Sjacobs * If applicable, add the following below this CDDL HEADER, with the 172264Sjacobs * fields enclosed by brackets "[]" replaced with your own identifying 182264Sjacobs * information: Portions Copyright [yyyy] [name of copyright owner] 192264Sjacobs * 202264Sjacobs * CDDL HEADER END 212264Sjacobs */ 222264Sjacobs 232264Sjacobs /* 249376SGowtham.Thommandra@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 252264Sjacobs * Use is subject to license terms. 262264Sjacobs * 272264Sjacobs */ 282264Sjacobs 292264Sjacobs /* $Id: accept.c 146 2006-03-24 00:26:54Z njacobs $ */ 302264Sjacobs 312264Sjacobs #include <stdio.h> 322264Sjacobs #include <stdlib.h> 332264Sjacobs #include <unistd.h> 342264Sjacobs #include <string.h> 352264Sjacobs #include <locale.h> 362264Sjacobs #include <libintl.h> 372264Sjacobs #include <papi.h> 382264Sjacobs #include "common.h" 392264Sjacobs 402264Sjacobs static void 412264Sjacobs usage(char *program) 422264Sjacobs { 432264Sjacobs char *name; 442264Sjacobs 452264Sjacobs if ((name = strrchr(program, '/')) == NULL) 462264Sjacobs name = program; 472264Sjacobs else 482264Sjacobs name++; 492264Sjacobs 502264Sjacobs fprintf(stdout, 519376SGowtham.Thommandra@Sun.COM gettext("Usage: %s destination ...\n"), 529376SGowtham.Thommandra@Sun.COM name); 532264Sjacobs exit(1); 542264Sjacobs } 552264Sjacobs 562264Sjacobs int 572264Sjacobs main(int ac, char *av[]) 582264Sjacobs { 592264Sjacobs papi_status_t status; 602264Sjacobs papi_service_t svc = NULL; 612264Sjacobs papi_encryption_t encryption = PAPI_ENCRYPT_NEVER; 622264Sjacobs int exit_status = 0; 632264Sjacobs int c; 642264Sjacobs 652264Sjacobs (void) setlocale(LC_ALL, ""); 662264Sjacobs (void) textdomain("SUNW_OST_OSCMD"); 672264Sjacobs 682264Sjacobs while ((c = getopt(ac, av, "E")) != EOF) 692264Sjacobs switch (c) { 702264Sjacobs case 'E': 712264Sjacobs encryption = PAPI_ENCRYPT_ALWAYS; 722264Sjacobs break; 732264Sjacobs default: 742264Sjacobs usage(av[0]); 752264Sjacobs } 762264Sjacobs 772264Sjacobs if (ac == optind) 782264Sjacobs usage(av[0]); 792264Sjacobs 802264Sjacobs for (c = optind; c < ac; c++) { 812264Sjacobs char *printer = av[c]; 822264Sjacobs 832264Sjacobs status = papiServiceCreate(&svc, printer, NULL, NULL, 849376SGowtham.Thommandra@Sun.COM cli_auth_callback, encryption, NULL); 852264Sjacobs if (status != PAPI_OK) { 862264Sjacobs fprintf(stderr, gettext( 879376SGowtham.Thommandra@Sun.COM "Failed to contact service for %s: %s\n"), 889376SGowtham.Thommandra@Sun.COM printer, verbose_papi_message(svc, status)); 892264Sjacobs exit_status = 1; 902264Sjacobs } 912264Sjacobs 922264Sjacobs status = papiPrinterResume(svc, printer); 939376SGowtham.Thommandra@Sun.COM if (status == PAPI_OK) { 949376SGowtham.Thommandra@Sun.COM printf(gettext( 959376SGowtham.Thommandra@Sun.COM "Destination \"%s\" now accepting requests\n"), 969376SGowtham.Thommandra@Sun.COM printer); 979376SGowtham.Thommandra@Sun.COM } else if (status == PAPI_NOT_ACCEPTING) { 989376SGowtham.Thommandra@Sun.COM fprintf(stderr, gettext( 999376SGowtham.Thommandra@Sun.COM "Destination \"%s\" was already " 1009376SGowtham.Thommandra@Sun.COM "accepting requests.\n"), printer); 1019376SGowtham.Thommandra@Sun.COM exit_status = 1; 1029376SGowtham.Thommandra@Sun.COM } else { 103*9855SNagaraj.Yedathore@Sun.COM if (status == PAPI_OPERATION_NOT_SUPPORTED) { 104*9855SNagaraj.Yedathore@Sun.COM fprintf(stderr, 105*9855SNagaraj.Yedathore@Sun.COM verbose_papi_message(svc, status)); 106*9855SNagaraj.Yedathore@Sun.COM } else { 107*9855SNagaraj.Yedathore@Sun.COM fprintf(stderr, gettext("accept: %s: %s\n"), 108*9855SNagaraj.Yedathore@Sun.COM printer, verbose_papi_message(svc, status)); 109*9855SNagaraj.Yedathore@Sun.COM exit_status = 1; 110*9855SNagaraj.Yedathore@Sun.COM } 1112264Sjacobs } 1122264Sjacobs 1132264Sjacobs papiServiceDestroy(svc); 1142264Sjacobs } 1152264Sjacobs 1162264Sjacobs return (exit_status); 1172264Sjacobs } 118