summaryrefslogtreecommitdiff
path: root/backend/escl/escl_capabilities.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2021-02-16 18:25:42 +0100
committerJörg Frings-Fürst <debian@jff-webhosting.net>2021-02-16 18:25:42 +0100
commit64ddd1a4dfcefd11f662f5cf4bb05b590d901a97 (patch)
tree4303648095deff998ae20c2393b56db527742ac9 /backend/escl/escl_capabilities.c
parent5793a221e112fa49073de0137d6bfa750a61b0a1 (diff)
parentecaaf250cb33ff61f37a7b441f2337584a655350 (diff)
Merge branch 'feature/upstream' into develop
Diffstat (limited to 'backend/escl/escl_capabilities.c')
-rw-r--r--backend/escl/escl_capabilities.c111
1 files changed, 92 insertions, 19 deletions
diff --git a/backend/escl/escl_capabilities.c b/backend/escl/escl_capabilities.c
index fdd5cfe..db194f9 100644
--- a/backend/escl/escl_capabilities.c
+++ b/backend/escl/escl_capabilities.c
@@ -16,8 +16,8 @@
for more details.
You should have received a copy of the GNU General Public License
- along with sane; see the file COPYING. If not, write to the Free
- Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ along with sane; see the file COPYING.
+ If not, see <https://www.gnu.org/licenses/>.
This file implements a SANE backend for eSCL scanners. */
@@ -30,7 +30,6 @@
#include <stdlib.h>
#include <string.h>
-#include <curl/curl.h>
#include <libxml/parser.h>
#include "../include/sane/saneopts.h"
@@ -90,9 +89,9 @@ char_to_array(SANE_String_Const *tab, int *tabsize, SANE_String_Const mode, int
}
(*tabsize)++;
if (*tabsize == 1)
- board = (SANE_String_Const *)malloc(sizeof(SANE_String_Const) * (*tabsize) + 1);
+ board = (SANE_String_Const *)malloc(sizeof(SANE_String_Const) * ((*tabsize) + 1));
else
- board = (SANE_String_Const *)realloc(tab, sizeof(SANE_String_Const) * (*tabsize) + 1);
+ board = (SANE_String_Const *)realloc(tab, sizeof(SANE_String_Const) * ((*tabsize) + 1));
board[*tabsize - 1] = (SANE_String_Const)strdup(convert);
board[*tabsize] = NULL;
return (board);
@@ -173,7 +172,7 @@ find_nodes_c(xmlNode *node)
/**
* \fn static int find_valor_of_array_variables(xmlNode *node, capabilities_t *scanner)
- * \brief Function that searchs in the xml file if a scanner capabilitie stocked
+ * \brief Function that searches in the xml file if a scanner capabilitie stocked
* in one of the created array (character/integer array) is found.
*
* \return 0
@@ -194,32 +193,40 @@ find_valor_of_array_variables(xmlNode *node, capabilities_t *scanner, int type)
int i = 0;
SANE_Bool have_jpeg = SANE_FALSE, have_png = SANE_FALSE, have_tiff = SANE_FALSE, have_pdf = SANE_FALSE;
scanner->caps[type].DocumentFormats = char_to_array(scanner->caps[type].DocumentFormats, &scanner->caps[type].DocumentFormatsSize, (SANE_String_Const)xmlNodeGetContent(node), 0);
+ scanner->caps[type].have_jpeg = -1;
+ scanner->caps[type].have_png = -1;
+ scanner->caps[type].have_tiff = -1;
+ scanner->caps[type].have_pdf = -1;
for(; i < scanner->caps[type].DocumentFormatsSize; i++)
{
if (!strcmp(scanner->caps[type].DocumentFormats[i], "image/jpeg"))
{
have_jpeg = SANE_TRUE;
+ scanner->caps[type].have_jpeg = i;
}
#if(defined HAVE_LIBPNG)
else if(!strcmp(scanner->caps[type].DocumentFormats[i], "image/png"))
{
have_png = SANE_TRUE;
+ scanner->caps[type].have_png = i;
}
#endif
#if(defined HAVE_TIFFIO_H)
else if(type == PLATEN && !strcmp(scanner->caps[type].DocumentFormats[i], "image/tiff"))
{
have_tiff = SANE_TRUE;
+ scanner->caps[type].have_tiff = i;
}
#endif
#if(defined HAVE_POPPLER_GLIB)
else if(type == PLATEN && !strcmp(scanner->caps[type].DocumentFormats[i], "application/pdf"))
{
have_pdf = SANE_TRUE;
+ scanner->caps[type].have_pdf = i;
}
#endif
}
- if (have_pdf)
+ if (have_pdf)
scanner->caps[type].default_format = strdup("application/pdf");
else if (have_tiff)
scanner->caps[type].default_format = strdup("image/tiff");
@@ -239,7 +246,7 @@ find_valor_of_array_variables(xmlNode *node, capabilities_t *scanner, int type)
/**
* \fn static int find_value_of_int_variables(xmlNode *node, capabilities_t *scanner)
- * \brief Function that searchs in the xml file if a integer scanner capabilitie is found.
+ * \brief Function that searches in the xml file if a integer scanner capabilitie is found.
* The integer scanner capabilities that are interesting are :
* MinWidth, MaxWidth, MaxHeight, MinHeight, MaxScanRegions, MaxOpticalXResolution,
* RiskyLeftMargin, RiskyRightMargin, RiskyTopMargin, RiskyBottomMargin.
@@ -283,11 +290,74 @@ find_value_of_int_variables(xmlNode *node, capabilities_t *scanner, int type)
return (0);
}
+static support_t*
+print_support(xmlNode *node)
+{
+ support_t *sup = (support_t*)calloc(1, sizeof(support_t));
+ int cpt = 0;
+ int have_norm = 0;
+ while (node) {
+ if (!strcmp((const char *)node->name, "Min")){
+ sup->min = atoi((const char *)xmlNodeGetContent(node));
+ cpt++;
+ }
+ else if (!strcmp((const char *)node->name, "Max")) {
+ sup->max = atoi((const char *)xmlNodeGetContent(node));
+ cpt++;
+ }
+ else if (!strcmp((const char *)node->name, "Normal")) {
+ sup->normal = atoi((const char *)xmlNodeGetContent(node));
+ cpt++;
+ have_norm = 1;
+ }
+ else if (!strcmp((const char *)node->name, "Step")) {
+ sup->step = atoi((const char *)xmlNodeGetContent(node));
+ cpt++;
+ }
+ node = node->next;
+ }
+ if (cpt == 4)
+ return sup;
+ if (cpt == 3 && have_norm == 0) {
+ sup->normal = (sup->max / 2 );
+ return sup;
+ }
+ free(sup);
+ return NULL;
+}
+
+static int
+find_struct_variables(xmlNode *node, capabilities_t *scanner)
+{
+ const char *name = (const char *)node->name;
+ if (strcmp(name, "BrightnessSupport") == 0) {
+ scanner->brightness =
+ print_support(node->children);
+ return 1;
+ }
+ else if (strcmp(name, "ContrastSupport") == 0) {
+ scanner->contrast =
+ print_support(node->children);
+ return 1;
+ }
+ else if (strcmp(name, "SharpenSupport") == 0) {
+ scanner->sharpen =
+ print_support(node->children);
+ return 1;
+ }
+ else if (strcmp(name, "ThresholdSupport") == 0) {
+ scanner->threshold =
+ print_support(node->children);
+ return 1;
+ }
+ return (0);
+}
+
/**
* \fn static int find_true_variables(xmlNode *node, capabilities_t *scanner)
- * \brief Function that searchs in the xml file if we find a scanner capabilitie stocked
+ * \brief Function that searches in the xml file if we find a scanner capability stored
* in one of the created array (character/integer array),
- * or, if we find a integer scanner capabilitie.
+ * or, if we find a integer scanner capability.
*
* \return 0
*/
@@ -322,36 +392,39 @@ find_true_variables(xmlNode *node, capabilities_t *scanner, int type)
* \return 0
*/
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) {
if (node->type == XML_ELEMENT_NODE) {
if (find_nodes_c(node) && type != -1)
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->SourcesSize++;
scanner->source = PLATEN;
- print_xml_c(node->children, scanner, PLATEN);
+ print_xml_c(node->children, device, scanner, PLATEN);
scanner->caps[PLATEN].duplex = 0;
}
else if (!strcmp((const char *)node->name, "AdfSimplexInputCaps")) {
scanner->Sources[ADFSIMPLEX] = (SANE_String_Const)strdup(SANE_I18N("ADF"));
scanner->SourcesSize++;
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;
}
else if (!strcmp((const char *)node->name, "AdfDuplexInputCaps")) {
scanner->Sources[ADFDUPLEX] = (SANE_String_Const)strdup(SANE_I18N ("ADF Duplex"));
scanner->SourcesSize++;
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;
}
- else
- print_xml_c(node->children, scanner, type);
+ else if (find_struct_variables(node, scanner) == 0)
+ print_xml_c(node->children, device, scanner, type);
node = node->next;
}
return (0);
@@ -390,7 +463,7 @@ _reduce_color_modes(capabilities_t *scanner)
* \return scanner (the structure that stocks all the capabilities elements)
*/
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));
CURL *curl_handle = NULL;
@@ -434,7 +507,7 @@ escl_capabilities(const ESCL_Device *device, SANE_Status *status)
scanner->Sources = (SANE_String_Const *)malloc(sizeof(SANE_String_Const) * 4);
for (i = 0; i < 4; i++)
scanner->Sources[i] = NULL;
- print_xml_c(node, scanner, -1);
+ print_xml_c(node, device, scanner, -1);
_reduce_color_modes(scanner);
clean:
xmlFreeDoc(data);