Utilise new MergeSym feature to no longer overwrite the source .DEF file when buildin...
[openh323.git] / src / t120proto.cxx
blob14cf4e8bb1e6ff33912a69a9689e0d6012261749
1 /*
2 * t120proto.cxx
4 * T.120 protocol handler
6 * Open Phone Abstraction 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 1.6 2004/05/20 02:07:29 csoutheren
28 * Use macro to work around MSVC internal compiler errors
30 * Revision 1.5 2004/05/19 07:38:24 csoutheren
31 * Changed OpalMediaFormat handling to use abstract factory method functions
33 * Revision 1.4 2002/09/03 06:04:11 robertj
34 * Added globally accessible functions for media format name.
36 * Revision 1.3 2002/08/05 10:03:48 robertj
37 * Cosmetic changes to normalise the usage of pragma interface/implementation.
39 * Revision 1.2 2002/02/01 01:47:34 robertj
40 * Some more fixes for T.120 channel establishment, more to do!
42 * Revision 1.1 2001/07/17 04:44:32 robertj
43 * Partial implementation of T.120 and T.38 logical channels.
47 #include <ptlib.h>
49 #ifdef __GNUC__
50 #pragma implementation "t120proto.h"
51 #endif
53 #include "t120proto.h"
55 #include "transports.h"
56 #include "mcspdu.h"
57 #include "x224.h"
60 class T120_X224 : public X224 {
61 PCLASSINFO(T120_X224, X224);
62 public:
63 BOOL Read(H323Transport & transport);
64 BOOL Write(H323Transport & transport);
68 class T120ConnectPDU : public MCS_ConnectMCSPDU {
69 PCLASSINFO(T120ConnectPDU, MCS_ConnectMCSPDU);
70 public:
71 BOOL Read(H323Transport & transport);
72 BOOL Write(H323Transport & transport);
73 protected:
74 T120_X224 x224;
78 #define new PNEW
80 /////////////////////////////////////////////////////////////////////////////
82 BOOL T120_X224::Read(H323Transport & transport)
84 PBYTEArray rawData;
86 if (!transport.ReadPDU(rawData)) {
87 PTRACE(1, "T120\tRead of X224 failed: " << transport.GetErrorText());
88 return FALSE;
91 if (Decode(rawData)) {
92 PTRACE(1, "T120\tDecode of PDU failed:\n " << setprecision(2) << *this);
93 return FALSE;
96 PTRACE(4, "T120\tRead X224 PDU:\n " << setprecision(2) << *this);
97 return TRUE;
101 BOOL T120_X224::Write(H323Transport & transport)
103 PBYTEArray rawData;
105 PTRACE(4, "T120\tWrite X224 PDU:\n " << setprecision(2) << *this);
107 if (!Encode(rawData)) {
108 PTRACE(1, "T120\tEncode of PDU failed:\n " << setprecision(2) << *this);
109 return FALSE;
112 if (!transport.WritePDU(rawData)) {
113 PTRACE(1, "T120\tWrite X224 PDU failed: " << transport.GetErrorText());
114 return FALSE;
117 return TRUE;
121 /////////////////////////////////////////////////////////////////////////////
123 BOOL T120ConnectPDU::Read(H323Transport & transport)
125 if (!x224.Read(transport))
126 return FALSE;
128 // An X224 Data PDU...
129 if (x224.GetCode() != X224::DataPDU) {
130 PTRACE(1, "T120\tX224 must be data PDU");
131 return FALSE;
134 // ... contains the T120 MCS PDU
135 PBER_Stream ber = x224.GetData();
136 if (!Decode(ber)) {
137 PTRACE(1, "T120\tDecode of PDU failed:\n " << setprecision(2) << *this);
138 return FALSE;
141 PTRACE(4, "T120\tReceived MCS Connect PDU:\n " << setprecision(2) << *this);
142 return TRUE;
146 BOOL T120ConnectPDU::Write(H323Transport & transport)
148 PTRACE(4, "T120\tSending MCS Connect PDU:\n " << setprecision(2) << *this);
150 PBER_Stream ber;
151 Encode(ber);
152 ber.CompleteEncoding();
153 x224.BuildData(ber);
154 return x224.Write(transport);
158 /////////////////////////////////////////////////////////////////////////////
160 OpalT120Protocol::OpalT120Protocol()
165 BOOL OpalT120Protocol::Originate(H323Transport & transport)
167 PTRACE(3, "T120\tOriginate, sending X224 CONNECT-REQUEST");
169 T120_X224 x224;
170 x224.BuildConnectRequest();
171 if (!x224.Write(transport))
172 return FALSE;
174 transport.SetReadTimeout(10000); // Wait 10 seconds for reply
175 if (!x224.Read(transport))
176 return FALSE;
178 if (x224.GetCode() != X224::ConnectConfirm) {
179 PTRACE(1, "T120\tPDU was not X224 CONNECT-CONFIRM");
180 return FALSE;
183 T120ConnectPDU pdu;
184 while (pdu.Read(transport)) {
185 if (!HandleConnect(pdu))
186 return TRUE;
189 return FALSE;
193 BOOL OpalT120Protocol::Answer(H323Transport & transport)
195 PTRACE(3, "T120\tAnswer, awaiting X224 CONNECT-REQUEST");
197 T120_X224 x224;
198 transport.SetReadTimeout(60000); // Wait 60 seconds for reply
200 do {
201 if (!x224.Read(transport))
202 return FALSE;
203 } while (x224.GetCode() != X224::ConnectRequest);
205 x224.BuildConnectConfirm();
206 if (!x224.Write(transport))
207 return FALSE;
209 T120ConnectPDU pdu;
210 while (pdu.Read(transport)) {
211 if (!HandleConnect(pdu))
212 return TRUE;
215 return FALSE;
219 BOOL OpalT120Protocol::HandleConnect(const MCS_ConnectMCSPDU & /*pdu*/)
221 return TRUE;
225 BOOL OpalT120Protocol::HandleDomain(const MCS_DomainMCSPDU & /*pdu*/)
227 return TRUE;
231 /////////////////////////////////////////////////////////////////////////////