1 // $Id: Configuration.cpp 80826 2008-03-04 14:51:23Z wotte $
2 #include "ace/Configuration.h"
3 #include "ace/Auto_Ptr.h"
4 #include "ace/SString.h"
5 #include "ace/OS_NS_string.h"
6 #include "ace/OS_NS_strings.h"
8 // Can remove this when import_config and export_config are removed from
9 // ACE_Configuration. They're deprecated at ACE 5.2.
10 #include "ace/Configuration_Import_Export.h"
12 #if !defined (ACE_LACKS_ACCESS)
13 # include "ace/OS_NS_unistd.h"
14 #endif /* ACE_LACKS_ACCESS */
16 #if !defined (__ACE_INLINE__)
17 #include "ace/Configuration.inl"
18 #endif /* __ACE_INLINE__ */
20 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
22 ACE_Section_Key_Internal::ACE_Section_Key_Internal (void)
27 ACE_Section_Key_Internal::~ACE_Section_Key_Internal (void)
32 ACE_Section_Key_Internal::add_ref (void)
39 ACE_Section_Key_Internal::dec_ref (void)
46 ACE_Configuration_Section_Key::ACE_Configuration_Section_Key (void)
51 ACE_Configuration_Section_Key::~ACE_Configuration_Section_Key (void)
57 ACE_Configuration_Section_Key::ACE_Configuration_Section_Key (ACE_Section_Key_Internal
* key
)
64 ACE_Configuration_Section_Key::ACE_Configuration_Section_Key (const ACE_Configuration_Section_Key
& rhs
)
71 ACE_Configuration_Section_Key
&
72 ACE_Configuration_Section_Key::operator= (const ACE_Configuration_Section_Key
& rhs
)
87 //////////////////////////////////////////////////////////////////////////////
89 ACE_TCHAR
ACE_Configuration::NULL_String_
= '\0';
91 ACE_Configuration::ACE_Configuration (void)
96 ACE_Configuration::~ACE_Configuration (void)
100 ACE_Section_Key_Internal
*
101 ACE_Configuration::get_internal_key (const ACE_Configuration_Section_Key
& key
)
107 ACE_Configuration::expand_path (const ACE_Configuration_Section_Key
& key
,
108 const ACE_TString
& path_in
,
109 ACE_Configuration_Section_Key
& key_out
,
112 // Make a copy of key
113 ACE_Configuration_Section_Key current_section
= key
;
114 ACE_Auto_Basic_Array_Ptr
<ACE_TCHAR
> pData (path_in
.rep ());
115 ACE_Tokenizer
parser (pData
.get ());
116 parser
.delimiter_replace ('\\', '\0');
117 parser
.delimiter_replace ('/', '\0');
119 for (ACE_TCHAR
*temp
= parser
.next ();
121 temp
= parser
.next ())
124 if (open_section (current_section
,
130 current_section
= key_out
;
137 // import_config and export_config are here for backward compatibility,
138 // and have been deprecated.
140 ACE_Configuration::export_config (const ACE_TCHAR
* filename
)
142 ACE_Registry_ImpExp
exporter (*this);
143 return exporter
.export_config (filename
);
147 ACE_Configuration::import_config (const ACE_TCHAR
* filename
)
149 ACE_Registry_ImpExp
importer (*this);
150 return importer
.import_config (filename
);
154 ACE_Configuration::validate_name (const ACE_TCHAR
* name
, int allow_path
)
156 // Invalid character set
157 const ACE_TCHAR
* reject
=
158 allow_path
? ACE_TEXT ("][") : ACE_TEXT ("\\][");
160 // Position of the first invalid character or terminating null.
161 size_t const pos
= ACE_OS::strcspn (name
, reject
);
163 // Check if it is an invalid character.
164 if (name
[pos
] != ACE_TEXT ('\0'))
170 // The first character can never be a path separator.
171 if (name
[0] == ACE_TEXT ('\\'))
178 if (pos
== 0 || pos
> 255)
180 errno
= ENAMETOOLONG
;
188 ACE_Configuration::validate_value_name (const ACE_TCHAR
* name
)
190 if (name
== 0 || *name
== this->NULL_String_
)
193 return this->validate_name (name
);
196 const ACE_Configuration_Section_Key
&
197 ACE_Configuration::root_section (void) const
203 * Determine if the contents of this object is the same as the
204 * contents of the object on the right hand side.
205 * Returns 1 (True) if they are equal and 0 (False) if they are not equal
208 ACE_Configuration::operator== (const ACE_Configuration
& rhs
) const
211 int sectionIndex
= 0;
212 ACE_TString sectionName
;
213 ACE_Configuration
*nonconst_this
= const_cast<ACE_Configuration
*> (this);
214 ACE_Configuration
&nonconst_rhs
= const_cast<ACE_Configuration
&> (rhs
);
216 const ACE_Configuration_Section_Key
& rhsRoot
= rhs
.root_section ();
217 ACE_Configuration_Section_Key rhsSection
;
218 ACE_Configuration_Section_Key thisSection
;
220 // loop through each section in this object
221 while ((rc
) && (nonconst_this
->enumerate_sections (this->root_
,
225 // find that section in the rhs object
226 if (nonconst_rhs
.open_section (rhsRoot
,
227 sectionName
.c_str (),
231 // If the rhs object does not contain the section then we are
235 else if (nonconst_this
->open_section (this->root_
,
236 sectionName
.c_str (),
240 // if there is some error opening the section in this object
245 // Well the sections match
247 ACE_TString valueName
;
251 // Enumerate each value in this section
252 while ((rc
) && nonconst_this
->enumerate_values (thisSection
,
257 // look for the same value in the rhs section
258 if (nonconst_rhs
.find_value (rhsSection
,
262 // We're not equal if the same value cannot
263 // be found in the rhs object.
266 else if (valueType
!= rhsType
)
268 // we're not equal if the types do not match.
273 // finally compare values.
274 if (valueType
== STRING
)
276 ACE_TString thisString
, rhsString
;
277 if (nonconst_this
->get_string_value (thisSection
,
281 // we're not equal if we cannot get this string
284 else if (nonconst_rhs
.get_string_value (
289 // we're not equal if we cannot get rhs string
292 rc
= (thisString
== rhsString
);
294 else if (valueType
== INTEGER
)
298 if (nonconst_this
->get_integer_value (
303 // we're not equal if we cannot get this int
306 else if (nonconst_rhs
.get_integer_value (
311 // we're not equal if we cannot get rhs int
314 rc
= (thisInt
== rhsInt
);
316 else if (valueType
== BINARY
)
320 size_t thisLength
= 0;
321 size_t rhsLength
= 0;
322 if (nonconst_this
->get_binary_value (thisSection
,
327 // we're not equal if we cannot get this data
330 else if (nonconst_rhs
.get_binary_value (
336 // we're not equal if we cannot get this data
340 rc
= (thisLength
== rhsLength
);
341 // are the length's the same?
345 unsigned char* thisCharData
=
346 (unsigned char*)thisData
;
347 unsigned char* rhsCharData
= (unsigned char*)rhsData
;
348 // yes, then check each element
349 for (size_t count
= 0;
350 (rc
) && (count
< thisLength
);
353 rc
= (* (thisCharData
+ count
) == * (rhsCharData
+ count
));
356 delete [] thisCharData
;
357 delete [] rhsCharData
;
358 }// end if the length's match
360 // We should never have valueTypes of INVALID, therefore
361 // we're not comparing them. How would we since we have
362 // no get operation for invalid types.
363 // So, if we have them, we guess they are equal.
365 }// end else if values match.
369 }// end value while loop
371 // look in the rhs for values not in this
373 while ((rc
) && (nonconst_rhs
.enumerate_values (rhsSection
,
378 // look for the same value in this section
379 if (nonconst_this
->find_value (thisSection
,
383 // We're not equal if the same value cannot
384 // be found in the rhs object.
388 }// end while for rhs values not in this.
390 }// end else if sections match.
394 }// end section while loop
396 // Finally, make sure that there are no sections in rhs that do not
400 && (nonconst_rhs
.enumerate_sections (rhsRoot
,
404 // find the section in this
405 if (nonconst_this
->open_section (this->root_
,
406 sectionName
.c_str (),
410 // if there is some error opening the section in this object
413 else if (nonconst_rhs
.open_section (rhsRoot
,
414 sectionName
.c_str (),
418 // If the rhs object does not contain the section then we
428 ACE_Configuration::operator!= (const ACE_Configuration
& rhs
) const
430 return !(*this == rhs
);
433 //////////////////////////////////////////////////////////////////////////////
435 #if defined (ACE_WIN32) && !defined (ACE_LACKS_WIN32_REGISTRY)
437 static const int ACE_DEFAULT_BUFSIZE
= 256;
439 static const ACE_TCHAR
*temp_name (const ACE_TCHAR
*name
)
441 if (name
&& *name
== ACE_Configuration::NULL_String_
)
446 ACE_Section_Key_Win32::ACE_Section_Key_Win32 (HKEY hKey
)
451 ACE_Section_Key_Win32::~ACE_Section_Key_Win32 (void)
453 ::RegCloseKey (hKey_
);
456 //////////////////////////////////////////////////////////////////////////////
459 ACE_Configuration_Win32Registry::operator== (const ACE_Configuration_Win32Registry
&rhs
) const
461 ACE_UNUSED_ARG (rhs
);
466 ACE_Configuration_Win32Registry::operator!= (const ACE_Configuration_Win32Registry
&rhs
) const
468 ACE_UNUSED_ARG (rhs
);
472 ACE_Configuration_Win32Registry::ACE_Configuration_Win32Registry (HKEY hKey
)
474 ACE_Section_Key_Win32
*temp
= 0;
476 ACE_NEW (temp
, ACE_Section_Key_Win32 (hKey
));
478 root_
= ACE_Configuration_Section_Key (temp
);
482 ACE_Configuration_Win32Registry::~ACE_Configuration_Win32Registry (void)
487 ACE_Configuration_Win32Registry::open_section (const ACE_Configuration_Section_Key
& base
,
488 const ACE_TCHAR
* sub_section
,
490 ACE_Configuration_Section_Key
& result
)
492 if (validate_name (sub_section
, 1))
496 if (load_key (base
, base_key
))
501 if ((errnum
= ACE_TEXT_RegOpenKeyEx (base_key
,
505 &result_key
)) != ERROR_SUCCESS
)
513 if ((errnum
= ACE_TEXT_RegCreateKeyEx (base_key
,
517 REG_OPTION_NON_VOLATILE
,
521 #if defined (__MINGW32__)
525 #endif /* __MINGW32__ */
533 ACE_Section_Key_Win32
*temp
;
535 ACE_NEW_RETURN (temp
, ACE_Section_Key_Win32 (result_key
), -1);
536 result
= ACE_Configuration_Section_Key (temp
);
541 ACE_Configuration_Win32Registry::remove_section (const ACE_Configuration_Section_Key
& key
,
542 const ACE_TCHAR
* sub_section
,
545 if (validate_name (sub_section
))
549 if (load_key (key
, base_key
))
554 ACE_Configuration_Section_Key section
;
555 if (open_section (key
, sub_section
, 0, section
))
559 if (load_key (section
, sub_key
))
562 ACE_TCHAR name_buffer
[ACE_DEFAULT_BUFSIZE
];
563 DWORD buffer_size
= ACE_DEFAULT_BUFSIZE
;
564 // Note we don't increment the index because the
565 // enumeration becomes invalid if we change the
566 // subkey, which we do when we delete it. By leaving
567 // it 0, we always delete the top entry
568 while (ACE_TEXT_RegEnumKeyEx (sub_key
,
577 remove_section (section
, name_buffer
, 1);
578 buffer_size
= ACE_DEFAULT_BUFSIZE
;
583 errnum
= ACE_TEXT_RegDeleteKey (base_key
, sub_section
);
584 if (errnum
!= ERROR_SUCCESS
)
594 ACE_Configuration_Win32Registry::enumerate_values (const ACE_Configuration_Section_Key
& key
,
600 if (load_key (key
, base_key
))
603 ACE_TCHAR name_buffer
[ACE_DEFAULT_BUFSIZE
];
604 DWORD buffer_size
= ACE_DEFAULT_BUFSIZE
;
607 int rc
= ACE_TEXT_RegEnumValue (base_key
,
615 if (rc
== ERROR_NO_MORE_ITEMS
)
617 else if (rc
!= ERROR_SUCCESS
)
644 ACE_Configuration_Win32Registry::enumerate_sections (const ACE_Configuration_Section_Key
& key
,
649 if (load_key (key
, base_key
))
652 ACE_TCHAR name_buffer
[ACE_DEFAULT_BUFSIZE
];
653 DWORD buffer_size
= ACE_DEFAULT_BUFSIZE
;
654 int rc
= ACE_TEXT_RegEnumKeyEx (base_key
,
662 if (rc
== ERROR_NO_MORE_ITEMS
)
664 else if (rc
!= ERROR_MORE_DATA
&& rc
!= ERROR_SUCCESS
)
676 ACE_Configuration_Win32Registry::set_string_value (const ACE_Configuration_Section_Key
& key
,
677 const ACE_TCHAR
* name
,
678 const ACE_TString
& value
)
680 const ACE_TCHAR
*t_name
= temp_name (name
);
681 if (validate_value_name (t_name
))
685 if (load_key (key
, base_key
))
689 DWORD len
= static_cast<DWORD
> (value
.length () + 1);
690 len
*= sizeof (ACE_TCHAR
);
691 if ((errnum
= ACE_TEXT_RegSetValueEx (base_key
,
695 (BYTE
*) value
.fast_rep (),
707 ACE_Configuration_Win32Registry::set_integer_value (const ACE_Configuration_Section_Key
& key
,
708 const ACE_TCHAR
* name
,
711 const ACE_TCHAR
*t_name
= temp_name (name
);
712 if (validate_value_name (t_name
))
716 if (load_key (key
, base_key
))
720 if ((errnum
= ACE_TEXT_RegSetValueEx (base_key
,
725 sizeof (value
))) != ERROR_SUCCESS
)
735 ACE_Configuration_Win32Registry::set_binary_value (const ACE_Configuration_Section_Key
& key
,
736 const ACE_TCHAR
* name
,
740 const ACE_TCHAR
*t_name
= temp_name (name
);
741 if (validate_value_name (t_name
))
745 if (load_key (key
, base_key
))
749 if ((errnum
= ACE_TEXT_RegSetValueEx (base_key
,
754 static_cast<DWORD
> (length
)))
765 ACE_Configuration_Win32Registry::get_string_value (const ACE_Configuration_Section_Key
& key
,
766 const ACE_TCHAR
* name
,
769 const ACE_TCHAR
*t_name
= temp_name (name
);
770 if (validate_value_name (t_name
))
774 if (load_key (key
, base_key
))
777 // Get the size of the binary data from windows
779 DWORD buffer_length
= 0;
781 if ((errnum
= ACE_TEXT_RegQueryValueEx (base_key
,
786 &buffer_length
)) != ERROR_SUCCESS
)
794 errno
= ERROR_INVALID_DATATYPE
;
799 ACE_NEW_RETURN (temp
,
800 ACE_TCHAR
[buffer_length
],
803 ACE_Auto_Basic_Array_Ptr
<ACE_TCHAR
> buffer (temp
);
805 if ((errnum
= ACE_TEXT_RegQueryValueEx (base_key
,
809 (BYTE
*) buffer
.get (),
810 &buffer_length
)) != ERROR_SUCCESS
)
816 value
= buffer
.get ();
821 ACE_Configuration_Win32Registry::get_integer_value (const ACE_Configuration_Section_Key
& key
,
822 const ACE_TCHAR
* name
,
825 const ACE_TCHAR
*t_name
= temp_name (name
);
826 if (validate_value_name (t_name
))
830 if (load_key (key
, base_key
))
834 DWORD length
= sizeof (value
);
836 if ((errnum
= ACE_TEXT_RegQueryValueEx (base_key
,
841 &length
)) != ERROR_SUCCESS
)
847 if (type
!= REG_DWORD
)
849 errno
= ERROR_INVALID_DATATYPE
;
857 ACE_Configuration_Win32Registry::get_binary_value (
858 const ACE_Configuration_Section_Key
&key
,
859 const ACE_TCHAR
*name
,
863 const ACE_TCHAR
*t_name
= temp_name (name
);
864 if (validate_value_name (t_name
))
868 if (load_key (key
, base_key
))
871 // Get the size of the binary data from windows
873 DWORD buffer_length
= 0;
875 if ((errnum
= ACE_TEXT_RegQueryValueEx (base_key
,
880 &buffer_length
)) != ERROR_SUCCESS
)
886 if (type
!= REG_BINARY
)
888 errno
= ERROR_INVALID_DATATYPE
;
892 length
= buffer_length
;
895 ACE_NEW_RETURN (the_data
, BYTE
[length
], -1);
896 ACE_Auto_Basic_Array_Ptr
<BYTE
> safe_data (the_data
);
898 if ((errnum
= ACE_TEXT_RegQueryValueEx (base_key
,
903 &buffer_length
)) != ERROR_SUCCESS
)
910 data
= safe_data
.release ();
916 ACE_Configuration_Win32Registry::find_value (const ACE_Configuration_Section_Key
& key
,
917 const ACE_TCHAR
* name
,
920 const ACE_TCHAR
*t_name
= temp_name (name
);
921 if (validate_value_name (t_name
))
925 if (load_key (key
, base_key
))
928 DWORD buffer_length
=0;
930 int result
=ACE_TEXT_RegQueryValueEx (base_key
,
936 if (result
!= ERROR_SUCCESS
)
954 return -1; // unknown type
961 ACE_Configuration_Win32Registry::remove_value (const ACE_Configuration_Section_Key
& key
,
962 const ACE_TCHAR
* name
)
964 const ACE_TCHAR
*t_name
= temp_name (name
);
965 if (validate_value_name (t_name
))
969 if (load_key (key
, base_key
))
973 if ((errnum
= ACE_TEXT_RegDeleteValue (base_key
, t_name
)) != ERROR_SUCCESS
)
984 ACE_Configuration_Win32Registry::load_key (const ACE_Configuration_Section_Key
& key
,
987 ACE_Section_Key_Win32
* pKey
= dynamic_cast<ACE_Section_Key_Win32
*> (get_internal_key (key
));
996 ACE_Configuration_Win32Registry::resolve_key (HKEY hKey
,
997 const ACE_TCHAR
* path
,
1001 // Make a copy of hKey
1003 #if defined (ACE_HAS_WINCE)
1004 if ((errnum
= RegOpenKeyEx (hKey
, 0, 0, 0, &result
)) != ERROR_SUCCESS
)
1006 if ((errnum
= RegOpenKey (hKey
, 0, &result
)) != ERROR_SUCCESS
)
1007 #endif // ACE_HAS_WINCE
1013 // recurse through the path
1014 ACE_TCHAR
*temp_path
= 0;
1015 ACE_NEW_RETURN (temp_path
,
1016 ACE_TCHAR
[ACE_OS::strlen (path
) + 1],
1018 ACE_Auto_Basic_Array_Ptr
<ACE_TCHAR
> pData (temp_path
);
1019 ACE_OS::strcpy (pData
.get (), path
);
1020 ACE_Tokenizer
parser (pData
.get ());
1021 parser
.delimiter_replace ('\\', '\0');
1022 parser
.delimiter_replace ('/', '\0');
1024 for (ACE_TCHAR
*temp
= parser
.next ();
1026 temp
= parser
.next ())
1031 #if defined (ACE_HAS_WINCE)
1032 if ((errnum
= ACE_TEXT_RegOpenKeyEx (result
,
1036 &subkey
)) != ERROR_SUCCESS
)
1038 if ((errnum
= ACE_TEXT_RegOpenKey (result
,
1040 &subkey
)) != ERROR_SUCCESS
)
1041 #endif // ACE_HAS_WINCE
1044 if (!create
|| (errnum
= ACE_TEXT_RegCreateKeyEx (result
,
1052 #if defined (__MINGW32__)
1056 #endif /* __MINGW32__ */
1061 ::RegCloseKey (result
);
1065 // release our open key handle
1066 ::RegCloseKey (result
);
1073 #endif /* ACE_WIN32 && !ACE_LACKS_WIN32_REGISTRY */
1075 ///////////////////////////////////////////////////////////////
1077 ACE_Configuration_Value_IntId::ACE_Configuration_Value_IntId (void)
1078 : type_ (ACE_Configuration::INVALID
),
1081 this->data_
.ptr_
= 0;
1084 ACE_Configuration_Value_IntId::ACE_Configuration_Value_IntId (ACE_TCHAR
* string
)
1085 : type_ (ACE_Configuration::STRING
),
1088 this->data_
.ptr_
= string
;
1091 ACE_Configuration_Value_IntId::ACE_Configuration_Value_IntId (u_int integer
)
1092 : type_ (ACE_Configuration::INTEGER
),
1095 this->data_
.int_
= integer
;
1098 ACE_Configuration_Value_IntId::ACE_Configuration_Value_IntId (void* data
, size_t length
)
1099 : type_ (ACE_Configuration::BINARY
),
1102 this->data_
.ptr_
= data
;
1105 ACE_Configuration_Value_IntId::ACE_Configuration_Value_IntId (const ACE_Configuration_Value_IntId
& rhs
)
1106 : type_ (rhs
.type_
),
1108 length_ (rhs
.length_
)
1112 ACE_Configuration_Value_IntId::~ACE_Configuration_Value_IntId (void)
1116 ACE_Configuration_Value_IntId
& ACE_Configuration_Value_IntId::operator= (const ACE_Configuration_Value_IntId
& rhs
)
1122 length_
= rhs
.length_
;
1128 ACE_Configuration_Value_IntId::free (ACE_Allocator
*alloc
)
1130 if (this->type_
== ACE_Configuration::STRING
1131 || this->type_
== ACE_Configuration::BINARY
)
1132 alloc
->free (data_
.ptr_
);
1133 // Do nothing in other cases...
1136 ACE_Configuration_ExtId::ACE_Configuration_ExtId (void)
1141 ACE_Configuration_ExtId::ACE_Configuration_ExtId (const ACE_TCHAR
* name
)
1146 ACE_Configuration_ExtId::ACE_Configuration_ExtId (const ACE_Configuration_ExtId
& rhs
)
1151 ACE_Configuration_ExtId::~ACE_Configuration_ExtId (void)
1155 ACE_Configuration_ExtId
& ACE_Configuration_ExtId::operator= (const ACE_Configuration_ExtId
& rhs
)
1164 ACE_Configuration_ExtId::operator== (const ACE_Configuration_ExtId
& rhs
) const
1166 return (ACE_OS::strcasecmp (name_
, rhs
.name_
) == 0);
1170 ACE_Configuration_ExtId::operator!= (const ACE_Configuration_ExtId
& rhs
) const
1172 return !this->operator== (rhs
);
1176 ACE_Configuration_ExtId::hash (void) const
1178 ACE_TString
temp (name_
, 0, false);
1179 return temp
.hash ();
1183 ACE_Configuration_ExtId::free (ACE_Allocator
*alloc
)
1185 alloc
->free ((void *) (name_
));
1188 ///////////////////////////////////////////////////////////////////////
1190 ACE_Configuration_Section_IntId::ACE_Configuration_Section_IntId (void)
1191 : value_hash_map_ (0),
1192 section_hash_map_ (0)
1196 ACE_Configuration_Section_IntId::ACE_Configuration_Section_IntId (VALUE_MAP
* value_hash_map
, SUBSECTION_MAP
* section_hash_map
)
1197 : value_hash_map_ (value_hash_map
),
1198 section_hash_map_ (section_hash_map
)
1202 ACE_Configuration_Section_IntId::ACE_Configuration_Section_IntId (const ACE_Configuration_Section_IntId
& rhs
)
1203 : value_hash_map_ (rhs
.value_hash_map_
),
1204 section_hash_map_ (rhs
.section_hash_map_
)
1209 ACE_Configuration_Section_IntId::~ACE_Configuration_Section_IntId ()
1213 ACE_Configuration_Section_IntId
&
1214 ACE_Configuration_Section_IntId::operator= (const ACE_Configuration_Section_IntId
& rhs
)
1218 value_hash_map_
= rhs
.value_hash_map_
;
1219 section_hash_map_
= rhs
.section_hash_map_
;
1225 ACE_Configuration_Section_IntId::free (ACE_Allocator
*alloc
)
1227 alloc
->free ((void *) (value_hash_map_
));
1228 alloc
->free ((void *) (section_hash_map_
));
1231 ACE_Configuration_Section_Key_Heap::ACE_Configuration_Section_Key_Heap (const ACE_TCHAR
* path
)
1236 path_
= ACE_OS::strdup (path
);
1239 ACE_Configuration_Section_Key_Heap::~ACE_Configuration_Section_Key_Heap ()
1242 delete section_iter_
;
1243 ACE_OS::free (path_
);
1246 //////////////////////////////////////////////////////////////////////////////
1248 ACE_Configuration_Heap::ACE_Configuration_Heap (void)
1251 default_map_size_ (0)
1253 ACE_Configuration_Section_Key_Heap
*temp
= 0;
1255 ACE_NEW (temp
, ACE_Configuration_Section_Key_Heap (ACE_TEXT ("")));
1256 root_
= ACE_Configuration_Section_Key (temp
);
1259 ACE_Configuration_Heap::~ACE_Configuration_Heap (void)
1262 allocator_
->sync ();
1268 ACE_Configuration_Heap::open (size_t default_map_size
)
1270 default_map_size_
= default_map_size
;
1271 // Create the allocator with the appropriate options.
1272 // The name used for the lock is the same as one used
1274 ACE_NEW_RETURN (this->allocator_
,
1277 return create_index ();
1282 ACE_Configuration_Heap::open (const ACE_TCHAR
* file_name
,
1284 size_t default_map_size
)
1286 default_map_size_
= default_map_size
;
1288 // Make sure that the file name is of the legal length.
1289 if (ACE_OS::strlen (file_name
) >= MAXNAMELEN
+ MAXPATHLEN
)
1291 errno
= ENAMETOOLONG
;
1295 ACE_MMAP_Memory_Pool::OPTIONS
options (base_address
);
1297 // Create the allocator with the appropriate options. The name used
1298 // for the lock is the same as one used for the file.
1299 ACE_NEW_RETURN (this->allocator_
,
1300 PERSISTENT_ALLOCATOR (file_name
,
1305 #if !defined (ACE_LACKS_ACCESS)
1306 // Now check if the backing store has been created successfully.
1307 if (ACE_OS::access (file_name
, F_OK
) != 0)
1308 ACE_ERROR_RETURN ((LM_ERROR
,
1309 ACE_TEXT ("create_index\n")),
1311 #endif /* ACE_LACKS_ACCESS */
1313 return create_index ();
1317 ACE_Configuration_Heap::create_index (void)
1319 void *section_index
= 0;
1321 // This is the easy case since if we find hash table in the
1322 // memory-mapped file we know it's already initialized.
1323 if (this->allocator_
->find (ACE_CONFIG_SECTION_INDEX
, section_index
) == 0)
1324 this->index_
= (SECTION_MAP
*) section_index
;
1326 // Create a new <index_> (because we've just created a new
1327 // memory-mapped file).
1330 size_t index_size
= sizeof (SECTION_MAP
);
1331 section_index
= this->allocator_
->malloc (index_size
);
1333 if (section_index
== 0
1334 || create_index_helper (section_index
) == -1
1335 || this->allocator_
->bind (ACE_CONFIG_SECTION_INDEX
,
1336 section_index
) == -1)
1338 // Attempt to clean up.
1339 ACE_ERROR ((LM_ERROR
,
1340 ACE_TEXT ("create_index failed\n")));
1341 this->allocator_
->remove ();
1344 // Add the root section
1345 return new_section (ACE_TEXT (""), root_
);
1351 ACE_Configuration_Heap::create_index_helper (void *buffer
)
1353 ACE_ASSERT (this->allocator_
);
1354 this->index_
= new (buffer
) SECTION_MAP (this->allocator_
);
1359 ACE_Configuration_Heap::load_key (const ACE_Configuration_Section_Key
& key
,
1362 ACE_ASSERT (this->allocator_
);
1363 ACE_Configuration_Section_Key_Heap
* pKey
=
1364 dynamic_cast<ACE_Configuration_Section_Key_Heap
*> (get_internal_key (key
));
1371 ACE_TString
temp (pKey
->path_
, 0, false);
1372 name
.assign_nocopy (temp
);
1378 ACE_Configuration_Heap::add_section (const ACE_Configuration_Section_Key
& base
,
1379 const ACE_TCHAR
* sub_section
,
1380 ACE_Configuration_Section_Key
& result
)
1382 ACE_ASSERT (this->allocator_
);
1383 ACE_TString section
;
1384 if (load_key (base
, section
))
1387 // Find the base section
1388 ACE_Configuration_ExtId
ExtId (section
.fast_rep ());
1389 ACE_Configuration_Section_IntId IntId
;
1390 if (index_
->find (ExtId
, IntId
, allocator_
))
1393 // See if this section already exists
1394 ACE_Configuration_ExtId
SubSectionExtId (sub_section
);
1397 if (!IntId
.section_hash_map_
->find (SubSectionExtId
, ignored
, allocator_
))
1404 // Create the new section name
1405 // only prepend a separater if were not at the root
1406 if (section
.length ())
1407 section
+= ACE_TEXT ("\\");
1409 section
+= sub_section
;
1411 // Add it to the base section
1412 ACE_TCHAR
* pers_name
= (ACE_TCHAR
*) allocator_
->malloc ((ACE_OS::strlen (sub_section
) + 1) * sizeof (ACE_TCHAR
));
1413 ACE_OS::strcpy (pers_name
, sub_section
);
1414 ACE_Configuration_ExtId
SSExtId (pers_name
);
1415 if (IntId
.section_hash_map_
->bind (SSExtId
, ignored
, allocator_
))
1417 allocator_
->free (pers_name
);
1420 return (new_section (section
, result
));
1424 ACE_Configuration_Heap::new_section (const ACE_TString
& section
,
1425 ACE_Configuration_Section_Key
& result
)
1427 ACE_ASSERT (this->allocator_
);
1428 // Create a new section and add it to the global list
1430 // Allocate memory for items to be stored in the table.
1431 size_t section_len
= section
.length () + 1;
1432 ACE_TCHAR
*ptr
= (ACE_TCHAR
*) this->allocator_
->malloc (section_len
* sizeof (ACE_TCHAR
));
1434 int return_value
= -1;
1440 // Populate memory with data.
1441 ACE_OS::strcpy (ptr
, section
.fast_rep ());
1443 void *value_hash_map
= 0;
1444 size_t map_size
= sizeof (VALUE_MAP
);
1445 value_hash_map
= this->allocator_
->malloc (map_size
);
1447 // If allocation failed ...
1448 if (value_hash_map
== 0)
1451 // Initialize allocated hash map through placement new.
1452 if (value_open_helper (default_map_size_
, value_hash_map
) == -1)
1454 this->allocator_
->free (value_hash_map
);
1458 // create the section map
1459 void* section_hash_map
= 0;
1460 map_size
= sizeof (SUBSECTION_MAP
);
1461 section_hash_map
= this->allocator_
->malloc (map_size
);
1463 // If allocation failed
1464 if (section_hash_map
== 0)
1467 // initialize allocated hash map through placement new
1468 if (section_open_helper (default_map_size_
, section_hash_map
) == -1)
1470 this->allocator_
->free (value_hash_map
);
1471 this->allocator_
->free (section_hash_map
);
1475 ACE_Configuration_ExtId
name (ptr
);
1476 ACE_Configuration_Section_IntId
entry ((VALUE_MAP
*) value_hash_map
,
1477 (SUBSECTION_MAP
*) section_hash_map
);
1479 // Do a normal bind. This will fail if there's already an
1480 // entry with the same name.
1481 return_value
= this->index_
->bind (name
, entry
, this->allocator_
);
1483 if (return_value
== 1 /* Entry already existed so bind failed. */
1484 || return_value
== -1 /* Unable to bind for other reasons. */)
1486 // Free our dynamically allocated memory.
1487 this->allocator_
->free (static_cast<void *> (ptr
));
1488 return return_value
;
1491 // If bind () succeed, it will automatically sync
1492 // up the map manager entry. However, we must sync up our
1493 // name/value memory.
1494 this->allocator_
->sync (ptr
, section_len
);
1498 ACE_Configuration_Section_Key_Heap
*temp
;
1499 ACE_NEW_RETURN (temp
,
1500 ACE_Configuration_Section_Key_Heap (ptr
),
1502 result
= ACE_Configuration_Section_Key (temp
);
1503 return return_value
;
1507 ACE_Configuration_Heap::value_open_helper (size_t hash_table_size
,
1510 ACE_ASSERT (this->allocator_
);
1511 new (buffer
) VALUE_MAP (hash_table_size
, this->allocator_
);
1516 ACE_Configuration_Heap::section_open_helper (size_t hash_table_size
,
1519 ACE_ASSERT (this->allocator_
);
1520 new (buffer
) SUBSECTION_MAP (hash_table_size
, this->allocator_
);
1525 ACE_Configuration_Heap::open_section (const ACE_Configuration_Section_Key
& base
,
1526 const ACE_TCHAR
* sub_section
,
1528 ACE_Configuration_Section_Key
& result
)
1530 ACE_ASSERT (this->allocator_
);
1531 if (validate_name (sub_section
, 1)) // 1 == allow_path
1536 for (const ACE_TCHAR
* separator
;
1537 (separator
= ACE_OS::strchr (sub_section
, ACE_TEXT ('\\'))) != 0;
1540 ACE_TString
simple_section (sub_section
, separator
- sub_section
);
1542 open_simple_section (result
, simple_section
.c_str (), create
, result
);
1545 sub_section
= separator
+ 1;
1548 return open_simple_section (result
, sub_section
, create
, result
);
1552 ACE_Configuration_Heap::open_simple_section (const ACE_Configuration_Section_Key
& base
,
1553 const ACE_TCHAR
* sub_section
,
1555 ACE_Configuration_Section_Key
& result
)
1557 ACE_TString
section (0, 0, false);
1559 if (load_key (base
, section
))
1564 // Only add the \\ if were not at the root
1565 if (section
.length ())
1567 section
+= ACE_TEXT ("\\");
1570 section
+= sub_section
;
1572 // resolve the section
1573 ACE_Configuration_ExtId
ExtId (section
.fast_rep ());
1574 ACE_Configuration_Section_IntId IntId
;
1576 if (index_
->find (ExtId
, IntId
, allocator_
))
1584 return add_section (base
, sub_section
, result
);
1587 ACE_Configuration_Section_Key_Heap
*temp
;
1588 ACE_NEW_RETURN (temp
,
1589 ACE_Configuration_Section_Key_Heap (section
.fast_rep ()),
1591 result
= ACE_Configuration_Section_Key (temp
);
1596 ACE_Configuration_Heap::remove_section (const ACE_Configuration_Section_Key
& key
,
1597 const ACE_TCHAR
* sub_section
,
1600 ACE_ASSERT (this->allocator_
);
1601 if (validate_name (sub_section
))
1604 ACE_TString section
;
1605 if (load_key (key
, section
))
1609 ACE_Configuration_ExtId
ParentExtId (section
.fast_rep ());
1610 ACE_Configuration_Section_IntId ParentIntId
;
1611 if (index_
->find (ParentExtId
, ParentIntId
, allocator_
))
1612 return -1;// no parent key
1615 if (section
.length ())
1616 section
+= ACE_TEXT ("\\");
1618 section
+= sub_section
;
1619 ACE_Configuration_ExtId
SectionExtId (section
.fast_rep ());
1620 SECTION_HASH::ENTRY
* section_entry
;
1621 SECTION_HASH
* hashmap
= index_
;
1622 if (hashmap
->find (SectionExtId
, section_entry
))
1627 ACE_Configuration_Section_Key section
;
1628 if (open_section (key
, sub_section
, 0, section
))
1633 while (!enumerate_sections (section
, index
, name
))
1635 if (remove_section (section
, name
.fast_rep (), 1))
1642 // Now make sure we dont have any subkeys
1643 if (section_entry
->int_id_
.section_hash_map_
->current_size ())
1649 // Now remove subkey from parent key
1650 ACE_Configuration_ExtId
SubSExtId (sub_section
);
1651 SUBSECTION_HASH::ENTRY
* subsection_entry
;
1652 if (((SUBSECTION_HASH
*)ParentIntId
.section_hash_map_
)->
1653 find (SubSExtId
, subsection_entry
))
1656 if (ParentIntId
.section_hash_map_
->unbind (SubSExtId
, allocator_
))
1659 subsection_entry
->ext_id_
.free (allocator_
);
1661 // Remember the pointers so we can free them after we unbind
1662 ACE_Configuration_ExtId
ExtIdToFree (section_entry
->ext_id_
);
1663 ACE_Configuration_Section_IntId
IntIdToFree (section_entry
->int_id_
);
1665 // iterate over all values and free memory
1666 VALUE_HASH
* value_hash_map
= section_entry
->int_id_
.value_hash_map_
;
1667 VALUE_HASH::ITERATOR value_iter
= value_hash_map
->begin ();
1668 while (!value_iter
.done ())
1670 VALUE_HASH::ENTRY
* value_entry
= 0;
1671 if (!value_iter
.next (value_entry
))
1674 value_entry
->ext_id_
.free (allocator_
);
1675 value_entry
->int_id_
.free (allocator_
);
1677 value_iter
.advance ();
1681 if (index_
->unbind (SectionExtId
, allocator_
))
1684 value_hash_map
->close ();
1685 section_entry
->int_id_
.section_hash_map_
->close (allocator_
);
1688 ExtIdToFree
.free (allocator_
);
1689 IntIdToFree
.free (allocator_
);
1695 ACE_Configuration_Heap::enumerate_values (const ACE_Configuration_Section_Key
& key
,
1700 ACE_ASSERT (this->allocator_
);
1701 ACE_Configuration_Section_Key_Heap
* pKey
=
1702 dynamic_cast<ACE_Configuration_Section_Key_Heap
*> (get_internal_key (key
));
1708 // resolve the section
1709 ACE_Configuration_ExtId
ExtId (pKey
->path_
);
1710 ACE_Configuration_Section_IntId IntId
;
1711 if (index_
->find (ExtId
, IntId
, allocator_
))
1714 // Handle iterator resets
1717 ACE_Hash_Map_Manager_Ex
<ACE_Configuration_ExtId
,
1718 ACE_Configuration_Value_IntId
,
1719 ACE_Hash
<ACE_Configuration_ExtId
>,
1720 ACE_Equal_To
<ACE_Configuration_ExtId
>,
1721 ACE_Null_Mutex
>* hash_map
= IntId
.value_hash_map_
;
1722 delete pKey
->value_iter_
;
1724 ACE_NEW_RETURN (pKey
->value_iter_
,
1725 VALUE_HASH::ITERATOR (hash_map
->begin ()),
1729 // Get the next entry
1730 ACE_Hash_Map_Entry
<ACE_Configuration_ExtId
, ACE_Configuration_Value_IntId
>* entry
= 0;
1732 if (!pKey
->value_iter_
->next (entry
))
1735 // Return the value of the iterator and advance it
1736 name
= entry
->ext_id_
.name_
;
1737 type
= entry
->int_id_
.type_
;
1738 pKey
->value_iter_
->advance ();
1744 ACE_Configuration_Heap::enumerate_sections (const ACE_Configuration_Section_Key
& key
,
1748 ACE_ASSERT (this->allocator_
);
1749 // cast to a heap section key
1750 ACE_Configuration_Section_Key_Heap
* pKey
=
1751 dynamic_cast<ACE_Configuration_Section_Key_Heap
*> (get_internal_key (key
));
1753 return -1; // not a heap key!
1755 // resolve the section
1756 ACE_Configuration_ExtId
ExtId (pKey
->path_
);
1757 ACE_Configuration_Section_IntId IntId
;
1758 if (index_
->find (ExtId
, IntId
, allocator_
))
1759 return -1; // unknown section
1761 // Handle iterator resets
1764 if (pKey
->section_iter_
)
1765 delete pKey
->section_iter_
;
1767 ACE_NEW_RETURN (pKey
->section_iter_
,
1768 SUBSECTION_HASH::ITERATOR (IntId
.section_hash_map_
->begin ()),
1772 // Get the next entry
1773 ACE_Hash_Map_Entry
<ACE_Configuration_ExtId
, int>* entry
= 0;
1774 if (!pKey
->section_iter_
->next (entry
))
1777 // Return the value of the iterator and advance it
1778 pKey
->section_iter_
->advance ();
1779 name
= entry
->ext_id_
.name_
;
1785 ACE_Configuration_Heap::set_string_value (const ACE_Configuration_Section_Key
& key
,
1786 const ACE_TCHAR
* name
,
1787 const ACE_TString
& value
)
1789 ACE_ASSERT (this->allocator_
);
1790 const ACE_TCHAR
*t_name
= name
? name
: &this->NULL_String_
;
1791 if (validate_value_name (t_name
))
1794 ACE_TString section
;
1795 if (load_key (key
, section
))
1798 ACE_Configuration_ExtId
section_ext (section
.fast_rep ());
1799 ACE_Configuration_Section_IntId section_int
;
1800 if (index_
->find (section_ext
, section_int
, allocator_
))
1803 // Get the entry for this item (if it exists)
1804 VALUE_HASH::ENTRY
* entry
;
1805 ACE_Configuration_ExtId
item_name (t_name
);
1806 if (section_int
.value_hash_map_
->VALUE_HASH::find (item_name
, entry
) == 0)
1808 // found item, replace it
1809 // Free the old value
1810 entry
->int_id_
.free (allocator_
);
1811 // Allocate the new value in this heap
1812 ACE_TCHAR
* pers_value
=
1813 (ACE_TCHAR
*) allocator_
->malloc ((value
.length () + 1) * sizeof (ACE_TCHAR
));
1814 ACE_OS::strcpy (pers_value
, value
.fast_rep ());
1815 ACE_Configuration_Value_IntId
new_value_int (pers_value
);
1816 entry
->int_id_
= new_value_int
;
1820 // it doesn't exist, bind it
1821 ACE_TCHAR
* pers_name
=
1822 (ACE_TCHAR
*) allocator_
->malloc ((ACE_OS::strlen (t_name
) + 1) * sizeof (ACE_TCHAR
));
1823 ACE_OS::strcpy (pers_name
, t_name
);
1824 ACE_TCHAR
* pers_value
=
1825 (ACE_TCHAR
*) allocator_
->malloc ((value
.length () + 1) * sizeof (ACE_TCHAR
));
1826 ACE_OS::strcpy (pers_value
, value
.fast_rep ());
1827 ACE_Configuration_ExtId
item_name (pers_name
);
1828 ACE_Configuration_Value_IntId
item_value (pers_value
);
1829 if (section_int
.value_hash_map_
->bind (item_name
, item_value
, allocator_
))
1831 allocator_
->free (pers_value
);
1832 allocator_
->free (pers_name
);
1842 ACE_Configuration_Heap::set_integer_value (const ACE_Configuration_Section_Key
& key
,
1843 const ACE_TCHAR
* name
,
1846 ACE_ASSERT (this->allocator_
);
1847 const ACE_TCHAR
*t_name
= name
? name
: &this->NULL_String_
;
1848 if (validate_value_name (t_name
))
1851 // Get the section name from the key
1852 ACE_TString section
;
1853 if (load_key (key
, section
))
1856 // Find this section
1857 ACE_Configuration_ExtId
section_ext (section
.fast_rep ());
1858 ACE_Configuration_Section_IntId section_int
;
1859 if (index_
->find (section_ext
, section_int
, allocator_
))
1860 return -1; // section does not exist
1862 // Get the entry for this item (if it exists)
1863 VALUE_HASH::ENTRY
* entry
;
1864 ACE_Configuration_ExtId
item_name (t_name
);
1865 if (section_int
.value_hash_map_
->VALUE_HASH::find (item_name
, entry
) == 0)
1867 // found item, replace it
1868 ACE_Configuration_Value_IntId
new_value_int (value
);
1869 entry
->int_id_
= new_value_int
;
1873 // it doesn't exist, bind it
1874 ACE_TCHAR
* pers_name
=
1875 (ACE_TCHAR
*) allocator_
->malloc ((ACE_OS::strlen (t_name
) + 1) * sizeof (ACE_TCHAR
));
1876 ACE_OS::strcpy (pers_name
, t_name
);
1877 ACE_Configuration_ExtId
item_name (pers_name
);
1878 ACE_Configuration_Value_IntId
item_value (value
);
1879 if (section_int
.value_hash_map_
->bind (item_name
, item_value
, allocator_
))
1881 allocator_
->free (pers_name
);
1891 ACE_Configuration_Heap::set_binary_value (const ACE_Configuration_Section_Key
& key
,
1892 const ACE_TCHAR
* name
,
1896 ACE_ASSERT (this->allocator_
);
1897 const ACE_TCHAR
*t_name
= name
? name
: &this->NULL_String_
;
1898 if (validate_value_name (t_name
))
1901 // Get the section name from the key
1902 ACE_TString section
;
1903 if (load_key (key
, section
))
1906 // Find this section
1907 ACE_Configuration_ExtId
section_ext (section
.fast_rep ());
1908 ACE_Configuration_Section_IntId section_int
;
1909 if (index_
->find (section_ext
, section_int
, allocator_
))
1910 return -1; // section does not exist
1912 // Get the entry for this item (if it exists)
1913 VALUE_HASH::ENTRY
* entry
;
1914 ACE_Configuration_ExtId
item_name (t_name
);
1915 if (section_int
.value_hash_map_
->VALUE_HASH::find (item_name
, entry
) == 0)
1917 // found item, replace it
1918 // Free the old value
1919 entry
->int_id_
.free (allocator_
);
1920 // Allocate the new value in this heap
1921 ACE_TCHAR
* pers_value
= (ACE_TCHAR
*) allocator_
->malloc (length
);
1922 ACE_OS::memcpy (pers_value
, data
, length
);
1923 ACE_Configuration_Value_IntId
new_value_int (pers_value
, length
);
1924 entry
->int_id_
= new_value_int
;
1928 // it doesn't exist, bind it
1929 ACE_TCHAR
* pers_name
=
1930 (ACE_TCHAR
*) allocator_
->malloc ((ACE_OS::strlen (t_name
) + 1) * sizeof (ACE_TCHAR
));
1931 ACE_OS::strcpy (pers_name
, t_name
);
1932 ACE_TCHAR
* pers_value
= (ACE_TCHAR
*) allocator_
->malloc (length
);
1933 ACE_OS::memcpy (pers_value
, data
, length
);
1934 ACE_Configuration_ExtId
item_name (pers_name
);
1935 ACE_Configuration_Value_IntId
item_value (pers_value
, length
);
1936 if (section_int
.value_hash_map_
->bind (item_name
, item_value
, allocator_
))
1938 allocator_
->free (pers_value
);
1939 allocator_
->free (pers_name
);
1949 ACE_Configuration_Heap::get_string_value (const ACE_Configuration_Section_Key
& key
,
1950 const ACE_TCHAR
* name
,
1953 ACE_ASSERT (this->allocator_
);
1954 const ACE_TCHAR
*t_name
= name
? name
: &this->NULL_String_
;
1955 if (validate_value_name (t_name
))
1958 // Get the section name from the key
1959 ACE_TString section
;
1960 if (load_key (key
, section
))
1963 // Find this section
1964 ACE_Configuration_ExtId
ExtId (section
.fast_rep ());
1965 ACE_Configuration_Section_IntId IntId
;
1966 if (index_
->find (ExtId
, IntId
, allocator_
))
1967 return -1; // section does not exist
1969 // See if it exists first
1970 ACE_Configuration_ExtId
VExtId (t_name
);
1971 ACE_Configuration_Value_IntId VIntId
;
1972 if (IntId
.value_hash_map_
->find (VExtId
, VIntId
, allocator_
))
1973 return -1; // unknown value
1976 if (VIntId
.type_
!= ACE_Configuration::STRING
)
1982 // everythings ok, return the data
1983 value
= static_cast<ACE_TCHAR
*> (VIntId
.data_
.ptr_
);
1988 ACE_Configuration_Heap::get_integer_value (const ACE_Configuration_Section_Key
& key
,
1989 const ACE_TCHAR
* name
,
1992 ACE_ASSERT (this->allocator_
);
1994 const ACE_TCHAR
*t_name
= name
? name
: &this->NULL_String_
;
1995 if (validate_value_name (t_name
))
1998 // Get the section name from the key
1999 ACE_TString
section (0, 0, false);
2001 if (this->load_key (key
, section
) != 0)
2006 // Find this section
2007 ACE_Configuration_ExtId
ExtId (section
.fast_rep ());
2008 ACE_Configuration_Section_IntId IntId
;
2010 if (index_
->find (ExtId
, IntId
, allocator_
) != 0)
2012 return -1; // section does not exist
2016 // See if it exists first
2017 ACE_Configuration_ExtId
VExtId (t_name
);
2018 ACE_Configuration_Value_IntId VIntId
;
2020 if (IntId
.value_hash_map_
->find (VExtId
, VIntId
, allocator_
) != 0)
2022 return -1; // unknown value
2026 if (VIntId
.type_
!= ACE_Configuration::INTEGER
)
2032 // Everythings ok, return the data
2033 value
= VIntId
.data_
.int_
;
2038 ACE_Configuration_Heap::get_binary_value (
2039 const ACE_Configuration_Section_Key
& key
,
2040 const ACE_TCHAR
* name
,
2044 ACE_ASSERT (this->allocator_
);
2045 const ACE_TCHAR
*t_name
= name
? name
: &this->NULL_String_
;
2046 if (validate_value_name (t_name
))
2049 // Get the section name from the key
2050 ACE_TString section
;
2051 if (load_key (key
, section
))
2054 // Find this section
2055 ACE_Configuration_ExtId
ExtId (section
.fast_rep ());
2056 ACE_Configuration_Section_IntId IntId
;
2057 if (index_
->find (ExtId
, IntId
, allocator_
))
2058 return -1; // section does not exist
2060 ACE_Configuration_ExtId
VExtId (t_name
);
2061 ACE_Configuration_Value_IntId VIntId
;
2062 // See if it exists first
2063 if (IntId
.value_hash_map_
->find (VExtId
, VIntId
, allocator_
))
2064 return -1; // unknown value
2067 if (VIntId
.type_
!= ACE_Configuration::BINARY
)
2074 ACE_NEW_RETURN (data
, char[VIntId
.length_
], -1);
2075 ACE_OS::memcpy (data
, VIntId
.data_
.ptr_
, VIntId
.length_
);
2076 length
= VIntId
.length_
;
2081 ACE_Configuration_Heap::find_value (const ACE_Configuration_Section_Key
& key
,
2082 const ACE_TCHAR
* name
,
2083 VALUETYPE
& type_out
)
2085 ACE_ASSERT (this->allocator_
);
2086 const ACE_TCHAR
*t_name
= name
? name
: &this->NULL_String_
;
2087 if (validate_value_name (t_name
))
2090 // Get the section name from the key
2091 ACE_TString section
;
2092 if (load_key (key
, section
))
2095 // Find this section
2096 ACE_Configuration_ExtId
ExtId (section
.fast_rep ());
2097 ACE_Configuration_Section_IntId IntId
;
2098 if (index_
->find (ExtId
, IntId
, allocator_
))
2099 return -1; // section does not exist
2102 ACE_Configuration_ExtId
ValueExtId (t_name
);
2103 VALUE_HASH::ENTRY
* value_entry
;
2104 if (((VALUE_HASH
*) IntId
.value_hash_map_
)->find (ValueExtId
, value_entry
))
2105 return -1; // value does not exist
2107 type_out
= value_entry
->int_id_
.type_
;
2112 ACE_Configuration_Heap::remove_value (const ACE_Configuration_Section_Key
& key
,
2113 const ACE_TCHAR
* name
)
2115 ACE_ASSERT (this->allocator_
);
2116 const ACE_TCHAR
*t_name
= name
? name
: &this->NULL_String_
;
2117 if (validate_value_name (t_name
))
2120 // Get the section name from the key
2121 ACE_TString section
;
2122 if (load_key (key
, section
))
2125 // Find this section
2126 ACE_Configuration_ExtId
ExtId (section
.fast_rep ());
2127 ACE_Configuration_Section_IntId IntId
;
2128 if (index_
->find (ExtId
, IntId
, allocator_
))
2129 return -1; // section does not exist
2132 ACE_Configuration_ExtId
ValueExtId (t_name
);
2133 VALUE_HASH::ENTRY
* value_entry
;
2134 if (((VALUE_HASH
*) IntId
.value_hash_map_
)->find (ValueExtId
, value_entry
))
2138 value_entry
->ext_id_
.free (allocator_
);
2139 value_entry
->int_id_
.free (allocator_
);
2142 if (IntId
.value_hash_map_
->unbind (ValueExtId
, allocator_
))
2148 ACE_END_VERSIONED_NAMESPACE_DECL