VirtualBox

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

Last change on this file since 33889 was 33656, checked in by vboxsync, 14 years ago

*: rebrand Sun (L)GPL disclaimers

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