/*
- * "$Id: ippserver.c 11097 2013-07-04 15:54:36Z msweet $"
+ * "$Id: ippserver.c 11986 2014-07-02 15:52:01Z msweet $"
*
- * Sample IPP/2.0 server for CUPS.
+ * Sample IPP/2.0 server for CUPS.
*
- * Copyright 2010-2013 by Apple Inc.
+ * Copyright 2010-2014 by Apple Inc.
*
- * These coded instructions, statements, and computer programs are the
- * property of Apple Inc. and are protected by Federal copyright
- * law. Distribution and use rights are outlined in the file "LICENSE.txt"
- * which should have been included with this file. If this file is
- * file is missing or damaged, see the license at "http://www.cups.org/".
+ * These coded instructions, statements, and computer programs are the
+ * property of Apple Inc. and are protected by Federal copyright
+ * law. Distribution and use rights are outlined in the file "LICENSE.txt"
+ * which should have been included with this file. If this file is
+ * file is missing or damaged, see the license at "http://www.cups.org/".
*
- * This file is subject to the Apple OS-Developed Software exception.
- *
- * Contents:
- *
- * main() - Main entry to the sample server.
- * clean_jobs() - Clean out old (completed) jobs.
- * compare_jobs() - Compare two jobs.
- * copy_attributes() - Copy attributes from one request to
- * another.
- * copy_job_attrs() - Copy job attributes to the response.
- * create_client() - Accept a new network connection and create
- * a client object.
- * create_job() - Create a new job object from a Print-Job or
- * Create-Job request.
- * create_listener() - Create a listener socket.
- * create_media_col() - Create a media-col value.
- * create_printer() - Create, register, and listen for
- * connections to a printer object.
- * create_requested_array() - Create an array for requested-attributes.
- * debug_attributes() - Print attributes in a request or response.
- * delete_client() - Close the socket and free all memory used
- * by a client object.
- * delete_job() - Remove from the printer and free all memory
- * used by a job object.
- * delete_printer() - Unregister, close listen sockets, and free
- * all memory used by a printer object.
- * dnssd_callback() - Handle Bonjour registration events.
- * find_job() - Find a job specified in a request.
- * html_escape() - Write a HTML-safe string.
- * html_printf() - Send formatted text to the client, quoting
- * as needed.
- * ipp_cancel_job() - Cancel a job.
- * ipp_create_job() - Create a job object.
- * ipp_get_job_attributes() - Get the attributes for a job object.
- * ipp_get_jobs() - Get a list of job objects.
- * ipp_get_printer_attributes() - Get the attributes for a printer object.
- * ipp_print_job() - Create a job object with an attached
- * document.
- * ipp_print_uri() - Create a job object with a referenced
- * document.
- * ipp_send_document() - Add an attached document to a job object
- * created with Create-Job.
- * ipp_send_uri() - Add a referenced document to a job object
- * created with Create-Job.
- * ipp_validate_job() - Validate job creation attributes.
- * process_client() - Process client requests on a thread.
- * process_http() - Process a HTTP request.
- * process_ipp() - Process an IPP request.
- * process_job() - Process a print job.
- * register_printer() - Register a printer object via Bonjour.
- * respond_http() - Send a HTTP response.
- * respond_ipp() - Send an IPP response.
- * respond_unsupported() - Respond with an unsupported attribute.
- * run_printer() - Run the printer service.
- * usage() - Show program usage.
- * valid_doc_attributes() - Determine whether the document attributes
- * are valid.
- * valid_job_attributes() - Determine whether the job attributes are
- * valid.
+ * This file is subject to the Apple OS-Developed Software exception.
*/
/*
*icon = "printer.png", /* Icon file */
*formats = "application/pdf,image/jpeg,image/pwg-raster";
/* Supported formats */
+#ifdef HAVE_SSL
+ const char *keypath = NULL; /* Keychain path */
+#endif /* HAVE_SSL */
#ifdef HAVE_DNSSD
const char *subtype = "_print"; /* Bonjour service subtype */
#endif /* HAVE_DNSSD */
if (argv[i][0] == '-')
{
for (opt = argv[i] + 1; *opt; opt ++)
+ {
switch (*opt)
{
case '2' : /* -2 (enable 2-sided printing) */
duplex = 1;
break;
+#ifdef HAVE_SSL
+ case 'K' : /* -K keypath */
+ i ++;
+ if (i >= argc)
+ usage(1);
+ keypath = argv[i];
+ break;
+#endif /* HAVE_SSL */
+
case 'M' : /* -M manufacturer */
i ++;
if (i >= argc)
case 'h' : /* -h (show help) */
usage(0);
- break;
case 'i' : /* -i icon.png */
i ++;
default : /* Unknown */
fprintf(stderr, "Unknown option \"-%c\".\n", *opt);
usage(1);
- break;
}
+ }
}
else if (!name)
{
fprintf(stderr, "Using spool directory \"%s\".\n", directory);
}
+#ifdef HAVE_SSL
+ cupsSetServerCredentials(keypath, servername, 1);
+#endif /* HAVE_SSL */
+
/*
* Create the printer...
*/
{
case IPP_JSTATE_PENDING :
ippAddString(client->response, IPP_TAG_JOB,
- IPP_TAG_KEYWORD | IPP_TAG_CUPS_CONST, "job-state-reasons",
+ IPP_CONST_TAG(IPP_TAG_KEYWORD), "job-state-reasons",
NULL, "none");
break;
case IPP_JSTATE_HELD :
if (job->fd >= 0)
ippAddString(client->response, IPP_TAG_JOB,
- IPP_TAG_KEYWORD | IPP_TAG_CUPS_CONST,
+ IPP_CONST_TAG(IPP_TAG_KEYWORD),
"job-state-reasons", NULL, "job-incoming");
else if (ippFindAttribute(job->attrs, "job-hold-until", IPP_TAG_ZERO))
ippAddString(client->response, IPP_TAG_JOB,
- IPP_TAG_KEYWORD | IPP_TAG_CUPS_CONST,
+ IPP_CONST_TAG(IPP_TAG_KEYWORD),
"job-state-reasons", NULL, "job-hold-until-specified");
else
ippAddString(client->response, IPP_TAG_JOB,
- IPP_TAG_KEYWORD | IPP_TAG_CUPS_CONST,
+ IPP_CONST_TAG(IPP_TAG_KEYWORD),
"job-state-reasons", NULL, "job-data-insufficient");
break;
case IPP_JSTATE_PROCESSING :
if (job->cancel)
ippAddString(client->response, IPP_TAG_JOB,
- IPP_TAG_KEYWORD | IPP_TAG_CUPS_CONST,
+ IPP_CONST_TAG(IPP_TAG_KEYWORD),
"job-state-reasons", NULL, "processing-to-stop-point");
else
ippAddString(client->response, IPP_TAG_JOB,
- IPP_TAG_KEYWORD | IPP_TAG_CUPS_CONST,
+ IPP_CONST_TAG(IPP_TAG_KEYWORD),
"job-state-reasons", NULL, "job-printing");
break;
case IPP_JSTATE_STOPPED :
ippAddString(client->response, IPP_TAG_JOB,
- IPP_TAG_KEYWORD | IPP_TAG_CUPS_CONST, "job-state-reasons",
+ IPP_CONST_TAG(IPP_TAG_KEYWORD), "job-state-reasons",
NULL, "job-stopped");
break;
case IPP_JSTATE_CANCELED :
ippAddString(client->response, IPP_TAG_JOB,
- IPP_TAG_KEYWORD | IPP_TAG_CUPS_CONST, "job-state-reasons",
+ IPP_CONST_TAG(IPP_TAG_KEYWORD), "job-state-reasons",
NULL, "job-canceled-by-user");
break;
case IPP_JSTATE_ABORTED :
ippAddString(client->response, IPP_TAG_JOB,
- IPP_TAG_KEYWORD | IPP_TAG_CUPS_CONST, "job-state-reasons",
+ IPP_CONST_TAG(IPP_TAG_KEYWORD), "job-state-reasons",
NULL, "aborted-by-system");
break;
case IPP_JSTATE_COMPLETED :
ippAddString(client->response, IPP_TAG_JOB,
- IPP_TAG_KEYWORD | IPP_TAG_CUPS_CONST, "job-state-reasons",
+ IPP_CONST_TAG(IPP_TAG_KEYWORD), "job-state-reasons",
NULL, "job-completed-successfully");
break;
}
if (!ra || cupsArrayFind(ra, "time-at-completed"))
ippAddInteger(client->response, IPP_TAG_JOB,
job->completed ? IPP_TAG_INTEGER : IPP_TAG_NOVALUE,
- "time-at-completed", job->completed);
+ "time-at-completed", (int)job->completed);
if (!ra || cupsArrayFind(ra, "time-at-processing"))
ippAddInteger(client->response, IPP_TAG_JOB,
job->processing ? IPP_TAG_INTEGER : IPP_TAG_NOVALUE,
- "time-at-processing", job->processing);
+ "time-at-processing", (int)job->processing);
}
ippSetName(job->attrs, &attr, "job-originating-user-name");
else
attr = ippAddString(job->attrs, IPP_TAG_JOB,
- IPP_TAG_NAME | IPP_TAG_CUPS_CONST,
+ IPP_CONST_TAG(IPP_TAG_NAME),
"job-originating-user-name", NULL, "anonymous");
if (attr)
for (i = 0; i < num_formats; i ++)
{
if (!_cups_strcasecmp(formats[i], "application/pdf"))
- snprintf(ptr, sizeof(device_id) - (ptr - device_id), "%sPDF", prefix);
+ snprintf(ptr, sizeof(device_id) - (size_t)(ptr - device_id), "%sPDF", prefix);
else if (!_cups_strcasecmp(formats[i], "application/postscript"))
- snprintf(ptr, sizeof(device_id) - (ptr - device_id), "%sPS", prefix);
+ snprintf(ptr, sizeof(device_id) - (size_t)(ptr - device_id), "%sPS", prefix);
else if (!_cups_strcasecmp(formats[i], "application/vnd.hp-PCL"))
- snprintf(ptr, sizeof(device_id) - (ptr - device_id), "%sPCL", prefix);
+ snprintf(ptr, sizeof(device_id) - (size_t)(ptr - device_id), "%sPCL", prefix);
else if (!_cups_strcasecmp(formats[i], "image/jpeg"))
- snprintf(ptr, sizeof(device_id) - (ptr - device_id), "%sJPEG", prefix);
+ snprintf(ptr, sizeof(device_id) - (size_t)(ptr - device_id), "%sJPEG", prefix);
else if (!_cups_strcasecmp(formats[i], "image/png"))
- snprintf(ptr, sizeof(device_id) - (ptr - device_id), "%sPNG", prefix);
+ snprintf(ptr, sizeof(device_id) - (size_t)(ptr - device_id), "%sPNG", prefix);
else if (_cups_strcasecmp(formats[i], "application/octet-stream"))
- snprintf(ptr, sizeof(device_id) - (ptr - device_id), "%s%s", prefix,
- formats[i]);
+ snprintf(ptr, sizeof(device_id) - (size_t)(ptr - device_id), "%s%s", prefix, formats[i]);
ptr += strlen(ptr);
prefix = ",";
/* charset-configured */
ippAddString(printer->attrs, IPP_TAG_PRINTER,
- IPP_TAG_CHARSET | IPP_TAG_CUPS_CONST,
+ IPP_CONST_TAG(IPP_TAG_CHARSET),
"charset-configured", NULL, "utf-8");
/* charset-supported */
ippAddStrings(printer->attrs, IPP_TAG_PRINTER,
- IPP_TAG_CHARSET | IPP_TAG_CUPS_CONST,
+ IPP_CONST_TAG(IPP_TAG_CHARSET),
"charset-supported", sizeof(charsets) / sizeof(charsets[0]),
NULL, charsets);
/* compression-supported */
ippAddStrings(printer->attrs, IPP_TAG_PRINTER,
- IPP_TAG_KEYWORD | IPP_TAG_CUPS_CONST,
+ IPP_CONST_TAG(IPP_TAG_KEYWORD),
"compression-supported",
(int)(sizeof(compressions) / sizeof(compressions[0])), NULL,
compressions);
/* generated-natural-language-supported */
ippAddString(printer->attrs, IPP_TAG_PRINTER,
- IPP_TAG_LANGUAGE | IPP_TAG_CUPS_CONST,
+ IPP_CONST_TAG(IPP_TAG_LANGUAGE),
"generated-natural-language-supported", NULL, "en");
/* ipp-versions-supported */
ippAddStrings(printer->attrs, IPP_TAG_PRINTER,
- IPP_TAG_KEYWORD | IPP_TAG_CUPS_CONST,
+ IPP_CONST_TAG(IPP_TAG_KEYWORD),
"ipp-versions-supported",
sizeof(versions) / sizeof(versions[0]), NULL, versions);
/* job-creation-attributes-supported */
ippAddStrings(printer->attrs, IPP_TAG_PRINTER,
- IPP_TAG_KEYWORD | IPP_TAG_CUPS_CONST,
+ IPP_CONST_TAG(IPP_TAG_KEYWORD),
"job-creation-attributes-supported",
sizeof(job_creation) / sizeof(job_creation[0]),
NULL, job_creation);
/* job-sheets-default */
ippAddString(printer->attrs, IPP_TAG_PRINTER,
- IPP_TAG_NAME | IPP_TAG_CUPS_CONST,
+ IPP_CONST_TAG(IPP_TAG_NAME),
"job-sheets-default", NULL, "none");
/* job-sheets-supported */
ippAddString(printer->attrs, IPP_TAG_PRINTER,
- IPP_TAG_NAME | IPP_TAG_CUPS_CONST,
+ IPP_CONST_TAG(IPP_TAG_NAME),
"job-sheets-supported", NULL, "none");
/* media-bottom-margin-supported */
/* media-col-supported */
ippAddStrings(printer->attrs, IPP_TAG_PRINTER,
- IPP_TAG_KEYWORD | IPP_TAG_CUPS_CONST,
+ IPP_CONST_TAG(IPP_TAG_KEYWORD),
"media-col-supported",
(int)(sizeof(media_col_supported) /
sizeof(media_col_supported[0])), NULL,
/* media-default */
ippAddString(printer->attrs, IPP_TAG_PRINTER,
- IPP_TAG_KEYWORD | IPP_TAG_CUPS_CONST,
+ IPP_CONST_TAG(IPP_TAG_KEYWORD),
"media-default", NULL, media_supported[0]);
/* media-left-margin-supported */
/* media-supported */
ippAddStrings(printer->attrs, IPP_TAG_PRINTER,
- IPP_TAG_KEYWORD | IPP_TAG_CUPS_CONST,
+ IPP_CONST_TAG(IPP_TAG_KEYWORD),
"media-supported",
(int)(sizeof(media_supported) / sizeof(media_supported[0])),
NULL, media_supported);
/* media-type-supported */
ippAddStrings(printer->attrs, IPP_TAG_PRINTER,
- IPP_TAG_KEYWORD | IPP_TAG_CUPS_CONST,
+ IPP_CONST_TAG(IPP_TAG_KEYWORD),
"media-type-supported",
(int)(sizeof(media_type_supported) /
sizeof(media_type_supported[0])),
/* multiple-document-handling-supported */
ippAddStrings(printer->attrs, IPP_TAG_PRINTER,
- IPP_TAG_KEYWORD | IPP_TAG_CUPS_CONST,
+ IPP_CONST_TAG(IPP_TAG_KEYWORD),
"multiple-document-handling-supported",
sizeof(multiple_document_handling) /
sizeof(multiple_document_handling[0]), NULL,
/* natural-language-configured */
ippAddString(printer->attrs, IPP_TAG_PRINTER,
- IPP_TAG_LANGUAGE | IPP_TAG_CUPS_CONST,
+ IPP_CONST_TAG(IPP_TAG_LANGUAGE),
"natural-language-configured", NULL, "en");
/* number-up-default */
/* output-bin-default */
ippAddString(printer->attrs, IPP_TAG_PRINTER,
- IPP_TAG_KEYWORD | IPP_TAG_CUPS_CONST,
+ IPP_CONST_TAG(IPP_TAG_KEYWORD),
"output-bin-default", NULL, "face-down");
/* output-bin-supported */
ippAddString(printer->attrs, IPP_TAG_PRINTER,
- IPP_TAG_KEYWORD | IPP_TAG_CUPS_CONST,
+ IPP_CONST_TAG(IPP_TAG_KEYWORD),
"output-bin-supported", NULL, "face-down");
/* pages-per-minute */
/* pdl-override-supported */
ippAddString(printer->attrs, IPP_TAG_PRINTER,
- IPP_TAG_KEYWORD | IPP_TAG_CUPS_CONST,
+ IPP_CONST_TAG(IPP_TAG_KEYWORD),
"pdl-override-supported", NULL, "attempted");
/* print-quality-default */
/* reference-uri-scheme-supported */
ippAddStrings(printer->attrs, IPP_TAG_PRINTER,
- IPP_TAG_URISCHEME | IPP_TAG_CUPS_CONST,
+ IPP_CONST_TAG(IPP_TAG_URISCHEME),
"reference-uri-schemes-supported",
(int)(sizeof(reference_uri_schemes_supported) /
sizeof(reference_uri_schemes_supported[0])),
/* sides-default */
ippAddString(printer->attrs, IPP_TAG_PRINTER,
- IPP_TAG_KEYWORD | IPP_TAG_CUPS_CONST,
+ IPP_CONST_TAG(IPP_TAG_KEYWORD),
"sides-default", NULL, "one-sided");
/* sides-supported */
ippAddStrings(printer->attrs, IPP_TAG_PRINTER,
- IPP_TAG_KEYWORD | IPP_TAG_CUPS_CONST,
+ IPP_CONST_TAG(IPP_TAG_KEYWORD),
"sides-supported", duplex ? 3 : 1, NULL, sides_supported);
/* uri-authentication-supported */
ippAddString(printer->attrs, IPP_TAG_PRINTER,
- IPP_TAG_KEYWORD | IPP_TAG_CUPS_CONST,
+ IPP_CONST_TAG(IPP_TAG_KEYWORD),
"uri-authentication-supported", NULL, "none");
/* uri-security-supported */
ippAddString(printer->attrs, IPP_TAG_PRINTER,
- IPP_TAG_KEYWORD | IPP_TAG_CUPS_CONST,
+ IPP_CONST_TAG(IPP_TAG_KEYWORD),
"uri-security-supported", NULL, "none");
/* which-jobs-supported */
ippAddStrings(printer->attrs, IPP_TAG_PRINTER,
- IPP_TAG_KEYWORD | IPP_TAG_CUPS_CONST,
+ IPP_CONST_TAG(IPP_TAG_KEYWORD),
"which-jobs-supported",
sizeof(which_jobs) / sizeof(which_jobs[0]), NULL, which_jobs);
const char *domain, /* I - Domain for service */
_ipp_printer_t *printer) /* I - Printer */
{
+ (void)sdRef;
+ (void)flags;
+ (void)domain;
+
if (errorCode)
{
fprintf(stderr, "DNSServiceRegister for %s failed with error %d.\n",
if (*s == '&' || *s == '<')
{
if (s > start)
- httpWrite2(client->http, start, s - start);
+ httpWrite2(client->http, start, (size_t)(s - start));
if (*s == '&')
httpWrite2(client->http, "&", 5);
}
if (s > start)
- httpWrite2(client->http, start, s - start);
+ httpWrite2(client->http, start, (size_t)(s - start));
}
if (*format == '%')
{
if (format > start)
- httpWrite2(client->http, start, format - start);
+ httpWrite2(client->http, start, (size_t)(format - start));
tptr = tformat;
*tptr++ = *format++;
format ++;
width = va_arg(ap, int);
- snprintf(tptr, sizeof(tformat) - (tptr - tformat), "%d", width);
+ snprintf(tptr, sizeof(tformat) - (size_t)(tptr - tformat), "%d", width);
tptr += strlen(tptr);
}
else
format ++;
prec = va_arg(ap, int);
- snprintf(tptr, sizeof(tformat) - (tptr - tformat), "%d", prec);
+ snprintf(tptr, sizeof(tformat) - (size_t)(tptr - tformat), "%d", prec);
tptr += strlen(tptr);
}
else
case 'e' :
case 'f' :
case 'g' :
- if ((width + 2) > sizeof(temp))
+ if ((size_t)(width + 2) > sizeof(temp))
break;
sprintf(temp, tformat, va_arg(ap, double));
case 'o' :
case 'u' :
case 'x' :
- if ((width + 2) > sizeof(temp))
+ if ((size_t)(width + 2) > sizeof(temp))
break;
# ifdef HAVE_LONG_LONG
break;
case 'p' : /* Pointer value */
- if ((width + 2) > sizeof(temp))
+ if ((size_t)(width + 2) > sizeof(temp))
break;
sprintf(temp, tformat, va_arg(ap, void *));
case 'c' : /* Character or character array */
if (width <= 1)
{
- temp[0] = va_arg(ap, int);
+ temp[0] = (char)va_arg(ap, int);
temp[1] = '\0';
html_escape(client, temp, 1);
}
}
if (format > start)
- httpWrite2(client->http, start, format - start);
+ httpWrite2(client->http, start, (size_t)(format - start));
va_end(ap);
}
{
if (printer->state_reasons == _IPP_PSTATE_NONE)
ippAddString(client->response, IPP_TAG_PRINTER,
- IPP_TAG_KEYWORD | IPP_TAG_CUPS_CONST,
+ IPP_CONST_TAG(IPP_TAG_KEYWORD),
"printer-state-reasons", NULL, "none");
else
{
reasons[num_reasons ++] = "toner-low-report";
ippAddStrings(client->response, IPP_TAG_PRINTER,
- IPP_TAG_KEYWORD | IPP_TAG_CUPS_CONST,
+ IPP_CONST_TAG(IPP_TAG_KEYWORD),
"printer-state-reasons", num_reasons, NULL, reasons);
}
}
snprintf(filename, sizeof(filename), "%s/%d.prn",
client->printer->directory, job->id);
+ if (Verbosity)
+ fprintf(stderr, "Creating job file \"%s\", format \"%s\".\n", filename, job->format);
+
if ((job->fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0600)) < 0)
{
job->state = IPP_JSTATE_ABORTED;
while ((bytes = httpRead2(client->http, buffer, sizeof(buffer))) > 0)
{
- if (write(job->fd, buffer, bytes) < bytes)
+ if (write(job->fd, buffer, (size_t)bytes) < bytes)
{
int error = errno; /* Write error */
if ((bytes = read(infile, buffer, sizeof(buffer))) < 0 &&
(errno == EAGAIN || errno == EINTR))
bytes = 1;
- else if (bytes > 0 && write(job->fd, buffer, bytes) < bytes)
+ else if (bytes > 0 && write(job->fd, buffer, (size_t)bytes) < bytes)
{
int error = errno; /* Write error */
while ((bytes = httpRead2(http, buffer, sizeof(buffer))) > 0)
{
- if (write(job->fd, buffer, bytes) < bytes)
+ if (write(job->fd, buffer, (size_t)bytes) < bytes)
{
int error = errno; /* Write error */
_cupsRWLockWrite(&(client->printer->rwlock));
- if ((attr = ippFindAttribute(job->attrs, "document-format",
- IPP_TAG_MIMETYPE)) != NULL)
+ if ((attr = ippFindAttribute(client->request, "document-format", IPP_TAG_MIMETYPE)) != NULL)
job->format = ippGetString(attr, 0, NULL);
else
job->format = "application/octet-stream";
snprintf(filename, sizeof(filename), "%s/%d.prn",
client->printer->directory, job->id);
+ if (Verbosity)
+ fprintf(stderr, "Creating job file \"%s\", format \"%s\".\n", filename, job->format);
+
job->fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0600);
_cupsRWUnlock(&(client->printer->rwlock));
while ((bytes = httpRead2(client->http, buffer, sizeof(buffer))) > 0)
{
- if (write(job->fd, buffer, bytes) < bytes)
+ if (write(job->fd, buffer, (size_t)bytes) < bytes)
{
int error = errno; /* Write error */
if ((bytes = read(infile, buffer, sizeof(buffer))) < 0 &&
(errno == EAGAIN || errno == EINTR))
bytes = 1;
- else if (bytes > 0 && write(job->fd, buffer, bytes) < bytes)
+ else if (bytes > 0 && write(job->fd, buffer, (size_t)bytes) < bytes)
{
int error = errno; /* Write error */
while ((bytes = httpRead2(http, buffer, sizeof(buffer))) > 0)
{
- if (write(job->fd, buffer, bytes) < bytes)
+ if (write(job->fd, buffer, (size_t)bytes) < bytes)
{
int error = errno; /* Write error */
* Loop until we are out of requests or timeout (30 seconds)...
*/
+#ifdef HAVE_SSL
+ int first_time = 1; /* First time request? */
+#endif /* HAVE_SSL */
+
while (httpWait(client->http, 30000))
+ {
+#ifdef HAVE_SSL
+ if (first_time)
+ {
+ /*
+ * See if we need to negotiate a TLS connection...
+ */
+
+ char buf[1]; /* First byte from client */
+
+ if (recv(httpGetFd(client->http), buf, 1, MSG_PEEK) == 1 && (!buf[0] || !strchr("DGHOPT", buf[0])))
+ {
+ fprintf(stderr, "%s Negotiating TLS session.\n", client->hostname);
+
+ if (httpEncryption(client->http, HTTP_ENCRYPTION_ALWAYS))
+ {
+ fprintf(stderr, "%s Unable to encrypt connection: %s\n", client->hostname, cupsLastErrorString());
+ break;
+ }
+ }
+
+ first_time = 0;
+ }
+#endif /* HAVE_SSL */
+
if (!process_http(client))
break;
+ }
/*
* Close the conection to the client and return...
return (respond_http(client, HTTP_STATUS_OK, NULL, "text/html", 0));
else
return (respond_http(client, HTTP_STATUS_NOT_FOUND, NULL, NULL, 0));
- break;
case HTTP_STATE_GET :
if (!strcmp(client->uri, "/icon.png"))
(fd = open(client->printer->icon, O_RDONLY)) >= 0)
{
if (!respond_http(client, HTTP_STATUS_OK, NULL, "image/png",
- fileinfo.st_size))
+ (size_t)fileinfo.st_size))
{
close(fd);
return (0);
}
while ((bytes = read(fd, buffer, sizeof(buffer))) > 0)
- httpWrite2(client->http, buffer, bytes);
+ httpWrite2(client->http, buffer, (size_t)bytes);
httpFlushWrite(client->http);
return (0);
}
-# if 0 /* ifdef HAVE_SSL */
+# ifdef HAVE_SSL
/*
* Then register the _ipps._tcp (IPP) service type with the real port number to
* advertise our IPP printer...
else
timeout = -1;
- if (poll(polldata, num_fds, timeout) < 0 && errno != EINTR)
+ if (poll(polldata, (nfds_t)num_fds, timeout) < 0 && errno != EINTR)
{
perror("poll() failed");
break;
/*
- * End of "$Id: ippserver.c 11097 2013-07-04 15:54:36Z msweet $".
+ * End of "$Id: ippserver.c 11986 2014-07-02 15:52:01Z msweet $".
*/