Exemple #1
0
					/* SET ATTRIBUTES ON A WINDOW */
void wsetattr( WINDOW *w, int att )
{	char	tmp[100];
	if ( w->attribute > _BLINK + _BOLD + _REVERSE + _UNDERLINE
			|| w->attribute < 0 )
		{failure( "illegal attribute %d", w->attribute );
		}
	w->attribute |= att;
	if ( 0 != debug_pcurses )
		{sprintf( tmp, "wsetattr %d ", w->index );
		list_attributes( tmp, w->attribute );
		inform( tmp );
		}
}
Exemple #2
0
static void list_attributes(const char *path, GList *source)
{
	GList *l;

	for (l = source; l; l = g_list_next(l)) {
		GDBusProxy *proxy = l->data;
		const char *proxy_path;

		proxy_path = g_dbus_proxy_get_path(proxy);

		if (!g_str_has_prefix(proxy_path, path))
			continue;

		if (source == services) {
			print_service(proxy, NULL);
			list_attributes(proxy_path, characteristics);
		} else if (source == characteristics) {
			print_characteristic(proxy, NULL);
			list_attributes(proxy_path, descriptors);
		} else if (source == descriptors)
			print_descriptor(proxy, NULL);
	}
}
Exemple #3
0
static void lsattr_args (const char * name)
{
	STRUCT_STAT	st;

	if (LSTAT (name, &st) == -1)
		com_err (program_name, errno, _("while trying to stat %s"),
			 name);
	else {
		if (S_ISDIR(st.st_mode) && !dirs_opt)
			iterate_on_dir (name, lsattr_dir_proc, NULL);
		else
			list_attributes (name);
	}
}
Exemple #4
0
static int lsattr_args (const char * name)
{
	STRUCT_STAT	st;
	int retval = 0;

	if (LSTAT (name, &st) == -1) {
		com_err (program_name, errno, _("while trying to stat %s"),
			 name);
		retval = -1;
	} else {
		if (S_ISDIR(st.st_mode) && !dirs_opt)
			retval = iterate_on_dir (name, lsattr_dir_proc, NULL);
		else
			retval = list_attributes (name);
	}
	return retval;
}
Exemple #5
0
void gatt_list_attributes(const char *path)
{
	list_attributes(path, services);
}
Exemple #6
0
int main(int argc, char **argv)
{
	int retval = 0;
	struct switch_dev *dev;
	struct switch_attr *a;
	struct switch_val val;
	int err;
	int i;

	int cmd = CMD_NONE;
	char *cdev = NULL;
	int cport = -1;
	int cvlan = -1;
	char *ckey = NULL;
	char *cvalue = NULL;

	if(argc < 4)
		print_usage();

	if(strcmp(argv[1], "dev"))
		print_usage();

	cdev = argv[2];

	for(i = 3; i < argc; i++)
	{
		char *arg = argv[i];
		if (cmd != CMD_NONE) {
			print_usage();
		} else if (!strcmp(arg, "port") && i+1 < argc) {
			cport = atoi(argv[++i]);
		} else if (!strcmp(arg, "vlan") && i+1 < argc) {
			cvlan = atoi(argv[++i]);
		} else if (!strcmp(arg, "help")) {
			cmd = CMD_HELP;
		} else if (!strcmp(arg, "set") && i+1 < argc) {
			cmd = CMD_SET;
			ckey = argv[++i];
			if (i+1 < argc)
				cvalue = argv[++i];
		} else if (!strcmp(arg, "get") && i+1 < argc) {
			cmd = CMD_GET;
			ckey = argv[++i];
		} else if (!strcmp(arg, "load") && i+1 < argc) {
			if ((cport >= 0) || (cvlan >= 0))
				print_usage();
			cmd = CMD_LOAD;
			ckey = argv[++i];
		} else if (!strcmp(arg, "show")) {
			cmd = CMD_SHOW;
		} else {
			print_usage();
		}
	}

	if (cmd == CMD_NONE)
		print_usage();
	if (cport > -1 && cvlan > -1)
		print_usage();

	dev = swlib_connect(cdev);
	if (!dev) {
		fprintf(stderr, "Failed to connect to the switch\n");
		return 1;
	}

	swlib_scan(dev);

	if (cmd == CMD_GET || cmd == CMD_SET) {
		if(cport > -1)
			a = swlib_lookup_attr(dev, SWLIB_ATTR_GROUP_PORT, ckey);
		else if(cvlan > -1)
			a = swlib_lookup_attr(dev, SWLIB_ATTR_GROUP_VLAN, ckey);
		else
			a = swlib_lookup_attr(dev, SWLIB_ATTR_GROUP_GLOBAL, ckey);

		if(!a)
		{
			fprintf(stderr, "Unknown attribute \"%s\"\n", ckey);
			goto out;
		}
	}

	switch(cmd)
	{
	case CMD_SET:
		if ((a->type != SWITCH_TYPE_NOVAL) &&
				(cvalue == NULL))
			print_usage();

		if(cvlan > -1)
			cport = cvlan;

		if(swlib_set_attr_string(dev, a, cport, cvalue) < 0)
		{
			fprintf(stderr, "failed\n");
			retval = -1;
			goto out;
		}
		break;
	case CMD_GET:
		if(cvlan > -1)
			val.port_vlan = cvlan;
		if(cport > -1)
			val.port_vlan = cport;
		if(swlib_get_attr(dev, a, &val) < 0)
		{
			fprintf(stderr, "failed\n");
			retval = -1;
			goto out;
		}
		print_attr_val(a, &val);
		putchar('\n');
		break;
	case CMD_LOAD:
		swconfig_load_uci(dev, ckey);
		break;
	case CMD_HELP:
		list_attributes(dev);
		break;
	case CMD_SHOW:
		if (cport >= 0 || cvlan >= 0) {
			if (cport >= 0)
				show_port(dev, cport);
			else
				show_vlan(dev, cvlan, false);
		} else {
			show_global(dev);
			for (i=0; i < dev->ports; i++)
				show_port(dev, i);
			for (i=0; i < dev->vlans; i++)
				show_vlan(dev, i, true);
		}
		break;
	}

out:
	swlib_free_all(dev);
	return 0;
}
Exemple #7
0
int main(int argc, char **argv)
{
	int retval = 0;
	struct switch_dev *dev;
	struct switch_attr *a;
	struct switch_val val;
	int err;
	int i;

	struct switch_port *ports;

	int cmd = 0;
	char *cdev = NULL;
	int cport = -1;
	int cvlan = -1;
	char *ckey = NULL;
	char *cvalue = NULL;
	int chelp = 0;

	if(argc < 4)
		print_usage();

	if(strcmp(argv[1], "dev"))
		print_usage();

	cdev = argv[2];

	for(i = 3; i < argc; i++)
	{
		int p;
		if(!strcmp(argv[i], "help"))
		{
			chelp = 1;
			continue;
		}
		if(i + 1 >= argc)
			print_usage();
		p = atoi(argv[i + 1]);
		if(!strcmp(argv[i], "port"))
		{
			cport = p;
		} else if(!strcmp(argv[i], "vlan"))
		{
			cvlan = p;
		} else if(!strcmp(argv[i], "set"))
		{
			if(argc <= i + 1)
				print_usage();
			cmd = SET;
			ckey = argv[i + 1];
			if (argc > i + 2)
				cvalue = argv[i + 2];
			else
				cvalue = NULL;
			i++;
		} else if(!strcmp(argv[i], "get"))
		{
			cmd = GET;
			ckey = argv[i + 1];
		} else{
			print_usage();
		}
		i++;
	}

	if(cport > -1 && cvlan > -1)
		print_usage();

	dev = swlib_connect(cdev);
	if (!dev) {
		fprintf(stderr, "Failed to connect to the switch\n");
		return 1;
	}

	ports = malloc(sizeof(struct switch_port) * dev->ports);
	memset(ports, 0, sizeof(struct switch_port) * dev->ports);
	swlib_scan(dev);

	if(chelp)
	{
		list_attributes(dev);
		goto out;
	}

	if(cport > -1)
		a = swlib_lookup_attr(dev, SWLIB_ATTR_GROUP_PORT, ckey);
	else if(cvlan > -1)
		a = swlib_lookup_attr(dev, SWLIB_ATTR_GROUP_VLAN, ckey);
	else
		a = swlib_lookup_attr(dev, SWLIB_ATTR_GROUP_GLOBAL, ckey);

	if(!a)
	{
		fprintf(stderr, "Unknown attribute \"%s\"\n", ckey);
		goto out;
	}

	switch(cmd)
	{
	case SET:
		if ((a->type != SWITCH_TYPE_NOVAL) &&
				(cvalue == NULL))
			print_usage();

		switch(a->type) {
		case SWITCH_TYPE_INT:
			val.value.i = atoi(cvalue);
			break;
		case SWITCH_TYPE_STRING:
			val.value.s = cvalue;
			break;
		case SWITCH_TYPE_PORTS:
			val.len = 0;
			while(cvalue && *cvalue)
			{
				ports[val.len].flags = 0;
				ports[val.len].id = strtol(cvalue, &cvalue, 10);
				while(*cvalue && !isspace(*cvalue)) {
					if (*cvalue == 't')
						ports[val.len].flags |= SWLIB_PORT_FLAG_TAGGED;
					cvalue++;
				}
				if (*cvalue)
					cvalue++;
				val.len++;
			}
			val.value.ports = ports;
			break;
		default:
			break;
		}
		if(cvlan > -1)
			val.port_vlan = cvlan;
		if(cport > -1)
			val.port_vlan = cport;
		if(swlib_set_attr(dev, a, &val) < 0)
		{
			fprintf(stderr, "failed\n");
			retval = -1;
			goto out;
		}
		break;
	case GET:
		if(cvlan > -1)
			val.port_vlan = cvlan;
		if(cport > -1)
			val.port_vlan = cport;
		if(swlib_get_attr(dev, a, &val) < 0)
		{
			fprintf(stderr, "failed\n");
			retval = -1;
			goto out;
		}
		switch(a->type) {
		case SWITCH_TYPE_INT:
			printf("%d\n", val.value.i);
			break;
		case SWITCH_TYPE_STRING:
			printf("%s\n", val.value.s);
			break;
		case SWITCH_TYPE_PORTS:
			for(i = 0; i < val.len; i++)
				printf("%d ", val.value.ports[i]);
			printf("\n");
			break;
		}
	}

out:
	swlib_free_all(dev);
	free(ports);

	return 0;
}