示例#1
0
文件: xmpp.c 项目: phyw/Sigfaultbot
/*
 * Инициализация 
 */
gboolean jid_init(LmConnection *connect, const struct _jid *jid) {
  LmMessage       *m;
  LmMessageNode   *query, *storage;
  GError          *error = NULL;

  // <iq type='get'><query xmlns='jabber:iq:roster'/></iq>
  m = lm_message_new_with_sub_type(NULL, LM_MESSAGE_TYPE_IQ,
                        LM_MESSAGE_SUB_TYPE_GET);  
  query = lm_message_node_add_child(m->node, "query", NULL);
  lm_message_node_set_attributes(query, "xmlns", "jabber:iq:roster", NULL);

  if(!lm_connection_send(connect, m, &error)) {
      g_print ("Failed sent query 'xmlns=jabber:iq:roster', due to: %s\n",
                error->message);
      return FALSE;
  }
  
  // <iq type='get'><query xmlns='jabber:iq:private'><storage xmlns='storage:bookmarks'/></query></iq>
  m = lm_message_new_with_sub_type(NULL, LM_MESSAGE_TYPE_IQ,
                        LM_MESSAGE_SUB_TYPE_GET);  
  query = lm_message_node_add_child(m->node, "query", NULL);
  storage = lm_message_node_add_child(m->node, "storage", NULL);

  lm_message_node_set_attributes(query, "xmlns", "jabber:iq:private", NULL);
  lm_message_node_set_attributes(storage, "xmlns", "storage:bookmarks", NULL);

  if(!lm_connection_send(connect, m, &error)) {
      g_print ("Failed sent query 'jabber:iq:private', due to: %s\n",
                error->message);
      return FALSE;
  }

  // <iq type='get'><query xmlns='jabber:iq:private'><storage xmlns='storage:rosternotes'/></query></iq>
  m = lm_message_new_with_sub_type(NULL, LM_MESSAGE_TYPE_IQ,
                        LM_MESSAGE_SUB_TYPE_GET);
  query = lm_message_node_add_child(m->node, "query", NULL);
  storage = lm_message_node_add_child(m->node, "storage", NULL);

  lm_message_node_set_attributes(query, "xmlns", "jabber:iq:private", NULL);
  lm_message_node_set_attributes(storage, "xmlns", "storage:rosternotes", NULL);

  if(!lm_connection_send(connect, m, &error)) {
      g_print ("Failed sent second query 'jabber:iq:private', due to: %s\n",
                error->message);
      return FALSE;
  }
  
  lm_message_unref(m);
  return TRUE;
}
示例#2
0
文件: xmpp_iq.c 项目: weiss/mcabber
LmHandlerResult handle_iq_last(LmMessageHandler *h, LmConnection *c,
                               LmMessage *m, gpointer ud)
{
  LmMessage *r;
  LmMessageNode *query;
  char *seconds;

  if (!settings_opt_get_int("iq_hide_requests")) {
    scr_LogPrint(LPRINT_LOGNORM, "Received an IQ last time request from <%s>",
                 lm_message_get_from(m));
  }

  if (settings_opt_get_int("iq_last_disable") ||
      (settings_opt_get_int("iq_last_disable_when_notavail") &&
       xmpp_getstatus() == notavail))
  {
    send_iq_error(c, m, XMPP_ERROR_SERVICE_UNAVAILABLE);
    return LM_HANDLER_RESULT_REMOVE_MESSAGE;
  }

  r = lm_message_new_iq_from_query(m, LM_MESSAGE_SUB_TYPE_RESULT);
  query = lm_message_node_add_child(r->node, "query", NULL);
  lm_message_node_set_attribute(query, "xmlns", NS_LAST);
  seconds = g_strdup_printf("%.0f", seconds_since_last_use());
  lm_message_node_set_attribute(query, "seconds", seconds);
  g_free(seconds);

  lm_connection_send(c, r, NULL);
  lm_message_unref(r);
  return LM_HANDLER_RESULT_REMOVE_MESSAGE;
}
示例#3
0
文件: xmpp_iq.c 项目: jbar/mcabber
void send_iq_error(LmConnection *c, LmMessage *m, guint error)
{
  LmMessage *r;
  r = lm_message_new_iq_error(m, error);
  lm_connection_send(c, r, NULL);
  lm_message_unref(r);
}
示例#4
0
static void
connection_auth_cb (LmConnection *connection, 
                    gboolean      success, 
                    gpointer      user_data)
{
    if (success) {
        GError    *error = NULL;
        LmMessage *m;

        g_print ("LmSendAsync: Authenticated successfully\n");
        
        m = lm_message_new (recipient, LM_MESSAGE_TYPE_MESSAGE);
        lm_message_node_add_child (m->node, "body", message);
        
        if (!lm_connection_send (connection, m, &error)) {
            g_printerr ("LmSendAsync: Failed to send message:'%s'\n", 
                        lm_message_node_to_string (m->node));
        } else {
            g_print ("LmSendAsync: Sent message:'%s'\n", 
                     lm_message_node_to_string (m->node));
            test_success = TRUE;
        }
        
        lm_message_unref (m);
    } else {
        g_printerr ("LmSendAsync: Failed to authenticate\n");
    }

    lm_connection_close (connection, NULL);
    g_main_loop_quit (main_loop);
}
bool XMPPAccountHandler::_send(const char* base64data, XMPPBuddyPtr pBuddy)
{
	UT_return_val_if_fail(base64data, false);
	UT_return_val_if_fail(pBuddy, false);
	
	if (!m_pConnection)
		return false;
	
	GError* error = NULL;
	
	// TODO: make sure these properties are always there
	const std::string resource = getProperty("resource");
	const std::string server = getProperty("server");

	// fully qualified address
	std::string fqa = pBuddy->getAddress() + "/" + resource;

	UT_DEBUGMSG(("Sending packet |%s| to |%s|\n", base64data, fqa.c_str()));
	LmMessage* m = lm_message_new (fqa.c_str(), LM_MESSAGE_TYPE_MESSAGE);
	lm_message_node_add_child (m->node, "body", base64data);
	if (!lm_connection_send (m_pConnection, m, &error))
	{
		UT_DEBUGMSG(("Error while sending message to '%s':\n%s\n",
				base64data, (error ? error->message : "") ));
		lm_message_unref(m);
		return false;
	}
	lm_message_unref(m);
	return true;
}
示例#6
0
文件: xmpp_iq.c 项目: weiss/mcabber
LmHandlerResult handle_iq_disco_info(LmMessageHandler *h,
                                     LmConnection *c,
                                     LmMessage *m, gpointer ud)
{
  LmMessage *r;
  LmMessageNode *query, *tmp;
  const char *node = NULL;
  const char *param = NULL;

  if (lm_message_get_sub_type(m) == LM_MESSAGE_SUB_TYPE_RESULT)
    return LM_HANDLER_RESULT_REMOVE_MESSAGE;

  r = lm_message_new_iq_from_query(m, LM_MESSAGE_SUB_TYPE_RESULT);
  query = lm_message_node_add_child(r->node, "query", NULL);
  lm_message_node_set_attribute(query, "xmlns", NS_DISCO_INFO);
  tmp = lm_message_node_find_child(m->node, "query");
  if (tmp) {
    node = lm_message_node_get_attribute(tmp, "node");
    param = node+strlen(MCABBER_CAPS_NODE)+1;
  }
  if (node && startswith(node, MCABBER_CAPS_NODE "#", FALSE))
    disco_info_set_caps(query, param);  // client#version
  else
    // Basic discovery request
    disco_info_set_caps(query, NULL);

  lm_connection_send(c, r, NULL);
  lm_message_unref(r);
  return LM_HANDLER_RESULT_REMOVE_MESSAGE;
}
示例#7
0
static gboolean
sasl_digest_md5_send_initial_response (LmSASL *sasl, GHashTable *challenge)
{
	LmMessage *msg;
	gchar     *response;
	gchar     *response64;
	int        result;

	response = sasl_md5_prepare_response(sasl, challenge);
	if (response == NULL) {
		return FALSE;
	}

	response64 = base64_encode ((gchar *)response, strlen(response));

	msg = lm_message_new (NULL, LM_MESSAGE_TYPE_RESPONSE);
	lm_message_node_set_attributes (msg->node,
					"xmlns", XMPP_NS_SASL_AUTH,
					NULL);
	lm_message_node_set_value (msg->node, response64);

	result = lm_connection_send (sasl->connection, msg, NULL);

	g_free (response);
	g_free (response64);
	lm_message_unref (msg);

	if (!result) {
		return FALSE;
	}

	sasl->state = SASL_AUTH_STATE_DIGEST_MD5_SENT_AUTH_RESPONSE;

	return TRUE;
}
示例#8
0
文件: xmpp.c 项目: phyw/Sigfaultbot
/*
 * Выход из конференции
 */
