static bool database_add_chrc(struct external_service *service,
						struct external_chrc *chrc)
{
	uint16_t handle;
	bt_uuid_t uuid;
	char str[MAX_LEN_UUID_STR];
	const struct queue_entry *entry;

	if (!parse_handle(chrc->proxy, &handle)) {
		error("Failed to read \"Handle\" property of characteristic");
		return false;
	}

	if (!parse_uuid(chrc->proxy, &uuid)) {
		error("Failed to read \"UUID\" property of characteristic");
		return false;
	}

	if (!check_service_path(chrc->proxy, service)) {
		error("Invalid service path for characteristic");
		return false;
	}

	chrc->attrib = gatt_db_service_insert_characteristic(service->attrib,
						handle, &uuid, chrc->perm,
						chrc->props, chrc_read_cb,
						chrc_write_cb, chrc);
	if (!chrc->attrib) {
		error("Failed to create characteristic entry in database");
		return false;
	}

	if (!database_add_ccc(service, chrc))
		return false;

	if (!database_add_cep(service, chrc))
		return false;

	if (!handle) {
		handle = gatt_db_attribute_get_handle(chrc->attrib);
		write_handle(chrc->proxy, handle);
	}

	bt_uuid_to_string(&uuid, str, sizeof(str));

	DBG("handle 0x%04x UUID %s", handle, str);

	/* Handle the descriptors that belong to this characteristic. */
	for (entry = queue_get_entries(service->descs); entry;
							entry = entry->next) {
		struct external_desc *desc = entry->data;

		if (desc->handled || g_strcmp0(desc->chrc_path, chrc->path))
			continue;

		if (!database_add_desc(service, desc)) {
			chrc->attrib = NULL;
			error("Failed to create descriptor entry");
			return false;
		}
	}

	return true;
}
static bool database_add_chrc(struct external_service *service,
						struct external_chrc *chrc)
{
	uint16_t handle;
	bt_uuid_t uuid;
	char str[MAX_LEN_UUID_STR];
	const struct queue_entry *entry;

	if (!parse_handle(chrc->proxy, &handle)) {
		error("Failed to read \"Handle\" property of characteristic");
		return false;
	}

	if (!parse_uuid(chrc->proxy, &uuid)) {
		error("Failed to read \"UUID\" property of characteristic");
		return false;
	}

	if (!check_service_path(chrc->proxy, service)) {
		error("Invalid service path for characteristic");
		return false;
	}

	chrc->attrib = gatt_db_service_insert_characteristic(service->attrib,
						handle, &uuid, chrc->perm,
						chrc->props, chrc_read_cb,
						chrc_write_cb, chrc);
	if (!chrc->attrib) {
		error("Failed to create characteristic entry in database");
		return false;
	}

	if (!database_add_ccc(service, chrc))
		return false;

	if (!database_add_cep(service, chrc))
		return false;

	if (!handle) {
		handle = gatt_db_attribute_get_handle(chrc->attrib);
		write_handle(chrc->proxy, handle);
	}

	bt_uuid_to_string(&uuid, str, sizeof(str));

	DBG("handle 0x%04x UUID %s", handle, str);

	 
	for (entry = queue_get_entries(service->descs); entry;
							entry = entry->next) {
		struct external_desc *desc = entry->data;

		if (desc->handled || g_strcmp0(desc->chrc_path, chrc->path))
			continue;

		if (!database_add_desc(service, desc)) {
			chrc->attrib = NULL;
			error("Failed to create descriptor entry");
			return false;
		}
	}

	return true;
}