/[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 776 by jsorg71, Sat Oct 2 01:30:33 2004 UTC revision 1319 by stargo, Thu Nov 2 20:48:28 2006 UTC
# Line 1  Line 1 
1  /* -*- c-basic-offset: 8 -*-  /* -*- c-basic-offset: 8 -*-
2     rdesktop: A Remote Desktop Protocol client.     rdesktop: A Remote Desktop Protocol client.
3     Copyright (C) Matthew Chapman 1999-2004     Copyright (C) Matthew Chapman 1999-2005
4    
5     This program is free software; you can redistribute it and/or modify     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by     it under the terms of the GNU General Public License as published by
# Line 60  extern DEVICE_FNS serial_fns; Line 60  extern DEVICE_FNS serial_fns;
60  extern DEVICE_FNS printer_fns;  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    #ifdef WITH_SCARD
64    extern DEVICE_FNS scard_fns;
65    #endif
66  extern FILEINFO g_fileinfo[];  extern FILEINFO g_fileinfo[];
67    extern BOOL g_notify_stamp;
68    
69  static VCHANNEL *rdpdr_channel;  static VCHANNEL *rdpdr_channel;
70    
# Line 154  add_async_iorequest(uint32 device, uint3 Line 158  add_async_iorequest(uint32 device, uint3
158    
159          while (iorq->fd != 0)          while (iorq->fd != 0)
160          {          {
161                  // create new element if needed                  /* create new element if needed */
162                  if (iorq->next == NULL)                  if (iorq->next == NULL)
163                  {                  {
164                          iorq->next =                          iorq->next =
# Line 227  announcedata_size() Line 231  announcedata_size()
231          int size, i;          int size, i;
232          PRINTER *printerinfo;          PRINTER *printerinfo;
233    
234          size = 8;               //static announce size          size = 8;               /* static announce size */
235          size += g_num_devices * 0x14;          size += g_num_devices * 0x14;
236    
237          for (i = 0; i < g_num_devices; i++)          for (i = 0; i < g_num_devices; i++)
# Line 308  rdpdr_send_available(void) Line 312  rdpdr_send_available(void)
312          channel_send(s, rdpdr_channel);          channel_send(s, rdpdr_channel);
313  }  }
314    
315  static void  void
316  rdpdr_send_completion(uint32 device, uint32 id, uint32 status, uint32 result, uint8 * buffer,  rdpdr_send_completion(uint32 device, uint32 id, uint32 status, uint32 result, uint8 * buffer,
317                        uint32 length)                        uint32 length)
318  {  {
# Line 323  rdpdr_send_completion(uint32 device, uin Line 327  rdpdr_send_completion(uint32 device, uin
327          out_uint32_le(s, result);          out_uint32_le(s, result);
328          out_uint8p(s, buffer, length);          out_uint8p(s, buffer, length);
329          s_mark_end(s);          s_mark_end(s);
330          /* JIF          /* JIF */
331             hexdump(s->channel_hdr + 8, s->end - s->channel_hdr - 8); */  #ifdef WITH_DEBUG_RDP5
332            printf("--> rdpdr_send_completion\n");
333            /* hexdump(s->channel_hdr + 8, s->end - s->channel_hdr - 8); */
334    #endif
335          channel_send(s, rdpdr_channel);          channel_send(s, rdpdr_channel);
336  }  }
337    
# Line 348  rdpdr_process_irp(STREAM s) Line 355  rdpdr_process_irp(STREAM s)
355                  error_mode,                  error_mode,
356                  share_mode, disposition, total_timeout, interval_timeout, flags_and_attributes = 0;                  share_mode, disposition, total_timeout, interval_timeout, flags_and_attributes = 0;
357    
358          char filename[256];          char filename[PATH_MAX];
359          uint8 *buffer, *pst_buf;          uint8 *buffer, *pst_buf;
360          struct stream out;          struct stream out;
361          DEVICE_FNS *fns;          DEVICE_FNS *fns;
# Line 391  rdpdr_process_irp(STREAM s) Line 398  rdpdr_process_irp(STREAM s)
398                          break;                          break;
399    
400                  case DEVICE_TYPE_SCARD:                  case DEVICE_TYPE_SCARD:
401    #ifdef WITH_SCARD
402                            fns = &scard_fns;
403                            rw_blocking = False;
404                            break;
405    #endif
406                  default:                  default:
407    
408                          error("IRP for bad device %ld\n", device);                          error("IRP for bad device %ld\n", device);
# Line 402  rdpdr_process_irp(STREAM s) Line 414  rdpdr_process_irp(STREAM s)
414                  case IRP_MJ_CREATE:                  case IRP_MJ_CREATE:
415    
416                          in_uint32_be(s, desired_access);                          in_uint32_be(s, desired_access);
417                          in_uint8s(s, 0x08);     // unknown                          in_uint8s(s, 0x08);     /* unknown */
418                          in_uint32_le(s, error_mode);                          in_uint32_le(s, error_mode);
419                          in_uint32_le(s, share_mode);                          in_uint32_le(s, share_mode);
420                          in_uint32_le(s, disposition);                          in_uint32_le(s, disposition);
# Line 459  rdpdr_process_irp(STREAM s) Line 471  rdpdr_process_irp(STREAM s)
471                                  break;                                  break;
472                          }                          }
473    
474                          if (rw_blocking)        // Complete read immediately                          if (rw_blocking)        /* Complete read immediately */
475                          {                          {
476                                  buffer = (uint8 *) xrealloc((void *) buffer, length);                                  buffer = (uint8 *) xrealloc((void *) buffer, length);
477                                  if (!buffer)                                  if (!buffer)
# Line 472  rdpdr_process_irp(STREAM s) Line 484  rdpdr_process_irp(STREAM s)
484                                  break;                                  break;
485                          }                          }
486    
487                          // Add request to table                          /* Add request to table */
488                          pst_buf = (uint8 *) xmalloc(length);                          pst_buf = (uint8 *) xmalloc(length);
489                          if (!pst_buf)                          if (!pst_buf)
490                          {                          {
# Line 512  rdpdr_process_irp(STREAM s) Line 524  rdpdr_process_irp(STREAM s)
524                                  break;                                  break;
525                          }                          }
526    
527                          if (rw_blocking)        // Complete immediately                          if (rw_blocking)        /* Complete immediately */
528                          {                          {
529                                  status = fns->write(file, s->p, length, offset, &result);                                  status = fns->write(file, s->p, length, offset, &result);
530                                  break;                                  break;
531                          }                          }
532    
533                          // Add to table                          /* Add to table */
534                          pst_buf = (uint8 *) xmalloc(length);                          pst_buf = (uint8 *) xmalloc(length);
535                          if (!pst_buf)                          if (!pst_buf)
536                          {                          {
# Line 623  rdpdr_process_irp(STREAM s) Line 635  rdpdr_process_irp(STREAM s)
635                                  case IRP_MN_NOTIFY_CHANGE_DIRECTORY:                                  case IRP_MN_NOTIFY_CHANGE_DIRECTORY:
636    
637                                          /* JIF                                          /* JIF
638                                             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);  */
639                                          status = STATUS_PENDING;        // Don't send completion packet  
640                                            in_uint32_le(s, info_level);    /* notify mask */
641    
642                                            g_notify_stamp = True;
643    
644                                            status = disk_create_notify(file, info_level);
645                                            result = 0;
646    
647                                            if (status == STATUS_PENDING)
648                                                    add_async_iorequest(device, file, id, major, length,
649                                                                        fns, 0, 0, NULL, 0);
650                                          break;                                          break;
651    
652                                  default:                                  default:
653    
654                                          status = STATUS_INVALID_PARAMETER;                                          status = STATUS_INVALID_PARAMETER;
655                                          /* JIF                                          /* JIF */
656                                             unimpl("IRP major=0x%x minor=0x%x\n", major, minor); */                                          unimpl("IRP major=0x%x minor=0x%x\n", major, minor);
657                          }                          }
658                          break;                          break;
659    
# Line 657  rdpdr_process_irp(STREAM s) Line 679  rdpdr_process_irp(STREAM s)
679    
680                          out.data = out.p = buffer;                          out.data = out.p = buffer;
681                          out.size = sizeof(buffer);                          out.size = sizeof(buffer);
682    
683                            DEBUG_SCARD(("[SMART-CARD TRACE]\n"));
684                            DEBUG_SCARD(("device 0x%.8x\n", device));
685                            DEBUG_SCARD(("file   0x%.8x\n", file));
686                            DEBUG_SCARD(("id     0x%.8x\n", id));
687    #ifdef WITH_SCARD
688                            scardSetInfo(device, id, bytes_out + 0x14);
689    #endif
690                          status = fns->device_control(file, request, s, &out);                          status = fns->device_control(file, request, s, &out);
691                          result = buffer_len = out.p - out.data;                          result = buffer_len = out.p - out.data;
692    
693                            DEBUG_SCARD(("[SMART-CARD TRACE] OUT 0x%.8x\n", status));
694    
695                            /* Serial SERIAL_WAIT_ON_MASK */
696                            if (status == STATUS_PENDING)
697                            {
698                                    if (add_async_iorequest
699                                        (device, file, id, major, length, fns, 0, 0, NULL, 0))
700                                    {
701                                            status = STATUS_PENDING;
702                                            break;
703                                    }
704                            }
705    #ifdef WITH_SCARD
706                            else if (status == (STATUS_PENDING | 0xC0000000))
707                                    status = STATUS_PENDING;
708    #endif
709                          break;                          break;
710    
711    
# Line 810  rdpdr_init() Line 857  rdpdr_init()
857  void  void
858  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)
859  {  {
860          uint32 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). */
861          struct async_iorequest *iorq;          struct async_iorequest *iorq;
862          char c;          char c;
863    
# Line 827  rdpdr_add_fds(int *n, fd_set * rfds, fd_ Line 874  rdpdr_add_fds(int *n, fd_set * rfds, fd_
874                                             reconnecting. FIXME: Real                                             reconnecting. FIXME: Real
875                                             support for reconnects. */                                             support for reconnects. */
876    
                                         if ((read(iorq->fd, &c, 0) != 0) && (errno == EBADF))  
                                                 break;  
   
877                                          FD_SET(iorq->fd, rfds);                                          FD_SET(iorq->fd, rfds);
878                                          *n = MAX(*n, iorq->fd);                                          *n = MAX(*n, iorq->fd);
879    
880                                          // Check if io request timeout is smaller than current (but not 0).                                          /* Check if io request timeout is smaller than current (but not 0). */
881                                          if (iorq->timeout                                          if (iorq->timeout
882                                              && (select_timeout == 0                                              && (select_timeout == 0
883                                                  || iorq->timeout < select_timeout))                                                  || iorq->timeout < select_timeout))
884                                          {                                          {
885                                                  // Set new timeout                                                  /* Set new timeout */
886                                                  select_timeout = iorq->timeout;                                                  select_timeout = iorq->timeout;
887                                                  g_min_timeout_fd = iorq->fd;    /* Remember fd */                                                  g_min_timeout_fd = iorq->fd;    /* Remember fd */
888                                                  tv->tv_sec = select_timeout / 1000;                                                  tv->tv_sec = select_timeout / 1000;
889                                                  tv->tv_usec = (select_timeout % 1000) * 1000;                                                  tv->tv_usec = (select_timeout % 1000) * 1000;
890                                                  *timeout = True;                                                  *timeout = True;
891                                                    break;
892                                            }
893                                            if (iorq->itv_timeout && iorq->partial_len > 0
894                                                && (select_timeout == 0
895                                                    || iorq->itv_timeout < select_timeout))
896                                            {
897                                                    /* Set new timeout */
898                                                    select_timeout = iorq->itv_timeout;
899                                                    g_min_timeout_fd = iorq->fd;    /* Remember fd */
900                                                    tv->tv_sec = select_timeout / 1000;
901                                                    tv->tv_usec = (select_timeout % 1000) * 1000;
902                                                    *timeout = True;
903                                                    break;
904                                          }                                          }
   
905                                          break;                                          break;
906    
907                                  case IRP_MJ_WRITE:                                  case IRP_MJ_WRITE:
# Line 857  rdpdr_add_fds(int *n, fd_set * rfds, fd_ Line 913  rdpdr_add_fds(int *n, fd_set * rfds, fd_
913                                          *n = MAX(*n, iorq->fd);                                          *n = MAX(*n, iorq->fd);
914                                          break;                                          break;
915    
916                                    case IRP_MJ_DEVICE_CONTROL:
917                                            if (select_timeout > 5)
918                                                    select_timeout = 5;     /* serial event queue */
919                                            break;
920    
921                          }                          }
922    
923                  }                  }
# Line 881  rdpdr_remove_iorequest(struct async_iore Line 942  rdpdr_remove_iorequest(struct async_iore
942          }          }
943          else          else
944          {          {
945                  // Even if NULL                  /* Even if NULL */
946                  g_iorequest = iorq->next;                  g_iorequest = iorq->next;
947                  xfree(iorq);                  xfree(iorq);
948                  iorq = NULL;                  iorq = NULL;
# Line 890  rdpdr_remove_iorequest(struct async_iore Line 951  rdpdr_remove_iorequest(struct async_iore
951  }  }
952    
953  /* 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 */
954  void  static void
955  rdpdr_check_fds(fd_set * rfds, fd_set * wfds, BOOL timed_out)  _rdpdr_check_fds(fd_set * rfds, fd_set * wfds, BOOL timed_out)
956  {  {
957          NTSTATUS status;          NTSTATUS status;
958          uint32 result = 0;          uint32 result = 0;
# Line 899  rdpdr_check_fds(fd_set * rfds, fd_set * Line 960  rdpdr_check_fds(fd_set * rfds, fd_set *
960          struct async_iorequest *iorq;          struct async_iorequest *iorq;
961          struct async_iorequest *prev;          struct async_iorequest *prev;
962          uint32 req_size = 0;          uint32 req_size = 0;
963            uint32 buffer_len;
964            struct stream out;
965            uint8 *buffer = NULL;
966    
967    
968          if (timed_out)          if (timed_out)
969          {          {
970                    /* check serial iv_timeout */
971    
972                    iorq = g_iorequest;
973                    prev = NULL;
974                    while (iorq != NULL)
975                    {
976                            if (iorq->fd == g_min_timeout_fd)
977                            {
978                                    if ((iorq->partial_len > 0) &&
979                                        (g_rdpdr_device[iorq->device].device_type ==
980                                         DEVICE_TYPE_SERIAL))
981                                    {
982    
983                                            /* iv_timeout between 2 chars, send partial_len */
984                                            /*printf("RDPDR: IVT total %u bytes read of %u\n", iorq->partial_len, iorq->length); */
985                                            rdpdr_send_completion(iorq->device,
986                                                                  iorq->id, STATUS_SUCCESS,
987                                                                  iorq->partial_len,
988                                                                  iorq->buffer, iorq->partial_len);
989                                            iorq = rdpdr_remove_iorequest(prev, iorq);
990                                            return;
991                                    }
992                                    else
993                                    {
994                                            break;
995                                    }
996    
997                            }
998                            else
999                            {
1000                                    break;
1001                            }
1002    
1003    
1004                            prev = iorq;
1005                            if (iorq)
1006                                    iorq = iorq->next;
1007    
1008                    }
1009    
1010                  rdpdr_abort_io(g_min_timeout_fd, 0, STATUS_TIMEOUT);                  rdpdr_abort_io(g_min_timeout_fd, 0, STATUS_TIMEOUT);
1011                  return;                  return;
1012          }          }
# Line 929  rdpdr_check_fds(fd_set * rfds, fd_set * Line 1034  rdpdr_check_fds(fd_set * rfds, fd_set *
1034                                                                     iorq->buffer + iorq->partial_len,                                                                     iorq->buffer + iorq->partial_len,
1035                                                                     req_size, iorq->offset, &result);                                                                     req_size, iorq->offset, &result);
1036    
1037                                                  if (result > 0)                                                  if ((long) result > 0)
1038                                                  {                                                  {
1039                                                          iorq->partial_len += result;                                                          iorq->partial_len += result;
1040                                                          iorq->offset += result;                                                          iorq->offset += result;
# Line 940  rdpdr_check_fds(fd_set * rfds, fd_set * Line 1045  rdpdr_check_fds(fd_set * rfds, fd_set *
1045                                                  /* only delete link if all data has been transfered */                                                  /* only delete link if all data has been transfered */
1046                                                  /* or if result was 0 and status success - EOF      */                                                  /* or if result was 0 and status success - EOF      */
1047                                                  if ((iorq->partial_len == iorq->length) ||                                                  if ((iorq->partial_len == iorq->length) ||
1048                                                      (g_rdpdr_device[iorq->device].device_type ==                                                      (result == 0))
                                                      DEVICE_TYPE_SERIAL) || (result == 0))  
1049                                                  {                                                  {
1050  #if WITH_DEBUG_RDP5  #if WITH_DEBUG_RDP5
1051                                                          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 1076  rdpdr_check_fds(fd_set * rfds, fd_set *
1076                                                                      iorq->partial_len, req_size,                                                                      iorq->partial_len, req_size,
1077                                                                      iorq->offset, &result);                                                                      iorq->offset, &result);
1078    
1079                                                  if (result > 0)                                                  if ((long) result > 0)
1080                                                  {                                                  {
1081                                                          iorq->partial_len += result;                                                          iorq->partial_len += result;
1082                                                          iorq->offset += result;                                                          iorq->offset += result;
# Line 999  rdpdr_check_fds(fd_set * rfds, fd_set * Line 1103  rdpdr_check_fds(fd_set * rfds, fd_set *
1103                                                  }                                                  }
1104                                          }                                          }
1105                                          break;                                          break;
1106                                    case IRP_MJ_DEVICE_CONTROL:
1107                                            if (serial_get_event(iorq->fd, &result))
1108                                            {
1109                                                    buffer = (uint8 *) xrealloc((void *) buffer, 0x14);
1110                                                    out.data = out.p = buffer;
1111                                                    out.size = sizeof(buffer);
1112                                                    out_uint32_le(&out, result);
1113                                                    result = buffer_len = out.p - out.data;
1114                                                    status = STATUS_SUCCESS;
1115                                                    rdpdr_send_completion(iorq->device, iorq->id,
1116                                                                          status, result, buffer,
1117                                                                          buffer_len);
1118                                                    xfree(buffer);
1119                                                    iorq = rdpdr_remove_iorequest(prev, iorq);
1120                                            }
1121    
1122                                            break;
1123                          }                          }
1124    
1125                  }                  }
# Line 1007  rdpdr_check_fds(fd_set * rfds, fd_set * Line 1128  rdpdr_check_fds(fd_set * rfds, fd_set *
1128                          iorq = iorq->next;                          iorq = iorq->next;
1129          }          }
1130    
1131            /* Check notify */
1132            iorq = g_iorequest;
1133            prev = NULL;
1134            while (iorq != NULL)
1135            {
1136                    if (iorq->fd != 0)
1137                    {
1138                            switch (iorq->major)
1139                            {
1140    
1141                                    case IRP_MJ_DIRECTORY_CONTROL:
1142                                            if (g_rdpdr_device[iorq->device].device_type ==
1143                                                DEVICE_TYPE_DISK)
1144                                            {
1145    
1146                                                    if (g_notify_stamp)
1147                                                    {
1148                                                            g_notify_stamp = False;
1149                                                            status = disk_check_notify(iorq->fd);
1150                                                            if (status != STATUS_PENDING)
1151                                                            {
1152                                                                    rdpdr_send_completion(iorq->device,
1153                                                                                          iorq->id,
1154                                                                                          status, 0,
1155                                                                                          NULL, 0);
1156                                                                    iorq = rdpdr_remove_iorequest(prev,
1157                                                                                                  iorq);
1158                                                            }
1159                                                    }
1160                                            }
1161                                            break;
1162    
1163    
1164    
1165                            }
1166                    }
1167    
1168                    prev = iorq;
1169                    if (iorq)
1170                            iorq = iorq->next;
1171            }
1172    
1173    }
1174    
1175    void
1176    rdpdr_check_fds(fd_set * rfds, fd_set * wfds, BOOL timed_out)
1177    {
1178            fd_set dummy;
1179    
1180    
1181            FD_ZERO(&dummy);
1182    
1183    
1184            /* fist check event queue only,
1185               any serial wait event must be done before read block will be sent
1186             */
1187    
1188            _rdpdr_check_fds(&dummy, &dummy, False);
1189            _rdpdr_check_fds(rfds, wfds, timed_out);
1190  }  }
1191    
1192    
1193  /* Abort a pending io request for a given handle and major */  /* Abort a pending io request for a given handle and major */
1194  BOOL  BOOL
1195  rdpdr_abort_io(uint32 fd, uint32 major, NTSTATUS status)  rdpdr_abort_io(uint32 fd, uint32 major, NTSTATUS status)
# Line 1021  rdpdr_abort_io(uint32 fd, uint32 major, Line 1202  rdpdr_abort_io(uint32 fd, uint32 major,
1202          prev = NULL;          prev = NULL;
1203          while (iorq != NULL)          while (iorq != NULL)
1204          {          {
1205                  // 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.
1206                  // Abort read should not abort a write io request.                     Abort read should not abort a write io request. */
1207                  if ((iorq->fd == fd) && (major == 0 || iorq->major == major))                  if ((iorq->fd == fd) && (major == 0 || iorq->major == major))
1208                  {                  {
1209                          result = 0;                          result = 0;

Legend:
Removed from v.776  
changed lines
  Added in v.1319

  ViewVC Help
Powered by ViewVC 1.1.26