ReactOS 0.4.15-dev-8219-ge8b88cf
printer.c
Go to the documentation of this file.
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 along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18*/
19
20#include "rdesktop.h"
21
22static PRINTER *
24{
25 int index;
26
27 for (index = 0; index < RDPDR_MAX_DEVICES; index++)
28 {
29 if (handle == This->rdpdr_device[index].handle)
30 return (PRINTER *) This->rdpdr_device[index].pdevice_data;
31 }
32 return NULL;
33}
34
35int
37{
38 PRINTER *pprinter_data;
39
40 char *pos = optarg;
41 char *pos2;
42 int count = 0;
43 int already = 0;
44
45 /* we need to know how many printers we've already set up
46 supplied from other -r flags than this one. */
47 while (count < *id)
48 {
49 if (This->rdpdr_device[count].device_type == DEVICE_TYPE_PRINTER)
50 already++;
51 count++;
52 }
53
54 count = 0;
55
56 if (*optarg == ':')
57 optarg++;
58
59 while ((pos = next_arg(optarg, ',')) && *id < RDPDR_MAX_DEVICES)
60 {
61 pprinter_data = (PRINTER *) xmalloc(sizeof(PRINTER));
62
63 strcpy(This->rdpdr_device[*id].name, "PRN");
64 strcat(This->rdpdr_device[*id].name, l_to_a(already + count + 1, 10));
65
66 /* first printer is set as default printer */
67 if ((already + count) == 0)
68 pprinter_data->default_printer = True;
69 else
70 pprinter_data->default_printer = False;
71
72 pos2 = next_arg(optarg, '=');
73 if (*optarg == (char) 0x00)
74 pprinter_data->printer = "mydeskjet"; /* set default */
75 else
76 {
77 pprinter_data->printer = xmalloc(strlen(optarg) + 1);
78 strcpy(pprinter_data->printer, optarg);
79 }
80
81 if (!pos2 || (*pos2 == (char) 0x00))
82 pprinter_data->driver = "HP Color LaserJet 8500 PS"; /* no printer driver supplied set default */
83 else
84 {
85 pprinter_data->driver = xmalloc(strlen(pos2) + 1);
86 strcpy(pprinter_data->driver, pos2);
87 }
88
89 printf("PRINTER %s to %s driver %s\n", This->rdpdr_device[*id].name,
90 pprinter_data->printer, pprinter_data->driver);
91 This->rdpdr_device[*id].device_type = DEVICE_TYPE_PRINTER;
92 This->rdpdr_device[*id].pdevice_data = (void *) pprinter_data;
93 count++;
94 (*id)++;
95
96 optarg = pos;
97 }
98 return count;
99}
100
101static NTSTATUS
102printer_create(RDPCLIENT * This, uint32 device_id, uint32 access, uint32 share_mode, uint32 disposition, uint32 flags,
103 char *filename, NTHANDLE * handle)
104{
105 char cmd[256];
106 PRINTER *pprinter_data;
107
108 pprinter_data = (PRINTER *) This->rdpdr_device[device_id].pdevice_data;
109
110 /* default printer name use default printer queue as well in unix */
111 if (pprinter_data->printer == "mydeskjet")
112 {
113 pprinter_data->printer_fp = popen("lpr", "w");
114 }
115 else
116 {
117 sprintf(cmd, "lpr -P %s", pprinter_data->printer);
118 pprinter_data->printer_fp = popen(cmd, "w");
119 }
120
121 This->rdpdr_device[device_id].handle = fileno(pprinter_data->printer_fp);
122 *handle = This->rdpdr_device[device_id].handle;
123 return STATUS_SUCCESS;
124}
125
126static NTSTATUS
128{
130 if (i >= 0)
131 {
132 PRINTER *pprinter_data = This->rdpdr_device[i].pdevice_data;
133 if (pprinter_data)
134 pclose(pprinter_data->printer_fp);
135 This->rdpdr_device[i].handle = 0;
136 }
137 return STATUS_SUCCESS;
138}
139
140static NTSTATUS
142{
143 PRINTER *pprinter_data;
144
145 pprinter_data = get_printer_data(This, handle);
146 *result = length * fwrite(data, length, 1, pprinter_data->printer_fp);
147
148 if (ferror(pprinter_data->printer_fp))
149 {
150 *result = 0;
152 }
153 return STATUS_SUCCESS;
154}
155
159 NULL, /* read */
161 NULL /* device_control */
162};
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define fileno
Definition: acwin.h:102
LONG NTSTATUS
Definition: precomp.h:26
#define DEVICE_TYPE_PRINTER
Definition: constants.h:487
#define RDPDR_MAX_DEVICES
Definition: constants.h:484
char * l_to_a(long N, int base)
Definition: rdesktop.c:1356
char * next_arg(char *src, char needle)
Definition: rdesktop.c:1174
int get_device_index(RD_NTHANDLE handle)
void * xmalloc(int size)
Definition: uimain.c:747
unsigned int uint32
Definition: types.h:32
#define False
Definition: types.h:25
#define True
Definition: types.h:24
unsigned char uint8
Definition: types.h:28
const char * optarg
Definition: getopt.c:49
#define index(s, c)
Definition: various.h:29
#define NULL
Definition: types.h:112
#define printf
Definition: freeldr.h:97
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLuint index
Definition: glext.h:6031
GLbitfield flags
Definition: glext.h:7161
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
GLuint GLint GLboolean GLint GLenum access
Definition: glext.h:7866
GLuint64EXT * result
Definition: glext.h:11304
GLuint id
Definition: glext.h:5910
GLintptr offset
Definition: glext.h:5920
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_Check_return_ _CRTIMP int __cdecl ferror(_In_ FILE *_File)
_Check_return_opt_ _CRTIMP size_t __cdecl fwrite(_In_reads_bytes_(_Size *_Count) const void *_Str, _In_ size_t _Size, _In_ size_t _Count, _Inout_ FILE *_File)
const char * filename
Definition: ioapi.h:137
if(dx< 0)
Definition: linetemp.h:194
#define sprintf(buf, format,...)
Definition: sprintf.c:55
#define popen
Definition: syshdrs.h:72
#define pclose
Definition: syshdrs.h:73
#define STATUS_INVALID_HANDLE
Definition: ntstatus.h:245
static NTSTATUS printer_create(RDPCLIENT *This, uint32 device_id, uint32 access, uint32 share_mode, uint32 disposition, uint32 flags, char *filename, NTHANDLE *handle)
Definition: printer.c:102
DEVICE_FNS printer_fns
Definition: printer.c:156
int printer_enum_devices(RDPCLIENT *This, uint32 *id, char *optarg)
Definition: printer.c:36
static PRINTER * get_printer_data(RDPCLIENT *This, NTHANDLE handle)
Definition: printer.c:23
static NTSTATUS printer_close(RDPCLIENT *This, NTHANDLE handle)
Definition: printer.c:127
static NTSTATUS printer_write(RDPCLIENT *This, NTHANDLE handle, uint8 *data, uint32 length, uint32 offset, uint32 *result)
Definition: printer.c:141
#define STATUS_SUCCESS
Definition: shellext.h:65
Definition: ftp_var.h:139
char * printer
Definition: types.h:263
char * driver
Definition: types.h:263
RD_BOOL default_printer
Definition: types.h:266
FILE * printer_fp
Definition: types.h:262