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

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

revision 591 by n-ki, Thu Jan 29 12:27:21 2004 UTC revision 592 by n-ki, Fri Jan 30 14:10:32 2004 UTC
# Line 22  Line 22 
22  #define IRP_MN_QUERY_DIRECTORY          0x01  #define IRP_MN_QUERY_DIRECTORY          0x01
23  #define IRP_MN_NOTIFY_CHANGE_DIRECTORY  0x02  #define IRP_MN_NOTIFY_CHANGE_DIRECTORY  0x02
24    
 //#define MAX_ASYNC_IO_REQUESTS   10  
   
25  extern char hostname[16];  extern char hostname[16];
26  extern DEVICE_FNS serial_fns;  extern DEVICE_FNS serial_fns;
27  extern DEVICE_FNS printer_fns;  extern DEVICE_FNS printer_fns;
28  extern DEVICE_FNS parallel_fns;  extern DEVICE_FNS parallel_fns;
29  extern DEVICE_FNS disk_fns;  extern DEVICE_FNS disk_fns;
30    
   
31  static VCHANNEL *rdpdr_channel;  static VCHANNEL *rdpdr_channel;
32    
33  /* If select() times out, the request for the device with handle g_min_timeout_fd is aborted */  /* If select() times out, the request for the device with handle g_min_timeout_fd is aborted */
# Line 40  uint32 g_num_devices; Line 37  uint32 g_num_devices;
37  /* Table with information about rdpdr devices */  /* Table with information about rdpdr devices */
38  RDPDR_DEVICE g_rdpdr_device[RDPDR_MAX_DEVICES];  RDPDR_DEVICE g_rdpdr_device[RDPDR_MAX_DEVICES];
39    
 #if 0  
40  /* Used to store incoming io request, until they are ready to be completed */  /* Used to store incoming io request, until they are ready to be completed */
41    /* using a linked list ensures that they are processed in the right order, */
42    /* if multiple ios are being done on the same fd */
43  struct async_iorequest  struct async_iorequest
44  {  {
45          uint32 fd, major, minor, offset, device, id, length;          uint32 fd, major, minor, offset, device, id, length, partial_len;
46          long timeout,           /* Total timeout */          long timeout,           /* Total timeout */
47            itv_timeout;          /* Interval timeout (between serial characters) */            itv_timeout;          /* Interval timeout (between serial characters) */
48          uint8 *buffer;          uint8 *buffer;
49          DEVICE_FNS *fns;          DEVICE_FNS *fns;
50  } g_iorequest[MAX_ASYNC_IO_REQUESTS];  
51  #endif          struct async_iorequest *next;   /* next element in list */
52    } g_iorequest;
53    
54  /* Return device_id for a given handle */  /* Return device_id for a given handle */
55  int  int
# Line 77  convert_to_unix_filename(char *filename) Line 76  convert_to_unix_filename(char *filename)
76          }          }
77  }  }
78    
 #if 0  
