MCPcopy Create free account
hub / github.com/OpenPrinting/cups / do_set_default

Function do_set_default

cgi-bin/admin.c:2540–2616  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2538 */
2539
2540static void
2541do_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 {

Callers 1

mainFunction · 0.85

Calls 15

cgiGetVariableFunction · 0.85
cgiGetTextfieldFunction · 0.85
cgiTextFunction · 0.85
cgiSetVariableFunction · 0.85
cgiStartHTMLFunction · 0.85
cgiCopyTemplateLangFunction · 0.85
cgiEndHTMLFunction · 0.85
ippNewRequestFunction · 0.85
httpAssembleURIfFunction · 0.85
ippAddStringFunction · 0.85
ippDeleteFunction · 0.85
cupsDoRequestFunction · 0.85

Tested by

no test coverage detected