From 8733651c4b07ac6ccbcee0d39eccca0c08057729 Mon Sep 17 00:00:00 2001 From: "m. allan noah" Date: Thu, 26 Jun 2008 13:14:23 +0000 Subject: [PATCH] test backend checks for options that have not been loaded before being controlled --- ChangeLog | 3 +++ backend/test.c | 20 ++++++++++++++++++++ backend/test.h | 1 + 3 files changed, 24 insertions(+) diff --git a/ChangeLog b/ChangeLog index 9214250ab..bc5d90eda 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2008-06-26 m. allan noah + * backend/test.[ch]: check for options being controlled before loading + 2008-06-25 Nicolas Martin * backend/pixma_imageclass.c: Patch from Sam Varshavchik to deal with libusb 64 read issue, diff --git a/backend/test.c b/backend/test.c index 5272e1549..d291a582c 100644 --- a/backend/test.c +++ b/backend/test.c @@ -295,6 +295,8 @@ init_options (Test_Device * test_device) od->constraint.range = 0; test_device->val[opt_num_opts].w = num_options; + test_device->loaded[opt_num_opts] = 1; + /* opt_mode_group */ od = &test_device->opt[opt_mode_group]; od->name = ""; @@ -1821,6 +1823,8 @@ sane_get_option_descriptor (SANE_Handle handle, SANE_Int option) return 0; } + test_device->loaded[option] = 1; + return &test_device->opt[option]; } @@ -1861,6 +1865,12 @@ sane_control_option (SANE_Handle handle, SANE_Int option, SANE_Action action, return SANE_STATUS_INVAL; } + if (!test_device->loaded[option]) + { + DBG (1, "sane_control_option: option not loaded\n"); + return SANE_STATUS_INVAL; + } + if (!SANE_OPTION_IS_ACTIVE (test_device->opt[option].cap)) { DBG (1, "sane_control_option: option is inactive\n"); @@ -2297,12 +2307,22 @@ sane_control_option (SANE_Handle handle, SANE_Int option, SANE_Action action, DBG (1, "sane_control_option: trying unexpected action %d\n", action); return SANE_STATUS_INVAL; } + if (info) *info = myinfo; + + if(myinfo & SANE_INFO_RELOAD_OPTIONS){ + SANE_Int i = 0; + for(i=1;iloaded[i] = 0; + } + } + DBG (4, "sane_control_option: finished, info=%s %s %s \n", myinfo & SANE_INFO_INEXACT ? "inexact" : "", myinfo & SANE_INFO_RELOAD_PARAMS ? "reload_parameters" : "", myinfo & SANE_INFO_RELOAD_OPTIONS ? "reload_options" : ""); + return SANE_STATUS_GOOD; } diff --git a/backend/test.h b/backend/test.h index 9392fd979..6d253fd63 100644 --- a/backend/test.h +++ b/backend/test.h @@ -124,6 +124,7 @@ typedef struct Test_Device SANE_Device sane; SANE_Option_Descriptor opt[num_options]; Option_Value val[num_options]; + SANE_Bool loaded[num_options]; SANE_Parameters params; SANE_String name; SANE_Pid reader_pid;