*
* IPP backend for CUPS.
*
- * Copyright 2007-2013 by Apple Inc.
+ * Copyright 2007-2014 by Apple Inc.
* Copyright 1997-2007 by Easy Software Products, all rights reserved.
*
* These coded instructions, statements, and computer programs are the
static const char *auth_info_required;
/* New auth-info-required value */
#if defined(HAVE_GSSAPI) && defined(HAVE_XPC)
-static int child_pid = 0; /* Child process ID */
+static pid_t child_pid = 0; /* Child process ID */
#endif /* HAVE_GSSAPI && HAVE_XPC */
static const char * const jattrs[] = /* Job attributes we want */
{
ppd_file_t *ppd,
ipp_attribute_t *media_col_sup,
ipp_attribute_t *doc_handling_sup,
- int print_color_mode);
+ ipp_attribute_t *print_color_mode_sup);
static const char *password_cb(const char *prompt, http_t *http,
const char *method, const char *resource,
int *user_data);
ipp_attribute_t *doc_handling_sup; /* multiple-document-handling-supported */
ipp_attribute_t *printer_state; /* printer-state attribute */
ipp_attribute_t *printer_accepting; /* printer-is-accepting-jobs */
+ ipp_attribute_t *print_color_mode_sup;/* Does printer support print-color-mode? */
int create_job = 0, /* Does printer support Create-Job? */
get_job_attrs = 0, /* Does printer support Get-Job-Attributes? */
send_document = 0, /* Does printer support Send-Document? */
validate_job = 0, /* Does printer support Validate-Job? */
- print_color_mode = 0; /* Does printer support print-color-mode? */
- int copies, /* Number of copies for job */
+ copies, /* Number of copies for job */
copies_remaining; /* Number of copies remaining */
const char *content_type, /* CONTENT_TYPE environment variable */
*final_content_type, /* FINAL_CONTENT_TYPE environment var */
break;
}
- sleep(delay);
+ sleep((unsigned)delay);
delay = _cupsNextDelay(delay, &prev_delay);
}
*/
#ifdef HAVE_LIBZ
- compression_sup = NULL;
+ compression_sup = NULL;
#endif /* HAVE_LIBZ */
- copies_sup = NULL;
- cups_version = NULL;
- format_sup = NULL;
- media_col_sup = NULL;
- supported = NULL;
- operations_sup = NULL;
- doc_handling_sup = NULL;
+ copies_sup = NULL;
+ cups_version = NULL;
+ format_sup = NULL;
+ media_col_sup = NULL;
+ supported = NULL;
+ operations_sup = NULL;
+ doc_handling_sup = NULL;
+ print_color_mode_sup = NULL;
do
{
*/
request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES);
- request->request.op.version[0] = version / 10;
- request->request.op.version[1] = version % 10;
-
+ ippSetVersion(request, version / 10, version % 10);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
NULL, uri);
report_printer_state(supported);
- sleep(delay);
+ sleep((unsigned)delay);
delay = _cupsNextDelay(delay, &prev_delay);
}
report_printer_state(supported);
- sleep(delay);
+ sleep((unsigned)delay);
delay = _cupsNextDelay(delay, &prev_delay);
ippDelete(supported);
- supported = NULL;
+ supported = NULL;
+ ipp_status = IPP_STATUS_ERROR_BUSY;
continue;
}
}
media_col_sup->values[i].string.text);
}
- print_color_mode = ippFindAttribute(supported,
- "print-color-mode-supported",
- IPP_TAG_KEYWORD) != NULL;
+ print_color_mode_sup = ippFindAttribute(supported, "print-color-mode-supported", IPP_TAG_KEYWORD);
if ((operations_sup = ippFindAttribute(supported, "operations-supported",
IPP_TAG_ENUM)) != NULL)
_cupsLangPrintFilter(stderr, "INFO", _("Copying print data."));
- if ((compatsize = write(fd, buffer, bytes)) < 0)
+ if ((compatsize = write(fd, buffer, (size_t)bytes)) < 0)
{
perror("DEBUG: Unable to write temporary file");
return (CUPS_BACKEND_FAILED);
request = new_request(IPP_VALIDATE_JOB, version, uri, argv[2],
monitor.job_name, num_options, options, compression,
copies_sup ? copies : 1, document_format, pc, ppd,
- media_col_sup, doc_handling_sup, print_color_mode);
+ media_col_sup, doc_handling_sup, print_color_mode_sup);
response = cupsDoRequest(http, request, resource);
version, uri, argv[2], monitor.job_name, num_options,
options, compression, copies_sup ? copies : 1,
document_format, pc, ppd, media_col_sup,
- doc_handling_sup, print_color_mode);
+ doc_handling_sup, print_color_mode_sup);
/*
* Do the request...
else
{
fd = 0;
- http_status = cupsWriteRequestData(http, buffer, bytes);
+ http_status = cupsWriteRequestData(http, buffer, (size_t)bytes);
}
while (http_status == HTTP_CONTINUE &&
{
fprintf(stderr, "DEBUG: Read %d bytes...\n", (int)bytes);
- if ((http_status = cupsWriteRequestData(http, buffer, bytes))
+ if ((http_status = cupsWriteRequestData(http, buffer, (size_t)bytes))
!= HTTP_CONTINUE)
break;
}
*/
request = ippNewRequest(IPP_SEND_DOCUMENT);
- request->request.op.version[0] = version / 10;
- request->request.op.version[1] = version % 10;
+ ippSetVersion(request, version / 10, version % 10);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
NULL, uri);
if (num_files == 0)
{
fd = 0;
- http_status = cupsWriteRequestData(http, buffer, bytes);
+ http_status = cupsWriteRequestData(http, buffer, (size_t)bytes);
}
else
{
while (!job_canceled && http_status == HTTP_CONTINUE &&
(bytes = read(fd, buffer, sizeof(buffer))) > 0)
{
- if ((http_status = cupsWriteRequestData(http, buffer, bytes))
+ if ((http_status = cupsWriteRequestData(http, buffer, (size_t)bytes))
!= HTTP_CONTINUE)
break;
else
if (!job_id || !waitjob || !get_job_attrs)
continue;
+ fputs("STATE: +cups-waiting-for-job-completed\n", stderr);
+
_cupsLangPrintFilter(stderr, "INFO", _("Waiting for job to complete."));
for (delay = _cupsNextDelay(0, &prev_delay); !job_canceled;)
*/
request = ippNewRequest(IPP_GET_JOB_ATTRIBUTES);
- request->request.op.version[0] = version / 10;
- request->request.op.version[1] = version % 10;
+ ippSetVersion(request, version / 10, version % 10);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
NULL, uri);
* Wait before polling again...
*/
- sleep(delay);
+ sleep((unsigned)delay);
delay = _cupsNextDelay(delay, &prev_delay);
}
_cupsLangPrintFilter(stderr, "INFO", _("Canceling print job."));
request = ippNewRequest(IPP_CANCEL_JOB);
- request->request.op.version[0] = version / 10;
- request->request.op.version[1] = version % 10;
+ ippSetVersion(request, version / 10, version % 10);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
NULL, uri);
*/
request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES);
- request->request.op.version[0] = version / 10;
- request->request.op.version[1] = version % 10;
+ ippSetVersion(request, version / 10, version % 10);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
NULL, uri);
job_op = (monitor->job_id > 0 && monitor->get_job_attrs) ?
IPP_GET_JOB_ATTRIBUTES : IPP_GET_JOBS;
request = ippNewRequest(job_op);
- request->request.op.version[0] = monitor->version / 10;
- request->request.op.version[1] = monitor->version % 10;
+ ippSetVersion(request, monitor->version / 10, monitor->version % 10);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
NULL, monitor->uri);
job_name = attr->values[0].string.text;
else if (!strcmp(attr->name, "job-state") &&
attr->value_tag == IPP_TAG_ENUM)
- job_state = attr->values[0].integer;
+ job_state = (ipp_jstate_t)attr->values[0].integer;
else if (!strcmp(attr->name, "job-originating-user-name") &&
(attr->value_tag == IPP_TAG_NAME ||
attr->value_tag == IPP_TAG_NAMELANG))
* Sleep for N seconds...
*/
- sleep(delay);
+ sleep((unsigned)delay);
delay = _cupsNextDelay(delay, &prev_delay);
}
ppd_file_t *ppd, /* I - PPD file data */
ipp_attribute_t *media_col_sup, /* I - media-col-supported values */
ipp_attribute_t *doc_handling_sup, /* I - multiple-document-handling-supported values */
- int print_color_mode) /* I - Printer supports print-color-mode */
+ ipp_attribute_t *print_color_mode_sup)
+ /* I - Printer supports print-color-mode */
{
int i; /* Looping var */
ipp_t *request; /* Request data */
* Create the IPP request...
*/
- request = ippNewRequest(op);
- request->request.op.version[0] = version / 10;
- request->request.op.version[1] = version % 10;
+ request = ippNewRequest(op);
+ ippSetVersion(request, version / 10, version % 10);
fprintf(stderr, "DEBUG: %s IPP/%d.%d\n",
ippOpString(request->request.op.operation_id),
(keyword = cupsGetOption("job-password", num_options,
options)) != NULL)
{
- ippAddOctetString(request, IPP_TAG_OPERATION, "job-password",
- keyword, strlen(keyword));
+ ippAddOctetString(request, IPP_TAG_OPERATION, "job-password", keyword, (int)strlen(keyword));
if ((keyword = cupsGetOption("job-password-encryption", num_options,
options)) == NULL)
}
break;
case IPP_TAG_STRING :
- ippAddOctetString(request, IPP_TAG_JOB, mandatory, keyword,
- strlen(keyword));
+ ippAddOctetString(request, IPP_TAG_JOB, mandatory, keyword, (int)strlen(keyword));
break;
default :
+ if (!strcmp(mandatory, "print-color-mode") && !strcmp(keyword, "monochrome"))
+ {
+ if (ippContainsString(print_color_mode_sup, "auto-monochrome"))
+ keyword = "auto-monochrome";
+ else if (ippContainsString(print_color_mode_sup, "process-monochrome") && !ippContainsString(print_color_mode_sup, "monochrome"))
+ keyword = "process-monochrome";
+ }
+
ippAddString(request, IPP_TAG_JOB, value_tag, mandatory,
NULL, keyword);
break;
ippAddString(request, IPP_TAG_JOB, IPP_TAG_KEYWORD, "output-bin",
NULL, keyword);
- color_attr_name = print_color_mode ? "print-color-mode" : "output-mode";
+ color_attr_name = print_color_mode_sup ? "print-color-mode" : "output-mode";
if ((keyword = cupsGetOption("print-color-mode", num_options,
- options)) != NULL)
- ippAddString(request, IPP_TAG_JOB, IPP_TAG_KEYWORD, color_attr_name,
- NULL, keyword);
- else if ((choice = ppdFindMarkedChoice(ppd, "ColorModel")) != NULL)
+ options)) == NULL)
{
- if (!_cups_strcasecmp(choice->choice, "Gray"))
- ippAddString(request, IPP_TAG_JOB, IPP_TAG_KEYWORD,
- color_attr_name, NULL, "monochrome");
- else
- ippAddString(request, IPP_TAG_JOB, IPP_TAG_KEYWORD,
- color_attr_name, NULL, "color");
+ if ((choice = ppdFindMarkedChoice(ppd, "ColorModel")) != NULL)
+ {
+ if (!_cups_strcasecmp(choice->choice, "Gray"))
+ keyword = "monochrome";
+ else
+ keyword = "color";
+ }
+ }
+
+ if (keyword && !strcmp(keyword, "monochrome"))
+ {
+ if (ippContainsString(print_color_mode_sup, "auto-monochrome"))
+ keyword = "auto-monochrome";
+ else if (ippContainsString(print_color_mode_sup, "process-monochrome") && !ippContainsString(print_color_mode_sup, "monochrome"))
+ keyword = "process-monochrome";
}
+ if (keyword)
+ ippAddString(request, IPP_TAG_JOB, IPP_TAG_KEYWORD, color_attr_name,
+ NULL, keyword);
+
if ((keyword = cupsGetOption("print-quality", num_options,
options)) != NULL)
ippAddInteger(request, IPP_TAG_JOB, IPP_TAG_ENUM, "print-quality",
{
if (*s == '\\' || *s == '\"' || *s == '\'')
{
- if (q < (qend - 3))
+ if (qptr < (qend - 4))
{
*qptr++ = '\\';
*qptr++ = '\\';
{
case IPP_TAG_INTEGER :
case IPP_TAG_ENUM :
- snprintf(valptr, sizeof(value) - (valptr - value), "%d",
- attr->values[i].integer);
+ snprintf(valptr, sizeof(value) - (size_t)(valptr - value), "%d", attr->values[i].integer);
valptr += strlen(valptr);
break;
case IPP_TAG_TEXT :
case IPP_TAG_NAME :
case IPP_TAG_KEYWORD :
- quote_string(attr->values[i].string.text, valptr,
- value + sizeof(value) - valptr);
+ quote_string(attr->values[i].string.text, valptr, (size_t)(value + sizeof(value) - valptr));
valptr += strlen(valptr);
break;
if (response)
{
- child_pid = xpc_dictionary_get_int64(response, "child-pid");
+ child_pid = (pid_t)xpc_dictionary_get_int64(response, "child-pid");
xpc_release(response);
if (child_pid)
- fprintf(stderr, "DEBUG: Child PID=%d.\n", child_pid);
+ fprintf(stderr, "DEBUG: Child PID=%d.\n", (int)child_pid);
else
{
_cupsLangPrintFilter(stderr, "ERROR",
if (response)
{
- status = xpc_dictionary_get_int64(response, "status");
+ status = (int)xpc_dictionary_get_int64(response, "status");
if (status == SIGTERM || status == SIGKILL || status == SIGPIPE)
{
temp = (char *)cupsArrayNext(state_reasons))
if (!strncmp(temp, "cups-remote-", 12))
{
- snprintf(remptr, sizeof(rem) - (remptr - rem), "%s%s", remprefix,
- temp);
+ snprintf(remptr, sizeof(rem) - (size_t)(remptr - rem), "%s%s", remprefix, temp);
remptr += strlen(remptr);
remprefix = ",";
cupsArrayAdd(state_reasons, reason);
- snprintf(addptr, sizeof(add) - (addptr - add), "%s%s", addprefix,
- reason);
+ snprintf(addptr, sizeof(add) - (size_t)(addptr - add), "%s%s", addprefix, reason);
addptr += strlen(addptr);
addprefix = ",";
}
{
if (cupsArrayFind(state_reasons, reason))
{
- snprintf(remptr, sizeof(rem) - (remptr - rem), "%s%s", remprefix,
- reason);
+ snprintf(remptr, sizeof(rem) - (size_t)(remptr - rem), "%s%s", remprefix, reason);
remptr += strlen(remptr);
remprefix = ",";
{
if (strncmp(reason, "cups-", 5) && !cupsArrayFind(new_reasons, reason))
{
- snprintf(remptr, sizeof(rem) - (remptr - rem), "%s%s", remprefix,
- reason);
+ snprintf(remptr, sizeof(rem) - (size_t)(remptr - rem), "%s%s", remprefix, reason);
remptr += strlen(remptr);
remprefix = ",";
{
cupsArrayAdd(state_reasons, reason);
- snprintf(addptr, sizeof(add) - (addptr - add), "%s%s", addprefix,
- reason);
+ snprintf(addptr, sizeof(add) - (size_t)(addptr - add), "%s%s", addprefix, reason);
addptr += strlen(addptr);
addprefix = ",";
}