First step towards message tags extension support

(see http://ircv3.atheme.org/specification/message-tags-3.2).

In particular this commit implements a (very) dummy implementation
sketch of the server-time extension
(see http://ircv3.atheme.org/specification/message-tags-3.2 and #499).
This commit is contained in:
Diogo Sousa 2013-06-22 00:13:36 +01:00
parent ac5771377e
commit 94186f7888
7 changed files with 136 additions and 32 deletions

View File

@ -158,6 +158,8 @@ inbound_privmsg (server *serv, char *from, char *ip, char *text, int id)
struct User *user; struct User *user;
char idtext[64]; char idtext[64];
gboolean nodiag = FALSE; gboolean nodiag = FALSE;
message_tags_data tags_data_ = MESSAGE_TAGS_DATA_INIT; /* TODO: this will be an argument */
const message_tags_data const *tags_data = &tags_data_;
sess = find_dialog (serv, from); sess = find_dialog (serv, from);
@ -186,7 +188,7 @@ inbound_privmsg (server *serv, char *from, char *ip, char *text, int id)
} }
set_topic (sess, ip, ip); set_topic (sess, ip, ip);
} }
inbound_chanmsg (serv, NULL, NULL, from, text, FALSE, id); inbound_chanmsg (serv, NULL, NULL, from, text, FALSE, id, tags_data);
return; return;
} }
@ -410,7 +412,9 @@ inbound_action (session *sess, char *chan, char *from, char *ip, char *text, int
} }
void void
inbound_chanmsg (server *serv, session *sess, char *chan, char *from, char *text, char fromme, int id) inbound_chanmsg (server *serv, session *sess, char *chan, char *from,
char *text, char fromme, int id,
const message_tags_data const *tags_data)
{ {
struct User *user; struct User *user;
int hilight = FALSE; int hilight = FALSE;
@ -462,11 +466,14 @@ inbound_chanmsg (server *serv, session *sess, char *chan, char *from, char *text
hilight = TRUE; hilight = TRUE;
if (sess->type == SESS_DIALOG) if (sess->type == SESS_DIALOG)
EMIT_SIGNAL (XP_TE_DPRIVMSG, sess, from, text, idtext, NULL, 0); EMIT_SIGNAL_TIMESTAMP (XP_TE_DPRIVMSG, sess, from, text,
idtext, NULL, 0, tags_data->timestamp);
else if (hilight) else if (hilight)
EMIT_SIGNAL (XP_TE_HCHANMSG, sess, from, text, nickchar, idtext, 0); EMIT_SIGNAL_TIMESTAMP (XP_TE_HCHANMSG, sess, from, text,
nickchar, idtext, 0, tags_data->timestamp);
else else
EMIT_SIGNAL (XP_TE_CHANMSG, sess, from, text, nickchar, idtext, 0); EMIT_SIGNAL_TIMESTAMP (XP_TE_CHANMSG, sess, from, text,
nickchar, idtext, 0, tags_data->timestamp);
} }
void void

View File

@ -17,6 +17,8 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
#include "proto-irc.h"
#ifndef HEXCHAT_INBOUND_H #ifndef HEXCHAT_INBOUND_H
#define HEXCHAT_INBOUND_H #define HEXCHAT_INBOUND_H
@ -46,7 +48,8 @@ void inbound_away (server *serv, char *nick, char *msg);
void inbound_away_notify (server *serv, char *nick, char *reason); void inbound_away_notify (server *serv, char *nick, char *reason);
void inbound_login_start (session *sess, char *nick, char *servname); void inbound_login_start (session *sess, char *nick, char *servname);
void inbound_login_end (session *sess, char *text); void inbound_login_end (session *sess, char *text);
void inbound_chanmsg (server *serv, session *sess, char *chan, char *from, char *text, char fromme, int id); void inbound_chanmsg (server *serv, session *sess, char *chan, char *from, char *text, char fromme, int id,
const message_tags_data const *tags_data);
void clear_channel (session *sess); void clear_channel (session *sess);
void set_topic (session *sess, char *topic, char *stripped_topic); void set_topic (session *sess, char *topic, char *stripped_topic);
void inbound_privmsg (server *serv, char *from, char *ip, char *text, int id); void inbound_privmsg (server *serv, char *from, char *ip, char *text, int id);

View File

@ -2755,7 +2755,7 @@ cmd_msg (struct session *sess, char *tbuf, char *word[], char *word_eol[])
while ((split_text = split_up_text (sess, msg + offset, cmd_length, split_text))) while ((split_text = split_up_text (sess, msg + offset, cmd_length, split_text)))
{ {
inbound_chanmsg (newsess->server, NULL, newsess->channel, inbound_chanmsg (newsess->server, NULL, newsess->channel,
newsess->server->nick, split_text, TRUE, FALSE); newsess->server->nick, split_text, TRUE, FALSE, 0);
if (*split_text) if (*split_text)
offset += strlen(split_text); offset += strlen(split_text);
@ -2763,7 +2763,7 @@ cmd_msg (struct session *sess, char *tbuf, char *word[], char *word_eol[])
g_free(split_text); g_free(split_text);
} }
inbound_chanmsg (newsess->server, NULL, newsess->channel, inbound_chanmsg (newsess->server, NULL, newsess->channel,
newsess->server->nick, msg + offset, TRUE, FALSE); newsess->server->nick, msg + offset, TRUE, FALSE, 0);
} }
else else
{ {
@ -3700,7 +3700,7 @@ cmd_wallchan (struct session *sess, char *tbuf, char *word[],
if (sess->type == SESS_CHANNEL) if (sess->type == SESS_CHANNEL)
{ {
inbound_chanmsg (sess->server, NULL, sess->channel, inbound_chanmsg (sess->server, NULL, sess->channel,
sess->server->nick, word_eol[2], TRUE, FALSE); sess->server->nick, word_eol[2], TRUE, FALSE, 0);
sess->server->p_message (sess->server, sess->channel, word_eol[2]); sess->server->p_message (sess->server, sess->channel, word_eol[2]);
} }
list = list->next; list = list->next;
@ -4396,7 +4396,7 @@ handle_say (session *sess, char *text, int check_spch)
if (dcc) if (dcc)
{ {
inbound_chanmsg (sess->server, NULL, sess->channel, inbound_chanmsg (sess->server, NULL, sess->channel,
sess->server->nick, text, TRUE, FALSE); sess->server->nick, text, TRUE, FALSE, 0);
set_topic (sess, net_ip (dcc->addr), net_ip (dcc->addr)); set_topic (sess, net_ip (dcc->addr), net_ip (dcc->addr));
goto xit; goto xit;
} }
@ -4411,7 +4411,7 @@ handle_say (session *sess, char *text, int check_spch)
while ((split_text = split_up_text (sess, text + offset, cmd_length, split_text))) while ((split_text = split_up_text (sess, text + offset, cmd_length, split_text)))
{ {
inbound_chanmsg (sess->server, sess, sess->channel, sess->server->nick, inbound_chanmsg (sess->server, sess, sess->channel, sess->server->nick,
split_text, TRUE, FALSE); split_text, TRUE, FALSE, 0);
sess->server->p_message (sess->server, sess->channel, split_text); sess->server->p_message (sess->server, sess->channel, split_text);
if (*split_text) if (*split_text)
@ -4421,7 +4421,7 @@ handle_say (session *sess, char *text, int check_spch)
} }
inbound_chanmsg (sess->server, sess, sess->channel, sess->server->nick, inbound_chanmsg (sess->server, sess, sess->channel, sess->server->nick,
text + offset, TRUE, FALSE); text + offset, TRUE, FALSE, 0);
sess->server->p_message (sess->server, sess->channel, text + offset); sess->server->p_message (sess->server, sess->channel, text + offset);
} else } else
{ {

View File

@ -29,6 +29,7 @@
#endif #endif
#include "hexchat.h" #include "hexchat.h"
#include "proto-irc.h"
#include "ctcp.h" #include "ctcp.h"
#include "fe.h" #include "fe.h"
#include "ignore.h" #include "ignore.h"
@ -959,7 +960,8 @@ process_numeric (session * sess, int n,
/* handle named messages that starts with a ':' */ /* handle named messages that starts with a ':' */
static void static void
process_named_msg (session *sess, char *type, char *word[], char *word_eol[]) process_named_msg (session *sess, char *type, char *word[], char *word_eol[],
const message_tags_data const *tags_data)
{ {
server *serv = sess->server; server *serv = sess->server;
char ip[128], nick[NICKLEN]; char ip[128], nick[NICKLEN];
@ -1173,7 +1175,7 @@ process_named_msg (session *sess, char *type, char *word[], char *word_eol[])
{ {
if (ignore_check (word[1], IG_CHAN)) if (ignore_check (word[1], IG_CHAN))
return; return;
inbound_chanmsg (serv, NULL, to, nick, text, FALSE, id); inbound_chanmsg (serv, NULL, to, nick, text, FALSE, id, tags_data);
} else } else
{ {
if (ignore_check (word[1], IG_PRIV)) if (ignore_check (word[1], IG_PRIV))
@ -1368,8 +1370,55 @@ process_named_servermsg (session *sess, char *buf, char *rawname, char *word_eol
EMIT_SIGNAL (XP_TE_SERVTEXT, sess, buf, sess->server->servername, rawname, NULL, 0); EMIT_SIGNAL (XP_TE_SERVTEXT, sess, buf, sess->server->servername, rawname, NULL, 0);
} }
/* irc_inline() - 1 single line received from serv */ /* Handle time-server tags.
*
* Sets timestamp to the correct time. This needs to take into account that
* time is in UTC, so we should convert it to our local time.
*
* See http://ircv3.atheme.org/extensions/server-time-3.2
*/
static void
handle_message_tag_time (const char const *time, message_tags_data *tags_data)
{
/* TODO, obviously :P */
tags_data->timestamp = 44332211;
}
/* Handle message tags.
*
* See http://ircv3.atheme.org/specification/message-tags-3.2
*/
/* FIXME: we should ignore capabilities not enabled! */
static void
handle_message_tags (const char const *tags_str, message_tags_data *tags_data)
{
char **tags;
int i;
/* FIXME We might want to avoid the allocation overhead here since
* this might be called for every message from the server.
*/
tags = g_strsplit (tags_str, ";", 0);
for (i=0; tags[i]; i++)
{
char *key = tags[i];
char *value = strchr (tags[i], '=');
if (!value)
continue;
*value = '\0';
value++;
if (!strcmp (key, "time"))
handle_message_tag_time (value, tags_data);
}
g_strfreev (tags);
}
/* irc_inline() - 1 single line received from serv */
static void static void
irc_inline (server *serv, char *buf, int len) irc_inline (server *serv, char *buf, int len)
{ {
@ -1379,8 +1428,7 @@ irc_inline (server *serv, char *buf, int len)
char *word_eol[PDIWORDS+1]; char *word_eol[PDIWORDS+1];
char pdibuf_static[522]; /* 1 line can potentially be 512*6 in utf8 */ char pdibuf_static[522]; /* 1 line can potentially be 512*6 in utf8 */
char *pdibuf = pdibuf_static; char *pdibuf = pdibuf_static;
message_tags_data tags_data = MESSAGE_TAGS_DATA_INIT;
url_check_line (buf, len);
/* need more than 522? fall back to malloc */ /* need more than 522? fall back to malloc */
if (len >= sizeof (pdibuf_static)) if (len >= sizeof (pdibuf_static))
@ -1392,11 +1440,27 @@ irc_inline (server *serv, char *buf, int len)
word[PDIWORDS] = NULL; word[PDIWORDS] = NULL;
word_eol[PDIWORDS] = NULL; word_eol[PDIWORDS] = NULL;
if (buf[0] == ':') if (*buf == '@')
{ {
char *tags = buf + 1; /* skip the '@' */
char *sep = strchr (buf, ' ');
if (!sep)
goto xit;
*sep = '\0';
buf = sep + 1;
handle_message_tags(tags, &tags_data);
}
url_check_line (buf, len);
/* split line into words and words_to_end_of_line */ /* split line into words and words_to_end_of_line */
process_data_init (pdibuf, buf, word, word_eol, FALSE, FALSE); process_data_init (pdibuf, buf, word, word_eol, FALSE, FALSE);
if (buf[0] == ':')
{
/* find a context for this message */ /* find a context for this message */
if (is_channel (serv, word[3])) if (is_channel (serv, word[3]))
{ {
@ -1417,7 +1481,6 @@ irc_inline (server *serv, char *buf, int len)
} else } else
{ {
process_data_init (pdibuf, buf, word, word_eol, FALSE, FALSE);
word[0] = type = word[1]; word[0] = type = word[1];
if (plugin_emit_server (sess, type, word, word_eol)) if (plugin_emit_server (sess, type, word, word_eol))
goto xit; goto xit;
@ -1439,7 +1502,7 @@ irc_inline (server *serv, char *buf, int len)
process_numeric (sess, atoi (word[2]), word, word_eol, text); process_numeric (sess, atoi (word[2]), word, word_eol, text);
} else } else
{ {
process_named_msg (sess, type, word, word_eol); process_named_msg (sess, type, word, word_eol, &tags_data);
} }
xit: xit:

View File

@ -17,9 +17,26 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
#include <time.h>
#include "hexchat.h"
#ifndef HEXCHAT_PROTO_H #ifndef HEXCHAT_PROTO_H
#define HEXCHAT_PROTO_H #define HEXCHAT_PROTO_H
#define MESSAGE_TAGS_DATA_INIT \
{ \
.timestamp=(time_t)0, \
}
/* Message tag information that might be passed along with a server message
*
* See http://ircv3.atheme.org/specification/capability-negotiation-3.1
*/
typedef struct
{
time_t timestamp;
} message_tags_data;
void proto_fill_her_up (server *serv); void proto_fill_her_up (server *serv);
#endif #endif

View File

@ -865,8 +865,8 @@ text_validate (char **text, int *len)
return utf; return utf;
} }
void static void
PrintText (session *sess, char *text) PrintTextTimeStamp (session *sess, char *text, time_t timestamp)
{ {
char *conv; char *conv;
@ -890,12 +890,18 @@ PrintText (session *sess, char *text)
log_write (sess, text); log_write (sess, text);
scrollback_save (sess, text); scrollback_save (sess, text);
fe_print_text (sess, text, 0); fe_print_text (sess, text, timestamp);
if (conv) if (conv)
g_free (conv); g_free (conv);
} }
void
PrintText (session *sess, char *text)
{
PrintTextTimeStamp (sess, text, 0);
}
void void
PrintTextf (session *sess, char *format, ...) PrintTextf (session *sess, char *format, ...)
{ {
@ -1836,12 +1842,13 @@ format_event (session *sess, int index, char **args, char *o, int sizeofo, unsig
} }
static void static void
display_event (session *sess, int event, char **args, unsigned int stripcolor_args) display_event (session *sess, int event, char **args,
unsigned int stripcolor_args, time_t timestamp)
{ {
char o[4096]; char o[4096];
format_event (sess, event, args, o, sizeof (o), stripcolor_args); format_event (sess, event, args, o, sizeof (o), stripcolor_args);
if (o[0]) if (o[0])
PrintText (sess, o); PrintTextTimeStamp (sess, o, timestamp);
} }
int int
@ -2042,7 +2049,8 @@ text_color_of (char *name)
/* called by EMIT_SIGNAL macro */ /* called by EMIT_SIGNAL macro */
void void
text_emit (int index, session *sess, char *a, char *b, char *c, char *d) text_emit (int index, session *sess, char *a, char *b, char *c, char *d,
time_t timestamp)
{ {
char *word[PDIWORDS]; char *word[PDIWORDS];
int i; int i;
@ -2120,7 +2128,7 @@ text_emit (int index, session *sess, char *a, char *b, char *c, char *d)
} }
sound_play_event (index); sound_play_event (index);
display_event (sess, index, word, stripcolor_args); display_event (sess, index, word, stripcolor_args, timestamp);
} }
char * char *
@ -2143,7 +2151,7 @@ text_emit_by_name (char *name, session *sess, char *a, char *b, char *c, char *d
i = pevent_find (name, &i); i = pevent_find (name, &i);
if (i >= 0) if (i >= 0)
{ {
text_emit (i, sess, a, b, c, d); text_emit (i, sess, a, b, c, d, 0);
return 1; return 1;
} }

View File

@ -17,12 +17,17 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
#include <time.h>
#include "textenums.h" #include "textenums.h"
#ifndef HEXCHAT_TEXT_H #ifndef HEXCHAT_TEXT_H
#define HEXCHAT_TEXT_H #define HEXCHAT_TEXT_H
#define EMIT_SIGNAL(i, sess, a, b, c, d, e) text_emit(i, sess, a, b, c, d) /* timestamp is non-zero if we are using server-time */
#define EMIT_SIGNAL_TIMESTAMP(i, sess, a, b, c, d, e, timestamp) \
text_emit(i, sess, a, b, c, d, timestamp)
#define EMIT_SIGNAL(i, sess, a, b, c, d, e) \
text_emit(i, sess, a, b, c, d, 0)
struct text_event struct text_event
{ {
@ -46,7 +51,8 @@ int pevt_build_string (const char *input, char **output, int *max_arg);
int pevent_load (char *filename); int pevent_load (char *filename);
void pevent_make_pntevts (void); void pevent_make_pntevts (void);
int text_color_of (char *name); int text_color_of (char *name);
void text_emit (int index, session *sess, char *a, char *b, char *c, char *d); void text_emit (int index, session *sess, char *a, char *b, char *c, char *d,
time_t timestamp);
int text_emit_by_name (char *name, session *sess, char *a, char *b, char *c, char *d); int text_emit_by_name (char *name, session *sess, char *a, char *b, char *c, char *d);
char *text_validate (char **text, int *len); char *text_validate (char **text, int *len);
int get_stamp_str (char *fmt, time_t tim, char **ret); int get_stamp_str (char *fmt, time_t tim, char **ret);