79  /* Add a new io request to the table containing pending io requests so it won't block rdesktop */  /* Add a new io request to the table containing pending io requests so it won't block rdesktop */
80  BOOL  BOOL
81  add_async_iorequest(uint32 device, uint32 file, uint32 id, uint32 major, uint32 length,  add_async_iorequest(uint32 device, uint32 file, uint32 id, uint32 major, uint32 length,
82                      DEVICE_FNS * fns, long total_timeout, long interval_timeout, uint8 * buffer)                      DEVICE_FNS * fns, long total_timeout, long interval_timeout, uint8 * buffer)
83  {  {
         int i;  
84          struct async_iorequest *iorq;          struct async_iorequest *iorq;
85    
86          for (i = 0; i < MAX_ASYNC_IO_REQUESTS; i++)          iorq = &g_iorequest;
87            while (iorq->fd != 0)
88          {          {
89                  iorq = &g_iorequest[i];                  // create new element if needed
90                    if (iorq->next == NULL)
91                            iorq->next =
92                                    (struct async_iorequest *) xmalloc(sizeof(struct async_iorequest));
93    
94                  if (iorq->fd == 0)                  iorq = iorq->next;
95            }
96    
97            /* first element is special since it doesn't get deleted */
98            /* don't want to get io out of order */
99            if (g_iorequest.fd == 0)
100            {
101                    iorq = &g_iorequest;
102                    /* look for first occurrence of fd */
103                    while (iorq->next != NULL)
104                  {                  {
105                          iorq->device = device;                          if (iorq->fd == file)
106                          iorq->fd = file;                                  break;
107                          iorq->id = id;                          iorq = iorq->next;
108                          iorq->major = major;                  }
109                          iorq->length = length;                  /* if same create new link at end of chain instead */
110                          iorq->fns = fns;                  if (iorq->fd == file)
111                          iorq->timeout = total_timeout;                  {
112                          iorq->itv_timeout = interval_timeout;                          while (iorq->next != NULL)
113                          iorq->buffer = buffer;                                  iorq = iorq->next;
114                          return True;                          iorq->next =
115                                    (struct async_iorequest *) xmalloc(sizeof(struct async_iorequest));
116                            iorq = iorq->next;
117                  }                  }
118                    else
119                            iorq = &g_iorequest;    /* didn't find fs use first entry */
120          }          }
121          error("IO request table full. Increase MAX_ASYNC_IO_REQUESTS in rdpdr.c!\n");  
122          return False;          iorq->device = device;
123            iorq->fd = file;
124            iorq->id = id;
125            iorq->major = major;
126            iorq->length = length;
127            iorq->partial_len = 0;
128            iorq->fns = fns;
129            iorq->timeout = total_timeout;
130            iorq->itv_timeout = interval_timeout;
131            iorq->buffer = buffer;
132            return True;
133  }  }
 #endif  
134    
135  void  void
136  rdpdr_send_connect(void)  rdpdr_send_connect(void)
# Line 290  rdpdr_process_irp(STREAM s) Line 313  rdpdr_process_irp(STREAM s)
313                  case DEVICE_TYPE_SERIAL:                  case DEVICE_TYPE_SERIAL:
314    
315                          fns = &serial_fns;                          fns = &serial_fns;
316                          /* should be async when aio is finished */                          rw_blocking = False;
                         /*rw_blocking = False; */  
317                          break;                          break;
318    
319                  case DEVICE_TYPE_PARALLEL:                  case DEVICE_TYPE_PARALLEL:
320    
321                          fns = &parallel_fns;                          fns = &parallel_fns;
322                          /* should be async when aio is finished */                          rw_blocking = False;
                         /*rw_blocking = False;*/  
323                          break;                          break;
324    
325                  case DEVICE_TYPE_PRINTER:                  case DEVICE_TYPE_PRINTER:
# Line 308  rdpdr_process_irp(STREAM s) Line 329  rdpdr_process_irp(STREAM s)
329    
330                  case DEVICE_TYPE_DISK:                  case DEVICE_TYPE_DISK:
331    
332                            /*rw_blocking = False; */
333                          fns = &disk_fns;                          fns = &disk_fns;
334                          break;                          break;
335    
# Line 374  rdpdr_process_irp(STREAM s) Line 396  rdpdr_process_irp(STREAM s)
396  #if WITH_DEBUG_RDP5  #if WITH_DEBUG_RDP5
397                          DEBUG(("RDPDR IRP Read (length: %d, offset: %d)\n", length, offset));                          DEBUG(("RDPDR IRP Read (length: %d, offset: %d)\n", length, offset));
398  #endif  #endif
399  //                      if (rw_blocking)        // Complete read immediately                          if (rw_blocking)        // Complete read immediately
400  //                      {                          {
401                                  buffer = (uint8 *) xrealloc((void *) buffer, length);                                  buffer = (uint8 *) xrealloc((void *) buffer, length);
402                                  status = fns->read(file, buffer, length, offset, &result);                                  status = fns->read(file, buffer, length, offset, &result);
403                                  buffer_len = result;                                  buffer_len = result;
404                                  break;                                  break;
405  //                      }                          }
406    
 #if 0  
