Added missing build dependency
[opal/cbnco.git] / src / t120 / x224.cxx
blob7184699b8fcba1a3850a966aecb78cc76ae9c4c0
1 /*
2 * x224.cxx
4 * X.224 protocol handler
6 * Open H323 Library
8 * Copyright (c) 1998-2000 Equivalence Pty. Ltd.
10 * The contents of this file are subject to the Mozilla Public License
11 * Version 1.0 (the "License"); you may not use this file except in
12 * compliance with the License. You may obtain a copy of the License at
13 * http://www.mozilla.org/MPL/
15 * Software distributed under the License is distributed on an "AS IS"
16 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17 * the License for the specific language governing rights and limitations
18 * under the License.
20 * The Original Code is Open H323 Library.
22 * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
24 * Contributor(s): ______________________________________.
26 * $Log$
27 * Revision 2.2 2002/09/04 06:01:49 robertj
28 * Updated to OpenH323 v1.9.6
30 * Revision 2.1 2002/07/01 04:56:33 robertj
31 * Updated to OpenH323 v1.9.1
33 * Revision 2.0 2001/07/27 15:48:25 robertj
34 * Conversion of OpenH323 to Open Phone Abstraction Library (OPAL)
36 * Revision 1.12 2002/09/03 06:21:01 robertj
37 * Cosmetic change to formatting.
39 * Revision 1.11 2002/08/05 10:03:48 robertj
40 * Cosmetic changes to normalise the usage of pragma interface/implementation.
42 * Revision 1.10 2002/06/27 03:11:12 robertj
43 * Fixed encoding bugs, thanks Greg Adams
45 * Revision 1.9 2001/02/09 05:13:56 craigs
46 * Added pragma implementation to (hopefully) reduce the executable image size
47 * under Linux
49 * Revision 1.8 2000/05/02 04:32:28 robertj
50 * Fixed copyright notice comment.
52 * Revision 1.7 2000/04/18 11:36:40 robertj
53 * Fixed bug in setting data compont size in X224 packet, thanks Wolfgang Platzer
55 * Revision 1.6 1999/11/19 01:00:07 robertj
56 * Fixed bug that disallowed zero length data PDU's, thanks Dave Kristol.
58 * Revision 1.5 1999/11/15 14:11:29 robertj
59 * Fixed trace output stream being put back after setting hex/fillchar modes.
61 * Revision 1.4 1999/09/03 14:03:54 robertj
62 * Fixed warning under GNU compiler.
64 * Revision 1.3 1999/08/31 13:30:20 robertj
65 * Added gatekeeper support.
67 * Revision 1.2 1999/06/09 05:26:20 robertj
68 * Major restructuring of classes.
70 * Revision 1.1 1998/12/14 09:13:48 robertj
71 * Initial revision
75 #include <ptlib.h>
77 #ifdef __GNUC__
78 #pragma implementation "x224.h"
79 #endif
81 #include <t120/x224.h>
83 #include <ptlib/sockets.h>
86 ///////////////////////////////////////////////////////////////////////////////
88 X224::X224()
93 void X224::PrintOn(ostream & strm) const
95 int indent = 2;
96 strm << setprecision(indent) << "{\n"
97 << setw(indent) << ' ' << "code=";
98 switch (GetCode()) {
99 case ConnectRequest :
100 strm << "ConnectRequest";
101 break;
102 case ConnectConfirm :
103 strm << "ConnectConfirm";
104 break;
105 case DataPDU :
106 strm << "DataPDU";
109 char fillchar = strm.fill();
111 strm << '\n'
112 << setw(indent) << ' ' << "data: " << data.GetSize() << " bytes\n"
113 << hex;
115 PINDEX i = 0;
116 while (i < data.GetSize()) {
117 strm << setfill(' ') << setw(indent) << ' ' << setfill('0');
118 PINDEX j;
119 for (j = 0; j < 16; j++)
120 if (i+j < data.GetSize())
121 strm << setw(2) << (unsigned)data[i+j] << ' ';
122 else
123 strm << " ";
124 strm << " ";
125 for (j = 0; j < 16; j++) {
126 if (i+j < data.GetSize()) {
127 if (isprint(data[i+j]))
128 strm << data[i+j];
129 else
130 strm << ' ';
133 strm << '\n';
134 i += 16;
136 strm << dec << setfill(fillchar)
137 << setw(indent-1) << '}'
138 << setprecision(indent-2);
142 BOOL X224::Decode(const PBYTEArray & rawData)
144 PINDEX packetLength = rawData.GetSize();
146 PINDEX headerLength = rawData[0];
147 if (packetLength < headerLength + 1) // Not enough bytes
148 return FALSE;
150 header.SetSize(headerLength);
151 memcpy(header.GetPointer(), (const BYTE *)rawData+1, headerLength);
153 packetLength -= headerLength + 1;
154 data.SetSize(packetLength);
155 if (packetLength > 0)
156 memcpy(data.GetPointer(), (const BYTE *)rawData+headerLength+1, packetLength);
158 return TRUE;
162 BOOL X224::Encode(PBYTEArray & rawData) const
164 PINDEX headerLength = header.GetSize();
165 PINDEX dataLength = data.GetSize();
167 if (!rawData.SetSize(headerLength + dataLength + 1))
168 return FALSE;
170 rawData[0] = (BYTE)headerLength;
171 memcpy(rawData.GetPointer() + 1, header, headerLength);
173 if (dataLength > 0)
174 memcpy(rawData.GetPointer()+headerLength+1, data, dataLength);
176 return TRUE;
180 void X224::BuildConnectRequest()
182 data.SetSize(0);
183 header.SetSize(6);
184 header[0] = ConnectRequest;
185 header[1] = 0;
186 header[2] = 0x7b;
187 header[3] = 2;
188 header[4] = 0;
189 header[5] = 0;
193 void X224::BuildConnectConfirm()
195 data.SetSize(0);
196 header.SetSize(6);
197 header[0] = ConnectConfirm;
198 header[1] = 0;
199 header[2] = 0x7b;
200 header[3] = 2;
201 header[4] = 0;
202 header[5] = 0;
206 void X224::BuildData(const PBYTEArray & d)
208 header.SetSize(2);
209 header[0] = DataPDU;
210 header[1] = 0x80;
211 data = d;
216 /////////////////////////////////////////////////////////////////////////////