#include "cups-private.h"
ipp_status_t
cupsCancelDestJob(http_t *http,
cups_dest_t *dest,
int job_id)
{
return (IPP_STATUS_ERROR_NOT_FOUND);
}
ipp_status_t
cupsCloseDestJob(
http_t *http,
cups_dest_t *dest,
cups_dinfo_t *info,
int job_id)
{
int i;
ipp_t *request = NULL;
ipp_attribute_t *attr;
DEBUG_printf(("cupsCloseDestJob(http=%p, dest=%p(%s/%s), info=%p, job_id=%d)",
http, dest, dest ? dest->name : NULL,
dest ? dest->instance : NULL, info, job_id));
if (!http || !dest || !info || job_id <= 0)
{
_cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0);
DEBUG_puts("1cupsCloseDestJob: Bad arguments.");
return (IPP_STATUS_ERROR_INTERNAL);
}
if ((attr = ippFindAttribute(info->attrs, "operations-supported",
IPP_TAG_ENUM)) != NULL)
{
for (i = 0; i < attr->num_values; i ++)
if (attr->values[i].integer == IPP_OP_CLOSE_JOB)
{
request = ippNewRequest(IPP_OP_CLOSE_JOB);
break;
}
}
if (!request)
request = ippNewRequest(IPP_OP_SEND_DOCUMENT);
if (!request)
{
_cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(ENOMEM), 0);
DEBUG_puts("1cupsCloseDestJob: Unable to create Close-Job/Send-Document "
"request.");
return (IPP_STATUS_ERROR_INTERNAL);
}
ippSetVersion(request, info->version / 10, info->version % 10);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
NULL, info->uri);
ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_INTEGER, "job-id",
job_id);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
NULL, cupsUser());
if (ippGetOperation(request) == IPP_OP_SEND_DOCUMENT)
ippAddBoolean(request, IPP_TAG_OPERATION, "last-document", 1);
ippDelete(cupsDoRequest(http, request, info->resource));
DEBUG_printf(("1cupsCloseDestJob: %s (%s)", ippErrorString(cupsLastError()),
cupsLastErrorString()));
return (cupsLastError());
}
ipp_status_t
cupsCreateDestJob(
http_t *http,
cups_dest_t *dest,
cups_dinfo_t *info,
int *job_id,
const char *title,
int num_options,
cups_option_t *options)
{
ipp_t *request,
*response;
ipp_attribute_t *attr;
DEBUG_printf(("cupsCreateDestJob(http=%p, dest=%p(%s/%s), info=%p, "
"job_id=%p, title=\"%s\", num_options=%d, options=%p)",
http, dest, dest ? dest->name : NULL,
dest ? dest->instance : NULL, info, job_id, title, num_options,
options));
if (job_id)
*job_id = 0;
if (!http || !dest || !info || !job_id)
{
_cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0);
DEBUG_puts("1cupsCreateDestJob: Bad arguments.");
return (IPP_STATUS_ERROR_INTERNAL);
}
if ((request = ippNewRequest(IPP_OP_CREATE_JOB)) == NULL)
{
_cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(ENOMEM), 0);
DEBUG_puts("1cupsCreateDestJob: Unable to create Create-Job request.");
return (IPP_STATUS_ERROR_INTERNAL);
}
ippSetVersion(request, info->version / 10, info->version % 10);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
NULL, info->uri);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
NULL, cupsUser());
if (title)
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "job-name", NULL,
title);
cupsEncodeOptions2(request, num_options, options, IPP_TAG_OPERATION);
cupsEncodeOptions2(request, num_options, options, IPP_TAG_JOB);
cupsEncodeOptions2(request, num_options, options, IPP_TAG_SUBSCRIPTION);
response = cupsDoRequest(http, request, info->resource);
if ((attr = ippFindAttribute(response, "job-id", IPP_TAG_INTEGER)) != NULL)
{
*job_id = attr->values[0].integer;
DEBUG_printf(("1cupsCreateDestJob: job-id=%d", *job_id));
}
ippDelete(response);
DEBUG_printf(("1cupsCreateDestJob: %s (%s)", ippErrorString(cupsLastError()),
cupsLastErrorString()));
return (cupsLastError());
}
ipp_status_t
cupsFinishDestDocument(
http_t *http,
cups_dest_t *dest,
cups_dinfo_t *info)
{
DEBUG_printf(("cupsFinishDestDocument(http=%p, dest=%p(%s/%s), info=%p)",
http, dest, dest ? dest->name : NULL,
dest ? dest->instance : NULL, info));
if (!http || !dest || !info)
{
_cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0);
DEBUG_puts("1cupsFinishDestDocument: Bad arguments.");
return (IPP_STATUS_ERROR_INTERNAL);
}
ippDelete(cupsGetResponse(http, info->resource));
DEBUG_printf(("1cupsFinishDestDocument: %s (%s)",
ippErrorString(cupsLastError()), cupsLastErrorString()));
return (cupsLastError());
}
http_status_t
cupsStartDestDocument(
http_t *http,
cups_dest_t *dest,
cups_dinfo_t *info,
int job_id,
const char *docname,
const char *format,
int num_options,
cups_option_t *options,
int last_document)
{
ipp_t *request;
http_status_t status;
DEBUG_printf(("cupsStartDestDocument(http=%p, dest=%p(%s/%s), info=%p, "
"job_id=%d, docname=\"%s\", format=\"%s\", num_options=%d, "
"options=%p, last_document=%d)",
http, dest, dest ? dest->name : NULL,
dest ? dest->instance : NULL, info, job_id, docname, format,
num_options, options, last_document));
if (!http || !dest || !info || job_id <= 0)
{
_cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0);
DEBUG_puts("1cupsStartDestDocument: Bad arguments.");
return (HTTP_STATUS_ERROR);
}
if ((request = ippNewRequest(IPP_OP_SEND_DOCUMENT)) == NULL)
{
_cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(ENOMEM), 0);
DEBUG_puts("1cupsStartDestDocument: Unable to create Send-Document "
"request.");
return (HTTP_STATUS_ERROR);
}
ippSetVersion(request, info->version / 10, info->version % 10);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
NULL, info->uri);
ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_INTEGER, "job-id", job_id);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
NULL, cupsUser());
if (docname)
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "document-name",
NULL, docname);
if (format)
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_MIMETYPE,
"document-format", NULL, format);
ippAddBoolean(request, IPP_TAG_OPERATION, "last-document", last_document);
cupsEncodeOptions2(request, num_options, options, IPP_TAG_OPERATION);
cupsEncodeOptions2(request, num_options, options, IPP_TAG_DOCUMENT);
status = cupsSendRequest(http, request, info->resource, CUPS_LENGTH_VARIABLE);
ippDelete(request);
return (status);
}