/[rdesktop]/jpeg/rdesktop/trunk/printer.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 /jpeg/rdesktop/trunk/printer.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1507 - (hide annotations)
Mon Jul 20 16:45:11 2009 UTC (14 years, 10 months ago) by dpavlin
File MIME type: text/plain
File size: 4303 byte(s)
branch for integration of Daniel Jarboe <daniel.jarboe(at)gmail.com>
patches for jpeg
1 astrand 963 /* -*- c-basic-offset: 8 -*-
2     rdesktop: A Remote Desktop Protocol client.
3 jsorg71 1475 Copyright (C) Matthew Chapman 1999-2008
4 astrand 963
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 matthewc 432 #include "rdesktop.h"
21    
22 n-ki 569 extern RDPDR_DEVICE g_rdpdr_device[];
23 matthewc 432
24 astrand 664 static PRINTER *
25 jsorg71 1364 get_printer_data(RD_NTHANDLE handle)
26 n-ki 569 {
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    
37     int
38 astrand 608 printer_enum_devices(uint32 * id, char *optarg)
39 n-ki 569 {
40     PRINTER *pprinter_data;
41    
42     char *pos = optarg;
43     char *pos2;
44     int count = 0;
45     int already = 0;
46    
47 stargo 865 /* we need to know how many printers we've already set up
48     supplied from other -r flags than this one. */
49 n-ki 569 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 stargo 603 strcat(g_rdpdr_device[*id].name, l_to_a(already + count + 1, 10));
67 n-ki 569
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 n-ki 582 pos2 = next_arg(optarg, '=');
75 n-ki 569 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 stargo 874 pprinter_data->driver = "HP Color LaserJet 8500 PS"; /* no printer driver supplied set default */
85 n-ki 569 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    
103 jsorg71 1364 static RD_NTSTATUS
104 n-ki 569 printer_create(uint32 device_id, uint32 access, uint32 share_mode, uint32 disposition, uint32 flags,
105 jsorg71 1364 char *filename, RD_NTHANDLE * handle)
106 matthewc 432 {
107 n-ki 569 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 astrand 1478 if (strncmp(pprinter_data->printer, "mydeskjet", strlen(pprinter_data->printer)) == 0)
114 n-ki 569 {
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 stargo 570 g_rdpdr_device[device_id].handle = fileno(pprinter_data->printer_fp);
124 n-ki 569 *handle = g_rdpdr_device[device_id].handle;
125 jsorg71 1364 return RD_STATUS_SUCCESS;
126 matthewc 432 }
127    
128 jsorg71 1364 static RD_NTSTATUS
129     printer_close(RD_NTHANDLE handle)
130 matthewc 432 {
131 n-ki 623 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 jsorg71 1364 return RD_STATUS_SUCCESS;
140 matthewc 432 }
141    
142 jsorg71 1364 static RD_NTSTATUS
143     printer_write(RD_NTHANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result)
144 matthewc 432 {
145 n-ki 569 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 jsorg71 1364 return RD_STATUS_INVALID_HANDLE;
154 n-ki 569 }
155 jsorg71 1364 return RD_STATUS_SUCCESS;
156 matthewc 432 }
157    
158 astrand 435 DEVICE_FNS printer_fns = {
159 matthewc 432 printer_create,
160     printer_close,
161 astrand 435 NULL, /* read */
162 matthewc 432 printer_write,
163 astrand 435 NULL /* device_control */
164 matthewc 432 };

  ViewVC Help
Powered by ViewVC 1.1.26