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;
022:
023: public abstract class RdpAbstractPacket implements java.io.Serializable {
024: public static final int MCS_HEADER = 1;
025: public static final int SECURE_HEADER = 2;
026: public static final int RDP_HEADER = 3;
027: public static final int CHANNEL_HEADER = 4;
028:
029: protected int m_mcs = -1;
030: protected int m_secure = -1;
031: protected int m_rdp = -1;
032: protected int m_channel = -1;
033: protected int m_start = -1;
034: protected int m_end = -1;
035:
036: public abstract int get8();
037:
038: public abstract int get8(int where);
039:
040: public abstract void set8(int what);
041:
042: public abstract void set8(int where, int what);
043:
044: public abstract int getLittleEndian16();
045:
046: public abstract int getLittleEndian16(int where);
047:
048: public abstract void setLittleEndian16(int what);
049:
050: public abstract void setLittleEndian16(int where, int what);
051:
052: public abstract int getBigEndian16();
053:
054: public abstract int getBigEndian16(int where);
055:
056: public abstract void setBigEndian16(int what);
057:
058: public abstract void setBigEndian16(int where, int what);
059:
060: public abstract int getLittleEndian32();
061:
062: public abstract int getLittleEndian32(int where);
063:
064: public abstract void setLittleEndian32(int what);
065:
066: public abstract void setLittleEndian32(int where, int what);
067:
068: public abstract int getBigEndian32();
069:
070: public abstract int getBigEndian32(int where);
071:
072: public abstract void setBigEndian32(int what);
073:
074: public abstract void setBigEndian32(int where, int what);
075:
076: public abstract void copyToByteArray(byte[] array,
077: int array_offset, int mem_offset, int len);
078:
079: public abstract void copyFromByteArray(byte[] array,
080: int array_offset, int mem_offset, int len);
081:
082: public abstract void copyToPacket(RdpPacket dst, int srcOffset,
083: int dstOffset, int len);
084:
085: public abstract void copyFromPacket(RdpPacket src, int srcOffset,
086: int dstOffset, int len);
087:
088: public abstract int getSize();
089:
090: public abstract int getPosition();
091:
092: public abstract void setPosition(int position);
093:
094: public abstract void incrementPosition(int length);
095:
096: public abstract int capacity();
097:
098: public void markEnd() {
099: m_end = getPosition();
100: }
101:
102: public void markEnd(int position) {
103: if (position > capacity()) {
104: throw new ArrayIndexOutOfBoundsException("Mark > size!");
105: }
106:
107: m_end = position;
108: }
109:
110: public int getEnd() {
111: return m_end;
112: }
113:
114: public void pushLayer(int header, int increment)
115: throws RdpDesktopException {
116: setHeader(header);
117: incrementPosition(increment);
118: }
119:
120: public void setHeader(int header) throws RdpDesktopException {
121: switch (header) {
122: case RdpPacket.MCS_HEADER: {
123: m_mcs = getPosition();
124: break;
125: }
126: case RdpPacket.SECURE_HEADER: {
127: m_secure = getPosition();
128: break;
129: }
130: case RdpPacket.RDP_HEADER: {
131: m_rdp = getPosition();
132: break;
133: }
134: case RdpPacket.CHANNEL_HEADER: {
135: m_channel = getPosition();
136: break;
137: }
138: default: {
139: throw new RdpDesktopException("Wrong Header!");
140: }
141: }
142: }
143:
144: public int getHeader(int header) throws RdpDesktopException {
145: switch (header) {
146: case RdpPacket.MCS_HEADER: {
147: return m_mcs;
148: }
149: case RdpPacket.SECURE_HEADER: {
150: return m_secure;
151: }
152: case RdpPacket.RDP_HEADER: {
153: return m_rdp;
154: }
155: case RdpPacket.CHANNEL_HEADER: {
156: return m_channel;
157: }
158: default: {
159: throw new RdpDesktopException("Wrong Header!");
160: }
161: }
162: }
163:
164: public void setStart(int position) {
165: m_start = position;
166: }
167:
168: public int getStart() {
169: return m_start;
170: }
171:
172: public void outUnicodeString(String str, int len) {
173: int i = 0, j = 0;
174:
175: if (str.length() != 0) {
176: char[] name = str.toCharArray();
177: while (i < len) {
178: setLittleEndian16((short) name[j++]);
179: i += 2;
180: }
181:
182: setLittleEndian16(0);
183: } else {
184: setLittleEndian16(0);
185: }
186: }
187:
188: public void out_uint8p(String str, int length) {
189: byte[] bStr = str.getBytes();
190: copyFromByteArray(bStr, 0, getPosition(), bStr.length);
191: incrementPosition(length);
192: }
193: }
|