# HG changeset patch # User Ka-Hing Cheung # Date 1227923556 0 # Node ID 9bb624e345aaeb505a6f7a923ab3b5ed1636b14b # Parent 10ab5441572f7a12c3b6dc4a30a3be39aa0d22f3 me likes this better, References #5565 diff -r 10ab5441572f -r 9bb624e345aa libpurple/protocols/jabber/jabber.c --- 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); }