Пример #1
0
static LmHandlerResult
handle_register(LmMessageHandler *handler, LmConnection *connection,
    LmMessage *lmsg, gpointer user_data)
{
	LmMessageNode *node;
	struct register_data *rd;
	const char *id;
	char *cmd;
	int error;

	rd = user_data;
	id = lm_message_node_get_attribute(lmsg->node, "id");
	if (id == NULL || (id != NULL && strcmp(id, rd->id) != 0))
		return LM_HANDLER_RESULT_REMOVE_MESSAGE;
	if ((node = lm_message_node_get_child(lmsg->node, "error")) != NULL) {
		error = atoi(lm_message_node_get_attribute(node, "code"));
		signal_emit("xmpp registration failed", 3, rd->username,
		    rd->domain, GINT_TO_POINTER(error));
	} else {
		signal_emit("xmpp registration succeed", 2, rd->username,
		    rd->domain);
		cmd = g_strdup_printf(
		    "%sXMPPCONNECT %s-host %s -port %d %s@%s %s",
		    settings_get_str("cmdchars"),
		    rd->use_ssl ? "-ssl " : "", rd->address, rd->port,
		    rd->username, rd->domain, rd->password);
		signal_emit("send command", 3, cmd, NULL, NULL);
		g_free(cmd);
	}
	rd_cleanup(rd);
	return LM_HANDLER_RESULT_REMOVE_MESSAGE;
}
Пример #2
0
void action_search_form(LmConnection * connection, LmMessage * message, gpointer data)
{
	GGaduDialog *dialog;
	LmMessageNode *node;
	
	dialog =  ggadu_dialog_new_full(GGADU_DIALOG_GENERIC,_("Jabber search: form"),"search", 
			    (gpointer) g_strdup(lm_message_node_get_attribute(message->node, "from")));

	node = lm_message_node_get_child(message->node, "query");
	if (!strcmp(lm_message_node_get_attribute(node, "xmlns"), "jabber:iq:search"))
	{
		/* child_instr = lm_message_node_get_child(node, "instructions"); */   

		if (lm_message_node_get_child(node, "first"))
			ggadu_dialog_add_entry(dialog, GGADU_SEARCH_FIRSTNAME, _("First name:"), VAR_STR, NULL,
					       VAR_FLAG_NONE);
		if (lm_message_node_get_child(node, "last"))
			ggadu_dialog_add_entry(dialog, GGADU_SEARCH_LASTNAME, _("Last name:"), VAR_STR, NULL,
					       VAR_FLAG_NONE);
		if (lm_message_node_get_child(node, "nick"))
			ggadu_dialog_add_entry(dialog, GGADU_SEARCH_NICKNAME, _("Nick:"), VAR_STR, NULL,
					       VAR_FLAG_NONE);
		if (lm_message_node_get_child(node, "email"))
			ggadu_dialog_add_entry(dialog, GGADU_SEARCH_EMAIL, _("Email:"), VAR_STR, NULL,
					       VAR_FLAG_NONE);

		signal_emit("jabber", "gui show dialog", dialog, "main-gui");
	}
}
Пример #3
0
static LmHandlerResult presence_handler(LmMessageHandler* /*handler*/,
					LmConnection * /*connection*/, LmMessage* m,
					gpointer /*user_data*/)
{
//	XMPPAccountHandler * pHandler = static_cast<XMPPAccountHandler *>(user_data);
	LmMessageNode* node = lm_message_get_node(m);
	if (node)
	{
		const char* from = static_cast<const char*>(lm_message_node_get_attribute (node, "from"));
		if (from)
		{
			const gchar* type = lm_message_node_get_attribute (node, "type");
			
			if (type && strcmp(type, "unavailable") == 0)
			{
				UT_DEBUGMSG(("Disconnect presence from %s\n", from));
				// TODO: handle this
			}
			else
			{
				UT_DEBUGMSG(("Connect presence from %s\n", from));
				// TODO: handle this
			}
		}
		else
		{
			UT_DEBUGMSG(("presence message without from\n"));
		}
	}
	return LM_HANDLER_RESULT_REMOVE_MESSAGE;
}
Пример #4
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;
}
Пример #5
0
const std::string
LM::Presentity::get_name () const
{
  const gchar* result = lm_message_node_get_attribute (item, "name");

  if (result == NULL) {

    result = lm_message_node_get_attribute (item, "jid");
  }

  return result;
}
Пример #6
0
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;
}
Пример #7
0
void action_search_result(LmConnection * connection, LmMessage * message, gpointer data)
{
	LmMessageNode *node;
	LmMessageNode *child;
	GSList *list = NULL;

	node = lm_message_node_get_child(message->node, "query");
	if (!strcmp(lm_message_node_get_attribute(node, "xmlns"), "jabber:iq:search"))
	{
		child = lm_message_node_get_child(node, "item");
		if (!child)
		{
			signal_emit("jabber", "gui show message", g_strdup(_("No users have been found!")), "main-gui");
			return;
		}

		while (child)
		{
			gchar *jid = (gchar *) lm_message_node_get_attribute(child, "jid");
			GGaduContact *k;
			LmMessageNode *child_node;

			k = g_new0(GGaduContact, 1);
			k->id = g_strdup(jid ? jid : "?");


			child_node = lm_message_node_get_child(node, "first");
			if (child_node)
				k->first_name = g_strdup((gchar *) lm_message_node_get_value(child_node));

			child_node = lm_message_node_get_child(node, "last");
			if (child_node)
				k->last_name = g_strdup((gchar *) lm_message_node_get_value(child_node));

			child_node = lm_message_node_get_child(node, "nick");
			if (child_node)
				k->nick = g_strdup((gchar *) lm_message_node_get_value(child_node));

			child_node = lm_message_node_get_child(node, "email");
			if (child_node)
				k->email = g_strdup((gchar *) lm_message_node_get_value(child_node));

			k->status = JABBER_STATUS_UNAVAILABLE;
			list = g_slist_append(list, k);
			child = child->next;
		}

		signal_emit("jabber", "gui show search results", list, "main-gui");
	}
}
Пример #8
0
static LmHandlerResult chat_handler(LmMessageHandler* /*handler*/,
				    LmConnection* /*connection*/, LmMessage* m,
				    gpointer user_data)
{
	XMPPAccountHandler * pHandler = static_cast<XMPPAccountHandler *>(user_data);
	UT_return_val_if_fail(pHandler, LM_HANDLER_RESULT_REMOVE_MESSAGE);
	
	/* TODO: we should run run through all the nodes to find the message node */
	LmMessageNode* node = lm_message_get_node(m);
	if (strcmp(node->name, "message") == 0)
	{
		for (LmMessageNode* child = node->children; child != 0; child = child->next)
		{
			if (strcmp(child->name, "body") == 0)
			{
				/*
				   Note: we don't trust a message body with a from-address in it, as it could be forged. 
				   Instead get the from-address directly from the LmMessage
				*/
				std::string buddy = lm_message_node_get_attribute (m->node, "from");
				std::string::size_type pos  = buddy.find_last_of("/");
				if (pos != std::string::npos)
					buddy.resize(pos);

				// TODO: check the resource as an additional sanity check

				UT_DEBUGMSG(("chat_handler(): Got a message from buddy: %s\n", buddy.c_str()));
				pHandler->handleMessage(child->value, buddy);
				break;
			}
		}
	}
	
	return LM_HANDLER_RESULT_REMOVE_MESSAGE;
}
Пример #9
0
static LmHandlerResult
sasl_failure_cb (LmMessageHandler *handler,
		 LmConnection     *connection,
		 LmMessage        *message,
		 gpointer          user_data)
{
	LmSASL      *sasl;
	const gchar *ns;
	const gchar *reason = "unknown reason";
	
	ns = lm_message_node_get_attribute (message->node, "xmlns");
	if (!ns || strcmp (ns, XMPP_NS_SASL_AUTH) != 0) {
		return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
	}

	sasl = (LmSASL *) user_data;

	if (message->node->children) {
		const gchar *r;
		
		r = lm_message_node_get_value (message->node->children);
		if (r) {
			reason = r;
		}
	}
	
	g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SASL,
	       "%s: SASL authentication failed: %s", G_STRFUNC, reason);

	if (sasl->handler) {
		sasl->handler (sasl, sasl->connection, FALSE, reason);
	}

	return LM_HANDLER_RESULT_REMOVE_MESSAGE;
}
Пример #10
0
static LmHandlerResult
xmpp_presence_callback (LmMessageHandler * handler, LmConnection * connection,
                       LmMessage * message, gpointer user_data)
{
  LmMessageNode * node = message->node;
  xmpp_user_t user;
  gchar * jid;
  gchar * resource = NULL;
  gchar * delimit;
  jid = g_strdup (lm_message_node_get_attribute (node, "from"));
  delimit = strchr (jid, '/');
  if (delimit != NULL)
    {
      *delimit = '\0';
      resource = delimit+1;
    }
  switch (lm_message_get_sub_type (message))
    {
    case LM_MESSAGE_SUB_TYPE_AVAILABLE:
      user = intern_user (jid);
      user->resource = g_strdup (resource);
      user->status = ONLINE;
      break;
    case LM_MESSAGE_SUB_TYPE_UNAVAILABLE:
      remuser (jid);
      break;
    }
  g_free (jid);
}
Пример #11
0
static LmHandlerResult
ft_msg_iq_handler (LmMessageHandler *handler, LmConnection *conn,
                   LmMessage *msg, gpointer user_data)
{
        /* Currently the only IQ message we'll handle is the roster */
        LmMessageNode *query = lm_message_node_get_child (msg->node, "query");

        int type = lm_message_get_sub_type (msg);

        if (query) {
                const char *ns = lm_message_node_get_attribute (query, "xmlns");

                if (ns && !g_ascii_strcasecmp (ns, "jabber:iq:roster"))
                        ft_roster_cb (msg);
                else if (ns && !g_ascii_strcasecmp (ns,
                                                    "jabber:iq:version")) {
                        if (type == LM_MESSAGE_SUB_TYPE_GET)
                                ft_msg_iq_version_cb (msg);
                } else if (ns && !g_ascii_strcasecmp (ns, "jabber:iq:last")) {
                        if (type == LM_MESSAGE_SUB_TYPE_GET)
                                ft_msg_iq_last_cb (msg);
                } else
                        PRINTF (_("[iq received: %s (unhandled yet)]"), ns);

        }
        return LM_HANDLER_RESULT_REMOVE_MESSAGE;
}
Пример #12
0
static void
sig_recv_iq(XMPP_SERVER_REC *server, LmMessage *lmsg, const int type,
    const char *id, const char *from, const char *to)
{
	LmMessageNode *node;
	GSList *features;

	if (type == LM_MESSAGE_SUB_TYPE_RESULT) {
		node = lm_find_node(lmsg->node, "query", XMLNS, XMLNS_DISCO);
		if (node == NULL)
			return;
		features = NULL;
		for (node = node->children; node != NULL; node = node->next) {
			if (strcmp(node->name, "feature") == 0) {
				features = g_slist_prepend(features,
				    xmpp_recode_in(
			    	    lm_message_node_get_attribute(node, "var")));
			}
		}
		signal_emit("xmpp features", 3, server, from, features);
		if (strcmp(from, server->domain) == 0) {
			cleanup_features(server->server_features);
			server->server_features = features;
			signal_emit("xmpp server features", 1, server);
		} else
			cleanup_features(features);
	} else if (type == LM_MESSAGE_SUB_TYPE_GET) {
		node = lm_find_node(lmsg->node, "query", XMLNS, XMLNS_DISCO);
		if (node != NULL)
			send_disco(server, from);
	}
}
Пример #13
0
LmMessage *
_lm_message_new_from_node (LmMessageNode *node)
{
    LmMessage        *m;
    LmMessageType     type;
    LmMessageSubType  sub_type;
    const gchar      *sub_type_str;
    
    type = message_type_from_string (node->name);

    if (type == LM_MESSAGE_TYPE_UNKNOWN) {
        return NULL;
    }

    sub_type_str = lm_message_node_get_attribute (node, "type");
    if (sub_type_str) {
        sub_type = message_sub_type_from_string (sub_type_str);
    } else {
        sub_type = message_sub_type_when_unset (type);
    }

    m = g_new0 (LmMessage, 1);
    m->priv = g_new0 (LmMessagePriv, 1);
    
    PRIV(m)->ref_count = 1;
    PRIV(m)->type = type;
    PRIV(m)->sub_type = sub_type;
    
    m->node = lm_message_node_ref (node);
    
    return m;
}
Пример #14
0
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;
}
Пример #15
0
static void
send_register(struct register_data *rd)
{
	LmMessage *lmsg;
	LmMessageNode *node;
	char *recoded;

	lmsg = lm_message_new_with_sub_type(rd->domain,
	    LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_SET);
	node = lm_message_node_add_child(lmsg->node, "query", NULL);
	lm_message_node_set_attribute(node, XMLNS, XMLNS_REGISTER);
	recoded = xmpp_recode_out(rd->username);
	lm_message_node_add_child(node, "username", recoded);
	g_free(recoded);
	recoded = xmpp_recode_out(rd->password);
	lm_message_node_add_child(node, "password", recoded);
	g_free(recoded);
	rd->id = g_strdup(lm_message_node_get_attribute(lmsg->node, "id"));
	if (!lm_connection_send_with_reply(rd->lmconn, lmsg, rd->handler,
	    NULL)) {
		signal_emit("xmpp registration failed", 3, rd->username,
		    rd->domain, REGISTRATION_ERROR_INFO);
		rd_cleanup(rd);
	}
	lm_message_unref(lmsg);
}
Пример #16
0
/*
 * Получение аттрибута одного из нодов
 */
