From 29e8be57e5c6b82fd88157b6909cdd14c2b91eca Mon Sep 17 00:00:00 2001 From: Julien BLACHE Date: Tue, 24 Jun 2008 20:07:01 +0000 Subject: [PATCH] Fetch option descriptors in sane_open() so a GET_VALUE on option 0 can still work without having to get option descriptor 0 beforehand. --- ChangeLog | 4 +++- backend/net.c | 21 ++++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 87646c474..01705e01f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,9 @@ 2008-06-24 Julien Blache * backend/net.c: do not reload options behind the frontend's back in sane_control_option; rather return SANE_STATUS_INVAL and warn - that the frontend is buggy. + that the frontend is buggy. Fetch option descriptors in + sane_open() so a GET_VALUE on option 0 can still work without + having to get option descriptor 0 beforehand. * frontend/saned.c: rework error/exit path in process_request() to properly terminate the Avahi thread when in debug mode. diff --git a/backend/net.c b/backend/net.c index 276b216ef..79dd394e0 100644 --- a/backend/net.c +++ b/backend/net.c @@ -1361,6 +1361,7 @@ sane_open (SANE_String_Const full_name, SANE_Handle * meta_handle) SANE_String nd_name; SANE_Status status; SANE_Word handle; + SANE_Word ack; Net_Device *dev; Net_Scanner *s; int need_auth; @@ -1585,8 +1586,26 @@ sane_open (SANE_String_Const full_name, SANE_Handle * meta_handle) s->next = first_handle; s->local_opt.desc = 0; s->local_opt.num_options = 0; + + DBG (3, "sane_open: getting option descriptors\n"); + status = fetch_options (s); + if (status != SANE_STATUS_GOOD) + { + DBG (1, "sane_open: fetch_options failed (%s), closing device again\n", + sane_strstatus (status)); + + sanei_w_call (&s->hw->wire, SANE_NET_CLOSE, + (WireCodecFunc) sanei_w_word, &s->handle, + (WireCodecFunc) sanei_w_word, &ack); + + free (s); + + return status; + } + first_handle = s; *meta_handle = s; + DBG (3, "sane_open: success\n"); return SANE_STATUS_GOOD; } @@ -1658,7 +1677,7 @@ sane_get_option_descriptor (SANE_Handle handle, SANE_Int option) if (!s->options_valid) { - DBG (3, "sane_get_option_descripter: getting option descriptors\n"); + DBG (3, "sane_get_option_descriptor: getting option descriptors\n"); status = fetch_options (s); if (status != SANE_STATUS_GOOD) {