/[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 794 by jsorg71, Sat Oct 2 01:30:33 2004 UTC revision 795 by stargo, Wed Nov 3 13:56:52 2004 UTC
# Line 61  extern DEVICE_FNS printer_fns; Line 61  extern DEVICE_FNS printer_fns;
61  extern DEVICE_FNS parallel_fns;  extern DEVICE_FNS parallel_fns;
62  extern DEVICE_FNS disk_fns;  extern DEVICE_FNS disk_fns;
63  extern FILEINFO g_fileinfo[];  extern FILEINFO g_fileinfo[];
64    extern BOOL g_notify_stamp;
65    
66  static VCHANNEL *rdpdr_channel;  static VCHANNEL *rdpdr_channel;
67    
# Line 323  rdpdr_send_completion(uint32 device, uin Line 324  rdpdr_send_completion(uint32 device, uin
324          out_uint32_le(s, result);          out_uint32_le(s, result);
325          out_uint8p(s, buffer, length);          out_uint8p(s, buffer, length);
326          s_mark_end(s);          s_mark_end(s);
327          /* JIF          /* JIF */
328             hexdump(s->channel_hdr + 8, s->end - s->channel_hdr - 8); */  #ifdef WITH_DEBUG_RDP5
329            printf("--> rdpdr_send_completion\n");
330            //hexdump(s->channel_hdr + 8, s->end - s->channel_hdr - 8);
331    #endif
332          channel_send(s, rdpdr_channel);          channel_send(s, rdpdr_channel);
333  }  }
334    
# Line 623  rdpdr_process_irp(STREAM s) Line 627  rdpdr_process_irp(STREAM s)
627                                  case IRP_MN_NOTIFY_CHANGE_DIRECTORY:                                  case IRP_MN_NOTIFY_CHANGE_DIRECTORY:
628    
629                                          /* JIF                                          /* JIF
630                                             unimpl("IRP major=0x%x minor=0x%x: IRP_MN_NOTIFY_CHANGE_DIRECTORY\n", major, minor); */                                             unimpl("IRP major=0x%x minor=0x%x: IRP_MN_NOTIFY_CHANGE_DIRECTORY\n", major, minor);  */
631                                          status = STATUS_PENDING;        // Don't send completion packet  
632                                            in_uint32_le(s, info_level);    // notify mask
633    
634                                            g_notify_stamp = True;
635    
636                                            status = disk_create_notify(file, info_level);
637                                            result = 0;
638    
639                                            if (status == STATUS_PENDING)
640                                                    add_async_iorequest(device, file, id, major, length,
641                                                                        fns, 0, 0, NULL, 0);
642                                          break;                                          break;
643    
644                                  default:                                  default:
645    
646                                          status = STATUS_INVALID_PARAMETER;                                          status = STATUS_INVALID_PARAMETER;
647                                          /* JIF                                          /* JIF */
648                                             unimpl("IRP major=0x%x minor=0x%x\n", major, minor); */                                          unimpl("IRP major=0x%x minor=0x%x\n", major, minor);
649                          }                          }
650                          break;                          break;
651    
# Line 659  rdpdr_process_irp(STREAM s) Line 673  rdpdr_process_irp(STREAM s)
673                          out.size = sizeof(buffer);                          out.size = sizeof(buffer);
674                          status = fns->device_control(file, request, s, &out);                          status = fns->device_control(file, request, s, &out);
675                          result = buffer_len = out.p - out.data;                          result = buffer_len = out.p - out.data;
676    
677                            /* Serial SERIAL_WAIT_ON_MASK */
678                            if (status == STATUS_PENDING)
679                            {
680                                    if (add_async_iorequest
681                                        (device, file, id, major, length, fns, 0, 0, NULL, 0))
682                                    {
683                                            status = STATUS_PENDING;
684                                            break;
685                                    }
686                            }
687                          break;                          break;
688    
689    
# Line 827  rdpdr_add_fds(int *n, fd_set * rfds, fd_ Line 852  rdpdr_add_fds(int *n, fd_set * rfds, fd_
852                                             reconnecting. FIXME: Real                                             reconnecting. FIXME: Real
853                                             support for reconnects. */                                             support for reconnects. */
854    
                                         if ((read(iorq->fd, &c, 0) != 0) && (errno == EBADF))  
                                                 break;  
   