407                          // Add request to table                          // Add request to table
408                          pst_buf = (uint8 *) xmalloc(length);                          pst_buf = (uint8 *) xmalloc(length);
409                          serial_get_timeout(file, length, &total_timeout, &interval_timeout);                          serial_get_timeout(file, length, &total_timeout, &interval_timeout);
# Line 396  rdpdr_process_irp(STREAM s) Line 417  rdpdr_process_irp(STREAM s)
417    
418                          status = STATUS_CANCELLED;                          status = STATUS_CANCELLED;
419                          break;                          break;
 #endif  
420                  case IRP_MJ_WRITE:                  case IRP_MJ_WRITE:
421    
422                          buffer_len = 1;                          buffer_len = 1;
# Line 413  rdpdr_process_irp(STREAM s) Line 433  rdpdr_process_irp(STREAM s)
433  #if WITH_DEBUG_RDP5  #if WITH_DEBUG_RDP5
434                          DEBUG(("RDPDR IRP Write (length: %d)\n", result));                          DEBUG(("RDPDR IRP Write (length: %d)\n", result));
435  #endif  #endif
436  //                      if (rw_blocking)        // Complete immediately                          if (rw_blocking)        // Complete immediately
437  //                      {                          {
438                                  status = fns->write(file, s->p, length, offset, &result);                                  status = fns->write(file, s->p, length, offset, &result);
439                                  break;                                  break;
440  //                      }                          }
441  #if 0  
442                          // Add to table                          // Add to table
443                          pst_buf = (uint8 *) xmalloc(length);                          pst_buf = (uint8 *) xmalloc(length);
444                          in_uint8a(s, pst_buf, length);                          in_uint8a(s, pst_buf, length);
# Line 432  rdpdr_process_irp(STREAM s) Line 452  rdpdr_process_irp(STREAM s)
452    
453                          status = STATUS_CANCELLED;                          status = STATUS_CANCELLED;
454                          break;                          break;
 #endif  
455    
456                  case IRP_MJ_QUERY_INFORMATION:                  case IRP_MJ_QUERY_INFORMATION:
457    
# Line 676  rdpdr_init() Line 695  rdpdr_init()
695          return (rdpdr_channel != NULL);          return (rdpdr_channel != NULL);
696  }  }
697    
 #if 0  
