]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/dest-job.c
Merge changes from CUPS 1.6svn-r10390.
[thirdparty/cups.git] / cups / dest-job.c
index 31cac7903c11c3f429c394ab5652426e1a3630ae..01f8578e0d6c24a152feeec2dc488612c40de44c 100644 (file)
@@ -53,27 +53,92 @@ cupsCancelDestJob(http_t      *http,        /* I - Connection to destination */
  * 'cupsCloseDestJob()' - Close a job and start printing.
  *
  * Use when the last call to cupsStartDocument passed 0 for "last_document".
- * "job_id" is the job ID returned by cupsCreateDestJob. Returns IPP_OK on
- * success.
+ * "job_id" is the job ID returned by cupsCreateDestJob. Returns @code IPP_OK@
+ * on success.
  *
  * @since CUPS 1.6@
  */
 
-ipp_status_t
+ipp_status_t                           /* O - IPP status code */
 cupsCloseDestJob(
-    http_t      *http,                 /* I - Connection to destination */
-    cups_dest_t *dest,                 /* I - Destination */
-    int         job_id)                        /* I - Job ID */
+    http_t       *http,                        /* I - Connection to destination */
+    cups_dest_t  *dest,                        /* I - Destination */
+    cups_dinfo_t *info,                /* I - Destination information */
+    int          job_id)               /* I - Job ID */
 {
-  return (IPP_NOT_FOUND);
+  int                  i;              /* Looping var */
+  ipp_t                        *request = NULL;/* Close-Job/Send-Document request */
+  ipp_attribute_t      *attr;          /* operations-supported attribute */
+
+
+  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));
+
+ /*
+  * Range check input...
+  */
+
+  if (!http || !dest || !info || job_id <= 0)
+  {
+    _cupsSetError(IPP_INTERNAL_ERROR, strerror(EINVAL), 0);
+    DEBUG_puts("1cupsCloseDestJob: Bad arguments.");
+    return (IPP_INTERNAL_ERROR);
+  }
+
+ /*
+  * Build a Close-Job or empty Send-Document request...
+  */
+
+  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_CLOSE_JOB)
+      {
+        request = ippNewRequest(IPP_CLOSE_JOB);
+        break;
+      }
+  }
+
+  if (!request)
+    request = ippNewRequest(IPP_SEND_DOCUMENT);
+
+  if (!request)
+  {
+    _cupsSetError(IPP_INTERNAL_ERROR, strerror(ENOMEM), 0);
+    DEBUG_puts("1cupsCloseDestJob: Unable to create Close-Job/Send-Document "
+               "request.");
+    return (IPP_INTERNAL_ERROR);
+  }
+
+  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_SEND_DOCUMENT)
+    ippAddBoolean(request, IPP_TAG_OPERATION, "last-document", 1);
+
+ /*
+  * Send the request and return the status...
+  */
+
+  ippDelete(cupsDoRequest(http, request, info->resource));
+
+  DEBUG_printf(("1cupsCloseDestJob: %s (%s)", ippErrorString(cupsLastError()),
+                cupsLastErrorString()));
+
+  return (cupsLastError());
 }
 
 
 /*
  * 'cupsCreateDestJob()' - Create a job on a destination.
  *
- * Returns IPP_OK or IPP_OK_SUBST on success, saving the job ID in the variable
- * pointed to by "job_id".
+ * Returns @code IPP_OK@ or @code IPP_OK_SUBST@ on success, saving the job ID
+ * in the variable pointed to by "job_id".
  *
  * @since CUPS 1.6@
  */
@@ -88,26 +153,115 @@ cupsCreateDestJob(
     int           num_options,         /* I - Number of job options */
     cups_option_t *options)            /* I - Job options */
 {
-  *job_id = 0;
+  ipp_t                        *request,       /* Create-Job request */
+                       *response;      /* Create-Job response */
+  ipp_attribute_t      *attr;          /* job-id attribute */
+
+
+  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));
+
+ /*
+  * Range check input...
+  */
+
+  if (job_id)
+    *job_id = 0;
+
+  if (!http || !dest || !info || !job_id)
+  {
+    _cupsSetError(IPP_INTERNAL_ERROR, strerror(EINVAL), 0);
+    DEBUG_puts("1cupsCreateDestJob: Bad arguments.");
+    return (IPP_INTERNAL_ERROR);
+  }
+
+ /*
+  * Build a Create-Job request...
+  */
+
+  if ((request = ippNewRequest(IPP_CREATE_JOB)) == NULL)
+  {
+    _cupsSetError(IPP_INTERNAL_ERROR, strerror(ENOMEM), 0);
+    DEBUG_puts("1cupsCreateDestJob: Unable to create Create-Job request.");
+    return (IPP_INTERNAL_ERROR);
+  }
+
+  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);
+  cupsEncodeOptions(request, num_options, options);
+
+ /*
+  * Send the request and get the job-id...
+  */
 
