4 * X.224 protocol handler
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
20 * The Original Code is Open H323 Library.
22 * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
24 * Contributor(s): ______________________________________.
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
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
78 #pragma implementation "x224.h"
81 #include <t120/x224.h>
83 #include <ptlib/sockets.h>
86 ///////////////////////////////////////////////////////////////////////////////
93 void X224::PrintOn(ostream
& strm
) const
96 strm
<< setprecision(indent
) << "{\n"
97 << setw(indent
) << ' ' << "code=";
100 strm
<< "ConnectRequest";
102 case ConnectConfirm
:
103 strm
<< "ConnectConfirm";
109 char fillchar
= strm
.fill();
112 << setw(indent
) << ' ' << "data: " << data
.GetSize() << " bytes\n"
116 while (i
< data
.GetSize()) {
117 strm
<< setfill(' ') << setw(indent
) << ' ' << setfill('0');
119 for (j
= 0; j
< 16; j
++)
120 if (i
+j
< data
.GetSize())
121 strm
<< setw(2) << (unsigned)data
[i
+j
] << ' ';
125 for (j
= 0; j
< 16; j
++) {
126 if (i
+j
< data
.GetSize()) {
127 if (isprint(data
[i
+j
]))
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
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
);
162 BOOL
X224::Encode(PBYTEArray
& rawData
) const
164 PINDEX headerLength
= header
.GetSize();
165 PINDEX dataLength
= data
.GetSize();
167 if (!rawData
.SetSize(headerLength
+ dataLength
+ 1))
170 rawData
[0] = (BYTE
)headerLength
;
171 memcpy(rawData
.GetPointer() + 1, header
, headerLength
);
174 memcpy(rawData
.GetPointer()+headerLength
+1, data
, dataLength
);
180 void X224::BuildConnectRequest()
184 header
[0] = ConnectRequest
;
193 void X224::BuildConnectConfirm()
197 header
[0] = ConnectConfirm
;
206 void X224::BuildData(const PBYTEArray
& d
)
216 /////////////////////////////////////////////////////////////////////////////