From e2b2db1f03616c1c4464e31b89fed9ae0b1353e7 Mon Sep 17 00:00:00 2001 From: Till Kamppeter Date: Tue, 27 Oct 2020 23:06:42 +0100 Subject: [PATCH] libcupsfilters: Made internal device-ID-related functions public and renamed them --- NEWS | 3 +- backend/parallel.c | 10 +++--- backend/test1284.c | 4 +-- cupsfilters/ieee1284.c | 74 +++++++++++++++++++----------------------- cupsfilters/ieee1284.h | 22 ++++++++----- 5 files changed, 56 insertions(+), 57 deletions(-) diff --git a/NEWS b/NEWS index 136afa4dd..dabbb009c 100644 --- a/NEWS +++ b/NEWS @@ -5,7 +5,8 @@ CHANGES IN V2.0.0 - libcupsfilters, parallel, test1284: Moved IEEE1284-device-ID-related functions into the public API of - libcupsfilters. + libcupsfilters, also made the internal functions public and + renamed them all to ieee1284...(). - foomatic-rip: Remove temporary file created during pdf-to-ps conversion (Pull request #313). - libppd: Added PPD collection handling functions (based on diff --git a/backend/parallel.c b/backend/parallel.c index 9c1c2143f..c5b83545a 100644 --- a/backend/parallel.c +++ b/backend/parallel.c @@ -419,9 +419,9 @@ list_devices(void) snprintf(uri, sizeof(uri), "parallel:%s", device); - if (!backendGetDeviceID(fd, device_id, sizeof(device_id), - make_model, sizeof(make_model), - NULL, uri, sizeof(uri))) + if (!ieee1284GetDeviceID(fd, device_id, sizeof(device_id), + make_model, sizeof(make_model), + NULL, uri, sizeof(uri))) { snprintf(info, sizeof(info), "%s LPT #%d", make_model, i + 1); cupsBackendReport("direct", uri, make_model, info, device_id, NULL); @@ -838,8 +838,8 @@ side_cb(int print_fd, /* I - Print file */ case CUPS_SC_CMD_GET_DEVICE_ID : memset(data, 0, sizeof(data)); - if (backendGetDeviceID(device_fd, data, sizeof(data) - 1, - NULL, 0, NULL, NULL, 0)) + if (ieee1284GetDeviceID(device_fd, data, sizeof(data) - 1, + NULL, 0, NULL, NULL, 0)) { status = CUPS_SC_STATUS_NOT_IMPLEMENTED; datalen = 0; diff --git a/backend/test1284.c b/backend/test1284.c index b8c546faf..ea06b2e79 100644 --- a/backend/test1284.c +++ b/backend/test1284.c @@ -62,8 +62,8 @@ main(int argc, /* I - Number of command-line args */ printf("%s:\n", argv[i]); - backendGetDeviceID(fd, device_id, sizeof(device_id), make_model, - sizeof(make_model), "test", uri, sizeof(uri)); + ieee1284GetDeviceID(fd, device_id, sizeof(device_id), make_model, + sizeof(make_model), "test", uri, sizeof(uri)); printf(" device_id=\"%s\"\n", device_id); printf(" make_model=\"%s\"\n", make_model); diff --git a/cupsfilters/ieee1284.c b/cupsfilters/ieee1284.c index 1685ae605..8327a2fe0 100644 --- a/cupsfilters/ieee1284.c +++ b/cupsfilters/ieee1284.c @@ -11,12 +11,13 @@ * * Contents: * - * backendGetDeviceID() - Get the IEEE-1284 device ID string and - * corresponding URI. - * backendGetMakeModel() - Get the make and model string from the device - * ID. - * get_1284_values() - Get 1284 device ID keys and values. - * normalize_make_and_model() - Normalize a product/make-and-model string. + * ieee1284GetDeviceID() - Get the IEEE-1284 device ID string and + * corresponding URI. + * ieee1284GetMakeModel() - Get the make and model string from the + * device ID. + * ieee1284GetValues() - Get 1284 device ID keys and values. + * ieee1284NormalizeMakeAndModel() - Normalize a product/make-and-model + * string. */ /* @@ -35,21 +36,12 @@ /* - * Local functions... - */ - -static int get_1284_values(const char *device_id, cups_option_t **values); -static char *normalize_make_and_model(const char *make_and_model, - char *buffer, size_t bufsize); - - -/* - * 'backendGetDeviceID()' - Get the IEEE-1284 device ID string and - * corresponding URI. + * 'ieee1284GetDeviceID()' - Get the IEEE-1284 device ID string and + * corresponding URI. */ int /* O - 0 on success, -1 on failure */ -backendGetDeviceID( +ieee1284GetDeviceID( int fd, /* I - File descriptor */ char *device_id, /* O - 1284 device ID */ int device_id_size, /* I - Size of buffer */ @@ -82,7 +74,7 @@ backendGetDeviceID( char *ptr; /* Pointer into device ID */ - DEBUG_printf(("backendGetDeviceID(fd=%d, device_id=%p, device_id_size=%d, " + DEBUG_printf(("ieee1284GetDeviceID(fd=%d, device_id=%p, device_id_size=%d, " "make_model=%p, make_model_size=%d, scheme=\"%s\", " "uri=%p, uri_size=%d)\n", fd, device_id, device_id_size, make_model, make_model_size, scheme ? scheme : "(null)", @@ -94,7 +86,7 @@ backendGetDeviceID( if (!device_id || device_id_size < 32) { - DEBUG_puts("backendGetDeviceID: Bad args!"); + DEBUG_puts("ieee1284GetDeviceID: Bad args!"); return (-1); } @@ -241,7 +233,7 @@ backendGetDeviceID( } else { - DEBUG_printf(("backendGetDeviceID: ioctl failed - %s\n", + DEBUG_printf(("ieee1284GetDeviceID: ioctl failed - %s\n", strerror(errno))); *device_id = '\0'; } @@ -266,7 +258,7 @@ backendGetDeviceID( } # ifdef DEBUG else - DEBUG_printf(("backendGetDeviceID: ioctl failed - %s\n", + DEBUG_printf(("ieee1284GetDeviceID: ioctl failed - %s\n", strerror(errno))); # endif /* DEBUG */ # endif /* __sun && ECPPIOC_GETDEVID */ @@ -282,13 +274,13 @@ backendGetDeviceID( *ptr = ' '; else if ((*ptr & 255) < ' ' || *ptr == 127) { - DEBUG_printf(("backendGetDeviceID: Bad device_id character %d.", + DEBUG_printf(("ieee1284GetDeviceID: Bad device_id character %d.", *ptr & 255)); *device_id = '\0'; break; } - DEBUG_printf(("backendGetDeviceID: device_id=\"%s\"\n", device_id)); + DEBUG_printf(("ieee1284GetDeviceID: device_id=\"%s\"\n", device_id)); if (scheme && uri) *uri = '\0'; @@ -301,7 +293,7 @@ backendGetDeviceID( */ if (make_model) - backendGetMakeModel(device_id, make_model, make_model_size); + ieee1284GetMakeModel(device_id, make_model, make_model_size); /* * Then generate a device URI... @@ -322,7 +314,7 @@ backendGetDeviceID( * Get the make, model, and serial numbers... */ - num_values = get_1284_values(device_id, &values); + num_values = ieee1284GetValues(device_id, &values); if ((sern = cupsGetOption("SERIALNUMBER", num_values, values)) == NULL) if ((sern = cupsGetOption("SERN", num_values, values)) == NULL) @@ -380,11 +372,11 @@ backendGetDeviceID( /* - * 'backendGetMakeModel()' - Get the make and model string from the device ID. + * 'ieee1284GetMakeModel()' - Get the make and model string from the device ID. */ int /* O - 0 on success, -1 on failure */ -backendGetMakeModel( +ieee1284GetMakeModel( const char *device_id, /* O - 1284 device ID */ char *make_model, /* O - Make/model */ int make_model_size) /* I - Size of buffer */ @@ -396,7 +388,7 @@ backendGetMakeModel( *des; /* Description string */ - DEBUG_printf(("backendGetMakeModel(device_id=\"%s\", " + DEBUG_printf(("ieee1284GetMakeModel(device_id=\"%s\", " "make_model=%p, make_model_size=%d)\n", device_id, make_model, make_model_size)); @@ -406,7 +398,7 @@ backendGetMakeModel( if (!device_id || !*device_id || !make_model || make_model_size < 32) { - DEBUG_puts("backendGetMakeModel: Bad args!"); + DEBUG_puts("ieee1284GetMakeModel: Bad args!"); return (-1); } @@ -416,7 +408,7 @@ backendGetMakeModel( * Look for the description field... */ - num_values = get_1284_values(device_id, &values); + num_values = ieee1284GetValues(device_id, &values); if ((mdl = cupsGetOption("MODEL", num_values, values)) == NULL) mdl = cupsGetOption("MDL", num_values, values); @@ -436,7 +428,7 @@ backendGetMakeModel( * Just copy the model string, since it has the manufacturer... */ - normalize_make_and_model(mdl, make_model, make_model_size); + ieee1284NormalizeMakeAndModel(mdl, make_model, make_model_size); } else { @@ -448,7 +440,7 @@ backendGetMakeModel( snprintf(temp, sizeof(temp), "%s %s", mfg, mdl); - normalize_make_and_model(temp, make_model, make_model_size); + ieee1284NormalizeMakeAndModel(temp, make_model, make_model_size); } } else if ((des = cupsGetOption("DESCRIPTION", num_values, values)) != NULL || @@ -482,7 +474,7 @@ backendGetMakeModel( } if (spaces && letters) - normalize_make_and_model(des, make_model, make_model_size); + ieee1284NormalizeMakeAndModel(des, make_model, make_model_size); } } @@ -503,14 +495,14 @@ backendGetMakeModel( /* - * 'get_1284_values()' - Get 1284 device ID keys and values. + * 'ieee1284GetValues()' - Get 1284 device ID keys and values. * * The returned dictionary is a CUPS option array that can be queried with * cupsGetOption and freed with cupsFreeOptions. */ -static int /* O - Number of key/value pairs */ -get_1284_values( +int /* O - Number of key/value pairs */ +ieee1284GetValues( const char *device_id, /* I - IEEE-1284 device ID string */ cups_option_t **values) /* O - Array of key/value pairs */ { @@ -586,14 +578,16 @@ get_1284_values( /* - * 'normalize_make_and_model()' - Normalize a product/make-and-model string. + * 'ieee1284NormalizeMakeAndModel()' - Normalize a product/make-and-model + * string. * * This function tries to undo the mistakes made by many printer manufacturers * to produce a clean make-and-model string we can use. */ -static char * /* O - Normalized make-and-model string or NULL on error */ -normalize_make_and_model( +char * /* O - Normalized make-and-model string + or NULL on error */ +ieee1284NormalizeMakeAndModel( const char *make_and_model, /* I - Original make-and-model string */ char *buffer, /* I - String buffer */ size_t bufsize) /* I - Size of string buffer */ diff --git a/cupsfilters/ieee1284.h b/cupsfilters/ieee1284.h index 6f5264558..359bd898d 100644 --- a/cupsfilters/ieee1284.h +++ b/cupsfilters/ieee1284.h @@ -62,15 +62,19 @@ extern "C" { * Prototypes... */ -extern int backendGetDeviceID(int fd, char *device_id, - int device_id_size, - char *make_model, - int make_model_size, - const char *scheme, char *uri, - int uri_size); -extern int backendGetMakeModel(const char *device_id, - char *make_model, - int make_model_size); +extern int ieee1284GetDeviceID(int fd, char *device_id, + int device_id_size, + char *make_model, + int make_model_size, + const char *scheme, char *uri, + int uri_size); +extern int ieee1284GetMakeModel(const char *device_id, + char *make_model, + int make_model_size); +extern int ieee1284GetValues(const char *device_id, + cups_option_t **values); +extern char *ieee1284NormalizeMakeAndModel(const char *make_and_model, + char *buffer, size_t bufsize); # ifdef __cplusplus -- 2.47.3