Beispiel #1
0
static void register_stored(struct serial_adapter *adapter)
{
    char filename[PATH_MAX + 1];
    char address[18];
    bdaddr_t src;

    adapter_get_address(adapter->btd_adapter, &src);
    ba2str(&src, address);
    snprintf(filename, PATH_MAX, "%s/%s/proxy", STORAGEDIR, address);
    textfile_foreach(filename, parse_proxy, adapter);
}
Beispiel #2
0
static void notify_devices(struct alert_adapter *al_adapter,
			enum notify_type type, uint8_t *value, size_t len)
{
	struct notify_data *notify_data;
	char filename[PATH_MAX + 1];

	notify_data = g_new0(struct notify_data, 1);
	notify_data->al_adapter = al_adapter;
	notify_data->type = type;
	notify_data->value = g_memdup(value, len);
	notify_data->len = len;

	create_filename(filename, al_adapter->adapter);
	textfile_foreach(filename, filter_devices_notify, notify_data);
}
static void register_connections_stored(const char *adapter)
{
	char filename[PATH_MAX + 1];
	char *pattern;
	struct stat st;
	GSList *list;
	bdaddr_t src;
	bdaddr_t default_src;
	int dev_id;

	create_name(filename, PATH_MAX, STORAGEDIR, adapter, "network");

	str2ba(adapter, &src);

	if (stat(filename, &st) < 0)
		return;

	if (!(st.st_mode & __S_IFREG))
		return;

	textfile_foreach(filename, parse_stored_connection, &src);

	/* Check default connection for current default adapter */
	bacpy(&default_src, BDADDR_ANY);
	dev_id = hci_get_route(&default_src);
	if (dev_id < 0 || hci_devba(dev_id, &default_src) < 0)
		return;

	if (bacmp(&default_src, &src) != 0)
		return;

	pattern = textfile_get(filename, "default");
	if (!pattern)
		return;

	list = find_connection_pattern(connection, pattern);
	if (!list)
		return;
	default_index = g_slist_position(connection_paths, list);
}
Beispiel #4
0
int main(int argc, char *argv[])
{
	char filename[] = "/tmp/textfile";
	char key[18], value[512], *str;
	unsigned int i, j, size, max = 10;
	int fd;

	size = getpagesize();
	printf("System uses a page size of %d bytes\n\n", size);

	fd = creat(filename, 0644);
	if (ftruncate(fd, 0) < 0)
		return -errno;

	memset(value, 0, sizeof(value));
	for (i = 0; i < (size / sizeof(value)); i++) {
		if (write(fd, value, sizeof(value)) < 0)
			return -errno;
	}

	close(fd);

	sprintf(key, "11:11:11:11:11:11");
	str = textfile_get(filename, key);

	if (truncate(filename, 0) < 0)
		return -errno;

	sprintf(key, "00:00:00:00:00:00");
	if (textfile_del(filename, key) < 0)
		fprintf(stderr, "%s (%d)\n", strerror(errno), errno);

	memset(value, 0, sizeof(value));
	if (textfile_put(filename, key, value) < 0)
		fprintf(stderr, "%s (%d)\n", strerror(errno), errno);

	str = textfile_get(filename, key);
	if (!str)
		fprintf(stderr, "No value for %s\n", key);
	else
		free(str);

	snprintf(value, sizeof(value), "Test");
	if (textfile_put(filename, key, value) < 0)
		fprintf(stderr, "%s (%d)\n", strerror(errno), errno);

	if (textfile_put(filename, key, value) < 0)
		fprintf(stderr, "%s (%d)\n", strerror(errno), errno);

	if (textfile_put(filename, key, value) < 0)
		fprintf(stderr, "%s (%d)\n", strerror(errno), errno);

	if (textfile_del(filename, key) < 0)
		fprintf(stderr, "%s (%d)\n", strerror(errno), errno);

	str = textfile_get(filename, key);
	if (str) {
		fprintf(stderr, "Found value for %s\n", key);
		free(str);
	}

	for (i = 1; i < max + 1; i++) {
		sprintf(key, "00:00:00:00:00:%02X", i);

		memset(value, 0, sizeof(value));
		for (j = 0; j < i; j++)
			value[j] = 'x';

		printf("%s %s\n", key, value);

		if (textfile_put(filename, key, value) < 0) {
			fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
			break;
		}

		str = textfile_get(filename, key);
		if (!str)
			fprintf(stderr, "No value for %s\n", key);
		else
			free(str);
	}


	sprintf(key, "00:00:00:00:00:%02X", max);

	memset(value, 0, sizeof(value));
	for (j = 0; j < max; j++)
		value[j] = 'y';

	if (textfile_put(filename, key, value) < 0)
		fprintf(stderr, "%s (%d)\n", strerror(errno), errno);

	sprintf(key, "00:00:00:00:00:%02X", 1);

	memset(value, 0, sizeof(value));
	for (j = 0; j < max; j++)
		value[j] = 'z';

	if (textfile_put(filename, key, value) < 0)
		fprintf(stderr, "%s (%d)\n", strerror(errno), errno);

	printf("\n");

	for (i = 1; i < max + 1; i++) {
		sprintf(key, "00:00:00:00:00:%02X", i);

		str = textfile_get(filename, key);
		if (str) {
			printf("%s %s\n", key, str);
			free(str);
		}
	}


	sprintf(key, "00:00:00:00:00:%02X", 2);

	if (textfile_del(filename, key) < 0)
		fprintf(stderr, "%s (%d)\n", strerror(errno), errno);

	sprintf(key, "00:00:00:00:00:%02X", max - 3);

	if (textfile_del(filename, key) < 0)
		fprintf(stderr, "%s (%d)\n", strerror(errno), errno);

	printf("\n");

	textfile_foreach(filename, print_entry, NULL);


	sprintf(key, "00:00:00:00:00:%02X", 1);

	if (textfile_del(filename, key) < 0)
		fprintf(stderr, "%s (%d)\n", strerror(errno), errno);

	sprintf(key, "00:00:00:00:00:%02X", max);

	if (textfile_del(filename, key) < 0)
		fprintf(stderr, "%s (%d)\n", strerror(errno), errno);

	sprintf(key, "00:00:00:00:00:%02X", max + 1);

	if (textfile_del(filename, key) < 0)
		fprintf(stderr, "%s (%d)\n", strerror(errno), errno);

	printf("\n");

	textfile_foreach(filename, print_entry, NULL);

	return 0;
}
static void test_multiple(const void *data)
{
	char key[18], value[512], *str;
	unsigned int i, j, max = 10;

	util_create_empty();

	for (i = 1; i < max + 1; i++) {
		sprintf(key, "00:00:00:00:00:%02X", i);

		memset(value, 0, sizeof(value));
		for (j = 0; j < i; j++)
			value[j] = 'x';

		g_assert(textfile_put(test_pathname, key, value) == 0);

		str = textfile_get(test_pathname, key);

		tester_debug("%s %s\n", key, str);

		g_assert(str != NULL);
		g_assert(strcmp(str, value) == 0);

		free(str);
	}

	sprintf(key, "00:00:00:00:00:%02X", max);

	memset(value, 0, sizeof(value));
	for (j = 0; j < max; j++)
		value[j] = 'y';

	g_assert(textfile_put(test_pathname, key, value) == 0);

	str = textfile_get(test_pathname, key);

	tester_debug("%s %s\n", key, str);

	g_assert(str != NULL);
	g_assert(strcmp(str, value) == 0);

	free(str);

	sprintf(key, "00:00:00:00:00:%02X", 1);

	memset(value, 0, sizeof(value));
	for (j = 0; j < max; j++)
		value[j] = 'z';

	g_assert(textfile_put(test_pathname, key, value) == 0);

	str = textfile_get(test_pathname, key);

	tester_debug("%s %s\n", key, str);

	g_assert(str != NULL);
	g_assert(strcmp(str, value) == 0);

	free(str);

	for (i = 1; i < max + 1; i++) {
		sprintf(key, "00:00:00:00:00:%02X", i);
		str = textfile_get(test_pathname, key);

		tester_debug("%s %s\n", key, str);

		g_assert(str != NULL);

		if (i == 1)
			g_assert(strlen(str) == max);
		else
			g_assert(strlen(str) == i);

		g_free(str);
	}

	sprintf(key, "00:00:00:00:00:%02X", 2);
	g_assert(textfile_del(test_pathname, key) == 0);

	sprintf(key, "00:00:00:00:00:%02X", max - 3);
	g_assert(textfile_del(test_pathname, key) == 0);

	textfile_foreach(test_pathname, check_entry, GUINT_TO_POINTER(max));

	sprintf(key, "00:00:00:00:00:%02X", 1);
	g_assert(textfile_del(test_pathname, key) == 0);

	sprintf(key, "00:00:00:00:00:%02X", max);
	g_assert(textfile_del(test_pathname, key) == 0);

	sprintf(key, "00:00:00:00:00:%02X", max + 1);
	g_assert(textfile_del(test_pathname, key) == 0);

	textfile_foreach(test_pathname, check_entry, GUINT_TO_POINTER(max));
	tester_test_passed();
}