Back to index

nordugrid-arc-nox  1.1.0~rc6
LDAPQuery.h
Go to the documentation of this file.
00001 // -*- indent-tabs-mode: nil -*-
00002 
00003 #ifndef __ARC_LDAPQUERY_H__
00004 #define __ARC_LDAPQUERY_H__
00005 
00006 #include <list>
00007 #include <string>
00008 
00009 #ifdef WIN32
00010 #include <arc/win32.h> 
00011 #endif
00012 
00013 #ifdef USE_WIN32_LDAP_API
00014 #include <winldap.h>
00015 #else
00016 #include <ldap.h>
00017 #endif
00018 
00019 #include <arc/Logger.h>
00020 #include <arc/URL.h>
00021 
00022 #define SASLMECH "GSI-GSSAPI"
00023 
00027 typedef void (*ldap_callback)(const std::string& attr,
00028                               const std::string& value,
00029                               void *ref);
00030 
00031 namespace Arc {
00032 
00036   class LDAPQuery {
00037 
00038   public:
00043     LDAPQuery(const std::string& ldaphost,
00044               int ldapport,
00045               int timeout,
00046               bool anonymous = true,
00047               const std::string& usersn = "");
00048 
00052     ~LDAPQuery();
00053 
00057     bool Query(const std::string& base,
00058                const std::string& filter = "(objectclass=*)",
00059                const std::list<std::string>& attributes =
00060                  std::list<std::string>(),
00061                URL::Scope scope = URL::subtree);
00062 
00066     bool Result(ldap_callback callback,
00067                 void *ref);
00068 
00069   private:
00070     bool Connect();
00071     bool SetConnectionOptions(int version);
00072     bool HandleResult(ldap_callback callback, void *ref);
00073     void HandleSearchEntry(LDAPMessage *msg,
00074                            ldap_callback callback,
00075                            void *ref);
00076 
00077     std::string host;
00078     int port;
00079     bool anonymous;
00080     std::string usersn;
00081     int timeout;
00082 
00083     ldap *connection;
00084 #ifdef USE_WIN32_LDAP_API
00085     ULONG messageid;
00086 #else
00087     int messageid;
00088 #endif
00089 
00090     static Logger logger;
00091 
00092     friend int my_sasl_interact(ldap*, unsigned int, void*, void*);
00093   };
00094 
00095 } // end namespace
00096 
00097 #endif // __ARC_LDAPQUERY_H__