1diff --git a/backend/dll.c b/backend/dll.c 2index bf34c4f6d..9b13d3a59 100644 3--- a/backend/dll.c 4+++ b/backend/dll.c 5@@ -292,6 +292,46 @@ static const char *op_name[] = { 6 }; 7 #endif /* __BEOS__ */ 8 9+#if defined(HAVE_SCAN_SERVICE) 10+static int has_suffix(const char *filename, const char *suffix) 11+{ 12+ size_t len_filename = strlen(filename); 13+ size_t len_suffix = strlen(suffix); 14+ return len_suffix <= len_filename && strcmp(filename + len_filename - len_suffix, suffix) == 0; 15+} 16+ 17+static void find_libname_by_drivername(char* libname, char* dir, char* drivername) 18+{ 19+ DBG(1, "%s: begin", __func__); 20+ if (libname == NULL || dir == NULL || drivername == NULL) { 21+ DBG(2, "%s: input parameter is a nullptr.\n", __func__); 22+ return; 23+ } 24+ char driver[PATH_MAX] = {0}; 25+ snprintf (driver, sizeof (driver), "libsane-%s.z.so", drivername); 26+ DIR *backends_dir = opendir(dir); 27+ if (backends_dir == NULL) { 28+ DBG(2, "open dir %s error\n", backends_dir); 29+ return; 30+ } 31+ struct dirent *entry; 32+ char full_path[PATH_MAX] = {0}; 33+ while ((entry = readdir(backends_dir)) != NULL) { 34+ if (strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0) { 35+ memset(full_path, 0, PATH_MAX); 36+ snprintf(full_path, PATH_MAX, "%s/" "%s", dir, entry->d_name); 37+ DBG(1, "full_path %s\n", full_path); 38+ if (has_suffix(full_path, driver)) { 39+ memset(libname, 0, PATH_MAX); 40+ strncpy(libname, full_path, PATH_MAX); 41+ break; 42+ } 43+ } 44+ } 45+ closedir(backends_dir); 46+} 47+#endif /* HAVE_SCAN_SERVICE */ 48+ 49 static void * 50 op_unsupported (void) 51 { 52@@ -498,6 +538,8 @@ load (struct backend *be) 53 snprintf (libname, sizeof (libname), "%s/" PREFIX "%.2s%.5s" POSTFIX, 54 dir, be->name, strlen(be->name)>7 ? (be->name)+strlen(be->name)-5 : 55 (be->name)+2, V_MAJOR); 56+#elif defined (HAVE_SCAN_SERVICE) 57+ find_libname_by_drivername(libname, dir, be->name); 58 #else 59 snprintf (libname, sizeof (libname), "%s/" PREFIX "%s" POSTFIX, 60 dir, be->name, V_MAJOR); 61@@ -807,6 +849,30 @@ read_config (const char *conffile) 62 fclose (fp); 63 } 64 65+#if defined(HAVE_SCAN_SERVICE) 66+static void 67+read_configs(const char *conffile) 68+{ 69+ const char* dir = "/data/service/el1/public/print_service/sane/config"; 70+ DBG(1, "%s: config_dir : %s ", __func__, dir); 71+ DIR *config_dir = opendir(dir); 72+ if (config_dir == NULL) { 73+ DBG(1, "sane_init/read_configs: opendir failed: %s\n", strerror (errno)); 74+ return; 75+ } 76+ struct dirent *entry; 77+ while ((entry = readdir(config_dir)) != NULL) { 78+ // ignore '.' and '..' 79+ if (strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0) { 80+ DBG(2, "find dll_config file : %s\n", entry->d_name); 81+ if (has_suffix(entry->d_name, conffile)) { 82+ read_config(entry->d_name); 83+ } 84+ } 85+ } 86+} 87+#endif 88+ 89 static void 90 read_dlld (void) 91 { 92@@ -931,8 +997,11 @@ sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize) 93 * Read dll.d first, so that the extras backends will be tried last 94 */ 95 read_dlld (); 96+#ifdef HAVE_SCAN_SERVICE 97+ read_configs(DLL_CONFIG_FILE); 98+#else 99 read_config (DLL_CONFIG_FILE); 100- 101+#endif 102 fp = sanei_config_open (DLL_ALIASES_FILE); 103 if (!fp) 104 return SANE_STATUS_GOOD; /* don't insist on aliases file */ 105diff --git a/include/sane/config.h b/include/sane/config.h 106index 20dfa104b..206a4147e 100644 107--- a/include/sane/config.h 108+++ b/include/sane/config.h 109@@ -209,6 +209,9 @@ 110 /* Define to 1 if you have libusb-1.0 */ 111 #define HAVE_LIBUSB 1 112 113+/* Define to 1 if you have scan_service */ 114+#define HAVE_SCAN_SERVICE 1 115+ 116 /* Define to 1 if you have libusb-0.1 */ 117 /* #undef HAVE_LIBUSB_LEGACY */ 118 119