/[rdesktop]/sourceforge.net/trunk/rdesktop/parallel.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

Diff of /sourceforge.net/trunk/rdesktop/parallel.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 584 by n-ki, Tue Jan 27 21:06:22 2004 UTC revision 963 by astrand, Wed Aug 3 10:56:16 2005 UTC
# Line 1  Line 1 
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
16       along with this program; if not, write to the Free Software
17       Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18    */
19  #define MAX_PARALLEL_DEVICES            1  #define MAX_PARALLEL_DEVICES            1
20    
21  #define FILE_DEVICE_PARALLEL            0x22  #define FILE_DEVICE_PARALLEL            0x22
# Line 7  Line 25 
25  #include "rdesktop.h"  #include "rdesktop.h"
26  #include <unistd.h>  #include <unistd.h>
27  #include <fcntl.h>  #include <fcntl.h>
28    #include <sys/ioctl.h>
29    #include <errno.h>
30    
31  extern RDPDR_DEVICE g_rdpdr_device[];  #if defined(__linux__)
32    #include <linux/lp.h>
33    #endif
34    
35  PARALLEL_DEVICE *  extern int errno;
 get_parallel_data(HANDLE handle)  
 {  
         int index;  
36    
37          for (index = 0; index < RDPDR_MAX_DEVICES; index++)  extern RDPDR_DEVICE g_rdpdr_device[];
         {  
                 if (handle == g_rdpdr_device[index].handle)  
                         return (PARALLEL_DEVICE *) g_rdpdr_device[index].pdevice_data;  
         }  
         return NULL;  
 }  
