1 |
/* -*- c-basic-offset: 8 -*- |
2 |
rdesktop: A Remote Desktop Protocol client. |
3 |
Protocol services - Channel register |
4 |
Copyright (C) Erik Forsberg <forsberg@cendio.se> 2003 |
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 "rdesktop.h" |
22 |
|
23 |
static uint16 num_channels; |
24 |
static rdp5_channel *channels[MAX_RDP5_CHANNELS]; |
25 |
|
26 |
uint16 |
27 |
get_num_channels(void) |
28 |
{ |
29 |
return num_channels; |
30 |
} |
31 |
|
32 |
void |
33 |
register_channel(char *name, uint32 flags, void (*callback) (STREAM, uint16)) |
34 |
{ |
35 |
if (num_channels > MAX_RDP5_CHANNELS) |
36 |
{ |
37 |
error("Maximum number of RDP5 channels reached. Redefine MAX_RDP5_CHANNELS in constants.h and recompile!\n!"); |
38 |
} |
39 |
num_channels++; |
40 |
channels[num_channels - 1] = xrealloc(channels[num_channels - 1], |
41 |
sizeof(rdp5_channel) * num_channels); |
42 |
channels[num_channels - 1]->channelno = MCS_GLOBAL_CHANNEL + num_channels; |
43 |
strcpy(channels[num_channels - 1]->name, name); |
44 |
channels[num_channels - 1]->channelflags = flags; |
45 |
channels[num_channels - 1]->channelcallback = callback; |
46 |
} |
47 |
|
48 |
rdp5_channel * |
49 |
find_channel_by_channelno(uint16 channelno) |
50 |
{ |
51 |
if (channelno > MCS_GLOBAL_CHANNEL + num_channels) |
52 |
{ |
53 |
warning("Channel %d not defined. Highest channel defined is %d\n", |
54 |
channelno, MCS_GLOBAL_CHANNEL + num_channels); |
55 |
return NULL; |
56 |
} |
57 |
else |
58 |
{ |
59 |
return channels[channelno - MCS_GLOBAL_CHANNEL - 1]; |
60 |
} |
61 |
} |
62 |
|
63 |
rdp5_channel * |
64 |
find_channel_by_num(uint16 num) |
65 |
{ |
66 |
if (num > num_channels) |
67 |
{ |
68 |
error("There are only %d channels defined, channel %d doesn't exist\n", |
69 |
num_channels, num); |
70 |
} |
71 |
else |
72 |
{ |
73 |
return channels[num]; |
74 |
} |
75 |
return NULL; // Shut the compiler up |
76 |
} |
77 |
|
78 |
|
79 |
|
80 |
void |
81 |
dummy_callback(STREAM s, uint16 channelno) |
82 |
{ |
83 |
warning("Server is sending information on our dummy channel (%d). Why?\n", channelno); |
84 |
} |
85 |
|
86 |
void |
87 |
channels_init(void) |
88 |
{ |
89 |
DEBUG_RDP5(("channels_init\n")); |
90 |
register_channel("dummych", 0xc0a0, dummy_callback); |
91 |
register_channel("cliprdr", 0xc0a0, cliprdr_callback); |
92 |
} |