]> git.sur5r.net Git - openldap/commitdiff
- remove unneeded Copy-Constructor
authorRalf Haferkamp <ralf@openldap.org>
Wed, 27 Aug 2008 21:19:51 +0000 (21:19 +0000)
committerRalf Haferkamp <ralf@openldap.org>
Wed, 27 Aug 2008 21:19:51 +0000 (21:19 +0000)
- allow to create Controls with no value

contrib/ldapc++/src/LDAPControl.cpp
contrib/ldapc++/src/LDAPControl.h

index 27213096219c9083b46edc2ca9f184dceb180b12..b995a35f6918572459dc4e4f69f46bacef349ac3 100644 (file)
 
 using namespace std;
 
-LDAPCtrl::LDAPCtrl(const LDAPCtrl& c){
-    DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPCtrl::LDAPCtrl(&)" << endl);
-    m_oid=c.m_oid;
-    m_data=c.m_data;
-    m_isCritical=c.m_isCritical;
-}
-
 LDAPCtrl::LDAPCtrl(const char *oid, bool critical, const char* data,
         int length){
     DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPCtrl::LDAPCtrl()" << endl);
@@ -28,10 +21,10 @@ LDAPCtrl::LDAPCtrl(const char *oid, bool critical, const char* data,
         m_data.assign(data,length);
     }else{
         m_data=string();
+        m_noData=true;
     }
 }
 
-
 LDAPCtrl::LDAPCtrl(const string& oid, bool critical, const string& data){
     DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPCtrl::LDAPCtrl()" << endl);
     DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER,
@@ -39,6 +32,7 @@ LDAPCtrl::LDAPCtrl(const string& oid, bool critical, const string& data){
     m_oid=oid;
     m_isCritical=critical;
     m_data=data;
+    m_noData=false;
 }
 
 LDAPCtrl::LDAPCtrl(const LDAPControl* ctrl){
@@ -62,6 +56,10 @@ bool LDAPCtrl::isCritical()const {
     return m_isCritical;
 }
 
+bool LDAPCtrl::hasData() const{
+    return !m_noData;
+}
 string LDAPCtrl::getData() const {
     DEBUG(LDAP_DEBUG_TRACE,"LDAPCtrl::getData()" << endl);
     return m_data;
@@ -73,9 +71,14 @@ LDAPControl* LDAPCtrl::getControlStruct() const {
     ret->ldctl_oid= new char[m_oid.size() + 1];
     m_oid.copy(ret->ldctl_oid,string::npos);
     ret->ldctl_oid[m_oid.size()]=0;
-    ret->ldctl_value.bv_len=m_data.size();
-    ret->ldctl_value.bv_val= new char[m_data.size()];
-    m_data.copy(ret->ldctl_value.bv_val,string::npos);
+    if ( m_noData ) {
+        ret->ldctl_value.bv_len = 0;
+        ret->ldctl_value.bv_val = NULL;
+    } else {
+        ret->ldctl_value.bv_len=m_data.size();
+        ret->ldctl_value.bv_val= new char[m_data.size()];
+        m_data.copy(ret->ldctl_value.bv_val,string::npos);
+    }
     ret->ldctl_iscritical = ( m_isCritical ? 1:0);
     return ret;
 }
index 5f4b9f3e31d25bf347ae63d8f336576d1f169dc9..002591429f09cc4c3f7654d4e1fe08b2f128f592 100644 (file)
  */
 class LDAPCtrl{
     public :
-        /**
-         * Copy-constructor
-         */
-        LDAPCtrl(const LDAPCtrl& c);
-
         /**
          * Constructor.
          * @param oid:  The Object Identifier of the Control
@@ -29,7 +24,7 @@ class LDAPCtrl{
          * @param data: If there is data for the control, put it here.
          * @param length: The length of the data field
          */
-        LDAPCtrl(const char *oid, bool critical, const char *data=0, 
+        LDAPCtrl(const char *oid, bool critical=false, const char *data=0, 
                 int length=0);
 
         /**
@@ -39,8 +34,8 @@ class LDAPCtrl{
          *                  critical by the server.
          * @param data: If there is data for the control, put it here.
          */
-        LDAPCtrl(const std::string& oid, bool critical=false,
-                const std::string& data=std::string());
+        LDAPCtrl(const std::string& oid, bool critical,
+                 const std::string& data);
 
         /**
          * Creates a copy of the Control that "ctrl is pointing to
@@ -58,7 +53,13 @@ class LDAPCtrl{
         std::string getOID() const;
 
         /**
-         * @return The Data of the control as a std::string-Objekt
+         * @return true if there is no "Control Value" (there is a
+         * difference between no and an empty control value)
+         */
+        bool hasData() const;
+
+        /**
+         * @return The Data of the control as a std::string-Object
          */
         std::string getData() const;
 
@@ -80,6 +81,7 @@ class LDAPCtrl{
         std::string m_oid;
         std::string m_data;
         bool m_isCritical;
+        bool m_noData;
 };
 
 #endif //LDAP_CONTROL_H