38    
39    
40  /* Enumeration of devices from rdesktop.c        */  /* Enumeration of devices from rdesktop.c        */
# Line 29  get_parallel_data(HANDLE handle) Line 42  get_parallel_data(HANDLE handle)
42  /* optarg looks like ':LPT1=/dev/lp0'            */  /* optarg looks like ':LPT1=/dev/lp0'            */
43  /* when it arrives to this function.             */  /* when it arrives to this function.             */
44  int  int
45  parallel_enum_devices(int *id, char *optarg)  parallel_enum_devices(uint32 * id, char *optarg)
46  {  {
47          PARALLEL_DEVICE *ppar_info;          PARALLEL_DEVICE *ppar_info;
48    
# Line 37  parallel_enum_devices(int *id, char *opt Line 50  parallel_enum_devices(int *id, char *opt
50          char *pos2;          char *pos2;
51          int count = 0;          int count = 0;
52    
53          // skip the first colon          /* skip the first colon */
54          optarg++;          optarg++;
55          while ((pos = next_arg(optarg, ',')) && *id < RDPDR_MAX_DEVICES)          while ((pos = next_arg(optarg, ',')) && *id < RDPDR_MAX_DEVICES)
56          {          {
# Line 52  parallel_enum_devices(int *id, char *opt Line 65  parallel_enum_devices(int *id, char *opt
65                  strcpy(g_rdpdr_device[*id].local_path, pos2);                  strcpy(g_rdpdr_device[*id].local_path, pos2);
66                  printf("PARALLEL %s to %s\n", optarg, pos2);                  printf("PARALLEL %s to %s\n", optarg, pos2);
67    
68                  // set device type                  /* set device type */
69                  g_rdpdr_device[*id].device_type = DEVICE_TYPE_PARALLEL;                  g_rdpdr_device[*id].device_type = DEVICE_TYPE_PARALLEL;
70                  g_rdpdr_device[*id].pdevice_data = (void *) ppar_info;                  g_rdpdr_device[*id].pdevice_data = (void *) ppar_info;
71                    g_rdpdr_device[*id].handle = 0;
72                  count++;                  count++;
73                  (*id)++;                  (*id)++;
74    
# Line 64  parallel_enum_devices(int *id, char *opt Line 78  parallel_enum_devices(int *id, char *opt
78  }  }
79    
80  static NTSTATUS  static NTSTATUS
81  parallel_create(uint32 device_id, uint32 access, uint32 share_mode, uint32 disposition, uint32 flags,  parallel_create(uint32 device_id, uint32 access, uint32 share_mode, uint32 disposition,
82                 char *filename, HANDLE * handle)                  uint32 flags, char *filename, NTHANDLE * handle)
83  {  {
84          int parallel_fd;          int parallel_fd;
85    
86          parallel_fd = open(g_rdpdr_device[device_id].local_path, O_WRONLY);          parallel_fd = open(g_rdpdr_device[device_id].local_path, O_RDWR);
87          if (parallel_fd == -1)          if (parallel_fd == -1)
88            {
89                    perror("open");
90                  return STATUS_ACCESS_DENIED;                  return STATUS_ACCESS_DENIED;
91            }
92    
93            /* all read and writes should be non blocking */
94            if (fcntl(parallel_fd, F_SETFL, O_NONBLOCK) == -1)
95                    perror("fcntl");
96    
97    #if defined(LPABORT)
98            /* Retry on errors */
99            ioctl(parallel_fd, LPABORT, (int) 1);
100    #endif
101    
102          g_rdpdr_device[device_id].handle = parallel_fd;          g_rdpdr_device[device_id].handle = parallel_fd;
103    
104          *handle = parallel_fd;          *handle = parallel_fd;
105    
106          return STATUS_SUCCESS;          return STATUS_SUCCESS;
107  }  }
108    
109  static NTSTATUS  static NTSTATUS
110  parallel_close(HANDLE handle)  parallel_close(NTHANDLE handle)
111  {  {
112          g_rdpdr_device[get_device_index(handle)].handle = 0;          int i = get_device_index(handle);
113            if (i >= 0)
114                    g_rdpdr_device[i].handle = 0;
115          close(handle);          close(handle);
116          return STATUS_SUCCESS;          return STATUS_SUCCESS;
117  }  }
118    
119  static NTSTATUS  static NTSTATUS
120  parallel_write(HANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result)  parallel_read(NTHANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result)
121  {  {
122          *result = write(handle, data, length);          *result = read(handle, data, length);
123          return STATUS_SUCCESS;          return STATUS_SUCCESS;
124  }  }
125    
126  static NTSTATUS  static NTSTATUS
127  parallel_device_control(HANDLE handle, uint32 request, STREAM in, STREAM out)  parallel_write(NTHANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result)
128    {
129            int rc = STATUS_SUCCESS;
130    
131            int n = write(handle, data, length);
132            if (n < 0)
133            {
134    #if defined(LPGETSTATUS)
135                    int status;
136    #endif
137    
138                    *result = 0;
139                    switch (errno)
140                    {
141                            case EAGAIN:
142                                    rc = STATUS_DEVICE_OFF_LINE;
143                            case ENOSPC:
144                                    rc = STATUS_DEVICE_PAPER_EMPTY;
145                            case EIO:
146                                    rc = STATUS_DEVICE_OFF_LINE;
147                            default:
148                                    rc = STATUS_DEVICE_POWERED_OFF;
149                    }
150    #if defined(LPGETSTATUS)
151                    if (ioctl(handle, LPGETSTATUS, &status) == 0)
152                    {
153                            /* coming soon: take care for the printer status */
154                            printf("parallel_write: status = %d, errno = %d\n", status, errno);
155                    }
156    #endif
157            }
158            *result = n;
159            return rc;
160    }
161    
162    static NTSTATUS
163    parallel_device_control(NTHANDLE handle, uint32 request, STREAM in, STREAM out)
164  {  {
165          if ((request >> 16) != FILE_DEVICE_PARALLEL)          if ((request >> 16) != FILE_DEVICE_PARALLEL)
166                  return STATUS_INVALID_PARAMETER;                  return STATUS_INVALID_PARAMETER;
# Line 121  parallel_device_control(HANDLE handle, u Line 186  parallel_device_control(HANDLE handle, u
186  DEVICE_FNS parallel_fns = {  DEVICE_FNS parallel_fns = {
187          parallel_create,          parallel_create,
188          parallel_close,          parallel_close,
189          NULL,          parallel_read,
190          parallel_write,          parallel_write,
191          parallel_device_control          parallel_device_control
192  };  };

Legend:
Removed from v.584  
changed lines
  Added in v.963

  ViewVC Help
Powered by ViewVC 1.1.26