Commit 415df82f 415df82fd2121a93faef814eff65c334e47ee306 by Alain Magloire

Put the bits in configure.in for checking for a proper thread lib.

Added the missings HAVE_CONFIG_H for certain files.
message_uidl --> message_uid
define _XOPEN_SOURCE 500 for GNU/Linux to get the namespace of UNIX98
1 parent 5efe9185
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999 Free Software Foundation, Inc.
Copyright (C) 1999, 2000 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -18,4 +18,4 @@
/* Define if using libpam */
#undef USE_LIBPAM
#undef HAVE_SNPRINTF
#undef WITH_PTHREAD
......
......@@ -26,10 +26,6 @@ AC_ARG_ENABLE(pthread,
*) AC_MSG_ERROR(bad value ${enableval} for --disable-pthread) ;;
esac],[usepthread=yes])
if test x"$usepthread" = x"yes"; then
AC_CHECK_HEADERS(pthread.h)
fi
dnl Check for headers
AC_HEADER_STDC
AC_HEADER_DIRENT
......@@ -73,9 +69,15 @@ if test x"$ac_cv_have_libpam" != x"yes"; then
AC_CHECK_LIB(crypt, crypt, AUTHLIBS="-lcrypt",, -lcrypt)
fi
fi
AC_SUBST(AUTHLIBS)
dnl Check threading support
if test x"$usepthread" = x"yes"; then
AC_CHECK_HEADERS(pthread.h)
AC_SEARCH_LIBS(pthread_cancel, pthread, AC_DEFINE(WITH_PTHREAD))
AC_CHECK_FUNCS(pthread_rwlock_init)
fi
dnl Do we need extra libs for networking?
AC_CHECK_FUNC(gethostbyname, [true],
AC_CHECK_LIB(nsl, gethostbyaddr, LIBS="-lnsl $LIBS"))
......@@ -87,4 +89,3 @@ dnl Output Makefiles
AC_OUTPUT(Makefile mailutils.spec include/Makefile include/mailutils/Makefile
m4/Makefile doc/Makefile lib/Makefile mailbox/Makefile imap4d/Makefile
mailbox/include/Makefile from/Makefile mail/Makefile pop3d/Makefile)
......
......@@ -96,8 +96,8 @@ extern int message_set_get_part __P ((message_t, int (*_get_part)
__P ((message_t, size_t,
message_t *)), void *owner));
extern int message_get_uidl __P ((message_t, char *, size_t, size_t *));
extern int message_set_uidl __P ((message_t, int (*_get_uidl)
extern int message_get_uid __P ((message_t, char *, size_t, size_t *));
extern int message_set_uid __P ((message_t, int (*_get_uid)
__P ((message_t, char *, size_t,
size_t *)), void *owner));
......
......@@ -15,6 +15,9 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
......
......@@ -15,6 +15,9 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <errno.h>
#include <stdlib.h>
#include <envelope0.h>
......
......@@ -26,6 +26,7 @@
#include <string.h>
#include <glob.h>
#include <stdio.h>
#include <stdlib.h>
#include <folder0.h>
#include <registrar0.h>
......
......@@ -17,7 +17,7 @@
#ifdef HAVE_CONFIG_H
# include "config.h"
# include <config.h>
#endif
#include <string.h>
......
......@@ -22,11 +22,6 @@
# include <dmalloc.h>
#endif
#ifdef HAVE_PTHREAD_H
# define __USE_UNIX98 /* ?? */
# include <pthread.h>
#endif
#include <sys/types.h>
#include <stdio.h>
......
......@@ -63,7 +63,7 @@ struct _message
size_t hdr_buflen;
int hdr_done;
int (*_get_uidl) __P ((message_t, char *, size_t, size_t *));
int (*_get_uid) __P ((message_t, char *, size_t, size_t *));
int (*_get_num_parts) __P ((message_t, size_t *));
int (*_get_part) __P ((message_t, size_t, message_t *));
int (*_is_multipart) __P ((message_t, int *));
......
......@@ -34,6 +34,7 @@
#include <limits.h>
#include <errno.h>
#ifdef HAVE_PTHREAD_H
# define _XOPEN_SOURCE 500
# include <pthread.h>
#endif
......@@ -140,7 +141,9 @@ static int mbox_body_size (body_t, size_t *);
static int mbox_body_lines (body_t, size_t *);
static int mbox_envelope_sender (envelope_t, char *, size_t, size_t *);
static int mbox_envelope_date (envelope_t, char *, size_t, size_t *);
#ifdef WITH_PTHREAD
static void mbox_cleanup (void *);
#endif
/* We allocate the mbox_data_t struct, but don't do any parsing on the name or
even test for existence. However we do strip any leading "mbox:" part of
......@@ -1367,6 +1370,7 @@ mbox_messages_count (mailbox_t mailbox, size_t *pcount)
return 0;
}
#ifdef WITH_PTHREAD
static void
mbox_cleanup (void *arg)
{
......@@ -1374,3 +1378,4 @@ mbox_cleanup (void *arg)
monitor_unlock (mailbox->monitor);
locker_unlock (mailbox->locker);
}
#endif
......
......@@ -95,7 +95,7 @@ static int pop_top (stream_t, char *, size_t, off_t, size_t *);
static int pop_retr (pop_message_t, char *, size_t, off_t, size_t *);
static int pop_get_fd (pop_message_t, int *);
static int pop_attr_flags (attribute_t, int *);
static int pop_uidl (message_t, char *, size_t, size_t *);
static int pop_uid (message_t, char *, size_t, size_t *);
static int fill_buffer (pop_data_t, char *, size_t);
static int pop_readline (pop_data_t);
static int pop_read_ack (pop_data_t);
......@@ -695,7 +695,7 @@ pop_get_message (mailbox_t mbox, size_t msgno, message_t *pmsg)
}
/* Set the UIDL call on the message. */
message_set_uidl (msg, pop_uidl, mpm);
message_set_uid (msg, pop_uid, mpm);
/* Add it to the list. */
monitor_wrlock (mbox->monitor);
......@@ -958,7 +958,7 @@ pop_message_size (message_t msg, size_t *psize)
default:
/*
fprintf (stderr, "pop_uidl state\n");
fprintf (stderr, "pop_uid state\n");
*/
break;
}
......@@ -1073,14 +1073,14 @@ pop_get_fd (pop_message_t mpm, int *pfd)
FIXME: We should check this with CAPA and fall back to md5 scheme ?
Or maybe check for "X-UIDL" a la Qpopper ? */
static int
pop_uidl (message_t msg, char *buffer, size_t buflen, size_t *pnwriten)
pop_uid (message_t msg, char *buffer, size_t buflen, size_t *pnwriten)
{
pop_message_t mpm = message_get_owner (msg);
pop_data_t mpd;
int status = 0;
void *func = (void *)pop_uidl;
void *func = (void *)pop_uid;
size_t num;
/* According to the RFC uidl's are no longer then 70 chars. */
/* According to the RFC uid's are no longer then 70 chars. */
char uniq[128];
if (mpm == NULL)
......@@ -1115,7 +1115,7 @@ pop_uidl (message_t msg, char *buffer, size_t buflen, size_t *pnwriten)
default:
/*
fprintf (stderr, "pop_uidl state\n");
fprintf (stderr, "pop_uid state\n");
*/
break;
}
......
......@@ -418,7 +418,7 @@ message_set_attribute (message_t msg, attribute_t attribute, void *owner)
}
int
message_get_uidl (message_t msg, char *buffer, size_t buflen, size_t *pwriten)
message_get_uid (message_t msg, char *buffer, size_t buflen, size_t *pwriten)
{
header_t header = NULL;
size_t n = 0;
......@@ -428,8 +428,8 @@ message_get_uidl (message_t msg, char *buffer, size_t buflen, size_t *pwriten)
return EINVAL;
buffer[0] = '\0';
if (msg->_get_uidl)
return msg->_get_uidl (msg, buffer, buflen, pwriten);
if (msg->_get_uid)
return msg->_get_uid (msg, buffer, buflen, pwriten);
/* Be compatible with Qpopper ? qppoper saves the UIDL in "X-UIDL".
We use "Message-ID" as a fallback. Is this bad ? should we generate
......@@ -458,14 +458,14 @@ message_get_uidl (message_t msg, char *buffer, size_t buflen, size_t *pwriten)
}
int
message_set_uidl (message_t msg, int (* _get_uidl)
message_set_uid (message_t msg, int (* _get_uid)
__P ((message_t, char *, size_t, size_t *)), void *owner)
{
if (msg == NULL)
return EINVAL;
if (msg->owner != owner)
return EACCES;
msg->_get_uidl = _get_uidl;
msg->_get_uid = _get_uid;
return 0;
}
......
......@@ -15,7 +15,9 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
......
......@@ -15,37 +15,44 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <errno.h>
#include <stdlib.h>
/* Tell GLIBC that we want UNIX98 pthread_rwlock_xx() functions. */
#define _XOPEN_SOURCE 500
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#ifdef HAVE_PTHREAD_H
# define __USE_UNIX98
#ifdef WITH_PTHREAD
# ifdef HAVE_PTHREAD_H
# include <pthread.h>
# endif
#endif
#include <errno.h>
#include <stdlib.h>
#include <monitor0.h>
#ifdef WITH_PTHREAD
pthread_mutex_t monitor_lock = PTHREAD_MUTEX_INITIALIZER;
#define STATIC_LOCK(m) pthread_mutex_lock(m)
#define STATIC_UNLOCK(m) pthread_mutex_unlock(m)
# define STATIC_LOCK(m) pthread_mutex_lock(m)
# define STATIC_UNLOCK(m) pthread_mutex_unlock(m)
#else
#define STATIC_LOCK(m) 0
#define STATIC_UNLOCK(m) 0
# define STATIC_LOCK(m) 0
# define STATIC_UNLOCK(m) 0
int monitor_lock;
#endif
union _p_lock
{
#ifdef WITH_PTHREAD
# ifdef USE_RWLOCK
# ifdef HAVE_PTHREAD_RWLOCK_INIT
pthread_rwlock_t mutex;
# else
pthread_mutex_t mutex;
# endif
#endif
#else
int dummy;
#endif
};
typedef union _p_lock *p_lock_t;
......@@ -198,17 +205,8 @@ monitor_notify (monitor_t monitor)
/* Concrete Implementation of pthread base on rwlocks. */
#define USE_RWLOCK
#ifdef WITH_PTHREAD
# ifdef USE_RWLOCK
# define RWLOCK_INIT(rwl, attr) pthread_mutex_init (rwl, attr)
# define RWLOCK_DESTROY(rwl) pthread_mutex_destroy (rwl)
# define RWLOCK_RDLOCK(rwl) pthread_mutex_lock (rwl)
# define RWLOCK_TRYRDLOCK(rwl) pthread_mutex_trylock (rwl)
# define RWLOCK_WRLOCK(rwl) pthread_mutex_lock (rwl)
# define RWLOCK_TRYWRLOCK(rwl) pthread_mutex_trylock (rwl)
# define RWLOCK_UNLOCK(rwl) pthread_mutex_unlock (rwl)
# else
# ifdef HAVE_PTHREAD_RWLOCK_INIT
# define RWLOCK_INIT(rwl, attr) pthread_rwlock_init (rwl, attr)
# define RWLOCK_DESTROY(rwl) pthread_rwlock_destroy (rwl)
# define RWLOCK_RDLOCK(rwl) pthread_rwlock_rdlock (rwl)
......@@ -216,6 +214,14 @@ monitor_notify (monitor_t monitor)
# define RWLOCK_WRLOCK(rwl) pthread_rwlock_wrlock (rwl)
# define RWLOCK_TRYWRLOCK(rwl) pthread_rwlock_trywrlock (rwl)
# define RWLOCK_UNLOCK(rwl) pthread_rwlock_unlock (rwl)
# else
# define RWLOCK_INIT(rwl, attr) pthread_mutex_init (rwl, attr)
# define RWLOCK_DESTROY(rwl) pthread_mutex_destroy (rwl)
# define RWLOCK_RDLOCK(rwl) pthread_mutex_lock (rwl)
# define RWLOCK_TRYRDLOCK(rwl) pthread_mutex_trylock (rwl)
# define RWLOCK_WRLOCK(rwl) pthread_mutex_lock (rwl)
# define RWLOCK_TRYWRLOCK(rwl) pthread_mutex_trylock (rwl)
# define RWLOCK_UNLOCK(rwl) pthread_mutex_unlock (rwl)
# endif
#else
# define RWLOCK_INIT(rwl, attr) 0
......
......@@ -42,7 +42,7 @@ pop3_uidl (const char *arg)
message_get_attribute (msg, &attr);
if (!attribute_is_deleted (attr))
{
message_get_uidl (msg, uidl, sizeof (uidl), NULL);
message_get_uid (msg, uidl, sizeof (uidl), NULL);
fprintf (ofile, "%d %s\r\n", mesgno, uidl);
}
}
......@@ -56,7 +56,7 @@ pop3_uidl (const char *arg)
message_get_attribute (msg, &attr);
if (attribute_is_deleted (attr))
return ERR_MESG_DELE;
message_get_uidl (msg, uidl, sizeof (uidl), NULL);
message_get_uid (msg, uidl, sizeof (uidl), NULL);
fprintf (ofile, "+OK %d %s\r\n", mesgno, uidl);
}
......