1 // Copyright (C) 2001-2015 Federico Montesino <fedemp@altern.org>
2 //
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 2 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 //
17 // As a special exception, you may use this file as part of a free software
18 // library without restriction. Specifically, if other files instantiate
19 // templates or use macros or inline functions from this file, or you compile
20 // this file and link it with other files to produce an executable, this
21 // file does not by itself cause the resulting executable to be covered by
22 // the GNU General Public License. This exception does not however
23 // invalidate any other reasons why the executable file might be covered by
24 // the GNU General Public License.
25 //
26 // This exception applies only to the code released under the name GNU
27 // ccRTP. If you copy code from other releases into a copy of GNU
28 // ccRTP, as the General Public License permits, the exception does
29 // not apply to the code that you add in this way. To avoid misleading
30 // anyone as to the status of such modified files, you must delete
31 // this exception notice from them.
32 //
33 // If you write modifications of your own for GNU ccRTP, it is your choice
34 // whether to permit this exception to apply to your modifications.
35 // If you do not wish that, delete this exception notice.
36 //
37
46
47 NAMESPACE_COMMONCPP
48
49 static void
50 findusername(std::string &username);
51
52 #ifndef _MSWINDOWS_
53 static void
54 findusername(std::string &username)
55 {
56 // LOGNAME environment var has two advantages:
57 // 1) avoids problems of getlogin(3) and cuserid(3)
58 // 2) unlike getpwuid, takes into account user
59 // customization of the environment.
60 // Try both LOGNAME and USER env. var.
61 const char *user = Process::getEnv("LOGNAME");
62 if ( !user || !strcmp(user,"") )
63 user = Process::getEnv("USER");
64 if ( !user || !strcmp(user,"") )
65 username = Process::getUser();
66
67 if ( user )
68 username = user;
69 else
70 username = "";
71 }
72
73 #else
74
75 static void
76 findusername(std::string &username)
77 {
78 unsigned long len = 0;
79 if ( GetUserName(NULL,&len) && (len > 0) ) {
80 char *n = new char[len];
81 GetUserName(n,&len);
82 username = n;
83 delete [] n;
84 } else {
85 username = "";
86 }
87 }
88 #endif // #ifndef WIN32
89
90 void
92 {
95 }
96 }
97
98 const std::string&
100 {
103 } else
105 }
106
108 state(stateUnknown), SSRC(ssrc), participant(NULL),
109 networkAddress("0"), dataTransportPort(0), controlTransportPort(0)
110 {}
111
113 {
116 }
117
119 {
121 }
122
124 {}
125
127
129 {
130 // default application CNAME is automatically assigned.
132
133 return defApp;
134 }
135
138 firstPart(NULL), lastPart(NULL)
139 {
140 // guess CNAME, in the form of user@host_fqn
141 if ( cname.length() > 0 )
143 else
145 }
146
148 {
153 #ifdef CCXX_EXCEPTIONS
154 try {
155 #endif
156 delete p;
157 #ifdef CCXX_EXCEPTIONS
158 } catch (...) {}
159 #endif
160 }
162 #ifdef CCXX_EXCEPTIONS
163 try {
164 #endif
166 #ifdef CCXX_EXCEPTIONS
167 } catch (...) {}
168 #endif
169 }
170
171 // TODO: it should be implemented using the participant iterators
174 {
176 while ( (NULL != pl) &&
178 != cname) ) {
180 }
181 if ( pl ) {
183 } else {
184 return NULL;
185 }
186 }
187
188 void
190 {
194 else
197 }
198
199 void
201 {
202 if ( NULL == pl )
203 return;
208 delete pl;
209 }
210
211 void
213 {
214 // build string username@host_fqn
215 std::string username;
216 findusername(username);
217
218 // First create an InetHostAddress object, otherwise the
219 // object will be destructed and the hostname corrupted.
220 InetHostAddress iha;
221 const char *p = iha.getHostname();
222 // Returned hostname can be NULL
223 std::string hname;
224 if (p) hname = p;
225
227 username + "@" + hname);
228 }
229
230 END_NAMESPACE
231
void setPrev(ParticipantLink *l)
ParticipantLink * lastPart
const std::string & getItem(SDESItemType type) const
An RTP application, holding identifying RTCP SDES item values.
ParticipantLink * firstPart
List of participants, ordered from older to newer.
ParticipantLink * getNext()
Canonical end-point identifier.
ParticipantLink * getPrev()
Sources of synchronization and participants related clases.
Participant * getParticipant()
Declaration of ccRTP internal stuff.
std::string sdesItems[SDESItemTypeLast+1]
A class of objects representing remote participants (RTP applications) in a multimedia session...
void setItem(SDESItemType item, const std::string &val)
Participant(const std::string &cname)
Construct a new participant.
void findCNAME()
Find out the local CNAME as user@host and store it as part of the internal state of this class...
void setSDESItem(SDESItemType item, const std::string &val)
void addParticipant(Participant &part)
void removeParticipant(ParticipantLink *part)
RTPApplication(const std::string &cname)
Create a new RTP application.
Holds the SDES items and related information from a participant in an RTP application.
static const size_t defaultParticipantsNum
Hash table with sources of RTP and RTCP packets.
Participant ** participants
const Participant * getParticipant(const std::string &cname) const
RTPApplication & defaultApplication()
Get the RTPApplication object for the "default" application (the only one used by common applications...
void setNext(ParticipantLink *l)
SDESItemType
SDES items that may be carried in a Source DEScription RTCP packet.
const std::string & getSDESItem(SDESItemType type) const
Get the value of an SDES item.