VirtualBox

source: vbox/trunk/src/VBox/RDP/client-1.8.3/printer.c@ 72372

Last change on this file since 72372 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#include "rdesktop.h"
29
30extern RDPDR_DEVICE g_rdpdr_device[];
31
32static PRINTER *
33get_printer_data(RD_NTHANDLE handle)
34{
35 int index;
36
37 for (index = 0; index < RDPDR_MAX_DEVICES; index++)
38 {
39 if (handle == g_rdpdr_device[index].handle)
40 return (PRINTER *) g_rdpdr_device[index].pdevice_data;
41 }
42 return NULL;
43}
44
45int
46printer_enum_devices(uint32 * id, char *optarg)
47{
48 PRINTER *pprinter_data;
49
50 char *pos = optarg;
51 char *pos2;
52 int count = 0;
53 int already = 0;
54
55 /* we need to know how many printers we've already set up
56 supplied from other -r flags than this one. */
57 while (count < *id)
58 {
59 if (g_rdpdr_device[count].device_type == DEVICE_TYPE_PRINTER)
60 already++;
61 count++;
62 }
63
64 count = 0;
65
66 if (*optarg == ':')
67 optarg++;
68
69 while ((pos = next_arg(optarg, ',')) && *id < RDPDR_MAX_DEVICES)
70 {
71 pprinter_data = (PRINTER *) xmalloc(sizeof(PRINTER));
72
73 strcpy(g_rdpdr_device[*id].name, "PRN");
74 strcat(g_rdpdr_device[*id].name, l_to_a(already + count + 1, 10));
75
76 /* first printer is set as default printer */
77 if ((already + count) == 0)
78 pprinter_data->default_printer = True;
79 else
80 pprinter_data->default_printer = False;
81
82 pos2 = next_arg(optarg, '=');
83 if (*optarg == (char) 0x00)
84 pprinter_data->printer = "mydeskjet"; /* set default */
85 else
86 {
87 pprinter_data->printer = xmalloc(strlen(optarg) + 1);
88 strcpy(pprinter_data->printer, optarg);
89 }
90
91 if (!pos2 || (*pos2 == (char) 0x00))
92 pprinter_data->driver = "MS Publisher Imagesetter"; /* no printer driver supplied set default */
93 else
94 {
95 pprinter_data->driver = xmalloc(strlen(pos2) + 1);
96 strcpy(pprinter_data->driver, pos2);
97 }
98
99 printf("PRINTER %s to %s driver %s\n", g_rdpdr_device[*id].name,
100 pprinter_data->printer, pprinter_data->driver);
101 g_rdpdr_device[*id].device_type = DEVICE_TYPE_PRINTER;
102 g_rdpdr_device[*id].pdevice_data = (void *) pprinter_data;
103 count++;
104 (*id)++;
105
106 optarg = pos;
107 }
108 return count;
109}
110
111static RD_NTSTATUS
112printer_create(uint32 device_id, uint32 access, uint32 share_mode, uint32 disposition, uint32 flags,
113 char *filename, RD_NTHANDLE * handle)
114{
115 char cmd[256];
116 PRINTER *pprinter_data;
117
118 pprinter_data = (PRINTER *) g_rdpdr_device[device_id].pdevice_data;
119
120 /* default printer name use default printer queue as well in unix */
121 if (strncmp(pprinter_data->printer, "mydeskjet", strlen(pprinter_data->printer)) == 0)
122 {
123 pprinter_data->printer_fp = popen("lpr", "w");
124 }
125 else
126 {
127#ifdef VBOX
128 snprintf(cmd, sizeof(cmd), "lpr -P %s", pprinter_data->printer);
129#else
130 sprintf(cmd, "lpr -P %s", pprinter_data->printer);
131#endif
132 pprinter_data->printer_fp = popen(cmd, "w");
133 }
134
135 g_rdpdr_device[device_id].handle = fileno(pprinter_data->printer_fp);
136 *handle = g_rdpdr_device[device_id].handle;
137 return RD_STATUS_SUCCESS;
138}
139
140static RD_NTSTATUS
141printer_close(RD_NTHANDLE handle)
142{
143 int i = get_device_index(handle);
144 if (i >= 0)
145 {
146 PRINTER *pprinter_data = g_rdpdr_device[i].pdevice_data;
147 if (pprinter_data)
148 pclose(pprinter_data->printer_fp);
149 g_rdpdr_device[i].handle = 0;
150 }
151 return RD_STATUS_SUCCESS;
152}
153
154static RD_NTSTATUS
155printer_write(RD_NTHANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result)
156{
157 PRINTER *pprinter_data;
158
159 pprinter_data = get_printer_data(handle);
160 *result = length * fwrite(data, length, 1, pprinter_data->printer_fp);
161
162 if (ferror(pprinter_data->printer_fp))
163 {
164 *result = 0;
165 return RD_STATUS_INVALID_HANDLE;
166 }
167 return RD_STATUS_SUCCESS;
168}
169
170DEVICE_FNS printer_fns = {
171 printer_create,
172 printer_close,
173 NULL, /* read */
174 printer_write,
175 NULL /* device_control */
176};
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