예제 #1
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);
}
예제 #2
0
파일: xmpp_conn.c 프로젝트: tadzik/gtkabber
void
xmpp_connect() {
    GError *err = NULL;
    const gchar *conf_server;
    LmSSL *ssl;
    int use_ssl, use_tls, port;
    const gchar *jid;
    wantconnection = 1;
    if (connection && lm_connection_is_open(connection)) {
        ui_print("connect: connection alredy opened, aborting\n");
        return;
    }
    if (connection == NULL)
        connection = lm_connection_new(NULL);
    use_ssl = get_settings_int(USE_SSL);
    use_tls = get_settings_int(USE_TLS);
    jid = get_settings_str(JID);
    port = get_settings_int(PORT);
    if (use_ssl || use_tls) {
        if (!lm_ssl_is_supported()) {
            ui_print("Error: SSL not available\n");
        } else if (use_ssl && use_tls) {
            ui_print("Error: You can't use ssl and tls at the same time");
        } else {
            ssl = lm_ssl_new(NULL, ssl_cb, NULL, NULL);
            lm_ssl_use_starttls(ssl, !use_ssl, use_tls);
            lm_connection_set_ssl(connection, ssl);
            lm_ssl_unref(ssl);
        }
    }
    if (!port) {
        port = (use_ssl) ? LM_CONNECTION_DEFAULT_PORT_SSL
               : LM_CONNECTION_DEFAULT_PORT;
    }
    lm_connection_set_port(connection, port);
    lm_connection_set_jid(connection, jid);
    lm_connection_set_keep_alive_rate(connection, 30);
    lm_connection_set_disconnect_function(connection,
                                          connection_disconnect_cb,
                                          NULL, NULL);

    conf_server = get_settings_str(SERVER);
    if (!conf_server) {
        ui_print("ERROR: Insufficient configuration, "
                 "connecting aborted (server not set)\n");
        return;
    } else {
        if(!lm_connection_get_server(connection))
            lm_connection_set_server(connection, conf_server);
    }
    ui_print("Opening connection to %s\n", conf_server);
    if(!lm_connection_open(connection, (LmResultFunction)connection_open_cb,
                           NULL, NULL, &err)) {
        ui_print("Error opening connection: %s\n", err->message);
        g_error_free(err);
    }
} /* xmpp_connect */
예제 #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 ();
  }
}
예제 #4
0
static void
start_registration(struct register_data *rd)
{
	LmConnection  *lmconn;
	GError *error = NULL;

	lmconn = lm_connection_new(NULL);
	if (rd->use_ssl) {
		if (!set_ssl(lmconn, &error, NULL, FALSE))
			goto err;
	} else {
		if (!set_ssl(lmconn, &error, NULL, TRUE))
			goto err;
	}
	if (settings_get_bool("xmpp_use_proxy") && !set_proxy(lmconn, &error))
		goto err;
	if (rd->port <= 0)
		rd->port = rd->use_ssl ? LM_CONNECTION_DEFAULT_PORT_SSL
		    : LM_CONNECTION_DEFAULT_PORT;
	lm_connection_set_server(lmconn, rd->address);
	lm_connection_set_port(lmconn, rd->port);
	lm_connection_set_jid(lmconn, NULL);
	rd->id = NULL;
	rd->lmconn = lmconn;
	rd->handler = NULL;
	register_data = g_slist_prepend(register_data, rd);
	lm_connection_set_disconnect_function(lmconn, register_lm_close_cb,
	    rd, NULL);
	if (!lm_connection_open(lmconn, register_lm_open_cb, rd, NULL,
	    &error)) {
		rd_cleanup(rd);
		signal_emit("xmpp register error", 3, rd->username, rd->domain,
		    error != NULL ? error->message : NULL);
		if (error != NULL)
			g_error_free(error);
	}
	return;

err:
	signal_emit("xmpp register error", 3, rd->username, rd->domain,
	    error != NULL ? error->message : NULL);
	if (error != NULL)
		g_error_free(error);
	lm_connection_unref(lmconn);
}
예제 #5
0
void
xmpp_server_connect(XMPP_SERVER_REC *server)
{
	GError *error;
	const char *err_msg;

	if (!IS_XMPP_SERVER(server))
		return;
	error = NULL;
	err_msg = NULL;
	if (server->connrec->use_ssl) {
		if (!set_ssl(server->lmconn, &error, server, FALSE)) {
			err_msg = "Cannot init ssl";
			goto err;
		}
	} else
		set_ssl(server->lmconn, &error, server, TRUE);
	if (settings_get_bool("xmpp_use_proxy")
	    && !set_proxy(server->lmconn, &error)) {
		err_msg = "Cannot set proxy";
		goto err;
	}
	lm_connection_set_disconnect_function(server->lmconn,
	    lm_close_cb, server, NULL);
	lookup_servers = g_slist_append(lookup_servers, server);
	signal_emit("server looking", 1, server);
	server->timeout_tag = g_timeout_add(
	    settings_get_time("server_connect_timeout"),
	    (GSourceFunc)check_connection_timeout, server);
	if (!lm_connection_open(server->lmconn,  lm_open_cb, server,
	    NULL, &error)) {
		err_msg = "Connection failed";
		goto err;
	}
	return;

err:
	server->connection_lost = TRUE;
	if (error != NULL) {
		server_connect_failed(SERVER(server), error->message);
		g_error_free(error);
	} else
		server_connect_failed(SERVER(server), err_msg);
}
예제 #6
0
파일: IoLoudmouth.c 프로젝트: ADTSH/io
//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;
}
예제 #7
0
LM::Account::Account (boost::shared_ptr<Ekiga::PersonalDetails> details_,
		      boost::shared_ptr<Dialect> dialect_,
		      boost::shared_ptr<Cluster> cluster_,
		      const std::string name, const std::string user,
		      const std::string server, int port,
		      const std::string resource, const std::string password,
		      bool enable_on_startup):
  details(details_), dialect(dialect_), cluster(cluster_)
{
  status = _("inactive");

  node = xmlNewNode (NULL, BAD_CAST "entry");
  xmlSetProp (node, BAD_CAST "name", BAD_CAST name.c_str ());
  xmlSetProp (node, BAD_CAST "user", BAD_CAST user.c_str ());
  xmlSetProp (node, BAD_CAST "server", BAD_CAST server.c_str ());
  {
    std::stringstream sstream;
    sstream << port;
    xmlSetProp (node, BAD_CAST "port", BAD_CAST sstream.str ().c_str ());
  }
  xmlSetProp (node, BAD_CAST "resource", BAD_CAST resource.c_str ());
  xmlSetProp (node, BAD_CAST "password", BAD_CAST password.c_str ());

  if (enable_on_startup) {

    xmlSetProp (node, BAD_CAST "startup", BAD_CAST "true");
  } else {

    xmlSetProp (node, BAD_CAST "startup", BAD_CAST "false");
  }

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

    enable ();
  }
}