Bugzilla – Attachment 217 Details for
Bug 1892
Scanner redirection based on the SANE network protocol
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Half-finished patch against SANE CVS for data port elimination
net-read1.patch (text/plain), 12.28 KB, created by
Peter Åstrand
on 2006-10-26 11:34:13 CEST
(
hide
)
Description:
Half-finished patch against SANE CVS for data port elimination
Filename:
MIME Type:
Creator:
Peter Åstrand
Created:
2006-10-26 11:34:13 CEST
Size:
12.28 KB
patch
obsolete
>? cleaninst.sh >? myconfigure.sh >? net-read1.patch >? tosandy >? backend/net.c.hack >? backend/snapscan.txt >? frontend/saned.c.hack >? sanei/sanei_net.c.hack >Index: backend/net.c >=================================================================== >RCS file: /cvsroot/sane/sane-backends/backend/net.c,v >retrieving revision 1.29 >diff -u -r1.29 net.c >--- backend/net.c 3 Oct 2004 17:34:36 -0000 1.29 >+++ backend/net.c 26 Oct 2006 09:12:27 -0000 >@@ -105,6 +105,10 @@ > static int client_big_endian; /* 1 == big endian; 0 == little endian */ > static int server_big_endian; /* 1 == big endian; 0 == little endian */ > static int depth; /* bits per pixel */ >+static SANE_Status sane_start1 (SANE_Handle handle); >+static SANE_Status sane_start2 (SANE_Handle handle); >+static SANE_Status sane_read1 (SANE_Handle handle, SANE_Byte * data, SANE_Int max_length, SANE_Int * length); >+static SANE_Status sane_read2 (SANE_Handle handle, SANE_Byte * data, SANE_Int max_length, SANE_Int * length); > > #ifndef NET_USES_AF_INDEP > static int saned_port; >@@ -546,7 +550,7 @@ > { > DBG (2, "do_cancel: %p\n", (void *) s); > s->hw->auth_active = 0; >- if (s->data >= 0) >+ if (s->data >= 0) /* xxx */ > { > DBG (3, "do_cancel: closing data pipe\n"); > close (s->data); >@@ -1220,7 +1224,7 @@ > memset (s, 0, sizeof (*s)); > s->hw = dev; > s->handle = handle; >- s->data = -1; >+ s->data = -1; /* xxx */ > s->next = first_handle; > s->local_opt.desc = 0; > s->local_opt.num_options = 0; >@@ -1278,7 +1282,7 @@ > sanei_w_call (&s->hw->wire, SANE_NET_CLOSE, > (WireCodecFunc) sanei_w_word, &s->handle, > (WireCodecFunc) sanei_w_word, &ack); >- if (s->data >= 0) >+ if (s->data >= 0) /* xxx */ > { > DBG (2, "sane_close: closing data pipe\n"); > close (s->data); >@@ -1457,10 +1461,25 @@ > return status; > } > >-#ifdef NET_USES_AF_INDEP >+ > SANE_Status > sane_start (SANE_Handle handle) > { >+ if (0) /* fixme */ >+ { >+ return sane_start1(handle); >+ } >+ else >+ { >+ return sane_start2(handle); >+ } >+} >+ >+ >+#ifdef NET_USES_AF_INDEP >+static SANE_Status >+sane_start1 (SANE_Handle handle) >+{ > Net_Scanner *s = handle; > SANE_Start_Reply reply; > struct sockaddr_in sin; >@@ -1588,7 +1607,7 @@ > return SANE_STATUS_IO_ERROR; > } > shutdown (fd, 1); >- s->data = fd; >+ s->data = fd; /* xxx */ > s->reclen_buf_offset = 0; > s->bytes_remaining = 0; > DBG (3, "sane_start: done (%s)\n", sane_strstatus (status)); >@@ -1597,8 +1616,8 @@ > > #else /* !NET_USES_AF_INDEP */ > >-SANE_Status >-sane_start (SANE_Handle handle) >+static SANE_Status >+sane_start1 (SANE_Handle handle) > { > Net_Scanner *s = handle; > SANE_Start_Reply reply; >@@ -1704,10 +1723,114 @@ > #endif /* NET_USES_AF_INDEP */ > > >+static SANE_Status >+sane_start2 (SANE_Handle handle) >+{ >+ Net_Scanner *s = handle; >+ SANE_Start2_Reply reply; >+ SANE_Status status; >+ int need_auth; >+ >+ DBG (3, "sane_start2\n"); >+ >+ hang_over = -1; >+ left_over = -1; >+ >+ DBG (3, "sane_start2: remote start\n"); >+ sanei_w_call (&s->hw->wire, SANE_NET_START2, >+ (WireCodecFunc) sanei_w_word, &s->handle, >+ (WireCodecFunc) sanei_w_start2_reply, &reply); >+ do >+ { >+ status = reply.status; >+ if (reply.byte_order == 0x1234) >+ { >+ server_big_endian = 0; >+ DBG (1, "sane_start2: server has little endian byte order\n"); >+ } >+ else >+ { >+ server_big_endian = 1; >+ DBG (1, "sane_start2: server has big endian byte order\n"); >+ } >+ >+ need_auth = (reply.resource_to_authorize != 0); >+ if (need_auth) >+ { >+ DBG (3, "sane_start2: auth required\n"); >+ do_authorization (s->hw, reply.resource_to_authorize); >+ >+ sanei_w_free (&s->hw->wire, >+ (WireCodecFunc) sanei_w_start2_reply, &reply); >+ >+ sanei_w_set_dir (&s->hw->wire, WIRE_DECODE); >+ >+ sanei_w_start2_reply (&s->hw->wire, &reply); >+ >+ continue; >+ } >+ sanei_w_free (&s->hw->wire, (WireCodecFunc) sanei_w_start2_reply, >+ &reply); >+ if (need_auth && !s->hw->auth_active) >+ return SANE_STATUS_CANCELLED; >+ >+ if (status != SANE_STATUS_GOOD) >+ { >+ DBG (1, "sane_start: remote start failed (%s)\n", >+ sane_strstatus (status)); >+ return status; >+ } >+ } >+ while (need_auth); >+ DBG (3, "sane_start2: remote start2 finished\n"); >+ s->reclen_buf_offset = 0; >+ s->bytes_remaining = 0; >+ DBG (3, "sane_start2: done (%s)\n", sane_strstatus (status)); >+ return status; >+} >+ >+ >+ > SANE_Status > sane_read (SANE_Handle handle, SANE_Byte * data, SANE_Int max_length, > SANE_Int * length) > { >+ if (0) /* FIXME */ >+ { >+ return sane_read1(handle, data, max_length, length); >+ } >+ else >+ { >+ return sane_read2(handle, data, max_length, length); >+ } >+ >+} >+ >+ >+static SANE_Status >+sane_read2 (SANE_Handle handle, SANE_Byte * data, SANE_Int max_length, >+ SANE_Int * length) >+{ >+ Net_Scanner *s = handle; >+ SANE_Read_Reply reply; >+ >+ DBG (3, "sane_read2\n"); >+ >+ sanei_w_call (&s->hw->wire, SANE_NET_READ, >+ (WireCodecFunc) sanei_w_word, &s->handle, >+ (WireCodecFunc) sanei_w_read_reply, &reply); >+ >+ DBG (3, "sane_read2 result:%s|\n", reply.data); >+ /* Funkar!!! */ >+ >+ return 0; /* FIXME */ >+} >+ >+ >+static SANE_Status >+sane_read1 (SANE_Handle handle, SANE_Byte * data, SANE_Int max_length, >+ SANE_Int * length) >+{ > Net_Scanner *s = handle; > ssize_t nread; > SANE_Int cnt; >@@ -1746,7 +1869,7 @@ > } > } > >- if (s->data < 0) >+ if (s->data < 0) /* xxx */ > { > DBG (1, "sane_read: data pipe doesn't exist, scan cancelled?\n"); > return SANE_STATUS_CANCELLED; >@@ -1757,6 +1880,7 @@ > /* boy, is this painful or what? */ > > DBG (4, "sane_read: reading paket length\n"); >+ /* xxx */ > nread = read (s->data, s->reclen_buf + s->reclen_buf_offset, > 4 - s->reclen_buf_offset); > if (nread < 0) >@@ -1797,9 +1921,11 @@ > DBG (2, "sane_read: received error signal\n"); > > /* turn off non-blocking I/O (s->data will be closed anyhow): */ >+ /* xxx */ > fcntl (s->data, F_SETFL, 0); > > /* read the status byte: */ >+ /* xxx */ > if (read (s->data, &ch, sizeof (ch)) != 1) > { > DBG (1, "sane_read: failed to read error code\n"); >@@ -1815,6 +1941,7 @@ > if (max_length > (SANE_Int) s->bytes_remaining) > max_length = s->bytes_remaining; > >+ /* xxx */ > nread = read (s->data, data, max_length); > > if (nread < 0) >@@ -1945,12 +2072,14 @@ > Net_Scanner *s = handle; > > DBG (3, "sane_set_io_mode: non_blocking = %d\n", non_blocking); >+ /* xxx */ > if (s->data < 0) > { > DBG (1, "sane_set_io_mode: pipe doesn't exist\n"); > return SANE_STATUS_INVAL; > } > >+ /* xxx */ > if (fcntl (s->data, F_SETFL, non_blocking ? O_NONBLOCK : 0) < 0) > { > DBG (1, "sane_set_io_mode: fcntl failed (%s)\n", strerror (errno)); >@@ -1967,12 +2096,14 @@ > > DBG (3, "sane_get_select_fd\n"); > >+ /* xxx */ > if (s->data < 0) > { > DBG (1, "sane_get_select_fd: pipe doesn't exist\n"); > return SANE_STATUS_INVAL; > } > >+ /* xxx */ > *fd = s->data; > DBG (3, "sane_get_select_fd: done; *fd = %d\n", *fd); > return SANE_STATUS_GOOD; >Index: frontend/saned.c >=================================================================== >RCS file: /cvsroot/sane/sane-backends/frontend/saned.c,v >retrieving revision 1.40 >diff -u -r1.40 saned.c >--- frontend/saned.c 9 Apr 2006 10:07:18 -0000 1.40 >+++ frontend/saned.c 26 Oct 2006 09:12:27 -0000 >@@ -319,6 +319,16 @@ > } > break; > >+ case SANE_NET_START2: >+ { >+ SANE_Start2_Reply reply; >+ >+ memset (&reply, 0, sizeof (reply)); >+ reply.resource_to_authorize = (char *) res; >+ sanei_w_reply (&wire, (WireCodecFunc) sanei_w_start2_reply, &reply); >+ } >+ break; >+ > default: > DBG (DBG_WARN, > "auth_callback: called for unexpected request %d (resource=%s)\n", >@@ -1790,6 +1800,7 @@ > else > { > handle[h].handle = be_handle; >+ DBG (DBG_MSG, "process_request: sane_open returning handle: %p\n", h); > reply.handle = h; > } > } >@@ -2004,6 +2015,69 @@ > do_scan (w, h, data_fd); > close (data_fd); > } >+ } >+ break; >+ >+ case SANE_NET_START2: >+ { >+ SANE_Start2_Reply reply; >+ >+ h = decode_handle (w, "start2"); >+ if (h < 0) >+ return; >+ >+ memset (&reply, 0, sizeof (reply)); /* avoid leaking bits */ >+ reply.byte_order = SANE_NET_LITTLE_ENDIAN; >+ if (byte_order.w != 1) >+ reply.byte_order = SANE_NET_BIG_ENDIAN; >+ >+ if (handle[h].scanning) >+ reply.status = SANE_STATUS_DEVICE_BUSY; >+ else >+ { >+ reply.status = sane_start (handle[h].handle); >+ } >+ >+ sanei_w_reply (w, (WireCodecFunc) sanei_w_start2_reply, &reply); >+ if (reply.status == SANE_STATUS_GOOD) >+ { >+ /* ev. göra detta innan jag skickar svaret */ >+ handle[h].scanning = 1; >+ handle[h].docancel = 0; >+ /* göra motsvarighet till do_scan */ >+ } >+ } >+ break; >+ >+ case SANE_NET_READ: >+ { >+ SANE_Read_Reply reply; >+ SANE_Handle be_handle = handle[h].handle; >+ >+ DBG (DBG_MSG, "process_request: SANE_NET_READ !!!!!!!!!!!!!!!!!!\n"); >+ >+ h = decode_handle (w, "read"); >+ if (h < 0) >+ return; >+ >+ DBG (DBG_MSG, "process_request: handle is %p\n", h); >+ memset (&reply, 0, sizeof (reply)); /* avoid leaking bits */ >+ >+#if 0 >+ DBG (DBG_INFO, >+ "do_scan: trying to read %d bytes from scanner\n", nbytes); >+ status = sane_read (be_handle, buf + reader, nbytes, &length); >+ DBG (DBG_INFO, >+ "do_scan: read %d bytes from scanner\n", length); >+#endif >+ >+ /* behöver sätta status, len och data. */ >+ reply.status == SANE_STATUS_GOOD; /* xxx, tillfällig */ >+ reply.len = 8; >+ reply.data = "abcdefg\0"; >+ >+ sanei_w_reply (w, (WireCodecFunc) sanei_w_read_reply, &reply); >+ > } > break; > >Index: include/sane/sanei_net.h >=================================================================== >RCS file: /cvsroot/sane/sane-backends/include/sane/sanei_net.h,v >retrieving revision 1.1.1.1 >diff -u -r1.1.1.1 sanei_net.h >--- include/sane/sanei_net.h 9 Aug 1999 18:05:43 -0000 1.1.1.1 >+++ include/sane/sanei_net.h 26 Oct 2006 09:12:27 -0000 >@@ -41,7 +41,9 @@ > SANE_NET_START, > SANE_NET_CANCEL, > SANE_NET_AUTHORIZE, >- SANE_NET_EXIT >+ SANE_NET_EXIT, >+ SANE_NET_START2, >+ SANE_NET_READ > } > SANE_Net_Procedure_Number; > >@@ -121,6 +123,22 @@ > > typedef struct > { >+ SANE_Status status; >+ SANE_Word byte_order; >+ SANE_String resource_to_authorize; >+ } >+SANE_Start2_Reply; >+ >+typedef struct >+ { >+ SANE_Status status; >+ SANE_Word len; >+ SANE_Byte *data; >+ } >+SANE_Read_Reply; >+ >+typedef struct >+ { > SANE_String resource; > SANE_String username; > SANE_String password; >@@ -139,6 +157,8 @@ > extern void sanei_w_get_parameters_reply (Wire *w, > SANE_Get_Parameters_Reply *reply); > extern void sanei_w_start_reply (Wire *w, SANE_Start_Reply *reply); >+extern void sanei_w_start2_reply (Wire *w, SANE_Start2_Reply *reply); >+extern void sanei_w_read_reply (Wire *w, SANE_Read_Reply *reply); > extern void sanei_w_authorization_req (Wire *w, SANE_Authorization_Req *req); > > #endif /* sanei_net_h */ >Index: sanei/sanei_net.c >=================================================================== >RCS file: /cvsroot/sane/sane-backends/sanei/sanei_net.c,v >retrieving revision 1.3 >diff -u -r1.3 sanei_net.c >--- sanei/sanei_net.c 13 May 2001 16:16:59 -0000 1.3 >+++ sanei/sanei_net.c 26 Oct 2006 09:12:27 -0000 >@@ -177,6 +177,35 @@ > } > > void >+sanei_w_start2_reply (Wire *w, SANE_Start2_Reply *reply) >+{ >+ sanei_w_status (w, &reply->status); >+ sanei_w_word (w, &reply->byte_order); >+ sanei_w_string (w, &reply->resource_to_authorize); >+} >+ >+void >+sanei_w_read_reply (Wire *w, SANE_Read_Reply *reply) >+{ >+ sanei_w_status (w, &reply->status); >+#if 0 >+ //sanei_w_word (w, &reply->len); >+ //sanei_w_string (w, &reply->resource_to_authorize); // XXX >+ //sanei_w_array (w, &len, value, w_value, element_size); // känns overkill... >+ // xxx, kan ju kolla hur string funkar. Svar: använda w_array, som i >+ // sin tur kodar varje tecken för sig! Suck. Jaja, lÃÂ¥t oss ocksÃÂ¥ >+ // göra det just nu: Loopa över varje tecken. >+ // Eller kan man använda w_ptr? Eller w_space? >+ // Titta ocksÃÂ¥ pÃÂ¥ hur interfacet till sane_read() ser ut. >+ >+ // saned översätter frÃÂ¥n sane_read() till Wire. libnet översätter >+ // frÃÂ¥n Wire till annat, väl? >+ // Nja, det är nog w_array oc Bytes vi ska välja! >+#endif >+ sanei_w_array (w, &reply->len, (void **)&reply->data, (WireCodecFunc)sanei_w_byte, 1); >+} >+ >+void > sanei_w_authorization_req (Wire *w, SANE_Authorization_Req *req) > { > sanei_w_string (w, &req->resource);
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 1892
: 217