OpenPrinting / libcups

OpenPrinting CUPS Library Sources
https://openprinting.github.io/cups/cups3.html
Apache License 2.0
37 stars 18 forks source link

CANCEL_JOB Question #79

Closed jpmsparks closed 2 months ago

jpmsparks commented 8 months ago

Describe the bug

Getting a 1024 error when submitting a cancel-job request on a job id generated by the "create-job" "send-document" operations. I get a legitimate job id via callback from "create-job", but then when I use that job (jobId) in the following snippet I will get a 1024 error (IPP_STATUS_ERROR_BAD_REQUEST = 0x0400) after the cupsDoRequest API. I had a similar issue with the "send-document" operation and it turned out I needed the "last-document" attribute, (apparently that needed to be added to documentation) hoping it is the same type of issue here. Note: change the jobId, printer, and pUser values below to suit test.

` http_t http; ipp_t request, response; ipp_status_t status; const char printer = "printer57"; const char* pUser = "aUser"; int jobId = 30; char szUriTag[150] = { 0 };

sprintf_s(szUriTag, "%s%s%s%s", "ipp://", printer, "/printers/", printer);

http = httpConnect(printer, 631, NULL, AF_UNSPEC, HTTP_ENCRYPTION_IF_REQUESTED, 1, 30000, NULL);
if (http == NULL)
{
    printf("Could not connect to: %s", printer);
    return 0;
}

//canx the job
request = ippNewRequest(IPP_OP_CANCEL_JOB);

ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, szUriTag);
ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_INTEGER, "job-id", jobId);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", NULL, pUser);

//In request.c This function sends the IPP request to the specified server, 
//The request is freed with ippDelete
response = cupsDoRequest(http, request, "/jobs/");
status = ippGetStatusCode(response);

httpClose(http);
if (request)
    ippDelete(response);
if (response)
    ippDelete(response);
return status;

`

To Reproduce

  1. Get a job id from large document submitted to a printer via create-job and use the send-document.
  2. Try to cancel the job using the job id returned from create job via cancel-job API.

Expected behavior I would expect to get as success if the job was not yet finished printing on the printer or another status code if the job had already finished (on the target printer) prior to the cancel-job API.

System Information:

Additional context If I test the above code with a random (not generated on the printer) job Id, I will get a 1030 (IPP_STATUS_ERROR_NOT_FOUND) status which appears reasonable? as a response for a job number not created on the printer.

michaelrsweet commented 8 months ago

OK, some quick feedback:

  1. client-error-bad-request isn't a valid response from the printer if the job is already completed - it should be successful-ok if the job is not in a terminating state (pending, pending-held, processing, or processing-stopped), client-error-not-possible if the job is terminated (aborted, canceled, completed), or client-error-not-found if the job-id is not found. A Wireshark trace might be useful to ensure everything is going across as expected.
  2. You don't delete the request after calling cupsDoRequest - that function deletes it for you.