lpsched-msgs.c (7c478bd95313f5f23a4c958a745db2134aa03244) | lpsched-msgs.c (355b4669e025ff377602b6fc7caaf30dbc218371) |
---|---|
1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the | 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, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. | 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. |
8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22/* | 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/* |
23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved. | 22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. |
24 * Use is subject to license terms. 25 */ 26 27#pragma ident "%Z%%M% %I% %E% SMI" 28 29/*LINTLIBRARY*/ 30 31#include <stdio.h> 32#include <stdarg.h> 33#include <libintl.h> 34#include <string.h> 35#include <stdlib.h> | 23 * Use is subject to license terms. 24 */ 25 26#pragma ident "%Z%%M% %I% %E% SMI" 27 28/*LINTLIBRARY*/ 29 30#include <stdio.h> 31#include <stdarg.h> 32#include <libintl.h> 33#include <string.h> 34#include <stdlib.h> |
35#include <errno.h> |
|
36 37 38/* lpsched include files */ 39#include "lp.h" 40#include "msgs.h" 41#include "printers.h" | 36 37 38/* lpsched include files */ 39#include "lp.h" 40#include "msgs.h" 41#include "printers.h" |
42#include "class.h" |
|
42 43#include <papi_impl.h> 44 45 46/* 47 * Format and send message to lpsched (die if any errors occur) 48 */ 49/*VARARGS1*/ --- 84 unchanged lines hidden (view full) --- 134 case MUNKNOWN: 135 case MNODEST: 136 case MNOINFO: 137 return (PAPI_NOT_FOUND); 138 case MTRANSMITERR: 139 return (PAPI_SERVICE_UNAVAILABLE); 140 case M2LATE: 141 return (PAPI_GONE); | 43 44#include <papi_impl.h> 45 46 47/* 48 * Format and send message to lpsched (die if any errors occur) 49 */ 50/*VARARGS1*/ --- 84 unchanged lines hidden (view full) --- 135 case MUNKNOWN: 136 case MNODEST: 137 case MNOINFO: 138 return (PAPI_NOT_FOUND); 139 case MTRANSMITERR: 140 return (PAPI_SERVICE_UNAVAILABLE); 141 case M2LATE: 142 return (PAPI_GONE); |
143 case MBUSY: 144 return (PAPI_PRINTER_BUSY); |
|
142 case MOK: 143 case MOKMORE: 144 return (PAPI_OK); 145 } 146 147 return (PAPI_INTERNAL_ERROR); 148} 149 --- 78 unchanged lines hidden (view full) --- 228 job, lpsched_status_string(status)); 229 result = lpsched_status_to_papi_status(status); 230 } 231 232 return (result); 233} 234 235papi_status_t | 145 case MOK: 146 case MOKMORE: 147 return (PAPI_OK); 148 } 149 150 return (PAPI_INTERNAL_ERROR); 151} 152 --- 78 unchanged lines hidden (view full) --- 231 job, lpsched_status_string(status)); 232 result = lpsched_status_to_papi_status(status); 233 } 234 235 return (result); 236} 237 238papi_status_t |
236lpsched_start_change(papi_service_t svc, const char *printer, int32_t job_id, | 239lpsched_start_change(papi_service_t svc, char *printer, int32_t job_id, |
237 char **tmp) 238{ 239 papi_status_t result = PAPI_OK; 240 short status = MOK; 241 char req[BUFSIZ]; 242 char *dest; 243 244 if ((svc == NULL) || (printer == NULL) || (job_id < 0)) --- 14 unchanged lines hidden (view full) --- 259 job_id, lpsched_status_string(status)); 260 result = lpsched_status_to_papi_status(status); 261 } 262 263 return (result); 264} 265 266papi_status_t | 240 char **tmp) 241{ 242 papi_status_t result = PAPI_OK; 243 short status = MOK; 244 char req[BUFSIZ]; 245 char *dest; 246 247 if ((svc == NULL) || (printer == NULL) || (job_id < 0)) --- 14 unchanged lines hidden (view full) --- 262 job_id, lpsched_status_string(status)); 263 result = lpsched_status_to_papi_status(status); 264 } 265 266 return (result); 267} 268 269papi_status_t |
267lpsched_end_change(papi_service_t svc, const char *printer, int32_t job_id) | 270lpsched_end_change(papi_service_t svc, char *printer, int32_t job_id) |
268{ 269 papi_status_t result = PAPI_OK; 270 short status = MOK; 271 long bits; 272 char req[BUFSIZ]; 273 char *dest; 274 275 if ((svc == NULL) || (printer == NULL) || (job_id < 0)) --- 13 unchanged lines hidden (view full) --- 289 job_id, lpsched_status_string(status)); 290 result = lpsched_status_to_papi_status(status); 291 } 292 293 return (result); 294} 295 296papi_status_t | 271{ 272 papi_status_t result = PAPI_OK; 273 short status = MOK; 274 long bits; 275 char req[BUFSIZ]; 276 char *dest; 277 278 if ((svc == NULL) || (printer == NULL) || (job_id < 0)) --- 13 unchanged lines hidden (view full) --- 292 job_id, lpsched_status_string(status)); 293 result = lpsched_status_to_papi_status(status); 294 } 295 296 return (result); 297} 298 299papi_status_t |
297lpsched_enable_printer(papi_service_t svc, const char *printer) | 300lpsched_accept_printer(papi_service_t svc, char *printer) |
298{ 299 papi_status_t result = PAPI_OK; 300 short status; 301 char *req_id; 302 char *dest; 303 304 if ((svc == NULL) || (printer == NULL)) 305 return (PAPI_BAD_ARGUMENT); 306 307 dest = printer_name_from_uri_id(printer, -1); | 301{ 302 papi_status_t result = PAPI_OK; 303 short status; 304 char *req_id; 305 char *dest; 306 307 if ((svc == NULL) || (printer == NULL)) 308 return (PAPI_BAD_ARGUMENT); 309 310 dest = printer_name_from_uri_id(printer, -1); |
311 if ((snd_msg(svc, S_ACCEPT_DEST, dest) < 0) || 312 (rcv_msg(svc, R_ACCEPT_DEST, &status, &req_id) < 0)) 313 status = MTRANSMITERR; 314 free(dest); 315 316 if ((status != MOK) && (status != MERRDEST)) { 317 detailed_error(svc, "%s: %s", printer, 318 lpsched_status_string(status)); 319 result = lpsched_status_to_papi_status(status); 320 } 321 322 return (result); 323} 324 325papi_status_t 326lpsched_reject_printer(papi_service_t svc, char *printer, char *message) 327{ 328 papi_status_t result = PAPI_OK; 329 short status; 330 char *req_id; 331 char *dest; 332 333 if ((svc == NULL) || (printer == NULL)) 334 return (PAPI_BAD_ARGUMENT); 335 336 if (message == NULL) 337 message = "stopped by user"; 338 339 dest = printer_name_from_uri_id(printer, -1); 340 if ((snd_msg(svc, S_REJECT_DEST, dest, message, 0) < 0) || 341 (rcv_msg(svc, R_REJECT_DEST, &status, &req_id) < 0)) 342 status = MTRANSMITERR; 343 free(dest); 344 345 if ((status != MOK) && (status != MERRDEST)) { 346 detailed_error(svc, "%s: %s", printer, 347 lpsched_status_string(status)); 348 result = lpsched_status_to_papi_status(status); 349 } 350 351 return (result); 352} 353 354papi_status_t 355lpsched_enable_printer(papi_service_t svc, char *printer) 356{ 357 papi_status_t result = PAPI_OK; 358 short status; 359 char *req_id; 360 char *dest; 361 362 if ((svc == NULL) || (printer == NULL)) 363 return (PAPI_BAD_ARGUMENT); 364 365 dest = printer_name_from_uri_id(printer, -1); |
|
308 if ((snd_msg(svc, S_ENABLE_DEST, dest) < 0) || 309 (rcv_msg(svc, R_ENABLE_DEST, &status, &req_id) < 0)) 310 status = MTRANSMITERR; 311 free(dest); 312 313 if ((status != MOK) && (status != MERRDEST)) { 314 detailed_error(svc, "%s: %s", printer, 315 lpsched_status_string(status)); 316 result = lpsched_status_to_papi_status(status); 317 } 318 319 return (result); 320} 321 322papi_status_t | 366 if ((snd_msg(svc, S_ENABLE_DEST, dest) < 0) || 367 (rcv_msg(svc, R_ENABLE_DEST, &status, &req_id) < 0)) 368 status = MTRANSMITERR; 369 free(dest); 370 371 if ((status != MOK) && (status != MERRDEST)) { 372 detailed_error(svc, "%s: %s", printer, 373 lpsched_status_string(status)); 374 result = lpsched_status_to_papi_status(status); 375 } 376 377 return (result); 378} 379 380papi_status_t |
323lpsched_disable_printer(papi_service_t svc, const char *printer, 324 const char *message) | 381lpsched_disable_printer(papi_service_t svc, char *printer, char *message) |
325{ 326 papi_status_t result = PAPI_OK; 327 short status; 328 char *req_id; 329 char *dest; 330 331 if ((svc == NULL) || (printer == NULL)) 332 return (PAPI_BAD_ARGUMENT); --- 10 unchanged lines hidden (view full) --- 343 if ((status != MOK) && (status != MERRDEST)) { 344 detailed_error(svc, "%s: %s", printer, 345 lpsched_status_string(status)); 346 result = lpsched_status_to_papi_status(status); 347 } 348 349 return (result); 350} | 382{ 383 papi_status_t result = PAPI_OK; 384 short status; 385 char *req_id; 386 char *dest; 387 388 if ((svc == NULL) || (printer == NULL)) 389 return (PAPI_BAD_ARGUMENT); --- 10 unchanged lines hidden (view full) --- 400 if ((status != MOK) && (status != MERRDEST)) { 401 detailed_error(svc, "%s: %s", printer, 402 lpsched_status_string(status)); 403 result = lpsched_status_to_papi_status(status); 404 } 405 406 return (result); 407} |
408 409papi_status_t 410lpsched_load_unload_dest(papi_service_t handle, char *dest, int type) 411{ 412 service_t *svc = handle; 413 papi_status_t result; 414 short status = MOK; 415 416 /* tell the scheduler it's going */ 417 if (snd_msg(svc, type, dest, "", "") < 0) 418 return (PAPI_SERVICE_UNAVAILABLE); 419 420 switch (type) { 421 case S_LOAD_PRINTER: 422 type = R_LOAD_PRINTER; 423 break; 424 case S_UNLOAD_PRINTER: 425 type = R_UNLOAD_PRINTER; 426 break; 427 case S_LOAD_CLASS: 428 type = R_LOAD_CLASS; 429 break; 430 case S_UNLOAD_CLASS: 431 type = R_UNLOAD_CLASS; 432 } 433 434 if (rcv_msg(svc, type, &status) < 0) 435 return (PAPI_SERVICE_UNAVAILABLE); 436 437 result = lpsched_status_to_papi_status(status); 438 439 return (result); 440} 441 442papi_status_t 443lpsched_remove_class(papi_service_t handle, char *dest) 444{ 445 papi_status_t result; 446 447 /* tell the scheduler it's going */ 448 result = lpsched_load_unload_dest(handle, dest, S_UNLOAD_CLASS); 449 450 if (result == PAPI_OK) { 451 /* remove the scheduler config files */ 452 if (delclass(dest) == -1) 453 result = PAPI_SERVICE_UNAVAILABLE; 454 } 455 456 return (result); 457} 458 459static void 460remove_from_class(papi_service_t handle, char *dest, CLASS *cls) 461{ 462 if (dellist(&cls->members, dest) == 0) { 463 if (cls->members != NULL) { 464 if (putclass(cls->name, cls) == 0) 465 (void) lpsched_load_unload_dest(handle, 466 cls->name, S_LOAD_CLASS); 467 } else 468 (void) lpsched_remove_class(handle, cls->name); 469 } 470} 471 472papi_status_t 473lpsched_remove_printer(papi_service_t handle, char *dest) 474{ 475 476 papi_status_t result; 477 478 /* tell the scheduler it's going */ 479 result = lpsched_load_unload_dest(handle, dest, S_UNLOAD_PRINTER); 480 481 if (result == PAPI_OK) { 482 CLASS *cls; 483 char *dflt; 484 485 /* remove the scheduler config files */ 486 if (delprinter(dest) == -1) 487 return (PAPI_SERVICE_UNAVAILABLE); 488 489 /* remove from any classes */ 490 while ((cls = getclass(NAME_ALL)) != NULL) 491 if (searchlist(dest, cls->members) != 0) 492 remove_from_class(handle, dest, cls); 493 494 /* reset the default if it needs to be done */ 495 if (((dflt = getdefault()) != NULL) && 496 (strcmp(dflt, dest) == 0)) 497 putdefault(NAME_NONE); 498 } 499 500 return (result); 501} 502 503papi_status_t 504lpsched_add_modify_class(papi_service_t handle, char *dest, 505 papi_attribute_t **attributes) 506{ 507 papi_status_t result; 508 void *iter = NULL; 509 char **members = NULL; 510 char *member; 511 512 /* 513 * The only attribute that we can modify for a class is the set of 514 * members. Anything else will be ignored. 515 */ 516 for (result = papiAttributeListGetString(attributes, &iter, 517 "member-names", &member); 518 result == PAPI_OK; 519 result = papiAttributeListGetString(attributes, &iter, 520 NULL, &member)) 521 addlist(&members, member); 522 523 if (members != NULL) { 524 /* modify the configuration file */ 525 CLASS class; 526 527 memset(&class, 0, sizeof (class)); 528 class.name = dest; 529 class.members = members; 530 531 if (putclass(dest, &class) == -1) { 532 if ((errno == EPERM) || (errno == EACCES)) 533 result = PAPI_NOT_AUTHORIZED; 534 else 535 result = PAPI_NOT_POSSIBLE; 536 } else 537 result = PAPI_OK; 538 539 freelist(members); 540 } else 541 result = PAPI_ATTRIBUTES; 542 543 /* tell the scheduler about the changes */ 544 if (result == PAPI_OK) 545 result = lpsched_load_unload_dest(handle, dest, S_LOAD_CLASS); 546 547 return (result); 548} 549 550papi_status_t 551lpsched_add_printer(papi_service_t handle, char *dest, 552 papi_attribute_t **attributes) 553{ 554 PRINTER *p; 555 papi_status_t result = PAPI_TEMPORARY_ERROR; 556 557 if ((p = calloc(1, sizeof (*p))) != NULL) { 558 p->name = strdup(dest); 559 p->banner = BAN_ALWAYS; 560 p->interface = strdup("/usr/lib/lp/model/uri"); 561 p->fault_alert.shcmd = strdup("mail"); 562 563 attributes_to_printer(attributes, p); 564 565 if (putprinter(dest, p) == -1) { 566 if ((errno == EPERM) || (errno == EACCES)) 567 result = PAPI_NOT_AUTHORIZED; 568 else 569 result = PAPI_NOT_POSSIBLE; 570 } else 571 result = PAPI_OK; 572 573 freeprinter(p); 574 } 575 576 /* tell the scheduler about the changes */ 577 if (result == PAPI_OK) 578 result = lpsched_load_unload_dest(handle, dest, S_LOAD_PRINTER); 579 580 return (result); 581} 582 583papi_status_t 584lpsched_add_modify_printer(papi_service_t handle, char *dest, 585 papi_attribute_t **attributes, int type) 586{ 587 PRINTER *p; 588 papi_status_t result; 589 590 if (type == 0) { 591 if ((p = calloc(1, sizeof (*p))) != NULL) { 592 p->name = strdup(dest); 593 p->banner = BAN_ALWAYS; 594 p->interface = strdup("/usr/lib/lp/model/uri"); 595 p->fault_alert.shcmd = strdup("mail"); 596 } 597 } else 598 p = getprinter(dest); 599 600 if (p != NULL) { 601 attributes_to_printer(attributes, p); 602 603 if (putprinter(dest, p) == -1) { 604 if ((errno == EPERM) || (errno == EACCES)) 605 result = PAPI_NOT_AUTHORIZED; 606 else 607 result = PAPI_NOT_POSSIBLE; 608 } else 609 result = PAPI_OK; 610 611 freeprinter(p); 612 } else 613 result = PAPI_NOT_POSSIBLE; 614 615 /* tell the scheduler about the changes */ 616 if (result == PAPI_OK) 617 result = lpsched_load_unload_dest(handle, dest, S_LOAD_PRINTER); 618 619 return (result); 620} |
|