#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; //public api string user_properties_file(); bool find_system_config_file(string& dest); bool find_custom_jre(string& dest); bool read_deploy_property_value(string property, string& dest); //end of public api // trim from start static string <rim(string& s) { s.erase(s.begin(), find_if(s.begin(), s.end(), not1(ptr_fun(isspace)))); return s; } // trim from end static string &rtrim(string& s) { s.erase(find_if(s.rbegin(), s.rend(), not1(ptr_fun(isspace))).base(), s.end()); return s; } // trim from both ends static string &trim(string& s) { return ltrim(rtrim(s)); } static void remove_all_spaces(string& str) { for(int i=0; ipw_dir)+"/.icedtea/deployment.properties"; } static string main_properties_file(){ return "/etc/.java/deployment/deployment.properties"; } static string default_java_properties_file(){ return ICEDTEA_WEB_JRE "/lib/deployment.properties"; } //this is reimplemntation as icedtea-web settings do this (Also name of function is the same): //try the main file in /etc/.java/deployment //if found, then return this file //try to find setUp jre // if found, then try if this file exists and end //if no jre custom jvm is set, then tryes default jre // if its deploy file exists, then return //not dound otherwise bool find_system_config_file(string& dest){ if(file_exists(main_properties_file())) { dest = main_properties_file(); return true; } else { string jdest; bool found = find_custom_jre(jdest); if (found){ jdest = jdest + "/lib/deployment.properties"; if(file_exists(jdest) ) { dest = jdest; return true; } } else { if(file_exists(default_java_properties_file())) { dest = default_java_properties_file(); return true; } } } return false; //nothing of above found } //returns false if not found, true otherwise static bool find_property(string filename, string property, string& dest){ string nwproperty(property); trim(nwproperty); nwproperty=nwproperty+"="; ifstream input( filename.c_str() ); for( string line; getline( input, line ); ){ /* read a line */ string copy = string(line); //java tolerates spaces around = char, remove them for matching remove_all_spaces(copy); //printf(line.c_str()); //printf(copy.c_str()); if (starts_with(copy,nwproperty)) { //provide non-spaced value, trimming is done in get_property_value get_property_value(line, dest); return true; } } return false; } //this is reimplmentation of itw-settings operations //first check in user's settings, if found, return //then check in global file (see the magic of find_system_config_file) bool read_deploy_property_value(string property, string& dest){ //is it in user's file? bool a = find_property(user_properties_file(), property, dest); if (a) { return true; } //is it in global file? string futurefile; bool b = find_system_config_file(futurefile); if (b) { return find_property(futurefile, property, dest); } return false; } //This is different from common get property, as it is avoiding to search in *java* //properties files bool find_custom_jre(string& dest){ string key("deployment.jre.dir"); if(file_exists(user_properties_file())) { bool a = find_property(user_properties_file(),key, dest); if (a) { return true; } } if(file_exists(main_properties_file())) { return find_property(main_properties_file(),key, dest); } return false; } int main(void){ printf("user's settings file\n"); cout << user_properties_file(); printf("\nmain settings file:\n"); cout << (main_properties_file()); printf("\njava settings file \n"); cout << (default_java_properties_file()); printf("\nsystem config file\n"); string a1; find_system_config_file(a1); cout << a1; printf("\ncustom jre\n"); string a2; find_custom_jre(a2); cout << a2; printf("\nsome custom property\n"); string a3; read_deploy_property_value("deployment.security.level", a3); cout << a3; printf("\n"); return 0; }