698  /* Add file descriptors of pending io request to select() */  /* Add file descriptors of pending io request to select() */
699  void  void
700  rdpdr_add_fds(int *n, fd_set * rfds, fd_set * wfds, struct timeval *tv, BOOL * timeout)  rdpdr_add_fds(int *n, fd_set * rfds, fd_set * wfds, struct timeval *tv, BOOL * timeout)
701  {  {
         int i;  
702          long select_timeout = 0;        // Timeout value to be used for select() (in millisecons).          long select_timeout = 0;        // Timeout value to be used for select() (in millisecons).
703          struct async_iorequest *iorq;          struct async_iorequest *iorq;
704    
705          for (i = 0; i < MAX_ASYNC_IO_REQUESTS; i++)          iorq = &g_iorequest;
706            while (iorq != NULL)
707          {          {
708                  iorq = &g_iorequest[i];                  if (iorq->fd != 0)
   
                 if (iorq->fd != 0)      // Found a pending io request  
709                  {                  {
710                          switch (iorq->major)                          switch (iorq->major)
711                          {                          {
# Line 712  rdpdr_add_fds(int *n, fd_set * rfds, fd_ Line 728  rdpdr_add_fds(int *n, fd_set * rfds, fd_
728                                          break;                                          break;
729    
730                                  case IRP_MJ_WRITE:                                  case IRP_MJ_WRITE:
   
731                                          FD_SET(iorq->fd, wfds);                                          FD_SET(iorq->fd, wfds);
732                                          break;                                          break;
733    
734                          }                          }
735                          *n = MAX(*n, iorq->fd);                          *n = MAX(*n, iorq->fd);
736                  }                  }
737    
738                    iorq = iorq->next;
739          }          }
740  }  }
741    
# Line 727  rdpdr_add_fds(int *n, fd_set * rfds, fd_ Line 744  rdpdr_add_fds(int *n, fd_set * rfds, fd_
744  void  void
745  rdpdr_check_fds(fd_set * rfds, fd_set * wfds, BOOL timed_out)  rdpdr_check_fds(fd_set * rfds, fd_set * wfds, BOOL timed_out)
746  {  {
         int i;  
747          NTSTATUS status;          NTSTATUS status;
748          uint32 result = 0, buffer_len = 0;          uint32 result = 0;
749          DEVICE_FNS *fns;          DEVICE_FNS *fns;
750          struct async_iorequest *iorq;          struct async_iorequest *iorq;
751            struct async_iorequest *prev;
752    
753          if (timed_out)          if (timed_out)
754          {          {
# Line 739  rdpdr_check_fds(fd_set * rfds, fd_set * Line 756  rdpdr_check_fds(fd_set * rfds, fd_set *
756                  return;                  return;
757          }          }
758    
759          // Walk through array of pending io_rq's          iorq = &g_iorequest;
760          for (i = 0; i < MAX_ASYNC_IO_REQUESTS; i++)          prev = NULL;
761            while (iorq != NULL)
762          {          {
                 iorq = &g_iorequest[i];  
763    
764                  if (iorq->fd != 0)                  if (iorq->fd != 0)
765                  {                  {
766                          switch (iorq->major)                          switch (iorq->major)
767                          {                          {
   
768                                  case IRP_MJ_READ:                                  case IRP_MJ_READ:
   
769                                          if (FD_ISSET(iorq->fd, rfds))                                          if (FD_ISSET(iorq->fd, rfds))
770                                          {                                          {
771                                                  // Read, and send data.                                                  /* Read the data */
772                                                  fns = iorq->fns;                                                  fns = iorq->fns;
773                                                  status = fns->read(iorq->fd, iorq->buffer,                                                  status = fns->read(iorq->fd,
774                                                                     iorq->length, 0, &result);                                                                     iorq->buffer + iorq->partial_len,
775                                                  buffer_len = result;                                                                     iorq->length - iorq->partial_len,
776                                                                       0, &result);
777                                                  rdpdr_send_completion(iorq->device, iorq->id,                                                  iorq->partial_len += result;
                                                                       status, result, iorq->buffer,  
                                                                       buffer_len);  
778  #if WITH_DEBUG_RDP5  #if WITH_DEBUG_RDP5
779                                                  DEBUG(("RDPDR: %d bytes of data read\n", result));                                                  DEBUG(("RDPDR: %d bytes of data read\n", result));
780  #endif  #endif
781                                                  xfree(iorq->buffer);                                                  /* only delete link if all data has been transfered */
782                                                  iorq->fd = 0;                                                  if (iorq->partial_len == iorq->length)
783                                                    {
784                                                            /* send the data */
785                                                            status = STATUS_SUCCESS;
786                                                            rdpdr_send_completion(iorq->device,
787                                                                                  iorq->id, status,
788                                                                                  iorq->length,
789                                                                                  iorq->buffer, result);
790    
791                                                            xfree(iorq->buffer);
792                                                            iorq->fd = 0;
793                                                            if (prev != NULL)
794                                                            {
795                                                                    prev->next = iorq->next;
796                                                                    xfree(iorq);
797                                                            }
798                                                    }
799                                          }                                          }
800                                          break;                                          break;
   
801                                  case IRP_MJ_WRITE:                                  case IRP_MJ_WRITE:
   
802                                          if (FD_ISSET(iorq->fd, wfds))                                          if (FD_ISSET(iorq->fd, wfds))
803                                          {                                          {
804                                                  // Write data and send completion.                                                  /* Write data. */
805                                                  fns = iorq->fns;                                                  fns = iorq->fns;
806                                                  status = fns->write(iorq->fd, iorq->buffer,                                                  status = fns->write(iorq->fd,
807                                                                      iorq->length, 0, &result);                                                                      iorq->buffer +
808                                                  rdpdr_send_completion(iorq->device, iorq->id,                                                                      iorq->partial_len,
809                                                                        status, result, "", 1);                                                                      iorq->length -
810                                                                        iorq->partial_len, 0, &result);
811                                                  xfree(iorq->buffer);                                                  iorq->partial_len += result;
812                                                  iorq->fd = 0;  #if WITH_DEBUG_RDP5
813                                                    DEBUG(("RDPDR: %d bytes of data written\n",
814                                                           result));
815    #endif
816                                                    /* only delete link if all data has been transfered */
817                                                    if (iorq->partial_len == iorq->length)
818                                                    {
819                                                            /* send a status success */
820                                                            status = STATUS_SUCCESS;
821                                                            rdpdr_send_completion(iorq->device,
822                                                                                  iorq->id, status,
823                                                                                  iorq->length, "", 1);
824    
825                                                            xfree(iorq->buffer);
826                                                            iorq->fd = 0;
827                                                            if (prev != NULL)
828                                                            {
829                                                                    prev->next = iorq->next;
830                                                                    xfree(iorq);
831                                                            }
832                                                    }
833                                          }                                          }
834                                          break;                                          break;
835                          }                          }
836    
837                  }                  }
838                    prev = iorq;
839                    iorq = iorq->next;
840          }          }
841    
842  }  }
843    
844  /* Abort a pending io request for a given handle and major */  /* Abort a pending io request for a given handle and major */
# Line 795  BOOL Line 846  BOOL
846  rdpdr_abort_io(uint32 fd, uint32 major, NTSTATUS status)  rdpdr_abort_io(uint32 fd, uint32 major, NTSTATUS status)
847  {  {
848          uint32 result;          uint32 result;
         int i;  
849          struct async_iorequest *iorq;          struct async_iorequest *iorq;
850            struct async_iorequest *prev;
851    
852          for (i = 0; i < MAX_ASYNC_IO_REQUESTS; i++)          iorq = &g_iorequest;
853            prev = NULL;
854            while (iorq != NULL)
855          {          {
                 iorq = &g_iorequest[i];  
   
856                  // Only remove from table when major is not set, or when correct major is supplied.                  // Only remove from table when major is not set, or when correct major is supplied.
857                  // Abort read should not abort a write io request.                  // Abort read should not abort a write io request.
858                  if ((iorq->fd == fd) && (major == 0 || iorq->major == major))                  if ((iorq->fd == fd) && (major == 0 || iorq->major == major))
# Line 810  rdpdr_abort_io(uint32 fd, uint32 major, Line 861  rdpdr_abort_io(uint32 fd, uint32 major,
861                          rdpdr_send_completion(iorq->device, iorq->id, status, result, "", 1);                          rdpdr_send_completion(iorq->device, iorq->id, status, result, "", 1);
862                          xfree(iorq->buffer);                          xfree(iorq->buffer);
863                          iorq->fd = 0;                          iorq->fd = 0;
864                            if (prev != NULL)
865                            {
866                                    prev->next = iorq->next;
867                                    xfree(iorq);
868                            }
869                          return True;                          return True;
870                  }                  }
871    
872                    prev = iorq;
873                    iorq = iorq->next;
874          }          }
875    
876          return False;          return False;
877  }  }
 #endif  

Legend:
Removed from v.591  
changed lines
  Added in v.592

  ViewVC Help
Powered by ViewVC 1.1.26