Merge branch 'escl-complete-hack-scanjob-request' into 'master'

Use MakeAndModel to apply the hack to the device

See merge request sane-project/backends!575
escl-fix-sleep-mode
Ordissimo 2021-01-17 16:52:58 +00:00
commit fc74de7c5e
3 zmienionych plików z 63 dodań i 15 usunięć

Wyświetl plik

@ -228,9 +228,6 @@ escl_device_add(int port_nb,
} }
model = (char*)(tmp[0] != 0 ? tmp : model_name); model = (char*)(tmp[0] != 0 ? tmp : model_name);
current->model_name = strdup(model); current->model_name = strdup(model);
if (strcasestr(current->model_name, "LaserJet FlowMFP M578") ||
strcasestr(current->model_name, "LaserJet MFP M630"))
current->hack = curl_slist_append(NULL, "Host: localhost");
current->ip_address = strdup(ip_address); current->ip_address = strdup(ip_address);
memset(tmp, 0, PATH_MAX); memset(tmp, 0, PATH_MAX);
snprintf(tmp, sizeof(tmp), "%s scanner", (is ? is : "flatbed or ADF")); snprintf(tmp, sizeof(tmp), "%s scanner", (is ? is : "flatbed or ADF"));
@ -474,8 +471,6 @@ attach_one_config(SANEI_Config __sane_unused__ *config, const char *line,
escl_device->is = strdup("flatbed or ADF scanner"); escl_device->is = strdup("flatbed or ADF scanner");
escl_device->type = strdup("In url"); escl_device->type = strdup("In url");
escl_device->uuid = NULL; 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) { if (strncmp(line, "[device]", 8) == 0) {
@ -1098,6 +1093,50 @@ escl_parse_name(SANE_String_Const name, ESCL_Device *device)
return SANE_STATUS_GOOD; return SANE_STATUS_GOOD;
} }
static void
_get_hack(SANE_String_Const name, ESCL_Device *device)
{
FILE *fp;
SANE_Char line[PATH_MAX];
DBG (3, "_get_hack: start\n");
if (device->model_name &&
(strcasestr(device->model_name, "LaserJet FlowMFP M578") ||
strcasestr(device->model_name, "LaserJet MFP M630"))) {
device->hack = curl_slist_append(NULL, "Host: localhost");
DBG (3, "_get_hack: finish\n");
return;
}
/* open configuration file */
fp = sanei_config_open (ESCL_CONFIG_FILE);
if (!fp)
{
DBG (2, "_get_hack: couldn't access %s\n", ESCL_CONFIG_FILE);
DBG (3, "_get_hack: exit\n");
}
/* loop reading the configuration file, all line beginning by "option " are
* parsed for value to store in configuration structure, other line are
* used are device to try to attach
*/
while (sanei_config_read (line, PATH_MAX, fp))
{
if (strstr(line, name)) {
DBG (3, "_get_hack: idevice found\n");
if (strstr(line, "hack=localhost")) {
DBG (3, "_get_hack: device found\n");
device->hack = curl_slist_append(NULL, "Host: localhost");
}
goto finish_hack;
}
}
finish_hack:
DBG (3, "_get_hack: finish\n");
fclose(fp);
}
/** /**
* \fn SANE_Status sane_open(SANE_String_Const name, SANE_Handle *h) * \fn SANE_Status sane_open(SANE_String_Const name, SANE_Handle *h)
* \brief Function that establishes a connection with the device named by 'name', * \brief Function that establishes a connection with the device named by 'name',
@ -1139,6 +1178,8 @@ sane_open(SANE_String_Const name, SANE_Handle *h)
escl_free_handler(handler); escl_free_handler(handler);
return (status); return (status);
} }
_get_hack(name, device);
status = init_options(NULL, handler); status = init_options(NULL, handler);
if (status != SANE_STATUS_GOOD) { if (status != SANE_STATUS_GOOD) {
escl_free_handler(handler); escl_free_handler(handler);
@ -1723,8 +1764,12 @@ escl_curl_url(CURL *handle, const ESCL_Device *device, SANE_String_Const path)
DBG( 1, "escl_curl_url: URL: %s\n", url ); DBG( 1, "escl_curl_url: URL: %s\n", url );
curl_easy_setopt(handle, CURLOPT_URL, url); curl_easy_setopt(handle, CURLOPT_URL, url);
free(url); free(url);
if (device->hack) DBG( 1, "Before use hack\n");
if (device->hack) {
DBG( 1, "Use hack\n");
curl_easy_setopt(handle, CURLOPT_HTTPHEADER, device->hack); curl_easy_setopt(handle, CURLOPT_HTTPHEADER, device->hack);
}
DBG( 1, "After use hack\n");
if (device->https) { if (device->https) {
DBG( 1, "Ignoring safety certificates, use https\n"); DBG( 1, "Ignoring safety certificates, use https\n");
curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0L); curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0L);

Wyświetl plik

@ -229,7 +229,7 @@ SANE_Status escl_status(const ESCL_Device *device,
const char* jobId, const char* jobId,
SANE_Status *job); SANE_Status *job);
capabilities_t *escl_capabilities(const ESCL_Device *device, capabilities_t *escl_capabilities(ESCL_Device *device,
SANE_Status *status); SANE_Status *status);
char *escl_newjob(capabilities_t *scanner, char *escl_newjob(capabilities_t *scanner,

Wyświetl plik

@ -392,36 +392,39 @@ find_true_variables(xmlNode *node, capabilities_t *scanner, int type)
* \return 0 * \return 0
*/ */
static int static int
print_xml_c(xmlNode *node, capabilities_t *scanner, int type) print_xml_c(xmlNode *node, ESCL_Device *device, capabilities_t *scanner, int type)
{ {
while (node) { while (node) {
if (node->type == XML_ELEMENT_NODE) { if (node->type == XML_ELEMENT_NODE) {
if (find_nodes_c(node) && type != -1) if (find_nodes_c(node) && type != -1)
find_true_variables(node, scanner, type); find_true_variables(node, scanner, type);
} }
if (!strcmp((const char *)node->name, "PlatenInputCaps")) { if (!strcmp((const char *)node->name, "MakeAndModel")){
device->model_name = strdup((const char *)xmlNodeGetContent(node));
}
else if (!strcmp((const char *)node->name, "PlatenInputCaps")) {
scanner->Sources[PLATEN] = (SANE_String_Const)strdup(SANE_I18N ("Flatbed")); scanner->Sources[PLATEN] = (SANE_String_Const)strdup(SANE_I18N ("Flatbed"));
scanner->SourcesSize++; scanner->SourcesSize++;
scanner->source = PLATEN; scanner->source = PLATEN;
print_xml_c(node->children, scanner, PLATEN); print_xml_c(node->children, device, scanner, PLATEN);
scanner->caps[PLATEN].duplex = 0; scanner->caps[PLATEN].duplex = 0;
} }
else if (!strcmp((const char *)node->name, "AdfSimplexInputCaps")) { else if (!strcmp((const char *)node->name, "AdfSimplexInputCaps")) {
scanner->Sources[ADFSIMPLEX] = (SANE_String_Const)strdup(SANE_I18N("ADF")); scanner->Sources[ADFSIMPLEX] = (SANE_String_Const)strdup(SANE_I18N("ADF"));
scanner->SourcesSize++; scanner->SourcesSize++;
if (scanner->source == -1) scanner->source = ADFSIMPLEX; if (scanner->source == -1) scanner->source = ADFSIMPLEX;
print_xml_c(node->children, scanner, ADFSIMPLEX); print_xml_c(node->children, device, scanner, ADFSIMPLEX);
scanner->caps[ADFSIMPLEX].duplex = 0; scanner->caps[ADFSIMPLEX].duplex = 0;
} }
else if (!strcmp((const char *)node->name, "AdfDuplexInputCaps")) { else if (!strcmp((const char *)node->name, "AdfDuplexInputCaps")) {
scanner->Sources[ADFDUPLEX] = (SANE_String_Const)strdup(SANE_I18N ("ADF Duplex")); scanner->Sources[ADFDUPLEX] = (SANE_String_Const)strdup(SANE_I18N ("ADF Duplex"));
scanner->SourcesSize++; scanner->SourcesSize++;
if (scanner->source == -1) scanner->source = ADFDUPLEX; if (scanner->source == -1) scanner->source = ADFDUPLEX;
print_xml_c(node->children, scanner, ADFDUPLEX); print_xml_c(node->children, device, scanner, ADFDUPLEX);
scanner->caps[ADFDUPLEX].duplex = 1; scanner->caps[ADFDUPLEX].duplex = 1;
} }
else if (find_struct_variables(node, scanner) == 0) else if (find_struct_variables(node, scanner) == 0)
print_xml_c(node->children, scanner, type); print_xml_c(node->children, device, scanner, type);
node = node->next; node = node->next;
} }
return (0); return (0);
@ -460,7 +463,7 @@ _reduce_color_modes(capabilities_t *scanner)
* \return scanner (the structure that stocks all the capabilities elements) * \return scanner (the structure that stocks all the capabilities elements)
*/ */
capabilities_t * capabilities_t *
escl_capabilities(const ESCL_Device *device, SANE_Status *status) escl_capabilities(ESCL_Device *device, SANE_Status *status)
{ {
capabilities_t *scanner = (capabilities_t*)calloc(1, sizeof(capabilities_t)); capabilities_t *scanner = (capabilities_t*)calloc(1, sizeof(capabilities_t));
CURL *curl_handle = NULL; CURL *curl_handle = NULL;
@ -504,7 +507,7 @@ escl_capabilities(const ESCL_Device *device, SANE_Status *status)
scanner->Sources = (SANE_String_Const *)malloc(sizeof(SANE_String_Const) * 4); scanner->Sources = (SANE_String_Const *)malloc(sizeof(SANE_String_Const) * 4);
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
scanner->Sources[i] = NULL; scanner->Sources[i] = NULL;
print_xml_c(node, scanner, -1); print_xml_c(node, device, scanner, -1);
_reduce_color_modes(scanner); _reduce_color_modes(scanner);
clean: clean:
xmlFreeDoc(data); xmlFreeDoc(data);