]> git.sur5r.net Git - openldap/blobdiff - contrib/ldapc++/src/LdifReader.cpp
Merge remote-tracking branch 'origin/mdb.master' into OPENLDAP_REL_ENG_2_5
[openldap] / contrib / ldapc++ / src / LdifReader.cpp
index dce0a632317fa58a85980baf756ca37e5df6cfe9..9db51e83411f93e70931a79792cfaad1eef911e6 100644 (file)
@@ -1,5 +1,6 @@
+// $OpenLDAP$
 /*
- * Copyright 2008, OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 2008-2013 The OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
  */
 
@@ -178,11 +179,12 @@ int LdifReader::readNextRecord( bool first )
 
 LDAPEntry LdifReader::getEntryRecord()
 {
+    std::list<stringpair>::const_iterator i = m_currentRecord.begin();
     if ( m_curRecType != LDAPMsg::SEARCH_ENTRY )
     {
-        // Error
+        throw( std::runtime_error( "The LDIF record: '" + i->second +
+                                   "' is not a valid LDAP Entry" ));
     }
-    std::list<stringpair>::const_iterator i = m_currentRecord.begin();
     LDAPEntry resEntry(i->second);
     i++;
     LDAPAttribute curAttr(i->first);
@@ -195,14 +197,14 @@ LDAPEntry LdifReader::getEntryRecord()
         }
         else
         {
-            if ( curAl->getAttributeByName( i->first ) )
+            const LDAPAttribute* existing = curAl->getAttributeByName( i->first );
+            if ( existing )
             {
-                // Attribute exists already -> Syntax Error
-                std::ostringstream err;
-                err << "Line " << this->m_lineNumber 
-                    << ": Attribute \"" << i->first 
-                    << "\" specified multiple times.";
-                throw( std::runtime_error(err.str()) );
+                // Attribute exists already (handle gracefully)
+                curAl->addAttribute( curAttr );
+                curAttr = LDAPAttribute( *existing );
+                curAttr.addValue(i->second);
+                curAl->delAttribute( i->first );
             }
             else
             {