gchar* lm_message_node_get_child_attribute(LmMessageNode *node,
                        const gchar *child, const gchar *attribute) {
  LmMessageNode *tmp;
  tmp = lm_message_node_find_child(node, child);
  if(tmp)
    return (gchar*)lm_message_node_get_attribute(tmp, attribute);
  else return NULL;
}
Пример #17
0
LmHandlerResult harmony_iq_callback(LmMessageHandler* handler, LmConnection *connection, LmMessage *message, gpointer void_harmony) {
    GError *err = NULL;
    MP3tunesHarmony *harmony = MP3TUNES_HARMONY(void_harmony);
    LmMessageNode *harmony_download_node, *harmony_email_node;

    mp3tunes_harmony_download_t *download;
    gchar *email;
    
    (void)handler;

    harmony_download_node = lm_message_node_get_child(message->node, "download");
    if (harmony_download_node) {
        mp3tunes_harmony_download_init(&download);
        mp3tunes_harmony_download_set_file_key(download, (char*)lm_message_node_get_attribute(harmony_download_node, "fileKey"));
        mp3tunes_harmony_download_set_file_name(download, (char*)lm_message_node_get_attribute(harmony_download_node, "fileName"));
        mp3tunes_harmony_download_set_file_format(download, (char*)lm_message_node_get_attribute(harmony_download_node, "fileFormat"));
        mp3tunes_harmony_download_set_file_size(download, atoi(lm_message_node_get_attribute(harmony_download_node, "fileSize")));
        mp3tunes_harmony_download_set_track_title(download, (char*)lm_message_node_get_attribute(harmony_download_node, "trackTitle"));
        mp3tunes_harmony_download_set_artist_name(download, (char*)lm_message_node_get_attribute(harmony_download_node, "artistName"));
        mp3tunes_harmony_download_set_album_title(download, (char*)lm_message_node_get_attribute(harmony_download_node, "albumTitle"));
        mp3tunes_harmony_download_set_device_bitrate(download, (char*)lm_message_node_get_attribute(harmony_download_node, "deviceBitrate"));
        mp3tunes_harmony_download_set_file_bitrate(download, (char*)lm_message_node_get_attribute(harmony_download_node, "fileBitrate"));
        
        download_pending_emit(harmony, download);
        
        mp3tunes_harmony_add_download_to_queue(harmony, download);
     
        harmony_success_reply(connection, message, &err);
        
        if (err != NULL) {
           error_emit(harmony, MP3TUNES_HARMONY_ERROR_MISC, "Sending success reply failed", err);
        }
        return LM_HANDLER_RESULT_REMOVE_MESSAGE;
    }
    
    harmony_email_node = lm_message_node_get_child(message->node, "email");
    if (harmony_email_node) {
        email = g_strdup(lm_message_node_get_value(harmony_email_node));
        mp3tunes_harmony_set_email(harmony, email);
        g_free(email);
        harmony_success_reply(connection, message, &err);
        if (err != NULL) {
           error_emit(harmony, MP3TUNES_HARMONY_ERROR_MISC, "Sending success reply failed", err);
        }
        close_connection(harmony);
        open_connection(harmony);
        return LM_HANDLER_RESULT_REMOVE_MESSAGE;
    }

    return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
}
Пример #18
0
static LmHandlerResult
handle_stanza(LmMessageHandler *handler, LmConnection *connection,
    LmMessage *lmsg, gpointer user_data)
{
	XMPP_SERVER_REC *server;
	int type;
	const char *id;
	char *from, *to, *raw;

	if ((server = XMPP_SERVER(user_data)) == NULL)
		return LM_HANDLER_RESULT_REMOVE_MESSAGE;
	raw = xmpp_recode_in(lm_message_node_to_string(lmsg->node));
	signal_emit("xmpp xml in", 2, server, raw);
	g_free(raw);
	type = lm_message_get_sub_type(lmsg);
	id = lm_message_node_get_attribute(lmsg->node, "id");
	if (id == NULL)
		id = "";
	from = xmpp_recode_in(lm_message_node_get_attribute(lmsg->node, "from"));
	if (from == NULL)
		from = g_strdup("");
	to = xmpp_recode_in(lm_message_node_get_attribute(lmsg->node, "to"));
	if (to == NULL)
		to = g_strdup("");
	switch(lm_message_get_type(lmsg)) {
	case LM_MESSAGE_TYPE_MESSAGE:
		signal_emit("xmpp recv message", 6,
		    server, lmsg, type, id, from, to);
		break;
	case LM_MESSAGE_TYPE_PRESENCE:
		signal_emit("xmpp recv presence", 6,
		    server, lmsg, type, id, from, to);
		break;
	case LM_MESSAGE_TYPE_IQ:
		signal_emit("xmpp recv iq", 6,
		    server, lmsg, type, id, from, to);
		break;
	default:
		signal_emit("xmpp recv others", 6,
		    server, lmsg, type, id, from, to);
		break;
	}
	g_free(from);
	g_free(to);
	return LM_HANDLER_RESULT_REMOVE_MESSAGE;
}
Пример #19
0
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);
}
Пример #20
0
bool
LM::Presentity::populate_menu (Ekiga::MenuBuilder& builder)
{
  const gchar* subscription = lm_message_node_get_attribute (item, "subscription");
  const gchar* ask = lm_message_node_get_attribute (item, "ask");

  if ( !has_chat) {

    builder.add_action ("im-message-new", _("Start chat"), boost::ref (chat_requested));
  } else {

    builder.add_action ("im-message-new", _("Continue chat"), boost::ref (chat_requested));
  }
  builder.add_separator ();

  builder.add_action ("edit", _("_Edit"),
		      boost::bind (&LM::Presentity::edit_presentity, this));

  if (g_strcmp0 (subscription, "none") == 0) {

    builder.add_action ("ask", _("Ask him/her to see his/her status"), boost::bind (&LM::Presentity::ask_to, this));
  }
  if (g_strcmp0 (subscription, "from") == 0) {

    builder.add_action ("stop", _("Forbid him/her to see my status"), boost::bind (&LM::Presentity::revoke_from, this));
    if (ask == NULL)
      builder.add_action ("ask", _("Ask him/her to see his/her status"), boost::bind (&LM::Presentity::ask_to, this));
    else
      builder.add_ghost ("ask", _("Ask him/her to see his/her status (pending)"));
  }
  if (g_strcmp0 (subscription, "to") == 0) {

    builder.add_action ("stop", _("Stop getting his/her status"), boost::bind (&LM::Presentity::stop_to, this));
  }
  if (g_strcmp0 (subscription, "both") == 0) {

    builder.add_action ("stop", _("Forbid him/her to see my status"), boost::bind (&LM::Presentity::revoke_from, this));
    builder.add_action ("stop", _("Stop getting his/her status"), boost::bind (&LM::Presentity::stop_to, this));
  }

  builder.add_action ("remove", _("_Remove"),
		      boost::bind (&LM::Presentity::remove_presentity, this));
  return true;
}
Пример #21
0
static void
sig_recv_message(XMPP_SERVER_REC *server, LmMessage *lmsg, const int type,
    const char *id, const char *from, const char *to)
{
	LmMessageNode *node;
	MUC_REC *channel;
	const char *stamp;
	char *nick, *str;
	time_t t;

	node = lm_find_node(lmsg->node, "delay", "xmlns", XMLNS_DELAY);
	if (node == NULL) {
		/* XEP-0091: Delayed Delivery (deprecated) */
		node = lm_find_node(lmsg->node, "x", "xmlns", XMLNS_OLD_DELAY);
		if (node == NULL)
			return;
	}
	stamp = lm_message_node_get_attribute(node, "stamp");
	if ((t = xep82_datetime(stamp)) == (time_t)-1)
		return;
	node = lm_message_node_get_child(lmsg->node, "body");
	if (node == NULL || node->value == NULL || *node->value == '\0')
		return;
	if (type == LM_MESSAGE_SUB_TYPE_GROUPCHAT
	    && (channel = get_muc(server, from)) != NULL
	    && (nick = muc_extract_nick(from)) != NULL) {
		str = xmpp_recode_in(node->value);
		if (g_ascii_strncasecmp(str, "/me ", 4) == 0)
			 signal_emit("message xmpp delay action", 6,
			     server, str+4, nick, channel->name, &t,
			     GINT_TO_POINTER(SEND_TARGET_CHANNEL));
		else
			 signal_emit("message xmpp delay", 6, server,
			     str, nick, channel->name, &t,
			     GINT_TO_POINTER(SEND_TARGET_CHANNEL));
		g_free(str);
		g_free(nick);
	} else if ((type == LM_MESSAGE_SUB_TYPE_NOT_SET
	    || type == LM_MESSAGE_SUB_TYPE_HEADLINE
	    || type == LM_MESSAGE_SUB_TYPE_NORMAL
	    || type == LM_MESSAGE_SUB_TYPE_CHAT)) {
		str = xmpp_recode_in(node->value);
		if (g_ascii_strncasecmp(str, "/me ", 4) == 0)
			signal_emit("message xmpp delay action", 6,
			    server, str+4, from, from, &t,
			    GINT_TO_POINTER(SEND_TARGET_NICK));
		else
			signal_emit("message xmpp delay", 6, server,
			    str+4, from, from, &t,
			    GINT_TO_POINTER(SEND_TARGET_NICK));
		g_free(str);
	} else
		return;
	signal_stop();
}
Пример #22
0
static LmHandlerResult
sasl_success_cb (LmMessageHandler *handler,
		 LmConnection     *connection,
		 LmMessage        *message,
		 gpointer          user_data)
{
	LmSASL      *sasl;
	const gchar *ns;
	
	ns = lm_message_node_get_attribute (message->node, "xmlns");
	if (!ns || strcmp (ns, XMPP_NS_SASL_AUTH) != 0) {
		return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
	}

	sasl = (LmSASL *) user_data;

	switch (sasl->auth_type) {
	case AUTH_TYPE_PLAIN:
		if (sasl->state != SASL_AUTH_STATE_PLAIN_STARTED) {
			g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SASL,
			       "%s: server sent success before finishing auth", 
			       G_STRFUNC);
			if (sasl->handler) {
				sasl->handler (sasl, sasl->connection, 
					       FALSE, "server error");
			}
		}
		break;
	case AUTH_TYPE_DIGEST:
		if (sasl->state != SASL_AUTH_STATE_DIGEST_MD5_SENT_AUTH_RESPONSE &&
		    sasl->state != SASL_AUTH_STATE_DIGEST_MD5_SENT_FINAL_RESPONSE) {
			g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SASL,
			       "%s: server sent success before finishing auth", 
			       G_STRFUNC);
			if (sasl->handler) {
				sasl->handler (sasl, sasl->connection, 
					       FALSE, "server error");
			}
		}
		break;
	default:
		g_warning ("Wrong auth type");
		break;
	}

	g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SASL,
	       "%s: SASL authentication successful", G_STRFUNC);

	if (sasl->handler) {
		sasl->handler (sasl, sasl->connection, TRUE, NULL);
	}

	return LM_HANDLER_RESULT_REMOVE_MESSAGE;
	
}
Пример #23
0
void
LM::Presentity::push_presence (const std::string resource,
			       LmMessageNode* presence)
{
  if (resource.empty ())
    return;

  ResourceInfo info;

  LmMessageNode* priority = lm_message_node_find_child (presence, "priority");
  if (priority != NULL) {

    info.priority = atoi (lm_message_node_get_value (priority));

  } else {

    info.priority = 50;
  }

  LmMessageNode* status = lm_message_node_find_child (presence, "status");
  if (status != NULL) {

    const gchar* status_str = lm_message_node_get_value (status);
    if (status_str != NULL)
      info.status = status_str;
  }

  LmMessageNode* away = lm_message_node_find_child (presence, "show");
  if (away != NULL) {

    info.presence = lm_message_node_get_value (away);
  } else {

    info.presence = "available";
  }

  const gchar* oftype = lm_message_node_get_attribute (presence, "type");
  if (oftype != NULL) {

    if (oftype == std::string ("unavailable")) {

      info.presence = "unavailable";
    }
  }

  infos[resource] = info;

  if (info.presence == "unavailable") {

    infos.erase (resource);
  }

  updated ();
}
Пример #24
0
static LmHandlerResult
handle_messages (LmMessageHandler *handler,
                 LmConnection     *connection,
                 LmMessage        *m,
                 gpointer          user_data)
{
        g_print ("Incoming message from: %s\n",
                 lm_message_node_get_attribute (m->node, "from"));
 
        return LM_HANDLER_RESULT_REMOVE_MESSAGE;
}
Пример #25
0
/*
 * Обработчик входящих сообщений
 */
