From: Michael R Sweet Date: Fri, 21 Nov 2025 16:44:59 +0000 (-0500) Subject: Need to invalidate destination cache after removing filters. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2f597e3de631bb5bdc71a1bb45bb094e5da6e280;p=thirdparty%2Fcups.git Need to invalidate destination cache after removing filters. --- diff --git a/scheduler/filter.c b/scheduler/filter.c index c8cb2c5931..d1e4eb5320 100644 --- a/scheduler/filter.c +++ b/scheduler/filter.c @@ -14,14 +14,6 @@ #include "mime-private.h" -// -// Debug macros that used to be private API... -// - -#define DEBUG_puts(x) -#define DEBUG_printf(...) - - // // Local types... // @@ -37,7 +29,7 @@ typedef struct _mime_typelist_s // List of source types // Local functions... // -static int mime_compare_ftypess(mime_ftypes_t *a, mime_ftypes_t *b, void *data); +static int mime_compare_ftypes(mime_ftypes_t *a, mime_ftypes_t *b, void *data); static int mime_compare_filters(mime_filter_t *, mime_filter_t *, void *); static int mime_compare_srcs(mime_filter_t *, mime_filter_t *, void *); static mime_ftypes_t *mime_find_ftypes(mime_t *mime, mime_type_t *dst); @@ -59,75 +51,33 @@ mimeAddFilter(mime_t *mime, // I - MIME database const char *filter) // I - Filter program to run { mime_filter_t *temp; // New filter - mime_ftypes_t *c; // Filter cache - DEBUG_printf(("mimeAddFilter(mime=%p, src=%p(%s/%s), dst=%p(%s/%s), cost=%d, " - "filter=\"%s\")", mime, - src, src ? src->super : "???", src ? src->type : "???", - dst, dst ? dst->super : "???", dst ? dst->type : "???", - cost, filter)); - - /* - * Range-check the input... - */ + MIME_DEBUG("mimeAddFilter(mime=%p, src=%p(%s/%s), dst=%p(%s/%s), cost=%d, filter=\"%s\")\n", (void *)mime, (void *)src, src ? src->super : "???", src ? src->type : "???", (void *)dst, dst ? dst->super : "???", dst ? dst->type : "???", cost, filter); + // Range-check the input... if (!mime || !src || !dst || !filter) { - DEBUG_puts("1mimeAddFilter: Returning NULL."); + MIME_DEBUG("mimeAddFilter: Returning NULL.\n"); return (NULL); } - // See if we have a cache for this destination type... - if ((c = mime_find_ftypes(mime, dst)) == NULL) - { - // No, add a cache for this type... - if ((c = (mime_ftypes_t *)calloc(1, sizeof(mime_ftypes_t))) != NULL) - { - c->dst = dst; - - 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); - } - } - - if (c && !cupsArrayFind(c->srcs, src)) - { - // Add source type to list of source types that can be converted to the - // destination type... - if (!c->srcs) - c->srcs = cupsArrayNew3((cups_array_cb_t)_mimeCompareTypes, /*cb_data*/NULL, /*hash_cb*/NULL, /*hash_size*/0, /*copy_cb*/NULL, /*free_cb*/NULL); - - cupsArrayAdd(c->srcs, src); - } - - /* - * See if we already have an existing filter for the given source and - * destination... - */ - + // See if we already have an existing filter for the given source and + // destination... if ((temp = mimeFilterLookup(mime, src, dst)) != NULL) { - /* - * Yup, does the existing filter have a higher cost? If so, copy the - * filter and cost to the existing filter entry and return it... - */ - + // Yup, does the existing filter have a higher cost? If so, copy the + // filter and cost to the existing filter entry and return it... if (temp->cost > cost) { - DEBUG_printf(("1mimeAddFilter: Replacing filter \"%s\", cost %d.", - temp->filter, temp->cost)); + MIME_DEBUG("mimeAddFilter: Replacing filter \"%s\", cost %d.\n", temp->filter, temp->cost); temp->cost = cost; cupsCopyString(temp->filter, filter, sizeof(temp->filter)); } } else { - /* - * Nope, add a new one... - */ - + // Nope, add a new one... if (!mime->filters) mime->filters = cupsArrayNew3((cups_array_cb_t)mime_compare_filters, /*cb_data*/NULL, /*hash_cb*/NULL, /*hash_size*/0, /*copy_cb*/NULL, (cups_afree_cb_t)mime_free_filter); @@ -137,25 +87,19 @@ mimeAddFilter(mime_t *mime, // I - MIME database if ((temp = calloc(1, sizeof(mime_filter_t))) == NULL) return (NULL); - /* - * Copy the information over and sort if necessary... - */ - + // Copy the information over and sort if necessary... temp->src = src; temp->dst = dst; temp->cost = cost; cupsCopyString(temp->filter, filter, sizeof(temp->filter)); - DEBUG_puts("1mimeAddFilter: Adding new filter."); + MIME_DEBUG("mimeAddFilter: Adding new filter.\n"); cupsArrayAdd(mime->filters, temp); cupsArrayAdd(mime->srcs, temp); } - /* - * Return the new/updated filter... - */ - - DEBUG_printf("1mimeAddFilter: Returning %p.", temp); + // Return the new/updated filter... + MIME_DEBUG("mimeAddFilter: Returning %p.\n", (void *)temp); return (temp); } @@ -171,11 +115,7 @@ mimeFilter(mime_t *mime, // I - MIME database mime_type_t *dst, // I - Destination file type int *cost) // O - Cost of filters { - DEBUG_printf(("mimeFilter(mime=%p, src=%p(%s/%s), dst=%p(%s/%s), " - "cost=%p(%d))", mime, - src, src ? src->super : "???", src ? src->type : "???", - dst, dst ? dst->super : "???", dst ? dst->type : "???", - cost, cost ? *cost : 0)); + MIME_DEBUG("mimeFilter(mime=%p, src=%p(%s/%s), dst=%p(%s/%s), cost=%p(%d))\n", (void *)mime, (void *)src, src ? src->super : "???", src ? src->type : "???", (void *)dst, dst ? dst->super : "???", dst ? dst->type : "???", (void *)cost, cost ? *cost : 0); return (mimeFilter2(mime, src, 0, dst, cost)); } @@ -196,16 +136,8 @@ mimeFilter2(mime_t *mime, // I - MIME database cups_array_t *filters; // Array of filters to run - /* - * Range-check the input... - */ - - DEBUG_printf(("mimeFilter2(mime=%p, src=%p(%s/%s), srcsize=" CUPS_LLFMT - ", dst=%p(%s/%s), cost=%p(%d))", mime, - src, src ? src->super : "???", src ? src->type : "???", - CUPS_LLCAST srcsize, - dst, dst ? dst->super : "???", dst ? dst->type : "???", - cost, cost ? *cost : 0)); + // Range-check the input... + MIME_DEBUG("mimeFilter2(mime=%p, src=%p(%s/%s), srcsize=" CUPS_LLFMT ", dst=%p(%s/%s), cost=%p(%d))\n", (void *)mime, (void *)src, src ? src->super : "???", src ? src->type : "???", CUPS_LLCAST srcsize, (void *)dst, dst ? dst->super : "???", dst ? dst->type : "???", (void *)cost, cost ? *cost : 0); if (cost) *cost = 0; @@ -213,40 +145,27 @@ mimeFilter2(mime_t *mime, // I - MIME database if (!mime || !src || !dst) return (NULL); - /* - * (Re)build the source lookup array as needed... - */ - + // (Re)build the source lookup array as needed... if (!mime->srcs) { mime_filter_t *current; // Current filter mime->srcs = cupsArrayNew((cups_array_cb_t)mime_compare_srcs, NULL); - for (current = mimeFirstFilter(mime); - current; - current = mimeNextFilter(mime)) + for (current = mimeFirstFilter(mime); current; current = mimeNextFilter(mime)) cupsArrayAdd(mime->srcs, current); } - /* - * Find the filters... - */ - + // Find the filters... filters = mime_find_filters(mime, src, srcsize, dst, cost, NULL); - DEBUG_printf(("1mimeFilter2: Returning %d filter(s), cost %d:", - cupsArrayCount(filters), cost ? *cost : -1)); + MIME_DEBUG("mimeFilter2: Returning %d filter(s), cost %d:\n", cupsArrayCount(filters), cost ? *cost : -1); #ifdef DEBUG { mime_filter_t *filter; // Current filter - for (filter = (mime_filter_t *)cupsArrayFirst(filters); - filter; - filter = (mime_filter_t *)cupsArrayNext(filters)) - DEBUG_printf(("1mimeFilter2: %s/%s %s/%s %d %s", filter->src->super, - filter->src->type, filter->dst->super, filter->dst->type, - filter->cost, filter->filter)); + for (filter = (mime_filter_t *)cupsArrayFirst(filters); filter; filter = (mime_filter_t *)cupsArrayNext(filters)) + MIME_DEBUG("mimeFilter2: %s/%s %s/%s %d %s\n", filter->src->super, filter->src->type, filter->dst->super, filter->dst->type, filter->cost, filter->filter); } #endif // DEBUG @@ -267,13 +186,13 @@ mimeFilterLookup(mime_t *mime, // I - MIME database *filter; // Matching filter - DEBUG_printf("2mimeFilterLookup(mime=%p, src=%p(%s/%s), dst=%p(%s/%s))", mime, src, src ? src->super : "???", src ? src->type : "???", dst, dst ? dst->super : "???", dst ? dst->type : "???"); + MIME_DEBUG("mimeFilterLookup(mime=%p, src=%p(%s/%s), dst=%p(%s/%s))\n", (void *)mime, (void *)src, src ? src->super : "???", src ? src->type : "???", (void *)dst, dst ? dst->super : "???", dst ? dst->type : "???"); key.src = src; key.dst = dst; filter = (mime_filter_t *)cupsArrayFind(mime->filters, &key); - DEBUG_printf("3mimeFilterLookup: Returning %p(%s).", filter, filter ? filter->filter : "???"); + MIME_DEBUG("mimeFilterLookup: Returning %p(%s).\n", (void *)filter, filter ? filter->filter : "???"); return (filter); } @@ -287,21 +206,62 @@ mimeGetFilterTypes(mime_t *mime, // I - MIME database mime_type_t *dst, // I - Destination media type cups_array_t *srcs) // I - Array of source types or `NULL` for none { + MIME_DEBUG("mimeGetFilterTypes(mime=%p, dst=%p(%s/%s), srcs=%p)\n", (void *)mime, (void *)dst, dst ? dst->super : "???", dst ? dst->type : "???", (void *)srcs); + // Range check input... if (!mime || !dst) return (srcs); + // (Re)build the filter destination cache as needed... + if (!mime->ftypes) + { + mime_filter_t *current; // Current filter + mime_ftypes_t *cftype; // Current filter type + + MIME_DEBUG("mimeGetFilterTypes: Building the filter destination cache.\n"); + + mime->ftypes = cupsArrayNew3((cups_array_cb_t)mime_compare_ftypes, /*cb_data*/NULL, /*hash_cb*/NULL, /*hash_size*/0, /*copy_cb*/NULL, (cups_afree_cb_t)mime_free_ftypes); + + for (current = mimeFirstFilter(mime); current; current = mimeNextFilter(mime)) + { + // See if we have a cache for this destination type... + MIME_DEBUG("mimeGetFilterTypes: Filter '%s' (%s/%s to %s/%s, cost %d)\n", current->filter, current->src->super, current->src->type, current->dst->super, current->dst->type, current->cost); + + if ((cftype = mime_find_ftypes(mime, current->dst)) == NULL) + { + // No, add a cache for this type... + if ((cftype = (mime_ftypes_t *)calloc(1, sizeof(mime_ftypes_t))) != NULL) + { + MIME_DEBUG("mimeGetFilterTypes: Adding %s/%s to destination cache.\n", current->dst->super, current->dst->type); + cftype->dst = current->dst; + cupsArrayAdd(mime->ftypes, cftype); + } + } + + if (cftype && !cupsArrayFind(cftype->srcs, current->src)) + { + // Add source type to list of source types that can be converted to the + // destination type... + if (!cftype->srcs) + cftype->srcs = cupsArrayNew3((cups_array_cb_t)_mimeCompareTypes, /*cb_data*/NULL, /*hash_cb*/NULL, /*hash_size*/0, /*copy_cb*/NULL, /*free_cb*/NULL); + + MIME_DEBUG("mimeGetFilterTypes: Adding %s/%s to %s/%s association.\n", current->src->super, current->src->type, current->dst->super, current->dst->type); + cupsArrayAdd(cftype->srcs, current->src); + } + } + } + // Get source types... return (mime_get_filter_types(mime, dst, srcs, 0)); } // -// 'mime_compare_ftypess()' - Compare two filter caches. +// 'mime_compare_ftypes()' - Compare two filter caches. // static int // O - Result of comparison -mime_compare_ftypess( +mime_compare_ftypes( mime_ftypes_t *a, // I - First cache mime_ftypes_t *b, // I - Second cache void *data) // I - Callback data (not used) @@ -387,24 +347,20 @@ mime_find_filters( *listptr; // Pointer in list - DEBUG_printf("2mime_find_filters(mime=%p, src=%p(%s/%s), srcsize=" CUPS_LLFMT ", dst=%p(%s/%s), cost=%p, list=%p)", mime, src, src->super, src->type, CUPS_LLCAST srcsize, dst, dst->super, dst->type, cost, list); + MIME_DEBUG("mime_find_filters(mime=%p, src=%p(%s/%s), srcsize=" CUPS_LLFMT ", dst=%p(%s/%s), cost=%p, list=%p)\n", (void *)mime, (void *)src, src->super, src->type, CUPS_LLCAST srcsize, (void *)dst, dst->super, dst->type, (void *)cost, (void *)list); /* * See if there is a filter that can convert the files directly... */ - if ((current = mimeFilterLookup(mime, src, dst)) != NULL && - (current->maxsize == 0 || srcsize <= current->maxsize)) + if ((current = mimeFilterLookup(mime, src, dst)) != NULL && (current->maxsize == 0 || srcsize <= current->maxsize)) { - /* - * Got a direct filter! - */ - - DEBUG_puts("3mime_find_filters: Direct filter found."); + // Got a direct filter! + MIME_DEBUG("mime_find_filters: Direct filter found.\n"); if ((mintemp = cupsArrayNew(NULL, NULL)) == NULL) { - DEBUG_puts("3mime_find_filters: Returning NULL (out of memory)."); + MIME_DEBUG("mime_find_filters: Returning NULL (out of memory).\n"); return (NULL); } @@ -414,70 +370,48 @@ mime_find_filters( if (!cost) { - DEBUG_printf(("3mime_find_filters: Returning 1 filter, cost %d:", - mincost)); - DEBUG_printf(("3mime_find_filters: %s/%s %s/%s %d %s", - current->src->super, current->src->type, - current->dst->super, current->dst->type, - current->cost, current->filter)); + MIME_DEBUG("mime_find_filters: Returning 1 filter, cost %d:\n", mincost); + MIME_DEBUG("mime_find_filters: %s/%s %s/%s %d %s\n", current->src->super, current->src->type, current->dst->super, current->dst->type, current->cost, current->filter); return (mintemp); } } else { - /* - * No direct filter... - */ - + // No direct filter... mintemp = NULL; mincost = 9999999; } - /* - * Initialize this node in the type list... - */ - + // Initialize this node in the type list... listnode.next = list; - /* - * OK, now look for filters from the source type to any other type... - */ - + // OK, now look for filters from the source type to any other type... srckey.src = src; - for (current = (mime_filter_t *)cupsArrayFind(mime->srcs, &srckey); - current && current->src == src; - current = (mime_filter_t *)cupsArrayNext(mime->srcs)) + for (current = (mime_filter_t *)cupsArrayFind(mime->srcs, &srckey); current && current->src == src; current = (mime_filter_t *)cupsArrayNext(mime->srcs)) { - /* - * See if we have already tried the destination type as a source - * type (this avoids extra filter looping...) - */ - + // See if we have already tried the destination type as a source + // type (this avoids extra filter looping...) mime_type_t *current_dst; // Current destination type if (current->maxsize > 0 && srcsize > current->maxsize) continue; - for (listptr = list, current_dst = current->dst; - listptr; - listptr = listptr->next) + for (listptr = list, current_dst = current->dst; listptr; listptr = listptr->next) + { if (current_dst == listptr->src) break; + } if (listptr) continue; - /* - * See if we have any filters that can convert from the destination type - * of this filter to the final type... - */ - + // See if we have any filters that can convert from the destination type + // of this filter to the final type... listnode.src = current->src; cupsArraySave(mime->srcs); - temp = mime_find_filters(mime, current->dst, srcsize, dst, &tempcost, - &listnode); + temp = mime_find_filters(mime, current->dst, srcsize, dst, &tempcost, &listnode); cupsArrayRestore(mime->srcs); if (!temp) @@ -485,63 +419,43 @@ mime_find_filters( if (!cost) { - DEBUG_printf(("3mime_find_filters: Returning %d filter(s), cost %d:", - cupsArrayCount(temp), tempcost)); + MIME_DEBUG("mime_find_filters: Returning %d filter(s), cost %d:\n", cupsArrayCount(temp), tempcost); #ifdef DEBUG - for (current = (mime_filter_t *)cupsArrayFirst(temp); - current; - current = (mime_filter_t *)cupsArrayNext(temp)) - DEBUG_printf(("3mime_find_filters: %s/%s %s/%s %d %s", - current->src->super, current->src->type, - current->dst->super, current->dst->type, - current->cost, current->filter)); + for (current = (mime_filter_t *)cupsArrayFirst(temp); current; current = (mime_filter_t *)cupsArrayNext(temp)) + MIME_DEBUG("mime_find_filters: %s/%s %s/%s %d %s\n", current->src->super, current->src->type, current->dst->super, current->dst->type, current->cost, current->filter); #endif // DEBUG return (temp); } - /* - * Found a match; see if this one is less costly than the last (if - * any...) - */ - + // Found a match; see if this one is less costly than the last (if any...) tempcost += current->cost; if (tempcost < mincost) { cupsArrayDelete(mintemp); - /* - * Hey, we got a match! Add the current filter to the beginning of the - * filter list... - */ - + // Hey, we got a match! Add the current filter to the beginning of the + // filter list... mintemp = temp; mincost = tempcost; cupsArrayInsert(mintemp, current); } else + { cupsArrayDelete(temp); + } } if (mintemp) { - /* - * Hey, we got a match! - */ - - DEBUG_printf(("3mime_find_filters: Returning %d filter(s), cost %d:", - cupsArrayCount(mintemp), mincost)); + // Hey, we got a match! + MIME_DEBUG("mime_find_filters: Returning %d filter(s), cost %d:\n", cupsArrayCount(mintemp), mincost); #ifdef DEBUG - for (current = (mime_filter_t *)cupsArrayFirst(mintemp); - current; - current = (mime_filter_t *)cupsArrayNext(mintemp)) - DEBUG_printf(("3mime_find_filters: %s/%s %s/%s %d %s", - current->src->super, current->src->type, - current->dst->super, current->dst->type, - current->cost, current->filter)); + for (current = (mime_filter_t *)cupsArrayFirst(mintemp); current; current = (mime_filter_t *)cupsArrayNext(mintemp)) + MIME_DEBUG("mime_find_filters: %s/%s %s/%s %d %s\n", current->src->super, current->src->type, current->dst->super, current->dst->type, current->cost, current->filter); #endif // DEBUG if (cost) @@ -550,7 +464,7 @@ mime_find_filters( return (mintemp); } - DEBUG_puts("3mime_find_filters: Returning NULL (no matches)."); + MIME_DEBUG("mime_find_filters: Returning NULL (no matches).\n"); return (NULL); } @@ -627,6 +541,7 @@ mime_get_filter_types( srcs = cupsArrayNew3((cups_array_cb_t)_mimeCompareTypes, /*cb_data*/NULL, /*hash_cb*/NULL, /*hash_size*/0, /*copy_cb*/NULL, /*free_cb*/NULL); // Add the source to the array... + MIME_DEBUG("mime_get_filter_types: Adding %s/%s to %s/%s filter.\n", src->super, src->type, dst->super, dst->type); cupsArrayAdd(srcs, src); if (level < 4) @@ -638,5 +553,10 @@ mime_get_filter_types( } } +#ifdef DEBUG + if (level == 0) + MIME_DEBUG("mime_get_filter_types: Returning %p(%d entries)\n", (void *)srcs, (int)cupsArrayGetCount(srcs)); +#endif // DEBUG + return (srcs); } diff --git a/scheduler/mime-private.h b/scheduler/mime-private.h index 824cb6adf8..dd013bc449 100644 --- a/scheduler/mime-private.h +++ b/scheduler/mime-private.h @@ -23,6 +23,17 @@ extern "C" { # endif // __cplusplus +// +// Debug macros (simpler than for libcups)... +// + +# ifdef DEBUG +# define MIME_DEBUG(...) fprintf(stderr, __VA_ARGS__) +# else +# define MIME_DEBUG(...) +# endif // DEBUG + + // // Prototypes... // diff --git a/scheduler/mime.c b/scheduler/mime.c index 91a69f0de8..1de91c4191 100644 --- a/scheduler/mime.c +++ b/scheduler/mime.c @@ -15,14 +15,6 @@ #include "mime-private.h" -// -// Debug macros that used to be private API... -// - -#define DEBUG_puts(x) -#define DEBUG_printf(...) - - // // Local types... // @@ -52,7 +44,7 @@ static void mime_load_types(mime_t *mime, const char *filename); void mimeDelete(mime_t *mime) // I - MIME database { - DEBUG_printf("mimeDelete(mime=%p)", mime); + MIME_DEBUG("mimeDelete(mime=%p)\n", (void *)mime); if (!mime) return; @@ -74,27 +66,32 @@ void mimeDeleteFilter(mime_t *mime, // I - MIME database mime_filter_t *filter) // I - Filter { - DEBUG_printf("mimeDeleteFilter(mime=%p, filter=%p(%s/%s->%s/%s, cost=%d, maxsize=" CUPS_LLFMT "))", mime, filter, filter ? filter->src->super : "???", filter ? filter->src->type : "???", filter ? filter->dst->super : "???", filter ? filter->dst->super : "???", filter ? filter->cost : -1, filter ? CUPS_LLCAST filter->maxsize : CUPS_LLCAST -1); + MIME_DEBUG("mimeDeleteFilter(mime=%p, filter=%p(%s/%s->%s/%s, cost=%d, maxsize=" CUPS_LLFMT "))\n", (void *)mime, (void *)filter, filter ? filter->src->super : "???", filter ? filter->src->type : "???", filter ? filter->dst->super : "???", filter ? filter->dst->super : "???", filter ? filter->cost : -1, filter ? CUPS_LLCAST filter->maxsize : CUPS_LLCAST -1); if (!mime || !filter) return; #ifdef DEBUG if (!cupsArrayFind(mime->filters, filter)) - DEBUG_puts("1mimeDeleteFilter: Filter not in MIME database."); + MIME_DEBUG("mimeDeleteFilter: Filter not in MIME database.\n"); #endif // DEBUG cupsArrayRemove(mime->filters, filter); - // Deleting a filter invalidates the source lookup cache used by mimeFilter()... + // Deleting a filter invalidates the source and destination lookup caches... if (mime->srcs) { - DEBUG_puts("1mimeDeleteFilter: Deleting source lookup cache."); + MIME_DEBUG("mimeDeleteFilter: Deleting source lookup cache.\n"); cupsArrayDelete(mime->srcs); mime->srcs = NULL; } - // TODO: Also invalidate the filter types array? + if (mime->ftypes) + { + MIME_DEBUG("mimeDeleteFilter: Deleting destination lookup cache.\n"); + cupsArrayDelete(mime->ftypes); + mime->ftypes = NULL; + } } @@ -106,14 +103,14 @@ void mimeDeleteType(mime_t *mime, // I - MIME database mime_type_t *mt) // I - Type { - DEBUG_printf("mimeDeleteType(mime=%p, mt=%p(%s/%s))", mime, mt, mt ? mt->super : "???", mt ? mt->type : "???"); + MIME_DEBUG("mimeDeleteType(mime=%p, mt=%p(%s/%s))\n", (void *)mime, (void *)mt, mt ? mt->super : "???", mt ? mt->type : "???"); if (!mime || !mt) return; #ifdef DEBUG if (!cupsArrayFind(mime->types, mt)) - DEBUG_puts("1mimeDeleteFilter: Type not in MIME database."); + MIME_DEBUG("mimeDeleteFilter: Type not in MIME database.\n"); #endif // DEBUG cupsArrayRemove(mime->types, mt); @@ -151,11 +148,11 @@ _mimeError(mime_t *mime, // I - MIME database mime_filter_t * // O - Filter or NULL mimeFirstFilter(mime_t *mime) // I - MIME database { - DEBUG_printf("6mimeFirstFilter(mime=%p)", mime); + MIME_DEBUG("mimeFirstFilter(mime=%p)\n", (void *)mime); if (!mime) { - DEBUG_puts("7mimeFirstFilter: Returning NULL."); + MIME_DEBUG("mimeFirstFilter: Returning NULL.\n"); return (NULL); } else @@ -163,7 +160,7 @@ mimeFirstFilter(mime_t *mime) // I - MIME database mime_filter_t *first = (mime_filter_t *)cupsArrayGetFirst(mime->filters); // First filter - DEBUG_printf("7mimeFirstFilter: Returning %p.", first); + MIME_DEBUG("mimeFirstFilter: Returning %p.\n", (void *)first); return (first); } } @@ -176,11 +173,11 @@ mimeFirstFilter(mime_t *mime) // I - MIME database mime_type_t * // O - Type or NULL mimeFirstType(mime_t *mime) // I - MIME database { - DEBUG_printf("6mimeFirstType(mime=%p)", mime); + MIME_DEBUG("mimeFirstType(mime=%p)\n", (void *)mime); if (!mime) { - DEBUG_puts("7mimeFirstType: Returning NULL."); + MIME_DEBUG("mimeFirstType: Returning NULL.\n"); return (NULL); } else @@ -188,7 +185,7 @@ mimeFirstType(mime_t *mime) // I - MIME database mime_type_t *first = (mime_type_t *)cupsArrayGetFirst(mime->types); // First type - DEBUG_printf("7mimeFirstType: Returning %p.", first); + MIME_DEBUG("mimeFirstType: Returning %p.\n", (void *)first); return (first); } } @@ -207,10 +204,10 @@ mimeLoad(const char *pathname, // I - Directory to load { mime_t *mime; // New MIME database - DEBUG_printf("mimeLoad(pathname=\"%s\", filterpath=\"%s\")", pathname, filterpath); + MIME_DEBUG("mimeLoad(pathname=\"%s\", filterpath=\"%s\")\n", pathname, filterpath); mime = mimeLoadFilters(mimeLoadTypes(NULL, pathname), pathname, filterpath); - DEBUG_printf("1mimeLoad: Returning %p.", mime); + MIME_DEBUG("mimeLoad: Returning %p.\n", (void *)mime); return (mime); } @@ -234,19 +231,19 @@ mimeLoadFilters(mime_t *mime, // I - MIME database cups_array_t *filtercache; // Filter cache - DEBUG_printf("mimeLoadFilters(mime=%p, pathname=\"%s\", filterpath=\"%s\")", mime, pathname, filterpath); + MIME_DEBUG("mimeLoadFilters(mime=%p, pathname=\"%s\", filterpath=\"%s\")\n", (void *)mime, pathname, filterpath); // Range check input... if (!mime || !pathname || !filterpath) { - DEBUG_puts("1mimeLoadFilters: Bad arguments."); + MIME_DEBUG("mimeLoadFilters: Bad arguments.\n"); return (mime); } // Then open the directory specified by pathname... if ((dir = cupsDirOpen(pathname)) == NULL) { - DEBUG_printf("1mimeLoadFilters: Unable to open \"%s\": %s", pathname, strerror(errno)); + MIME_DEBUG("mimeLoadFilters: Unable to open \"%s\": %s\n", pathname, strerror(errno)); _mimeError(mime, "Unable to open \"%s\": %s", pathname, strerror(errno)); return (mime); } @@ -260,7 +257,7 @@ mimeLoadFilters(mime_t *mime, // I - MIME database { // Load a mime.convs file... snprintf(filename, sizeof(filename), "%s/%s", pathname, dent->filename); - DEBUG_printf("1mimeLoadFilters: Loading \"%s\".", filename); + MIME_DEBUG("mimeLoadFilters: Loading \"%s\".\n", filename); mime_load_convs(mime, filename, filterpath, filtercache); } } @@ -289,13 +286,13 @@ mimeLoadTypes(mime_t *mime, // I - MIME database or @code NULL@ to create a char filename[1024]; // Full filename of .types file - DEBUG_printf("mimeLoadTypes(mime=%p, pathname=\"%s\")", mime, pathname); + MIME_DEBUG("mimeLoadTypes(mime=%p, pathname=\"%s\")\n", (void *)mime, pathname); // First open the directory specified by pathname... if ((dir = cupsDirOpen(pathname)) == NULL) { - DEBUG_printf("1mimeLoadTypes: Unable to open \"%s\": %s", pathname, strerror(errno)); - DEBUG_printf("1mimeLoadTypes: Returning %p.", mime); + MIME_DEBUG("mimeLoadTypes: Unable to open \"%s\": %s\n", pathname, strerror(errno)); + MIME_DEBUG("mimeLoadTypes: Returning %p.\n", (void *)mime); _mimeError(mime, "Unable to open \"%s\": %s", pathname, strerror(errno)); return (mime); } @@ -307,7 +304,7 @@ mimeLoadTypes(mime_t *mime, // I - MIME database or @code NULL@ to create a if (!mime) { cupsDirClose(dir); - DEBUG_puts("1mimeLoadTypes: Returning NULL."); + MIME_DEBUG("mimeLoadTypes: Returning NULL.\n"); return (NULL); } @@ -318,14 +315,14 @@ mimeLoadTypes(mime_t *mime, // I - MIME database or @code NULL@ to create a { // Load a mime.types file... snprintf(filename, sizeof(filename), "%s/%s", pathname, dent->filename); - DEBUG_printf("1mimeLoadTypes: Loading \"%s\".", filename); + MIME_DEBUG("mimeLoadTypes: Loading \"%s\".\n", filename); mime_load_types(mime, filename); } } cupsDirClose(dir); - DEBUG_printf("1mimeLoadTypes: Returning %p.", mime); + MIME_DEBUG("mimeLoadTypes: Returning %p.\n", (void *)mime); return (mime); } @@ -349,11 +346,11 @@ mimeNew(void) mime_filter_t * // O - Filter or NULL mimeNextFilter(mime_t *mime) // I - MIME database { - DEBUG_printf("6mimeNextFilter(mime=%p)", mime); + MIME_DEBUG("mimeNextFilter(mime=%p)\n", (void *)mime); if (!mime) { - DEBUG_puts("7mimeNextFilter: Returning NULL."); + MIME_DEBUG("mimeNextFilter: Returning NULL.\n"); return (NULL); } else @@ -361,7 +358,7 @@ mimeNextFilter(mime_t *mime) // I - MIME database mime_filter_t *next = (mime_filter_t *)cupsArrayGetNext(mime->filters); // Next filter - DEBUG_printf("7mimeNextFilter: Returning %p.", next); + MIME_DEBUG("mimeNextFilter: Returning %p.\n", (void *)next); return (next); } } @@ -374,11 +371,11 @@ mimeNextFilter(mime_t *mime) // I - MIME database mime_type_t * // O - Type or NULL mimeNextType(mime_t *mime) // I - MIME database { - DEBUG_printf("6mimeNextType(mime=%p)", mime); + MIME_DEBUG("mimeNextType(mime=%p)\n", (void *)mime); if (!mime) { - DEBUG_puts("7mimeNextType: Returning NULL."); + MIME_DEBUG("mimeNextType: Returning NULL.\n"); return (NULL); } else @@ -386,7 +383,7 @@ mimeNextType(mime_t *mime) // I - MIME database mime_type_t *next = (mime_type_t *)cupsArrayGetNext(mime->types); // Next type - DEBUG_printf("7mimeNextType: Returning %p.", next); + MIME_DEBUG("mimeNextType: Returning %p.\n", (void *)next); return (next); } } @@ -399,16 +396,16 @@ mimeNextType(mime_t *mime) // I - MIME database int mimeNumFilters(mime_t *mime) // I - MIME database { - DEBUG_printf("mimeNumFilters(mime=%p)", mime); + MIME_DEBUG("mimeNumFilters(mime=%p\n)", (void *)mime); if (!mime) { - DEBUG_puts("1mimeNumFilters: Returning 0."); + MIME_DEBUG("mimeNumFilters: Returning 0.\n"); return (0); } else { - DEBUG_printf("1mimeNumFilters: Returning %d.", (int)cupsArrayGetCount(mime->filters)); + MIME_DEBUG("mimeNumFilters: Returning %d.\n", (int)cupsArrayGetCount(mime->filters)); return ((int)cupsArrayGetCount(mime->filters)); } } @@ -421,16 +418,16 @@ mimeNumFilters(mime_t *mime) // I - MIME database int mimeNumTypes(mime_t *mime) // I - MIME database { - DEBUG_printf("mimeNumTypes(mime=%p)", mime); + MIME_DEBUG("mimeNumTypes(mime=%p\n)", (void *)mime); if (!mime) { - DEBUG_puts("1mimeNumTypes: Returning 0."); + MIME_DEBUG("mimeNumTypes: Returning 0.\n"); return (0); } else { - DEBUG_printf("1mimeNumTypes: Returning %d.", (int)cupsArrayGetCount(mime->types)); + MIME_DEBUG("mimeNumTypes: Returning %d.\n", (int)cupsArrayGetCount(mime->types)); return ((int)cupsArrayGetCount(mime->types)); } } @@ -469,18 +466,18 @@ mime_add_fcache( char path[1024]; // Full path to filter - DEBUG_printf("2mime_add_fcache(filtercache=%p, name=\"%s\", filterpath=\"%s\")", filtercache, name, filterpath); + MIME_DEBUG("mime_add_fcache(filtercache=%p, name=\"%s\", filterpath=\"%s\")", filtercache, name, filterpath); key.name = (char *)name; if ((temp = (_mime_fcache_t *)cupsArrayFind(filtercache, &key)) != NULL) { - DEBUG_printf("3mime_add_fcache: Returning \"%s\".", temp->path); + MIME_DEBUG("mime_add_fcache: Returning \"%s\".\n", temp->path); return (temp->path); } if ((temp = calloc(1, sizeof(_mime_fcache_t))) == NULL) { - DEBUG_puts("3mime_add_fcache: Returning NULL."); + MIME_DEBUG("mime_add_fcache: Returning NULL.\n"); return (NULL); } @@ -491,7 +488,7 @@ mime_add_fcache( cupsArrayAdd(filtercache, temp); - DEBUG_printf("3mime_add_fcache: Returning \"%s\".", temp->path); + MIME_DEBUG("mime_add_fcache: Returning \"%s\".\n", temp->path); return (temp->path); } @@ -523,7 +520,7 @@ mime_delete_fcache( _mime_fcache_t *current; // Current cache entry - DEBUG_printf("2mime_delete_fcache(filtercache=%p)", filtercache); + MIME_DEBUG("mime_delete_fcache(filtercache=%p)\n", (void *)filtercache); for (current = (_mime_fcache_t *)cupsArrayGetFirst(filtercache); current; current = (_mime_fcache_t *)cupsArrayGetNext(filtercache)) { @@ -559,12 +556,12 @@ mime_load_convs( int cost; // Cost of filter - DEBUG_printf("2mime_load_convs(mime=%p, filename=\"%s\", filterpath=\"%s\", filtercache=%p)", mime, filename, filterpath, filtercache); + MIME_DEBUG("mime_load_convs(mime=%p, filename=\"%s\", filterpath=\"%s\", filtercache=%p)\n", (void *)mime, filename, filterpath, (void *)filtercache); // First try to open the file... if ((fp = cupsFileOpen(filename, "r")) == NULL) { - DEBUG_printf("3mime_load_convs: Unable to open \"%s\": %s", filename, strerror(errno)); + MIME_DEBUG("mime_load_convs: Unable to open \"%s\": %s\n", filename, strerror(errno)); _mimeError(mime, "Unable to open \"%s\": %s", filename, strerror(errno)); return; } @@ -612,7 +609,7 @@ mime_load_convs( if ((dsttype = mimeType(mime, super, type)) == NULL) { - DEBUG_printf("3mime_load_convs: Destination type %s/%s not found.", super, type); + MIME_DEBUG("mime_load_convs: Destination type %s/%s not found.\n", super, type); continue; } @@ -640,7 +637,7 @@ mime_load_convs( // Verify that the filter exists and is executable... if (!mime_add_fcache(filtercache, filter, filterpath)) { - DEBUG_printf("mime_load_convs: Filter %s not found in %s.", filter, filterpath); + MIME_DEBUG("mime_load_convs: Filter %s not found in %s.\n", filter, filterpath); _mimeError(mime, "Filter \"%s\" not found.", filter); continue; } @@ -704,12 +701,12 @@ mime_load_types(mime_t *mime, // I - MIME database mime_type_t *typeptr; // New MIME type - DEBUG_printf("2mime_load_types(mime=%p, filename=\"%s\")", mime, filename); + MIME_DEBUG("mime_load_types(mime=%p, filename=\"%s\")\n", (void *)mime, filename); // First try to open the file... if ((fp = cupsFileOpen(filename, "r")) == NULL) { - DEBUG_printf("3mime_load_types: Unable to open \"%s\": %s", filename, strerror(errno)); + MIME_DEBUG("mime_load_types: Unable to open \"%s\": %s\n", filename, strerror(errno)); _mimeError(mime, "Unable to open \"%s\": %s", filename, strerror(errno)); return; } diff --git a/scheduler/printers.c b/scheduler/printers.c index 12a73008be..2e64bf2606 100644 --- a/scheduler/printers.c +++ b/scheduler/printers.c @@ -3671,12 +3671,16 @@ delete_printer_filters( * Delete the current filter... */ + cupsdLogPrinter(p, CUPSD_LOG_DEBUG2, "delete_printer_filters: Removing filter '%s' (%s/%s to %s/%s, cost %d)", filter->filter, filter->src->super, filter->src->type, filter->dst->super, filter->dst->type, filter->cost); mimeDeleteFilter(MimeDatabase, filter); } } for (type = (mime_type_t *)cupsArrayFirst(p->dest_types); type; type = (mime_type_t *)cupsArrayNext(p->dest_types)) + { + cupsdLogPrinter(p, CUPSD_LOG_DEBUG2, "delete_printer_filters: Removing type %s/%s", type->super, type->type); mimeDeleteType(MimeDatabase, type); + } cupsArrayDelete(p->dest_types); p->dest_types = NULL; diff --git a/scheduler/type.c b/scheduler/type.c index ba6aa3dfb1..0a4548a19c 100644 --- a/scheduler/type.c +++ b/scheduler/type.c @@ -15,14 +15,6 @@ #include "mime-private.h" -// -// Debug macros that used to be private API... -// - -#define DEBUG_puts(x) -#define DEBUG_printf(...) - - // // Local types... // @@ -83,20 +75,19 @@ mimeAddType(mime_t *mime, // I - MIME database size_t typelen; // Length of type name - DEBUG_printf(("mimeAddType(mime=%p, super=\"%s\", type=\"%s\")", mime, super, - type)); + MIME_DEBUG("mimeAddType(mime=%p, super=\"%s\", type=\"%s\")\n", (void *)mime, super, type); // Range check input... if (!mime || !super || !*super || !type || !*type) { - DEBUG_puts("1mimeAddType: Returning NULL (bad arguments)."); + MIME_DEBUG("mimeAddType: Returning NULL (bad arguments)."); return (NULL); } // See if the type already exists; if so, return the existing type... if ((temp = mimeType(mime, super, type)) != NULL) { - DEBUG_printf("1mimeAddType: Returning %p (existing).", temp); + MIME_DEBUG("mimeAddType: Returning %p (existing).\n", (void *)temp); return (temp); } @@ -106,7 +97,7 @@ mimeAddType(mime_t *mime, // I - MIME database if (!mime->types) { - DEBUG_puts("1mimeAddType: Returning NULL (no types)."); + MIME_DEBUG("mimeAddType: Returning NULL (no types).\n"); return (NULL); } @@ -114,7 +105,7 @@ mimeAddType(mime_t *mime, // I - MIME database if ((temp = calloc(1, sizeof(mime_type_t) - MIME_MAX_TYPE + typelen)) == NULL) { - DEBUG_puts("1mimeAddType: Returning NULL (out of memory)."); + MIME_DEBUG("mimeAddType: Returning NULL (out of memory).\n"); return (NULL); } @@ -124,7 +115,7 @@ mimeAddType(mime_t *mime, // I - MIME database cupsArrayAdd(mime->types, temp); - DEBUG_printf("1mimeAddType: Returning %p (new).", temp); + MIME_DEBUG("mimeAddType: Returning %p (new).\n", (void *)temp); return (temp); } @@ -150,8 +141,7 @@ mimeAddTypeRule(mime_type_t *mt, // I - Type to add to *current; // Current rule - DEBUG_printf(("mimeAddTypeRule(mt=%p(%s/%s), rule=\"%s\")", mt, - mt ? mt->super : "???", mt ? mt->type : "???", rule)); + MIME_DEBUG("mimeAddTypeRule(mt=%p(%s/%s), rule=\"%s\")\n", (void *)mt, mt ? mt->super : "???", mt ? mt->type : "???", rule); // Range check input... if (!mt || !rule) @@ -159,8 +149,10 @@ mimeAddTypeRule(mime_type_t *mt, // I - Type to add to // Find the last rule in the top-level of the rules tree. for (current = mt->rules; current; current = current->next) + { if (!current->next) break; + } // Parse the rules string. Most rules are either a file extension or a // comparison function: @@ -177,13 +169,13 @@ mimeAddTypeRule(mime_type_t *mt, // I - Type to add to if (*rule == '(') { - DEBUG_puts("1mimeAddTypeRule: New parenthesis group"); + MIME_DEBUG("mimeAddTypeRule: New parenthesis group.\n"); logic = MIME_MAGIC_NOP; rule ++; } else if (*rule == ')') { - DEBUG_puts("1mimeAddTypeRule: Close paren..."); + MIME_DEBUG("mimeAddTypeRule: Close paren.\n"); if (current == NULL || current->parent == NULL) return (-1); @@ -215,11 +207,11 @@ mimeAddTypeRule(mime_type_t *mt, // I - Type to add to current->prev = NULL; current->parent = temp; - DEBUG_printf("1mimeAddTypeRule: Creating new AND group %p.", temp); + MIME_DEBUG("mimeAddTypeRule: Creating new AND group %p.\n", (void *)temp); } else if (current->parent) { - DEBUG_printf("1mimeAddTypeRule: Setting group %p op to AND.", current->parent); + MIME_DEBUG("mimeAddTypeRule: Setting group %p op to AND.\n", (void *)current->parent); current->parent->op = MIME_MAGIC_AND; } @@ -239,7 +231,7 @@ mimeAddTypeRule(mime_type_t *mt, // I - Type to add to if ((temp = calloc(1, sizeof(mime_magic_t))) == NULL) return (-1); - DEBUG_printf("1mimeAddTypeRule: Creating new AND group %p inside OR group.", temp); + MIME_DEBUG("mimeAddTypeRule: Creating new AND group %p inside OR group.\n", (void *)temp); while (current->prev != NULL) { @@ -256,7 +248,7 @@ mimeAddTypeRule(mime_type_t *mt, // I - Type to add to else { // This isn't the top rule, so go up one level... - DEBUG_puts("1mimeAddTypeRule: Going up one level."); + MIME_DEBUG("mimeAddTypeRule: Going up one level.\n"); current = current->parent; } } @@ -266,7 +258,7 @@ mimeAddTypeRule(mime_type_t *mt, // I - Type to add to } else if (*rule == '!') { - DEBUG_puts("1mimeAddTypeRule: NOT"); + MIME_DEBUG("mimeAddTypeRule: NOT\n"); invert = 1; rule ++; } @@ -420,7 +412,7 @@ mimeAddTypeRule(mime_type_t *mt, // I - Type to add to if (logic == MIME_MAGIC_NOP) { // Add parenthetical grouping... - DEBUG_printf("1mimeAddTypeRule: Making new OR group %p for parenthesis.", temp); + MIME_DEBUG("mimeAddTypeRule: Making new OR group %p for parenthesis.\n", (void *)temp); temp->op = MIME_MAGIC_OR; @@ -435,7 +427,7 @@ mimeAddTypeRule(mime_type_t *mt, // I - Type to add to logic = MIME_MAGIC_OR; } - DEBUG_printf("1mimeAddTypeRule: Adding %p: %s, op=MIME_MAGIC_%s(%d), logic=MIME_MAGIC_%s, invert=%d.", temp, name, debug_ops[op], op, debug_ops[logic], invert); + MIME_DEBUG("mimeAddTypeRule: Adding %p: %s, op=MIME_MAGIC_%s(%d), logic=MIME_MAGIC_%s, invert=%d.\n", (void *)temp, name, debug_ops[op], op, debug_ops[logic], invert); // Fill in data for the rule... current = temp; @@ -479,8 +471,7 @@ mimeAddTypeRule(mime_type_t *mt, // I - Type to add to else temp->value.charv = (unsigned char)strtol(value[1], NULL, 0); - DEBUG_printf(("1mimeAddTypeRule: CHAR(%d,0x%02x)", temp->offset, - temp->value.charv)); + MIME_DEBUG("mimeAddTypeRule: CHAR(%d,0x%02x)", temp->offset, temp->value.charv); break; case MIME_MAGIC_SHORT : temp->offset = strtol(value[0], NULL, 0); @@ -553,22 +544,20 @@ mimeFileType(mime_t *mime, // I - MIME database *best; // Best match - DEBUG_printf(("mimeFileType(mime=%p, pathname=\"%s\", filename=\"%s\", " - "compression=%p)", mime, pathname, filename, compression)); + MIME_DEBUG("mimeFileType(mime=%p, pathname=\"%s\", filename=\"%s\", compression=%p)\n", (void *)mime, pathname, filename, (void *)compression); // Range check input parameters... if (!mime || !pathname) { - DEBUG_puts("1mimeFileType: Returning NULL."); + MIME_DEBUG("mimeFileType: Returning NULL.\n"); return (NULL); } // Try to open the file... if ((fb.fp = cupsFileOpen(pathname, "r")) == NULL) { - DEBUG_printf(("1mimeFileType: Unable to open \"%s\": %s", pathname, - strerror(errno))); - DEBUG_puts("1mimeFileType: Returning NULL."); + MIME_DEBUG("mimeFileType: Unable to open \"%s\": %s\n", pathname, strerror(errno)); + MIME_DEBUG("mimeFileType: Returning NULL.\n"); return (NULL); } @@ -579,8 +568,8 @@ mimeFileType(mime_t *mime, // I - MIME database if (fb.length <= 0) { - DEBUG_printf("1mimeFileType: Unable to read from \"%s\": %s", pathname, strerror(errno)); - DEBUG_puts("1mimeFileType: Returning NULL."); + MIME_DEBUG("mimeFileType: Unable to read from \"%s\": %s\n", pathname, strerror(errno)); + MIME_DEBUG("mimeFileType: Returning NULL.\n"); cupsFileClose(fb.fp); @@ -618,13 +607,12 @@ mimeFileType(mime_t *mime, // I - MIME database if (compression) { *compression = cupsFileCompression(fb.fp); - DEBUG_printf("1mimeFileType: *compression=%d", *compression); + MIME_DEBUG("mimeFileType: *compression=%d\n", *compression); } cupsFileClose(fb.fp); - DEBUG_printf(("1mimeFileType: Returning %p(%s/%s).", best, - best ? best->super : "???", best ? best->type : "???")); + MIME_DEBUG("mimeFileType: Returning %p(%s/%s).\n", (void *)best, best ? best->super : "???", best ? best->type : "???"); return (best); } @@ -657,13 +645,12 @@ mimeType(mime_t *mime, // I - MIME database *mt; // Matching type - DEBUG_printf(("mimeType(mime=%p, super=\"%s\", type=\"%s\")", mime, super, - type)); + MIME_DEBUG("mimeType(mime=%p, super=\"%s\", type=\"%s\")\n", (void *)mime, super, type); // Range check input... if (!mime || !super || !type) { - DEBUG_puts("1mimeType: Returning NULL."); + MIME_DEBUG("mimeType: Returning NULL.\n"); return (NULL); } @@ -672,7 +659,7 @@ mimeType(mime_t *mime, // I - MIME database cupsCopyString(key.type, type, sizeof(key.type)); mt = (mime_type_t *)cupsArrayFind(mime->types, &key); - DEBUG_printf("1mimeType: Returning %p.", mt); + MIME_DEBUG("mimeType: Returning %p.\n", (void *)mt); return (mt); } @@ -696,7 +683,7 @@ mime_check_rules( unsigned char *bufptr; // Pointer into buffer - DEBUG_printf("4mime_check_rules(filename=\"%s\", fb=%p, rules=%p)", filename, fb, rules); + MIME_DEBUG("mime_check_rules(filename=\"%s\", fb=%p, rules=%p)\n", filename, (void *)fb, (void *)rules); if (rules == NULL) return (0); @@ -733,7 +720,7 @@ mime_check_rules( fb->offset = rules->offset; } - DEBUG_printf("4mime_check_rules: MIME_MAGIC_ASCII fb->length=%d", fb->length); + MIME_DEBUG("mime_check_rules: MIME_MAGIC_ASCII fb->length=%d", fb->length); } // Test for ASCII printable characters plus standard control chars. @@ -777,7 +764,7 @@ mime_check_rules( fb->offset = rules->offset; } - DEBUG_printf("4mime_check_rules: MIME_MAGIC_PRINTABLE fb->length=%d", fb->length); + MIME_DEBUG("mime_check_rules: MIME_MAGIC_PRINTABLE fb->length=%d", fb->length); } // Test for 8-bit printable characters plus standard control chars. @@ -803,7 +790,7 @@ mime_check_rules( break; case MIME_MAGIC_REGEX : - DEBUG_printf("5mime_check_rules: regex(%d, \"%s\")", rules->offset, rules->value.stringv); + MIME_DEBUG("mime_check_rules: regex(%d, \"%s\")", rules->offset, rules->value.stringv); // Load the buffer if necessary... if (fb->offset < 0 || rules->offset < fb->offset || (rules->offset + rules->length) > (fb->offset + fb->length)) @@ -820,9 +807,9 @@ mime_check_rules( fb->offset = rules->offset; } - DEBUG_printf("4mime_check_rules: MIME_MAGIC_REGEX fb->length=%d", fb->length); + MIME_DEBUG("mime_check_rules: MIME_MAGIC_REGEX fb->length=%d", fb->length); - DEBUG_printf("5mime_check_rules: loaded %d byte fb->buffer at %d, starts with \"%c%c%c%c\".", fb->length, fb->offset, fb->buffer[0], fb->buffer[1], fb->buffer[2], fb->buffer[3]); + MIME_DEBUG("mime_check_rules: loaded %d byte fb->buffer at %d, starts with \"%c%c%c%c\".", fb->length, fb->offset, fb->buffer[0], fb->buffer[1], fb->buffer[2], fb->buffer[3]); } // Compare the buffer against the string. If the file is too @@ -837,11 +824,11 @@ mime_check_rules( result = !regexec(&(rules->value.rev), temp, 0, NULL, 0); } - DEBUG_printf("5mime_check_rules: result=%d", result); + MIME_DEBUG("mime_check_rules: result=%d", result); break; case MIME_MAGIC_STRING : - DEBUG_printf("5mime_check_rules: string(%d, \"%s\")", rules->offset, rules->value.stringv); + MIME_DEBUG("mime_check_rules: string(%d, \"%s\")", rules->offset, rules->value.stringv); // Load the buffer if necessary... if (fb->offset < 0 || rules->offset < fb->offset || (rules->offset + rules->length) > (fb->offset + fb->length)) @@ -858,9 +845,9 @@ mime_check_rules( fb->offset = rules->offset; } - DEBUG_printf("4mime_check_rules: MIME_MAGIC_STRING fb->length=%d", fb->length); + MIME_DEBUG("mime_check_rules: MIME_MAGIC_STRING fb->length=%d", fb->length); - DEBUG_printf("5mime_check_rules: loaded %d byte fb->buffer at %d, starts with \"%c%c%c%c\".", fb->length, fb->offset, fb->buffer[0], fb->buffer[1], fb->buffer[2], fb->buffer[3]); + MIME_DEBUG("mime_check_rules: loaded %d byte fb->buffer at %d, starts with \"%c%c%c%c\".", fb->length, fb->offset, fb->buffer[0], fb->buffer[1], fb->buffer[2], fb->buffer[3]); } // Compare the buffer against the string. If the file is too @@ -869,7 +856,7 @@ mime_check_rules( result = 0; else result = !memcmp(fb->buffer + rules->offset - fb->offset, rules->value.stringv, (size_t)rules->length); - DEBUG_printf("5mime_check_rules: result=%d", result); + MIME_DEBUG("mime_check_rules: result=%d", result); break; case MIME_MAGIC_ISTRING : @@ -888,7 +875,7 @@ mime_check_rules( fb->offset = rules->offset; } - DEBUG_printf("4mime_check_rules: MIME_MAGIC_ISTRING fb->length=%d", fb->length); + MIME_DEBUG("mime_check_rules: MIME_MAGIC_ISTRING fb->length=%d", fb->length); } // Compare the buffer against the string. If the file is too @@ -915,7 +902,7 @@ mime_check_rules( fb->offset = rules->offset; } - DEBUG_printf("4mime_check_rules: MIME_MAGIC_CHAR fb->length=%d", fb->length); + MIME_DEBUG("mime_check_rules: MIME_MAGIC_CHAR fb->length=%d", fb->length); } // Compare the character values; if the file is too short, it @@ -942,7 +929,7 @@ mime_check_rules( fb->offset = rules->offset; } - DEBUG_printf("4mime_check_rules: MIME_MAGIC_SHORT fb->length=%d", fb->length); + MIME_DEBUG("mime_check_rules: MIME_MAGIC_SHORT fb->length=%d", fb->length); } // Compare the short values; if the file is too short, it can't match... @@ -974,7 +961,7 @@ mime_check_rules( fb->offset = rules->offset; } - DEBUG_printf("4mime_check_rules: MIME_MAGIC_INT fb->length=%d", fb->length); + MIME_DEBUG("mime_check_rules: MIME_MAGIC_INT fb->length=%d", fb->length); } // Compare the int values; if the file is too short, it can't match... @@ -1014,7 +1001,7 @@ mime_check_rules( fb->offset = rules->offset; } - DEBUG_printf("4mime_check_rules: MIME_MAGIC_CONTAINS fb->length=%d", fb->length); + MIME_DEBUG("mime_check_rules: MIME_MAGIC_CONTAINS fb->length=%d", fb->length); } // Compare the buffer against the string. If the file is too @@ -1053,7 +1040,7 @@ mime_check_rules( // OK, now if the current logic is OR and this result is true, this // rule set is true. If the current logic is AND and this result is false, // the rule set is false... - DEBUG_printf("5mime_check_rules: result of test %p (MIME_MAGIC_%s) is %d", rules, debug_ops[rules->op], result); + MIME_DEBUG("mime_check_rules: result of test %p (MIME_MAGIC_%s) is %d.\n", (void *)rules, debug_ops[rules->op], result); if ((result && logic == MIME_MAGIC_OR) || (!result && logic == MIME_MAGIC_AND)) return (result); @@ -1076,7 +1063,7 @@ mime_delete_rules(mime_magic_t *rules) // I - Rules to free mime_magic_t *next; // Next rule to free - DEBUG_printf("2mime_delete_rules(rules=%p)", rules); + MIME_DEBUG("mime_delete_rules(rules=%p)\n", (void *)rules); // Free the rules list, descending recursively to free any child rules. while (rules != NULL)