changeset 24560:9bb624e345aa

me likes this better, References #5565
author Ka-Hing Cheung <khc@hxbc.us>
date Sat, 29 Nov 2008 01:52:36 +0000
parents 10ab5441572f
children 0b2a1b6f7464 e1f363f8fd6b
files libpurple/protocols/jabber/jabber.c
diffstat 1 files changed, 10 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/jabber.c	Sat Nov 29 01:35:02 2008 +0000
+++ b/libpurple/protocols/jabber/jabber.c	Sat Nov 29 01:52:36 2008 +0000
@@ -150,14 +150,21 @@
 	char hostname[256]; /* current hostname */
 
 	/* Empty resource == don't send any */
-	if (strlen(input) == 0)
+	if (*input == '\0' || strstr(input, "__HOSTNAME__") == NULL)
 		return NULL;
 
 	/* Replace __HOSTNAME__ with hostname */
-	if (gethostname(hostname, sizeof(hostname))) {
-		purple_debug_warning("jabber", "gethostname() failed -- is your hostname set?");
+	if (gethostname(hostname, sizeof(hostname) - 1)) {
+		purple_debug_warning("jabber", "gethostname: %s\n", g_strerror(errno));
+		/* according to glibc doc, the only time an error is returned
+		   is if the hostname is longer than the buffer, in which case
+		   glibc 2.2+ would still fill the buffer with partial
+		   hostname, so maybe we want to detect that and use it
+		   instead
+		*/
 		strcpy(hostname, "localhost");
 	}
+	hostname[sizeof(hostname) - 1] = '\0';
 
 	return purple_strreplace(input, "__HOSTNAME__", hostname);
 }