dovecot-1.2: Added my_hostdomain() function which mbox code now ...
dovecot at dovecot.org
dovecot at dovecot.org
Wed Jan 7 20:46:51 EET 2009
details: http://hg.dovecot.org/dovecot-1.2/rev/2609eca99495
changeset: 8596:2609eca99495
user: Timo Sirainen <tss at iki.fi>
date: Wed Jan 07 13:45:37 2009 -0500
description:
Added my_hostdomain() function which mbox code now uses instead of doing that internally.
Based on patch by Apple.
diffstat:
3 files changed, 29 insertions(+), 21 deletions(-)
src/lib-storage/index/mbox/mbox-save.c | 20 +-------------------
src/lib/hostpid.c | 23 +++++++++++++++++++++++
src/lib/hostpid.h | 7 +++++--
diffs (113 lines):
diff -r 829b6555392b -r 2609eca99495 src/lib-storage/index/mbox/mbox-save.c
--- a/src/lib-storage/index/mbox/mbox-save.c Wed Jan 07 13:44:41 2009 -0500
+++ b/src/lib-storage/index/mbox/mbox-save.c Wed Jan 07 13:45:37 2009 -0500
@@ -27,7 +27,6 @@
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
-#include <netdb.h>
#include <utime.h>
#define MBOX_DELIVERY_ID_RAND_BYTES (64/8)
@@ -58,8 +57,6 @@ struct mbox_save_context {
unsigned int finished:1;
};
-static char my_hostdomain[256] = "";
-
static int write_error(struct mbox_save_context *ctx)
{
mbox_set_syscall_error(ctx->mbox, "write()");
@@ -114,22 +111,7 @@ static int write_from_line(struct mbox_s
static int write_from_line(struct mbox_save_context *ctx, time_t received_date,
const char *from_envelope)
{
- const char *name;
int ret;
-
- if (*my_hostdomain == '\0') {
- struct hostent *hent;
-
- hent = gethostbyname(my_hostname);
-
- name = hent != NULL ? hent->h_name : NULL;
- if (name == NULL) {
- /* failed, use just the hostname */
- name = my_hostname;
- }
-
- i_strocpy(my_hostdomain, name, sizeof(my_hostdomain));
- }
T_BEGIN {
const char *line;
@@ -139,7 +121,7 @@ static int write_from_line(struct mbox_s
&ctx->mbox->storage->storage;
from_envelope = t_strconcat(storage->ns->user->username,
- "@", my_hostdomain, NULL);
+ "@", my_hostdomain(), NULL);
}
/* save in local timezone, no matter what it was given with */
diff -r 829b6555392b -r 2609eca99495 src/lib/hostpid.c
--- a/src/lib/hostpid.c Wed Jan 07 13:44:41 2009 -0500
+++ b/src/lib/hostpid.c Wed Jan 07 13:45:37 2009 -0500
@@ -4,9 +4,12 @@
#include "hostpid.h"
#include <unistd.h>
+#include <netdb.h>
const char *my_hostname = NULL;
const char *my_pid = NULL;
+
+static char *my_domain = NULL;
void hostpid_init(void)
{
@@ -17,6 +20,26 @@ void hostpid_init(void)
hostname[sizeof(hostname)-1] = '\0';
my_hostname = hostname;
+ /* allow calling hostpid_init() multiple times to reset hostname */
+ i_free_and_null(my_domain);
+
i_strocpy(pid, dec2str(getpid()), sizeof(pid));
my_pid = pid;
}
+
+const char *my_hostdomain(void)
+{
+ struct hostent *hent;
+ const char *name;
+
+ if (my_domain == NULL) {
+ hent = gethostbyname(my_hostname);
+ name = hent != NULL ? hent->h_name : NULL;
+ if (name == NULL) {
+ /* failed, use just the hostname */
+ name = my_hostname;
+ }
+ my_domain = i_strdup(name);
+ }
+ return my_domain;
+}
diff -r 829b6555392b -r 2609eca99495 src/lib/hostpid.h
--- a/src/lib/hostpid.h Wed Jan 07 13:44:41 2009 -0500
+++ b/src/lib/hostpid.h Wed Jan 07 13:45:37 2009 -0500
@@ -4,9 +4,12 @@ extern const char *my_hostname;
extern const char *my_hostname;
extern const char *my_pid;
-/* Initializes my_hostname and my_pid. Done only once, so it's safe and
- fast to call this function multiple times. */
+/* Initializes my_hostname and my_pid. */
void hostpid_init(void);
+
+/* Returns the current host+domain, or if it fails fallback to returning
+ hostname. */
+const char *my_hostdomain(void);
#endif
More information about the dovecot-cvs
mailing list