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

Function do_printer_op

cgi-bin/printers.c:215–289  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

213 */
214
215static void
216do_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);

Callers 1

mainFunction · 0.85

Calls 13

ippNewRequestFunction · 0.85
httpAssembleURIfFunction · 0.85
ippAddStringFunction · 0.85
ippDeleteFunction · 0.85
cupsDoRequestFunction · 0.85
cupsLastErrorFunction · 0.85
cgiStartHTMLFunction · 0.85
cgiShowIPPErrorFunction · 0.85
cgiRewriteURLFunction · 0.85
cgiFormEncodeFunction · 0.85
cgiSetVariableFunction · 0.85
cgiCopyTemplateLangFunction · 0.85

Tested by

no test coverage detected