| 2538 | */ |
| 2539 | |
| 2540 | static void |
| 2541 | do_set_default(http_t *http) /* I - HTTP connection */ |
| 2542 | { |
| 2543 | const char *title; /* Page title */ |
| 2544 | ipp_t *request; /* IPP request */ |
| 2545 | char uri[HTTP_MAX_URI]; /* Printer URI */ |
| 2546 | const char *printer, /* Printer name */ |
| 2547 | *is_class; /* Is a class? */ |
| 2548 | |
| 2549 | |
| 2550 | is_class = cgiGetVariable("IS_CLASS"); |
| 2551 | printer = cgiGetTextfield("PRINTER_NAME"); |
| 2552 | title = cgiText(_("Set As Server Default")); |
| 2553 | |
| 2554 | if (!printer) |
| 2555 | { |
| 2556 | cgiSetVariable("ERROR", cgiText(_("Missing form variable"))); |
| 2557 | cgiStartHTML(title); |
| 2558 | cgiCopyTemplateLang("error.tmpl"); |
| 2559 | cgiEndHTML(); |
| 2560 | return; |
| 2561 | } |
| 2562 | |
| 2563 | /* |
| 2564 | * Build a printer request, which requires the following |
| 2565 | * attributes: |
| 2566 | * |
| 2567 | * attributes-charset |
| 2568 | * attributes-natural-language |
| 2569 | * printer-uri |
| 2570 | */ |
| 2571 | |
| 2572 | request = ippNewRequest(CUPS_SET_DEFAULT); |
| 2573 | |
| 2574 | httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL, |
| 2575 | "localhost", 0, is_class ? "/classes/%s" : "/printers/%s", |
| 2576 | printer); |
| 2577 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", |
| 2578 | NULL, uri); |
| 2579 | |
| 2580 | /* |
| 2581 | * Do the request and get back a response... |
| 2582 | */ |
| 2583 | |
| 2584 | ippDelete(cupsDoRequest(http, request, "/admin/")); |
| 2585 | |
| 2586 | if (cupsLastError() == IPP_NOT_AUTHORIZED) |
| 2587 | { |
| 2588 | puts("Status: 401\n"); |
| 2589 | exit(0); |
| 2590 | } |
| 2591 | else if (cupsLastError() > IPP_OK_CONFLICT) |
| 2592 | { |
| 2593 | cgiStartHTML(title); |
| 2594 | cgiShowIPPError(_("Unable to set server default")); |
| 2595 | } |
| 2596 | else |
| 2597 | { |
no test coverage detected