VirtualBox

source: vbox/trunk/src/VBox/RDP/client-1.8.4/parallel.c@ 77801

Last change on this file since 77801 was 55123, checked in by vboxsync, 10 years ago

rdesktop 1.8.3 modified for VBox

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.8 KB
Line 
1/* -*- c-basic-offset: 8 -*-
2 rdesktop: A Remote Desktop Protocol client.
3 Copyright (C) Matthew Chapman <matthewc.unsw.edu.au> 1999-2008
4
5 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 3 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
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19/*
20 * Oracle GPL Disclaimer: For the avoidance of doubt, except that if any license choice
21 * other than GPL or LGPL is available it will apply instead, Oracle elects to use only
22 * the General Public License version 2 (GPLv2) at this time for any software where
23 * a choice of GPL license versions is made available with the language indicating
24 * that GPLv2 or any later version may be used, or where a choice of which version
25 * of the GPL is applied is otherwise unspecified.
26 */
27
28#define MAX_PARALLEL_DEVICES 1
29
30#define FILE_DEVICE_PARALLEL 0x22
31
32#define IOCTL_PAR_QUERY_RAW_DEVICE_ID 0x0c
33
34#include "rdesktop.h"
35#include <unistd.h>
36#include <fcntl.h>
37#include <sys/ioctl.h>
38#include <errno.h>
39
40#if defined(__linux__)
41#include <linux/lp.h>
42#endif
43
44extern RDPDR_DEVICE g_rdpdr_device[];
45
46
47/* Enumeration of devices from rdesktop.c */
48/* returns numer of units found and initialized. */
49/* optarg looks like ':LPT1=/dev/lp0' */
50/* when it arrives to this function. */
51int
52parallel_enum_devices(uint32 * id, char *optarg)
53{
54 PARALLEL_DEVICE *ppar_info;
55
56 char *pos = optarg;
57 char *pos2;
58 int count = 0;
59
60 /* skip the first colon */
61 optarg++;
62 while ((pos = next_arg(optarg, ',')) && *id < RDPDR_MAX_DEVICES)
63 {
64 ppar_info = (PARALLEL_DEVICE *) xmalloc(sizeof(PARALLEL_DEVICE));
65
66 pos2 = next_arg(optarg, '=');
67 strcpy(g_rdpdr_device[*id].name, optarg);
68
69 toupper_str(g_rdpdr_device[*id].name);
70
71 g_rdpdr_device[*id].local_path = xmalloc(strlen(pos2) + 1);
72 strcpy(g_rdpdr_device[*id].local_path, pos2);
73 printf("PARALLEL %s to %s\n", optarg, pos2);
74
75 /* set device type */
76 g_rdpdr_device[*id].device_type = DEVICE_TYPE_PARALLEL;
77 g_rdpdr_device[*id].pdevice_data = (void *) ppar_info;
78 g_rdpdr_device[*id].handle = 0;
79 count++;
80 (*id)++;
81
82 optarg = pos;
83 }
84 return count;
85}
86
87static RD_NTSTATUS
88parallel_create(uint32 device_id, uint32 access, uint32 share_mode, uint32 disposition,
89 uint32 flags, char *filename, RD_NTHANDLE * handle)
90{
91 int parallel_fd;
92
93 parallel_fd = open(g_rdpdr_device[device_id].local_path, O_RDWR);
94 if (parallel_fd == -1)
95 {
96 perror("open");
97 return RD_STATUS_ACCESS_DENIED;
98 }
99
100 /* all read and writes should be non blocking */
101 if (fcntl(parallel_fd, F_SETFL, O_NONBLOCK) == -1)
102 perror("fcntl");
103
104#if defined(LPABORT)
105 /* Retry on errors */
106 ioctl(parallel_fd, LPABORT, (int) 1);
107#endif
108
109 g_rdpdr_device[device_id].handle = parallel_fd;
110
111 *handle = parallel_fd;
112
113 return RD_STATUS_SUCCESS;
114}
115
116static RD_NTSTATUS
117parallel_close(RD_NTHANDLE handle)
118{
119 int i = get_device_index(handle);
120 if (i >= 0)
121 g_rdpdr_device[i].handle = 0;
122 close(handle);
123 return RD_STATUS_SUCCESS;
124}
125
126static RD_NTSTATUS
127parallel_read(RD_NTHANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result)
128{
129 *result = read(handle, data, length);
130 return RD_STATUS_SUCCESS;
131}
132
133static RD_NTSTATUS
134parallel_write(RD_NTHANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result)
135{
136 int rc = RD_STATUS_SUCCESS;
137
138 int n = write(handle, data, length);
139 if (n < 0)
140 {
141#if defined(LPGETSTATUS)
142 int status;
143#endif
144
145 *result = 0;
146 switch (errno)
147 {
148 case EAGAIN:
149 rc = RD_STATUS_DEVICE_OFF_LINE;
150 case ENOSPC:
151 rc = RD_STATUS_DEVICE_PAPER_EMPTY;
152 case EIO:
153 rc = RD_STATUS_DEVICE_OFF_LINE;
154 default:
155 rc = RD_STATUS_DEVICE_POWERED_OFF;
156 }
157#if defined(LPGETSTATUS)
158 if (ioctl(handle, LPGETSTATUS, &status) == 0)
159 {
160 /* coming soon: take care for the printer status */
161 printf("parallel_write: status = %d, errno = %d\n", status, errno);
162 }
163#endif
164 }
165 *result = n;
166 return rc;
167}
168
169static RD_NTSTATUS
170parallel_device_control(RD_NTHANDLE handle, uint32 request, STREAM in, STREAM out)
171{
172 if ((request >> 16) != FILE_DEVICE_PARALLEL)
173 return RD_STATUS_INVALID_PARAMETER;
174
175 /* extract operation */
176 request >>= 2;
177 request &= 0xfff;
178
179 printf("PARALLEL IOCTL %d: ", request);
180
181 switch (request)
182 {
183 case IOCTL_PAR_QUERY_RAW_DEVICE_ID:
184
185 default:
186
187 printf("\n");
188 unimpl("UNKNOWN IOCTL %d\n", request);
189 }
190 return RD_STATUS_SUCCESS;
191}
192
193DEVICE_FNS parallel_fns = {
194 parallel_create,
195 parallel_close,
196 parallel_read,
197 parallel_write,
198 parallel_device_control
199};
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette