From: Rose <83477269+AtariDreams@users.noreply.github.com> Date: Sun, 23 Apr 2023 20:02:16 +0000 (-0400) Subject: Create shims to pass to array structures as to not pass incompatible function pointers X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cfe4c0c3783252782e29f94f93d8d528cdf0a60e;p=thirdparty%2Fcups.git Create shims to pass to array structures as to not pass incompatible function pointers Although it may seem to work on modern systems, casting functions that do not have the same number of arguments as the expected type can cause ABI problems and will be removed from the latest version of C. By sheer luck, most modern ABIs and compilers will treat the CPU register that contains the third argumentas a scratch register that may contain information from the function that called itand push it to the stack just in case. However, not all ABIs are guaranteed to do this, and because this program is not supposed to rely on these implementation details, it is best to ensure by the C standard that undefined behavior, or platform-dependent behavior, does not occur by the creation of private shim functions meant to be passed. The reason I did this instead of changing the function definition is to maintain backwards compatibility; some of the functions being passed are public API and therefore I cannot change them. This is the best I could do, but if there is anything else I could do, please let me know. --- diff --git a/backend/dnssd.c b/backend/dnssd.c index 14a6772fb7..8f48a9e272 100644 --- a/backend/dnssd.c +++ b/backend/dnssd.c @@ -101,7 +101,7 @@ static void client_callback(AvahiClient *client, void *context); #endif /* HAVE_AVAHI */ -static int compare_devices(cups_device_t *a, cups_device_t *b); +static int compare_devices(cups_device_t *a, cups_device_t *b, void *data); static void exec_backend(char **argv) _CUPS_NORETURN; static cups_device_t *get_device(cups_array_t *devices, const char *serviceName, const char *regtype, const char *replyDomain) _CUPS_NONNULL(1,2,3,4); #ifdef HAVE_MDNSRESPONDER @@ -721,8 +721,10 @@ client_callback( static int /* O - Result of comparison */ compare_devices(cups_device_t *a, /* I - First device */ - cups_device_t *b) /* I - Second device */ + cups_device_t *b, /* I - Second device */ + void *data) /* I - Unused */ { + (void)data; return (strcmp(a->name, b->name)); } diff --git a/backend/ipp.c b/backend/ipp.c index be1f2c0481..b89fdd75e8 100644 --- a/backend/ipp.c +++ b/backend/ipp.c @@ -3534,7 +3534,7 @@ update_reasons(ipp_attribute_t *attr, /* I - printer-state-reasons or NULL */ { int i; /* Looping var */ - new_reasons = cupsArrayNew((cups_array_func_t)strcmp, NULL); + new_reasons = cupsArrayNew((cups_array_func_t)_cupsArrayStrcmp, NULL); op = '\0'; for (i = 0; i < attr->num_values; i ++) diff --git a/backend/snmp.c b/backend/snmp.c index 17a29f8eeb..6a21ca63f9 100644 --- a/backend/snmp.c +++ b/backend/snmp.c @@ -121,7 +121,7 @@ static void add_cache(http_addr_t *addr, const char *addrname, const char *make_and_model); static device_uri_t *add_device_uri(char *value); static void alarm_handler(int sig); -static int compare_cache(snmp_cache_t *a, snmp_cache_t *b); +static int compare_cache(snmp_cache_t *a, snmp_cache_t *b, void *data); static void debug_printf(const char *format, ...); static void fix_make_model(char *make_model, const char *old_make_model, @@ -441,10 +441,12 @@ alarm_handler(int sig) /* I - Signal number */ * 'compare_cache()' - Compare two cache entries. */ -static int /* O - Result of comparison */ -compare_cache(snmp_cache_t *a, /* I - First cache entry */ - snmp_cache_t *b) /* I - Second cache entry */ +static int /* O - Result of comparison */ +compare_cache(snmp_cache_t *a, /* I - First cache entry */ + snmp_cache_t *b, /* I - Second cache entry */ + void *data) /* I - Unused */ { + (void)data; return (_cups_strcasecmp(a->addrname, b->addrname)); } diff --git a/backend/usb-libusb.c b/backend/usb-libusb.c index 281102fee8..1c591a0ac3 100644 --- a/backend/usb-libusb.c +++ b/backend/usb-libusb.c @@ -128,7 +128,7 @@ libusb_device **all_list; /* List of connected USB devices */ */ static int close_device(usb_printer_t *printer); -static int compare_quirks(usb_quirk_t *a, usb_quirk_t *b); +static int compare_quirks(usb_quirk_t *a, usb_quirk_t *b, void *data); static usb_printer_t *find_device(usb_cb_t cb, const void *data); static unsigned find_quirks(int vendor_id, int product_id); static int get_device_id(usb_printer_t *printer, char *buffer, @@ -771,12 +771,15 @@ close_device(usb_printer_t *printer) /* I - Printer */ * 'compare_quirks()' - Compare two quirks entries. */ -static int /* O - Result of comparison */ -compare_quirks(usb_quirk_t *a, /* I - First quirk entry */ - usb_quirk_t *b) /* I - Second quirk entry */ +static int /* O - Result of comparison */ +compare_quirks(usb_quirk_t *a, /* I - First quirk entry */ + usb_quirk_t *b, /* I - Second quirk entry */ + void *data) /* I - Unused */ { int result; /* Result of comparison */ + (void)data; + if ((result = b->vendor_id - a->vendor_id) == 0) result = b->product_id - a->product_id; diff --git a/cgi-bin/admin.c b/cgi-bin/admin.c index 863e885568..096eb34f99 100644 --- a/cgi-bin/admin.c +++ b/cgi-bin/admin.c @@ -1985,7 +1985,7 @@ do_list_printers(http_t *http) /* I - HTTP connection */ * Allocate an array and copy the device strings... */ - printer_devices = cupsArrayNew((cups_array_func_t)strcmp, NULL); + printer_devices = cupsArrayNew((cups_array_func_t)_cupsArrayStrcmp, NULL); for (attr = ippFindAttribute(response, "device-uri", IPP_TAG_URI); attr; diff --git a/cgi-bin/help-index.c b/cgi-bin/help-index.c index 4a10235f33..05bdc6638e 100644 --- a/cgi-bin/help-index.c +++ b/cgi-bin/help-index.c @@ -136,9 +136,9 @@ static int help_load_file(help_index_t *hi, const char *relative, time_t mtime); static help_node_t *help_new_node(const char *filename, const char *anchor, const char *section, const char *text, time_t mtime, off_t offset, size_t length) _CUPS_NONNULL(1,3,4); -static int help_sort_by_name(help_node_t *p1, help_node_t *p2); -static int help_sort_by_score(help_node_t *p1, help_node_t *p2); -static int help_sort_words(help_word_t *w1, help_word_t *w2); +static int help_sort_by_name(help_node_t *p1, help_node_t *p2, void *data); +static int help_sort_by_score(help_node_t *p1, help_node_t *p2, void *data); +static int help_sort_words(help_word_t *w1, help_word_t *w2, void *data); /* @@ -1205,9 +1205,10 @@ help_new_node(const char *filename, /* I - Filename */ * 'help_sort_nodes_by_name()' - Sort nodes by section, filename, and anchor. */ -static int /* O - Difference */ -help_sort_by_name(help_node_t *n1, /* I - First node */ - help_node_t *n2) /* I - Second node */ +static int /* O - Difference */ +help_sort_by_name(help_node_t *n1, /* I - First node */ + help_node_t *n2, /* I - Second node */ + void *data) /* Unused */ { int diff; /* Difference */ @@ -1230,13 +1231,16 @@ help_sort_by_name(help_node_t *n1, /* I - First node */ * 'help_sort_nodes_by_score()' - Sort nodes by score and text. */ -static int /* O - Difference */ -help_sort_by_score(help_node_t *n1, /* I - First node */ - help_node_t *n2) /* I - Second node */ +static int /* O - Difference */ +help_sort_by_score(help_node_t *n1, /* I - First node */ + help_node_t *n2, /* I - Second node */ + void *data) /* I - Unused */ { int diff; /* Difference */ + (void)data; + if (n1->score != n2->score) return (n2->score - n1->score); @@ -1256,9 +1260,11 @@ help_sort_by_score(help_node_t *n1, /* I - First node */ * 'help_sort_words()' - Sort words alphabetically. */ -static int /* O - Difference */ -help_sort_words(help_word_t *w1, /* I - Second word */ - help_word_t *w2) /* I - Second word */ +static int /* O - Difference */ +help_sort_words(help_word_t *w1, /* I - Second word */ + help_word_t *w2, /* I - Second word */ + void *data) /* Unused */ { + (void)data; return (_cups_strcasecmp(w1->text, w2->text)); } diff --git a/cups/array.c b/cups/array.c index 41289a5c22..f54e66485a 100644 --- a/cups/array.c +++ b/cups/array.c @@ -787,9 +787,9 @@ _cupsArrayNewStrings(const char *s, /* I - Delimited strings or NULL */ cups_array_t *a; /* Array */ - if ((a = cupsArrayNew3((cups_array_func_t)strcmp, NULL, NULL, 0, - (cups_acopy_func_t)_cupsStrAlloc, - (cups_afree_func_t)_cupsStrFree)) != NULL) + if ((a = cupsArrayNew3((cups_array_func_t)_cupsArrayStrcmp, NULL, NULL, 0, + (cups_acopy_func_t)_cupsStrPrivAlloc, + (cups_afree_func_t)_cupsStrPrivFree)) != NULL) _cupsArrayAddStrings(a, s, delim); return (a); @@ -1317,3 +1317,43 @@ cups_array_find(cups_array_t *a, /* I - Array */ return (current); } + + +/* + * '_cupsArrayStrcmp()' - Meant to be passed as a pointer to CUPS arrays instead + * of strcmp. Will also work if called directly. + */ + +int _cupsArrayStrcmp(const char *s1, /* I - first string to compare */ + const char *s2, /* I - second string to compare */ + void *data) /* Unused */ +{ + (void)data; + return (strcmp(s1, s2)); +} + + +/* + * '_cupsArrayStrdup()' - Meant to be passed as a pointer to CUPS arrays instead + * of strdup. Will also work if called directly. + */ + +char *_cupsArrayStrdup(const char *element, /* I - element to duplicate */ + void *data) /* Unused */ +{ + (void)data; + return (strdup(element)); +} + + +/* + * '_cupsArrayFree()' - Meant to be passed as a pointer to CUPS arrays instead + * of free. Will also work if called directly. + */ + +void _cupsArrayFree(void *element, /* I - element to free */ + void *data) /* Unused */ +{ + (void)data; + free(element); +} diff --git a/cups/dest-options.c b/cups/dest-options.c index d0d683d7a6..4555c10829 100644 --- a/cups/dest-options.c +++ b/cups/dest-options.c @@ -30,18 +30,18 @@ static void cups_add_dconstres(cups_array_t *a, ipp_t *collection); static int cups_collection_contains(ipp_t *test, ipp_t *match); static size_t cups_collection_string(ipp_attribute_t *attr, char *buffer, size_t bufsize) _CUPS_NONNULL((1,2)); -static int cups_compare_dconstres(_cups_dconstres_t *a, - _cups_dconstres_t *b); -static int cups_compare_media_db(_cups_media_db_t *a, - _cups_media_db_t *b); -static _cups_media_db_t *cups_copy_media_db(_cups_media_db_t *mdb); +static int cups_compare_dconstres(_cups_dconstres_t *a, _cups_dconstres_t *b, + void *data); +static int cups_compare_media_db(_cups_media_db_t *a, _cups_media_db_t *b, + void *data); +static _cups_media_db_t *cups_copy_media_db(_cups_media_db_t *mdb, void *data); static void cups_create_cached(http_t *http, cups_dinfo_t *dinfo, unsigned flags); static void cups_create_constraints(cups_dinfo_t *dinfo); static void cups_create_defaults(cups_dinfo_t *dinfo); static void cups_create_media_db(cups_dinfo_t *dinfo, unsigned flags); -static void cups_free_media_db(_cups_media_db_t *mdb); +static void cups_free_media_db(_cups_media_db_t *mdb, void *data); static int cups_get_media_db(http_t *http, cups_dinfo_t *dinfo, pwg_media_t *pwg, unsigned flags, cups_size_t *size); @@ -1730,11 +1730,12 @@ cups_collection_string( * 'cups_compare_dconstres()' - Compare to resolver entries. */ -static int /* O - Result of comparison */ -cups_compare_dconstres( - _cups_dconstres_t *a, /* I - First resolver */ - _cups_dconstres_t *b) /* I - Second resolver */ +static int /* O - Result of comparison */ +cups_compare_dconstres(_cups_dconstres_t *a, /* I - First resolver */ + _cups_dconstres_t *b, /* I - Second resolver */ + void *data) /* Unused */ { + (void)data; return (strcmp(a->name, b->name)); } @@ -1743,13 +1744,14 @@ cups_compare_dconstres( * 'cups_compare_media_db()' - Compare two media entries. */ -static int /* O - Result of comparison */ -cups_compare_media_db( - _cups_media_db_t *a, /* I - First media entries */ - _cups_media_db_t *b) /* I - Second media entries */ +static int /* O - Result of comparison */ +cups_compare_media_db(_cups_media_db_t *a, /* I - First media entries */ + _cups_media_db_t *b, /* I - Second media entries */ + void *data) /* Unused */ { int result; /* Result of comparison */ + (void)data; if ((result = a->width - b->width) == 0) result = a->length - b->length; @@ -1762,12 +1764,13 @@ cups_compare_media_db( * 'cups_copy_media_db()' - Copy a media entry. */ -static _cups_media_db_t * /* O - New media entry */ -cups_copy_media_db( - _cups_media_db_t *mdb) /* I - Media entry to copy */ +static _cups_media_db_t * /* O - New media entry */ +cups_copy_media_db(_cups_media_db_t *mdb, /* I - Media entry to copy */ + void *data) /* Unused */ { _cups_media_db_t *temp; /* New media entry */ + (void)data; if ((temp = calloc(1, sizeof(_cups_media_db_t))) == NULL) return (NULL); @@ -1888,12 +1891,9 @@ cups_create_constraints( ipp_attribute_t *attr; /* Attribute */ _ipp_value_t *val; /* Current value */ - - dinfo->constraints = cupsArrayNew3(NULL, NULL, NULL, 0, NULL, - (cups_afree_func_t)free); - dinfo->resolvers = cupsArrayNew3((cups_array_func_t)cups_compare_dconstres, - NULL, NULL, 0, NULL, - (cups_afree_func_t)free); + dinfo->constraints = cupsArrayNew3(NULL, NULL, NULL, 0, NULL, _cupsArrayFree); + dinfo->resolvers = cupsArrayNew3((cups_array_func_t)cups_compare_dconstres, + NULL, NULL, 0, NULL, _cupsArrayFree); if ((attr = ippFindAttribute(dinfo->attrs, "job-constraints-supported", IPP_TAG_BEGIN_COLLECTION)) != NULL) @@ -2253,9 +2253,10 @@ cups_create_media_db( */ static void -cups_free_media_db( - _cups_media_db_t *mdb) /* I - Media entry to free */ +cups_free_media_db(_cups_media_db_t *mdb, /* I - Media entry to free */ + void *data) /* I - Unused */ { + (void)data; if (mdb->color) _cupsStrFree(mdb->color); if (mdb->key) @@ -2332,11 +2333,11 @@ cups_get_media_db(http_t *http, /* I - Connection to destination */ if (best->left != 0 || best->right != 0 || best->top != 0 || best->bottom != 0) { - for (mdb = (_cups_media_db_t *)cupsArrayNext(db); - mdb && !cups_compare_media_db(mdb, &key); - mdb = (_cups_media_db_t *)cupsArrayNext(db)) - { - if (mdb->left <= best->left && mdb->right <= best->right && + for (mdb = (_cups_media_db_t *)cupsArrayNext(db); + mdb && !cups_compare_media_db(mdb, &key, NULL); + mdb = (_cups_media_db_t *)cupsArrayNext(db)) + { + if (mdb->left <= best->left && mdb->right <= best->right && mdb->top <= best->top && mdb->bottom <= best->bottom) { best = mdb; @@ -2344,7 +2345,7 @@ cups_get_media_db(http_t *http, /* I - Connection to destination */ mdb->top == 0) break; } - } + } } /* @@ -2363,10 +2364,10 @@ cups_get_media_db(http_t *http, /* I - Connection to destination */ */ for (mdb = (_cups_media_db_t *)cupsArrayNext(db); - mdb && !cups_compare_media_db(mdb, &key); - mdb = (_cups_media_db_t *)cupsArrayNext(db)) + mdb && !cups_compare_media_db(mdb, &key, NULL); + mdb = (_cups_media_db_t *)cupsArrayNext(db)) { - if (mdb->left >= best->left && mdb->right >= best->right && + if (mdb->left >= best->left && mdb->right >= best->right && mdb->top >= best->top && mdb->bottom >= best->bottom && (mdb->bottom != best->bottom || mdb->left != best->left || mdb->right != best->right || mdb->top != best->top)) best = mdb; @@ -2379,10 +2380,10 @@ cups_get_media_db(http_t *http, /* I - Connection to destination */ */ for (mdb = (_cups_media_db_t *)cupsArrayNext(db); - mdb && !cups_compare_media_db(mdb, &key); - mdb = (_cups_media_db_t *)cupsArrayNext(db)) + mdb && !cups_compare_media_db(mdb, &key, NULL); + mdb = (_cups_media_db_t *)cupsArrayNext(db)) { - if (((mdb->left > 0 && mdb->left <= best->left) || best->left == 0) && + if (((mdb->left > 0 && mdb->left <= best->left) || best->left == 0) && ((mdb->right > 0 && mdb->right <= best->right) || best->right == 0) && ((mdb->top > 0 && mdb->top <= best->top) || best->top == 0) && ((mdb->bottom > 0 && mdb->bottom <= best->bottom) || best->bottom == 0) && diff --git a/cups/dest.c b/cups/dest.c index da775a3901..416bd2ddc2 100644 --- a/cups/dest.c +++ b/cups/dest.c @@ -185,7 +185,7 @@ static void cups_dnssd_client_cb(AvahiClient *client, void *context); # endif /* HAVE_MDNSRESPONDER */ static int cups_dnssd_compare_devices(_cups_dnssd_device_t *a, - _cups_dnssd_device_t *b); + _cups_dnssd_device_t *b, void *data); static void cups_dnssd_free_device(_cups_dnssd_device_t *device, _cups_dnssd_data_t *data); static _cups_dnssd_device_t * @@ -2706,11 +2706,12 @@ cups_dnssd_client_cb( * 'cups_dnssd_compare_device()' - Compare two devices. */ -static int /* O - Result of comparison */ -cups_dnssd_compare_devices( - _cups_dnssd_device_t *a, /* I - First device */ - _cups_dnssd_device_t *b) /* I - Second device */ +static int /* O - Result of comparison */ +cups_dnssd_compare_devices(_cups_dnssd_device_t *a, /* I - First device */ + _cups_dnssd_device_t *b, /* I - Second device */ + void *data) /* Unused */ { + (void)data; return (strcmp(a->dest.name, b->dest.name)); } diff --git a/cups/ipp-support.c b/cups/ipp-support.c index bb0c6c8bd9..e0574c219e 100644 --- a/cups/ipp-support.c +++ b/cups/ipp-support.c @@ -1947,7 +1947,7 @@ ippCreateRequestedArray(ipp_t *request) /* I - IPP request */ if (op == IPP_OP_GET_JOBS) { - ra = cupsArrayNew((cups_array_func_t)strcmp, NULL); + ra = cupsArrayNew((cups_array_func_t)_cupsArrayStrcmp, NULL); cupsArrayAdd(ra, "job-id"); cupsArrayAdd(ra, "job-uri"); @@ -1969,7 +1969,7 @@ ippCreateRequestedArray(ipp_t *request) /* I - IPP request */ * Create an array using "strcmp" as the comparison function... */ - ra = cupsArrayNew((cups_array_func_t)strcmp, NULL); + ra = cupsArrayNew((cups_array_func_t)_cupsArrayStrcmp, NULL); for (i = 0; i < count; i ++) { diff --git a/cups/language.c b/cups/language.c index 96e828332f..6f5d6fcfa0 100644 --- a/cups/language.c +++ b/cups/language.c @@ -145,8 +145,9 @@ static cups_array_t *appleMessageLoad(const char *locale) CF_RETURNS_RETAINED; # endif /* CUPS_BUNDLEDIR */ #endif /* __APPLE__ */ static cups_lang_t *cups_cache_lookup(const char *name, cups_encoding_t encoding); -static int cups_message_compare(_cups_message_t *m1, _cups_message_t *m2); -static void cups_message_free(_cups_message_t *m); +static int cups_message_compare(_cups_message_t *m1, _cups_message_t *m2, + void *data); +static void cups_message_free(_cups_message_t *m, void *data); static void cups_message_load(cups_lang_t *lang); static void cups_message_puts(cups_file_t *fp, const char *s); static int cups_read_strings(cups_file_t *fp, int flags, cups_array_t *a); @@ -1646,11 +1647,12 @@ cups_cache_lookup( * 'cups_message_compare()' - Compare two messages. */ -static int /* O - Result of comparison */ -cups_message_compare( - _cups_message_t *m1, /* I - First message */ - _cups_message_t *m2) /* I - Second message */ +static int /* O - Result of comparison */ +cups_message_compare(_cups_message_t *m1, /* I - First message */ + _cups_message_t *m2, /* I - Second message */ + void *data) /* Unused */ { + (void)data; return (strcmp(m1->msg, m2->msg)); } @@ -1659,9 +1661,10 @@ cups_message_compare( * 'cups_message_free()' - Free a message. */ -static void -cups_message_free(_cups_message_t *m) /* I - Message */ +static void cups_message_free(_cups_message_t *m, /* I - Message */ + void *data) /* Unused */ { + (void)data; if (m->msg) free(m->msg); diff --git a/cups/libcups2.def b/cups/libcups2.def index 268522259d..d5ec4f1825 100644 --- a/cups/libcups2.def +++ b/cups/libcups2.def @@ -52,6 +52,9 @@ _cupsRasterReadHeader _cupsRasterReadPixels _cupsRasterWriteHeader _cupsRasterWritePixels +_cupsArrayStrcmp +_cupsArrayStrdup +_cupsArrayFree _cupsSetDefaults _cupsSetError _cupsSetHTTPError diff --git a/cups/ppd-cache.c b/cups/ppd-cache.c index 40881cd395..88decc7067 100644 --- a/cups/ppd-cache.c +++ b/cups/ppd-cache.c @@ -34,10 +34,10 @@ static int cups_get_url(http_t **http, const char *url, char *name, size_t names static const char *ppd_inputslot_for_keyword(_ppd_cache_t *pc, const char *keyword); static void pwg_add_finishing(cups_array_t *finishings, ipp_finishings_t template, const char *name, const char *value); static void pwg_add_message(cups_array_t *a, const char *msg, const char *str); -static int pwg_compare_finishings(_pwg_finishings_t *a, _pwg_finishings_t *b); -static int pwg_compare_sizes(cups_size_t *a, cups_size_t *b); -static cups_size_t *pwg_copy_size(cups_size_t *size); -static void pwg_free_finishings(_pwg_finishings_t *f); +static int pwg_compare_finishings(_pwg_finishings_t *a, _pwg_finishings_t *b, void *data); +static int pwg_compare_sizes(cups_size_t *a, cups_size_t *b, void *data); +static cups_size_t *pwg_copy_size(cups_size_t *size, void *data); +static void pwg_free_finishings(_pwg_finishings_t *f, void *data); static void pwg_ppdize_name(const char *ipp, char *name, size_t namesize); static void pwg_ppdize_resolution(ipp_attribute_t *attr, int element, int *xres, int *yres, char *name, size_t namesize); static void pwg_unppdize_name(const char *ppd, char *name, size_t namesize, @@ -598,14 +598,14 @@ _ppdCacheCreateWithFile( else if (!_cups_strcasecmp(line, "Filter")) { if (!pc->filters) - pc->filters = cupsArrayNew3(NULL, NULL, NULL, 0, (cups_acopy_func_t)strdup, (cups_afree_func_t)free); + pc->filters = cupsArrayNew3(NULL, NULL, NULL, 0, (cups_acopy_func_t)_cupsArrayStrdup, _cupsArrayFree); cupsArrayAdd(pc->filters, value); } else if (!_cups_strcasecmp(line, "PreFilter")) { if (!pc->prefilters) - pc->prefilters = cupsArrayNew3(NULL, NULL, NULL, 0, (cups_acopy_func_t)strdup, (cups_afree_func_t)free); + pc->prefilters = cupsArrayNew3(NULL, NULL, NULL, 0, (cups_acopy_func_t)_cupsArrayStrdup, _cupsArrayFree); cupsArrayAdd(pc->prefilters, value); } @@ -957,7 +957,7 @@ _ppdCacheCreateWithFile( else if (!_cups_strcasecmp(line, "FinishingTemplate")) { if (!pc->templates) - pc->templates = cupsArrayNew3((cups_array_func_t)strcmp, NULL, NULL, 0, (cups_acopy_func_t)strdup, (cups_afree_func_t)free); + pc->templates = cupsArrayNew3((cups_array_func_t)_cupsArrayStrcmp, NULL, NULL, 0, (cups_acopy_func_t)_cupsArrayStrdup, _cupsArrayFree); cupsArrayAdd(pc->templates, value); } @@ -981,7 +981,7 @@ _ppdCacheCreateWithFile( else if (!_cups_strcasecmp(line, "SupportFile")) { if (!pc->support_files) - pc->support_files = cupsArrayNew3(NULL, NULL, NULL, 0, (cups_acopy_func_t)strdup, (cups_afree_func_t)free); + pc->support_files = cupsArrayNew3(NULL, NULL, NULL, 0, (cups_acopy_func_t)_cupsArrayStrdup, _cupsArrayFree); cupsArrayAdd(pc->support_files, value); } @@ -1756,7 +1756,7 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd) /* I - PPD file */ * Copy filters and pre-filters... */ - pc->filters = cupsArrayNew3(NULL, NULL, NULL, 0, (cups_acopy_func_t)strdup, (cups_afree_func_t)free); + pc->filters = cupsArrayNew3(NULL, NULL, NULL, 0, (cups_acopy_func_t)_cupsArrayStrdup, _cupsArrayFree); cupsArrayAdd(pc->filters, "application/vnd.cups-raw application/octet-stream 0 -"); @@ -1813,7 +1813,7 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd) /* I - PPD file */ if ((ppd_attr = ppdFindAttr(ppd, "cupsPreFilter", NULL)) != NULL) { - pc->prefilters = cupsArrayNew3(NULL, NULL, NULL, 0, (cups_acopy_func_t)strdup, (cups_afree_func_t)free); + pc->prefilters = cupsArrayNew3(NULL, NULL, NULL, 0, (cups_acopy_func_t)_cupsArrayStrdup, _cupsArrayFree); do { @@ -1970,7 +1970,7 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd) /* I - PPD file */ if ((ppd_option = ppdFindOption(ppd, "cupsFinishingTemplate")) != NULL) { - pc->templates = cupsArrayNew3((cups_array_func_t)strcmp, NULL, NULL, 0, (cups_acopy_func_t)strdup, (cups_afree_func_t)free); + pc->templates = cupsArrayNew3((cups_array_func_t)_cupsArrayStrcmp, NULL, NULL, 0, (cups_acopy_func_t)_cupsArrayStrdup, _cupsArrayFree); for (choice = ppd_option->choices, i = ppd_option->num_choices; i > 0; choice ++, i --) { @@ -2020,7 +2020,7 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd) /* I - PPD file */ * Support files... */ - pc->support_files = cupsArrayNew3(NULL, NULL, NULL, 0, (cups_acopy_func_t)strdup, (cups_afree_func_t)free); + pc->support_files = cupsArrayNew3(NULL, NULL, NULL, 0, (cups_acopy_func_t)_cupsArrayStrdup, _cupsArrayFree); for (ppd_attr = ppdFindAttr(ppd, "cupsICCProfile", NULL); ppd_attr; @@ -2349,6 +2349,7 @@ ppd_inputslot_for_keyword( return (NULL); } + /* * '_ppdCacheGetInputSlot()' - Get the PPD InputSlot associated with the job * attributes or a keyword string. @@ -3539,7 +3540,7 @@ _ppdCreateFromIPP2( else strlcpy(ppdname, "Unknown", sizeof(ppdname)); - sizes = cupsArrayNew3((cups_array_func_t)pwg_compare_sizes, NULL, NULL, 0, (cups_acopy_func_t)pwg_copy_size, (cups_afree_func_t)free); + sizes = cupsArrayNew3((cups_array_func_t)pwg_compare_sizes, NULL, NULL, 0, (cups_acopy_func_t)pwg_copy_size, _cupsArrayFree); if ((attr = ippFindAttribute(supported, "media-col-database", IPP_TAG_BEGIN_COLLECTION)) != NULL) { @@ -4494,8 +4495,8 @@ _ppdCreateFromIPP2( }; count = ippGetCount(attr); - names = cupsArrayNew3((cups_array_func_t)strcmp, NULL, NULL, 0, (cups_acopy_func_t)strdup, (cups_afree_func_t)free); - fin_options = cupsArrayNew((cups_array_func_t)strcmp, NULL); + names = cupsArrayNew3((cups_array_func_t)_cupsArrayStrcmp, NULL, NULL, 0, (cups_acopy_func_t)_cupsArrayStrdup, _cupsArrayFree); + fin_options = cupsArrayNew((cups_array_func_t)_cupsArrayStrcmp, NULL); /* * Staple/Bind/Stitch @@ -4851,7 +4852,7 @@ _ppdCreateFromIPP2( cupsFilePuts(fp, "*cupsFinishingTemplate none: \"\"\n"); cupsFilePrintf(fp, "*%s.cupsFinishingTemplate none/%s: \"\"\n", lang->language, _cupsLangString(lang, _("None"))); - templates = cupsArrayNew((cups_array_func_t)strcmp, NULL); + templates = cupsArrayNew((cups_array_func_t)_cupsArrayStrcmp, NULL); count = ippGetCount(attr); for (i = 0; i < count; i ++) @@ -5371,11 +5372,13 @@ pwg_add_message(cups_array_t *a, /* I - Message catalog */ * 'pwg_compare_finishings()' - Compare two finishings values. */ -static int /* O - Result of comparison */ +static int /* O - Result of comparison */ pwg_compare_finishings( - _pwg_finishings_t *a, /* I - First finishings value */ - _pwg_finishings_t *b) /* I - Second finishings value */ + _pwg_finishings_t *a, /* I - First finishings value */ + _pwg_finishings_t *b, /* I - Second finishings value */ + void *data) /* Unused */ { + (void)data; return ((int)b->value - (int)a->value); } @@ -5384,10 +5387,12 @@ pwg_compare_finishings( * 'pwg_compare_sizes()' - Compare two media sizes... */ -static int /* O - Result of comparison */ -pwg_compare_sizes(cups_size_t *a, /* I - First media size */ - cups_size_t *b) /* I - Second media size */ +static int /* O - Result of comparison */ +pwg_compare_sizes(cups_size_t *a, /* I - First media size */ + cups_size_t *b, /* I - Second media size */ + void *data) /* Unused */ { + (void)data; return (strcmp(a->media, b->media)); } @@ -5396,12 +5401,13 @@ pwg_compare_sizes(cups_size_t *a, /* I - First media size */ * 'pwg_copy_size()' - Copy a media size. */ -static cups_size_t * /* O - New media size */ -pwg_copy_size(cups_size_t *size) /* I - Media size to copy */ +static cups_size_t * /* O - New media size */ +pwg_copy_size(cups_size_t *size, /* I - Media size to copy */ + void *data) /* Unused*/ { - cups_size_t *newsize = (cups_size_t *)calloc(1, sizeof(cups_size_t)); - /* New media size */ - + cups_size_t *newsize = (cups_size_t *)calloc(1, sizeof(cups_size_t)); + /* New media size */ + (void)data; if (newsize) memcpy(newsize, size, sizeof(cups_size_t)); @@ -5414,9 +5420,10 @@ pwg_copy_size(cups_size_t *size) /* I - Media size to copy */ */ static void -pwg_free_finishings( - _pwg_finishings_t *f) /* I - Finishings value */ +pwg_free_finishings(_pwg_finishings_t *f, /* I - Finishings value */ + void *data) /* Unused */ { + (void)data; cupsFreeOptions(f->num_options, f->options); free(f); } diff --git a/cups/ppd-conflicts.c b/cups/ppd-conflicts.c index ffbacadca1..07020ce651 100644 --- a/cups/ppd-conflicts.c +++ b/cups/ppd-conflicts.c @@ -218,7 +218,7 @@ cupsResolveConflicts( cupsArraySave(ppd->sorted_attrs); resolvers = NULL; - pass = cupsArrayNew((cups_array_func_t)_cups_strcasecmp, NULL); + pass = cupsArrayNew((cups_array_func_t)_cupsArrayStrcasecmp, NULL); tries = 0; while (tries < 100 && @@ -228,7 +228,7 @@ cupsResolveConflicts( tries ++; if (!resolvers) - resolvers = cupsArrayNew((cups_array_func_t)_cups_strcasecmp, NULL); + resolvers = cupsArrayNew((cups_array_func_t)_cupsArrayStrcasecmp, NULL); for (consts = (_ppd_cups_uiconsts_t *)cupsArrayFirst(active), changed = 0; consts; diff --git a/cups/ppd-emit.c b/cups/ppd-emit.c index 74908d451c..88de0ae8b0 100644 --- a/cups/ppd-emit.c +++ b/cups/ppd-emit.c @@ -28,7 +28,7 @@ * Local functions... */ -static int ppd_compare_cparams(ppd_cparam_t *a, ppd_cparam_t *b); +static int ppd_compare_cparams(ppd_cparam_t *a, ppd_cparam_t *b, void *data); static void ppd_handle_media(ppd_file_t *ppd); @@ -1105,10 +1105,12 @@ ppdEmitString(ppd_file_t *ppd, /* I - PPD file record */ * 'ppd_compare_cparams()' - Compare the order of two custom parameters. */ -static int /* O - Result of comparison */ -ppd_compare_cparams(ppd_cparam_t *a, /* I - First parameter */ - ppd_cparam_t *b) /* I - Second parameter */ +static int /* O - Result of comparison */ +ppd_compare_cparams(ppd_cparam_t *a, /* I - First parameter */ + ppd_cparam_t *b, /* I - Second parameter */ + void *data) /* Unused */ { + (void)data; return (a->order - b->order); } diff --git a/cups/ppd-localize.c b/cups/ppd-localize.c index ea8491532a..45dcdfc0cb 100644 --- a/cups/ppd-localize.c +++ b/cups/ppd-localize.c @@ -511,7 +511,8 @@ _ppdGetLanguages(ppd_file_t *ppd) /* I - PPD file */ * Yes, load the list... */ - if ((languages = cupsArrayNew((cups_array_func_t)strcmp, NULL)) == NULL) + if ((languages = cupsArrayNew((cups_array_func_t)_cupsArrayStrcmp, NULL)) == + NULL) return (NULL); if ((value = strdup(attr->value)) == NULL) diff --git a/cups/ppd.c b/cups/ppd.c index 4ce9fcc5cd..92d91aa8e2 100644 --- a/cups/ppd.c +++ b/cups/ppd.c @@ -64,22 +64,20 @@ static ppd_attr_t *ppd_add_attr(ppd_file_t *ppd, const char *name, const char *value); static ppd_choice_t *ppd_add_choice(ppd_option_t *option, const char *name); static ppd_size_t *ppd_add_size(ppd_file_t *ppd, const char *name); -static int ppd_compare_attrs(ppd_attr_t *a, ppd_attr_t *b); -static int ppd_compare_choices(ppd_choice_t *a, ppd_choice_t *b); -static int ppd_compare_coptions(ppd_coption_t *a, - ppd_coption_t *b); -static int ppd_compare_options(ppd_option_t *a, ppd_option_t *b); +static int ppd_compare_attrs(ppd_attr_t *a, ppd_attr_t *b, void *data); +static int ppd_compare_choices(ppd_choice_t *a, ppd_choice_t *b, void *data); +static int ppd_compare_coptions(ppd_coption_t *a, ppd_coption_t *b, void *data); +static int ppd_compare_options(ppd_option_t *a, ppd_option_t *b, void *data); static int ppd_decode(char *string); static void ppd_free_filters(ppd_file_t *ppd); static void ppd_free_group(ppd_group_t *group); static void ppd_free_option(ppd_option_t *option); static ppd_coption_t *ppd_get_coption(ppd_file_t *ppd, const char *name); -static ppd_cparam_t *ppd_get_cparam(ppd_coption_t *opt, - const char *param, - const char *text); -static ppd_group_t *ppd_get_group(ppd_file_t *ppd, const char *name, - const char *text, _ppd_globals_t *pg, - cups_encoding_t encoding); +static ppd_cparam_t *ppd_get_cparam(ppd_coption_t *opt, const char *param, + const char *text); +static ppd_group_t *ppd_get_group(ppd_file_t *ppd, const char *name, + const char *text, _ppd_globals_t *pg, + cups_encoding_t encoding); static ppd_option_t *ppd_get_option(ppd_group_t *group, const char *name); static _ppd_globals_t *ppd_globals_alloc(void); #if defined(HAVE_PTHREAD_H) || defined(_WIN32) @@ -88,13 +86,13 @@ static void ppd_globals_free(_ppd_globals_t *g); #ifdef HAVE_PTHREAD_H static void ppd_globals_init(void); #endif /* HAVE_PTHREAD_H */ -static int ppd_hash_option(ppd_option_t *option); +static int ppd_hash_option(ppd_option_t *option, void *data); static int ppd_read(cups_file_t *fp, _ppd_line_t *line, - char *keyword, char *option, char *text, - char **string, int ignoreblank, - _ppd_globals_t *pg); + char *keyword, char *option, char *text, + char **string, int ignoreblank, + _ppd_globals_t *pg); static int ppd_update_filters(ppd_file_t *ppd, - _ppd_globals_t *pg); + _ppd_globals_t *pg); /* @@ -2484,10 +2482,12 @@ ppd_add_size(ppd_file_t *ppd, /* I - PPD file */ * 'ppd_compare_attrs()' - Compare two attributes. */ -static int /* O - Result of comparison */ -ppd_compare_attrs(ppd_attr_t *a, /* I - First attribute */ - ppd_attr_t *b) /* I - Second attribute */ +static int /* O - Result of comparison */ +ppd_compare_attrs(ppd_attr_t *a, /* I - First attribute */ + ppd_attr_t *b, /* I - Second attribute */ + void *data) /* Unused */ { + (void)data; return (_cups_strcasecmp(a->name, b->name)); } @@ -2496,10 +2496,12 @@ ppd_compare_attrs(ppd_attr_t *a, /* I - First attribute */ * 'ppd_compare_choices()' - Compare two choices... */ -static int /* O - Result of comparison */ -ppd_compare_choices(ppd_choice_t *a, /* I - First choice */ - ppd_choice_t *b) /* I - Second choice */ +static int /* O - Result of comparison */ +ppd_compare_choices(ppd_choice_t *a, /* I - First choice */ + ppd_choice_t *b, /* I - Second choice */ + void *data) /* Unused */ { + (void)data; return (strcmp(a->option->keyword, b->option->keyword)); } @@ -2508,10 +2510,12 @@ ppd_compare_choices(ppd_choice_t *a, /* I - First choice */ * 'ppd_compare_coptions()' - Compare two custom options. */ -static int /* O - Result of comparison */ -ppd_compare_coptions(ppd_coption_t *a, /* I - First option */ - ppd_coption_t *b) /* I - Second option */ +static int /* O - Result of comparison */ +ppd_compare_coptions(ppd_coption_t *a, /* I - First option */ + ppd_coption_t *b, /* I - Second option */ + void *data) /* Unused */ { + (void)data; return (_cups_strcasecmp(a->keyword, b->keyword)); } @@ -2520,10 +2524,12 @@ ppd_compare_coptions(ppd_coption_t *a, /* I - First option */ * 'ppd_compare_options()' - Compare two options. */ -static int /* O - Result of comparison */ -ppd_compare_options(ppd_option_t *a, /* I - First option */ - ppd_option_t *b) /* I - Second option */ +static int /* O - Result of comparison */ +ppd_compare_options(ppd_option_t *a, /* I - First option */ + ppd_option_t *b, /* I - Second option */ + void *data) /* Unused */ { + (void)data; return (_cups_strcasecmp(a->keyword, b->keyword)); } @@ -2897,12 +2903,13 @@ ppd_globals_init(void) * 'ppd_hash_option()' - Generate a hash of the option name... */ -static int /* O - Hash index */ -ppd_hash_option(ppd_option_t *option) /* I - Option */ -{ +static int /* O - Hash index */ +ppd_hash_option(ppd_option_t *option, /* I - Option */ + void *data) { int hash = 0; /* Hash index */ const char *k; /* Pointer into keyword */ + (void)data; for (hash = option->keyword[0], k = option->keyword + 1; *k;) hash = (int)(33U * (unsigned)hash) + *k++; diff --git a/cups/pwg-media.c b/cups/pwg-media.c index 3653739703..a56c058e38 100644 --- a/cups/pwg-media.c +++ b/cups/pwg-media.c @@ -30,9 +30,9 @@ * Local functions... */ -static int pwg_compare_legacy(pwg_media_t *a, pwg_media_t *b); -static int pwg_compare_pwg(pwg_media_t *a, pwg_media_t *b); -static int pwg_compare_ppd(pwg_media_t *a, pwg_media_t *b); +static int pwg_compare_legacy(pwg_media_t *a, pwg_media_t *b, void *data); +static int pwg_compare_pwg(pwg_media_t *a, pwg_media_t *b, void *data); +static int pwg_compare_ppd(pwg_media_t *a, pwg_media_t *b, void *data); static char *pwg_format_inches(char *buf, size_t bufsize, int val); static char *pwg_format_millimeters(char *buf, size_t bufsize, int val); static int pwg_scan_measurement(const char *buf, char **bufptr, int numer, int denom); @@ -1058,10 +1058,12 @@ _pwgMediaTable(size_t *num_media) /* O - Number of entries */ * 'pwg_compare_legacy()' - Compare two sizes using the legacy names. */ -static int /* O - Result of comparison */ -pwg_compare_legacy(pwg_media_t *a, /* I - First size */ - pwg_media_t *b) /* I - Second size */ +static int /* O - Result of comparison */ +pwg_compare_legacy(pwg_media_t *a, /* I - First size */ + pwg_media_t *b, /* I - Second size */ + void *data) /* Unused */ { + (void)data; return (strcmp(a->legacy, b->legacy)); } @@ -1070,10 +1072,12 @@ pwg_compare_legacy(pwg_media_t *a, /* I - First size */ * 'pwg_compare_ppd()' - Compare two sizes using the PPD names. */ -static int /* O - Result of comparison */ -pwg_compare_ppd(pwg_media_t *a, /* I - First size */ - pwg_media_t *b) /* I - Second size */ +static int /* O - Result of comparison */ +pwg_compare_ppd(pwg_media_t *a, /* I - First size */ + pwg_media_t *b, /* I - Second size */ + void *data) /* Unused */ { + (void)data; return (strcmp(a->ppd, b->ppd)); } @@ -1082,10 +1086,12 @@ pwg_compare_ppd(pwg_media_t *a, /* I - First size */ * 'pwg_compare_pwg()' - Compare two sizes using the PWG names. */ -static int /* O - Result of comparison */ -pwg_compare_pwg(pwg_media_t *a, /* I - First size */ - pwg_media_t *b) /* I - Second size */ +static int /* O - Result of comparison */ +pwg_compare_pwg(pwg_media_t *a, /* I - First size */ + pwg_media_t *b, /* I - Second size */ + void *data) /* Unused */ { + (void)data; return (strcmp(a->pwg, b->pwg)); } diff --git a/cups/string-private.h b/cups/string-private.h index 335e579c86..df5873c8ca 100644 --- a/cups/string-private.h +++ b/cups/string-private.h @@ -180,6 +180,8 @@ extern void _cupsStrFree(const char *s) _CUPS_PRIVATE; extern char *_cupsStrRetain(const char *s) _CUPS_PRIVATE; extern size_t _cupsStrStatistics(size_t *alloc_bytes, size_t *total_bytes) _CUPS_PRIVATE; +extern char *_cupsStrPrivAlloc(const char *s, void *data) _CUPS_PRIVATE; +extern void _cupsStrPrivFree(const char *s, void *data) _CUPS_PRIVATE; /* * Floating point number functions... @@ -197,6 +199,13 @@ extern double _cupsStrScand(const char *buf, char **bufptr, extern char *_cupsStrDate(char *buf, size_t bufsize, time_t timeval) _CUPS_PRIVATE; +extern int _cupsArrayStrcmp(const char *s1, const char *s2, void *data) _CUPS_PRIVATE; + +extern int _cupsArrayStrcasecmp(const char *s, const char *t, void *data) _CUPS_PRIVATE; + +extern char *_cupsArrayStrdup(const char *element, void *data) _CUPS_PRIVATE; + +extern void _cupsArrayFree(void *element, void *data) _CUPS_PRIVATE; /* * C++ magic... diff --git a/cups/string.c b/cups/string.c index b4fc12050c..770616cf52 100644 --- a/cups/string.c +++ b/cups/string.c @@ -34,8 +34,7 @@ static cups_array_t *stringpool = NULL; * Local functions... */ -static int compare_sp_items(_cups_sp_item_t *a, _cups_sp_item_t *b); - +static int compare_sp_items(_cups_sp_item_t *a, _cups_sp_item_t *b, void *data); /* * '_cupsStrAlloc()' - Allocate/reference a string. @@ -136,6 +135,32 @@ _cupsStrAlloc(const char *s) /* I - String */ } +/* + * '_cupsStrPrivAlloc()' - Allocate/reference a string. + */ + +char * /* O - String pointer */ +_cupsStrPrivAlloc(const char *s, /* I - String */ + void *data) /* Unused */ +{ + (void)data; + return _cupsStrAlloc(s); +} + + +/* + * '_cupsStrPrivFree()' - Free a string. + */ + +void /* O - String pointer */ +_cupsStrPrivFree(const char *s, /* I - String */ + void *data) /* Unused */ +{ + (void)data; + _cupsStrFree(s); +} + + /* * '_cupsStrDate()' - Return a localized date for a given time value. * @@ -621,11 +646,15 @@ int /* O - Result of comparison (-1, 0, or 1) */ _cups_strcasecmp(const char *s, /* I - First string */ const char *t) /* I - Second string */ { + char u, v; while (*s != '\0' && *t != '\0') { - if (_cups_tolower(*s) < _cups_tolower(*t)) + u = _cups_tolower(*s); + v = _cups_tolower(*t); + + if (u < v) return (-1); - else if (_cups_tolower(*s) > _cups_tolower(*t)) + else if (u > v) return (1); s ++; @@ -640,6 +669,7 @@ _cups_strcasecmp(const char *s, /* I - First string */ return (-1); } + /* * '_cups_strncasecmp()' - Do a case-insensitive comparison on up to N chars. */ @@ -649,11 +679,14 @@ _cups_strncasecmp(const char *s, /* I - First string */ const char *t, /* I - Second string */ size_t n) /* I - Maximum number of characters to compare */ { + char u, v; while (*s != '\0' && *t != '\0' && n > 0) { - if (_cups_tolower(*s) < _cups_tolower(*t)) + u = _cups_tolower(*s); + v = _cups_tolower(*t); + if (u < v) return (-1); - else if (_cups_tolower(*s) > _cups_tolower(*t)) + else if (u > v) return (1); s ++; @@ -761,9 +794,24 @@ _cups_strlcpy(char *dst, /* O - Destination string */ * 'compare_sp_items()' - Compare two string pool items... */ -static int /* O - Result of comparison */ -compare_sp_items(_cups_sp_item_t *a, /* I - First item */ - _cups_sp_item_t *b) /* I - Second item */ +static int /* O - Result of comparison */ +compare_sp_items(_cups_sp_item_t *a, /* I - First item */ + _cups_sp_item_t *b, /* I - Second item */ + void *data) /* Unused */ { + (void)data; return (strcmp(a->str, b->str)); } + + +/* + * '_cupsArrayStrcasecmp()' - Compare two strings... + */ + +int _cupsArrayStrcasecmp(const char *s, /* I - First string */ + const char *t, /* I - Second string */ + void *data) /* Unused */ +{ + (void)data; + return _cups_strcasecmp(s, t); +} diff --git a/cups/testarray.c b/cups/testarray.c index 185fcbec57..a224fce85e 100644 --- a/cups/testarray.c +++ b/cups/testarray.c @@ -59,7 +59,7 @@ main(void) fputs("cupsArrayNew: ", stdout); data = (void *)"testarray"; - array = cupsArrayNew((cups_array_func_t)strcmp, data); + array = cupsArrayNew((cups_array_func_t)_cupsArrayStrcmp, data); if (array) puts("PASS"); diff --git a/notifier/rss.c b/notifier/rss.c index 5c652fdb90..153dc7b67f 100644 --- a/notifier/rss.c +++ b/notifier/rss.c @@ -45,7 +45,7 @@ static char *rss_password; /* Password for remote RSS */ * Local functions... */ -static int compare_rss(_cups_rss_t *a, _cups_rss_t *b); +static int compare_rss(_cups_rss_t *a, _cups_rss_t *b, void *data); static void delete_message(_cups_rss_t *msg); static void load_rss(cups_array_t *rss, const char *filename); static _cups_rss_t *new_message(int sequence_number, char *subject, @@ -397,10 +397,12 @@ main(int argc, /* I - Number of command-line arguments */ * 'compare_rss()' - Compare two messages. */ -static int /* O - Result of comparison */ -compare_rss(_cups_rss_t *a, /* I - First message */ - _cups_rss_t *b) /* I - Second message */ +static int /* O - Result of comparison */ +compare_rss(_cups_rss_t *a, /* I - First message */ + _cups_rss_t *b, /* I - Second message */ + void *data) /* Unused */ { + (void)data; return (a->sequence_number - b->sequence_number); } diff --git a/ppdc/ppdc.cxx b/ppdc/ppdc.cxx index 385f456413..213b0a23d8 100644 --- a/ppdc/ppdc.cxx +++ b/ppdc/ppdc.cxx @@ -69,7 +69,7 @@ main(int argc, // I - Number of command-line arguments src = new ppdcSource(); use_model_name = 0; verbose = 0; - filenames = cupsArrayNew((cups_array_func_t)_cups_strcasecmp, NULL); + filenames = cupsArrayNew((cups_array_func_t)_cupsArrayStrcasecmp, NULL); for (i = 1; i < argc; i ++) if (argv[i][0] == '-') diff --git a/ppdc/ppdmerge.cxx b/ppdc/ppdmerge.cxx index cd83964fae..3edd99f4ea 100644 --- a/ppdc/ppdmerge.cxx +++ b/ppdc/ppdmerge.cxx @@ -174,7 +174,7 @@ main(int argc, // I - Number of command-line arguments // Loop through the PPD files we loaded to generate a new language list... if (!languages) - languages = cupsArrayNew((cups_array_func_t)strcmp, NULL); + languages = cupsArrayNew((cups_array_func_t)_cupsArrayStrcmp, NULL); for (ppd = (ppd_file_t *)cupsArrayFirst(ppds); ppd; diff --git a/scheduler/auth.c b/scheduler/auth.c index 7f6c3f6d2f..5de91b34dd 100644 --- a/scheduler/auth.c +++ b/scheduler/auth.c @@ -70,7 +70,8 @@ static int check_admin_access(cupsd_client_t *con); static int check_authref(cupsd_client_t *con, const char *right); #endif /* HAVE_AUTHORIZATION_H */ static int compare_locations(cupsd_location_t *a, - cupsd_location_t *b); + cupsd_location_t *b, + void *data); static cupsd_authmask_t *copy_authmask(cupsd_authmask_t *am, void *data); static void free_authmask(cupsd_authmask_t *am, void *data); #if HAVE_LIBPAM @@ -162,8 +163,8 @@ cupsdAddName(cupsd_location_t *loc, /* I - Location to add to */ if (!loc->names) loc->names = cupsArrayNew3(NULL, NULL, NULL, 0, - (cups_acopy_func_t)_cupsStrAlloc, - (cups_afree_func_t)_cupsStrFree); + (cups_acopy_func_t)_cupsStrPrivAlloc, + (cups_afree_func_t)_cupsStrPrivFree); if (!cupsArrayAdd(loc->names, name)) { @@ -1310,7 +1311,7 @@ cupsdCopyLocation( "Unable to allocate memory for %d names: %s", cupsArrayCount(loc->names), strerror(errno)); - cupsdFreeLocation(temp); + cupsdFreeLocation(temp, NULL); return (NULL); } } @@ -1326,7 +1327,7 @@ cupsdCopyLocation( cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to allocate memory for %d allow rules: %s", cupsArrayCount(loc->allow), strerror(errno)); - cupsdFreeLocation(temp); + cupsdFreeLocation(temp, NULL); return (NULL); } } @@ -1342,7 +1343,7 @@ cupsdCopyLocation( cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to allocate memory for %d deny rules: %s", cupsArrayCount(loc->deny), strerror(errno)); - cupsdFreeLocation(temp); + cupsdFreeLocation(temp, NULL); return (NULL); } } @@ -1509,9 +1510,10 @@ cupsdFindLocation(const char *location) /* I - Connection */ * 'cupsdFreeLocation()' - Free all memory used by a location. */ -void -cupsdFreeLocation(cupsd_location_t *loc)/* I - Location to free */ +void cupsdFreeLocation(cupsd_location_t *loc, /* I - Location to free */ + void *data) /* Unused */ { + (void)data; cupsArrayDelete(loc->names); cupsArrayDelete(loc->allow); cupsArrayDelete(loc->deny); @@ -2199,10 +2201,12 @@ check_authref(cupsd_client_t *con, /* I - Connection */ * 'compare_locations()' - Compare two locations. */ -static int /* O - Result of comparison */ -compare_locations(cupsd_location_t *a, /* I - First location */ - cupsd_location_t *b) /* I - Second location */ +static int /* O - Result of comparison */ +compare_locations(cupsd_location_t *a, /* I - First location */ + cupsd_location_t *b, /* I - Second location */ + void *data) /* Unused */ { + (void)data; return (strcmp(b->location, a->location)); } diff --git a/scheduler/auth.h b/scheduler/auth.h index 14885b0283..01c55aa2c4 100644 --- a/scheduler/auth.h +++ b/scheduler/auth.h @@ -133,6 +133,6 @@ extern cupsd_location_t *cupsdCopyLocation(cupsd_location_t *loc); extern void cupsdDeleteAllLocations(void); extern cupsd_location_t *cupsdFindBest(const char *path, http_state_t state); extern cupsd_location_t *cupsdFindLocation(const char *location); -extern void cupsdFreeLocation(cupsd_location_t *loc); +extern void cupsdFreeLocation(cupsd_location_t *loc, void *data); extern http_status_t cupsdIsAuthorized(cupsd_client_t *con, const char *owner); extern cupsd_location_t *cupsdNewLocation(const char *location); diff --git a/scheduler/banners.c b/scheduler/banners.c index e939923020..ed4078bc0b 100644 --- a/scheduler/banners.c +++ b/scheduler/banners.c @@ -21,7 +21,8 @@ static void add_banner(const char *name, const char *filename); static int compare_banners(const cupsd_banner_t *b0, - const cupsd_banner_t *b1); + const cupsd_banner_t *b1, + void *data); static void free_banners(void); @@ -173,11 +174,12 @@ add_banner(const char *name, /* I - Name of banner */ * 'compare_banners()' - Compare two banners. */ -static int /* O - -1 if name0 < name1, etc. */ -compare_banners( - const cupsd_banner_t *b0, /* I - First banner */ - const cupsd_banner_t *b1) /* I - Second banner */ +static int /* O - -1 if name0 < name1, etc. */ +compare_banners(const cupsd_banner_t *b0, /* I - First banner */ + const cupsd_banner_t *b1, /* I - Second banner */ + void *data) /* Unused */ { + (void)data; return (_cups_strcasecmp(b0->name, b1->name)); } diff --git a/scheduler/client.c b/scheduler/client.c index 91e441188c..90731441dc 100644 --- a/scheduler/client.c +++ b/scheduler/client.c @@ -35,22 +35,22 @@ static int check_if_modified(cupsd_client_t *con, struct stat *filestats); static int compare_clients(cupsd_client_t *a, cupsd_client_t *b, - void *data); + void *data); #ifdef HAVE_TLS static int cupsd_start_tls(cupsd_client_t *con, http_encryption_t e); #endif /* HAVE_TLS */ static char *get_file(cupsd_client_t *con, struct stat *filestats, - char *filename, size_t len); + char *filename, size_t len); static http_status_t install_cupsd_conf(cupsd_client_t *con); static int is_cgi(cupsd_client_t *con, const char *filename, - struct stat *filestats, mime_type_t *type); + struct stat *filestats, mime_type_t *type); static int is_path_absolute(const char *path); static int pipe_command(cupsd_client_t *con, int infile, int *outfile, - char *command, char *options, int root); + char *command, char *options, int root); static int valid_host(cupsd_client_t *con); static int write_file(cupsd_client_t *con, http_status_t code, - char *filename, char *type, - struct stat *filestats); + char *filename, char *type, + struct stat *filestats); static void write_pipe(cupsd_client_t *con); @@ -2641,10 +2641,10 @@ check_if_modified( * 'compare_clients()' - Compare two client connections. */ -static int /* O - Result of comparison */ -compare_clients(cupsd_client_t *a, /* I - First client */ - cupsd_client_t *b, /* I - Second client */ - void *data) /* I - User data (not used) */ +static int /* O - Result of comparison */ +compare_clients(cupsd_client_t *a, /* I - First client */ + cupsd_client_t *b, /* I - Second client */ + void *data) /* I - User data (not used) */ { (void)data; diff --git a/scheduler/colorman.c b/scheduler/colorman.c index 809ed7c65d..c025dbcfd4 100644 --- a/scheduler/colorman.c +++ b/scheduler/colorman.c @@ -1398,8 +1398,8 @@ colord_register_printer( * See if we have any embedded profiles... */ - profiles = cupsArrayNew3(NULL, NULL, NULL, 0, (cups_acopy_func_t)strdup, - (cups_afree_func_t)free); + profiles = cupsArrayNew3(NULL, NULL, NULL, 0, (cups_acopy_func_t)_cupsArrayStrdup, + _cupsArrayFree); for (attr = ppdFindAttr(ppd, "cupsICCProfile", NULL); attr; attr = ppdFindNextAttr(ppd, "cupsICCProfile", NULL)) diff --git a/scheduler/cups-driverd.cxx b/scheduler/cups-driverd.cxx index ef45e92671..28eea0da93 100644 --- a/scheduler/cups-driverd.cxx +++ b/scheduler/cups-driverd.cxx @@ -155,13 +155,16 @@ static int cat_drv(const char *name, int request_id); static void cat_ppd(const char *name, int request_id) _CUPS_NORETURN; static int cat_static(const char *name, int request_id); static int cat_tar(const char *name, int request_id); -static int compare_inodes(struct stat *a, struct stat *b); -static int compare_matches(const ppd_info_t *p0, - const ppd_info_t *p1); -static int compare_names(const ppd_info_t *p0, - const ppd_info_t *p1); -static int compare_ppds(const ppd_info_t *p0, - const ppd_info_t *p1); +static int compare_inodes(struct stat *a, struct stat *b, void *data); +static int compare_matches(const ppd_info_t *p0, + const ppd_info_t *p1, + void *data); +static int compare_names(const ppd_info_t *p0, + const ppd_info_t *p1, + void *data); +static int compare_ppds(const ppd_info_t *p0, + const ppd_info_t *p1, + void *data); static void dump_ppds_dat(const char *filename) _CUPS_NORETURN; static void free_array(cups_array_t *a); static cups_file_t *get_file(const char *name, int request_id, @@ -701,10 +704,13 @@ cat_tar(const char *name, /* I - PPD name */ * 'compare_inodes()' - Compare two inodes. */ -static int /* O - Result of comparison */ -compare_inodes(struct stat *a, /* I - First inode */ - struct stat *b) /* I - Second inode */ +static int /* O - Result of comparison */ +compare_inodes(struct stat *a, /* I - First inode */ + struct stat *b, /* I - Second inode */ + void *data) /* Unused */ { + (void)data; + if (a->st_dev != b->st_dev) return (a->st_dev - b->st_dev); else @@ -716,10 +722,12 @@ compare_inodes(struct stat *a, /* I - First inode */ * 'compare_matches()' - Compare PPD match scores for sorting. */ -static int -compare_matches(const ppd_info_t *p0, /* I - First PPD */ - const ppd_info_t *p1) /* I - Second PPD */ +static int compare_matches(const ppd_info_t *p0, /* I - First PPD */ + const ppd_info_t *p1, /* I - Second PPD */ + void *data) /* Unused */ { + (void)data; + if (p1->matches != p0->matches) return (p1->matches - p0->matches); else @@ -732,12 +740,14 @@ compare_matches(const ppd_info_t *p0, /* I - First PPD */ * 'compare_names()' - Compare PPD filenames for sorting. */ -static int /* O - Result of comparison */ -compare_names(const ppd_info_t *p0, /* I - First PPD file */ - const ppd_info_t *p1) /* I - Second PPD file */ +static int /* O - Result of comparison */ +compare_names(const ppd_info_t *p0, /* I - First PPD file */ + const ppd_info_t *p1, /* I - Second PPD file */ + void *data) /* Unused */ { int diff; /* Difference between strings */ + (void)data; if ((diff = strcmp(p0->record.filename, p1->record.filename)) != 0) return (diff); @@ -750,9 +760,10 @@ compare_names(const ppd_info_t *p0, /* I - First PPD file */ * 'compare_ppds()' - Compare PPD file make and model names for sorting. */ -static int /* O - Result of comparison */ -compare_ppds(const ppd_info_t *p0, /* I - First PPD file */ - const ppd_info_t *p1) /* I - Second PPD file */ +static int /* O - Result of comparison */ +compare_ppds(const ppd_info_t *p0, /* I - First PPD file */ + const ppd_info_t *p1, /* I - Second PPD file */ + void *data) /* Unused */ { int diff; /* Difference between strings */ @@ -761,6 +772,8 @@ compare_ppds(const ppd_info_t *p0, /* I - First PPD file */ * First compare manufacturers... */ + (void)data; + if ((diff = _cups_strcasecmp(p0->record.make, p1->record.make)) != 0) return (diff); else if ((diff = cupsdCompareNames(p0->record.make_and_model, @@ -770,7 +783,7 @@ compare_ppds(const ppd_info_t *p0, /* I - First PPD file */ p1->record.languages[0])) != 0) return (diff); else - return (compare_names(p0, p1)); + return (compare_names(p0, p1, NULL)); } diff --git a/scheduler/cupsd.h b/scheduler/cupsd.h index bc1350e7e7..58a3512839 100644 --- a/scheduler/cupsd.h +++ b/scheduler/cupsd.h @@ -220,3 +220,7 @@ extern void cupsdStopSelect(void); /* server.c */ extern void cupsdStartServer(void); extern void cupsdStopServer(void); + +extern int _cupsArrayStrcmp(const char *s1, const char *s2, void *data); +extern char *_cupsArrayStrdup(const char *element, void *data); +extern void _cupsArrayFree(void *element, void *data); diff --git a/scheduler/cupsfilter.c b/scheduler/cupsfilter.c index dc9ba898a1..2e28c96429 100644 --- a/scheduler/cupsfilter.c +++ b/scheduler/cupsfilter.c @@ -60,7 +60,7 @@ static mime_type_t *add_printer_filters(const char *command, mime_type_t **prefilter_type); static void check_cb(void *context, _cups_fc_result_t result, const char *message); -static int compare_pids(mime_filter_t *a, mime_filter_t *b); +static int compare_pids(mime_filter_t *a, mime_filter_t *b, void *data); static char *escape_options(int num_options, cups_option_t *options); static int exec_filter(const char *filter, char **argv, char **envp, int infd, int outfd); @@ -769,14 +769,17 @@ check_cb(void *context, /* I - Context (command name) */ * 'compare_pids()' - Compare two filter PIDs... */ -static int /* O - Result of comparison */ -compare_pids(mime_filter_t *a, /* I - First filter */ - mime_filter_t *b) /* I - Second filter */ +static int /* O - Result of comparison */ +compare_pids(mime_filter_t *a, /* I - First filter */ + mime_filter_t *b, /* I - Second filter */ + void *data) /* Unused */ { - /* - * Because we're particularly lazy, we store the process ID in the "cost" - * variable... - */ + /* + * Because we're particularly lazy, we store the process ID in the "cost" + * variable... + */ + + (void)data; return (a->cost - b->cost); } diff --git a/scheduler/filter.c b/scheduler/filter.c index 5596d623cc..aa96f13132 100644 --- a/scheduler/filter.c +++ b/scheduler/filter.c @@ -38,8 +38,8 @@ typedef struct _mime_typelist_s /**** List of source types ****/ * Local functions... */ -static int mime_compare_filters(mime_filter_t *, mime_filter_t *); -static int mime_compare_srcs(mime_filter_t *, mime_filter_t *); +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 cups_array_t *mime_find_filters(mime_t *mime, mime_type_t *src, size_t srcsize, mime_type_t *dst, int *cost, _mime_typelist_t *visited); @@ -258,12 +258,14 @@ mimeFilterLookup(mime_t *mime, /* I - MIME database */ * 'mime_compare_filters()' - Compare two filters. */ -static int /* O - Comparison result */ -mime_compare_filters(mime_filter_t *f0, /* I - First filter */ - mime_filter_t *f1) /* I - Second filter */ +static int /* O - Comparison result */ +mime_compare_filters(mime_filter_t *f0, /* I - First filter */ + mime_filter_t *f1, /* I - Second filter */ + void *data) /* Unused */ { int i; /* Result of comparison */ + (void)data; if ((i = strcmp(f0->src->super, f1->src->super)) == 0) if ((i = strcmp(f0->src->type, f1->src->type)) == 0) @@ -278,13 +280,13 @@ mime_compare_filters(mime_filter_t *f0, /* I - First filter */ * 'mime_compare_srcs()' - Compare two filter source types. */ -static int /* O - Comparison result */ -mime_compare_srcs(mime_filter_t *f0, /* I - First filter */ - mime_filter_t *f1) /* I - Second filter */ -{ +static int /* O - Comparison result */ +mime_compare_srcs(mime_filter_t *f0, /* I - First filter */ + mime_filter_t *f1, /* I - Second filter */ + void *data) { int i; /* Result of comparison */ - + (void)data; if ((i = strcmp(f0->src->super, f1->src->super)) == 0) i = strcmp(f0->src->type, f1->src->type); diff --git a/scheduler/job.c b/scheduler/job.c index 5ac782e759..71cb2b34a0 100644 --- a/scheduler/job.c +++ b/scheduler/job.c @@ -2898,10 +2898,10 @@ cupsdUpdateJobs(void) * 'compare_active_jobs()' - Compare the job IDs and priorities of two jobs. */ -static int /* O - Difference */ -compare_active_jobs(void *first, /* I - First job */ - void *second, /* I - Second job */ - void *data) /* I - App data (not used) */ +static int /* O - Difference */ +compare_active_jobs(void *first, /* I - First job */ + void *second, /* I - Second job */ + void *data) /* I - App data (not used) */ { int diff; /* Difference */ @@ -2920,10 +2920,10 @@ compare_active_jobs(void *first, /* I - First job */ * 'compare_completed_jobs()' - Compare the job IDs and completion times of two jobs. */ -static int /* O - Difference */ -compare_completed_jobs(void *first, /* I - First job */ - void *second, /* I - Second job */ - void *data) /* I - App data (not used) */ +static int /* O - Difference */ +compare_completed_jobs(void *first, /* I - First job */ + void *second, /* I - Second job */ + void *data) /* I - App data (not used) */ { int diff; /* Difference */ @@ -2942,10 +2942,10 @@ compare_completed_jobs(void *first, /* I - First job */ * 'compare_jobs()' - Compare the job IDs of two jobs. */ -static int /* O - Difference */ -compare_jobs(void *first, /* I - First job */ - void *second, /* I - Second job */ - void *data) /* I - App data (not used) */ +static int /* O - Difference */ +compare_jobs(void *first, /* I - First job */ + void *second, /* I - Second job */ + void *data) /* I - App data (not used) */ { (void)data; diff --git a/scheduler/main.c b/scheduler/main.c index d971d4ffe8..3fae37c431 100644 --- a/scheduler/main.c +++ b/scheduler/main.c @@ -1216,10 +1216,10 @@ cupsdAddString(cups_array_t **a, /* IO - String array */ const char *s) /* I - String to copy and add */ { if (!*a) - *a = cupsArrayNew3((cups_array_func_t)strcmp, NULL, + *a = cupsArrayNew3((cups_array_func_t)_cupsArrayStrcmp, NULL, (cups_ahash_func_t)NULL, 0, - (cups_acopy_func_t)strdup, - (cups_afree_func_t)free); + (cups_acopy_func_t)_cupsArrayStrdup, + _cupsArrayFree); return (cupsArrayAdd(*a, (char *)s)); } diff --git a/scheduler/mime.c b/scheduler/mime.c index d60d4efb95..9fe90bd6a4 100644 --- a/scheduler/mime.c +++ b/scheduler/mime.c @@ -41,7 +41,7 @@ typedef struct _mime_fcache_s /**** Filter cache structure ****/ static const char *mime_add_fcache(cups_array_t *filtercache, const char *name, const char *filterpath); -static int mime_compare_fcache(_mime_fcache_t *a, _mime_fcache_t *b); +static int mime_compare_fcache(_mime_fcache_t *a, _mime_fcache_t *b, void *data); static void mime_delete_fcache(cups_array_t *filtercache); static void mime_delete_rules(mime_magic_t *rules); static void mime_load_convs(mime_t *mime, const char *filename, @@ -576,10 +576,12 @@ mime_add_fcache( * 'mime_compare_fcache()' - Compare two filter cache entries. */ -static int /* O - Result of comparison */ -mime_compare_fcache(_mime_fcache_t *a, /* I - First entry */ - _mime_fcache_t *b) /* I - Second entry */ +static int /* O - Result of comparison */ +mime_compare_fcache(_mime_fcache_t *a, /* I - First entry */ + _mime_fcache_t *b, /* I - Second entry */ + void *data) /* Unused */ { + (void)data; return (strcmp(a->name, b->name)); } diff --git a/scheduler/network.c b/scheduler/network.c index 5ba00a1fb6..7e389c55a4 100644 --- a/scheduler/network.c +++ b/scheduler/network.c @@ -22,7 +22,7 @@ */ static void cupsdNetIFFree(void); -static int compare_netif(cupsd_netif_t *a, cupsd_netif_t *b); +static int compare_netif(cupsd_netif_t *a, cupsd_netif_t *b, void *data); /* @@ -285,9 +285,11 @@ cupsdNetIFUpdate(void) * 'compare_netif()' - Compare two network interfaces. */ -static int /* O - Result of comparison */ -compare_netif(cupsd_netif_t *a, /* I - First network interface */ - cupsd_netif_t *b) /* I - Second network interface */ +static int /* O - Result of comparison */ +compare_netif(cupsd_netif_t *a, /* I - First network interface */ + cupsd_netif_t *b, /* I - Second network interface */ + void *data) /* Unused */ { + (void)data; return (strcmp(a->name, b->name)); } diff --git a/scheduler/policy.c b/scheduler/policy.c index 20c91c8350..dde53500da 100644 --- a/scheduler/policy.c +++ b/scheduler/policy.c @@ -19,10 +19,10 @@ * Local functions... */ -static int compare_ops(cupsd_location_t *a, cupsd_location_t *b); -static int compare_policies(cupsd_policy_t *a, cupsd_policy_t *b); -static void free_policy(cupsd_policy_t *p); -static int hash_op(cupsd_location_t *op); +static int compare_ops(cupsd_location_t *a, cupsd_location_t *b, void *data); +static int compare_policies(cupsd_policy_t *a, cupsd_policy_t *b, void *data); +static void free_policy(cupsd_policy_t *p, void *data); +static int hash_op(cupsd_location_t *op, void *data); /* @@ -448,10 +448,12 @@ cupsdGetPrivateAttrs( * 'compare_ops()' - Compare two operations. */ -static int /* O - Result of comparison */ -compare_ops(cupsd_location_t *a, /* I - First operation */ - cupsd_location_t *b) /* I - Second operation */ +static int /* O - Result of comparison */ +compare_ops(cupsd_location_t *a, /* I - First operation */ + cupsd_location_t *b, /* I - Second operation */ + void *data) /* Unused */ { + (void)data; return (a->op - b->op); } @@ -460,10 +462,12 @@ compare_ops(cupsd_location_t *a, /* I - First operation */ * 'compare_policies()' - Compare two policies. */ -static int /* O - Result of comparison */ -compare_policies(cupsd_policy_t *a, /* I - First policy */ - cupsd_policy_t *b) /* I - Second policy */ +static int /* O - Result of comparison */ +compare_policies(cupsd_policy_t *a, /* I - First policy */ + cupsd_policy_t *b, /* I - Second policy */ + void *data) /* Unused */ { + (void)data; return (_cups_strcasecmp(a->name, b->name)); } @@ -472,9 +476,10 @@ compare_policies(cupsd_policy_t *a, /* I - First policy */ * 'free_policy()' - Free the memory used by a policy. */ -static void -free_policy(cupsd_policy_t *p) /* I - Policy to free */ +static void free_policy(cupsd_policy_t *p, /* I - Policy to free */ + void *data) /* Unused */ { + (void)data; cupsArrayDelete(p->job_access); cupsArrayDelete(p->job_attrs); cupsArrayDelete(p->sub_access); @@ -489,8 +494,10 @@ free_policy(cupsd_policy_t *p) /* I - Policy to free */ * 'hash_op()' - Generate a lookup hash for the operation. */ -static int /* O - Hash value */ -hash_op(cupsd_location_t *op) /* I - Operation */ +static int /* O - Hash value */ +hash_op(cupsd_location_t *op, /* I - Operation */ + void *data) /* Unused */ { + (void)data; return (((op->op >> 6) & 0x40) | (op->op & 0x3f)); } diff --git a/scheduler/printers.c b/scheduler/printers.c index 5f9852e64f..ec8b387157 100644 --- a/scheduler/printers.c +++ b/scheduler/printers.c @@ -517,7 +517,7 @@ cupsdCreateCommonData(void) snprintf(filename, sizeof(filename), "%s/notifier", ServerBin); if ((dir = cupsDirOpen(filename)) != NULL) { - notifiers = cupsArrayNew((cups_array_func_t)strcmp, NULL); + notifiers = cupsArrayNew((cups_array_func_t)_cupsArrayStrcmp, NULL); while ((dent = cupsDirRead(dir)) != NULL) { @@ -3285,7 +3285,7 @@ add_printer_defaults(cupsd_printer_t *p)/* I - Printer */ if (!CommonDefaults) { - CommonDefaults = cupsArrayNew((cups_array_func_t)strcmp, NULL); + CommonDefaults = cupsArrayNew((cups_array_func_t)_cupsArrayStrcmp, NULL); cupsArrayAdd(CommonDefaults, _cupsStrAlloc("copies-default")); cupsArrayAdd(CommonDefaults, _cupsStrAlloc("document-format-default")); @@ -3685,15 +3685,15 @@ add_printer_formats(cupsd_printer_t *p) /* I - Printer */ * 'compare_printers()' - Compare two printers. */ -static int /* O - Result of comparison */ -compare_printers(void *first, /* I - First printer */ - void *second, /* I - Second printer */ - void *data) /* I - App data (not used) */ +static int /* O - Result of comparison */ +compare_printers(void *first, /* I - First printer */ + void *second, /* I - Second printer */ + void *data) /* I - App data (not used) */ { (void)data; return (_cups_strcasecmp(((cupsd_printer_t *)first)->name, - ((cupsd_printer_t *)second)->name)); + ((cupsd_printer_t *)second)->name)); } diff --git a/scheduler/process.c b/scheduler/process.c index 840c0b88df..221f1bf042 100644 --- a/scheduler/process.c +++ b/scheduler/process.c @@ -59,7 +59,7 @@ static cups_array_t *process_array = NULL; * Local functions... */ -static int compare_procs(cupsd_proc_t *a, cupsd_proc_t *b); +static int compare_procs(cupsd_proc_t *a, cupsd_proc_t *b, void *data); #ifdef HAVE_SANDBOX_H static char *cupsd_requote(char *dst, const char *src, size_t dstsize); #endif /* HAVE_SANDBOX_H */ @@ -851,10 +851,12 @@ cupsdStartProcess( * 'compare_procs()' - Compare two processes. */ -static int /* O - Result of comparison */ -compare_procs(cupsd_proc_t *a, /* I - First process */ - cupsd_proc_t *b) /* I - Second process */ +static int /* O - Result of comparison */ +compare_procs(cupsd_proc_t *a, /* I - First process */ + cupsd_proc_t *b, /* I - Second process */ + void *data) /* Unused */ { + (void)data; return (a->pid - b->pid); } diff --git a/scheduler/quotas.c b/scheduler/quotas.c index d649dcb833..e06e83794d 100644 --- a/scheduler/quotas.c +++ b/scheduler/quotas.c @@ -19,9 +19,9 @@ */ static cupsd_quota_t *add_quota(cupsd_printer_t *p, const char *username); -static int compare_quotas(const cupsd_quota_t *q1, - const cupsd_quota_t *q2); - +static int compare_quotas(const cupsd_quota_t *q1, + const cupsd_quota_t *q2, + void *data); /* * 'cupsdFindQuota()' - Find a quota record. @@ -217,9 +217,11 @@ add_quota(cupsd_printer_t *p, /* I - Printer */ * 'compare_quotas()' - Compare two quota records... */ -static int /* O - Result of comparison */ -compare_quotas(const cupsd_quota_t *q1, /* I - First quota record */ - const cupsd_quota_t *q2) /* I - Second quota record */ +static int /* O - Result of comparison */ +compare_quotas(const cupsd_quota_t *q1, /* I - First quota record */ + const cupsd_quota_t *q2, /* I - Second quota record */ + void *data) /* Unused */ { + (void)data; return (_cups_strcasecmp(q1->username, q2->username)); } diff --git a/scheduler/select.c b/scheduler/select.c index 173155538b..3079f3d52b 100644 --- a/scheduler/select.c +++ b/scheduler/select.c @@ -217,7 +217,7 @@ static fd_set cupsd_global_input, * Local functions... */ -static int compare_fds(_cupsd_fd_t *a, _cupsd_fd_t *b); +static int compare_fds(_cupsd_fd_t *a, _cupsd_fd_t *b, void *data); static _cupsd_fd_t *find_fd(int fd); #define release_fd(f) { \ (f)->use --; \ @@ -887,10 +887,12 @@ cupsdStopSelect(void) * 'compare_fds()' - Compare file descriptors. */ -static int /* O - Result of comparison */ -compare_fds(_cupsd_fd_t *a, /* I - First file descriptor */ - _cupsd_fd_t *b) /* I - Second file descriptor */ +static int /* O - Result of comparison */ +compare_fds(_cupsd_fd_t *a, /* I - First file descriptor */ + _cupsd_fd_t *b, /* I - Second file descriptor */ + void *data) /* Unused */ { + (void)data; return (a->fd - b->fd); } diff --git a/scheduler/subscriptions.c b/scheduler/subscriptions.c index 9b31ec250e..5212db7a4e 100644 --- a/scheduler/subscriptions.c +++ b/scheduler/subscriptions.c @@ -30,7 +30,7 @@ static int cupsd_compare_subscriptions(cupsd_subscription_t *first, cupsd_subscription_t *second, void *unused); -static void cupsd_delete_event(cupsd_event_t *event); +static void cupsd_delete_event(cupsd_event_t *event, void *data); #ifdef HAVE_DBUS static void cupsd_send_dbus(cupsd_eventmask_t event, cupsd_printer_t *dest, cupsd_job_t *job); @@ -1194,11 +1194,11 @@ cupsdStopAllNotifiers(void) * 'cupsd_compare_subscriptions()' - Compare two subscriptions. */ -static int /* O - Result of comparison */ +static int /* O - Result of comparison */ cupsd_compare_subscriptions( - cupsd_subscription_t *first, /* I - First subscription object */ - cupsd_subscription_t *second, /* I - Second subscription object */ - void *unused) /* I - Unused user data pointer */ + cupsd_subscription_t *first, /* I - First subscription object */ + cupsd_subscription_t *second, /* I - Second subscription object */ + void *unused) /* I - Unused user data pointer */ { (void)unused; @@ -1213,18 +1213,18 @@ cupsd_compare_subscriptions( * flushing code will not work properly. */ -static void -cupsd_delete_event(cupsd_event_t *event)/* I - Event to delete */ +static void cupsd_delete_event(cupsd_event_t *event, /* I - Event to delete */ + void *data) /* Unused */ { - /* - * Free memory... - */ + /* + * Free memory... + */ + (void)data; ippDelete(event->attrs); free(event); } - #ifdef HAVE_DBUS /* * 'cupsd_send_dbus()' - Send a DBUS notification... diff --git a/scheduler/type.c b/scheduler/type.c index cd252c450d..49c469cc95 100644 --- a/scheduler/type.c +++ b/scheduler/type.c @@ -43,7 +43,7 @@ typedef struct _mime_filebuf_s /**** File buffer for MIME typing ****/ * Local functions... */ -static int mime_compare_types(mime_type_t *t0, mime_type_t *t1); +static int mime_compare_types(mime_type_t *t0, mime_type_t *t1, void *data); static int mime_check_rules(const char *filename, _mime_filebuf_t *fb, mime_magic_t *rules); static int mime_patmatch(const char *s, const char *pat); @@ -728,12 +728,14 @@ mimeType(mime_t *mime, /* I - MIME database */ * 'mime_compare_types()' - Compare two MIME super/type names. */ -static int /* O - Result of comparison */ -mime_compare_types(mime_type_t *t0, /* I - First type */ - mime_type_t *t1) /* I - Second type */ +static int /* O - Result of comparison */ +mime_compare_types(mime_type_t *t0, /* I - First type */ + mime_type_t *t1, /* I - Second type */ + void *data) /* Unused */ { int i; /* Result of comparison */ + (void)data; if ((i = _cups_strcasecmp(t0->super, t1->super)) == 0) i = _cups_strcasecmp(t0->type, t1->type); diff --git a/scheduler/util.h b/scheduler/util.h index 6fa8dfd244..0a697fa8c7 100644 --- a/scheduler/util.h +++ b/scheduler/util.h @@ -28,13 +28,6 @@ extern "C" { # endif /* __cplusplus */ -/* - * Types... - */ - -typedef int (*cupsd_compare_func_t)(const void *, const void *); - - /* * Prototypes... */ diff --git a/tools/ippeveprinter.c b/tools/ippeveprinter.c index 041a468ef7..7cc730567c 100644 --- a/tools/ippeveprinter.c +++ b/tools/ippeveprinter.c @@ -274,7 +274,7 @@ typedef struct ippeve_client_s /**** Client data ****/ static http_status_t authenticate_request(ippeve_client_t *client); static void clean_jobs(ippeve_printer_t *printer); -static int compare_jobs(ippeve_job_t *a, ippeve_job_t *b); +static int compare_jobs(ippeve_job_t *a, ippeve_job_t *b, void *data); static void copy_attributes(ipp_t *to, ipp_t *from, cups_array_t *ra, ipp_tag_t group_tag, int quickcopy); static void copy_job_attributes(ippeve_client_t *client, ippeve_job_t *job, cups_array_t *ra); static ippeve_client_t *create_client(ippeve_printer_t *printer, int sock); @@ -880,10 +880,12 @@ clean_jobs(ippeve_printer_t *printer) /* I - Printer */ * 'compare_jobs()' - Compare two jobs. */ -static int /* O - Result of comparison */ -compare_jobs(ippeve_job_t *a, /* I - First job */ - ippeve_job_t *b) /* I - Second job */ +static int /* O - Result of comparison */ +compare_jobs(ippeve_job_t *a, /* I - First job */ + ippeve_job_t *b, /* I - Second job */ + void *data) /* Unused */ { + (void)data; return (b->id - a->id); } @@ -2486,7 +2488,7 @@ finish_document_data( respond_ipp(client, IPP_STATUS_OK, NULL); - ra = cupsArrayNew((cups_array_func_t)strcmp, NULL); + ra = cupsArrayNew((cups_array_func_t)_cupsArrayStrcmp, NULL); cupsArrayAdd(ra, "job-id"); cupsArrayAdd(ra, "job-state"); cupsArrayAdd(ra, "job-state-message"); @@ -2506,7 +2508,7 @@ finish_document_data( job->state = IPP_JSTATE_ABORTED; job->completed = time(NULL); - ra = cupsArrayNew((cups_array_func_t)strcmp, NULL); + ra = cupsArrayNew((cups_array_func_t)_cupsArrayStrcmp, NULL); cupsArrayAdd(ra, "job-id"); cupsArrayAdd(ra, "job-state"); cupsArrayAdd(ra, "job-state-reasons"); @@ -2770,7 +2772,7 @@ finish_document_uri( respond_ipp(client, IPP_STATUS_OK, NULL); - ra = cupsArrayNew((cups_array_func_t)strcmp, NULL); + ra = cupsArrayNew((cups_array_func_t)_cupsArrayStrcmp, NULL); cupsArrayAdd(ra, "job-id"); cupsArrayAdd(ra, "job-state"); cupsArrayAdd(ra, "job-state-reasons"); @@ -2789,7 +2791,7 @@ finish_document_uri( job->state = IPP_JSTATE_ABORTED; job->completed = time(NULL); - ra = cupsArrayNew((cups_array_func_t)strcmp, NULL); + ra = cupsArrayNew((cups_array_func_t)_cupsArrayStrcmp, NULL); cupsArrayAdd(ra, "job-id"); cupsArrayAdd(ra, "job-state"); cupsArrayAdd(ra, "job-state-reasons"); @@ -3381,7 +3383,7 @@ ipp_create_job(ippeve_client_t *client) /* I - Client */ respond_ipp(client, IPP_STATUS_OK, NULL); - ra = cupsArrayNew((cups_array_func_t)strcmp, NULL); + ra = cupsArrayNew((cups_array_func_t)_cupsArrayStrcmp, NULL); cupsArrayAdd(ra, "job-id"); cupsArrayAdd(ra, "job-state"); cupsArrayAdd(ra, "job-state-message"); diff --git a/tools/ippfind.c b/tools/ippfind.c index 2e4272653d..58eb62145d 100644 --- a/tools/ippfind.c +++ b/tools/ippfind.c @@ -163,7 +163,7 @@ static void client_callback(AvahiClient *client, void *context); #endif /* HAVE_MDNSRESPONDER */ -static int compare_services(ippfind_srv_t *a, ippfind_srv_t *b); +static int compare_services(ippfind_srv_t *a, ippfind_srv_t *b, void *data); static const char *dnssd_error_string(int error); static int eval_expr(ippfind_srv_t *service, ippfind_expr_t *expressions); @@ -1629,10 +1629,12 @@ client_callback( * 'compare_services()' - Compare two devices. */ -static int /* O - Result of comparison */ -compare_services(ippfind_srv_t *a, /* I - First device */ - ippfind_srv_t *b) /* I - Second device */ +static int /* O - Result of comparison */ +compare_services(ippfind_srv_t *a, /* I - First device */ + ippfind_srv_t *b, /* I - Second device */ + void *data) /* Unused */ { + (void)data; return (strcmp(a->name, b->name)); } diff --git a/tools/ipptool.c b/tools/ipptool.c index 98f6657fab..0ca9870a9f 100644 --- a/tools/ipptool.c +++ b/tools/ipptool.c @@ -1578,7 +1578,7 @@ do_test(_ipp_file_t *f, /* I - IPP data file */ add_stringf(data->errors, "detailed-status-message (text(MAX)) has bad length %d (RFC 8011 section 4.1.6.3).", (int)strlen(detailed_status_message)); } - a = cupsArrayNew((cups_array_func_t)strcmp, NULL); + a = cupsArrayNew((cups_array_func_t)_cupsArrayStrcmp, NULL); for (attrptr = ippFirstAttribute(response), group = ippGetGroupTag(attrptr); attrptr; @@ -2654,7 +2654,7 @@ init_data(ipptool_test_t *data) /* I - Data */ data->family = AF_UNSPEC; data->def_transfer = IPPTOOL_TRANSFER_AUTO; data->def_version = 11; - data->errors = cupsArrayNew3(NULL, NULL, NULL, 0, (cups_acopy_func_t)strdup, (cups_afree_func_t)free); + data->errors = cupsArrayNew3(NULL, NULL, NULL, 0, (cups_acopy_func_t)_cupsArrayStrdup, _cupsArrayFree); data->pass = 1; data->prev_pass = 1; data->request_id = (CUPS_RAND() % 1000) * 137; @@ -5704,7 +5704,7 @@ with_distinct_values( } // Collect values and determine they are all unique... - values = cupsArrayNew3((cups_array_func_t)strcmp, NULL, NULL, 0, (cups_acopy_func_t)strdup, (cups_afree_func_t)free); + values = cupsArrayNew3((cups_array_func_t)_cupsArrayStrcmp, NULL, NULL, 0, (cups_acopy_func_t)_cupsArrayStrdup, _cupsArrayFree); for (i = 0; i < count; i ++) {