855                                          FD_SET(iorq->fd, rfds);                                          FD_SET(iorq->fd, rfds);
856                                          *n = MAX(*n, iorq->fd);                                          *n = MAX(*n, iorq->fd);
857    
858                                          // Check if io request timeout is smaller than current (but not 0).                                          /* Check if io request timeout is smaller than current (but not 0). */
859                                          if (iorq->timeout                                          if (iorq->timeout
860                                              && (select_timeout == 0                                              && (select_timeout == 0
861                                                  || iorq->timeout < select_timeout))                                                  || iorq->timeout < select_timeout))
862                                          {                                          {
863                                                  // Set new timeout                                                  /* Set new timeout */
864                                                  select_timeout = iorq->timeout;                                                  select_timeout = iorq->timeout;
865                                                  g_min_timeout_fd = iorq->fd;    /* Remember fd */                                                  g_min_timeout_fd = iorq->fd;    /* Remember fd */
866                                                  tv->tv_sec = select_timeout / 1000;                                                  tv->tv_sec = select_timeout / 1000;
867                                                  tv->tv_usec = (select_timeout % 1000) * 1000;                                                  tv->tv_usec = (select_timeout % 1000) * 1000;
868                                                  *timeout = True;                                                  *timeout = True;
869                                                    break;
870                                            }
871                                            if (iorq->itv_timeout && iorq->partial_len > 0
872                                                && (select_timeout == 0
873                                                    || iorq->itv_timeout < select_timeout))
874                                            {
875                                                    /* Set new timeout */
876                                                    select_timeout = iorq->itv_timeout;
877                                                    g_min_timeout_fd = iorq->fd;    /* Remember fd */
878                                                    tv->tv_sec = select_timeout / 1000;
879                                                    tv->tv_usec = (select_timeout % 1000) * 1000;
880                                                    *timeout = True;
881                                                    break;
882                                          }                                          }
   
