1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 * 26 */ 27 28 /* $Id: accept.c 146 2006-03-24 00:26:54Z njacobs $ */ 29 30 #include <stdio.h> 31 #include <stdlib.h> 32 #include <unistd.h> 33 #include <string.h> 34 #include <locale.h> 35 #include <libintl.h> 36 #include <papi.h> 37 #include "common.h" 38 39 static void 40 usage(char *program) 41 { 42 char *name; 43 44 if ((name = strrchr(program, '/')) == NULL) 45 name = program; 46 else 47 name++; 48 49 fprintf(stdout, 50 gettext("Usage: %s destination ...\n"), 51 name); 52 exit(1); 53 } 54 55 int 56 main(int ac, char *av[]) 57 { 58 papi_status_t status; 59 papi_service_t svc = NULL; 60 papi_encryption_t encryption = PAPI_ENCRYPT_NEVER; 61 int exit_status = 0; 62 int c; 63 64 (void) setlocale(LC_ALL, ""); 65 (void) textdomain("SUNW_OST_OSCMD"); 66 67 while ((c = getopt(ac, av, "E")) != EOF) 68 switch (c) { 69 case 'E': 70 encryption = PAPI_ENCRYPT_ALWAYS; 71 break; 72 default: 73 usage(av[0]); 74 } 75 76 if (ac == optind) 77 usage(av[0]); 78 79 for (c = optind; c < ac; c++) { 80 char *printer = av[c]; 81 82 status = papiServiceCreate(&svc, printer, NULL, NULL, 83 cli_auth_callback, encryption, NULL); 84 if (status != PAPI_OK) { 85 fprintf(stderr, gettext( 86 "Failed to contact service for %s: %s\n"), 87 printer, verbose_papi_message(svc, status)); 88 exit_status = 1; 89 } 90 91 status = papiPrinterResume(svc, printer); 92 if (status == PAPI_OK) { 93 printf(gettext( 94 "Destination \"%s\" now accepting requests\n"), 95 printer); 96 } else if (status == PAPI_NOT_ACCEPTING) { 97 fprintf(stderr, gettext( 98 "Destination \"%s\" was already " 99 "accepting requests.\n"), printer); 100 exit_status = 1; 101 } else { 102 fprintf(stderr, gettext("accept: %s: %s\n"), printer, 103 verbose_papi_message(svc, status)); 104 exit_status = 1; 105 } 106 107 papiServiceDestroy(svc); 108 } 109 110 return (exit_status); 111 } 112