001: ///////////////////////////////////////////////////////////////////////////////
002: //
003: // This program is free software; you can redistribute it and/or modify
004: // it under the terms of the GNU General Public License and GNU Library
005: // General Public License as published by the Free Software Foundation;
006: // either version 2, or (at your option) any later version.
007: //
008: // This program is distributed in the hope that it will be useful,
009: // but WITHOUT ANY WARRANTY; without even the implied warranty of
010: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
011: // GNU General Public License and GNU Library General Public License
012: // for more details.
013: //
014: // You should have received a copy of the GNU General Public License
015: // and GNU Library General Public License along with this program; if
016: // not, write to the Free Software Foundation, 675 Mass Ave, Cambridge,
017: // MA 02139, USA.
018: //
019: ///////////////////////////////////////////////////////////////////////////////
020:
021: package org.rdesktop.server.rdp.rdp5;
022:
023: import java.io.IOException;
024:
025: import org.rdesktop.server.rdp.*;
026: import org.rdesktop.server.rdp.crypto.CryptoException;
027:
028: public abstract class VChannel {
029: private int m_mcs_id = 0;
030: protected RdpSecure m_secureLayer;
031:
032: public VChannel(RdpSecure secureLayer) {
033: m_secureLayer = secureLayer;
034: }
035:
036: public abstract String name();
037:
038: public abstract int flags();
039:
040: public abstract void process(RdpPacket data)
041: throws RdpDesktopException, IOException, CryptoException;
042:
043: public void set_mcs_id(int mcs_id) {
044: m_mcs_id = mcs_id;
045: }
046:
047: public int mcs_id() {
048: return m_mcs_id;
049: }
050:
051: public RdpPacket init(int length) throws RdpDesktopException {
052: RdpPacket s;
053:
054: s = m_secureLayer.init(
055: RdpOptions.encryption ? RdpSecure.SEC_ENCRYPT : 0,
056: length + 8);
057: s.setHeader(RdpPacket.CHANNEL_HEADER);
058: s.incrementPosition(8);
059:
060: return s;
061: }
062:
063: public void send_packet(RdpPacket data) throws RdpDesktopException,
064: IOException, CryptoException {
065: if (m_secureLayer == null) {
066: return;
067: }
068:
069: int data_offset = 0;
070: int packets_sent = 0;
071: int length = data.getSize();
072: int num_packets = (length / VChannels.CHANNEL_CHUNK_LENGTH);
073: num_packets += length - (VChannels.CHANNEL_CHUNK_LENGTH)
074: * num_packets;
075:
076: while (data_offset < length) {
077: int this Length = Math.min(VChannels.CHANNEL_CHUNK_LENGTH,
078: length - data_offset);
079:
080: RdpPacket s = m_secureLayer.init(
081: RdpOptions.encryption ? RdpSecure.SEC_ENCRYPT : 0,
082: 8 + this Length);
083: s.setLittleEndian32(length);
084:
085: int flags = ((data_offset == 0) ? VChannels.CHANNEL_FLAG_FIRST
086: : 0);
087: if (data_offset + this Length >= length) {
088: flags |= VChannels.CHANNEL_FLAG_LAST;
089: }
090:
091: if ((flags() & VChannels.CHANNEL_OPTION_SHOW_PROTOCOL) != 0) {
092: flags |= VChannels.CHANNEL_FLAG_SHOW_PROTOCOL;
093: }
094:
095: s.setLittleEndian32(flags);
096: s.copyFromPacket(data, data_offset, s.getPosition(),
097: this Length);
098: s.incrementPosition(this Length);
099: s.markEnd();
100:
101: data_offset += this Length;
102:
103: if (m_secureLayer != null) {
104: m_secureLayer.send_to_channel(s,
105: RdpOptions.encryption ? RdpSecure.SEC_ENCRYPT
106: : 0, mcs_id());
107: }
108:
109: packets_sent++;
110: }
111: }
112: }
|