Example #1
0
static void
connection_auth_cb(LmConnection *c, gboolean success, gpointer udata) {
    if(!success) {
        ui_print("ERROR: Authentication failed\n");
    } else {
        LmMessageHandler *handler;
        handler = lm_message_handler_new(xmpp_iq_handler, NULL, NULL);
        lm_connection_register_message_handler(c, handler,
                                               LM_MESSAGE_TYPE_IQ,
                                               LM_HANDLER_PRIORITY_NORMAL);
        lm_message_handler_unref(handler);
        handler = lm_message_handler_new(xmpp_mesg_handler, NULL, NULL);
        lm_connection_register_message_handler(c, handler,
                                               LM_MESSAGE_TYPE_MESSAGE,
                                               LM_HANDLER_PRIORITY_NORMAL);
        lm_message_handler_unref(handler);
        handler = lm_message_handler_new(xmpp_pres_handler, NULL, NULL);
        lm_connection_register_message_handler(c, handler,
                                               LM_MESSAGE_TYPE_PRESENCE,
                                               LM_HANDLER_PRIORITY_NORMAL);
        lm_message_handler_unref(handler);
        xmpp_roster_request(c);
        g_timeout_add(60000, (GSourceFunc)reconnect, NULL);
    }
    lua_post_connect();
    UNUSED(udata);
} /* connection_auth_cb */
Example #2
0
void
ft_register_msg_handlers (LmConnection *conn)
{
        LmMessageHandler *handler = lm_message_handler_new ((LmHandleMessageFunction) ft_msg_msg_handler,
                                                            NULL, NULL);
        lm_connection_register_message_handler (conn, handler, LM_MESSAGE_TYPE_MESSAGE,
                                                LM_HANDLER_PRIORITY_NORMAL);
        lm_message_handler_unref (handler);


        handler = lm_message_handler_new ((LmHandleMessageFunction) ft_msg_presence_handler,
                                          NULL, NULL);
        lm_connection_register_message_handler (conn, handler, LM_MESSAGE_TYPE_PRESENCE,
                                                LM_HANDLER_PRIORITY_NORMAL);
        lm_message_handler_unref (handler);


        handler = lm_message_handler_new ((LmHandleMessageFunction) ft_msg_iq_handler,
                                          NULL, NULL);
        lm_connection_register_message_handler (conn, handler, LM_MESSAGE_TYPE_IQ,
                                                LM_HANDLER_PRIORITY_NORMAL);
        lm_message_handler_unref (handler);

        lm_connection_set_disconnect_function (conn, ft_disconnect_function, NULL, NULL);
}
Example #3
0
LM::Account::Account (boost::shared_ptr<Ekiga::PersonalDetails> details_,
		      boost::shared_ptr<Dialect> dialect_,
		      boost::shared_ptr<Cluster> cluster_,
		      xmlNodePtr node_):
  details(details_), dialect(dialect_), cluster(cluster_), node(node_)
{
  if (node == NULL) throw std::logic_error ("NULL node pointer received");

  status = _("inactive");

  xmlChar* xml_str = xmlGetProp (node, BAD_CAST "startup");
  bool enable_on_startup = false;
  if (xml_str != NULL) {

    if (xmlStrEqual (xml_str, BAD_CAST "true")) {

      enable_on_startup = true;
    } else {

      enable_on_startup = false;
    }
  }
  xmlFree (xml_str);

  connection = lm_connection_new (NULL);

  LmMessageHandler* iq_lm_handler = lm_message_handler_new ((LmHandleMessageFunction)iq_handler_c, this, NULL);
  lm_connection_register_message_handler (connection, iq_lm_handler, LM_MESSAGE_TYPE_IQ, LM_HANDLER_PRIORITY_NORMAL);
  lm_message_handler_unref (iq_lm_handler);

  LmMessageHandler* presence_lm_handler = lm_message_handler_new ((LmHandleMessageFunction)presence_handler_c, this, NULL);
  lm_connection_register_message_handler (connection, presence_lm_handler, LM_MESSAGE_TYPE_PRESENCE, LM_HANDLER_PRIORITY_NORMAL);
  lm_message_handler_unref (presence_lm_handler);

  LmMessageHandler* message_lm_handler = lm_message_handler_new ((LmHandleMessageFunction)message_handler_c, this, NULL);
  lm_connection_register_message_handler (connection, message_lm_handler, LM_MESSAGE_TYPE_MESSAGE, LM_HANDLER_PRIORITY_NORMAL);
  lm_message_handler_unref (message_lm_handler);

  lm_connection_set_disconnect_function (connection, (LmDisconnectFunction)on_disconnected_c,
					 this, NULL);
  if (enable_on_startup) {

    enable ();
  }
}
Example #4
0
void
xmpp_init (void)
{
  LmMessageHandler * handler;
  initialize_user_table();
  connection = lm_connection_new (NULL);
  handler = lm_message_handler_new (xmpp_presence_callback, NULL, NULL);
  lm_connection_register_message_handler (connection, handler, LM_MESSAGE_TYPE_PRESENCE, 0);
}
Example #5
0
void
lm_sasl_authenticate (LmSASL              *sasl,
		      const gchar         *username,
		      const gchar         *password,
		      const gchar         *server,
		      LmSASLResultHandler  handler)
{
	sasl->username   = g_strdup (username);
	sasl->password   = g_strdup (password);
	sasl->server     = g_strdup (server);
	sasl->handler    = handler;

	sasl->challenge_cb = lm_message_handler_new (sasl_challenge_cb,
						     sasl,
						     NULL);
	lm_connection_register_message_handler (sasl->connection,
						sasl->challenge_cb,
						LM_MESSAGE_TYPE_CHALLENGE,
						LM_HANDLER_PRIORITY_FIRST);
	
	sasl->success_cb = lm_message_handler_new (sasl_success_cb,
						   sasl,
						   NULL);
	lm_connection_register_message_handler (sasl->connection,
						sasl->success_cb,
						LM_MESSAGE_TYPE_SUCCESS,
						LM_HANDLER_PRIORITY_FIRST);

	sasl->failure_cb = lm_message_handler_new (sasl_failure_cb,
						   sasl,
						   NULL);
	lm_connection_register_message_handler (sasl->connection,
						sasl->failure_cb,
						LM_MESSAGE_TYPE_FAILURE,
						LM_HANDLER_PRIORITY_FIRST);

	if (sasl->features_received) {
		sasl_authenticate (sasl);
	} else {
		sasl->start_auth = TRUE;
	}
}
Example #6
0
int
main (int argc, char **argv)
{
        GMainLoop        *main_loop;
        LmConnection     *connection;
        LmMessageHandler *handler;
        gboolean          result;
        UserInfo         *info;
	LmProxy          *proxy; 
	guint             proxy_port;
                                                                                
        if (argc < 6) {
                g_print ("Usage: %s <server> <username> <password> <proxyserver> <proxyport>\n", argv[0]);
                return 1;
        }
                                                                                
        connection = lm_connection_new (argv[1]);

	proxy = lm_proxy_new (LM_PROXY_TYPE_HTTP);
	lm_proxy_set_server (proxy, argv[4]);

	proxy_port = strtol (argv[5], (char **) NULL, 10);
	lm_proxy_set_port (proxy, proxy_port);
	lm_connection_set_proxy (connection, proxy);
	lm_proxy_unref (proxy);
                                                                                
        handler = lm_message_handler_new (handle_messages, NULL, NULL);
        lm_connection_register_message_handler (connection, handler,
                                                LM_MESSAGE_TYPE_MESSAGE,
                                                LM_HANDLER_PRIORITY_NORMAL);
                                                                                
        lm_message_handler_unref (handler);
                                                                                
        info = g_new0 (UserInfo, 1);
        info->name = g_strdup (argv[2]);
        info->passwd = g_strdup (argv[3]);
                                                                                
        result = lm_connection_open (connection,
                                     (LmResultFunction) connection_open_cb,
                                     info, NULL, NULL);
                                                                                
        if (!result) {
                g_print ("Opening connection failed: %d\n", result);
        } else {
                g_print ("Returned from the connection_open\n");
        }
                                                                                
        main_loop = g_main_loop_new (NULL, FALSE);
        g_main_loop_run (main_loop);
                                                                                
        return 0;
}
Example #7
0
int
main (int argc, char **argv)
{
    GMainLoop        *main_loop;
    LmConnection     *connection;
    LmMessageHandler *handler;
    gboolean          result;
    UserInfo         *info;
    gchar            *jid;
                                                                                
    if (argc < 6) {
        g_print ("Usage: %s <server> <username> <password> <connectserver> <connectport>\n", argv[0]);
        return 1;
    }
                                                                                
    connection = lm_connection_new (argv[4]);

    jid = g_strdup_printf ("%s@%s", argv[2], argv[1]);
    lm_connection_set_jid (connection, jid);
    g_free (jid);

    lm_connection_set_port (connection, strtol (argv[5], (char **) NULL, 10));

    handler = lm_message_handler_new (handle_messages, NULL, NULL);
    lm_connection_register_message_handler (connection, handler,
                                            LM_MESSAGE_TYPE_MESSAGE,
                                            LM_HANDLER_PRIORITY_NORMAL);
                                                                                
    lm_message_handler_unref (handler);
                                                                                
    info = g_new0 (UserInfo, 1);
    info->name = g_strdup (argv[2]);
    info->passwd = g_strdup (argv[3]);
                                                                                
    result = lm_connection_open (connection,
                                 (LmResultFunction) connection_open_cb,
                                 info, NULL, NULL);
                                                                                
    if (!result) {
        g_print ("Opening connection failed: %d\n", result);
    } else {
        g_print ("Returned from the connection_open\n");
    }
                                                                                
    main_loop = g_main_loop_new (NULL, FALSE);
    g_main_loop_run (main_loop);
                                                                                
    return 0;
}
Example #8
0
static void
register_stanzas(XMPP_SERVER_REC *server)
{
	LmMessageHandler *h;
	int i;

	if (!IS_XMPP_SERVER(server))
		return;
	if (server->msg_handlers != NULL &&
	    g_slist_length(server->msg_handlers) != 0)
		unregister_stanzas(server);
	for(i = 0; message_types[i] != -1; ++i) {
		h = lm_message_handler_new(handle_stanza, server, NULL);
		lm_connection_register_message_handler(server->lmconn, h,
		    message_types[i], LM_HANDLER_PRIORITY_NORMAL);
		server->msg_handlers = g_slist_prepend(server->msg_handlers, h);
	}
}
Example #9
0
//doc Loudmouth connect Connects to the server. Returns <code>self</code>.
IoObject *IoLoudmouth_connect(IoLoudmouth *self, IoObject *locals, IoMessage *m) {
//  Q: Should we io_free() these?
  IoSeq* username   = IoObject_getSlot_(self, IOSYMBOL("username"));
  IoSeq* password   = IoObject_getSlot_(self, IOSYMBOL("password"));
  IoSeq* resource   = IoObject_getSlot_(self, IOSYMBOL("resource"));
  IoSeq* host       = IoObject_getSlot_(self, IOSYMBOL("host"));
  IoNumber* port    = IoObject_getSlot_(self, IOSYMBOL("port"));
  IoObject* use_ssl = IoObject_getSlot_(self, IOSYMBOL("useSsl"));

  IOASSERT(ISSEQ(username), "Loudmouth: username should be a Sequence");
  IOASSERT(ISSEQ(password), "Loudmouth: password should be a Sequence");
  IOASSERT(ISSEQ(resource), "Loudmouth: resource should be a Sequence");
  IOASSERT(ISSEQ(host),     "Loudmouth: host should be a Sequence");
  IOASSERT(ISNUMBER(port),  "Loudmouth: port should be a Number");

  if(LMCONN(self) == NULL) {
    LmConnection *connection = lm_connection_new_with_context(CSTRING(host), main_context);
    IoObject_setDataPointer_(self, connection);

    lm_connection_set_jid(connection, CSTRING(IoObject_getSlot_(self, IOSYMBOL("jid"))));
    lm_connection_set_port(connection, CNUMBER(port));

    if(ISTRUE(use_ssl) && lm_ssl_is_supported()) {
      LmSSL *ssl = lm_ssl_new(NULL, onSslError, NULL, NULL);
      lm_connection_set_ssl(connection, ssl);
      lm_ssl_unref(ssl);
    }

    LmMessageHandler* handler = lm_message_handler_new(onXmppMessage, self, NULL);
    lm_connection_register_message_handler(
      connection, handler,
      LM_MESSAGE_TYPE_MESSAGE, LM_HANDLER_PRIORITY_NORMAL
    );
    lm_message_handler_unref(handler);

    lm_connection_set_disconnect_function(connection, onXmppDisconnect, NULL, NULL);
  }

  lm_connection_open(LMCONN(self), onXmppConnect, self, NULL, NULL);
  return self;
}
Example #10
0
LmSASL *
lm_sasl_new (LmConnection *connection)
{
	LmSASL *sasl;
	
	sasl = g_new0 (LmSASL, 1);

	sasl->connection = connection;
	sasl->features_received = FALSE;
	sasl->start_auth = FALSE;

	sasl->features_cb = lm_message_handler_new (sasl_features_cb,
						    sasl,
						    NULL);

	lm_connection_register_message_handler (connection,
						sasl->features_cb,
						LM_MESSAGE_TYPE_STREAM_FEATURES,
						LM_HANDLER_PRIORITY_LAST);
	return sasl;
}
Example #11
0
File: harmony.c Project: KDE/amarok
void rebuild_connection(MP3tunesHarmony* harmony) {
    gchar* jid; 
    
    /*
    if (harmony->connection != NULL) {
        lm_connection_unref(harmony->connection);
        harmony->connection = NULL;
    }
    if (harmony->harmony_download_message_handler != NULL) {
        lm_message_handler_unref(harmony->harmony_download_message_handler);
        harmony->harmony_download_message_handler = NULL;
    }
    */
    harmony->connection = lm_connection_new(harmony->host);
    harmony->harmony_iq_message_handler = lm_message_handler_new(harmony_iq_callback, harmony, NULL);    

    lm_connection_set_port(harmony->connection, harmony->port);

    jid = mp3tunes_harmony_get_jid(harmony);
    g_debug("Logging in with: %s", jid);
    lm_connection_set_jid(harmony->connection, jid);
    g_free(jid);
    lm_connection_register_message_handler(harmony->connection, harmony->harmony_iq_message_handler, LM_MESSAGE_TYPE_IQ, LM_HANDLER_PRIORITY_LAST);
}
bool XMPPAccountHandler::setup()
{
	UT_DEBUGMSG(("XMPPAccountHandler::setup()\n"));

	UT_return_val_if_fail(m_pConnection, false);

	AbiCollabSessionManager* pManager = AbiCollabSessionManager::getManager();
	UT_return_val_if_fail(pManager, false);	

	// try to request a frame here; note that this might return 0, for example on application startup
	XAP_Frame *pFrame = XAP_App::getApp()->getLastFocussedFrame();

	const std::string server = getProperty("server");

	// Register message handler for presence messages
	m_pPresenceHandler = lm_message_handler_new((LmHandleMessageFunction)presence_handler, reinterpret_cast< gpointer >(this), NULL);
	lm_connection_register_message_handler(m_pConnection, m_pPresenceHandler, LM_MESSAGE_TYPE_PRESENCE, LM_HANDLER_PRIORITY_NORMAL);

	// Register message handler for stream error messages
	m_pStreamErrorHandler = lm_message_handler_new((LmHandleMessageFunction)stream_error_handler, reinterpret_cast< gpointer >(this), NULL);
	lm_connection_register_message_handler(m_pConnection, m_pStreamErrorHandler, LM_MESSAGE_TYPE_STREAM_ERROR, LM_HANDLER_PRIORITY_NORMAL);

	// Register message handler for chat messages
	m_pChatHandler = lm_message_handler_new((LmHandleMessageFunction)chat_handler, reinterpret_cast< gpointer >(this), NULL);
	lm_connection_register_message_handler(m_pConnection, m_pChatHandler, LM_MESSAGE_TYPE_MESSAGE, LM_HANDLER_PRIORITY_NORMAL);

	// Send presence message to server
	GError* error = NULL;
	LmMessage* m = lm_message_new_with_sub_type(NULL, LM_MESSAGE_TYPE_PRESENCE, LM_MESSAGE_SUB_TYPE_NOT_SET);
	if (!lm_connection_send(m_pConnection, m, &error)) 
	{
		UT_DEBUGMSG(("Presence message could not be sent: %s", error ? error->message : ""));
		lm_connection_close(m_pConnection, NULL);
		lm_connection_unref(m_pConnection);
		m_pConnection = NULL;
		
		// FIXME: unregister the message handlers!
		// ...
		
		if (pFrame)
		{
			// inform the user of the sending error
			// TODO: this shouldn't be here, the caller should handle this
			UT_UTF8String msg;
			// TODO: make this localizable
			UT_UTF8String_sprintf(msg, "Error while connecting to %s: %s\n", server.c_str(), (error ? error->message : "")); 
			pFrame->showMessageBox(msg.utf8_str(), XAP_Dialog_MessageBox::b_O, XAP_Dialog_MessageBox::a_OK);			
		}
		
		return false;
	}
	lm_message_unref(m);

	m_bLoggedIn = true;

	// we are connected now, time to start sending out messages (such as events)
	pManager->registerEventListener(this);
	// signal all listeners we are logged in
	AccountOnlineEvent event;
	// TODO: fill the event
	AbiCollabSessionManager::getManager()->signal(event);
		
	return true;;
}