883                                          break;                                          break;
884    
885                                  case IRP_MJ_WRITE:                                  case IRP_MJ_WRITE:
# Line 857  rdpdr_add_fds(int *n, fd_set * rfds, fd_ Line 891  rdpdr_add_fds(int *n, fd_set * rfds, fd_
891                                          *n = MAX(*n, iorq->fd);                                          *n = MAX(*n, iorq->fd);
892                                          break;                                          break;
893    
894                                    case IRP_MJ_DEVICE_CONTROL:
895                                            if (select_timeout > 5)
896                                                    select_timeout = 5;     /* serial event queue */
897                                            break;
898    
899                          }                          }
900    
901                  }                  }
# Line 891  rdpdr_remove_iorequest(struct async_iore Line 930  rdpdr_remove_iorequest(struct async_iore
930    
931  /* Check if select() returned with one of the rdpdr file descriptors, and complete io if it did */  /* Check if select() returned with one of the rdpdr file descriptors, and complete io if it did */
932  void  void
933  rdpdr_check_fds(fd_set * rfds, fd_set * wfds, BOOL timed_out)  _rdpdr_check_fds(fd_set * rfds, fd_set * wfds, BOOL timed_out)
934  {  {
935          NTSTATUS status;          NTSTATUS status;
936          uint32 result = 0;          uint32 result = 0;
# Line 899  rdpdr_check_fds(fd_set * rfds, fd_set * Line 938  rdpdr_check_fds(fd_set * rfds, fd_set *
938          struct async_iorequest *iorq;          struct async_iorequest *iorq;
939          struct async_iorequest *prev;          struct async_iorequest *prev;
940          uint32 req_size = 0;          uint32 req_size = 0;
941            uint32 buffer_len;
942            struct stream out;
943            uint8 *buffer = NULL;
944    
945    
946          if (timed_out)          if (timed_out)
947          {          {
948                    /* check serial iv_timeout */
949    
950                    iorq = g_iorequest;
951                    prev = NULL;
952                    while (iorq != NULL)
953                    {
954                            if (iorq->fd == g_min_timeout_fd)
955                            {
956                                    if ((iorq->partial_len > 0) &&
957                                        (g_rdpdr_device[iorq->device].device_type ==
958                                         DEVICE_TYPE_SERIAL))
959                                    {
960    
961                                            /* iv_timeout between 2 chars, send partial_len */
962                                            //printf("RDPDR: IVT total %u bytes read of %u\n", iorq->partial_len, iorq->length);
963                                            rdpdr_send_completion(iorq->device,
964                                                                  iorq->id, STATUS_SUCCESS,
965                                                                  iorq->partial_len,
966                                                                  iorq->buffer, iorq->partial_len);
967                                            iorq = rdpdr_remove_iorequest(prev, iorq);
968                                            return;
969                                    }
970                                    else
971                                    {
972                                            break;
973                                    }
974    
975                            }
976                            else
977                            {
978                                    break;
979                            }
980    
981    
982                            prev = iorq;
983                            if (iorq)
984                                    iorq = iorq->next;
985    
986                    }
987    
988                  rdpdr_abort_io(g_min_timeout_fd, 0, STATUS_TIMEOUT);                  rdpdr_abort_io(g_min_timeout_fd, 0, STATUS_TIMEOUT);
989                  return;                  return;
990          }          }
# Line 929  rdpdr_check_fds(fd_set * rfds, fd_set * Line 1012  rdpdr_check_fds(fd_set * rfds, fd_set *
1012                                                                     iorq->buffer + iorq->partial_len,                                                                     iorq->buffer + iorq->partial_len,
1013                                                                     req_size, iorq->offset, &result);                                                                     req_size, iorq->offset, &result);
1014    
1015                                                  if (result > 0)                                                  if ((long) result > 0)
1016                                                  {                                                  {
1017                                                          iorq->partial_len += result;                                                          iorq->partial_len += result;
1018                                                          iorq->offset += result;                                                          iorq->offset += result;
# Line 940  rdpdr_check_fds(fd_set * rfds, fd_set * Line 1023  rdpdr_check_fds(fd_set * rfds, fd_set *
1023                                                  /* only delete link if all data has been transfered */                                                  /* only delete link if all data has been transfered */
1024                                                  /* or if result was 0 and status success - EOF      */                                                  /* or if result was 0 and status success - EOF      */
1025                                                  if ((iorq->partial_len == iorq->length) ||                                                  if ((iorq->partial_len == iorq->length) ||
1026                                                      (g_rdpdr_device[iorq->device].device_type ==                                                      (result == 0))
                                                      DEVICE_TYPE_SERIAL) || (result == 0))  
1027                                                  {                                                  {
1028  #if WITH_DEBUG_RDP5  #if WITH_DEBUG_RDP5
1029                                                          DEBUG(("RDPDR: AIO total %u bytes read of %u\n", iorq->partial_len, iorq->length));                                                          DEBUG(("RDPDR: AIO total %u bytes read of %u\n", iorq->partial_len, iorq->length));
# Line 972  rdpdr_check_fds(fd_set * rfds, fd_set * Line 1054  rdpdr_check_fds(fd_set * rfds, fd_set *
1054                                                                      iorq->partial_len, req_size,                                                                      iorq->partial_len, req_size,
1055                                                                      iorq->offset, &result);                                                                      iorq->offset, &result);
1056    
1057                                                  if (result > 0)                                                  if ((long) result > 0)
1058                                                  {                                                  {
1059                                                          iorq->partial_len += result;                                                          iorq->partial_len += result;
1060                                                          iorq->offset += result;                                                          iorq->offset += result;
# Line 999  rdpdr_check_fds(fd_set * rfds, fd_set * Line 1081  rdpdr_check_fds(fd_set * rfds, fd_set *
1081                                                  }                                                  }
1082                                          }                                          }
1083                                          break;                                          break;
1084                                    case IRP_MJ_DEVICE_CONTROL:
1085                                            if (serial_get_event(iorq->fd, &result))
1086                                            {
1087                                                    buffer = (uint8 *) xrealloc((void *) buffer, 0x14);
1088                                                    out.data = out.p = buffer;
1089                                                    out.size = sizeof(buffer);
1090                                                    out_uint32_le(&out, result);
1091                                                    result = buffer_len = out.p - out.data;
1092                                                    status = STATUS_SUCCESS;
1093                                                    rdpdr_send_completion(iorq->device, iorq->id,
1094                                                                          status, result, buffer,
1095                                                                          buffer_len);
1096                                                    xfree(buffer);
1097                                                    iorq = rdpdr_remove_iorequest(prev, iorq);
1098                                            }
1099    
1100                                            break;
1101                          }                          }
1102    
1103                  }                  }
# Line 1007  rdpdr_check_fds(fd_set * rfds, fd_set * Line 1106  rdpdr_check_fds(fd_set * rfds, fd_set *
1106                          iorq = iorq->next;                          iorq = iorq->next;
1107          }          }
1108    
1109            /* Check notify */
1110            iorq = g_iorequest;
1111            prev = NULL;
1112            while (iorq != NULL)
1113            {
1114                    if (iorq->fd != 0)
1115                    {
1116                            switch (iorq->major)
1117                            {
1118    
1119                                    case IRP_MJ_DIRECTORY_CONTROL:
1120                                            if (g_rdpdr_device[iorq->device].device_type ==
1121                                                DEVICE_TYPE_DISK)
1122                                            {
1123    
1124                                                    if (g_notify_stamp)
1125                                                    {
1126                                                            g_notify_stamp = False;
1127                                                            status = disk_check_notify(iorq->fd);
1128                                                            if (status != STATUS_PENDING)
1129                                                            {
1130                                                                    rdpdr_send_completion(iorq->device,
1131                                                                                          iorq->id,
1132                                                                                          status, 0,
1133                                                                                          NULL, 0);
1134                                                                    iorq = rdpdr_remove_iorequest(prev,
1135                                                                                                  iorq);
1136                                                            }
1137                                                    }
1138                                            }
1139                                            break;
1140    
1141    
1142    
1143                            }
1144                    }
1145    
1146                    prev = iorq;
1147                    if (iorq)
1148                            iorq = iorq->next;
1149            }
1150    
1151  }  }
1152    
1153    void
1154    rdpdr_check_fds(fd_set * rfds, fd_set * wfds, BOOL timed_out)
1155    {
1156            fd_set dummy;
1157    
1158    
1159            FD_ZERO(&dummy);
1160    
1161    
1162            /* fist check event queue only,
1163               any serial wait event must be done before read block will be sent
1164             */
1165    
1166            _rdpdr_check_fds(&dummy, &dummy, False);
1167            _rdpdr_check_fds(rfds, wfds, timed_out);
1168    }
1169    
1170    
1171  /* Abort a pending io request for a given handle and major */  /* Abort a pending io request for a given handle and major */
1172  BOOL  BOOL
1173  rdpdr_abort_io(uint32 fd, uint32 major, NTSTATUS status)  rdpdr_abort_io(uint32 fd, uint32 major, NTSTATUS status)

Legend:
Removed from v.794  
changed lines
  Added in v.795

  ViewVC Help
Powered by ViewVC 1.1.26