Example #1
0
int main(int argc, char* argv[])
{
  setlocale(LC_ALL, "");

  settings setting;
  try {
    if (!setting.load(argc, argv)) {
      return 0;
    }
  }
  catch (const boost::property_tree::ptree_error& error) {
    std::cerr << "Error: " << error.what() << std::endl;
    return 1;
  }
  catch (const boost::program_options::error& error) {
    std::cerr << "Error: " << error.what() << std::endl;
    return 1;
  }
  catch (const std::exception& error) {
    std::cerr << "Error: " << error.what() << std::endl;
    return 1;
  }

  print_setting(setting);

  if (setting.log_filename.size() != 0 && 
      !boost::filesystem::exists(setting.log_filename)) {
    std::cerr << "Log file path error " + setting.log_filename;
    setting.log_filename = "logs/" + setting.section + ".log";
  }

  init_log(setting.log_level, setting.log_filename);

  boost::asio::io_service ios;

  try {
    acceptor acceptor(ios, setting.local.host, setting.local.port,
                      setting.remote.host, setting.remote.port,
                      setting.cn,
                      certs_path(setting.cert_filename,
                      setting.key_filename,
                      setting.dh_filename));
    BLOG(info) << "accept connections on " 
               << setting.local.host << ":" << setting.local.port 
               << ", remote host " 
               << setting.remote.host << ":" << setting.remote.port;
    acceptor.accept_connections();
    ios.run();
  }
  catch(std::exception& e) {
    std::cerr << std::string("Error: ") + e.what() << std::endl;
    return 1;
  }

  return 0;
}
Example #2
0
void print_all_settings(void)
{
	setting_st *current_setting = settings_root;

	while (current_setting != NULL) {
		printf("all: ");
		print_setting(current_setting);
		current_setting = current_setting->next;
	}
}
Example #3
0
void free_setting(setting_st *setting)
{
	if (setting) {
#ifdef DEBUG
		printf("<<< freeing: ");
		print_setting(setting);
#endif
		if (setting->value)
			free(setting->value);
		free(setting);
		setting = NULL;
	}
}
Example #4
0
void print_routes(struct config_parse_state *state)
{
    int i, j;
    printf("\n==============================================\n");
    for ( i = 0; i < state->ar->num_mixer_paths; i++) {
        struct mixer_path mp = state->ar->mixer_path[i];
        printf("\nPATHe: %s\n", mp.name);
        for ( j = 0; j < mp.length; j++) {
            struct mixer_setting ms = mp.setting[j];
			print_setting(&ms);
        }
		printf("\n");
    }
}
static void
print_connection (const char *path)
{
	GDBusProxy *proxy;
	GError *error = NULL;
	GVariant *ret, *connection = NULL, *s_con = NULL;
	const char *id, *type;
	gboolean found;
	GVariantIter iter;
	const char *setting_name;
	GVariant *setting;

	/* This function asks NetworkManager for the details of the connection */

	/* Create the D-Bus proxy so we can ask it for the connection configuration details. */
	proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
	                                       G_DBUS_PROXY_FLAGS_NONE,
	                                       NULL,
	                                       NM_DBUS_SERVICE,
	                                       path,
	                                       NM_DBUS_INTERFACE_SETTINGS_CONNECTION,
	                                       NULL, NULL);
	g_assert (proxy);

	/* Request the all the configuration of the Connection */
	ret = g_dbus_proxy_call_sync (proxy,
	                              "GetSettings",
	                              NULL,
	                              G_DBUS_CALL_FLAGS_NONE, -1,
	                              NULL, &error);
	if (!ret) {
		g_dbus_error_strip_remote_error (error);
		g_warning ("Failed to get connection settings: %s\n", error->message);
		g_error_free (error);
		goto out;
	}

	g_variant_get (ret, "(@a{sa{sv}})", &connection);

	s_con = g_variant_lookup_value (connection, NM_SETTING_CONNECTION_SETTING_NAME, NULL);
	g_assert (s_con != NULL);
	found = g_variant_lookup (s_con, NM_SETTING_CONNECTION_ID, "&s", &id);
	g_assert (found);
	found = g_variant_lookup (s_con, NM_SETTING_CONNECTION_TYPE, "&s", &type);
	g_assert (found);

	/* Dump the configuration to stdout */
	g_print ("%s <=> %s\n", id, path);

	/* Connection setting first */
	print_setting (NM_SETTING_CONNECTION_SETTING_NAME, s_con);

	/* Then the type-specific setting */
	setting = g_variant_lookup_value (connection, type, NULL);
	if (setting) {
		print_setting (type, setting);
		g_variant_unref (setting);
	}

	g_variant_iter_init (&iter, connection);
	while (g_variant_iter_next (&iter, "{&s@a{sv}}", &setting_name, &setting)) {
		if (   strcmp (setting_name, NM_SETTING_CONNECTION_SETTING_NAME) != 0
		    && strcmp (setting_name, type) != 0)
			print_setting (setting_name, setting);
		g_variant_unref (setting);
	}
	g_print ("\n");

out:
	if (s_con)
		g_variant_unref (s_con);
	if (connection)
		g_variant_unref (connection);
	if (ret)
		g_variant_unref (ret);
	g_object_unref (proxy);
}