| 321 | */ |
| 322 | |
| 323 | const char * /* O - Default printer or @code NULL@ */ |
| 324 | cupsGetDefault2(http_t *http) /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */ |
| 325 | { |
| 326 | ipp_t *request, /* IPP Request */ |
| 327 | *response; /* IPP Response */ |
| 328 | ipp_attribute_t *attr; /* Current attribute */ |
| 329 | _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */ |
| 330 | |
| 331 | |
| 332 | /* |
| 333 | * See if we have a user default printer set... |
| 334 | */ |
| 335 | |
| 336 | if (_cupsUserDefault(cg->def_printer, sizeof(cg->def_printer))) |
| 337 | return (cg->def_printer); |
| 338 | |
| 339 | /* |
| 340 | * Connect to the server as needed... |
| 341 | */ |
| 342 | |
| 343 | if (!http) |
| 344 | if ((http = _cupsConnect()) == NULL) |
| 345 | return (NULL); |
| 346 | |
| 347 | /* |
| 348 | * Build a CUPS_GET_DEFAULT request, which requires the following |
| 349 | * attributes: |
| 350 | * |
| 351 | * attributes-charset |
| 352 | * attributes-natural-language |
| 353 | */ |
| 354 | |
| 355 | request = ippNewRequest(IPP_OP_CUPS_GET_DEFAULT); |
| 356 | |
| 357 | /* |
| 358 | * Do the request and get back a response... |
| 359 | */ |
| 360 | |
| 361 | if ((response = cupsDoRequest(http, request, "/")) != NULL) |
| 362 | { |
| 363 | if ((attr = ippFindAttribute(response, "printer-name", |
| 364 | IPP_TAG_NAME)) != NULL) |
| 365 | { |
| 366 | strlcpy(cg->def_printer, attr->values[0].string.text, |
| 367 | sizeof(cg->def_printer)); |
| 368 | ippDelete(response); |
| 369 | return (cg->def_printer); |
| 370 | } |
| 371 | |
| 372 | ippDelete(response); |
| 373 | } |
| 374 | |
| 375 | return (NULL); |
| 376 | } |
| 377 | |
| 378 | |
| 379 | /* |
no test coverage detected