blob: 221f56ab461577fd5342e70892b81dba7627a948 [file] [log] [blame]
Allow filter search in epson-escpr-wrapper
Instead of calling epson-escpr from wrapper in hard coded CUPS_FILTER_PATH,
this patch allows wrapper to search filter in non-standard location by calling
cups API cupsSearchFilterLatest:
https://chromium-review.googlesource.com/c/518931/
--- a/src/wrapper.c
+++ b/src/wrapper.c
@@ -33,6 +33,8 @@
#include <ctype.h>
/* added 22-04-2004 */
#include <signal.h>
+/* added 07-09-2017 */
+#include <linux/limits.h>
#include "libprtX.h"
@@ -282,10 +284,42 @@ main (int argc, char *argv[])
if (pfp == NULL)
{
- char tmpbuf[256];
+ char tmpbuf[256 + PATH_MAX];
+ char cups_filter_path[PATH_MAX]; // filter full path.
+ // Fill in default filter path (2 additional characters: '/' and '\0').
+ int total_size = snprintf(cups_filter_path, sizeof(cups_filter_path),
+ "%s/%s", CUPS_FILTER_PATH, CUPS_FILTER_NAME);
+ if (total_size < 0 || total_size >= sizeof(cups_filter_path))
+ return 1;
+ if (access(cups_filter_path, F_OK) != 0)
+ {
+ // Filter does not exist in default location.
+ int status = _cupsSearchFilterLatest(
+ "epson-escpr",
+ cups_filter_path,
+ sizeof(cups_filter_path));
+ if (status == 1)
+ {
+ // found a filter.
+ char *end_of_basedir = strrchr(cups_filter_path, '/');
+ if (!end_of_basedir)
+ return 1;
+ // cut the filename off the filter path.
+ *end_of_basedir = '\0';
+ }
+ else {
+ debug_msg("_cupsSearchFilterLatest failed: %d", status);
+ return 1;
+ }
+ }
+ else {
+ // cut off filename (CUPS_FILTER_NAME).
+ strncpy(cups_filter_path, CUPS_FILTER_PATH,
+ sizeof(cups_filter_path));
+ }
sprintf (tmpbuf, "%s/%s \"%s\" %d %d %d %s %s %s %s %s %s %s %s",
- CUPS_FILTER_PATH,
+ cups_filter_path,
CUPS_FILTER_NAME,
fopt.model,
header.cupsWidth,