Exemplo n.º 1
0
/**
 * infinoted_startup_new:
 * @error: Location to store error information, if any.
 *
 * Creates parameters for starting an infinote daemon. This involves option
 * parsing, reading config files, reading or creating data for TLS
 * (private key and certificate).
 *
 * Returns: A new #InfinotedStartup. Free with infinoted_startup_free().
 */
InfinotedStartup*
infinoted_startup_new(int* argc,
                      char*** argv,
                      GError** error)
{
  InfinotedStartup* startup;

  if(!inf_init(error))
    return NULL;

  startup = g_slice_new(InfinotedStartup);
  startup->options = NULL;
  startup->log = NULL;
  startup->private_key = NULL;
  startup->certificates = NULL;
  startup->credentials = NULL;
  startup->sasl_context = NULL;

  if(infinoted_startup_load(startup, argc, argv, error) == FALSE)
  {
    infinoted_startup_free(startup);
    return NULL;
  }

  startup->keepalive.mask =
    INF_KEEPALIVE_ENABLED | INF_KEEPALIVE_TIME | INF_KEEPALIVE_INTERVAL;
  startup->keepalive.enabled = TRUE;
  startup->keepalive.time = 60;
  startup->keepalive.interval = 5;

  return startup;
}
int
main(int argc,
     char** argv)
{
  const InfTestCertificateValidateDesc* test;
  GError* error;
  int res;

  error = NULL;
  if(inf_init(&error) == FALSE)
  {
    fprintf(stderr, "%s\n", error->message);
    g_error_free(error);
    return EXIT_FAILURE;
  }

  /* So that the certificate files are found */
  chdir("certs");

  res = EXIT_SUCCESS;
  for(test = TESTS; test->name != NULL; ++test)
  {
    printf("%s...", test->name);

    error = NULL;
    if(inf_test_certificate_validate_run(test, &error) == FALSE)
    {
      printf(" %s\n", error->message);
      g_error_free(error);
      res = EXIT_FAILURE;
    }
    else
    {
      printf(" OK\n");
    }
  }

  return res;
}
Exemplo n.º 3
0
int
main(int argc,
     char* argv[])
{
    InfTestMassJoin massjoin;
    GError* error;
    int i;
    gchar* name;

    error = NULL;
    if(!inf_init(&error))
    {
        fprintf(stderr, "%s\n", error->message);
        return -1;
    }

    massjoin.io = INF_IO(inf_standalone_io_new());
    massjoin.joiners = NULL;

    for(i = 0; i < 128; ++i)
    {
        name = g_strdup_printf("MassJoin%03d", i);

        inf_test_mass_join_connect(
            &massjoin,
            "127.0.0.1",
            inf_protocol_get_default_port(),
            "Test",
            name
        );

        g_free(name);
        //g_usleep(100000);
    }

    inf_standalone_io_loop(INF_STANDALONE_IO(massjoin.io));
    return 0;
}
Exemplo n.º 4
0
int main(int argc, char* argv[])
{
  InfStandaloneIo* io;
  InfNameResolver* resolver;
  InfTcpConnection* connection;
  GError* error;

  error = NULL;
  if(inf_init(&error) == FALSE)
  {
    fprintf(stderr, "%s", error->message);
    g_error_free(error);
    return 1;
  }

  io = inf_standalone_io_new();

  resolver =
    inf_name_resolver_new(INF_IO(io), "0x539.de", "5223", "_jabber._tcp");

  g_signal_connect(
    G_OBJECT(resolver),
    "resolved",
    G_CALLBACK(resolved_cb),
    io
  );

  connection = inf_tcp_connection_new_resolve(INF_IO(io), resolver);
  g_object_unref(resolver);

  g_signal_connect(
    G_OBJECT(connection),
    "received",
    G_CALLBACK(received_cb),
    io
  );

  g_signal_connect(
    G_OBJECT(connection),
    "sent",
    G_CALLBACK(sent_cb),
    io
  );

  g_signal_connect(
    G_OBJECT(connection),
    "error",
    G_CALLBACK(error_cb),
    io
  );

  g_signal_connect(
    G_OBJECT(connection),
    "notify::status",
    G_CALLBACK(notify_status_cb),
    io
  );

  if(inf_tcp_connection_open(connection, &error) == FALSE)
  {
    fprintf(stderr, "Could not open connection: %s\n", error->message);
    g_error_free(error);
  }
  else
  {
    inf_standalone_io_loop(io);
  }

  g_object_unref(G_OBJECT(io));
  g_object_unref(G_OBJECT(connection));

  return 0;
}
Exemplo n.º 5
0
int main(int argc, char* argv[]) try
{
	g_thread_init(NULL);
	Gio::init();

	setlocale(LC_ALL, "");
	bindtextdomain(GETTEXT_PACKAGE, gobby_localedir().c_str());
	bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");

	bool new_instance = false;
	bool display_version = false;
	std::vector<Glib::ustring> hostnames;

	Glib::OptionGroup opt_group_gobby("gobby",
		_("Gobby options"), _("Options related to Gobby"));
	Glib::OptionEntry opt_version;
	opt_version.set_short_name('v');
	opt_version.set_long_name("version");
	opt_version.set_description(
		_("Display version information and exit"));
	opt_group_gobby.add_entry(opt_version, display_version);

	Glib::OptionEntry opt_new_instance;
	opt_new_instance.set_short_name('n');
	opt_new_instance.set_long_name("new-instance");
	opt_new_instance.set_description(
		_("Also start a new Gobby instance when there is one "
		  "running already"));
	opt_group_gobby.add_entry(opt_new_instance, new_instance);

	Glib::OptionEntry opt_connect;
	opt_connect.set_short_name('c');
	opt_connect.set_long_name("connect");
	opt_connect.set_description(
		_("Connect to given host on startup, can be given multiple times"));
	opt_connect.set_arg_description(_("HOSTNAME"));
	opt_group_gobby.add_entry(opt_connect, hostnames);

	Glib::OptionContext opt_ctx;
	opt_ctx.set_help_enabled(true);
	opt_ctx.set_ignore_unknown_options(false);
	opt_ctx.set_main_group(opt_group_gobby);

	// I would rather like to have Gtk::Main on the stack, but I see
	// no other chance to catch exceptions from the command line option
	// parsing. armin.
	// TODO: Maybe we should parse before initializing GTK+, using
	// Gtk::Main::add_gtk_option_group() with open_default_display set
	// to false.
	std::auto_ptr<Gtk::Main> kit;

	try
	{
		kit.reset(new Gtk::Main(argc, argv, opt_ctx));
	}
	catch(Glib::Exception& e)
	{
		// Protect for non-UTF8 command lines (GTK probably already
		// converts to UTF-8 in case the system locale is not UTF-8,
		// but it can happen that input is given not in the system
		// locale, or simply invalid UTF-8. In that case, printing
		// e.what() on stdout would throw another exception, which we
		// want to avoid here, because otherwise we would want to
		// show that exception in an error dialog, but GTK+ failed
		// to initialize.
		if(e.what().validate())
			std::cerr << e.what() << std::endl;
		else
			std::cerr << "Invalid input on command line" << std::endl;

		return EXIT_FAILURE;
	}

	if(display_version)
	{
		std::cout << "Gobby " << PACKAGE_VERSION << std::endl;
		return EXIT_SUCCESS;
	}

#ifdef WITH_UNIQUE
	UniqueApp* app = unique_app_new_with_commands(
		"de._0x539.gobby", NULL,
		"UNIQUE_GOBBY_CONNECT", Gobby::UNIQUE_GOBBY_CONNECT,
		NULL);

	if(!new_instance && unique_app_is_running(app))
	{
		int exit_code = my_unique_check_other(
			app,
			argc - 1, argv + 1,
			hostnames);
		g_object_unref(app);
		return exit_code;
	}
#endif // WITH_UNIQUE

	GError* error = NULL;
	if(!inf_init(&error))
	{
		std::string message = error->message;
		g_error_free(error);
		throw std::runtime_error(message);
	}

	// Read the configuration
	Gobby::Config config(Gobby::config_filename("config.xml"));
	Gobby::Preferences preferences(config);
	Gobby::CertificateManager cert_manager(preferences);
	Gobby::IconManager icon_manager;

	// Set default icon
	Gtk::Window::set_default_icon_name("gobby-0.5");

	// Open a scope here, so that the main window is destructed
	// before we serialize the preferences, so that if the window
	// sets options at destruction time, they are stored correctly.
	{
		// Create window
		Gobby::Window wnd(
			argc-1,
			argv+1,
			config,
			preferences,
			icon_manager,
			cert_manager
#ifdef WITH_UNIQUE
			, app
#endif
			);

#ifdef WITH_UNIQUE
		g_object_unref(app);
#endif

		wnd.show();

		for(std::vector<Glib::ustring>::const_iterator i =
			hostnames.begin();
		    i != hostnames.end(); ++ i)
		{
			wnd.connect_to_host(*i);
		}

		wnd.signal_hide().connect(sigc::ptr_fun(&Gtk::Main::quit) );
		kit->run();
	}

	preferences.serialize(config);

	//inf_deinit();
	return 0;
}
catch(Glib::Exception& e)
{
	handle_exception(e.what() );
}
catch(std::exception& e)
{
	handle_exception(e.what() );
}
int
main(int argc, char* argv[])
{
  InfTestCertificateRequest test;
  InfIpAddress* address;
  InfCommunicationManager* manager;
  InfTcpConnection* tcp_conn;
  GError* error;

  error = NULL;
  inf_init(NULL);
/*  gnutls_global_init();
  g_type_init();*/

  test.key = NULL;
  test.io = inf_standalone_io_new();
  address = inf_ip_address_new_loopback4();

  tcp_conn =
    inf_tcp_connection_new_and_open(INF_IO(test.io), address, inf_protocol_get_default_port(), &error);

  inf_ip_address_free(address);

  if(tcp_conn == NULL)
  {
    fprintf(stderr, "Could not open TCP connection: %s\n", error->message);
    g_error_free(error);
  }
  else
  {
    test.conn = inf_xmpp_connection_new(
      tcp_conn,
      INF_XMPP_CONNECTION_CLIENT,
      NULL,
      "localhost",
      INF_XMPP_CONNECTION_SECURITY_BOTH_PREFER_TLS,
      NULL,
      NULL,
      NULL
    );

    g_object_unref(G_OBJECT(tcp_conn));

    manager = inf_communication_manager_new();
    test.browser = INF_BROWSER(
      infc_browser_new(
        INF_IO(test.io),
        manager,
        INF_XML_CONNECTION(test.conn)
      )
    );

    g_signal_connect_after(
      G_OBJECT(test.browser),
      "notify::status",
      G_CALLBACK(inf_test_certificate_request_notify_status_cb),
      &test
    );

    g_signal_connect(
      G_OBJECT(test.browser),
      "error",
      G_CALLBACK(inf_test_certificate_request_error_cb),
      &test
    );

    inf_standalone_io_loop(test.io);
    g_object_unref(G_OBJECT(manager));
    g_object_unref(G_OBJECT(test.browser));

    /* TODO: Wait until the XMPP connection is in status closed */
    g_object_unref(G_OBJECT(test.conn));
  }

  g_object_unref(G_OBJECT(test.io));
  if(test.key != NULL) gnutls_x509_privkey_deinit(test.key);
  return 0;
}
Exemplo n.º 7
0
int main(int argc, char* argv[])
{
  InfAdoptedSessionReplay* replay;
  InfAdoptedSession* session;
  GError* error;
  int i;
  int ret;

  InfBuffer* buffer;
  GSList* item;
  gint counter;

  if(argc < 2)
  {
    fprintf(stderr, "Usage: %s <record-file> [index]\n", argv[0]);
    return -1;
  }

  counter = 0;
  if(argc > 2) counter = atoi(argv[2]);

  error = NULL;
  if(!inf_init(&error))
  {
    fprintf(stderr, "%s\n", error->message);
    g_error_free(error);
    return -1;
  }

  ret = 0;
  for(i = 1; i < 2; ++ i)
  {
    replay = inf_adopted_session_replay_new();
    inf_adopted_session_replay_set_record(
      replay,
      argv[i],
      &INF_TEST_TEXT_RECOVER_TEXT_PLUGIN,
      &error
    );

    if(error != NULL)
    {
      fprintf(stderr, "%s\n", error->message);
      g_error_free(error);
      error = NULL;

      ret = -1;
    }
    else
    {
      session = inf_adopted_session_replay_get_session(replay);
      buffer = inf_session_get_buffer(INF_SESSION(session));

      g_signal_connect(
        buffer,
        "text-erased",
        G_CALLBACK(inf_test_text_recover_text_erased_cb),
        &counter
      );

      if(!inf_adopted_session_replay_play_to_end(replay, &error))
      {
        fprintf(stderr, "%s\n", error->message);
        g_error_free(error);
        error = NULL;

        ret = -1;
      }
      else if(counter == 0)
      {
        inf_test_util_print_buffer(INF_TEXT_BUFFER(buffer));
      }
    }

    g_object_unref(replay);
  }

  return ret;
}
Exemplo n.º 8
0
int main(int argc, char* argv[])
{
  InfStandaloneIo* io;
  InfdTcpServer* server;
  InfdXmppServer* xmpp;
  GError* error;

  error = NULL;
  if(!inf_init(&error))
  {
    fprintf(stderr, "%s\n", error->message);
    return 1;
  }

  io = inf_standalone_io_new();

  server = g_object_new(
    INFD_TYPE_TCP_SERVER,
    "io", io,
    "local-port", 5223,
    NULL
  );

  if(infd_tcp_server_open(server, &error) == FALSE)
  {
    fprintf(stderr, "Could not open server: %s\n", error->message);
    g_error_free(error);
  }
  else
  {
    xmpp = infd_xmpp_server_new(
      server,
      INF_XMPP_CONNECTION_SECURITY_ONLY_UNSECURED,
      NULL,
      NULL,
      NULL
    );

    g_signal_connect(
      G_OBJECT(xmpp),
      "error",
      G_CALLBACK(error_cb),
      io
    );

    g_signal_connect(
      G_OBJECT(xmpp),
      "new-connection",
      G_CALLBACK(new_connection_cb),
      io
    );

    g_signal_connect(
      G_OBJECT(xmpp),
      "notify::status",
      G_CALLBACK(notify_status_cb),
      io
    );

    inf_standalone_io_loop(io);
  }

  g_object_unref(G_OBJECT(io));
  g_object_unref(G_OBJECT(server));

  return 0;
}