Added IsSupportingRTP function to simplify detecting when STUN supports RTP
[pwlib.git] / src / ptclib / pils.cxx
blob9bfa0955cefb6d03ca5c235e3b56f1c3c89254f3
1 /*
2 * pils.cxx
4 * Microsoft Internet Location Server Protocol interface class.
6 * Portable Windows Library
8 * Copyright (c) 1993-2003 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 Portable Windows Library.
22 * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
24 * Contributor(s): ______________________________________.
26 * $Log$
27 * Revision 1.5 2003/06/05 23:19:52 rjongbloed
28 * Changed LDAP version to be compatible with ILS servers.
30 * Revision 1.4 2003/04/11 00:07:56 robertj
31 * More for Microsoft IP address specification wierdness (registration side).
33 * Revision 1.3 2003/04/07 13:05:20 robertj
34 * Workaround for Microsoft IP address specification wierdness.
36 * Revision 1.2 2003/03/31 12:18:43 robertj
37 * Fixed pragma implementation
39 * Revision 1.1 2003/03/31 03:35:20 robertj
40 * Major addition of LDAP functionality.
41 * Added ILS specialisation of LDAP.
45 #ifdef __GNUC__
46 #pragma implementation "pils.h"
47 #endif
49 #include <ptlib.h>
51 #include <ptclib/pils.h>
54 #if P_LDAP
56 // Microsoft in their infinite wisdom save the IP address as an little endian
57 // integer from a 32 bit integer that was in network byte order (big endian)
58 // which causes immense confusion. Reading into a PIPSocket::Address does not
59 // work as it assumes that any integer forms would be in host order.
60 istream & operator>>(istream & s, PILSSession::MSIPAddress & a)
62 DWORD u;
63 s >> u;
65 #if PBYTE_ORDER==PLITTLE_ENDIAN
66 a = u;
67 #else
68 a = PIPSocket::Address((BYTE)(u>>24),(BYTE)(u>>16),(BYTE)(u>>8),(BYTE)u);
69 #endif
71 return s;
75 ostream & operator<<(ostream & s, PILSSession::MSIPAddress & a)
77 #if PBYTE_ORDER==PLITTLE_ENDIAN
78 DWORD u = a;
79 #else
80 DWORD u = (a.Byte1()<<24)|(a.Byte2()<<16)|(a.Byte3()<<8)|a.Byte4();
81 #endif
83 return s << u;
87 ///////////////////////////////////////////////////////////////////////////////
89 PILSSession::PILSSession()
90 : PLDAPSession("objectClass=RTPerson")
92 protocolVersion = 2;
96 BOOL PILSSession::AddPerson(const RTPerson & person)
98 return Add(person.GetDN(), person);
102 BOOL PILSSession::ModifyPerson(const RTPerson & person)
104 return Modify(person.GetDN(), person);
108 BOOL PILSSession::DeletePerson(const RTPerson & person)
110 return Delete(person.GetDN());
114 BOOL PILSSession::SearchPerson(const PString & canonicalName, RTPerson & person)
116 SearchContext context;
117 if (!Search(context, "cn="+canonicalName))
118 return FALSE;
120 if (!GetSearchResult(context, person))
121 return FALSE;
123 // Return FALSE if there is more than one match
124 return !GetNextSearchResult(context);
128 PList<PILSSession::RTPerson> PILSSession::SearchPeople(const PString & filter)
130 PList<RTPerson> persons;
132 SearchContext context;
133 if (Search(context, filter)) {
134 do {
135 RTPerson * person = new RTPerson;
136 if (GetSearchResult(context, *person))
137 persons.Append(person);
138 else
139 delete person;
140 } while (GetNextSearchResult(context));
143 return persons;
147 PString PILSSession::RTPerson::GetDN() const
149 PStringStream dn;
151 if (!c)
152 dn << "c=" << c << ", ";
154 if (!o)
155 dn << "o=" << o << ", ";
157 dn << "cn=" + cn + ", objectClass=" + objectClass;
159 return dn;
163 #endif // P_LDAP
166 // End of file ////////////////////////////////////////////////////////////////