| 213 | */ |
| 214 | |
| 215 | static void |
| 216 | do_printer_op(http_t *http, /* I - HTTP connection */ |
| 217 | const char *printer, /* I - Printer name */ |
| 218 | ipp_op_t op, /* I - Operation to perform */ |
| 219 | const char *title) /* I - Title of page */ |
| 220 | { |
| 221 | ipp_t *request; /* IPP request */ |
| 222 | char uri[HTTP_MAX_URI], /* Printer URI */ |
| 223 | resource[HTTP_MAX_URI]; /* Path for request */ |
| 224 | |
| 225 | |
| 226 | /* |
| 227 | * Build a printer request, which requires the following |
| 228 | * attributes: |
| 229 | * |
| 230 | * attributes-charset |
| 231 | * attributes-natural-language |
| 232 | * printer-uri |
| 233 | */ |
| 234 | |
| 235 | request = ippNewRequest(op); |
| 236 | |
| 237 | httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL, |
| 238 | "localhost", 0, "/printers/%s", printer); |
| 239 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", |
| 240 | NULL, uri); |
| 241 | |
| 242 | /* |
| 243 | * Do the request and get back a response... |
| 244 | */ |
| 245 | |
| 246 | snprintf(resource, sizeof(resource), "/printers/%s", printer); |
| 247 | ippDelete(cupsDoRequest(http, request, resource)); |
| 248 | |
| 249 | if (cupsLastError() == IPP_NOT_AUTHORIZED) |
| 250 | { |
| 251 | puts("Status: 401\n"); |
| 252 | exit(0); |
| 253 | } |
| 254 | else if (cupsLastError() > IPP_OK_CONFLICT) |
| 255 | { |
| 256 | cgiStartHTML(title); |
| 257 | cgiShowIPPError(_("Unable to do maintenance command")); |
| 258 | } |
| 259 | else |
| 260 | { |
| 261 | /* |
| 262 | * Redirect successful updates back to the printer page... |
| 263 | */ |
| 264 | |
| 265 | char url[1024], /* Printer/class URL */ |
| 266 | refresh[1024]; /* Refresh URL */ |
| 267 | |
| 268 | |
| 269 | cgiRewriteURL(uri, url, sizeof(url), NULL); |
| 270 | cgiFormEncode(uri, url, sizeof(uri)); |
| 271 | snprintf(refresh, sizeof(refresh), "5;URL=%s", uri); |
| 272 | cgiSetVariable("refresh_page", refresh); |
no test coverage detected