View | Details | Raw Unified | Return to bug 1892
Collapse All | Expand All

(-)backend/net.c (-8 / +139 lines)
Lines 105-110 Link Here
105
static int client_big_endian; /* 1 == big endian; 0 == little endian */
105
static int client_big_endian; /* 1 == big endian; 0 == little endian */
106
static int server_big_endian; /* 1 == big endian; 0 == little endian */
106
static int server_big_endian; /* 1 == big endian; 0 == little endian */
107
static int depth; /* bits per pixel */
107
static int depth; /* bits per pixel */
108
static SANE_Status sane_start1 (SANE_Handle handle);
109
static SANE_Status sane_start2 (SANE_Handle handle);
110
static SANE_Status sane_read1 (SANE_Handle handle, SANE_Byte * data, SANE_Int max_length, SANE_Int * length);
111
static SANE_Status sane_read2 (SANE_Handle handle, SANE_Byte * data, SANE_Int max_length, SANE_Int * length);
108
112
109
#ifndef NET_USES_AF_INDEP
113
#ifndef NET_USES_AF_INDEP
110
static int saned_port;
114
static int saned_port;
Lines 546-552 Link Here
546
{
550
{
547
  DBG (2, "do_cancel: %p\n", (void *) s);
551
  DBG (2, "do_cancel: %p\n", (void *) s);
548
  s->hw->auth_active = 0;
552
  s->hw->auth_active = 0;
549
  if (s->data >= 0)
553
  if (s->data >= 0) /* xxx */
550
    {
554
    {
551
      DBG (3, "do_cancel: closing data pipe\n");
555
      DBG (3, "do_cancel: closing data pipe\n");
552
      close (s->data);
556
      close (s->data);
Lines 1220-1226 Link Here
1220
  memset (s, 0, sizeof (*s));
1224
  memset (s, 0, sizeof (*s));
1221
  s->hw = dev;
1225
  s->hw = dev;
1222
  s->handle = handle;
1226
  s->handle = handle;
1223
  s->data = -1;
1227
  s->data = -1; /* xxx */
1224
  s->next = first_handle;
1228
  s->next = first_handle;
1225
  s->local_opt.desc = 0;
1229
  s->local_opt.desc = 0;
1226
  s->local_opt.num_options = 0;
1230
  s->local_opt.num_options = 0;
Lines 1278-1284 Link Here
1278
  sanei_w_call (&s->hw->wire, SANE_NET_CLOSE,
1282
  sanei_w_call (&s->hw->wire, SANE_NET_CLOSE,
1279
		(WireCodecFunc) sanei_w_word, &s->handle,
1283
		(WireCodecFunc) sanei_w_word, &s->handle,
1280
		(WireCodecFunc) sanei_w_word, &ack);
1284
		(WireCodecFunc) sanei_w_word, &ack);
1281
  if (s->data >= 0)
1285
  if (s->data >= 0) /* xxx */
1282
    {
1286
    {
1283
      DBG (2, "sane_close: closing data pipe\n");
1287
      DBG (2, "sane_close: closing data pipe\n");
1284
      close (s->data);
1288
      close (s->data);
Lines 1457-1466 Link Here
1457
  return status;
1461
  return status;
1458
}
1462
}
1459
1463
1460
#ifdef NET_USES_AF_INDEP
1464
1461
SANE_Status
1465
SANE_Status
1462
sane_start (SANE_Handle handle)
1466
sane_start (SANE_Handle handle)
1463
{
1467
{
1468
    if (0) /* fixme */
1469
      {
1470
	return sane_start1(handle);
1471
      } 
1472
    else 
1473
      {
1474
	return sane_start2(handle);
1475
      }
1476
}
1477
1478
1479
#ifdef NET_USES_AF_INDEP
1480
static SANE_Status
1481
sane_start1 (SANE_Handle handle)
1482
{
1464
  Net_Scanner *s = handle;
1483
  Net_Scanner *s = handle;
1465
  SANE_Start_Reply reply;
1484
  SANE_Start_Reply reply;
1466
  struct sockaddr_in sin;
1485
  struct sockaddr_in sin;
Lines 1588-1594 Link Here
1588
      return SANE_STATUS_IO_ERROR;
1607
      return SANE_STATUS_IO_ERROR;
1589
    }
1608
    }
1590
  shutdown (fd, 1);
1609
  shutdown (fd, 1);
1591
  s->data = fd;
1610
  s->data = fd; /* xxx */
1592
  s->reclen_buf_offset = 0;
1611
  s->reclen_buf_offset = 0;
1593
  s->bytes_remaining = 0;
1612
  s->bytes_remaining = 0;
1594
  DBG (3, "sane_start: done (%s)\n", sane_strstatus (status));
1613
  DBG (3, "sane_start: done (%s)\n", sane_strstatus (status));
Lines 1597-1604 Link Here
1597
1616
1598
#else /* !NET_USES_AF_INDEP */
1617
#else /* !NET_USES_AF_INDEP */
1599
1618
1600
SANE_Status
1619
static SANE_Status
1601
sane_start (SANE_Handle handle)
1620
sane_start1 (SANE_Handle handle)
1602
{
1621
{
1603
  Net_Scanner *s = handle;
1622
  Net_Scanner *s = handle;
1604
  SANE_Start_Reply reply;
1623
  SANE_Start_Reply reply;
Lines 1704-1713 Link Here
1704
#endif /* NET_USES_AF_INDEP */
1723
#endif /* NET_USES_AF_INDEP */
1705
1724
1706
1725
1726
static SANE_Status
1727
sane_start2 (SANE_Handle handle)
1728
{
1729
  Net_Scanner *s = handle;
1730
  SANE_Start2_Reply reply;
1731
  SANE_Status status;
1732
  int need_auth;
1733
1734
  DBG (3, "sane_start2\n");
1735
  
1736
  hang_over = -1;
1737
  left_over = -1;
1738
  
1739
  DBG (3, "sane_start2: remote start\n");
1740
  sanei_w_call (&s->hw->wire, SANE_NET_START2,
1741
		(WireCodecFunc) sanei_w_word, &s->handle,
1742
		(WireCodecFunc) sanei_w_start2_reply, &reply);
1743
  do
1744
    {
1745
      status = reply.status;
1746
      if (reply.byte_order == 0x1234)
1747
	{
1748
	  server_big_endian = 0;
1749
	  DBG (1, "sane_start2: server has little endian byte order\n");
1750
	}
1751
      else
1752
	{
1753
	  server_big_endian = 1;
1754
	  DBG (1, "sane_start2: server has big endian byte order\n");
1755
	}
1756
1757
      need_auth = (reply.resource_to_authorize != 0);
1758
      if (need_auth)
1759
	{
1760
	  DBG (3, "sane_start2: auth required\n");
1761
	  do_authorization (s->hw, reply.resource_to_authorize);
1762
1763
	  sanei_w_free (&s->hw->wire,
1764
			(WireCodecFunc) sanei_w_start2_reply, &reply);
1765
1766
	  sanei_w_set_dir (&s->hw->wire, WIRE_DECODE);
1767
1768
	  sanei_w_start2_reply (&s->hw->wire, &reply);
1769
1770
	  continue;
1771
	}
1772
      sanei_w_free (&s->hw->wire, (WireCodecFunc) sanei_w_start2_reply,
1773
		    &reply);
1774
      if (need_auth && !s->hw->auth_active)
1775
	return SANE_STATUS_CANCELLED;
1776
1777
      if (status != SANE_STATUS_GOOD)
1778
	{
1779
	  DBG (1, "sane_start: remote start failed (%s)\n",
1780
	       sane_strstatus (status));
1781
	  return status;
1782
	}
1783
    }
1784
  while (need_auth);
1785
  DBG (3, "sane_start2: remote start2 finished\n");
1786
  s->reclen_buf_offset = 0;
1787
  s->bytes_remaining = 0;
1788
  DBG (3, "sane_start2: done (%s)\n", sane_strstatus (status));
1789
  return status;
1790
}
1791
1792
1793
1707
SANE_Status
1794
SANE_Status
1708
sane_read (SANE_Handle handle, SANE_Byte * data, SANE_Int max_length,
1795
sane_read (SANE_Handle handle, SANE_Byte * data, SANE_Int max_length,
1709
	   SANE_Int * length)
1796
	   SANE_Int * length)
1710
{
1797
{
1798
  if (0) /* FIXME */
1799
    {
1800
      return sane_read1(handle, data, max_length, length);
1801
    }
1802
  else
1803
    {
1804
      return sane_read2(handle, data, max_length, length);
1805
    }
1806
1807
}
1808
1809
1810
static SANE_Status
1811
sane_read2 (SANE_Handle handle, SANE_Byte * data, SANE_Int max_length,
1812
	   SANE_Int * length)
1813
{
1814
  Net_Scanner *s = handle;
1815
  SANE_Read_Reply reply;
1816
1817
  DBG (3, "sane_read2\n");
1818
1819
  sanei_w_call (&s->hw->wire, SANE_NET_READ,
1820
		(WireCodecFunc) sanei_w_word, &s->handle, 
1821
		(WireCodecFunc) sanei_w_read_reply, &reply);
1822
1823
  DBG (3, "sane_read2 result:%s|\n", reply.data);
1824
  /* Funkar!!! */
1825
1826
  return 0; /* FIXME */
1827
}
1828
1829
1830
static SANE_Status
1831
sane_read1 (SANE_Handle handle, SANE_Byte * data, SANE_Int max_length,
1832
	   SANE_Int * length)
1833
{
1711
  Net_Scanner *s = handle;
1834
  Net_Scanner *s = handle;
1712
  ssize_t nread;
1835
  ssize_t nread;
1713
  SANE_Int cnt;
1836
  SANE_Int cnt;
Lines 1746-1752 Link Here
1746
	}
1869
	}
1747
    }
1870
    }
1748
1871
1749
  if (s->data < 0)
1872
  if (s->data < 0) /* xxx */
1750
    {
1873
    {
1751
      DBG (1, "sane_read: data pipe doesn't exist, scan cancelled?\n");
1874
      DBG (1, "sane_read: data pipe doesn't exist, scan cancelled?\n");
1752
      return SANE_STATUS_CANCELLED;
1875
      return SANE_STATUS_CANCELLED;
Lines 1757-1762 Link Here
1757
      /* boy, is this painful or what? */
1880
      /* boy, is this painful or what? */
1758
      
1881
      
1759
      DBG (4, "sane_read: reading paket length\n");
1882
      DBG (4, "sane_read: reading paket length\n");
1883
      /* xxx */
1760
      nread = read (s->data, s->reclen_buf + s->reclen_buf_offset,
1884
      nread = read (s->data, s->reclen_buf + s->reclen_buf_offset,
1761
		    4 - s->reclen_buf_offset);
1885
		    4 - s->reclen_buf_offset);
1762
      if (nread < 0)
1886
      if (nread < 0)
Lines 1797-1805 Link Here
1797
	  DBG (2, "sane_read: received error signal\n");
1921
	  DBG (2, "sane_read: received error signal\n");
1798
1922
1799
	  /* turn off non-blocking I/O (s->data will be closed anyhow): */
1923
	  /* turn off non-blocking I/O (s->data will be closed anyhow): */
1924
	  /* xxx */
1800
	  fcntl (s->data, F_SETFL, 0);
1925
	  fcntl (s->data, F_SETFL, 0);
1801
1926
1802
	  /* read the status byte: */
1927
	  /* read the status byte: */
1928
	  /* xxx */
1803
	  if (read (s->data, &ch, sizeof (ch)) != 1)
1929
	  if (read (s->data, &ch, sizeof (ch)) != 1)
1804
	    {
1930
	    {
1805
	      DBG (1, "sane_read: failed to read error code\n");
1931
	      DBG (1, "sane_read: failed to read error code\n");
Lines 1815-1820 Link Here
1815
  if (max_length > (SANE_Int) s->bytes_remaining)
1941
  if (max_length > (SANE_Int) s->bytes_remaining)
1816
    max_length = s->bytes_remaining;
1942
    max_length = s->bytes_remaining;
1817
1943
1944
  /* xxx */
1818
  nread = read (s->data, data, max_length);
1945
  nread = read (s->data, data, max_length);
1819
  
1946
  
1820
  if (nread < 0)
1947
  if (nread < 0)
Lines 1945-1956 Link Here
1945
  Net_Scanner *s = handle;
2072
  Net_Scanner *s = handle;
1946
2073
1947
  DBG (3, "sane_set_io_mode: non_blocking = %d\n", non_blocking);
2074
  DBG (3, "sane_set_io_mode: non_blocking = %d\n", non_blocking);
2075
  /* xxx */
1948
  if (s->data < 0)
2076
  if (s->data < 0)
1949
    {
2077
    {
1950
      DBG (1, "sane_set_io_mode: pipe doesn't exist\n");
2078
      DBG (1, "sane_set_io_mode: pipe doesn't exist\n");
1951
      return SANE_STATUS_INVAL;
2079
      return SANE_STATUS_INVAL;
1952
    }
2080
    }
1953
2081
2082
  /* xxx */
1954
  if (fcntl (s->data, F_SETFL, non_blocking ? O_NONBLOCK : 0) < 0)
2083
  if (fcntl (s->data, F_SETFL, non_blocking ? O_NONBLOCK : 0) < 0)
1955
    {
2084
    {
1956
      DBG (1, "sane_set_io_mode: fcntl failed (%s)\n", strerror (errno));
2085
      DBG (1, "sane_set_io_mode: fcntl failed (%s)\n", strerror (errno));
Lines 1967-1978 Link Here
1967
2096
1968
  DBG (3, "sane_get_select_fd\n");
2097
  DBG (3, "sane_get_select_fd\n");
1969
2098
2099
  /* xxx */
1970
  if (s->data < 0)
2100
  if (s->data < 0)
1971
    {
2101
    {
1972
      DBG (1, "sane_get_select_fd: pipe doesn't exist\n");
2102
      DBG (1, "sane_get_select_fd: pipe doesn't exist\n");
1973
      return SANE_STATUS_INVAL;
2103
      return SANE_STATUS_INVAL;
1974
    }
2104
    }
1975
2105
2106
  /* xxx */
1976
  *fd = s->data;
2107
  *fd = s->data;
1977
  DBG (3, "sane_get_select_fd: done; *fd = %d\n", *fd);
2108
  DBG (3, "sane_get_select_fd: done; *fd = %d\n", *fd);
1978
  return SANE_STATUS_GOOD;
2109
  return SANE_STATUS_GOOD;
(-)frontend/saned.c (+74 lines)
Lines 319-324 Link Here
319
      }
319
      }
320
      break;
320
      break;
321
321
322
    case SANE_NET_START2:
323
      {
324
	SANE_Start2_Reply reply;
325
326
	memset (&reply, 0, sizeof (reply));
327
	reply.resource_to_authorize = (char *) res;
328
	sanei_w_reply (&wire, (WireCodecFunc) sanei_w_start2_reply, &reply);
329
      }
330
      break;
331
322
    default:
332
    default:
323
      DBG (DBG_WARN, 
333
      DBG (DBG_WARN, 
324
	   "auth_callback: called for unexpected request %d (resource=%s)\n",
334
	   "auth_callback: called for unexpected request %d (resource=%s)\n",
Lines 1790-1795 Link Here
1790
	    else
1800
	    else
1791
	      {
1801
	      {
1792
		handle[h].handle = be_handle;
1802
		handle[h].handle = be_handle;
1803
		DBG (DBG_MSG, "process_request: sane_open returning handle: %p\n", h);
1793
		reply.handle = h;
1804
		reply.handle = h;
1794
	      }
1805
	      }
1795
	  }
1806
	  }
Lines 2004-2009 Link Here
2004
	    do_scan (w, h, data_fd);
2015
	    do_scan (w, h, data_fd);
2005
	    close (data_fd);
2016
	    close (data_fd);
2006
	  }
2017
	  }
2018
	  }
2019
      break;
2020
2021
    case SANE_NET_START2:
2022
      {
2023
	SANE_Start2_Reply reply;
2024
2025
	h = decode_handle (w, "start2");
2026
	if (h < 0)
2027
	  return;
2028
2029
	memset (&reply, 0, sizeof (reply));	/* avoid leaking bits */
2030
	reply.byte_order = SANE_NET_LITTLE_ENDIAN;
2031
	if (byte_order.w != 1)
2032
	  reply.byte_order = SANE_NET_BIG_ENDIAN;
2033
2034
	if (handle[h].scanning)
2035
	  reply.status = SANE_STATUS_DEVICE_BUSY;
2036
	else
2037
	  {
2038
	    reply.status = sane_start (handle[h].handle);
2039
	  }
2040
2041
	sanei_w_reply (w, (WireCodecFunc) sanei_w_start2_reply, &reply);
2042
	if (reply.status == SANE_STATUS_GOOD)
2043
	  {
2044
	    /* ev. göra detta innan jag skickar svaret */
2045
	    handle[h].scanning = 1;
2046
	    handle[h].docancel = 0;
2047
	    /* göra motsvarighet till do_scan  */
2048
	  }
2049
      }
2050
      break;
2051
2052
    case SANE_NET_READ:
2053
      {
2054
	SANE_Read_Reply reply;
2055
	SANE_Handle be_handle = handle[h].handle;
2056
2057
	DBG (DBG_MSG, "process_request: SANE_NET_READ !!!!!!!!!!!!!!!!!!\n");
2058
2059
	h = decode_handle (w, "read");
2060
	if (h < 0)
2061
	  return;
2062
2063
	DBG (DBG_MSG, "process_request: handle is %p\n", h);
2064
	memset (&reply, 0, sizeof (reply));	/* avoid leaking bits */
2065
2066
#if 0
2067
	DBG (DBG_INFO,
2068
	     "do_scan: trying to read %d bytes from scanner\n", nbytes);
2069
	status = sane_read (be_handle, buf + reader, nbytes, &length);
2070
	DBG (DBG_INFO,
2071
	     "do_scan: read %d bytes from scanner\n", length);
2072
#endif
2073
	
2074
	/* behöver sätta status, len och data. */
2075
	reply.status == SANE_STATUS_GOOD; /* xxx, tillfällig */
2076
	reply.len = 8;
2077
	reply.data = "abcdefg\0";
2078
2079
	sanei_w_reply (w, (WireCodecFunc) sanei_w_read_reply, &reply);
2080
2007
      }
2081
      }
2008
      break;
2082
      break;
2009
2083
(-)include/sane/sanei_net.h (-1 / +21 lines)
Lines 41-47 Link Here
41
    SANE_NET_START,
41
    SANE_NET_START,
42
    SANE_NET_CANCEL,
42
    SANE_NET_CANCEL,
43
    SANE_NET_AUTHORIZE,
43
    SANE_NET_AUTHORIZE,
44
    SANE_NET_EXIT
44
    SANE_NET_EXIT,
45
    SANE_NET_START2,
46
    SANE_NET_READ
45
  }
47
  }
46
SANE_Net_Procedure_Number;
48
SANE_Net_Procedure_Number;
47
49
Lines 121-126 Link Here
121
123
122
typedef struct
124
typedef struct
123
  {
125
  {
126
    SANE_Status status;
127
    SANE_Word byte_order;
128
    SANE_String resource_to_authorize;
129
  }
130
SANE_Start2_Reply;
131
132
typedef struct
133
  {
134
    SANE_Status status;
135
    SANE_Word len;
136
    SANE_Byte *data;
137
  }
138
SANE_Read_Reply;
139
140
typedef struct
141
  {
124
    SANE_String resource;
142
    SANE_String resource;
125
    SANE_String username;
143
    SANE_String username;
126
    SANE_String password;
144
    SANE_String password;
Lines 139-144 Link Here
139
extern void sanei_w_get_parameters_reply (Wire *w,
157
extern void sanei_w_get_parameters_reply (Wire *w,
140
					  SANE_Get_Parameters_Reply *reply);
158
					  SANE_Get_Parameters_Reply *reply);
141
extern void sanei_w_start_reply (Wire *w, SANE_Start_Reply *reply);
159
extern void sanei_w_start_reply (Wire *w, SANE_Start_Reply *reply);
160
extern void sanei_w_start2_reply (Wire *w, SANE_Start2_Reply *reply);
161
extern void sanei_w_read_reply (Wire *w, SANE_Read_Reply *reply);
142
extern void sanei_w_authorization_req (Wire *w, SANE_Authorization_Req *req);
162
extern void sanei_w_authorization_req (Wire *w, SANE_Authorization_Req *req);
143
163
144
#endif /* sanei_net_h */
164
#endif /* sanei_net_h */
(-)sanei/sanei_net.c (+29 lines)
Lines 177-182 Link Here
177
}
177
}
178
178
179
void
179
void
180
sanei_w_start2_reply (Wire *w, SANE_Start2_Reply *reply)
181
{
182
  sanei_w_status (w, &reply->status);
183
  sanei_w_word (w, &reply->byte_order);
184
  sanei_w_string (w, &reply->resource_to_authorize);
185
}
186
187
void
188
sanei_w_read_reply (Wire *w, SANE_Read_Reply *reply)
189
{
190
  sanei_w_status (w, &reply->status);
191
#if 0
192
  //sanei_w_word (w, &reply->len);
193
  //sanei_w_string (w, &reply->resource_to_authorize); // XXX
194
  //sanei_w_array (w, &len, value, w_value, element_size); // känns overkill...
195
  // xxx, kan ju kolla hur string funkar. Svar: använda w_array, som i
196
  // sin tur kodar varje tecken för sig! Suck. Jaja, låt oss också
197
  // göra det just nu: Loopa över varje tecken. 
198
  // Eller kan man använda w_ptr? Eller w_space? 
199
  // Titta också på hur interfacet till sane_read() ser ut. 
200
201
  // saned översätter från sane_read() till Wire. libnet översätter
202
  // från Wire till annat, väl? 
203
  // Nja, det är nog w_array oc Bytes vi ska välja! 
204
#endif
205
  sanei_w_array (w, &reply->len, (void **)&reply->data, (WireCodecFunc)sanei_w_byte, 1);
206
}
207
208
void
180
sanei_w_authorization_req (Wire *w, SANE_Authorization_Req *req)
209
sanei_w_authorization_req (Wire *w, SANE_Authorization_Req *req)
181
{
210
{
182
  sanei_w_string (w, &req->resource);
211
  sanei_w_string (w, &req->resource);

Return to bug 1892