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

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

revision 540 by astrand, Fri Oct 31 20:34:26 2003 UTC revision 831 by jdmeijer, Tue Mar 8 00:43:10 2005 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     RDP order processing     RDP order processing
4     Copyright (C) Matthew Chapman 1999-2002     Copyright (C) Matthew Chapman 1999-2005
5    
6     This program is free software; you can redistribute it and/or modify     This program is free software; you can redistribute it and/or modify
7     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 70  rdp_in_coord(STREAM s, sint16 * coord, B Line 70  rdp_in_coord(STREAM s, sint16 * coord, B
70          }          }
71  }  }
72    
73    /* Parse a delta co-ordinate in polyline/polygon order form */
74    static int
75    parse_delta(uint8 * buffer, int *offset)
76    {
77            int value = buffer[(*offset)++];
78            int two_byte = value & 0x80;
79    
80            if (value & 0x40)       /* sign bit */
81                    value |= ~0x3f;
82            else
83                    value &= 0x3f;
84    
85            if (two_byte)
86                    value = (value << 8) | buffer[(*offset)++];
87    
88            return value;
89    }
90    
91  /* Read a colour entry */  /* Read a colour entry */
92  static void  static void
93  rdp_in_colour(STREAM s, uint32 * colour)  rdp_in_colour(STREAM s, uint32 * colour)
# Line 269  process_line(STREAM s, LINE_ORDER * os, Line 287  process_line(STREAM s, LINE_ORDER * os,
287    
288          rdp_parse_pen(s, &os->pen, present >> 7);          rdp_parse_pen(s, &os->pen, present >> 7);
289    
290          DEBUG(("LINE(op=0x%x,sx=%d,sy=%d,dx=%d,dx=%d,fg=0x%x)\n",          DEBUG(("LINE(op=0x%x,sx=%d,sy=%d,dx=%d,dy=%d,fg=0x%x)\n",
291                 os->opcode, os->startx, os->starty, os->endx, os->endy, os->pen.colour));                 os->opcode, os->startx, os->starty, os->endx, os->endy, os->pen.colour));
292    
293          if (os->opcode < 0x01 || os->opcode > 0x10)          if (os->opcode < 0x01 || os->opcode > 0x10)
# Line 462  process_triblt(STREAM s, TRIBLT_ORDER * Line 480  process_triblt(STREAM s, TRIBLT_ORDER *
480                    bitmap, os->srcx, os->srcy, &os->brush, os->bgcolour, os->fgcolour);                    bitmap, os->srcx, os->srcy, &os->brush, os->bgcolour, os->fgcolour);
481  }  }
482    
483  /* Parse a delta co-ordinate in polyline order form */  /* Process a polygon order */
484  static int  static void
485  parse_delta(uint8 * buffer, int *offset)  process_polygon(STREAM s, POLYGON_ORDER * os, uint32 present, BOOL delta)
486  {  {
487          int value = buffer[(*offset)++];          int index, data, next;
488          int two_byte = value & 0x80;          uint8 flags = 0;
489            POINT *points;
490    
491          if (value & 0x40)       /* sign bit */          if (present & 0x01)
492                  value |= ~0x3f;                  rdp_in_coord(s, &os->x, delta);
493    
494            if (present & 0x02)
495                    rdp_in_coord(s, &os->y, delta);
496    
497            if (present & 0x04)
498                    in_uint8(s, os->opcode);
499    
500            if (present & 0x08)
501                    in_uint8(s, os->fillmode);
502    
503            if (present & 0x10)
504                    rdp_in_colour(s, &os->fgcolour);
505    
506            if (present & 0x20)
507                    in_uint8(s, os->npoints);
508    
509            if (present & 0x40)
510            {
511                    in_uint8(s, os->datasize);
512                    in_uint8a(s, os->data, os->datasize);
513            }
514    
515            DEBUG(("POLYGON(x=%d,y=%d,op=0x%x,fm=%d,fg=0x%x,n=%d,sz=%d)\n",
516                   os->x, os->y, os->opcode, os->fillmode, os->fgcolour, os->npoints, os->datasize));
517    
518            DEBUG(("Data: "));
519    
520            for (index = 0; index < os->datasize; index++)
521                    DEBUG(("%02x ", os->data[index]));
522    
523            DEBUG(("\n"));
524    
525            if (os->opcode < 0x01 || os->opcode > 0x10)
526            {
527                    error("bad ROP2 0x%x\n", os->opcode);
528                    return;
529            }
530    
531            points = (POINT *) xmalloc((os->npoints + 1) * sizeof(POINT));
532            memset(points, 0, (os->npoints + 1) * sizeof(POINT));
533    
534            points[0].x = os->x;
535            points[0].y = os->y;
536    
537            index = 0;
538            data = ((os->npoints - 1) / 4) + 1;
539            for (next = 1; (next <= os->npoints) && (next < 256) && (data < os->datasize); next++)
540            {
541                    if ((next - 1) % 4 == 0)
542                            flags = os->data[index++];
543    
544                    if (~flags & 0x80)
545                            points[next].x = parse_delta(os->data, &data);
546    
547                    if (~flags & 0x40)
548                            points[next].y = parse_delta(os->data, &data);
549    
550                    flags <<= 2;
551            }
552    
553            if (next - 1 == os->npoints)
554                    ui_polygon(os->opcode - 1, os->fillmode, points, os->npoints + 1, NULL, 0,
555                               os->fgcolour);
556          else          else
557                  value &= 0x3f;                  error("polygon parse error\n");
558    
559          if (two_byte)          xfree(points);
560                  value = (value << 8) | buffer[(*offset)++];  }
561    
562          return value;  /* Process a polygon2 order */
563    static void
564    process_polygon2(STREAM s, POLYGON2_ORDER * os, uint32 present, BOOL delta)
565    {
566            int index, data, next;
567            uint8 flags = 0;
568            POINT *points;
569    
570            if (present & 0x0001)
571                    rdp_in_coord(s, &os->x, delta);
572    
573            if (present & 0x0002)
574                    rdp_in_coord(s, &os->y, delta);
575    
576            if (present & 0x0004)
577                    in_uint8(s, os->opcode);
578    
579            if (present & 0x0008)
580                    in_uint8(s, os->fillmode);
581    
582            if (present & 0x0010)
583                    rdp_in_colour(s, &os->bgcolour);
584    
585            if (present & 0x0020)
586                    rdp_in_colour(s, &os->fgcolour);
587    
588            rdp_parse_brush(s, &os->brush, present >> 6);
589    
590            if (present & 0x0800)
591                    in_uint8(s, os->npoints);
592    
593            if (present & 0x1000)
594            {
595                    in_uint8(s, os->datasize);
596                    in_uint8a(s, os->data, os->datasize);
597            }
598    
599            DEBUG(("POLYGON2(x=%d,y=%d,op=0x%x,fm=%d,bs=%d,bg=0x%x,fg=0x%x,n=%d,sz=%d)\n",
600                   os->x, os->y, os->opcode, os->fillmode, os->brush.style, os->bgcolour, os->fgcolour,
601                   os->npoints, os->datasize));
602    
603            DEBUG(("Data: "));
604    
605            for (index = 0; index < os->datasize; index++)
606                    DEBUG(("%02x ", os->data[index]));
607    
608            DEBUG(("\n"));
609    
610            if (os->opcode < 0x01 || os->opcode > 0x10)
611            {
612                    error("bad ROP2 0x%x\n", os->opcode);
613                    return;
614            }
615    
616            points = (POINT *) xmalloc((os->npoints + 1) * sizeof(POINT));
617            memset(points, 0, (os->npoints + 1) * sizeof(POINT));
618    
619            points[0].x = os->x;
620            points[0].y = os->y;
621    
622            index = 0;
623            data = ((os->npoints - 1) / 4) + 1;
624            for (next = 1; (next <= os->npoints) && (next < 256) && (data < os->datasize); next++)
625            {
626                    if ((next - 1) % 4 == 0)
627                            flags = os->data[index++];
628    
629                    if (~flags & 0x80)
630                            points[next].x = parse_delta(os->data, &data);
631    
632                    if (~flags & 0x40)
633                            points[next].y = parse_delta(os->data, &data);
634    
635                    flags <<= 2;
636            }
637    
638            if (next - 1 == os->npoints)
639                    ui_polygon(os->opcode - 1, os->fillmode, points, os->npoints + 1,
640                               &os->brush, os->bgcolour, os->fgcolour);
641            else
642                    error("polygon2 parse error\n");
643    
644            xfree(points);
645  }  }
646    
647  /* Process a polyline order */  /* Process a polyline order */
# Line 558  process_polyline(STREAM s, POLYLINE_ORDE Line 722  process_polyline(STREAM s, POLYLINE_ORDE
722          }          }
723  }  }
724    
725    /* Process an ellipse order */
726    static void
727    process_ellipse(STREAM s, ELLIPSE_ORDER * os, uint32 present, BOOL delta)
728    {
729            if (present & 0x01)
730                    rdp_in_coord(s, &os->left, delta);
731    
732            if (present & 0x02)
733                    rdp_in_coord(s, &os->top, delta);
734    
735            if (present & 0x04)
736                    rdp_in_coord(s, &os->right, delta);
737    
738            if (present & 0x08)
739                    rdp_in_coord(s, &os->bottom, delta);
740    
741            if (present & 0x10)
742                    in_uint8(s, os->opcode);
743    
744            if (present & 0x20)
745                    in_uint8(s, os->fillmode);
746    
747            if (present & 0x40)
748                    rdp_in_colour(s, &os->fgcolour);
749    
750            DEBUG(("ELLIPSE(l=%d,t=%d,r=%d,b=%d,op=0x%x,fm=%d,fg=0x%x)\n", os->left, os->top,
751                   os->right, os->bottom, os->opcode, os->fillmode, os->fgcolour));
752    
753            ui_ellipse(os->opcode - 1, os->fillmode, os->left, os->top, os->right - os->left,
754                       os->bottom - os->top, NULL, 0, os->fgcolour);
755    }
756    
757    /* Process an ellipse2 order */
758    static void
759    process_ellipse2(STREAM s, ELLIPSE2_ORDER * os, uint32 present, BOOL delta)
760    {
761            if (present & 0x0001)
762                    rdp_in_coord(s, &os->left, delta);
763    
764            if (present & 0x0002)
765                    rdp_in_coord(s, &os->top, delta);
766    
767            if (present & 0x0004)
768                    rdp_in_coord(s, &os->right, delta);
769    
770            if (present & 0x0008)
771                    rdp_in_coord(s, &os->bottom, delta);
772    
773            if (present & 0x0010)
774                    in_uint8(s, os->opcode);
775    
776            if (present & 0x0020)
777                    in_uint8(s, os->fillmode);
778    
779            if (present & 0x0040)
780                    rdp_in_colour(s, &os->bgcolour);
781    
782            if (present & 0x0080)
783                    rdp_in_colour(s, &os->fgcolour);
784    
785            rdp_parse_brush(s, &os->brush, present >> 8);
786    
787            DEBUG(("ELLIPSE2(l=%d,t=%d,r=%d,b=%d,op=0x%x,fm=%d,bs=%d,bg=0x%x,fg=0x%x)\n",
788                   os->left, os->top, os->right, os->bottom, os->opcode, os->fillmode, os->brush.style,
789                   os->bgcolour, os->fgcolour));
790    
791            ui_ellipse(os->opcode - 1, os->fillmode, os->left, os->top, os->right - os->left,
792                       os->bottom - os->top, &os->brush, os->bgcolour, os->fgcolour);
793    }
794    
795  /* Process a text order */  /* Process a text order */
796  static void  static void
797  process_text2(STREAM s, TEXT2_ORDER * os, uint32 present, BOOL delta)  process_text2(STREAM s, TEXT2_ORDER * os, uint32 present, BOOL delta)
# Line 606  process_text2(STREAM s, TEXT2_ORDER * os Line 840  process_text2(STREAM s, TEXT2_ORDER * os
840          if (present & 0x002000)          if (present & 0x002000)
841                  in_uint16_le(s, os->boxbottom);                  in_uint16_le(s, os->boxbottom);
842    
843          if (present & 0x004000) /* fix for connecting to a server that */          /*
844                  in_uint8s(s, 10);       /* was disconnected with mstsc.exe */           * Unknown members, seen when connecting to a session that was disconnected with
845          /* 0x008000, 0x020000, and 0x040000 are present too ??? */           * mstsc and with wintach's spreadsheet test.
846             */
847            if (present & 0x004000)
848                    in_uint8s(s, 1);
849    
850            if (present & 0x008000)
851                    in_uint8s(s, 1);
852    
853            if (present & 0x010000)
854            {
855                    in_uint8s(s, 1);        /* guessing the length here */
856                    warning("Unknown order state member (0x010000) in text2 order.\n");
857            }
858    
859            if (present & 0x020000)
860                    in_uint8s(s, 4);
861    
862            if (present & 0x040000)
863                    in_uint8s(s, 4);
864    
865          if (present & 0x080000)          if (present & 0x080000)
866                  in_uint16_le(s, os->x);                  in_uint16_le(s, os->x);
# Line 695  process_bmpcache(STREAM s) Line 947  process_bmpcache(STREAM s)
947          in_uint16_le(s, bufsize);       /* bufsize */          in_uint16_le(s, bufsize);       /* bufsize */
948          in_uint16_le(s, cache_idx);          in_uint16_le(s, cache_idx);
949    
950          if (!g_use_rdp5)          if (g_use_rdp5)
951            {
952                    size = bufsize;
953            }
954            else
955          {          {
956    
957                  /* Begin compressedBitmapData */                  /* Begin compressedBitmapData */
958                  in_uint16_le(s, pad2);  /* pad */                  in_uint16_le(s, pad2);  /* pad */
959                  in_uint16_le(s, size);                  in_uint16_le(s, size);
960                  /*      in_uint8s(s, 4);  */      /* row_size, final_size */                  /*      in_uint8s(s, 4);  *//* row_size, final_size */
961                  in_uint16_le(s, row_size);                  in_uint16_le(s, row_size);
962                  in_uint16_le(s, final_size);                  in_uint16_le(s, final_size);
963    
964          }          }
         else  
         {  
                 size = bufsize;  
         }  
