express: Added Admin and Away commands.
Summary: Added Admin and away commands. Also cleanedup commands.c file Signed-off-by: Srivardhan Hebbar <sri.hebbar@samsung.com> Reviewers: devilhorns Differential Revision: https://phab.enlightenment.org/D2497
This commit is contained in:
parent
474ce07250
commit
5e10671c9c
|
@ -84,7 +84,7 @@ _callback_server_notice(Express_Network *net EINA_UNUSED, const char *event EINA
|
|||
_row_color_simple_create(COLOR_SERVER_NOTICE));
|
||||
}
|
||||
|
||||
void
|
||||
void
|
||||
_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)
|
||||
{
|
||||
Channel *chl = NULL;
|
||||
|
@ -224,6 +224,18 @@ _callback_channel_names(Express_Network *net EINA_UNUSED, const char *event EINA
|
|||
}
|
||||
|
||||
void
|
||||
_callback_user_away(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];
|
||||
|
||||
if (!(chl = _window_channel_active_get())) return;
|
||||
snprintf(buff, sizeof(buff), "%s", params[1]);
|
||||
_channel_text_append(chl, NULL, params[1],
|
||||
_row_color_simple_create(COLOR_TEXT));
|
||||
}
|
||||
|
||||
void
|
||||
_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)
|
||||
{
|
||||
Eina_List *channels, *l;
|
||||
|
|
|
@ -11,6 +11,7 @@ void _callback_channel_topic(Express_Network *net, const char *event, const char
|
|||
void _callback_channel_topic_time(Express_Network *net, const char *event, const char *source, const char **params, unsigned int count, void *data);
|
||||
void _callback_channel_names(Express_Network *net, const char *event, const char *source, const char **params, unsigned int count, void *data);
|
||||
|
||||
void _callback_user_away(Express_Network *net, const char *event, const char *source, const char **params, unsigned int count, void *data);
|
||||
void _callback_user_quit(Express_Network *net, const char *event, const char *source, const char **params, unsigned int count, void *data);
|
||||
void _callback_user_part(Express_Network *net, const char *event, const char *source, const char **params, unsigned int count, void *data);
|
||||
void _callback_user_join(Express_Network *net, const char *event, const char *source, const char **params, unsigned int count, void *data);
|
||||
|
|
|
@ -1,7 +1,29 @@
|
|||
#include "private.h"
|
||||
#include "channel.h"
|
||||
|
||||
static int
|
||||
static Eina_Bool
|
||||
_cmd_admin_handle(Express_Network *net, char *token, char *buff)
|
||||
{
|
||||
snprintf(buff, PATH_MAX, "ADMIN %s\r\n", token);
|
||||
express_network_command_send(net, buff);
|
||||
|
||||
return EINA_FALSE;
|
||||
}
|
||||
|
||||
static Eina_Bool
|
||||
_cmd_away_handle(Express_Network *net, char *token, char *buff)
|
||||
{
|
||||
if (token)
|
||||
snprintf(buff, PATH_MAX, "AWAY %s\r\n", token);
|
||||
else
|
||||
snprintf(buff, PATH_MAX, "AWAY\r\n");
|
||||
|
||||
express_network_command_send(net, buff);
|
||||
|
||||
return EINA_FALSE;
|
||||
}
|
||||
|
||||
static Eina_Bool
|
||||
_cmd_help_handle(char *token, char *buff)
|
||||
{
|
||||
fprintf(stderr, "%s\n", __FUNCTION__);
|
||||
|
@ -305,7 +327,7 @@ help_help:
|
|||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
static int
|
||||
static Eina_Bool
|
||||
_cmd_join_handle(Express_Network *net, char *token, char *buff)
|
||||
{
|
||||
if (!token)
|
||||
|
@ -317,8 +339,8 @@ _cmd_join_handle(Express_Network *net, char *token, char *buff)
|
|||
return EINA_FALSE;
|
||||
}
|
||||
|
||||
static int
|
||||
_cmd_handle_quit(Express_Network *net, char *token, char *buff)
|
||||
static Eina_Bool
|
||||
_cmd_quit_handle(Express_Network *net, char *token, char *buff)
|
||||
{
|
||||
snprintf(buff, PATH_MAX,"(Disconnected)\r\n");
|
||||
express_network_disconnect(net, token);
|
||||
|
@ -326,32 +348,36 @@ _cmd_handle_quit(Express_Network *net, char *token, char *buff)
|
|||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
static Eina_Bool
|
||||
_nocmd_handle(Express_Network *net, const char *name, char *str, char *buff)
|
||||
{
|
||||
snprintf(buff, PATH_MAX, "%s\r\n", str);
|
||||
express_network_channel_priv_send(net, name, buff);
|
||||
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
Eina_Bool
|
||||
_cmd_txt_handle(Express_Network *net, const char *name, char *str, char *buff)
|
||||
{
|
||||
char **tokens, *tmpstr = strdup(str);
|
||||
char **tokens;
|
||||
Eina_Bool ret;
|
||||
|
||||
tokens = eina_str_split(tmpstr, " ", 0);
|
||||
if (!strcasecmp(tokens[0], "/HELP"))
|
||||
{
|
||||
ret =_cmd_help_handle(tokens[1], buff);
|
||||
}
|
||||
else if (!strncasecmp(tokens[0], "/JOIN", 5))
|
||||
{
|
||||
ret = _cmd_join_handle(net, tokens[1], buff);
|
||||
}
|
||||
else if (!strncasecmp(tokens[0], "/QUIT", 5))
|
||||
{
|
||||
ret = _cmd_handle_quit(net, str + strlen(tokens[0] + 1), buff);
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf(buff, PATH_MAX, "%s\r\n", str);
|
||||
express_network_channel_priv_send(net, name, buff);
|
||||
ret = EINA_TRUE;
|
||||
}
|
||||
tokens = eina_str_split(str, " ", 2);
|
||||
|
||||
free(tmpstr);
|
||||
if (!strcasecmp(tokens[0], "/ADMIN"))
|
||||
ret = _cmd_admin_handle(net, tokens[1], buff);
|
||||
else if (!strcasecmp(tokens[0], "/AWAY"))
|
||||
ret = _cmd_away_handle(net, tokens[1], buff);
|
||||
else if (!strcasecmp(tokens[0], "/HELP"))
|
||||
ret =_cmd_help_handle(tokens[1], buff);
|
||||
else if (!strncasecmp(tokens[0], "/JOIN", 5))
|
||||
ret = _cmd_join_handle(net, tokens[1], buff);
|
||||
else if (!strncasecmp(tokens[0], "/QUIT", 5))
|
||||
ret = _cmd_quit_handle(net, str + strlen(tokens[0] + 1), buff);
|
||||
else
|
||||
ret = _nocmd_handle(net, name, str, buff);
|
||||
|
||||
free(tokens);
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -215,6 +215,7 @@ _cb_idle(void *data EINA_UNUSED)
|
|||
memset(&cbs, 0, sizeof(cbs));
|
||||
|
||||
cbs.data = _win;
|
||||
cbs.away = _callback_user_away;
|
||||
cbs.connect = _callback_server_connected;
|
||||
cbs.motd = _callback_server_motd;
|
||||
cbs.notice = _callback_server_notice;
|
||||
|
|
|
@ -34,6 +34,9 @@ typedef void (*Express_Event_Numeric_Callback)(Express_Network *net, unsigned in
|
|||
/* NB: See http://irchelp.org/irchelp/rfc/chapter4.html for parameters */
|
||||
typedef struct _Express_Callbacks
|
||||
{
|
||||
/* params[1]: Status message, whether set to away or not */
|
||||
Express_Event_Callback away;
|
||||
|
||||
/* source: server which was connected
|
||||
* params: none */
|
||||
Express_Event_Callback connect;
|
||||
|
|
|
@ -145,11 +145,16 @@ _process_buffer(Express_Network *net, char *data, int length)
|
|||
case 253:
|
||||
case 254:
|
||||
case 255:
|
||||
case 256:
|
||||
case 257:
|
||||
case 258:
|
||||
case 259:
|
||||
case 265:
|
||||
case 266:
|
||||
case 372:
|
||||
case 375:
|
||||
case 376:
|
||||
case 402:
|
||||
case 403:
|
||||
case 422:
|
||||
{
|
||||
|
@ -191,6 +196,13 @@ _process_buffer(Express_Network *net, char *data, int length)
|
|||
if (code == 376) express_network_nick_password_send(net);
|
||||
}
|
||||
break;
|
||||
case 305:
|
||||
case 306:
|
||||
{
|
||||
if (net->callbacks.away)
|
||||
(*net->callbacks.away)(net, "AWAY", prefix, params, index,
|
||||
net->callbacks.data);
|
||||
}
|
||||
case 332:
|
||||
{
|
||||
if (net->callbacks.topic)
|
||||
|
|
Loading…
Reference in New Issue