mirror of
https://git.openldap.org/openldap/openldap.git
synced 2026-01-11 01:12:54 -05:00
* javascript * kernel * ldap * length * macros * maintained * manager * matching * maximum * mechanism * memory * method * mimic * minimum * modifiable * modifiers * modifying * multiple * necessary * normalized * objectclass * occurrence * occurring * offered * operation * original * overridden * parameter * permanent * preemptively * printable * protocol * provider * really * redistribution * referenced * refresh * regardless * registered * request * reserved * resource * response * sanity * separated * setconcurrency * should * specially * specifies * structure * structures * subordinates * substitution * succeed * successful * successfully * sudoers * sufficient * superiors * supported * synchronization * terminated * they're * through * traffic * transparent * unsigned * unsupported * version * absence * achieves * adamson * additional * address * against * appropriate * architecture * associated * async * attribute * authentication * authorized * auxiliary * available * begin * beginning * buffered * canonical * certificate * charray * check * class * compatibility * compilation * component * configurable * configuration * configure * conjunction * constraints * constructor * contained * containing * continued * control * convenience * correspond * credentials * cyrillic * database * definitions * deloldrdn * dereferencing * destroy * distinguish * documentation * emmanuel * enabled * entry * enumerated * everything * exhaustive * existence * existing * explicitly * extract * fallthru * fashion * february * finally * function * generically * groupname * happened * implementation * including * initialization * initializes * insensitive * instantiated * instantiation * integral * internal * iterate
116 lines
2.8 KiB
C++
116 lines
2.8 KiB
C++
// $OpenLDAP$
|
|
/*
|
|
* Copyright 2008-2017 The OpenLDAP Foundation, All Rights Reserved.
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
*/
|
|
|
|
#include "LdifWriter.h"
|
|
#include "StringList.h"
|
|
#include "LDAPAttribute.h"
|
|
#include "debug.h"
|
|
#include <sstream>
|
|
#include <stdexcept>
|
|
|
|
LdifWriter::LdifWriter( std::ostream& output, int version ) :
|
|
m_ldifstream(output), m_version(version), m_addSeparator(false)
|
|
{
|
|
if ( version )
|
|
{
|
|
if ( version == 1 )
|
|
{
|
|
m_ldifstream << "version: " << version << std::endl;
|
|
m_addSeparator = true;
|
|
} else {
|
|
std::ostringstream err;
|
|
err << "Unsupported LDIF Version";
|
|
throw( std::runtime_error(err.str()) );
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
void LdifWriter::writeRecord(const LDAPEntry& le)
|
|
{
|
|
std::ostringstream line;
|
|
|
|
if ( m_addSeparator )
|
|
{
|
|
m_ldifstream << std::endl;
|
|
} else {
|
|
m_addSeparator = true;
|
|
}
|
|
|
|
line << "dn: " << le.getDN();
|
|
this->breakline( line.str(), m_ldifstream );
|
|
|
|
const LDAPAttributeList *al = le.getAttributes();
|
|
LDAPAttributeList::const_iterator i = al->begin();
|
|
for ( ; i != al->end(); i++ )
|
|
{
|
|
StringList values = i->getValues();
|
|
StringList::const_iterator j = values.begin();
|
|
for( ; j != values.end(); j++)
|
|
{
|
|
// clear output stream
|
|
line.str("");
|
|
line << i->getName() << ": " << *j;
|
|
this->breakline( line.str(), m_ldifstream );
|
|
}
|
|
}
|
|
}
|
|
|
|
void LdifWriter::writeIncludeRecord( const std::string& target )
|
|
{
|
|
DEBUG(LDAP_DEBUG_TRACE, "writeIncludeRecord: " << target << std::endl);
|
|
std::string scheme = target.substr( 0, sizeof("file:")-1 );
|
|
|
|
if ( m_version == 1 )
|
|
{
|
|
std::ostringstream err;
|
|
err << "\"include\" not allowed in LDIF version 1.";
|
|
throw( std::runtime_error(err.str()) );
|
|
}
|
|
|
|
if ( m_addSeparator )
|
|
{
|
|
m_ldifstream << std::endl;
|
|
} else {
|
|
m_addSeparator = true;
|
|
}
|
|
|
|
m_ldifstream << "include: ";
|
|
if ( scheme != "file:" )
|
|
{
|
|
m_ldifstream << "file://";
|
|
}
|
|
|
|
m_ldifstream << target << std::endl;
|
|
}
|
|
|
|
void LdifWriter::breakline( const std::string &line, std::ostream &out )
|
|
{
|
|
std::string::size_type pos = 0;
|
|
std::string::size_type linelength = 76;
|
|
bool first = true;
|
|
|
|
if ( line.length() >= linelength )
|
|
{
|
|
while ( pos < line.length() )
|
|
{
|
|
if (! first )
|
|
{
|
|
out << " ";
|
|
}
|
|
out << line.substr(pos, linelength) << std::endl;
|
|
pos += linelength;
|
|
if ( first )
|
|
{
|
|
first = false;
|
|
linelength--; //account for the leading space
|
|
}
|
|
}
|
|
} else {
|
|
out << line << std::endl;
|
|
}
|
|
}
|
|
|