/[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 612 by n-ki, Mon Feb 23 09:58:16 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  {  {
87          struct async_iorequest *iorq;          struct async_iorequest *iorq;
88    
89          iorq = &g_iorequest;          if (g_iorequest == NULL)
         while (iorq->fd != 0)  
90          {          {
91                  // create new element if needed                  g_iorequest = (struct async_iorequest *) xmalloc(sizeof(struct async_iorequest));
92                  if (iorq->next == NULL)                  if (!g_iorequest)
93                          iorq->next =                          return False;
94                                  (struct async_iorequest *) xmalloc(sizeof(struct async_iorequest));                  g_iorequest->fd = 0;
95                    g_iorequest->next = NULL;
                 iorq = iorq->next;  
96          }          }
97    
98          /* first element is special since it doesn't get deleted */          iorq = g_iorequest;
99          /* don't want to get io out of order */  
100          if (g_iorequest.fd == 0)          while (iorq->fd != 0)
101          {          {
102                  iorq = &g_iorequest;                  // create new element if needed
103                  /* 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)  
104                  {                  {
                         while (iorq->next != NULL)  
                                 iorq = iorq->next;  
105                          iorq->next =                          iorq->next =
106                                  (struct async_iorequest *) xmalloc(sizeof(struct async_iorequest));                                  (struct async_iorequest *) xmalloc(sizeof(struct async_iorequest));
107                          iorq = iorq->next;                          if (!iorq->next)
108                                    return False;
109                            iorq->next->fd = 0;
110                            iorq->next->next = NULL;
111                  }                  }
112                  else                  iorq = iorq->next;
                         iorq = &g_iorequest;    /* didn't find fs use first entry */  
113          }          }
   
114          iorq->device = device;          iorq->device = device;
115          iorq->fd = file;          iorq->fd = file;
116          iorq->id = id;          iorq->id = id;
# Line 233  rdpdr_send_available(void) Line 225  rdpdr_send_available(void)
225                                  rdp_out_unistr(s, printerinfo->printer, printerlen - 2);                                  rdp_out_unistr(s, printerinfo->printer, printerlen - 2);
226                                  out_uint8a(s, printerinfo->blob, bloblen);                                  out_uint8a(s, printerinfo->blob, bloblen);
227    
228                                  xfree(printerinfo->blob);       /* Blob is sent twice if reconnecting */                                  if (printerinfo->blob)
229                                            xfree(printerinfo->blob);       /* Blob is sent twice if reconnecting */
230                                  break;                                  break;
231                          default:                          default:
232                                  out_uint32(s, 0);                                  out_uint32(s, 0);
# Line 329  rdpdr_process_irp(STREAM s) Line 322  rdpdr_process_irp(STREAM s)
322    
323                  case DEVICE_TYPE_DISK:                  case DEVICE_TYPE_DISK:
324    
                         /*rw_blocking = False; */  
325                          fns = &disk_fns;                          fns = &disk_fns;
326                            rw_blocking = False;
327                          break;                          break;
328    
329                  case DEVICE_TYPE_SCARD:                  case DEVICE_TYPE_SCARD:
# Line 399  rdpdr_process_irp(STREAM s) Line 392  rdpdr_process_irp(STREAM s)
392                          if (rw_blocking)        // Complete read immediately                          if (rw_blocking)        // Complete read immediately
393                          {                          {
394                                  buffer = (uint8 *) xrealloc((void *) buffer, length);                                  buffer = (uint8 *) xrealloc((void *) buffer, length);
395                                    if (!buffer)
396                                    {
397                                            status = STATUS_CANCELLED;
398                                            break;
399                                    }
400                                  status = fns->read(file, buffer, length, offset, &result);                                  status = fns->read(file, buffer, length, offset, &result);
401                                  buffer_len = result;                                  buffer_len = result;
402                                  break;                                  break;
# Line 406  rdpdr_process_irp(STREAM s) Line 404  rdpdr_process_irp(STREAM s)
404    
405                          // Add request to table                          // Add request to table
406                          pst_buf = (uint8 *) xmalloc(length);                          pst_buf = (uint8 *) xmalloc(length);
407                            if (!pst_buf)
408                            {
409                                    status = STATUS_CANCELLED;
410                                    break;
411                            }
412                          serial_get_timeout(file, length, &total_timeout, &interval_timeout);                          serial_get_timeout(file, length, &total_timeout, &interval_timeout);
413                          if (add_async_iorequest                          if (add_async_iorequest
414                              (device, file, id, major, length, fns, total_timeout, interval_timeout,                              (device, file, id, major, length, fns, total_timeout, interval_timeout,
# Line 441  rdpdr_process_irp(STREAM s) Line 444  rdpdr_process_irp(STREAM s)
444    
445                          // Add to table                          // Add to table
446                          pst_buf = (uint8 *) xmalloc(length);                          pst_buf = (uint8 *) xmalloc(length);
447                            if (!pst_buf)
448                            {
449                                    status = STATUS_CANCELLED;
450                                    break;
451                            }
452    
453                          in_uint8a(s, pst_buf, length);                          in_uint8a(s, pst_buf, length);
454    
455                          if (add_async_iorequest                          if (add_async_iorequest
# Line 564  rdpdr_process_irp(STREAM s) Line 573  rdpdr_process_irp(STREAM s)
573                          in_uint8s(s, 0x14);                          in_uint8s(s, 0x14);
574    
575                          buffer = (uint8 *) xrealloc((void *) buffer, bytes_out + 0x14);                          buffer = (uint8 *) xrealloc((void *) buffer, bytes_out + 0x14);
576                            if (!buffer)
577                            {
578                                    status = STATUS_CANCELLED;
579                                    break;
580                            }
581    
582                          out.data = out.p = buffer;                          out.data = out.p = buffer;
583                          out.size = sizeof(buffer);                          out.size = sizeof(buffer);
584                          status = fns->device_control(file, request, s, &out);                          status = fns->device_control(file, request, s, &out);
# Line 579  rdpdr_process_irp(STREAM s) Line 594  rdpdr_process_irp(STREAM s)
594          {          {
595                  rdpdr_send_completion(device, id, status, result, buffer, buffer_len);                  rdpdr_send_completion(device, id, status, result, buffer, buffer_len);
596          }          }
597          xfree(buffer);          if (buffer)
598                    xfree(buffer);
599            buffer = NULL;
600  }  }
601    
602  void  void
# Line 699  rdpdr_init() Line 715  rdpdr_init()
715  void  void
716  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)
717  {  {
718          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).
719          struct async_iorequest *iorq;          struct async_iorequest *iorq;
720    
721          iorq = &g_iorequest;          iorq = g_iorequest;
722          while (iorq != NULL)          while (iorq != NULL)
723          {          {
724                  if (iorq->fd != 0)                  if (iorq->fd != 0)
# Line 749  rdpdr_check_fds(fd_set * rfds, fd_set * Line 765  rdpdr_check_fds(fd_set * rfds, fd_set *
765          DEVICE_FNS *fns;          DEVICE_FNS *fns;
766          struct async_iorequest *iorq;          struct async_iorequest *iorq;
767          struct async_iorequest *prev;          struct async_iorequest *prev;
768            uint32 req_size = 0;
769    
770          if (timed_out)          if (timed_out)
771          {          {
# Line 756  rdpdr_check_fds(fd_set * rfds, fd_set * Line 773  rdpdr_check_fds(fd_set * rfds, fd_set *
773                  return;                  return;
774          }          }
775    
776          iorq = &g_iorequest;          iorq = g_iorequest;
777          prev = NULL;          prev = NULL;
778          while (iorq != NULL)          while (iorq != NULL)
779          {          {
   
780                  if (iorq->fd != 0)                  if (iorq->fd != 0)
781                  {                  {
782                          switch (iorq->major)                          switch (iorq->major)
# Line 770  rdpdr_check_fds(fd_set * rfds, fd_set * Line 786  rdpdr_check_fds(fd_set * rfds, fd_set *
786                                          {                                          {
787                                                  /* Read the data */                                                  /* Read the data */
788                                                  fns = iorq->fns;                                                  fns = iorq->fns;
789    
790                                                    req_size =
791                                                            (iorq->length - iorq->partial_len) >
792                                                            8192 ? 8192 : (iorq->length -
793                                                                           iorq->partial_len);
794                                                    /* never read larger chunks than 8k - chances are that it will block */
795                                                  status = fns->read(iorq->fd,                                                  status = fns->read(iorq->fd,
796                                                                     iorq->buffer + iorq->partial_len,                                                                     iorq->buffer + iorq->partial_len,
797                                                                     iorq->length - iorq->partial_len,                                                                     req_size, 0, &result);
                                                                    0, &result);  
798                                                  iorq->partial_len += result;                                                  iorq->partial_len += result;
799    
800  #if WITH_DEBUG_RDP5  #if WITH_DEBUG_RDP5
801                                                  DEBUG(("RDPDR: %d bytes of data read\n", result));                                                  DEBUG(("RDPDR: %d bytes of data read\n", result));
802  #endif  #endif
803                                                  /* only delete link if all data has been transfered */                                                  /* only delete link if all data has been transfered */
804                                                  if (iorq->partial_len == iorq->length)                                                  /* or if result was 0 and status success - EOF      */
805                                                    if ((iorq->partial_len == iorq->length) ||
806                                                        (result == 0))
807                                                  {                                                  {
808    #if WITH_DEBUG_RDP5
809                                                            DEBUG(("RDPDR: AIO total %u bytes read of %u\n", iorq->partial_len, iorq->length));
810    #endif
811                                                          /* send the data */                                                          /* send the data */
812                                                          status = STATUS_SUCCESS;                                                          status = STATUS_SUCCESS;
813                                                          rdpdr_send_completion(iorq->device,                                                          rdpdr_send_completion(iorq->device,
814                                                                                iorq->id, status,                                                                                iorq->id, status,
815                                                                                iorq->length,                                                                                iorq->partial_len,
816                                                                                iorq->buffer, result);                                                                                iorq->buffer,
817                                                                                  iorq->partial_len);
818                                                          xfree(iorq->buffer);                                                          xfree(iorq->buffer);
819                                                          iorq->fd = 0;                                                          iorq->fd = 0;
820                                                          if (prev != NULL)                                                          if (prev != NULL)
# Line 795  rdpdr_check_fds(fd_set * rfds, fd_set * Line 822  rdpdr_check_fds(fd_set * rfds, fd_set *
822                                                                  prev->next = iorq->next;                                                                  prev->next = iorq->next;
823                                                                  xfree(iorq);                                                                  xfree(iorq);
824                                                          }                                                          }
825                                                            else
826                                                            {
827                                                                    // Even if NULL
828                                                                    g_iorequest = iorq->next;
829                                                                    xfree(iorq);
830                                                            }
831                                                  }                                                  }
832                                          }                                          }
833                                          break;                                          break;
# Line 803  rdpdr_check_fds(fd_set * rfds, fd_set * Line 836  rdpdr_check_fds(fd_set * rfds, fd_set *
836                                          {                                          {
837                                                  /* Write data. */                                                  /* Write data. */
838                                                  fns = iorq->fns;                                                  fns = iorq->fns;
839    
840                                                    req_size =
841                                                            (iorq->length - iorq->partial_len) >
842                                                            8192 ? 8192 : (iorq->length -
843                                                                           iorq->partial_len);
844    
845                                                    /* never write larger chunks than 8k - chances are that it will block */
846                                                  status = fns->write(iorq->fd,                                                  status = fns->write(iorq->fd,
847                                                                      iorq->buffer +                                                                      iorq->buffer +
848                                                                      iorq->partial_len,                                                                      iorq->partial_len, req_size, 0,
849                                                                      iorq->length -                                                                      &result);
                                                                     iorq->partial_len, 0, &result);  
850                                                  iorq->partial_len += result;                                                  iorq->partial_len += result;
851  #if WITH_DEBUG_RDP5  #if WITH_DEBUG_RDP5
852                                                  DEBUG(("RDPDR: %d bytes of data written\n",                                                  DEBUG(("RDPDR: %d bytes of data written\n",
853                                                         result));                                                         result));
854  #endif  #endif
855                                                  /* only delete link if all data has been transfered */                                                  /* only delete link if all data has been transfered */
856                                                  if (iorq->partial_len == iorq->length)                                                  /* or we couldn't write */
857                                                    if ((iorq->partial_len == iorq->length)
858                                                        || (result == 0))
859                                                  {                                                  {
860    #if WITH_DEBUG_RDP5
861                                                            DEBUG(("RDPDR: AIO total %u bytes written of %u\n", iorq->partial_len, iorq->length));
862    #endif
863                                                          /* send a status success */                                                          /* send a status success */
864                                                          status = STATUS_SUCCESS;                                                          status = STATUS_SUCCESS;
865                                                          rdpdr_send_completion(iorq->device,                                                          rdpdr_send_completion(iorq->device,
866                                                                                iorq->id, status,                                                                                iorq->id, status,
867                                                                                iorq->length, "", 1);                                                                                iorq->partial_len,
868                                                                                  (uint8 *) "", 1);
869    
870                                                          xfree(iorq->buffer);                                                          xfree(iorq->buffer);
871                                                          iorq->fd = 0;                                                          iorq->fd = 0;
# Line 829  rdpdr_check_fds(fd_set * rfds, fd_set * Line 874  rdpdr_check_fds(fd_set * rfds, fd_set *
874                                                                  prev->next = iorq->next;                                                                  prev->next = iorq->next;
875                                                                  xfree(iorq);                                                                  xfree(iorq);
876                                                          }                                                          }
877                                                            else
878                                                            {
879                                                                    // Even if NULL
880                                                                    g_iorequest = iorq->next;
881                                                                    xfree(iorq);
882                                                            }
883                                                  }                                                  }
884                                          }                                          }
885                                          break;                                          break;
# Line 849  rdpdr_abort_io(uint32 fd, uint32 major, Line 900  rdpdr_abort_io(uint32 fd, uint32 major,
900          struct async_iorequest *iorq;          struct async_iorequest *iorq;
901          struct async_iorequest *prev;          struct async_iorequest *prev;
902    
903          iorq = &g_iorequest;          iorq = g_iorequest;
904          prev = NULL;          prev = NULL;
905          while (iorq != NULL)          while (iorq != NULL)
906          {          {
# Line 858  rdpdr_abort_io(uint32 fd, uint32 major, Line 909  rdpdr_abort_io(uint32 fd, uint32 major,
909                  if ((iorq->fd == fd) && (major == 0 || iorq->major == major))                  if ((iorq->fd == fd) && (major == 0 || iorq->major == major))
910                  {                  {
911                          result = 0;                          result = 0;
912                          rdpdr_send_completion(iorq->device, iorq->id, status, result, "", 1);                          rdpdr_send_completion(iorq->device, iorq->id, status, result, (uint8 *) "",
913                                                  1);
914                          xfree(iorq->buffer);                          xfree(iorq->buffer);
915                          iorq->fd = 0;                          iorq->fd = 0;
916                          if (prev != NULL)                          if (prev != NULL)
# Line 866  rdpdr_abort_io(uint32 fd, uint32 major, Line 918  rdpdr_abort_io(uint32 fd, uint32 major,
918                                  prev->next = iorq->next;                                  prev->next = iorq->next;
919                                  xfree(iorq);                                  xfree(iorq);
920                          }                          }
921                            else
922                            {
923                                    // Even if NULL
924                                    g_iorequest = iorq->next;
925                                    xfree(iorq);
926                            }
927                          return True;                          return True;
928                  }                  }
929    

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

  ViewVC Help
Powered by ViewVC 1.1.26