| 454 | */ |
| 455 | |
| 456 | static void |
| 457 | show_printer(http_t *http, /* I - Connection to server */ |
| 458 | const char *printer) /* I - Name of printer */ |
| 459 | { |
| 460 | ipp_t *request, /* IPP request */ |
| 461 | *response; /* IPP response */ |
| 462 | ipp_attribute_t *attr; /* IPP attribute */ |
| 463 | char uri[HTTP_MAX_URI]; /* Printer URI */ |
| 464 | char refresh[1024]; /* Refresh URL */ |
| 465 | |
| 466 | |
| 467 | fprintf(stderr, "DEBUG: show_printer(http=%p, printer=\"%s\")\n", |
| 468 | http, printer ? printer : "(null)"); |
| 469 | |
| 470 | /* |
| 471 | * Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the following |
| 472 | * attributes: |
| 473 | * |
| 474 | * attributes-charset |
| 475 | * attributes-natural-language |
| 476 | * printer-uri |
| 477 | */ |
| 478 | |
| 479 | request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES); |
| 480 | |
| 481 | httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL, |
| 482 | "localhost", 0, "/printers/%s", printer); |
| 483 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, |
| 484 | uri); |
| 485 | |
| 486 | cgiGetAttributes(request, "printer.tmpl"); |
| 487 | |
| 488 | /* |
| 489 | * Do the request and get back a response... |
| 490 | */ |
| 491 | |
| 492 | if ((response = cupsDoRequest(http, request, "/")) != NULL) |
| 493 | { |
| 494 | /* |
| 495 | * Got the result; set the CGI variables and check the status of a |
| 496 | * single-queue request... |
| 497 | */ |
| 498 | |
| 499 | cgiSetIPPVars(response, NULL, NULL, NULL, 0); |
| 500 | |
| 501 | if (printer && (attr = ippFindAttribute(response, "printer-state", |
| 502 | IPP_TAG_ENUM)) != NULL && |
| 503 | attr->values[0].integer == IPP_PRINTER_PROCESSING) |
| 504 | { |
| 505 | /* |
| 506 | * Printer is processing - automatically refresh the page until we |
| 507 | * are done printing... |
| 508 | */ |
| 509 | |
| 510 | cgiFormEncode(uri, printer, sizeof(uri)); |
| 511 | snprintf(refresh, sizeof(refresh), "10;URL=/printers/%s", uri); |
| 512 | cgiSetVariable("refresh_page", refresh); |
| 513 | } |
no test coverage detected