void Gobby::AuthCommands::handle_error_detail(InfXmppConnection* xmpp, const GError* detail_error, Glib::ustring& old_password, Glib::ustring& last_password) { GError* error = NULL; switch(detail_error->code) { case INF_AUTHENTICATION_DETAIL_ERROR_AUTHENTICATION_FAILED: inf_xmpp_connection_retry_sasl_authentication(xmpp, &error); break; case INF_AUTHENTICATION_DETAIL_ERROR_TRY_AGAIN: old_password.swap(last_password); inf_xmpp_connection_retry_sasl_authentication(xmpp, &error); break; default: show_error(detail_error, m_statusbar, INF_XML_CONNECTION(xmpp)); break; } if(error) { show_error(error, m_statusbar, INF_XML_CONNECTION(xmpp)); g_error_free(error); } }
XmlConnection::Status XmlConnection::status() const { InfXmlConnectionStatus infStatus; Status status; InfXmlConnection *connection; connection = INF_XML_CONNECTION(gobject()); g_object_get( G_OBJECT(connection), "status", &infStatus, NULL ); switch( infStatus ) { case INF_XML_CONNECTION_CLOSED: status = Closed; break; case INF_XML_CONNECTION_CLOSING: status = Closing; break; case INF_XML_CONNECTION_OPEN: status = Open; break; case INF_XML_CONNECTION_OPENING: status = Opening; break; default: status = Closed; } return status; }
void XmlConnection::close() { InfXmlConnection *infXmlConnection; infXmlConnection = INF_XML_CONNECTION(gobject()); inf_xml_connection_close( infXmlConnection ); }
static void inf_user_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec) { InfUser* user; InfUserPrivate* priv; user = INF_USER(object); priv = INF_USER_PRIVATE(user); /* TODO: Check if properties are still valid. * There are several combinations possible: * * Status | Flags | Connection | Desc * UNAVAIL | 0 | unset | User not available, was non-local last time * AVAIL | 0 | unset | INVALID * UNAVAIL | LOCAL | unset | User not available, was local last time * AVAIL | LOCAL | unset | User is available, and local * UNAVAIL | 0 | set | INVALID * AVAIL | 0 | set | User is available, non-local * UNAVAIL | LOCAL | set | INVALID * AVAIL | LOCAL | set | INVALID */ switch(prop_id) { case PROP_ID: priv->id = g_value_get_uint(value); break; case PROP_NAME: g_free(priv->name); priv->name = g_value_dup_string(value); break; case PROP_STATUS: g_signal_emit( object, user_signals[SET_STATUS], 0, g_value_get_enum(value) ); break; case PROP_FLAGS: priv->flags = g_value_get_flags(value); break; case PROP_CONNECTION: if(priv->connection != NULL) g_object_unref(priv->connection); priv->connection = INF_XML_CONNECTION(g_value_dup_object(value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); break; } }
static void infd_xmpp_server_new_connection_cb(InfdTcpServer* tcp_server, InfTcpConnection* tcp_connection, gpointer user_data) { InfdXmppServer* xmpp_server; InfdXmppServerPrivate* priv; InfXmppConnection* xmpp_connection; InfIpAddress* addr; gchar* addr_str; xmpp_server = INFD_XMPP_SERVER(user_data); priv = INFD_XMPP_SERVER_PRIVATE(xmpp_server); /* TODO: We could perform a reverse DNS lookup to find the client hostname * here. */ g_object_get(G_OBJECT(tcp_connection), "remote-address", &addr, NULL); addr_str = inf_ip_address_to_string(addr); inf_ip_address_free(addr); xmpp_connection = inf_xmpp_connection_new( tcp_connection, INF_XMPP_CONNECTION_SERVER, priv->local_hostname, addr_str, priv->security_policy, priv->tls_creds, priv->sasl_context, priv->sasl_own_context != NULL ? "ANONYMOUS" : priv->sasl_mechanisms ); g_free(addr_str); /* We could, alternatively, keep the connection around until authentication * has completed and emit the new_connection signal after that, to guarantee * that the connection is open when new_connection is emitted. */ infd_xml_server_new_connection( INFD_XML_SERVER(xmpp_server), INF_XML_CONNECTION(xmpp_connection) ); g_object_unref(G_OBJECT(xmpp_connection)); }
InfBrowser* Gobby::Browser::connect_to_host(const InfIpAddress* address, guint port, unsigned int device_index, const std::string& hostname) { // Check whether we do have such a connection already: InfXmppConnection* xmpp = m_connection_manager.make_connection( address, port, device_index, hostname); // Should have thrown otherwise: g_assert(xmpp != NULL); // TODO: Remove erroneous entry with same name, if any, before // adding. InfBrowser* browser = inf_gtk_browser_store_add_connection( m_browser_store, INF_XML_CONNECTION(xmpp), hostname.c_str()); return browser; }
static void bookmark_added (GeditCollaborationWindowHelper *helper, GeditCollaborationBookmark *bookmark) { GResolver *resolver = g_resolver_get_default (); GList *addresses; InfTcpConnection *tcp; InfIpAddress *ipaddress; InfXmppConnection *connection; gchar *ipaddr; NameInfo *info; GeditCollaborationUser *user; /* TODO: make this asynchronous and be smarter about it */ addresses = g_resolver_lookup_by_name (resolver, gedit_collaboration_bookmark_get_host (bookmark), NULL, NULL); if (!addresses) { return; } ipaddr = g_inet_address_to_string ((GInetAddress *)addresses->data); g_resolver_free_addresses (addresses); ipaddress = inf_ip_address_new_from_string (ipaddr); g_free (ipaddr); tcp = inf_tcp_connection_new (helper->priv->io, ipaddress, (guint)gedit_collaboration_bookmark_get_port (bookmark)); user = gedit_collaboration_bookmark_get_user (bookmark); connection = inf_xmpp_connection_new (tcp, INF_XMPP_CONNECTION_CLIENT, NULL, gedit_collaboration_bookmark_get_host (bookmark), INF_XMPP_CONNECTION_SECURITY_BOTH_PREFER_TLS, helper->priv->certificate_credentials, gedit_collaboration_user_get_sasl_context (user), "ANONYMOUS PLAIN"); g_signal_connect (user, "request-password", G_CALLBACK (user_request_password), helper); inf_gtk_browser_store_add_connection (helper->priv->browser_store, INF_XML_CONNECTION (connection), gedit_collaboration_bookmark_get_name (bookmark)); g_object_set_data (G_OBJECT (connection), BOOKMARK_DATA_KEY, bookmark); inf_ip_address_free (ipaddress); g_object_unref (tcp); info = g_slice_new (NameInfo); info->helper = helper; info->connection = INF_XML_CONNECTION (connection); g_signal_connect_data (bookmark, "notify::name", G_CALLBACK (on_bookmark_name_changed), info, (GClosureNotify)name_info_free, 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; }
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)); } }