Ejemplo n.º 1
0
int parse_script_and_set_config(int argc, char *argv[],
                                struct config *config,
                                struct script *script,
                                const char *script_path,
                                const char *script_buffer)
{
	struct invocation invocation =
	{
		.argc = argc,
		.argv = argv,
		.config = config,
		.script = script,
	};

	DEBUGP("parse_and_run_script: %s\n", script_path);
	assert(script_path != NULL);

	init_script(script);

	set_default_config(config);
	config->script_path = strdup(script_path);

	if (script_buffer != NULL)
		copy_script(script_buffer, script);
	else
		read_script(script_path, script);

	return parse_script(config, script, &invocation);
}
Ejemplo n.º 2
0
void l2cap_sock_init(struct sock *sk, struct sock *parent)
{
	struct l2cap_pinfo *pi = l2cap_pi(sk);

	BT_DBG("sk %p parent %p", sk, parent);

	if (parent) {
		sk->sk_type = parent->sk_type;
		sk->sk_rcvbuf = parent->sk_rcvbuf;
		sk->sk_sndbuf = parent->sk_sndbuf;
		bt_sk(sk)->defer_setup = bt_sk(parent)->defer_setup;

		pi->imtu = l2cap_pi(parent)->imtu;
		pi->omtu = l2cap_pi(parent)->omtu;
		pi->conf_state = l2cap_pi(parent)->conf_state;
		pi->mode = l2cap_pi(parent)->mode;
		pi->fcs  = l2cap_pi(parent)->fcs;
		pi->max_tx = l2cap_pi(parent)->max_tx;
		pi->tx_win = l2cap_pi(parent)->tx_win;
		pi->sec_level = l2cap_pi(parent)->sec_level;
		pi->role_switch = l2cap_pi(parent)->role_switch;
		pi->force_reliable = l2cap_pi(parent)->force_reliable;
		pi->flushable = l2cap_pi(parent)->flushable;
		pi->force_active = l2cap_pi(parent)->force_active;
		pi->amp_pref = l2cap_pi(parent)->amp_pref;
	} else {
		pi->imtu = L2CAP_DEFAULT_MTU;
		pi->omtu = 0;
		if (!disable_ertm && sk->sk_type == SOCK_STREAM) {
			pi->mode = L2CAP_MODE_ERTM;
			pi->conf_state |= L2CAP_CONF_STATE2_DEVICE;
		} else {
			pi->mode = L2CAP_MODE_BASIC;
		}
		pi->reconf_state = L2CAP_RECONF_NONE;
		pi->max_tx = L2CAP_DEFAULT_MAX_TX;
		pi->fcs = L2CAP_FCS_CRC16;
		pi->tx_win = L2CAP_DEFAULT_TX_WINDOW;
		pi->sec_level = BT_SECURITY_LOW;
		pi->role_switch = 0;
		pi->force_reliable = 0;
		pi->flushable = 0;
		pi->force_active = 1;
		pi->amp_pref = BT_AMP_POLICY_REQUIRE_BR_EDR;
	}

	/* Default config options */
	sk->sk_backlog_rcv = l2cap_data_channel;
	pi->ampcon = NULL;
	pi->ampchan = NULL;
	pi->conf_len = 0;
	pi->flush_to = L2CAP_DEFAULT_FLUSH_TO;
	pi->scid = 0;
	pi->dcid = 0;
	pi->tx_win_max = L2CAP_TX_WIN_MAX_ENHANCED;
	pi->ack_win = pi->tx_win;
	pi->extended_control = 0;

	pi->local_conf.fcs = pi->fcs;
	pi->local_conf.flush_to = pi->flush_to;

	set_default_config(&pi->remote_conf);

	skb_queue_head_init(TX_QUEUE(sk));
	skb_queue_head_init(SREJ_QUEUE(sk));
}
Ejemplo n.º 3
0
/* Handle a wire connection from a client. */
static void *wire_server_thread(void *arg)
{
	struct wire_server *wire_server = (struct wire_server *)arg;
	struct netdev *netdev = NULL;
	char *error = NULL;

	DEBUGP("wire_server_thread\n");

	set_default_config(&wire_server->config);

	if (wire_server_receive_args(wire_server))
		goto error_done;

	if (wire_server_receive_script_path(wire_server))
		goto error_done;

	if (wire_server_receive_script(wire_server))
		goto error_done;

	if (wire_server_receive_hw_address(wire_server))
		goto error_done;

	if (parse_script_and_set_config(wire_server->argc,
						wire_server->argv,
						&wire_server->config,
						&wire_server->script,
						wire_server->script_path,
						wire_server->script_buffer))
		goto error_done;

	set_scheduling_priority();
	lock_memory();

	netdev =
	  wire_server_netdev_new(&wire_server->config,
				 wire_server->wire_server_device,
				 &wire_server->client_ether_addr,
				 &wire_server->server_ether_addr);

	wire_server->state = state_new(&wire_server->config,
					       &wire_server->script,
					       netdev);

	if (wire_server_send_server_ready(wire_server))
		goto error_done;

	if (wire_server_receive_client_starting(wire_server))
		goto error_done;

	if (wire_server_run_script(wire_server, &error))
		goto error_done;

	DEBUGP("wire_server_thread: finished test successfully\n");

error_done:
	if (error != NULL)
		fprintf(stderr, "%s\n", error);

	if (wire_server->state != NULL)
		state_free(wire_server->state, 0);

	DEBUGP("wire_server_thread: connection is done\n");
	wire_server_free(wire_server);
	return NULL;
}
Ejemplo n.º 4
0
// TODO: error handling
// TODO: better exit point handling
// (freeing resources for valgrind-cleanliness is too tedious at the moment)
void options_parse(int argc, char * argv[], struct Options * options) {
	int opt;
	// modified when config is loaded on the command line
	config_t config;
	config_init(&config);
	set_default_config(&config);

	// only to used for -g: print default config
	config_t config_default;
	config_init(&config_default);
	set_default_config(&config_default);

	// -i flag should only print options after all other
	// command line arguments have been applied
	bool print_options = false;

	while (-1 != (opt = getopt(argc, argv, OPTSTR))) {
		switch (opt) {
			case 'c':
				config_set_auto_convert(&config, CONFIG_TRUE);

				if (CONFIG_FALSE == config_read_file(&config, optarg)) {
					// failure reporting
					fprintf(stderr, "Failed to use config file '%s'!\n", optarg);
					switch (config_error_type(&config)) {
						case CONFIG_ERR_NONE:
							fprintf(stderr, "\tno error reported\n"
									"\t(This might be a libconfig problem.)\n");
							break;
						case CONFIG_ERR_FILE_IO:
							fprintf(stderr, "\tfile I/O error\n");
							break;
						case CONFIG_ERR_PARSE:
							fprintf(stderr, "\tparse error on line %d:\n"
									"\t%s\n",
									config_error_line(&config),
									config_error_text(&config));
							break;
						default:
							fprintf(stderr, "\tunknown error\n"
									"\t(A new libconfig version might have introduced"
									" new kinds of warnings.)\n");
					}
				}
				break;
			case 'g':
				config_write(&config_default, stdout);
				// be valgrind-clean
				config_destroy(&config_default);
				config_destroy(&config);
				exit(EXIT_SUCCESS);
				break;
			case 'i':
				print_options = true;
				break;
			default: /* '?' 'h' */
				options_help(*argv);
				// be valgrind-clean
				config_destroy(&config_default);
				config_destroy(&config);
				exit(EXIT_FAILURE);
		}
	}

	config2options(&config, options);
	// be valgrind-clean
	config_destroy(&config_default);
	config_destroy(&config);

	if (print_options)
		options_print(stderr, "", options);
}
Ejemplo n.º 5
0
/* loads configuration from .gnome/Etherape */
void load_config(void)
{
  gchar *pref_file;
  gchar *tmpstr = NULL;
  gchar **colorarray;
  GKeyFile *gkey;

  /* first reset configurations to defaults */
  set_default_config(&pref);

  gkey = g_key_file_new();

  /* tries to read config from file (~/.config/etherape) */
  pref_file = config_file_name();
  if (!g_key_file_load_from_file(gkey, pref_file, G_KEY_FILE_NONE, NULL))
    {
      /* file not found, try old location (~/.gnome2/Etherape) */
      g_free(pref_file);
      pref_file = old_config_file_name();
      if (!g_key_file_load_from_file(gkey, pref_file, G_KEY_FILE_NONE, NULL))
        {
          g_free(pref_file);
          return; 
        }
    }
  g_free(pref_file);

  read_string_config(&pref.filter, gkey, "filter");
  read_string_config(&pref.fontname, gkey, "fontname");
  read_string_config(&pref.text_color, gkey, "text_color");
  read_string_config(&pref.center_node, gkey, "center_node");

  read_boolean_config(&pref.diagram_only, gkey, "diagram_only");
  read_boolean_config(&pref.group_unk, gkey, "group_unk");
  read_boolean_config(&pref.stationary, gkey, "stationary");
  read_boolean_config(&pref.name_res, gkey, "name_res");
  read_int_config((gint *)&pref.refresh_period, gkey, "refresh_period");
  read_int_config((gint *)&pref.size_mode, gkey, "size_mode");
  read_int_config((gint *)&pref.node_size_variable, gkey, "node_size_variable");
  read_int_config((gint *)&pref.stack_level, gkey, "stack_level");

  read_double_config(&pref.node_timeout_time, gkey, "node_timeout_time"); 
  read_double_config(&pref.gui_node_timeout_time, gkey, "gui_node_timeout_time");
  read_double_config(&pref.proto_node_timeout_time, gkey, "proto_node_timeout_time");
  read_double_config(&pref.link_timeout_time, gkey, "link_timeout_time");
  read_double_config(&pref.gui_link_timeout_time, gkey, "gui_link_timeout_time");
  read_double_config(&pref.proto_link_timeout_time, gkey, "proto_link_timeout_time");
  read_double_config(&pref.proto_timeout_time, gkey, "proto_timeout_time");
  read_double_config(&pref.averaging_time, gkey, "averaging_time");
  read_double_config(&pref.node_radius_multiplier, gkey, "node_radius_multiplier");
  read_double_config(&pref.link_node_ratio, gkey, "link_node_ratio");

  read_string_config(&tmpstr, gkey, "colors");
  if (tmpstr)
    {
      colorarray = g_strsplit(tmpstr, " ", 0);
      if (colorarray)
        {
          g_strfreev(pref.colors);
          pref.colors = protohash_compact(colorarray);
          protohash_read_prefvect(pref.colors);
        }
      g_free(tmpstr);
    }

  /* if needed, read the config version 
  version = g_key_file_get_string(gkey, "General", "version");
  ... do processing here ...
  g_free(version);
  */

  g_key_file_free(gkey);
}				/* load_config */