/[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 592 by n-ki, Fri Jan 30 14:10:32 2004 UTC revision 613 by n-ki, Mon Feb 23 10:34:18 2004 UTC
# Line 1  Line 1 
1  #include <unistd.h>  #include <unistd.h>
2  #include <sys/types.h>  #include <sys/types.h>
3    #include <sys/time.h>
4  #include <time.h>  #include <time.h>
5  #include "rdesktop.h"  #include "rdesktop.h"
6    
# Line 49  struct async_iorequest Line 50  struct async_iorequest
50          DEVICE_FNS *fns;          DEVICE_FNS *fns;
51    
52          struct async_iorequest *next;   /* next element in list */          struct async_iorequest *next;   /* next element in list */
53  } g_iorequest;  };
54    
55    struct async_iorequest *g_iorequest;
56    
57  /* Return device_id for a given handle */  /* Return device_id for a given handle */
58  int  int
# Line 79  convert_to_unix_filename(char *filename) Line 82  convert_to_unix_filename(char *filename)
82  /* 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 */
83  BOOL  BOOL
84  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,
85                      DEVICE_FNS * fns, long total_timeout, long interval_timeout, uint8 * buffer)                      DEVICE_FNS * fns, uint32 total_timeout, uint32 interval_timeout, uint8 * buffer,
86                        uint32 offset)
87  {  {
88          struct async_iorequest *iorq;          struct async_iorequest *iorq;
89    
90          iorq = &g_iorequest;          if (g_iorequest == NULL)
         while (iorq->fd != 0)  
91          {          {
92                  // create new element if needed                  g_iorequest = (struct async_iorequest *) xmalloc(sizeof(struct async_iorequest));
93                  if (iorq->next == NULL)                  if (!g_iorequest)
94                          iorq->next =                          return False;
95                                  (struct async_iorequest *) xmalloc(sizeof(struct async_iorequest));                  g_iorequest->fd = 0;
96                    g_iorequest->next = NULL;
                 iorq = iorq->next;  
97          }          }
98    
99          /* first element is special since it doesn't get deleted */          iorq = g_iorequest;
100          /* don't want to get io out of order */  
101          if (g_iorequest.fd == 0)          while (iorq->fd != 0)
102          {          {
103                  iorq = &g_iorequest;                  // create new element if needed
104                  /* look for first occurrence of fd */                  if (iorq->next == NULL)
                 while (iorq->next != NULL)  
                 {  
                         if (iorq->fd == file)  
                                 break;  
                         iorq = iorq->next;  
                 }  
                 /* if same create new link at end of chain instead */  
                 if (iorq->fd == file)  
105                  {                  {
                         while (iorq->next != NULL)  
                                 iorq = iorq->next;  
106                          iorq->next =                          iorq->next =
107                                  (struct async_iorequest *) xmalloc(sizeof(struct async_iorequest));                                  (struct async_iorequest *) xmalloc(sizeof(struct async_iorequest));
108                          iorq = iorq->next;                          if (!iorq->next)
109                                    return False;
110                            iorq->next->fd = 0;
111                            iorq->next->next = NULL;
112                  }                  }
113                  else                  iorq = iorq->next;
                         iorq = &g_iorequest;    /* didn't find fs use first entry */  
114          }          }
   
115          iorq->device = device;          iorq->device = device;
116          iorq->fd = file;          iorq->fd = file;
117          iorq->id = id;          iorq->id = id;
# Line 129  add_async_iorequest(uint32 device, uint3 Line 122  add_async_iorequest(uint32 device, uint3
122          iorq->timeout = total_timeout;          iorq->timeout = total_timeout;
123          iorq->itv_timeout = interval_timeout;          iorq->itv_timeout = interval_timeout;
124          iorq->buffer = buffer;          iorq->buffer = buffer;
125            iorq->offset = offset;
126          return True;          return True;
127  }  }
128    
# Line 233  rdpdr_send_available(void) Line 227  rdpdr_send_available(void)
227                                  rdp_out_unistr(s, printerinfo->printer, printerlen - 2);                                  rdp_out_unistr(s, printerinfo->printer, printerlen - 2);
228                                  out_uint8a(s, printerinfo->blob, bloblen);                                  out_uint8a(s, printerinfo->blob, bloblen);
229    
230                                  xfree(printerinfo->blob);       /* Blob is sent twice if reconnecting */                                  if (printerinfo->blob)
231                                            xfree(printerinfo->blob);       /* Blob is sent twice if reconnecting */
232                                  break;                                  break;
233                          default:                          default:
234                                  out_uint32(s, 0);                                  out_uint32(s, 0);
# Line 329  rdpdr_process_irp(STREAM s) Line 324  rdpdr_process_irp(STREAM s)
324    
325                  case DEVICE_TYPE_DISK:                  case DEVICE_TYPE_DISK:
326    
                         /*rw_blocking = False; */  
