| 308 | */ |
| 309 | |
| 310 | ipp_t * /* O - Response or @code NULL@ on HTTP error */ |
| 311 | cupsGetResponse(http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */ |
| 312 | const char *resource) /* I - HTTP resource for POST */ |
| 313 | { |
| 314 | http_status_t status; /* HTTP status */ |
| 315 | ipp_state_t state; /* IPP read state */ |
| 316 | ipp_t *response = NULL; /* IPP response */ |
| 317 | |
| 318 | |
| 319 | DEBUG_printf(("cupsGetResponse(http=%p, resource=\"%s\")", (void *)http, resource)); |
| 320 | DEBUG_printf(("1cupsGetResponse: http->state=%d", http ? http->state : HTTP_STATE_ERROR)); |
| 321 | |
| 322 | /* |
| 323 | * Connect to the default server as needed... |
| 324 | */ |
| 325 | |
| 326 | if (!http) |
| 327 | { |
| 328 | _cups_globals_t *cg = _cupsGlobals(); |
| 329 | /* Pointer to library globals */ |
| 330 | |
| 331 | if ((http = cg->http) == NULL) |
| 332 | { |
| 333 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("No active connection."), 1); |
| 334 | DEBUG_puts("1cupsGetResponse: No active connection - returning NULL."); |
| 335 | return (NULL); |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | if (http->state != HTTP_STATE_POST_RECV && http->state != HTTP_STATE_POST_SEND) |
| 340 | { |
| 341 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("No request sent."), 1); |
| 342 | DEBUG_puts("1cupsGetResponse: Not in POST state - returning NULL."); |
| 343 | return (NULL); |
| 344 | } |
| 345 | |
| 346 | /* |
| 347 | * Check for an unfinished chunked request... |
| 348 | */ |
| 349 | |
| 350 | if (http->data_encoding == HTTP_ENCODING_CHUNKED) |
| 351 | { |
| 352 | /* |
| 353 | * Send a 0-length chunk to finish off the request... |
| 354 | */ |
| 355 | |
| 356 | DEBUG_puts("2cupsGetResponse: Finishing chunked POST..."); |
| 357 | |
| 358 | if (httpWrite2(http, "", 0) < 0) |
| 359 | { |
| 360 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Unable to finish request."), 1); |
| 361 | return (NULL); |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | /* |
| 366 | * Wait for a response from the server... |
| 367 | */ |
no test coverage detected