Пример #1
0
/* irc_inline() - 1 single line received from serv */
void
server::p_inline (const boost::string_ref& text)
{
	session *sess;
	char *type;
	char *word[PDIWORDS+1];
	char *word_eol[PDIWORDS+1];
	message_tags_data tags_data = message_tags_data();

	std::string pdibuf(text.size(), '\0');

	sess = this->front_session;

	/* Python relies on this */
	word[PDIWORDS] = NULL;
	word_eol[PDIWORDS] = NULL;
	std::string buf;
	if (text.starts_with('@'))
	{
		auto sep = text.find_first_of(' ');
		if (sep == boost::string_ref::npos)
			return;
		
		/* skip the '@' */
		auto tags = text.substr(1, sep - 1);
		
		buf = text.substr(sep + 1).to_string();

		handle_message_tags(*this, tags, tags_data);
	}
	else
	{
		buf = text.to_string();
	}

	url_check_line(buf.data(), buf.size());

	/* split line into words and words_to_end_of_line */
	process_data_init (&pdibuf[0], &buf[0], word, word_eol, false, false);

	if (buf[0] == ':')
	{
		/* find a context for this message */
		if (this->is_channel_name (word[3]))
		{
			auto tmp = find_channel (word[3]);
			if (tmp)
				sess = &(*tmp);
		}

		/* for server messages, the 2nd word is the "message type" */
		type = word[2];

		word[0] = type;
		word_eol[1] = &buf[0];	/* keep the ":" for plugins */

		if (plugin_emit_server(sess, type, word, word_eol,
			tags_data.timestamp))
		{
			return;
		}

		word[1]++;
		word_eol[1] = &buf[1];	/* but not for HexChat internally */

	} else
	{
		word[0] = type = word[1];

		if (plugin_emit_server(sess, type, word, word_eol,
			tags_data.timestamp))
		{
			return;
		}
	}

	if (buf[0] != ':')
	{
		process_named_servermsg (sess, &buf[0], word[0], word_eol, &tags_data);
		return;
	}

	/* see if the second word is a numeric */
	std::locale locale;
	if (std::isdigit (word[2][0], locale))
	{
		char* t = word_eol[4];
		if (*t == ':')
			t++;

		process_numeric (sess, atoi (word[2]), word, word_eol, t, &tags_data);
	} else
	{
		process_named_msg (sess, type, word, word_eol, &tags_data);
	}
}
Пример #2
0
static void
irc_inline (server *serv, char *buf, int len)
{
	session *sess, *tmp;
	char *type, *text;
	char *word[PDIWORDS+1];
	char *word_eol[PDIWORDS+1];
	char pdibuf_static[522]; /* 1 line can potentially be 512*6 in utf8 */
	char *pdibuf = pdibuf_static;

	/* need more than 522? fall back to malloc */
	if (len >= sizeof (pdibuf_static))
		pdibuf = malloc (len + 1);

	sess = serv->front_session;

	/* Python relies on this */
	word[PDIWORDS] = NULL;
	word_eol[PDIWORDS] = NULL;

	if (buf[0] == ':')
	{
		/* split line into words and words_to_end_of_line */
		process_data_init (pdibuf, buf, word, word_eol, FALSE, FALSE);

		/* find a context for this message */
		if (is_channel (serv, word[3]))
		{
			tmp = find_channel (serv, word[3]);
			if (tmp)
				sess = tmp;
		}

		/* for server messages, the 2nd word is the "message type" */
		type = word[2];

		word[0] = type;
		word_eol[1] = buf;	/* keep the ":" for plugins */
		if (plugin_emit_server (sess, type, word, word_eol))
			goto xit;
		word[1]++;
		word_eol[1] = buf + 1;	/* but not for xchat internally */

	} else
	{
		process_data_init (pdibuf, buf, word, word_eol, FALSE, FALSE);
		word[0] = type = word[1];
		if (plugin_emit_server (sess, type, word, word_eol))
			goto xit;
	}

	if (buf[0] != ':')
	{
		process_named_servermsg (sess, buf, word[0], word_eol);
		goto xit;
	}

	/* see if the second word is a numeric */
	if (isdigit ((unsigned char) word[2][0]))
	{
		text = word_eol[4];
		if (*text == ':')
			text++;

		process_numeric (sess, atoi (word[2]), word, word_eol, text);
	} else
	{
		process_named_msg (sess, type, word, word_eol);
	}

xit:
	if (pdibuf != pdibuf_static)
		free (pdibuf);
}
Пример #3
0
/* irc_inline() - 1 single line received from serv */
static void
irc_inline (server *serv, char *buf, int len)
{
	session *sess, *tmp;
	char *type, *text;
	char *word[PDIWORDS+1];
	char *word_eol[PDIWORDS+1];
	char *pdibuf;
	message_tags_data tags_data = MESSAGE_TAGS_DATA_INIT;

	pdibuf = g_malloc (len + 1);

	sess = serv->front_session;

	/* Python relies on this */
	word[PDIWORDS] = NULL;
	word_eol[PDIWORDS] = NULL;

	if (*buf == '@')
	{
		char *tags = buf + 1; /* skip the '@' */
		char *sep = strchr (buf, ' ');

		if (!sep)
			goto xit;
		
		*sep = '\0';
		buf = sep + 1;

		handle_message_tags(serv, tags, &tags_data);
	}

	url_check_line (buf);

	/* split line into words and words_to_end_of_line */
	process_data_init (pdibuf, buf, word, word_eol, FALSE, FALSE);

	if (buf[0] == ':')
	{
		/* find a context for this message */
		if (is_channel (serv, word[3]))
		{
			tmp = find_channel (serv, word[3]);
			if (tmp)
				sess = tmp;
		}

		/* for server messages, the 2nd word is the "message type" */
		type = word[2];

		word[0] = type;
		word_eol[1] = buf;	/* keep the ":" for plugins */

		if (plugin_emit_server (sess, type, word, word_eol,
								tags_data.timestamp))
			goto xit;

		word[1]++;
		word_eol[1] = buf + 1;	/* but not for HexChat internally */

	} else
	{
		word[0] = type = word[1];

		if (plugin_emit_server (sess, type, word, word_eol,
								tags_data.timestamp))
			goto xit;
	}

	if (buf[0] != ':')
	{
		process_named_servermsg (sess, buf, word[0], word_eol, &tags_data);
		goto xit;
	}

	/* see if the second word is a numeric */
	if (isdigit ((unsigned char) word[2][0]))
	{
		text = word_eol[4];
		if (*text == ':')
			text++;

		process_numeric (sess, atoi (word[2]), word, word_eol, text, &tags_data);
	} else
	{
		process_named_msg (sess, type, word, word_eol, &tags_data);
	}

xit:
	g_free (pdibuf);
}