1
0
mirror of https://github.com/irssi/irssi.git synced 2024-12-04 14:46:39 -05:00
irssi/src/fe-common/irc/fe-ctcp.c

111 lines
3.5 KiB
C
Raw Normal View History

/*
fe-ctcp.c : irssi
Copyright (C) 1999-2000 Timo Sirainen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "module.h"
#include "module-formats.h"
#include "misc.h"
#include "settings.h"
#include "irc.h"
#include "levels.h"
#include "server.h"
#include "channels.h"
#include "query.h"
#include "ignore.h"
#include "windows.h"
#include "window-items.h"
static void ctcp_print(const char *pre, const char *data, IRC_SERVER_REC *server, const char *nick, const char *addr, const char *target)
{
char *str;
g_return_if_fail(data != NULL);
str = g_strconcat(pre, " ", data, NULL);
printformat(server, ischannel(*target) ? target : nick, MSGLEVEL_CTCPS,
IRCTXT_CTCP_REQUESTED, nick, addr, str, target);
g_free(str);
}
static void ctcp_default_msg(const char *data, IRC_SERVER_REC *server, const char *nick, const char *addr, const char *target)
{
ctcp_print("unknown CTCP", data, server, nick, addr, target);
}
static void ctcp_ping_msg(const char *data, IRC_SERVER_REC *server, const char *nick, const char *addr, const char *target)
{
ctcp_print("CTCP PING", data, server, nick, addr, target);
}
static void ctcp_version_msg(const char *data, IRC_SERVER_REC *server, const char *nick, const char *addr, const char *target)
{
ctcp_print("CTCP VERSION", data, server, nick, addr, target);
}
static void ctcp_default_reply(const char *data, IRC_SERVER_REC *server, const char *nick, const char *addr, const char *target)
{
char *ptr, *str;
g_return_if_fail(data != NULL);
str = g_strdup(data);
ptr = strchr(str, ' ');
if (ptr != NULL) *ptr++ = '\0'; else ptr = "";
printformat(server, ischannel(*target) ? target : nick, MSGLEVEL_CTCPS,
IRCTXT_CTCP_REPLY, str, nick, ptr);
g_free(str);
}
static void ctcp_ping_reply(const char *data, IRC_SERVER_REC *server, const char *nick, const char *addr, const char *target)
{
GTimeVal tv, tv2;
long usecs;
g_return_if_fail(data != NULL);
if (sscanf(data, "%ld %ld", &tv2.tv_sec, &tv2.tv_usec) != 2)
return;
g_get_current_time(&tv);
usecs = get_timeval_diff(&tv, &tv2);
printformat(server, ischannel(*target) ? target : nick, MSGLEVEL_CTCPS,
IRCTXT_CTCP_PING_REPLY, nick, usecs/1000, usecs%1000);
}
void fe_ctcp_init(void)
{
signal_add("default ctcp msg", (SIGNAL_FUNC) ctcp_default_msg);
signal_add("ctcp msg ping", (SIGNAL_FUNC) ctcp_ping_msg);
signal_add("ctcp msg version", (SIGNAL_FUNC) ctcp_version_msg);
signal_add("default ctcp reply", (SIGNAL_FUNC) ctcp_default_reply);
signal_add("ctcp reply ping", (SIGNAL_FUNC) ctcp_ping_reply);
}
void fe_ctcp_deinit(void)
{
signal_remove("default ctcp msg", (SIGNAL_FUNC) ctcp_default_msg);
signal_remove("ctcp msg ping", (SIGNAL_FUNC) ctcp_ping_msg);
signal_remove("ctcp msg version", (SIGNAL_FUNC) ctcp_version_msg);
signal_remove("default ctcp reply", (SIGNAL_FUNC) ctcp_default_reply);
signal_remove("ctcp reply ping", (SIGNAL_FUNC) ctcp_ping_reply);
}