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); }
bool btif_config_has_section(const char *section) { assert(config != NULL); assert(section != NULL); pthread_mutex_lock(&lock); bool ret = config_has_section(config, section); pthread_mutex_unlock(&lock); return ret; }
bool btc_config_has_section(const char *section) { assert(config != NULL); assert(section != NULL); osi_mutex_lock(&lock, OSI_MUTEX_MAX_TIMEOUT); bool ret = config_has_section(config, section); osi_mutex_unlock(&lock); return ret; }
// Parses the specified Device ID configuration file and registers the // Device ID records with SDP. void bte_load_did_conf(const char *p_path) { assert(p_path != NULL); config_t *config = config_new(p_path); if (!config) { LOG_ERROR(LOG_TAG, "%s unable to load DID config '%s'.", __func__, p_path); return; } for (int i = 1; i <= BTA_DI_NUM_MAX; ++i) { char section_name[16] = { 0 }; snprintf(section_name, sizeof(section_name), "DID%d", i); if (!config_has_section(config, section_name)) { LOG_DEBUG(LOG_TAG, "%s no section named %s.", __func__, section_name); break; } tBTA_DI_RECORD record; record.vendor = config_get_int(config, section_name, "vendorId", LMP_COMPID_BROADCOM); record.vendor_id_source = config_get_int(config, section_name, "vendorIdSource", DI_VENDOR_ID_SOURCE_BTSIG); record.product = config_get_int(config, section_name, "productId", 0); record.version = config_get_int(config, section_name, "version", 0); record.primary_record = config_get_bool(config, section_name, "primaryRecord", false); strlcpy(record.client_executable_url, config_get_string(config, section_name, "clientExecutableURL", ""), sizeof(record.client_executable_url)); strlcpy(record.service_description, config_get_string(config, section_name, "serviceDescription", ""), sizeof(record.service_description)); strlcpy(record.documentation_url, config_get_string(config, section_name, "documentationURL", ""), sizeof(record.documentation_url)); if (record.vendor_id_source != DI_VENDOR_ID_SOURCE_BTSIG && record.vendor_id_source != DI_VENDOR_ID_SOURCE_USBIF) { LOG_ERROR(LOG_TAG, "%s invalid vendor id source %d; ignoring DID record %d.", __func__, record.vendor_id_source, i); continue; } LOG_DEBUG(LOG_TAG, "Device ID record %d : %s", i, (record.primary_record ? "primary" : "not primary")); LOG_DEBUG(LOG_TAG, " vendorId = %04x", record.vendor); LOG_DEBUG(LOG_TAG, " vendorIdSource = %04x", record.vendor_id_source); LOG_DEBUG(LOG_TAG, " product = %04x", record.product); LOG_DEBUG(LOG_TAG, " version = %04x", record.version); LOG_DEBUG(LOG_TAG, " clientExecutableURL = %s", record.client_executable_url); LOG_DEBUG(LOG_TAG, " serviceDescription = %s", record.service_description); LOG_DEBUG(LOG_TAG, " documentationURL = %s", record.documentation_url); uint32_t record_handle; tBTA_STATUS status = BTA_DmSetLocalDiRecord(&record, &record_handle); if (status != BTA_SUCCESS) { LOG_ERROR(LOG_TAG, "%s unable to set device ID record %d: error %d.", __func__, i, status); } } config_free(config); }
TEST_F(ConfigTest, config_has_section) { config_t *config = config_new(CONFIG_FILE); EXPECT_TRUE(config_has_section(config, "DID")); config_free(config); }
/** recursively read the menu hierarchy */ MenuEntry *menu_read(MenuEntry *parent, const char *name) { static int id = 0; if ((name != NULL) && (config_has_section(name))) { MenuEntry *me = calloc(1, sizeof(MenuEntry)); // auto-NULL elements if (me == NULL) return NULL; // set common entries me->id = id++; me->name = strdup(name); if (me->name == NULL) { //menu_free(me); return NULL; } me->displayname = strdup(config_get_string(name, "DisplayName", 0, name)); if (me->displayname == NULL) { //menu_free(me); return NULL; } me->parent = parent; me->next = NULL; me->children = NULL; me->numChildren = 0; if (config_get_string(name, "Entry", 0, NULL) != NULL) { MenuEntry **addr = &me->children; const char *entryname; // it is a sub-menu me->type = MT_MENU; // read menu entries while ((entryname = config_get_string(name, "Entry", me->numChildren, NULL)) != NULL) { MenuEntry *entry = menu_read(me, entryname); if (entry == NULL) { //menu_free(me); return NULL; } me->numChildren++; *addr = entry; addr = &entry->next; } } else if (config_get_string(name, "Exec", 0, NULL) != NULL) { MenuEntry **addr = &me->children; const char *entryname; // it's a command to execute me->type = MT_EXEC; me->data.exec.command = strdup(config_get_string(name, "Exec", 0, "")); if (me->data.exec.command == NULL) { //menu_free(me); return NULL; } me->data.exec.feedback = config_get_bool(name, "Feedback", 0, 0); // try to read parameters while ((entryname = config_get_string(name, "Parameter", me->numChildren, NULL)) != NULL) { MenuEntry *entry = menu_read(me, entryname); if (entry == NULL) { //menu_free(me); return NULL; } me->numChildren++; *addr = entry; addr = &entry->next; } // automagically add an "Apply ?" action if ((me->numChildren > 0) && (addr != NULL)) *addr = menu_read(me, NULL); } else if (config_get_string(name, "Type", 0, NULL) != NULL) { // it's a command parameter const char *type; type = config_get_string(name, "Type", 0, ""); if (strcasecmp(type, "slider") == 0) { char buf[35]; me->type = MT_ARG_SLIDER; me->data.slider.value = config_get_int(name, "Value", 0, 0); me->data.slider.minval = config_get_int(name, "MinValue", 0, 0); me->data.slider.maxval = config_get_int(name, "MaxValue", 0, 1000); sprintf(buf, "%d", me->data.slider.minval); me->data.slider.mintext = strdup(config_get_string(name, "MinText", 0, buf)); sprintf(buf, "%d", me->data.slider.maxval); me->data.slider.maxtext = strdup(config_get_string(name, "MaxText", 0, buf)); me->data.slider.stepsize = config_get_int(name, "StepSize", 0, 1); } else if (strcasecmp(type, "ring") == 0) { const char *tmp; int numStrings = 0; int i = 0; me->type = MT_ARG_RING; me->data.ring.value = config_get_int(name, "Value", 0, 0); numStrings = config_has_key(name, "String"); me->data.ring.strings = calloc(sizeof(char *), numStrings+1); me->data.ring.strings[numStrings] = NULL; while ((tmp = config_get_string(name, "String", i, NULL)) != NULL) { me->data.ring.strings[i] = strdup(tmp); i++; } me->data.ring.strings[i] = NULL; } else if (strcasecmp(type, "numeric") == 0) { me->type = MT_ARG_NUMERIC; me->data.numeric.value = config_get_int(name, "Value", 0, 0); me->data.numeric.minval = config_get_int(name, "MinValue", 0, 0); me->data.numeric.maxval = config_get_int(name, "MaxValue", 0, 1000); } else if (strcasecmp(type, "alpha") == 0) { me->type = MT_ARG_ALPHA; me->data.alpha.value = strdup(config_get_string(name, "Value", 0, "")); me->data.alpha.minlen = config_get_int(name, "MinLength", 0, 0); me->data.alpha.maxlen = config_get_int(name, "MaxLength", 0, 100); me->data.alpha.allowed = strdup(config_get_string(name, "AllowedChars", 0, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")); } else if (strcasecmp(type, "ip") == 0) { me->type = MT_ARG_IP; me->data.ip.value = strdup(config_get_string(name, "Value", 0, "")); me->data.ip.v6 = config_get_bool(name, "Value", 0, 0); } else if (strcasecmp(type, "checkbox") == 0) { const char *tmp; me->type = MT_ARG_CHECKBOX; me->data.checkbox.allow_gray = config_get_bool(name, "AllowGray", 0, 0); me->data.checkbox.value = (me->data.checkbox.allow_gray) ? config_get_tristate(name, "Value", 0, "gray", 0) : config_get_bool(name, "Value", 0, 0); // get replacement strings for different values tmp = config_get_string(name, "OffText", 0, NULL); me->data.checkbox.map[0] = (tmp != NULL) ? strdup(tmp) : NULL; tmp = config_get_string(name, "OnText", 0, NULL); me->data.checkbox.map[1] = (tmp != NULL) ? strdup(tmp) : NULL; tmp = config_get_string(name, "GrayText", 0, NULL); me->data.checkbox.map[2] = (tmp != NULL) ? strdup(tmp) : NULL; } else { report(RPT_DEBUG, "illegal parameter type"); //menu_free(me); return NULL; } } else { report(RPT_DEBUG, "unknown menu entry type"); //menu_free(me); return NULL; } return me; } else { /* the magic stuff: if name is NULL and parent is an EXEC entry, * then generate an Action entry with the name "Apply" */ if ((name == NULL) && (parent != NULL) && (parent->type = MT_EXEC)) { MenuEntry *me = calloc(1, sizeof(MenuEntry)); // auto-NULL elements if (me == NULL) return NULL; // set common entries me->id = id++; me->name = malloc(strlen(parent->name) + 10); if (me->name == NULL) { //menu_free(me); return NULL; } strcpy(me->name, "Apply_"); strcat(me->name, parent->name); me->displayname = strdup("Apply!"); if (me->displayname == NULL) { //menu_free(me); return NULL; } me->parent = parent; me->next = NULL; me->children = NULL; me->numChildren = 0; me->type = MT_ARG_ACTION | MT_AUTOMATIC; return me; } } return NULL; }