diff options
author | TingPing <tingping@tingping.se> | 2014-01-08 01:32:28 -0500 |
---|---|---|
committer | TingPing <tingping@tingping.se> | 2014-01-08 01:32:28 -0500 |
commit | 20d26aea943d8de63a61cb92f506dd51b934fe36 (patch) | |
tree | bb9f0377978fcc400e92a07f6ff53b1ec862199e /src | |
parent | 9cba22c38ab58e7e54258ce012a5e296f81f3f7b (diff) |
Rewrite dns command
- Cross platform - Doesn't depend on external tools
Diffstat (limited to 'src')
-rw-r--r-- | src/common/cfgfiles.c | 3 | ||||
-rw-r--r-- | src/common/hexchat.h | 1 | ||||
-rw-r--r-- | src/common/inbound.c | 63 | ||||
-rw-r--r-- | src/common/outbound.c | 18 | ||||
-rw-r--r-- | src/common/plugin.c | 1 |
5 files changed, 64 insertions, 22 deletions
diff --git a/src/common/cfgfiles.c b/src/common/cfgfiles.c index 7d0e9c91..826c56d8 100644 --- a/src/common/cfgfiles.c +++ b/src/common/cfgfiles.c @@ -417,8 +417,6 @@ const struct prefs vars[] = {"dcc_stall_timeout", P_OFFINT (hex_dcc_stall_timeout), TYPE_INT}, {"dcc_timeout", P_OFFINT (hex_dcc_timeout), TYPE_INT}, - {"dnsprogram", P_OFFSET (hex_dnsprogram), TYPE_STR}, - {"flood_ctcp_num", P_OFFINT (hex_flood_ctcp_num), TYPE_INT}, {"flood_ctcp_time", P_OFFINT (hex_flood_ctcp_time), TYPE_INT}, {"flood_msg_num", P_OFFINT (hex_flood_msg_num), TYPE_INT}, @@ -875,7 +873,6 @@ load_default_config(void) strcpy (prefs.hex_dcc_dir, g_build_filename (g_get_home_dir (), "Downloads", NULL)); } #endif - strcpy (prefs.hex_dnsprogram, "host"); strcpy (prefs.hex_gui_ulist_doubleclick, "QUERY %s"); strcpy (prefs.hex_input_command_char, "/"); strcpy (prefs.hex_irc_logmask, g_build_filename ("%n", "%c.log", NULL)); diff --git a/src/common/hexchat.h b/src/common/hexchat.h index 063a55b7..63d0fbed 100644 --- a/src/common/hexchat.h +++ b/src/common/hexchat.h @@ -318,7 +318,6 @@ struct hexchatprefs char hex_dcc_completed_dir[PATHLEN + 1]; char hex_dcc_dir[PATHLEN + 1]; char hex_dcc_ip[DOMAINLEN + 1]; - char hex_dnsprogram[72]; char hex_gui_ulist_doubleclick[256]; char hex_input_command_char[4]; char hex_irc_extra_hilight[300]; diff --git a/src/common/inbound.c b/src/common/inbound.c index 1ea0a412..780e4ae3 100644 --- a/src/common/inbound.c +++ b/src/common/inbound.c @@ -33,6 +33,8 @@ #define WANTDNS #include "inet.h" +#include <gio/gio.h> + #include "hexchat.h" #include "util.h" #include "ignore.h" @@ -1270,20 +1272,71 @@ inbound_next_nick (session *sess, char *nick, int error, } } + +static void +dns_addr_callback (GResolver *resolver, GAsyncResult *result, session *sess) +{ + gchar *addr; + + g_return_if_fail (is_session(sess)); + + addr = g_resolver_lookup_by_address_finish (resolver, result, NULL); + if (addr) + PrintTextf (sess, _("Resolved to %s"), addr); + else + PrintText (sess, _("Not found")); +} + +static void +dns_name_callback (GResolver *resolver, GAsyncResult *result, session *sess) +{ + GList* addrs; + gchar* addr; + GList* list; + + g_return_if_fail (is_session (sess)); + + addrs = g_resolver_lookup_by_name_finish (resolver, result, NULL); + if (addrs) + { + PrintText (sess, _("Resolved to:")); + + for (list = g_list_first (addrs); list; list = g_list_next (list)) + { + addr = g_inet_address_to_string (list->data); + PrintTextf (sess, " %s", addr); + } + + g_resolver_free_addresses (addrs); + } + else + PrintText (sess, _("Not found")); +} + void do_dns (session *sess, char *nick, char *host, - const message_tags_data *tags_data) +const message_tags_data *tags_data) { + GResolver *res = g_resolver_get_default (); + GInetAddress *addr; char *po; char tbuf[1024]; po = strrchr (host, '@'); if (po) host = po + 1; - EMIT_SIGNAL_TIMESTAMP (XP_TE_RESOLVINGUSER, sess, nick, host, NULL, NULL, 0, - tags_data->timestamp); - snprintf (tbuf, sizeof (tbuf), "exec -d %s %s", prefs.hex_dnsprogram, host); - handle_command (sess, tbuf, FALSE); + + if (nick) + EMIT_SIGNAL_TIMESTAMP (XP_TE_RESOLVINGUSER, sess, nick, host, NULL, NULL, 0, + tags_data->timestamp); + + PrintTextf (sess, _("Looking up %s..."), host); + + addr = g_inet_address_new_from_string (host); + if (addr) + g_resolver_lookup_by_address_async (res, addr, NULL, dns_addr_callback, sess); + else + g_resolver_lookup_by_name_async (res, host, NULL, dns_name_callback, sess); } static void diff --git a/src/common/outbound.c b/src/common/outbound.c index 96425f8f..7d64e65f 100644 --- a/src/common/outbound.c +++ b/src/common/outbound.c @@ -1414,21 +1414,17 @@ cmd_discon (struct session *sess, char *tbuf, char *word[], char *word_eol[]) static int cmd_dns (struct session *sess, char *tbuf, char *word[], char *word_eol[]) { -#ifdef WIN32 - PrintText (sess, "DNS is not implemented in Windows.\n"); - return TRUE; -#else char *nick = word[2]; struct User *user; + message_tags_data no_tags = MESSAGE_TAGS_DATA_INIT; if (*nick) { - if (strchr (nick, '.') == NULL) + user = userlist_find (sess, nick); + if (user) { - user = userlist_find (sess, nick); - if (user && user->hostname) + if (user->hostname) { - message_tags_data no_tags = MESSAGE_TAGS_DATA_INIT; do_dns (sess, user->nick, user->hostname, &no_tags); } else { @@ -1437,13 +1433,11 @@ cmd_dns (struct session *sess, char *tbuf, char *word[], char *word_eol[]) } } else { - snprintf (tbuf, TBUFSIZE, "exec -d %s %s", prefs.hex_dnsprogram, nick); - handle_command (sess, tbuf, FALSE); + do_dns (sess, NULL, nick, &no_tags); } return TRUE; } return FALSE; -#endif } static int @@ -3904,7 +3898,7 @@ const struct commands xc_cmds[] = { {"DEVOICE", cmd_devoice, 1, 1, 1, N_("DEVOICE <nick>, removes voice status from the nick on the current channel (needs chanop)")}, {"DISCON", cmd_discon, 0, 0, 1, N_("DISCON, Disconnects from server")}, - {"DNS", cmd_dns, 0, 0, 1, N_("DNS <nick|host|ip>, Finds a users IP number")}, + {"DNS", cmd_dns, 0, 0, 1, N_("DNS <nick|host|ip>, Resolves an IP or hostname")}, {"ECHO", cmd_echo, 0, 0, 1, N_("ECHO <text>, Prints text locally")}, #ifndef WIN32 {"EXEC", cmd_exec, 0, 0, 1, diff --git a/src/common/plugin.c b/src/common/plugin.c index ee3b26c8..286a68c7 100644 --- a/src/common/plugin.c +++ b/src/common/plugin.c @@ -491,7 +491,6 @@ plugin_auto_load (session *sess) /* a long list of bundled plugins that should be loaded automatically, * user plugins should go to <config>, leave Program Files alone! */ for_files (HEXCHATLIBDIR, "hcchecksum.dll", plugin_auto_load_cb); - for_files (HEXCHATLIBDIR, "hcdns.dll", plugin_auto_load_cb); for_files (HEXCHATLIBDIR, "hcdoat.dll", plugin_auto_load_cb); for_files (HEXCHATLIBDIR, "hcexec.dll", plugin_auto_load_cb); for_files (HEXCHATLIBDIR, "hcfishlim.dll", plugin_auto_load_cb); |