gboolean leave_room(LmConnection *connect,
            const gchar* room_name, const gchar* nick, const gchar* leave_status) {
  LmMessage *m;
  gchar     *room_jid;
  GError    *error = NULL;

  room_jid = (gchar*)xcalloc(strlen(room_name)+strlen(nick)+2, sizeof(gchar));
  strcat(room_jid, room_name);
  strcat(room_jid, "/");
  strcat(room_jid, nick);
  
  // Создаём и отправляем сообщение о выходе
  m = lm_message_new_with_sub_type(room_jid, LM_MESSAGE_TYPE_PRESENCE, 
                                    LM_MESSAGE_SUB_TYPE_UNAVAILABLE);
  free(room_jid);

  if(leave_status)
    lm_message_node_add_child(m->node, "status", leave_status);

  if(!lm_connection_send(connect, m, &error)) {
      g_print("Failed leave to '%s' due to: %s\n",
                room_name, error->message);
      return FALSE;
  }
  fprintf(stderr, "Leave to %s\n", room_name);

  lm_message_unref(m);
  return TRUE;
}
示例#9
0
文件: xmpp.c 项目: phyw/Sigfaultbot
/*
 * Вход в конферецию
 */
gboolean join_room(LmConnection *connect,
              const gchar* room_name, const gchar* nick) {

  LmMessage       *m;
  LmMessageNode   *query;
  gchar           *room_jid;
  GError          *error = NULL;

  room_jid = (gchar*)xcalloc(strlen(room_name)+strlen(nick)+2, sizeof(gchar));
  strcat(room_jid, room_name);
  strcat(room_jid, "/");
  strcat(room_jid, nick);
  
  // Создаём новое сообщение запросом на вход
  m = lm_message_new(room_jid, LM_MESSAGE_TYPE_PRESENCE);
  query = lm_message_node_add_child(m->node, "x", NULL);
  lm_message_node_set_attributes(query, "xmlns",
                      "http://jabber.org/protocol/muc", NULL);
  // Заходим...
  if(!lm_connection_send(connect, m, &error)) {
      g_print("Failed join to '%s' due to: %s\n",
                room_jid, error->message);
      free(room_jid); //FIXME
      return FALSE;
  }
  
  fprintf(stderr, "Join to %s as %s\n", room_name, nick);
  
  free(room_jid);
  lm_message_unref(m);
  return TRUE;
}
示例#10
0
文件: xmpp_iq.c 项目: jbar/mcabber
// This function borrows some code from the Pidgin project
LmHandlerResult handle_iq_time202(LmMessageHandler *h, LmConnection *c,
                                  LmMessage *m, gpointer ud)
{
  LmMessage *r;
  LmMessageNode *query;
  char *buf, *utf8_buf;
  time_t now_t;
  struct tm *now;
  char const *sign;
  int diff = 0;

  time(&now_t);

  if (!settings_opt_get_int("iq_hide_requests")) {
    scr_LogPrint(LPRINT_LOGNORM, "Received an IQ time request from <%s>",
                 lm_message_get_from(m));
  }

  buf = g_new0(char, 512);

  r = lm_message_new_iq_from_query(m, LM_MESSAGE_SUB_TYPE_RESULT);
  query = lm_message_node_add_child(r->node, "time", NULL);
  lm_message_node_set_attribute(query, "xmlns", NS_XMPP_TIME);

  now = localtime(&now_t);

  if (now->tm_isdst >= 0) {
#if defined HAVE_TM_GMTOFF
    diff = now->tm_gmtoff;
#elif defined HAVE_TIMEZONE
    tzset();
    diff = -timezone;
#endif
  }

  if (diff < 0) {
    sign = "-";
    diff = -diff;
  } else {
    sign = "+";
  }
  diff /= 60;
  snprintf(buf, 512, "%c%02d:%02d", *sign, diff / 60, diff % 60);
  if ((utf8_buf = to_utf8(buf))) {
    lm_message_node_add_child(query, "tzo", utf8_buf);
    g_free(utf8_buf);
  }

  now = gmtime(&now_t);

  strftime(buf, 512, "%Y-%m-%dT%TZ", now);
  lm_message_node_add_child(query, "utc", buf);

  lm_connection_send(c, r, NULL);
  lm_message_unref(r);
  g_free(buf);
  return LM_HANDLER_RESULT_REMOVE_MESSAGE;
}
示例#11
0
文件: xmpp_iq.c 项目: weiss/mcabber
LmHandlerResult handle_iq_ping(LmMessageHandler *h, LmConnection *c,
                               LmMessage *m, gpointer ud)
{
  LmMessage *r;

  r = lm_message_new_iq_from_query(m, LM_MESSAGE_SUB_TYPE_RESULT);
  lm_connection_send(c, r, NULL);
  lm_message_unref(r);
  return LM_HANDLER_RESULT_REMOVE_MESSAGE;
}
示例#12
0
boolean
xmpp_connect (const char *user, const char * passwd, const char * server, unsigned short port)
{

  GError * error = NULL;
  LmMessage * m;
  LmMessage * reply;
  LmMessageNode * query;
  LmMessageNode * item;
  gboolean success;

  lm_connection_set_server (connection, server);
  lm_connection_set_port (connection, port);

  g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, _("Connecting to %s..."), server);
  success = lm_connection_open_and_block (connection, &error);
  if (!success) goto error;

  g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, _("Authenticating with JID %s..."), user);
  success = lm_connection_authenticate_and_block (connection, user, passwd, CONN_XMPP_RESOURCE, &error);
  if (!success) goto error;
  g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, _("Connected successfully."), user);

  /* Fetch roster */
  m = lm_message_new_with_sub_type (NULL, LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_GET);
  query = lm_message_node_add_child (m->node, "query", NULL);
  lm_message_node_set_attributes (query, "xmlns", "jabber:iq:roster", NULL);
  reply = lm_connection_send_with_reply_and_block (connection, m, &error);
  query = lm_message_node_get_child (reply->node, "query");
  item  = lm_message_node_get_child (query, "item");
  while (item)
    {
      xmpp_user_t user;
      const gchar *jid, *name;
      jid = lm_message_node_get_attribute (item, "jid");
      name = lm_message_node_get_attribute (item, "name");
      user = intern_user (jid);
      user->name = g_strdup (name);
      user->status = OFFLINE;
      item = item->next;
    }
  lm_message_unref (reply);
  lm_message_unref (m);

  m = lm_message_new_with_sub_type (NULL, LM_MESSAGE_TYPE_PRESENCE, LM_MESSAGE_SUB_TYPE_AVAILABLE);
  lm_connection_send(connection, m, NULL);
  lm_message_unref (m);

  return TRUE;

  /* Error handling */
 error:
  g_message ("%s", error->message);
  return FALSE;
}
示例#13
0
static void
send_message (LmConnection *conn, Arguments *arguments)
{
    LmMessage     *m;

    m = lm_message_new (arguments->test_contact, LM_MESSAGE_TYPE_MESSAGE);

    lm_message_node_add_child (m->node, "body", arguments->test_message);
    lm_connection_send (conn, m, NULL);
    lm_message_unref (m);
}
示例#14
0
void
LM::HeapRoster::on_personal_details_updated ()
{
  LmMessage* message = lm_message_new (NULL, LM_MESSAGE_TYPE_PRESENCE);

  lm_message_node_add_child (lm_message_get_node (message), "show", details->get_presence ().c_str ());
  lm_message_node_add_child (lm_message_get_node (message), "status", details->get_status ().c_str ());

  lm_connection_send (connection, message, NULL);
  lm_message_unref (message);
}
示例#15
0
文件: xmpp_iq.c 项目: weiss/mcabber
LmHandlerResult handle_iq_commands(LmMessageHandler *h,
                                   LmConnection *c,
                                   LmMessage *m, gpointer ud)
{
  const char *requester_jid = NULL;
  LmMessageNode *cmd;
  const struct adhoc_command *command;

  // mcabber has only partial XEP-0146 support...
  if (LM_MESSAGE_SUB_TYPE_SET != lm_message_get_sub_type(m))
    return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;

  requester_jid = lm_message_get_from(m);

  cmd = lm_message_node_get_child(m->node, "command");
  if (!cmd) {
    //send_iq_error(c, m, XMPP_ERROR_BAD_REQUEST);
    return LM_HANDLER_RESULT_REMOVE_MESSAGE;
  }
  if (jid_equal(lm_connection_get_jid(c), requester_jid)) {
    const char *action, *node;
    action = lm_message_node_get_attribute(cmd, "action");
    node = lm_message_node_get_attribute(cmd, "node");
    // action can be NULL, in which case it seems to take the default,
    // ie execute
    if (!action || !strcmp(action, "execute") || !strcmp(action, "cancel")
        || !strcmp(action, "next") || !strcmp(action, "complete")) {
      for (command = adhoc_command_list; command->name; command++) {
        if (!strcmp(node, command->name))
          command->callback(h, c, m, ud);
      }
      // "prev" action will get there, as we do not implement it,
      // and do not authorize it
    } else {
      LmMessage *r;
      LmMessageNode *err;
      r = lm_message_new_iq_error(m, XMPP_ERROR_BAD_REQUEST);
      if (r) {
        err = lm_message_node_get_child(r->node, "error");
        lm_message_node_set_attribute
          (lm_message_node_add_child(err, "malformed-action", NULL),
           "xmlns", NS_COMMANDS);
        lm_connection_send(c, r, NULL);
        lm_message_unref(r);
      }
    }
  } else {
    send_iq_error(c, m, XMPP_ERROR_FORBIDDEN);
  }
  return LM_HANDLER_RESULT_REMOVE_MESSAGE;
}
示例#16
0
文件: xmpp_iq.c 项目: weiss/mcabber
// This function borrows some code from the Pidgin project
LmHandlerResult handle_iq_time(LmMessageHandler *h, LmConnection *c,
                               LmMessage *m, gpointer ud)
{
  LmMessage *r;
  LmMessageNode *query;
  char *buf, *utf8_buf;
  time_t now_t;
  struct tm *now;

  time(&now_t);

  if (!settings_opt_get_int("iq_hide_requests")) {
    scr_LogPrint(LPRINT_LOGNORM, "Received an IQ time request from <%s>",
                 lm_message_get_from(m));
  }

  if (settings_opt_get_int("iq_time_hide")) {
    send_iq_error(c, m, XMPP_ERROR_SERVICE_UNAVAILABLE);
    return LM_HANDLER_RESULT_REMOVE_MESSAGE;
  }

  buf = g_new0(char, 512);

  r = lm_message_new_iq_from_query(m, LM_MESSAGE_SUB_TYPE_RESULT);
  query = lm_message_node_add_child(r->node, "query", NULL);
  lm_message_node_set_attribute(query, "xmlns", NS_TIME);

  now = gmtime(&now_t);

  strftime(buf, 512, "%Y%m%dT%T", now);
  lm_message_node_add_child(query, "utc", buf);

  now = localtime(&now_t);

  strftime(buf, 512, "%Z", now);
  if ((utf8_buf = to_utf8(buf))) {
    lm_message_node_add_child(query, "tz", utf8_buf);
    g_free(utf8_buf);
  }

  strftime(buf, 512, "%d %b %Y %T", now);
  if ((utf8_buf = to_utf8(buf))) {
    lm_message_node_add_child(query, "display", utf8_buf);
    g_free(utf8_buf);
  }

  lm_connection_send(c, r, NULL);
  lm_message_unref(r);
  g_free(buf);
  return LM_HANDLER_RESULT_REMOVE_MESSAGE;
}
示例#17
0
static void
send_stanza(XMPP_SERVER_REC *server, LmMessage *lmsg)
{
	char *xml, *recoded;

	g_return_if_fail(IS_XMPP_SERVER(server));
	g_return_if_fail(lmsg != NULL);
	xml = lm_message_node_to_string(lmsg->node);
	recoded = xmpp_recode_in(xml);
	g_free(xml);
	signal_emit("xmpp xml out", 2, server, recoded);
	g_free(recoded);
	lm_connection_send(server->lmconn, lmsg, NULL);
}
示例#18
0
void
LM::HeapRoster::subscribe_from_form_submitted (bool submitted,
					       Ekiga::Form& result)
{
  if ( !submitted)
    return;

  const std::string jid = result.hidden ("jid");
  const std::string answer = result.single_choice ("answer");

  if (answer == "grant") {

    LmMessage* message = lm_message_new (NULL, LM_MESSAGE_TYPE_PRESENCE);
    lm_message_node_set_attributes (lm_message_get_node (message),
				    "to", jid.c_str (),
				    "type", "subscribed",
				    NULL);
    lm_connection_send (connection, message, NULL);
    lm_message_unref (message);
    LmMessage* subscribe = lm_message_new (NULL, LM_MESSAGE_TYPE_PRESENCE);
    lm_message_node_set_attributes (lm_message_get_node (subscribe),
				    "to", jid.c_str (),
				    "type", "subscribe",
				    NULL);
    lm_connection_send (connection, subscribe, NULL);
    lm_message_unref (subscribe);
  } else if (answer == "refuse") {

    LmMessage* message = lm_message_new (NULL, LM_MESSAGE_TYPE_PRESENCE);
    lm_message_node_set_attributes (lm_message_get_node (message),
				    "to", jid.c_str (),
				    "type", "unsubscribed",
				    NULL);
    lm_connection_send (connection, message, NULL);
    lm_message_unref (message);
  }
}
示例#19
0
static gboolean
sasl_digest_md5_check_server_response(LmSASL *sasl, GHashTable *challenge)
{
	LmMessage   *msg;
	const gchar *rspauth;
	int          result;

	rspauth = g_hash_table_lookup (challenge, "rspauth");
	if (rspauth == NULL) {
		g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SSL,
		       "%s: server sent an invalid reply (no rspauth)\n",
		       G_STRFUNC);

		if (sasl->handler) {
			sasl->handler (sasl, sasl->connection, 
				       TRUE, "server error");
		}
		return FALSE;
	}

	if (strcmp (sasl->digest_md5_rspauth, rspauth) != 0) {
		g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SSL,
		       "%s: server sent an invalid reply (rspauth not matching)\n", 
		       G_STRFUNC);

		if (sasl->handler) {
			sasl->handler (sasl, sasl->connection,
				       TRUE, "server error");
		}
		return FALSE;
	}

	msg = lm_message_new (NULL, LM_MESSAGE_TYPE_RESPONSE);
	lm_message_node_set_attributes (msg->node,
					"xmlns", XMPP_NS_SASL_AUTH,
					NULL);

	result = lm_connection_send (sasl->connection, msg, NULL);
	lm_message_unref (msg);

	if (!result) {
		g_warning ("Failed to send SASL response\n");
		return FALSE;
	}

	sasl->state = SASL_AUTH_STATE_DIGEST_MD5_SENT_FINAL_RESPONSE;

	return TRUE;
}
示例#20
0
void
xmpp_mesg_send(const char *to, const char *msg)
{
	LmMessage *m;
	GError *err = NULL;
	m = lm_message_new_with_sub_type(to, LM_MESSAGE_TYPE_MESSAGE,
	                                 LM_MESSAGE_SUB_TYPE_CHAT);
	lm_message_node_add_child(m->node, "body", msg);
	if(!lm_connection_send(xmpp_connection_get(), m, &err)) {
		ui_print("Error sending message: %s\n", err->message);
		g_error_free(err);
	}
	lua_msg_callback(NULL, to, msg);
	lm_message_unref(m);
} /* xmpp_send_message */
示例#21
0
// Join a MUC room
void xmpp_room_join(const char *room, const char *nickname, const char *passwd)
{
  LmMessage *x;
  LmMessageNode *y;
  gchar *roomid;
  GSList *room_elt;

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

  roomid = g_strdup_printf("%s/%s", room, nickname);
  if (check_jid_syntax(roomid)) {
    scr_LogPrint(LPRINT_NORMAL, "<%s/%s> is not a valid Jabber room", room,
                 nickname);
    g_free(roomid);
    return;
  }

  room_elt = roster_find(room, jidsearch, ROSTER_TYPE_USER|ROSTER_TYPE_ROOM);
  // Add room if it doesn't already exist
  if (!room_elt) {
    room_elt = roster_add_user(room, NULL, NULL, ROSTER_TYPE_ROOM,
                               sub_none, -1);
  } else {
    // Make sure this is a room (it can be a conversion user->room)
    buddy_settype(room_elt->data, ROSTER_TYPE_ROOM);
  }
  // If insideroom is TRUE, this is a nickname change and we don't care here
  if (!buddy_getinsideroom(room_elt->data)) {
    // We're trying to enter a room
    buddy_setnickname(room_elt->data, nickname);
  }

  // Send the XML request
  x = lm_message_new_presence(mystatus, roomid, mystatusmsg);
  xmpp_insert_entity_capabilities(x->node, mystatus); // Entity Caps (XEP-0115)
  y = lm_message_node_add_child(x->node, "x", NULL);
  lm_message_node_set_attribute(y, "xmlns", NS_MUC);
  if (passwd)
    lm_message_node_add_child(y, "password", passwd);

  lm_connection_send(lconnection, x, NULL);
  lm_message_unref(x);
  g_free(roomid);
}
示例#22
0
文件: IoLoudmouth.c 项目: ADTSH/io
//doc Loudmouth send(toJid, message) Sends a message (<code>Sequence</code>) to provided JID (<code>Sequence</code>). Returns <code>true</code> or <code>false</code>.
IoObject *IoLoudmouth_send(IoLoudmouth *self, IoObject *locals, IoMessage *m) {
  char *to        = IoMessage_locals_cStringArgAt_(m, locals, 0);
  char *msg_body  = IoMessage_locals_cStringArgAt_(m, locals, 1);
  int success     = 0;

  LmMessage *xmpp_msg = lm_message_new_with_sub_type(
    to, LM_MESSAGE_TYPE_MESSAGE, LM_MESSAGE_SUB_TYPE_CHAT
  );

  lm_message_node_add_child(xmpp_msg->node, "body", msg_body);
  success = lm_connection_send(LMCONN(self), xmpp_msg, NULL);
  lm_message_unref(xmpp_msg);
  free(to);
  free(msg_body);

  return IOBOOL(self, success);
}
示例#23
0
文件: xmpp_iq.c 项目: weiss/mcabber
LmHandlerResult handle_iq_version(LmMessageHandler *h, LmConnection *c,
                                  LmMessage *m, gpointer ud)
{
  LmMessage *r;
  LmMessageNode *query;

  if (!settings_opt_get_int("iq_hide_requests")) {
    scr_LogPrint(LPRINT_LOGNORM, "Received an IQ version request from <%s>",
                 lm_message_get_from(m));
  }

  if (settings_opt_get_int("iq_version_hide")) {
    send_iq_error(c, m, XMPP_ERROR_SERVICE_UNAVAILABLE);
    return LM_HANDLER_RESULT_REMOVE_MESSAGE;
  }

  r = lm_message_new_iq_from_query(m, LM_MESSAGE_SUB_TYPE_RESULT);

  query = lm_message_node_add_child(r->node, "query", NULL);
  lm_message_node_set_attribute(query, "xmlns", NS_VERSION);

  lm_message_node_add_child(query, "name", PACKAGE_NAME);

  // MCabber version
  if (!settings_opt_get_int("iq_version_hide_version")) {
    char *ver = mcabber_version();
    lm_message_node_add_child(query, "version", ver);
    g_free(ver);
  }

  // OS details
  if (!settings_opt_get_int("iq_version_hide_os")) {
    char *os;
    struct utsname osinfo;
    uname(&osinfo);
    os = g_strdup_printf("%s %s %s", osinfo.sysname, osinfo.release,
                         osinfo.machine);
    lm_message_node_add_child(query, "os", os);
    g_free(os);
  }

  lm_connection_send(c, r, NULL);
  lm_message_unref(r);
  return LM_HANDLER_RESULT_REMOVE_MESSAGE;
}
示例#24
0
文件: xmpp.c 项目: phyw/Sigfaultbot
/*
 * Установка статуса и приоритета
 */
