From cde66129c8579445f3594d17a10c849142ae56d0 Mon Sep 17 00:00:00 2001
From: Quanah Gibson-Mount <quanah@openldap.org>
Date: Wed, 3 Sep 2008 20:03:43 +0000
Subject: [PATCH] - remove unneeded Copy-Constructor - allow to create Controls
 with no value

---
 contrib/ldapc++/src/LDAPControl.cpp | 25 ++++++++++++++-----------
 contrib/ldapc++/src/LDAPControl.h   | 20 +++++++++++---------
 2 files changed, 25 insertions(+), 20 deletions(-)

diff --git a/contrib/ldapc++/src/LDAPControl.cpp b/contrib/ldapc++/src/LDAPControl.cpp
index 2721309621..b995a35f69 100644
--- a/contrib/ldapc++/src/LDAPControl.cpp
+++ b/contrib/ldapc++/src/LDAPControl.cpp
@@ -10,13 +10,6 @@
 
 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;
 }
diff --git a/contrib/ldapc++/src/LDAPControl.h b/contrib/ldapc++/src/LDAPControl.h
index 5f4b9f3e31..002591429f 100644
--- a/contrib/ldapc++/src/LDAPControl.h
+++ b/contrib/ldapc++/src/LDAPControl.h
@@ -16,11 +16,6 @@
  */
 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
-- 
GitLab