ReactOS 0.4.15-dev-5666-gc548b97
printer.c File Reference
#include "rdesktop.h"
Include dependency graph for printer.c:

Go to the source code of this file.

Functions

static PRINTERget_printer_data (RDPCLIENT *This, NTHANDLE handle)
 
int printer_enum_devices (RDPCLIENT *This, uint32 *id, char *optarg)
 
static NTSTATUS printer_create (RDPCLIENT *This, uint32 device_id, uint32 access, uint32 share_mode, uint32 disposition, uint32 flags, char *filename, NTHANDLE *handle)
 
static NTSTATUS printer_close (RDPCLIENT *This, NTHANDLE handle)
 
static NTSTATUS printer_write (RDPCLIENT *This, NTHANDLE handle, uint8 *data, uint32 length, uint32 offset, uint32 *result)
 

Variables

DEVICE_FNS printer_fns
 

Function Documentation

◆ get_printer_data()

static PRINTER * get_printer_data ( RDPCLIENT This,
NTHANDLE  handle 
)
static

Definition at line 23 of file printer.c.

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}
#define RDPDR_MAX_DEVICES
Definition: constants.h:484
#define index(s, c)
Definition: various.h:29
#define NULL
Definition: types.h:112
GLuint index
Definition: glext.h:6031

Referenced by printer_write().

◆ printer_close()

static NTSTATUS printer_close ( RDPCLIENT This,
NTHANDLE  handle 
)
static

Definition at line 127 of file printer.c.

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}
int get_device_index(RD_NTHANDLE handle)
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
#define pclose
Definition: syshdrs.h:73
#define STATUS_SUCCESS
Definition: shellext.h:65
FILE * printer_fp
Definition: types.h:262

◆ printer_create()

static NTSTATUS printer_create ( RDPCLIENT This,
uint32  device_id,
uint32  access,
uint32  share_mode,
uint32  disposition,
uint32  flags,
char filename,
NTHANDLE *  handle 
)
static

Definition at line 102 of file printer.c.

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}
#define fileno
Definition: acwin.h:102
if(dx< 0)
Definition: linetemp.h:194
#define sprintf(buf, format,...)
Definition: sprintf.c:55
#define popen
Definition: syshdrs.h:72
Definition: ftp_var.h:139
char * printer
Definition: types.h:263

◆ printer_enum_devices()

int printer_enum_devices ( RDPCLIENT This,
uint32 id,
char optarg 
)

Definition at line 36 of file printer.c.

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}
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 DEVICE_TYPE_PRINTER
Definition: constants.h:487
char * l_to_a(long N, int base)
Definition: rdesktop.c:1356
char * next_arg(char *src, char needle)
Definition: rdesktop.c:1174
void * xmalloc(int size)
Definition: uimain.c:747
#define False
Definition: types.h:25
#define True
Definition: types.h:24
const char * optarg
Definition: getopt.c:49
#define printf
Definition: freeldr.h:94
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLuint id
Definition: glext.h:5910
char * driver
Definition: types.h:263
RD_BOOL default_printer
Definition: types.h:266

◆ printer_write()

static NTSTATUS printer_write ( RDPCLIENT This,
NTHANDLE  handle,
uint8 data,
uint32  length,
uint32  offset,
uint32 result 
)
static

Definition at line 141 of file printer.c.

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}
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
GLuint64EXT * result
Definition: glext.h:11304
_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)
#define STATUS_INVALID_HANDLE
Definition: ntstatus.h:245
static PRINTER * get_printer_data(RDPCLIENT *This, NTHANDLE handle)
Definition: printer.c:23

Variable Documentation

◆ printer_fns

DEVICE_FNS printer_fns
Initial value:
= {
NULL,
}
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
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

Definition at line 156 of file printer.c.

Referenced by rdpdr_process_irp().