gboolean set_status(LmConnection *connect, const struct _jid *jid,
                    const gchar *status, const gchar *priority) {
  LmMessage *m;
  GError    *error = NULL;

  // Создаём и отправляем сообщение
  m = lm_message_new(NULL, LM_MESSAGE_TYPE_PRESENCE); 
  lm_message_node_add_child(m->node, "status", status);
  lm_message_node_add_child(m->node, "priority", priority);

  if(!lm_connection_send(connect, m, &error)) {
      g_print ("Failed set status and priority, due to: %s\n",
                error->message);
      return FALSE;
  }
  lm_message_unref(m); 
  return TRUE;
}
示例#25
0
文件: harmony.c 项目: KDE/amarok
void harmony_success_reply(LmConnection *connection, LmMessage *message, GError **err) {
    LmMessage *message_out;
    LmMessageNode *harmony_download_node;
    LmMessageNode *message_out_node;
    
    message_out = lm_message_new_with_sub_type(MP3TUNES_HARMONY_CONDUCTOR, LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_RESULT);
    lm_message_node_set_attribute(message_out->node, "id", lm_message_node_get_attribute(message->node, "id"));
    message_out_node = lm_message_node_add_child(message_out->node, "success", NULL);

    harmony_download_node = lm_message_node_get_child(message->node, "download");
    if (harmony_download_node) {
        lm_message_node_set_attribute(message_out_node, "messageId", lm_message_node_get_attribute(harmony_download_node, "messageId"));
    }
    lm_message_node_set_attribute(message_out_node, "xmlns", MP3TUNES_HARMONY_XMLNS);

    lm_connection_send(connection, message_out, err);
    lm_message_unref(message_out);
}
示例#26
0
文件: IoLoudmouth.c 项目: ADTSH/io
IoObject *IoLoudmouth_setPresence(IoLoudmouth *self, IoObject *locals, IoMessage *m) {
  char *pres_c  = IoMessage_locals_cStringArgAt_(m, locals, 0);
  IoSeq *status = IoMessage_locals_valueArgAt_(m, locals, 1);
  int success   = 0;
  LmMessage *xmpp_msg = lm_message_new_with_sub_type(
    NULL,
    LM_MESSAGE_TYPE_PRESENCE,
    str2msg_subtype(pres_c)
  );

  if(ISSEQ(status))
    lm_message_node_add_child(xmpp_msg->node, "status", CSTRING(status));

  success = lm_connection_send(LMCONN(self), xmpp_msg, NULL);
  lm_message_unref(xmpp_msg);
  free(pres_c);

  return IOBOOL(self, success);
}
示例#27
0
static void
authentication_cb (LmConnection *connection, gboolean result, gpointer ud)
{
        g_print ("Auth: %d\n", result);
	free_user_info ((UserInfo *) ud);
 
        if (result == TRUE) {
                LmMessage *m;
                 
		m = lm_message_new_with_sub_type (NULL,
                                                  LM_MESSAGE_TYPE_PRESENCE,
                                                  LM_MESSAGE_SUB_TYPE_AVAILABLE);
                g_print (":: %s\n", lm_message_node_to_string (m->node));
                 
                lm_connection_send (connection, m, NULL);
                lm_message_unref (m);
        }

}
示例#28
0
文件: xmpp.c 项目: grouzen/xinb
gboolean xmpp_send_presence(Xinb *x, LmMessageSubType subtype)
{
    LmMessage *m;

    if(x->state != LM_CONNECTION_STATE_AUTHENTICATED) {
        log_record(x, LOGS_ERR,
                   "Unable to send presense: not authenticated");
        return FALSE;
    }

    m = lm_message_new_with_sub_type(NULL, LM_MESSAGE_TYPE_PRESENCE, subtype);
    if(!lm_connection_send(x->conn, m, &(x->gerror))) {
        log_record(x, LOGS_ERR, "Unable to send presence of type '%d': %s",
                   subtype, x->gerror->message);
        g_clear_error(&(x->gerror));
        return FALSE;
    }

    return TRUE;
}
示例#29
0
文件: xmpp.c 项目: phyw/Sigfaultbot
/*
 * Отправка сообщения на другой jid
 */
