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