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

« back to all changes in this revision

Viewing changes to libfreerdp/chan.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
   Channels
 
4
   Copyright (C) Jay Sorg 2009
 
5
 
 
6
   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
 
8
   the Free Software Foundation; either version 2 of the License, or
 
9
   (at your option) any later version.
 
10
 
 
11
   This program is distributed in the hope that it will be useful,
 
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
   GNU General Public License for more details.
 
15
 
 
16
   You should have received a copy of the GNU General Public License
 
17
   along with this program; if not, write to the Free Software
 
18
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
19
*/
 
20
 
 
21
#include <stdio.h>
 
22
#include <stdlib.h>
 
23
#include <string.h>
 
24
#include <freerdp/constants_vchan.h>
 
25
#include "frdp.h"
 
26
#include "chan.h"
 
27
#include "mcs.h"
 
28
#include "mem.h"
 
29
#include "secure.h"
 
30
#include "rdp.h"
 
31
#include "rdpset.h"
 
32
 
 
33
int
 
34
vchan_send(rdpChannels * chan, int mcs_id, char * data, int total_length)
 
35
{
 
36
        STREAM s;
 
37
        int sec_flags;
 
38
        int length;
 
39
        int sent;
 
40
        int chan_flags;
 
41
        int chan_index;
 
42
        rdpSet * settings;
 
43
        struct rdp_chan * channel;
 
44
 
 
45
        settings = chan->mcs->sec->rdp->settings;
 
46
        chan_index = (mcs_id - MCS_GLOBAL_CHANNEL) - 1;
 
47
        if ((chan_index < 0) || (chan_index >= settings->num_channels))
 
48
        {
 
49
                ui_error(chan->mcs->sec->rdp->inst, "error\n");
 
50
                return 0;
 
51
        }
 
52
        channel = &(settings->channels[chan_index]);
 
53
        chan_flags = CHANNEL_FLAG_FIRST;
 
54
        sent = 0;
 
55
        sec_flags = settings->encryption ? SEC_ENCRYPT : 0;
 
56
        while (sent < total_length)
 
57
        {
 
58
                length = MIN(CHANNEL_CHUNK_LENGTH, total_length);
 
59
                length = MIN(total_length - sent, length);
 
60
                if ((sent + length) >= total_length)
 
61
                {
 
62
                        chan_flags |= CHANNEL_FLAG_LAST;
 
63
                }
 
64
                if (channel->flags & CHANNEL_OPTION_SHOW_PROTOCOL)
 
65
                {
 
66
                        chan_flags |= CHANNEL_FLAG_SHOW_PROTOCOL;
 
67
                }
 
68
                s = sec_init(chan->mcs->sec, sec_flags, length + 8);
 
69
                out_uint32_le(s, total_length);
 
70
                out_uint32_le(s, chan_flags);
 
71
                out_uint8p(s, data + sent, length);
 
72
                s_mark_end(s);
 
73
                sec_send_to_channel(chan->mcs->sec, s, sec_flags, mcs_id);
 
74
                sent += length;
 
75
                chan_flags = 0;
 
76
        }
 
77
        return sent;
 
78
}
 
79
 
 
80
void
 
81
vchan_process(rdpChannels * chan, STREAM s, int mcs_id)
 
82
{
 
83
        int length;
 
84
        int total_length;
 
85
        int flags;
 
86
        char * data;
 
87
 
 
88
        in_uint32_le(s, total_length);
 
89
        in_uint32_le(s, flags);
 
90
        length = (int) (s->end - s->p);
 
91
        data = (char *) (s->p);
 
92
        s->p += length;
 
93
        ui_channel_data(chan->mcs->sec->rdp->inst, mcs_id, data, length, flags, total_length);
 
94
}
 
95
 
 
96
rdpChannels *
 
97
vchan_new(struct rdp_mcs * mcs)
 
98
{
 
99
        rdpChannels * self;
 
100
 
 
101
        self = (rdpChannels *) xmalloc(sizeof(rdpChannels));
 
102
        if (self != NULL)
 
103
        {
 
104
                memset(self, 0, sizeof(rdpChannels));
 
105
                self->mcs = mcs;
 
106
        }
 
107
        return self;
 
108
}
 
109
 
 
110
void
 
111
vchan_free(rdpChannels * chan)
 
112
{
 
113
        if (chan != NULL)
 
114
        {
 
115
                xfree(chan);
 
116
        }
 
117
}