00001 #include "ace_pch.h"
00002
00003 #include "ace/Configuration.h"
00004 #include "ace/Auto_Ptr.h"
00005
00006
00007
00008 #include "ace/Configuration_Import_Export.h"
00009
00010 #if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
00011
00012 #if defined (ACE_HAS_THREADS)
00013
00014
00015
00016 template class ACE_Allocator_Adapter<ACE_Malloc<ACE_MMAP_MEMORY_POOL, ACE_Thread_Mutex> >;
00017 template class ACE_Malloc<ACE_MMAP_MEMORY_POOL, ACE_Thread_Mutex>;
00018 template class ACE_Malloc_T<ACE_MMAP_MEMORY_POOL, ACE_Thread_Mutex, ACE_Control_Block>;
00019 #endif
00020 template class ACE_Hash_Map_Entry<ACE_Configuration_ExtId, ACE_Configuration_Section_IntId>;
00021 template class ACE_Hash_Map_Entry<ACE_Configuration_ExtId, ACE_Configuration_Value_IntId>;
00022 template class ACE_Hash_Map_Entry<ACE_Configuration_ExtId, int>;
00023 template class ACE_Hash_Map_Iterator_Base_Ex<ACE_Configuration_ExtId, ACE_Configuration_Section_IntId, ACE_Hash<ACE_Configuration_ExtId>, ACE_Equal_To<ACE_Configuration_ExtId>, ACE_Null_Mutex>;
00024 template class ACE_Hash_Map_Iterator_Base_Ex<ACE_Configuration_ExtId, ACE_Configuration_Value_IntId, ACE_Hash<ACE_Configuration_ExtId>, ACE_Equal_To<ACE_Configuration_ExtId>, ACE_Null_Mutex>;
00025 template class ACE_Hash_Map_Iterator_Base_Ex<ACE_Configuration_ExtId, int, ACE_Hash<ACE_Configuration_ExtId>, ACE_Equal_To<ACE_Configuration_ExtId>, ACE_Null_Mutex>;
00026
00027
00028
00029 template class ACE_Hash_Map_Reverse_Iterator_Ex<ACE_Configuration_ExtId,ACE_Configuration_Value_IntId,ACE_Hash<ACE_Configuration_ExtId>,ACE_Equal_To<ACE_Configuration_ExtId>,ACE_Null_Mutex>;
00030 template class ACE_Hash_Map_Iterator_Ex<ACE_Configuration_ExtId,ACE_Configuration_Value_IntId,ACE_Hash<ACE_Configuration_ExtId>,ACE_Equal_To<ACE_Configuration_ExtId>,ACE_Null_Mutex>;
00031 template class ACE_Hash_Map_Iterator_Ex<ACE_Configuration_ExtId,int,ACE_Hash<ACE_Configuration_ExtId>,ACE_Equal_To<ACE_Configuration_ExtId>,ACE_Null_Mutex>;
00032 template class ACE_Hash_Map_Iterator_Ex<ACE_Configuration_ExtId,ACE_Configuration_Section_IntId,ACE_Hash<ACE_Configuration_ExtId>,ACE_Equal_To<ACE_Configuration_ExtId>,ACE_Null_Mutex>;
00033 template class ACE_Equal_To<ACE_Configuration_ExtId>;
00034 template class ACE_Hash_Map_Reverse_Iterator_Ex<ACE_Configuration_ExtId,ACE_Configuration_Section_IntId,ACE_Hash<ACE_Configuration_ExtId>,ACE_Equal_To<ACE_Configuration_ExtId>,ACE_Null_Mutex>;
00035 template class ACE_Hash_Map_Reverse_Iterator_Ex<ACE_Configuration_ExtId,int,ACE_Hash<ACE_Configuration_ExtId>,ACE_Equal_To<ACE_Configuration_ExtId>,ACE_Null_Mutex>;
00036 template class ACE_Hash<ACE_Configuration_ExtId>;
00037
00038 template class ACE_Hash_Map_Manager_Ex<ACE_Configuration_ExtId, ACE_Configuration_Section_IntId, ACE_Hash<ACE_Configuration_ExtId>, ACE_Equal_To<ACE_Configuration_ExtId>, ACE_Null_Mutex>;
00039 template class ACE_Hash_Map_Manager_Ex<ACE_Configuration_ExtId, ACE_Configuration_Value_IntId, ACE_Hash<ACE_Configuration_ExtId>, ACE_Equal_To<ACE_Configuration_ExtId>, ACE_Null_Mutex>;
00040 template class ACE_Hash_Map_Manager_Ex<ACE_Configuration_ExtId, int, ACE_Hash<ACE_Configuration_ExtId>, ACE_Equal_To<ACE_Configuration_ExtId>, ACE_Null_Mutex>;
00041 template class ACE_Hash_Map_Manager<ACE_Configuration_ExtId, ACE_Configuration_Section_IntId, ACE_Null_Mutex>;
00042 template class ACE_Hash_Map_Manager<ACE_Configuration_ExtId, ACE_Configuration_Value_IntId, ACE_Null_Mutex>;
00043 template class ACE_Hash_Map_Manager<ACE_Configuration_ExtId, int, ACE_Null_Mutex>;
00044 template class ACE_Hash_Map_With_Allocator<ACE_Configuration_ExtId, ACE_Configuration_Section_IntId>;
00045 template class ACE_Hash_Map_With_Allocator<ACE_Configuration_ExtId, ACE_Configuration_Value_IntId>;
00046 template class ACE_Hash_Map_With_Allocator<ACE_Configuration_ExtId, int>;
00047
00048 #elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
00049
00050 #if defined (ACE_HAS_THREADS)
00051
00052
00053
00054 #pragma instantiate ACE_Allocator_Adapter<ACE_Malloc<ACE_MMAP_MEMORY_POOL, ACE_Thread_Mutex> >
00055 #pragma instantiate ACE_Malloc<ACE_MMAP_MEMORY_POOL, ACE_Thread_Mutex>
00056 #pragma instantiate ACE_Malloc_T<ACE_MMAP_MEMORY_POOL, ACE_Thread_Mutex, ACE_Control_Block>
00057 #endif
00058 #pragma instantiate ACE_Hash_Map_Entry<ACE_Configuration_ExtId, ACE_Configuration_Section_IntId>
00059 #pragma instantiate ACE_Hash_Map_Entry<ACE_Configuration_ExtId, ACE_Configuration_Value_IntId>
00060 #pragma instantiate ACE_Hash_Map_Entry<ACE_Configuration_ExtId, int>
00061 #pragma instantiate ACE_Hash_Map_Iterator_Base_Ex<ACE_Configuration_ExtId, ACE_Configuration_Section_IntId, ACE_Hash<ACE_Configuration_ExtId>, ACE_Equal_To<ACE_Configuration_ExtId>, ACE_Null_Mutex>
00062 #pragma instantiate ACE_Hash_Map_Iterator_Base_Ex<ACE_Configuration_ExtId, ACE_Configuration_Value_IntId, ACE_Hash<ACE_Configuration_ExtId>, ACE_Equal_To<ACE_Configuration_ExtId>, ACE_Null_Mutex>
00063 #pragma instantiate ACE_Hash_Map_Iterator_Base_Ex<ACE_Configuration_ExtId, int, ACE_Hash<ACE_Configuration_ExtId>, ACE_Equal_To<ACE_Configuration_ExtId>, ACE_Null_Mutex>
00064
00065 #pragma instantiate ACE_Hash_Map_Reverse_Iterator_Ex<ACE_Configuration_ExtId,ACE_Configuration_Value_IntId,ACE_Hash<ACE_Configuration_ExtId>,ACE_Equal_To<ACE_Configuration_ExtId>,ACE_Null_Mutex>
00066 #pragma instantiate ACE_Hash_Map_Iterator_Ex<ACE_Configuration_ExtId,ACE_Configuration_Value_IntId,ACE_Hash<ACE_Configuration_ExtId>,ACE_Equal_To<ACE_Configuration_ExtId>,ACE_Null_Mutex>
00067 #pragma instantiate ACE_Hash_Map_Iterator_Ex<ACE_Configuration_ExtId,int,ACE_Hash<ACE_Configuration_ExtId>,ACE_Equal_To<ACE_Configuration_ExtId>,ACE_Null_Mutex>
00068 #pragma instantiate ACE_Hash_Map_Iterator_Ex<ACE_Configuration_ExtId,ACE_Configuration_Section_IntId,ACE_Hash<ACE_Configuration_ExtId>,ACE_Equal_To<ACE_Configuration_ExtId>,ACE_Null_Mutex>
00069 #pragma instantiate ACE_Equal_To<ACE_Configuration_ExtId>
00070 #pragma instantiate ACE_Hash_Map_Reverse_Iterator_Ex<ACE_Configuration_ExtId,ACE_Configuration_Section_IntId,ACE_Hash<ACE_Configuration_ExtId>,ACE_Equal_To<ACE_Configuration_ExtId>,ACE_Null_Mutex>
00071 #pragma instantiate ACE_Hash_Map_Reverse_Iterator_Ex<ACE_Configuration_ExtId,int,ACE_Hash<ACE_Configuration_ExtId>,ACE_Equal_To<ACE_Configuration_ExtId>,ACE_Null_Mutex>
00072 #pragma instantiate ACE_Hash<ACE_Configuration_ExtId>
00073
00074 #pragma instantiate ACE_Hash_Map_Manager_Ex<ACE_Configuration_ExtId, ACE_Configuration_Section_IntId, ACE_Hash<ACE_Configuration_ExtId>, ACE_Equal_To<ACE_Configuration_ExtId>, ACE_Null_Mutex>
00075 #pragma instantiate ACE_Hash_Map_Manager_Ex<ACE_Configuration_ExtId, ACE_Configuration_Value_IntId, ACE_Hash<ACE_Configuration_ExtId>, ACE_Equal_To<ACE_Configuration_ExtId>, ACE_Null_Mutex>
00076 #pragma instantiate ACE_Hash_Map_Manager_Ex<ACE_Configuration_ExtId, int, ACE_Hash<ACE_Configuration_ExtId>, ACE_Equal_To<ACE_Configuration_ExtId>, ACE_Null_Mutex>
00077 #pragma instantiate ACE_Hash_Map_Manager<ACE_Configuration_ExtId, ACE_Configuration_Section_IntId, ACE_Null_Mutex>
00078 #pragma instantiate ACE_Hash_Map_Manager<ACE_Configuration_ExtId, ACE_Configuration_Value_IntId, ACE_Null_Mutex>
00079 #pragma instantiate ACE_Hash_Map_Manager<ACE_Configuration_ExtId, int, ACE_Null_Mutex>
00080 #pragma instantiate ACE_Hash_Map_With_Allocator<ACE_Configuration_ExtId, ACE_Configuration_Section_IntId>
00081 #pragma instantiate ACE_Hash_Map_With_Allocator<ACE_Configuration_ExtId, ACE_Configuration_Value_IntId>
00082 #pragma instantiate ACE_Hash_Map_With_Allocator<ACE_Configuration_ExtId, int>
00083
00084 #endif
00085
00086 ACE_Section_Key_Internal::ACE_Section_Key_Internal (void)
00087 : ref_count_ (0)
00088 {
00089 }
00090
00091 ACE_Section_Key_Internal::~ACE_Section_Key_Internal (void)
00092 {
00093 }
00094
00095 int
00096 ACE_Section_Key_Internal::add_ref (void)
00097 {
00098 ++ref_count_;
00099 return 0;
00100 }
00101
00102 int
00103 ACE_Section_Key_Internal::dec_ref (void)
00104 {
00105 if (!--ref_count_)
00106 delete this;
00107 return 0;
00108 }
00109
00110 ACE_Configuration_Section_Key::ACE_Configuration_Section_Key (void)
00111 : key_ (0)
00112 {
00113 }
00114
00115 ACE_Configuration_Section_Key::~ACE_Configuration_Section_Key (void)
00116 {
00117 if (key_)
00118 key_->dec_ref ();
00119 }
00120
00121 ACE_Configuration_Section_Key::ACE_Configuration_Section_Key (ACE_Section_Key_Internal* key)
00122 : key_ (key)
00123 {
00124 if (key_)
00125 key_->add_ref ();
00126 }
00127
00128 ACE_Configuration_Section_Key::ACE_Configuration_Section_Key (const ACE_Configuration_Section_Key& rhs)
00129 : key_ (rhs.key_)
00130 {
00131 if (key_)
00132 key_->add_ref ();
00133 }
00134
00135 ACE_Configuration_Section_Key&
00136 ACE_Configuration_Section_Key::operator= (const ACE_Configuration_Section_Key& rhs)
00137 {
00138 if (this != &rhs)
00139 {
00140 if (key_)
00141 key_->dec_ref ();
00142
00143 key_ = rhs.key_;
00144
00145 if (key_)
00146 key_->add_ref ();
00147 }
00148 return *this;
00149 }
00150
00151
00152
00153 ACE_Configuration::ACE_Configuration (void)
00154 : root_ ()
00155 {
00156 }
00157
00158 ACE_Configuration::~ACE_Configuration (void)
00159 {
00160 }
00161
00162 ACE_Section_Key_Internal*
00163 ACE_Configuration::get_internal_key (const ACE_Configuration_Section_Key& key)
00164 {
00165 return key.key_;
00166 }
00167
00168 int
00169 ACE_Configuration::expand_path (const ACE_Configuration_Section_Key& key,
00170 const ACE_TString& path_in,
00171 ACE_Configuration_Section_Key& key_out,
00172 int create)
00173 {
00174
00175 ACE_Configuration_Section_Key current_section = key;
00176 ACE_Auto_Basic_Array_Ptr<ACE_TCHAR> pData (path_in.rep ());
00177 ACE_Tokenizer parser (pData.get ());
00178 parser.delimiter_replace ('\\', '\0');
00179 parser.delimiter_replace ('/', '\0');
00180
00181 for (ACE_TCHAR *temp = parser.next ();
00182 temp != 0;
00183 temp = parser.next ())
00184 {
00185
00186 if (open_section (current_section,
00187 temp,
00188 create,
00189 key_out))
00190 return -1;
00191
00192 current_section = key_out;
00193 }
00194
00195 return 0;
00196
00197 }
00198
00199
00200
00201 int
00202 ACE_Configuration::export_config (const ACE_TCHAR* filename)
00203 {
00204 ACE_Registry_ImpExp exporter (*this);
00205 return exporter.export_config (filename);
00206 }
00207
00208 int
00209 ACE_Configuration::import_config (const ACE_TCHAR* filename)
00210 {
00211 ACE_Registry_ImpExp importer (*this);
00212 return importer.import_config (filename);
00213 }
00214
00215 int
00216 ACE_Configuration::validate_name (const ACE_TCHAR* name, int allow_path)
00217 {
00218
00219 const ACE_TCHAR* reject =
00220 allow_path ? ACE_LIB_TEXT ("][") : ACE_LIB_TEXT ("\\][");
00221
00222
00223 size_t pos = ACE_OS_String::strcspn (name, reject);
00224
00225
00226 if (name[pos] != ACE_LIB_TEXT ('\0'))
00227 {
00228 errno = EINVAL;
00229 return -1;
00230 }
00231
00232
00233 if (name[0] == ACE_LIB_TEXT ('\\'))
00234 {
00235 errno = EINVAL;
00236 return -1;
00237 }
00238
00239
00240 if (pos == 0 || pos > 255)
00241 {
00242 errno = ENAMETOOLONG;
00243 return -1;
00244 }
00245
00246 return 0;
00247 }
00248
00249
00250 const ACE_Configuration_Section_Key&
00251 ACE_Configuration::root_section (void) const
00252 {
00253 return root_;
00254 }
00255
00256
00257
00258
00259
00260
00261 int ACE_Configuration::operator== (const ACE_Configuration& rhs) const
00262 {
00263 int rc = 1;
00264 int sectionIndex = 0;
00265 ACE_TString sectionName;
00266 ACE_Configuration *nonconst_this = ACE_const_cast (ACE_Configuration*, this);
00267 ACE_Configuration &nonconst_rhs = ACE_const_cast (ACE_Configuration&, rhs);
00268
00269 const ACE_Configuration_Section_Key& rhsRoot = rhs.root_section ();
00270 ACE_Configuration_Section_Key rhsSection;
00271 ACE_Configuration_Section_Key thisSection;
00272
00273
00274 while ((rc) && (!nonconst_this->enumerate_sections (this->root_,
00275 sectionIndex,
00276 sectionName)))
00277 {
00278
00279 if (nonconst_rhs.open_section (rhsRoot,
00280 sectionName.c_str (),
00281 0,
00282 rhsSection) != 0)
00283 {
00284
00285
00286 rc = 0;
00287 }
00288 else if (nonconst_this->open_section (this->root_,
00289 sectionName.c_str (),
00290 0,
00291 thisSection) != 0)
00292 {
00293
00294 rc = 0;
00295 }
00296 else
00297 {
00298
00299 int valueIndex = 0;
00300 ACE_TString valueName;
00301 VALUETYPE valueType;
00302 VALUETYPE rhsType;
00303
00304
00305 while ((rc) && nonconst_this->enumerate_values (thisSection,
00306 valueIndex,
00307 valueName,
00308 valueType))
00309 {
00310
00311 if (nonconst_rhs.find_value (rhsSection,
00312 valueName.c_str (),
00313 rhsType) != 0)
00314 {
00315
00316
00317 rc = 0;
00318 }
00319 else if (valueType != rhsType)
00320 {
00321
00322 rc = 0;
00323 }
00324 else
00325 {
00326
00327 if (valueType == STRING)
00328 {
00329 ACE_TString thisString, rhsString;
00330 if (nonconst_this->get_string_value (thisSection,
00331 valueName.c_str (),
00332 thisString) != 0)
00333 {
00334
00335 rc = 0;
00336 }
00337 else if (nonconst_rhs.get_string_value (rhsSection,
00338 valueName.c_str (),
00339 rhsString) != 0)
00340 {
00341
00342 rc = 0;
00343 }
00344 rc = thisString == rhsString;
00345 }
00346 else if (valueType == INTEGER)
00347 {
00348 u_int thisInt, rhsInt;
00349 if (nonconst_this->get_integer_value (thisSection,
00350 valueName.c_str (),
00351 thisInt) != 0)
00352 {
00353
00354 rc = 0;
00355 }
00356 else if (nonconst_rhs.get_integer_value (rhsSection,
00357 valueName.c_str (),
00358 rhsInt) != 0)
00359 {
00360
00361 rc = 0;
00362 }
00363 rc = thisInt == rhsInt;
00364 }
00365 else if (valueType == BINARY)
00366 {
00367 void* thisData = 0;
00368 void* rhsData = 0;
00369 size_t thisLength, rhsLength;
00370 if (nonconst_this->get_binary_value (thisSection,
00371 valueName.c_str (),
00372 thisData,
00373 thisLength) != 0)
00374 {
00375
00376 rc = 0;
00377 }
00378 else if (nonconst_rhs.get_binary_value (rhsSection,
00379 valueName.c_str (),
00380 rhsData,
00381 rhsLength) != 0)
00382 {
00383
00384 rc = 0;
00385 }
00386
00387 rc = thisLength == rhsLength;
00388
00389
00390 if (rc)
00391 {
00392 unsigned char* thisCharData = (unsigned char*)thisData;
00393 unsigned char* rhsCharData = (unsigned char*)rhsData;
00394
00395 for (size_t count = 0;
00396 (rc) && (count < thisLength);
00397 count++)
00398 {
00399 rc = (* (thisCharData + count) == * (rhsCharData + count));
00400 }
00401
00402 delete [] thisCharData;
00403 delete [] rhsCharData;
00404 }
00405
00406
00407 }
00408
00409
00410
00411
00412
00413 }
00414
00415 valueIndex++;
00416
00417 }
00418
00419
00420 valueIndex = 0;
00421 while ((rc) &&
00422 (!nonconst_rhs.enumerate_values (rhsSection,
00423 valueIndex,
00424 valueName,
00425 rhsType)))
00426 {
00427
00428 if (nonconst_this->find_value (thisSection,
00429 valueName.c_str (),
00430 valueType) != 0)
00431 {
00432
00433
00434 rc = 0;
00435 }
00436 valueIndex++;
00437 }
00438
00439 }
00440
00441 sectionIndex++;
00442
00443 }
00444
00445
00446
00447 sectionIndex = 0;
00448 while ((rc)
00449 && (!nonconst_rhs.enumerate_sections (rhsRoot,
00450 sectionIndex,
00451 sectionName)))
00452 {
00453
00454 if (nonconst_this->open_section (this->root_,
00455 sectionName.c_str (),
00456 0,
00457 thisSection) != 0)
00458 {
00459
00460 rc = 0;
00461 }
00462 else if (nonconst_rhs.open_section (rhsRoot,
00463 sectionName.c_str (),
00464 0,
00465 rhsSection) != 0)
00466 {
00467
00468
00469 rc = 0;
00470 }
00471 sectionIndex++;
00472 }
00473 return rc;
00474 }
00475
00476
00477
00478
00479 #if defined (WIN32)
00480
00481 static const int ACE_DEFAULT_BUFSIZE = 256;
00482
00483 ACE_Section_Key_Win32::ACE_Section_Key_Win32 (HKEY hKey)
00484 : hKey_ (hKey)
00485 {
00486 }
00487
00488 ACE_Section_Key_Win32::~ACE_Section_Key_Win32 (void)
00489 {
00490 ::RegCloseKey (hKey_);
00491 }
00492
00493
00494
00495 int
00496 ACE_Configuration_Win32Registry::operator== (const ACE_Configuration_Win32Registry &rhs) const
00497 {
00498 ACE_UNUSED_ARG (rhs);
00499 return 1;
00500 }
00501
00502 int
00503 ACE_Configuration_Win32Registry::operator!= (const ACE_Configuration_Win32Registry &rhs) const
00504 {
00505 ACE_UNUSED_ARG (rhs);
00506 return 1;
00507 }
00508
00509 ACE_Configuration_Win32Registry::ACE_Configuration_Win32Registry (HKEY hKey)
00510 {
00511 ACE_Section_Key_Win32 *temp;
00512
00513 ACE_NEW (temp, ACE_Section_Key_Win32 (hKey));
00514
00515 root_ = ACE_Configuration_Section_Key (temp);
00516 }
00517
00518
00519 ACE_Configuration_Win32Registry::~ACE_Configuration_Win32Registry (void)
00520 {
00521 }
00522
00523 int
00524 ACE_Configuration_Win32Registry::open_section (const ACE_Configuration_Section_Key& base,
00525 const ACE_TCHAR* sub_section,
00526 int create,
00527 ACE_Configuration_Section_Key& result)
00528 {
00529 if (validate_name (sub_section, 1))
00530 return -1;
00531
00532 HKEY base_key;
00533 if (load_key (base, base_key))
00534 return -1;
00535
00536 HKEY result_key;
00537 if (ACE_TEXT_RegOpenKeyEx (base_key,
00538 sub_section,
00539 0,
00540 KEY_ALL_ACCESS,
00541 &result_key) != ERROR_SUCCESS)
00542 {
00543 if (!create)
00544 return -1;
00545
00546 if (ACE_TEXT_RegCreateKeyEx (base_key,
00547 sub_section,
00548 0,
00549 0,
00550 REG_OPTION_NON_VOLATILE,
00551 KEY_ALL_ACCESS,
00552 0,
00553 &result_key,
00554 0
00555 ) != ERROR_SUCCESS)
00556 return -1;
00557 }
00558
00559 ACE_Section_Key_Win32 *temp;
00560
00561 ACE_NEW_RETURN (temp, ACE_Section_Key_Win32 (result_key), -1);
00562 result = ACE_Configuration_Section_Key (temp);
00563 return 0;
00564 }
00565
00566 int
00567 ACE_Configuration_Win32Registry::remove_section (const ACE_Configuration_Section_Key& key,
00568 const ACE_TCHAR* sub_section,
00569 int recursive)
00570 {
00571 if (validate_name (sub_section))
00572 return -1;
00573
00574 HKEY base_key;
00575 if (load_key (key, base_key))
00576 return -1;
00577
00578 if (recursive)
00579 {
00580 ACE_Configuration_Section_Key section;
00581 if (open_section (key, sub_section, 0, section))
00582 return -1;
00583
00584 HKEY sub_key;
00585 if (load_key (section, sub_key))
00586 return -1;
00587
00588 ACE_TCHAR name_buffer[ACE_DEFAULT_BUFSIZE];
00589 DWORD buffer_size = ACE_DEFAULT_BUFSIZE;
00590
00591
00592
00593
00594 while (ACE_TEXT_RegEnumKeyEx (sub_key,
00595 0,
00596 name_buffer,
00597 &buffer_size,
00598 0,
00599 0,
00600 0,
00601 0) == ERROR_SUCCESS)
00602 {
00603 remove_section (section, name_buffer, 1);
00604 buffer_size = ACE_DEFAULT_BUFSIZE;
00605 }
00606 }
00607
00608 #if (ACE_HAS_WINNT4 != 0)
00609 if (ACE_TEXT_RegDeleteKey (base_key, sub_section) != ERROR_SUCCESS)
00610 return -1;
00611 #else
00612 if (!recursive)
00613 {
00614 ACE_Configuration_Section_Key section;
00615 if (open_section (key, sub_section, 0, section))
00616 return -1;
00617
00618 HKEY sub_key;
00619 if (load_key (section, sub_key))
00620 return -1;
00621
00622 ACE_TCHAR name_buffer[ACE_DEFAULT_BUFSIZE];
00623 DWORD buffer_size = ACE_DEFAULT_BUFSIZE;
00624
00625 if (ACE_TEXT_RegEnumKeyEx (sub_key,
00626 0,
00627 name_buffer,
00628 &buffer_size,
00629 0,
00630 0,
00631 0,
00632 0) == ERROR_SUCCESS)
00633 return -1;
00634 }
00635 else if (ACE_TEXT_RegDeleteKey (base_key, sub_section) != ERROR_SUCCESS)
00636 return -1;
00637 #endif
00638
00639 return 0;
00640 }
00641
00642 int
00643 ACE_Configuration_Win32Registry::enumerate_values (const ACE_Configuration_Section_Key& key,
00644 int index,
00645 ACE_TString& name,
00646 VALUETYPE& type)
00647 {
00648 HKEY base_key;
00649 if (load_key (key, base_key))
00650 return -1;
00651
00652 ACE_TCHAR name_buffer[ACE_DEFAULT_BUFSIZE];
00653 DWORD buffer_size = ACE_DEFAULT_BUFSIZE;
00654 DWORD value_type;
00655
00656 int rc = ACE_TEXT_RegEnumValue (base_key,
00657 index,
00658 name_buffer,
00659 &buffer_size,
00660 0,
00661 &value_type,
00662 0,
00663 0);
00664 if (rc == ERROR_NO_MORE_ITEMS)
00665 return 1;
00666 else if (rc != ERROR_SUCCESS)
00667 return -1;
00668
00669 name = name_buffer;
00670
00671 switch (value_type)
00672 {
00673 case REG_BINARY:
00674 type = BINARY;
00675 break;
00676 case REG_SZ:
00677 type = STRING;
00678 break;
00679 case REG_DWORD:
00680 type = INTEGER;
00681 break;
00682 default:
00683 type = INVALID;
00684 }
00685
00686 return 0;
00687 }
00688
00689 int
00690 ACE_Configuration_Win32Registry::enumerate_sections (const ACE_Configuration_Section_Key& key,
00691 int index,
00692 ACE_TString& name)
00693 {
00694 HKEY base_key;
00695 if (load_key (key, base_key))
00696 return -1;
00697
00698 ACE_TCHAR name_buffer[ACE_DEFAULT_BUFSIZE];
00699 DWORD buffer_size = ACE_DEFAULT_BUFSIZE;
00700 int rc = ACE_TEXT_RegEnumKeyEx (base_key,
00701 index,
00702 name_buffer,
00703 &buffer_size,
00704 0,
00705 0,
00706 0,
00707 0);
00708 if (rc == ERROR_NO_MORE_ITEMS)
00709 return 1;
00710 else if (rc != ERROR_MORE_DATA && rc != ERROR_SUCCESS)
00711 return -1;
00712
00713 name = name_buffer;
00714
00715 return 0;
00716 }
00717
00718 int
00719 ACE_Configuration_Win32Registry::set_string_value (const ACE_Configuration_Section_Key& key,
00720 const ACE_TCHAR* name,
00721 const ACE_TString& value)
00722 {
00723 if (validate_name (name))
00724 return -1;
00725
00726 HKEY base_key;
00727 if (load_key (key, base_key))
00728 return -1;
00729
00730 DWORD len = ACE_static_cast (DWORD, value.length () + 1);
00731 len *= sizeof (ACE_TCHAR);
00732 if (ACE_TEXT_RegSetValueEx (base_key,
00733 name,
00734 0,
00735 REG_SZ,
00736 (BYTE *) value.fast_rep (),
00737 len)
00738 != ERROR_SUCCESS)
00739 return -1;
00740
00741 return 0;
00742 }
00743
00744 int
00745 ACE_Configuration_Win32Registry::set_integer_value (const ACE_Configuration_Section_Key& key,
00746 const ACE_TCHAR* name,
00747 u_int value)
00748 {
00749 if (validate_name (name))
00750 return -1;
00751
00752 HKEY base_key;
00753 if (load_key (key, base_key))
00754 return -1;
00755
00756 if (ACE_TEXT_RegSetValueEx (base_key,
00757 name,
00758 0,
00759 REG_DWORD,
00760 (BYTE *) &value,
00761 sizeof (value)) != ERROR_SUCCESS)
00762 return -1;
00763
00764 return 0;
00765 }
00766
00767 int
00768 ACE_Configuration_Win32Registry::set_binary_value (const ACE_Configuration_Section_Key& key,
00769 const ACE_TCHAR* name,
00770 const void* data,
00771 size_t length)
00772 {
00773 if (validate_name (name))
00774 return -1;
00775
00776 HKEY base_key;
00777 if (load_key (key, base_key))
00778 return -1;
00779
00780 if (ACE_TEXT_RegSetValueEx (base_key,
00781 name,
00782 0,
00783 REG_BINARY,
00784 (BYTE *) data,
00785 ACE_static_cast (DWORD, length))
00786 != ERROR_SUCCESS)
00787 return -1;
00788
00789 return 0;
00790 }
00791
00792 int
00793 ACE_Configuration_Win32Registry::get_string_value (const ACE_Configuration_Section_Key& key,
00794 const ACE_TCHAR* name,
00795 ACE_TString& value)
00796 {
00797 if (validate_name (name))
00798 return -1;
00799
00800 HKEY base_key;
00801 if (load_key (key, base_key))
00802 return -1;
00803
00804
00805 DWORD buffer_length = 0;
00806 DWORD type;
00807 if (ACE_TEXT_RegQueryValueEx (base_key,
00808 name,
00809 0,
00810 &type,
00811 (BYTE *) 0,
00812 &buffer_length) != ERROR_SUCCESS)
00813 return -1;
00814
00815 if (type != REG_SZ)
00816 {
00817 errno = 0; ACE_OS::last_error (ERROR_INVALID_DATATYPE);
00818 return -1;
00819 }
00820
00821 ACE_TCHAR *temp = 0;
00822 ACE_NEW_RETURN (temp,
00823 ACE_TCHAR[buffer_length],
00824 -1);
00825
00826 ACE_Auto_Basic_Array_Ptr<ACE_TCHAR> buffer (temp);
00827
00828 if (ACE_TEXT_RegQueryValueEx (base_key,
00829 name,
00830 0,
00831 &type,
00832 (BYTE *) buffer.get (),
00833 &buffer_length) != ERROR_SUCCESS)
00834 {
00835 return -1;
00836 }
00837
00838 value = buffer.get ();
00839 return 0;
00840 }
00841
00842 int
00843 ACE_Configuration_Win32Registry::get_integer_value (const ACE_Configuration_Section_Key& key,
00844 const ACE_TCHAR* name,
00845 u_int& value)
00846 {
00847 if (validate_name (name))
00848 return -1;
00849
00850 HKEY base_key;
00851 if (load_key (key, base_key))
00852 return -1;
00853
00854 DWORD length = sizeof (value);
00855 DWORD type;
00856 if (ACE_TEXT_RegQueryValueEx (base_key,
00857 name,
00858 0,
00859 &type,
00860 (BYTE *) &value,
00861 &length) != ERROR_SUCCESS)
00862 return -1;
00863
00864 if (type != REG_DWORD)
00865 {
00866 errno = 0; ACE_OS::last_error (ERROR_INVALID_DATATYPE);
00867 return -1;
00868 }
00869
00870 return 0;
00871 }
00872
00873 int
00874 ACE_Configuration_Win32Registry::get_binary_value (const ACE_Configuration_Section_Key &key,
00875 const ACE_TCHAR *name,
00876 void *&data,
00877 size_t &length)
00878 {
00879 if (validate_name (name))
00880 return -1;
00881
00882 HKEY base_key;
00883 if (load_key (key, base_key))
00884 return -1;
00885
00886
00887 DWORD buffer_length = 0;
00888 DWORD type;
00889 if (ACE_TEXT_RegQueryValueEx (base_key,
00890 name,
00891 0,
00892 &type,
00893 (BYTE *) 0,
00894 &buffer_length) != ERROR_SUCCESS)
00895 return -1;
00896
00897 if (type != REG_BINARY)
00898 {
00899 errno = 0; ACE_OS::last_error (ERROR_INVALID_DATATYPE);
00900 return -1;
00901 }
00902
00903 length = buffer_length;
00904
00905 ACE_NEW_RETURN (data, BYTE[length], -1);
00906
00907 if (ACE_TEXT_RegQueryValueEx (base_key,
00908 name,
00909 0,
00910 &type,
00911 (BYTE *) data,
00912 &buffer_length) != ERROR_SUCCESS)
00913 {
00914 delete [] (BYTE *) data;
00915 data = 0;
00916 return -1;
00917 }
00918
00919 return 0;
00920 }
00921
00922 int
00923 ACE_Configuration_Win32Registry::find_value (const ACE_Configuration_Section_Key& key,
00924 const ACE_TCHAR* name,
00925 VALUETYPE& type_out)
00926 {
00927 if (validate_name (name))
00928 return -1;
00929
00930 HKEY base_key;
00931 if (load_key (key, base_key))
00932 return -1;
00933
00934 DWORD buffer_length=0;
00935 DWORD type;
00936 int result=ACE_TEXT_RegQueryValueEx (base_key,
00937 name,
00938 0,
00939 &type,
00940 0,
00941 &buffer_length);
00942 if (result != ERROR_SUCCESS)
00943 return -1;
00944
00945 switch (type)
00946 {
00947 case REG_SZ:
00948 type_out = STRING;
00949 break;
00950 case REG_DWORD:
00951 type_out = INTEGER;
00952 break;
00953 case REG_BINARY:
00954 type_out = BINARY;
00955 break;
00956 default:
00957 return -1;
00958 }
00959
00960 return 0;
00961 }
00962
00963 int
00964 ACE_Configuration_Win32Registry::remove_value (const ACE_Configuration_Section_Key& key,
00965 const ACE_TCHAR* name)
00966 {
00967 if (validate_name (name))
00968 return -1;
00969
00970 HKEY base_key;
00971 if (load_key (key, base_key))
00972 return -1;
00973
00974 if (ACE_TEXT_RegDeleteValue (base_key, name) != ERROR_SUCCESS)
00975 return -1;
00976
00977 return 0;
00978 }
00979
00980
00981 int
00982 ACE_Configuration_Win32Registry::load_key (const ACE_Configuration_Section_Key& key,
00983 HKEY& hKey)
00984 {
00985 ACE_Section_Key_Win32* pKey = ACE_dynamic_cast (ACE_Section_Key_Win32*,
00986 get_internal_key (key));
00987 if (!pKey)
00988 return -1;
00989
00990 hKey = pKey->hKey_;
00991 return 0;
00992 }
00993
00994 HKEY
00995 ACE_Configuration_Win32Registry::resolve_key (HKEY hKey,
00996 const ACE_TCHAR* path,
00997 int create)
00998 {
00999 HKEY result = 0;
01000
01001 #if defined (ACE_HAS_WINCE)
01002 if (::RegOpenKeyEx (hKey, 0, 0, 0, &result) != ERROR_SUCCESS)
01003 #else
01004 if (::RegOpenKey (hKey, 0, &result) != ERROR_SUCCESS)
01005 #endif // ACE_HAS_WINCE
01006 return 0;
01007
01008
01009 ACE_TCHAR *temp_path = 0;
01010 ACE_NEW_RETURN (temp_path,
01011 ACE_TCHAR[ACE_OS::strlen (path) + 1],
01012 0);
01013 ACE_Auto_Basic_Array_Ptr<ACE_TCHAR> pData (temp_path);
01014 ACE_OS::strcpy (pData.get (), path);
01015 ACE_Tokenizer parser (pData.get ());
01016 parser.delimiter_replace ('\\', '\0');
01017 parser.delimiter_replace ('/', '\0');
01018
01019 for (ACE_TCHAR *temp = parser.next ();
01020 temp != 0;
01021 temp = parser.next ())
01022 {
01023
01024 HKEY subkey;
01025
01026 #if defined (ACE_HAS_WINCE)
01027 if (ACE_TEXT_RegOpenKeyEx (result,
01028 temp,
01029 0,
01030 0,
01031 &subkey) != ERROR_SUCCESS)
01032 #else
01033 if (ACE_TEXT_RegOpenKey (result,
01034 temp,
01035 &subkey) != ERROR_SUCCESS)
01036 #endif // ACE_HAS_WINCE
01037 {
01038
01039 if (!create || ACE_TEXT_RegCreateKeyEx (result,
01040 temp,
01041 0,
01042 0,
01043 0,
01044 KEY_ALL_ACCESS,
01045 0,
01046 &subkey,
01047 #if defined (__MINGW32__)
01048 (PDWORD) 0
01049 #else
01050 0
01051 #endif
01052 ) != ERROR_SUCCESS)
01053 {
01054
01055 ::RegCloseKey (result);
01056 return 0;
01057 }
01058 }
01059
01060 ::RegCloseKey (result);
01061 result = subkey;
01062 }
01063
01064 return result;
01065 }
01066
01067 #endif
01068
01069
01070
01071 ACE_Configuration_Value_IntId::ACE_Configuration_Value_IntId (void)
01072 : type_ (ACE_Configuration::INVALID),
01073 length_ (0)
01074 {
01075 this->data_.ptr_ = 0;
01076 }
01077
01078 ACE_Configuration_Value_IntId::ACE_Configuration_Value_IntId (ACE_TCHAR* string)
01079 : type_ (ACE_Configuration::STRING),
01080 length_ (0)
01081 {
01082 this->data_.ptr_ = string;
01083 }
01084
01085 ACE_Configuration_Value_IntId::ACE_Configuration_Value_IntId (u_int integer)
01086 : type_ (ACE_Configuration::INTEGER),
01087 length_ (0)
01088 {
01089 this->data_.int_ = integer;
01090 }
01091
01092 ACE_Configuration_Value_IntId::ACE_Configuration_Value_IntId (void* data, size_t length)
01093 : type_ (ACE_Configuration::BINARY),
01094 length_ (length)
01095 {
01096 this->data_.ptr_ = data;
01097 }
01098
01099 ACE_Configuration_Value_IntId::ACE_Configuration_Value_IntId (const ACE_Configuration_Value_IntId& rhs)
01100 : type_ (rhs.type_),
01101 data_ (rhs.data_),
01102 length_ (rhs.length_)
01103 {
01104 }
01105
01106 ACE_Configuration_Value_IntId::~ACE_Configuration_Value_IntId (void)
01107 {
01108 }
01109
01110 ACE_Configuration_Value_IntId& ACE_Configuration_Value_IntId::operator= (const ACE_Configuration_Value_IntId& rhs)
01111 {
01112 if (this != &rhs)
01113 {
01114 type_ = rhs.type_;
01115 data_ = rhs.data_;
01116 length_ = rhs.length_;
01117 }
01118 return *this;
01119 }
01120
01121 void
01122 ACE_Configuration_Value_IntId::free (ACE_Allocator *alloc)
01123 {
01124 if (this->type_ == ACE_Configuration::STRING
01125 || this->type_ == ACE_Configuration::BINARY)
01126 alloc->free (data_.ptr_);
01127
01128 }
01129
01130 ACE_Configuration_ExtId::ACE_Configuration_ExtId (void)
01131 : name_ (0)
01132 {
01133 }
01134
01135 ACE_Configuration_ExtId::ACE_Configuration_ExtId (const ACE_TCHAR* name)
01136 : name_ (name)
01137 {
01138 }
01139
01140 ACE_Configuration_ExtId::ACE_Configuration_ExtId (const ACE_Configuration_ExtId& rhs)
01141 : name_ (rhs.name_)
01142 {
01143 }
01144
01145 ACE_Configuration_ExtId::~ACE_Configuration_ExtId (void)
01146 {
01147 }
01148
01149 ACE_Configuration_ExtId& ACE_Configuration_ExtId::operator= (const ACE_Configuration_ExtId& rhs)
01150 {
01151 if (this != &rhs)
01152 name_ = rhs.name_;
01153
01154 return *this;
01155 }
01156
01157 int
01158 ACE_Configuration_ExtId::operator == (const ACE_Configuration_ExtId& rhs) const
01159 {
01160 return (ACE_OS::strcmp (name_, rhs.name_) == 0);
01161 }
01162
01163 int
01164 ACE_Configuration_ExtId::operator != (const ACE_Configuration_ExtId& rhs) const
01165 {
01166 return (ACE_OS::strcmp (name_, rhs.name_) != 0);
01167 }
01168
01169 u_long
01170 ACE_Configuration_ExtId::hash (void) const
01171 {
01172 ACE_TString temp (name_);
01173 return temp.hash ();
01174 }
01175
01176 const ACE_TCHAR*
01177 ACE_Configuration_ExtId::name (void)
01178 {
01179 return name_;
01180 }
01181
01182 void
01183 ACE_Configuration_ExtId::free (ACE_Allocator *alloc)
01184 {
01185 alloc->free ((void *) (name_));
01186 }
01187
01188
01189
01190 ACE_Configuration_Section_IntId::ACE_Configuration_Section_IntId (void)
01191 : value_hash_map_ (0),
01192 section_hash_map_ (0)
01193 {
01194 }
01195
01196 ACE_Configuration_Section_IntId::ACE_Configuration_Section_IntId (VALUE_MAP* value_hash_map, SUBSECTION_MAP* section_hash_map)
01197 : value_hash_map_ (value_hash_map),
01198 section_hash_map_ (section_hash_map)
01199 {
01200 }
01201
01202 ACE_Configuration_Section_IntId::ACE_Configuration_Section_IntId (const ACE_Configuration_Section_IntId& rhs)
01203 : value_hash_map_ (rhs.value_hash_map_),
01204 section_hash_map_ (rhs.section_hash_map_)
01205 {
01206
01207 }
01208
01209 ACE_Configuration_Section_IntId::~ACE_Configuration_Section_IntId ()
01210 {
01211 }
01212
01213 ACE_Configuration_Section_IntId&
01214 ACE_Configuration_Section_IntId::operator= (const ACE_Configuration_Section_IntId& rhs)
01215 {
01216 if (this != &rhs)
01217 {
01218 value_hash_map_ = rhs.value_hash_map_;
01219 section_hash_map_ = rhs.section_hash_map_;
01220 }
01221 return *this;
01222 }
01223
01224 void
01225 ACE_Configuration_Section_IntId::free (ACE_Allocator *alloc)
01226 {
01227 alloc->free ((void *) (value_hash_map_));
01228 alloc->free ((void *) (section_hash_map_));
01229 }
01230
01231 ACE_Configuration_Section_Key_Heap::ACE_Configuration_Section_Key_Heap (const ACE_TCHAR* path)
01232 : path_ (0),
01233 value_iter_ (0),
01234 section_iter_ (0)
01235 {
01236 path_ = ACE_OS::strdup (path);
01237 }
01238
01239 ACE_Configuration_Section_Key_Heap::~ACE_Configuration_Section_Key_Heap ()
01240 {
01241 delete value_iter_;
01242 delete section_iter_;
01243 ACE_OS::free (path_);
01244 }
01245
01246
01247
01248 ACE_Configuration_Heap::ACE_Configuration_Heap (void)
01249 : allocator_ (0),
01250 index_ (0),
01251 default_map_size_ (0)
01252 {
01253 ACE_Configuration_Section_Key_Heap *temp = 0;
01254
01255 ACE_NEW (temp, ACE_Configuration_Section_Key_Heap (ACE_LIB_TEXT ("")));
01256 root_ = ACE_Configuration_Section_Key (temp);
01257 }
01258
01259 ACE_Configuration_Heap::~ACE_Configuration_Heap (void)
01260 {
01261 if (allocator_)
01262 allocator_->sync ();
01263
01264 delete allocator_;
01265 }
01266
01267 int
01268 ACE_Configuration_Heap::open (int default_map_size)
01269 {
01270 default_map_size_ = default_map_size;
01271
01272
01273
01274 ACE_NEW_RETURN (this->allocator_,
01275 HEAP_ALLOCATOR (),
01276 -1);
01277 return create_index ();
01278 }
01279
01280
01281 int
01282 ACE_Configuration_Heap::open (const ACE_TCHAR* file_name,
01283 void* base_address,
01284 int default_map_size)
01285 {
01286 default_map_size_ = default_map_size;
01287
01288
01289 if (ACE_OS::strlen (file_name) >= MAXNAMELEN + MAXPATHLEN)
01290 {
01291 errno = ENAMETOOLONG;
01292 return -1;
01293 }
01294
01295 #if !defined (CHORUS)
01296 ACE_MMAP_Memory_Pool::OPTIONS options (base_address);
01297 #else
01298
01299 ACE_MMAP_Memory_Pool::OPTIONS options (0,
01300 0,
01301 0,
01302 ACE_CHORUS_LOCAL_NAME_SPACE_T_SIZE);
01303 #endif
01304
01305
01306
01307 ACE_NEW_RETURN (this->allocator_,
01308 PERSISTENT_ALLOCATOR (file_name,
01309 file_name,
01310 &options),
01311 -1);
01312
01313 #if !defined (ACE_LACKS_ACCESS)
01314
01315 if (ACE_OS::access (file_name, F_OK) != 0)
01316 ACE_ERROR_RETURN ((LM_ERROR,
01317 ACE_LIB_TEXT ("create_index\n")),
01318 -1);
01319 #endif
01320
01321 return create_index ();
01322 }
01323
01324 int
01325 ACE_Configuration_Heap::create_index (void)
01326 {
01327 void *section_index = 0;
01328
01329
01330
01331 if (this->allocator_->find (ACE_CONFIG_SECTION_INDEX, section_index) == 0)
01332 this->index_ = (SECTION_MAP *) section_index;
01333
01334
01335
01336 else
01337 {
01338 size_t index_size = sizeof (SECTION_MAP);
01339 section_index = this->allocator_->malloc (index_size);
01340
01341 if (section_index == 0
01342 || create_index_helper (section_index) == -1
01343 || this->allocator_->bind (ACE_CONFIG_SECTION_INDEX,
01344 section_index) == -1)
01345 {
01346
01347 ACE_ERROR ((LM_ERROR,
01348 ACE_LIB_TEXT ("create_index\n")));
01349 this->allocator_->remove ();
01350 return -1;
01351 }
01352
01353 return new_section (ACE_LIB_TEXT (""), root_);
01354 }
01355 return 0;
01356 }
01357
01358 int
01359 ACE_Configuration_Heap::create_index_helper (void *buffer)
01360 {
01361 ACE_ASSERT (this->allocator_);
01362 this->index_ = new (buffer) SECTION_MAP (this->allocator_);
01363 return 0;
01364 }
01365
01366 int
01367 ACE_Configuration_Heap::load_key (const ACE_Configuration_Section_Key& key,
01368 ACE_TString& name)
01369 {
01370 ACE_ASSERT (this->allocator_);
01371 ACE_Configuration_Section_Key_Heap* pKey =
01372 ACE_dynamic_cast (ACE_Configuration_Section_Key_Heap*,
01373 get_internal_key (key));
01374 if (!pKey)
01375 return -1;
01376
01377 name = pKey->path_;
01378 return 0;
01379 }
01380
01381
01382 int
01383 ACE_Configuration_Heap::add_section (const ACE_Configuration_Section_Key& base,
01384 const ACE_TCHAR* sub_section,
01385 ACE_Configuration_Section_Key& result)
01386 {
01387 ACE_ASSERT (this->allocator_);
01388 ACE_TString section;
01389 if (load_key (base, section))
01390 return -1;
01391
01392
01393 ACE_Configuration_ExtId ExtId (section.fast_rep ());
01394 ACE_Configuration_Section_IntId IntId;
01395 if (index_->find (ExtId, IntId, allocator_))
01396 return -1;
01397
01398
01399 ACE_Configuration_ExtId SubSectionExtId (sub_section);
01400 int ignored = 0;
01401
01402 if (!IntId.section_hash_map_->find (SubSectionExtId, ignored, allocator_))
01403 {
01404
01405 errno = EEXIST;
01406 return -1;
01407 }
01408
01409
01410
01411 if (section.length ())
01412 section += ACE_LIB_TEXT ("\\");
01413
01414 section += sub_section;
01415
01416
01417 ACE_TCHAR* pers_name = (ACE_TCHAR *) allocator_->malloc ((ACE_OS::strlen (sub_section) + 1) * sizeof (ACE_TCHAR));
01418 ACE_OS::strcpy (pers_name, sub_section);
01419 ACE_Configuration_ExtId SSExtId (pers_name);
01420 if (IntId.section_hash_map_->bind (SSExtId, ignored, allocator_))
01421 {
01422 allocator_->free (pers_name);
01423 return -1;
01424 }
01425 return (new_section (section, result));
01426 }
01427
01428 int
01429 ACE_Configuration_Heap::new_section (const ACE_TString& section,
01430 ACE_Configuration_Section_Key& result)
01431 {
01432 ACE_ASSERT (this->allocator_);
01433
01434
01435
01436 size_t section_len = section.length () + 1;
01437 ACE_TCHAR *ptr = (ACE_TCHAR*) this->allocator_->malloc (section_len * sizeof (ACE_TCHAR));
01438
01439 int return_value = -1;
01440
01441 if (ptr == 0)
01442 return -1;
01443 else
01444 {
01445
01446 ACE_OS::strcpy (ptr, section.fast_rep ());
01447
01448 void *value_hash_map = 0;
01449 size_t map_size = sizeof (VALUE_MAP);
01450 value_hash_map = this->allocator_->malloc (map_size);
01451
01452
01453 if (value_hash_map == 0)
01454 return -1;
01455
01456
01457 if (value_open_helper (default_map_size_, value_hash_map ) == -1)
01458 {
01459 this->allocator_->free (value_hash_map );
01460 return -1;
01461 }
01462
01463
01464 void* section_hash_map = 0;
01465 map_size = sizeof (SUBSECTION_MAP);
01466 section_hash_map = this->allocator_->malloc (map_size);
01467
01468
01469 if (section_hash_map == 0)
01470 return -1;
01471
01472
01473 if (section_open_helper (default_map_size_, section_hash_map) == -1)
01474 {
01475 this->allocator_->free (value_hash_map );
01476 this->allocator_->free (section_hash_map);
01477 return -1;
01478 }
01479
01480 ACE_Configuration_ExtId name (ptr);
01481 ACE_Configuration_Section_IntId entry ((VALUE_MAP*) value_hash_map ,
01482 (SUBSECTION_MAP*) section_hash_map);
01483
01484
01485
01486 return_value = this->index_->bind (name, entry, this->allocator_);
01487
01488 if (return_value == 1)
01489 {
01490
01491
01492 this->allocator_->free ((void *) ptr);
01493 return return_value;
01494 }
01495
01496 if (return_value == -1)
01497
01498 this->allocator_->free ((void *) ptr);
01499 else
01500
01501
01502
01503 this->allocator_->sync (ptr, section_len);
01504
01505 }
01506
01507
01508 ACE_Configuration_Section_Key_Heap *temp;
01509 ACE_NEW_RETURN (temp,
01510 ACE_Configuration_Section_Key_Heap (section.fast_rep ()),
01511 -1);
01512 result = ACE_Configuration_Section_Key (temp);
01513 return return_value;
01514 }
01515
01516 int
01517 ACE_Configuration_Heap::value_open_helper (size_t hash_table_size,
01518 void *buffer)
01519 {
01520 ACE_ASSERT (this->allocator_);
01521 new (buffer) VALUE_MAP (hash_table_size, this->allocator_);
01522 return 0;
01523 }
01524
01525 int
01526 ACE_Configuration_Heap::section_open_helper (size_t hash_table_size,
01527 void *buffer)
01528 {
01529 ACE_ASSERT (this->allocator_);
01530 new (buffer) SUBSECTION_MAP (hash_table_size, this->allocator_);
01531 return 0;
01532 }
01533
01534 int
01535 ACE_Configuration_Heap::open_section (const ACE_Configuration_Section_Key& base,
01536 const ACE_TCHAR* sub_section,
01537 int create,
01538 ACE_Configuration_Section_Key& result)
01539 {
01540 ACE_ASSERT (this->allocator_);
01541 if (validate_name (sub_section, 1))
01542 return -1;
01543
01544 result = base;
01545
01546 for (const ACE_TCHAR* separator;
01547 (separator = ACE_OS_String::strchr (sub_section, ACE_TEXT ('\\'))) != 0;
01548 )
01549 {
01550 ACE_TString simple_section (sub_section, separator - sub_section);
01551 int ret_val =
01552 open_simple_section (result, simple_section.c_str (), create, result);
01553 if (ret_val)
01554 return ret_val;
01555 sub_section = separator + 1;
01556 }
01557
01558 return open_simple_section (result, sub_section, create, result);
01559 }
01560
01561 int
01562 ACE_Configuration_Heap::open_simple_section (const ACE_Configuration_Section_Key& base,
01563 const ACE_TCHAR* sub_section,
01564 int create,
01565 ACE_Configuration_Section_Key& result)
01566 {
01567 ACE_TString section;
01568 if (load_key (base, section))
01569 return -1;
01570
01571
01572 if (section.length ())
01573 section += ACE_LIB_TEXT ("\\");
01574
01575 section += sub_section;
01576
01577
01578 ACE_Configuration_ExtId ExtId (section.fast_rep ());
01579 ACE_Configuration_Section_IntId IntId;
01580 if (index_->find (ExtId, IntId, allocator_))
01581 {
01582 if (!create)
01583 {
01584 errno = ENOENT;
01585 return -1;
01586 }
01587 return add_section (base, sub_section, result);
01588 }
01589
01590 ACE_Configuration_Section_Key_Heap *temp;
01591
01592 ACE_NEW_RETURN (temp,
01593 ACE_Configuration_Section_Key_Heap (section.fast_rep ()),
01594 -1);
01595 result = ACE_Configuration_Section_Key (temp);
01596
01597 return 0;
01598 }
01599
01600 int
01601 ACE_Configuration_Heap::remove_section (const ACE_Configuration_Section_Key& key,
01602 const ACE_TCHAR* sub_section,
01603 int recursive)
01604 {
01605 ACE_ASSERT (this->allocator_);
01606 if (validate_name (sub_section))
01607 return -1;
01608
01609 ACE_TString section;
01610 if (load_key (key, section))
01611 return -1;
01612
01613
01614 ACE_Configuration_ExtId ParentExtId (section.fast_rep ());
01615 ACE_Configuration_Section_IntId ParentIntId;
01616 if (index_->find (ParentExtId, ParentIntId, allocator_))
01617 return -1;
01618
01619
01620 if (section.length ())
01621 section += ACE_LIB_TEXT ("\\");
01622
01623 section += sub_section;
01624 ACE_Configuration_ExtId SectionExtId (section.fast_rep ());
01625 SECTION_ENTRY* section_entry;
01626 SECTION_HASH* hashmap = index_;
01627 if (hashmap->find (SectionExtId, section_entry))
01628 return -1;
01629
01630 if (recursive)
01631 {
01632 ACE_Configuration_Section_Key section;
01633 if (open_section (key, sub_section, 0, section))
01634 return -1;
01635
01636 int index = 0;
01637 ACE_TString name;
01638 while (!enumerate_sections (section, index, name))
01639 {
01640 if (remove_section (section, name.fast_rep (), 1))
01641 return -1;
01642
01643 index++;
01644 }
01645 }
01646
01647
01648 if (section_entry->int_id_.section_hash_map_->current_size ())
01649 {
01650 errno = ENOTEMPTY;
01651 return -1;
01652 }
01653
01654
01655 ACE_Configuration_ExtId SubSExtId (sub_section);
01656 SUBSECTION_ENTRY* subsection_entry;
01657 if (((SUBSECTION_HASH*)ParentIntId.section_hash_map_)->
01658 find (SubSExtId, subsection_entry))
01659 return -1;
01660
01661 if (ParentIntId.section_hash_map_->unbind (SubSExtId, allocator_))
01662 return -1;
01663
01664 subsection_entry->ext_id_.free (allocator_);
01665
01666
01667 ACE_Configuration_ExtId ExtIdToFree (section_entry->ext_id_);
01668 ACE_Configuration_Section_IntId IntIdToFree (section_entry->int_id_);
01669
01670
01671 VALUE_HASH* value_hash_map = section_entry->int_id_.value_hash_map_;
01672 VALUE_HASH::ITERATOR value_iter = value_hash_map->begin ();
01673 while (!value_iter.done ())
01674 {
01675 VALUE_ENTRY* value_entry;
01676 if (!value_iter.next (value_entry))
01677 return 1;
01678
01679 value_entry->ext_id_.free (allocator_);
01680 value_entry->int_id_.free (allocator_);
01681
01682 value_iter.advance ();
01683 }
01684
01685
01686 if (index_->unbind (SectionExtId, allocator_))
01687 return -1;
01688
01689 value_hash_map->close ();
01690 section_entry->int_id_.section_hash_map_->close (allocator_);
01691
01692
01693 ExtIdToFree.free (allocator_);
01694 IntIdToFree.free (allocator_);
01695
01696 return 0;
01697 }
01698
01699 int
01700 ACE_Configuration_Heap::enumerate_values (const ACE_Configuration_Section_Key& key,
01701 int index,
01702 ACE_TString& name,
01703 VALUETYPE& type)
01704 {
01705 ACE_ASSERT (this->allocator_);
01706 ACE_Configuration_Section_Key_Heap* pKey =
01707 ACE_dynamic_cast (ACE_Configuration_Section_Key_Heap*,
01708 get_internal_key (key));
01709 if (!pKey)
01710 return -1;
01711
01712 name = pKey->path_;
01713
01714
01715 ACE_Configuration_ExtId ExtId (pKey->path_);
01716 ACE_Configuration_Section_IntId IntId;
01717 if (index_->find (ExtId, IntId, allocator_))
01718 return -1;
01719
01720
01721 if (index == 0)
01722 {
01723 ACE_Hash_Map_Manager_Ex<ACE_Configuration_ExtId ,
01724 ACE_Configuration_Value_IntId,
01725 ACE_Hash<ACE_Configuration_ExtId>,
01726 ACE_Equal_To<ACE_Configuration_ExtId>,
01727 ACE_Null_Mutex>* hash_map = IntId.value_hash_map_;
01728 delete pKey->value_iter_;
01729
01730 ACE_NEW_RETURN (pKey->value_iter_,
01731 VALUE_HASH::ITERATOR (hash_map->begin ()),
01732 -1);
01733 }
01734
01735
01736 ACE_Hash_Map_Entry<ACE_Configuration_ExtId, ACE_Configuration_Value_IntId>* entry;
01737
01738 if (!pKey->value_iter_->next (entry))
01739 return 1;
01740
01741
01742 name = entry->ext_id_.name_;
01743 type = entry->int_id_.type_;
01744 pKey->value_iter_->advance ();
01745
01746 return 0;
01747 }
01748
01749 int
01750 ACE_Configuration_Heap::enumerate_sections (const ACE_Configuration_Section_Key& key,
01751 int index,
01752 ACE_TString& name)
01753 {
01754 ACE_ASSERT (this->allocator_);
01755
01756 ACE_Configuration_Section_Key_Heap* pKey =
01757 ACE_dynamic_cast (ACE_Configuration_Section_Key_Heap*,
01758 get_internal_key (key));
01759 if (!pKey)
01760 return -1;
01761
01762
01763 ACE_Configuration_ExtId ExtId (pKey->path_);
01764 ACE_Configuration_Section_IntId IntId;
01765 if (index_->find (ExtId, IntId, allocator_))
01766 return -1;
01767
01768
01769 if (index == 0)
01770 {
01771 if (pKey->section_iter_)
01772 delete pKey->section_iter_;
01773
01774 ACE_NEW_RETURN (pKey->section_iter_,
01775 SUBSECTION_HASH::ITERATOR (IntId.section_hash_map_->begin ()),
01776 -1);
01777 }
01778
01779
01780 ACE_Hash_Map_Entry<ACE_Configuration_ExtId, int>* entry;
01781 if (!pKey->section_iter_->next (entry))
01782 return 1;
01783
01784
01785 pKey->section_iter_->advance ();
01786 name = entry->ext_id_.name_;
01787
01788 return 0;
01789 }
01790
01791 int
01792 ACE_Configuration_Heap::set_string_value (const ACE_Configuration_Section_Key& key,
01793 const ACE_TCHAR* name,
01794 const ACE_TString& value)
01795 {
01796 ACE_ASSERT (this->allocator_);
01797 if (validate_name (name))
01798 return -1;
01799
01800 ACE_TString section;
01801 if (load_key (key, section))
01802 return -1;
01803
01804 ACE_Configuration_ExtId section_ext (section.fast_rep ());
01805 ACE_Configuration_Section_IntId section_int;
01806 if (index_->find (section_ext, section_int, allocator_))
01807 return -1;
01808
01809
01810 VALUE_ENTRY* entry;
01811 ACE_Configuration_ExtId item_name (name);
01812 if (section_int.value_hash_map_->VALUE_HASH::find (item_name, entry) == 0)
01813 {
01814
01815
01816 entry->int_id_.free (allocator_);
01817
01818 ACE_TCHAR* pers_value =
01819 (ACE_TCHAR *) allocator_->malloc ((value.length () + 1) * sizeof (ACE_TCHAR));
01820 ACE_OS::strcpy (pers_value, value.fast_rep ());
01821 ACE_Configuration_Value_IntId new_value_int (pers_value);
01822 entry->int_id_ = new_value_int;
01823 }
01824 else
01825 {
01826
01827 ACE_TCHAR* pers_name =
01828 (ACE_TCHAR *) allocator_->malloc ((ACE_OS::strlen (name) + 1) * sizeof (ACE_TCHAR));
01829 ACE_OS::strcpy (pers_name, name);
01830 ACE_TCHAR* pers_value =
01831 (ACE_TCHAR *) allocator_->malloc ((value.length () + 1) * sizeof (ACE_TCHAR));
01832 ACE_OS::strcpy (pers_value, value.fast_rep ());
01833 ACE_Configuration_ExtId item_name (pers_name);
01834 ACE_Configuration_Value_IntId item_value (pers_value);
01835 if (section_int.value_hash_map_->bind (item_name, item_value, allocator_))
01836 {
01837 allocator_->free (pers_value);
01838 allocator_->free (pers_name);
01839 return -1;
01840 }
01841 return 0;
01842 }
01843
01844 return 0;
01845 }
01846
01847 int
01848 ACE_Configuration_Heap::set_integer_value (const ACE_Configuration_Section_Key& key,
01849 const ACE_TCHAR* name,
01850 u_int value)
01851 {
01852 ACE_ASSERT (this->allocator_);
01853 if (validate_name (name))
01854 return -1;
01855
01856
01857 ACE_TString section;
01858 if (load_key (key, section))
01859 return -1;
01860
01861
01862 ACE_Configuration_ExtId section_ext (section.fast_rep ());
01863 ACE_Configuration_Section_IntId section_int;
01864 if (index_->find (section_ext, section_int, allocator_))
01865 return -1;
01866
01867
01868 VALUE_ENTRY* entry;
01869 ACE_Configuration_ExtId item_name (name);
01870 if (section_int.value_hash_map_->VALUE_HASH::find (item_name, entry) == 0)
01871 {
01872
01873 ACE_Configuration_Value_IntId new_value_int (value);
01874 entry->int_id_ = new_value_int;
01875 }
01876 else
01877 {
01878
01879 ACE_TCHAR* pers_name =
01880 (ACE_TCHAR *) allocator_->malloc ((ACE_OS::strlen (name) + 1) * sizeof (ACE_TCHAR));
01881 ACE_OS::strcpy (pers_name, name);
01882 ACE_Configuration_ExtId item_name (pers_name);
01883 ACE_Configuration_Value_IntId item_value (value);
01884 if (section_int.value_hash_map_->bind (item_name, item_value, allocator_))
01885 {
01886 allocator_->free (pers_name);
01887 return -1;
01888 }
01889 return 0;
01890 }
01891
01892 return 0;
01893 }
01894
01895 int
01896 ACE_Configuration_Heap::set_binary_value (const ACE_Configuration_Section_Key& key,
01897 const ACE_TCHAR* name,
01898 const void* data,
01899 size_t length)
01900 {
01901 ACE_ASSERT (this->allocator_);
01902 if (validate_name (name))
01903 return -1;
01904
01905
01906 ACE_TString section;
01907 if (load_key (key, section))
01908 return -1;
01909
01910
01911 ACE_Configuration_ExtId section_ext (section.fast_rep ());
01912 ACE_Configuration_Section_IntId section_int;
01913 if (index_->find (section_ext, section_int, allocator_))
01914 return -1;
01915
01916
01917 VALUE_ENTRY* entry;
01918 ACE_Configuration_ExtId item_name (name);
01919 if (section_int.value_hash_map_->VALUE_HASH::find (item_name, entry) == 0)
01920 {
01921
01922
01923 entry->int_id_.free (allocator_);
01924
01925 ACE_TCHAR* pers_value = (ACE_TCHAR *) allocator_->malloc (length);
01926 ACE_OS::memcpy (pers_value, data, length);
01927 ACE_Configuration_Value_IntId new_value_int (pers_value, length);
01928 entry->int_id_ = new_value_int;
01929 }
01930 else
01931 {
01932
01933 ACE_TCHAR* pers_name =
01934 (ACE_TCHAR *) allocator_->malloc ((ACE_OS::strlen (name) + 1) * sizeof (ACE_TCHAR));
01935 ACE_OS::strcpy (pers_name, name);
01936 ACE_TCHAR* pers_value = (ACE_TCHAR *) allocator_->malloc (length);
01937 ACE_OS::memcpy (pers_value, data, length);
01938 ACE_Configuration_ExtId item_name (pers_name);
01939 ACE_Configuration_Value_IntId item_value (pers_value, length);
01940 if (section_int.value_hash_map_->bind (item_name, item_value, allocator_))
01941 {
01942 allocator_->free (pers_value);
01943 allocator_->free (pers_name);
01944 return -1;
01945 }
01946 return 0;
01947 }
01948
01949
01950
01951
01952
01953
01954
01955
01956
01957
01958
01959
01960
01961
01962
01963
01964
01965
01966
01967
01968
01969
01970
01971
01972
01973
01974
01975
01976
01977
01978
01979
01980
01981
01982
01983
01984
01985
01986
01987
01988 return 0;
01989 }
01990
01991 int
01992 ACE_Configuration_Heap::get_string_value (const ACE_Configuration_Section_Key& key,
01993 const ACE_TCHAR* name,
01994 ACE_TString& value)
01995 {
01996 ACE_ASSERT (this->allocator_);
01997 if (validate_name (name))
01998 return -1;
01999
02000
02001 ACE_TString section;
02002 if (load_key (key, section))
02003 return -1;
02004
02005
02006 ACE_Configuration_ExtId ExtId (section.fast_rep ());
02007 ACE_Configuration_Section_IntId IntId;
02008 if (index_->find (ExtId, IntId, allocator_))
02009 return -1;
02010
02011
02012 ACE_Configuration_ExtId VExtId (name);
02013 ACE_Configuration_Value_IntId VIntId;
02014 if (IntId.value_hash_map_->find (VExtId, VIntId, allocator_))
02015 return -1;
02016
02017
02018 if (VIntId.type_ != ACE_Configuration::STRING)
02019 {
02020 errno = ENOENT;
02021 return -1;
02022 }
02023
02024
02025 value = ACE_static_cast (ACE_TCHAR*, VIntId.data_.ptr_);
02026 return 0;
02027 }
02028
02029 int
02030 ACE_Configuration_Heap::get_integer_value (const ACE_Configuration_Section_Key& key,
02031 const ACE_TCHAR* name,
02032 u_int& value)
02033 {
02034 ACE_ASSERT (this->allocator_);
02035 if (validate_name (name))
02036 return -1;
02037
02038
02039 ACE_TString section;
02040 if (load_key (key, section))
02041 return -1;
02042
02043
02044 ACE_Configuration_ExtId ExtId (section.fast_rep ());
02045 ACE_Configuration_Section_IntId IntId;
02046 if (index_->find (ExtId, IntId, allocator_))
02047 return -1;
02048
02049
02050
02051 ACE_Configuration_ExtId VExtId (name);
02052 ACE_Configuration_Value_IntId VIntId;
02053 if (IntId.value_hash_map_->find (VExtId, VIntId, allocator_))
02054 return -1;
02055
02056
02057 if (VIntId.type_ != ACE_Configuration::INTEGER)
02058 {
02059 errno = ENOENT;
02060 return -1;
02061 }
02062
02063
02064 value = VIntId.data_.int_;
02065 return 0;
02066 }
02067
02068 int
02069 ACE_Configuration_Heap::get_binary_value (const ACE_Configuration_Section_Key& key,
02070 const ACE_TCHAR* name,
02071 void*& data,
02072 size_t& length)
02073 {
02074 ACE_ASSERT (this->allocator_);
02075 if (validate_name (name))
02076 return -1;
02077
02078
02079 ACE_TString section;
02080 if (load_key (key, section))
02081 return -1;
02082
02083
02084 ACE_Configuration_ExtId ExtId (section.fast_rep ());
02085 ACE_Configuration_Section_IntId IntId;
02086 if (index_->find (ExtId, IntId, allocator_))
02087 return -1;
02088
02089 ACE_Configuration_ExtId VExtId (name);
02090 ACE_Configuration_Value_IntId VIntId;
02091
02092 if (IntId.value_hash_map_->find (VExtId, VIntId, allocator_))
02093 return -1;
02094
02095
02096 if (VIntId.type_ != ACE_Configuration::BINARY)
02097 {
02098 errno = ENOENT;
02099 return -1;
02100 }
02101
02102
02103 ACE_NEW_RETURN (data, char[VIntId.length_], -1);
02104 ACE_OS::memcpy (data, VIntId.data_.ptr_, VIntId.length_);
02105 length = VIntId.length_;
02106 return 0;
02107 }
02108
02109 int
02110 ACE_Configuration_Heap::find_value (const ACE_Configuration_Section_Key& key,
02111 const ACE_TCHAR* name,
02112 VALUETYPE& type_out)
02113 {
02114 ACE_ASSERT (this->allocator_);
02115 if (validate_name (name))
02116 return -1;
02117
02118
02119 ACE_TString section;
02120 if (load_key (key, section))
02121 return -1;
02122
02123
02124 ACE_Configuration_ExtId ExtId (section.fast_rep ());
02125 ACE_Configuration_Section_IntId IntId;
02126 if (index_->find (ExtId, IntId, allocator_))
02127 return -1;
02128
02129
02130 ACE_Configuration_ExtId ValueExtId (name);
02131 VALUE_ENTRY* value_entry;
02132 if (((VALUE_HASH *) IntId.value_hash_map_)->find (ValueExtId, value_entry))
02133 return -1;
02134
02135 type_out = value_entry->int_id_.type_;
02136 return 0;
02137 }
02138
02139 int
02140 ACE_Configuration_Heap::remove_value (const ACE_Configuration_Section_Key& key,
02141 const ACE_TCHAR* name)
02142 {
02143 ACE_ASSERT (this->allocator_);
02144 if (validate_name (name))
02145 return -1;
02146
02147
02148 ACE_TString section;
02149 if (load_key (key, section))
02150 return -1;
02151
02152
02153 ACE_Configuration_ExtId ExtId (section.fast_rep ());
02154 ACE_Configuration_Section_IntId IntId;
02155 if (index_->find (ExtId, IntId, allocator_))
02156 return -1;
02157
02158
02159 ACE_Configuration_ExtId ValueExtId (name);
02160 VALUE_ENTRY* value_entry;
02161 if (((VALUE_HASH *) IntId.value_hash_map_)->find (ValueExtId, value_entry))
02162 return -1;
02163
02164
02165 value_entry->ext_id_.free (allocator_);
02166 value_entry->int_id_.free (allocator_);
02167
02168
02169 if (IntId.value_hash_map_->unbind (ValueExtId, allocator_))
02170 return -1;
02171
02172 return 0;
02173 }