OSDN Git Service

Fix no pic
[uclinux-h8/uClinux-dist.git] / user / gnugk / sigmsg.cxx
1 /*
2  * sigmsg.cxx
3  *
4  * Structures to hold and process signaling messages
5  *
6  * Copyright (c) 2005, Michal Zygmuntowicz
7  *
8  * This work is published under the GNU Public License (GPL)
9  * see file COPYING for details.
10  * We also explicitely grant the right to link this code
11  * with the OpenH323 library.
12  *
13  * @(#) $Id: sigmsg.cxx,v 1.3 2006/04/14 13:56:19 willamowius Exp $
14  */
15 #include <ptlib.h>
16 #include <ptlib/sockets.h>
17 #include <q931.h>
18 #include <h225.h>
19 #include "sigmsg.h"
20
21
22 SignalingMsg::SignalingMsg(
23         Q931 *q931pdu, /// this pointer is not cloned and deleted by this class destructor
24         H225_H323_UserInformation *uuie, /// decoded User-User IE
25         const PIPSocket::Address &localAddr, /// an address the message has been received on
26         WORD localPort, /// a port number the message has been received on
27         const PIPSocket::Address &peerAddr, /// an address the message has been received from
28         WORD peerPort /// a port number the message has been received from
29         ) : m_q931(q931pdu), m_uuie(uuie), m_localAddr(localAddr), m_localPort(localPort),
30         m_peerAddr(peerAddr), m_peerPort(peerPort), m_changed(false), m_uuieChanged(false)
31 {
32         PAssertNULL(q931pdu);
33 }
34
35 SignalingMsg::~SignalingMsg()
36 {
37         delete m_uuie;
38         delete m_q931;
39 }
40
41 SignalingMsg* SignalingMsg::Clone()
42 {
43         return new SignalingMsg(new Q931(*m_q931), 
44                 (H225_H323_UserInformation*)(m_uuie->Clone()),
45                 m_localAddr, m_localPort, m_peerAddr, m_peerPort
46                 );
47 }
48
49 unsigned SignalingMsg::GetTag() const
50
51         return m_q931->GetMessageType(); 
52 }
53
54 PString SignalingMsg::GetTagName() const
55 {
56         return m_q931->GetMessageTypeName();
57 }
58
59 unsigned SignalingMsg::GetCallReference() const
60
61         return m_q931->GetCallReference(); 
62 }
63
64
65 void SignalingMsg::GetLocalAddr(
66         PIPSocket::Address &addr,
67         WORD &port
68         ) const
69 {
70         addr = m_localAddr;
71         port = m_localPort;
72 }
73
74 void SignalingMsg::GetLocalAddr(
75         PIPSocket::Address &addr
76         ) const
77 {
78         addr = m_localAddr;
79 }
80
81 void SignalingMsg::GetPeerAddr(
82         PIPSocket::Address &addr,
83         WORD &port
84         ) const
85 {
86         addr = m_peerAddr;
87         port = m_peerPort;
88 }
89
90 void SignalingMsg::GetPeerAddr(
91         PIPSocket::Address &addr
92         ) const
93 {
94         addr = m_peerAddr;
95 }
96
97 bool SignalingMsg::Encode(
98         PBYTEArray &buffer
99         )
100 {
101         if (m_uuie != NULL && m_uuieChanged) {
102                 PPER_Stream strm;
103                 m_uuie->Encode(strm);
104                 strm.CompleteEncoding();
105                 m_q931->SetIE(Q931::UserUserIE, strm);
106         }
107         return m_q931->Encode(buffer) ? true : false;
108 }
109
110 SignalingMsg* SignalingMsg::Create(
111         Q931 *q931pdu, /// this pointer is not cloned and deleted by this class destructor
112         H225_H323_UserInformation *uuie, /// decoded User-User IE
113         const PIPSocket::Address &localAddr, /// an address the message has been received on
114         WORD localPort, /// a port number the message has been received on
115         const PIPSocket::Address &peerAddr, /// an address the message has been received from
116         WORD peerPort /// a port number the message has been received from
117         )
118 {
119         if (q931pdu == NULL)
120                 return NULL;
121                 
122         if (uuie != NULL) {
123                 H225_H323_UU_PDU_h323_message_body &body = uuie->m_h323_uu_pdu.m_h323_message_body;
124                 switch (body.GetTag()) {
125                 case H225_H323_UU_PDU_h323_message_body::e_setup:
126                         return new SetupMsg(q931pdu, uuie, (H225_Setup_UUIE&)body, localAddr, localPort, peerAddr, peerPort);
127                 case H225_H323_UU_PDU_h323_message_body::e_callProceeding:
128                         return new CallProceedingMsg(q931pdu, uuie, (H225_CallProceeding_UUIE&)body, localAddr, localPort, peerAddr, peerPort);
129                 case H225_H323_UU_PDU_h323_message_body::e_connect:
130                         return new ConnectMsg(q931pdu, uuie, (H225_Connect_UUIE&)body, localAddr, localPort, peerAddr, peerPort);
131                 case H225_H323_UU_PDU_h323_message_body::e_alerting:
132                         return new AlertingMsg(q931pdu, uuie, (H225_Alerting_UUIE&)body, localAddr, localPort, peerAddr, peerPort);
133                 case H225_H323_UU_PDU_h323_message_body::e_information:
134                         return new InformationMsg(q931pdu, uuie, (H225_Information_UUIE&)body, localAddr, localPort, peerAddr, peerPort);
135                 case H225_H323_UU_PDU_h323_message_body::e_releaseComplete:
136                         return new ReleaseCompleteMsg(q931pdu, uuie, (H225_ReleaseComplete_UUIE&)body, localAddr, localPort, peerAddr, peerPort);
137                 case H225_H323_UU_PDU_h323_message_body::e_facility:
138                         return new FacilityMsg(q931pdu, uuie, (H225_Facility_UUIE&)body, localAddr, localPort, peerAddr, peerPort);
139                 case H225_H323_UU_PDU_h323_message_body::e_progress:
140                         return new ProgressMsg(q931pdu, uuie, (H225_Progress_UUIE&)body, localAddr, localPort, peerAddr, peerPort);
141 //              case H225_H323_UU_PDU_h323_message_body::e_status:
142 //                      return new StatusMsg(q931pdu, uuie, (H225_Status_UUIE&)body, localAddr, localPort, peerAddr, peerPort);
143 //              case H225_H323_UU_PDU_h323_message_body::e_statusInquiry:
144 //                      return new StatusInquiryMsg(q931pdu, uuie, (H225_StatusInquiry_UUIE&)body, localAddr, localPort, peerAddr, peerPort);
145 //              case H225_H323_UU_PDU_h323_message_body::e_notify:
146 //                      return new NotifyMsg(q931pdu, uuie, (H225_Notify_UUIE&)body, localAddr, localPort, peerAddr, peerPort);
147                 }
148         }
149         
150         return new SignalingMsg(q931pdu, uuie, localAddr, localPort, peerAddr, peerPort);
151 }
152
153 SignalingMsg& SignalingMsg::operator=(const SignalingMsg& obj)
154 {
155         // TODO: check for equal objects, duplicate pointer content ?
156         m_q931 = obj.m_q931;
157         m_uuie = obj.m_uuie;
158         m_localAddr = obj.m_localAddr;
159         m_localPort = obj.m_localPort;
160         m_peerAddr = obj.m_peerAddr;
161         m_peerPort = obj.m_peerPort;
162         m_changed = false;
163         m_uuieChanged = false;
164         return *this;
165 }