#include "private.h" #include "callbacks.h" #include "window.h" #include "channel.h" #include 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; } void _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) { DBG("Server %s Connected", source); _window_network_channels_create(net); } void _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) { Channel *chl; /* DBG("Server Motd"); */ /* DBG("\tServer: %s", source); */ /* DBG("\tCount: %d", count); */ /* DBG("\tUser: %s", params[0]); */ /* DBG("\tMessage:"); */ /* DBG("\t%s", params[1]); */ if (!(chl = _window_channel_server_find(source))) return; _channel_text_append(chl, NULL, params[1]); } 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]); */ if (!(chl = _window_channel_active_get())) return; _channel_text_append(chl, NULL, params[1]); } 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; /* DBG("Channel Message: %s", params[0]); */ /* DBG("\tCount: %d", count); */ /* DBG("\tUser: %s", source); */ /* DBG("\tMessage:"); */ /* DBG("\t%s", params[1]); */ if (!(chl = _window_channel_find(params[0]))) return; _channel_text_append(chl, source, params[1]); } void _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) { Channel *chl = NULL; /* DBG("Channel Notice: %s", params[0]); */ /* DBG("\tCount: %d", count); */ /* DBG("\tServer: %s", source); */ /* DBG("\tMessage:"); */ /* DBG("\t%s", params[1]); */ if (!strcmp(params[0], "*")) { if (!(chl = _window_channel_server_find(source))) { ERR("Could not find channel with server name: %s", source); if (!(chl = _window_channel_find("Default"))) chl = _window_channel_active_get(); } } else { if (!(chl = _window_channel_find(params[0]))) chl = _window_channel_active_get(); } if (!chl) return; _channel_text_append(chl, NULL, params[1]); } void _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) { Channel *chl = NULL; char buff[PATH_MAX]; /* 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]); */ 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]); } 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; snprintf(buff, sizeof(buff), "Topic for %s set by %s at %s\r\n", params[1], params[2], strtime); _channel_text_append(chl, NULL, buff); } 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) { Channel *chl = NULL; char **users; unsigned int n = 0, i = 0; int crlf = 0, lf = 0; /* 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]); */ if (!(chl = _window_channel_find(params[2]))) return; if (strlen(params[3]) > 0) _channel_userlist_show(chl); else _channel_userlist_hide(chl); users = eina_str_split_full(params[3], " ", -1, &n); for (; i < n; i++) { 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); else _channel_userlist_user_append(chl, buff, EINA_FALSE); } _channel_userlist_go(chl); free(users); } void _callback_user_quit(Express_Network *net EINA_UNUSED, const char *event EINA_UNUSED, const char *source, const char **params EINA_UNUSED, unsigned int count EINA_UNUSED, void *data EINA_UNUSED) { Channel *chl; char buff[PATH_MAX]; /* DBG("User Quit"); */ /* DBG("\tCount: %d", count); */ /* DBG("\tUser: %s", source); */ /* DBG("\tMessage:"); */ /* DBG("\t%s", params[0]); */ // param[0] == reason // source == user /* FIXME: We have a problem here. No channel gets passed in, so we will * need to find all the channels this user is in, and send to channels */ if (!(chl = _window_channel_user_find(source))) return; snprintf(buff, sizeof(buff), "%s has quit: %s", source, params[0]); _channel_text_append(chl, "*", buff); } void _callback_user_part(Express_Network *net EINA_UNUSED, const char *event EINA_UNUSED, const char *source, const char **params EINA_UNUSED, unsigned int count EINA_UNUSED, void *data EINA_UNUSED) { Channel *chl = NULL; char buff[PATH_MAX]; /* DBG("User Part %s", params[0]); */ /* DBG("\tCount: %d", count); */ /* DBG("\tUser: %s", source); */ /* DBG("\tMessage:"); */ /* DBG("\t%s", params[1]); */ if (!(chl = _window_channel_find(params[0]))) return; snprintf(buff, sizeof(buff), "%s has left %s: %s", source, params[0], params[1]); _channel_text_append(chl, NULL, buff); } void _callback_user_join(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) { Channel *chl = NULL; char buff[PATH_MAX]; /* DBG("User Join %s", params[0]); */ /* DBG("\tCount: %d", count); */ /* DBG("\tUser: %s", source); */ /* DBG("\tMessage:"); */ /* DBG("\t%s", params[1]); */ /* skip user join messages for our own nick */ if (!strcmp(source, express_network_nickname_get(net))) return; /* find the channel */ if (!(chl = _window_channel_find(params[0]))) return; snprintf(buff, sizeof(buff), "%s has joined %s\r\n", source, params[0]); _channel_text_append(chl, NULL, buff); } void _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) { 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]); }