gboolean jid_message(LmConnection *connect, 
                    const gchar* to_jid, const gchar* text) {
  LmMessage *m;
  GError    *error = NULL;
  // Создаём сообщение
  m = lm_message_new_with_sub_type(to_jid, LM_MESSAGE_TYPE_MESSAGE,
                                      LM_MESSAGE_SUB_TYPE_CHAT);

  lm_message_node_add_child(m->node, "body", text);

  if(!lm_connection_send(connect, m, &error)) {
      g_print ("Failed sent message to '%s' due to: %s\n",
                to_jid, error->message);
      return FALSE;
  }

  printf("Send message to %s\n", to_jid);
  lm_message_unref(m);
  return TRUE;
}
示例#30
0
void
xmpp_disconnect() {
    LmMessage *m;
    const gchar *conf_server = get_settings_str(SERVER);
    wantconnection = 0;
    if (connection == NULL)
        return;
    if (lm_connection_get_state(connection)
            == LM_CONNECTION_STATE_AUTHENTICATED) {
        m = lm_message_new_with_sub_type(NULL, LM_MESSAGE_TYPE_PRESENCE,
                                         LM_MESSAGE_SUB_TYPE_UNAVAILABLE);
        lm_connection_send(connection, m, NULL);
    }
    if(lm_connection_is_open(connection)) {
        ui_print("Closing connection to %s\n", conf_server);
        lm_connection_close(connection, NULL);
        g_printerr("Disconnected\n");
    }
    lm_connection_unref(connection);
    connection = NULL;
} /* xmpp_disconnect */