Exemplo n.º 1
0
TEST_F(ConfigTest, config_remove_section) {
  config_t *config = config_new(CONFIG_FILE);
  EXPECT_TRUE(config_remove_section(config, "DID"));
  EXPECT_FALSE(config_has_section(config, "DID"));
  EXPECT_FALSE(config_has_key(config, "DID", "productId"));
  config_free(config);
}
Exemplo n.º 2
0
bool btc_config_remove_section(const char *section)
{
    assert(config != NULL);
    assert(section != NULL);

    osi_mutex_lock(&lock, OSI_MUTEX_MAX_TIMEOUT);
    bool ret = config_remove_section(config, section);
    osi_mutex_unlock(&lock);

    return ret;
}
Exemplo n.º 3
0
bool btc_compare_address_key_value(const char *section, char *key_type, void *key_value, int key_length)
{
    assert(key_value != NULL);
    bool status = false;
    char value_str[100] = {0};
    if(key_length > sizeof(value_str)/2) {
        return false;
    }
    btc_key_value_to_string((uint8_t *)key_value, value_str, key_length);
    osi_mutex_lock(&lock, OSI_MUTEX_MAX_TIMEOUT);
    if ((status = config_has_key_in_section(config, key_type, value_str)) == true) {
        config_remove_section(config, section);
    }
    osi_mutex_unlock(&lock);
    return status;
}
Exemplo n.º 4
0
void btc_config_save(void)
{
       assert(config != NULL);
    // Garbage collection process: the config file accumulates
    // cached information about remote devices during regular
    // inquiry scans. We remove some of these junk entries
    // so the file doesn't grow indefinitely. We have to take care
    // to make sure we don't remove information about bonded
    // devices (hence the check for link keys).
    static const size_t CACHE_MAX = 256;
    const char *keys[CACHE_MAX];
    size_t num_keys = 0;
    size_t total_candidates = 0;

    osi_mutex_lock(&lock, OSI_MUTEX_MAX_TIMEOUT);
    for (const config_section_node_t *snode = config_section_begin(config); snode != config_section_end(config); snode = config_section_next(snode)) {
        const char *section = config_section_name(snode);
        if (!string_is_bdaddr(section)) {
            continue;
        }

        if (config_has_key(config, section, "LinkKey") ||
                config_has_key(config, section, "LE_KEY_PENC") ||
                config_has_key(config, section, "LE_KEY_PID") ||
                config_has_key(config, section, "LE_KEY_PCSRK") ||
                config_has_key(config, section, "LE_KEY_LENC") ||
                config_has_key(config, section, "LE_KEY_LCSRK")) {
            continue;
        }

        if (num_keys < CACHE_MAX) {
            keys[num_keys++] = section;
        }

        ++total_candidates;
    }

    if (total_candidates > CACHE_MAX * 2)
        while (num_keys > 0) {
            config_remove_section(config, keys[--num_keys]);
        }
    config_save(config, CONFIG_FILE_PATH);
    osi_mutex_unlock(&lock);
}
Exemplo n.º 5
0
TEST_F(ConfigTest, config_remove_section_missing) {
  config_t *config = config_new(CONFIG_FILE);
  EXPECT_FALSE(config_remove_section(config, "not a section"));
  config_free(config);
}