Ejemplo n.º 1
0
int
main(int argc, char* argv[])
{
  InfTestBrowser test;
  InfIpAddress* address;
  InfCommunicationManager* manager;
  InfTcpConnection* tcp_conn;
  GError* error;

  gnutls_global_init();
  g_type_init();

  test.io = inf_standalone_io_new();
#ifndef G_OS_WIN32
  test.input_fd = STDIN_FILENO;
#endif
  address = inf_ip_address_new_loopback4();

  error = NULL;
  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_browser_notify_status_cb),
      &test
    );

    g_signal_connect(
      G_OBJECT(test.browser),
      "error",
      G_CALLBACK(inf_test_browser_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));
  return 0;
}
Ejemplo n.º 2
0
static void
inf_test_mass_join_connect(InfTestMassJoin* massjoin,
                           const char* hostname,
                           guint port,
                           const char* document,
                           const char* username)
{
    InfIpAddress* addr;
    InfTcpConnection* tcp;
    InfXmppConnection* xmpp;
    InfTestMassJoiner* joiner;
    InfXmlConnection* xml;
    GError* error;

    addr = inf_ip_address_new_from_string(hostname);
    tcp = inf_tcp_connection_new(massjoin->io, addr, port);
    xmpp = inf_xmpp_connection_new(
               tcp,
               INF_XMPP_CONNECTION_CLIENT,
               g_get_host_name(),
               hostname,
               INF_XMPP_CONNECTION_SECURITY_BOTH_PREFER_TLS,
               NULL,
               NULL,
               NULL
           );

    joiner = g_slice_new(InfTestMassJoiner);
    joiner->communication_manager = inf_communication_manager_new();
    joiner->browser = infc_browser_new(
                          massjoin->io,
                          joiner->communication_manager,
                          INF_XML_CONNECTION(xmpp)
                      );
    joiner->session = NULL;
    joiner->document = g_strdup(document);
    joiner->username = g_strdup(username);

    g_object_unref(xmpp);
    g_object_unref(tcp);
    inf_ip_address_free(addr);

    massjoin->joiners = g_slist_prepend(massjoin->joiners, joiner);
    infc_browser_add_plugin(joiner->browser, &INF_TEST_MASS_JOIN_TEXT_PLUGIN);

    g_signal_connect(
        G_OBJECT(joiner->browser),
        "notify::status",
        G_CALLBACK(inf_test_mass_join_browser_notify_status_cb),
        massjoin
    );

    error = NULL;
    xml = infc_browser_get_connection(joiner->browser);
    if(inf_xml_connection_open(xml, &error) == FALSE)
    {
        fprintf(
            stderr,
            "Joiner %s: Failed to connect to %s: %s\n",
            joiner->username,
            hostname,
            error->message
        );

        g_error_free(error);
        massjoin->joiners = g_slist_remove(massjoin->joiners, joiner);

        if(massjoin->joiners == NULL)
            inf_standalone_io_loop_quit(INF_STANDALONE_IO(massjoin->io));
    }
}