LmHandlerResult handle_messages(LmMessageHandler *handler,
                  LmConnection *connect, LmMessage *m, gpointer data) {
  printf("\nОбрабатываю событие LM_MESSAGE_TYPE_MESSAGE\n");

  const gchar *from, *to, *body, *xmlns;
        gchar  *str, *sstr = NULL;
  
  LmMessageSubType mstype;

  xmlns = lm_message_node_get_child_attribute(m->node, "x", "xmlns");
  if(!xmlns)
    xmlns = "";
  if(!strstr(xmlns, "delay")) {

    from = lm_message_node_get_attribute(m->node, "from");
    to = lm_message_node_get_attribute(m->node, "to");
    body = lm_message_node_get_child_value(m->node, "body");

    mstype = lm_message_get_sub_type(m);

    if(body) {
      str = g_strdup(body);
      sstr = g_strdup(strtok(str, " "));
    }

    if(sstr) {

      printf("Incoming message\n\tfrom: %s\n\tto: %s\n\tbody: %s\n",
              from, to, body);

      handler_cmd(connect, sstr, strchr(body, ' '));
    }
    
    free(str);
    free(sstr);
  }
  
  usleep(100000);
  lm_message_unref(m);
  return LM_HANDLER_RESULT_REMOVE_MESSAGE;
}
Пример #26
0
LmHandlerResult
xmpp_mesg_handler(LmMessageHandler *h, LmConnection *c,
		LmMessage *m, gpointer udata)
{
	const char *from, *to, *body;
	LmMessageNode *node;
	from = lm_message_node_get_attribute(m->node, "from");
	to = lm_message_node_get_attribute(m->node, "to");
	node = lm_message_node_get_child(m->node, "body");
	if(node && (body = lm_message_node_get_value(node))) {
		ui_tab_print_message(from, body);
		lua_msg_callback(from, to, body);
	}
	/* we're actually ignoring <subject> and <thread> elements,
	 * as I've never actually seen them being used. If you do, and you care,
	 * feel obliged to mail me and yell at me */
	return LM_HANDLER_RESULT_REMOVE_MESSAGE;
	UNUSED(h);
	UNUSED(c);
	UNUSED(udata);
} /* xmpp_mesg_handler */
Пример #27
0
/**
 * @brief A function to handle incoming jingle action
 * @param action The action which have been received
 * @param data   Contain the JingleFT of the content concerned
 * @param node   The node himself
 * @return       TRUE if the action was handled, FALSE otherwise
 */
