Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

more/net/ldap.h

Go to the documentation of this file.
00001 //  Copyright (C) 2002  Petter Urkedal (petter.urkedal@matfys.lth.se)
00002 //
00003 //  This file is free software; you can redistribute it and/or modify
00004 //  it under the terms of the GNU General Public License as published by
00005 //  the Free Software Foundation; either version 2 of the License, or
00006 //  (at your option) any later version.
00007 //
00008 //  This file is distributed in the hope that it will be useful,
00009 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 //  GNU General Public License for more details.
00012 //
00013 //  You should have received a copy of the GNU General Public License
00014 //  along with this program; if not, write to the Free Software
00015 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00016 //
00017 //  As a special exception, you may use this file as part of a free
00018 //  software library without restriction.  Specifically, if other files
00019 //  instantiate templates or use macros or inline functions from this
00020 //  file, or you compile this file and link it with other files to
00021 //  produce an executable, this file does not by itself cause the
00022 //  resulting executable to be covered by the GNU General Public
00023 //  License.  This exception does not however invalidate any other
00024 //  reasons why the executable file might be covered by the GNU General
00025 //  Public License.
00026 //
00027 //  $Id: ldap.h,v 1.2 2002/06/02 21:39:53 petter_urkedal Exp $
00028 
00029 #ifndef MORE_NET_LDAP_H
00030 #define MORE_NET_LDAP_H
00031 
00032 #include <more/gen/utility.h>
00033 #include <more/bits/experimental.h> // !! and unfinished !!
00034 #include <more/io/fwd.h>
00035 #include <map>
00036 
00037 namespace more {
00038 namespace net {
00039 
00040   class ldap_connection;
00041 
00042   enum ldap_dn_syntax {
00043       ldap_dn_syntax_none,
00044       ldap_dn_syntax_rfc,
00045       ldap_dn_syntax_osf
00046   };
00047 
00048   struct ldap_dn
00049   {
00050   private:
00051       struct content : gen::handle_data
00052       {
00053           ~content()
00054           {
00055               if (m_cxt && m_cxt->unref() == 0)
00056                   delete m_cxt;
00057           }
00058 
00059           std::string m_rdn;
00060           content const* m_cxt;
00061       };
00062 
00063       explicit ldap_dn(content const* cxt)
00064           : m_data(cxt) {}
00065 
00066   public:
00067       ldap_dn(std::string dn,
00068               ldap_dn_syntax stx = ldap_dn_syntax_none)
00069       {
00070           m_data.set_data(init(0, dn, stx));
00071       }
00072 
00073       ldap_dn(ldap_dn const& cxt, std::string const& rdn,
00074               ldap_dn_syntax stx = ldap_dn_syntax_none)
00075       {
00076           m_data.set_data(init(cxt.m_data.data_ref(), rdn, stx));
00077       }
00078 
00079       ~ldap_dn();
00080 
00081       std::string const& rdn() const { return m_data.data()->m_rdn; }
00082 
00083       bool is_single_rdn() const { return m_data.data()->m_cxt == 0; }
00084 
00085       ldap_dn context() const
00086       {
00087 #ifndef MORE_NDEBUG
00088           if (m_data.data()->m_cxt == 0)
00089               throw std::logic_error("more::net::ldap_dn::context: "
00090                                      "Toplevel DN has no context.");
00091 #endif
00092           return ldap_dn(m_data.data()->m_cxt);
00093       }
00094 
00095       bool operator==(ldap_dn const& rhs) const
00096       {
00097           return m_data.data() == rhs.m_data.data();
00098       }
00099 
00100   private:
00101       static content*
00102       init(content const* cxt,
00103            std::string const& rdn, ldap_dn_syntax stx);
00104 
00105       gen::handle<content> m_data;
00106   };
00107 
00108   std::ostream& operator<<(std::ostream& os, ldap_dn const& dn);
00109 
00110   struct ldap_entry_ref
00111   {
00112   private:
00113       typedef std::multimap<std::string, std::string> multimap_type;
00114 
00115       struct content : gen::handle_data
00116       {
00117           ldap_connection*      m_connection;
00118           ldap_dn               m_current_dn;
00119           multimap_type         m_current_attrs;
00120           ldap_dn               m_update_dn;
00121           multimap_type         m_update_attrs;
00122       };
00123 
00124       ldap_entry_ref(content* c)
00125           : m_data(c) {}
00126 
00127   public:
00128       ldap_entry_ref() {}
00129 
00130       ldap_dn const& dn() const { return m_data.datachk()->m_current_dn; }
00131 
00132       bool is_changed() const
00133       {
00134           return m_data.datachk()->m_current_dn == m_data.data()->m_update_dn
00135               && m_data.data()->m_current_attrs
00136               == m_data.data()->m_update_attrs;
00137       }
00138 
00139       void commit() const;
00140 
00141       /** Full comparison of DN and content. */
00142 //       bool operator==(ldap_entry_ref const& rhs) const
00143 //       {
00144 //        return m_dn == rhs.m_dn
00145 //            && *static_cast<std::multimap<std::string, std::string>*>(this)
00146 //            == rhs;
00147 //       }
00148 
00149     private:
00150       gen::handle<content> m_data;
00151       friend class ldap_connection;
00152   };
00153 
00154   /** \class ldap_connection ldap.h more/net/ldap.h
00155    **
00156    ** A connection to an LDAP server.  */
00157   struct ldap_connection : gen::noncopyable
00158   {
00159       enum search_scope_type
00160       {
00161           search_scope_base,
00162           search_scope_one,
00163           search_scope_sub
00164       };
00165 
00166       ldap_connection();
00167 
00168       /** Include some common LDAP options in the \a cl command-line
00169        ** parser.  \c cl.parse(...) must be called before \c bind(). */
00170       void declare_options(io::cmdline& cl);
00171 
00172       void bind();
00173 
00174       ldap_entry_ref const& checkout(ldap_dn const& dn);
00175 
00176       template<typename OutputIterator>
00177       void search(std::string const& base, search_scope_type scope,
00178                   std::string const& filter, OutputIterator it_out);
00179       // XX skipped args char* attrs[], bool attrs_only.
00180 
00181     private:
00182       gen::degenerate_set<ldap_entry_ref> m_cache;
00183   };
00184 
00185 }} // more::net
00186 
00187 #endif

Generated on Sat Sep 7 19:11:19 2002 for more with Doxygen 1.2.13.1. Doxygen 1.2.13.1 is written and copyright 1997-2002 by Dimitri van Heesch.