2014-01-19 04:04:02 -08:00
|
|
|
#include "private.h"
|
|
|
|
#include "callbacks.h"
|
2014-01-19 06:40:03 -08:00
|
|
|
#include "window.h"
|
2014-01-20 09:32:08 -08:00
|
|
|
#include "channel.h"
|
2014-12-18 08:32:18 -08:00
|
|
|
#include <time.h>
|
2014-01-19 04:04:02 -08:00
|
|
|
|
2015-02-12 10:45:32 -08:00
|
|
|
static int
|
|
|
|
_find_crlf(const char *data, int length, int *lf)
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
*lf = 0;
|
|
|
|
for (; i < length; i++)
|
|
|
|
{
|
|
|
|
/* find crlf (\r\n) */
|
|
|
|
if ((data[i] == 0x0D) &&
|
|
|
|
(i < (length - 1)) && (data[i + 1] == 0x0A))
|
|
|
|
{
|
|
|
|
*lf = 2;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* find just lf */
|
|
|
|
if (data[i] == 0x0A)
|
|
|
|
{
|
|
|
|
*lf = 1;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-01-19 04:04:02 -08:00
|
|
|
void
|
2014-01-19 06:40:03 -08:00
|
|
|
_callback_server_connected(Express_Network *net, const char *event EINA_UNUSED, const char *source, const char **params EINA_UNUSED, unsigned int count EINA_UNUSED, void *data EINA_UNUSED)
|
2014-01-19 04:04:02 -08:00
|
|
|
{
|
|
|
|
DBG("Server %s Connected", source);
|
2014-01-19 06:40:03 -08:00
|
|
|
_window_network_channels_create(net);
|
2014-01-19 04:04:02 -08:00
|
|
|
}
|
|
|
|
|
2014-01-20 09:32:08 -08:00
|
|
|
void
|
2014-12-16 12:35:44 -08:00
|
|
|
_callback_server_motd(Express_Network *net EINA_UNUSED, const char *event EINA_UNUSED, const char *source, const char **params, unsigned int count EINA_UNUSED, void *data EINA_UNUSED)
|
2014-01-20 09:32:08 -08:00
|
|
|
{
|
|
|
|
Channel *chl;
|
|
|
|
|
2014-12-18 08:32:18 -08:00
|
|
|
/* DBG("Server Motd"); */
|
|
|
|
/* DBG("\tServer: %s", source); */
|
|
|
|
/* DBG("\tCount: %d", count); */
|
|
|
|
/* DBG("\tUser: %s", params[0]); */
|
|
|
|
/* DBG("\tMessage:"); */
|
|
|
|
/* DBG("\t%s", params[1]); */
|
2014-01-20 09:32:08 -08:00
|
|
|
|
2014-12-11 11:14:34 -08:00
|
|
|
if (!(chl = _window_channel_server_find(source))) return;
|
2014-12-16 11:26:58 -08:00
|
|
|
_channel_text_append(chl, NULL, params[1]);
|
2014-01-20 09:32:08 -08:00
|
|
|
}
|
|
|
|
|
2014-12-18 11:24:53 -08:00
|
|
|
void
|
|
|
|
_callback_server_notice(Express_Network *net EINA_UNUSED, const char *event EINA_UNUSED, const char *source EINA_UNUSED, const char **params, unsigned int count EINA_UNUSED, void *data EINA_UNUSED)
|
|
|
|
{
|
|
|
|
Channel *chl;
|
|
|
|
|
|
|
|
/* DBG("Server Notice"); */
|
|
|
|
/* DBG("\tServer: %s", source); */
|
|
|
|
/* DBG("\tCount: %d", count); */
|
|
|
|
/* DBG("\tUser: %s", params[0]); */
|
|
|
|
/* DBG("\tMessage:"); */
|
|
|
|
/* DBG("\t%s", params[1]); */
|
|
|
|
|
2015-02-11 06:54:02 -08:00
|
|
|
if (!(chl = _window_channel_active_get())) return;
|
2014-12-18 11:24:53 -08:00
|
|
|
_channel_text_append(chl, NULL, params[1]);
|
|
|
|
}
|
|
|
|
|
2014-01-20 09:32:08 -08:00
|
|
|
void
|
2014-12-18 08:32:18 -08:00
|
|
|
_callback_channel_message(Express_Network *net EINA_UNUSED, const char *event EINA_UNUSED, const char *source, const char **params, unsigned int count EINA_UNUSED, void *data EINA_UNUSED)
|
2014-01-20 09:32:08 -08:00
|
|
|
{
|
|
|
|
Channel *chl = NULL;
|
|
|
|
|
2014-12-18 08:32:18 -08:00
|
|
|
/* DBG("Channel Message: %s", params[0]); */
|
|
|
|
/* DBG("\tCount: %d", count); */
|
|
|
|
/* DBG("\tUser: %s", source); */
|
|
|
|
/* DBG("\tMessage:"); */
|
|
|
|
/* DBG("\t%s", params[1]); */
|
2014-01-20 09:32:08 -08:00
|
|
|
|
|
|
|
if (!(chl = _window_channel_find(params[0]))) return;
|
2014-12-16 11:26:58 -08:00
|
|
|
_channel_text_append(chl, source, params[1]);
|
2014-01-20 09:32:08 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-12-16 12:35:44 -08:00
|
|
|
_callback_channel_notice(Express_Network *net EINA_UNUSED, const char *event EINA_UNUSED, const char *source, const char **params, unsigned int count EINA_UNUSED, void *data EINA_UNUSED)
|
2014-01-20 09:32:08 -08:00
|
|
|
{
|
|
|
|
Channel *chl = NULL;
|
|
|
|
|
2014-12-18 08:32:18 -08:00
|
|
|
/* DBG("Channel Notice: %s", params[0]); */
|
|
|
|
/* DBG("\tCount: %d", count); */
|
|
|
|
/* DBG("\tServer: %s", source); */
|
|
|
|
/* DBG("\tMessage:"); */
|
|
|
|
/* DBG("\t%s", params[1]); */
|
2014-01-20 09:32:08 -08:00
|
|
|
|
|
|
|
if (!strcmp(params[0], "*"))
|
|
|
|
{
|
2014-12-11 11:14:34 -08:00
|
|
|
if (!(chl = _window_channel_server_find(source)))
|
|
|
|
{
|
|
|
|
ERR("Could not find channel with server name: %s", source);
|
|
|
|
if (!(chl = _window_channel_find("Default")))
|
2015-02-11 06:54:02 -08:00
|
|
|
chl = _window_channel_active_get();
|
2014-12-11 11:14:34 -08:00
|
|
|
}
|
2014-01-20 09:32:08 -08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!(chl = _window_channel_find(params[0])))
|
2015-02-11 06:54:02 -08:00
|
|
|
chl = _window_channel_active_get();
|
2014-01-20 09:32:08 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!chl) return;
|
2014-12-16 11:26:58 -08:00
|
|
|
_channel_text_append(chl, NULL, params[1]);
|
2014-01-20 09:32:08 -08:00
|
|
|
}
|
2014-12-16 12:35:44 -08:00
|
|
|
|
|
|
|
void
|
2014-12-18 08:32:18 -08:00
|
|
|
_callback_channel_topic(Express_Network *net EINA_UNUSED, const char *event EINA_UNUSED, const char *source EINA_UNUSED, const char **params, unsigned int count EINA_UNUSED, void *data EINA_UNUSED)
|
2014-12-16 12:35:44 -08:00
|
|
|
{
|
|
|
|
Channel *chl = NULL;
|
|
|
|
char buff[PATH_MAX];
|
|
|
|
|
2014-12-18 08:32:18 -08:00
|
|
|
/* DBG("Channel Topic: %s", params[0]); */
|
|
|
|
/* DBG("\tCount: %d", count); */
|
|
|
|
/* DBG("\tUser: %s", source); */
|
|
|
|
/* DBG("\tMessage:"); */
|
|
|
|
/* DBG("\t%s", params[1]); */
|
|
|
|
/* DBG("\t%s", params[2]); */
|
2014-12-16 12:35:44 -08:00
|
|
|
|
|
|
|
if (!(chl = _window_channel_find(params[1]))) return;
|
|
|
|
snprintf(buff, sizeof(buff), "Topic for %s is: ", params[1]);
|
|
|
|
_channel_text_append(chl, NULL, buff);
|
|
|
|
_channel_text_append(chl, NULL, params[2]);
|
|
|
|
}
|
2014-12-17 12:26:47 -08:00
|
|
|
|
2014-12-18 08:32:18 -08:00
|
|
|
void
|
|
|
|
_callback_channel_topic_time(Express_Network *net EINA_UNUSED, const char *event EINA_UNUSED, const char *source EINA_UNUSED, const char **params, unsigned int count EINA_UNUSED, void *data EINA_UNUSED)
|
|
|
|
{
|
|
|
|
Channel *chl = NULL;
|
|
|
|
char buff[PATH_MAX], *strtime;
|
|
|
|
time_t stamp;
|
|
|
|
|
|
|
|
/* DBG("Channel Topic Time: %s", params[0]); */
|
|
|
|
/* DBG("\tCount: %d", count); */
|
|
|
|
/* DBG("\tUser: %s", source); */
|
|
|
|
/* DBG("\tMessage:"); */
|
|
|
|
/* DBG("\t%s", params[1]); */
|
|
|
|
/* DBG("\t%s", params[2]); */
|
|
|
|
/* DBG("\t%s", params[3]); */
|
|
|
|
|
|
|
|
stamp = atol(params[3]);
|
|
|
|
strtime = ctime(&stamp);
|
|
|
|
strtime[24] = 0;
|
|
|
|
|
|
|
|
if (!(chl = _window_channel_find(params[1]))) return;
|
2014-12-18 08:53:08 -08:00
|
|
|
snprintf(buff, sizeof(buff), "Topic for %s set by %s at %s\r\n",
|
2014-12-18 08:32:18 -08:00
|
|
|
params[1], params[2], strtime);
|
|
|
|
_channel_text_append(chl, NULL, buff);
|
|
|
|
}
|
|
|
|
|
2014-12-18 09:23:28 -08:00
|
|
|
void
|
|
|
|
_callback_channel_names(Express_Network *net EINA_UNUSED, const char *event EINA_UNUSED, const char *source EINA_UNUSED, const char **params, unsigned int count EINA_UNUSED, void *data EINA_UNUSED)
|
|
|
|
{
|
2015-01-30 10:03:52 -08:00
|
|
|
Channel *chl = NULL;
|
2015-01-30 11:54:35 -08:00
|
|
|
char **users;
|
|
|
|
unsigned int n = 0, i = 0;
|
2015-02-12 10:45:32 -08:00
|
|
|
int crlf = 0, lf = 0;
|
2014-12-18 09:23:28 -08:00
|
|
|
|
2015-01-30 11:54:35 -08:00
|
|
|
/* DBG("Channel Names: %s", params[0]); */
|
|
|
|
/* DBG("\tCount: %d", count); */
|
|
|
|
/* DBG("\tUser: %s", source); */
|
|
|
|
/* DBG("\tMessage:"); */
|
|
|
|
/* DBG("\t%s", params[1]); */
|
|
|
|
/* DBG("\t%s", params[2]); */
|
|
|
|
/* DBG("\t%s", params[3]); */
|
2014-12-18 09:23:28 -08:00
|
|
|
|
2015-01-30 10:03:52 -08:00
|
|
|
if (!(chl = _window_channel_find(params[2]))) return;
|
|
|
|
|
|
|
|
if (strlen(params[3]) > 0)
|
|
|
|
_channel_userlist_show(chl);
|
|
|
|
else
|
|
|
|
_channel_userlist_hide(chl);
|
|
|
|
|
2015-01-30 11:54:35 -08:00
|
|
|
users = eina_str_split_full(params[3], " ", -1, &n);
|
|
|
|
for (; i < n; i++)
|
|
|
|
{
|
2015-02-12 10:45:32 -08:00
|
|
|
char buff[PATH_MAX];
|
|
|
|
|
|
|
|
crlf = _find_crlf(users[i], strlen(users[i]), &lf);
|
|
|
|
if (crlf > 0)
|
|
|
|
eina_strlcpy(buff, users[i], crlf + lf);
|
|
|
|
else
|
|
|
|
eina_strlcpy(buff, users[i], strlen(users[i]) + 1);
|
|
|
|
|
|
|
|
if (buff[0] == '@')
|
|
|
|
_channel_userlist_user_append(chl, buff + 1, EINA_TRUE);
|
2015-01-30 11:54:35 -08:00
|
|
|
else
|
2015-02-12 10:45:32 -08:00
|
|
|
_channel_userlist_user_append(chl, buff, EINA_FALSE);
|
2015-01-30 11:54:35 -08:00
|
|
|
}
|
2015-02-11 08:30:19 -08:00
|
|
|
|
2015-01-30 11:54:35 -08:00
|
|
|
_channel_userlist_go(chl);
|
|
|
|
|
|
|
|
free(users);
|
2014-12-18 09:23:28 -08:00
|
|
|
}
|
|
|
|
|
2014-12-17 12:26:47 -08:00
|
|
|
void
|
2015-03-03 10:05:51 -08:00
|
|
|
_callback_user_quit(Express_Network *net EINA_UNUSED, const char *event EINA_UNUSED, const char *source, const char **params, unsigned int count EINA_UNUSED, void *data EINA_UNUSED)
|
2014-12-17 12:26:47 -08:00
|
|
|
{
|
2015-03-03 11:31:13 -08:00
|
|
|
Eina_List *channels, *l;
|
2015-02-20 09:21:10 -08:00
|
|
|
Channel *chl;
|
|
|
|
char buff[PATH_MAX];
|
|
|
|
|
|
|
|
/* DBG("User Quit"); */
|
|
|
|
/* DBG("\tCount: %d", count); */
|
|
|
|
/* DBG("\tUser: %s", source); */
|
|
|
|
/* DBG("\tMessage:"); */
|
|
|
|
/* DBG("\t%s", params[0]); */
|
2014-12-17 12:26:47 -08:00
|
|
|
|
2015-02-20 09:21:10 -08:00
|
|
|
snprintf(buff, sizeof(buff), "%s has quit: %s", source, params[0]);
|
2015-03-03 11:31:13 -08:00
|
|
|
|
|
|
|
channels = _window_channels_user_find(source);
|
|
|
|
EINA_LIST_FOREACH(channels, l, chl)
|
|
|
|
_channel_text_append(chl, "*", buff);
|
2014-12-17 12:26:47 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-03-03 10:05:51 -08:00
|
|
|
_callback_user_part(Express_Network *net EINA_UNUSED, const char *event EINA_UNUSED, const char *source, const char **params, unsigned int count EINA_UNUSED, void *data EINA_UNUSED)
|
2014-12-17 12:26:47 -08:00
|
|
|
{
|
|
|
|
Channel *chl = NULL;
|
|
|
|
char buff[PATH_MAX];
|
|
|
|
|
2014-12-18 08:32:18 -08:00
|
|
|
/* DBG("User Part %s", params[0]); */
|
|
|
|
/* DBG("\tCount: %d", count); */
|
|
|
|
/* DBG("\tUser: %s", source); */
|
|
|
|
/* DBG("\tMessage:"); */
|
|
|
|
/* DBG("\t%s", params[1]); */
|
2014-12-17 12:26:47 -08:00
|
|
|
|
|
|
|
if (!(chl = _window_channel_find(params[0]))) return;
|
|
|
|
|
2015-02-20 09:21:10 -08:00
|
|
|
snprintf(buff, sizeof(buff), "%s has left %s: %s",
|
2014-12-17 12:26:47 -08:00
|
|
|
source, params[0], params[1]);
|
|
|
|
_channel_text_append(chl, NULL, buff);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-03-03 10:05:51 -08:00
|
|
|
_callback_user_join(Express_Network *net, const char *event EINA_UNUSED, const char *source, const char **params, unsigned int count EINA_UNUSED, void *data EINA_UNUSED)
|
2014-12-17 12:26:47 -08:00
|
|
|
{
|
2014-12-18 07:44:07 -08:00
|
|
|
Channel *chl = NULL;
|
2015-03-03 10:05:51 -08:00
|
|
|
char buff[PATH_MAX], channel[PATH_MAX];
|
|
|
|
int crlf = 0, lf = 0;
|
|
|
|
|
|
|
|
crlf = _find_crlf(params[0], strlen(params[0]), &lf);
|
|
|
|
if (crlf > 0)
|
|
|
|
eina_strlcpy(channel, params[0], crlf + lf - 1);
|
|
|
|
else
|
|
|
|
eina_strlcpy(channel, params[0], strlen(params[0]) + 1);
|
2014-12-17 12:26:47 -08:00
|
|
|
|
2015-03-03 10:05:51 -08:00
|
|
|
/* DBG("User Join %s", channel); */
|
2014-12-18 08:32:18 -08:00
|
|
|
/* DBG("\tCount: %d", count); */
|
|
|
|
/* DBG("\tUser: %s", source); */
|
|
|
|
/* DBG("\tMessage:"); */
|
|
|
|
/* DBG("\t%s", params[1]); */
|
2014-12-17 12:26:47 -08:00
|
|
|
|
2015-03-03 10:05:51 -08:00
|
|
|
/* find the channel */
|
|
|
|
if (!(chl = _window_channel_find(channel)))
|
|
|
|
{
|
|
|
|
Express_Server *srv;
|
|
|
|
|
|
|
|
if ((srv = express_network_server_connected_get(net)))
|
|
|
|
{
|
|
|
|
const char *srv_name = NULL;
|
|
|
|
|
|
|
|
srv_name = express_network_server_realname_get(srv);
|
|
|
|
if ((chl = _window_channel_create(channel, srv_name)))
|
|
|
|
_channel_network_set(chl, net);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-18 07:44:07 -08:00
|
|
|
/* skip user join messages for our own nick */
|
|
|
|
if (!strcmp(source, express_network_nickname_get(net))) return;
|
2014-12-17 12:26:47 -08:00
|
|
|
|
2015-03-03 10:05:51 -08:00
|
|
|
snprintf(buff, sizeof(buff), "%s has joined %s\r\n", source, channel);
|
2015-03-03 11:31:13 -08:00
|
|
|
_channel_text_append(chl, "*", buff);
|
2014-12-17 12:26:47 -08:00
|
|
|
}
|
2014-12-18 09:23:28 -08:00
|
|
|
|
|
|
|
void
|
2014-12-18 11:24:53 -08:00
|
|
|
_callback_user_private(Express_Network *net EINA_UNUSED, const char *event EINA_UNUSED, const char *source, const char **params, unsigned int count, void *data EINA_UNUSED)
|
2014-12-18 09:23:28 -08:00
|
|
|
{
|
|
|
|
DBG("User Private %s", params[0]);
|
|
|
|
DBG("\tCount: %d", count);
|
|
|
|
DBG("\tUser: %s", source);
|
|
|
|
DBG("\tMessage:");
|
|
|
|
DBG("\t%s", params[1]);
|
|
|
|
DBG("\t%s", params[2]);
|
|
|
|
DBG("\t%s", params[3]);
|
|
|
|
}
|
2015-03-03 11:10:43 -08:00
|
|
|
|
|
|
|
void
|
|
|
|
_callback_user_nick(Express_Network *net EINA_UNUSED, const char *event EINA_UNUSED, const char *source, const char **params, unsigned int count, void *data EINA_UNUSED)
|
|
|
|
{
|
2015-03-03 11:31:13 -08:00
|
|
|
Eina_List *channels, *l;
|
|
|
|
Channel *chl;
|
|
|
|
char buff[PATH_MAX], user[PATH_MAX];
|
2015-03-03 11:10:43 -08:00
|
|
|
int crlf = 0, lf = 0;
|
|
|
|
|
|
|
|
crlf = _find_crlf(params[0], strlen(params[0]), &lf);
|
|
|
|
if (crlf > 0)
|
2015-03-03 11:31:13 -08:00
|
|
|
eina_strlcpy(user, params[0], crlf + lf - 1);
|
2015-03-03 11:10:43 -08:00
|
|
|
else
|
2015-03-03 11:31:13 -08:00
|
|
|
eina_strlcpy(user, params[0], strlen(params[0]) + 1);
|
2015-03-03 11:10:43 -08:00
|
|
|
|
2015-03-03 11:31:13 -08:00
|
|
|
DBG("User Changed Nick %s", user);
|
2015-03-03 11:10:43 -08:00
|
|
|
DBG("\tCount: %d", count);
|
|
|
|
DBG("\tUser: %s", source);
|
|
|
|
DBG("\tMessage:");
|
|
|
|
DBG("\t%s", params[1]);
|
|
|
|
DBG("\t%s", params[2]);
|
|
|
|
DBG("\t%s", params[3]);
|
2015-03-03 11:31:13 -08:00
|
|
|
|
2015-04-28 06:19:30 -07:00
|
|
|
snprintf(buff, sizeof(buff), "%s is now known as %s\r\n", source, user);
|
2015-03-03 11:31:13 -08:00
|
|
|
|
|
|
|
/* find all channels that this user is in */
|
|
|
|
channels = _window_channels_user_find(source);
|
|
|
|
EINA_LIST_FOREACH(channels, l, chl)
|
|
|
|
_channel_text_append(chl, "*", buff);
|
2015-03-03 11:10:43 -08:00
|
|
|
}
|