bool
SimpleConfig::load_all_config ()
{
    String sysconf = get_sysconf_filename ();
    String userconf = get_userconf_filename ();

    KeyValueRepository config;

    if (userconf.length ()) {
        std::ifstream is (userconf.c_str ());
        if (is) {
            SCIM_DEBUG_CONFIG(1) << "Parsing user config file: "
                                 << userconf << "\n";
            parse_config (is, config);
        }
    }

    if (sysconf.length ()) {
        std::ifstream is (sysconf.c_str ());
        if (is) {
            SCIM_DEBUG_CONFIG(1) << "Parsing system config file: "
                                 << sysconf << "\n";
            parse_config (is, config);
        }
    }

    if (!m_config.size () || (m_update_timestamp.tv_sec == 0 && m_update_timestamp.tv_usec == 0)) {
        m_config.swap (config);
        gettimeofday (&m_update_timestamp, 0);
        return true;
    }

    KeyValueRepository::iterator it = config.find (String (SCIM_CONFIG_UPDATE_TIMESTAMP));

    if (it != config.end ()) {
        std::vector <String> strs;
        if (scim_split_string_list (strs, it->second, ':') == 2) {
            time_t sec = (time_t) strtol (strs [0].c_str (), 0, 10);
            suseconds_t usec = (suseconds_t) strtol (strs [1].c_str (), 0, 10);

            // The config file is newer, so load it.
            if (m_update_timestamp.tv_sec < sec || (m_update_timestamp.tv_sec == sec && m_update_timestamp.tv_usec < usec)) {
                m_config.swap (config);
                m_update_timestamp.tv_sec = (time_t) sec;
                m_update_timestamp.tv_usec = (suseconds_t) usec;
                return true;
            }
        }
    }
    return false;
}
void
SimpleConfig::parse_config (std::istream &is, KeyValueRepository &config)
{
    char *conf_line = new char [SCIM_MAX_CONFIG_LINE_LENGTH];

    while (!is.eof()) {
        is.getline(conf_line, SCIM_MAX_CONFIG_LINE_LENGTH);
        if (!is.eof()) {
            String normalized_line = trim_blank(conf_line);

            if ((normalized_line.find_first_of("#") > 0) && (normalized_line.length() != 0)) {
                if (normalized_line.find_first_of("=") == String::npos) {
                    SCIM_DEBUG_CONFIG(2) << " Invalid config line : " << normalized_line << "\n";
                    continue;
                }

                if (normalized_line[0] == '=') {
                    SCIM_DEBUG_CONFIG(2) << " Invalid config line : " << normalized_line << "\n";
                    continue;
                }

                String param = get_param_portion(normalized_line);
                KeyValueRepository::iterator i = config.find(param);

                if (i != config.end()) {
                    SCIM_DEBUG_CONFIG(2) << " Config entry " << normalized_line << " has been read.\n";
                } else {
                    String value = get_value_portion (normalized_line); 
                    config [param] = value;
                    SCIM_DEBUG_CONFIG(2) << " Config entry " << param << "=" << value << " is successfully read.\n";
                }
            }
        }
    }

    delete [] conf_line;
}
Beispiel #3
0
 MODULE_EXPORT void scim_config_module_init()
 {
     SCIM_DEBUG_CONFIG(1) << "Initializing KConfig Config module (more)...\n";
 }
Beispiel #4
0
 MODULE_EXPORT ConfigPointer scim_config_module_create_config()
 {
     SCIM_DEBUG_CONFIG(1) << "Creating a KConfig Config instance...\n";
     return new KConfigConfig;
 }
Beispiel #5
0
 MODULE_EXPORT void scim_module_exit()
 {
     SCIM_DEBUG_CONFIG(1) << "Exiting KConfig Config module...\n";
 }