Mercurial > pidgin
changeset 23538:399975ad001c
Add purple_get_host_name to get the hostname of the machine.
This is a replacement for g_get_host_name in glib2.8+. Thanks to Phil
Hannent and Marcus Lundblad for the initial patch. References #5627.
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Sun, 13 Jul 2008 18:01:57 +0000 |
parents | ad0d0efa30dd |
children | 1f7191e0b24b |
files | COPYRIGHT ChangeLog.API libpurple/protocols/bonjour/bonjour.c libpurple/protocols/irc/irc.c libpurple/util.c libpurple/util.h |
diffstat | 6 files changed, 31 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/COPYRIGHT Sun Jul 13 17:20:41 2008 +0000 +++ b/COPYRIGHT Sun Jul 13 18:01:57 2008 +0000 @@ -161,6 +161,7 @@ Christian Hammond Erick Hamness Fred Hampton +Phil Hannent Casey Harkins Andy Harrison Andrew Hart (arhart)
--- a/ChangeLog.API Sun Jul 13 17:20:41 2008 +0000 +++ b/ChangeLog.API Sun Jul 13 18:01:57 2008 +0000 @@ -20,6 +20,7 @@ * "website" and "dev_website" items to the ui_info hash table * purple_cmds_get_handle, purple_cmds_init, purple_cmds_uninit * cmd-added and cmd-removed signals + * purple_get_host_name Deprecated: * purple_blist_update_buddy_icon
--- a/libpurple/protocols/bonjour/bonjour.c Sun Jul 13 17:20:41 2008 +0000 +++ b/libpurple/protocols/bonjour/bonjour.c Sun Jul 13 18:01:57 2008 +0000 @@ -641,7 +641,6 @@ struct passwd *info; #endif const char *fullname = NULL, *splitpoint, *tmp; - char hostname[255]; gchar *conv = NULL; #ifndef _WIN32 @@ -691,13 +690,7 @@ /* Try to figure out a good host name to use */ /* TODO: Avoid 'localhost,' if possible */ - if (gethostname(hostname, sizeof(hostname)) != 0) { - purple_debug_warning("bonjour", "Error when getting host name: %s. Using \"localhost.\"\n", - g_strerror(errno)); - strcpy(hostname, "localhost"); - } - hostname[sizeof(hostname) - 1] = '\0'; - default_hostname = g_strdup(hostname); + default_hostname = g_strdup(purple_get_host_name()); } static void
--- a/libpurple/protocols/irc/irc.c Sun Jul 13 17:20:41 2008 +0000 +++ b/libpurple/protocols/irc/irc.c Sun Jul 13 18:01:57 2008 +0000 @@ -360,11 +360,10 @@ static gboolean do_login(PurpleConnection *gc) { char *buf, *tmp = NULL; - char hostname[256]; + const char *hostname; const char *username, *realname; struct irc_conn *irc = gc->proto_data; const char *pass = purple_connection_get_password(gc); - int ret; if (pass && *pass) { buf = irc_format(irc, "vv", "PASS", pass); @@ -375,13 +374,7 @@ g_free(buf); } - - ret = gethostname(hostname, sizeof(hostname)); - hostname[sizeof(hostname) - 1] = '\0'; - if (ret < 0 || hostname[0] == '\0') { - purple_debug_warning("irc", "gethostname() failed -- is your hostname set?"); - strcpy(hostname, "localhost"); - } + hostname = purple_get_host_name(); realname = purple_account_get_string(irc->account, "realname", ""); username = purple_account_get_string(irc->account, "username", "");
--- a/libpurple/util.c Sun Jul 13 17:20:41 2008 +0000 +++ b/libpurple/util.c Sun Jul 13 18:01:57 2008 +0000 @@ -4723,3 +4723,21 @@ return g_string_free(string, FALSE); } +const gchar * +purple_get_host_name(void) +{ +#if GLIB_CHECK_VERSION(2,8,0) + return g_get_host_name(); +#else + static char hostname[256]; + int ret = gethostname(hostname, sizeof(hostname)); + hostname[sizeof(hostname) - 1] = '\0'; + + if (ret == -1 || hostname[0] == '\0') { + purple_debug_info("purple_get_host_name: ", "could not find host name"); + return "localhost"; + } else { + return hostname; + } +#endif +}
--- a/libpurple/util.h Sun Jul 13 17:20:41 2008 +0000 +++ b/libpurple/util.h Sun Jul 13 18:01:57 2008 +0000 @@ -1271,6 +1271,14 @@ */ void purple_restore_default_signal_handlers(void); +/** + * Gets the host name of the machine. If it not possible to determine the + * host name, "localhost" is returned + * + * @constreturn The hostname + */ +const gchar *purple_get_host_name(void); + #ifdef __cplusplus } #endif