965          in_uint8p(s, data, size);          in_uint8p(s, data, size);
966    
967          DEBUG(("BMPCACHE(cx=%d,cy=%d,id=%d,idx=%d,bpp=%d,size=%d,pad1=%d,bufsize=%d,pad2=%d,rs=%d,fs=%d)\n", width, height, cache_id, cache_idx, bpp, size, pad1, bufsize, pad2, row_size, final_size));          DEBUG(("BMPCACHE(cx=%d,cy=%d,id=%d,idx=%d,bpp=%d,size=%d,pad1=%d,bufsize=%d,pad2=%d,rs=%d,fs=%d)\n", width, height, cache_id, cache_idx, bpp, size, pad1, bufsize, pad2, row_size, final_size));
# Line 729  process_bmpcache(STREAM s) Line 981  process_bmpcache(STREAM s)
981          xfree(bmpdata);          xfree(bmpdata);
982  }  }
983    
984    /* Process a bitmap cache v2 order */
985    static void
986    process_bmpcache2(STREAM s, uint16 flags, BOOL compressed)
987    {
988            HBITMAP bitmap;
989            int y;
990            uint8 cache_id, cache_idx_low, width, height, Bpp;
991            uint16 cache_idx, bufsize;
992            uint8 *data, *bmpdata, *bitmap_id;
993    
994            bitmap_id = NULL;       /* prevent compiler warning */
995            cache_id = flags & ID_MASK;
996            Bpp = ((flags & MODE_MASK) >> MODE_SHIFT) - 2;
997    
998            if (flags & PERSIST)
999            {
1000                    in_uint8p(s, bitmap_id, 8);
1001            }
1002    
1003            if (flags & SQUARE)
1004            {
1005                    in_uint8(s, width);
1006                    height = width;
1007            }
1008            else
1009            {
1010                    in_uint8(s, width);
1011                    in_uint8(s, height);
1012            }
1013    
1014            in_uint16_be(s, bufsize);
1015            bufsize &= BUFSIZE_MASK;
1016            in_uint8(s, cache_idx);
1017    
1018            if (cache_idx & LONG_FORMAT)
1019            {
1020                    in_uint8(s, cache_idx_low);
1021                    cache_idx = ((cache_idx ^ LONG_FORMAT) << 8) + cache_idx_low;
1022            }
1023    
1024            in_uint8p(s, data, bufsize);
1025    
1026            DEBUG(("BMPCACHE2(compr=%d,flags=%x,cx=%d,cy=%d,id=%d,idx=%d,Bpp=%d,bs=%d)\n",
1027                   compressed, flags, width, height, cache_id, cache_idx, Bpp, bufsize));
1028    
1029            bmpdata = (uint8 *) xmalloc(width * height * Bpp);
1030    
1031            if (compressed)
1032            {
1033                    if (!bitmap_decompress(bmpdata, width, height, data, bufsize, Bpp))
1034                    {
1035                            DEBUG(("Failed to decompress bitmap data\n"));
1036                            xfree(bmpdata);
1037                            return;
1038                    }
1039            }
1040            else
1041            {
1042                    for (y = 0; y < height; y++)
1043                            memcpy(&bmpdata[(height - y - 1) * (width * Bpp)],
1044                                   &data[y * (width * Bpp)], width * Bpp);
1045            }
1046    
1047            bitmap = ui_create_bitmap(width, height, bmpdata);
1048    
1049            if (bitmap)
1050            {
1051                    cache_put_bitmap(cache_id, cache_idx, bitmap);
1052                    if (flags & PERSIST)
1053                            pstcache_save_bitmap(cache_id, cache_idx, bitmap_id, width, height,
1054                                                 width * height * Bpp, bmpdata);
1055            }
1056            else
1057            {
1058                    DEBUG(("process_bmpcache2: ui_create_bitmap failed\n"));
1059            }
1060    
1061            xfree(bmpdata);
1062    }
1063    
1064  /* Process a colourmap cache order */  /* Process a colourmap cache order */
1065  static void  static void
1066  process_colcache(STREAM s)  process_colcache(STREAM s)
# Line 796  process_fontcache(STREAM s) Line 1128  process_fontcache(STREAM s)
1128  static void  static void
1129  process_secondary_order(STREAM s)  process_secondary_order(STREAM s)
1130  {  {
1131            /* The length isn't calculated correctly by the server.
1132             * For very compact orders the length becomes negative
1133             * so a signed integer must be used. */
1134          uint16 length;          uint16 length;
1135            uint16 flags;
1136          uint8 type;          uint8 type;
1137          uint8 *next_order;          uint8 *next_order;
1138    
1139          in_uint16_le(s, length);          in_uint16_le(s, length);
1140          in_uint8s(s, 2);        /* flags */          in_uint16_le(s, flags); /* used by bmpcache2 */
1141          in_uint8(s, type);          in_uint8(s, type);
1142    
1143          next_order = s->p + length + 7;          next_order = s->p + (sint16) length + 7;
1144    
1145          switch (type)          switch (type)
1146          {          {
# Line 824  process_secondary_order(STREAM s) Line 1160  process_secondary_order(STREAM s)
1160                          process_fontcache(s);                          process_fontcache(s);
1161                          break;                          break;
1162    
1163                    case RDP_ORDER_RAW_BMPCACHE2:
1164                            process_bmpcache2(s, flags, False);     /* uncompressed */
1165                            break;
1166    
1167                    case RDP_ORDER_BMPCACHE2:
1168                            process_bmpcache2(s, flags, True);      /* compressed */
1169                            break;
1170    
1171                  default:                  default:
1172                          unimpl("secondary order %d\n", type);                          unimpl("secondary order %d\n", type);
1173          }          }
# Line 872  process_orders(STREAM s, uint16 num_orde Line 1216  process_orders(STREAM s, uint16 num_orde
1216                                  case RDP_ORDER_PATBLT:                                  case RDP_ORDER_PATBLT:
1217                                  case RDP_ORDER_MEMBLT:                                  case RDP_ORDER_MEMBLT:
1218                                  case RDP_ORDER_LINE:                                  case RDP_ORDER_LINE:
1219                                    case RDP_ORDER_POLYGON2:
1220                                    case RDP_ORDER_ELLIPSE2:
1221                                          size = 2;                                          size = 2;
1222                                          break;                                          break;
1223    
# Line 929  process_orders(STREAM s, uint16 num_orde Line 1275  process_orders(STREAM s, uint16 num_orde
1275                                          process_triblt(s, &os->triblt, present, delta);                                          process_triblt(s, &os->triblt, present, delta);
1276                                          break;                                          break;
1277    
1278                                    case RDP_ORDER_POLYGON:
1279                                            process_polygon(s, &os->polygon, present, delta);
1280                                            break;
1281    
1282                                    case RDP_ORDER_POLYGON2:
1283                                            process_polygon2(s, &os->polygon2, present, delta);
1284                                            break;
1285    
1286                                  case RDP_ORDER_POLYLINE:                                  case RDP_ORDER_POLYLINE:
1287                                          process_polyline(s, &os->polyline, present, delta);                                          process_polyline(s, &os->polyline, present, delta);
1288                                          break;                                          break;
1289    
1290                                    case RDP_ORDER_ELLIPSE:
1291                                            process_ellipse(s, &os->ellipse, present, delta);
1292                                            break;
1293    
1294                                    case RDP_ORDER_ELLIPSE2:
1295                                            process_ellipse2(s, &os->ellipse2, present, delta);
1296                                            break;
1297    
1298                                  case RDP_ORDER_TEXT2:                                  case RDP_ORDER_TEXT2:
1299                                          process_text2(s, &os->text2, present, delta);                                          process_text2(s, &os->text2, present, delta);
1300                                          break;                                          break;
# Line 948  process_orders(STREAM s, uint16 num_orde Line 1310  process_orders(STREAM s, uint16 num_orde
1310    
1311                  processed++;                  processed++;
1312          }          }
1313    #if 0
1314            /* not true when RDP_COMPRESSION is set */
1315          if (s->p != g_next_packet)          if (s->p != g_next_packet)
1316                  error("%d bytes remaining\n", (int) (g_next_packet - s->p));                  error("%d bytes remaining\n", (int) (g_next_packet - s->p));
1317    #endif
1318    
1319  }  }
1320    
1321  /* Reset order state */  /* Reset order state */

Legend:
Removed from v.540  
changed lines
  Added in v.831

  ViewVC Help
Powered by ViewVC 1.1.26