/[rdesktop]/sourceforge.net/trunk/rdesktop/parallel.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /sourceforge.net/trunk/rdesktop/parallel.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1365 - (hide annotations)
Thu Jan 4 05:39:39 2007 UTC (17 years, 6 months ago) by jsorg71
File MIME type: text/plain
File size: 4494 byte(s)
copyright year update

1 astrand 963 /* -*- c-basic-offset: 8 -*-
2     rdesktop: A Remote Desktop Protocol client.
3 jsorg71 1365 Copyright (C) Matthew Chapman 1999-2007
4 jsorg71 1364
5 astrand 963 This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9    
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13     GNU General Public License for more details.
14 jsorg71 1364
15 astrand 963 You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18     */
19 n-ki 569 #define MAX_PARALLEL_DEVICES 1
20    
21     #define FILE_DEVICE_PARALLEL 0x22
22    
23     #define IOCTL_PAR_QUERY_RAW_DEVICE_ID 0x0c
24    
25     #include "rdesktop.h"
26     #include <unistd.h>
27     #include <fcntl.h>
28 n-ki 631 #include <sys/ioctl.h>
29     #include <errno.h>
30 n-ki 569
31 stargo 632 #if defined(__linux__)
32     #include <linux/lp.h>
33     #endif
34    
35 n-ki 569 extern RDPDR_DEVICE g_rdpdr_device[];
36    
37    
38     /* Enumeration of devices from rdesktop.c */
39     /* returns numer of units found and initialized. */
40     /* optarg looks like ':LPT1=/dev/lp0' */
41     /* when it arrives to this function. */
42     int
43 astrand 608 parallel_enum_devices(uint32 * id, char *optarg)
44 n-ki 569 {
45     PARALLEL_DEVICE *ppar_info;
46    
47     char *pos = optarg;
48     char *pos2;
49     int count = 0;
50    
51 stargo 865 /* skip the first colon */
52 n-ki 569 optarg++;
53     while ((pos = next_arg(optarg, ',')) && *id < RDPDR_MAX_DEVICES)
54     {
55     ppar_info = (PARALLEL_DEVICE *) xmalloc(sizeof(PARALLEL_DEVICE));
56    
57     pos2 = next_arg(optarg, '=');
58     strcpy(g_rdpdr_device[*id].name, optarg);
59    
60 stargo 570 toupper_str(g_rdpdr_device[*id].name);
61 n-ki 569
62     g_rdpdr_device[*id].local_path = xmalloc(strlen(pos2) + 1);
63     strcpy(g_rdpdr_device[*id].local_path, pos2);
64     printf("PARALLEL %s to %s\n", optarg, pos2);
65    
66 stargo 865 /* set device type */
67 n-ki 569 g_rdpdr_device[*id].device_type = DEVICE_TYPE_PARALLEL;
68     g_rdpdr_device[*id].pdevice_data = (void *) ppar_info;
69 n-ki 631 g_rdpdr_device[*id].handle = 0;
70 n-ki 569 count++;
71     (*id)++;
72    
73     optarg = pos;
74     }
75     return count;
76     }
77    
78 jsorg71 1364 static RD_NTSTATUS
79 n-ki 592 parallel_create(uint32 device_id, uint32 access, uint32 share_mode, uint32 disposition,
80 jsorg71 1364 uint32 flags, char *filename, RD_NTHANDLE * handle)
81 n-ki 569 {
82     int parallel_fd;
83    
84 n-ki 589 parallel_fd = open(g_rdpdr_device[device_id].local_path, O_RDWR);
85 n-ki 592 if (parallel_fd == -1)
86     {
87 n-ki 589 perror("open");
88 jsorg71 1364 return RD_STATUS_ACCESS_DENIED;
89 n-ki 589 }
90 n-ki 569
91 n-ki 631 /* all read and writes should be non blocking */
92     if (fcntl(parallel_fd, F_SETFL, O_NONBLOCK) == -1)
93     perror("fcntl");
94    
95 stargo 632 #if defined(LPABORT)
96     /* Retry on errors */
97 n-ki 631 ioctl(parallel_fd, LPABORT, (int) 1);
98 stargo 632 #endif
99 n-ki 631
100 n-ki 584 g_rdpdr_device[device_id].handle = parallel_fd;
101    
102 n-ki 569 *handle = parallel_fd;
103 n-ki 592
104 jsorg71 1364 return RD_STATUS_SUCCESS;
105 n-ki 569 }
106    
107 jsorg71 1364 static RD_NTSTATUS
108     parallel_close(RD_NTHANDLE handle)
109 n-ki 569 {
110 n-ki 631 int i = get_device_index(handle);
111     if (i >= 0)
112     g_rdpdr_device[i].handle = 0;
113 n-ki 569 close(handle);
114 jsorg71 1364 return RD_STATUS_SUCCESS;
115 n-ki 569 }
116    
117 jsorg71 1364 static RD_NTSTATUS
118     parallel_read(RD_NTHANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result)
119 n-ki 589 {
120     *result = read(handle, data, length);
121 jsorg71 1364 return RD_STATUS_SUCCESS;
122 n-ki 589 }
123    
124 jsorg71 1364 static RD_NTSTATUS
125     parallel_write(RD_NTHANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result)
126 n-ki 569 {
127 jsorg71 1364 int rc = RD_STATUS_SUCCESS;
128 n-ki 631
129     int n = write(handle, data, length);
130     if (n < 0)
131     {
132 stargo 832 #if defined(LPGETSTATUS)
133 n-ki 631 int status;
134 stargo 832 #endif
135 n-ki 631
136     *result = 0;
137     switch (errno)
138     {
139     case EAGAIN:
140 jsorg71 1364 rc = RD_STATUS_DEVICE_OFF_LINE;
141 n-ki 631 case ENOSPC:
142 jsorg71 1364 rc = RD_STATUS_DEVICE_PAPER_EMPTY;
143 n-ki 631 case EIO:
144 jsorg71 1364 rc = RD_STATUS_DEVICE_OFF_LINE;
145 n-ki 631 default:
146 jsorg71 1364 rc = RD_STATUS_DEVICE_POWERED_OFF;
147 n-ki 631 }
148 stargo 632 #if defined(LPGETSTATUS)
149 n-ki 631 if (ioctl(handle, LPGETSTATUS, &status) == 0)
150     {
151     /* coming soon: take care for the printer status */
152     printf("parallel_write: status = %d, errno = %d\n", status, errno);
153     }
154 stargo 632 #endif
155 n-ki 631 }
156     *result = n;
157     return rc;
158 n-ki 569 }
159    
160 jsorg71 1364 static RD_NTSTATUS
161     parallel_device_control(RD_NTHANDLE handle, uint32 request, STREAM in, STREAM out)
162 n-ki 569 {
163     if ((request >> 16) != FILE_DEVICE_PARALLEL)
164 jsorg71 1364 return RD_STATUS_INVALID_PARAMETER;
165 n-ki 569
166     /* extract operation */
167     request >>= 2;
168     request &= 0xfff;
169    
170     printf("PARALLEL IOCTL %d: ", request);
171    
172     switch (request)
173     {
174     case IOCTL_PAR_QUERY_RAW_DEVICE_ID:
175    
176     default:
177    
178     printf("\n");
179     unimpl("UNKNOWN IOCTL %d\n", request);
180     }
181 jsorg71 1364 return RD_STATUS_SUCCESS;
182 n-ki 569 }
183    
184     DEVICE_FNS parallel_fns = {
185     parallel_create,
186     parallel_close,
187 n-ki 589 parallel_read,
188 n-ki 569 parallel_write,
189     parallel_device_control
190     };

  ViewVC Help
Powered by ViewVC 1.1.26