static void infd_xmpp_server_dispose(GObject* object) { InfdXmppServer* xmpp; InfdXmppServerPrivate* priv; xmpp = INFD_XMPP_SERVER(object); priv = INFD_XMPP_SERVER_PRIVATE(xmpp); if(priv->status != INFD_XMPP_SERVER_CLOSED) infd_xml_server_close(INFD_XML_SERVER(xmpp)); infd_xmpp_server_set_tcp(xmpp, NULL); if(priv->sasl_own_context != NULL) { inf_sasl_context_unref(priv->sasl_own_context); priv->sasl_own_context = NULL; } if(priv->sasl_context != NULL) { inf_sasl_context_unref(priv->sasl_context); priv->sasl_context = NULL; } if(priv->tls_creds != NULL) { inf_certificate_credentials_unref(priv->tls_creds); priv->tls_creds = NULL; } G_OBJECT_CLASS(parent_class)->dispose(object); }
void Gobby::Server::close() { g_assert(is_open()); if(m_xmpp6 != NULL) { // Will be removed from server pool automatically infd_xml_server_close(INFD_XML_SERVER(m_xmpp6)); g_object_unref(m_xmpp6); m_xmpp6 = NULL; } if(m_xmpp4 != NULL) { // Will be removed from server pool automatically infd_xml_server_close(INFD_XML_SERVER(m_xmpp4)); g_object_unref(m_xmpp4); m_xmpp4 = NULL; } }
void Gobby::Server::set_pool(InfdServerPool* pool) { if(m_pool != NULL) { if(m_xmpp4 != NULL) infd_server_pool_remove_server( m_pool, INFD_XML_SERVER(m_xmpp4)); if(m_xmpp6 != NULL) infd_server_pool_remove_server( m_pool, INFD_XML_SERVER(m_xmpp6)); g_object_unref(m_pool); } m_pool = pool; if(m_pool != NULL) { g_object_ref(m_pool); if(m_xmpp4 != NULL) { infd_server_pool_add_server( m_pool, INFD_XML_SERVER(m_xmpp4)); infd_server_pool_add_local_publisher( m_pool, m_xmpp4, m_publisher); } if(m_xmpp6 != NULL) { infd_server_pool_add_server( m_pool, INFD_XML_SERVER(m_xmpp6)); infd_server_pool_add_local_publisher( m_pool, m_xmpp6, m_publisher); } } }
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)); }
void Gobby::Server::open(unsigned int port, InfXmppConnectionSecurityPolicy security_policy, InfCertificateCredentials* creds, InfSaslContext* context, const char* sasl_mechanisms) { // If we can open one of tcp4 or tcp6 that's a success. InfdTcpServer* tcp4; InfdTcpServer* tcp6; // If the server is already open and we do not need to change the // port, then just change the credentials and SASL context without // doing anything else. if(is_open() && get_port() == port) { set_credentials(security_policy, creds); set_sasl_context(context, sasl_mechanisms); return; } static const guint8 ANY6_ADDR[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; InfIpAddress* any6 = inf_ip_address_new_raw6(ANY6_ADDR); tcp4 = INFD_TCP_SERVER(g_object_new( INFD_TYPE_TCP_SERVER, "io", m_io, "local-address", NULL, "local-port", port, NULL)); tcp6 = INFD_TCP_SERVER(g_object_new( INFD_TYPE_TCP_SERVER, "io", m_io, "local-address", any6, "local-port", port, NULL)); inf_ip_address_free(any6); if(!infd_tcp_server_open(tcp6, NULL)) { g_object_unref(tcp6); tcp6 = NULL; GError* error = NULL; if(!infd_tcp_server_open(tcp4, &error)) { g_object_unref(tcp4); const std::string message = error->message; g_error_free(error); throw std::runtime_error(message); } } else { if(!infd_tcp_server_open(tcp4, NULL)) { g_object_unref(tcp4); tcp4 = NULL; } } // We have the new server open, from this point on there is nothing // that can go wrong anymore. Therefore, close the old server and // take over the new one. if(is_open()) close(); InfXmppConnectionSecurityPolicy policy = INF_XMPP_CONNECTION_SECURITY_ONLY_UNSECURED; if(creds != NULL) policy = security_policy; if(tcp4) { m_xmpp4 = infd_xmpp_server_new( tcp4, security_policy, creds, context, sasl_mechanisms); g_object_unref(tcp4); } if(tcp6) { m_xmpp6 = infd_xmpp_server_new( tcp6, security_policy, creds, context, sasl_mechanisms); g_object_unref(tcp6); } if(m_pool) { if(m_xmpp4 != NULL) { infd_server_pool_add_server( m_pool, INFD_XML_SERVER(m_xmpp4)); infd_server_pool_add_local_publisher( m_pool, m_xmpp4, m_publisher); } if(m_xmpp6 != NULL) { infd_server_pool_add_server( m_pool, INFD_XML_SERVER(m_xmpp6)); infd_server_pool_add_local_publisher( m_pool, m_xmpp6, m_publisher); } } }