Fix changelog email address
[freerdp-ubuntu-pcb-backport.git] / libfreerdp-core / channel.c
1 /**
2  * FreeRDP: A Remote Desktop Protocol Client
3  * Virtual Channels
4  *
5  * Copyright 2011 Vic Lee
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <freerdp/freerdp.h>
24 #include <freerdp/peer.h>
25 #include <freerdp/constants.h>
26 #include <freerdp/utils/memory.h>
27 #include <freerdp/utils/stream.h>
28
29 #include "rdp.h"
30 #include "channel.h"
31
32 boolean freerdp_channel_send(rdpRdp* rdp, uint16 channel_id, uint8* data, int size)
33 {
34         STREAM* s;
35         uint32 flags;
36         int i, left;
37         int chunk_size;
38         rdpChannel* channel = NULL;
39
40         for (i = 0; i < rdp->settings->num_channels; i++)
41         {
42                 if (rdp->settings->channels[i].channel_id == channel_id)
43                 {
44                         channel = &rdp->settings->channels[i];
45                         break;
46                 }
47         }
48
49         if (channel == NULL)
50         {
51                 printf("freerdp_channel_send: unknown channel_id %d\n", channel_id);
52                 return false;
53         }
54
55         flags = CHANNEL_FLAG_FIRST;
56         left = size;
57         while (left > 0)
58         {
59                 s = rdp_send_stream_init(rdp);
60
61                 if (left > (int) rdp->settings->vc_chunk_size)
62                 {
63                         chunk_size = rdp->settings->vc_chunk_size;
64                 }
65                 else
66                 {
67                         chunk_size = left;
68                         flags |= CHANNEL_FLAG_LAST;
69                 }
70                 if ((channel->options & CHANNEL_OPTION_SHOW_PROTOCOL))
71                 {
72                         flags |= CHANNEL_FLAG_SHOW_PROTOCOL;
73                 }
74
75                 stream_write_uint32(s, size);
76                 stream_write_uint32(s, flags);
77                 stream_check_size(s, chunk_size);
78                 stream_write(s, data, chunk_size);
79
80                 rdp_send(rdp, s, channel_id);
81
82                 data += chunk_size;
83                 left -= chunk_size;
84                 flags = 0;
85         }
86
87         return true;
88 }
89
90 void freerdp_channel_process(freerdp* instance, STREAM* s, uint16 channel_id)
91 {
92         uint32 length;
93         uint32 flags;
94         int chunk_length;
95
96         stream_read_uint32(s, length);
97         stream_read_uint32(s, flags);
98         chunk_length = stream_get_left(s);
99
100         IFCALL(instance->ReceiveChannelData, instance,
101                 channel_id, stream_get_tail(s), chunk_length, flags, length);
102 }
103
104 void freerdp_channel_peer_process(freerdp_peer* client, STREAM* s, uint16 channel_id)
105 {
106         uint32 length;
107         uint32 flags;
108         int chunk_length;
109
110         stream_read_uint32(s, length);
111         stream_read_uint32(s, flags);
112         chunk_length = stream_get_left(s);
113
114         IFCALL(client->ReceiveChannelData, client,
115                 channel_id, stream_get_tail(s), chunk_length, flags, length);
116 }