/*
- * "$Id: util.c 7850 2008-08-20 00:07:25Z mike $"
+ * "$Id$"
*
* Printing utilities for CUPS.
*
- * Copyright 2007-2012 by Apple Inc.
+ * Copyright 2007-2013 by Apple Inc.
* Copyright 1997-2006 by Easy Software Products.
*
* These coded instructions, statements, and computer programs are the
int job_id) /* I - Job ID, @code CUPS_JOBID_CURRENT@ for the current job, or @code CUPS_JOBID_ALL@ for all jobs */
{
return (cupsCancelJob2(CUPS_HTTP_DEFAULT, name, job_id, 0)
- < IPP_REDIRECTION_OTHER_SITE);
+ < IPP_STATUS_REDIRECTION_OTHER_SITE);
}
if (job_id < -1 || (!name && job_id == 0))
{
- _cupsSetError(IPP_INTERNAL_ERROR, strerror(EINVAL), 0);
+ _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0);
return (0);
}
if (!http)
if ((http = _cupsConnect()) == NULL)
- return (IPP_SERVICE_UNAVAILABLE);
+ return (IPP_STATUS_ERROR_SERVICE_UNAVAILABLE);
/*
* Build an IPP_CANCEL_JOB or IPP_PURGE_JOBS request, which requires the following
* [purge-job] or [purge-jobs]
*/
- request = ippNewRequest(job_id < 0 ? IPP_PURGE_JOBS : IPP_CANCEL_JOB);
+ request = ippNewRequest(job_id < 0 ? IPP_OP_PURGE_JOBS : IPP_OP_CANCEL_JOB);
if (name)
{
if (!name)
{
- _cupsSetError(IPP_INTERNAL_ERROR, strerror(EINVAL), 0);
+ _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0);
return (0);
}
* Build a Create-Job request...
*/
- if ((request = ippNewRequest(IPP_CREATE_JOB)) == NULL)
+ if ((request = ippNewRequest(IPP_OP_CREATE_JOB)) == NULL)
{
- _cupsSetError(IPP_INTERNAL_ERROR, strerror(ENOMEM), 0);
+ _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(ENOMEM), 0);
return (0);
}
if (!classes)
{
- _cupsSetError(IPP_INTERNAL_ERROR, strerror(EINVAL), 0);
+ _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0);
return (0);
}
* requested-attributes
*/
- request = ippNewRequest(CUPS_GET_CLASSES);
+ request = ippNewRequest(IPP_OP_CUPS_GET_CLASSES);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
"requested-attributes", NULL, "printer-name");
* attributes-natural-language
*/
- request = ippNewRequest(CUPS_GET_DEFAULT);
+ request = ippNewRequest(IPP_OP_CUPS_GET_DEFAULT);
/*
* Do the request and get back a response...
if (!jobs)
{
- _cupsSetError(IPP_INTERNAL_ERROR, strerror(EINVAL), 0);
+ _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0);
return (-1);
}
if (name)
{
if (httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
- "localhost", 0, "/printers/%s", name) != HTTP_URI_OK)
+ "localhost", 0, "/printers/%s",
+ name) < HTTP_URI_STATUS_OK)
{
- _cupsSetError(IPP_INTERNAL_ERROR, _("Unable to create printer-uri"), 1);
+ _cupsSetError(IPP_STATUS_ERROR_INTERNAL,
+ _("Unable to create printer-uri"), 1);
return (-1);
}
* requested-attributes
*/
- request = ippNewRequest(IPP_GET_JOBS);
+ request = ippNewRequest(IPP_OP_GET_JOBS);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
"printer-uri", NULL, uri);
id = 0;
size = 0;
priority = 50;
- state = IPP_JOB_PENDING;
+ state = IPP_JSTATE_PENDING;
user = "unknown";
dest = NULL;
format = "application/octet-stream";
* Ran out of memory!
*/
- _cupsSetError(IPP_INTERNAL_ERROR, NULL, 0);
+ _cupsSetError(IPP_STATUS_ERROR_INTERNAL, NULL, 0);
cupsFreeJobs(n, *jobs);
*jobs = NULL;
ippDelete(response);
}
- if (n == 0 && cg->last_error >= IPP_BAD_REQUEST)
+ if (n == 0 && cg->last_error >= IPP_STATUS_ERROR_BAD_REQUEST)
return (-1);
else
return (n);
cg->ppd_filename[0] = '\0';
if (cupsGetPPD3(CUPS_HTTP_DEFAULT, name, &modtime, cg->ppd_filename,
- sizeof(cg->ppd_filename)) == HTTP_OK)
+ sizeof(cg->ppd_filename)) == HTTP_STATUS_OK)
return (cg->ppd_filename);
else
return (NULL);
cg->ppd_filename[0] = '\0';
if (cupsGetPPD3(http, name, &modtime, cg->ppd_filename,
- sizeof(cg->ppd_filename)) == HTTP_OK)
+ sizeof(cg->ppd_filename)) == HTTP_STATUS_OK)
return (cg->ppd_filename);
else
return (NULL);
* file will be overwritten as needed. The caller "owns" the file that is
* created and must @code unlink@ the returned filename.
*
- * On success, @code HTTP_OK@ is returned for a new PPD file and
- * @code HTTP_NOT_MODIFIED@ if the existing PPD file is up-to-date. Any other
+ * On success, @code HTTP_STATUS_OK@ is returned for a new PPD file and
+ * @code HTTP_STATUS_NOT_MODIFIED@ if the existing PPD file is up-to-date. Any other
* status is an error.
*
* For classes, @code cupsGetPPD3@ returns the PPD file for the first printer
if (!name)
{
- _cupsSetError(IPP_INTERNAL_ERROR, _("No printer name"), 1);
- return (HTTP_NOT_ACCEPTABLE);
+ _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("No printer name"), 1);
+ return (HTTP_STATUS_NOT_ACCEPTABLE);
}
if (!modtime)
{
- _cupsSetError(IPP_INTERNAL_ERROR, _("No modification time"), 1);
- return (HTTP_NOT_ACCEPTABLE);
+ _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("No modification time"), 1);
+ return (HTTP_STATUS_NOT_ACCEPTABLE);
}
if (!buffer || bufsize <= 1)
{
- _cupsSetError(IPP_INTERNAL_ERROR, _("Bad filename buffer"), 1);
- return (HTTP_NOT_ACCEPTABLE);
+ _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Bad filename buffer"), 1);
+ return (HTTP_STATUS_NOT_ACCEPTABLE);
}
#ifndef WIN32
if (symlink(ppdname, buffer) && errno != EEXIST)
{
- _cupsSetError(IPP_INTERNAL_ERROR, NULL, 0);
+ _cupsSetError(IPP_STATUS_ERROR_INTERNAL, NULL, 0);
- return (HTTP_SERVER_ERROR);
+ return (HTTP_STATUS_SERVER_ERROR);
}
}
else
if (tries >= 1000)
{
- _cupsSetError(IPP_INTERNAL_ERROR, NULL, 0);
+ _cupsSetError(IPP_STATUS_ERROR_INTERNAL, NULL, 0);
- return (HTTP_SERVER_ERROR);
+ return (HTTP_STATUS_SERVER_ERROR);
}
}
if (*modtime >= ppdinfo.st_mtime)
- return (HTTP_NOT_MODIFIED);
+ return (HTTP_STATUS_NOT_MODIFIED);
else
{
*modtime = ppdinfo.st_mtime;
- return (HTTP_OK);
+ return (HTTP_STATUS_OK);
}
}
}
if (!http)
if ((http = _cupsConnect()) == NULL)
- return (HTTP_SERVICE_UNAVAILABLE);
+ return (HTTP_STATUS_SERVICE_UNAVAILABLE);
if (!cups_get_printer_uri(http, name, hostname, sizeof(hostname), &port,
resource, sizeof(resource), 0))
- return (HTTP_NOT_FOUND);
+ return (HTTP_STATUS_NOT_FOUND);
DEBUG_printf(("2cupsGetPPD3: Printer hostname=\"%s\", port=%d", hostname,
port));
if (!_cups_strcasecmp(http_hostname, hostname) && port == http_port)
http2 = http;
- else if ((http2 = httpConnectEncrypt(hostname, port,
- cupsEncryption())) == NULL)
+ else if ((http2 = httpConnect2(hostname, port, NULL, AF_UNSPEC,
+ cupsEncryption(), 1, 30000, NULL)) == NULL)
{
DEBUG_puts("1cupsGetPPD3: Unable to connect to server");
- return (HTTP_SERVICE_UNAVAILABLE);
+ return (HTTP_STATUS_SERVICE_UNAVAILABLE);
}
/*
* Can't open file; close the server connection and return NULL...
*/
- _cupsSetError(IPP_INTERNAL_ERROR, NULL, 0);
+ _cupsSetError(IPP_STATUS_ERROR_INTERNAL, NULL, 0);
if (http2 != http)
httpClose(http2);
- return (HTTP_SERVER_ERROR);
+ return (HTTP_STATUS_SERVER_ERROR);
}
/*
* See if we actually got the file or an error...
*/
- if (status == HTTP_OK)
+ if (status == HTTP_STATUS_OK)
{
*modtime = httpGetDateTime(httpGetField(http2, HTTP_FIELD_DATE));
if (tempfile[0])
strlcpy(buffer, tempfile, bufsize);
}
- else if (status != HTTP_NOT_MODIFIED)
+ else if (status != HTTP_STATUS_NOT_MODIFIED)
{
_cupsSetHTTPError(status);
if (!printers)
{
- _cupsSetError(IPP_INTERNAL_ERROR, strerror(EINVAL), 0);
+ _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0);
return (0);
}
* requested-attributes
*/
- request = ippNewRequest(CUPS_GET_PRINTERS);
+ request = ippNewRequest(IPP_OP_CUPS_GET_PRINTERS);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
"requested-attributes", NULL, "printer-name");
if (!name)
{
- _cupsSetError(IPP_INTERNAL_ERROR, _("No PPD name"), 1);
+ _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("No PPD name"), 1);
return (NULL);
}
* Can't open file; close the server connection and return NULL...
*/
- _cupsSetError(IPP_INTERNAL_ERROR, NULL, 0);
+ _cupsSetError(IPP_STATUS_ERROR_INTERNAL, NULL, 0);
return (NULL);
}
* Get the PPD file...
*/
- request = ippNewRequest(CUPS_GET_PPD);
+ request = ippNewRequest(IPP_OP_CUPS_GET_PPD);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "ppd-name", NULL,
name);
close(fd);
- if (cupsLastError() != IPP_OK)
+ if (cupsLastError() != IPP_STATUS_OK)
{
unlink(cg->ppd_filename);
return (NULL);
if (!name || num_files < 1 || !files)
{
- _cupsSetError(IPP_INTERNAL_ERROR, strerror(EINVAL), 0);
+ _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0);
return (0);
}
* Unable to open print file, cancel the job and return...
*/
- _cupsSetError(IPP_DOCUMENT_ACCESS_ERROR, NULL, 0);
+ _cupsSetError(IPP_STATUS_ERROR_DOCUMENT_ACCESS, NULL, 0);
goto cancel_job;
}
status = cupsStartDocument(http, name, job_id, docname, format,
i == (num_files - 1));
- while (status == HTTP_CONTINUE &&
+ while (status == HTTP_STATUS_CONTINUE &&
(bytes = cupsFileRead(fp, buffer, sizeof(buffer))) > 0)
status = cupsWriteRequestData(http, buffer, bytes);
cupsFileClose(fp);
- if (status != HTTP_CONTINUE || cupsFinishDocument(http, name) != IPP_OK)
+ if (status != HTTP_STATUS_CONTINUE || cupsFinishDocument(http, name) != IPP_STATUS_OK)
{
/*
* Unable to queue, cancel the job and return...
* Create a Send-Document request...
*/
- if ((request = ippNewRequest(IPP_SEND_DOCUMENT)) == NULL)
+ if ((request = ippNewRequest(IPP_OP_SEND_DOCUMENT)) == NULL)
{
- _cupsSetError(IPP_INTERNAL_ERROR, strerror(ENOMEM), 0);
- return (HTTP_ERROR);
+ _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(ENOMEM), 0);
+ return (HTTP_STATUS_ERROR);
}
httpAssembleURIf(HTTP_URI_CODING_ALL, printer_uri, sizeof(printer_uri), "ipp",
*/
if (httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
- "localhost", 0, "/printers/%s", name) != HTTP_URI_OK)
+ "localhost", 0, "/printers/%s",
+ name) < HTTP_URI_STATUS_OK)
{
- _cupsSetError(IPP_INTERNAL_ERROR, _("Unable to create printer-uri"), 1);
+ _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Unable to create printer-uri"),
+ 1);
*host = '\0';
*resource = '\0';
* requested-attributes
*/
- request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES);
+ request = ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
NULL, uri);
if (!_cups_strcasecmp(http_hostname, host) && *port == http_port)
http2 = http;
- else if ((http2 = httpConnectEncrypt(host, *port,
- cupsEncryption())) == NULL)
+ else if ((http2 = httpConnect2(host, *port, NULL, AF_UNSPEC,
+ cupsEncryption(), 1, 30000,
+ NULL)) == NULL)
{
DEBUG_puts("8cups_get_printer_uri: Unable to connect to server");
if (!strncmp(resource, "/classes/", 9))
{
- _cupsSetError(IPP_INTERNAL_ERROR,
+ _cupsSetError(IPP_STATUS_ERROR_INTERNAL,
_("No printer-uri found for class"), 1);
*host = '\0';
ippDelete(response);
}
- if (cupsLastError() != IPP_NOT_FOUND)
- _cupsSetError(IPP_INTERNAL_ERROR, _("No printer-uri found"), 1);
+ if (cupsLastError() != IPP_STATUS_ERROR_NOT_FOUND)
+ _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("No printer-uri found"), 1);
*host = '\0';
*resource = '\0';
/*
- * End of "$Id: util.c 7850 2008-08-20 00:07:25Z mike $".
+ * End of "$Id$".
*/