pidgin: ee0b2e33: Add purple_get_host_name to get the host...
sadrul at pidgin.im
sadrul at pidgin.im
Sun Jul 13 14:05:49 EDT 2008
-----------------------------------------------------------------
Revision: ee0b2e3380c2604a456e2388ce05e8ba8913f4f8
Ancestor: 947fd3aa904cf2b1909e0b2d9f06352455573d21
Author: sadrul at pidgin.im
Date: 2008-07-13T18:01:57
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/ee0b2e3380c2604a456e2388ce05e8ba8913f4f8
Modified files:
COPYRIGHT ChangeLog.API
libpurple/protocols/bonjour/bonjour.c
libpurple/protocols/irc/irc.c libpurple/util.c
libpurple/util.h
ChangeLog:
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.
-------------- next part --------------
============================================================
--- COPYRIGHT 6cb045cac3306bb2d1d4b600a7482996c66a5fc5
+++ COPYRIGHT 434e7b106950621eca8fefc4ea324cc9afc60857
@@ -161,6 +161,7 @@ Fred Hampton
Christian Hammond
Erick Hamness
Fred Hampton
+Phil Hannent
Casey Harkins
Andy Harrison
Andrew Hart (arhart)
============================================================
--- ChangeLog.API 67f750cf86e3393211037d0433d31a7437a69f84
+++ ChangeLog.API 602f1af93b834224a0449956feea1320c4ecd501
@@ -20,6 +20,7 @@ version 2.5.0 (??/??/2008):
* "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
============================================================
--- libpurple/protocols/bonjour/bonjour.c ffcfd0731fbd5ffad35e41f68dcdc328595c544d
+++ libpurple/protocols/bonjour/bonjour.c 1219251e75ffb9d3843eb0d9547ba21b71879d86
@@ -641,7 +641,6 @@ initialize_default_account_values(void)
struct passwd *info;
#endif
const char *fullname = NULL, *splitpoint, *tmp;
- char hostname[255];
gchar *conv = NULL;
#ifndef _WIN32
@@ -691,13 +690,7 @@ initialize_default_account_values(void)
/* 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
============================================================
--- libpurple/protocols/irc/irc.c 4cd58114573cf8a298bd295e43f9430e69401373
+++ libpurple/protocols/irc/irc.c 9a2f7b26ea21ff1002cbab7b3b708448db60a880
@@ -360,11 +360,10 @@ static gboolean do_login(PurpleConnectio
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 @@ static gboolean do_login(PurpleConnectio
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", "");
============================================================
--- libpurple/util.c a08cd7019e3369d87f7ab6edc77962b7c2baa352
+++ libpurple/util.c a3168300e653eb6e2c4e8106658db346ad27e36b
@@ -4723,3 +4723,21 @@ char * purple_util_format_song_info(cons
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
+}
============================================================
--- libpurple/util.h 65e82b7d0c4368c900060f5a861f7b69ea0e101f
+++ libpurple/util.h 731af6e9837b0b89a2b263eb97a08f352d74f5ae
@@ -1271,6 +1271,14 @@ void purple_restore_default_signal_handl
*/
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
More information about the Commits
mailing list