~ubuntu-branches/ubuntu/raring/freerdp/raring

« back to all changes in this revision

Viewing changes to libfreerdp/rdp5.c

  • Committer: Bazaar Package Importer
  • Author(s): Otavio Salvador
  • Date: 2010-06-23 21:39:09 UTC
  • Revision ID: james.westby@ubuntu.com-20100623213909-bb9pvvv03913tdv6
Tags: upstream-0.7.1
ImportĀ upstreamĀ versionĀ 0.7.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- c-basic-offset: 8 -*-
 
2
   rdesktop: A Remote Desktop Protocol client.
 
3
   Protocol services - RDP5 short form PDU processing
 
4
   Copyright (C) Matthew Chapman 1999-2008
 
5
   Copyright (C) Erik Forsberg 2003-2008
 
6
 
 
7
   This program is free software; you can redistribute it and/or modify
 
8
   it under the terms of the GNU General Public License as published by
 
9
   the Free Software Foundation; either version 2 of the License, or
 
10
   (at your option) any later version.
 
11
 
 
12
   This program is distributed in the hope that it will be useful,
 
13
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
   GNU General Public License for more details.
 
16
 
 
17
   You should have received a copy of the GNU General Public License
 
18
   along with this program; if not, write to the Free Software
 
19
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
20
*/
 
21
 
 
22
#include "frdp.h"
 
23
#include "rdp.h"
 
24
#include "orders.h"
 
25
#include "mem.h"
 
26
 
 
27
void
 
28
rdp5_process(rdpRdp * rdp, STREAM s)
 
29
{
 
30
        uint16 length, count, x, y;
 
31
        uint8 type, ctype;
 
32
        uint8 *next;
 
33
 
 
34
        uint32 roff, rlen;
 
35
        struct stream *ns = &(rdp->mppc_dict.ns);
 
36
        struct stream *ts;
 
37
 
 
38
        ui_begin_update(rdp->inst);
 
39
        while (s->p < s->end)
 
40
        {
 
41
                in_uint8(s, type);
 
42
                if (type & RDP5_COMPRESSED)
 
43
                {
 
44
                        in_uint8(s, ctype);
 
45
                        in_uint16_le(s, length);
 
46
                        type ^= RDP5_COMPRESSED;
 
47
                }
 
48
                else
 
49
                {
 
50
                        ctype = 0;
 
51
                        in_uint16_le(s, length);
 
52
                }
 
53
                rdp->next_packet = next = s->p + length;
 
54
 
 
55
                if (ctype & RDP_MPPC_COMPRESSED)
 
56
                {
 
57
                        if (mppc_expand(rdp, s->p, length, ctype, &roff, &rlen) == -1)
 
58
                                ui_error(rdp->inst, "error while decompressing packet\n");
 
59
 
 
60
                        /* allocate memory and copy the uncompressed data into the temporary stream */
 
61
                        ns->data = (uint8 *) xrealloc(ns->data, rlen);
 
62
 
 
63
                        memcpy((ns->data), (unsigned char *) (rdp->mppc_dict.hist + roff), rlen);
 
64
 
 
65
                        ns->size = rlen;
 
66
                        ns->end = (ns->data + ns->size);
 
67
                        ns->p = ns->data;
 
68
                        ns->rdp_hdr = ns->p;
 
69
 
 
70
                        ts = ns;
 
71
                }
 
72
                else
 
73
                        ts = s;
 
74
 
 
75
                switch (type)
 
76
                {
 
77
                        case 0: /* update orders */
 
78
                                in_uint16_le(ts, count);
 
79
                                process_orders(rdp->orders, ts, count);
 
80
                                break;
 
81
                        case 1: /* update bitmap */
 
82
                                in_uint8s(ts, 2);       /* part length */
 
83
                                process_bitmap_updates(rdp, ts);
 
84
                                break;
 
85
                        case 2: /* update palette */
 
86
                                in_uint8s(ts, 2);       /* uint16 = 2 */
 
87
                                process_palette(rdp, ts);
 
88
                                break;
 
89
                        case 3: /* update synchronize */
 
90
                                break;
 
91
                        case 5: /* null pointer */
 
92
                                ui_set_null_cursor(rdp->inst);
 
93
                                break;
 
94
                        case 6: /* default pointer */
 
95
                                break;
 
96
                        case 8: /* pointer position */
 
97
                                in_uint16_le(ts, x);
 
98
                                in_uint16_le(ts, y);
 
99
                                if (s_check(ts))
 
100
                                        ui_move_pointer(rdp->inst, x, y);
 
101
                                break;
 
102
                        case 9: /* color pointer */
 
103
                                process_colour_pointer_pdu(rdp, ts);
 
104
                                break;
 
105
                        case 10:        /* cached pointer */
 
106
                                process_cached_pointer_pdu(rdp, ts);
 
107
                                break;
 
108
                        case 11:
 
109
                                process_new_pointer_pdu(rdp, ts);
 
110
                                break;
 
111
                        default:
 
112
                                ui_unimpl(rdp->inst, "RDP5 opcode %d\n", type);
 
113
                }
 
114
 
 
115
                s->p = next;
 
116
        }
 
117
        ui_end_update(rdp->inst);
 
118
}