#include <Configuration_Import_Export.h>
Inheritance diagram for ACE_Registry_ImpExp:


Public Methods | |
| ACE_Registry_ImpExp (ACE_Configuration &) | |
| Construction. More... | |
| virtual | ~ACE_Registry_ImpExp (void) |
| Destruction. More... | |
| virtual int | import_config (const ACE_TCHAR *filename) |
| virtual int | export_config (const ACE_TCHAR *filename) |
Private Methods | |
| int | export_section (const ACE_Configuration_Section_Key §ion, const ACE_TString &path, FILE *out) |
| int | process_previous_line_format (ACE_TCHAR *buffer, ACE_Configuration_Section_Key §ion) |
| ACE_Registry_ImpExp (const ACE_Registry_ImpExp &) | |
| ACE_Registry_ImpExp & | operator= (const ACE_Registry_ImpExp &) |
Definition at line 92 of file Configuration_Import_Export.h.
|
|
Construction.
Definition at line 15 of file Configuration_Import_Export.cpp.
00016 : ACE_Config_ImpExp_Base (config) 00017 { 00018 } |
|
|
Destruction.
Definition at line 20 of file Configuration_Import_Export.cpp.
00021 {
00022 }
|
|
|
|
|
|
This method exports the entire configuration database to filename. Once the file is opened this method calls export_section() passing the root section. Implements ACE_Config_ImpExp_Base. Definition at line 166 of file Configuration_Import_Export.cpp. References ACE_LIB_TEXT, ACE_TCHAR, ACE_Config_ImpExp_Base::config_, export_section, ACE_OS::fclose, ACE_OS::fopen, and ACE_Configuration::root_section. Referenced by ACE_Configuration::export_config.
00167 {
00168 if (0 == filename)
00169 {
00170 errno = EINVAL;
00171 return -1;
00172 }
00173 int result = -1;
00174
00175 FILE* out = ACE_OS::fopen (filename, ACE_LIB_TEXT ("w"));
00176 if (out)
00177 {
00178 result = this->export_section (config_.root_section (),
00179 ACE_LIB_TEXT (""),
00180 out);
00181 ACE_OS::fclose (out);
00182 }
00183 return result;
00184 }
|
|
||||||||||||||||
|
Definition at line 191 of file Configuration_Import_Export.cpp. References ACE_LIB_TEXT, ACE_TCHAR, ACE_Configuration::BINARY, ACE_Config_ImpExp_Base::config_, ACE_Configuration::enumerate_sections, ACE_Configuration::enumerate_values, ACE_String_Base< char >::fast_rep, ACE_OS::fputs, ACE_Configuration::get_binary_value, ACE_Configuration::get_integer_value, ACE_Configuration::get_string_value, ACE_Configuration::INTEGER, ACE_Configuration::INVALID, ACE_String_Base< char >::length, ACE_Configuration::open_section, ACE_OS::sprintf, ACE_Configuration::STRING, and ACE_Configuration::VALUETYPE. Referenced by export_config.
00194 {
00195 // don't export the root
00196 if (path.length ())
00197 {
00198 // Write out the section header
00199 ACE_TString header = ACE_LIB_TEXT ("[");
00200 header += path;
00201 header += ACE_LIB_TEXT ("]");
00202 header += ACE_LIB_TEXT (" \n");
00203 if (ACE_OS::fputs (header.fast_rep (), out) < 0)
00204 return -1;
00205 // Write out each value
00206 int index = 0;
00207 ACE_TString name;
00208 ACE_Configuration::VALUETYPE type;
00209 ACE_TString line;
00210 ACE_TCHAR int_value[32];
00211 ACE_TCHAR bin_value[3];
00212 void* binary_data;
00213 size_t binary_length;
00214 ACE_TString string_value;
00215 while (!config_.enumerate_values (section, index, name, type))
00216 {
00217 line = ACE_LIB_TEXT ("\"") + name + ACE_LIB_TEXT ("\"=");
00218 switch (type)
00219 {
00220 case ACE_Configuration::INTEGER:
00221 {
00222 u_int value;
00223 if (config_.get_integer_value (section, name.fast_rep (), value))
00224 return -2;
00225 ACE_OS::sprintf (int_value, ACE_LIB_TEXT ("%08x"), value);
00226 line += ACE_LIB_TEXT ("dword:");
00227 line += int_value;
00228 break;
00229 }
00230 case ACE_Configuration::STRING:
00231 {
00232 if (config_.get_string_value (section,
00233 name.fast_rep (),
00234 string_value))
00235 return -2;
00236 line += ACE_LIB_TEXT ("\"");
00237 line += string_value + ACE_LIB_TEXT ("\"");
00238 break;
00239 }
00240 #ifdef _WIN32
00241 case ACE_Configuration::INVALID:
00242 break; // JDO added break. Otherwise INVALID is processed
00243 // like BINARY. If that's correct, please remove the
00244 // break and these comments
00245 #endif
00246 case ACE_Configuration::BINARY:
00247 {
00248 // not supported yet - maybe use BASE64 codeing?
00249 if (config_.get_binary_value (section,
00250 name.fast_rep (),
00251 binary_data,
00252 binary_length))
00253 return -2;
00254 line += ACE_LIB_TEXT ("hex:");
00255 unsigned char* ptr = (unsigned char*)binary_data;
00256 while (binary_length)
00257 {
00258 if (ptr != binary_data)
00259 {
00260 line += ACE_LIB_TEXT (",");
00261 }
00262 ACE_OS::sprintf (bin_value, ACE_LIB_TEXT ("%02x"), *ptr);
00263 line += bin_value;
00264 --binary_length;
00265 ++ptr;
00266 }
00267 delete [] (char*) binary_data;
00268 break;
00269 }
00270 default:
00271 return -3;
00272 }
00273 line += ACE_LIB_TEXT ("\n");
00274 if (ACE_OS::fputs (line.fast_rep (), out) < 0)
00275 return -4;
00276 index++;
00277 }
00278 }
00279 // Export all sub sections
00280 int index = 0;
00281 ACE_TString name;
00282 ACE_Configuration_Section_Key sub_key;
00283 ACE_TString sub_section;
00284 while (!config_.enumerate_sections (section, index, name))
00285 {
00286 ACE_TString sub_section (path);
00287 if (path.length ())
00288 sub_section += ACE_LIB_TEXT ("\\");
00289 sub_section += name;
00290 if (config_.open_section (section, name.fast_rep (), 0, sub_key))
00291 return -5;
00292 if (export_section (sub_key, sub_section.fast_rep (), out))
00293 return -6;
00294 index++;
00295 }
00296 return 0;
00297 }
|
|
|
Imports the configuration database from filename. No existing data is removed. Implements ACE_Config_ImpExp_Base. Definition at line 27 of file Configuration_Import_Export.cpp. References ACE_LIB_TEXT, ACE_NEW_RETURN, ACE_TCHAR, ACE_Config_ImpExp_Base::config_, ACE_Configuration::expand_path, ACE_OS::fclose, ACE_OS::fgets, ACE_OS::fopen, process_previous_line_format, ACE_Configuration::root_section, ACE_Configuration::set_binary_value, ACE_Configuration::set_integer_value, ACE_Configuration::set_string_value, ACE_OS_String::strchr, ACE_OS_String::strlen, ACE_OS_String::strncmp, ACE_OS_String::strrchr, and ACE_OS_String::strtoul. Referenced by ACE_Configuration::import_config.
00028 {
00029 if (0 == filename)
00030 {
00031 errno = EINVAL;
00032 return -1;
00033 }
00034 FILE* in = ACE_OS::fopen (filename, ACE_LIB_TEXT ("r"));
00035 if (!in)
00036 return -1;
00037
00038 // @@ XXX - change this to a dynamic buffer
00039 ACE_TCHAR buffer[4096];
00040 ACE_Configuration_Section_Key section;
00041 while (ACE_OS::fgets (buffer, 4096, in))
00042 {
00043 // Check for a comment
00044 if (buffer[0] == ACE_LIB_TEXT (';') || buffer[0] == ACE_LIB_TEXT ('#'))
00045 continue;
00046
00047 if (buffer[0] == ACE_LIB_TEXT ('['))
00048 {
00049 // We have a new section here, strip out the section name
00050 ACE_TCHAR* end = ACE_OS::strrchr (buffer, ACE_LIB_TEXT (']'));
00051 if (!end)
00052 {
00053 ACE_OS::fclose (in);
00054 return -3;
00055 }
00056 *end = 0;
00057
00058 if (config_.expand_path (config_.root_section (), buffer + 1, section, 1))
00059 {
00060 ACE_OS::fclose (in);
00061 return -3;
00062 }
00063 continue;
00064 } // end if firs char is a [
00065
00066 if (buffer[0] == ACE_LIB_TEXT ('"'))
00067 {
00068 // we have a value
00069 ACE_TCHAR* end = ACE_OS::strchr (buffer+1, '"');
00070 if (!end) // no closing quote, not a value so just skip it
00071 continue;
00072
00073 // null terminate the name
00074 *end = 0;
00075 ACE_TCHAR* name = buffer + 1;
00076 end+=2;
00077 // determine the type
00078 if (*end == '\"')
00079 {
00080 // string type
00081 // truncate trailing "
00082 ++end;
00083 ACE_TCHAR* trailing = ACE_OS::strrchr (end, '"');
00084 if (trailing)
00085 *trailing = 0;
00086 if (config_.set_string_value (section, name, end))
00087 {
00088 ACE_OS::fclose (in);
00089 return -4;
00090 }
00091 }
00092 else if (ACE_OS::strncmp (end, ACE_LIB_TEXT ("dword:"), 6) == 0)
00093 {
00094 // number type
00095 ACE_TCHAR* endptr = 0;
00096 u_int value = ACE_OS::strtoul (end + 6, &endptr, 16);
00097 if (config_.set_integer_value (section, name, value))
00098 {
00099 ACE_OS::fclose (in);
00100 return -4;
00101 }
00102 }
00103 else if (ACE_OS::strncmp (end, ACE_LIB_TEXT ("hex:"), 4) == 0)
00104 {
00105 // binary type
00106 size_t string_length = ACE_OS::strlen (end + 4);
00107 // divide by 3 to get the actual buffer length
00108 size_t length = string_length / 3;
00109 size_t remaining = length;
00110 u_char* data = 0;
00111 ACE_NEW_RETURN (data,
00112 u_char[length],
00113 -1);
00114 u_char* out = data;
00115 ACE_TCHAR* inb = end + 4;
00116 ACE_TCHAR* endptr = 0;
00117 while (remaining)
00118 {
00119 u_char charin = (u_char) ACE_OS::strtoul (inb, &endptr, 16);
00120 *out = charin;
00121 ++out;
00122 --remaining;
00123 inb += 3;
00124 }
00125 if (config_.set_binary_value (section, name, data, length))
00126 {
00127 ACE_OS::fclose (in);
00128 return -4;
00129 }
00130 }
00131 else
00132 {
00133 // invalid type, ignore
00134 continue;
00135 }
00136 }// end if first char is a "
00137 else
00138 {
00139 // if the first character is not a ", [, ;, or # we may be
00140 // processing a file in the old format.
00141 // Try and process the line as such and if it fails,
00142 // return an error
00143 int rc;
00144 if ((rc = process_previous_line_format (buffer, section)) != 0)
00145 {
00146 ACE_OS::fclose (in);
00147 return rc;
00148 }
00149 } // end if maybe old format
00150 } // end while fgets
00151
00152 if (ferror (in))
00153 {
00154 ACE_OS::fclose (in);
00155 return -1;
00156 }
00157
00158 ACE_OS::fclose (in);
00159 return 0;
00160 }
|
|
|
|
|
||||||||||||
|
Definition at line 303 of file Configuration_Import_Export.cpp. References ACE_LIB_TEXT, ACE_TCHAR, ACE_OS::atoi, ACE_Config_ImpExp_Base::config_, ACE_Configuration::set_integer_value, ACE_Configuration::set_string_value, ACE_OS_String::strchr, and ACE_OS_String::strpbrk. Referenced by import_config.
00305 {
00306 // Chop any cr/lf at the end of the line.
00307 ACE_TCHAR *endp = ACE_OS_String::strpbrk (buffer, ACE_LIB_TEXT ("\r\n"));
00308 if (endp != 0)
00309 *endp = '\0';
00310
00311 // assume this is a value, read in the value name
00312 ACE_TCHAR* end = ACE_OS::strchr (buffer, '=');
00313 if (end) // no =, not a value so just skip it
00314 {
00315 // null terminate the name
00316 *end = 0;
00317 end++;
00318 // determine the type
00319 if (*end == '\"')
00320 {
00321 // string type
00322 if(config_.set_string_value (section, buffer, end + 1))
00323 return -4;
00324 }
00325 else if (*end == '#')
00326 {
00327 // number type
00328 u_int value = ACE_OS::atoi (end + 1);
00329 if (config_.set_integer_value (section, buffer, value))
00330 return -4;
00331 }
00332 }
00333 return 0;
00334 } // end read_previous_line_format
|
1.2.14 written by Dimitri van Heesch,
© 1997-2002