diff libpurple/protocols/jabber/jabber.c @ 24505:9bb624e345aa

me likes this better, References #5565
author Ka-Hing Cheung <khc@hxbc.us>
date Sat, 29 Nov 2008 01:52:36 +0000
parents 8e7e6f60e053
children 5cd0188892f6 e1f363f8fd6b
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);
 }