327                          fns = &disk_fns;                          fns = &disk_fns;
328                            rw_blocking = False;
329                          break;                          break;
330    
331                  case DEVICE_TYPE_SCARD:                  case DEVICE_TYPE_SCARD:
# Line 399  rdpdr_process_irp(STREAM s) Line 394  rdpdr_process_irp(STREAM s)
394                          if (rw_blocking)        // Complete read immediately                          if (rw_blocking)        // Complete read immediately
395                          {                          {
396                                  buffer = (uint8 *) xrealloc((void *) buffer, length);                                  buffer = (uint8 *) xrealloc((void *) buffer, length);
397                                    if (!buffer)
398                                    {
399                                            status = STATUS_CANCELLED;
400                                            break;
401                                    }
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;
# Line 406  rdpdr_process_irp(STREAM s) Line 406  rdpdr_process_irp(STREAM s)
406    
407                          // Add request to table                          // Add request to table
408                          pst_buf = (uint8 *) xmalloc(length);                          pst_buf = (uint8 *) xmalloc(length);
409                            if (!pst_buf)
410                            {
411                                    status = STATUS_CANCELLED;
412                                    break;
413                            }
414                          serial_get_timeout(file, length, &total_timeout, &interval_timeout);                          serial_get_timeout(file, length, &total_timeout, &interval_timeout);
415                          if (add_async_iorequest                          if (add_async_iorequest
416                              (device, file, id, major, length, fns, total_timeout, interval_timeout,                              (device, file, id, major, length, fns, total_timeout, interval_timeout,
417                               pst_buf))                               pst_buf, offset))
418                          {                          {
419                                  status = STATUS_PENDING;                                  status = STATUS_PENDING;
420                                  break;                                  break;
# Line 441  rdpdr_process_irp(STREAM s) Line 446  rdpdr_process_irp(STREAM s)
446    
447                          // Add to table                          // Add to table
448                          pst_buf = (uint8 *) xmalloc(length);                          pst_buf = (uint8 *) xmalloc(length);
449                            if (!pst_buf)
450                            {
451                                    status = STATUS_CANCELLED;
452                                    break;
453                            }
454    
455                          in_uint8a(s, pst_buf, length);                          in_uint8a(s, pst_buf, length);
456    
457                          if (add_async_iorequest                          if (add_async_iorequest
458                              (device, file, id, major, length, fns, 0, 0, pst_buf))                              (device, file, id, major, length, fns, 0, 0, pst_buf, offset))
459                          {                          {
460                                  status = STATUS_PENDING;                                  status = STATUS_PENDING;
461                                  break;                                  break;
# Line 564  rdpdr_process_irp(STREAM s) Line 575  rdpdr_process_irp(STREAM s)
575                          in_uint8s(s, 0x14);                          in_uint8s(s, 0x14);
576    
577                          buffer = (uint8 *) xrealloc((void *) buffer, bytes_out + 0x14);                          buffer = (uint8 *) xrealloc((void *) buffer, bytes_out + 0x14);
578                            if (!buffer)
579                            {
580                                    status = STATUS_CANCELLED;
581                                    break;
582                            }
583    
584                          out.data = out.p = buffer;                          out.data = out.p = buffer;
585                          out.size = sizeof(buffer);                          out.size = sizeof(buffer);
586                          status = fns->device_control(file, request, s, &out);                          status = fns->device_control(file, request, s, &out);
# Line 579  rdpdr_process_irp(STREAM s) Line 596  rdpdr_process_irp(STREAM s)
596          {          {
597                  rdpdr_send_completion(device, id, status, result, buffer, buffer_len);                  rdpdr_send_completion(device, id, status, result, buffer, buffer_len);
598          }          }
599          xfree(buffer);          if (buffer)
600                    xfree(buffer);
601            buffer = NULL;
602  }  }
603    
604  void  void
# Line 699  rdpdr_init() Line 717  rdpdr_init()
717  void  void
718  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)
719  {  {
720          long select_timeout = 0;        // Timeout value to be used for select() (in millisecons).          uint32 select_timeout = 0;      // Timeout value to be used for select() (in millisecons).
721          struct async_iorequest *iorq;          struct async_iorequest *iorq;
722    
723          iorq = &g_iorequest;          iorq = g_iorequest;
724          while (iorq != NULL)          while (iorq != NULL)
725          {          {
726                  if (iorq->fd != 0)                  if (iorq->fd != 0)
# Line 749  rdpdr_check_fds(fd_set * rfds, fd_set * Line 767  rdpdr_check_fds(fd_set * rfds, fd_set *
767          DEVICE_FNS *fns;          DEVICE_FNS *fns;
768          struct async_iorequest *iorq;          struct async_iorequest *iorq;
769          struct async_iorequest *prev;          struct async_iorequest *prev;
770            uint32 req_size = 0;
771    
772          if (timed_out)          if (timed_out)
773          {          {
# Line 756  rdpdr_check_fds(fd_set * rfds, fd_set * Line 775  rdpdr_check_fds(fd_set * rfds, fd_set *
775                  return;                  return;
776          }          }
777    
778          iorq = &g_iorequest;          iorq = g_iorequest;
779          prev = NULL;          prev = NULL;
780          while (iorq != NULL)          while (iorq != NULL)
781          {          {
   
782                  if (iorq->fd != 0)                  if (iorq->fd != 0)
783                  {                  {
784                          switch (iorq->major)                          switch (iorq->major)
# Line 770  rdpdr_check_fds(fd_set * rfds, fd_set * Line 788  rdpdr_check_fds(fd_set * rfds, fd_set *
788                                          {                                          {
789                                                  /* Read the data */                                                  /* Read the data */
790                                                  fns = iorq->fns;                                                  fns = iorq->fns;
791    
792                                                    req_size =
793                                                            (iorq->length - iorq->partial_len) >
794                                                            8192 ? 8192 : (iorq->length -
795                                                                           iorq->partial_len);
796                                                    /* never read larger chunks than 8k - chances are that it will block */
797                                                  status = fns->read(iorq->fd,                                                  status = fns->read(iorq->fd,
798                                                                     iorq->buffer + iorq->partial_len,                                                                     iorq->buffer + iorq->partial_len,
799                                                                     iorq->length - iorq->partial_len,                                                                     req_size, iorq->offset, &result);
                                                                    0, &result);  
800                                                  iorq->partial_len += result;                                                  iorq->partial_len += result;
801                                                    iorq->offset += result;
802    
803  #if WITH_DEBUG_RDP5  #if WITH_DEBUG_RDP5
804                                                  DEBUG(("RDPDR: %d bytes of data read\n", result));                                                  DEBUG(("RDPDR: %d bytes of data read\n", result));
805  #endif  #endif
806                                                  /* only delete link if all data has been transfered */                                                  /* only delete link if all data has been transfered */
807                                                  if (iorq->partial_len == iorq->length)                                                  /* or if result was 0 and status success - EOF      */
808                                                    if ((iorq->partial_len == iorq->length) ||
809                                                        (result == 0))
810                                                  {                                                  {
811    #if WITH_DEBUG_RDP5
812                                                            DEBUG(("RDPDR: AIO total %u bytes read of %u\n", iorq->partial_len, iorq->length));
813    #endif
814                                                          /* send the data */                                                          /* send the data */
815                                                          status = STATUS_SUCCESS;                                                          status = STATUS_SUCCESS;
816                                                          rdpdr_send_completion(iorq->device,                                                          rdpdr_send_completion(iorq->device,
817                                                                                iorq->id, status,                                                                                iorq->id, status,
818                                                                                iorq->length,                                                                                iorq->partial_len,
819                                                                                iorq->buffer, result);                                                                                iorq->buffer,
820                                                                                  iorq->partial_len);
821                                                          xfree(iorq->buffer);                                                          xfree(iorq->buffer);
822                                                          iorq->fd = 0;                                                          iorq->fd = 0;
823                                                          if (prev != NULL)                                                          if (prev != NULL)
# Line 795  rdpdr_check_fds(fd_set * rfds, fd_set * Line 825  rdpdr_check_fds(fd_set * rfds, fd_set *
825                                                                  prev->next = iorq->next;                                                                  prev->next = iorq->next;
826                                                                  xfree(iorq);                                                                  xfree(iorq);
827                                                          }                                                          }
828                                                            else
829                                                            {
830                                                                    // Even if NULL
831                                                                    g_iorequest = iorq->next;
832                                                                    xfree(iorq);
833                                                            }
834                                                  }                                                  }
835                                          }                                          }
836                                          break;                                          break;
# Line 803  rdpdr_check_fds(fd_set * rfds, fd_set * Line 839  rdpdr_check_fds(fd_set * rfds, fd_set *
839                                          {                                          {
840                                                  /* Write data. */                                                  /* Write data. */
841                                                  fns = iorq->fns;                                                  fns = iorq->fns;
842    
843                                                    req_size =
844                                                            (iorq->length - iorq->partial_len) >
845                                                            8192 ? 8192 : (iorq->length -
846                                                                           iorq->partial_len);
847    
848                                                    /* never write larger chunks than 8k - chances are that it will block */
849                                                  status = fns->write(iorq->fd,                                                  status = fns->write(iorq->fd,
850                                                                      iorq->buffer +                                                                      iorq->buffer +
851                                                                      iorq->partial_len,                                                                      iorq->partial_len, req_size,
852                                                                      iorq->length -                                                                      iorq->offset, &result);
                                                                     iorq->partial_len, 0, &result);  
853                                                  iorq->partial_len += result;                                                  iorq->partial_len += result;
854                                                    iorq->offset += result;
855  #if WITH_DEBUG_RDP5  #if WITH_DEBUG_RDP5
856                                                  DEBUG(("RDPDR: %d bytes of data written\n",                                                  DEBUG(("RDPDR: %d bytes of data written\n",
857                                                         result));                                                         result));
858  #endif  #endif
859                                                  /* only delete link if all data has been transfered */                                                  /* only delete link if all data has been transfered */
860                                                  if (iorq->partial_len == iorq->length)                                                  /* or we couldn't write */
861                                                    if ((iorq->partial_len == iorq->length)
862                                                        || (result == 0))
863                                                  {                                                  {
864    #if WITH_DEBUG_RDP5
865                                                            DEBUG(("RDPDR: AIO total %u bytes written of %u\n", iorq->partial_len, iorq->length));
866    #endif
867                                                          /* send a status success */                                                          /* send a status success */
868                                                          status = STATUS_SUCCESS;                                                          status = STATUS_SUCCESS;
869                                                          rdpdr_send_completion(iorq->device,                                                          rdpdr_send_completion(iorq->device,
870                                                                                iorq->id, status,                                                                                iorq->id, status,
871                                                                                iorq->length, "", 1);                                                                                iorq->partial_len,
872                                                                                  (uint8 *) "", 1);
873    
874                                                          xfree(iorq->buffer);                                                          xfree(iorq->buffer);
875                                                          iorq->fd = 0;                                                          iorq->fd = 0;
# Line 829  rdpdr_check_fds(fd_set * rfds, fd_set * Line 878  rdpdr_check_fds(fd_set * rfds, fd_set *
878                                                                  prev->next = iorq->next;                                                                  prev->next = iorq->next;
879                                                                  xfree(iorq);                                                                  xfree(iorq);
880                                                          }                                                          }
881                                                            else
882                                                            {
883                                                                    // Even if NULL
884                                                                    g_iorequest = iorq->next;
885                                                                    xfree(iorq);
886                                                            }
887                                                  }                                                  }
888                                          }                                          }
889                                          break;                                          break;
# Line 849  rdpdr_abort_io(uint32 fd, uint32 major, Line 904  rdpdr_abort_io(uint32 fd, uint32 major,
904          struct async_iorequest *iorq;          struct async_iorequest *iorq;
905          struct async_iorequest *prev;          struct async_iorequest *prev;
906    
907          iorq = &g_iorequest;          iorq = g_iorequest;
908          prev = NULL;          prev = NULL;
909          while (iorq != NULL)          while (iorq != NULL)
910          {          {
# Line 858  rdpdr_abort_io(uint32 fd, uint32 major, Line 913  rdpdr_abort_io(uint32 fd, uint32 major,
913                  if ((iorq->fd == fd) && (major == 0 || iorq->major == major))                  if ((iorq->fd == fd) && (major == 0 || iorq->major == major))
914                  {                  {
915                          result = 0;                          result = 0;
916                          rdpdr_send_completion(iorq->device, iorq->id, status, result, "", 1);                          rdpdr_send_completion(iorq->device, iorq->id, status, result, (uint8 *) "",
917                                                  1);
918                          xfree(iorq->buffer);                          xfree(iorq->buffer);
919                          iorq->fd = 0;                          iorq->fd = 0;
920                          if (prev != NULL)                          if (prev != NULL)
# Line 866  rdpdr_abort_io(uint32 fd, uint32 major, Line 922  rdpdr_abort_io(uint32 fd, uint32 major,
922                                  prev->next = iorq->next;                                  prev->next = iorq->next;
923                                  xfree(iorq);                                  xfree(iorq);
924                          }                          }
925                            else
926                            {
927                                    // Even if NULL
928                                    g_iorequest = iorq->next;
929                                    xfree(iorq);
930                            }
931                          return True;                          return True;
932                  }                  }
933    

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

  ViewVC Help
Powered by ViewVC 1.1.26