char buf[1024]; /* Buffer for real filename */
struct stat filestats; /* File information */
mime_type_t *type; /* MIME type of file */
- cupsd_printer_t *p; /* Printer */
static unsigned request_id = 0; /* Request ID for temp files */
case HTTP_STATE_GET_SEND :
cupsdLogClient(con, CUPSD_LOG_DEBUG, "Processing GET %s", con->uri);
- if ((!strncmp(con->uri, "/ppd/", 5) ||
- !strncmp(con->uri, "/printers/", 10) ||
- !strncmp(con->uri, "/classes/", 9)) &&
- !strcmp(con->uri + strlen(con->uri) - 4, ".ppd"))
- {
- /*
- * Send PPD file - get the real printer name since printer
- * names are not case sensitive but filenames can be...
- */
+ if ((filename = get_file(con, &filestats, buf, sizeof(buf))) != NULL)
+ {
+ type = mimeFileType(MimeDatabase, filename, NULL, NULL);
- con->uri[strlen(con->uri) - 4] = '\0'; /* Drop ".ppd" */
+ cupsdLogClient(con, CUPSD_LOG_DEBUG, "filename=\"%s\", type=%s/%s", filename, type ? type->super : "", type ? type->type : "");
- if (!strncmp(con->uri, "/ppd/", 5))
- p = cupsdFindPrinter(con->uri + 5);
- else if (!strncmp(con->uri, "/printers/", 10))
- p = cupsdFindPrinter(con->uri + 10);
- else
+ if (is_cgi(con, filename, &filestats, type))
{
- p = cupsdFindClass(con->uri + 9);
+ /*
+ * Note: con->command and con->options were set by is_cgi()...
+ */
- if (p)
+ if (!cupsdSendCommand(con, con->command, con->options, 0))
{
- int i; /* Looping var */
-
- for (i = 0; i < p->num_printers; i ++)
+ if (!cupsdSendError(con, HTTP_STATUS_NOT_FOUND, CUPSD_AUTH_NONE))
{
- if (!(p->printers[i]->type & CUPS_PRINTER_CLASS))
- {
- char ppdname[1024];/* PPD filename */
-
- snprintf(ppdname, sizeof(ppdname), "%s/ppd/%s.ppd",
- ServerRoot, p->printers[i]->name);
- if (!access(ppdname, 0))
- {
- p = p->printers[i];
- break;
- }
- }
+ cupsdCloseClient(con);
+ return;
}
+ }
+ else
+ cupsdLogRequest(con, HTTP_STATUS_OK);
- if (i >= p->num_printers)
- p = NULL;
- }
+ if (httpGetVersion(con->http) <= HTTP_VERSION_1_0)
+ httpSetKeepAlive(con->http, HTTP_KEEPALIVE_OFF);
+ break;
}
- if (p)
- {
- snprintf(con->uri, sizeof(con->uri), "/ppd/%s.ppd", p->name);
- }
- else
- {
- if (!cupsdSendError(con, HTTP_STATUS_NOT_FOUND, CUPSD_AUTH_NONE))
+ if (!check_if_modified(con, &filestats))
+ {
+ if (!cupsdSendError(con, HTTP_STATUS_NOT_MODIFIED, CUPSD_AUTH_NONE))
{
cupsdCloseClient(con);
return;
}
-
- break;
}
- }
- else if ((!strncmp(con->uri, "/icons/", 7) ||
- !strncmp(con->uri, "/printers/", 10) ||
- !strncmp(con->uri, "/classes/", 9)) &&
- !strcmp(con->uri + strlen(con->uri) - 4, ".png"))
- {
- /*
- * Send icon file - get the real queue name since queue names are
- * not case sensitive but filenames can be...
- */
-
- con->uri[strlen(con->uri) - 4] = '\0'; /* Drop ".png" */
-
- if (!strncmp(con->uri, "/icons/", 7))
- p = cupsdFindPrinter(con->uri + 7);
- else if (!strncmp(con->uri, "/printers/", 10))
- p = cupsdFindPrinter(con->uri + 10);
- else
+ else
{
- p = cupsdFindClass(con->uri + 9);
-
- if (p)
- {
- int i; /* Looping var */
-
- for (i = 0; i < p->num_printers; i ++)
- {
- if (!(p->printers[i]->type & CUPS_PRINTER_CLASS))
- {
- char ppdname[1024];/* PPD filename */
-
- snprintf(ppdname, sizeof(ppdname), "%s/ppd/%s.ppd",
- ServerRoot, p->printers[i]->name);
- if (!access(ppdname, 0))
- {
- p = p->printers[i];
- break;
- }
- }
- }
-
- if (i >= p->num_printers)
- p = NULL;
- }
- }
+ if (type == NULL)
+ strlcpy(line, "text/plain", sizeof(line));
+ else
+ snprintf(line, sizeof(line), "%s/%s", type->super, type->type);
- if (p)
- snprintf(con->uri, sizeof(con->uri), "/icons/%s.png", p->name);
- else
- {
- if (!cupsdSendError(con, HTTP_STATUS_NOT_FOUND, CUPSD_AUTH_NONE))
+ if (!write_file(con, HTTP_STATUS_OK, filename, line, &filestats))
{
cupsdCloseClient(con);
return;
}
-
- break;
}
- }
-
- if ((!strncmp(con->uri, "/admin", 6) && strcmp(con->uri, "/admin/conf/cupsd.conf") && strncmp(con->uri, "/admin/log/", 11)) ||
- !strncmp(con->uri, "/printers", 9) ||
- !strncmp(con->uri, "/classes", 8) ||
- !strncmp(con->uri, "/help", 5) ||
- !strncmp(con->uri, "/jobs", 5))
+ }
+ else if (!strncmp(con->uri, "/admin", 6) || !strncmp(con->uri, "/printers", 9) || !strncmp(con->uri, "/classes", 8) || !strncmp(con->uri, "/help", 5) || !strncmp(con->uri, "/jobs", 5))
{
if (!WebInterface)
{
if (!strncmp(con->uri, "/admin", 6))
{
- cupsdSetStringf(&con->command, "%s/cgi-bin/admin.cgi",
- ServerBin);
-
+ cupsdSetStringf(&con->command, "%s/cgi-bin/admin.cgi", ServerBin);
cupsdSetString(&con->options, strchr(con->uri + 6, '?'));
}
else if (!strncmp(con->uri, "/printers", 9))
{
- cupsdSetStringf(&con->command, "%s/cgi-bin/printers.cgi",
- ServerBin);
-
+ cupsdSetStringf(&con->command, "%s/cgi-bin/printers.cgi", ServerBin);
if (con->uri[9] && con->uri[10])
cupsdSetString(&con->options, con->uri + 9);
else
}
else if (!strncmp(con->uri, "/classes", 8))
{
- cupsdSetStringf(&con->command, "%s/cgi-bin/classes.cgi",
- ServerBin);
-
+ cupsdSetStringf(&con->command, "%s/cgi-bin/classes.cgi", ServerBin);
if (con->uri[8] && con->uri[9])
cupsdSetString(&con->options, con->uri + 8);
else
}
else if (!strncmp(con->uri, "/jobs", 5))
{
- cupsdSetStringf(&con->command, "%s/cgi-bin/jobs.cgi",
- ServerBin);
-
+ cupsdSetStringf(&con->command, "%s/cgi-bin/jobs.cgi", ServerBin);
if (con->uri[5] && con->uri[6])
cupsdSetString(&con->options, con->uri + 5);
else
}
else
{
- cupsdSetStringf(&con->command, "%s/cgi-bin/help.cgi",
- ServerBin);
-
+ cupsdSetStringf(&con->command, "%s/cgi-bin/help.cgi", ServerBin);
if (con->uri[5] && con->uri[6])
cupsdSetString(&con->options, con->uri + 5);
else
if (httpGetVersion(con->http) <= HTTP_VERSION_1_0)
httpSetKeepAlive(con->http, HTTP_KEEPALIVE_OFF);
}
- else if (!strncmp(con->uri, "/admin/log/", 11) && (strchr(con->uri + 11, '/') || strlen(con->uri) == 11))
+ else
{
- /*
- * GET can only be done to configuration files directly under
- * /admin/conf...
- */
-
- cupsdLogClient(con, CUPSD_LOG_ERROR, "Request for subdirectory \"%s\".", con->uri);
-
- if (!cupsdSendError(con, HTTP_STATUS_FORBIDDEN, CUPSD_AUTH_NONE))
+ if (!cupsdSendError(con, HTTP_STATUS_NOT_FOUND, CUPSD_AUTH_NONE))
{
cupsdCloseClient(con);
return;
}
-
- break;
- }
- else
- {
- /*
- * Serve a file...
- */
-
- if ((filename = get_file(con, &filestats, buf,
- sizeof(buf))) == NULL)
- {
- if (!cupsdSendError(con, HTTP_STATUS_NOT_FOUND, CUPSD_AUTH_NONE))
- {
- cupsdCloseClient(con);
- return;
- }
-
- break;
- }
-
- type = mimeFileType(MimeDatabase, filename, NULL, NULL);
-
- cupsdLogClient(con, CUPSD_LOG_DEBUG, "filename=\"%s\", type=%s/%s", filename, type ? type->super : "", type ? type->type : "");
-
- if (is_cgi(con, filename, &filestats, type))
- {
- /*
- * Note: con->command and con->options were set by
- * is_cgi()...
- */
-
- if (!cupsdSendCommand(con, con->command, con->options, 0))
- {
- if (!cupsdSendError(con, HTTP_STATUS_NOT_FOUND, CUPSD_AUTH_NONE))
- {
- cupsdCloseClient(con);
- return;
- }
- }
- else
- cupsdLogRequest(con, HTTP_STATUS_OK);
-
- if (httpGetVersion(con->http) <= HTTP_VERSION_1_0)
- httpSetKeepAlive(con->http, HTTP_KEEPALIVE_OFF);
- break;
- }
-
- if (!check_if_modified(con, &filestats))
- {
- if (!cupsdSendError(con, HTTP_STATUS_NOT_MODIFIED, CUPSD_AUTH_NONE))
- {
- cupsdCloseClient(con);
- return;
- }
- }
- else
- {
- if (type == NULL)
- strlcpy(line, "text/plain", sizeof(line));
- else
- snprintf(line, sizeof(line), "%s/%s", type->super, type->type);
-
- if (!write_file(con, HTTP_STATUS_OK, filename, line, &filestats))
- {
- cupsdCloseClient(con);
- return;
- }
- }
}
break;
* so check the length against any limits that are set...
*/
- if (httpGetField(con->http, HTTP_FIELD_CONTENT_LENGTH)[0] &&
- MaxRequestSize > 0 &&
- httpGetLength2(con->http) > MaxRequestSize)
+ if (httpGetField(con->http, HTTP_FIELD_CONTENT_LENGTH)[0] && MaxRequestSize > 0 && httpGetLength2(con->http) > MaxRequestSize)
{
/*
* Request too large...
* content-type field will be "application/ipp"...
*/
- if (!strcmp(httpGetField(con->http, HTTP_FIELD_CONTENT_TYPE),
- "application/ipp"))
+ if (!strcmp(httpGetField(con->http, HTTP_FIELD_CONTENT_TYPE), "application/ipp"))
+ {
con->request = ippNew();
+ break;
+ }
else if (!WebInterface)
{
/*
break;
}
- else if ((!strncmp(con->uri, "/admin", 6) && strncmp(con->uri, "/admin/log/", 11)) ||
- !strncmp(con->uri, "/printers", 9) ||
- !strncmp(con->uri, "/classes", 8) ||
- !strncmp(con->uri, "/help", 5) ||
- !strncmp(con->uri, "/jobs", 5))
+
+ if ((filename = get_file(con, &filestats, buf, sizeof(buf))) != NULL)
+ {
+ /*
+ * POST to a file...
+ */
+
+ type = mimeFileType(MimeDatabase, filename, NULL, NULL);
+
+ if (!is_cgi(con, filename, &filestats, type))
+ {
+ /*
+ * Only POST to CGI's...
+ */
+
+ if (!cupsdSendError(con, HTTP_STATUS_UNAUTHORIZED, CUPSD_AUTH_NONE))
+ {
+ cupsdCloseClient(con);
+ return;
+ }
+ }
+ }
+ else if (!strncmp(con->uri, "/admin", 6) || !strncmp(con->uri, "/printers", 9) || !strncmp(con->uri, "/classes", 8) || !strncmp(con->uri, "/help", 5) || !strncmp(con->uri, "/jobs", 5))
{
/*
* CGI request...
if (!strncmp(con->uri, "/admin", 6))
{
- cupsdSetStringf(&con->command, "%s/cgi-bin/admin.cgi",
- ServerBin);
-
+ cupsdSetStringf(&con->command, "%s/cgi-bin/admin.cgi", ServerBin);
cupsdSetString(&con->options, strchr(con->uri + 6, '?'));
}
else if (!strncmp(con->uri, "/printers", 9))
{
- cupsdSetStringf(&con->command, "%s/cgi-bin/printers.cgi",
- ServerBin);
-
+ cupsdSetStringf(&con->command, "%s/cgi-bin/printers.cgi", ServerBin);
if (con->uri[9] && con->uri[10])
cupsdSetString(&con->options, con->uri + 9);
else
}
else if (!strncmp(con->uri, "/classes", 8))
{
- cupsdSetStringf(&con->command, "%s/cgi-bin/classes.cgi",
- ServerBin);
-
+ cupsdSetStringf(&con->command, "%s/cgi-bin/classes.cgi", ServerBin);
if (con->uri[8] && con->uri[9])
cupsdSetString(&con->options, con->uri + 8);
else
}
else if (!strncmp(con->uri, "/jobs", 5))
{
- cupsdSetStringf(&con->command, "%s/cgi-bin/jobs.cgi",
- ServerBin);
-
+ cupsdSetStringf(&con->command, "%s/cgi-bin/jobs.cgi", ServerBin);
if (con->uri[5] && con->uri[6])
cupsdSetString(&con->options, con->uri + 5);
else
}
else
{
- cupsdSetStringf(&con->command, "%s/cgi-bin/help.cgi",
- ServerBin);
-
+ cupsdSetStringf(&con->command, "%s/cgi-bin/help.cgi", ServerBin);
if (con->uri[5] && con->uri[6])
cupsdSetString(&con->options, con->uri + 5);
else
}
else
{
- /*
- * POST to a file...
- */
-
- if ((filename = get_file(con, &filestats, buf,
- sizeof(buf))) == NULL)
- {
- if (!cupsdSendError(con, HTTP_STATUS_NOT_FOUND, CUPSD_AUTH_NONE))
- {
- cupsdCloseClient(con);
- return;
- }
-
- break;
- }
-
- type = mimeFileType(MimeDatabase, filename, NULL, NULL);
-
- if (!is_cgi(con, filename, &filestats, type))
+ if (!cupsdSendError(con, HTTP_STATUS_NOT_FOUND, CUPSD_AUTH_NONE))
{
- /*
- * Only POST to CGI's...
- */
-
- if (!cupsdSendError(con, HTTP_STATUS_UNAUTHORIZED, CUPSD_AUTH_NONE))
- {
- cupsdCloseClient(con);
- return;
- }
+ cupsdCloseClient(con);
+ return;
}
}
break;
* PUT can only be done to the cupsd.conf file...
*/
- cupsdLogClient(con, CUPSD_LOG_ERROR,
- "Disallowed PUT request for \"%s\".", con->uri);
+ cupsdLogClient(con, CUPSD_LOG_ERROR, "Disallowed PUT request for \"%s\".", con->uri);
if (!cupsdSendError(con, HTTP_STATUS_FORBIDDEN, CUPSD_AUTH_NONE))
{
* so check the length against any limits that are set...
*/
- if (httpGetField(con->http, HTTP_FIELD_CONTENT_LENGTH)[0] &&
- MaxRequestSize > 0 &&
- httpGetLength2(con->http) > MaxRequestSize)
+ if (httpGetField(con->http, HTTP_FIELD_CONTENT_LENGTH)[0] && MaxRequestSize > 0 && httpGetLength2(con->http) > MaxRequestSize)
{
/*
* Request too large...
* Open a temporary file to hold the request...
*/
- cupsdSetStringf(&con->filename, "%s/%08x", RequestRoot,
- request_id ++);
+ cupsdSetStringf(&con->filename, "%s/%08x", RequestRoot, request_id ++);
con->file = open(con->filename, O_WRONLY | O_CREAT | O_TRUNC, 0640);
if (con->file < 0)
{
- cupsdLogClient(con, CUPSD_LOG_ERROR,
- "Unable to create request file \"%s\": %s",
- con->filename, strerror(errno));
+ cupsdLogClient(con, CUPSD_LOG_ERROR, "Unable to create request file \"%s\": %s", con->filename, strerror(errno));
if (!cupsdSendError(con, HTTP_STATUS_REQUEST_TOO_LARGE, CUPSD_AUTH_NONE))
{
return;
case HTTP_STATE_HEAD :
- if (!strncmp(con->uri, "/printers/", 10) &&
- !strcmp(con->uri + strlen(con->uri) - 4, ".ppd"))
- {
- /*
- * Send PPD file - get the real printer name since printer
- * names are not case sensitive but filenames can be...
- */
-
- con->uri[strlen(con->uri) - 4] = '\0'; /* Drop ".ppd" */
-
- if ((p = cupsdFindPrinter(con->uri + 10)) != NULL)
- snprintf(con->uri, sizeof(con->uri), "/ppd/%s.ppd", p->name);
- else
+ if ((filename = get_file(con, &filestats, buf, sizeof(buf))) != NULL)
+ {
+ if (!check_if_modified(con, &filestats))
{
- if (!cupsdSendError(con, HTTP_STATUS_NOT_FOUND, CUPSD_AUTH_NONE))
+ if (!cupsdSendError(con, HTTP_STATUS_NOT_MODIFIED, CUPSD_AUTH_NONE))
{
cupsdCloseClient(con);
return;
}
- cupsdLogRequest(con, HTTP_STATUS_NOT_FOUND);
- break;
+ cupsdLogRequest(con, HTTP_STATUS_NOT_MODIFIED);
}
- }
- else if (!strncmp(con->uri, "/printers/", 10) &&
- !strcmp(con->uri + strlen(con->uri) - 4, ".png"))
- {
- /*
- * Send PNG file - get the real printer name since printer
- * names are not case sensitive but filenames can be...
- */
-
- con->uri[strlen(con->uri) - 4] = '\0'; /* Drop ".ppd" */
-
- if ((p = cupsdFindPrinter(con->uri + 10)) != NULL)
- snprintf(con->uri, sizeof(con->uri), "/icons/%s.png", p->name);
else
{
- if (!cupsdSendError(con, HTTP_STATUS_NOT_FOUND, CUPSD_AUTH_NONE))
+ /*
+ * Serve a file...
+ */
+
+ type = mimeFileType(MimeDatabase, filename, NULL, NULL);
+ if (type == NULL)
+ strlcpy(line, "text/plain", sizeof(line));
+ else
+ snprintf(line, sizeof(line), "%s/%s", type->super, type->type);
+
+ httpClearFields(con->http);
+
+ httpSetField(con->http, HTTP_FIELD_LAST_MODIFIED, httpGetDateString(filestats.st_mtime));
+ httpSetLength(con->http, (size_t)filestats.st_size);
+
+ if (!cupsdSendHeader(con, HTTP_STATUS_OK, line, CUPSD_AUTH_NONE))
{
cupsdCloseClient(con);
return;
}
- cupsdLogRequest(con, HTTP_STATUS_NOT_FOUND);
- break;
+ cupsdLogRequest(con, HTTP_STATUS_OK);
}
- }
+ }
else if (!WebInterface)
{
httpClearFields(con->http);
break;
}
- if ((!strncmp(con->uri, "/admin", 6) && strcmp(con->uri, "/admin/conf/cupsd.conf") && strncmp(con->uri, "/admin/log/", 11)) ||
- !strncmp(con->uri, "/printers", 9) ||
- !strncmp(con->uri, "/classes", 8) ||
- !strncmp(con->uri, "/help", 5) ||
- !strncmp(con->uri, "/jobs", 5))
+ if (!strncmp(con->uri, "/admin", 6) || !strncmp(con->uri, "/printers", 9) || !strncmp(con->uri, "/classes", 8) || !strncmp(con->uri, "/help", 5) || !strncmp(con->uri, "/jobs", 5))
{
/*
* CGI output...
cupsdLogRequest(con, HTTP_STATUS_OK);
}
- else if (!strncmp(con->uri, "/admin/log/", 11) && (strchr(con->uri + 11, '/') || strlen(con->uri) == 11))
- {
- /*
- * HEAD can only be done to configuration files under
- * /admin/conf...
- */
-
- cupsdLogClient(con, CUPSD_LOG_ERROR,
- "Request for subdirectory \"%s\".", con->uri);
-
- if (!cupsdSendError(con, HTTP_STATUS_FORBIDDEN, CUPSD_AUTH_NONE))
- {
- cupsdCloseClient(con);
- return;
- }
-
- cupsdLogRequest(con, HTTP_STATUS_FORBIDDEN);
- break;
- }
- else if ((filename = get_file(con, &filestats, buf,
- sizeof(buf))) == NULL)
- {
- httpClearFields(con->http);
-
- if (!cupsdSendHeader(con, HTTP_STATUS_NOT_FOUND, "text/html",
- CUPSD_AUTH_NONE))
- {
- cupsdCloseClient(con);
- return;
- }
-
- cupsdLogRequest(con, HTTP_STATUS_NOT_FOUND);
- }
- else if (!check_if_modified(con, &filestats))
- {
- if (!cupsdSendError(con, HTTP_STATUS_NOT_MODIFIED, CUPSD_AUTH_NONE))
- {
- cupsdCloseClient(con);
- return;
- }
-
- cupsdLogRequest(con, HTTP_STATUS_NOT_MODIFIED);
- }
else
{
- /*
- * Serve a file...
- */
-
- type = mimeFileType(MimeDatabase, filename, NULL, NULL);
- if (type == NULL)
- strlcpy(line, "text/plain", sizeof(line));
- else
- snprintf(line, sizeof(line), "%s/%s", type->super, type->type);
-
httpClearFields(con->http);
- httpSetField(con->http, HTTP_FIELD_LAST_MODIFIED,
- httpGetDateString(filestats.st_mtime));
- httpSetLength(con->http, (size_t)filestats.st_size);
-
- if (!cupsdSendHeader(con, HTTP_STATUS_OK, line, CUPSD_AUTH_NONE))
+ if (!cupsdSendHeader(con, HTTP_STATUS_NOT_FOUND, "text/html", CUPSD_AUTH_NONE))
{
cupsdCloseClient(con);
return;
}
- cupsdLogRequest(con, HTTP_STATUS_OK);
+ cupsdLogRequest(con, HTTP_STATUS_NOT_FOUND);
}
break;
char language[7], /* Language subdirectory, if any */
dest[1024]; /* Destination name */
int perm_check = 1; /* Do permissions check? */
+ cupsd_printer_t *p; /* Printer */
/*
language[0] = '\0';
- if (!strncmp(con->uri, "/ppd/", 5) && !strchr(con->uri + 5, '/'))
+ if ((!strncmp(con->uri, "/ppd/", 5) || !strncmp(con->uri, "/printers/", 10) || !strncmp(con->uri, "/classes/", 9)) && !strcmp(con->uri + strlen(con->uri) - 4, ".ppd"))
{
- strlcpy(dest, con->uri + 5, sizeof(dest));
- ptr = dest + strlen(dest) - 4;
+ strlcpy(dest, strchr(con->uri + 1, '/') + 1, sizeof(dest));
+ dest[strlen(dest) - 4] = '\0'; /* Strip .ppd */
- if (ptr <= dest || strcmp(ptr, ".ppd"))
+ if ((p = cupsdFindDest(dest)) == NULL)
{
- cupsdLogClient(con, CUPSD_LOG_INFO, "Disallowed path \"%s\".", con->uri);
+ cupsdLogClient(con, CUPSD_LOG_INFO, "No destination \"%s\" found.", dest);
return (NULL);
}
- *ptr = '\0';
- if (!cupsdFindPrinter(dest))
+ if (p->type & CUPS_PRINTER_CLASS)
{
- cupsdLogClient(con, CUPSD_LOG_INFO, "No printer \"%s\" found.", dest);
- return (NULL);
- }
+ int i; /* Looping var */
- snprintf(filename, len, "%s%s", ServerRoot, con->uri);
+ for (i = 0; i < p->num_printers; i ++)
+ {
+ if (!(p->printers[i]->type & CUPS_PRINTER_CLASS))
+ {
+ snprintf(filename, len, "%s/ppd/%s.ppd", ServerRoot, p->printers[i]->name);
+ if (!access(filename, 0))
+ {
+ p = p->printers[i];
+ break;
+ }
+ }
+ }
+
+ if (i >= p->num_printers)
+ p = NULL;
+ }
+ else
+ snprintf(filename, len, "%s/ppd/%s.ppd", ServerRoot, p->name);
perm_check = 0;
}
- else if (!strncmp(con->uri, "/icons/", 7) && !strchr(con->uri + 7, '/'))
+ else if ((!strncmp(con->uri, "/icons/", 7) || !strncmp(con->uri, "/printers/", 10) || !strncmp(con->uri, "/classes/", 9)) && !strcmp(con->uri + strlen(con->uri) - 4, ".png"))
{
- strlcpy(dest, con->uri + 7, sizeof(dest));
- ptr = dest + strlen(dest) - 4;
+ strlcpy(dest, strchr(con->uri + 1, '/') + 1, sizeof(dest));
+ dest[strlen(dest) - 4] = '\0'; /* Strip .png */
- if (ptr <= dest || strcmp(ptr, ".png"))
+ if ((p = cupsdFindDest(dest)) == NULL)
{
- cupsdLogClient(con, CUPSD_LOG_INFO, "Disallowed path \"%s\".", con->uri);
+ cupsdLogClient(con, CUPSD_LOG_INFO, "No destination \"%s\" found.", dest);
return (NULL);
}
- *ptr = '\0';
- if (!cupsdFindDest(dest))
+ if (p->type & CUPS_PRINTER_CLASS)
{
- cupsdLogClient(con, CUPSD_LOG_INFO, "No printer \"%s\" found.", dest);
- return (NULL);
+ int i; /* Looping var */
+
+ for (i = 0; i < p->num_printers; i ++)
+ {
+ if (!(p->printers[i]->type & CUPS_PRINTER_CLASS))
+ {
+ snprintf(filename, len, "%s/images/%s.png", CacheDir, p->printers[i]->name);
+ if (!access(filename, 0))
+ {
+ p = p->printers[i];
+ break;
+ }
+ }
+ }
+
+ if (i >= p->num_printers)
+ p = NULL;
}
+ else
+ snprintf(filename, len, "%s/images/%s.png", CacheDir, p->name);
- snprintf(filename, len, "%s/%s.png", CacheDir, dest);
if (access(filename, F_OK) < 0)
snprintf(filename, len, "%s/images/generic.png", DocumentRoot);
}
else if (!strncmp(con->uri, "/rss/", 5) && !strchr(con->uri + 5, '/'))
snprintf(filename, len, "%s/rss/%s", CacheDir, con->uri + 5);
+ else if (!strncmp(con->uri, "/strings/", 9) && !strcmp(con->uri + strlen(con->uri) - 8, ".strings"))
+ {
+ strlcpy(dest, con->uri + 9, sizeof(dest));
+ dest[strlen(dest) - 8] = '\0';
+
+ if ((p = cupsdFindDest(dest)) == NULL)
+ {
+ cupsdLogClient(con, CUPSD_LOG_INFO, "No destination \"%s\" found.", dest);
+ return (NULL);
+ }
+
+ if (!p->strings)
+ {
+ cupsdLogClient(con, CUPSD_LOG_INFO, "No strings files for \"%s\".", dest);
+ return (NULL);
+ }
+
+ strlcpy(filename, p->strings, len);
+
+ perm_check = 0;
+ }
else if (!strcmp(con->uri, "/admin/conf/cupsd.conf"))
{
strlcpy(filename, ConfigurationFile, len);
strncmp(con->uri, "/icons/", 7) &&
strncmp(con->uri, "/ppd/", 5) &&
strncmp(con->uri, "/rss/", 5) &&
+ strncmp(con->uri, "/strings/", 9) &&
strncmp(con->uri, "/admin/conf/", 12) &&
strncmp(con->uri, "/admin/log/", 11))
{
cupsd_printer_t *printer, /* I - Printer */
cups_array_t *ra) /* I - Requested attributes array */
{
- char printer_uri[HTTP_MAX_URI];
- /* Printer URI */
- char printer_icons[HTTP_MAX_URI];
- /* Printer icons */
- time_t curtime; /* Current time */
- int i; /* Looping var */
+ char uri[HTTP_MAX_URI]; /* URI value */
+ time_t curtime; /* Current time */
+ int i; /* Looping var */
+ int is_encrypted = httpIsEncrypted(con->http);
+ /* Is the connection encrypted? */
/*
curtime = time(NULL);
if (!ra || cupsArrayFind(ra, "marker-change-time"))
- ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
- "marker-change-time", printer->marker_time);
+ ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "marker-change-time", printer->marker_time);
- if (printer->num_printers > 0 &&
- (!ra || cupsArrayFind(ra, "member-uris")))
+ if (printer->num_printers > 0 && (!ra || cupsArrayFind(ra, "member-uris")))
{
ipp_attribute_t *member_uris; /* member-uris attribute */
cupsd_printer_t *p2; /* Printer in class */
ipp_attribute_t *p2_uri; /* printer-uri-supported for class printer */
- if ((member_uris = ippAddStrings(con->response, IPP_TAG_PRINTER,
- IPP_TAG_URI, "member-uris",
- printer->num_printers, NULL,
- NULL)) != NULL)
+ if ((member_uris = ippAddStrings(con->response, IPP_TAG_PRINTER, IPP_TAG_URI, "member-uris", printer->num_printers, NULL, NULL)) != NULL)
{
for (i = 0; i < printer->num_printers; i ++)
{
p2 = printer->printers[i];
- if ((p2_uri = ippFindAttribute(p2->attrs, "printer-uri-supported",
- IPP_TAG_URI)) != NULL)
- member_uris->values[i].string.text =
- _cupsStrRetain(p2_uri->values[0].string.text);
+ if ((p2_uri = ippFindAttribute(p2->attrs, "printer-uri-supported", IPP_TAG_URI)) != NULL)
+ {
+ member_uris->values[i].string.text = _cupsStrRetain(p2_uri->values[0].string.text);
+ }
else
{
- httpAssembleURIf(HTTP_URI_CODING_ALL, printer_uri,
- sizeof(printer_uri), "ipp", NULL, con->clientname,
- con->clientport,
- (p2->type & CUPS_PRINTER_CLASS) ?
- "/classes/%s" : "/printers/%s", p2->name);
- member_uris->values[i].string.text = _cupsStrAlloc(printer_uri);
+ httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), is_encrypted ? "ipps" : "ipp", NULL, con->clientname, con->clientport, (p2->type & CUPS_PRINTER_CLASS) ? "/classes/%s" : "/printers/%s", p2->name);
+ member_uris->values[i].string.text = _cupsStrAlloc(uri);
}
}
}
}
if (printer->alert && (!ra || cupsArrayFind(ra, "printer-alert")))
- ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_STRING,
- "printer-alert", NULL, printer->alert);
+ ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_STRING, "printer-alert", NULL, printer->alert);
- if (printer->alert_description &&
- (!ra || cupsArrayFind(ra, "printer-alert-description")))
- ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_TEXT,
- "printer-alert-description", NULL,
- printer->alert_description);
+ if (printer->alert_description && (!ra || cupsArrayFind(ra, "printer-alert-description")))
+ ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-alert-description", NULL, printer->alert_description);
if (!ra || cupsArrayFind(ra, "printer-config-change-date-time"))
ippAddDate(con->response, IPP_TAG_PRINTER, "printer-config-change-date-time", ippTimeToDate(printer->config_time));
if (!ra || cupsArrayFind(ra, "printer-config-change-time"))
- ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
- "printer-config-change-time", printer->config_time);
+ ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "printer-config-change-time", printer->config_time);
if (!ra || cupsArrayFind(ra, "printer-current-time"))
- ippAddDate(con->response, IPP_TAG_PRINTER, "printer-current-time",
- ippTimeToDate(curtime));
+ ippAddDate(con->response, IPP_TAG_PRINTER, "printer-current-time", ippTimeToDate(curtime));
#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
if (!ra || cupsArrayFind(ra, "printer-dns-sd-name"))
{
if (printer->reg_name)
- ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_NAME,
- "printer-dns-sd-name", NULL, printer->reg_name);
+ ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_NAME, "printer-dns-sd-name", NULL, printer->reg_name);
else
- ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_NOVALUE,
- "printer-dns-sd-name", 0);
+ ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_NOVALUE, "printer-dns-sd-name", 0);
}
#endif /* HAVE_DNSSD || HAVE_AVAHI */
if (!ra || cupsArrayFind(ra, "printer-error-policy"))
- ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_NAME,
- "printer-error-policy", NULL, printer->error_policy);
+ ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_NAME, "printer-error-policy", NULL, printer->error_policy);
if (!ra || cupsArrayFind(ra, "printer-error-policy-supported"))
{
static const char * const errors[] =/* printer-error-policy-supported values */
- {
- "abort-job",
- "retry-current-job",
- "retry-job",
- "stop-printer"
- };
+ {
+ "abort-job",
+ "retry-current-job",
+ "retry-job",
+ "stop-printer"
+ };
if (printer->type & CUPS_PRINTER_CLASS)
- ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_NAME | IPP_TAG_COPY,
- "printer-error-policy-supported", NULL, "retry-current-job");
+ ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_NAME | IPP_TAG_COPY, "printer-error-policy-supported", NULL, "retry-current-job");
else
- ippAddStrings(con->response, IPP_TAG_PRINTER, IPP_TAG_NAME | IPP_TAG_COPY,
- "printer-error-policy-supported",
- sizeof(errors) / sizeof(errors[0]), NULL, errors);
+ ippAddStrings(con->response, IPP_TAG_PRINTER, IPP_TAG_NAME | IPP_TAG_COPY, "printer-error-policy-supported", sizeof(errors) / sizeof(errors[0]), NULL, errors);
}
if (!ra || cupsArrayFind(ra, "printer-icons"))
{
- httpAssembleURIf(HTTP_URI_CODING_ALL, printer_icons, sizeof(printer_icons),
- "http", NULL, con->clientname, con->clientport,
- "/icons/%s.png", printer->name);
- ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_URI, "printer-icons",
- NULL, printer_icons);
- cupsdLogMessage(CUPSD_LOG_DEBUG2, "printer-icons=\"%s\"", printer_icons);
+ httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), is_encrypted ? "https" : "http", NULL, con->clientname, con->clientport, "/icons/%s.png", printer->name);
+ ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_URI, "printer-icons", NULL, uri);
+ cupsdLogMessage(CUPSD_LOG_DEBUG2, "printer-icons=\"%s\"", uri);
}
if (!ra || cupsArrayFind(ra, "printer-is-accepting-jobs"))
if (!ra || cupsArrayFind(ra, "printer-more-info"))
{
- httpAssembleURIf(HTTP_URI_CODING_ALL, printer_uri, sizeof(printer_uri),
- "http", NULL, con->clientname, con->clientport,
- (printer->type & CUPS_PRINTER_CLASS) ?
- "/classes/%s" : "/printers/%s", printer->name);
- ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_URI,
- "printer-more-info", NULL, printer_uri);
+ httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), is_encrypted ? "https" : "http", NULL, con->clientname, con->clientport, (printer->type & CUPS_PRINTER_CLASS) ? "/classes/%s" : "/printers/%s", printer->name);
+ ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_URI, "printer-more-info", NULL, uri);
}
if (!ra || cupsArrayFind(ra, "printer-op-policy"))
- ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_NAME,
- "printer-op-policy", NULL, printer->op_policy);
+ ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_NAME, "printer-op-policy", NULL, printer->op_policy);
if (!ra || cupsArrayFind(ra, "printer-state"))
- ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_ENUM, "printer-state",
- printer->state);
+ ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_ENUM, "printer-state", printer->state);
if (!ra || cupsArrayFind(ra, "printer-state-change-date-time"))
ippAddDate(con->response, IPP_TAG_PRINTER, "printer-state-change-date-time", ippTimeToDate(printer->state_time));
if (!ra || cupsArrayFind(ra, "printer-state-change-time"))
- ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
- "printer-state-change-time", printer->state_time);
+ ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "printer-state-change-time", printer->state_time);
if (!ra || cupsArrayFind(ra, "printer-state-message"))
- ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_TEXT,
- "printer-state-message", NULL, printer->state_message);
+ ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-state-message", NULL, printer->state_message);
if (!ra || cupsArrayFind(ra, "printer-state-reasons"))
add_printer_state_reasons(con, printer);
+ if (!ra || cupsArrayFind(ra, "printer-strings-uri"))
+ {
+ httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), is_encrypted ? "https" : "http", NULL, con->clientname, con->clientport, "/strings/%s.strings", printer->name);
+ ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_URI, "printer-strings-uri", NULL, uri);
+ cupsdLogMessage(CUPSD_LOG_DEBUG2, "printer-strings-uri=\"%s\"", uri);
+ }
+
if (!ra || cupsArrayFind(ra, "printer-type"))
{
cups_ptype_t type; /* printer-type value */
}
if (!ra || cupsArrayFind(ra, "printer-up-time"))
- ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
- "printer-up-time", curtime);
+ ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "printer-up-time", curtime);
if (!ra || cupsArrayFind(ra, "printer-uri-supported"))
{
- httpAssembleURIf(HTTP_URI_CODING_ALL, printer_uri, sizeof(printer_uri),
- "ipp", NULL, con->clientname, con->clientport,
- (printer->type & CUPS_PRINTER_CLASS) ?
- "/classes/%s" : "/printers/%s", printer->name);
- ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_URI,
- "printer-uri-supported", NULL, printer_uri);
- cupsdLogMessage(CUPSD_LOG_DEBUG2, "printer-uri-supported=\"%s\"",
- printer_uri);
+ httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), is_encrypted ? "ipps" : "ipp", NULL, con->clientname, con->clientport, (printer->type & CUPS_PRINTER_CLASS) ? "/classes/%s" : "/printers/%s", printer->name);
+ ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_URI, "printer-uri-supported", NULL, uri);
+ cupsdLogMessage(CUPSD_LOG_DEBUG2, "printer-uri-supported=\"%s\"", uri);
}
if (!ra || cupsArrayFind(ra, "queued-job-count"))