| 475 | */ |
| 476 | |
| 477 | char * /* O - Name of PPD file or @code NULL@ on error */ |
| 478 | cupsGetServerPPD(http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */ |
| 479 | const char *name) /* I - Name of PPD file ("ppd-name") */ |
| 480 | { |
| 481 | int fd; /* PPD file descriptor */ |
| 482 | ipp_t *request; /* IPP request */ |
| 483 | _ppd_globals_t *pg = _ppdGlobals(); |
| 484 | /* Pointer to library globals */ |
| 485 | |
| 486 | |
| 487 | /* |
| 488 | * Range check input... |
| 489 | */ |
| 490 | |
| 491 | if (!name) |
| 492 | { |
| 493 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("No PPD name"), 1); |
| 494 | |
| 495 | return (NULL); |
| 496 | } |
| 497 | |
| 498 | if (!http) |
| 499 | if ((http = _cupsConnect()) == NULL) |
| 500 | return (NULL); |
| 501 | |
| 502 | /* |
| 503 | * Get a temp file... |
| 504 | */ |
| 505 | |
| 506 | if ((fd = cupsTempFd(pg->ppd_filename, sizeof(pg->ppd_filename))) < 0) |
| 507 | { |
| 508 | /* |
| 509 | * Can't open file; close the server connection and return NULL... |
| 510 | */ |
| 511 | |
| 512 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, NULL, 0); |
| 513 | |
| 514 | return (NULL); |
| 515 | } |
| 516 | |
| 517 | /* |
| 518 | * Get the PPD file... |
| 519 | */ |
| 520 | |
| 521 | request = ippNewRequest(IPP_OP_CUPS_GET_PPD); |
| 522 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "ppd-name", NULL, |
| 523 | name); |
| 524 | |
| 525 | ippDelete(cupsDoIORequest(http, request, "/", -1, fd)); |
| 526 | |
| 527 | close(fd); |
| 528 | |
| 529 | if (cupsLastError() != IPP_STATUS_OK) |
| 530 | { |
| 531 | unlink(pg->ppd_filename); |
| 532 | return (NULL); |
| 533 | } |
| 534 | else |