diff --git a/backend/escl.conf.in b/backend/escl.conf.in index 9c482b573..fa89ae722 100644 --- a/backend/escl.conf.in +++ b/backend/escl.conf.in @@ -13,6 +13,7 @@ #device http://123.456.789.10:8080 OptionalModel1 #device https://123.456.789.10:443 "Optional Model 2" +#device https://123.456.789.10:443 ""HP Color LaserJet FlowMFP M578" "hack=localhost" #device unix:/run/proxy.sock:http://123.456.789.10:80 #[device] diff --git a/backend/escl/escl.c b/backend/escl/escl.c index 5df34471b..a997ea208 100644 --- a/backend/escl/escl.c +++ b/backend/escl/escl.c @@ -94,7 +94,7 @@ escl_free_device(ESCL_Device *current) free((void*)current->is); free((void*)current->uuid); free((void*)current->unix_socket); - curl_slist_free_all(current->localhost); + curl_slist_free_all(current->hack); free(current); return NULL; } @@ -230,7 +230,7 @@ escl_device_add(int port_nb, current->model_name = strdup(model); if (strcasestr(current->model_name, "LaserJet FlowMFP M578") || strcasestr(current->model_name, "LaserJet MFP M630")) - current->localhost = curl_slist_append(NULL, "Host: localhost"); + current->hack = curl_slist_append(NULL, "Host: localhost"); current->ip_address = strdup(ip_address); memset(tmp, 0, PATH_MAX); snprintf(tmp, sizeof(tmp), "%s scanner", (is ? is : "flatbed or ADF")); @@ -439,6 +439,7 @@ attach_one_config(SANEI_Config __sane_unused__ *config, const char *line, if (strncmp(line, "device", 6) == 0) { char *name_str = NULL; char *opt_model = NULL; + char *opt_hack = NULL; line = sanei_config_get_string(line + 6, &name_str); DBG (10, "New Escl_Device URL [%s].\n", (name_str ? name_str : "VIDE")); @@ -450,6 +451,10 @@ attach_one_config(SANEI_Config __sane_unused__ *config, const char *line, line = sanei_config_get_string(line, &opt_model); DBG (10, "New Escl_Device model [%s].\n", opt_model); } + if (*line) { + line = sanei_config_get_string(line, &opt_hack); + DBG (10, "New Escl_Device hack [%s].\n", opt_hack); + } escl_free_device(escl_device); escl_device = (ESCL_Device*)calloc(1, sizeof(ESCL_Device)); @@ -469,6 +474,8 @@ attach_one_config(SANEI_Config __sane_unused__ *config, const char *line, escl_device->is = strdup("flatbed or ADF scanner"); escl_device->type = strdup("In url"); escl_device->uuid = NULL; + if (opt_hack && !strcmp(opt_hack, "hack=localhost")) + escl_device->hack = curl_slist_append(NULL, "Host: localhost"); } if (strncmp(line, "[device]", 8) == 0) { @@ -479,7 +486,7 @@ attach_one_config(SANEI_Config __sane_unused__ *config, const char *line, return (SANE_STATUS_NO_MEM); } } - if (strncmp(line, "ip", 2) == 0) { + else if (strncmp(line, "ip", 2) == 0) { const char *ip_space = sanei_config_skip_whitespace(line + 2); DBG (10, "New Escl_Device IP [%s].", (ip_space ? ip_space : "VIDE")); if (escl_device != NULL && ip_space != NULL) { @@ -487,14 +494,14 @@ attach_one_config(SANEI_Config __sane_unused__ *config, const char *line, escl_device->ip_address = strdup(ip_space); } } - if (sscanf(line, "port %i", &port) == 1 && port != 0) { + else if (sscanf(line, "port %i", &port) == 1 && port != 0) { DBG (10, "New Escl_Device PORT [%d].", port); if (escl_device != NULL) { DBG (10, "New Escl_Device PORT Affected."); escl_device->port_nb = port; } } - if (strncmp(line, "model", 5) == 0) { + else if (strncmp(line, "model", 5) == 0) { const char *model_space = sanei_config_skip_whitespace(line + 5); DBG (10, "New Escl_Device MODEL [%s].", (model_space ? model_space : "VIDE")); if (escl_device != NULL && model_space != NULL) { @@ -502,7 +509,7 @@ attach_one_config(SANEI_Config __sane_unused__ *config, const char *line, escl_device->model_name = strdup(model_space); } } - if (strncmp(line, "type", 4) == 0) { + else if (strncmp(line, "type", 4) == 0) { const char *type_space = sanei_config_skip_whitespace(line + 4); DBG (10, "New Escl_Device TYPE [%s].", (type_space ? type_space : "VIDE")); if (escl_device != NULL && type_space != NULL) { @@ -1716,8 +1723,8 @@ escl_curl_url(CURL *handle, const ESCL_Device *device, SANE_String_Const path) DBG( 1, "escl_curl_url: URL: %s\n", url ); curl_easy_setopt(handle, CURLOPT_URL, url); free(url); - if (device->localhost) - curl_easy_setopt(handle, CURLOPT_HTTPHEADER, device->localhost); + if (device->hack) + curl_easy_setopt(handle, CURLOPT_HTTPHEADER, device->hack); if (device->https) { DBG( 1, "Ignoring safety certificates, use https\n"); curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0L); diff --git a/backend/escl/escl.h b/backend/escl/escl.h index 131153e2b..e93f58b63 100644 --- a/backend/escl/escl.h +++ b/backend/escl/escl.h @@ -99,7 +99,7 @@ typedef struct ESCL_Device { char *uuid; char *type; SANE_Bool https; - struct curl_slist *localhost; + struct curl_slist *hack; char *unix_socket; } ESCL_Device;