Exemplo n.º 1
0
bool XMPPAccountHandler::tearDown()
{
	if (m_pConnection)
	{
		// unregister and destroy the message handler callbacks
		if (m_pPresenceHandler)
		{
			lm_connection_unregister_message_handler(m_pConnection, m_pPresenceHandler, LM_MESSAGE_TYPE_PRESENCE);
			lm_message_handler_unref(m_pPresenceHandler);
			m_pPresenceHandler = NULL;
		}
	
		if (m_pStreamErrorHandler)
		{
			lm_connection_unregister_message_handler(m_pConnection, m_pStreamErrorHandler, LM_MESSAGE_TYPE_STREAM_ERROR);
			lm_message_handler_unref(m_pStreamErrorHandler);
			m_pStreamErrorHandler = NULL;
		}

		if (m_pChatHandler)
		{
			lm_connection_unregister_message_handler(m_pConnection, m_pChatHandler, LM_MESSAGE_TYPE_MESSAGE);
			lm_message_handler_unref(m_pChatHandler);
			m_pChatHandler = NULL;
		}
	
		lm_connection_close(m_pConnection, NULL);
		lm_connection_unref(m_pConnection);
		m_pConnection = NULL;
	}
	m_bLoggedIn = false;
	return true;
}
Exemplo n.º 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);
}
Exemplo n.º 3
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 */
Exemplo n.º 4
0
void xmpp_request_storage(const gchar *storage)
{
  LmMessage *iq;
  LmMessageNode *query;
  LmMessageHandler *handler;
  int i;

  iq = lm_message_new_with_sub_type(NULL, LM_MESSAGE_TYPE_IQ,
                                    LM_MESSAGE_SUB_TYPE_GET);
  query = lm_message_node_add_child(iq->node, "query", NULL);
  lm_message_node_set_attribute(query, "xmlns", NS_PRIVATE);
  lm_message_node_set_attribute(lm_message_node_add_child
                                (query, "storage", NULL),
                                "xmlns", storage);

  for (i = 0;
       g_strcmp0(iq_request_storage_handlers[i].storagens, storage) != 0;
       ++i) ;

  handler = lm_message_handler_new(iq_request_storage_handlers[i].handler,
                                   NULL, FALSE);
  lm_connection_send_with_reply(lconnection, iq, handler, NULL);
  lm_message_handler_unref(handler);
  lm_message_unref(iq);
}
Exemplo n.º 5
0
// Destroy a MUC room
// room syntax: "room@server"
void xmpp_room_destroy(const char *room, const char *venue, const char *reason)
{
  LmMessage *iq;
  LmMessageHandler *handler;
  LmMessageNode *query, *x;

  if (!xmpp_is_online() || !room)
    return;

  iq = lm_message_new_with_sub_type(room, LM_MESSAGE_TYPE_IQ,
                                    LM_MESSAGE_SUB_TYPE_SET);
  query = lm_message_node_add_child(iq->node, "query", NULL);
  lm_message_node_set_attribute(query, "xmlns", NS_MUC_OWNER);
  x = lm_message_node_add_child(query, "destroy", NULL);

  if (venue && *venue)
    lm_message_node_set_attribute(x, "jid", venue);

  if (reason)
    lm_message_node_add_child(x, "reason", reason);

  handler = lm_message_handler_new(handle_iq_dummy, NULL, FALSE);
  lm_connection_send_with_reply(lconnection, iq, handler, NULL);
  lm_message_handler_unref(handler);
  lm_message_unref(iq);
}
Exemplo n.º 6
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 ();
  }
}
Exemplo n.º 7
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;
}
Exemplo n.º 8
0
static LmHandlerResult
handler_function_c (LmMessageHandler* handler,
		    LmConnection* connection,
		    LmMessage* message,
		    handler_data* data)
{
  LmHandlerResult result = data->callback (connection, message);

  delete data;
  lm_message_handler_unref (handler);

  return result;
}
Exemplo n.º 9
0
int xmpp_room_setattrib(const char *roomid, const char *fjid,
                        const char *nick, struct role_affil ra,
                        const char *reason)
{
  LmMessage *iq;
  LmMessageHandler *handler;
  LmMessageNode *query, *x;

  if (!xmpp_is_online() || !roomid)
    return 1;
  if (!fjid && !nick) return 1;

  if (check_jid_syntax((char*)roomid)) {
    scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber id", roomid);
    return 1;
  }
  if (fjid && check_jid_syntax((char*)fjid)) {
    scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber id", fjid);
    return 1;
  }

  if (ra.type == type_affil && ra.val.affil == affil_outcast && !fjid)
    return 1; // Shouldn't happen (jid mandatory when banning)

  iq = lm_message_new_with_sub_type(roomid, LM_MESSAGE_TYPE_IQ,
                                    LM_MESSAGE_SUB_TYPE_SET);
  query = lm_message_node_add_child(iq->node, "query", NULL);
  lm_message_node_set_attribute(query, "xmlns", NS_MUC_ADMIN);
  x = lm_message_node_add_child(query, "item", NULL);

  if (fjid) {
    lm_message_node_set_attribute(x, "jid", fjid);
  } else { // nickname
    lm_message_node_set_attribute(x, "nick", nick);
  }

  if (ra.type == type_affil)
    lm_message_node_set_attribute(x, "affiliation", straffil[ra.val.affil]);
  else if (ra.type == type_role)
    lm_message_node_set_attribute(x, "role", strrole[ra.val.role]);

  if (reason)
    lm_message_node_add_child(x, "reason", reason);

  handler = lm_message_handler_new(handle_iq_dummy, NULL, FALSE);
  lm_connection_send_with_reply(lconnection, iq, handler, NULL);
  lm_message_handler_unref(handler);
  lm_message_unref(iq);

  return 0;
}
Exemplo n.º 10
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;
}
Exemplo n.º 11
0
static void
unregister_stanzas(XMPP_SERVER_REC *server)
{
	GSList *tmp, *next;

	if (!IS_XMPP_SERVER(server))
		return;
	for (tmp = server->msg_handlers; tmp != NULL; tmp = next) {
		next = tmp->next;
		if (lm_message_handler_is_valid(tmp->data))
			lm_message_handler_invalidate(tmp->data);
		lm_message_handler_unref(tmp->data);
		server->msg_handlers =
		    g_slist_remove(server->msg_handlers, tmp->data);
	}
}
Exemplo n.º 12
0
static void
rd_cleanup(struct register_data *rd)
{
	register_data = g_slist_remove(register_data, rd);
	g_free(rd->username);
	g_free(rd->domain);
	g_free(rd->password);
	g_free(rd->address);
	g_free(rd->id);
	if (rd->handler != NULL) {
		if (lm_message_handler_is_valid(rd->handler))
			lm_message_handler_invalidate(rd->handler);
		lm_message_handler_unref(rd->handler);
	}
	if (lm_connection_get_state(rd->lmconn) != LM_CONNECTION_STATE_CLOSED)
		lm_connection_close(rd->lmconn, NULL);
	lm_connection_unref(rd->lmconn);
	g_free(rd);
}
Exemplo n.º 13
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;
}
Exemplo n.º 14
0
// Warning!! xmlns has to be a namespace from iq_request_handlers[].xmlns
void xmpp_iq_request(const char *fulljid, const char *xmlns)
{
  LmMessage *iq;
  LmMessageNode *query;
  LmMessageHandler *handler;
  gpointer data = NULL;
  GDestroyNotify notifier = NULL;
  GError *error = NULL;
  int i;

  iq = lm_message_new_with_sub_type(fulljid, LM_MESSAGE_TYPE_IQ,
                                    LM_MESSAGE_SUB_TYPE_GET);
  for (i = 0; strcmp(iq_request_handlers[i].xmlns, xmlns) != 0 ; ++i)
       ;
  query = lm_message_node_add_child(iq->node,
                                    iq_request_handlers[i].querytag,
                                    NULL);
  lm_message_node_set_attribute(query, "xmlns", xmlns);

  if (!g_strcmp0(xmlns, NS_PING)) {     // Create handler for ping queries
    struct timeval *now = g_new(struct timeval, 1);
    gettimeofday(now, NULL);
    data = (gpointer)now;
    notifier = g_free;
  }

  handler = lm_message_handler_new(iq_request_handlers[i].handler,
                                   data, notifier);

  lm_connection_send_with_reply(lconnection, iq, handler, &error);
  lm_message_handler_unref(handler);
  lm_message_unref(iq);

  if (error) {
    scr_LogPrint(LPRINT_LOGNORM, "Error sending IQ request: %s.", error->message);
    g_error_free(error);
  }
}
Exemplo n.º 15
0
// Unlock a MUC room
// room syntax: "room@server"
void xmpp_room_unlock(const char *room)
{
  LmMessageNode *node;
  LmMessageHandler *handler;
  LmMessage *iq;

  if (!xmpp_is_online() || !room)
    return;

  iq = lm_message_new_with_sub_type(room, LM_MESSAGE_TYPE_IQ,
                                    LM_MESSAGE_SUB_TYPE_SET);

  node = lm_message_node_add_child(iq->node, "query", NULL);
  lm_message_node_set_attribute(node, "xmlns", NS_MUC_OWNER);
  node = lm_message_node_add_child(node, "x", NULL);
  lm_message_node_set_attributes(node, "xmlns", "jabber:x:data",
                                 "type", "submit", NULL);

  handler = lm_message_handler_new(handle_iq_dummy, NULL, FALSE);
  lm_connection_send_with_reply(lconnection, iq, handler, NULL);
  lm_message_handler_unref(handler);
  lm_message_unref(iq);
}