static JingleHandleStatus handle(JingleAction action, gconstpointer data,
                                 LmMessageNode *node, GError **err)
{
  if (action == JINGLE_SESSION_INFO) {
    if (!g_strcmp0(lm_message_node_get_attribute(node, "xmlns"),
                   NS_JINGLE_APP_FT_INFO)
        && !g_strcmp0(node->name, "hash")) {
      ((JingleFT *)data)->hash = g_strdup(lm_message_node_get_value(node));
      return JINGLE_STATUS_HANDLED;
    }
    return JINGLE_STATUS_NOT_HANDLED;
  }
  return JINGLE_STATUS_NOT_HANDLED;
}
Пример #28
0
LmHandlerResult
LM::HeapRoster::handle_message (LmConnection* /*connection*/,
				LmMessage* message)
{
  LmHandlerResult result = LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
  LmMessageNode* node = lm_message_get_node (message);
  const gchar* from_c = lm_message_node_get_attribute (node, "from");
  const gchar* type_attr = lm_message_node_get_attribute (node, "type");
  std::string base_jid;

  if (from_c != 0) {

    std::string from (from_c);
    std::string::size_type index = from.find ('/');
    base_jid = std::string (from, 0, index);
  }

  PresentityPtr item = find_item (base_jid);

  if (item && (type_attr == NULL
	       || (type_attr != NULL && g_strcmp0 (type_attr, "normal") == 0)
	       || (type_attr != NULL && g_strcmp0 (type_attr, "chat") == 0))) {

    // let's imagine it's a basic chat message
    LmMessageNode* body = lm_message_node_find_child (node, "body");
    if (body && lm_message_node_get_value (body) != NULL) {

      result = LM_HANDLER_RESULT_REMOVE_MESSAGE;
      Ekiga::Message::payload_type payload;
      payload["text/plain"] = lm_message_node_get_value (body);
      dialect->push_message (item, payload);
    }
    // it could also be an avatar or a pubsub event or...
  }

  return result;
}
Пример #29
0
static void handle_event(LmMessage* message) {
  LmMessageNode *child = NULL;
  XML_Parser p;
  char *buf = NULL;
  const char *new_node = NULL;
  int ret;

#ifdef DB_DEBUG
  printf("message:%s\n",lm_message_node_to_string(message->node));
#endif

  //If message is a DeviceCreation message, subscribe to new event node
  child = lm_message_node_find_child(message->node,"Created");
  if(child != NULL) {
    new_node = lm_message_node_get_attribute(child,"name");
#ifdef DB_DEBUG
    printf("Got DeviceCreation message for '%s'\n",new_node);
#endif
    g_print("Got DeviceCreation message for '%s'\n",new_node);
    if((ret = subscribe_to_node(xmpp_connection,new_node)) != XMPP_NO_ERROR)
      printf("Could not subscribe to event node '%s'\n",new_node);
    return;
  }

  //Look for SensorNode in message, and invoke parser to update database entries
  child = lm_message_node_find_child(message->node,"Device");
  if(child == NULL) {
      return;
  }

  buf = lm_message_node_to_string(child);

  p = XML_ParserCreate(NULL);
  if(!p) {
    printf("Couldnt allocate memory for XML Parser\n");
    return;
  }

  XML_SetElementHandler(p,startElement,endElement);
  
  if(XML_Parse(p,buf,strlen(buf),1) == XML_STATUS_ERROR) {
    printf("Parse Error at line %u:\n%s\n",
	   XML_GetCurrentLineNumber(p),
	   XML_ErrorString(XML_GetErrorCode(p)));
    return;
  }

  XML_ParserFree(p);
}
Пример #30
0
//  muc_get_item_info(...)
// Get room member's information from xmlndata.
// The variables must be initialized before calling this function,
// because they are not touched if the relevant information is missing.
// Note that *actor should be freed by the caller.
static void muc_get_item_info(const char *from, LmMessageNode *xmldata,
                              enum imrole *mbrole, enum imaffiliation *mbaffil,
                              const char **mbjid, const char **mbnick,
                              char **actor, const char **reason)
{
  LmMessageNode *y, *z;
  const char *p, *actorjid, *actornick;

  y = lm_message_node_find_child(xmldata, "item");
  if (!y)
    return;

  p = lm_message_node_get_attribute(y, "affiliation");
  if (p) {
    if (!strcmp(p, "owner"))        *mbaffil = affil_owner;
    else if (!strcmp(p, "admin"))   *mbaffil = affil_admin;
    else if (!strcmp(p, "member"))  *mbaffil = affil_member;
    else if (!strcmp(p, "outcast")) *mbaffil = affil_outcast;
    else if (!strcmp(p, "none"))    *mbaffil = affil_none;
    else scr_LogPrint(LPRINT_LOGNORM, "<%s>: Unknown affiliation \"%s\"",
                      from, p);
  }
  p = lm_message_node_get_attribute(y, "role");
  if (p) {
    if (!strcmp(p, "moderator"))        *mbrole = role_moderator;
    else if (!strcmp(p, "participant")) *mbrole = role_participant;
    else if (!strcmp(p, "visitor"))     *mbrole = role_visitor;
    else if (!strcmp(p, "none"))        *mbrole = role_none;
    else scr_LogPrint(LPRINT_LOGNORM, "<%s>: Unknown role \"%s\"",
                      from, p);
  }
  *mbjid = lm_message_node_get_attribute(y, "jid");
  *mbnick = lm_message_node_get_attribute(y, "nick");
  // For kick/ban, there can be actor and reason tags
  z = lm_message_node_find_child(y, "actor");
  if (z) {
    actornick = lm_message_node_get_attribute(z, "nick");
    actorjid  = lm_message_node_get_attribute(z, "jid");
    if (actorjid) {
      if (actornick) {
        // We have both the actor's jid and nick
        *actor = g_strdup_printf("%s <%s>", actornick, actorjid);
      } else {
        *actor = g_strdup(actorjid); // jid only
      }
    } else if (!actorjid && actornick) {
      // We only have the nickname
      *actor = g_strdup(actornick);
    }
  }

  *reason = lm_message_node_get_child_value(y, "reason");
  if (*reason && !**reason)
    *reason = NULL;
}