| 61 | */ |
| 62 | |
| 63 | ipp_status_t /* O - IPP status */ |
| 64 | cupsCancelJob2(http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */ |
| 65 | const char *name, /* I - Name of printer or class */ |
| 66 | int job_id, /* I - Job ID, @code CUPS_JOBID_CURRENT@ for the current job, or @code CUPS_JOBID_ALL@ for all jobs */ |
| 67 | int purge) /* I - 1 to purge, 0 to cancel */ |
| 68 | { |
| 69 | char uri[HTTP_MAX_URI]; /* Job/printer URI */ |
| 70 | ipp_t *request; /* IPP request */ |
| 71 | |
| 72 | |
| 73 | /* |
| 74 | * Range check input... |
| 75 | */ |
| 76 | |
| 77 | if (job_id < -1 || (!name && job_id == 0)) |
| 78 | { |
| 79 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0); |
| 80 | return (0); |
| 81 | } |
| 82 | |
| 83 | /* |
| 84 | * Connect to the default server as needed... |
| 85 | */ |
| 86 | |
| 87 | if (!http) |
| 88 | if ((http = _cupsConnect()) == NULL) |
| 89 | return (IPP_STATUS_ERROR_SERVICE_UNAVAILABLE); |
| 90 | |
| 91 | /* |
| 92 | * Build an IPP_CANCEL_JOB or IPP_PURGE_JOBS request, which requires the following |
| 93 | * attributes: |
| 94 | * |
| 95 | * attributes-charset |
| 96 | * attributes-natural-language |
| 97 | * job-uri or printer-uri + job-id |
| 98 | * requesting-user-name |
| 99 | * [purge-job] or [purge-jobs] |
| 100 | */ |
| 101 | |
| 102 | request = ippNewRequest(job_id < 0 ? IPP_OP_PURGE_JOBS : IPP_OP_CANCEL_JOB); |
| 103 | |
| 104 | if (name) |
| 105 | { |
| 106 | httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL, |
| 107 | "localhost", ippPort(), "/printers/%s", name); |
| 108 | |
| 109 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, |
| 110 | uri); |
| 111 | ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_INTEGER, "job-id", |
| 112 | job_id); |
| 113 | } |
| 114 | else if (job_id > 0) |
| 115 | { |
| 116 | snprintf(uri, sizeof(uri), "ipp://localhost/jobs/%d", job_id); |
| 117 | |
| 118 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri); |
| 119 | } |
| 120 |
no test coverage detected