2 * Copyright (c) 2000-2001,2003-2004,2006,2011-2012,2014 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
23 #include <security_cdsa_utilities/cssmdbname.h>
24 #include <security_cdsa_utilities/cssmbridge.h>
25 #include <security_utilities/utilities.h>
27 CssmNetAddress::CssmNetAddress(CSSM_DB_RECORDTYPE inAddressType
, const CssmData
&inAddress
)
29 AddressType
= inAddressType
;
30 Address
.Length
= inAddress
.Length
;
31 if (Address
.Length
> 0)
33 Address
.Data
= new uint8
[Address
.Length
];
34 memcpy (Address
.Data
, inAddress
.Data
, Address
.Length
);
40 CssmNetAddress::CssmNetAddress(const CSSM_NET_ADDRESS
&other
)
42 AddressType
= other
.AddressType
;
43 Address
.Length
= other
.Address
.Length
;
44 if (Address
.Length
> 0)
46 Address
.Data
= new uint8
[Address
.Length
];
47 memcpy (Address
.Data
, other
.Address
.Data
, Address
.Length
);
53 CssmNetAddress::~CssmNetAddress()
55 if (Address
.Length
> 0)
59 void DbName::CanonicalizeName()
63 char* s
= cached_realpath(mDbName
.c_str(), NULL
);
71 // the most likely situation here is that the file doesn't exist.
72 // we will pull the path apart and try again.
74 // search backward for the delimiter
75 ptrdiff_t n
= mDbName
.length() - 1;
77 // all subpaths must be tested, because there may be more than just
78 // the file name that doesn't exist.
81 while (n
> 0 && mDbName
[n
] != '/') // if the delimiter is 0, we would never
82 // have gotten here in the first place
89 string tmpPath
= mDbName
.substr(0, n
);
90 s
= cached_realpath(tmpPath
.c_str(), NULL
);
95 mCanonicalName
+= mDbName
.substr(n
, mDbName
.length() - n
);
103 // if we get here, all other paths have failed. Just reuse the original string.
104 mCanonicalName
= mDbName
;
111 DbName::DbName(const char *inDbName
, const CSSM_NET_ADDRESS
*inDbLocation
)
112 : mDbName(inDbName
? inDbName
: ""), mDbNameValid(inDbName
), mDbLocation(NULL
)
116 mDbLocation
= new CssmNetAddress(*inDbLocation
);
122 DbName::DbName(const DbName
&other
)
123 : mDbName(other
.mDbName
), mDbNameValid(other
.mDbNameValid
), mDbLocation(NULL
)
125 if (other
.mDbLocation
)
127 mDbLocation
= new CssmNetAddress(*other
.mDbLocation
);
134 DbName::operator =(const DbName
&other
)
136 mDbName
= other
.mDbName
;
137 mDbNameValid
= other
.mDbNameValid
;
138 if (other
.mDbLocation
)
140 mDbLocation
= new CssmNetAddress(*other
.mDbLocation
);