File: sigmsg.h

package info (click to toggle)
gnugk 2%3A3.0.2-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 5,208 kB
  • sloc: cpp: 48,392; php: 2,314; sql: 2,089; perl: 588; sh: 511; java: 220; makefile: 198
file content (185 lines) | stat: -rw-r--r-- 6,485 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
 * sigmsg.h
 *
 * Structures to hold and process signaling messages
 *
 * Copyright (c) 2005, Michal Zygmuntowicz
 * Copyright (c) 2005-2010, Jan Willamowius
 *
 * This work is published under the GNU Public License version 2 (GPLv2)
 * see file COPYING for details.
 * We also explicitly grant the right to link this code
 * with the OpenH323/H323Plus and OpenSSL library.
 *
 */

#ifndef SIGMSG_H
#define SIGMSG_H "@(#) $Id: sigmsg.h,v 1.10 2010/10/25 15:01:51 willamowius Exp $"


#include <ptlib/sockets.h>
#include "q931.h"
class H225_H323_UserInformation;
class H225_Setup_UUIE;
class H225_SetupAck_UUIE;
class H225_CallProceeding_UUIE;
class H225_Alerting_UUIE;
class H225_Connect_UUIE;
class H225_Progress_UUIE;
class H225_Facility_UUIE;
class H225_ReleaseComplete_UUIE;
class H225_Information_UUIE;
class H225_Notify_UUIE;
class H225_Status_UUIE;
class H225_StatusInquiry_UUIE;

/// Base class to hold generic information associated with a signaling message
class SignalingMsg {
public:
	virtual ~SignalingMsg();

	/// @return	a cloned object of this or a derived class
	virtual SignalingMsg* Clone();
	
	/// @return	signaling message type (#Q931::MsgTypes enum#)
	unsigned GetTag() const;

	/// @return	signaling message type as a string
	PString GetTagName() const;

	/// @return	CRV associated with the signaling message
	unsigned GetCallReference() const;

	/// @return	a reference to the Q.931 message stored
	Q931& GetQ931() const { return *m_q931; }

	/// @return a pointer to the User-User IE, NULL if not present
	H225_H323_UserInformation* GetUUIE() { return m_uuie; }

	/// Get an address the message has been received on
	void GetLocalAddr(
		PIPSocket::Address &addr,
		WORD &port
		) const;
	void GetLocalAddr(
		PIPSocket::Address &addr
		) const;

	/// Get an address the message has been received from
	void GetPeerAddr(
		PIPSocket::Address &addr,
		WORD &port
		) const;
	void GetPeerAddr(
		PIPSocket::Address &addr
		) const;

	/// Set a flag to indicate that the Q.931 message has been modified
	void SetChanged() { m_changed = true; }

	/** Set a flag to indicate that the decoded H.225 UserInformation element
	    has been modified and the corresponding Q.931 IE should be recreated.
	*/
	void SetUUIEChanged() { m_changed = m_uuieChanged = true; }

	/// @return	true if the Q.931 message has been modified	
	bool IsChanged() const { return m_changed; }

	/** Encode the Q.931 message back into a binary form.
	
	    @return
	    True if the message has been encoded successfully.
	*/
	bool Encode(
		PBYTEArray &buffer /// buffer to hold the encoded message
		);
	bool Decode(
		const PBYTEArray & buffer /// buffer holding the encoded message
		);
			
	/// factory constructor for signaling messages
	static SignalingMsg* Create(
		Q931 *q931pdu, /// this pointer is not cloned and deleted by this class destructor
		H225_H323_UserInformation *uuie, /// decoded User-User IE
		const PIPSocket::Address &localAddr, /// an address the message has been received on
		WORD localPort, /// a port number the message has been received on
		const PIPSocket::Address &peerAddr, /// an address the message has been received from
		WORD peerPort /// a port number the message has been received from
		);

protected:
	SignalingMsg(
		Q931 *q931pdu, /// this pointer is not cloned and deleted by this class destructor
		H225_H323_UserInformation *uuie, /// decoded User-User IE
		const PIPSocket::Address &localAddr, /// an address the message has been received on
		WORD localPort, /// a port number the message has been received on
		const PIPSocket::Address &peerAddr, /// an address the message has been received from
		WORD peerPort /// a port number the message has been received from
		);
		
private:
	SignalingMsg();
	SignalingMsg(const SignalingMsg&);
public:
	SignalingMsg& operator=(const SignalingMsg&);

protected:
	Q931 *m_q931; /// whole Q.931 message
	H225_H323_UserInformation *m_uuie; /// User-User IE element of the Q.931 msg
	PIPSocket::Address m_localAddr; /// local IP address the msg arrived to
	WORD m_localPort; /// local port number the msg arrived to
	PIPSocket::Address m_peerAddr; /// remote IP address the msg arrived from
	WORD m_peerPort; /// remote port number the msg arrived from
	bool m_changed; /// indicate changes to the Q.931 message
	bool m_uuieChanged; /// indicate changes to the H.225 User Information element
};

/// Specialized template for a particular H.225.0 signaling message
template<class UUIE>
class H225SignalingMsg : public SignalingMsg {
public:
	/// Build a new SignalingMsg
	H225SignalingMsg(
		Q931 *q931pdu, /// this pointer is not cloned and deleted by this class destructor
		H225_H323_UserInformation *uuie, /// decoded User-User IE
		UUIE& /*uuieBody*/, /// decoded UUIE body
		const PIPSocket::Address &localAddr, /// an address the message has been received on
		WORD localPort, /// a port number the message has been received on
		const PIPSocket::Address &peerAddr, /// an address the message has been received from
		WORD peerPort /// a port number the message has been received from
		) : SignalingMsg(q931pdu, uuie, localAddr, localPort, peerAddr, peerPort),
			m_uuieBody(uuie->m_h323_uu_pdu.m_h323_message_body) {}

	UUIE& GetUUIEBody() const { return m_uuieBody; }

	virtual SignalingMsg* Clone()
	{
		H225_H323_UserInformation *uuieClone = (H225_H323_UserInformation*)(m_uuie->Clone());
		return new H225SignalingMsg<UUIE>(new Q931(*m_q931), uuieClone,
			(UUIE&)(uuieClone->m_h323_uu_pdu.m_h323_message_body),
			m_localAddr, m_localPort, m_peerAddr, m_peerPort
			);
	}
	
private:
	H225SignalingMsg();
	H225SignalingMsg(const H225SignalingMsg&);
	H225SignalingMsg& operator=(const H225SignalingMsg&);
	
protected:
	UUIE &m_uuieBody; /// H.225.0 UUIE structure associated with the message
};

typedef H225SignalingMsg<H225_Setup_UUIE> SetupMsg;
typedef H225SignalingMsg<H225_Alerting_UUIE> AlertingMsg;
typedef H225SignalingMsg<H225_CallProceeding_UUIE> CallProceedingMsg;
typedef H225SignalingMsg<H225_Connect_UUIE> ConnectMsg;
typedef H225SignalingMsg<H225_Progress_UUIE> ProgressMsg;
typedef H225SignalingMsg<H225_ReleaseComplete_UUIE> ReleaseCompleteMsg;
typedef H225SignalingMsg<H225_Information_UUIE> InformationMsg;
typedef H225SignalingMsg<H225_Facility_UUIE> FacilityMsg;
//typedef H225SignalingMsg<H225_Notify_UUIE> NotifyMsg;
//typedef H225SignalingMsg<H225_Status_UUIE> StatusMsg;
//typedef H225SignalingMsg<H225_StatusInquiry_UUIE> StatusInquiryMsg;

#endif // SIGMSG_H