#ifndef _DBNAME_H_
#define _DBNAME_H_ 1
#include <security_utilities/utilities.h>
#include <security_cdsa_utilities/walkers.h>
#include <Security/cssmtype.h>
#include <string>
#ifdef _CPP_DBNAME
# pragma export on
#endif
using namespace std;
namespace Security
{
class CssmNetAddress : public PodWrapper<CssmNetAddress, CSSM_NET_ADDRESS>
{
public:
CssmNetAddress(CSSM_DB_RECORDTYPE inAddressType, const CssmData &inAddress);
CssmNetAddress(const CSSM_NET_ADDRESS &other);
~CssmNetAddress();
CSSM_DB_RECORDTYPE addressType() const { return AddressType; }
const CssmData &address() const { return CssmData::overlay(Address); }
bool operator <(const CssmNetAddress &other) const
{
return AddressType != other.AddressType ? AddressType < other.AddressType : address() < other.address();
}
};
class DbName
{
public:
DbName (const char *inDbName = NULL, const CSSM_NET_ADDRESS *inDbLocation = NULL);
DbName(const DbName &other);
DbName &operator =(const DbName &other);
~DbName ();
const char *dbName() const { return mDbNameValid ? mDbName.c_str() : NULL; }
const char *canonicalName() const { return mDbNameValid ? mCanonicalName.c_str() : NULL; }
const CssmNetAddress *dbLocation() const { return mDbLocation; }
bool operator <(const DbName &other) const
{
if (!mDbNameValid || !other.mDbNameValid)
return mDbNameValid < other.mDbNameValid;
if (canonicalName() != other.canonicalName())
return mDbName < other.mDbName;
if (mDbLocation == other.mDbLocation)
return false;
if (mDbLocation == nil || other.mDbLocation == nil)
return mDbLocation < other.mDbLocation;
return *mDbLocation < *other.mDbLocation;
}
bool operator ==(const DbName &other) const
{ return (!(*this < other)) && (!(other < *this)); }
bool operator !=(const DbName &other) const
{ return *this < other || other < *this; }
private:
void CanonicalizeName();
string mDbName;
string mCanonicalName;
bool mDbNameValid;
CssmNetAddress *mDbLocation;
};
namespace DataWalkers
{
template<class Action>
CssmNetAddress *walk(Action &operate, CssmNetAddress * &addr)
{
operate(addr);
walk(operate, addr->Address);
return addr;
}
}
}
#ifdef _CPP_DBNAME
# pragma export off
#endif
#endif //_DBNAME_H_