VirtualBox

source: vbox/trunk/src/VBox/RDP/client/printer.c@ 8057

Last change on this file since 8057 was 7826, checked in by vboxsync, 17 years ago

Export modified rdesktop version including USB support to OSE. It's GPL anyway.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.1 KB
Line 
1/* -*- c-basic-offset: 8 -*-
2 rdesktop: A Remote Desktop Protocol client.
3 Copyright (C) Matthew Chapman 1999-2005
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 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
15 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
20#include "rdesktop.h"
21
22extern RDPDR_DEVICE g_rdpdr_device[];
23
24static PRINTER *
25get_printer_data(NTHANDLE handle)
26{
27 int index;
28
29 for (index = 0; index < RDPDR_MAX_DEVICES; index++)
30 {
31 if (handle == g_rdpdr_device[index].handle)
32 return (PRINTER *) g_rdpdr_device[index].pdevice_data;
33 }
34 return NULL;
35}
36
37int
38printer_enum_devices(uint32 * id, char *optarg)
39{
40 PRINTER *pprinter_data;
41
42 char *pos = optarg;
43 char *pos2;
44 int count = 0;
45 int already = 0;
46
47 /* we need to know how many printers we've already set up
48 supplied from other -r flags than this one. */
49 while (count < *id)
50 {
51 if (g_rdpdr_device[count].device_type == DEVICE_TYPE_PRINTER)
52 already++;
53 count++;
54 }
55
56 count = 0;
57
58 if (*optarg == ':')
59 optarg++;
60
61 while ((pos = next_arg(optarg, ',')) && *id < RDPDR_MAX_DEVICES)
62 {
63 pprinter_data = (PRINTER *) xmalloc(sizeof(PRINTER));
64
65 strcpy(g_rdpdr_device[*id].name, "PRN");
66 strcat(g_rdpdr_device[*id].name, l_to_a(already + count + 1, 10));
67
68 /* first printer is set as default printer */
69 if ((already + count) == 0)
70 pprinter_data->default_printer = True;
71 else
72 pprinter_data->default_printer = False;
73
74 pos2 = next_arg(optarg, '=');
75 if (*optarg == (char) 0x00)
76 pprinter_data->printer = "mydeskjet"; /* set default */
77 else
78 {
79 pprinter_data->printer = xmalloc(strlen(optarg) + 1);
80 strcpy(pprinter_data->printer, optarg);
81 }
82
83 if (!pos2 || (*pos2 == (char) 0x00))
84 pprinter_data->driver = "HP Color LaserJet 8500 PS"; /* no printer driver supplied set default */
85 else
86 {
87 pprinter_data->driver = xmalloc(strlen(pos2) + 1);
88 strcpy(pprinter_data->driver, pos2);
89 }
90
91 printf("PRINTER %s to %s driver %s\n", g_rdpdr_device[*id].name,
92 pprinter_data->printer, pprinter_data->driver);
93 g_rdpdr_device[*id].device_type = DEVICE_TYPE_PRINTER;
94 g_rdpdr_device[*id].pdevice_data = (void *) pprinter_data;
95 count++;
96 (*id)++;
97
98 optarg = pos;
99 }
100 return count;
101}
102
103static NTSTATUS
104printer_create(uint32 device_id, uint32 access, uint32 share_mode, uint32 disposition, uint32 flags,
105 char *filename, NTHANDLE * handle)
106{
107 char cmd[256];
108 PRINTER *pprinter_data;
109
110 pprinter_data = (PRINTER *) g_rdpdr_device[device_id].pdevice_data;
111
112 /* default printer name use default printer queue as well in unix */
113 if (!strcmp(pprinter_data->printer, "mydeskjet"))
114 {
115 pprinter_data->printer_fp = popen("lpr", "w");
116 }
117 else
118 {
119 sprintf(cmd, "lpr -P %s", pprinter_data->printer);
120 pprinter_data->printer_fp = popen(cmd, "w");
121 }
122
123 g_rdpdr_device[device_id].handle = fileno(pprinter_data->printer_fp);
124 *handle = g_rdpdr_device[device_id].handle;
125 return STATUS_SUCCESS;
126}
127
128static NTSTATUS
129printer_close(NTHANDLE handle)
130{
131 int i = get_device_index(handle);
132 if (i >= 0)
133 {
134 PRINTER *pprinter_data = g_rdpdr_device[i].pdevice_data;
135 if (pprinter_data)
136 pclose(pprinter_data->printer_fp);
137 g_rdpdr_device[i].handle = 0;
138 }
139 return STATUS_SUCCESS;
140}
141
142static NTSTATUS
143printer_write(NTHANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result)
144{
145 PRINTER *pprinter_data;
146
147 pprinter_data = get_printer_data(handle);
148 *result = length * fwrite(data, length, 1, pprinter_data->printer_fp);
149
150 if (ferror(pprinter_data->printer_fp))
151 {
152 *result = 0;
153 return STATUS_INVALID_HANDLE;
154 }
155 return STATUS_SUCCESS;
156}
157
158DEVICE_FNS printer_fns = {
159 printer_create,
160 printer_close,
161 NULL, /* read */
162 printer_write,
163 NULL /* device_control */
164};
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