3 /// Storage, parser, and builder classes for ldif operations.
7 Copyright (C) 2010-2011, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
26 LdifStore::LdifStore(const std::string
&filename
)
27 : m_ifs( new std::ifstream(filename
.c_str()) )
29 , m_os(*m_ofs
) // yes, this is a reference to a null ptr
30 // but will never be used (see below as well)
31 , m_end_of_file(false)
36 LdifStore::LdifStore(std::istream
&is
)
39 , m_end_of_file(false)
44 // output constructors
45 LdifStore::LdifStore(const std::string
&filename
,
46 const std::string
&baseDN
,
47 const std::string
&dnattr
)
48 : m_ofs( new std::ofstream(filename
.c_str()) )
51 , m_end_of_file(false)
54 m_ldif
.SetDNAttr(dnattr
);
57 LdifStore::LdifStore(std::ostream
&os
,
58 const std::string
&baseDN
,
59 const std::string
&dnattr
)
62 , m_end_of_file(false)
65 m_ldif
.SetDNAttr(dnattr
);
69 void LdifStore::operator() (const Contact
&rec
)
71 m_ldif
.DumpLdif(m_os
, rec
);
75 bool LdifStore::operator() (Contact
&rec
, const Barry::Builder
&builder
)
80 // there may be LDIF records in the input that generate
81 // invalid Contact records, but valid Contact records
82 // may come after.. so keep processing until end of stream
84 if( m_ldif
.ReadLdif(m_is
, rec
) )