-  return (IPP_NOT_POSSIBLE);
+  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);
+
+ /*
+  * Return the status code from the Create-Job request...
+  */
+
+  DEBUG_printf(("1cupsCreateDestJob: %s (%s)", ippErrorString(cupsLastError()),
+                cupsLastErrorString()));
+
+  return (cupsLastError());
 }
 
 
 /*
  * 'cupsFinishDestDocument()' - Finish the current document.
  *
- * Returns IPP_OK on success.
+ * Returns @code IPP_OK@ or @code IPP_OK_SUBST@ on success.
  *
  * @since CUPS 1.6@
  */
 
-ipp_status_t
+ipp_status_t                           /* O - Status of document submission */
 cupsFinishDestDocument(
-    http_t      *http,                 /* I - Connection to destination */
-    cups_dest_t *dest)                 /* I - Destination */
+    http_t       *http,                        /* I - Connection to destination */
+    cups_dest_t  *dest,                        /* I - Destination */
+    cups_dinfo_t *info)                /* I - Destination information */
 {
-  return (IPP_NOT_FOUND);
+  DEBUG_printf(("cupsFinishDestDocument(http=%p, dest=%p(%s/%s), info=%p)",
+                http, dest, dest ? dest->name : NULL,
+                dest ? dest->instance : NULL, info));
+
+ /*
+  * Range check input...
+  */
+
+  if (!http || !dest || !info)
+  {
+    _cupsSetError(IPP_INTERNAL_ERROR, strerror(EINVAL), 0);
+    DEBUG_puts("1cupsFinishDestDocument: Bad arguments.");
+    return (IPP_INTERNAL_ERROR);
+  }
+
+ /*
+  * Get the response at the end of the document and return it...
+  */
+
+  ippDelete(cupsGetResponse(http, info->resource));
+
+  DEBUG_printf(("1cupsFinishDestDocument: %s (%s)",
+                ippErrorString(cupsLastError()), cupsLastErrorString()));
+
+  return (cupsLastError());
 }
 
 
@@ -119,12 +273,12 @@ cupsFinishDestDocument(
  * document (see CUPS_FORMAT_xxx constants), and "num_options" and "options"
  * are the options do be applied to the document. "last_document" should be 1
  * if this is the last document to be submitted in the job.  Returns
- * HTTP_CONTINUE on success.
+ * @code HTTP_CONTINUE@ on success.
  *
  * @since CUPS 1.6@
  */
 
-http_status_t
+http_status_t                          /* O - Status of document creation */
 cupsStartDestDocument(
     http_t        *http,               /* I - Connection to destination */
     cups_dest_t   *dest,               /* I - Destination */
@@ -136,7 +290,64 @@ cupsStartDestDocument(
     cups_option_t *options,            /* I - Document options */
     int           last_document)       /* I - 1 if this is the last document */
 {
-  return (HTTP_CONTINUE);
+  ipp_t                *request;               /* Send-Document request */
+  http_status_t        status;                 /* HTTP 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));
+
+ /*
+  * Range check input...
+  */
+
+  if (!http || !dest || !info || job_id <= 0)
+  {
+    _cupsSetError(IPP_INTERNAL_ERROR, strerror(EINVAL), 0);
+    DEBUG_puts("1cupsStartDestDocument: Bad arguments.");
+    return (HTTP_ERROR);
+  }
+
+ /*
+  * Create a Send-Document request...
+  */
+
+  if ((request = ippNewRequest(IPP_SEND_DOCUMENT)) == NULL)
+  {
+    _cupsSetError(IPP_INTERNAL_ERROR, strerror(ENOMEM), 0);
+    DEBUG_puts("1cupsStartDestDocument: Unable to create Send-Document "
+               "request.");
+    return (HTTP_ERROR);
+  }
+
+  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_DOCUMENT);
+
+ /*
+  * Send and delete the request, then return the status...
+  */
+
+  status = cupsSendRequest(http, request, info->resource, CUPS_LENGTH_VARIABLE);
+
+  ippDelete(request);
+
+  return (status);
 }