if ((filename = get_file(con, &filestats, buf, sizeof(buf))) != NULL)
{
- cupsRWLockRead(&MimeDatabase->lock);
+ cupsRWLockRead(&MimeLock);
type = mimeFileType(MimeDatabase, filename, NULL, NULL);
- cupsRWUnlock(&MimeDatabase->lock);
+ cupsRWUnlock(&MimeLock);
cupsdLogClient(con, CUPSD_LOG_DEBUG, "filename=\"%s\", type=%s/%s", filename, type ? type->super : "", type ? type->type : "");
!old_serverroot || !ServerRoot || strcmp(old_serverroot, ServerRoot) ||
!old_requestroot || !RequestRoot || strcmp(old_requestroot, RequestRoot))
{
- mime_type_t *type; /* Current type */
- char mimetype[MIME_MAX_SUPER + MIME_MAX_TYPE];
- /* MIME type name */
-
-
cupsdLogMessage(CUPSD_LOG_INFO, "Full reload is required.");
/*
if (MimeDatabase != NULL)
mimeDelete(MimeDatabase);
- if (NumMimeTypes)
- {
- for (i = 0; i < NumMimeTypes; i ++)
- _cupsStrFree(MimeTypes[i]);
-
- free(MimeTypes);
- }
-
/*
* Read the MIME type and conversion database...
*/
MimeDatabase = mimeNew();
mimeSetErrorCallback(MimeDatabase, mime_error_cb, NULL);
- cupsRWInit(&MimeDatabase->lock);
- cupsRWLockWrite(&MimeDatabase->lock);
- MimeDatabase = mimeLoadTypes(MimeDatabase, mimedir);
- MimeDatabase = mimeLoadTypes(MimeDatabase, ServerRoot);
- MimeDatabase = mimeLoadFilters(MimeDatabase, mimedir, temp);
- MimeDatabase = mimeLoadFilters(MimeDatabase, ServerRoot, temp);
- cupsRWUnlock(&MimeDatabase->lock);
+ mimeAddType(MimeDatabase, "application", "octet-stream");
+ mimeLoadTypes(MimeDatabase, mimedir);
+ mimeLoadTypes(MimeDatabase, ServerRoot);
+ mimeLoadFilters(MimeDatabase, mimedir, temp);
+ mimeLoadFilters(MimeDatabase, ServerRoot, temp);
- if (!MimeDatabase)
+ if (mimeNumTypes(MimeDatabase) == 1 || mimeNumFilters(MimeDatabase) == 0)
{
- cupsdLogMessage(CUPSD_LOG_EMERG,
- "Unable to load MIME database from \"%s\" or \"%s\".",
- mimedir, ServerRoot);
+ cupsdLogMessage(CUPSD_LOG_EMERG, "Unable to load MIME database from \"%s\" or \"%s\".", mimedir, ServerRoot);
if (FatalErrors & CUPSD_FATAL_CONFIG)
return (0);
}
- cupsdLogMessage(CUPSD_LOG_INFO,
- "Loaded MIME database from \"%s\" and \"%s\": %d types, "
- "%d filters...", mimedir, ServerRoot,
- mimeNumTypes(MimeDatabase), mimeNumFilters(MimeDatabase));
-
- /*
- * Create a list of MIME types for the document-format-supported
- * attribute...
- */
-
- NumMimeTypes = mimeNumTypes(MimeDatabase);
- if (!mimeType(MimeDatabase, "application", "octet-stream"))
- NumMimeTypes ++;
-
- if ((MimeTypes = calloc((size_t)NumMimeTypes, sizeof(const char *))) == NULL)
- {
- cupsdLogMessage(CUPSD_LOG_ERROR,
- "Unable to allocate memory for %d MIME types.",
- NumMimeTypes);
- NumMimeTypes = 0;
- }
- else
- {
- for (i = 0, type = mimeFirstType(MimeDatabase);
- type;
- i ++, type = mimeNextType(MimeDatabase))
- {
- snprintf(mimetype, sizeof(mimetype), "%s/%s", type->super, type->type);
-
- MimeTypes[i] = _cupsStrAlloc(mimetype);
- }
-
- if (i < NumMimeTypes)
- MimeTypes[i] = _cupsStrAlloc("application/octet-stream");
- }
+ cupsdLogMessage(CUPSD_LOG_INFO, "Loaded MIME database from \"%s\" and \"%s\": %d types, %d filters.", mimedir, ServerRoot, mimeNumTypes(MimeDatabase), mimeNumFilters(MimeDatabase));
if (LogLevel == CUPSD_LOG_DEBUG2)
{
+ mime_type_t *type; /* Current type */
mime_filter_t *filter; /* Current filter */
+ for (type = mimeFirstType(MimeDatabase); type; type = mimeNextType(MimeDatabase))
+ cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdReadConfiguration: type %s/%s", type->super, type->type);
- for (type = mimeFirstType(MimeDatabase);
- type;
- type = mimeNextType(MimeDatabase))
- cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdReadConfiguration: type %s/%s",
- type->super, type->type);
-
- for (filter = mimeFirstFilter(MimeDatabase);
- filter;
- filter = mimeNextFilter(MimeDatabase))
- cupsdLogMessage(CUPSD_LOG_DEBUG2,
- "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s",
- filter->src->super, filter->src->type,
- filter->dst->super, filter->dst->type,
- filter->cost, filter->filter);
+ for (filter = mimeFirstFilter(MimeDatabase); filter; filter = mimeNextFilter(MimeDatabase))
+ cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdReadConfiguration: filter %s/%s to %s/%s %d %s", filter->src->super, filter->src->type, filter->dst->super, filter->dst->type, filter->cost, filter->filter);
}
/*
/* Page log format */
VAR mime_t *MimeDatabase VALUE(NULL);
/* MIME type database */
-VAR int NumMimeTypes VALUE(0);
- /* Number of MIME types */
-VAR const char **MimeTypes VALUE(NULL);
- /* Array of MIME types */
+VAR cups_rwlock_t MimeLock VALUE(CUPS_RWLOCK_INITIALIZER);
+ // Read/write lock for MIME type database
VAR int CreateSelfSignedCerts VALUE(TRUE);
/* Automatically create self-signed certs? */
{
c->dst = dst;
- cupsRWLockWrite(&mime->lock);
if (!mime->ftypes)
mime->ftypes = cupsArrayNew3((cups_array_cb_t)mime_compare_ftypess, /*cb_data*/NULL, /*hash_cb*/NULL, /*hash_size*/0, /*copy_cb*/NULL, (cups_afree_cb_t)mime_free_ftypes);
cupsArrayAdd(mime->ftypes, c);
- cupsRWUnlock(&mime->lock);
}
}
// Lookup the destination type in the array...
key.dst = dst;
- cupsRWLockRead(&mime->lock);
match = (mime_ftypes_t *)cupsArrayFind(mime->ftypes, &key);
- cupsRWUnlock(&mime->lock);
return (match);
}
cupsCopyString(type, "octet-stream", sizeof(type));
}
- cupsRWLockRead(&MimeDatabase->lock);
+ cupsRWLockRead(&MimeLock);
if (!strcmp(super, "application") && !strcmp(type, "octet-stream"))
{
else
filetype = mimeType(MimeDatabase, super, type);
- cupsRWUnlock(&MimeDatabase->lock);
+ cupsRWUnlock(&MimeLock);
if (filetype &&
(!format ||
cupsCopyString(type, "octet-stream", sizeof(type));
}
- cupsRWLockRead(&MimeDatabase->lock);
+ cupsRWLockRead(&MimeLock);
if (!strcmp(super, "application") && !strcmp(type, "octet-stream"))
{
else
filetype = mimeType(MimeDatabase, super, type);
- cupsRWUnlock(&MimeDatabase->lock);
+ cupsRWUnlock(&MimeLock);
if (filetype)
{
return;
}
- cupsRWLockRead(&MimeDatabase->lock);
+ cupsRWLockRead(&MimeLock);
if ((strcmp(super, "application") || strcmp(type, "octet-stream")) &&
!mimeType(MimeDatabase, super, type))
ippAddString(con->response, IPP_TAG_UNSUPPORTED_GROUP, IPP_TAG_MIMETYPE,
"document-format", NULL, format->values[0].string.text);
- cupsRWUnlock(&MimeDatabase->lock);
+ cupsRWUnlock(&MimeLock);
return;
}
- cupsRWUnlock(&MimeDatabase->lock);
+ cupsRWUnlock(&MimeLock);
}
/*
if (stat(filename, &fileinfo))
fileinfo.st_size = 0;
- cupsRWLockWrite(&MimeDatabase->lock);
+ cupsRWLockWrite(&MimeLock);
if (job->print_as_raster)
{
ippSetString(job->attrs, &job->reasons, 0, "document-unprintable-error");
- cupsRWUnlock(&MimeDatabase->lock);
+ cupsRWUnlock(&MimeLock);
goto abort_job;
}
filters = prefilters;
}
- cupsRWUnlock(&MimeDatabase->lock);
+ cupsRWUnlock(&MimeLock);
}
/*
* Find all the d##### files...
*/
- cupsRWLockRead(&MimeDatabase->lock);
+ cupsRWLockRead(&MimeLock);
for (fileid = 1; fileid < 10000; fileid ++)
{
job->num_files = 0;
- cupsRWUnlock(&MimeDatabase->lock);
+ cupsRWUnlock(&MimeLock);
return (0);
}
"vnd.cups-raw");
}
- cupsRWUnlock(&MimeDatabase->lock);
+ cupsRWUnlock(&MimeLock);
}
/*
number --;
- cupsRWLockRead(&MimeDatabase->lock);
+ cupsRWLockRead(&MimeLock);
job->compressions[number] = compression;
job->filetypes[number] = mimeType(MimeDatabase, super, type);
"vnd.cups-raw");
}
- cupsRWUnlock(&MimeDatabase->lock);
+ cupsRWUnlock(&MimeLock);
}
else
cupsdLogMessage(CUPSD_LOG_ERROR, "Unknown %s directive on line %d of %s.", line, linenum, filename);
# include <cups/array.h>
# include <cups/ipp.h>
# include <cups/file.h>
-# include <cups/thread.h>
# include <regex.h>
# ifdef __cplusplus
extern "C" {
cups_array_t *ftypes; // Filter types
mime_error_cb_t error_cb; // Error message callback
void *error_ctx; // Pointer for callback
- cups_rwlock_t lock; // Read/write lock for guarding data for background updates
} mime_t;
p->accepting = 0;
p->shared = DefaultShared;
- cupsRWLockWrite(&MimeDatabase->lock);
+ cupsRWLockWrite(&MimeLock);
- p->filetype = mimeAddType(MimeDatabase, "printer", name);
+ p->filetype = mimeAddType(MimeDatabase, "printer", name);
- cupsRWUnlock(&MimeDatabase->lock);
+ cupsRWUnlock(&MimeLock);
cupsdSetString(&p->job_sheets[0], "none");
cupsdSetString(&p->job_sheets[1], "none");
if (p->printers != NULL)
free(p->printers);
- cupsRWLockWrite(&MimeDatabase->lock);
+ cupsRWLockWrite(&MimeLock);
delete_printer_filters(p);
mimeDeleteType(MimeDatabase, p->filetype);
mimeDeleteType(MimeDatabase, p->prefiltertype);
- cupsRWUnlock(&MimeDatabase->lock);
+ cupsRWUnlock(&MimeLock);
cupsdFreeStrings(&(p->users));
cupsdFreeQuotas(p);
* Rename the printer type...
*/
- cupsRWLockWrite(&MimeDatabase->lock);
+ cupsRWLockWrite(&MimeLock);
mimeDeleteType(MimeDatabase, p->filetype);
p->filetype = mimeAddType(MimeDatabase, "printer", name);
p->prefiltertype = mimeAddType(MimeDatabase, "prefilter", name);
}
- cupsRWUnlock(&MimeDatabase->lock);
+ cupsRWUnlock(&MimeLock);
/*
* Rename the printer...
cupsdCreateCommonData();
cupsRWLockWrite(&p->lock);
- cupsRWLockWrite(&MimeDatabase->lock);
/*
* Clear out old filters, if any...
*/
+ cupsRWLockWrite(&MimeLock);
delete_printer_filters(p);
+ cupsRWUnlock(&MimeLock);
/*
* Figure out the authentication that is required for the printer.
* Add filters for printer...
*/
- cupsdSetPrinterReasons(p, "-cups-missing-filter-warning,"
- "cups-insecure-filter-warning");
+ cupsRWLockWrite(&MimeLock);
+ cupsdSetPrinterReasons(p, "-cups-missing-filter-warning,cups-insecure-filter-warning");
if (p->pc && p->pc->filters)
{
- for (filter = (char *)cupsArrayFirst(p->pc->filters);
- filter;
- filter = (char *)cupsArrayNext(p->pc->filters))
+ for (filter = (char *)cupsArrayFirst(p->pc->filters); filter; filter = (char *)cupsArrayNext(p->pc->filters))
add_printer_filter(p, p->filetype, filter);
}
else if (!(p->type & CUPS_PTYPE_REMOTE))
* Add a PostScript filter, since this is still possibly PS printer.
*/
- add_printer_filter(p, p->filetype,
- "application/vnd.cups-postscript 0 -");
+ add_printer_filter(p, p->filetype, "application/vnd.cups-postscript 0 -");
}
if (p->pc && p->pc->prefilters)
if (!p->prefiltertype)
p->prefiltertype = mimeAddType(MimeDatabase, "prefilter", p->name);
- for (filter = (char *)cupsArrayFirst(p->pc->prefilters);
- filter;
- filter = (char *)cupsArrayNext(p->pc->prefilters))
+ for (filter = (char *)cupsArrayFirst(p->pc->prefilters); filter; filter = (char *)cupsArrayNext(p->pc->prefilters))
add_printer_filter(p, p->prefiltertype, filter);
}
}
+ cupsRWUnlock(&MimeLock);
+
/*
* Copy marker attributes as needed...
*/
* Populate the document-format-supported attribute...
*/
+ cupsRWLockWrite(&MimeLock);
add_printer_formats(p);
-
- cupsRWUnlock(&MimeDatabase->lock);
+ cupsRWUnlock(&MimeLock);
/*
* Add name-default attributes...
* Add the filter to the MIME database, supporting wildcards as needed...
*/
- for (temptype = mimeFirstType(MimeDatabase);
- temptype;
- temptype = mimeNextType(MimeDatabase))
- if (((super[0] == '*' && _cups_strcasecmp(temptype->super, "printer")) ||
- !_cups_strcasecmp(temptype->super, super)) &&
- (type[0] == '*' || !_cups_strcasecmp(temptype->type, type)))
+ for (temptype = mimeFirstType(MimeDatabase); temptype; temptype = mimeNextType(MimeDatabase))
+ {
+ if (((super[0] == '*' && _cups_strcasecmp(temptype->super, "printer")) || !_cups_strcasecmp(temptype->super, super)) && (type[0] == '*' || !_cups_strcasecmp(temptype->type, type)))
{
if (desttype != filtertype)
{
cupsdLogPrinter(p, CUPSD_LOG_DEBUG2, "add_printer_filter: Adding filter %s/%s %s/%s %d %s", temptype->super, temptype->type, desttype->super, desttype->type, cost, program);
- filterptr = mimeAddFilter(MimeDatabase, temptype, desttype, cost,
- program);
+ filterptr = mimeAddFilter(MimeDatabase, temptype, desttype, cost, program);
if (!mimeFilterLookup(MimeDatabase, desttype, filtertype))
{
else
{
cupsdLogPrinter(p, CUPSD_LOG_DEBUG2, "add_printer_filter: Adding filter %s/%s %s/%s %d %s", temptype->super, temptype->type, filtertype->super, filtertype->type, cost, program);
- filterptr = mimeAddFilter(MimeDatabase, temptype, filtertype, cost,
- program);
+ filterptr = mimeAddFilter(MimeDatabase, temptype, filtertype, cost, program);
}
if (filterptr)
filterptr->maxsize = maxsize;
}
+ }
}
if (p->raw)
{
- ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_CONST_TAG(IPP_TAG_MIMETYPE), "document-format-supported", NumMimeTypes, NULL, MimeTypes);
+ ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_CONST_TAG(IPP_TAG_MIMETYPE), "document-format-supported", NULL, "application/octet-stream");
return;
}
* Add the file formats that can be filtered...
*/
- if ((type = mimeType(MimeDatabase, "application", "octet-stream")) == NULL ||
- !cupsArrayFind(p->filetypes, type))
- i = 1;
- else
- i = 0;
-
- cupsdLogPrinter(p, CUPSD_LOG_DEBUG2, "add_printer_formats: %d supported types", cupsArrayCount(p->filetypes) + i);
+ cupsdLogPrinter(p, CUPSD_LOG_DEBUG2, "add_printer_formats: %d supported types", cupsArrayCount(p->filetypes) + 1);
- attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_MIMETYPE,
- "document-format-supported",
- cupsArrayCount(p->filetypes) + i, NULL, NULL);
+ attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_MIMETYPE, "document-format-supported", cupsArrayCount(p->filetypes) + 1, NULL, NULL);
+ attr->values[0].string.text = _cupsStrAlloc("application/octet-stream");
+ cupsdLogPrinter(p, CUPSD_LOG_DEBUG2, "add_printer_formats: document-format-supported[0]='application/octet-stream'");
- if (i)
- {
- attr->values[0].string.text = _cupsStrAlloc("application/octet-stream");
- cupsdLogPrinter(p, CUPSD_LOG_DEBUG2, "add_printer_formats: document-format-supported[0]='application/octet-stream'");
- }
-
- for (type = (mime_type_t *)cupsArrayFirst(p->filetypes); type; i ++, type = (mime_type_t *)cupsArrayNext(p->filetypes))
+ for (i = 1, type = (mime_type_t *)cupsArrayFirst(p->filetypes); type; i ++, type = (mime_type_t *)cupsArrayNext(p->filetypes))
{
snprintf(mimetype, sizeof(mimetype), "%s/%s", type->super, type->type);
* type == printer...
*/
- for (filter = mimeFirstFilter(MimeDatabase);
- filter;
- filter = mimeNextFilter(MimeDatabase))
+ for (filter = mimeFirstFilter(MimeDatabase); filter; filter = mimeNextFilter(MimeDatabase))
+ {
if (filter->dst == p->filetype || filter->dst == p->prefiltertype ||
cupsArrayFind(p->dest_types, filter->dst))
{
mimeDeleteFilter(MimeDatabase, filter);
}
+ }
- for (type = (mime_type_t *)cupsArrayFirst(p->dest_types);
- type;
- type = (mime_type_t *)cupsArrayNext(p->dest_types))
+ for (type = (mime_type_t *)cupsArrayFirst(p->dest_types); type; type = (mime_type_t *)cupsArrayNext(p->dest_types))
mimeDeleteType(MimeDatabase, type);
cupsArrayDelete(p->dest_types);
p->dest_types = NULL;
- cupsdSetPrinterReasons(p, "-cups-insecure-filter-warning"
- ",cups-missing-filter-warning");
+ cupsdSetPrinterReasons(p, "-cups-insecure-filter-warning,cups-missing-filter-warning");
}
_mimeFreeType(mime_type_t *t, // I - File type
void *data) // I - Callback data (not used)
{
+ (void)data;
+
mime_delete_rules(t->rules);
free(t);
}